[asterisk-scf-commits] asterisk-scf/integration/file_media_service.git branch "initial_development" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Fri Oct 7 11:29:44 CDT 2011


branch "initial_development" has been updated
       via  6c709564f50f467984ba65bac6b1568e48246426 (commit)
      from  0d32acb0c24b52ff4b8d0a0a85a2647ed73d0e34 (commit)

Summary of changes:
 .../FileMediaService/ContainerFileIf.ice           |   35 +--
 src/CMakeLists.txt                                 |   16 +-
 src/ContainerImpl.cpp                              |  331 +++++++++++++++++++-
 src/ContainerImpl.h                                |    1 +
 src/ContainerRepository.cpp                        |   12 +-
 src/MatroskaCodec.cpp                              |    6 +-
 src/MatroskaUtils.cpp                              |   86 +++++-
 src/MatroskaUtils.h                                |   26 +-
 src/StreamImpl.cpp                                 |   86 +-----
 src/StreamImpl.h                                   |   29 +-
 test/UnitTest_ContainerRepository.cpp              |   19 +-
 11 files changed, 464 insertions(+), 183 deletions(-)


- Log -----------------------------------------------------------------
commit 6c709564f50f467984ba65bac6b1568e48246426
Author: Brent Eagles <beagles at digium.com>
Date:   Fri Oct 7 13:59:07 2011 -0230

    Some cleanups.. working out support for playback thread.

diff --git a/slice/AsteriskSCF/FileMediaService/ContainerFileIf.ice b/slice/AsteriskSCF/FileMediaService/ContainerFileIf.ice
index 10a6ad1..555b38c 100644
--- a/slice/AsteriskSCF/FileMediaService/ContainerFileIf.ice
+++ b/slice/AsteriskSCF/FileMediaService/ContainerFileIf.ice
@@ -64,42 +64,11 @@ unsliceable class ContainerInfo
 
 sequence<ContainerInfo> ContainerInfoSeq;
 
-unsliceable class StreamInfo
-{
-    string name;
-    /**
-     * We will need to do some kind of format identification even here.
-     **/
-};
-sequence<StreamInfo> StreamInfoSeq;
-
-interface Stream
-{
-    Ice::ByteSeq read(long readCount);
-
-    /**
-     * Note: the typical write API has a value for the number of bytes to write, but
-     * a.) the amount of available bytes is available from the native sequence type
-     * b.) including data in the argument that you do not want written is unwise 
-     **/
-    void write(Ice::ByteSeq data);
-
-    /**
-     * Destroy this stream object.
-     **/
-    void destroy();
-
-    StreamInfo getInfo();
-};
-sequence<Stream> StreamSeq;
-
 interface Container
 {
     ContainerInfo getInfo();
-    StreamInfoSeq getStreamInfo(); 
-
-    Stream* createStream(string id);
-    StreamSeq createAllStreams(); 
+    
+    AsteriskSCF::Media::File::V1::FileSession* getMediaSession();
 };
 
 exception ContainerNotExist
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d1fcd97..31c04cc 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -17,18 +17,18 @@ astscf_component_add_files(FileMediaService
 	ContainerRepository.h
 	FileMediaServiceComponent.cpp
 	FileMediaServiceComponent.h
-        ContainerImpl.cpp
-        ContainerImpl.h
-        OpaqueContainerData.h
+    ContainerImpl.cpp
+    ContainerImpl.h
+    OpaqueContainerData.h
 	LoggerF.h
 	ReplicationListener.h
 	RepositoryConfigurationAdapter.h
 	RepositoryReplicationAdapter.h
-        MatroskaDefines.h
-        MatroskaCodec.h
-        MatroskaCodec.cpp
-        MatroskaUtils.h
-        MatroskaUtils.cpp
+    MatroskaDefines.h
+    MatroskaCodec.h
+    MatroskaCodec.cpp
+    MatroskaUtils.h
+    MatroskaUtils.cpp
 )
 
 astscf_component_add_ice_libraries(FileMediaService IceStorm)
diff --git a/src/ContainerImpl.cpp b/src/ContainerImpl.cpp
index c0d6650..3e04d05 100644
--- a/src/ContainerImpl.cpp
+++ b/src/ContainerImpl.cpp
@@ -36,6 +36,8 @@ using namespace libmatroska;
 using namespace libebml;
 using namespace AsteriskSCF::MatroskaContainer::Implementation;
 using namespace AsteriskSCF::FileMediaService::MediaContainer::V1;
