From 4cd22b77380e6e3411fdfa0cb6c8c2b5def973fc Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 19 Jul 2012 19:47:08 -0400 Subject: [PATCH 1/4] alac: fix channel pointer assignment for 24 and 32-bit Needs to be done separately for each element. --- libavcodec/alac.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavcodec/alac.c b/libavcodec/alac.c index 310a1f0d5b..aa2e6c8a3c 100644 --- a/libavcodec/alac.c +++ b/libavcodec/alac.c @@ -322,16 +322,16 @@ static int decode_element(AVCodecContext *avctx, void *data, int ch_index, av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - if (alac->sample_size > 16) { - for (ch = 0; ch < channels; ch++) - alac->output_samples_buffer[ch] = (int32_t *)alac->frame.extended_data[ch_index + ch]; - } } else if (output_samples != alac->nb_samples) { av_log(avctx, AV_LOG_ERROR, "sample count mismatch: %u != %d\n", output_samples, alac->nb_samples); return AVERROR_INVALIDDATA; } alac->nb_samples = output_samples; + if (alac->sample_size > 16) { + for (ch = 0; ch < channels; ch++) + alac->output_samples_buffer[ch] = (int32_t *)alac->frame.extended_data[ch_index + ch]; + } if (is_compressed) { int16_t lpc_coefs[2][32]; From 1749e12f4535d773a442ae6106f9f5d78d4c633c Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 19 Jul 2012 19:48:21 -0400 Subject: [PATCH 2/4] cafdec: allow larger ALAC magic cookie It already skips any extra bytes at the end, and apparently there are some samples in the wild with larger 'kuki' chunks. --- libavformat/cafdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c index 6c40b1b229..b2eccb9d37 100644 --- a/libavformat/cafdec.c +++ b/libavformat/cafdec.c @@ -124,7 +124,7 @@ static int read_kuki_chunk(AVFormatContext *s, int64_t size) #define ALAC_HEADER 36 #define ALAC_NEW_KUKI 24 uint8_t preamble[12]; - if (size < ALAC_NEW_KUKI || size > ALAC_PREAMBLE + ALAC_HEADER) { + if (size < ALAC_NEW_KUKI) { av_log(s, AV_LOG_ERROR, "invalid ALAC magic cookie\n"); avio_skip(pb, size); return AVERROR_INVALIDDATA; From 5eb9c495af75721dd5e401ab3aacf316d2f25433 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 4 Jul 2012 10:46:10 +0200 Subject: [PATCH 3/4] FATE: add a test for flac cover art. --- tests/fate/cover-art.mak | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/fate/cover-art.mak b/tests/fate/cover-art.mak index f35e9bb729..dadfcd8901 100644 --- a/tests/fate/cover-art.mak +++ b/tests/fate/cover-art.mak @@ -2,6 +2,10 @@ FATE_COVER_ART += fate-cover-art-ape fate-cover-art-ape: CMD = md5 -i $(SAMPLES)/cover_art/luckynight_cover.ape -an -c:v copy -f rawvideo fate-cover-art-ape: REF = 45333c983c45af54449dff10af144317 +FATE_COVER_ART += fate-cover-art-flac +fate-cover-art-flac: CMD = md5 -i $(SAMPLES)/cover_art/cover_art.flac -an -c:v copy -f rawvideo +fate-cover-art-flac: REF = 0de1fc6200596fa32b8f7300a14c0261 + FATE_COVER_ART += fate-cover-art-m4a fate-cover-art-m4a: CMD = md5 -i $(SAMPLES)/cover_art/Owner-iTunes_9.0.3.15.m4a -an -c:v copy -f rawvideo fate-cover-art-m4a: REF = 08ba70a3b594ff6345a93965e96a9d3e From ce64e5bfd11ae63af0fb10317a2aea6f7501be62 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Thu, 19 Jul 2012 01:31:39 +0200 Subject: [PATCH 4/4] libopenjpeg: introduce lowres and lowqual private options OpenJPEG can decode in lower resolution or decode only a number of enhancement layers. --- libavcodec/libopenjpegdec.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/libavcodec/libopenjpegdec.c b/libavcodec/libopenjpegdec.c index 799ccd7745..4b3e8d6e48 100644 --- a/libavcodec/libopenjpegdec.c +++ b/libavcodec/libopenjpegdec.c @@ -24,6 +24,7 @@ * JPEG 2000 decoder using libopenjpeg */ +#include "libavutil/opt.h" #include "libavutil/imgutils.h" #include "avcodec.h" #include "libavutil/intreadwrite.h" @@ -35,8 +36,11 @@ #define JP2_SIG_VALUE 0x0D0A870A typedef struct { + AVClass *class; opj_dparameters_t dec_params; AVFrame image; + int lowres; + int lowqual; } LibOpenJPEGContext; static int check_image_attributes(opj_image_t *image) @@ -104,6 +108,8 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx, opj_set_event_mgr((opj_common_ptr)dec, NULL, NULL); ctx->dec_params.cp_limit_decoding = LIMIT_TO_MAIN_HEADER; + ctx->dec_params.cp_reduce = ctx->lowres; + ctx->dec_params.cp_layer = ctx->lowqual; // Tie decoder with decoding parameters opj_setup_decoder(dec, &ctx->dec_params); stream = opj_cio_open((opj_common_ptr)dec, buf, buf_size); @@ -123,6 +129,12 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx, } width = image->x1 - image->x0; height = image->y1 - image->y0; + + if (ctx->lowres) { + width = (width + (1 << ctx->lowres) - 1) >> ctx->lowres; + height = (height + (1 << ctx->lowres) - 1) >> ctx->lowres; + } + if(av_image_check_size(width, height, 0, avctx) < 0) { av_log(avctx, AV_LOG_ERROR, "%dx%d dimension invalid.\n", width, height); goto done; @@ -208,6 +220,21 @@ static av_cold int libopenjpeg_decode_close(AVCodecContext *avctx) return 0 ; } +#define OFFSET(x) offsetof(LibOpenJPEGContext, x) +#define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM + +static const AVOption options[] = { + { "lowqual", "Limit the number of layers used for decoding", OFFSET(lowqual), AV_OPT_TYPE_INT, { 0 }, 0, INT_MAX, VD }, + { "lowres", "Lower the decoding resolution by a power of two", OFFSET(lowres), AV_OPT_TYPE_INT, { 0 }, 0, INT_MAX, VD }, + { NULL }, +}; + +static const AVClass class = { + .class_name = "libopenjpeg", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; AVCodec ff_libopenjpeg_decoder = { .name = "libopenjpeg", @@ -219,5 +246,6 @@ AVCodec ff_libopenjpeg_decoder = { .decode = libopenjpeg_decode_frame, .capabilities = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS, .long_name = NULL_IF_CONFIG_SMALL("OpenJPEG based JPEG 2000 decoder"), + .priv_class = &class, .init_thread_copy = ONLY_IF_THREADS_ENABLED(libopenjpeg_decode_init_thread_copy), };