gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] [SCM] Gnash branch, master, updated. release_0_8_9_final-


From: Bastiaan Jacques
Subject: [Gnash-commit] [SCM] Gnash branch, master, updated. release_0_8_9_final-2162-gdb94166
Date: Fri, 12 Sep 2014 21:34:06 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Gnash".

The branch, master has been updated
       via  db94166994fad90d01b47aa7f5fec639dd32c942 (commit)
       via  66b83d0b1490cb22fb0a18588fcfc5cdb890fef6 (commit)
       via  5477eaad21f3cddb17243ab527332b934dc275f6 (commit)
       via  09e80bfc7e061f77c0afb539e7b2844d0dbc8ef6 (commit)
       via  5e419485a472ac8a8495a21d0791f9ff20c69477 (commit)
       via  345e5286e26b25afb487d73eb17d6e9cd7624209 (commit)
       via  96f7d4705151a4c383cd9bd518f0bd0c178eb18d (commit)
       via  9ae4b8bdc707cd6f60d19c126f52ed7110833a52 (commit)
       via  bebc26da7dcbbae45280f609ffce34a612b02cd4 (commit)
      from  6c5143024c91f79d381353f4f910ede1824c1875 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit//commit/?id=db94166994fad90d01b47aa7f5fec639dd32c942


commit db94166994fad90d01b47aa7f5fec639dd32c942
Author: Bastiaan Jacques <address@hidden>
Date:   Fri Sep 12 21:09:59 2014 +0200

    Fix typo.

diff --git a/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp 
b/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp
index 41d27af..09dc291 100644
--- a/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp
+++ b/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp
@@ -375,7 +375,7 @@ VideoDecoderFfmpeg::decode(const std::uint8_t* input,
                                               frame.get(), &got_frame, &pkt);
     
     if (bytesConsumed < 0) {
-        log_error(_("Decoding of a video frame failed: %1%", bytesConsumed));
+        log_error(_("Decoding of a video frame failed: %1%"), bytesConsumed);
         return ret;
     }
     if (bytesConsumed < input_size) {

http://git.savannah.gnu.org/cgit//commit/?id=66b83d0b1490cb22fb0a18588fcfc5cdb890fef6


commit 66b83d0b1490cb22fb0a18588fcfc5cdb890fef6
Author: Bastiaan Jacques <address@hidden>
Date:   Fri Sep 12 20:58:46 2014 +0200

    Set the mime_type field for new libavformat (and hope there was no ffmpeg 
release between the addition of the field and the bumping of the ffmpeg 
version.)
    
    Should fix the memory error detected by asan on the buildbots.

diff --git a/libmedia/ffmpeg/MediaParserFfmpeg.cpp 
b/libmedia/ffmpeg/MediaParserFfmpeg.cpp
index c6fb459..2c64eed 100644
--- a/libmedia/ffmpeg/MediaParserFfmpeg.cpp
+++ b/libmedia/ffmpeg/MediaParserFfmpeg.cpp
@@ -86,7 +86,10 @@ MediaParserFfmpeg::probeStream()
        probe_data.filename = "";
        probe_data.buf = buffer.get();
     probe_data.buf_size = actuallyRead;
-       
+#if LIBAVFORMAT_VERSION_MAJOR > 55
+    probe_data.mime_type = nullptr;
+#endif
+
     AVInputFormat* ret = av_probe_input_format(&probe_data, 1);
        return ret;
 }

http://git.savannah.gnu.org/cgit//commit/?id=5477eaad21f3cddb17243ab527332b934dc275f6


commit 5477eaad21f3cddb17243ab527332b934dc275f6
Author: Bastiaan Jacques <address@hidden>
Date:   Tue Jun 24 14:56:39 2014 +0200

    Fix spacing.

