[LEDE-DEV] [packages for-15.05 PATCH 2/2] ffmpeg: backport AAC fix for multichannel mapping

Ted Hess lede at kitschensync.net
Fri Sep 30 12:00:29 PDT 2016


Thanks for these updates - I manually merged them to for-15.05.
https://github.com/openwrt/packages/commit/9de3069a949d303dcafd52c6df11baa7c673b
57f

(Tried to include your SoB, but branch wouldn't allow force-push after amend --
sorry)

/ted

On Fri, 2016-09-30 at 14:17 +0200, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal at milecki.pl>
> 
> It's a backport from 2.7 branch that fixes parsing some AAC formats.
> 
> What makes this quite important is that broken parsing was leading to
> many loop iterations, scanning taking a lot of time and allocating a lot
> of memory. Parsing 1.3 GB MPEG TS file could result in allocating
> 55+ MiB of memory causing OOM on some embedded platforms.
> 
> This is important change e.g. for minidlna users who were complaining
> about slowness and memory consumption of scanning process. This problem
> was forcing some users to building minidlna database on PCs and moving
> ready one to the target device.
> 
> Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
> ---
>  multimedia/ffmpeg/Makefile                         |  2 +-
>  ...ly-map-multichannel-ADTS-AAC-with-non-zer.patch | 68
> ++++++++++++++++++++++
>  2 files changed, 69 insertions(+), 1 deletion(-)
>  create mode 100644 multimedia/ffmpeg/patches/050-aac-Correctly-map-
> multichannel-ADTS-AAC-with-non-zer.patch
> 
> diff --git a/multimedia/ffmpeg/Makefile b/multimedia/ffmpeg/Makefile
> index 493f47a..4d9cf01 100644
> --- a/multimedia/ffmpeg/Makefile
> +++ b/multimedia/ffmpeg/Makefile
> @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
>  
>  PKG_NAME:=ffmpeg
>  PKG_VERSION:=2.6.9
> -PKG_RELEASE:=1
> +PKG_RELEASE:=2
>  
>  PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
>  PKG_SOURCE_URL:=http://ffmpeg.org/releases/
> diff --git a/multimedia/ffmpeg/patches/050-aac-Correctly-map-multichannel-
> ADTS-AAC-with-non-zer.patch b/multimedia/ffmpeg/patches/050-aac-Correctly-map-
> multichannel-ADTS-AAC-with-non-zer.patch
> new file mode 100644
> index 0000000..4ef1914
> --- /dev/null
> +++ b/multimedia/ffmpeg/patches/050-aac-Correctly-map-multichannel-ADTS-AAC-
> with-non-zer.patch
> @@ -0,0 +1,68 @@
> +From 0289f81241e720452b5a77713488d54d3ec252d7 Mon Sep 17 00:00:00 2001
> +From: nu774 <honeycomb77 at gmail.com>
> +Date: Wed, 3 Jun 2015 14:01:32 +0900
> +Subject: [PATCH] aac: Correctly map multichannel ADTS AAC with non-zero
> + channel_config + PCE
> +
> +The decoder assigns channels using default channel configuration
> +for 5.1ch when it parses an ADTS frame header using consecutive
> +channel ids.
> +
> +When a PCE comes, it reassigns channels using PCE configuration
> +using directly the ids provided. They can be arbitrary.
> +
> +Always use consecutive channel ids to avoid decoding glitches due
> +spurious reconfigurations due the channel ids mismatch between the
> +two otherwise-identical channel maps.
> +
> +Signed-off-by: Luca Barbato <lu_zero at gentoo.org>
> +---
> + libavcodec/aacdec.c | 13 ++++++++++---
> + 1 file changed, 10 insertions(+), 3 deletions(-)
> +
> +--- a/libavcodec/aacdec.c
> ++++ b/libavcodec/aacdec.c
> +@@ -457,12 +457,18 @@ static int output_configure(AACContext *
> +     AVCodecContext *avctx = ac->avctx;
> +     int i, channels = 0, ret;
> +     uint64_t layout = 0;
> ++    uint8_t id_map[TYPE_END][MAX_ELEM_ID] = {{ 0 }};
> ++    uint8_t type_counts[TYPE_END] = { 0 };
>> +     if (ac->oc[1].layout_map != layout_map) {
> +         memcpy(ac->oc[1].layout_map, layout_map, tags *
> sizeof(layout_map[0]));
> +         ac->oc[1].layout_map_tags = tags;
> +     }
> +-
> ++    for (i = 0; i < tags; i++) {
> ++        int type =         layout_map[i][0];
> ++        int id =           layout_map[i][1];
> ++        id_map[type][id] = type_counts[type]++;
> ++    }
> +     // Try to sniff a reasonable channel order, otherwise output the
> +     // channels in the order the PCE declared them.
> +     if (avctx->request_channel_layout != AV_CH_LAYOUT_NATIVE)
> +@@ -470,12 +476,14 @@ static int output_configure(AACContext *
> +     for (i = 0; i < tags; i++) {
> +         int type =     layout_map[i][0];
> +         int id =       layout_map[i][1];
> ++        int iid =      id_map[type][id];
> +         int position = layout_map[i][2];
> +         // Allocate or free elements depending on if they are in the
> +         // current program configuration.
> +-        ret = che_configure(ac, position, type, id, &channels);
> ++        ret = che_configure(ac, position, type, iid, &channels);
> +         if (ret < 0)
> +             return ret;
> ++        ac->tag_che_map[type][id] = ac->che[type][iid];
> +     }
> +     if (ac->oc[1].m4ac.ps == 1 && channels == 2) {
> +         if (layout == AV_CH_FRONT_CENTER) {
> +@@ -485,7 +493,6 @@ static int output_configure(AACContext *
> +         }
> +     }
>> +-    memcpy(ac->tag_che_map, ac->che, 4 * MAX_ELEM_ID * sizeof(ac-
> >che[0][0]));
> +     if (layout) avctx->channel_layout = layout;
> +                             ac->oc[1].channel_layout = layout;
> +     avctx->channels       = ac->oc[1].channels       = channels;




More information about the Lede-dev mailing list