M7350v1_en_gpl

This commit is contained in:
T
2024-09-09 08:52:07 +00:00
commit f9cc65cfda
65988 changed files with 26357421 additions and 0 deletions

View File

@@ -0,0 +1,584 @@
/*
* Copyright (C) 2011 The Android Open Source Project
* Copyright (c) 2012, The Linux Foundation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_AUDIO_HAL_INTERFACE_H
#define ANDROID_AUDIO_HAL_INTERFACE_H
#include <stdint.h>
#include <string.h>
#include <strings.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <string.h>
#include <cutils/bitops.h>
#include <hardware/hardware.h>
#include <system/audio.h>
#include <hardware/audio_effect.h>
__BEGIN_DECLS
/**
* The id of this module
*/
#define AUDIO_HARDWARE_MODULE_ID "audio"
/**
* Name of the audio devices to open
*/
#define AUDIO_HARDWARE_INTERFACE "audio_hw_if"
/* Use version 0.1 to be compatible with first generation of audio hw module with version_major
* hardcoded to 1. No audio module API change.
*/
#define AUDIO_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
#define AUDIO_MODULE_API_VERSION_CURRENT AUDIO_MODULE_API_VERSION_0_1
/* First generation of audio devices had version hardcoded to 0. all devices with versions < 1.0
* will be considered of first generation API.
*/
#define AUDIO_DEVICE_API_VERSION_0_0 HARDWARE_DEVICE_API_VERSION(0, 0)
#define AUDIO_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
#define AUDIO_DEVICE_API_VERSION_CURRENT AUDIO_DEVICE_API_VERSION_1_0
/**
* List of known audio HAL modules. This is the base name of the audio HAL
* library composed of the "audio." prefix, one of the base names below and
* a suffix specific to the device.
* e.g: audio.primary.goldfish.so or audio.a2dp.default.so
*/
#define AUDIO_HARDWARE_MODULE_ID_PRIMARY "primary"
#define AUDIO_HARDWARE_MODULE_ID_A2DP "a2dp"
#define AUDIO_HARDWARE_MODULE_ID_USB "usb"
/**************************************/
/**
* standard audio parameters that the HAL may need to handle
*/
/**
* audio device parameters
*/
/* BT SCO Noise Reduction + Echo Cancellation parameters */
#define AUDIO_PARAMETER_KEY_BT_NREC "bt_headset_nrec"
#define AUDIO_PARAMETER_VALUE_ON "on"
#define AUDIO_PARAMETER_VALUE_OFF "off"
/* TTY mode selection */
#define AUDIO_PARAMETER_KEY_TTY_MODE "tty_mode"
#define AUDIO_PARAMETER_VALUE_TTY_OFF "tty_off"
#define AUDIO_PARAMETER_VALUE_TTY_VCO "tty_vco"
#define AUDIO_PARAMETER_VALUE_TTY_HCO "tty_hco"
#define AUDIO_PARAMETER_VALUE_TTY_FULL "tty_full"
/* A2DP sink address set by framework */
#define AUDIO_PARAMETER_A2DP_SINK_ADDRESS "a2dp_sink_address"
/* Screen state */
#define AUDIO_PARAMETER_KEY_SCREEN_STATE "screen_state"
/**
* audio stream parameters
*/
#define AUDIO_PARAMETER_STREAM_ROUTING "routing" // audio_devices_t
#define AUDIO_PARAMETER_STREAM_FORMAT "format" // audio_format_t
#define AUDIO_PARAMETER_STREAM_CHANNELS "channels" // audio_channel_mask_t
#define AUDIO_PARAMETER_STREAM_FRAME_COUNT "frame_count" // size_t
#define AUDIO_PARAMETER_STREAM_INPUT_SOURCE "input_source" // audio_source_t
#define AUDIO_PARAMETER_STREAM_SAMPLING_RATE "sampling_rate" // uint32_t
/* Query supported formats. The response is a '|' separated list of strings from
* audio_format_t enum e.g: "sup_formats=AUDIO_FORMAT_PCM_16_BIT" */
#define AUDIO_PARAMETER_STREAM_SUP_FORMATS "sup_formats"
/* Query supported channel masks. The response is a '|' separated list of strings from
* audio_channel_mask_t enum e.g: "sup_channels=AUDIO_CHANNEL_OUT_STEREO|AUDIO_CHANNEL_OUT_MONO" */
#define AUDIO_PARAMETER_STREAM_SUP_CHANNELS "sup_channels"
/* Query supported sampling rates. The response is a '|' separated list of integer values e.g:
* "sup_sampling_rates=44100|48000" */
#define AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES "sup_sampling_rates"
/* Query handle fm parameter*/
#define AUDIO_PARAMETER_KEY_HANDLE_FM "handle_fm"
/* Query voip flag */
#define AUDIO_PARAMETER_KEY_VOIP_CHECK "voip_flag"
/* Query Fluence type */
#define AUDIO_PARAMETER_KEY_FLUENCE_TYPE "fluence"
/* Query if surround sound recording is supported */
#define AUDIO_PARAMETER_KEY_SSR "ssr"
/* Query if a2dp is supported */
#define AUDIO_PARAMETER_KEY_HANDLE_A2DP_DEVICE "isA2dpDeviceSupported"
/**************************************/
/* common audio stream configuration parameters */
struct audio_config {
uint32_t sample_rate;
audio_channel_mask_t channel_mask;
audio_format_t format;
};
typedef struct audio_config audio_config_t;
typedef struct buf_info;
/* common audio stream parameters and operations */
struct audio_stream {
/**
* Return the sampling rate in Hz - eg. 44100.
*/
uint32_t (*get_sample_rate)(const struct audio_stream *stream);
/* currently unused - use set_parameters with key
* AUDIO_PARAMETER_STREAM_SAMPLING_RATE
*/
int (*set_sample_rate)(struct audio_stream *stream, uint32_t rate);
/**
* Return size of input/output buffer in bytes for this stream - eg. 4800.
* It should be a multiple of the frame size. See also get_input_buffer_size.
*/
size_t (*get_buffer_size)(const struct audio_stream *stream);
/**
* Return the channel mask -
* e.g. AUDIO_CHANNEL_OUT_STEREO or AUDIO_CHANNEL_IN_STEREO
*/
audio_channel_mask_t (*get_channels)(const struct audio_stream *stream);
/**
* Return the audio format - e.g. AUDIO_FORMAT_PCM_16_BIT
*/
audio_format_t (*get_format)(const struct audio_stream *stream);
/* currently unused - use set_parameters with key
* AUDIO_PARAMETER_STREAM_FORMAT
*/
int (*set_format)(struct audio_stream *stream, audio_format_t format);
/**
* Put the audio hardware input/output into standby mode.
* Driver should exit from standby mode at the next I/O operation.
* Returns 0 on success and <0 on failure.
*/
int (*standby)(struct audio_stream *stream);
/** dump the state of the audio input/output device */
int (*dump)(const struct audio_stream *stream, int fd);
/** Return the set of device(s) which this stream is connected to */
audio_devices_t (*get_device)(const struct audio_stream *stream);
/**
* Currently unused - set_device() corresponds to set_parameters() with key
* AUDIO_PARAMETER_STREAM_ROUTING for both input and output.
* AUDIO_PARAMETER_STREAM_INPUT_SOURCE is an additional information used by
* input streams only.
*/
int (*set_device)(struct audio_stream *stream, audio_devices_t device);
/**
* set/get audio stream parameters. The function accepts a list of
* parameter key value pairs in the form: key1=value1;key2=value2;...
*
* Some keys are reserved for standard parameters (See AudioParameter class)
*
* If the implementation does not accept a parameter change while
* the output is active but the parameter is acceptable otherwise, it must
* return -ENOSYS.
*
* The audio flinger will put the stream in standby and then change the
* parameter value.
*/
int (*set_parameters)(struct audio_stream *stream, const char *kv_pairs);
/*
* Returns a pointer to a heap allocated string. The caller is responsible
* for freeing the memory for it using free().
*/
char * (*get_parameters)(const struct audio_stream *stream,
const char *keys);
int (*add_audio_effect)(const struct audio_stream *stream,
effect_handle_t effect);
int (*remove_audio_effect)(const struct audio_stream *stream,
effect_handle_t effect);
};
typedef struct audio_stream audio_stream_t;
/**
* audio_stream_out is the abstraction interface for the audio output hardware.
*
* It provides information about various properties of the audio output
* hardware driver.
*/
struct audio_stream_out {
struct audio_stream common;
/**
* Return the audio hardware driver estimated latency in milliseconds.
*/
uint32_t (*get_latency)(const struct audio_stream_out *stream);
/**
* Use this method in situations where audio mixing is done in the
* hardware. This method serves as a direct interface with hardware,
* allowing you to directly set the volume as apposed to via the framework.
* This method might produce multiple PCM outputs or hardware accelerated
* codecs, such as MP3 or AAC.
*/
int (*set_volume)(struct audio_stream_out *stream, float left, float right);
/**
* Write audio buffer to driver. Returns number of bytes written, or a
* negative status_t. If at least one frame was written successfully prior to the error,
* it is suggested that the driver return that successful (short) byte count
* and then return an error in the subsequent call.
*/
ssize_t (*write)(struct audio_stream_out *stream, const void* buffer,
size_t bytes);
/* return the number of audio frames written by the audio dsp to DAC since
* the output has exited standby
*/
int (*get_render_position)(const struct audio_stream_out *stream,
uint32_t *dsp_frames);
/**
* start audio data rendering
*/
int (*start)(struct audio_stream_out *stream);
/**
* pause audio rendering
*/
int (*pause)(struct audio_stream_out *stream);
/**
* flush audio data with driver
*/
int (*flush)(struct audio_stream_out *stream);
/**
* stop audio data rendering
*/
int (*stop)(struct audio_stream_out *stream);
/**
* get the local time at which the next write to the audio driver will be presented.
* The units are microseconds, where the epoch is decided by the local audio HAL.
*/
int (*get_next_write_timestamp)(const struct audio_stream_out *stream,
int64_t *timestamp);
/**
* return the current timestamp after quering to the driver
*/
int (*get_time_stamp)(const struct audio_stream_out *stream,
uint64_t *time_stamp);
/**
* EOS notification from HAL to Player
*/
int (*set_observer)(const struct audio_stream_out *stream,
void *observer);
/**
* Get the physical address of the buffer allocated in the
* driver
*/
int (*get_buffer_info) (const struct audio_stream_out *stream,
struct buf_info **buf);
/**
* Check if next buffer is available. Waits until next buffer is
* available
*/
int (*is_buffer_available) (const struct audio_stream_out *stream,
int *isAvail);
};
typedef struct audio_stream_out audio_stream_out_t;
/**
* audio_broadcast_stream is the abstraction interface for the
* audio output hardware.
*
* It provides information about various properties of the audio output
* hardware driver.
*/
struct audio_broadcast_stream {
struct audio_stream common;
/**
* return the audio hardware driver latency in milli seconds.
*/
uint32_t (*get_latency)(const struct audio_broadcast_stream *stream);
/**
* Use this method in situations where audio mixing is done in the
* hardware. This method serves as a direct interface with hardware,
* allowing you to directly set the volume as apposed to via the framework.
* This method might produce multiple PCM outputs or hardware accelerated
* codecs, such as MP3 or AAC.
*/
int (*set_volume)(struct audio_broadcast_stream *stream, float left, float right);
int (*mute)(struct audio_broadcast_stream *stream, bool mute);
int (*start)(struct audio_broadcast_stream *stream, int64_t absTimeToStart);
/**
* write audio buffer to driver. Returns number of bytes written
*/
ssize_t (*write)(struct audio_broadcast_stream *stream, const void* buffer,
size_t bytes, int64_t timestamp, int audioType);
};
typedef struct audio_broadcast_stream audio_broadcast_stream_t;
struct audio_stream_in {
struct audio_stream common;
/** set the input gain for the audio driver. This method is for
* for future use */
int (*set_gain)(struct audio_stream_in *stream, float gain);
/** Read audio buffer in from audio driver. Returns number of bytes read, or a
* negative status_t. If at least one frame was read prior to the error,
* read should return that byte count and then return an error in the subsequent call.
*/
ssize_t (*read)(struct audio_stream_in *stream, void* buffer,
size_t bytes);
/**
* Return the amount of input frames lost in the audio driver since the
* last call of this function.
* Audio driver is expected to reset the value to 0 and restart counting
* upon returning the current value by this function call.
* Such loss typically occurs when the user space process is blocked
* longer than the capacity of audio driver buffers.
*
* Unit: the number of input audio frames
*/
uint32_t (*get_input_frames_lost)(struct audio_stream_in *stream);
};
typedef struct audio_stream_in audio_stream_in_t;
/**
* return the frame size (number of bytes per sample).
*/
static inline size_t audio_stream_frame_size(struct audio_stream *s)
{
size_t chan_samp_sz;
uint32_t chan_mask = s->get_channels(s);
int format = s->get_format(s);
if (audio_is_input_channel(chan_mask)) {
chan_mask &= (AUDIO_CHANNEL_IN_STEREO | \
AUDIO_CHANNEL_IN_MONO | \
AUDIO_CHANNEL_IN_5POINT1);
}
if(!strcmp(s->get_parameters(s, "voip_flag"),"voip_flag=1")) {
if(format != AUDIO_FORMAT_PCM_8_BIT)
return popcount(chan_mask) * sizeof(int16_t);
else
return popcount(chan_mask) * sizeof(int8_t);
}
switch (format) {
case AUDIO_FORMAT_AMR_NB:
chan_samp_sz = 32;
break;
case AUDIO_FORMAT_EVRC:
chan_samp_sz = 23;
break;
case AUDIO_FORMAT_QCELP:
chan_samp_sz = 35;
break;
case AUDIO_FORMAT_AMR_WB:
chan_samp_sz = 61;
break;
case AUDIO_FORMAT_PCM_16_BIT:
chan_samp_sz = sizeof(int16_t);
break;
case AUDIO_FORMAT_PCM_8_BIT:
default:
chan_samp_sz = sizeof(int8_t);
break;
}
return popcount(chan_mask) * chan_samp_sz;
}
/**********************************************************************/
/**
* Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
* and the fields of this data structure must begin with hw_module_t
* followed by module specific information.
*/
struct audio_module {
struct hw_module_t common;
};
struct audio_hw_device {
struct hw_device_t common;
/**
* used by audio flinger to enumerate what devices are supported by
* each audio_hw_device implementation.
*
* Return value is a bitmask of 1 or more values of audio_devices_t
*/
uint32_t (*get_supported_devices)(const struct audio_hw_device *dev);
/**
* check to see if the audio hardware interface has been initialized.
* returns 0 on success, -ENODEV on failure.
*/
int (*init_check)(const struct audio_hw_device *dev);
/** set the audio volume of a voice call. Range is between 0.0 and 1.0 */
int (*set_voice_volume)(struct audio_hw_device *dev, float volume);
/**
* set the audio volume for all audio activities other than voice call.
* Range between 0.0 and 1.0. If any value other than 0 is returned,
* the software mixer will emulate this capability.
*/
int (*set_master_volume)(struct audio_hw_device *dev, float volume);
/**
* Get the current master volume value for the HAL, if the HAL supports
* master volume control. AudioFlinger will query this value from the
* primary audio HAL when the service starts and use the value for setting
* the initial master volume across all HALs. HALs which do not support
* this method should may leave it set to NULL.
*/
int (*get_master_volume)(struct audio_hw_device *dev, float *volume);
/** set the fm audio volume. Range is between 0.0 and 1.0 */
int (*set_fm_volume)(struct audio_hw_device *dev, float volume);
/**
* set_mode is called when the audio mode changes. AUDIO_MODE_NORMAL mode
* is for standard audio playback, AUDIO_MODE_RINGTONE when a ringtone is
* playing, and AUDIO_MODE_IN_CALL when a call is in progress.
*/
int (*set_mode)(struct audio_hw_device *dev, audio_mode_t mode);
/* mic mute */
int (*set_mic_mute)(struct audio_hw_device *dev, bool state);
int (*get_mic_mute)(const struct audio_hw_device *dev, bool *state);
/* set/get global audio parameters */
int (*set_parameters)(struct audio_hw_device *dev, const char *kv_pairs);
/*
* Returns a pointer to a heap allocated string. The caller is responsible
* for freeing the memory for it using free().
*/
char * (*get_parameters)(const struct audio_hw_device *dev,
const char *keys);
/* Returns audio input buffer size according to parameters passed or
* 0 if one of the parameters is not supported.
* See also get_buffer_size which is for a particular stream.
*/
size_t (*get_input_buffer_size)(const struct audio_hw_device *dev,
const struct audio_config *config);
/** This method creates and opens the audio hardware output stream */
int (*open_output_stream)(struct audio_hw_device *dev,
audio_io_handle_t handle,
audio_devices_t devices,
audio_output_flags_t flags,
struct audio_config *config,
struct audio_stream_out **stream_out);
void (*close_output_stream)(struct audio_hw_device *dev,
struct audio_stream_out* stream_out);
/** This method creates and opens the audio hardware output
* for broadcast stream */
int (*open_broadcast_stream)(struct audio_hw_device *dev, uint32_t devices,
int format, uint32_t channels,
uint32_t sample_rate,
uint32_t audio_source,
struct audio_broadcast_stream **out);
void (*close_broadcast_stream)(struct audio_hw_device *dev,
struct audio_broadcast_stream *out);
/** This method creates and opens the audio hardware input stream */
int (*open_input_stream)(struct audio_hw_device *dev,
audio_io_handle_t handle,
audio_devices_t devices,
struct audio_config *config,
struct audio_stream_in **stream_in);
void (*close_input_stream)(struct audio_hw_device *dev,
struct audio_stream_in *stream_in);
/** This method dumps the state of the audio hardware */
int (*dump)(const struct audio_hw_device *dev, int fd);
};
typedef struct audio_hw_device audio_hw_device_t;
/** convenience API for opening and closing a supported device */
static inline int audio_hw_device_open(const struct hw_module_t* module,
struct audio_hw_device** device)
{
return module->methods->open(module, AUDIO_HARDWARE_INTERFACE,
(struct hw_device_t**)device);
}
static inline int audio_hw_device_close(struct audio_hw_device* device)
{
return device->common.close(&device->common);
}
/** Structure to save buffer information for applying effects for
* LPA buffers */
struct buf_info {
int bufsize;
int nBufs;
int **buffers;
};
#ifdef __cplusplus
/**
*Observer class to post the Events from HAL to Flinger
*/
class AudioEventObserver {
public:
virtual ~AudioEventObserver() {}
virtual void postEOS(int64_t delayUs) = 0;
};
#endif
__END_DECLS
#endif // ANDROID_AUDIO_INTERFACE_H

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,445 @@
/*
* Copyright (C) 2011 The Android Open Source Project
* Copyright (c) 2012, The Linux Foundation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_AUDIO_POLICY_INTERFACE_H
#define ANDROID_AUDIO_POLICY_INTERFACE_H
#include <stdint.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <hardware/hardware.h>
#include <system/audio.h>
#include <system/audio_policy.h>
__BEGIN_DECLS
/**
* The id of this module
*/
#define AUDIO_POLICY_HARDWARE_MODULE_ID "audio_policy"
/**
* Name of the audio devices to open
*/
#define AUDIO_POLICY_INTERFACE "policy"
/* ---------------------------------------------------------------------------- */
/*
* The audio_policy and audio_policy_service_ops structs define the
* communication interfaces between the platform specific audio policy manager
* and Android generic audio policy manager.
* The platform specific audio policy manager must implement methods of the
* audio_policy struct.
* This implementation makes use of the audio_policy_service_ops to control
* the activity and configuration of audio input and output streams.
*
* The platform specific audio policy manager is in charge of the audio
* routing and volume control policies for a given platform.
* The main roles of this module are:
* - keep track of current system state (removable device connections, phone
* state, user requests...).
* System state changes and user actions are notified to audio policy
* manager with methods of the audio_policy.
*
* - process get_output() queries received when AudioTrack objects are
* created: Those queries return a handler on an output that has been
* selected, configured and opened by the audio policy manager and that
* must be used by the AudioTrack when registering to the AudioFlinger
* with the createTrack() method.
* When the AudioTrack object is released, a release_output() query
* is received and the audio policy manager can decide to close or
* reconfigure the output depending on other streams using this output and
* current system state.
*
* - similarly process get_input() and release_input() queries received from
* AudioRecord objects and configure audio inputs.
* - process volume control requests: the stream volume is converted from
* an index value (received from UI) to a float value applicable to each
* output as a function of platform specific settings and current output
* route (destination device). It also make sure that streams are not
* muted if not allowed (e.g. camera shutter sound in some countries).
*/
/* XXX: this should be defined OUTSIDE of frameworks/base */
struct effect_descriptor_s;
struct audio_policy {
/*
* configuration functions
*/
/* indicate a change in device connection status */
int (*set_device_connection_state)(struct audio_policy *pol,
audio_devices_t device,
audio_policy_dev_state_t state,
const char *device_address);
/* retrieve a device connection status */
audio_policy_dev_state_t (*get_device_connection_state)(
const struct audio_policy *pol,
audio_devices_t device,
const char *device_address);
/* indicate a change in phone state. Valid phones states are defined
* by audio_mode_t */
void (*set_phone_state)(struct audio_policy *pol, audio_mode_t state);
/* deprecated, never called (was "indicate a change in ringer mode") */
void (*set_ringer_mode)(struct audio_policy *pol, uint32_t mode,
uint32_t mask);
/* force using a specific device category for the specified usage */
void (*set_force_use)(struct audio_policy *pol,
audio_policy_force_use_t usage,
audio_policy_forced_cfg_t config);
/* retrieve current device category forced for a given usage */
audio_policy_forced_cfg_t (*get_force_use)(const struct audio_policy *pol,
audio_policy_force_use_t usage);
/* if can_mute is true, then audio streams that are marked ENFORCED_AUDIBLE
* can still be muted. */
void (*set_can_mute_enforced_audible)(struct audio_policy *pol,
bool can_mute);
/* check proper initialization */
int (*init_check)(const struct audio_policy *pol);
/*
* Audio routing query functions
*/
/* request an output appropriate for playback of the supplied stream type and
* parameters */
audio_io_handle_t (*get_output)(struct audio_policy *pol,
audio_stream_type_t stream,
uint32_t samplingRate,
audio_format_t format,
uint32_t channels,
audio_output_flags_t flags);
/* indicates to the audio policy manager that the output starts being used
* by corresponding stream. */
int (*start_output)(struct audio_policy *pol,
audio_io_handle_t output,
audio_stream_type_t stream,
int session);
/* indicates to the audio policy manager that the output stops being used
* by corresponding stream. */
int (*stop_output)(struct audio_policy *pol,
audio_io_handle_t output,
audio_stream_type_t stream,
int session);
/* releases the output. */
void (*release_output)(struct audio_policy *pol, audio_io_handle_t output);
/* request an input appropriate for record from the supplied device with
* supplied parameters. */
audio_io_handle_t (*get_input)(struct audio_policy *pol, audio_source_t inputSource,
uint32_t samplingRate,
audio_format_t format,
uint32_t channels,
audio_in_acoustics_t acoustics);
/* indicates to the audio policy manager that the input starts being used */
int (*start_input)(struct audio_policy *pol, audio_io_handle_t input);
/* indicates to the audio policy manager that the input stops being used. */
int (*stop_input)(struct audio_policy *pol, audio_io_handle_t input);
/* releases the input. */
void (*release_input)(struct audio_policy *pol, audio_io_handle_t input);
/*
* volume control functions
*/
/* initialises stream volume conversion parameters by specifying volume
* index range. The index range for each stream is defined by AudioService. */
void (*init_stream_volume)(struct audio_policy *pol,
audio_stream_type_t stream,
int index_min,
int index_max);
/* sets the new stream volume at a level corresponding to the supplied
* index. The index is within the range specified by init_stream_volume() */
int (*set_stream_volume_index)(struct audio_policy *pol,
audio_stream_type_t stream,
int index);
/* retrieve current volume index for the specified stream */
int (*get_stream_volume_index)(const struct audio_policy *pol,
audio_stream_type_t stream,
int *index);
/* sets the new stream volume at a level corresponding to the supplied
* index for the specified device.
* The index is within the range specified by init_stream_volume() */
int (*set_stream_volume_index_for_device)(struct audio_policy *pol,
audio_stream_type_t stream,
int index,
audio_devices_t device);
/* retrieve current volume index for the specified stream for the specified device */
int (*get_stream_volume_index_for_device)(const struct audio_policy *pol,
audio_stream_type_t stream,
int *index,
audio_devices_t device);
/* return the strategy corresponding to a given stream type */
uint32_t (*get_strategy_for_stream)(const struct audio_policy *pol,
audio_stream_type_t stream);
/* return the enabled output devices for the given stream type */
audio_devices_t (*get_devices_for_stream)(const struct audio_policy *pol,
audio_stream_type_t stream);
/* Audio effect management */
audio_io_handle_t (*get_output_for_effect)(struct audio_policy *pol,
struct effect_descriptor_s *desc);
int (*register_effect)(struct audio_policy *pol,
struct effect_descriptor_s *desc,
audio_io_handle_t output,
uint32_t strategy,
int session,
int id);
int (*unregister_effect)(struct audio_policy *pol, int id);
int (*set_effect_enabled)(struct audio_policy *pol, int id, bool enabled);
bool (*is_stream_active)(const struct audio_policy *pol,
audio_stream_type_t stream,
uint32_t in_past_ms);
/* dump state */
int (*dump)(const struct audio_policy *pol, int fd);
};
/* audio hw module handle used by load_hw_module(), open_output_on_module()
* and open_input_on_module() */
typedef int audio_module_handle_t;
struct audio_policy_service_ops {
/*
* Audio output Control functions
*/
/* Opens an audio output with the requested parameters.
*
* The parameter values can indicate to use the default values in case the
* audio policy manager has no specific requirements for the output being
* opened.
*
* When the function returns, the parameter values reflect the actual
* values used by the audio hardware output stream.
*
* The audio policy manager can check if the proposed parameters are
* suitable or not and act accordingly.
*/
audio_io_handle_t (*open_output)(void *service,
audio_devices_t *pDevices,
uint32_t *pSamplingRate,
audio_format_t *pFormat,
audio_channel_mask_t *pChannelMask,
uint32_t *pLatencyMs,
audio_output_flags_t flags);
/* creates a special output that is duplicated to the two outputs passed as
* arguments. The duplication is performed by
* a special mixer thread in the AudioFlinger.
*/
audio_io_handle_t (*open_duplicate_output)(void *service,
audio_io_handle_t output1,
audio_io_handle_t output2);
/* closes the output stream */
int (*close_output)(void *service, audio_io_handle_t output);
/* suspends the output.
*
* When an output is suspended, the corresponding audio hardware output
* stream is placed in standby and the AudioTracks attached to the mixer
* thread are still processed but the output mix is discarded.
*/
int (*suspend_output)(void *service, audio_io_handle_t output);
/* restores a suspended output. */
int (*restore_output)(void *service, audio_io_handle_t output);
/* */
/* Audio input Control functions */
/* */
/* opens an audio input */
audio_io_handle_t (*open_input)(void *service,
audio_devices_t *pDevices,
uint32_t *pSamplingRate,
audio_format_t *pFormat,
audio_channel_mask_t *pChannelMask,
audio_in_acoustics_t acoustics);
/* closes an audio input */
int (*close_input)(void *service, audio_io_handle_t input);
/* */
/* misc control functions */
/* */
/* set a stream volume for a particular output.
*
* For the same user setting, a given stream type can have different
* volumes for each output (destination device) it is attached to.
*/
int (*set_stream_volume)(void *service,
audio_stream_type_t stream,
float volume,
audio_io_handle_t output,
int delay_ms);
/* reroute a given stream type to the specified output */
int (*set_stream_output)(void *service,
audio_stream_type_t stream,
audio_io_handle_t output);
/* function enabling to send proprietary informations directly from audio
* policy manager to audio hardware interface. */
void (*set_parameters)(void *service,
audio_io_handle_t io_handle,
const char *kv_pairs,
int delay_ms);
/* function enabling to receive proprietary informations directly from
* audio hardware interface to audio policy manager.
*
* Returns a pointer to a heap allocated string. The caller is responsible
* for freeing the memory for it using free().
*/
char * (*get_parameters)(void *service, audio_io_handle_t io_handle,
const char *keys);
/* request the playback of a tone on the specified stream.
* used for instance to replace notification sounds when playing over a
* telephony device during a phone call.
*/
int (*start_tone)(void *service,
audio_policy_tone_t tone,
audio_stream_type_t stream);
int (*stop_tone)(void *service);
/* set down link audio volume. */
int (*set_voice_volume)(void *service,
float volume,
int delay_ms);
/* move effect to the specified output */
int (*move_effects)(void *service,
int session,
audio_io_handle_t src_output,
audio_io_handle_t dst_output);
/* set fm audio volume. */
int (*set_fm_volume)(void *service,
float volume,
int delay_ms);
/* loads an audio hw module.
*
* The module name passed is the base name of the HW module library, e.g "primary" or "a2dp".
* The function returns a handle on the module that will be used to specify a particular
* module when calling open_output_on_module() or open_input_on_module()
*/
audio_module_handle_t (*load_hw_module)(void *service,
const char *name);
/* Opens an audio output on a particular HW module.
*
* Same as open_output() but specifying a specific HW module on which the output must be opened.
*/
audio_io_handle_t (*open_output_on_module)(void *service,
audio_module_handle_t module,
audio_devices_t *pDevices,
uint32_t *pSamplingRate,
audio_format_t *pFormat,
audio_channel_mask_t *pChannelMask,
uint32_t *pLatencyMs,
audio_output_flags_t flags);
/* Opens an audio input on a particular HW module.
*
* Same as open_input() but specifying a specific HW module on which the input must be opened.
* Also removed deprecated acoustics parameter
*/
audio_io_handle_t (*open_input_on_module)(void *service,
audio_module_handle_t module,
audio_devices_t *pDevices,
uint32_t *pSamplingRate,
audio_format_t *pFormat,
audio_channel_mask_t *pChannelMask);
};
/**********************************************************************/
/**
* Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
* and the fields of this data structure must begin with hw_module_t
* followed by module specific information.
*/
typedef struct audio_policy_module {
struct hw_module_t common;
} audio_policy_module_t;
struct audio_policy_device {
struct hw_device_t common;
int (*create_audio_policy)(const struct audio_policy_device *device,
struct audio_policy_service_ops *aps_ops,
void *service,
struct audio_policy **ap);
int (*destroy_audio_policy)(const struct audio_policy_device *device,
struct audio_policy *ap);
};
/** convenience API for opening and closing a supported device */
static inline int audio_policy_dev_open(const hw_module_t* module,
struct audio_policy_device** device)
{
return module->methods->open(module, AUDIO_POLICY_INTERFACE,
(hw_device_t**)device);
}
static inline int audio_policy_dev_close(struct audio_policy_device* device)
{
return device->common.close(&device->common);
}
__END_DECLS
#endif // ANDROID_AUDIO_POLICY_INTERFACE_H

