blob: 6f7316b10a69e9cd1db76ed0b5aa37cd15ae13fa [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
hbosbab934b2016-01-27 01:36:03 -080014#if defined(WEBRTC_THIRD_PARTY_H264)
15#include "webrtc/modules/video_coding/codecs/h264/h264_encoder_impl.h"
16#include "webrtc/modules/video_coding/codecs/h264/h264_decoder_impl.h"
17#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
28// We need this file to be C++ only so it will compile properly for all
29// platforms. In order to write ObjC specific implementations we use private
30// externs. This function is defined in h264.mm.
31#if defined(WEBRTC_IOS)
32extern bool IsH264CodecSupportedObjC();
33#endif
34
hbosbab934b2016-01-27 01:36:03 -080035// If any H.264 codec is supported (iOS HW or OpenH264/FFmpeg).
Zeke Chin71f6f442015-06-29 14:34:58 -070036bool IsH264CodecSupported() {
37#if defined(WEBRTC_IOS)
hbosbab934b2016-01-27 01:36:03 -080038 if (IsH264CodecSupportedObjC()) {
39 return true;
40 }
41#endif
42#if defined(WEBRTC_THIRD_PARTY_H264)
43 return true;
Zeke Chin71f6f442015-06-29 14:34:58 -070044#else
45 return false;
46#endif
47}
48
49H264Encoder* H264Encoder::Create() {
henrikg91d6ede2015-09-17 00:24:34 -070050 RTC_DCHECK(H264Encoder::IsSupported());
Zeke Chin71f6f442015-06-29 14:34:58 -070051#if defined(WEBRTC_IOS) && defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED)
hbosbab934b2016-01-27 01:36:03 -080052 if (IsH264CodecSupportedObjC()) {
53 LOG(LS_INFO) << "Creating H264VideoToolboxEncoder.";
54 return new H264VideoToolboxEncoder();
55 }
56#endif
57#if defined(WEBRTC_THIRD_PARTY_H264)
58 LOG(LS_INFO) << "Creating H264EncoderImpl.";
59 return new H264EncoderImpl();
Zeke Chin71f6f442015-06-29 14:34:58 -070060#else
61 RTC_NOTREACHED();
62 return nullptr;
63#endif
64}
65
66bool H264Encoder::IsSupported() {
67 return IsH264CodecSupported();
68}
69
70H264Decoder* H264Decoder::Create() {
henrikg91d6ede2015-09-17 00:24:34 -070071 RTC_DCHECK(H264Decoder::IsSupported());
Zeke Chin71f6f442015-06-29 14:34:58 -070072#if defined(WEBRTC_IOS) && defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED)
hbosbab934b2016-01-27 01:36:03 -080073 if (IsH264CodecSupportedObjC()) {
74 LOG(LS_INFO) << "Creating H264VideoToolboxDecoder.";
75 return new H264VideoToolboxDecoder();
76 }
77#endif
78#if defined(WEBRTC_THIRD_PARTY_H264)
79 LOG(LS_INFO) << "Creating H264DecoderImpl.";
80 return new H264DecoderImpl();
Zeke Chin71f6f442015-06-29 14:34:58 -070081#else
82 RTC_NOTREACHED();
83 return nullptr;
84#endif
85}
86
87bool H264Decoder::IsSupported() {
88 return IsH264CodecSupported();
89}
90
91} // namespace webrtc