blob: 5ce0462cff12a258fcbbbe7b68d3f34fcbaaf4c8 [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
magjed39607c92016-07-14 08:12:17 -070016#include "webrtc/common_video/include/i420_buffer_pool.h"
kjellandera96e2d72016-02-04 23:52:28 -080017#include "webrtc/media/base/videocapturer.h"
Jon Hjelle7ac8bab2016-01-21 11:44:55 -080018#include "webrtc/video_frame.h"
19
Jon Hjelle7ac8bab2016-01-21 11:44:55 -080020@class RTCAVFoundationVideoCapturerInternal;
21
Niels Möller505945a2016-03-17 12:20:41 +010022namespace rtc {
23class Thread;
24} // namespace rtc
25
Jon Hjelle7ac8bab2016-01-21 11:44:55 -080026namespace webrtc {
27
tkchin89717aa2016-03-31 17:14:04 -070028class AVFoundationVideoCapturer : public cricket::VideoCapturer,
29 public rtc::MessageHandler {
Jon Hjelle7ac8bab2016-01-21 11:44:55 -080030 public:
31 AVFoundationVideoCapturer();
32 ~AVFoundationVideoCapturer();
33
34 cricket::CaptureState Start(const cricket::VideoFormat& format) override;
35 void Stop() override;
36 bool IsRunning() override;
37 bool IsScreencast() const override {
38 return false;
39 }
40 bool GetPreferredFourccs(std::vector<uint32_t> *fourccs) override {
41 fourccs->push_back(cricket::FOURCC_NV12);
42 return true;
43 }
44
tkchin89717aa2016-03-31 17:14:04 -070045 // Returns the active capture session. Calls to the capture session should
46 // occur on the RTCDispatcherTypeCaptureSession queue in RTCDispatcher.
Jon Hjelle7ac8bab2016-01-21 11:44:55 -080047 AVCaptureSession* GetCaptureSession();
48
tkchin89717aa2016-03-31 17:14:04 -070049 // Returns whether the rear-facing camera can be used.
50 // e.g. It can't be used because it doesn't exist.
hjona1cf3662016-03-14 20:55:22 -070051 bool CanUseBackCamera() const;
52
tkchin89717aa2016-03-31 17:14:04 -070053 // Switches the camera being used (either front or back).
Jon Hjelle7ac8bab2016-01-21 11:44:55 -080054 void SetUseBackCamera(bool useBackCamera);
55 bool GetUseBackCamera() const;
56
tkchin89717aa2016-03-31 17:14:04 -070057 // Converts the sample buffer into a cricket::CapturedFrame and signals the
58 // frame for capture.
magjed2ab012c2016-08-25 03:25:04 -070059 void CaptureSampleBuffer(CMSampleBufferRef sample_buffer,
60 webrtc::VideoRotation rotation);
Jon Hjelle7ac8bab2016-01-21 11:44:55 -080061
tkchin89717aa2016-03-31 17:14:04 -070062 // Handles messages from posts.
63 void OnMessage(rtc::Message *msg) override;
64
Jon Hjelle7ac8bab2016-01-21 11:44:55 -080065 private:
magjed2ab012c2016-08-25 03:25:04 -070066 void OnFrameMessage(CVImageBufferRef image_buffer,
67 webrtc::VideoRotation rotation,
68 int64_t capture_time_ns);
Jon Hjelle7ac8bab2016-01-21 11:44:55 -080069
70 RTCAVFoundationVideoCapturerInternal *_capturer;
71 rtc::Thread *_startThread; // Set in Start(), unset in Stop().
magjed39607c92016-07-14 08:12:17 -070072 webrtc::I420BufferPool _buffer_pool;
Jon Hjelle7ac8bab2016-01-21 11:44:55 -080073}; // AVFoundationVideoCapturer
74
75} // namespace webrtc
76
tkchin89717aa2016-03-31 17:14:04 -070077#endif // WEBRTC_API_OBJC_AVFOUNDATION_VIDEO_CAPTURER_H_