View File

@@ -0,0 +1,295 @@
/*
* Copyright (C) 2010-2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_INCLUDE_CAMERA_H
#define ANDROID_INCLUDE_CAMERA_H
#include "camera_common.h"
/**
* Camera device HAL, initial version [ CAMERA_DEVICE_API_VERSION_1_0 ]
*
* Supports the android.hardware.Camera API.
*
* Camera devices that support this version of the HAL must return a value in
* the range HARDWARE_DEVICE_API_VERSION(0,0)-(1,FF) in
* camera_device_t.common.version. CAMERA_DEVICE_API_VERSION_1_0 is the
* recommended value.
*
* Camera modules that implement version 2.0 or higher of camera_module_t must
* also return the value of camera_device_t.common.version in
* camera_info_t.device_version.
*
* See camera_common.h for more details.
*/
__BEGIN_DECLS
struct camera_memory;
typedef void (*camera_release_memory)(struct camera_memory *mem);
typedef struct camera_memory {
void *data;
size_t size;
void *handle;
camera_release_memory release;
} camera_memory_t;
typedef camera_memory_t* (*camera_request_memory)(int fd, size_t buf_size, unsigned int num_bufs,
void *user);
typedef void (*camera_notify_callback)(int32_t msg_type,
int32_t ext1,
int32_t ext2,
void *user);
typedef void (*camera_data_callback)(int32_t msg_type,
const camera_memory_t *data, unsigned int index,
camera_frame_metadata_t *metadata, void *user);
typedef void (*camera_data_timestamp_callback)(int64_t timestamp,
int32_t msg_type,
const camera_memory_t *data, unsigned int index,
void *user);
#define HAL_CAMERA_PREVIEW_WINDOW_TAG 0xcafed00d
typedef struct preview_stream_ops {
int (*dequeue_buffer)(struct preview_stream_ops* w,
buffer_handle_t** buffer, int *stride);
int (*enqueue_buffer)(struct preview_stream_ops* w,
buffer_handle_t* buffer);
int (*cancel_buffer)(struct preview_stream_ops* w,
buffer_handle_t* buffer);
int (*set_buffer_count)(struct preview_stream_ops* w, int count);
int (*set_buffers_geometry)(struct preview_stream_ops* pw,
int w, int h, int format);
int (*set_crop)(struct preview_stream_ops *w,
int left, int top, int right, int bottom);
int (*set_usage)(struct preview_stream_ops* w, int usage);
int (*set_swap_interval)(struct preview_stream_ops *w, int interval);
int (*get_min_undequeued_buffer_count)(const struct preview_stream_ops *w,
int *count);
int (*lock_buffer)(struct preview_stream_ops* w,
buffer_handle_t* buffer);
// Timestamps are measured in nanoseconds, and must be comparable
// and monotonically increasing between two frames in the same
// preview stream. They do not need to be comparable between
// consecutive or parallel preview streams, cameras, or app runs.
int (*set_timestamp)(struct preview_stream_ops *w, int64_t timestamp);
} preview_stream_ops_t;
struct camera_device;
typedef struct camera_device_ops {
/** Set the ANativeWindow to which preview frames are sent */
int (*set_preview_window)(struct camera_device *,
struct preview_stream_ops *window);
/** Set the notification and data callbacks */
void (*set_callbacks)(struct camera_device *,
camera_notify_callback notify_cb,
camera_data_callback data_cb,
camera_data_timestamp_callback data_cb_timestamp,
camera_request_memory get_memory,
void *user);
/**
* The following three functions all take a msg_type, which is a bitmask of
* the messages defined in include/ui/Camera.h
*/
/**
* Enable a message, or set of messages.
*/
void (*enable_msg_type)(struct camera_device *, int32_t msg_type);
/**
* Disable a message, or a set of messages.
*
* Once received a call to disableMsgType(CAMERA_MSG_VIDEO_FRAME), camera
* HAL should not rely on its client to call releaseRecordingFrame() to
* release video recording frames sent out by the cameral HAL before and
* after the disableMsgType(CAMERA_MSG_VIDEO_FRAME) call. Camera HAL
* clients must not modify/access any video recording frame after calling
* disableMsgType(CAMERA_MSG_VIDEO_FRAME).
*/
void (*disable_msg_type)(struct camera_device *, int32_t msg_type);
/**
* Query whether a message, or a set of messages, is enabled. Note that
* this is operates as an AND, if any of the messages queried are off, this
* will return false.
*/
int (*msg_type_enabled)(struct camera_device *, int32_t msg_type);
/**
* Start preview mode.
*/
int (*start_preview)(struct camera_device *);
/**
* Stop a previously started preview.
*/
void (*stop_preview)(struct camera_device *);
/**
* Returns true if preview is enabled.
*/
int (*preview_enabled)(struct camera_device *);
/**
* Request the camera HAL to store meta data or real YUV data in the video
* buffers sent out via CAMERA_MSG_VIDEO_FRAME for a recording session. If
* it is not called, the default camera HAL behavior is to store real YUV
* data in the video buffers.
*
* This method should be called before startRecording() in order to be
* effective.
*
* If meta data is stored in the video buffers, it is up to the receiver of
* the video buffers to interpret the contents and to find the actual frame
* data with the help of the meta data in the buffer. How this is done is
* outside of the scope of this method.
*
* Some camera HALs may not support storing meta data in the video buffers,
* but all camera HALs should support storing real YUV data in the video
* buffers. If the camera HAL does not support storing the meta data in the
* video buffers when it is requested to do do, INVALID_OPERATION must be
* returned. It is very useful for the camera HAL to pass meta data rather
* than the actual frame data directly to the video encoder, since the
* amount of the uncompressed frame data can be very large if video size is
* large.
*
* @param enable if true to instruct the camera HAL to store
* meta data in the video buffers; false to instruct
* the camera HAL to store real YUV data in the video
* buffers.
*
* @return OK on success.
*/
int (*store_meta_data_in_buffers)(struct camera_device *, int enable);
/**
* Start record mode. When a record image is available, a
* CAMERA_MSG_VIDEO_FRAME message is sent with the corresponding
* frame. Every record frame must be released by a camera HAL client via
* releaseRecordingFrame() before the client calls
* disableMsgType(CAMERA_MSG_VIDEO_FRAME). After the client calls
* disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is the camera HAL's
* responsibility to manage the life-cycle of the video recording frames,
* and the client must not modify/access any video recording frames.
*/
int (*start_recording)(struct camera_device *);
/**
* Stop a previously started recording.
*/
void (*stop_recording)(struct camera_device *);
/**
* Returns true if recording is enabled.
*/
int (*recording_enabled)(struct camera_device *);
/**
* Release a record frame previously returned by CAMERA_MSG_VIDEO_FRAME.
*
* It is camera HAL client's responsibility to release video recording
* frames sent out by the camera HAL before the camera HAL receives a call
* to disableMsgType(CAMERA_MSG_VIDEO_FRAME). After it receives the call to
* disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is the camera HAL's
* responsibility to manage the life-cycle of the video recording frames.
*/
void (*release_recording_frame)(struct camera_device *,
const void *opaque);
/**
* Start auto focus, the notification callback routine is called with
* CAMERA_MSG_FOCUS once when focusing is complete. autoFocus() will be
* called again if another auto focus is needed.
*/
int (*auto_focus)(struct camera_device *);
/**
* Cancels auto-focus function. If the auto-focus is still in progress,
* this function will cancel it. Whether the auto-focus is in progress or
* not, this function will return the focus position to the default. If
* the camera does not support auto-focus, this is a no-op.
*/
int (*cancel_auto_focus)(struct camera_device *);
/**
* Take a picture.
*/
int (*take_picture)(struct camera_device *);
/**
* Cancel a picture that was started with takePicture. Calling this method
* when no picture is being taken is a no-op.
*/
int (*cancel_picture)(struct camera_device *);
/**
* Set the camera parameters. This returns BAD_VALUE if any parameter is
* invalid or not supported.
*/
int (*set_parameters)(struct camera_device *, const char *parms);
/** Retrieve the camera parameters. The buffer returned by the camera HAL
must be returned back to it with put_parameters, if put_parameters
is not NULL.
*/
char *(*get_parameters)(struct camera_device *);
/** The camera HAL uses its own memory to pass us the parameters when we
call get_parameters. Use this function to return the memory back to
the camera HAL, if put_parameters is not NULL. If put_parameters
is NULL, then you have to use free() to release the memory.
*/
void (*put_parameters)(struct camera_device *, char *);
/**
* Send command to camera driver.
*/
int (*send_command)(struct camera_device *,
int32_t cmd, int32_t arg1, int32_t arg2);
/**
* Release the hardware resources owned by this object. Note that this is
* *not* done in the destructor.
*/
void (*release)(struct camera_device *);
/**
* Dump state of the camera hardware
*/
int (*dump)(struct camera_device *, int fd);
} camera_device_ops_t;
typedef struct camera_device {
/**
* camera_device.common.version must be in the range
* HARDWARE_DEVICE_API_VERSION(0,0)-(1,FF). CAMERA_DEVICE_API_VERSION_1_0 is
* recommended.
*/
hw_device_t common;
camera_device_ops_t *ops;
void *priv;
} camera_device_t;
__END_DECLS
#endif /* #ifdef ANDROID_INCLUDE_CAMERA_H */

