OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 DeltaSize delta_size = (delta >= 0 && delta <= 0xff) ? 1 : 2; | 359 DeltaSize delta_size = (delta >= 0 && delta <= 0xff) ? 1 : 2; |
360 if (!AddDeltaSize(delta_size)) | 360 if (!AddDeltaSize(delta_size)) |
361 return false; | 361 return false; |
362 | 362 |
363 packets_.emplace_back(sequence_number, delta); | 363 packets_.emplace_back(sequence_number, delta); |
364 last_timestamp_us_ += delta * kDeltaScaleFactor; | 364 last_timestamp_us_ += delta * kDeltaScaleFactor; |
365 size_bytes_ += delta_size; | 365 size_bytes_ += delta_size; |
366 return true; | 366 return true; |
367 } | 367 } |
368 | 368 |
| 369 const std::vector<TransportFeedback::ReceivedPacket>& |
| 370 TransportFeedback::GetReceivedPackets() const { |
| 371 return packets_; |
| 372 } |
| 373 |
369 uint16_t TransportFeedback::GetBaseSequence() const { | 374 uint16_t TransportFeedback::GetBaseSequence() const { |
370 return base_seq_no_; | 375 return base_seq_no_; |
371 } | 376 } |
372 | 377 |
373 std::vector<TransportFeedback::StatusSymbol> | 378 std::vector<TransportFeedback::StatusSymbol> |
374 TransportFeedback::GetStatusVector() const { | 379 TransportFeedback::GetStatusVector() const { |
375 std::vector<TransportFeedback::StatusSymbol> symbols; | 380 std::vector<TransportFeedback::StatusSymbol> symbols; |
376 uint16_t seq_no = GetBaseSequence(); | 381 uint16_t seq_no = GetBaseSequence(); |
377 for (const auto& packet : packets_) { | 382 for (const auto& packet : packets_) { |
378 for (; seq_no != packet.sequence_number; ++seq_no) | 383 for (; seq_no != packet.sequence_number(); ++seq_no) |
379 symbols.push_back(StatusSymbol::kNotReceived); | 384 symbols.push_back(StatusSymbol::kNotReceived); |
380 if (packet.delta_ticks >= 0x00 && packet.delta_ticks <= 0xff) { | 385 if (packet.delta_ticks() >= 0x00 && packet.delta_ticks() <= 0xff) { |
381 symbols.push_back(StatusSymbol::kReceivedSmallDelta); | 386 symbols.push_back(StatusSymbol::kReceivedSmallDelta); |
382 } else { | 387 } else { |
383 symbols.push_back(StatusSymbol::kReceivedLargeDelta); | 388 symbols.push_back(StatusSymbol::kReceivedLargeDelta); |
384 } | 389 } |
385 ++seq_no; | 390 ++seq_no; |
386 } | 391 } |
387 return symbols; | 392 return symbols; |
388 } | 393 } |
389 | 394 |
390 std::vector<int16_t> TransportFeedback::GetReceiveDeltas() const { | 395 std::vector<int16_t> TransportFeedback::GetReceiveDeltas() const { |
391 std::vector<int16_t> deltas; | 396 std::vector<int16_t> deltas; |
392 for (const auto& packet : packets_) | 397 for (const auto& packet : packets_) |
393 deltas.push_back(packet.delta_ticks); | 398 deltas.push_back(packet.delta_ticks()); |
394 return deltas; | 399 return deltas; |
395 } | 400 } |
396 | 401 |
397 int64_t TransportFeedback::GetBaseTimeUs() const { | 402 int64_t TransportFeedback::GetBaseTimeUs() const { |
398 return static_cast<int64_t>(base_time_ticks_) * kBaseScaleFactor; | 403 return static_cast<int64_t>(base_time_ticks_) * kBaseScaleFactor; |
399 } | 404 } |
400 | 405 |
401 std::vector<int64_t> TransportFeedback::GetReceiveDeltasUs() const { | 406 std::vector<int64_t> TransportFeedback::GetReceiveDeltasUs() const { |
402 std::vector<int64_t> us_deltas; | 407 std::vector<int64_t> us_deltas; |
403 for (const auto& packet : packets_) | 408 for (const auto& packet : packets_) |
404 us_deltas.push_back(packet.delta_ticks * kDeltaScaleFactor); | 409 us_deltas.push_back(packet.delta_us()); |
405 return us_deltas; | 410 return us_deltas; |
406 } | 411 } |
407 | 412 |
408 // De-serialize packet. | 413 // De-serialize packet. |
409 bool TransportFeedback::Parse(const CommonHeader& packet) { | 414 bool TransportFeedback::Parse(const CommonHeader& packet) { |
410 RTC_DCHECK_EQ(packet.type(), kPacketType); | 415 RTC_DCHECK_EQ(packet.type(), kPacketType); |
411 RTC_DCHECK_EQ(packet.fmt(), kFeedbackMessageType); | 416 RTC_DCHECK_EQ(packet.fmt(), kFeedbackMessageType); |
412 | 417 |
413 if (packet.payload_size_bytes() < kMinPayloadSizeBytes) { | 418 if (packet.payload_size_bytes() < kMinPayloadSizeBytes) { |
414 LOG(LS_WARNING) << "Buffer too small (" << packet.payload_size_bytes() | 419 LOG(LS_WARNING) << "Buffer too small (" << packet.payload_size_bytes() |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 } | 532 } |
528 int64_t timestamp_us = base_time_ticks_ * kBaseScaleFactor; | 533 int64_t timestamp_us = base_time_ticks_ * kBaseScaleFactor; |
529 auto packet_it = packets_.begin(); | 534 auto packet_it = packets_.begin(); |
530 uint16_t seq_no = base_seq_no_; | 535 uint16_t seq_no = base_seq_no_; |
531 for (DeltaSize delta_size : delta_sizes) { | 536 for (DeltaSize delta_size : delta_sizes) { |
532 if (delta_size > 0) { | 537 if (delta_size > 0) { |
533 if (packet_it == packets_.end()) { | 538 if (packet_it == packets_.end()) { |
534 LOG(LS_ERROR) << "Failed to find delta for seq_no " << seq_no; | 539 LOG(LS_ERROR) << "Failed to find delta for seq_no " << seq_no; |
535 return false; | 540 return false; |
536 } | 541 } |
537 if (packet_it->sequence_number != seq_no) { | 542 if (packet_it->sequence_number() != seq_no) { |
538 LOG(LS_ERROR) << "Expected to find delta for seq_no " << seq_no | 543 LOG(LS_ERROR) << "Expected to find delta for seq_no " << seq_no |
539 << ". Next delta is for " << packet_it->sequence_number; | 544 << ". Next delta is for " << packet_it->sequence_number(); |
540 return false; | 545 return false; |
541 } | 546 } |
542 if (delta_size == 1 && | 547 if (delta_size == 1 && |
543 (packet_it->delta_ticks < 0 || packet_it->delta_ticks > 0xff)) { | 548 (packet_it->delta_ticks() < 0 || packet_it->delta_ticks() > 0xff)) { |
544 LOG(LS_ERROR) << "Delta " << packet_it->delta_ticks << " for seq_no " | 549 LOG(LS_ERROR) << "Delta " << packet_it->delta_ticks() << " for seq_no " |
545 << seq_no << " doesn't fit into one byte"; | 550 << seq_no << " doesn't fit into one byte"; |
546 return false; | 551 return false; |
547 } | 552 } |
548 timestamp_us += packet_it->delta_ticks * kDeltaScaleFactor; | 553 timestamp_us += packet_it->delta_us(); |
549 ++packet_it; | 554 ++packet_it; |
550 } | 555 } |
551 packet_size += delta_size; | 556 packet_size += delta_size; |
552 ++seq_no; | 557 ++seq_no; |
553 } | 558 } |
554 if (packet_it != packets_.end()) { | 559 if (packet_it != packets_.end()) { |
555 LOG(LS_ERROR) << "Unencoded delta for seq_no " | 560 LOG(LS_ERROR) << "Unencoded delta for seq_no " |
556 << packet_it->sequence_number; | 561 << packet_it->sequence_number(); |
557 return false; | 562 return false; |
558 } | 563 } |
559 if (timestamp_us != last_timestamp_us_) { | 564 if (timestamp_us != last_timestamp_us_) { |
560 LOG(LS_ERROR) << "Last timestamp mismatch. Calculated: " << timestamp_us | 565 LOG(LS_ERROR) << "Last timestamp mismatch. Calculated: " << timestamp_us |
561 << ". Saved: " << last_timestamp_us_; | 566 << ". Saved: " << last_timestamp_us_; |
562 return false; | 567 return false; |
563 } | 568 } |
564 if (size_bytes_ != packet_size) { | 569 if (size_bytes_ != packet_size) { |
565 LOG(LS_ERROR) << "Rtcp packet size mismatch. Calculated: " << packet_size | 570 LOG(LS_ERROR) << "Rtcp packet size mismatch. Calculated: " << packet_size |
566 << ". Saved: " << size_bytes_; | 571 << ". Saved: " << size_bytes_; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 ByteWriter<uint16_t>::WriteBigEndian(&packet[*position], chunk); | 608 ByteWriter<uint16_t>::WriteBigEndian(&packet[*position], chunk); |
604 *position += 2; | 609 *position += 2; |
605 } | 610 } |
606 if (!last_chunk_->Empty()) { | 611 if (!last_chunk_->Empty()) { |
607 uint16_t chunk = last_chunk_->EncodeLast(); | 612 uint16_t chunk = last_chunk_->EncodeLast(); |
608 ByteWriter<uint16_t>::WriteBigEndian(&packet[*position], chunk); | 613 ByteWriter<uint16_t>::WriteBigEndian(&packet[*position], chunk); |
609 *position += 2; | 614 *position += 2; |
610 } | 615 } |
611 | 616 |
612 for (const auto& received_packet : packets_) { | 617 for (const auto& received_packet : packets_) { |
613 int16_t delta = received_packet.delta_ticks; | 618 int16_t delta = received_packet.delta_ticks(); |
614 if (delta >= 0 && delta <= 0xFF) { | 619 if (delta >= 0 && delta <= 0xFF) { |
615 packet[(*position)++] = delta; | 620 packet[(*position)++] = delta; |
616 } else { | 621 } else { |
617 ByteWriter<int16_t>::WriteBigEndian(&packet[*position], delta); | 622 ByteWriter<int16_t>::WriteBigEndian(&packet[*position], delta); |
618 *position += 2; | 623 *position += 2; |
619 } | 624 } |
620 } | 625 } |
621 | 626 |
622 while ((*position % 4) != 0) | 627 while ((*position % 4) != 0) |
623 packet[(*position)++] = 0; | 628 packet[(*position)++] = 0; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 | 663 |
659 encoded_chunks_.push_back(last_chunk_->Emit()); | 664 encoded_chunks_.push_back(last_chunk_->Emit()); |
660 size_bytes_ += kChunkSizeBytes; | 665 size_bytes_ += kChunkSizeBytes; |
661 last_chunk_->Add(delta_size); | 666 last_chunk_->Add(delta_size); |
662 ++num_seq_no_; | 667 ++num_seq_no_; |
663 return true; | 668 return true; |
664 } | 669 } |
665 | 670 |
666 } // namespace rtcp | 671 } // namespace rtcp |
667 } // namespace webrtc | 672 } // namespace webrtc |
OLD | NEW |