Chromium Code Reviews| 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/base64.h" | 10 #include "base/base64.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 DCHECK(!enc_key_id.empty()); | 88 DCHECK(!enc_key_id.empty()); |
| 89 if (enc_key_id.empty()) | 89 if (enc_key_id.empty()) |
| 90 return; | 90 return; |
| 91 | 91 |
| 92 encryption_key_id_.assign(enc_key_id); | 92 encryption_key_id_.assign(enc_key_id); |
| 93 demuxer_->FireNeedKey(kWebMEncryptInitDataType, enc_key_id); | 93 demuxer_->FireNeedKey(kWebMEncryptInitDataType, enc_key_id); |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 void FFmpegDemuxerStream::EnqueuePacket(ScopedAVPacket packet) { | 97 void FFmpegDemuxerStream::EnqueuePacket(ScopedAVPacket packet) { |
| 98 | |
| 98 DCHECK(message_loop_->BelongsToCurrentThread()); | 99 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 99 | 100 |
| 100 if (stopped_ || end_of_stream_) { | 101 if (stopped_ || end_of_stream_) { |
| 101 NOTREACHED() << "Attempted to enqueue packet on a stopped stream"; | 102 NOTREACHED() << "Attempted to enqueue packet on a stopped stream"; |
| 102 return; | 103 return; |
| 103 } | 104 } |
| 104 | 105 |
| 105 // Convert the packet if there is a bitstream filter. | 106 // Convert the packet if there is a bitstream filter. |
| 106 if (packet->data && bitstream_converter_enabled_ && | 107 if (packet->data && bitstream_converter_enabled_ && |
| 107 !bitstream_converter_->ConvertPacket(packet.get())) { | 108 !bitstream_converter_->ConvertPacket(packet.get())) { |
| 108 LOG(ERROR) << "Format conversion failed."; | 109 LOG(ERROR) << "Format conversion failed."; |
| 109 } | 110 } |
| 110 | 111 |
| 112 // Get side data if any. For now, the only type of side_data is VP8 Alpha. We | |
| 113 // keep this generic so that other side_data types in the future can be | |
| 114 // handled the same way as well. | |
| 115 uint8* side_data; | |
|
scherkus (not reviewing)
2013/04/04 22:54:00
nit: I'd declare + assign on same line
vignesh
2013/04/05 19:06:58
Done.
| |
| 116 int side_data_size = 0; | |
| 117 av_packet_split_side_data(packet.get()); | |
| 118 side_data = av_packet_get_side_data(packet.get(), | |
| 119 AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL, | |
| 120 &side_data_size); | |
| 121 | |
| 111 // If a packet is returned by FFmpeg's av_parser_parse2() the packet will | 122 // If a packet is returned by FFmpeg's av_parser_parse2() the packet will |
| 112 // reference inner memory of FFmpeg. As such we should transfer the packet | 123 // reference inner memory of FFmpeg. As such we should transfer the packet |
| 113 // into memory we control. | 124 // into memory we control. |
| 114 scoped_refptr<DecoderBuffer> buffer; | 125 scoped_refptr<DecoderBuffer> buffer; |
| 115 buffer = DecoderBuffer::CopyFrom(packet->data, packet->size); | 126 if (side_data_size > 0) { |
| 127 buffer = DecoderBuffer::CopyFrom(packet.get()->data, packet.get()->size, | |
| 128 side_data, side_data_size); | |
| 129 } else { | |
| 130 buffer = DecoderBuffer::CopyFrom(packet.get()->data, packet.get()->size); | |
| 131 } | |
| 116 | 132 |
| 117 if ((type() == DemuxerStream::AUDIO && audio_config_.is_encrypted()) || | 133 if ((type() == DemuxerStream::AUDIO && audio_config_.is_encrypted()) || |
| 118 (type() == DemuxerStream::VIDEO && video_config_.is_encrypted())) { | 134 (type() == DemuxerStream::VIDEO && video_config_.is_encrypted())) { |
| 119 scoped_ptr<DecryptConfig> config(WebMCreateDecryptConfig( | 135 scoped_ptr<DecryptConfig> config(WebMCreateDecryptConfig( |
| 120 packet->data, packet->size, | 136 packet->data, packet->size, |
| 121 reinterpret_cast<const uint8*>(encryption_key_id_.data()), | 137 reinterpret_cast<const uint8*>(encryption_key_id_.data()), |
| 122 encryption_key_id_.size())); | 138 encryption_key_id_.size())); |
| 123 if (!config) | 139 if (!config) |
| 124 LOG(ERROR) << "Creation of DecryptConfig failed."; | 140 LOG(ERROR) << "Creation of DecryptConfig failed."; |
| 125 buffer->SetDecryptConfig(config.Pass()); | 141 buffer->SetDecryptConfig(config.Pass()); |
| (...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 730 } | 746 } |
| 731 for (size_t i = 0; i < buffered.size(); ++i) | 747 for (size_t i = 0; i < buffered.size(); ++i) |
| 732 host_->AddBufferedTimeRange(buffered.start(i), buffered.end(i)); | 748 host_->AddBufferedTimeRange(buffered.start(i), buffered.end(i)); |
| 733 } | 749 } |
| 734 | 750 |
| 735 void FFmpegDemuxer::OnDataSourceError() { | 751 void FFmpegDemuxer::OnDataSourceError() { |
| 736 host_->OnDemuxerError(PIPELINE_ERROR_READ); | 752 host_->OnDemuxerError(PIPELINE_ERROR_READ); |
| 737 } | 753 } |
| 738 | 754 |
| 739 } // namespace media | 755 } // namespace media |
| OLD | NEW |