+using namespace AsteriskSCF::Media::File::V1;
+using namespace AsteriskSCF::Media::V1;
 using namespace AsteriskSCF::System::Logging;
 using namespace std;
 
@@ -123,11 +125,313 @@ private:
     
 };
 
+class CookieManager
+{
+public:
+    CookieManager()
+    {
+    }
+
+    void setCookies(const SessionCookies& cookies)
+    {
+        UniqueLock lock(mLock);
+        for (SessionCookies::const_iterator lookingFor = cookies.begin(); 
+            lookingFor != cookies.end(); ++lookingFor)
+        {
+            for (SessionCookies::iterator myCookie = mCookies.begin(); 
+                myCookie != mCookies.end(); ++myCookie)
+            {
+                if ((*lookingFor)->ice_id() == (*myCookie)->ice_id())
+                {
+                    *myCookie = *lookingFor;
+                    break;
+                }
+            }
+        }
+    }
+
+    void removeCookies(const SessionCookies& cookies)
+    {
+        UniqueLock lock(mLock);
+        for (SessionCookies::const_iterator lookingFor = cookies.begin(); 
+            lookingFor != cookies.end(); ++lookingFor)
+        {
+            for (SessionCookies::iterator myCookie = mCookies.begin(); myCookie != mCookies.end(); ++myCookie)
+            {
+                if ((*lookingFor)->ice_id() == (*myCookie)->ice_id())
+                {
+                    mCookies.erase(myCookie);
+                    break;
+                }
+            }
+        }
+    }
+
+    SessionCookies getCookies(const SessionCookies& cookies)
+    {
+        SharedLock lock(mLock);
+        SessionCookies results;
+        for (SessionCookies::const_iterator lookingFor = cookies.begin(); 
+            lookingFor != cookies.end(); ++lookingFor)
+        {
+            for (SessionCookies::const_iterator myCookie = mCookies.begin(); myCookie != mCookies.end(); ++myCookie)
+            {
+                if ((*lookingFor)->ice_id() == (*myCookie)->ice_id())
+                {
+                    results.push_back(*myCookie);
+                }
+            }
+        }
+        return results;
+    }
+
+private:
+    boost::shared_mutex mLock;
+    typedef boost::shared_lock<boost::shared_mutex> SharedLock;
+    typedef boost::unique_lock<boost::shared_mutex> UniqueLock;
+
+    SessionCookies mCookies;
+};
+
+class PlaybackSessionImpl : public AsteriskSCF::Media::File::V1::FileSession
+{
+public:
+
+    class TrackPlayer : public AsteriskSCF::Media::V1::StreamSource
+    {
+    public:
+        TrackPlayer(const string& id, const TrackReaderPtr& reader) :
+            mId(id),
+            mReader(reader),
+            mLastRealTime(IceUtil::Time::now())
+        {
+            mLastTimecode = reader->getStartTimecode();
+        }
+
+        void addSink(const StreamSinkPrx& sink, const Ice::Current& current)
+        {
+            UniqueLock lock(mLock);
+            string newSinkId = current.adapter->getCommunicator()->identityToString(sink->ice_getIdentity());
+            if (mSinks.find(newSinkId) != mSinks.end())
+            {
+                //
+                // Probably should indicated that a sink is being updated.
+                //
+            }
+            mSinks[newSinkId] = sink;
+        }
+
+        StreamSinkSeq getSinks(const Ice::Current&)
+        {
+            SharedLock lock(mLock);
+            return getSinksImpl();
+        }
+
+        FormatSeq getFormats(const Ice::Current&)
+        {
+            return FormatSeq(); // XXX ooo
+        }
+
+        string getId(const Ice::Current&)
+        {
+            return mId;
+        }
+
+        void requestFormat(const FormatPtr&, const Ice::Current&)
+        {
+            //
+            // You get what you got!
+            // 
+            throw MediaFormatSwitchException();
+        }
+
+        void doWork()
+        {
+            SharedLock lock(mLock);
+            //
+            // Pull data out from track.
+            //
+            FrameSeq frames;
+            IceUtil::Time advance = IceUtil::Time::now() - mLastRealTime;
+            mLastRealTime = IceUtil::Time::now();
+            uint64 nextTimecode = mLastTimecode + advance.toMilliSeconds();
+
+            //
+            // Get the frames from the last time to now, it's relative because
+            //
+            mReader->getFrames(frames, mLastTimecode, nextTimecode);
+
+            //
+            // XXX convert frames.. 
+            //
+            AsteriskSCF::Media::V1::FrameSeq ascfFrames;
+
+            for (SinkMap::const_iterator iter = mSinks.begin(); iter != mSinks.end() ; ++iter)
+            {
+                try
+                {
+                    //
+                    // Dispatch model?
+                    //
+                    iter->second->write(ascfFrames);
+                }
+                catch (const std::exception&x)
+                {
+                    //
+                    //  XXX do something.
+                    // 
+                }
+            }
+            mLastTimecode = nextTimecode;
+        }
+
+    private:
+        boost::shared_mutex mLock;
+        typedef boost::shared_lock<boost::shared_mutex> SharedLock;
+        typedef boost::unique_lock<boost::shared_mutex> UniqueLock;
+
+        typedef map<string, StreamSinkPrx> SinkMap;
+
+        SinkMap mSinks;
+
+        string mId;
+        TrackReaderPtr mReader;
+        uint64 mLastTimecode;
+        IceUtil::Time mLastRealTime;
+
+        StreamSinkSeq getSinksImpl()
+        {
+            StreamSinkSeq results;
+            for (SinkMap::const_iterator iter = mSinks.begin(); iter != mSinks.end(); ++iter)
+            {
+                results.push_back(iter->second);
+            }
+            return results;
+        }
+    };
+
+    PlaybackSessionImpl(const Ice::ObjectAdapterPtr& adapter, const ContainerReaderPtr& reader, const string& id,
+        const FileMediaSpecification& spec) :
+        mObjectAdapter(adapter),
+        mReader(reader),
+        mId(id),
+        mSpec(spec)
+    {
+        //
+        // Nothing to do here yet.
+        //
+    }
+
+    StreamSourceSeq getSources(const Ice::Current&)
+    {
+        return StreamSourceSeq();
+    }
+
+    StreamSinkSeq getSinks(const Ice::Current&)
+    {
+        return StreamSinkSeq();
+    }
+
+    string getId(const Ice::Current&)
+    {
+        return mId;
+    }
+
+    void setCookies(const SessionCookies& cookies, const Ice::Current&)
+    {
+        mCookieManager.setCookies(cookies);
+    }
+
+    void removeCookies(const SessionCookies& cookies, const Ice::Current&)
+    {
+        mCookieManager.removeCookies(cookies);
+    }
+
+    void getCookies_async(
+          const ::AsteriskSCF::Media::V1::AMD_Session_getCookiesPtr& cb,
+          const AsteriskSCF::Media::V1::SessionCookies& cookiesToGet,
+          const Ice::Current&)
+    {
+        try
+        {
+            cb->ice_response(mCookieManager.getCookies(cookiesToGet));
+        }
+        catch (const Ice::Exception& ex)
+        {
+            cb->ice_exception(ex);
+        }
+        catch (...)
+        {
+            cb->ice_exception();
+        }
+    }
+
+    FileMediaSpecification getInfo(const Ice::Current&)
+    {
+        return mSpec;
+    }
+
+    void start(const Ice::Current&)
+    {
+    }
+
+    void pause(const Ice::Current&)
+    {
+    }
+
+    void unpause(const Ice::Current&)
+    {
+    }
+
+    void restart(const Ice::Current&)
+    {
+        //
+        // TODO: this is trickier to implement than I thought!
+        //
+    }
+
+    void release(const Ice::Current& current)
+    {
+        mReader.reset();
+
+        Ice::Identity myAlleged = current.id;
+        try
+        {
+            mObjectAdapter->remove(myAlleged);
+        }
+        catch (const Ice::Exception&)
+        {
+        }
+    }
+
+private:
+    Ice::ObjectAdapterPtr mObjectAdapter;
+    ContainerReaderPtr mReader;
+    const string mId;
+    FileMediaSpecification mSpec;
+    CookieManager mCookieManager;
+};
+
+class RecordingSessionImpl : public AsteriskSCF::Media::File::V1::FileSession
+{
+public:
+    RecordingSessionImpl(const Ice::ObjectAdapterPtr& adapter, const ContainerWriterPtr& writer) :
+        mObjectAdapter(adapter),
+        mWriter(writer)
+    {
+
+    }
+private:
+    Ice::ObjectAdapterPtr mObjectAdapter;
+    ContainerWriterPtr mWriter;
+};
+
 class ContainerServant : public ContainerImpl
 {
 public:
-    ContainerServant(const ContainerInfoImplPtr& info, const Logger& logger) :
+    ContainerServant(const ContainerInfoImplPtr& info, const Ice::ObjectAdapterPtr& adapter, const Logger& logger) :
        mInfo(info),
+       mAdapter(adapter),
        mLogger(logger)
     {
     }
@@ -166,19 +470,17 @@ public:
         return getInfoImpl();
     }
 
