blob: 10eba70fed6c0a58a0343a30ca71b7286f2f4980 [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
11#include "packet.h"
12#include "module_common_types.h"
13
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),
22 seqNum(0),
23 dataPtr(NULL),
24 sizeBytes(0),
25 markerBit(false),
26 frameType(kFrameEmpty),
27 codec(kVideoCodecUnknown),
28 isFirstPacket(false),
29 completeNALU(kNaluUnset),
30 insertStartCode(false),
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000031 codecSpecificHeader() {
32}
33
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000034VCMPacket::VCMPacket(const uint8_t* ptr,
35 const uint32_t size,
niklase@google.com470e71d2011-07-07 08:21:25 +000036 const WebRtcRTPHeader& rtpHeader) :
37 payloadType(rtpHeader.header.payloadType),
38 timestamp(rtpHeader.header.timestamp),
39 seqNum(rtpHeader.header.sequenceNumber),
40 dataPtr(ptr),
41 sizeBytes(size),
42 markerBit(rtpHeader.header.markerBit),
43
44 frameType(rtpHeader.frameType),
45 codec(kVideoCodecUnknown),
46 isFirstPacket(rtpHeader.type.Video.isFirstPacket),
47 completeNALU(kNaluComplete),
48 insertStartCode(false),
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000049 codecSpecificHeader(rtpHeader.type.Video)
niklase@google.com470e71d2011-07-07 08:21:25 +000050{
51 CopyCodecSpecifics(rtpHeader.type.Video);
52}
53
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000054VCMPacket::VCMPacket(const uint8_t* ptr, uint32_t size, uint16_t seq, uint32_t ts, bool mBit) :
niklase@google.com470e71d2011-07-07 08:21:25 +000055 payloadType(0),
56 timestamp(ts),
57 seqNum(seq),
58 dataPtr(ptr),
59 sizeBytes(size),
60 markerBit(mBit),
61
62 frameType(kVideoFrameDelta),
63 codec(kVideoCodecUnknown),
64 isFirstPacket(false),
65 completeNALU(kNaluComplete),
66 insertStartCode(false),
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000067 codecSpecificHeader()
niklase@google.com470e71d2011-07-07 08:21:25 +000068{}
69
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000070void VCMPacket::Reset() {
71 payloadType = 0;
72 timestamp = 0;
73 seqNum = 0;
74 dataPtr = NULL;
75 sizeBytes = 0;
76 markerBit = false;
77 frameType = kFrameEmpty;
78 codec = kVideoCodecUnknown;
79 isFirstPacket = false;
80 completeNALU = kNaluUnset;
81 insertStartCode = false;
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000082 memset(&codecSpecificHeader, 0, sizeof(RTPVideoHeader));
83}
84
niklase@google.com470e71d2011-07-07 08:21:25 +000085void VCMPacket::CopyCodecSpecifics(const RTPVideoHeader& videoHeader)
86{
niklase@google.com470e71d2011-07-07 08:21:25 +000087 switch(videoHeader.codec)
88 {
89 case kRTPVideoVP8:
90 {
holmer@google.com155188c2011-08-15 09:21:27 +000091 // Handle all packets within a frame as depending on the previous packet
92 // TODO(holmer): This should be changed to make fragments independent
93 // when the VP8 RTP receiver supports fragments.
94 if (isFirstPacket && markerBit)
95 completeNALU = kNaluComplete;
96 else if (isFirstPacket)
97 completeNALU = kNaluStart;
98 else if (markerBit)
99 completeNALU = kNaluEnd;
100 else
101 completeNALU = kNaluIncomplete;
102
niklase@google.com470e71d2011-07-07 08:21:25 +0000103 codec = kVideoCodecVP8;
104 break;
105 }
106 case kRTPVideoI420:
107 {
108 codec = kVideoCodecI420;
109 break;
110 }
111 default:
112 {
113 codec = kVideoCodecUnknown;
114 break;
115 }
116 }
117}
118
119}