61ef2ee859af2265c23c0f628edd970e7d106ef6
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / modules / video_coding / main / source / packet.cc
1 /*
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 "webrtc/modules/interface/module_common_types.h"
12 #include "webrtc/modules/video_coding/main/source/packet.h"
13
14 #include <assert.h>
15
16 namespace webrtc {
17
18 VCMPacket::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),
31     width(0),
32     height(0),
33     codecSpecificHeader() {
34 }
35
36 VCMPacket::VCMPacket(const uint8_t* ptr,
37                      const uint32_t size,
38                      const WebRtcRTPHeader& rtpHeader) :
39     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),
51     width(rtpHeader.type.Video.width),
52     height(rtpHeader.type.Video.height),
53     codecSpecificHeader(rtpHeader.type.Video)
54 {
55     CopyCodecSpecifics(rtpHeader.type.Video);
56 }
57
58 VCMPacket::VCMPacket(const uint8_t* ptr, uint32_t size, uint16_t seq, uint32_t ts, bool mBit) :
59     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),
71     width(0),
72     height(0),
73     codecSpecificHeader()
74 {}
75
76 void 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;
88   width = 0;
89   height = 0;
90   memset(&codecSpecificHeader, 0, sizeof(RTPVideoHeader));
91 }
92
93 void VCMPacket::CopyCodecSpecifics(const RTPVideoHeader& videoHeader)
94 {
95     switch(videoHeader.codec)
96     {
97         case kRtpVideoVp8:
98             {
99                 // 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
111                 codec = kVideoCodecVP8;
112                 break;
113             }
114         default:
115             {
116                 codec = kVideoCodecUnknown;
117                 break;
118             }
119     }
120 }
121
122 }