View File

@@ -0,0 +1,311 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_INCLUDE_CAMERA2_H
#define ANDROID_INCLUDE_CAMERA2_H
#include "camera_common.h"
/**
* Camera device HAL 2.0 [ CAMERA_DEVICE_API_VERSION_2_0 ]
*
* EXPERIMENTAL.
*
* Supports both the android.hardware.ProCamera and
* android.hardware.Camera APIs.
*
* Camera devices that support this version of the HAL must return
* CAMERA_DEVICE_API_VERSION_2_0 in camera_device_t.common.version and in
* camera_info_t.device_version (from camera_module_t.get_camera_info).
*
* Camera modules that may contain version 2.0 devices must implement at least
* version 2.0 of the camera module interface (as defined by
* camera_module_t.common.module_api_version).
*
* See camera_common.h for more details.
*
*/
__BEGIN_DECLS
struct camera2_device;
/**
* Output image stream queue management
*/
typedef struct camera2_stream_ops {
int (*dequeue_buffer)(struct camera2_stream_ops* w,
buffer_handle_t** buffer, int *stride);
int (*enqueue_buffer)(struct camera2_stream_ops* w,
buffer_handle_t* buffer);
int (*cancel_buffer)(struct camera2_stream_ops* w,
buffer_handle_t* buffer);
int (*set_buffer_count)(struct camera2_stream_ops* w, int count);
int (*set_buffers_geometry)(struct camera2_stream_ops* pw,
int w, int h, int format);
int (*set_crop)(struct camera2_stream_ops *w,
int left, int top, int right, int bottom);
// Timestamps are measured in nanoseconds, and must be comparable
// and monotonically increasing between two frames in the same
// preview stream. They do not need to be comparable between
// consecutive or parallel preview streams, cameras, or app runs.
// The timestamp must be the time at the start of image exposure.
int (*set_timestamp)(struct camera2_stream_ops *w, int64_t timestamp);
int (*set_usage)(struct camera2_stream_ops* w, int usage);
int (*get_min_undequeued_buffer_count)(const struct camera2_stream_ops *w,
int *count);
int (*lock_buffer)(struct camera2_stream_ops* w,
buffer_handle_t* buffer);
} camera2_stream_ops_t;
/**
* Metadata queue management, used for requests sent to HAL module, and for
* frames produced by the HAL.
*
* Queue protocol:
*
* The source holds the queue and its contents. At start, the queue is empty.
*
* 1. When the first metadata buffer is placed into the queue, the source must
* signal the destination by calling notify_queue_not_empty().
*
* 2. After receiving notify_queue_not_empty, the destination must call
* dequeue() once it's ready to handle the next buffer.
*
* 3. Once the destination has processed a buffer, it should try to dequeue
* another buffer. If there are no more buffers available, dequeue() will
* return NULL. In this case, when a buffer becomes available, the source
* must call notify_queue_not_empty() again. If the destination receives a
* NULL return from dequeue, it does not need to query the queue again until
* a notify_queue_not_empty() call is received from the source.
*
* 4. If the destination calls buffer_count() and receives 0, this does not mean
* that the source will provide a notify_queue_not_empty() call. The source
* must only provide such a call after the destination has received a NULL
* from dequeue, or on initial startup.
*
* 5. The dequeue() call in response to notify_queue_not_empty() may be on the
* same thread as the notify_queue_not_empty() call. The source must not
* deadlock in that case.
*/
typedef struct camera2_metadata_queue_src_ops {
/**
* Get count of buffers in queue
*/
int (*buffer_count)(camera2_metadata_queue_src_ops *q);
/**
* Get a metadata buffer from the source. Returns OK if a request is
* available, placing a pointer to it in next_request.
*/
int (*dequeue)(camera2_metadata_queue_src_ops *q,
camera_metadata_t **buffer);
/**
* Return a metadata buffer to the source once it has been used
*/
int (*free)(camera2_metadata_queue_src_ops *q,
camera_metadata_t *old_buffer);
} camera2_metadata_queue_src_ops_t;
typedef struct camera2_metadata_queue_dst_ops {
/**
* Notify destination that the queue is no longer empty
*/
int (*notify_queue_not_empty)(struct camera2_metadata_queue_dst_ops *);
} camera2_metadata_queue_dst_ops_t;
/* Defined in camera_metadata.h */
typedef struct vendor_tag_query_ops vendor_tag_query_ops_t;
/**
* Asynchronous notification callback from the HAL, fired for various
* reasons. Only for information independent of frame capture, or that require
* specific timing.
*/
typedef void (*camera2_notify_callback)(int32_t msg_type,
int32_t ext1,
int32_t ext2,
void *user);
/**
* Possible message types for camera2_notify_callback
*/
enum {
/**
* A serious error has occurred. Argument ext1 contains the error code, and
* ext2 and user contain any error-specific information.
*/
CAMERA2_MSG_ERROR = 0x0001,
/**
* The exposure of a given request has begun. Argument ext1 contains the
* request id.
*/
CAMERA2_MSG_SHUTTER = 0x0002
};
/**
* Error codes for CAMERA_MSG_ERROR
*/
enum {
/**
* A serious failure occured. Camera device may not work without reboot, and
* no further frames or buffer streams will be produced by the
* device. Device should be treated as closed.
*/
CAMERA2_MSG_ERROR_HARDWARE_FAULT = 0x0001,
/**
* A serious failure occured. No further frames or buffer streams will be
* produced by the device. Device should be treated as closed. The client
* must reopen the device to use it again.
*/
CAMERA2_MSG_ERROR_DEVICE_FAULT = 0x0002,
/**
* The camera service has failed. Device should be treated as released. The client
* must reopen the device to use it again.
*/
CAMERA2_MSG_ERROR_SERVER_FAULT = 0x0003
};
typedef struct camera2_device_ops {
/**
* Input request queue methods
*/
int (*set_request_queue_src_ops)(struct camera2_device *,
camera2_metadata_queue_src_ops *queue_src_ops);
int (*get_request_queue_dst_ops)(struct camera2_device *,
camera2_metadata_queue_dst_ops **queue_dst_ops);
/**
* Input reprocessing queue methods
*/
int (*set_reprocess_queue_ops)(struct camera2_device *,
camera2_metadata_queue_src_ops *queue_src_ops);
int (*get_reprocess_queue_dst_ops)(struct camera2_device *,
camera2_metadata_queue_dst_ops **queue_dst_ops);
/**
* Output frame queue methods
*/
int (*set_frame_queue_dst_ops)(struct camera2_device *,
camera2_metadata_queue_dst_ops *queue_dst_ops);
int (*get_frame_queue_src_ops)(struct camera2_device *,
camera2_metadata_queue_src_ops **queue_dst_ops);
/**
* Pass in notification methods
*/
int (*set_notify_callback)(struct camera2_device *,
camera2_notify_callback notify_cb);
/**
* Number of camera frames being processed by the device
* at the moment (frames that have had their request dequeued,
* but have not yet been enqueued onto output pipeline(s) )
*/
int (*get_in_progress_count)(struct camera2_device *);
/**
* Flush all in-progress captures. This includes all dequeued requests
* (regular or reprocessing) that have not yet placed any outputs into a
* stream or the frame queue. Partially completed captures must be completed
* normally. No new requests may be dequeued from the request or
* reprocessing queues until the flush completes.
*/
int (*flush_captures_in_progress)(struct camera2_device *);
/**
* Camera stream management
*/
/**
* Operations on the input reprocessing stream
*/
int (*get_reprocess_stream_ops)(struct camera2_device *,
camera2_stream_ops_t **stream_ops);
/**
* Get the number of streams that can be simultaneously allocated.
* A request may include any allocated pipeline for its output, without
* causing a substantial delay in frame production.
*/
int (*get_stream_slot_count)(struct camera2_device *);
/**
* Allocate a new stream for use. Requires specifying which pipeline slot
* to use. Specifies the buffer width, height, and format.
* Error conditions:
* - Allocating an already-allocated slot without first releasing it
* - Requesting a width/height/format combination not listed as supported
* - Requesting a pipeline slot >= pipeline slot count.
*/
int (*allocate_stream)(
struct camera2_device *,
uint32_t stream_slot,
uint32_t width,
uint32_t height,
uint32_t format,
camera2_stream_ops_t *camera2_stream_ops);
/**
* Release a stream. Returns an error if called when
* get_in_progress_count is non-zero, or if the pipeline slot is not
* allocated.
*/
int (*release_stream)(
struct camera2_device *,
uint32_t stream_slot);
/**
* Get methods to query for vendor extension metadata tag infomation. May
* set ops to NULL if no vendor extension tags are defined.
*/
int (*get_metadata_vendor_tag_ops)(struct camera2_device*,
vendor_tag_query_ops_t **ops);
/**
* Release the camera hardware. Requests that are in flight will be
* canceled. No further buffers will be pushed into any allocated pipelines
* once this call returns.
*/
void (*release)(struct camera2_device *);
/**
* Dump state of the camera hardware
*/
int (*dump)(struct camera2_device *, int fd);
} camera2_device_ops_t;
typedef struct camera2_device {
/**
* common.version must equal CAMERA_DEVICE_API_VERSION_2_0 to identify
* this device as implementing version 2.0 of the camera device HAL.
*/
hw_device_t common;
camera2_device_ops_t *ops;
void *priv;
} camera2_device_t;
__END_DECLS
#endif /* #ifdef ANDROID_INCLUDE_CAMERA2_H */

