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

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

Issue 251893002: Support start trimming post-decoding. Use it with FFmpegDemuxer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/strings/string_util.h" 5 #include "base/strings/string_util.h"
6 #include "base/strings/stringprintf.h" 6 #include "base/strings/stringprintf.h"
7 #include "media/base/audio_buffer.h" 7 #include "media/base/audio_buffer.h"
8 #include "media/base/audio_bus.h" 8 #include "media/base/audio_bus.h"
9 #include "media/base/test_helpers.h" 9 #include "media/base/test_helpers.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 namespace media { 12 namespace media {
13 13
14 const static int kSampleRate = 44100; 14 const static int kSampleRate = 44100;
15 15
16 static void VerifyResult(float* channel_data, 16 static void VerifyResult(float* channel_data,
17 int frames, 17 int frames,
18 float start, 18 float start,
19 float increment) { 19 float increment) {
20 for (int i = 0; i < frames; ++i) { 20 for (int i = 0; i < frames; ++i) {
21 SCOPED_TRACE(base::StringPrintf( 21 SCOPED_TRACE(base::StringPrintf(
22 "i=%d/%d start=%f, increment=%f", i, frames, start, increment)); 22 "i=%d/%d start=%f, increment=%f", i, frames, start, increment));
23 ASSERT_EQ(channel_data[i], start); 23 ASSERT_EQ(channel_data[i], start);
24 start += increment; 24 start += increment;
wolenetz 2014/04/29 19:18:08 nits: If MakeAudioBuffer was subject to error usin
DaleCurtis 2014/04/30 22:04:04 Fixed here: https://codereview.chromium.org/261533
25 } 25 }
26 } 26 }
27 27
28 TEST(AudioBufferTest, CopyFrom) { 28 TEST(AudioBufferTest, CopyFrom) {
29 const ChannelLayout channel_layout = CHANNEL_LAYOUT_MONO; 29 const ChannelLayout channel_layout = CHANNEL_LAYOUT_MONO;
30 const int frames = 8; 30 const int frames = 8;
31 const base::TimeDelta start_time; 31 const base::TimeDelta start_time;
32 const base::TimeDelta duration = base::TimeDelta::FromSeconds(frames); 32 const base::TimeDelta duration = base::TimeDelta::FromSeconds(frames);
33 scoped_refptr<AudioBuffer> buffer = 33 scoped_refptr<AudioBuffer> buffer =
34 MakeAudioBuffer<uint8>(kSampleFormatU8, 34 MakeAudioBuffer<uint8>(kSampleFormatU8,
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 buffer->ReadFrames(10, 0, 0, bus.get()); 351 buffer->ReadFrames(10, 0, 0, bus.get());
352 VerifyResult(bus->channel(0), 10, 61.0f, 1.0f); 352 VerifyResult(bus->channel(0), 10, 61.0f, 1.0f);
353 353
354 // Trim off the last 30 frames. 354 // Trim off the last 30 frames.
355 buffer->TrimEnd(30); 355 buffer->TrimEnd(30);
356 EXPECT_EQ(buffer->frame_count(), 0); 356 EXPECT_EQ(buffer->frame_count(), 0);
357 EXPECT_EQ(buffer->timestamp(), start_time + base::TimeDelta::FromSeconds(60)); 357 EXPECT_EQ(buffer->timestamp(), start_time + base::TimeDelta::FromSeconds(60));
358 EXPECT_EQ(buffer->duration(), base::TimeDelta::FromSeconds(0)); 358 EXPECT_EQ(buffer->duration(), base::TimeDelta::FromSeconds(0));
359 } 359 }
360 360
361 TEST(AudioBufferTest, TrimRange) {
362 const ChannelLayout channel_layout = CHANNEL_LAYOUT_4_0;
363 const int channels = ChannelLayoutToChannelCount(channel_layout);
364 const int frames = 100;
365 const base::TimeDelta start_time;
366 const base::TimeDelta duration = base::TimeDelta::FromSeconds(frames);
wolenetz 2014/04/29 19:18:08 Do you really intend duration to be 100 seconds, e
DaleCurtis 2014/04/30 22:04:04 Fixed here https://codereview.chromium.org/2615330
367 const float step = 1.0f;
368 scoped_refptr<AudioBuffer> buffer =
369 MakeAudioBuffer<float>(kSampleFormatPlanarF32,
wolenetz 2014/04/29 19:18:08 TrimRange does fancy mem ops depending on planar v
DaleCurtis 2014/04/30 22:04:04 Done.
370 channel_layout,
371 channels,
372 kSampleRate,
373 0,
374 step,
375 frames,
376 start_time,
377 duration);
378 EXPECT_EQ(frames, buffer->frame_count());
379 EXPECT_EQ(start_time, buffer->timestamp());
380 EXPECT_EQ(frames, buffer->duration().InSeconds());
381
382 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, frames);
383
384 const int trim_start = 25;
385 const int trim_length = 50;
386
387 // Verify the first 25 frames before trimming.
388 buffer->ReadFrames(trim_start, 0, 0, bus.get());
389 VerifyResult(bus->channel(0), trim_start, 0, step);
wolenetz 2014/04/29 19:18:08 TrimRange's fancy mem ops could use additional ver
DaleCurtis 2014/04/30 22:04:04 Done.
390
391 // Trim frames from the middle of the buffer.
392 buffer->TrimRange(trim_start, trim_start + trim_length);
393 EXPECT_EQ(buffer->frame_count(), frames - trim_length);
394 EXPECT_EQ(buffer->timestamp(), start_time);
395 EXPECT_EQ(buffer->duration(), base::TimeDelta::FromSeconds(50));
wolenetz 2014/04/29 19:18:08 I don't understand why an AudioBuffer could be giv
DaleCurtis 2014/04/29 20:46:35 Generally the duration will only be off by a micro
DaleCurtis 2014/04/30 22:04:04 Fixed here: https://codereview.chromium.org/261533
396
397 // Verify the first 25 frames.
398 buffer->ReadFrames(trim_start, 0, 0, bus.get());
399 VerifyResult(bus->channel(0), trim_start, 0, step);
wolenetz 2014/04/29 19:18:08 ditto: verify all channels
DaleCurtis 2014/04/30 22:04:04 Done.
400
401 // Verify the next 25 frames.
402 buffer->ReadFrames(trim_start, trim_start, 0, bus.get());
403 VerifyResult(bus->channel(0), trim_start, trim_start + trim_length, step);
wolenetz 2014/04/29 19:18:08 ditto
DaleCurtis 2014/04/30 22:04:04 Done.
404 }
405
361 } // namespace media 406 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698