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" | |
11 #include "media/base/timestamp_constants.h" | 10 #include "media/base/timestamp_constants.h" |
12 #include "media/formats/webm/webm_constants.h" | 11 #include "media/formats/webm/webm_constants.h" |
13 #include "media/formats/webm/webm_content_encodings.h" | 12 #include "media/formats/webm/webm_content_encodings.h" |
14 | 13 |
15 namespace media { | 14 namespace media { |
16 | 15 |
17 static TextKind CodecIdToTextKind(const std::string& codec_id) { | 16 static TextKind CodecIdToTextKind(const std::string& codec_id) { |
18 if (codec_id == kWebMCodecSubtitles) | 17 if (codec_id == kWebMCodecSubtitles) |
19 return kTextSubtitles; | 18 return kTextSubtitles; |
20 | 19 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 | 186 |
188 std::string encryption_key_id; | 187 std::string encryption_key_id; |
189 if (track_content_encodings_client_) { | 188 if (track_content_encodings_client_) { |
190 DCHECK(!track_content_encodings_client_->content_encodings().empty()); | 189 DCHECK(!track_content_encodings_client_->content_encodings().empty()); |
191 // If we have multiple ContentEncoding in one track. Always choose the | 190 // If we have multiple ContentEncoding in one track. Always choose the |
192 // key id in the first ContentEncoding as the key id of the track. | 191 // key id in the first ContentEncoding as the key id of the track. |
193 encryption_key_id = track_content_encodings_client_-> | 192 encryption_key_id = track_content_encodings_client_-> |
194 content_encodings()[0]->encryption_key_id(); | 193 content_encodings()[0]->encryption_key_id(); |
195 } | 194 } |
196 | 195 |
197 EncryptionScheme encryption_scheme = | |
198 encryption_key_id.empty() ? Unencrypted() : AesCtrEncryptionScheme(); | |
199 | |
200 if (track_type_ == kWebMTrackTypeAudio) { | 196 if (track_type_ == kWebMTrackTypeAudio) { |
201 if (audio_track_num_ == -1) { | 197 if (audio_track_num_ == -1) { |
202 audio_track_num_ = track_num_; | 198 audio_track_num_ = track_num_; |
203 audio_encryption_key_id_ = encryption_key_id; | 199 audio_encryption_key_id_ = encryption_key_id; |
204 | 200 |
205 if (default_duration_ == 0) { | 201 if (default_duration_ == 0) { |
206 MEDIA_LOG(ERROR, media_log_) << "Illegal 0ns audio TrackEntry " | 202 MEDIA_LOG(ERROR, media_log_) << "Illegal 0ns audio TrackEntry " |
207 "DefaultDuration"; | 203 "DefaultDuration"; |
208 return false; | 204 return false; |
209 } | 205 } |
210 audio_default_duration_ = default_duration_; | 206 audio_default_duration_ = default_duration_; |
211 | 207 |
212 DCHECK(!audio_decoder_config_.IsValidConfig()); | 208 DCHECK(!audio_decoder_config_.IsValidConfig()); |
213 if (!audio_client_.InitializeConfig( | 209 if (!audio_client_.InitializeConfig( |
214 codec_id_, codec_private_, seek_preroll_, codec_delay_, | 210 codec_id_, codec_private_, seek_preroll_, codec_delay_, |
215 encryption_scheme, &audio_decoder_config_)) { | 211 !audio_encryption_key_id_.empty(), &audio_decoder_config_)) { |
216 return false; | 212 return false; |
217 } | 213 } |
218 media_tracks_->AddAudioTrack(audio_decoder_config_, | 214 media_tracks_->AddAudioTrack(audio_decoder_config_, |
219 base::Uint64ToString(track_num_), "main", | 215 base::Uint64ToString(track_num_), "main", |
220 track_name_, track_language_); | 216 track_name_, track_language_); |
221 } else { | 217 } else { |
222 MEDIA_LOG(DEBUG, media_log_) << "Ignoring audio track " << track_num_; | 218 MEDIA_LOG(DEBUG, media_log_) << "Ignoring audio track " << track_num_; |
223 ignored_tracks_.insert(track_num_); | 219 ignored_tracks_.insert(track_num_); |
224 } | 220 } |
225 } else if (track_type_ == kWebMTrackTypeVideo) { | 221 } else if (track_type_ == kWebMTrackTypeVideo) { |
226 if (video_track_num_ == -1) { | 222 if (video_track_num_ == -1) { |
227 video_track_num_ = track_num_; | 223 video_track_num_ = track_num_; |
228 video_encryption_key_id_ = encryption_key_id; | 224 video_encryption_key_id_ = encryption_key_id; |
229 | 225 |
230 if (default_duration_ == 0) { | 226 if (default_duration_ == 0) { |
231 MEDIA_LOG(ERROR, media_log_) << "Illegal 0ns video TrackEntry " | 227 MEDIA_LOG(ERROR, media_log_) << "Illegal 0ns video TrackEntry " |
232 "DefaultDuration"; | 228 "DefaultDuration"; |
233 return false; | 229 return false; |
234 } | 230 } |
235 video_default_duration_ = default_duration_; | 231 video_default_duration_ = default_duration_; |
236 | 232 |
237 DCHECK(!video_decoder_config_.IsValidConfig()); | 233 DCHECK(!video_decoder_config_.IsValidConfig()); |
238 if (!video_client_.InitializeConfig(codec_id_, codec_private_, | 234 if (!video_client_.InitializeConfig( |
239 encryption_scheme, | 235 codec_id_, codec_private_, !video_encryption_key_id_.empty(), |
240 &video_decoder_config_)) { | 236 &video_decoder_config_)) { |
241 return false; | 237 return false; |
242 } | 238 } |
243 media_tracks_->AddVideoTrack(video_decoder_config_, | 239 media_tracks_->AddVideoTrack(video_decoder_config_, |
244 base::Uint64ToString(track_num_), "main", | 240 base::Uint64ToString(track_num_), "main", |
245 track_name_, track_language_); | 241 track_name_, track_language_); |
246 } else { | 242 } else { |
247 MEDIA_LOG(DEBUG, media_log_) << "Ignoring video track " << track_num_; | 243 MEDIA_LOG(DEBUG, media_log_) << "Ignoring video track " << track_num_; |
248 ignored_tracks_.insert(track_num_); | 244 ignored_tracks_.insert(track_num_); |
249 } | 245 } |
250 } else if (track_type_ == kWebMTrackTypeSubtitlesOrCaptions || | 246 } else if (track_type_ == kWebMTrackTypeSubtitlesOrCaptions || |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 } else { | 351 } else { |
356 track_language_ = str; | 352 track_language_ = str; |
357 } | 353 } |
358 return true; | 354 return true; |
359 } | 355 } |
360 | 356 |
361 return true; | 357 return true; |
362 } | 358 } |
363 | 359 |
364 } // namespace media | 360 } // namespace media |
OLD | NEW |