| 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 |
| 13 | #include <memory> |
| 14 | #include <utility> |
| 15 |
| 16 | #include "modules/video_coding/include/video_codec_interface.h" |
| 17 | #include "modules/video_coding/utility/ivf_file_writer.h" |
| 18 |
| 19 | namespace webrtc { |
| 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 | DecoderInfo GetDecoderInfo() 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 | }; |
| 43 |
| 44 | FrameDumpingDecoder::FrameDumpingDecoder(std::unique_ptr<VideoDecoder> decoder, |
| 45 | FileWrapper file) |
| 46 | : decoder_(std::move(decoder)), |
| 47 | writer_(IvfFileWriter::Wrap(std::move(file), |
| 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) { |
| 54 | codec_type_ = codec_settings->codecType; |
| 55 | return decoder_->InitDecode(codec_settings, number_of_cores); |
| 56 | } |
| 57 |
| 58 | int32_t FrameDumpingDecoder::Decode(const EncodedImage& input_image, |
| 59 | bool missing_frames, |
| 60 | int64_t render_time_ms) { |
| 61 | int32_t ret = decoder_->Decode(input_image, missing_frames, render_time_ms); |
| 62 | writer_->WriteFrame(input_image, codec_type_); |
| 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 | VideoDecoder::DecoderInfo FrameDumpingDecoder::GetDecoderInfo() const { |
| 77 | return decoder_->GetDecoderInfo(); |
| 78 | } |
| 79 |
| 80 | const char* FrameDumpingDecoder::ImplementationName() const { |
| 81 | return decoder_->ImplementationName(); |
| 82 | } |
| 83 |
| 84 | } // namespace |
| 85 |
| 86 | std::unique_ptr<VideoDecoder> CreateFrameDumpingDecoderWrapper( |
| 87 | std::unique_ptr<VideoDecoder> decoder, |
| 88 | FileWrapper file) { |
| 89 | return std::make_unique<FrameDumpingDecoder>(std::move(decoder), |
| 90 | std::move(file)); |
| 91 | } |
| 92 |
| 93 | } // namespace webrtc |
| 94 |