[Ffmpeg-devel] [PATCH] use avcodec_decode_audio2 in ffplay.c
Limin Wang
lance.lmwang
Thu Mar 8 05:48:23 CET 2007
Hi,
* Michael Niedermayer <michaelni at gmx.at> [2007-03-08 04:17:57 +0100]:
> Hi
>
> On Thu, Mar 08, 2007 at 10:03:53AM +0800, Limin Wang wrote:
> > 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.
>
> as avcodec_decode_audio2() changes data_size this wont work
Yes, it's necessary to reset the data_size to buf_size every time. I have tested with
several samples with the new patch and it's OK.
Thanks,
Limin
-------------- next part --------------
Index: ffplay.c
===================================================================
--- ffplay.c (revision 8268)
+++ ffplay.c (working copy)
@@ -1547,7 +1547,7 @@
}
/* 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 buf_size, double *pts_ptr)
{
AVPacket *pkt = &is->audio_pkt;
int n, len1, data_size;
@@ -1556,7 +1556,8 @@
for(;;) {
/* NOTE: the audio packet can contain several frames */
while (is->audio_pkt_size > 0) {
- len1 = avcodec_decode_audio(is->audio_st->codec,
+ data_size = buf_size;
+ 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 +1633,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/a4e43602/attachment.pgp>
More information about the ffmpeg-devel
mailing list