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 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 std::unique_ptr<uint8_t[]> payload; | 500 std::unique_ptr<uint8_t[]> payload; |
501 size_t payload_mem_size_bytes = 0; | 501 size_t payload_mem_size_bytes = 0; |
502 if (replace_payload) { | 502 if (replace_payload) { |
503 // Initially assume that the frame size is 30 ms at the initial sample rate. | 503 // Initially assume that the frame size is 30 ms at the initial sample rate. |
504 // This value will be replaced with the correct one as soon as two | 504 // This value will be replaced with the correct one as soon as two |
505 // consecutive packets are found. | 505 // consecutive packets are found. |
506 input_frame_size_timestamps = 30 * sample_rate_hz / 1000; | 506 input_frame_size_timestamps = 30 * sample_rate_hz / 1000; |
507 replacement_audio.reset(new int16_t[input_frame_size_timestamps]); | 507 replacement_audio.reset(new int16_t[input_frame_size_timestamps]); |
508 payload_mem_size_bytes = 2 * input_frame_size_timestamps; | 508 payload_mem_size_bytes = 2 * input_frame_size_timestamps; |
509 payload.reset(new uint8_t[payload_mem_size_bytes]); | 509 payload.reset(new uint8_t[payload_mem_size_bytes]); |
510 next_packet.reset(file_source->NextPacket()); | 510 next_packet = file_source->NextPacket(); |
511 assert(next_packet); | 511 assert(next_packet); |
512 next_packet_available = true; | 512 next_packet_available = true; |
513 } | 513 } |
514 | 514 |
515 // This is the main simulation loop. | 515 // This is the main simulation loop. |
516 // Set the simulation clock to start immediately with the first packet. | 516 // Set the simulation clock to start immediately with the first packet. |
517 int64_t start_time_ms = rtc::checked_cast<int64_t>(packet->time_ms()); | 517 int64_t start_time_ms = rtc::checked_cast<int64_t>(packet->time_ms()); |
518 int64_t time_now_ms = start_time_ms; | 518 int64_t time_now_ms = start_time_ms; |
519 int64_t next_input_time_ms = time_now_ms; | 519 int64_t next_input_time_ms = time_now_ms; |
520 int64_t next_output_time_ms = time_now_ms; | 520 int64_t next_output_time_ms = time_now_ms; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 std::cerr << " PT = " | 573 std::cerr << " PT = " |
574 << static_cast<int>(rtp_header.header.payloadType) | 574 << static_cast<int>(rtp_header.header.payloadType) |
575 << std::endl; | 575 << std::endl; |
576 std::cerr << " SN = " << rtp_header.header.sequenceNumber | 576 std::cerr << " SN = " << rtp_header.header.sequenceNumber |
577 << std::endl; | 577 << std::endl; |
578 std::cerr << " TS = " << rtp_header.header.timestamp << std::endl; | 578 std::cerr << " TS = " << rtp_header.header.timestamp << std::endl; |
579 } | 579 } |
580 } | 580 } |
581 | 581 |
582 // Get next packet from file. | 582 // Get next packet from file. |
583 webrtc::test::Packet* temp_packet = file_source->NextPacket(); | 583 std::unique_ptr<webrtc::test::Packet> temp_packet = |
| 584 file_source->NextPacket(); |
584 if (temp_packet) { | 585 if (temp_packet) { |
585 packet.reset(temp_packet); | 586 packet = std::move(temp_packet); |
586 if (replace_payload) { | 587 if (replace_payload) { |
587 // At this point |packet| contains the packet *after* |next_packet|. | 588 // At this point |packet| contains the packet *after* |next_packet|. |
588 // Swap Packet objects between |packet| and |next_packet|. | 589 // Swap Packet objects between |packet| and |next_packet|. |
589 packet.swap(next_packet); | 590 packet.swap(next_packet); |
590 // Swap the status indicators unless they're already the same. | 591 // Swap the status indicators unless they're already the same. |
591 if (packet_available != next_packet_available) { | 592 if (packet_available != next_packet_available) { |
592 packet_available = !packet_available; | 593 packet_available = !packet_available; |
593 next_packet_available = !next_packet_available; | 594 next_packet_available = !next_packet_available; |
594 } | 595 } |
595 } | 596 } |
596 next_input_time_ms = rtc::checked_cast<int64_t>(packet->time_ms()); | 597 next_input_time_ms = rtc::checked_cast<int64_t>(packet->time_ms()); |
597 } else { | 598 } else { |
598 // Set next input time to the maximum value of int64_t to prevent the | 599 // Set next input time to the maximum value of int64_t to prevent the |
599 // time_now_ms from becoming stuck at the final value. | 600 // time_now_ms from becoming stuck at the final value. |
600 next_input_time_ms = std::numeric_limits<int64_t>::max(); | 601 next_input_time_ms = std::numeric_limits<int64_t>::max(); |
601 packet_available = false; | 602 packet_available = false; |
602 } | 603 } |
| 604 RTC_DCHECK(!temp_packet); // Must have transferred to another variable. |
603 } | 605 } |
604 | 606 |
605 // Check if it is time to get output audio. | 607 // Check if it is time to get output audio. |
606 while (time_now_ms >= next_output_time_ms && output_event_available) { | 608 while (time_now_ms >= next_output_time_ms && output_event_available) { |
607 webrtc::AudioFrame out_frame; | 609 webrtc::AudioFrame out_frame; |
608 bool muted; | 610 bool muted; |
609 int error = neteq->GetAudio(&out_frame, &muted); | 611 int error = neteq->GetAudio(&out_frame, &muted); |
610 RTC_CHECK(!muted); | 612 RTC_CHECK(!muted); |
611 if (error != NetEq::kOK) { | 613 if (error != NetEq::kOK) { |
612 std::cerr << "GetAudio returned error code " << | 614 std::cerr << "GetAudio returned error code " << |
(...skipping 22 matching lines...) Expand all Loading... |
635 } | 637 } |
636 } | 638 } |
637 printf("Simulation done\n"); | 639 printf("Simulation done\n"); |
638 printf("Produced %i ms of audio\n", | 640 printf("Produced %i ms of audio\n", |
639 static_cast<int>(time_now_ms - start_time_ms)); | 641 static_cast<int>(time_now_ms - start_time_ms)); |
640 | 642 |
641 delete neteq; | 643 delete neteq; |
642 webrtc::Trace::ReturnTrace(); | 644 webrtc::Trace::ReturnTrace(); |
643 return 0; | 645 return 0; |
644 } | 646 } |
OLD | NEW |