OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/filters/chunk_demuxer.h" | 5 #include "media/filters/chunk_demuxer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <list> | 9 #include <list> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/callback_helpers.h" | 13 #include "base/callback_helpers.h" |
14 #include "base/location.h" | 14 #include "base/location.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
18 #include "media/base/audio_decoder_config.h" | 18 #include "media/base/audio_decoder_config.h" |
19 #include "media/base/bind_to_current_loop.h" | 19 #include "media/base/bind_to_current_loop.h" |
| 20 #include "media/base/media_tracks.h" |
20 #include "media/base/stream_parser_buffer.h" | 21 #include "media/base/stream_parser_buffer.h" |
21 #include "media/base/timestamp_constants.h" | 22 #include "media/base/timestamp_constants.h" |
22 #include "media/base/video_decoder_config.h" | 23 #include "media/base/video_decoder_config.h" |
23 #include "media/filters/frame_processor.h" | 24 #include "media/filters/frame_processor.h" |
24 #include "media/filters/stream_parser_factory.h" | 25 #include "media/filters/stream_parser_factory.h" |
25 | 26 |
26 using base::TimeDelta; | 27 using base::TimeDelta; |
27 | 28 |
28 namespace media { | 29 namespace media { |
29 | 30 |
(...skipping 967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 | 998 |
998 if (duration_ == kNoTimestamp()) | 999 if (duration_ == kNoTimestamp()) |
999 duration_ = kInfiniteDuration(); | 1000 duration_ = kInfiniteDuration(); |
1000 | 1001 |
1001 // The demuxer is now initialized after the |start_timestamp_| was set. | 1002 // The demuxer is now initialized after the |start_timestamp_| was set. |
1002 ChangeState_Locked(INITIALIZED); | 1003 ChangeState_Locked(INITIALIZED); |
1003 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); | 1004 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); |
1004 } | 1005 } |
1005 | 1006 |
1006 ChunkDemuxerStream* ChunkDemuxer::CreateDemuxerStream( | 1007 ChunkDemuxerStream* ChunkDemuxer::CreateDemuxerStream( |
1007 DemuxerStream::Type type) { | 1008 const MediaTrack& media_track) { |
1008 switch (type) { | 1009 // Demuxer streams can only be created when ChunkDemuxer::AppendData is in |
1009 case DemuxerStream::AUDIO: | 1010 // progress. |
| 1011 lock_.AssertAcquired(); |
| 1012 switch (media_track.type()) { |
| 1013 case MediaTrack::Audio: |
1010 if (audio_) | 1014 if (audio_) |
1011 return NULL; | 1015 return NULL; |
1012 audio_.reset( | 1016 audio_.reset( |
1013 new ChunkDemuxerStream(DemuxerStream::AUDIO, splice_frames_enabled_)); | 1017 new ChunkDemuxerStream(DemuxerStream::AUDIO, splice_frames_enabled_)); |
1014 return audio_.get(); | 1018 return audio_.get(); |
1015 break; | 1019 break; |
1016 case DemuxerStream::VIDEO: | 1020 case MediaTrack::Video: |
1017 if (video_) | 1021 if (video_) |
1018 return NULL; | 1022 return NULL; |
1019 video_.reset( | 1023 video_.reset( |
1020 new ChunkDemuxerStream(DemuxerStream::VIDEO, splice_frames_enabled_)); | 1024 new ChunkDemuxerStream(DemuxerStream::VIDEO, splice_frames_enabled_)); |
1021 return video_.get(); | 1025 return video_.get(); |
1022 break; | 1026 break; |
1023 case DemuxerStream::TEXT: { | 1027 case MediaTrack::Text: { |
1024 return new ChunkDemuxerStream(DemuxerStream::TEXT, | 1028 return new ChunkDemuxerStream(DemuxerStream::TEXT, |
1025 splice_frames_enabled_); | 1029 splice_frames_enabled_); |
1026 break; | 1030 break; |
1027 } | 1031 } |
1028 case DemuxerStream::UNKNOWN: | |
1029 case DemuxerStream::NUM_TYPES: | |
1030 NOTREACHED(); | |
1031 return NULL; | |
1032 } | 1032 } |
1033 NOTREACHED(); | 1033 NOTREACHED(); |
1034 return NULL; | 1034 return NULL; |
1035 } | 1035 } |
1036 | 1036 |
1037 void ChunkDemuxer::OnNewTextTrack(ChunkDemuxerStream* text_stream, | 1037 void ChunkDemuxer::OnNewTextTrack(ChunkDemuxerStream* text_stream, |
1038 const TextTrackConfig& config) { | 1038 const TextTrackConfig& config) { |
1039 lock_.AssertAcquired(); | 1039 lock_.AssertAcquired(); |
1040 DCHECK_NE(state_, SHUTDOWN); | 1040 DCHECK_NE(state_, SHUTDOWN); |
1041 host_->AddTextStream(text_stream, config); | 1041 host_->AddTextStream(text_stream, config); |
1042 } | 1042 } |
1043 | 1043 |
| 1044 void ChunkDemuxer::OnTrackIdsAssigned(const MediaTracks& tracks, |
| 1045 const std::vector<unsigned>& track_ids) { |
| 1046 // New tracks and therefore track id assignements can happen only during |
| 1047 // ChunkDemuxer::AppendData processing, which should be holding the lock. |
| 1048 lock_.AssertAcquired(); |
| 1049 |
| 1050 const auto& new_track_id_map = tracks.OnTrackIdsAssigned(track_ids); |
| 1051 |
| 1052 // ChunkDemuxer might have multiple media track sets (since it can have |
| 1053 // multiple SourceBuffers), so we need to merge the map for the current set of |
| 1054 // tracks with the global |track_id_to_demux_stream_| map shared across all |
| 1055 // SourceBuffers. |
| 1056 for (const auto& it : new_track_id_map) { |
| 1057 track_id_to_demux_stream_[it.first] = it.second; |
| 1058 } |
| 1059 } |
| 1060 |
| 1061 const DemuxerStream* ChunkDemuxer::GetDemuxerStreamByTrackId( |
| 1062 unsigned track_id) const { |
| 1063 base::AutoLock auto_lock(lock_); |
| 1064 const auto& it = track_id_to_demux_stream_.find(track_id); |
| 1065 CHECK(it != track_id_to_demux_stream_.end()); |
| 1066 return it->second; |
| 1067 } |
| 1068 |
1044 bool ChunkDemuxer::IsValidId(const std::string& source_id) const { | 1069 bool ChunkDemuxer::IsValidId(const std::string& source_id) const { |
1045 lock_.AssertAcquired(); | 1070 lock_.AssertAcquired(); |
1046 return source_state_map_.count(source_id) > 0u; | 1071 return source_state_map_.count(source_id) > 0u; |
1047 } | 1072 } |
1048 | 1073 |
1049 void ChunkDemuxer::UpdateDuration(TimeDelta new_duration) { | 1074 void ChunkDemuxer::UpdateDuration(TimeDelta new_duration) { |
1050 DCHECK(duration_ != new_duration); | 1075 DCHECK(duration_ != new_duration); |
1051 user_specified_duration_ = -1; | 1076 user_specified_duration_ = -1; |
1052 duration_ = new_duration; | 1077 duration_ = new_duration; |
1053 host_->SetDuration(new_duration); | 1078 host_->SetDuration(new_duration); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1140 } | 1165 } |
1141 | 1166 |
1142 void ChunkDemuxer::ShutdownAllStreams() { | 1167 void ChunkDemuxer::ShutdownAllStreams() { |
1143 for (MediaSourceStateMap::iterator itr = source_state_map_.begin(); | 1168 for (MediaSourceStateMap::iterator itr = source_state_map_.begin(); |
1144 itr != source_state_map_.end(); ++itr) { | 1169 itr != source_state_map_.end(); ++itr) { |
1145 itr->second->Shutdown(); | 1170 itr->second->Shutdown(); |
1146 } | 1171 } |
1147 } | 1172 } |
1148 | 1173 |
1149 } // namespace media | 1174 } // namespace media |
OLD | NEW |