| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_h265_to_annex_b_bitstream_converter.h" | 5 #include "media/filters/ffmpeg_h265_to_annex_b_bitstream_converter.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "media/base/decrypt_config.h" | 10 #include "media/base/decrypt_config.h" |
| 11 #include "media/ffmpeg/ffmpeg_common.h" | 11 #include "media/ffmpeg/ffmpeg_common.h" |
| 12 #include "media/formats/mp4/avc.h" | 12 #include "media/formats/mp4/avc.h" |
| 13 #include "media/formats/mp4/box_definitions.h" | 13 #include "media/formats/mp4/box_definitions.h" |
| 14 #include "media/formats/mp4/hevc.h" | 14 #include "media/formats/mp4/hevc.h" |
| 15 | 15 |
| 16 namespace media { | 16 namespace media { |
| 17 | 17 |
| 18 FFmpegH265ToAnnexBBitstreamConverter::FFmpegH265ToAnnexBBitstreamConverter( | 18 FFmpegH265ToAnnexBBitstreamConverter::FFmpegH265ToAnnexBBitstreamConverter( |
| 19 AVCodecContext* stream_codec_context) | 19 AVCodecParameters* stream_codec_parameters) |
| 20 : stream_codec_context_(stream_codec_context) { | 20 : stream_codec_parameters_(stream_codec_parameters) { |
| 21 CHECK(stream_codec_context_); | 21 CHECK(stream_codec_parameters_); |
| 22 } | 22 } |
| 23 | 23 |
| 24 FFmpegH265ToAnnexBBitstreamConverter::~FFmpegH265ToAnnexBBitstreamConverter() {} | 24 FFmpegH265ToAnnexBBitstreamConverter::~FFmpegH265ToAnnexBBitstreamConverter() {} |
| 25 | 25 |
| 26 bool FFmpegH265ToAnnexBBitstreamConverter::ConvertPacket(AVPacket* packet) { | 26 bool FFmpegH265ToAnnexBBitstreamConverter::ConvertPacket(AVPacket* packet) { |
| 27 DVLOG(3) << __FUNCTION__; | 27 DVLOG(3) << __FUNCTION__; |
| 28 if (packet == NULL || !packet->data) | 28 if (packet == NULL || !packet->data) |
| 29 return false; | 29 return false; |
| 30 | 30 |
| 31 // Calculate the needed output buffer size. | 31 // Calculate the needed output buffer size. |
| 32 if (!hevc_config_) { | 32 if (!hevc_config_) { |
| 33 if (!stream_codec_context_->extradata || | 33 if (!stream_codec_parameters_->extradata || |
| 34 stream_codec_context_->extradata_size <= 0) { | 34 stream_codec_parameters_->extradata_size <= 0) { |
| 35 DVLOG(1) << "HEVCDecoderConfiguration not found, no extra codec data"; | 35 DVLOG(1) << "HEVCDecoderConfiguration not found, no extra codec data"; |
| 36 return false; | 36 return false; |
| 37 } | 37 } |
| 38 | 38 |
| 39 hevc_config_.reset(new mp4::HEVCDecoderConfigurationRecord()); | 39 hevc_config_.reset(new mp4::HEVCDecoderConfigurationRecord()); |
| 40 | 40 |
| 41 if (!hevc_config_->Parse( | 41 if (!hevc_config_->Parse(stream_codec_parameters_->extradata, |
| 42 stream_codec_context_->extradata, | 42 stream_codec_parameters_->extradata_size)) { |
| 43 stream_codec_context_->extradata_size)) { | |
| 44 DVLOG(1) << "Parsing HEVCDecoderConfiguration failed"; | 43 DVLOG(1) << "Parsing HEVCDecoderConfiguration failed"; |
| 45 return false; | 44 return false; |
| 46 } | 45 } |
| 47 } | 46 } |
| 48 | 47 |
| 49 std::vector<uint8_t> input_frame; | 48 std::vector<uint8_t> input_frame; |
| 50 std::vector<SubsampleEntry> subsamples; | 49 std::vector<SubsampleEntry> subsamples; |
| 51 // TODO(servolk): Performance could be improved here, by reducing unnecessary | 50 // TODO(servolk): Performance could be improved here, by reducing unnecessary |
| 52 // data copying, but first annex b conversion code needs to be refactored to | 51 // data copying, but first annex b conversion code needs to be refactored to |
| 53 // allow that (see crbug.com/455379). | 52 // allow that (see crbug.com/455379). |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 memcpy(dest_packet.data, &input_frame[0], input_frame.size()); | 85 memcpy(dest_packet.data, &input_frame[0], input_frame.size()); |
| 87 | 86 |
| 88 // At the end we must destroy the old packet. | 87 // At the end we must destroy the old packet. |
| 89 av_packet_unref(packet); | 88 av_packet_unref(packet); |
| 90 *packet = dest_packet; // Finally, replace the values in the input packet. | 89 *packet = dest_packet; // Finally, replace the values in the input packet. |
| 91 | 90 |
| 92 return true; | 91 return true; |
| 93 } | 92 } |
| 94 | 93 |
| 95 } // namespace media | 94 } // namespace media |
| OLD | NEW |