View File

@@ -0,0 +1,164 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// FIXME: add well-defined names for cameras
#ifndef ANDROID_INCLUDE_CAMERA_COMMON_H
#define ANDROID_INCLUDE_CAMERA_COMMON_H
#include <stdint.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <cutils/native_handle.h>
#include <system/camera.h>
#include <hardware/hardware.h>
#include <hardware/gralloc.h>
__BEGIN_DECLS
/**
* The id of this module
*/
#define CAMERA_HARDWARE_MODULE_ID "camera"
/**
* Module versioning information for the Camera hardware module, based on
* camera_module_t.common.module_api_version. The two most significant hex
* digits represent the major version, and the two least significant represent
* the minor version.
*
*******************************************************************************
* Versions: 0.X - 1.X [CAMERA_MODULE_API_VERSION_1_0]
*
* Camera modules that report these version numbers implement the initial
* camera module HAL interface. All camera devices openable through this
* module support only version 1 of the camera device HAL. The device_version
* and static_camera_characteristics fields of camera_info are not valid. Only
* the android.hardware.Camera API can be supported by this module and its
* devices.
*
*******************************************************************************
* Version: 2.0 [CAMERA_MODULE_API_VERSION_2_0]
*
* Camera modules that report this version number implement the second version
* of the camera module HAL interface. Camera devices openable through this
* module may support either version 1.0 or version 2.0 of the camera device
* HAL interface. The device_version field of camera_info is always valid; the
* static_camera_characteristics field of camera_info is valid if the
* device_version field is 2.0 or higher.
*/
/**
* Predefined macros for currently-defined version numbers
*/
/**
* All module versions <= HARDWARE_MODULE_API_VERSION(1, 0xFF) must be treated
* as CAMERA_MODULE_API_VERSION_1_0
*/
#define CAMERA_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
#define CAMERA_MODULE_API_VERSION_2_0 HARDWARE_MODULE_API_VERSION(2, 0)
#define CAMERA_MODULE_API_VERSION_CURRENT CAMERA_MODULE_API_VERSION_2_0
/**
* All device versions <= HARDWARE_DEVICE_API_VERSION(1, 0xFF) must be treated
* as CAMERA_DEVICE_API_VERSION_1_0
*/
#define CAMERA_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
#define CAMERA_DEVICE_API_VERSION_2_0 HARDWARE_DEVICE_API_VERSION(2, 0)
// Device version 2.0 is experimental
#define CAMERA_DEVICE_API_VERSION_CURRENT CAMERA_DEVICE_API_VERSION_1_0
/**
* Defined in /system/media/camera/include/system/camera_metadata.h
*/
typedef struct camera_metadata camera_metadata_t;
struct camera_info {
/**
* The direction that the camera faces to. It should be CAMERA_FACING_BACK
* or CAMERA_FACING_FRONT.
*
* Version information:
* Valid in all camera_module versions
*/
int facing;
/**
* The orientation of the camera image. The value is the angle that the
* camera image needs to be rotated clockwise so it shows correctly on the
* display in its natural orientation. It should be 0, 90, 180, or 270.
*
* For example, suppose a device has a naturally tall screen. The
* back-facing camera sensor is mounted in landscape. You are looking at
* the screen. If the top side of the camera sensor is aligned with the
* right edge of the screen in natural orientation, the value should be
* 90. If the top side of a front-facing camera sensor is aligned with the
* right of the screen, the value should be 270.
*
* Version information:
* Valid in all camera_module versions
*/
int orientation;
/**
* The value of camera_device_t.common.version.
*
* Version information (based on camera_module_t.common.module_api_version):
*
* CAMERA_MODULE_API_VERSION_1_0:
*
* Not valid. Can be assumed to be CAMERA_DEVICE_API_VERSION_1_0. Do
* not read this field.
*
* CAMERA_MODULE_API_VERSION_2_0:
*
* Always valid
*
*/
uint32_t device_version;
/**
* The camera's fixed characteristics, which include all camera metadata in
* the android.*.info.* sections.
*
* Version information (based on camera_module_t.common.module_api_version):
*
* CAMERA_MODULE_API_VERSION_1_0:
*
* Not valid. Extra characteristics are not available. Do not read this
* field.
*
* CAMERA_MODULE_API_VERSION_2_0:
*
* Valid if device_version >= CAMERA_DEVICE_API_VERSION_2_0. Do not read
* otherwise.
*
*/
camera_metadata_t *static_camera_characteristics;
};
typedef struct camera_module {
hw_module_t common;
int (*get_number_of_cameras)(void);
int (*get_camera_info)(int camera_id, struct camera_info *info);
} camera_module_t;
__END_DECLS
#endif /* ANDROID_INCLUDE_CAMERA_COMMON_H */

View File

@@ -0,0 +1,167 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_FB_INTERFACE_H
#define ANDROID_FB_INTERFACE_H
#include <stdint.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <cutils/native_handle.h>
#include <hardware/hardware.h>
__BEGIN_DECLS
#define GRALLOC_HARDWARE_FB0 "fb0"
/*****************************************************************************/
/*****************************************************************************/
typedef struct framebuffer_device_t {
struct hw_device_t common;
/* flags describing some attributes of the framebuffer */
const uint32_t flags;
/* dimensions of the framebuffer in pixels */
const uint32_t width;
const uint32_t height;
/* frambuffer stride in pixels */
const int stride;
/* framebuffer pixel format */
const int format;
/* resolution of the framebuffer's display panel in pixel per inch*/
const float xdpi;
const float ydpi;
/* framebuffer's display panel refresh rate in frames per second */
const float fps;
/* min swap interval supported by this framebuffer */
const int minSwapInterval;
/* max swap interval supported by this framebuffer */
const int maxSwapInterval;
/* Number of framebuffers supported*/
const int numFramebuffers;
int reserved[7];
/*
* requests a specific swap-interval (same definition than EGL)
*
* Returns 0 on success or -errno on error.
*/
int (*setSwapInterval)(struct framebuffer_device_t* window,
int interval);
/*
* This hook is OPTIONAL.
*
* It is non NULL If the framebuffer driver supports "update-on-demand"
* and the given rectangle is the area of the screen that gets
* updated during (*post)().
*
* This is useful on devices that are able to DMA only a portion of
* the screen to the display panel, upon demand -- as opposed to
* constantly refreshing the panel 60 times per second, for instance.
*
* Only the area defined by this rectangle is guaranteed to be valid, that
* is, the driver is not allowed to post anything outside of this
* rectangle.
*
* The rectangle evaluated during (*post)() and specifies which area
* of the buffer passed in (*post)() shall to be posted.
*
* return -EINVAL if width or height <=0, or if left or top < 0
*/
int (*setUpdateRect)(struct framebuffer_device_t* window,
int left, int top, int width, int height);
/*
* Post <buffer> to the display (display it on the screen)
* The buffer must have been allocated with the
* GRALLOC_USAGE_HW_FB usage flag.
* buffer must be the same width and height as the display and must NOT
* be locked.
*
* The buffer is shown during the next VSYNC.
*
* If the same buffer is posted again (possibly after some other buffer),
* post() will block until the the first post is completed.
*
* Internally, post() is expected to lock the buffer so that a
* subsequent call to gralloc_module_t::(*lock)() with USAGE_RENDER or
* USAGE_*_WRITE will block until it is safe; that is typically once this
* buffer is shown and another buffer has been posted.
*
* Returns 0 on success or -errno on error.
*/
int (*post)(struct framebuffer_device_t* dev, buffer_handle_t buffer);
/*
* The (*compositionComplete)() method must be called after the
* compositor has finished issuing GL commands for client buffers.
*/
int (*compositionComplete)(struct framebuffer_device_t* dev);
/*
* This hook is OPTIONAL.
*
* If non NULL it will be caused by SurfaceFlinger on dumpsys
*/
void (*dump)(struct framebuffer_device_t* dev, char *buff, int buff_len);
/*
* (*enableScreen)() is used to either blank (enable=0) or
* unblank (enable=1) the screen this framebuffer is attached to.
*
* Returns 0 on success or -errno on error.
*/
int (*enableScreen)(struct framebuffer_device_t* dev, int enable);
void* reserved_proc[6];
} framebuffer_device_t;
/** convenience API for opening and closing a supported device */
static inline int framebuffer_open(const struct hw_module_t* module,
struct framebuffer_device_t** device) {
return module->methods->open(module,
GRALLOC_HARDWARE_FB0, (struct hw_device_t**)device);
}
static inline int framebuffer_close(struct framebuffer_device_t* device) {
return device->common.close(&device->common);
}
__END_DECLS
#endif // ANDROID_FB_INTERFACE_H

View File

