[FFmpeg-cvslog] Merge commit '3d66717f7cb5555257244be8f5bce172ed3af7ac'

Clément Bœsch git at videolan.org
Tue Apr 4 12:31:37 EEST 2017


ffmpeg | branch: master | Clément Bœsch <cboesch at gopro.com> | Tue Apr  4 11:33:04 2017 +0200| [3d12d106775a5a821b3cb3aaaeadd8cb48f19550] | committer: Clément Bœsch

Merge commit '3d66717f7cb5555257244be8f5bce172ed3af7ac'

* commit '3d66717f7cb5555257244be8f5bce172ed3af7ac':
  examples/decode_audio: use the new audio decoding API

Merged-by: Clément Bœsch <cboesch at gopro.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3d12d106775a5a821b3cb3aaaeadd8cb48f19550
---

 doc/examples/decode_audio.c | 43 ++++++++++++++++++++++++-------------------
 1 file changed, 24 insertions(+), 19 deletions(-)

diff --git a/doc/examples/decode_audio.c b/doc/examples/decode_audio.c
index 8ad9f06..47c878d 100644
--- a/doc/examples/decode_audio.c
+++ b/doc/examples/decode_audio.c
@@ -42,29 +42,34 @@
 static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame,
                    FILE *outfile)
 {
-    int len, got_frame;
+    int i, ch;
+    int ret, data_size;
 
-    while (pkt->size > 0) {
-        len = avcodec_decode_audio4(dec_ctx, frame, &got_frame, pkt);
-        if (len < 0) {
-            fprintf(stderr, "Error while decoding\n");
+    /* send the packet with the compressed data to the decoder */
+    ret = avcodec_send_packet(dec_ctx, pkt);
+    if (ret < 0) {
+        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);
         }
-        if (got_frame) {
-            int i, ch;
-            /* if a frame has been decoded, output it */
-            int data_size = av_get_bytes_per_sample(dec_ctx->sample_fmt);
-            if (data_size < 0) {
-                /* 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);
+        data_size = av_get_bytes_per_sample(dec_ctx->sample_fmt);
+        if (data_size < 0) {
+            /* This should not occur, checking just for paranoia */
+            fprintf(stderr, "Failed to calculate data size\n");
+            exit(1);
         }
-        pkt->size -= len;
-        pkt->data += len;
+        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);
     }
 }
 


======================================================================

diff --cc doc/examples/decode_audio.c
index 8ad9f06,5e128f8..47c878d
--- a/doc/examples/decode_audio.c
+++ b/doc/examples/decode_audio.c
@@@ -42,29 -40,29 +42,34 @@@
  static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame,
                     FILE *outfile)
  {
-     int len, got_frame;
++    int i, ch;
+     int ret, data_size;
  
-     while (pkt->size > 0) {
-         len = avcodec_decode_audio4(dec_ctx, frame, &got_frame, pkt);
-         if (len < 0) {
-             fprintf(stderr, "Error while decoding\n");
+     /* send the packet with the compressed data to the decoder */
+     ret = avcodec_send_packet(dec_ctx, pkt);
+     if (ret < 0) {
+         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);
          }
-         if (got_frame) {
-             int i, ch;
-             /* if a frame has been decoded, output it */
-             int data_size = av_get_bytes_per_sample(dec_ctx->sample_fmt);
-             if (data_size < 0) {
-                 /* 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);
 -
 -        data_size = av_samples_get_buffer_size(NULL, dec_ctx->channels,
 -                                               frame->nb_samples,
 -                                               dec_ctx->sample_fmt, 1);
 -        fwrite(frame->data[0], 1, data_size, outfile);
++        data_size = av_get_bytes_per_sample(dec_ctx->sample_fmt);
++        if (data_size < 0) {
++            /* This should not occur, checking just for paranoia */
++            fprintf(stderr, "Failed to calculate data size\n");
++            exit(1);
 +        }
-         pkt->size -= len;
-         pkt->data += len;
++        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);
      }
  }
  



More information about the ffmpeg-cvslog mailing list