[asterisk-scf-commits] asterisk-scf/release/test_channel.git branch "fileplayback_endpoint" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Thu Dec 23 19:40:03 UTC 2010


branch "fileplayback_endpoint" has been updated
       via  a881e011306db9ce9b170cb937481be007fa6730 (commit)
      from  c47719f27b298b80c547c972716708d3654f312c (commit)

Summary of changes:
 src/FilePlaybackSessionEndpoint.cpp |   39 +++++++++++++++++++++++-----------
 1 files changed, 26 insertions(+), 13 deletions(-)


- Log -----------------------------------------------------------------
commit a881e011306db9ce9b170cb937481be007fa6730
Author: Brent Eagles <beagles at digium.com>
Date:   Thu Dec 23 16:08:06 2010 -0330

    Respond to review feedback:
    - change log level to error where indicate
    - alter wave file processing to address read size error
    - remove magic number from reading
    - replace pointer with byte sequence
    - replace get()'s with read()'s.

diff --git a/src/FilePlaybackSessionEndpoint.cpp b/src/FilePlaybackSessionEndpoint.cpp
index 56f5c82..76d9b3c 100644
--- a/src/FilePlaybackSessionEndpoint.cpp
+++ b/src/FilePlaybackSessionEndpoint.cpp
@@ -60,7 +60,7 @@ static std::string getFilename(const Ice::CommunicatorPtr& communicator, const s
     basePath /= destination;
     if (!boost::filesystem::exists(basePath))
     {
-        logger(Debug) << __FILE__ << ':' << __LINE__ << ' ' << __FUNCTION__ << 
+        logger(Error) << __FILE__ << ':' << __LINE__ << ' ' << __FUNCTION__ << 
             " non-existent file " << destination;
         throw AsteriskSCF::RemoteControl::V1::FileNotFoundException(basePath.string());
     }
@@ -288,8 +288,13 @@ public:
         // 
 
         pjmedia_wave_hdr waveHeader;
-        int rdSize = sizeof(waveHeader) -8;
-        input.get((char*)(&waveHeader), rdSize + 1);
+        const int dataHdrSize = sizeof(waveHeader.data_hdr);
+
+        //
+        // Read everything except the first data header.
+        //
+        int rdSize = sizeof(waveHeader) - dataHdrSize;
+        input.read((char*)(&waveHeader), rdSize);
         if(!input.good() || input.gcount() != rdSize)
         {
             std::cout << "header read reported: " << input.gcount() << " was supposed to have read " << rdSize << std::endl;
@@ -339,12 +344,11 @@ public:
         //
         // get to the actual audio data.
         //
-        int readSize = 8;
-        while(true)
+        while(input)
         {
             pjmedia_wave_subchunk subchunk;
-            input.get(reinterpret_cast<char*>(&subchunk), readSize +1);
-            if(input.gcount() != readSize || !input.good())
+            input.read(reinterpret_cast<char*>(&subchunk), sizeof(subchunk));
+            if(input.gcount() != dataHdrSize || !input.good())
             {
                 mLogger(Debug) << __FILE__ << ':' << __LINE__ << ' ' << __FUNCTION__ <<
                     " sorry, wave file was too short."; 
@@ -357,8 +361,7 @@ public:
                 waveHeader.data_hdr.len = subchunk.len;
                 break;
             }
-            readSize = subchunk.len;
-            input.seekg(readSize, std::ios_base::cur);
+            input.seekg(subchunk.len, std::ios_base::cur);
         }
 
         //
@@ -384,7 +387,13 @@ public:
         size_t samplesPerFrame =  20 * sampleRate / 1000;
 
         size_t bufSize = samplesPerFrame * bitsPerSample / 8;
-        std::unique_ptr<char> buf(new char[bufSize]);
+
+        //
+        // Initialize a byte sequence of size bufSize with each element
+        // assigned 0. (The default constructor for unsigned char would do this
+        // but its specified for clarity).
+        //
+        Ice::ByteSeq buf(bufSize, 0);
         mLogger(Debug) <<  __FILE__ << ':' << __LINE__ << ' ' << __FUNCTION__ <<
             "Using a buffer size of " << bufSize << " bytes.";
 
@@ -404,9 +413,9 @@ public:
             ", Data start: " << dataStart <<
             ", Sample rate: " << sampleRate;
 
-        while(true)
+        while(input)
         {
-            input.get(buf.get(), bufSize +1);
+            input.read(reinterpret_cast<char*>(&buf.front()), bufSize);
             size_t bytesRead = input.gcount();
 
             if(bytesRead == 0)
@@ -421,7 +430,11 @@ public:
             frame->mediaformat = mediaFormat;
             frame->seqno = sequence++;
             frame->timestamp = samplesPerFrame;
-            frame->payload.assign(buf.get(), buf.get()+bytesRead);
+            // 
+            // swapping will move the contents of buf into payload if possible.
+            //
+            frame->payload.swap(buf);
+            buf.resize(bufSize);
             frames.push_back(frame);
         }
         mThread->pushFrames(frames);

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


-- 
asterisk-scf/release/test_channel.git



More information about the asterisk-scf-commits mailing list