liveMedia/MPEG1or2VideoRTPSource.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-2014 Live Networks, Inc.  All rights reserved.
00018 // MPEG-1 or MPEG-2 Video RTP Sources
00019 // Implementation
00020 
00021 #include "MPEG1or2VideoRTPSource.hh"
00022 
00023 MPEG1or2VideoRTPSource*
00024 MPEG1or2VideoRTPSource::createNew(UsageEnvironment& env, Groupsock* RTPgs,
00025                               unsigned char rtpPayloadFormat,
00026                               unsigned rtpTimestampFrequency) {
00027   return new MPEG1or2VideoRTPSource(env, RTPgs, rtpPayloadFormat,
00028                                 rtpTimestampFrequency);
00029 }
00030 
00031 MPEG1or2VideoRTPSource::MPEG1or2VideoRTPSource(UsageEnvironment& env,
00032                                        Groupsock* RTPgs,
00033                                        unsigned char rtpPayloadFormat,
00034                                        unsigned rtpTimestampFrequency)
00035   : MultiFramedRTPSource(env, RTPgs,
00036                          rtpPayloadFormat, rtpTimestampFrequency){
00037 }
00038 
00039 MPEG1or2VideoRTPSource::~MPEG1or2VideoRTPSource() {
00040 }
00041 
00042 Boolean MPEG1or2VideoRTPSource
00043 ::processSpecialHeader(BufferedPacket* packet,
00044                        unsigned& resultSpecialHeaderSize) {
00045   // There's a 4-byte video-specific header
00046   if (packet->dataSize() < 4) return False;
00047 
00048   u_int32_t header = ntohl(*(u_int32_t*)(packet->data()));
00049 
00050   u_int32_t sBit = header&0x00002000; // sequence-header-present
00051   u_int32_t bBit = header&0x00001000; // beginning-of-slice
00052   u_int32_t eBit = header&0x00000800; // end-of-slice
00053 
00054   fCurrentPacketBeginsFrame = (sBit|bBit) != 0;
00055   fCurrentPacketCompletesFrame = ((sBit != 0) && (bBit == 0)) || (eBit != 0);
00056 
00057   resultSpecialHeaderSize = 4;
00058   return True;
00059 }
00060 
00061 Boolean MPEG1or2VideoRTPSource
00062 ::packetIsUsableInJitterCalculation(unsigned char* packet,
00063                                     unsigned packetSize) {
00064   // There's a 4-byte video-specific header
00065   if (packetSize < 4) return False;
00066 
00067   // Extract the "Picture-Type" field from this, to determine whether
00068   // this packet can be used in jitter calculations:
00069   unsigned header = ntohl(*(u_int32_t*)packet);
00070 
00071   unsigned short pictureType = (header>>8)&0x7;
00072   if (pictureType == 1) { // an I frame
00073     return True;
00074   } else { // a P, B, D, or other unknown frame type
00075     return False;
00076   }
00077 }
00078 
00079 char const* MPEG1or2VideoRTPSource::MIMEtype() const {
00080   return "video/MPEG";
00081 }
00082 

Generated on Tue Mar 25 14:35:35 2014 for live by  doxygen 1.5.2