@@ -0,0 +1,95 @@
/*
* Copyright (c) 2012 The Linux Foundation. All rights reserved.
* Copyright (C) 2010-2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_INCLUDE_GESTURES_H
#define ANDROID_INCLUDE_GESTURES_H
#include <hardware/hardware.h>
#include <system/gestures.h>
__BEGIN_DECLS
/**
* The id of this module
*/
#define GESTURE_HARDWARE_MODULE_ID "gestures"
typedef void (*gesture_notify_callback)(int32_t msg_type,
int32_t ext1,
int32_t ext2,
void *user);
typedef void (*gesture_data_callback)(gesture_result_t* gs_results,
void *user);
struct gesture_device;
typedef struct gesture_device_ops {
/** Set the notification and data callbacks */
void (*set_callbacks)(struct gesture_device *,
gesture_notify_callback notify_cb,
gesture_data_callback data_cb,
void *user,
bool isreg);
/**
* Start gesture.
*/
int (*start)(struct gesture_device *);
/**
* Stop gesture.
*/
void (*stop)(struct gesture_device *);
/**
* Set the vision parameters. This returns BAD_VALUE if any
* parameter is invalid or not supported.
*/
int (*set_parameters)(struct gesture_device *, const char *parms);
/** Retrieve the vision parameters. The buffer returned by the
camera HAL must be returned back to it with put_parameters,
if put_parameters is not NULL.
*/
char *(*get_parameters)(struct gesture_device *);
/**
* Send command to vision driver.
*/
int (*send_command)(struct gesture_device *,
int32_t cmd, int32_t arg1, int32_t arg2);
/**
* Dump state of the gesture device
*/
int (*dump)(struct gesture_device *, int fd);
} gesture_device_ops_t;
typedef struct gesture_device {
hw_device_t common;
gesture_device_ops_t *ops;
void *priv;
} gesture_device_t;
typedef struct gesture_module {
hw_module_t common;
int (*get_number_of_gesture_devices)(void);
} gesture_module_t;
__END_DECLS
#endif /* ANDROID_INCLUDE_GESTURES_H */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,273 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_GRALLOC_INTERFACE_H
#define ANDROID_GRALLOC_INTERFACE_H
#include <system/window.h>
#include <hardware/hardware.h>
#include <stdint.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <cutils/native_handle.h>
#include <hardware/hardware.h>
#include <hardware/fb.h>
__BEGIN_DECLS
#define GRALLOC_API_VERSION 1
/**
* The id of this module
*/
#define GRALLOC_HARDWARE_MODULE_ID "gralloc"
/**
* Name of the graphics device to open
*/
#define GRALLOC_HARDWARE_GPU0 "gpu0"
enum {
/* buffer is never read in software */
GRALLOC_USAGE_SW_READ_NEVER = 0x00000000,
/* buffer is rarely read in software */
GRALLOC_USAGE_SW_READ_RARELY = 0x00000002,
/* buffer is often read in software */
GRALLOC_USAGE_SW_READ_OFTEN = 0x00000003,
/* mask for the software read values */
GRALLOC_USAGE_SW_READ_MASK = 0x0000000F,
/* buffer is never written in software */
GRALLOC_USAGE_SW_WRITE_NEVER = 0x00000000,
/* buffer is never written in software */
GRALLOC_USAGE_SW_WRITE_RARELY = 0x00000020,
/* buffer is never written in software */
GRALLOC_USAGE_SW_WRITE_OFTEN = 0x00000030,
/* mask for the software write values */
GRALLOC_USAGE_SW_WRITE_MASK = 0x000000F0,
/* buffer will be used as an OpenGL ES texture */
GRALLOC_USAGE_HW_TEXTURE = 0x00000100,
/* buffer will be used as an OpenGL ES render target */
GRALLOC_USAGE_HW_RENDER = 0x00000200,
/* buffer will be used by the 2D hardware blitter */
GRALLOC_USAGE_HW_2D = 0x00000400,
/* buffer will be used by the HWComposer HAL module */
GRALLOC_USAGE_HW_COMPOSER = 0x00000800,
/* buffer will be used with the framebuffer device */
GRALLOC_USAGE_HW_FB = 0x00001000,
/* buffer will be used with the HW video encoder */
GRALLOC_USAGE_HW_VIDEO_ENCODER = 0x00010000,
/* mask for the software usage bit-mask */
GRALLOC_USAGE_HW_MASK = 0x00011F00,
/* buffer should be displayed full-screen on an external display when
* possible
*/
GRALLOC_USAGE_EXTERNAL_DISP = 0x00002000,
/* Must have a hardware-protected path to external display sink for
* this buffer. If a hardware-protected path is not available, then
* either don't composite only this buffer (preferred) to the
* external sink, or (less desirable) do not route the entire
* composition to the external sink.
*/
GRALLOC_USAGE_PROTECTED = 0x00004000,
/* implementation-specific private usage flags */
GRALLOC_USAGE_PRIVATE_0 = 0x10000000,
GRALLOC_USAGE_PRIVATE_1 = 0x20000000,
GRALLOC_USAGE_PRIVATE_2 = 0x40000000,
GRALLOC_USAGE_PRIVATE_3 = 0x80000000,
GRALLOC_USAGE_PRIVATE_MASK = 0xF0000000,
};
/*****************************************************************************/
/**
* Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
* and the fields of this data structure must begin with hw_module_t
* followed by module specific information.
*/
typedef struct gralloc_module_t {
struct hw_module_t common;
/*
* (*registerBuffer)() must be called before a buffer_handle_t that has not
* been created with (*alloc_device_t::alloc)() can be used.
*
* This is intended to be used with buffer_handle_t's that have been
* received in this process through IPC.
*
* This function checks that the handle is indeed a valid one and prepares
* it for use with (*lock)() and (*unlock)().
*
* It is not necessary to call (*registerBuffer)() on a handle created
* with (*alloc_device_t::alloc)().
*
* returns an error if this buffer_handle_t is not valid.
*/
int (*registerBuffer)(struct gralloc_module_t const* module,
buffer_handle_t handle);
/*
* (*unregisterBuffer)() is called once this handle is no longer needed in
* this process. After this call, it is an error to call (*lock)(),
* (*unlock)(), or (*registerBuffer)().
*
* This function doesn't close or free the handle itself; this is done
* by other means, usually through libcutils's native_handle_close() and
* native_handle_free().
*
* It is an error to call (*unregisterBuffer)() on a buffer that wasn't
* explicitly registered first.
*/
int (*unregisterBuffer)(struct gralloc_module_t const* module,
buffer_handle_t handle);
/*
* The (*lock)() method is called before a buffer is accessed for the
* specified usage. This call may block, for instance if the h/w needs
* to finish rendering or if CPU caches need to be synchronized.
*
* The caller promises to modify only pixels in the area specified
* by (l,t,w,h).
*
* The content of the buffer outside of the specified area is NOT modified
* by this call.
*
* If usage specifies GRALLOC_USAGE_SW_*, vaddr is filled with the address
* of the buffer in virtual memory.
*
* THREADING CONSIDERATIONS:
*
* It is legal for several different threads to lock a buffer from
* read access, none of the threads are blocked.
*
* However, locking a buffer simultaneously for write or read/write is
* undefined, but:
* - shall not result in termination of the process
* - shall not block the caller
* It is acceptable to return an error or to leave the buffer's content
* into an indeterminate state.
*
* If the buffer was created with a usage mask incompatible with the
* requested usage flags here, -EINVAL is returned.
*
*/
int (*lock)(struct gralloc_module_t const* module,
buffer_handle_t handle, int usage,
int l, int t, int w, int h,
void** vaddr);
/*
* The (*unlock)() method must be called after all changes to the buffer
* are completed.
*/
int (*unlock)(struct gralloc_module_t const* module,
buffer_handle_t handle);
/* reserved for future use */
int (*perform)(struct gralloc_module_t const* module,
int operation, ... );
/* reserved for future use */
void* reserved_proc[7];
} gralloc_module_t;
/*****************************************************************************/
/**
* Every device data structure must begin with hw_device_t
* followed by module specific public methods and attributes.
*/
typedef struct alloc_device_t {
struct hw_device_t common;
/*
* (*allocSize)() Allocates a buffer in graphic memory with the requested
* bufferSize parameter and returns a buffer_handle_t and the stride in
* pixels to allow the implementation to satisfy hardware constraints on
* the width of a pixmap (eg: it may have to be multiple of 8 pixels).
* The CALLER TAKES OWNERSHIP of the buffer_handle_t.
*
* Returns 0 on success or -errno on error.
*/
int (*allocSize)(struct alloc_device_t* dev,
int w, int h, int format, int usage,
buffer_handle_t* handle, int* stride, int bufferSize);
/*
* (*alloc)() Allocates a buffer in graphic memory with the requested
* parameters and returns a buffer_handle_t and the stride in pixels to
* allow the implementation to satisfy hardware constraints on the width
* of a pixmap (eg: it may have to be multiple of 8 pixels).
* The CALLER TAKES OWNERSHIP of the buffer_handle_t.
*
* Returns 0 on success or -errno on error.
*/
int (*alloc)(struct alloc_device_t* dev,
int w, int h, int format, int usage,
buffer_handle_t* handle, int* stride);
/*
* (*free)() Frees a previously allocated buffer.
* Behavior is undefined if the buffer is still mapped in any process,
* but shall not result in termination of the program or security breaches
* (allowing a process to get access to another process' buffers).
* THIS FUNCTION TAKES OWNERSHIP of the buffer_handle_t which becomes
* invalid after the call.
*
* Returns 0 on success or -errno on error.
*/
int (*free)(struct alloc_device_t* dev,
buffer_handle_t handle);
/* This hook is OPTIONAL.
*
* If non NULL it will be caused by SurfaceFlinger on dumpsys
*/
void (*dump)(struct alloc_device_t *dev, char *buff, int buff_len);
void* reserved_proc[7];
} alloc_device_t;
/** convenience API for opening and closing a supported device */
static inline int gralloc_open(const struct hw_module_t* module,
struct alloc_device_t** device) {
return module->methods->open(module,
GRALLOC_HARDWARE_GPU0, (struct hw_device_t**)device);
}
static inline int gralloc_close(struct alloc_device_t* device) {
return device->common.close(&device->common);
}
__END_DECLS
#endif // ANDROID_GRALLOC_INTERFACE_H

View File

@@ -0,0 +1,233 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_INCLUDE_HARDWARE_HARDWARE_H
#define ANDROID_INCLUDE_HARDWARE_HARDWARE_H
#include <stdint.h>
#include <sys/cdefs.h>
#include <cutils/native_handle.h>
__BEGIN_DECLS
/*
* Value for the hw_module_t.tag field
*/
#define MAKE_TAG_CONSTANT(A,B,C,D) (((A) << 24) | ((B) << 16) | ((C) << 8) | (D))
#define HARDWARE_MODULE_TAG MAKE_TAG_CONSTANT('H', 'W', 'M', 'T')
#define HARDWARE_DEVICE_TAG MAKE_TAG_CONSTANT('H', 'W', 'D', 'T')
#define IS_TARGET_MPQ(status) \
{ \
int id = 0; \
FILE *fp; \
if ((fp = fopen("/sys/devices/system/soc/soc0/id", "r")) != NULL) { \
fscanf(fp, "%d", &id); \
fclose(fp); \
} \
if (id == 130) \
status = 1; \
else \
status = 0;\
}
#define HARDWARE_MAKE_API_VERSION(maj,min) \
((((maj) & 0xff) << 8) | ((min) & 0xff))
/*
* The current HAL API version.
*
* All module implementations must set the hw_module_t.hal_api_version field
* to this value when declaring the module with HAL_MODULE_INFO_SYM.
*
* Note that previous implementations have always set this field to 0.
* Therefore, libhardware HAL API will always consider versions 0.0 and 1.0
* to be 100% binary compatible.
*
*/
#define HARDWARE_HAL_API_VERSION HARDWARE_MAKE_API_VERSION(1, 0)
/*
* Helper macros for module implementors.
*
* The derived modules should provide convenience macros for supported
* versions so that implementations can explicitly specify module/device
* versions at definition time.
*
* Use this macro to set the hw_module_t.module_api_version field.
*/
#define HARDWARE_MODULE_API_VERSION(maj,min) HARDWARE_MAKE_API_VERSION(maj,min)
/*
* Use this macro to set the hw_device_t.version field
*/
#define HARDWARE_DEVICE_API_VERSION(maj,min) HARDWARE_MAKE_API_VERSION(maj,min)
struct hw_module_t;
struct hw_module_methods_t;
struct hw_device_t;
/**
* Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
* and the fields of this data structure must begin with hw_module_t
* followed by module specific information.
*/
typedef struct hw_module_t {
/** tag must be initialized to HARDWARE_MODULE_TAG */
uint32_t tag;
/**
* The API version of the implemented module. The module owner is
* responsible for updating the version when a module interface has
* changed.
*
* The derived modules such as gralloc and audio own and manage this field.
* The module user must interpret the version field to decide whether or
* not to inter-operate with the supplied module implementation.
* For example, SurfaceFlinger is responsible for making sure that
* it knows how to manage different versions of the gralloc-module API,
* and AudioFlinger must know how to do the same for audio-module API.
*
* The module API version should include a major and a minor component.
* For example, version 1.0 could be represented as 0x0100. This format
* implies that versions 0x0100-0x01ff are all API-compatible.
*
* In the future, libhardware will expose a hw_get_module_version()
* (or equivalent) function that will take minimum/maximum supported
* versions as arguments and would be able to reject modules with
* versions outside of the supplied range.
*/
uint16_t module_api_version;
#define version_major module_api_version
/**
* version_major/version_minor defines are supplied here for temporary
* source code compatibility. They will be removed in the next version.
* ALL clients must convert to the new version format.
*/
/**
* The API version of the HAL module interface. This is meant to
* version the hw_module_t, hw_module_methods_t, and hw_device_t
* structures and definitions.
*
* The HAL interface owns this field. Module users/implementations
* must NOT rely on this value for version information.
*
* Presently, 0 is the only valid value.
*/
uint16_t hal_api_version;
#define version_minor hal_api_version
/** Identifier of module */
const char *id;
/** Name of this module */
const char *name;
/** Author/owner/implementor of the module */
const char *author;
/** Modules methods */
struct hw_module_methods_t* methods;
/** module's dso */
void* dso;
/** padding to 128 bytes, reserved for future use */
uint32_t reserved[32-7];
} hw_module_t;
typedef struct hw_module_methods_t {
/** Open a specific device */
int (*open)(const struct hw_module_t* module, const char* id,
struct hw_device_t** device);
} hw_module_methods_t;
/**
* Every device data structure must begin with hw_device_t
* followed by module specific public methods and attributes.
*/
typedef struct hw_device_t {
/** tag must be initialized to HARDWARE_DEVICE_TAG */
uint32_t tag;
/**
* Version of the module-specific device API. This value is used by
* the derived-module user to manage different device implementations.
*
* The module user is responsible for checking the module_api_version
* and device version fields to ensure that the user is capable of
* communicating with the specific module implementation.
*
* One module can support multiple devices with different versions. This
* can be useful when a device interface changes in an incompatible way
* but it is still necessary to support older implementations at the same
* time. One such example is the Camera 2.0 API.
*
* This field is interpreted by the module user and is ignored by the
* HAL interface itself.
*/
uint32_t version;
/** reference to the module this device belongs to */
struct hw_module_t* module;
/** padding reserved for future use */
uint32_t reserved[12];
/** Close this device */
int (*close)(struct hw_device_t* device);
} hw_device_t;
/**
* Name of the hal_module_info
*/
#define HAL_MODULE_INFO_SYM HMI
/**
* Name of the hal_module_info as a string
*/
#define HAL_MODULE_INFO_SYM_AS_STR "HMI"
/**
* Get the module info associated with a module by id.
*
* @return: 0 == success, <0 == error and *module == NULL
*/
int hw_get_module(const char *id, const struct hw_module_t **module);
/**
* Get the module info associated with a module instance by class 'class_id'
* and instance 'inst'.
*
* Some modules types necessitate multiple instances. For example audio supports
* multiple concurrent interfaces and thus 'audio' is the module class
* and 'primary' or 'a2dp' are module interfaces. This implies that the files
* providing these modules would be named audio.primary.<variant>.so and
* audio.a2dp.<variant>.so
*
* @return: 0 == success, <0 == error and *module == NULL
*/
int hw_get_module_by_class(const char *class_id, const char *inst,
const struct hw_module_t **module);
__END_DECLS
#endif /* ANDROID_INCLUDE_HARDWARE_HARDWARE_H */

View File

