Chromium Code Reviews| 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 <deque> | 8 #include <deque> |
| 9 #include <limits> | 9 #include <limits> |
| 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 "media/base/audio_decoder_config.h" | 16 #include "media/base/audio_decoder_config.h" |
| 16 #include "media/base/bind_to_loop.h" | 17 #include "media/base/bind_to_loop.h" |
| 17 #include "media/base/stream_parser_buffer.h" | 18 #include "media/base/stream_parser_buffer.h" |
| 18 #include "media/base/video_decoder_config.h" | 19 #include "media/base/video_decoder_config.h" |
| 19 #include "media/filters/stream_parser_factory.h" | 20 #include "media/filters/stream_parser_factory.h" |
| 20 #include "media/webm/webm_webvtt_parser.h" | |
| 21 | 21 |
| 22 using base::TimeDelta; | 22 using base::TimeDelta; |
| 23 | 23 |
| 24 namespace media { | 24 namespace media { |
| 25 | 25 |
| 26 // Contains state belonging to a source id. | 26 // Contains state belonging to a source id. |
| 27 class SourceState { | 27 class SourceState { |
| 28 public: | 28 public: |
| 29 // Callback signature used to create ChunkDemuxerStreams. | 29 // Callback signature used to create ChunkDemuxerStreams. |
| 30 typedef base::Callback<ChunkDemuxerStream*( | 30 typedef base::Callback<ChunkDemuxerStream*( |
| 31 DemuxerStream::Type)> CreateDemuxerStreamCB; | 31 DemuxerStream::Type)> CreateDemuxerStreamCB; |
| 32 | 32 |
| 33 // Callback signature used to notify ChunkDemuxer of timestamps | 33 // Callback signature used to notify ChunkDemuxer of timestamps |
| 34 // that may cause the duration to be updated. | 34 // that may cause the duration to be updated. |
| 35 typedef base::Callback<void( | 35 typedef base::Callback<void( |
| 36 TimeDelta, ChunkDemuxerStream*)> IncreaseDurationCB; | 36 TimeDelta, ChunkDemuxerStream*)> IncreaseDurationCB; |
| 37 | 37 |
| 38 typedef base::Callback<void( | |
| 39 ChunkDemuxerStream*, const TextTrackConfig&)> NewTextTrackCB; | |
| 40 | |
| 38 SourceState(scoped_ptr<StreamParser> stream_parser, const LogCB& log_cb, | 41 SourceState(scoped_ptr<StreamParser> stream_parser, const LogCB& log_cb, |
| 39 const CreateDemuxerStreamCB& create_demuxer_stream_cb, | 42 const CreateDemuxerStreamCB& create_demuxer_stream_cb, |
| 40 const IncreaseDurationCB& increase_duration_cb); | 43 const IncreaseDurationCB& increase_duration_cb); |
| 41 | 44 |
| 45 ~SourceState(); | |
| 46 | |
| 42 void Init(const StreamParser::InitCB& init_cb, | 47 void Init(const StreamParser::InitCB& init_cb, |
| 43 bool allow_audio, | 48 bool allow_audio, |
| 44 bool allow_video, | 49 bool allow_video, |
| 45 const StreamParser::NewTextBuffersCB& text_cb, | |
| 46 const StreamParser::NeedKeyCB& need_key_cb, | 50 const StreamParser::NeedKeyCB& need_key_cb, |
| 47 const AddTextTrackCB& add_text_track_cb); | 51 const NewTextTrackCB& new_text_track_cb); |
| 48 | 52 |
| 49 // Appends new data to the StreamParser. | 53 // Appends new data to the StreamParser. |
| 50 // Returns true if the data was successfully appended. Returns false if an | 54 // Returns true if the data was successfully appended. Returns false if an |
| 51 // error occurred. | 55 // error occurred. |
| 52 bool Append(const uint8* data, size_t length); | 56 bool Append(const uint8* data, size_t length); |
| 53 | 57 |
| 54 // Aborts the current append sequence and resets the parser. | 58 // Aborts the current append sequence and resets the parser. |
| 55 void Abort(); | 59 void Abort(); |
| 56 | 60 |
| 57 // Sets |timestamp_offset_| if possible. | 61 // Sets |timestamp_offset_| if possible. |
| 58 // Returns if the offset was set. Returns false if the offset could not be | 62 // Returns if the offset was set. Returns false if the offset could not be |
| 59 // updated at this time. | 63 // updated at this time. |
| 60 bool SetTimestampOffset(TimeDelta timestamp_offset); | 64 bool SetTimestampOffset(TimeDelta timestamp_offset); |
| 61 | 65 |
| 62 TimeDelta timestamp_offset() const { return timestamp_offset_; } | 66 TimeDelta timestamp_offset() const { return timestamp_offset_; } |
| 63 | 67 |
| 64 void set_append_window_start(TimeDelta start) { | 68 void set_append_window_start(TimeDelta start) { |
| 65 append_window_start_ = start; | 69 append_window_start_ = start; |
| 66 } | 70 } |
| 67 void set_append_window_end(TimeDelta end) { append_window_end_ = end; } | 71 void set_append_window_end(TimeDelta end) { append_window_end_ = end; } |
| 68 | 72 |
| 73 void TextStartReturningData(); | |
| 74 void TextAbortReads(); | |
| 75 void TextSeek(TimeDelta seek_time); | |
| 76 void TextCompletePendingReadIfPossible(); | |
| 77 | |
| 69 private: | 78 private: |
| 70 // Called by the |stream_parser_| when a new initialization segment is | 79 // Called by the |stream_parser_| when a new initialization segment is |
| 71 // encountered. | 80 // encountered. |
| 72 // Returns true on a successful call. Returns false if an error occured while | 81 // Returns true on a successful call. Returns false if an error occured while |
| 73 // processing decoder configurations. | 82 // processing decoder configurations. |
| 74 bool OnNewConfigs(bool allow_audio, bool allow_video, | 83 bool OnNewConfigs(bool allow_audio, bool allow_video, |
| 75 const AudioDecoderConfig& audio_config, | 84 const AudioDecoderConfig& audio_config, |
| 76 const VideoDecoderConfig& video_config); | 85 const VideoDecoderConfig& video_config, |
| 86 const StreamParser::TextTrackConfigMap& text_configs); | |
| 77 | 87 |
| 78 // Called by the |stream_parser_| at the beginning of a new media segment. | 88 // Called by the |stream_parser_| at the beginning of a new media segment. |
| 79 void OnNewMediaSegment(); | 89 void OnNewMediaSegment(); |
| 80 | 90 |
| 81 // Called by the |stream_parser_| at the end of a media segment. | 91 // Called by the |stream_parser_| at the end of a media segment. |
| 82 void OnEndOfMediaSegment(); | 92 void OnEndOfMediaSegment(); |
| 83 | 93 |
| 84 // Called by the |stream_parser_| when new buffers have been parsed. It | 94 // Called by the |stream_parser_| when new buffers have been parsed. It |
| 85 // applies |timestamp_offset_| to all buffers in |audio_buffers| and | 95 // applies |timestamp_offset_| to all buffers in |audio_buffers| and |
| 86 // |video_buffers| and then calls Append() on |audio_| and/or | 96 // |video_buffers| and then calls Append() on |audio_| and/or |
| 87 // |video_| with the modified buffers. | 97 // |video_| with the modified buffers. |
| 88 // Returns true on a successful call. Returns false if an error occured while | 98 // Returns true on a successful call. Returns false if an error occured while |
| 89 // processing the buffers. | 99 // processing the buffers. |
| 90 bool OnNewBuffers(const StreamParser::BufferQueue& audio_buffers, | 100 bool OnNewBuffers(const StreamParser::BufferQueue& audio_buffers, |
| 91 const StreamParser::BufferQueue& video_buffers); | 101 const StreamParser::BufferQueue& video_buffers); |
| 92 | 102 |
| 93 // Called by the |stream_parser_| when new text buffers have been parsed. It | 103 // Called by the |stream_parser_| when new text buffers have been parsed. It |
| 94 // applies |timestamp_offset_| to all buffers in |buffers| and then calls | 104 // applies |timestamp_offset_| to all buffers in |buffers| and then appends |
| 95 // |new_buffers_cb| with the modified buffers. | 105 // the (modified) buffers to the demuxer stream associated with |
| 106 // the track having |text_track_number|. | |
| 96 // Returns true on a successful call. Returns false if an error occured while | 107 // Returns true on a successful call. Returns false if an error occured while |
| 97 // processing the buffers. | 108 // processing the buffers. |
| 98 bool OnTextBuffers(const StreamParser::NewTextBuffersCB& new_buffers_cb, | 109 bool OnTextBuffers(int text_track_number, |
| 99 TextTrack* text_track, | |
| 100 const StreamParser::BufferQueue& buffers); | 110 const StreamParser::BufferQueue& buffers); |
| 101 | 111 |
| 102 // Helper function that adds |timestamp_offset_| to each buffer in |buffers|. | 112 // Helper function that adds |timestamp_offset_| to each buffer in |buffers|. |
| 103 void AdjustBufferTimestamps(const StreamParser::BufferQueue& buffers); | 113 void AdjustBufferTimestamps(const StreamParser::BufferQueue& buffers); |
| 104 | 114 |
| 105 // Filters out buffers that are outside of the append window | 115 // Filters out buffers that are outside of the append window |
| 106 // [|append_window_start_|, |append_window_end_|). | 116 // [|append_window_start_|, |append_window_end_|). |
| 107 // |needs_keyframe| is a pointer to the |xxx_need_keyframe_| flag | 117 // |needs_keyframe| is a pointer to the |xxx_need_keyframe_| flag |
| 108 // associated with the |buffers|. Its state is read an updated as | 118 // associated with the |buffers|. Its state is read an updated as |
| 109 // this method filters |buffers|. | 119 // this method filters |buffers|. |
| 110 // Buffers that are inside the append window are appended to the end | 120 // Buffers that are inside the append window are appended to the end |
| 111 // of |filtered_buffers|. | 121 // of |filtered_buffers|. |
| 112 void FilterWithAppendWindow(const StreamParser::BufferQueue& buffers, | 122 void FilterWithAppendWindow(const StreamParser::BufferQueue& buffers, |
| 113 bool* needs_keyframe, | 123 bool* needs_keyframe, |
| 114 StreamParser::BufferQueue* filtered_buffers); | 124 StreamParser::BufferQueue* filtered_buffers); |
| 115 | 125 |
| 116 CreateDemuxerStreamCB create_demuxer_stream_cb_; | 126 CreateDemuxerStreamCB create_demuxer_stream_cb_; |
| 117 IncreaseDurationCB increase_duration_cb_; | 127 IncreaseDurationCB increase_duration_cb_; |
| 128 NewTextTrackCB new_text_track_cb_; | |
| 118 | 129 |
| 119 // The offset to apply to media segment timestamps. | 130 // The offset to apply to media segment timestamps. |
| 120 TimeDelta timestamp_offset_; | 131 TimeDelta timestamp_offset_; |
| 121 | 132 |
| 122 TimeDelta append_window_start_; | 133 TimeDelta append_window_start_; |
| 123 TimeDelta append_window_end_; | 134 TimeDelta append_window_end_; |
| 124 | 135 |
| 125 // Set to true if the next buffers appended within the append window | 136 // Set to true if the next buffers appended within the append window |
| 126 // represent the start of a new media segment. This flag being set | 137 // represent the start of a new media segment. This flag being set |
| 127 // triggers a call to |new_segment_cb_| when the new buffers are | 138 // triggers a call to |new_segment_cb_| when the new buffers are |
| 128 // appended. The flag is set on actual media segment boundaries and | 139 // appended. The flag is set on actual media segment boundaries and |
| 129 // when the "append window" filtering causes discontinuities in the | 140 // when the "append window" filtering causes discontinuities in the |
| 130 // appended data. | 141 // appended data. |
| 131 bool new_media_segment_; | 142 bool new_media_segment_; |
| 132 | 143 |
| 133 // Keeps track of whether |timestamp_offset_| can be modified. | 144 // Keeps track of whether |timestamp_offset_| can be modified. |
| 134 bool can_update_offset_; | 145 bool can_update_offset_; |
| 135 | 146 |
| 136 // The object used to parse appended data. | 147 // The object used to parse appended data. |
| 137 scoped_ptr<StreamParser> stream_parser_; | 148 scoped_ptr<StreamParser> stream_parser_; |
| 138 | 149 |
| 139 ChunkDemuxerStream* audio_; | 150 ChunkDemuxerStream* audio_; |
| 140 bool audio_needs_keyframe_; | 151 bool audio_needs_keyframe_; |
| 141 | 152 |
| 142 ChunkDemuxerStream* video_; | 153 ChunkDemuxerStream* video_; |
| 143 bool video_needs_keyframe_; | 154 bool video_needs_keyframe_; |
| 144 | 155 |
| 156 typedef std::map<int, ChunkDemuxerStream*> TextStreamMap; | |
| 157 TextStreamMap text_stream_map_; | |
| 158 | |
| 145 LogCB log_cb_; | 159 LogCB log_cb_; |
| 146 | 160 |
| 147 DISALLOW_COPY_AND_ASSIGN(SourceState); | 161 DISALLOW_COPY_AND_ASSIGN(SourceState); |
| 148 }; | 162 }; |
| 149 | 163 |
| 150 class ChunkDemuxerStream : public DemuxerStream { | 164 class ChunkDemuxerStream : public DemuxerStream { |
| 151 public: | 165 public: |
| 152 typedef std::deque<scoped_refptr<StreamParserBuffer> > BufferQueue; | 166 typedef std::deque<scoped_refptr<StreamParserBuffer> > BufferQueue; |
| 153 | 167 |
| 154 explicit ChunkDemuxerStream(Type type); | 168 explicit ChunkDemuxerStream(Type type); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 | 200 |
| 187 // Signal to the stream that buffers handed in through subsequent calls to | 201 // Signal to the stream that buffers handed in through subsequent calls to |
| 188 // Append() belong to a media segment that starts at |start_timestamp|. | 202 // Append() belong to a media segment that starts at |start_timestamp|. |
| 189 void OnNewMediaSegment(TimeDelta start_timestamp); | 203 void OnNewMediaSegment(TimeDelta start_timestamp); |
| 190 | 204 |
| 191 // Called when midstream config updates occur. | 205 // Called when midstream config updates occur. |
| 192 // Returns true if the new config is accepted. | 206 // Returns true if the new config is accepted. |
| 193 // Returns false if the new config should trigger an error. | 207 // Returns false if the new config should trigger an error. |
| 194 bool UpdateAudioConfig(const AudioDecoderConfig& config, const LogCB& log_cb); | 208 bool UpdateAudioConfig(const AudioDecoderConfig& config, const LogCB& log_cb); |
| 195 bool UpdateVideoConfig(const VideoDecoderConfig& config, const LogCB& log_cb); | 209 bool UpdateVideoConfig(const VideoDecoderConfig& config, const LogCB& log_cb); |
| 210 void UpdateTextConfig(const TextTrackConfig& config, const LogCB& log_cb); | |
| 196 | 211 |
| 197 void MarkEndOfStream(); | 212 void MarkEndOfStream(); |
| 198 void UnmarkEndOfStream(); | 213 void UnmarkEndOfStream(); |
| 199 | 214 |
| 200 // DemuxerStream methods. | 215 // DemuxerStream methods. |
| 201 virtual void Read(const ReadCB& read_cb) OVERRIDE; | 216 virtual void Read(const ReadCB& read_cb) OVERRIDE; |
| 202 virtual Type type() OVERRIDE; | 217 virtual Type type() OVERRIDE; |
| 203 virtual void EnableBitstreamConverter() OVERRIDE; | 218 virtual void EnableBitstreamConverter() OVERRIDE; |
| 204 virtual AudioDecoderConfig audio_decoder_config() OVERRIDE; | 219 virtual AudioDecoderConfig audio_decoder_config() OVERRIDE; |
| 205 virtual VideoDecoderConfig video_decoder_config() OVERRIDE; | 220 virtual VideoDecoderConfig video_decoder_config() OVERRIDE; |
| 206 | 221 |
| 222 // Returns the text track configuration. It is an error to call this method | |
| 223 // if type() != TEXT. | |
| 224 TextTrackConfig text_track_config(); | |
| 225 | |
| 207 void set_memory_limit_for_testing(int memory_limit) { | 226 void set_memory_limit_for_testing(int memory_limit) { |
| 208 stream_->set_memory_limit_for_testing(memory_limit); | 227 stream_->set_memory_limit_for_testing(memory_limit); |
| 209 } | 228 } |
| 210 | 229 |
| 211 private: | 230 private: |
| 212 enum State { | 231 enum State { |
| 213 UNINITIALIZED, | 232 UNINITIALIZED, |
| 214 RETURNING_DATA_FOR_READS, | 233 RETURNING_DATA_FOR_READS, |
| 215 RETURNING_ABORT_FOR_READS, | 234 RETURNING_ABORT_FOR_READS, |
| 216 SHUTDOWN, | 235 SHUTDOWN, |
| 217 }; | 236 }; |
| 218 | 237 |
| 219 // Assigns |state_| to |state| | 238 // Assigns |state_| to |state| |
| 220 void ChangeState_Locked(State state); | 239 void ChangeState_Locked(State state); |
| 221 | 240 |
| 222 void CompletePendingReadIfPossible_Locked(); | 241 void CompletePendingReadIfPossible_Locked(); |
| 223 | 242 |
| 224 // Gets the value to pass to the next Read() callback. Returns true if | 243 // Gets the value to pass to the next Read() callback. Returns true if |
| 225 // |status| and |buffer| should be passed to the callback. False indicates | 244 // |status| and |buffer| should be passed to the callback. False indicates |
| 226 // that |status| and |buffer| were not set and more data is needed. | 245 // that |status| and |buffer| were not set and more data is needed. |
| 227 bool GetNextBuffer_Locked(DemuxerStream::Status* status, | 246 bool GetNextBuffer_Locked(DemuxerStream::Status* status, |
| 228 scoped_refptr<StreamParserBuffer>* buffer); | 247 scoped_refptr<StreamParserBuffer>* buffer); |
| 229 | 248 |
| 230 // Specifies the type of the stream (must be AUDIO or VIDEO for now). | 249 // Specifies the type of the stream. |
| 231 Type type_; | 250 Type type_; |
| 232 | 251 |
| 233 scoped_ptr<SourceBufferStream> stream_; | 252 scoped_ptr<SourceBufferStream> stream_; |
| 234 | 253 |
| 235 mutable base::Lock lock_; | 254 mutable base::Lock lock_; |
| 236 State state_; | 255 State state_; |
| 237 ReadCB read_cb_; | 256 ReadCB read_cb_; |
| 238 | 257 |
| 239 DISALLOW_IMPLICIT_CONSTRUCTORS(ChunkDemuxerStream); | 258 DISALLOW_IMPLICIT_CONSTRUCTORS(ChunkDemuxerStream); |
| 240 }; | 259 }; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 251 stream_parser_(stream_parser.release()), | 270 stream_parser_(stream_parser.release()), |
| 252 audio_(NULL), | 271 audio_(NULL), |
| 253 audio_needs_keyframe_(true), | 272 audio_needs_keyframe_(true), |
| 254 video_(NULL), | 273 video_(NULL), |
| 255 video_needs_keyframe_(true), | 274 video_needs_keyframe_(true), |
| 256 log_cb_(log_cb) { | 275 log_cb_(log_cb) { |
| 257 DCHECK(!create_demuxer_stream_cb_.is_null()); | 276 DCHECK(!create_demuxer_stream_cb_.is_null()); |
| 258 DCHECK(!increase_duration_cb_.is_null()); | 277 DCHECK(!increase_duration_cb_.is_null()); |
| 259 } | 278 } |
| 260 | 279 |
| 280 SourceState::~SourceState() { | |
| 281 for (TextStreamMap::iterator itr = text_stream_map_.begin(); | |
| 282 itr != text_stream_map_.end(); ++itr) { | |
| 283 itr->second->Shutdown(); | |
| 284 delete itr->second; | |
| 285 } | |
| 286 } | |
| 287 | |
| 261 void SourceState::Init(const StreamParser::InitCB& init_cb, | 288 void SourceState::Init(const StreamParser::InitCB& init_cb, |
| 262 bool allow_audio, | 289 bool allow_audio, |
| 263 bool allow_video, | 290 bool allow_video, |
| 264 const StreamParser::NewTextBuffersCB& text_cb, | |
| 265 const StreamParser::NeedKeyCB& need_key_cb, | 291 const StreamParser::NeedKeyCB& need_key_cb, |
| 266 const AddTextTrackCB& add_text_track_cb) { | 292 const NewTextTrackCB& new_text_track_cb) { |
| 267 StreamParser::NewBuffersCB audio_cb; | 293 new_text_track_cb_ = new_text_track_cb; |
| 294 | |
| 295 StreamParser::NewTextBuffersCB new_text_buffers_cb; | |
| 296 | |
| 297 if (!new_text_track_cb_.is_null()) { | |
| 298 new_text_buffers_cb = base::Bind(&SourceState::OnTextBuffers, | |
| 299 base::Unretained(this)); | |
| 300 } | |
| 268 | 301 |
| 269 stream_parser_->Init(init_cb, | 302 stream_parser_->Init(init_cb, |
| 270 base::Bind(&SourceState::OnNewConfigs, | 303 base::Bind(&SourceState::OnNewConfigs, |
| 271 base::Unretained(this), | 304 base::Unretained(this), |
| 272 allow_audio, | 305 allow_audio, |
| 273 allow_video), | 306 allow_video), |
| 274 base::Bind(&SourceState::OnNewBuffers, | 307 base::Bind(&SourceState::OnNewBuffers, |
| 275 base::Unretained(this)), | 308 base::Unretained(this)), |
| 276 base::Bind(&SourceState::OnTextBuffers, | 309 new_text_buffers_cb, |
| 277 base::Unretained(this), text_cb), | |
| 278 need_key_cb, | 310 need_key_cb, |
| 279 add_text_track_cb, | |
| 280 base::Bind(&SourceState::OnNewMediaSegment, | 311 base::Bind(&SourceState::OnNewMediaSegment, |
| 281 base::Unretained(this)), | 312 base::Unretained(this)), |
| 282 base::Bind(&SourceState::OnEndOfMediaSegment, | 313 base::Bind(&SourceState::OnEndOfMediaSegment, |
| 283 base::Unretained(this)), | 314 base::Unretained(this)), |
| 284 log_cb_); | 315 log_cb_); |
| 285 } | 316 } |
| 286 | 317 |
| 287 bool SourceState::SetTimestampOffset(TimeDelta timestamp_offset) { | 318 bool SourceState::SetTimestampOffset(TimeDelta timestamp_offset) { |
| 288 if (!can_update_offset_) | 319 if (!can_update_offset_) |
| 289 return false; | 320 return false; |
| 290 | 321 |
| 291 timestamp_offset_ = timestamp_offset; | 322 timestamp_offset_ = timestamp_offset; |
| 292 return true; | 323 return true; |
| 293 } | 324 } |
| 294 | 325 |
| 295 bool SourceState::Append(const uint8* data, size_t length) { | 326 bool SourceState::Append(const uint8* data, size_t length) { |
| 296 return stream_parser_->Parse(data, length); | 327 return stream_parser_->Parse(data, length); |
| 297 } | 328 } |
| 298 | 329 |
| 299 void SourceState::Abort() { | 330 void SourceState::Abort() { |
| 300 stream_parser_->Flush(); | 331 stream_parser_->Flush(); |
| 301 audio_needs_keyframe_ = true; | 332 audio_needs_keyframe_ = true; |
| 302 video_needs_keyframe_ = true; | 333 video_needs_keyframe_ = true; |
| 303 can_update_offset_ = true; | 334 can_update_offset_ = true; |
| 304 } | 335 } |
| 305 | 336 |
| 337 | |
| 338 void SourceState::TextStartReturningData() { | |
| 339 for (TextStreamMap::iterator itr = text_stream_map_.begin(); | |
| 340 itr != text_stream_map_.end(); ++itr) { | |
| 341 itr->second->StartReturningData(); | |
| 342 } | |
| 343 } | |
| 344 | |
| 345 void SourceState::TextAbortReads() { | |
| 346 for (TextStreamMap::iterator itr = text_stream_map_.begin(); | |
| 347 itr != text_stream_map_.end(); ++itr) { | |
| 348 itr->second->AbortReads(); | |
| 349 } | |
| 350 } | |
| 351 | |
| 352 void SourceState::TextSeek(TimeDelta seek_time) { | |
| 353 for (TextStreamMap::iterator itr = text_stream_map_.begin(); | |
| 354 itr != text_stream_map_.end(); ++itr) { | |
| 355 itr->second->Seek(seek_time); | |
| 356 } | |
| 357 } | |
| 358 | |
| 359 void SourceState::TextCompletePendingReadIfPossible() { | |
| 360 for (TextStreamMap::iterator itr = text_stream_map_.begin(); | |
| 361 itr != text_stream_map_.end(); ++itr) { | |
| 362 itr->second->CompletePendingReadIfPossible(); | |
| 363 } | |
| 364 } | |
| 365 | |
| 306 void SourceState::AdjustBufferTimestamps( | 366 void SourceState::AdjustBufferTimestamps( |
| 307 const StreamParser::BufferQueue& buffers) { | 367 const StreamParser::BufferQueue& buffers) { |
| 308 if (timestamp_offset_ == TimeDelta()) | 368 if (timestamp_offset_ == TimeDelta()) |
| 309 return; | 369 return; |
| 310 | 370 |
| 311 for (StreamParser::BufferQueue::const_iterator itr = buffers.begin(); | 371 for (StreamParser::BufferQueue::const_iterator itr = buffers.begin(); |
| 312 itr != buffers.end(); ++itr) { | 372 itr != buffers.end(); ++itr) { |
| 313 (*itr)->SetDecodeTimestamp( | 373 (*itr)->SetDecodeTimestamp( |
| 314 (*itr)->GetDecodeTimestamp() + timestamp_offset_); | 374 (*itr)->GetDecodeTimestamp() + timestamp_offset_); |
| 315 (*itr)->set_timestamp((*itr)->timestamp() + timestamp_offset_); | 375 (*itr)->set_timestamp((*itr)->timestamp() + timestamp_offset_); |
| 316 } | 376 } |
| 317 } | 377 } |
| 318 | 378 |
| 319 bool SourceState::OnNewConfigs(bool allow_audio, bool allow_video, | 379 bool SourceState::OnNewConfigs( |
| 320 const AudioDecoderConfig& audio_config, | 380 bool allow_audio, bool allow_video, |
| 321 const VideoDecoderConfig& video_config) { | 381 const AudioDecoderConfig& audio_config, |
| 382 const VideoDecoderConfig& video_config, | |
| 383 const StreamParser::TextTrackConfigMap& text_configs) { | |
| 322 DVLOG(1) << "OnNewConfigs(" << allow_audio << ", " << allow_video | 384 DVLOG(1) << "OnNewConfigs(" << allow_audio << ", " << allow_video |
| 323 << ", " << audio_config.IsValidConfig() | 385 << ", " << audio_config.IsValidConfig() |
| 324 << ", " << video_config.IsValidConfig() << ")"; | 386 << ", " << video_config.IsValidConfig() << ")"; |
| 325 | 387 |
| 326 if (!audio_config.IsValidConfig() && !video_config.IsValidConfig()) { | 388 if (!audio_config.IsValidConfig() && !video_config.IsValidConfig()) { |
| 327 DVLOG(1) << "OnNewConfigs() : Audio & video config are not valid!"; | 389 DVLOG(1) << "OnNewConfigs() : Audio & video config are not valid!"; |
| 328 return false; | 390 return false; |
| 329 } | 391 } |
| 330 | 392 |
| 331 // Signal an error if we get configuration info for stream types that weren't | 393 // Signal an error if we get configuration info for stream types that weren't |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 370 | 432 |
| 371 if (!video_) { | 433 if (!video_) { |
| 372 DVLOG(1) << "Failed to create a video stream."; | 434 DVLOG(1) << "Failed to create a video stream."; |
| 373 return false; | 435 return false; |
| 374 } | 436 } |
| 375 } | 437 } |
| 376 | 438 |
| 377 success &= video_->UpdateVideoConfig(video_config, log_cb_); | 439 success &= video_->UpdateVideoConfig(video_config, log_cb_); |
| 378 } | 440 } |
| 379 | 441 |
| 442 typedef StreamParser::TextTrackConfigMap::const_iterator TextConfigItr; | |
| 443 if (text_stream_map_.empty()) { | |
| 444 for (TextConfigItr itr = text_configs.begin(); | |
| 445 itr != text_configs.end(); ++itr) { | |
| 446 ChunkDemuxerStream* const text_stream = | |
| 447 create_demuxer_stream_cb_.Run(DemuxerStream::TEXT); | |
| 448 text_stream->UpdateTextConfig(itr->second, log_cb_); | |
| 449 text_stream_map_[itr->first] = text_stream; | |
| 450 new_text_track_cb_.Run(text_stream, itr->second); | |
| 451 } | |
| 452 } else { | |
| 453 const size_t text_count = text_stream_map_.size(); | |
| 454 if (text_configs.size() != text_count) { | |
| 455 success &= false; | |
|
acolwell GONE FROM CHROMIUM
2013/11/20 01:15:24
nit: Add MEDIA_LOG(log_cb_) << "The number of text
Matthew Heaney (Chromium)
2013/11/20 19:23:16
Done.
| |
| 456 } else if (text_count == 1) { | |
| 457 TextConfigItr config_itr = text_configs.begin(); | |
| 458 const TextTrackConfig& new_config = config_itr->second; | |
| 459 TextStreamMap::iterator stream_itr = text_stream_map_.begin(); | |
| 460 ChunkDemuxerStream* text_stream = stream_itr->second; | |
| 461 TextTrackConfig old_config = text_stream->text_track_config(); | |
| 462 if (!new_config.Matches(old_config)) { | |
| 463 success &= false; | |
|
acolwell GONE FROM CHROMIUM
2013/11/20 01:15:24
nit: Add MEDIA_LOG(log_cb_) << "New text track con
Matthew Heaney (Chromium)
2013/11/20 19:23:16
Done.
| |
| 464 } else { | |
| 465 text_stream_map_.clear(); | |
| 466 text_stream_map_[config_itr->first] = text_stream; | |
| 467 } | |
| 468 } else { | |
| 469 for (TextConfigItr config_itr = text_configs.begin(); | |
| 470 config_itr != text_configs.end(); ++config_itr) { | |
| 471 TextStreamMap::iterator stream_itr = | |
| 472 text_stream_map_.find(config_itr->first); | |
| 473 if (stream_itr == text_stream_map_.end()) { | |
| 474 success &= false; | |
|
acolwell GONE FROM CHROMIUM
2013/11/20 01:15:24
nit: Add MEDIA_LOG(log_cb_) << "Unexpected text tr
Matthew Heaney (Chromium)
2013/11/20 19:23:16
Done.
| |
| 475 break; | |
| 476 } | |
| 477 | |
| 478 const TextTrackConfig& new_config = config_itr->second; | |
| 479 ChunkDemuxerStream* stream = stream_itr->second; | |
| 480 TextTrackConfig old_config = stream->text_track_config(); | |
| 481 if (!new_config.Matches(old_config)) { | |
| 482 success &= false; | |
|
acolwell GONE FROM CHROMIUM
2013/11/20 01:15:24
nit: Add MEDIA_LOG(log_cb_) << "New text track con
Matthew Heaney (Chromium)
2013/11/20 19:23:16
Done.
| |
| 483 break; | |
| 484 } | |
| 485 } | |
| 486 } | |
| 487 } | |
| 488 | |
| 380 DVLOG(1) << "OnNewConfigs() : " << (success ? "success" : "failed"); | 489 DVLOG(1) << "OnNewConfigs() : " << (success ? "success" : "failed"); |
| 381 return success; | 490 return success; |
| 382 } | 491 } |
| 383 | 492 |
| 384 void SourceState::OnNewMediaSegment() { | 493 void SourceState::OnNewMediaSegment() { |
| 385 DVLOG(2) << "OnNewMediaSegment()"; | 494 DVLOG(2) << "OnNewMediaSegment()"; |
| 386 can_update_offset_ = false; | 495 can_update_offset_ = false; |
| 387 new_media_segment_ = true; | 496 new_media_segment_ = true; |
| 388 } | 497 } |
| 389 | 498 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 segment_timestamp = filtered_video.front()->GetDecodeTimestamp(); | 534 segment_timestamp = filtered_video.front()->GetDecodeTimestamp(); |
| 426 } | 535 } |
| 427 | 536 |
| 428 new_media_segment_ = false; | 537 new_media_segment_ = false; |
| 429 | 538 |
| 430 if (audio_) | 539 if (audio_) |
| 431 audio_->OnNewMediaSegment(segment_timestamp); | 540 audio_->OnNewMediaSegment(segment_timestamp); |
| 432 | 541 |
| 433 if (video_) | 542 if (video_) |
| 434 video_->OnNewMediaSegment(segment_timestamp); | 543 video_->OnNewMediaSegment(segment_timestamp); |
| 544 | |
| 545 for (TextStreamMap::iterator itr = text_stream_map_.begin(); | |
| 546 itr != text_stream_map_.end(); ++itr) { | |
| 547 itr->second->OnNewMediaSegment(segment_timestamp); | |
| 548 } | |
| 435 } | 549 } |
| 436 | 550 |
| 437 if (!filtered_audio.empty()) { | 551 if (!filtered_audio.empty()) { |
| 438 if (!audio_ || !audio_->Append(filtered_audio)) | 552 if (!audio_ || !audio_->Append(filtered_audio)) |
| 439 return false; | 553 return false; |
| 440 increase_duration_cb_.Run(filtered_audio.back()->timestamp(), audio_); | 554 increase_duration_cb_.Run(filtered_audio.back()->timestamp(), audio_); |
| 441 } | 555 } |
| 442 | 556 |
| 443 if (!filtered_video.empty()) { | 557 if (!filtered_video.empty()) { |
| 444 if (!video_ || !video_->Append(filtered_video)) | 558 if (!video_ || !video_->Append(filtered_video)) |
| 445 return false; | 559 return false; |
| 446 increase_duration_cb_.Run(filtered_video.back()->timestamp(), video_); | 560 increase_duration_cb_.Run(filtered_video.back()->timestamp(), video_); |
| 447 } | 561 } |
| 448 | 562 |
| 449 return true; | 563 return true; |
| 450 } | 564 } |
| 451 | 565 |
| 452 bool SourceState::OnTextBuffers( | 566 bool SourceState::OnTextBuffers( |
| 453 const StreamParser::NewTextBuffersCB& new_buffers_cb, | 567 int text_track_number, |
| 454 TextTrack* text_track, | |
| 455 const StreamParser::BufferQueue& buffers) { | 568 const StreamParser::BufferQueue& buffers) { |
| 456 if (new_buffers_cb.is_null()) | 569 DCHECK(!buffers.empty()); |
| 570 | |
| 571 TextStreamMap::iterator itr = text_stream_map_.find(text_track_number); | |
| 572 if (itr == text_stream_map_.end()) | |
| 457 return false; | 573 return false; |
| 458 | 574 |
| 459 AdjustBufferTimestamps(buffers); | 575 AdjustBufferTimestamps(buffers); |
| 460 | 576 |
| 461 return new_buffers_cb.Run(text_track, buffers); | 577 return itr->second->Append(buffers); |
| 462 } | 578 } |
| 463 | 579 |
| 464 void SourceState::FilterWithAppendWindow( | 580 void SourceState::FilterWithAppendWindow( |
| 465 const StreamParser::BufferQueue& buffers, bool* needs_keyframe, | 581 const StreamParser::BufferQueue& buffers, bool* needs_keyframe, |
| 466 StreamParser::BufferQueue* filtered_buffers) { | 582 StreamParser::BufferQueue* filtered_buffers) { |
| 467 DCHECK(needs_keyframe); | 583 DCHECK(needs_keyframe); |
| 468 DCHECK(filtered_buffers); | 584 DCHECK(filtered_buffers); |
| 469 | 585 |
| 470 // This loop implements steps 1.9, 1.10, & 1.11 of the "Coded frame | 586 // This loop implements steps 1.9, 1.10, & 1.11 of the "Coded frame |
| 471 // processing loop" in the Media Source Extensions spec. | 587 // processing loop" in the Media Source Extensions spec. |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 642 | 758 |
| 643 if (!stream_) { | 759 if (!stream_) { |
| 644 DCHECK_EQ(state_, UNINITIALIZED); | 760 DCHECK_EQ(state_, UNINITIALIZED); |
| 645 stream_.reset(new SourceBufferStream(config, log_cb)); | 761 stream_.reset(new SourceBufferStream(config, log_cb)); |
| 646 return true; | 762 return true; |
| 647 } | 763 } |
| 648 | 764 |
| 649 return stream_->UpdateVideoConfig(config); | 765 return stream_->UpdateVideoConfig(config); |
| 650 } | 766 } |
| 651 | 767 |
| 768 void ChunkDemuxerStream::UpdateTextConfig(const TextTrackConfig& config, | |
| 769 const LogCB& log_cb) { | |
| 770 DCHECK_EQ(type_, TEXT); | |
| 771 base::AutoLock auto_lock(lock_); | |
| 772 DCHECK(!stream_); | |
| 773 DCHECK_EQ(state_, UNINITIALIZED); | |
| 774 stream_.reset(new SourceBufferStream(config, log_cb)); | |
| 775 } | |
| 776 | |
| 652 void ChunkDemuxerStream::MarkEndOfStream() { | 777 void ChunkDemuxerStream::MarkEndOfStream() { |
| 653 base::AutoLock auto_lock(lock_); | 778 base::AutoLock auto_lock(lock_); |
| 654 stream_->MarkEndOfStream(); | 779 stream_->MarkEndOfStream(); |
| 655 } | 780 } |
| 656 | 781 |
| 657 void ChunkDemuxerStream::UnmarkEndOfStream() { | 782 void ChunkDemuxerStream::UnmarkEndOfStream() { |
| 658 base::AutoLock auto_lock(lock_); | 783 base::AutoLock auto_lock(lock_); |
| 659 stream_->UnmarkEndOfStream(); | 784 stream_->UnmarkEndOfStream(); |
| 660 } | 785 } |
| 661 | 786 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 678 base::AutoLock auto_lock(lock_); | 803 base::AutoLock auto_lock(lock_); |
| 679 return stream_->GetCurrentAudioDecoderConfig(); | 804 return stream_->GetCurrentAudioDecoderConfig(); |
| 680 } | 805 } |
| 681 | 806 |
| 682 VideoDecoderConfig ChunkDemuxerStream::video_decoder_config() { | 807 VideoDecoderConfig ChunkDemuxerStream::video_decoder_config() { |
| 683 CHECK_EQ(type_, VIDEO); | 808 CHECK_EQ(type_, VIDEO); |
| 684 base::AutoLock auto_lock(lock_); | 809 base::AutoLock auto_lock(lock_); |
| 685 return stream_->GetCurrentVideoDecoderConfig(); | 810 return stream_->GetCurrentVideoDecoderConfig(); |
| 686 } | 811 } |
| 687 | 812 |
| 813 TextTrackConfig ChunkDemuxerStream::text_track_config() { | |
| 814 CHECK_EQ(type_, TEXT); | |
| 815 base::AutoLock auto_lock(lock_); | |
| 816 return stream_->GetCurrentTextTrackConfig(); | |
| 817 } | |
| 818 | |
| 688 void ChunkDemuxerStream::ChangeState_Locked(State state) { | 819 void ChunkDemuxerStream::ChangeState_Locked(State state) { |
| 689 lock_.AssertAcquired(); | 820 lock_.AssertAcquired(); |
| 690 DVLOG(1) << "ChunkDemuxerStream::ChangeState_Locked() : " | 821 DVLOG(1) << "ChunkDemuxerStream::ChangeState_Locked() : " |
| 691 << "type " << type_ | 822 << "type " << type_ |
| 692 << " - " << state_ << " -> " << state; | 823 << " - " << state_ << " -> " << state; |
| 693 state_ = state; | 824 state_ = state; |
| 694 } | 825 } |
| 695 | 826 |
| 696 ChunkDemuxerStream::~ChunkDemuxerStream() {} | 827 ChunkDemuxerStream::~ChunkDemuxerStream() {} |
| 697 | 828 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 737 status = DemuxerStream::kOk; | 868 status = DemuxerStream::kOk; |
| 738 buffer = StreamParserBuffer::CreateEOSBuffer(); | 869 buffer = StreamParserBuffer::CreateEOSBuffer(); |
| 739 break; | 870 break; |
| 740 } | 871 } |
| 741 | 872 |
| 742 base::ResetAndReturn(&read_cb_).Run(status, buffer); | 873 base::ResetAndReturn(&read_cb_).Run(status, buffer); |
| 743 } | 874 } |
| 744 | 875 |
| 745 ChunkDemuxer::ChunkDemuxer(const base::Closure& open_cb, | 876 ChunkDemuxer::ChunkDemuxer(const base::Closure& open_cb, |
| 746 const NeedKeyCB& need_key_cb, | 877 const NeedKeyCB& need_key_cb, |
| 747 const AddTextTrackCB& add_text_track_cb, | |
| 748 const LogCB& log_cb) | 878 const LogCB& log_cb) |
| 749 : state_(WAITING_FOR_INIT), | 879 : state_(WAITING_FOR_INIT), |
| 750 cancel_next_seek_(false), | 880 cancel_next_seek_(false), |
| 751 host_(NULL), | 881 host_(NULL), |
| 752 open_cb_(open_cb), | 882 open_cb_(open_cb), |
| 753 need_key_cb_(need_key_cb), | 883 need_key_cb_(need_key_cb), |
| 754 add_text_track_cb_(add_text_track_cb), | 884 enable_text_(false), |
| 755 log_cb_(log_cb), | 885 log_cb_(log_cb), |
| 756 duration_(kNoTimestamp()), | 886 duration_(kNoTimestamp()), |
| 757 user_specified_duration_(-1) { | 887 user_specified_duration_(-1) { |
| 758 DCHECK(!open_cb_.is_null()); | 888 DCHECK(!open_cb_.is_null()); |
| 759 DCHECK(!need_key_cb_.is_null()); | 889 DCHECK(!need_key_cb_.is_null()); |
| 760 } | 890 } |
| 761 | 891 |
| 762 void ChunkDemuxer::Initialize(DemuxerHost* host, const PipelineStatusCB& cb) { | 892 void ChunkDemuxer::Initialize( |
| 893 DemuxerHost* host, | |
| 894 const PipelineStatusCB& cb, | |
| 895 bool enable_text_tracks) { | |
| 763 DVLOG(1) << "Init()"; | 896 DVLOG(1) << "Init()"; |
| 764 | 897 |
| 765 base::AutoLock auto_lock(lock_); | 898 base::AutoLock auto_lock(lock_); |
| 766 | 899 |
| 767 init_cb_ = BindToCurrentLoop(cb); | 900 init_cb_ = BindToCurrentLoop(cb); |
| 768 if (state_ == SHUTDOWN) { | 901 if (state_ == SHUTDOWN) { |
| 769 base::ResetAndReturn(&init_cb_).Run(DEMUXER_ERROR_COULD_NOT_OPEN); | 902 base::ResetAndReturn(&init_cb_).Run(DEMUXER_ERROR_COULD_NOT_OPEN); |
| 770 return; | 903 return; |
| 771 } | 904 } |
| 772 DCHECK_EQ(state_, WAITING_FOR_INIT); | 905 DCHECK_EQ(state_, WAITING_FOR_INIT); |
| 773 host_ = host; | 906 host_ = host; |
| 907 enable_text_ = enable_text_tracks; | |
| 774 | 908 |
| 775 ChangeState_Locked(INITIALIZING); | 909 ChangeState_Locked(INITIALIZING); |
| 776 | 910 |
| 777 base::ResetAndReturn(&open_cb_).Run(); | 911 base::ResetAndReturn(&open_cb_).Run(); |
| 778 } | 912 } |
| 779 | 913 |
| 780 void ChunkDemuxer::Stop(const base::Closure& callback) { | 914 void ChunkDemuxer::Stop(const base::Closure& callback) { |
| 781 DVLOG(1) << "Stop()"; | 915 DVLOG(1) << "Stop()"; |
| 782 Shutdown(); | 916 Shutdown(); |
| 783 callback.Run(); | 917 callback.Run(); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 814 } | 948 } |
| 815 | 949 |
| 816 void ChunkDemuxer::OnAudioRendererDisabled() { | 950 void ChunkDemuxer::OnAudioRendererDisabled() { |
| 817 base::AutoLock auto_lock(lock_); | 951 base::AutoLock auto_lock(lock_); |
| 818 audio_->Shutdown(); | 952 audio_->Shutdown(); |
| 819 disabled_audio_ = audio_.Pass(); | 953 disabled_audio_ = audio_.Pass(); |
| 820 } | 954 } |
| 821 | 955 |
| 822 // Demuxer implementation. | 956 // Demuxer implementation. |
| 823 DemuxerStream* ChunkDemuxer::GetStream(DemuxerStream::Type type) { | 957 DemuxerStream* ChunkDemuxer::GetStream(DemuxerStream::Type type) { |
| 958 DCHECK_NE(type, DemuxerStream::TEXT); | |
| 824 base::AutoLock auto_lock(lock_); | 959 base::AutoLock auto_lock(lock_); |
| 825 if (type == DemuxerStream::VIDEO) | 960 if (type == DemuxerStream::VIDEO) |
| 826 return video_.get(); | 961 return video_.get(); |
| 827 | 962 |
| 828 if (type == DemuxerStream::AUDIO) | 963 if (type == DemuxerStream::AUDIO) |
| 829 return audio_.get(); | 964 return audio_.get(); |
| 830 | 965 |
| 831 return NULL; | 966 return NULL; |
| 832 } | 967 } |
| 833 | 968 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 899 if (has_video) | 1034 if (has_video) |
| 900 source_id_video_ = id; | 1035 source_id_video_ = id; |
| 901 | 1036 |
| 902 scoped_ptr<SourceState> source_state( | 1037 scoped_ptr<SourceState> source_state( |
| 903 new SourceState(stream_parser.Pass(), log_cb_, | 1038 new SourceState(stream_parser.Pass(), log_cb_, |
| 904 base::Bind(&ChunkDemuxer::CreateDemuxerStream, | 1039 base::Bind(&ChunkDemuxer::CreateDemuxerStream, |
| 905 base::Unretained(this)), | 1040 base::Unretained(this)), |
| 906 base::Bind(&ChunkDemuxer::IncreaseDurationIfNecessary, | 1041 base::Bind(&ChunkDemuxer::IncreaseDurationIfNecessary, |
| 907 base::Unretained(this)))); | 1042 base::Unretained(this)))); |
| 908 | 1043 |
| 1044 SourceState::NewTextTrackCB new_text_track_cb; | |
| 1045 | |
| 1046 if (enable_text_) { | |
| 1047 new_text_track_cb = base::Bind(&ChunkDemuxer::OnNewTextTrack, | |
| 1048 base::Unretained(this)); | |
| 1049 } | |
| 1050 | |
| 909 source_state->Init( | 1051 source_state->Init( |
| 910 base::Bind(&ChunkDemuxer::OnSourceInitDone, base::Unretained(this)), | 1052 base::Bind(&ChunkDemuxer::OnSourceInitDone, base::Unretained(this)), |
| 911 has_audio, | 1053 has_audio, |
| 912 has_video, | 1054 has_video, |
| 913 base::Bind(&ChunkDemuxer::OnTextBuffers, base::Unretained(this)), | |
| 914 need_key_cb_, | 1055 need_key_cb_, |
| 915 add_text_track_cb_); | 1056 new_text_track_cb); |
| 916 | 1057 |
| 917 source_state_map_[id] = source_state.release(); | 1058 source_state_map_[id] = source_state.release(); |
| 918 return kOk; | 1059 return kOk; |
| 919 } | 1060 } |
| 920 | 1061 |
| 921 void ChunkDemuxer::RemoveId(const std::string& id) { | 1062 void ChunkDemuxer::RemoveId(const std::string& id) { |
| 922 base::AutoLock auto_lock(lock_); | 1063 base::AutoLock auto_lock(lock_); |
| 923 CHECK(IsValidId(id)); | 1064 CHECK(IsValidId(id)); |
| 924 | 1065 |
| 925 delete source_state_map_[id]; | 1066 delete source_state_map_[id]; |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1335 return NULL; | 1476 return NULL; |
| 1336 audio_.reset(new ChunkDemuxerStream(DemuxerStream::AUDIO)); | 1477 audio_.reset(new ChunkDemuxerStream(DemuxerStream::AUDIO)); |
| 1337 return audio_.get(); | 1478 return audio_.get(); |
| 1338 break; | 1479 break; |
| 1339 case DemuxerStream::VIDEO: | 1480 case DemuxerStream::VIDEO: |
| 1340 if (video_) | 1481 if (video_) |
| 1341 return NULL; | 1482 return NULL; |
| 1342 video_.reset(new ChunkDemuxerStream(DemuxerStream::VIDEO)); | 1483 video_.reset(new ChunkDemuxerStream(DemuxerStream::VIDEO)); |
| 1343 return video_.get(); | 1484 return video_.get(); |
| 1344 break; | 1485 break; |
| 1486 case DemuxerStream::TEXT: { | |
| 1487 return new ChunkDemuxerStream(DemuxerStream::TEXT); | |
| 1488 break; | |
| 1489 } | |
| 1345 case DemuxerStream::UNKNOWN: | 1490 case DemuxerStream::UNKNOWN: |
| 1346 case DemuxerStream::NUM_TYPES: | 1491 case DemuxerStream::NUM_TYPES: |
| 1347 NOTREACHED(); | 1492 NOTREACHED(); |
| 1348 return NULL; | 1493 return NULL; |
| 1349 } | 1494 } |
| 1350 NOTREACHED(); | 1495 NOTREACHED(); |
| 1351 return NULL; | 1496 return NULL; |
| 1352 } | 1497 } |
| 1353 | 1498 |
| 1354 bool ChunkDemuxer::OnTextBuffers( | 1499 void ChunkDemuxer::OnNewTextTrack(ChunkDemuxerStream* text_stream, |
| 1355 TextTrack* text_track, | 1500 const TextTrackConfig& config) { |
| 1356 const StreamParser::BufferQueue& buffers) { | |
| 1357 lock_.AssertAcquired(); | 1501 lock_.AssertAcquired(); |
| 1358 DCHECK_NE(state_, SHUTDOWN); | 1502 DCHECK_NE(state_, SHUTDOWN); |
| 1359 | 1503 host_->AddTextStream(text_stream, config); |
| 1360 // TODO(matthewjheaney): IncreaseDurationIfNecessary | |
| 1361 | |
| 1362 for (StreamParser::BufferQueue::const_iterator itr = buffers.begin(); | |
| 1363 itr != buffers.end(); ++itr) { | |
| 1364 const StreamParserBuffer* const buffer = itr->get(); | |
| 1365 const TimeDelta start = buffer->timestamp(); | |
| 1366 const TimeDelta end = start + buffer->duration(); | |
| 1367 | |
| 1368 std::string id, settings, content; | |
| 1369 | |
| 1370 WebMWebVTTParser::Parse(buffer->data(), | |
| 1371 buffer->data_size(), | |
| 1372 &id, &settings, &content); | |
| 1373 | |
| 1374 text_track->addWebVTTCue(start, end, id, content, settings); | |
| 1375 } | |
| 1376 | |
| 1377 return true; | |
| 1378 } | 1504 } |
| 1379 | 1505 |
| 1380 bool ChunkDemuxer::IsValidId(const std::string& source_id) const { | 1506 bool ChunkDemuxer::IsValidId(const std::string& source_id) const { |
| 1381 lock_.AssertAcquired(); | 1507 lock_.AssertAcquired(); |
| 1382 return source_state_map_.count(source_id) > 0u; | 1508 return source_state_map_.count(source_id) > 0u; |
| 1383 } | 1509 } |
| 1384 | 1510 |
| 1385 void ChunkDemuxer::UpdateDuration(TimeDelta new_duration) { | 1511 void ChunkDemuxer::UpdateDuration(TimeDelta new_duration) { |
| 1386 DCHECK(duration_ != new_duration); | 1512 DCHECK(duration_ != new_duration); |
| 1387 user_specified_duration_ = -1; | 1513 user_specified_duration_ = -1; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1428 return video_->GetBufferedRanges(duration_); | 1554 return video_->GetBufferedRanges(duration_); |
| 1429 return ComputeIntersection(); | 1555 return ComputeIntersection(); |
| 1430 } | 1556 } |
| 1431 | 1557 |
| 1432 void ChunkDemuxer::StartReturningData() { | 1558 void ChunkDemuxer::StartReturningData() { |
| 1433 if (audio_) | 1559 if (audio_) |
| 1434 audio_->StartReturningData(); | 1560 audio_->StartReturningData(); |
| 1435 | 1561 |
| 1436 if (video_) | 1562 if (video_) |
| 1437 video_->StartReturningData(); | 1563 video_->StartReturningData(); |
| 1564 | |
| 1565 for (SourceStateMap::iterator itr = source_state_map_.begin(); | |
| 1566 itr != source_state_map_.end(); ++itr) { | |
| 1567 itr->second->TextStartReturningData(); | |
| 1568 } | |
| 1438 } | 1569 } |
| 1439 | 1570 |
| 1440 void ChunkDemuxer::AbortPendingReads() { | 1571 void ChunkDemuxer::AbortPendingReads() { |
| 1441 if (audio_) | 1572 if (audio_) |
| 1442 audio_->AbortReads(); | 1573 audio_->AbortReads(); |
| 1443 | 1574 |
| 1444 if (video_) | 1575 if (video_) |
| 1445 video_->AbortReads(); | 1576 video_->AbortReads(); |
| 1577 | |
| 1578 for (SourceStateMap::iterator itr = source_state_map_.begin(); | |
| 1579 itr != source_state_map_.end(); ++itr) { | |
| 1580 itr->second->TextAbortReads(); | |
| 1581 } | |
| 1446 } | 1582 } |
| 1447 | 1583 |
| 1448 void ChunkDemuxer::SeekAllSources(TimeDelta seek_time) { | 1584 void ChunkDemuxer::SeekAllSources(TimeDelta seek_time) { |
| 1449 if (audio_) | 1585 if (audio_) |
| 1450 audio_->Seek(seek_time); | 1586 audio_->Seek(seek_time); |
| 1451 | 1587 |
| 1452 if (video_) | 1588 if (video_) |
| 1453 video_->Seek(seek_time); | 1589 video_->Seek(seek_time); |
| 1590 | |
| 1591 for (SourceStateMap::iterator itr = source_state_map_.begin(); | |
| 1592 itr != source_state_map_.end(); ++itr) { | |
| 1593 itr->second->TextSeek(seek_time); | |
| 1594 } | |
| 1454 } | 1595 } |
| 1455 | 1596 |
| 1456 void ChunkDemuxer::CompletePendingReadsIfPossible() { | 1597 void ChunkDemuxer::CompletePendingReadsIfPossible() { |
| 1457 if (audio_) | 1598 if (audio_) |
| 1458 audio_->CompletePendingReadIfPossible(); | 1599 audio_->CompletePendingReadIfPossible(); |
| 1459 | 1600 |
| 1460 if (video_) | 1601 if (video_) |
| 1461 video_->CompletePendingReadIfPossible(); | 1602 video_->CompletePendingReadIfPossible(); |
| 1603 | |
| 1604 for (SourceStateMap::iterator itr = source_state_map_.begin(); | |
| 1605 itr != source_state_map_.end(); ++itr) { | |
| 1606 itr->second->TextCompletePendingReadIfPossible(); | |
| 1607 } | |
| 1462 } | 1608 } |
| 1463 | 1609 |
| 1464 } // namespace media | 1610 } // namespace media |
| OLD | NEW |