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" |
Per | 3354419 | 2015-04-02 12:30:51 +0200 | [diff] [blame] | 34 | #include "webrtc/base/thread_checker.h" |
perkj@webrtc.org | 83bc721 | 2015-02-11 11:26:56 +0000 | [diff] [blame] | 35 | |
| 36 | namespace webrtc { |
| 37 | |
| 38 | class AndroidVideoCapturer; |
| 39 | |
Per | 3354419 | 2015-04-02 12:30:51 +0200 | [diff] [blame] | 40 | class AndroidVideoCapturerDelegate : public rtc::RefCountInterface { |
perkj@webrtc.org | 83bc721 | 2015-02-11 11:26:56 +0000 | [diff] [blame] | 41 | public: |
| 42 | virtual ~AndroidVideoCapturerDelegate() {} |
| 43 | // Start capturing. The implementation of the delegate must call |
| 44 | // AndroidVideoCapturer::OnCapturerStarted with the result of this request. |
| 45 | virtual void Start(int width, int height, int framerate, |
| 46 | AndroidVideoCapturer* capturer) = 0; |
| 47 | |
perkj@webrtc.org | 3db042e | 2015-02-19 08:43:38 +0000 | [diff] [blame] | 48 | // Stops capturing. |
perkj@webrtc.org | 83bc721 | 2015-02-11 11:26:56 +0000 | [diff] [blame] | 49 | // The delegate may not call into AndroidVideoCapturer after this call. |
perkj@webrtc.org | 3db042e | 2015-02-19 08:43:38 +0000 | [diff] [blame] | 50 | virtual void Stop() = 0; |
perkj@webrtc.org | 83bc721 | 2015-02-11 11:26:56 +0000 | [diff] [blame] | 51 | |
perkj@webrtc.org | 112f127 | 2015-02-25 09:20:07 +0000 | [diff] [blame] | 52 | // Notify that a frame received in OnIncomingFrame with |time_stamp| has been |
Per | 3354419 | 2015-04-02 12:30:51 +0200 | [diff] [blame] | 53 | // processed and can be returned. May be called on an arbitrary thread. |
perkj@webrtc.org | 112f127 | 2015-02-25 09:20:07 +0000 | [diff] [blame] | 54 | virtual void ReturnBuffer(int64 time_stamp) = 0; |
| 55 | |
perkj@webrtc.org | 83bc721 | 2015-02-11 11:26:56 +0000 | [diff] [blame] | 56 | // Must returns a JSON string "{{width=xxx, height=xxx, framerate = xxx}}" |
| 57 | virtual std::string GetSupportedFormats() = 0; |
| 58 | }; |
| 59 | |
| 60 | // Android implementation of cricket::VideoCapturer for use with WebRtc |
| 61 | // PeerConnection. |
| 62 | class AndroidVideoCapturer : public cricket::VideoCapturer { |
| 63 | public: |
| 64 | explicit AndroidVideoCapturer( |
Per | 3354419 | 2015-04-02 12:30:51 +0200 | [diff] [blame] | 65 | const rtc::scoped_refptr<AndroidVideoCapturerDelegate>& delegate); |
perkj@webrtc.org | 83bc721 | 2015-02-11 11:26:56 +0000 | [diff] [blame] | 66 | virtual ~AndroidVideoCapturer(); |
| 67 | |
perkj@webrtc.org | 112f127 | 2015-02-25 09:20:07 +0000 | [diff] [blame] | 68 | // Called from JNI when the capturer has been started. |
perkj@webrtc.org | 83bc721 | 2015-02-11 11:26:56 +0000 | [diff] [blame] | 69 | void OnCapturerStarted(bool success); |
| 70 | |
perkj@webrtc.org | 112f127 | 2015-02-25 09:20:07 +0000 | [diff] [blame] | 71 | // Called from JNI when a new frame has been captured. |
| 72 | void OnIncomingFrame(void* video_frame, |
perkj@webrtc.org | 83bc721 | 2015-02-11 11:26:56 +0000 | [diff] [blame] | 73 | int length, |
magjed | b69ab79 | 2015-07-22 02:32:00 -0700 | [diff] [blame] | 74 | int width, |
| 75 | int height, |
perkj@webrtc.org | 83bc721 | 2015-02-11 11:26:56 +0000 | [diff] [blame] | 76 | int rotation, |
| 77 | int64 time_stamp); |
| 78 | |
Åsa Persson | 2b67925 | 2015-06-15 09:53:05 +0200 | [diff] [blame] | 79 | // Called from JNI to request a new video format. |
| 80 | void OnOutputFormatRequest(int width, int height, int fps); |
| 81 | |
perkj@webrtc.org | 83bc721 | 2015-02-11 11:26:56 +0000 | [diff] [blame] | 82 | AndroidVideoCapturerDelegate* delegate() { return delegate_.get(); } |
| 83 | |
| 84 | private: |
perkj@webrtc.org | 83bc721 | 2015-02-11 11:26:56 +0000 | [diff] [blame] | 85 | // cricket::VideoCapturer implementation. |
| 86 | // Video frames will be delivered using |
| 87 | // cricket::VideoCapturer::SignalFrameCaptured on the thread that calls Start. |
| 88 | cricket::CaptureState Start( |
| 89 | const cricket::VideoFormat& capture_format) override; |
| 90 | void Stop() override; |
| 91 | bool IsRunning() override; |
| 92 | bool IsScreencast() const override { return false; } |
| 93 | bool GetPreferredFourccs(std::vector<uint32>* fourccs) override; |
| 94 | |
| 95 | bool running_; |
Per | 3354419 | 2015-04-02 12:30:51 +0200 | [diff] [blame] | 96 | rtc::scoped_refptr<AndroidVideoCapturerDelegate> delegate_; |
perkj@webrtc.org | 83bc721 | 2015-02-11 11:26:56 +0000 | [diff] [blame] | 97 | |
Per | 3354419 | 2015-04-02 12:30:51 +0200 | [diff] [blame] | 98 | rtc::ThreadChecker thread_checker_; |
perkj@webrtc.org | 83bc721 | 2015-02-11 11:26:56 +0000 | [diff] [blame] | 99 | |
| 100 | class FrameFactory; |
| 101 | FrameFactory* frame_factory_; // Owned by cricket::VideoCapturer. |
perkj@webrtc.org | 8f605e8 | 2015-02-17 13:53:56 +0000 | [diff] [blame] | 102 | |
| 103 | cricket::CaptureState current_state_; |
perkj@webrtc.org | 83bc721 | 2015-02-11 11:26:56 +0000 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | } // namespace webrtc |
| 107 | |
| 108 | #endif // TALK_APP_WEBRTC_ANDROIDVIDEOCAPTURER_H_ |