Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / media / formats / mpeg / mpeg1_audio_stream_parser_unittest.cc
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
3 // found in the LICENSE file.
4
5 #include "media/base/test_data_util.h"
6 #include "media/formats/common/stream_parser_test_base.h"
7 #include "media/formats/mpeg/mpeg1_audio_stream_parser.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace media {
11
12 class MPEG1AudioStreamParserTest
13     : public StreamParserTestBase, public testing::Test {
14  public:
15   MPEG1AudioStreamParserTest()
16       : StreamParserTestBase(
17             scoped_ptr<StreamParser>(new MPEG1AudioStreamParser()).Pass()) {}
18   virtual ~MPEG1AudioStreamParserTest() {}
19 };
20
21 // Test parsing with small prime sized chunks to smoke out "power of
22 // 2" field size assumptions.
23 TEST_F(MPEG1AudioStreamParserTest, UnalignedAppend) {
24   const std::string expected =
25       "NewSegment"
26       "{ 0K }"
27       "{ 0K }"
28       "{ 0K }"
29       "{ 0K }"
30       "{ 0K }"
31       "{ 0K }"
32       "{ 0K }"
33       "EndOfSegment"
34       "NewSegment"
35       "{ 0K }"
36       "{ 0K }"
37       "{ 0K }"
38       "EndOfSegment"
39       "NewSegment"
40       "{ 0K }"
41       "{ 0K }"
42       "EndOfSegment";
43   EXPECT_EQ(expected, ParseFile("sfx.mp3", 17));
44   EXPECT_GT(last_audio_config().codec_delay(), 0);
45 }
46
47 // Test parsing with a larger piece size to verify that multiple buffers
48 // are passed to |new_buffer_cb_|.
49 TEST_F(MPEG1AudioStreamParserTest, UnalignedAppend512) {
50   const std::string expected =
51       "NewSegment"
52       "{ 0K 26K 52K 78K }"
53       "EndOfSegment"
54       "NewSegment"
55       "{ 0K 26K 52K }"
56       "{ 0K 26K 52K 78K }"
57       "{ 0K }"
58       "EndOfSegment";
59   EXPECT_EQ(expected, ParseFile("sfx.mp3", 512));
60   EXPECT_GT(last_audio_config().codec_delay(), 0);
61 }
62
63 TEST_F(MPEG1AudioStreamParserTest, MetadataParsing) {
64   scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("sfx.mp3");
65   const uint8_t* buffer_ptr = buffer->data();
66
67   // The first 32 bytes of sfx.mp3 are an ID3 tag, so no segments should be
68   // extracted after appending those bytes.
69   const int kId3TagSize = 32;
70   EXPECT_EQ("", ParseData(buffer_ptr, kId3TagSize));
71   EXPECT_FALSE(last_audio_config().IsValidConfig());
72   buffer_ptr += kId3TagSize;
73
74   // The next 417 bytes are a Xing frame; with the identifier 21 bytes into
75   // the frame.  Appending less than 21 bytes, should result in no segments
76   // nor an AudioDecoderConfig being created.
77   const int kXingTagPosition = 21;
78   EXPECT_EQ("", ParseData(buffer_ptr, kXingTagPosition));
79   EXPECT_FALSE(last_audio_config().IsValidConfig());
80   buffer_ptr += kXingTagPosition;
81
82   // Appending the rests of the Xing frame should result in no segments, but
83   // should generate a valid AudioDecoderConfig.
84   const int kXingRemainingSize = 417 - kXingTagPosition;
85   EXPECT_EQ("", ParseData(buffer_ptr, kXingRemainingSize));
86   EXPECT_TRUE(last_audio_config().IsValidConfig());
87   buffer_ptr += kXingRemainingSize;
88
89   // Append the first real frame and ensure we get a segment.
90   const int kFirstRealFrameSize = 182;
91   EXPECT_EQ("NewSegment{ 0K }EndOfSegment",
92             ParseData(buffer_ptr, kFirstRealFrameSize));
93   EXPECT_TRUE(last_audio_config().IsValidConfig());
94 }
95
96 }  // namespace media