blob: ed31cd2e166e490cf92ec0b25655769a28119dc8 [file] [log] [blame]
perkj@webrtc.org83bc7212015-02-11 11:26:56 +00001/*
2 * libjingle
3 * Copyright 2015 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27#ifndef TALK_APP_WEBRTC_ANDROIDVIDEOCAPTURER_H_
28#define TALK_APP_WEBRTC_ANDROIDVIDEOCAPTURER_H_
29
30#include <string>
31#include <vector>
32
33#include "talk/media/base/videocapturer.h"
34
35namespace webrtc {
36
37class AndroidVideoCapturer;
38
39class AndroidVideoCapturerDelegate {
40 public:
41 virtual ~AndroidVideoCapturerDelegate() {}
42 // Start capturing. The implementation of the delegate must call
43 // AndroidVideoCapturer::OnCapturerStarted with the result of this request.
44 virtual void Start(int width, int height, int framerate,
45 AndroidVideoCapturer* capturer) = 0;
46
perkj@webrtc.org3db042e2015-02-19 08:43:38 +000047 // Stops capturing.
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000048 // The delegate may not call into AndroidVideoCapturer after this call.
perkj@webrtc.org3db042e2015-02-19 08:43:38 +000049 virtual void Stop() = 0;
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000050
51 // Must returns a JSON string "{{width=xxx, height=xxx, framerate = xxx}}"
52 virtual std::string GetSupportedFormats() = 0;
53};
54
55// Android implementation of cricket::VideoCapturer for use with WebRtc
56// PeerConnection.
57class AndroidVideoCapturer : public cricket::VideoCapturer {
58 public:
59 explicit AndroidVideoCapturer(
60 rtc::scoped_ptr<AndroidVideoCapturerDelegate> delegate);
61 virtual ~AndroidVideoCapturer();
62
63 // Called from JNI when the capturer has been started. Called from a Java
64 // thread.
65 void OnCapturerStarted(bool success);
66
67 // Called from JNI when a new frame has been captured. Called from a Java
68 // thread.
69 void OnIncomingFrame(signed char* videoFrame,
70 int length,
71 int rotation,
72 int64 time_stamp);
73
74 AndroidVideoCapturerDelegate* delegate() { return delegate_.get(); }
75
76 private:
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000077 // cricket::VideoCapturer implementation.
78 // Video frames will be delivered using
79 // cricket::VideoCapturer::SignalFrameCaptured on the thread that calls Start.
80 cricket::CaptureState Start(
81 const cricket::VideoFormat& capture_format) override;
82 void Stop() override;
83 bool IsRunning() override;
84 bool IsScreencast() const override { return false; }
85 bool GetPreferredFourccs(std::vector<uint32>* fourccs) override;
86
87 bool running_;
88 rtc::scoped_ptr<AndroidVideoCapturerDelegate> delegate_;
89
90 // |worker_thread_| is the thread that calls Start and is used for
91 // communication with the Java capturer.
92 // Video frames are delivered to cricket::VideoCapturer::SignalFrameCaptured
93 // on this thread.
94 rtc::Thread* worker_thread_;
95
96 class FrameFactory;
97 FrameFactory* frame_factory_; // Owned by cricket::VideoCapturer.
perkj@webrtc.org8f605e82015-02-17 13:53:56 +000098
99 cricket::CaptureState current_state_;
perkj@webrtc.org83bc7212015-02-11 11:26:56 +0000100};
101
102} // namespace webrtc
103
104#endif // TALK_APP_WEBRTC_ANDROIDVIDEOCAPTURER_H_