live555 RTSPServer H264-live-streamimg

来源:互联网 发布:网站域名服务器多少钱 编辑:程序博客网 时间:2024/06/05 06:17

 参考 :

live555源码分析----H264的数据处理

http://blog.csdn.net/lifan_3a/article/details/9674391

 

in liveMedia/H264VideoRTPSink.cpp,
104 Boolean H264VideoRTPSink::continuePlaying() {
105   // First, check whether we have a 'fragmenter' class set up yet.
106   // If not, create it now:
107   if (fOurFragmenter == NULL) {
108     fOurFragmenter = new H264FUAFragmenter(envir(), fSource, OutPacketBuffer::maxSize,
109                        ourMaxPacketSize() - 12/*RTP hdr size*/);
110   } else {
111     fOurFragmenter->reassignInputSource(fSource);
112   }
113   fSource = fOurFragmenter;   //here fSource is assigned to fOurFragmenter
114
115   // Then call the parent class's implementation:
116   return MultiFramedRTPSink::continuePlaying();
117 }

in liveMedia/MultiFramedRTPSink.cpp:
149 Boolean MultiFramedRTPSink::continuePlaying() {
150   // Send the first packet.
151   // (This will also schedule any future sends.)
152   buildAndSendPacket(True);
153   return True;
154 }

165 void MultiFramedRTPSink::buildAndSendPacket(Boolean isFirstPacket) {
...
...
...
187   // Begin packing as many (complete) frames into the packet as we can:
188   fTotalFrameSpecificHeaderSizes = 0;
189   fNoFramesLeft = False;
190   fNumFramesUsedSoFar = 0;
191   packFrame();
}

194 void MultiFramedRTPSink::packFrame() {
195   // Get the next frame.
196
197   // First, see if we have an overflow frame that was too big for the last pkt
198   if (fOutBuf->haveOverflowData()) {
199     // Use this frame before reading a new one from the source
200     unsigned frameSize = fOutBuf->overflowDataSize();
201     struct timeval presentationTime = fOutBuf->overflowPresentationTime();
202     unsigned durationInMicroseconds = fOutBuf->overflowDurationInMicroseconds();
203     fOutBuf->useOverflowData();
204
205     printf("packFrame0 durationInMicroseconds = %d\n",durationInMicroseconds);
206     afterGettingFrame1(frameSize, 0, presentationTime, durationInMicroseconds);
207   } else {
208     // Normal case: we need to read a new frame from the source
209     if (fSource == NULL) return;

211     fCurFrameSpecificHeaderPosition = fOutBuf->curPacketSize();
212     fCurFrameSpecificHeaderSize = frameSpecificHeaderSize();
213     fOutBuf->skipBytes(fCurFrameSpecificHeaderSize);
214     fTotalFrameSpecificHeaderSizes += fCurFrameSpecificHeaderSize;
215
216     printf("packFrame1\n");
217     fSource->getNextFrame(fOutBuf->curPtr(), fOutBuf->totalBytesAvailable(),
218               afterGettingFrame, this, ourHandleClosure, this);
219   }
220 }

in liveMedia/FramedSource.cpp:  
57 void FramedSource::getNextFrame(unsigned char* to, unsigned maxSize,
 58                 afterGettingFunc* afterGettingFunc,
 59                 void* afterGettingClientData,
 60                 onCloseFunc* onCloseFunc,
 61                 void* onCloseClientData) {
 62   // Make sure we're not already being read:
 63   if (fIsCurrentlyAwaitingData) {
 64     envir() << "FramedSource[" << this << "]::getNextFrame(): attempting to read more     than once at the same time!\n";
 65     envir().internalError();
 66   }
 67
 68   fTo = to;
 69   fMaxSize = maxSize;
 70   fNumTruncatedBytes = 0; // by default; could be changed by doGetNextFrame()
 71   fDurationInMicroseconds = 0; // by default; could be changed by doGetNextFrame()
 72   fAfterGettingFunc = afterGettingFunc;
 73   fAfterGettingClientData = afterGettingClientData;
 74   fOnCloseFunc = onCloseFunc;
 75   fOnCloseClientData = onCloseClientData;
 76   fIsCurrentlyAwaitingData = True;
 77
 78   doGetNextFrame();   //
 79 }

