gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash ChangeLog libmedia/AudioDecoder.h libmedi...


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog libmedia/AudioDecoder.h libmedi...
Date: Fri, 06 Jun 2008 10:20:00 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  08/06/06 10:19:59

Modified files:
        .              : ChangeLog 
        libmedia       : AudioDecoder.h 
        libmedia/ffmpeg: AudioDecoderFfmpeg.cpp AudioDecoderFfmpeg.h 
        server/asobj   : NetStreamFfmpeg.cpp 

Log message:
                * libmedia/AudioDecoder.h: add a decode(EncodedAudioFrame&) 
method.
                * libmedia/ffmpeg/AudioDecoderFfmpeg.{cpp,h}: Implement
                  decode(EncodeAudioFrame), fix resampling code, disable 
(log_unimp)
                  the "parsing" feature (should be dropped)
                * server/asobj/NetStreamFfmpeg.cpp: use
                  AudioDecoder::decode(EncodedAudioFrame) interface, cleaner.
        
        This fixes sound in NetStream (tested with NetStream-SquareTest.swf
        modified to load the 2hrs.flv movie - mp3 audio in it).

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.6833&r2=1.6834
http://cvs.savannah.gnu.org/viewcvs/gnash/libmedia/AudioDecoder.h?cvsroot=gnash&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/gnash/libmedia/ffmpeg/AudioDecoderFfmpeg.cpp?cvsroot=gnash&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/gnash/libmedia/ffmpeg/AudioDecoderFfmpeg.h?cvsroot=gnash&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/NetStreamFfmpeg.cpp?cvsroot=gnash&r1=1.144&r2=1.145

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.6833
retrieving revision 1.6834
diff -u -b -r1.6833 -r1.6834
--- ChangeLog   6 Jun 2008 03:48:27 -0000       1.6833
+++ ChangeLog   6 Jun 2008 10:19:57 -0000       1.6834
@@ -1,5 +1,15 @@
+2008-06-06 Sandro Santilli <address@hidden>
+
+       * libmedia/AudioDecoder.h: add a decode(EncodedAudioFrame&) method.
+       * libmedia/ffmpeg/AudioDecoderFfmpeg.{cpp,h}: Implement
+         decode(EncodeAudioFrame), fix resampling code, disable (log_unimp)
+         the "parsing" feature (should be dropped)
+       * server/asobj/NetStreamFfmpeg.cpp: use
+         AudioDecoder::decode(EncodedAudioFrame) interface, cleaner.
+
 2008-06-06 Zou Lunkai <address@hidden>
        
+       YOUR ADV HERE
 
 2008-06-06 Sandro Santilli <address@hidden>
 

Index: libmedia/AudioDecoder.h
===================================================================
RCS file: /sources/gnash/gnash/libmedia/AudioDecoder.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- libmedia/AudioDecoder.h     3 Jun 2008 16:11:44 -0000       1.12
+++ libmedia/AudioDecoder.h     6 Jun 2008 10:19:59 -0000       1.13
@@ -87,6 +87,23 @@
        ///
        virtual boost::uint8_t* decode(boost::uint8_t* /*input*/, 
boost::uint32_t /*inputSize*/, boost::uint32_t& /*outputSize*/, 
boost::uint32_t& /*decodedData*/, bool /*parse*/) { return NULL; }
 
+       /// Decodes an EncodedAudioFrame and returns a pointer to the decoded 
data
+       //
+       /// @param input
+       ///     The audio data
+       ///
+       /// @param outputSize
+       ///     The output size of the video data, is passed by reference.
+       ///
+       /// @return a pointer to the decoded data, or NULL if decoding fails.
+       ///     The caller owns the decoded data.
+       ///
+       virtual boost::uint8_t* decode(const EncodedAudioFrame& /*input*/,
+                                      boost::uint32_t& /*outputSize*/)
+       {
+               return NULL;
+       }
+
 };
        
 } // gnash.media namespace 

