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