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