Index: libmedia/ffmpeg/AudioDecoderFfmpeg.cpp
===================================================================
RCS file: /sources/gnash/gnash/libmedia/ffmpeg/AudioDecoderFfmpeg.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- libmedia/ffmpeg/AudioDecoderFfmpeg.cpp      5 Jun 2008 13:32:45 -0000       
1.7
+++ libmedia/ffmpeg/AudioDecoderFfmpeg.cpp      6 Jun 2008 10:19:59 -0000       
1.8
@@ -20,6 +20,8 @@
 
 #include "AudioDecoderFfmpeg.h"
 
+//#define GNASH_DEBUG_AUDIO_DECODING
+
 namespace gnash {
 namespace media {
        
@@ -167,7 +169,7 @@
        if (_audioCodecCtx->codec->id != CODEC_ID_MP3) {
                _audioCodecCtx->channels = (info->stereo ? 2 : 1);
                _audioCodecCtx->sample_rate = info->sampleRate;
-               //_audioCodecCtx->sample_fmt = SAMPLE_FMT_S16;
+               _audioCodecCtx->sample_fmt = SAMPLE_FMT_S16; // was commented 
out, why ?
        }
 
        log_debug(_("AudioDecoderFfmpeg::setup: initialized FFMPEG codec %s 
(%d)"),
@@ -176,107 +178,135 @@
        return true;
 }
 
-boost::uint8_t* AudioDecoderFfmpeg::decode(boost::uint8_t* input, 
boost::uint32_t inputSize, boost::uint32_t& outputSize, boost::uint32_t& 
decodedBytes, bool parse)
+boost::uint8_t*
+AudioDecoderFfmpeg::decode(boost::uint8_t* input, boost::uint32_t inputSize, 
boost::uint32_t& outputSize, boost::uint32_t& decodedBytes, bool parse)
 {
+       //GNASH_REPORT_FUNCTION;
 
-       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 (parse) {
-       
-               if (!_parser)
+       if ( ! parse )
                {       
-                       log_error(_("libavcodec can't parse the current audio 
format"));
-                       return NULL;
+               boost::uint8_t* ret = decodeFrame(input, inputSize, outputSize);
+               if ( ret ) decodedBytes=inputSize;
+               else decodedBytes=0;
+               return ret;
                }
        
+       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;
+}
        
-               bufsize = 0;
-               while (bufsize == 0 && decodedBytes < inputSize) {
-                       boost::uint8_t* frame;
-                       int framesize;
-
-                       bytes_decoded = av_parser_parse(_parser, 
_audioCodecCtx, &frame, &framesize, input+decodedBytes, inputSize-decodedBytes, 
0, 0); //the last 2 is pts & dts
-
-                       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
+boost::uint8_t*
+AudioDecoderFfmpeg::decode(const EncodedAudioFrame& ef, boost::uint32_t& 
outputSize)
+{
+       return decodeFrame(ef.data.get(), ef.dataSize, outputSize);
+}
 
-                       if (bytes_decoded < 0 || tmp < 0 || bufsize < 0) {
-                               log_error(_("Error while decoding audio data. 
Upgrading ffmpeg/libavcodec might fix this issue."));
-                               // Setting data position to data size will get 
the sound removed
-                               // from the active sound list later on.
-                               decodedBytes = inputSize;
-                               break;
-                       }
+boost::uint8_t*
+AudioDecoderFfmpeg::decodeFrame(boost::uint8_t* input, boost::uint32_t 
inputSize, boost::uint32_t& outputSize)
+{
+       //GNASH_REPORT_FUNCTION;
 
-                       decodedBytes += bytes_decoded;
-               }
+        //static const unsigned int bufsize = (AVCODEC_MAX_AUDIO_FRAME_SIZE * 
3) / 2;
+        static const unsigned int bufsize = AVCODEC_MAX_AUDIO_FRAME_SIZE;
 
-       } else {
+       // TODO: make this a private member, to reuse (see NetStreamFfmpeg in 
0.8.3)
+       boost::uint8_t* output = new boost::uint8_t[bufsize];
+        boost::int16_t* outPtr = reinterpret_cast<boost::int16_t*>(output);
 
-               int tmp = 0;
+       // We initialize output size to the full size
+       // then decoding will eventually reduce it
+       int outSize = bufsize; 
 
+       int tmp = 
 #ifdef FFMPEG_AUDIO2
-               tmp = avcodec_decode_audio2(_audioCodecCtx, 
reinterpret_cast<boost::int16_t*>(output), &bufsize, input, inputSize);
+               avcodec_decode_audio2(_audioCodecCtx, outPtr, &outSize, input, 
inputSize);
 #else
-               tmp = avcodec_decode_audio(_audioCodecCtx, 
reinterpret_cast<boost::int16_t*>(output), &bufsize, input, inputSize);
+               avcodec_decode_audio (_audioCodecCtx, outPtr, &outSize, input, 
inputSize);
 #endif
 
+#ifdef GNASH_DEBUG_AUDIO_DECODING
+       log_debug(" avcodec_decode_audio[2](ctx, bufptr, %d, input, %d) 
returned %d and set frame_size to %d",
+               bufsize, inputSize, tmp, outSize);
+#endif
 
-
-               if (bytes_decoded < 0 || tmp < 0 || bufsize < 0) {
-                       log_error(_("Error while decoding audio data. Upgrading 
ffmpeg/libavcodec might fix this issue."));
-                       // Setting data position to data size will get the 
sound removed
-                       // from the active sound list later on.
-                       decodedBytes = 0;
+       if (tmp < 0)
+       {
+               log_error(_("avcodec_decode_audio returned %d. Upgrading 
ffmpeg/libavcodec might fix this issue."), tmp);
                        outputSize = 0;
                        delete [] output;
                        return NULL;
                }
 
-               decodedBytes = inputSize;
-       }
-
-       // Error handling
-       if (bufsize < 1) {
-               log_error(_("Error while decoding audio data."));
-               delete [] output;
-               decodedBytes = 0;
+       if (outSize < 1)
+       {
+               log_error(_("outputSize:%d after decoding audio data. Upgrading 
ffmpeg/libavcodec might fix this issue."),
+                       outputSize);
                outputSize = 0;
+               delete [] output;
                return NULL;
        }
 
        // Resampling is needed.
-       if (_resampler.init(_audioCodecCtx)) {
+       if (_resampler.init(_audioCodecCtx))
+       {
+               // Resampling is needed.
+
+               // Compute new size based on frame_size and
+               // resampling configuration
+               double resampleFactor = (44100.0/_audioCodecCtx->sample_rate) * 
(2.0/_audioCodecCtx->channels);
                bool stereo = _audioCodecCtx->channels > 1 ? true : false;
-               int samples = stereo ? bufsize >> 2 : bufsize >> 1;
+               int samples = stereo ? outSize >> 2 : outSize >> 1;
 
-               boost::uint8_t* tmp = new boost::uint8_t[orgbufsize];
+               int resampledFrameSize = int(ceil(outSize*resampleFactor));
                        
-               samples = 
_resampler.resample(reinterpret_cast<boost::int16_t*>(output),
-                                                
reinterpret_cast<boost::int16_t*>(tmp),
-                                                samples);
-               outputSize = samples *2 *2; // the resampled audio has 
samplesize 2, and is stereo
-               boost::uint8_t* ret = new boost::uint8_t[outputSize];
-               memcpy(ret, tmp, outputSize);
-               delete [] tmp;
-               delete [] output;
-               return ret;
-       } else {
-               outputSize = bufsize;
-               boost::uint8_t* ret = new boost::uint8_t[outputSize];
-               memcpy(ret, output, outputSize);
+               // Allocate just the required amount of bytes
+               boost::uint8_t* resampledOutput = new boost::uint8_t[bufsize]; 
// be safe for now, but should be resampledFrameSize;
+
+#ifdef GNASH_DEBUG_AUDIO_DECODING
+               log_debug("Calling the resampler; "
+                       "ouput to 44100hz, 2channels; "
+                       "input is %dhz, %dchannels",
+                       _audioCodecCtx->sample_rate, _audioCodecCtx->channels);
+#endif
+
+               samples = _resampler.resample(outPtr, // input
+                       reinterpret_cast<boost::int16_t*>(resampledOutput), // 
output
+                       samples); // input..
+
+               // make sure to set outPtr *after* we use it as input to the 
resampler
+               outPtr = reinterpret_cast<boost::int16_t*>(resampledOutput);
                delete [] output;
-               return ret;             
+
+               if (resampledFrameSize < samples*2*2)
+               {
+                       log_error(" --- Computation of resampled frame size 
(%d) < then the one based on samples (%d)",
+                               resampledFrameSize, samples*2*2);
+
+                       log_debug(" input frame size: %d", outSize);
+                       log_debug(" input sample rate: %d", 
_audioCodecCtx->sample_rate);
+                       log_debug(" input channels: %d", 
_audioCodecCtx->channels);
+                       log_debug(" input samples: %d", samples);
+
+                       log_debug(" output sample rate (assuming): %d", 44100);
+                       log_debug(" output channels (assuming): %d", 2);
+                       log_debug(" output samples: %d", samples);
+
+                       abort(); // the call to resample() likely corrupted 
memory...
        }
+
+               // we let the consistency check run before we override outSize
+               // to make debugging values correct
+               outSize = resampledFrameSize;
+
+       }
+
+       outputSize = outSize;
+       return reinterpret_cast<uint8_t*>(outPtr);
 }
 
 

Index: libmedia/ffmpeg/AudioDecoderFfmpeg.h
===================================================================
RCS file: /sources/gnash/gnash/libmedia/ffmpeg/AudioDecoderFfmpeg.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- libmedia/ffmpeg/AudioDecoderFfmpeg.h        23 May 2008 05:58:09 -0000      
1.4
+++ libmedia/ffmpeg/AudioDecoderFfmpeg.h        6 Jun 2008 10:19:59 -0000       
1.5
@@ -54,8 +54,12 @@
 
        boost::uint8_t* decode(boost::uint8_t* input, boost::uint32_t 
inputSize, boost::uint32_t& outputSize, boost::uint32_t& decodedBytes, bool 
parse);
 
+       boost::uint8_t* decode(const EncodedAudioFrame& af, boost::uint32_t& 
outputSize);
+
 private:
 
+       boost::uint8_t* decodeFrame(boost::uint8_t* input, boost::uint32_t 
inputSize, boost::uint32_t& outputSize);
+
        AVCodec* _audioCodec;
        AVCodecContext* _audioCodecCtx;
        AVCodecParserContext* _parser;

Index: server/asobj/NetStreamFfmpeg.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/NetStreamFfmpeg.cpp,v
retrieving revision 1.144
retrieving revision 1.145
diff -u -b -r1.144 -r1.145
--- server/asobj/NetStreamFfmpeg.cpp    5 Jun 2008 13:51:55 -0000       1.144
+++ server/asobj/NetStreamFfmpeg.cpp    6 Jun 2008 10:19:59 -0000       1.145
@@ -507,15 +507,15 @@
        }
 
        media::raw_mediadata_t* raw = new media::raw_mediadata_t();
-       boost::uint32_t decodedData=0;
-       bool parseAudio = true; // I don't get this...
-       raw->m_data = _audioDecoder->decode(frame->data.get(), frame->dataSize, 
raw->m_size, decodedData, parseAudio);
+       raw->m_data = _audioDecoder->decode(*frame, raw->m_size);
 
-       if ( decodedData != frame->dataSize )
-       {
-               log_error("FIXME: NetStreamFfmpeg::decodeNextAudioFrame: not 
all data in EncodedAudioFrame was decoded, just %d/%d bytes.",
-                       decodedData,frame->dataSize);
-       }
+#ifdef GNASH_DEBUG_DECODING
+        log_debug("NetStreamFfmpeg::decodeNextAudioFrame: "
+                "%d bytes of encoded audio "
+                "decoded to %d bytes",
+                frame->dataSize,
+                raw->m_size);
+#endif // GNASH_DEBUG_DECODING
 
        //raw->m_stream_index = m_audio_index; // no idea what this is needed 
for
        raw->m_ptr = raw->m_data; // no idea what this is needed for




reply via email to

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