OggMuxStream.cpp

Go to the documentation of this file.
00001 //===========================================================================
00002 //Copyright (C) 2003, 2004 Zentaro Kavanagh
00003 //
00004 //Redistribution and use in source and binary forms, with or without
00005 //modification, are permitted provided that the following conditions
00006 //are met:
00007 //
00008 //- Redistributions of source code must retain the above copyright
00009 //  notice, this list of conditions and the following disclaimer.
00010 //
00011 //- Redistributions in binary form must reproduce the above copyright
00012 //  notice, this list of conditions and the following disclaimer in the
00013 //  documentation and/or other materials provided with the distribution.
00014 //
00015 //- Neither the name of Zentaro Kavanagh nor the names of contributors 
00016 //  may be used to endorse or promote products derived from this software 
00017 //  without specific prior written permission.
00018 //
00019 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00020 //``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00021 //LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00022 //PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ORGANISATION OR
00023 //CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00024 //EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00025 //PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00026 //PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00027 //LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00028 //NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00029 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030 //===========================================================================
00031 #include "stdafx.h"
00032 #include <libOOOgg/OggMuxStream.h>
00033 
00034 OggMuxStream::OggMuxStream(INotifyArrival* inNotifier)
00035         :       mIsEOS(false)
00036         ,       mIsActive(false)
00037         ,       mNotifier(inNotifier)
00038         ,       mIsSensibleTime(true)
00039         ,       mConvNumerator(1)
00040         ,       mConvDenominator(1)
00041         ,       mConvScaleFactor(1)
00042         ,       mConvTheoraLogKeyFrameInterval(0)
00043         ,       mNumHeaders(0)
00044         ,       mPacketsSent(0)
00045 {
00046         //debugLog.open("G:\\logs\\oggmuxstream.log", ios_base::out);
00047 }
00048 
00049 OggMuxStream::~OggMuxStream(void)
00050 {
00051         //LEAK::: Need to delete the contents of the queue later.
00052 }
00053 
00054 LOOG_INT64 OggMuxStream::granuleNumerator() {
00055         return mConvNumerator;
00056 }
00057 LOOG_INT64 OggMuxStream::granuleDenominator() {
00058         return mConvDenominator;
00059 }
00060 unsigned long OggMuxStream::numAvail() {
00061         return (unsigned long)mPageQueue.size();
00062 }
00063 bool OggMuxStream::acceptOggPage(OggPage* inOggPage) {          //Holds page for later... still needs deleting in destructor
00064 //      mIsEOS = false;
00065         if (inOggPage == NULL) {
00066                 int x = 0;
00067                 x= x/x;
00068         }
00069         if (!mIsEOS) {
00070                 mPageQueue.push_back(inOggPage);                //AOP::: Clone not required.
00071                 mNotifier->notifyArrival();
00072                 return true;
00073         } else {
00074                 delete inOggPage;
00075                 return true;
00076         }
00077 }
00078 
00079 bool OggMuxStream::pushFront(OggPage* inOggPage) {
00080         mIsEOS = false;
00081         mPageQueue.push_front(inOggPage);
00082         mNotifier->notifyArrival();
00083         return true;
00084 }
00085 
00086 OggPage* OggMuxStream::popFront() {
00087         OggPage* retPage = NULL;
00088         if (!mPageQueue.empty()) {
00089                 retPage = mPageQueue.front();
00090                 mPageQueue.pop_front();
00091                 mPacketsSent++;
00092         }
00093         return retPage;
00094 }
00095 OggPage* OggMuxStream::peekFront() {
00096         OggPage* retPage = NULL;
00097         if (!mPageQueue.empty()) {
00098                 retPage = mPageQueue.front();
00099                 
00100         }
00101         return retPage;
00102 }
00103 LOOG_INT64 OggMuxStream::frontTime() {
00104         LOOG_INT64 retTime = INT64_MAX;
00105         if (!mPageQueue.empty()) {
00106                 retTime = mPageQueue.front()->header()->GranulePos();;
00107         }
00108         return retTime;
00109 }
00110 
00111 LOOG_INT64 OggMuxStream::scaledFrontTime() {
00112 
00113         return convertTime(frontTime());
00114 }
00115 
00116 LOOG_INT64 OggMuxStream::convertTime(LOOG_INT64 inGranulePos) {
00117         LOOG_INT64 retTime = -1;
00118         if (inGranulePos != -1) {
00119                 if (mIsSensibleTime) {
00120                         retTime = (inGranulePos * mConvScaleFactor * mConvDenominator) / mConvNumerator;
00121                 } else {
00122                         //Timestamp hacks start here...
00123                         unsigned long locMod = (unsigned long)pow((double) 2, (double) mConvTheoraLogKeyFrameInterval);
00124                         
00125                         unsigned long locInterFrameNo = (unsigned long)((inGranulePos) % locMod);
00126         
00127                         LOOG_INT64 locAbsFramePos = (inGranulePos >> mConvTheoraLogKeyFrameInterval) + locInterFrameNo;
00128         
00129                         retTime = (locAbsFramePos * mConvScaleFactor * mConvDenominator) / mConvNumerator;
00130                         
00131                         
00132                 }
00133         } 
00134         return retTime;
00135                 
00136         
00137 }
00138 
00139 bool OggMuxStream::setConversionParams(LOOG_INT64 inNumerator, LOOG_INT64 inDenominator, LOOG_INT64 inScaleFactor) {
00140         mConvNumerator = inNumerator;
00141         mConvDenominator = inDenominator;
00142         mConvScaleFactor = inScaleFactor;
00143         mIsSensibleTime = true;
00144         return true;
00145 }
00146 
00147 void OggMuxStream::setNumHeaders(unsigned long inNumHeaders) {
00148         mNumHeaders = inNumHeaders;
00149 }
00150 unsigned long OggMuxStream::numHeaders() {
00151         return mNumHeaders;
00152 }
00153 
00154 unsigned long OggMuxStream::packetsSent() {
00155         return mPacketsSent;
00156 }
00157 bool OggMuxStream::sentAllHeaders() {
00158         return (mPacketsSent >= mNumHeaders);
00159 }
00160 
00161 
00162 bool OggMuxStream::setConversionParams(LOOG_INT64 inNumerator, LOOG_INT64 inDenominator, LOOG_INT64 inScaleFactor, LOOG_INT64 inTheoraLogKFI) {
00163         mConvNumerator = inNumerator;
00164         mConvDenominator = inDenominator;
00165         mConvScaleFactor = inScaleFactor;
00166         mConvTheoraLogKeyFrameInterval = inTheoraLogKFI;
00167         mIsSensibleTime = false;
00168         return true;
00169 }
00170 
00171 bool OggMuxStream::isEmpty() {
00172         return mPageQueue.empty();
00173 }
00174 bool OggMuxStream::isEOS() {
00175         return mIsEOS;
00176 }
00177 
00178 //a) All inactive streams are processable.
00179 //b) All EOS empty streams are processable.
00180 
00181 //Empty                         EOS                             Active          Processable
00182 //=========================================================
00183 // T                            T                               T                               T       -b
00184 // T                            T                               F                               T       -a
00185 // T                            F                               T                               F 
00186 // T                            F                               F                               T       -a
00187 // F                            T                               T                               T       -b
00188 // F                            T                               F                               T       -a
00189 // F                            F                               T                               T 
00190 // F                            F                               F                               T       -a
00191 
00192 bool OggMuxStream::isProcessable() {
00193         if (isEmpty() &&  !isEOS() && isActive()) {
00194                 return false;
00195         } else {
00196                 return true;
00197         }
00198 }
00199 void OggMuxStream::setIsEOS(bool inIsEOS) {
00200         mIsEOS = inIsEOS;
00201         //Notify that the streams are in new state.
00202         mNotifier->notifyArrival();
00203 }
00204 
00205 bool OggMuxStream::isActive() {
00206         return mIsActive;
00207 }
00208 void OggMuxStream::setIsActive(bool inIsActive) {
00209         mIsActive = inIsActive;
00210 }
00211 

Generated on Tue Feb 15 14:54:21 2005 for oggdsf by  doxygen 1.3.9