blob: a3295e1ff38dbdc1249e1c63f23efa2a96053340 [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
37 // Must returns a JSON string "{{width=xxx, height=xxx, framerate = xxx}}"
38 virtual std::string GetSupportedFormats() = 0;
39};
40
41// Android implementation of cricket::VideoCapturer for use with WebRtc
42// PeerConnection.
43class AndroidVideoCapturer : public cricket::VideoCapturer {
44 public:
45 explicit AndroidVideoCapturer(
Per33544192015-04-02 12:30:51 +020046 const rtc::scoped_refptr<AndroidVideoCapturerDelegate>& delegate);
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000047 virtual ~AndroidVideoCapturer();
48
perkj@webrtc.org112f1272015-02-25 09:20:07 +000049 // Called from JNI when the capturer has been started.
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000050 void OnCapturerStarted(bool success);
51
perkj@webrtc.org112f1272015-02-25 09:20:07 +000052 // Called from JNI when a new frame has been captured.
Magnus Jedvertc464f502015-08-25 23:22:08 +020053 // Argument |buffer| is intentionally by value, for use with rtc::Bind.
olka30a5b5e2015-10-20 11:04:56 -070054 void OnIncomingFrame(
55 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer,
56 int rotation,
57 int64_t time_stamp);
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000058
Åsa Persson2b679252015-06-15 09:53:05 +020059 // Called from JNI to request a new video format.
60 void OnOutputFormatRequest(int width, int height, int fps);
61
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000062 AndroidVideoCapturerDelegate* delegate() { return delegate_.get(); }
63
Magnus Jedvert6ec1f922015-08-28 11:40:59 +020064 // cricket::VideoCapturer implementation.
65 bool GetBestCaptureFormat(const cricket::VideoFormat& desired,
66 cricket::VideoFormat* best_format) override;
67
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000068 private:
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000069 // cricket::VideoCapturer implementation.
70 // Video frames will be delivered using
71 // cricket::VideoCapturer::SignalFrameCaptured on the thread that calls Start.
72 cricket::CaptureState Start(
73 const cricket::VideoFormat& capture_format) override;
74 void Stop() override;
75 bool IsRunning() override;
76 bool IsScreencast() const override { return false; }
Peter Boström0c4e06b2015-10-07 12:23:21 +020077 bool GetPreferredFourccs(std::vector<uint32_t>* fourccs) override;
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000078
79 bool running_;
Per33544192015-04-02 12:30:51 +020080 rtc::scoped_refptr<AndroidVideoCapturerDelegate> delegate_;
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000081
Per33544192015-04-02 12:30:51 +020082 rtc::ThreadChecker thread_checker_;
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000083
84 class FrameFactory;
85 FrameFactory* frame_factory_; // Owned by cricket::VideoCapturer.
perkj@webrtc.org8f605e82015-02-17 13:53:56 +000086
87 cricket::CaptureState current_state_;
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000088};
89
90} // namespace webrtc
91
Henrik Kjellander15583c12016-02-10 10:53:12 +010092#endif // WEBRTC_API_ANDROIDVIDEOCAPTURER_H_