Add ability to mark video sources for screen casting in ObjC
Bug: webrtc:13033
Change-Id: If30a4889cd2cb0ecc5ee91eed2ee9b496a40c852
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/227295
Reviewed-by: Kári Helgason <kthelgason@webrtc.org>
Commit-Queue: Kári Helgason <kthelgason@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#34818}
diff --git a/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.h b/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.h
index 2b04898..7891352 100644
--- a/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.h
+++ b/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.h
@@ -60,6 +60,13 @@
*/
- (RTC_OBJC_TYPE(RTCVideoSource) *)videoSource;
+/** Initialize a generic RTCVideoSource with he posibility of marking
+ * it as usable for screen sharing. The RTCVideoSource should be
+ * passed to a RTCVideoCapturer implementation, e.g.
+ * RTCCameraVideoCapturer, in order to produce frames.
+ */
+- (RTC_OBJC_TYPE(RTCVideoSource) *)videoSourceForScreenCast:(BOOL)forScreenCast;
+
/** Initialize an RTCVideoTrack with a source and an id. */
- (RTC_OBJC_TYPE(RTCVideoTrack) *)videoTrackWithSource:(RTC_OBJC_TYPE(RTCVideoSource) *)source
trackId:(NSString *)trackId;
diff --git a/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm b/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm
index 2f324f7..1f0549a 100644
--- a/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm
+++ b/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm
@@ -247,6 +247,13 @@
workerThread:_workerThread.get()];
}
+- (RTC_OBJC_TYPE(RTCVideoSource) *)videoSourceForScreenCast:(BOOL)forScreenCast {
+ return [[RTC_OBJC_TYPE(RTCVideoSource) alloc] initWithFactory:self
+ signalingThread:_signalingThread.get()
+ workerThread:_workerThread.get()
+ isScreenCast:forScreenCast];
+}
+
- (RTC_OBJC_TYPE(RTCVideoTrack) *)videoTrackWithSource:(RTC_OBJC_TYPE(RTCVideoSource) *)source
trackId:(NSString *)trackId {
return [[RTC_OBJC_TYPE(RTCVideoTrack) alloc] initWithFactory:self source:source trackId:trackId];
diff --git a/sdk/objc/api/peerconnection/RTCVideoSource+Private.h b/sdk/objc/api/peerconnection/RTCVideoSource+Private.h
index 0390846..8e475dd 100644
--- a/sdk/objc/api/peerconnection/RTCVideoSource+Private.h
+++ b/sdk/objc/api/peerconnection/RTCVideoSource+Private.h
@@ -41,6 +41,11 @@
signalingThread:(rtc::Thread *)signalingThread
workerThread:(rtc::Thread *)workerThread;
+- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
+ signalingThread:(rtc::Thread *)signalingThread
+ workerThread:(rtc::Thread *)workerThread
+ isScreenCast:(BOOL)isScreenCast;
+
@end
NS_ASSUME_NONNULL_END
diff --git a/sdk/objc/api/peerconnection/RTCVideoSource.mm b/sdk/objc/api/peerconnection/RTCVideoSource.mm
index 3a1ea6a..0b1d4a6 100644
--- a/sdk/objc/api/peerconnection/RTCVideoSource.mm
+++ b/sdk/objc/api/peerconnection/RTCVideoSource.mm
@@ -51,8 +51,18 @@
- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
signalingThread:(rtc::Thread *)signalingThread
workerThread:(rtc::Thread *)workerThread {
+ return [self initWithFactory:factory
+ signalingThread:signalingThread
+ workerThread:workerThread
+ isScreenCast:NO];
+}
+
+- (instancetype)initWithFactory:(RTC_OBJC_TYPE(RTCPeerConnectionFactory) *)factory
+ signalingThread:(rtc::Thread *)signalingThread
+ workerThread:(rtc::Thread *)workerThread
+ isScreenCast:(BOOL)isScreenCast {
rtc::scoped_refptr<webrtc::ObjCVideoTrackSource> objCVideoTrackSource(
- new rtc::RefCountedObject<webrtc::ObjCVideoTrackSource>());
+ new rtc::RefCountedObject<webrtc::ObjCVideoTrackSource>(isScreenCast));
return [self initWithFactory:factory
nativeVideoSource:webrtc::VideoTrackSourceProxy::Create(
diff --git a/sdk/objc/native/src/objc_video_track_source.h b/sdk/objc/native/src/objc_video_track_source.h
index dad6544..19a3d6d 100644
--- a/sdk/objc/native/src/objc_video_track_source.h
+++ b/sdk/objc/native/src/objc_video_track_source.h
@@ -27,10 +27,9 @@
class ObjCVideoTrackSource : public rtc::AdaptedVideoTrackSource {
public:
ObjCVideoTrackSource();
+ explicit ObjCVideoTrackSource(bool is_screencast);
explicit ObjCVideoTrackSource(RTCObjCVideoSourceAdapter* adapter);
- // This class can not be used for implementing screen casting. Hopefully, this
- // function will be removed before we add that to iOS/Mac.
bool is_screencast() const override;
// Indicates that the encoder should denoise video before encoding it.
@@ -52,6 +51,7 @@
rtc::TimestampAligner timestamp_aligner_;
RTCObjCVideoSourceAdapter* adapter_;
+ bool is_screencast_;
};
} // namespace webrtc
diff --git a/sdk/objc/native/src/objc_video_track_source.mm b/sdk/objc/native/src/objc_video_track_source.mm
index 85ad087..a973237 100644
--- a/sdk/objc/native/src/objc_video_track_source.mm
+++ b/sdk/objc/native/src/objc_video_track_source.mm
@@ -34,15 +34,18 @@
namespace webrtc {
-ObjCVideoTrackSource::ObjCVideoTrackSource()
- : AdaptedVideoTrackSource(/* required resolution alignment */ 2) {}
+ObjCVideoTrackSource::ObjCVideoTrackSource() : ObjCVideoTrackSource(false) {}
+
+ObjCVideoTrackSource::ObjCVideoTrackSource(bool is_screencast)
+ : AdaptedVideoTrackSource(/* required resolution alignment */ 2),
+ is_screencast_(is_screencast) {}
ObjCVideoTrackSource::ObjCVideoTrackSource(RTCObjCVideoSourceAdapter *adapter) : adapter_(adapter) {
adapter_.objCVideoTrackSource = this;
}
bool ObjCVideoTrackSource::is_screencast() const {
- return false;
+ return is_screencast_;
}
absl::optional<bool> ObjCVideoTrackSource::needs_denoising() const {