| 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/webm/webm_stream_parser.h" | 5 #include "media/formats/webm/webm_stream_parser.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 WebMStreamParser::~WebMStreamParser() { | 26 WebMStreamParser::~WebMStreamParser() { |
| 27 } | 27 } |
| 28 | 28 |
| 29 void WebMStreamParser::Init( | 29 void WebMStreamParser::Init( |
| 30 const InitCB& init_cb, | 30 const InitCB& init_cb, |
| 31 const NewConfigCB& config_cb, | 31 const NewConfigCB& config_cb, |
| 32 const NewBuffersCB& new_buffers_cb, | 32 const NewBuffersCB& new_buffers_cb, |
| 33 bool ignore_text_tracks, | 33 bool ignore_text_tracks, |
| 34 const EncryptedMediaInitDataCB& encrypted_media_init_data_cb, | 34 const EncryptedMediaInitDataCB& encrypted_media_init_data_cb, |
| 35 const NewMediaSegmentCB& new_segment_cb, | 35 const NewMediaSegmentCB& new_segment_cb, |
| 36 const base::Closure& end_of_segment_cb, | 36 const EndMediaSegmentCB& end_of_segment_cb, |
| 37 const scoped_refptr<MediaLog>& media_log) { | 37 const scoped_refptr<MediaLog>& media_log) { |
| 38 DCHECK_EQ(state_, kWaitingForInit); | 38 DCHECK_EQ(state_, kWaitingForInit); |
| 39 DCHECK(init_cb_.is_null()); | 39 DCHECK(init_cb_.is_null()); |
| 40 DCHECK(!init_cb.is_null()); | 40 DCHECK(!init_cb.is_null()); |
| 41 DCHECK(!config_cb.is_null()); | 41 DCHECK(!config_cb.is_null()); |
| 42 DCHECK(!new_buffers_cb.is_null()); | 42 DCHECK(!new_buffers_cb.is_null()); |
| 43 DCHECK(!encrypted_media_init_data_cb.is_null()); | 43 DCHECK(!encrypted_media_init_data_cb.is_null()); |
| 44 DCHECK(!new_segment_cb.is_null()); | 44 DCHECK(!new_segment_cb.is_null()); |
| 45 DCHECK(!end_of_segment_cb.is_null()); | 45 DCHECK(!end_of_segment_cb.is_null()); |
| 46 | 46 |
| 47 ChangeState(kParsingHeaders); | 47 ChangeState(kParsingHeaders); |
| 48 init_cb_ = init_cb; | 48 init_cb_ = init_cb; |
| 49 config_cb_ = config_cb; | 49 config_cb_ = config_cb; |
| 50 new_buffers_cb_ = new_buffers_cb; | 50 new_buffers_cb_ = new_buffers_cb; |
| 51 ignore_text_tracks_ = ignore_text_tracks; | 51 ignore_text_tracks_ = ignore_text_tracks; |
| 52 encrypted_media_init_data_cb_ = encrypted_media_init_data_cb; | 52 encrypted_media_init_data_cb_ = encrypted_media_init_data_cb; |
| 53 new_segment_cb_ = new_segment_cb; | 53 new_segment_cb_ = new_segment_cb; |
| 54 end_of_segment_cb_ = end_of_segment_cb; | 54 end_of_segment_cb_ = end_of_segment_cb; |
| 55 media_log_ = media_log; | 55 media_log_ = media_log; |
| 56 } | 56 } |
| 57 | 57 |
| 58 void WebMStreamParser::Flush() { | 58 void WebMStreamParser::Flush() { |
| 59 DCHECK_NE(state_, kWaitingForInit); | 59 DCHECK_NE(state_, kWaitingForInit); |
| 60 | 60 |
| 61 byte_queue_.Reset(); | 61 byte_queue_.Reset(); |
| 62 if (cluster_parser_) | 62 if (cluster_parser_) |
| 63 cluster_parser_->Reset(); | 63 cluster_parser_->Reset(); |
| 64 if (state_ == kParsingClusters) { | 64 if (state_ == kParsingClusters) |
| 65 ChangeState(kParsingHeaders); | 65 ChangeState(kParsingHeaders); |
| 66 end_of_segment_cb_.Run(); | |
| 67 } | |
| 68 } | 66 } |
| 69 | 67 |
| 70 bool WebMStreamParser::Parse(const uint8_t* buf, int size) { | 68 bool WebMStreamParser::Parse(const uint8_t* buf, int size) { |
| 71 DCHECK_NE(state_, kWaitingForInit); | 69 DCHECK_NE(state_, kWaitingForInit); |
| 72 | 70 |
| 73 if (state_ == kError) | 71 if (state_ == kError) |
| 74 return false; | 72 return false; |
| 75 | 73 |
| 76 byte_queue_.Push(buf, size); | 74 byte_queue_.Push(buf, size); |
| 77 | 75 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 bool cluster_ended = cluster_parser_->cluster_ended(); | 260 bool cluster_ended = cluster_parser_->cluster_ended(); |
| 263 | 261 |
| 264 if ((!audio_buffers.empty() || !video_buffers.empty() || | 262 if ((!audio_buffers.empty() || !video_buffers.empty() || |
| 265 !text_map.empty()) && | 263 !text_map.empty()) && |
| 266 !new_buffers_cb_.Run(audio_buffers, video_buffers, text_map)) { | 264 !new_buffers_cb_.Run(audio_buffers, video_buffers, text_map)) { |
| 267 return -1; | 265 return -1; |
| 268 } | 266 } |
| 269 | 267 |
| 270 if (cluster_ended) { | 268 if (cluster_ended) { |
| 271 ChangeState(kParsingHeaders); | 269 ChangeState(kParsingHeaders); |
| 272 end_of_segment_cb_.Run(); | 270 if (!end_of_segment_cb_.Run()) |
| 271 return -1; |
| 273 } | 272 } |
| 274 | 273 |
| 275 return bytes_parsed; | 274 return bytes_parsed; |
| 276 } | 275 } |
| 277 | 276 |
| 278 void WebMStreamParser::OnEncryptedMediaInitData(const std::string& key_id) { | 277 void WebMStreamParser::OnEncryptedMediaInitData(const std::string& key_id) { |
| 279 std::vector<uint8_t> key_id_vector(key_id.begin(), key_id.end()); | 278 std::vector<uint8_t> key_id_vector(key_id.begin(), key_id.end()); |
| 280 encrypted_media_init_data_cb_.Run(EmeInitDataType::WEBM, key_id_vector); | 279 encrypted_media_init_data_cb_.Run(EmeInitDataType::WEBM, key_id_vector); |
| 281 } | 280 } |
| 282 | 281 |
| 283 } // namespace media | 282 } // namespace media |
| OLD | NEW |