Skip to content

Commit

Permalink
avcodec/ac4dec: minor fixes
Browse files Browse the repository at this point in the history
- avcodec/ac4dec_data: declare qwin aligned as required by vector_fmul
- avcodec/ac4dec: avoid division by zero
- avcodec/ac4dec: fix channel mapping for 5.1 decode w/ 2ch_mode
- avformat/ac4dec: fix order of operations
- avcodec/utils: add ac4 frame duration
  • Loading branch information
gnattu committed May 26, 2024
1 parent 22ce430 commit c500f24
Showing 1 changed file with 100 additions and 78 deletions.
178 changes: 100 additions & 78 deletions debian/patches/0077-add-ac4-decoder.patch
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
diff --git a/libavcodec/kbdwin.h b/libavcodec/kbdwin.h
index 4185c4206f..2ea35e1bd5 100644
--- a/libavcodec/kbdwin.h
+++ b/libavcodec/kbdwin.h
Index: FFmpeg/libavcodec/kbdwin.h
===================================================================
--- FFmpeg.orig/libavcodec/kbdwin.h
+++ FFmpeg/libavcodec/kbdwin.h
@@ -24,7 +24,7 @@
/**
* Maximum window size for ff_kbd_window_init.
*/
-#define FF_KBD_WINDOW_MAX 1024
+#define FF_KBD_WINDOW_MAX 2048

