| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/callback.h" | 6 #include "base/callback.h" |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 DCHECK(demuxer_); | 66 DCHECK(demuxer_); |
| 67 | 67 |
| 68 // Determine our media format. | 68 // Determine our media format. |
| 69 switch (stream->codec->codec_type) { | 69 switch (stream->codec->codec_type) { |
| 70 case AVMEDIA_TYPE_AUDIO: | 70 case AVMEDIA_TYPE_AUDIO: |
| 71 type_ = AUDIO; | 71 type_ = AUDIO; |
| 72 AVCodecContextToAudioDecoderConfig(stream->codec, &audio_config_); | 72 AVCodecContextToAudioDecoderConfig(stream->codec, &audio_config_); |
| 73 break; | 73 break; |
| 74 case AVMEDIA_TYPE_VIDEO: | 74 case AVMEDIA_TYPE_VIDEO: |
| 75 type_ = VIDEO; | 75 type_ = VIDEO; |
| 76 AVStreamToVideoDecoderConfig(stream, &video_config_); |
| 76 break; | 77 break; |
| 77 default: | 78 default: |
| 78 NOTREACHED(); | 79 NOTREACHED(); |
| 79 break; | 80 break; |
| 80 } | 81 } |
| 81 | 82 |
| 82 // Calculate the duration. | 83 // Calculate the duration. |
| 83 duration_ = ConvertStreamTimestamp(stream->time_base, stream->duration); | 84 duration_ = ConvertStreamTimestamp(stream->time_base, stream->duration); |
| 84 } | 85 } |
| 85 | 86 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 filter_name = "vc1_asftoannexg"; | 248 filter_name = "vc1_asftoannexg"; |
| 248 } | 249 } |
| 249 | 250 |
| 250 if (filter_name) { | 251 if (filter_name) { |
| 251 bitstream_converter_.reset( | 252 bitstream_converter_.reset( |
| 252 new FFmpegBitstreamConverter(filter_name, stream_->codec)); | 253 new FFmpegBitstreamConverter(filter_name, stream_->codec)); |
| 253 CHECK(bitstream_converter_->Initialize()); | 254 CHECK(bitstream_converter_->Initialize()); |
| 254 } | 255 } |
| 255 } | 256 } |
| 256 | 257 |
| 257 AVStream* FFmpegDemuxerStream::GetAVStream() { | |
| 258 return stream_; | |
| 259 } | |
| 260 | |
| 261 const AudioDecoderConfig& FFmpegDemuxerStream::audio_decoder_config() { | 258 const AudioDecoderConfig& FFmpegDemuxerStream::audio_decoder_config() { |
| 262 CHECK_EQ(type_, AUDIO); | 259 CHECK_EQ(type_, AUDIO); |
| 263 return audio_config_; | 260 return audio_config_; |
| 264 } | 261 } |
| 265 | 262 |
| 263 const VideoDecoderConfig& FFmpegDemuxerStream::video_decoder_config() { |
| 264 CHECK_EQ(type_, VIDEO); |
| 265 return video_config_; |
| 266 } |
| 267 |
| 266 // static | 268 // static |
| 267 base::TimeDelta FFmpegDemuxerStream::ConvertStreamTimestamp( | 269 base::TimeDelta FFmpegDemuxerStream::ConvertStreamTimestamp( |
| 268 const AVRational& time_base, int64 timestamp) { | 270 const AVRational& time_base, int64 timestamp) { |
| 269 if (timestamp == static_cast<int64>(AV_NOPTS_VALUE)) | 271 if (timestamp == static_cast<int64>(AV_NOPTS_VALUE)) |
| 270 return kNoTimestamp; | 272 return kNoTimestamp; |
| 271 | 273 |
| 272 return ConvertFromTimeBase(time_base, timestamp); | 274 return ConvertFromTimeBase(time_base, timestamp); |
| 273 } | 275 } |
| 274 | 276 |
| 275 // | 277 // |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 DCHECK_EQ(MessageLoop::current(), message_loop_); | 679 DCHECK_EQ(MessageLoop::current(), message_loop_); |
| 678 | 680 |
| 679 StreamVector::iterator iter; | 681 StreamVector::iterator iter; |
| 680 for (size_t i = 0; i < packet_streams_.size(); ++i) { | 682 for (size_t i = 0; i < packet_streams_.size(); ++i) { |
| 681 if (!packet_streams_[i]) | 683 if (!packet_streams_[i]) |
| 682 continue; | 684 continue; |
| 683 | 685 |
| 684 // If the codec type is audio, remove the reference. DemuxTask() will | 686 // If the codec type is audio, remove the reference. DemuxTask() will |
| 685 // look for such reference, and this will result in deleting the | 687 // look for such reference, and this will result in deleting the |
| 686 // audio packets after they are demuxed. | 688 // audio packets after they are demuxed. |
| 687 if (packet_streams_[i]->GetAVStream()->codec->codec_type == | 689 if (packet_streams_[i]->type() == DemuxerStream::AUDIO) { |
| 688 AVMEDIA_TYPE_AUDIO) { | |
| 689 packet_streams_[i] = NULL; | 690 packet_streams_[i] = NULL; |
| 690 } | 691 } |
| 691 } | 692 } |
| 692 } | 693 } |
| 693 | 694 |
| 694 bool FFmpegDemuxer::StreamsHavePendingReads() { | 695 bool FFmpegDemuxer::StreamsHavePendingReads() { |
| 695 DCHECK_EQ(MessageLoop::current(), message_loop_); | 696 DCHECK_EQ(MessageLoop::current(), message_loop_); |
| 696 StreamVector::iterator iter; | 697 StreamVector::iterator iter; |
| 697 for (iter = streams_.begin(); iter != streams_.end(); ++iter) { | 698 for (iter = streams_.begin(); iter != streams_.end(); ++iter) { |
| 698 if (*iter && (*iter)->HasPendingReads()) { | 699 if (*iter && (*iter)->HasPendingReads()) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 722 read_event_.Wait(); | 723 read_event_.Wait(); |
| 723 return last_read_bytes_; | 724 return last_read_bytes_; |
| 724 } | 725 } |
| 725 | 726 |
| 726 void FFmpegDemuxer::SignalReadCompleted(size_t size) { | 727 void FFmpegDemuxer::SignalReadCompleted(size_t size) { |
| 727 last_read_bytes_ = size; | 728 last_read_bytes_ = size; |
| 728 read_event_.Signal(); | 729 read_event_.Signal(); |
| 729 } | 730 } |
| 730 | 731 |
| 731 } // namespace media | 732 } // namespace media |
| OLD | NEW |