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.
5 #include "media/formats/common/stream_parser_test_base.h"
8 #include "media/base/test_data_util.h"
9 #include "testing/gtest/include/gtest/gtest.h"
13 static std::string
BufferQueueToString(
14 const StreamParser::BufferQueue
& buffers
) {
18 for (StreamParser::BufferQueue::const_iterator itr
= buffers
.begin();
21 ss
<< " " << (*itr
)->timestamp().InMilliseconds();
22 if ((*itr
)->is_key_frame())
30 StreamParserTestBase::StreamParserTestBase(
31 scoped_ptr
<StreamParser
> stream_parser
)
32 : parser_(stream_parser
.Pass()) {
34 base::Bind(&StreamParserTestBase::OnInitDone
, base::Unretained(this)),
35 base::Bind(&StreamParserTestBase::OnNewConfig
, base::Unretained(this)),
36 base::Bind(&StreamParserTestBase::OnNewBuffers
, base::Unretained(this)),
38 base::Bind(&StreamParserTestBase::OnKeyNeeded
, base::Unretained(this)),
39 base::Bind(&StreamParserTestBase::OnNewSegment
, base::Unretained(this)),
40 base::Bind(&StreamParserTestBase::OnEndOfSegment
, base::Unretained(this)),
44 StreamParserTestBase::~StreamParserTestBase() {}
46 std::string
StreamParserTestBase::ParseFile(const std::string
& filename
,
48 results_stream_
.clear();
49 scoped_refptr
<DecoderBuffer
> buffer
= ReadTestDataFile(filename
);
51 AppendDataInPieces(buffer
->data(), buffer
->data_size(), append_bytes
));
52 return results_stream_
.str();
55 std::string
StreamParserTestBase::ParseData(const uint8
* data
, size_t length
) {
56 results_stream_
.clear();
57 EXPECT_TRUE(AppendDataInPieces(data
, length
, length
));
58 return results_stream_
.str();
61 bool StreamParserTestBase::AppendDataInPieces(const uint8
* data
,
64 const uint8
* start
= data
;
65 const uint8
* end
= data
+ length
;
67 size_t append_size
= std::min(piece_size
, static_cast<size_t>(end
- start
));
68 if (!parser_
->Parse(start
, append_size
))
75 void StreamParserTestBase::OnInitDone(
76 const StreamParser::InitParameters
& params
) {
77 EXPECT_TRUE(params
.auto_update_timestamp_offset
);
78 DVLOG(1) << __FUNCTION__
<< "(" << params
.duration
.InMilliseconds() << ", "
79 << params
.auto_update_timestamp_offset
<< ")";
82 bool StreamParserTestBase::OnNewConfig(
83 const AudioDecoderConfig
& audio_config
,
84 const VideoDecoderConfig
& video_config
,
85 const StreamParser::TextTrackConfigMap
& text_config
) {
86 DVLOG(1) << __FUNCTION__
<< "(" << audio_config
.IsValidConfig() << ", "
87 << video_config
.IsValidConfig() << ")";
88 EXPECT_TRUE(audio_config
.IsValidConfig());
89 EXPECT_FALSE(video_config
.IsValidConfig());
90 last_audio_config_
= audio_config
;
94 bool StreamParserTestBase::OnNewBuffers(
95 const StreamParser::BufferQueue
& audio_buffers
,
96 const StreamParser::BufferQueue
& video_buffers
,
97 const StreamParser::TextBufferQueueMap
& text_map
) {
98 EXPECT_FALSE(audio_buffers
.empty());
99 EXPECT_TRUE(video_buffers
.empty());
101 // TODO(wolenetz/acolwell): Add text track support to more MSE parsers. See
102 // http://crbug.com/336926.
103 EXPECT_TRUE(text_map
.empty());
105 const std::string buffers_str
= BufferQueueToString(audio_buffers
);
106 DVLOG(1) << __FUNCTION__
<< " : " << buffers_str
;
107 results_stream_
<< buffers_str
;
111 void StreamParserTestBase::OnKeyNeeded(EmeInitDataType type
,
112 const std::vector
<uint8
>& init_data
) {
113 DVLOG(1) << __FUNCTION__
<< "(" << static_cast<int>(type
) << ", "
114 << init_data
.size() << ")";
117 void StreamParserTestBase::OnNewSegment() {
118 DVLOG(1) << __FUNCTION__
;
119 results_stream_
<< "NewSegment";
122 void StreamParserTestBase::OnEndOfSegment() {
123 DVLOG(1) << __FUNCTION__
;
124 results_stream_
<< "EndOfSegment";