| 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 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 if (packets_.empty()) | 53 if (packets_.empty()) |
| 54 return empty_seq_num_high_; | 54 return empty_seq_num_high_; |
| 55 if (empty_seq_num_high_ == -1) | 55 if (empty_seq_num_high_ == -1) |
| 56 return packets_.back().seqNum; | 56 return packets_.back().seqNum; |
| 57 return LatestSequenceNumber(packets_.back().seqNum, empty_seq_num_high_); | 57 return LatestSequenceNumber(packets_.back().seqNum, empty_seq_num_high_); |
| 58 } | 58 } |
| 59 | 59 |
| 60 int VCMSessionInfo::PictureId() const { | 60 int VCMSessionInfo::PictureId() const { |
| 61 if (packets_.empty()) | 61 if (packets_.empty()) |
| 62 return kNoPictureId; | 62 return kNoPictureId; |
| 63 if (packets_.front().codecSpecificHeader.codec == kRtpVideoVp8) { | 63 if (packets_.front().video_header.codec == kRtpVideoVp8) { |
| 64 return packets_.front().codecSpecificHeader.codecHeader.VP8.pictureId; | 64 return packets_.front().video_header.codecHeader.VP8.pictureId; |
| 65 } else if (packets_.front().codecSpecificHeader.codec == kRtpVideoVp9) { | 65 } else if (packets_.front().video_header.codec == kRtpVideoVp9) { |
| 66 return packets_.front().codecSpecificHeader.codecHeader.VP9.picture_id; | 66 return packets_.front().video_header.codecHeader.VP9.picture_id; |
| 67 } else { | 67 } else { |
| 68 return kNoPictureId; | 68 return kNoPictureId; |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 | 71 |
| 72 int VCMSessionInfo::TemporalId() const { | 72 int VCMSessionInfo::TemporalId() const { |
| 73 if (packets_.empty()) | 73 if (packets_.empty()) |
| 74 return kNoTemporalIdx; | 74 return kNoTemporalIdx; |
| 75 if (packets_.front().codecSpecificHeader.codec == kRtpVideoVp8) { | 75 if (packets_.front().video_header.codec == kRtpVideoVp8) { |
| 76 return packets_.front().codecSpecificHeader.codecHeader.VP8.temporalIdx; | 76 return packets_.front().video_header.codecHeader.VP8.temporalIdx; |
| 77 } else if (packets_.front().codecSpecificHeader.codec == kRtpVideoVp9) { | 77 } else if (packets_.front().video_header.codec == kRtpVideoVp9) { |
| 78 return packets_.front().codecSpecificHeader.codecHeader.VP9.temporal_idx; | 78 return packets_.front().video_header.codecHeader.VP9.temporal_idx; |
| 79 } else { | 79 } else { |
| 80 return kNoTemporalIdx; | 80 return kNoTemporalIdx; |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 | 83 |
| 84 bool VCMSessionInfo::LayerSync() const { | 84 bool VCMSessionInfo::LayerSync() const { |
| 85 if (packets_.empty()) | 85 if (packets_.empty()) |
| 86 return false; | 86 return false; |
| 87 if (packets_.front().codecSpecificHeader.codec == kRtpVideoVp8) { | 87 if (packets_.front().video_header.codec == kRtpVideoVp8) { |
| 88 return packets_.front().codecSpecificHeader.codecHeader.VP8.layerSync; | 88 return packets_.front().video_header.codecHeader.VP8.layerSync; |
| 89 } else if (packets_.front().codecSpecificHeader.codec == kRtpVideoVp9) { | 89 } else if (packets_.front().video_header.codec == kRtpVideoVp9) { |
| 90 return packets_.front() | 90 return packets_.front().video_header.codecHeader.VP9.temporal_up_switch; |
| 91 .codecSpecificHeader.codecHeader.VP9.temporal_up_switch; | |
| 92 } else { | 91 } else { |
| 93 return false; | 92 return false; |
| 94 } | 93 } |
| 95 } | 94 } |
| 96 | 95 |
| 97 int VCMSessionInfo::Tl0PicId() const { | 96 int VCMSessionInfo::Tl0PicId() const { |
| 98 if (packets_.empty()) | 97 if (packets_.empty()) |
| 99 return kNoTl0PicIdx; | 98 return kNoTl0PicIdx; |
| 100 if (packets_.front().codecSpecificHeader.codec == kRtpVideoVp8) { | 99 if (packets_.front().video_header.codec == kRtpVideoVp8) { |
| 101 return packets_.front().codecSpecificHeader.codecHeader.VP8.tl0PicIdx; | 100 return packets_.front().video_header.codecHeader.VP8.tl0PicIdx; |
| 102 } else if (packets_.front().codecSpecificHeader.codec == kRtpVideoVp9) { | 101 } else if (packets_.front().video_header.codec == kRtpVideoVp9) { |
| 103 return packets_.front().codecSpecificHeader.codecHeader.VP9.tl0_pic_idx; | 102 return packets_.front().video_header.codecHeader.VP9.tl0_pic_idx; |
| 104 } else { | 103 } else { |
| 105 return kNoTl0PicIdx; | 104 return kNoTl0PicIdx; |
| 106 } | 105 } |
| 107 } | 106 } |
| 108 | 107 |
| 109 bool VCMSessionInfo::NonReference() const { | 108 bool VCMSessionInfo::NonReference() const { |
| 110 if (packets_.empty() || | 109 if (packets_.empty() || packets_.front().video_header.codec != kRtpVideoVp8) |
| 111 packets_.front().codecSpecificHeader.codec != kRtpVideoVp8) | |
| 112 return false; | 110 return false; |
| 113 return packets_.front().codecSpecificHeader.codecHeader.VP8.nonReference; | 111 return packets_.front().video_header.codecHeader.VP8.nonReference; |
| 114 } | 112 } |
| 115 | 113 |
| 116 void VCMSessionInfo::SetGofInfo(const GofInfoVP9& gof_info, size_t idx) { | 114 void VCMSessionInfo::SetGofInfo(const GofInfoVP9& gof_info, size_t idx) { |
| 117 if (packets_.empty() || | 115 if (packets_.empty() || packets_.front().video_header.codec != kRtpVideoVp9 || |
| 118 packets_.front().codecSpecificHeader.codec != kRtpVideoVp9 || | 116 packets_.front().video_header.codecHeader.VP9.flexible_mode) { |
| 119 packets_.front().codecSpecificHeader.codecHeader.VP9.flexible_mode) { | |
| 120 return; | 117 return; |
| 121 } | 118 } |
| 122 packets_.front().codecSpecificHeader.codecHeader.VP9.temporal_idx = | 119 packets_.front().video_header.codecHeader.VP9.temporal_idx = |
| 123 gof_info.temporal_idx[idx]; | 120 gof_info.temporal_idx[idx]; |
| 124 packets_.front().codecSpecificHeader.codecHeader.VP9.temporal_up_switch = | 121 packets_.front().video_header.codecHeader.VP9.temporal_up_switch = |
| 125 gof_info.temporal_up_switch[idx]; | 122 gof_info.temporal_up_switch[idx]; |
| 126 packets_.front().codecSpecificHeader.codecHeader.VP9.num_ref_pics = | 123 packets_.front().video_header.codecHeader.VP9.num_ref_pics = |
| 127 gof_info.num_ref_pics[idx]; | 124 gof_info.num_ref_pics[idx]; |
| 128 for (uint8_t i = 0; i < gof_info.num_ref_pics[idx]; ++i) { | 125 for (uint8_t i = 0; i < gof_info.num_ref_pics[idx]; ++i) { |
| 129 packets_.front().codecSpecificHeader.codecHeader.VP9.pid_diff[i] = | 126 packets_.front().video_header.codecHeader.VP9.pid_diff[i] = |
| 130 gof_info.pid_diff[idx][i]; | 127 gof_info.pid_diff[idx][i]; |
| 131 } | 128 } |
| 132 } | 129 } |
| 133 | 130 |
| 134 void VCMSessionInfo::Reset() { | 131 void VCMSessionInfo::Reset() { |
| 135 session_nack_ = false; | 132 session_nack_ = false; |
| 136 complete_ = false; | 133 complete_ = false; |
| 137 decodable_ = false; | 134 decodable_ = false; |
| 138 frame_type_ = kVideoFrameDelta; | 135 frame_type_ = kVideoFrameDelta; |
| 139 packets_.clear(); | 136 packets_.clear(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 168 // frame buffer. | 165 // frame buffer. |
| 169 const uint8_t* packet_buffer = packet.dataPtr; | 166 const uint8_t* packet_buffer = packet.dataPtr; |
| 170 packet.dataPtr = frame_buffer + offset; | 167 packet.dataPtr = frame_buffer + offset; |
| 171 | 168 |
| 172 // We handle H.264 STAP-A packets in a special way as we need to remove the | 169 // We handle H.264 STAP-A packets in a special way as we need to remove the |
| 173 // two length bytes between each NAL unit, and potentially add start codes. | 170 // two length bytes between each NAL unit, and potentially add start codes. |
| 174 // TODO(pbos): Remove H264 parsing from this step and use a fragmentation | 171 // TODO(pbos): Remove H264 parsing from this step and use a fragmentation |
| 175 // header supplied by the H264 depacketizer. | 172 // header supplied by the H264 depacketizer. |
| 176 const size_t kH264NALHeaderLengthInBytes = 1; | 173 const size_t kH264NALHeaderLengthInBytes = 1; |
| 177 const size_t kLengthFieldLength = 2; | 174 const size_t kLengthFieldLength = 2; |
| 178 if (packet.codecSpecificHeader.codec == kRtpVideoH264 && | 175 if (packet.video_header.codec == kRtpVideoH264 && |
| 179 packet.codecSpecificHeader.codecHeader.H264.packetization_type == | 176 packet.video_header.codecHeader.H264.packetization_type == kH264StapA) { |
| 180 kH264StapA) { | |
| 181 size_t required_length = 0; | 177 size_t required_length = 0; |
| 182 const uint8_t* nalu_ptr = packet_buffer + kH264NALHeaderLengthInBytes; | 178 const uint8_t* nalu_ptr = packet_buffer + kH264NALHeaderLengthInBytes; |
| 183 while (nalu_ptr < packet_buffer + packet.sizeBytes) { | 179 while (nalu_ptr < packet_buffer + packet.sizeBytes) { |
| 184 size_t length = BufferToUWord16(nalu_ptr); | 180 size_t length = BufferToUWord16(nalu_ptr); |
| 185 required_length += | 181 required_length += |
| 186 length + (packet.insertStartCode ? kH264StartCodeLengthBytes : 0); | 182 length + (packet.insertStartCode ? kH264StartCodeLengthBytes : 0); |
| 187 nalu_ptr += kLengthFieldLength + length; | 183 nalu_ptr += kLengthFieldLength + length; |
| 188 } | 184 } |
| 189 ShiftSubsequentPackets(packet_it, required_length); | 185 ShiftSubsequentPackets(packet_it, required_length); |
| 190 nalu_ptr = packet_buffer + kH264NALHeaderLengthInBytes; | 186 nalu_ptr = packet_buffer + kH264NALHeaderLengthInBytes; |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 size_t new_length = 0; | 333 size_t new_length = 0; |
| 338 // Allocate space for max number of partitions | 334 // Allocate space for max number of partitions |
| 339 fragmentation->VerifyAndAllocateFragmentationHeader(kMaxVP8Partitions); | 335 fragmentation->VerifyAndAllocateFragmentationHeader(kMaxVP8Partitions); |
| 340 fragmentation->fragmentationVectorSize = 0; | 336 fragmentation->fragmentationVectorSize = 0; |
| 341 memset(fragmentation->fragmentationLength, 0, | 337 memset(fragmentation->fragmentationLength, 0, |
| 342 kMaxVP8Partitions * sizeof(size_t)); | 338 kMaxVP8Partitions * sizeof(size_t)); |
| 343 if (packets_.empty()) | 339 if (packets_.empty()) |
| 344 return new_length; | 340 return new_length; |
| 345 PacketIterator it = FindNextPartitionBeginning(packets_.begin()); | 341 PacketIterator it = FindNextPartitionBeginning(packets_.begin()); |
| 346 while (it != packets_.end()) { | 342 while (it != packets_.end()) { |
| 347 const int partition_id = | 343 const int partition_id = (*it).video_header.codecHeader.VP8.partitionId; |
| 348 (*it).codecSpecificHeader.codecHeader.VP8.partitionId; | |
| 349 PacketIterator partition_end = FindPartitionEnd(it); | 344 PacketIterator partition_end = FindPartitionEnd(it); |
| 350 fragmentation->fragmentationOffset[partition_id] = | 345 fragmentation->fragmentationOffset[partition_id] = |
| 351 (*it).dataPtr - frame_buffer; | 346 (*it).dataPtr - frame_buffer; |
| 352 assert(fragmentation->fragmentationOffset[partition_id] < | 347 assert(fragmentation->fragmentationOffset[partition_id] < |
| 353 frame_buffer_length); | 348 frame_buffer_length); |
| 354 fragmentation->fragmentationLength[partition_id] = | 349 fragmentation->fragmentationLength[partition_id] = |
| 355 (*partition_end).dataPtr + (*partition_end).sizeBytes - (*it).dataPtr; | 350 (*partition_end).dataPtr + (*partition_end).sizeBytes - (*it).dataPtr; |
| 356 assert(fragmentation->fragmentationLength[partition_id] <= | 351 assert(fragmentation->fragmentationLength[partition_id] <= |
| 357 frame_buffer_length); | 352 frame_buffer_length); |
| 358 new_length += fragmentation->fragmentationLength[partition_id]; | 353 new_length += fragmentation->fragmentationLength[partition_id]; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 374 fragmentation->fragmentationOffset[i] >= | 369 fragmentation->fragmentationOffset[i] >= |
| 375 fragmentation->fragmentationOffset[i - 1]); | 370 fragmentation->fragmentationOffset[i - 1]); |
| 376 } | 371 } |
| 377 assert(new_length <= frame_buffer_length); | 372 assert(new_length <= frame_buffer_length); |
| 378 return new_length; | 373 return new_length; |
| 379 } | 374 } |
| 380 | 375 |
| 381 VCMSessionInfo::PacketIterator VCMSessionInfo::FindNextPartitionBeginning( | 376 VCMSessionInfo::PacketIterator VCMSessionInfo::FindNextPartitionBeginning( |
| 382 PacketIterator it) const { | 377 PacketIterator it) const { |
| 383 while (it != packets_.end()) { | 378 while (it != packets_.end()) { |
| 384 if ((*it).codecSpecificHeader.codecHeader.VP8.beginningOfPartition) { | 379 if ((*it).video_header.codecHeader.VP8.beginningOfPartition) { |
| 385 return it; | 380 return it; |
| 386 } | 381 } |
| 387 ++it; | 382 ++it; |
| 388 } | 383 } |
| 389 return it; | 384 return it; |
| 390 } | 385 } |
| 391 | 386 |
| 392 VCMSessionInfo::PacketIterator VCMSessionInfo::FindPartitionEnd( | 387 VCMSessionInfo::PacketIterator VCMSessionInfo::FindPartitionEnd( |
| 393 PacketIterator it) const { | 388 PacketIterator it) const { |
| 394 assert((*it).codec == kVideoCodecVP8); | 389 assert((*it).codec == kVideoCodecVP8); |
| 395 PacketIterator prev_it = it; | 390 PacketIterator prev_it = it; |
| 396 const int partition_id = | 391 const int partition_id = (*it).video_header.codecHeader.VP8.partitionId; |
| 397 (*it).codecSpecificHeader.codecHeader.VP8.partitionId; | |
| 398 while (it != packets_.end()) { | 392 while (it != packets_.end()) { |
| 399 bool beginning = | 393 bool beginning = (*it).video_header.codecHeader.VP8.beginningOfPartition; |
| 400 (*it).codecSpecificHeader.codecHeader.VP8.beginningOfPartition; | 394 int current_partition_id = (*it).video_header.codecHeader.VP8.partitionId; |
| 401 int current_partition_id = | |
| 402 (*it).codecSpecificHeader.codecHeader.VP8.partitionId; | |
| 403 bool packet_loss_found = (!beginning && !InSequence(it, prev_it)); | 395 bool packet_loss_found = (!beginning && !InSequence(it, prev_it)); |
| 404 if (packet_loss_found || | 396 if (packet_loss_found || |
| 405 (beginning && current_partition_id != partition_id)) { | 397 (beginning && current_partition_id != partition_id)) { |
| 406 // Missing packet, the previous packet was the last in sequence. | 398 // Missing packet, the previous packet was the last in sequence. |
| 407 return prev_it; | 399 return prev_it; |
| 408 } | 400 } |
| 409 prev_it = it; | 401 prev_it = it; |
| 410 ++it; | 402 ++it; |
| 411 } | 403 } |
| 412 return prev_it; | 404 return prev_it; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 if (empty_seq_num_high_ == -1) | 552 if (empty_seq_num_high_ == -1) |
| 561 empty_seq_num_high_ = seq_num; | 553 empty_seq_num_high_ = seq_num; |
| 562 else | 554 else |
| 563 empty_seq_num_high_ = LatestSequenceNumber(seq_num, empty_seq_num_high_); | 555 empty_seq_num_high_ = LatestSequenceNumber(seq_num, empty_seq_num_high_); |
| 564 if (empty_seq_num_low_ == -1 || | 556 if (empty_seq_num_low_ == -1 || |
| 565 IsNewerSequenceNumber(empty_seq_num_low_, seq_num)) | 557 IsNewerSequenceNumber(empty_seq_num_low_, seq_num)) |
| 566 empty_seq_num_low_ = seq_num; | 558 empty_seq_num_low_ = seq_num; |
| 567 } | 559 } |
| 568 | 560 |
| 569 } // namespace webrtc | 561 } // namespace webrtc |
| OLD | NEW |