-    StreamInfoSeq getStreamInfo(const Ice::Current&)
+    AsteriskSCF::Media::File::V1::FileSessionPrx getMediaSession(const Ice::Current&)
     {
-        return StreamInfoSeq();
-    }
+        if (mInfo->supportedOperations == AsteriskSCF::Media::File::V1::Playback)
+        {
 
-    StreamPrx createStream(const string& id, const Ice::Current&)
-    {
-        return 0;
-    }
+        }
+        else if(mInfo->supportedOperations == AsteriskSCF::Media::File::V1::Recording)
+        {
 
-    StreamSeq createAllStreams(const Ice::Current&)
-    {
-        return StreamSeq();
+        }
+        return 0;
     }
 
 private:
@@ -191,13 +493,11 @@ private:
     typedef boost::unique_lock<boost::shared_mutex> UniqueLock;
 
     ContainerInfoImplPtr mInfo;
+    Ice::ObjectAdapterPtr mAdapter;
     Logger mLogger;
 
-    StreamInfoSeq mStreamInfo;
     ContainerDataImplPtr mMatroskaData;
 
-    StreamImplSeq mStreams;
-
     ContainerInfoImplPtr getInfoImpl()
     {
         SharedLock lock(mLock);
@@ -265,9 +565,10 @@ typedef IceUtil::Handle<ContainerServant> ContainerServantPtr;
 
 ContainerImplPtr
 ContainerImpl::create(const ContainerInfoImplPtr& info,
+    const Ice::ObjectAdapterPtr& adapter,
     const AsteriskSCF::System::Logging::Logger& logger)
 {
-    return new ContainerServant(info, logger);
+    return new ContainerServant(info, adapter, logger);
 }
 
 
diff --git a/src/ContainerImpl.h b/src/ContainerImpl.h
index 77dd459..33aa8b0 100644
--- a/src/ContainerImpl.h
+++ b/src/ContainerImpl.h
@@ -36,6 +36,7 @@ public:
 
     static IceUtil::Handle<ContainerImpl> create(
         const ContainerInfoImplPtr& info,
+        const Ice::ObjectAdapterPtr& adapter,
         const AsteriskSCF::System::Logging::Logger& logger);
 };
 typedef IceUtil::Handle<ContainerImpl>  ContainerImplPtr;
