tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

fake_frame_source.cc (2885B)


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