[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 Sep 30 08:12:48 CDT 2011


branch "initial_development" has been updated
       via  95eb8295f1d07626fe29c86dc6b47bcd26b9e6f4 (commit)
      from  305536948c8fdc092042fd1593aa05dd39fb8242 (commit)

Summary of changes:
 src/MatroskaUtils.cpp                 |   57 ++++++++++++++++++++++-----------
 test/UnitTest_ContainerRepository.cpp |    4 +-
 2 files changed, 40 insertions(+), 21 deletions(-)


- Log -----------------------------------------------------------------
commit 95eb8295f1d07626fe29c86dc6b47bcd26b9e6f4
Author: Brent Eagles <beagles at digium.com>
Date:   Fri Sep 30 10:41:03 2011 -0230

    Fixes:
     - duration is correct (foulness in test)
     - rewrites segment header properly
     - forces default value write of Ebml file header, bypassing some
       inadvertant madness in libmatroska to skip defaults... but the
       real values are the defaults
     - fix bug in segment calculation size
     - fix bug where track indexing was getting muffed.

diff --git a/src/MatroskaUtils.cpp b/src/MatroskaUtils.cpp
index bc6f2fe..812470a 100755
--- a/src/MatroskaUtils.cpp
+++ b/src/MatroskaUtils.cpp
@@ -79,7 +79,7 @@ void Header::writeTo(const OpaqueContainerDataPtr& data)
     uintField = dynamic_cast<EbmlUInteger*>(&docTypeReadVer);
     assert(uintField);
     *uintField = 1;
-    header.Render(*data->getIO());
+    header.Render(*data->getIO(), true);
 }
 
 class SegmentImpl;
@@ -125,6 +125,7 @@ private:
     uint64 mLastTimeCode;
     uint32 mDuration;
     uint64 mByteCount;
+    uint64 mTotalTime;
 };
 
 typedef boost::shared_ptr<TrackImpl> TrackImplPtr;
@@ -149,6 +150,7 @@ public:
     void commit(const TrackImplPtr& track);
 
 private:
+    uint64 mSegmentStart;
     KaxSegment mSegment;
     KaxSeekHead* mSeekHead;
     EbmlVoid* mIndexSpace;
