Instead use a dedicated context for the few decoders that use the LUT. Also use a dedicated init function for them.
Showing the changes to libavcodec (1 of 1 file). Show all
Unified · Split
| @@ -244,31 +244,17 @@ static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 243 unmodified lines | ||
| 244 | 244 | |
| 245 | 245 | typedef struct PCMDecode { |
| 246 | 246 | int sample_size; |
| 247 | − short table[256]; | |
| 248 | 247 | void (*vector_fmul_scalar)(float *dst, const float *src, float mul, |
| 249 | 248 | int len); |
| 250 | 249 | float scale; |
| 251 | 250 | } PCMDecode; |
| 252 | 251 | |
| 253 | −static av_cold int pcm_decode_init(AVCodecContext *avctx) | |
| 252 | +static av_cold av_unused int pcm_decode_init(AVCodecContext *avctx) | |
| 254 | 253 | { |
| 255 | 254 | PCMDecode *s = avctx->priv_data; |
| 256 | 255 | AVFloatDSPContext *fdsp; |
| 257 | − int i; | |
| 258 | 256 | |
| 259 | 257 | switch (avctx->codec_id) { |
| 260 | − case AV_CODEC_ID_PCM_ALAW: | |
| 261 | − for (i = 0; i < 256; i++) | |
| 262 | − s->table[i] = alaw2linear(i); | |
| 263 | − break; | |
| 264 | − case AV_CODEC_ID_PCM_MULAW: | |
| 265 | − for (i = 0; i < 256; i++) | |
| 266 | − s->table[i] = ulaw2linear(i); | |
| 267 | − break; | |
| 268 | − case AV_CODEC_ID_PCM_VIDC: | |
| 269 | − for (i = 0; i < 256; i++) | |
| 270 | − s->table[i] = vidc2linear(i); | |
| 271 | − break; | |
| 272 | 258 | case AV_CODEC_ID_PCM_F16LE: |
| 273 | 259 | case AV_CODEC_ID_PCM_F24LE: |
| 274 | 260 | if (avctx->bits_per_coded_sample < 1 || avctx->bits_per_coded_sample > 24) |
| @@ -299,6 +285,36 @@ static av_cold int pcm_decode_init(AVCodecContext *avctx) · 24 unmodified lines | ||
| 299 | 285 | return 0; |
| 300 | 286 | } |
| 301 | 287 | |
| 288 | +typedef struct PCMLUTDecode { | |
| 289 | + PCMDecode base; | |
| 290 | + int16_t table[256]; | |
| 291 | +} PCMLUTDecode; | |
| 292 | + | |
| 293 | +static av_cold av_unused int pcm_lut_decode_init(AVCodecContext *avctx) | |
| 294 | +{ | |
| 295 | + PCMLUTDecode *s = avctx->priv_data; | |
| 296 | + | |
| 297 | + switch (avctx->codec_id) { | |
| 298 | + case AV_CODEC_ID_PCM_ALAW: | |
| 299 | + for (int i = 0; i < 256; i++) | |
| 300 | + s->table[i] = alaw2linear(i); | |
| 301 | + break; | |
| 302 | + case AV_CODEC_ID_PCM_MULAW: | |
| 303 | + for (int i = 0; i < 256; i++) | |
| 304 | + s->table[i] = ulaw2linear(i); | |
| 305 | + break; | |
| 306 | + case AV_CODEC_ID_PCM_VIDC: | |
| 307 | + for (int i = 0; i < 256; i++) | |
| 308 | + s->table[i] = vidc2linear(i); | |
| 309 | + break; | |
| 310 | + } | |
| 311 | + | |
| 312 | + avctx->sample_fmt = AV_SAMPLE_FMT_S16; | |
| 313 | + s->base.sample_size = 1; | |
| 314 | + | |
| 315 | + return 0; | |
| 316 | +} | |
| 317 | + | |
| 302 | 318 | /** |
| 303 | 319 | * Read PCM samples macro |
| 304 | 320 | * @param size Data size of native machine format |
| @@ -499,12 +515,14 @@ static int pcm_decode_frame(AVCodecContext *avctx, AVFrame *frame, · 194 unmodified lines | ||
| 499 | 515 | break; |
| 500 | 516 | case AV_CODEC_ID_PCM_ALAW: |
| 501 | 517 | case AV_CODEC_ID_PCM_MULAW: |
| 502 | − case AV_CODEC_ID_PCM_VIDC: | |
| 503 | − for (; n > 0; n--) { | |
| 504 | − AV_WN16A(samples, s->table[*src++]); | |
| 505 | − samples += 2; | |
| 506 | − } | |
| 518 | + case AV_CODEC_ID_PCM_VIDC: { | |
| 519 | + const int16_t *const lut = ((PCMLUTDecode*)avctx->priv_data)->table; | |
| 520 | + int16_t *restrict samples_16 = (int16_t*)samples; | |
| 521 | + | |
| 522 | + for (; n > 0; n--) | |
| 523 | + *samples_16++ = lut[*src++]; | |
| 507 | 524 | break; |
| 525 | + } | |
| 508 | 526 | case AV_CODEC_ID_PCM_LXF: |
| 509 | 527 | { |
| 510 | 528 | int i; |
| @@ -567,36 +585,44 @@ const FFCodec ff_ ## name_ ## _encoder = { \ · 56 unmodified lines | ||
| 567 | 585 | PCM_ENCODER_3(CONFIG_PCM_ ## id ## _ENCODER, AV_CODEC_ID_PCM_ ## id, \ |
| 568 | 586 | AV_SAMPLE_FMT_ ## sample_fmt, pcm_ ## name, long_name) |
| 569 | 587 | |
| 570 | −#define PCM_DECODER_0(id, sample_fmt, name, long_name) | |
| 571 | −#define PCM_DECODER_1(id_, sample_fmt_, name_, long_name_) \ | |
| 588 | +#define PCM_DECODER_0(id, sample_fmt, name, long_name, Context, init_func) | |
| 589 | +#define PCM_DECODER_1(id_, sample_fmt, name_, long_name, Context, init_func) \ | |
| 572 | 590 | const FFCodec ff_ ## name_ ## _decoder = { \ |
| 573 | 591 | .p.name = #name_, \ |
| 574 | − CODEC_LONG_NAME(long_name_), \ | |
| 592 | + CODEC_LONG_NAME(long_name), \ | |
| 575 | 593 | .p.type = AVMEDIA_TYPE_AUDIO, \ |
| 576 | 594 | .p.id = id_, \ |
| 577 | − .priv_data_size = sizeof(PCMDecode), \ | |
| 578 | − .init = pcm_decode_init, \ | |
| 595 | + .priv_data_size = sizeof(Context), \ | |
| 596 | + .init = init_func, \ | |
| 579 | 597 | FF_CODEC_DECODE_CB(pcm_decode_frame), \ |
| 580 | 598 | .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_PARAM_CHANGE, \ |
| 581 | − CODEC_SAMPLEFMTS(sample_fmt_), \ | |
| 599 | + CODEC_SAMPLEFMTS(sample_fmt), \ | |
| 582 | 600 | } |
| 583 | 601 | |
| 584 | −#define PCM_DECODER_2(cf, id, sample_fmt, name, long_name) \ | |
| 585 | − PCM_DECODER_ ## cf(id, sample_fmt, name, long_name) | |
| 586 | −#define PCM_DECODER_3(cf, id, sample_fmt, name, long_name) \ | |
| 587 | − PCM_DECODER_2(cf, id, sample_fmt, name, long_name) | |
| 588 | −#define PCM_DECODER(id, sample_fmt, name, long_name) \ | |
| 602 | +#define PCM_DECODER_2(cf, id, sample_fmt, name, long_name, Context, init_func) \ | |
| 603 | + PCM_DECODER_ ## cf(id, sample_fmt, name, long_name, Context, init_func) | |
| 604 | +#define PCM_DECODER_3(cf, id, sample_fmt, name, long_name, Context, init_func) \ | |
| 605 | + PCM_DECODER_2(cf, id, sample_fmt, name, long_name, Context, init_func) | |
| 606 | +#define PCM_DEC_EXT(id, sample_fmt, name, long_name, Context, init_func) \ | |
| 589 | 607 | PCM_DECODER_3(CONFIG_PCM_ ## id ## _DECODER, AV_CODEC_ID_PCM_ ## id, \ |
| 590 | − AV_SAMPLE_FMT_ ## sample_fmt, pcm_ ## name, long_name) | |
| 608 | + AV_SAMPLE_FMT_ ## sample_fmt, pcm_ ## name, long_name, \ | |
| 609 | + Context, init_func) | |
| 610 | + | |
| 611 | +#define PCM_DECODER(id, sample_fmt, name, long_name) \ | |
| 612 | + PCM_DEC_EXT(id, sample_fmt, name, long_name, PCMDecode, pcm_decode_init) | |
| 591 | 613 | |
| 592 | 614 | #define PCM_CODEC(id, sample_fmt_, name, long_name_) \ |
| 593 | 615 | PCM_ENCODER(id, sample_fmt_, name, long_name_); \ |
| 594 | 616 | PCM_DECODER(id, sample_fmt_, name, long_name_) |
| 595 | 617 | |
| 618 | +#define PCM_CODEC_EXT(id, sample_fmt, name, long_name, DecContext, dec_init_func) \ | |
| 619 | + PCM_DEC_EXT(id, sample_fmt, name, long_name, DecContext, dec_init_func); \ | |
| 620 | + PCM_ENCODER(id, sample_fmt, name, long_name) | |
| 621 | + | |
| 596 | 622 | /* Note: Do not forget to add new entries to the Makefile as well. */ |
| 597 | 623 | // AV_CODEC_ID_* pcm_* name |
| 598 | −// AV_SAMPLE_FMT_* long name | |
| 599 | −PCM_CODEC (ALAW, S16, alaw, "PCM A-law / G.711 A-law"); | |
| 624 | +// AV_SAMPLE_FMT_* long name DecodeContext decode init func | |
| 625 | +PCM_CODEC_EXT(ALAW, S16, alaw, "PCM A-law / G.711 A-law", PCMLUTDecode, pcm_lut_decode_init); | |
| 600 | 626 | PCM_DECODER (F16LE, FLT, f16le, "PCM 16.8 floating point little-endian"); |
| 601 | 627 | PCM_DECODER (F24LE, FLT, f24le, "PCM 24.0 floating point little-endian"); |
| 602 | 628 | PCM_CODEC (F32BE, FLT, f32be, "PCM 32-bit floating point big-endian"); |
| @@ -604,7 +630,7 @@ PCM_CODEC (F32LE, FLT, f32le, "PCM 32-bit floating point little · 1 unmodified line | ||
| 604 | 630 | PCM_CODEC (F64BE, DBL, f64be, "PCM 64-bit floating point big-endian"); |
| 605 | 631 | PCM_CODEC (F64LE, DBL, f64le, "PCM 64-bit floating point little-endian"); |
| 606 | 632 | PCM_DECODER (LXF, S32P,lxf, "PCM signed 20-bit little-endian planar"); |
| 607 | −PCM_CODEC (MULAW, S16, mulaw, "PCM mu-law / G.711 mu-law"); | |
| 633 | +PCM_CODEC_EXT(MULAW, S16, mulaw, "PCM mu-law / G.711 mu-law", PCMLUTDecode, pcm_lut_decode_init); | |
| 608 | 634 | PCM_CODEC (S8, U8, s8, "PCM signed 8-bit"); |
| 609 | 635 | PCM_CODEC (S8_PLANAR, U8P, s8_planar, "PCM signed 8-bit planar"); |
| 610 | 636 | PCM_CODEC (S16BE, S16, s16be, "PCM signed 16-bit big-endian"); |
| @@ -627,5 +653,5 @@ PCM_CODEC (U32BE, S32, u32be, "PCM unsigned 32-bit big-endian") · 16 unmodified lines | ||
| 627 | 653 | PCM_CODEC (U32LE, S32, u32le, "PCM unsigned 32-bit little-endian"); |
| 628 | 654 | PCM_CODEC (S64BE, S64, s64be, "PCM signed 64-bit big-endian"); |
| 629 | 655 | PCM_CODEC (S64LE, S64, s64le, "PCM signed 64-bit little-endian"); |
| 630 | −PCM_CODEC (VIDC, S16, vidc, "PCM Archimedes VIDC"); | |
| 656 | +PCM_CODEC_EXT(VIDC, S16, vidc, "PCM Archimedes VIDC", PCMLUTDecode, pcm_lut_decode_init); | |
| 631 | 657 | PCM_DECODER (SGA, U8, sga, "PCM SGA"); |