1 diff --git a/examples/am7xxx-modeswitch.c b/examples/am7xxx-modeswitch.c
2 index c304515..4f132d6 100644
3 --- a/examples/am7xxx-modeswitch.c
4 +++ b/examples/am7xxx-modeswitch.c
5 @@ -46,7 +46,7 @@ int main(void)
9 - libusb_set_debug(NULL, LIBUSB_LOG_LEVEL_INFO);
10 + libusb_set_debug(NULL, 3);
12 usb_device = libusb_open_device_with_vid_pid(NULL,
14 diff --git a/examples/am7xxx-play.c b/examples/am7xxx-play.c
15 index 81aff84..1ee42e0 100644
16 --- a/examples/am7xxx-play.c
17 +++ b/examples/am7xxx-play.c
20 #include <libavdevice/avdevice.h>
21 #include <libavformat/avformat.h>
22 -#include <libavutil/imgutils.h>
23 #include <libswscale/swscale.h>
26 @@ -51,10 +50,10 @@ static int video_input_init(struct video_input_ctx *input_ctx,
28 AVInputFormat *input_format = NULL;
29 AVFormatContext *input_format_ctx;
30 - AVCodecParameters *input_codec_params;
31 AVCodecContext *input_codec_ctx;
37 avdevice_register_all();
38 @@ -99,32 +98,34 @@ static int video_input_init(struct video_input_ctx *input_ctx,
39 av_dump_format(input_format_ctx, 0, input_path, 0);
41 /* look for the first video_stream */
42 - video_index = av_find_best_stream(input_format_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, &input_codec, 0);
43 - if (video_index < 0) {
45 + for (i = 0; i < input_format_ctx->nb_streams; i++)
46 + if (input_format_ctx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
50 + if (video_index == -1) {
51 fprintf(stderr, "cannot find any video streams\n");
56 - input_codec_ctx = avcodec_alloc_context3(input_codec);
57 - if (input_codec_ctx == NULL) {
58 - fprintf(stderr, "failed to allocate the input codec context\n");
62 + /* get a pointer to the codec context for the video stream */
63 + input_codec_ctx = input_format_ctx->streams[video_index]->codec;
65 - input_codec_params = input_format_ctx->streams[video_index]->codecpar;
66 - ret = avcodec_parameters_to_context(input_codec_ctx, input_codec_params);
68 - fprintf(stderr, "cannot copy parameters to input codec context\n");
70 + /* find the decoder for the video stream */
71 + input_codec = avcodec_find_decoder(input_codec_ctx->codec_id);
72 + if (input_codec == NULL) {
73 + fprintf(stderr, "input_codec is NULL!\n");
78 /* open the decoder */
79 ret = avcodec_open2(input_codec_ctx, input_codec, NULL);
81 fprintf(stderr, "cannot open input codec\n");
86 input_ctx->format_ctx = input_format_ctx;
87 @@ -134,8 +135,6 @@ static int video_input_init(struct video_input_ctx *input_ctx,
92 - avcodec_free_context(&input_codec_ctx);
94 avformat_close_input(&input_format_ctx);
96 @@ -177,7 +176,7 @@ static int video_output_init(struct video_output_ctx *output_ctx,
100 - /* Calculate the new output dimension so the original frame is shown
101 + /* Calculate the new output dimension so the original picture is shown
103 ret = am7xxx_calc_scaled_image_dimensions(dev,
105 @@ -226,7 +225,7 @@ static int video_output_init(struct video_output_ctx *output_ctx,
106 output_codec_ctx->qmin = output_codec_ctx->qmax = ((100 - (quality - 1)) * FF_QUALITY_SCALE) / 100;
107 output_codec_ctx->mb_lmin = output_codec_ctx->qmin * FF_QP2LAMBDA;
108 output_codec_ctx->mb_lmax = output_codec_ctx->qmax * FF_QP2LAMBDA;
109 - output_codec_ctx->flags |= AV_CODEC_FLAG_QSCALE;
110 + output_codec_ctx->flags |= CODEC_FLAG_QSCALE;
111 output_codec_ctx->global_quality = output_codec_ctx->qmin * FF_QP2LAMBDA;
113 /* find the encoder */
114 @@ -257,67 +256,6 @@ out:
119 - * Wrap the new avcodec API from FFMpeg 3.1 to minimize the changes in the
122 - * If the use of the wrappers were to be made conditional, a check like the
123 - * following could be used:
125 - * #if (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 101))
127 - * As derived from the APIchanges document:
128 - * https://github.com/FFmpeg/FFmpeg/blob/master/doc/APIchanges
130 - * The wrapper implementation has been taken from:
131 - * https://blogs.gentoo.org/lu_zero/2016/03/29/new-avcodec-api/
133 -static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
140 - ret = avcodec_send_packet(avctx, pkt);
142 - * In particular, we don't expect AVERROR(EAGAIN), because we
143 - * read all decoded frames with avcodec_receive_frame() until
147 - return ret == AVERROR_EOF ? 0 : ret;
150 - ret = avcodec_receive_frame(avctx, frame);
151 - if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
159 -static int encode(AVCodecContext *avctx, AVPacket *pkt, int *got_packet, AVFrame *frame)
165 - ret = avcodec_send_frame(avctx, frame);
169 - ret = avcodec_receive_packet(avctx, pkt);
172 - if (ret == AVERROR(EAGAIN))
179 static int am7xxx_play(const char *input_format_string,
180 AVDictionary **input_options,
181 const char *input_path,
182 @@ -330,16 +268,16 @@ static int am7xxx_play(const char *input_format_string,
184 struct video_input_ctx input_ctx;
185 struct video_output_ctx output_ctx;
186 - AVFrame *frame_raw;
187 - AVFrame *frame_scaled;
188 + AVFrame *picture_raw;
189 + AVFrame *picture_scaled;
192 - int out_frame_size;
193 - uint8_t *out_frame;
194 + int out_picture_size;
195 + uint8_t *out_picture;
196 struct SwsContext *sw_scale_ctx;
204 @@ -356,44 +294,41 @@ static int am7xxx_play(const char *input_format_string,
207 /* allocate an input frame */
208 - frame_raw = av_frame_alloc();
209 - if (frame_raw == NULL) {
210 - fprintf(stderr, "cannot allocate the raw frame!\n");
211 + picture_raw = avcodec_alloc_frame();
212 + if (picture_raw == NULL) {
213 + fprintf(stderr, "cannot allocate the raw picture frame!\n");
218 /* allocate output frame */
219 - frame_scaled = av_frame_alloc();
220 - if (frame_scaled == NULL) {
221 - fprintf(stderr, "cannot allocate the scaled frame!\n");
222 + picture_scaled = avcodec_alloc_frame();
223 + if (picture_scaled == NULL) {
224 + fprintf(stderr, "cannot allocate the scaled picture!\n");
226 - goto cleanup_frame_raw;
227 + goto cleanup_picture_raw;
229 - frame_scaled->format = (output_ctx.codec_ctx)->pix_fmt;
230 - frame_scaled->width = (output_ctx.codec_ctx)->width;
231 - frame_scaled->height = (output_ctx.codec_ctx)->height;
232 + picture_scaled->format = (output_ctx.codec_ctx)->pix_fmt;
233 + picture_scaled->width = (output_ctx.codec_ctx)->width;
234 + picture_scaled->height = (output_ctx.codec_ctx)->height;
236 /* calculate the bytes needed for the output image and create buffer for the output image */
237 - out_buf_size = av_image_get_buffer_size((output_ctx.codec_ctx)->pix_fmt,
238 - (output_ctx.codec_ctx)->width,
239 - (output_ctx.codec_ctx)->height,
241 + out_buf_size = avpicture_get_size((output_ctx.codec_ctx)->pix_fmt,
242 + (output_ctx.codec_ctx)->width,
243 + (output_ctx.codec_ctx)->height);
244 out_buf = av_malloc(out_buf_size * sizeof(uint8_t));
245 if (out_buf == NULL) {
246 fprintf(stderr, "cannot allocate output data buffer!\n");
248 - goto cleanup_frame_scaled;
249 + goto cleanup_picture_scaled;
252 - /* assign appropriate parts of buffer to image planes in frame_scaled */
253 - av_image_fill_arrays(frame_scaled->data,
254 - frame_scaled->linesize,
256 - (output_ctx.codec_ctx)->pix_fmt,
257 - (output_ctx.codec_ctx)->width,
258 - (output_ctx.codec_ctx)->height,
260 + /* assign appropriate parts of buffer to image planes in picture_scaled */
261 + avpicture_fill((AVPicture *)picture_scaled,
263 + (output_ctx.codec_ctx)->pix_fmt,
264 + (output_ctx.codec_ctx)->width,
265 + (output_ctx.codec_ctx)->height);
267 sw_scale_ctx = sws_getCachedContext(NULL,
268 (input_ctx.codec_ctx)->width,
269 @@ -430,8 +365,8 @@ static int am7xxx_play(const char *input_format_string,
274 - ret = decode(input_ctx.codec_ctx, frame_raw, &got_frame, &in_packet);
276 + ret = avcodec_decode_video2(input_ctx.codec_ctx, picture_raw, &got_picture, &in_packet);
278 fprintf(stderr, "cannot decode video\n");
280 @@ -439,41 +374,41 @@ static int am7xxx_play(const char *input_format_string,
283 /* if we got the complete frame */
287 - * Rescaling the frame also changes its pixel format
288 + * Rescaling the picture also changes its pixel format
289 * to the raw format supported by the projector if
290 * this was set in video_output_init()
292 sws_scale(sw_scale_ctx,
293 - (const uint8_t * const *)frame_raw->data,
294 - frame_raw->linesize,
295 + (const uint8_t * const *)picture_raw->data,
296 + picture_raw->linesize,
298 (input_ctx.codec_ctx)->height,
299 - frame_scaled->data,
300 - frame_scaled->linesize);
301 + picture_scaled->data,
302 + picture_scaled->linesize);
304 if (output_ctx.raw_output) {
305 - out_frame = out_buf;
306 - out_frame_size = out_buf_size;
307 + out_picture = out_buf;
308 + out_picture_size = out_buf_size;
310 - frame_scaled->quality = (output_ctx.codec_ctx)->global_quality;
311 + picture_scaled->quality = (output_ctx.codec_ctx)->global_quality;
312 av_init_packet(&out_packet);
313 out_packet.data = NULL;
316 - ret = encode(output_ctx.codec_ctx,
320 + ret = avcodec_encode_video2(output_ctx.codec_ctx,
324 if (ret < 0 || !got_packet) {
325 fprintf(stderr, "cannot encode video\n");
330 - out_frame = out_packet.data;
331 - out_frame_size = out_packet.size;
332 + out_picture = out_packet.data;
333 + out_picture_size = out_packet.size;
337 @@ -485,7 +420,7 @@ static int am7xxx_play(const char *input_format_string,
339 snprintf(filename, NAME_MAX, "out.raw");
340 file = fopen(filename, "wb");
341 - fwrite(out_frame, 1, out_frame_size, file);
342 + fwrite(out_picture, 1, out_picture_size, file);
346 @@ -496,8 +431,8 @@ static int am7xxx_play(const char *input_format_string,
348 (output_ctx.codec_ctx)->width,
349 (output_ctx.codec_ctx)->height,
355 perror("am7xxx_send_image_async");
357 @@ -506,17 +441,17 @@ static int am7xxx_play(const char *input_format_string,
360 if (!output_ctx.raw_output && got_packet)
361 - av_packet_unref(&out_packet);
362 - av_packet_unref(&in_packet);
363 + av_free_packet(&out_packet);
364 + av_free_packet(&in_packet);
367 sws_freeContext(sw_scale_ctx);
370 -cleanup_frame_scaled:
371 - av_frame_free(&frame_scaled);
373 - av_frame_free(&frame_raw);
374 +cleanup_picture_scaled:
375 + avcodec_free_frame(&picture_scaled);
376 +cleanup_picture_raw:
377 + avcodec_free_frame(&picture_raw);
380 /* Freeing the codec context is needed as well,
381 @@ -527,7 +462,6 @@ cleanup_output:
384 avcodec_close(input_ctx.codec_ctx);
385 - avcodec_free_context(&(input_ctx.codec_ctx));
386 avformat_close_input(&(input_ctx.format_ctx));
389 diff --git a/src/am7xxx.c b/src/am7xxx.c
390 index 8573a59..fd726af 100644
393 @@ -1117,7 +1117,7 @@ AM7XXX_PUBLIC int am7xxx_init(am7xxx_context **ctx)
394 goto out_free_context;
397 - libusb_set_debug((*ctx)->usb_context, LIBUSB_LOG_LEVEL_INFO);
398 + libusb_set_debug((*ctx)->usb_context, 3);
400 ret = scan_devices(*ctx, SCAN_OP_BUILD_DEVLIST , 0, NULL);