@@ -228,7 +230,8 @@ TrackImpl::TrackImpl(const SegmentImplPtr& segment, KaxTrackEntry* t, unsigned c
     mGroup(0),
     mLastTimeCode(0),
     mDuration(0),
-    mByteCount(0)
+    mByteCount(0),
+    mTotalTime(0)
 {
 }
 
@@ -242,8 +245,11 @@ void TrackImpl::setCodecAndType(const CodecPtr& codec, const TrackTypePtr& track
     EbmlString* stringField = dynamic_cast<EbmlString*>(&GetChild<KaxCodecID>(*mTrack));
     assert(stringField);
     *stringField = codec->id();
-    KaxCodecPrivate& privateData = GetChild<KaxCodecPrivate>(*mTrack);
-    privateData.CopyBuffer((unsigned char*)&(codec->bytes().begin()), static_cast<uint32>(codec->bytes().size()));
+    if (codec->bytes().size() != 0)
+    {
+        KaxCodecPrivate& privateData = GetChild<KaxCodecPrivate>(*mTrack);
+        privateData.CopyBuffer((unsigned char*)&(codec->bytes().begin()), static_cast<uint32>(codec->bytes().size()));
+    }
 
     if (mTrackType->getType() == track_audio)
     {
@@ -351,6 +357,7 @@ void TrackImpl::write(uint64 timeCode, uint32 duration, const unsigned char* dat
         mGroup->SetParentTrack(*mTrack);
     }
     mByteCount += len;
+    mTotalTime += duration;
 
     KaxBlock& block = GetChild<KaxBlock>(*mGroup);
     block.SetParent(*cluster->kax());
@@ -360,12 +367,11 @@ void TrackImpl::write(uint64 timeCode, uint32 duration, const unsigned char* dat
     bool blockWantsMore = block.AddFrame(*mTrack, mLastTimeCode * mSegment->globalTimeScale(), *buf);
     cluster->increaseSize(buf->Size());
     mDuration += duration;
-    mGroup->SetBlockDuration(mDuration * mSegment->globalTimeScale());
     if (!blockWantsMore)
     {
+        mGroup->SetBlockDuration(mDuration * mSegment->globalTimeScale());
         mGroup = 0;
         mLastTimeCode = mDuration + mLastTimeCode; 
-        mSegment->addTime(mDuration);
         mDuration = 0;
     }
 
@@ -393,7 +399,7 @@ void TrackImpl::finished()
     {
         throw IncompleteException();
     }
-    mSegment->addTime(mDuration);
+    mSegment->addTime(mTotalTime);
     mSegment->commit(shared_from_this());
     cerr << "Track " << trackNumber() << " wrote " << mByteCount << " bytes" << endl;
 }
@@ -404,6 +410,7 @@ uint64 TrackImpl::getID()
 }
 
 SegmentImpl::SegmentImpl() :
+    mSegmentStart(0),
     mTimeCodeScale(1000000),
     mMaxTimePerCluster(1000),
     mPrevTime(0xFFFFFFFFFFFFFFFF),
@@ -424,6 +431,7 @@ SegmentImpl::SegmentImpl() :
 
 void SegmentImpl::addTo(const OpaqueContainerDataPtr& data)
 {
+    mSegmentStart = data->getIO()->getFilePointer();
     mContainer = data;
     mInitialSegmentSize = mSegment.WriteHead(*(data->getIO()), 5);
     //
@@ -469,8 +477,10 @@ void SegmentImpl::addTo(const OpaqueContainerDataPtr& data)
     mCues = &GetChild<KaxCues>(mSegment);
     mCues->SetGlobalTimecodeScale(mTimeCodeScale);
     mTracks->Render(*(data->getIO()));
-    mSeekHead->IndexThis(*mTracks, mSegment);
-
+    //mSeekHead->IndexThis(*mTracks, mSegment);
+    EbmlVoid moreSpace;
+    moreSpace.SetSize(1024);
+    moreSpace.Render(*(data->getIO()));
     //
     // Ok.. so I think that is it for setup .. whew!
     //
@@ -549,17 +559,19 @@ void SegmentImpl::close()
     uint64 bookmark = mContainer->getIO()->getFilePointer();
     mContainer->getIO()->setFilePointer(info.GetElementPosition());
     info.Render(*mContainer->getIO());
-    mContainer->getIO()->setFilePointer(bookmark);
 
-    if (mLeftOverSeek && mLeftOverSeek->ListSize() != 0)
-    {
-        mLeftOverSeek->Render(*mContainer->getIO());
-        if (mLeftOverSeek)
-        {
-            mSeekHead->IndexThis(*mCues, mSegment);
-        }
-    }
+    //if (mLeftOverSeek && mLeftOverSeek->ListSize() != 0)
+    //{
+    //    mLeftOverSeek->Render(*mContainer->getIO());
+    //    if (mLeftOverSeek)
+    //    {
+    //        mSeekHead->IndexThis(*mCues, mSegment);
+    //    }
+    //}
     size_t trackSize = mTracks->Render(*mContainer->getIO());
+    mSeekHead->IndexThis(*mTracks, mSegment);
+
+    mContainer->getIO()->setFilePointer(bookmark);
 
     //
     // TODO: Add tag support.
@@ -616,12 +628,19 @@ void SegmentImpl::close()
     {
         mSeekHead->IndexThis(tags, mSegment);
     }
+
+    if (mCues)
+    {
+        mCues->Render(*mContainer->getIO());
+        mSeekHead->IndexThis(*mCues, mSegment);
+    }
     if (mIndexSpace)
     {
         metaSeekSize = mIndexSpace->ReplaceWith(*mSeekHead, *mContainer->getIO());
     }
     mContainer->getIO()->setFilePointer(0, seek_end);
-    uint64 newSize = mContainer->getIO()->getFilePointer(); //  - mSegment.GetElementPosition() - mSegment.HeadSize();
+    uint64 newSize = mContainer->getIO()->getFilePointer() - mSegment.GetElementPosition() - mSegment.HeadSize();
+    mContainer->getIO()->setFilePointer(mSegmentStart);
     if (mSegment.ForceSize(newSize))
     {
         mSegment.OverwriteHead(*mContainer->getIO());
diff --git a/test/UnitTest_ContainerRepository.cpp b/test/UnitTest_ContainerRepository.cpp
index f30b2a3..ed5a31e 100644
--- a/test/UnitTest_ContainerRepository.cpp
+++ b/test/UnitTest_ContainerRepository.cpp
@@ -209,7 +209,7 @@ public:
         TrackPtr track = segment->getTrack(1);
         BOOST_REQUIRE(track);
         TrackTypePtr trackType(new AudioTrackType);
-        CodecPtr codec (new Mono16BitWav(44.1));
+        CodecPtr codec (new Mono16BitWav(44100));
         track->setCodecAndType(codec, trackType);
         track->addTag("test_tag", "some test value");
         boost::shared_ptr<pj_caching_pool> cachingPool(new pj_caching_pool);
@@ -221,7 +221,7 @@ public:
         BOOST_REQUIRE(result == PJ_SUCCESS);
         BOOST_REQUIRE(port != 0);
         pjmedia_frame frame;
-        pj_int16_t frameDataBuf[441];
+        pj_int16_t frameDataBuf[882];
         frame.buf = frameDataBuf;
         frame.size = sizeof(frameDataBuf);
         result = pjmedia_port_get_frame(port, &frame);

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


-- 
asterisk-scf/integration/file_media_service.git



More information about the asterisk-scf-commits mailing list