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.9 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 "media/base/fake_frame_source.h"
  11. #include "api/scoped_refptr.h"
  12. #include "api/video/i420_buffer.h"
  13. #include "api/video/video_frame_buffer.h"
  14. #include "rtc_base/checks.h"
  15. #include "rtc_base/time_utils.h"
  16. namespace cricket {
  17. FakeFrameSource::FakeFrameSource(int width,
  18. int height,
  19. int interval_us,
  20. int64_t timestamp_offset_us)
  21. : width_(width),
  22. height_(height),
  23. interval_us_(interval_us),
  24. next_timestamp_us_(timestamp_offset_us) {
  25. RTC_CHECK_GT(width_, 0);
  26. RTC_CHECK_GT(height_, 0);
  27. RTC_CHECK_GT(interval_us_, 0);
  28. RTC_CHECK_GE(next_timestamp_us_, 0);
  29. }
  30. FakeFrameSource::FakeFrameSource(int width, int height, int interval_us)
  31. : FakeFrameSource(width, height, interval_us, rtc::TimeMicros()) {}
  32. webrtc::VideoRotation FakeFrameSource::GetRotation() const {
  33. return rotation_;
  34. }
  35. void FakeFrameSource::SetRotation(webrtc::VideoRotation rotation) {
  36. rotation_ = rotation;
  37. }
  38. webrtc::VideoFrame FakeFrameSource::GetFrameRotationApplied() {
  39. switch (rotation_) {
  40. case webrtc::kVideoRotation_0:
  41. case webrtc::kVideoRotation_180:
  42. return GetFrame(width_, height_, webrtc::kVideoRotation_0, interval_us_);
  43. case webrtc::kVideoRotation_90:
  44. case webrtc::kVideoRotation_270:
  45. return GetFrame(height_, width_, webrtc::kVideoRotation_0, interval_us_);
  46. }
  47. RTC_NOTREACHED() << "Invalid rotation value: " << static_cast<int>(rotation_);
  48. // Without this return, the Windows Visual Studio compiler complains
  49. // "not all control paths return a value".
  50. return GetFrame();
  51. }
  52. webrtc::VideoFrame FakeFrameSource::GetFrame() {
  53. return GetFrame(width_, height_, rotation_, interval_us_);
  54. }
  55. webrtc::VideoFrame FakeFrameSource::GetFrame(int width,
  56. int height,
  57. webrtc::VideoRotation rotation,
  58. int interval_us) {
  59. RTC_CHECK_GT(width, 0);
  60. RTC_CHECK_GT(height, 0);
  61. RTC_CHECK_GT(interval_us, 0);
  62. rtc::scoped_refptr<webrtc::I420Buffer> buffer(
  63. webrtc::I420Buffer::Create(width, height));
  64. buffer->InitializeData();
  65. webrtc::VideoFrame frame = webrtc::VideoFrame::Builder()
  66. .set_video_frame_buffer(buffer)
  67. .set_rotation(rotation)
  68. .set_timestamp_us(next_timestamp_us_)
  69. .build();
  70. next_timestamp_us_ += interval_us;
  71. return frame;
  72. }
  73. } // namespace cricket