Add a webrtc{en,de}coderfactory implementation for VideoToolbox
This CL removes the coupling of the VideoToolbox h264 implementation
to the generic h264 code. The files have been moved into sdb/obj/Framework
and all dependency on them has been removed from the rest of WebRTC.
We now add it as an external encoder via a factory supplied to the
CreatePeerConnectionFactory call. This also brings the iOS implementation
closer to what we do on Android for MediaCodec.
BUG=webrtc:6619
Review-Url: https://codereview.webrtc.org/2463313002
Cr-Commit-Position: refs/heads/master@{#14953}
diff --git a/webrtc/modules/BUILD.gn b/webrtc/modules/BUILD.gn
index 13f74f8..8321bcd 100644
--- a/webrtc/modules/BUILD.gn
+++ b/webrtc/modules/BUILD.gn
@@ -705,10 +705,7 @@
"//build/config/compiler:enable_arc",
]
- sources += [
- "audio_device/ios/objc/RTCAudioSessionTest.mm",
- "video_coding/codecs/h264/h264_video_toolbox_nalu_unittest.cc",
- ]
+ sources += [ "audio_device/ios/objc/RTCAudioSessionTest.mm" ]
if (target_cpu != "x64") {
sources += [ "audio_device/ios/audio_device_unittest_ios.cc" ]
diff --git a/webrtc/modules/video_coding/BUILD.gn b/webrtc/modules/video_coding/BUILD.gn
index e567b89..9bd746b 100644
--- a/webrtc/modules/video_coding/BUILD.gn
+++ b/webrtc/modules/video_coding/BUILD.gn
@@ -141,11 +141,6 @@
"../../system_wrappers",
]
- if (is_ios) {
- sources += [ "codecs/h264/h264_objc.mm" ]
- deps += [ ":webrtc_h264_video_toolbox" ]
- }
-
if (rtc_use_h264) {
defines += [ "WEBRTC_USE_H264" ]
if (rtc_initialize_ffmpeg) {
@@ -165,60 +160,6 @@
}
}
-if (is_ios) {
- config("webrtc_h264_video_toolbox_warnings_config") {
- if (is_clang) {
- # TODO(tkchin): Make webrtc_h264_video_toolbox compile with the standard set
- # of warnings.
- # See https://bugs.chromium.org/p/webrtc/issues/detail?id=6307
- cflags = [ "-Wno-thread-safety-analysis" ]
- }
- }
-
- rtc_static_library("webrtc_h264_video_toolbox") {
- sources = [
- "codecs/h264/h264_video_toolbox_decoder.cc",
- "codecs/h264/h264_video_toolbox_decoder.h",
- "codecs/h264/h264_video_toolbox_encoder.h",
- "codecs/h264/h264_video_toolbox_encoder.mm",
- "codecs/h264/h264_video_toolbox_nalu.cc",
- "codecs/h264/h264_video_toolbox_nalu.h",
- ]
-
- configs += [
- ":webrtc_h264_video_toolbox_warnings_config",
- "../..:common_objc",
- "//build/config/compiler:enable_arc",
- ]
-
- deps = [
- "../../sdk:rtc_sdk_common_objc",
- ]
-
- libs = [
- "CoreFoundation.framework",
- "CoreMedia.framework",
- "CoreVideo.framework",
- "VideoToolbox.framework",
- ]
-
- if (!build_with_chromium && is_clang) {
- # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
- suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
- }
-
- if (rtc_build_libyuv) {
- deps += [ "$rtc_libyuv_dir" ]
- public_deps = [
- "$rtc_libyuv_dir",
- ]
- } else {
- # Need to add a directory normally exported by libyuv.
- include_dirs = [ "$rtc_libyuv_dir/include" ]
- }
- }
-}
-
rtc_static_library("webrtc_i420") {
sources = [
"codecs/i420/i420.cc",
diff --git a/webrtc/modules/video_coding/codecs/h264/h264.cc b/webrtc/modules/video_coding/codecs/h264/h264.cc
index 1c0fc70..bbff225 100644
--- a/webrtc/modules/video_coding/codecs/h264/h264.cc
+++ b/webrtc/modules/video_coding/codecs/h264/h264.cc
@@ -15,10 +15,6 @@
#include "webrtc/modules/video_coding/codecs/h264/h264_decoder_impl.h"
#include "webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.h"
#endif
-#if defined(WEBRTC_IOS)
-#include "webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_decoder.h"
-#include "webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.h"
-#endif
#include "webrtc/base/checks.h"
#include "webrtc/base/logging.h"
@@ -39,20 +35,8 @@
#endif
}
-// We need this file to be C++ only so it will compile properly for all
-// platforms. In order to write ObjC specific implementations we use private
-// externs. This function is defined in h264.mm.
-#if defined(WEBRTC_IOS)
-extern bool IsH264CodecSupportedObjC();
-#endif
-
// If any H.264 codec is supported (iOS HW or OpenH264/FFmpeg).
bool IsH264CodecSupported() {
-#if defined(WEBRTC_IOS) && defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED)
- if (IsH264CodecSupportedObjC()) {
- return true;
- }
-#endif
#if defined(WEBRTC_USE_H264)
return g_rtc_use_h264;
#else
@@ -62,12 +46,6 @@
H264Encoder* H264Encoder::Create() {
RTC_DCHECK(H264Encoder::IsSupported());
-#if defined(WEBRTC_IOS) && defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED)
- if (IsH264CodecSupportedObjC()) {
- LOG(LS_INFO) << "Creating H264VideoToolboxEncoder.";
- return new H264VideoToolboxEncoder();
- }
-#endif
#if defined(WEBRTC_USE_H264)
RTC_CHECK(g_rtc_use_h264);
LOG(LS_INFO) << "Creating H264EncoderImpl.";
@@ -84,12 +62,6 @@
H264Decoder* H264Decoder::Create() {
RTC_DCHECK(H264Decoder::IsSupported());
-#if defined(WEBRTC_IOS) && defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED)
- if (IsH264CodecSupportedObjC()) {
- LOG(LS_INFO) << "Creating H264VideoToolboxDecoder.";
- return new H264VideoToolboxDecoder();
- }
-#endif
#if defined(WEBRTC_USE_H264)
RTC_CHECK(g_rtc_use_h264);
LOG(LS_INFO) << "Creating H264DecoderImpl.";
diff --git a/webrtc/modules/video_coding/codecs/h264/h264.gypi b/webrtc/modules/video_coding/codecs/h264/h264.gypi
index 5d92823..2a10384 100644
--- a/webrtc/modules/video_coding/codecs/h264/h264.gypi
+++ b/webrtc/modules/video_coding/codecs/h264/h264.gypi
@@ -15,14 +15,6 @@
'target_name': 'webrtc_h264',
'type': 'static_library',
'conditions': [
- ['OS=="ios"', {
- 'dependencies': [
- 'webrtc_h264_video_toolbox',
- ],
- 'sources': [
- 'h264_objc.mm',
- ],
- }],
# TODO(hbos): Consider renaming this flag and the below macro to
# something which helps distinguish OpenH264/FFmpeg from other H264
# implementations.
@@ -56,41 +48,4 @@
],
}, # webrtc_h264
],
- 'conditions': [
- ['OS=="ios"', {
- 'targets': [
- {
- 'target_name': 'webrtc_h264_video_toolbox',
- 'type': 'static_library',
- 'includes': [ '../../../../build/objc_common.gypi' ],
- 'dependencies': [
- '<(webrtc_root)/sdk/sdk.gyp:rtc_sdk_common_objc',
- ],
- 'link_settings': {
- 'xcode_settings': {
- 'OTHER_LDFLAGS': [
- '-framework CoreFoundation',
- '-framework CoreMedia',
- '-framework CoreVideo',
- '-framework VideoToolbox',
- ],
- },
- },
- 'sources': [
- 'h264_video_toolbox_decoder.cc',
- 'h264_video_toolbox_decoder.h',
- 'h264_video_toolbox_encoder.h',
- 'h264_video_toolbox_encoder.mm',
- 'h264_video_toolbox_nalu.cc',
- 'h264_video_toolbox_nalu.h',
- ],
- 'conditions': [
- ['build_libyuv==1', {
- 'dependencies': ['<(DEPTH)/third_party/libyuv/libyuv.gyp:libyuv'],
- }],
- ],
- }, # webrtc_h264_video_toolbox
- ], # targets
- }], # OS=="ios"
- ], # conditions
}
diff --git a/webrtc/modules/video_coding/codecs/h264/h264_objc.mm b/webrtc/modules/video_coding/codecs/h264/h264_objc.mm
deleted file mode 100644
index 9a6582d..0000000
--- a/webrtc/modules/video_coding/codecs/h264/h264_objc.mm
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (c) 2015 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 "webrtc/modules/video_coding/codecs/h264/include/h264.h"
-
-#if defined(WEBRTC_IOS)
-#import <UIKit/UIKit.h>
-#endif
-
-namespace webrtc {
-
-bool IsH264CodecSupportedObjC() {
-#if defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED) && \
- defined(WEBRTC_IOS)
- // Supported on iOS8+.
- return [[[UIDevice currentDevice] systemVersion] doubleValue] >= 8.0;
-#else
- // TODO(tkchin): Support OS/X once we stop mixing libstdc++ and libc++ on
- // OSX 10.9.
- return false;
-#endif
-}
-
-} // namespace webrtc
diff --git a/webrtc/sdk/BUILD.gn b/webrtc/sdk/BUILD.gn
index 0779291..d54961c 100644
--- a/webrtc/sdk/BUILD.gn
+++ b/webrtc/sdk/BUILD.gn
@@ -30,6 +30,14 @@
"objc/Framework/Headers",
]
}
+ config("webrtc_h264_video_toolbox_warnings_config") {
+ if (is_clang) {
+ # TODO(tkchin): Make webrtc_h264_video_toolbox compile with the standard set
+ # of warnings.
+ # See https://bugs.chromium.org/p/webrtc/issues/detail?id=6307
+ cflags = [ "-Wno-thread-safety-analysis" ]
+ }
+ }
rtc_static_library("rtc_sdk_common_objc") {
deps = [
@@ -143,6 +151,8 @@
"objc/Framework/Classes/RTCVideoTrack.mm",
"objc/Framework/Classes/avfoundationvideocapturer.h",
"objc/Framework/Classes/avfoundationvideocapturer.mm",
+ "objc/Framework/Classes/videotoolboxvideocodecfactory.cc",
+ "objc/Framework/Classes/videotoolboxvideocodecfactory.h",
"objc/Framework/Headers/WebRTC/RTCAVFoundationVideoSource.h",
"objc/Framework/Headers/WebRTC/RTCAudioSource.h",
"objc/Framework/Headers/WebRTC/RTCAudioTrack.h",
@@ -182,6 +192,9 @@
"OpenGLES.framework",
"QuartzCore.framework",
]
+ deps = [
+ ":webrtc_h264_video_toolbox",
+ ]
}
if (is_mac) {
@@ -193,6 +206,7 @@
"CoreMedia.framework",
"OpenGL.framework",
]
+ deps = []
}
configs += [
@@ -209,7 +223,7 @@
libs += [ "AVFoundation.framework" ]
- deps = [
+ deps += [
":rtc_sdk_common_objc",
"../api:libjingle_peerconnection",
]
@@ -351,8 +365,51 @@
complete_static_lib = true
deps = [
":rtc_sdk_peerconnection_objc",
- "../system_wrappers:field_trial_default",
- "../system_wrappers:metrics_default",
+ "//webrtc/system_wrappers:field_trial_default",
+ "//webrtc/system_wrappers:metrics_default",
]
}
+
+ rtc_static_library("webrtc_h264_video_toolbox") {
+ sources = [
+ "objc/Framework/Classes/h264_video_toolbox_decoder.cc",
+ "objc/Framework/Classes/h264_video_toolbox_decoder.h",
+ "objc/Framework/Classes/h264_video_toolbox_encoder.h",
+ "objc/Framework/Classes/h264_video_toolbox_encoder.mm",
+ "objc/Framework/Classes/h264_video_toolbox_nalu.cc",
+ "objc/Framework/Classes/h264_video_toolbox_nalu.h",
+ ]
+
+ configs += [
+ ":webrtc_h264_video_toolbox_warnings_config",
+ "//webrtc:common_objc",
+ "//build/config/compiler:enable_arc",
+ ]
+
+ deps = [
+ ":rtc_sdk_common_objc",
+ ]
+
+ libs = [
+ "CoreFoundation.framework",
+ "CoreMedia.framework",
+ "CoreVideo.framework",
+ "VideoToolbox.framework",
+ ]
+
+ if (!build_with_chromium && is_clang) {
+ # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
+ suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
+ }
+
+ if (rtc_build_libyuv) {
+ deps += [ "$rtc_libyuv_dir" ]
+ public_deps = [
+ "$rtc_libyuv_dir",
+ ]
+ } else {
+ # Need to add a directory normally exported by libyuv.
+ include_dirs = [ "$rtc_libyuv_dir/include" ]
+ }
+ }
}
diff --git a/webrtc/sdk/DEPS b/webrtc/sdk/DEPS
index d6e53d5..137f67a 100644
--- a/webrtc/sdk/DEPS
+++ b/webrtc/sdk/DEPS
@@ -2,6 +2,8 @@
"+WebRTC",
"+webrtc/api",
"+webrtc/common_video/include",
+ "+webrtc/common_video/h264",
"+webrtc/media",
+ "+webrtc/modules/video_coding",
"+webrtc/system_wrappers",
]
diff --git a/webrtc/sdk/objc/Framework/Classes/RTCPeerConnectionFactory.mm b/webrtc/sdk/objc/Framework/Classes/RTCPeerConnectionFactory.mm
index 9f24aec..4f542a9 100644
--- a/webrtc/sdk/objc/Framework/Classes/RTCPeerConnectionFactory.mm
+++ b/webrtc/sdk/objc/Framework/Classes/RTCPeerConnectionFactory.mm
@@ -21,6 +21,8 @@
#import "RTCVideoTrack+Private.h"
#import "WebRTC/RTCLogging.h"
+#include "videotoolboxvideocodecfactory.h"
+
@implementation RTCPeerConnectionFactory {
std::unique_ptr<rtc::Thread> _networkThread;
std::unique_ptr<rtc::Thread> _workerThread;
@@ -44,9 +46,14 @@
result = _signalingThread->Start();
NSAssert(result, @"Failed to start signaling thread.");
+ const auto encoder_factory = new webrtc::VideoToolboxVideoEncoderFactory();
+ const auto decoder_factory = new webrtc::VideoToolboxVideoDecoderFactory();
+
+ // Ownership of encoder/decoder factories is passed on to the
+ // peerconnectionfactory, that handles deleting them.
_nativeFactory = webrtc::CreatePeerConnectionFactory(
_networkThread.get(), _workerThread.get(), _signalingThread.get(),
- nullptr, nullptr, nullptr);
+ nullptr, encoder_factory, decoder_factory);
NSAssert(_nativeFactory, @"Failed to initialize PeerConnectionFactory!");
}
return self;
diff --git a/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_decoder.cc b/webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_decoder.cc
similarity index 97%
rename from webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_decoder.cc
rename to webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_decoder.cc
index 18820d3..31c8baf 100644
--- a/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_decoder.cc
+++ b/webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_decoder.cc
@@ -9,9 +9,7 @@
*
*/
-#include "webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_decoder.h"
-
-#if defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED)
+#include "webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_decoder.h"
#include <memory>
@@ -22,7 +20,7 @@
#include "webrtc/base/checks.h"
#include "webrtc/base/logging.h"
#include "webrtc/common_video/include/corevideo_frame_buffer.h"
-#include "webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_nalu.h"
+#include "webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_nalu.h"
#include "webrtc/video_frame.h"
namespace internal {
@@ -277,5 +275,3 @@
}
} // namespace webrtc
-
-#endif // defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED)
diff --git a/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_decoder.h b/webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_decoder.h
similarity index 84%
rename from webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_decoder.h
rename to webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_decoder.h
index 1fbccda..d81c112 100644
--- a/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_decoder.h
+++ b/webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_decoder.h
@@ -9,13 +9,11 @@
*
*/
-#ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_H264_H264_VIDEO_TOOLBOX_DECODER_H_
-#define WEBRTC_MODULES_VIDEO_CODING_CODECS_H264_H264_VIDEO_TOOLBOX_DECODER_H_
+#ifndef WEBRTC_SDK_OBJC_FRAMEWORK_CLASSES_H264_VIDEO_TOOLBOX_DECODER_H_
+#define WEBRTC_SDK_OBJC_FRAMEWORK_CLASSES_H264_VIDEO_TOOLBOX_DECODER_H_
#include "webrtc/modules/video_coding/codecs/h264/include/h264.h"
-#if defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED)
-
#include <VideoToolbox/VideoToolbox.h>
// This file provides a H264 encoder implementation using the VideoToolbox
@@ -58,5 +56,4 @@
} // namespace webrtc
-#endif // defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED)
-#endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_H264_H264_VIDEO_TOOLBOX_DECODER_H_
+#endif // WEBRTC_SDK_OBJC_FRAMEWORK_CLASSES_H264_VIDEO_TOOLBOX_DECODER_H_
diff --git a/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.h b/webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_encoder.h
similarity index 90%
rename from webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.h
rename to webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_encoder.h
index 2b38756..3acdf64 100644
--- a/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.h
+++ b/webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_encoder.h
@@ -9,8 +9,8 @@
*
*/
-#ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_H264_H264_VIDEO_TOOLBOX_ENCODER_H_
-#define WEBRTC_MODULES_VIDEO_CODING_CODECS_H264_H264_VIDEO_TOOLBOX_ENCODER_H_
+#ifndef WEBRTC_SDK_OBJC_FRAMEWORK_CLASSES_H264_VIDEO_TOOLBOX_ENCODER_H_
+#define WEBRTC_SDK_OBJC_FRAMEWORK_CLASSES_H264_VIDEO_TOOLBOX_ENCODER_H_
#include "webrtc/base/criticalsection.h"
#include "webrtc/common_video/h264/h264_bitstream_parser.h"
@@ -19,8 +19,6 @@
#include "webrtc/modules/video_coding/codecs/h264/include/h264.h"
#include "webrtc/modules/video_coding/utility/quality_scaler.h"
-#if defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED)
-
#include <VideoToolbox/VideoToolbox.h>
#include <vector>
@@ -94,5 +92,4 @@
} // namespace webrtc
-#endif // defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED)
-#endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_H264_H264_VIDEO_TOOLBOX_ENCODER_H_
+#endif // WEBRTC_SDK_OBJC_FRAMEWORK_CLASSES_H264_VIDEO_TOOLBOX_ENCODER_H_
diff --git a/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm b/webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_encoder.mm
similarity index 98%
rename from webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm
rename to webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_encoder.mm
index 538734b..d3ce820 100644
--- a/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm
+++ b/webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_encoder.mm
@@ -9,9 +9,7 @@
*
*/
-#include "webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.h"
-
-#if defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED)
+#include "webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_encoder.h"
#include <memory>
#include <string>
@@ -25,7 +23,7 @@
#include "webrtc/base/checks.h"
#include "webrtc/base/logging.h"
#include "webrtc/common_video/include/corevideo_frame_buffer.h"
-#include "webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_nalu.h"
+#include "webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_nalu.h"
#include "webrtc/system_wrappers/include/clock.h"
namespace internal {
@@ -660,5 +658,3 @@
}
} // namespace webrtc
-
-#endif // defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED)
diff --git a/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_nalu.cc b/webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_nalu.cc
similarity index 98%
rename from webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_nalu.cc
rename to webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_nalu.cc
index 357b4d4..0d79758 100644
--- a/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_nalu.cc
+++ b/webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_nalu.cc
@@ -9,9 +9,7 @@
*
*/
-#include "webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_nalu.h"
-
-#if defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED)
+#include "webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_nalu.h"
#include <CoreFoundation/CoreFoundation.h>
#include <memory>
@@ -365,5 +363,3 @@
}
} // namespace webrtc
-
-#endif // defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED)
diff --git a/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_nalu.h b/webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_nalu.h
similarity index 92%
rename from webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_nalu.h
rename to webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_nalu.h
index 7862c3b..23e9f7f 100644
--- a/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_nalu.h
+++ b/webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_nalu.h
@@ -9,13 +9,11 @@
*
*/
-#ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_H264_H264_VIDEO_TOOLBOX_NALU_H_
-#define WEBRTC_MODULES_VIDEO_CODING_CODECS_H264_H264_VIDEO_TOOLBOX_NALU_H_
+#ifndef WEBRTC_SDK_OBJC_FRAMEWORK_CLASSES_H264_VIDEO_TOOLBOX_NALU_H_
+#define WEBRTC_SDK_OBJC_FRAMEWORK_CLASSES_H264_VIDEO_TOOLBOX_NALU_H_
#include "webrtc/modules/video_coding/codecs/h264/include/h264.h"
-#if defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED)
-
#include <CoreMedia/CoreMedia.h>
#include <vector>
@@ -111,5 +109,4 @@
} // namespace webrtc
-#endif // defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED)
-#endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_H264_H264_VIDEO_TOOLBOX_NALU_H_
+#endif // WEBRTC_SDK_OBJC_FRAMEWORK_CLASSES_H264_VIDEO_TOOLBOX_NALU_H_
diff --git a/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_nalu_unittest.cc b/webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_nalu_unittest.cc
similarity index 97%
rename from webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_nalu_unittest.cc
rename to webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_nalu_unittest.cc
index df71f54..bc4efa04 100644
--- a/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_nalu_unittest.cc
+++ b/webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_nalu_unittest.cc
@@ -12,11 +12,9 @@
#include <memory>
#include "webrtc/base/arraysize.h"
-#include "webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_nalu.h"
+#include "webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_nalu.h"
#include "webrtc/test/gtest.h"
-#if defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED)
-
namespace webrtc {
static const uint8_t NALU_TEST_DATA_0[] = {0xAA, 0xBB, 0xCC};
@@ -204,5 +202,3 @@
}
} // namespace webrtc
-
-#endif // WEBRTC_VIDEO_TOOLBOX_SUPPORTED
diff --git a/webrtc/sdk/objc/Framework/Classes/videotoolboxvideocodecfactory.cc b/webrtc/sdk/objc/Framework/Classes/videotoolboxvideocodecfactory.cc
new file mode 100644
index 0000000..b7a5141
--- /dev/null
+++ b/webrtc/sdk/objc/Framework/Classes/videotoolboxvideocodecfactory.cc
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2015 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 "webrtc/sdk/objc/Framework/Classes/videotoolboxvideocodecfactory.h"
+
+#include "webrtc/base/logging.h"
+#include "webrtc/media/base/codec.h"
+#if defined(WEBRTC_IOS)
+#include "webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_encoder.h"
+#include "webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_decoder.h"
+#endif
+
+// TODO(kthelgason): delete this when CreateVideoDecoder takes
+// a cricket::VideoCodec instead of webrtc::VideoCodecType.
+static const char* NameFromCodecType(webrtc::VideoCodecType type) {
+ switch (type) {
+ case webrtc::kVideoCodecVP8:
+ return cricket::kVp8CodecName;
+ case webrtc::kVideoCodecVP9:
+ return cricket::kVp9CodecName;
+ case webrtc::kVideoCodecH264:
+ return cricket::kH264CodecName;
+ default:
+ return "Unknown codec";
+ }
+}
+
+namespace webrtc {
+
+// VideoToolboxVideoEncoderFactory
+
+VideoToolboxVideoEncoderFactory::VideoToolboxVideoEncoderFactory() {
+// Hardware H264 encoding only supported on iOS for now.
+#if defined(WEBRTC_IOS)
+ supported_codecs_.push_back(cricket::VideoCodec(cricket::kH264CodecName));
+#endif
+}
+
+VideoToolboxVideoEncoderFactory::~VideoToolboxVideoEncoderFactory() {}
+
+VideoEncoder* VideoToolboxVideoEncoderFactory::CreateVideoEncoder(
+ const cricket::VideoCodec& codec) {
+#if defined(WEBRTC_IOS)
+ if (IsCodecSupported(supported_codecs_, codec)) {
+ LOG(LS_INFO) << "Creating HW encoder for " << codec.name;
+ return new H264VideoToolboxEncoder();
+ }
+#endif
+ LOG(LS_INFO) << "No HW encoder found for codec " << codec.name;
+ return nullptr;
+}
+
+void VideoToolboxVideoEncoderFactory::DestroyVideoEncoder(
+ VideoEncoder* encoder) {
+#if defined(WEBRTC_IOS)
+ delete encoder;
+ encoder = nullptr;
+#endif
+}
+
+const std::vector<cricket::VideoCodec>&
+VideoToolboxVideoEncoderFactory::supported_codecs() const {
+ return supported_codecs_;
+}
+
+// VideoToolboxVideoDecoderFactory
+
+VideoToolboxVideoDecoderFactory::VideoToolboxVideoDecoderFactory() {
+#if defined(WEBRTC_IOS)
+ supported_codecs_.push_back(cricket::VideoCodec("H264"));
+#endif
+}
+
+VideoToolboxVideoDecoderFactory::~VideoToolboxVideoDecoderFactory() {}
+
+VideoDecoder* VideoToolboxVideoDecoderFactory::CreateVideoDecoder(
+ VideoCodecType type) {
+ const auto codec = cricket::VideoCodec(NameFromCodecType(type));
+#if defined(WEBRTC_IOS)
+ if (IsCodecSupported(supported_codecs_, codec)) {
+ LOG(LS_INFO) << "Creating HW decoder for " << codec.name;
+ return new H264VideoToolboxDecoder();
+ }
+#endif
+ LOG(LS_INFO) << "No HW decoder found for codec " << codec.name;
+ return nullptr;
+}
+
+void VideoToolboxVideoDecoderFactory::DestroyVideoDecoder(
+ VideoDecoder* decoder) {
+#if defined(WEBRTC_IOS)
+ delete decoder;
+ decoder = nullptr;
+#endif
+}
+
+} // namespace webrtc
diff --git a/webrtc/sdk/objc/Framework/Classes/videotoolboxvideocodecfactory.h b/webrtc/sdk/objc/Framework/Classes/videotoolboxvideocodecfactory.h
new file mode 100644
index 0000000..5100710
--- /dev/null
+++ b/webrtc/sdk/objc/Framework/Classes/videotoolboxvideocodecfactory.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2016 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 WEBRTC_SDK_OBJC_FRAMEWORK_CLASSES_VIDEOTOOLBOXVIDEOCODECFACTORY_H_
+#define WEBRTC_SDK_OBJC_FRAMEWORK_CLASSES_VIDEOTOOLBOXVIDEOCODECFACTORY_H_
+
+#include "webrtc/media/engine/webrtcvideoencoderfactory.h"
+#include "webrtc/media/engine/webrtcvideodecoderfactory.h"
+
+namespace webrtc {
+
+class VideoToolboxVideoEncoderFactory
+ : public cricket::WebRtcVideoEncoderFactory {
+ public:
+ VideoToolboxVideoEncoderFactory();
+ ~VideoToolboxVideoEncoderFactory();
+
+ // WebRtcVideoEncoderFactory implementation.
+ VideoEncoder* CreateVideoEncoder(const cricket::VideoCodec& codec) override;
+ void DestroyVideoEncoder(VideoEncoder* encoder) override;
+ const std::vector<cricket::VideoCodec>& supported_codecs() const override;
+
+ private:
+ std::vector<cricket::VideoCodec> supported_codecs_;
+};
+
+class VideoToolboxVideoDecoderFactory
+ : public cricket::WebRtcVideoDecoderFactory {
+ public:
+ VideoToolboxVideoDecoderFactory();
+ ~VideoToolboxVideoDecoderFactory();
+
+ // WebRtcVideoDecoderFactory implementation.
+ VideoDecoder* CreateVideoDecoder(VideoCodecType type) override;
+ void DestroyVideoDecoder(VideoDecoder* decoder) override;
+
+ private:
+ std::vector<cricket::VideoCodec> supported_codecs_;
+};
+
+} // namespace webrtc
+
+#endif // WEBRTC_SDK_OBJC_FRAMEWORK_CLASSES_VIDEOTOOLBOXVIDEOCODECFACTORY_H_