/**
* Generate a Kaiser-Bessel Derived Window.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 389253f5d0..dbb0450874 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
Index: FFmpeg/libavcodec/Makefile
===================================================================
--- FFmpeg.orig/libavcodec/Makefile
+++ FFmpeg/libavcodec/Makefile
@@ -201,6 +201,7 @@ OBJS-$(CONFIG_AC3_ENCODER) +
ac3.o kbdwin.o
OBJS-$(CONFIG_AC3_FIXED_ENCODER) += ac3enc_fixed.o ac3enc.o ac3tab.o ac3.o kbdwin.o
Expand All @@ -23,24 +23,23 @@ index 389253f5d0..dbb0450874 100644
OBJS-$(CONFIG_ACELP_KELVIN_DECODER) += g729dec.o lsp.o celp_math.o celp_filters.o acelp_filters.o acelp_pitch_delay.o acelp_vectors.o g729postfilter.o
OBJS-$(CONFIG_AGM_DECODER) += agm.o jpegquanttables.o
OBJS-$(CONFIG_AIC_DECODER) += aic.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index e593ad19af..60e4e124d8 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -434,6 +438,7 @@ extern const FFCodec ff_ac3_encoder;
Index: FFmpeg/libavcodec/allcodecs.c
===================================================================
--- FFmpeg.orig/libavcodec/allcodecs.c
+++ FFmpeg/libavcodec/allcodecs.c
@@ -434,6 +434,7 @@ extern const FFCodec ff_ac3_encoder;
extern const FFCodec ff_ac3_decoder;
extern const FFCodec ff_ac3_fixed_encoder;
extern const FFCodec ff_ac3_fixed_decoder;
+extern const FFCodec ff_ac4_decoder;
extern const FFCodec ff_acelp_kelvin_decoder;
extern const FFCodec ff_alac_encoder;
extern const FFCodec ff_alac_decoder;
diff --git a/libavcodec/ac4dec.c b/libavcodec/ac4dec.c
new file mode 100644
index 0000000000..56662b4314
Index: FFmpeg/libavcodec/ac4dec.c
===================================================================
--- /dev/null
+++ b/libavcodec/ac4dec.c
@@ -0,0 +1,5891 @@
+++ FFmpeg/libavcodec/ac4dec.c
@@ -0,0 +1,5901 @@
+/*
+ * AC-4 Audio Decoder
+ *
Expand Down Expand Up @@ -3179,7 +3178,12 @@ index 0000000000..56662b4314
+ ssch->num_sbg_sig[0] = ssch->num_sbg_sig_lowres;
+ ssch->num_sbg_sig[1] = ssch->num_sbg_sig_highres;
+
+ ssch->num_sbg_noise = FFMAX(1, floorf(ss->aspx_noise_sbg * log2f(ssch->sbz / (float)ssch->sbx) + 0.5));
+ if (ssch->sbx) {
+ ssch->num_sbg_noise = FFMAX(1, floorf(ss->aspx_noise_sbg * log2f(ssch->sbz / (float)ssch->sbx) + 0.5));
+ }
+ else {
+ ssch->num_sbg_noise = 0;
+ }
+ if (ssch->num_sbg_noise > 5) {
+ av_log(s->avctx, AV_LOG_ERROR, "invalid num sbg noise: %d\n", ssch->num_sbg_noise);
+ return AVERROR_INVALIDDATA;
Expand Down Expand Up @@ -4058,18 +4062,21 @@ index 0000000000..56662b4314
+ ss->coding_config = get_bits(gb, 2);
+ av_log(s->avctx, AV_LOG_DEBUG, "coding_config: %d\n", ss->coding_config);
+ switch (ss->coding_config) {
+ case 0:
+ ss->mode_2ch = get_bits1(gb);
+ ret = two_channel_data(s, ss, &ss->ssch[0], &ss->ssch[1], 0);
+ if (ret < 0)
+ return ret;
+ ret = two_channel_data(s, ss, &ss->ssch[2], &ss->ssch[3], 1);
+ if (ret < 0)
+ return ret;
+ ret = mono_data(s, ss, &ss->ssch[4], 0, iframe);
+ if (ret < 0)
+ return ret;
+ break;
+ case 0: {
+ int fl = 0, fr = 1, fc = 2, sl = 3, sr = 4;
+ ss->mode_2ch = get_bits1(gb);
+ av_log(s->avctx, AV_LOG_DEBUG, "2ch_mode: %d\n", ss->mode_2ch);
+ ret = two_channel_data(s, ss, &ss->ssch[fl], &ss->ssch[ss->mode_2ch ? sl : fr], 0);
+ if (ret < 0)
+ return ret;
+ ret = two_channel_data(s, ss, &ss->ssch[ss->mode_2ch ? fr : sl], &ss->ssch[sr], 1);
+ if (ret < 0)
+ return ret;
+ ret = mono_data(s, ss, &ss->ssch[fc], 0, iframe);
+ if (ret < 0)
+ return ret;
+ break;
+ }
+ case 1:
+ ret = three_channel_data(s, ss, &ss->ssch[0], &ss->ssch[1], &ss->ssch[2]);
+ if (ret < 0)
Expand Down Expand Up @@ -5787,8 +5794,10 @@ index 0000000000..56662b4314
+ int size = AV_RB16(avpkt->data + 2);
+
+ start_offset = 4;
+ if (size == 0xFFFF)
+ if (size == 0xFFFF) {
+ start_offset += 3;
+ size = AV_RB24(avpkt->data + 4);
+ }
+ }
+
+ if ((ret = init_get_bits8(gb, avpkt->data, avpkt->size)) < 0)
Expand All @@ -5805,12 +5814,12 @@ index 0000000000..56662b4314
+
+ presentation = FFMIN(s->target_presentation, FFMAX(0, s->nb_presentations - 1));
+ ssinfo = s->version == 2 ? &s->ssgroup[0].ssinfo : &s->pinfo[presentation].ssinfo;
+ avctx->sample_rate = s->fs_index ? 48000 : 44100;
+ avctx->ch_layout.nb_channels = channel_mode_nb_channels[ssinfo->channel_mode];
+ avctx->ch_layout = ff_ac4_ch_layouts[ssinfo->channel_mode];
+ //frame->nb_samples = av_rescale(s->frame_len_base,
+ // s->resampling_ratio.num,
+ // s->resampling_ratio.den);
+ avctx->sample_rate = s->fs_index ? 48000 : 44100;
+// avctx->sample_rate = (int)av_rescale(avctx->sample_rate,
+// s->resampling_ratio.den,
+// s->resampling_ratio.num);
+ frame->nb_samples = s->frame_len_base;
+ if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
+ return ret;
Expand Down Expand Up @@ -5932,12 +5941,11 @@ index 0000000000..56662b4314
+ .p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
+ AV_SAMPLE_FMT_NONE },
+};
diff --git a/libavcodec/ac4dec_data.h b/libavcodec/ac4dec_data.h
new file mode 100644
index 0000000000..4fa5aaedf1
Index: FFmpeg/libavcodec/ac4dec_data.h
===================================================================
--- /dev/null
+++ b/libavcodec/ac4dec_data.h
@@ -0,0 +1,1664 @@
+++ FFmpeg/libavcodec/ac4dec_data.h
@@ -0,0 +1,1665 @@
+/*
+ * AC-4 Audio Decoder
+ *
Expand All @@ -5962,6 +5970,7 @@ index 0000000000..4fa5aaedf1
+#define AVCODEC_AC4DEC_DATA_H
+
+#include <stdint.h>
+#include <libavutil/mem.h>
+
+static const uint8_t aspx_hcb_env_level_15_f0_bits[71] = {
+ 7, 9, 9, 9, 9, 8, 8, 7, 7, 7, 7, 7, 6, 6, 6, 6,
Expand Down Expand Up @@ -7200,7 +7209,7 @@ index 0000000000..4fa5aaedf1
+ 0x031e10,
+};
+
+static const float qwin[640] = {
+DECLARE_ASM_CONST(16, float, qwin)[640] = {
+ 0,
+ 1.990318758627504e-004, 2.494762615491542e-004, 3.021769445225078e-004,
+ 3.548460080857985e-004, 4.058915811480806e-004, 4.546408052001889e-004,
Expand Down Expand Up @@ -7602,11 +7611,11 @@ index 0000000000..4fa5aaedf1
+};
+
+#endif /* AVCODEC_AC4DECDATA_H */
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 199f62df15..d856aa4a36 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -3367,6 +3367,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
Index: FFmpeg/libavcodec/codec_desc.c
===================================================================
--- FFmpeg.orig/libavcodec/codec_desc.c
+++ FFmpeg/libavcodec/codec_desc.c
@@ -3367,6 +3367,13 @@ static const AVCodecDescriptor codec_des
.long_name = NULL_IF_CONFIG_SMALL("RKA (RK Audio)"),
.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY | AV_CODEC_PROP_LOSSLESS,
},
Expand All @@ -7617,38 +7626,37 @@ index 199f62df15..d856aa4a36 100644
+ .long_name = NULL_IF_CONFIG_SMALL("AC-4"),
+ .props = AV_CODEC_PROP_LOSSY,
+ },

