admin 管理员组

文章数量: 1184232

上一篇文章有分析TIF事件传递流程,TvIputHal会call到JNI,JNI将event给到Java层,但是JNI层又是怎么拿到event事件的呢?

分析TIF HAL层,需要掌握:

1.HAL层主要结构体的含义

2.HAL层主要代码实现

3.Native层或JNI层load hal模块的流程

4.hal,native和jni调用关系

1.HAL层主要结构体的含义

TIF HAL层头文件路径:

hardware\libhardware\include\hardware\tv_input.h

在Java层我们定义了TvInputService,我们知道,每一种Tv input device,需要对应一个TvInputService,系统目前支持的Tv Input device类型定义如下:

enum {
    /* Generic hardware. */
    TV_INPUT_TYPE_OTHER_HARDWARE = 1,
    /* Tuner. (e.g. built-in terrestrial tuner) */
    TV_INPUT_TYPE_TUNER = 2,
    TV_INPUT_TYPE_COMPOSITE = 3,
    TV_INPUT_TYPE_SVIDEO = 4,
    TV_INPUT_TYPE_SCART = 5,
    TV_INPUT_TYPE_COMPONENT = 6,
    TV_INPUT_TYPE_VGA = 7,
    TV_INPUT_TYPE_DVI = 8,
    /* Physical HDMI port. (e.g. HDMI 1) */
    TV_INPUT_TYPE_HDMI = 9,
    TV_INPUT_TYPE_DISPLAY_PORT = 10,
};
tv input device对应hal层info结构体定义如下:

typedef struct tv_input_device_info {
    /* Device ID */
    int device_id;
    /* Type of physical TV input. */
    tv_input_type_t type;
    union {
        struct {
            /* HDMI port ID number */
            uint32_t port_id;
        } hdmi;
        /* TODO: add other type specific information. */
        int32_t type_info_reserved[16];
    };
    /* TODO: Add capability if necessary. */
    /*
     * Audio info
     *
     * audio_type == AUDIO_DEVICE_NONE if this input has no audio.
     */
    audio_devices_t audio_type;
    const char* audio_address;
    int32_t reserved[16];
} tv_input_device_info_t;
其中的tv_input_type_t即上面枚举的tv input device type。对于TV平台,HDMI支持多个端口,对于端口序号定义了port_id,HDMI事件插拔时,可以得到指定端口的事件。

tv input device有各种事件类型,对于事件类型定义如下:

/* See tv_input_event_t for more details. */
enum {
    /*
     * Hardware notifies the framework that a device is available.
     *
     * Note that DEVICE_AVAILABLE and DEVICE_UNAVAILABLE events do not represent
     * hotplug events (i.e. plugging cable into or out of the physical port).
     * These events notify the framework whether the port is available or not.
     * For a concrete example, when a user plugs in or pulls out the HDMI cable
     * from a HDMI port, it does not generate DEVICE_AVAILABLE and/or
     * DEVICE_UNAVAILABLE events. However, if a user inserts a pluggable USB
     * tuner into the Android device, it will generate a DEVICE_AVAILABLE event
     * and when the port is removed, it should generate a DEVICE_UNAVAILABLE
     * event.
     *
     * For hotplug events, please see STREAM_CONFIGURATION_CHANGED for more
     * details.
     *
     * HAL implementation should register devices by using this event when the
     * device boots up. The framework will recognize device reported via this
     * event only. In addition, the implementation could use this event to
     * notify the framework that a removable TV input device (such as USB tuner
     * as stated in the example above) is attached.
     */
    TV_INPUT_EVENT_DEVICE_AVAILABLE = 1,
    /*
     * Hardware notifies the framework that a device is unavailable.
     *
     * HAL implementation should generate this event when a device registered
     * by TV_INPUT_EVENT_DEVICE_AVAILABLE is no longer available. For example,
     * the event can indicate that a USB tuner is plugged out from the Android
     * device.
     *
     * Note that this event is not for indicating cable plugged out of the port;
     * for that purpose, the implementation should use
     * STREAM_CONFIGURATION_CHANGED event. This event represents the port itself
     * being no longer available.
     */
    TV_INPUT_EVENT_DEVICE_UNAVAILABLE = 2,
    /*
     * Stream configurations are changed. Client should regard all open streams
     * at the specific device are closed, and should call
     * get_stream

本文标签: 类型定义 层主要结 系统