liveMedia/H263plusVideoRTPSource.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-2012 Live Networks, Inc.  All rights reserved.
00018 // H.263+ Video RTP Sources
00019 // Implementation
00020 
00021 #include "H263plusVideoRTPSource.hh"
00022 
00023 H263plusVideoRTPSource*
00024 H263plusVideoRTPSource::createNew(UsageEnvironment& env, Groupsock* RTPgs,
00025                                   unsigned char rtpPayloadFormat,
00026                                   unsigned rtpTimestampFrequency) {
00027   return new H263plusVideoRTPSource(env, RTPgs, rtpPayloadFormat,
00028                                     rtpTimestampFrequency);
00029 }
00030 
00031 H263plusVideoRTPSource
00032 ::H263plusVideoRTPSource(UsageEnvironment& env, Groupsock* RTPgs,
00033                          unsigned char rtpPayloadFormat,
00034                          unsigned rtpTimestampFrequency)
00035   : MultiFramedRTPSource(env, RTPgs,
00036                          rtpPayloadFormat, rtpTimestampFrequency),
00037   fNumSpecialHeaders(0), fSpecialHeaderBytesLength(0) {
00038 }
00039 
00040 H263plusVideoRTPSource::~H263plusVideoRTPSource() {
00041 }
00042 
00043 Boolean H263plusVideoRTPSource
00044 ::processSpecialHeader(BufferedPacket* packet,
00045                        unsigned& resultSpecialHeaderSize) {
00046   unsigned char* headerStart = packet->data();
00047   unsigned packetSize = packet->dataSize();
00048 
00049   // The H.263+ payload header is at least 2 bytes in size.
00050   // Extract the known fields from the first 2 bytes:
00051   unsigned expectedHeaderSize = 2;
00052   if (packetSize < expectedHeaderSize) return False;
00053 
00054   //unsigned char RR = headerStart[0]>>3;
00055   Boolean P = (headerStart[0]&0x4) != 0;
00056   Boolean V = (headerStart[0]&0x2) != 0;
00057   unsigned char PLEN = ((headerStart[0]&0x1)<<5)|(headerStart[1]>>3);
00058   //unsigned char PEBIT = headerStart[1]&0x7;
00059 
00060   if (V) {
00061     // There's an extra VRC byte at the end of the header:
00062     ++expectedHeaderSize;
00063     if (packetSize < expectedHeaderSize) return False;
00064   }
00065 
00066   if (PLEN > 0) {
00067     // There's an extra picture header at the end:
00068     expectedHeaderSize += PLEN;
00069     if (packetSize < expectedHeaderSize) return False;
00070   }
00071 
00072   fCurrentPacketBeginsFrame = P;
00073   if (fCurrentPacketBeginsFrame) {
00074     fNumSpecialHeaders = fSpecialHeaderBytesLength = 0;
00075   }
00076 
00077   // Make a copy of the special header bytes, in case a reader
00078   // can use them:
00079   unsigned bytesAvailable
00080     = SPECIAL_HEADER_BUFFER_SIZE - fSpecialHeaderBytesLength - 1;
00081   if (expectedHeaderSize <= bytesAvailable) {
00082     fSpecialHeaderBytes[fSpecialHeaderBytesLength++] = expectedHeaderSize;
00083     for (unsigned i = 0; i < expectedHeaderSize; ++i) {
00084       fSpecialHeaderBytes[fSpecialHeaderBytesLength++] = headerStart[i];
00085     }
00086     fPacketSizes[fNumSpecialHeaders++] = packetSize;
00087   }
00088 
00089   if (P) {
00090     // Prepend two zero bytes to the start of the payload proper.
00091     // Hack: Do this by shrinking this special header by 2 bytes:
00092     expectedHeaderSize -= 2;
00093     headerStart[expectedHeaderSize] = 0;
00094     headerStart[expectedHeaderSize+1] = 0;
00095   }
00096 
00097   // The RTP "M" (marker) bit indicates the last fragment of a frame:
00098   fCurrentPacketCompletesFrame = packet->rtpMarkerBit();
00099 
00100   resultSpecialHeaderSize = expectedHeaderSize;
00101   return True;
00102 }
00103 
00104 char const* H263plusVideoRTPSource::MIMEtype() const {
00105   return "video/H263-1998";
00106 }

Generated on Thu May 17 07:11:45 2012 for live by  doxygen 1.5.2