 Chromium Code Reviews
 Chromium Code Reviews Issue 12263013:
  media: Add support for playback of VP8 Alpha video streams  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 12263013:
  media: Add support for playback of VP8 Alpha video streams  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| 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 <string> | 8 #include <string> | 
| 9 | 9 | 
| 10 #include "base/bind.h" | 10 #include "base/bind.h" | 
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 // Calculate the duration. | 63 // Calculate the duration. | 
| 64 duration_ = ConvertStreamTimestamp(stream->time_base, stream->duration); | 64 duration_ = ConvertStreamTimestamp(stream->time_base, stream->duration); | 
| 65 | 65 | 
| 66 if (stream_->codec->codec_id == CODEC_ID_H264) { | 66 if (stream_->codec->codec_id == CODEC_ID_H264) { | 
| 67 bitstream_converter_.reset( | 67 bitstream_converter_.reset( | 
| 68 new FFmpegH264ToAnnexBBitstreamConverter(stream_->codec)); | 68 new FFmpegH264ToAnnexBBitstreamConverter(stream_->codec)); | 
| 69 } | 69 } | 
| 70 } | 70 } | 
| 71 | 71 | 
| 72 void FFmpegDemuxerStream::EnqueuePacket(ScopedAVPacket packet) { | 72 void FFmpegDemuxerStream::EnqueuePacket(ScopedAVPacket packet) { | 
| 73 uint8* side_data; | |
| 74 int side_data_size = 0; | |
| 75 AVPacket* pkt; | |
| 
scherkus (not reviewing)
2013/02/27 07:28:26
nit: this is C++! we can move these closer to wher
 
vignesh
2013/03/28 21:45:12
yeah, i was writing this along side when i made th
 | |
| 76 | |
| 73 DCHECK(message_loop_->BelongsToCurrentThread()); | 77 DCHECK(message_loop_->BelongsToCurrentThread()); | 
| 74 | 78 | 
| 75 if (stopped_ || end_of_stream_) { | 79 if (stopped_ || end_of_stream_) { | 
| 76 NOTREACHED() << "Attempted to enqueue packet on a stopped stream"; | 80 NOTREACHED() << "Attempted to enqueue packet on a stopped stream"; | 
| 77 return; | 81 return; | 
| 78 } | 82 } | 
| 79 | 83 | 
| 80 // Convert the packet if there is a bitstream filter. | 84 // Convert the packet if there is a bitstream filter. | 
| 81 if (packet->data && bitstream_converter_enabled_ && | 85 if (packet->data && bitstream_converter_enabled_ && | 
| 82 !bitstream_converter_->ConvertPacket(packet.get())) { | 86 !bitstream_converter_->ConvertPacket(packet.get())) { | 
| 83 LOG(ERROR) << "Format conversion failed."; | 87 LOG(ERROR) << "Format conversion failed."; | 
| 84 } | 88 } | 
| 85 | 89 | 
| 90 // Get side data if any. For now, the only type of side_data is VP8 Alpha. We | |
| 91 // keep this generic so that other side_data types in the future can be | |
| 92 // handled the same way as well. | |
| 93 pkt = packet.get(); | |
| 
scherkus (not reviewing)
2013/02/27 07:28:26
nit: can we inline the packet.get() calls instead
 
vignesh
2013/03/28 21:45:12
Done.
 | |
| 94 av_packet_split_side_data(pkt); | |
| 95 side_data = av_packet_get_side_data(pkt, | |
| 96 AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL, | |
| 
scherkus (not reviewing)
2013/02/27 07:28:26
is it safe to call this method with this enum for
 
vignesh
2013/03/28 21:45:12
we are requesting a very specific type of side dat
 | |
| 97 &side_data_size); | |
| 98 | |
| 86 // If a packet is returned by FFmpeg's av_parser_parse2() the packet will | 99 // If a packet is returned by FFmpeg's av_parser_parse2() the packet will | 
| 87 // reference inner memory of FFmpeg. As such we should transfer the packet | 100 // reference inner memory of FFmpeg. As such we should transfer the packet | 
| 88 // into memory we control. | 101 // into memory we control. | 
| 89 scoped_refptr<DecoderBuffer> buffer; | 102 scoped_refptr<DecoderBuffer> buffer; | 
| 90 buffer = DecoderBuffer::CopyFrom(packet->data, packet->size); | 103 if (side_data_size > 0) { | 
| 104 buffer = DecoderBuffer::CopyFrom(pkt->data, pkt->size, | |
| 105 side_data, side_data_size); | |
| 106 } else { | |
| 107 buffer = DecoderBuffer::CopyFrom(pkt->data, pkt->size); | |
| 108 } | |
| 91 buffer->SetTimestamp(ConvertStreamTimestamp( | 109 buffer->SetTimestamp(ConvertStreamTimestamp( | 
| 92 stream_->time_base, packet->pts)); | 110 stream_->time_base, packet->pts)); | 
| 93 buffer->SetDuration(ConvertStreamTimestamp( | 111 buffer->SetDuration(ConvertStreamTimestamp( | 
| 94 stream_->time_base, packet->duration)); | 112 stream_->time_base, packet->duration)); | 
| 95 if (buffer->GetTimestamp() != kNoTimestamp() && | 113 if (buffer->GetTimestamp() != kNoTimestamp() && | 
| 96 last_packet_timestamp_ != kNoTimestamp() && | 114 last_packet_timestamp_ != kNoTimestamp() && | 
| 97 last_packet_timestamp_ < buffer->GetTimestamp()) { | 115 last_packet_timestamp_ < buffer->GetTimestamp()) { | 
| 98 buffered_ranges_.Add(last_packet_timestamp_, buffer->GetTimestamp()); | 116 buffered_ranges_.Add(last_packet_timestamp_, buffer->GetTimestamp()); | 
| 99 demuxer_->NotifyBufferingChanged(); | 117 demuxer_->NotifyBufferingChanged(); | 
| 100 } | 118 } | 
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 678 } | 696 } | 
| 679 for (size_t i = 0; i < buffered.size(); ++i) | 697 for (size_t i = 0; i < buffered.size(); ++i) | 
| 680 host_->AddBufferedTimeRange(buffered.start(i), buffered.end(i)); | 698 host_->AddBufferedTimeRange(buffered.start(i), buffered.end(i)); | 
| 681 } | 699 } | 
| 682 | 700 | 
| 683 void FFmpegDemuxer::OnDataSourceError() { | 701 void FFmpegDemuxer::OnDataSourceError() { | 
| 684 host_->OnDemuxerError(PIPELINE_ERROR_READ); | 702 host_->OnDemuxerError(PIPELINE_ERROR_READ); | 
| 685 } | 703 } | 
| 686 | 704 | 
| 687 } // namespace media | 705 } // namespace media | 
| OLD | NEW |