Chromium Code Reviews| Index: webrtc/sdk/objc/Framework/Classes/videotoolboxvideocodecfactory.cc | 
| diff --git a/webrtc/sdk/objc/Framework/Classes/videotoolboxvideocodecfactory.cc b/webrtc/sdk/objc/Framework/Classes/videotoolboxvideocodecfactory.cc | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..063025ac8b319267bda00a9d6ef735e3c60a2ede | 
| --- /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) { | 
| 
 
magjed_webrtc
2016/11/01 14:00:20
nit: We should probably move this function to webr
 
kthelgason
2016/11/01 15:14:31
Yeah, I agree that it's dirty to be pasting this a
 
 | 
| + 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("H264")); | 
| 
 
magjed_webrtc
2016/11/01 14:00:20
nit: Maybe we should use cricket::kH264CodecName h
 
kthelgason
2016/11/01 15:14:31
Done.
 
 | 
| +#endif | 
| +} | 
| + | 
| +VideoToolboxVideoEncoderFactory::~VideoToolboxVideoEncoderFactory() {} | 
| + | 
| +VideoEncoder* VideoToolboxVideoEncoderFactory::CreateVideoEncoder( | 
| + const cricket::VideoCodec& codec) { | 
| +#if defined(WEBRTC_IOS) | 
| 
 
magjed_webrtc
2016/11/01 14:00:20
Can we have just one ifdef in the ctor and leave t
 
kthelgason
2016/11/01 15:14:31
We could do that, but that requires compiling the
 
 | 
| + 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)) { | 
| 
 
magjed_webrtc
2016/11/01 14:00:20
Thanks for implementing it like this. I want to re
 
 | 
| + 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 |