tor-browser

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

video_capture_avfoundation.h (3795B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef DOM_MEDIA_SYSTEMSERVICES_OBJC_VIDEO_CAPTURE_VIDEO_CAPTURE2_H_
      8 #define DOM_MEDIA_SYSTEMSERVICES_OBJC_VIDEO_CAPTURE_VIDEO_CAPTURE2_H_
      9 
     10 #import "components/capturer/RTCCameraVideoCapturer.h"
     11 
     12 #include "PerformanceRecorder.h"
     13 #include "api/scoped_refptr.h"
     14 #include "api/sequence_checker.h"
     15 #include "modules/video_capture/video_capture_impl.h"
     16 #include "mozilla/Maybe.h"
     17 #include "system_wrappers/include/clock.h"
     18 
     19 @class VideoCaptureAdapter;
     20 
     21 namespace webrtc::videocapturemodule {
     22 
     23 /**
     24 * VideoCaptureImpl implementation of the libwebrtc ios/mac sdk camera backend.
     25 * Single threaded except for OnFrame() that happens on a platform callback
     26 * thread.
     27 */
     28 class VideoCaptureAvFoundation : public VideoCaptureImpl {
     29 public:
     30  VideoCaptureAvFoundation(Clock* _Nonnull clock,
     31                           AVCaptureDevice* _Nonnull aDevice);
     32  virtual ~VideoCaptureAvFoundation();
     33 
     34  static webrtc::scoped_refptr<VideoCaptureModule> Create(
     35      Clock* _Nonnull clock, const char* _Nullable aDeviceUniqueIdUTF8);
     36 
     37  // Implementation of VideoCaptureImpl. Single threaded.
     38 
     39  // Starts capturing synchronously. Idempotent. If an existing capture is live
     40  // and another capability is requested we'll restart the underlying backend
     41  // with the new capability.
     42  int32_t StartCapture(const VideoCaptureCapability& aCapability)
     43      MOZ_EXCLUDES(api_lock_) override;
     44  // Stops capturing synchronously. Idempotent.
     45  int32_t StopCapture() MOZ_EXCLUDES(api_lock_) override;
     46  bool CaptureStarted() MOZ_EXCLUDES(api_lock_) override;
     47  int32_t CaptureSettings(VideoCaptureCapability& aSettings) override;
     48 
     49  // Callback. This can be called on any thread.
     50  int32_t OnFrame(__strong RTCVideoFrame* _Nonnull aFrame)
     51      MOZ_EXCLUDES(api_lock_);
     52 
     53  void SetTrackingId(uint32_t aTrackingIdProcId)
     54      MOZ_EXCLUDES(api_lock_) override;
     55 
     56  // Registers the current thread with the profiler if not already registered.
     57  void MaybeRegisterCallbackThread();
     58 
     59 private:
     60  // Control thread checker.
     61  SequenceChecker mChecker;
     62  AVCaptureDevice* _Nonnull const mDevice RTC_GUARDED_BY(mChecker);
     63  VideoCaptureAdapter* _Nonnull const mAdapter RTC_GUARDED_BY(mChecker);
     64  RTCCameraVideoCapturer* _Nonnull const mCapturer RTC_GUARDED_BY(mChecker);
     65  // If capture has started, this is the capability it was started for. Written
     66  // on the mChecker thread only.
     67  mozilla::Maybe<VideoCaptureCapability> mCapability MOZ_GUARDED_BY(api_lock_);
     68  // The image type that mCapability maps to. Set in lockstep with mCapability.
     69  mozilla::Maybe<mozilla::CaptureStage::ImageType> mImageType
     70      MOZ_GUARDED_BY(api_lock_);
     71  // Id string uniquely identifying this capture source. Written on the mChecker
     72  // thread only.
     73  mozilla::Maybe<mozilla::TrackingId> mTrackingId MOZ_GUARDED_BY(api_lock_);
     74  // Adds frame specific markers to the profiler while mTrackingId is set.
     75  // Callback thread only.
     76  mozilla::PerformanceRecorderMulti<mozilla::CaptureStage> mCaptureRecorder;
     77  mozilla::PerformanceRecorderMulti<mozilla::CopyVideoStage>
     78      mConversionRecorder;
     79  std::atomic<ProfilerThreadId> mCallbackThreadId;
     80 };
     81 
     82 }  // namespace webrtc::videocapturemodule
     83 
     84 @interface VideoCaptureAdapter : NSObject <RTCVideoCapturerDelegate> {
     85  webrtc::Mutex _mutex;
     86  webrtc::videocapturemodule::VideoCaptureAvFoundation* _Nullable _capturer
     87      RTC_GUARDED_BY(_mutex);
     88 }
     89 - (void)setCapturer:
     90    (webrtc::videocapturemodule::VideoCaptureAvFoundation* _Nullable)capturer;
     91 @end
     92 
     93 #endif