blob: 34384483bec6cd1963dc93f4acdb41959e7c45c6 [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
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010011#include "webrtc/modules/include/module_common_types.h"
pbos@webrtc.orga4407322013-07-16 12:32:05 +000012#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()
pbos22993e12015-10-19 02:39:06 -070019 : payloadType(0),
20 timestamp(0),
21 ntp_time_ms_(0),
22 seqNum(0),
23 dataPtr(NULL),
24 sizeBytes(0),
25 markerBit(false),
26 frameType(kEmptyFrame),
27 codec(kVideoCodecUnknown),
28 isFirstPacket(false),
29 completeNALU(kNaluUnset),
30 insertStartCode(false),
31 width(0),
32 height(0),
33 codecSpecificHeader() {}
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000034
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000035VCMPacket::VCMPacket(const uint8_t* ptr,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000036 const size_t size,
stefan@webrtc.org3417eb42013-05-21 15:25:53 +000037 const WebRtcRTPHeader& rtpHeader) :
niklase@google.com470e71d2011-07-07 08:21:25 +000038 payloadType(rtpHeader.header.payloadType),
39 timestamp(rtpHeader.header.timestamp),
wu@webrtc.org6c75c982014-04-15 17:46:33 +000040 ntp_time_ms_(rtpHeader.ntp_time_ms),
niklase@google.com470e71d2011-07-07 08:21:25 +000041 seqNum(rtpHeader.header.sequenceNumber),
42 dataPtr(ptr),
43 sizeBytes(size),
44 markerBit(rtpHeader.header.markerBit),
45
46 frameType(rtpHeader.frameType),
47 codec(kVideoCodecUnknown),
48 isFirstPacket(rtpHeader.type.Video.isFirstPacket),
49 completeNALU(kNaluComplete),
50 insertStartCode(false),
stefan@webrtc.org3417eb42013-05-21 15:25:53 +000051 width(rtpHeader.type.Video.width),
52 height(rtpHeader.type.Video.height),
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000053 codecSpecificHeader(rtpHeader.type.Video)
niklase@google.com470e71d2011-07-07 08:21:25 +000054{
55 CopyCodecSpecifics(rtpHeader.type.Video);
56}
57
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000058VCMPacket::VCMPacket(const uint8_t* ptr,
59 size_t size,
60 uint16_t seq,
61 uint32_t ts,
62 bool mBit) :
niklase@google.com470e71d2011-07-07 08:21:25 +000063 payloadType(0),
64 timestamp(ts),
wu@webrtc.org6c75c982014-04-15 17:46:33 +000065 ntp_time_ms_(0),
niklase@google.com470e71d2011-07-07 08:21:25 +000066 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),
stefan@webrtc.org3417eb42013-05-21 15:25:53 +000076 width(0),
77 height(0),
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000078 codecSpecificHeader()
niklase@google.com470e71d2011-07-07 08:21:25 +000079{}
80
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000081void VCMPacket::Reset() {
82 payloadType = 0;
83 timestamp = 0;
wu@webrtc.org6c75c982014-04-15 17:46:33 +000084 ntp_time_ms_ = 0;
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000085 seqNum = 0;
86 dataPtr = NULL;
87 sizeBytes = 0;
88 markerBit = false;
pbos22993e12015-10-19 02:39:06 -070089 frameType = kEmptyFrame;
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000090 codec = kVideoCodecUnknown;
91 isFirstPacket = false;
92 completeNALU = kNaluUnset;
93 insertStartCode = false;
stefan@webrtc.org3417eb42013-05-21 15:25:53 +000094 width = 0;
95 height = 0;
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000096 memset(&codecSpecificHeader, 0, sizeof(RTPVideoHeader));
97}
98
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000099void VCMPacket::CopyCodecSpecifics(const RTPVideoHeader& videoHeader) {
Guo-wei Shieh64c1e8c2015-04-01 15:33:06 -0700100 if (markerBit) {
101 codecSpecificHeader.rotation = videoHeader.rotation;
102 }
stefan@webrtc.org2ec56062014-07-31 14:59:24 +0000103 switch (videoHeader.codec) {
104 case kRtpVideoVp8:
105 // Handle all packets within a frame as depending on the previous packet
106 // TODO(holmer): This should be changed to make fragments independent
107 // when the VP8 RTP receiver supports fragments.
108 if (isFirstPacket && markerBit)
109 completeNALU = kNaluComplete;
110 else if (isFirstPacket)
111 completeNALU = kNaluStart;
112 else if (markerBit)
113 completeNALU = kNaluEnd;
114 else
115 completeNALU = kNaluIncomplete;
holmer@google.com155188c2011-08-15 09:21:27 +0000116
stefan@webrtc.org2ec56062014-07-31 14:59:24 +0000117 codec = kVideoCodecVP8;
118 return;
asaperssonf38ea3c2015-07-28 04:02:54 -0700119 case kRtpVideoVp9:
120 if (isFirstPacket && markerBit)
121 completeNALU = kNaluComplete;
122 else if (isFirstPacket)
123 completeNALU = kNaluStart;
124 else if (markerBit)
125 completeNALU = kNaluEnd;
126 else
127 completeNALU = kNaluIncomplete;
128
129 codec = kVideoCodecVP9;
130 return;
stefan@webrtc.org2ec56062014-07-31 14:59:24 +0000131 case kRtpVideoH264:
132 isFirstPacket = videoHeader.isFirstPacket;
133 if (isFirstPacket)
134 insertStartCode = true;
135
Noah Richards97282412015-04-23 11:15:08 -0700136 if (isFirstPacket && markerBit) {
stefan@webrtc.org2ec56062014-07-31 14:59:24 +0000137 completeNALU = kNaluComplete;
138 } else if (isFirstPacket) {
139 completeNALU = kNaluStart;
140 } else if (markerBit) {
141 completeNALU = kNaluEnd;
142 } else {
143 completeNALU = kNaluIncomplete;
144 }
145 codec = kVideoCodecH264;
146 return;
147 case kRtpVideoGeneric:
148 case kRtpVideoNone:
149 codec = kVideoCodecUnknown;
150 return;
151 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000152}
153
stefan@webrtc.org2ec56062014-07-31 14:59:24 +0000154} // namespace webrtc