OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/webm/webm_stream_parser.h" | 5 #include "media/webm/webm_stream_parser.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "media/ffmpeg/ffmpeg_common.h" | 9 #include "media/ffmpeg/ffmpeg_common.h" |
10 #include "media/filters/ffmpeg_glue.h" | 10 #include "media/filters/ffmpeg_glue.h" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 waiting_for_buffers_(false) { | 185 waiting_for_buffers_(false) { |
186 } | 186 } |
187 | 187 |
188 WebMStreamParser::~WebMStreamParser() {} | 188 WebMStreamParser::~WebMStreamParser() {} |
189 | 189 |
190 void WebMStreamParser::Init(const InitCB& init_cb, | 190 void WebMStreamParser::Init(const InitCB& init_cb, |
191 const NewConfigCB& config_cb, | 191 const NewConfigCB& config_cb, |
192 const NewBuffersCB& audio_cb, | 192 const NewBuffersCB& audio_cb, |
193 const NewBuffersCB& video_cb, | 193 const NewBuffersCB& video_cb, |
194 const NeedKeyCB& need_key_cb, | 194 const NeedKeyCB& need_key_cb, |
195 const NewMediaSegmentCB& new_segment_cb) { | 195 const NewMediaSegmentCB& new_segment_cb, |
| 196 const base::Closure& end_of_segment_cb) { |
196 DCHECK_EQ(state_, kWaitingForInit); | 197 DCHECK_EQ(state_, kWaitingForInit); |
197 DCHECK(init_cb_.is_null()); | 198 DCHECK(init_cb_.is_null()); |
198 DCHECK(!init_cb.is_null()); | 199 DCHECK(!init_cb.is_null()); |
199 DCHECK(!config_cb.is_null()); | 200 DCHECK(!config_cb.is_null()); |
200 DCHECK(!audio_cb.is_null() || !video_cb.is_null()); | 201 DCHECK(!audio_cb.is_null() || !video_cb.is_null()); |
201 DCHECK(!need_key_cb.is_null()); | 202 DCHECK(!need_key_cb.is_null()); |
202 DCHECK(!new_segment_cb.is_null()); | 203 DCHECK(!new_segment_cb.is_null()); |
| 204 DCHECK(!end_of_segment_cb.is_null()); |
203 | 205 |
204 ChangeState(kParsingHeaders); | 206 ChangeState(kParsingHeaders); |
205 init_cb_ = init_cb; | 207 init_cb_ = init_cb; |
206 config_cb_ = config_cb; | 208 config_cb_ = config_cb; |
207 audio_cb_ = audio_cb; | 209 audio_cb_ = audio_cb; |
208 video_cb_ = video_cb; | 210 video_cb_ = video_cb; |
209 need_key_cb_ = need_key_cb; | 211 need_key_cb_ = need_key_cb; |
210 new_segment_cb_ = new_segment_cb; | 212 new_segment_cb_ = new_segment_cb; |
| 213 end_of_segment_cb_ = end_of_segment_cb; |
211 } | 214 } |
212 | 215 |
213 void WebMStreamParser::Flush() { | 216 void WebMStreamParser::Flush() { |
214 DCHECK_NE(state_, kWaitingForInit); | 217 DCHECK_NE(state_, kWaitingForInit); |
215 | 218 |
216 byte_queue_.Reset(); | 219 byte_queue_.Reset(); |
217 | 220 |
218 if (state_ != kParsingClusters) | 221 if (state_ != kParsingClusters) |
219 return; | 222 return; |
220 | 223 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 } | 407 } |
405 | 408 |
406 int bytes_parsed = cluster_parser_->Parse(data, size); | 409 int bytes_parsed = cluster_parser_->Parse(data, size); |
407 | 410 |
408 if (bytes_parsed <= 0) | 411 if (bytes_parsed <= 0) |
409 return bytes_parsed; | 412 return bytes_parsed; |
410 | 413 |
411 const BufferQueue& audio_buffers = cluster_parser_->audio_buffers(); | 414 const BufferQueue& audio_buffers = cluster_parser_->audio_buffers(); |
412 const BufferQueue& video_buffers = cluster_parser_->video_buffers(); | 415 const BufferQueue& video_buffers = cluster_parser_->video_buffers(); |
413 base::TimeDelta cluster_start_time = cluster_parser_->cluster_start_time(); | 416 base::TimeDelta cluster_start_time = cluster_parser_->cluster_start_time(); |
| 417 bool cluster_ended = cluster_parser_->cluster_ended(); |
414 | 418 |
415 if (waiting_for_buffers_ && cluster_start_time != kNoTimestamp()) { | 419 if (waiting_for_buffers_ && cluster_start_time != kNoTimestamp()) { |
416 new_segment_cb_.Run(cluster_start_time); | 420 new_segment_cb_.Run(cluster_start_time); |
417 waiting_for_buffers_ = false; | 421 waiting_for_buffers_ = false; |
418 } | 422 } |
419 | 423 |
420 if (!audio_buffers.empty() && !audio_cb_.Run(audio_buffers)) | 424 if (!audio_buffers.empty() && !audio_cb_.Run(audio_buffers)) |
421 return -1; | 425 return -1; |
422 | 426 |
423 if (!video_buffers.empty() && !video_cb_.Run(video_buffers)) | 427 if (!video_buffers.empty() && !video_cb_.Run(video_buffers)) |
424 return -1; | 428 return -1; |
425 | 429 |
| 430 if (cluster_ended) |
| 431 end_of_segment_cb_.Run(); |
| 432 |
426 return bytes_parsed; | 433 return bytes_parsed; |
427 } | 434 } |
428 | 435 |
429 } // namespace media | 436 } // namespace media |
OLD | NEW |