gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash ChangeLog libmedia/ffmpeg/AudioDecoderFfm...


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog libmedia/ffmpeg/AudioDecoderFfm...
Date: Wed, 11 Jun 2008 18:53:29 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  08/06/11 18:53:29

Modified files:
        .              : ChangeLog 
        libmedia/ffmpeg: AudioDecoderFfmpeg.cpp 

Log message:
                * libmedia/ffmpeg/AudioDecoderFfmpeg.cpp (decode): reintroduce
                  support for the 'parse' parameter. Still not sure if that's
                  a clean way to decode *sets* of frames, but at least it works
                  for the time being.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.6902&r2=1.6903
http://cvs.savannah.gnu.org/viewcvs/gnash/libmedia/ffmpeg/AudioDecoderFfmpeg.cpp?cvsroot=gnash&r1=1.10&r2=1.11

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.6902
retrieving revision 1.6903
diff -u -b -r1.6902 -r1.6903
--- ChangeLog   11 Jun 2008 15:35:49 -0000      1.6902
+++ ChangeLog   11 Jun 2008 18:53:29 -0000      1.6903
@@ -1,5 +1,12 @@
 2008-06-11 Sandro Santilli <address@hidden>
 
+       * libmedia/ffmpeg/AudioDecoderFfmpeg.cpp (decode): reintroduce
+         support for the 'parse' parameter. Still not sure if that's
+         a clean way to decode *sets* of frames, but at least it works
+         for the time being.
+
+2008-06-11 Sandro Santilli <address@hidden>
+
        * libbase/Buffer.h: add copy ctor and assignment op.
 
 2008-06-11 Benjamin Wolsey <address@hidden>

Index: libmedia/ffmpeg/AudioDecoderFfmpeg.cpp
===================================================================
RCS file: /sources/gnash/gnash/libmedia/ffmpeg/AudioDecoderFfmpeg.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- libmedia/ffmpeg/AudioDecoderFfmpeg.cpp      11 Jun 2008 14:40:27 -0000      
1.10
+++ libmedia/ffmpeg/AudioDecoderFfmpeg.cpp      11 Jun 2008 18:53:29 -0000      
1.11
@@ -20,9 +20,16 @@
 
 #include "AudioDecoderFfmpeg.h"
 #include <cmath> // for std::ceil
+#include <algorithm> // for std::copy
 
 //#define GNASH_DEBUG_AUDIO_DECODING
 
