| 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 | bool Configure(const Settings& settings) override; |
| 28 | int32_t Decode(const EncodedImage& input_image, |
| 29 | int64_t render_time_ms) override; |
| 30 | int32_t RegisterDecodeCompleteCallback( |
| 31 | DecodedImageCallback* callback) override; |
| 32 | int32_t Release() override; |
| 33 | DecoderInfo GetDecoderInfo() const override; |
| 34 | const char* ImplementationName() const override; |
| 35 |
| 36 | private: |
| 37 | std::unique_ptr<VideoDecoder> decoder_; |
| 38 | VideoCodecType codec_type_ = VideoCodecType::kVideoCodecGeneric; |
| 39 | std::unique_ptr<IvfFileWriter> writer_; |
| 40 | }; |
| 41 |
| 42 | FrameDumpingDecoder::FrameDumpingDecoder(std::unique_ptr<VideoDecoder> decoder, |
| 43 | FileWrapper file) |
| 44 | : decoder_(std::move(decoder)), |
| 45 | writer_(IvfFileWriter::Wrap(std::move(file), |
| 46 | /* byte_limit= */ 100000000)) {} |
| 47 |
| 48 | FrameDumpingDecoder::~FrameDumpingDecoder() = default; |
| 49 |
| 50 | bool FrameDumpingDecoder::Configure(const Settings& settings) { |
| 51 | codec_type_ = settings.codec_type(); |
| 52 | return decoder_->Configure(settings); |
| 53 | } |
| 54 |
| 55 | int32_t FrameDumpingDecoder::Decode(const EncodedImage& input_image, |
| 56 | int64_t render_time_ms) { |
| 57 | int32_t ret = decoder_->Decode(input_image, render_time_ms); |
| 58 | writer_->WriteFrame(input_image, codec_type_); |
| 59 |
| 60 | return ret; |
| 61 | } |
| 62 |
| 63 | int32_t FrameDumpingDecoder::RegisterDecodeCompleteCallback( |
| 64 | DecodedImageCallback* callback) { |
| 65 | return decoder_->RegisterDecodeCompleteCallback(callback); |
| 66 | } |
| 67 |
| 68 | int32_t FrameDumpingDecoder::Release() { |
| 69 | return decoder_->Release(); |
| 70 | } |
| 71 |
| 72 | VideoDecoder::DecoderInfo FrameDumpingDecoder::GetDecoderInfo() const { |
| 73 | return decoder_->GetDecoderInfo(); |
| 74 | } |
| 75 |
| 76 | const char* FrameDumpingDecoder::ImplementationName() const { |
| 77 | return decoder_->ImplementationName(); |
| 78 | } |
| 79 |
| 80 | } // namespace |
| 81 |
| 82 | std::unique_ptr<VideoDecoder> CreateFrameDumpingDecoderWrapper( |
| 83 | std::unique_ptr<VideoDecoder> decoder, |
| 84 | FileWrapper file) { |
| 85 | return std::make_unique<FrameDumpingDecoder>(std::move(decoder), |
| 86 | std::move(file)); |
| 87 | } |
| 88 |
| 89 | } // namespace webrtc |
| 90 |