Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: webrtc/modules/video_coding/codecs/h264/h264_decoder_impl.cc

Issue 1306813009: H.264 video codec support using OpenH264/FFmpeg (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Misc (WebRtcVideoChannel2::...::ConfigureVideoEncoderSettings care about H264 case) Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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/h264_decoder_impl.h"
13
14 #include <bitset>
15
16 // OpenH264
17 #include "codec_api.h"
18 #include "codec_app_def.h"
19 #include "codec_def.h"
20
21 #include "webrtc/base/checks.h"
22 #include "webrtc/base/logging.h"
23 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
24
25 namespace webrtc {
26
27 namespace {
28 const bool OPENH264_DECODER_LOGGING = false;
stefan-webrtc 2015/09/28 11:19:01 I think it's more common to use kOpenH264DecodeLog
hbos 2015/09/30 15:35:18 Done.
29 } // anonymous namespace
stefan-webrtc 2015/09/28 11:19:01 // namespace
hbos 2015/09/30 15:35:18 Done.
30
31 H264DecoderImpl::H264DecoderImpl()
32 : openh264_decoder_(nullptr),
33 decoded_image_(),
34 decoded_image_callback_(nullptr) {
35 }
36
37 H264DecoderImpl::~H264DecoderImpl() {
38 Release();
39 }
40
41 int32_t H264DecoderImpl::InitDecode(const VideoCodec* codec_settings,
42 int32_t /*number_of_cores*/) {
43 if (codec_settings &&
44 codec_settings->codecType != VideoCodecType::kVideoCodecH264) {
45 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
46 }
47
48 int release_ret = Release();
49 if (release_ret != WEBRTC_VIDEO_CODEC_OK)
50 return release_ret;
51 DCHECK(!openh264_decoder_);
stefan-webrtc 2015/09/28 11:19:02 I think you have to rebase since DCHECK is now RTC
hbos 2015/09/30 15:35:18 Done.
52
53 // Create decoder.
54 if (WelsCreateDecoder(&openh264_decoder_) != 0) {
55 // Failed to create decoder.
stefan-webrtc 2015/09/28 11:19:01 This comment isn't needed since the log below says
hbos 2015/09/30 15:35:18 Done.
56 LOG(LS_ERROR) << "Failed to create OpenH264 decoder";
57 DCHECK(!openh264_decoder_);
58 return WEBRTC_VIDEO_CODEC_ERROR;
59 }
60 DCHECK(openh264_decoder_);
61
62 // Initialization parameters.
63 SDecodingParam init_params;
64 memset(&init_params, 0, sizeof(SDecodingParam));
65 init_params.eOutputColorFormat = EVideoFormatType::videoFormatI420;
66 init_params.uiCpuLoad = 0;
stefan-webrtc 2015/09/28 11:19:02 Looks like this is unused by OpenH264, but does it
hbos 2015/09/30 15:35:18 The decoder example on github just clears all the
stefan-webrtc 2015/10/01 08:19:30 SG
67 init_params.uiTargetDqLayer = 0xFF;
68 init_params.eEcActiveIdc = ERROR_CON_IDC::ERROR_CON_DISABLE;
69 init_params.bParseOnly = false;
70 init_params.sVideoProperty.eVideoBsType =
71 VIDEO_BITSTREAM_TYPE::VIDEO_BITSTREAM_DEFAULT;
72
73 // Initialize.
74 if (openh264_decoder_->Initialize(&init_params) != 0) {
75 LOG(LS_ERROR) << "Failed to initialize OpenH264 decoder";
76 Release();
77 return WEBRTC_VIDEO_CODEC_ERROR;
78 }
79 if (OPENH264_DECODER_LOGGING) {
80 int trace_level = WELS_LOG_DETAIL;
81 openh264_decoder_->SetOption(DECODER_OPTION_TRACE_LEVEL,
82 &trace_level);
83 }
84 return WEBRTC_VIDEO_CODEC_OK;
85 }
86
87 int32_t H264DecoderImpl::Release() {
88 if (openh264_decoder_) {
89 int64_t uninit_ret = openh264_decoder_->Uninitialize();
90 if (uninit_ret != 0) {
91 LOG(LS_WARNING) << "OpenH264 decoder's Uninitialize() returned "
92 << "unsuccessful: " << uninit_ret;
93 }
94 WelsDestroyDecoder(openh264_decoder_);
95 openh264_decoder_ = nullptr;
96 }
97 return WEBRTC_VIDEO_CODEC_OK;
98 }
99
100 int32_t H264DecoderImpl::Reset() {
101 if (!IsInitialized())
102 return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
103 InitDecode(nullptr, 1);
104 return WEBRTC_VIDEO_CODEC_OK;
105 }
106
107 int32_t H264DecoderImpl::RegisterDecodeCompleteCallback(
108 DecodedImageCallback* callback) {
109 decoded_image_callback_ = callback;
110 return WEBRTC_VIDEO_CODEC_OK;
111 }
112
113 int32_t H264DecoderImpl::Decode(const EncodedImage& input_image,
114 bool /*missing_frames*/,
115 const RTPFragmentationHeader* /*fragmentation*/,
116 const CodecSpecificInfo* codec_specific_info,
117 int64_t /*render_time_ms*/) {
118 if (!IsInitialized()) {
119 return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
120 }
121 if (!decoded_image_callback_) {
122 LOG(LS_WARNING) << "InitDecode() has been called, but a callback function "
123 << "has not been set with RegisterDecodeCompleteCallback()";
124 return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
125 }
126 if (!input_image._buffer || !input_image._length)
127 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
128 if (codec_specific_info &&
129 codec_specific_info->codecType != VideoCodecType::kVideoCodecH264) {
130 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
131 }
132
133 // DecodeFrameNoDelay output.
134 uint8_t* data[3] = { 0, 0, 0 };
135 SBufferInfo buffer_info;
136 memset(&buffer_info, 0, sizeof(SBufferInfo));
137
138 // Decode!
139 DECODING_STATE decode_ret = openh264_decoder_->DecodeFrameNoDelay(
140 input_image._buffer, input_image._length, data, &buffer_info);
141 if (decode_ret != 0) {
142 LOG(LS_ERROR) << "H264 decode failed, returned error bitmask: "
143 << std::bitset<8>(decode_ret).to_string() << " = "
144 << decode_ret;
145 if (decode_ret & dsFramePending)
146 LOG(LS_ERROR) << " dsFramePending";
147 if (decode_ret & dsRefLost)
148 LOG(LS_ERROR) << " dsRefLost";
149 if (decode_ret & dsBitstreamError)
150 LOG(LS_ERROR) << " dsBitstreamError";
151 if (decode_ret & dsDepLayerLost)
152 LOG(LS_ERROR) << " dsDepLayerLost";
153 if (decode_ret & dsNoParamSets)
154 LOG(LS_ERROR) << " dsNoParamSets";
155 if (decode_ret & dsDataErrorConcealed)
156 LOG(LS_ERROR) << " dsDataErrorConcealed";
157 return WEBRTC_VIDEO_CODEC_ERROR;
158 }
159 CHECK_EQ(decode_ret, 0);
stefan-webrtc 2015/09/28 11:19:01 Should this be a DCHECK?
hbos 2015/09/30 15:35:18 Done.
160
161 // Frame data ready?
162 if (buffer_info.iBufferStatus == 1) {
163 // Copy decoded data into |decoded_image_|. Must copy because the internal
164 // VideoFrameBuffer is reference counted.
165 decoded_image_.CreateFrame(data[0], data[1], data[2],
166 buffer_info.UsrData.sSystemBuffer.iWidth,
167 buffer_info.UsrData.sSystemBuffer.iHeight,
168 buffer_info.UsrData.sSystemBuffer.iStride[0],
169 buffer_info.UsrData.sSystemBuffer.iStride[1],
170 buffer_info.UsrData.sSystemBuffer.iStride[1]);
171 decoded_image_.set_timestamp(input_image._timeStamp);
172 decoded_image_.set_ntp_time_ms(input_image.ntp_time_ms_);
173
174 // Deliver decoded image.
175 decoded_image_callback_->Decoded(decoded_image_);
176 }
177 return WEBRTC_VIDEO_CODEC_OK;
178 }
179
180 bool H264DecoderImpl::IsInitialized() {
181 return openh264_decoder_ != nullptr;
182 }
183
184 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698