+#ifdef FFMPEG_AUDIO2
+# define AVCODEC_DECODE_AUDIO avcodec_decode_audio2
+#else
+# define AVCODEC_DECODE_AUDIO avcodec_decode_audio
+#endif
+
 namespace gnash {
 namespace media {
        
@@ -200,51 +207,98 @@
                return 0;
        }
 
-#if 0
-       LOG_ONCE( log_unimpl("Parsing inside FFMPEG AudioDecoder (shouldn't be 
needed, core lib should be fixed to not even try)") );
-       // TODO: for each parsed frame, call decodeFrame and
-       //       grow the buffer to return...
-       //assert(!parse);
-       decodedBytes=inputSize; // pretend we decoded everything
-       outputSize=0;           // and that resulting output is empty
-       return 0;
+       size_t retCapacity = AVCODEC_MAX_AUDIO_FRAME_SIZE;
+       boost::uint8_t* retBuf = new boost::uint8_t[retCapacity];
+       int retBufSize = 0;
 
-#else
+#ifdef GNASH_DEBUG_AUDIO_DECODING
+       log_debug("  Parsing loop starts, input is %d bytes, retCapacity is %d 
bytes", inputSize, retCapacity);
+#endif // GNASH_DEBUG_AUDIO_DECODING
+       decodedBytes = 0; // nothing decoded yet
+       while (decodedBytes < inputSize)
+       {
+               boost::uint8_t* frame=0; // parsed frame (pointer into input)
+               int framesize; // parsed frame size
+
+               int consumed = av_parser_parse(_parser, _audioCodecCtx,
+                       &frame, &framesize,
+                       input+decodedBytes, inputSize-decodedBytes,
+                       0, 0); // pts & dts
+               if (consumed < 0)
+               {
+                       log_error(_("av_parser_parse returned %d. Upgrading 
ffmpeg/libavcodec might fix this issue."), consumed);
+                       // Setting data position to data size will get the 
sound removed
+                       // from the active sound list later on.
+                       decodedBytes = inputSize;
+                       break;
+               }
 
-       long bytes_decoded = 0;
-       int bufsize = (AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2;
-       boost::uint8_t* output = new boost::uint8_t[bufsize];
-       boost::uint32_t orgbufsize = bufsize;
-       decodedBytes = 0;
+#if GNASH_PARANOIA_LEVEL > 1
+               // the returned frame pointer is inside the input buffer
+               assert(frame >= input+decodedBytes && frame < input+inputSize);
+               // the returned frame size is within the input size
+               assert(framesize <= inputSize);
+               assert(frame+framesize <= input+inputSize);
+               // the number of bytes skipped to get to the frame
+               // is the offset to the parsed frame
+               assert(consumed == framesize);
+               assert(input+decodedBytes == frame);
+#endif
 
-       bufsize = 0;
-       while (bufsize == 0 && decodedBytes < inputSize)
-       {
-               boost::uint8_t* frame;
-               int framesize;
+               // all good so far, keep going..
+               // (we might do this immediately, as we'll override 
decodedBytes on error anyway)
+               decodedBytes += consumed;
 
-               bytes_decoded = av_parser_parse(_parser, _audioCodecCtx, 
&frame, &framesize, input+decodedBytes, inputSize-decodedBytes, 0, 0); //the 
last 2 is pts & dts
+#ifdef GNASH_DEBUG_AUDIO_DECODING
+               log_debug("   parsed frame is %d bytes (consumed %d/%d)", 
framesize, decodedBytes, inputSize);
+#endif // GNASH_DEBUG_AUDIO_DECODING
 
-               int tmp = 0;
-#ifdef FFMPEG_AUDIO2
-               bufsize = AVCODEC_MAX_AUDIO_FRAME_SIZE;
-               tmp = avcodec_decode_audio2(_audioCodecCtx, 
reinterpret_cast<boost::int16_t*>(output), &bufsize, frame, framesize);
-#else
-               tmp = avcodec_decode_audio(_audioCodecCtx, 
reinterpret_cast<boost::int16_t*>(output), &bufsize, frame, framesize);
-#endif
 
-               if (bytes_decoded < 0 || tmp < 0 || bufsize < 0) {
-                       log_error(_("Error while decoding audio data. Upgrading 
ffmpeg/libavcodec might fix this issue."));
+               // Now, decode the frame. We use the ::decodeFrame specialized 
function
+               // here so resampling is done appropriately
+               boost::uint32_t outSize = 0;
+               boost::uint8_t* outBuf = decodeFrame(frame, framesize, outSize);
+
+               if (!outBuf)
+               {
                        // Setting data position to data size will get the 
sound removed
                        // from the active sound list later on.
                        decodedBytes = inputSize;
                        break;
                }
 
-               decodedBytes += bytes_decoded;
+#ifdef GNASH_DEBUG_AUDIO_DECODING
+               log_debug("   decoded frame is %d bytes, would grow return 
buffer size to %d bytes", outSize, retBufSize+(unsigned)outSize);
+#endif // GNASH_DEBUG_AUDIO_DECODING
+
+               //
+               // Now append this data to the buffer we're going to return
+               //
+
+               // if the new data doesn't fit, reallocate the output
+               // TODO: can use the Buffer class here.. if we return it too...
+               if ( retBufSize+(unsigned)outSize > retCapacity )
+               {
+#ifdef GNASH_DEBUG_AUDIO_DECODING
+                       log_debug("    output buffer won't be able to hold %d 
bytes, capacity is only %d bytes",
+                               retBufSize+(unsigned)outSize, retCapacity);
+#endif // GNASH_DEBUG_AUDIO_DECODING
+                       boost::uint8_t* tmp = retBuf;
+                       retCapacity = std::max(retBufSize+(unsigned)outSize, 
retCapacity*2);
+#ifdef GNASH_DEBUG_AUDIO_DECODING
+                       log_debug("    reallocating it to hold up to %d bytes", 
retCapacity);
+#endif // GNASH_DEBUG_AUDIO_DECODING
+                       retBuf = new boost::uint8_t[retCapacity];
+                       if ( retBufSize ) std::copy(tmp, tmp+retBufSize, 
retBuf);
+                       delete [] tmp;
+               }
+               std::copy(outBuf, outBuf+outSize, retBuf+retBufSize);
+               retBufSize+=(unsigned)outSize;
        }
 
-#endif
+       
+       outputSize = retBufSize;
+       return retBuf;
 
 }
 
@@ -270,12 +324,7 @@
        // then decoding will eventually reduce it
        int outSize = bufsize; 
 
-       int tmp = 
-#ifdef FFMPEG_AUDIO2
-               avcodec_decode_audio2(_audioCodecCtx, outPtr, &outSize, input, 
inputSize);
-#else
-               avcodec_decode_audio (_audioCodecCtx, outPtr, &outSize, input, 
inputSize);
-#endif
+       int tmp = AVCODEC_DECODE_AUDIO(_audioCodecCtx, outPtr, &outSize, input, 
inputSize);
 
 #ifdef GNASH_DEBUG_AUDIO_DECODING
        log_debug(" avcodec_decode_audio[2](ctx, bufptr, %d, input, %d) 
returned %d and set frame_size to %d",




reply via email to

[Prev in Thread] Current Thread [Next in Thread]