Browse code

Use the new avcodec_decode_* API.

Patch by Thilo Borgmann name.surname AT googlemail.com.

Originally committed as revision 18409 to svn://svn.ffmpeg.org/ffmpeg/trunk

Thilo Borgmann authored on 2009/04/10 20:07:52
Showing 1 changed files
... ...
@@ -115,10 +115,13 @@ static void audio_decode_example(const char *outfilename, const char *filename)
115 115
 {
116 116
     AVCodec *codec;
117 117
     AVCodecContext *c= NULL;
118
-    int out_size, size, len;
118
+    int out_size, len;
119 119
     FILE *f, *outfile;
120 120
     uint8_t *outbuf;
121
-    uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE], *inbuf_ptr;
121
+    uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
122
+    AVPacket avpkt;
123
+
124
+    av_init_packet(&avpkt);
122 125
 
123 126
     printf("Audio decoding\n");
124 127
 
... ...
@@ -151,17 +154,16 @@ static void audio_decode_example(const char *outfilename, const char *filename)
151 151
     }
152 152
 
153 153
     /* decode until eof */
154
-    inbuf_ptr = inbuf;
154
+    avpkt.data = inbuf;
155 155
     for(;;) {
156
-        size = fread(inbuf, 1, INBUF_SIZE, f);
157
-        if (size == 0)
156
+        avpkt.size = fread(inbuf, 1, INBUF_SIZE, f);
157
+        if (avpkt.size == 0)
158 158
             break;
159 159
 
160
-        inbuf_ptr = inbuf;
161
-        while (size > 0) {
160
+        avpkt.data = inbuf;
161
+        while (avpkt.size > 0) {
162 162
             out_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;
163
-            len = avcodec_decode_audio2(c, (short *)outbuf, &out_size,
164
-                                       inbuf_ptr, size);
163
+            len = avcodec_decode_audio3(c, (short *)outbuf, &out_size, &avpkt);
165 164
             if (len < 0) {
166 165
                 fprintf(stderr, "Error while decoding\n");
167 166
                 exit(1);
... ...
@@ -170,8 +172,8 @@ static void audio_decode_example(const char *outfilename, const char *filename)
170 170
                 /* if a frame has been decoded, output it */
171 171
                 fwrite(outbuf, 1, out_size, outfile);
172 172
             }
173
-            size -= len;
174
-            inbuf_ptr += len;
173
+            avpkt.size -= len;
174
+            avpkt.data += len;
175 175
         }
176 176
     }
177 177
 
... ...
@@ -314,11 +316,14 @@ static void video_decode_example(const char *outfilename, const char *filename)
314 314
 {
315 315
     AVCodec *codec;
316 316
     AVCodecContext *c= NULL;
317
-    int frame, size, got_picture, len;
317
+    int frame, got_picture, len;
318 318
     FILE *f;
319 319
     AVFrame *picture;
320
-    uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE], *inbuf_ptr;
320
+    uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
321 321
     char buf[1024];
322
+    AVPacket avpkt;
323
+
324
+    av_init_packet(&avpkt);
322 325
 
323 326
     /* set end of buffer to 0 (this ensures that no overreading happens for damaged mpeg streams) */
324 327
     memset(inbuf + INBUF_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE);
... ...
@@ -358,8 +363,8 @@ static void video_decode_example(const char *outfilename, const char *filename)
358 358
 
359 359
     frame = 0;
360 360
     for(;;) {
361
-        size = fread(inbuf, 1, INBUF_SIZE, f);
362
-        if (size == 0)
361
+        avpkt.size = fread(inbuf, 1, INBUF_SIZE, f);
362
+        if (avpkt.size == 0)
363 363
             break;
364 364
 
365 365
         /* NOTE1: some codecs are stream based (mpegvideo, mpegaudio)
... ...
@@ -377,10 +382,9 @@ static void video_decode_example(const char *outfilename, const char *filename)
377 377
 
378 378
         /* here, we use a stream based decoder (mpeg1video), so we
379 379
            feed decoder and see if it could decode a frame */
380
-        inbuf_ptr = inbuf;
381
-        while (size > 0) {
382
-            len = avcodec_decode_video(c, picture, &got_picture,
383
-                                       inbuf_ptr, size);
380
+        avpkt.data = inbuf;
381
+        while (avpkt.size > 0) {
382
+            len = avcodec_decode_video2(c, picture, &got_picture, &avpkt);
384 383
             if (len < 0) {
385 384
                 fprintf(stderr, "Error while decoding frame %d\n", frame);
386 385
                 exit(1);
... ...
@@ -396,16 +400,17 @@ static void video_decode_example(const char *outfilename, const char *filename)
396 396
                          c->width, c->height, buf);
397 397
                 frame++;
398 398
             }
399
-            size -= len;
400
-            inbuf_ptr += len;
399
+            avpkt.size -= len;
400
+            avpkt.data += len;
401 401
         }
402 402
     }
403 403
 
404 404
     /* some codecs, such as MPEG, transmit the I and P frame with a
405 405
        latency of one frame. You must do the following to have a
406 406
        chance to get the last frame of the video */
407
-    len = avcodec_decode_video(c, picture, &got_picture,
408
-                               NULL, 0);
407
+    avpkt.data = NULL;
408
+    avpkt.size = 0;
409
+    len = avcodec_decode_video2(c, picture, &got_picture, &avpkt);
409 410
     if (got_picture) {
410 411
         printf("saving last frame %3d\n", frame);
411 412
         fflush(stdout);