diff --git a/src/ContainerRepository.cpp b/src/ContainerRepository.cpp
index 8d7a3ba..56f6748 100644
--- a/src/ContainerRepository.cpp
+++ b/src/ContainerRepository.cpp
@@ -348,12 +348,16 @@ ContainerConfigurationAdapterPtr ConfigurationAdapterImpl::addContainer(const st
     AsteriskSCF::Media::File::V1::FileOperations supportedOperations)
 {
     ContainerInfoImplPtr newInfo(new ContainerInfoImpl);
-    return 0;
+    newInfo->id = id;
+    newInfo->filename = uri;
+    newInfo->supportedOperations = supportedOperations;
+
+    return ContainerConfigurationAdapterPtr();
 }
 
 ContainerConfigurationAdapterPtr ConfigurationAdapterImpl::getContainer(const string&)
 {
-    return 0;
+    return ContainerConfigurationAdapterPtr();
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -453,7 +457,7 @@ ContainerPrx ContainerRepositoryServant::getContainer(const string& containerId,
     //
     // If we got this far, we need to create a new servant, activate it and move on!
     //
-    ContainerImplPtr newContainer(ContainerImpl::create(containerInfo, mLogger));
+    ContainerImplPtr newContainer(ContainerImpl::create(containerInfo, mAdapter, mLogger));
     return ContainerPrx::uncheckedCast(mAdapter->add(newContainer, id));
 }
 
@@ -510,7 +514,7 @@ void ContainerRepositoryServant::refresh()
                  containerInfo != mContainerInfoList.end(); ++containerInfo)
             {
                 bool found = false;
-                for (vector<boost::filesystem::path>::const_iterator filename = dirList.begin(); filename != dirList.end();
+                for (vector<boost::filesystem::path>::iterator filename = dirList.begin(); filename != dirList.end();
                      ++filename)
                 {
                     
diff --git a/src/MatroskaCodec.cpp b/src/MatroskaCodec.cpp
index fdfcd88..e80e9c6 100755
--- a/src/MatroskaCodec.cpp
+++ b/src/MatroskaCodec.cpp
@@ -19,12 +19,12 @@
 using namespace AsteriskSCF::MatroskaContainer::Implementation;
 
 
-CodecPtr MatroskaCodecTranslator::create(const AsteriskSCF::Media::V1::FormatPtr& format)
+CodecPtr MatroskaCodecTranslator::create(const AsteriskSCF::Media::V1::FormatPtr&)
 {
     return CodecPtr();
 }
 
-AsteriskSCF::Media::V1::FormatPtr create(const CodecPtr& codec)
+AsteriskSCF::Media::V1::FormatPtr create(const CodecPtr&)
 {
     return AsteriskSCF::Media::V1::FormatPtr();
-}
\ No newline at end of file
+}
diff --git a/src/MatroskaUtils.cpp b/src/MatroskaUtils.cpp
index 148c5c3..f548d56 100755
--- a/src/MatroskaUtils.cpp
+++ b/src/MatroskaUtils.cpp
@@ -14,8 +14,14 @@
  * at the top of the source tree.
  */
 
-// boost does something here that VC++ complains loudly and annoyingly about
-#pragma warning(disable: 4996)  
+//
+// boost does something here that VC++ complains loudly and annoyingly about.
+// Unfortunately GCC complains about the pragma and warnings-as-errors busts
+// compilation.
+//
+#ifdef WIN32
+#pragma warning(disable: 4996)
+#endif
 
 #include "MatroskaUtils.h"
 
@@ -48,6 +54,10 @@
 #include <boost/thread/locks.hpp>
 #include <boost/thread/shared_mutex.hpp>
 
+//
+// TODO: TimeCode or Timecode.. pick one.
+//
+
 using namespace libebml;
 using namespace libmatroska;
 using namespace std;
@@ -220,6 +230,7 @@ public:
     TrackingDataBuf(const BlockAccessTrackers& trackers);
 
     size_t fillFrames(FrameSeq& frames, size_t frameCount);
+    void getAllFrames(FrameSeq& frames);
 
     //
     // Shouldn't be used by anybody.. more for testing than anything
@@ -303,6 +314,14 @@ public:
     void reset();
 
     void getFrames(FrameSeq& frames, size_t requestedNumberOfFrames);
+
+    void getFrames(FrameSeq& frames, uint64 fromTime, uint64 untilTime);
+
+    uint64 getStartTimecode();
+
+    CodecPtr getCodec();
+
+    TrackTypePtr getType();
     
 private:
     ContainerReaderImplPtr mContainer;
@@ -461,6 +480,20 @@ size_t TrackingDataBuf::fillFrames(FrameSeq& frames, size_t frameCount)
     return framesFilled;
 }
 
+void TrackingDataBuf::getAllFrames(FrameSeq& frames)
+{
+    for (BlockAccessTrackers::iterator iter = mTrackers.begin(); iter != mTrackers.end(); ++iter)
+    {
+        KaxInternalBlock& current = (KaxInternalBlock&)(*(*mCurrentTracker)->blockGroup());
+        
+        for (unsigned long currentBuf = 0; currentBuf < current.NumberFrames(); ++currentBuf)
+        {
+            DataBuffer& buf = current.GetBuffer(static_cast<unsigned int>(currentBuf));
+            frames.push_back(FramePtr(new DataToFrameAdapter(buf)));
+        }
+    }
+}
+
 ////////////////////////////////////////////////////////////////////////////////////////////
 // TrackData implementation.
 //
@@ -495,7 +528,8 @@ void TrackData::addBlock(KaxBlockGroup* block)
                 //
                 // This is actually safe because the "tack on" the last block case is handled.
                 //
-                mBlocks.insert(i + 1, new BlockAccessTracker(block));
+                ++i;
+                mBlocks.insert(i, BlockAccessTrackerPtr(new BlockAccessTracker(block)));
                 break;
             }
         }
