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 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/message_loop/message_loop_proxy.h" | 14 #include "base/message_loop/message_loop_proxy.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "media/base/audio_decoder_config.h" | 16 #include "media/base/audio_decoder_config.h" |
17 #include "media/base/bind_to_current_loop.h" | 17 #include "media/base/bind_to_current_loop.h" |
18 #include "media/base/stream_parser_buffer.h" | 18 #include "media/base/stream_parser_buffer.h" |
19 #include "media/base/video_decoder_config.h" | 19 #include "media/base/video_decoder_config.h" |
| 20 #include "media/filters/frame_processor.h" |
20 #include "media/filters/legacy_frame_processor.h" | 21 #include "media/filters/legacy_frame_processor.h" |
21 #include "media/filters/stream_parser_factory.h" | 22 #include "media/filters/stream_parser_factory.h" |
22 | 23 |
23 using base::TimeDelta; | 24 using base::TimeDelta; |
24 | 25 |
25 namespace media { | 26 namespace media { |
26 | 27 |
27 static TimeDelta EndTimestamp(const StreamParser::BufferQueue& queue) { | 28 static TimeDelta EndTimestamp(const StreamParser::BufferQueue& queue) { |
28 return queue.back()->timestamp() + queue.back()->duration(); | 29 return queue.back()->timestamp() + queue.back()->duration(); |
29 } | 30 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 // Calls Remove(|start|, |end|, |duration|) on all | 126 // Calls Remove(|start|, |end|, |duration|) on all |
126 // ChunkDemuxerStreams managed by this object. | 127 // ChunkDemuxerStreams managed by this object. |
127 void Remove(TimeDelta start, TimeDelta end, TimeDelta duration); | 128 void Remove(TimeDelta start, TimeDelta end, TimeDelta duration); |
128 | 129 |
129 // Returns true if currently parsing a media segment, or false otherwise. | 130 // Returns true if currently parsing a media segment, or false otherwise. |
130 bool parsing_media_segment() const { return parsing_media_segment_; } | 131 bool parsing_media_segment() const { return parsing_media_segment_; } |
131 | 132 |
132 // Sets |frame_processor_|'s sequence mode to |sequence_mode|. | 133 // Sets |frame_processor_|'s sequence mode to |sequence_mode|. |
133 void SetSequenceMode(bool sequence_mode); | 134 void SetSequenceMode(bool sequence_mode); |
134 | 135 |
| 136 // Signals the coded frame processor to update its group start timestamp to be |
| 137 // |timestamp_offset| if it is in sequence append mode. |
| 138 void SetGroupStartTimestampIfInSequenceMode(base::TimeDelta timestamp_offset); |
| 139 |
135 // Returns the range of buffered data in this source, capped at |duration|. | 140 // Returns the range of buffered data in this source, capped at |duration|. |
136 // |ended| - Set to true if end of stream has been signaled and the special | 141 // |ended| - Set to true if end of stream has been signaled and the special |
137 // end of stream range logic needs to be executed. | 142 // end of stream range logic needs to be executed. |
138 Ranges<TimeDelta> GetBufferedRanges(TimeDelta duration, bool ended) const; | 143 Ranges<TimeDelta> GetBufferedRanges(TimeDelta duration, bool ended) const; |
139 | 144 |
140 // Returns the highest buffered duration across all streams managed | 145 // Returns the highest buffered duration across all streams managed |
141 // by this object. | 146 // by this object. |
142 // Returns TimeDelta() if none of the streams contain buffered data. | 147 // Returns TimeDelta() if none of the streams contain buffered data. |
143 TimeDelta GetMaxBufferedDuration() const; | 148 TimeDelta GetMaxBufferedDuration() const; |
144 | 149 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 base::Bind(&SourceState::OnEndOfMediaSegment, base::Unretained(this)), | 284 base::Bind(&SourceState::OnEndOfMediaSegment, base::Unretained(this)), |
280 log_cb_); | 285 log_cb_); |
281 } | 286 } |
282 | 287 |
283 void SourceState::SetSequenceMode(bool sequence_mode) { | 288 void SourceState::SetSequenceMode(bool sequence_mode) { |
284 DCHECK(!parsing_media_segment_); | 289 DCHECK(!parsing_media_segment_); |
285 | 290 |
286 frame_processor_->SetSequenceMode(sequence_mode); | 291 frame_processor_->SetSequenceMode(sequence_mode); |
287 } | 292 } |
288 | 293 |
| 294 void SourceState::SetGroupStartTimestampIfInSequenceMode( |
| 295 base::TimeDelta timestamp_offset) { |
| 296 DCHECK(!parsing_media_segment_); |
| 297 |
| 298 frame_processor_->SetGroupStartTimestampIfInSequenceMode(timestamp_offset); |
| 299 } |
| 300 |
289 bool SourceState::Append(const uint8* data, size_t length, | 301 bool SourceState::Append(const uint8* data, size_t length, |
290 TimeDelta append_window_start, | 302 TimeDelta append_window_start, |
291 TimeDelta append_window_end, | 303 TimeDelta append_window_end, |
292 TimeDelta* timestamp_offset) { | 304 TimeDelta* timestamp_offset) { |
293 DCHECK(timestamp_offset); | 305 DCHECK(timestamp_offset); |
294 DCHECK(!timestamp_offset_during_append_); | 306 DCHECK(!timestamp_offset_during_append_); |
295 timestamp_offset_during_append_ = timestamp_offset; | |
296 append_window_start_during_append_ = append_window_start; | 307 append_window_start_during_append_ = append_window_start; |
297 append_window_end_during_append_ = append_window_end; | 308 append_window_end_during_append_ = append_window_end; |
| 309 timestamp_offset_during_append_ = timestamp_offset; |
298 | 310 |
299 // TODO(wolenetz/acolwell): Curry and pass a NewBuffersCB here bound with | 311 // TODO(wolenetz/acolwell): Curry and pass a NewBuffersCB here bound with |
300 // append window and timestamp offset pointer. See http://crbug.com/351454. | 312 // append window and timestamp offset pointer. See http://crbug.com/351454. |
301 bool err = stream_parser_->Parse(data, length); | 313 bool err = stream_parser_->Parse(data, length); |
302 timestamp_offset_during_append_ = NULL; | 314 timestamp_offset_during_append_ = NULL; |
303 return err; | 315 return err; |
304 } | 316 } |
305 | 317 |
306 void SourceState::Abort(TimeDelta append_window_start, | 318 void SourceState::Abort(TimeDelta append_window_start, |
307 TimeDelta append_window_end, | 319 TimeDelta append_window_end, |
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1155 if ((has_audio && !source_id_audio_.empty()) || | 1167 if ((has_audio && !source_id_audio_.empty()) || |
1156 (has_video && !source_id_video_.empty())) | 1168 (has_video && !source_id_video_.empty())) |
1157 return kReachedIdLimit; | 1169 return kReachedIdLimit; |
1158 | 1170 |
1159 if (has_audio) | 1171 if (has_audio) |
1160 source_id_audio_ = id; | 1172 source_id_audio_ = id; |
1161 | 1173 |
1162 if (has_video) | 1174 if (has_video) |
1163 source_id_video_ = id; | 1175 source_id_video_ = id; |
1164 | 1176 |
1165 if (!use_legacy_frame_processor) { | 1177 scoped_ptr<FrameProcessorBase> frame_processor; |
1166 DLOG(WARNING) << "New frame processor is not yet supported. Using legacy."; | 1178 if (use_legacy_frame_processor) { |
| 1179 frame_processor.reset(new LegacyFrameProcessor( |
| 1180 base::Bind(&ChunkDemuxer::IncreaseDurationIfNecessary, |
| 1181 base::Unretained(this)))); |
| 1182 } else { |
| 1183 frame_processor.reset(new FrameProcessor( |
| 1184 base::Bind(&ChunkDemuxer::IncreaseDurationIfNecessary, |
| 1185 base::Unretained(this)))); |
1167 } | 1186 } |
1168 | 1187 |
1169 scoped_ptr<FrameProcessorBase> frame_processor(new LegacyFrameProcessor( | |
1170 base::Bind(&ChunkDemuxer::IncreaseDurationIfNecessary, | |
1171 base::Unretained(this)))); | |
1172 | |
1173 scoped_ptr<SourceState> source_state( | 1188 scoped_ptr<SourceState> source_state( |
1174 new SourceState(stream_parser.Pass(), | 1189 new SourceState(stream_parser.Pass(), |
1175 frame_processor.Pass(), log_cb_, | 1190 frame_processor.Pass(), log_cb_, |
1176 base::Bind(&ChunkDemuxer::CreateDemuxerStream, | 1191 base::Bind(&ChunkDemuxer::CreateDemuxerStream, |
1177 base::Unretained(this)))); | 1192 base::Unretained(this)))); |
1178 | 1193 |
1179 SourceState::NewTextTrackCB new_text_track_cb; | 1194 SourceState::NewTextTrackCB new_text_track_cb; |
1180 | 1195 |
1181 if (enable_text_) { | 1196 if (enable_text_) { |
1182 new_text_track_cb = base::Bind(&ChunkDemuxer::OnNewTextTrack, | 1197 new_text_track_cb = base::Bind(&ChunkDemuxer::OnNewTextTrack, |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1388 void ChunkDemuxer::SetSequenceMode(const std::string& id, | 1403 void ChunkDemuxer::SetSequenceMode(const std::string& id, |
1389 bool sequence_mode) { | 1404 bool sequence_mode) { |
1390 base::AutoLock auto_lock(lock_); | 1405 base::AutoLock auto_lock(lock_); |
1391 DVLOG(1) << "SetSequenceMode(" << id << ", " << sequence_mode << ")"; | 1406 DVLOG(1) << "SetSequenceMode(" << id << ", " << sequence_mode << ")"; |
1392 CHECK(IsValidId(id)); | 1407 CHECK(IsValidId(id)); |
1393 DCHECK_NE(state_, ENDED); | 1408 DCHECK_NE(state_, ENDED); |
1394 | 1409 |
1395 source_state_map_[id]->SetSequenceMode(sequence_mode); | 1410 source_state_map_[id]->SetSequenceMode(sequence_mode); |
1396 } | 1411 } |
1397 | 1412 |
| 1413 void ChunkDemuxer::SetGroupStartTimestampIfInSequenceMode( |
| 1414 const std::string& id, |
| 1415 base::TimeDelta timestamp_offset) { |
| 1416 base::AutoLock auto_lock(lock_); |
| 1417 DVLOG(1) << "SetGroupStartTimestampIfInSequenceMode(" << id << ", " |
| 1418 << timestamp_offset.InSecondsF() << ")"; |
| 1419 CHECK(IsValidId(id)); |
| 1420 DCHECK_NE(state_, ENDED); |
| 1421 |
| 1422 source_state_map_[id]->SetGroupStartTimestampIfInSequenceMode( |
| 1423 timestamp_offset); |
| 1424 } |
| 1425 |
| 1426 |
1398 void ChunkDemuxer::MarkEndOfStream(PipelineStatus status) { | 1427 void ChunkDemuxer::MarkEndOfStream(PipelineStatus status) { |
1399 DVLOG(1) << "MarkEndOfStream(" << status << ")"; | 1428 DVLOG(1) << "MarkEndOfStream(" << status << ")"; |
1400 base::AutoLock auto_lock(lock_); | 1429 base::AutoLock auto_lock(lock_); |
1401 DCHECK_NE(state_, WAITING_FOR_INIT); | 1430 DCHECK_NE(state_, WAITING_FOR_INIT); |
1402 DCHECK_NE(state_, ENDED); | 1431 DCHECK_NE(state_, ENDED); |
1403 | 1432 |
1404 if (state_ == SHUTDOWN || state_ == PARSE_ERROR) | 1433 if (state_ == SHUTDOWN || state_ == PARSE_ERROR) |
1405 return; | 1434 return; |
1406 | 1435 |
1407 if (state_ == INITIALIZING) { | 1436 if (state_ == INITIALIZING) { |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1618 | 1647 |
1619 void ChunkDemuxer::UpdateDuration(TimeDelta new_duration) { | 1648 void ChunkDemuxer::UpdateDuration(TimeDelta new_duration) { |
1620 DCHECK(duration_ != new_duration); | 1649 DCHECK(duration_ != new_duration); |
1621 user_specified_duration_ = -1; | 1650 user_specified_duration_ = -1; |
1622 duration_ = new_duration; | 1651 duration_ = new_duration; |
1623 host_->SetDuration(new_duration); | 1652 host_->SetDuration(new_duration); |
1624 } | 1653 } |
1625 | 1654 |
1626 void ChunkDemuxer::IncreaseDurationIfNecessary(TimeDelta new_duration) { | 1655 void ChunkDemuxer::IncreaseDurationIfNecessary(TimeDelta new_duration) { |
1627 DCHECK(new_duration != kNoTimestamp()); | 1656 DCHECK(new_duration != kNoTimestamp()); |
| 1657 DCHECK(new_duration != kInfiniteDuration()); |
| 1658 |
| 1659 // Per April 1, 2014 MSE spec editor's draft: |
| 1660 // https://dvcs.w3.org/hg/html-media/raw-file/d471a4412040/media-source/media-
source.html#sourcebuffer-coded-frame-processing |
| 1661 // 5. If the media segment contains data beyond the current duration, then run |
| 1662 // the duration change algorithm with new duration set to the maximum of |
| 1663 // the current duration and the group end timestamp. |
1628 | 1664 |
1629 if (new_duration <= duration_) | 1665 if (new_duration <= duration_) |
1630 return; | 1666 return; |
1631 | 1667 |
1632 DVLOG(2) << __FUNCTION__ << ": Increasing duration: " | 1668 DVLOG(2) << __FUNCTION__ << ": Increasing duration: " |
1633 << duration_.InSecondsF() << " -> " << new_duration.InSecondsF(); | 1669 << duration_.InSecondsF() << " -> " << new_duration.InSecondsF(); |
1634 | 1670 |
1635 UpdateDuration(new_duration); | 1671 UpdateDuration(new_duration); |
1636 } | 1672 } |
1637 | 1673 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1702 } | 1738 } |
1703 | 1739 |
1704 void ChunkDemuxer::ShutdownAllStreams() { | 1740 void ChunkDemuxer::ShutdownAllStreams() { |
1705 for (SourceStateMap::iterator itr = source_state_map_.begin(); | 1741 for (SourceStateMap::iterator itr = source_state_map_.begin(); |
1706 itr != source_state_map_.end(); ++itr) { | 1742 itr != source_state_map_.end(); ++itr) { |
1707 itr->second->Shutdown(); | 1743 itr->second->Shutdown(); |
1708 } | 1744 } |
1709 } | 1745 } |
1710 | 1746 |
1711 } // namespace media | 1747 } // namespace media |
OLD | NEW |