liveMedia/FramedSource.cpp

Go to the documentation of this file.
00001 /**********
00002 This library is free software; you can redistribute it and/or modify it under
00003 the terms of the GNU Lesser General Public License as published by the
00004 Free Software Foundation; either version 2.1 of the License, or (at your
00005 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
00006 
00007 This library is distributed in the hope that it will be useful, but WITHOUT
00008 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00009 FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
00010 more details.
00011 
00012 You should have received a copy of the GNU Lesser General Public License
00013 along with this library; if not, write to the Free Software Foundation, Inc.,
00014 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
00015 **********/
00016 // "liveMedia"
00017 // Copyright (c) 1996-2013 Live Networks, Inc.  All rights reserved.
00018 // Framed Sources
00019 // Implementation
00020 
00021 #include "FramedSource.hh"
00022 #include <stdlib.h>
00023 
00025 
00026 FramedSource::FramedSource(UsageEnvironment& env)
00027   : MediaSource(env),
00028     fAfterGettingFunc(NULL), fAfterGettingClientData(NULL),
00029     fOnCloseFunc(NULL), fOnCloseClientData(NULL),
00030     fIsCurrentlyAwaitingData(False) {
00031   fPresentationTime.tv_sec = fPresentationTime.tv_usec = 0; // initially
00032 }
00033 
00034 FramedSource::~FramedSource() {
00035 }
00036 
00037 Boolean FramedSource::isFramedSource() const {
00038   return True;
00039 }
00040 
00041 Boolean FramedSource::lookupByName(UsageEnvironment& env, char const* sourceName,
00042                                    FramedSource*& resultSource) {
00043   resultSource = NULL; // unless we succeed
00044 
00045   MediaSource* source;
00046   if (!MediaSource::lookupByName(env, sourceName, source)) return False;
00047 
00048   if (!source->isFramedSource()) {
00049     env.setResultMsg(sourceName, " is not a framed source");
00050     return False;
00051   }
00052 
00053   resultSource = (FramedSource*)source;
00054   return True;
00055 }
00056 
00057 void FramedSource::getNextFrame(unsigned char* to, unsigned maxSize,
00058                                 afterGettingFunc* afterGettingFunc,
00059                                 void* afterGettingClientData,
00060                                 onCloseFunc* onCloseFunc,
00061                                 void* onCloseClientData) {
00062   // Make sure we're not already being read:
00063   if (fIsCurrentlyAwaitingData) {
00064     envir() << "FramedSource[" << this << "]::getNextFrame(): attempting to read more than once at the same time!\n";
00065     envir().internalError();
00066   }
00067 
00068   fTo = to;
00069   fMaxSize = maxSize;
00070   fNumTruncatedBytes = 0; // by default; could be changed by doGetNextFrame()
00071   fDurationInMicroseconds = 0; // by default; could be changed by doGetNextFrame()
00072   fAfterGettingFunc = afterGettingFunc;
00073   fAfterGettingClientData = afterGettingClientData;
00074   fOnCloseFunc = onCloseFunc;
00075   fOnCloseClientData = onCloseClientData;
00076   fIsCurrentlyAwaitingData = True;
00077 
00078   doGetNextFrame();
00079 }
00080 
00081 void FramedSource::afterGetting(FramedSource* source) {
00082   source->fIsCurrentlyAwaitingData = False;
00083       // indicates that we can be read again
00084       // Note that this needs to be done here, in case the "fAfterFunc"
00085       // called below tries to read another frame (which it usually will)
00086 
00087   if (source->fAfterGettingFunc != NULL) {
00088     (*(source->fAfterGettingFunc))(source->fAfterGettingClientData,
00089                                    source->fFrameSize, source->fNumTruncatedBytes,
00090                                    source->fPresentationTime,
00091                                    source->fDurationInMicroseconds);
00092   }
00093 }
00094 
00095 void FramedSource::handleClosure(void* clientData) {
00096   FramedSource* source = (FramedSource*)clientData;
00097   source->fIsCurrentlyAwaitingData = False; // because we got a close instead
00098   if (source->fOnCloseFunc != NULL) {
00099     (*(source->fOnCloseFunc))(source->fOnCloseClientData);
00100   }
00101 }
00102 
00103 void FramedSource::stopGettingFrames() {
00104   fIsCurrentlyAwaitingData = False; // indicates that we can be read again
00105 
00106   // Perform any specialized action now:
00107   doStopGettingFrames();
00108 }
00109 
00110 void FramedSource::doStopGettingFrames() {
00111   // Default implementation: Do nothing except cancel any pending 'delivery' task:
00112   envir().taskScheduler().unscheduleDelayedTask(nextTask());
00113   // Subclasses may wish to redefine this function.
00114 }
00115 
00116 unsigned FramedSource::maxFrameSize() const {
00117   // By default, this source has no maximum frame size.
00118   return 0;
00119 }

Generated on Mon Apr 29 13:28:01 2013 for live by  doxygen 1.5.2