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: Sandro Santilli
Subject: [Gnash-commit] [SCM] Gnash branch, master, updated. release_0_8_9_final-2231-g41ae739
Date: Mon, 07 Dec 2015 14:28:14 +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  41ae739439c796f7f310f813f18cc12287b2e450 (commit)
      from  eda27746fcd190fc4092e0cb1166726bebf000df (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=41ae739439c796f7f310f813f18cc12287b2e450


commit 41ae739439c796f7f310f813f18cc12287b2e450
Author: Sandro Santilli <address@hidden>
Date:   Sat Dec 5 17:14:26 2015 +0100

    Revert "Reduce malloc() churn for SWF-embedded audio."
    
    This reverts commit a9f7f743c66f2f36d81c348da238d94877473372.
    
    Conflicts:
        libsound/LiveSound.h
    
    The change resulted in a degraded audio quality as described in
    https://savannah.gnu.org/bugs/?46607

diff --git a/libbase/SimpleBuffer.h b/libbase/SimpleBuffer.h
index 2757a5e..c0a411b 100644
--- a/libbase/SimpleBuffer.h
+++ b/libbase/SimpleBuffer.h
@@ -57,17 +57,6 @@ public:
                }
        }
 
-        /// Construct a SimpleBuffer by taking ownership of an existing buffer.
-        //
-        /// @param size the size of the buffer.
-        /// @param buffer a pointer a a new[]-allocated buffer.
-        SimpleBuffer(size_t size, std::uint8_t* buffer)
-            : _size(size),
-              _capacity(size),
-              _data(buffer)
-        {
-        }
-
         /// Move constructor.
         SimpleBuffer(SimpleBuffer&&) = default;
 
diff --git a/libsound/EmbedSoundInst.cpp b/libsound/EmbedSoundInst.cpp
index dd6401b..b33dc7d 100644
--- a/libsound/EmbedSoundInst.cpp
+++ b/libsound/EmbedSoundInst.cpp
@@ -148,7 +148,7 @@ EmbedSoundInst::decodeNextBlock()
 
 
     // decodedData ownership transferred here
-    appendDecodedData(SimpleBuffer(decodedDataSize, decodedData));
+    appendDecodedData(decodedData, decodedDataSize);
 }
 
 void
