| 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 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 | 607 |
| 608 if (!audio_) { | 608 if (!audio_) { |
| 609 DVLOG(1) << "Failed to create an audio stream."; | 609 DVLOG(1) << "Failed to create an audio stream."; |
| 610 return false; | 610 return false; |
| 611 } | 611 } |
| 612 | 612 |
| 613 if (!frame_processor_->AddTrack(FrameProcessor::kAudioTrackId, audio_)) { | 613 if (!frame_processor_->AddTrack(FrameProcessor::kAudioTrackId, audio_)) { |
| 614 DVLOG(1) << "Failed to add audio track to frame processor."; | 614 DVLOG(1) << "Failed to add audio track to frame processor."; |
| 615 return false; | 615 return false; |
| 616 } | 616 } |
| 617 |
| 618 audio_->UpdateRangeRemovalCB( |
| 619 base::Bind(&FrameProcessor::OnRangeRemoval, |
| 620 base::Unretained(frame_processor_.get()), |
| 621 FrameProcessor::kAudioTrackId)); |
| 617 } | 622 } |
| 618 | 623 |
| 619 frame_processor_->OnPossibleAudioConfigUpdate(audio_config); | 624 frame_processor_->OnPossibleAudioConfigUpdate(audio_config); |
| 620 success &= audio_->UpdateAudioConfig(audio_config, log_cb_); | 625 success &= audio_->UpdateAudioConfig(audio_config, log_cb_); |
| 621 } | 626 } |
| 622 | 627 |
| 623 if (video_config.IsValidConfig()) { | 628 if (video_config.IsValidConfig()) { |
| 624 if (!video_) { | 629 if (!video_) { |
| 625 media_log_->SetBooleanProperty("found_video_stream", true); | 630 media_log_->SetBooleanProperty("found_video_stream", true); |
| 626 } | 631 } |
| 627 if (!video_ || | 632 if (!video_ || |
| 628 video_->video_decoder_config().codec() != video_config.codec()) { | 633 video_->video_decoder_config().codec() != video_config.codec()) { |
| 629 media_log_->SetStringProperty("video_codec_name", | 634 media_log_->SetStringProperty("video_codec_name", |
| 630 video_config.GetHumanReadableCodecName()); | 635 video_config.GetHumanReadableCodecName()); |
| 631 } | 636 } |
| 632 | 637 |
| 633 if (!video_) { | 638 if (!video_) { |
| 634 video_ = create_demuxer_stream_cb_.Run(DemuxerStream::VIDEO); | 639 video_ = create_demuxer_stream_cb_.Run(DemuxerStream::VIDEO); |
| 635 | 640 |
| 636 if (!video_) { | 641 if (!video_) { |
| 637 DVLOG(1) << "Failed to create a video stream."; | 642 DVLOG(1) << "Failed to create a video stream."; |
| 638 return false; | 643 return false; |
| 639 } | 644 } |
| 640 | 645 |
| 641 if (!frame_processor_->AddTrack(FrameProcessor::kVideoTrackId, video_)) { | 646 if (!frame_processor_->AddTrack(FrameProcessor::kVideoTrackId, video_)) { |
| 642 DVLOG(1) << "Failed to add video track to frame processor."; | 647 DVLOG(1) << "Failed to add video track to frame processor."; |
| 643 return false; | 648 return false; |
| 644 } | 649 } |
| 650 |
| 651 video_->UpdateRangeRemovalCB( |
| 652 base::Bind(&FrameProcessor::OnRangeRemoval, |
| 653 base::Unretained(frame_processor_.get()), |
| 654 FrameProcessor::kVideoTrackId)); |
| 645 } | 655 } |
| 646 | 656 |
| 647 success &= video_->UpdateVideoConfig(video_config, log_cb_); | 657 success &= video_->UpdateVideoConfig(video_config, log_cb_); |
| 648 } | 658 } |
| 649 | 659 |
| 650 typedef StreamParser::TextTrackConfigMap::const_iterator TextConfigItr; | 660 typedef StreamParser::TextTrackConfigMap::const_iterator TextConfigItr; |
| 651 if (text_stream_map_.empty()) { | 661 if (text_stream_map_.empty()) { |
| 652 for (TextConfigItr itr = text_configs.begin(); | 662 for (TextConfigItr itr = text_configs.begin(); |
| 653 itr != text_configs.end(); ++itr) { | 663 itr != text_configs.end(); ++itr) { |
| 654 ChunkDemuxerStream* const text_stream = | 664 ChunkDemuxerStream* const text_stream = |
| 655 create_demuxer_stream_cb_.Run(DemuxerStream::TEXT); | 665 create_demuxer_stream_cb_.Run(DemuxerStream::TEXT); |
| 656 if (!frame_processor_->AddTrack(itr->first, text_stream)) { | 666 if (!frame_processor_->AddTrack(itr->first, text_stream)) { |
| 657 success &= false; | 667 success &= false; |
| 658 MEDIA_LOG(ERROR, log_cb_) << "Failed to add text track ID " | 668 MEDIA_LOG(ERROR, log_cb_) << "Failed to add text track ID " |
| 659 << itr->first << " to frame processor."; | 669 << itr->first << " to frame processor."; |
| 660 break; | 670 break; |
| 661 } | 671 } |
| 672 text_stream->UpdateRangeRemovalCB( |
| 673 base::Bind(&FrameProcessor::OnRangeRemoval, |
| 674 base::Unretained(frame_processor_.get()), itr->first)); |
| 662 text_stream->UpdateTextConfig(itr->second, log_cb_); | 675 text_stream->UpdateTextConfig(itr->second, log_cb_); |
| 663 text_stream_map_[itr->first] = text_stream; | 676 text_stream_map_[itr->first] = text_stream; |
| 664 new_text_track_cb_.Run(text_stream, itr->second); | 677 new_text_track_cb_.Run(text_stream, itr->second); |
| 665 } | 678 } |
| 666 } else { | 679 } else { |
| 667 const size_t text_count = text_stream_map_.size(); | 680 const size_t text_count = text_stream_map_.size(); |
| 668 if (text_configs.size() != text_count) { | 681 if (text_configs.size() != text_count) { |
| 669 success &= false; | 682 success &= false; |
| 670 MEDIA_LOG(ERROR, log_cb_) << "The number of text track configs changed."; | 683 MEDIA_LOG(ERROR, log_cb_) << "The number of text track configs changed."; |
| 671 } else if (text_count == 1) { | 684 } else if (text_count == 1) { |
| 672 TextConfigItr config_itr = text_configs.begin(); | 685 TextConfigItr config_itr = text_configs.begin(); |
| 673 TextStreamMap::iterator stream_itr = text_stream_map_.begin(); | 686 TextStreamMap::iterator stream_itr = text_stream_map_.begin(); |
| 674 ChunkDemuxerStream* text_stream = stream_itr->second; | 687 ChunkDemuxerStream* text_stream = stream_itr->second; |
| 675 TextTrackConfig old_config = text_stream->text_track_config(); | 688 TextTrackConfig old_config = text_stream->text_track_config(); |
| 676 TextTrackConfig new_config(config_itr->second.kind(), | 689 TextTrackConfig new_config(config_itr->second.kind(), |
| 677 config_itr->second.label(), | 690 config_itr->second.label(), |
| 678 config_itr->second.language(), | 691 config_itr->second.language(), |
| 679 old_config.id()); | 692 old_config.id()); |
| 680 if (!new_config.Matches(old_config)) { | 693 if (!new_config.Matches(old_config)) { |
| 681 success &= false; | 694 success &= false; |
| 682 MEDIA_LOG(ERROR, log_cb_) | 695 MEDIA_LOG(ERROR, log_cb_) |
| 683 << "New text track config does not match old one."; | 696 << "New text track config does not match old one."; |
| 684 } else { | 697 } else { |
| 685 StreamParser::TrackId old_id = stream_itr->first; | 698 StreamParser::TrackId old_id = stream_itr->first; |
| 686 StreamParser::TrackId new_id = config_itr->first; | 699 StreamParser::TrackId new_id = config_itr->first; |
| 687 if (new_id != old_id) { | 700 if (new_id != old_id) { |
| 688 if (frame_processor_->UpdateTrack(old_id, new_id)) { | 701 if (frame_processor_->UpdateTrack(old_id, new_id)) { |
| 702 text_stream->UpdateRangeRemovalCB( |
| 703 base::Bind(&FrameProcessor::OnRangeRemoval, |
| 704 base::Unretained(frame_processor_.get()), new_id)); |
| 689 text_stream_map_.clear(); | 705 text_stream_map_.clear(); |
| 690 text_stream_map_[config_itr->first] = text_stream; | 706 text_stream_map_[new_id] = text_stream; |
| 691 } else { | 707 } else { |
| 692 success &= false; | 708 success &= false; |
| 693 MEDIA_LOG(ERROR, log_cb_) | 709 MEDIA_LOG(ERROR, log_cb_) |
| 694 << "Error remapping single text track number"; | 710 << "Error remapping single text track number"; |
| 695 } | 711 } |
| 696 } | 712 } |
| 697 } | 713 } |
| 698 } else { | 714 } else { |
| 699 for (TextConfigItr config_itr = text_configs.begin(); | 715 for (TextConfigItr config_itr = text_configs.begin(); |
| 700 config_itr != text_configs.end(); ++config_itr) { | 716 config_itr != text_configs.end(); ++config_itr) { |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 969 | 985 |
| 970 void ChunkDemuxerStream::UpdateTextConfig(const TextTrackConfig& config, | 986 void ChunkDemuxerStream::UpdateTextConfig(const TextTrackConfig& config, |
| 971 const LogCB& log_cb) { | 987 const LogCB& log_cb) { |
| 972 DCHECK_EQ(type_, TEXT); | 988 DCHECK_EQ(type_, TEXT); |
| 973 base::AutoLock auto_lock(lock_); | 989 base::AutoLock auto_lock(lock_); |
| 974 DCHECK(!stream_); | 990 DCHECK(!stream_); |
| 975 DCHECK_EQ(state_, UNINITIALIZED); | 991 DCHECK_EQ(state_, UNINITIALIZED); |
| 976 stream_.reset(new SourceBufferStream(config, log_cb, splice_frames_enabled_)); | 992 stream_.reset(new SourceBufferStream(config, log_cb, splice_frames_enabled_)); |
| 977 } | 993 } |
| 978 | 994 |
| 995 void ChunkDemuxerStream::UpdateRangeRemovalCB( |
| 996 const SourceBufferStream::NotifyRangeRemovalCB& range_removal_cb) { |
| 997 DCHECK(!range_removal_cb.is_null()); |
| 998 base::AutoLock auto_lock(lock_); |
| 999 stream_->set_range_removal_cb(range_removal_cb); |
| 1000 } |
| 1001 |
| 979 void ChunkDemuxerStream::MarkEndOfStream() { | 1002 void ChunkDemuxerStream::MarkEndOfStream() { |
| 980 base::AutoLock auto_lock(lock_); | 1003 base::AutoLock auto_lock(lock_); |
| 981 stream_->MarkEndOfStream(); | 1004 stream_->MarkEndOfStream(); |
| 982 } | 1005 } |
| 983 | 1006 |
| 984 void ChunkDemuxerStream::UnmarkEndOfStream() { | 1007 void ChunkDemuxerStream::UnmarkEndOfStream() { |
| 985 base::AutoLock auto_lock(lock_); | 1008 base::AutoLock auto_lock(lock_); |
| 986 stream_->UnmarkEndOfStream(); | 1009 stream_->UnmarkEndOfStream(); |
| 987 } | 1010 } |
| 988 | 1011 |
| (...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1840 } | 1863 } |
| 1841 | 1864 |
| 1842 void ChunkDemuxer::ShutdownAllStreams() { | 1865 void ChunkDemuxer::ShutdownAllStreams() { |
| 1843 for (SourceStateMap::iterator itr = source_state_map_.begin(); | 1866 for (SourceStateMap::iterator itr = source_state_map_.begin(); |
| 1844 itr != source_state_map_.end(); ++itr) { | 1867 itr != source_state_map_.end(); ++itr) { |
| 1845 itr->second->Shutdown(); | 1868 itr->second->Shutdown(); |
| 1846 } | 1869 } |
| 1847 } | 1870 } |
| 1848 | 1871 |
| 1849 } // namespace media | 1872 } // namespace media |
| OLD | NEW |