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

Function audio_decode_frame

fftools/ffplay.c:2422–2529  ·  view source on GitHub ↗

* Decode one audio frame and return its uncompressed size. * * The processed audio frame is decoded, converted if required, and * stored in is->audio_buf, with size in bytes given by the return * value. */

Source from the content-addressed store, hash-verified

2420 * value.
2421 */
2422static int audio_decode_frame(VideoState *is)
2423{
2424 int data_size, resampled_data_size;
2425 av_unused double audio_clock0;
2426 int wanted_nb_samples;
2427 Frame *af;
2428
2429 if (is->paused)
2430 return -1;
2431
2432 do {
2433#if defined(_WIN32)
2434 while (frame_queue_nb_remaining(&is->sampq) == 0) {
2435 if ((av_gettime_relative() - audio_callback_time) > 1000000LL * is->audio_hw_buf_size / is->audio_tgt.bytes_per_sec / 2)
2436 return -1;
2437 av_usleep (1000);
2438 }
2439#endif
2440 if (!(af = frame_queue_peek_readable(&is->sampq)))
2441 return -1;
2442 frame_queue_next(&is->sampq);
2443 } while (af->serial != is->audioq.serial);
2444
2445 data_size = av_samples_get_buffer_size(NULL, af->frame->ch_layout.nb_channels,
2446 af->frame->nb_samples,
2447 af->frame->format, 1);
2448
2449 wanted_nb_samples = synchronize_audio(is, af->frame->nb_samples);
2450
2451 if (af->frame->format != is->audio_src.fmt ||
2452 av_channel_layout_compare(&af->frame->ch_layout, &is->audio_src.ch_layout) ||
2453 af->frame->sample_rate != is->audio_src.freq ||
2454 (wanted_nb_samples != af->frame->nb_samples && !is->swr_ctx)) {
2455 int ret;
2456 swr_free(&is->swr_ctx);
2457 ret = swr_alloc_set_opts2(&is->swr_ctx,
2458 &is->audio_tgt.ch_layout, is->audio_tgt.fmt, is->audio_tgt.freq,
2459 &af->frame->ch_layout, af->frame->format, af->frame->sample_rate,
2460 0, NULL);
2461 if (ret < 0 || swr_init(is->swr_ctx) < 0) {
2462 av_log(NULL, AV_LOG_ERROR,
2463 "Cannot create sample rate converter for conversion of %d Hz %s %d channels to %d Hz %s %d channels!\n",
2464 af->frame->sample_rate, av_get_sample_fmt_name(af->frame->format), af->frame->ch_layout.nb_channels,
2465 is->audio_tgt.freq, av_get_sample_fmt_name(is->audio_tgt.fmt), is->audio_tgt.ch_layout.nb_channels);
2466 swr_free(&is->swr_ctx);
2467 return -1;
2468 }
2469 if (av_channel_layout_copy(&is->audio_src.ch_layout, &af->frame->ch_layout) < 0)
2470 return -1;
2471 is->audio_src.freq = af->frame->sample_rate;
2472 is->audio_src.fmt = af->frame->format;
2473 }
2474
2475 if (is->swr_ctx) {
2476 const uint8_t **in = (const uint8_t **)af->frame->extended_data;
2477 uint8_t **out = &is->audio_buf1;
2478 int out_count = (int64_t)wanted_nb_samples * is->audio_tgt.freq / af->frame->sample_rate + 256;
2479 int out_size = av_samples_get_buffer_size(NULL, is->audio_tgt.ch_layout.nb_channels, out_count, is->audio_tgt.fmt, 0);

Callers 1

sdl_audio_callbackFunction · 0.85

Calls 15

frame_queue_nb_remainingFunction · 0.85
av_gettime_relativeFunction · 0.85
av_usleepFunction · 0.85
frame_queue_nextFunction · 0.85
synchronize_audioFunction · 0.85
swr_freeFunction · 0.85
swr_alloc_set_opts2Function · 0.85
swr_initFunction · 0.85
av_logFunction · 0.85

Tested by

no test coverage detected