| 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 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 // Contains state belonging to a source id. | 86 // Contains state belonging to a source id. |
| 87 class SourceState { | 87 class SourceState { |
| 88 public: | 88 public: |
| 89 // Callback signature used to create ChunkDemuxerStreams. | 89 // Callback signature used to create ChunkDemuxerStreams. |
| 90 typedef base::Callback<ChunkDemuxerStream*( | 90 typedef base::Callback<ChunkDemuxerStream*( |
| 91 DemuxerStream::Type)> CreateDemuxerStreamCB; | 91 DemuxerStream::Type)> CreateDemuxerStreamCB; |
| 92 | 92 |
| 93 typedef base::Callback<void( | 93 typedef base::Callback<void( |
| 94 ChunkDemuxerStream*, const TextTrackConfig&)> NewTextTrackCB; | 94 ChunkDemuxerStream*, const TextTrackConfig&)> NewTextTrackCB; |
| 95 | 95 |
| 96 // First parameter - Indicates initialization success. Set to true if | |
| 97 // initialization was successful. False if an error | |
| 98 // occurred. | |
| 99 // Second parameter - Indicates the stream duration. Only contains a valid | |
| 100 // value if the first parameter is true. | |
| 101 // Third parameter - Indicates the source Time associated with | |
| 102 // presentation timestamp 0. A null Time is returned if | |
| 103 // no mapping to Time exists. Only contains a | |
| 104 // valid value if the first parameter is true. | |
| 105 typedef base::Callback<void(bool, TimeDelta, base::Time)> InitCB; | |
| 106 | |
| 107 SourceState( | 96 SourceState( |
| 108 scoped_ptr<StreamParser> stream_parser, | 97 scoped_ptr<StreamParser> stream_parser, |
| 109 scoped_ptr<FrameProcessorBase> frame_processor, const LogCB& log_cb, | 98 scoped_ptr<FrameProcessorBase> frame_processor, const LogCB& log_cb, |
| 110 const CreateDemuxerStreamCB& create_demuxer_stream_cb); | 99 const CreateDemuxerStreamCB& create_demuxer_stream_cb); |
| 111 | 100 |
| 112 ~SourceState(); | 101 ~SourceState(); |
| 113 | 102 |
| 114 void Init(const InitCB& init_cb, | 103 void Init(const StreamParser::InitCB& init_cb, |
| 115 bool allow_audio, | 104 bool allow_audio, |
| 116 bool allow_video, | 105 bool allow_video, |
| 117 const StreamParser::NeedKeyCB& need_key_cb, | 106 const StreamParser::NeedKeyCB& need_key_cb, |
| 118 const NewTextTrackCB& new_text_track_cb); | 107 const NewTextTrackCB& new_text_track_cb); |
| 119 | 108 |
| 120 // Appends new data to the StreamParser. | 109 // Appends new data to the StreamParser. |
| 121 // Returns true if the data was successfully appended. Returns false if an | 110 // Returns true if the data was successfully appended. Returns false if an |
| 122 // error occurred. |*timestamp_offset| is used and possibly updated by the | 111 // error occurred. |*timestamp_offset| is used and possibly updated by the |
| 123 // append. |append_window_start| and |append_window_end| correspond to the MSE | 112 // append. |append_window_start| and |append_window_end| correspond to the MSE |
| 124 // spec's similarly named source buffer attributes that are used in coded | 113 // spec's similarly named source buffer attributes that are used in coded |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 // It processes the new buffers using |frame_processor_|, which includes | 175 // It processes the new buffers using |frame_processor_|, which includes |
| 187 // appending the processed frames to associated demuxer streams for each | 176 // appending the processed frames to associated demuxer streams for each |
| 188 // frame's track. | 177 // frame's track. |
| 189 // Returns true on a successful call. Returns false if an error occurred while | 178 // Returns true on a successful call. Returns false if an error occurred while |
| 190 // processing the buffers. | 179 // processing the buffers. |
| 191 bool OnNewBuffers(const StreamParser::BufferQueue& audio_buffers, | 180 bool OnNewBuffers(const StreamParser::BufferQueue& audio_buffers, |
| 192 const StreamParser::BufferQueue& video_buffers, | 181 const StreamParser::BufferQueue& video_buffers, |
| 193 const StreamParser::TextBufferQueueMap& text_map); | 182 const StreamParser::TextBufferQueueMap& text_map); |
| 194 | 183 |
| 195 void OnSourceInitDone(bool success, | 184 void OnSourceInitDone(bool success, |
| 196 TimeDelta duration, | 185 const StreamParser::StreamParameters& params); |
| 197 base::Time timeline_offset, | |
| 198 bool auto_update_timestamp_offset); | |
| 199 | 186 |
| 200 CreateDemuxerStreamCB create_demuxer_stream_cb_; | 187 CreateDemuxerStreamCB create_demuxer_stream_cb_; |
| 201 NewTextTrackCB new_text_track_cb_; | 188 NewTextTrackCB new_text_track_cb_; |
| 202 | 189 |
| 203 // During Append(), if OnNewBuffers() coded frame processing updates the | 190 // During Append(), if OnNewBuffers() coded frame processing updates the |
| 204 // timestamp offset then |*timestamp_offset_during_append_| is also updated | 191 // timestamp offset then |*timestamp_offset_during_append_| is also updated |
| 205 // so Append()'s caller can know the new offset. This pointer is only non-NULL | 192 // so Append()'s caller can know the new offset. This pointer is only non-NULL |
| 206 // during the lifetime of an Append() call. | 193 // during the lifetime of an Append() call. |
| 207 TimeDelta* timestamp_offset_during_append_; | 194 TimeDelta* timestamp_offset_during_append_; |
| 208 | 195 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 229 scoped_ptr<StreamParser> stream_parser_; | 216 scoped_ptr<StreamParser> stream_parser_; |
| 230 | 217 |
| 231 ChunkDemuxerStream* audio_; // Not owned by |this|. | 218 ChunkDemuxerStream* audio_; // Not owned by |this|. |
| 232 ChunkDemuxerStream* video_; // Not owned by |this|. | 219 ChunkDemuxerStream* video_; // Not owned by |this|. |
| 233 | 220 |
| 234 typedef std::map<StreamParser::TrackId, ChunkDemuxerStream*> TextStreamMap; | 221 typedef std::map<StreamParser::TrackId, ChunkDemuxerStream*> TextStreamMap; |
| 235 TextStreamMap text_stream_map_; // |this| owns the map's stream pointers. | 222 TextStreamMap text_stream_map_; // |this| owns the map's stream pointers. |
| 236 | 223 |
| 237 scoped_ptr<FrameProcessorBase> frame_processor_; | 224 scoped_ptr<FrameProcessorBase> frame_processor_; |
| 238 LogCB log_cb_; | 225 LogCB log_cb_; |
| 239 InitCB init_cb_; | 226 StreamParser::InitCB init_cb_; |
| 240 | 227 |
| 241 // Indicates that timestampOffset should be updated automatically during | 228 // Indicates that timestampOffset should be updated automatically during |
| 242 // OnNewBuffers() based on the earliest end timestamp of the buffers provided. | 229 // OnNewBuffers() based on the earliest end timestamp of the buffers provided. |
| 243 bool auto_update_timestamp_offset_; | 230 bool auto_update_timestamp_offset_; |
| 244 | 231 |
| 245 DISALLOW_COPY_AND_ASSIGN(SourceState); | 232 DISALLOW_COPY_AND_ASSIGN(SourceState); |
| 246 }; | 233 }; |
| 247 | 234 |
| 248 SourceState::SourceState(scoped_ptr<StreamParser> stream_parser, | 235 SourceState::SourceState(scoped_ptr<StreamParser> stream_parser, |
| 249 scoped_ptr<FrameProcessorBase> frame_processor, | 236 scoped_ptr<FrameProcessorBase> frame_processor, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 262 DCHECK(!create_demuxer_stream_cb_.is_null()); | 249 DCHECK(!create_demuxer_stream_cb_.is_null()); |
| 263 DCHECK(frame_processor_); | 250 DCHECK(frame_processor_); |
| 264 } | 251 } |
| 265 | 252 |
| 266 SourceState::~SourceState() { | 253 SourceState::~SourceState() { |
| 267 Shutdown(); | 254 Shutdown(); |
| 268 | 255 |
| 269 STLDeleteValues(&text_stream_map_); | 256 STLDeleteValues(&text_stream_map_); |
| 270 } | 257 } |
| 271 | 258 |
| 272 void SourceState::Init(const InitCB& init_cb, | 259 void SourceState::Init(const StreamParser::InitCB& init_cb, |
| 273 bool allow_audio, | 260 bool allow_audio, |
| 274 bool allow_video, | 261 bool allow_video, |
| 275 const StreamParser::NeedKeyCB& need_key_cb, | 262 const StreamParser::NeedKeyCB& need_key_cb, |
| 276 const NewTextTrackCB& new_text_track_cb) { | 263 const NewTextTrackCB& new_text_track_cb) { |
| 277 new_text_track_cb_ = new_text_track_cb; | 264 new_text_track_cb_ = new_text_track_cb; |
| 278 init_cb_ = init_cb; | 265 init_cb_ = init_cb; |
| 279 | 266 |
| 280 stream_parser_->Init( | 267 stream_parser_->Init( |
| 281 base::Bind(&SourceState::OnSourceInitDone, base::Unretained(this)), | 268 base::Bind(&SourceState::OnSourceInitDone, base::Unretained(this)), |
| 282 base::Bind(&SourceState::OnNewConfigs, | 269 base::Bind(&SourceState::OnNewConfigs, |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 | 680 |
| 694 // Only update the timestamp offset if the frame processor hasn't already. | 681 // Only update the timestamp offset if the frame processor hasn't already. |
| 695 if (auto_update_timestamp_offset_ && | 682 if (auto_update_timestamp_offset_ && |
| 696 timestamp_offset_before_processing == *timestamp_offset_during_append_) { | 683 timestamp_offset_before_processing == *timestamp_offset_during_append_) { |
| 697 *timestamp_offset_during_append_ = new_timestamp_offset; | 684 *timestamp_offset_during_append_ = new_timestamp_offset; |
| 698 } | 685 } |
| 699 | 686 |
| 700 return true; | 687 return true; |
| 701 } | 688 } |
| 702 | 689 |
| 703 void SourceState::OnSourceInitDone(bool success, | 690 void SourceState::OnSourceInitDone( |
| 704 TimeDelta duration, | 691 bool success, |
| 705 base::Time timeline_offset, | 692 const StreamParser::StreamParameters& params) { |
| 706 bool auto_update_timestamp_offset) { | 693 auto_update_timestamp_offset_ = params.auto_update_timestamp_offset; |
| 707 auto_update_timestamp_offset_ = auto_update_timestamp_offset; | 694 base::ResetAndReturn(&init_cb_).Run(success, params); |
| 708 base::ResetAndReturn(&init_cb_).Run( | |
| 709 success, duration, timeline_offset); | |
| 710 } | 695 } |
| 711 | 696 |
| 712 ChunkDemuxerStream::ChunkDemuxerStream(Type type, bool splice_frames_enabled) | 697 ChunkDemuxerStream::ChunkDemuxerStream(Type type, bool splice_frames_enabled) |
| 713 : type_(type), | 698 : type_(type), |
| 714 state_(UNINITIALIZED), | 699 state_(UNINITIALIZED), |
| 715 splice_frames_enabled_(splice_frames_enabled) {} | 700 splice_frames_enabled_(splice_frames_enabled) {} |
| 716 | 701 |
| 717 void ChunkDemuxerStream::StartReturningData() { | 702 void ChunkDemuxerStream::StartReturningData() { |
| 718 DVLOG(1) << "ChunkDemuxerStream::StartReturningData()"; | 703 DVLOG(1) << "ChunkDemuxerStream::StartReturningData()"; |
| 719 base::AutoLock auto_lock(lock_); | 704 base::AutoLock auto_lock(lock_); |
| (...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1490 lock_.AssertAcquired(); | 1475 lock_.AssertAcquired(); |
| 1491 for (SourceStateMap::const_iterator itr = source_state_map_.begin(); | 1476 for (SourceStateMap::const_iterator itr = source_state_map_.begin(); |
| 1492 itr != source_state_map_.end(); ++itr) { | 1477 itr != source_state_map_.end(); ++itr) { |
| 1493 if (itr->second->IsSeekWaitingForData()) | 1478 if (itr->second->IsSeekWaitingForData()) |
| 1494 return true; | 1479 return true; |
| 1495 } | 1480 } |
| 1496 | 1481 |
| 1497 return false; | 1482 return false; |
| 1498 } | 1483 } |
| 1499 | 1484 |
| 1500 void ChunkDemuxer::OnSourceInitDone(bool success, TimeDelta duration, | 1485 void ChunkDemuxer::OnSourceInitDone( |
| 1501 base::Time timeline_offset) { | 1486 bool success, |
| 1487 const StreamParser::StreamParameters& params) { |
| 1502 DVLOG(1) << "OnSourceInitDone(" << success << ", " | 1488 DVLOG(1) << "OnSourceInitDone(" << success << ", " |
| 1503 << duration.InSecondsF() << ")"; | 1489 << params.duration.InSecondsF() << ")"; |
| 1504 lock_.AssertAcquired(); | 1490 lock_.AssertAcquired(); |
| 1505 DCHECK_EQ(state_, INITIALIZING); | 1491 DCHECK_EQ(state_, INITIALIZING); |
| 1506 if (!success || (!audio_ && !video_)) { | 1492 if (!success || (!audio_ && !video_)) { |
| 1507 ReportError_Locked(DEMUXER_ERROR_COULD_NOT_OPEN); | 1493 ReportError_Locked(DEMUXER_ERROR_COULD_NOT_OPEN); |
| 1508 return; | 1494 return; |
| 1509 } | 1495 } |
| 1510 | 1496 |
| 1511 if (duration != TimeDelta() && duration_ == kNoTimestamp()) | 1497 if (params.duration != TimeDelta() && duration_ == kNoTimestamp()) |
| 1512 UpdateDuration(duration); | 1498 UpdateDuration(params.duration); |
| 1513 | 1499 |
| 1514 if (!timeline_offset.is_null()) { | 1500 if (!params.timeline_offset.is_null()) { |
| 1515 if (!timeline_offset_.is_null() && | 1501 if (!timeline_offset_.is_null() && |
| 1516 timeline_offset != timeline_offset_) { | 1502 params.timeline_offset != timeline_offset_) { |
| 1517 MEDIA_LOG(log_cb_) | 1503 MEDIA_LOG(log_cb_) |
| 1518 << "Timeline offset is not the same across all SourceBuffers."; | 1504 << "Timeline offset is not the same across all SourceBuffers."; |
| 1519 ReportError_Locked(DEMUXER_ERROR_COULD_NOT_OPEN); | 1505 ReportError_Locked(DEMUXER_ERROR_COULD_NOT_OPEN); |
| 1520 return; | 1506 return; |
| 1521 } | 1507 } |
| 1522 | 1508 |
| 1523 timeline_offset_ = timeline_offset; | 1509 timeline_offset_ = params.timeline_offset; |
| 1524 } | 1510 } |
| 1525 | 1511 |
| 1526 // Wait until all streams have initialized. | 1512 // Wait until all streams have initialized. |
| 1527 if ((!source_id_audio_.empty() && !audio_) || | 1513 if ((!source_id_audio_.empty() && !audio_) || |
| 1528 (!source_id_video_.empty() && !video_)) | 1514 (!source_id_video_.empty() && !video_)) { |
| 1529 return; | 1515 return; |
| 1516 } |
| 1530 | 1517 |
| 1531 SeekAllSources(GetStartTime()); | 1518 SeekAllSources(GetStartTime()); |
| 1532 StartReturningData(); | 1519 StartReturningData(); |
| 1533 | 1520 |
| 1534 if (duration_ == kNoTimestamp()) | 1521 if (duration_ == kNoTimestamp()) |
| 1535 duration_ = kInfiniteDuration(); | 1522 duration_ = kInfiniteDuration(); |
| 1536 | 1523 |
| 1537 // The demuxer is now initialized after the |start_timestamp_| was set. | 1524 // The demuxer is now initialized after the |start_timestamp_| was set. |
| 1538 ChangeState_Locked(INITIALIZED); | 1525 ChangeState_Locked(INITIALIZED); |
| 1539 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); | 1526 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1668 } | 1655 } |
| 1669 | 1656 |
| 1670 void ChunkDemuxer::ShutdownAllStreams() { | 1657 void ChunkDemuxer::ShutdownAllStreams() { |
| 1671 for (SourceStateMap::iterator itr = source_state_map_.begin(); | 1658 for (SourceStateMap::iterator itr = source_state_map_.begin(); |
| 1672 itr != source_state_map_.end(); ++itr) { | 1659 itr != source_state_map_.end(); ++itr) { |
| 1673 itr->second->Shutdown(); | 1660 itr->second->Shutdown(); |
| 1674 } | 1661 } |
| 1675 } | 1662 } |
| 1676 | 1663 |
| 1677 } // namespace media | 1664 } // namespace media |
| OLD | NEW |