perkj@webrtc.org | 83bc721 | 2015-02-11 11:26:56 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 35 | namespace webrtc { |
| 36 | |
| 37 | class AndroidVideoCapturer; |
| 38 | |
| 39 | class 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 | |
| 47 | // Stops capturing. The implementation must synchronously stop the capturer. |
| 48 | // The delegate may not call into AndroidVideoCapturer after this call. |
| 49 | virtual bool Stop() = 0; |
| 50 | |
| 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. |
| 57 | class 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: |
| 77 | void OnCapturerStarted_w(bool success); |
| 78 | |
| 79 | void OnIncomingFrame_w(signed char* frame_data, |
| 80 | int length, |
| 81 | int rotation, |
| 82 | int64 time_stamp); |
| 83 | |
| 84 | // cricket::VideoCapturer implementation. |
| 85 | // Video frames will be delivered using |
| 86 | // cricket::VideoCapturer::SignalFrameCaptured on the thread that calls Start. |
| 87 | cricket::CaptureState Start( |
| 88 | const cricket::VideoFormat& capture_format) override; |
| 89 | void Stop() override; |
| 90 | bool IsRunning() override; |
| 91 | bool IsScreencast() const override { return false; } |
| 92 | bool GetPreferredFourccs(std::vector<uint32>* fourccs) override; |
| 93 | |
| 94 | bool running_; |
| 95 | rtc::scoped_ptr<AndroidVideoCapturerDelegate> delegate_; |
| 96 | |
| 97 | // |worker_thread_| is the thread that calls Start and is used for |
| 98 | // communication with the Java capturer. |
| 99 | // Video frames are delivered to cricket::VideoCapturer::SignalFrameCaptured |
| 100 | // on this thread. |
| 101 | rtc::Thread* worker_thread_; |
| 102 | |
| 103 | class FrameFactory; |
| 104 | FrameFactory* frame_factory_; // Owned by cricket::VideoCapturer. |
perkj@webrtc.org | 8f605e8 | 2015-02-17 13:53:56 +0000 | [diff] [blame^] | 105 | |
| 106 | cricket::CaptureState current_state_; |
perkj@webrtc.org | 83bc721 | 2015-02-11 11:26:56 +0000 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | } // namespace webrtc |
| 110 | |
| 111 | #endif // TALK_APP_WEBRTC_ANDROIDVIDEOCAPTURER_H_ |