blob: 4ccb333081d84666930803b89c6651bb1a81e76c [file] [log] [blame]
Erik Språng96965ae2018-10-23 15:42:37 +02001/*
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 Bonadei317a1f02019-09-17 17:06:18 +020013#include <memory>
Erik Språng96965ae2018-10-23 15:42:37 +020014#include <utility>
15
16#include "modules/video_coding/include/video_codec_interface.h"
Markus Handell1c2f6372019-08-20 20:21:37 +020017#include "modules/video_coding/utility/ivf_file_writer.h"
Erik Språng96965ae2018-10-23 15:42:37 +020018
19namespace webrtc {
Markus Handell1c2f6372019-08-20 20:21:37 +020020namespace {
21
22class 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ång96965ae2018-10-23 15:42:37 +020043
44FrameDumpingDecoder::FrameDumpingDecoder(std::unique_ptr<VideoDecoder> decoder,
Niels Möllerb7edf692019-02-08 16:40:53 +010045 FileWrapper file)
Erik Språng96965ae2018-10-23 15:42:37 +020046 : decoder_(std::move(decoder)),
Niels Möllerb7edf692019-02-08 16:40:53 +010047 writer_(IvfFileWriter::Wrap(std::move(file),
Erik Språng96965ae2018-10-23 15:42:37 +020048 /* byte_limit= */ 100000000)) {}
49
50FrameDumpingDecoder::~FrameDumpingDecoder() = default;
51
52int32_t FrameDumpingDecoder::InitDecode(const VideoCodec* codec_settings,
53 int32_t number_of_cores) {
Niels Möller7aacdd92019-03-25 09:11:40 +010054 codec_type_ = codec_settings->codecType;
Erik Språng96965ae2018-10-23 15:42:37 +020055 return decoder_->InitDecode(codec_settings, number_of_cores);
56}
57
Jonas Olssona4d87372019-07-05 19:08:33 +020058int32_t FrameDumpingDecoder::Decode(const EncodedImage& input_image,
59 bool missing_frames,
60 int64_t render_time_ms) {
Niels Möller7aacdd92019-03-25 09:11:40 +010061 int32_t ret = decoder_->Decode(input_image, missing_frames, render_time_ms);
62 writer_->WriteFrame(input_image, codec_type_);
Erik Språng96965ae2018-10-23 15:42:37 +020063
64 return ret;
65}
66
67int32_t FrameDumpingDecoder::RegisterDecodeCompleteCallback(
68 DecodedImageCallback* callback) {
69 return decoder_->RegisterDecodeCompleteCallback(callback);
70}
71
72int32_t FrameDumpingDecoder::Release() {
73 return decoder_->Release();
74}
75
76bool FrameDumpingDecoder::PrefersLateDecoding() const {
77 return decoder_->PrefersLateDecoding();
78}
79
80const char* FrameDumpingDecoder::ImplementationName() const {
81 return decoder_->ImplementationName();
82}
83
Markus Handell1c2f6372019-08-20 20:21:37 +020084} // namespace
85
86std::unique_ptr<VideoDecoder> CreateFrameDumpingDecoderWrapper(
87 std::unique_ptr<VideoDecoder> decoder,
88 FileWrapper file) {
Mirko Bonadei317a1f02019-09-17 17:06:18 +020089 return std::make_unique<FrameDumpingDecoder>(std::move(decoder),
90 std::move(file));
Markus Handell1c2f6372019-08-20 20:21:37 +020091}
92
Erik Språng96965ae2018-10-23 15:42:37 +020093} // namespace webrtc