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/video_coding/packet.h"
12
13 #include <assert.h>
14
15 #include "webrtc/modules/include/module_common_types.h"
16
17 namespace webrtc {
18
VCMPacket()19 VCMPacket::VCMPacket()
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(kEmptyFrame),
28 codec(kVideoCodecUnknown),
29 isFirstPacket(false),
30 completeNALU(kNaluUnset),
31 insertStartCode(false),
32 width(0),
33 height(0),
34 codecSpecificHeader() {}
35
VCMPacket(const uint8_t * ptr,const size_t size,const WebRtcRTPHeader & rtpHeader)36 VCMPacket::VCMPacket(const uint8_t* ptr,
37 const size_t size,
38 const WebRtcRTPHeader& rtpHeader)
39 : payloadType(rtpHeader.header.payloadType),
40 timestamp(rtpHeader.header.timestamp),
41 ntp_time_ms_(rtpHeader.ntp_time_ms),
42 seqNum(rtpHeader.header.sequenceNumber),
43 dataPtr(ptr),
44 sizeBytes(size),
45 markerBit(rtpHeader.header.markerBit),
46
47 frameType(rtpHeader.frameType),
48 codec(kVideoCodecUnknown),
49 isFirstPacket(rtpHeader.type.Video.isFirstPacket),
50 completeNALU(kNaluComplete),
51 insertStartCode(false),
52 width(rtpHeader.type.Video.width),
53 height(rtpHeader.type.Video.height),
54 codecSpecificHeader(rtpHeader.type.Video) {
55 CopyCodecSpecifics(rtpHeader.type.Video);
56 }
57
VCMPacket(const uint8_t * ptr,size_t size,uint16_t seq,uint32_t ts,bool mBit)58 VCMPacket::VCMPacket(const uint8_t* ptr,
59 size_t size,
60 uint16_t seq,
61 uint32_t ts,
62 bool mBit)
63 : payloadType(0),
64 timestamp(ts),
65 ntp_time_ms_(0),
66 seqNum(seq),
67 dataPtr(ptr),
68 sizeBytes(size),
69 markerBit(mBit),
70
71 frameType(kVideoFrameDelta),
72 codec(kVideoCodecUnknown),
73 isFirstPacket(false),
74 completeNALU(kNaluComplete),
75 insertStartCode(false),
76 width(0),
77 height(0),
78 codecSpecificHeader() {}
79
Reset()80 void VCMPacket::Reset() {
81 payloadType = 0;
82 timestamp = 0;
83 ntp_time_ms_ = 0;
84 seqNum = 0;
85 dataPtr = NULL;
86 sizeBytes = 0;
87 markerBit = false;
88 frameType = kEmptyFrame;
89 codec = kVideoCodecUnknown;
90 isFirstPacket = false;
91 completeNALU = kNaluUnset;
92 insertStartCode = false;
93 width = 0;
94 height = 0;
95 memset(&codecSpecificHeader, 0, sizeof(RTPVideoHeader));
96 }
97
CopyCodecSpecifics(const RTPVideoHeader & videoHeader)98 void VCMPacket::CopyCodecSpecifics(const RTPVideoHeader& videoHeader) {
99 if (markerBit) {
100 codecSpecificHeader.rotation = videoHeader.rotation;
101 }
102 switch (videoHeader.codec) {
103 case kRtpVideoVp8:
104 // Handle all packets within a frame as depending on the previous packet
105 // TODO(holmer): This should be changed to make fragments independent
106 // when the VP8 RTP receiver supports fragments.
107 if (isFirstPacket && markerBit)
108 completeNALU = kNaluComplete;
109 else if (isFirstPacket)
110 completeNALU = kNaluStart;
111 else if (markerBit)
112 completeNALU = kNaluEnd;
113 else
114 completeNALU = kNaluIncomplete;
115
116 codec = kVideoCodecVP8;
117 return;
118 case kRtpVideoVp9:
119 if (isFirstPacket && markerBit)
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 = kVideoCodecVP9;
129 return;
130 case kRtpVideoH264:
131 isFirstPacket = videoHeader.isFirstPacket;
132 if (isFirstPacket)
133 insertStartCode = true;
134
135 if (isFirstPacket && markerBit) {
136 completeNALU = kNaluComplete;
137 } else if (isFirstPacket) {
138 completeNALU = kNaluStart;
139 } else if (markerBit) {
140 completeNALU = kNaluEnd;
141 } else {
142 completeNALU = kNaluIncomplete;
143 }
144 codec = kVideoCodecH264;
145 return;
146 case kRtpVideoGeneric:
147 case kRtpVideoNone:
148 codec = kVideoCodecUnknown;
149 return;
150 }
151 }
152
153 } // namespace webrtc
154