@@ -0,0 +1,387 @@
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_INCLUDE_HARDWARE_HWCOMPOSER_H
#define ANDROID_INCLUDE_HARDWARE_HWCOMPOSER_H
#include <stdint.h>
#include <sys/cdefs.h>
#include <hardware/gralloc.h>
#include <hardware/hardware.h>
#include <cutils/native_handle.h>
#include <hardware/hwcomposer_defs.h>
__BEGIN_DECLS
/*****************************************************************************/
// for compatibility
#define HWC_MODULE_API_VERSION HWC_MODULE_API_VERSION_0_1
#define HWC_DEVICE_API_VERSION HWC_DEVICE_API_VERSION_0_1
#define HWC_API_VERSION HWC_DEVICE_API_VERSION
/**
* The id of this module
*/
#define HWC_HARDWARE_MODULE_ID "hwcomposer"
/**
* Name of the sensors device to open
*/
#define HWC_HARDWARE_COMPOSER "composer"
struct hwc_composer_device;
/*
* availability: HWC_DEVICE_API_VERSION_0_3
*
* struct hwc_methods cannot be embedded in other structures as
* sizeof(struct hwc_methods) cannot be relied upon.
*
*/
typedef struct hwc_methods {
/*************************************************************************
* HWC_DEVICE_API_VERSION_0_3
*************************************************************************/
/*
* eventControl(..., event, value)
* Enables or disables h/w composer events.
*
* eventControl can be called from any thread and takes effect
* immediately.
*
* Supported events are:
* HWC_EVENT_VSYNC
* HWC_EVENT_ORIENTATION
*
* returns -EINVAL if the "event" parameter is not one of the value above
* or if the "value" parameter is not 0 or 1 for HWC_EVENT_VSYNC.
* and if the "value" parameter is not going to be just 0 or 1 for
* HWC_EVENT_ORIENTATION
*/
int (*eventControl)(
struct hwc_composer_device* dev, int event, int value);
} hwc_methods_t;
typedef struct hwc_rect {
int left;
int top;
int right;
int bottom;
} hwc_rect_t;
typedef struct hwc_region {
size_t numRects;
hwc_rect_t const* rects;
} hwc_region_t;
typedef struct hwc_color {
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t a;
} hwc_color_t;
typedef struct hwc_layer {
/*
* initially set to HWC_FRAMEBUFFER or HWC_BACKGROUND.
* HWC_FRAMEBUFFER
* indicates the layer will be drawn into the framebuffer
* using OpenGL ES.
* The HWC can toggle this value to HWC_OVERLAY, to indicate
* it will handle the layer.
*
* HWC_BACKGROUND
* indicates this is a special "background" layer. The only valid
* field is backgroundColor. HWC_BACKGROUND can only be used with
* HWC_API_VERSION >= 0.2
* The HWC can toggle this value to HWC_FRAMEBUFFER, to indicate
* it CANNOT handle the background color
*
*/
int32_t compositionType;
/* see hwc_layer_t::hints above */
uint32_t hints;
/* see hwc_layer_t::flags above */
uint32_t flags;
union {
/* color of the background. hwc_color_t.a is ignored */
hwc_color_t backgroundColor;
struct {
/* handle of buffer to compose. This handle is guaranteed to have been
* allocated from gralloc using the GRALLOC_USAGE_HW_COMPOSER usage flag. If
* the layer's handle is unchanged across two consecutive prepare calls and
* the HWC_GEOMETRY_CHANGED flag is not set for the second call then the
* HWComposer implementation may assume that the contents of the buffer have
* not changed. */
buffer_handle_t handle;
/* transformation to apply to the buffer during composition */
uint32_t transform;
/* source transform of the buffer */
uint32_t sourceTransform;
/* blending to apply during composition */
int32_t blending;
/* area of the source to consider, the origin is the top-left corner of
* the buffer */
hwc_rect_t sourceCrop;
/* where to composite the sourceCrop onto the display. The sourceCrop
* is scaled using linear filtering to the displayFrame. The origin is the
* top-left corner of the screen.
*/
hwc_rect_t displayFrame;
/* visible region in screen space. The origin is the
* top-left corner of the screen.
* The visible region INCLUDES areas overlapped by a translucent layer.
*/
hwc_region_t visibleRegionScreen;
};
};
} hwc_layer_t;
/*
* hwc_layer_list_t::flags values
*/
enum {
/*
* HWC_GEOMETRY_CHANGED is set by SurfaceFlinger to indicate that the list
* passed to (*prepare)() has changed by more than just the buffer handles.
*/
HWC_GEOMETRY_CHANGED = 0x00000001,
};
/*
* List of layers.
* The handle members of hwLayers elements must be unique.
*/
typedef struct hwc_layer_list {
uint32_t flags;
size_t numHwLayers;
hwc_layer_t hwLayers[0];
} hwc_layer_list_t;
/* This represents a display, typically an EGLDisplay object */
typedef void* hwc_display_t;
/* This represents a surface, typically an EGLSurface object */
typedef void* hwc_surface_t;
/* see hwc_composer_device::registerProcs()
* Any of the callbacks can be NULL, in which case the corresponding
* functionality is not supported.
*/
typedef struct hwc_procs {
/*
* (*invalidate)() triggers a screen refresh, in particular prepare and set
* will be called shortly after this call is made. Note that there is
* NO GUARANTEE that the screen refresh will happen after invalidate()
* returns (in particular, it could happen before).
* invalidate() is GUARANTEED TO NOT CALL BACK into the h/w composer HAL and
* it is safe to call invalidate() from any of hwc_composer_device
* hooks, unless noted otherwise.
*/
void (*invalidate)(struct hwc_procs* procs);
/*
* (*vsync)() is called by the h/w composer HAL when a vsync event is
* received and HWC_EVENT_VSYNC is enabled (see: hwc_event_control).
*
* the "zero" parameter must always be 0.
* the "timestamp" parameter is the system monotonic clock timestamp in
* nanosecond of when the vsync event happened.
*
* vsync() is GUARANTEED TO NOT CALL BACK into the h/w composer HAL.
*
* It is expected that vsync() is called from a thread of at least
* HAL_PRIORITY_URGENT_DISPLAY with as little latency as possible,
* typically less than 0.5 ms.
*
* It is a (silent) error to have HWC_EVENT_VSYNC enabled when calling
* hwc_composer_device.set(..., 0, 0, 0) (screen off). The implementation
* can either stop or continue to process VSYNC events, but must not
* crash or cause other problems.
*
*/
void (*vsync)(struct hwc_procs* procs, int zero, int64_t timestamp);
} hwc_procs_t;
/*****************************************************************************/
typedef struct hwc_module {
struct hw_module_t common;
} hwc_module_t;
typedef struct hwc_composer_device {
struct hw_device_t common;
/*
* (*prepare)() is called for each frame before composition and is used by
* SurfaceFlinger to determine what composition steps the HWC can handle.
*
* (*prepare)() can be called more than once, the last call prevails.
*
* The HWC responds by setting the compositionType field to either
* HWC_FRAMEBUFFER or HWC_OVERLAY. In the former case, the composition for
* this layer is handled by SurfaceFlinger with OpenGL ES, in the later
* case, the HWC will have to handle this layer's composition.
*
* (*prepare)() is called with HWC_GEOMETRY_CHANGED to indicate that the
* list's geometry has changed, that is, when more than just the buffer's
* handles have been updated. Typically this happens (but is not limited to)
* when a window is added, removed, resized or moved.
*
* a NULL list parameter or a numHwLayers of zero indicates that the
* entire composition will be handled by SurfaceFlinger with OpenGL ES.
*
* returns: 0 on success. An negative error code on error. If an error is
* returned, SurfaceFlinger will assume that none of the layer will be
* handled by the HWC.
*/
int (*prepare)(struct hwc_composer_device *dev, hwc_layer_list_t* list);
/*
* (*set)() is used in place of eglSwapBuffers(), and assumes the same
* functionality, except it also commits the work list atomically with
* the actual eglSwapBuffers().
*
* The list parameter is guaranteed to be the same as the one returned
* from the last call to (*prepare)().
*
* When this call returns the caller assumes that:
*
* - the display will be updated in the near future with the content
* of the work list, without artifacts during the transition from the
* previous frame.
*
* - all objects are available for immediate access or destruction, in
* particular, hwc_region_t::rects data and hwc_layer_t::layer's buffer.
* Note that this means that immediately accessing (potentially from a
* different process) a buffer used in this call will not result in
* screen corruption, the driver must apply proper synchronization or
* scheduling (eg: block the caller, such as gralloc_module_t::lock(),
* OpenGL ES, Camera, Codecs, etc..., or schedule the caller's work
* after the buffer is freed from the actual composition).
*
* a NULL list parameter or a numHwLayers of zero indicates that the
* entire composition has been handled by SurfaceFlinger with OpenGL ES.
* In this case, (*set)() behaves just like eglSwapBuffers().
*
* dpy, sur, and list are set to NULL to indicate that the screen is
* turning off. This happens WITHOUT prepare() being called first.
* This is a good time to free h/w resources and/or power
* the relevant h/w blocks down.
*
* IMPORTANT NOTE: there is an implicit layer containing opaque black
* pixels behind all the layers in the list.
* It is the responsibility of the hwcomposer module to make
* sure black pixels are output (or blended from).
*
* returns: 0 on success. An negative error code on error:
* HWC_EGL_ERROR: eglGetError() will provide the proper error code
* Another code for non EGL errors.
*
*/
int (*set)(struct hwc_composer_device *dev,
hwc_display_t dpy,
hwc_surface_t sur,
hwc_layer_list_t* list);
/*
* This field is OPTIONAL and can be NULL.
*
* If non NULL it will be called by SurfaceFlinger on dumpsys
*/
void (*dump)(struct hwc_composer_device* dev, char *buff, int buff_len);
/*
* This field is OPTIONAL and can be NULL.
*
* (*registerProcs)() registers a set of callbacks the h/w composer HAL
* can later use. It is FORBIDDEN to call any of the callbacks from
* within registerProcs(). registerProcs() must save the hwc_procs_t pointer
* which is needed when calling a registered callback.
* Each call to registerProcs replaces the previous set of callbacks.
* registerProcs is called with NULL to unregister all callbacks.
*
* Any of the callbacks can be NULL, in which case the corresponding
* functionality is not supported.
*/
void (*registerProcs)(struct hwc_composer_device* dev,
hwc_procs_t const* procs);
/*
* This field is OPTIONAL and can be NULL.
* availability: HWC_DEVICE_API_VERSION_0_2
*
* Used to retrieve information about the h/w composer
*
* Returns 0 on success or -errno on error.
*/
int (*query)(struct hwc_composer_device* dev, int what, int* value);
/*
* Reserved for future use. Must be NULL.
*/
void* reserved_proc[4];
/*
* This field is OPTIONAL and can be NULL.
* availability: HWC_DEVICE_API_VERSION_0_3
*/
hwc_methods_t const *methods;
} hwc_composer_device_t;
/** convenience API for opening and closing a device */
static inline int hwc_open(const struct hw_module_t* module,
hwc_composer_device_t** device) {
return module->methods->open(module,
HWC_HARDWARE_COMPOSER, (struct hw_device_t**)device);
}
static inline int hwc_close(hwc_composer_device_t* device) {
return device->common.close(&device->common);
}
/*****************************************************************************/
__END_DECLS
#endif /* ANDROID_INCLUDE_HARDWARE_HWCOMPOSER_H */

View File

@@ -0,0 +1,149 @@
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_INCLUDE_HARDWARE_HWCOMPOSER_DEFS_H
#define ANDROID_INCLUDE_HARDWARE_HWCOMPOSER_DEFS_H
#include <stdint.h>
#include <sys/cdefs.h>
#include <hardware/gralloc.h>
#include <hardware/hardware.h>
#include <cutils/native_handle.h>
__BEGIN_DECLS
/*****************************************************************************/
#define HWC_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
#define HWC_DEVICE_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION(0, 1)
#define HWC_DEVICE_API_VERSION_0_2 HARDWARE_DEVICE_API_VERSION(0, 2)
#define HWC_DEVICE_API_VERSION_0_3 HARDWARE_DEVICE_API_VERSION(0, 3)
enum {
/* hwc_composer_device_t::set failed in EGL */
HWC_EGL_ERROR = -1
};
/*
* hwc_layer_t::hints values
* Hints are set by the HAL and read by SurfaceFlinger
*/
enum {
/*
* HWC can set the HWC_HINT_TRIPLE_BUFFER hint to indicate to SurfaceFlinger
* that it should triple buffer this layer. Typically HWC does this when
* the layer will be unavailable for use for an extended period of time,
* e.g. if the display will be fetching data directly from the layer and
* the layer can not be modified until after the next set().
*/
HWC_HINT_TRIPLE_BUFFER = 0x00000001,
/*
* HWC sets HWC_HINT_CLEAR_FB to tell SurfaceFlinger that it should clear the
* framebuffer with transparent pixels where this layer would be.
* SurfaceFlinger will only honor this flag when the layer has no blending
*
*/
HWC_HINT_CLEAR_FB = 0x00000002
};
/*
* hwc_layer_t::flags values
* Flags are set by SurfaceFlinger and read by the HAL
*/
enum {
/*
* HWC_SKIP_LAYER is set by SurfaceFlnger to indicate that the HAL
* shall not consider this layer for composition as it will be handled
* by SurfaceFlinger (just as if compositionType was set to HWC_OVERLAY).
*/
HWC_SKIP_LAYER = 0x00000001,
};
/*
* hwc_layer_t::compositionType values
*/
enum {
/* this layer is to be drawn into the framebuffer by SurfaceFlinger */
HWC_FRAMEBUFFER = 0,
/* this layer will be handled in the HWC */
HWC_OVERLAY = 1,
/* this is the background layer. it's used to set the background color.
* there is only a single background layer */
HWC_BACKGROUND = 2,
};
/*
* hwc_layer_t::blending values
*/
enum {
/* no blending */
HWC_BLENDING_NONE = 0x0100,
/* ONE / ONE_MINUS_SRC_ALPHA */
HWC_BLENDING_PREMULT = 0x0105,
/* SRC_ALPHA / ONE_MINUS_SRC_ALPHA */
HWC_BLENDING_COVERAGE = 0x0405
};
/*
* hwc_layer_t::transform values
*/
enum {
/* flip source image horizontally */
HWC_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
/* flip source image vertically */
HWC_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
/* rotate source image 90 degrees clock-wise */
HWC_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
/* rotate source image 180 degrees */
HWC_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
/* rotate source image 270 degrees clock-wise */
HWC_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
};
/* attributes queriable with query() */
enum {
/*
* availability: HWC_DEVICE_API_VERSION_0_2
* must return 1 if the background layer is supported, 0 otherwise
*/
HWC_BACKGROUND_LAYER_SUPPORTED = 0,
/*
* availability: HWC_DEVICE_API_VERSION_0_3
* returns the vsync period in nanosecond
*/
HWC_VSYNC_PERIOD = 1,
};
/* Allowed events for hwc_methods::eventControl() */
enum {
HWC_EVENT_VSYNC = 0,
HWC_EVENT_ORIENTATION // To notify HWC about the device orientation
};
/*****************************************************************************/
__END_DECLS
#endif /* ANDROID_INCLUDE_HARDWARE_HWCOMPOSER_DEFS_H */

View File

@@ -0,0 +1,214 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_HARDWARE_KEYMASTER_H
#define ANDROID_HARDWARE_KEYMASTER_H
#include <stdint.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <hardware/hardware.h>
__BEGIN_DECLS
/**
* The id of this module
*/
#define KEYSTORE_HARDWARE_MODULE_ID "keystore"
#define KEYSTORE_KEYMASTER "keymaster"
/**
* The API level of this version of the header. The allows the implementing
* module to recognize which API level of the client it is dealing with in
* the case of pre-compiled binary clients.
*/
#define KEYMASTER_API_VERSION 1
/**
* Flags for keymaster_device::flags
*/
enum {
/*
* Indicates this keymaster implementation does not have hardware that
* keeps private keys out of user space.
*
* This should not be implemented on anything other than the default
* implementation.
*/
KEYMASTER_SOFTWARE_ONLY = 0x00000001,
};
struct keystore_module {
hw_module_t common;
};
/**
* Asymmetric key pair types.
*/
typedef enum {
TYPE_RSA = 1,
} keymaster_keypair_t;
/**
* Parameters needed to generate an RSA key.
*/
typedef struct {
uint32_t modulus_size;
uint64_t public_exponent;
} keymaster_rsa_keygen_params_t;
/**
* Digest type used for RSA operations.
*/
typedef enum {
DIGEST_NONE,
} keymaster_rsa_digest_t;
/**
* Type of padding used for RSA operations.
*/
typedef enum {
PADDING_NONE,
} keymaster_rsa_padding_t;
typedef struct {
keymaster_rsa_digest_t digest_type;
keymaster_rsa_padding_t padding_type;
} keymaster_rsa_sign_params_t;
/**
* The parameters that can be set for a given keymaster implementation.
*/
struct keymaster_device {
struct hw_device_t common;
uint32_t client_version;
/**
* See flags defined for keymaster_device::flags above.
*/
uint32_t flags;
void* context;
/**
* Generates a public and private key. The key-blob returned is opaque
* and must subsequently provided for signing and verification.
*
* Returns: 0 on success or an error code less than 0.
*/
int (*generate_keypair)(const struct keymaster_device* dev,
const keymaster_keypair_t key_type, const void* key_params,
uint8_t** key_blob, size_t* key_blob_length);
/**
* Imports a public and private key pair. The imported keys will be in
* PKCS#8 format with DER encoding (Java standard). The key-blob
* returned is opaque and will be subsequently provided for signing
* and verification.
*
* Returns: 0 on success or an error code less than 0.
*/
int (*import_keypair)(const struct keymaster_device* dev,
const uint8_t* key, const size_t key_length,
uint8_t** key_blob, size_t* key_blob_length);
/**
* Gets the public key part of a key pair. The public key must be in
* X.509 format (Java standard) encoded byte array.
*
* Returns: 0 on success or an error code less than 0.
* On error, x509_data should not be allocated.
*/
int (*get_keypair_public)(const struct keymaster_device* dev,
const uint8_t* key_blob, const size_t key_blob_length,
uint8_t** x509_data, size_t* x509_data_length);
/**
* Deletes the key pair associated with the key blob.
*
* This function is optional and should be set to NULL if it is not
* implemented.
*
* Returns 0 on success or an error code less than 0.
*/
int (*delete_keypair)(const struct keymaster_device* dev,
const uint8_t* key_blob, const size_t key_blob_length);
/**
* Deletes all keys in the hardware keystore. Used when keystore is
* reset completely.
*
* This function is optional and should be set to NULL if it is not
* implemented.
*
* Returns 0 on success or an error code less than 0.
*/
int (*delete_all)(const struct keymaster_device* dev);
/**
* Signs data using a key-blob generated before. This can use either
* an asymmetric key or a secret key.
*
* Returns: 0 on success or an error code less than 0.
*/
int (*sign_data)(const struct keymaster_device* dev,
const void* signing_params,
const uint8_t* key_blob, const size_t key_blob_length,
const uint8_t* data, const size_t data_length,
uint8_t** signed_data, size_t* signed_data_length);
/**
* Verifies data signed with a key-blob. This can use either
* an asymmetric key or a secret key.
*
* Returns: 0 on successful verification or an error code less than 0.
*/
int (*verify_data)(const struct keymaster_device* dev,
const void* signing_params,
const uint8_t* key_blob, const size_t key_blob_length,
const uint8_t* signed_data, const size_t signed_data_length,
const uint8_t* signature, const size_t signature_length);
};
typedef struct keymaster_device keymaster_device_t;
/* Convenience API for opening and closing keymaster devices */
static inline int keymaster_open(const struct hw_module_t* module,
keymaster_device_t** device)
{
int rc = module->methods->open(module, KEYSTORE_KEYMASTER,
(struct hw_device_t**) device);
if (!rc) {
(*device)->client_version = KEYMASTER_API_VERSION;
}
return rc;
}
static inline int keymaster_close(keymaster_device_t* device)
{
return device->common.close(&device->common);
}
__END_DECLS
#endif // ANDROID_HARDWARE_KEYMASTER_H

