| 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_tracks_parser.h" | 5 #include "media/formats/webm/webm_tracks_parser.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "media/base/media_util.h" | 10 #include "media/base/media_util.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 ResetTrackEntry(); | 60 ResetTrackEntry(); |
| 61 reset_on_next_parse_ = false; | 61 reset_on_next_parse_ = false; |
| 62 audio_track_num_ = -1; | 62 audio_track_num_ = -1; |
| 63 audio_default_duration_ = -1; | 63 audio_default_duration_ = -1; |
| 64 audio_decoder_config_ = AudioDecoderConfig(); | 64 audio_decoder_config_ = AudioDecoderConfig(); |
| 65 video_track_num_ = -1; | 65 video_track_num_ = -1; |
| 66 video_default_duration_ = -1; | 66 video_default_duration_ = -1; |
| 67 video_decoder_config_ = VideoDecoderConfig(); | 67 video_decoder_config_ = VideoDecoderConfig(); |
| 68 text_tracks_.clear(); | 68 text_tracks_.clear(); |
| 69 ignored_tracks_.clear(); | 69 ignored_tracks_.clear(); |
| 70 detected_audio_track_count_ = 0; |
| 71 detected_video_track_count_ = 0; |
| 72 detected_text_track_count_ = 0; |
| 70 media_tracks_.reset(new MediaTracks()); | 73 media_tracks_.reset(new MediaTracks()); |
| 71 } | 74 } |
| 72 | 75 |
| 73 void WebMTracksParser::ResetTrackEntry() { | 76 void WebMTracksParser::ResetTrackEntry() { |
| 74 track_type_ = -1; | 77 track_type_ = -1; |
| 75 track_num_ = -1; | 78 track_num_ = -1; |
| 76 track_name_.clear(); | 79 track_name_.clear(); |
| 77 track_language_.clear(); | 80 track_language_.clear(); |
| 78 codec_id_ = ""; | 81 codec_id_ = ""; |
| 79 codec_private_.clear(); | 82 codec_private_.clear(); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 // If we have multiple ContentEncoding in one track. Always choose the | 196 // If we have multiple ContentEncoding in one track. Always choose the |
| 194 // key id in the first ContentEncoding as the key id of the track. | 197 // key id in the first ContentEncoding as the key id of the track. |
| 195 encryption_key_id = track_content_encodings_client_-> | 198 encryption_key_id = track_content_encodings_client_-> |
| 196 content_encodings()[0]->encryption_key_id(); | 199 content_encodings()[0]->encryption_key_id(); |
| 197 } | 200 } |
| 198 | 201 |
| 199 EncryptionScheme encryption_scheme = | 202 EncryptionScheme encryption_scheme = |
| 200 encryption_key_id.empty() ? Unencrypted() : AesCtrEncryptionScheme(); | 203 encryption_key_id.empty() ? Unencrypted() : AesCtrEncryptionScheme(); |
| 201 | 204 |
| 202 if (track_type_ == kWebMTrackTypeAudio) { | 205 if (track_type_ == kWebMTrackTypeAudio) { |
| 206 detected_audio_track_count_++; |
| 203 if (audio_track_num_ == -1) { | 207 if (audio_track_num_ == -1) { |
| 204 audio_track_num_ = track_num_; | 208 audio_track_num_ = track_num_; |
| 205 audio_encryption_key_id_ = encryption_key_id; | 209 audio_encryption_key_id_ = encryption_key_id; |
| 206 | 210 |
| 207 if (default_duration_ == 0) { | 211 if (default_duration_ == 0) { |
| 208 MEDIA_LOG(ERROR, media_log_) << "Illegal 0ns audio TrackEntry " | 212 MEDIA_LOG(ERROR, media_log_) << "Illegal 0ns audio TrackEntry " |
| 209 "DefaultDuration"; | 213 "DefaultDuration"; |
| 210 return false; | 214 return false; |
| 211 } | 215 } |
| 212 audio_default_duration_ = default_duration_; | 216 audio_default_duration_ = default_duration_; |
| 213 | 217 |
| 214 DCHECK(!audio_decoder_config_.IsValidConfig()); | 218 DCHECK(!audio_decoder_config_.IsValidConfig()); |
| 215 if (!audio_client_.InitializeConfig( | 219 if (!audio_client_.InitializeConfig( |
| 216 codec_id_, codec_private_, seek_preroll_, codec_delay_, | 220 codec_id_, codec_private_, seek_preroll_, codec_delay_, |
| 217 encryption_scheme, &audio_decoder_config_)) { | 221 encryption_scheme, &audio_decoder_config_)) { |
| 218 return false; | 222 return false; |
| 219 } | 223 } |
| 220 media_tracks_->AddAudioTrack(audio_decoder_config_, | 224 media_tracks_->AddAudioTrack(audio_decoder_config_, |
| 221 base::Uint64ToString(track_num_), "main", | 225 base::Uint64ToString(track_num_), "main", |
| 222 track_name_, track_language_); | 226 track_name_, track_language_); |
| 223 } else { | 227 } else { |
| 224 MEDIA_LOG(DEBUG, media_log_) << "Ignoring audio track " << track_num_; | 228 MEDIA_LOG(DEBUG, media_log_) << "Ignoring audio track " << track_num_; |
| 225 ignored_tracks_.insert(track_num_); | 229 ignored_tracks_.insert(track_num_); |
| 226 } | 230 } |
| 227 } else if (track_type_ == kWebMTrackTypeVideo) { | 231 } else if (track_type_ == kWebMTrackTypeVideo) { |
| 232 detected_video_track_count_++; |
| 228 if (video_track_num_ == -1) { | 233 if (video_track_num_ == -1) { |
| 229 video_track_num_ = track_num_; | 234 video_track_num_ = track_num_; |
| 230 video_encryption_key_id_ = encryption_key_id; | 235 video_encryption_key_id_ = encryption_key_id; |
| 231 | 236 |
| 232 if (default_duration_ == 0) { | 237 if (default_duration_ == 0) { |
| 233 MEDIA_LOG(ERROR, media_log_) << "Illegal 0ns video TrackEntry " | 238 MEDIA_LOG(ERROR, media_log_) << "Illegal 0ns video TrackEntry " |
| 234 "DefaultDuration"; | 239 "DefaultDuration"; |
| 235 return false; | 240 return false; |
| 236 } | 241 } |
| 237 video_default_duration_ = default_duration_; | 242 video_default_duration_ = default_duration_; |
| 238 | 243 |
| 239 DCHECK(!video_decoder_config_.IsValidConfig()); | 244 DCHECK(!video_decoder_config_.IsValidConfig()); |
| 240 if (!video_client_.InitializeConfig(codec_id_, codec_private_, | 245 if (!video_client_.InitializeConfig(codec_id_, codec_private_, |
| 241 encryption_scheme, | 246 encryption_scheme, |
| 242 &video_decoder_config_)) { | 247 &video_decoder_config_)) { |
| 243 return false; | 248 return false; |
| 244 } | 249 } |
| 245 media_tracks_->AddVideoTrack(video_decoder_config_, | 250 media_tracks_->AddVideoTrack(video_decoder_config_, |
| 246 base::Uint64ToString(track_num_), "main", | 251 base::Uint64ToString(track_num_), "main", |
| 247 track_name_, track_language_); | 252 track_name_, track_language_); |
| 248 } else { | 253 } else { |
| 249 MEDIA_LOG(DEBUG, media_log_) << "Ignoring video track " << track_num_; | 254 MEDIA_LOG(DEBUG, media_log_) << "Ignoring video track " << track_num_; |
| 250 ignored_tracks_.insert(track_num_); | 255 ignored_tracks_.insert(track_num_); |
| 251 } | 256 } |
| 252 } else if (track_type_ == kWebMTrackTypeSubtitlesOrCaptions || | 257 } else if (track_type_ == kWebMTrackTypeSubtitlesOrCaptions || |
| 253 track_type_ == kWebMTrackTypeDescriptionsOrMetadata) { | 258 track_type_ == kWebMTrackTypeDescriptionsOrMetadata) { |
| 259 detected_text_track_count_++; |
| 254 if (ignore_text_tracks_) { | 260 if (ignore_text_tracks_) { |
| 255 MEDIA_LOG(DEBUG, media_log_) << "Ignoring text track " << track_num_; | 261 MEDIA_LOG(DEBUG, media_log_) << "Ignoring text track " << track_num_; |
| 256 ignored_tracks_.insert(track_num_); | 262 ignored_tracks_.insert(track_num_); |
| 257 } else { | 263 } else { |
| 258 std::string track_num = base::Int64ToString(track_num_); | 264 std::string track_num = base::Int64ToString(track_num_); |
| 259 text_tracks_[track_num_] = TextTrackConfig( | 265 text_tracks_[track_num_] = TextTrackConfig( |
| 260 text_track_kind, track_name_, track_language_, track_num); | 266 text_track_kind, track_name_, track_language_, track_num); |
| 261 } | 267 } |
| 262 } else { | 268 } else { |
| 263 MEDIA_LOG(ERROR, media_log_) << "Unexpected TrackType " << track_type_; | 269 MEDIA_LOG(ERROR, media_log_) << "Unexpected TrackType " << track_type_; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 } else { | 363 } else { |
| 358 track_language_ = str; | 364 track_language_ = str; |
| 359 } | 365 } |
| 360 return true; | 366 return true; |
| 361 } | 367 } |
| 362 | 368 |
| 363 return true; | 369 return true; |
| 364 } | 370 } |
| 365 | 371 |
| 366 } // namespace media | 372 } // namespace media |
| OLD | NEW |