[ffmpeg] Update most deprecated functions

This commit is contained in:
ejurgensen 2016-01-05 23:22:01 +01:00
parent 7caf8cc66a
commit 0d55e055c0
4 changed files with 35 additions and 45 deletions

View File

@ -96,6 +96,8 @@ AC_CHECK_LIB([avfilter], [av_buffersink_get_frame],
AC_DEFINE(HAVE_LIBAV_BUFFERSINK_GET_FRAME, 1, [Define to 1 if you have ffmpeg/libav with av_buffersink_get_frame]))
AC_CHECK_LIB([avfilter], [avfilter_graph_parse_ptr],
AC_DEFINE(HAVE_LIBAV_GRAPH_PARSE_PTR, 1, [Define to 1 if you have ffmpeg/libav with avfilter_graph_parse_ptr]))
AC_CHECK_LIB([avcodec], [av_packet_unref],
AC_DEFINE(HAVE_LIBAV_PACKET_UNREF, 1, [Define to 1 if you have ffmpeg/libav with av_packet_unref]),,[-lavutil])
AC_CHECK_LIB([avcodec], [av_packet_rescale_ts],
AC_DEFINE(HAVE_LIBAV_PACKET_RESCALE_TS, 1, [Define to 1 if you have ffmpeg/libav with av_packet_rescale_ts]),,[-lavutil])
AC_CHECK_LIB([avformat], [avformat_alloc_output_context2],
@ -104,6 +106,8 @@ AC_CHECK_LIB([avutil], [av_frame_alloc],
AC_DEFINE(HAVE_LIBAV_FRAME_ALLOC, 1, [Define to 1 if you have ffmpeg/libav with av_frame_alloc]))
AC_CHECK_LIB([avutil], [av_frame_get_best_effort_timestamp],
AC_DEFINE(HAVE_LIBAV_BEST_EFFORT_TIMESTAMP, 1, [Define to 1 if you have ffmpeg/libav with av_frame_get_best_effort_timestamp]))
AC_CHECK_LIB([avutil], [av_image_get_buffer_size],
AC_DEFINE(HAVE_LIBAV_IMAGE_GET_BUFFER_SIZE, 1, [Define to 1 if you have ffmpeg/libav with av_image_get_buffer_size]))
AC_CHECK_HEADERS([libavutil/channel_layout.h])
AC_CHECK_HEADERS([libavutil/mathematics.h])

View File

@ -33,6 +33,7 @@
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libavutil/imgutils.h>
#include "db.h"
#include "misc.h"
@ -49,14 +50,7 @@
# include "spotify.h"
#endif
#ifndef HAVE_FFMPEG
# define avcodec_find_best_pix_fmt_of_list(a, b, c, d) avcodec_find_best_pix_fmt2((enum AVPixelFormat *)(a), (b), (c), (d))
#endif
#ifndef HAVE_LIBAV_FRAME_ALLOC
# define av_frame_alloc() avcodec_alloc_frame()
# define av_frame_free(x) avcodec_free_frame((x))
#endif
#include "ffmpeg-compat.h"
/* This artwork module will look for artwork by consulting a set of sources one
* at a time. A source is for instance the local library, the cache or a cover
@ -261,7 +255,6 @@ static int
artwork_rescale(struct evbuffer *evbuf, AVFormatContext *src_ctx, int s, int out_w, int out_h)
{
uint8_t *buf;
uint8_t *outbuf;
AVCodecContext *src;
@ -280,9 +273,6 @@ artwork_rescale(struct evbuffer *evbuf, AVFormatContext *src_ctx, int s, int out
AVPacket pkt;
int have_frame;
int outbuf_len;
int ret;
src = src_ctx->streams[s]->codec;
@ -414,7 +404,7 @@ artwork_rescale(struct evbuffer *evbuf, AVFormatContext *src_ctx, int s, int out
goto out_free_frames;
}
ret = avpicture_get_size(dst->pix_fmt, src->width, src->height);
ret = av_image_get_buffer_size(dst->pix_fmt, src->width, src->height, 1);
DPRINTF(E_DBG, L_ART, "Artwork buffer size: %d\n", ret);
@ -446,7 +436,7 @@ artwork_rescale(struct evbuffer *evbuf, AVFormatContext *src_ctx, int s, int out
{
if (pkt.stream_index != s)
{
av_free_packet(&pkt);
av_packet_unref(&pkt);
continue;
}
@ -458,7 +448,7 @@ artwork_rescale(struct evbuffer *evbuf, AVFormatContext *src_ctx, int s, int out
{
DPRINTF(E_LOG, L_ART, "Could not decode artwork\n");
av_free_packet(&pkt);
av_packet_unref(&pkt);
sws_freeContext(swsctx);
ret = -1;
@ -469,7 +459,7 @@ artwork_rescale(struct evbuffer *evbuf, AVFormatContext *src_ctx, int s, int out
sws_scale(swsctx, (const uint8_t * const *)i_frame->data, i_frame->linesize, 0, src->height, o_frame->data, o_frame->linesize);
sws_freeContext(swsctx);
av_free_packet(&pkt);
av_packet_unref(&pkt);
/* Open output file */
dst_ctx->pb = avio_output_evbuffer_open(evbuf);
@ -482,31 +472,12 @@ artwork_rescale(struct evbuffer *evbuf, AVFormatContext *src_ctx, int s, int out
}
/* Encode frame */
outbuf_len = dst->width * dst->height * 3;
if (outbuf_len < FF_MIN_BUFFER_SIZE)
outbuf_len = FF_MIN_BUFFER_SIZE;
outbuf = (uint8_t *)av_malloc(outbuf_len);
if (!outbuf)
{
DPRINTF(E_LOG, L_ART, "Out of memory for encoded artwork buffer\n");
avio_evbuffer_close(dst_ctx->pb);
ret = -1;
goto out_free_buf;
}
av_init_packet(&pkt);
pkt.data = outbuf;
pkt.size = outbuf_len;
pkt.data = NULL;
pkt.size = 0;
ret = avcodec_encode_video2(dst, &pkt, o_frame, &have_frame);
if (!ret && have_frame && dst->coded_frame)
{
dst->coded_frame->pts = pkt.pts;
dst->coded_frame->key_frame = !!(pkt.flags & AV_PKT_FLAG_KEY);
}
else if (ret < 0)
if (ret < 0)
{
DPRINTF(E_LOG, L_ART, "Could not encode artwork\n");
@ -560,7 +531,7 @@ artwork_rescale(struct evbuffer *evbuf, AVFormatContext *src_ctx, int s, int out
out_fclose_dst:
avio_evbuffer_close(dst_ctx->pb);
av_free(outbuf);
av_packet_unref(&pkt);
out_free_buf:
av_free(buf);

View File

@ -1,3 +1,6 @@
#ifndef __FFMPEG_COMPAT_H__
#define __FFMPEG_COMPAT_H__
#ifdef HAVE_LIBAVUTIL_CHANNEL_LAYOUT_H
# include <libavutil/channel_layout.h>
#endif
@ -19,6 +22,14 @@
# define av_frame_get_best_effort_timestamp(x) (x)->pts
#endif
#ifndef HAVE_LIBAV_IMAGE_GET_BUFFER_SIZE
# define av_image_get_buffer_size(a, b, c, d) avpicture_get_size((a), (b), (c))
#endif
#ifndef HAVE_LIBAV_PACKET_UNREF
# define av_packet_unref(a) av_free_packet((a))
#endif
#ifndef HAVE_LIBAV_PACKET_RESCALE_TS
static void
av_packet_rescale_ts(AVPacket *pkt, AVRational src_tb, AVRational dst_tb)
@ -35,6 +46,8 @@ av_packet_rescale_ts(AVPacket *pkt, AVRational src_tb, AVRational dst_tb)
#endif
#ifndef HAVE_LIBAV_ALLOC_OUTPUT_CONTEXT2
# include <libavutil/opt.h>
static int
avformat_alloc_output_context2(AVFormatContext **avctx, AVOutputFormat *oformat, const char *format, const char *filename)
{
@ -88,3 +101,5 @@ error:
return ret;
}
#endif
#endif /* !__FFMPEG_COMPAT_H__ */

View File

@ -36,7 +36,7 @@
#ifdef HAVE_LIBAVFILTER
# include <libavfilter/avcodec.h>
#else
# include "ffmpeg-compat.c"
# include "ffmpeg-compat.h"
#endif
#include "logger.h"
@ -285,7 +285,7 @@ static int decode_interrupt_cb(void *arg)
* packet will be updated, and packet->data is pointed to the data
* returned by av_read_frame(). The packet struct is owned by the
* caller, but *not* packet->data, so don't free the packet with
* av_free_packet()
* av_free_packet()/av_packet_unref()
* @out stream Set to the input AVStream corresponding to the packet
* @out stream_index
* Set to the input stream index corresponding to the packet
@ -314,7 +314,7 @@ read_packet(AVPacket *packet, AVStream **stream, unsigned int *stream_index, str
{
// We are going to read a new packet from source, so now it is safe to
// discard the previous packet and reset resume_offset
av_free_packet(&ctx->packet);
av_packet_unref(&ctx->packet);
ctx->resume_offset = 0;
ctx->timestamp = av_gettime();
@ -1441,7 +1441,7 @@ transcode_needed(const char *user_agent, const char *client_codecs, char *file_c
void
transcode_decode_cleanup(struct decode_ctx *ctx)
{
av_free_packet(&ctx->packet);
av_packet_unref(&ctx->packet);
close_input(ctx);
free(ctx);
}
@ -1735,7 +1735,7 @@ transcode_seek(struct transcode_ctx *ctx, int ms)
in_stream->codec->skip_frame = AVDISCARD_NONREF;
while (1)
{
av_free_packet(&decode_ctx->packet);
av_packet_unref(&decode_ctx->packet);
decode_ctx->timestamp = av_gettime();