diff --git a/libsound/LiveSound.cpp b/libsound/LiveSound.cpp
index 83df3ef..843d719 100644
--- a/libsound/LiveSound.cpp
+++ b/libsound/LiveSound.cpp
@@ -33,8 +33,9 @@ namespace sound {
 LiveSound::LiveSound(media::MediaHandler& mh, const media::SoundInfo& info,
         size_t inPoint)
     :
-    _samplesFetched(0),
-    _decodedBuffers(inPoint * 4)
+    _inPoint(inPoint * 4),
+    _playbackPosition(_inPoint),
+    _samplesFetched(0)
 {
     createDecoder(mh, info);
 }
@@ -58,16 +59,26 @@ LiveSound::fetchSamples(std::int16_t* to, unsigned int 
nSamples)
         unsigned int availableSamples = decodedSamplesAhead();
 
         if (availableSamples) {
-            size_t bytesCopied = _decodedBuffers.copy(
-                reinterpret_cast<std::uint8_t*>(to), nSamples * 2);
-
-            fetchedSamples += bytesCopied / 2;
+            const std::int16_t* data = getDecodedData(_playbackPosition);
 
             if (availableSamples >= nSamples) {
+                std::copy(data, data + nSamples, to);
+                fetchedSamples += nSamples;
+
+                // Update playback position (samples are 16bit)
+                _playbackPosition += nSamples * 2;
+
                 break; // fetched all
-            } else {
+            }
+            else {
                 // not enough decoded samples available:
                 // copy what we have and go on
+                std::copy(data, data + availableSamples, to);
+                fetchedSamples += availableSamples;
+
+                // Update playback position (samples are 16bit)
+                _playbackPosition += availableSamples * 2;
+
                 to += availableSamples;
                 nSamples -= availableSamples;
                 assert(nSamples);
diff --git a/libsound/LiveSound.h b/libsound/LiveSound.h
index 1463bab..82df6a5 100644
--- a/libsound/LiveSound.h
+++ b/libsound/LiveSound.h
@@ -23,7 +23,6 @@
 #include <memory>
 #include <cassert>
 #include <cstdint> // For C99 int types
-#include <iostream>
 
 #include "InputStream.h" 
 #include "AudioDecoder.h" 
@@ -40,121 +39,6 @@ namespace gnash {
 namespace gnash {
 namespace sound {
 
-
-/// Maintains a collection of SimpleBuffers, providing stateful sequential
-/// read access to the data contained therein.
-//
-// TODO: this shares some functionality with CursoredBuffer, and the two
-// classes might be merged.
-class Buffers {
-public:
-    Buffers(size_t in_point)
-    : _buffers(),
-      _index(0),
-      _pos(0),
-      _consumed(0),
-      _in_point(in_point)
-    {}
-
-    Buffers(const Buffers&) = delete;
-    Buffers& operator=(const Buffers&) = delete;
-
-    /// Append a buffer of data to be read by the consumer later.
-    void append(SimpleBuffer buf) {
-        _buffers.push_back(std::move(buf));
-        consumeInPoint();
-    }
-
-    void restart()
-    {
-        _index = 0;
-        _consumed = 0;
-        consumeInPoint();
-    }
-
-    /// Copy up to the given number of bytes to the given buffer.
-    //
-    /// @to points to a buffer to be written to.
-    /// @bytes number of bytes to be written.
-    /// @return number of bytes actually written.
-    size_t copy(std::uint8_t* to, size_t bytes) {
-        assert(_consumed >= _in_point);
-
-        size_t bytes_remaining = bytes;
-
-        for (; _index < _buffers.size(); ++_index) {
-            const SimpleBuffer& buffer = _buffers[_index];
-
-            size_t to_copy = std::min(bytes_remaining, buffer.size() - _pos);
-
-            std::copy(buffer.data() + _pos, buffer.data() + _pos + to_copy, 
to);
-            to += to_copy;
-            bytes_remaining -= to_copy;
-            _pos += to_copy;
-
-            if (_pos == buffer.size()) {
-                ++_index;
-                _pos = 0;
-                break;
-            }
-
-            if (bytes_remaining == 0) {
-                break;
-            }
-        }
-
-        size_t written = bytes - bytes_remaining;
-        _consumed += written;
-        return written;
-    }
-
-    /// @return total number of bytes contained.
-    std::uint64_t countBytes() const
-    {
-        std::uint64_t bytes = 0;
-        for (const SimpleBuffer& buffer : _buffers) {
-            bytes += buffer.size();
-        }
-        return bytes;
-    }
-
-    /// @return number of bytes previously copied by calls to copy().
-    std::uint64_t consumed() const
-    {
-        return std::max<uint64_t>(_consumed, _in_point);
-    }
-
-private:
-    void consumeInPoint() {
-        if (_consumed >= _in_point) {
-            return;
-        }
-        size_t inPoint = _in_point;
-
-        for (const SimpleBuffer& buffer : _buffers) {
-            size_t advance = std::min(inPoint, buffer.size());
-            if (advance == buffer.size()) {
-                ++_index;
-                inPoint -= advance;
-            } else {
-                _pos = advance;
-                break;
-            }
-        }
-        _consumed = _in_point;
-    }
-
-    std::vector<SimpleBuffer> _buffers;
-    /// Zero-based index of the buffer currently being indicated.
-    size_t _index;
-    /// Current position inside the current buffer.
-    size_t _pos;
-    /// Total bytes consumed by calls to copy().
-    std::uint64_t _consumed;
-    /// Number of bytes to skip from the input.
-    size_t _in_point;
-};
-
 /// Instance of a defined %sound (LiveSoundData)
 //
 /// This class contains a pointer to the LiveSoundData used for playing
@@ -173,6 +57,13 @@ protected:
     LiveSound(media::MediaHandler& mh, const media::SoundInfo& info,
             size_t inPoint);
 
+    // Pointer handling and checking functions
+    const std::int16_t* getDecodedData(unsigned long int pos) const {
+        assert(pos < _decodedData.size());
+        return reinterpret_cast<const std::int16_t*>(
+                _decodedData.data() + pos);
+    }
+
     /// Called when more decoded sound data is required.
     //
     /// This will be called whenever no more decoded data is available
@@ -186,8 +77,8 @@ protected:
 
     /// Start from the beginning again.
     void restart() {
+        _playbackPosition = _inPoint;
         _samplesFetched = 0;
-        _decodedBuffers.restart();
     }
 
     /// How many samples have been fetched since the beginning
@@ -197,27 +88,28 @@ protected:
         return _samplesFetched;
     }
 
-    std::uint64_t playbackPosition() const {
-        return _decodedBuffers.consumed();
+    size_t playbackPosition() const {
+        return _playbackPosition;
     }
 
     media::AudioDecoder& decoder() const {
         return *_decoder;
     }
 
-    void appendDecodedData(SimpleBuffer data) {
-        _decodedBuffers.append(std::move(data));
+    void appendDecodedData(std::uint8_t* data, unsigned int size) {
+        _decodedData.append(data, size);
+        delete [] data;
     }
 
     /// Return number of already-decoded samples available
     /// from playback position on
     unsigned int decodedSamplesAhead() const {
 
-        const unsigned int dds = _decodedBuffers.countBytes();
-        if (dds <= playbackPosition()) return 0;
+        const unsigned int dds = _decodedData.size();
+        if (dds <= _playbackPosition) return 0; 
 
-        size_t bytesAhead = dds - playbackPosition();
-        bytesAhead = checkEarlierEnd(bytesAhead, playbackPosition());
+        size_t bytesAhead = dds - _playbackPosition;
+        bytesAhead = checkEarlierEnd(bytesAhead, _playbackPosition);
 
         assert(!(bytesAhead % 2));
 
@@ -243,13 +135,18 @@ private:
 
     virtual bool decodingCompleted() const = 0;
 
+    const size_t _inPoint;
+
+    /// Current playback position in the decoded stream
+    size_t _playbackPosition;
+
     /// Number of samples fetched so far.
     unsigned long _samplesFetched;
 
     std::unique_ptr<media::AudioDecoder> _decoder;
 
-    /// The decoded buffers
-    Buffers _decodedBuffers;
+    /// The decoded buffer
+    SimpleBuffer _decodedData;
 
 };
 
diff --git a/libsound/StreamingSound.cpp b/libsound/StreamingSound.cpp
index 4b56f5f..1284ac5 100644
--- a/libsound/StreamingSound.cpp
+++ b/libsound/StreamingSound.cpp
@@ -99,7 +99,7 @@ StreamingSound::decodeNextBlock()
         }
 
         // decodedData ownership transferred here
-        appendDecodedData(SimpleBuffer(decodedDataSize, decodedData));
+        appendDecodedData(decodedData, decodedDataSize);
     }
 
     // Check if the entire block was consumed.

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

Summary of changes:
 libbase/SimpleBuffer.h      |   11 ---
 libsound/EmbedSoundInst.cpp |    2 +-
 libsound/LiveSound.cpp      |   25 +++++--
 libsound/LiveSound.h        |  151 +++++++------------------------------------
 libsound/StreamingSound.cpp |    2 +-
 5 files changed, 44 insertions(+), 147 deletions(-)


hooks/post-receive
-- 
Gnash



reply via email to

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