183bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org/* 283bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org * libjingle 383bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org * Copyright 2015 Google Inc. 483bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org * 583bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org * Redistribution and use in source and binary forms, with or without 683bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org * modification, are permitted provided that the following conditions are met: 783bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org * 883bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org * 1. Redistributions of source code must retain the above copyright notice, 983bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org * this list of conditions and the following disclaimer. 1083bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org * 2. Redistributions in binary form must reproduce the above copyright notice, 1183bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org * this list of conditions and the following disclaimer in the documentation 1283bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org * and/or other materials provided with the distribution. 1383bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org * 3. The name of the author may not be used to endorse or promote products 1483bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org * derived from this software without specific prior written permission. 1583bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org * 1683bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 1783bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 1883bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 1983bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2083bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 2183bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 2283bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 2383bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 2483bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 2583bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2683bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org */ 2783bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org#ifndef TALK_APP_WEBRTC_ANDROIDVIDEOCAPTURER_H_ 2883bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org#define TALK_APP_WEBRTC_ANDROIDVIDEOCAPTURER_H_ 2983bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org 3083bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org#include <string> 3183bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org#include <vector> 3283bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org 3383bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org#include "talk/media/base/videocapturer.h" 343354419a2d53c3bfee8077cfbb0d86022b03e94aPer#include "webrtc/base/thread_checker.h" 356f8ce060a21fcdc1c951fbf06768eb0cc0083b2fkjellander#include "webrtc/common_video/include/video_frame_buffer.h" 3683bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org 3783bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.orgnamespace webrtc { 3883bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org 3983bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.orgclass AndroidVideoCapturer; 4083bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org 413354419a2d53c3bfee8077cfbb0d86022b03e94aPerclass AndroidVideoCapturerDelegate : public rtc::RefCountInterface { 4283bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org public: 4383bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org virtual ~AndroidVideoCapturerDelegate() {} 4483bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org // Start capturing. The implementation of the delegate must call 4583bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org // AndroidVideoCapturer::OnCapturerStarted with the result of this request. 4683bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org virtual void Start(int width, int height, int framerate, 4783bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org AndroidVideoCapturer* capturer) = 0; 4883bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org 493db042e2f09f1df7d8b5d40f30766f780848ecd9perkj@webrtc.org // Stops capturing. 5083bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org // The delegate may not call into AndroidVideoCapturer after this call. 513db042e2f09f1df7d8b5d40f30766f780848ecd9perkj@webrtc.org virtual void Stop() = 0; 5283bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org 5383bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org // Must returns a JSON string "{{width=xxx, height=xxx, framerate = xxx}}" 5483bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org virtual std::string GetSupportedFormats() = 0; 5583bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org}; 5683bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org 5783bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org// Android implementation of cricket::VideoCapturer for use with WebRtc 5883bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org// PeerConnection. 5983bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.orgclass AndroidVideoCapturer : public cricket::VideoCapturer { 6083bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org public: 6183bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org explicit AndroidVideoCapturer( 623354419a2d53c3bfee8077cfbb0d86022b03e94aPer const rtc::scoped_refptr<AndroidVideoCapturerDelegate>& delegate); 6383bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org virtual ~AndroidVideoCapturer(); 6483bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org 65112f127170193bf022565b112b03827c025168b6perkj@webrtc.org // Called from JNI when the capturer has been started. 6683bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org void OnCapturerStarted(bool success); 6783bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org 68112f127170193bf022565b112b03827c025168b6perkj@webrtc.org // Called from JNI when a new frame has been captured. 69c464f504dcb40ad40b5258875493f12783bd5fdaMagnus Jedvert // Argument |buffer| is intentionally by value, for use with rtc::Bind. 7030a5b5e9fb574016ced1a45ae43921c1a01860a0olka void OnIncomingFrame( 7130a5b5e9fb574016ced1a45ae43921c1a01860a0olka const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer, 7230a5b5e9fb574016ced1a45ae43921c1a01860a0olka int rotation, 7330a5b5e9fb574016ced1a45ae43921c1a01860a0olka int64_t time_stamp); 7483bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org 752b679250fbd50b3c8d9ac266a42fbc8a1bd84167Åsa Persson // Called from JNI to request a new video format. 762b679250fbd50b3c8d9ac266a42fbc8a1bd84167Åsa Persson void OnOutputFormatRequest(int width, int height, int fps); 772b679250fbd50b3c8d9ac266a42fbc8a1bd84167Åsa Persson 7883bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org AndroidVideoCapturerDelegate* delegate() { return delegate_.get(); } 7983bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org 806ec1f921b1186127467393dc82c0a786e0de4e2bMagnus Jedvert // cricket::VideoCapturer implementation. 816ec1f921b1186127467393dc82c0a786e0de4e2bMagnus Jedvert bool GetBestCaptureFormat(const cricket::VideoFormat& desired, 826ec1f921b1186127467393dc82c0a786e0de4e2bMagnus Jedvert cricket::VideoFormat* best_format) override; 836ec1f921b1186127467393dc82c0a786e0de4e2bMagnus Jedvert 8483bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org private: 8583bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org // cricket::VideoCapturer implementation. 8683bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org // Video frames will be delivered using 8783bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org // cricket::VideoCapturer::SignalFrameCaptured on the thread that calls Start. 8883bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org cricket::CaptureState Start( 8983bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org const cricket::VideoFormat& capture_format) override; 9083bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org void Stop() override; 9183bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org bool IsRunning() override; 9283bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org bool IsScreencast() const override { return false; } 930c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström bool GetPreferredFourccs(std::vector<uint32_t>* fourccs) override; 9483bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org 9583bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org bool running_; 963354419a2d53c3bfee8077cfbb0d86022b03e94aPer rtc::scoped_refptr<AndroidVideoCapturerDelegate> delegate_; 9783bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org 983354419a2d53c3bfee8077cfbb0d86022b03e94aPer rtc::ThreadChecker thread_checker_; 9983bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org 10083bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org class FrameFactory; 10183bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org FrameFactory* frame_factory_; // Owned by cricket::VideoCapturer. 1028f605e89113ccdd02a5d68edf8e7a048ab0fdaffperkj@webrtc.org 1038f605e89113ccdd02a5d68edf8e7a048ab0fdaffperkj@webrtc.org cricket::CaptureState current_state_; 10483bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org}; 10583bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org 10683bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org} // namespace webrtc 10783bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org 10883bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org#endif // TALK_APP_WEBRTC_ANDROIDVIDEOCAPTURER_H_ 109