| 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 <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "media/base/video_codecs.h" | 24 #include "media/base/video_codecs.h" |
| 25 #include "media/base/video_decoder_config.h" | 25 #include "media/base/video_decoder_config.h" |
| 26 #include "media/filters/frame_processor.h" | 26 #include "media/filters/frame_processor.h" |
| 27 #include "media/filters/stream_parser_factory.h" | 27 #include "media/filters/stream_parser_factory.h" |
| 28 | 28 |
| 29 using base::TimeDelta; | 29 using base::TimeDelta; |
| 30 | 30 |
| 31 namespace media { | 31 namespace media { |
| 32 | 32 |
| 33 ChunkDemuxerStream::ChunkDemuxerStream(Type type, | 33 ChunkDemuxerStream::ChunkDemuxerStream(Type type, |
| 34 bool splice_frames_enabled, | |
| 35 MediaTrack::Id media_track_id) | 34 MediaTrack::Id media_track_id) |
| 36 : type_(type), | 35 : type_(type), |
| 37 liveness_(DemuxerStream::LIVENESS_UNKNOWN), | 36 liveness_(DemuxerStream::LIVENESS_UNKNOWN), |
| 38 media_track_id_(media_track_id), | 37 media_track_id_(media_track_id), |
| 39 state_(UNINITIALIZED), | 38 state_(UNINITIALIZED), |
| 40 splice_frames_enabled_(splice_frames_enabled), | |
| 41 partial_append_window_trimming_enabled_(false), | 39 partial_append_window_trimming_enabled_(false), |
| 42 is_enabled_(true) {} | 40 is_enabled_(true) {} |
| 43 | 41 |
| 44 void ChunkDemuxerStream::StartReturningData() { | 42 void ChunkDemuxerStream::StartReturningData() { |
| 45 DVLOG(1) << "ChunkDemuxerStream::StartReturningData()"; | 43 DVLOG(1) << "ChunkDemuxerStream::StartReturningData()"; |
| 46 base::AutoLock auto_lock(lock_); | 44 base::AutoLock auto_lock(lock_); |
| 47 DCHECK(read_cb_.is_null()); | 45 DCHECK(read_cb_.is_null()); |
| 48 ChangeState_Locked(RETURNING_DATA_FOR_READS); | 46 ChangeState_Locked(RETURNING_DATA_FOR_READS); |
| 49 } | 47 } |
| 50 | 48 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 | 178 |
| 181 bool ChunkDemuxerStream::UpdateAudioConfig( | 179 bool ChunkDemuxerStream::UpdateAudioConfig( |
| 182 const AudioDecoderConfig& config, | 180 const AudioDecoderConfig& config, |
| 183 const scoped_refptr<MediaLog>& media_log) { | 181 const scoped_refptr<MediaLog>& media_log) { |
| 184 DCHECK(config.IsValidConfig()); | 182 DCHECK(config.IsValidConfig()); |
| 185 DCHECK_EQ(type_, AUDIO); | 183 DCHECK_EQ(type_, AUDIO); |
| 186 base::AutoLock auto_lock(lock_); | 184 base::AutoLock auto_lock(lock_); |
| 187 if (!stream_) { | 185 if (!stream_) { |
| 188 DCHECK_EQ(state_, UNINITIALIZED); | 186 DCHECK_EQ(state_, UNINITIALIZED); |
| 189 | 187 |
| 190 // On platforms which support splice frames, enable splice frames and | 188 // Enable partial append window support for most audio codecs (notably: not |
| 191 // partial append window support for most codecs (notably: not opus). | 189 // opus). |
| 192 const bool codec_supported = config.codec() == kCodecMP3 || | 190 partial_append_window_trimming_enabled_ = config.codec() == kCodecMP3 || |
| 193 config.codec() == kCodecAAC || | 191 config.codec() == kCodecAAC || |
| 194 config.codec() == kCodecVorbis; | 192 config.codec() == kCodecVorbis; |
| 195 splice_frames_enabled_ = splice_frames_enabled_ && codec_supported; | |
| 196 partial_append_window_trimming_enabled_ = | |
| 197 splice_frames_enabled_ && codec_supported; | |
| 198 | 193 |
| 199 stream_.reset( | 194 stream_.reset(new SourceBufferStream(config, media_log)); |
| 200 new SourceBufferStream(config, media_log, splice_frames_enabled_)); | |
| 201 return true; | 195 return true; |
| 202 } | 196 } |
| 203 | 197 |
| 204 return stream_->UpdateAudioConfig(config); | 198 return stream_->UpdateAudioConfig(config); |
| 205 } | 199 } |
| 206 | 200 |
| 207 bool ChunkDemuxerStream::UpdateVideoConfig( | 201 bool ChunkDemuxerStream::UpdateVideoConfig( |
| 208 const VideoDecoderConfig& config, | 202 const VideoDecoderConfig& config, |
| 209 const scoped_refptr<MediaLog>& media_log) { | 203 const scoped_refptr<MediaLog>& media_log) { |
| 210 DCHECK(config.IsValidConfig()); | 204 DCHECK(config.IsValidConfig()); |
| 211 DCHECK_EQ(type_, VIDEO); | 205 DCHECK_EQ(type_, VIDEO); |
| 212 base::AutoLock auto_lock(lock_); | 206 base::AutoLock auto_lock(lock_); |
| 213 | 207 |
| 214 if (!stream_) { | 208 if (!stream_) { |
| 215 DCHECK_EQ(state_, UNINITIALIZED); | 209 DCHECK_EQ(state_, UNINITIALIZED); |
| 216 stream_.reset( | 210 stream_.reset(new SourceBufferStream(config, media_log)); |
| 217 new SourceBufferStream(config, media_log, splice_frames_enabled_)); | |
| 218 return true; | 211 return true; |
| 219 } | 212 } |
| 220 | 213 |
| 221 return stream_->UpdateVideoConfig(config); | 214 return stream_->UpdateVideoConfig(config); |
| 222 } | 215 } |
| 223 | 216 |
| 224 void ChunkDemuxerStream::UpdateTextConfig( | 217 void ChunkDemuxerStream::UpdateTextConfig( |
| 225 const TextTrackConfig& config, | 218 const TextTrackConfig& config, |
| 226 const scoped_refptr<MediaLog>& media_log) { | 219 const scoped_refptr<MediaLog>& media_log) { |
| 227 DCHECK_EQ(type_, TEXT); | 220 DCHECK_EQ(type_, TEXT); |
| 228 base::AutoLock auto_lock(lock_); | 221 base::AutoLock auto_lock(lock_); |
| 229 DCHECK(!stream_); | 222 DCHECK(!stream_); |
| 230 DCHECK_EQ(state_, UNINITIALIZED); | 223 DCHECK_EQ(state_, UNINITIALIZED); |
| 231 stream_.reset( | 224 stream_.reset(new SourceBufferStream(config, media_log)); |
| 232 new SourceBufferStream(config, media_log, splice_frames_enabled_)); | |
| 233 } | 225 } |
| 234 | 226 |
| 235 void ChunkDemuxerStream::MarkEndOfStream() { | 227 void ChunkDemuxerStream::MarkEndOfStream() { |
| 236 base::AutoLock auto_lock(lock_); | 228 base::AutoLock auto_lock(lock_); |
| 237 stream_->MarkEndOfStream(); | 229 stream_->MarkEndOfStream(); |
| 238 } | 230 } |
| 239 | 231 |
| 240 void ChunkDemuxerStream::UnmarkEndOfStream() { | 232 void ChunkDemuxerStream::UnmarkEndOfStream() { |
| 241 base::AutoLock auto_lock(lock_); | 233 base::AutoLock auto_lock(lock_); |
| 242 stream_->UnmarkEndOfStream(); | 234 stream_->UnmarkEndOfStream(); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 DVLOG(2) << __func__ << ": returning kOk with EOS buffer, type " << type_; | 385 DVLOG(2) << __func__ << ": returning kOk with EOS buffer, type " << type_; |
| 394 break; | 386 break; |
| 395 } | 387 } |
| 396 | 388 |
| 397 base::ResetAndReturn(&read_cb_).Run(status, buffer); | 389 base::ResetAndReturn(&read_cb_).Run(status, buffer); |
| 398 } | 390 } |
| 399 | 391 |
| 400 ChunkDemuxer::ChunkDemuxer( | 392 ChunkDemuxer::ChunkDemuxer( |
| 401 const base::Closure& open_cb, | 393 const base::Closure& open_cb, |
| 402 const EncryptedMediaInitDataCB& encrypted_media_init_data_cb, | 394 const EncryptedMediaInitDataCB& encrypted_media_init_data_cb, |
| 403 const scoped_refptr<MediaLog>& media_log, | 395 const scoped_refptr<MediaLog>& media_log) |
| 404 bool splice_frames_enabled) | |
| 405 : state_(WAITING_FOR_INIT), | 396 : state_(WAITING_FOR_INIT), |
| 406 cancel_next_seek_(false), | 397 cancel_next_seek_(false), |
| 407 host_(NULL), | 398 host_(NULL), |
| 408 open_cb_(open_cb), | 399 open_cb_(open_cb), |
| 409 encrypted_media_init_data_cb_(encrypted_media_init_data_cb), | 400 encrypted_media_init_data_cb_(encrypted_media_init_data_cb), |
| 410 enable_text_(false), | 401 enable_text_(false), |
| 411 media_log_(media_log), | 402 media_log_(media_log), |
| 412 duration_(kNoTimestamp), | 403 duration_(kNoTimestamp), |
| 413 user_specified_duration_(-1), | 404 user_specified_duration_(-1), |
| 414 liveness_(DemuxerStream::LIVENESS_UNKNOWN), | 405 liveness_(DemuxerStream::LIVENESS_UNKNOWN), |
| 415 splice_frames_enabled_(splice_frames_enabled), | |
| 416 detected_audio_track_count_(0), | 406 detected_audio_track_count_(0), |
| 417 detected_video_track_count_(0), | 407 detected_video_track_count_(0), |
| 418 detected_text_track_count_(0) { | 408 detected_text_track_count_(0) { |
| 419 DCHECK(!open_cb_.is_null()); | 409 DCHECK(!open_cb_.is_null()); |
| 420 DCHECK(!encrypted_media_init_data_cb_.is_null()); | 410 DCHECK(!encrypted_media_init_data_cb_.is_null()); |
| 421 } | 411 } |
| 422 | 412 |
| 423 std::string ChunkDemuxer::GetDisplayName() const { | 413 std::string ChunkDemuxer::GetDisplayName() const { |
| 424 return "ChunkDemuxer"; | 414 return "ChunkDemuxer"; |
| 425 } | 415 } |
| (...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1189 case DemuxerStream::TEXT: | 1179 case DemuxerStream::TEXT: |
| 1190 owning_vector = &text_streams_; | 1180 owning_vector = &text_streams_; |
| 1191 break; | 1181 break; |
| 1192 | 1182 |
| 1193 case DemuxerStream::UNKNOWN: | 1183 case DemuxerStream::UNKNOWN: |
| 1194 NOTREACHED(); | 1184 NOTREACHED(); |
| 1195 return nullptr; | 1185 return nullptr; |
| 1196 } | 1186 } |
| 1197 | 1187 |
| 1198 std::unique_ptr<ChunkDemuxerStream> stream = | 1188 std::unique_ptr<ChunkDemuxerStream> stream = |
| 1199 base::MakeUnique<ChunkDemuxerStream>(type, splice_frames_enabled_, | 1189 base::MakeUnique<ChunkDemuxerStream>(type, media_track_id); |
| 1200 media_track_id); | |
| 1201 DCHECK(track_id_to_demux_stream_map_.find(media_track_id) == | 1190 DCHECK(track_id_to_demux_stream_map_.find(media_track_id) == |
| 1202 track_id_to_demux_stream_map_.end()); | 1191 track_id_to_demux_stream_map_.end()); |
| 1203 track_id_to_demux_stream_map_[media_track_id] = stream.get(); | 1192 track_id_to_demux_stream_map_[media_track_id] = stream.get(); |
| 1204 id_to_streams_map_[source_id].push_back(stream.get()); | 1193 id_to_streams_map_[source_id].push_back(stream.get()); |
| 1205 owning_vector->push_back(std::move(stream)); | 1194 owning_vector->push_back(std::move(stream)); |
| 1206 return owning_vector->back().get(); | 1195 return owning_vector->back().get(); |
| 1207 } | 1196 } |
| 1208 | 1197 |
| 1209 void ChunkDemuxer::OnNewTextTrack(ChunkDemuxerStream* text_stream, | 1198 void ChunkDemuxer::OnNewTextTrack(ChunkDemuxerStream* text_stream, |
| 1210 const TextTrackConfig& config) { | 1199 const TextTrackConfig& config) { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1312 } | 1301 } |
| 1313 | 1302 |
| 1314 void ChunkDemuxer::ShutdownAllStreams() { | 1303 void ChunkDemuxer::ShutdownAllStreams() { |
| 1315 for (auto itr = source_state_map_.begin(); itr != source_state_map_.end(); | 1304 for (auto itr = source_state_map_.begin(); itr != source_state_map_.end(); |
| 1316 ++itr) { | 1305 ++itr) { |
| 1317 itr->second->Shutdown(); | 1306 itr->second->Shutdown(); |
| 1318 } | 1307 } |
| 1319 } | 1308 } |
| 1320 | 1309 |
| 1321 } // namespace media | 1310 } // namespace media |
| OLD | NEW |