OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 #include "webrtc/sdk/objc/Framework/Classes/videotoolboxvideocodecfactory.h" |
| 11 |
| 12 #include "webrtc/base/logging.h" |
| 13 #include "webrtc/media/base/codec.h" |
| 14 #if defined(WEBRTC_IOS) |
| 15 #include "webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_encoder.h" |
| 16 #include "webrtc/sdk/objc/Framework/Classes/h264_video_toolbox_decoder.h" |
| 17 #endif |
| 18 |
| 19 // TODO(kthelgason): delete this when CreateVideoDecoder takes |
| 20 // a cricket::VideoCodec instead of webrtc::VideoCodecType. |
| 21 static const char* NameFromCodecType(webrtc::VideoCodecType type) { |
| 22 switch (type) { |
| 23 case webrtc::kVideoCodecVP8: |
| 24 return cricket::kVp8CodecName; |
| 25 case webrtc::kVideoCodecVP9: |
| 26 return cricket::kVp9CodecName; |
| 27 case webrtc::kVideoCodecH264: |
| 28 return cricket::kH264CodecName; |
| 29 default: |
| 30 return "Unknown codec"; |
| 31 } |
| 32 } |
| 33 |
| 34 namespace webrtc { |
| 35 |
| 36 // VideoToolboxVideoEncoderFactory |
| 37 |
| 38 VideoToolboxVideoEncoderFactory::VideoToolboxVideoEncoderFactory() { |
| 39 // Hardware H264 encoding only supported on iOS for now. |
| 40 #if defined(WEBRTC_IOS) |
| 41 supported_codecs_.push_back(cricket::VideoCodec(cricket::kH264CodecName)); |
| 42 #endif |
| 43 } |
| 44 |
| 45 VideoToolboxVideoEncoderFactory::~VideoToolboxVideoEncoderFactory() {} |
| 46 |
| 47 VideoEncoder* VideoToolboxVideoEncoderFactory::CreateVideoEncoder( |
| 48 const cricket::VideoCodec& codec) { |
| 49 #if defined(WEBRTC_IOS) |
| 50 if (IsCodecSupported(supported_codecs_, codec)) { |
| 51 LOG(LS_INFO) << "Creating HW encoder for " << codec.name; |
| 52 return new H264VideoToolboxEncoder(); |
| 53 } |
| 54 #endif |
| 55 LOG(LS_INFO) << "No HW encoder found for codec " << codec.name; |
| 56 return nullptr; |
| 57 } |
| 58 |
| 59 void VideoToolboxVideoEncoderFactory::DestroyVideoEncoder( |
| 60 VideoEncoder* encoder) { |
| 61 #if defined(WEBRTC_IOS) |
| 62 delete encoder; |
| 63 encoder = nullptr; |
| 64 #endif |
| 65 } |
| 66 |
| 67 const std::vector<cricket::VideoCodec>& |
| 68 VideoToolboxVideoEncoderFactory::supported_codecs() const { |
| 69 return supported_codecs_; |
| 70 } |
| 71 |
| 72 // VideoToolboxVideoDecoderFactory |
| 73 |
| 74 VideoToolboxVideoDecoderFactory::VideoToolboxVideoDecoderFactory() { |
| 75 #if defined(WEBRTC_IOS) |
| 76 supported_codecs_.push_back(cricket::VideoCodec("H264")); |
| 77 #endif |
| 78 } |
| 79 |
| 80 VideoToolboxVideoDecoderFactory::~VideoToolboxVideoDecoderFactory() {} |
| 81 |
| 82 VideoDecoder* VideoToolboxVideoDecoderFactory::CreateVideoDecoder( |
| 83 VideoCodecType type) { |
| 84 const auto codec = cricket::VideoCodec(NameFromCodecType(type)); |
| 85 #if defined(WEBRTC_IOS) |
| 86 if (IsCodecSupported(supported_codecs_, codec)) { |
| 87 LOG(LS_INFO) << "Creating HW decoder for " << codec.name; |
| 88 return new H264VideoToolboxDecoder(); |
| 89 } |
| 90 #endif |
| 91 LOG(LS_INFO) << "No HW decoder found for codec " << codec.name; |
| 92 return nullptr; |
| 93 } |
| 94 |
| 95 void VideoToolboxVideoDecoderFactory::DestroyVideoDecoder( |
| 96 VideoDecoder* decoder) { |
| 97 #if defined(WEBRTC_IOS) |
| 98 delete decoder; |
| 99 decoder = nullptr; |
| 100 #endif |
| 101 } |
| 102 |
| 103 } // namespace webrtc |
OLD | NEW |