mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-28 08:05:56 -05:00
Cleaning up deprecated ffmpeg/libav
This commit is contained in:
parent
c1c171e21f
commit
3471b6c147
@ -136,7 +136,11 @@ artwork_rescale(AVFormatContext *src_ctx, int s, int out_w, int out_h, int forma
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if LIBAVCODEC_VERSION_MAJOR >= 54 || (LIBAVCODEC_VERSION_MAJOR == 53 && LIBAVCODEC_VERSION_MINOR >= 6)
|
||||
ret = avcodec_open2(src, img_decoder, NULL);
|
||||
#else
|
||||
ret = avcodec_open(src, img_decoder);
|
||||
#endif
|
||||
if (ret < 0)
|
||||
{
|
||||
DPRINTF(E_LOG, L_ART, "Could not open codec for decoding: %s\n", strerror(AVUNERROR(ret)));
|
||||
@ -209,7 +213,11 @@ artwork_rescale(AVFormatContext *src_ctx, int s, int out_w, int out_h, int forma
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LIBAVFORMAT_VERSION_MAJOR >= 54 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 21)
|
||||
dst_st = avformat_new_stream(dst_ctx, NULL);
|
||||
#else
|
||||
dst_st = av_new_stream(dst_ctx, 0);
|
||||
#endif
|
||||
if (!dst_st)
|
||||
{
|
||||
DPRINTF(E_LOG, L_ART, "Out of memory for new output stream\n");
|
||||
@ -220,10 +228,10 @@ artwork_rescale(AVFormatContext *src_ctx, int s, int out_w, int out_h, int forma
|
||||
|
||||
dst = dst_st->codec;
|
||||
|
||||
#if LIBAVCODEC_VERSION_MAJOR >= 53 || (LIBAVCODEC_VERSION_MAJOR == 52 && LIBAVCODEC_VERSION_MINOR >= 64)
|
||||
avcodec_get_context_defaults2(dst, AVMEDIA_TYPE_VIDEO);
|
||||
#if LIBAVCODEC_VERSION_MAJOR >= 54 || (LIBAVCODEC_VERSION_MAJOR == 53 && LIBAVCODEC_VERSION_MINOR >= 35)
|
||||
avcodec_get_context_defaults3(dst, NULL);
|
||||
#else
|
||||
avcodec_get_context_defaults2(dst, CODEC_TYPE_VIDEO);
|
||||
avcodec_get_context_defaults2(dst, AVMEDIA_TYPE_VIDEO);
|
||||
#endif
|
||||
|
||||
if (dst_fmt->flags & AVFMT_GLOBALHEADER)
|
||||
@ -262,7 +270,7 @@ artwork_rescale(AVFormatContext *src_ctx, int s, int out_w, int out_h, int forma
|
||||
dst->width = out_w;
|
||||
dst->height = out_h;
|
||||
|
||||
#if LIBAVFORMAT_VERSION_MAJOR <= 52 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVCODEC_VERSION_MINOR <= 1)
|
||||
#if LIBAVFORMAT_VERSION_MAJOR <= 52 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR <= 1)
|
||||
ret = av_set_parameters(dst_ctx, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
@ -274,7 +282,11 @@ artwork_rescale(AVFormatContext *src_ctx, int s, int out_w, int out_h, int forma
|
||||
#endif
|
||||
|
||||
/* Open encoder */
|
||||
#if LIBAVCODEC_VERSION_MAJOR >= 54 || (LIBAVCODEC_VERSION_MAJOR == 53 && LIBAVCODEC_VERSION_MINOR >= 6)
|
||||
ret = avcodec_open2(dst, img_encoder, NULL);
|
||||
#else
|
||||
ret = avcodec_open(dst, img_encoder);
|
||||
#endif
|
||||
if (ret < 0)
|
||||
{
|
||||
DPRINTF(E_LOG, L_ART, "Could not open codec for encoding: %s\n", strerror(AVUNERROR(ret)));
|
||||
@ -410,7 +422,7 @@ artwork_rescale(AVFormatContext *src_ctx, int s, int out_w, int out_h, int forma
|
||||
pkt.data = outbuf;
|
||||
pkt.size = ret;
|
||||
|
||||
#if LIBAVFORMAT_VERSION_MAJOR >= 53 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVCODEC_VERSION_MINOR >= 3)
|
||||
#if LIBAVFORMAT_VERSION_MAJOR >= 53 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 3)
|
||||
ret = avformat_write_header(dst_ctx, NULL);
|
||||
#else
|
||||
ret = av_write_header(dst_ctx);
|
||||
@ -505,7 +517,7 @@ artwork_get(char *filename, int max_w, int max_h, int format, struct evbuffer *e
|
||||
|
||||
src_ctx = NULL;
|
||||
|
||||
#if LIBAVFORMAT_VERSION_MAJOR >= 53 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVCODEC_VERSION_MINOR >= 3)
|
||||
#if LIBAVFORMAT_VERSION_MAJOR >= 53 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 3)
|
||||
ret = avformat_open_input(&src_ctx, filename, NULL, NULL);
|
||||
#else
|
||||
ret = av_open_input_file(&src_ctx, filename, NULL, 0, NULL);
|
||||
@ -517,12 +529,20 @@ artwork_get(char *filename, int max_w, int max_h, int format, struct evbuffer *e
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if LIBAVFORMAT_VERSION_MAJOR >= 53 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 3)
|
||||
ret = avformat_find_stream_info(src_ctx, NULL);
|
||||
#else
|
||||
ret = av_find_stream_info(src_ctx);
|
||||
#endif
|
||||
if (ret < 0)
|
||||
{
|
||||
DPRINTF(E_WARN, L_ART, "Cannot get stream info: %s\n", strerror(AVUNERROR(ret)));
|
||||
|
||||
#if LIBAVFORMAT_VERSION_MAJOR >= 54 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 21)
|
||||
avformat_close_input(&src_ctx);
|
||||
#else
|
||||
av_close_input_file(src_ctx);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -545,7 +565,11 @@ artwork_get(char *filename, int max_w, int max_h, int format, struct evbuffer *e
|
||||
{
|
||||
DPRINTF(E_LOG, L_ART, "Artwork file '%s' not a PNG or JPEG file\n", filename);
|
||||
|
||||
#if LIBAVFORMAT_VERSION_MAJOR >= 54 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 21)
|
||||
avformat_close_input(&src_ctx);
|
||||
#else
|
||||
av_close_input_file(src_ctx);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -602,7 +626,11 @@ artwork_get(char *filename, int max_w, int max_h, int format, struct evbuffer *e
|
||||
else
|
||||
ret = artwork_rescale(src_ctx, s, target_w, target_h, format, evbuf);
|
||||
|
||||
#if LIBAVFORMAT_VERSION_MAJOR >= 54 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 21)
|
||||
avformat_close_input(&src_ctx);
|
||||
#else
|
||||
av_close_input_file(src_ctx);
|
||||
#endif
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
|
@ -329,7 +329,7 @@ scan_metadata_ffmpeg(char *file, struct media_file_info *mfi)
|
||||
|
||||
ctx = NULL;
|
||||
|
||||
#if LIBAVFORMAT_VERSION_MAJOR >= 53 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVCODEC_VERSION_MINOR >= 3)
|
||||
#if LIBAVFORMAT_VERSION_MAJOR >= 53 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 3)
|
||||
ret = avformat_open_input(&ctx, file, NULL, NULL);
|
||||
#else
|
||||
ret = av_open_input_file(&ctx, file, NULL, 0, NULL);
|
||||
@ -341,18 +341,26 @@ scan_metadata_ffmpeg(char *file, struct media_file_info *mfi)
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if LIBAVFORMAT_VERSION_MAJOR >= 53 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 3)
|
||||
ret = avformat_find_stream_info(ctx, NULL);
|
||||
#else
|
||||
ret = av_find_stream_info(ctx);
|
||||
#endif
|
||||
if (ret < 0)
|
||||
{
|
||||
DPRINTF(E_WARN, L_SCAN, "Cannot get stream info: %s\n", strerror(AVUNERROR(ret)));
|
||||
|
||||
#if LIBAVFORMAT_VERSION_MAJOR >= 54 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 21)
|
||||
avformat_close_input(&ctx);
|
||||
#else
|
||||
av_close_input_file(ctx);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* Dump input format as determined by ffmpeg */
|
||||
# if LIBAVFORMAT_VERSION_MAJOR >= 52 || (LIBAVFORMAT_VERSION_MAJOR == 52 && LIBAVCODEC_VERSION_MINOR >= 101)
|
||||
# if LIBAVFORMAT_VERSION_MAJOR >= 52 || (LIBAVFORMAT_VERSION_MAJOR == 52 && LIBAVFORMAT_VERSION_MINOR >= 101)
|
||||
av_dump_format(ctx, 0, file, 0);
|
||||
# else
|
||||
dump_format(ctx, 0, file, FALSE);
|
||||
@ -408,7 +416,11 @@ scan_metadata_ffmpeg(char *file, struct media_file_info *mfi)
|
||||
{
|
||||
DPRINTF(E_DBG, L_SCAN, "File has no audio streams, discarding\n");
|
||||
|
||||
#if LIBAVFORMAT_VERSION_MAJOR >= 54 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 21)
|
||||
avformat_close_input(&ctx);
|
||||
#else
|
||||
av_close_input_file(ctx);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -462,7 +474,7 @@ scan_metadata_ffmpeg(char *file, struct media_file_info *mfi)
|
||||
DPRINTF(E_DBG, L_SCAN, "ALAC\n");
|
||||
mfi->type = strdup("m4a");
|
||||
mfi->codectype = strdup("alac");
|
||||
mfi->description = strdup("AAC audio file");
|
||||
mfi->description = strdup("Apple Lossless audio file");
|
||||
break;
|
||||
|
||||
case CODEC_ID_FLAC:
|
||||
@ -617,7 +629,11 @@ scan_metadata_ffmpeg(char *file, struct media_file_info *mfi)
|
||||
{
|
||||
DPRINTF(E_WARN, L_SCAN, "Falling back to legacy WMA scanner\n");
|
||||
|
||||
#if LIBAVFORMAT_VERSION_MAJOR >= 54 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 21)
|
||||
avformat_close_input(&ctx);
|
||||
#else
|
||||
av_close_input_file(ctx);
|
||||
#endif
|
||||
return (scan_get_wmainfo(file, mfi) ? 0 : -1);
|
||||
}
|
||||
#ifdef FLAC
|
||||
@ -625,7 +641,11 @@ scan_metadata_ffmpeg(char *file, struct media_file_info *mfi)
|
||||
{
|
||||
DPRINTF(E_WARN, L_SCAN, "Falling back to legacy FLAC scanner\n");
|
||||
|
||||
#if LIBAVFORMAT_VERSION_MAJOR >= 54 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 21)
|
||||
avformat_close_input(&ctx);
|
||||
#else
|
||||
av_close_input_file(ctx);
|
||||
#endif
|
||||
return (scan_get_flacinfo(file, mfi) ? 0 : -1);
|
||||
}
|
||||
#endif /* FLAC */
|
||||
@ -635,7 +655,11 @@ scan_metadata_ffmpeg(char *file, struct media_file_info *mfi)
|
||||
{
|
||||
DPRINTF(E_WARN, L_SCAN, "Falling back to legacy Musepack scanner\n");
|
||||
|
||||
#if LIBAVFORMAT_VERSION_MAJOR >= 54 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 21)
|
||||
avformat_close_input(&ctx);
|
||||
#else
|
||||
av_close_input_file(ctx);
|
||||
#endif
|
||||
return (scan_get_mpcinfo(file, mfi) ? 0 : -1);
|
||||
}
|
||||
#endif /* MUSEPACK */
|
||||
@ -648,7 +672,11 @@ scan_metadata_ffmpeg(char *file, struct media_file_info *mfi)
|
||||
mfi->title = strdup(mfi->fname);
|
||||
|
||||
/* All done */
|
||||
#if LIBAVFORMAT_VERSION_MAJOR >= 54 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 21)
|
||||
avformat_close_input(&ctx);
|
||||
#else
|
||||
av_close_input_file(ctx);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -147,6 +147,10 @@ transcode(struct transcode_ctx *ctx, struct evbuffer *evbuf, int wanted)
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
int i;
|
||||
#endif
|
||||
#if LIBAVCODEC_VERSION_MAJOR >= 54 || (LIBAVCODEC_VERSION_MAJOR == 53 && LIBAVCODEC_VERSION_MINOR >= 35)
|
||||
AVFrame frame;
|
||||
int got_frame = 0;
|
||||
#endif
|
||||
|
||||
processed = 0;
|
||||
|
||||
@ -165,15 +169,20 @@ transcode(struct transcode_ctx *ctx, struct evbuffer *evbuf, int wanted)
|
||||
{
|
||||
buflen = XCODE_BUFFER_SIZE;
|
||||
|
||||
#if LIBAVCODEC_VERSION_MAJOR >= 53 || (LIBAVCODEC_VERSION_MAJOR == 52 && LIBAVCODEC_VERSION_MINOR >= 32)
|
||||
/* FFmpeg 0.6 */
|
||||
#if LIBAVCODEC_VERSION_MAJOR >= 54 || (LIBAVCODEC_VERSION_MAJOR == 53 && LIBAVCODEC_VERSION_MINOR >= 35)
|
||||
if (ctx->acodec->get_buffer != avcodec_default_get_buffer)
|
||||
{
|
||||
DPRINTF(E_LOG, L_XCODE, "Custom get_buffer - not allowed by ffmpeg/libav!\n");
|
||||
|
||||
ctx->acodec->get_buffer = avcodec_default_get_buffer;
|
||||
}
|
||||
used = avcodec_decode_audio4(ctx->acodec,
|
||||
&frame, &got_frame,
|
||||
&ctx->apacket2);
|
||||
#else
|
||||
used = avcodec_decode_audio3(ctx->acodec,
|
||||
ctx->abuffer, &buflen,
|
||||
&ctx->apacket2);
|
||||
#else
|
||||
used = avcodec_decode_audio2(ctx->acodec,
|
||||
ctx->abuffer, &buflen,
|
||||
ctx->apacket2.data, ctx->apacket2.size);
|
||||
#endif
|
||||
|
||||
if (used < 0)
|
||||
@ -186,9 +195,42 @@ transcode(struct transcode_ctx *ctx, struct evbuffer *evbuf, int wanted)
|
||||
ctx->apacket2.data += used;
|
||||
ctx->apacket2.size -= used;
|
||||
|
||||
#if LIBAVCODEC_VERSION_MAJOR >= 54 || (LIBAVCODEC_VERSION_MAJOR == 53 && LIBAVCODEC_VERSION_MINOR >= 35)
|
||||
/* This part is from the libav wrapper for avcodec_decode_audio3 - it may be useless in this context */
|
||||
if (got_frame != 0)
|
||||
{
|
||||
int ch, plane_size;
|
||||
int planar = av_sample_fmt_is_planar(ctx->acodec->sample_fmt);
|
||||
int data_size = av_samples_get_buffer_size(&plane_size, ctx->acodec->channels,
|
||||
frame.nb_samples, ctx->acodec->sample_fmt, 1);
|
||||
|
||||
if (XCODE_BUFFER_SIZE < data_size)
|
||||
{
|
||||
DPRINTF(E_WARN, L_XCODE, "Output buffer too small for frame (%d < %d)\n", XCODE_BUFFER_SIZE, data_size);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
memcpy(ctx->abuffer, frame.extended_data[0], plane_size);
|
||||
|
||||
if (planar && ctx->acodec->channels > 1)
|
||||
{
|
||||
uint8_t *out = ((uint8_t *)ctx->abuffer) + plane_size;
|
||||
for (ch = 1; ch < ctx->acodec->channels; ch++)
|
||||
{
|
||||
memcpy(out, frame.extended_data[ch], plane_size);
|
||||
out += plane_size;
|
||||
}
|
||||
}
|
||||
buflen = data_size;
|
||||
}
|
||||
else
|
||||
continue;
|
||||
#else
|
||||
/* No frame decoded this time around */
|
||||
if (buflen == 0)
|
||||
continue;
|
||||
#endif
|
||||
|
||||
if (ctx->need_resample)
|
||||
{
|
||||
@ -355,7 +397,7 @@ transcode_setup(struct media_file_info *mfi, off_t *est_size, int wavhdr)
|
||||
}
|
||||
memset(ctx, 0, sizeof(struct transcode_ctx));
|
||||
|
||||
#if LIBAVFORMAT_VERSION_MAJOR >= 53 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVCODEC_VERSION_MINOR >= 3)
|
||||
#if LIBAVFORMAT_VERSION_MAJOR >= 53 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 3)
|
||||
ret = avformat_open_input(&ctx->fmtctx, mfi->path, NULL, NULL);
|
||||
#else
|
||||
ret = av_open_input_file(&ctx->fmtctx, mfi->path, NULL, 0, NULL);
|
||||
@ -368,7 +410,11 @@ transcode_setup(struct media_file_info *mfi, off_t *est_size, int wavhdr)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if LIBAVFORMAT_VERSION_MAJOR >= 53 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 3)
|
||||
ret = avformat_find_stream_info(ctx->fmtctx, NULL);
|
||||
#else
|
||||
ret = av_find_stream_info(ctx->fmtctx);
|
||||
#endif
|
||||
if (ret < 0)
|
||||
{
|
||||
DPRINTF(E_WARN, L_XCODE, "Could not find stream info: %s\n", strerror(AVUNERROR(ret)));
|
||||
@ -411,7 +457,11 @@ transcode_setup(struct media_file_info *mfi, off_t *est_size, int wavhdr)
|
||||
if (ctx->adecoder->capabilities & CODEC_CAP_TRUNCATED)
|
||||
ctx->acodec->flags |= CODEC_FLAG_TRUNCATED;
|
||||
|
||||
#if LIBAVCODEC_VERSION_MAJOR >= 54 || (LIBAVCODEC_VERSION_MAJOR == 53 && LIBAVCODEC_VERSION_MINOR >= 6)
|
||||
ret = avcodec_open2(ctx->acodec, ctx->adecoder, NULL);
|
||||
#else
|
||||
ret = avcodec_open(ctx->acodec, ctx->adecoder);
|
||||
#endif
|
||||
if (ret != 0)
|
||||
{
|
||||
DPRINTF(E_WARN, L_XCODE, "Could not open codec: %s\n", strerror(AVUNERROR(ret)));
|
||||
@ -477,7 +527,11 @@ transcode_setup(struct media_file_info *mfi, off_t *est_size, int wavhdr)
|
||||
avcodec_close(ctx->acodec);
|
||||
|
||||
setup_fail:
|
||||
#if LIBAVFORMAT_VERSION_MAJOR >= 54 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 21)
|
||||
avformat_close_input(&ctx->fmtctx);
|
||||
#else
|
||||
av_close_input_file(ctx->fmtctx);
|
||||
#endif
|
||||
free(ctx);
|
||||
|
||||
return NULL;
|
||||
@ -490,7 +544,11 @@ transcode_cleanup(struct transcode_ctx *ctx)
|
||||
av_free_packet(&ctx->apacket);
|
||||
|
||||
avcodec_close(ctx->acodec);
|
||||
#if LIBAVFORMAT_VERSION_MAJOR >= 54 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 21)
|
||||
avformat_close_input(&ctx->fmtctx);
|
||||
#else
|
||||
av_close_input_file(ctx->fmtctx);
|
||||
#endif
|
||||
|
||||
av_free(ctx->abuffer);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user