| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/modules/video_coding/frame_buffer.h" | 11 #include "webrtc/modules/video_coding/frame_buffer.h" |
| 12 | 12 |
| 13 #include <assert.h> | 13 #include <assert.h> |
| 14 #include <string.h> | 14 #include <string.h> |
| 15 | 15 |
| 16 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
| 17 #include "webrtc/base/logging.h" | 17 #include "webrtc/base/logging.h" |
| 18 #include "webrtc/base/trace_event.h" |
| 18 #include "webrtc/modules/video_coding/packet.h" | 19 #include "webrtc/modules/video_coding/packet.h" |
| 19 | 20 |
| 20 namespace webrtc { | 21 namespace webrtc { |
| 21 | 22 |
| 22 VCMFrameBuffer::VCMFrameBuffer() | 23 VCMFrameBuffer::VCMFrameBuffer() |
| 23 : _state(kStateEmpty), _nackCount(0), _latestPacketTimeMs(-1) {} | 24 : _state(kStateEmpty), _nackCount(0), _latestPacketTimeMs(-1) {} |
| 24 | 25 |
| 25 VCMFrameBuffer::~VCMFrameBuffer() {} | 26 VCMFrameBuffer::~VCMFrameBuffer() {} |
| 26 | 27 |
| 27 VCMFrameBuffer::VCMFrameBuffer(const VCMFrameBuffer& rhs) | 28 VCMFrameBuffer::VCMFrameBuffer(const VCMFrameBuffer& rhs) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 65 |
| 65 bool VCMFrameBuffer::NonReference() const { | 66 bool VCMFrameBuffer::NonReference() const { |
| 66 return _sessionInfo.NonReference(); | 67 return _sessionInfo.NonReference(); |
| 67 } | 68 } |
| 68 | 69 |
| 69 std::vector<NaluInfo> VCMFrameBuffer::GetNaluInfos() const { | 70 std::vector<NaluInfo> VCMFrameBuffer::GetNaluInfos() const { |
| 70 return _sessionInfo.GetNaluInfos(); | 71 return _sessionInfo.GetNaluInfos(); |
| 71 } | 72 } |
| 72 | 73 |
| 73 void VCMFrameBuffer::SetGofInfo(const GofInfoVP9& gof_info, size_t idx) { | 74 void VCMFrameBuffer::SetGofInfo(const GofInfoVP9& gof_info, size_t idx) { |
| 75 TRACE_EVENT0("webrtc", "VCMFrameBuffer::SetGofInfo"); |
| 74 _sessionInfo.SetGofInfo(gof_info, idx); | 76 _sessionInfo.SetGofInfo(gof_info, idx); |
| 75 // TODO(asapersson): Consider adding hdr->VP9.ref_picture_id for testing. | 77 // TODO(asapersson): Consider adding hdr->VP9.ref_picture_id for testing. |
| 76 _codecSpecificInfo.codecSpecific.VP9.temporal_idx = | 78 _codecSpecificInfo.codecSpecific.VP9.temporal_idx = |
| 77 gof_info.temporal_idx[idx]; | 79 gof_info.temporal_idx[idx]; |
| 78 _codecSpecificInfo.codecSpecific.VP9.temporal_up_switch = | 80 _codecSpecificInfo.codecSpecific.VP9.temporal_up_switch = |
| 79 gof_info.temporal_up_switch[idx]; | 81 gof_info.temporal_up_switch[idx]; |
| 80 } | 82 } |
| 81 | 83 |
| 82 bool VCMFrameBuffer::IsSessionComplete() const { | 84 bool VCMFrameBuffer::IsSessionComplete() const { |
| 85 TRACE_EVENT0("webrtc", "VCMFrameBuffer::IsSessionComplete"); |
| 83 return _sessionInfo.complete(); | 86 return _sessionInfo.complete(); |
| 84 } | 87 } |
| 85 | 88 |
| 86 // Insert packet | 89 // Insert packet |
| 87 VCMFrameBufferEnum VCMFrameBuffer::InsertPacket( | 90 VCMFrameBufferEnum VCMFrameBuffer::InsertPacket( |
| 88 const VCMPacket& packet, | 91 const VCMPacket& packet, |
| 89 int64_t timeInMs, | 92 int64_t timeInMs, |
| 90 VCMDecodeErrorMode decode_error_mode, | 93 VCMDecodeErrorMode decode_error_mode, |
| 91 const FrameData& frame_data) { | 94 const FrameData& frame_data) { |
| 95 TRACE_EVENT0("webrtc", "VCMFrameBuffer::InsertPacket"); |
| 92 assert(!(NULL == packet.dataPtr && packet.sizeBytes > 0)); | 96 assert(!(NULL == packet.dataPtr && packet.sizeBytes > 0)); |
| 93 if (packet.dataPtr != NULL) { | 97 if (packet.dataPtr != NULL) { |
| 94 _payloadType = packet.payloadType; | 98 _payloadType = packet.payloadType; |
| 95 } | 99 } |
| 96 | 100 |
| 97 if (kStateEmpty == _state) { | 101 if (kStateEmpty == _state) { |
| 98 // First packet (empty and/or media) inserted into this frame. | 102 // First packet (empty and/or media) inserted into this frame. |
| 99 // store some info and set some initial values. | 103 // store some info and set some initial values. |
| 100 _timeStamp = packet.timestamp; | 104 _timeStamp = packet.timestamp; |
| 101 // We only take the ntp timestamp of the first packet of a frame. | 105 // We only take the ntp timestamp of the first packet of a frame. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 SetState(kStateComplete); | 173 SetState(kStateComplete); |
| 170 return kCompleteSession; | 174 return kCompleteSession; |
| 171 } else if (_sessionInfo.decodable()) { | 175 } else if (_sessionInfo.decodable()) { |
| 172 SetState(kStateDecodable); | 176 SetState(kStateDecodable); |
| 173 return kDecodableSession; | 177 return kDecodableSession; |
| 174 } | 178 } |
| 175 return kIncomplete; | 179 return kIncomplete; |
| 176 } | 180 } |
| 177 | 181 |
| 178 int64_t VCMFrameBuffer::LatestPacketTimeMs() const { | 182 int64_t VCMFrameBuffer::LatestPacketTimeMs() const { |
| 183 TRACE_EVENT0("webrtc", "VCMFrameBuffer::LatestPacketTimeMs"); |
| 179 return _latestPacketTimeMs; | 184 return _latestPacketTimeMs; |
| 180 } | 185 } |
| 181 | 186 |
| 182 void VCMFrameBuffer::IncrementNackCount() { | 187 void VCMFrameBuffer::IncrementNackCount() { |
| 188 TRACE_EVENT0("webrtc", "VCMFrameBuffer::IncrementNackCount"); |
| 183 _nackCount++; | 189 _nackCount++; |
| 184 } | 190 } |
| 185 | 191 |
| 186 int16_t VCMFrameBuffer::GetNackCount() const { | 192 int16_t VCMFrameBuffer::GetNackCount() const { |
| 193 TRACE_EVENT0("webrtc", "VCMFrameBuffer::GetNackCount"); |
| 187 return _nackCount; | 194 return _nackCount; |
| 188 } | 195 } |
| 189 | 196 |
| 190 bool VCMFrameBuffer::HaveFirstPacket() const { | 197 bool VCMFrameBuffer::HaveFirstPacket() const { |
| 198 TRACE_EVENT0("webrtc", "VCMFrameBuffer::HaveFirstPacket"); |
| 191 return _sessionInfo.HaveFirstPacket(); | 199 return _sessionInfo.HaveFirstPacket(); |
| 192 } | 200 } |
| 193 | 201 |
| 194 bool VCMFrameBuffer::HaveLastPacket() const { | 202 bool VCMFrameBuffer::HaveLastPacket() const { |
| 203 TRACE_EVENT0("webrtc", "VCMFrameBuffer::HaveLastPacket"); |
| 195 return _sessionInfo.HaveLastPacket(); | 204 return _sessionInfo.HaveLastPacket(); |
| 196 } | 205 } |
| 197 | 206 |
| 198 int VCMFrameBuffer::NumPackets() const { | 207 int VCMFrameBuffer::NumPackets() const { |
| 208 TRACE_EVENT0("webrtc", "VCMFrameBuffer::NumPackets"); |
| 199 return _sessionInfo.NumPackets(); | 209 return _sessionInfo.NumPackets(); |
| 200 } | 210 } |
| 201 | 211 |
| 202 void VCMFrameBuffer::Reset() { | 212 void VCMFrameBuffer::Reset() { |
| 213 TRACE_EVENT0("webrtc", "VCMFrameBuffer::Reset"); |
| 203 _length = 0; | 214 _length = 0; |
| 204 _timeStamp = 0; | 215 _timeStamp = 0; |
| 205 _sessionInfo.Reset(); | 216 _sessionInfo.Reset(); |
| 206 _payloadType = 0; | 217 _payloadType = 0; |
| 207 _nackCount = 0; | 218 _nackCount = 0; |
| 208 _latestPacketTimeMs = -1; | 219 _latestPacketTimeMs = -1; |
| 209 _state = kStateEmpty; | 220 _state = kStateEmpty; |
| 210 VCMEncodedFrame::Reset(); | 221 VCMEncodedFrame::Reset(); |
| 211 } | 222 } |
| 212 | 223 |
| 213 // Set state of frame | 224 // Set state of frame |
| 214 void VCMFrameBuffer::SetState(VCMFrameBufferStateEnum state) { | 225 void VCMFrameBuffer::SetState(VCMFrameBufferStateEnum state) { |
| 226 TRACE_EVENT0("webrtc", "VCMFrameBuffer::SetState"); |
| 215 if (_state == state) { | 227 if (_state == state) { |
| 216 return; | 228 return; |
| 217 } | 229 } |
| 218 switch (state) { | 230 switch (state) { |
| 219 case kStateIncomplete: | 231 case kStateIncomplete: |
| 220 // we can go to this state from state kStateEmpty | 232 // we can go to this state from state kStateEmpty |
| 221 assert(_state == kStateEmpty); | 233 assert(_state == kStateEmpty); |
| 222 | 234 |
| 223 // Do nothing, we received a packet | 235 // Do nothing, we received a packet |
| 224 break; | 236 break; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 241 _state = state; | 253 _state = state; |
| 242 } | 254 } |
| 243 | 255 |
| 244 // Get current state of frame | 256 // Get current state of frame |
| 245 VCMFrameBufferStateEnum VCMFrameBuffer::GetState() const { | 257 VCMFrameBufferStateEnum VCMFrameBuffer::GetState() const { |
| 246 return _state; | 258 return _state; |
| 247 } | 259 } |
| 248 | 260 |
| 249 // Get current state of frame | 261 // Get current state of frame |
| 250 VCMFrameBufferStateEnum VCMFrameBuffer::GetState(uint32_t& timeStamp) const { | 262 VCMFrameBufferStateEnum VCMFrameBuffer::GetState(uint32_t& timeStamp) const { |
| 263 TRACE_EVENT0("webrtc", "VCMFrameBuffer::GetState"); |
| 251 timeStamp = TimeStamp(); | 264 timeStamp = TimeStamp(); |
| 252 return GetState(); | 265 return GetState(); |
| 253 } | 266 } |
| 254 | 267 |
| 255 bool VCMFrameBuffer::IsRetransmitted() const { | 268 bool VCMFrameBuffer::IsRetransmitted() const { |
| 256 return _sessionInfo.session_nack(); | 269 return _sessionInfo.session_nack(); |
| 257 } | 270 } |
| 258 | 271 |
| 259 void VCMFrameBuffer::PrepareForDecode(bool continuous) { | 272 void VCMFrameBuffer::PrepareForDecode(bool continuous) { |
| 273 TRACE_EVENT0("webrtc", "VCMFrameBuffer::PrepareForDecode"); |
| 260 size_t bytes_removed = _sessionInfo.MakeDecodable(); | 274 size_t bytes_removed = _sessionInfo.MakeDecodable(); |
| 261 _length -= bytes_removed; | 275 _length -= bytes_removed; |
| 262 // Transfer frame information to EncodedFrame and create any codec | 276 // Transfer frame information to EncodedFrame and create any codec |
| 263 // specific information. | 277 // specific information. |
| 264 _frameType = _sessionInfo.FrameType(); | 278 _frameType = _sessionInfo.FrameType(); |
| 265 _completeFrame = _sessionInfo.complete(); | 279 _completeFrame = _sessionInfo.complete(); |
| 266 _missingFrame = !continuous; | 280 _missingFrame = !continuous; |
| 267 } | 281 } |
| 268 | 282 |
| 269 } // namespace webrtc | 283 } // namespace webrtc |
| OLD | NEW |