because fSource = fOurFragmenter; so doGetNextFrame(); will call to
liveMedia/H264VideoRTPSink.cpp:
212 void H264FUAFragmenter::doGetNextFrame() {
214   if (fNumValidDataBytes == 1) {
215     // We have no NAL unit data currently in the buffer.  Read a new one:
216     fInputSource->getNextFrame(&fInputBuffer[1], fInputBufferSize - 1,
217                    afterGettingFrame, this,
218                    FramedSource::handleClosure, this);
219   } else {
........
      }
}

fInputSource->getNextFrame() will call functions again
in liveMedia/FramedSource.cpp:  
57 void FramedSource::getNextFrame(unsigned char* to, unsigned maxSize,
 58                 afterGettingFunc* afterGettingFunc,
 59                 void* afterGettingClientData,
 60                 onCloseFunc* onCloseFunc,
 61                 void* onCloseClientData) {
 62   // Make sure we're not already being read:
 63   if (fIsCurrentlyAwaitingData) {
 64     envir() << "FramedSource[" << this << "]::getNextFrame(): attempting to read more     than once at the same time!\n";
 65     envir().internalError();
 66   }
 67
 68   fTo = to;
 69   fMaxSize = maxSize;
 70   fNumTruncatedBytes = 0; // by default; could be changed by doGetNextFrame()
 71   fDurationInMicroseconds = 0; // by default; could be changed by doGetNextFrame()
 72   fAfterGettingFunc = afterGettingFunc;
 73   fAfterGettingClientData = afterGettingClientData;
 74   fOnCloseFunc = onCloseFunc;
 75   fOnCloseClientData = onCloseClientData;
 76   fIsCurrentlyAwaitingData = True;
 77
 78   doGetNextFrame();   //
 79 }
 
 here doGetNextFrame(); will call to
liveMedia/MPEGVideoStreamFramer.cpp:
140 void MPEGVideoStreamFramer::doGetNextFrame() {
141 //  printf("MPEGVideoStreamFramer::doGetNextFrame\n");
142   fParser->registerReadInterest(fTo, fMaxSize);
143   continueReadProcessing();
144 }

154 void MPEGVideoStreamFramer::continueReadProcessing() {
155 //  printf("MPEGVideoStreamFramer::continueReadProcessing\n");
156   unsigned acquiredFrameSize = fParser->parse();
157   if (acquiredFrameSize > 0) {
      ....
   ....
181   }
182 }

fParser->parse() call to
liveMedia/H264VideoStreamFramer.cpp :
568 unsigned H264VideoStreamParser::parse() {
569    // printf("H264VideoStreamParser::parse\n");
570   try {
571     // The stream must start with a 0x00000001:
572     if (!fHaveSeenFirstStartCode) {
573       // Skip over any input bytes that precede the first 0x00000001:
574       u_int32_t first4Bytes;
575       while ((first4Bytes = test4Bytes()) != 0x00000001) {
576     get1Byte(); setParseState(); // ensures that we progress over bad data
577       }
578       skipBytes(4); // skip this initial code
         ....
   ....
839     return 0;  // the parsing got interrupted
840   }
841 }

 then test4Bytes() --call-->ensureValidBytes(4) --call--> ensureValidBytes1(numBytesNeeded)
 in liveMedia/StreamParser.cpp :
121 void StreamParser::ensureValidBytes1(unsigned numBytesNeeded) {
122   // We need to read some more bytes from the input source.
123   // First, clarify how much data to ask for:
124   unsigned maxInputFrameSize = fInputSource->maxFrameSize();
125   if (maxInputFrameSize > numBytesNeeded) numBytesNeeded = maxInputFrameSize;
 ....
 ....
 ....
155   // Try to read as many new bytes as will fit in the current bank:
156   unsigned maxNumBytesToRead = BANK_SIZE - fTotNumValidBytes;
157   fInputSource->getNextFrame(&curBank()[fTotNumValidBytes],
158                  maxNumBytesToRead,
159                  afterGettingBytes, this,
160                  onInputClosure, this);
161
162   throw NO_MORE_BUFFERED_INPUT;
163 }

then fInputSource->getNextFrame --call-->FramedSource::getNextFrame() --call-->doGetNextFrame()
 in liveMedia/ENCVideoLiveFramedSource.cpp:
 116 void ENCVideoLiveFramedSource::doGetNextFrame() {
 .....
}

0 0
原创粉丝点击