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

Function encode_superframe

libavcodec/wmaenc.c:378–436  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

376}
377
378static int encode_superframe(AVCodecContext *avctx, AVPacket *avpkt,
379 const AVFrame *frame, int *got_packet_ptr)
380{
381 WMACodecContext *s = avctx->priv_data;
382 int i, total_gain, ret, error;
383
384 s->block_len_bits = s->frame_len_bits; // required by non variable block len
385 s->block_len = 1 << s->block_len_bits;
386
387 ret = apply_window_and_mdct(avctx, frame);
388
389 if (ret < 0)
390 return ret;
391
392 if (s->ms_stereo) {
393 float a, b;
394 int i;
395
396 for (i = 0; i < s->block_len; i++) {
397 a = s->coefs[0][i] * 0.5;
398 b = s->coefs[1][i] * 0.5;
399 s->coefs[0][i] = a + b;
400 s->coefs[1][i] = a - b;
401 }
402 }
403
404 if ((ret = ff_alloc_packet(avctx, avpkt, 2 * MAX_CODED_SUPERFRAME_SIZE)) < 0)
405 return ret;
406
407 total_gain = 128;
408 for (i = 64; i; i >>= 1) {
409 error = encode_frame(s, s->coefs, avpkt->data, avpkt->size,
410 total_gain - i);
411 if (error <= 0)
412 total_gain -= i;
413 }
414
415 while(total_gain <= 128 && error > 0)
416 error = encode_frame(s, s->coefs, avpkt->data, avpkt->size, total_gain++);
417 if (error > 0) {
418 av_log(avctx, AV_LOG_ERROR, "Invalid input data or requested bitrate too low, cannot encode\n");
419 return AVERROR(EINVAL);
420 }
421 av_assert0((put_bits_count(&s->pb) & 7) == 0);
422 i = avctx->block_align - put_bytes_count(&s->pb, 0);
423 av_assert0(i>=0);
424 while(i--)
425 put_bits(&s->pb, 8, 'N');
426
427 flush_put_bits(&s->pb);
428 av_assert0(put_bytes_output(&s->pb) == avctx->block_align);
429
430 if (frame->pts != AV_NOPTS_VALUE)
431 avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->initial_padding);
432
433 avpkt->size = avctx->block_align;
434 *got_packet_ptr = 1;
435 return 0;

Callers

nothing calls this directly

Calls 10

ff_alloc_packetFunction · 0.85
av_logFunction · 0.85
put_bits_countFunction · 0.85
put_bytes_countFunction · 0.85
flush_put_bitsFunction · 0.85
put_bytes_outputFunction · 0.85
ff_samples_to_time_baseFunction · 0.85
apply_window_and_mdctFunction · 0.70
encode_frameFunction · 0.70
put_bitsFunction · 0.70

Tested by

no test coverage detected