[Ffmpeg-devel] [PATCH] use avcodec_decode_audio2 in ffplay.c

Limin Wang lance.lmwang
Thu Mar 8 03:03:53 CET 2007


Hi,

* Michael Niedermayer <michaelni at gmx.at> [2007-03-07 15:36:39 +0100]:

> Hi
> 
> On Wed, Mar 07, 2007 at 06:16:38PM +0800, Limin Wang wrote:
> > Hi,
> > 
> > As 'avcodec_decode_audio' is deprecated, the patch try to replace it with
> > avcodec_decode_audio2.
> 
> as audio_buf is passed as argument into audio_decode_frame() so should
> its size, instead of hardcoding the current size, this is very risky as
> there is nothing in the functions documentation which says that the
> buffer must be that large

Yes, now audio_buf is allocated by array, so input the audio_buf actual size by
sizeof(), please review it.


Thanks,
Limin


-------------- next part --------------
Index: ffplay.c
===================================================================
--- ffplay.c	(revision 8289)
+++ ffplay.c	(working copy)
@@ -1547,16 +1547,16 @@
 }
 
 /* decode one audio frame and returns its uncompressed size */
-static int audio_decode_frame(VideoState *is, uint8_t *audio_buf, double *pts_ptr)
+static int audio_decode_frame(VideoState *is, uint8_t *audio_buf, int data_size, double *pts_ptr)
 {
     AVPacket *pkt = &is->audio_pkt;
-    int n, len1, data_size;
+    int n, len1;
     double pts;
 
     for(;;) {
         /* NOTE: the audio packet can contain several frames */
         while (is->audio_pkt_size > 0) {
-            len1 = avcodec_decode_audio(is->audio_st->codec,
+            len1 = avcodec_decode_audio2(is->audio_st->codec,
                                         (int16_t *)audio_buf, &data_size,
                                         is->audio_pkt_data, is->audio_pkt_size);
             if (len1 < 0) {
@@ -1632,7 +1632,7 @@
 
     while (len > 0) {
         if (is->audio_buf_index >= is->audio_buf_size) {
-           audio_size = audio_decode_frame(is, is->audio_buf, &pts);
+           audio_size = audio_decode_frame(is, is->audio_buf, sizeof(is->audio_buf), &pts);
            if (audio_size < 0) {
                 /* if error, just output silence */
                is->audio_buf_size = 1024;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 481 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070308/4a4a49ac/attachment.pgp>



More information about the ffmpeg-devel mailing list