128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org/* 228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * libjingle 35f93d0a140515e3b8cdd1b9a4c6f5871144e5deejlmiller@webrtc.org * Copyright 2013 Google Inc. 428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * 528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * Redistribution and use in source and binary forms, with or without 628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * modification, are permitted provided that the following conditions are met: 728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * 828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * 1. Redistributions of source code must retain the above copyright notice, 928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * this list of conditions and the following disclaimer. 1028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * 2. Redistributions in binary form must reproduce the above copyright notice, 1128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * this list of conditions and the following disclaimer in the documentation 1228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * and/or other materials provided with the distribution. 1328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * 3. The name of the author may not be used to endorse or promote products 1428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * derived from this software without specific prior written permission. 1528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * 1628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 1728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 1828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 1928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 2128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 2228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 2328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 2428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 2528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org */ 2728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 2828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgpackage org.webrtc; 2928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 3032001ef124f5082651c661965dc5d75d7f06a57bfischman@webrtc.org/** Java version of cricket::VideoCapturer. */ 3128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgpublic class VideoCapturer { 3232001ef124f5082651c661965dc5d75d7f06a57bfischman@webrtc.org private long nativeVideoCapturer; 3328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 3483bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org protected VideoCapturer() { 3528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org } 3628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 3728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org public static VideoCapturer create(String deviceName) { 3883bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org Object capturer = nativeCreateVideoCapturer(deviceName); 3983bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org if (capturer != null) 4083bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org return (VideoCapturer) (capturer); 4183bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org return null; 4283bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org } 4383bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org 4483bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org // Sets |nativeCapturer| to be owned by VideoCapturer. 4583bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org protected void setNativeCapturer(long nativeCapturer) { 4683bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org this.nativeVideoCapturer = nativeCapturer; 4728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org } 4828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 4932001ef124f5082651c661965dc5d75d7f06a57bfischman@webrtc.org // Package-visible for PeerConnectionFactory. 5032001ef124f5082651c661965dc5d75d7f06a57bfischman@webrtc.org long takeNativeVideoCapturer() { 5132001ef124f5082651c661965dc5d75d7f06a57bfischman@webrtc.org if (nativeVideoCapturer == 0) { 5232001ef124f5082651c661965dc5d75d7f06a57bfischman@webrtc.org throw new RuntimeException("Capturer can only be taken once!"); 5332001ef124f5082651c661965dc5d75d7f06a57bfischman@webrtc.org } 5432001ef124f5082651c661965dc5d75d7f06a57bfischman@webrtc.org long ret = nativeVideoCapturer; 5532001ef124f5082651c661965dc5d75d7f06a57bfischman@webrtc.org nativeVideoCapturer = 0; 5632001ef124f5082651c661965dc5d75d7f06a57bfischman@webrtc.org return ret; 5732001ef124f5082651c661965dc5d75d7f06a57bfischman@webrtc.org } 5832001ef124f5082651c661965dc5d75d7f06a57bfischman@webrtc.org 5928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org public void dispose() { 6032001ef124f5082651c661965dc5d75d7f06a57bfischman@webrtc.org // No-op iff this capturer is owned by a source (see comment on 6132001ef124f5082651c661965dc5d75d7f06a57bfischman@webrtc.org // PeerConnectionFactoryInterface::CreateVideoSource()). 6232001ef124f5082651c661965dc5d75d7f06a57bfischman@webrtc.org if (nativeVideoCapturer != 0) { 6332001ef124f5082651c661965dc5d75d7f06a57bfischman@webrtc.org free(nativeVideoCapturer); 6432001ef124f5082651c661965dc5d75d7f06a57bfischman@webrtc.org } 6528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org } 6628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 6783bc721c7e1760ce7f96eed11a5351fa3154f523perkj@webrtc.org private static native Object nativeCreateVideoCapturer(String deviceName); 6828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 6928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org private static native void free(long nativeVideoCapturer); 7028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org} 71