Chromium Code Reviews| 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 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 539 } | 539 } |
| 540 | 540 |
| 541 // Should encode now. | 541 // Should encode now. |
| 542 states.encoder->Encode(rtp_timestamp, audio_frames->GetNextBlock(), | 542 states.encoder->Encode(rtp_timestamp, audio_frames->GetNextBlock(), |
| 543 &encoded); | 543 &encoded); |
| 544 EXPECT_GT(encoded.size(), 0u); | 544 EXPECT_GT(encoded.size(), 0u); |
| 545 encoded.Clear(); | 545 encoded.Clear(); |
| 546 } | 546 } |
| 547 } | 547 } |
| 548 | 548 |
| 549 TEST(AudioEncoderOpusTest, EncodeCbr) { | |
|
minyue-webrtc
2017/03/29 20:45:26
I am not sure that we have to test Cbr is Cbr in A
squashingskak
2017/03/30 08:25:54
Main reason to do the test is to check that enable
| |
| 550 auto states = CreateCodec(1); | |
| 551 constexpr int kNumRuns = 4; | |
| 552 constexpr int kNumPacketsPerRun = 20; | |
| 553 constexpr int kNumPacketsToEncode = kNumPacketsPerRun * kNumRuns; | |
| 554 auto audio_frames = | |
| 555 Create10msAudioBlocks(states.encoder, kNumPacketsToEncode * 20); | |
|
minyue-webrtc
2017/03/29 20:45:26
needs indent. you can do
git cl format
| |
| 556 ASSERT_TRUE(audio_frames) << "Create10msAudioBlocks failed"; | |
| 557 rtc::Buffer encoded; | |
| 558 uint32_t rtp_timestamp = 12345; // Just a number not important to this test. | |
| 559 | |
| 560 for(int run = 0; run < kNumRuns; run++){ | |
| 561 int32_t max_pkt_size_diff = 0; | |
| 562 int32_t prev_pkt_size = 0; | |
| 563 bool use_cbr = (run & 1) ? true : false; | |
|
minyue-webrtc
2017/03/29 20:45:26
are you trying combinations of {use_cbr, bitrate}?
kwiberg-webrtc
2017/03/29 21:54:17
Nowadays, it should be legal to do simply
for (
| |
| 564 int bitrate = (run & 2) ? 100000 : 0; | |
| 565 | |
| 566 states.encoder->SetCbr(use_cbr); | |
| 567 states.encoder->OnReceivedUplinkBandwidth(bitrate, | |
| 568 rtc::Optional<int64_t>()); | |
| 569 for (int packet_index = 0; packet_index < kNumPacketsPerRun; | |
| 570 packet_index++) { | |
| 571 // Make sure we are not encoding before we have enough data for | |
| 572 // a 20ms packet. | |
| 573 for (int index = 0; index < 1; index++) { | |
| 574 states.encoder->Encode(rtp_timestamp, audio_frames->GetNextBlock(), | |
| 575 &encoded); | |
| 576 EXPECT_EQ(0u, encoded.size()); | |
| 577 } | |
| 578 | |
| 579 // Should encode now. | |
| 580 states.encoder->Encode(rtp_timestamp, audio_frames->GetNextBlock(), | |
| 581 &encoded); | |
| 582 EXPECT_GT(encoded.size(), 0u); | |
| 583 | |
| 584 if(prev_pkt_size > 0){ | |
| 585 int32_t diff = std::abs((int32_t)encoded.size() - prev_pkt_size); | |
| 586 max_pkt_size_diff = std::max(max_pkt_size_diff, diff); | |
| 587 } | |
| 588 prev_pkt_size = encoded.size(); | |
| 589 | |
| 590 encoded.Clear(); | |
| 591 } | |
| 592 if(use_cbr){ | |
| 593 EXPECT_EQ(max_pkt_size_diff, 0); | |
| 594 } else { | |
| 595 EXPECT_GT(max_pkt_size_diff, 0); | |
| 596 } | |
| 597 } | |
| 598 } | |
| 599 | |
| 549 } // namespace webrtc | 600 } // namespace webrtc |
| OLD | NEW |