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 14 matching lines...) Expand all Loading... |
25 | 25 |
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 base::Closure& start_of_segment_cb, |
36 const base::Closure& end_of_segment_cb, | 36 const base::Closure& 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(!start_of_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 start_of_segment_cb_ = start_of_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(); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 } | 152 } |
153 // Skip the element. | 153 // Skip the element. |
154 return result + element_size; | 154 return result + element_size; |
155 break; | 155 break; |
156 case kWebMIdCluster: | 156 case kWebMIdCluster: |
157 if (!cluster_parser_) { | 157 if (!cluster_parser_) { |
158 MEDIA_LOG(ERROR, media_log_) << "Found Cluster element before Info."; | 158 MEDIA_LOG(ERROR, media_log_) << "Found Cluster element before Info."; |
159 return -1; | 159 return -1; |
160 } | 160 } |
161 ChangeState(kParsingClusters); | 161 ChangeState(kParsingClusters); |
162 new_segment_cb_.Run(); | 162 start_of_segment_cb_.Run(); |
163 return 0; | 163 return 0; |
164 break; | 164 break; |
165 case kWebMIdSegment: | 165 case kWebMIdSegment: |
166 // Segment of unknown size indicates live stream. | 166 // Segment of unknown size indicates live stream. |
167 if (element_size == kWebMUnknownSize) | 167 if (element_size == kWebMUnknownSize) |
168 unknown_segment_size_ = true; | 168 unknown_segment_size_ = true; |
169 // Just consume the segment header. | 169 // Just consume the segment header. |
170 return result; | 170 return result; |
171 break; | 171 break; |
172 case kWebMIdInfo: | 172 case kWebMIdInfo: |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 | 274 |
275 return bytes_parsed; | 275 return bytes_parsed; |
276 } | 276 } |
277 | 277 |
278 void WebMStreamParser::OnEncryptedMediaInitData(const std::string& key_id) { | 278 void WebMStreamParser::OnEncryptedMediaInitData(const std::string& key_id) { |
279 std::vector<uint8> key_id_vector(key_id.begin(), key_id.end()); | 279 std::vector<uint8> key_id_vector(key_id.begin(), key_id.end()); |
280 encrypted_media_init_data_cb_.Run(EmeInitDataType::WEBM, key_id_vector); | 280 encrypted_media_init_data_cb_.Run(EmeInitDataType::WEBM, key_id_vector); |
281 } | 281 } |
282 | 282 |
283 } // namespace media | 283 } // namespace media |
OLD | NEW |