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

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

Issue 2788483003: Introduce AudioBufferMemoryPool to avoid thrashing on audio buffers. (Closed)
Patch Set: Add class comments. Created 3 years, 8 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
« no previous file with comments | « media/base/audio_buffer_converter.cc ('k') | media/cdm/cdm_adapter.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 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <limits> 7 #include <limits>
8 #include <memory> 8 #include <memory>
9 9
10 #include "media/base/audio_buffer.h" 10 #include "media/base/audio_buffer.h"
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 } 427 }
428 428
429 TEST(AudioBufferTest, TrimRangePlanar) { 429 TEST(AudioBufferTest, TrimRangePlanar) {
430 TrimRangeTest(kSampleFormatPlanarF32); 430 TrimRangeTest(kSampleFormatPlanarF32);
431 } 431 }
432 432
433 TEST(AudioBufferTest, TrimRangeInterleaved) { 433 TEST(AudioBufferTest, TrimRangeInterleaved) {
434 TrimRangeTest(kSampleFormatF32); 434 TrimRangeTest(kSampleFormatF32);
435 } 435 }
436 436
437 TEST(AudioBufferTest, AudioBufferMemoryPool) {
438 scoped_refptr<AudioBufferMemoryPool> pool(new AudioBufferMemoryPool());
439 EXPECT_EQ(0u, pool->get_pool_size_for_testing());
440
441 const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_MONO;
442 scoped_refptr<AudioBuffer> buffer = MakeAudioBuffer<uint8_t>(
443 kSampleFormatU8, kChannelLayout,
444 ChannelLayoutToChannelCount(kChannelLayout), kSampleRate, 1, 1,
445 kSampleRate / 100, base::TimeDelta());
446
447 // Creating and returning a buffer should increase pool size.
448 scoped_refptr<AudioBuffer> b1 = AudioBuffer::CopyFrom(
449 kSampleFormatU8, buffer->channel_layout(), buffer->channel_count(),
450 buffer->sample_rate(), buffer->frame_count(), &buffer->channel_data()[0],
451 buffer->timestamp(), pool);
452 EXPECT_EQ(0u, pool->get_pool_size_for_testing());
453 b1 = nullptr;
454 EXPECT_EQ(1u, pool->get_pool_size_for_testing());
455
456 // Even (especially) when used with CreateBuffer.
457 b1 = AudioBuffer::CreateBuffer(kSampleFormatU8, buffer->channel_layout(),
458 buffer->channel_count(), buffer->sample_rate(),
459 buffer->frame_count(), pool);
460 EXPECT_EQ(0u, pool->get_pool_size_for_testing());
461 scoped_refptr<AudioBuffer> b2 = AudioBuffer::CreateBuffer(
462 kSampleFormatU8, buffer->channel_layout(), buffer->channel_count(),
463 buffer->sample_rate(), buffer->frame_count(), pool);
464 EXPECT_EQ(0u, pool->get_pool_size_for_testing());
465 b2 = nullptr;
466 EXPECT_EQ(1u, pool->get_pool_size_for_testing());
467 b1 = nullptr;
468 EXPECT_EQ(2u, pool->get_pool_size_for_testing());
469
470 // A buffer of a different size should not reuse the buffer and drain pool.
471 b2 = AudioBuffer::CreateBuffer(kSampleFormatU8, buffer->channel_layout(),
472 buffer->channel_count(), buffer->sample_rate(),
473 buffer->frame_count() / 2, pool);
474 EXPECT_EQ(0u, pool->get_pool_size_for_testing());
475
476 // Mark pool for destruction and ensure buffer is still valid.
477 pool = nullptr;
478 memset(b2->channel_data()[0], 0, b2->frame_count());
479
480 // Destruct final frame after pool; hope nothing explodes.
481 b2 = nullptr;
482 }
483
437 } // namespace media 484 } // namespace media
OLDNEW
« no previous file with comments | « media/base/audio_buffer_converter.cc ('k') | media/cdm/cdm_adapter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698