Home | History | Annotate | Download | only in source
      1 /*
      2  *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 #include "webrtc/modules/interface/module_common_types.h"
     12 #include "webrtc/modules/video_coding/main/source/packet.h"
     13 
     14 #include <assert.h>
     15 
     16 namespace webrtc {
     17 
     18 VCMPacket::VCMPacket()
     19   :
     20     payloadType(0),
     21     timestamp(0),
     22     ntp_time_ms_(0),
     23     seqNum(0),
     24     dataPtr(NULL),
     25     sizeBytes(0),
     26     markerBit(false),
     27     frameType(kFrameEmpty),
     28     codec(kVideoCodecUnknown),
     29     isFirstPacket(false),
     30     completeNALU(kNaluUnset),
     31     insertStartCode(false),
     32     width(0),
     33     height(0),
     34     codecSpecificHeader() {
     35 }
     36 
     37 VCMPacket::VCMPacket(const uint8_t* ptr,
     38                      const uint32_t size,
     39                      const WebRtcRTPHeader& rtpHeader) :
     40     payloadType(rtpHeader.header.payloadType),
     41     timestamp(rtpHeader.header.timestamp),
     42     ntp_time_ms_(rtpHeader.ntp_time_ms),
     43     seqNum(rtpHeader.header.sequenceNumber),
     44     dataPtr(ptr),
     45     sizeBytes(size),
     46     markerBit(rtpHeader.header.markerBit),
     47 
     48     frameType(rtpHeader.frameType),
     49     codec(kVideoCodecUnknown),
     50     isFirstPacket(rtpHeader.type.Video.isFirstPacket),
     51     completeNALU(kNaluComplete),
     52     insertStartCode(false),
     53     width(rtpHeader.type.Video.width),
     54     height(rtpHeader.type.Video.height),
     55     codecSpecificHeader(rtpHeader.type.Video)
     56 {
     57     CopyCodecSpecifics(rtpHeader.type.Video);
     58 }
     59 
     60 VCMPacket::VCMPacket(const uint8_t* ptr, uint32_t size, uint16_t seq, uint32_t ts, bool mBit) :
     61     payloadType(0),
     62     timestamp(ts),
     63     ntp_time_ms_(0),
     64     seqNum(seq),
     65     dataPtr(ptr),
     66     sizeBytes(size),
     67     markerBit(mBit),
     68 
     69     frameType(kVideoFrameDelta),
     70     codec(kVideoCodecUnknown),
     71     isFirstPacket(false),
     72     completeNALU(kNaluComplete),
     73     insertStartCode(false),
     74     width(0),
     75     height(0),
     76     codecSpecificHeader()
     77 {}
     78 
     79 void VCMPacket::Reset() {
     80   payloadType = 0;
     81   timestamp = 0;
     82   ntp_time_ms_ = 0;
     83   seqNum = 0;
     84   dataPtr = NULL;
     85   sizeBytes = 0;
     86   markerBit = false;
     87   frameType = kFrameEmpty;
     88   codec = kVideoCodecUnknown;
     89   isFirstPacket = false;
     90   completeNALU = kNaluUnset;
     91   insertStartCode = false;
     92   width = 0;
     93   height = 0;
     94   memset(&codecSpecificHeader, 0, sizeof(RTPVideoHeader));
     95 }
     96 
     97 void VCMPacket::CopyCodecSpecifics(const RTPVideoHeader& videoHeader)
     98 {
     99     switch(videoHeader.codec)
    100     {
    101         case kRtpVideoVp8:
    102             {
    103                 // Handle all packets within a frame as depending on the previous packet
    104                 // TODO(holmer): This should be changed to make fragments independent
    105                 // when the VP8 RTP receiver supports fragments.
    106                 if (isFirstPacket && markerBit)
    107                     completeNALU = kNaluComplete;
    108                 else if (isFirstPacket)
    109                     completeNALU = kNaluStart;
    110                 else if (markerBit)
    111                     completeNALU = kNaluEnd;
    112                 else
    113                     completeNALU = kNaluIncomplete;
    114 
    115                 codec = kVideoCodecVP8;
    116                 break;
    117             }
    118         default:
    119             {
    120                 codec = kVideoCodecUnknown;
    121                 break;
    122             }
    123     }
    124 }
    125 
    126 }
    127