View File

@@ -0,0 +1,137 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_LIGHTS_INTERFACE_H
#define ANDROID_LIGHTS_INTERFACE_H
#include <stdint.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <hardware/hardware.h>
__BEGIN_DECLS
/**
* The id of this module
*/
#define LIGHTS_HARDWARE_MODULE_ID "lights"
/*
* These light IDs correspond to logical lights, not physical.
* So for example, if your INDICATOR light is in line with your
* BUTTONS, it might make sense to also light the INDICATOR
* light to a reasonable color when the BUTTONS are lit.
*/
#define LIGHT_ID_BACKLIGHT "backlight"
#define LIGHT_ID_KEYBOARD "keyboard"
#define LIGHT_ID_BUTTONS "buttons"
#define LIGHT_ID_BATTERY "battery"
#define LIGHT_ID_NOTIFICATIONS "notifications"
#define LIGHT_ID_ATTENTION "attention"
/*
* These lights aren't currently supported by the higher
* layers, but could be someday, so we have the constants
* here now.
*/
#define LIGHT_ID_BLUETOOTH "bluetooth"
#define LIGHT_ID_WIFI "wifi"
/* ************************************************************************
* Flash modes for the flashMode field of light_state_t.
*/
#define LIGHT_FLASH_NONE 0
/**
* To flash the light at a given rate, set flashMode to LIGHT_FLASH_TIMED,
* and then flashOnMS should be set to the number of milliseconds to turn
* the light on, followed by the number of milliseconds to turn the light
* off.
*/
#define LIGHT_FLASH_TIMED 1
/**
* To flash the light using hardware assist, set flashMode to
* the hardware mode.
*/
#define LIGHT_FLASH_HARDWARE 2
/**
* Light brightness is managed by a user setting.
*/
#define BRIGHTNESS_MODE_USER 0
/**
* Light brightness is managed by a light sensor.
*/
#define BRIGHTNESS_MODE_SENSOR 1
/**
* The parameters that can be set for a given light.
*
* Not all lights must support all parameters. If you
* can do something backward-compatible, you should.
*/
struct light_state_t {
/**
* The color of the LED in ARGB.
*
* Do your best here.
* - If your light can only do red or green, if they ask for blue,
* you should do green.
* - If you can only do a brightness ramp, then use this formula:
* unsigned char brightness = ((77*((color>>16)&0x00ff))
* + (150*((color>>8)&0x00ff)) + (29*(color&0x00ff))) >> 8;
* - If you can only do on or off, 0 is off, anything else is on.
*
* The high byte should be ignored. Callers will set it to 0xff (which
* would correspond to 255 alpha).
*/
unsigned int color;
/**
* See the LIGHT_FLASH_* constants
*/
int flashMode;
int flashOnMS;
int flashOffMS;
/**
* Policy used by the framework to manage the light's brightness.
* Currently the values are BRIGHTNESS_MODE_USER and BRIGHTNESS_MODE_SENSOR.
*/
int brightnessMode;
};
struct light_device_t {
struct hw_device_t common;
/**
* Set the provided lights to the provided values.
*
* Returns: 0 on succes, error code on failure.
*/
int (*set_light)(struct light_device_t* dev,
struct light_state_t const* state);
};
__END_DECLS
#endif // ANDROID_LIGHTS_INTERFACE_H

View File

@@ -0,0 +1,117 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_LOCAL_TIME_HAL_INTERFACE_H
#define ANDROID_LOCAL_TIME_HAL_INTERFACE_H
#include <stdint.h>
#include <hardware/hardware.h>
__BEGIN_DECLS
/**
* The id of this module
*/
#define LOCAL_TIME_HARDWARE_MODULE_ID "local_time"
/**
* Name of the local time devices to open
*/
#define LOCAL_TIME_HARDWARE_INTERFACE "local_time_hw_if"
/**********************************************************************/
/**
* A structure used to collect low level sync data in a lab environment. Most
* HAL implementations will never need this structure.
*/
struct local_time_debug_event {
int64_t local_timesync_event_id;
int64_t local_time;
};
/**
* Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
* and the fields of this data structure must begin with hw_module_t
* followed by module specific information.
*/
struct local_time_module {
struct hw_module_t common;
};
struct local_time_hw_device {
struct hw_device_t common;
/**
*
* Returns the current value of the system wide local time counter
*/
int64_t (*get_local_time)(struct local_time_hw_device* dev);
/**
*
* Returns the nominal frequency (in hertz) of the system wide local time
* counter
*/
uint64_t (*get_local_freq)(struct local_time_hw_device* dev);
/**
*
* Sets the HW slew rate of oscillator which drives the system wide local
* time counter. On success, platforms should return 0. Platforms which
* do not support HW slew should leave this method set to NULL.
*
* Valid values for rate range from MIN_INT16 to MAX_INT16. Platform
* implementations should attempt map this range linearly to the min/max
* slew rate of their hardware.
*/
int (*set_local_slew)(struct local_time_hw_device* dev, int16_t rate);
/**
*
* A method used to collect low level sync data in a lab environments.
* Most HAL implementations will simply set this member to NULL, or return
* -EINVAL to indicate that this functionality is not supported.
* Production HALs should never support this method.
*/
int (*get_debug_log)(struct local_time_hw_device* dev,
struct local_time_debug_event* records,
int max_records);
};
typedef struct local_time_hw_device local_time_hw_device_t;
/** convenience API for opening and closing a supported device */
static inline int local_time_hw_device_open(
const struct hw_module_t* module,
struct local_time_hw_device** device)
{
return module->methods->open(module, LOCAL_TIME_HARDWARE_INTERFACE,
(struct hw_device_t**)device);
}
static inline int local_time_hw_device_close(struct local_time_hw_device* device)
{
return device->common.close(&device->common);
}
__END_DECLS
#endif // ANDROID_LOCAL_TIME_INTERFACE_H

View File

@@ -0,0 +1,101 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_NFC_HAL_INTERFACE_H
#define ANDROID_NFC_HAL_INTERFACE_H
#include <stdint.h>
#include <strings.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <hardware/hardware.h>
__BEGIN_DECLS
#define NFC_HARDWARE_MODULE_ID "nfc"
/*
* Begin PN544 specific HAL
*/
#define NFC_PN544_CONTROLLER "pn544"
typedef struct nfc_module_t {
struct hw_module_t common;
} nfc_module_t;
/*
* PN544 linktypes.
* UART
* I2C
* USB (uses UART DAL)
*/
typedef enum {
PN544_LINK_TYPE_UART,
PN544_LINK_TYPE_I2C,
PN544_LINK_TYPE_USB,
PN544_LINK_TYPE_INVALID,
} nfc_pn544_linktype;
typedef struct {
struct hw_device_t common;
/* The number of EEPROM registers to write */
uint32_t num_eeprom_settings;
/* The actual EEPROM settings
* For PN544, each EEPROM setting is a 4-byte entry,
* of the format [0x00, addr_msb, addr_lsb, value].
*/
uint8_t* eeprom_settings;
/* The link type to which the PN544 is connected */
nfc_pn544_linktype linktype;
/* The device node to which the PN544 is connected */
const char* device_node;
/* On Crespo we had an I2C issue that would cause us to sometimes read
* the I2C slave address (0x57) over the bus. libnfc contains
* a hack to ignore this byte and try to read the length byte
* again.
* Set to 0 to disable the workaround, 1 to enable it.
*/
uint8_t enable_i2c_workaround;
/* I2C slave address. Multiple I2C addresses are
* possible for PN544 module. Configure address according to
* board design.
*/
uint8_t i2c_device_address;
} nfc_pn544_device_t;
static inline int nfc_pn544_open(const struct hw_module_t* module,
nfc_pn544_device_t** dev) {
return module->methods->open(module, NFC_PN544_CONTROLLER,
(struct hw_device_t**) dev);
}
static inline int nfc_pn544_close(nfc_pn544_device_t* dev) {
return dev->common.close(&dev->common);
}
/*
* End PN544 specific HAL
*/
__END_DECLS
#endif // ANDROID_NFC_HAL_INTERFACE_H

View File

@@ -0,0 +1,136 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_INCLUDE_HARDWARE_POWER_H
#define ANDROID_INCLUDE_HARDWARE_POWER_H
#include <stdint.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <hardware/hardware.h>
__BEGIN_DECLS
#define POWER_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
#define POWER_MODULE_API_VERSION_0_2 HARDWARE_MODULE_API_VERSION(0, 2)
/**
* The id of this module
*/
#define POWER_HARDWARE_MODULE_ID "power"
/*
* Power hint identifiers passed to (*powerHint)
*/
typedef enum {
POWER_HINT_VSYNC = 0x00000001,
POWER_HINT_INTERACTION = 0x00000002,
POWER_HINT_VIDEO_ENCODE = 0x00000003,
POWER_HINT_VIDEO_DECODE = 0x00000004,
} power_hint_t;
/**
* Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
* and the fields of this data structure must begin with hw_module_t
* followed by module specific information.
*/
typedef struct power_module {
struct hw_module_t common;
/*
* (*init)() performs power management setup actions at runtime
* startup, such as to set default cpufreq parameters. This is
* called only by the Power HAL instance loaded by
* PowerManagerService.
*/
void (*init)(struct power_module *module);
/*
* (*setInteractive)() performs power management actions upon the
* system entering interactive state (that is, the system is awake
* and ready for interaction, often with UI devices such as
* display and touchscreen enabled) or non-interactive state (the
* system appears asleep, display usually turned off). The
* non-interactive state is usually entered after a period of
* inactivity, in order to conserve battery power during
* such inactive periods.
*
* Typical actions are to turn on or off devices and adjust
* cpufreq parameters. This function may also call the
* appropriate interfaces to allow the kernel to suspend the
* system to low-power sleep state when entering non-interactive
* state, and to disallow low-power suspend when the system is in
* interactive state. When low-power suspend state is allowed, the
* kernel may suspend the system whenever no wakelocks are held.
*
* on is non-zero when the system is transitioning to an
* interactive / awake state, and zero when transitioning to a
* non-interactive / asleep state.
*
* This function is called to enter non-interactive state after
* turning off the screen (if present), and called to enter
* interactive state prior to turning on the screen.
*/
void (*setInteractive)(struct power_module *module, int on);
/*
* (*powerHint) is called to pass hints on power requirements, which
* may result in adjustment of power/performance parameters of the
* cpufreq governor and other controls. The possible hints are:
*
* POWER_HINT_VSYNC
*
* Foreground app has started or stopped requesting a VSYNC pulse
* from SurfaceFlinger. If the app has started requesting VSYNC
* then CPU and GPU load is expected soon, and it may be appropriate
* to raise speeds of CPU, memory bus, etc. The data parameter is
* non-zero to indicate VSYNC pulse is now requested, or zero for
* VSYNC pulse no longer requested.
*
* POWER_HINT_INTERACTION
*
* User is interacting with the device, for example, touchscreen
* events are incoming. CPU and GPU load may be expected soon,
* and it may be appropriate to raise speeds of CPU, memory bus,
* etc. The data parameter is unused.
*
* POWER_HINT_VIDEO_ENCODE
*
* The user just started or stopped recording video. When encode
* begins, large writes to the SD card will be done and this may
* cause CPU frequency to increase. The data parameter is a string
* with semicolon-separated 'key:value' pairs. The most common key is
* 'state', which takes 0 or 1 as its value. For instance, To
* indicate that recording is beginning, the string "state:1" would
* need to be used. More keys can be provided depending on the data
* that is to be passed.
*
* A particular platform may choose to ignore any hint.
*
* availability: version 0.2
*
*/
void (*powerHint)(struct power_module *module, power_hint_t hint,
void *data);
} power_module_t;
__END_DECLS
#endif // ANDROID_INCLUDE_HARDWARE_POWER_H

View File

@@ -0,0 +1,91 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_INCLUDE_HARDWARE_QEMU_PIPE_H
#define ANDROID_INCLUDE_HARDWARE_QEMU_PIPE_H
#include <sys/cdefs.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <pthread.h> /* for pthread_once() */
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#ifndef D
# define D(...) do{}while(0)
#endif
/* Try to open a new Qemu fast-pipe. This function returns a file descriptor
* that can be used to communicate with a named service managed by the
* emulator.
*
* This file descriptor can be used as a standard pipe/socket descriptor.
*
* 'pipeName' is the name of the emulator service you want to connect to.
* E.g. 'opengles' or 'camera'.
*
* On success, return a valid file descriptor
* Returns -1 on error, and errno gives the error code, e.g.:
*
* EINVAL -> unknown/unsupported pipeName
* ENOSYS -> fast pipes not available in this system.
*
* ENOSYS should never happen, except if you're trying to run within a
* misconfigured emulator.
*
* You should be able to open several pipes to the same pipe service,
* except for a few special cases (e.g. GSM modem), where EBUSY will be
* returned if more than one client tries to connect to it.
*/
static __inline__ int
qemu_pipe_open(const char* pipeName)
{
char buff[256];
int buffLen;
int fd, ret;
if (pipeName == NULL || pipeName[0] == '\0') {
errno = EINVAL;
return -1;
}
snprintf(buff, sizeof buff, "pipe:%s", pipeName);
fd = open("/dev/qemu_pipe", O_RDWR);
if (fd < 0) {
D("%s: Could not open /dev/qemu_pipe: %s", __FUNCTION__, strerror(errno));
//errno = ENOSYS;
return -1;
}
buffLen = strlen(buff);
ret = TEMP_FAILURE_RETRY(write(fd, buff, buffLen+1));
if (ret != buffLen+1) {
D("%s: Could not connect to %s pipe service: %s", __FUNCTION__, pipeName, strerror(errno));
if (ret == 0) {
errno = ECONNRESET;
} else if (ret > 0) {
errno = EINVAL;
}
return -1;
}
return fd;
}
#endif /* ANDROID_INCLUDE_HARDWARE_QEMUD_PIPE_H */

View File

