This is cherrypicked from libav, from commits
82b7525173f20702a8cbc26ebedbf4b69b8fecec and
d0b1e6049b06eeeeca146ece4d2f199c5dba1565.
Signed-off-by: Martin Storsjö <martin@martin.st>
... | ... |
@@ -2771,6 +2771,8 @@ libopencore_amrnb_decoder_deps="libopencore_amrnb" |
2771 | 2771 |
libopencore_amrnb_encoder_deps="libopencore_amrnb" |
2772 | 2772 |
libopencore_amrnb_encoder_select="audio_frame_queue" |
2773 | 2773 |
libopencore_amrwb_decoder_deps="libopencore_amrwb" |
2774 |
+libopenh264_decoder_deps="libopenh264" |
|
2775 |
+libopenh264_decoder_select="h264_mp4toannexb_bsf" |
|
2774 | 2776 |
libopenh264_encoder_deps="libopenh264" |
2775 | 2777 |
libopenjpeg_decoder_deps="libopenjpeg" |
2776 | 2778 |
libopenjpeg_encoder_deps="libopenjpeg" |
... | ... |
@@ -103,12 +103,19 @@ enable it. |
103 | 103 |
|
104 | 104 |
@section OpenH264 |
105 | 105 |
|
106 |
-FFmpeg can make use of the OpenH264 library for H.264 encoding. |
|
106 |
+FFmpeg can make use of the OpenH264 library for H.264 encoding and decoding. |
|
107 | 107 |
|
108 | 108 |
Go to @url{http://www.openh264.org/} and follow the instructions for |
109 | 109 |
installing the library. Then pass @code{--enable-libopenh264} to configure to |
110 | 110 |
enable it. |
111 | 111 |
|
112 |
+For decoding, this library is much more limited than the built-in decoder |
|
113 |
+in libavcodec; currently, this library lacks support for decoding B-frames |
|
114 |
+and some other main/high profile features. (It currently only supports |
|
115 |
+constrained baseline profile and CABAC.) Using it is mostly useful for |
|
116 |
+testing and for taking advantage of Cisco's patent portfolio license |
|
117 |
+(@url{http://www.openh264.org/BINARY_LICENSE.txt}). |
|
118 |
+ |
|
112 | 119 |
@section x264 |
113 | 120 |
|
114 | 121 |
FFmpeg can make use of the x264 library for H.264 encoding. |
... | ... |
@@ -868,7 +868,8 @@ OBJS-$(CONFIG_LIBMP3LAME_ENCODER) += libmp3lame.o mpegaudiodata.o mpegau |
868 | 868 |
OBJS-$(CONFIG_LIBOPENCORE_AMRNB_DECODER) += libopencore-amr.o |
869 | 869 |
OBJS-$(CONFIG_LIBOPENCORE_AMRNB_ENCODER) += libopencore-amr.o |
870 | 870 |
OBJS-$(CONFIG_LIBOPENCORE_AMRWB_DECODER) += libopencore-amr.o |
871 |
-OBJS-$(CONFIG_LIBOPENH264_ENCODER) += libopenh264enc.o |
|
871 |
+OBJS-$(CONFIG_LIBOPENH264_DECODER) += libopenh264dec.o libopenh264.o |
|
872 |
+OBJS-$(CONFIG_LIBOPENH264_ENCODER) += libopenh264enc.o libopenh264.o |
|
872 | 873 |
OBJS-$(CONFIG_LIBOPENJPEG_DECODER) += libopenjpegdec.o |
873 | 874 |
OBJS-$(CONFIG_LIBOPENJPEG_ENCODER) += libopenjpegenc.o |
874 | 875 |
OBJS-$(CONFIG_LIBOPUS_DECODER) += libopusdec.o libopus.o \ |
... | ... |
@@ -623,7 +623,7 @@ void avcodec_register_all(void) |
623 | 623 |
|
624 | 624 |
/* external libraries, that shouldn't be used by default if one of the |
625 | 625 |
* above is available */ |
626 |
- REGISTER_ENCODER(LIBOPENH264, libopenh264); |
|
626 |
+ REGISTER_ENCDEC (LIBOPENH264, libopenh264); |
|
627 | 627 |
REGISTER_DECODER(H264_CUVID, h264_cuvid); |
628 | 628 |
REGISTER_ENCODER(H264_NVENC, h264_nvenc); |
629 | 629 |
REGISTER_ENCODER(H264_OMX, h264_omx); |
630 | 630 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,62 @@ |
0 |
+/* |
|
1 |
+ * OpenH264 shared utils |
|
2 |
+ * Copyright (C) 2014 Martin Storsjo |
|
3 |
+ * |
|
4 |
+ * This file is part of FFmpeg. |
|
5 |
+ * |
|
6 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
7 |
+ * modify it under the terms of the GNU Lesser General Public |
|
8 |
+ * License as published by the Free Software Foundation; either |
|
9 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
10 |
+ * |
|
11 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
12 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 |
+ * Lesser General Public License for more details. |
|
15 |
+ * |
|
16 |
+ * You should have received a copy of the GNU Lesser General Public |
|
17 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
18 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
19 |
+ */ |
|
20 |
+ |
|
21 |
+#include <string.h> |
|
22 |
+#include <wels/codec_api.h> |
|
23 |
+#include <wels/codec_ver.h> |
|
24 |
+ |
|
25 |
+#include "libavutil/log.h" |
|
26 |
+ |
|
27 |
+#include "libopenh264.h" |
|
28 |
+ |
|
29 |
+// Convert libopenh264 log level to equivalent ffmpeg log level. |
|
30 |
+static int libopenh264_to_ffmpeg_log_level(int libopenh264_log_level) |
|
31 |
+{ |
|
32 |
+ if (libopenh264_log_level >= WELS_LOG_DETAIL) return AV_LOG_TRACE; |
|
33 |
+ else if (libopenh264_log_level >= WELS_LOG_DEBUG) return AV_LOG_DEBUG; |
|
34 |
+ else if (libopenh264_log_level >= WELS_LOG_INFO) return AV_LOG_VERBOSE; |
|
35 |
+ else if (libopenh264_log_level >= WELS_LOG_WARNING) return AV_LOG_WARNING; |
|
36 |
+ else if (libopenh264_log_level >= WELS_LOG_ERROR) return AV_LOG_ERROR; |
|
37 |
+ else return AV_LOG_QUIET; |
|
38 |
+} |
|
39 |
+ |
|
40 |
+void ff_libopenh264_trace_callback(void *ctx, int level, const char *msg) |
|
41 |
+{ |
|
42 |
+ // The message will be logged only if the requested EQUIVALENT ffmpeg log level is |
|
43 |
+ // less than or equal to the current ffmpeg log level. |
|
44 |
+ int equiv_ffmpeg_log_level = libopenh264_to_ffmpeg_log_level(level); |
|
45 |
+ av_log(ctx, equiv_ffmpeg_log_level, "%s\n", msg); |
|
46 |
+} |
|
47 |
+ |
|
48 |
+int ff_libopenh264_check_version(void *logctx) |
|
49 |
+{ |
|
50 |
+ // Mingw GCC < 4.7 on x86_32 uses an incorrect/buggy ABI for the WelsGetCodecVersion |
|
51 |
+ // function (for functions returning larger structs), thus skip the check in those |
|
52 |
+ // configurations. |
|
53 |
+#if !defined(_WIN32) || !defined(__GNUC__) || !ARCH_X86_32 || AV_GCC_VERSION_AT_LEAST(4, 7) |
|
54 |
+ OpenH264Version libver = WelsGetCodecVersion(); |
|
55 |
+ if (memcmp(&libver, &g_stCodecVersion, sizeof(libver))) { |
|
56 |
+ av_log(logctx, AV_LOG_ERROR, "Incorrect library version loaded\n"); |
|
57 |
+ return AVERROR(EINVAL); |
|
58 |
+ } |
|
59 |
+#endif |
|
60 |
+ return 0; |
|
61 |
+} |
0 | 62 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,39 @@ |
0 |
+/* |
|
1 |
+ * OpenH264 shared utils |
|
2 |
+ * Copyright (C) 2014 Martin Storsjo |
|
3 |
+ * |
|
4 |
+ * This file is part of FFmpeg. |
|
5 |
+ * |
|
6 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
7 |
+ * modify it under the terms of the GNU Lesser General Public |
|
8 |
+ * License as published by the Free Software Foundation; either |
|
9 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
10 |
+ * |
|
11 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
12 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 |
+ * Lesser General Public License for more details. |
|
15 |
+ * |
|
16 |
+ * You should have received a copy of the GNU Lesser General Public |
|
17 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
18 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
19 |
+ */ |
|
20 |
+ |
|
21 |
+#ifndef AVCODEC_LIBOPENH264_H |
|
22 |
+#define AVCODEC_LIBOPENH264_H |
|
23 |
+ |
|
24 |
+#define OPENH264_VER_AT_LEAST(maj, min) \ |
|
25 |
+ ((OPENH264_MAJOR > (maj)) || \ |
|
26 |
+ (OPENH264_MAJOR == (maj) && OPENH264_MINOR >= (min))) |
|
27 |
+ |
|
28 |
+// This function will be provided to the libopenh264 library. The function will be called |
|
29 |
+// when libopenh264 wants to log a message (error, warning, info, etc.). The signature for |
|
30 |
+// this function (defined in .../codec/api/svc/codec_api.h) is: |
|
31 |
+// |
|
32 |
+// typedef void (*WelsTraceCallback) (void* ctx, int level, const char* string); |
|
33 |
+ |
|
34 |
+void ff_libopenh264_trace_callback(void *ctx, int level, const char *msg); |
|
35 |
+ |
|
36 |
+int ff_libopenh264_check_version(void *logctx); |
|
37 |
+ |
|
38 |
+#endif /* AVCODEC_LIBOPENH264_H */ |
0 | 39 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,243 @@ |
0 |
+/* |
|
1 |
+ * OpenH264 video decoder |
|
2 |
+ * Copyright (C) 2016 Martin Storsjo |
|
3 |
+ * |
|
4 |
+ * This file is part of FFmpeg. |
|
5 |
+ * |
|
6 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
7 |
+ * modify it under the terms of the GNU Lesser General Public |
|
8 |
+ * License as published by the Free Software Foundation; either |
|
9 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
10 |
+ * |
|
11 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
12 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 |
+ * Lesser General Public License for more details. |
|
15 |
+ * |
|
16 |
+ * You should have received a copy of the GNU Lesser General Public |
|
17 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
18 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
19 |
+ */ |
|
20 |
+ |
|
21 |
+#include <wels/codec_api.h> |
|
22 |
+#include <wels/codec_ver.h> |
|
23 |
+ |
|
24 |
+#include "libavutil/common.h" |
|
25 |
+#include "libavutil/fifo.h" |
|
26 |
+#include "libavutil/imgutils.h" |
|
27 |
+#include "libavutil/intreadwrite.h" |
|
28 |
+#include "libavutil/mathematics.h" |
|
29 |
+#include "libavutil/opt.h" |
|
30 |
+ |
|
31 |
+#include "avcodec.h" |
|
32 |
+#include "internal.h" |
|
33 |
+#include "libopenh264.h" |
|
34 |
+ |
|
35 |
+typedef struct SVCContext { |
|
36 |
+ ISVCDecoder *decoder; |
|
37 |
+ AVBSFContext *bsf; |
|
38 |
+ AVFifoBuffer *packet_fifo; |
|
39 |
+ AVPacket pkt_filtered; |
|
40 |
+} SVCContext; |
|
41 |
+ |
|
42 |
+static av_cold int svc_decode_close(AVCodecContext *avctx) |
|
43 |
+{ |
|
44 |
+ SVCContext *s = avctx->priv_data; |
|
45 |
+ AVPacket pkt; |
|
46 |
+ |
|
47 |
+ if (s->decoder) |
|
48 |
+ WelsDestroyDecoder(s->decoder); |
|
49 |
+ |
|
50 |
+ while (s->packet_fifo && av_fifo_size(s->packet_fifo) >= sizeof(pkt)) { |
|
51 |
+ av_fifo_generic_read(s->packet_fifo, &pkt, sizeof(pkt), NULL); |
|
52 |
+ av_packet_unref(&pkt); |
|
53 |
+ } |
|
54 |
+ |
|
55 |
+ av_bsf_free(&s->bsf); |
|
56 |
+ av_packet_unref(&s->pkt_filtered); |
|
57 |
+ av_fifo_free(s->packet_fifo); |
|
58 |
+ |
|
59 |
+ return 0; |
|
60 |
+} |
|
61 |
+ |
|
62 |
+static av_cold int svc_decode_init(AVCodecContext *avctx) |
|
63 |
+{ |
|
64 |
+ SVCContext *s = avctx->priv_data; |
|
65 |
+ SDecodingParam param = { 0 }; |
|
66 |
+ int err; |
|
67 |
+ int log_level; |
|
68 |
+ WelsTraceCallback callback_function; |
|
69 |
+ |
|
70 |
+ if ((err = ff_libopenh264_check_version(avctx)) < 0) |
|
71 |
+ return err; |
|
72 |
+ |
|
73 |
+ s->packet_fifo = av_fifo_alloc(sizeof(AVPacket)); |
|
74 |
+ if (!s->packet_fifo) { |
|
75 |
+ err = AVERROR(ENOMEM); |
|
76 |
+ goto fail; |
|
77 |
+ } |
|
78 |
+ |
|
79 |
+ if (WelsCreateDecoder(&s->decoder)) { |
|
80 |
+ av_log(avctx, AV_LOG_ERROR, "Unable to create decoder\n"); |
|
81 |
+ err = AVERROR_UNKNOWN; |
|
82 |
+ goto fail; |
|
83 |
+ } |
|
84 |
+ |
|
85 |
+ // Pass all libopenh264 messages to our callback, to allow ourselves to filter them. |
|
86 |
+ log_level = WELS_LOG_DETAIL; |
|
87 |
+ callback_function = ff_libopenh264_trace_callback; |
|
88 |
+ (*s->decoder)->SetOption(s->decoder, DECODER_OPTION_TRACE_LEVEL, &log_level); |
|
89 |
+ (*s->decoder)->SetOption(s->decoder, DECODER_OPTION_TRACE_CALLBACK, (void *)&callback_function); |
|
90 |
+ (*s->decoder)->SetOption(s->decoder, DECODER_OPTION_TRACE_CALLBACK_CONTEXT, (void *)&avctx); |
|
91 |
+ |
|
92 |
+ param.eOutputColorFormat = videoFormatI420; |
|
93 |
+ param.eEcActiveIdc = ERROR_CON_DISABLE; |
|
94 |
+ param.sVideoProperty.eVideoBsType = VIDEO_BITSTREAM_DEFAULT; |
|
95 |
+ |
|
96 |
+ if ((*s->decoder)->Initialize(s->decoder, ¶m) != cmResultSuccess) { |
|
97 |
+ av_log(avctx, AV_LOG_ERROR, "Initialize failed\n"); |
|
98 |
+ err = AVERROR_UNKNOWN; |
|
99 |
+ goto fail; |
|
100 |
+ } |
|
101 |
+ |
|
102 |
+ avctx->pix_fmt = AV_PIX_FMT_YUV420P; |
|
103 |
+ |
|
104 |
+fail: |
|
105 |
+ return err; |
|
106 |
+} |
|
107 |
+ |
|
108 |
+static int init_bsf(AVCodecContext *avctx) |
|
109 |
+{ |
|
110 |
+ SVCContext *s = avctx->priv_data; |
|
111 |
+ const AVBitStreamFilter *filter; |
|
112 |
+ int ret; |
|
113 |
+ |
|
114 |
+ if (s->bsf) |
|
115 |
+ return 0; |
|
116 |
+ |
|
117 |
+ // If the input stream already is annex b, this BSF only passes the |
|
118 |
+ // packets through unchanged. |
|
119 |
+ filter = av_bsf_get_by_name("h264_mp4toannexb"); |
|
120 |
+ if (!filter) |
|
121 |
+ return AVERROR_BUG; |
|
122 |
+ |
|
123 |
+ ret = av_bsf_alloc(filter, &s->bsf); |
|
124 |
+ if (ret < 0) |
|
125 |
+ return ret; |
|
126 |
+ |
|
127 |
+ ret = avcodec_parameters_from_context(s->bsf->par_in, avctx); |
|
128 |
+ if (ret < 0) |
|
129 |
+ return ret; |
|
130 |
+ |
|
131 |
+ s->bsf->time_base_in = avctx->time_base; |
|
132 |
+ |
|
133 |
+ ret = av_bsf_init(s->bsf); |
|
134 |
+ if (ret < 0) |
|
135 |
+ return ret; |
|
136 |
+ |
|
137 |
+ return ret; |
|
138 |
+} |
|
139 |
+ |
|
140 |
+static int svc_decode_frame(AVCodecContext *avctx, void *data, |
|
141 |
+ int *got_frame, AVPacket *avpkt) |
|
142 |
+{ |
|
143 |
+ SVCContext *s = avctx->priv_data; |
|
144 |
+ SBufferInfo info = { 0 }; |
|
145 |
+ uint8_t* ptrs[3]; |
|
146 |
+ int linesize[3]; |
|
147 |
+ AVFrame *avframe = data; |
|
148 |
+ int ret; |
|
149 |
+ DECODING_STATE state; |
|
150 |
+ |
|
151 |
+ if ((ret = init_bsf(avctx)) < 0) |
|
152 |
+ return ret; |
|
153 |
+ |
|
154 |
+ if (avpkt->size) { |
|
155 |
+ AVPacket input_ref = { 0 }; |
|
156 |
+ if (av_fifo_space(s->packet_fifo) < sizeof(input_ref)) { |
|
157 |
+ ret = av_fifo_realloc2(s->packet_fifo, |
|
158 |
+ av_fifo_size(s->packet_fifo) + sizeof(input_ref)); |
|
159 |
+ if (ret < 0) |
|
160 |
+ return ret; |
|
161 |
+ } |
|
162 |
+ |
|
163 |
+ ret = av_packet_ref(&input_ref, avpkt); |
|
164 |
+ if (ret < 0) |
|
165 |
+ return ret; |
|
166 |
+ av_fifo_generic_write(s->packet_fifo, &input_ref, sizeof(input_ref), NULL); |
|
167 |
+ } |
|
168 |
+ |
|
169 |
+ while (!*got_frame) { |
|
170 |
+ /* prepare the input data -- convert to Annex B if needed */ |
|
171 |
+ if (s->pkt_filtered.size <= 0) { |
|
172 |
+ AVPacket input_ref; |
|
173 |
+ |
|
174 |
+ /* no more data */ |
|
175 |
+ if (av_fifo_size(s->packet_fifo) < sizeof(AVPacket)) |
|
176 |
+ return avpkt->size ? avpkt->size : 0; |
|
177 |
+ |
|
178 |
+ av_packet_unref(&s->pkt_filtered); |
|
179 |
+ |
|
180 |
+ av_fifo_generic_read(s->packet_fifo, &input_ref, sizeof(input_ref), NULL); |
|
181 |
+ ret = av_bsf_send_packet(s->bsf, &input_ref); |
|
182 |
+ if (ret < 0) { |
|
183 |
+ av_packet_unref(&input_ref); |
|
184 |
+ return ret; |
|
185 |
+ } |
|
186 |
+ |
|
187 |
+ ret = av_bsf_receive_packet(s->bsf, &s->pkt_filtered); |
|
188 |
+ if (ret < 0) |
|
189 |
+ av_packet_move_ref(&s->pkt_filtered, &input_ref); |
|
190 |
+ else |
|
191 |
+ av_packet_unref(&input_ref); |
|
192 |
+ } |
|
193 |
+ |
|
194 |
+ state = (*s->decoder)->DecodeFrame2(s->decoder, s->pkt_filtered.data, s->pkt_filtered.size, ptrs, &info); |
|
195 |
+ s->pkt_filtered.size = 0; |
|
196 |
+ if (state != dsErrorFree) { |
|
197 |
+ av_log(avctx, AV_LOG_ERROR, "DecodeFrame2 failed\n"); |
|
198 |
+ return AVERROR_UNKNOWN; |
|
199 |
+ } |
|
200 |
+ if (info.iBufferStatus != 1) { |
|
201 |
+ av_log(avctx, AV_LOG_DEBUG, "No frame produced\n"); |
|
202 |
+ continue; |
|
203 |
+ } |
|
204 |
+ |
|
205 |
+ ret = ff_set_dimensions(avctx, info.UsrData.sSystemBuffer.iWidth, info.UsrData.sSystemBuffer.iHeight); |
|
206 |
+ if (ret < 0) |
|
207 |
+ return ret; |
|
208 |
+ // The decoder doesn't (currently) support decoding into a user |
|
209 |
+ // provided buffer, so do a copy instead. |
|
210 |
+ if (ff_get_buffer(avctx, avframe, 0) < 0) { |
|
211 |
+ av_log(avctx, AV_LOG_ERROR, "Unable to allocate buffer\n"); |
|
212 |
+ return AVERROR(ENOMEM); |
|
213 |
+ } |
|
214 |
+ |
|
215 |
+ linesize[0] = info.UsrData.sSystemBuffer.iStride[0]; |
|
216 |
+ linesize[1] = linesize[2] = info.UsrData.sSystemBuffer.iStride[1]; |
|
217 |
+ av_image_copy(avframe->data, avframe->linesize, (const uint8_t **) ptrs, linesize, avctx->pix_fmt, avctx->width, avctx->height); |
|
218 |
+ |
|
219 |
+ avframe->pts = s->pkt_filtered.pts; |
|
220 |
+ avframe->pkt_dts = s->pkt_filtered.dts; |
|
221 |
+ avframe->pkt_pts = s->pkt_filtered.pts; |
|
222 |
+ |
|
223 |
+ *got_frame = 1; |
|
224 |
+ } |
|
225 |
+ return avpkt->size; |
|
226 |
+} |
|
227 |
+ |
|
228 |
+AVCodec ff_libopenh264_decoder = { |
|
229 |
+ .name = "libopenh264", |
|
230 |
+ .long_name = NULL_IF_CONFIG_SMALL("OpenH264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"), |
|
231 |
+ .type = AVMEDIA_TYPE_VIDEO, |
|
232 |
+ .id = AV_CODEC_ID_H264, |
|
233 |
+ .priv_data_size = sizeof(SVCContext), |
|
234 |
+ .init = svc_decode_init, |
|
235 |
+ .decode = svc_decode_frame, |
|
236 |
+ .close = svc_decode_close, |
|
237 |
+ // The decoder doesn't currently support B-frames, and the decoder's API |
|
238 |
+ // doesn't support reordering/delay, but the BSF could incur delay. |
|
239 |
+ .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1, |
|
240 |
+ .caps_internal = FF_CODEC_CAP_SETS_PKT_DTS | FF_CODEC_CAP_INIT_THREADSAFE | |
|
241 |
+ FF_CODEC_CAP_INIT_CLEANUP, |
|
242 |
+}; |
... | ... |
@@ -31,6 +31,7 @@ |
31 | 31 |
|
32 | 32 |
#include "avcodec.h" |
33 | 33 |
#include "internal.h" |
34 |
+#include "libopenh264.h" |
|
34 | 35 |
|
35 | 36 |
typedef struct SVCContext { |
36 | 37 |
const AVClass *av_class; |
... | ... |
@@ -44,10 +45,6 @@ typedef struct SVCContext { |
44 | 44 |
int cabac; |
45 | 45 |
} SVCContext; |
46 | 46 |
|
47 |
-#define OPENH264_VER_AT_LEAST(maj, min) \ |
|
48 |
- ((OPENH264_MAJOR > (maj)) || \ |
|
49 |
- (OPENH264_MAJOR == (maj) && OPENH264_MINOR >= (min))) |
|
50 |
- |
|
51 | 47 |
#define OFFSET(x) offsetof(SVCContext, x) |
52 | 48 |
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM |
53 | 49 |
static const AVOption options[] = { |
... | ... |
@@ -68,31 +65,6 @@ static const AVClass class = { |
68 | 68 |
"libopenh264enc", av_default_item_name, options, LIBAVUTIL_VERSION_INT |
69 | 69 |
}; |
70 | 70 |
|
71 |
-// Convert libopenh264 log level to equivalent ffmpeg log level. |
|
72 |
-static int libopenh264_to_ffmpeg_log_level(int libopenh264_log_level) |
|
73 |
-{ |
|
74 |
- if (libopenh264_log_level >= WELS_LOG_DETAIL) return AV_LOG_TRACE; |
|
75 |
- else if (libopenh264_log_level >= WELS_LOG_DEBUG) return AV_LOG_DEBUG; |
|
76 |
- else if (libopenh264_log_level >= WELS_LOG_INFO) return AV_LOG_VERBOSE; |
|
77 |
- else if (libopenh264_log_level >= WELS_LOG_WARNING) return AV_LOG_WARNING; |
|
78 |
- else if (libopenh264_log_level >= WELS_LOG_ERROR) return AV_LOG_ERROR; |
|
79 |
- else return AV_LOG_QUIET; |
|
80 |
-} |
|
81 |
- |
|
82 |
-// This function will be provided to the libopenh264 library. The function will be called |
|
83 |
-// when libopenh264 wants to log a message (error, warning, info, etc.). The signature for |
|
84 |
-// this function (defined in .../codec/api/svc/codec_api.h) is: |
|
85 |
-// |
|
86 |
-// typedef void (*WelsTraceCallback) (void* ctx, int level, const char* string); |
|
87 |
- |
|
88 |
-static void libopenh264_trace_callback(void *ctx, int level, const char *msg) |
|
89 |
-{ |
|
90 |
- // The message will be logged only if the requested EQUIVALENT ffmpeg log level is |
|
91 |
- // less than or equal to the current ffmpeg log level. |
|
92 |
- int equiv_ffmpeg_log_level = libopenh264_to_ffmpeg_log_level(level); |
|
93 |
- av_log(ctx, equiv_ffmpeg_log_level, "%s\n", msg); |
|
94 |
-} |
|
95 |
- |
|
96 | 71 |
static av_cold int svc_encode_close(AVCodecContext *avctx) |
97 | 72 |
{ |
98 | 73 |
SVCContext *s = avctx->priv_data; |
... | ... |
@@ -108,21 +80,15 @@ static av_cold int svc_encode_init(AVCodecContext *avctx) |
108 | 108 |
{ |
109 | 109 |
SVCContext *s = avctx->priv_data; |
110 | 110 |
SEncParamExt param = { 0 }; |
111 |
- int err = AVERROR_UNKNOWN; |
|
111 |
+ int err; |
|
112 | 112 |
int log_level; |
113 | 113 |
WelsTraceCallback callback_function; |
114 | 114 |
AVCPBProperties *props; |
115 | 115 |
|
116 |
- // Mingw GCC < 4.7 on x86_32 uses an incorrect/buggy ABI for the WelsGetCodecVersion |
|
117 |
- // function (for functions returning larger structs), thus skip the check in those |
|
118 |
- // configurations. |
|
119 |
-#if !defined(_WIN32) || !defined(__GNUC__) || !ARCH_X86_32 || AV_GCC_VERSION_AT_LEAST(4, 7) |
|
120 |
- OpenH264Version libver = WelsGetCodecVersion(); |
|
121 |
- if (memcmp(&libver, &g_stCodecVersion, sizeof(libver))) { |
|
122 |
- av_log(avctx, AV_LOG_ERROR, "Incorrect library version loaded\n"); |
|
123 |
- return AVERROR(EINVAL); |
|
124 |
- } |
|
125 |
-#endif |
|
116 |
+ if ((err = ff_libopenh264_check_version(avctx)) < 0) |
|
117 |
+ return err; |
|
118 |
+ // Use a default error for multiple error paths below |
|
119 |
+ err = AVERROR_UNKNOWN; |
|
126 | 120 |
|
127 | 121 |
if (WelsCreateSVCEncoder(&s->encoder)) { |
128 | 122 |
av_log(avctx, AV_LOG_ERROR, "Unable to create encoder\n"); |
... | ... |
@@ -134,7 +100,7 @@ static av_cold int svc_encode_init(AVCodecContext *avctx) |
134 | 134 |
(*s->encoder)->SetOption(s->encoder, ENCODER_OPTION_TRACE_LEVEL, &log_level); |
135 | 135 |
|
136 | 136 |
// Set the logging callback function to one that uses av_log() (see implementation above). |
137 |
- callback_function = (WelsTraceCallback) libopenh264_trace_callback; |
|
137 |
+ callback_function = (WelsTraceCallback) ff_libopenh264_trace_callback; |
|
138 | 138 |
(*s->encoder)->SetOption(s->encoder, ENCODER_OPTION_TRACE_CALLBACK, (void *)&callback_function); |
139 | 139 |
|
140 | 140 |
// Set the AVCodecContext as the libopenh264 callback context so that it can be passed to av_log(). |
... | ... |
@@ -28,7 +28,7 @@ |
28 | 28 |
#include "libavutil/version.h" |
29 | 29 |
|
30 | 30 |
#define LIBAVCODEC_VERSION_MAJOR 57 |
31 |
-#define LIBAVCODEC_VERSION_MINOR 50 |
|
31 |
+#define LIBAVCODEC_VERSION_MINOR 51 |
|
32 | 32 |
#define LIBAVCODEC_VERSION_MICRO 100 |
33 | 33 |
|
34 | 34 |
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |