blob: c523b527bbb0de88ee9adf88139e4d8348bbf1cd [file] [log] [blame]
Jon Hjelle7ac8bab2016-01-21 11:44:55 -08001/*
2 * Copyright 2015 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#ifndef WEBRTC_API_OBJC_AVFOUNDATION_VIDEO_CAPTURER_H_
12#define WEBRTC_API_OBJC_AVFOUNDATION_VIDEO_CAPTURER_H_
13
tkchin9eeb6242016-04-27 01:54:20 -070014#import <AVFoundation/AVFoundation.h>
15
kjellandera96e2d72016-02-04 23:52:28 -080016#include "webrtc/media/base/videocapturer.h"
Jon Hjelle7ac8bab2016-01-21 11:44:55 -080017#include "webrtc/video_frame.h"
18
Jon Hjelle7ac8bab2016-01-21 11:44:55 -080019@class RTCAVFoundationVideoCapturerInternal;
20
Niels Möller505945a2016-03-17 12:20:41 +010021namespace rtc {
22class Thread;
23} // namespace rtc
24
Jon Hjelle7ac8bab2016-01-21 11:44:55 -080025namespace webrtc {
26
tkchin89717aa2016-03-31 17:14:04 -070027class AVFoundationVideoCapturer : public cricket::VideoCapturer,
28 public rtc::MessageHandler {
Jon Hjelle7ac8bab2016-01-21 11:44:55 -080029 public:
30 AVFoundationVideoCapturer();
31 ~AVFoundationVideoCapturer();
32
33 cricket::CaptureState Start(const cricket::VideoFormat& format) override;
34 void Stop() override;
35 bool IsRunning() override;
36 bool IsScreencast() const override {
37 return false;
38 }
39 bool GetPreferredFourccs(std::vector<uint32_t> *fourccs) override {
40 fourccs->push_back(cricket::FOURCC_NV12);
41 return true;
42 }
43
tkchin89717aa2016-03-31 17:14:04 -070044 // Returns the active capture session. Calls to the capture session should
45 // occur on the RTCDispatcherTypeCaptureSession queue in RTCDispatcher.
Jon Hjelle7ac8bab2016-01-21 11:44:55 -080046 AVCaptureSession* GetCaptureSession();
47
tkchin89717aa2016-03-31 17:14:04 -070048 // Returns whether the rear-facing camera can be used.
49 // e.g. It can't be used because it doesn't exist.
hjona1cf3662016-03-14 20:55:22 -070050 bool CanUseBackCamera() const;
51
tkchin89717aa2016-03-31 17:14:04 -070052 // Switches the camera being used (either front or back).
Jon Hjelle7ac8bab2016-01-21 11:44:55 -080053 void SetUseBackCamera(bool useBackCamera);
54 bool GetUseBackCamera() const;
55
tkchin89717aa2016-03-31 17:14:04 -070056 // Converts the sample buffer into a cricket::CapturedFrame and signals the
57 // frame for capture.
Jon Hjelle7ac8bab2016-01-21 11:44:55 -080058 void CaptureSampleBuffer(CMSampleBufferRef sampleBuffer);
59
tkchin89717aa2016-03-31 17:14:04 -070060 // Handles messages from posts.
61 void OnMessage(rtc::Message *msg) override;
62
Jon Hjelle7ac8bab2016-01-21 11:44:55 -080063 private:
tkchin89717aa2016-03-31 17:14:04 -070064 void OnFrameMessage(CVImageBufferRef image_buffer, int64_t capture_time);
Jon Hjelle7ac8bab2016-01-21 11:44:55 -080065
66 RTCAVFoundationVideoCapturerInternal *_capturer;
67 rtc::Thread *_startThread; // Set in Start(), unset in Stop().
68}; // AVFoundationVideoCapturer
69
70} // namespace webrtc
71
tkchin89717aa2016-03-31 17:14:04 -070072#endif // WEBRTC_API_OBJC_AVFOUNDATION_VIDEO_CAPTURER_H_