| 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/callback.h" | 5 #include "base/callback.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/time.h" | 11 #include "base/time.h" |
| 12 #include "media/base/data_buffer.h" |
| 12 #include "media/base/filter_host.h" | 13 #include "media/base/filter_host.h" |
| 13 #include "media/base/limits.h" | 14 #include "media/base/limits.h" |
| 14 #include "media/base/media_switches.h" | 15 #include "media/base/media_switches.h" |
| 15 #include "media/ffmpeg/ffmpeg_common.h" | 16 #include "media/ffmpeg/ffmpeg_common.h" |
| 16 #include "media/filters/bitstream_converter.h" | 17 #include "media/filters/bitstream_converter.h" |
| 17 #include "media/filters/ffmpeg_demuxer.h" | 18 #include "media/filters/ffmpeg_demuxer.h" |
| 18 #include "media/filters/ffmpeg_glue.h" | 19 #include "media/filters/ffmpeg_glue.h" |
| 19 #include "media/filters/ffmpeg_h264_bitstream_converter.h" | 20 #include "media/filters/ffmpeg_h264_bitstream_converter.h" |
| 20 | 21 |
| 21 namespace media { | 22 namespace media { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 DCHECK_EQ(MessageLoop::current(), demuxer_->message_loop()); | 131 DCHECK_EQ(MessageLoop::current(), demuxer_->message_loop()); |
| 131 base::AutoLock auto_lock(lock_); | 132 base::AutoLock auto_lock(lock_); |
| 132 DCHECK(read_queue_.empty()) << "Read requests should be empty"; | 133 DCHECK(read_queue_.empty()) << "Read requests should be empty"; |
| 133 buffer_queue_.clear(); | 134 buffer_queue_.clear(); |
| 134 } | 135 } |
| 135 | 136 |
| 136 void FFmpegDemuxerStream::Stop() { | 137 void FFmpegDemuxerStream::Stop() { |
| 137 DCHECK_EQ(MessageLoop::current(), demuxer_->message_loop()); | 138 DCHECK_EQ(MessageLoop::current(), demuxer_->message_loop()); |
| 138 base::AutoLock auto_lock(lock_); | 139 base::AutoLock auto_lock(lock_); |
| 139 buffer_queue_.clear(); | 140 buffer_queue_.clear(); |
| 141 for (ReadQueue::iterator it = read_queue_.begin(); |
| 142 it != read_queue_.end(); ++it) { |
| 143 it->Run(new DataBuffer(0)); |
| 144 } |
| 140 read_queue_.clear(); | 145 read_queue_.clear(); |
| 141 stopped_ = true; | 146 stopped_ = true; |
| 142 } | 147 } |
| 143 | 148 |
| 144 base::TimeDelta FFmpegDemuxerStream::duration() { | 149 base::TimeDelta FFmpegDemuxerStream::duration() { |
| 145 return duration_; | 150 return duration_; |
| 146 } | 151 } |
| 147 | 152 |
| 148 DemuxerStream::Type FFmpegDemuxerStream::type() { | 153 DemuxerStream::Type FFmpegDemuxerStream::type() { |
| 149 return type_; | 154 return type_; |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 base::TimeDelta max_duration; | 469 base::TimeDelta max_duration; |
| 465 const bool kDemuxerIsWebm = !strcmp("webm", format_context_->iformat->name); | 470 const bool kDemuxerIsWebm = !strcmp("webm", format_context_->iformat->name); |
| 466 bool no_supported_streams = true; | 471 bool no_supported_streams = true; |
| 467 for (size_t i = 0; i < format_context_->nb_streams; ++i) { | 472 for (size_t i = 0; i < format_context_->nb_streams; ++i) { |
| 468 AVCodecContext* codec_context = format_context_->streams[i]->codec; | 473 AVCodecContext* codec_context = format_context_->streams[i]->codec; |
| 469 AVMediaType codec_type = codec_context->codec_type; | 474 AVMediaType codec_type = codec_context->codec_type; |
| 470 if (codec_type == AVMEDIA_TYPE_AUDIO || codec_type == AVMEDIA_TYPE_VIDEO) { | 475 if (codec_type == AVMEDIA_TYPE_AUDIO || codec_type == AVMEDIA_TYPE_VIDEO) { |
| 471 AVStream* stream = format_context_->streams[i]; | 476 AVStream* stream = format_context_->streams[i]; |
| 472 // WebM is currently strictly VP8 and Vorbis. | 477 // WebM is currently strictly VP8 and Vorbis. |
| 473 if (kDemuxerIsWebm && (stream->codec->codec_id != CODEC_ID_VP8 && | 478 if (kDemuxerIsWebm && (stream->codec->codec_id != CODEC_ID_VP8 && |
| 474 stream->codec->codec_id != CODEC_ID_VORBIS)) { | 479 stream->codec->codec_id != CODEC_ID_VORBIS)) { |
| 475 packet_streams_.push_back(NULL); | 480 packet_streams_.push_back(NULL); |
| 476 continue; | 481 continue; |
| 477 } | 482 } |
| 478 | 483 |
| 479 scoped_refptr<FFmpegDemuxerStream> demuxer_stream( | 484 scoped_refptr<FFmpegDemuxerStream> demuxer_stream( |
| 480 new FFmpegDemuxerStream(this, stream)); | 485 new FFmpegDemuxerStream(this, stream)); |
| 481 if (!streams_[demuxer_stream->type()]) { | 486 if (!streams_[demuxer_stream->type()]) { |
| 482 no_supported_streams = false; | 487 no_supported_streams = false; |
| 483 streams_[demuxer_stream->type()] = demuxer_stream; | 488 streams_[demuxer_stream->type()] = demuxer_stream; |
| 484 max_duration = std::max(max_duration, demuxer_stream->duration()); | 489 max_duration = std::max(max_duration, demuxer_stream->duration()); |
| 485 | 490 |
| 486 if (stream->first_dts != static_cast<int64_t>(AV_NOPTS_VALUE)) { | 491 if (stream->first_dts != static_cast<int64_t>(AV_NOPTS_VALUE)) { |
| 487 const base::TimeDelta first_dts = ConvertFromTimeBase( | 492 const base::TimeDelta first_dts = ConvertFromTimeBase( |
| 488 stream->time_base, stream->first_dts); | 493 stream->time_base, stream->first_dts); |
| 489 if (start_time_ == kNoTimestamp || first_dts < start_time_) | 494 if (start_time_ == kNoTimestamp || first_dts < start_time_) |
| 490 start_time_ = first_dts; | 495 start_time_ = first_dts; |
| 491 } | 496 } |
| 492 } | 497 } |
| 493 packet_streams_.push_back(demuxer_stream); | 498 packet_streams_.push_back(demuxer_stream); |
| 494 } else { | 499 } else { |
| 495 packet_streams_.push_back(NULL); | 500 packet_streams_.push_back(NULL); |
| 496 } | 501 } |
| 497 } | 502 } |
| 498 if (no_supported_streams) { | 503 if (no_supported_streams) { |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 read_event_.Wait(); | 684 read_event_.Wait(); |
| 680 return last_read_bytes_; | 685 return last_read_bytes_; |
| 681 } | 686 } |
| 682 | 687 |
| 683 void FFmpegDemuxer::SignalReadCompleted(size_t size) { | 688 void FFmpegDemuxer::SignalReadCompleted(size_t size) { |
| 684 last_read_bytes_ = size; | 689 last_read_bytes_ = size; |
| 685 read_event_.Signal(); | 690 read_event_.Signal(); |
| 686 } | 691 } |
| 687 | 692 |
| 688 } // namespace media | 693 } // namespace media |
| OLD | NEW |