blob: 9fdc4d4623c232b859e8de1f214ced85c5894803 [file] [log] [blame]
Zeke Chin71f6f442015-06-29 14:34:58 -07001/*
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
hbos9dc59282016-02-03 05:09:37 -080014#if defined(WEBRTC_USE_H264)
hbosbab934b2016-01-27 01:36:03 -080015#include "webrtc/modules/video_coding/codecs/h264/h264_decoder_impl.h"
hbos9dc59282016-02-03 05:09:37 -080016#include "webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.h"
hbosbab934b2016-01-27 01:36:03 -080017#endif
Zeke Chin71f6f442015-06-29 14:34:58 -070018#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"
hbosbab934b2016-01-27 01:36:03 -080024#include "webrtc/base/logging.h"
Zeke Chin71f6f442015-06-29 14:34:58 -070025
26namespace webrtc {
27
hbos9dc59282016-02-03 05:09:37 -080028namespace {
29
30#if defined(WEBRTC_USE_H264)
31bool g_rtc_use_h264 = true;
32#endif
33
34} // namespace
35
36void DisableRtcUseH264() {
37#if defined(WEBRTC_USE_H264)
38 g_rtc_use_h264 = false;
39#endif
40}
41
Zeke Chin71f6f442015-06-29 14:34:58 -070042// 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)
46extern bool IsH264CodecSupportedObjC();
47#endif
48
hbosbab934b2016-01-27 01:36:03 -080049// If any H.264 codec is supported (iOS HW or OpenH264/FFmpeg).
Zeke Chin71f6f442015-06-29 14:34:58 -070050bool IsH264CodecSupported() {
51#if defined(WEBRTC_IOS)
hbosbab934b2016-01-27 01:36:03 -080052 if (IsH264CodecSupportedObjC()) {
53 return true;
54 }
55#endif
hbos9dc59282016-02-03 05:09:37 -080056#if defined(WEBRTC_USE_H264)
57 return g_rtc_use_h264;
Zeke Chin71f6f442015-06-29 14:34:58 -070058#else
59 return false;
60#endif
61}
62
63H264Encoder* H264Encoder::Create() {
henrikg91d6ede2015-09-17 00:24:34 -070064 RTC_DCHECK(H264Encoder::IsSupported());
Zeke Chin71f6f442015-06-29 14:34:58 -070065#if defined(WEBRTC_IOS) && defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED)
hbosbab934b2016-01-27 01:36:03 -080066 if (IsH264CodecSupportedObjC()) {
67 LOG(LS_INFO) << "Creating H264VideoToolboxEncoder.";
68 return new H264VideoToolboxEncoder();
69 }
70#endif
hbos9dc59282016-02-03 05:09:37 -080071#if defined(WEBRTC_USE_H264)
72 RTC_CHECK(g_rtc_use_h264);
hbosbab934b2016-01-27 01:36:03 -080073 LOG(LS_INFO) << "Creating H264EncoderImpl.";
74 return new H264EncoderImpl();
Zeke Chin71f6f442015-06-29 14:34:58 -070075#else
76 RTC_NOTREACHED();
77 return nullptr;
78#endif
79}
80
81bool H264Encoder::IsSupported() {
82 return IsH264CodecSupported();
83}
84
85H264Decoder* H264Decoder::Create() {
henrikg91d6ede2015-09-17 00:24:34 -070086 RTC_DCHECK(H264Decoder::IsSupported());
Zeke Chin71f6f442015-06-29 14:34:58 -070087#if defined(WEBRTC_IOS) && defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED)
hbosbab934b2016-01-27 01:36:03 -080088 if (IsH264CodecSupportedObjC()) {
89 LOG(LS_INFO) << "Creating H264VideoToolboxDecoder.";
90 return new H264VideoToolboxDecoder();
91 }
92#endif
hbos9dc59282016-02-03 05:09:37 -080093#if defined(WEBRTC_USE_H264)
94 RTC_CHECK(g_rtc_use_h264);
hbosbab934b2016-01-27 01:36:03 -080095 LOG(LS_INFO) << "Creating H264DecoderImpl.";
96 return new H264DecoderImpl();
Zeke Chin71f6f442015-06-29 14:34:58 -070097#else
98 RTC_NOTREACHED();
99 return nullptr;
100#endif
101}
102
103bool H264Decoder::IsSupported() {
104 return IsH264CodecSupported();
105}
106
107} // namespace webrtc