15976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org/*
25976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * libjingle
35976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * Copyright 2013, Google Inc.
45976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *
55976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * Redistribution and use in source and binary forms, with or without
65976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * modification, are permitted provided that the following conditions are met:
75976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *
85976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *  1. Redistributions of source code must retain the above copyright notice,
95976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *     this list of conditions and the following disclaimer.
105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *  2. Redistributions in binary form must reproduce the above copyright notice,
115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *     this list of conditions and the following disclaimer in the documentation
125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *     and/or other materials provided with the distribution.
135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *  3. The name of the author may not be used to endorse or promote products
145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *     derived from this software without specific prior written permission.
155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *
165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
245976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
255976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
265976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org */
275976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
285976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgpackage org.webrtc;
295976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
3033ff0831ca67eeb4e33cfb4e0a0b68c6cc631cccmarpan@webrtc.org/** Java version of cricket::VideoCapturer. */
315976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgpublic class VideoCapturer {
3233ff0831ca67eeb4e33cfb4e0a0b68c6cc631cccmarpan@webrtc.org  private long nativeVideoCapturer;
335976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
345976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  private VideoCapturer(long nativeVideoCapturer) {
355976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    this.nativeVideoCapturer = nativeVideoCapturer;
365976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
375976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
385976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  public static VideoCapturer create(String deviceName) {
395976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    long nativeVideoCapturer = nativeCreateVideoCapturer(deviceName);
405976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    if (nativeVideoCapturer == 0) {
415976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org      return null;
425976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    }
435976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    return new VideoCapturer(nativeVideoCapturer);
445976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
455976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
4633ff0831ca67eeb4e33cfb4e0a0b68c6cc631cccmarpan@webrtc.org  // Package-visible for PeerConnectionFactory.
4733ff0831ca67eeb4e33cfb4e0a0b68c6cc631cccmarpan@webrtc.org  long takeNativeVideoCapturer() {
4833ff0831ca67eeb4e33cfb4e0a0b68c6cc631cccmarpan@webrtc.org    if (nativeVideoCapturer == 0) {
4933ff0831ca67eeb4e33cfb4e0a0b68c6cc631cccmarpan@webrtc.org      throw new RuntimeException("Capturer can only be taken once!");
5033ff0831ca67eeb4e33cfb4e0a0b68c6cc631cccmarpan@webrtc.org    }
5133ff0831ca67eeb4e33cfb4e0a0b68c6cc631cccmarpan@webrtc.org    long ret = nativeVideoCapturer;
5233ff0831ca67eeb4e33cfb4e0a0b68c6cc631cccmarpan@webrtc.org    nativeVideoCapturer = 0;
5333ff0831ca67eeb4e33cfb4e0a0b68c6cc631cccmarpan@webrtc.org    return ret;
5433ff0831ca67eeb4e33cfb4e0a0b68c6cc631cccmarpan@webrtc.org  }
5533ff0831ca67eeb4e33cfb4e0a0b68c6cc631cccmarpan@webrtc.org
565976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  public void dispose() {
5733ff0831ca67eeb4e33cfb4e0a0b68c6cc631cccmarpan@webrtc.org    // No-op iff this capturer is owned by a source (see comment on
5833ff0831ca67eeb4e33cfb4e0a0b68c6cc631cccmarpan@webrtc.org    // PeerConnectionFactoryInterface::CreateVideoSource()).
5933ff0831ca67eeb4e33cfb4e0a0b68c6cc631cccmarpan@webrtc.org    if (nativeVideoCapturer != 0) {
6033ff0831ca67eeb4e33cfb4e0a0b68c6cc631cccmarpan@webrtc.org      free(nativeVideoCapturer);
6133ff0831ca67eeb4e33cfb4e0a0b68c6cc631cccmarpan@webrtc.org    }
625976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
635976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
645976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  private static native long nativeCreateVideoCapturer(String deviceName);
655976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
665976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  private static native void free(long nativeVideoCapturer);
675976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org}
68