MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / wavpack_encode_frame

Function wavpack_encode_frame

libavcodec/wavpackenc.c:2864–2920  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2862}
2863
2864static int wavpack_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
2865 const AVFrame *frame, int *got_packet_ptr)
2866{
2867 WavPackEncodeContext *s = avctx->priv_data;
2868 int buf_size, ret;
2869 uint8_t *buf;
2870
2871 s->block_samples = frame->nb_samples;
2872 av_fast_padded_malloc(&s->samples[0], &s->samples_size[0],
2873 sizeof(int32_t) * s->block_samples);
2874 if (!s->samples[0])
2875 return AVERROR(ENOMEM);
2876 if (avctx->ch_layout.nb_channels > 1) {
2877 av_fast_padded_malloc(&s->samples[1], &s->samples_size[1],
2878 sizeof(int32_t) * s->block_samples);
2879 if (!s->samples[1])
2880 return AVERROR(ENOMEM);
2881 }
2882
2883 buf_size = s->block_samples * avctx->ch_layout.nb_channels * 8
2884 + 200 * avctx->ch_layout.nb_channels /* for headers */;
2885 if ((ret = ff_alloc_packet(avctx, avpkt, buf_size)) < 0)
2886 return ret;
2887 buf = avpkt->data;
2888
2889 for (s->ch_offset = 0; s->ch_offset < avctx->ch_layout.nb_channels;) {
2890 set_samplerate(s);
2891
2892 switch (s->avctx->sample_fmt) {
2893 case AV_SAMPLE_FMT_S16P: s->flags |= 1; break;
2894 case AV_SAMPLE_FMT_S32P: s->flags |= 3 - (s->avctx->bits_per_raw_sample <= 24); break;
2895 case AV_SAMPLE_FMT_FLTP: s->flags |= 3 | WV_FLOAT_DATA;
2896 }
2897
2898 fill_buffer(s, frame->extended_data[s->ch_offset], s->samples[0], s->block_samples);
2899 if (avctx->ch_layout.nb_channels - s->ch_offset == 1) {
2900 s->flags |= WV_MONO;
2901 } else {
2902 s->flags |= WV_CROSS_DECORR;
2903 fill_buffer(s, frame->extended_data[s->ch_offset + 1], s->samples[1], s->block_samples);
2904 }
2905
2906 s->flags += (1 << MAG_LSB) * ((s->flags & 3) * 8 + 7);
2907
2908 if ((ret = wavpack_encode_block(s, s->samples[0], s->samples[1],
2909 buf, buf_size)) < 0)
2910 return ret;
2911
2912 buf += ret;
2913 buf_size -= ret;
2914 }
2915 s->sample_index += frame->nb_samples;
2916
2917 avpkt->size = buf - avpkt->data;
2918 *got_packet_ptr = 1;
2919 return 0;
2920}
2921

Callers

nothing calls this directly

Calls 5

av_fast_padded_mallocFunction · 0.85
ff_alloc_packetFunction · 0.85
set_samplerateFunction · 0.85
wavpack_encode_blockFunction · 0.85
fill_bufferFunction · 0.70

Tested by

no test coverage detected