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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 : state_(kWaitingForInit), | 184 : state_(kWaitingForInit), |
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 KeyNeededCB& key_needed_cb, | 194 const NeedKeyCB& need_key_cb, |
195 const NewMediaSegmentCB& new_segment_cb) { | 195 const NewMediaSegmentCB& new_segment_cb) { |
196 DCHECK_EQ(state_, kWaitingForInit); | 196 DCHECK_EQ(state_, kWaitingForInit); |
197 DCHECK(init_cb_.is_null()); | 197 DCHECK(init_cb_.is_null()); |
198 DCHECK(!init_cb.is_null()); | 198 DCHECK(!init_cb.is_null()); |
199 DCHECK(!config_cb.is_null()); | 199 DCHECK(!config_cb.is_null()); |
200 DCHECK(!audio_cb.is_null() || !video_cb.is_null()); | 200 DCHECK(!audio_cb.is_null() || !video_cb.is_null()); |
201 DCHECK(!key_needed_cb.is_null()); | 201 DCHECK(!need_key_cb.is_null()); |
202 DCHECK(!new_segment_cb.is_null()); | 202 DCHECK(!new_segment_cb.is_null()); |
203 | 203 |
204 ChangeState(kParsingHeaders); | 204 ChangeState(kParsingHeaders); |
205 init_cb_ = init_cb; | 205 init_cb_ = init_cb; |
206 config_cb_ = config_cb; | 206 config_cb_ = config_cb; |
207 audio_cb_ = audio_cb; | 207 audio_cb_ = audio_cb; |
208 video_cb_ = video_cb; | 208 video_cb_ = video_cb; |
209 key_needed_cb_ = key_needed_cb; | 209 need_key_cb_ = need_key_cb; |
210 new_segment_cb_ = new_segment_cb; | 210 new_segment_cb_ = new_segment_cb; |
211 } | 211 } |
212 | 212 |
213 void WebMStreamParser::Flush() { | 213 void WebMStreamParser::Flush() { |
214 DCHECK_NE(state_, kWaitingForInit); | 214 DCHECK_NE(state_, kWaitingForInit); |
215 | 215 |
216 byte_queue_.Reset(); | 216 byte_queue_.Reset(); |
217 | 217 |
218 if (state_ != kParsingClusters) | 218 if (state_ != kParsingClusters) |
219 return; | 219 return; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 DVLOG(1) << "New config data isn't allowed."; | 347 DVLOG(1) << "New config data isn't allowed."; |
348 return -1; | 348 return -1; |
349 } | 349 } |
350 | 350 |
351 // TODO(xhwang): Support decryption of audio (see http://crbug.com/123421). | 351 // TODO(xhwang): Support decryption of audio (see http://crbug.com/123421). |
352 if (tracks_parser.video_encryption_key_id()) { | 352 if (tracks_parser.video_encryption_key_id()) { |
353 int key_id_size = tracks_parser.video_encryption_key_id_size(); | 353 int key_id_size = tracks_parser.video_encryption_key_id_size(); |
354 CHECK_GT(key_id_size, 0); | 354 CHECK_GT(key_id_size, 0); |
355 scoped_array<uint8> key_id(new uint8[key_id_size]); | 355 scoped_array<uint8> key_id(new uint8[key_id_size]); |
356 memcpy(key_id.get(), tracks_parser.video_encryption_key_id(), key_id_size); | 356 memcpy(key_id.get(), tracks_parser.video_encryption_key_id(), key_id_size); |
357 key_needed_cb_.Run(key_id.Pass(), key_id_size); | 357 need_key_cb_.Run(key_id.Pass(), key_id_size); |
358 } | 358 } |
359 | 359 |
360 cluster_parser_.reset(new WebMClusterParser( | 360 cluster_parser_.reset(new WebMClusterParser( |
361 info_parser.timecode_scale(), | 361 info_parser.timecode_scale(), |
362 tracks_parser.audio_track_num(), | 362 tracks_parser.audio_track_num(), |
363 tracks_parser.video_track_num(), | 363 tracks_parser.video_track_num(), |
364 tracks_parser.video_encryption_key_id(), | 364 tracks_parser.video_encryption_key_id(), |
365 tracks_parser.video_encryption_key_id_size())); | 365 tracks_parser.video_encryption_key_id_size())); |
366 | 366 |
367 ChangeState(kParsingClusters); | 367 ChangeState(kParsingClusters); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 if (!audio_buffers.empty() && !audio_cb_.Run(audio_buffers)) | 433 if (!audio_buffers.empty() && !audio_cb_.Run(audio_buffers)) |
434 return -1; | 434 return -1; |
435 | 435 |
436 if (!video_buffers.empty() && !video_cb_.Run(video_buffers)) | 436 if (!video_buffers.empty() && !video_cb_.Run(video_buffers)) |
437 return -1; | 437 return -1; |
438 | 438 |
439 return bytes_parsed; | 439 return bytes_parsed; |
440 } | 440 } |
441 | 441 |
442 } // namespace media | 442 } // namespace media |
OLD | NEW |