FileDocCategorySizeDatePackage
TvInputHal.javaAPI DocAndroid 5.1 API7599Thu Mar 12 22:22:42 GMT 2015com.android.server.tv

TvInputHal

public final class TvInputHal extends Object implements Handler.Callback
Provides access to the low-level TV input hardware abstraction layer.

Fields Summary
private static final boolean
DEBUG
private static final String
TAG
public static final int
SUCCESS
public static final int
ERROR_NO_INIT
public static final int
ERROR_STALE_CONFIG
public static final int
ERROR_UNKNOWN
public static final int
EVENT_DEVICE_AVAILABLE
public static final int
EVENT_DEVICE_UNAVAILABLE
public static final int
EVENT_STREAM_CONFIGURATION_CHANGED
public static final int
EVENT_FIRST_FRAME_CAPTURED
private final Object
mLock
private long
mPtr
private final Callback
mCallback
private final android.os.Handler
mHandler
private final android.util.SparseIntArray
mStreamConfigGenerations
private final android.util.SparseArray
mStreamConfigs
private final Queue
mPendingMessageQueue
Constructors Summary
public TvInputHal(Callback callback)


       
        mCallback = callback;
        mHandler = new Handler(this);
    
Methods Summary
public intaddOrUpdateStream(int deviceId, android.view.Surface surface, android.media.tv.TvStreamConfig streamConfig)

        synchronized (mLock) {
            if (mPtr == 0) {
                return ERROR_NO_INIT;
            }
            int generation = mStreamConfigGenerations.get(deviceId, 0);
            if (generation != streamConfig.getGeneration()) {
                return ERROR_STALE_CONFIG;
            }
            if (nativeAddOrUpdateStream(mPtr, deviceId, streamConfig.getStreamId(), surface) == 0) {
                return SUCCESS;
            } else {
                return ERROR_UNKNOWN;
            }
        }
    
public voidclose()

        synchronized (mLock) {
            if (mPtr != 0l) {
                nativeClose(mPtr);
            }
        }
    
private voiddeviceAvailableFromNative(android.media.tv.TvInputHardwareInfo info)

        if (DEBUG) {
            Slog.d(TAG, "deviceAvailableFromNative: info = " + info);
        }
        mHandler.obtainMessage(EVENT_DEVICE_AVAILABLE, info).sendToTarget();
    
private voiddeviceUnavailableFromNative(int deviceId)

        mHandler.obtainMessage(EVENT_DEVICE_UNAVAILABLE, deviceId, 0).sendToTarget();
    
private voidfirstFrameCapturedFromNative(int deviceId, int streamId)

        mHandler.sendMessage(
                mHandler.obtainMessage(EVENT_STREAM_CONFIGURATION_CHANGED, deviceId, streamId));
    
public booleanhandleMessage(android.os.Message msg)


    
        
        switch (msg.what) {
            case EVENT_DEVICE_AVAILABLE: {
                TvStreamConfig[] configs;
                TvInputHardwareInfo info = (TvInputHardwareInfo)msg.obj;
                synchronized (mLock) {
                    retrieveStreamConfigsLocked(info.getDeviceId());
                    if (DEBUG) {
                        Slog.d(TAG, "EVENT_DEVICE_AVAILABLE: info = " + info);
                    }
                    configs = mStreamConfigs.get(info.getDeviceId());
                }
                mCallback.onDeviceAvailable(info, configs);
                break;
            }

            case EVENT_DEVICE_UNAVAILABLE: {
                int deviceId = msg.arg1;
                if (DEBUG) {
                    Slog.d(TAG, "EVENT_DEVICE_UNAVAILABLE: deviceId = " + deviceId);
                }
                mCallback.onDeviceUnavailable(deviceId);
                break;
            }

            case EVENT_STREAM_CONFIGURATION_CHANGED: {
                TvStreamConfig[] configs;
                int deviceId = msg.arg1;
                synchronized (mLock) {
                    if (DEBUG) {
                        Slog.d(TAG, "EVENT_STREAM_CONFIGURATION_CHANGED: deviceId = " + deviceId);
                    }
                    retrieveStreamConfigsLocked(deviceId);
                    configs = mStreamConfigs.get(deviceId);
                }
                mCallback.onStreamConfigurationChanged(deviceId, configs);
                break;
            }

            case EVENT_FIRST_FRAME_CAPTURED: {
                int deviceId = msg.arg1;
                int streamId = msg.arg2;
                mCallback.onFirstFrameCaptured(deviceId, streamId);
                break;
            }

            default:
                Slog.e(TAG, "Unknown event: " + msg);
                return false;
        }

        return true;
    
public voidinit()

        synchronized (mLock) {
            mPtr = nativeOpen(mHandler.getLooper().getQueue());
        }
    
private static native intnativeAddOrUpdateStream(long ptr, int deviceId, int streamId, android.view.Surface surface)

private static native voidnativeClose(long ptr)

private static native android.media.tv.TvStreamConfig[]nativeGetStreamConfigs(long ptr, int deviceId, int generation)

private native longnativeOpen(android.os.MessageQueue queue)

private static native intnativeRemoveStream(long ptr, int deviceId, int streamId)

public intremoveStream(int deviceId, android.media.tv.TvStreamConfig streamConfig)

        synchronized (mLock) {
            if (mPtr == 0) {
                return ERROR_NO_INIT;
            }
            int generation = mStreamConfigGenerations.get(deviceId, 0);
            if (generation != streamConfig.getGeneration()) {
                return ERROR_STALE_CONFIG;
            }
            if (nativeRemoveStream(mPtr, deviceId, streamConfig.getStreamId()) == 0) {
                return SUCCESS;
            } else {
                return ERROR_UNKNOWN;
            }
        }
    
private voidretrieveStreamConfigsLocked(int deviceId)

        int generation = mStreamConfigGenerations.get(deviceId, 0) + 1;
        mStreamConfigs.put(deviceId, nativeGetStreamConfigs(mPtr, deviceId, generation));
        mStreamConfigGenerations.put(deviceId, generation);
    
private voidstreamConfigsChangedFromNative(int deviceId)

        mHandler.obtainMessage(EVENT_STREAM_CONFIGURATION_CHANGED, deviceId, 0).sendToTarget();