Commit 3d12d106 authored by Clément Bœsch's avatar Clément Bœsch

Merge commit '3d66717f'

* commit '3d66717f':
  examples/decode_audio: use the new audio decoding API
Merged-by: 's avatarClément Bœsch <cboesch@gopro.com>
parents 87e16e2b 3d66717f
...@@ -42,29 +42,34 @@ ...@@ -42,29 +42,34 @@
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame,
FILE *outfile) FILE *outfile)
{ {
int len, got_frame; int i, ch;
int ret, data_size;
while (pkt->size > 0) { /* send the packet with the compressed data to the decoder */
len = avcodec_decode_audio4(dec_ctx, frame, &got_frame, pkt); ret = avcodec_send_packet(dec_ctx, pkt);
if (len < 0) { if (ret < 0) {
fprintf(stderr, "Error while decoding\n"); fprintf(stderr, "Error submitting the packet to the decoder\n");
exit(1);
}
/* read all the output frames (in general there may be any number of them */
while (ret >= 0) {
ret = avcodec_receive_frame(dec_ctx, frame);
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
return;
else if (ret < 0) {
fprintf(stderr, "Error during decoding\n");
exit(1); exit(1);
} }
if (got_frame) { data_size = av_get_bytes_per_sample(dec_ctx->sample_fmt);
int i, ch; if (data_size < 0) {
/* if a frame has been decoded, output it */ /* This should not occur, checking just for paranoia */
int data_size = av_get_bytes_per_sample(dec_ctx->sample_fmt); fprintf(stderr, "Failed to calculate data size\n");
if (data_size < 0) { exit(1);
/* This should not occur, checking just for paranoia */
fprintf(stderr, "Failed to calculate data size\n");
exit(1);
}
for (i = 0; i < frame->nb_samples; i++)
for (ch = 0; ch < dec_ctx->channels; ch++)
fwrite(frame->data[ch] + data_size*i, 1, data_size, outfile);
} }
pkt->size -= len; for (i = 0; i < frame->nb_samples; i++)
pkt->data += len; for (ch = 0; ch < dec_ctx->channels; ch++)
fwrite(frame->data[ch] + data_size*i, 1, data_size, outfile);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment