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