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

Function decode_audio_frame

doc/examples/transcode_aac.c:370–430  ·  view source on GitHub ↗

* Decode one audio frame from the input file. * @param frame Audio frame to be decoded * @param input_format_context Format context of the input file * @param input_codec_context Codec context of the input file * @param[out] data_present Indicates whether data has been decoded * @param[out] finished Indicates whether the end of file has *

Source from the content-addressed store, hash-verified

368 * @return Error code (0 if successful)
369 */
370static int decode_audio_frame(AVFrame *frame,
371 AVFormatContext *input_format_context,
372 AVCodecContext *input_codec_context,
373 int *data_present, int *finished)
374{
375 /* Packet used for temporary storage. */
376 AVPacket *input_packet;
377 int error;
378
379 error = init_packet(&input_packet);
380 if (error < 0)
381 return error;
382
383 *data_present = 0;
384 *finished = 0;
385 /* Read one audio frame from the input file into a temporary packet. */
386 if ((error = av_read_frame(input_format_context, input_packet)) < 0) {
387 /* If we are at the end of the file, flush the decoder below. */
388 if (error == AVERROR_EOF)
389 *finished = 1;
390 else {
391 fprintf(stderr, "Could not read frame (error '%s')\n",
392 av_err2str(error));
393 goto cleanup;
394 }
395 }
396
397 /* Send the audio frame stored in the temporary packet to the decoder.
398 * The input audio stream decoder is used to do this. */
399 if ((error = avcodec_send_packet(input_codec_context, input_packet)) < 0) {
400 fprintf(stderr, "Could not send packet for decoding (error '%s')\n",
401 av_err2str(error));
402 goto cleanup;
403 }
404
405 /* Receive one frame from the decoder. */
406 error = avcodec_receive_frame(input_codec_context, frame);
407 /* If the decoder asks for more data to be able to decode a frame,
408 * return indicating that no data is present. */
409 if (error == AVERROR(EAGAIN)) {
410 error = 0;
411 goto cleanup;
412 /* If the end of the input file is reached, stop decoding. */
413 } else if (error == AVERROR_EOF) {
414 *finished = 1;
415 error = 0;
416 goto cleanup;
417 } else if (error < 0) {
418 fprintf(stderr, "Could not decode frame (error '%s')\n",
419 av_err2str(error));
420 goto cleanup;
421 /* Default case: Return decoded data. */
422 } else {
423 *data_present = 1;
424 goto cleanup;
425 }
426
427cleanup:

Callers 1

Calls 5

init_packetFunction · 0.85
av_read_frameFunction · 0.85
avcodec_send_packetFunction · 0.85
avcodec_receive_frameFunction · 0.85
av_packet_freeFunction · 0.85

Tested by

no test coverage detected