Erik Språng | 96965ae | 2018-10-23 15:42:37 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include "video/frame_dumping_decoder.h" |
| 12 | |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 13 | #include <memory> |
Erik Språng | 96965ae | 2018-10-23 15:42:37 +0200 | [diff] [blame] | 14 | #include <utility> |
| 15 | |
| 16 | #include "modules/video_coding/include/video_codec_interface.h" |
Markus Handell | 1c2f637 | 2019-08-20 20:21:37 +0200 | [diff] [blame] | 17 | #include "modules/video_coding/utility/ivf_file_writer.h" |
Erik Språng | 96965ae | 2018-10-23 15:42:37 +0200 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
Markus Handell | 1c2f637 | 2019-08-20 20:21:37 +0200 | [diff] [blame] | 20 | namespace { |
| 21 | |
| 22 | class FrameDumpingDecoder : public VideoDecoder { |
| 23 | public: |
| 24 | FrameDumpingDecoder(std::unique_ptr<VideoDecoder> decoder, FileWrapper file); |
| 25 | ~FrameDumpingDecoder() override; |
| 26 | |
| 27 | int32_t InitDecode(const VideoCodec* codec_settings, |
| 28 | int32_t number_of_cores) override; |
| 29 | int32_t Decode(const EncodedImage& input_image, |
| 30 | bool missing_frames, |
| 31 | int64_t render_time_ms) override; |
| 32 | int32_t RegisterDecodeCompleteCallback( |
| 33 | DecodedImageCallback* callback) override; |
| 34 | int32_t Release() override; |
| 35 | bool PrefersLateDecoding() const override; |
| 36 | const char* ImplementationName() const override; |
| 37 | |
| 38 | private: |
| 39 | std::unique_ptr<VideoDecoder> decoder_; |
| 40 | VideoCodecType codec_type_ = VideoCodecType::kVideoCodecGeneric; |
| 41 | std::unique_ptr<IvfFileWriter> writer_; |
| 42 | }; |
Erik Språng | 96965ae | 2018-10-23 15:42:37 +0200 | [diff] [blame] | 43 | |
| 44 | FrameDumpingDecoder::FrameDumpingDecoder(std::unique_ptr<VideoDecoder> decoder, |
Niels Möller | b7edf69 | 2019-02-08 16:40:53 +0100 | [diff] [blame] | 45 | FileWrapper file) |
Erik Språng | 96965ae | 2018-10-23 15:42:37 +0200 | [diff] [blame] | 46 | : decoder_(std::move(decoder)), |
Niels Möller | b7edf69 | 2019-02-08 16:40:53 +0100 | [diff] [blame] | 47 | writer_(IvfFileWriter::Wrap(std::move(file), |
Erik Språng | 96965ae | 2018-10-23 15:42:37 +0200 | [diff] [blame] | 48 | /* byte_limit= */ 100000000)) {} |
| 49 | |
| 50 | FrameDumpingDecoder::~FrameDumpingDecoder() = default; |
| 51 | |
| 52 | int32_t FrameDumpingDecoder::InitDecode(const VideoCodec* codec_settings, |
| 53 | int32_t number_of_cores) { |
Niels Möller | 7aacdd9 | 2019-03-25 09:11:40 +0100 | [diff] [blame] | 54 | codec_type_ = codec_settings->codecType; |
Erik Språng | 96965ae | 2018-10-23 15:42:37 +0200 | [diff] [blame] | 55 | return decoder_->InitDecode(codec_settings, number_of_cores); |
| 56 | } |
| 57 | |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 58 | int32_t FrameDumpingDecoder::Decode(const EncodedImage& input_image, |
| 59 | bool missing_frames, |
| 60 | int64_t render_time_ms) { |
Niels Möller | 7aacdd9 | 2019-03-25 09:11:40 +0100 | [diff] [blame] | 61 | int32_t ret = decoder_->Decode(input_image, missing_frames, render_time_ms); |
| 62 | writer_->WriteFrame(input_image, codec_type_); |
Erik Språng | 96965ae | 2018-10-23 15:42:37 +0200 | [diff] [blame] | 63 | |
| 64 | return ret; |
| 65 | } |
| 66 | |
| 67 | int32_t FrameDumpingDecoder::RegisterDecodeCompleteCallback( |
| 68 | DecodedImageCallback* callback) { |
| 69 | return decoder_->RegisterDecodeCompleteCallback(callback); |
| 70 | } |
| 71 | |
| 72 | int32_t FrameDumpingDecoder::Release() { |
| 73 | return decoder_->Release(); |
| 74 | } |
| 75 | |
| 76 | bool FrameDumpingDecoder::PrefersLateDecoding() const { |
| 77 | return decoder_->PrefersLateDecoding(); |
| 78 | } |
| 79 | |
| 80 | const char* FrameDumpingDecoder::ImplementationName() const { |
| 81 | return decoder_->ImplementationName(); |
| 82 | } |
| 83 | |
Markus Handell | 1c2f637 | 2019-08-20 20:21:37 +0200 | [diff] [blame] | 84 | } // namespace |
| 85 | |
| 86 | std::unique_ptr<VideoDecoder> CreateFrameDumpingDecoderWrapper( |
| 87 | std::unique_ptr<VideoDecoder> decoder, |
| 88 | FileWrapper file) { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 89 | return std::make_unique<FrameDumpingDecoder>(std::move(decoder), |
| 90 | std::move(file)); |
Markus Handell | 1c2f637 | 2019-08-20 20:21:37 +0200 | [diff] [blame] | 91 | } |
| 92 | |
Erik Språng | 96965ae | 2018-10-23 15:42:37 +0200 | [diff] [blame] | 93 | } // namespace webrtc |