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.

87 lines
2.7 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 "test/fake_vp8_decoder.h"
  11. #include <stddef.h>
  12. #include "absl/types/optional.h"
  13. #include "api/scoped_refptr.h"
  14. #include "api/video/i420_buffer.h"
  15. #include "api/video/video_frame.h"
  16. #include "api/video/video_frame_buffer.h"
  17. #include "api/video/video_rotation.h"
  18. #include "modules/video_coding/include/video_error_codes.h"
  19. #include "rtc_base/time_utils.h"
  20. namespace webrtc {
  21. namespace test {
  22. namespace {
  23. // Read width and height from the payload of the frame if it is a key frame the
  24. // same way as the real VP8 decoder.
  25. // FakeEncoder writes width, height and frame type.
  26. void ParseFakeVp8(const unsigned char* data, int* width, int* height) {
  27. bool key_frame = data[0] == 0;
  28. if (key_frame) {
  29. *width = ((data[7] << 8) + data[6]) & 0x3FFF;
  30. *height = ((data[9] << 8) + data[8]) & 0x3FFF;
  31. }
  32. }
  33. } // namespace
  34. FakeVp8Decoder::FakeVp8Decoder() : callback_(nullptr), width_(0), height_(0) {}
  35. int32_t FakeVp8Decoder::InitDecode(const VideoCodec* config,
  36. int32_t number_of_cores) {
  37. return WEBRTC_VIDEO_CODEC_OK;
  38. }
  39. int32_t FakeVp8Decoder::Decode(const EncodedImage& input,
  40. bool missing_frames,
  41. int64_t render_time_ms) {
  42. constexpr size_t kMinPayLoadHeaderLength = 10;
  43. if (input.size() < kMinPayLoadHeaderLength) {
  44. return WEBRTC_VIDEO_CODEC_ERROR;
  45. }
  46. ParseFakeVp8(input.data(), &width_, &height_);
  47. VideoFrame frame =
  48. VideoFrame::Builder()
  49. .set_video_frame_buffer(I420Buffer::Create(width_, height_))
  50. .set_rotation(webrtc::kVideoRotation_0)
  51. .set_timestamp_ms(render_time_ms)
  52. .build();
  53. frame.set_timestamp(input.Timestamp());
  54. frame.set_ntp_time_ms(input.ntp_time_ms_);
  55. callback_->Decoded(frame, /*decode_time_ms=*/absl::nullopt,
  56. /*qp=*/absl::nullopt);
  57. return WEBRTC_VIDEO_CODEC_OK;
  58. }
  59. int32_t FakeVp8Decoder::RegisterDecodeCompleteCallback(
  60. DecodedImageCallback* callback) {
  61. callback_ = callback;
  62. return WEBRTC_VIDEO_CODEC_OK;
  63. }
  64. int32_t FakeVp8Decoder::Release() {
  65. return WEBRTC_VIDEO_CODEC_OK;
  66. }
  67. const char* FakeVp8Decoder::kImplementationName = "fake_vp8_decoder";
  68. const char* FakeVp8Decoder::ImplementationName() const {
  69. return kImplementationName;
  70. }
  71. } // namespace test
  72. } // namespace webrtc