blob: ad69418be09bcaf0adb7e54ac6fc9ad678cbc5bd [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),
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.org3417eb42013-05-21 15:25:53 +000031 width(0),
32 height(0),
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000033 codecSpecificHeader() {
34}
35
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000036VCMPacket::VCMPacket(const uint8_t* ptr,
stefan@webrtc.org3417eb42013-05-21 15:25:53 +000037 const uint32_t size,
38 const WebRtcRTPHeader& rtpHeader) :
niklase@google.com470e71d2011-07-07 08:21:25 +000039 payloadType(rtpHeader.header.payloadType),
40 timestamp(rtpHeader.header.timestamp),
41 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
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000058VCMPacket::VCMPacket(const uint8_t* ptr, uint32_t size, uint16_t seq, uint32_t ts, bool mBit) :
niklase@google.com470e71d2011-07-07 08:21:25 +000059 payloadType(0),
60 timestamp(ts),
61 seqNum(seq),
62 dataPtr(ptr),
63 sizeBytes(size),
64 markerBit(mBit),
65
66 frameType(kVideoFrameDelta),
67 codec(kVideoCodecUnknown),
68 isFirstPacket(false),
69 completeNALU(kNaluComplete),
70 insertStartCode(false),
stefan@webrtc.org3417eb42013-05-21 15:25:53 +000071 width(0),
72 height(0),
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000073 codecSpecificHeader()
niklase@google.com470e71d2011-07-07 08:21:25 +000074{}
75
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000076void VCMPacket::Reset() {
77 payloadType = 0;
78 timestamp = 0;
79 seqNum = 0;
80 dataPtr = NULL;
81 sizeBytes = 0;
82 markerBit = false;
83 frameType = kFrameEmpty;
84 codec = kVideoCodecUnknown;
85 isFirstPacket = false;
86 completeNALU = kNaluUnset;
87 insertStartCode = false;
stefan@webrtc.org3417eb42013-05-21 15:25:53 +000088 width = 0;
89 height = 0;
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000090 memset(&codecSpecificHeader, 0, sizeof(RTPVideoHeader));
91}
92
niklase@google.com470e71d2011-07-07 08:21:25 +000093void VCMPacket::CopyCodecSpecifics(const RTPVideoHeader& videoHeader)
94{
niklase@google.com470e71d2011-07-07 08:21:25 +000095 switch(videoHeader.codec)
96 {
wu@webrtc.org822fbd82013-08-15 23:38:54 +000097 case kRtpVideoVp8:
niklase@google.com470e71d2011-07-07 08:21:25 +000098 {
holmer@google.com155188c2011-08-15 09:21:27 +000099 // Handle all packets within a frame as depending on the previous packet
100 // TODO(holmer): This should be changed to make fragments independent
101 // when the VP8 RTP receiver supports fragments.
102 if (isFirstPacket && markerBit)
103 completeNALU = kNaluComplete;
104 else if (isFirstPacket)
105 completeNALU = kNaluStart;
106 else if (markerBit)
107 completeNALU = kNaluEnd;
108 else
109 completeNALU = kNaluIncomplete;
110
niklase@google.com470e71d2011-07-07 08:21:25 +0000111 codec = kVideoCodecVP8;
112 break;
113 }
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000114 case kRtpVideoI420:
niklase@google.com470e71d2011-07-07 08:21:25 +0000115 {
116 codec = kVideoCodecI420;
117 break;
118 }
119 default:
120 {
121 codec = kVideoCodecUnknown;
122 break;
123 }
124 }
125}
126
127}