@@ -0,0 +1,153 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_INCLUDE_HARDWARE_QEMUD_H
#define ANDROID_INCLUDE_HARDWARE_QEMUD_H
#include <cutils/sockets.h>
#include "qemu_pipe.h"
/* the following is helper code that is used by the QEMU-specific
* hardware HAL modules to communicate with the emulator program
* through the 'qemud' multiplexing daemon, or through the qemud
* pipe.
*
* see the documentation comments for details in
* development/emulator/qemud/qemud.c
*
* all definitions here are built into the HAL module to avoid
* having to write a tiny shared library for this.
*/
/* we expect the D macro to be defined to a function macro
* that sends its formatted string argument(s) to the log.
* If not, ignore the traces.
*/
#ifndef D
# define D(...) ((void)0)
#endif
static __inline__ int
qemud_fd_write(int fd, const void* buff, int len)
{
int len2;
do {
len2 = write(fd, buff, len);
} while (len2 < 0 && errno == EINTR);
return len2;
}
static __inline__ int
qemud_fd_read(int fd, void* buff, int len)
{
int len2;
do {
len2 = read(fd, buff, len);
} while (len2 < 0 && errno == EINTR);
return len2;
}
static __inline__ int
qemud_channel_open(const char* name)
{
int fd;
int namelen = strlen(name);
char answer[2];
char pipe_name[256];
/* First, try to connect to the pipe. */
snprintf(pipe_name, sizeof(pipe_name), "qemud:%s", name);
fd = qemu_pipe_open(pipe_name);
if (fd < 0) {
D("QEMUD pipe is not available for %s: %s", name, strerror(errno));
/* If pipe is not available, connect to qemud control socket */
fd = socket_local_client( "qemud",
ANDROID_SOCKET_NAMESPACE_RESERVED,
SOCK_STREAM );
if (fd < 0) {
D("no qemud control socket: %s", strerror(errno));
return -1;
}
/* send service name to connect */
if (qemud_fd_write(fd, name, namelen) != namelen) {
D("can't send service name to qemud: %s",
strerror(errno));
close(fd);
return -1;
}
/* read answer from daemon */
if (qemud_fd_read(fd, answer, 2) != 2 ||
answer[0] != 'O' || answer[1] != 'K') {
D("cant' connect to %s service through qemud", name);
close(fd);
return -1;
}
}
return fd;
}
static __inline__ int
qemud_channel_send(int fd, const void* msg, int msglen)
{
char header[5];
if (msglen < 0)
msglen = strlen((const char*)msg);
if (msglen == 0)
return 0;
snprintf(header, sizeof header, "%04x", msglen);
if (qemud_fd_write(fd, header, 4) != 4) {
D("can't write qemud frame header: %s", strerror(errno));
return -1;
}
if (qemud_fd_write(fd, msg, msglen) != msglen) {
D("can4t write qemud frame payload: %s", strerror(errno));
return -1;
}
return 0;
}
static __inline__ int
qemud_channel_recv(int fd, void* msg, int msgsize)
{
char header[5];
int size, avail;
if (qemud_fd_read(fd, header, 4) != 4) {
D("can't read qemud frame header: %s", strerror(errno));
return -1;
}
header[4] = 0;
if (sscanf(header, "%04x", &size) != 1) {
D("malformed qemud frame header: '%.*s'", 4, header);
return -1;
}
if (size > msgsize)
return -1;
if (qemud_fd_read(fd, msg, size) != size) {
D("can't read qemud frame payload: %s", strerror(errno));
return -1;
}
return size;
}
#endif /* ANDROID_INCLUDE_HARDWARE_QEMUD_H */

View File

@@ -0,0 +1,485 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_SENSORS_INTERFACE_H
#define ANDROID_SENSORS_INTERFACE_H
#include <stdint.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <hardware/hardware.h>
#include <cutils/native_handle.h>
__BEGIN_DECLS
/**
* The id of this module
*/
#define SENSORS_HARDWARE_MODULE_ID "sensors"
/**
* Name of the sensors device to open
*/
#define SENSORS_HARDWARE_POLL "poll"
/**
* Handles must be higher than SENSORS_HANDLE_BASE and must be unique.
* A Handle identifies a given sensors. The handle is used to activate
* and/or deactivate sensors.
* In this version of the API there can only be 256 handles.
*/
#define SENSORS_HANDLE_BASE 0
#define SENSORS_HANDLE_BITS 8
#define SENSORS_HANDLE_COUNT (1<<SENSORS_HANDLE_BITS)
/**
* Sensor types
*/
#define SENSOR_TYPE_ACCELEROMETER 1
#define SENSOR_TYPE_MAGNETIC_FIELD 2
#define SENSOR_TYPE_ORIENTATION 3
#define SENSOR_TYPE_GYROSCOPE 4
#define SENSOR_TYPE_LIGHT 5
#define SENSOR_TYPE_PRESSURE 6
#define SENSOR_TYPE_TEMPERATURE 7 // deprecated
#define SENSOR_TYPE_PROXIMITY 8
#define SENSOR_TYPE_GRAVITY 9
#define SENSOR_TYPE_LINEAR_ACCELERATION 10
#define SENSOR_TYPE_ROTATION_VECTOR 11
#define SENSOR_TYPE_RELATIVE_HUMIDITY 12
#define SENSOR_TYPE_AMBIENT_TEMPERATURE 13
/**
* Values returned by the accelerometer in various locations in the universe.
* all values are in SI units (m/s^2)
*/
#define GRAVITY_SUN (275.0f)
#define GRAVITY_EARTH (9.80665f)
/** Maximum magnetic field on Earth's surface */
#define MAGNETIC_FIELD_EARTH_MAX (60.0f)
/** Minimum magnetic field on Earth's surface */
#define MAGNETIC_FIELD_EARTH_MIN (30.0f)
/**
* status of each sensor
*/
#define SENSOR_STATUS_UNRELIABLE 0
#define SENSOR_STATUS_ACCURACY_LOW 1
#define SENSOR_STATUS_ACCURACY_MEDIUM 2
#define SENSOR_STATUS_ACCURACY_HIGH 3
/**
* Definition of the axis
* ----------------------
*
* This API is relative to the screen of the device in its default orientation,
* that is, if the device can be used in portrait or landscape, this API
* is only relative to the NATURAL orientation of the screen. In other words,
* the axis are not swapped when the device's screen orientation changes.
* Higher level services /may/ perform this transformation.
*
* x<0 x>0
* ^
* |
* +-----------+--> y>0
* | |
* | |
* | |
* | | / z<0
* | | /
* | | /
* O-----------+/
* |[] [ ] []/
* +----------/+ y<0
* /
* /
* |/ z>0 (toward the sky)
*
* O: Origin (x=0,y=0,z=0)
*
*
* SENSOR_TYPE_ORIENTATION
* -----------------------
*
* All values are angles in degrees.
*
* Orientation sensors return sensor events for all 3 axes at a constant
* rate defined by setDelay().
*
* azimuth: angle between the magnetic north direction and the Y axis, around
* the Z axis (0<=azimuth<360).
* 0=North, 90=East, 180=South, 270=West
*
* pitch: Rotation around X axis (-180<=pitch<=180), with positive values when
* the z-axis moves toward the y-axis.
*
* roll: Rotation around Y axis (-90<=roll<=90), with positive values when
* the x-axis moves towards the z-axis.
*
* Note: For historical reasons the roll angle is positive in the clockwise
* direction (mathematically speaking, it should be positive in the
* counter-clockwise direction):
*
* Z
* ^
* (+roll) .--> |
* / |
* | | roll: rotation around Y axis
* X <-------(.)
* Y
* note that +Y == -roll
*
*
*
* Note: This definition is different from yaw, pitch and roll used in aviation
* where the X axis is along the long side of the plane (tail to nose).
*
*
* SENSOR_TYPE_ACCELEROMETER
* -------------------------
*
* All values are in SI units (m/s^2) and measure the acceleration of the
* device minus the force of gravity.
*
* Acceleration sensors return sensor events for all 3 axes at a constant
* rate defined by setDelay().
*
* x: Acceleration minus Gx on the x-axis
* y: Acceleration minus Gy on the y-axis
* z: Acceleration minus Gz on the z-axis
*
* Examples:
* When the device lies flat on a table and is pushed on its left side
* toward the right, the x acceleration value is positive.
*
* When the device lies flat on a table, the acceleration value is +9.81,
* which correspond to the acceleration of the device (0 m/s^2) minus the
* force of gravity (-9.81 m/s^2).
*
* When the device lies flat on a table and is pushed toward the sky, the
* acceleration value is greater than +9.81, which correspond to the
* acceleration of the device (+A m/s^2) minus the force of
* gravity (-9.81 m/s^2).
*
*
* SENSOR_TYPE_MAGNETIC_FIELD
* --------------------------
*
* All values are in micro-Tesla (uT) and measure the ambient magnetic
* field in the X, Y and Z axis.
*
* Magnetic Field sensors return sensor events for all 3 axes at a constant
* rate defined by setDelay().
*
* SENSOR_TYPE_GYROSCOPE
* ---------------------
*
* All values are in radians/second and measure the rate of rotation
* around the X, Y and Z axis. The coordinate system is the same as is
* used for the acceleration sensor. Rotation is positive in the
* counter-clockwise direction (right-hand rule). That is, an observer
* looking from some positive location on the x, y or z axis at a device
* positioned on the origin would report positive rotation if the device
* appeared to be rotating counter clockwise. Note that this is the
* standard mathematical definition of positive rotation and does not agree
* with the definition of roll given earlier.
* The range should at least be 17.45 rad/s (ie: ~1000 deg/s).
*
* SENSOR_TYPE_PROXIMITY
* ----------------------
*
* The distance value is measured in centimeters. Note that some proximity
* sensors only support a binary "close" or "far" measurement. In this case,
* the sensor should report its maxRange value in the "far" state and a value
* less than maxRange in the "near" state.
*
* Proximity sensors report a value only when it changes and each time the
* sensor is enabled.
*
* SENSOR_TYPE_LIGHT
* -----------------
*
* The light sensor value is returned in SI lux units.
*
* Light sensors report a value only when it changes and each time the
* sensor is enabled.
*
* SENSOR_TYPE_PRESSURE
* --------------------
*
* The pressure sensor return the athmospheric pressure in hectopascal (hPa)
*
* Pressure sensors report events at a constant rate defined by setDelay().
*
* SENSOR_TYPE_GRAVITY
* -------------------
*
* A gravity output indicates the direction of and magnitude of gravity in
* the devices's coordinates. On Earth, the magnitude is 9.8 m/s^2.
* Units are m/s^2. The coordinate system is the same as is used for the
* acceleration sensor. When the device is at rest, the output of the
* gravity sensor should be identical to that of the accelerometer.
*
* SENSOR_TYPE_LINEAR_ACCELERATION
* --------------------------------
*
* Indicates the linear acceleration of the device in device coordinates,
* not including gravity.
* This output is essentially Acceleration - Gravity. Units are m/s^2.
* The coordinate system is the same as is used for the acceleration sensor.
*
*
* SENSOR_TYPE_ROTATION_VECTOR
* ---------------------------
*
* A rotation vector represents the orientation of the device as a combination
* of an angle and an axis, in which the device has rotated through an angle
* theta around an axis <x, y, z>. The three elements of the rotation vector
* are <x*sin(theta/2), y*sin(theta/2), z*sin(theta/2)>, such that the magnitude
* of the rotation vector is equal to sin(theta/2), and the direction of the
* rotation vector is equal to the direction of the axis of rotation. The three
* elements of the rotation vector are equal to the last three components of a
* unit quaternion <cos(theta/2), x*sin(theta/2), y*sin(theta/2), z*sin(theta/2)>.
* Elements of the rotation vector are unitless. The x, y, and z axis are defined
* in the same was as for the acceleration sensor.
*
* The reference coordinate system is defined as a direct orthonormal basis,
* where:
*
* - X is defined as the vector product Y.Z (It is tangential to
* the ground at the device's current location and roughly points East).
*
* - Y is tangential to the ground at the device's current location and
* points towards the magnetic North Pole.
*
* - Z points towards the sky and is perpendicular to the ground.
*
*
* The rotation-vector is stored as:
*
* sensors_event_t.data[0] = x*sin(theta/2)
* sensors_event_t.data[1] = y*sin(theta/2)
* sensors_event_t.data[2] = z*sin(theta/2)
* sensors_event_t.data[3] = cos(theta/2)
*
*
* SENSOR_TYPE_RELATIVE_HUMIDITY
* ------------------------------
*
* A relative humidity sensor measures relative ambient air humidity and
* returns a value in percent.
*
* Relative humidity sensors report a value only when it changes and each
* time the sensor is enabled.
*
*
* SENSOR_TYPE_AMBIENT_TEMPERATURE
* -------------------------------
*
* The ambient (room) temperature in degree Celsius.
*
* Temperature sensors report a value only when it changes and each time the
* sensor is enabled.
*
*/
typedef struct {
union {
float v[3];
struct {
float x;
float y;
float z;
};
struct {
float azimuth;
float pitch;
float roll;
};
};
int8_t status;
uint8_t reserved[3];
} sensors_vec_t;
/**
* Union of the various types of sensor data
* that can be returned.
*/
typedef struct sensors_event_t {
/* must be sizeof(struct sensors_event_t) */
int32_t version;
/* sensor identifier */
int32_t sensor;
/* sensor type */
int32_t type;
/* reserved */
int32_t reserved0;
/* time is in nanosecond */
int64_t timestamp;
union {
float data[16];
/* acceleration values are in meter per second per second (m/s^2) */
sensors_vec_t acceleration;
/* magnetic vector values are in micro-Tesla (uT) */
sensors_vec_t magnetic;
/* orientation values are in degrees */
sensors_vec_t orientation;
/* gyroscope values are in rad/s */
sensors_vec_t gyro;
/* temperature is in degrees centigrade (Celsius) */
float temperature;
/* distance in centimeters */
float distance;
/* light in SI lux units */
float light;
/* pressure in hectopascal (hPa) */
float pressure;
/* relative humidity in percent */
float relative_humidity;
};
uint32_t reserved1[4];
} sensors_event_t;
struct sensor_t;
/**
* Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
* and the fields of this data structure must begin with hw_module_t
* followed by module specific information.
*/
struct sensors_module_t {
struct hw_module_t common;
/**
* Enumerate all available sensors. The list is returned in "list".
* @return number of sensors in the list
*/
int (*get_sensors_list)(struct sensors_module_t* module,
struct sensor_t const** list);
};
struct sensor_t {
/* name of this sensors */
const char* name;
/* vendor of the hardware part */
const char* vendor;
/* version of the hardware part + driver. The value of this field
* must increase when the driver is updated in a way that changes the
* output of this sensor. This is important for fused sensors when the
* fusion algorithm is updated.
*/
int version;
/* handle that identifies this sensors. This handle is used to activate
* and deactivate this sensor. The value of the handle must be 8 bits
* in this version of the API.
*/
int handle;
/* this sensor's type. */
int type;
/* maximaum range of this sensor's value in SI units */
float maxRange;
/* smallest difference between two values reported by this sensor */
float resolution;
/* rough estimate of this sensor's power consumption in mA */
float power;
/* minimum delay allowed between events in microseconds. A value of zero
* means that this sensor doesn't report events at a constant rate, but
* rather only when a new data is available */
int32_t minDelay;
/* reserved fields, must be zero */
void* reserved[8];
};
/**
* Every device data structure must begin with hw_device_t
* followed by module specific public methods and attributes.
*/
struct sensors_poll_device_t {
struct hw_device_t common;
/** Activate/deactivate one sensor.
*
* @param handle is the handle of the sensor to change.
* @param enabled set to 1 to enable, or 0 to disable the sensor.
*
* @return 0 on success, negative errno code otherwise
*/
int (*activate)(struct sensors_poll_device_t *dev,
int handle, int enabled);
/**
* Set the delay between sensor events in nanoseconds for a given sensor.
*
* If the requested value is less than sensor_t::minDelay, then it's
* silently clamped to sensor_t::minDelay unless sensor_t::minDelay is
* 0, in which case it is clamped to >= 1ms.
*
* @return 0 if successful, < 0 on error
*/
int (*setDelay)(struct sensors_poll_device_t *dev,
int handle, int64_t ns);
/**
* Returns an array of sensor data.
* This function must block until events are available.
*
* @return the number of events read on success, or -errno in case of an error.
* This function should never return 0 (no event).
*
*/
int (*poll)(struct sensors_poll_device_t *dev,
sensors_event_t* data, int count);
};
/** convenience API for opening and closing a device */
static inline int sensors_open(const struct hw_module_t* module,
struct sensors_poll_device_t** device) {
return module->methods->open(module,
SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
}
static inline int sensors_close(struct sensors_poll_device_t* device) {
return device->common.close(&device->common);
}
__END_DECLS
#endif // ANDROID_SENSORS_INTERFACE_H