/* subtitle codecs */
{
diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
index 89a4a0cb89..64a3893475 100644
--- a/libavcodec/codec_id.h
+++ b/libavcodec/codec_id.h
Index: FFmpeg/libavcodec/codec_id.h
===================================================================
--- FFmpeg.orig/libavcodec/codec_id.h
+++ FFmpeg/libavcodec/codec_id.h
@@ -538,6 +538,7 @@ enum AVCodecID {
AV_CODEC_ID_FTR,
AV_CODEC_ID_WAVARC,
AV_CODEC_ID_RKA,
+ AV_CODEC_ID_AC4,

/* subtitle codecs */
AV_CODEC_ID_FIRST_SUBTITLE = 0x17000, ///< A dummy ID pointing at the start of subtitle codecs.
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 47bbbbfb2a..b6896013a1 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -76,6 +76,7 @@ OBJS-$(CONFIG_AA_DEMUXER) += aadec.o
Index: FFmpeg/libavformat/Makefile
===================================================================
--- FFmpeg.orig/libavformat/Makefile
+++ FFmpeg/libavformat/Makefile
@@ -76,6 +76,7 @@ OBJS-$(CONFIG_AA_DEMUXER)
OBJS-$(CONFIG_AAC_DEMUXER) += aacdec.o apetag.o img2.o rawdec.o
OBJS-$(CONFIG_AAX_DEMUXER) += aaxdec.o
OBJS-$(CONFIG_AC3_DEMUXER) += ac3dec.o rawdec.o
+OBJS-$(CONFIG_AC4_DEMUXER) += ac4dec.o
OBJS-$(CONFIG_AC3_MUXER) += rawenc.o
OBJS-$(CONFIG_ACE_DEMUXER) += acedec.o
OBJS-$(CONFIG_ACM_DEMUXER) += acm.o rawdec.o
diff --git a/libavformat/ac4dec.c b/libavformat/ac4dec.c
new file mode 100644
index 0000000000..94a5f4b601
Index: FFmpeg/libavformat/ac4dec.c
===================================================================
--- /dev/null
+++ b/libavformat/ac4dec.c
+++ FFmpeg/libavformat/ac4dec.c
@@ -0,0 +1,105 @@
+/*
+ * RAW AC-4 demuxer
Expand Down Expand Up @@ -7755,39 +7763,53 @@ index 0000000000..94a5f4b601
+ .flags = AVFMT_GENERIC_INDEX,
+ .extensions = "ac4",
+};
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index cb5b69e9cd..ca050bf03b 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -34,6 +34,7 @@ extern const AVInputFormat ff_aac_demuxer;
Index: FFmpeg/libavformat/allformats.c
===================================================================
--- FFmpeg.orig/libavformat/allformats.c
+++ FFmpeg/libavformat/allformats.c
@@ -34,6 +34,7 @@ extern const AVInputFormat ff_aac_demux
extern const AVInputFormat ff_aax_demuxer;
extern const AVInputFormat ff_ac3_demuxer;
extern const FFOutputFormat ff_ac3_muxer;
+extern const AVInputFormat ff_ac4_demuxer;
extern const AVInputFormat ff_ace_demuxer;
extern const AVInputFormat ff_acm_demuxer;
extern const AVInputFormat ff_act_demuxer;
diff --git a/libavformat/isom_tags.c b/libavformat/isom_tags.c
index e2b80405cc..7e8d46a02e 100644
--- a/libavformat/isom_tags.c
+++ b/libavformat/isom_tags.c
@@ -298,6 +298,7 @@ const AVCodecTag ff_codec_movaudio_tags[] = {
Index: FFmpeg/libavformat/isom_tags.c
===================================================================
--- FFmpeg.orig/libavformat/isom_tags.c
+++ FFmpeg/libavformat/isom_tags.c
@@ -298,6 +298,7 @@ const AVCodecTag ff_codec_movaudio_tags[
{ AV_CODEC_ID_DTS, MKTAG('d', 't', 's', 'e') }, /* DTS Express */
{ AV_CODEC_ID_DTS, MKTAG('D', 'T', 'S', ' ') }, /* non-standard */
{ AV_CODEC_ID_EAC3, MKTAG('e', 'c', '-', '3') }, /* ETSI TS 102 366 Annex F (only valid in ISOBMFF) */
+ { AV_CODEC_ID_AC4, MKTAG('a', 'c', '-', '4') },
{ AV_CODEC_ID_DVAUDIO, MKTAG('v', 'd', 'v', 'a') },
{ AV_CODEC_ID_DVAUDIO, MKTAG('d', 'v', 'c', 'a') },
{ AV_CODEC_ID_GSM, MKTAG('a', 'g', 's', 'm') },
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index d97702fcd7..dfca8782f3 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -859,6 +859,7 @@ static const StreamType HLS_SAMPLE_ENC_types[] = {
Index: FFmpeg/libavformat/mpegts.c
===================================================================
--- FFmpeg.orig/libavformat/mpegts.c
+++ FFmpeg/libavformat/mpegts.c
@@ -859,6 +859,7 @@ static const StreamType HLS_SAMPLE_ENC_t
static const StreamType REGD_types[] = {
{ MKTAG('d', 'r', 'a', 'c'), AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_DIRAC },
{ MKTAG('A', 'C', '-', '3'), AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_AC3 },
+ { MKTAG('A', 'C', '-', '4'), AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_AC4 },
{ MKTAG('B', 'S', 'S', 'D'), AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_S302M },
{ MKTAG('D', 'T', 'S', '1'), AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_DTS },
{ MKTAG('D', 'T', 'S', '2'), AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_DTS },
Index: FFmpeg/libavcodec/utils.c
===================================================================
--- FFmpeg.orig/libavcodec/utils.c
+++ FFmpeg/libavcodec/utils.c
@@ -634,7 +634,8 @@ static int get_audio_frame_duration(enum
case AV_CODEC_ID_ATRAC3P: return 2048;
case AV_CODEC_ID_MP2:
case AV_CODEC_ID_MUSEPACK7: return 1152;
- case AV_CODEC_ID_AC3: return 1536;
+ case AV_CODEC_ID_AC3:
+ case AV_CODEC_ID_AC4: return 1536;
case AV_CODEC_ID_FTR: return 1024;
}

0 comments on commit c500f24

Please sign in to comment.