@@ -722,7 +756,8 @@ void Writer::setCodecAndType(const CodecPtr& codec, const TrackTypePtr& trackTyp
     if (codec->privateBytes().size() != 0)
     {
         KaxCodecPrivate& privateData = GetChild<KaxCodecPrivate>(*mTrack);
-        privateData.CopyBuffer((unsigned char*)&(codec->privateBytes().begin()), static_cast<uint32>(codec->privateBytes().size()));
+        vector<unsigned char> codecsData = codec->privateBytes();
+        privateData.CopyBuffer(static_cast<unsigned char*>(&codecsData[0]), static_cast<uint32>(codecsData.size()));
     }
 
     if (mTrackType->getType() == track_audio)
@@ -987,6 +1022,41 @@ void Reader::getFrames(FrameSeq& frames, size_t requestedNumberOfFrames)
     }
 }
 
+void Reader::getFrames(FrameSeq& frames, uint64 fromTime, uint64 untilTime)
+{
+    TrackingDataBufPtr data = mTrackData->getFromUntil(fromTime * mTrack->GlobalTimecodeScale(), 
+        untilTime * mTrack->GlobalTimecodeScale());
+    data->getAllFrames(frames);
+}
+
+uint64 Reader::getStartTimecode() 
+{
+    return mTrackData->getStartTimeCode();
+}
+
+CodecPtr Reader::getCodec()
+{
+    //
+    // XXX translate track codec info to our codec objectsj
+    // 
+    return CodecPtr();
+}
+
+TrackTypePtr Reader::getType()
+{
+    EbmlUInteger* uintField = dynamic_cast<EbmlUInteger*>(&GetChild<KaxTrackType>(*mTrack));
+    assert(uintField);
+    if ((uint16)(*uintField) == track_audio)
+    {
+        return TrackTypePtr(new AudioTrackType);
+    }
+    else if ((uint16)(*uintField) == track_video)
+    {
+        return TrackTypePtr(new VideoTrackType);
+    }
+    return TrackTypePtr();
+}
+
 ////////////////////////////////////////////////////////////////////////////////////////////
 // ContainerImplBase implementation.
 //
