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                         LOOG_INT64 locMod = (LOOG_INT64)pow((double) 2, (double) mConvTheoraLogKeyFrameInterval);
00124                         LOOG_INT64 locInterFrameNo = ((inGranulePos) % locMod);
00125 
00126                         LOOG_INT64 locAbsFramePos = (inGranulePos >> mConvTheoraLogKeyFrameInterval) + locInterFrameNo;
00127         
00128                         retTime = (locAbsFramePos * mConvScaleFactor * mConvDenominator) / mConvNumerator;
00129                 }
00130         } 
00131         return retTime;
00132 }
00133 
00134 bool OggMuxStream::setConversionParams(LOOG_INT64 inNumerator, LOOG_INT64 inDenominator, LOOG_INT64 inScaleFactor) {
00135         mConvNumerator = inNumerator;
00136         mConvDenominator = inDenominator;
00137         mConvScaleFactor = inScaleFactor;
00138         mIsSensibleTime = true;
00139         return true;
00140 }
00141 
00142 void OggMuxStream::setNumHeaders(unsigned long inNumHeaders) {
00143         mNumHeaders = inNumHeaders;
00144 }
00145 unsigned long OggMuxStream::numHeaders() {
00146         return mNumHeaders;
00147 }
00148 
00149 unsigned long OggMuxStream::packetsSent() {
00150         return mPacketsSent;
00151 }
00152 bool OggMuxStream::sentAllHeaders() {
00153         return (mPacketsSent >= mNumHeaders);
00154 }
00155 
00156 
00157 bool OggMuxStream::setConversionParams(LOOG_INT64 inNumerator, LOOG_INT64 inDenominator, LOOG_INT64 inScaleFactor, LOOG_INT64 inTheoraLogKFI) {
00158         mConvNumerator = inNumerator;
00159         mConvDenominator = inDenominator;
00160         mConvScaleFactor = inScaleFactor;
00161         mConvTheoraLogKeyFrameInterval = inTheoraLogKFI;
00162         mIsSensibleTime = false;
00163         return true;
00164 }
00165 
00166 bool OggMuxStream::isEmpty() {
00167         return mPageQueue.empty();
00168 }
00169 bool OggMuxStream::isEOS() {
00170         return mIsEOS;
00171 }
00172 
00173 //a) All inactive streams are processable.
00174 //b) All EOS empty streams are processable.
00175 
00176 //Empty                         EOS                             Active          Processable
00177 //=========================================================
00178 // T                            T                               T                               T       -b
00179 // T                            T                               F                               T       -a
00180 // T                            F                               T                               F 
00181 // T                            F                               F                               T       -a
00182 // F                            T                               T                               T       -b
00183 // F                            T                               F                               T       -a
00184 // F                            F                               T                               T 
00185 // F                            F                               F                               T       -a
00186 
00187 bool OggMuxStream::isProcessable() {
00188         if (isEmpty() &&  !isEOS() && isActive()) {
00189                 return false;
00190         } else {
00191                 return true;
00192         }
00193 }
00194 void OggMuxStream::setIsEOS(bool inIsEOS) {
00195         mIsEOS = inIsEOS;
00196         //Notify that the streams are in new state.
00197         mNotifier->notifyArrival();
00198 }
00199 
00200 bool OggMuxStream::isActive() {
00201         return mIsActive;
00202 }
00203 void OggMuxStream::setIsActive(bool inIsActive) {
00204         mIsActive = inIsActive;
00205 }
00206 

Generated on Thu Feb 16 23:48:16 2006 for oggdsf by  doxygen 1.3.9