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

Side by Side Diff: third_party/openh264/testing/h264_decoder_impl.cc

Issue 1446453004: Adding third_party/openh264 build files for encoding (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed torbjorng's comments Created 5 years, 1 month 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 // TODO(hbos): This is essentially a copy of an decoder class in WebRTC that as
13 // of this statement has not yet landed, but that I want to have accessible in
14 // Chromium before that CL lands. This is because I use it in order to validate
15 // the build files for OpenH264 and the WebRTC encoder/decoder CL cannot land
16 // until I can build OpenH264 from source. Once the build files are stable I
17 // will land both CLs and remove this copy of the decoder.
18
19 #include "openh264/testing/h264_decoder_impl.h"
20
21 #include <bitset>
22
23 // OpenH264
24 #include "openh264/src/codec/api/svc/codec_api.h"
25 #include "openh264/src/codec/api/svc/codec_app_def.h"
26 #include "openh264/src/codec/api/svc/codec_def.h"
27
28 #include "webrtc/base/checks.h"
29 #include "webrtc/base/logging.h"
30 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
31
32 using webrtc::VideoCodecType;
33
34 namespace openh264 {
35
36 namespace {
37 const bool kOpenH264DecoderDetailedLogging = false;
38 } // namespace
39
40 H264DecoderImpl::H264DecoderImpl()
41 : openh264_decoder_(nullptr),
42 decoded_image_(),
43 decoded_image_callback_(nullptr) {
44 }
45
46 H264DecoderImpl::~H264DecoderImpl() {
47 Release();
48 }
49
50 int32_t H264DecoderImpl::InitDecode(const VideoCodec* codec_settings,
51 int32_t /*number_of_cores*/) {
52 if (codec_settings &&
53 codec_settings->codecType != VideoCodecType::kVideoCodecH264) {
54 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
55 }
56
57 int release_ret = Release();
58 if (release_ret != WEBRTC_VIDEO_CODEC_OK)
59 return release_ret;
60 RTC_DCHECK(!openh264_decoder_);
61
62 // Create decoder.
63 if (WelsCreateDecoder(&openh264_decoder_) != 0) {
64 RTC_DCHECK(!openh264_decoder_);
65 return WEBRTC_VIDEO_CODEC_ERROR;
66 }
67 RTC_DCHECK(openh264_decoder_);
68 if (kOpenH264DecoderDetailedLogging) {
69 int trace_level = WELS_LOG_DETAIL;
70 openh264_decoder_->SetOption(DECODER_OPTION_TRACE_LEVEL,
71 &trace_level);
72 }
73 // else WELS_LOG_DEFAULT is used by default.
74
75 // Initialization parameters.
76 SDecodingParam init_params;
77 memset(&init_params, 0, sizeof(SDecodingParam));
78 init_params.eOutputColorFormat = EVideoFormatType::videoFormatI420;
79 init_params.uiCpuLoad = 0;
80 init_params.uiTargetDqLayer = 0xFF;
81 init_params.eEcActiveIdc = ERROR_CON_IDC::ERROR_CON_DISABLE;
82 init_params.bParseOnly = false;
83 init_params.sVideoProperty.eVideoBsType =
84 VIDEO_BITSTREAM_TYPE::VIDEO_BITSTREAM_DEFAULT;
85
86 // Initialize.
87 if (openh264_decoder_->Initialize(&init_params) != 0) {
88 Release();
89 return WEBRTC_VIDEO_CODEC_ERROR;
90 }
91
92 return WEBRTC_VIDEO_CODEC_OK;
93 }
94
95 int32_t H264DecoderImpl::Release() {
96 if (openh264_decoder_) {
97 openh264_decoder_->Uninitialize();
98 WelsDestroyDecoder(openh264_decoder_);
99 openh264_decoder_ = nullptr;
100 }
101 return WEBRTC_VIDEO_CODEC_OK;
102 }
103
104 int32_t H264DecoderImpl::Reset() {
105 if (!IsInitialized())
106 return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
107 InitDecode(nullptr, 1);
108 return WEBRTC_VIDEO_CODEC_OK;
109 }
110
111 int32_t H264DecoderImpl::RegisterDecodeCompleteCallback(
112 DecodedImageCallback* callback) {
113 decoded_image_callback_ = callback;
114 return WEBRTC_VIDEO_CODEC_OK;
115 }
116
117 int32_t H264DecoderImpl::Decode(const EncodedImage& input_image,
118 bool /*missing_frames*/,
119 const RTPFragmentationHeader* /*fragmentation*/,
120 const CodecSpecificInfo* codec_specific_info,
121 int64_t /*render_time_ms*/) {
122 if (!IsInitialized()) {
123 return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
124 }
125 if (!decoded_image_callback_) {
126 return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
127 }
128 if (!input_image._buffer || !input_image._length)
129 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
130 if (codec_specific_info &&
131 codec_specific_info->codecType != VideoCodecType::kVideoCodecH264) {
132 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
133 }
134
135 // DecodeFrameNoDelay output.
136 uint8_t* data[3] = { 0, 0, 0 };
137 SBufferInfo buffer_info;
138 memset(&buffer_info, 0, sizeof(SBufferInfo));
139
140 // Decode!
141 DECODING_STATE decode_ret = openh264_decoder_->DecodeFrameNoDelay(
142 input_image._buffer, static_cast<int>(input_image._length), data,
143 &buffer_info);
144 if (decode_ret != 0) {
145 return WEBRTC_VIDEO_CODEC_ERROR;
146 }
147 RTC_DCHECK_EQ(decode_ret, 0);
148
149 // Frame data ready?
150 if (buffer_info.iBufferStatus == 1) {
151 // Copy decoded data into |decoded_image_|. Must copy because the internal
152 // VideoFrameBuffer is reference counted.
153 decoded_image_.CreateFrame(data[0], data[1], data[2],
154 buffer_info.UsrData.sSystemBuffer.iWidth,
155 buffer_info.UsrData.sSystemBuffer.iHeight,
156 buffer_info.UsrData.sSystemBuffer.iStride[0],
157 buffer_info.UsrData.sSystemBuffer.iStride[1],
158 buffer_info.UsrData.sSystemBuffer.iStride[1]);
159 decoded_image_.set_timestamp(input_image._timeStamp);
160 decoded_image_.set_ntp_time_ms(input_image.ntp_time_ms_);
161
162 // Deliver decoded image.
163 decoded_image_callback_->Decoded(decoded_image_);
164 }
165 return WEBRTC_VIDEO_CODEC_OK;
166 }
167
168 bool H264DecoderImpl::IsInitialized() {
169 return openh264_decoder_ != nullptr;
170 }
171
172 } // namespace openh264
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698