Path: blob/21.2-virgl/include/android_stub/system/radio.h
4547 views
/*1* Copyright (C) 2015 The Android Open Source Project2*3* Licensed under the Apache License, Version 2.0 (the "License");4* you may not use this file except in compliance with the License.5* You may obtain a copy of the License at6*7* http://www.apache.org/licenses/LICENSE-2.08*9* Unless required by applicable law or agreed to in writing, software10* distributed under the License is distributed on an "AS IS" BASIS,11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12* See the License for the specific language governing permissions and13* limitations under the License.14*/1516#ifndef ANDROID_RADIO_H17#define ANDROID_RADIO_H1819#include <stdbool.h>20#include <stdint.h>21#include <stdio.h>22#include <sys/cdefs.h>23#include <sys/types.h>242526#define RADIO_NUM_BANDS_MAX 1627#define RADIO_NUM_SPACINGS_MAX 1628#define RADIO_STRING_LEN_MAX 1282930/*31* Radio hardware module class. A given radio hardware module HAL is of one class32* only. The platform can not have more than one hardware module of each class.33* Current version of the framework only supports RADIO_CLASS_AM_FM.34*/35typedef enum {36RADIO_CLASS_AM_FM = 0, /* FM (including HD radio) and AM */37RADIO_CLASS_SAT = 1, /* Satellite Radio */38RADIO_CLASS_DT = 2, /* Digital Radio (DAB) */39} radio_class_t;4041/* value for field "type" of radio band described in struct radio_hal_band_config */42typedef enum {43RADIO_BAND_AM = 0, /* Amplitude Modulation band: LW, MW, SW */44RADIO_BAND_FM = 1, /* Frequency Modulation band: FM */45RADIO_BAND_FM_HD = 2, /* FM HD Radio / DRM (IBOC) */46RADIO_BAND_AM_HD = 3, /* AM HD Radio / DRM (IBOC) */47} radio_band_t;4849/* RDS variant implemented. A struct radio_hal_fm_band_config can list none or several. */50enum {51RADIO_RDS_NONE = 0x0,52RADIO_RDS_WORLD = 0x01,53RADIO_RDS_US = 0x02,54};55typedef unsigned int radio_rds_t;5657/* FM deemphasis variant implemented. A struct radio_hal_fm_band_config can list one or more. */58enum {59RADIO_DEEMPHASIS_50 = 0x1,60RADIO_DEEMPHASIS_75 = 0x2,61};62typedef unsigned int radio_deemphasis_t;6364/* Region a particular radio band configuration corresponds to. Not used at the HAL.65* Derived by the framework when converting the band descriptors retrieved from the HAL to66* individual band descriptors for each supported region. */67typedef enum {68RADIO_REGION_NONE = -1,69RADIO_REGION_ITU_1 = 0,70RADIO_REGION_ITU_2 = 1,71RADIO_REGION_OIRT = 2,72RADIO_REGION_JAPAN = 3,73RADIO_REGION_KOREA = 4,74} radio_region_t;7576/* scanning direction for scan() and step() tuner APIs */77typedef enum {78RADIO_DIRECTION_UP,79RADIO_DIRECTION_DOWN80} radio_direction_t;8182/* unique handle allocated to a radio module */83typedef uint32_t radio_handle_t;8485/* Opaque meta data structure used by radio meta data API (see system/radio_metadata.h) */86typedef struct radio_metadata radio_metadata_t;878889/* Additional attributes for an FM band configuration */90typedef struct radio_hal_fm_band_config {91radio_deemphasis_t deemphasis; /* deemphasis variant */92bool stereo; /* stereo supported */93radio_rds_t rds; /* RDS variants supported */94bool ta; /* Traffic Announcement supported */95bool af; /* Alternate Frequency supported */96bool ea; /* Emergency announcements supported */97} radio_hal_fm_band_config_t;9899/* Additional attributes for an AM band configuration */100typedef struct radio_hal_am_band_config {101bool stereo; /* stereo supported */102} radio_hal_am_band_config_t;103104/* Radio band configuration. Describes a given band supported by the radio module.105* The HAL can expose only one band per type with the the maximum range supported and all options.106* THe framework will derive the actual regions were this module can operate and expose separate107* band configurations for applications to chose from. */108typedef struct radio_hal_band_config {109radio_band_t type;110bool antenna_connected;111uint32_t lower_limit;112uint32_t upper_limit;113uint32_t num_spacings;114uint32_t spacings[RADIO_NUM_SPACINGS_MAX];115union {116radio_hal_fm_band_config_t fm;117radio_hal_am_band_config_t am;118};119} radio_hal_band_config_t;120121/* Used internally by the framework to represent a band for s specific region */122typedef struct radio_band_config {123radio_region_t region;124radio_hal_band_config_t band;125} radio_band_config_t;126127128/* Exposes properties of a given hardware radio module.129* NOTE: current framework implementation supports only one audio source (num_audio_sources = 1).130* The source corresponds to AUDIO_DEVICE_IN_FM_TUNER.131* If more than one tuner is supported (num_tuners > 1), only one can be connected to the audio132* source. */133typedef struct radio_hal_properties {134radio_class_t class_id; /* Class of this module. E.g RADIO_CLASS_AM_FM */135char implementor[RADIO_STRING_LEN_MAX]; /* implementor name */136char product[RADIO_STRING_LEN_MAX]; /* product name */137char version[RADIO_STRING_LEN_MAX]; /* product version */138char serial[RADIO_STRING_LEN_MAX]; /* serial number (for subscription services) */139uint32_t num_tuners; /* number of tuners controllable independently */140uint32_t num_audio_sources; /* number of audio sources driven simultaneously */141bool supports_capture; /* the hardware supports capture of audio source audio HAL */142uint32_t num_bands; /* number of band descriptors */143radio_hal_band_config_t bands[RADIO_NUM_BANDS_MAX]; /* band descriptors */144} radio_hal_properties_t;145146/* Used internally by the framework. Same information as in struct radio_hal_properties plus a147* unique handle and one band configuration per region. */148typedef struct radio_properties {149radio_handle_t handle;150radio_class_t class_id;151char implementor[RADIO_STRING_LEN_MAX];152char product[RADIO_STRING_LEN_MAX];153char version[RADIO_STRING_LEN_MAX];154char serial[RADIO_STRING_LEN_MAX];155uint32_t num_tuners;156uint32_t num_audio_sources;157bool supports_capture;158uint32_t num_bands;159radio_band_config_t bands[RADIO_NUM_BANDS_MAX];160} radio_properties_t;161162/* Radio program information. Returned by the HAL with event RADIO_EVENT_TUNED.163* Contains information on currently tuned channel.164*/165typedef struct radio_program_info {166uint32_t channel; /* current channel. (e.g kHz for band type RADIO_BAND_FM) */167uint32_t sub_channel; /* current sub channel. (used for RADIO_BAND_FM_HD) */168bool tuned; /* tuned to a program or not */169bool stereo; /* program is stereo or not */170bool digital; /* digital program or not (e.g HD Radio program) */171uint32_t signal_strength; /* signal strength from 0 to 100 */172/* meta data (e.g PTY, song title ...), must not be NULL */173__attribute__((aligned(8))) radio_metadata_t *metadata;174} radio_program_info_t;175176177/* Events sent to the framework via the HAL callback. An event can notify the completion of an178* asynchronous command (configuration, tune, scan ...) or a spontaneous change (antenna connection,179* failure, AF switching, meta data reception... */180enum {181RADIO_EVENT_HW_FAILURE = 0, /* hardware module failure. Requires reopening the tuner */182RADIO_EVENT_CONFIG = 1, /* configuration change completed */183RADIO_EVENT_ANTENNA = 2, /* Antenna connected, disconnected */184RADIO_EVENT_TUNED = 3, /* tune, step, scan completed */185RADIO_EVENT_METADATA = 4, /* New meta data received */186RADIO_EVENT_TA = 5, /* Traffic announcement start or stop */187RADIO_EVENT_AF_SWITCH = 6, /* Switch to Alternate Frequency */188RADIO_EVENT_EA = 7, /* Emergency announcement start or stop */189// begin framework only events190RADIO_EVENT_CONTROL = 100, /* loss/gain of tuner control */191RADIO_EVENT_SERVER_DIED = 101, /* radio service died */192};193typedef unsigned int radio_event_type_t;194195/* Event passed to the framework by the HAL callback */196typedef struct radio_hal_event {197radio_event_type_t type; /* event type */198int32_t status; /* used by RADIO_EVENT_CONFIG, RADIO_EVENT_TUNED */199union {200/* RADIO_EVENT_ANTENNA, RADIO_EVENT_TA, RADIO_EVENT_EA */201bool on;202radio_hal_band_config_t config; /* RADIO_EVENT_CONFIG */203radio_program_info_t info; /* RADIO_EVENT_TUNED, RADIO_EVENT_AF_SWITCH */204radio_metadata_t *metadata; /* RADIO_EVENT_METADATA */205};206} radio_hal_event_t;207208/* Used internally by the framework. Same information as in struct radio_hal_event */209typedef struct radio_event {210radio_event_type_t type;211int32_t status;212union {213bool on;214radio_band_config_t config;215radio_program_info_t info;216/* meta data (e.g PTY, song title ...), must not be NULL */217__attribute__((aligned(8))) radio_metadata_t *metadata;218};219} radio_event_t;220221222static inline223radio_rds_t radio_rds_for_region(bool rds, radio_region_t region) {224if (!rds)225return RADIO_RDS_NONE;226switch(region) {227case RADIO_REGION_ITU_1:228case RADIO_REGION_OIRT:229case RADIO_REGION_JAPAN:230case RADIO_REGION_KOREA:231return RADIO_RDS_WORLD;232case RADIO_REGION_ITU_2:233return RADIO_RDS_US;234default:235return RADIO_REGION_NONE;236}237}238239static inline240radio_deemphasis_t radio_demephasis_for_region(radio_region_t region) {241switch(region) {242case RADIO_REGION_KOREA:243case RADIO_REGION_ITU_2:244return RADIO_DEEMPHASIS_75;245case RADIO_REGION_ITU_1:246case RADIO_REGION_OIRT:247case RADIO_REGION_JAPAN:248default:249return RADIO_DEEMPHASIS_50;250}251}252253#endif // ANDROID_RADIO_H254255256