| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/logging.h" | 5 #include "base/logging.h" |
| 6 #include "services/media/framework_ffmpeg/av_codec_context.h" | 6 #include "services/media/framework_ffmpeg/av_codec_context.h" |
| 7 #include "services/media/framework_ffmpeg/ffmpeg_decoder_base.h" | 7 #include "services/media/framework_ffmpeg/ffmpeg_decoder_base.h" |
| 8 | 8 |
| 9 namespace mojo { | 9 namespace mojo { |
| 10 namespace media { | 10 namespace media { |
| 11 | 11 |
| 12 FfmpegDecoderBase::FfmpegDecoderBase(AvCodecContextPtr av_codec_context) : | 12 FfmpegDecoderBase::FfmpegDecoderBase(AvCodecContextPtr av_codec_context) |
| 13 av_codec_context_(std::move(av_codec_context)), | 13 : av_codec_context_(std::move(av_codec_context)), |
| 14 av_frame_ptr_(av_frame_alloc()) { | 14 av_frame_ptr_(av_frame_alloc()) { |
| 15 DCHECK(av_codec_context_); | 15 DCHECK(av_codec_context_); |
| 16 } | 16 } |
| 17 | 17 |
| 18 FfmpegDecoderBase::~FfmpegDecoderBase() {} | 18 FfmpegDecoderBase::~FfmpegDecoderBase() {} |
| 19 | 19 |
| 20 std::unique_ptr<StreamType> FfmpegDecoderBase::output_stream_type() { | 20 std::unique_ptr<StreamType> FfmpegDecoderBase::output_stream_type() { |
| 21 return AvCodecContext::GetStreamType(*av_codec_context_); | 21 return AvCodecContext::GetStreamType(*av_codec_context_); |
| 22 } | 22 } |
| 23 | 23 |
| 24 void FfmpegDecoderBase::Flush() { | 24 void FfmpegDecoderBase::Flush() { |
| 25 DCHECK(av_codec_context_); | 25 DCHECK(av_codec_context_); |
| 26 avcodec_flush_buffers(av_codec_context_.get()); | 26 avcodec_flush_buffers(av_codec_context_.get()); |
| 27 } | 27 } |
| 28 | 28 |
| 29 bool FfmpegDecoderBase::TransformPacket( | 29 bool FfmpegDecoderBase::TransformPacket(const PacketPtr& input, |
| 30 const PacketPtr& input, | 30 bool new_input, |
| 31 bool new_input, | 31 PayloadAllocator* allocator, |
| 32 PayloadAllocator* allocator, | 32 PacketPtr* output) { |
| 33 PacketPtr* output) { | |
| 34 DCHECK(input); | 33 DCHECK(input); |
| 35 DCHECK(allocator); | 34 DCHECK(allocator); |
| 36 DCHECK(output); | 35 DCHECK(output); |
| 37 | 36 |
| 38 *output = nullptr; | 37 *output = nullptr; |
| 39 | 38 |
| 40 if (new_input) { | 39 if (new_input) { |
| 41 PrepareInputPacket(input); | 40 PrepareInputPacket(input); |
| 42 } | 41 } |
| 43 | 42 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 72 return UnprepareInputPacket(input, output); | 71 return UnprepareInputPacket(input, output); |
| 73 } | 72 } |
| 74 | 73 |
| 75 void FfmpegDecoderBase::PrepareInputPacket(const PacketPtr& input) { | 74 void FfmpegDecoderBase::PrepareInputPacket(const PacketPtr& input) { |
| 76 av_init_packet(&av_packet_); | 75 av_init_packet(&av_packet_); |
| 77 av_packet_.data = reinterpret_cast<uint8_t*>(input->payload()); | 76 av_packet_.data = reinterpret_cast<uint8_t*>(input->payload()); |
| 78 av_packet_.size = input->size(); | 77 av_packet_.size = input->size(); |
| 79 av_packet_.pts = input->pts(); | 78 av_packet_.pts = input->pts(); |
| 80 } | 79 } |
| 81 | 80 |
| 82 bool FfmpegDecoderBase::UnprepareInputPacket( | 81 bool FfmpegDecoderBase::UnprepareInputPacket(const PacketPtr& input, |
| 83 const PacketPtr& input, | 82 PacketPtr* output) { |
| 84 PacketPtr* output) { | |
| 85 if (input->end_of_stream()) { | 83 if (input->end_of_stream()) { |
| 86 // Indicate end of stream. This happens when we're draining for the last | 84 // Indicate end of stream. This happens when we're draining for the last |
| 87 // time, so there should be no output packet yet. | 85 // time, so there should be no output packet yet. |
| 88 DCHECK(*output == nullptr); | 86 DCHECK(*output == nullptr); |
| 89 *output = CreateOutputEndOfStreamPacket(); | 87 *output = CreateOutputEndOfStreamPacket(); |
| 90 } | 88 } |
| 91 | 89 |
| 92 av_packet_.size = 0; | 90 av_packet_.size = 0; |
| 93 av_packet_.data = nullptr; | 91 av_packet_.data = nullptr; |
| 94 | 92 |
| 95 return true; | 93 return true; |
| 96 } | 94 } |
| 97 | 95 |
| 98 } // namespace media | 96 } // namespace media |
| 99 } // namespace mojo | 97 } // namespace mojo |
| OLD | NEW |