OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "media/base/test_data_util.h" | 5 #include "media/base/test_data_util.h" |
6 #include "media/formats/common/stream_parser_test_base.h" | 6 #include "media/formats/common/stream_parser_test_base.h" |
7 #include "media/formats/mpeg/mp3_stream_parser.h" | 7 #include "media/formats/mpeg/mpeg1_audio_stream_parser.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace media { | 10 namespace media { |
11 | 11 |
12 class MP3StreamParserTest : public StreamParserTestBase, public testing::Test { | 12 class MPEG1AudioStreamParserTest |
| 13 : public StreamParserTestBase, public testing::Test { |
13 public: | 14 public: |
14 MP3StreamParserTest() | 15 MPEG1AudioStreamParserTest() |
15 : StreamParserTestBase( | 16 : StreamParserTestBase( |
16 scoped_ptr<StreamParser>(new MP3StreamParser()).Pass()) {} | 17 scoped_ptr<StreamParser>(new MPEG1AudioStreamParser()).Pass()) {} |
17 virtual ~MP3StreamParserTest() {} | 18 virtual ~MPEG1AudioStreamParserTest() {} |
18 }; | 19 }; |
19 | 20 |
20 // Test parsing with small prime sized chunks to smoke out "power of | 21 // Test parsing with small prime sized chunks to smoke out "power of |
21 // 2" field size assumptions. | 22 // 2" field size assumptions. |
22 TEST_F(MP3StreamParserTest, UnalignedAppend) { | 23 TEST_F(MPEG1AudioStreamParserTest, UnalignedAppend) { |
23 const std::string expected = | 24 const std::string expected = |
24 "NewSegment" | 25 "NewSegment" |
25 "{ 0K }" | 26 "{ 0K }" |
26 "{ 0K }" | 27 "{ 0K }" |
27 "{ 0K }" | 28 "{ 0K }" |
28 "{ 0K }" | 29 "{ 0K }" |
29 "{ 0K }" | 30 "{ 0K }" |
30 "{ 0K }" | 31 "{ 0K }" |
31 "{ 0K }" | 32 "{ 0K }" |
32 "EndOfSegment" | 33 "EndOfSegment" |
33 "NewSegment" | 34 "NewSegment" |
34 "{ 0K }" | 35 "{ 0K }" |
35 "{ 0K }" | 36 "{ 0K }" |
36 "{ 0K }" | 37 "{ 0K }" |
37 "EndOfSegment" | 38 "EndOfSegment" |
38 "NewSegment" | 39 "NewSegment" |
39 "{ 0K }" | 40 "{ 0K }" |
40 "{ 0K }" | 41 "{ 0K }" |
41 "EndOfSegment"; | 42 "EndOfSegment"; |
42 EXPECT_EQ(expected, ParseFile("sfx.mp3", 17)); | 43 EXPECT_EQ(expected, ParseFile("sfx.mp3", 17)); |
43 EXPECT_GT(last_audio_config().codec_delay(), 0); | 44 EXPECT_GT(last_audio_config().codec_delay(), 0); |
44 } | 45 } |
45 | 46 |
46 // Test parsing with a larger piece size to verify that multiple buffers | 47 // Test parsing with a larger piece size to verify that multiple buffers |
47 // are passed to |new_buffer_cb_|. | 48 // are passed to |new_buffer_cb_|. |
48 TEST_F(MP3StreamParserTest, UnalignedAppend512) { | 49 TEST_F(MPEG1AudioStreamParserTest, UnalignedAppend512) { |
49 const std::string expected = | 50 const std::string expected = |
50 "NewSegment" | 51 "NewSegment" |
51 "{ 0K 26K 52K 78K }" | 52 "{ 0K 26K 52K 78K }" |
52 "EndOfSegment" | 53 "EndOfSegment" |
53 "NewSegment" | 54 "NewSegment" |
54 "{ 0K 26K 52K }" | 55 "{ 0K 26K 52K }" |
55 "{ 0K 26K 52K 78K }" | 56 "{ 0K 26K 52K 78K }" |
56 "{ 0K }" | 57 "{ 0K }" |
57 "EndOfSegment"; | 58 "EndOfSegment"; |
58 EXPECT_EQ(expected, ParseFile("sfx.mp3", 512)); | 59 EXPECT_EQ(expected, ParseFile("sfx.mp3", 512)); |
59 EXPECT_GT(last_audio_config().codec_delay(), 0); | 60 EXPECT_GT(last_audio_config().codec_delay(), 0); |
60 } | 61 } |
61 | 62 |
62 TEST_F(MP3StreamParserTest, MetadataParsing) { | 63 TEST_F(MPEG1AudioStreamParserTest, MetadataParsing) { |
63 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("sfx.mp3"); | 64 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("sfx.mp3"); |
64 const uint8_t* buffer_ptr = buffer->data(); | 65 const uint8_t* buffer_ptr = buffer->data(); |
65 | 66 |
66 // The first 32 bytes of sfx.mp3 are an ID3 tag, so no segments should be | 67 // The first 32 bytes of sfx.mp3 are an ID3 tag, so no segments should be |
67 // extracted after appending those bytes. | 68 // extracted after appending those bytes. |
68 const int kId3TagSize = 32; | 69 const int kId3TagSize = 32; |
69 EXPECT_EQ("", ParseData(buffer_ptr, kId3TagSize)); | 70 EXPECT_EQ("", ParseData(buffer_ptr, kId3TagSize)); |
70 EXPECT_FALSE(last_audio_config().IsValidConfig()); | 71 EXPECT_FALSE(last_audio_config().IsValidConfig()); |
71 buffer_ptr += kId3TagSize; | 72 buffer_ptr += kId3TagSize; |
72 | 73 |
(...skipping 13 matching lines...) Expand all Loading... |
86 buffer_ptr += kXingRemainingSize; | 87 buffer_ptr += kXingRemainingSize; |
87 | 88 |
88 // Append the first real frame and ensure we get a segment. | 89 // Append the first real frame and ensure we get a segment. |
89 const int kFirstRealFrameSize = 182; | 90 const int kFirstRealFrameSize = 182; |
90 EXPECT_EQ("NewSegment{ 0K }EndOfSegment", | 91 EXPECT_EQ("NewSegment{ 0K }EndOfSegment", |
91 ParseData(buffer_ptr, kFirstRealFrameSize)); | 92 ParseData(buffer_ptr, kFirstRealFrameSize)); |
92 EXPECT_TRUE(last_audio_config().IsValidConfig()); | 93 EXPECT_TRUE(last_audio_config().IsValidConfig()); |
93 } | 94 } |
94 | 95 |
95 } // namespace media | 96 } // namespace media |
OLD | NEW |