Create experimental Obj-C++ API.
This can be used to wrap Objective-C components in C++ classes, so users
can use the WebRTC C++ API directly together with the iOS specific
components provided by our SDK.
Bug: webrtc:8832
Change-Id: I6d34f7ec62d51df8d3a5340a2e17d30ae73e13e8
Reviewed-on: https://webrtc-review.googlesource.com/46162
Commit-Queue: Anders Carlsson <andersc@webrtc.org>
Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
Reviewed-by: Kári Helgason <kthelgason@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21850}
diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactory.mm b/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactory.mm
index ec9d16c..e304068 100644
--- a/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactory.mm
+++ b/sdk/objc/Framework/Classes/PeerConnection/RTCPeerConnectionFactory.mm
@@ -24,8 +24,6 @@
#import "WebRTC/RTCLogging.h"
#import "WebRTC/RTCVideoCodecFactory.h"
#ifndef HAVE_NO_MEDIA
-#include "VideoToolbox/objc_video_decoder_factory.h"
-#include "VideoToolbox/objc_video_encoder_factory.h"
#import "WebRTC/RTCVideoCodecH264.h"
// The no-media version PeerConnectionFactory doesn't depend on these files, but the gn check tool
// is not smart enough to take the #ifdef into account.
@@ -34,6 +32,11 @@
#include "media/engine/convert_legacy_video_factory.h" // nogncheck
#include "modules/audio_device/include/audio_device.h" // nogncheck
#include "modules/audio_processing/include/audio_processing.h" // nogncheck
+
+#include "sdk/objc/Framework/Native/api/video_decoder_factory.h"
+#include "sdk/objc/Framework/Native/api/video_encoder_factory.h"
+#include "sdk/objc/Framework/Native/src/objc_video_decoder_factory.h"
+#include "sdk/objc/Framework/Native/src/objc_video_encoder_factory.h"
#endif
#include "Video/objcvideotracksource.h"
@@ -61,15 +64,16 @@
#elif !defined(USE_BUILTIN_SW_CODECS)
return [self initWithNativeAudioEncoderFactory:webrtc::CreateBuiltinAudioEncoderFactory()
nativeAudioDecoderFactory:webrtc::CreateBuiltinAudioDecoderFactory()
- nativeVideoEncoderFactory:std::unique_ptr<webrtc::VideoEncoderFactory>(
- new webrtc::ObjCVideoEncoderFactory(
- [[RTCVideoEncoderFactoryH264 alloc] init]))
- nativeVideoDecoderFactory:std::unique_ptr<webrtc::VideoDecoderFactory>(
- new webrtc::ObjCVideoDecoderFactory(
- [[RTCVideoDecoderFactoryH264 alloc] init]))
+ nativeVideoEncoderFactory:webrtc::ObjCToNativeVideoEncoderFactory(
+ [[RTCVideoEncoderFactoryH264 alloc] init])
+ nativeVideoDecoderFactory:webrtc::ObjCToNativeVideoDecoderFactory(
+ [[RTCVideoDecoderFactoryH264 alloc] init])
audioDeviceModule:nullptr
audioProcessingModule:nullptr];
#else
+ // Here we construct webrtc::ObjCVideoEncoderFactory directly because we rely
+ // on the fact that they inherit from both webrtc::VideoEncoderFactory and
+ // cricket::WebRtcVideoEncoderFactory.
return [self initWithNativeAudioEncoderFactory:webrtc::CreateBuiltinAudioEncoderFactory()
nativeAudioDecoderFactory:webrtc::CreateBuiltinAudioDecoderFactory()
legacyNativeVideoEncoderFactory:new webrtc::ObjCVideoEncoderFactory(
@@ -89,10 +93,10 @@
std::unique_ptr<webrtc::VideoEncoderFactory> native_encoder_factory;
std::unique_ptr<webrtc::VideoDecoderFactory> native_decoder_factory;
if (encoderFactory) {
- native_encoder_factory.reset(new webrtc::ObjCVideoEncoderFactory(encoderFactory));
+ native_encoder_factory = webrtc::ObjCToNativeVideoEncoderFactory(encoderFactory);
}
if (decoderFactory) {
- native_decoder_factory.reset(new webrtc::ObjCVideoDecoderFactory(decoderFactory));
+ native_decoder_factory = webrtc::ObjCToNativeVideoDecoderFactory(decoderFactory);
}
return [self initWithNativeAudioEncoderFactory:webrtc::CreateBuiltinAudioEncoderFactory()
nativeAudioDecoderFactory:webrtc::CreateBuiltinAudioDecoderFactory()
diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCVideoCodecH264.mm b/sdk/objc/Framework/Classes/PeerConnection/RTCVideoCodecH264.mm
index f862453..402e09f 100644
--- a/sdk/objc/Framework/Classes/PeerConnection/RTCVideoCodecH264.mm
+++ b/sdk/objc/Framework/Classes/PeerConnection/RTCVideoCodecH264.mm
@@ -16,7 +16,6 @@
#import "WebRTC/RTCVideoCodec.h"
#include "rtc_base/timeutils.h"
-#include "sdk/objc/Framework/Classes/Video/objc_frame_buffer.h"
#include "system_wrappers/include/field_trial.h"
const char kHighProfileExperiment[] = "WebRTC-H264HighProfile";
diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCVideoFrame+Private.h b/sdk/objc/Framework/Classes/PeerConnection/RTCVideoFrame+Private.h
index 43d3fbf..7fd2247 100644
--- a/sdk/objc/Framework/Classes/PeerConnection/RTCVideoFrame+Private.h
+++ b/sdk/objc/Framework/Classes/PeerConnection/RTCVideoFrame+Private.h
@@ -13,7 +13,6 @@
#import "WebRTC/RTCVideoFrameBuffer.h"
#include "api/video/video_frame.h"
-#include "sdk/objc/Framework/Classes/Video/objc_frame_buffer.h"
NS_ASSUME_NONNULL_BEGIN
diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCVideoFrame.mm b/sdk/objc/Framework/Classes/PeerConnection/RTCVideoFrame.mm
index 19dd245..f5d7195 100644
--- a/sdk/objc/Framework/Classes/PeerConnection/RTCVideoFrame.mm
+++ b/sdk/objc/Framework/Classes/PeerConnection/RTCVideoFrame.mm
@@ -15,6 +15,8 @@
#include "api/video/video_frame.h"
#include "rtc_base/timeutils.h"
+#include "sdk/objc/Framework/Native/api/video_frame_buffer.h"
+#include "sdk/objc/Framework/Native/src/objc_frame_buffer.h"
id<RTCVideoFrameBuffer> nativeToRtcFrameBuffer(
const rtc::scoped_refptr<webrtc::VideoFrameBuffer> &buffer) {
@@ -104,7 +106,7 @@
- (webrtc::VideoFrame)nativeVideoFrame {
rtc::scoped_refptr<webrtc::VideoFrameBuffer> frameBuffer =
- new rtc::RefCountedObject<webrtc::ObjCFrameBuffer>(self.buffer);
+ webrtc::ObjCToNativeVideoFrameBuffer(self.buffer);
webrtc::VideoFrame videoFrame(frameBuffer,
(webrtc::VideoRotation)self.rotation,
self.timeStampNs / rtc::kNumNanosecsPerMicrosec);
diff --git a/sdk/objc/Framework/Classes/PeerConnection/RTCVideoRendererAdapter.mm b/sdk/objc/Framework/Classes/PeerConnection/RTCVideoRendererAdapter.mm
index 79cc1a7..639d060 100644
--- a/sdk/objc/Framework/Classes/PeerConnection/RTCVideoRendererAdapter.mm
+++ b/sdk/objc/Framework/Classes/PeerConnection/RTCVideoRendererAdapter.mm
@@ -13,7 +13,6 @@
#import "RTCVideoRendererAdapter+Private.h"
#import "WebRTC/RTCVideoFrame.h"
#import "WebRTC/RTCVideoFrameBuffer.h"
-#import "objc_frame_buffer.h"
#include <memory>
diff --git a/sdk/objc/Framework/Classes/Video/avfoundationvideocapturer.mm b/sdk/objc/Framework/Classes/Video/avfoundationvideocapturer.mm
index 77cb88b..50b4f10 100644
--- a/sdk/objc/Framework/Classes/Video/avfoundationvideocapturer.mm
+++ b/sdk/objc/Framework/Classes/Video/avfoundationvideocapturer.mm
@@ -24,7 +24,7 @@
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
#include "rtc_base/thread.h"
-#include "sdk/objc/Framework/Classes/Video/objc_frame_buffer.h"
+#include "sdk/objc/Framework/Native/src/objc_frame_buffer.h"
namespace webrtc {
diff --git a/sdk/objc/Framework/Classes/Video/objc_frame_buffer.h b/sdk/objc/Framework/Classes/Video/objc_frame_buffer.h
deleted file mode 100644
index 85a89e6..0000000
--- a/sdk/objc/Framework/Classes/Video/objc_frame_buffer.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright 2017 The WebRTC project authors. All Rights Reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
-
-#ifndef SDK_OBJC_FRAMEWORK_CLASSES_VIDEO_OBJC_FRAME_BUFFER_H_
-#define SDK_OBJC_FRAMEWORK_CLASSES_VIDEO_OBJC_FRAME_BUFFER_H_
-
-#import <CoreVideo/CoreVideo.h>
-
-#include "common_video/include/video_frame_buffer.h"
-
-@protocol RTCVideoFrameBuffer;
-
-namespace webrtc {
-
-class ObjCFrameBuffer : public VideoFrameBuffer {
- public:
- explicit ObjCFrameBuffer(id<RTCVideoFrameBuffer>);
- ~ObjCFrameBuffer() override;
-
- Type type() const override;
-
- int width() const override;
- int height() const override;
-
- rtc::scoped_refptr<I420BufferInterface> ToI420() override;
-
- id<RTCVideoFrameBuffer> wrapped_frame_buffer() const;
-
- private:
- id<RTCVideoFrameBuffer> frame_buffer_;
- int width_;
- int height_;
-};
-
-} // namespace webrtc
-
-#endif // SDK_OBJC_FRAMEWORK_CLASSES_VIDEO_OBJC_FRAME_BUFFER_H_
diff --git a/sdk/objc/Framework/Classes/Video/objc_frame_buffer.mm b/sdk/objc/Framework/Classes/Video/objc_frame_buffer.mm
deleted file mode 100644
index 3658562..0000000
--- a/sdk/objc/Framework/Classes/Video/objc_frame_buffer.mm
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright 2017 The WebRTC project authors. All Rights Reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
-
-#include "sdk/objc/Framework/Classes/Video/objc_frame_buffer.h"
-
-#import "WebRTC/RTCVideoFrameBuffer.h"
-
-namespace webrtc {
-
-namespace {
-
-/** ObjCFrameBuffer that conforms to I420BufferInterface by wrapping RTCI420Buffer */
-class ObjCI420FrameBuffer : public I420BufferInterface {
- public:
- explicit ObjCI420FrameBuffer(id<RTCI420Buffer> frame_buffer)
- : frame_buffer_(frame_buffer), width_(frame_buffer.width), height_(frame_buffer.height) {}
- ~ObjCI420FrameBuffer() override{};
-
- int width() const override { return width_; }
-
- int height() const override { return height_; }
-
- const uint8_t* DataY() const override { return frame_buffer_.dataY; }
-
- const uint8_t* DataU() const override { return frame_buffer_.dataU; }
-
- const uint8_t* DataV() const override { return frame_buffer_.dataV; }
-
- int StrideY() const override { return frame_buffer_.strideY; }
-
- int StrideU() const override { return frame_buffer_.strideU; }
-
- int StrideV() const override { return frame_buffer_.strideV; }
-
- private:
- id<RTCI420Buffer> frame_buffer_;
- int width_;
- int height_;
-};
-
-} // namespace
-
-ObjCFrameBuffer::ObjCFrameBuffer(id<RTCVideoFrameBuffer> frame_buffer)
- : frame_buffer_(frame_buffer), width_(frame_buffer.width), height_(frame_buffer.height) {}
-
-ObjCFrameBuffer::~ObjCFrameBuffer() {}
-
-VideoFrameBuffer::Type ObjCFrameBuffer::type() const {
- return Type::kNative;
-}
-
-int ObjCFrameBuffer::width() const {
- return width_;
-}
-
-int ObjCFrameBuffer::height() const {
- return height_;
-}
-
-rtc::scoped_refptr<I420BufferInterface> ObjCFrameBuffer::ToI420() {
- rtc::scoped_refptr<I420BufferInterface> buffer =
- new rtc::RefCountedObject<ObjCI420FrameBuffer>([frame_buffer_ toI420]);
-
- return buffer;
-}
-
-id<RTCVideoFrameBuffer> ObjCFrameBuffer::wrapped_frame_buffer() const {
- return frame_buffer_;
-}
-
-} // namespace webrtc
diff --git a/sdk/objc/Framework/Classes/Video/objcvideotracksource.mm b/sdk/objc/Framework/Classes/Video/objcvideotracksource.mm
index eca8852..d67f610 100644
--- a/sdk/objc/Framework/Classes/Video/objcvideotracksource.mm
+++ b/sdk/objc/Framework/Classes/Video/objcvideotracksource.mm
@@ -14,7 +14,7 @@
#import "WebRTC/RTCVideoFrameBuffer.h"
#include "api/video/i420_buffer.h"
-#include "sdk/objc/Framework/Classes/Video/objc_frame_buffer.h"
+#include "sdk/objc/Framework/Native/src/objc_frame_buffer.h"
namespace webrtc {