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 "base/strings/string_number_conversions.h" |
18 #include "media/base/audio_decoder_config.h" | 19 #include "media/base/audio_decoder_config.h" |
19 #include "media/base/bind_to_current_loop.h" | 20 #include "media/base/bind_to_current_loop.h" |
| 21 #include "media/base/media_tracks.h" |
20 #include "media/base/stream_parser_buffer.h" | 22 #include "media/base/stream_parser_buffer.h" |
21 #include "media/base/timestamp_constants.h" | 23 #include "media/base/timestamp_constants.h" |
22 #include "media/base/video_decoder_config.h" | 24 #include "media/base/video_decoder_config.h" |
23 #include "media/filters/frame_processor.h" | 25 #include "media/filters/frame_processor.h" |
24 #include "media/filters/stream_parser_factory.h" | 26 #include "media/filters/stream_parser_factory.h" |
25 | 27 |
26 using base::TimeDelta; | 28 using base::TimeDelta; |
27 | 29 |
28 namespace media { | 30 namespace media { |
29 | 31 |
30 ChunkDemuxerStream::ChunkDemuxerStream(Type type, | 32 ChunkDemuxerStream::ChunkDemuxerStream(Type type, |
31 bool splice_frames_enabled) | 33 bool splice_frames_enabled, |
| 34 MediaTrack::Id media_track_id) |
32 : type_(type), | 35 : type_(type), |
33 liveness_(DemuxerStream::LIVENESS_UNKNOWN), | 36 liveness_(DemuxerStream::LIVENESS_UNKNOWN), |
| 37 media_track_id_(media_track_id), |
34 state_(UNINITIALIZED), | 38 state_(UNINITIALIZED), |
35 splice_frames_enabled_(splice_frames_enabled), | 39 splice_frames_enabled_(splice_frames_enabled), |
36 partial_append_window_trimming_enabled_(false) { | 40 partial_append_window_trimming_enabled_(false) {} |
37 } | |
38 | 41 |
39 void ChunkDemuxerStream::StartReturningData() { | 42 void ChunkDemuxerStream::StartReturningData() { |
40 DVLOG(1) << "ChunkDemuxerStream::StartReturningData()"; | 43 DVLOG(1) << "ChunkDemuxerStream::StartReturningData()"; |
41 base::AutoLock auto_lock(lock_); | 44 base::AutoLock auto_lock(lock_); |
42 DCHECK(read_cb_.is_null()); | 45 DCHECK(read_cb_.is_null()); |
43 ChangeState_Locked(RETURNING_DATA_FOR_READS); | 46 ChangeState_Locked(RETURNING_DATA_FOR_READS); |
44 } | 47 } |
45 | 48 |
46 void ChunkDemuxerStream::AbortReads() { | 49 void ChunkDemuxerStream::AbortReads() { |
47 DVLOG(1) << "ChunkDemuxerStream::AbortReads()"; | 50 DVLOG(1) << "ChunkDemuxerStream::AbortReads()"; |
(...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
996 StartReturningData(); | 999 StartReturningData(); |
997 | 1000 |
998 if (duration_ == kNoTimestamp()) | 1001 if (duration_ == kNoTimestamp()) |
999 duration_ = kInfiniteDuration(); | 1002 duration_ = kInfiniteDuration(); |
1000 | 1003 |
1001 // The demuxer is now initialized after the |start_timestamp_| was set. | 1004 // The demuxer is now initialized after the |start_timestamp_| was set. |
1002 ChangeState_Locked(INITIALIZED); | 1005 ChangeState_Locked(INITIALIZED); |
1003 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); | 1006 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); |
1004 } | 1007 } |
1005 | 1008 |
| 1009 // static |
| 1010 MediaTrack::Id ChunkDemuxer::GenerateMediaTrackId() { |
| 1011 static unsigned g_track_count = 0; |
| 1012 return base::UintToString(++g_track_count); |
| 1013 } |
| 1014 |
1006 ChunkDemuxerStream* ChunkDemuxer::CreateDemuxerStream( | 1015 ChunkDemuxerStream* ChunkDemuxer::CreateDemuxerStream( |
1007 DemuxerStream::Type type) { | 1016 DemuxerStream::Type type) { |
| 1017 // New ChunkDemuxerStreams can be created only during initialization segment |
| 1018 // processing, which happens when a new chunk of data is appended and the |
| 1019 // lock_ must be held by ChunkDemuxer::AppendData. |
| 1020 lock_.AssertAcquired(); |
| 1021 |
| 1022 MediaTrack::Id media_track_id = GenerateMediaTrackId(); |
| 1023 |
1008 switch (type) { | 1024 switch (type) { |
1009 case DemuxerStream::AUDIO: | 1025 case DemuxerStream::AUDIO: |
1010 if (audio_) | 1026 if (audio_) |
1011 return NULL; | 1027 return NULL; |
1012 audio_.reset( | 1028 audio_.reset(new ChunkDemuxerStream( |
1013 new ChunkDemuxerStream(DemuxerStream::AUDIO, splice_frames_enabled_)); | 1029 DemuxerStream::AUDIO, splice_frames_enabled_, media_track_id)); |
1014 return audio_.get(); | 1030 return audio_.get(); |
1015 break; | 1031 break; |
1016 case DemuxerStream::VIDEO: | 1032 case DemuxerStream::VIDEO: |
1017 if (video_) | 1033 if (video_) |
1018 return NULL; | 1034 return NULL; |
1019 video_.reset( | 1035 video_.reset(new ChunkDemuxerStream( |
1020 new ChunkDemuxerStream(DemuxerStream::VIDEO, splice_frames_enabled_)); | 1036 DemuxerStream::VIDEO, splice_frames_enabled_, media_track_id)); |
1021 return video_.get(); | 1037 return video_.get(); |
1022 break; | 1038 break; |
1023 case DemuxerStream::TEXT: { | 1039 case DemuxerStream::TEXT: { |
1024 return new ChunkDemuxerStream(DemuxerStream::TEXT, | 1040 return new ChunkDemuxerStream(DemuxerStream::TEXT, splice_frames_enabled_, |
1025 splice_frames_enabled_); | 1041 media_track_id); |
1026 break; | 1042 break; |
1027 } | 1043 } |
1028 case DemuxerStream::UNKNOWN: | 1044 case DemuxerStream::UNKNOWN: |
1029 case DemuxerStream::NUM_TYPES: | 1045 case DemuxerStream::NUM_TYPES: |
1030 NOTREACHED(); | 1046 NOTREACHED(); |
1031 return NULL; | 1047 return NULL; |
1032 } | 1048 } |
1033 NOTREACHED(); | 1049 NOTREACHED(); |
1034 return NULL; | 1050 return NULL; |
1035 } | 1051 } |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1140 } | 1156 } |
1141 | 1157 |
1142 void ChunkDemuxer::ShutdownAllStreams() { | 1158 void ChunkDemuxer::ShutdownAllStreams() { |
1143 for (MediaSourceStateMap::iterator itr = source_state_map_.begin(); | 1159 for (MediaSourceStateMap::iterator itr = source_state_map_.begin(); |
1144 itr != source_state_map_.end(); ++itr) { | 1160 itr != source_state_map_.end(); ++itr) { |
1145 itr->second->Shutdown(); | 1161 itr->second->Shutdown(); |
1146 } | 1162 } |
1147 } | 1163 } |
1148 | 1164 |
1149 } // namespace media | 1165 } // namespace media |
OLD | NEW |