blob: 24294efc13fac415dfb71120a650a1336865e8d3 [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
Åsa Persson2b679252015-06-15 09:53:05 +020051 // Called from JNI to request a new video format.
52 void OnOutputFormatRequest(int width, int height, int fps);
53
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000054 AndroidVideoCapturerDelegate* delegate() { return delegate_.get(); }
55
Magnus Jedvert6ec1f922015-08-28 11:40:59 +020056 // cricket::VideoCapturer implementation.
57 bool GetBestCaptureFormat(const cricket::VideoFormat& desired,
58 cricket::VideoFormat* best_format) override;
59
nisse47ac4622016-05-25 08:47:01 -070060 // Expose these protected methods as public, to be used by the
61 // AndroidVideoCapturerJni.
62 using VideoCapturer::AdaptFrame;
63 using VideoCapturer::OnFrame;
64
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000065 private:
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000066 // cricket::VideoCapturer implementation.
67 // Video frames will be delivered using
68 // cricket::VideoCapturer::SignalFrameCaptured on the thread that calls Start.
69 cricket::CaptureState Start(
70 const cricket::VideoFormat& capture_format) override;
71 void Stop() override;
72 bool IsRunning() override;
73 bool IsScreencast() const override { return false; }
Peter Boström0c4e06b2015-10-07 12:23:21 +020074 bool GetPreferredFourccs(std::vector<uint32_t>* fourccs) override;
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000075
76 bool running_;
Per33544192015-04-02 12:30:51 +020077 rtc::scoped_refptr<AndroidVideoCapturerDelegate> delegate_;
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000078
Per33544192015-04-02 12:30:51 +020079 rtc::ThreadChecker thread_checker_;
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000080};
81
82} // namespace webrtc
83
Henrik Kjellander15583c12016-02-10 10:53:12 +010084#endif // WEBRTC_API_ANDROIDVIDEOCAPTURER_H_