Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(633)

Unified Diff: media/filters/audio_file_reader_unittest.cc

Issue 2655783004: Decode entire in-memory file for WebAudio (Closed)
Patch Set: Remove old implmenetation and update tests Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/filters/audio_file_reader_unittest.cc
diff --git a/media/filters/audio_file_reader_unittest.cc b/media/filters/audio_file_reader_unittest.cc
index 449934bcb19d80aa92877a1ea7dd3674d395f3f6..1f5a41fbd490f4afd1f5d14c6b56e5ce7814063f 100644
--- a/media/filters/audio_file_reader_unittest.cc
+++ b/media/filters/audio_file_reader_unittest.cc
@@ -35,9 +35,17 @@ class AudioFileReaderTest : public testing::Test {
// Reads and the entire file provided to Initialize().
void ReadAndVerify(const char* expected_audio_hash, int expected_frames) {
+ std::vector<std::unique_ptr<AudioBus>> decodedAudioPackets;
+ int actual_frames = reader_->Read(decodedAudioPackets);
std::unique_ptr<AudioBus> decoded_audio_data =
- AudioBus::Create(reader_->channels(), reader_->GetNumberOfFrames());
- int actual_frames = reader_->Read(decoded_audio_data.get());
+ AudioBus::Create(reader_->channels(), actual_frames);
+ int dest_start_frame = 0;
+ for (auto&& packet : decodedAudioPackets) {
DaleCurtis 2017/02/09 18:47:36 no &&
Raymond Toy 2017/02/09 21:45:06 Done.
+ int frame_count = packet->frames();
+ packet->CopyPartialFramesTo(0, frame_count, dest_start_frame,
+ decoded_audio_data.get());
+ dest_start_frame += frame_count;
+ }
ASSERT_LE(actual_frames, decoded_audio_data->frames());
ASSERT_EQ(expected_frames, actual_frames);
@@ -89,17 +97,21 @@ class AudioFileReaderTest : public testing::Test {
int sample_rate,
base::TimeDelta duration,
int frames,
- int trimmed_frames) {
+ int expected_frames) {
Initialize(fn);
ASSERT_TRUE(reader_->Open());
EXPECT_EQ(channels, reader_->channels());
EXPECT_EQ(sample_rate, reader_->sample_rate());
- EXPECT_EQ(duration.InMicroseconds(),
- reader_->GetDuration().InMicroseconds());
- EXPECT_EQ(frames, reader_->GetNumberOfFrames());
+ if (frames >= 0) {
+ EXPECT_EQ(duration.InMicroseconds(),
+ reader_->GetDuration().InMicroseconds());
+ EXPECT_EQ(frames, reader_->GetNumberOfFrames());
+ } else {
+ EXPECT_EQ(reader_->HasKnownDuration(), false);
DaleCurtis 2017/02/09 18:47:36 If this is only used for testing now rename it as
Raymond Toy 2017/02/09 19:56:05 It's used in audio_decoder.cc in a DVLOG. I'm deba
Raymond Toy 2017/02/09 21:45:06 Renamed to HasKnownDurationForTesting. Still used
DaleCurtis 2017/02/09 22:42:20 Yeah either drop from DVLOG or rename back to what
Raymond Toy 2017/02/09 23:09:28 Renamed.
+ }
if (!packet_verification_disabled_)
ASSERT_NO_FATAL_FAILURE(VerifyPackets());
- ReadAndVerify(hash, trimmed_frames);
+ ReadAndVerify(hash, expected_frames);
}
void RunTestFailingDemux(const char* fn) {
@@ -110,9 +122,8 @@ class AudioFileReaderTest : public testing::Test {
void RunTestFailingDecode(const char* fn) {
Initialize(fn);
EXPECT_TRUE(reader_->Open());
- std::unique_ptr<AudioBus> decoded_audio_data =
- AudioBus::Create(reader_->channels(), reader_->GetNumberOfFrames());
- EXPECT_EQ(reader_->Read(decoded_audio_data.get()), 0);
+ std::vector<std::unique_ptr<AudioBus>> decodedAudioPackets;
+ EXPECT_EQ(reader_->Read(decodedAudioPackets), 0);
}
void disable_packet_verification() {
@@ -136,28 +147,34 @@ TEST_F(AudioFileReaderTest, InvalidFile) {
RunTestFailingDemux("ten_byte_file");
}
-TEST_F(AudioFileReaderTest, InfiniteDuration) {
- RunTestFailingDemux("bear-320x240-live.webm");
+TEST_F(AudioFileReaderTest, UnknownDuration) {
+ RunTest("bear-320x240-live.webm",
Raymond Toy 2017/02/09 21:45:07 Presubmit keeps telling me I need to reformat this
DaleCurtis 2017/02/09 22:42:20 Just run git cl format.
Raymond Toy 2017/02/09 23:09:28 Done.
+ "-3.59,-2.06,-0.43,2.15,0.77,-0.95,",
+ 2,
+ 44100,
+ base::TimeDelta::FromMicroseconds(-1),
+ -1,
+ 121024);
}
TEST_F(AudioFileReaderTest, WithVideo) {
RunTest("bear.ogv",
- "-2.49,-0.75,0.38,1.60,0.70,-1.22,",
+ "-0.73,0.92,0.48,-0.07,-0.92,-0.88,",
2,
44100,
base::TimeDelta::FromMicroseconds(1011520),
44609,
- 44609);
+ 45632);
}
TEST_F(AudioFileReaderTest, Vorbis) {
RunTest("sfx.ogg",
- "4.36,4.81,4.84,4.45,4.61,4.63,",
+ "2.17,3.31,5.15,6.33,5.97,4.35,",
1,
44100,
base::TimeDelta::FromMicroseconds(350001),
15436,
- 15436);
+ 15936);
}
TEST_F(AudioFileReaderTest, WaveU8) {

Powered by Google App Engine
This is Rietveld 408576698