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/mp4/mp4_stream_parser.h" | 5 #include "media/formats/mp4/mp4_stream_parser.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <limits> | 8 #include <limits> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/strings/string_number_conversions.h" |
14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
16 #include "media/base/audio_decoder_config.h" | 17 #include "media/base/audio_decoder_config.h" |
17 #include "media/base/media_tracks.h" | 18 #include "media/base/media_tracks.h" |
18 #include "media/base/stream_parser_buffer.h" | 19 #include "media/base/stream_parser_buffer.h" |
19 #include "media/base/text_track_config.h" | 20 #include "media/base/text_track_config.h" |
20 #include "media/base/timestamp_constants.h" | 21 #include "media/base/timestamp_constants.h" |
21 #include "media/base/video_decoder_config.h" | 22 #include "media/base/video_decoder_config.h" |
22 #include "media/base/video_util.h" | 23 #include "media/base/video_util.h" |
23 #include "media/formats/mp4/box_definitions.h" | 24 #include "media/formats/mp4/box_definitions.h" |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 } | 181 } |
181 | 182 |
182 bool MP4StreamParser::ParseMoov(BoxReader* reader) { | 183 bool MP4StreamParser::ParseMoov(BoxReader* reader) { |
183 moov_.reset(new Movie); | 184 moov_.reset(new Movie); |
184 RCHECK(moov_->Parse(reader)); | 185 RCHECK(moov_->Parse(reader)); |
185 runs_.reset(); | 186 runs_.reset(); |
186 | 187 |
187 has_audio_ = false; | 188 has_audio_ = false; |
188 has_video_ = false; | 189 has_video_ = false; |
189 | 190 |
| 191 scoped_ptr<MediaTracks> media_tracks(new MediaTracks()); |
190 AudioDecoderConfig audio_config; | 192 AudioDecoderConfig audio_config; |
191 VideoDecoderConfig video_config; | 193 VideoDecoderConfig video_config; |
192 | 194 |
193 for (std::vector<Track>::const_iterator track = moov_->tracks.begin(); | 195 for (std::vector<Track>::const_iterator track = moov_->tracks.begin(); |
194 track != moov_->tracks.end(); ++track) { | 196 track != moov_->tracks.end(); ++track) { |
195 // TODO(strobe): Only the first audio and video track present in a file are | 197 // TODO(strobe): Only the first audio and video track present in a file are |
196 // used. (Track selection is better accomplished via Source IDs, though, so | 198 // used. (Track selection is better accomplished via Source IDs, though, so |
197 // adding support for track selection within a stream is low-priority.) | 199 // adding support for track selection within a stream is low-priority.) |
198 const SampleDescription& samp_descr = | 200 const SampleDescription& samp_descr = |
199 track->media.information.sample_table.description; | 201 track->media.information.sample_table.description; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 return false; | 302 return false; |
301 } | 303 } |
302 | 304 |
303 is_audio_track_encrypted_ = entry.sinf.info.track_encryption.is_encrypted; | 305 is_audio_track_encrypted_ = entry.sinf.info.track_encryption.is_encrypted; |
304 DVLOG(1) << "is_audio_track_encrypted_: " << is_audio_track_encrypted_; | 306 DVLOG(1) << "is_audio_track_encrypted_: " << is_audio_track_encrypted_; |
305 audio_config.Initialize(codec, sample_format, channel_layout, | 307 audio_config.Initialize(codec, sample_format, channel_layout, |
306 sample_per_second, extra_data, | 308 sample_per_second, extra_data, |
307 is_audio_track_encrypted_, base::TimeDelta(), 0); | 309 is_audio_track_encrypted_, base::TimeDelta(), 0); |
308 has_audio_ = true; | 310 has_audio_ = true; |
309 audio_track_id_ = track->header.track_id; | 311 audio_track_id_ = track->header.track_id; |
| 312 media_tracks->AddAudioTrack( |
| 313 audio_config, base::UintToString(audio_track_id_), "main", |
| 314 track->media.handler.name, track->media.header.language()); |
310 } | 315 } |
311 if (track->media.handler.type == kVideo && !video_config.IsValidConfig()) { | 316 if (track->media.handler.type == kVideo && !video_config.IsValidConfig()) { |
312 RCHECK(!samp_descr.video_entries.empty()); | 317 RCHECK(!samp_descr.video_entries.empty()); |
313 if (desc_idx >= samp_descr.video_entries.size()) | 318 if (desc_idx >= samp_descr.video_entries.size()) |
314 desc_idx = 0; | 319 desc_idx = 0; |
315 const VideoSampleEntry& entry = samp_descr.video_entries[desc_idx]; | 320 const VideoSampleEntry& entry = samp_descr.video_entries[desc_idx]; |
316 | 321 |
317 if (!entry.IsFormatValid()) { | 322 if (!entry.IsFormatValid()) { |
318 MEDIA_LOG(ERROR, media_log_) << "Unsupported video format 0x" | 323 MEDIA_LOG(ERROR, media_log_) << "Unsupported video format 0x" |
319 << std::hex << entry.format | 324 << std::hex << entry.format |
(...skipping 21 matching lines...) Expand all Loading... |
341 is_video_track_encrypted_ = entry.sinf.info.track_encryption.is_encrypted; | 346 is_video_track_encrypted_ = entry.sinf.info.track_encryption.is_encrypted; |
342 DVLOG(1) << "is_video_track_encrypted_: " << is_video_track_encrypted_; | 347 DVLOG(1) << "is_video_track_encrypted_: " << is_video_track_encrypted_; |
343 video_config.Initialize( | 348 video_config.Initialize( |
344 entry.video_codec, entry.video_codec_profile, PIXEL_FORMAT_YV12, | 349 entry.video_codec, entry.video_codec_profile, PIXEL_FORMAT_YV12, |
345 COLOR_SPACE_HD_REC709, coded_size, visible_rect, natural_size, | 350 COLOR_SPACE_HD_REC709, coded_size, visible_rect, natural_size, |
346 // No decoder-specific buffer needed for AVC; | 351 // No decoder-specific buffer needed for AVC; |
347 // SPS/PPS are embedded in the video stream | 352 // SPS/PPS are embedded in the video stream |
348 std::vector<uint8_t>(), is_video_track_encrypted_); | 353 std::vector<uint8_t>(), is_video_track_encrypted_); |
349 has_video_ = true; | 354 has_video_ = true; |
350 video_track_id_ = track->header.track_id; | 355 video_track_id_ = track->header.track_id; |
| 356 media_tracks->AddVideoTrack( |
| 357 video_config, base::UintToString(video_track_id_), "main", |
| 358 track->media.handler.name, track->media.header.language()); |
351 } | 359 } |
352 } | 360 } |
353 | 361 |
354 if (!moov_->pssh.empty()) | 362 if (!moov_->pssh.empty()) |
355 OnEncryptedMediaInitData(moov_->pssh); | 363 OnEncryptedMediaInitData(moov_->pssh); |
356 | 364 |
357 scoped_ptr<MediaTracks> media_tracks(new MediaTracks()); | |
358 // TODO(servolk): Implement proper sourcing of media track info as described | |
359 // in crbug.com/590085 | |
360 if (audio_config.IsValidConfig()) { | |
361 media_tracks->AddAudioTrack(audio_config, "audio", "", "", ""); | |
362 } | |
363 if (video_config.IsValidConfig()) { | |
364 media_tracks->AddVideoTrack(video_config, "video", "", "", ""); | |
365 } | |
366 RCHECK(config_cb_.Run(std::move(media_tracks), TextTrackConfigMap())); | 365 RCHECK(config_cb_.Run(std::move(media_tracks), TextTrackConfigMap())); |
367 | 366 |
368 StreamParser::InitParameters params(kInfiniteDuration()); | 367 StreamParser::InitParameters params(kInfiniteDuration()); |
369 if (moov_->extends.header.fragment_duration > 0) { | 368 if (moov_->extends.header.fragment_duration > 0) { |
370 params.duration = TimeDeltaFromRational( | 369 params.duration = TimeDeltaFromRational( |
371 moov_->extends.header.fragment_duration, moov_->header.timescale); | 370 moov_->extends.header.fragment_duration, moov_->header.timescale); |
372 params.liveness = DemuxerStream::LIVENESS_RECORDED; | 371 params.liveness = DemuxerStream::LIVENESS_RECORDED; |
373 } else if (moov_->header.duration > 0 && | 372 } else if (moov_->header.duration > 0 && |
374 moov_->header.duration != std::numeric_limits<uint64_t>::max()) { | 373 moov_->header.duration != std::numeric_limits<uint64_t>::max()) { |
375 params.duration = | 374 params.duration = |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 runs.AdvanceSample(); | 665 runs.AdvanceSample(); |
667 } | 666 } |
668 runs.AdvanceRun(); | 667 runs.AdvanceRun(); |
669 } | 668 } |
670 | 669 |
671 return true; | 670 return true; |
672 } | 671 } |
673 | 672 |
674 } // namespace mp4 | 673 } // namespace mp4 |
675 } // namespace media | 674 } // namespace media |
OLD | NEW |