Delete chrome.mediaGalleriesPrivate because the functionality unique to it has since...
[chromium-blink-merge.git] / media / formats / common / stream_parser_test_base.cc
blob41892d1e2ce1a261fa5fdd471dd98ef3954b97a1
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"
7 #include "base/bind.h"
8 #include "media/base/test_data_util.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace media {
13 static std::string BufferQueueToString(
14 const StreamParser::BufferQueue& buffers) {
15 std::stringstream ss;
17 ss << "{";
18 for (StreamParser::BufferQueue::const_iterator itr = buffers.begin();
19 itr != buffers.end();
20 ++itr) {
21 ss << " " << (*itr)->timestamp().InMilliseconds();
22 if ((*itr)->is_key_frame())
23 ss << "K";
25 ss << " }";
27 return ss.str();
30 StreamParserTestBase::StreamParserTestBase(
31 scoped_ptr<StreamParser> stream_parser)
32 : parser_(stream_parser.Pass()) {
33 parser_->Init(
34 base::Bind(&StreamParserTestBase::OnInitDone, base::Unretained(this)),
35 base::Bind(&StreamParserTestBase::OnNewConfig, base::Unretained(this)),
36 base::Bind(&StreamParserTestBase::OnNewBuffers, base::Unretained(this)),
37 true,
38 base::Bind(&StreamParserTestBase::OnKeyNeeded, base::Unretained(this)),
39 base::Bind(&StreamParserTestBase::OnNewSegment, base::Unretained(this)),
40 base::Bind(&StreamParserTestBase::OnEndOfSegment, base::Unretained(this)),
41 LogCB());
44 StreamParserTestBase::~StreamParserTestBase() {}
46 std::string StreamParserTestBase::ParseFile(const std::string& filename,
47 int append_bytes) {
48 results_stream_.clear();
49 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile(filename);
50 EXPECT_TRUE(
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,
62 size_t length,
63 size_t piece_size) {
64 const uint8* start = data;
65 const uint8* end = data + length;
66 while (start < end) {
67 size_t append_size = std::min(piece_size, static_cast<size_t>(end - start));
68 if (!parser_->Parse(start, append_size))
69 return false;
70 start += append_size;
72 return true;
75 void StreamParserTestBase::OnInitDone(
76 bool success,
77 const StreamParser::InitParameters& params) {
78 EXPECT_TRUE(params.auto_update_timestamp_offset);
79 DVLOG(1) << __FUNCTION__ << "(" << success << ", "
80 << params.duration.InMilliseconds() << ", "
81 << params.auto_update_timestamp_offset << ")";
84 bool StreamParserTestBase::OnNewConfig(
85 const AudioDecoderConfig& audio_config,
86 const VideoDecoderConfig& video_config,
87 const StreamParser::TextTrackConfigMap& text_config) {
88 DVLOG(1) << __FUNCTION__ << "(" << audio_config.IsValidConfig() << ", "
89 << video_config.IsValidConfig() << ")";
90 EXPECT_TRUE(audio_config.IsValidConfig());
91 EXPECT_FALSE(video_config.IsValidConfig());
92 last_audio_config_ = audio_config;
93 return true;
96 bool StreamParserTestBase::OnNewBuffers(
97 const StreamParser::BufferQueue& audio_buffers,
98 const StreamParser::BufferQueue& video_buffers,
99 const StreamParser::TextBufferQueueMap& text_map) {
100 EXPECT_FALSE(audio_buffers.empty());
101 EXPECT_TRUE(video_buffers.empty());
103 // TODO(wolenetz/acolwell): Add text track support to more MSE parsers. See
104 // http://crbug.com/336926.
105 EXPECT_TRUE(text_map.empty());
107 const std::string buffers_str = BufferQueueToString(audio_buffers);
108 DVLOG(1) << __FUNCTION__ << " : " << buffers_str;
109 results_stream_ << buffers_str;
110 return true;
113 void StreamParserTestBase::OnKeyNeeded(const std::string& type,
114 const std::vector<uint8>& init_data) {
115 DVLOG(1) << __FUNCTION__ << "(" << type << ", " << init_data.size() << ")";
118 void StreamParserTestBase::OnNewSegment() {
119 DVLOG(1) << __FUNCTION__;
120 results_stream_ << "NewSegment";
123 void StreamParserTestBase::OnEndOfSegment() {
124 DVLOG(1) << __FUNCTION__;
125 results_stream_ << "EndOfSegment";
128 } // namespace media