| 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 } | 26 } |
| 27 | 27 |
| 28 void WebMStreamParser::Init( | 28 void WebMStreamParser::Init( |
| 29 const InitCB& init_cb, | 29 const InitCB& init_cb, |
| 30 const NewConfigCB& config_cb, | 30 const NewConfigCB& config_cb, |
| 31 const NewBuffersCB& new_buffers_cb, | 31 const NewBuffersCB& new_buffers_cb, |
| 32 bool ignore_text_tracks, | 32 bool ignore_text_tracks, |
| 33 const EncryptedMediaInitDataCB& encrypted_media_init_data_cb, | 33 const EncryptedMediaInitDataCB& encrypted_media_init_data_cb, |
| 34 const NewMediaSegmentCB& new_segment_cb, | 34 const NewMediaSegmentCB& new_segment_cb, |
| 35 const base::Closure& end_of_segment_cb, | 35 const base::Closure& end_of_segment_cb, |
| 36 const LogCB& log_cb) { | 36 const scoped_refptr<MediaLog>& media_log) { |
| 37 DCHECK_EQ(state_, kWaitingForInit); | 37 DCHECK_EQ(state_, kWaitingForInit); |
| 38 DCHECK(init_cb_.is_null()); | 38 DCHECK(init_cb_.is_null()); |
| 39 DCHECK(!init_cb.is_null()); | 39 DCHECK(!init_cb.is_null()); |
| 40 DCHECK(!config_cb.is_null()); | 40 DCHECK(!config_cb.is_null()); |
| 41 DCHECK(!new_buffers_cb.is_null()); | 41 DCHECK(!new_buffers_cb.is_null()); |
| 42 DCHECK(!encrypted_media_init_data_cb.is_null()); | 42 DCHECK(!encrypted_media_init_data_cb.is_null()); |
| 43 DCHECK(!new_segment_cb.is_null()); | 43 DCHECK(!new_segment_cb.is_null()); |
| 44 DCHECK(!end_of_segment_cb.is_null()); | 44 DCHECK(!end_of_segment_cb.is_null()); |
| 45 | 45 |
| 46 ChangeState(kParsingHeaders); | 46 ChangeState(kParsingHeaders); |
| 47 init_cb_ = init_cb; | 47 init_cb_ = init_cb; |
| 48 config_cb_ = config_cb; | 48 config_cb_ = config_cb; |
| 49 new_buffers_cb_ = new_buffers_cb; | 49 new_buffers_cb_ = new_buffers_cb; |
| 50 ignore_text_tracks_ = ignore_text_tracks; | 50 ignore_text_tracks_ = ignore_text_tracks; |
| 51 encrypted_media_init_data_cb_ = encrypted_media_init_data_cb; | 51 encrypted_media_init_data_cb_ = encrypted_media_init_data_cb; |
| 52 new_segment_cb_ = new_segment_cb; | 52 new_segment_cb_ = new_segment_cb; |
| 53 end_of_segment_cb_ = end_of_segment_cb; | 53 end_of_segment_cb_ = end_of_segment_cb; |
| 54 log_cb_ = log_cb; | 54 media_log_ = media_log; |
| 55 } | 55 } |
| 56 | 56 |
| 57 void WebMStreamParser::Flush() { | 57 void WebMStreamParser::Flush() { |
| 58 DCHECK_NE(state_, kWaitingForInit); | 58 DCHECK_NE(state_, kWaitingForInit); |
| 59 | 59 |
| 60 byte_queue_.Reset(); | 60 byte_queue_.Reset(); |
| 61 if (cluster_parser_) | 61 if (cluster_parser_) |
| 62 cluster_parser_->Reset(); | 62 cluster_parser_->Reset(); |
| 63 if (state_ == kParsingClusters) { | 63 if (state_ == kParsingClusters) { |
| 64 ChangeState(kParsingHeaders); | 64 ChangeState(kParsingHeaders); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 // TODO(matthewjheaney): Implement support for chapters. | 147 // TODO(matthewjheaney): Implement support for chapters. |
| 148 if (cur_size < (result + element_size)) { | 148 if (cur_size < (result + element_size)) { |
| 149 // We don't have the whole element yet. Signal we need more data. | 149 // We don't have the whole element yet. Signal we need more data. |
| 150 return 0; | 150 return 0; |
| 151 } | 151 } |
| 152 // Skip the element. | 152 // Skip the element. |
| 153 return result + element_size; | 153 return result + element_size; |
| 154 break; | 154 break; |
| 155 case kWebMIdCluster: | 155 case kWebMIdCluster: |
| 156 if (!cluster_parser_) { | 156 if (!cluster_parser_) { |
| 157 MEDIA_LOG(ERROR, log_cb_) << "Found Cluster element before Info."; | 157 MEDIA_LOG(ERROR, media_log_) << "Found Cluster element before Info."; |
| 158 return -1; | 158 return -1; |
| 159 } | 159 } |
| 160 ChangeState(kParsingClusters); | 160 ChangeState(kParsingClusters); |
| 161 new_segment_cb_.Run(); | 161 new_segment_cb_.Run(); |
| 162 return 0; | 162 return 0; |
| 163 break; | 163 break; |
| 164 case kWebMIdSegment: | 164 case kWebMIdSegment: |
| 165 // Segment of unknown size indicates live stream. | 165 // Segment of unknown size indicates live stream. |
| 166 if (element_size == kWebMUnknownSize) | 166 if (element_size == kWebMUnknownSize) |
| 167 unknown_segment_size_ = true; | 167 unknown_segment_size_ = true; |
| 168 // Just consume the segment header. | 168 // Just consume the segment header. |
| 169 return result; | 169 return result; |
| 170 break; | 170 break; |
| 171 case kWebMIdInfo: | 171 case kWebMIdInfo: |
| 172 // We've found the element we are looking for. | 172 // We've found the element we are looking for. |
| 173 break; | 173 break; |
| 174 default: { | 174 default: { |
| 175 MEDIA_LOG(ERROR, log_cb_) << "Unexpected element ID 0x" << std::hex << id; | 175 MEDIA_LOG(ERROR, media_log_) << "Unexpected element ID 0x" << std::hex |
| 176 << id; |
| 176 return -1; | 177 return -1; |
| 177 } | 178 } |
| 178 } | 179 } |
| 179 | 180 |
| 180 WebMInfoParser info_parser; | 181 WebMInfoParser info_parser; |
| 181 result = info_parser.Parse(cur, cur_size); | 182 result = info_parser.Parse(cur, cur_size); |
| 182 | 183 |
| 183 if (result <= 0) | 184 if (result <= 0) |
| 184 return result; | 185 return result; |
| 185 | 186 |
| 186 cur += result; | 187 cur += result; |
| 187 cur_size -= result; | 188 cur_size -= result; |
| 188 bytes_parsed += result; | 189 bytes_parsed += result; |
| 189 | 190 |
| 190 WebMTracksParser tracks_parser(log_cb_, ignore_text_tracks_); | 191 WebMTracksParser tracks_parser(media_log_, ignore_text_tracks_); |
| 191 result = tracks_parser.Parse(cur, cur_size); | 192 result = tracks_parser.Parse(cur, cur_size); |
| 192 | 193 |
| 193 if (result <= 0) | 194 if (result <= 0) |
| 194 return result; | 195 return result; |
| 195 | 196 |
| 196 bytes_parsed += result; | 197 bytes_parsed += result; |
| 197 | 198 |
| 198 double timecode_scale_in_us = info_parser.timecode_scale() / 1000.0; | 199 double timecode_scale_in_us = info_parser.timecode_scale() / 1000.0; |
| 199 InitParameters params(kInfiniteDuration()); | 200 InitParameters params(kInfiniteDuration()); |
| 200 | 201 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 223 OnEncryptedMediaInitData(tracks_parser.video_encryption_key_id()); | 224 OnEncryptedMediaInitData(tracks_parser.video_encryption_key_id()); |
| 224 | 225 |
| 225 if (!config_cb_.Run(audio_config, | 226 if (!config_cb_.Run(audio_config, |
| 226 video_config, | 227 video_config, |
| 227 tracks_parser.text_tracks())) { | 228 tracks_parser.text_tracks())) { |
| 228 DVLOG(1) << "New config data isn't allowed."; | 229 DVLOG(1) << "New config data isn't allowed."; |
| 229 return -1; | 230 return -1; |
| 230 } | 231 } |
| 231 | 232 |
| 232 cluster_parser_.reset(new WebMClusterParser( | 233 cluster_parser_.reset(new WebMClusterParser( |
| 233 info_parser.timecode_scale(), | 234 info_parser.timecode_scale(), tracks_parser.audio_track_num(), |
| 234 tracks_parser.audio_track_num(), | |
| 235 tracks_parser.GetAudioDefaultDuration(timecode_scale_in_us), | 235 tracks_parser.GetAudioDefaultDuration(timecode_scale_in_us), |
| 236 tracks_parser.video_track_num(), | 236 tracks_parser.video_track_num(), |
| 237 tracks_parser.GetVideoDefaultDuration(timecode_scale_in_us), | 237 tracks_parser.GetVideoDefaultDuration(timecode_scale_in_us), |
| 238 tracks_parser.text_tracks(), | 238 tracks_parser.text_tracks(), tracks_parser.ignored_tracks(), |
| 239 tracks_parser.ignored_tracks(), | |
| 240 tracks_parser.audio_encryption_key_id(), | 239 tracks_parser.audio_encryption_key_id(), |
| 241 tracks_parser.video_encryption_key_id(), | 240 tracks_parser.video_encryption_key_id(), audio_config.codec(), |
| 242 audio_config.codec(), | 241 media_log_)); |
| 243 log_cb_)); | |
| 244 | 242 |
| 245 if (!init_cb_.is_null()) | 243 if (!init_cb_.is_null()) |
| 246 base::ResetAndReturn(&init_cb_).Run(params); | 244 base::ResetAndReturn(&init_cb_).Run(params); |
| 247 | 245 |
| 248 return bytes_parsed; | 246 return bytes_parsed; |
| 249 } | 247 } |
| 250 | 248 |
| 251 int WebMStreamParser::ParseCluster(const uint8* data, int size) { | 249 int WebMStreamParser::ParseCluster(const uint8* data, int size) { |
| 252 if (!cluster_parser_) | 250 if (!cluster_parser_) |
| 253 return -1; | 251 return -1; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 275 | 273 |
| 276 return bytes_parsed; | 274 return bytes_parsed; |
| 277 } | 275 } |
| 278 | 276 |
| 279 void WebMStreamParser::OnEncryptedMediaInitData(const std::string& key_id) { | 277 void WebMStreamParser::OnEncryptedMediaInitData(const std::string& key_id) { |
| 280 std::vector<uint8> key_id_vector(key_id.begin(), key_id.end()); | 278 std::vector<uint8> key_id_vector(key_id.begin(), key_id.end()); |
| 281 encrypted_media_init_data_cb_.Run(EmeInitDataType::WEBM, key_id_vector); | 279 encrypted_media_init_data_cb_.Run(EmeInitDataType::WEBM, key_id_vector); |
| 282 } | 280 } |
| 283 | 281 |
| 284 } // namespace media | 282 } // namespace media |
| OLD | NEW |