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
35
39
41 {
43
45 WelsDestroyDecoder(
s->decoder);
46
47 return 0;
48 }
49
51 {
53 SDecodingParam param = { 0 };
54 int err;
55 int log_level;
56 WelsTraceCallback callback_function;
57
59 return err;
60
61 if (WelsCreateDecoder(&
s->decoder)) {
64 }
65
66 // Pass all libopenh264 messages to our callback, to allow ourselves to filter them.
67 log_level = WELS_LOG_DETAIL;
69 (*
s->decoder)->SetOption(
s->decoder, DECODER_OPTION_TRACE_LEVEL, &log_level);
70 (*
s->decoder)->SetOption(
s->decoder, DECODER_OPTION_TRACE_CALLBACK, (
void *)&callback_function);
71 (*
s->decoder)->SetOption(
s->decoder, DECODER_OPTION_TRACE_CALLBACK_CONTEXT, (
void *)&avctx);
72
73 #if !OPENH264_VER_AT_LEAST(1, 6)
74 param.eOutputColorFormat = videoFormatI420;
75 #endif
76 param.eEcActiveIdc = ERROR_CON_DISABLE;
77 param.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT;
78
79 if ((*
s->decoder)->Initialize(
s->decoder, ¶m) != cmResultSuccess) {
82 }
83
85
86 return 0;
87 }
88
91 {
93 SBufferInfo
info = { 0 };
94 uint8_t *ptrs[4] = {
NULL };
98 #if OPENH264_VER_AT_LEAST(1, 7)
99 int opt;
100 #endif
101
103 #if OPENH264_VER_AT_LEAST(1, 9)
105 (*
s->decoder)->SetOption(
s->decoder, DECODER_OPTION_END_OF_STREAM, &
end_of_stream);
106 state = (*
s->decoder)->FlushFrame(
s->decoder, ptrs, &
info);
107 #else
108 return 0;
109 #endif
110 } else {
111 info.uiInBsTimeStamp = avpkt->
pts;
112 #if OPENH264_VER_AT_LEAST(1, 4)
113 // Contrary to the name, DecodeFrameNoDelay actually does buffering
114 // and reordering of frames, and is the recommended decoding entry
115 // point since 1.4. This is essential for successfully decoding
116 // B-frames.
117 state = (*
s->decoder)->DecodeFrameNoDelay(
s->decoder, avpkt->
data, avpkt->
size, ptrs, &
info);
118 #else
120 #endif
121 }
122 if (
state != dsErrorFree) {
125 }
126 if (
info.iBufferStatus != 1) {
129 }
130
134 // The decoder doesn't (currently) support decoding into a user
135 // provided buffer, so do a copy instead.
139 }
140
141 linesize[0] =
info.UsrData.sSystemBuffer.iStride[0];
142 linesize[1] = linesize[2] =
info.UsrData.sSystemBuffer.iStride[1];
143 linesize[3] = 0;
145
146 avframe->
pts =
info.uiOutYuvTimeStamp;
148 #if OPENH264_VER_AT_LEAST(1, 7)
149 (*
s->decoder)->GetOption(
s->decoder, DECODER_OPTION_PROFILE, &opt);
151 (*
s->decoder)->GetOption(
s->decoder, DECODER_OPTION_LEVEL, &opt);
153 #endif
154
155 *got_frame = 1;
157 }
158
160 .
name =
"libopenh264",
171 .bsfs = "h264_mp4toannexb",
172 .wrapper_name = "libopenh264",
173 };