blob: c1f1a048e8f4f99c23f8eaf7a777141cb1204cb2 [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,
stefan@webrtc.org3417eb42013-05-21 15:25:53 +000038 const uint32_t size,
39 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
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000060VCMPacket::VCMPacket(const uint8_t* ptr, uint32_t size, uint16_t seq, uint32_t ts, bool mBit) :
niklase@google.com470e71d2011-07-07 08:21:25 +000061 payloadType(0),
62 timestamp(ts),
wu@webrtc.org6c75c982014-04-15 17:46:33 +000063 ntp_time_ms_(0),
niklase@google.com470e71d2011-07-07 08:21:25 +000064 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),
stefan@webrtc.org3417eb42013-05-21 15:25:53 +000074 width(0),
75 height(0),
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000076 codecSpecificHeader()
niklase@google.com470e71d2011-07-07 08:21:25 +000077{}
78
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000079void VCMPacket::Reset() {
80 payloadType = 0;
81 timestamp = 0;
wu@webrtc.org6c75c982014-04-15 17:46:33 +000082 ntp_time_ms_ = 0;
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000083 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;
stefan@webrtc.org3417eb42013-05-21 15:25:53 +000092 width = 0;
93 height = 0;
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000094 memset(&codecSpecificHeader, 0, sizeof(RTPVideoHeader));
95}
96
niklase@google.com470e71d2011-07-07 08:21:25 +000097void VCMPacket::CopyCodecSpecifics(const RTPVideoHeader& videoHeader)
98{
niklase@google.com470e71d2011-07-07 08:21:25 +000099 switch(videoHeader.codec)
100 {
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000101 case kRtpVideoVp8:
niklase@google.com470e71d2011-07-07 08:21:25 +0000102 {
holmer@google.com155188c2011-08-15 09:21:27 +0000103 // Handle all packets within a frame as depending on the previous packet
104 // TODO(holmer): This should be changed to make fragments independent
105 // when the VP8 RTP receiver supports fragments.
106 if (isFirstPacket && markerBit)
107 completeNALU = kNaluComplete;
108 else if (isFirstPacket)
109 completeNALU = kNaluStart;
110 else if (markerBit)
111 completeNALU = kNaluEnd;
112 else
113 completeNALU = kNaluIncomplete;
114
niklase@google.com470e71d2011-07-07 08:21:25 +0000115 codec = kVideoCodecVP8;
116 break;
117 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000118 default:
119 {
120 codec = kVideoCodecUnknown;
121 break;
122 }
123 }
124}
125
126}