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

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: Addressed stefan and hta comments Created 5 years, 2 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 kOpenH264DecoderDetailedLogging = false;
29 } // namespace
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;
palmer 2015/11/25 02:20:50 Ultimately it may be a good idea to re-declare the
hbos 2015/11/27 14:43:42 Acknowledged. (Won't do that as part of this work
46 }
47
48 int release_ret = Release();
palmer 2015/11/25 02:20:50 Nit: Are these codes intended to be ints, or int32
hbos 2015/11/27 14:43:42 Done.
49 if (release_ret != WEBRTC_VIDEO_CODEC_OK)
50 return release_ret;
51 RTC_DCHECK(!openh264_decoder_);
52
53 // Create decoder.
54 if (WelsCreateDecoder(&openh264_decoder_) != 0) {
55 LOG(LS_ERROR) << "Failed to create OpenH264 decoder";
56 RTC_DCHECK(!openh264_decoder_);
57 return WEBRTC_VIDEO_CODEC_ERROR;
58 }
59 RTC_DCHECK(openh264_decoder_);
60 if (kOpenH264DecoderDetailedLogging) {
61 int trace_level = WELS_LOG_DETAIL;
62 openh264_decoder_->SetOption(DECODER_OPTION_TRACE_LEVEL,
63 &trace_level);
64 }
65 // else WELS_LOG_DEFAULT is used by default.
66
67 // Initialization parameters.
68 SDecodingParam init_params;
69 memset(&init_params, 0, sizeof(SDecodingParam));
palmer 2015/11/25 02:20:50 Is this necessary? The SDecodingParam default cons
hbos 2015/11/27 14:43:43 It's necessary. It's a struct with a default const
70 init_params.eOutputColorFormat = EVideoFormatType::videoFormatI420;
71 init_params.uiCpuLoad = 0;
72 init_params.uiTargetDqLayer = 0xFF;
73 init_params.eEcActiveIdc = ERROR_CON_IDC::ERROR_CON_DISABLE;
74 init_params.bParseOnly = false;
75 init_params.sVideoProperty.eVideoBsType =
palmer 2015/11/25 02:20:50 Nit: Yeah, it seems like all this could be done wi
hbos 2015/11/27 14:43:43 I'm afraid not (unless we start contributing to th
76 VIDEO_BITSTREAM_TYPE::VIDEO_BITSTREAM_DEFAULT;
77
78 // Initialize.
79 if (openh264_decoder_->Initialize(&init_params) != 0) {
80 LOG(LS_ERROR) << "Failed to initialize OpenH264 decoder";
81 Release();
82 return WEBRTC_VIDEO_CODEC_ERROR;
83 }
84
85 return WEBRTC_VIDEO_CODEC_OK;
86 }
87
88 int32_t H264DecoderImpl::Release() {
89 if (openh264_decoder_) {
90 int64_t uninit_ret = openh264_decoder_->Uninitialize();
91 if (uninit_ret != 0) {
92 LOG(LS_WARNING) << "OpenH264 decoder's Uninitialize() returned "
93 << "unsuccessful: " << uninit_ret;
94 }
95 WelsDestroyDecoder(openh264_decoder_);
96 openh264_decoder_ = nullptr;
97 }
98 return WEBRTC_VIDEO_CODEC_OK;
99 }
100
101 int32_t H264DecoderImpl::Reset() {
102 if (!IsInitialized())
103 return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
104 InitDecode(nullptr, 1);
105 return WEBRTC_VIDEO_CODEC_OK;
106 }
107
108 int32_t H264DecoderImpl::RegisterDecodeCompleteCallback(
109 DecodedImageCallback* callback) {
110 decoded_image_callback_ = callback;
111 return WEBRTC_VIDEO_CODEC_OK;
112 }
113
114 int32_t H264DecoderImpl::Decode(const EncodedImage& input_image,
115 bool /*missing_frames*/,
116 const RTPFragmentationHeader* /*fragmentation*/,
117 const CodecSpecificInfo* codec_specific_info,
118 int64_t /*render_time_ms*/) {
119 if (!IsInitialized()) {
120 return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
121 }
122 if (!decoded_image_callback_) {
123 LOG(LS_WARNING) << "InitDecode() has been called, but a callback function "
124 << "has not been set with RegisterDecodeCompleteCallback()";
125 return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
126 }
127 if (!input_image._buffer || !input_image._length)
palmer 2015/11/25 02:20:50 BUG?: It looks like _length is declared as a size_
hbos 2015/11/27 14:43:42 Hmh I don't know if it's possible to receive crazy
128 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
129 if (codec_specific_info &&
130 codec_specific_info->codecType != VideoCodecType::kVideoCodecH264) {
131 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
132 }
133
134 // DecodeFrameNoDelay output.
135 uint8_t* data[3] = { 0, 0, 0 };
136 SBufferInfo buffer_info;
137 memset(&buffer_info, 0, sizeof(SBufferInfo));
palmer 2015/11/25 02:20:50 Same default constructor issue here, too. (Unless
hbos 2015/11/27 14:43:42 See other comment.
138
139 // Decode!
140 DECODING_STATE decode_ret = openh264_decoder_->DecodeFrameNoDelay(
141 input_image._buffer, input_image._length, data, &buffer_info);
142 if (decode_ret != 0) {
143 LOG(LS_ERROR) << "H264 decode failed, returned error bitmask: "
144 << std::bitset<8>(decode_ret).to_string() << " = "
145 << decode_ret;
146 if (decode_ret & dsFramePending)
147 LOG(LS_ERROR) << " dsFramePending";
148 if (decode_ret & dsRefLost)
149 LOG(LS_ERROR) << " dsRefLost";
150 if (decode_ret & dsBitstreamError)
151 LOG(LS_ERROR) << " dsBitstreamError";
152 if (decode_ret & dsDepLayerLost)
153 LOG(LS_ERROR) << " dsDepLayerLost";
154 if (decode_ret & dsNoParamSets)
155 LOG(LS_ERROR) << " dsNoParamSets";
156 if (decode_ret & dsDataErrorConcealed)
157 LOG(LS_ERROR) << " dsDataErrorConcealed";
158 return WEBRTC_VIDEO_CODEC_ERROR;
159 }
160 RTC_DCHECK_EQ(decode_ret, 0);
161
162 // Frame data ready?
163 if (buffer_info.iBufferStatus == 1) {
164 // Copy decoded data into |decoded_image_|. Must copy because the internal
165 // VideoFrameBuffer is reference counted.
166 decoded_image_.CreateFrame(data[0], data[1], data[2],
167 buffer_info.UsrData.sSystemBuffer.iWidth,
168 buffer_info.UsrData.sSystemBuffer.iHeight,
169 buffer_info.UsrData.sSystemBuffer.iStride[0],
170 buffer_info.UsrData.sSystemBuffer.iStride[1],
171 buffer_info.UsrData.sSystemBuffer.iStride[1]);
172 decoded_image_.set_timestamp(input_image._timeStamp);
173 decoded_image_.set_ntp_time_ms(input_image.ntp_time_ms_);
stefan-webrtc 2015/10/01 13:13:52 I think you have to call set_render_time_ms() too.
hbos 2015/11/27 14:43:42 Done. Looks like every encoder uses a different ti
174
175 // Deliver decoded image.
176 decoded_image_callback_->Decoded(decoded_image_);
177 }
178 return WEBRTC_VIDEO_CODEC_OK;
179 }
180
181 bool H264DecoderImpl::IsInitialized() {
182 return openh264_decoder_ != nullptr;
183 }
184
185 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698