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
VCMPacket()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
VCMPacket(const uint8_t * ptr,const uint32_t size,const WebRtcRTPHeader & rtpHeader)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
VCMPacket(const uint8_t * ptr,uint32_t size,uint16_t seq,uint32_t ts,bool mBit)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
Reset()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
CopyCodecSpecifics(const RTPVideoHeader & videoHeader)97 void VCMPacket::CopyCodecSpecifics(const RTPVideoHeader& videoHeader) {
98 switch (videoHeader.codec) {
99 case kRtpVideoVp8:
100 // Handle all packets within a frame as depending on the previous packet
101 // TODO(holmer): This should be changed to make fragments independent
102 // when the VP8 RTP receiver supports fragments.
103 if (isFirstPacket && markerBit)
104 completeNALU = kNaluComplete;
105 else if (isFirstPacket)
106 completeNALU = kNaluStart;
107 else if (markerBit)
108 completeNALU = kNaluEnd;
109 else
110 completeNALU = kNaluIncomplete;
111
112 codec = kVideoCodecVP8;
113 return;
114 case kRtpVideoH264:
115 isFirstPacket = videoHeader.isFirstPacket;
116 if (isFirstPacket)
117 insertStartCode = true;
118
119 if (videoHeader.codecHeader.H264.single_nalu) {
120 completeNALU = kNaluComplete;
121 } else if (isFirstPacket) {
122 completeNALU = kNaluStart;
123 } else if (markerBit) {
124 completeNALU = kNaluEnd;
125 } else {
126 completeNALU = kNaluIncomplete;
127 }
128 codec = kVideoCodecH264;
129 return;
130 case kRtpVideoGeneric:
131 case kRtpVideoNone:
132 codec = kVideoCodecUnknown;
133 return;
134 }
135 }
136
137 } // namespace webrtc
138