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/ffmpeg_demuxer.h" | 5 #include "media/filters/ffmpeg_demuxer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 task_runner_(base::ThreadTaskRunnerHandle::Get()), | 260 task_runner_(base::ThreadTaskRunnerHandle::Get()), |
261 stream_(stream), | 261 stream_(stream), |
262 audio_config_(audio_config.release()), | 262 audio_config_(audio_config.release()), |
263 video_config_(video_config.release()), | 263 video_config_(video_config.release()), |
264 type_(UNKNOWN), | 264 type_(UNKNOWN), |
265 liveness_(LIVENESS_UNKNOWN), | 265 liveness_(LIVENESS_UNKNOWN), |
266 end_of_stream_(false), | 266 end_of_stream_(false), |
267 last_packet_timestamp_(kNoTimestamp()), | 267 last_packet_timestamp_(kNoTimestamp()), |
268 last_packet_duration_(kNoTimestamp()), | 268 last_packet_duration_(kNoTimestamp()), |
269 video_rotation_(VIDEO_ROTATION_0), | 269 video_rotation_(VIDEO_ROTATION_0), |
270 is_enabled_(true), | |
270 fixup_negative_timestamps_(false) { | 271 fixup_negative_timestamps_(false) { |
271 DCHECK(demuxer_); | 272 DCHECK(demuxer_); |
272 | 273 |
273 bool is_encrypted = false; | 274 bool is_encrypted = false; |
274 int rotation = 0; | 275 int rotation = 0; |
275 AVDictionaryEntry* rotation_entry = NULL; | 276 AVDictionaryEntry* rotation_entry = NULL; |
276 | 277 |
277 // Determine our media format. | 278 // Determine our media format. |
278 switch (stream->codec->codec_type) { | 279 switch (stream->codec->codec_type) { |
279 case AVMEDIA_TYPE_AUDIO: | 280 case AVMEDIA_TYPE_AUDIO: |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
606 // Don't accept any additional reads if we've been told to stop. | 607 // Don't accept any additional reads if we've been told to stop. |
607 // The |demuxer_| may have been destroyed in the pipeline thread. | 608 // The |demuxer_| may have been destroyed in the pipeline thread. |
608 // | 609 // |
609 // TODO(scherkus): it would be cleaner to reply with an error message. | 610 // TODO(scherkus): it would be cleaner to reply with an error message. |
610 if (!demuxer_) { | 611 if (!demuxer_) { |
611 base::ResetAndReturn(&read_cb_).Run( | 612 base::ResetAndReturn(&read_cb_).Run( |
612 DemuxerStream::kOk, DecoderBuffer::CreateEOSBuffer()); | 613 DemuxerStream::kOk, DecoderBuffer::CreateEOSBuffer()); |
613 return; | 614 return; |
614 } | 615 } |
615 | 616 |
617 if (!is_enabled_) { | |
618 DVLOG(1) << "Read from disabled stream, returning EOS"; | |
619 base::ResetAndReturn(&read_cb_).Run(kOk, DecoderBuffer::CreateEOSBuffer()); | |
620 return; | |
621 } | |
622 | |
616 SatisfyPendingRead(); | 623 SatisfyPendingRead(); |
617 } | 624 } |
618 | 625 |
619 void FFmpegDemuxerStream::EnableBitstreamConverter() { | 626 void FFmpegDemuxerStream::EnableBitstreamConverter() { |
620 DCHECK(task_runner_->BelongsToCurrentThread()); | 627 DCHECK(task_runner_->BelongsToCurrentThread()); |
621 | 628 |
622 #if defined(USE_PROPRIETARY_CODECS) | 629 #if defined(USE_PROPRIETARY_CODECS) |
623 InitBitstreamConverter(); | 630 InitBitstreamConverter(); |
624 #else | 631 #else |
625 NOTREACHED() << "Proprietary codecs not enabled."; | 632 NOTREACHED() << "Proprietary codecs not enabled."; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
669 DCHECK(task_runner_->BelongsToCurrentThread()); | 676 DCHECK(task_runner_->BelongsToCurrentThread()); |
670 DCHECK_EQ(type_, VIDEO); | 677 DCHECK_EQ(type_, VIDEO); |
671 DCHECK(video_config_.get()); | 678 DCHECK(video_config_.get()); |
672 return *video_config_; | 679 return *video_config_; |
673 } | 680 } |
674 | 681 |
675 VideoRotation FFmpegDemuxerStream::video_rotation() { | 682 VideoRotation FFmpegDemuxerStream::video_rotation() { |
676 return video_rotation_; | 683 return video_rotation_; |
677 } | 684 } |
678 | 685 |
686 bool FFmpegDemuxerStream::enabled() const { | |
687 DCHECK(task_runner_->BelongsToCurrentThread()); | |
688 return is_enabled_; | |
689 } | |
690 | |
691 void FFmpegDemuxerStream::set_enabled(bool enabled, base::TimeDelta timestamp) { | |
chcunningham
2016/06/02 23:49:43
I feel like we need some logic here to drop frames
| |
692 DCHECK(task_runner_->BelongsToCurrentThread()); | |
693 if (enabled == is_enabled_) | |
694 return; | |
695 | |
696 is_enabled_ = enabled; | |
697 if (!is_enabled_ && !read_cb_.is_null()) { | |
698 DVLOG(1) << "Read from disabled stream, returning EOS"; | |
699 base::ResetAndReturn(&read_cb_).Run(kOk, DecoderBuffer::CreateEOSBuffer()); | |
700 return; | |
701 } | |
702 } | |
703 | |
679 void FFmpegDemuxerStream::SetLiveness(Liveness liveness) { | 704 void FFmpegDemuxerStream::SetLiveness(Liveness liveness) { |
680 DCHECK(task_runner_->BelongsToCurrentThread()); | 705 DCHECK(task_runner_->BelongsToCurrentThread()); |
681 DCHECK_EQ(liveness_, LIVENESS_UNKNOWN); | 706 DCHECK_EQ(liveness_, LIVENESS_UNKNOWN); |
682 liveness_ = liveness; | 707 liveness_ = liveness; |
683 } | 708 } |
684 | 709 |
685 base::TimeDelta FFmpegDemuxerStream::GetElapsedTime() const { | 710 base::TimeDelta FFmpegDemuxerStream::GetElapsedTime() const { |
686 return ConvertStreamTimestamp(stream_->time_base, stream_->cur_dts); | 711 return ConvertStreamTimestamp(stream_->time_base, stream_->cur_dts); |
687 } | 712 } |
688 | 713 |
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1531 // | 1556 // |
1532 // https://code.google.com/p/chromium/issues/detail?id=169133#c10 | 1557 // https://code.google.com/p/chromium/issues/detail?id=169133#c10 |
1533 if (!packet->data) { | 1558 if (!packet->data) { |
1534 ScopedAVPacket new_packet(new AVPacket()); | 1559 ScopedAVPacket new_packet(new AVPacket()); |
1535 av_new_packet(new_packet.get(), 0); | 1560 av_new_packet(new_packet.get(), 0); |
1536 av_packet_copy_props(new_packet.get(), packet.get()); | 1561 av_packet_copy_props(new_packet.get(), packet.get()); |
1537 packet.swap(new_packet); | 1562 packet.swap(new_packet); |
1538 } | 1563 } |
1539 | 1564 |
1540 FFmpegDemuxerStream* demuxer_stream = streams_[packet->stream_index]; | 1565 FFmpegDemuxerStream* demuxer_stream = streams_[packet->stream_index]; |
1541 demuxer_stream->EnqueuePacket(std::move(packet)); | 1566 if (demuxer_stream->enabled()) |
1567 demuxer_stream->EnqueuePacket(std::move(packet)); | |
1542 } | 1568 } |
1543 | 1569 |
1544 // Keep reading until we've reached capacity. | 1570 // Keep reading until we've reached capacity. |
1545 ReadFrameIfNeeded(); | 1571 ReadFrameIfNeeded(); |
1546 } | 1572 } |
1547 | 1573 |
1548 bool FFmpegDemuxer::StreamsHaveAvailableCapacity() { | 1574 bool FFmpegDemuxer::StreamsHaveAvailableCapacity() { |
1549 DCHECK(task_runner_->BelongsToCurrentThread()); | 1575 DCHECK(task_runner_->BelongsToCurrentThread()); |
1550 StreamVector::iterator iter; | 1576 StreamVector::iterator iter; |
1551 for (iter = streams_.begin(); iter != streams_.end(); ++iter) { | 1577 for (iter = streams_.begin(); iter != streams_.end(); ++iter) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1606 } | 1632 } |
1607 | 1633 |
1608 const DemuxerStream* FFmpegDemuxer::GetDemuxerStreamByTrackId( | 1634 const DemuxerStream* FFmpegDemuxer::GetDemuxerStreamByTrackId( |
1609 unsigned track_id) const { | 1635 unsigned track_id) const { |
1610 const auto& it = track_id_to_demux_stream_.find(track_id); | 1636 const auto& it = track_id_to_demux_stream_.find(track_id); |
1611 CHECK(it != track_id_to_demux_stream_.end()); | 1637 CHECK(it != track_id_to_demux_stream_.end()); |
1612 return it->second; | 1638 return it->second; |
1613 } | 1639 } |
1614 | 1640 |
1615 } // namespace media | 1641 } // namespace media |
OLD | NEW |