Chromium Code Reviews| 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 29 matching lines...) Expand all Loading... | |
| 40 mult /= timecode_scale_in_us; | 40 mult /= timecode_scale_in_us; |
| 41 if (mult == 0) | 41 if (mult == 0) |
| 42 return kNoTimestamp(); | 42 return kNoTimestamp(); |
| 43 | 43 |
| 44 mult = static_cast<double>(mult) * timecode_scale_in_us; | 44 mult = static_cast<double>(mult) * timecode_scale_in_us; |
| 45 return base::TimeDelta::FromMicroseconds(mult); | 45 return base::TimeDelta::FromMicroseconds(mult); |
| 46 } | 46 } |
| 47 | 47 |
| 48 WebMTracksParser::WebMTracksParser(const scoped_refptr<MediaLog>& media_log, | 48 WebMTracksParser::WebMTracksParser(const scoped_refptr<MediaLog>& media_log, |
| 49 bool ignore_text_tracks) | 49 bool ignore_text_tracks) |
| 50 : track_type_(-1), | 50 : ignore_text_tracks_(ignore_text_tracks), |
| 51 track_num_(-1), | |
|
chcunningham
2016/03/23 23:05:56
Nit: You might be better off with a private method
wolenetz
2016/03/25 23:25:08
Agreed. Will be in later patch set.
wolenetz
2016/03/28 20:41:46
I've sent this particular cleanup as a prereq CL [
| |
| 52 seek_preroll_(-1), | |
| 53 codec_delay_(-1), | |
| 54 default_duration_(-1), | |
| 55 audio_track_num_(-1), | |
| 56 audio_default_duration_(-1), | |
| 57 video_track_num_(-1), | |
| 58 video_default_duration_(-1), | |
| 59 ignore_text_tracks_(ignore_text_tracks), | |
| 60 media_log_(media_log), | 51 media_log_(media_log), |
| 61 audio_client_(media_log), | 52 audio_client_(media_log), |
| 62 video_client_(media_log) { | 53 video_client_(media_log) {} |
| 63 } | |
| 64 | 54 |
| 65 WebMTracksParser::~WebMTracksParser() {} | 55 WebMTracksParser::~WebMTracksParser() {} |
| 66 | 56 |
| 67 int WebMTracksParser::Parse(const uint8_t* buf, int size) { | 57 int WebMTracksParser::Parse(const uint8_t* buf, int size) { |
| 68 track_type_ =-1; | 58 track_type_ =-1; |
| 69 track_num_ = -1; | 59 track_num_ = -1; |
| 70 default_duration_ = -1; | 60 default_duration_ = -1; |
| 71 track_name_.clear(); | 61 track_name_.clear(); |
| 72 track_language_.clear(); | 62 track_language_.clear(); |
| 73 audio_track_num_ = -1; | 63 audio_track_num_ = -1; |
| 74 audio_default_duration_ = -1; | 64 audio_default_duration_ = -1; |
| 75 audio_decoder_config_ = AudioDecoderConfig(); | 65 audio_decoder_config_ = AudioDecoderConfig(); |
| 76 video_track_num_ = -1; | 66 video_track_num_ = -1; |
| 77 video_default_duration_ = -1; | 67 video_default_duration_ = -1; |
| 78 video_decoder_config_ = VideoDecoderConfig(); | 68 video_decoder_config_ = VideoDecoderConfig(); |
| 79 text_tracks_.clear(); | 69 text_tracks_.clear(); |
| 80 ignored_tracks_.clear(); | 70 ignored_tracks_.clear(); |
| 71 detected_audio_track_count_ = 0; | |
| 72 detected_video_track_count_ = 0; | |
| 73 detected_text_track_count_ = 0; | |
| 81 media_tracks_.reset(new MediaTracks()); | 74 media_tracks_.reset(new MediaTracks()); |
| 82 | 75 |
| 83 WebMListParser parser(kWebMIdTracks, this); | 76 WebMListParser parser(kWebMIdTracks, this); |
| 84 int result = parser.Parse(buf, size); | 77 int result = parser.Parse(buf, size); |
| 85 | 78 |
| 86 if (result <= 0) | 79 if (result <= 0) |
| 87 return result; | 80 return result; |
| 88 | 81 |
| 89 // For now we do all or nothing parsing. | 82 // For now we do all or nothing parsing. |
| 90 return parser.IsParsingComplete() ? result : 0; | 83 return parser.IsParsingComplete() ? result : 0; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 // If we have multiple ContentEncoding in one track. Always choose the | 184 // 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. | 185 // key id in the first ContentEncoding as the key id of the track. |
| 193 encryption_key_id = track_content_encodings_client_-> | 186 encryption_key_id = track_content_encodings_client_-> |
| 194 content_encodings()[0]->encryption_key_id(); | 187 content_encodings()[0]->encryption_key_id(); |
| 195 } | 188 } |
| 196 | 189 |
| 197 EncryptionScheme encryption_scheme = | 190 EncryptionScheme encryption_scheme = |
| 198 encryption_key_id.empty() ? Unencrypted() : AesCtrEncryptionScheme(); | 191 encryption_key_id.empty() ? Unencrypted() : AesCtrEncryptionScheme(); |
| 199 | 192 |
| 200 if (track_type_ == kWebMTrackTypeAudio) { | 193 if (track_type_ == kWebMTrackTypeAudio) { |
| 194 detected_audio_track_count_++; | |
| 201 if (audio_track_num_ == -1) { | 195 if (audio_track_num_ == -1) { |
| 202 audio_track_num_ = track_num_; | 196 audio_track_num_ = track_num_; |
| 203 audio_encryption_key_id_ = encryption_key_id; | 197 audio_encryption_key_id_ = encryption_key_id; |
| 204 | 198 |
| 205 if (default_duration_ == 0) { | 199 if (default_duration_ == 0) { |
| 206 MEDIA_LOG(ERROR, media_log_) << "Illegal 0ns audio TrackEntry " | 200 MEDIA_LOG(ERROR, media_log_) << "Illegal 0ns audio TrackEntry " |
| 207 "DefaultDuration"; | 201 "DefaultDuration"; |
| 208 return false; | 202 return false; |
| 209 } | 203 } |
| 210 audio_default_duration_ = default_duration_; | 204 audio_default_duration_ = default_duration_; |
| 211 | 205 |
| 212 DCHECK(!audio_decoder_config_.IsValidConfig()); | 206 DCHECK(!audio_decoder_config_.IsValidConfig()); |
| 213 if (!audio_client_.InitializeConfig( | 207 if (!audio_client_.InitializeConfig( |
| 214 codec_id_, codec_private_, seek_preroll_, codec_delay_, | 208 codec_id_, codec_private_, seek_preroll_, codec_delay_, |
| 215 encryption_scheme, &audio_decoder_config_)) { | 209 encryption_scheme, &audio_decoder_config_)) { |
| 216 return false; | 210 return false; |
| 217 } | 211 } |
| 218 media_tracks_->AddAudioTrack(audio_decoder_config_, | 212 media_tracks_->AddAudioTrack(audio_decoder_config_, |
| 219 base::Uint64ToString(track_num_), "main", | 213 base::Uint64ToString(track_num_), "main", |
| 220 track_name_, track_language_); | 214 track_name_, track_language_); |
| 221 } else { | 215 } else { |
| 222 MEDIA_LOG(DEBUG, media_log_) << "Ignoring audio track " << track_num_; | 216 MEDIA_LOG(DEBUG, media_log_) << "Ignoring audio track " << track_num_; |
| 223 ignored_tracks_.insert(track_num_); | 217 ignored_tracks_.insert(track_num_); |
| 224 } | 218 } |
| 225 } else if (track_type_ == kWebMTrackTypeVideo) { | 219 } else if (track_type_ == kWebMTrackTypeVideo) { |
| 220 detected_video_track_count_++; | |
| 226 if (video_track_num_ == -1) { | 221 if (video_track_num_ == -1) { |
| 227 video_track_num_ = track_num_; | 222 video_track_num_ = track_num_; |
| 228 video_encryption_key_id_ = encryption_key_id; | 223 video_encryption_key_id_ = encryption_key_id; |
| 229 | 224 |
| 230 if (default_duration_ == 0) { | 225 if (default_duration_ == 0) { |
| 231 MEDIA_LOG(ERROR, media_log_) << "Illegal 0ns video TrackEntry " | 226 MEDIA_LOG(ERROR, media_log_) << "Illegal 0ns video TrackEntry " |
| 232 "DefaultDuration"; | 227 "DefaultDuration"; |
| 233 return false; | 228 return false; |
| 234 } | 229 } |
| 235 video_default_duration_ = default_duration_; | 230 video_default_duration_ = default_duration_; |
| 236 | 231 |
| 237 DCHECK(!video_decoder_config_.IsValidConfig()); | 232 DCHECK(!video_decoder_config_.IsValidConfig()); |
| 238 if (!video_client_.InitializeConfig(codec_id_, codec_private_, | 233 if (!video_client_.InitializeConfig(codec_id_, codec_private_, |
| 239 encryption_scheme, | 234 encryption_scheme, |
| 240 &video_decoder_config_)) { | 235 &video_decoder_config_)) { |
| 241 return false; | 236 return false; |
| 242 } | 237 } |
| 243 media_tracks_->AddVideoTrack(video_decoder_config_, | 238 media_tracks_->AddVideoTrack(video_decoder_config_, |
| 244 base::Uint64ToString(track_num_), "main", | 239 base::Uint64ToString(track_num_), "main", |
| 245 track_name_, track_language_); | 240 track_name_, track_language_); |
| 246 } else { | 241 } else { |
| 247 MEDIA_LOG(DEBUG, media_log_) << "Ignoring video track " << track_num_; | 242 MEDIA_LOG(DEBUG, media_log_) << "Ignoring video track " << track_num_; |
| 248 ignored_tracks_.insert(track_num_); | 243 ignored_tracks_.insert(track_num_); |
| 249 } | 244 } |
| 250 } else if (track_type_ == kWebMTrackTypeSubtitlesOrCaptions || | 245 } else if (track_type_ == kWebMTrackTypeSubtitlesOrCaptions || |
| 251 track_type_ == kWebMTrackTypeDescriptionsOrMetadata) { | 246 track_type_ == kWebMTrackTypeDescriptionsOrMetadata) { |
| 247 detected_text_track_count_++; | |
|
wolenetz
2016/03/23 01:45:50
aside: For better data (and similar to ffmpeg_demu
chcunningham
2016/03/23 23:05:56
Acknowledged.
| |
| 252 if (ignore_text_tracks_) { | 248 if (ignore_text_tracks_) { |
| 253 MEDIA_LOG(DEBUG, media_log_) << "Ignoring text track " << track_num_; | 249 MEDIA_LOG(DEBUG, media_log_) << "Ignoring text track " << track_num_; |
| 254 ignored_tracks_.insert(track_num_); | 250 ignored_tracks_.insert(track_num_); |
| 255 } else { | 251 } else { |
| 256 std::string track_num = base::Int64ToString(track_num_); | 252 std::string track_num = base::Int64ToString(track_num_); |
| 257 text_tracks_[track_num_] = TextTrackConfig( | 253 text_tracks_[track_num_] = TextTrackConfig( |
| 258 text_track_kind, track_name_, track_language_, track_num); | 254 text_track_kind, track_name_, track_language_, track_num); |
| 259 } | 255 } |
| 260 } else { | 256 } else { |
| 261 MEDIA_LOG(ERROR, media_log_) << "Unexpected TrackType " << track_type_; | 257 MEDIA_LOG(ERROR, media_log_) << "Unexpected TrackType " << track_type_; |
| (...skipping 93 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 |