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/formats/mp2t/mp2t_stream_parser.h" | 5 #include "media/formats/mp2t/mp2t_stream_parser.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 return true; | 111 return true; |
112 } | 112 } |
113 | 113 |
114 void OnInit(const StreamParser::InitParameters& params) { | 114 void OnInit(const StreamParser::InitParameters& params) { |
115 DVLOG(1) << "OnInit: dur=" << params.duration.InMilliseconds() | 115 DVLOG(1) << "OnInit: dur=" << params.duration.InMilliseconds() |
116 << ", autoTimestampOffset=" << params.auto_update_timestamp_offset; | 116 << ", autoTimestampOffset=" << params.auto_update_timestamp_offset; |
117 } | 117 } |
118 | 118 |
119 bool OnNewConfig(std::unique_ptr<MediaTracks> tracks, | 119 bool OnNewConfig(std::unique_ptr<MediaTracks> tracks, |
120 const StreamParser::TextTrackConfigMap& tc) { | 120 const StreamParser::TextTrackConfigMap& tc) { |
121 const AudioDecoderConfig& ac = tracks->getFirstAudioConfig(); | 121 DVLOG(1) << "OnNewConfig: got " << tracks->tracks().size() << " tracks"; |
122 const VideoDecoderConfig& vc = tracks->getFirstVideoConfig(); | 122 bool found_audio_track = false; |
123 DVLOG(1) << "OnNewConfig: media tracks count=" << tracks->tracks().size() | 123 bool found_video_track = false; |
124 << ", audio=" << ac.IsValidConfig() | 124 for (const auto& track : tracks->tracks()) { |
125 << ", video=" << vc.IsValidConfig(); | 125 const auto& track_id = track->bytestream_track_id(); |
| 126 if (track->type() == MediaTrack::Audio) { |
| 127 found_audio_track = true; |
| 128 EXPECT_TRUE(tracks->getAudioConfig(track_id).IsValidConfig()); |
| 129 } else if (track->type() == MediaTrack::Video) { |
| 130 found_video_track = true; |
| 131 EXPECT_TRUE(tracks->getVideoConfig(track_id).IsValidConfig()); |
| 132 } else { |
| 133 // Unexpected track type. |
| 134 LOG(ERROR) << "Unexpected track type " << track->type(); |
| 135 EXPECT_TRUE(false); |
| 136 } |
| 137 } |
| 138 EXPECT_TRUE(found_audio_track); |
| 139 EXPECT_EQ(has_video_, found_video_track); |
126 config_count_++; | 140 config_count_++; |
127 EXPECT_TRUE(ac.IsValidConfig()); | |
128 EXPECT_EQ(vc.IsValidConfig(), has_video_); | |
129 return true; | 141 return true; |
130 } | 142 } |
131 | 143 |
132 | 144 |
133 void DumpBuffers(const std::string& label, | 145 void DumpBuffers(const std::string& label, |
134 const StreamParser::BufferQueue& buffers) { | 146 const StreamParser::BufferQueue& buffers) { |
135 DVLOG(2) << "DumpBuffers: " << label << " size " << buffers.size(); | 147 DVLOG(2) << "DumpBuffers: " << label << " size " << buffers.size(); |
136 for (StreamParser::BufferQueue::const_iterator buf = buffers.begin(); | 148 for (StreamParser::BufferQueue::const_iterator buf = buffers.begin(); |
137 buf != buffers.end(); buf++) { | 149 buf != buffers.end(); buf++) { |
138 DVLOG(3) << " n=" << buf - buffers.begin() | 150 DVLOG(3) << " n=" << buf - buffers.begin() |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 audio_max_dts_ = last_dts; | 190 audio_max_dts_ = last_dts; |
179 } | 191 } |
180 | 192 |
181 audio_frame_count_ += audio_buffers.size(); | 193 audio_frame_count_ += audio_buffers.size(); |
182 video_frame_count_ += video_buffers.size(); | 194 video_frame_count_ += video_buffers.size(); |
183 return true; | 195 return true; |
184 } | 196 } |
185 | 197 |
186 void OnKeyNeeded(EmeInitDataType type, | 198 void OnKeyNeeded(EmeInitDataType type, |
187 const std::vector<uint8_t>& init_data) { | 199 const std::vector<uint8_t>& init_data) { |
188 NOTREACHED() << "OnKeyNeeded not expected in the Mpeg2 TS parser"; | 200 LOG(ERROR) << "OnKeyNeeded not expected in the Mpeg2 TS parser"; |
| 201 EXPECT_TRUE(false); |
189 } | 202 } |
190 | 203 |
191 void OnNewSegment() { | 204 void OnNewSegment() { |
192 DVLOG(1) << "OnNewSegment"; | 205 DVLOG(1) << "OnNewSegment"; |
193 segment_count_++; | 206 segment_count_++; |
194 } | 207 } |
195 | 208 |
196 void OnEndOfSegment() { | 209 void OnEndOfSegment() { |
197 NOTREACHED() << "OnEndOfSegment not expected in the Mpeg2 TS parser"; | 210 LOG(ERROR) << "OnEndOfSegment not expected in the Mpeg2 TS parser"; |
| 211 EXPECT_TRUE(false); |
198 } | 212 } |
199 | 213 |
200 void InitializeParser() { | 214 void InitializeParser() { |
201 parser_->Init( | 215 parser_->Init( |
202 base::Bind(&Mp2tStreamParserTest::OnInit, base::Unretained(this)), | 216 base::Bind(&Mp2tStreamParserTest::OnInit, base::Unretained(this)), |
203 base::Bind(&Mp2tStreamParserTest::OnNewConfig, base::Unretained(this)), | 217 base::Bind(&Mp2tStreamParserTest::OnNewConfig, base::Unretained(this)), |
204 base::Bind(&Mp2tStreamParserTest::OnNewBuffers, base::Unretained(this)), | 218 base::Bind(&Mp2tStreamParserTest::OnNewBuffers, base::Unretained(this)), |
205 true, | 219 true, |
206 base::Bind(&Mp2tStreamParserTest::OnKeyNeeded, base::Unretained(this)), | 220 base::Bind(&Mp2tStreamParserTest::OnKeyNeeded, base::Unretained(this)), |
207 base::Bind(&Mp2tStreamParserTest::OnNewSegment, base::Unretained(this)), | 221 base::Bind(&Mp2tStreamParserTest::OnNewSegment, base::Unretained(this)), |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 parser_->Flush(); | 311 parser_->Flush(); |
298 EXPECT_EQ(audio_frame_count_, 40); | 312 EXPECT_EQ(audio_frame_count_, 40); |
299 EXPECT_EQ(video_frame_count_, 0); | 313 EXPECT_EQ(video_frame_count_, 0); |
300 // This stream has no mid-stream configuration change. | 314 // This stream has no mid-stream configuration change. |
301 EXPECT_EQ(config_count_, 1); | 315 EXPECT_EQ(config_count_, 1); |
302 EXPECT_EQ(segment_count_, 1); | 316 EXPECT_EQ(segment_count_, 1); |
303 } | 317 } |
304 | 318 |
305 } // namespace mp2t | 319 } // namespace mp2t |
306 } // namespace media | 320 } // namespace media |
OLD | NEW |