diff --git a/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp 
b/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp
index a2a128c..41d27af 100644
--- a/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp
+++ b/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp
@@ -359,7 +359,7 @@ VideoDecoderFfmpeg::decode(const std::uint8_t* input,
 
     std::unique_ptr<image::GnashImage> ret;
 
-    std::unique_ptr<AVFrame, decltype(av_free)*> frame ( FRAMEALLOC(), av_free 
);
+    std::unique_ptr<AVFrame, decltype(av_free)*> frame(FRAMEALLOC(), av_free);
     if ( ! frame ) {
         log_error(_("Out of memory while allocating avcodec frame"));
         return ret;

http://git.savannah.gnu.org/cgit//commit/?id=09e80bfc7e061f77c0afb539e7b2844d0dbc8ef6


commit 09e80bfc7e061f77c0afb539e7b2844d0dbc8ef6
Author: Bastiaan Jacques <address@hidden>
Date:   Tue Jun 24 12:40:07 2014 +0200

    Handle avcodec_decode_video2() return values. Clean up a bit.

diff --git a/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp 
b/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp
index 911df6f..a2a128c 100644
--- a/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp
+++ b/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp
@@ -359,30 +359,35 @@ VideoDecoderFfmpeg::decode(const std::uint8_t* input,
 
     std::unique_ptr<image::GnashImage> ret;
 
-    AVFrame* frame = FRAMEALLOC();
+    std::unique_ptr<AVFrame, decltype(av_free)*> frame ( FRAMEALLOC(), av_free 
);
     if ( ! frame ) {
         log_error(_("Out of memory while allocating avcodec frame"));
         return ret;
     }
 
-    int bytes = 0;    
+    int got_frame = 0;
     // no idea why avcodec_decode_video wants a non-const input...
     AVPacket pkt;
     av_init_packet(&pkt);
     pkt.data = const_cast<uint8_t*>(input);
     pkt.size = input_size;
-    avcodec_decode_video2(_videoCodecCtx->getContext(), frame, &bytes,
-            &pkt);
+    int bytesConsumed = avcodec_decode_video2(_videoCodecCtx->getContext(),
+                                              frame.get(), &got_frame, &pkt);
     
-    if (!bytes) {
-        log_error(_("Decoding of a video frame failed"));
-        av_free(frame);
+    if (bytesConsumed < 0) {
+        log_error(_("Decoding of a video frame failed: %1%", bytesConsumed));
+        return ret;
+    }
+    if (bytesConsumed < input_size) {
+        log_error("only %1% of %2% bytes consumed", bytesConsumed, input_size);
+    }
+    if (!got_frame) {
+        log_debug("Decoding succeeded, but no frame is available yet.");
         return ret;
     }
 
     ret = frameToImage(_videoCodecCtx->getContext(), *frame);
 
-    av_free(frame);
     return ret;
 }
 

http://git.savannah.gnu.org/cgit//commit/?id=5e419485a472ac8a8495a21d0791f9ff20c69477


commit 5e419485a472ac8a8495a21d0791f9ff20c69477
Author: Bastiaan Jacques <address@hidden>
Date:   Tue Jun 24 11:28:43 2014 +0200

    'frame' does not own frame->data in this case.

diff --git a/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp 
b/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp
index cbed605..911df6f 100644
--- a/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp
+++ b/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp
@@ -382,7 +382,6 @@ VideoDecoderFfmpeg::decode(const std::uint8_t* input,
 
     ret = frameToImage(_videoCodecCtx->getContext(), *frame);
 
-    // FIXME: av_free doesn't free frame->data!
     av_free(frame);
     return ret;
 }

http://git.savannah.gnu.org/cgit//commit/?id=345e5286e26b25afb487d73eb17d6e9cd7624209


commit 345e5286e26b25afb487d73eb17d6e9cd7624209
Author: Bastiaan Jacques <address@hidden>
Date:   Tue Jun 24 11:22:28 2014 +0200

    Drop code supporting unsupported FFMPEG versions.

diff --git a/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp 
b/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp
index 81256ec..cbed605 100644
--- a/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp
+++ b/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp
@@ -186,11 +186,7 @@ VideoDecoderFfmpeg::init(enum CODECID codecId, int 
/*width*/, int /*height*/,
         throw MediaException(_("libavcodec can't decode this video format"));
     }
 
-#if LIBAVCODEC_VERSION_INT > AV_VERSION_INT(53,8,0)
     _videoCodecCtx.reset(new 
CodecContextWrapper(avcodec_alloc_context3(_videoCodec)));
-#else
-    _videoCodecCtx.reset(new CodecContextWrapper(avcodec_alloc_context()));
-#endif
     if (!_videoCodecCtx->getContext()) {
         throw MediaException(_("libavcodec couldn't allocate context"));
     }
@@ -217,11 +213,7 @@ VideoDecoderFfmpeg::init(enum CODECID codecId, int 
/*width*/, int /*height*/,
     }
 #endif
 
-#if LIBAVCODEC_VERSION_INT > AV_VERSION_INT(53,8,0)
     int ret = avcodec_open2(ctx, _videoCodec, nullptr);
-#else
-    int ret = avcodec_open(ctx, _videoCodec);
-#endif
     if (ret < 0) {
         boost::format msg = boost::format(_("libavcodec "
                             "failed to initialize FFMPEG "
@@ -375,17 +367,12 @@ VideoDecoderFfmpeg::decode(const std::uint8_t* input,
 
     int bytes = 0;    
     // no idea why avcodec_decode_video wants a non-const input...
-#if LIBAVCODEC_VERSION_MAJOR >= 53
     AVPacket pkt;
     av_init_packet(&pkt);
     pkt.data = const_cast<uint8_t*>(input);
     pkt.size = input_size;
     avcodec_decode_video2(_videoCodecCtx->getContext(), frame, &bytes,
             &pkt);
-#else
-    avcodec_decode_video(_videoCodecCtx->getContext(), frame, &bytes,
-            input, input_size);
-#endif
     
     if (!bytes) {
         log_error(_("Decoding of a video frame failed"));

http://git.savannah.gnu.org/cgit//commit/?id=96f7d4705151a4c383cd9bd518f0bd0c178eb18d


commit 96f7d4705151a4c383cd9bd518f0bd0c178eb18d
Author: Bastiaan Jacques <address@hidden>
Date:   Tue Jun 24 11:07:03 2014 +0200

    Pad, rather than double, the encoded buffers.

diff --git a/libmedia/ffmpeg/MediaParserFfmpeg.cpp 
b/libmedia/ffmpeg/MediaParserFfmpeg.cpp
index 634254e..c6fb459 100644
--- a/libmedia/ffmpeg/MediaParserFfmpeg.cpp
+++ b/libmedia/ffmpeg/MediaParserFfmpeg.cpp
@@ -168,10 +168,9 @@ MediaParserFfmpeg::parseVideoFrame(AVPacket& packet)
        // flags, for keyframe
        //bool isKeyFrame = packet.flags&PKT_FLAG_KEY;
 
-       // TODO: FIXME: *2 is an hack to avoid libavcodec reading past end of 
allocated space
-       //       we might do proper padding or (better) avoid the copy as a 
whole by making
-       //       EncodedVideoFrame virtual.
-       size_t allocSize = packet.size*2;
+       // TODO: We might avoid the copy as a whole by making EncodedVideoFrame
+       //       virtual.
+       size_t allocSize = packet.size + FF_INPUT_BUFFER_PADDING_SIZE;
        std::uint8_t* data = new std::uint8_t[allocSize];
        std::copy(packet.data, packet.data+packet.size, data);
        std::unique_ptr<EncodedVideoFrame> frame(new EncodedVideoFrame(data, 
packet.size, 0, timestamp));
@@ -217,10 +216,9 @@ MediaParserFfmpeg::parseAudioFrame(AVPacket& packet)
 
        std::unique_ptr<EncodedAudioFrame> frame ( new EncodedAudioFrame );
 
-       // TODO: FIXME: *2 is an hack to avoid libavcodec reading past end of 
allocated space
-       //       we might do proper padding or (better) avoid the copy as a 
whole by making
-       //       EncodedVideoFrame virtual.
-       size_t allocSize = packet.size*2;
+       // TODO: We might avoid the copy as a whole by making EncodedAudioFrame
+       //       virtual.
+       size_t allocSize = packet.size + FF_INPUT_BUFFER_PADDING_SIZE;
        std::uint8_t* data = new std::uint8_t[allocSize];
        std::copy(packet.data, packet.data+packet.size, data);
 

http://git.savannah.gnu.org/cgit//commit/?id=9ae4b8bdc707cd6f60d19c126f52ed7110833a52


commit 9ae4b8bdc707cd6f60d19c126f52ed7110833a52
Author: Bastiaan Jacques <address@hidden>
Date:   Tue Jun 24 00:18:23 2014 +0200

    Drop code from unsupported FFMPEG versions.

diff --git a/libmedia/ffmpeg/AudioDecoderFfmpeg.cpp 
b/libmedia/ffmpeg/AudioDecoderFfmpeg.cpp
index 26c213b..0400eb3 100644
--- a/libmedia/ffmpeg/AudioDecoderFfmpeg.cpp
+++ b/libmedia/ffmpeg/AudioDecoderFfmpeg.cpp
@@ -78,10 +78,6 @@ AudioDecoderFfmpeg::~AudioDecoderFfmpeg()
 
 void AudioDecoderFfmpeg::setup(SoundInfo& info)
 {
-#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(52,6,2)
-    // Starting from this version avcodec_register calls avcodec_init
-    avcodec_init();
-#endif
     avcodec_register_all();// change this to only register need codec?
 
     enum CODECID codec_id;
@@ -127,20 +123,12 @@ void AudioDecoderFfmpeg::setup(SoundInfo& info)
         }
     }
 
-#if LIBAVCODEC_VERSION_INT > AV_VERSION_INT(53,8,0)
     _audioCodecCtx = avcodec_alloc_context3(_audioCodec);
-#else
-    _audioCodecCtx = avcodec_alloc_context();
-#endif
     if (!_audioCodecCtx) {
         throw MediaException(_("libavcodec couldn't allocate context"));
     }
 
-#if LIBAVCODEC_VERSION_INT > AV_VERSION_INT(53,8,0)
     int ret = avcodec_open2(_audioCodecCtx, _audioCodec, nullptr);
-#else
-    int ret = avcodec_open(_audioCodecCtx, _audioCodec);
-#endif
     if (ret < 0) {
         av_free(_audioCodecCtx);
         _audioCodecCtx=nullptr;
@@ -177,10 +165,6 @@ void AudioDecoderFfmpeg::setup(SoundInfo& info)
 void AudioDecoderFfmpeg::setup(const AudioInfo& info)
 {
     // Init the avdecoder-decoder
-#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(52,6,2)
-    // Starting from this version avcodec_register calls avcodec_init
-    avcodec_init();
-#endif
     avcodec_register_all();// change this to only register need codec?
 
     enum CODECID codec_id = AV_CODEC_ID_NONE;
@@ -261,11 +245,7 @@ void AudioDecoderFfmpeg::setup(const AudioInfo& info)
     _needsParsing = (_parser != nullptr);
 
     // Create an audioCodecCtx from the ffmpeg parser if exists/possible
-#if LIBAVCODEC_VERSION_INT > AV_VERSION_INT(53,8,0)
     _audioCodecCtx = avcodec_alloc_context3(_audioCodec);
-#else
-    _audioCodecCtx = avcodec_alloc_context();
-#endif
     if (!_audioCodecCtx) {
         throw MediaException(_("AudioDecoderFfmpeg: libavcodec couldn't "
                     "allocate context"));
@@ -316,11 +296,7 @@ void AudioDecoderFfmpeg::setup(const AudioInfo& info)
 #ifdef GNASH_DEBUG_AUDIO_DECODING
     log_debug("  Opening codec");
 #endif // GNASH_DEBUG_AUDIO_DECODING
-#if LIBAVCODEC_VERSION_INT > AV_VERSION_INT(53,8,0)
     int ret = avcodec_open2(_audioCodecCtx, _audioCodec, nullptr);
-#else
-    int ret = avcodec_open(_audioCodecCtx, _audioCodec);
-#endif
     if (ret < 0) {
         //avcodec_close(_audioCodecCtx);
         av_free(_audioCodecCtx);
@@ -548,21 +524,13 @@ AudioDecoderFfmpeg::parseInput(const std::uint8_t* input,
 {
     if ( _needsParsing )
     {
-#if LIBAVCODEC_VERSION_MAJOR >= 53
         return av_parser_parse2(_parser, _audioCodecCtx,
-#else
-        return av_parser_parse(_parser, _audioCodecCtx,
-#endif
                     // as of 2008-10-28 SVN, ffmpeg doesn't
                     // accept a pointer to pointer to const..
                     const_cast<std::uint8_t**>(outFrame),
                     outFrameSize,
                     input, inputSize,
-#if LIBAVCODEC_VERSION_MAJOR >= 53
                     0, 0, AV_NOPTS_VALUE); // pts, dts, pos
-#else
-                    0, 0); // pts & dts
-#endif
     }
     else
     {

http://git.savannah.gnu.org/cgit//commit/?id=bebc26da7dcbbae45280f609ffce34a612b02cd4


commit bebc26da7dcbbae45280f609ffce34a612b02cd4
Author: Bastiaan Jacques <address@hidden>
Date:   Tue Jun 24 00:14:21 2014 +0200

    Don't reallocate the audio buffer should it need to be resampled.
    
    Also simplify things considerably.

diff --git a/libmedia/ffmpeg/AudioDecoderFfmpeg.cpp 
b/libmedia/ffmpeg/AudioDecoderFfmpeg.cpp
index 56b5248..26c213b 100644
--- a/libmedia/ffmpeg/AudioDecoderFfmpeg.cpp
+++ b/libmedia/ffmpeg/AudioDecoderFfmpeg.cpp
@@ -470,23 +470,9 @@ std::uint8_t*
 AudioDecoderFfmpeg::decodeFrame(const std::uint8_t* input,
         std::uint32_t inputSize, std::uint32_t& outputSize)
 {
-    //GNASH_REPORT_FUNCTION;
-
     assert(inputSize);
 
-    size_t outSize = MAX_AUDIO_FRAME_SIZE;
-
-    // TODO: make this a private member, to reuse (see NetStreamFfmpeg in 
0.8.3)
-    std::unique_ptr<std::int16_t, decltype(av_free)*> output(
-        reinterpret_cast<std::int16_t*>(av_malloc(outSize)), av_free );
-    if (!output.get()) {
-        log_error(_("failed to allocate audio buffer."));
-        outputSize = 0;
-        return nullptr;
-    }
-
-    std::int16_t* outPtr = output.get();
-
+    outputSize = 0;
 
 #ifdef GNASH_DEBUG_AUDIO_DECODING
     log_debug("AudioDecoderFfmpeg: about to decode %d bytes; "
@@ -496,7 +482,6 @@ AudioDecoderFfmpeg::decodeFrame(const std::uint8_t* input,
 
     // older ffmpeg versions didn't accept a const input..
     AVPacket pkt;
-    int got_frm = 0;
     av_init_packet(&pkt);
     pkt.data = const_cast<uint8_t*>(input);
     pkt.size = inputSize;
@@ -505,7 +490,28 @@ AudioDecoderFfmpeg::decodeFrame(const std::uint8_t* input,
         log_error(_("failed to allocate frame."));
         return nullptr;
     }
-    int tmp = avcodec_decode_audio4(_audioCodecCtx, frm.get(), &got_frm, &pkt);
+
+    int got_frm = 0;
+    int bytesRead = avcodec_decode_audio4(_audioCodecCtx, frm.get(), &got_frm, 
&pkt);
+
+    // FIXME: "[Some] decoders ... decode the first frame and the return value
+    // would be less than the packet size. In this case, avcodec_decode_audio4
+    // has to be called again with an AVPacket containing the remaining data in
+    // order to decode the second frame, etc... Even if no frames are returned,
+    // the packet needs to be fed to the decoder with remaining data until it
+    // is completely consumed or an error occurs."
+
+    if (bytesRead < 0) {
+        log_error(_("avcodec_decode_audio4() returned error code %d."), 
bytesRead);
+        return nullptr;
+    }
+    if (!got_frm) {
+        // FIXME: "Note that this field being set to zero does not mean that an
+        // error has occurred. For decoders with CODEC_CAP_DELAY set, no given
+        // decode call is guaranteed to produce a frame."
+        log_error(_("avcodec_decode_audio4() didn't produce a frame."));
+        return nullptr;
+    }
 
 #ifdef GNASH_DEBUG_AUDIO_DECODING
     const char* fmtname = av_get_sample_fmt_name(_audioCodecCtx->sample_fmt);
@@ -513,118 +519,26 @@ AudioDecoderFfmpeg::decodeFrame(const std::uint8_t* 
input,
         "returned %d | inputSize: %d",
         frm->nb_samples, got_frm, tmp, inputSize);
 #endif
+    bool resamplingNeeded = _resampler.init(_audioCodecCtx);
 
-    int plane_size;
-    if (tmp >= 0 && got_frm) {
-        int data_size = av_samples_get_buffer_size( &plane_size,
-            _audioCodecCtx->channels, frm->nb_samples,
-            _audioCodecCtx->sample_fmt, 1);
-        if (static_cast<int>(outSize) < data_size) {
-            log_error(_("output buffer size is too small for the current frame 
"
-                "(%d < %d)"), outSize, data_size);
-            return nullptr;
-        }
-
-        memcpy(outPtr, frm->extended_data[0], plane_size);
-
-#if !(defined(HAVE_SWRESAMPLE_H) || defined(HAVE_AVRESAMPLE_H))
-        int planar = av_sample_fmt_is_planar(_audioCodecCtx->sample_fmt);
-        if (planar && _audioCodecCtx->channels > 1) {
-            uint8_t *out = ((uint8_t *)outPtr) + plane_size;
-            for (int ch = 1; ch < _audioCodecCtx->channels; ch++) {
-                memcpy(out, frm->extended_data[ch], plane_size);
-                out += plane_size;
-            }
-        }
-#endif
+    int plane_size = 0;
+    int frameSize = av_samples_get_buffer_size(&plane_size, 2 /* channels */,
+        frm->nb_samples, AV_SAMPLE_FMT_S16, 0 /* default alignment */);
 
-        outSize = data_size;
-#ifdef GNASH_DEBUG_AUDIO_DECODING
-        log_debug(" decodeFrame | fmt: %d | fmt_name: %s | planar: %d | "
-            "plane_size: %d | outSize: %d",
-            _audioCodecCtx->sample_fmt, fmtname, planar, plane_size, outSize);
-#endif
+    // TODO: make this a private member, to reuse (see NetStreamFfmpeg in 
0.8.3)
+    std::unique_ptr<uint8_t[]> output(new std::uint8_t[frameSize]);
+    outputSize = frameSize;
+    if (!resamplingNeeded) {
+        memcpy(output.get(), frm->extended_data[0], frameSize);
     } else {
-        if (tmp < 0)
-            log_error(_("avcodec_decode_audio returned %d."), tmp);
-        if (outSize < 2)
-            log_error(_("outputSize:%d after decoding %d bytes of input audio "
-                "data."), outputSize, inputSize);
-        log_error(_("Upgrading ffmpeg/libavcodec might fix this issue."));
-        outputSize = 0;
-        return nullptr;
-    }
-
-    // Resampling is needed.
-    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 inSamples = stereo ? outSize >> 2 : outSize >> 1;
-
-        int expectedMaxOutSamples = std::ceil(inSamples*resampleFactor);
-
-        // *channels *sampleSize 
-        int resampledFrameSize = expectedMaxOutSamples*2*2;
-
-        // Allocate just the required amount of bytes
-        std::uint8_t* resampledOutput = new std::uint8_t[resampledFrameSize];
-
-#ifdef GNASH_DEBUG_AUDIO_DECODING
-        log_debug(" decodeFrame | Calling the resampler, resampleFactor: %d | "
-            "in %d hz %d ch %d bytes %d samples, %s fmt", resampleFactor,
-            _audioCodecCtx->sample_rate, _audioCodecCtx->channels, outSize,
-            inSamples, fmtname);
-        log_debug(" decodeFrame | out 44100 hz 2 ch %d bytes",
-            resampledFrameSize);
-#endif
-
+        std::uint8_t* outPtr = output.get();
         int outSamples = _resampler.resample(frm->extended_data, // input
             plane_size, // input
             frm->nb_samples, // input
-            &resampledOutput); // output
-
-        // make sure to set outPtr *after* we use it as input to the resampler
-        outPtr = reinterpret_cast<std::int16_t*>(resampledOutput);
-
-#ifdef GNASH_DEBUG_AUDIO_DECODING
-        log_debug("resampler returned %d samples ", outSamples);
-#endif
-
-        if (expectedMaxOutSamples < outSamples) {
-            log_error(_(" --- Computation of resampled samples (%d) < then the 
actual returned samples (%d)"),
-                expectedMaxOutSamples, outSamples);
-
-            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", inSamples);
-
-            log_debug(" output sample rate (assuming): %d", 44100);
-            log_debug(" output channels (assuming): %d", 2);
-            log_debug(" output samples: %d", outSamples);
-
-            /// Memory errors...
-            abort();
-        }
-
-        // Use the actual number of samples returned, multiplied
-        // to get size in bytes (not two-byte samples) and for 
-        // stereo?
-        outSize = outSamples * 2 * 2;
-
-    }
-    else {
-        std::uint8_t* newOutput = new std::uint8_t[outSize];
-        std::memcpy(newOutput, outPtr, outSize);
-        outPtr = reinterpret_cast<std::int16_t*>(newOutput);
+            &outPtr);
     }
 
-    outputSize = outSize;
-    return reinterpret_cast<uint8_t*>(outPtr);
+    return output.release();
 }
 
 int

-----------------------------------------------------------------------

Summary of changes:
 libmedia/ffmpeg/AudioDecoderFfmpeg.cpp |  188 ++++++--------------------------
 libmedia/ffmpeg/MediaParserFfmpeg.cpp  |   19 ++--
 libmedia/ffmpeg/VideoDecoderFfmpeg.cpp |   35 ++----
 3 files changed, 58 insertions(+), 184 deletions(-)


hooks/post-receive
-- 
Gnash



reply via email to

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