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

Side by Side Diff: media/base/audio_splicer_unittest.cc

Issue 265943002: Revert of Remove AudioBuffer::set_duration(), instead base on frames. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/base/audio_splicer.cc ('k') | media/base/test_helpers.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "media/base/audio_buffer.h" 6 #include "media/base/audio_buffer.h"
7 #include "media/base/audio_bus.h" 7 #include "media/base/audio_bus.h"
8 #include "media/base/audio_splicer.h" 8 #include "media/base/audio_splicer.h"
9 #include "media/base/audio_timestamp_helper.h" 9 #include "media/base/audio_timestamp_helper.h"
10 #include "media/base/buffers.h" 10 #include "media/base/buffers.h"
(...skipping 17 matching lines...) Expand all
28 : splicer_(kDefaultSampleRate), 28 : splicer_(kDefaultSampleRate),
29 input_timestamp_helper_(kDefaultSampleRate) { 29 input_timestamp_helper_(kDefaultSampleRate) {
30 input_timestamp_helper_.SetBaseTimestamp(base::TimeDelta()); 30 input_timestamp_helper_.SetBaseTimestamp(base::TimeDelta());
31 } 31 }
32 32
33 scoped_refptr<AudioBuffer> GetNextInputBuffer(float value) { 33 scoped_refptr<AudioBuffer> GetNextInputBuffer(float value) {
34 return GetNextInputBuffer(value, kDefaultBufferSize); 34 return GetNextInputBuffer(value, kDefaultBufferSize);
35 } 35 }
36 36
37 scoped_refptr<AudioBuffer> GetNextInputBuffer(float value, int frame_size) { 37 scoped_refptr<AudioBuffer> GetNextInputBuffer(float value, int frame_size) {
38 scoped_refptr<AudioBuffer> buffer = 38 scoped_refptr<AudioBuffer> buffer = MakeAudioBuffer<float>(
39 MakeAudioBuffer<float>(kSampleFormat, 39 kSampleFormat,
40 kChannelLayout, 40 kChannelLayout,
41 kChannels, 41 kChannels,
42 kDefaultSampleRate, 42 kDefaultSampleRate,
43 value, 43 value,
44 0.0f, 44 0.0f,
45 frame_size, 45 frame_size,
46 input_timestamp_helper_.GetTimestamp()); 46 input_timestamp_helper_.GetTimestamp(),
47 input_timestamp_helper_.GetFrameDuration(frame_size));
47 input_timestamp_helper_.AddFrames(frame_size); 48 input_timestamp_helper_.AddFrames(frame_size);
48 return buffer; 49 return buffer;
49 } 50 }
50 51
51 float GetValue(const scoped_refptr<AudioBuffer>& buffer) { 52 float GetValue(const scoped_refptr<AudioBuffer>& buffer) {
52 return reinterpret_cast<const float*>(buffer->channel_data()[0])[0]; 53 return reinterpret_cast<const float*>(buffer->channel_data()[0])[0];
53 } 54 }
54 55
55 bool VerifyData(const scoped_refptr<AudioBuffer>& buffer, float value) { 56 bool VerifyData(const scoped_refptr<AudioBuffer>& buffer, float value) {
56 int frames = buffer->frame_count(); 57 int frames = buffer->frame_count();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 // is not modified in unexpected ways. 132 // is not modified in unexpected ways.
132 scoped_refptr<AudioBuffer> buffer_copy = 133 scoped_refptr<AudioBuffer> buffer_copy =
133 input->end_of_stream() 134 input->end_of_stream()
134 ? AudioBuffer::CreateEOSBuffer() 135 ? AudioBuffer::CreateEOSBuffer()
135 : AudioBuffer::CopyFrom(kSampleFormat, 136 : AudioBuffer::CopyFrom(kSampleFormat,
136 input->channel_layout(), 137 input->channel_layout(),
137 input->channel_count(), 138 input->channel_count(),
138 input->sample_rate(), 139 input->sample_rate(),
139 input->frame_count(), 140 input->frame_count(),
140 &input->channel_data()[0], 141 &input->channel_data()[0],
141 input->timestamp()); 142 input->timestamp(),
143 input->duration());
142 return splicer_.AddInput(buffer_copy); 144 return splicer_.AddInput(buffer_copy);
143 } 145 }
144 146
145 base::TimeDelta max_crossfade_duration() { 147 base::TimeDelta max_crossfade_duration() {
146 return splicer_.max_crossfade_duration_; 148 return splicer_.max_crossfade_duration_;
147 } 149 }
148 150
149 protected: 151 protected:
150 AudioSplicer splicer_; 152 AudioSplicer splicer_;
151 AudioTimestampHelper input_timestamp_helper_; 153 AudioTimestampHelper input_timestamp_helper_;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 // Verify that the first input buffer passed through unmodified. 241 // Verify that the first input buffer passed through unmodified.
240 VerifyNextBuffer(input_1); 242 VerifyNextBuffer(input_1);
241 243
242 // Verify the contents of the gap buffer. 244 // Verify the contents of the gap buffer.
243 scoped_refptr<AudioBuffer> output_2 = splicer_.GetNextBuffer(); 245 scoped_refptr<AudioBuffer> output_2 = splicer_.GetNextBuffer();
244 base::TimeDelta gap_timestamp = 246 base::TimeDelta gap_timestamp =
245 input_1->timestamp() + input_1->duration(); 247 input_1->timestamp() + input_1->duration();
246 base::TimeDelta gap_duration = input_2->timestamp() - gap_timestamp; 248 base::TimeDelta gap_duration = input_2->timestamp() - gap_timestamp;
247 EXPECT_GT(gap_duration, base::TimeDelta()); 249 EXPECT_GT(gap_duration, base::TimeDelta());
248 EXPECT_EQ(gap_timestamp, output_2->timestamp()); 250 EXPECT_EQ(gap_timestamp, output_2->timestamp());
249 EXPECT_NEAR( 251 EXPECT_EQ(gap_duration, output_2->duration());
250 gap_duration.InMicroseconds(), output_2->duration().InMicroseconds(), 1);
251 EXPECT_EQ(kGapSize, output_2->frame_count()); 252 EXPECT_EQ(kGapSize, output_2->frame_count());
252 EXPECT_TRUE(VerifyData(output_2, 0.0f)); 253 EXPECT_TRUE(VerifyData(output_2, 0.0f));
253 254
254 // Verify that the second input buffer passed through unmodified. 255 // Verify that the second input buffer passed through unmodified.
255 VerifyNextBuffer(input_2); 256 VerifyNextBuffer(input_2);
256 EXPECT_FALSE(splicer_.HasNextBuffer()); 257 EXPECT_FALSE(splicer_.HasNextBuffer());
257 } 258 }
258 259
259 // Test that an error is signalled when the gap between input buffers is 260 // Test that an error is signalled when the gap between input buffers is
260 // too large. 261 // too large.
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 ASSERT_TRUE(splicer_.HasNextBuffer()); 437 ASSERT_TRUE(splicer_.HasNextBuffer());
437 438
438 // Add one more buffer to make sure it's passed through untouched. 439 // Add one more buffer to make sure it's passed through untouched.
439 scoped_refptr<AudioBuffer> extra_post_splice_buffer = 440 scoped_refptr<AudioBuffer> extra_post_splice_buffer =
440 GetNextInputBuffer(0.5f, kBufferSize); 441 GetNextInputBuffer(0.5f, kBufferSize);
441 EXPECT_TRUE(AddInput(extra_post_splice_buffer)); 442 EXPECT_TRUE(AddInput(extra_post_splice_buffer));
442 443
443 VerifyPreSpliceOutput(overlapped_buffer, 444 VerifyPreSpliceOutput(overlapped_buffer,
444 overlapping_buffer, 445 overlapping_buffer,
445 221, 446 221,
446 base::TimeDelta::FromMicroseconds(5011)); 447 base::TimeDelta::FromMicroseconds(5012));
447 448
448 // Due to rounding the crossfade size may vary by up to a frame. 449 // Due to rounding the crossfade size may vary by up to a frame.
449 const int kExpectedCrossfadeSize = 220; 450 const int kExpectedCrossfadeSize = 220;
450 EXPECT_NEAR(kExpectedCrossfadeSize, kCrossfadeSize, 1); 451 EXPECT_NEAR(kExpectedCrossfadeSize, kCrossfadeSize, 1);
451 452
452 VerifyCrossfadeOutput(overlapped_buffer, 453 VerifyCrossfadeOutput(overlapped_buffer,
453 NULL, 454 NULL,
454 overlapping_buffer, 455 overlapping_buffer,
455 0, 456 0,
456 kExpectedCrossfadeSize, 457 kExpectedCrossfadeSize,
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 // |1111111111|22222222222222| 612 // |1111111111|22222222222222|
612 // +----------+--------------+ 613 // +----------+--------------+
613 TEST_F(AudioSplicerTest, IncorrectlyMarkedSplice) { 614 TEST_F(AudioSplicerTest, IncorrectlyMarkedSplice) {
614 const int kBufferSize = 615 const int kBufferSize =
615 input_timestamp_helper_.GetFramesToTarget(max_crossfade_duration()) * 2; 616 input_timestamp_helper_.GetFramesToTarget(max_crossfade_duration()) * 2;
616 617
617 scoped_refptr<AudioBuffer> first_buffer = 618 scoped_refptr<AudioBuffer> first_buffer =
618 GetNextInputBuffer(1.0f, kBufferSize); 619 GetNextInputBuffer(1.0f, kBufferSize);
619 // Fuzz the duration slightly so that the buffer overlaps the splice timestamp 620 // Fuzz the duration slightly so that the buffer overlaps the splice timestamp
620 // by a microsecond, which is not enough to crossfade. 621 // by a microsecond, which is not enough to crossfade.
621 const base::TimeDelta kSpliceTimestamp = 622 first_buffer->set_duration(first_buffer->duration() +
622 input_timestamp_helper_.GetTimestamp() - 623 base::TimeDelta::FromMicroseconds(1));
623 base::TimeDelta::FromMicroseconds(1); 624 splicer_.SetSpliceTimestamp(input_timestamp_helper_.GetTimestamp());
624 splicer_.SetSpliceTimestamp(kSpliceTimestamp);
625 scoped_refptr<AudioBuffer> second_buffer = 625 scoped_refptr<AudioBuffer> second_buffer =
626 GetNextInputBuffer(0.0f, kBufferSize); 626 GetNextInputBuffer(0.0f, kBufferSize);
627 second_buffer->set_timestamp(kSpliceTimestamp);
628 627
629 // The splicer should be internally queuing input since |first_buffer| is part 628 // The splicer should be internally queuing input since |first_buffer| is part
630 // of the supposed splice. 629 // of the supposed splice.
631 EXPECT_TRUE(AddInput(first_buffer)); 630 EXPECT_TRUE(AddInput(first_buffer));
632 EXPECT_FALSE(splicer_.HasNextBuffer()); 631 EXPECT_FALSE(splicer_.HasNextBuffer());
633 632
634 // |second_buffer| should complete the supposed splice, so ensure output is 633 // |second_buffer| should complete the supposed splice, so ensure output is
635 // now available. 634 // now available.
636 splicer_.SetSpliceTimestamp(kNoTimestamp()); 635 splicer_.SetSpliceTimestamp(kNoTimestamp());
637 EXPECT_TRUE(AddInput(second_buffer)); 636 EXPECT_TRUE(AddInput(second_buffer));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 // |second_buffer| will complete the supposed splice. 675 // |second_buffer| will complete the supposed splice.
677 splicer_.SetSpliceTimestamp(kNoTimestamp()); 676 splicer_.SetSpliceTimestamp(kNoTimestamp());
678 EXPECT_TRUE(AddInput(second_buffer)); 677 EXPECT_TRUE(AddInput(second_buffer));
679 678
680 VerifyNextBuffer(gap_buffer); 679 VerifyNextBuffer(gap_buffer);
681 VerifyNextBuffer(second_buffer); 680 VerifyNextBuffer(second_buffer);
682 EXPECT_FALSE(splicer_.HasNextBuffer()); 681 EXPECT_FALSE(splicer_.HasNextBuffer());
683 } 682 }
684 683
685 } // namespace media 684 } // namespace media
OLDNEW
« no previous file with comments | « media/base/audio_splicer.cc ('k') | media/base/test_helpers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698