History

avcodec/wavarc: add support for 0CPY

Paul B Mahol committed 3 years ago

Commit df4ab691 parent 0c7af7b2 files · +32 −3Browse files

Unified · Split

2 files
  1. libavcodec/wavarc.c +30 −2
  2. libavformat/wavarc.c +2 −1
libavcodec/wavarc.c+30−2
@@ -35,6 +35,8 @@ typedef struct WavArcContext { · 34 unmodified lines
3535 int shift;
3636 int nb_samples;
3737 int offset;
38+ int align;
39+ int add;
3840
3941 int eof;
4042 int skip;
@@ -68,22 +70,32 @@ static av_cold int wavarc_init(AVCodecContext *avctx) · 27 unmodified lines
6870 av_channel_layout_default(&avctx->ch_layout, AV_RL16(avctx->extradata + 38));
6971 avctx->sample_rate = AV_RL32(avctx->extradata + 40);
7072
73+ s->align = avctx->ch_layout.nb_channels;
74+
7175 switch (AV_RL16(avctx->extradata + 50)) {
7276 case 8: avctx->sample_fmt = AV_SAMPLE_FMT_U8P; break;
73− case 16: avctx->sample_fmt = AV_SAMPLE_FMT_S16P; break;
77+ case 16: s->align *= 2;
78+ avctx->sample_fmt = AV_SAMPLE_FMT_S16P; break;
7479 }
7580
7681 s->shift = 0;
7782 switch (avctx->codec_tag) {
83+ case MKTAG('0','C','P','Y'):
84+ s->nb_samples = 640;
85+ s->offset = 0;
86+ s->add = 0;
87+ break;
7888 case MKTAG('1','D','I','F'):
7989 s->nb_samples = 256;
8090 s->offset = 4;
91+ s->add = 0x80;
8192 break;
8293 case MKTAG('2','S','L','P'):
8394 case MKTAG('3','N','L','P'):
8495 case MKTAG('4','A','L','P'):
8596 s->nb_samples = 570;
8697 s->offset = 70;
98+ s->add = 0x80;
8799 break;
88100 default:
89101 return AVERROR_INVALIDDATA;
@@ -142,6 +154,19 @@ static void do_stereo(WavArcContext *s, int ch, int correlated, int len) · 52 unmodified lines
142154 }
143155 }
144156
157+static int decode_0cpy(AVCodecContext *avctx,
158+ WavArcContext *s, GetBitContext *gb)
159+{
160+ int bits = s->align * 8;
161+ s->nb_samples = FFMIN(640, get_bits_left(gb) / bits);
162+
163+ for (int n = 0; n < s->nb_samples; n++) {
164+ for (int ch = 0; ch < avctx->ch_layout.nb_channels; ch++)
165+ s->samples[ch][n] = get_bits(gb, bits);
166+ }
167+ return 0;
168+}
169+
145170 static int decode_1dif(AVCodecContext *avctx,
146171 WavArcContext *s, GetBitContext *gb)
147172 {
@@ -375,6 +400,9 @@ static int wavarc_decode(AVCodecContext *avctx, AVFrame *frame, · 227 unmodified lines
375400 skip_bits(gb, s->skip);
376401
377402 switch (avctx->codec_tag) {
403+ case MKTAG('0','C','P','Y'):
404+ ret = decode_0cpy(avctx, s, gb);
405+ break;
378406 case MKTAG('1','D','I','F'):
379407 ret = decode_1dif(avctx, s, gb);
380408 break;
@@ -413,7 +441,7 @@ fail: · 32 unmodified lines
413441 const int *src = s->samples[ch] + s->offset;
414442
415443 for (int n = 0; n < frame->nb_samples; n++)
416− dst[n] = src[n] * (1 << s->shift) + 0x80U;
444+ dst[n] = src[n] * (1 << s->shift) + s->add;
417445 }
418446 break;
419447 case AV_SAMPLE_FMT_S16P:
libavformat/wavarc.c+2−1
@@ -38,7 +38,8 @@ static int wavarc_probe(const AVProbeData *p) · 37 unmodified lines
3838 return 0;
3939
4040 id = AV_RL32(p->buf + len + 2);
41− if (id != MKTAG('1','D','I','F') &&
41+ if (id != MKTAG('0','C','P','Y') &&
42+ id != MKTAG('1','D','I','F') &&
4243 id != MKTAG('2','S','L','P') &&
4344 id != MKTAG('3','N','L','P') &&
4445 id != MKTAG('4','A','L','P') &&

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t