You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
3.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. #include "video/frame_dumping_decoder.h"
  11. #include <memory>
  12. #include <utility>
  13. #include "modules/video_coding/include/video_codec_interface.h"
  14. #include "modules/video_coding/utility/ivf_file_writer.h"
  15. namespace webrtc {
  16. namespace {
  17. class FrameDumpingDecoder : public VideoDecoder {
  18. public:
  19. FrameDumpingDecoder(std::unique_ptr<VideoDecoder> decoder, FileWrapper file);
  20. ~FrameDumpingDecoder() override;
  21. int32_t InitDecode(const VideoCodec* codec_settings,
  22. int32_t number_of_cores) override;
  23. int32_t Decode(const EncodedImage& input_image,
  24. bool missing_frames,
  25. int64_t render_time_ms) override;
  26. int32_t RegisterDecodeCompleteCallback(
  27. DecodedImageCallback* callback) override;
  28. int32_t Release() override;
  29. bool PrefersLateDecoding() const override;
  30. const char* ImplementationName() const override;
  31. private:
  32. std::unique_ptr<VideoDecoder> decoder_;
  33. VideoCodecType codec_type_ = VideoCodecType::kVideoCodecGeneric;
  34. std::unique_ptr<IvfFileWriter> writer_;
  35. };
  36. FrameDumpingDecoder::FrameDumpingDecoder(std::unique_ptr<VideoDecoder> decoder,
  37. FileWrapper file)
  38. : decoder_(std::move(decoder)),
  39. writer_(IvfFileWriter::Wrap(std::move(file),
  40. /* byte_limit= */ 100000000)) {}
  41. FrameDumpingDecoder::~FrameDumpingDecoder() = default;
  42. int32_t FrameDumpingDecoder::InitDecode(const VideoCodec* codec_settings,
  43. int32_t number_of_cores) {
  44. codec_type_ = codec_settings->codecType;
  45. return decoder_->InitDecode(codec_settings, number_of_cores);
  46. }
  47. int32_t FrameDumpingDecoder::Decode(const EncodedImage& input_image,
  48. bool missing_frames,
  49. int64_t render_time_ms) {
  50. int32_t ret = decoder_->Decode(input_image, missing_frames, render_time_ms);
  51. writer_->WriteFrame(input_image, codec_type_);
  52. return ret;
  53. }
  54. int32_t FrameDumpingDecoder::RegisterDecodeCompleteCallback(
  55. DecodedImageCallback* callback) {
  56. return decoder_->RegisterDecodeCompleteCallback(callback);
  57. }
  58. int32_t FrameDumpingDecoder::Release() {
  59. return decoder_->Release();
  60. }
  61. bool FrameDumpingDecoder::PrefersLateDecoding() const {
  62. return decoder_->PrefersLateDecoding();
  63. }
  64. const char* FrameDumpingDecoder::ImplementationName() const {
  65. return decoder_->ImplementationName();
  66. }
  67. } // namespace
  68. std::unique_ptr<VideoDecoder> CreateFrameDumpingDecoderWrapper(
  69. std::unique_ptr<VideoDecoder> decoder,
  70. FileWrapper file) {
  71. return std::make_unique<FrameDumpingDecoder>(std::move(decoder),
  72. std::move(file));
  73. }
  74. } // namespace webrtc