OLD | NEW |
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/string_util.h" | 5 #include "base/string_util.h" |
6 #include "media/base/decoder_buffer.h" | 6 #include "media/base/decoder_buffer.h" |
7 #if !defined(OS_ANDROID) | |
8 #include "media/ffmpeg/ffmpeg_common.h" | |
9 #endif | |
10 | |
11 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
12 | 8 |
13 namespace media { | 9 namespace media { |
14 | 10 |
15 TEST(DecoderBufferTest, Constructors) { | 11 TEST(DecoderBufferTest, Constructors) { |
16 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(0)); | 12 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(0)); |
17 EXPECT_TRUE(buffer->GetData()); | 13 EXPECT_TRUE(buffer->GetData()); |
18 EXPECT_EQ(0, buffer->GetDataSize()); | 14 EXPECT_EQ(0, buffer->GetDataSize()); |
19 EXPECT_FALSE(buffer->IsEndOfStream()); | 15 EXPECT_FALSE(buffer->IsEndOfStream()); |
20 | 16 |
(...skipping 23 matching lines...) Expand all Loading... |
44 } | 40 } |
45 | 41 |
46 #if !defined(OS_ANDROID) | 42 #if !defined(OS_ANDROID) |
47 TEST(DecoderBufferTest, PaddingAlignment) { | 43 TEST(DecoderBufferTest, PaddingAlignment) { |
48 const uint8 kData[] = "hello"; | 44 const uint8 kData[] = "hello"; |
49 const int kDataSize = arraysize(kData); | 45 const int kDataSize = arraysize(kData); |
50 scoped_refptr<DecoderBuffer> buffer2(DecoderBuffer::CopyFrom( | 46 scoped_refptr<DecoderBuffer> buffer2(DecoderBuffer::CopyFrom( |
51 reinterpret_cast<const uint8*>(&kData), kDataSize)); | 47 reinterpret_cast<const uint8*>(&kData), kDataSize)); |
52 ASSERT_TRUE(buffer2); | 48 ASSERT_TRUE(buffer2); |
53 | 49 |
54 // FFmpeg padding data should always be zeroed. | 50 // Padding data should always be zeroed. |
55 for(int i = 0; i < FF_INPUT_BUFFER_PADDING_SIZE; i++) | 51 for(int i = 0; i < DecoderBuffer::kPaddingSize; i++) |
56 EXPECT_EQ((buffer2->GetData() + kDataSize)[i], 0); | 52 EXPECT_EQ((buffer2->GetData() + kDataSize)[i], 0); |
57 | 53 |
58 // If the data is padded correctly we should be able to read and write past | 54 // If the data is padded correctly we should be able to read and write past |
59 // the end of the data by FF_INPUT_BUFFER_PADDING_SIZE bytes without crashing | 55 // the end of the data by DecoderBuffer::kPaddingSize bytes without crashing |
60 // or Valgrind/ASAN throwing errors. | 56 // or Valgrind/ASAN throwing errors. |
61 const uint8 kFillChar = 0xFF; | 57 const uint8 kFillChar = 0xFF; |
62 memset( | 58 memset( |
63 buffer2->GetWritableData() + kDataSize, kFillChar, | 59 buffer2->GetWritableData() + kDataSize, kFillChar, |
64 FF_INPUT_BUFFER_PADDING_SIZE); | 60 DecoderBuffer::kPaddingSize); |
65 for(int i = 0; i < FF_INPUT_BUFFER_PADDING_SIZE; i++) | 61 for(int i = 0; i < DecoderBuffer::kPaddingSize; i++) |
66 EXPECT_EQ((buffer2->GetData() + kDataSize)[i], kFillChar); | 62 EXPECT_EQ((buffer2->GetData() + kDataSize)[i], kFillChar); |
67 | 63 |
68 // These alignments will need to be updated to match FFmpeg when it changes. | |
69 #if defined(ARCH_CPU_ARM_FAMILY) | |
70 // FFmpeg data should be aligned on a 16 byte boundary for ARM. | |
71 const int kDataAlignment = 16; | |
72 #else | |
73 // FFmpeg data should be aligned on a 32 byte boundary for x86. | |
74 const int kDataAlignment = 32; | |
75 #endif | |
76 EXPECT_EQ(0u, reinterpret_cast<uintptr_t>( | 64 EXPECT_EQ(0u, reinterpret_cast<uintptr_t>( |
77 buffer2->GetData()) & (kDataAlignment - 1)); | 65 buffer2->GetData()) & (DecoderBuffer::kAlignmentSize - 1)); |
78 } | 66 } |
79 #endif | 67 #endif |
80 | 68 |
81 TEST(DecoderBufferTest, ReadingWriting) { | 69 TEST(DecoderBufferTest, ReadingWriting) { |
82 const char kData[] = "hello"; | 70 const char kData[] = "hello"; |
83 const int kDataSize = arraysize(kData); | 71 const int kDataSize = arraysize(kData); |
84 | 72 |
85 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(kDataSize)); | 73 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(kDataSize)); |
86 ASSERT_TRUE(buffer); | 74 ASSERT_TRUE(buffer); |
87 | 75 |
88 uint8* data = buffer->GetWritableData(); | 76 uint8* data = buffer->GetWritableData(); |
89 ASSERT_TRUE(data); | 77 ASSERT_TRUE(data); |
90 ASSERT_EQ(kDataSize, buffer->GetDataSize()); | 78 ASSERT_EQ(kDataSize, buffer->GetDataSize()); |
91 memcpy(data, kData, kDataSize); | 79 memcpy(data, kData, kDataSize); |
92 const uint8* read_only_data = buffer->GetData(); | 80 const uint8* read_only_data = buffer->GetData(); |
93 ASSERT_EQ(data, read_only_data); | 81 ASSERT_EQ(data, read_only_data); |
94 ASSERT_EQ(0, memcmp(read_only_data, kData, kDataSize)); | 82 ASSERT_EQ(0, memcmp(read_only_data, kData, kDataSize)); |
95 EXPECT_FALSE(buffer->IsEndOfStream()); | 83 EXPECT_FALSE(buffer->IsEndOfStream()); |
96 } | 84 } |
97 | 85 |
98 TEST(DecoderBufferTest, GetDecryptConfig) { | 86 TEST(DecoderBufferTest, GetDecryptConfig) { |
99 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(0)); | 87 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(0)); |
100 EXPECT_FALSE(buffer->GetDecryptConfig()); | 88 EXPECT_FALSE(buffer->GetDecryptConfig()); |
101 } | 89 } |
102 | 90 |
103 } // namespace media | 91 } // namespace media |
OLD | NEW |