| Index: media/capture/video/android/java/src/org/chromium/media/VideoCaptureTango.java
|
| diff --git a/media/capture/video/android/java/src/org/chromium/media/VideoCaptureTango.java b/media/capture/video/android/java/src/org/chromium/media/VideoCaptureTango.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..43f26d8bd8deafd870b19262a1ee81e0f2e39c6a
|
| --- /dev/null
|
| +++ b/media/capture/video/android/java/src/org/chromium/media/VideoCaptureTango.java
|
| @@ -0,0 +1,77 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +package org.chromium.media;
|
| +
|
| +import android.content.ComponentName;
|
| +import android.content.Context;
|
| +import android.content.Intent;
|
| +import android.content.ServiceConnection;
|
| +import android.os.IBinder;
|
| +
|
| +import org.chromium.base.ContextUtils;
|
| +import org.chromium.base.annotations.CalledByNative;
|
| +import org.chromium.base.annotations.JNINamespace;
|
| +
|
| +/**
|
| + * This class used for establishing connection to Tango service. Most of the code implementing Tango
|
| + *capture is native, in VideoCaptureDevicetangoAndroid class.
|
| + **/
|
| +@JNINamespace("media")
|
| +public class VideoCaptureTango {
|
| + private static final String TAG = "cr.mediatango";
|
| +
|
| + // Native callback context variable.
|
| + private final long mNativeVideoCaptureDeviceTangoAndroid;
|
| + private boolean mBound = false;
|
| +
|
| + private ServiceConnection mTangoServiceConnection = new ServiceConnection() {
|
| + public void onServiceConnected(ComponentName name, IBinder service) {
|
| + mBound = true;
|
| + nativeOnTangoServiceConnected(mNativeVideoCaptureDeviceTangoAndroid, service);
|
| + }
|
| +
|
| + public void onServiceDisconnected(ComponentName name) {
|
| + mBound = false;
|
| + }
|
| + };
|
| +
|
| + private static final boolean bindTangoService(
|
| + final Context context, ServiceConnection connection) {
|
| + Intent intent = new Intent();
|
| + intent.setClassName("com.google.tango", "com.google.atap.tango.TangoService");
|
| +
|
| + if (context.getPackageManager().resolveService(intent, 0) == null) return false;
|
| + return context.bindService(intent, connection, Context.BIND_AUTO_CREATE);
|
| + }
|
| +
|
| + VideoCaptureTango(long nativeVideoCaptureDeviceTangoAndroid) {
|
| + mNativeVideoCaptureDeviceTangoAndroid = nativeVideoCaptureDeviceTangoAndroid;
|
| + }
|
| +
|
| + @CalledByNative
|
| + public boolean startCapture() {
|
| + final Context context = ContextUtils.getApplicationContext();
|
| + return bindTangoService(context, mTangoServiceConnection);
|
| + }
|
| +
|
| + @CalledByNative
|
| + public void stopCapture() {
|
| + nativeTangoDisconnect(mNativeVideoCaptureDeviceTangoAndroid);
|
| + if (mBound) {
|
| + ContextUtils.getApplicationContext().unbindService(mTangoServiceConnection);
|
| + mBound = false;
|
| + }
|
| + }
|
| +
|
| + // Factory method.
|
| + @CalledByNative
|
| + static VideoCaptureTango create(long nativeVideoCaptureDeviceTangoAndroid) {
|
| + return new VideoCaptureTango(nativeVideoCaptureDeviceTangoAndroid);
|
| + }
|
| +
|
| + public native void nativeOnTangoServiceConnected(
|
| + long nativeVideoCaptureDeviceTangoAndroid, IBinder service);
|
| + public native void nativeTangoDisconnect(long nativeVideoCaptureDeviceTangoAndroid);
|
| +}
|
|
|