@@ -1213,7 +1283,7 @@ void ContainerWriterImpl::close()
     KaxDuration& duration = GetChild<KaxDuration>(info);
     EbmlFloat* floatField = dynamic_cast<EbmlFloat*>(&duration);
     assert(floatField);
-    *floatField = (mLastTime * 1.0);
+    *floatField = static_cast<double>(mLastTime);
     info.UpdateSize();
     uint64 bookmark = mContainer->getIO()->getFilePointer();
     mContainer->getIO()->setFilePointer(info.GetElementPosition());
@@ -1222,7 +1292,7 @@ void ContainerWriterImpl::close()
     //
     // As I recall the tracks were right after info, so we can write them now too..
     //
-    size_t trackSize = mTracks->Render(*mContainer->getIO());
+    mTracks->Render(*mContainer->getIO());
     mSeekHead->IndexThis(*mTracks, *mSegment);
 
     // 
@@ -1400,8 +1470,8 @@ TrackReaderSeq ContainerReaderImpl::getTracks()
         {
             t->ReadData(*mContainer->getIO(), SCOPE_ALL_DATA);
         }
-        result.push_back(TrackReaderPtr(new Reader(shared_from_this(), t, trackNumber, 
-            mTrackPool->getTrackData(trackNumber))));
+        result.push_back(TrackReaderPtr(new Reader(shared_from_this(), t, trackNo(trackNumber),
+            mTrackPool->getTrackData(trackNo(trackNumber)))));
     }
     return result;
 }
diff --git a/src/MatroskaUtils.h b/src/MatroskaUtils.h
index e4f5d7e..820b173 100755
--- a/src/MatroskaUtils.h
+++ b/src/MatroskaUtils.h
@@ -20,6 +20,7 @@
 #include <boost/shared_ptr.hpp>
 #include <vector>
 #include <string>
+#include <stdexcept>
 
 #include "MatroskaCodec.h"
 
@@ -93,8 +94,8 @@ public:
 protected:
     unsigned char mTrackNumber;
 
-    TrackBase(unsigned char trackNumber) :
-         mTrackNumber(trackNumber)
+    TrackBase(unsigned char trackNo) :
+         mTrackNumber(trackNo)
     {
     }
 };
@@ -127,22 +128,17 @@ public:
     virtual void finished() = 0;
 
 protected:
-    TrackWriter(unsigned char trackNumber) :
-         TrackBase(trackNumber) {}
+    TrackWriter(unsigned char trackNum) :
+         TrackBase(trackNum) {}
 };
 typedef boost::shared_ptr<TrackWriter> TrackWriterPtr;
 
 class Frame
 {
 public:
-
     std::vector<unsigned char>& data() const;
-    uint64 start();
-    uint64 duration();
 
 protected:
-    uint64 mStart;
-    uint64 mEnd;
     std::vector<unsigned char> mData;
 };
 typedef boost::shared_ptr<Frame> FramePtr;
@@ -161,6 +157,14 @@ public:
 
     virtual void getFrames(FrameSeq& frames, size_t requestedNumberOfFrames) = 0;
 
