blob: fdc86290bb25119b03758a6b9e754516a4fa7aee [file] [log] [blame]
perkj@webrtc.org83bc7212015-02-11 11:26:561/*
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"
Per33544192015-04-02 10:30:5134#include "webrtc/base/thread_checker.h"
Magnus Jedvertc464f502015-08-25 21:22:0835#include "webrtc/common_video/interface/video_frame_buffer.h"
perkj@webrtc.org83bc7212015-02-11 11:26:5636
37namespace webrtc {
38
39class AndroidVideoCapturer;
40
Per33544192015-04-02 10:30:5141class AndroidVideoCapturerDelegate : public rtc::RefCountInterface {
perkj@webrtc.org83bc7212015-02-11 11:26:5642 public:
43 virtual ~AndroidVideoCapturerDelegate() {}
44 // Start capturing. The implementation of the delegate must call
45 // AndroidVideoCapturer::OnCapturerStarted with the result of this request.
46 virtual void Start(int width, int height, int framerate,
47 AndroidVideoCapturer* capturer) = 0;
48
perkj@webrtc.org3db042e2015-02-19 08:43:3849 // Stops capturing.
perkj@webrtc.org83bc7212015-02-11 11:26:5650 // The delegate may not call into AndroidVideoCapturer after this call.
perkj@webrtc.org3db042e2015-02-19 08:43:3851 virtual void Stop() = 0;
perkj@webrtc.org83bc7212015-02-11 11:26:5652
53 // Must returns a JSON string "{{width=xxx, height=xxx, framerate = xxx}}"
54 virtual std::string GetSupportedFormats() = 0;
55};
56
57// Android implementation of cricket::VideoCapturer for use with WebRtc
58// PeerConnection.
59class AndroidVideoCapturer : public cricket::VideoCapturer {
60 public:
61 explicit AndroidVideoCapturer(
Per33544192015-04-02 10:30:5162 const rtc::scoped_refptr<AndroidVideoCapturerDelegate>& delegate);
perkj@webrtc.org83bc7212015-02-11 11:26:5663 virtual ~AndroidVideoCapturer();
64
perkj@webrtc.org112f1272015-02-25 09:20:0765 // Called from JNI when the capturer has been started.
perkj@webrtc.org83bc7212015-02-11 11:26:5666 void OnCapturerStarted(bool success);
67
perkj@webrtc.org112f1272015-02-25 09:20:0768 // Called from JNI when a new frame has been captured.
Magnus Jedvertc464f502015-08-25 21:22:0869 // Argument |buffer| is intentionally by value, for use with rtc::Bind.
70 void OnIncomingFrame(rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer,
perkj@webrtc.org83bc7212015-02-11 11:26:5671 int rotation,
Peter Boström0c4e06b2015-10-07 10:23:2172 int64_t time_stamp);
perkj@webrtc.org83bc7212015-02-11 11:26:5673
Åsa Persson2b679252015-06-15 07:53:0574 // Called from JNI to request a new video format.
75 void OnOutputFormatRequest(int width, int height, int fps);
76
perkj@webrtc.org83bc7212015-02-11 11:26:5677 AndroidVideoCapturerDelegate* delegate() { return delegate_.get(); }
78
Magnus Jedvert6ec1f922015-08-28 09:40:5979 // cricket::VideoCapturer implementation.
80 bool GetBestCaptureFormat(const cricket::VideoFormat& desired,
81 cricket::VideoFormat* best_format) override;
82
perkj@webrtc.org83bc7212015-02-11 11:26:5683 private:
perkj@webrtc.org83bc7212015-02-11 11:26:5684 // 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; }
Peter Boström0c4e06b2015-10-07 10:23:2192 bool GetPreferredFourccs(std::vector<uint32_t>* fourccs) override;
perkj@webrtc.org83bc7212015-02-11 11:26:5693
94 bool running_;
Per33544192015-04-02 10:30:5195 rtc::scoped_refptr<AndroidVideoCapturerDelegate> delegate_;
perkj@webrtc.org83bc7212015-02-11 11:26:5696
Per33544192015-04-02 10:30:5197 rtc::ThreadChecker thread_checker_;
perkj@webrtc.org83bc7212015-02-11 11:26:5698
99 class FrameFactory;
100 FrameFactory* frame_factory_; // Owned by cricket::VideoCapturer.
perkj@webrtc.org8f605e82015-02-17 13:53:56101
102 cricket::CaptureState current_state_;
perkj@webrtc.org83bc7212015-02-11 11:26:56103};
104
105} // namespace webrtc
106
107#endif // TALK_APP_WEBRTC_ANDROIDVIDEOCAPTURER_H_