1 /*
2 * OpenH264 video decoder
3 * Copyright (C) 2016 Martin Storsjo
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <wels/codec_api.h>
23 #include <wels/codec_ver.h>
24
31
36
40
42 {
44
46 WelsDestroyDecoder(
s->decoder);
47
48 return 0;
49 }
50
52 {
54 SDecodingParam param = { 0 };
55 int log_level;
56 WelsTraceCallback callback_function;
57
58 if (WelsCreateDecoder(&
s->decoder)) {
61 }
62
63 // Pass all libopenh264 messages to our callback, to allow ourselves to filter them.
64 log_level = WELS_LOG_DETAIL;
66 (*
s->decoder)->SetOption(
s->decoder, DECODER_OPTION_TRACE_LEVEL, &log_level);
67 (*
s->decoder)->SetOption(
s->decoder, DECODER_OPTION_TRACE_CALLBACK, (
void *)&callback_function);
68 (*
s->decoder)->SetOption(
s->decoder, DECODER_OPTION_TRACE_CALLBACK_CONTEXT, (
void *)&avctx);
69
70 #if !OPENH264_VER_AT_LEAST(1, 6)
71 param.eOutputColorFormat = videoFormatI420;
72 #endif
73 param.eEcActiveIdc = ERROR_CON_DISABLE;
74 param.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;
75
76 if ((*
s->decoder)->Initialize(
s->decoder, ¶m) != cmResultSuccess) {
79 }
80
82
83 return 0;
84 }
85
88 {
90 SBufferInfo
info = { 0 };
91 uint8_t *ptrs[4] = {
NULL };
94 #if OPENH264_VER_AT_LEAST(1, 7)
95 int opt;
96 #endif
97
99 #if OPENH264_VER_AT_LEAST(1, 9)
101 (*
s->decoder)->SetOption(
s->decoder, DECODER_OPTION_END_OF_STREAM, &
end_of_stream);
102 state = (*
s->decoder)->FlushFrame(
s->decoder, ptrs, &
info);
103 #else
104 return 0;
105 #endif
106 } else {
107 info.uiInBsTimeStamp = avpkt->
pts;
108 #if OPENH264_VER_AT_LEAST(1, 4)
109 // Contrary to the name, DecodeFrameNoDelay actually does buffering
110 // and reordering of frames, and is the recommended decoding entry
111 // point since 1.4. This is essential for successfully decoding
112 // B-frames.
113 state = (*
s->decoder)->DecodeFrameNoDelay(
s->decoder, avpkt->
data, avpkt->
size, ptrs, &
info);
114 #else
116 #endif
117 }
118 if (
state != dsErrorFree) {
121 }
122 if (
info.iBufferStatus != 1) {
125 }
126
130 // The decoder doesn't (currently) support decoding into a user
131 // provided buffer, so do a copy instead.
135 }
136
137 linesize[0] =
info.UsrData.sSystemBuffer.iStride[0];
138 linesize[1] = linesize[2] =
info.UsrData.sSystemBuffer.iStride[1];
139 linesize[3] = 0;
142
143 avframe->
pts =
info.uiOutYuvTimeStamp;
145 #if OPENH264_VER_AT_LEAST(1, 7)
146 (*
s->decoder)->GetOption(
s->decoder, DECODER_OPTION_PROFILE, &opt);
148 (*
s->decoder)->GetOption(
s->decoder, DECODER_OPTION_LEVEL, &opt);
150 #endif
151
152 *got_frame = 1;
154 }
155
157 .
p.
name =
"libopenh264",
168 .bsfs = "h264_mp4toannexb",
169 .p.wrapper_name = "libopenh264",
170 };