OLD | NEW |
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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 original_buffer->timestamp()); | 173 original_buffer->timestamp()); |
174 EXPECT_EQ(original_buffer->frame_count(), new_buffer->frame_count()); | 174 EXPECT_EQ(original_buffer->frame_count(), new_buffer->frame_count()); |
175 EXPECT_EQ(original_buffer->timestamp(), new_buffer->timestamp()); | 175 EXPECT_EQ(original_buffer->timestamp(), new_buffer->timestamp()); |
176 EXPECT_EQ(original_buffer->duration(), new_buffer->duration()); | 176 EXPECT_EQ(original_buffer->duration(), new_buffer->duration()); |
177 EXPECT_EQ(original_buffer->sample_rate(), new_buffer->sample_rate()); | 177 EXPECT_EQ(original_buffer->sample_rate(), new_buffer->sample_rate()); |
178 EXPECT_EQ(original_buffer->channel_count(), new_buffer->channel_count()); | 178 EXPECT_EQ(original_buffer->channel_count(), new_buffer->channel_count()); |
179 EXPECT_EQ(original_buffer->channel_layout(), new_buffer->channel_layout()); | 179 EXPECT_EQ(original_buffer->channel_layout(), new_buffer->channel_layout()); |
180 EXPECT_FALSE(original_buffer->end_of_stream()); | 180 EXPECT_FALSE(original_buffer->end_of_stream()); |
181 } | 181 } |
182 | 182 |
| 183 TEST(AudioBufferTest, CopyBitstreamFrom) { |
| 184 const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO; |
| 185 const int kChannelCount = ChannelLayoutToChannelCount(kChannelLayout); |
| 186 const int kFrameCount = 128; |
| 187 const uint8_t kTestData[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, |
| 188 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
| 189 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}; |
| 190 const base::TimeDelta kTimestamp = base::TimeDelta::FromMicroseconds(1337); |
| 191 const uint8_t* const data[] = {kTestData}; |
| 192 |
| 193 scoped_refptr<AudioBuffer> buffer = AudioBuffer::CopyBitstreamFrom( |
| 194 kSampleFormatAc3, kChannelLayout, kChannelCount, kSampleRate, kFrameCount, |
| 195 data, sizeof(kTestData), kTimestamp); |
| 196 |
| 197 EXPECT_EQ(kChannelLayout, buffer->channel_layout()); |
| 198 EXPECT_EQ(kFrameCount, buffer->frame_count()); |
| 199 EXPECT_EQ(kSampleRate, buffer->sample_rate()); |
| 200 EXPECT_EQ(kFrameCount, buffer->frame_count()); |
| 201 EXPECT_EQ(kTimestamp, buffer->timestamp()); |
| 202 EXPECT_TRUE(buffer->IsBitstreamFormat()); |
| 203 EXPECT_FALSE(buffer->end_of_stream()); |
| 204 } |
| 205 |
| 206 TEST(AudioBufferTest, CreateBitstreamBuffer) { |
| 207 const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO; |
| 208 const int kChannelCount = ChannelLayoutToChannelCount(kChannelLayout); |
| 209 const int kFrameCount = 128; |
| 210 const int kDataSize = 32; |
| 211 |
| 212 scoped_refptr<AudioBuffer> buffer = AudioBuffer::CreateBitstreamBuffer( |
| 213 kSampleFormatAc3, kChannelLayout, kChannelCount, kSampleRate, kFrameCount, |
| 214 kDataSize); |
| 215 |
| 216 EXPECT_EQ(kChannelLayout, buffer->channel_layout()); |
| 217 EXPECT_EQ(kFrameCount, buffer->frame_count()); |
| 218 EXPECT_EQ(kSampleRate, buffer->sample_rate()); |
| 219 EXPECT_EQ(kFrameCount, buffer->frame_count()); |
| 220 EXPECT_EQ(kNoTimestamp, buffer->timestamp()); |
| 221 EXPECT_TRUE(buffer->IsBitstreamFormat()); |
| 222 EXPECT_FALSE(buffer->end_of_stream()); |
| 223 } |
| 224 |
183 TEST(AudioBufferTest, CreateEOSBuffer) { | 225 TEST(AudioBufferTest, CreateEOSBuffer) { |
184 scoped_refptr<AudioBuffer> buffer = AudioBuffer::CreateEOSBuffer(); | 226 scoped_refptr<AudioBuffer> buffer = AudioBuffer::CreateEOSBuffer(); |
185 EXPECT_TRUE(buffer->end_of_stream()); | 227 EXPECT_TRUE(buffer->end_of_stream()); |
186 } | 228 } |
187 | 229 |
188 TEST(AudioBufferTest, FrameSize) { | 230 TEST(AudioBufferTest, FrameSize) { |
189 const uint8_t kTestData[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, | 231 const uint8_t kTestData[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, |
190 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, | 232 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, |
191 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}; | 233 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}; |
192 const base::TimeDelta kTimestamp = base::TimeDelta::FromMicroseconds(1337); | 234 const base::TimeDelta kTimestamp = base::TimeDelta::FromMicroseconds(1337); |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 | 551 |
510 // Mark pool for destruction and ensure buffer is still valid. | 552 // Mark pool for destruction and ensure buffer is still valid. |
511 pool = nullptr; | 553 pool = nullptr; |
512 memset(b1->channel_data()[0], 0, b1->frame_count()); | 554 memset(b1->channel_data()[0], 0, b1->frame_count()); |
513 | 555 |
514 // Destruct final frame after pool; hope nothing explodes. | 556 // Destruct final frame after pool; hope nothing explodes. |
515 b1 = nullptr; | 557 b1 = nullptr; |
516 } | 558 } |
517 | 559 |
518 } // namespace media | 560 } // namespace media |
OLD | NEW |