Zeke Chin | 71f6f44 | 2015-06-29 14:34:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 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 | */ |
| 11 | |
| 12 | #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" |
| 13 | |
hbos | 9dc5928 | 2016-02-03 05:09:37 -0800 | [diff] [blame] | 14 | #if defined(WEBRTC_USE_H264) |
hbos | bab934b | 2016-01-27 01:36:03 -0800 | [diff] [blame] | 15 | #include "webrtc/modules/video_coding/codecs/h264/h264_decoder_impl.h" |
hbos | 9dc5928 | 2016-02-03 05:09:37 -0800 | [diff] [blame] | 16 | #include "webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.h" |
hbos | bab934b | 2016-01-27 01:36:03 -0800 | [diff] [blame] | 17 | #endif |
Zeke Chin | 71f6f44 | 2015-06-29 14:34:58 -0700 | [diff] [blame] | 18 | #if defined(WEBRTC_IOS) |
| 19 | #include "webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_decoder.h" |
| 20 | #include "webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.h" |
| 21 | #endif |
| 22 | |
| 23 | #include "webrtc/base/checks.h" |
hbos | bab934b | 2016-01-27 01:36:03 -0800 | [diff] [blame] | 24 | #include "webrtc/base/logging.h" |
Zeke Chin | 71f6f44 | 2015-06-29 14:34:58 -0700 | [diff] [blame] | 25 | |
| 26 | namespace webrtc { |
| 27 | |
hbos | 9dc5928 | 2016-02-03 05:09:37 -0800 | [diff] [blame] | 28 | namespace { |
| 29 | |
| 30 | #if defined(WEBRTC_USE_H264) |
| 31 | bool g_rtc_use_h264 = true; |
| 32 | #endif |
| 33 | |
| 34 | } // namespace |
| 35 | |
| 36 | void DisableRtcUseH264() { |
| 37 | #if defined(WEBRTC_USE_H264) |
| 38 | g_rtc_use_h264 = false; |
| 39 | #endif |
| 40 | } |
| 41 | |
Zeke Chin | 71f6f44 | 2015-06-29 14:34:58 -0700 | [diff] [blame] | 42 | // We need this file to be C++ only so it will compile properly for all |
| 43 | // platforms. In order to write ObjC specific implementations we use private |
| 44 | // externs. This function is defined in h264.mm. |
| 45 | #if defined(WEBRTC_IOS) |
| 46 | extern bool IsH264CodecSupportedObjC(); |
| 47 | #endif |
| 48 | |
hbos | bab934b | 2016-01-27 01:36:03 -0800 | [diff] [blame] | 49 | // If any H.264 codec is supported (iOS HW or OpenH264/FFmpeg). |
Zeke Chin | 71f6f44 | 2015-06-29 14:34:58 -0700 | [diff] [blame] | 50 | bool IsH264CodecSupported() { |
| 51 | #if defined(WEBRTC_IOS) |
hbos | bab934b | 2016-01-27 01:36:03 -0800 | [diff] [blame] | 52 | if (IsH264CodecSupportedObjC()) { |
| 53 | return true; |
| 54 | } |
| 55 | #endif |
hbos | 9dc5928 | 2016-02-03 05:09:37 -0800 | [diff] [blame] | 56 | #if defined(WEBRTC_USE_H264) |
| 57 | return g_rtc_use_h264; |
Zeke Chin | 71f6f44 | 2015-06-29 14:34:58 -0700 | [diff] [blame] | 58 | #else |
| 59 | return false; |
| 60 | #endif |
| 61 | } |
| 62 | |
| 63 | H264Encoder* H264Encoder::Create() { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 64 | RTC_DCHECK(H264Encoder::IsSupported()); |
Zeke Chin | 71f6f44 | 2015-06-29 14:34:58 -0700 | [diff] [blame] | 65 | #if defined(WEBRTC_IOS) && defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED) |
hbos | bab934b | 2016-01-27 01:36:03 -0800 | [diff] [blame] | 66 | if (IsH264CodecSupportedObjC()) { |
| 67 | LOG(LS_INFO) << "Creating H264VideoToolboxEncoder."; |
| 68 | return new H264VideoToolboxEncoder(); |
| 69 | } |
| 70 | #endif |
hbos | 9dc5928 | 2016-02-03 05:09:37 -0800 | [diff] [blame] | 71 | #if defined(WEBRTC_USE_H264) |
| 72 | RTC_CHECK(g_rtc_use_h264); |
hbos | bab934b | 2016-01-27 01:36:03 -0800 | [diff] [blame] | 73 | LOG(LS_INFO) << "Creating H264EncoderImpl."; |
| 74 | return new H264EncoderImpl(); |
Zeke Chin | 71f6f44 | 2015-06-29 14:34:58 -0700 | [diff] [blame] | 75 | #else |
| 76 | RTC_NOTREACHED(); |
| 77 | return nullptr; |
| 78 | #endif |
| 79 | } |
| 80 | |
| 81 | bool H264Encoder::IsSupported() { |
| 82 | return IsH264CodecSupported(); |
| 83 | } |
| 84 | |
| 85 | H264Decoder* H264Decoder::Create() { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 86 | RTC_DCHECK(H264Decoder::IsSupported()); |
Zeke Chin | 71f6f44 | 2015-06-29 14:34:58 -0700 | [diff] [blame] | 87 | #if defined(WEBRTC_IOS) && defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED) |
hbos | bab934b | 2016-01-27 01:36:03 -0800 | [diff] [blame] | 88 | if (IsH264CodecSupportedObjC()) { |
| 89 | LOG(LS_INFO) << "Creating H264VideoToolboxDecoder."; |
| 90 | return new H264VideoToolboxDecoder(); |
| 91 | } |
| 92 | #endif |
hbos | 9dc5928 | 2016-02-03 05:09:37 -0800 | [diff] [blame] | 93 | #if defined(WEBRTC_USE_H264) |
| 94 | RTC_CHECK(g_rtc_use_h264); |
hbos | bab934b | 2016-01-27 01:36:03 -0800 | [diff] [blame] | 95 | LOG(LS_INFO) << "Creating H264DecoderImpl."; |
| 96 | return new H264DecoderImpl(); |
Zeke Chin | 71f6f44 | 2015-06-29 14:34:58 -0700 | [diff] [blame] | 97 | #else |
| 98 | RTC_NOTREACHED(); |
| 99 | return nullptr; |
| 100 | #endif |
| 101 | } |
| 102 | |
| 103 | bool H264Decoder::IsSupported() { |
| 104 | return IsH264CodecSupported(); |
| 105 | } |
| 106 | |
| 107 | } // namespace webrtc |