blob: 4c73f3159874e76323fdee76a04702c6d575969d [file] [log] [blame]
perkj@webrtc.org83bc7212015-02-11 11:26:56 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
perkj@webrtc.org83bc7212015-02-11 11:26:56 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.
perkj@webrtc.org83bc7212015-02-11 11:26:56 +00009 */
Henrik Kjellander15583c12016-02-10 10:53:12 +010010
11#ifndef WEBRTC_API_ANDROIDVIDEOCAPTURER_H_
12#define WEBRTC_API_ANDROIDVIDEOCAPTURER_H_
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000013
14#include <string>
15#include <vector>
16
Per33544192015-04-02 12:30:51 +020017#include "webrtc/base/thread_checker.h"
kjellander6f8ce062015-11-16 13:52:24 -080018#include "webrtc/common_video/include/video_frame_buffer.h"
kjellandera96e2d72016-02-04 23:52:28 -080019#include "webrtc/media/base/videocapturer.h"
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000020
21namespace webrtc {
22
23class AndroidVideoCapturer;
24
Per33544192015-04-02 12:30:51 +020025class AndroidVideoCapturerDelegate : public rtc::RefCountInterface {
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000026 public:
27 virtual ~AndroidVideoCapturerDelegate() {}
28 // Start capturing. The implementation of the delegate must call
29 // AndroidVideoCapturer::OnCapturerStarted with the result of this request.
30 virtual void Start(int width, int height, int framerate,
31 AndroidVideoCapturer* capturer) = 0;
32
perkj@webrtc.org3db042e2015-02-19 08:43:38 +000033 // Stops capturing.
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000034 // The delegate may not call into AndroidVideoCapturer after this call.
perkj@webrtc.org3db042e2015-02-19 08:43:38 +000035 virtual void Stop() = 0;
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000036
Magnus Jedvert5199c742016-02-18 13:09:54 +010037 virtual std::vector<cricket::VideoFormat> GetSupportedFormats() = 0;
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000038};
39
40// Android implementation of cricket::VideoCapturer for use with WebRtc
41// PeerConnection.
42class AndroidVideoCapturer : public cricket::VideoCapturer {
43 public:
44 explicit AndroidVideoCapturer(
Per33544192015-04-02 12:30:51 +020045 const rtc::scoped_refptr<AndroidVideoCapturerDelegate>& delegate);
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000046 virtual ~AndroidVideoCapturer();
47
perkj@webrtc.org112f1272015-02-25 09:20:07 +000048 // Called from JNI when the capturer has been started.
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000049 void OnCapturerStarted(bool success);
50
perkj@webrtc.org112f1272015-02-25 09:20:07 +000051 // Called from JNI when a new frame has been captured.
Magnus Jedvertc464f502015-08-25 23:22:08 +020052 // Argument |buffer| is intentionally by value, for use with rtc::Bind.
olka30a5b5e2015-10-20 11:04:56 -070053 void OnIncomingFrame(
54 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer,
55 int rotation,
56 int64_t time_stamp);
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000057
Åsa Persson2b679252015-06-15 09:53:05 +020058 // Called from JNI to request a new video format.
59 void OnOutputFormatRequest(int width, int height, int fps);
60
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000061 AndroidVideoCapturerDelegate* delegate() { return delegate_.get(); }
62
Magnus Jedvert6ec1f922015-08-28 11:40:59 +020063 // cricket::VideoCapturer implementation.
64 bool GetBestCaptureFormat(const cricket::VideoFormat& desired,
65 cricket::VideoFormat* best_format) override;
66
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000067 private:
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000068 // cricket::VideoCapturer implementation.
69 // Video frames will be delivered using
70 // cricket::VideoCapturer::SignalFrameCaptured on the thread that calls Start.
71 cricket::CaptureState Start(
72 const cricket::VideoFormat& capture_format) override;
73 void Stop() override;
74 bool IsRunning() override;
75 bool IsScreencast() const override { return false; }
Peter Boström0c4e06b2015-10-07 12:23:21 +020076 bool GetPreferredFourccs(std::vector<uint32_t>* fourccs) override;
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000077
78 bool running_;
Per33544192015-04-02 12:30:51 +020079 rtc::scoped_refptr<AndroidVideoCapturerDelegate> delegate_;
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000080
Per33544192015-04-02 12:30:51 +020081 rtc::ThreadChecker thread_checker_;
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000082
83 class FrameFactory;
84 FrameFactory* frame_factory_; // Owned by cricket::VideoCapturer.
perkj@webrtc.org8f605e82015-02-17 13:53:56 +000085
86 cricket::CaptureState current_state_;
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000087};
88
89} // namespace webrtc
90
Henrik Kjellander15583c12016-02-10 10:53:12 +010091#endif // WEBRTC_API_ANDROIDVIDEOCAPTURER_H_