diff --git a/sdk/objc/Framework/Classes/VideoToolbox/objc_video_decoder_factory.h b/sdk/objc/Framework/Classes/VideoToolbox/objc_video_decoder_factory.h deleted file mode 100644 index a0106ff83f..0000000000 --- a/sdk/objc/Framework/Classes/VideoToolbox/objc_video_decoder_factory.h +++ /dev/null @@ -1,50 +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_PEERCONNECTION_OBJC_VIDEO_DECODER_FACTORY_H_ -#define SDK_OBJC_FRAMEWORK_CLASSES_PEERCONNECTION_OBJC_VIDEO_DECODER_FACTORY_H_ - -#include "api/video_codecs/video_decoder_factory.h" -#include "media/base/codec.h" -#include "media/engine/webrtcvideodecoderfactory.h" - -@protocol RTCVideoDecoderFactory; - -namespace webrtc { - -// TODO(andersc): Remove the inheritance from cricket::WebRtcVideoDecoderFactory -// when the legacy path in [RTCPeerConnectionFactory init] is no longer needed. -class ObjCVideoDecoderFactory : public VideoDecoderFactory, - public cricket::WebRtcVideoDecoderFactory { - public: - explicit ObjCVideoDecoderFactory(id); - ~ObjCVideoDecoderFactory(); - - id wrapped_decoder_factory() const; - - std::vector GetSupportedFormats() const override; - std::unique_ptr CreateVideoDecoder( - const SdpVideoFormat& format) override; - - // Needed for WebRtcVideoDecoderFactory interface. - webrtc::VideoDecoder* CreateVideoDecoderWithParams( - const cricket::VideoCodec& codec, - cricket::VideoDecoderParams params) override; - webrtc::VideoDecoder* CreateVideoDecoder( - webrtc::VideoCodecType type) override; - void DestroyVideoDecoder(webrtc::VideoDecoder* decoder) override; - - private: - id decoder_factory_; -}; - -} // namespace webrtc - -#endif // SDK_OBJC_FRAMEWORK_CLASSES_PEERCONNECTION_OBJC_VIDEO_DECODER_FACTORY_H_ diff --git a/sdk/objc/Framework/Classes/VideoToolbox/objc_video_decoder_factory.mm b/sdk/objc/Framework/Classes/VideoToolbox/objc_video_decoder_factory.mm deleted file mode 100644 index ab615a3968..0000000000 --- a/sdk/objc/Framework/Classes/VideoToolbox/objc_video_decoder_factory.mm +++ /dev/null @@ -1,154 +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/VideoToolbox/objc_video_decoder_factory.h" - -#import "NSString+StdString.h" -#import "RTCVideoCodec+Private.h" -#import "RTCWrappedNativeVideoDecoder.h" -#import "WebRTC/RTCVideoCodec.h" -#import "WebRTC/RTCVideoCodecFactory.h" -#import "WebRTC/RTCVideoCodecH264.h" -#import "WebRTC/RTCVideoFrame.h" -#import "WebRTC/RTCVideoFrameBuffer.h" - -#include "api/video_codecs/sdp_video_format.h" -#include "api/video_codecs/video_decoder.h" -#include "modules/include/module_common_types.h" -#include "modules/video_coding/include/video_codec_interface.h" -#include "modules/video_coding/include/video_error_codes.h" -#include "rtc_base/logging.h" -#include "rtc_base/timeutils.h" -#include "sdk/objc/Framework/Classes/Video/objc_frame_buffer.h" - -namespace webrtc { - -namespace { -class ObjCVideoDecoder : public VideoDecoder { - public: - ObjCVideoDecoder(id decoder) - : decoder_(decoder), implementation_name_([decoder implementationName].stdString) {} - - int32_t InitDecode(const VideoCodec *codec_settings, int32_t number_of_cores) { - RTCVideoEncoderSettings *settings = - [[RTCVideoEncoderSettings alloc] initWithNativeVideoCodec:codec_settings]; - return [decoder_ startDecodeWithSettings:settings numberOfCores:number_of_cores]; - } - - int32_t Decode(const EncodedImage &input_image, - bool missing_frames, - const RTPFragmentationHeader *fragmentation, - const CodecSpecificInfo *codec_specific_info = NULL, - int64_t render_time_ms = -1) { - RTCEncodedImage *encodedImage = - [[RTCEncodedImage alloc] initWithNativeEncodedImage:input_image]; - RTCRtpFragmentationHeader *header = - [[RTCRtpFragmentationHeader alloc] initWithNativeFragmentationHeader:fragmentation]; - - // webrtc::CodecSpecificInfo only handles a hard coded list of codecs - id rtcCodecSpecificInfo = nil; - if (codec_specific_info) { - if (codec_specific_info->codecType == kVideoCodecH264) { - RTCCodecSpecificInfoH264 *h264Info = [[RTCCodecSpecificInfoH264 alloc] init]; - h264Info.packetizationMode = - (RTCH264PacketizationMode)codec_specific_info->codecSpecific.H264.packetization_mode; - rtcCodecSpecificInfo = h264Info; - } - } - - return [decoder_ decode:encodedImage - missingFrames:missing_frames - fragmentationHeader:header - codecSpecificInfo:rtcCodecSpecificInfo - renderTimeMs:render_time_ms]; - } - - int32_t RegisterDecodeCompleteCallback(DecodedImageCallback *callback) { - [decoder_ setCallback:^(RTCVideoFrame *frame) { - const rtc::scoped_refptr buffer = - new rtc::RefCountedObject(frame.buffer); - VideoFrame videoFrame(buffer, - (uint32_t)(frame.timeStampNs / rtc::kNumNanosecsPerMicrosec), - 0, - (VideoRotation)frame.rotation); - videoFrame.set_timestamp(frame.timeStamp); - - callback->Decoded(videoFrame); - }]; - - return WEBRTC_VIDEO_CODEC_OK; - } - - int32_t Release() { return [decoder_ releaseDecoder]; } - - const char *ImplementationName() const { return implementation_name_.c_str(); } - - private: - id decoder_; - const std::string implementation_name_; -}; -} // namespace - -ObjCVideoDecoderFactory::ObjCVideoDecoderFactory(id decoder_factory) - : decoder_factory_(decoder_factory) {} - -ObjCVideoDecoderFactory::~ObjCVideoDecoderFactory() {} - -id ObjCVideoDecoderFactory::wrapped_decoder_factory() const { - return decoder_factory_; -} - -std::unique_ptr ObjCVideoDecoderFactory::CreateVideoDecoder( - const SdpVideoFormat &format) { - NSString *codecName = [NSString stringWithUTF8String:format.name.c_str()]; - for (RTCVideoCodecInfo *codecInfo in decoder_factory_.supportedCodecs) { - if ([codecName isEqualToString:codecInfo.name]) { - id decoder = [decoder_factory_ createDecoder:codecInfo]; - - if ([decoder isKindOfClass:[RTCWrappedNativeVideoDecoder class]]) { - return [(RTCWrappedNativeVideoDecoder *)decoder releaseWrappedDecoder]; - } else { - return std::unique_ptr(new ObjCVideoDecoder(decoder)); - } - } - } - - return nullptr; -} - -std::vector ObjCVideoDecoderFactory::GetSupportedFormats() const { - std::vector supported_formats; - for (RTCVideoCodecInfo *supportedCodec in decoder_factory_.supportedCodecs) { - SdpVideoFormat format = [supportedCodec nativeSdpVideoFormat]; - supported_formats.push_back(format); - } - - return supported_formats; -} - -// WebRtcVideoDecoderFactory - -VideoDecoder *ObjCVideoDecoderFactory::CreateVideoDecoderWithParams( - const cricket::VideoCodec &codec, cricket::VideoDecoderParams params) { - return CreateVideoDecoder(SdpVideoFormat(codec.name, codec.params)).release(); -} - -VideoDecoder *ObjCVideoDecoderFactory::CreateVideoDecoder(VideoCodecType type) { - // This is implemented to avoid hiding an overloaded virtual function - RTC_NOTREACHED(); - return nullptr; -} - -void ObjCVideoDecoderFactory::DestroyVideoDecoder(VideoDecoder *decoder) { - delete decoder; - decoder = nullptr; -} - -} // namespace webrtc diff --git a/sdk/objc/Framework/Classes/VideoToolbox/objc_video_encoder_factory.h b/sdk/objc/Framework/Classes/VideoToolbox/objc_video_encoder_factory.h deleted file mode 100644 index 6cdfc56f54..0000000000 --- a/sdk/objc/Framework/Classes/VideoToolbox/objc_video_encoder_factory.h +++ /dev/null @@ -1,53 +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_PEERCONNECTION_OBJC_VIDEO_ENCODER_FACTORY_H_ -#define SDK_OBJC_FRAMEWORK_CLASSES_PEERCONNECTION_OBJC_VIDEO_ENCODER_FACTORY_H_ - -#import - -#include "api/video_codecs/video_encoder_factory.h" -#include "media/engine/webrtcvideoencoderfactory.h" - -@protocol RTCVideoEncoderFactory; - -namespace webrtc { - -// TODO(andersc): Remove the inheritance from cricket::WebRtcVideoEncoderFactory -// when the legacy path in [RTCPeerConnectionFactory init] is no longer needed. -class ObjCVideoEncoderFactory : public VideoEncoderFactory, - public cricket::WebRtcVideoEncoderFactory { - public: - explicit ObjCVideoEncoderFactory(id); - ~ObjCVideoEncoderFactory(); - - id wrapped_encoder_factory() const; - - std::vector GetSupportedFormats() const override; - std::unique_ptr CreateVideoEncoder( - const SdpVideoFormat& format) override; - CodecInfo QueryVideoEncoder(const SdpVideoFormat& format) const override; - - // Needed for WebRtcVideoEncoderFactory interface. - webrtc::VideoEncoder* CreateVideoEncoder( - const cricket::VideoCodec& codec) override; - const std::vector& supported_codecs() const override; - void DestroyVideoEncoder(webrtc::VideoEncoder* encoder) override; - - private: - id encoder_factory_; - - // Needed for WebRtcVideoEncoderFactory interface. - mutable std::vector supported_codecs_; -}; - -} // namespace webrtc - -#endif // SDK_OBJC_FRAMEWORK_CLASSES_PEERCONNECTION_OBJC_VIDEO_ENCODER_FACTORY_H_ diff --git a/sdk/objc/Framework/Classes/VideoToolbox/objc_video_encoder_factory.mm b/sdk/objc/Framework/Classes/VideoToolbox/objc_video_encoder_factory.mm deleted file mode 100644 index 1380486730..0000000000 --- a/sdk/objc/Framework/Classes/VideoToolbox/objc_video_encoder_factory.mm +++ /dev/null @@ -1,191 +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/VideoToolbox/objc_video_encoder_factory.h" - -#include - -#import "NSString+StdString.h" -#import "RTCI420Buffer+Private.h" -#import "RTCVideoCodec+Private.h" -#import "RTCVideoFrame+Private.h" -#import "RTCWrappedNativeVideoEncoder.h" -#import "WebRTC/RTCVideoCodec.h" -#import "WebRTC/RTCVideoCodecFactory.h" -#import "WebRTC/RTCVideoCodecH264.h" -#import "WebRTC/RTCVideoFrame.h" -#import "WebRTC/RTCVideoFrameBuffer.h" - -#include "api/video/video_frame.h" -#include "api/video_codecs/sdp_video_format.h" -#include "api/video_codecs/video_encoder.h" -#include "modules/include/module_common_types.h" -#include "modules/video_coding/include/video_codec_interface.h" -#include "modules/video_coding/include/video_error_codes.h" -#include "rtc_base/logging.h" -#include "sdk/objc/Framework/Classes/Common/helpers.h" -#include "sdk/objc/Framework/Classes/Video/objc_frame_buffer.h" - -namespace webrtc { - -namespace { - -class ObjCVideoEncoder : public VideoEncoder { - public: - ObjCVideoEncoder(id encoder) - : encoder_(encoder), implementation_name_([encoder implementationName].stdString) {} - - int32_t InitEncode(const VideoCodec *codec_settings, - int32_t number_of_cores, - size_t max_payload_size) { - RTCVideoEncoderSettings *settings = - [[RTCVideoEncoderSettings alloc] initWithNativeVideoCodec:codec_settings]; - return [encoder_ startEncodeWithSettings:settings numberOfCores:number_of_cores]; - } - - int32_t RegisterEncodeCompleteCallback(EncodedImageCallback *callback) { - [encoder_ setCallback:^BOOL(RTCEncodedImage *_Nonnull frame, - id _Nonnull info, - RTCRtpFragmentationHeader *_Nonnull header) { - EncodedImage encodedImage = [frame nativeEncodedImage]; - - // Handle types that can be converted into one of CodecSpecificInfo's hard coded cases. - CodecSpecificInfo codecSpecificInfo; - if ([info isKindOfClass:[RTCCodecSpecificInfoH264 class]]) { - codecSpecificInfo = [(RTCCodecSpecificInfoH264 *)info nativeCodecSpecificInfo]; - } - - std::unique_ptr fragmentationHeader = - [header createNativeFragmentationHeader]; - EncodedImageCallback::Result res = - callback->OnEncodedImage(encodedImage, &codecSpecificInfo, fragmentationHeader.get()); - return res.error == EncodedImageCallback::Result::OK; - }]; - - return WEBRTC_VIDEO_CODEC_OK; - } - - int32_t Release() { return [encoder_ releaseEncoder]; } - - int32_t Encode(const VideoFrame &frame, - const CodecSpecificInfo *codec_specific_info, - const std::vector *frame_types) { - // CodecSpecificInfo only handles a hard coded list of codecs - id rtcCodecSpecificInfo = nil; - if (codec_specific_info) { - if (strcmp(codec_specific_info->codec_name, cricket::kH264CodecName) == 0) { - RTCCodecSpecificInfoH264 *h264Info = [[RTCCodecSpecificInfoH264 alloc] init]; - h264Info.packetizationMode = - (RTCH264PacketizationMode)codec_specific_info->codecSpecific.H264.packetization_mode; - rtcCodecSpecificInfo = h264Info; - } - } - - NSMutableArray *rtcFrameTypes = [NSMutableArray array]; - for (size_t i = 0; i < frame_types->size(); ++i) { - [rtcFrameTypes addObject:@(RTCFrameType(frame_types->at(i)))]; - } - - return [encoder_ encode:[[RTCVideoFrame alloc] initWithNativeVideoFrame:frame] - codecSpecificInfo:rtcCodecSpecificInfo - frameTypes:rtcFrameTypes]; - } - - int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) { return WEBRTC_VIDEO_CODEC_OK; } - - int32_t SetRates(uint32_t bitrate, uint32_t framerate) { - return [encoder_ setBitrate:bitrate framerate:framerate]; - } - - bool SupportsNativeHandle() const { return true; } - - VideoEncoder::ScalingSettings GetScalingSettings() const { - RTCVideoEncoderQpThresholds* qp_thresholds = [encoder_ scalingSettings]; - return qp_thresholds ? - ScalingSettings(true /* enabled */, qp_thresholds.low, qp_thresholds.high) : - ScalingSettings(false /* enabled */); - } - - const char *ImplementationName() const { return implementation_name_.c_str(); } - - private: - id encoder_; - const std::string implementation_name_; -}; -} // namespace - -ObjCVideoEncoderFactory::ObjCVideoEncoderFactory(id encoder_factory) - : encoder_factory_(encoder_factory) {} - -ObjCVideoEncoderFactory::~ObjCVideoEncoderFactory() {} - -id ObjCVideoEncoderFactory::wrapped_encoder_factory() const { - return encoder_factory_; -} - -std::vector ObjCVideoEncoderFactory::GetSupportedFormats() const { - std::vector supported_formats; - for (RTCVideoCodecInfo *supportedCodec in encoder_factory_.supportedCodecs) { - SdpVideoFormat format = [supportedCodec nativeSdpVideoFormat]; - supported_formats.push_back(format); - } - - return supported_formats; -} - -VideoEncoderFactory::CodecInfo ObjCVideoEncoderFactory::QueryVideoEncoder( - const SdpVideoFormat &format) const { - // TODO(andersc): This is a hack until we figure out how this should be done properly. - NSString *formatName = [NSString stringForStdString:format.name]; - NSSet *wrappedSoftwareFormats = - [NSSet setWithObjects:kRTCVideoCodecVp8Name, kRTCVideoCodecVp9Name, nil]; - - CodecInfo codec_info; - codec_info.is_hardware_accelerated = ![wrappedSoftwareFormats containsObject:formatName]; - codec_info.has_internal_source = false; - return codec_info; -} - -std::unique_ptr ObjCVideoEncoderFactory::CreateVideoEncoder( - const SdpVideoFormat &format) { - RTCVideoCodecInfo *info = [[RTCVideoCodecInfo alloc] initWithNativeSdpVideoFormat:format]; - id encoder = [encoder_factory_ createEncoder:info]; - if ([encoder isKindOfClass:[RTCWrappedNativeVideoEncoder class]]) { - return [(RTCWrappedNativeVideoEncoder *)encoder releaseWrappedEncoder]; - } else { - return std::unique_ptr(new ObjCVideoEncoder(encoder)); - } -} - -// WebRtcVideoEncoderFactory - -VideoEncoder *ObjCVideoEncoderFactory::CreateVideoEncoder(const cricket::VideoCodec &codec) { - RTCVideoCodecInfo *info = [[RTCVideoCodecInfo alloc] - initWithNativeSdpVideoFormat:SdpVideoFormat(codec.name, codec.params)]; - id encoder = [encoder_factory_ createEncoder:info]; - return new ObjCVideoEncoder(encoder); -} - -const std::vector &ObjCVideoEncoderFactory::supported_codecs() const { - supported_codecs_.clear(); - for (RTCVideoCodecInfo *supportedCodec in encoder_factory_.supportedCodecs) { - SdpVideoFormat format = [supportedCodec nativeSdpVideoFormat]; - supported_codecs_.push_back(cricket::VideoCodec(format)); - } - - return supported_codecs_; -} - -void ObjCVideoEncoderFactory::DestroyVideoEncoder(VideoEncoder *encoder) { - delete encoder; - encoder = nullptr; -} - -} // namespace webrtc