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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 } | 406 } |
404 | 407 |
405 int bytes_parsed = cluster_parser_->Parse(data, size); | 408 int bytes_parsed = cluster_parser_->Parse(data, size); |
406 | 409 |
407 if (bytes_parsed <= 0) | 410 if (bytes_parsed <= 0) |
408 return bytes_parsed; | 411 return bytes_parsed; |
409 | 412 |
410 const BufferQueue& audio_buffers = cluster_parser_->audio_buffers(); | 413 const BufferQueue& audio_buffers = cluster_parser_->audio_buffers(); |
411 const BufferQueue& video_buffers = cluster_parser_->video_buffers(); | 414 const BufferQueue& video_buffers = cluster_parser_->video_buffers(); |
412 base::TimeDelta cluster_start_time = cluster_parser_->cluster_start_time(); | 415 base::TimeDelta cluster_start_time = cluster_parser_->cluster_start_time(); |
| 416 bool cluster_ended = cluster_parser_->cluster_ended(); |
413 | 417 |
414 if (waiting_for_buffers_ && cluster_start_time != kNoTimestamp()) { | 418 if (waiting_for_buffers_ && cluster_start_time != kNoTimestamp()) { |
415 new_segment_cb_.Run(cluster_start_time); | 419 new_segment_cb_.Run(cluster_start_time); |
416 waiting_for_buffers_ = false; | 420 waiting_for_buffers_ = false; |
417 } | 421 } |
418 | 422 |
419 if (!audio_buffers.empty() && !audio_cb_.Run(audio_buffers)) | 423 if (!audio_buffers.empty() && !audio_cb_.Run(audio_buffers)) |
420 return -1; | 424 return -1; |
421 | 425 |
422 if (!video_buffers.empty() && !video_cb_.Run(video_buffers)) | 426 if (!video_buffers.empty() && !video_cb_.Run(video_buffers)) |
423 return -1; | 427 return -1; |
424 | 428 |
| 429 if (cluster_ended) |
| 430 end_of_segment_cb_.Run(); |
| 431 |
425 return bytes_parsed; | 432 return bytes_parsed; |
426 } | 433 } |
427 | 434 |
428 } // namespace media | 435 } // namespace media |
OLD | NEW |