OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 std::unique_ptr<uint8_t[]> payload; | 486 std::unique_ptr<uint8_t[]> payload; |
487 size_t payload_mem_size_bytes = 0; | 487 size_t payload_mem_size_bytes = 0; |
488 if (replace_payload) { | 488 if (replace_payload) { |
489 // Initially assume that the frame size is 30 ms at the initial sample rate. | 489 // Initially assume that the frame size is 30 ms at the initial sample rate. |
490 // This value will be replaced with the correct one as soon as two | 490 // This value will be replaced with the correct one as soon as two |
491 // consecutive packets are found. | 491 // consecutive packets are found. |
492 input_frame_size_timestamps = 30 * sample_rate_hz / 1000; | 492 input_frame_size_timestamps = 30 * sample_rate_hz / 1000; |
493 replacement_audio.reset(new int16_t[input_frame_size_timestamps]); | 493 replacement_audio.reset(new int16_t[input_frame_size_timestamps]); |
494 payload_mem_size_bytes = 2 * input_frame_size_timestamps; | 494 payload_mem_size_bytes = 2 * input_frame_size_timestamps; |
495 payload.reset(new uint8_t[payload_mem_size_bytes]); | 495 payload.reset(new uint8_t[payload_mem_size_bytes]); |
496 next_packet.reset(file_source->NextPacket()); | 496 next_packet = file_source->NextPacket(); |
497 assert(next_packet); | 497 assert(next_packet); |
498 next_packet_available = true; | 498 next_packet_available = true; |
499 } | 499 } |
500 | 500 |
501 // This is the main simulation loop. | 501 // This is the main simulation loop. |
502 // Set the simulation clock to start immediately with the first packet. | 502 // Set the simulation clock to start immediately with the first packet. |
503 int64_t start_time_ms = rtc::checked_cast<int64_t>(packet->time_ms()); | 503 int64_t start_time_ms = rtc::checked_cast<int64_t>(packet->time_ms()); |
504 int64_t time_now_ms = start_time_ms; | 504 int64_t time_now_ms = start_time_ms; |
505 int64_t next_input_time_ms = time_now_ms; | 505 int64_t next_input_time_ms = time_now_ms; |
506 int64_t next_output_time_ms = time_now_ms; | 506 int64_t next_output_time_ms = time_now_ms; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 std::cerr << " PT = " | 559 std::cerr << " PT = " |
560 << static_cast<int>(rtp_header.header.payloadType) | 560 << static_cast<int>(rtp_header.header.payloadType) |
561 << std::endl; | 561 << std::endl; |
562 std::cerr << " SN = " << rtp_header.header.sequenceNumber | 562 std::cerr << " SN = " << rtp_header.header.sequenceNumber |
563 << std::endl; | 563 << std::endl; |
564 std::cerr << " TS = " << rtp_header.header.timestamp << std::endl; | 564 std::cerr << " TS = " << rtp_header.header.timestamp << std::endl; |
565 } | 565 } |
566 } | 566 } |
567 | 567 |
568 // Get next packet from file. | 568 // Get next packet from file. |
569 Packet* temp_packet = file_source->NextPacket(); | 569 std::unique_ptr<Packet> temp_packet = file_source->NextPacket(); |
570 if (temp_packet) { | 570 if (temp_packet) { |
571 packet.reset(temp_packet); | 571 packet = std::move(temp_packet); |
572 if (replace_payload) { | 572 if (replace_payload) { |
573 // At this point |packet| contains the packet *after* |next_packet|. | 573 // At this point |packet| contains the packet *after* |next_packet|. |
574 // Swap Packet objects between |packet| and |next_packet|. | 574 // Swap Packet objects between |packet| and |next_packet|. |
575 packet.swap(next_packet); | 575 packet.swap(next_packet); |
576 // Swap the status indicators unless they're already the same. | 576 // Swap the status indicators unless they're already the same. |
577 if (packet_available != next_packet_available) { | 577 if (packet_available != next_packet_available) { |
578 packet_available = !packet_available; | 578 packet_available = !packet_available; |
579 next_packet_available = !next_packet_available; | 579 next_packet_available = !next_packet_available; |
580 } | 580 } |
581 } | 581 } |
582 next_input_time_ms = rtc::checked_cast<int64_t>(packet->time_ms()); | 582 next_input_time_ms = rtc::checked_cast<int64_t>(packet->time_ms()); |
583 } else { | 583 } else { |
584 // Set next input time to the maximum value of int64_t to prevent the | 584 // Set next input time to the maximum value of int64_t to prevent the |
585 // time_now_ms from becoming stuck at the final value. | 585 // time_now_ms from becoming stuck at the final value. |
586 next_input_time_ms = std::numeric_limits<int64_t>::max(); | 586 next_input_time_ms = std::numeric_limits<int64_t>::max(); |
587 packet_available = false; | 587 packet_available = false; |
588 } | 588 } |
| 589 RTC_DCHECK(!temp_packet); // Must have transferred to another variable. |
589 } | 590 } |
590 | 591 |
591 // Check if it is time to get output audio. | 592 // Check if it is time to get output audio. |
592 while (time_now_ms >= next_output_time_ms && output_event_available) { | 593 while (time_now_ms >= next_output_time_ms && output_event_available) { |
593 AudioFrame out_frame; | 594 AudioFrame out_frame; |
594 bool muted; | 595 bool muted; |
595 int error = neteq->GetAudio(&out_frame, &muted); | 596 int error = neteq->GetAudio(&out_frame, &muted); |
596 RTC_CHECK(!muted); | 597 RTC_CHECK(!muted); |
597 if (error != NetEq::kOK) { | 598 if (error != NetEq::kOK) { |
598 std::cerr << "GetAudio returned error code " << | 599 std::cerr << "GetAudio returned error code " << |
(...skipping 25 matching lines...) Expand all Loading... |
624 printf("Produced %i ms of audio\n", | 625 printf("Produced %i ms of audio\n", |
625 static_cast<int>(time_now_ms - start_time_ms)); | 626 static_cast<int>(time_now_ms - start_time_ms)); |
626 | 627 |
627 delete neteq; | 628 delete neteq; |
628 Trace::ReturnTrace(); | 629 Trace::ReturnTrace(); |
629 return 0; | 630 return 0; |
630 } | 631 } |
631 | 632 |
632 } // namespace test | 633 } // namespace test |
633 } // namespace webrtc | 634 } // namespace webrtc |
OLD | NEW |