+    virtual void getFrames(FrameSeq& frames, uint64 fromTime, uint64 untilTime) = 0;
+
+    virtual uint64 getStartTimecode() = 0;
+
+    virtual CodecPtr getCodec() = 0;
+
+    virtual TrackTypePtr getType() = 0;
+
     /**
      * Note the absence of a close method. This is because a track reader only provides
      * a view on data that is read or in the process of being read. The resources
@@ -171,8 +175,8 @@ public:
      */
 
 protected:
-    TrackReader(unsigned char trackNumber) :
-         TrackBase(trackNumber)
+    TrackReader(unsigned char trackNum) :
+         TrackBase(trackNum)
     {
     }
 };
diff --git a/src/StreamImpl.cpp b/src/StreamImpl.cpp
index 7f9de2f..d7ca7d4 100644
--- a/src/StreamImpl.cpp
+++ b/src/StreamImpl.cpp
@@ -15,6 +15,7 @@
  */
 
 #include "StreamImpl.h"
+#include <AsteriskSCF/FileMediaService/ContainerFileIf.h>
 #include <AsteriskSCF/logger.h>
 #include <matroska/FileKax.h>
 #include <matroska/KaxSegment.h>
@@ -32,92 +33,11 @@ namespace MatroskaContainer
 namespace Implementation
 {
 
-class MatroskaStreamWriter : public IceUtil::Shared
+StreamSinkImpl::StreamSinkImpl(const TrackWriterPtr& writer) :
+    mWriter(writer)
 {
-public:
-    MatroskaStreamWriter(const OpaqueContainerDataPtr& data) :
-      mMatroskaData(data)
-    {
-    }
-
-private:
-    KaxSegment mFileSegment;
-    OpaqueContainerDataPtr mMatroskaData;
-};
-
-typedef IceUtil::Handle<MatroskaStreamWriter> MatroskaStreamWriterPtr;
-
-class MatroskaStreamReader : public IceUtil::Shared
-{
-public:
-    MatroskaStreamReader(const OpaqueContainerDataPtr& data) :
-      mMatroskaData(data)
-    {
-    }
-
-private:
-    KaxSegment mFileSegment;
-    OpaqueContainerDataPtr mMatroskaData;
-};
-class StreamServant : public StreamImpl
-{
-public:
-    StreamServant(const OpaqueContainerDataPtr& data, const string& id, const Logger& logger,
-        AsteriskSCF::Media::File::V1::FileOperations supportedOperations) :
-        mData(data),
-        mId(id),
-        mLogger(logger),
-        mOps(supportedOperations)
-    {
-        //
-        // We don't support both operations on a particular stream.. it needs to be
-        // either write or read.
-        //
-        assert(supportedOperations != AsteriskSCF::Media::File::V1::Both);
-    }
-
-    Ice::ByteSeq read(Ice::Long, const Ice::Current&)
-    {
-        return Ice::ByteSeq();
-    }
-
-    void write(const Ice::ByteSeq&, const Ice::Current&)
-    {
-    }
-
-    void destroy(const Ice::Current&)
-    {
-    }
-
-    StreamInfoPtr getInfo(const Ice::Current&)
-    {
-        return 0;
-    }
-
-    void flush()
-    {
-    }
-    
-private:
-    OpaqueContainerDataPtr mData;
-    string mId;
-    Logger mLogger;
-    AsteriskSCF::Media::File::V1::FileOperations mOps;
-};
-typedef IceUtil::Handle<StreamServant>  StreamServantPtr;
-
-
-IceUtil::Handle<AsteriskSCF::MatroskaContainer::Implementation::StreamImpl>
-StreamImpl::create(const OpaqueContainerDataPtr& data, const string& id, const Logger& logger,
-    AsteriskSCF::Media::File::V1::FileOperations supportedOperations)
-{
-    //
-    // TODO: Find the container itself so it can be opened.
-    //
-    return new StreamServant(data, id, logger, supportedOperations);
 }
 
-
 } /* End of namespace Implementation */
 } /* End of namespace MatroskaContainer */
 } /* End of namespace AsteriskSCF */
diff --git a/src/StreamImpl.h b/src/StreamImpl.h
index 693d760..870a628 100644
--- a/src/StreamImpl.h
+++ b/src/StreamImpl.h
@@ -16,9 +16,11 @@
 
 #pragma once
 
-#include <AsteriskSCF/FileMediaService/ContainerFileIf.h>
 #include "OpaqueContainerData.h"
 #include "LoggerF.h"
