| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 } | 319 } |
| 320 | 320 |
| 321 Ranges<TimeDelta> ChunkDemuxerStream::GetBufferedRanges() { | 321 Ranges<TimeDelta> ChunkDemuxerStream::GetBufferedRanges() { |
| 322 base::AutoLock auto_lock(lock_); | 322 base::AutoLock auto_lock(lock_); |
| 323 return stream_->GetBufferedTime(); | 323 return stream_->GetBufferedTime(); |
| 324 } | 324 } |
| 325 | 325 |
| 326 bool ChunkDemuxerStream::UpdateAudioConfig(const AudioDecoderConfig& config) { | 326 bool ChunkDemuxerStream::UpdateAudioConfig(const AudioDecoderConfig& config) { |
| 327 DCHECK(config.IsValidConfig()); | 327 DCHECK(config.IsValidConfig()); |
| 328 DCHECK_EQ(type_, AUDIO); | 328 DCHECK_EQ(type_, AUDIO); |
| 329 | 329 return stream_->UpdateAudioConfig(config); |
| 330 const AudioDecoderConfig& current_config = | |
| 331 stream_->GetCurrentAudioDecoderConfig(); | |
| 332 | |
| 333 bool success = (current_config.codec() == config.codec()) && | |
| 334 (current_config.bits_per_channel() == config.bits_per_channel()) && | |
| 335 (current_config.channel_layout() == config.channel_layout()) && | |
| 336 (current_config.samples_per_second() == config.samples_per_second()) && | |
| 337 (current_config.extra_data_size() == config.extra_data_size()) && | |
| 338 (!current_config.extra_data() || | |
| 339 !memcmp(current_config.extra_data(), config.extra_data(), | |
| 340 current_config.extra_data_size())); | |
| 341 | |
| 342 if (!success) | |
| 343 DVLOG(1) << "UpdateAudioConfig() : Failed to update audio config."; | |
| 344 | |
| 345 return success; | |
| 346 } | 330 } |
| 347 | 331 |
| 348 bool ChunkDemuxerStream::UpdateVideoConfig(const VideoDecoderConfig& config) { | 332 bool ChunkDemuxerStream::UpdateVideoConfig(const VideoDecoderConfig& config) { |
| 349 DCHECK(config.IsValidConfig()); | 333 DCHECK(config.IsValidConfig()); |
| 350 DCHECK_EQ(type_, VIDEO); | 334 DCHECK_EQ(type_, VIDEO); |
| 351 const VideoDecoderConfig& current_config = | 335 return stream_->UpdateVideoConfig(config); |
| 352 stream_->GetCurrentVideoDecoderConfig(); | |
| 353 | |
| 354 bool success = (current_config.codec() == config.codec()) && | |
| 355 (current_config.format() == config.format()) && | |
| 356 (current_config.profile() == config.profile()) && | |
| 357 (current_config.coded_size() == config.coded_size()) && | |
| 358 (current_config.visible_rect() == config.visible_rect()) && | |
| 359 (current_config.natural_size() == config.natural_size()) && | |
| 360 (current_config.extra_data_size() == config.extra_data_size()) && | |
| 361 (!current_config.extra_data() || | |
| 362 !memcmp(current_config.extra_data(), config.extra_data(), | |
| 363 current_config.extra_data_size())); | |
| 364 | |
| 365 if (!success) | |
| 366 DVLOG(1) << "UpdateVideoConfig() : Failed to update video config."; | |
| 367 | |
| 368 return success; | |
| 369 } | 336 } |
| 370 | 337 |
| 371 void ChunkDemuxerStream::EndOfStream() { | 338 void ChunkDemuxerStream::EndOfStream() { |
| 372 ClosureQueue closures; | 339 ClosureQueue closures; |
| 373 { | 340 { |
| 374 base::AutoLock auto_lock(lock_); | 341 base::AutoLock auto_lock(lock_); |
| 375 DCHECK(!end_of_stream_); | 342 DCHECK(!end_of_stream_); |
| 376 DCHECK(stream_->IsEndSelected()); | 343 DCHECK(stream_->IsEndSelected()); |
| 377 end_of_stream_ = true; | 344 end_of_stream_ = true; |
| 378 CreateReadDoneClosures_Locked(&closures); | 345 CreateReadDoneClosures_Locked(&closures); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 } | 408 } |
| 442 | 409 |
| 443 const VideoDecoderConfig& ChunkDemuxerStream::video_decoder_config() { | 410 const VideoDecoderConfig& ChunkDemuxerStream::video_decoder_config() { |
| 444 CHECK_EQ(type_, VIDEO); | 411 CHECK_EQ(type_, VIDEO); |
| 445 base::AutoLock auto_lock(lock_); | 412 base::AutoLock auto_lock(lock_); |
| 446 return stream_->GetCurrentVideoDecoderConfig(); | 413 return stream_->GetCurrentVideoDecoderConfig(); |
| 447 } | 414 } |
| 448 | 415 |
| 449 void ChunkDemuxerStream::ChangeState_Locked(State state) { | 416 void ChunkDemuxerStream::ChangeState_Locked(State state) { |
| 450 lock_.AssertAcquired(); | 417 lock_.AssertAcquired(); |
| 418 DVLOG(1) << "ChunkDemuxerStream::ChangeState_Locked() : " |
| 419 << "type " << type_ |
| 420 << " - " << state_ << " -> " << state; |
| 451 state_ = state; | 421 state_ = state; |
| 452 } | 422 } |
| 453 | 423 |
| 454 ChunkDemuxerStream::~ChunkDemuxerStream() {} | 424 ChunkDemuxerStream::~ChunkDemuxerStream() {} |
| 455 | 425 |
| 456 void ChunkDemuxerStream::DeferRead_Locked(const ReadCB& read_cb) { | 426 void ChunkDemuxerStream::DeferRead_Locked(const ReadCB& read_cb) { |
| 457 lock_.AssertAcquired(); | 427 lock_.AssertAcquired(); |
| 458 // Wrap & store |read_cb| so that it will | 428 // Wrap & store |read_cb| so that it will |
| 459 // get called on the current MessageLoop. | 429 // get called on the current MessageLoop. |
| 460 read_cbs_.push_back(base::Bind(&RunOnMessageLoop, read_cb, | 430 read_cbs_.push_back(base::Bind(&RunOnMessageLoop, read_cb, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 478 } | 448 } |
| 479 } | 449 } |
| 480 | 450 |
| 481 bool ChunkDemuxerStream::GetNextBuffer_Locked( | 451 bool ChunkDemuxerStream::GetNextBuffer_Locked( |
| 482 DemuxerStream::Status* status, | 452 DemuxerStream::Status* status, |
| 483 scoped_refptr<StreamParserBuffer>* buffer) { | 453 scoped_refptr<StreamParserBuffer>* buffer) { |
| 484 lock_.AssertAcquired(); | 454 lock_.AssertAcquired(); |
| 485 | 455 |
| 486 switch (state_) { | 456 switch (state_) { |
| 487 case RETURNING_DATA_FOR_READS: | 457 case RETURNING_DATA_FOR_READS: |
| 488 if (stream_->GetNextBuffer(buffer)) { | 458 switch (stream_->GetNextBuffer(buffer)) { |
| 489 *status = DemuxerStream::kOk; | 459 case SourceBufferStream::kSuccess: |
| 490 return true; | 460 *status = DemuxerStream::kOk; |
| 461 return true; |
| 462 case SourceBufferStream::kNeedBuffer: |
| 463 if (end_of_stream_) { |
| 464 *status = DemuxerStream::kOk; |
| 465 *buffer = StreamParserBuffer::CreateEOSBuffer(); |
| 466 return true; |
| 467 } |
| 468 return false; |
| 469 case SourceBufferStream::kConfigChange: |
| 470 *status = kConfigChanged; |
| 471 *buffer = NULL; |
| 472 return true; |
| 491 } | 473 } |
| 492 | 474 break; |
| 493 if (end_of_stream_) { | |
| 494 *status = DemuxerStream::kOk; | |
| 495 *buffer = StreamParserBuffer::CreateEOSBuffer(); | |
| 496 return true; | |
| 497 } | |
| 498 return false; | |
| 499 case WAITING_FOR_SEEK: | 475 case WAITING_FOR_SEEK: |
| 500 // Null buffers should be returned in this state since we are waiting | 476 // Null buffers should be returned in this state since we are waiting |
| 501 // for a seek. Any buffers in the SourceBuffer should NOT be returned | 477 // for a seek. Any buffers in the SourceBuffer should NOT be returned |
| 502 // because they are associated with the seek. | 478 // because they are associated with the seek. |
| 503 DCHECK(read_cbs_.empty()); | 479 DCHECK(read_cbs_.empty()); |
| 504 *status = DemuxerStream::kAborted; | 480 *status = DemuxerStream::kAborted; |
| 505 *buffer = NULL; | 481 *buffer = NULL; |
| 506 return true; | 482 return true; |
| 507 case SHUTDOWN: | 483 case SHUTDOWN: |
| 508 DCHECK(read_cbs_.empty()); | 484 DCHECK(read_cbs_.empty()); |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1055 video_->SetStartTime(start_time_); | 1031 video_->SetStartTime(start_time_); |
| 1056 video_->Seek(start_time_); | 1032 video_->Seek(start_time_); |
| 1057 } | 1033 } |
| 1058 | 1034 |
| 1059 // The demuxer is now initialized after the |start_timestamp_| was set. | 1035 // The demuxer is now initialized after the |start_timestamp_| was set. |
| 1060 ChangeState_Locked(INITIALIZED); | 1036 ChangeState_Locked(INITIALIZED); |
| 1061 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); | 1037 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); |
| 1062 } | 1038 } |
| 1063 | 1039 |
| 1064 } // namespace media | 1040 } // namespace media |
| OLD | NEW |