00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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;
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;
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
00063 if (fIsCurrentlyAwaitingData) {
00064 envir() << "FramedSource[" << this << "]::getNextFrame(): attempting to read more than once at the same time!\n";
00065 exit(1);
00066 }
00067
00068 fTo = to;
00069 fMaxSize = maxSize;
00070 fNumTruncatedBytes = 0;
00071 fDurationInMicroseconds = 0;
00072 fAfterGettingFunc = afterGettingFunc;
00073 fAfterGettingClientData = afterGettingClientData;
00074 fOnCloseFunc = onCloseFunc;
00075 fOnCloseClientData = onCloseClientData;
00076 fIsCurrentlyAwaitingData = True;
00077
00078 doGetNextFrame();
00079 }
00080
00081 #ifdef BACKWARDS_COMPATIBLE_WITH_OLD_AFTER_GETTING_FUNC
00082 static void bwCompatHackAfterGetting(void* clientData, unsigned frameSize,
00083 unsigned ,
00084 struct timeval presentationTime,
00085 unsigned ) {
00086 FramedSource* source = (FramedSource*)clientData;
00087 FramedSource::bwCompatAfterGettingFunc* clientAfterGettingFunc
00088 = source->fSavedBWCompatAfterGettingFunc;
00089 void* afterGettingClientData = source->fSavedBWCompatAfterGettingClientData;
00090 if (clientAfterGettingFunc != NULL) {
00091 (*clientAfterGettingFunc)(afterGettingClientData, frameSize, presentationTime);
00092 }
00093 }
00094 void FramedSource::getNextFrame(unsigned char* to, unsigned maxSize,
00095 bwCompatAfterGettingFunc* afterGettingFunc,
00096 void* afterGettingClientData,
00097 onCloseFunc* onCloseFunc,
00098 void* onCloseClientData) {
00099 fSavedBWCompatAfterGettingFunc = afterGettingFunc;
00100 fSavedBWCompatAfterGettingClientData = afterGettingClientData;
00101
00102 getNextFrame(to, maxSize, bwCompatHackAfterGetting, this,
00103 onCloseFunc, onCloseClientData);
00104 }
00105 #endif
00106
00107
00108 void FramedSource::afterGetting(FramedSource* source) {
00109 source->fIsCurrentlyAwaitingData = False;
00110
00111
00112
00113
00114 if (source->fAfterGettingFunc != NULL) {
00115 (*(source->fAfterGettingFunc))(source->fAfterGettingClientData,
00116 source->fFrameSize, source->fNumTruncatedBytes,
00117 source->fPresentationTime,
00118 source->fDurationInMicroseconds);
00119 }
00120 }
00121
00122 void FramedSource::handleClosure(void* clientData) {
00123 FramedSource* source = (FramedSource*)clientData;
00124 source->fIsCurrentlyAwaitingData = False;
00125 if (source->fOnCloseFunc != NULL) {
00126 (*(source->fOnCloseFunc))(source->fOnCloseClientData);
00127 }
00128 }
00129
00130 void FramedSource::stopGettingFrames() {
00131 fIsCurrentlyAwaitingData = False;
00132
00133
00134 doStopGettingFrames();
00135 }
00136
00137 void FramedSource::doStopGettingFrames() {
00138
00139
00140
00141 }
00142
00143 unsigned FramedSource::maxFrameSize() const {
00144
00145 return 0;
00146 }
00147
00148 Boolean FramedSource::isPrioritizedRTPStreamSelector() const {
00149 return False;
00150 }