+#include "MatroskaUtils.h"
+
+#include <AsteriskSCF/Media/MediaIf.h>
 #include <vector>
 
 namespace AsteriskSCF
@@ -27,21 +29,24 @@ namespace MatroskaContainer
 {
 namespace Implementation
 {
-class StreamImpl : public AsteriskSCF::FileMediaService::MediaContainer::V1::Stream
+
+class StreamSinkImpl : public AsteriskSCF::Media::V1::StreamSink
 {
 public:
+    StreamSinkImpl(const TrackWriterPtr& writer);
+private:
+    TrackWriterPtr mWriter;
+};
+typedef IceUtil::Handle<StreamSinkImpl> StreamSinkImplPtr;
 
-    /**
-     * Causes the stream to flush any buffers stored for writing.
-     */
-    virtual void flush() = 0;
-
-    static IceUtil::Handle<StreamImpl> create(const OpaqueContainerDataPtr& data, const std::string& id, 
-        const AsteriskSCF::System::Logging::Logger& logger,
-        AsteriskSCF::Media::File::V1::FileOperations supportedOperations);
+class StreamSourceImpl : public AsteriskSCF::Media::V1::StreamSource
+{
+public:
+    StreamSourceImpl(const TrackReaderPtr& reader);
+private:
+    TrackReaderPtr mReader;
 };
-typedef IceUtil::Handle<StreamImpl>  StreamImplPtr;
-typedef std::vector<StreamImplPtr> StreamImplSeq;
+typedef IceUtil::Handle<StreamSourceImpl> StreamSourceImplPtr;
 
 } /* End of namespace Implementation */
 } /* End of namespace MatroskaContainer */
diff --git a/test/UnitTest_ContainerRepository.cpp b/test/UnitTest_ContainerRepository.cpp
index 356a900..d3dce41 100644
--- a/test/UnitTest_ContainerRepository.cpp
+++ b/test/UnitTest_ContainerRepository.cpp
@@ -16,7 +16,10 @@
 
 
 // boost does something here that VC++ complains loudly and annoyingly about
-#pragma warning(disable: 4996)  
+
+#ifdef WIN32
+#pragma warning(disable: 4996)
+#endif
 
 #define BOOST_TEST_NO_MAIN
 
@@ -35,13 +38,17 @@
 #include "../src/OpaqueContainerData.h"
 #include "../src/ContainerRepository.cpp"
 
+#ifdef WIN32
 #pragma warning(push)
 #pragma warning(disable: 4244 4267)
+#endif
 
 #include <pjmedia.h>
 #include <pjlib.h>
 
+#ifdef WIN32
 #pragma warning(pop)
+#endif
 
 using namespace AsteriskSCF::MatroskaContainer::Implementation;
 using namespace AsteriskSCF::MatroskaContainer::Implementation::Internal;
@@ -124,7 +131,7 @@ public:
         {
             ContainerRepositoryServantPtr testImpl(new ContainerRepositoryServant(mObjectAdapter, "TestRepository", mLogger));
             BOOST_REQUIRE(testImpl != 0);
-            ContainerRepositoryPrx repository = ContainerRepositoryPrx::uncheckedCast(
+            repository = ContainerRepositoryPrx::uncheckedCast(
                 mObjectAdapter->addWithUUID(testImpl));
             BOOST_REQUIRE(repository != 0);
 
@@ -135,7 +142,7 @@ public:
         }
         catch (...)
         {
-            mLogger(Error) << "Unexception occurred in test.";
+            mLogger(Error) << "Unknown exception occurred in test.";
         }
         if (repository)
         {
@@ -185,7 +192,7 @@ public:
         }
         catch (...)
         {
-            mLogger(Error) << "Unexception occurred in test.";
+            mLogger(Error) << "Unknown exception occurred in test.";
         }
 
         if (repository)
@@ -252,7 +259,7 @@ public:
         frame.size = sizeof(frameDataBuf);
         result = pjmedia_port_get_frame(port, &frame);
         uint64 totalTime = 0;
-        assert(frame.type == PJMEDIA_TYPE_AUDIO);
+        assert(frame.type == PJMEDIA_FRAME_TYPE_AUDIO);
         uint64 totalBytes = 0;
         try
         {
@@ -430,4 +437,4 @@ int main(int argc, char** argv)
     }
     matroska_done();
     return EXIT_SUCCESS;
-}
\ No newline at end of file
+}

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


-- 
asterisk-scf/integration/file_media_service.git



More information about the asterisk-scf-commits mailing list