blob: 380313bf79ef107738385c7a1bb4b2ded29b93e4 [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
perkj@webrtc.org112f1272015-02-25 09:20:07 +000051 // Notify that a frame received in OnIncomingFrame with |time_stamp| has been
52 // processed and can be returned.
53 virtual void ReturnBuffer(int64 time_stamp) = 0;
54
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000055 // Must returns a JSON string "{{width=xxx, height=xxx, framerate = xxx}}"
56 virtual std::string GetSupportedFormats() = 0;
57};
58
59// Android implementation of cricket::VideoCapturer for use with WebRtc
60// PeerConnection.
61class AndroidVideoCapturer : public cricket::VideoCapturer {
62 public:
63 explicit AndroidVideoCapturer(
64 rtc::scoped_ptr<AndroidVideoCapturerDelegate> delegate);
65 virtual ~AndroidVideoCapturer();
66
perkj@webrtc.org112f1272015-02-25 09:20:07 +000067 // Called from JNI when the capturer has been started.
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000068 void OnCapturerStarted(bool success);
69
perkj@webrtc.org112f1272015-02-25 09:20:07 +000070 // Called from JNI when a new frame has been captured.
71 void OnIncomingFrame(void* video_frame,
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000072 int length,
73 int rotation,
74 int64 time_stamp);
75
76 AndroidVideoCapturerDelegate* delegate() { return delegate_.get(); }
77
78 private:
perkj@webrtc.org83bc7212015-02-11 11:26:56 +000079 // cricket::VideoCapturer implementation.
80 // Video frames will be delivered using
81 // cricket::VideoCapturer::SignalFrameCaptured on the thread that calls Start.
82 cricket::CaptureState Start(
83 const cricket::VideoFormat& capture_format) override;
84 void Stop() override;
85 bool IsRunning() override;
86 bool IsScreencast() const override { return false; }
87 bool GetPreferredFourccs(std::vector<uint32>* fourccs) override;
88
89 bool running_;
90 rtc::scoped_ptr<AndroidVideoCapturerDelegate> delegate_;
91
92 // |worker_thread_| is the thread that calls Start and is used for
93 // communication with the Java capturer.
94 // Video frames are delivered to cricket::VideoCapturer::SignalFrameCaptured
95 // on this thread.
96 rtc::Thread* worker_thread_;
97
98 class FrameFactory;
99 FrameFactory* frame_factory_; // Owned by cricket::VideoCapturer.
perkj@webrtc.org8f605e82015-02-17 13:53:56 +0000100
101 cricket::CaptureState current_state_;
perkj@webrtc.org83bc7212015-02-11 11:26:56 +0000102};
103
104} // namespace webrtc
105
106#endif // TALK_APP_WEBRTC_ANDROIDVIDEOCAPTURER_H_