blob: 88838f35f8a0cebcd729fa86292b0d592a0d313b [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
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
pbos@webrtc.orga4407322013-07-16 12:32:05 +000011#include "webrtc/modules/interface/module_common_types.h"
12#include "webrtc/modules/video_coding/main/source/packet.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000013
14#include <assert.h>
15
16namespace webrtc {
17
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000018VCMPacket::VCMPacket()
19 :
20 payloadType(0),
21 timestamp(0),
wu@webrtc.org6c75c982014-04-15 17:46:33 +000022 ntp_time_ms_(0),
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000023 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),
stefan@webrtc.org3417eb42013-05-21 15:25:53 +000032 width(0),
33 height(0),
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000034 codecSpecificHeader() {
35}
36
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000037VCMPacket::VCMPacket(const uint8_t* ptr,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000038 const size_t size,
stefan@webrtc.org3417eb42013-05-21 15:25:53 +000039 const WebRtcRTPHeader& rtpHeader) :
niklase@google.com470e71d2011-07-07 08:21:25 +000040 payloadType(rtpHeader.header.payloadType),
41 timestamp(rtpHeader.header.timestamp),
wu@webrtc.org6c75c982014-04-15 17:46:33 +000042 ntp_time_ms_(rtpHeader.ntp_time_ms),
niklase@google.com470e71d2011-07-07 08:21:25 +000043 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),
stefan@webrtc.org3417eb42013-05-21 15:25:53 +000053 width(rtpHeader.type.Video.width),
54 height(rtpHeader.type.Video.height),
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000055 codecSpecificHeader(rtpHeader.type.Video)
niklase@google.com470e71d2011-07-07 08:21:25 +000056{
57 CopyCodecSpecifics(rtpHeader.type.Video);
58}
59
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000060VCMPacket::VCMPacket(const uint8_t* ptr,
61 size_t size,
62 uint16_t seq,
63 uint32_t ts,
64 bool mBit) :
niklase@google.com470e71d2011-07-07 08:21:25 +000065 payloadType(0),
66 timestamp(ts),
wu@webrtc.org6c75c982014-04-15 17:46:33 +000067 ntp_time_ms_(0),
niklase@google.com470e71d2011-07-07 08:21:25 +000068 seqNum(seq),
69 dataPtr(ptr),
70 sizeBytes(size),
71 markerBit(mBit),
72
73 frameType(kVideoFrameDelta),
74 codec(kVideoCodecUnknown),
75 isFirstPacket(false),
76 completeNALU(kNaluComplete),
77 insertStartCode(false),
stefan@webrtc.org3417eb42013-05-21 15:25:53 +000078 width(0),
79 height(0),
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000080 codecSpecificHeader()
niklase@google.com470e71d2011-07-07 08:21:25 +000081{}
82
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000083void VCMPacket::Reset() {
84 payloadType = 0;
85 timestamp = 0;
wu@webrtc.org6c75c982014-04-15 17:46:33 +000086 ntp_time_ms_ = 0;
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000087 seqNum = 0;
88 dataPtr = NULL;
89 sizeBytes = 0;
90 markerBit = false;
91 frameType = kFrameEmpty;
92 codec = kVideoCodecUnknown;
93 isFirstPacket = false;
94 completeNALU = kNaluUnset;
95 insertStartCode = false;
stefan@webrtc.org3417eb42013-05-21 15:25:53 +000096 width = 0;
97 height = 0;
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000098 memset(&codecSpecificHeader, 0, sizeof(RTPVideoHeader));
99}
100
stefan@webrtc.org2ec56062014-07-31 14:59:24 +0000101void VCMPacket::CopyCodecSpecifics(const RTPVideoHeader& videoHeader) {
Guo-wei Shieh64c1e8c2015-04-01 15:33:06 -0700102 if (markerBit) {
103 codecSpecificHeader.rotation = videoHeader.rotation;
104 }
stefan@webrtc.org2ec56062014-07-31 14:59:24 +0000105 switch (videoHeader.codec) {
106 case kRtpVideoVp8:
107 // Handle all packets within a frame as depending on the previous packet
108 // TODO(holmer): This should be changed to make fragments independent
109 // when the VP8 RTP receiver supports fragments.
110 if (isFirstPacket && markerBit)
111 completeNALU = kNaluComplete;
112 else if (isFirstPacket)
113 completeNALU = kNaluStart;
114 else if (markerBit)
115 completeNALU = kNaluEnd;
116 else
117 completeNALU = kNaluIncomplete;
holmer@google.com155188c2011-08-15 09:21:27 +0000118
stefan@webrtc.org2ec56062014-07-31 14:59:24 +0000119 codec = kVideoCodecVP8;
120 return;
asaperssonf38ea3c2015-07-28 04:02:54 -0700121 case kRtpVideoVp9:
122 if (isFirstPacket && markerBit)
123 completeNALU = kNaluComplete;
124 else if (isFirstPacket)
125 completeNALU = kNaluStart;
126 else if (markerBit)
127 completeNALU = kNaluEnd;
128 else
129 completeNALU = kNaluIncomplete;
130
131 codec = kVideoCodecVP9;
132 return;
stefan@webrtc.org2ec56062014-07-31 14:59:24 +0000133 case kRtpVideoH264:
134 isFirstPacket = videoHeader.isFirstPacket;
135 if (isFirstPacket)
136 insertStartCode = true;
137
Noah Richards97282412015-04-23 11:15:08 -0700138 if (isFirstPacket && markerBit) {
stefan@webrtc.org2ec56062014-07-31 14:59:24 +0000139 completeNALU = kNaluComplete;
140 } else if (isFirstPacket) {
141 completeNALU = kNaluStart;
142 } else if (markerBit) {
143 completeNALU = kNaluEnd;
144 } else {
145 completeNALU = kNaluIncomplete;
146 }
147 codec = kVideoCodecH264;
148 return;
149 case kRtpVideoGeneric:
150 case kRtpVideoNone:
151 codec = kVideoCodecUnknown;
152 return;
153 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000154}
155
stefan@webrtc.org2ec56062014-07-31 14:59:24 +0000156} // namespace webrtc