diff options
253 files changed, 2497 insertions, 57566 deletions
diff --git a/camera/include/system/camera_metadata.h b/camera/include/system/camera_metadata.h new file mode 100644 index 00000000..424fc0f2 --- /dev/null +++ b/camera/include/system/camera_metadata.h @@ -0,0 +1,327 @@ +/* + * 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 SYSTEM_CORE_INCLUDE_ANDROID_CAMERA_METADATA_H +#define SYSTEM_CORE_INCLUDE_ANDROID_CAMERA_METADATA_H + +#include <string.h> +#include <stdint.h> +#include <cutils/compiler.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Tag hierarchy and enum definitions for camera_metadata_entry + * ============================================================================= + */ + +/** + * Main enum definitions are in a separate file to make it easy to + * maintain + */ +#include "camera_metadata_tags.h" + +/** + * Enum range for each top-level category + */ +ANDROID_API +extern unsigned int camera_metadata_section_bounds[ANDROID_SECTION_COUNT][2]; +ANDROID_API +extern const char *camera_metadata_section_names[ANDROID_SECTION_COUNT]; + +/** + * Type definitions for camera_metadata_entry + * ============================================================================= + */ +enum { + // Unsigned 8-bit integer (uint8_t) + TYPE_BYTE = 0, + // Signed 32-bit integer (int32_t) + TYPE_INT32 = 1, + // 32-bit float (float) + TYPE_FLOAT = 2, + // Signed 64-bit integer (int64_t) + TYPE_INT64 = 3, + // 64-bit float (double) + TYPE_DOUBLE = 4, + // A 64-bit fraction (camera_metadata_rational_t) + TYPE_RATIONAL = 5, + // Number of type fields + NUM_TYPES +}; + +typedef struct camera_metadata_rational { + int32_t numerator; + int32_t denominator; +} camera_metadata_rational_t; + +/** + * Size in bytes of each entry type + */ +ANDROID_API +extern size_t camera_metadata_type_sizes[NUM_TYPES]; + +/** + * Main definitions for the metadata entry and array structures + * ============================================================================= + */ + +/** + * A packet of metadata. This is a list of metadata entries, each of which has + * an integer tag to identify its meaning, 'type' and 'count' field, and the + * data, which contains a 'count' number of entries of type 'type'. The packet + * has a fixed capacity for entries and for extra data. A new entry uses up one + * entry slot, and possibly some amount of data capacity; the function + * calculate_camera_metadata_entry_data_size() provides the amount of data + * capacity that would be used up by an entry. + * + * Entries are not sorted, and are not forced to be unique - multiple entries + * with the same tag are allowed. The packet will not dynamically resize when + * full. + * + * The packet is contiguous in memory, with size in bytes given by + * get_camera_metadata_size(). Therefore, it can be copied safely with memcpy() + * to a buffer of sufficient size. The copy_camera_metadata() function is + * intended for eliminating unused capacity in the destination packet. + */ +struct camera_metadata; +typedef struct camera_metadata camera_metadata_t; + +/** + * Functions for manipulating camera metadata + * ============================================================================= + */ + +/** + * Allocate a new camera_metadata structure, with some initial space for entries + * and extra data. The entry_capacity is measured in entry counts, and + * data_capacity in bytes. The resulting structure is all contiguous in memory, + * and can be freed with free_camera_metadata(). + */ +ANDROID_API +camera_metadata_t *allocate_camera_metadata(size_t entry_capacity, + size_t data_capacity); + +/** + * Place a camera metadata structure into an existing buffer. Returns NULL if + * the buffer is too small for the requested number of reserved entries and + * bytes of data. The entry_capacity is measured in entry counts, and + * data_capacity in bytes. If the buffer is larger than the required space, + * unused space will be left at the end. If successful, returns a pointer to the + * metadata header placed at the start of the buffer. It is the caller's + * responsibility to free the original buffer; do not call + * free_camera_metadata() with the returned pointer. + */ +ANDROID_API +camera_metadata_t *place_camera_metadata(void *dst, size_t dst_size, + size_t entry_capacity, + size_t data_capacity); + +/** + * Free a camera_metadata structure. Should only be used with structures + * allocated with allocate_camera_metadata(). + */ +ANDROID_API +void free_camera_metadata(camera_metadata_t *metadata); + +/** + * Calculate the buffer size needed for a metadata structure of entry_count + * metadata entries, needing a total of data_count bytes of extra data storage. + */ +ANDROID_API +size_t calculate_camera_metadata_size(size_t entry_count, + size_t data_count); + +/** + * Get current size of entire metadata structure in bytes, including reserved + * but unused space. + */ +ANDROID_API +size_t get_camera_metadata_size(const camera_metadata_t *metadata); + +/** + * Get size of entire metadata buffer in bytes, not including reserved but + * unused space. This is the amount of space needed by copy_camera_metadata for + * its dst buffer. + */ +ANDROID_API +size_t get_camera_metadata_compact_size(const camera_metadata_t *metadata); + +/** + * Get the current number of entries in the metadata packet. + */ +ANDROID_API +size_t get_camera_metadata_entry_count(const camera_metadata_t *metadata); + +/** + * Get the maximum number of entries that could fit in the metadata packet. + */ +ANDROID_API +size_t get_camera_metadata_entry_capacity(const camera_metadata_t *metadata); + +/** + * Get the current count of bytes used for value storage in the metadata packet. + */ +ANDROID_API +size_t get_camera_metadata_data_count(const camera_metadata_t *metadata); + +/** + * Get the maximum count of bytes that could be used for value storage in the + * metadata packet. + */ +ANDROID_API +size_t get_camera_metadata_data_capacity(const camera_metadata_t *metadata); + +/** + * Copy a metadata structure to a memory buffer, compacting it along the + * way. That is, in the copied structure, entry_count == entry_capacity, and + * data_count == data_capacity. + * + * If dst_size > get_camera_metadata_compact_size(), the unused bytes are at the + * end of the buffer. If dst_size < get_camera_metadata_compact_size(), returns + * NULL. Otherwise returns a pointer to the metadata structure header placed at + * the start of dst. + * + * Since the buffer was not allocated by allocate_camera_metadata, the caller is + * responsible for freeing the underlying buffer when needed; do not call + * free_camera_metadata. + */ +ANDROID_API +camera_metadata_t *copy_camera_metadata(void *dst, size_t dst_size, + const camera_metadata_t *src); + +/** + * Append camera metadata in src to an existing metadata structure in dst. This + * does not resize the destination structure, so if it is too small, a non-zero + * value is returned. On success, 0 is returned. + */ +ANDROID_API +int append_camera_metadata(camera_metadata_t *dst, const camera_metadata_t *src); + +/** + * Calculate the number of bytes of extra data a given metadata entry will take + * up. That is, if entry of 'type' with a payload of 'data_count' values is + * added, how much will the value returned by get_camera_metadata_data_count() + * be increased? This value may be zero, if no extra data storage is needed. + */ +ANDROID_API +size_t calculate_camera_metadata_entry_data_size(uint8_t type, + size_t data_count); + +/** + * Add a metadata entry to a metadata structure. Returns 0 if the addition + * succeeded. Returns a non-zero value if there is insufficient reserved space + * left to add the entry, or if the tag is unknown. data_count is the number of + * entries in the data array of the tag's type, not a count of + * bytes. Vendor-defined tags can not be added using this method, unless + * set_vendor_tag_query_ops() has been called first. + */ +ANDROID_API +int add_camera_metadata_entry(camera_metadata_t *dst, + uint32_t tag, + const void *data, + size_t data_count); + +/** + * Get pointers to the fields for a metadata entry at position index in the + * entry array. The data pointer points either to the entry's data.value field + * or to the right offset in camera_metadata_t.data. Returns 0 on + * success. Data_count is the number of entries in the data array when cast to + * the tag's type, not a count of bytes. + * + * src and index are inputs; tag, type, data, and data_count are outputs. + */ +ANDROID_API +int get_camera_metadata_entry(camera_metadata_t *src, + uint32_t index, + uint32_t *tag, + uint8_t *type, + void **data, + size_t *data_count); + +/** + * Retrieve human-readable name of section the tag is in. Returns NULL if + * no such tag is defined. Returns NULL for tags in the vendor section, unless + * set_vendor_tag_query_ops() has been used. + */ +ANDROID_API +const char *get_camera_metadata_section_name(uint32_t tag); + +/** + * Retrieve human-readable name of tag (not including section). Returns NULL if + * no such tag is defined. Returns NULL for tags in the vendor section, unless + * set_vendor_tag_query_ops() has been used. + */ +ANDROID_API +const char *get_camera_metadata_tag_name(uint32_t tag); + +/** + * Retrieve the type of a tag. Returns -1 if no such tag is defined. Returns -1 + * for tags in the vendor section, unless set_vendor_tag_query_ops() has been + * used. + */ +ANDROID_API +int get_camera_metadata_tag_type(uint32_t tag); + +/** + * Set up vendor-specific tag query methods. These are needed to properly add + * entries with vendor-specified tags and to use the + * get_camera_metadata_section_name, _tag_name, and _tag_type methods with + * vendor tags. Returns 0 on success. + */ +typedef struct vendor_tag_query_ops { + /** + * Get vendor section name for a vendor-specified entry tag. Only called for + * tags >= 0x80000000. The section name must start with the name of the + * vendor in the Java package style. For example, CameraZoom inc must prefix + * their sections with "com.camerazoom." Must return NULL if the tag is + * outside the bounds of vendor-defined sections. + */ + const char *(*get_camera_vendor_section_name)(uint32_t tag); + /** + * Get tag name for a vendor-specified entry tag. Only called for tags >= + * 0x80000000. Must return NULL if the tag is outside the bounds of + * vendor-defined sections. + */ + const char *(*get_camera_vendor_tag_name)(uint32_t tag); + /** + * Get tag type for a vendor-specified entry tag. Only called for tags >= + * 0x80000000. Must return -1 if the tag is outside the bounds of + * vendor-defined sections. + */ + int (*get_camera_vendor_tag_type)(uint32_t tag); +} vendor_tag_query_ops_t; + +ANDROID_API +int set_camera_metadata_vendor_tag_ops(const vendor_tag_query_ops_t *query_ops); + +/** + * Print fields in the metadata to the log. + * verbosity = 0: Only tag entry information + * verbosity = 1: Tag entry information plus at most 16 data values + * verbosity = 2: All information + */ +ANDROID_API +void dump_camera_metadata(const camera_metadata_t *metadata, + int verbosity); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/camera/include/system/camera_metadata_tags.h b/camera/include/system/camera_metadata_tags.h new file mode 100644 index 00000000..1fcfacb6 --- /dev/null +++ b/camera/include/system/camera_metadata_tags.h @@ -0,0 +1,291 @@ +/* + * 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. + */ + +/** + * !! Do not include this file directly !! + * + * Include camera_metadata.h instead. + */ + +/** + * Top level hierarchy definitions for camera metadata. *_INFO sections are for + * the static metadata that can be retrived without opening the camera device. + * New sections must be added right before ANDROID_SECTION_COUNT to maintain + * existing enumerations. + */ +enum { + ANDROID_REQUEST = 0, + ANDROID_LENS, + ANDROID_LENS_INFO, + ANDROID_SENSOR, + ANDROID_SENSOR_INFO, + ANDROID_FLASH, + ANDROID_FLASH_INFO, + ANDROID_HOT_PIXEL, + ANDROID_HOT_PIXEL_INFO, + ANDROID_DEMOSAIC, + ANDROID_DEMOSAIC_INFO, + ANDROID_NOISE, + ANDROID_NOISE_INFO, + ANDROID_SHADING, + ANDROID_SHADING_INFO, + ANDROID_GEOMETRIC, + ANDROID_GEOMETRIC_INFO, + ANDROID_COLOR, + ANDROID_COLOR_INFO, + ANDROID_TONEMAP, + ANDROID_TONEMAP_INFO, + ANDROID_EDGE, + ANDROID_EDGE_INFO, + ANDROID_SCALER, + ANDROID_SCALER_INFO, + ANDROID_JPEG, + ANDROID_JPEG_INFO, + ANDROID_STATS, + ANDROID_STATS_INFO, + ANDROID_CONTROL, + ANDROID_CONTROL_INFO, + ANDROID_SECTION_COUNT, + + VENDOR_SECTION = 0x8000 +}; + +/** + * Hierarchy positions in enum space. All vendor extension tags must be + * defined with tag >= VENDOR_SECTION_START + */ +enum { + ANDROID_REQUEST_START = ANDROID_REQUEST << 16, + ANDROID_LENS_START = ANDROID_LENS << 16, + ANDROID_LENS_INFO_START = ANDROID_LENS_INFO << 16, + ANDROID_SENSOR_START = ANDROID_SENSOR << 16, + ANDROID_SENSOR_INFO_START = ANDROID_SENSOR_INFO << 16, + ANDROID_FLASH_START = ANDROID_FLASH << 16, + ANDROID_FLASH_INFO_START = ANDROID_FLASH_INFO << 16, + ANDROID_HOT_PIXEL_START = ANDROID_HOT_PIXEL << 16, + ANDROID_HOT_PIXEL_INFO_START = ANDROID_HOT_PIXEL_INFO << 16, + ANDROID_DEMOSAIC_START = ANDROID_DEMOSAIC << 16, + ANDROID_DEMOSAIC_INFO_START = ANDROID_DEMOSAIC_INFO << 16, + ANDROID_NOISE_START = ANDROID_NOISE << 16, + ANDROID_NOISE_INFO_START = ANDROID_NOISE_INFO << 16, + ANDROID_SHADING_START = ANDROID_SHADING << 16, + ANDROID_SHADING_INFO_START = ANDROID_SHADING_INFO << 16, + ANDROID_GEOMETRIC_START = ANDROID_GEOMETRIC << 16, + ANDROID_GEOMETRIC_INFO_START = ANDROID_GEOMETRIC_INFO << 16, + ANDROID_COLOR_START = ANDROID_COLOR << 16, + ANDROID_COLOR_INFO_START = ANDROID_COLOR_INFO << 16, + ANDROID_TONEMAP_START = ANDROID_TONEMAP << 16, + ANDROID_TONEMAP_INFO_START = ANDROID_TONEMAP_INFO << 16, + ANDROID_EDGE_START = ANDROID_EDGE << 16, + ANDROID_EDGE_INFO_START = ANDROID_EDGE_INFO << 16, + ANDROID_SCALER_START = ANDROID_SCALER << 16, + ANDROID_SCALER_INFO_START = ANDROID_SCALER_INFO << 16, + ANDROID_JPEG_START = ANDROID_JPEG << 16, + ANDROID_JPEG_INFO_START = ANDROID_JPEG_INFO << 16, + ANDROID_STATS_START = ANDROID_STATS << 16, + ANDROID_STATS_INFO_START = ANDROID_STATS_INFO << 16, + ANDROID_CONTROL_START = ANDROID_CONTROL << 16, + ANDROID_CONTROL_INFO_START = ANDROID_CONTROL_INFO << 16, + VENDOR_SECTION_START = VENDOR_SECTION << 16 +}; + +/** + * Main enum for defining camera metadata tags. New entries must always go + * before the section _END tag to preserve existing enumeration values. In + * addition, the name and type of the tag needs to be added to + * system/media/camera/src/camera_metadata_tag_info.c + */ +enum { + ANDROID_REQUEST_ID = ANDROID_REQUEST_START, + ANDROID_REQUEST_METADATA_MODE, + ANDROID_REQUEST_OUTPUT_STREAMS, + ANDROID_REQUEST_FRAME_COUNT, + ANDROID_REQUEST_END, + + ANDROID_LENS_FOCUS_DISTANCE = ANDROID_LENS_START, + ANDROID_LENS_APERTURE, + ANDROID_LENS_FOCAL_LENGTH, + ANDROID_LENS_FILTER_DENSITY, + ANDROID_LENS_OPTICAL_STABILIZATION_MODE, + ANDROID_LENS_FOCUS_RANGE, + ANDROID_LENS_END, + + ANDROID_LENS_MINIMUM_FOCUS_DISTANCE = ANDROID_LENS_INFO_START, + ANDROID_LENS_AVAILABLE_FOCAL_LENGTHS, + ANDROID_LENS_AVAILABLE_APERTURES, + ANDROID_LENS_AVAILABLE_FILTER_DENSITY, + ANDROID_LENS_AVAILABLE_OPTICAL_STABILIZATION, + ANDROID_LENS_SHADING_MAP, + ANDROID_LENS_GEOMETRIC_CORRECTION_MAP, + ANDROID_LENS_FACING, + ANDROID_LENS_POSITION, + ANDROID_LENS_INFO_END, + + ANDROID_SENSOR_EXPOSURE_TIME = ANDROID_SENSOR_START, + ANDROID_SENSOR_FRAME_DURATION, + ANDROID_SENSOR_SENSITIVITY, + ANDROID_SENSOR_TIMESTAMP, + ANDROID_SENSOR_END, + + ANDROID_SENSOR_EXPOSURE_TIME_RANGE = ANDROID_SENSOR_INFO_START, + ANDROID_SENSOR_MAX_FRAME_DURATION, + ANDROID_SENSOR_SENSITIVITY_RANGE, + ANDROID_SENSOR_COLOR_FILTER_ARRANGEMENT, + ANDROID_SENSOR_PIXEL_ARRAY_SIZE, + ANDROID_SENSOR_ACTIVE_ARRAY_SIZE, + ANDROID_SENSOR_WHITE_LEVEL, + ANDROID_SENSOR_BLACK_LEVEL_PATTERN, + ANDROID_SENSOR_COLOR_TRANSFORM_1, + ANDROID_SENSOR_COLOR_TRANSFORM_2, + ANDROID_SENSOR_REFERENCE_ILLUMINANT_1, + ANDROID_SENSOR_REFERENCE_ILLUMINANT_2, + ANDROID_SENSOR_FORWARD_MATRIX_1, + ANDROID_SENSOR_FORWARD_MATRIX_2, + ANDROID_SENSOR_CALIBRATION_TRANSFORM_1, + ANDROID_SENSOR_CALIBRATION_TRANSFORM_2, + ANDROID_SENSOR_BASE_GAIN_FACTOR, + ANDROID_SENSOR_MAX_ANALOG_SENSITIVITY, + ANDROID_SENSOR_NOISE_MODEL_COEFFICIENTS, + ANDROID_SENSOR_ORIENTATION, + ANDROID_SENSOR_INFO_END, + + ANDROID_FLASH_MODE = ANDROID_FLASH_START, + ANDROID_FLASH_FIRING_POWER, + ANDROID_FLASH_FIRING_TIME, + ANDROID_FLASH_END, + + ANDROID_FLASH_AVAILABLE_MODES = ANDROID_FLASH_INFO_START, + ANDROID_FLASH_CHARGE_DURATION, + ANDROID_FLASH_INFO_END, + + ANDROID_HOT_PIXEL_MODE = ANDROID_HOT_PIXEL_START, + ANDROID_HOT_PIXEL_END, + + ANDROID_HOT_PIXEL_INFO_END = ANDROID_HOT_PIXEL_INFO_START, + + ANDROID_DEMOSAIC_MODE = ANDROID_DEMOSAIC_START, + ANDROID_DEMOSAIC_END, + + ANDROID_DEMOSAIC_INFO_END = ANDROID_DEMOSAIC_INFO_START, + + ANDROID_NOISE_MODE = ANDROID_NOISE_START, + ANDROID_NOISE_STRENGTH, + ANDROID_NOISE_END, + + ANDROID_NOISE_INFO_END = ANDROID_NOISE_INFO_START, + + ANDROID_SHADING_MODE = ANDROID_SHADING_START, + ANDROID_SHADING_END, + + ANDROID_SHADING_INFO_END = ANDROID_SHADING_INFO_START, + + ANDROID_GEOMETRIC_MODE = ANDROID_GEOMETRIC_START, + ANDROID_GEOMETRIC_END, + + ANDROID_GEOMETRIC_INFO_END = ANDROID_GEOMETRIC_INFO_START, + + ANDROID_COLOR_MODE = ANDROID_COLOR_START, + ANDROID_COLOR_TRANSFORM, + ANDROID_COLOR_END, + + ANDROID_COLOR_AVAILABLE_MODES = ANDROID_COLOR_INFO_START, + ANDROID_COLOR_INFO_END, + + ANDROID_TONEMAP_MODE = ANDROID_TONEMAP_START, + ANDROID_TONEMAP_CURVE_RED, + ANDROID_TONEMAP_CURVE_GREEN, + ANDROID_TONEMAP_CURVE_BLUE, + ANDROID_TONEMAP_END, + + ANDROID_TONEMAP_MAX_CURVE_POINTS = ANDROID_TONEMAP_INFO_START, + ANDROID_TONEMAP_INFO_END, + + ANDROID_EDGE_MODE = ANDROID_EDGE_START, + ANDROID_EDGE_STRENGTH, + ANDROID_EDGE_END, + + ANDROID_EDGE_INFO_END = ANDROID_EDGE_INFO_START, + + ANDROID_SCALER_SIZE = ANDROID_SCALER_START, + ANDROID_SCALER_FORMAT, + ANDROID_SCALER_CROP_REGION, + ANDROID_SCALER_ROTATION, + ANDROID_SCALER_END, + + ANDROID_SCALER_AVAILABLE_FORMATS = ANDROID_SCALER_INFO_START, + ANDROID_SCALER_AVAILABLE_SIZES_PER_FORMAT, + ANDROID_SCALER_AVAILABLE_SIZES, + ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS, + ANDROID_SCALER_AVAILABLE_MAX_ZOOM, + ANDROID_SCALER_INFO_END, + + ANDROID_JPEG_QUALITY = ANDROID_JPEG_START, + ANDROID_JPEG_THUMBNAIL_SIZE, + ANDROID_JPEG_THUMBNAIL_QUALITY, + ANDROID_JPEG_GPS_COORDINATES, + ANDROID_JPEG_GPS_PROCESSING_METHOD, + ANDROID_JPEG_GPS_TIMESTAMP, + ANDROID_JPEG_ORIENTATION, + ANDROID_JPEG_END, + + ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES = ANDROID_JPEG_INFO_START, + ANDROID_JPEG_INFO_END, + + ANDROID_STATS_FACE_DETECT_MODE = ANDROID_STATS_START, + ANDROID_STATS_HISTOGRAM_MODE, + ANDROID_STATS_SHARPNESS_MAP_MODE, + ANDROID_STATS_FACE_RECTANGLES, + ANDROID_STATS_FACE_SCORES, + ANDROID_STATS_FACE_LANDMARKS, + ANDROID_STATS_FACE_IDS, + ANDROID_STATS_HISTOGRAM, + ANDROID_STATS_SHARPNESS_MAP, + ANDROID_STATS_END, + + ANDROID_STATS_AVAILABLE_FACE_DETECT_MODES = ANDROID_STATS_INFO_START, + ANDROID_STATS_MAX_FACE_COUNT, + ANDROID_STATS_HISTOGRAM_BUCKET_COUNT, + ANDROID_STATS_MAX_HISTOGRAM_COUNT, + ANDROID_STATS_SHARPNESS_MAP_SIZE, + ANDROID_STATS_MAX_SHARPNESS_MAP_VALUE, + ANDROID_STATS_INFO_END, + + ANDROID_CONTROL_MODE = ANDROID_CONTROL_START, + ANDROID_CONTROL_AE_MODE, + ANDROID_CONTROL_AE_REGIONS, + ANDROID_CONTROL_AE_EXP_COMPENSATION, + ANDROID_CONTROL_AE_TARGET_FPS_RANGE, + ANDROID_CONTROL_AE_ANTIBANDING_MODE, + ANDROID_CONTROL_AWB_MODE, + ANDROID_CONTROL_AWB_REGIONS, + ANDROID_CONTROL_AF_MODE, + ANDROID_CONTROL_AF_REGIONS, + ANDROID_CONTROL_AF_TRIGGER, + ANDROID_CONTROL_AF_STATE, + ANDROID_CONTROL_VIDEO_STABILIZATION_MODE, + ANDROID_CONTROL_END, + + ANDROID_CONTROL_AVAILABLE_MODES = ANDROID_CONTROL_INFO_START, + ANDROID_CONTROL_MAX_REGIONS, + ANDROID_CONTROL_AE_AVAILABLE_MODES, + ANDROID_CONTROL_AE_EXP_COMPENSATION_STEP, + ANDROID_CONTROL_AE_EXP_COMPENSATION_RANGE, + ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES, + ANDROID_CONTROL_AE_AVAILABLE_ANTIBANDING_MODES, + ANDROID_CONTROL_AWB_AVAILABLE_MODES, + ANDROID_CONTROL_AF_AVAILABLE_MODES, + ANDROID_CONTROL_INFO_END +}; diff --git a/camera/src/Android.mk b/camera/src/Android.mk new file mode 100644 index 00000000..19a6f5b9 --- /dev/null +++ b/camera/src/Android.mk @@ -0,0 +1,24 @@ +LOCAL_PATH:= $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := \ + camera_metadata.c + +LOCAL_C_INCLUDES:= \ + system/media/camera/include + +LOCAL_SHARED_LIBRARIES := \ + libcutils + +LOCAL_MODULE := libcamera_metadata +LOCAL_MODULE_TAGS := optional + +LOCAL_CFLAGS += \ + -Wall \ + -fvisibility=hidden \ + + +include $(BUILD_SHARED_LIBRARY) + + diff --git a/camera/src/camera_metadata.c b/camera/src/camera_metadata.c new file mode 100644 index 00000000..a481bec5 --- /dev/null +++ b/camera/src/camera_metadata.c @@ -0,0 +1,500 @@ +/* + * 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. + */ + +#include <system/camera_metadata.h> +#include <cutils/log.h> + +#define OK 0 +#define ERROR 1 + +/** + * A single metadata entry, storing an array of values of a given type. If the + * array is no larger than 4 bytes in size, it is stored in the data.value[] + * array; otherwise, it can found in the parent's data array at index + * data.offset. + */ +typedef struct camera_metadata_entry { + uint32_t tag; + size_t count; + union { + size_t offset; + uint8_t value[4]; + } data; + uint8_t type; + uint8_t reserved[3]; +} __attribute__((packed)) camera_metadata_entry_t; + +/** + * A packet of metadata. This is a list of entries, each of which may point to + * its values stored at an offset in data. + * + * It is assumed by the utility functions that the memory layout of the packet + * is as follows: + * + * |----------------------------------------| + * | camera_metadata_t | + * | | + * |----------------------------------------| + * | reserved for future expansion | + * |----------------------------------------| + * | camera_metadata_entry_t #0 | + * |----------------------------------------| + * | .... | + * |----------------------------------------| + * | camera_metadata_entry_t #entry_count-1 | + * |----------------------------------------| + * | free space for | + * | (entry_capacity-entry_count) entries | + * |----------------------------------------| + * | start of camera_metadata.data | + * | | + * |----------------------------------------| + * | free space for | + * | (data_capacity-data_count) bytes | + * |----------------------------------------| + * + * With the total length of the whole packet being camera_metadata.size bytes. + * + * In short, the entries and data are contiguous in memory after the metadata + * header. + */ +struct camera_metadata { + size_t size; + size_t entry_count; + size_t entry_capacity; + camera_metadata_entry_t *entries; + size_t data_count; + size_t data_capacity; + uint8_t *data; + uint8_t reserved[0]; +}; + +typedef struct tag_info { + const char *tag_name; + uint8_t tag_type; +} tag_info_t; + +#include "camera_metadata_tag_info.c" + +size_t camera_metadata_type_size[NUM_TYPES] = { + [TYPE_BYTE] = sizeof(uint8_t), + [TYPE_INT32] = sizeof(int32_t), + [TYPE_FLOAT] = sizeof(float), + [TYPE_INT64] = sizeof(int64_t), + [TYPE_DOUBLE] = sizeof(double), + [TYPE_RATIONAL] = sizeof(camera_metadata_rational_t) +}; + +char *camera_metadata_type_names[NUM_TYPES] = { + [TYPE_BYTE] = "byte", + [TYPE_INT32] = "int32", + [TYPE_FLOAT] = "float", + [TYPE_INT64] = "int64", + [TYPE_RATIONAL] = "rational" +}; + +camera_metadata_t *allocate_camera_metadata(size_t entry_capacity, + size_t data_capacity) { + size_t memory_needed = calculate_camera_metadata_size(entry_capacity, + data_capacity); + void *buffer = malloc(memory_needed); + return place_camera_metadata(buffer, memory_needed, + entry_capacity, + data_capacity); +} + +camera_metadata_t *place_camera_metadata(void *dst, + size_t dst_size, + size_t entry_capacity, + size_t data_capacity) { + if (dst == NULL) return NULL; + if (entry_capacity == 0) return NULL; + + size_t memory_needed = calculate_camera_metadata_size(entry_capacity, + data_capacity); + if (memory_needed > dst_size) return NULL; + + camera_metadata_t *metadata = (camera_metadata_t*)dst; + metadata->entry_count = 0; + metadata->entry_capacity = entry_capacity; + metadata->entries = (camera_metadata_entry_t*)(metadata + 1); + metadata->data_count = 0; + metadata->data_capacity = data_capacity; + metadata->size = memory_needed; + if (metadata->data_capacity != 0) { + metadata->data = + (uint8_t*)(metadata->entries + metadata->entry_capacity); + } else { + metadata->data = NULL; + } + + return metadata; +} +void free_camera_metadata(camera_metadata_t *metadata) { + free(metadata); +} + +size_t calculate_camera_metadata_size(size_t entry_count, + size_t data_count) { + size_t memory_needed = sizeof(camera_metadata_t); + memory_needed += sizeof(camera_metadata_entry_t[entry_count]); + memory_needed += sizeof(uint8_t[data_count]); + return memory_needed; +} + +size_t get_camera_metadata_size(const camera_metadata_t *metadata) { + if (metadata == NULL) return ERROR; + + return metadata->size; +} + +size_t get_camera_metadata_compact_size(const camera_metadata_t *metadata) { + if (metadata == NULL) return ERROR; + + ptrdiff_t reserved_size = metadata->size - + calculate_camera_metadata_size(metadata->entry_capacity, + metadata->data_capacity); + + return calculate_camera_metadata_size(metadata->entry_count, + metadata->data_count) + reserved_size; +} + +size_t get_camera_metadata_entry_count(const camera_metadata_t *metadata) { + return metadata->entry_count; +} + +size_t get_camera_metadata_entry_capacity(const camera_metadata_t *metadata) { + return metadata->entry_capacity; +} + +size_t get_camera_metadata_data_count(const camera_metadata_t *metadata) { + return metadata->data_count; +} + +size_t get_camera_metadata_data_capacity(const camera_metadata_t *metadata) { + return metadata->data_capacity; +} + +camera_metadata_t* copy_camera_metadata(void *dst, size_t dst_size, + const camera_metadata_t *src) { + size_t memory_needed = get_camera_metadata_compact_size(src); + + if (dst == NULL) return NULL; + if (dst_size < memory_needed) return NULL; + + // If copying a newer version of the structure, there may be additional + // header fields we don't know about but need to copy + ptrdiff_t reserved_size = src->size - + calculate_camera_metadata_size(src->entry_capacity, + src->data_capacity); + + camera_metadata_t *metadata = (camera_metadata_t*)dst; + metadata->entry_count = src->entry_count; + metadata->entry_capacity = src->entry_count; + metadata->entries = (camera_metadata_entry_t*) + ((uint8_t *)(metadata + 1) + reserved_size); + metadata->data_count = src->data_count; + metadata->data_capacity = src->data_count; + metadata->data = (uint8_t *)(metadata->entries + metadata->entry_capacity); + metadata->size = memory_needed; + + if (reserved_size > 0) { + memcpy(metadata->reserved, src->reserved, reserved_size); + } + memcpy(metadata->entries, src->entries, + sizeof(camera_metadata_entry_t[metadata->entry_count])); + memcpy(metadata->data, src->data, + sizeof(uint8_t[metadata->data_count])); + + return metadata; +} + +int append_camera_metadata(camera_metadata_t *dst, + const camera_metadata_t *src) { + if (dst == NULL || src == NULL ) return ERROR; + + if (dst->entry_capacity < src->entry_count + dst->entry_count) return ERROR; + if (dst->data_capacity < src->data_count + dst->data_count) return ERROR; + + memcpy(dst->entries + dst->entry_count, src->entries, + sizeof(camera_metadata_entry_t[src->entry_count])); + memcpy(dst->data + dst->data_count, src->data, + sizeof(uint8_t[src->data_count])); + if (dst->data_count != 0) { + unsigned int i; + for (i = dst->entry_count; + i < dst->entry_count + src->entry_count; + i++) { + camera_metadata_entry_t *entry = dst->entries + i; + if ( camera_metadata_type_size[entry->type] * entry->count > 4 ) { + entry->data.offset += dst->data_count; + } + } + } + dst->entry_count += src->entry_count; + dst->data_count += src->data_count; + + return OK; +} + +size_t calculate_camera_metadata_entry_data_size(uint8_t type, + size_t data_count) { + if (type >= NUM_TYPES) return 0; + size_t data_bytes = data_count * + camera_metadata_type_size[type]; + return data_bytes <= 4 ? 0 : data_bytes; +} + +int add_camera_metadata_entry_raw(camera_metadata_t *dst, + uint32_t tag, + uint8_t type, + const void *data, + size_t data_count) { + + if (dst == NULL) return ERROR; + if (dst->entry_count == dst->entry_capacity) return ERROR; + if (data == NULL) return ERROR; + + size_t data_bytes = + calculate_camera_metadata_entry_data_size(type, data_count); + + camera_metadata_entry_t *entry = dst->entries + dst->entry_count; + entry->tag = tag; + entry->type = type; + entry->count = data_count; + + if (data_bytes == 0) { + memcpy(entry->data.value, data, + data_count * camera_metadata_type_size[type] ); + } else { + entry->data.offset = dst->data_count; + memcpy(dst->data + entry->data.offset, data, data_bytes); + dst->data_count += data_bytes; + } + dst->entry_count++; + return OK; +} + +int add_camera_metadata_entry(camera_metadata_t *dst, + uint32_t tag, + const void *data, + size_t data_count) { + + int type = get_camera_metadata_tag_type(tag); + if (type == -1) { + ALOGE("Unknown tag %04x (can't find type)", tag); + return ERROR; + } + + return add_camera_metadata_entry_raw(dst, + tag, + type, + data, + data_count); +} + +int get_camera_metadata_entry(camera_metadata_t *src, + uint32_t index, + uint32_t *tag, + uint8_t *type, + void **data, + size_t *data_count) { + if (src == NULL ) return ERROR; + if (tag == NULL) return ERROR; + if (type == NULL ) return ERROR; + if (data == NULL) return ERROR; + if (data_count == NULL) return ERROR; + + if (index >= src->entry_count) return ERROR; + + camera_metadata_entry_t *entry = src->entries + index; + + *tag = entry->tag; + *type = entry->type; + *data_count = entry->count; + if (entry->count * camera_metadata_type_size[entry->type] > 4) { + *data = src->data + entry->data.offset; + } else { + *data = entry->data.value; + } + return OK; +} + +static const vendor_tag_query_ops_t *vendor_tag_ops = NULL; + +const char *get_camera_metadata_section_name(uint32_t tag) { + uint32_t tag_section = tag >> 16; + if (tag_section >= VENDOR_SECTION && vendor_tag_ops != NULL) { + return vendor_tag_ops->get_camera_vendor_section_name(tag); + } + if (tag_section >= ANDROID_SECTION_COUNT) { + return NULL; + } + return camera_metadata_section_names[tag_section]; +} + +const char *get_camera_metadata_tag_name(uint32_t tag) { + uint32_t tag_section = tag >> 16; + if (tag_section >= VENDOR_SECTION && vendor_tag_ops != NULL) { + return vendor_tag_ops->get_camera_vendor_tag_name(tag); + } + if (tag_section >= ANDROID_SECTION_COUNT || + tag >= camera_metadata_section_bounds[tag_section][1] ) { + return NULL; + } + uint32_t tag_index = tag & 0xFFFF; + return tag_info[tag_section][tag_index].tag_name; +} + +int get_camera_metadata_tag_type(uint32_t tag) { + uint32_t tag_section = tag >> 16; + if (tag_section >= VENDOR_SECTION && vendor_tag_ops != NULL) { + return vendor_tag_ops->get_camera_vendor_tag_type(tag); + } + if (tag_section >= ANDROID_SECTION_COUNT || + tag >= camera_metadata_section_bounds[tag_section][1] ) { + return -1; + } + uint32_t tag_index = tag & 0xFFFF; + return tag_info[tag_section][tag_index].tag_type; +} + +int set_camera_metadata_vendor_tag_ops(const vendor_tag_query_ops_t *query_ops) { + vendor_tag_ops = query_ops; + return OK; +} + +void print_data(const uint8_t *data_ptr, int type, int count); + +void dump_camera_metadata(const camera_metadata_t *metadata, int verbosity) { + if (metadata == NULL) { + ALOGE("Metadata is null."); + return; + } + unsigned int i; + ALOGD("Dumping camera metadata array. %d entries, %d bytes of extra data.", + metadata->entry_count, metadata->data_count); + ALOGD(" (%d entries and %d bytes data reserved)", + metadata->entry_capacity, metadata->data_capacity); + for (i=0; i < metadata->entry_count; i++) { + camera_metadata_entry_t *entry = metadata->entries + i; + + const char *tag_name, *tag_section; + tag_section = get_camera_metadata_section_name(entry->tag); + if (tag_section == NULL) { + tag_section = "unknownSection"; + } + tag_name = get_camera_metadata_tag_name(entry->tag); + if (tag_name == NULL) { + tag_name = "unknownTag"; + } + const char *type_name; + if (entry->type >= NUM_TYPES) { + type_name = "unknown"; + } else { + type_name = camera_metadata_type_names[entry->type]; + } + ALOGD("Tag: %s.%s (%05x): %s[%d]", + tag_section, + tag_name, + entry->tag, + type_name, + entry->count); + + if (verbosity < 1) continue; + + if (entry->type >= NUM_TYPES) continue; + + size_t type_size = camera_metadata_type_size[entry->type]; + uint8_t *data_ptr; + if ( type_size * entry->count > 4 ) { + if (entry->data.offset >= metadata->data_count) { + ALOGE("Malformed entry data offset: %d (max %d)", + entry->data.offset, + metadata->data_count); + continue; + } + data_ptr = metadata->data + entry->data.offset; + } else { + data_ptr = entry->data.value; + } + int count = entry->count; + if (verbosity < 2 && count > 16) count = 16; + + print_data(data_ptr, entry->type, count); + } +} + +void print_data(const uint8_t *data_ptr, int type, int count) { + static int values_per_line[NUM_TYPES] = { + [TYPE_BYTE] = 16, + [TYPE_INT32] = 4, + [TYPE_FLOAT] = 8, + [TYPE_INT64] = 2, + [TYPE_DOUBLE] = 4, + [TYPE_RATIONAL] = 2, + }; + size_t type_size = camera_metadata_type_size[type]; + + int lines = count / values_per_line[type]; + if (count % values_per_line[type] != 0) lines++; + + char tmp1[80], tmp2[80]; + + int index = 0; + int j, k; + for (j = 0; j < lines; j++) { + tmp1[0] = 0; + for (k = 0; + k < values_per_line[type] && count > 0; + k++, count--, index += type_size) { + + switch (type) { + case TYPE_BYTE: + snprintf(tmp2, sizeof(tmp2), "%hhu ", + *(data_ptr + index)); + break; + case TYPE_INT32: + snprintf(tmp2, sizeof(tmp2), "%d ", + *(int32_t*)(data_ptr + index)); + break; + case TYPE_FLOAT: + snprintf(tmp2, sizeof(tmp2), "%0.2f ", + *(float*)(data_ptr + index)); + break; + case TYPE_INT64: + snprintf(tmp2, sizeof(tmp2), "%lld ", + *(int64_t*)(data_ptr + index)); + break; + case TYPE_DOUBLE: + snprintf(tmp2, sizeof(tmp2), "%0.2f ", + *(float*)(data_ptr + index)); + break; + case TYPE_RATIONAL: { + int32_t numerator = *(int32_t*)(data_ptr + index); + int32_t denominator = *(int32_t*)(data_ptr + index + 4); + snprintf(tmp2, sizeof(tmp2), "(%d / %d) ", + numerator, denominator); + break; + } + default: + snprintf(tmp2, sizeof(tmp2), "??? "); + } + strncat(tmp1, tmp2, sizeof(tmp1)); + } + ALOGD(" [ %s]", tmp1); + } +} diff --git a/camera/src/camera_metadata_tag_info.c b/camera/src/camera_metadata_tag_info.c new file mode 100644 index 00000000..5d394e2f --- /dev/null +++ b/camera/src/camera_metadata_tag_info.c @@ -0,0 +1,360 @@ +/* + * 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. + */ + +/** + * !! Do not reference this file directly !! + * + * It is logically a part of camera_metadata.c. It is broken out for ease of + * maintaining the tag info. + */ + +const char *camera_metadata_section_names[ANDROID_SECTION_COUNT] = { + "android.request", + "android.control", + "android.control.info", + "android.sensor", + "android.sensor.info", + "android.lens", + "android.lens.info", + "android.flash", + "android.flash.info", + "android.hotPixel", + "android.hotPixel.info", + "android.demosaic", + "android.demosaic.info", + "android.noiseReduction", + "android.noiseReduction.info", + "android.shadingCorrection", + "android.shadingCorrection.info", + "android.geometricCorrection", + "android.geometricCorrection.info", + "android.colorCorrection", + "android.colorCorrection.info", + "android.tonemap", + "android.tonemap.info", + "android.edge", + "android.edge.info", + "android.scaler", + "android.scaler.info", + "android.jpeg", + "android.jpeg.info", + "android.statistics", + "android.statistics.info" +}; + +unsigned int camera_metadata_section_bounds[ANDROID_SECTION_COUNT][2] = { + { ANDROID_REQUEST_START, ANDROID_REQUEST_END }, + { ANDROID_LENS_START, ANDROID_LENS_END }, + { ANDROID_LENS_INFO_START, ANDROID_LENS_INFO_END }, + { ANDROID_SENSOR_START, ANDROID_SENSOR_END }, + { ANDROID_SENSOR_INFO_START, ANDROID_SENSOR_INFO_END }, + { ANDROID_FLASH_START, ANDROID_FLASH_END }, + { ANDROID_FLASH_INFO_START, ANDROID_FLASH_INFO_END }, + { ANDROID_HOT_PIXEL_START, ANDROID_HOT_PIXEL_END }, + { ANDROID_HOT_PIXEL_INFO_START, ANDROID_HOT_PIXEL_INFO_END }, + { ANDROID_DEMOSAIC_START, ANDROID_DEMOSAIC_END }, + { ANDROID_DEMOSAIC_INFO_START, ANDROID_DEMOSAIC_INFO_END }, + { ANDROID_NOISE_START, ANDROID_NOISE_END }, + { ANDROID_NOISE_INFO_START, ANDROID_NOISE_INFO_END }, + { ANDROID_SHADING_START, ANDROID_SHADING_END }, + { ANDROID_SHADING_INFO_START, ANDROID_SHADING_INFO_END }, + { ANDROID_GEOMETRIC_START, ANDROID_GEOMETRIC_END }, + { ANDROID_GEOMETRIC_INFO_START, ANDROID_GEOMETRIC_INFO_END }, + { ANDROID_COLOR_START, ANDROID_COLOR_END }, + { ANDROID_COLOR_INFO_START, ANDROID_COLOR_INFO_END }, + { ANDROID_TONEMAP_START, ANDROID_TONEMAP_END }, + { ANDROID_TONEMAP_INFO_START, ANDROID_TONEMAP_INFO_END }, + { ANDROID_EDGE_START, ANDROID_EDGE_END }, + { ANDROID_EDGE_INFO_START, ANDROID_EDGE_INFO_END }, + { ANDROID_SCALER_START, ANDROID_SCALER_END }, + { ANDROID_SCALER_INFO_START, ANDROID_SCALER_INFO_END }, + { ANDROID_JPEG_START, ANDROID_JPEG_END }, + { ANDROID_JPEG_INFO_START, ANDROID_JPEG_INFO_END }, + { ANDROID_STATS_START, ANDROID_STATS_END }, + { ANDROID_STATS_INFO_START, ANDROID_STATS_INFO_END }, + { ANDROID_CONTROL_START, ANDROID_CONTROL_END }, + { ANDROID_CONTROL_INFO_START, ANDROID_CONTROL_INFO_END } +}; + +tag_info_t android_request[ANDROID_REQUEST_END - + ANDROID_REQUEST_START] = { + { "id", TYPE_INT32 }, + { "metadataMode", TYPE_BYTE }, + { "outputStreams", TYPE_BYTE }, + { "frameCount", TYPE_INT32 } +}; + +tag_info_t android_control[ANDROID_CONTROL_END - + ANDROID_CONTROL_START] = { + { "mode", TYPE_BYTE }, + { "aeMode", TYPE_BYTE }, + { "aeRegions", TYPE_INT32 }, + { "aeExposureCompensation", TYPE_INT32 }, + { "aeTargetFpsRange", TYPE_INT32 }, + { "aeAntibandingMode", TYPE_BYTE }, + { "awbMode", TYPE_BYTE }, + { "awbRegions", TYPE_INT32 }, + { "afMode", TYPE_BYTE }, + { "afRegions", TYPE_INT32 }, + { "afTrigger", TYPE_BYTE }, + { "afState", TYPE_BYTE }, + { "videoStabilizationMode", TYPE_BYTE } +}; + +tag_info_t android_control_info[ANDROID_CONTROL_INFO_END - + ANDROID_CONTROL_INFO_START] = { + { "availableModes", TYPE_BYTE }, + { "maxRegions", TYPE_INT32 }, + { "aeAvailableModes", TYPE_BYTE }, + { "aeCompensationStep", TYPE_RATIONAL }, + { "aeCompensationRange", TYPE_INT32 }, + { "aeAvailableTargetFpsRanges", TYPE_INT32 }, + { "aeAvailableAntibandingModes", TYPE_BYTE }, + { "awbAvailableModes", TYPE_BYTE }, + { "afAvailableModes", TYPE_BYTE } +}; + +tag_info_t android_sensor[ANDROID_SENSOR_END - + ANDROID_SENSOR_START] = { + { "exposureTime", TYPE_INT64 }, + { "frameDuration", TYPE_INT64 }, + { "sensitivity", TYPE_INT32 }, + { "timestamp", TYPE_INT64 } +}; + +tag_info_t android_sensor_info[ANDROID_SENSOR_INFO_END - + ANDROID_SENSOR_INFO_START] = { + { "exposureTimeRange", TYPE_INT64 }, + { "maxFrameDuration", TYPE_INT64 }, + { "sensitivityRange", TYPE_INT32 }, + { "colorFilterArrangement", TYPE_BYTE }, + { "pixelArraySize", TYPE_INT32 }, + { "activeArraySize", TYPE_INT32 }, + { "whiteLevel", TYPE_INT32 }, + { "blackLevelPattern", TYPE_INT32 }, + { "colorTransform1", TYPE_RATIONAL }, + { "colorTransform2", TYPE_RATIONAL }, + { "referenceIlluminant1", TYPE_BYTE }, + { "referenceIlluminant2", TYPE_BYTE }, + { "forwardMatrix1", TYPE_RATIONAL }, + { "forwardMatrix2", TYPE_RATIONAL }, + { "calibrationTransform1", TYPE_RATIONAL }, + { "calibrationTransform2", TYPE_RATIONAL }, + { "baseGainFactor", TYPE_RATIONAL }, + { "maxAnalogSensitivity", TYPE_INT32 }, + { "noiseModelCoefficients", TYPE_FLOAT }, + { "orientation", TYPE_INT32 } +}; + +tag_info_t android_lens[ANDROID_LENS_END - + ANDROID_LENS_START] = { + { "focusDistance", TYPE_FLOAT }, + { "aperture", TYPE_FLOAT }, + { "focalLength", TYPE_FLOAT }, + { "filterDensity", TYPE_FLOAT }, + { "opticalStabilizationMode", TYPE_BYTE }, + { "focusRange", TYPE_FLOAT } +}; + +tag_info_t android_lens_info[ANDROID_LENS_INFO_END - + ANDROID_LENS_INFO_START] = { + { "minimumFocusDistance", TYPE_FLOAT }, + { "availableFocalLengths", TYPE_FLOAT }, + { "availableApertures", TYPE_FLOAT }, + { "availableFilterDensities", TYPE_FLOAT }, + { "availableOpticalStabilizationModes", TYPE_BYTE }, + { "shadingMap", TYPE_FLOAT }, + { "geometricCorrectionMap", TYPE_FLOAT }, + { "facing", TYPE_BYTE }, + { "position", TYPE_FLOAT } +}; + +tag_info_t android_flash[ANDROID_FLASH_END - + ANDROID_FLASH_START] = { + { "mode", TYPE_BYTE }, + { "firingPower", TYPE_BYTE }, + { "firingTime", TYPE_INT64 } +}; + +tag_info_t android_flash_info[ANDROID_FLASH_INFO_END - + ANDROID_FLASH_INFO_START] = { + { "available", TYPE_BYTE }, + { "chargeDuration", TYPE_INT64 }, +}; + +tag_info_t android_hot_pixel[ANDROID_HOT_PIXEL_END - + ANDROID_HOT_PIXEL_START] = { + { "mode", TYPE_BYTE } +}; + +tag_info_t android_hot_pixel_info[ANDROID_HOT_PIXEL_INFO_END - + ANDROID_HOT_PIXEL_INFO_START]; + +tag_info_t android_demosaic[ANDROID_DEMOSAIC_END - + ANDROID_DEMOSAIC_START] = { + { "mode", TYPE_BYTE } +}; + +tag_info_t android_demosaic_info[ANDROID_DEMOSAIC_INFO_END - + ANDROID_DEMOSAIC_INFO_START]; + +tag_info_t android_noise[ANDROID_NOISE_END - + ANDROID_NOISE_START] = { + { "mode", TYPE_BYTE }, + { "strength", TYPE_BYTE } +}; + +tag_info_t android_noise_info[ANDROID_NOISE_INFO_END - + ANDROID_NOISE_INFO_START]; + +tag_info_t android_shading[ANDROID_SHADING_END - + ANDROID_SHADING_START] = { + { "mode", TYPE_BYTE } +}; + +tag_info_t android_shading_info[ANDROID_SHADING_INFO_END - + ANDROID_SHADING_INFO_START]; + +tag_info_t android_geometric[ANDROID_GEOMETRIC_END - + ANDROID_GEOMETRIC_START] = { + { "mode", TYPE_BYTE } +}; + +tag_info_t android_geometric_info[ANDROID_GEOMETRIC_INFO_END - + ANDROID_GEOMETRIC_INFO_START]; + +tag_info_t android_color[ANDROID_COLOR_END - + ANDROID_COLOR_START] = { + { "mode", TYPE_BYTE }, + { "transform", TYPE_FLOAT } +}; + +tag_info_t android_color_info[ANDROID_COLOR_INFO_END - + ANDROID_COLOR_INFO_START] = { + { "availableModes", TYPE_INT32 } +}; + +tag_info_t android_tonemap[ANDROID_TONEMAP_END - + ANDROID_TONEMAP_START] = { + { "mode", TYPE_BYTE }, + { "curveRed", TYPE_FLOAT }, + { "curveGreen", TYPE_FLOAT }, + { "curveBlue", TYPE_FLOAT } +}; + +tag_info_t android_tonemap_info[ANDROID_TONEMAP_INFO_END - + ANDROID_TONEMAP_INFO_START] = { + { "maxCurvePoints", TYPE_INT32 } +}; + +tag_info_t android_edge[ANDROID_EDGE_END - + ANDROID_EDGE_START] = { + { "mode", TYPE_BYTE }, + { "strength", TYPE_BYTE } +}; + +tag_info_t android_edge_info[ANDROID_EDGE_INFO_END - + ANDROID_EDGE_INFO_START]; + +tag_info_t android_scaler[ANDROID_SCALER_END - + ANDROID_SCALER_START] = { + { "size", TYPE_INT32 }, + { "format", TYPE_BYTE }, + { "cropRegion", TYPE_INT32 }, + { "rotation", TYPE_INT32 }, +}; + +tag_info_t android_scaler_info[ANDROID_SCALER_INFO_END - + ANDROID_SCALER_INFO_START] = { + { "availableFormats", TYPE_INT32 }, + { "availableSizesPerFormat", TYPE_INT32 }, + { "availableSizes", TYPE_INT32 }, + { "availableMinFrameDurations", TYPE_INT32 }, + { "availableMaxDigitalZoom", TYPE_INT32 } +}; + +tag_info_t android_jpeg[ANDROID_JPEG_END - + ANDROID_JPEG_START] = { + { "quality", TYPE_INT32 }, + { "thumbnailSize", TYPE_INT32 }, + { "thumbnailQuality", TYPE_INT32 }, + { "gpsCoordinates", TYPE_DOUBLE }, + { "gpsProcessingMethod", TYPE_BYTE }, + { "gpsTimestamp", TYPE_INT64 }, + { "orientation", TYPE_INT32 } +}; + +tag_info_t android_jpeg_info[ANDROID_JPEG_INFO_END - + ANDROID_JPEG_INFO_START] = { + { "availableThumbnailSizes", TYPE_INT32 } +}; + +tag_info_t android_stats[ANDROID_STATS_END - + ANDROID_STATS_START] = { + { "faceDetectMode", TYPE_BYTE }, + { "faceRectangles", TYPE_INT32 }, + { "faceScores", TYPE_BYTE }, + { "faceLandmarks", TYPE_INT32 }, + { "faceIds", TYPE_INT32 }, + { "histogramMode", TYPE_BYTE }, + { "histogram", TYPE_INT32 }, + { "sharpnessMapMode", TYPE_BYTE }, + { "sharpnessMap", TYPE_INT32 } +}; + +tag_info_t android_stats_info[ANDROID_STATS_INFO_END - + ANDROID_STATS_INFO_START] = { + { "availableFaceDetectModes", TYPE_BYTE }, + { "maxFaceCount", TYPE_INT32 }, + { "histogramBucketCount", TYPE_INT32 }, + { "maxHistogramCount", TYPE_INT32 }, + { "sharpnessMapSize", TYPE_INT32 }, + { "maxSharpnessMapValue", TYPE_INT32 } +}; + +tag_info_t *tag_info[ANDROID_SECTION_COUNT] = { + android_request, + android_lens, + android_lens_info, + android_sensor, + android_sensor_info, + android_flash, + android_flash_info, + android_hot_pixel, + android_hot_pixel_info, + android_demosaic, + android_demosaic_info, + android_noise, + android_noise_info, + android_shading, + android_shading_info, + android_geometric, + android_geometric_info, + android_color, + android_color_info, + android_tonemap, + android_tonemap_info, + android_edge, + android_edge_info, + android_scaler, + android_scaler_info, + android_jpeg, + android_jpeg_info, + android_stats, + android_stats_info, + android_control, + android_control_info +}; diff --git a/camera/tests/Android.mk b/camera/tests/Android.mk new file mode 100644 index 00000000..d7a53de1 --- /dev/null +++ b/camera/tests/Android.mk @@ -0,0 +1,27 @@ +# Build the unit tests. +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_SHARED_LIBRARIES := \ + libutils \ + libstlport \ + libcamera_metadata + +LOCAL_STATIC_LIBRARIES := \ + libgtest \ + libgtest_main + +LOCAL_C_INCLUDES := \ + bionic \ + bionic/libstdc++/include \ + external/gtest/include \ + external/stlport/stlport \ + system/media/camera/include \ + +LOCAL_SRC_FILES := \ + camera_metadata_tests.cpp + +LOCAL_MODULE := camera_metadata_tests +LOCAL_MODULE_TAGS := tests + +include $(BUILD_EXECUTABLE) diff --git a/camera/tests/camera_metadata_tests.cpp b/camera/tests/camera_metadata_tests.cpp new file mode 100644 index 00000000..3f1800ec --- /dev/null +++ b/camera/tests/camera_metadata_tests.cpp @@ -0,0 +1,829 @@ +/* + * 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. + */ + +#include "gtest/gtest.h" +#include "system/camera_metadata.h" + +#include "camera_metadata_tests_fake_vendor.h" + +#define EXPECT_NULL(x) EXPECT_EQ((void*)0, x) +#define EXPECT_NOT_NULL(x) EXPECT_NE((void*)0, x) + +#define OK 0 +#define ERROR 1 + +TEST(camera_metadata, allocate_normal) { + camera_metadata_t *m = NULL; + const size_t entry_capacity = 5; + const size_t data_capacity = 32; + + m = allocate_camera_metadata(entry_capacity, data_capacity); + + EXPECT_NOT_NULL(m); + EXPECT_EQ((size_t)0, get_camera_metadata_entry_count(m)); + EXPECT_EQ(entry_capacity, get_camera_metadata_entry_capacity(m)); + EXPECT_EQ((size_t)0, get_camera_metadata_data_count(m)); + EXPECT_EQ(data_capacity, get_camera_metadata_data_capacity(m)); + + free_camera_metadata(m); +} + +TEST(camera_metadata, allocate_nodata) { + camera_metadata_t *m = NULL; + + m = allocate_camera_metadata(1, 0); + + EXPECT_NOT_NULL(m); + EXPECT_EQ((size_t)0, get_camera_metadata_entry_count(m)); + EXPECT_EQ((size_t)1, get_camera_metadata_entry_capacity(m)); + EXPECT_EQ((size_t)0, get_camera_metadata_data_count(m)); + EXPECT_EQ((size_t)0, get_camera_metadata_data_capacity(m)); + + free_camera_metadata(m); +} + +TEST(camera_metadata, allocate_nothing) { + camera_metadata_t *m = NULL; + + m = allocate_camera_metadata(0, 0); + + EXPECT_NULL(m); +} + +TEST(camera_metadata, place_normal) { + camera_metadata_t *m = NULL; + void *buf = NULL; + + const size_t entry_capacity = 5; + const size_t data_capacity = 32; + + size_t buf_size = calculate_camera_metadata_size(entry_capacity, + data_capacity); + + EXPECT_TRUE(buf_size > 0); + + buf = malloc(buf_size); + + EXPECT_NOT_NULL(buf); + + m = place_camera_metadata(buf, buf_size, entry_capacity, data_capacity); + + EXPECT_EQ(buf, (uint8_t*)m); + EXPECT_EQ((size_t)0, get_camera_metadata_entry_count(m)); + EXPECT_EQ(entry_capacity, get_camera_metadata_entry_capacity(m)); + EXPECT_EQ((size_t)0, get_camera_metadata_data_count(m)); + EXPECT_EQ(data_capacity, get_camera_metadata_data_capacity(m)); + + free(buf); +} + +TEST(camera_metadata, place_nospace) { + camera_metadata_t *m = NULL; + void *buf = NULL; + + const size_t entry_capacity = 5; + const size_t data_capacity = 32; + + size_t buf_size = calculate_camera_metadata_size(entry_capacity, + data_capacity); + + EXPECT_GT(buf_size, (size_t)0); + + buf_size--; + + buf = malloc(buf_size); + + EXPECT_NOT_NULL(buf); + + m = place_camera_metadata(buf, buf_size, entry_capacity, data_capacity); + + EXPECT_NULL(m); + + free(buf); +} + +TEST(camera_metadata, place_extraspace) { + camera_metadata_t *m = NULL; + uint8_t *buf = NULL; + + const size_t entry_capacity = 5; + const size_t data_capacity = 32; + const size_t extra_space = 10; + + size_t buf_size = calculate_camera_metadata_size(entry_capacity, + data_capacity); + + EXPECT_GT(buf_size, (size_t)0); + + buf_size += extra_space; + + buf = (uint8_t*)malloc(buf_size); + + EXPECT_NOT_NULL(buf); + + m = place_camera_metadata(buf, buf_size, entry_capacity, data_capacity); + + EXPECT_EQ((uint8_t*)m, buf); + EXPECT_EQ((size_t)0, get_camera_metadata_entry_count(m)); + EXPECT_EQ(entry_capacity, get_camera_metadata_entry_capacity(m)); + EXPECT_EQ((size_t)0, get_camera_metadata_data_count(m)); + EXPECT_EQ(data_capacity, get_camera_metadata_data_capacity(m)); + EXPECT_EQ(buf + buf_size - extra_space, (uint8_t*)m + get_camera_metadata_size(m)); + + free(buf); +} + +TEST(camera_metadata, get_size) { + camera_metadata_t *m = NULL; + const size_t entry_capacity = 5; + const size_t data_capacity = 32; + + m = allocate_camera_metadata(entry_capacity, data_capacity); + + EXPECT_EQ(calculate_camera_metadata_size(entry_capacity, data_capacity), + get_camera_metadata_size(m) ); + + EXPECT_EQ(calculate_camera_metadata_size(0,0), + get_camera_metadata_compact_size(m) ); + + free_camera_metadata(m); +} + +TEST(camera_metadata, add_get_normal) { + camera_metadata_t *m = NULL; + const size_t entry_capacity = 5; + const size_t data_capacity = 80; + + m = allocate_camera_metadata(entry_capacity, data_capacity); + + int result; + size_t data_used = 0; + size_t entries_used = 0; + + // INT64 + + int64_t exposure_time = 1000000000; + result = add_camera_metadata_entry(m, + ANDROID_SENSOR_EXPOSURE_TIME, + &exposure_time, 1); + EXPECT_EQ(OK, result); + data_used += calculate_camera_metadata_entry_data_size( + get_camera_metadata_tag_type(ANDROID_SENSOR_EXPOSURE_TIME), 1); + entries_used++; + + // INT32 + + int32_t sensitivity = 800; + result = add_camera_metadata_entry(m, + ANDROID_SENSOR_SENSITIVITY, + &sensitivity, 1); + EXPECT_EQ(OK, result); + data_used += calculate_camera_metadata_entry_data_size( + get_camera_metadata_tag_type(ANDROID_SENSOR_SENSITIVITY), 1); + entries_used++; + + // FLOAT + + float focusDistance = 0.5f; + result = add_camera_metadata_entry(m, + ANDROID_LENS_FOCUS_DISTANCE, + &focusDistance, 1); + EXPECT_EQ(OK, result); + data_used += calculate_camera_metadata_entry_data_size( + get_camera_metadata_tag_type(ANDROID_LENS_FOCUS_DISTANCE), 1); + entries_used++; + + // Array of FLOAT + + float colorTransform[9] = { + 0.9f, 0.0f, 0.0f, + 0.2f, 0.5f, 0.0f, + 0.0f, 0.1f, 0.7f + }; + result = add_camera_metadata_entry(m, + ANDROID_COLOR_TRANSFORM, + colorTransform, 9); + EXPECT_EQ(OK, result); + data_used += calculate_camera_metadata_entry_data_size( + get_camera_metadata_tag_type(ANDROID_COLOR_TRANSFORM), 9); + entries_used++; + + // Check added entries + + uint32_t tag = 0; + uint8_t type = 0; + int32_t *data_int32; + int64_t *data_int64; + float *data_float; + size_t data_count = 0; + + result = get_camera_metadata_entry(m, + 0, &tag, &type, (void**)&data_int64, &data_count); + EXPECT_EQ(OK, result); + EXPECT_EQ(ANDROID_SENSOR_EXPOSURE_TIME, tag); + EXPECT_EQ(TYPE_INT64, type); + EXPECT_EQ((size_t)1, data_count); + EXPECT_EQ(exposure_time, *data_int64); + + result = get_camera_metadata_entry(m, + 1, &tag, &type, (void**)&data_int32, &data_count); + EXPECT_EQ(OK, result); + EXPECT_EQ(ANDROID_SENSOR_SENSITIVITY, tag); + EXPECT_EQ(TYPE_INT32, type); + EXPECT_EQ((size_t)1, data_count); + EXPECT_EQ(sensitivity, *data_int32); + + result = get_camera_metadata_entry(m, + 2, &tag, &type, (void**)&data_float, &data_count); + EXPECT_EQ(OK, result); + EXPECT_EQ(ANDROID_LENS_FOCUS_DISTANCE, tag); + EXPECT_EQ(TYPE_FLOAT, type); + EXPECT_EQ((size_t)1, data_count); + EXPECT_EQ(focusDistance, *data_float); + + result = get_camera_metadata_entry(m, + 3, &tag, &type, (void**)&data_float, &data_count); + EXPECT_EQ(OK, result); + EXPECT_EQ(ANDROID_COLOR_TRANSFORM, tag); + EXPECT_EQ(TYPE_FLOAT, type); + EXPECT_EQ((size_t)9, data_count); + for (unsigned int i=0; i < data_count; i++) { + EXPECT_EQ(colorTransform[i], data_float[i] ); + } + + EXPECT_EQ(calculate_camera_metadata_size(entry_capacity, data_capacity), + get_camera_metadata_size(m) ); + + EXPECT_EQ(calculate_camera_metadata_size(entries_used, data_used), + get_camera_metadata_compact_size(m) ); + + dump_camera_metadata(m, 2); + + free_camera_metadata(m); +} + +void add_test_metadata(camera_metadata_t *m, int entry_count) { + + EXPECT_NOT_NULL(m); + + int result; + size_t data_used = 0; + size_t entries_used = 0; + int64_t exposure_time; + for (int i=0; i < entry_count; i++ ) { + exposure_time = 100 + i * 100; + result = add_camera_metadata_entry(m, + ANDROID_SENSOR_EXPOSURE_TIME, + &exposure_time, 1); + EXPECT_EQ(OK, result); + data_used += calculate_camera_metadata_entry_data_size( + get_camera_metadata_tag_type(ANDROID_SENSOR_EXPOSURE_TIME), 1); + entries_used++; + } + EXPECT_EQ(data_used, get_camera_metadata_data_count(m)); + EXPECT_EQ(entries_used, get_camera_metadata_entry_count(m)); + EXPECT_GT(get_camera_metadata_data_capacity(m), + get_camera_metadata_data_count(m)); +} + +TEST(camera_metadata, add_get_toomany) { + camera_metadata_t *m = NULL; + const size_t entry_capacity = 5; + const size_t data_capacity = 50; + int result; + + m = allocate_camera_metadata(entry_capacity, data_capacity); + + add_test_metadata(m, entry_capacity); + + int32_t sensitivity = 100; + result = add_camera_metadata_entry(m, + ANDROID_SENSOR_SENSITIVITY, + &sensitivity, 1); + + EXPECT_EQ(ERROR, result); + + uint32_t tag = 0; + uint8_t type = 0; + int32_t *data_int32; + size_t data_count = 0; + for (unsigned int i=0; i < entry_capacity; i++) { + int64_t exposure_time = 100 + i * 100; + result = get_camera_metadata_entry(m, + i, &tag, &type, (void**)&data_int32, &data_count); + EXPECT_EQ(OK, result); + EXPECT_EQ(ANDROID_SENSOR_EXPOSURE_TIME, tag); + EXPECT_EQ(TYPE_INT64, type); + EXPECT_EQ((size_t)1, data_count); + EXPECT_EQ(exposure_time, *data_int32); + } + tag = 0; + type = 0; + data_int32 = NULL; + data_count = 0; + result = get_camera_metadata_entry(m, + entry_capacity, &tag, &type, (void**)&data_int32, &data_count); + EXPECT_EQ(ERROR, result); + EXPECT_EQ((uint32_t)0, tag); + EXPECT_EQ((uint8_t)0, type); + EXPECT_EQ((size_t)0, data_count); + EXPECT_EQ(NULL, data_int32); + + dump_camera_metadata(m, 2); + + free_camera_metadata(m); +} + +TEST(camera_metadata, copy_metadata) { + camera_metadata_t *m = NULL; + const size_t entry_capacity = 50; + const size_t data_capacity = 450; + + int result; + + m = allocate_camera_metadata(entry_capacity, data_capacity); + + add_test_metadata(m, entry_capacity); + + size_t buf_size = get_camera_metadata_compact_size(m); + EXPECT_LT((size_t)0, buf_size); + + uint8_t *buf = (uint8_t*)malloc(buf_size); + EXPECT_NOT_NULL(buf); + + camera_metadata_t *m2 = copy_camera_metadata(buf, buf_size, m); + EXPECT_NOT_NULL(m2); + EXPECT_EQ(buf, (uint8_t*)m2); + EXPECT_EQ(get_camera_metadata_entry_count(m), + get_camera_metadata_entry_count(m2)); + EXPECT_EQ(get_camera_metadata_data_count(m), + get_camera_metadata_data_count(m2)); + EXPECT_EQ(get_camera_metadata_entry_capacity(m2), + get_camera_metadata_entry_count(m2)); + EXPECT_EQ(get_camera_metadata_data_capacity(m2), + get_camera_metadata_data_count(m2)); + + for (unsigned int i=0; i < get_camera_metadata_entry_count(m); i++) { + uint32_t tag, tag2; + uint8_t type, type2; + uint8_t *data, *data2; + size_t data_count, data_count2; + + int result; + result = get_camera_metadata_entry(m, + i, &tag, &type, (void**)&data, &data_count); + EXPECT_EQ(OK, result); + result = get_camera_metadata_entry(m2, + i, &tag2, &type2, (void**)&data2, &data_count2); + EXPECT_EQ(OK, result); + EXPECT_EQ(tag, tag2); + EXPECT_EQ(type, type2); + EXPECT_EQ(data_count, data_count2); + for (unsigned int j=0; j < data_count; j++) { + EXPECT_EQ(data[j], data2[j]); + } + } + + free(buf); + + free_camera_metadata(m); +} + +TEST(camera_metadata, copy_metadata_extraspace) { + camera_metadata_t *m = NULL; + const size_t entry_capacity = 12; + const size_t data_capacity = 100; + + const size_t extra_space = 10; + + int result; + + m = allocate_camera_metadata(entry_capacity, data_capacity); + + add_test_metadata(m, entry_capacity); + + size_t buf_size = get_camera_metadata_compact_size(m); + EXPECT_LT((size_t)0, buf_size); + buf_size += extra_space; + + uint8_t *buf = (uint8_t*)malloc(buf_size); + EXPECT_NOT_NULL(buf); + + camera_metadata_t *m2 = copy_camera_metadata(buf, buf_size, m); + EXPECT_NOT_NULL(m2); + EXPECT_EQ(buf, (uint8_t*)m2); + EXPECT_EQ(get_camera_metadata_entry_count(m), + get_camera_metadata_entry_count(m2)); + EXPECT_EQ(get_camera_metadata_data_count(m), + get_camera_metadata_data_count(m2)); + EXPECT_EQ(get_camera_metadata_entry_capacity(m2), + get_camera_metadata_entry_count(m2)); + EXPECT_EQ(get_camera_metadata_data_capacity(m2), + get_camera_metadata_data_count(m2)); + EXPECT_EQ(buf + buf_size - extra_space, + (uint8_t*)m2 + get_camera_metadata_size(m2) ); + + for (unsigned int i=0; i < get_camera_metadata_entry_count(m); i++) { + uint32_t tag, tag2; + uint8_t type, type2; + uint8_t *data, *data2; + size_t data_count, data_count2; + + int result; + result = get_camera_metadata_entry(m, + i, &tag, &type, (void**)&data, &data_count); + EXPECT_EQ(OK, result); + result = get_camera_metadata_entry(m2, + i, &tag2, &type2, (void**)&data2, &data_count2); + EXPECT_EQ(OK, result); + EXPECT_EQ(tag, tag2); + EXPECT_EQ(type, type2); + EXPECT_EQ(data_count, data_count2); + for (unsigned int j=0; j < data_count; j++) { + EXPECT_EQ(data[j], data2[j]); + } + } + + free(buf); + + free_camera_metadata(m); +} + +TEST(camera_metadata, copy_metadata_nospace) { + camera_metadata_t *m = NULL; + const size_t entry_capacity = 5; + const size_t data_capacity = 50; + + int result; + + m = allocate_camera_metadata(entry_capacity, data_capacity); + + add_test_metadata(m, entry_capacity); + + size_t buf_size = get_camera_metadata_compact_size(m); + EXPECT_LT((size_t)0, buf_size); + + buf_size--; + + uint8_t *buf = (uint8_t*)malloc(buf_size); + EXPECT_NOT_NULL(buf); + + camera_metadata_t *m2 = copy_camera_metadata(buf, buf_size, m); + EXPECT_NULL(m2); + + free(buf); + + free_camera_metadata(m); +} + +TEST(camera_metadata, append_metadata) { + camera_metadata_t *m = NULL; + const size_t entry_capacity = 5; + const size_t data_capacity = 50; + + int result; + + m = allocate_camera_metadata(entry_capacity, data_capacity); + + add_test_metadata(m, entry_capacity); + + camera_metadata_t *m2 = NULL; + + m2 = allocate_camera_metadata(entry_capacity*2, data_capacity*2); + EXPECT_NOT_NULL(m2); + + result = append_camera_metadata(m2, m); + + EXPECT_EQ(OK, result); + + EXPECT_EQ(get_camera_metadata_entry_count(m), get_camera_metadata_entry_count(m2)); + EXPECT_EQ(get_camera_metadata_data_count(m), get_camera_metadata_data_count(m2)); + EXPECT_EQ(entry_capacity*2, get_camera_metadata_entry_capacity(m2)); + EXPECT_EQ(data_capacity*2, get_camera_metadata_data_capacity(m2)); + + for (unsigned int i=0; i < get_camera_metadata_entry_count(m); i++) { + uint32_t tag, tag2; + uint8_t type, type2; + uint8_t *data, *data2; + size_t data_count, data_count2; + + int result; + result = get_camera_metadata_entry(m, + i, &tag, &type, (void**)&data, &data_count); + EXPECT_EQ(OK, result); + result = get_camera_metadata_entry(m2, + i, &tag2, &type2, (void**)&data2, &data_count2); + EXPECT_EQ(OK, result); + EXPECT_EQ(tag, tag2); + EXPECT_EQ(type, type2); + EXPECT_EQ(data_count, data_count2); + for (unsigned int j=0; j < data_count; j++) { + EXPECT_EQ(data[j], data2[j]); + } + } + + result = append_camera_metadata(m2, m); + + EXPECT_EQ(OK, result); + + EXPECT_EQ(get_camera_metadata_entry_count(m)*2, get_camera_metadata_entry_count(m2)); + EXPECT_EQ(get_camera_metadata_data_count(m)*2, get_camera_metadata_data_count(m2)); + EXPECT_EQ(entry_capacity*2, get_camera_metadata_entry_capacity(m2)); + EXPECT_EQ(data_capacity*2, get_camera_metadata_data_capacity(m2)); + + for (unsigned int i=0; i < get_camera_metadata_entry_count(m2); i++) { + uint32_t tag, tag2; + uint8_t type, type2; + uint8_t *data, *data2; + size_t data_count, data_count2; + + int result; + result = get_camera_metadata_entry(m, + i % entry_capacity, &tag, &type, (void**)&data, &data_count); + EXPECT_EQ(OK, result); + result = get_camera_metadata_entry(m2, + i, &tag2, &type2, (void**)&data2, &data_count2); + EXPECT_EQ(OK, result); + EXPECT_EQ(tag, tag2); + EXPECT_EQ(type, type2); + EXPECT_EQ(data_count, data_count2); + for (unsigned int j=0; j < data_count; j++) { + EXPECT_EQ(data[j], data2[j]); + } + } + + free_camera_metadata(m); + free_camera_metadata(m2); +} + +TEST(camera_metadata, append_metadata_nospace) { + camera_metadata_t *m = NULL; + const size_t entry_capacity = 5; + const size_t data_capacity = 50; + + int result; + + m = allocate_camera_metadata(entry_capacity, data_capacity); + + add_test_metadata(m, entry_capacity); + + camera_metadata_t *m2 = NULL; + + m2 = allocate_camera_metadata(entry_capacity-1, data_capacity); + EXPECT_NOT_NULL(m2); + + result = append_camera_metadata(m2, m); + + EXPECT_EQ(ERROR, result); + EXPECT_EQ((size_t)0, get_camera_metadata_entry_count(m2)); + EXPECT_EQ((size_t)0, get_camera_metadata_data_count(m2)); + + free_camera_metadata(m); + free_camera_metadata(m2); +} + +TEST(camera_metadata, append_metadata_onespace) { + camera_metadata_t *m = NULL; + const size_t entry_capacity = 5; + const size_t data_capacity = 50; + const size_t entry_capacity2 = entry_capacity * 2 - 2; + const size_t data_capacity2 = data_capacity * 2; + int result; + + m = allocate_camera_metadata(entry_capacity, data_capacity); + + add_test_metadata(m, entry_capacity); + + camera_metadata_t *m2 = NULL; + + m2 = allocate_camera_metadata(entry_capacity2, data_capacity2); + EXPECT_NOT_NULL(m2); + + result = append_camera_metadata(m2, m); + + EXPECT_EQ(OK, result); + + EXPECT_EQ(get_camera_metadata_entry_count(m), get_camera_metadata_entry_count(m2)); + EXPECT_EQ(get_camera_metadata_data_count(m), get_camera_metadata_data_count(m2)); + EXPECT_EQ(entry_capacity2, get_camera_metadata_entry_capacity(m2)); + EXPECT_EQ(data_capacity2, get_camera_metadata_data_capacity(m2)); + + for (unsigned int i=0; i < get_camera_metadata_entry_count(m); i++) { + uint32_t tag, tag2; + uint8_t type, type2; + uint8_t *data, *data2; + size_t data_count, data_count2; + + int result; + result = get_camera_metadata_entry(m, + i, &tag, &type, (void**)&data, &data_count); + EXPECT_EQ(OK, result); + result = get_camera_metadata_entry(m2, + i, &tag2, &type2, (void**)&data2, &data_count2); + EXPECT_EQ(OK, result); + EXPECT_EQ(tag, tag2); + EXPECT_EQ(type, type2); + EXPECT_EQ(data_count, data_count2); + for (unsigned int j=0; j < data_count; j++) { + EXPECT_EQ(data[j], data2[j]); + } + } + + result = append_camera_metadata(m2, m); + + EXPECT_EQ(ERROR, result); + EXPECT_EQ(entry_capacity, get_camera_metadata_entry_count(m2)); + EXPECT_EQ(get_camera_metadata_data_count(m), + get_camera_metadata_data_count(m2)); + EXPECT_EQ(entry_capacity2, get_camera_metadata_entry_capacity(m2)); + EXPECT_EQ(data_capacity2, get_camera_metadata_data_capacity(m2)); + + for (unsigned int i=0; i < get_camera_metadata_entry_count(m2); i++) { + uint32_t tag, tag2; + uint8_t type, type2; + uint8_t *data, *data2; + size_t data_count, data_count2; + + int result; + result = get_camera_metadata_entry(m, + i % entry_capacity, &tag, &type, (void**)&data, &data_count); + EXPECT_EQ(OK, result); + result = get_camera_metadata_entry(m2, + i, &tag2, &type2, (void**)&data2, &data_count2); + EXPECT_EQ(OK, result); + EXPECT_EQ(tag, tag2); + EXPECT_EQ(type, type2); + EXPECT_EQ(data_count, data_count2); + for (unsigned int j=0; j < data_count; j++) { + EXPECT_EQ(data[j], data2[j]); + } + } + + free_camera_metadata(m); + free_camera_metadata(m2); +} + +TEST(camera_metadata, vendor_tags) { + camera_metadata_t *m = NULL; + const size_t entry_capacity = 5; + const size_t data_capacity = 50; + int result; + + m = allocate_camera_metadata(entry_capacity, data_capacity); + + uint8_t superMode = 5; + result = add_camera_metadata_entry(m, + FAKEVENDOR_SENSOR_SUPERMODE, + &superMode, 1); + EXPECT_EQ(ERROR, result); + + result = add_camera_metadata_entry(m, + ANDROID_REQUEST_METADATA_MODE, + &superMode, 1); + EXPECT_EQ(OK, result); + + EXPECT_NULL(get_camera_metadata_section_name(FAKEVENDOR_SENSOR_SUPERMODE)); + EXPECT_NULL(get_camera_metadata_tag_name(FAKEVENDOR_SENSOR_SUPERMODE)); + EXPECT_EQ(-1, get_camera_metadata_tag_type(FAKEVENDOR_SENSOR_SUPERMODE)); + + set_camera_metadata_vendor_tag_ops(&fakevendor_query_ops); + + result = add_camera_metadata_entry(m, + FAKEVENDOR_SENSOR_SUPERMODE, + &superMode, 1); + EXPECT_EQ(OK, result); + + result = add_camera_metadata_entry(m, + ANDROID_REQUEST_METADATA_MODE, + &superMode, 1); + EXPECT_EQ(OK, result); + + result = add_camera_metadata_entry(m, + FAKEVENDOR_SCALER_END, + &superMode, 1); + EXPECT_EQ(ERROR, result); + + EXPECT_STREQ("com.fakevendor.sensor", + get_camera_metadata_section_name(FAKEVENDOR_SENSOR_SUPERMODE)); + EXPECT_STREQ("superMode", + get_camera_metadata_tag_name(FAKEVENDOR_SENSOR_SUPERMODE)); + EXPECT_EQ(TYPE_BYTE, + get_camera_metadata_tag_type(FAKEVENDOR_SENSOR_SUPERMODE)); + + EXPECT_STREQ("com.fakevendor.scaler", + get_camera_metadata_section_name(FAKEVENDOR_SCALER_END)); + EXPECT_NULL(get_camera_metadata_tag_name(FAKEVENDOR_SCALER_END)); + EXPECT_EQ(-1, get_camera_metadata_tag_type(FAKEVENDOR_SCALER_END)); + + set_camera_metadata_vendor_tag_ops(NULL); + + result = add_camera_metadata_entry(m, + FAKEVENDOR_SENSOR_SUPERMODE, + &superMode, 1); + EXPECT_EQ(ERROR, result); + + result = add_camera_metadata_entry(m, + ANDROID_REQUEST_METADATA_MODE, + &superMode, 1); + EXPECT_EQ(OK, result); + + EXPECT_NULL(get_camera_metadata_section_name(FAKEVENDOR_SENSOR_SUPERMODE)); + EXPECT_NULL(get_camera_metadata_tag_name(FAKEVENDOR_SENSOR_SUPERMODE)); + EXPECT_EQ(-1, get_camera_metadata_tag_type(FAKEVENDOR_SENSOR_SUPERMODE)); + + free_camera_metadata(m); +} + +TEST(camera_metadata, add_all_tags) { + int total_tag_count = 0; + for (int i = 0; i < ANDROID_SECTION_COUNT; i++) { + total_tag_count += camera_metadata_section_bounds[i][1] - + camera_metadata_section_bounds[i][0]; + } + int entry_data_count = 3; + int conservative_data_space = total_tag_count * entry_data_count * 8; + uint8_t data[entry_data_count * 8]; + int32_t *data_int32 = (int32_t *)data; + float *data_float = (float *)data; + int64_t *data_int64 = (int64_t *)data; + double *data_double = (double *)data; + camera_metadata_rational_t *data_rational = (camera_metadata_rational_t *)data; + + camera_metadata_t *m = allocate_camera_metadata(total_tag_count, conservative_data_space); + + ASSERT_NE((void*)NULL, (void*)m); + + int result; + + int counter = 0; + for (int i = 0; i < ANDROID_SECTION_COUNT; i++) { + for (uint32_t tag = camera_metadata_section_bounds[i][0]; + tag < camera_metadata_section_bounds[i][1]; + tag++, counter++) { + int type = get_camera_metadata_tag_type(tag); + ASSERT_NE(-1, type); + + switch (type) { + case TYPE_BYTE: + data[0] = tag & 0xFF; + data[1] = (tag >> 8) & 0xFF; + data[2] = (tag >> 16) & 0xFF; + break; + case TYPE_INT32: + data_int32[0] = tag; + data_int32[1] = i; + data_int32[2] = counter; + break; + case TYPE_FLOAT: + data_float[0] = tag; + data_float[1] = i; + data_float[2] = counter / (float)total_tag_count; + break; + case TYPE_INT64: + data_int64[0] = (int64_t)tag | ( (int64_t)tag << 32); + data_int64[1] = i; + data_int64[2] = counter; + break; + case TYPE_DOUBLE: + data_double[0] = tag; + data_double[1] = i; + data_double[2] = counter / (double)total_tag_count; + break; + case TYPE_RATIONAL: + data_rational[0].numerator = tag; + data_rational[0].denominator = 1; + data_rational[1].numerator = i; + data_rational[1].denominator = 1; + data_rational[2].numerator = counter; + data_rational[2].denominator = total_tag_count; + break; + default: + FAIL() << "Unknown type field encountered:" << type; + break; + } + result = add_camera_metadata_entry(m, + tag, + data, + entry_data_count); + ASSERT_EQ(OK, result); + + } + } + + dump_camera_metadata(m, 2); + + free_camera_metadata(m); +} diff --git a/camera/tests/camera_metadata_tests_fake_vendor.h b/camera/tests/camera_metadata_tests_fake_vendor.h new file mode 100644 index 00000000..8522fa66 --- /dev/null +++ b/camera/tests/camera_metadata_tests_fake_vendor.h @@ -0,0 +1,139 @@ +/* + * 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. + */ + +/** + * Fake vendor extensions for testing + */ + +#ifndef TESTING_CAMERA_METADATA_FAKEVENDOR_H +#define TESTING_CAMERA_METADATA_FAKEVENDOR_H + +enum vendor_extension_section { + FAKEVENDOR_SENSOR = VENDOR_SECTION, + FAKEVENDOR_SENSOR_INFO, + FAKEVENDOR_COLORCORRECTION, + FAKEVENDOR_SCALER, + FAKEVENDOR_SECTION_END +}; + +const int FAKEVENDOR_SECTION_COUNT = FAKEVENDOR_SECTION_END - VENDOR_SECTION; + +enum vendor_extension_section_ranges { + FAKEVENDOR_SENSOR_START = FAKEVENDOR_SENSOR << 16, + FAKEVENDOR_SENSOR_I_START = FAKEVENDOR_SENSOR_INFO << 16, + FAKEVENDOR_COLORCORRECTION_START = FAKEVENDOR_COLORCORRECTION << 16, + FAKEVENDOR_SCALER_START = FAKEVENDOR_SCALER << 16 +}; + +enum vendor_extension_tags { + FAKEVENDOR_SENSOR_SUPERMODE = FAKEVENDOR_SENSOR_START, + FAKEVENDOR_SENSOR_DOUBLE_EXPOSURE, + FAKEVENDOR_SENSOR_END, + + FAKEVENDOR_SENSOR_AVAILABLE_SUPERMODES = FAKEVENDOR_SENSOR_I_START, + FAKEVENDOR_SENSOR_I_END, + + FAKEVENDOR_COLORCORRECTION_3DLUT_MODE = FAKEVENDOR_COLORCORRECTION_START, + FAKEVENDOR_COLORCORRECTION_3DLUT_TABLES, + FAKEVENDOR_COLORCORRECTION_END, + + FAKEVENDOR_SCALER_DOWNSCALE_MODE = FAKEVENDOR_SCALER_START, + FAKEVENDOR_SCALER_DOWNSCALE_COEFF, + FAKEVENDOR_SCALER_END +}; + +typedef struct vendor_tag_info { + const char *tag_name; + uint8_t tag_type; +} vendor_tag_info_t; + +const char *fakevendor_section_names[FAKEVENDOR_SECTION_COUNT] = { + "com.fakevendor.sensor", + "com.fakevendor.sensor.info", + "com.fakevendor.colorCorrection", + "com.fakevendor.scaler" +}; + +unsigned int fakevendor_section_bounds[FAKEVENDOR_SECTION_COUNT][2] = { + { FAKEVENDOR_SENSOR_START, FAKEVENDOR_SENSOR_END }, + { FAKEVENDOR_SENSOR_I_START, FAKEVENDOR_SENSOR_I_END }, + { FAKEVENDOR_COLORCORRECTION_START, FAKEVENDOR_COLORCORRECTION_END }, + { FAKEVENDOR_SCALER_START, FAKEVENDOR_SCALER_END} +}; + +vendor_tag_info_t fakevendor_sensor[FAKEVENDOR_SENSOR_END - + FAKEVENDOR_SENSOR_START] = { + { "superMode", TYPE_BYTE }, + { "doubleExposure", TYPE_INT64 } +}; + +vendor_tag_info_t fakevendor_sensor_info[FAKEVENDOR_SENSOR_I_END - + FAKEVENDOR_SENSOR_I_START] = { + { "availableSuperModes", TYPE_BYTE } +}; + +vendor_tag_info_t fakevendor_color_correction[FAKEVENDOR_COLORCORRECTION_END - + FAKEVENDOR_COLORCORRECTION_START] = { + { "3dLutMode", TYPE_BYTE }, + { "3dLutTables", TYPE_FLOAT } +}; + +vendor_tag_info_t fakevendor_scaler[FAKEVENDOR_SCALER_END - + FAKEVENDOR_SCALER_START] = { + { "downscaleMode", TYPE_BYTE }, + { "downscaleCoefficients", TYPE_FLOAT } +}; + +vendor_tag_info_t *fakevendor_tag_info[FAKEVENDOR_SECTION_COUNT] = { + fakevendor_sensor, + fakevendor_sensor_info, + fakevendor_color_correction, + fakevendor_scaler +}; + +const char *get_fakevendor_section_name(uint32_t tag) { + int tag_section = (tag >> 16) - VENDOR_SECTION; + if (tag_section < 0 || + tag_section >= FAKEVENDOR_SECTION_COUNT) return NULL; + + return fakevendor_section_names[tag_section]; +} + +const char *get_fakevendor_tag_name(uint32_t tag) { + int tag_section = (tag >> 16) - VENDOR_SECTION; + if (tag_section < 0 + || tag_section >= FAKEVENDOR_SECTION_COUNT + || tag >= fakevendor_section_bounds[tag_section][1]) return NULL; + int tag_index = tag & 0xFFFF; + return fakevendor_tag_info[tag_section][tag_index].tag_name; +} + +int get_fakevendor_tag_type(uint32_t tag) { + int tag_section = (tag >> 16) - VENDOR_SECTION; + if (tag_section < 0 + || tag_section >= FAKEVENDOR_SECTION_COUNT + || tag >= fakevendor_section_bounds[tag_section][1]) return -1; + int tag_index = tag & 0xFFFF; + return fakevendor_tag_info[tag_section][tag_index].tag_type; +} + +static const vendor_tag_query_ops_t fakevendor_query_ops = { + get_fakevendor_section_name, + get_fakevendor_tag_name, + get_fakevendor_tag_type +}; + +#endif diff --git a/wilhelm/doc/Doxyfile b/wilhelm/doc/Doxyfile deleted file mode 100644 index 7f6ade73..00000000 --- a/wilhelm/doc/Doxyfile +++ /dev/null @@ -1,1630 +0,0 @@ -# Doxyfile 1.7.1 - -# This file describes the settings to be used by the documentation system -# doxygen (www.doxygen.org) for a project -# -# All text after a hash (#) is considered a comment and will be ignored -# The format is: -# TAG = value [value, ...] -# For lists items can also be appended using: -# TAG += value [value, ...] -# Values that contain spaces should be placed between quotes (" ") - -#--------------------------------------------------------------------------- -# Project related configuration options -#--------------------------------------------------------------------------- - -# This tag specifies the encoding used for all characters in the config file -# that follow. The default is UTF-8 which is also the encoding used for all -# text before the first occurrence of this tag. Doxygen uses libiconv (or the -# iconv built into libc) for the transcoding. See -# http://www.gnu.org/software/libiconv for the list of possible encodings. - -DOXYFILE_ENCODING = UTF-8 - -# The PROJECT_NAME tag is a single word (or a sequence of words surrounded -# by quotes) that should identify the project. - -PROJECT_NAME = Wilhelm - -# The PROJECT_NUMBER tag can be used to enter a project or revision number. -# This could be handy for archiving the generated documentation or -# if some version control system is used. - -PROJECT_NUMBER = 0.1 - -# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) -# base path where the generated documentation will be put. -# If a relative path is entered, it will be relative to the location -# where doxygen was started. If left blank the current directory will be used. - -OUTPUT_DIRECTORY = - -# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create -# 4096 sub-directories (in 2 levels) under the output directory of each output -# format and will distribute the generated files over these directories. -# Enabling this option can be useful when feeding doxygen a huge amount of -# source files, where putting all generated files in the same directory would -# otherwise cause performance problems for the file system. - -CREATE_SUBDIRS = NO - -# The OUTPUT_LANGUAGE tag is used to specify the language in which all -# documentation generated by doxygen is written. Doxygen will use this -# information to generate all constant output in the proper language. -# The default language is English, other supported languages are: -# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, -# Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German, -# Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English -# messages), Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, -# Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrilic, Slovak, -# Slovene, Spanish, Swedish, Ukrainian, and Vietnamese. - -OUTPUT_LANGUAGE = English - -# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will -# include brief member descriptions after the members that are listed in -# the file and class documentation (similar to JavaDoc). -# Set to NO to disable this. - -BRIEF_MEMBER_DESC = YES - -# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend -# the brief description of a member or function before the detailed description. -# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the -# brief descriptions will be completely suppressed. - -REPEAT_BRIEF = YES - -# This tag implements a quasi-intelligent brief description abbreviator -# that is used to form the text in various listings. Each string -# in this list, if found as the leading text of the brief description, will be -# stripped from the text and the result after processing the whole list, is -# used as the annotated text. Otherwise, the brief description is used as-is. -# If left blank, the following values are used ("$name" is automatically -# replaced with the name of the entity): "The $name class" "The $name widget" -# "The $name file" "is" "provides" "specifies" "contains" -# "represents" "a" "an" "the" - -ABBREVIATE_BRIEF = - -# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then -# Doxygen will generate a detailed section even if there is only a brief -# description. - -ALWAYS_DETAILED_SEC = NO - -# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all -# inherited members of a class in the documentation of that class as if those -# members were ordinary class members. Constructors, destructors and assignment -# operators of the base classes will not be shown. - -INLINE_INHERITED_MEMB = NO - -# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full -# path before files name in the file list and in the header files. If set -# to NO the shortest path that makes the file name unique will be used. - -FULL_PATH_NAMES = NO - -# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag -# can be used to strip a user-defined part of the path. Stripping is -# only done if one of the specified strings matches the left-hand part of -# the path. The tag can be used to show relative paths in the file list. -# If left blank the directory from which doxygen is run is used as the -# path to strip. - -STRIP_FROM_PATH = - -# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of -# the path mentioned in the documentation of a class, which tells -# the reader which header file to include in order to use a class. -# If left blank only the name of the header file containing the class -# definition is used. Otherwise one should specify the include paths that -# are normally passed to the compiler using the -I flag. - -STRIP_FROM_INC_PATH = - -# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter -# (but less readable) file names. This can be useful is your file systems -# doesn't support long names like on DOS, Mac, or CD-ROM. - -SHORT_NAMES = NO - -# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen -# will interpret the first line (until the first dot) of a JavaDoc-style -# comment as the brief description. If set to NO, the JavaDoc -# comments will behave just like regular Qt-style comments -# (thus requiring an explicit @brief command for a brief description.) - -JAVADOC_AUTOBRIEF = NO - -# If the QT_AUTOBRIEF tag is set to YES then Doxygen will -# interpret the first line (until the first dot) of a Qt-style -# comment as the brief description. If set to NO, the comments -# will behave just like regular Qt-style comments (thus requiring -# an explicit \brief command for a brief description.) - -QT_AUTOBRIEF = NO - -# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen -# treat a multi-line C++ special comment block (i.e. a block of //! or /// -# comments) as a brief description. This used to be the default behaviour. -# The new default is to treat a multi-line C++ comment block as a detailed -# description. Set this tag to YES if you prefer the old behaviour instead. - -MULTILINE_CPP_IS_BRIEF = NO - -# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented -# member inherits the documentation from any documented member that it -# re-implements. - -INHERIT_DOCS = YES - -# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce -# a new page for each member. If set to NO, the documentation of a member will -# be part of the file/class/namespace that contains it. - -SEPARATE_MEMBER_PAGES = NO - -# The TAB_SIZE tag can be used to set the number of spaces in a tab. -# Doxygen uses this value to replace tabs by spaces in code fragments. - -TAB_SIZE = 8 - -# This tag can be used to specify a number of aliases that acts -# as commands in the documentation. An alias has the form "name=value". -# For example adding "sideeffect=\par Side Effects:\n" will allow you to -# put the command \sideeffect (or @sideeffect) in the documentation, which -# will result in a user-defined paragraph with heading "Side Effects:". -# You can put \n's in the value part of an alias to insert newlines. - -ALIASES = - -# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C -# sources only. Doxygen will then generate output that is more tailored for C. -# For instance, some of the names that are used will be different. The list -# of all members will be omitted, etc. - -OPTIMIZE_OUTPUT_FOR_C = NO - -# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java -# sources only. Doxygen will then generate output that is more tailored for -# Java. For instance, namespaces will be presented as packages, qualified -# scopes will look different, etc. - -OPTIMIZE_OUTPUT_JAVA = NO - -# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran -# sources only. Doxygen will then generate output that is more tailored for -# Fortran. - -OPTIMIZE_FOR_FORTRAN = NO - -# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL -# sources. Doxygen will then generate output that is tailored for -# VHDL. - -OPTIMIZE_OUTPUT_VHDL = NO - -# Doxygen selects the parser to use depending on the extension of the files it -# parses. With this tag you can assign which parser to use for a given extension. -# Doxygen has a built-in mapping, but you can override or extend it using this -# tag. The format is ext=language, where ext is a file extension, and language -# is one of the parsers supported by doxygen: IDL, Java, Javascript, CSharp, C, -# C++, D, PHP, Objective-C, Python, Fortran, VHDL, C, C++. For instance to make -# doxygen treat .inc files as Fortran files (default is PHP), and .f files as C -# (default is Fortran), use: inc=Fortran f=C. Note that for custom extensions -# you also need to set FILE_PATTERNS otherwise the files are not read by doxygen. - -EXTENSION_MAPPING = - -# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want -# to include (a tag file for) the STL sources as input, then you should -# set this tag to YES in order to let doxygen match functions declarations and -# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. -# func(std::string) {}). This also make the inheritance and collaboration -# diagrams that involve STL classes more complete and accurate. - -BUILTIN_STL_SUPPORT = NO - -# If you use Microsoft's C++/CLI language, you should set this option to YES to -# enable parsing support. - -CPP_CLI_SUPPORT = NO - -# Set the SIP_SUPPORT tag to YES if your project consists of sip sources only. -# Doxygen will parse them like normal C++ but will assume all classes use public -# instead of private inheritance when no explicit protection keyword is present. - -SIP_SUPPORT = NO - -# For Microsoft's IDL there are propget and propput attributes to indicate getter -# and setter methods for a property. Setting this option to YES (the default) -# will make doxygen to replace the get and set methods by a property in the -# documentation. This will only work if the methods are indeed getting or -# setting a simple type. If this is not the case, or you want to show the -# methods anyway, you should set this option to NO. - -IDL_PROPERTY_SUPPORT = YES - -# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC -# tag is set to YES, then doxygen will reuse the documentation of the first -# member in the group (if any) for the other members of the group. By default -# all members of a group must be documented explicitly. - -DISTRIBUTE_GROUP_DOC = NO - -# Set the SUBGROUPING tag to YES (the default) to allow class member groups of -# the same type (for instance a group of public functions) to be put as a -# subgroup of that type (e.g. under the Public Functions section). Set it to -# NO to prevent subgrouping. Alternatively, this can be done per class using -# the \nosubgrouping command. - -SUBGROUPING = YES - -# When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum -# is documented as struct, union, or enum with the name of the typedef. So -# typedef struct TypeS {} TypeT, will appear in the documentation as a struct -# with name TypeT. When disabled the typedef will appear as a member of a file, -# namespace, or class. And the struct will be named TypeS. This can typically -# be useful for C code in case the coding convention dictates that all compound -# types are typedef'ed and only the typedef is referenced, never the tag name. - -TYPEDEF_HIDES_STRUCT = NO - -# The SYMBOL_CACHE_SIZE determines the size of the internal cache use to -# determine which symbols to keep in memory and which to flush to disk. -# When the cache is full, less often used symbols will be written to disk. -# For small to medium size projects (<1000 input files) the default value is -# probably good enough. For larger projects a too small cache size can cause -# doxygen to be busy swapping symbols to and from disk most of the time -# causing a significant performance penality. -# If the system has enough physical memory increasing the cache will improve the -# performance by keeping more symbols in memory. Note that the value works on -# a logarithmic scale so increasing the size by one will rougly double the -# memory usage. The cache size is given by this formula: -# 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0, -# corresponding to a cache size of 2^16 = 65536 symbols - -SYMBOL_CACHE_SIZE = 0 - -#--------------------------------------------------------------------------- -# Build related configuration options -#--------------------------------------------------------------------------- - -# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in -# documentation are documented, even if no documentation was available. -# Private class members and static file members will be hidden unless -# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES - -EXTRACT_ALL = YES - -# If the EXTRACT_PRIVATE tag is set to YES all private members of a class -# will be included in the documentation. - -EXTRACT_PRIVATE = YES - -# If the EXTRACT_STATIC tag is set to YES all static members of a file -# will be included in the documentation. - -EXTRACT_STATIC = YES - -# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) -# defined locally in source files will be included in the documentation. -# If set to NO only classes defined in header files are included. - -EXTRACT_LOCAL_CLASSES = YES - -# This flag is only useful for Objective-C code. When set to YES local -# methods, which are defined in the implementation section but not in -# the interface are included in the documentation. -# If set to NO (the default) only methods in the interface are included. - -EXTRACT_LOCAL_METHODS = NO - -# If this flag is set to YES, the members of anonymous namespaces will be -# extracted and appear in the documentation as a namespace called -# 'anonymous_namespace{file}', where file will be replaced with the base -# name of the file that contains the anonymous namespace. By default -# anonymous namespace are hidden. - -EXTRACT_ANON_NSPACES = NO - -# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all -# undocumented members of documented classes, files or namespaces. -# If set to NO (the default) these members will be included in the -# various overviews, but no documentation section is generated. -# This option has no effect if EXTRACT_ALL is enabled. - -HIDE_UNDOC_MEMBERS = NO - -# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all -# undocumented classes that are normally visible in the class hierarchy. -# If set to NO (the default) these classes will be included in the various -# overviews. This option has no effect if EXTRACT_ALL is enabled. - -HIDE_UNDOC_CLASSES = NO - -# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all -# friend (class|struct|union) declarations. -# If set to NO (the default) these declarations will be included in the -# documentation. - -HIDE_FRIEND_COMPOUNDS = NO - -# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any -# documentation blocks found inside the body of a function. -# If set to NO (the default) these blocks will be appended to the -# function's detailed documentation block. - -HIDE_IN_BODY_DOCS = NO - -# The INTERNAL_DOCS tag determines if documentation -# that is typed after a \internal command is included. If the tag is set -# to NO (the default) then the documentation will be excluded. -# Set it to YES to include the internal documentation. - -INTERNAL_DOCS = NO - -# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate -# file names in lower-case letters. If set to YES upper-case letters are also -# allowed. This is useful if you have classes or files whose names only differ -# in case and if your file system supports case sensitive file names. Windows -# and Mac users are advised to set this option to NO. - -CASE_SENSE_NAMES = NO - -# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen -# will show members with their full class and namespace scopes in the -# documentation. If set to YES the scope will be hidden. - -HIDE_SCOPE_NAMES = NO - -# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen -# will put a list of the files that are included by a file in the documentation -# of that file. - -SHOW_INCLUDE_FILES = YES - -# If the FORCE_LOCAL_INCLUDES tag is set to YES then Doxygen -# will list include files with double quotes in the documentation -# rather than with sharp brackets. - -FORCE_LOCAL_INCLUDES = NO - -# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] -# is inserted in the documentation for inline members. - -INLINE_INFO = YES - -# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen -# will sort the (detailed) documentation of file and class members -# alphabetically by member name. If set to NO the members will appear in -# declaration order. - -SORT_MEMBER_DOCS = NO - -# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the -# brief documentation of file, namespace and class members alphabetically -# by member name. If set to NO (the default) the members will appear in -# declaration order. - -SORT_BRIEF_DOCS = NO - -# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen -# will sort the (brief and detailed) documentation of class members so that -# constructors and destructors are listed first. If set to NO (the default) -# the constructors will appear in the respective orders defined by -# SORT_MEMBER_DOCS and SORT_BRIEF_DOCS. -# This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO -# and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO. - -SORT_MEMBERS_CTORS_1ST = NO - -# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the -# hierarchy of group names into alphabetical order. If set to NO (the default) -# the group names will appear in their defined order. - -SORT_GROUP_NAMES = NO - -# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be -# sorted by fully-qualified names, including namespaces. If set to -# NO (the default), the class list will be sorted only by class name, -# not including the namespace part. -# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. -# Note: This option applies only to the class list, not to the -# alphabetical list. - -SORT_BY_SCOPE_NAME = NO - -# The GENERATE_TODOLIST tag can be used to enable (YES) or -# disable (NO) the todo list. This list is created by putting \todo -# commands in the documentation. - -GENERATE_TODOLIST = YES - -# The GENERATE_TESTLIST tag can be used to enable (YES) or -# disable (NO) the test list. This list is created by putting \test -# commands in the documentation. - -GENERATE_TESTLIST = YES - -# The GENERATE_BUGLIST tag can be used to enable (YES) or -# disable (NO) the bug list. This list is created by putting \bug -# commands in the documentation. - -GENERATE_BUGLIST = YES - -# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or -# disable (NO) the deprecated list. This list is created by putting -# \deprecated commands in the documentation. - -GENERATE_DEPRECATEDLIST= YES - -# The ENABLED_SECTIONS tag can be used to enable conditional -# documentation sections, marked by \if sectionname ... \endif. - -ENABLED_SECTIONS = - -# The MAX_INITIALIZER_LINES tag determines the maximum number of lines -# the initial value of a variable or define consists of for it to appear in -# the documentation. If the initializer consists of more lines than specified -# here it will be hidden. Use a value of 0 to hide initializers completely. -# The appearance of the initializer of individual variables and defines in the -# documentation can be controlled using \showinitializer or \hideinitializer -# command in the documentation regardless of this setting. - -MAX_INITIALIZER_LINES = 30 - -# Set the SHOW_USED_FILES tag to NO to disable the list of files generated -# at the bottom of the documentation of classes and structs. If set to YES the -# list will mention the files that were used to generate the documentation. - -SHOW_USED_FILES = YES - -# If the sources in your project are distributed over multiple directories -# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy -# in the documentation. The default is NO. - -SHOW_DIRECTORIES = NO - -# Set the SHOW_FILES tag to NO to disable the generation of the Files page. -# This will remove the Files entry from the Quick Index and from the -# Folder Tree View (if specified). The default is YES. - -SHOW_FILES = YES - -# Set the SHOW_NAMESPACES tag to NO to disable the generation of the -# Namespaces page. -# This will remove the Namespaces entry from the Quick Index -# and from the Folder Tree View (if specified). The default is YES. - -SHOW_NAMESPACES = YES - -# The FILE_VERSION_FILTER tag can be used to specify a program or script that -# doxygen should invoke to get the current version for each file (typically from -# the version control system). Doxygen will invoke the program by executing (via -# popen()) the command <command> <input-file>, where <command> is the value of -# the FILE_VERSION_FILTER tag, and <input-file> is the name of an input file -# provided by doxygen. Whatever the program writes to standard output -# is used as the file version. See the manual for examples. - -FILE_VERSION_FILTER = - -# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed -# by doxygen. The layout file controls the global structure of the generated -# output files in an output format independent way. The create the layout file -# that represents doxygen's defaults, run doxygen with the -l option. -# You can optionally specify a file name after the option, if omitted -# DoxygenLayout.xml will be used as the name of the layout file. - -LAYOUT_FILE = - -#--------------------------------------------------------------------------- -# configuration options related to warning and progress messages -#--------------------------------------------------------------------------- - -# The QUIET tag can be used to turn on/off the messages that are generated -# by doxygen. Possible values are YES and NO. If left blank NO is used. - -QUIET = YES - -# The WARNINGS tag can be used to turn on/off the warning messages that are -# generated by doxygen. Possible values are YES and NO. If left blank -# NO is used. - -WARNINGS = YES - -# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings -# for undocumented members. If EXTRACT_ALL is set to YES then this flag will -# automatically be disabled. - -WARN_IF_UNDOCUMENTED = YES - -# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for -# potential errors in the documentation, such as not documenting some -# parameters in a documented function, or documenting parameters that -# don't exist or using markup commands wrongly. - -WARN_IF_DOC_ERROR = YES - -# This WARN_NO_PARAMDOC option can be abled to get warnings for -# functions that are documented, but have no documentation for their parameters -# or return value. If set to NO (the default) doxygen will only warn about -# wrong or incomplete parameter documentation, but not about the absence of -# documentation. - -WARN_NO_PARAMDOC = NO - -# The WARN_FORMAT tag determines the format of the warning messages that -# doxygen can produce. The string should contain the $file, $line, and $text -# tags, which will be replaced by the file and line number from which the -# warning originated and the warning text. Optionally the format may contain -# $version, which will be replaced by the version of the file (if it could -# be obtained via FILE_VERSION_FILTER) - -WARN_FORMAT = "$file:$line: $text" - -# The WARN_LOGFILE tag can be used to specify a file to which warning -# and error messages should be written. If left blank the output is written -# to stderr. - -WARN_LOGFILE = - -#--------------------------------------------------------------------------- -# configuration options related to the input files -#--------------------------------------------------------------------------- - -# The INPUT tag can be used to specify the files and/or directories that contain -# documented source files. You may enter file names like "myfile.cpp" or -# directories like "/usr/src/myproject". Separate the files or directories -# with spaces. - -INPUT = ../src - -# This tag can be used to specify the character encoding of the source files -# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is -# also the default input encoding. Doxygen uses libiconv (or the iconv built -# into libc) for the transcoding. See http://www.gnu.org/software/libiconv for -# the list of possible encodings. - -INPUT_ENCODING = UTF-8 - -# If the value of the INPUT tag contains directories, you can use the -# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp -# and *.h) to filter out the source-files in the directories. If left -# blank the following patterns are tested: -# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx -# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py *.f90 - -FILE_PATTERNS = - -# The RECURSIVE tag can be used to turn specify whether or not subdirectories -# should be searched for input files as well. Possible values are YES and NO. -# If left blank NO is used. - -RECURSIVE = NO - -# The EXCLUDE tag can be used to specify files and/or directories that should -# excluded from the INPUT source files. This way you can easily exclude a -# subdirectory from a directory tree whose root is specified with the INPUT tag. - -EXCLUDE = - -# The EXCLUDE_SYMLINKS tag can be used select whether or not files or -# directories that are symbolic links (a Unix filesystem feature) are excluded -# from the input. - -EXCLUDE_SYMLINKS = NO - -# If the value of the INPUT tag contains directories, you can use the -# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude -# certain files from those directories. Note that the wildcards are matched -# against the file with absolute path, so to exclude all test directories -# for example use the pattern */test/* - -EXCLUDE_PATTERNS = - -# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names -# (namespaces, classes, functions, etc.) that should be excluded from the -# output. The symbol name can be a fully qualified name, a word, or if the -# wildcard * is used, a substring. Examples: ANamespace, AClass, -# AClass::ANamespace, ANamespace::*Test - -EXCLUDE_SYMBOLS = - -# The EXAMPLE_PATH tag can be used to specify one or more files or -# directories that contain example code fragments that are included (see -# the \include command). - -EXAMPLE_PATH = - -# If the value of the EXAMPLE_PATH tag contains directories, you can use the -# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp -# and *.h) to filter out the source-files in the directories. If left -# blank all files are included. - -EXAMPLE_PATTERNS = - -# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be -# searched for input files to be used with the \include or \dontinclude -# commands irrespective of the value of the RECURSIVE tag. -# Possible values are YES and NO. If left blank NO is used. - -EXAMPLE_RECURSIVE = NO - -# The IMAGE_PATH tag can be used to specify one or more files or -# directories that contain image that are included in the documentation (see -# the \image command). - -IMAGE_PATH = - -# The INPUT_FILTER tag can be used to specify a program that doxygen should -# invoke to filter for each input file. Doxygen will invoke the filter program -# by executing (via popen()) the command <filter> <input-file>, where <filter> -# is the value of the INPUT_FILTER tag, and <input-file> is the name of an -# input file. Doxygen will then use the output that the filter program writes -# to standard output. -# If FILTER_PATTERNS is specified, this tag will be -# ignored. - -INPUT_FILTER = - -# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern -# basis. -# Doxygen will compare the file name with each pattern and apply the -# filter if there is a match. -# The filters are a list of the form: -# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further -# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER -# is applied to all files. - -FILTER_PATTERNS = - -# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using -# INPUT_FILTER) will be used to filter the input files when producing source -# files to browse (i.e. when SOURCE_BROWSER is set to YES). - -FILTER_SOURCE_FILES = NO - -#--------------------------------------------------------------------------- -# configuration options related to source browsing -#--------------------------------------------------------------------------- - -# If the SOURCE_BROWSER tag is set to YES then a list of source files will -# be generated. Documented entities will be cross-referenced with these sources. -# Note: To get rid of all source code in the generated output, make sure also -# VERBATIM_HEADERS is set to NO. - -SOURCE_BROWSER = NO - -# Setting the INLINE_SOURCES tag to YES will include the body -# of functions and classes directly in the documentation. - -INLINE_SOURCES = NO - -# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct -# doxygen to hide any special comment blocks from generated source code -# fragments. Normal C and C++ comments will always remain visible. - -STRIP_CODE_COMMENTS = NO - -# If the REFERENCED_BY_RELATION tag is set to YES -# then for each documented function all documented -# functions referencing it will be listed. - -REFERENCED_BY_RELATION = YES - -# If the REFERENCES_RELATION tag is set to YES -# then for each documented function all documented entities -# called/used by that function will be listed. - -REFERENCES_RELATION = YES - -# If the REFERENCES_LINK_SOURCE tag is set to YES (the default) -# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from -# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will -# link to the source code. -# Otherwise they will link to the documentation. - -REFERENCES_LINK_SOURCE = YES - -# If the USE_HTAGS tag is set to YES then the references to source code -# will point to the HTML generated by the htags(1) tool instead of doxygen -# built-in source browser. The htags tool is part of GNU's global source -# tagging system (see http://www.gnu.org/software/global/global.html). You -# will need version 4.8.6 or higher. - -USE_HTAGS = NO - -# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen -# will generate a verbatim copy of the header file for each class for -# which an include is specified. Set to NO to disable this. - -VERBATIM_HEADERS = YES - -#--------------------------------------------------------------------------- -# configuration options related to the alphabetical class index -#--------------------------------------------------------------------------- - -# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index -# of all compounds will be generated. Enable this if the project -# contains a lot of classes, structs, unions or interfaces. - -ALPHABETICAL_INDEX = YES - -# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then -# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns -# in which this list will be split (can be a number in the range [1..20]) - -COLS_IN_ALPHA_INDEX = 5 - -# In case all classes in a project start with a common prefix, all -# classes will be put under the same header in the alphabetical index. -# The IGNORE_PREFIX tag can be used to specify one or more prefixes that -# should be ignored while generating the index headers. - -IGNORE_PREFIX = - -#--------------------------------------------------------------------------- -# configuration options related to the HTML output -#--------------------------------------------------------------------------- - -# If the GENERATE_HTML tag is set to YES (the default) Doxygen will -# generate HTML output. - -GENERATE_HTML = YES - -# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `html' will be used as the default path. - -HTML_OUTPUT = html - -# The HTML_FILE_EXTENSION tag can be used to specify the file extension for -# each generated HTML page (for example: .htm,.php,.asp). If it is left blank -# doxygen will generate files with .html extension. - -HTML_FILE_EXTENSION = .html - -# The HTML_HEADER tag can be used to specify a personal HTML header for -# each generated HTML page. If it is left blank doxygen will generate a -# standard header. - -HTML_HEADER = - -# The HTML_FOOTER tag can be used to specify a personal HTML footer for -# each generated HTML page. If it is left blank doxygen will generate a -# standard footer. - -HTML_FOOTER = - -# The HTML_STYLESHEET tag can be used to specify a user-defined cascading -# style sheet that is used by each HTML page. It can be used to -# fine-tune the look of the HTML output. If the tag is left blank doxygen -# will generate a default style sheet. Note that doxygen will try to copy -# the style sheet file to the HTML output directory, so don't put your own -# stylesheet in the HTML output directory as well, or it will be erased! - -HTML_STYLESHEET = - -# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. -# Doxygen will adjust the colors in the stylesheet and background images -# according to this color. Hue is specified as an angle on a colorwheel, -# see http://en.wikipedia.org/wiki/Hue for more information. -# For instance the value 0 represents red, 60 is yellow, 120 is green, -# 180 is cyan, 240 is blue, 300 purple, and 360 is red again. -# The allowed range is 0 to 359. - -HTML_COLORSTYLE_HUE = 220 - -# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of -# the colors in the HTML output. For a value of 0 the output will use -# grayscales only. A value of 255 will produce the most vivid colors. - -HTML_COLORSTYLE_SAT = 100 - -# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to -# the luminance component of the colors in the HTML output. Values below -# 100 gradually make the output lighter, whereas values above 100 make -# the output darker. The value divided by 100 is the actual gamma applied, -# so 80 represents a gamma of 0.8, The value 220 represents a gamma of 2.2, -# and 100 does not change the gamma. - -HTML_COLORSTYLE_GAMMA = 80 - -# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML -# page will contain the date and time when the page was generated. Setting -# this to NO can help when comparing the output of multiple runs. - -HTML_TIMESTAMP = YES - -# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, -# files or namespaces will be aligned in HTML using tables. If set to -# NO a bullet list will be used. - -HTML_ALIGN_MEMBERS = YES - -# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML -# documentation will contain sections that can be hidden and shown after the -# page has loaded. For this to work a browser that supports -# JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox -# Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari). - -HTML_DYNAMIC_SECTIONS = NO - -# If the GENERATE_DOCSET tag is set to YES, additional index files -# will be generated that can be used as input for Apple's Xcode 3 -# integrated development environment, introduced with OSX 10.5 (Leopard). -# To create a documentation set, doxygen will generate a Makefile in the -# HTML output directory. Running make will produce the docset in that -# directory and running "make install" will install the docset in -# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find -# it at startup. -# See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html -# for more information. - -GENERATE_DOCSET = NO - -# When GENERATE_DOCSET tag is set to YES, this tag determines the name of the -# feed. A documentation feed provides an umbrella under which multiple -# documentation sets from a single provider (such as a company or product suite) -# can be grouped. - -DOCSET_FEEDNAME = "Doxygen generated docs" - -# When GENERATE_DOCSET tag is set to YES, this tag specifies a string that -# should uniquely identify the documentation set bundle. This should be a -# reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen -# will append .docset to the name. - -DOCSET_BUNDLE_ID = org.doxygen.Project - -# When GENERATE_PUBLISHER_ID tag specifies a string that should uniquely identify -# the documentation publisher. This should be a reverse domain-name style -# string, e.g. com.mycompany.MyDocSet.documentation. - -DOCSET_PUBLISHER_ID = org.doxygen.Publisher - -# The GENERATE_PUBLISHER_NAME tag identifies the documentation publisher. - -DOCSET_PUBLISHER_NAME = Publisher - -# If the GENERATE_HTMLHELP tag is set to YES, additional index files -# will be generated that can be used as input for tools like the -# Microsoft HTML help workshop to generate a compiled HTML help file (.chm) -# of the generated HTML documentation. - -GENERATE_HTMLHELP = NO - -# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can -# be used to specify the file name of the resulting .chm file. You -# can add a path in front of the file if the result should not be -# written to the html output directory. - -CHM_FILE = - -# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can -# be used to specify the location (absolute path including file name) of -# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run -# the HTML help compiler on the generated index.hhp. - -HHC_LOCATION = - -# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag -# controls if a separate .chi index file is generated (YES) or that -# it should be included in the master .chm file (NO). - -GENERATE_CHI = NO - -# If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING -# is used to encode HtmlHelp index (hhk), content (hhc) and project file -# content. - -CHM_INDEX_ENCODING = - -# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag -# controls whether a binary table of contents is generated (YES) or a -# normal table of contents (NO) in the .chm file. - -BINARY_TOC = NO - -# The TOC_EXPAND flag can be set to YES to add extra items for group members -# to the contents of the HTML help documentation and to the tree view. - -TOC_EXPAND = NO - -# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and -# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated -# that can be used as input for Qt's qhelpgenerator to generate a -# Qt Compressed Help (.qch) of the generated HTML documentation. - -GENERATE_QHP = NO - -# If the QHG_LOCATION tag is specified, the QCH_FILE tag can -# be used to specify the file name of the resulting .qch file. -# The path specified is relative to the HTML output folder. - -QCH_FILE = - -# The QHP_NAMESPACE tag specifies the namespace to use when generating -# Qt Help Project output. For more information please see -# http://doc.trolltech.com/qthelpproject.html#namespace - -QHP_NAMESPACE = org.doxygen.Project - -# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating -# Qt Help Project output. For more information please see -# http://doc.trolltech.com/qthelpproject.html#virtual-folders - -QHP_VIRTUAL_FOLDER = doc - -# If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to -# add. For more information please see -# http://doc.trolltech.com/qthelpproject.html#custom-filters - -QHP_CUST_FILTER_NAME = - -# The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the -# custom filter to add. For more information please see -# <a href="http://doc.trolltech.com/qthelpproject.html#custom-filters"> -# Qt Help Project / Custom Filters</a>. - -QHP_CUST_FILTER_ATTRS = - -# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this -# project's -# filter section matches. -# <a href="http://doc.trolltech.com/qthelpproject.html#filter-attributes"> -# Qt Help Project / Filter Attributes</a>. - -QHP_SECT_FILTER_ATTRS = - -# If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can -# be used to specify the location of Qt's qhelpgenerator. -# If non-empty doxygen will try to run qhelpgenerator on the generated -# .qhp file. - -QHG_LOCATION = - -# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files -# will be generated, which together with the HTML files, form an Eclipse help -# plugin. To install this plugin and make it available under the help contents -# menu in Eclipse, the contents of the directory containing the HTML and XML -# files needs to be copied into the plugins directory of eclipse. The name of -# the directory within the plugins directory should be the same as -# the ECLIPSE_DOC_ID value. After copying Eclipse needs to be restarted before -# the help appears. - -GENERATE_ECLIPSEHELP = NO - -# A unique identifier for the eclipse help plugin. When installing the plugin -# the directory name containing the HTML and XML files should also have -# this name. - -ECLIPSE_DOC_ID = org.doxygen.Project - -# The DISABLE_INDEX tag can be used to turn on/off the condensed index at -# top of each HTML page. The value NO (the default) enables the index and -# the value YES disables it. - -DISABLE_INDEX = NO - -# This tag can be used to set the number of enum values (range [1..20]) -# that doxygen will group on one line in the generated HTML documentation. - -ENUM_VALUES_PER_LINE = 4 - -# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index -# structure should be generated to display hierarchical information. -# If the tag value is set to YES, a side panel will be generated -# containing a tree-like index structure (just like the one that -# is generated for HTML Help). For this to work a browser that supports -# JavaScript, DHTML, CSS and frames is required (i.e. any modern browser). -# Windows users are probably better off using the HTML help feature. - -GENERATE_TREEVIEW = NO - -# By enabling USE_INLINE_TREES, doxygen will generate the Groups, Directories, -# and Class Hierarchy pages using a tree view instead of an ordered list. - -USE_INLINE_TREES = NO - -# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be -# used to set the initial width (in pixels) of the frame in which the tree -# is shown. - -TREEVIEW_WIDTH = 250 - -# When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open -# links to external symbols imported via tag files in a separate window. - -EXT_LINKS_IN_WINDOW = NO - -# Use this tag to change the font size of Latex formulas included -# as images in the HTML documentation. The default is 10. Note that -# when you change the font size after a successful doxygen run you need -# to manually remove any form_*.png images from the HTML output directory -# to force them to be regenerated. - -FORMULA_FONTSIZE = 10 - -# Use the FORMULA_TRANPARENT tag to determine whether or not the images -# generated for formulas are transparent PNGs. Transparent PNGs are -# not supported properly for IE 6.0, but are supported on all modern browsers. -# Note that when changing this option you need to delete any form_*.png files -# in the HTML output before the changes have effect. - -FORMULA_TRANSPARENT = YES - -# When the SEARCHENGINE tag is enabled doxygen will generate a search box -# for the HTML output. The underlying search engine uses javascript -# and DHTML and should work on any modern browser. Note that when using -# HTML help (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets -# (GENERATE_DOCSET) there is already a search function so this one should -# typically be disabled. For large projects the javascript based search engine -# can be slow, then enabling SERVER_BASED_SEARCH may provide a better solution. - -SEARCHENGINE = YES - -# When the SERVER_BASED_SEARCH tag is enabled the search engine will be -# implemented using a PHP enabled web server instead of at the web client -# using Javascript. Doxygen will generate the search PHP script and index -# file to put on the web server. The advantage of the server -# based approach is that it scales better to large projects and allows -# full text search. The disadvances is that it is more difficult to setup -# and does not have live searching capabilities. - -SERVER_BASED_SEARCH = NO - -#--------------------------------------------------------------------------- -# configuration options related to the LaTeX output -#--------------------------------------------------------------------------- - -# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will -# generate Latex output. - -GENERATE_LATEX = NO - -# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `latex' will be used as the default path. - -LATEX_OUTPUT = latex - -# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be -# invoked. If left blank `latex' will be used as the default command name. -# Note that when enabling USE_PDFLATEX this option is only used for -# generating bitmaps for formulas in the HTML output, but not in the -# Makefile that is written to the output directory. - -LATEX_CMD_NAME = latex - -# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to -# generate index for LaTeX. If left blank `makeindex' will be used as the -# default command name. - -MAKEINDEX_CMD_NAME = makeindex - -# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact -# LaTeX documents. This may be useful for small projects and may help to -# save some trees in general. - -COMPACT_LATEX = NO - -# The PAPER_TYPE tag can be used to set the paper type that is used -# by the printer. Possible values are: a4, a4wide, letter, legal and -# executive. If left blank a4wide will be used. - -PAPER_TYPE = a4wide - -# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX -# packages that should be included in the LaTeX output. - -EXTRA_PACKAGES = - -# The LATEX_HEADER tag can be used to specify a personal LaTeX header for -# the generated latex document. The header should contain everything until -# the first chapter. If it is left blank doxygen will generate a -# standard header. Notice: only use this tag if you know what you are doing! - -LATEX_HEADER = - -# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated -# is prepared for conversion to pdf (using ps2pdf). The pdf file will -# contain links (just like the HTML output) instead of page references -# This makes the output suitable for online browsing using a pdf viewer. - -PDF_HYPERLINKS = YES - -# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of -# plain latex in the generated Makefile. Set this option to YES to get a -# higher quality PDF documentation. - -USE_PDFLATEX = YES - -# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. -# command to the generated LaTeX files. This will instruct LaTeX to keep -# running if errors occur, instead of asking the user for help. -# This option is also used when generating formulas in HTML. - -LATEX_BATCHMODE = NO - -# If LATEX_HIDE_INDICES is set to YES then doxygen will not -# include the index chapters (such as File Index, Compound Index, etc.) -# in the output. - -LATEX_HIDE_INDICES = NO - -# If LATEX_SOURCE_CODE is set to YES then doxygen will include -# source code with syntax highlighting in the LaTeX output. -# Note that which sources are shown also depends on other settings -# such as SOURCE_BROWSER. - -LATEX_SOURCE_CODE = NO - -#--------------------------------------------------------------------------- -# configuration options related to the RTF output -#--------------------------------------------------------------------------- - -# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output -# The RTF output is optimized for Word 97 and may not look very pretty with -# other RTF readers or editors. - -GENERATE_RTF = NO - -# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `rtf' will be used as the default path. - -RTF_OUTPUT = rtf - -# If the COMPACT_RTF tag is set to YES Doxygen generates more compact -# RTF documents. This may be useful for small projects and may help to -# save some trees in general. - -COMPACT_RTF = NO - -# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated -# will contain hyperlink fields. The RTF file will -# contain links (just like the HTML output) instead of page references. -# This makes the output suitable for online browsing using WORD or other -# programs which support those fields. -# Note: wordpad (write) and others do not support links. - -RTF_HYPERLINKS = NO - -# Load stylesheet definitions from file. Syntax is similar to doxygen's -# config file, i.e. a series of assignments. You only have to provide -# replacements, missing definitions are set to their default value. - -RTF_STYLESHEET_FILE = - -# Set optional variables used in the generation of an rtf document. -# Syntax is similar to doxygen's config file. - -RTF_EXTENSIONS_FILE = - -#--------------------------------------------------------------------------- -# configuration options related to the man page output -#--------------------------------------------------------------------------- - -# If the GENERATE_MAN tag is set to YES (the default) Doxygen will -# generate man pages - -GENERATE_MAN = NO - -# The MAN_OUTPUT tag is used to specify where the man pages will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `man' will be used as the default path. - -MAN_OUTPUT = man - -# The MAN_EXTENSION tag determines the extension that is added to -# the generated man pages (default is the subroutine's section .3) - -MAN_EXTENSION = .3 - -# If the MAN_LINKS tag is set to YES and Doxygen generates man output, -# then it will generate one additional man file for each entity -# documented in the real man page(s). These additional files -# only source the real man page, but without them the man command -# would be unable to find the correct page. The default is NO. - -MAN_LINKS = NO - -#--------------------------------------------------------------------------- -# configuration options related to the XML output -#--------------------------------------------------------------------------- - -# If the GENERATE_XML tag is set to YES Doxygen will -# generate an XML file that captures the structure of -# the code including all documentation. - -GENERATE_XML = NO - -# The XML_OUTPUT tag is used to specify where the XML pages will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `xml' will be used as the default path. - -XML_OUTPUT = xml - -# The XML_SCHEMA tag can be used to specify an XML schema, -# which can be used by a validating XML parser to check the -# syntax of the XML files. - -XML_SCHEMA = - -# The XML_DTD tag can be used to specify an XML DTD, -# which can be used by a validating XML parser to check the -# syntax of the XML files. - -XML_DTD = - -# If the XML_PROGRAMLISTING tag is set to YES Doxygen will -# dump the program listings (including syntax highlighting -# and cross-referencing information) to the XML output. Note that -# enabling this will significantly increase the size of the XML output. - -XML_PROGRAMLISTING = YES - -#--------------------------------------------------------------------------- -# configuration options for the AutoGen Definitions output -#--------------------------------------------------------------------------- - -# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will -# generate an AutoGen Definitions (see autogen.sf.net) file -# that captures the structure of the code including all -# documentation. Note that this feature is still experimental -# and incomplete at the moment. - -GENERATE_AUTOGEN_DEF = NO - -#--------------------------------------------------------------------------- -# configuration options related to the Perl module output -#--------------------------------------------------------------------------- - -# If the GENERATE_PERLMOD tag is set to YES Doxygen will -# generate a Perl module file that captures the structure of -# the code including all documentation. Note that this -# feature is still experimental and incomplete at the -# moment. - -GENERATE_PERLMOD = NO - -# If the PERLMOD_LATEX tag is set to YES Doxygen will generate -# the necessary Makefile rules, Perl scripts and LaTeX code to be able -# to generate PDF and DVI output from the Perl module output. - -PERLMOD_LATEX = NO - -# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be -# nicely formatted so it can be parsed by a human reader. -# This is useful -# if you want to understand what is going on. -# On the other hand, if this -# tag is set to NO the size of the Perl module output will be much smaller -# and Perl will parse it just the same. - -PERLMOD_PRETTY = YES - -# The names of the make variables in the generated doxyrules.make file -# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. -# This is useful so different doxyrules.make files included by the same -# Makefile don't overwrite each other's variables. - -PERLMOD_MAKEVAR_PREFIX = - -#--------------------------------------------------------------------------- -# Configuration options related to the preprocessor -#--------------------------------------------------------------------------- - -# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will -# evaluate all C-preprocessor directives found in the sources and include -# files. - -ENABLE_PREPROCESSING = YES - -# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro -# names in the source code. If set to NO (the default) only conditional -# compilation will be performed. Macro expansion can be done in a controlled -# way by setting EXPAND_ONLY_PREDEF to YES. - -MACRO_EXPANSION = NO - -# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES -# then the macro expansion is limited to the macros specified with the -# PREDEFINED and EXPAND_AS_DEFINED tags. - -EXPAND_ONLY_PREDEF = NO - -# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files -# in the INCLUDE_PATH (see below) will be search if a #include is found. - -SEARCH_INCLUDES = YES - -# The INCLUDE_PATH tag can be used to specify one or more directories that -# contain include files that are not input files but should be processed by -# the preprocessor. - -INCLUDE_PATH = - -# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard -# patterns (like *.h and *.hpp) to filter out the header-files in the -# directories. If left blank, the patterns specified with FILE_PATTERNS will -# be used. - -INCLUDE_FILE_PATTERNS = - -# The PREDEFINED tag can be used to specify one or more macro names that -# are defined before the preprocessor is started (similar to the -D option of -# gcc). The argument of the tag is a list of macros of the form: name -# or name=definition (no spaces). If the definition and the = are -# omitted =1 is assumed. To prevent a macro definition from being -# undefined via #undef or recursively expanded use the := operator -# instead of the = operator. - -PREDEFINED = - -# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then -# this tag can be used to specify a list of macro names that should be expanded. -# The macro definition that is found in the sources will be used. -# Use the PREDEFINED tag if you want to use a different macro definition. - -EXPAND_AS_DEFINED = - -# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then -# doxygen's preprocessor will remove all function-like macros that are alone -# on a line, have an all uppercase name, and do not end with a semicolon. Such -# function macros are typically used for boiler-plate code, and will confuse -# the parser if not removed. - -SKIP_FUNCTION_MACROS = YES - -#--------------------------------------------------------------------------- -# Configuration::additions related to external references -#--------------------------------------------------------------------------- - -# The TAGFILES option can be used to specify one or more tagfiles. -# Optionally an initial location of the external documentation -# can be added for each tagfile. The format of a tag file without -# this location is as follows: -# -# TAGFILES = file1 file2 ... -# Adding location for the tag files is done as follows: -# -# TAGFILES = file1=loc1 "file2 = loc2" ... -# where "loc1" and "loc2" can be relative or absolute paths or -# URLs. If a location is present for each tag, the installdox tool -# does not have to be run to correct the links. -# Note that each tag file must have a unique name -# (where the name does NOT include the path) -# If a tag file is not located in the directory in which doxygen -# is run, you must also specify the path to the tagfile here. - -TAGFILES = - -# When a file name is specified after GENERATE_TAGFILE, doxygen will create -# a tag file that is based on the input files it reads. - -GENERATE_TAGFILE = - -# If the ALLEXTERNALS tag is set to YES all external classes will be listed -# in the class index. If set to NO only the inherited external classes -# will be listed. - -ALLEXTERNALS = NO - -# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed -# in the modules index. If set to NO, only the current project's groups will -# be listed. - -EXTERNAL_GROUPS = YES - -# The PERL_PATH should be the absolute path and name of the perl script -# interpreter (i.e. the result of `which perl'). - -PERL_PATH = /usr/bin/perl - -#--------------------------------------------------------------------------- -# Configuration options related to the dot tool -#--------------------------------------------------------------------------- - -# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will -# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base -# or super classes. Setting the tag to NO turns the diagrams off. Note that -# this option is superseded by the HAVE_DOT option below. This is only a -# fallback. It is recommended to install and use dot, since it yields more -# powerful graphs. - -CLASS_DIAGRAMS = YES - -# You can define message sequence charts within doxygen comments using the \msc -# command. Doxygen will then run the mscgen tool (see -# http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the -# documentation. The MSCGEN_PATH tag allows you to specify the directory where -# the mscgen tool resides. If left empty the tool is assumed to be found in the -# default search path. - -MSCGEN_PATH = - -# If set to YES, the inheritance and collaboration graphs will hide -# inheritance and usage relations if the target is undocumented -# or is not a class. - -HIDE_UNDOC_RELATIONS = YES - -# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is -# available from the path. This tool is part of Graphviz, a graph visualization -# toolkit from AT&T and Lucent Bell Labs. The other options in this section -# have no effect if this option is set to NO (the default) - -HAVE_DOT = NO - -# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is -# allowed to run in parallel. When set to 0 (the default) doxygen will -# base this on the number of processors available in the system. You can set it -# explicitly to a value larger than 0 to get control over the balance -# between CPU load and processing speed. - -DOT_NUM_THREADS = 0 - -# By default doxygen will write a font called FreeSans.ttf to the output -# directory and reference it in all dot files that doxygen generates. This -# font does not include all possible unicode characters however, so when you need -# these (or just want a differently looking font) you can specify the font name -# using DOT_FONTNAME. You need need to make sure dot is able to find the font, -# which can be done by putting it in a standard location or by setting the -# DOTFONTPATH environment variable or by setting DOT_FONTPATH to the directory -# containing the font. - -DOT_FONTNAME = FreeSans.ttf - -# The DOT_FONTSIZE tag can be used to set the size of the font of dot graphs. -# The default size is 10pt. - -DOT_FONTSIZE = 10 - -# By default doxygen will tell dot to use the output directory to look for the -# FreeSans.ttf font (which doxygen will put there itself). If you specify a -# different font using DOT_FONTNAME you can set the path where dot -# can find it using this tag. - -DOT_FONTPATH = - -# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen -# will generate a graph for each documented class showing the direct and -# indirect inheritance relations. Setting this tag to YES will force the -# the CLASS_DIAGRAMS tag to NO. - -CLASS_GRAPH = YES - -# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen -# will generate a graph for each documented class showing the direct and -# indirect implementation dependencies (inheritance, containment, and -# class references variables) of the class with other documented classes. - -COLLABORATION_GRAPH = YES - -# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen -# will generate a graph for groups, showing the direct groups dependencies - -GROUP_GRAPHS = YES - -# If the UML_LOOK tag is set to YES doxygen will generate inheritance and -# collaboration diagrams in a style similar to the OMG's Unified Modeling -# Language. - -UML_LOOK = NO - -# If set to YES, the inheritance and collaboration graphs will show the -# relations between templates and their instances. - -TEMPLATE_RELATIONS = NO - -# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT -# tags are set to YES then doxygen will generate a graph for each documented -# file showing the direct and indirect include dependencies of the file with -# other documented files. - -INCLUDE_GRAPH = YES - -# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and -# HAVE_DOT tags are set to YES then doxygen will generate a graph for each -# documented header file showing the documented files that directly or -# indirectly include this file. - -INCLUDED_BY_GRAPH = YES - -# If the CALL_GRAPH and HAVE_DOT options are set to YES then -# doxygen will generate a call dependency graph for every global function -# or class method. Note that enabling this option will significantly increase -# the time of a run. So in most cases it will be better to enable call graphs -# for selected functions only using the \callgraph command. - -CALL_GRAPH = NO - -# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then -# doxygen will generate a caller dependency graph for every global function -# or class method. Note that enabling this option will significantly increase -# the time of a run. So in most cases it will be better to enable caller -# graphs for selected functions only using the \callergraph command. - -CALLER_GRAPH = NO - -# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen -# will graphical hierarchy of all classes instead of a textual one. - -GRAPHICAL_HIERARCHY = YES - -# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES -# then doxygen will show the dependencies a directory has on other directories -# in a graphical way. The dependency relations are determined by the #include -# relations between the files in the directories. - -DIRECTORY_GRAPH = YES - -# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images -# generated by dot. Possible values are png, jpg, or gif -# If left blank png will be used. - -DOT_IMAGE_FORMAT = png - -# The tag DOT_PATH can be used to specify the path where the dot tool can be -# found. If left blank, it is assumed the dot tool can be found in the path. - -DOT_PATH = - -# The DOTFILE_DIRS tag can be used to specify one or more directories that -# contain dot files that are included in the documentation (see the -# \dotfile command). - -DOTFILE_DIRS = - -# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of -# nodes that will be shown in the graph. If the number of nodes in a graph -# becomes larger than this value, doxygen will truncate the graph, which is -# visualized by representing a node as a red box. Note that doxygen if the -# number of direct children of the root node in a graph is already larger than -# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note -# that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH. - -DOT_GRAPH_MAX_NODES = 50 - -# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the -# graphs generated by dot. A depth value of 3 means that only nodes reachable -# from the root by following a path via at most 3 edges will be shown. Nodes -# that lay further from the root node will be omitted. Note that setting this -# option to 1 or 2 may greatly reduce the computation time needed for large -# code bases. Also note that the size of a graph can be further restricted by -# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction. - -MAX_DOT_GRAPH_DEPTH = 0 - -# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent -# background. This is disabled by default, because dot on Windows does not -# seem to support this out of the box. Warning: Depending on the platform used, -# enabling this option may lead to badly anti-aliased labels on the edges of -# a graph (i.e. they become hard to read). - -DOT_TRANSPARENT = NO - -# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output -# files in one run (i.e. multiple -o and -T options on the command line). This -# makes dot run faster, but since only newer versions of dot (>1.8.10) -# support this, this feature is disabled by default. - -DOT_MULTI_TARGETS = NO - -# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will -# generate a legend page explaining the meaning of the various boxes and -# arrows in the dot generated graphs. - -GENERATE_LEGEND = YES - -# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will -# remove the intermediate dot files that are used to generate -# the various graphs. - -DOT_CLEANUP = YES diff --git a/wilhelm/doc/Makefile b/wilhelm/doc/Makefile deleted file mode 100644 index 1ab6ceef..00000000 --- a/wilhelm/doc/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -html/index.html : Doxyfile clean - doxygen $< - -clean : - $(RM) -r html diff --git a/wilhelm/doc/OpenMAX_AL_1_0_1_Specification.pdf b/wilhelm/doc/OpenMAX_AL_1_0_1_Specification.pdf Binary files differdeleted file mode 100644 index a3380fd7..00000000 --- a/wilhelm/doc/OpenMAX_AL_1_0_1_Specification.pdf +++ /dev/null diff --git a/wilhelm/doc/OpenSL_ES_Specification_1.0.1.pdf b/wilhelm/doc/OpenSL_ES_Specification_1.0.1.pdf Binary files differdeleted file mode 100644 index fe6b2663..00000000 --- a/wilhelm/doc/OpenSL_ES_Specification_1.0.1.pdf +++ /dev/null diff --git a/wilhelm/doc/README.txt b/wilhelm/doc/README.txt deleted file mode 100644 index 7ed9498e..00000000 --- a/wilhelm/doc/README.txt +++ /dev/null @@ -1,2 +0,0 @@ -When building applications using the OpenSL-ES API you should compile and link the OpenSLES_IID.c file into your project. This file contains unique interface IDs for all OpenSL-ES API interfaces. These IDs have -have been automatically generated. Application developers should not edit these interface IDs.
\ No newline at end of file diff --git a/wilhelm/include/OMXAL/OpenMAXAL.h b/wilhelm/include/OMXAL/OpenMAXAL.h deleted file mode 100644 index d31283c8..00000000 --- a/wilhelm/include/OMXAL/OpenMAXAL.h +++ /dev/null @@ -1,3195 +0,0 @@ -/* - * Copyright (c) 2007-2010 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and/or associated documentation files (the - * "Materials "), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - * - * OpenMAXAL.h - OpenMAX AL version 1.0.1 - * - */ - -/****************************************************************************/ -/* NOTE: This file is a standard OpenMAX AL header file and should not be */ -/* modified in any way. */ -/****************************************************************************/ - -#ifndef _OPENMAXAL_H_ -#define _OPENMAXAL_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "OpenMAXAL_Platform.h" - - - /*****************************************************************/ - /* TYPES */ - /*****************************************************************/ - -/* remap common types to XA types for clarity */ -typedef xa_int8_t XAint8; /* 8 bit signed integer */ -typedef xa_uint8_t XAuint8; /* 8 bit unsigned integer */ -typedef xa_int16_t XAint16; /* 16 bit signed integer */ -typedef xa_uint16_t XAuint16; /* 16 bit unsigned integer */ -typedef xa_int32_t XAint32; /* 32 bit signed integer */ -typedef xa_uint32_t XAuint32; /* 32 bit unsigned integer */ -typedef xa_uint64_t XAuint64; /* 64 bit unsigned integer */ - -typedef XAuint32 XAboolean; -typedef XAuint8 XAchar; -typedef XAint16 XAmillibel; -typedef XAuint32 XAmillisecond; -typedef XAuint32 XAmilliHertz; -typedef XAint32 XAmillimeter; -typedef XAint32 XAmillidegree; -typedef XAint16 XApermille; -typedef XAuint32 XAmicrosecond; -typedef XAuint64 XAtime; -typedef XAuint32 XAresult; - -#define XA_BOOLEAN_FALSE ((XAuint32) 0x00000000) -#define XA_BOOLEAN_TRUE ((XAuint32) 0x00000001) - -#define XA_MILLIBEL_MAX ((XAmillibel) 0x7FFF) -#define XA_MILLIBEL_MIN ((XAmillibel) (-XA_MILLIBEL_MAX-1)) - -#define XA_MILLIHERTZ_MAX ((XAmilliHertz) 0xFFFFFFFF) - -#define XA_MILLIMETER_MAX ((XAmillimeter) 0x7FFFFFFF) - - - - /*****************************************************************/ - /* RESULT CODES */ - /*****************************************************************/ - -#define XA_RESULT_SUCCESS ((XAuint32) 0x00000000) -#define XA_RESULT_PRECONDITIONS_VIOLATED ((XAuint32) 0x00000001) -#define XA_RESULT_PARAMETER_INVALID ((XAuint32) 0x00000002) -#define XA_RESULT_MEMORY_FAILURE ((XAuint32) 0x00000003) -#define XA_RESULT_RESOURCE_ERROR ((XAuint32) 0x00000004) -#define XA_RESULT_RESOURCE_LOST ((XAuint32) 0x00000005) -#define XA_RESULT_IO_ERROR ((XAuint32) 0x00000006) -#define XA_RESULT_BUFFER_INSUFFICIENT ((XAuint32) 0x00000007) -#define XA_RESULT_CONTENT_CORRUPTED ((XAuint32) 0x00000008) -#define XA_RESULT_CONTENT_UNSUPPORTED ((XAuint32) 0x00000009) -#define XA_RESULT_CONTENT_NOT_FOUND ((XAuint32) 0x0000000A) -#define XA_RESULT_PERMISSION_DENIED ((XAuint32) 0x0000000B) -#define XA_RESULT_FEATURE_UNSUPPORTED ((XAuint32) 0x0000000C) -#define XA_RESULT_INTERNAL_ERROR ((XAuint32) 0x0000000D) -#define XA_RESULT_UNKNOWN_ERROR ((XAuint32) 0x0000000E) -#define XA_RESULT_OPERATION_ABORTED ((XAuint32) 0x0000000F) -#define XA_RESULT_CONTROL_LOST ((XAuint32) 0x00000010) - - - - /*****************************************************************/ - /* INTERFACE ID DEFINITION */ - /*****************************************************************/ - -/* Interface ID defined as a UUID */ -typedef const struct XAInterfaceID_ { - XAuint32 time_low; - XAuint16 time_mid; - XAuint16 time_hi_and_version; - XAuint16 clock_seq; - XAuint8 node[6]; -} * XAInterfaceID; - -/* NULL Interface */ -XA_API extern const XAInterfaceID XA_IID_NULL; - - - - /*****************************************************************/ - /* GENERAL INTERFACES, STRUCTS AND DEFINES */ - /*****************************************************************/ - -/* OBJECT */ - -#define XA_PRIORITY_LOWEST ((XAint32) (-0x7FFFFFFF-1)) -#define XA_PRIORITY_VERYLOW ((XAint32) -0x60000000) -#define XA_PRIORITY_LOW ((XAint32) -0x40000000) -#define XA_PRIORITY_BELOWNORMAL ((XAint32) -0x20000000) -#define XA_PRIORITY_NORMAL ((XAint32) 0x00000000) -#define XA_PRIORITY_ABOVENORMAL ((XAint32) 0x20000000) -#define XA_PRIORITY_HIGH ((XAint32) 0x40000000) -#define XA_PRIORITY_VERYHIGH ((XAint32) 0x60000000) -#define XA_PRIORITY_HIGHEST ((XAint32) 0x7FFFFFFF) - -#define XA_OBJECT_EVENT_RUNTIME_ERROR ((XAuint32) 0x00000001) -#define XA_OBJECT_EVENT_ASYNC_TERMINATION ((XAuint32) 0x00000002) -#define XA_OBJECT_EVENT_RESOURCES_LOST ((XAuint32) 0x00000003) -#define XA_OBJECT_EVENT_RESOURCES_AVAILABLE ((XAuint32) 0x00000004) -#define XA_OBJECT_EVENT_ITF_CONTROL_TAKEN ((XAuint32) 0x00000005) -#define XA_OBJECT_EVENT_ITF_CONTROL_RETURNED ((XAuint32) 0x00000006) -#define XA_OBJECT_EVENT_ITF_PARAMETERS_CHANGED ((XAuint32) 0x00000007) - -#define XA_OBJECT_STATE_UNREALIZED ((XAuint32) 0x00000001) -#define XA_OBJECT_STATE_REALIZED ((XAuint32) 0x00000002) -#define XA_OBJECT_STATE_SUSPENDED ((XAuint32) 0x00000003) - - -XA_API extern const XAInterfaceID XA_IID_OBJECT; - -struct XAObjectItf_; -typedef const struct XAObjectItf_ * const * XAObjectItf; - -typedef void (XAAPIENTRY * xaObjectCallback) ( - XAObjectItf caller, - const void * pContext, - XAuint32 event, - XAresult result, - XAuint32 param, - void * pInterface -); - -struct XAObjectItf_ { - XAresult (*Realize) ( - XAObjectItf self, - XAboolean async - ); - XAresult (*Resume) ( - XAObjectItf self, - XAboolean async - ); - XAresult (*GetState) ( - XAObjectItf self, - XAuint32 * pState - ); - XAresult (*GetInterface) ( - XAObjectItf self, - const XAInterfaceID iid, - void * pInterface - ); - XAresult (*RegisterCallback) ( - XAObjectItf self, - xaObjectCallback callback, - void * pContext - ); - void (*AbortAsyncOperation) ( - XAObjectItf self - ); - void (*Destroy) ( - XAObjectItf self - ); - XAresult (*SetPriority) ( - XAObjectItf self, - XAint32 priority, - XAboolean preemptable - ); - XAresult (*GetPriority) ( - XAObjectItf self, - XAint32 * pPriority, - XAboolean * pPreemptable - ); - XAresult (*SetLossOfControlInterfaces) ( - XAObjectItf self, - XAint16 numInterfaces, - XAInterfaceID * pInterfaceIDs, - XAboolean enabled - ); -}; - -/* CONFIG EXTENSION */ - -XA_API extern const XAInterfaceID XA_IID_CONFIGEXTENSION; - -struct XAConfigExtensionsItf_; -typedef const struct XAConfigExtensionsItf_ - * const * XAConfigExtensionsItf; - -struct XAConfigExtensionsItf_ { - XAresult (*SetConfiguration) ( - XAConfigExtensionsItf self, - const XAchar * configKey, - XAuint32 valueSize, - const void * pConfigValue - ); - XAresult (*GetConfiguration) ( - XAConfigExtensionsItf self, - const XAchar * configKey, - XAuint32 * pValueSize, - void * pConfigValue - ); -}; - -/* DYNAMIC INTERFACE MANAGEMENT */ - -#define XA_DYNAMIC_ITF_EVENT_RUNTIME_ERROR ((XAuint32) 0x00000001) -#define XA_DYNAMIC_ITF_EVENT_ASYNC_TERMINATION ((XAuint32) 0x00000002) -#define XA_DYNAMIC_ITF_EVENT_RESOURCES_LOST ((XAuint32) 0x00000003) -#define XA_DYNAMIC_ITF_EVENT_RESOURCES_LOST_PERMANENTLY ((XAuint32) 0x00000004) -#define XA_DYNAMIC_ITF_EVENT_RESOURCES_AVAILABLE ((XAuint32) 0x00000005) - -XA_API extern const XAInterfaceID XA_IID_DYNAMICINTERFACEMANAGEMENT; - -struct XADynamicInterfaceManagementItf_; -typedef const struct XADynamicInterfaceManagementItf_ - * const * XADynamicInterfaceManagementItf; - -typedef void (XAAPIENTRY * xaDynamicInterfaceManagementCallback) ( - XADynamicInterfaceManagementItf caller, - void * pContext, - XAuint32 event, - XAresult result, - const XAInterfaceID iid -); - -struct XADynamicInterfaceManagementItf_ { - XAresult (*AddInterface) ( - XADynamicInterfaceManagementItf self, - const XAInterfaceID iid, - XAboolean aysnc - ); - XAresult (*RemoveInterface) ( - XADynamicInterfaceManagementItf self, - const XAInterfaceID iid - ); - XAresult (*ResumeInterface) ( - XADynamicInterfaceManagementItf self, - const XAInterfaceID iid, - XAboolean aysnc - ); - XAresult (*RegisterCallback) ( - XADynamicInterfaceManagementItf self, - xaDynamicInterfaceManagementCallback callback, - void * pContext - ); -}; - -/* DATA SOURCES/SINKS */ - -#define XA_DATAFORMAT_MIME ((XAuint32) 0x00000001) -#define XA_DATAFORMAT_PCM ((XAuint32) 0x00000002) -#define XA_DATAFORMAT_RAWIMAGE ((XAuint32) 0x00000003) - -#define XA_DATALOCATOR_URI ((XAuint32) 0x00000001) -#define XA_DATALOCATOR_ADDRESS ((XAuint32) 0x00000002) -#define XA_DATALOCATOR_IODEVICE ((XAuint32) 0x00000003) -#define XA_DATALOCATOR_OUTPUTMIX ((XAuint32) 0x00000004) -#define XA_DATALOCATOR_NATIVEDISPLAY ((XAuint32) 0x00000005) -#define XA_DATALOCATOR_RESERVED6 ((XAuint32) 0x00000006) -#define XA_DATALOCATOR_RESERVED7 ((XAuint32) 0x00000007) - -typedef struct XADataSink_ { - void * pLocator; - void * pFormat; -} XADataSink; - -typedef struct XADataSource_ { - void * pLocator; - void * pFormat; -} XADataSource; - -#define XA_CONTAINERTYPE_UNSPECIFIED ((XAuint32) 0x00000001) -#define XA_CONTAINERTYPE_RAW ((XAuint32) 0x00000002) -#define XA_CONTAINERTYPE_ASF ((XAuint32) 0x00000003) -#define XA_CONTAINERTYPE_AVI ((XAuint32) 0x00000004) -#define XA_CONTAINERTYPE_BMP ((XAuint32) 0x00000005) -#define XA_CONTAINERTYPE_JPG ((XAuint32) 0x00000006) -#define XA_CONTAINERTYPE_JPG2000 ((XAuint32) 0x00000007) -#define XA_CONTAINERTYPE_M4A ((XAuint32) 0x00000008) -#define XA_CONTAINERTYPE_MP3 ((XAuint32) 0x00000009) -#define XA_CONTAINERTYPE_MP4 ((XAuint32) 0x0000000A) -#define XA_CONTAINERTYPE_MPEG_ES ((XAuint32) 0x0000000B) -#define XA_CONTAINERTYPE_MPEG_PS ((XAuint32) 0x0000000C) -#define XA_CONTAINERTYPE_MPEG_TS ((XAuint32) 0x0000000D) -#define XA_CONTAINERTYPE_QT ((XAuint32) 0x0000000E) -#define XA_CONTAINERTYPE_WAV ((XAuint32) 0x0000000F) -#define XA_CONTAINERTYPE_XMF_0 ((XAuint32) 0x00000010) -#define XA_CONTAINERTYPE_XMF_1 ((XAuint32) 0x00000011) -#define XA_CONTAINERTYPE_XMF_2 ((XAuint32) 0x00000012) -#define XA_CONTAINERTYPE_XMF_3 ((XAuint32) 0x00000013) -#define XA_CONTAINERTYPE_XMF_GENERIC ((XAuint32) 0x00000014) -#define XA_CONTAINERTYPE_AMR ((XAuint32) 0x00000015) -#define XA_CONTAINERTYPE_AAC ((XAuint32) 0x00000016) -#define XA_CONTAINERTYPE_3GPP ((XAuint32) 0x00000017) -#define XA_CONTAINERTYPE_3GA ((XAuint32) 0x00000018) -#define XA_CONTAINERTYPE_RM ((XAuint32) 0x00000019) -#define XA_CONTAINERTYPE_DMF ((XAuint32) 0x0000001A) -#define XA_CONTAINERTYPE_SMF ((XAuint32) 0x0000001B) -#define XA_CONTAINERTYPE_MOBILE_DLS ((XAuint32) 0x0000001C) -#define XA_CONTAINERTYPE_OGG ((XAuint32) 0x0000001D) - -typedef struct XADataFormat_MIME_ { - XAuint32 formatType; - XAchar * mimeType; - XAuint32 containerType; -} XADataFormat_MIME; - -#define XA_BYTEORDER_BIGENDIAN ((XAuint32) 0x00000001) -#define XA_BYTEORDER_LITTLEENDIAN ((XAuint32) 0x00000002) - -#define XA_SAMPLINGRATE_8 ((XAuint32) 8000000) -#define XA_SAMPLINGRATE_11_025 ((XAuint32) 11025000) -#define XA_SAMPLINGRATE_12 ((XAuint32) 12000000) -#define XA_SAMPLINGRATE_16 ((XAuint32) 16000000) -#define XA_SAMPLINGRATE_22_05 ((XAuint32) 22050000) -#define XA_SAMPLINGRATE_24 ((XAuint32) 24000000) -#define XA_SAMPLINGRATE_32 ((XAuint32) 32000000) -#define XA_SAMPLINGRATE_44_1 ((XAuint32) 44100000) -#define XA_SAMPLINGRATE_48 ((XAuint32) 48000000) -#define XA_SAMPLINGRATE_64 ((XAuint32) 64000000) -#define XA_SAMPLINGRATE_88_2 ((XAuint32) 88200000) -#define XA_SAMPLINGRATE_96 ((XAuint32) 96000000) -#define XA_SAMPLINGRATE_192 ((XAuint32) 192000000) - -#define XA_SPEAKER_FRONT_LEFT ((XAuint32) 0x00000001) -#define XA_SPEAKER_FRONT_RIGHT ((XAuint32) 0x00000002) -#define XA_SPEAKER_FRONT_CENTER ((XAuint32) 0x00000004) -#define XA_SPEAKER_LOW_FREQUENCY ((XAuint32) 0x00000008) -#define XA_SPEAKER_BACK_LEFT ((XAuint32) 0x00000010) -#define XA_SPEAKER_BACK_RIGHT ((XAuint32) 0x00000020) -#define XA_SPEAKER_FRONT_LEFT_OF_CENTER ((XAuint32) 0x00000040) -#define XA_SPEAKER_FRONT_RIGHT_OF_CENTER ((XAuint32) 0x00000080) -#define XA_SPEAKER_BACK_CENTER ((XAuint32) 0x00000100) -#define XA_SPEAKER_SIDE_LEFT ((XAuint32) 0x00000200) -#define XA_SPEAKER_SIDE_RIGHT ((XAuint32) 0x00000400) -#define XA_SPEAKER_TOP_CENTER ((XAuint32) 0x00000800) -#define XA_SPEAKER_TOP_FRONT_LEFT ((XAuint32) 0x00001000) -#define XA_SPEAKER_TOP_FRONT_CENTER ((XAuint32) 0x00002000) -#define XA_SPEAKER_TOP_FRONT_RIGHT ((XAuint32) 0x00004000) -#define XA_SPEAKER_TOP_BACK_LEFT ((XAuint32) 0x00008000) -#define XA_SPEAKER_TOP_BACK_CENTER ((XAuint32) 0x00010000) -#define XA_SPEAKER_TOP_BACK_RIGHT ((XAuint32) 0x00020000) - -#define XA_PCMSAMPLEFORMAT_FIXED_8 ((XAuint16) 0x0008) -#define XA_PCMSAMPLEFORMAT_FIXED_16 ((XAuint16) 0x0010) -#define XA_PCMSAMPLEFORMAT_FIXED_20 ((XAuint16) 0x0014) -#define XA_PCMSAMPLEFORMAT_FIXED_24 ((XAuint16) 0x0018) -#define XA_PCMSAMPLEFORMAT_FIXED_28 ((XAuint16) 0x001C) -#define XA_PCMSAMPLEFORMAT_FIXED_32 ((XAuint16) 0x0020) - -typedef struct XADataFormat_PCM_ { - XAuint32 formatType; - XAuint32 numChannels; - XAuint32 samplesPerSec; - XAuint32 bitsPerSample; - XAuint32 containerSize; - XAuint32 channelMask; - XAuint32 endianness; -} XADataFormat_PCM; - -#define XA_COLORFORMAT_UNUSED ((XAuint32) 0x00000000) -#define XA_COLORFORMAT_MONOCHROME ((XAuint32) 0x00000001) -#define XA_COLORFORMAT_8BITRGB332 ((XAuint32) 0x00000002) -#define XA_COLORFORMAT_12BITRGB444 ((XAuint32) 0x00000003) -#define XA_COLORFORMAT_16BITARGB4444 ((XAuint32) 0x00000004) -#define XA_COLORFORMAT_16BITARGB1555 ((XAuint32) 0x00000005) -#define XA_COLORFORMAT_16BITRGB565 ((XAuint32) 0x00000006) -#define XA_COLORFORMAT_16BITBGR565 ((XAuint32) 0x00000007) -#define XA_COLORFORMAT_18BITRGB666 ((XAuint32) 0x00000008) -#define XA_COLORFORMAT_18BITARGB1665 ((XAuint32) 0x00000009) -#define XA_COLORFORMAT_19BITARGB1666 ((XAuint32) 0x0000000A) -#define XA_COLORFORMAT_24BITRGB888 ((XAuint32) 0x0000000B) -#define XA_COLORFORMAT_24BITBGR888 ((XAuint32) 0x0000000C) -#define XA_COLORFORMAT_24BITARGB1887 ((XAuint32) 0x0000000D) -#define XA_COLORFORMAT_25BITARGB1888 ((XAuint32) 0x0000000E) -#define XA_COLORFORMAT_32BITBGRA8888 ((XAuint32) 0x0000000F) -#define XA_COLORFORMAT_32BITARGB8888 ((XAuint32) 0x00000010) -#define XA_COLORFORMAT_YUV411PLANAR ((XAuint32) 0x00000011) -#define XA_COLORFORMAT_YUV420PLANAR ((XAuint32) 0x00000013) -#define XA_COLORFORMAT_YUV420SEMIPLANAR ((XAuint32) 0x00000015) -#define XA_COLORFORMAT_YUV422PLANAR ((XAuint32) 0x00000016) -#define XA_COLORFORMAT_YUV422SEMIPLANAR ((XAuint32) 0x00000018) -#define XA_COLORFORMAT_YCBYCR ((XAuint32) 0x00000019) -#define XA_COLORFORMAT_YCRYCB ((XAuint32) 0x0000001A) -#define XA_COLORFORMAT_CBYCRY ((XAuint32) 0x0000001B) -#define XA_COLORFORMAT_CRYCBY ((XAuint32) 0x0000001C) -#define XA_COLORFORMAT_YUV444INTERLEAVED ((XAuint32) 0x0000001D) -#define XA_COLORFORMAT_RAWBAYER8BIT ((XAuint32) 0x0000001E) -#define XA_COLORFORMAT_RAWBAYER10BIT ((XAuint32) 0x0000001F) -#define XA_COLORFORMAT_RAWBAYER8BITCOMPRESSED ((XAuint32) 0x00000020) -#define XA_COLORFORMAT_L2 ((XAuint32) 0x00000021) -#define XA_COLORFORMAT_L4 ((XAuint32) 0x00000022) -#define XA_COLORFORMAT_L8 ((XAuint32) 0x00000023) -#define XA_COLORFORMAT_L16 ((XAuint32) 0x00000024) -#define XA_COLORFORMAT_L24 ((XAuint32) 0x00000025) -#define XA_COLORFORMAT_L32 ((XAuint32) 0x00000026) -#define XA_COLORFORMAT_18BITBGR666 ((XAuint32) 0x00000029) -#define XA_COLORFORMAT_24BITARGB6666 ((XAuint32) 0x0000002A) -#define XA_COLORFORMAT_24BITABGR6666 ((XAuint32) 0x0000002B) - -typedef struct XADataFormat_RawImage_ { - XAuint32 formatType; - XAuint32 colorFormat; - XAuint32 height; - XAuint32 width; - XAuint32 stride; -} XADataFormat_RawImage; - -typedef struct XADataLocator_Address_ { - XAuint32 locatorType; - void * pAddress; - XAuint32 length; -} XADataLocator_Address; - -#define XA_IODEVICE_AUDIOINPUT ((XAuint32) 0x00000001) -#define XA_IODEVICE_LEDARRAY ((XAuint32) 0x00000002) -#define XA_IODEVICE_VIBRA ((XAuint32) 0x00000003) -#define XA_IODEVICE_CAMERA ((XAuint32) 0x00000004) -#define XA_IODEVICE_RADIO ((XAuint32) 0x00000005) - -typedef struct XADataLocator_IODevice_ { - XAuint32 locatorType; - XAuint32 deviceType; - XAuint32 deviceID; - XAObjectItf device; -} XADataLocator_IODevice; - -typedef void * XANativeHandle; - -typedef struct XADataLocator_NativeDisplay_{ - XAuint32 locatorType; - XANativeHandle hWindow; - XANativeHandle hDisplay; -} XADataLocator_NativeDisplay; - -typedef struct XADataLocator_OutputMix { - XAuint32 locatorType; - XAObjectItf outputMix; -} XADataLocator_OutputMix; - -typedef struct XADataLocator_URI_ { - XAuint32 locatorType; - XAchar * URI; -} XADataLocator_URI; - - -/* ENGINE */ - -#define XA_DEFAULTDEVICEID_AUDIOINPUT ((XAuint32) 0xFFFFFFFF) -#define XA_DEFAULTDEVICEID_AUDIOOUTPUT ((XAuint32) 0xFFFFFFFE) -#define XA_DEFAULTDEVICEID_LED ((XAuint32) 0xFFFFFFFD) -#define XA_DEFAULTDEVICEID_VIBRA ((XAuint32) 0xFFFFFFFC) -#define XA_DEFAULTDEVICEID_CAMERA ((XAuint32) 0xFFFFFFFB) - -#define XA_ENGINEOPTION_THREADSAFE ((XAuint32) 0x00000001) -#define XA_ENGINEOPTION_LOSSOFCONTROL ((XAuint32) 0x00000002) - -#define XA_OBJECTID_ENGINE ((XAuint32) 0x00000001) -#define XA_OBJECTID_LEDDEVICE ((XAuint32) 0x00000002) -#define XA_OBJECTID_VIBRADEVICE ((XAuint32) 0x00000003) -#define XA_OBJECTID_MEDIAPLAYER ((XAuint32) 0x00000004) -#define XA_OBJECTID_MEDIARECORDER ((XAuint32) 0x00000005) -#define XA_OBJECTID_RADIODEVICE ((XAuint32) 0x00000006) -#define XA_OBJECTID_OUTPUTMIX ((XAuint32) 0x00000007) -#define XA_OBJECTID_METADATAEXTRACTOR ((XAuint32) 0x00000008) -#define XA_OBJECTID_CAMERADEVICE ((XAuint32) 0x00000009) - -#define XA_PROFILES_MEDIA_PLAYER ((XAint16) 0x0001) -#define XA_PROFILES_MEDIA_PLAYER_RECORDER ((XAint16) 0x0002) -#define XA_PROFILES_PLUS_MIDI ((XAint16) 0x0004) - -typedef struct XAEngineOption_ { - XAuint32 feature; - XAuint32 data; -} XAEngineOption; - -XA_API XAresult XAAPIENTRY xaCreateEngine( - XAObjectItf * pEngine, - XAuint32 numOptions, - const XAEngineOption * pEngineOptions, - XAuint32 numInterfaces, - const XAInterfaceID * pInterfaceIds, - const XAboolean * pInterfaceRequired -); - -XA_API XAresult XAAPIENTRY xaQueryNumSupportedEngineInterfaces( - XAuint32 * pNumSupportedInterfaces -); - -XA_API XAresult XAAPIENTRY xaQuerySupportedEngineInterfaces( - XAuint32 index, - XAInterfaceID * pInterfaceId -); - -typedef struct XALEDDescriptor_ { - XAuint8 ledCount; - XAuint8 primaryLED; - XAuint32 colorMask; -} XALEDDescriptor; - -typedef struct XAVibraDescriptor_ { - XAboolean supportsFrequency; - XAboolean supportsIntensity; - XAmilliHertz minFrequency; - XAmilliHertz maxFrequency; -} XAVibraDescriptor; - - -XA_API extern const XAInterfaceID XA_IID_ENGINE; - -struct XAEngineItf_; -typedef const struct XAEngineItf_ * const * XAEngineItf; - -struct XAEngineItf_ { - XAresult (*CreateCameraDevice) ( - XAEngineItf self, - XAObjectItf * pDevice, - XAuint32 deviceID, - XAuint32 numInterfaces, - const XAInterfaceID * pInterfaceIds, - const XAboolean * pInterfaceRequired - ); - XAresult (*CreateRadioDevice) ( - XAEngineItf self, - XAObjectItf * pDevice, - XAuint32 numInterfaces, - const XAInterfaceID * pInterfaceIds, - const XAboolean * pInterfaceRequired - ); - XAresult (*CreateLEDDevice) ( - XAEngineItf self, - XAObjectItf * pDevice, - XAuint32 deviceID, - XAuint32 numInterfaces, - const XAInterfaceID * pInterfaceIds, - const XAboolean * pInterfaceRequired - ); - XAresult (*CreateVibraDevice) ( - XAEngineItf self, - XAObjectItf * pDevice, - XAuint32 deviceID, - XAuint32 numInterfaces, - const XAInterfaceID * pInterfaceIds, - const XAboolean * pInterfaceRequired - ); - XAresult (*CreateMediaPlayer) ( - XAEngineItf self, - XAObjectItf * pPlayer, - XADataSource * pDataSrc, - XADataSource * pBankSrc, - XADataSink * pAudioSnk, - XADataSink * pImageVideoSnk, - XADataSink * pVibra, - XADataSink * pLEDArray, - XAuint32 numInterfaces, - const XAInterfaceID * pInterfaceIds, - const XAboolean * pInterfaceRequired - ); - XAresult (*CreateMediaRecorder) ( - XAEngineItf self, - XAObjectItf * pRecorder, - XADataSource * pAudioSrc, - XADataSource * pImageVideoSrc, - XADataSink * pDataSnk, - XAuint32 numInterfaces, - const XAInterfaceID * pInterfaceIds, - const XAboolean * pInterfaceRequired - ); - XAresult (*CreateOutputMix) ( - XAEngineItf self, - XAObjectItf * pMix, - XAuint32 numInterfaces, - const XAInterfaceID * pInterfaceIds, - const XAboolean * pInterfaceRequired - ); - XAresult (*CreateMetadataExtractor) ( - XAEngineItf self, - XAObjectItf * pMetadataExtractor, - XADataSource * pDataSource, - XAuint32 numInterfaces, - const XAInterfaceID * pInterfaceIds, - const XAboolean * pInterfaceRequired - ); - XAresult (*CreateExtensionObject) ( - XAEngineItf self, - XAObjectItf * pObject, - void * pParameters, - XAuint32 objectID, - XAuint32 numInterfaces, - const XAInterfaceID * pInterfaceIds, - const XAboolean * pInterfaceRequired - ); - XAresult (*GetImplementationInfo) ( - XAEngineItf self, - XAuint32 * pMajor, - XAuint32 * pMinor, - XAuint32 * pStep, - const XAchar * pImplementationText - ); - XAresult (*QuerySupportedProfiles) ( - XAEngineItf self, - XAint16 * pProfilesSupported - ); - XAresult (*QueryNumSupportedInterfaces) ( - XAEngineItf self, - XAuint32 objectID, - XAuint32 * pNumSupportedInterfaces - ); - XAresult (*QuerySupportedInterfaces) ( - XAEngineItf self, - XAuint32 objectID, - XAuint32 index, - XAInterfaceID * pInterfaceId - ); - XAresult (*QueryNumSupportedExtensions) ( - XAEngineItf self, - XAuint32 * pNumExtensions - ); - XAresult (*QuerySupportedExtension) ( - XAEngineItf self, - XAuint32 index, - XAchar * pExtensionName, - XAint16 * pNameLength - ); - XAresult (*IsExtensionSupported) ( - XAEngineItf self, - const XAchar * pExtensionName, - XAboolean * pSupported - ); - XAresult (*QueryLEDCapabilities) ( - XAEngineItf self, - XAuint32 *pIndex, - XAuint32 * pLEDDeviceID, - XALEDDescriptor * pDescriptor - ); - XAresult (*QueryVibraCapabilities) ( - XAEngineItf self, - XAuint32 *pIndex, - XAuint32 * pVibraDeviceID, - XAVibraDescriptor * pDescriptor - ); -}; - -/* THREAD SYNC */ - -XA_API extern const XAInterfaceID XA_IID_THREADSYNC; - -struct XAThreadSyncItf_; -typedef const struct XAThreadSyncItf_ * const * XAThreadSyncItf; - -struct XAThreadSyncItf_ { - XAresult (*EnterCriticalSection) ( - XAThreadSyncItf self - ); - XAresult (*ExitCriticalSection) ( - XAThreadSyncItf self - ); -}; - - - - /*****************************************************************/ - /* PLAYBACK RELATED INTERFACES, STRUCTS AND DEFINES */ - /*****************************************************************/ - -/* PLAY */ - -#define XA_TIME_UNKNOWN ((XAuint32) 0xFFFFFFFF) - -#define XA_PLAYEVENT_HEADATEND ((XAuint32) 0x00000001) -#define XA_PLAYEVENT_HEADATMARKER ((XAuint32) 0x00000002) -#define XA_PLAYEVENT_HEADATNEWPOS ((XAuint32) 0x00000004) -#define XA_PLAYEVENT_HEADMOVING ((XAuint32) 0x00000008) -#define XA_PLAYEVENT_HEADSTALLED ((XAuint32) 0x00000010) - -#define XA_PLAYSTATE_STOPPED ((XAuint32) 0x00000001) -#define XA_PLAYSTATE_PAUSED ((XAuint32) 0x00000002) -#define XA_PLAYSTATE_PLAYING ((XAuint32) 0x00000003) - -#define XA_PREFETCHEVENT_STATUSCHANGE ((XAuint32) 0x00000001) -#define XA_PREFETCHEVENT_FILLLEVELCHANGE ((XAuint32) 0x00000002) - -#define XA_PREFETCHSTATUS_UNDERFLOW ((XAuint32) 0x00000001) -#define XA_PREFETCHSTATUS_SUFFICIENTDATA ((XAuint32) 0x00000002) -#define XA_PREFETCHSTATUS_OVERFLOW ((XAuint32) 0x00000003) - -#define XA_SEEKMODE_FAST ((XAuint32) 0x0001) -#define XA_SEEKMODE_ACCURATE ((XAuint32) 0x0002) - -XA_API extern const XAInterfaceID XA_IID_PLAY; - -struct XAPlayItf_; -typedef const struct XAPlayItf_ * const * XAPlayItf; - -typedef void (XAAPIENTRY * xaPlayCallback) ( - XAPlayItf caller, - void * pContext, - XAuint32 event -); - -struct XAPlayItf_ { - XAresult (*SetPlayState) ( - XAPlayItf self, - XAuint32 state - ); - XAresult (*GetPlayState) ( - XAPlayItf self, - XAuint32 * pState - ); - XAresult (*GetDuration) ( - XAPlayItf self, - XAmillisecond * pMsec - ); - XAresult (*GetPosition) ( - XAPlayItf self, - XAmillisecond * pMsec - ); - XAresult (*RegisterCallback) ( - XAPlayItf self, - xaPlayCallback callback, - void * pContext - ); - XAresult (*SetCallbackEventsMask) ( - XAPlayItf self, - XAuint32 eventFlags - ); - XAresult (*GetCallbackEventsMask) ( - XAPlayItf self, - XAuint32 * pEventFlags - ); - XAresult (*SetMarkerPosition) ( - XAPlayItf self, - XAmillisecond mSec - ); - XAresult (*ClearMarkerPosition) ( - XAPlayItf self - ); - XAresult (*GetMarkerPosition) ( - XAPlayItf self, - XAmillisecond * pMsec - ); - XAresult (*SetPositionUpdatePeriod) ( - XAPlayItf self, - XAmillisecond mSec - ); - XAresult (*GetPositionUpdatePeriod) ( - XAPlayItf self, - XAmillisecond * pMsec - ); -}; - -/* PLAYBACK RATE */ - -#define XA_RATEPROP_STAGGEREDVIDEO ((XAuint32) 0x00000001) -#define XA_RATEPROP_SMOOTHVIDEO ((XAuint32) 0x00000002) -#define XA_RATEPROP_SILENTAUDIO ((XAuint32) 0x00000100) -#define XA_RATEPROP_STAGGEREDAUDIO ((XAuint32) 0x00000200) -#define XA_RATEPROP_NOPITCHCORAUDIO ((XAuint32) 0x00000400) -#define XA_RATEPROP_PITCHCORAUDIO ((XAuint32) 0x00000800) - -XA_API extern const XAInterfaceID XA_IID_PLAYBACKRATE; - -struct XAPlaybackRateItf_; -typedef const struct XAPlaybackRateItf_ * const * XAPlaybackRateItf; - -struct XAPlaybackRateItf_ { - XAresult (*SetRate) ( - XAPlaybackRateItf self, - XApermille rate - ); - XAresult (*GetRate) ( - XAPlaybackRateItf self, - XApermille * pRate - ); - XAresult (*SetPropertyConstraints) ( - XAPlaybackRateItf self, - XAuint32 constraints - ); - XAresult (*GetProperties) ( - XAPlaybackRateItf self, - XAuint32 * pProperties - ); - XAresult (*GetCapabilitiesOfRate) ( - XAPlaybackRateItf self, - XApermille rate, - XAuint32 * pCapabilities - ); - XAresult (*GetRateRange) ( - XAPlaybackRateItf self, - XAuint8 index, - XApermille * pMinRate, - XApermille * pMaxRate, - XApermille * pStepSize, - XAuint32 * pCapabilities - ); -}; - -/* PREFETCH STATUS */ - -XA_API extern const XAInterfaceID XA_IID_PREFETCHSTATUS; - -struct XAPrefetchStatusItf_; -typedef const struct XAPrefetchStatusItf_ - * const * XAPrefetchStatusItf; - -typedef void (XAAPIENTRY * xaPrefetchCallback) ( - XAPrefetchStatusItf caller, - void * pContext, - XAuint32 event -); - -struct XAPrefetchStatusItf_ { - XAresult (*GetPrefetchStatus) ( - XAPrefetchStatusItf self, - XAuint32 * pStatus - ); - XAresult (*GetFillLevel) ( - XAPrefetchStatusItf self, - XApermille * pLevel - ); - XAresult (*RegisterCallback) ( - XAPrefetchStatusItf self, - xaPrefetchCallback callback, - void * pContext - ); - XAresult (*SetCallbackEventsMask) ( - XAPrefetchStatusItf self, - XAuint32 eventFlags - ); - XAresult (*GetCallbackEventsMask) ( - XAPrefetchStatusItf self, - XAuint32 * pEventFlags - ); - XAresult (*SetFillUpdatePeriod) ( - XAPrefetchStatusItf self, - XApermille period - ); - XAresult (*GetFillUpdatePeriod) ( - XAPrefetchStatusItf self, - XApermille * pPeriod - ); -}; - -/* SEEK */ - -XA_API extern const XAInterfaceID XA_IID_SEEK; - -struct XASeekItf_; -typedef const struct XASeekItf_ * const * XASeekItf; - -struct XASeekItf_ { - XAresult (*SetPosition) ( - XASeekItf self, - XAmillisecond pos, - XAuint32 seekMode - ); - XAresult (*SetLoop) ( - XASeekItf self, - XAboolean loopEnable, - XAmillisecond startPos, - XAmillisecond endPos - ); - XAresult (*GetLoop) ( - XASeekItf self, - XAboolean * pLoopEnabled, - XAmillisecond * pStartPos, - XAmillisecond * pEndPos - ); -}; - -/* VOLUME */ - -XA_API extern const XAInterfaceID XA_IID_VOLUME; - -struct XAVolumeItf_; -typedef const struct XAVolumeItf_ * const * XAVolumeItf; - -struct XAVolumeItf_ { - XAresult (*SetVolumeLevel) ( - XAVolumeItf self, - XAmillibel level - ); - XAresult (*GetVolumeLevel) ( - XAVolumeItf self, - XAmillibel * pLevel - ); - XAresult (*GetMaxVolumeLevel) ( - XAVolumeItf self, - XAmillibel * pMaxLevel - ); - XAresult (*SetMute) ( - XAVolumeItf self, - XAboolean mute - ); - XAresult (*GetMute) ( - XAVolumeItf self, - XAboolean * pMute - ); - XAresult (*EnableStereoPosition) ( - XAVolumeItf self, - XAboolean enable - ); - XAresult (*IsEnabledStereoPosition) ( - XAVolumeItf self, - XAboolean * pEnable - ); - XAresult (*SetStereoPosition) ( - XAVolumeItf self, - XApermille stereoPosition - ); - XAresult (*GetStereoPosition) ( - XAVolumeItf self, - XApermille * pStereoPosition - ); -}; - -/* IMAGE CONTROL */ - -XA_API extern const XAInterfaceID XA_IID_IMAGECONTROLS; - -struct XAImageControlsItf_; -typedef const struct XAImageControlsItf_ * const * XAImageControlsItf; - -struct XAImageControlsItf_ { - XAresult (*SetBrightness) ( - XAImageControlsItf self, - XAuint32 brightness - ); - XAresult (*GetBrightness) ( - XAImageControlsItf self, - XAuint32 * pBrightness - ); - XAresult (*SetContrast) ( - XAImageControlsItf self, - XAint32 contrast - ); - XAresult (*GetContrast) ( - XAImageControlsItf self, - XAint32 * pContrast - ); - XAresult (*SetGamma) ( - XAImageControlsItf self, - XApermille gamma - ); - XAresult (*GetGamma) ( - XAImageControlsItf self, - XApermille * pGamma - ); - XAresult (*GetSupportedGammaSettings) ( - XAImageControlsItf self, - XApermille * pMinValue, - XApermille * pMaxValue, - XAuint32 * pNumSettings, - XApermille ** ppSettings - ); -}; - -/* IMAGE EFFECT */ - -#define XA_IMAGEEFFECT_MONOCHROME ((XAuint32) 0x00000001) -#define XA_IMAGEEFFECT_NEGATIVE ((XAuint32) 0x00000002) -#define XA_IMAGEEFFECT_SEPIA ((XAuint32) 0x00000003) -#define XA_IMAGEEFFECT_EMBOSS ((XAuint32) 0x00000004) -#define XA_IMAGEEFFECT_PAINTBRUSH ((XAuint32) 0x00000005) -#define XA_IMAGEEFFECT_SOLARIZE ((XAuint32) 0x00000006) -#define XA_IMAGEEFFECT_CARTOON ((XAuint32) 0x00000007) - -XA_API extern const XAInterfaceID XA_IID_IMAGEEFFECTS; - -struct XAImageEffectsItf_; -typedef const struct XAImageEffectsItf_ * const * XAImageEffectsItf; - -struct XAImageEffectsItf_ { - XAresult (*QuerySupportedImageEffects) ( - XAImageEffectsItf self, - XAuint32 index, - XAuint32 * pImageEffectId - ); - XAresult (*EnableImageEffect) ( - XAImageEffectsItf self, - XAuint32 imageEffectID - ); - XAresult (*DisableImageEffect) ( - XAImageEffectsItf self, - XAuint32 imageEffectID - ); - XAresult (*IsImageEffectEnabled) ( - XAImageEffectsItf self, - XAuint32 imageEffectID, - XAboolean * pEnabled - ); -}; - -/* VIDEO POST PROCESSING */ - -#define XA_VIDEOMIRROR_NONE ((XAuint32) 0x00000001) -#define XA_VIDEOMIRROR_VERTICAL ((XAuint32) 0x00000002) -#define XA_VIDEOMIRROR_HORIZONTAL ((XAuint32) 0x00000003) -#define XA_VIDEOMIRROR_BOTH ((XAuint32) 0x00000004) - -#define XA_VIDEOSCALE_STRETCH ((XAuint32) 0x00000001) -#define XA_VIDEOSCALE_FIT ((XAuint32) 0x00000002) -#define XA_VIDEOSCALE_CROP ((XAuint32) 0x00000003) - -#define XA_RENDERINGHINT_NONE ((XAuint32) 0x00000000) -#define XA_RENDERINGHINT_ANTIALIASING ((XAuint32) 0x00000001) - -typedef struct XARectangle_ { - XAuint32 left; - XAuint32 top; - XAuint32 width; - XAuint32 height; -} XARectangle; - -XA_API extern const XAInterfaceID XA_IID_VIDEOPOSTPROCESSING; - -struct XAVideoPostProcessingItf_; -typedef const struct XAVideoPostProcessingItf_ * const * XAVideoPostProcessingItf; - -struct XAVideoPostProcessingItf_ { - XAresult (*SetRotation) ( - XAVideoPostProcessingItf self, - XAmillidegree rotation - ); - XAresult (*IsArbitraryRotationSupported) ( - XAVideoPostProcessingItf self, - XAboolean *pSupported - ); - XAresult (*SetScaleOptions) ( - XAVideoPostProcessingItf self, - XAuint32 scaleOptions, - XAuint32 backgroundColor, - XAuint32 renderingHints - ); - XAresult (*SetSourceRectangle) ( - XAVideoPostProcessingItf self, - const XARectangle *pSrcRect - ); - XAresult (*SetDestinationRectangle) ( - XAVideoPostProcessingItf self, - const XARectangle *pDestRect - ); - XAresult (*SetMirror) ( - XAVideoPostProcessingItf self, - XAuint32 mirror - ); - XAresult (*Commit) ( - XAVideoPostProcessingItf self - ); -}; - - - - /*****************************************************************/ - /* CAPTURING INTERFACES, STRUCTS AND DEFINES */ - /*****************************************************************/ - -/* RECORD */ - -#define XA_RECORDEVENT_HEADATLIMIT ((XAuint32) 0x00000001) -#define XA_RECORDEVENT_HEADATMARKER ((XAuint32) 0x00000002) -#define XA_RECORDEVENT_HEADATNEWPOS ((XAuint32) 0x00000004) -#define XA_RECORDEVENT_HEADMOVING ((XAuint32) 0x00000008) -#define XA_RECORDEVENT_HEADSTALLED ((XAuint32) 0x00000010) -#define XA_RECORDEVENT_BUFFER_FULL ((XAuint32) 0x00000020) - -#define XA_RECORDSTATE_STOPPED ((XAuint32) 0x00000001) -#define XA_RECORDSTATE_PAUSED ((XAuint32) 0x00000002) -#define XA_RECORDSTATE_RECORDING ((XAuint32) 0x00000003) - -XA_API extern const XAInterfaceID XA_IID_RECORD; - -struct XARecordItf_; -typedef const struct XARecordItf_ * const * XARecordItf; - -typedef void (XAAPIENTRY * xaRecordCallback) ( - XARecordItf caller, - void * pContext, - XAuint32 event -); - -struct XARecordItf_ { - XAresult (*SetRecordState) ( - XARecordItf self, - XAuint32 state - ); - XAresult (*GetRecordState) ( - XARecordItf self, - XAuint32 * pState - ); - XAresult (*SetDurationLimit) ( - XARecordItf self, - XAmillisecond msec - ); - XAresult (*GetPosition) ( - XARecordItf self, - XAmillisecond * pMsec - ); - XAresult (*RegisterCallback) ( - XARecordItf self, - xaRecordCallback callback, - void * pContext - ); - XAresult (*SetCallbackEventsMask) ( - XARecordItf self, - XAuint32 eventFlags - ); - XAresult (*GetCallbackEventsMask) ( - XARecordItf self, - XAuint32 * pEventFlags - ); - XAresult (*SetMarkerPosition) ( - XARecordItf self, - XAmillisecond mSec - ); - XAresult (*ClearMarkerPosition) ( - XARecordItf self - ); - XAresult (*GetMarkerPosition) ( - XARecordItf self, - XAmillisecond * pMsec - ); - XAresult (*SetPositionUpdatePeriod) ( - XARecordItf self, - XAmillisecond mSec - ); - XAresult (*GetPositionUpdatePeriod) ( - XARecordItf self, - XAmillisecond * pMsec - ); -}; - -/* SNAPSHOT */ - -XA_API extern const XAInterfaceID XA_IID_SNAPSHOT; - -struct XASnapshotItf_; -typedef const struct XASnapshotItf_ * const * XASnapshotItf; - -typedef void (XAAPIENTRY * xaSnapshotInitiatedCallback) ( - XASnapshotItf caller, - void * context -); - -typedef void (XAAPIENTRY * xaSnapshotTakenCallback) ( - XASnapshotItf caller, - void * context, - XAuint32 numberOfPicsTaken, - const XADataSink * image -); - -struct XASnapshotItf_ { - XAresult (*InitiateSnapshot) ( - XASnapshotItf self, - XAuint32 numberOfPictures, - XAuint32 fps, - XAboolean freezeViewFinder, - XADataSink sink, - xaSnapshotInitiatedCallback initiatedCallback, - xaSnapshotTakenCallback takenCallback, - void * pContext - ); - XAresult (*TakeSnapshot) ( - XASnapshotItf self - ); - XAresult (*CancelSnapshot) ( - XASnapshotItf self - ); - XAresult (*ReleaseBuffers) ( - XASnapshotItf self, - XADataSink * image - ); - XAresult (*GetMaxPicsPerBurst) ( - XASnapshotItf self, - XAuint32 * maxNumberOfPictures - ); - XAresult (*GetBurstFPSRange) ( - XASnapshotItf self, - XAuint32 * minFPS, - XAuint32 * maxFPS - ); - XAresult (*SetShutterFeedback) ( - XASnapshotItf self, - XAboolean enabled - ); - XAresult (*GetShutterFeedback) ( - XASnapshotItf self, - XAboolean * enabled - ); -}; - - - - /*****************************************************************/ - /* METADATA RELATED INTERFACES, STRUCTS AND DEFINES */ - /*****************************************************************/ - -/* METADATA (EXTRACTION, INSERTION, TRAVERSAL) */ - -#define XA_NODE_PARENT ((XAuint32) 0xFFFFFFFF) - -#define XA_ROOT_NODE_ID ((XAint32) 0x7FFFFFFF) - -#define XA_NODETYPE_UNSPECIFIED ((XAuint32) 0x00000001) -#define XA_NODETYPE_AUDIO ((XAuint32) 0x00000002) -#define XA_NODETYPE_VIDEO ((XAuint32) 0x00000003) -#define XA_NODETYPE_IMAGE ((XAuint32) 0x00000004) - -#define XA_CHARACTERENCODING_UNKNOWN ((XAuint32) 0x00000000) -#define XA_CHARACTERENCODING_BINARY ((XAuint32) 0x00000001) -#define XA_CHARACTERENCODING_ASCII ((XAuint32) 0x00000002) -#define XA_CHARACTERENCODING_BIG5 ((XAuint32) 0x00000003) -#define XA_CHARACTERENCODING_CODEPAGE1252 ((XAuint32) 0x00000004) -#define XA_CHARACTERENCODING_GB2312 ((XAuint32) 0x00000005) -#define XA_CHARACTERENCODING_HZGB2312 ((XAuint32) 0x00000006) -#define XA_CHARACTERENCODING_GB12345 ((XAuint32) 0x00000007) -#define XA_CHARACTERENCODING_GB18030 ((XAuint32) 0x00000008) -#define XA_CHARACTERENCODING_GBK ((XAuint32) 0x00000009) -#define XA_CHARACTERENCODING_IMAPUTF7 ((XAuint32) 0x0000000A) -#define XA_CHARACTERENCODING_ISO2022JP ((XAuint32) 0x0000000B) -#define XA_CHARACTERENCODING_ISO2022JP1 ((XAuint32) 0x0000000B) -#define XA_CHARACTERENCODING_ISO88591 ((XAuint32) 0x0000000C) -#define XA_CHARACTERENCODING_ISO885910 ((XAuint32) 0x0000000D) -#define XA_CHARACTERENCODING_ISO885913 ((XAuint32) 0x0000000E) -#define XA_CHARACTERENCODING_ISO885914 ((XAuint32) 0x0000000F) -#define XA_CHARACTERENCODING_ISO885915 ((XAuint32) 0x00000010) -#define XA_CHARACTERENCODING_ISO88592 ((XAuint32) 0x00000011) -#define XA_CHARACTERENCODING_ISO88593 ((XAuint32) 0x00000012) -#define XA_CHARACTERENCODING_ISO88594 ((XAuint32) 0x00000013) -#define XA_CHARACTERENCODING_ISO88595 ((XAuint32) 0x00000014) -#define XA_CHARACTERENCODING_ISO88596 ((XAuint32) 0x00000015) -#define XA_CHARACTERENCODING_ISO88597 ((XAuint32) 0x00000016) -#define XA_CHARACTERENCODING_ISO88598 ((XAuint32) 0x00000017) -#define XA_CHARACTERENCODING_ISO88599 ((XAuint32) 0x00000018) -#define XA_CHARACTERENCODING_ISOEUCJP ((XAuint32) 0x00000019) -#define XA_CHARACTERENCODING_SHIFTJIS ((XAuint32) 0x0000001A) -#define XA_CHARACTERENCODING_SMS7BIT ((XAuint32) 0x0000001B) -#define XA_CHARACTERENCODING_UTF7 ((XAuint32) 0x0000001C) -#define XA_CHARACTERENCODING_UTF8 ((XAuint32) 0x0000001D) -#define XA_CHARACTERENCODING_JAVACONFORMANTUTF8 ((XAuint32) 0x0000001E) -#define XA_CHARACTERENCODING_UTF16BE ((XAuint32) 0x0000001F) -#define XA_CHARACTERENCODING_UTF16LE ((XAuint32) 0x00000020) - -#define XA_METADATA_FILTER_KEY ((XAuint8) 0x01) -#define XA_METADATA_FILTER_LANG ((XAuint8) 0x02) -#define XA_METADATA_FILTER_ENCODING ((XAuint8) 0x04) - -#define XA_METADATATRAVERSALMODE_ALL ((XAuint32) 0x00000001) -#define XA_METADATATRAVERSALMODE_NODE ((XAuint32) 0x00000002) - -#ifndef _KHRONOS_KEYS_ -#define _KHRONOS_KEYS_ -#define KHRONOS_TITLE "KhronosTitle" -#define KHRONOS_ALBUM "KhronosAlbum" -#define KHRONOS_TRACK_NUMBER "KhronosTrackNumber" -#define KHRONOS_ARTIST "KhronosArtist" -#define KHRONOS_GENRE "KhronosGenre" -#define KHRONOS_YEAR "KhronosYear" -#define KHRONOS_COMMENT "KhronosComment" -#define KHRONOS_ARTIST_URL "KhronosArtistURL" -#define KHRONOS_CONTENT_URL "KhronosContentURL" -#define KHRONOS_RATING "KhronosRating" -#define KHRONOS_ALBUM_ART "KhronosAlbumArt" -#define KHRONOS_COPYRIGHT "KhronosCopyright" -#endif /* _KHRONOS_KEYS_ */ - - -typedef struct XAMetadataInfo_ { - XAuint32 size; - XAuint32 encoding; - const XAchar langCountry[16]; - XAuint8 data[1]; -} XAMetadataInfo; - -XA_API extern const XAInterfaceID XA_IID_METADATAEXTRACTION; - -struct XAMetadataExtractionItf_; -typedef const struct XAMetadataExtractionItf_ - * const * XAMetadataExtractionItf; - -struct XAMetadataExtractionItf_ { - XAresult (*GetItemCount) ( - XAMetadataExtractionItf self, - XAuint32 * pItemCount - ); - XAresult (*GetKeySize) ( - XAMetadataExtractionItf self, - XAuint32 index, - XAuint32 * pKeySize - ); - XAresult (*GetKey) ( - XAMetadataExtractionItf self, - XAuint32 index, - XAuint32 keySize, - XAMetadataInfo * pKey - ); - XAresult (*GetValueSize) ( - XAMetadataExtractionItf self, - XAuint32 index, - XAuint32 * pValueSize - ); - XAresult (*GetValue) ( - XAMetadataExtractionItf self, - XAuint32 index, - XAuint32 valueSize, - XAMetadataInfo * pValue - ); - XAresult (*AddKeyFilter) ( - XAMetadataExtractionItf self, - XAuint32 keySize, - const void * pKey, - XAuint32 keyEncoding, - const XAchar * pValueLangCountry, - XAuint32 valueEncoding, - XAuint8 filterMask - ); - XAresult (*ClearKeyFilter) ( - XAMetadataExtractionItf self - ); -}; - - -XA_API extern const XAInterfaceID XA_IID_METADATAINSERTION; - -struct XAMetadataInsertionItf_; -typedef const struct XAMetadataInsertionItf_ - * const * XAMetadataInsertionItf; - -typedef void (XAAPIENTRY * xaMetadataInsertionCallback) ( - XAMetadataInsertionItf caller, - void * pContext, - XAMetadataInfo * pKey, - XAMetadataInfo * pValue, - XAint32 nodeID, - XAboolean result -); - -struct XAMetadataInsertionItf_ { - XAresult (*CreateChildNode) ( - XAMetadataInsertionItf self, - XAint32 parentNodeID, - XAuint32 type, - XAchar * mimeType, - XAint32 * pChildNodeID - ); - XAresult (*GetSupportedKeysCount) ( - XAMetadataInsertionItf self, - XAint32 nodeID, - XAboolean * pFreeKeys, - XAuint32 * pKeyCount, - XAuint32 * pEncodingCount - ); - XAresult (*GetKeySize) ( - XAMetadataInsertionItf self, - XAint32 nodeID, - XAuint32 keyIndex, - XAuint32 * pKeySize - ); - XAresult (*GetKey) ( - XAMetadataInsertionItf self, - XAint32 nodeID, - XAuint32 keyIndex, - XAuint32 keySize, - XAMetadataInfo * pKey - ); - XAresult (*GetFreeKeysEncoding) ( - XAMetadataInsertionItf self, - XAint32 nodeID, - XAuint32 encodingIndex, - XAuint32 * pEncoding - ); - XAresult (*InsertMetadataItem) ( - XAMetadataInsertionItf self, - XAint32 nodeID, - XAMetadataInfo * pKey, - XAMetadataInfo * pValue, - XAboolean overwrite - ); - XAresult (*RegisterCallback) ( - XAMetadataInsertionItf self, - xaMetadataInsertionCallback callback, - void * pContext - ); -}; - - -XA_API extern const XAInterfaceID XA_IID_METADATATRAVERSAL; - -struct XAMetadataTraversalItf_; -typedef const struct XAMetadataTraversalItf_ - * const * XAMetadataTraversalItf; - -struct XAMetadataTraversalItf_ { - XAresult (*SetMode) ( - XAMetadataTraversalItf self, - XAuint32 mode - ); - XAresult (*GetChildCount) ( - XAMetadataTraversalItf self, - XAuint32 * pCount - ); - XAresult (*GetChildMIMETypeSize) ( - XAMetadataTraversalItf self, - XAuint32 index, - XAuint32 * pSize - ); - XAresult (*GetChildInfo) ( - XAMetadataTraversalItf self, - XAuint32 index, - XAint32 * pNodeID, - XAuint32 * pType, - XAuint32 size, - XAchar * pMimeType - ); - XAresult (*SetActiveNode) ( - XAMetadataTraversalItf self, - XAuint32 index - ); -}; - -/* DYNAMIC SOURCE */ - -XA_API extern const XAInterfaceID XA_IID_DYNAMICSOURCE; - -struct XADynamicSourceItf_; -typedef const struct XADynamicSourceItf_ * const * XADynamicSourceItf; - -struct XADynamicSourceItf_ { - XAresult (*SetSource) ( - XADynamicSourceItf self, - XADataSource * pDataSource - ); -}; - - - - /*****************************************************************/ - /* I/O DEVICES RELATED INTERFACES, STRUCTS AND DEFINES */ - /*****************************************************************/ - -/* CAMERA AND CAMERA CAPABILITIES */ - -#define XA_CAMERA_APERTUREMODE_MANUAL ((XAuint32) 0x00000001) -#define XA_CAMERA_APERTUREMODE_AUTO ((XAuint32) 0x00000002) - -#define XA_CAMERA_AUTOEXPOSURESTATUS_SUCCESS ((XAuint32) 0x00000001) -#define XA_CAMERA_AUTOEXPOSURESTATUS_UNDEREXPOSURE ((XAuint32) 0x00000002) -#define XA_CAMERA_AUTOEXPOSURESTATUS_OVEREXPOSURE ((XAuint32) 0x00000003) - -#define XA_CAMERACBEVENT_ROTATION ((XAuint32) 0x00000001) -#define XA_CAMERACBEVENT_FLASHREADY ((XAuint32) 0x00000002) -#define XA_CAMERACBEVENT_FOCUSSTATUS ((XAuint32) 0x00000003) -#define XA_CAMERACBEVENT_EXPOSURESTATUS ((XAuint32) 0x00000004) -#define XA_CAMERACBEVENT_WHITEBALANCELOCKED ((XAuint32) 0x00000005) -#define XA_CAMERACBEVENT_ZOOMSTATUS ((XAuint32) 0x00000006) - -#define XA_CAMERACAP_FLASH ((XAuint32) 0x00000001) -#define XA_CAMERACAP_AUTOFOCUS ((XAuint32) 0x00000002) -#define XA_CAMERACAP_CONTINUOUSAUTOFOCUS ((XAuint32) 0x00000004) -#define XA_CAMERACAP_MANUALFOCUS ((XAuint32) 0x00000008) -#define XA_CAMERACAP_AUTOEXPOSURE ((XAuint32) 0x00000010) -#define XA_CAMERACAP_MANUALEXPOSURE ((XAuint32) 0x00000020) -#define XA_CAMERACAP_AUTOISOSENSITIVITY ((XAuint32) 0x00000040) -#define XA_CAMERACAP_MANUALISOSENSITIVITY ((XAuint32) 0x00000080) -#define XA_CAMERACAP_AUTOAPERTURE ((XAuint32) 0x00000100) -#define XA_CAMERACAP_MANUALAPERTURE ((XAuint32) 0x00000200) -#define XA_CAMERACAP_AUTOSHUTTERSPEED ((XAuint32) 0x00000400) -#define XA_CAMERACAP_MANUALSHUTTERSPEED ((XAuint32) 0x00000800) -#define XA_CAMERACAP_AUTOWHITEBALANCE ((XAuint32) 0x00001000) -#define XA_CAMERACAP_MANUALWHITEBALANCE ((XAuint32) 0x00002000) -#define XA_CAMERACAP_OPTICALZOOM ((XAuint32) 0x00004000) -#define XA_CAMERACAP_DIGITALZOOM ((XAuint32) 0x00008000) -#define XA_CAMERACAP_METERING ((XAuint32) 0x00010000) -#define XA_CAMERACAP_BRIGHTNESS ((XAuint32) 0x00020000) -#define XA_CAMERACAP_CONTRAST ((XAuint32) 0x00040000) -#define XA_CAMERACAP_GAMMA ((XAuint32) 0x00080000) - - -#define XA_CAMERA_EXPOSUREMODE_MANUAL ((XAuint32) 0x00000001) -#define XA_CAMERA_EXPOSUREMODE_AUTO ((XAuint32) 0x00000002) -#define XA_CAMERA_EXPOSUREMODE_NIGHT ((XAuint32) 0x00000004) -#define XA_CAMERA_EXPOSUREMODE_BACKLIGHT ((XAuint32) 0x00000008) -#define XA_CAMERA_EXPOSUREMODE_SPOTLIGHT ((XAuint32) 0x00000010) -#define XA_CAMERA_EXPOSUREMODE_SPORTS ((XAuint32) 0x00000020) -#define XA_CAMERA_EXPOSUREMODE_SNOW ((XAuint32) 0x00000040) -#define XA_CAMERA_EXPOSUREMODE_BEACH ((XAuint32) 0x00000080) -#define XA_CAMERA_EXPOSUREMODE_LARGEAPERTURE ((XAuint32) 0x00000100) -#define XA_CAMERA_EXPOSUREMODE_SMALLAPERTURE ((XAuint32) 0x00000200) -#define XA_CAMERA_EXPOSUREMODE_PORTRAIT ((XAuint32) 0x0000400) -#define XA_CAMERA_EXPOSUREMODE_NIGHTPORTRAIT ((XAuint32) 0x00000800) - -#define XA_CAMERA_FLASHMODE_OFF ((XAuint32) 0x00000001) -#define XA_CAMERA_FLASHMODE_ON ((XAuint32) 0x00000002) -#define XA_CAMERA_FLASHMODE_AUTO ((XAuint32) 0x00000004) -#define XA_CAMERA_FLASHMODE_REDEYEREDUCTION ((XAuint32) 0x00000008) -#define XA_CAMERA_FLASHMODE_REDEYEREDUCTION_AUTO ((XAuint32) 0x00000010) -#define XA_CAMERA_FLASHMODE_FILLIN ((XAuint32) 0x00000020) -#define XA_CAMERA_FLASHMODE_TORCH ((XAuint32) 0x00000040) - -#define XA_CAMERA_FOCUSMODE_MANUAL ((XAuint32) 0x00000001) -#define XA_CAMERA_FOCUSMODE_AUTO ((XAuint32) 0x00000002) -#define XA_CAMERA_FOCUSMODE_CENTROID ((XAuint32) 0x00000004) -#define XA_CAMERA_FOCUSMODE_CONTINUOUS_AUTO ((XAuint32) 0x00000008) -#define XA_CAMERA_FOCUSMODE_CONTINUOUS_CENTROID ((XAuint32) 0x00000010) - -#define XA_CAMERA_FOCUSMODESTATUS_OFF ((XAuint32) 0x00000001) -#define XA_CAMERA_FOCUSMODESTATUS_REQUEST ((XAuint32) 0x00000002) -#define XA_CAMERA_FOCUSMODESTATUS_REACHED ((XAuint32) 0x00000003) -#define XA_CAMERA_FOCUSMODESTATUS_UNABLETOREACH ((XAuint32) 0x00000004) -#define XA_CAMERA_FOCUSMODESTATUS_LOST ((XAuint32) 0x00000005) - -#define XA_CAMERA_ISOSENSITIVITYMODE_MANUAL ((XAuint32) 0x00000001) -#define XA_CAMERA_ISOSENSITIVITYMODE_AUTO ((XAuint32) 0x00000002) - -#define XA_CAMERA_LOCK_AUTOFOCUS ((XAuint32) 0x00000001) -#define XA_CAMERA_LOCK_AUTOEXPOSURE ((XAuint32) 0x00000002) -#define XA_CAMERA_LOCK_AUTOWHITEBALANCE ((XAuint32) 0x00000004) - -#define XA_CAMERA_METERINGMODE_AVERAGE ((XAuint32) 0x00000001) -#define XA_CAMERA_METERINGMODE_SPOT ((XAuint32) 0x00000002) -#define XA_CAMERA_METERINGMODE_MATRIX ((XAuint32) 0x00000004) - -#define XA_CAMERA_SHUTTERSPEEDMODE_MANUAL ((XAuint32) 0x00000001) -#define XA_CAMERA_SHUTTERSPEEDMODE_AUTO ((XAuint32) 0x00000002) - -#define XA_CAMERA_WHITEBALANCEMODE_MANUAL ((XAuint32) 0x00000001) -#define XA_CAMERA_WHITEBALANCEMODE_AUTO ((XAuint32) 0x00000002) -#define XA_CAMERA_WHITEBALANCEMODE_SUNLIGHT ((XAuint32) 0x00000004) -#define XA_CAMERA_WHITEBALANCEMODE_CLOUDY ((XAuint32) 0x00000008) -#define XA_CAMERA_WHITEBALANCEMODE_SHADE ((XAuint32) 0x00000010) -#define XA_CAMERA_WHITEBALANCEMODE_TUNGSTEN ((XAuint32) 0x00000020) -#define XA_CAMERA_WHITEBALANCEMODE_FLUORESCENT ((XAuint32) 0x00000040) -#define XA_CAMERA_WHITEBALANCEMODE_INCANDESCENT ((XAuint32) 0x00000080) -#define XA_CAMERA_WHITEBALANCEMODE_FLASH ((XAuint32) 0x00000100) -#define XA_CAMERA_WHITEBALANCEMODE_SUNSET ((XAuint32) 0x00000200) - -#define XA_CAMERA_ZOOM_SLOW ((XAuint32) 50) -#define XA_CAMERA_ZOOM_NORMAL ((XAuint32) 100) -#define XA_CAMERA_ZOOM_FAST ((XAuint32) 200) -#define XA_CAMERA_ZOOM_FASTEST ((XAuint32) 0xFFFFFFFF) - -#define XA_FOCUSPOINTS_ONE ((XAuint32) 0x00000001) -#define XA_FOCUSPOINTS_THREE_3X1 ((XAuint32) 0x00000002) -#define XA_FOCUSPOINTS_FIVE_CROSS ((XAuint32) 0x00000003) -#define XA_FOCUSPOINTS_SEVEN_CROSS ((XAuint32) 0x00000004) -#define XA_FOCUSPOINTS_NINE_SQUARE ((XAuint32) 0x00000005) -#define XA_FOCUSPOINTS_ELEVEN_CROSS ((XAuint32) 0x00000006) -#define XA_FOCUSPOINTS_TWELVE_3X4 ((XAuint32) 0x00000007) -#define XA_FOCUSPOINTS_TWELVE_4X3 ((XAuint32) 0x00000008) -#define XA_FOCUSPOINTS_SIXTEEN_SQUARE ((XAuint32) 0x00000009) -#define XA_FOCUSPOINTS_CUSTOM ((XAuint32) 0x0000000A) - -typedef struct XAFocusPointPosition_ { - XAuint32 left; - XAuint32 top; - XAuint32 width; - XAuint32 height; -} XAFocusPointPosition; - -#define XA_ORIENTATION_UNKNOWN ((XAuint32) 0x00000001) -#define XA_ORIENTATION_OUTWARDS ((XAuint32) 0x00000002) -#define XA_ORIENTATION_INWARDS ((XAuint32) 0x00000003) - -typedef struct XACameraDescriptor_ { - XAchar * name; - XAuint32 maxWidth; - XAuint32 maxHeight; - XAuint32 orientation; - XAuint32 featuresSupported; - XAuint32 exposureModesSupported; - XAuint32 flashModesSupported; - XAuint32 focusModesSupported; - XAuint32 meteringModesSupported; - XAuint32 whiteBalanceModesSupported; -} XACameraDescriptor; - -XA_API extern const XAInterfaceID XA_IID_CAMERACAPABILITIES; - -struct XACameraCapabilitiesItf_; -typedef const struct XACameraCapabilitiesItf_ - * const * XACameraCapabilitiesItf; - -struct XACameraCapabilitiesItf_ { - XAresult (*GetCameraCapabilities) ( - XACameraCapabilitiesItf self, - XAuint32 *pIndex, - XAuint32 * pCameraDeviceID, - XACameraDescriptor * pDescriptor - ); - XAresult (*QueryFocusRegionPatterns) ( - XACameraCapabilitiesItf self, - XAuint32 cameraDeviceID, - XAuint32 * pPatternID, - XAuint32 * pFocusPattern, - XAuint32 * pCustomPoints1, - XAuint32 * pCustomPoints2 - ); - XAresult (*GetSupportedAutoLocks) ( - XACameraCapabilitiesItf self, - XAuint32 cameraDeviceID, - XAuint32 * pNumCombinations, - XAuint32 ** ppLocks - ); - XAresult (*GetSupportedFocusManualSettings) ( - XACameraCapabilitiesItf self, - XAuint32 cameraDeviceID, - XAboolean macroEnabled, - XAmillimeter * pMinValue, - XAmillimeter * pMaxValue, - XAuint32 * pNumSettings, - XAmillimeter ** ppSettings - ); - XAresult (*GetSupportedISOSensitivitySettings) ( - XACameraCapabilitiesItf self, - XAuint32 cameraDeviceID, - XAuint32 * pMinValue, - XAuint32 * pMaxValue, - XAuint32 * pNumSettings, - XAuint32 ** ppSettings - ); - XAresult (*GetSupportedApertureManualSettings) ( - XACameraCapabilitiesItf self, - XAuint32 cameraDeviceID, - XAuint32 * pMinValue, - XAuint32 * pMaxValue, - XAuint32 * pNumSettings, - XAuint32 ** ppSettings - ); - XAresult (*GetSupportedShutterSpeedManualSettings) ( - XACameraCapabilitiesItf self, - XAuint32 cameraDeviceID, - XAmicrosecond * pMinValue, - XAmicrosecond * pMaxValue, - XAuint32 * pNumSettings, - XAmicrosecond ** ppSettings - ); - XAresult (*GetSupportedWhiteBalanceManualSettings) ( - XACameraCapabilitiesItf self, - XAuint32 cameraDeviceID, - XAuint32 * pMinValue, - XAuint32 * pMaxValue, - XAuint32 * pNumSettings, - XAuint32 ** ppSettings - ); - XAresult (*GetSupportedZoomSettings) ( - XACameraCapabilitiesItf self, - XAuint32 cameraDeviceID, - XAboolean digitalEnabled, - XAboolean macroEnabled, - XApermille * pMaxValue, - XAuint32 * pNumSettings, - XApermille ** ppSettings, - XAboolean * pSpeedSupported - - ); -}; - -XA_API extern const XAInterfaceID XA_IID_CAMERA; - -struct XACameraItf_; -typedef const struct XACameraItf_ * const * XACameraItf; - -typedef void (XAAPIENTRY * xaCameraCallback) ( - XACameraItf caller, - void * pContext, - XAuint32 eventId, - XAuint32 eventData -); - -struct XACameraItf_ { - XAresult (*RegisterCallback) ( - XACameraItf self, - xaCameraCallback callback, - void * pContext - ); - XAresult (*SetFlashMode) ( - XACameraItf self, - XAuint32 flashMode - ); - XAresult (*GetFlashMode) ( - XACameraItf self, - XAuint32 * pFlashMode - ); - XAresult (*IsFlashReady) ( - XACameraItf self, - XAboolean * pReady - ); - XAresult (*SetFocusMode) ( - XACameraItf self, - XAuint32 focusMode, - XAmillimeter manualSetting, - XAboolean macroEnabled - ); - XAresult (*GetFocusMode) ( - XACameraItf self, - XAuint32 * pFocusMode, - XAmillimeter * pManualSetting, - XAboolean * pMacroEnabled - ); - XAresult (*SetFocusRegionPattern) ( - XACameraItf self, - XAuint32 focusPattern, - XAuint32 activePoints1, - XAuint32 activePoints2 - ); - XAresult (*GetFocusRegionPattern) ( - XACameraItf self, - XAuint32 * pFocusPattern, - XAuint32 * pActivePoints1, - XAuint32 * pActivePoints2 - ); - XAresult (*GetFocusRegionPositions) ( - XACameraItf self, - XAuint32 * pNumPositionEntries, - XAFocusPointPosition * pFocusPosition - ); - XAresult (*GetFocusModeStatus) ( - XACameraItf self, - XAuint32 * pFocusStatus, - XAuint32 * pRegionStatus1, - XAuint32 * pRegionStatus2 - ); - XAresult (*SetMeteringMode) ( - XACameraItf self, - XAuint32 meteringMode - ); - XAresult (*GetMeteringMode) ( - XACameraItf self, - XAuint32 * pMeteringMode - ); - XAresult (*SetExposureMode) ( - XACameraItf self, - XAuint32 exposure, - XAuint32 compensation - ); - XAresult (*GetExposureMode) ( - XACameraItf self, - XAuint32 * pExposure, - XAuint32 * pCompensation - ); - XAresult (*SetISOSensitivity) ( - XACameraItf self, - XAuint32 isoSensitivity, - XAuint32 manualSetting - ); - XAresult (*GetISOSensitivity) ( - XACameraItf self, - XAuint32 * pIsoSensitivity, - XAuint32 * pManualSetting - ); - XAresult (*SetAperture) ( - XACameraItf self, - XAuint32 aperture, - XAuint32 manualSetting - ); - XAresult (*GetAperture) ( - XACameraItf self, - XAuint32 * pAperture, - XAuint32 * pManualSetting - ); - XAresult (*SetShutterSpeed) ( - XACameraItf self, - XAuint32 shutterSpeed, - XAmicrosecond manualSetting - ); - XAresult (*GetShutterSpeed) ( - XACameraItf self, - XAuint32 * pShutterSpeed, - XAmicrosecond * pManualSetting - ); - XAresult (*SetWhiteBalance) ( - XACameraItf self, - XAuint32 whiteBalance, - XAuint32 manualSetting - ); - XAresult (*GetWhiteBalance) ( - XACameraItf self, - XAuint32 * pWhiteBalance, - XAuint32 * pManualSetting - ); - XAresult (*SetAutoLocks) ( - XACameraItf self, - XAuint32 locks - ); - XAresult (*GetAutoLocks) ( - XACameraItf self, - XAuint32 * locks - ); - XAresult (*SetZoom) ( - XACameraItf self, - XApermille zoom, - XAboolean digitalEnabled, - XAuint32 speed, - XAboolean async - ); - XAresult (*GetZoom) ( - XACameraItf self, - XApermille * pZoom, - XAboolean * pDigital - ); -}; - -/* AUDIO I/O DEVICE CAPABILITIES */ - -#define XA_DEVCONNECTION_INTEGRATED ((XAint16) 0x0001) -#define XA_DEVCONNECTION_ATTACHED_WIRED ((XAint16) 0x0100) -#define XA_DEVCONNECTION_ATTACHED_WIRELESS ((XAint16) 0x0200) -#define XA_DEVCONNECTION_NETWORK ((XAint16) 0x0400) - -#define XA_DEVLOCATION_HANDSET ((XAint16) 0x0001) -#define XA_DEVLOCATION_HEADSET ((XAint16) 0x0002) -#define XA_DEVLOCATION_CARKIT ((XAint16) 0x0003) -#define XA_DEVLOCATION_DOCK ((XAint16) 0x0004) -#define XA_DEVLOCATION_REMOTE ((XAint16) 0x0005) - -#define XA_DEVSCOPE_UNKNOWN ((XAint16) 0x0001) -#define XA_DEVSCOPE_ENVIRONMENT ((XAint16) 0x0002) -#define XA_DEVSCOPE_USER ((XAint16) 0x0003) - -typedef struct XAAudioInputDescriptor_ { - XAchar * deviceName; - XAint16 deviceConnection; - XAint16 deviceScope; - XAint16 deviceLocation; - XAboolean isForTelephony; - XAmilliHertz minSampleRate; - XAmilliHertz maxSampleRate; - XAboolean isFreqRangeContinuous; - XAmilliHertz * samplingRatesSupported; - XAint16 numOfSamplingRatesSupported; - XAint16 maxChannels; -} XAAudioInputDescriptor; - -typedef struct XAAudioOutputDescriptor_ { - XAchar *pDeviceName; - XAint16 deviceConnection; - XAint16 deviceScope; - XAint16 deviceLocation; - XAboolean isForTelephony; - XAmilliHertz minSampleRate; - XAmilliHertz maxSampleRate; - XAboolean isFreqRangeContinuous; - XAmilliHertz *samplingRatesSupported; - XAint16 numOfSamplingRatesSupported; - XAint16 maxChannels; -} XAAudioOutputDescriptor; - -XA_API extern const XAInterfaceID XA_IID_AUDIOIODEVICECAPABILITIES; - -struct XAAudioIODeviceCapabilitiesItf_; -typedef const struct XAAudioIODeviceCapabilitiesItf_ - * const * XAAudioIODeviceCapabilitiesItf; - -typedef void (XAAPIENTRY * xaAvailableAudioInputsChangedCallback) ( - XAAudioIODeviceCapabilitiesItf caller, - void * pContext, - XAuint32 deviceID, - XAint32 numInputs, - XAboolean isNew -); - -typedef void (XAAPIENTRY * xaAvailableAudioOutputsChangedCallback) ( - XAAudioIODeviceCapabilitiesItf caller, - void * pContext, - XAuint32 deviceID, - XAint32 numOutputs, - XAboolean isNew -); - -typedef void (XAAPIENTRY * xaDefaultDeviceIDMapChangedCallback) ( - XAAudioIODeviceCapabilitiesItf caller, - void * pContext, - XAboolean isOutput, - XAint32 numDevices -); - -struct XAAudioIODeviceCapabilitiesItf_ { - XAresult (*GetAvailableAudioInputs) ( - XAAudioIODeviceCapabilitiesItf self, - XAint32 * pNumInputs, - XAuint32 * pInputDeviceIDs - ); - XAresult (*QueryAudioInputCapabilities) ( - XAAudioIODeviceCapabilitiesItf self, - XAuint32 deviceID, - XAAudioInputDescriptor * pDescriptor - ); - XAresult (*RegisterAvailableAudioInputsChangedCallback) ( - XAAudioIODeviceCapabilitiesItf self, - xaAvailableAudioInputsChangedCallback callback, - void * pContext - ); - XAresult (*GetAvailableAudioOutputs) ( - XAAudioIODeviceCapabilitiesItf self, - XAint32 * pNumOutputs, - XAuint32 * pOutputDeviceIDs - ); - XAresult (*QueryAudioOutputCapabilities) ( - XAAudioIODeviceCapabilitiesItf self, - XAuint32 deviceID, - XAAudioOutputDescriptor * pDescriptor - ); - XAresult (*RegisterAvailableAudioOutputsChangedCallback) ( - XAAudioIODeviceCapabilitiesItf self, - xaAvailableAudioOutputsChangedCallback callback, - void * pContext - ); - XAresult (*RegisterDefaultDeviceIDMapChangedCallback) ( - XAAudioIODeviceCapabilitiesItf self, - xaDefaultDeviceIDMapChangedCallback callback, - void * pContext - ); - XAresult (*GetAssociatedAudioInputs) ( - XAAudioIODeviceCapabilitiesItf self, - XAuint32 deviceID, - XAint32 * pNumAudioInputs, - XAuint32 * pAudioInputDeviceIDs - ); - XAresult (*GetAssociatedAudioOutputs) ( - XAAudioIODeviceCapabilitiesItf self, - XAuint32 deviceID, - XAint32 * pNumAudioOutputs, - XAuint32 * pAudioOutputDeviceIDs - ); - XAresult (*GetDefaultAudioDevices) ( - XAAudioIODeviceCapabilitiesItf self, - XAuint32 defaultDeviceID, - XAint32 *pNumAudioDevices, - XAuint32 *pAudioDeviceIDs - ); - XAresult (*QuerySampleFormatsSupported) ( - XAAudioIODeviceCapabilitiesItf self, - XAuint32 deviceID, - XAmilliHertz samplingRate, - XAint32 *pSampleFormats, - XAint32 *pNumOfSampleFormats - ); -}; - -/* DEVICE VOLUME */ - -XA_API extern const XAInterfaceID XA_IID_DEVICEVOLUME; - -struct XADeviceVolumeItf_; -typedef const struct XADeviceVolumeItf_ * const * XADeviceVolumeItf; - -struct XADeviceVolumeItf_ { - XAresult (*GetVolumeScale) ( - XADeviceVolumeItf self, - XAuint32 deviceID, - XAint32 * pMinValue, - XAint32 * pMaxValue, - XAboolean * pIsMillibelScale - ); - XAresult (*SetVolume) ( - XADeviceVolumeItf self, - XAuint32 deviceID, - XAint32 volume - ); - XAresult (*GetVolume) ( - XADeviceVolumeItf self, - XAuint32 deviceID, - XAint32 * pVolume - ); -}; - -/* EQUALIZER */ - -#define XA_EQUALIZER_UNDEFINED ((XAuint16) 0xFFFF) - -XA_API extern const XAInterfaceID XA_IID_EQUALIZER; - -struct XAEqualizerItf_; -typedef const struct XAEqualizerItf_ * const * XAEqualizerItf; - -struct XAEqualizerItf_ { - XAresult (*SetEnabled) ( - XAEqualizerItf self, - XAboolean enabled - ); - XAresult (*IsEnabled) ( - XAEqualizerItf self, - XAboolean * pEnabled - ); - XAresult (*GetNumberOfBands) ( - XAEqualizerItf self, - XAuint16 * pNumBands - ); - XAresult (*GetBandLevelRange) ( - XAEqualizerItf self, - XAmillibel * pMin, - XAmillibel * pMax - ); - XAresult (*SetBandLevel) ( - XAEqualizerItf self, - XAuint16 band, - XAmillibel level - ); - XAresult (*GetBandLevel) ( - XAEqualizerItf self, - XAuint16 band, - XAmillibel * pLevel - ); - XAresult (*GetCenterFreq) ( - XAEqualizerItf self, - XAuint16 band, - XAmilliHertz * pCenter - ); - XAresult (*GetBandFreqRange) ( - XAEqualizerItf self, - XAuint16 band, - XAmilliHertz * pMin, - XAmilliHertz * pMax - ); - XAresult (*GetBand) ( - XAEqualizerItf self, - XAmilliHertz frequency, - XAuint16 * pBand - ); - XAresult (*GetCurrentPreset) ( - XAEqualizerItf self, - XAuint16 * pPreset - ); - XAresult (*UsePreset) ( - XAEqualizerItf self, - XAuint16 index - ); - XAresult (*GetNumberOfPresets) ( - XAEqualizerItf self, - XAuint16 * pNumPresets - ); - XAresult (*GetPresetName) ( - XAEqualizerItf self, - XAuint16 index, - const XAchar ** ppName - ); -}; - -/* OUTPUT MIX */ - -XA_API extern const XAInterfaceID XA_IID_OUTPUTMIX; - -struct XAOutputMixItf_; -typedef const struct XAOutputMixItf_ * const * XAOutputMixItf; - -typedef void (XAAPIENTRY * xaMixDeviceChangeCallback) ( - XAOutputMixItf caller, - void * pContext -); - -struct XAOutputMixItf_ { - XAresult (*GetDestinationOutputDeviceIDs) ( - XAOutputMixItf self, - XAint32 * pNumDevices, - XAuint32 * pDeviceIDs - ); - XAresult (*RegisterDeviceChangeCallback) ( - XAOutputMixItf self, - xaMixDeviceChangeCallback callback, - void * pContext - ); - XAresult (*ReRoute) ( - XAOutputMixItf self, - XAint32 numOutputDevices, - XAuint32 * pOutputDeviceIDs - ); -}; - -/* RADIO */ - -#define XA_FREQRANGE_FMEUROAMERICA ((XAuint8) 0x01) -#define XA_FREQRANGE_FMJAPAN ((XAuint8) 0x02) -#define XA_FREQRANGE_AMLW ((XAuint8) 0x03) -#define XA_FREQRANGE_AMMW ((XAuint8) 0x04) -#define XA_FREQRANGE_AMSW ((XAuint8) 0x05) - -#define XA_RADIO_EVENT_ANTENNA_STATUS_CHANGED ((XAuint32) 0x00000001) -#define XA_RADIO_EVENT_FREQUENCY_CHANGED ((XAuint32) 0x00000002) -#define XA_RADIO_EVENT_FREQUENCY_RANGE_CHANGED ((XAuint32) 0x00000003) -#define XA_RADIO_EVENT_PRESET_CHANGED ((XAuint32) 0x00000004) -#define XA_RADIO_EVENT_SEEK_COMPLETED ((XAuint32) 0x00000005) - -#define XA_STEREOMODE_MONO ((XAuint32) 0x00000000) -#define XA_STEREOMODE_STEREO ((XAuint32) 0x00000001) -#define XA_STEREOMODE_AUTO ((XAuint32) 0x00000002) - -XA_API extern const XAInterfaceID XA_IID_RADIO; - -struct XARadioItf_; -typedef const struct XARadioItf_ * const * XARadioItf; - -typedef void (XAAPIENTRY * xaRadioCallback) ( - XARadioItf caller, - void * pContext, - XAuint32 event, - XAuint32 eventIntData, - XAboolean eventBooleanData -); - -struct XARadioItf_ { - XAresult (*SetFreqRange) ( - XARadioItf self, - XAuint8 range - ); - XAresult (*GetFreqRange) ( - XARadioItf self, - XAuint8 * pRange - ); - XAresult (*IsFreqRangeSupported) ( - XARadioItf self, - XAuint8 range, - XAboolean * pSupported - ); - XAresult (*GetFreqRangeProperties) ( - XARadioItf self, - XAuint8 range, - XAuint32 * pMinFreq, - XAuint32 * pMaxFreq, - XAuint32 * pFreqInterval - ); - XAresult (*SetFrequency) ( - XARadioItf self, - XAuint32 freq - ); - XAresult (*CancelSetFrequency) ( - XARadioItf self - ); - XAresult (*GetFrequency) ( - XARadioItf self, - XAuint32 * pFreq - ); - XAresult (*SetSquelch) ( - XARadioItf self, - XAboolean squelch - ); - XAresult (*GetSquelch) ( - XARadioItf self, - XAboolean * pSquelch - ); - XAresult (*SetStereoMode) ( - XARadioItf self, - XAuint32 mode - ); - XAresult (*GetStereoMode) ( - XARadioItf self, - XAuint32 * pMode - ); - XAresult (*GetSignalStrength) ( - XARadioItf self, - XAuint32 * pStrength - ); - XAresult (*Seek) ( - XARadioItf self, - XAboolean upwards - ); - XAresult (*StopSeeking) ( - XARadioItf self - ); - XAresult (*GetNumberOfPresets) ( - XARadioItf self, - XAuint32 * pNumPresets - ); - XAresult (*SetPreset) ( - XARadioItf self, - XAuint32 preset, - XAuint32 freq, - XAuint8 range, - XAuint32 mode, - const XAchar * pName - ); - XAresult (*GetPreset) ( - XARadioItf self, - XAuint32 preset, - XAuint32 * pFreq, - XAuint8 * pRange, - XAuint32 * pMode, - XAchar * pName, - XAuint16 * pNameLength - ); - XAresult (*RegisterRadioCallback) ( - XARadioItf self, - xaRadioCallback callback, - void * pContext - ); -}; - -/* RDS */ - -#define XA_RDS_EVENT_NEW_PI ((XAuint16) 0x0001) -#define XA_RDS_EVENT_NEW_PTY ((XAuint16) 0x0002) -#define XA_RDS_EVENT_NEW_PS ((XAuint16) 0x0004) -#define XA_RDS_EVENT_NEW_RT ((XAuint16) 0x0008) -#define XA_RDS_EVENT_NEW_RT_PLUS ((XAuint16) 0x0010) -#define XA_RDS_EVENT_NEW_CT ((XAuint16) 0x0020) -#define XA_RDS_EVENT_NEW_TA ((XAuint16) 0x0040) -#define XA_RDS_EVENT_NEW_TP ((XAuint16) 0x0080) -#define XA_RDS_EVENT_NEW_ALARM ((XAuint16) 0x0100) - -#define XA_RDSPROGRAMMETYPE_RDSPTY_NONE \ - ((XAuint32) 0x00000000) -#define XA_RDSPROGRAMMETYPE_RDSPTY_NEWS \ - ((XAuint32) 0x00000001) -#define XA_RDSPROGRAMMETYPE_RDSPTY_CURRENTAFFAIRS \ - ((XAuint32) 0x00000002) -#define XA_RDSPROGRAMMETYPE_RDSPTY_INFORMATION \ - ((XAuint32) 0x00000003) -#define XA_RDSPROGRAMMETYPE_RDSPTY_SPORT \ - ((XAuint32) 0x00000004) -#define XA_RDSPROGRAMMETYPE_RDSPTY_EDUCATION \ - ((XAuint32) 0x00000005) -#define XA_RDSPROGRAMMETYPE_RDSPTY_DRAMA \ - ((XAuint32) 0x00000006) -#define XA_RDSPROGRAMMETYPE_RDSPTY_CULTURE \ - ((XAuint32) 0x00000007) -#define XA_RDSPROGRAMMETYPE_RDSPTY_SCIENCE \ - ((XAuint32) 0x00000008) -#define XA_RDSPROGRAMMETYPE_RDSPTY_VARIEDSPEECH \ - ((XAuint32) 0x00000009) -#define XA_RDSPROGRAMMETYPE_RDSPTY_POPMUSIC \ - ((XAuint32) 0x0000000A) -#define XA_RDSPROGRAMMETYPE_RDSPTY_ROCKMUSIC \ - ((XAuint32) 0x0000000B) -#define XA_RDSPROGRAMMETYPE_RDSPTY_EASYLISTENING \ - ((XAuint32) 0x0000000C) -#define XA_RDSPROGRAMMETYPE_RDSPTY_LIGHTCLASSICAL \ - ((XAuint32) 0x0000000D) -#define XA_RDSPROGRAMMETYPE_RDSPTY_SERIOUSCLASSICAL \ - ((XAuint32) 0x0000000E) -#define XA_RDSPROGRAMMETYPE_RDSPTY_OTHERMUSIC \ - ((XAuint32) 0x0000000F) -#define XA_RDSPROGRAMMETYPE_RDSPTY_WEATHER \ - ((XAuint32) 0x00000010) -#define XA_RDSPROGRAMMETYPE_RDSPTY_FINANCE \ - ((XAuint32) 0x00000011) -#define XA_RDSPROGRAMMETYPE_RDSPTY_CHILDRENSPROGRAMMES \ - ((XAuint32) 0x00000012) -#define XA_RDSPROGRAMMETYPE_RDSPTY_SOCIALAFFAIRS \ - ((XAuint32) 0x00000013) -#define XA_RDSPROGRAMMETYPE_RDSPTY_RELIGION \ - ((XAuint32) 0x00000014) -#define XA_RDSPROGRAMMETYPE_RDSPTY_PHONEIN \ - ((XAuint32) 0x00000015) -#define XA_RDSPROGRAMMETYPE_RDSPTY_TRAVEL \ - ((XAuint32) 0x00000016) -#define XA_RDSPROGRAMMETYPE_RDSPTY_LEISURE \ - ((XAuint32) 0x00000017) -#define XA_RDSPROGRAMMETYPE_RDSPTY_JAZZMUSIC \ - ((XAuint32) 0x00000018) -#define XA_RDSPROGRAMMETYPE_RDSPTY_COUNTRYMUSIC \ - ((XAuint32) 0x00000019) -#define XA_RDSPROGRAMMETYPE_RDSPTY_NATIONALMUSIC \ - ((XAuint32) 0x0000001A) -#define XA_RDSPROGRAMMETYPE_RDSPTY_OLDIESMUSIC \ - ((XAuint32) 0x0000001B) -#define XA_RDSPROGRAMMETYPE_RDSPTY_FOLKMUSIC \ - ((XAuint32) 0x0000001C) -#define XA_RDSPROGRAMMETYPE_RDSPTY_DOCUMENTARY \ - ((XAuint32) 0x0000001D) -#define XA_RDSPROGRAMMETYPE_RDSPTY_ALARMTEST \ - ((XAuint32) 0x0000001E) -#define XA_RDSPROGRAMMETYPE_RDSPTY_ALARM \ - ((XAuint32) 0x0000001F) - -#define XA_RDSPROGRAMMETYPE_RBDSPTY_NONE \ - ((XAuint32) 0x00000000) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_NEWS \ - ((XAuint32) 0x00000001) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_INFORMATION \ - ((XAuint32) 0x00000002) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_SPORTS \ - ((XAuint32) 0x00000003) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_TALK \ - ((XAuint32) 0x00000004) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_ROCK \ - ((XAuint32) 0x00000005) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_CLASSICROCK \ - ((XAuint32) 0x00000006) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_ADULTHITS \ - ((XAuint32) 0x00000007) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_SOFTROCK \ - ((XAuint32) 0x00000008) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_TOP40 \ - ((XAuint32) 0x00000009) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_COUNTRY \ - ((XAuint32) 0x0000000A) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_OLDIES \ - ((XAuint32) 0x0000000B) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_SOFT \ - ((XAuint32) 0x0000000C) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_NOSTALGIA \ - ((XAuint32) 0x0000000D) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_JAZZ \ - ((XAuint32) 0x0000000E) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_CLASSICAL \ - ((XAuint32) 0x0000000F) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_RHYTHMANDBLUES \ - ((XAuint32) 0x00000010) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_SOFTRHYTHMANDBLUES \ - ((XAuint32) 0x00000011) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_LANGUAGE \ - ((XAuint32) 0x00000012) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_RELIGIOUSMUSIC \ - ((XAuint32) 0x00000013) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_RELIGIOUSTALK \ - ((XAuint32) 0x00000014) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_PERSONALITY \ - ((XAuint32) 0x00000015) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_PUBLIC \ - ((XAuint32) 0x00000016) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_COLLEGE \ - ((XAuint32) 0x00000017) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_UNASSIGNED1 \ - ((XAuint32) 0x00000018) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_UNASSIGNED2 \ - ((XAuint32) 0x00000019) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_UNASSIGNED3 \ - ((XAuint32) 0x0000001A) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_UNASSIGNED4 \ - ((XAuint32) 0x0000001B) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_UNASSIGNED5 \ - ((XAuint32) 0x0000001C) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_WEATHER \ - ((XAuint32) 0x0000001D) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_EMERGENCYTEST \ - ((XAuint32) 0x0000001E) -#define XA_RDSPROGRAMMETYPE_RBDSPTY_EMERGENCY \ - ((XAuint32) 0x0000001F) - -#define XA_RDSRTPLUS_ITEMTITLE ((XAuint8) 0x01) -#define XA_RDSRTPLUS_ITEMALBUM ((XAuint8) 0x02) -#define XA_RDSRTPLUS_ITEMTRACKNUMBER ((XAuint8) 0x03) -#define XA_RDSRTPLUS_ITEMARTIST ((XAuint8) 0x04) -#define XA_RDSRTPLUS_ITEMCOMPOSITION ((XAuint8) 0x05) -#define XA_RDSRTPLUS_ITEMMOVEMENT ((XAuint8) 0x06) -#define XA_RDSRTPLUS_ITEMCONDUCTOR ((XAuint8) 0x07) -#define XA_RDSRTPLUS_ITEMCOMPOSER ((XAuint8) 0x08) -#define XA_RDSRTPLUS_ITEMBAND ((XAuint8) 0x09) -#define XA_RDSRTPLUS_ITEMCOMMENT ((XAuint8) 0x0A) -#define XA_RDSRTPLUS_ITEMGENRE ((XAuint8) 0x0B) -#define XA_RDSRTPLUS_INFONEWS ((XAuint8) 0x0C) -#define XA_RDSRTPLUS_INFONEWSLOCAL ((XAuint8) 0x0D) -#define XA_RDSRTPLUS_INFOSTOCKMARKET ((XAuint8) 0x0E) -#define XA_RDSRTPLUS_INFOSPORT ((XAuint8) 0x0F) -#define XA_RDSRTPLUS_INFOLOTTERY ((XAuint8) 0x10) -#define XA_RDSRTPLUS_INFOHOROSCOPE ((XAuint8) 0x11) -#define XA_RDSRTPLUS_INFODAILYDIVERSION ((XAuint8) 0x12) -#define XA_RDSRTPLUS_INFOHEALTH ((XAuint8) 0x13) -#define XA_RDSRTPLUS_INFOEVENT ((XAuint8) 0x14) -#define XA_RDSRTPLUS_INFOSZENE ((XAuint8) 0x15) -#define XA_RDSRTPLUS_INFOCINEMA ((XAuint8) 0x16) -#define XA_RDSRTPLUS_INFOTV ((XAuint8) 0x17) -#define XA_RDSRTPLUS_INFODATETIME ((XAuint8) 0x18) -#define XA_RDSRTPLUS_INFOWEATHER ((XAuint8) 0x19) -#define XA_RDSRTPLUS_INFOTRAFFIC ((XAuint8) 0x1A) -#define XA_RDSRTPLUS_INFOALARM ((XAuint8) 0x1B) -#define XA_RDSRTPLUS_INFOADVISERTISEMENT ((XAuint8) 0x1C) -#define XA_RDSRTPLUS_INFOURL ((XAuint8) 0x1D) -#define XA_RDSRTPLUS_INFOOTHER ((XAuint8) 0x1E) -#define XA_RDSRTPLUS_STATIONNAMESHORT ((XAuint8) 0x1F) -#define XA_RDSRTPLUS_STATIONNAMELONG ((XAuint8) 0x20) -#define XA_RDSRTPLUS_PROGRAMNOW ((XAuint8) 0x21) -#define XA_RDSRTPLUS_PROGRAMNEXT ((XAuint8) 0x22) -#define XA_RDSRTPLUS_PROGRAMPART ((XAuint8) 0x23) -#define XA_RDSRTPLUS_PROGRAMHOST ((XAuint8) 0x24) -#define XA_RDSRTPLUS_PROFRAMEDITORIALSTAFF ((XAuint8) 0x25) -#define XA_RDSRTPLUS_PROGRAMFREQUENCY ((XAuint8) 0x26) -#define XA_RDSRTPLUS_PROGRAMHOMEPAGE ((XAuint8) 0x27) -#define XA_RDSRTPLUS_PROGRAMSUBCHANNEL ((XAuint8) 0x28) -#define XA_RDSRTPLUS_PHONEHOTLINE ((XAuint8) 0x29) -#define XA_RDSRTPLUS_PHONESTUDIO ((XAuint8) 0x2A) -#define XA_RDSRTPLUS_PHONEOTHER ((XAuint8) 0x2B) -#define XA_RDSRTPLUS_SMSSTUDIO ((XAuint8) 0x2C) -#define XA_RDSRTPLUS_SMSOTHER ((XAuint8) 0x2D) -#define XA_RDSRTPLUS_EMAILHOTLINE ((XAuint8) 0x2E) -#define XA_RDSRTPLUS_EMAILSTUDIO ((XAuint8) 0x2F) -#define XA_RDSRTPLUS_EMAILOTHER ((XAuint8) 0x30) -#define XA_RDSRTPLUS_MMSOTHER ((XAuint8) 0x31) -#define XA_RDSRTPLUS_CHAT ((XAuint8) 0x32) -#define XA_RDSRTPLUS_CHATCENTER ((XAuint8) 0x33) -#define XA_RDSRTPLUS_VOTEQUESTION ((XAuint8) 0x34) -#define XA_RDSRTPLUS_VOTECENTER ((XAuint8) 0x35) -#define XA_RDSRTPLUS_OPENCLASS45 ((XAuint8) 0x36) -#define XA_RDSRTPLUS_OPENCLASS55 ((XAuint8) 0x37) -#define XA_RDSRTPLUS_OPENCLASS56 ((XAuint8) 0x38) -#define XA_RDSRTPLUS_OPENCLASS57 ((XAuint8) 0x39) -#define XA_RDSRTPLUS_OPENCLASS58 ((XAuint8) 0x3A) -#define XA_RDSRTPLUS_PLACE ((XAuint8) 0x3B) -#define XA_RDSRTPLUS_APPOINTMENT ((XAuint8) 0x3C) -#define XA_RDSRTPLUS_IDENTIFIER ((XAuint8) 0x3D) -#define XA_RDSRTPLUS_PURCHASE ((XAuint8) 0x3E) -#define XA_RDSRTPLUS_GETDATA ((XAuint8) 0x3F) - -XA_API extern const XAInterfaceID XA_IID_RDS; - -struct XARDSItf_; -typedef const struct XARDSItf_ * const * XARDSItf; - -typedef void (XAAPIENTRY * xaGetODAGroupCallback) ( - XARadioItf caller, - void * pContext, - XAboolean success, - XAint16 group, - XAuint16 message -); - -typedef void (XAAPIENTRY * xaNewODADataCallback) ( - XARDSItf caller, - void * pContext, - XAint16 group, - XAuint64 data -); - -typedef void (XAAPIENTRY * xaRDSCallback) ( - XARDSItf caller, - void * pContext, - XAuint16 event, - XAuint8 eventData -); - -struct XARDSItf_ { - XAresult (*QueryRDSSignal) ( - XARDSItf self, - XAboolean * isSignal - ); - XAresult (*GetProgrammeServiceName) ( - XARDSItf self, - XAchar * ps - ); - XAresult (*GetRadioText) ( - XARDSItf self, - XAchar * rt - ); - XAresult (*GetRadioTextPlus) ( - XARDSItf self, - XAuint8 contentType, - XAchar * informationElement, - XAchar * descriptor, - XAuint8 * descriptorContentType - ); - XAresult (*GetProgrammeType) ( - XARDSItf self, - XAuint32 * pty - ); - XAresult (*GetProgrammeTypeString) ( - XARDSItf self, - XAboolean isLengthMax16, - XAchar * pty - ); - XAresult (*GetProgrammeIdentificationCode) ( - XARDSItf self, - XAint16 * pi - ); - XAresult (*GetClockTime) ( - XARDSItf self, - XAtime * dateAndTime - ); - XAresult (*GetTrafficAnnouncement) ( - XARDSItf self, - XAboolean * ta - ); - XAresult (*GetTrafficProgramme) ( - XARDSItf self, - XAboolean * tp - ); - XAresult (*SeekByProgrammeType) ( - XARDSItf self, - XAuint32 pty, - XAboolean upwards - ); - XAresult (*SeekTrafficAnnouncement) ( - XARDSItf self, - XAboolean upwards - ); - XAresult (*SeekTrafficProgramme) ( - XARDSItf self, - XAboolean upwards - ); - XAresult (*SetAutomaticSwitching) ( - XARDSItf self, - XAboolean automatic - ); - XAresult (*GetAutomaticSwitching) ( - XARDSItf self, - XAboolean * automatic - ); - XAresult (*SetAutomaticTrafficAnnouncement) ( - XARDSItf self, - XAboolean automatic - ); - XAresult (*GetAutomaticTrafficAnnouncement) ( - XARDSItf self, - XAboolean * automatic - ); - XAresult (*GetODAGroup) ( - XARDSItf self, - XAuint16 AID, - xaGetODAGroupCallback callback, - void * pContext - ); - XAresult (*SubscribeODAGroup) ( - XARDSItf self, - XAint16 group, - XAboolean useErrorCorrection - ); - XAresult (*UnsubscribeODAGroup) ( - XARDSItf self, - XAint16 group - ); - XAresult (*ListODAGroupSubscriptions) ( - XARDSItf self, - XAint16* pGroups, - XAuint32* pLength - ); - XAresult (*RegisterRDSCallback) ( - XARDSItf self, - xaRDSCallback callback, - void * pContext - ); - XAresult (*RegisterODADataCallback) ( - XARDSItf self, - xaNewODADataCallback callback, - void * pContext - ); -}; - -/* VIBRA */ - -XA_API extern const XAInterfaceID XA_IID_VIBRA; - -struct XAVibraItf_; -typedef const struct XAVibraItf_ * const * XAVibraItf; - -struct XAVibraItf_ { - XAresult (*Vibrate) ( - XAVibraItf self, - XAboolean vibrate - ); - XAresult (*IsVibrating) ( - XAVibraItf self, - XAboolean * pVibrating - ); - XAresult (*SetFrequency) ( - XAVibraItf self, - XAmilliHertz frequency - ); - XAresult (*GetFrequency) ( - XAVibraItf self, - XAmilliHertz * pFrequency - ); - XAresult (*SetIntensity) ( - XAVibraItf self, - XApermille intensity - ); - XAresult (*GetIntensity) ( - XAVibraItf self, - XApermille * pIntensity - ); -}; - -/* LED ARRAY */ - -typedef struct XAHSL_ { - XAmillidegree hue; - XApermille saturation; - XApermille lightness; -} XAHSL; - -XA_API extern const XAInterfaceID XA_IID_LED; - -struct XALEDArrayItf_; -typedef const struct XALEDArrayItf_ * const * XALEDArrayItf; - -struct XALEDArrayItf_ { - XAresult (*ActivateLEDArray) ( - XALEDArrayItf self, - XAuint32 lightMask - ); - XAresult (*IsLEDArrayActivated) ( - XALEDArrayItf self, - XAuint32 * pLightMask - ); - XAresult (*SetColor) ( - XALEDArrayItf self, - XAuint8 index, - const XAHSL * pColor - ); - XAresult (*GetColor) ( - XALEDArrayItf self, - XAuint8 index, - XAHSL * pColor - ); -}; - - - - /*****************************************************************/ - /* CODEC RELATED INTERFACES, STRUCTS AND DEFINES */ - /*****************************************************************/ - -/* AUDIO ENCODER AND AUDIO ENCODER/DECODER CAPABILITIES */ - -#define XA_RATECONTROLMODE_CONSTANTBITRATE ((XAuint32) 0x00000001) -#define XA_RATECONTROLMODE_VARIABLEBITRATE ((XAuint32) 0x00000002) - -#define XA_AUDIOCODEC_PCM ((XAuint32) 0x00000001) -#define XA_AUDIOCODEC_MP3 ((XAuint32) 0x00000002) -#define XA_AUDIOCODEC_AMR ((XAuint32) 0x00000003) -#define XA_AUDIOCODEC_AMRWB ((XAuint32) 0x00000004) -#define XA_AUDIOCODEC_AMRWBPLUS ((XAuint32) 0x00000005) -#define XA_AUDIOCODEC_AAC ((XAuint32) 0x00000006) -#define XA_AUDIOCODEC_WMA ((XAuint32) 0x00000007) -#define XA_AUDIOCODEC_REAL ((XAuint32) 0x00000008) -#define XA_AUDIOCODEC_VORBIS ((XAuint32) 0x00000009) - -#define XA_AUDIOPROFILE_PCM ((XAuint32) 0x00000001) - -#define XA_AUDIOPROFILE_MPEG1_L3 ((XAuint32) 0x00000001) -#define XA_AUDIOPROFILE_MPEG2_L3 ((XAuint32) 0x00000002) -#define XA_AUDIOPROFILE_MPEG25_L3 ((XAuint32) 0x00000003) - -#define XA_AUDIOCHANMODE_MP3_MONO ((XAuint32) 0x00000001) -#define XA_AUDIOCHANMODE_MP3_STEREO ((XAuint32) 0x00000002) -#define XA_AUDIOCHANMODE_MP3_JOINTSTEREO ((XAuint32) 0x00000003) -#define XA_AUDIOCHANMODE_MP3_DUAL ((XAuint32) 0x00000004) - -#define XA_AUDIOPROFILE_AMR ((XAuint32) 0x00000001) - -#define XA_AUDIOSTREAMFORMAT_CONFORMANCE ((XAuint32) 0x00000001) -#define XA_AUDIOSTREAMFORMAT_IF1 ((XAuint32) 0x00000002) -#define XA_AUDIOSTREAMFORMAT_IF2 ((XAuint32) 0x00000003) -#define XA_AUDIOSTREAMFORMAT_FSF ((XAuint32) 0x00000004) -#define XA_AUDIOSTREAMFORMAT_RTPPAYLOAD ((XAuint32) 0x00000005) -#define XA_AUDIOSTREAMFORMAT_ITU ((XAuint32) 0x00000006) - -#define XA_AUDIOPROFILE_AMRWB ((XAuint32) 0x00000001) - -#define XA_AUDIOPROFILE_AMRWBPLUS ((XAuint32) 0x00000001) - -#define XA_AUDIOPROFILE_AAC_AAC ((XAuint32) 0x00000001) - -#define XA_AUDIOMODE_AAC_MAIN ((XAuint32) 0x00000001) -#define XA_AUDIOMODE_AAC_LC ((XAuint32) 0x00000002) -#define XA_AUDIOMODE_AAC_SSR ((XAuint32) 0x00000003) -#define XA_AUDIOMODE_AAC_LTP ((XAuint32) 0x00000004) -#define XA_AUDIOMODE_AAC_HE ((XAuint32) 0x00000005) -#define XA_AUDIOMODE_AAC_SCALABLE ((XAuint32) 0x00000006) -#define XA_AUDIOMODE_AAC_ERLC ((XAuint32) 0x00000007) -#define XA_AUDIOMODE_AAC_LD ((XAuint32) 0x00000008) -#define XA_AUDIOMODE_AAC_HE_PS ((XAuint32) 0x00000009) -#define XA_AUDIOMODE_AAC_HE_MPS ((XAuint32) 0x0000000A) - -#define XA_AUDIOSTREAMFORMAT_MP2ADTS ((XAuint32) 0x00000001) -#define XA_AUDIOSTREAMFORMAT_MP4ADTS ((XAuint32) 0x00000002) -#define XA_AUDIOSTREAMFORMAT_MP4LOAS ((XAuint32) 0x00000003) -#define XA_AUDIOSTREAMFORMAT_MP4LATM ((XAuint32) 0x00000004) -#define XA_AUDIOSTREAMFORMAT_ADIF ((XAuint32) 0x00000005) -#define XA_AUDIOSTREAMFORMAT_MP4FF ((XAuint32) 0x00000006) -#define XA_AUDIOSTREAMFORMAT_RAW ((XAuint32) 0x00000007) - -#define XA_AUDIOPROFILE_WMA7 ((XAuint32) 0x00000001) -#define XA_AUDIOPROFILE_WMA8 ((XAuint32) 0x00000002) -#define XA_AUDIOPROFILE_WMA9 ((XAuint32) 0x00000003) -#define XA_AUDIOPROFILE_WMA10 ((XAuint32) 0x00000004) - -#define XA_AUDIOMODE_WMA_LEVEL1 ((XAuint32) 0x00000001) -#define XA_AUDIOMODE_WMA_LEVEL2 ((XAuint32) 0x00000002) -#define XA_AUDIOMODE_WMA_LEVEL3 ((XAuint32) 0x00000003) -#define XA_AUDIOMODE_WMA_LEVEL4 ((XAuint32) 0x00000004) -#define XA_AUDIOMODE_WMAPRO_LEVELM0 ((XAuint32) 0x00000005) -#define XA_AUDIOMODE_WMAPRO_LEVELM1 ((XAuint32) 0x00000006) -#define XA_AUDIOMODE_WMAPRO_LEVELM2 ((XAuint32) 0x00000007) -#define XA_AUDIOMODE_WMAPRO_LEVELM3 ((XAuint32) 0x00000008) - -#define XA_AUDIOPROFILE_REALAUDIO ((XAuint32) 0x00000001) - -#define XA_AUDIOMODE_REALAUDIO_G2 ((XAuint32) 0x00000001) -#define XA_AUDIOMODE_REALAUDIO_8 ((XAuint32) 0x00000002) -#define XA_AUDIOMODE_REALAUDIO_10 ((XAuint32) 0x00000003) -#define XA_AUDIOMODE_REALAUDIO_SURROUND ((XAuint32) 0x00000004) - -#define XA_AUDIOPROFILE_VORBIS ((XAuint32) 0x00000001) - -#define XA_AUDIOMODE_VORBIS ((XAuint32) 0x00000001) - - -typedef struct XAAudioCodecDescriptor_ { - XAuint32 maxChannels; - XAuint32 minBitsPerSample; - XAuint32 maxBitsPerSample; - XAmilliHertz minSampleRate; - XAmilliHertz maxSampleRate; - XAboolean isFreqRangeContinuous; - XAmilliHertz * pSampleRatesSupported; - XAuint32 numSampleRatesSupported; - XAuint32 minBitRate; - XAuint32 maxBitRate; - XAboolean isBitrateRangeContinuous; - XAuint32 * pBitratesSupported; - XAuint32 numBitratesSupported; - XAuint32 profileSetting; - XAuint32 modeSetting; -} XAAudioCodecDescriptor; - -typedef struct XAAudioEncoderSettings_ { - XAuint32 encoderId; - XAuint32 channelsIn; - XAuint32 channelsOut; - XAmilliHertz sampleRate; - XAuint32 bitRate; - XAuint32 bitsPerSample; - XAuint32 rateControl; - XAuint32 profileSetting; - XAuint32 levelSetting; - XAuint32 channelMode; - XAuint32 streamFormat; - XAuint32 encodeOptions; - XAuint32 blockAlignment; -} XAAudioEncoderSettings; - -XA_API extern const XAInterfaceID XA_IID_AUDIODECODERCAPABILITIES; - -struct XAAudioDecoderCapabilitiesItf_; -typedef const struct XAAudioDecoderCapabilitiesItf_ - * const * XAAudioDecoderCapabilitiesItf; - -struct XAAudioDecoderCapabilitiesItf_ { - XAresult (*GetAudioDecoders) ( - XAAudioDecoderCapabilitiesItf self, - XAuint32 * pNumDecoders, - XAuint32 * pDecoderIds - ); - XAresult (*GetAudioDecoderCapabilities) ( - XAAudioDecoderCapabilitiesItf self, - XAuint32 decoderId, - XAuint32 * pIndex, - XAAudioCodecDescriptor * pDescriptor - ); -}; - -XA_API extern const XAInterfaceID XA_IID_AUDIOENCODER; - -struct XAAudioEncoderItf_; -typedef const struct XAAudioEncoderItf_ * const * XAAudioEncoderItf; - -struct XAAudioEncoderItf_ { - XAresult (*SetEncoderSettings) ( - XAAudioEncoderItf self, - XAAudioEncoderSettings * pSettings - ); - XAresult (*GetEncoderSettings) ( - XAAudioEncoderItf self, - XAAudioEncoderSettings * pSettings - ); -}; - -XA_API extern const XAInterfaceID XA_IID_AUDIOENCODERCAPABILITIES; - -struct XAAudioEncoderCapabilitiesItf_; -typedef const struct XAAudioEncoderCapabilitiesItf_ - * const * XAAudioEncoderCapabilitiesItf; - -struct XAAudioEncoderCapabilitiesItf_ { - XAresult (*GetAudioEncoders) ( - XAAudioEncoderCapabilitiesItf self, - XAuint32 * pNumEncoders, - XAuint32 * pEncoderIds - ); - XAresult (*GetAudioEncoderCapabilities) ( - XAAudioEncoderCapabilitiesItf self, - XAuint32 encoderId, - XAuint32 * pIndex, - XAAudioCodecDescriptor * pDescriptor - ); -}; - -/* IMAGE ENCODER AND IMAGE ENCODER/DECODER CAPABILITIES */ - -#define XA_IMAGECODEC_JPEG ((XAuint32) 0x00000001) -#define XA_IMAGECODEC_GIF ((XAuint32) 0x00000002) -#define XA_IMAGECODEC_BMP ((XAuint32) 0x00000003) -#define XA_IMAGECODEC_PNG ((XAuint32) 0x00000004) -#define XA_IMAGECODEC_TIFF ((XAuint32) 0x00000005) -#define XA_IMAGECODEC_RAW ((XAuint32) 0x00000006) - -typedef struct XAImageCodecDescriptor_ { - XAuint32 codecId; - XAuint32 maxWidth; - XAuint32 maxHeight; -} XAImageCodecDescriptor; - -typedef struct XAImageSettings_ { - XAuint32 encoderId; - XAuint32 width; - XAuint32 height; - XApermille compressionLevel; - XAuint32 colorFormat; -} XAImageSettings; - -XA_API extern const XAInterfaceID XA_IID_IMAGEENCODERCAPABILITIES; - -struct XAImageEncoderCapabilitiesItf_; -typedef const struct XAImageEncoderCapabilitiesItf_ - * const * XAImageEncoderCapabilitiesItf; - -struct XAImageEncoderCapabilitiesItf_ { - XAresult (*GetImageEncoderCapabilities) ( - XAImageEncoderCapabilitiesItf self, - XAuint32 * pEncoderId, - XAImageCodecDescriptor * pDescriptor - ); - XAresult (*QueryColorFormats) ( - const XAImageEncoderCapabilitiesItf self, - XAuint32 * pIndex, - XAuint32 * pColorFormat - ); -}; - -XA_API extern const XAInterfaceID XA_IID_IMAGEDECODERCAPABILITIES; - -struct XAImageDecoderCapabilitiesItf_; -typedef const struct XAImageDecoderCapabilitiesItf_ - * const * XAImageDecoderCapabilitiesItf; - -struct XAImageDecoderCapabilitiesItf_ { - XAresult (*GetImageDecoderCapabilities) ( - XAImageDecoderCapabilitiesItf self, - XAuint32 * pDecoderId, - XAImageCodecDescriptor * pDescriptor - ); - XAresult (*QueryColorFormats) ( - const XAImageDecoderCapabilitiesItf self, - XAuint32 * pIndex, - XAuint32 * pColorFormat - ); -}; - -XA_API extern const XAInterfaceID XA_IID_IMAGEENCODER; - -struct XAImageEncoderItf_; -typedef const struct XAImageEncoderItf_ * const * XAImageEncoderItf; - -struct XAImageEncoderItf_ { - XAresult (*SetImageSettings) ( - XAImageEncoderItf self, - const XAImageSettings * pSettings - ); - XAresult (*GetImageSettings) ( - XAImageEncoderItf self, - XAImageSettings * pSettings - ); - XAresult (*GetSizeEstimate) ( - XAImageEncoderItf self, - XAuint32 * pSize - ); -}; - -/* VIDEO ENCODER AND VIDEO ENCODER/DECODER CAPABILITIES */ - -#define XA_VIDEOCODEC_MPEG2 ((XAuint32) 0x00000001) -#define XA_VIDEOCODEC_H263 ((XAuint32) 0x00000002) -#define XA_VIDEOCODEC_MPEG4 ((XAuint32) 0x00000003) -#define XA_VIDEOCODEC_AVC ((XAuint32) 0x00000004) -#define XA_VIDEOCODEC_VC1 ((XAuint32) 0x00000005) - -#define XA_VIDEOPROFILE_MPEG2_SIMPLE ((XAuint32) 0x00000001) -#define XA_VIDEOPROFILE_MPEG2_MAIN ((XAuint32) 0x00000002) -#define XA_VIDEOPROFILE_MPEG2_422 ((XAuint32) 0x00000003) -#define XA_VIDEOPROFILE_MPEG2_SNR ((XAuint32) 0x00000004) -#define XA_VIDEOPROFILE_MPEG2_SPATIAL ((XAuint32) 0x00000005) -#define XA_VIDEOPROFILE_MPEG2_HIGH ((XAuint32) 0x00000006) - -#define XA_VIDEOLEVEL_MPEG2_LL ((XAuint32) 0x00000001) -#define XA_VIDEOLEVEL_MPEG2_ML ((XAuint32) 0x00000002) -#define XA_VIDEOLEVEL_MPEG2_H14 ((XAuint32) 0x00000003) -#define XA_VIDEOLEVEL_MPEG2_HL ((XAuint32) 0x00000004) - -#define XA_VIDEOPROFILE_H263_BASELINE ((XAuint32) 0x00000001) -#define XA_VIDEOPROFILE_H263_H320CODING ((XAuint32) 0x00000002) -#define XA_VIDEOPROFILE_H263_BACKWARDCOMPATIBLE ((XAuint32) 0x00000003) -#define XA_VIDEOPROFILE_H263_ISWV2 ((XAuint32) 0x00000004) -#define XA_VIDEOPROFILE_H263_ISWV3 ((XAuint32) 0x00000005) -#define XA_VIDEOPROFILE_H263_HIGHCOMPRESSION ((XAuint32) 0x00000006) -#define XA_VIDEOPROFILE_H263_INTERNET ((XAuint32) 0x00000007) -#define XA_VIDEOPROFILE_H263_INTERLACE ((XAuint32) 0x00000008) -#define XA_VIDEOPROFILE_H263_HIGHLATENCY ((XAuint32) 0x00000009) - -#define XA_VIDEOLEVEL_H263_10 ((XAuint32) 0x00000001) -#define XA_VIDEOLEVEL_H263_20 ((XAuint32) 0x00000002) -#define XA_VIDEOLEVEL_H263_30 ((XAuint32) 0x00000003) -#define XA_VIDEOLEVEL_H263_40 ((XAuint32) 0x00000004) -#define XA_VIDEOLEVEL_H263_45 ((XAuint32) 0x00000005) -#define XA_VIDEOLEVEL_H263_50 ((XAuint32) 0x00000006) -#define XA_VIDEOLEVEL_H263_60 ((XAuint32) 0x00000007) -#define XA_VIDEOLEVEL_H263_70 ((XAuint32) 0x00000008) - -#define XA_VIDEOPROFILE_MPEG4_SIMPLE ((XAuint32) 0x00000001) -#define XA_VIDEOPROFILE_MPEG4_SIMPLESCALABLE ((XAuint32) 0x00000002) -#define XA_VIDEOPROFILE_MPEG4_CORE ((XAuint32) 0x00000003) -#define XA_VIDEOPROFILE_MPEG4_MAIN ((XAuint32) 0x00000004) -#define XA_VIDEOPROFILE_MPEG4_NBIT ((XAuint32) 0x00000005) -#define XA_VIDEOPROFILE_MPEG4_SCALABLETEXTURE ((XAuint32) 0x00000006) -#define XA_VIDEOPROFILE_MPEG4_SIMPLEFACE ((XAuint32) 0x00000007) -#define XA_VIDEOPROFILE_MPEG4_SIMPLEFBA ((XAuint32) 0x00000008) -#define XA_VIDEOPROFILE_MPEG4_BASICANIMATED ((XAuint32) 0x00000009) -#define XA_VIDEOPROFILE_MPEG4_HYBRID ((XAuint32) 0x0000000A) -#define XA_VIDEOPROFILE_MPEG4_ADVANCEDREALTIME ((XAuint32) 0x0000000B) -#define XA_VIDEOPROFILE_MPEG4_CORESCALABLE ((XAuint32) 0x0000000C) -#define XA_VIDEOPROFILE_MPEG4_ADVANCEDCODING ((XAuint32) 0x0000000D) -#define XA_VIDEOPROFILE_MPEG4_ADVANCEDCORE ((XAuint32) 0x0000000E) -#define XA_VIDEOPROFILE_MPEG4_ADVANCEDSCALABLE ((XAuint32) 0x0000000F) - -#define XA_VIDEOLEVEL_MPEG4_0 ((XAuint32) 0x00000001) -#define XA_VIDEOLEVEL_MPEG4_0b ((XAuint32) 0x00000002) -#define XA_VIDEOLEVEL_MPEG4_1 ((XAuint32) 0x00000003) -#define XA_VIDEOLEVEL_MPEG4_2 ((XAuint32) 0x00000004) -#define XA_VIDEOLEVEL_MPEG4_3 ((XAuint32) 0x00000005) -#define XA_VIDEOLEVEL_MPEG4_4 ((XAuint32) 0x00000006) -#define XA_VIDEOLEVEL_MPEG4_4a ((XAuint32) 0x00000007) -#define XA_VIDEOLEVEL_MPEG4_5 ((XAuint32) 0x00000008) - -#define XA_VIDEOPROFILE_AVC_BASELINE ((XAuint32) 0x00000001) -#define XA_VIDEOPROFILE_AVC_MAIN ((XAuint32) 0x00000002) -#define XA_VIDEOPROFILE_AVC_EXTENDED ((XAuint32) 0x00000003) -#define XA_VIDEOPROFILE_AVC_HIGH ((XAuint32) 0x00000004) -#define XA_VIDEOPROFILE_AVC_HIGH10 ((XAuint32) 0x00000005) -#define XA_VIDEOPROFILE_AVC_HIGH422 ((XAuint32) 0x00000006) -#define XA_VIDEOPROFILE_AVC_HIGH444 ((XAuint32) 0x00000007) - -#define XA_VIDEOLEVEL_AVC_1 ((XAuint32) 0x00000001) -#define XA_VIDEOLEVEL_AVC_1B ((XAuint32) 0x00000002) -#define XA_VIDEOLEVEL_AVC_11 ((XAuint32) 0x00000003) -#define XA_VIDEOLEVEL_AVC_12 ((XAuint32) 0x00000004) -#define XA_VIDEOLEVEL_AVC_13 ((XAuint32) 0x00000005) -#define XA_VIDEOLEVEL_AVC_2 ((XAuint32) 0x00000006) -#define XA_VIDEOLEVEL_AVC_21 ((XAuint32) 0x00000007) -#define XA_VIDEOLEVEL_AVC_22 ((XAuint32) 0x00000008) -#define XA_VIDEOLEVEL_AVC_3 ((XAuint32) 0x00000009) -#define XA_VIDEOLEVEL_AVC_31 ((XAuint32) 0x0000000A) -#define XA_VIDEOLEVEL_AVC_32 ((XAuint32) 0x0000000B) -#define XA_VIDEOLEVEL_AVC_4 ((XAuint32) 0x0000000C) -#define XA_VIDEOLEVEL_AVC_41 ((XAuint32) 0x0000000D) -#define XA_VIDEOLEVEL_AVC_42 ((XAuint32) 0x0000000E) -#define XA_VIDEOLEVEL_AVC_5 ((XAuint32) 0x0000000F) -#define XA_VIDEOLEVEL_AVC_51 ((XAuint32) 0x00000010) - -#define XA_VIDEOLEVEL_VC1_SIMPLE ((XAuint32) 0x00000001) -#define XA_VIDEOLEVEL_VC1_MAIN ((XAuint32) 0x00000002) -#define XA_VIDEOLEVEL_VC1_ADVANCED ((XAuint32) 0x00000003) - -#define XA_VIDEOLEVEL_VC1_LOW ((XAuint32) 0x00000001) -#define XA_VIDEOLEVEL_VC1_MEDIUM ((XAuint32) 0x00000002) -#define XA_VIDEOLEVEL_VC1_HIGH ((XAuint32) 0x00000003) -#define XA_VIDEOLEVEL_VC1_L0 ((XAuint32) 0x00000004) -#define XA_VIDEOLEVEL_VC1_L1 ((XAuint32) 0x00000005) -#define XA_VIDEOLEVEL_VC1_L2 ((XAuint32) 0x00000006) -#define XA_VIDEOLEVEL_VC1_L3 ((XAuint32) 0x00000007) -#define XA_VIDEOLEVEL_VC1_L4 ((XAuint32) 0x00000008) - -typedef struct XAVideoCodecDescriptor_ { - XAuint32 codecId; - XAuint32 maxWidth; - XAuint32 maxHeight; - XAuint32 maxFrameRate; - XAuint32 maxBitRate; - XAuint32 rateControlSupported; - XAuint32 profileSetting; - XAuint32 levelSetting; -} XAVideoCodecDescriptor; - -typedef struct XAVideoSettings_ { - XAuint32 encoderId; - XAuint32 width; - XAuint32 height; - XAuint32 frameRate; - XAuint32 bitRate; - XAuint32 rateControl; - XAuint32 profileSetting; - XAuint32 levelSetting; - XAuint32 keyFrameInterval; -} XAVideoSettings; - -XA_API extern const XAInterfaceID XA_IID_VIDEODECODERCAPABILITIES; - -struct XAVideoDecoderCapabilitiesItf_; -typedef const struct XAVideoDecoderCapabilitiesItf_ - * const * XAVideoDecoderCapabilitiesItf; - -struct XAVideoDecoderCapabilitiesItf_ { - XAresult (*GetVideoDecoders) ( - XAVideoDecoderCapabilitiesItf self, - XAuint32 * pNumDecoders, - XAuint32 * pDecoderIds - ); - XAresult (*GetVideoDecoderCapabilities) ( - XAVideoDecoderCapabilitiesItf self, - XAuint32 decoderId, - XAuint32 * pIndex, - XAVideoCodecDescriptor * pDescriptor - ); -}; - -XA_API extern const XAInterfaceID XA_IID_VIDEOENCODER; - -XA_API extern const XAInterfaceID XA_IID_VIDEOENCODERCAPABILITIES; - -struct XAVideoEncoderCapabilitiesItf_; -typedef const struct XAVideoEncoderCapabilitiesItf_ - * const * XAVideoEncoderCapabilitiesItf; - -struct XAVideoEncoderCapabilitiesItf_ { - XAresult (*GetVideoEncoders) ( - XAVideoEncoderCapabilitiesItf self, - XAuint32 * pNumEncoders, - XAuint32 * pEncoderIds - ); - XAresult (*GetVideoEncoderCapabilities) ( - XAVideoEncoderCapabilitiesItf self, - XAuint32 encoderId, - XAuint32 * pIndex, - XAVideoCodecDescriptor * pDescriptor - ); -}; - -struct XAVideoEncoderItf_; -typedef const struct XAVideoEncoderItf_ * const * XAVideoEncoderItf; - -struct XAVideoEncoderItf_ { - XAresult (*SetVideoSettings) ( - XAVideoEncoderItf self, - XAVideoSettings * pSettings - ); - XAresult (*GetVideoSettings) ( - XAVideoEncoderItf self, - XAVideoSettings * pSettings - ); -}; - -/* STREAM INFORMATION */ - -#define XA_DOMAINTYPE_AUDIO 0x00000001 -#define XA_DOMAINTYPE_VIDEO 0x00000002 -#define XA_DOMAINTYPE_IMAGE 0x00000003 -#define XA_DOMAINTYPE_TIMEDTEXT 0x00000004 -#define XA_DOMAINTYPE_MIDI 0x00000005 -#define XA_DOMAINTYPE_VENDOR 0xFFFFFFFE -#define XA_DOMAINTYPE_UNKNOWN 0xFFFFFFFF - -#define XA_MIDIBANK_DEVICE 0x00000001 -#define XA_MIDIBANK_CUSTOM 0x00000002 - -#define XA_MIDI_UNKNOWN 0xFFFFFFFF - -#define XA_STREAMCBEVENT_PROPERTYCHANGE ((XAuint32) 0x00000001) - -typedef struct XAMediaContainerInformation_ { - XAuint32 containerType; - XAmillisecond mediaDuration; - XAuint32 numStreams; -} XAMediaContainerInformation; - -typedef struct XAVideoStreamInformation_ { - XAuint32 codecId; - XAuint32 width; - XAuint32 height; - XAuint32 frameRate; - XAuint32 bitRate; - XAmillisecond duration; -} XAVideoStreamInformation; - -typedef struct XAAudioStreamInformation_ { - XAuint32 codecId; - XAuint32 channels; - XAmilliHertz sampleRate; - XAuint32 bitRate; - XAchar langCountry[16]; - XAmillisecond duration; -} XAAudioStreamInformation; - -typedef struct XAImageStreamInformation_ { - XAuint32 codecId; - XAuint32 width; - XAuint32 height; - XAmillisecond presentationDuration; -} XAImageStreamInformation; - -typedef struct XATimedTextStreamInformation_ { - XAuint16 layer; - XAuint32 width; - XAuint32 height; - XAuint16 tx; - XAuint16 ty; - XAuint32 bitrate; - XAchar langCountry[16]; - XAmillisecond duration; -} XATimedTextStreamInformation; - -typedef struct XAMIDIStreamInformation_ { - XAuint32 channels; - XAuint32 tracks; - XAuint32 bankType; - XAchar langCountry[16]; - XAmillisecond duration; -} XAMIDIStreamInformation; - -typedef struct XAVendorStreamInformation_ { - void *VendorStreamInfo; -} XAVendorStreamInformation; - -XA_API extern const XAInterfaceID XA_IID_STREAMINFORMATION; - -struct XAStreamInformationItf_; -typedef const struct XAStreamInformationItf_ * const * XAStreamInformationItf; - -typedef void (XAAPIENTRY * xaStreamEventChangeCallback) ( - XAStreamInformationItf caller, - XAuint32 eventId, - XAuint32 streamIndex, - void * pEventData, - void * pContext -); - -struct XAStreamInformationItf_ { - XAresult (*QueryMediaContainerInformation) ( - XAStreamInformationItf self, - XAMediaContainerInformation * info - ); - XAresult (*QueryStreamType) ( - XAStreamInformationItf self, - XAuint32 streamIndex, - XAuint32 *domain - ); - XAresult (*QueryStreamInformation) ( - XAStreamInformationItf self, - XAuint32 streamIndex, - void * info - ); - XAresult (*QueryStreamName) ( - XAStreamInformationItf self, - XAuint32 streamIndex, - XAuint16 * pNameSize, - XAchar * pName - ); - XAresult (*RegisterStreamChangeCallback) ( - XAStreamInformationItf self, - xaStreamEventChangeCallback callback, - void * pContext - ); - XAresult (*QueryActiveStreams) ( - XAStreamInformationItf self, - XAuint32 *numStreams, - XAboolean *activeStreams - ); - XAresult (*SetActiveStream) ( - XAStreamInformationItf self, - XAuint32 streamNum, - XAboolean active, - XAboolean commitNow - ); -}; - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* _OPENMAXAL_H_ */ diff --git a/wilhelm/include/OMXAL/OpenMAXAL_Android.h b/wilhelm/include/OMXAL/OpenMAXAL_Android.h deleted file mode 100644 index 34b9dd91..00000000 --- a/wilhelm/include/OMXAL/OpenMAXAL_Android.h +++ /dev/null @@ -1,178 +0,0 @@ -/* - * 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 OPENMAX_AL_ANDROID_H_ -#define OPENMAX_AL_ANDROID_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/*---------------------------------------------------------------------------*/ -/* Android common types */ -/*---------------------------------------------------------------------------*/ - -typedef xa_int64_t XAAint64; /* 64 bit signed integer */ - -typedef xa_uint64_t XAAuint64; /* 64 bit unsigned integer */ - -/*---------------------------------------------------------------------------*/ -/* Android common types */ -/*---------------------------------------------------------------------------*/ - -#define XA_ANDROID_VIDEOCODEC_VP8 ((XAuint32) 0x00000006) - -#define XA_ANDROID_VIDEOPROFILE_VP8_MAIN ((XAuint32) 0x00000001) - -#define XA_ANDROID_VIDEOLEVEL_VP8_VERSION0 ((XAuint32) 0x00000001) -#define XA_ANDROID_VIDEOLEVEL_VP8_VERSION1 ((XAuint32) 0x00000002) -#define XA_ANDROID_VIDEOLEVEL_VP8_VERSION2 ((XAuint32) 0x00000003) -#define XA_ANDROID_VIDEOLEVEL_VP8_VERSION3 ((XAuint32) 0x00000004) - -/*---------------------------------------------------------------------------*/ -/* Android Buffer Queue Interface */ -/*---------------------------------------------------------------------------*/ - -extern XA_API const XAInterfaceID XA_IID_ANDROIDBUFFERQUEUESOURCE; - -struct XAAndroidBufferQueueItf_; -typedef const struct XAAndroidBufferQueueItf_ * const * XAAndroidBufferQueueItf; - -#define XA_ANDROID_ITEMKEY_NONE ((XAuint32) 0x00000000) -#define XA_ANDROID_ITEMKEY_EOS ((XAuint32) 0x00000001) -#define XA_ANDROID_ITEMKEY_DISCONTINUITY ((XAuint32) 0x00000002) -#define XA_ANDROID_ITEMKEY_BUFFERQUEUEEVENT ((XAuint32) 0x00000003) -#define XA_ANDROID_ITEMKEY_FORMAT_CHANGE ((XAuint32) 0x00000004) - -// optional data for XA_ANDROID_ITEMKEY_FORMAT_CHANGE, used when only one stream changes format, -// and the others remain continuous (i.e. no temporal discontinuity is introduced for them) -// candidate for being exposed in NDK -#define XA_ANDROID_FORMATCHANGE_ITEMDATA_VIDEO ((XAuint32) 0x00000001) -// not supported at this stage, for illustration purposes only -//#define XA_ANDROID_FORMATCHANGE_ITEMDATA_AUDIO ((XAuint32) 0x00000002) - -#define XA_ANDROIDBUFFERQUEUEEVENT_NONE ((XAuint32) 0x00000000) -#define XA_ANDROIDBUFFERQUEUEEVENT_PROCESSED ((XAuint32) 0x00000001) -#if 0 // reserved for future use -#define XA_ANDROIDBUFFERQUEUEEVENT_UNREALIZED ((XAuint32) 0x00000002) -#define XA_ANDROIDBUFFERQUEUEEVENT_CLEARED ((XAuint32) 0x00000004) -#define XA_ANDROIDBUFFERQUEUEEVENT_STOPPED ((XAuint32) 0x00000008) -#define XA_ANDROIDBUFFERQUEUEEVENT_ERROR ((XAuint32) 0x00000010) -#define XA_ANDROIDBUFFERQUEUEEVENT_CONTENT_END ((XAuint32) 0x00000020) -#endif - -typedef struct XAAndroidBufferItem_ { - XAuint32 itemKey; // identifies the item - XAuint32 itemSize; - XAuint8 itemData[0]; -} XAAndroidBufferItem; - -typedef XAresult (XAAPIENTRY *xaAndroidBufferQueueCallback)( - XAAndroidBufferQueueItf caller,/* input */ - void *pCallbackContext, /* input */ - void *pBufferContext, /* input */ - void *pBufferData, /* input */ - XAuint32 dataSize, /* input */ - XAuint32 dataUsed, /* input */ - const XAAndroidBufferItem *pItems,/* input */ - XAuint32 itemsLength /* input */ -); - -typedef struct XAAndroidBufferQueueState_ { - XAuint32 count; - XAuint32 index; -} XAAndroidBufferQueueState; - -struct XAAndroidBufferQueueItf_ { - XAresult (*RegisterCallback) ( - XAAndroidBufferQueueItf self, - xaAndroidBufferQueueCallback callback, - void* pCallbackContext - ); - - XAresult (*Clear) ( - XAAndroidBufferQueueItf self - ); - - XAresult (*Enqueue) ( - XAAndroidBufferQueueItf self, - void *pBufferContext, - void *pData, - XAuint32 dataLength, - const XAAndroidBufferItem *pItems, - XAuint32 itemsLength - ); - - XAresult (*GetState) ( - XAAndroidBufferQueueItf self, - XAAndroidBufferQueueState *pState - ); - - - XAresult (*SetCallbackEventsMask) ( - XAAndroidBufferQueueItf self, - XAuint32 eventFlags - ); - - XAresult (*GetCallbackEventsMask) ( - XAAndroidBufferQueueItf self, - XAuint32 *pEventFlags - ); -}; - - -/*---------------------------------------------------------------------------*/ -/* Android Buffer Queue Data Locator */ -/*---------------------------------------------------------------------------*/ - -/** Addendum to Data locator macros */ -#define XA_DATALOCATOR_ANDROIDBUFFERQUEUE ((XAuint32) 0x800007BE) - -/** Android Buffer Queue-based data locator definition, - * locatorType must be XA_DATALOCATOR_ANDROIDBUFFERQUEUE */ -typedef struct XADataLocator_AndroidBufferQueue_ { - XAuint32 locatorType; - XAuint32 numBuffers; -} XADataLocator_AndroidBufferQueue; - - -/*---------------------------------------------------------------------------*/ -/* Android File Descriptor Data Locator */ -/*---------------------------------------------------------------------------*/ - -/** Addendum to Data locator macros */ -#define XA_DATALOCATOR_ANDROIDFD ((XAuint32) 0x800007BC) - -#define XA_DATALOCATOR_ANDROIDFD_USE_FILE_SIZE ((XAAint64) 0xFFFFFFFFFFFFFFFFll) - -/** File Descriptor-based data locator definition, locatorType must be XA_DATALOCATOR_ANDROIDFD */ -typedef struct XADataLocator_AndroidFD_ { - XAuint32 locatorType; - XAint32 fd; - XAAint64 offset; - XAAint64 length; -} XADataLocator_AndroidFD; - -/** - * MIME types required for data in Android Buffer Queues - */ -#define XA_ANDROID_MIME_MP2TS ((XAchar *) "video/mp2ts") - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* OPENMAX_AL_ANDROID_H_ */ diff --git a/wilhelm/include/OMXAL/OpenMAXAL_Platform.h b/wilhelm/include/OMXAL/OpenMAXAL_Platform.h deleted file mode 100644 index 23be77e4..00000000 --- a/wilhelm/include/OMXAL/OpenMAXAL_Platform.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2007-2010 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and/or associated documentation files (the - * "Materials "), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - * - * OpenMAXAL_Platform.h - OpenMAX AL version 1.0.1 - * - */ - -/****************************************************************************/ -/* NOTE: This file contains definitions for the base types and the */ -/* XAAPIENTRY macro. This file **WILL NEED TO BE EDITED** to provide */ -/* the correct definitions specific to the platform being used. */ -/****************************************************************************/ - -#ifndef _OPENMAXAL_PLATFORM_H_ -#define _OPENMAXAL_PLATFORM_H_ - -typedef unsigned char xa_uint8_t; -typedef signed char xa_int8_t; -typedef unsigned short xa_uint16_t; -typedef signed short xa_int16_t; -typedef unsigned int /*long*/ xa_uint32_t; -typedef signed int /*long*/ xa_int32_t; -typedef long long xa_int64_t; -typedef unsigned long long xa_uint64_t; - -#ifndef XAAPIENTRY -#define XAAPIENTRY /* override per-platform */ -#endif - -/** The XA_API is a platform-specific macro used - * to declare OPENMAX AL function prototypes. It is modified to meet the - * requirements for a particular platform - * - * Example: - * #ifdef __SYMBIAN32__ - * # define XA_API __declspec(dllimport) - * #endif - */ - -#ifndef XA_API -#ifdef __GNUC__ -#define XA_API -#else -#define XA_API __declspec(dllimport) -#endif -#endif - -#endif /* _OPENMAXAL_PLATFORM_H_ */ diff --git a/wilhelm/include/SLES/OpenSLES.h b/wilhelm/include/SLES/OpenSLES.h deleted file mode 100644 index 8686997c..00000000 --- a/wilhelm/include/SLES/OpenSLES.h +++ /dev/null @@ -1,2774 +0,0 @@ -/* - * Copyright (c) 2007-2009 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and /or associated documentation files (the "Materials "), to - * deal in the Materials without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Materials, and to permit persons to whom the Materials are - * furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS IN THE - * MATERIALS. - * - * OpenSLES.h - OpenSL ES version 1.0.1 - * - */ - -/****************************************************************************/ -/* NOTE: This file is a standard OpenSL ES header file and should not be */ -/* modified in any way. */ -/****************************************************************************/ - -#ifndef OPENSL_ES_H_ -#define OPENSL_ES_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "OpenSLES_Platform.h" - - -/*****************************************************************************/ -/* Common types, structures, and defines */ -/*****************************************************************************/ - -#ifndef _KHRONOS_KEYS_ -#define _KHRONOS_KEYS_ - -#define KHRONOS_TITLE "KhronosTitle" -#define KHRONOS_ALBUM "KhronosAlbum" -#define KHRONOS_TRACK_NUMBER "KhronosTrackNumber" -#define KHRONOS_ARTIST "KhronosArtist" -#define KHRONOS_GENRE "KhronosGenre" -#define KHRONOS_YEAR "KhronosYear" -#define KHRONOS_COMMENT "KhronosComment" -#define KHRONOS_ARTIST_URL "KhronosArtistURL" -#define KHRONOS_CONTENT_URL "KhronosContentURL" -#define KHRONOS_RATING "KhronosRating" -#define KHRONOS_ALBUM_ART "KhronosAlbumArt" -#define KHRONOS_COPYRIGHT "KhronosCopyright" - -#endif - - -/* remap common types to SL types for clarity */ -typedef sl_int8_t SLint8; /* 8 bit signed integer */ -typedef sl_uint8_t SLuint8; /* 8 bit unsigned integer */ -typedef sl_int16_t SLint16; /* 16 bit signed integer */ -typedef sl_uint16_t SLuint16; /* 16 bit unsigned integer */ -typedef sl_int32_t SLint32; /* 32 bit signed integer */ -typedef sl_uint32_t SLuint32; /* 32 bit unsigned integer */ - -typedef SLuint32 SLboolean; -#define SL_BOOLEAN_FALSE ((SLboolean) 0x00000000) -#define SL_BOOLEAN_TRUE ((SLboolean) 0x00000001) - -typedef SLuint8 SLchar; /* UTF-8 is to be used */ -typedef SLint16 SLmillibel; -typedef SLuint32 SLmillisecond; -typedef SLuint32 SLmilliHertz; -typedef SLint32 SLmillimeter; -typedef SLint32 SLmillidegree; -typedef SLint16 SLpermille; -typedef SLuint32 SLmicrosecond; -typedef SLuint32 SLresult; - -#define SL_MILLIBEL_MAX ((SLmillibel) 0x7FFF) -#define SL_MILLIBEL_MIN ((SLmillibel) (-SL_MILLIBEL_MAX-1)) - -#define SL_MILLIHERTZ_MAX ((SLmilliHertz) 0xFFFFFFFF) -#define SL_MILLIMETER_MAX ((SLmillimeter) 0x7FFFFFFF) - -/** Interface ID defined as a UUID */ -typedef const struct SLInterfaceID_ { - SLuint32 time_low; - SLuint16 time_mid; - SLuint16 time_hi_and_version; - SLuint16 clock_seq; - SLuint8 node[6]; -} * SLInterfaceID; - -/* Forward declaration for the object interface */ -struct SLObjectItf_; - -typedef const struct SLObjectItf_ * const * SLObjectItf; - -/* Objects ID's */ - -#define SL_OBJECTID_ENGINE ((SLuint32) 0x00001001) -#define SL_OBJECTID_LEDDEVICE ((SLuint32) 0x00001002) -#define SL_OBJECTID_VIBRADEVICE ((SLuint32) 0x00001003) -#define SL_OBJECTID_AUDIOPLAYER ((SLuint32) 0x00001004) -#define SL_OBJECTID_AUDIORECORDER ((SLuint32) 0x00001005) -#define SL_OBJECTID_MIDIPLAYER ((SLuint32) 0x00001006) -#define SL_OBJECTID_LISTENER ((SLuint32) 0x00001007) -#define SL_OBJECTID_3DGROUP ((SLuint32) 0x00001008) -#define SL_OBJECTID_OUTPUTMIX ((SLuint32) 0x00001009) -#define SL_OBJECTID_METADATAEXTRACTOR ((SLuint32) 0x0000100A) - - -/* SL Profiles */ - -#define SL_PROFILES_PHONE ((SLuint16) 0x0001) -#define SL_PROFILES_MUSIC ((SLuint16) 0x0002) -#define SL_PROFILES_GAME ((SLuint16) 0x0004) - -/* Types of voices supported by the system */ - -#define SL_VOICETYPE_2D_AUDIO ((SLuint16) 0x0001) -#define SL_VOICETYPE_MIDI ((SLuint16) 0x0002) -#define SL_VOICETYPE_3D_AUDIO ((SLuint16) 0x0004) -#define SL_VOICETYPE_3D_MIDIOUTPUT ((SLuint16) 0x0008) - -/* Convenient macros representing various different priority levels, for use with the SetPriority method */ - -#define SL_PRIORITY_LOWEST ((SLint32) (-0x7FFFFFFF-1)) -#define SL_PRIORITY_VERYLOW ((SLint32) -0x60000000) -#define SL_PRIORITY_LOW ((SLint32) -0x40000000) -#define SL_PRIORITY_BELOWNORMAL ((SLint32) -0x20000000) -#define SL_PRIORITY_NORMAL ((SLint32) 0x00000000) -#define SL_PRIORITY_ABOVENORMAL ((SLint32) 0x20000000) -#define SL_PRIORITY_HIGH ((SLint32) 0x40000000) -#define SL_PRIORITY_VERYHIGH ((SLint32) 0x60000000) -#define SL_PRIORITY_HIGHEST ((SLint32) 0x7FFFFFFF) - - -/** These macros list the various sample formats that are possible on audio input and output devices. */ - -#define SL_PCMSAMPLEFORMAT_FIXED_8 ((SLuint16) 0x0008) -#define SL_PCMSAMPLEFORMAT_FIXED_16 ((SLuint16) 0x0010) -#define SL_PCMSAMPLEFORMAT_FIXED_20 ((SLuint16) 0x0014) -#define SL_PCMSAMPLEFORMAT_FIXED_24 ((SLuint16) 0x0018) -#define SL_PCMSAMPLEFORMAT_FIXED_28 ((SLuint16) 0x001C) -#define SL_PCMSAMPLEFORMAT_FIXED_32 ((SLuint16) 0x0020) - - -/** These macros specify the commonly used sampling rates (in milliHertz) supported by most audio I/O devices. */ - -#define SL_SAMPLINGRATE_8 ((SLuint32) 8000000) -#define SL_SAMPLINGRATE_11_025 ((SLuint32) 11025000) -#define SL_SAMPLINGRATE_12 ((SLuint32) 12000000) -#define SL_SAMPLINGRATE_16 ((SLuint32) 16000000) -#define SL_SAMPLINGRATE_22_05 ((SLuint32) 22050000) -#define SL_SAMPLINGRATE_24 ((SLuint32) 24000000) -#define SL_SAMPLINGRATE_32 ((SLuint32) 32000000) -#define SL_SAMPLINGRATE_44_1 ((SLuint32) 44100000) -#define SL_SAMPLINGRATE_48 ((SLuint32) 48000000) -#define SL_SAMPLINGRATE_64 ((SLuint32) 64000000) -#define SL_SAMPLINGRATE_88_2 ((SLuint32) 88200000) -#define SL_SAMPLINGRATE_96 ((SLuint32) 96000000) -#define SL_SAMPLINGRATE_192 ((SLuint32) 192000000) - -#define SL_SPEAKER_FRONT_LEFT ((SLuint32) 0x00000001) -#define SL_SPEAKER_FRONT_RIGHT ((SLuint32) 0x00000002) -#define SL_SPEAKER_FRONT_CENTER ((SLuint32) 0x00000004) -#define SL_SPEAKER_LOW_FREQUENCY ((SLuint32) 0x00000008) -#define SL_SPEAKER_BACK_LEFT ((SLuint32) 0x00000010) -#define SL_SPEAKER_BACK_RIGHT ((SLuint32) 0x00000020) -#define SL_SPEAKER_FRONT_LEFT_OF_CENTER ((SLuint32) 0x00000040) -#define SL_SPEAKER_FRONT_RIGHT_OF_CENTER ((SLuint32) 0x00000080) -#define SL_SPEAKER_BACK_CENTER ((SLuint32) 0x00000100) -#define SL_SPEAKER_SIDE_LEFT ((SLuint32) 0x00000200) -#define SL_SPEAKER_SIDE_RIGHT ((SLuint32) 0x00000400) -#define SL_SPEAKER_TOP_CENTER ((SLuint32) 0x00000800) -#define SL_SPEAKER_TOP_FRONT_LEFT ((SLuint32) 0x00001000) -#define SL_SPEAKER_TOP_FRONT_CENTER ((SLuint32) 0x00002000) -#define SL_SPEAKER_TOP_FRONT_RIGHT ((SLuint32) 0x00004000) -#define SL_SPEAKER_TOP_BACK_LEFT ((SLuint32) 0x00008000) -#define SL_SPEAKER_TOP_BACK_CENTER ((SLuint32) 0x00010000) -#define SL_SPEAKER_TOP_BACK_RIGHT ((SLuint32) 0x00020000) - - -/*****************************************************************************/ -/* Errors */ -/* */ -/*****************************************************************************/ - -#define SL_RESULT_SUCCESS ((SLuint32) 0x00000000) -#define SL_RESULT_PRECONDITIONS_VIOLATED ((SLuint32) 0x00000001) -#define SL_RESULT_PARAMETER_INVALID ((SLuint32) 0x00000002) -#define SL_RESULT_MEMORY_FAILURE ((SLuint32) 0x00000003) -#define SL_RESULT_RESOURCE_ERROR ((SLuint32) 0x00000004) -#define SL_RESULT_RESOURCE_LOST ((SLuint32) 0x00000005) -#define SL_RESULT_IO_ERROR ((SLuint32) 0x00000006) -#define SL_RESULT_BUFFER_INSUFFICIENT ((SLuint32) 0x00000007) -#define SL_RESULT_CONTENT_CORRUPTED ((SLuint32) 0x00000008) -#define SL_RESULT_CONTENT_UNSUPPORTED ((SLuint32) 0x00000009) -#define SL_RESULT_CONTENT_NOT_FOUND ((SLuint32) 0x0000000A) -#define SL_RESULT_PERMISSION_DENIED ((SLuint32) 0x0000000B) -#define SL_RESULT_FEATURE_UNSUPPORTED ((SLuint32) 0x0000000C) -#define SL_RESULT_INTERNAL_ERROR ((SLuint32) 0x0000000D) -#define SL_RESULT_UNKNOWN_ERROR ((SLuint32) 0x0000000E) -#define SL_RESULT_OPERATION_ABORTED ((SLuint32) 0x0000000F) -#define SL_RESULT_CONTROL_LOST ((SLuint32) 0x00000010) - - -/* Object state definitions */ - -#define SL_OBJECT_STATE_UNREALIZED ((SLuint32) 0x00000001) -#define SL_OBJECT_STATE_REALIZED ((SLuint32) 0x00000002) -#define SL_OBJECT_STATE_SUSPENDED ((SLuint32) 0x00000003) - -/* Object event definitions */ - -#define SL_OBJECT_EVENT_RUNTIME_ERROR ((SLuint32) 0x00000001) -#define SL_OBJECT_EVENT_ASYNC_TERMINATION ((SLuint32) 0x00000002) -#define SL_OBJECT_EVENT_RESOURCES_LOST ((SLuint32) 0x00000003) -#define SL_OBJECT_EVENT_RESOURCES_AVAILABLE ((SLuint32) 0x00000004) -#define SL_OBJECT_EVENT_ITF_CONTROL_TAKEN ((SLuint32) 0x00000005) -#define SL_OBJECT_EVENT_ITF_CONTROL_RETURNED ((SLuint32) 0x00000006) -#define SL_OBJECT_EVENT_ITF_PARAMETERS_CHANGED ((SLuint32) 0x00000007) - - -/*****************************************************************************/ -/* Interface definitions */ -/*****************************************************************************/ - -/** NULL Interface */ - -extern SL_API const SLInterfaceID SL_IID_NULL; - -/*---------------------------------------------------------------------------*/ -/* Data Source and Data Sink Structures */ -/*---------------------------------------------------------------------------*/ - -/** Data locator macros */ -#define SL_DATALOCATOR_URI ((SLuint32) 0x00000001) -#define SL_DATALOCATOR_ADDRESS ((SLuint32) 0x00000002) -#define SL_DATALOCATOR_IODEVICE ((SLuint32) 0x00000003) -#define SL_DATALOCATOR_OUTPUTMIX ((SLuint32) 0x00000004) -#define SL_DATALOCATOR_RESERVED5 ((SLuint32) 0x00000005) -#define SL_DATALOCATOR_BUFFERQUEUE ((SLuint32) 0x00000006) -#define SL_DATALOCATOR_MIDIBUFFERQUEUE ((SLuint32) 0x00000007) -#define SL_DATALOCATOR_RESERVED8 ((SLuint32) 0x00000008) - - - -/** URI-based data locator definition where locatorType must be SL_DATALOCATOR_URI*/ -typedef struct SLDataLocator_URI_ { - SLuint32 locatorType; - SLchar * URI; -} SLDataLocator_URI; - -/** Address-based data locator definition where locatorType must be SL_DATALOCATOR_ADDRESS*/ -typedef struct SLDataLocator_Address_ { - SLuint32 locatorType; - void *pAddress; - SLuint32 length; -} SLDataLocator_Address; - -/** IODevice-types */ -#define SL_IODEVICE_AUDIOINPUT ((SLuint32) 0x00000001) -#define SL_IODEVICE_LEDARRAY ((SLuint32) 0x00000002) -#define SL_IODEVICE_VIBRA ((SLuint32) 0x00000003) -#define SL_IODEVICE_RESERVED4 ((SLuint32) 0x00000004) -#define SL_IODEVICE_RESERVED5 ((SLuint32) 0x00000005) - -/** IODevice-based data locator definition where locatorType must be SL_DATALOCATOR_IODEVICE*/ -typedef struct SLDataLocator_IODevice_ { - SLuint32 locatorType; - SLuint32 deviceType; - SLuint32 deviceID; - SLObjectItf device; -} SLDataLocator_IODevice; - -/** OutputMix-based data locator definition where locatorType must be SL_DATALOCATOR_OUTPUTMIX*/ -typedef struct SLDataLocator_OutputMix { - SLuint32 locatorType; - SLObjectItf outputMix; -} SLDataLocator_OutputMix; - - -/** BufferQueue-based data locator definition where locatorType must be SL_DATALOCATOR_BUFFERQUEUE*/ -typedef struct SLDataLocator_BufferQueue { - SLuint32 locatorType; - SLuint32 numBuffers; -} SLDataLocator_BufferQueue; - -/** MidiBufferQueue-based data locator definition where locatorType must be SL_DATALOCATOR_MIDIBUFFERQUEUE*/ -typedef struct SLDataLocator_MIDIBufferQueue { - SLuint32 locatorType; - SLuint32 tpqn; - SLuint32 numBuffers; -} SLDataLocator_MIDIBufferQueue; - -/** Data format defines */ -#define SL_DATAFORMAT_MIME ((SLuint32) 0x00000001) -#define SL_DATAFORMAT_PCM ((SLuint32) 0x00000002) -#define SL_DATAFORMAT_RESERVED3 ((SLuint32) 0x00000003) - - -/** MIME-type-based data format definition where formatType must be SL_DATAFORMAT_MIME*/ -typedef struct SLDataFormat_MIME_ { - SLuint32 formatType; - SLchar * mimeType; - SLuint32 containerType; -} SLDataFormat_MIME; - -/* Byte order of a block of 16- or 32-bit data */ -#define SL_BYTEORDER_BIGENDIAN ((SLuint32) 0x00000001) -#define SL_BYTEORDER_LITTLEENDIAN ((SLuint32) 0x00000002) - -/* Container type */ -#define SL_CONTAINERTYPE_UNSPECIFIED ((SLuint32) 0x00000001) -#define SL_CONTAINERTYPE_RAW ((SLuint32) 0x00000002) -#define SL_CONTAINERTYPE_ASF ((SLuint32) 0x00000003) -#define SL_CONTAINERTYPE_AVI ((SLuint32) 0x00000004) -#define SL_CONTAINERTYPE_BMP ((SLuint32) 0x00000005) -#define SL_CONTAINERTYPE_JPG ((SLuint32) 0x00000006) -#define SL_CONTAINERTYPE_JPG2000 ((SLuint32) 0x00000007) -#define SL_CONTAINERTYPE_M4A ((SLuint32) 0x00000008) -#define SL_CONTAINERTYPE_MP3 ((SLuint32) 0x00000009) -#define SL_CONTAINERTYPE_MP4 ((SLuint32) 0x0000000A) -#define SL_CONTAINERTYPE_MPEG_ES ((SLuint32) 0x0000000B) -#define SL_CONTAINERTYPE_MPEG_PS ((SLuint32) 0x0000000C) -#define SL_CONTAINERTYPE_MPEG_TS ((SLuint32) 0x0000000D) -#define SL_CONTAINERTYPE_QT ((SLuint32) 0x0000000E) -#define SL_CONTAINERTYPE_WAV ((SLuint32) 0x0000000F) -#define SL_CONTAINERTYPE_XMF_0 ((SLuint32) 0x00000010) -#define SL_CONTAINERTYPE_XMF_1 ((SLuint32) 0x00000011) -#define SL_CONTAINERTYPE_XMF_2 ((SLuint32) 0x00000012) -#define SL_CONTAINERTYPE_XMF_3 ((SLuint32) 0x00000013) -#define SL_CONTAINERTYPE_XMF_GENERIC ((SLuint32) 0x00000014) -#define SL_CONTAINERTYPE_AMR ((SLuint32) 0x00000015) -#define SL_CONTAINERTYPE_AAC ((SLuint32) 0x00000016) -#define SL_CONTAINERTYPE_3GPP ((SLuint32) 0x00000017) -#define SL_CONTAINERTYPE_3GA ((SLuint32) 0x00000018) -#define SL_CONTAINERTYPE_RM ((SLuint32) 0x00000019) -#define SL_CONTAINERTYPE_DMF ((SLuint32) 0x0000001A) -#define SL_CONTAINERTYPE_SMF ((SLuint32) 0x0000001B) -#define SL_CONTAINERTYPE_MOBILE_DLS ((SLuint32) 0x0000001C) -#define SL_CONTAINERTYPE_OGG ((SLuint32) 0x0000001D) - - -/** PCM-type-based data format definition where formatType must be SL_DATAFORMAT_PCM*/ -typedef struct SLDataFormat_PCM_ { - SLuint32 formatType; - SLuint32 numChannels; - SLuint32 samplesPerSec; - SLuint32 bitsPerSample; - SLuint32 containerSize; - SLuint32 channelMask; - SLuint32 endianness; -} SLDataFormat_PCM; - -typedef struct SLDataSource_ { - void *pLocator; - void *pFormat; -} SLDataSource; - - -typedef struct SLDataSink_ { - void *pLocator; - void *pFormat; -} SLDataSink; - - - - - - -/*---------------------------------------------------------------------------*/ -/* Standard Object Interface */ -/*---------------------------------------------------------------------------*/ - -extern SL_API const SLInterfaceID SL_IID_OBJECT; - -/** Object callback */ - - -typedef void (SLAPIENTRY *slObjectCallback) ( - SLObjectItf caller, - const void * pContext, - SLuint32 event, - SLresult result, - SLuint32 param, - void *pInterface -); - - -struct SLObjectItf_ { - SLresult (*Realize) ( - SLObjectItf self, - SLboolean async - ); - SLresult (*Resume) ( - SLObjectItf self, - SLboolean async - ); - SLresult (*GetState) ( - SLObjectItf self, - SLuint32 * pState - ); - SLresult (*GetInterface) ( - SLObjectItf self, - const SLInterfaceID iid, - void * pInterface - ); - SLresult (*RegisterCallback) ( - SLObjectItf self, - slObjectCallback callback, - void * pContext - ); - void (*AbortAsyncOperation) ( - SLObjectItf self - ); - void (*Destroy) ( - SLObjectItf self - ); - SLresult (*SetPriority) ( - SLObjectItf self, - SLint32 priority, - SLboolean preemptable - ); - SLresult (*GetPriority) ( - SLObjectItf self, - SLint32 *pPriority, - SLboolean *pPreemptable - ); - SLresult (*SetLossOfControlInterfaces) ( - SLObjectItf self, - SLint16 numInterfaces, - SLInterfaceID * pInterfaceIDs, - SLboolean enabled - ); -}; - - -/*---------------------------------------------------------------------------*/ -/* Audio IO Device capabilities interface */ -/*---------------------------------------------------------------------------*/ - -#define SL_DEFAULTDEVICEID_AUDIOINPUT ((SLuint32) 0xFFFFFFFF) -#define SL_DEFAULTDEVICEID_AUDIOOUTPUT ((SLuint32) 0xFFFFFFFE) -#define SL_DEFAULTDEVICEID_LED ((SLuint32) 0xFFFFFFFD) -#define SL_DEFAULTDEVICEID_VIBRA ((SLuint32) 0xFFFFFFFC) -#define SL_DEFAULTDEVICEID_RESERVED1 ((SLuint32) 0xFFFFFFFB) - - -#define SL_DEVCONNECTION_INTEGRATED ((SLint16) 0x0001) -#define SL_DEVCONNECTION_ATTACHED_WIRED ((SLint16) 0x0100) -#define SL_DEVCONNECTION_ATTACHED_WIRELESS ((SLint16) 0x0200) -#define SL_DEVCONNECTION_NETWORK ((SLint16) 0x0400) - - -#define SL_DEVLOCATION_HANDSET ((SLuint16) 0x0001) -#define SL_DEVLOCATION_HEADSET ((SLuint16) 0x0002) -#define SL_DEVLOCATION_CARKIT ((SLuint16) 0x0003) -#define SL_DEVLOCATION_DOCK ((SLuint16) 0x0004) -#define SL_DEVLOCATION_REMOTE ((SLuint16) 0x0005) -/* Note: SL_DEVLOCATION_RESLTE is deprecated, use SL_DEVLOCATION_REMOTE instead. */ -#define SL_DEVLOCATION_RESLTE ((SLuint16) 0x0005) - - -#define SL_DEVSCOPE_UNKNOWN ((SLuint16) 0x0001) -#define SL_DEVSCOPE_ENVIRONMENT ((SLuint16) 0x0002) -#define SL_DEVSCOPE_USER ((SLuint16) 0x0003) - - -typedef struct SLAudioInputDescriptor_ { - SLchar *deviceName; - SLint16 deviceConnection; - SLint16 deviceScope; - SLint16 deviceLocation; - SLboolean isForTelephony; - SLmilliHertz minSampleRate; - SLmilliHertz maxSampleRate; - SLboolean isFreqRangeContinuous; - SLmilliHertz *samplingRatesSupported; - SLint16 numOfSamplingRatesSupported; - SLint16 maxChannels; -} SLAudioInputDescriptor; - - -typedef struct SLAudioOutputDescriptor_ { - SLchar *pDeviceName; - SLint16 deviceConnection; - SLint16 deviceScope; - SLint16 deviceLocation; - SLboolean isForTelephony; - SLmilliHertz minSampleRate; - SLmilliHertz maxSampleRate; - SLboolean isFreqRangeContinuous; - SLmilliHertz *samplingRatesSupported; - SLint16 numOfSamplingRatesSupported; - SLint16 maxChannels; -} SLAudioOutputDescriptor; - - - -extern SL_API const SLInterfaceID SL_IID_AUDIOIODEVICECAPABILITIES; - -struct SLAudioIODeviceCapabilitiesItf_; -typedef const struct SLAudioIODeviceCapabilitiesItf_ * const * SLAudioIODeviceCapabilitiesItf; - - -typedef void (SLAPIENTRY *slAvailableAudioInputsChangedCallback) ( - SLAudioIODeviceCapabilitiesItf caller, - void *pContext, - SLuint32 deviceID, - SLint32 numInputs, - SLboolean isNew -); - - -typedef void (SLAPIENTRY *slAvailableAudioOutputsChangedCallback) ( - SLAudioIODeviceCapabilitiesItf caller, - void *pContext, - SLuint32 deviceID, - SLint32 numOutputs, - SLboolean isNew -); - -typedef void (SLAPIENTRY *slDefaultDeviceIDMapChangedCallback) ( - SLAudioIODeviceCapabilitiesItf caller, - void *pContext, - SLboolean isOutput, - SLint32 numDevices -); - - -struct SLAudioIODeviceCapabilitiesItf_ { - SLresult (*GetAvailableAudioInputs)( - SLAudioIODeviceCapabilitiesItf self, - SLint32 *pNumInputs, - SLuint32 *pInputDeviceIDs - ); - SLresult (*QueryAudioInputCapabilities)( - SLAudioIODeviceCapabilitiesItf self, - SLuint32 deviceId, - SLAudioInputDescriptor *pDescriptor - ); - SLresult (*RegisterAvailableAudioInputsChangedCallback) ( - SLAudioIODeviceCapabilitiesItf self, - slAvailableAudioInputsChangedCallback callback, - void *pContext - ); - SLresult (*GetAvailableAudioOutputs)( - SLAudioIODeviceCapabilitiesItf self, - SLint32 *pNumOutputs, - SLuint32 *pOutputDeviceIDs - ); - SLresult (*QueryAudioOutputCapabilities)( - SLAudioIODeviceCapabilitiesItf self, - SLuint32 deviceId, - SLAudioOutputDescriptor *pDescriptor - ); - SLresult (*RegisterAvailableAudioOutputsChangedCallback) ( - SLAudioIODeviceCapabilitiesItf self, - slAvailableAudioOutputsChangedCallback callback, - void *pContext - ); - SLresult (*RegisterDefaultDeviceIDMapChangedCallback) ( - SLAudioIODeviceCapabilitiesItf self, - slDefaultDeviceIDMapChangedCallback callback, - void *pContext - ); - SLresult (*GetAssociatedAudioInputs) ( - SLAudioIODeviceCapabilitiesItf self, - SLuint32 deviceId, - SLint32 *pNumAudioInputs, - SLuint32 *pAudioInputDeviceIDs - ); - SLresult (*GetAssociatedAudioOutputs) ( - SLAudioIODeviceCapabilitiesItf self, - SLuint32 deviceId, - SLint32 *pNumAudioOutputs, - SLuint32 *pAudioOutputDeviceIDs - ); - SLresult (*GetDefaultAudioDevices) ( - SLAudioIODeviceCapabilitiesItf self, - SLuint32 defaultDeviceID, - SLint32 *pNumAudioDevices, - SLuint32 *pAudioDeviceIDs - ); - SLresult (*QuerySampleFormatsSupported)( - SLAudioIODeviceCapabilitiesItf self, - SLuint32 deviceId, - SLmilliHertz samplingRate, - SLint32 *pSampleFormats, - SLint32 *pNumOfSampleFormats - ); -}; - - - -/*---------------------------------------------------------------------------*/ -/* Capabilities of the LED array IODevice */ -/*---------------------------------------------------------------------------*/ - -typedef struct SLLEDDescriptor_ { - SLuint8 ledCount; - SLuint8 primaryLED; - SLuint32 colorMask; -} SLLEDDescriptor; - - -/*---------------------------------------------------------------------------*/ -/* LED Array interface */ -/*---------------------------------------------------------------------------*/ - -typedef struct SLHSL_ { - SLmillidegree hue; - SLpermille saturation; - SLpermille lightness; -} SLHSL; - - -extern SL_API const SLInterfaceID SL_IID_LED; - -struct SLLEDArrayItf_; -typedef const struct SLLEDArrayItf_ * const * SLLEDArrayItf; - -struct SLLEDArrayItf_ { - SLresult (*ActivateLEDArray) ( - SLLEDArrayItf self, - SLuint32 lightMask - ); - SLresult (*IsLEDArrayActivated) ( - SLLEDArrayItf self, - SLuint32 *lightMask - ); - SLresult (*SetColor) ( - SLLEDArrayItf self, - SLuint8 index, - const SLHSL *color - ); - SLresult (*GetColor) ( - SLLEDArrayItf self, - SLuint8 index, - SLHSL *color - ); -}; - -/*---------------------------------------------------------------------------*/ -/* Capabilities of the Vibra IODevice */ -/*---------------------------------------------------------------------------*/ - -typedef struct SLVibraDescriptor_ { - SLboolean supportsFrequency; - SLboolean supportsIntensity; - SLmilliHertz minFrequency; - SLmilliHertz maxFrequency; -} SLVibraDescriptor; - - - -/*---------------------------------------------------------------------------*/ -/* Vibra interface */ -/*---------------------------------------------------------------------------*/ - - -extern SL_API const SLInterfaceID SL_IID_VIBRA; - - -struct SLVibraItf_; -typedef const struct SLVibraItf_ * const * SLVibraItf; - -struct SLVibraItf_ { - SLresult (*Vibrate) ( - SLVibraItf self, - SLboolean vibrate - ); - SLresult (*IsVibrating) ( - SLVibraItf self, - SLboolean *pVibrating - ); - SLresult (*SetFrequency) ( - SLVibraItf self, - SLmilliHertz frequency - ); - SLresult (*GetFrequency) ( - SLVibraItf self, - SLmilliHertz *pFrequency - ); - SLresult (*SetIntensity) ( - SLVibraItf self, - SLpermille intensity - ); - SLresult (*GetIntensity) ( - SLVibraItf self, - SLpermille *pIntensity - ); -}; - - -/*---------------------------------------------------------------------------*/ -/* Meta data extraction related types and interface */ -/*---------------------------------------------------------------------------*/ - -#define SL_CHARACTERENCODING_UNKNOWN ((SLuint32) 0x00000000) -#define SL_CHARACTERENCODING_BINARY ((SLuint32) 0x00000001) -#define SL_CHARACTERENCODING_ASCII ((SLuint32) 0x00000002) -#define SL_CHARACTERENCODING_BIG5 ((SLuint32) 0x00000003) -#define SL_CHARACTERENCODING_CODEPAGE1252 ((SLuint32) 0x00000004) -#define SL_CHARACTERENCODING_GB2312 ((SLuint32) 0x00000005) -#define SL_CHARACTERENCODING_HZGB2312 ((SLuint32) 0x00000006) -#define SL_CHARACTERENCODING_GB12345 ((SLuint32) 0x00000007) -#define SL_CHARACTERENCODING_GB18030 ((SLuint32) 0x00000008) -#define SL_CHARACTERENCODING_GBK ((SLuint32) 0x00000009) -#define SL_CHARACTERENCODING_IMAPUTF7 ((SLuint32) 0x0000000A) -#define SL_CHARACTERENCODING_ISO2022JP ((SLuint32) 0x0000000B) -#define SL_CHARACTERENCODING_ISO2022JP1 ((SLuint32) 0x0000000B) -#define SL_CHARACTERENCODING_ISO88591 ((SLuint32) 0x0000000C) -#define SL_CHARACTERENCODING_ISO885910 ((SLuint32) 0x0000000D) -#define SL_CHARACTERENCODING_ISO885913 ((SLuint32) 0x0000000E) -#define SL_CHARACTERENCODING_ISO885914 ((SLuint32) 0x0000000F) -#define SL_CHARACTERENCODING_ISO885915 ((SLuint32) 0x00000010) -#define SL_CHARACTERENCODING_ISO88592 ((SLuint32) 0x00000011) -#define SL_CHARACTERENCODING_ISO88593 ((SLuint32) 0x00000012) -#define SL_CHARACTERENCODING_ISO88594 ((SLuint32) 0x00000013) -#define SL_CHARACTERENCODING_ISO88595 ((SLuint32) 0x00000014) -#define SL_CHARACTERENCODING_ISO88596 ((SLuint32) 0x00000015) -#define SL_CHARACTERENCODING_ISO88597 ((SLuint32) 0x00000016) -#define SL_CHARACTERENCODING_ISO88598 ((SLuint32) 0x00000017) -#define SL_CHARACTERENCODING_ISO88599 ((SLuint32) 0x00000018) -#define SL_CHARACTERENCODING_ISOEUCJP ((SLuint32) 0x00000019) -#define SL_CHARACTERENCODING_SHIFTJIS ((SLuint32) 0x0000001A) -#define SL_CHARACTERENCODING_SMS7BIT ((SLuint32) 0x0000001B) -#define SL_CHARACTERENCODING_UTF7 ((SLuint32) 0x0000001C) -#define SL_CHARACTERENCODING_UTF8 ((SLuint32) 0x0000001D) -#define SL_CHARACTERENCODING_JAVACONFORMANTUTF8 ((SLuint32) 0x0000001E) -#define SL_CHARACTERENCODING_UTF16BE ((SLuint32) 0x0000001F) -#define SL_CHARACTERENCODING_UTF16LE ((SLuint32) 0x00000020) - - -#define SL_METADATA_FILTER_KEY ((SLuint8) 0x01) -#define SL_METADATA_FILTER_LANG ((SLuint8) 0x02) -#define SL_METADATA_FILTER_ENCODING ((SLuint8) 0x04) - - -typedef struct SLMetadataInfo_ { - SLuint32 size; - SLuint32 encoding; - SLchar langCountry[16]; - SLuint8 data[1]; -} SLMetadataInfo; - -extern SL_API const SLInterfaceID SL_IID_METADATAEXTRACTION; - -struct SLMetadataExtractionItf_; -typedef const struct SLMetadataExtractionItf_ * const * SLMetadataExtractionItf; - - -struct SLMetadataExtractionItf_ { - SLresult (*GetItemCount) ( - SLMetadataExtractionItf self, - SLuint32 *pItemCount - ); - SLresult (*GetKeySize) ( - SLMetadataExtractionItf self, - SLuint32 index, - SLuint32 *pKeySize - ); - SLresult (*GetKey) ( - SLMetadataExtractionItf self, - SLuint32 index, - SLuint32 keySize, - SLMetadataInfo *pKey - ); - SLresult (*GetValueSize) ( - SLMetadataExtractionItf self, - SLuint32 index, - SLuint32 *pValueSize - ); - SLresult (*GetValue) ( - SLMetadataExtractionItf self, - SLuint32 index, - SLuint32 valueSize, - SLMetadataInfo *pValue - ); - SLresult (*AddKeyFilter) ( - SLMetadataExtractionItf self, - SLuint32 keySize, - const void *pKey, - SLuint32 keyEncoding, - const SLchar *pValueLangCountry, - SLuint32 valueEncoding, - SLuint8 filterMask - ); - SLresult (*ClearKeyFilter) ( - SLMetadataExtractionItf self - ); -}; - - -/*---------------------------------------------------------------------------*/ -/* Meta data traversal related types and interface */ -/*---------------------------------------------------------------------------*/ - -#define SL_METADATATRAVERSALMODE_ALL ((SLuint32) 0x00000001) -#define SL_METADATATRAVERSALMODE_NODE ((SLuint32) 0x00000002) - - -#define SL_NODETYPE_UNSPECIFIED ((SLuint32) 0x00000001) -#define SL_NODETYPE_AUDIO ((SLuint32) 0x00000002) -#define SL_NODETYPE_VIDEO ((SLuint32) 0x00000003) -#define SL_NODETYPE_IMAGE ((SLuint32) 0x00000004) - -#define SL_NODE_PARENT 0xFFFFFFFF - -extern SL_API const SLInterfaceID SL_IID_METADATATRAVERSAL; - -struct SLMetadataTraversalItf_; -typedef const struct SLMetadataTraversalItf_ * const * SLMetadataTraversalItf; - -struct SLMetadataTraversalItf_ { - SLresult (*SetMode) ( - SLMetadataTraversalItf self, - SLuint32 mode - ); - SLresult (*GetChildCount) ( - SLMetadataTraversalItf self, - SLuint32 *pCount - ); - SLresult (*GetChildMIMETypeSize) ( - SLMetadataTraversalItf self, - SLuint32 index, - SLuint32 *pSize - ); - SLresult (*GetChildInfo) ( - SLMetadataTraversalItf self, - SLuint32 index, - SLint32 *pNodeID, - SLuint32 *pType, - SLuint32 size, - SLchar *pMimeType - ); - SLresult (*SetActiveNode) ( - SLMetadataTraversalItf self, - SLuint32 index - ); -}; - -/*---------------------------------------------------------------------------*/ -/* Dynamic Source types and interface */ -/*---------------------------------------------------------------------------*/ - -extern SL_API const SLInterfaceID SL_IID_DYNAMICSOURCE; - -struct SLDynamicSourceItf_; -typedef const struct SLDynamicSourceItf_ * const * SLDynamicSourceItf; - -struct SLDynamicSourceItf_ { - SLresult (*SetSource) ( - SLDynamicSourceItf self, - SLDataSource *pDataSource - ); -}; - -/*---------------------------------------------------------------------------*/ -/* Output Mix interface */ -/*---------------------------------------------------------------------------*/ - -extern SL_API const SLInterfaceID SL_IID_OUTPUTMIX; - -struct SLOutputMixItf_; -typedef const struct SLOutputMixItf_ * const * SLOutputMixItf; - -typedef void (SLAPIENTRY *slMixDeviceChangeCallback) ( - SLOutputMixItf caller, - void *pContext -); - - -struct SLOutputMixItf_ { - SLresult (*GetDestinationOutputDeviceIDs) ( - SLOutputMixItf self, - SLint32 *pNumDevices, - SLuint32 *pDeviceIDs - ); - SLresult (*RegisterDeviceChangeCallback) ( - SLOutputMixItf self, - slMixDeviceChangeCallback callback, - void *pContext - ); - SLresult (*ReRoute)( - SLOutputMixItf self, - SLint32 numOutputDevices, - SLuint32 *pOutputDeviceIDs - ); -}; - - -/*---------------------------------------------------------------------------*/ -/* Playback interface */ -/*---------------------------------------------------------------------------*/ - -/** Playback states */ -#define SL_PLAYSTATE_STOPPED ((SLuint32) 0x00000001) -#define SL_PLAYSTATE_PAUSED ((SLuint32) 0x00000002) -#define SL_PLAYSTATE_PLAYING ((SLuint32) 0x00000003) - -/** Play events **/ -#define SL_PLAYEVENT_HEADATEND ((SLuint32) 0x00000001) -#define SL_PLAYEVENT_HEADATMARKER ((SLuint32) 0x00000002) -#define SL_PLAYEVENT_HEADATNEWPOS ((SLuint32) 0x00000004) -#define SL_PLAYEVENT_HEADMOVING ((SLuint32) 0x00000008) -#define SL_PLAYEVENT_HEADSTALLED ((SLuint32) 0x00000010) - -#define SL_TIME_UNKNOWN ((SLuint32) 0xFFFFFFFF) - - -extern SL_API const SLInterfaceID SL_IID_PLAY; - -/** Playback interface methods */ - -struct SLPlayItf_; -typedef const struct SLPlayItf_ * const * SLPlayItf; - -typedef void (SLAPIENTRY *slPlayCallback) ( - SLPlayItf caller, - void *pContext, - SLuint32 event -); - -struct SLPlayItf_ { - SLresult (*SetPlayState) ( - SLPlayItf self, - SLuint32 state - ); - SLresult (*GetPlayState) ( - SLPlayItf self, - SLuint32 *pState - ); - SLresult (*GetDuration) ( - SLPlayItf self, - SLmillisecond *pMsec - ); - SLresult (*GetPosition) ( - SLPlayItf self, - SLmillisecond *pMsec - ); - SLresult (*RegisterCallback) ( - SLPlayItf self, - slPlayCallback callback, - void *pContext - ); - SLresult (*SetCallbackEventsMask) ( - SLPlayItf self, - SLuint32 eventFlags - ); - SLresult (*GetCallbackEventsMask) ( - SLPlayItf self, - SLuint32 *pEventFlags - ); - SLresult (*SetMarkerPosition) ( - SLPlayItf self, - SLmillisecond mSec - ); - SLresult (*ClearMarkerPosition) ( - SLPlayItf self - ); - SLresult (*GetMarkerPosition) ( - SLPlayItf self, - SLmillisecond *pMsec - ); - SLresult (*SetPositionUpdatePeriod) ( - SLPlayItf self, - SLmillisecond mSec - ); - SLresult (*GetPositionUpdatePeriod) ( - SLPlayItf self, - SLmillisecond *pMsec - ); -}; - -/*---------------------------------------------------------------------------*/ -/* Prefetch status interface */ -/*---------------------------------------------------------------------------*/ - -#define SL_PREFETCHEVENT_STATUSCHANGE ((SLuint32) 0x00000001) -#define SL_PREFETCHEVENT_FILLLEVELCHANGE ((SLuint32) 0x00000002) - -#define SL_PREFETCHSTATUS_UNDERFLOW ((SLuint32) 0x00000001) -#define SL_PREFETCHSTATUS_SUFFICIENTDATA ((SLuint32) 0x00000002) -#define SL_PREFETCHSTATUS_OVERFLOW ((SLuint32) 0x00000003) - - -extern SL_API const SLInterfaceID SL_IID_PREFETCHSTATUS; - - -/** Prefetch status interface methods */ - -struct SLPrefetchStatusItf_; -typedef const struct SLPrefetchStatusItf_ * const * SLPrefetchStatusItf; - -typedef void (SLAPIENTRY *slPrefetchCallback) ( - SLPrefetchStatusItf caller, - void *pContext, - SLuint32 event -); - -struct SLPrefetchStatusItf_ { - SLresult (*GetPrefetchStatus) ( - SLPrefetchStatusItf self, - SLuint32 *pStatus - ); - SLresult (*GetFillLevel) ( - SLPrefetchStatusItf self, - SLpermille *pLevel - ); - SLresult (*RegisterCallback) ( - SLPrefetchStatusItf self, - slPrefetchCallback callback, - void *pContext - ); - SLresult (*SetCallbackEventsMask) ( - SLPrefetchStatusItf self, - SLuint32 eventFlags - ); - SLresult (*GetCallbackEventsMask) ( - SLPrefetchStatusItf self, - SLuint32 *pEventFlags - ); - SLresult (*SetFillUpdatePeriod) ( - SLPrefetchStatusItf self, - SLpermille period - ); - SLresult (*GetFillUpdatePeriod) ( - SLPrefetchStatusItf self, - SLpermille *pPeriod - ); -}; - -/*---------------------------------------------------------------------------*/ -/* Playback Rate interface */ -/*---------------------------------------------------------------------------*/ - -#define SL_RATEPROP_RESERVED1 ((SLuint32) 0x00000001) -#define SL_RATEPROP_RESERVED2 ((SLuint32) 0x00000002) -#define SL_RATEPROP_SILENTAUDIO ((SLuint32) 0x00000100) -#define SL_RATEPROP_STAGGEREDAUDIO ((SLuint32) 0x00000200) -#define SL_RATEPROP_NOPITCHCORAUDIO ((SLuint32) 0x00000400) -#define SL_RATEPROP_PITCHCORAUDIO ((SLuint32) 0x00000800) - - -extern SL_API const SLInterfaceID SL_IID_PLAYBACKRATE; - -struct SLPlaybackRateItf_; -typedef const struct SLPlaybackRateItf_ * const * SLPlaybackRateItf; - -struct SLPlaybackRateItf_ { - SLresult (*SetRate)( - SLPlaybackRateItf self, - SLpermille rate - ); - SLresult (*GetRate)( - SLPlaybackRateItf self, - SLpermille *pRate - ); - SLresult (*SetPropertyConstraints)( - SLPlaybackRateItf self, - SLuint32 constraints - ); - SLresult (*GetProperties)( - SLPlaybackRateItf self, - SLuint32 *pProperties - ); - SLresult (*GetCapabilitiesOfRate)( - SLPlaybackRateItf self, - SLpermille rate, - SLuint32 *pCapabilities - ); - SLresult (*GetRateRange) ( - SLPlaybackRateItf self, - SLuint8 index, - SLpermille *pMinRate, - SLpermille *pMaxRate, - SLpermille *pStepSize, - SLuint32 *pCapabilities - ); -}; - -/*---------------------------------------------------------------------------*/ -/* Seek Interface */ -/*---------------------------------------------------------------------------*/ - -#define SL_SEEKMODE_FAST ((SLuint32) 0x0001) -#define SL_SEEKMODE_ACCURATE ((SLuint32) 0x0002) - -extern SL_API const SLInterfaceID SL_IID_SEEK; - -struct SLSeekItf_; -typedef const struct SLSeekItf_ * const * SLSeekItf; - -struct SLSeekItf_ { - SLresult (*SetPosition)( - SLSeekItf self, - SLmillisecond pos, - SLuint32 seekMode - ); - SLresult (*SetLoop)( - SLSeekItf self, - SLboolean loopEnable, - SLmillisecond startPos, - SLmillisecond endPos - ); - SLresult (*GetLoop)( - SLSeekItf self, - SLboolean *pLoopEnabled, - SLmillisecond *pStartPos, - SLmillisecond *pEndPos - ); -}; - -/*---------------------------------------------------------------------------*/ -/* Standard Recording Interface */ -/*---------------------------------------------------------------------------*/ - -/** Recording states */ -#define SL_RECORDSTATE_STOPPED ((SLuint32) 0x00000001) -#define SL_RECORDSTATE_PAUSED ((SLuint32) 0x00000002) -#define SL_RECORDSTATE_RECORDING ((SLuint32) 0x00000003) - - -/** Record event **/ -#define SL_RECORDEVENT_HEADATLIMIT ((SLuint32) 0x00000001) -#define SL_RECORDEVENT_HEADATMARKER ((SLuint32) 0x00000002) -#define SL_RECORDEVENT_HEADATNEWPOS ((SLuint32) 0x00000004) -#define SL_RECORDEVENT_HEADMOVING ((SLuint32) 0x00000008) -#define SL_RECORDEVENT_HEADSTALLED ((SLuint32) 0x00000010) -/* Note: SL_RECORDEVENT_BUFFER_INSUFFICIENT is deprecated, use SL_RECORDEVENT_BUFFER_FULL instead. */ -#define SL_RECORDEVENT_BUFFER_INSUFFICIENT ((SLuint32) 0x00000020) -#define SL_RECORDEVENT_BUFFER_FULL ((SLuint32) 0x00000020) - - -extern SL_API const SLInterfaceID SL_IID_RECORD; - -struct SLRecordItf_; -typedef const struct SLRecordItf_ * const * SLRecordItf; - -typedef void (SLAPIENTRY *slRecordCallback) ( - SLRecordItf caller, - void *pContext, - SLuint32 event -); - -/** Recording interface methods */ -struct SLRecordItf_ { - SLresult (*SetRecordState) ( - SLRecordItf self, - SLuint32 state - ); - SLresult (*GetRecordState) ( - SLRecordItf self, - SLuint32 *pState - ); - SLresult (*SetDurationLimit) ( - SLRecordItf self, - SLmillisecond msec - ); - SLresult (*GetPosition) ( - SLRecordItf self, - SLmillisecond *pMsec - ); - SLresult (*RegisterCallback) ( - SLRecordItf self, - slRecordCallback callback, - void *pContext - ); - SLresult (*SetCallbackEventsMask) ( - SLRecordItf self, - SLuint32 eventFlags - ); - SLresult (*GetCallbackEventsMask) ( - SLRecordItf self, - SLuint32 *pEventFlags - ); - SLresult (*SetMarkerPosition) ( - SLRecordItf self, - SLmillisecond mSec - ); - SLresult (*ClearMarkerPosition) ( - SLRecordItf self - ); - SLresult (*GetMarkerPosition) ( - SLRecordItf self, - SLmillisecond *pMsec - ); - SLresult (*SetPositionUpdatePeriod) ( - SLRecordItf self, - SLmillisecond mSec - ); - SLresult (*GetPositionUpdatePeriod) ( - SLRecordItf self, - SLmillisecond *pMsec - ); -}; - -/*---------------------------------------------------------------------------*/ -/* Equalizer interface */ -/*---------------------------------------------------------------------------*/ - -#define SL_EQUALIZER_UNDEFINED ((SLuint16) 0xFFFF) - -extern SL_API const SLInterfaceID SL_IID_EQUALIZER; - -struct SLEqualizerItf_; -typedef const struct SLEqualizerItf_ * const * SLEqualizerItf; - -struct SLEqualizerItf_ { - SLresult (*SetEnabled)( - SLEqualizerItf self, - SLboolean enabled - ); - SLresult (*IsEnabled)( - SLEqualizerItf self, - SLboolean *pEnabled - ); - SLresult (*GetNumberOfBands)( - SLEqualizerItf self, - SLuint16 *pAmount - ); - SLresult (*GetBandLevelRange)( - SLEqualizerItf self, - SLmillibel *pMin, - SLmillibel *pMax - ); - SLresult (*SetBandLevel)( - SLEqualizerItf self, - SLuint16 band, - SLmillibel level - ); - SLresult (*GetBandLevel)( - SLEqualizerItf self, - SLuint16 band, - SLmillibel *pLevel - ); - SLresult (*GetCenterFreq)( - SLEqualizerItf self, - SLuint16 band, - SLmilliHertz *pCenter - ); - SLresult (*GetBandFreqRange)( - SLEqualizerItf self, - SLuint16 band, - SLmilliHertz *pMin, - SLmilliHertz *pMax - ); - SLresult (*GetBand)( - SLEqualizerItf self, - SLmilliHertz frequency, - SLuint16 *pBand - ); - SLresult (*GetCurrentPreset)( - SLEqualizerItf self, - SLuint16 *pPreset - ); - SLresult (*UsePreset)( - SLEqualizerItf self, - SLuint16 index - ); - SLresult (*GetNumberOfPresets)( - SLEqualizerItf self, - SLuint16 *pNumPresets - ); - SLresult (*GetPresetName)( - SLEqualizerItf self, - SLuint16 index, - const SLchar ** ppName - ); -}; - -/*---------------------------------------------------------------------------*/ -/* Volume Interface */ -/* --------------------------------------------------------------------------*/ - -extern SL_API const SLInterfaceID SL_IID_VOLUME; - -struct SLVolumeItf_; -typedef const struct SLVolumeItf_ * const * SLVolumeItf; - -struct SLVolumeItf_ { - SLresult (*SetVolumeLevel) ( - SLVolumeItf self, - SLmillibel level - ); - SLresult (*GetVolumeLevel) ( - SLVolumeItf self, - SLmillibel *pLevel - ); - SLresult (*GetMaxVolumeLevel) ( - SLVolumeItf self, - SLmillibel *pMaxLevel - ); - SLresult (*SetMute) ( - SLVolumeItf self, - SLboolean mute - ); - SLresult (*GetMute) ( - SLVolumeItf self, - SLboolean *pMute - ); - SLresult (*EnableStereoPosition) ( - SLVolumeItf self, - SLboolean enable - ); - SLresult (*IsEnabledStereoPosition) ( - SLVolumeItf self, - SLboolean *pEnable - ); - SLresult (*SetStereoPosition) ( - SLVolumeItf self, - SLpermille stereoPosition - ); - SLresult (*GetStereoPosition) ( - SLVolumeItf self, - SLpermille *pStereoPosition - ); -}; - - -/*---------------------------------------------------------------------------*/ -/* Device Volume Interface */ -/* --------------------------------------------------------------------------*/ - -extern SL_API const SLInterfaceID SL_IID_DEVICEVOLUME; - -struct SLDeviceVolumeItf_; -typedef const struct SLDeviceVolumeItf_ * const * SLDeviceVolumeItf; - -struct SLDeviceVolumeItf_ { - SLresult (*GetVolumeScale) ( - SLDeviceVolumeItf self, - SLuint32 deviceID, - SLint32 *pMinValue, - SLint32 *pMaxValue, - SLboolean *pIsMillibelScale - ); - SLresult (*SetVolume) ( - SLDeviceVolumeItf self, - SLuint32 deviceID, - SLint32 volume - ); - SLresult (*GetVolume) ( - SLDeviceVolumeItf self, - SLuint32 deviceID, - SLint32 *pVolume - ); -}; - - -/*---------------------------------------------------------------------------*/ -/* Buffer Queue Interface */ -/*---------------------------------------------------------------------------*/ - -extern SL_API const SLInterfaceID SL_IID_BUFFERQUEUE; - -struct SLBufferQueueItf_; -typedef const struct SLBufferQueueItf_ * const * SLBufferQueueItf; - -typedef void (SLAPIENTRY *slBufferQueueCallback)( - SLBufferQueueItf caller, - void *pContext -); - -/** Buffer queue state **/ - -typedef struct SLBufferQueueState_ { - SLuint32 count; - SLuint32 playIndex; -} SLBufferQueueState; - - -struct SLBufferQueueItf_ { - SLresult (*Enqueue) ( - SLBufferQueueItf self, - const void *pBuffer, - SLuint32 size - ); - SLresult (*Clear) ( - SLBufferQueueItf self - ); - SLresult (*GetState) ( - SLBufferQueueItf self, - SLBufferQueueState *pState - ); - SLresult (*RegisterCallback) ( - SLBufferQueueItf self, - slBufferQueueCallback callback, - void* pContext - ); -}; - - -/*---------------------------------------------------------------------------*/ -/* PresetReverb */ -/*---------------------------------------------------------------------------*/ - -#define SL_REVERBPRESET_NONE ((SLuint16) 0x0000) -#define SL_REVERBPRESET_SMALLROOM ((SLuint16) 0x0001) -#define SL_REVERBPRESET_MEDIUMROOM ((SLuint16) 0x0002) -#define SL_REVERBPRESET_LARGEROOM ((SLuint16) 0x0003) -#define SL_REVERBPRESET_MEDIUMHALL ((SLuint16) 0x0004) -#define SL_REVERBPRESET_LARGEHALL ((SLuint16) 0x0005) -#define SL_REVERBPRESET_PLATE ((SLuint16) 0x0006) - - -extern SL_API const SLInterfaceID SL_IID_PRESETREVERB; - -struct SLPresetReverbItf_; -typedef const struct SLPresetReverbItf_ * const * SLPresetReverbItf; - -struct SLPresetReverbItf_ { - SLresult (*SetPreset) ( - SLPresetReverbItf self, - SLuint16 preset - ); - SLresult (*GetPreset) ( - SLPresetReverbItf self, - SLuint16 *pPreset - ); -}; - - -/*---------------------------------------------------------------------------*/ -/* EnvironmentalReverb */ -/*---------------------------------------------------------------------------*/ - -#define SL_I3DL2_ENVIRONMENT_PRESET_DEFAULT \ - { SL_MILLIBEL_MIN, 0, 1000, 500, SL_MILLIBEL_MIN, 20, SL_MILLIBEL_MIN, 40, 1000,1000 } -#define SL_I3DL2_ENVIRONMENT_PRESET_GENERIC \ - { -1000, -100, 1490, 830, -2602, 7, 200, 11, 1000,1000 } -#define SL_I3DL2_ENVIRONMENT_PRESET_PADDEDCELL \ - { -1000,-6000, 170, 100, -1204, 1, 207, 2, 1000,1000 } -#define SL_I3DL2_ENVIRONMENT_PRESET_ROOM \ - { -1000, -454, 400, 830, -1646, 2, 53, 3, 1000,1000 } -#define SL_I3DL2_ENVIRONMENT_PRESET_BATHROOM \ - { -1000,-1200, 1490, 540, -370, 7, 1030, 11, 1000, 600 } -#define SL_I3DL2_ENVIRONMENT_PRESET_LIVINGROOM \ - { -1000,-6000, 500, 100, -1376, 3, -1104, 4, 1000,1000 } -#define SL_I3DL2_ENVIRONMENT_PRESET_STONEROOM \ - { -1000, -300, 2310, 640, -711, 12, 83, 17, 1000,1000 } -#define SL_I3DL2_ENVIRONMENT_PRESET_AUDITORIUM \ - { -1000, -476, 4320, 590, -789, 20, -289, 30, 1000,1000 } -#define SL_I3DL2_ENVIRONMENT_PRESET_CONCERTHALL \ - { -1000, -500, 3920, 700, -1230, 20, -2, 29, 1000,1000 } -#define SL_I3DL2_ENVIRONMENT_PRESET_CAVE \ - { -1000, 0, 2910, 1300, -602, 15, -302, 22, 1000,1000 } -#define SL_I3DL2_ENVIRONMENT_PRESET_ARENA \ - { -1000, -698, 7240, 330, -1166, 20, 16, 30, 1000,1000 } -#define SL_I3DL2_ENVIRONMENT_PRESET_HANGAR \ - { -1000,-1000, 10050, 230, -602, 20, 198, 30, 1000,1000 } -#define SL_I3DL2_ENVIRONMENT_PRESET_CARPETEDHALLWAY \ - { -1000,-4000, 300, 100, -1831, 2, -1630, 30, 1000,1000 } -#define SL_I3DL2_ENVIRONMENT_PRESET_HALLWAY \ - { -1000, -300, 1490, 590, -1219, 7, 441, 11, 1000,1000 } -#define SL_I3DL2_ENVIRONMENT_PRESET_STONECORRIDOR \ - { -1000, -237, 2700, 790, -1214, 13, 395, 20, 1000,1000 } -#define SL_I3DL2_ENVIRONMENT_PRESET_ALLEY \ - { -1000, -270, 1490, 860, -1204, 7, -4, 11, 1000,1000 } -#define SL_I3DL2_ENVIRONMENT_PRESET_FOREST \ - { -1000,-3300, 1490, 540, -2560, 162, -613, 88, 790,1000 } -#define SL_I3DL2_ENVIRONMENT_PRESET_CITY \ - { -1000, -800, 1490, 670, -2273, 7, -2217, 11, 500,1000 } -#define SL_I3DL2_ENVIRONMENT_PRESET_MOUNTAINS \ - { -1000,-2500, 1490, 210, -2780, 300, -2014, 100, 270,1000 } -#define SL_I3DL2_ENVIRONMENT_PRESET_QUARRY \ - { -1000,-1000, 1490, 830, SL_MILLIBEL_MIN, 61, 500, 25, 1000,1000 } -#define SL_I3DL2_ENVIRONMENT_PRESET_PLAIN \ - { -1000,-2000, 1490, 500, -2466, 179, -2514, 100, 210,1000 } -#define SL_I3DL2_ENVIRONMENT_PRESET_PARKINGLOT \ - { -1000, 0, 1650, 1500, -1363, 8, -1153, 12, 1000,1000 } -#define SL_I3DL2_ENVIRONMENT_PRESET_SEWERPIPE \ - { -1000,-1000, 2810, 140, 429, 14, 648, 21, 800, 600 } -#define SL_I3DL2_ENVIRONMENT_PRESET_UNDERWATER \ - { -1000,-4000, 1490, 100, -449, 7, 1700, 11, 1000,1000 } -#define SL_I3DL2_ENVIRONMENT_PRESET_SMALLROOM \ - { -1000,-600, 1100, 830, -400, 5, 500, 10, 1000, 1000 } -#define SL_I3DL2_ENVIRONMENT_PRESET_MEDIUMROOM \ - { -1000,-600, 1300, 830, -1000, 20, -200, 20, 1000, 1000 } -#define SL_I3DL2_ENVIRONMENT_PRESET_LARGEROOM \ - { -1000,-600, 1500, 830, -1600, 5, -1000, 40, 1000, 1000 } -#define SL_I3DL2_ENVIRONMENT_PRESET_MEDIUMHALL \ - { -1000,-600, 1800, 700, -1300, 15, -800, 30, 1000, 1000 } -#define SL_I3DL2_ENVIRONMENT_PRESET_LARGEHALL \ - { -1000,-600, 1800, 700, -2000, 30, -1400, 60, 1000, 1000 } -#define SL_I3DL2_ENVIRONMENT_PRESET_PLATE \ - { -1000,-200, 1300, 900, 0, 2, 0, 10, 1000, 750 } - - -typedef struct SLEnvironmentalReverbSettings_ { - SLmillibel roomLevel; - SLmillibel roomHFLevel; - SLmillisecond decayTime; - SLpermille decayHFRatio; - SLmillibel reflectionsLevel; - SLmillisecond reflectionsDelay; - SLmillibel reverbLevel; - SLmillisecond reverbDelay; - SLpermille diffusion; - SLpermille density; -} SLEnvironmentalReverbSettings; - - - - -extern SL_API const SLInterfaceID SL_IID_ENVIRONMENTALREVERB; - - -struct SLEnvironmentalReverbItf_; -typedef const struct SLEnvironmentalReverbItf_ * const * SLEnvironmentalReverbItf; - -struct SLEnvironmentalReverbItf_ { - SLresult (*SetRoomLevel) ( - SLEnvironmentalReverbItf self, - SLmillibel room - ); - SLresult (*GetRoomLevel) ( - SLEnvironmentalReverbItf self, - SLmillibel *pRoom - ); - SLresult (*SetRoomHFLevel) ( - SLEnvironmentalReverbItf self, - SLmillibel roomHF - ); - SLresult (*GetRoomHFLevel) ( - SLEnvironmentalReverbItf self, - SLmillibel *pRoomHF - ); - SLresult (*SetDecayTime) ( - SLEnvironmentalReverbItf self, - SLmillisecond decayTime - ); - SLresult (*GetDecayTime) ( - SLEnvironmentalReverbItf self, - SLmillisecond *pDecayTime - ); - SLresult (*SetDecayHFRatio) ( - SLEnvironmentalReverbItf self, - SLpermille decayHFRatio - ); - SLresult (*GetDecayHFRatio) ( - SLEnvironmentalReverbItf self, - SLpermille *pDecayHFRatio - ); - SLresult (*SetReflectionsLevel) ( - SLEnvironmentalReverbItf self, - SLmillibel reflectionsLevel - ); - SLresult (*GetReflectionsLevel) ( - SLEnvironmentalReverbItf self, - SLmillibel *pReflectionsLevel - ); - SLresult (*SetReflectionsDelay) ( - SLEnvironmentalReverbItf self, - SLmillisecond reflectionsDelay - ); - SLresult (*GetReflectionsDelay) ( - SLEnvironmentalReverbItf self, - SLmillisecond *pReflectionsDelay - ); - SLresult (*SetReverbLevel) ( - SLEnvironmentalReverbItf self, - SLmillibel reverbLevel - ); - SLresult (*GetReverbLevel) ( - SLEnvironmentalReverbItf self, - SLmillibel *pReverbLevel - ); - SLresult (*SetReverbDelay) ( - SLEnvironmentalReverbItf self, - SLmillisecond reverbDelay - ); - SLresult (*GetReverbDelay) ( - SLEnvironmentalReverbItf self, - SLmillisecond *pReverbDelay - ); - SLresult (*SetDiffusion) ( - SLEnvironmentalReverbItf self, - SLpermille diffusion - ); - SLresult (*GetDiffusion) ( - SLEnvironmentalReverbItf self, - SLpermille *pDiffusion - ); - SLresult (*SetDensity) ( - SLEnvironmentalReverbItf self, - SLpermille density - ); - SLresult (*GetDensity) ( - SLEnvironmentalReverbItf self, - SLpermille *pDensity - ); - SLresult (*SetEnvironmentalReverbProperties) ( - SLEnvironmentalReverbItf self, - const SLEnvironmentalReverbSettings *pProperties - ); - SLresult (*GetEnvironmentalReverbProperties) ( - SLEnvironmentalReverbItf self, - SLEnvironmentalReverbSettings *pProperties - ); -}; - -/*---------------------------------------------------------------------------*/ -/* Effects Send Interface */ -/*---------------------------------------------------------------------------*/ - - -extern SL_API const SLInterfaceID SL_IID_EFFECTSEND; - -struct SLEffectSendItf_; -typedef const struct SLEffectSendItf_ * const * SLEffectSendItf; - -struct SLEffectSendItf_ { - SLresult (*EnableEffectSend) ( - SLEffectSendItf self, - const void *pAuxEffect, - SLboolean enable, - SLmillibel initialLevel - ); - SLresult (*IsEnabled) ( - SLEffectSendItf self, - const void * pAuxEffect, - SLboolean *pEnable - ); - SLresult (*SetDirectLevel) ( - SLEffectSendItf self, - SLmillibel directLevel - ); - SLresult (*GetDirectLevel) ( - SLEffectSendItf self, - SLmillibel *pDirectLevel - ); - SLresult (*SetSendLevel) ( - SLEffectSendItf self, - const void *pAuxEffect, - SLmillibel sendLevel - ); - SLresult (*GetSendLevel)( - SLEffectSendItf self, - const void *pAuxEffect, - SLmillibel *pSendLevel - ); -}; - - -/*---------------------------------------------------------------------------*/ -/* 3D Grouping Interface */ -/*---------------------------------------------------------------------------*/ - - -extern SL_API const SLInterfaceID SL_IID_3DGROUPING; - - -struct SL3DGroupingItf_ ; -typedef const struct SL3DGroupingItf_ * const * SL3DGroupingItf; - -struct SL3DGroupingItf_ { - SLresult (*Set3DGroup) ( - SL3DGroupingItf self, - SLObjectItf group - ); - SLresult (*Get3DGroup) ( - SL3DGroupingItf self, - SLObjectItf *pGroup - ); -}; - - -/*---------------------------------------------------------------------------*/ -/* 3D Commit Interface */ -/*---------------------------------------------------------------------------*/ - - -extern SL_API const SLInterfaceID SL_IID_3DCOMMIT; - -struct SL3DCommitItf_; -typedef const struct SL3DCommitItf_* const * SL3DCommitItf; - -struct SL3DCommitItf_ { - SLresult (*Commit) ( - SL3DCommitItf self - ); - SLresult (*SetDeferred) ( - SL3DCommitItf self, - SLboolean deferred - ); -}; - - -/*---------------------------------------------------------------------------*/ -/* 3D Location Interface */ -/*---------------------------------------------------------------------------*/ - -typedef struct SLVec3D_ { - SLint32 x; - SLint32 y; - SLint32 z; -} SLVec3D; - -extern SL_API const SLInterfaceID SL_IID_3DLOCATION; - -struct SL3DLocationItf_; -typedef const struct SL3DLocationItf_ * const * SL3DLocationItf; - -struct SL3DLocationItf_ { - SLresult (*SetLocationCartesian) ( - SL3DLocationItf self, - const SLVec3D *pLocation - ); - SLresult (*SetLocationSpherical) ( - SL3DLocationItf self, - SLmillidegree azimuth, - SLmillidegree elevation, - SLmillimeter distance - ); - SLresult (*Move) ( - SL3DLocationItf self, - const SLVec3D *pMovement - ); - SLresult (*GetLocationCartesian) ( - SL3DLocationItf self, - SLVec3D *pLocation - ); - SLresult (*SetOrientationVectors) ( - SL3DLocationItf self, - const SLVec3D *pFront, - const SLVec3D *pAbove - ); - SLresult (*SetOrientationAngles) ( - SL3DLocationItf self, - SLmillidegree heading, - SLmillidegree pitch, - SLmillidegree roll - ); - SLresult (*Rotate) ( - SL3DLocationItf self, - SLmillidegree theta, - const SLVec3D *pAxis - ); - SLresult (*GetOrientationVectors) ( - SL3DLocationItf self, - SLVec3D *pFront, - SLVec3D *pUp - ); -}; - - -/*---------------------------------------------------------------------------*/ -/* 3D Doppler Interface */ -/*---------------------------------------------------------------------------*/ - - -extern SL_API const SLInterfaceID SL_IID_3DDOPPLER; - -struct SL3DDopplerItf_; -typedef const struct SL3DDopplerItf_ * const * SL3DDopplerItf; - -struct SL3DDopplerItf_ { - SLresult (*SetVelocityCartesian) ( - SL3DDopplerItf self, - const SLVec3D *pVelocity - ); - SLresult (*SetVelocitySpherical) ( - SL3DDopplerItf self, - SLmillidegree azimuth, - SLmillidegree elevation, - SLmillimeter speed - ); - SLresult (*GetVelocityCartesian) ( - SL3DDopplerItf self, - SLVec3D *pVelocity - ); - SLresult (*SetDopplerFactor) ( - SL3DDopplerItf self, - SLpermille dopplerFactor - ); - SLresult (*GetDopplerFactor) ( - SL3DDopplerItf self, - SLpermille *pDopplerFactor - ); -}; - -/*---------------------------------------------------------------------------*/ -/* 3D Source Interface and associated defines */ -/* --------------------------------------------------------------------------*/ - -#define SL_ROLLOFFMODEL_EXPONENTIAL ((SLuint32) 0x00000000) -#define SL_ROLLOFFMODEL_LINEAR ((SLuint32) 0x00000001) - - -extern SL_API const SLInterfaceID SL_IID_3DSOURCE; - -struct SL3DSourceItf_; -typedef const struct SL3DSourceItf_ * const * SL3DSourceItf; - -struct SL3DSourceItf_ { - SLresult (*SetHeadRelative) ( - SL3DSourceItf self, - SLboolean headRelative - ); - SLresult (*GetHeadRelative) ( - SL3DSourceItf self, - SLboolean *pHeadRelative - ); - SLresult (*SetRolloffDistances) ( - SL3DSourceItf self, - SLmillimeter minDistance, - SLmillimeter maxDistance - ); - SLresult (*GetRolloffDistances) ( - SL3DSourceItf self, - SLmillimeter *pMinDistance, - SLmillimeter *pMaxDistance - ); - SLresult (*SetRolloffMaxDistanceMute) ( - SL3DSourceItf self, - SLboolean mute - ); - SLresult (*GetRolloffMaxDistanceMute) ( - SL3DSourceItf self, - SLboolean *pMute - ); - SLresult (*SetRolloffFactor) ( - SL3DSourceItf self, - SLpermille rolloffFactor - ); - SLresult (*GetRolloffFactor) ( - SL3DSourceItf self, - SLpermille *pRolloffFactor - ); - SLresult (*SetRoomRolloffFactor) ( - SL3DSourceItf self, - SLpermille roomRolloffFactor - ); - SLresult (*GetRoomRolloffFactor) ( - SL3DSourceItf self, - SLpermille *pRoomRolloffFactor - ); - SLresult (*SetRolloffModel) ( - SL3DSourceItf self, - SLuint8 model - ); - SLresult (*GetRolloffModel) ( - SL3DSourceItf self, - SLuint8 *pModel - ); - SLresult (*SetCone) ( - SL3DSourceItf self, - SLmillidegree innerAngle, - SLmillidegree outerAngle, - SLmillibel outerLevel - ); - SLresult (*GetCone) ( - SL3DSourceItf self, - SLmillidegree *pInnerAngle, - SLmillidegree *pOuterAngle, - SLmillibel *pOuterLevel - ); -}; - -/*---------------------------------------------------------------------------*/ -/* 3D Macroscopic Interface */ -/* --------------------------------------------------------------------------*/ - -extern SL_API const SLInterfaceID SL_IID_3DMACROSCOPIC; - -struct SL3DMacroscopicItf_; -typedef const struct SL3DMacroscopicItf_ * const * SL3DMacroscopicItf; - -struct SL3DMacroscopicItf_ { - SLresult (*SetSize) ( - SL3DMacroscopicItf self, - SLmillimeter width, - SLmillimeter height, - SLmillimeter depth - ); - SLresult (*GetSize) ( - SL3DMacroscopicItf self, - SLmillimeter *pWidth, - SLmillimeter *pHeight, - SLmillimeter *pDepth - ); - SLresult (*SetOrientationAngles) ( - SL3DMacroscopicItf self, - SLmillidegree heading, - SLmillidegree pitch, - SLmillidegree roll - ); - SLresult (*SetOrientationVectors) ( - SL3DMacroscopicItf self, - const SLVec3D *pFront, - const SLVec3D *pAbove - ); - SLresult (*Rotate) ( - SL3DMacroscopicItf self, - SLmillidegree theta, - const SLVec3D *pAxis - ); - SLresult (*GetOrientationVectors) ( - SL3DMacroscopicItf self, - SLVec3D *pFront, - SLVec3D *pUp - ); -}; - -/*---------------------------------------------------------------------------*/ -/* Mute Solo Interface */ -/* --------------------------------------------------------------------------*/ - - -extern SL_API const SLInterfaceID SL_IID_MUTESOLO; - -struct SLMuteSoloItf_; -typedef const struct SLMuteSoloItf_ * const * SLMuteSoloItf; - -struct SLMuteSoloItf_ { - SLresult (*SetChannelMute) ( - SLMuteSoloItf self, - SLuint8 chan, - SLboolean mute - ); - SLresult (*GetChannelMute) ( - SLMuteSoloItf self, - SLuint8 chan, - SLboolean *pMute - ); - SLresult (*SetChannelSolo) ( - SLMuteSoloItf self, - SLuint8 chan, - SLboolean solo - ); - SLresult (*GetChannelSolo) ( - SLMuteSoloItf self, - SLuint8 chan, - SLboolean *pSolo - ); - SLresult (*GetNumChannels) ( - SLMuteSoloItf self, - SLuint8 *pNumChannels - ); -}; - - -/*---------------------------------------------------------------------------*/ -/* Dynamic Interface Management Interface and associated types and macros */ -/* --------------------------------------------------------------------------*/ - -#define SL_DYNAMIC_ITF_EVENT_RUNTIME_ERROR ((SLuint32) 0x00000001) -#define SL_DYNAMIC_ITF_EVENT_ASYNC_TERMINATION ((SLuint32) 0x00000002) -#define SL_DYNAMIC_ITF_EVENT_RESOURCES_LOST ((SLuint32) 0x00000003) -#define SL_DYNAMIC_ITF_EVENT_RESOURCES_LOST_PERMANENTLY ((SLuint32) 0x00000004) -#define SL_DYNAMIC_ITF_EVENT_RESOURCES_AVAILABLE ((SLuint32) 0x00000005) - - - - -extern SL_API const SLInterfaceID SL_IID_DYNAMICINTERFACEMANAGEMENT; - -struct SLDynamicInterfaceManagementItf_; -typedef const struct SLDynamicInterfaceManagementItf_ * const * SLDynamicInterfaceManagementItf; - -typedef void (SLAPIENTRY *slDynamicInterfaceManagementCallback) ( - SLDynamicInterfaceManagementItf caller, - void * pContext, - SLuint32 event, - SLresult result, - const SLInterfaceID iid -); - - -struct SLDynamicInterfaceManagementItf_ { - SLresult (*AddInterface) ( - SLDynamicInterfaceManagementItf self, - const SLInterfaceID iid, - SLboolean async - ); - SLresult (*RemoveInterface) ( - SLDynamicInterfaceManagementItf self, - const SLInterfaceID iid - ); - SLresult (*ResumeInterface) ( - SLDynamicInterfaceManagementItf self, - const SLInterfaceID iid, - SLboolean async - ); - SLresult (*RegisterCallback) ( - SLDynamicInterfaceManagementItf self, - slDynamicInterfaceManagementCallback callback, - void * pContext - ); -}; - -/*---------------------------------------------------------------------------*/ -/* Midi Message Interface and associated types */ -/* --------------------------------------------------------------------------*/ - -#define SL_MIDIMESSAGETYPE_NOTE_ON_OFF ((SLuint32) 0x00000001) -#define SL_MIDIMESSAGETYPE_POLY_PRESSURE ((SLuint32) 0x00000002) -#define SL_MIDIMESSAGETYPE_CONTROL_CHANGE ((SLuint32) 0x00000003) -#define SL_MIDIMESSAGETYPE_PROGRAM_CHANGE ((SLuint32) 0x00000004) -#define SL_MIDIMESSAGETYPE_CHANNEL_PRESSURE ((SLuint32) 0x00000005) -#define SL_MIDIMESSAGETYPE_PITCH_BEND ((SLuint32) 0x00000006) -#define SL_MIDIMESSAGETYPE_SYSTEM_MESSAGE ((SLuint32) 0x00000007) - - -extern SL_API const SLInterfaceID SL_IID_MIDIMESSAGE; - -struct SLMIDIMessageItf_; -typedef const struct SLMIDIMessageItf_ * const * SLMIDIMessageItf; - -typedef void (SLAPIENTRY *slMetaEventCallback) ( - SLMIDIMessageItf caller, - void *pContext, - SLuint8 type, - SLuint32 length, - const SLuint8 *pData, - SLuint32 tick, - SLuint16 track -); - -typedef void (SLAPIENTRY *slMIDIMessageCallback) ( - SLMIDIMessageItf caller, - void *pContext, - SLuint8 statusByte, - SLuint32 length, - const SLuint8 *pData, - SLuint32 tick, - SLuint16 track -); - -struct SLMIDIMessageItf_ { - SLresult (*SendMessage) ( - SLMIDIMessageItf self, - const SLuint8 *data, - SLuint32 length - ); - SLresult (*RegisterMetaEventCallback) ( - SLMIDIMessageItf self, - slMetaEventCallback callback, - void *pContext - ); - SLresult (*RegisterMIDIMessageCallback) ( - SLMIDIMessageItf self, - slMIDIMessageCallback callback, - void *pContext - ); - SLresult (*AddMIDIMessageCallbackFilter) ( - SLMIDIMessageItf self, - SLuint32 messageType - ); - SLresult (*ClearMIDIMessageCallbackFilter) ( - SLMIDIMessageItf self - ); -}; - - -/*---------------------------------------------------------------------------*/ -/* Midi Mute Solo interface */ -/* --------------------------------------------------------------------------*/ - - -extern SL_API const SLInterfaceID SL_IID_MIDIMUTESOLO; - -struct SLMIDIMuteSoloItf_; -typedef const struct SLMIDIMuteSoloItf_ * const * SLMIDIMuteSoloItf; - -struct SLMIDIMuteSoloItf_ { - SLresult (*SetChannelMute) ( - SLMIDIMuteSoloItf self, - SLuint8 channel, - SLboolean mute - ); - SLresult (*GetChannelMute) ( - SLMIDIMuteSoloItf self, - SLuint8 channel, - SLboolean *pMute - ); - SLresult (*SetChannelSolo) ( - SLMIDIMuteSoloItf self, - SLuint8 channel, - SLboolean solo - ); - SLresult (*GetChannelSolo) ( - SLMIDIMuteSoloItf self, - SLuint8 channel, - SLboolean *pSolo - ); - SLresult (*GetTrackCount) ( - SLMIDIMuteSoloItf self, - SLuint16 *pCount - ); - SLresult (*SetTrackMute) ( - SLMIDIMuteSoloItf self, - SLuint16 track, - SLboolean mute - ); - SLresult (*GetTrackMute) ( - SLMIDIMuteSoloItf self, - SLuint16 track, - SLboolean *pMute - ); - SLresult (*SetTrackSolo) ( - SLMIDIMuteSoloItf self, - SLuint16 track, - SLboolean solo - ); - SLresult (*GetTrackSolo) ( - SLMIDIMuteSoloItf self, - SLuint16 track, - SLboolean *pSolo - ); -}; - - -/*---------------------------------------------------------------------------*/ -/* Midi Tempo interface */ -/* --------------------------------------------------------------------------*/ - - -extern SL_API const SLInterfaceID SL_IID_MIDITEMPO; - -struct SLMIDITempoItf_; -typedef const struct SLMIDITempoItf_ * const * SLMIDITempoItf; - -struct SLMIDITempoItf_ { - SLresult (*SetTicksPerQuarterNote) ( - SLMIDITempoItf self, - SLuint32 tpqn - ); - SLresult (*GetTicksPerQuarterNote) ( - SLMIDITempoItf self, - SLuint32 *pTpqn - ); - SLresult (*SetMicrosecondsPerQuarterNote) ( - SLMIDITempoItf self, - SLmicrosecond uspqn - ); - SLresult (*GetMicrosecondsPerQuarterNote) ( - SLMIDITempoItf self, - SLmicrosecond *uspqn - ); -}; - - -/*---------------------------------------------------------------------------*/ -/* Midi Time interface */ -/* --------------------------------------------------------------------------*/ - - -extern SL_API const SLInterfaceID SL_IID_MIDITIME; - -struct SLMIDITimeItf_; -typedef const struct SLMIDITimeItf_ * const * SLMIDITimeItf; - -struct SLMIDITimeItf_ { - SLresult (*GetDuration) ( - SLMIDITimeItf self, - SLuint32 *pDuration - ); - SLresult (*SetPosition) ( - SLMIDITimeItf self, - SLuint32 position - ); - SLresult (*GetPosition) ( - SLMIDITimeItf self, - SLuint32 *pPosition - ); - SLresult (*SetLoopPoints) ( - SLMIDITimeItf self, - SLuint32 startTick, - SLuint32 numTicks - ); - SLresult (*GetLoopPoints) ( - SLMIDITimeItf self, - SLuint32 *pStartTick, - SLuint32 *pNumTicks - ); -}; - - -/*---------------------------------------------------------------------------*/ -/* Audio Decoder Capabilities Interface */ -/* --------------------------------------------------------------------------*/ - -/*Audio Codec related defines*/ - -#define SL_RATECONTROLMODE_CONSTANTBITRATE ((SLuint32) 0x00000001) -#define SL_RATECONTROLMODE_VARIABLEBITRATE ((SLuint32) 0x00000002) - -#define SL_AUDIOCODEC_PCM ((SLuint32) 0x00000001) -#define SL_AUDIOCODEC_MP3 ((SLuint32) 0x00000002) -#define SL_AUDIOCODEC_AMR ((SLuint32) 0x00000003) -#define SL_AUDIOCODEC_AMRWB ((SLuint32) 0x00000004) -#define SL_AUDIOCODEC_AMRWBPLUS ((SLuint32) 0x00000005) -#define SL_AUDIOCODEC_AAC ((SLuint32) 0x00000006) -#define SL_AUDIOCODEC_WMA ((SLuint32) 0x00000007) -#define SL_AUDIOCODEC_REAL ((SLuint32) 0x00000008) - -#define SL_AUDIOPROFILE_PCM ((SLuint32) 0x00000001) - -#define SL_AUDIOPROFILE_MPEG1_L3 ((SLuint32) 0x00000001) -#define SL_AUDIOPROFILE_MPEG2_L3 ((SLuint32) 0x00000002) -#define SL_AUDIOPROFILE_MPEG25_L3 ((SLuint32) 0x00000003) - -#define SL_AUDIOCHANMODE_MP3_MONO ((SLuint32) 0x00000001) -#define SL_AUDIOCHANMODE_MP3_STEREO ((SLuint32) 0x00000002) -#define SL_AUDIOCHANMODE_MP3_JOINTSTEREO ((SLuint32) 0x00000003) -#define SL_AUDIOCHANMODE_MP3_DUAL ((SLuint32) 0x00000004) - -#define SL_AUDIOPROFILE_AMR ((SLuint32) 0x00000001) - -#define SL_AUDIOSTREAMFORMAT_CONFORMANCE ((SLuint32) 0x00000001) -#define SL_AUDIOSTREAMFORMAT_IF1 ((SLuint32) 0x00000002) -#define SL_AUDIOSTREAMFORMAT_IF2 ((SLuint32) 0x00000003) -#define SL_AUDIOSTREAMFORMAT_FSF ((SLuint32) 0x00000004) -#define SL_AUDIOSTREAMFORMAT_RTPPAYLOAD ((SLuint32) 0x00000005) -#define SL_AUDIOSTREAMFORMAT_ITU ((SLuint32) 0x00000006) - -#define SL_AUDIOPROFILE_AMRWB ((SLuint32) 0x00000001) - -#define SL_AUDIOPROFILE_AMRWBPLUS ((SLuint32) 0x00000001) - -#define SL_AUDIOPROFILE_AAC_AAC ((SLuint32) 0x00000001) - -#define SL_AUDIOMODE_AAC_MAIN ((SLuint32) 0x00000001) -#define SL_AUDIOMODE_AAC_LC ((SLuint32) 0x00000002) -#define SL_AUDIOMODE_AAC_SSR ((SLuint32) 0x00000003) -#define SL_AUDIOMODE_AAC_LTP ((SLuint32) 0x00000004) -#define SL_AUDIOMODE_AAC_HE ((SLuint32) 0x00000005) -#define SL_AUDIOMODE_AAC_SCALABLE ((SLuint32) 0x00000006) -#define SL_AUDIOMODE_AAC_ERLC ((SLuint32) 0x00000007) -#define SL_AUDIOMODE_AAC_LD ((SLuint32) 0x00000008) -#define SL_AUDIOMODE_AAC_HE_PS ((SLuint32) 0x00000009) -#define SL_AUDIOMODE_AAC_HE_MPS ((SLuint32) 0x0000000A) - -#define SL_AUDIOSTREAMFORMAT_MP2ADTS ((SLuint32) 0x00000001) -#define SL_AUDIOSTREAMFORMAT_MP4ADTS ((SLuint32) 0x00000002) -#define SL_AUDIOSTREAMFORMAT_MP4LOAS ((SLuint32) 0x00000003) -#define SL_AUDIOSTREAMFORMAT_MP4LATM ((SLuint32) 0x00000004) -#define SL_AUDIOSTREAMFORMAT_ADIF ((SLuint32) 0x00000005) -#define SL_AUDIOSTREAMFORMAT_MP4FF ((SLuint32) 0x00000006) -#define SL_AUDIOSTREAMFORMAT_RAW ((SLuint32) 0x00000007) - -#define SL_AUDIOPROFILE_WMA7 ((SLuint32) 0x00000001) -#define SL_AUDIOPROFILE_WMA8 ((SLuint32) 0x00000002) -#define SL_AUDIOPROFILE_WMA9 ((SLuint32) 0x00000003) -#define SL_AUDIOPROFILE_WMA10 ((SLuint32) 0x00000004) - -#define SL_AUDIOMODE_WMA_LEVEL1 ((SLuint32) 0x00000001) -#define SL_AUDIOMODE_WMA_LEVEL2 ((SLuint32) 0x00000002) -#define SL_AUDIOMODE_WMA_LEVEL3 ((SLuint32) 0x00000003) -#define SL_AUDIOMODE_WMA_LEVEL4 ((SLuint32) 0x00000004) -#define SL_AUDIOMODE_WMAPRO_LEVELM0 ((SLuint32) 0x00000005) -#define SL_AUDIOMODE_WMAPRO_LEVELM1 ((SLuint32) 0x00000006) -#define SL_AUDIOMODE_WMAPRO_LEVELM2 ((SLuint32) 0x00000007) -#define SL_AUDIOMODE_WMAPRO_LEVELM3 ((SLuint32) 0x00000008) - -#define SL_AUDIOPROFILE_REALAUDIO ((SLuint32) 0x00000001) - -#define SL_AUDIOMODE_REALAUDIO_G2 ((SLuint32) 0x00000001) -#define SL_AUDIOMODE_REALAUDIO_8 ((SLuint32) 0x00000002) -#define SL_AUDIOMODE_REALAUDIO_10 ((SLuint32) 0x00000003) -#define SL_AUDIOMODE_REALAUDIO_SURROUND ((SLuint32) 0x00000004) - -typedef struct SLAudioCodecDescriptor_ { - SLuint32 maxChannels; - SLuint32 minBitsPerSample; - SLuint32 maxBitsPerSample; - SLmilliHertz minSampleRate; - SLmilliHertz maxSampleRate; - SLboolean isFreqRangeContinuous; - SLmilliHertz *pSampleRatesSupported; - SLuint32 numSampleRatesSupported; - SLuint32 minBitRate; - SLuint32 maxBitRate; - SLboolean isBitrateRangeContinuous; - SLuint32 *pBitratesSupported; - SLuint32 numBitratesSupported; - SLuint32 profileSetting; - SLuint32 modeSetting; -} SLAudioCodecDescriptor; - -/*Structure used to retrieve the profile and level settings supported by an audio encoder */ - -typedef struct SLAudioCodecProfileMode_ { - SLuint32 profileSetting; - SLuint32 modeSetting; -} SLAudioCodecProfileMode; - -extern SL_API const SLInterfaceID SL_IID_AUDIODECODERCAPABILITIES; - -struct SLAudioDecoderCapabilitiesItf_; -typedef const struct SLAudioDecoderCapabilitiesItf_ * const * SLAudioDecoderCapabilitiesItf; - -struct SLAudioDecoderCapabilitiesItf_ { - SLresult (*GetAudioDecoders) ( - SLAudioDecoderCapabilitiesItf self, - SLuint32 * pNumDecoders , - SLuint32 *pDecoderIds - ); - SLresult (*GetAudioDecoderCapabilities) ( - SLAudioDecoderCapabilitiesItf self, - SLuint32 decoderId, - SLuint32 *pIndex, - SLAudioCodecDescriptor *pDescriptor - ); -}; - - - - -/*---------------------------------------------------------------------------*/ -/* Audio Encoder Capabilities Interface */ -/* --------------------------------------------------------------------------*/ - -/* Structure used when setting audio encoding parameters */ - -typedef struct SLAudioEncoderSettings_ { - SLuint32 encoderId; - SLuint32 channelsIn; - SLuint32 channelsOut; - SLmilliHertz sampleRate; - SLuint32 bitRate; - SLuint32 bitsPerSample; - SLuint32 rateControl; - SLuint32 profileSetting; - SLuint32 levelSetting; - SLuint32 channelMode; - SLuint32 streamFormat; - SLuint32 encodeOptions; - SLuint32 blockAlignment; -} SLAudioEncoderSettings; - -extern SL_API const SLInterfaceID SL_IID_AUDIOENCODERCAPABILITIES; - -struct SLAudioEncoderCapabilitiesItf_; -typedef const struct SLAudioEncoderCapabilitiesItf_ * const * SLAudioEncoderCapabilitiesItf; - -struct SLAudioEncoderCapabilitiesItf_ { - SLresult (*GetAudioEncoders) ( - SLAudioEncoderCapabilitiesItf self, - SLuint32 *pNumEncoders , - SLuint32 *pEncoderIds - ); - SLresult (*GetAudioEncoderCapabilities) ( - SLAudioEncoderCapabilitiesItf self, - SLuint32 encoderId, - SLuint32 *pIndex, - SLAudioCodecDescriptor * pDescriptor - ); -}; - - -/*---------------------------------------------------------------------------*/ -/* Audio Encoder Interface */ -/* --------------------------------------------------------------------------*/ - - -extern SL_API const SLInterfaceID SL_IID_AUDIOENCODER; - -struct SLAudioEncoderItf_; -typedef const struct SLAudioEncoderItf_ * const * SLAudioEncoderItf; - -struct SLAudioEncoderItf_ { - SLresult (*SetEncoderSettings) ( - SLAudioEncoderItf self, - SLAudioEncoderSettings *pSettings - ); - SLresult (*GetEncoderSettings) ( - SLAudioEncoderItf self, - SLAudioEncoderSettings *pSettings - ); -}; - - -/*---------------------------------------------------------------------------*/ -/* Bass Boost Interface */ -/* --------------------------------------------------------------------------*/ - - -extern SL_API const SLInterfaceID SL_IID_BASSBOOST; - -struct SLBassBoostItf_; -typedef const struct SLBassBoostItf_ * const * SLBassBoostItf; - -struct SLBassBoostItf_ { - SLresult (*SetEnabled)( - SLBassBoostItf self, - SLboolean enabled - ); - SLresult (*IsEnabled)( - SLBassBoostItf self, - SLboolean *pEnabled - ); - SLresult (*SetStrength)( - SLBassBoostItf self, - SLpermille strength - ); - SLresult (*GetRoundedStrength)( - SLBassBoostItf self, - SLpermille *pStrength - ); - SLresult (*IsStrengthSupported)( - SLBassBoostItf self, - SLboolean *pSupported - ); -}; - -/*---------------------------------------------------------------------------*/ -/* Pitch Interface */ -/* --------------------------------------------------------------------------*/ - - -extern SL_API const SLInterfaceID SL_IID_PITCH; - -struct SLPitchItf_; -typedef const struct SLPitchItf_ * const * SLPitchItf; - -struct SLPitchItf_ { - SLresult (*SetPitch) ( - SLPitchItf self, - SLpermille pitch - ); - SLresult (*GetPitch) ( - SLPitchItf self, - SLpermille *pPitch - ); - SLresult (*GetPitchCapabilities) ( - SLPitchItf self, - SLpermille *pMinPitch, - SLpermille *pMaxPitch - ); -}; - - -/*---------------------------------------------------------------------------*/ -/* Rate Pitch Interface */ -/* RatePitchItf is an interface for controlling the rate a sound is played */ -/* back. A change in rate will cause a change in pitch. */ -/* --------------------------------------------------------------------------*/ - - -extern SL_API const SLInterfaceID SL_IID_RATEPITCH; - -struct SLRatePitchItf_; -typedef const struct SLRatePitchItf_ * const * SLRatePitchItf; - -struct SLRatePitchItf_ { - SLresult (*SetRate) ( - SLRatePitchItf self, - SLpermille rate - ); - SLresult (*GetRate) ( - SLRatePitchItf self, - SLpermille *pRate - ); - SLresult (*GetRatePitchCapabilities) ( - SLRatePitchItf self, - SLpermille *pMinRate, - SLpermille *pMaxRate - ); -}; - - -/*---------------------------------------------------------------------------*/ -/* Virtualizer Interface */ -/* --------------------------------------------------------------------------*/ - - -extern SL_API const SLInterfaceID SL_IID_VIRTUALIZER; - -struct SLVirtualizerItf_; -typedef const struct SLVirtualizerItf_ * const * SLVirtualizerItf; - -struct SLVirtualizerItf_ { - SLresult (*SetEnabled)( - SLVirtualizerItf self, - SLboolean enabled - ); - SLresult (*IsEnabled)( - SLVirtualizerItf self, - SLboolean *pEnabled - ); - SLresult (*SetStrength)( - SLVirtualizerItf self, - SLpermille strength - ); - SLresult (*GetRoundedStrength)( - SLVirtualizerItf self, - SLpermille *pStrength - ); - SLresult (*IsStrengthSupported)( - SLVirtualizerItf self, - SLboolean *pSupported - ); -}; - -/*---------------------------------------------------------------------------*/ -/* Visualization Interface */ -/* --------------------------------------------------------------------------*/ - - -extern SL_API const SLInterfaceID SL_IID_VISUALIZATION; - -struct SLVisualizationItf_; -typedef const struct SLVisualizationItf_ * const * SLVisualizationItf; - -typedef void (SLAPIENTRY *slVisualizationCallback) ( - void *pContext, - const SLuint8 waveform[], - const SLuint8 fft[], - SLmilliHertz samplerate -); - -struct SLVisualizationItf_{ - SLresult (*RegisterVisualizationCallback)( - SLVisualizationItf self, - slVisualizationCallback callback, - void *pContext, - SLmilliHertz rate - ); - SLresult (*GetMaxRate)( - SLVisualizationItf self, - SLmilliHertz* pRate - ); -}; - - -/*---------------------------------------------------------------------------*/ -/* Engine Interface */ -/* --------------------------------------------------------------------------*/ - - -extern SL_API const SLInterfaceID SL_IID_ENGINE; - -struct SLEngineItf_; -typedef const struct SLEngineItf_ * const * SLEngineItf; - - -struct SLEngineItf_ { - - SLresult (*CreateLEDDevice) ( - SLEngineItf self, - SLObjectItf * pDevice, - SLuint32 deviceID, - SLuint32 numInterfaces, - const SLInterfaceID * pInterfaceIds, - const SLboolean * pInterfaceRequired - ); - SLresult (*CreateVibraDevice) ( - SLEngineItf self, - SLObjectItf * pDevice, - SLuint32 deviceID, - SLuint32 numInterfaces, - const SLInterfaceID * pInterfaceIds, - const SLboolean * pInterfaceRequired - ); - SLresult (*CreateAudioPlayer) ( - SLEngineItf self, - SLObjectItf * pPlayer, - SLDataSource *pAudioSrc, - SLDataSink *pAudioSnk, - SLuint32 numInterfaces, - const SLInterfaceID * pInterfaceIds, - const SLboolean * pInterfaceRequired - ); - SLresult (*CreateAudioRecorder) ( - SLEngineItf self, - SLObjectItf * pRecorder, - SLDataSource *pAudioSrc, - SLDataSink *pAudioSnk, - SLuint32 numInterfaces, - const SLInterfaceID * pInterfaceIds, - const SLboolean * pInterfaceRequired - ); - SLresult (*CreateMidiPlayer) ( - SLEngineItf self, - SLObjectItf * pPlayer, - SLDataSource *pMIDISrc, - SLDataSource *pBankSrc, - SLDataSink *pAudioOutput, - SLDataSink *pVibra, - SLDataSink *pLEDArray, - SLuint32 numInterfaces, - const SLInterfaceID * pInterfaceIds, - const SLboolean * pInterfaceRequired - ); - SLresult (*CreateListener) ( - SLEngineItf self, - SLObjectItf * pListener, - SLuint32 numInterfaces, - const SLInterfaceID * pInterfaceIds, - const SLboolean * pInterfaceRequired - ); - SLresult (*Create3DGroup) ( - SLEngineItf self, - SLObjectItf * pGroup, - SLuint32 numInterfaces, - const SLInterfaceID * pInterfaceIds, - const SLboolean * pInterfaceRequired - ); - SLresult (*CreateOutputMix) ( - SLEngineItf self, - SLObjectItf * pMix, - SLuint32 numInterfaces, - const SLInterfaceID * pInterfaceIds, - const SLboolean * pInterfaceRequired - ); - SLresult (*CreateMetadataExtractor) ( - SLEngineItf self, - SLObjectItf * pMetadataExtractor, - SLDataSource * pDataSource, - SLuint32 numInterfaces, - const SLInterfaceID * pInterfaceIds, - const SLboolean * pInterfaceRequired - ); - SLresult (*CreateExtensionObject) ( - SLEngineItf self, - SLObjectItf * pObject, - void * pParameters, - SLuint32 objectID, - SLuint32 numInterfaces, - const SLInterfaceID * pInterfaceIds, - const SLboolean * pInterfaceRequired - ); - SLresult (*QueryNumSupportedInterfaces) ( - SLEngineItf self, - SLuint32 objectID, - SLuint32 * pNumSupportedInterfaces - ); - SLresult (*QuerySupportedInterfaces) ( - SLEngineItf self, - SLuint32 objectID, - SLuint32 index, - SLInterfaceID * pInterfaceId - ); - SLresult (*QueryNumSupportedExtensions) ( - SLEngineItf self, - SLuint32 * pNumExtensions - ); - SLresult (*QuerySupportedExtension) ( - SLEngineItf self, - SLuint32 index, - SLchar * pExtensionName, - SLint16 * pNameLength - ); - SLresult (*IsExtensionSupported) ( - SLEngineItf self, - const SLchar * pExtensionName, - SLboolean * pSupported - ); -}; - - -/*---------------------------------------------------------------------------*/ -/* Engine Capabilities Interface */ -/* --------------------------------------------------------------------------*/ - - -extern SL_API const SLInterfaceID SL_IID_ENGINECAPABILITIES; - -struct SLEngineCapabilitiesItf_; -typedef const struct SLEngineCapabilitiesItf_ * const * SLEngineCapabilitiesItf; - -struct SLEngineCapabilitiesItf_ { - SLresult (*QuerySupportedProfiles) ( - SLEngineCapabilitiesItf self, - SLuint16 *pProfilesSupported - ); - SLresult (*QueryAvailableVoices) ( - SLEngineCapabilitiesItf self, - SLuint16 voiceType, - SLint16 *pNumMaxVoices, - SLboolean *pIsAbsoluteMax, - SLint16 *pNumFreeVoices - ); - SLresult (*QueryNumberOfMIDISynthesizers) ( - SLEngineCapabilitiesItf self, - SLint16 *pNumMIDIsynthesizers - ); - SLresult (*QueryAPIVersion) ( - SLEngineCapabilitiesItf self, - SLint16 *pMajor, - SLint16 *pMinor, - SLint16 *pStep - ); - SLresult (*QueryLEDCapabilities) ( - SLEngineCapabilitiesItf self, - SLuint32 *pIndex, - SLuint32 *pLEDDeviceID, - SLLEDDescriptor *pDescriptor - ); - SLresult (*QueryVibraCapabilities) ( - SLEngineCapabilitiesItf self, - SLuint32 *pIndex, - SLuint32 *pVibraDeviceID, - SLVibraDescriptor *pDescriptor - ); - SLresult (*IsThreadSafe) ( - SLEngineCapabilitiesItf self, - SLboolean *pIsThreadSafe - ); -}; - -/*---------------------------------------------------------------------------*/ -/* Thread Sync Interface */ -/* --------------------------------------------------------------------------*/ - - -extern SL_API const SLInterfaceID SL_IID_THREADSYNC; - -struct SLThreadSyncItf_; -typedef const struct SLThreadSyncItf_ * const * SLThreadSyncItf; - - -struct SLThreadSyncItf_ { - SLresult (*EnterCriticalSection) ( - SLThreadSyncItf self - ); - SLresult (*ExitCriticalSection) ( - SLThreadSyncItf self - ); -}; - - -/*****************************************************************************/ -/* SL engine constructor */ -/*****************************************************************************/ - -#define SL_ENGINEOPTION_THREADSAFE ((SLuint32) 0x00000001) -#define SL_ENGINEOPTION_LOSSOFCONTROL ((SLuint32) 0x00000002) - -typedef struct SLEngineOption_ { - SLuint32 feature; - SLuint32 data; -} SLEngineOption; - - -SL_API SLresult SLAPIENTRY slCreateEngine( - SLObjectItf *pEngine, - SLuint32 numOptions, - const SLEngineOption *pEngineOptions, - SLuint32 numInterfaces, - const SLInterfaceID *pInterfaceIds, - const SLboolean * pInterfaceRequired -); - -SL_API SLresult SLAPIENTRY slQueryNumSupportedEngineInterfaces( - SLuint32 * pNumSupportedInterfaces -); - -SL_API SLresult SLAPIENTRY slQuerySupportedEngineInterfaces( - SLuint32 index, - SLInterfaceID * pInterfaceId -); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* OPENSL_ES_H_ */ diff --git a/wilhelm/include/SLES/OpenSLES_Android.h b/wilhelm/include/SLES/OpenSLES_Android.h deleted file mode 100644 index f295518e..00000000 --- a/wilhelm/include/SLES/OpenSLES_Android.h +++ /dev/null @@ -1,349 +0,0 @@ -/* - * 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 OPENSL_ES_ANDROID_H_ -#define OPENSL_ES_ANDROID_H_ - -#include "OpenSLES_AndroidConfiguration.h" -#include "OpenSLES_AndroidMetadata.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/*---------------------------------------------------------------------------*/ -/* Android common types */ -/*---------------------------------------------------------------------------*/ - -typedef sl_int64_t SLAint64; /* 64 bit signed integer */ - -typedef sl_uint64_t SLAuint64; /* 64 bit unsigned integer */ - -/*---------------------------------------------------------------------------*/ -/* Android Effect interface */ -/*---------------------------------------------------------------------------*/ - -extern SL_API const SLInterfaceID SL_IID_ANDROIDEFFECT; - -/** Android Effect interface methods */ - -struct SLAndroidEffectItf_; -typedef const struct SLAndroidEffectItf_ * const * SLAndroidEffectItf; - -struct SLAndroidEffectItf_ { - - SLresult (*CreateEffect) (SLAndroidEffectItf self, - SLInterfaceID effectImplementationId); - - SLresult (*ReleaseEffect) (SLAndroidEffectItf self, - SLInterfaceID effectImplementationId); - - SLresult (*SetEnabled) (SLAndroidEffectItf self, - SLInterfaceID effectImplementationId, - SLboolean enabled); - - SLresult (*IsEnabled) (SLAndroidEffectItf self, - SLInterfaceID effectImplementationId, - SLboolean *pEnabled); - - SLresult (*SendCommand) (SLAndroidEffectItf self, - SLInterfaceID effectImplementationId, - SLuint32 command, - SLuint32 commandSize, - void *pCommandData, - SLuint32 *replySize, - void *pReplyData); -}; - - -/*---------------------------------------------------------------------------*/ -/* Android Effect Send interface */ -/*---------------------------------------------------------------------------*/ - -extern SL_API const SLInterfaceID SL_IID_ANDROIDEFFECTSEND; - -/** Android Effect Send interface methods */ - -struct SLAndroidEffectSendItf_; -typedef const struct SLAndroidEffectSendItf_ * const * SLAndroidEffectSendItf; - -struct SLAndroidEffectSendItf_ { - SLresult (*EnableEffectSend) ( - SLAndroidEffectSendItf self, - SLInterfaceID effectImplementationId, - SLboolean enable, - SLmillibel initialLevel - ); - SLresult (*IsEnabled) ( - SLAndroidEffectSendItf self, - SLInterfaceID effectImplementationId, - SLboolean *pEnable - ); - SLresult (*SetDirectLevel) ( - SLAndroidEffectSendItf self, - SLmillibel directLevel - ); - SLresult (*GetDirectLevel) ( - SLAndroidEffectSendItf self, - SLmillibel *pDirectLevel - ); - SLresult (*SetSendLevel) ( - SLAndroidEffectSendItf self, - SLInterfaceID effectImplementationId, - SLmillibel sendLevel - ); - SLresult (*GetSendLevel)( - SLAndroidEffectSendItf self, - SLInterfaceID effectImplementationId, - SLmillibel *pSendLevel - ); -}; - - -/*---------------------------------------------------------------------------*/ -/* Android Effect Capabilities interface */ -/*---------------------------------------------------------------------------*/ - -extern SL_API const SLInterfaceID SL_IID_ANDROIDEFFECTCAPABILITIES; - -/** Android Effect Capabilities interface methods */ - -struct SLAndroidEffectCapabilitiesItf_; -typedef const struct SLAndroidEffectCapabilitiesItf_ * const * SLAndroidEffectCapabilitiesItf; - -struct SLAndroidEffectCapabilitiesItf_ { - - SLresult (*QueryNumEffects) (SLAndroidEffectCapabilitiesItf self, - SLuint32 *pNumSupportedEffects); - - - SLresult (*QueryEffect) (SLAndroidEffectCapabilitiesItf self, - SLuint32 index, - SLInterfaceID *pEffectType, - SLInterfaceID *pEffectImplementation, - SLchar *pName, - SLuint16 *pNameSize); -}; - - -/*---------------------------------------------------------------------------*/ -/* Android Configuration interface */ -/*---------------------------------------------------------------------------*/ -extern SL_API const SLInterfaceID SL_IID_ANDROIDCONFIGURATION; - -/** Android Configuration interface methods */ - -struct SLAndroidConfigurationItf_; -typedef const struct SLAndroidConfigurationItf_ * const * SLAndroidConfigurationItf; - -struct SLAndroidConfigurationItf_ { - - SLresult (*SetConfiguration) (SLAndroidConfigurationItf self, - const SLchar *configKey, - const void *pConfigValue, - SLuint32 valueSize); - - SLresult (*GetConfiguration) (SLAndroidConfigurationItf self, - const SLchar *configKey, - SLuint32 *pValueSize, - void *pConfigValue - ); -}; - - -/*---------------------------------------------------------------------------*/ -/* Android Simple Buffer Queue Interface */ -/*---------------------------------------------------------------------------*/ - -extern SL_API const SLInterfaceID SL_IID_ANDROIDSIMPLEBUFFERQUEUE; - -struct SLAndroidSimpleBufferQueueItf_; -typedef const struct SLAndroidSimpleBufferQueueItf_ * const * SLAndroidSimpleBufferQueueItf; - -typedef void (SLAPIENTRY *slAndroidSimpleBufferQueueCallback)( - SLAndroidSimpleBufferQueueItf caller, - void *pContext -); - -/** Android simple buffer queue state **/ - -typedef struct SLAndroidSimpleBufferQueueState_ { - SLuint32 count; - SLuint32 index; -} SLAndroidSimpleBufferQueueState; - - -struct SLAndroidSimpleBufferQueueItf_ { - SLresult (*Enqueue) ( - SLAndroidSimpleBufferQueueItf self, - const void *pBuffer, - SLuint32 size - ); - SLresult (*Clear) ( - SLAndroidSimpleBufferQueueItf self - ); - SLresult (*GetState) ( - SLAndroidSimpleBufferQueueItf self, - SLAndroidSimpleBufferQueueState *pState - ); - SLresult (*RegisterCallback) ( - SLAndroidSimpleBufferQueueItf self, - slAndroidSimpleBufferQueueCallback callback, - void* pContext - ); -}; - - -/*---------------------------------------------------------------------------*/ -/* Android Buffer Queue Interface */ -/*---------------------------------------------------------------------------*/ - -extern SL_API const SLInterfaceID SL_IID_ANDROIDBUFFERQUEUESOURCE; - -struct SLAndroidBufferQueueItf_; -typedef const struct SLAndroidBufferQueueItf_ * const * SLAndroidBufferQueueItf; - -#define SL_ANDROID_ITEMKEY_NONE ((SLuint32) 0x00000000) -#define SL_ANDROID_ITEMKEY_EOS ((SLuint32) 0x00000001) -#define SL_ANDROID_ITEMKEY_DISCONTINUITY ((SLuint32) 0x00000002) -#define SL_ANDROID_ITEMKEY_BUFFERQUEUEEVENT ((SLuint32) 0x00000003) -#define SL_ANDROID_ITEMKEY_FORMAT_CHANGE ((SLuint32) 0x00000004) - -#define SL_ANDROIDBUFFERQUEUEEVENT_NONE ((SLuint32) 0x00000000) -#define SL_ANDROIDBUFFERQUEUEEVENT_PROCESSED ((SLuint32) 0x00000001) -#if 0 // reserved for future use -#define SL_ANDROIDBUFFERQUEUEEVENT_UNREALIZED ((SLuint32) 0x00000002) -#define SL_ANDROIDBUFFERQUEUEEVENT_CLEARED ((SLuint32) 0x00000004) -#define SL_ANDROIDBUFFERQUEUEEVENT_STOPPED ((SLuint32) 0x00000008) -#define SL_ANDROIDBUFFERQUEUEEVENT_ERROR ((SLuint32) 0x00000010) -#define SL_ANDROIDBUFFERQUEUEEVENT_CONTENT_END ((SLuint32) 0x00000020) -#endif - -typedef struct SLAndroidBufferItem_ { - SLuint32 itemKey; // identifies the item - SLuint32 itemSize; - SLuint8 itemData[0]; -} SLAndroidBufferItem; - -typedef SLresult (SLAPIENTRY *slAndroidBufferQueueCallback)( - SLAndroidBufferQueueItf caller,/* input */ - void *pCallbackContext, /* input */ - void *pBufferContext, /* input */ - void *pBufferData, /* input */ - SLuint32 dataSize, /* input */ - SLuint32 dataUsed, /* input */ - const SLAndroidBufferItem *pItems,/* input */ - SLuint32 itemsLength /* input */ -); - -typedef struct SLAndroidBufferQueueState_ { - SLuint32 count; - SLuint32 index; -} SLAndroidBufferQueueState; - -struct SLAndroidBufferQueueItf_ { - SLresult (*RegisterCallback) ( - SLAndroidBufferQueueItf self, - slAndroidBufferQueueCallback callback, - void* pCallbackContext - ); - - SLresult (*Clear) ( - SLAndroidBufferQueueItf self - ); - - SLresult (*Enqueue) ( - SLAndroidBufferQueueItf self, - void *pBufferContext, - void *pData, - SLuint32 dataLength, - const SLAndroidBufferItem *pItems, - SLuint32 itemsLength - ); - - SLresult (*GetState) ( - SLAndroidBufferQueueItf self, - SLAndroidBufferQueueState *pState - ); - - SLresult (*SetCallbackEventsMask) ( - SLAndroidBufferQueueItf self, - SLuint32 eventFlags - ); - - SLresult (*GetCallbackEventsMask) ( - SLAndroidBufferQueueItf self, - SLuint32 *pEventFlags - ); -}; - - -/*---------------------------------------------------------------------------*/ -/* Android File Descriptor Data Locator */ -/*---------------------------------------------------------------------------*/ - -/** Addendum to Data locator macros */ -#define SL_DATALOCATOR_ANDROIDFD ((SLuint32) 0x800007BC) - -#define SL_DATALOCATOR_ANDROIDFD_USE_FILE_SIZE ((SLAint64) 0xFFFFFFFFFFFFFFFFll) - -/** File Descriptor-based data locator definition, locatorType must be SL_DATALOCATOR_ANDROIDFD */ -typedef struct SLDataLocator_AndroidFD_ { - SLuint32 locatorType; - SLint32 fd; - SLAint64 offset; - SLAint64 length; -} SLDataLocator_AndroidFD; - - -/*---------------------------------------------------------------------------*/ -/* Android Android Simple Buffer Queue Data Locator */ -/*---------------------------------------------------------------------------*/ - -/** Addendum to Data locator macros */ -#define SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE ((SLuint32) 0x800007BD) - -/** BufferQueue-based data locator definition where locatorType must be SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE*/ -typedef struct SLDataLocator_AndroidSimpleBufferQueue { - SLuint32 locatorType; - SLuint32 numBuffers; -} SLDataLocator_AndroidSimpleBufferQueue; - - -/*---------------------------------------------------------------------------*/ -/* Android Buffer Queue Data Locator */ -/*---------------------------------------------------------------------------*/ - -/** Addendum to Data locator macros */ -#define SL_DATALOCATOR_ANDROIDBUFFERQUEUE ((SLuint32) 0x800007BE) - -/** Android Buffer Queue-based data locator definition, - * locatorType must be SL_DATALOCATOR_ANDROIDBUFFERQUEUE */ -typedef struct SLDataLocator_AndroidBufferQueue_ { - SLuint32 locatorType; - SLuint32 numBuffers; -} SLDataLocator_AndroidBufferQueue; - -/** - * MIME types required for data in Android Buffer Queues - */ -#define SL_ANDROID_MIME_AACADTS ((SLchar *) "audio/vnd.android.aac-adts") - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* OPENSL_ES_ANDROID_H_ */ diff --git a/wilhelm/include/SLES/OpenSLES_AndroidConfiguration.h b/wilhelm/include/SLES/OpenSLES_AndroidConfiguration.h deleted file mode 100644 index 01f460de..00000000 --- a/wilhelm/include/SLES/OpenSLES_AndroidConfiguration.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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 OPENSL_ES_ANDROIDCONFIGURATION_H_ -#define OPENSL_ES_ANDROIDCONFIGURATION_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/*---------------------------------------------------------------------------*/ -/* Android AudioRecorder configuration */ -/*---------------------------------------------------------------------------*/ - -/** Audio recording preset */ -/** Audio recording preset key */ -#define SL_ANDROID_KEY_RECORDING_PRESET ((const SLchar*) "androidRecordingPreset") -/** Audio recording preset values */ -/** preset "none" cannot be set, it is used to indicate the current settings - * do not match any of the presets. */ -#define SL_ANDROID_RECORDING_PRESET_NONE ((SLuint32) 0x00000000) -/** generic recording configuration on the platform */ -#define SL_ANDROID_RECORDING_PRESET_GENERIC ((SLuint32) 0x00000001) -/** uses the microphone audio source with the same orientation as the camera - * if available, the main device microphone otherwise */ -#define SL_ANDROID_RECORDING_PRESET_CAMCORDER ((SLuint32) 0x00000002) -/** uses the main microphone tuned for voice recognition */ -#define SL_ANDROID_RECORDING_PRESET_VOICE_RECOGNITION ((SLuint32) 0x00000003) -/** uses the main microphone tuned for audio communications */ -#define SL_ANDROID_RECORDING_PRESET_VOICE_COMMUNICATION ((SLuint32) 0x00000004) - -/*---------------------------------------------------------------------------*/ -/* Android AudioPlayer configuration */ -/*---------------------------------------------------------------------------*/ - -/** Audio playback stream type */ -/** Audio playback stream type key */ -#define SL_ANDROID_KEY_STREAM_TYPE ((const SLchar*) "androidPlaybackStreamType") - -/** Audio playback stream type values */ -/* same as android.media.AudioManager.STREAM_VOICE_CALL */ -#define SL_ANDROID_STREAM_VOICE ((SLint32) 0x00000000) -/* same as android.media.AudioManager.STREAM_SYSTEM */ -#define SL_ANDROID_STREAM_SYSTEM ((SLint32) 0x00000001) -/* same as android.media.AudioManager.STREAM_RING */ -#define SL_ANDROID_STREAM_RING ((SLint32) 0x00000002) -/* same as android.media.AudioManager.STREAM_MUSIC */ -#define SL_ANDROID_STREAM_MEDIA ((SLint32) 0x00000003) -/* same as android.media.AudioManager.STREAM_ALARM */ -#define SL_ANDROID_STREAM_ALARM ((SLint32) 0x00000004) -/* same as android.media.AudioManager.STREAM_NOTIFICATION */ -#define SL_ANDROID_STREAM_NOTIFICATION ((SLint32) 0x00000005) - - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* OPENSL_ES_ANDROIDCONFIGURATION_H_ */ diff --git a/wilhelm/include/SLES/OpenSLES_AndroidMetadata.h b/wilhelm/include/SLES/OpenSLES_AndroidMetadata.h deleted file mode 100644 index 01e33b8d..00000000 --- a/wilhelm/include/SLES/OpenSLES_AndroidMetadata.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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 OPENSL_ES_ANDROIDMETADATA_H_ -#define OPENSL_ES_ANDROIDMETADATA_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/*---------------------------------------------------------------------------*/ -/* Android metadata keys */ -/*---------------------------------------------------------------------------*/ - -/** - * Additional metadata keys to be used in SLMetadataExtractionItf: - * the ANDROID_KEY_PCMFORMAT_* keys follow the fields of the SLDataFormat_PCM struct, and as such - * all values corresponding to these keys are of SLuint32 type, and are defined as the fields - * of the same name in SLDataFormat_PCM. The exception is that sample rate is expressed here - * in Hz units, rather than in milliHz units. - */ -#define ANDROID_KEY_PCMFORMAT_NUMCHANNELS "AndroidPcmFormatNumChannels" -#define ANDROID_KEY_PCMFORMAT_SAMPLERATE "AndroidPcmFormatSampleRate" -#define ANDROID_KEY_PCMFORMAT_BITSPERSAMPLE "AndroidPcmFormatBitsPerSample" -#define ANDROID_KEY_PCMFORMAT_CONTAINERSIZE "AndroidPcmFormatContainerSize" -#define ANDROID_KEY_PCMFORMAT_CHANNELMASK "AndroidPcmFormatChannelMask" -#define ANDROID_KEY_PCMFORMAT_ENDIANNESS "AndroidPcmFormatEndianness" - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* OPENSL_ES_ANDROIDMETADATA_H_ */ diff --git a/wilhelm/include/SLES/OpenSLES_Platform.h b/wilhelm/include/SLES/OpenSLES_Platform.h deleted file mode 100644 index 527693d8..00000000 --- a/wilhelm/include/SLES/OpenSLES_Platform.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2007-2009 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and /or associated documentation files (the "Materials "), to - * deal in the Materials without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Materials, and to permit persons to whom the Materials are - * furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS IN THE - * MATERIALS. - * - * OpenSLES_Platform.h - OpenSL ES version 1.0 - * - */ - -/****************************************************************************/ -/* NOTE: This file contains definitions for the base types and the */ -/* SLAPIENTRY macro. This file **WILL NEED TO BE EDITED** to provide */ -/* the correct definitions specific to the platform being used. */ -/****************************************************************************/ - -#ifndef _OPENSLES_PLATFORM_H_ -#define _OPENSLES_PLATFORM_H_ - -typedef unsigned char sl_uint8_t; -typedef signed char sl_int8_t; -typedef unsigned short sl_uint16_t; -typedef signed short sl_int16_t; -typedef unsigned int /*long*/ sl_uint32_t; -typedef signed int /*long*/ sl_int32_t; -typedef long long sl_int64_t; -typedef unsigned long long sl_uint64_t; - -#ifndef SL_API -#ifdef __GNUC__ -#define SL_API /* override per-platform */ -#else -#define SL_API __declspec(dllimport) -#endif -#endif - -#ifndef SLAPIENTRY -#define SLAPIENTRY -#endif - -#endif /* _OPENSLES_PLATFORM_H_ */ diff --git a/wilhelm/src/Android.mk b/wilhelm/src/Android.mk deleted file mode 100644 index c0ced447..00000000 --- a/wilhelm/src/Android.mk +++ /dev/null @@ -1,228 +0,0 @@ -LOCAL_PATH:= $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_SRC_FILES := \ - assert.c \ - ut/OpenSLESUT.c \ - ut/slesutResult.c - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_CFLAGS += -fvisibility=hidden -UNDEBUG - -LOCAL_MODULE := libOpenSLESUT - -include $(BUILD_STATIC_LIBRARY) - -include $(CLEAR_VARS) - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_CFLAGS += -Wno-override-init -# -Wno-missing-field-initializers -# optional, see comments in MPH_to.c: -DUSE_DESIGNATED_INITIALIZERS -S -# and also see ../tools/mphgen/Makefile -LOCAL_CFLAGS += -DUSE_DESIGNATED_INITIALIZERS -UNDEBUG - -LOCAL_SRC_FILES:= \ - assert.c \ - MPH_to.c \ - handlers.c - -LOCAL_MODULE:= libopensles_helper - -include $(BUILD_STATIC_LIBRARY) - -include $(CLEAR_VARS) - -# do not claim support for any OpenSL ES or OpenMAX AL profiles -LOCAL_CFLAGS += -DUSE_PROFILES=0 - -# enable API logging; details are set separately by SL_TRACE_DEFAULT below -LOCAL_CFLAGS += -DUSE_TRACE -# or -UUSE_TRACE to disable API logging - -# enable mutex deadlock detection -LOCAL_CFLAGS += -DUSE_DEBUG -# or -UUSE_DEBUG for no mutex deadlock detection - -# enable assert() to do runtime checking -LOCAL_CFLAGS += -UNDEBUG -# or -DNDEBUG for no runtime checking - -# select the level of log messages -LOCAL_CFLAGS += -DUSE_LOG=SLAndroidLogLevel_Info -# or -DUSE_LOG=SLAndroidLogLevel_Verbose for verbose logging - -# log all API entries and exits (also requires Debug or Verbose log level) -# LOCAL_CFLAGS += -DSL_TRACE_DEFAULT=SL_TRACE_ALL -# (otherwise a warning log on error results only) - -# API level -LOCAL_CFLAGS += -DPLATFORM_SDK_VERSION=$(PLATFORM_SDK_VERSION) - -# Reduce size of .so and hide internal global symbols -LOCAL_CFLAGS += -fvisibility=hidden -DLI_API='__attribute__((visibility("default")))' - -LOCAL_SRC_FILES:= \ - OpenSLES_IID.c \ - assert.c \ - classes.c \ - data.c \ - devices.c \ - entry.c \ - handler_bodies.c \ - trace.c \ - locks.c \ - sles.c \ - sl_iid.c \ - sllog.c \ - ThreadPool.c \ - android/AudioPlayer_to_android.cpp \ - android/AudioRecorder_to_android.cpp \ - android/MediaPlayer_to_android.cpp \ - android/OutputMix_to_android.cpp \ - android/VideoCodec_to_android.cpp \ - android/BufferQueueSource.cpp \ - android/CallbackProtector.cpp \ - android/AacBqToPcmCbRenderer.cpp \ - android/android_AudioSfDecoder.cpp \ - android/android_AudioToCbRenderer.cpp \ - android/android_GenericMediaPlayer.cpp\ - android/android_GenericPlayer.cpp \ - android/android_LocAVPlayer.cpp \ - android/android_StreamPlayer.cpp \ - android/android_Effect.cpp \ - android/util/AacAdtsExtractor.cpp \ - autogen/IID_to_MPH.c \ - objects/C3DGroup.c \ - objects/CAudioPlayer.c \ - objects/CAudioRecorder.c \ - objects/CEngine.c \ - objects/COutputMix.c \ - objects/CMediaPlayer.c \ - itf/IAndroidBufferQueue.c \ - itf/IAndroidConfiguration.c \ - itf/IAndroidEffect.cpp \ - itf/IAndroidEffectCapabilities.c \ - itf/IAndroidEffectSend.c \ - itf/IBassBoost.c \ - itf/IBufferQueue.c \ - itf/IDynamicInterfaceManagement.c \ - itf/IEffectSend.c \ - itf/IEngine.c \ - itf/IEngineCapabilities.c \ - itf/IEnvironmentalReverb.c \ - itf/IEqualizer.c \ - itf/IMetadataExtraction.c \ - itf/IMuteSolo.c \ - itf/IObject.c \ - itf/IOutputMix.c \ - itf/IPlay.c \ - itf/IPlaybackRate.c \ - itf/IPrefetchStatus.c \ - itf/IPresetReverb.c \ - itf/IRecord.c \ - itf/ISeek.c \ - itf/IStreamInformation.cpp \ - itf/IVideoDecoderCapabilities.cpp \ - itf/IVirtualizer.c \ - itf/IVolume.c - -EXCLUDE_SRC := \ - sync.c \ - itf/I3DCommit.c \ - itf/I3DDoppler.c \ - itf/I3DGrouping.c \ - itf/I3DLocation.c \ - itf/I3DMacroscopic.c \ - itf/I3DSource.c \ - itf/IAudioDecoderCapabilities.c \ - itf/IAudioEncoder.c \ - itf/IAudioEncoderCapabilities.c \ - itf/IAudioIODeviceCapabilities.c \ - itf/IDeviceVolume.c \ - itf/IDynamicSource.c \ - itf/ILEDArray.c \ - itf/IMIDIMessage.c \ - itf/IMIDIMuteSolo.c \ - itf/IMIDITempo.c \ - itf/IMIDITime.c \ - itf/IMetadataTraversal.c \ - itf/IPitch.c \ - itf/IRatePitch.c \ - itf/IThreadSync.c \ - itf/IVibra.c \ - itf/IVisualization.c - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) \ - frameworks/base/media/libstagefright \ - frameworks/base/media/libstagefright/include \ - frameworks/native/include/media/openmax \ - $(call include-path-for, audio-effects) - -# __pthread_gettid -LOCAL_C_INCLUDES += bionic/libc/private - -LOCAL_CFLAGS += -x c++ -Wno-multichar -Wno-invalid-offsetof - -LOCAL_STATIC_LIBRARIES += \ - libopensles_helper \ - libOpenSLESUT - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libmedia \ - libmedia_native \ - libbinder \ - libstagefright \ - libstagefright_foundation \ - libcutils \ - libgui \ - libdl - - - -LOCAL_MODULE := libwilhelm -LOCAL_MODULE_TAGS := optional - -ifeq ($(TARGET_BUILD_VARIANT),userdebug) - LOCAL_CFLAGS += -DUSERDEBUG_BUILD=1 -endif - -LOCAL_PRELINK_MODULE := false -include $(BUILD_SHARED_LIBRARY) - -include $(CLEAR_VARS) -LOCAL_SRC_FILES := sl_entry.c sl_iid.c assert.c -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) \ - frameworks/base/media/libstagefright \ - frameworks/base/media/libstagefright/include \ - frameworks/native/include/media/openmax -LOCAL_MODULE := libOpenSLES -LOCAL_PRELINK_MODULE := false -LOCAL_MODULE_TAGS := optional -LOCAL_CFLAGS += -x c++ -DLI_API= -fvisibility=hidden -UNDEBUG \ - -DSL_API='__attribute__((visibility("default")))' -LOCAL_SHARED_LIBRARIES := libwilhelm -include $(BUILD_SHARED_LIBRARY) - -include $(CLEAR_VARS) -LOCAL_SRC_FILES := xa_entry.c xa_iid.c assert.c -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) \ - frameworks/base/media/libstagefright \ - frameworks/base/media/libstagefright/include \ - frameworks/native/include/media/openmax -LOCAL_MODULE := libOpenMAXAL -LOCAL_PRELINK_MODULE := false -LOCAL_MODULE_TAGS := optional -LOCAL_CFLAGS += -x c++ -DLI_API= -fvisibility=hidden -UNDEBUG \ - -DXA_API='__attribute__((visibility("default")))' -LOCAL_SHARED_LIBRARIES := libwilhelm -include $(BUILD_SHARED_LIBRARY) diff --git a/wilhelm/src/MPH.h b/wilhelm/src/MPH.h deleted file mode 100644 index f822390d..00000000 --- a/wilhelm/src/MPH.h +++ /dev/null @@ -1,131 +0,0 @@ -/* - * 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 __MPH_H -#define __MPH_H - -// Minimal perfect hash for each interface ID - -#define MPH_NONE (-1) -#define MPH_MIN 0 - -// OpenSL ES 1.0.1 interfaces -#define MPH_3DCOMMIT 0 -#define MPH_3DDOPPLER 1 -#define MPH_3DGROUPING 2 -#define MPH_3DLOCATION 3 -#define MPH_3DMACROSCOPIC 4 -#define MPH_3DSOURCE 5 -#define MPH_AUDIODECODERCAPABILITIES 6 -#define MPH_AUDIOENCODER 7 -#define MPH_AUDIOENCODERCAPABILITIES 8 -#define MPH_AUDIOIODEVICECAPABILITIES 9 -#define MPH_BASSBOOST 10 -#define MPH_BUFFERQUEUE 11 -#define MPH_DEVICEVOLUME 12 -#define MPH_DYNAMICINTERFACEMANAGEMENT 13 -#define MPH_DYNAMICSOURCE 14 -#define MPH_EFFECTSEND 15 -#define MPH_ENGINE 16 -#define MPH_ENGINECAPABILITIES 17 -#define MPH_ENVIRONMENTALREVERB 18 -#define MPH_EQUALIZER 19 -#define MPH_LED 20 -#define MPH_METADATAEXTRACTION 21 -#define MPH_METADATATRAVERSAL 22 -#define MPH_MIDIMESSAGE 23 -#define MPH_MIDIMUTESOLO 24 -#define MPH_MIDITEMPO 25 -#define MPH_MIDITIME 26 -#define MPH_MUTESOLO 27 -#define MPH_NULL 28 // shared by SL and XA -#define MPH_OBJECT 29 -#define MPH_OUTPUTMIX 30 -#define MPH_PITCH 31 -#define MPH_PLAY 32 -#define MPH_PLAYBACKRATE 33 -#define MPH_PREFETCHSTATUS 34 -#define MPH_PRESETREVERB 35 -#define MPH_RATEPITCH 36 -#define MPH_RECORD 37 -#define MPH_SEEK 38 -#define MPH_THREADSYNC 39 -#define MPH_VIBRA 40 -#define MPH_VIRTUALIZER 41 -#define MPH_VISUALIZATION 42 -#define MPH_VOLUME 43 - -// Wilhelm desktop extended interfaces -#define MPH_OUTPUTMIXEXT 44 - -// Android API level 9 extended interfaces -// GUID and MPH are shared by SL and XA, but currently documented for SL only -#define MPH_ANDROIDEFFECT 45 -#define MPH_ANDROIDEFFECTCAPABILITIES 46 -#define MPH_ANDROIDEFFECTSEND 47 -#define MPH_ANDROIDCONFIGURATION 48 -#define MPH_ANDROIDSIMPLEBUFFERQUEUE 49 - -// Android API level 12 extended interfaces -// GUID and MPH are shared by SL and XA, but currently documented for XA only -#define MPH_ANDROIDBUFFERQUEUESOURCE 50 - -// OpenMAX AL 1.0.1 interfaces -#define MPH_XAAUDIODECODERCAPABILITIES 51 -#define MPH_XAAUDIOENCODER 52 -#define MPH_XAAUDIOENCODERCAPABILITIES 53 -#define MPH_XAAUDIOIODEVICECAPABILITIES 54 -#define MPH_XACAMERA 55 -#define MPH_XACAMERACAPABILITIES 56 -#define MPH_XACONFIGEXTENSION 57 -#define MPH_XADEVICEVOLUME 58 -#define MPH_XADYNAMICINTERFACEMANAGEMENT 59 -#define MPH_XADYNAMICSOURCE 60 -#define MPH_XAENGINE 61 -#define MPH_XAEQUALIZER 62 -#define MPH_XAIMAGECONTROLS 63 -#define MPH_XAIMAGEDECODERCAPABILITIES 64 -#define MPH_XAIMAGEEFFECTS 65 -#define MPH_XAIMAGEENCODER 66 -#define MPH_XAIMAGEENCODERCAPABILITIES 67 -#define MPH_XALED 68 -#define MPH_XAMETADATAEXTRACTION 69 -#define MPH_XAMETADATAINSERTION 70 -#define MPH_XAMETADATATRAVERSAL 71 -#define MPH_XANULL MPH_NULL -#define MPH_XAOBJECT 72 -#define MPH_XAOUTPUTMIX 73 -#define MPH_XAPLAY 74 -#define MPH_XAPLAYBACKRATE 75 -#define MPH_XAPREFETCHSTATUS 76 -#define MPH_XARADIO 77 -#define MPH_XARDS 78 -#define MPH_XARECORD 79 -#define MPH_XASEEK 80 -#define MPH_XASNAPSHOT 81 -#define MPH_XASTREAMINFORMATION 82 -#define MPH_XATHREADSYNC 83 -#define MPH_XAVIBRA 84 -#define MPH_XAVIDEODECODERCAPABILITIES 85 -#define MPH_XAVIDEOENCODER 86 -#define MPH_XAVIDEOENCODERCAPABILITIES 87 -#define MPH_XAVIDEOPOSTPROCESSING 88 -#define MPH_XAVOLUME 89 - -// total number of interface IDs -#define MPH_MAX 90 - -#endif // !defined(__MPH_H) diff --git a/wilhelm/src/MPH_to.c b/wilhelm/src/MPH_to.c deleted file mode 100644 index 638117a3..00000000 --- a/wilhelm/src/MPH_to.c +++ /dev/null @@ -1,263 +0,0 @@ -/* - * 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. - */ - -// Map minimal perfect hash of an interface ID to its class index. - -#include "MPH.h" - -// If defined, then compile with C99 such as GNU C, not GNU C++ or non-GNU C. -//#define USE_DESIGNATED_INITIALIZERS - -// It is critical that all entries are populated with either a specific index -// or -1. Do not let the compiler use a default initializer of zero, because -// that actually maps to the IObject index. For non-USE_DESIGNATED_INITIALIZERS -// builds, we use the automagically-generated MPH_to_*.h files for this reason. - -// A good test is to use the GNU C compiler with -S option (for assembler output), -// and compile both with and without USE_DESIGNATED_INITIALIZERS. The resulting .s -// files should be identical for both compilations. - -// Important note: if you add any interfaces here, be sure to also -// update the #define for the corresponding INTERFACES_<Class>. - -// IObject is the first interface in a class, so the index for MPH_OBJECT must be zero. -// Don't cross streams, otherwise bad things happen. - - -const signed char MPH_to_3DGroup[MPH_MAX] = { -#ifdef USE_DESIGNATED_INITIALIZERS - [0 ... MPH_MAX-1] = -1, - [MPH_OBJECT] = 0, - [MPH_DYNAMICINTERFACEMANAGEMENT] = 1, - [MPH_3DLOCATION] = 2, - [MPH_3DDOPPLER] = 3, - [MPH_3DSOURCE] = 4, - [MPH_3DMACROSCOPIC] = 5 -#else -#include "MPH_to_3DGroup.h" -#endif -}; - -const signed char MPH_to_AudioPlayer[MPH_MAX] = { -#ifdef USE_DESIGNATED_INITIALIZERS - [0 ... MPH_MAX-1] = -1, - [MPH_OBJECT] = 0, - [MPH_DYNAMICINTERFACEMANAGEMENT] = 1, - [MPH_PLAY] = 2, - [MPH_3DDOPPLER] = 3, - [MPH_3DGROUPING] = 4, - [MPH_3DLOCATION] = 5, - [MPH_3DSOURCE] = 6, - [MPH_BUFFERQUEUE] = 7, - [MPH_EFFECTSEND] = 8, - [MPH_MUTESOLO] = 9, - [MPH_METADATAEXTRACTION] = 10, - [MPH_METADATATRAVERSAL] = 11, - [MPH_PREFETCHSTATUS] = 12, - [MPH_RATEPITCH] = 13, - [MPH_SEEK] = 14, - [MPH_VOLUME] = 15, - [MPH_3DMACROSCOPIC] = 16, - [MPH_BASSBOOST] = 17, - [MPH_DYNAMICSOURCE] = 18, - [MPH_ENVIRONMENTALREVERB] = 19, - [MPH_EQUALIZER] = 20, - [MPH_PITCH] = 21, - [MPH_PRESETREVERB] = 22, - [MPH_PLAYBACKRATE] = 23, - [MPH_VIRTUALIZER] = 24, - [MPH_VISUALIZATION] = 25, -#ifdef ANDROID - [MPH_ANDROIDEFFECT] = 26, - [MPH_ANDROIDEFFECTSEND] = 27, - [MPH_ANDROIDCONFIGURATION] = 28, - [MPH_ANDROIDSIMPLEBUFFERQUEUE] = 7, // alias for [MPH_BUFFERQUEUE] - [MPH_ANDROIDBUFFERQUEUESOURCE] = 29 -#endif -#else -#include "MPH_to_AudioPlayer.h" -#endif -}; - -const signed char MPH_to_AudioRecorder[MPH_MAX] = { -#ifdef USE_DESIGNATED_INITIALIZERS - [0 ... MPH_MAX-1] = -1, - [MPH_OBJECT] = 0, - [MPH_DYNAMICINTERFACEMANAGEMENT] = 1, - [MPH_RECORD] = 2, - [MPH_AUDIOENCODER] = 3, - [MPH_BASSBOOST] = 4, - [MPH_DYNAMICSOURCE] = 5, - [MPH_EQUALIZER] = 6, - [MPH_VISUALIZATION] = 7, - [MPH_VOLUME] = 8, -#ifdef ANDROID - [MPH_ANDROIDSIMPLEBUFFERQUEUE] = 9, // this is not an alias - [MPH_ANDROIDCONFIGURATION] = 10 -#endif -#else -#include "MPH_to_AudioRecorder.h" -#endif -}; - -const signed char MPH_to_Engine[MPH_MAX] = { -#ifdef USE_DESIGNATED_INITIALIZERS - [0 ... MPH_MAX-1] = -1, - [MPH_OBJECT] = 0, - [MPH_DYNAMICINTERFACEMANAGEMENT] = 1, - [MPH_ENGINE] = 2, - [MPH_ENGINECAPABILITIES] = 3, - [MPH_THREADSYNC] = 4, - [MPH_AUDIOIODEVICECAPABILITIES] = 5, - [MPH_AUDIODECODERCAPABILITIES] = 6, - [MPH_AUDIOENCODERCAPABILITIES] = 7, - [MPH_3DCOMMIT] = 8, - [MPH_DEVICEVOLUME] = 9, - [MPH_XAENGINE] = 10, -#ifdef ANDROID - [MPH_ANDROIDEFFECTCAPABILITIES] = 11, -#endif - [MPH_XAVIDEODECODERCAPABILITIES] = 12 -#else -#include "MPH_to_Engine.h" -#endif -}; - -const signed char MPH_to_LEDDevice[MPH_MAX] = { -#ifdef USE_DESIGNATED_INITIALIZERS - [0 ... MPH_MAX-1] = -1, - [MPH_OBJECT] = 0, - [MPH_DYNAMICINTERFACEMANAGEMENT] = 1, - [MPH_LED] = 2 -#else -#include "MPH_to_LEDDevice.h" -#endif -}; - -const signed char MPH_to_Listener[MPH_MAX] = { -#ifdef USE_DESIGNATED_INITIALIZERS - [0 ... MPH_MAX-1] = -1, - [MPH_OBJECT] = 0, - [MPH_DYNAMICINTERFACEMANAGEMENT] = 1, - [MPH_3DDOPPLER] = 2, - [MPH_3DLOCATION] = 3 -#else -#include "MPH_to_Listener.h" -#endif -}; - -const signed char MPH_to_MetadataExtractor[MPH_MAX] = { -#ifdef USE_DESIGNATED_INITIALIZERS - [0 ... MPH_MAX-1] = -1, - [MPH_OBJECT] = 0, - [MPH_DYNAMICINTERFACEMANAGEMENT] = 1, - [MPH_DYNAMICSOURCE] = 2, - [MPH_METADATAEXTRACTION] = 3, - [MPH_METADATATRAVERSAL] = 4 -#else -#include "MPH_to_MetadataExtractor.h" -#endif -}; - -const signed char MPH_to_MidiPlayer[MPH_MAX] = { -#ifdef USE_DESIGNATED_INITIALIZERS - [0 ... MPH_MAX-1] = -1, - [MPH_OBJECT] = 0, - [MPH_DYNAMICINTERFACEMANAGEMENT] = 1, - [MPH_PLAY] = 2, - [MPH_3DDOPPLER] = 3, - [MPH_3DGROUPING] = 4, - [MPH_3DLOCATION] = 5, - [MPH_3DSOURCE] = 6, - [MPH_BUFFERQUEUE] = 7, - [MPH_EFFECTSEND] = 8, - [MPH_MUTESOLO] = 9, - [MPH_METADATAEXTRACTION] = 10, - [MPH_METADATATRAVERSAL] = 11, - [MPH_MIDIMESSAGE] = 12, - [MPH_MIDITIME] = 13, - [MPH_MIDITEMPO] = 14, - [MPH_MIDIMUTESOLO] = 15, - [MPH_PREFETCHSTATUS] = 16, - [MPH_SEEK] = 17, - [MPH_VOLUME] = 18, - [MPH_3DMACROSCOPIC] = 19, - [MPH_BASSBOOST] = 20, - [MPH_DYNAMICSOURCE] = 21, - [MPH_ENVIRONMENTALREVERB] = 22, - [MPH_EQUALIZER] = 23, - [MPH_PITCH] = 24, - [MPH_PRESETREVERB] = 25, - [MPH_PLAYBACKRATE] = 26, - [MPH_VIRTUALIZER] = 27, - [MPH_VISUALIZATION] = 28, -#else -#include "MPH_to_MidiPlayer.h" -#endif -}; - -const signed char MPH_to_OutputMix[MPH_MAX] = { -#ifdef USE_DESIGNATED_INITIALIZERS - [0 ... MPH_MAX-1] = -1, - [MPH_OBJECT] = 0, - [MPH_DYNAMICINTERFACEMANAGEMENT] = 1, - [MPH_OUTPUTMIX] = 2, -#ifdef USE_OUTPUTMIXEXT - [MPH_OUTPUTMIXEXT] = 3, -#endif - [MPH_ENVIRONMENTALREVERB] = 4, - [MPH_EQUALIZER] = 5, - [MPH_PRESETREVERB] = 6, - [MPH_VIRTUALIZER] = 7, - [MPH_VOLUME] = 8, - [MPH_BASSBOOST] = 9, - [MPH_VISUALIZATION] = 10, -#ifdef ANDROID - [MPH_ANDROIDEFFECT] = 11 -#endif -#else -#include "MPH_to_OutputMix.h" -#endif -}; - -const signed char MPH_to_Vibra[MPH_MAX] = { -#ifdef USE_DESIGNATED_INITIALIZERS - [0 ... MPH_MAX-1] = -1, - [MPH_OBJECT] = 0, - [MPH_DYNAMICINTERFACEMANAGEMENT] = 1, - [MPH_VIBRA] = 2 -#else -#include "MPH_to_Vibra.h" -#endif -}; - -const signed char MPH_to_MediaPlayer[MPH_MAX] = { -#ifdef USE_DESIGNATED_INITIALIZERS - [0 ... MPH_MAX-1] = -1, - [MPH_XAOBJECT] = 0, - [MPH_XADYNAMICINTERFACEMANAGEMENT] = 1, - [MPH_XAPLAY] = 2, - [MPH_XASTREAMINFORMATION] = 3, - [MPH_XAVOLUME] = 4, - [MPH_XASEEK] = 5, - [MPH_XAPREFETCHSTATUS] = 6, -#ifdef ANDROID - [MPH_ANDROIDBUFFERQUEUESOURCE] = 7, -#endif -#else -#include "MPH_to_MediaPlayer.h" -#endif -}; diff --git a/wilhelm/src/MPH_to.h b/wilhelm/src/MPH_to.h deleted file mode 100644 index 1dc83c4e..00000000 --- a/wilhelm/src/MPH_to.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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 __MPH_to_H -#define __MPH_to_H - -/** \brief Map minimal perfect hash of an interface ID to its class index. */ - -extern const signed char - MPH_to_3DGroup[MPH_MAX], - MPH_to_AudioPlayer[MPH_MAX], - MPH_to_AudioRecorder[MPH_MAX], - MPH_to_Engine[MPH_MAX], - MPH_to_LEDDevice[MPH_MAX], - MPH_to_Listener[MPH_MAX], - MPH_to_MetadataExtractor[MPH_MAX], - MPH_to_MidiPlayer[MPH_MAX], - MPH_to_OutputMix[MPH_MAX], - MPH_to_Vibra[MPH_MAX], - MPH_to_MediaPlayer[MPH_MAX]; - -/** \brief Maximum number of interfaces on a single object. */ -#define MAX_INDEX 32 - -#endif // !defined(__MPH_to_H) diff --git a/wilhelm/src/OpenSLES_IID.c b/wilhelm/src/OpenSLES_IID.c deleted file mode 100644 index 95f05999..00000000 --- a/wilhelm/src/OpenSLES_IID.c +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (c) 2007-2009 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and /or associated documentation files (the "Materials "), to - * deal in the Materials without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Materials, and to permit persons to whom the Materials are - * furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS IN THE - * MATERIALS. - * - * OpenSLES_IID.c - OpenSL ES version 1.0 - * - */ - -/****************************************************************************/ -/* NOTE: This file is a standard OpenSL ES file and should not be */ -/* modified in any way. */ -/****************************************************************************/ - - -#include <SLES/OpenSLES.h> /* SL Header */ -#include <OMXAL/OpenMAXAL.h> -#ifdef ANDROID -#include <SLES/OpenSLES_Android.h> /* Android-specific SL Header */ -#include <OMXAL/OpenMAXAL_Android.h>/* Android-specific MAX AL Header */ -#endif -#include "MPH.h" - -#ifdef __cplusplus -LI_API extern const struct SLInterfaceID_ SL_IID_array[MPH_MAX]; -#endif - -/*****************************************************************************/ -/* Interface IDs */ -/*****************************************************************************/ - -// Note that the lack of an ifdef on each section is intentional. The entries in this table map -// to an interface GUID from an MPH (a short-hand representation of the full interface GUID). -// The presence of an entry does not represent a commitment to support that particular interface. - -const struct SLInterfaceID_ SL_IID_array[MPH_MAX] = { - -// OpenSL ES 1.0.1 interfaces - - // SL_IID_3DCOMMIT - { 0x3564ad80, 0xdd0f, 0x11db, 0x9e19, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_3DDOPPLER - { 0xb45c9a80, 0xddd2, 0x11db, 0xb028, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_3DGROUPING - { 0xebe844e0, 0xddd2, 0x11db, 0xb510, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_3DLOCATION - { 0x2b878020, 0xddd3, 0x11db, 0x8a01, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_3DMACROSCOPIC - { 0x5089aec0, 0xddd3, 0x11db, 0x9ad3, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_3DSOURCE - { 0x70bc7b00, 0xddd3, 0x11db, 0xa873, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_AUDIODECODERCAPABILITIES - { 0x3fe5a3a0, 0xfcc6, 0x11db, 0x94ac, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_AUDIOENCODER - { 0xd7d5af7a, 0x351c, 0x41a6, 0x94ec, { 0x1a, 0xc9, 0x5c, 0x71, 0x82, 0x2c } }, - // SL_IID_AUDIOENCODERCAPABILITIES - { 0x0f52a340, 0xfcd1, 0x11db, 0xa993, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_AUDIOIODEVICECAPABILITIES - { 0xb2564dc0, 0xddd3, 0x11db, 0xbd62, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_BASSBOOST - { 0x0634f220, 0xddd4, 0x11db, 0xa0fc, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_BUFFERQUEUE - { 0x2bc99cc0, 0xddd4, 0x11db, 0x8d99, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_DEVICEVOLUME - { 0xe1634760, 0xf3e2, 0x11db, 0x9ca9, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_DYNAMICINTERFACEMANAGEMENT - { 0x63936540, 0xf775, 0x11db, 0x9cc4, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_DYNAMICSOURCE - { 0xc55cc100, 0x038b, 0x11dc, 0xbb45, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_EFFECTSEND - { 0x56e7d200, 0xddd4, 0x11db, 0xaefb, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_ENGINE - { 0x8d97c260, 0xddd4, 0x11db, 0x958f, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_ENGINECAPABILITIES - { 0x8320d0a0, 0xddd5, 0x11db, 0xa1b1, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_ENVIRONMENTALREVERB - { 0xc2e5d5f0, 0x94bd, 0x4763, 0x9cac, { 0x4e, 0x23, 0x4d, 0x6, 0x83, 0x9e } }, - // SL_IID_EQUALIZER - { 0x0bed4300, 0xddd6, 0x11db, 0x8f34, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_LED - { 0x2cc1cd80, 0xddd6, 0x11db, 0x807e, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_METADATAEXTRACTION - { 0xaa5b1f80, 0xddd6, 0x11db, 0xac8e, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_METADATATRAVERSAL - { 0xc43662c0, 0xddd6, 0x11db, 0xa7ab, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_MIDIMESSAGE - { 0xddf4a820, 0xddd6, 0x11db, 0xb174, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_MIDIMUTESOLO - { 0x039eaf80, 0xddd7, 0x11db, 0x9a02, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_MIDITEMPO - { 0x1f347400, 0xddd7, 0x11db, 0xa7ce, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_MIDITIME - { 0x3da51de0, 0xddd7, 0x11db, 0xaf70, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_MUTESOLO - { 0x5a28ebe0, 0xddd7, 0x11db, 0x8220, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_NULL - { 0xec7178ec, 0xe5e1, 0x4432, 0xa3f4, { 0x46, 0x57, 0xe6, 0x79, 0x52, 0x10 } }, - // SL_IID_OBJECT - { 0x79216360, 0xddd7, 0x11db, 0xac16, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_OUTPUTMIX - { 0x97750f60, 0xddd7, 0x11db, 0x92b1, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_PITCH - { 0xc7e8ee00, 0xddd7, 0x11db, 0xa42c, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_PLAY - { 0xef0bd9c0, 0xddd7, 0x11db, 0xbf49, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_PLAYBACKRATE - { 0x2e3b2a40, 0xddda, 0x11db, 0xa349, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_PREFETCHSTATUS - { 0x2a41ee80, 0xddd8, 0x11db, 0xa41f, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_PRESETREVERB - { 0x47382d60, 0xddd8, 0x11db, 0xbf3a, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_RATEPITCH - { 0x61b62e60, 0xddda, 0x11db, 0x9eb8, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_RECORD - { 0xc5657aa0, 0xdddb, 0x11db, 0x82f7, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_SEEK - { 0xd43135a0, 0xdddc, 0x11db, 0xb458, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_THREADSYNC - { 0xf6ac6b40, 0xdddc, 0x11db, 0xa62e, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_VIBRA - { 0x169a8d60, 0xdddd, 0x11db, 0x923d, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_VIRTUALIZER - { 0x37cc2c00, 0xdddd, 0x11db, 0x8577, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_VISUALIZATION - { 0xe46b26a0, 0xdddd, 0x11db, 0x8afd, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_VOLUME - { 0x09e8ede0, 0xddde, 0x11db, 0xb4f6, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - -// Wilhelm desktop extended interfaces - - // SL_IID_OUTPUTMIXEXT - { 0xfe5cce00, 0x57bb, 0x11df, 0x951c, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - -// Android API level 9 extended interfaces -// GUID and MPH shared by SL and XA, but currently documented for SL only - - // SL_IID_ANDROIDEFFECT - { 0xae12da60, 0x99ac, 0x11df, 0xb456, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_ANDROIDEFFECTCAPABILITIES - { 0x6a4f6d60, 0xb5e6, 0x11df, 0xbb3b, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_ANDROIDEFFECTSEND - { 0x7be462c0, 0xbc43, 0x11df, 0x8670, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_ANDROIDCONFIGURATION - { 0x89f6a7e0, 0xbeac, 0x11df, 0x8b5c, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // SL_IID_ANDROIDSIMPLEBUFERQUEUE - { 0x198e4940, 0xc5d7, 0x11df, 0xa2a6, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - -// Android API level 12 extended interfaces -// GUID and MPH shared by SL and XA, but currently documented for XA only - - // SL_IID_ANDROIDBUFFERQUEUESOURCE - { 0x7fc1a460, 0xeec1, 0x11df, 0xa306, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - -// OpenMAX AL 1.0.1 interfaces - - // XA_IID_AUDIODECODERCAPABILITIES - { 0xdeac0cc0, 0x3995, 0x11dc, 0x8872, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_AUDIOENCODER - { 0xebbab900, 0x3997, 0x11dc, 0x891f, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_AUDIOENCODERCAPABILITIES - { 0x83fbc600, 0x3998, 0x11dc, 0x8f6d, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_AUDIOIODEVICECAPABILITIES - { 0x2b276d00, 0xf775, 0x11db, 0xa963, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_CAMERA - { 0xc7b84d20, 0xdf00, 0x11db, 0xba87, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_CAMERACAPABILITIES - { 0x01cab1c0, 0xe86a, 0x11db, 0xa5b9, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_CONFIGEXTENSION - { 0x6dc22ea0, 0xdf03, 0x11db, 0xbed7, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_DEVICEVOLUME - { 0x4bb44020, 0xf775, 0x11db, 0xad03, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_DYNAMICINTERFACEMANAGEMENT - { 0x6e2340c0, 0xf775, 0x11db, 0x85da, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_DYNAMICSOURCE - { 0xc88d5480, 0x3a12, 0x11dc, 0x80a2, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_ENGINE - { 0x45c58f40, 0xdf04, 0x11db, 0x9e76, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_EQUALIZER - { 0x7ad86d40, 0xf775, 0x11db, 0xbc77, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_IMAGECONTROLS - { 0xf46de3e0, 0xdf03, 0x11db, 0x92f1, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_IMAGEDECODERCAPABILITIES - { 0xc333e7a0, 0xe616, 0x11dc, 0xa93e, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_IMAGEEFFECTS - { 0xb865bca0, 0xdf04, 0x11db, 0xbab9, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_IMAGEENCODER - { 0xcd49f140, 0xdf04, 0x11db, 0x8888, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_IMAGEENCODERCAPABILITIES - { 0xc19f0640, 0xe86f, 0x11db, 0xb2d2, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_LED - { 0xa534d920, 0xf775, 0x11db, 0x8b70, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_METADATAEXTRACTION - { 0x5df4fda0, 0xf776, 0x11db, 0xabc5, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_METADATAINSERTION - { 0x49a14d60, 0xdf05, 0x11db, 0x9191, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_METADATATRAVERSAL - { 0x73ffb0e0, 0xf776, 0x11db, 0xa00e, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_OBJECT - { 0x82f5a5a0, 0xf776, 0x11db, 0x9700, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_OUTPUTMIX - { 0xb25b6fa0, 0xf776, 0x11db, 0xb86b, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_NULL - // shared with OpenSL ES - // XA_IID_PLAY - { 0xb9c293e0, 0xf776, 0x11db, 0x80df, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_PLAYBACKRATE - { 0xc36f1440, 0xf776, 0x11db, 0xac48, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_PREFETCHSTATUS - { 0xcceac0a0, 0xf776, 0x11db, 0xbb9c, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_RADIO - { 0xb316ad80, 0xdf05, 0x11db, 0xb5b6, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_RDS - { 0xb80f42c0, 0xdf05, 0x11db, 0x92a5, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_RECORD - { 0xd7948cc0, 0xf776, 0x11db, 0x8a3b, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_SEEK - { 0xee6a3120, 0xf776, 0x11db, 0xb518, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_SNAPSHOT - { 0xdb1b6dc0, 0xdf05, 0x11db, 0x8c01, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_STREAMINFORMATION - { 0x3a628fe0, 0x1238, 0x11de, 0xad9f, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_THREADSYNC - { 0xf3599ea0, 0xf776, 0x11db, 0xb3ea, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_VIBRA - { 0xfe374c00, 0xf776, 0x11db, 0xa8f0, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_VIDEODECODERCAPABILITIES - { 0xd18cb200, 0xe616, 0x11dc, 0xab01, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_VIDEOENCODER - { 0x9444db60, 0xdf06, 0x11db, 0xb311, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_VIDEOENCODERCAPABILITIES - { 0x5aef2760, 0xe872, 0x11db, 0x849f, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_VIDEOPOSTPROCESSING - { 0x898b6820, 0x7e6e, 0x11dd, 0x8caf, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, - // XA_IID_VOLUME - { 0x088ba520, 0xf777, 0x11db, 0xa5e3, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, -}; diff --git a/wilhelm/src/README.txt b/wilhelm/src/README.txt deleted file mode 100644 index 8230d1b7..00000000 --- a/wilhelm/src/README.txt +++ /dev/null @@ -1,15 +0,0 @@ -This is the source code for the Wilhelm project, an implementation of native audio -and multimedia for Android based on Khronos Group OpenSL ES and OpenMAX AL 1.0.1. - -Top-level: - * Makefile - * Initial entry points - * Common glue code - -Subdirectories: -android/ Android platform-specific code, other than interfaces -autogen/ Automagically generated files, do not edit by hand -desktop/ Experimental desktop PC platform-specific code -itf/ OpenSL ES and OpenMAX AL interfaces, including Android-specific extensions -objects/ OpenSL ES and OpenMAX AL objects aka classes -ut/ Private utility toolkit diff --git a/wilhelm/src/ThreadPool.c b/wilhelm/src/ThreadPool.c deleted file mode 100644 index 20130cf5..00000000 --- a/wilhelm/src/ThreadPool.c +++ /dev/null @@ -1,393 +0,0 @@ -/* - * 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. - */ - -/* ThreadPool */ - -#include "sles_allinclusive.h" - -// Entry point for each worker thread - -static void *ThreadPool_start(void *context) -{ - ThreadPool *tp = (ThreadPool *) context; - assert(NULL != tp); - for (;;) { - Closure *pClosure = ThreadPool_remove(tp); - // closure is NULL when thread pool is being destroyed - if (NULL == pClosure) { - break; - } - // make a copy of parameters, then free the parameters - const Closure closure = *pClosure; - free(pClosure); - // extract parameters and call the right method depending on kind - ClosureKind kind = closure.mKind; - void *context1 = closure.mContext1; - void *context2 = closure.mContext2; - int parameter1 = closure.mParameter1; - switch (kind) { - case CLOSURE_KIND_PPI: - { - ClosureHandler_ppi handler_ppi = closure.mHandler.mHandler_ppi; - assert(NULL != handler_ppi); - (*handler_ppi)(context1, context2, parameter1); - } - break; - case CLOSURE_KIND_PPII: - { - ClosureHandler_ppii handler_ppii = closure.mHandler.mHandler_ppii; - assert(NULL != handler_ppii); - int parameter2 = closure.mParameter2; - (*handler_ppii)(context1, context2, parameter1, parameter2); - } - break; - case CLOSURE_KIND_PIIPP: - { - ClosureHandler_piipp handler_piipp = closure.mHandler.mHandler_piipp; - assert(NULL != handler_piipp); - int parameter2 = closure.mParameter2; - void *context3 = closure.mContext3; - (*handler_piipp)(context1, parameter1, parameter2, context2, context3); - } - break; - default: - SL_LOGE("Unexpected callback kind %d", kind); - assert(false); - break; - } - } - return NULL; -} - -#define INITIALIZED_NONE 0 -#define INITIALIZED_MUTEX 1 -#define INITIALIZED_CONDNOTFULL 2 -#define INITIALIZED_CONDNOTEMPTY 4 -#define INITIALIZED_ALL 7 - -static void ThreadPool_deinit_internal(ThreadPool *tp, unsigned initialized, unsigned nThreads); - -// Initialize a ThreadPool -// maxClosures defaults to CLOSURE_TYPICAL if 0 -// maxThreads defaults to THREAD_TYPICAL if 0 - -SLresult ThreadPool_init(ThreadPool *tp, unsigned maxClosures, unsigned maxThreads) -{ - assert(NULL != tp); - memset(tp, 0, sizeof(ThreadPool)); - tp->mShutdown = SL_BOOLEAN_FALSE; - unsigned initialized = INITIALIZED_NONE; // which objects were successfully initialized - unsigned nThreads = 0; // number of threads successfully created - int err; - SLresult result; - - // initialize mutex and condition variables - err = pthread_mutex_init(&tp->mMutex, (const pthread_mutexattr_t *) NULL); - result = err_to_result(err); - if (SL_RESULT_SUCCESS != result) - goto fail; - initialized |= INITIALIZED_MUTEX; - err = pthread_cond_init(&tp->mCondNotFull, (const pthread_condattr_t *) NULL); - result = err_to_result(err); - if (SL_RESULT_SUCCESS != result) - goto fail; - initialized |= INITIALIZED_CONDNOTFULL; - err = pthread_cond_init(&tp->mCondNotEmpty, (const pthread_condattr_t *) NULL); - result = err_to_result(err); - if (SL_RESULT_SUCCESS != result) - goto fail; - initialized |= INITIALIZED_CONDNOTEMPTY; - - // use default values for parameters, if not specified explicitly - tp->mWaitingNotFull = 0; - tp->mWaitingNotEmpty = 0; - if (0 == maxClosures) - maxClosures = CLOSURE_TYPICAL; - tp->mMaxClosures = maxClosures; - if (0 == maxThreads) - maxThreads = THREAD_TYPICAL; - tp->mMaxThreads = maxThreads; - - // initialize circular buffer for closures - if (CLOSURE_TYPICAL >= maxClosures) { - tp->mClosureArray = tp->mClosureTypical; - } else { - tp->mClosureArray = (Closure **) malloc((maxClosures + 1) * sizeof(Closure *)); - if (NULL == tp->mClosureArray) { - result = SL_RESULT_RESOURCE_ERROR; - goto fail; - } - } - tp->mClosureFront = tp->mClosureArray; - tp->mClosureRear = tp->mClosureArray; - - // initialize thread pool - if (THREAD_TYPICAL >= maxThreads) { - tp->mThreadArray = tp->mThreadTypical; - } else { - tp->mThreadArray = (pthread_t *) malloc(maxThreads * sizeof(pthread_t)); - if (NULL == tp->mThreadArray) { - result = SL_RESULT_RESOURCE_ERROR; - goto fail; - } - } - unsigned i; - for (i = 0; i < maxThreads; ++i) { - int err = pthread_create(&tp->mThreadArray[i], (const pthread_attr_t *) NULL, - ThreadPool_start, tp); - result = err_to_result(err); - if (SL_RESULT_SUCCESS != result) - goto fail; - ++nThreads; - } - tp->mInitialized = initialized; - - // done - return SL_RESULT_SUCCESS; - - // here on any kind of error -fail: - ThreadPool_deinit_internal(tp, initialized, nThreads); - return result; -} - -static void ThreadPool_deinit_internal(ThreadPool *tp, unsigned initialized, unsigned nThreads) -{ - int ok; - - assert(NULL != tp); - // Destroy all threads - if (0 < nThreads) { - assert(INITIALIZED_ALL == initialized); - ok = pthread_mutex_lock(&tp->mMutex); - assert(0 == ok); - tp->mShutdown = SL_BOOLEAN_TRUE; - ok = pthread_cond_broadcast(&tp->mCondNotEmpty); - assert(0 == ok); - ok = pthread_cond_broadcast(&tp->mCondNotFull); - assert(0 == ok); - ok = pthread_mutex_unlock(&tp->mMutex); - assert(0 == ok); - unsigned i; - for (i = 0; i < nThreads; ++i) { - ok = pthread_join(tp->mThreadArray[i], (void **) NULL); - assert(ok == 0); - } - - // Empty out the circular buffer of closures - ok = pthread_mutex_lock(&tp->mMutex); - assert(0 == ok); - Closure **oldFront = tp->mClosureFront; - while (oldFront != tp->mClosureRear) { - Closure **newFront = oldFront; - if (++newFront == &tp->mClosureArray[tp->mMaxClosures + 1]) - newFront = tp->mClosureArray; - Closure *pClosure = *oldFront; - assert(NULL != pClosure); - *oldFront = NULL; - tp->mClosureFront = newFront; - ok = pthread_mutex_unlock(&tp->mMutex); - assert(0 == ok); - free(pClosure); - ok = pthread_mutex_lock(&tp->mMutex); - assert(0 == ok); - } - ok = pthread_mutex_unlock(&tp->mMutex); - assert(0 == ok); - // Note that we can't be sure when mWaitingNotFull will drop to zero - } - - // destroy the mutex and condition variables - if (initialized & INITIALIZED_CONDNOTEMPTY) { - ok = pthread_cond_destroy(&tp->mCondNotEmpty); - assert(0 == ok); - } - if (initialized & INITIALIZED_CONDNOTFULL) { - ok = pthread_cond_destroy(&tp->mCondNotFull); - assert(0 == ok); - } - if (initialized & INITIALIZED_MUTEX) { - ok = pthread_mutex_destroy(&tp->mMutex); - assert(0 == ok); - } - tp->mInitialized = INITIALIZED_NONE; - - // release the closure circular buffer - if (tp->mClosureTypical != tp->mClosureArray && NULL != tp->mClosureArray) { - free(tp->mClosureArray); - tp->mClosureArray = NULL; - } - - // release the thread pool - if (tp->mThreadTypical != tp->mThreadArray && NULL != tp->mThreadArray) { - free(tp->mThreadArray); - tp->mThreadArray = NULL; - } - -} - -void ThreadPool_deinit(ThreadPool *tp) -{ - ThreadPool_deinit_internal(tp, tp->mInitialized, tp->mMaxThreads); -} - -// Enqueue a closure to be executed later by a worker thread. -// Note that this raw interface requires an explicit "kind" and full parameter list. -// There are convenience methods below that make this easier to use. -SLresult ThreadPool_add(ThreadPool *tp, ClosureKind kind, ClosureHandler_generic handler, - void *context1, void *context2, void *context3, int parameter1, int parameter2) -{ - assert(NULL != tp); - assert(NULL != handler); - Closure *closure = (Closure *) malloc(sizeof(Closure)); - if (NULL == closure) { - return SL_RESULT_RESOURCE_ERROR; - } - closure->mKind = kind; - switch(kind) { - case CLOSURE_KIND_PPI: - closure->mHandler.mHandler_ppi = (ClosureHandler_ppi)handler; - break; - case CLOSURE_KIND_PPII: - closure->mHandler.mHandler_ppii = (ClosureHandler_ppii)handler; - break; - case CLOSURE_KIND_PIIPP: - closure->mHandler.mHandler_piipp = (ClosureHandler_piipp)handler; - break; - default: - SL_LOGE("ThreadPool_add() invalid closure kind %d", kind); - assert(false); - } - closure->mContext1 = context1; - closure->mContext2 = context2; - closure->mContext3 = context3; - closure->mParameter1 = parameter1; - closure->mParameter2 = parameter2; - int ok; - ok = pthread_mutex_lock(&tp->mMutex); - assert(0 == ok); - // can't enqueue while thread pool shutting down - if (tp->mShutdown) { - ok = pthread_mutex_unlock(&tp->mMutex); - assert(0 == ok); - free(closure); - return SL_RESULT_PRECONDITIONS_VIOLATED; - } - for (;;) { - Closure **oldRear = tp->mClosureRear; - Closure **newRear = oldRear; - if (++newRear == &tp->mClosureArray[tp->mMaxClosures + 1]) - newRear = tp->mClosureArray; - // if closure circular buffer is full, then wait for it to become non-full - if (newRear == tp->mClosureFront) { - ++tp->mWaitingNotFull; - ok = pthread_cond_wait(&tp->mCondNotFull, &tp->mMutex); - assert(0 == ok); - // can't enqueue while thread pool shutting down - if (tp->mShutdown) { - assert(0 < tp->mWaitingNotFull); - --tp->mWaitingNotFull; - ok = pthread_mutex_unlock(&tp->mMutex); - assert(0 == ok); - free(closure); - return SL_RESULT_PRECONDITIONS_VIOLATED; - } - continue; - } - assert(NULL == *oldRear); - *oldRear = closure; - tp->mClosureRear = newRear; - // if a worker thread was waiting to dequeue, then suggest that it try again - if (0 < tp->mWaitingNotEmpty) { - --tp->mWaitingNotEmpty; - ok = pthread_cond_signal(&tp->mCondNotEmpty); - assert(0 == ok); - } - break; - } - ok = pthread_mutex_unlock(&tp->mMutex); - assert(0 == ok); - return SL_RESULT_SUCCESS; -} - -// Called by a worker thread when it is ready to accept the next closure to execute -Closure *ThreadPool_remove(ThreadPool *tp) -{ - Closure *pClosure; - int ok; - ok = pthread_mutex_lock(&tp->mMutex); - assert(0 == ok); - for (;;) { - // fail if thread pool is shutting down - if (tp->mShutdown) { - pClosure = NULL; - break; - } - Closure **oldFront = tp->mClosureFront; - // if closure circular buffer is empty, then wait for it to become non-empty - if (oldFront == tp->mClosureRear) { - ++tp->mWaitingNotEmpty; - ok = pthread_cond_wait(&tp->mCondNotEmpty, &tp->mMutex); - assert(0 == ok); - // try again - continue; - } - // dequeue the closure at front of circular buffer - Closure **newFront = oldFront; - if (++newFront == &tp->mClosureArray[tp->mMaxClosures + 1]) { - newFront = tp->mClosureArray; - } - pClosure = *oldFront; - assert(NULL != pClosure); - *oldFront = NULL; - tp->mClosureFront = newFront; - // if a client thread was waiting to enqueue, then suggest that it try again - if (0 < tp->mWaitingNotFull) { - --tp->mWaitingNotFull; - ok = pthread_cond_signal(&tp->mCondNotFull); - assert(0 == ok); - } - break; - } - ok = pthread_mutex_unlock(&tp->mMutex); - assert(0 == ok); - return pClosure; -} - -// Convenience methods for applications -SLresult ThreadPool_add_ppi(ThreadPool *tp, ClosureHandler_ppi handler, - void *context1, void *context2, int parameter1) -{ - // function pointers are the same size so this is a safe cast - return ThreadPool_add(tp, CLOSURE_KIND_PPI, (ClosureHandler_generic) handler, - context1, context2, NULL, parameter1, 0); -} - -SLresult ThreadPool_add_ppii(ThreadPool *tp, ClosureHandler_ppii handler, - void *context1, void *context2, int parameter1, int parameter2) -{ - // function pointers are the same size so this is a safe cast - return ThreadPool_add(tp, CLOSURE_KIND_PPII, (ClosureHandler_generic) handler, - context1, context2, NULL, parameter1, parameter2); -} - -SLresult ThreadPool_add_piipp(ThreadPool *tp, ClosureHandler_piipp handler, - void *cntxt1, int param1, int param2, void *cntxt2, void *cntxt3) -{ - // function pointers are the same size so this is a safe cast - return ThreadPool_add(tp, CLOSURE_KIND_PIIPP, (ClosureHandler_generic) handler, - cntxt1, cntxt2, cntxt3, param1, param2); -} diff --git a/wilhelm/src/ThreadPool.h b/wilhelm/src/ThreadPool.h deleted file mode 100644 index 27031a3a..00000000 --- a/wilhelm/src/ThreadPool.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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. - */ - -/** \file ThreadPool.h ThreadPool interface */ - -/** Kind of closure */ - -typedef enum { - CLOSURE_KIND_PPI, // void *, void *, int - CLOSURE_KIND_PPII, // void *, void *, int, int - CLOSURE_KIND_PIIPP // void *, int, int, void *, void * -} ClosureKind; - -/** Closure handlers */ - -typedef void (*ClosureHandler_generic)(void *p1, void *p2, void *p3, int i1, int i2); -typedef void (*ClosureHandler_ppi) (void *p1, void *p2, int i1); -typedef void (*ClosureHandler_ppii) (void *p1, void *p2, int i1, int i2); -typedef void (*ClosureHandler_piipp) (void *p1, int i1, int i2, void *p2, void *p3); - -/** \brief Closure represents a deferred computation */ - -typedef struct { - union { - ClosureHandler_ppi mHandler_ppi; - ClosureHandler_ppii mHandler_ppii; - ClosureHandler_piipp mHandler_piipp; - } mHandler; - ClosureKind mKind; - void *mContext1; - void *mContext2; - void *mContext3; - int mParameter1; - int mParameter2; -} Closure; - -/** \brief ThreadPool manages a pool of worker threads that execute Closures */ - -typedef struct { - unsigned mInitialized; ///< Indicates which of the following 3 fields are initialized - pthread_mutex_t mMutex; - pthread_cond_t mCondNotFull; ///< Signalled when a client thread could be unblocked - pthread_cond_t mCondNotEmpty; ///< Signalled when a worker thread could be unblocked - SLboolean mShutdown; ///< Whether shutdown of thread pool has been requested - unsigned mWaitingNotFull; ///< Number of client threads waiting to enqueue - unsigned mWaitingNotEmpty; ///< Number of worker threads waiting to dequeue - unsigned mMaxClosures; ///< Number of slots in circular buffer for closures, not counting spare - unsigned mMaxThreads; ///< Number of worker threads - Closure **mClosureArray; ///< The circular buffer of closures - Closure **mClosureFront, **mClosureRear; - /// Saves a malloc in the typical case -#define CLOSURE_TYPICAL 15 - Closure *mClosureTypical[CLOSURE_TYPICAL+1]; - pthread_t *mThreadArray; ///< The worker threads -#ifdef ANDROID -// Note: if you set THREAD_TYPICAL to a non-zero value because you -// want to use asynchronous callbacks, be aware that any value greater -// than 1 can result in out-of-order callbacks on a given player, in the -// current implementation. Thus you should probably configure 1 total or -// change the implementation so that it uses at most 1 thread per player. -#if defined(USE_ASYNCHRONOUS_PLAY_CALLBACK) || \ - defined(USE_ASYNCHRONOUS_STREAMCBEVENT_PROPERTYCHANGE_CALLBACK) -#define THREAD_TYPICAL 1 -#else -#define THREAD_TYPICAL 0 -#endif -#else // !ANDROID -#define THREAD_TYPICAL 4 -#endif - pthread_t mThreadTypical[THREAD_TYPICAL]; -} ThreadPool; - -extern SLresult ThreadPool_init(ThreadPool *tp, unsigned maxClosures, unsigned maxThreads); -extern void ThreadPool_deinit(ThreadPool *tp); -extern SLresult ThreadPool_add(ThreadPool *tp, ClosureKind kind, - ClosureHandler_generic, - void *cntxt1, void *cntxt2, void *cntxt3, int param1, int param2); -extern Closure *ThreadPool_remove(ThreadPool *tp); -extern SLresult ThreadPool_add_ppi(ThreadPool *tp, ClosureHandler_ppi handler, - void *cntxt1, void *cntxt2, int param1); -extern SLresult ThreadPool_add_ppii(ThreadPool *tp, ClosureHandler_ppii handler, - void *cntxt1, void *cntxt2, int param1, int param2); -extern SLresult ThreadPool_add_piipp(ThreadPool *tp, ClosureHandler_piipp handler, - void *cntxt1, int param1, int param2, void *cntxt2, void *cntxt3); diff --git a/wilhelm/src/android/AacBqToPcmCbRenderer.cpp b/wilhelm/src/android/AacBqToPcmCbRenderer.cpp deleted file mode 100644 index 194662bd..00000000 --- a/wilhelm/src/android/AacBqToPcmCbRenderer.cpp +++ /dev/null @@ -1,222 +0,0 @@ -/* - * 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. - */ - -//#define USE_LOG SLAndroidLogLevel_Debug - -#include "sles_allinclusive.h" -#include "android/include/AacBqToPcmCbRenderer.h" -#include <media/stagefright/foundation/ADebug.h> - -namespace android { - -// ADTS header size is 7, but frame size information ends on byte 6 (when counting from byte 1) -#define ADTS_HEADER_SIZE_UP_TO_FRAMESIZE 6 - -/** - * Returns the size of an AAC ADTS frame. - * Note that if the returned value + offset > size, it means that a partial frame starts at that - * offset, but this function will still return the size of the full frame. - * @param data pointer to the compressed audio data - * @param offset offset in bytes relative to data of where the frame is supposed to start - * @param size the size in bytes of the data block starting at data - * @return the size in bytes of the AAC ADTS frame starting at the given offset of the given - * memory address, 0 if the frame couldn't be parsed. - */ -static size_t getAdtsFrameSize(const uint8_t *data, off64_t offset, size_t size) { - size_t frameSize = 0; - - if (!(offset + ADTS_HEADER_SIZE_UP_TO_FRAMESIZE < size)) { - SL_LOGE("AacBqToPcmCbRenderer::getAdtsFrameSize() returns 0 (can't read syncword or header)" - ); - return 0; - } - - const uint8_t *syncword = data + offset; - if ((syncword[0] != 0xff) || ((syncword[1] & 0xf6) != 0xf0)) { - SL_LOGE("AacBqToPcmCbRenderer::getAdtsFrameSize() returns 0 (wrong syncword)"); - return 0; - } - - const uint8_t protectionAbsent = data[offset+1] & 0x1; - - const uint8_t* header = data + offset + 3; - frameSize = (header[0] & 0x3) << 11 | header[1] << 3 | header[2] >> 5; - // the frame size read already contains the size of the header, so no need to add it here - - // protectionAbsent is 0 if there is CRC - static const size_t kAdtsHeaderLengthNoCrc = 7; - static const size_t kAdtsHeaderLengthWithCrc = 9; - size_t headSize = protectionAbsent ? kAdtsHeaderLengthNoCrc : kAdtsHeaderLengthWithCrc; - if (headSize > frameSize) { - SL_LOGE("AacBqToPcmCbRenderer::getAdtsFrameSize() returns 0 (frameSize %u < headSize %u)", - frameSize, headSize); - return 0; - } - - SL_LOGV("AacBqToPcmCbRenderer::getAdtsFrameSize() returns %u", frameSize); - - return frameSize; -} - -/** - * Returns whether a block of memory starts and ends on AAC ADTS frame boundaries - * @param data pointer to the compressed audio data - * @param size the size in bytes of the data block to validate - * @return SL_RESULT_SUCCESS if there is AAC ADTS data, and it starts and ends on frame boundaries, - * or an appropriate error code otherwise: - * SL_RESULT_PARAMETER_INVALID if not possible to attempt validation of even one frame - * SL_RESULT_CONTENT_CORRUPTED if the frame contents are otherwise invalid - */ -SLresult AacBqToPcmCbRenderer::validateBufferStartEndOnFrameBoundaries(void* data, size_t size) -{ - off64_t offset = 0; - size_t frameSize = 0; - - if ((NULL == data) || (size == 0)) { - SL_LOGE("No ADTS to validate"); - return SL_RESULT_PARAMETER_INVALID; - } - - while (offset < size) { - if ((frameSize = getAdtsFrameSize((uint8_t *)data, offset, size)) == 0) { - SL_LOGE("found ADTS frame of size 0 at offset %llu", offset); - return SL_RESULT_CONTENT_CORRUPTED; - } - //SL_LOGV("last good offset %llu", offset); - offset += frameSize; - if (offset > size) { - SL_LOGE("found incomplete ADTS frame at end of data"); - return SL_RESULT_CONTENT_CORRUPTED; - } - } - if (offset != size) { SL_LOGE("ADTS parsing error: reached end of incomplete frame"); } - assert(offset == size); - return SL_RESULT_SUCCESS; -} - -//-------------------------------------------------------------------------------------------------- -AacBqToPcmCbRenderer::AacBqToPcmCbRenderer(const AudioPlayback_Parameters* params, - IAndroidBufferQueue *androidBufferQueue) : - AudioToCbRenderer(params), - mBqSource(new BufferQueueSource(androidBufferQueue)) -{ - SL_LOGD("AacBqToPcmCbRenderer::AacBqToPcmCbRenderer()"); -} - - -AacBqToPcmCbRenderer::~AacBqToPcmCbRenderer() { - SL_LOGD("AacBqToPcmCbRenderer::~AacBqToPcmCbRenderer()"); - -} - - -//-------------------------------------------------- -// Event handlers -void AacBqToPcmCbRenderer::onPrepare() { - SL_LOGD("AacBqToPcmCbRenderer::onPrepare()"); - Mutex::Autolock _l(mBufferSourceLock); - - // Initialize the PCM format info with the known parameters before the start of the decode - { - android::Mutex::Autolock autoLock(mPcmFormatLock); - mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_BITSPERSAMPLE] = SL_PCMSAMPLEFORMAT_FIXED_16; - mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_CONTAINERSIZE] = 16; - //FIXME not true on all platforms - mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_ENDIANNESS] = SL_BYTEORDER_LITTLEENDIAN; - // initialization with the default values: they will be replaced by the actual values - // once the decoder has figured them out - mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_NUMCHANNELS] = UNKNOWN_NUMCHANNELS; - mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_SAMPLERATE] = UNKNOWN_SAMPLERATE; - mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_CHANNELMASK] = UNKNOWN_CHANNELMASK; - } - - sp<MediaExtractor> extractor = new AacAdtsExtractor(mBqSource); - - // only decoding a single track of data - const size_t kTrackToDecode = 0; - - sp<MediaSource> source = extractor->getTrack(kTrackToDecode); - if (source == 0) { - SL_LOGE("AacBqToPcmCbRenderer::onPrepare: error getting source from extractor"); - notifyPrepared(ERROR_UNSUPPORTED); - return; - } - sp<MetaData> meta = extractor->getTrackMetaData(kTrackToDecode); - - // the audio content is not raw PCM, so we need a decoder - OMXClient client; - CHECK_EQ(client.connect(), (status_t)OK); - - source = OMXCodec::Create( - client.interface(), meta, false /* createEncoder */, - source); - - if (source == NULL) { - SL_LOGE("AacBqToPcmCbRenderer::onPrepare: Could not instantiate decoder."); - notifyPrepared(ERROR_UNSUPPORTED); - return; - } - - meta = source->getFormat(); - - SL_LOGD("AacBqToPcmCbRenderer::onPrepare() after instantiating decoder"); - - if (source->start() != OK) { - SL_LOGE("AacBqToPcmCbRenderer::onPrepare() Failed to start source/decoder."); - notifyPrepared(MEDIA_ERROR_BASE); - return; - } - - //--------------------------------- - int32_t channelCount; - CHECK(meta->findInt32(kKeyChannelCount, &channelCount)); - int32_t sr; - CHECK(meta->findInt32(kKeySampleRate, &sr)); - // FIXME similar to AudioSfDecoder::onPrepare() - - // already "good to go" (compare to AudioSfDecoder::onPrepare) - mCacheStatus = kStatusHigh; - mCacheFill = 1000; - notifyStatus(); - notifyCacheFill(); - - { - android::Mutex::Autolock autoLock(mPcmFormatLock); - mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_SAMPLERATE] = sr; - mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_NUMCHANNELS] = channelCount; - mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_CHANNELMASK] = - channelCountToMask(channelCount); - } - SL_LOGV("AacBqToPcmCbRenderer::onPrepare() channel count=%d SR=%d", - channelCount, sr); - - //--------------------------------- - // The data source, and audio source (a decoder) are ready to be used - mDataSource = mBqSource; - mAudioSource = source; - mAudioSourceStarted = true; - - //------------------------------------- - // signal successful completion of prepare - mStateFlags |= kFlagPrepared; - - // skipping past AudioToCbRenderer and AudioSfDecoder - GenericPlayer::onPrepare(); - - SL_LOGD("AacBqToPcmCbRenderer::onPrepare() done, mStateFlags=0x%x", mStateFlags); -} - -} // namespace android diff --git a/wilhelm/src/android/AudioPlayer_to_android.cpp b/wilhelm/src/android/AudioPlayer_to_android.cpp deleted file mode 100644 index ae526fe2..00000000 --- a/wilhelm/src/android/AudioPlayer_to_android.cpp +++ /dev/null @@ -1,2163 +0,0 @@ -/* - * 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. - */ - -#include "sles_allinclusive.h" -#include "android_prompts.h" -#include "android/android_AudioToCbRenderer.h" -#include "android/android_StreamPlayer.h" -#include "android/android_LocAVPlayer.h" -#include "android/include/AacBqToPcmCbRenderer.h" - -#include <fcntl.h> -#include <sys/stat.h> - -#include <system/audio.h> - -template class android::KeyedVector<SLuint32, android::AudioEffect* > ; - -#define KEY_STREAM_TYPE_PARAMSIZE sizeof(SLint32) - -#define AUDIOTRACK_MIN_PLAYBACKRATE_PERMILLE 500 -#define AUDIOTRACK_MAX_PLAYBACKRATE_PERMILLE 2000 - -//----------------------------------------------------------------------------- -// FIXME this method will be absorbed into android_audioPlayer_setPlayState() once -// bufferqueue and uri/fd playback are moved under the GenericPlayer C++ object -SLresult aplayer_setPlayState(const android::sp<android::GenericPlayer> &ap, SLuint32 playState, - AndroidObjectState* pObjState) { - SLresult result = SL_RESULT_SUCCESS; - AndroidObjectState objState = *pObjState; - - switch (playState) { - case SL_PLAYSTATE_STOPPED: - SL_LOGV("setting GenericPlayer to SL_PLAYSTATE_STOPPED"); - ap->stop(); - break; - case SL_PLAYSTATE_PAUSED: - SL_LOGV("setting GenericPlayer to SL_PLAYSTATE_PAUSED"); - switch(objState) { - case ANDROID_UNINITIALIZED: - *pObjState = ANDROID_PREPARING; - ap->prepare(); - break; - case ANDROID_PREPARING: - break; - case ANDROID_READY: - ap->pause(); - break; - default: - SL_LOGE(ERROR_PLAYERSETPLAYSTATE_INVALID_OBJECT_STATE_D, playState); - result = SL_RESULT_INTERNAL_ERROR; - break; - } - break; - case SL_PLAYSTATE_PLAYING: { - SL_LOGV("setting GenericPlayer to SL_PLAYSTATE_PLAYING"); - switch(objState) { - case ANDROID_UNINITIALIZED: - *pObjState = ANDROID_PREPARING; - ap->prepare(); - // intended fall through - case ANDROID_PREPARING: - // intended fall through - case ANDROID_READY: - ap->play(); - break; - default: - SL_LOGE(ERROR_PLAYERSETPLAYSTATE_INVALID_OBJECT_STATE_D, playState); - result = SL_RESULT_INTERNAL_ERROR; - break; - } - } - break; - default: - // checked by caller, should not happen - SL_LOGE(ERROR_SHOULDNT_BE_HERE_S, "aplayer_setPlayState"); - result = SL_RESULT_INTERNAL_ERROR; - break; - } - - return result; -} - - -//----------------------------------------------------------------------------- -// Callback associated with a AudioToCbRenderer of an SL ES AudioPlayer that gets its data -// from a URI or FD, to write the decoded audio data to a buffer queue -static size_t adecoder_writeToBufferQueue(const uint8_t *data, size_t size, CAudioPlayer* ap) { - if (!android::CallbackProtector::enterCbIfOk(ap->mCallbackProtector)) { - // it is not safe to enter the callback (the player is about to go away) - return 0; - } - size_t sizeConsumed = 0; - SL_LOGD("received %d bytes from decoder", size); - slBufferQueueCallback callback = NULL; - void * callbackPContext = NULL; - - // push decoded data to the buffer queue - object_lock_exclusive(&ap->mObject); - - if (ap->mBufferQueue.mState.count != 0) { - assert(ap->mBufferQueue.mFront != ap->mBufferQueue.mRear); - - BufferHeader *oldFront = ap->mBufferQueue.mFront; - BufferHeader *newFront = &oldFront[1]; - - uint8_t *pDest = (uint8_t *)oldFront->mBuffer + ap->mBufferQueue.mSizeConsumed; - if (ap->mBufferQueue.mSizeConsumed + size < oldFront->mSize) { - // room to consume the whole or rest of the decoded data in one shot - ap->mBufferQueue.mSizeConsumed += size; - // consume data but no callback to the BufferQueue interface here - memcpy (pDest, data, size); - sizeConsumed = size; - } else { - // push as much as possible of the decoded data into the buffer queue - sizeConsumed = oldFront->mSize - ap->mBufferQueue.mSizeConsumed; - - // the buffer at the head of the buffer queue is full, update the state - ap->mBufferQueue.mSizeConsumed = 0; - if (newFront == &ap->mBufferQueue.mArray[ap->mBufferQueue.mNumBuffers + 1]) { - newFront = ap->mBufferQueue.mArray; - } - ap->mBufferQueue.mFront = newFront; - - ap->mBufferQueue.mState.count--; - ap->mBufferQueue.mState.playIndex++; - // consume data - memcpy (pDest, data, sizeConsumed); - // data has been copied to the buffer, and the buffer queue state has been updated - // we will notify the client if applicable - callback = ap->mBufferQueue.mCallback; - // save callback data - callbackPContext = ap->mBufferQueue.mContext; - } - - } else { - // no available buffers in the queue to write the decoded data - sizeConsumed = 0; - } - - object_unlock_exclusive(&ap->mObject); - // notify client - if (NULL != callback) { - (*callback)(&ap->mBufferQueue.mItf, callbackPContext); - } - - ap->mCallbackProtector->exitCb(); - return sizeConsumed; -} - -//----------------------------------------------------------------------------- -int android_getMinFrameCount(uint32_t sampleRate) { - int afSampleRate; - if (android::AudioSystem::getOutputSamplingRate(&afSampleRate, - ANDROID_DEFAULT_OUTPUT_STREAM_TYPE) != android::NO_ERROR) { - return ANDROID_DEFAULT_AUDIOTRACK_BUFFER_SIZE; - } - int afFrameCount; - if (android::AudioSystem::getOutputFrameCount(&afFrameCount, - ANDROID_DEFAULT_OUTPUT_STREAM_TYPE) != android::NO_ERROR) { - return ANDROID_DEFAULT_AUDIOTRACK_BUFFER_SIZE; - } - uint32_t afLatency; - if (android::AudioSystem::getOutputLatency(&afLatency, - ANDROID_DEFAULT_OUTPUT_STREAM_TYPE) != android::NO_ERROR) { - return ANDROID_DEFAULT_AUDIOTRACK_BUFFER_SIZE; - } - // minimum nb of buffers to cover output latency, given the size of each hardware audio buffer - uint32_t minBufCount = afLatency / ((1000 * afFrameCount)/afSampleRate); - if (minBufCount < 2) minBufCount = 2; - // minimum number of frames to cover output latency at the sample rate of the content - return (afFrameCount*sampleRate*minBufCount)/afSampleRate; -} - - -//----------------------------------------------------------------------------- -#define LEFT_CHANNEL_MASK 0x1 << 0 -#define RIGHT_CHANNEL_MASK 0x1 << 1 - -void android_audioPlayer_volumeUpdate(CAudioPlayer* ap) -{ - assert(ap != NULL); - - // the source's channel count, where zero means unknown - SLuint8 channelCount = ap->mNumChannels; - - // whether each channel is audible - bool leftAudibilityFactor, rightAudibilityFactor; - - // mute has priority over solo - if (channelCount >= STEREO_CHANNELS) { - if (ap->mMuteMask & LEFT_CHANNEL_MASK) { - // left muted - leftAudibilityFactor = false; - } else { - // left not muted - if (ap->mSoloMask & LEFT_CHANNEL_MASK) { - // left soloed - leftAudibilityFactor = true; - } else { - // left not soloed - if (ap->mSoloMask & RIGHT_CHANNEL_MASK) { - // right solo silences left - leftAudibilityFactor = false; - } else { - // left and right are not soloed, and left is not muted - leftAudibilityFactor = true; - } - } - } - - if (ap->mMuteMask & RIGHT_CHANNEL_MASK) { - // right muted - rightAudibilityFactor = false; - } else { - // right not muted - if (ap->mSoloMask & RIGHT_CHANNEL_MASK) { - // right soloed - rightAudibilityFactor = true; - } else { - // right not soloed - if (ap->mSoloMask & LEFT_CHANNEL_MASK) { - // left solo silences right - rightAudibilityFactor = false; - } else { - // left and right are not soloed, and right is not muted - rightAudibilityFactor = true; - } - } - } - - // channel mute and solo are ignored for mono and unknown channel count sources - } else { - leftAudibilityFactor = true; - rightAudibilityFactor = true; - } - - // compute volumes without setting - const bool audibilityFactors[2] = {leftAudibilityFactor, rightAudibilityFactor}; - float volumes[2]; - android_player_volumeUpdate(volumes, &ap->mVolume, channelCount, ap->mAmplFromDirectLevel, - audibilityFactors); - float leftVol = volumes[0], rightVol = volumes[1]; - - // set volume on the underlying media player or audio track - if (ap->mAPlayer != 0) { - ap->mAPlayer->setVolume(leftVol, rightVol); - } else if (ap->mAudioTrack != 0) { - ap->mAudioTrack->setVolume(leftVol, rightVol); - } - - // changes in the AudioPlayer volume must be reflected in the send level: - // in SLEffectSendItf or in SLAndroidEffectSendItf? - // FIXME replace interface test by an internal API once we have one. - if (NULL != ap->mEffectSend.mItf) { - for (unsigned int i=0 ; i<AUX_MAX ; i++) { - if (ap->mEffectSend.mEnableLevels[i].mEnable) { - android_fxSend_setSendLevel(ap, - ap->mEffectSend.mEnableLevels[i].mSendLevel + ap->mVolume.mLevel); - // there's a single aux bus on Android, so we can stop looking once the first - // aux effect is found. - break; - } - } - } else if (NULL != ap->mAndroidEffectSend.mItf) { - android_fxSend_setSendLevel(ap, ap->mAndroidEffectSend.mSendLevel + ap->mVolume.mLevel); - } -} - -// Called by android_audioPlayer_volumeUpdate and android_mediaPlayer_volumeUpdate to compute -// volumes, but setting volumes is handled by the caller. - -void android_player_volumeUpdate(float *pVolumes /*[2]*/, const IVolume *volumeItf, unsigned -channelCount, float amplFromDirectLevel, const bool *audibilityFactors /*[2]*/) -{ - assert(pVolumes != NULL); - assert(volumeItf != NULL); - // OK for audibilityFactors to be NULL - - bool leftAudibilityFactor, rightAudibilityFactor; - - // apply player mute factor - // note that AudioTrack has mute() but not MediaPlayer, so it's easier to use volume - // to mute for both rather than calling mute() for AudioTrack - - // player is muted - if (volumeItf->mMute) { - leftAudibilityFactor = false; - rightAudibilityFactor = false; - // player isn't muted, and channel mute/solo audibility factors are available (AudioPlayer) - } else if (audibilityFactors != NULL) { - leftAudibilityFactor = audibilityFactors[0]; - rightAudibilityFactor = audibilityFactors[1]; - // player isn't muted, and channel mute/solo audibility factors aren't available (MediaPlayer) - } else { - leftAudibilityFactor = true; - rightAudibilityFactor = true; - } - - // compute amplification as the combination of volume level and stereo position - // amplification (or attenuation) from volume level - float amplFromVolLevel = sles_to_android_amplification(volumeItf->mLevel); - // amplification from direct level (changed in SLEffectSendtItf and SLAndroidEffectSendItf) - float leftVol = amplFromVolLevel * amplFromDirectLevel; - float rightVol = leftVol; - - // amplification from stereo position - if (volumeItf->mEnableStereoPosition) { - // Left/right amplification (can be attenuations) factors derived for the StereoPosition - float amplFromStereoPos[STEREO_CHANNELS]; - // panning law depends on content channel count: mono to stereo panning vs stereo balance - if (1 == channelCount) { - // mono to stereo panning - double theta = (1000+volumeItf->mStereoPosition)*M_PI_4/1000.0f; // 0 <= theta <= Pi/2 - amplFromStereoPos[0] = cos(theta); - amplFromStereoPos[1] = sin(theta); - // channel count is 0 (unknown), 2 (stereo), or > 2 (multi-channel) - } else { - // stereo balance - if (volumeItf->mStereoPosition > 0) { - amplFromStereoPos[0] = (1000-volumeItf->mStereoPosition)/1000.0f; - amplFromStereoPos[1] = 1.0f; - } else { - amplFromStereoPos[0] = 1.0f; - amplFromStereoPos[1] = (1000+volumeItf->mStereoPosition)/1000.0f; - } - } - leftVol *= amplFromStereoPos[0]; - rightVol *= amplFromStereoPos[1]; - } - - // apply audibility factors - if (!leftAudibilityFactor) { - leftVol = 0.0; - } - if (!rightAudibilityFactor) { - rightVol = 0.0; - } - - // return the computed volumes - pVolumes[0] = leftVol; - pVolumes[1] = rightVol; -} - -//----------------------------------------------------------------------------- -void audioTrack_handleMarker_lockPlay(CAudioPlayer* ap) { - //SL_LOGV("received event EVENT_MARKER from AudioTrack"); - slPlayCallback callback = NULL; - void* callbackPContext = NULL; - - interface_lock_shared(&ap->mPlay); - callback = ap->mPlay.mCallback; - callbackPContext = ap->mPlay.mContext; - interface_unlock_shared(&ap->mPlay); - - if (NULL != callback) { - // getting this event implies SL_PLAYEVENT_HEADATMARKER was set in the event mask - (*callback)(&ap->mPlay.mItf, callbackPContext, SL_PLAYEVENT_HEADATMARKER); - } -} - -//----------------------------------------------------------------------------- -void audioTrack_handleNewPos_lockPlay(CAudioPlayer* ap) { - //SL_LOGV("received event EVENT_NEW_POS from AudioTrack"); - slPlayCallback callback = NULL; - void* callbackPContext = NULL; - - interface_lock_shared(&ap->mPlay); - callback = ap->mPlay.mCallback; - callbackPContext = ap->mPlay.mContext; - interface_unlock_shared(&ap->mPlay); - - if (NULL != callback) { - // getting this event implies SL_PLAYEVENT_HEADATNEWPOS was set in the event mask - (*callback)(&ap->mPlay.mItf, callbackPContext, SL_PLAYEVENT_HEADATNEWPOS); - } -} - - -//----------------------------------------------------------------------------- -void audioTrack_handleUnderrun_lockPlay(CAudioPlayer* ap) { - slPlayCallback callback = NULL; - void* callbackPContext = NULL; - - interface_lock_shared(&ap->mPlay); - callback = ap->mPlay.mCallback; - callbackPContext = ap->mPlay.mContext; - bool headStalled = (ap->mPlay.mEventFlags & SL_PLAYEVENT_HEADSTALLED) != 0; - interface_unlock_shared(&ap->mPlay); - - if ((NULL != callback) && headStalled) { - (*callback)(&ap->mPlay.mItf, callbackPContext, SL_PLAYEVENT_HEADSTALLED); - } -} - - -//----------------------------------------------------------------------------- -/** - * post-condition: play state of AudioPlayer is SL_PLAYSTATE_PAUSED if setPlayStateToPaused is true - * - * note: a conditional flag, setPlayStateToPaused, is used here to specify whether the play state - * needs to be changed when the player reaches the end of the content to play. This is - * relative to what the specification describes for buffer queues vs the - * SL_PLAYEVENT_HEADATEND event. In the OpenSL ES specification 1.0.1: - * - section 8.12 SLBufferQueueItf states "In the case of starvation due to insufficient - * buffers in the queue, the playing of audio data stops. The player remains in the - * SL_PLAYSTATE_PLAYING state." - * - section 9.2.31 SL_PLAYEVENT states "SL_PLAYEVENT_HEADATEND Playback head is at the end - * of the current content and the player has paused." - */ -void audioPlayer_dispatch_headAtEnd_lockPlay(CAudioPlayer *ap, bool setPlayStateToPaused, - bool needToLock) { - //SL_LOGV("ap=%p, setPlayStateToPaused=%d, needToLock=%d", ap, setPlayStateToPaused, - // needToLock); - slPlayCallback playCallback = NULL; - void * playContext = NULL; - // SLPlayItf callback or no callback? - if (needToLock) { - interface_lock_exclusive(&ap->mPlay); - } - if (ap->mPlay.mEventFlags & SL_PLAYEVENT_HEADATEND) { - playCallback = ap->mPlay.mCallback; - playContext = ap->mPlay.mContext; - } - if (setPlayStateToPaused) { - ap->mPlay.mState = SL_PLAYSTATE_PAUSED; - } - if (needToLock) { - interface_unlock_exclusive(&ap->mPlay); - } - // enqueue callback with no lock held - if (NULL != playCallback) { -#ifndef USE_ASYNCHRONOUS_PLAY_CALLBACK - (*playCallback)(&ap->mPlay.mItf, playContext, SL_PLAYEVENT_HEADATEND); -#else - SLresult result = EnqueueAsyncCallback_ppi(ap, playCallback, &ap->mPlay.mItf, playContext, - SL_PLAYEVENT_HEADATEND); - if (SL_RESULT_SUCCESS != result) { - ALOGW("Callback %p(%p, %p, SL_PLAYEVENT_HEADATEND) dropped", playCallback, - &ap->mPlay.mItf, playContext); - } -#endif - } - -} - - -//----------------------------------------------------------------------------- -SLresult audioPlayer_setStreamType(CAudioPlayer* ap, SLint32 type) { - SLresult result = SL_RESULT_SUCCESS; - SL_LOGV("type %d", type); - - audio_stream_type_t newStreamType = ANDROID_DEFAULT_OUTPUT_STREAM_TYPE; - switch(type) { - case SL_ANDROID_STREAM_VOICE: - newStreamType = AUDIO_STREAM_VOICE_CALL; - break; - case SL_ANDROID_STREAM_SYSTEM: - newStreamType = AUDIO_STREAM_SYSTEM; - break; - case SL_ANDROID_STREAM_RING: - newStreamType = AUDIO_STREAM_RING; - break; - case SL_ANDROID_STREAM_MEDIA: - newStreamType = AUDIO_STREAM_MUSIC; - break; - case SL_ANDROID_STREAM_ALARM: - newStreamType = AUDIO_STREAM_ALARM; - break; - case SL_ANDROID_STREAM_NOTIFICATION: - newStreamType = AUDIO_STREAM_NOTIFICATION; - break; - default: - SL_LOGE(ERROR_PLAYERSTREAMTYPE_SET_UNKNOWN_TYPE); - result = SL_RESULT_PARAMETER_INVALID; - break; - } - - // stream type needs to be set before the object is realized - // (ap->mAudioTrack is supposed to be NULL until then) - if (SL_OBJECT_STATE_UNREALIZED != ap->mObject.mState) { - SL_LOGE(ERROR_PLAYERSTREAMTYPE_REALIZED); - result = SL_RESULT_PRECONDITIONS_VIOLATED; - } else { - ap->mStreamType = newStreamType; - } - - return result; -} - - -//----------------------------------------------------------------------------- -SLresult audioPlayer_getStreamType(CAudioPlayer* ap, SLint32 *pType) { - SLresult result = SL_RESULT_SUCCESS; - - switch(ap->mStreamType) { - case AUDIO_STREAM_VOICE_CALL: - *pType = SL_ANDROID_STREAM_VOICE; - break; - case AUDIO_STREAM_SYSTEM: - *pType = SL_ANDROID_STREAM_SYSTEM; - break; - case AUDIO_STREAM_RING: - *pType = SL_ANDROID_STREAM_RING; - break; - case AUDIO_STREAM_DEFAULT: - case AUDIO_STREAM_MUSIC: - *pType = SL_ANDROID_STREAM_MEDIA; - break; - case AUDIO_STREAM_ALARM: - *pType = SL_ANDROID_STREAM_ALARM; - break; - case AUDIO_STREAM_NOTIFICATION: - *pType = SL_ANDROID_STREAM_NOTIFICATION; - break; - default: - result = SL_RESULT_INTERNAL_ERROR; - *pType = SL_ANDROID_STREAM_MEDIA; - break; - } - - return result; -} - - -//----------------------------------------------------------------------------- -void audioPlayer_auxEffectUpdate(CAudioPlayer* ap) { - if ((ap->mAudioTrack != 0) && (ap->mAuxEffect != 0)) { - android_fxSend_attach(ap, true, ap->mAuxEffect, ap->mVolume.mLevel + ap->mAuxSendLevel); - } -} - - -//----------------------------------------------------------------------------- -/* - * returns true if the given data sink is supported by AudioPlayer that doesn't - * play to an OutputMix object, false otherwise - * - * pre-condition: the locator of the audio sink is not SL_DATALOCATOR_OUTPUTMIX - */ -bool audioPlayer_isSupportedNonOutputMixSink(const SLDataSink* pAudioSink) { - bool result = true; - const SLuint32 sinkLocatorType = *(SLuint32 *)pAudioSink->pLocator; - const SLuint32 sinkFormatType = *(SLuint32 *)pAudioSink->pFormat; - - switch (sinkLocatorType) { - - case SL_DATALOCATOR_BUFFERQUEUE: - case SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE: - if (SL_DATAFORMAT_PCM != sinkFormatType) { - SL_LOGE("Unsupported sink format 0x%x, expected SL_DATAFORMAT_PCM", - (unsigned)sinkFormatType); - result = false; - } - // it's no use checking the PCM format fields because additional characteristics - // such as the number of channels, or sample size are unknown to the player at this stage - break; - - default: - SL_LOGE("Unsupported sink locator type 0x%x", (unsigned)sinkLocatorType); - result = false; - break; - } - - return result; -} - - -//----------------------------------------------------------------------------- -/* - * returns the Android object type if the locator type combinations for the source and sinks - * are supported by this implementation, INVALID_TYPE otherwise - */ -AndroidObjectType audioPlayer_getAndroidObjectTypeForSourceSink(CAudioPlayer *ap) { - - const SLDataSource *pAudioSrc = &ap->mDataSource.u.mSource; - const SLDataSink *pAudioSnk = &ap->mDataSink.u.mSink; - const SLuint32 sourceLocatorType = *(SLuint32 *)pAudioSrc->pLocator; - const SLuint32 sinkLocatorType = *(SLuint32 *)pAudioSnk->pLocator; - AndroidObjectType type = INVALID_TYPE; - - //-------------------------------------- - // Sink / source matching check: - // the following source / sink combinations are supported - // SL_DATALOCATOR_BUFFERQUEUE / SL_DATALOCATOR_OUTPUTMIX - // SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE / SL_DATALOCATOR_OUTPUTMIX - // SL_DATALOCATOR_URI / SL_DATALOCATOR_OUTPUTMIX - // SL_DATALOCATOR_ANDROIDFD / SL_DATALOCATOR_OUTPUTMIX - // SL_DATALOCATOR_ANDROIDBUFFERQUEUE / SL_DATALOCATOR_OUTPUTMIX - // SL_DATALOCATOR_ANDROIDBUFFERQUEUE / SL_DATALOCATOR_BUFFERQUEUE - // SL_DATALOCATOR_URI / SL_DATALOCATOR_BUFFERQUEUE - // SL_DATALOCATOR_ANDROIDFD / SL_DATALOCATOR_BUFFERQUEUE - // SL_DATALOCATOR_URI / SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE - // SL_DATALOCATOR_ANDROIDFD / SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE - switch (sinkLocatorType) { - - case SL_DATALOCATOR_OUTPUTMIX: { - switch (sourceLocatorType) { - - // Buffer Queue to AudioTrack - case SL_DATALOCATOR_BUFFERQUEUE: - case SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE: - type = AUDIOPLAYER_FROM_PCM_BUFFERQUEUE; - break; - - // URI or FD to MediaPlayer - case SL_DATALOCATOR_URI: - case SL_DATALOCATOR_ANDROIDFD: - type = AUDIOPLAYER_FROM_URIFD; - break; - - // Android BufferQueue to MediaPlayer (shared memory streaming) - case SL_DATALOCATOR_ANDROIDBUFFERQUEUE: - type = AUDIOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE; - break; - - default: - SL_LOGE("Source data locator 0x%x not supported with SL_DATALOCATOR_OUTPUTMIX sink", - (unsigned)sourceLocatorType); - break; - } - } - break; - - case SL_DATALOCATOR_BUFFERQUEUE: - case SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE: - switch (sourceLocatorType) { - - // URI or FD decoded to PCM in a buffer queue - case SL_DATALOCATOR_URI: - case SL_DATALOCATOR_ANDROIDFD: - type = AUDIOPLAYER_FROM_URIFD_TO_PCM_BUFFERQUEUE; - break; - - // AAC ADTS Android buffer queue decoded to PCM in a buffer queue - case SL_DATALOCATOR_ANDROIDBUFFERQUEUE: - type = AUDIOPLAYER_FROM_ADTS_ABQ_TO_PCM_BUFFERQUEUE; - break; - - default: - SL_LOGE("Source data locator 0x%x not supported with SL_DATALOCATOR_BUFFERQUEUE sink", - (unsigned)sourceLocatorType); - break; - } - break; - - default: - SL_LOGE("Sink data locator 0x%x not supported", (unsigned)sinkLocatorType); - break; - } - - return type; -} - - -//----------------------------------------------------------------------------- -/* - * Callback associated with an SfPlayer of an SL ES AudioPlayer that gets its data - * from a URI or FD, for prepare, prefetch, and play events - */ -static void sfplayer_handlePrefetchEvent(int event, int data1, int data2, void* user) { - - // FIXME see similar code and comment in player_handleMediaPlayerEventNotifications - - if (NULL == user) { - return; - } - - CAudioPlayer *ap = (CAudioPlayer *)user; - if (!android::CallbackProtector::enterCbIfOk(ap->mCallbackProtector)) { - // it is not safe to enter the callback (the track is about to go away) - return; - } - union { - char c[sizeof(int)]; - int i; - } u; - u.i = event; - SL_LOGV("sfplayer_handlePrefetchEvent(event='%c%c%c%c' (%d), data1=%d, data2=%d, user=%p) from " - "SfAudioPlayer", u.c[3], u.c[2], u.c[1], u.c[0], event, data1, data2, user); - switch(event) { - - case android::GenericPlayer::kEventPrepared: { - SL_LOGV("Received GenericPlayer::kEventPrepared for CAudioPlayer %p", ap); - - // assume no callback - slPrefetchCallback callback = NULL; - void* callbackPContext; - SLuint32 events; - - object_lock_exclusive(&ap->mObject); - - // mark object as prepared; same state is used for successful or unsuccessful prepare - assert(ap->mAndroidObjState == ANDROID_PREPARING); - ap->mAndroidObjState = ANDROID_READY; - - if (PLAYER_SUCCESS == data1) { - // Most of successful prepare completion for ap->mAPlayer - // is handled by GenericPlayer and its subclasses. - } else { - // SfPlayer prepare() failed prefetching, there is no event in SLPrefetchStatus to - // indicate a prefetch error, so we signal it by sending simultaneously two events: - // - SL_PREFETCHEVENT_FILLLEVELCHANGE with a level of 0 - // - SL_PREFETCHEVENT_STATUSCHANGE with a status of SL_PREFETCHSTATUS_UNDERFLOW - SL_LOGE(ERROR_PLAYER_PREFETCH_d, data1); - if (IsInterfaceInitialized(&(ap->mObject), MPH_PREFETCHSTATUS)) { - ap->mPrefetchStatus.mLevel = 0; - ap->mPrefetchStatus.mStatus = SL_PREFETCHSTATUS_UNDERFLOW; - if (!(~ap->mPrefetchStatus.mCallbackEventsMask & - (SL_PREFETCHEVENT_FILLLEVELCHANGE | SL_PREFETCHEVENT_STATUSCHANGE))) { - callback = ap->mPrefetchStatus.mCallback; - callbackPContext = ap->mPrefetchStatus.mContext; - events = SL_PREFETCHEVENT_FILLLEVELCHANGE | SL_PREFETCHEVENT_STATUSCHANGE; - } - } - } - - object_unlock_exclusive(&ap->mObject); - - // callback with no lock held - if (NULL != callback) { - (*callback)(&ap->mPrefetchStatus.mItf, callbackPContext, events); - } - - } - break; - - case android::GenericPlayer::kEventPrefetchFillLevelUpdate : { - if (!IsInterfaceInitialized(&(ap->mObject), MPH_PREFETCHSTATUS)) { - break; - } - slPrefetchCallback callback = NULL; - void* callbackPContext = NULL; - - // SLPrefetchStatusItf callback or no callback? - interface_lock_exclusive(&ap->mPrefetchStatus); - if (ap->mPrefetchStatus.mCallbackEventsMask & SL_PREFETCHEVENT_FILLLEVELCHANGE) { - callback = ap->mPrefetchStatus.mCallback; - callbackPContext = ap->mPrefetchStatus.mContext; - } - ap->mPrefetchStatus.mLevel = (SLpermille)data1; - interface_unlock_exclusive(&ap->mPrefetchStatus); - - // callback with no lock held - if (NULL != callback) { - (*callback)(&ap->mPrefetchStatus.mItf, callbackPContext, - SL_PREFETCHEVENT_FILLLEVELCHANGE); - } - } - break; - - case android::GenericPlayer::kEventPrefetchStatusChange: { - if (!IsInterfaceInitialized(&(ap->mObject), MPH_PREFETCHSTATUS)) { - break; - } - slPrefetchCallback callback = NULL; - void* callbackPContext = NULL; - - // SLPrefetchStatusItf callback or no callback? - object_lock_exclusive(&ap->mObject); - if (ap->mPrefetchStatus.mCallbackEventsMask & SL_PREFETCHEVENT_STATUSCHANGE) { - callback = ap->mPrefetchStatus.mCallback; - callbackPContext = ap->mPrefetchStatus.mContext; - } - if (data1 >= android::kStatusIntermediate) { - ap->mPrefetchStatus.mStatus = SL_PREFETCHSTATUS_SUFFICIENTDATA; - } else if (data1 < android::kStatusIntermediate) { - ap->mPrefetchStatus.mStatus = SL_PREFETCHSTATUS_UNDERFLOW; - } - object_unlock_exclusive(&ap->mObject); - - // callback with no lock held - if (NULL != callback) { - (*callback)(&ap->mPrefetchStatus.mItf, callbackPContext, SL_PREFETCHEVENT_STATUSCHANGE); - } - } - break; - - case android::GenericPlayer::kEventEndOfStream: { - audioPlayer_dispatch_headAtEnd_lockPlay(ap, true /*set state to paused?*/, true); - if ((ap->mAudioTrack != 0) && (!ap->mSeek.mLoopEnabled)) { - ap->mAudioTrack->stop(); - } - } - break; - - case android::GenericPlayer::kEventChannelCount: { - object_lock_exclusive(&ap->mObject); - if (UNKNOWN_NUMCHANNELS == ap->mNumChannels && UNKNOWN_NUMCHANNELS != data1) { - ap->mNumChannels = data1; - android_audioPlayer_volumeUpdate(ap); - } - object_unlock_exclusive(&ap->mObject); - } - break; - - case android::GenericPlayer::kEventPlay: { - slPlayCallback callback = NULL; - void* callbackPContext = NULL; - - interface_lock_shared(&ap->mPlay); - callback = ap->mPlay.mCallback; - callbackPContext = ap->mPlay.mContext; - interface_unlock_shared(&ap->mPlay); - - if (NULL != callback) { - SLuint32 event = (SLuint32) data1; // SL_PLAYEVENT_HEAD* -#ifndef USE_ASYNCHRONOUS_PLAY_CALLBACK - // synchronous callback requires a synchronous GetPosition implementation - (*callback)(&ap->mPlay.mItf, callbackPContext, event); -#else - // asynchronous callback works with any GetPosition implementation - SLresult result = EnqueueAsyncCallback_ppi(ap, callback, &ap->mPlay.mItf, - callbackPContext, event); - if (SL_RESULT_SUCCESS != result) { - ALOGW("Callback %p(%p, %p, 0x%x) dropped", callback, - &ap->mPlay.mItf, callbackPContext, event); - } -#endif - } - } - break; - - case android::GenericPlayer::kEventErrorAfterPrepare: { - SL_LOGV("kEventErrorAfterPrepare"); - - // assume no callback - slPrefetchCallback callback = NULL; - void* callbackPContext = NULL; - - object_lock_exclusive(&ap->mObject); - if (IsInterfaceInitialized(&ap->mObject, MPH_PREFETCHSTATUS)) { - ap->mPrefetchStatus.mLevel = 0; - ap->mPrefetchStatus.mStatus = SL_PREFETCHSTATUS_UNDERFLOW; - if (!(~ap->mPrefetchStatus.mCallbackEventsMask & - (SL_PREFETCHEVENT_FILLLEVELCHANGE | SL_PREFETCHEVENT_STATUSCHANGE))) { - callback = ap->mPrefetchStatus.mCallback; - callbackPContext = ap->mPrefetchStatus.mContext; - } - } - object_unlock_exclusive(&ap->mObject); - - // FIXME there's interesting information in data1, but no API to convey it to client - SL_LOGE("Error after prepare: %d", data1); - - // callback with no lock held - if (NULL != callback) { - (*callback)(&ap->mPrefetchStatus.mItf, callbackPContext, - SL_PREFETCHEVENT_FILLLEVELCHANGE | SL_PREFETCHEVENT_STATUSCHANGE); - } - - } - break; - - case android::GenericPlayer::kEventHasVideoSize: - //SL_LOGW("Unexpected kEventHasVideoSize"); - break; - - default: - break; - } - - ap->mCallbackProtector->exitCb(); -} - - -//----------------------------------------------------------------------------- -SLresult android_audioPlayer_checkSourceSink(CAudioPlayer *pAudioPlayer) -{ - // verify that the locator types for the source / sink combination is supported - pAudioPlayer->mAndroidObjType = audioPlayer_getAndroidObjectTypeForSourceSink(pAudioPlayer); - if (INVALID_TYPE == pAudioPlayer->mAndroidObjType) { - return SL_RESULT_PARAMETER_INVALID; - } - - const SLDataSource *pAudioSrc = &pAudioPlayer->mDataSource.u.mSource; - const SLDataSink *pAudioSnk = &pAudioPlayer->mDataSink.u.mSink; - - // format check: - const SLuint32 sourceLocatorType = *(SLuint32 *)pAudioSrc->pLocator; - const SLuint32 sinkLocatorType = *(SLuint32 *)pAudioSnk->pLocator; - const SLuint32 sourceFormatType = *(SLuint32 *)pAudioSrc->pFormat; - const SLuint32 sinkFormatType = *(SLuint32 *)pAudioSnk->pFormat; - - switch (sourceLocatorType) { - //------------------ - // Buffer Queues - case SL_DATALOCATOR_BUFFERQUEUE: - case SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE: - { - SLDataLocator_BufferQueue *dl_bq = (SLDataLocator_BufferQueue *) pAudioSrc->pLocator; - - // Buffer format - switch (sourceFormatType) { - // currently only PCM buffer queues are supported, - case SL_DATAFORMAT_PCM: { - SLDataFormat_PCM *df_pcm = (SLDataFormat_PCM *) pAudioSrc->pFormat; - switch (df_pcm->numChannels) { - case 1: - case 2: - break; - default: - // this should have already been rejected by checkDataFormat - SL_LOGE("Cannot create audio player: unsupported " \ - "PCM data source with %u channels", (unsigned) df_pcm->numChannels); - return SL_RESULT_CONTENT_UNSUPPORTED; - } - switch (df_pcm->samplesPerSec) { - case SL_SAMPLINGRATE_8: - case SL_SAMPLINGRATE_11_025: - case SL_SAMPLINGRATE_12: - case SL_SAMPLINGRATE_16: - case SL_SAMPLINGRATE_22_05: - case SL_SAMPLINGRATE_24: - case SL_SAMPLINGRATE_32: - case SL_SAMPLINGRATE_44_1: - case SL_SAMPLINGRATE_48: - break; - case SL_SAMPLINGRATE_64: - case SL_SAMPLINGRATE_88_2: - case SL_SAMPLINGRATE_96: - case SL_SAMPLINGRATE_192: - default: - SL_LOGE("Cannot create audio player: unsupported sample rate %u milliHz", - (unsigned) df_pcm->samplesPerSec); - return SL_RESULT_CONTENT_UNSUPPORTED; - } - switch (df_pcm->bitsPerSample) { - case SL_PCMSAMPLEFORMAT_FIXED_8: - case SL_PCMSAMPLEFORMAT_FIXED_16: - break; - // others - default: - // this should have already been rejected by checkDataFormat - SL_LOGE("Cannot create audio player: unsupported sample bit depth %u", - (SLuint32)df_pcm->bitsPerSample); - return SL_RESULT_CONTENT_UNSUPPORTED; - } - switch (df_pcm->containerSize) { - case 8: - case 16: - break; - // others - default: - SL_LOGE("Cannot create audio player: unsupported container size %u", - (unsigned) df_pcm->containerSize); - return SL_RESULT_CONTENT_UNSUPPORTED; - } - // df_pcm->channelMask: the earlier platform-independent check and the - // upcoming check by sles_to_android_channelMaskOut are sufficient - switch (df_pcm->endianness) { - case SL_BYTEORDER_LITTLEENDIAN: - break; - case SL_BYTEORDER_BIGENDIAN: - SL_LOGE("Cannot create audio player: unsupported big-endian byte order"); - return SL_RESULT_CONTENT_UNSUPPORTED; - // native is proposed but not yet in spec - default: - SL_LOGE("Cannot create audio player: unsupported byte order %u", - (unsigned) df_pcm->endianness); - return SL_RESULT_CONTENT_UNSUPPORTED; - } - } //case SL_DATAFORMAT_PCM - break; - case SL_DATAFORMAT_MIME: - case XA_DATAFORMAT_RAWIMAGE: - SL_LOGE("Cannot create audio player with buffer queue data source " - "without SL_DATAFORMAT_PCM format"); - return SL_RESULT_CONTENT_UNSUPPORTED; - default: - // invalid data format is detected earlier - assert(false); - return SL_RESULT_INTERNAL_ERROR; - } // switch (sourceFormatType) - } // case SL_DATALOCATOR_BUFFERQUEUE or SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE - break; - //------------------ - // URI - case SL_DATALOCATOR_URI: - { - SLDataLocator_URI *dl_uri = (SLDataLocator_URI *) pAudioSrc->pLocator; - if (NULL == dl_uri->URI) { - return SL_RESULT_PARAMETER_INVALID; - } - // URI format - switch (sourceFormatType) { - case SL_DATAFORMAT_MIME: - break; - case SL_DATAFORMAT_PCM: - case XA_DATAFORMAT_RAWIMAGE: - SL_LOGE("Cannot create audio player with SL_DATALOCATOR_URI data source without " - "SL_DATAFORMAT_MIME format"); - return SL_RESULT_CONTENT_UNSUPPORTED; - } // switch (sourceFormatType) - // decoding format check - if ((sinkLocatorType != SL_DATALOCATOR_OUTPUTMIX) && - !audioPlayer_isSupportedNonOutputMixSink(pAudioSnk)) { - return SL_RESULT_CONTENT_UNSUPPORTED; - } - } // case SL_DATALOCATOR_URI - break; - //------------------ - // File Descriptor - case SL_DATALOCATOR_ANDROIDFD: - { - // fd is already non null - switch (sourceFormatType) { - case SL_DATAFORMAT_MIME: - break; - case SL_DATAFORMAT_PCM: - // FIXME implement - SL_LOGD("[ FIXME implement PCM FD data sources ]"); - break; - case XA_DATAFORMAT_RAWIMAGE: - SL_LOGE("Cannot create audio player with SL_DATALOCATOR_ANDROIDFD data source " - "without SL_DATAFORMAT_MIME or SL_DATAFORMAT_PCM format"); - return SL_RESULT_CONTENT_UNSUPPORTED; - default: - // invalid data format is detected earlier - assert(false); - return SL_RESULT_INTERNAL_ERROR; - } // switch (sourceFormatType) - if ((sinkLocatorType != SL_DATALOCATOR_OUTPUTMIX) && - !audioPlayer_isSupportedNonOutputMixSink(pAudioSnk)) { - return SL_RESULT_CONTENT_UNSUPPORTED; - } - } // case SL_DATALOCATOR_ANDROIDFD - break; - //------------------ - // Stream - case SL_DATALOCATOR_ANDROIDBUFFERQUEUE: - { - switch (sourceFormatType) { - case SL_DATAFORMAT_MIME: - { - SLDataFormat_MIME *df_mime = (SLDataFormat_MIME *) pAudioSrc->pFormat; - if (NULL == df_mime) { - SL_LOGE("MIME type null invalid"); - return SL_RESULT_CONTENT_UNSUPPORTED; - } - SL_LOGD("source MIME is %s", (char*)df_mime->mimeType); - switch(df_mime->containerType) { - case SL_CONTAINERTYPE_MPEG_TS: - if (strcasecmp((char*)df_mime->mimeType, (const char *)XA_ANDROID_MIME_MP2TS)) { - SL_LOGE("Invalid MIME (%s) for container SL_CONTAINERTYPE_MPEG_TS, expects %s", - (char*)df_mime->mimeType, XA_ANDROID_MIME_MP2TS); - return SL_RESULT_CONTENT_UNSUPPORTED; - } - break; - case SL_CONTAINERTYPE_RAW: - case SL_CONTAINERTYPE_AAC: - if (strcasecmp((char*)df_mime->mimeType, (const char *)SL_ANDROID_MIME_AACADTS) && - strcasecmp((char*)df_mime->mimeType, - ANDROID_MIME_AACADTS_ANDROID_FRAMEWORK)) { - SL_LOGE("Invalid MIME (%s) for container type %d, expects %s", - (char*)df_mime->mimeType, df_mime->containerType, - SL_ANDROID_MIME_AACADTS); - return SL_RESULT_CONTENT_UNSUPPORTED; - } - break; - default: - SL_LOGE("Cannot create player with SL_DATALOCATOR_ANDROIDBUFFERQUEUE data source " - "that is not fed MPEG-2 TS data or AAC ADTS data"); - return SL_RESULT_CONTENT_UNSUPPORTED; - } - } - break; - default: - SL_LOGE("Cannot create player with SL_DATALOCATOR_ANDROIDBUFFERQUEUE data source " - "without SL_DATAFORMAT_MIME format"); - return SL_RESULT_CONTENT_UNSUPPORTED; - } - } - break; // case SL_DATALOCATOR_ANDROIDBUFFERQUEUE - //------------------ - // Address - case SL_DATALOCATOR_ADDRESS: - case SL_DATALOCATOR_IODEVICE: - case SL_DATALOCATOR_OUTPUTMIX: - case XA_DATALOCATOR_NATIVEDISPLAY: - case SL_DATALOCATOR_MIDIBUFFERQUEUE: - SL_LOGE("Cannot create audio player with data locator type 0x%x", - (unsigned) sourceLocatorType); - return SL_RESULT_CONTENT_UNSUPPORTED; - default: - SL_LOGE("Cannot create audio player with invalid data locator type 0x%x", - (unsigned) sourceLocatorType); - return SL_RESULT_PARAMETER_INVALID; - }// switch (locatorType) - - return SL_RESULT_SUCCESS; -} - - -//----------------------------------------------------------------------------- -// Callback associated with an AudioTrack of an SL ES AudioPlayer that gets its data -// from a buffer queue. This will not be called once the AudioTrack has been destroyed. -static void audioTrack_callBack_pullFromBuffQueue(int event, void* user, void *info) { - CAudioPlayer *ap = (CAudioPlayer *)user; - - if (!android::CallbackProtector::enterCbIfOk(ap->mCallbackProtector)) { - // it is not safe to enter the callback (the track is about to go away) - return; - } - - void * callbackPContext = NULL; - switch(event) { - - case android::AudioTrack::EVENT_MORE_DATA: { - //SL_LOGV("received event EVENT_MORE_DATA from AudioTrack TID=%d", gettid()); - slBufferQueueCallback callback = NULL; - slPrefetchCallback prefetchCallback = NULL; - void *prefetchContext = NULL; - SLuint32 prefetchEvents = SL_PREFETCHEVENT_NONE; - android::AudioTrack::Buffer* pBuff = (android::AudioTrack::Buffer*)info; - - // retrieve data from the buffer queue - interface_lock_exclusive(&ap->mBufferQueue); - - if (ap->mBufferQueue.mState.count != 0) { - //SL_LOGV("nbBuffers in queue = %u",ap->mBufferQueue.mState.count); - assert(ap->mBufferQueue.mFront != ap->mBufferQueue.mRear); - - BufferHeader *oldFront = ap->mBufferQueue.mFront; - BufferHeader *newFront = &oldFront[1]; - - // declared as void * because this code supports both 8-bit and 16-bit PCM data - void *pSrc = (char *)oldFront->mBuffer + ap->mBufferQueue.mSizeConsumed; - if (ap->mBufferQueue.mSizeConsumed + pBuff->size < oldFront->mSize) { - // can't consume the whole or rest of the buffer in one shot - ap->mBufferQueue.mSizeConsumed += pBuff->size; - // leave pBuff->size untouched - // consume data - // FIXME can we avoid holding the lock during the copy? - memcpy (pBuff->raw, pSrc, pBuff->size); - } else { - // finish consuming the buffer or consume the buffer in one shot - pBuff->size = oldFront->mSize - ap->mBufferQueue.mSizeConsumed; - ap->mBufferQueue.mSizeConsumed = 0; - - if (newFront == - &ap->mBufferQueue.mArray - [ap->mBufferQueue.mNumBuffers + 1]) - { - newFront = ap->mBufferQueue.mArray; - } - ap->mBufferQueue.mFront = newFront; - - ap->mBufferQueue.mState.count--; - ap->mBufferQueue.mState.playIndex++; - - // consume data - // FIXME can we avoid holding the lock during the copy? - memcpy (pBuff->raw, pSrc, pBuff->size); - - // data has been consumed, and the buffer queue state has been updated - // we will notify the client if applicable - callback = ap->mBufferQueue.mCallback; - // save callback data - callbackPContext = ap->mBufferQueue.mContext; - } - } else { // empty queue - // signal no data available - pBuff->size = 0; - - // signal we're at the end of the content, but don't pause (see note in function) - audioPlayer_dispatch_headAtEnd_lockPlay(ap, false /*set state to paused?*/, false); - - // signal underflow to prefetch status itf - if (IsInterfaceInitialized(&(ap->mObject), MPH_PREFETCHSTATUS)) { - ap->mPrefetchStatus.mStatus = SL_PREFETCHSTATUS_UNDERFLOW; - ap->mPrefetchStatus.mLevel = 0; - // callback or no callback? - prefetchEvents = ap->mPrefetchStatus.mCallbackEventsMask & - (SL_PREFETCHEVENT_STATUSCHANGE | SL_PREFETCHEVENT_FILLLEVELCHANGE); - if (SL_PREFETCHEVENT_NONE != prefetchEvents) { - prefetchCallback = ap->mPrefetchStatus.mCallback; - prefetchContext = ap->mPrefetchStatus.mContext; - } - } - - // stop the track so it restarts playing faster when new data is enqueued - ap->mAudioTrack->stop(); - } - interface_unlock_exclusive(&ap->mBufferQueue); - - // notify client - if (NULL != prefetchCallback) { - assert(SL_PREFETCHEVENT_NONE != prefetchEvents); - // spec requires separate callbacks for each event - if (prefetchEvents & SL_PREFETCHEVENT_STATUSCHANGE) { - (*prefetchCallback)(&ap->mPrefetchStatus.mItf, prefetchContext, - SL_PREFETCHEVENT_STATUSCHANGE); - } - if (prefetchEvents & SL_PREFETCHEVENT_FILLLEVELCHANGE) { - (*prefetchCallback)(&ap->mPrefetchStatus.mItf, prefetchContext, - SL_PREFETCHEVENT_FILLLEVELCHANGE); - } - } - if (NULL != callback) { - (*callback)(&ap->mBufferQueue.mItf, callbackPContext); - } - } - break; - - case android::AudioTrack::EVENT_MARKER: - //SL_LOGI("received event EVENT_MARKER from AudioTrack"); - audioTrack_handleMarker_lockPlay(ap); - break; - - case android::AudioTrack::EVENT_NEW_POS: - //SL_LOGI("received event EVENT_NEW_POS from AudioTrack"); - audioTrack_handleNewPos_lockPlay(ap); - break; - - case android::AudioTrack::EVENT_UNDERRUN: - //SL_LOGI("received event EVENT_UNDERRUN from AudioTrack"); - audioTrack_handleUnderrun_lockPlay(ap); - break; - - case android::AudioTrack::EVENT_BUFFER_END: - case android::AudioTrack::EVENT_LOOP_END: - // These are unexpected so fall through - default: - // FIXME where does the notification of SL_PLAYEVENT_HEADMOVING fit? - SL_LOGE("Encountered unknown AudioTrack event %d for CAudioPlayer %p", event, - (CAudioPlayer *)user); - break; - } - - ap->mCallbackProtector->exitCb(); -} - - -//----------------------------------------------------------------------------- -void android_audioPlayer_create(CAudioPlayer *pAudioPlayer) { - - // pAudioPlayer->mAndroidObjType has been set in android_audioPlayer_checkSourceSink() - // and if it was == INVALID_TYPE, then IEngine_CreateAudioPlayer would never call us - assert(INVALID_TYPE != pAudioPlayer->mAndroidObjType); - - // These initializations are in the same order as the field declarations in classes.h - - // FIXME Consolidate initializations (many of these already in IEngine_CreateAudioPlayer) - // mAndroidObjType: see above comment - pAudioPlayer->mAndroidObjState = ANDROID_UNINITIALIZED; - pAudioPlayer->mSessionId = android::AudioSystem::newAudioSessionId(); - - // placeholder: not necessary yet as session ID lifetime doesn't extend beyond player - // android::AudioSystem::acquireAudioSessionId(pAudioPlayer->mSessionId); - - pAudioPlayer->mStreamType = ANDROID_DEFAULT_OUTPUT_STREAM_TYPE; - - // mAudioTrack - pAudioPlayer->mCallbackProtector = new android::CallbackProtector(); - // mAPLayer - // mAuxEffect - - pAudioPlayer->mAuxSendLevel = 0; - pAudioPlayer->mAmplFromDirectLevel = 1.0f; // matches initial mDirectLevel value - pAudioPlayer->mDeferredStart = false; - - // This section re-initializes interface-specific fields that - // can be set or used regardless of whether the interface is - // exposed on the AudioPlayer or not - - // Only AudioTrack supports a non-trivial playback rate - switch (pAudioPlayer->mAndroidObjType) { - case AUDIOPLAYER_FROM_PCM_BUFFERQUEUE: - pAudioPlayer->mPlaybackRate.mMinRate = AUDIOTRACK_MIN_PLAYBACKRATE_PERMILLE; - pAudioPlayer->mPlaybackRate.mMaxRate = AUDIOTRACK_MAX_PLAYBACKRATE_PERMILLE; - break; - default: - // use the default range - break; - } - -} - - -//----------------------------------------------------------------------------- -SLresult android_audioPlayer_setConfig(CAudioPlayer *ap, const SLchar *configKey, - const void *pConfigValue, SLuint32 valueSize) { - - SLresult result; - - assert(NULL != ap && NULL != configKey && NULL != pConfigValue); - if (strcmp((const char*)configKey, (const char*)SL_ANDROID_KEY_STREAM_TYPE) == 0) { - - // stream type - if (KEY_STREAM_TYPE_PARAMSIZE > valueSize) { - SL_LOGE(ERROR_CONFIG_VALUESIZE_TOO_LOW); - result = SL_RESULT_BUFFER_INSUFFICIENT; - } else { - result = audioPlayer_setStreamType(ap, *(SLuint32*)pConfigValue); - } - - } else { - SL_LOGE(ERROR_CONFIG_UNKNOWN_KEY); - result = SL_RESULT_PARAMETER_INVALID; - } - - return result; -} - - -//----------------------------------------------------------------------------- -SLresult android_audioPlayer_getConfig(CAudioPlayer* ap, const SLchar *configKey, - SLuint32* pValueSize, void *pConfigValue) { - - SLresult result; - - assert(NULL != ap && NULL != configKey && NULL != pValueSize); - if (strcmp((const char*)configKey, (const char*)SL_ANDROID_KEY_STREAM_TYPE) == 0) { - - // stream type - if (NULL == pConfigValue) { - result = SL_RESULT_SUCCESS; - } else if (KEY_STREAM_TYPE_PARAMSIZE > *pValueSize) { - SL_LOGE(ERROR_CONFIG_VALUESIZE_TOO_LOW); - result = SL_RESULT_BUFFER_INSUFFICIENT; - } else { - result = audioPlayer_getStreamType(ap, (SLint32*)pConfigValue); - } - *pValueSize = KEY_STREAM_TYPE_PARAMSIZE; - - } else { - SL_LOGE(ERROR_CONFIG_UNKNOWN_KEY); - result = SL_RESULT_PARAMETER_INVALID; - } - - return result; -} - - -//----------------------------------------------------------------------------- -// FIXME abstract out the diff between CMediaPlayer and CAudioPlayer -SLresult android_audioPlayer_realize(CAudioPlayer *pAudioPlayer, SLboolean async) { - - SLresult result = SL_RESULT_SUCCESS; - SL_LOGV("Realize pAudioPlayer=%p", pAudioPlayer); - - AudioPlayback_Parameters app; - app.sessionId = pAudioPlayer->mSessionId; - app.streamType = pAudioPlayer->mStreamType; - - switch (pAudioPlayer->mAndroidObjType) { - - //----------------------------------- - // AudioTrack - case AUDIOPLAYER_FROM_PCM_BUFFERQUEUE: - { - // initialize platform-specific CAudioPlayer fields - - SLDataLocator_BufferQueue *dl_bq = (SLDataLocator_BufferQueue *) - pAudioPlayer->mDynamicSource.mDataSource; - SLDataFormat_PCM *df_pcm = (SLDataFormat_PCM *) - pAudioPlayer->mDynamicSource.mDataSource->pFormat; - - uint32_t sampleRate = sles_to_android_sampleRate(df_pcm->samplesPerSec); - - pAudioPlayer->mAudioTrack = new android::AudioTrack( - pAudioPlayer->mStreamType, // streamType - sampleRate, // sampleRate - sles_to_android_sampleFormat(df_pcm->bitsPerSample), // format - sles_to_android_channelMaskOut(df_pcm->numChannels, df_pcm->channelMask), - //channel mask - 0, // frameCount (here min) - AUDIO_POLICY_OUTPUT_FLAG_NONE, // flags - audioTrack_callBack_pullFromBuffQueue, // callback - (void *) pAudioPlayer, // user - 0 // FIXME find appropriate frame count // notificationFrame - , pAudioPlayer->mSessionId - ); - android::status_t status = pAudioPlayer->mAudioTrack->initCheck(); - if (status != android::NO_ERROR) { - SL_LOGE("AudioTrack::initCheck status %u", status); - result = SL_RESULT_CONTENT_UNSUPPORTED; - pAudioPlayer->mAudioTrack.clear(); - return result; - } - - // initialize platform-independent CAudioPlayer fields - - pAudioPlayer->mNumChannels = df_pcm->numChannels; - pAudioPlayer->mSampleRateMilliHz = df_pcm->samplesPerSec; // Note: bad field name in SL ES - - // This use case does not have a separate "prepare" step - pAudioPlayer->mAndroidObjState = ANDROID_READY; - } - break; - - //----------------------------------- - // MediaPlayer - case AUDIOPLAYER_FROM_URIFD: { - pAudioPlayer->mAPlayer = new android::LocAVPlayer(&app, false /*hasVideo*/); - pAudioPlayer->mAPlayer->init(sfplayer_handlePrefetchEvent, - (void*)pAudioPlayer /*notifUSer*/); - - switch (pAudioPlayer->mDataSource.mLocator.mLocatorType) { - case SL_DATALOCATOR_URI: { - // The legacy implementation ran Stagefright within the application process, and - // so allowed local pathnames specified by URI that were openable by - // the application but were not openable by mediaserver. - // The current implementation runs Stagefright (mostly) within mediaserver, - // which runs as a different UID and likely a different current working directory. - // For backwards compatibility with any applications which may have relied on the - // previous behavior, we convert an openable file URI into an FD. - // Note that unlike SL_DATALOCATOR_ANDROIDFD, this FD is owned by us - // and so we close it as soon as we've passed it (via Binder dup) to mediaserver. - const char *uri = (const char *)pAudioPlayer->mDataSource.mLocator.mURI.URI; - if (!isDistantProtocol(uri)) { - // don't touch the original uri, we may need it later - const char *pathname = uri; - // skip over an optional leading file:// prefix - if (!strncasecmp(pathname, "file://", 7)) { - pathname += 7; - } - // attempt to open it as a file using the application's credentials - int fd = ::open(pathname, O_RDONLY); - if (fd >= 0) { - // if open is successful, then check to see if it's a regular file - struct stat statbuf; - if (!::fstat(fd, &statbuf) && S_ISREG(statbuf.st_mode)) { - // treat similarly to an FD data locator, but - // let setDataSource take responsibility for closing fd - pAudioPlayer->mAPlayer->setDataSource(fd, 0, statbuf.st_size, true); - break; - } - // we were able to open it, but it's not a file, so let mediaserver try - (void) ::close(fd); - } - } - // if either the URI didn't look like a file, or open failed, or not a file - pAudioPlayer->mAPlayer->setDataSource(uri); - } break; - case SL_DATALOCATOR_ANDROIDFD: { - int64_t offset = (int64_t)pAudioPlayer->mDataSource.mLocator.mFD.offset; - pAudioPlayer->mAPlayer->setDataSource( - (int)pAudioPlayer->mDataSource.mLocator.mFD.fd, - offset == SL_DATALOCATOR_ANDROIDFD_USE_FILE_SIZE ? - (int64_t)PLAYER_FD_FIND_FILE_SIZE : offset, - (int64_t)pAudioPlayer->mDataSource.mLocator.mFD.length); - } - break; - default: - SL_LOGE(ERROR_PLAYERREALIZE_UNKNOWN_DATASOURCE_LOCATOR); - break; - } - - } - break; - - //----------------------------------- - // StreamPlayer - case AUDIOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE: { - android::StreamPlayer* splr = new android::StreamPlayer(&app, false /*hasVideo*/, - &pAudioPlayer->mAndroidBufferQueue, pAudioPlayer->mCallbackProtector); - pAudioPlayer->mAPlayer = splr; - splr->init(sfplayer_handlePrefetchEvent, (void*)pAudioPlayer); - } - break; - - //----------------------------------- - // AudioToCbRenderer - case AUDIOPLAYER_FROM_URIFD_TO_PCM_BUFFERQUEUE: { - android::AudioToCbRenderer* decoder = new android::AudioToCbRenderer(&app); - pAudioPlayer->mAPlayer = decoder; - // configures the callback for the sink buffer queue - decoder->setDataPushListener(adecoder_writeToBufferQueue, pAudioPlayer); - // configures the callback for the notifications coming from the SF code - decoder->init(sfplayer_handlePrefetchEvent, (void*)pAudioPlayer); - - switch (pAudioPlayer->mDataSource.mLocator.mLocatorType) { - case SL_DATALOCATOR_URI: - decoder->setDataSource( - (const char*)pAudioPlayer->mDataSource.mLocator.mURI.URI); - break; - case SL_DATALOCATOR_ANDROIDFD: { - int64_t offset = (int64_t)pAudioPlayer->mDataSource.mLocator.mFD.offset; - decoder->setDataSource( - (int)pAudioPlayer->mDataSource.mLocator.mFD.fd, - offset == SL_DATALOCATOR_ANDROIDFD_USE_FILE_SIZE ? - (int64_t)PLAYER_FD_FIND_FILE_SIZE : offset, - (int64_t)pAudioPlayer->mDataSource.mLocator.mFD.length); - } - break; - default: - SL_LOGE(ERROR_PLAYERREALIZE_UNKNOWN_DATASOURCE_LOCATOR); - break; - } - - } - break; - - //----------------------------------- - // AacBqToPcmCbRenderer - case AUDIOPLAYER_FROM_ADTS_ABQ_TO_PCM_BUFFERQUEUE: { - android::AacBqToPcmCbRenderer* bqtobq = new android::AacBqToPcmCbRenderer(&app, - &pAudioPlayer->mAndroidBufferQueue); - // configures the callback for the sink buffer queue - bqtobq->setDataPushListener(adecoder_writeToBufferQueue, pAudioPlayer); - pAudioPlayer->mAPlayer = bqtobq; - // configures the callback for the notifications coming from the SF code, - // but also implicitly configures the AndroidBufferQueue from which ADTS data is read - pAudioPlayer->mAPlayer->init(sfplayer_handlePrefetchEvent, (void*)pAudioPlayer); - } - break; - - //----------------------------------- - default: - SL_LOGE(ERROR_PLAYERREALIZE_UNEXPECTED_OBJECT_TYPE_D, pAudioPlayer->mAndroidObjType); - result = SL_RESULT_INTERNAL_ERROR; - break; - } - - // proceed with effect initialization - // initialize EQ - // FIXME use a table of effect descriptors when adding support for more effects - if (memcmp(SL_IID_EQUALIZER, &pAudioPlayer->mEqualizer.mEqDescriptor.type, - sizeof(effect_uuid_t)) == 0) { - SL_LOGV("Need to initialize EQ for AudioPlayer=%p", pAudioPlayer); - android_eq_init(pAudioPlayer->mSessionId, &pAudioPlayer->mEqualizer); - } - // initialize BassBoost - if (memcmp(SL_IID_BASSBOOST, &pAudioPlayer->mBassBoost.mBassBoostDescriptor.type, - sizeof(effect_uuid_t)) == 0) { - SL_LOGV("Need to initialize BassBoost for AudioPlayer=%p", pAudioPlayer); - android_bb_init(pAudioPlayer->mSessionId, &pAudioPlayer->mBassBoost); - } - // initialize Virtualizer - if (memcmp(SL_IID_VIRTUALIZER, &pAudioPlayer->mVirtualizer.mVirtualizerDescriptor.type, - sizeof(effect_uuid_t)) == 0) { - SL_LOGV("Need to initialize Virtualizer for AudioPlayer=%p", pAudioPlayer); - android_virt_init(pAudioPlayer->mSessionId, &pAudioPlayer->mVirtualizer); - } - - // initialize EffectSend - // FIXME initialize EffectSend - - return result; -} - - -//----------------------------------------------------------------------------- -/** - * Called with a lock on AudioPlayer, and blocks until safe to destroy - */ -SLresult android_audioPlayer_preDestroy(CAudioPlayer *pAudioPlayer) { - SL_LOGD("android_audioPlayer_preDestroy(%p)", pAudioPlayer); - SLresult result = SL_RESULT_SUCCESS; - - bool disableCallbacksBeforePreDestroy; - switch (pAudioPlayer->mAndroidObjType) { - // Not yet clear why this order is important, but it reduces detected deadlocks - case AUDIOPLAYER_FROM_URIFD_TO_PCM_BUFFERQUEUE: - disableCallbacksBeforePreDestroy = true; - break; - // Use the old behavior for all other use cases until proven - // case AUDIOPLAYER_FROM_ADTS_ABQ_TO_PCM_BUFFERQUEUE: - default: - disableCallbacksBeforePreDestroy = false; - break; - } - - if (disableCallbacksBeforePreDestroy) { - object_unlock_exclusive(&pAudioPlayer->mObject); - if (pAudioPlayer->mCallbackProtector != 0) { - pAudioPlayer->mCallbackProtector->requestCbExitAndWait(); - } - object_lock_exclusive(&pAudioPlayer->mObject); - } - - if (pAudioPlayer->mAPlayer != 0) { - pAudioPlayer->mAPlayer->preDestroy(); - } - SL_LOGD("android_audioPlayer_preDestroy(%p) after mAPlayer->preDestroy()", pAudioPlayer); - - if (!disableCallbacksBeforePreDestroy) { - object_unlock_exclusive(&pAudioPlayer->mObject); - if (pAudioPlayer->mCallbackProtector != 0) { - pAudioPlayer->mCallbackProtector->requestCbExitAndWait(); - } - object_lock_exclusive(&pAudioPlayer->mObject); - } - - return result; -} - - -//----------------------------------------------------------------------------- -SLresult android_audioPlayer_destroy(CAudioPlayer *pAudioPlayer) { - SLresult result = SL_RESULT_SUCCESS; - SL_LOGV("android_audioPlayer_destroy(%p)", pAudioPlayer); - switch (pAudioPlayer->mAndroidObjType) { - - case AUDIOPLAYER_FROM_PCM_BUFFERQUEUE: - // We own the audio track for PCM buffer queue players - if (pAudioPlayer->mAudioTrack != 0) { - pAudioPlayer->mAudioTrack->stop(); - // Note that there may still be another reference in post-unlock phase of SetPlayState - pAudioPlayer->mAudioTrack.clear(); - } - break; - - case AUDIOPLAYER_FROM_URIFD: // intended fall-through - case AUDIOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE: // intended fall-through - case AUDIOPLAYER_FROM_URIFD_TO_PCM_BUFFERQUEUE: // intended fall-through - case AUDIOPLAYER_FROM_ADTS_ABQ_TO_PCM_BUFFERQUEUE: - pAudioPlayer->mAPlayer.clear(); - break; - //----------------------------------- - default: - SL_LOGE(ERROR_PLAYERDESTROY_UNEXPECTED_OBJECT_TYPE_D, pAudioPlayer->mAndroidObjType); - result = SL_RESULT_INTERNAL_ERROR; - break; - } - - // placeholder: not necessary yet as session ID lifetime doesn't extend beyond player - // android::AudioSystem::releaseAudioSessionId(pAudioPlayer->mSessionId); - - pAudioPlayer->mCallbackProtector.clear(); - - // explicit destructor - pAudioPlayer->mAudioTrack.~sp(); - // note that SetPlayState(PLAYING) may still hold a reference - pAudioPlayer->mCallbackProtector.~sp(); - pAudioPlayer->mAuxEffect.~sp(); - pAudioPlayer->mAPlayer.~sp(); - - return result; -} - - -//----------------------------------------------------------------------------- -SLresult android_audioPlayer_setPlaybackRateAndConstraints(CAudioPlayer *ap, SLpermille rate, - SLuint32 constraints) { - SLresult result = SL_RESULT_SUCCESS; - switch(ap->mAndroidObjType) { - case AUDIOPLAYER_FROM_PCM_BUFFERQUEUE: { - // these asserts were already checked by the platform-independent layer - assert((AUDIOTRACK_MIN_PLAYBACKRATE_PERMILLE <= rate) && - (rate <= AUDIOTRACK_MAX_PLAYBACKRATE_PERMILLE)); - assert(constraints & SL_RATEPROP_NOPITCHCORAUDIO); - // get the content sample rate - uint32_t contentRate = sles_to_android_sampleRate(ap->mSampleRateMilliHz); - // apply the SL ES playback rate on the AudioTrack as a factor of its content sample rate - if (ap->mAudioTrack != 0) { - ap->mAudioTrack->setSampleRate(contentRate * (rate/1000.0f)); - } - } - break; - case AUDIOPLAYER_FROM_URIFD: - assert(rate == 1000); - assert(constraints & SL_RATEPROP_NOPITCHCORAUDIO); - // that was easy - break; - - default: - SL_LOGE("Unexpected object type %d", ap->mAndroidObjType); - result = SL_RESULT_FEATURE_UNSUPPORTED; - break; - } - return result; -} - - -//----------------------------------------------------------------------------- -// precondition -// called with no lock held -// ap != NULL -// pItemCount != NULL -SLresult android_audioPlayer_metadata_getItemCount(CAudioPlayer *ap, SLuint32 *pItemCount) { - if (ap->mAPlayer == 0) { - return SL_RESULT_PARAMETER_INVALID; - } - switch(ap->mAndroidObjType) { - case AUDIOPLAYER_FROM_URIFD_TO_PCM_BUFFERQUEUE: - case AUDIOPLAYER_FROM_ADTS_ABQ_TO_PCM_BUFFERQUEUE: - { - android::AudioSfDecoder* decoder = - static_cast<android::AudioSfDecoder*>(ap->mAPlayer.get()); - *pItemCount = decoder->getPcmFormatKeyCount(); - } - break; - default: - *pItemCount = 0; - break; - } - return SL_RESULT_SUCCESS; -} - - -//----------------------------------------------------------------------------- -// precondition -// called with no lock held -// ap != NULL -// pKeySize != NULL -SLresult android_audioPlayer_metadata_getKeySize(CAudioPlayer *ap, - SLuint32 index, SLuint32 *pKeySize) { - if (ap->mAPlayer == 0) { - return SL_RESULT_PARAMETER_INVALID; - } - SLresult res = SL_RESULT_SUCCESS; - switch(ap->mAndroidObjType) { - case AUDIOPLAYER_FROM_URIFD_TO_PCM_BUFFERQUEUE: - case AUDIOPLAYER_FROM_ADTS_ABQ_TO_PCM_BUFFERQUEUE: - { - android::AudioSfDecoder* decoder = - static_cast<android::AudioSfDecoder*>(ap->mAPlayer.get()); - SLuint32 keyNameSize = 0; - if (!decoder->getPcmFormatKeySize(index, &keyNameSize)) { - res = SL_RESULT_PARAMETER_INVALID; - } else { - // *pKeySize is the size of the region used to store the key name AND - // the information about the key (size, lang, encoding) - *pKeySize = keyNameSize + sizeof(SLMetadataInfo); - } - } - break; - default: - *pKeySize = 0; - res = SL_RESULT_PARAMETER_INVALID; - break; - } - return res; -} - - -//----------------------------------------------------------------------------- -// precondition -// called with no lock held -// ap != NULL -// pKey != NULL -SLresult android_audioPlayer_metadata_getKey(CAudioPlayer *ap, - SLuint32 index, SLuint32 size, SLMetadataInfo *pKey) { - if (ap->mAPlayer == 0) { - return SL_RESULT_PARAMETER_INVALID; - } - SLresult res = SL_RESULT_SUCCESS; - switch(ap->mAndroidObjType) { - case AUDIOPLAYER_FROM_URIFD_TO_PCM_BUFFERQUEUE: - case AUDIOPLAYER_FROM_ADTS_ABQ_TO_PCM_BUFFERQUEUE: - { - android::AudioSfDecoder* decoder = - static_cast<android::AudioSfDecoder*>(ap->mAPlayer.get()); - if ((size < sizeof(SLMetadataInfo) || - (!decoder->getPcmFormatKeyName(index, size - sizeof(SLMetadataInfo), - (char*)pKey->data)))) { - res = SL_RESULT_PARAMETER_INVALID; - } else { - // successfully retrieved the key value, update the other fields - pKey->encoding = SL_CHARACTERENCODING_UTF8; - memcpy((char *) pKey->langCountry, "en", 3); - pKey->size = strlen((char*)pKey->data) + 1; - } - } - break; - default: - res = SL_RESULT_PARAMETER_INVALID; - break; - } - return res; -} - - -//----------------------------------------------------------------------------- -// precondition -// called with no lock held -// ap != NULL -// pValueSize != NULL -SLresult android_audioPlayer_metadata_getValueSize(CAudioPlayer *ap, - SLuint32 index, SLuint32 *pValueSize) { - if (ap->mAPlayer == 0) { - return SL_RESULT_PARAMETER_INVALID; - } - SLresult res = SL_RESULT_SUCCESS; - switch(ap->mAndroidObjType) { - case AUDIOPLAYER_FROM_URIFD_TO_PCM_BUFFERQUEUE: - case AUDIOPLAYER_FROM_ADTS_ABQ_TO_PCM_BUFFERQUEUE: - { - android::AudioSfDecoder* decoder = - static_cast<android::AudioSfDecoder*>(ap->mAPlayer.get()); - SLuint32 valueSize = 0; - if (!decoder->getPcmFormatValueSize(index, &valueSize)) { - res = SL_RESULT_PARAMETER_INVALID; - } else { - // *pValueSize is the size of the region used to store the key value AND - // the information about the value (size, lang, encoding) - *pValueSize = valueSize + sizeof(SLMetadataInfo); - } - } - break; - default: - *pValueSize = 0; - res = SL_RESULT_PARAMETER_INVALID; - break; - } - return res; -} - - -//----------------------------------------------------------------------------- -// precondition -// called with no lock held -// ap != NULL -// pValue != NULL -SLresult android_audioPlayer_metadata_getValue(CAudioPlayer *ap, - SLuint32 index, SLuint32 size, SLMetadataInfo *pValue) { - if (ap->mAPlayer == 0) { - return SL_RESULT_PARAMETER_INVALID; - } - SLresult res = SL_RESULT_SUCCESS; - switch(ap->mAndroidObjType) { - case AUDIOPLAYER_FROM_URIFD_TO_PCM_BUFFERQUEUE: - case AUDIOPLAYER_FROM_ADTS_ABQ_TO_PCM_BUFFERQUEUE: - { - android::AudioSfDecoder* decoder = - static_cast<android::AudioSfDecoder*>(ap->mAPlayer.get()); - pValue->encoding = SL_CHARACTERENCODING_BINARY; - memcpy((char *) pValue->langCountry, "en", 3); // applicable here? - SLuint32 valueSize = 0; - if ((size < sizeof(SLMetadataInfo) - || (!decoder->getPcmFormatValueSize(index, &valueSize)) - || (!decoder->getPcmFormatKeyValue(index, size - sizeof(SLMetadataInfo), - (SLuint32*)pValue->data)))) { - res = SL_RESULT_PARAMETER_INVALID; - } else { - pValue->size = valueSize; - } - } - break; - default: - res = SL_RESULT_PARAMETER_INVALID; - break; - } - return res; -} - -//----------------------------------------------------------------------------- -// preconditions -// ap != NULL -// mutex is locked -// play state has changed -void android_audioPlayer_setPlayState(CAudioPlayer *ap) { - - SLuint32 playState = ap->mPlay.mState; - AndroidObjectState objState = ap->mAndroidObjState; - - switch(ap->mAndroidObjType) { - case AUDIOPLAYER_FROM_PCM_BUFFERQUEUE: - switch (playState) { - case SL_PLAYSTATE_STOPPED: - SL_LOGV("setting AudioPlayer to SL_PLAYSTATE_STOPPED"); - if (ap->mAudioTrack != 0) { - ap->mAudioTrack->stop(); - } - break; - case SL_PLAYSTATE_PAUSED: - SL_LOGV("setting AudioPlayer to SL_PLAYSTATE_PAUSED"); - if (ap->mAudioTrack != 0) { - ap->mAudioTrack->pause(); - } - break; - case SL_PLAYSTATE_PLAYING: - SL_LOGV("setting AudioPlayer to SL_PLAYSTATE_PLAYING"); - if (ap->mAudioTrack != 0) { - // instead of ap->mAudioTrack->start(); - ap->mDeferredStart = true; - } - break; - default: - // checked by caller, should not happen - break; - } - break; - - case AUDIOPLAYER_FROM_URIFD: // intended fall-through - case AUDIOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE: // intended fall-through - case AUDIOPLAYER_FROM_URIFD_TO_PCM_BUFFERQUEUE: // intended fall-through - case AUDIOPLAYER_FROM_ADTS_ABQ_TO_PCM_BUFFERQUEUE: - // FIXME report and use the return code to the lock mechanism, which is where play state - // changes are updated (see object_unlock_exclusive_attributes()) - aplayer_setPlayState(ap->mAPlayer, playState, &(ap->mAndroidObjState)); - break; - default: - SL_LOGE(ERROR_PLAYERSETPLAYSTATE_UNEXPECTED_OBJECT_TYPE_D, ap->mAndroidObjType); - break; - } -} - - -//----------------------------------------------------------------------------- -// call when either player event flags, marker position, or position update period changes -void android_audioPlayer_usePlayEventMask(CAudioPlayer *ap) { - IPlay *pPlayItf = &ap->mPlay; - SLuint32 eventFlags = pPlayItf->mEventFlags; - /*switch(ap->mAndroidObjType) { - case AUDIOPLAYER_FROM_PCM_BUFFERQUEUE:*/ - - if (ap->mAPlayer != 0) { - assert(ap->mAudioTrack == 0); - ap->mAPlayer->setPlayEvents((int32_t) eventFlags, (int32_t) pPlayItf->mMarkerPosition, - (int32_t) pPlayItf->mPositionUpdatePeriod); - return; - } - - if (ap->mAudioTrack == 0) { - return; - } - - if (eventFlags & SL_PLAYEVENT_HEADATMARKER) { - ap->mAudioTrack->setMarkerPosition((uint32_t)((((int64_t)pPlayItf->mMarkerPosition - * sles_to_android_sampleRate(ap->mSampleRateMilliHz)))/1000)); - } else { - // clear marker - ap->mAudioTrack->setMarkerPosition(0); - } - - if (eventFlags & SL_PLAYEVENT_HEADATNEWPOS) { - ap->mAudioTrack->setPositionUpdatePeriod( - (uint32_t)((((int64_t)pPlayItf->mPositionUpdatePeriod - * sles_to_android_sampleRate(ap->mSampleRateMilliHz)))/1000)); - } else { - // clear periodic update - ap->mAudioTrack->setPositionUpdatePeriod(0); - } - - if (eventFlags & SL_PLAYEVENT_HEADATEND) { - // nothing to do for SL_PLAYEVENT_HEADATEND, callback event will be checked against mask - } - - if (eventFlags & SL_PLAYEVENT_HEADMOVING) { - // FIXME support SL_PLAYEVENT_HEADMOVING - SL_LOGD("[ FIXME: IPlay_SetCallbackEventsMask(SL_PLAYEVENT_HEADMOVING) on an " - "SL_OBJECTID_AUDIOPLAYER to be implemented ]"); - } - if (eventFlags & SL_PLAYEVENT_HEADSTALLED) { - // nothing to do for SL_PLAYEVENT_HEADSTALLED, callback event will be checked against mask - } - -} - - -//----------------------------------------------------------------------------- -SLresult android_audioPlayer_getDuration(IPlay *pPlayItf, SLmillisecond *pDurMsec) { - CAudioPlayer *ap = (CAudioPlayer *)pPlayItf->mThis; - switch(ap->mAndroidObjType) { - - case AUDIOPLAYER_FROM_URIFD: // intended fall-through - case AUDIOPLAYER_FROM_URIFD_TO_PCM_BUFFERQUEUE: { - int32_t durationMsec = ANDROID_UNKNOWN_TIME; - if (ap->mAPlayer != 0) { - ap->mAPlayer->getDurationMsec(&durationMsec); - } - *pDurMsec = durationMsec == ANDROID_UNKNOWN_TIME ? SL_TIME_UNKNOWN : durationMsec; - break; - } - - case AUDIOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE: // intended fall-through - case AUDIOPLAYER_FROM_PCM_BUFFERQUEUE: - case AUDIOPLAYER_FROM_ADTS_ABQ_TO_PCM_BUFFERQUEUE: - default: { - *pDurMsec = SL_TIME_UNKNOWN; - } - } - return SL_RESULT_SUCCESS; -} - - -//----------------------------------------------------------------------------- -void android_audioPlayer_getPosition(IPlay *pPlayItf, SLmillisecond *pPosMsec) { - CAudioPlayer *ap = (CAudioPlayer *)pPlayItf->mThis; - switch(ap->mAndroidObjType) { - - case AUDIOPLAYER_FROM_PCM_BUFFERQUEUE: - if ((ap->mSampleRateMilliHz == UNKNOWN_SAMPLERATE) || (ap->mAudioTrack == 0)) { - *pPosMsec = 0; - } else { - uint32_t positionInFrames; - ap->mAudioTrack->getPosition(&positionInFrames); - *pPosMsec = ((int64_t)positionInFrames * 1000) / - sles_to_android_sampleRate(ap->mSampleRateMilliHz); - } - break; - - case AUDIOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE: // intended fall-through - case AUDIOPLAYER_FROM_URIFD: - case AUDIOPLAYER_FROM_URIFD_TO_PCM_BUFFERQUEUE: - case AUDIOPLAYER_FROM_ADTS_ABQ_TO_PCM_BUFFERQUEUE: { - int32_t posMsec = ANDROID_UNKNOWN_TIME; - if (ap->mAPlayer != 0) { - ap->mAPlayer->getPositionMsec(&posMsec); - } - *pPosMsec = posMsec == ANDROID_UNKNOWN_TIME ? 0 : posMsec; - break; - } - - default: - *pPosMsec = 0; - } -} - - -//----------------------------------------------------------------------------- -SLresult android_audioPlayer_seek(CAudioPlayer *ap, SLmillisecond posMsec) { - SLresult result = SL_RESULT_SUCCESS; - - switch(ap->mAndroidObjType) { - - case AUDIOPLAYER_FROM_PCM_BUFFERQUEUE: // intended fall-through - case AUDIOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE: - case AUDIOPLAYER_FROM_ADTS_ABQ_TO_PCM_BUFFERQUEUE: - result = SL_RESULT_FEATURE_UNSUPPORTED; - break; - - case AUDIOPLAYER_FROM_URIFD: // intended fall-through - case AUDIOPLAYER_FROM_URIFD_TO_PCM_BUFFERQUEUE: - if (ap->mAPlayer != 0) { - ap->mAPlayer->seek(posMsec); - } - break; - - default: - break; - } - return result; -} - - -//----------------------------------------------------------------------------- -SLresult android_audioPlayer_loop(CAudioPlayer *ap, SLboolean loopEnable) { - SLresult result = SL_RESULT_SUCCESS; - - switch (ap->mAndroidObjType) { - case AUDIOPLAYER_FROM_URIFD: - // case AUDIOPLAY_FROM_URIFD_TO_PCM_BUFFERQUEUE: - // would actually work, but what's the point? - if (ap->mAPlayer != 0) { - ap->mAPlayer->loop((bool)loopEnable); - } - break; - default: - result = SL_RESULT_FEATURE_UNSUPPORTED; - break; - } - return result; -} - - -//----------------------------------------------------------------------------- -SLresult android_audioPlayer_setBufferingUpdateThresholdPerMille(CAudioPlayer *ap, - SLpermille threshold) { - SLresult result = SL_RESULT_SUCCESS; - - switch (ap->mAndroidObjType) { - case AUDIOPLAYER_FROM_URIFD: - if (ap->mAPlayer != 0) { - ap->mAPlayer->setBufferingUpdateThreshold(threshold / 10); - } - break; - - default: {} - } - - return result; -} - - -//----------------------------------------------------------------------------- -void android_audioPlayer_bufferQueue_onRefilled_l(CAudioPlayer *ap) { - // the AudioTrack associated with the AudioPlayer receiving audio from a PCM buffer - // queue was stopped when the queue become empty, we restart as soon as a new buffer - // has been enqueued since we're in playing state - if (ap->mAudioTrack != 0) { - // instead of ap->mAudioTrack->start(); - ap->mDeferredStart = true; - } - - // when the queue became empty, an underflow on the prefetch status itf was sent. Now the queue - // has received new data, signal it has sufficient data - if (IsInterfaceInitialized(&(ap->mObject), MPH_PREFETCHSTATUS)) { - // we wouldn't have been called unless we were previously in the underflow state - assert(SL_PREFETCHSTATUS_UNDERFLOW == ap->mPrefetchStatus.mStatus); - assert(0 == ap->mPrefetchStatus.mLevel); - ap->mPrefetchStatus.mStatus = SL_PREFETCHSTATUS_SUFFICIENTDATA; - ap->mPrefetchStatus.mLevel = 1000; - // callback or no callback? - SLuint32 prefetchEvents = ap->mPrefetchStatus.mCallbackEventsMask & - (SL_PREFETCHEVENT_STATUSCHANGE | SL_PREFETCHEVENT_FILLLEVELCHANGE); - if (SL_PREFETCHEVENT_NONE != prefetchEvents) { - ap->mPrefetchStatus.mDeferredPrefetchCallback = ap->mPrefetchStatus.mCallback; - ap->mPrefetchStatus.mDeferredPrefetchContext = ap->mPrefetchStatus.mContext; - ap->mPrefetchStatus.mDeferredPrefetchEvents = prefetchEvents; - } - } -} - - -//----------------------------------------------------------------------------- -/* - * BufferQueue::Clear - */ -SLresult android_audioPlayer_bufferQueue_onClear(CAudioPlayer *ap) { - SLresult result = SL_RESULT_SUCCESS; - - switch (ap->mAndroidObjType) { - //----------------------------------- - // AudioTrack - case AUDIOPLAYER_FROM_PCM_BUFFERQUEUE: - if (ap->mAudioTrack != 0) { - ap->mAudioTrack->flush(); - } - break; - default: - result = SL_RESULT_INTERNAL_ERROR; - break; - } - - return result; -} - - -//----------------------------------------------------------------------------- -void android_audioPlayer_androidBufferQueue_clear_l(CAudioPlayer *ap) { - switch (ap->mAndroidObjType) { - case AUDIOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE: - if (ap->mAPlayer != 0) { - android::StreamPlayer* splr = static_cast<android::StreamPlayer*>(ap->mAPlayer.get()); - splr->appClear_l(); - } break; - case AUDIOPLAYER_FROM_ADTS_ABQ_TO_PCM_BUFFERQUEUE: - // nothing to do here, fall through - default: - break; - } -} - -void android_audioPlayer_androidBufferQueue_onRefilled_l(CAudioPlayer *ap) { - switch (ap->mAndroidObjType) { - case AUDIOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE: - if (ap->mAPlayer != 0) { - android::StreamPlayer* splr = static_cast<android::StreamPlayer*>(ap->mAPlayer.get()); - splr->queueRefilled(); - } break; - case AUDIOPLAYER_FROM_ADTS_ABQ_TO_PCM_BUFFERQUEUE: - // FIXME this may require waking up the decoder if it is currently starved and isn't polling - default: - break; - } -} diff --git a/wilhelm/src/android/AudioPlayer_to_android.h b/wilhelm/src/android/AudioPlayer_to_android.h deleted file mode 100644 index 12113b58..00000000 --- a/wilhelm/src/android/AudioPlayer_to_android.h +++ /dev/null @@ -1,138 +0,0 @@ -/* - * 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. - */ - -#define ANDROID_DEFAULT_AUDIOTRACK_BUFFER_SIZE 4096 - -/************************************************************************************************** - * AudioPlayer lifecycle - ****************************/ -/* - * Checks that the combination of source and sink parameters is supported in this implementation. - * Return - * SL_RESULT_SUCCESS - * SL_PARAMETER_INVALID - */ -extern SLresult android_audioPlayer_checkSourceSink(CAudioPlayer *pAudioPlayer); - -/* - * Finish the Android-specific pre-Realize initialization of a CAudioPlayer. - */ -extern void android_audioPlayer_create(CAudioPlayer *pAudioPlayer); - -/* - * Allocates and initializes the Android media framework objects intended to be used with the - * given CAudioPlayer data - * Return - * SL_RESULT_SUCCESS - * SL_RESULT_CONTENT_UNSUPPORTED if an error occurred during the allocation and initialization - * of the Android resources - */ -extern SLresult android_audioPlayer_realize(CAudioPlayer *pAudioPlayer, SLboolean async); - -/* - * Return - * SL_RESULT_SUCCESS - * SL_RESULT_PARAMETER_INVALID - * SL_RESULT_INTERNAL_ERROR - * SL_RESULT_PRECONDITIONS_VIOLATED - */ -extern SLresult android_audioPlayer_setConfig(CAudioPlayer *pAudioPlayer, const SLchar *configKey, - const void *pConfigValue, SLuint32 valueSize); - -/* - * if pConfigValue is NULL, pValueSize contains the size required for the given key - * - * Return - * SL_RESULT_SUCCESS - * SL_RESULT_PARAMETER_INVALID - * SL_RESULT_INTERNAL_ERROR - * SL_RESULT_PRECONDITIONS_VIOLATED - */ -extern SLresult android_audioPlayer_getConfig(CAudioPlayer *pAudioPlayer, const SLchar *configKey, - SLuint32* pValueSize, void *pConfigValue); - -extern SLresult android_audioPlayer_preDestroy(CAudioPlayer *pAudioPlayer); - -extern SLresult android_audioPlayer_destroy(CAudioPlayer *pAudioPlayer); - -/************************************************************************************************** - * Configuration - ****************************/ -extern SLresult android_audioPlayer_setPlaybackRateAndConstraints(CAudioPlayer *pAudioPlayer, - SLpermille rate, SLuint32 constraints); - -extern SLresult android_audioPlayer_getDuration(IPlay *pPlayItf, SLmillisecond *pDurMsec); - -extern void android_audioPlayer_volumeUpdate(CAudioPlayer *pAudioPlayer); - -extern SLresult android_audioPlayer_setBufferingUpdateThresholdPerMille(CAudioPlayer *pAudioPlayer, - SLpermille threshold); - -/************************************************************************************************** - * Metadata Extraction - ****************************/ -/* - * For all metadata extraction functions: - * Precondition: - * no lock held - * pAudioPlayer != NULL - * input pointers != NULL (pItemCount, pKeySize, pKey, pValueSize, pValue) - * Return: - * SL_RESULT_SUCCESS - * SL_RESULT_PARAMETER_INVALID - */ -extern SLresult android_audioPlayer_metadata_getItemCount(CAudioPlayer *pAudioPlayer, - SLuint32 *pItemCount); - -extern SLresult android_audioPlayer_metadata_getKeySize(CAudioPlayer *pAudioPlayer, - SLuint32 index, SLuint32 *pKeySize); - -extern SLresult android_audioPlayer_metadata_getKey(CAudioPlayer *pAudioPlayer, - SLuint32 index, SLuint32 size, SLMetadataInfo *pKey); - -extern SLresult android_audioPlayer_metadata_getValueSize(CAudioPlayer *pAudioPlayer, - SLuint32 index, SLuint32 *pValueSize); - -extern SLresult android_audioPlayer_metadata_getValue(CAudioPlayer *pAudioPlayer, - SLuint32 index, SLuint32 size, SLMetadataInfo *pValue); - -/************************************************************************************************** - * Playback control and events - ****************************/ -extern void android_audioPlayer_setPlayState(CAudioPlayer *pAudioPlayer); - -extern void android_audioPlayer_usePlayEventMask(CAudioPlayer *pAudioPlayer); - -extern SLresult android_audioPlayer_seek(CAudioPlayer *pAudioPlayer, SLmillisecond posMsec); - -extern SLresult android_audioPlayer_loop(CAudioPlayer *pAudioPlayer, SLboolean loopEnable); - -extern void android_audioPlayer_getPosition(IPlay *pPlayItf, SLmillisecond *pPosMsec); - -/************************************************************************************************** - * Buffer Queue events - ****************************/ -extern void android_audioPlayer_bufferQueue_onRefilled_l(CAudioPlayer *pAudioPlayer); - -extern SLresult android_audioPlayer_bufferQueue_onClear(CAudioPlayer *pAudioPlayer); - -/************************************************************************************************** - * Android Buffer Queue - ****************************/ -/* must be called with a lock on pAudioPlayer->mThis */ -extern void android_audioPlayer_androidBufferQueue_clear_l(CAudioPlayer *pAudioPlayer); -/* must be called with a lock on pAudioPlayer->mThis */ -extern void android_audioPlayer_androidBufferQueue_onRefilled_l(CAudioPlayer *pAudioPlayer); diff --git a/wilhelm/src/android/AudioRecorder_to_android.cpp b/wilhelm/src/android/AudioRecorder_to_android.cpp deleted file mode 100644 index 326b8c9a..00000000 --- a/wilhelm/src/android/AudioRecorder_to_android.cpp +++ /dev/null @@ -1,540 +0,0 @@ -/* - * 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. - */ - - -#include "sles_allinclusive.h" -#include "android_prompts.h" - -#include <system/audio.h> - -// use this flag to dump all recorded audio into a file -//#define MONITOR_RECORDING -#ifdef MONITOR_RECORDING -#define MONITOR_TARGET "/sdcard/monitor.raw" -#include <stdio.h> -static FILE* gMonitorFp = NULL; -#endif - - -#define KEY_RECORDING_SOURCE_PARAMSIZE sizeof(SLuint32) -#define KEY_RECORDING_PRESET_PARAMSIZE sizeof(SLuint32) - -//----------------------------------------------------------------------------- -// Internal utility functions -//---------------------------- - -SLresult audioRecorder_setPreset(CAudioRecorder* ar, SLuint32 recordPreset) { - SLresult result = SL_RESULT_SUCCESS; - - audio_source_t newRecordSource = AUDIO_SOURCE_DEFAULT; - switch (recordPreset) { - case SL_ANDROID_RECORDING_PRESET_GENERIC: - newRecordSource = AUDIO_SOURCE_DEFAULT; - break; - case SL_ANDROID_RECORDING_PRESET_CAMCORDER: - newRecordSource = AUDIO_SOURCE_CAMCORDER; - break; - case SL_ANDROID_RECORDING_PRESET_VOICE_RECOGNITION: - newRecordSource = AUDIO_SOURCE_VOICE_RECOGNITION; - break; - case SL_ANDROID_RECORDING_PRESET_VOICE_COMMUNICATION: - newRecordSource = AUDIO_SOURCE_VOICE_COMMUNICATION; - break; - case SL_ANDROID_RECORDING_PRESET_NONE: - // it is an error to set preset "none" - default: - SL_LOGE(ERROR_RECORDERPRESET_SET_UNKNOWN_PRESET); - result = SL_RESULT_PARAMETER_INVALID; - } - - // recording preset needs to be set before the object is realized - // (ap->mAudioRecord is supposed to be NULL until then) - if (SL_OBJECT_STATE_UNREALIZED != ar->mObject.mState) { - SL_LOGE(ERROR_RECORDERPRESET_REALIZED); - result = SL_RESULT_PRECONDITIONS_VIOLATED; - } else { - ar->mRecordSource = newRecordSource; - } - - return result; -} - - -SLresult audioRecorder_getPreset(CAudioRecorder* ar, SLuint32* pPreset) { - SLresult result = SL_RESULT_SUCCESS; - - switch (ar->mRecordSource) { - case AUDIO_SOURCE_DEFAULT: - case AUDIO_SOURCE_MIC: - *pPreset = SL_ANDROID_RECORDING_PRESET_GENERIC; - break; - case AUDIO_SOURCE_VOICE_UPLINK: - case AUDIO_SOURCE_VOICE_DOWNLINK: - case AUDIO_SOURCE_VOICE_CALL: - *pPreset = SL_ANDROID_RECORDING_PRESET_NONE; - break; - case AUDIO_SOURCE_VOICE_RECOGNITION: - *pPreset = SL_ANDROID_RECORDING_PRESET_VOICE_RECOGNITION; - break; - case AUDIO_SOURCE_CAMCORDER: - *pPreset = SL_ANDROID_RECORDING_PRESET_CAMCORDER; - break; - case AUDIO_SOURCE_VOICE_COMMUNICATION: - *pPreset = SL_ANDROID_RECORDING_PRESET_VOICE_COMMUNICATION; - break; - default: - *pPreset = SL_ANDROID_RECORDING_PRESET_NONE; - result = SL_RESULT_INTERNAL_ERROR; - break; - } - - return result; -} - - -void audioRecorder_handleNewPos_lockRecord(CAudioRecorder* ar) { - //SL_LOGV("received event EVENT_NEW_POS from AudioRecord"); - slRecordCallback callback = NULL; - void* callbackPContext = NULL; - - interface_lock_shared(&ar->mRecord); - callback = ar->mRecord.mCallback; - callbackPContext = ar->mRecord.mContext; - interface_unlock_shared(&ar->mRecord); - - if (NULL != callback) { - // getting this event implies SL_RECORDEVENT_HEADATNEWPOS was set in the event mask - (*callback)(&ar->mRecord.mItf, callbackPContext, SL_RECORDEVENT_HEADATNEWPOS); - } -} - - -void audioRecorder_handleMarker_lockRecord(CAudioRecorder* ar) { - //SL_LOGV("received event EVENT_MARKER from AudioRecord"); - slRecordCallback callback = NULL; - void* callbackPContext = NULL; - - interface_lock_shared(&ar->mRecord); - callback = ar->mRecord.mCallback; - callbackPContext = ar->mRecord.mContext; - interface_unlock_shared(&ar->mRecord); - - if (NULL != callback) { - // getting this event implies SL_RECORDEVENT_HEADATMARKER was set in the event mask - (*callback)(&ar->mRecord.mItf, callbackPContext, SL_RECORDEVENT_HEADATMARKER); - } -} - - -void audioRecorder_handleOverrun_lockRecord(CAudioRecorder* ar) { - //SL_LOGV("received event EVENT_OVERRUN from AudioRecord"); - slRecordCallback callback = NULL; - void* callbackPContext = NULL; - - interface_lock_shared(&ar->mRecord); - if (ar->mRecord.mCallbackEventsMask & SL_RECORDEVENT_HEADSTALLED) { - callback = ar->mRecord.mCallback; - callbackPContext = ar->mRecord.mContext; - } - interface_unlock_shared(&ar->mRecord); - - if (NULL != callback) { - (*callback)(&ar->mRecord.mItf, callbackPContext, SL_RECORDEVENT_HEADSTALLED); - } -} - -//----------------------------------------------------------------------------- -SLresult android_audioRecorder_checkSourceSinkSupport(CAudioRecorder* ar) { - - const SLDataSource *pAudioSrc = &ar->mDataSource.u.mSource; - const SLDataSink *pAudioSnk = &ar->mDataSink.u.mSink; - - // Sink check: - // only buffer queue sinks are supported, regardless of the data source - if (SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE != *(SLuint32 *)pAudioSnk->pLocator) { - SL_LOGE(ERROR_RECORDER_SINK_MUST_BE_ANDROIDSIMPLEBUFFERQUEUE); - return SL_RESULT_PARAMETER_INVALID; - } else { - // only PCM buffer queues are supported - SLuint32 formatType = *(SLuint32 *)pAudioSnk->pFormat; - if (SL_DATAFORMAT_PCM == formatType) { - SLDataFormat_PCM *df_pcm = (SLDataFormat_PCM *)ar->mDataSink.u.mSink.pFormat; - ar->mSampleRateMilliHz = df_pcm->samplesPerSec; - ar->mNumChannels = df_pcm->numChannels; - SL_LOGV("AudioRecorder requested sample rate = %u mHz, %u channel(s)", - ar->mSampleRateMilliHz, ar->mNumChannels); - } - else { - SL_LOGE(ERROR_RECORDER_SINK_FORMAT_MUST_BE_PCM); - return SL_RESULT_PARAMETER_INVALID; - } - } - - // Source check: - // only input device sources are supported - // check it's an IO device - if (SL_DATALOCATOR_IODEVICE != *(SLuint32 *)pAudioSrc->pLocator) { - SL_LOGE(ERROR_RECORDER_SOURCE_MUST_BE_IODEVICE); - return SL_RESULT_PARAMETER_INVALID; - } else { - - // check it's an input device - SLDataLocator_IODevice *dl_iod = (SLDataLocator_IODevice *) pAudioSrc->pLocator; - if (SL_IODEVICE_AUDIOINPUT != dl_iod->deviceType) { - SL_LOGE(ERROR_RECORDER_IODEVICE_MUST_BE_AUDIOINPUT); - return SL_RESULT_PARAMETER_INVALID; - } - - // check it's the default input device, others aren't supported here - if (SL_DEFAULTDEVICEID_AUDIOINPUT != dl_iod->deviceID) { - SL_LOGE(ERROR_RECORDER_INPUT_ID_MUST_BE_DEFAULT); - return SL_RESULT_PARAMETER_INVALID; - } - } - - return SL_RESULT_SUCCESS; -} -//----------------------------------------------------------------------------- -static void audioRecorder_callback(int event, void* user, void *info) { - //SL_LOGV("audioRecorder_callback(%d, %p, %p) entering", event, user, info); - - CAudioRecorder *ar = (CAudioRecorder *)user; - void * callbackPContext = NULL; - - switch(event) { - case android::AudioRecord::EVENT_MORE_DATA: { - slBufferQueueCallback callback = NULL; - android::AudioRecord::Buffer* pBuff = (android::AudioRecord::Buffer*)info; - - // push data to the buffer queue - interface_lock_exclusive(&ar->mBufferQueue); - - if (ar->mBufferQueue.mState.count != 0) { - assert(ar->mBufferQueue.mFront != ar->mBufferQueue.mRear); - - BufferHeader *oldFront = ar->mBufferQueue.mFront; - BufferHeader *newFront = &oldFront[1]; - - // FIXME handle 8bit based on buffer format - short *pDest = (short*)((char *)oldFront->mBuffer + ar->mBufferQueue.mSizeConsumed); - if (ar->mBufferQueue.mSizeConsumed + pBuff->size < oldFront->mSize) { - // can't consume the whole or rest of the buffer in one shot - ar->mBufferQueue.mSizeConsumed += pBuff->size; - // leave pBuff->size untouched - // consume data - // FIXME can we avoid holding the lock during the copy? - memcpy (pDest, pBuff->i16, pBuff->size); -#ifdef MONITOR_RECORDING - if (NULL != gMonitorFp) { fwrite(pBuff->i16, pBuff->size, 1, gMonitorFp); } -#endif - } else { - // finish pushing the buffer or push the buffer in one shot - pBuff->size = oldFront->mSize - ar->mBufferQueue.mSizeConsumed; - ar->mBufferQueue.mSizeConsumed = 0; - if (newFront == &ar->mBufferQueue.mArray[ar->mBufferQueue.mNumBuffers + 1]) { - newFront = ar->mBufferQueue.mArray; - } - ar->mBufferQueue.mFront = newFront; - - ar->mBufferQueue.mState.count--; - ar->mBufferQueue.mState.playIndex++; - // consume data - // FIXME can we avoid holding the lock during the copy? - memcpy (pDest, pBuff->i16, pBuff->size); -#ifdef MONITOR_RECORDING - if (NULL != gMonitorFp) { fwrite(pBuff->i16, pBuff->size, 1, gMonitorFp); } -#endif - // data has been copied to the buffer, and the buffer queue state has been updated - // we will notify the client if applicable - callback = ar->mBufferQueue.mCallback; - // save callback data - callbackPContext = ar->mBufferQueue.mContext; - } - } else { - // no destination to push the data - pBuff->size = 0; - } - - interface_unlock_exclusive(&ar->mBufferQueue); - // notify client - if (NULL != callback) { - (*callback)(&ar->mBufferQueue.mItf, callbackPContext); - } - } - break; - - case android::AudioRecord::EVENT_OVERRUN: - audioRecorder_handleOverrun_lockRecord(ar); - break; - - case android::AudioRecord::EVENT_MARKER: - audioRecorder_handleMarker_lockRecord(ar); - break; - - case android::AudioRecord::EVENT_NEW_POS: - audioRecorder_handleNewPos_lockRecord(ar); - break; - - } -} - - -//----------------------------------------------------------------------------- -SLresult android_audioRecorder_create(CAudioRecorder* ar) { - SL_LOGV("android_audioRecorder_create(%p) entering", ar); - - const SLDataSource *pAudioSrc = &ar->mDataSource.u.mSource; - const SLDataSink *pAudioSnk = &ar->mDataSink.u.mSink; - SLresult result = SL_RESULT_SUCCESS; - - const SLuint32 sourceLocatorType = *(SLuint32 *)pAudioSrc->pLocator; - const SLuint32 sinkLocatorType = *(SLuint32 *)pAudioSnk->pLocator; - - // the following platform-independent fields have been initialized in CreateAudioRecorder() - // ar->mNumChannels - // ar->mSampleRateMilliHz - - if ((SL_DATALOCATOR_IODEVICE == sourceLocatorType) && - (SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE == sinkLocatorType)) { - // microphone to simple buffer queue - ar->mAndroidObjType = AUDIORECORDER_FROM_MIC_TO_PCM_BUFFERQUEUE; - ar->mAudioRecord = NULL; - ar->mRecordSource = AUDIO_SOURCE_DEFAULT; - } else { - result = SL_RESULT_CONTENT_UNSUPPORTED; - } - - return result; -} - - -//----------------------------------------------------------------------------- -SLresult android_audioRecorder_setConfig(CAudioRecorder* ar, const SLchar *configKey, - const void *pConfigValue, SLuint32 valueSize) { - - SLresult result; - - assert(NULL != ar && NULL != configKey && NULL != pConfigValue); - if (strcmp((const char*)configKey, (const char*)SL_ANDROID_KEY_RECORDING_PRESET) == 0) { - - // recording preset - if (KEY_RECORDING_PRESET_PARAMSIZE > valueSize) { - SL_LOGE(ERROR_CONFIG_VALUESIZE_TOO_LOW); - result = SL_RESULT_BUFFER_INSUFFICIENT; - } else { - result = audioRecorder_setPreset(ar, *(SLuint32*)pConfigValue); - } - - } else { - SL_LOGE(ERROR_CONFIG_UNKNOWN_KEY); - result = SL_RESULT_PARAMETER_INVALID; - } - - return result; -} - - -//----------------------------------------------------------------------------- -SLresult android_audioRecorder_getConfig(CAudioRecorder* ar, const SLchar *configKey, - SLuint32* pValueSize, void *pConfigValue) { - - SLresult result; - - assert(NULL != ar && NULL != configKey && NULL != pValueSize); - if (strcmp((const char*)configKey, (const char*)SL_ANDROID_KEY_RECORDING_PRESET) == 0) { - - // recording preset - if (NULL == pConfigValue) { - result = SL_RESULT_SUCCESS; - } else if (KEY_RECORDING_PRESET_PARAMSIZE > *pValueSize) { - SL_LOGE(ERROR_CONFIG_VALUESIZE_TOO_LOW); - result = SL_RESULT_BUFFER_INSUFFICIENT; - } else { - result = audioRecorder_getPreset(ar, (SLuint32*)pConfigValue); - } - *pValueSize = KEY_RECORDING_PRESET_PARAMSIZE; - - } else { - SL_LOGE(ERROR_CONFIG_UNKNOWN_KEY); - result = SL_RESULT_PARAMETER_INVALID; - } - - return result; -} - - -//----------------------------------------------------------------------------- -SLresult android_audioRecorder_realize(CAudioRecorder* ar, SLboolean async) { - SL_LOGV("android_audioRecorder_realize(%p) entering", ar); - - SLresult result = SL_RESULT_SUCCESS; - - // initialize platform-independent CAudioRecorder fields - if (SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE != ar->mDataSink.mLocator.mLocatorType) { - SL_LOGE(ERROR_RECORDER_SINK_MUST_BE_ANDROIDSIMPLEBUFFERQUEUE); - return SL_RESULT_CONTENT_UNSUPPORTED; - } - // the following platform-independent fields have been initialized in CreateAudioRecorder() - // ar->mNumChannels - // ar->mSampleRateMilliHz - - SL_LOGV("new AudioRecord %u channels, %u mHz", ar->mNumChannels, ar->mSampleRateMilliHz); - - // initialize platform-specific CAudioRecorder fields - ar->mAudioRecord = new android::AudioRecord(); - ar->mAudioRecord->set(ar->mRecordSource, // source - sles_to_android_sampleRate(ar->mSampleRateMilliHz), // sample rate in Hertz - AUDIO_FORMAT_PCM_16_BIT, //FIXME use format from buffer queue sink - sles_to_android_channelMaskIn(ar->mNumChannels, 0 /*no channel mask*/), - // channel config - 0, //frameCount min - (android::AudioRecord::record_flags) 0, // flags - audioRecorder_callback,// callback_t - (void*)ar, // user, callback data, here the AudioRecorder - 0, // notificationFrames - false); // threadCanCallJava, note: this will prevent direct Java - // callbacks, but we don't want them in the recording loop - - if (android::NO_ERROR != ar->mAudioRecord->initCheck()) { - SL_LOGE("android_audioRecorder_realize(%p) error creating AudioRecord object", ar); - result = SL_RESULT_CONTENT_UNSUPPORTED; - } - -#ifdef MONITOR_RECORDING - gMonitorFp = fopen(MONITOR_TARGET, "w"); - if (NULL == gMonitorFp) { SL_LOGE("error opening %s", MONITOR_TARGET); } - else { SL_LOGE("recording to %s", MONITOR_TARGET); } // SL_LOGE so it's always displayed -#endif - - return result; -} - - -//----------------------------------------------------------------------------- -void android_audioRecorder_destroy(CAudioRecorder* ar) { - SL_LOGV("android_audioRecorder_destroy(%p) entering", ar); - - if (NULL != ar->mAudioRecord) { - ar->mAudioRecord->stop(); - delete ar->mAudioRecord; - ar->mAudioRecord = NULL; - } - -#ifdef MONITOR_RECORDING - if (NULL != gMonitorFp) { - fclose(gMonitorFp); - gMonitorFp = NULL; - } -#endif -} - - -//----------------------------------------------------------------------------- -void android_audioRecorder_setRecordState(CAudioRecorder* ar, SLuint32 state) { - SL_LOGV("android_audioRecorder_setRecordState(%p, %u) entering", ar, state); - - if (NULL == ar->mAudioRecord) { - return; - } - - switch (state) { - case SL_RECORDSTATE_STOPPED: - ar->mAudioRecord->stop(); - break; - case SL_RECORDSTATE_PAUSED: - // Note that pausing is treated like stop as this implementation only records to a buffer - // queue, so there is no notion of destination being "opened" or "closed" (See description - // of SL_RECORDSTATE in specification) - ar->mAudioRecord->stop(); - break; - case SL_RECORDSTATE_RECORDING: - ar->mAudioRecord->start(); - break; - default: - break; - } - -} - - -//----------------------------------------------------------------------------- -void android_audioRecorder_useRecordEventMask(CAudioRecorder *ar) { - IRecord *pRecordItf = &ar->mRecord; - SLuint32 eventFlags = pRecordItf->mCallbackEventsMask; - - if (NULL == ar->mAudioRecord) { - return; - } - - if ((eventFlags & SL_RECORDEVENT_HEADATMARKER) && (pRecordItf->mMarkerPosition != 0)) { - ar->mAudioRecord->setMarkerPosition((uint32_t)((((int64_t)pRecordItf->mMarkerPosition - * sles_to_android_sampleRate(ar->mSampleRateMilliHz)))/1000)); - } else { - // clear marker - ar->mAudioRecord->setMarkerPosition(0); - } - - if (eventFlags & SL_RECORDEVENT_HEADATNEWPOS) { - SL_LOGV("pos update period %d", pRecordItf->mPositionUpdatePeriod); - ar->mAudioRecord->setPositionUpdatePeriod( - (uint32_t)((((int64_t)pRecordItf->mPositionUpdatePeriod - * sles_to_android_sampleRate(ar->mSampleRateMilliHz)))/1000)); - } else { - // clear periodic update - ar->mAudioRecord->setPositionUpdatePeriod(0); - } - - if (eventFlags & SL_RECORDEVENT_HEADATLIMIT) { - // FIXME support SL_RECORDEVENT_HEADATLIMIT - SL_LOGD("[ FIXME: IRecord_SetCallbackEventsMask(SL_RECORDEVENT_HEADATLIMIT) on an " - "SL_OBJECTID_AUDIORECORDER to be implemented ]"); - } - - if (eventFlags & SL_RECORDEVENT_HEADMOVING) { - // FIXME support SL_RECORDEVENT_HEADMOVING - SL_LOGD("[ FIXME: IRecord_SetCallbackEventsMask(SL_RECORDEVENT_HEADMOVING) on an " - "SL_OBJECTID_AUDIORECORDER to be implemented ]"); - } - - if (eventFlags & SL_RECORDEVENT_BUFFER_FULL) { - // nothing to do for SL_RECORDEVENT_BUFFER_FULL since this will not be encountered on - // recording to buffer queues - } - - if (eventFlags & SL_RECORDEVENT_HEADSTALLED) { - // nothing to do for SL_RECORDEVENT_HEADSTALLED, callback event will be checked against mask - // when AudioRecord::EVENT_OVERRUN is encountered - - } - -} - - -//----------------------------------------------------------------------------- -void android_audioRecorder_getPosition(CAudioRecorder *ar, SLmillisecond *pPosMsec) { - if ((NULL == ar) || (NULL == ar->mAudioRecord)) { - *pPosMsec = 0; - } else { - uint32_t positionInFrames; - ar->mAudioRecord->getPosition(&positionInFrames); - if (ar->mSampleRateMilliHz == UNKNOWN_SAMPLERATE) { - *pPosMsec = 0; - } else { - *pPosMsec = ((int64_t)positionInFrames * 1000) / - sles_to_android_sampleRate(ar->mSampleRateMilliHz); - } - } -} diff --git a/wilhelm/src/android/AudioRecorder_to_android.h b/wilhelm/src/android/AudioRecorder_to_android.h deleted file mode 100644 index b8d4dd27..00000000 --- a/wilhelm/src/android/AudioRecorder_to_android.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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. - */ - -/************************************************************************************************** - * AudioRecorder lifecycle - ****************************/ -extern SLresult android_audioRecorder_checkSourceSinkSupport(CAudioRecorder* ar); - -extern SLresult android_audioRecorder_create(CAudioRecorder* ar); - -/* - * Return - * SL_RESULT_SUCCESS - * SL_RESULT_PARAMETER_INVALID - * SL_RESULT_INTERNAL_ERROR - * SL_RESULT_PRECONDITIONS_VIOLATED - */ -extern SLresult android_audioRecorder_setConfig(CAudioRecorder* ar, const SLchar *configKey, - const void *pConfigValue, SLuint32 valueSize); - -/* - * if pConfigValue is NULL, pValueSize contains the size required for the given key - * - * Return - * SL_RESULT_SUCCESS - * SL_RESULT_PARAMETER_INVALID - * SL_RESULT_INTERNAL_ERROR - * SL_RESULT_PRECONDITIONS_VIOLATED - */ -extern SLresult android_audioRecorder_getConfig(CAudioRecorder* ar, const SLchar *configKey, - SLuint32* pValueSize, void *pConfigValue); - -extern SLresult android_audioRecorder_realize(CAudioRecorder* ar, SLboolean async); - -extern void android_audioRecorder_destroy(CAudioRecorder* ar); - -/************************************************************************************************** - * AudioRecorder control - ****************************/ - -extern void android_audioRecorder_setRecordState(CAudioRecorder* ar, SLuint32 state); - -extern void android_audioRecorder_useRecordEventMask(CAudioRecorder *ar); - -extern void android_audioRecorder_getPosition(CAudioRecorder *ar, SLmillisecond *pPosMsec); diff --git a/wilhelm/src/android/BufferQueueSource.cpp b/wilhelm/src/android/BufferQueueSource.cpp deleted file mode 100644 index 6cf04fbc..00000000 --- a/wilhelm/src/android/BufferQueueSource.cpp +++ /dev/null @@ -1,172 +0,0 @@ -/* - * 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. - */ - -//#define USE_LOG SLAndroidLogLevel_Verbose - -#include "sles_allinclusive.h" -#include "android/BufferQueueSource.h" - -#include <media/stagefright/foundation/ADebug.h> -#include <sys/types.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> - -namespace android { - - -const SLuint32 BufferQueueSource::kItemProcessed[NB_BUFFEREVENT_ITEM_FIELDS] = { - SL_ANDROID_ITEMKEY_BUFFERQUEUEEVENT, // item key - sizeof(SLuint32), // item size - SL_ANDROIDBUFFERQUEUEEVENT_PROCESSED // item data -}; - - -BufferQueueSource::BufferQueueSource(IAndroidBufferQueue *androidBufferQueue) : - mAndroidBufferQueueSource(androidBufferQueue), - mStreamToBqOffset(0), - mEosReached(false) -{ -} - - -BufferQueueSource::~BufferQueueSource() { - SL_LOGD("BufferQueueSource::~BufferQueueSource"); -} - - -//-------------------------------------------------------------------------- -status_t BufferQueueSource::initCheck() const { - return mAndroidBufferQueueSource != NULL ? OK : NO_INIT; -} - -ssize_t BufferQueueSource::readAt(off64_t offset, void *data, size_t size) { - SL_LOGD("BufferQueueSource::readAt(offset=%lld, data=%p, size=%d)", offset, data, size); - - if (mEosReached) { - // once EOS has been received from the buffer queue, you can't read anymore - return 0; - } - - ssize_t readSize; - slAndroidBufferQueueCallback callback = NULL; - void* pBufferContext, *pBufferData, *callbackPContext; - uint32_t dataSize, dataUsed; - - interface_lock_exclusive(mAndroidBufferQueueSource); - - if (mAndroidBufferQueueSource->mState.count == 0) { - readSize = 0; - } else { - assert(mAndroidBufferQueueSource->mFront != mAndroidBufferQueueSource->mRear); - - AdvancedBufferHeader *oldFront = mAndroidBufferQueueSource->mFront; - AdvancedBufferHeader *newFront = &oldFront[1]; - - // where to read from - char *pSrc = NULL; - // can this read operation cause us to call the buffer queue callback - // (either because there was a command with no data, or all the data has been consumed) - bool queueCallbackCandidate = false; - - // consume events when starting to read data from a buffer for the first time - if (oldFront->mDataSizeConsumed == 0) { - if (oldFront->mItems.mAdtsCmdData.mAdtsCmdCode & ANDROID_ADTSEVENT_EOS) { - mEosReached = true; - // EOS has no associated data - queueCallbackCandidate = true; - } - oldFront->mItems.mAdtsCmdData.mAdtsCmdCode = ANDROID_ADTSEVENT_NONE; - } - - //assert(mStreamToBqOffset <= offset); - CHECK_LE(mStreamToBqOffset, offset); - - if (offset + size <= mStreamToBqOffset + oldFront->mDataSize) { - pSrc = ((char*)oldFront->mDataBuffer) + (offset - mStreamToBqOffset); - - if (offset - mStreamToBqOffset + size == oldFront->mDataSize) { - // consumed buffer entirely - oldFront->mDataSizeConsumed = oldFront->mDataSize; - mStreamToBqOffset += oldFront->mDataSize; - queueCallbackCandidate = true; - - // move queue to next buffer - if (newFront == &mAndroidBufferQueueSource-> - mBufferArray[mAndroidBufferQueueSource->mNumBuffers + 1]) { - // reached the end, circle back - newFront = mAndroidBufferQueueSource->mBufferArray; - } - mAndroidBufferQueueSource->mFront = newFront; - // update the queue state - mAndroidBufferQueueSource->mState.count--; - mAndroidBufferQueueSource->mState.index++; - SL_LOGV("BufferQueueSource moving to next buffer"); - } - } - - // consume data: copy to given destination - if (NULL != pSrc) { - memcpy(data, pSrc, size); - readSize = size; - } else { - readSize = 0; - } - - if (queueCallbackCandidate) { - // data has been consumed, and the buffer queue state has been updated - // we will notify the client if applicable - if (mAndroidBufferQueueSource->mCallbackEventsMask & - SL_ANDROIDBUFFERQUEUEEVENT_PROCESSED) { - callback = mAndroidBufferQueueSource->mCallback; - // save callback data while under lock - callbackPContext = mAndroidBufferQueueSource->mContext; - pBufferContext = (void *)oldFront->mBufferContext; - pBufferData = (void *)oldFront->mDataBuffer; - dataSize = oldFront->mDataSize; - dataUsed = oldFront->mDataSizeConsumed; - } - } - } - - interface_unlock_exclusive(mAndroidBufferQueueSource); - - // notify client - if (NULL != callback) { - SLresult result = (*callback)(&mAndroidBufferQueueSource->mItf, callbackPContext, - pBufferContext, pBufferData, dataSize, dataUsed, - // no messages during playback other than marking the buffer as processed - (const SLAndroidBufferItem*)(&kItemProcessed) /* pItems */, - NB_BUFFEREVENT_ITEM_FIELDS * sizeof(SLuint32) /* itemsLength */ ); - if (SL_RESULT_SUCCESS != result) { - // Reserved for future use - SL_LOGW("Unsuccessful result %d returned from AndroidBufferQueueCallback", result); - } - } - - return readSize; -} - - -status_t BufferQueueSource::getSize(off64_t *size) { - SL_LOGD("BufferQueueSource::getSize()"); - // we're streaming, we don't know how much there is - *size = 0; - return ERROR_UNSUPPORTED; -} - -} // namespace android diff --git a/wilhelm/src/android/BufferQueueSource.h b/wilhelm/src/android/BufferQueueSource.h deleted file mode 100644 index c362df27..00000000 --- a/wilhelm/src/android/BufferQueueSource.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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 BUFFERQUEUE_SOURCE_H_ -#define BUFFERQUEUE_SOURCE_H_ - -#include <media/stagefright/DataSource.h> - -// number of SLuint32 fields to store a buffer event message in an item, by mapping each -// to the item key (SLuint32), the item size (SLuint32), and the item data (mask on SLuint32) -#define NB_BUFFEREVENT_ITEM_FIELDS 3 - -namespace android { - -// a Stagefright DataSource that pulls data from an AndroidBufferQueue - -class BufferQueueSource : public DataSource { -public: - - // store an item structure to indicate a processed buffer - static const SLuint32 kItemProcessed[NB_BUFFEREVENT_ITEM_FIELDS]; - - BufferQueueSource(IAndroidBufferQueue *androidBufferQueue); - - virtual status_t initCheck() const; - - virtual ssize_t readAt(off64_t offset, void *data, size_t size); - - virtual status_t getSize(off64_t *size); - - virtual ~BufferQueueSource(); - -private: - // the Android Buffer Queue from which data is consumed - IAndroidBufferQueue* const mAndroidBufferQueueSource; - - // a monotonically increasing offset used to translate an offset from the beginning - // of the stream, to an offset in each buffer from the buffer queue source - off64_t mStreamToBqOffset; - - // indicates whether an EOS command has been reached when consuming the buffers in the queue - bool mEosReached; - - BufferQueueSource(const BufferQueueSource &); - BufferQueueSource &operator=(const BufferQueueSource &); -}; - -} // namespace android - -#endif // BUFFERQUEUE_SOURCE_H_ - diff --git a/wilhelm/src/android/CallbackProtector.cpp b/wilhelm/src/android/CallbackProtector.cpp deleted file mode 100644 index 85eceac6..00000000 --- a/wilhelm/src/android/CallbackProtector.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/* - * 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. - */ - -#include "CallbackProtector.h" -#include "sllog.h" - -#include <media/stagefright/foundation/ADebug.h> - -//-------------------------------------------------------------------------------------------------- -namespace android { - - -CallbackProtector::CallbackProtector() : RefBase(), - mSafeToEnterCb(true), - mCbCount(0) -#ifdef USE_DEBUG - , mCallbackThread(NULL), - mCallbackTid(0), - mRequesterThread(NULL), - mRequesterTid(0) -#endif -{ -} - - -CallbackProtector::~CallbackProtector() { - Mutex::Autolock _l(mLock); - if (mCbCount) { - SL_LOGE("Callback protector detected an active callback after destroy"); - } - -} - - -// static -bool CallbackProtector::enterCbIfOk(const sp<CallbackProtector> &protector) { - if (protector != 0) { - return protector->enterCb(); - } else { - SL_LOGE("Callback protector is missing"); - return false; - } -} - - -bool CallbackProtector::enterCb() { - Mutex::Autolock _l(mLock); - if (mSafeToEnterCb) { - mCbCount++; -#ifdef USE_DEBUG - if (mCbCount > 1) { - SL_LOGV("Callback protector allowed multiple or nested callback entry: %u", mCbCount); - } else { - mCallbackThread = pthread_self(); - mCallbackTid = gettid(); - } -#endif - } else { -#ifdef USE_DEBUG - SL_LOGV("Callback protector denied callback entry by thread %p tid %d during destroy" - " requested by thread %p tid %d", - (void *) pthread_self(), gettid(), - (void *) mRequesterThread, mRequesterTid); -#else - SL_LOGV("Callback protector denied callback entry during destroy"); -#endif - } - return mSafeToEnterCb; -} - - -void CallbackProtector::exitCb() { - Mutex::Autolock _l(mLock); - - CHECK(mCbCount > 0); - mCbCount--; - - if (mCbCount == 0) { - if (!mSafeToEnterCb) { -#ifdef USE_DEBUG - SL_LOGV("Callback protector detected return from callback by thread %p tid %d during" - " destroy requested by thread %p tid %d", - (void *) mCallbackThread, mCallbackTid, - (void *) mRequesterThread, mRequesterTid); -#else - SL_LOGV("Callback protector detected return from callback during destroy"); -#endif - mCbExitedCondition.broadcast(); - } -#ifdef USE_DEBUG - mCallbackThread = NULL; - mCallbackTid = 0; -#endif - } -} - - -void CallbackProtector::requestCbExitAndWait() { - Mutex::Autolock _l(mLock); - mSafeToEnterCb = false; -#ifdef USE_DEBUG - mRequesterThread = pthread_self(); - mRequesterTid = gettid(); -#endif - while (mCbCount) { -#ifdef USE_DEBUG - SL_LOGV("Callback protector detected in-progress callback by thread %p tid %d during" - " blocking destroy requested by thread %p tid %d", - (void *) mCallbackThread, mCallbackTid, - (void *) pthread_self(), gettid()); -#else - SL_LOGV("Callback protector detected in-progress callback during blocking destroy"); -#endif - mCbExitedCondition.wait(mLock); - } -} - - -void CallbackProtector::requestCbExit() { - Mutex::Autolock _l(mLock); - mSafeToEnterCb = false; -#ifdef USE_DEBUG - mRequesterThread = pthread_self(); - mRequesterTid = gettid(); -#endif - if (mCbCount) { -#ifdef USE_DEBUG - SL_LOGV("Callback protector detected in-progress callback by thread %p tid %d during" - " non-blocking destroy requested by thread %p tid %d", - (void *) mCallbackThread, mCallbackTid, - (void *) pthread_self(), gettid()); -#else - SL_LOGV("Callback protector detected in-progress callback during non-blocking destroy"); -#endif - } -} - -} // namespace android diff --git a/wilhelm/src/android/CallbackProtector.h b/wilhelm/src/android/CallbackProtector.h deleted file mode 100644 index 8b7d2cde..00000000 --- a/wilhelm/src/android/CallbackProtector.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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. - */ - -#include "utils/threads.h" - -//-------------------------------------------------------------------------------------------------- -namespace android { - -class CallbackProtector : public RefBase { - -public: - CallbackProtector(); - virtual ~CallbackProtector(); - - /** - * Indicates whether the CallbackProtector is non-NULL and it's safe to enter the callback. - */ - static bool enterCbIfOk(const sp<CallbackProtector> &protector); - - /** - * Indicates whether it's safe to enter the callback. It would typically return false - * if the associated object (AudioTrack, AudioPlayer, MediaPlayer) is about to be destroyed. - */ - bool enterCb(); - - /** - * This method must be paired to each call to enterCb() or enterCbIfOk(), - * only it returned that it is safe enter the callback; - */ - void exitCb(); - - /** - * Called to signal the associated object is about to be destroyed, so whenever a callback is - * entered (see enterCb) it will be notified it is pointless to process the callback. This will - * return immediately if there are no callbacks, and will block until current callbacks exit. - */ - void requestCbExitAndWait(); - - /** - * Similar to requestCbExitAndWait, but does not wait for current callbacks to exit. - */ - void requestCbExit(); - -private: - Mutex mLock; - Condition mCbExitedCondition; - - bool mSafeToEnterCb; - - /** Counts the number of callbacks actively locking the associated AudioPlayer */ - unsigned int mCbCount; - -#ifdef USE_DEBUG - pthread_t mCallbackThread; - pid_t mCallbackTid; - pthread_t mRequesterThread; - pid_t mRequesterTid; -#endif - - // disallow "evil" constructors - CallbackProtector(const CallbackProtector &); - CallbackProtector &operator=(const CallbackProtector &); -}; - -} // namespace android diff --git a/wilhelm/src/android/MediaPlayer_to_android.cpp b/wilhelm/src/android/MediaPlayer_to_android.cpp deleted file mode 100644 index 981a6bd2..00000000 --- a/wilhelm/src/android/MediaPlayer_to_android.cpp +++ /dev/null @@ -1,768 +0,0 @@ -/* - * 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. - */ - -#include <system/window.h> -#include <utils/StrongPointer.h> -#include <gui/Surface.h> - -#include "sles_allinclusive.h" -#include "android_prompts.h" -// LocAVPlayer and StreamPlayer derive from GenericMediaPlayer, -// so no need to #include "android_GenericMediaPlayer.h" -#include "android_LocAVPlayer.h" -#include "android_StreamPlayer.h" - -//----------------------------------------------------------------------------- -static void player_handleMediaPlayerEventNotifications(int event, int data1, int data2, void* user) -{ - - // FIXME This code is derived from similar code in sfplayer_handlePrefetchEvent. The two - // versions are quite similar, but still different enough that they need to be separate. - // At some point they should be re-factored and merged if feasible. - // As with other OpenMAX AL implementation code, this copy mostly uses SL_ symbols - // rather than XA_ unless the difference is significant. - - if (NULL == user) { - return; - } - - CMediaPlayer* mp = (CMediaPlayer*) user; - if (!android::CallbackProtector::enterCbIfOk(mp->mCallbackProtector)) { - // it is not safe to enter the callback (the media player is about to go away) - return; - } - union { - char c[sizeof(int)]; - int i; - } u; - u.i = event; - SL_LOGV("player_handleMediaPlayerEventNotifications(event='%c%c%c%c' (%d), data1=%d, data2=%d, " - "user=%p) from AVPlayer", u.c[3], u.c[2], u.c[1], u.c[0], event, data1, data2, user); - switch(event) { - - case android::GenericPlayer::kEventPrepared: { - SL_LOGV("Received GenericPlayer::kEventPrepared for CMediaPlayer %p", mp); - - // assume no callback - slPrefetchCallback callback = NULL; - void* callbackPContext; - XAuint32 events; - - object_lock_exclusive(&mp->mObject); - - // mark object as prepared; same state is used for successful or unsuccessful prepare - assert(mp->mAndroidObjState == ANDROID_PREPARING); - mp->mAndroidObjState = ANDROID_READY; - - if (PLAYER_SUCCESS == data1) { - // Most of successful prepare completion for mp->mAVPlayer - // is handled by GenericPlayer and its subclasses. - } else { - // AVPlayer prepare() failed prefetching, there is no event in XAPrefetchStatus to - // indicate a prefetch error, so we signal it by sending simultaneously two events: - // - SL_PREFETCHEVENT_FILLLEVELCHANGE with a level of 0 - // - SL_PREFETCHEVENT_STATUSCHANGE with a status of SL_PREFETCHSTATUS_UNDERFLOW - SL_LOGE(ERROR_PLAYER_PREFETCH_d, data1); - if (IsInterfaceInitialized(&mp->mObject, MPH_XAPREFETCHSTATUS)) { - mp->mPrefetchStatus.mLevel = 0; - mp->mPrefetchStatus.mStatus = SL_PREFETCHSTATUS_UNDERFLOW; - if (!(~mp->mPrefetchStatus.mCallbackEventsMask & - (SL_PREFETCHEVENT_FILLLEVELCHANGE | SL_PREFETCHEVENT_STATUSCHANGE))) { - callback = mp->mPrefetchStatus.mCallback; - callbackPContext = mp->mPrefetchStatus.mContext; - events = SL_PREFETCHEVENT_FILLLEVELCHANGE | SL_PREFETCHEVENT_STATUSCHANGE; - } - } - } - - object_unlock_exclusive(&mp->mObject); - - // callback with no lock held - if (NULL != callback) { - (*callback)(&mp->mPrefetchStatus.mItf, callbackPContext, events); - } - - break; - } - - case android::GenericPlayer::kEventHasVideoSize: { - SL_LOGV("Received AVPlayer::kEventHasVideoSize (%d,%d) for CMediaPlayer %p", - data1, data2, mp); - - object_lock_exclusive(&mp->mObject); - - // remove an existing video info entry (here we only have one video stream) - for(size_t i=0 ; i < mp->mStreamInfo.mStreamInfoTable.size() ; i++) { - if (XA_DOMAINTYPE_VIDEO == mp->mStreamInfo.mStreamInfoTable.itemAt(i).domain) { - mp->mStreamInfo.mStreamInfoTable.removeAt(i); - break; - } - } - // update the stream information with a new video info entry - StreamInfo streamInfo; - streamInfo.domain = XA_DOMAINTYPE_VIDEO; - streamInfo.videoInfo.codecId = 0;// unknown, we don't have that info FIXME - streamInfo.videoInfo.width = (XAuint32)data1; - streamInfo.videoInfo.height = (XAuint32)data2; - streamInfo.videoInfo.bitRate = 0;// unknown, we don't have that info FIXME - streamInfo.videoInfo.frameRate = 0; - streamInfo.videoInfo.duration = XA_TIME_UNKNOWN; - StreamInfo &contInfo = mp->mStreamInfo.mStreamInfoTable.editItemAt(0); - contInfo.containerInfo.numStreams = 1; - ssize_t index = mp->mStreamInfo.mStreamInfoTable.add(streamInfo); - - // callback is unconditional; there is no bitmask of enabled events - xaStreamEventChangeCallback callback = mp->mStreamInfo.mCallback; - void* callbackPContext = mp->mStreamInfo.mContext; - - object_unlock_exclusive(&mp->mObject); - - // enqueue notification (outside of lock) that the stream information has been updated - if ((NULL != callback) && (index >= 0)) { -#ifndef USE_ASYNCHRONOUS_STREAMCBEVENT_PROPERTYCHANGE_CALLBACK - (*callback)(&mp->mStreamInfo.mItf, XA_STREAMCBEVENT_PROPERTYCHANGE /*eventId*/, - 1 /*streamIndex, only one stream supported here, 0 is reserved*/, - NULL /*pEventData, always NULL in OpenMAX AL 1.0.1*/, - callbackPContext /*pContext*/); -#else - SLresult res = EnqueueAsyncCallback_piipp(mp, callback, - /*p1*/ &mp->mStreamInfo.mItf, - /*i1*/ XA_STREAMCBEVENT_PROPERTYCHANGE /*eventId*/, - /*i2*/ 1 /*streamIndex, only one stream supported here, 0 is reserved*/, - /*p2*/ NULL /*pEventData, always NULL in OpenMAX AL 1.0.1*/, - /*p3*/ callbackPContext /*pContext*/); - ALOGW_IF(SL_RESULT_SUCCESS != res, - "Callback %p(%p, XA_STREAMCBEVENT_PROPERTYCHANGE, 1, NULL, %p) dropped", - callback, &mp->mStreamInfo.mItf, callbackPContext); -#endif - } - break; - } - - case android::GenericPlayer::kEventEndOfStream: { - SL_LOGV("Received AVPlayer::kEventEndOfStream for CMediaPlayer %p", mp); - - object_lock_exclusive(&mp->mObject); - // should be xaPlayCallback but we're sharing the itf between SL and AL - slPlayCallback playCallback = NULL; - void * playContext = NULL; - // XAPlayItf callback or no callback? - if (mp->mPlay.mEventFlags & XA_PLAYEVENT_HEADATEND) { - playCallback = mp->mPlay.mCallback; - playContext = mp->mPlay.mContext; - } - mp->mPlay.mState = XA_PLAYSTATE_PAUSED; - object_unlock_exclusive(&mp->mObject); - - // enqueue callback with no lock held - if (NULL != playCallback) { -#ifndef USE_ASYNCHRONOUS_PLAY_CALLBACK - (*playCallback)(&mp->mPlay.mItf, playContext, XA_PLAYEVENT_HEADATEND); -#else - SLresult res = EnqueueAsyncCallback_ppi(mp, playCallback, &mp->mPlay.mItf, playContext, - XA_PLAYEVENT_HEADATEND); - ALOGW_IF(SL_RESULT_SUCCESS != res, - "Callback %p(%p, %p, SL_PLAYEVENT_HEADATEND) dropped", playCallback, - &mp->mPlay.mItf, playContext); -#endif - } - break; - } - - case android::GenericPlayer::kEventChannelCount: { - SL_LOGV("kEventChannelCount channels = %d", data1); - object_lock_exclusive(&mp->mObject); - if (UNKNOWN_NUMCHANNELS == mp->mNumChannels && UNKNOWN_NUMCHANNELS != data1) { - mp->mNumChannels = data1; - android_Player_volumeUpdate(mp); - } - object_unlock_exclusive(&mp->mObject); - } - break; - - case android::GenericPlayer::kEventPrefetchFillLevelUpdate: { - SL_LOGV("kEventPrefetchFillLevelUpdate"); - if (!IsInterfaceInitialized(&mp->mObject, MPH_XAPREFETCHSTATUS)) { - break; - } - slPrefetchCallback callback = NULL; - void* callbackPContext = NULL; - - // SLPrefetchStatusItf callback or no callback? - interface_lock_exclusive(&mp->mPrefetchStatus); - if (mp->mPrefetchStatus.mCallbackEventsMask & SL_PREFETCHEVENT_FILLLEVELCHANGE) { - callback = mp->mPrefetchStatus.mCallback; - callbackPContext = mp->mPrefetchStatus.mContext; - } - mp->mPrefetchStatus.mLevel = (SLpermille)data1; - interface_unlock_exclusive(&mp->mPrefetchStatus); - - // callback with no lock held - if (NULL != callback) { - (*callback)(&mp->mPrefetchStatus.mItf, callbackPContext, - SL_PREFETCHEVENT_FILLLEVELCHANGE); - } - } - break; - - case android::GenericPlayer::kEventPrefetchStatusChange: { - SL_LOGV("kEventPrefetchStatusChange"); - if (!IsInterfaceInitialized(&mp->mObject, MPH_XAPREFETCHSTATUS)) { - break; - } - slPrefetchCallback callback = NULL; - void* callbackPContext = NULL; - - // SLPrefetchStatusItf callback or no callback? - object_lock_exclusive(&mp->mObject); - if (mp->mPrefetchStatus.mCallbackEventsMask & SL_PREFETCHEVENT_STATUSCHANGE) { - callback = mp->mPrefetchStatus.mCallback; - callbackPContext = mp->mPrefetchStatus.mContext; - } - if (data1 >= android::kStatusIntermediate) { - mp->mPrefetchStatus.mStatus = SL_PREFETCHSTATUS_SUFFICIENTDATA; - } else if (data1 < android::kStatusIntermediate) { - mp->mPrefetchStatus.mStatus = SL_PREFETCHSTATUS_UNDERFLOW; - } - object_unlock_exclusive(&mp->mObject); - - // callback with no lock held - if (NULL != callback) { - (*callback)(&mp->mPrefetchStatus.mItf, callbackPContext, SL_PREFETCHEVENT_STATUSCHANGE); - } - } - break; - - case android::GenericPlayer::kEventPlay: { - SL_LOGV("kEventPlay"); - - interface_lock_shared(&mp->mPlay); - slPlayCallback callback = mp->mPlay.mCallback; - void* callbackPContext = mp->mPlay.mContext; - interface_unlock_shared(&mp->mPlay); - - if (NULL != callback) { - (*callback)(&mp->mPlay.mItf, callbackPContext, (SLuint32) data1); // SL_PLAYEVENT_HEAD* - } - } - break; - - case android::GenericPlayer::kEventErrorAfterPrepare: { - SL_LOGV("kEventErrorAfterPrepare"); - - // assume no callback - slPrefetchCallback callback = NULL; - void* callbackPContext = NULL; - - object_lock_exclusive(&mp->mObject); - if (IsInterfaceInitialized(&mp->mObject, MPH_XAPREFETCHSTATUS)) { - mp->mPrefetchStatus.mLevel = 0; - mp->mPrefetchStatus.mStatus = SL_PREFETCHSTATUS_UNDERFLOW; - if (!(~mp->mPrefetchStatus.mCallbackEventsMask & - (SL_PREFETCHEVENT_FILLLEVELCHANGE | SL_PREFETCHEVENT_STATUSCHANGE))) { - callback = mp->mPrefetchStatus.mCallback; - callbackPContext = mp->mPrefetchStatus.mContext; - } - } - object_unlock_exclusive(&mp->mObject); - - // FIXME there's interesting information in data1, but no API to convey it to client - SL_LOGE("Error after prepare: %d", data1); - - // callback with no lock held - if (NULL != callback) { - (*callback)(&mp->mPrefetchStatus.mItf, callbackPContext, - SL_PREFETCHEVENT_FILLLEVELCHANGE | SL_PREFETCHEVENT_STATUSCHANGE); - } - - } - break; - - default: { - SL_LOGE("Received unknown event %d, data %d from AVPlayer", event, data1); - } - } - - mp->mCallbackProtector->exitCb(); -} - - -//----------------------------------------------------------------------------- -XAresult android_Player_checkSourceSink(CMediaPlayer *mp) { - - XAresult result = XA_RESULT_SUCCESS; - - const SLDataSource *pSrc = &mp->mDataSource.u.mSource; - const SLDataSink *pAudioSnk = &mp->mAudioSink.u.mSink; - - // format check: - const SLuint32 sourceLocatorType = *(SLuint32 *)pSrc->pLocator; - const SLuint32 sourceFormatType = *(SLuint32 *)pSrc->pFormat; - const SLuint32 audioSinkLocatorType = *(SLuint32 *)pAudioSnk->pLocator; - //const SLuint32 sinkFormatType = *(SLuint32 *)pAudioSnk->pFormat; - - // Source check - switch(sourceLocatorType) { - - case XA_DATALOCATOR_ANDROIDBUFFERQUEUE: { - switch (sourceFormatType) { - case XA_DATAFORMAT_MIME: { - SLDataFormat_MIME *df_mime = (SLDataFormat_MIME *) pSrc->pFormat; - if (SL_CONTAINERTYPE_MPEG_TS != df_mime->containerType) { - SL_LOGE("Cannot create player with XA_DATALOCATOR_ANDROIDBUFFERQUEUE data source " - "that is not fed MPEG-2 TS data"); - return SL_RESULT_CONTENT_UNSUPPORTED; - } - } break; - default: - SL_LOGE("Cannot create player with XA_DATALOCATOR_ANDROIDBUFFERQUEUE data source " - "without SL_DATAFORMAT_MIME format"); - return XA_RESULT_CONTENT_UNSUPPORTED; - } - } break; - - case XA_DATALOCATOR_URI: // intended fall-through - case XA_DATALOCATOR_ANDROIDFD: - break; - - default: - SL_LOGE("Cannot create media player with data locator type 0x%x", - (unsigned) sourceLocatorType); - return SL_RESULT_PARAMETER_INVALID; - }// switch (locatorType) - - // Audio sink check: only playback is supported here - switch(audioSinkLocatorType) { - - case XA_DATALOCATOR_OUTPUTMIX: - break; - - default: - SL_LOGE("Cannot create media player with audio sink data locator of type 0x%x", - (unsigned) audioSinkLocatorType); - return XA_RESULT_PARAMETER_INVALID; - }// switch (locaaudioSinkLocatorTypeorType) - - return result; -} - - -//----------------------------------------------------------------------------- -XAresult android_Player_create(CMediaPlayer *mp) { - - XAresult result = XA_RESULT_SUCCESS; - - // FIXME verify data source - const SLDataSource *pDataSrc = &mp->mDataSource.u.mSource; - // FIXME verify audio data sink - const SLDataSink *pAudioSnk = &mp->mAudioSink.u.mSink; - // FIXME verify image data sink - const SLDataSink *pVideoSnk = &mp->mImageVideoSink.u.mSink; - - XAuint32 sourceLocator = *(XAuint32 *)pDataSrc->pLocator; - switch(sourceLocator) { - // FIXME support Android simple buffer queue as well - case XA_DATALOCATOR_ANDROIDBUFFERQUEUE: - mp->mAndroidObjType = AUDIOVIDEOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE; - break; - case XA_DATALOCATOR_URI: // intended fall-through - case SL_DATALOCATOR_ANDROIDFD: - mp->mAndroidObjType = AUDIOVIDEOPLAYER_FROM_URIFD; - break; - case XA_DATALOCATOR_ADDRESS: // intended fall-through - default: - mp->mAndroidObjType = INVALID_TYPE; - SL_LOGE("Unable to create MediaPlayer for data source locator 0x%x", sourceLocator); - result = XA_RESULT_PARAMETER_INVALID; - break; - } - - // FIXME duplicates an initialization also done by higher level - mp->mAndroidObjState = ANDROID_UNINITIALIZED; - mp->mStreamType = ANDROID_DEFAULT_OUTPUT_STREAM_TYPE; - mp->mSessionId = android::AudioSystem::newAudioSessionId(); - - // placeholder: not necessary yet as session ID lifetime doesn't extend beyond player - // android::AudioSystem::acquireAudioSessionId(mp->mSessionId); - - mp->mCallbackProtector = new android::CallbackProtector(); - - return result; -} - - -//----------------------------------------------------------------------------- -// FIXME abstract out the diff between CMediaPlayer and CAudioPlayer -XAresult android_Player_realize(CMediaPlayer *mp, SLboolean async) { - SL_LOGV("android_Player_realize_l(%p)", mp); - XAresult result = XA_RESULT_SUCCESS; - - const SLDataSource *pDataSrc = &mp->mDataSource.u.mSource; - const SLuint32 sourceLocator = *(SLuint32 *)pDataSrc->pLocator; - - AudioPlayback_Parameters ap_params; - ap_params.sessionId = mp->mSessionId; - ap_params.streamType = mp->mStreamType; - - switch(mp->mAndroidObjType) { - case AUDIOVIDEOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE: { - mp->mAVPlayer = new android::StreamPlayer(&ap_params, true /*hasVideo*/, - &mp->mAndroidBufferQueue, mp->mCallbackProtector); - mp->mAVPlayer->init(player_handleMediaPlayerEventNotifications, (void*)mp); - } - break; - case AUDIOVIDEOPLAYER_FROM_URIFD: { - mp->mAVPlayer = new android::LocAVPlayer(&ap_params, true /*hasVideo*/); - mp->mAVPlayer->init(player_handleMediaPlayerEventNotifications, (void*)mp); - switch (mp->mDataSource.mLocator.mLocatorType) { - case XA_DATALOCATOR_URI: - ((android::LocAVPlayer*)mp->mAVPlayer.get())->setDataSource( - (const char*)mp->mDataSource.mLocator.mURI.URI); - break; - case XA_DATALOCATOR_ANDROIDFD: { - int64_t offset = (int64_t)mp->mDataSource.mLocator.mFD.offset; - ((android::LocAVPlayer*)mp->mAVPlayer.get())->setDataSource( - (int)mp->mDataSource.mLocator.mFD.fd, - offset == SL_DATALOCATOR_ANDROIDFD_USE_FILE_SIZE ? - (int64_t)PLAYER_FD_FIND_FILE_SIZE : offset, - (int64_t)mp->mDataSource.mLocator.mFD.length); - } - break; - default: - SL_LOGE("Invalid or unsupported data locator type %u for data source", - mp->mDataSource.mLocator.mLocatorType); - result = XA_RESULT_PARAMETER_INVALID; - } - } - break; - case INVALID_TYPE: // intended fall-through - default: - SL_LOGE("Unable to realize MediaPlayer, invalid internal Android object type"); - result = XA_RESULT_PARAMETER_INVALID; - break; - } - - if (XA_RESULT_SUCCESS == result) { - - // if there is a video sink - if (XA_DATALOCATOR_NATIVEDISPLAY == - mp->mImageVideoSink.mLocator.mLocatorType) { - ANativeWindow *nativeWindow = (ANativeWindow *) - mp->mImageVideoSink.mLocator.mNativeDisplay.hWindow; - // we already verified earlier that hWindow is non-NULL - assert(nativeWindow != NULL); - result = android_Player_setNativeWindow(mp, nativeWindow); - } - - } - - return result; -} - -// Called with a lock on MediaPlayer, and blocks until safe to destroy -XAresult android_Player_preDestroy(CMediaPlayer *mp) { - SL_LOGV("android_Player_preDestroy(%p)", mp); - - // Not yet clear why this order is important, but it reduces detected deadlocks - object_unlock_exclusive(&mp->mObject); - if (mp->mCallbackProtector != 0) { - mp->mCallbackProtector->requestCbExitAndWait(); - } - object_lock_exclusive(&mp->mObject); - - if (mp->mAVPlayer != 0) { - mp->mAVPlayer->preDestroy(); - } - SL_LOGV("android_Player_preDestroy(%p) after mAVPlayer->preDestroy()", mp); - - return XA_RESULT_SUCCESS; -} - -//----------------------------------------------------------------------------- -XAresult android_Player_destroy(CMediaPlayer *mp) { - SL_LOGV("android_Player_destroy(%p)", mp); - - mp->mAVPlayer.clear(); - - // placeholder: not necessary yet as session ID lifetime doesn't extend beyond player - // android::AudioSystem::releaseAudioSessionId(mp->mSessionId); - - mp->mCallbackProtector.clear(); - - // explicit destructor - mp->mAVPlayer.~sp(); - mp->mCallbackProtector.~sp(); - - return XA_RESULT_SUCCESS; -} - - -void android_Player_usePlayEventMask(CMediaPlayer *mp) { - if (mp->mAVPlayer != 0) { - IPlay *pPlayItf = &mp->mPlay; - mp->mAVPlayer->setPlayEvents((int32_t) pPlayItf->mEventFlags, - (int32_t) pPlayItf->mMarkerPosition, (int32_t) pPlayItf->mPositionUpdatePeriod); - } -} - - -XAresult android_Player_getDuration(IPlay *pPlayItf, XAmillisecond *pDurMsec) { - CMediaPlayer *avp = (CMediaPlayer *)pPlayItf->mThis; - - switch (avp->mAndroidObjType) { - - case AUDIOVIDEOPLAYER_FROM_URIFD: { - int dur = ANDROID_UNKNOWN_TIME; - if (avp->mAVPlayer != 0) { - avp->mAVPlayer->getDurationMsec(&dur); - } - if (dur == ANDROID_UNKNOWN_TIME) { - *pDurMsec = XA_TIME_UNKNOWN; - } else { - *pDurMsec = (XAmillisecond)dur; - } - } break; - - case AUDIOVIDEOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE: // intended fall-through - default: - *pDurMsec = XA_TIME_UNKNOWN; - break; - } - - return XA_RESULT_SUCCESS; -} - - -XAresult android_Player_getPosition(IPlay *pPlayItf, XAmillisecond *pPosMsec) { - SL_LOGD("android_Player_getPosition()"); - XAresult result = XA_RESULT_SUCCESS; - CMediaPlayer *avp = (CMediaPlayer *)pPlayItf->mThis; - - switch (avp->mAndroidObjType) { - - case AUDIOVIDEOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE: // intended fall-through - case AUDIOVIDEOPLAYER_FROM_URIFD: { - int pos = ANDROID_UNKNOWN_TIME; - if (avp->mAVPlayer != 0) { - avp->mAVPlayer->getPositionMsec(&pos); - } - if (pos == ANDROID_UNKNOWN_TIME) { - *pPosMsec = 0; - } else { - *pPosMsec = (XAmillisecond)pos; - } - } break; - - default: - // we shouldn't be here - assert(false); - break; - } - - return result; -} - - -//----------------------------------------------------------------------------- -/** - * pre-condition: mp != NULL - */ -void android_Player_volumeUpdate(CMediaPlayer* mp) -{ - android::GenericPlayer* avp = mp->mAVPlayer.get(); - if (avp != NULL) { - float volumes[2]; - // MediaPlayer does not currently support EffectSend or MuteSolo - android_player_volumeUpdate(volumes, &mp->mVolume, mp->mNumChannels, 1.0f, NULL); - float leftVol = volumes[0], rightVol = volumes[1]; - avp->setVolume(leftVol, rightVol); - } -} - -//----------------------------------------------------------------------------- -/** - * pre-condition: gp != 0 - */ -XAresult android_Player_setPlayState(const android::sp<android::GenericPlayer> &gp, - SLuint32 playState, - AndroidObjectState* pObjState) -{ - XAresult result = XA_RESULT_SUCCESS; - AndroidObjectState objState = *pObjState; - - switch (playState) { - case SL_PLAYSTATE_STOPPED: { - SL_LOGV("setting AVPlayer to SL_PLAYSTATE_STOPPED"); - gp->stop(); - } - break; - case SL_PLAYSTATE_PAUSED: { - SL_LOGV("setting AVPlayer to SL_PLAYSTATE_PAUSED"); - switch(objState) { - case ANDROID_UNINITIALIZED: - *pObjState = ANDROID_PREPARING; - gp->prepare(); - break; - case ANDROID_PREPARING: - break; - case ANDROID_READY: - gp->pause(); - break; - default: - SL_LOGE("Android object in invalid state"); - break; - } - } - break; - case SL_PLAYSTATE_PLAYING: { - SL_LOGV("setting AVPlayer to SL_PLAYSTATE_PLAYING"); - switch(objState) { - case ANDROID_UNINITIALIZED: - *pObjState = ANDROID_PREPARING; - gp->prepare(); - // intended fall through - case ANDROID_PREPARING: - // intended fall through - case ANDROID_READY: - gp->play(); - break; - default: - SL_LOGE("Android object in invalid state"); - break; - } - } - break; - default: - // checked by caller, should not happen - break; - } - - return result; -} - - -/** - * pre-condition: mp != NULL - */ -XAresult android_Player_seek(CMediaPlayer *mp, SLmillisecond posMsec) { - XAresult result = XA_RESULT_SUCCESS; - switch (mp->mAndroidObjType) { - case AUDIOVIDEOPLAYER_FROM_URIFD: - if (mp->mAVPlayer !=0) { - mp->mAVPlayer->seek(posMsec); - } - break; - case AUDIOVIDEOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE: // intended fall-through - default: { - result = XA_RESULT_FEATURE_UNSUPPORTED; - } - } - return result; -} - - -/** - * pre-condition: mp != NULL - */ -XAresult android_Player_loop(CMediaPlayer *mp, SLboolean loopEnable) { - XAresult result = XA_RESULT_SUCCESS; - switch (mp->mAndroidObjType) { - case AUDIOVIDEOPLAYER_FROM_URIFD: - if (mp->mAVPlayer !=0) { - mp->mAVPlayer->loop(loopEnable); - } - break; - case AUDIOVIDEOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE: // intended fall-through - default: { - result = XA_RESULT_FEATURE_UNSUPPORTED; - } - } - return result; -} - - -//----------------------------------------------------------------------------- -void android_Player_androidBufferQueue_clear_l(CMediaPlayer *mp) { - if ((mp->mAndroidObjType == AUDIOVIDEOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE) - && (mp->mAVPlayer != 0)) { - android::StreamPlayer* splr = static_cast<android::StreamPlayer*>(mp->mAVPlayer.get()); - splr->appClear_l(); - } -} - - -void android_Player_androidBufferQueue_onRefilled_l(CMediaPlayer *mp) { - if ((mp->mAndroidObjType == AUDIOVIDEOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE) - && (mp->mAVPlayer != 0)) { - android::StreamPlayer* splr = static_cast<android::StreamPlayer*>(mp->mAVPlayer.get()); - splr->queueRefilled(); - } -} - - -/* - * pre-conditions: - * mp != NULL - * mp->mAVPlayer != 0 (player is realized) - * nativeWindow can be NULL, but if NULL it is treated as an error - */ -SLresult android_Player_setNativeWindow(CMediaPlayer *mp, ANativeWindow *nativeWindow) -{ - assert(mp != NULL); - assert(mp->mAVPlayer != 0); - if (nativeWindow == NULL) { - SL_LOGE("ANativeWindow is NULL"); - return SL_RESULT_PARAMETER_INVALID; - } - SLresult result; - int err; - int value; - // this could crash if app passes in a bad parameter, but that's OK - err = (*nativeWindow->query)(nativeWindow, NATIVE_WINDOW_CONCRETE_TYPE, &value); - if (0 != err) { - SL_LOGE("Query NATIVE_WINDOW_CONCRETE_TYPE on ANativeWindow * %p failed; " - "errno %d", nativeWindow, err); - result = SL_RESULT_PARAMETER_INVALID; - } else { - switch (value) { - case NATIVE_WINDOW_SURFACE: { // Surface - SL_LOGV("Displaying on ANativeWindow of type NATIVE_WINDOW_SURFACE"); - android::sp<android::Surface> nativeSurface( - static_cast<android::Surface *>(nativeWindow)); - mp->mAVPlayer->setVideoSurfaceTexture( - nativeSurface->getSurfaceTexture()); - result = SL_RESULT_SUCCESS; - } break; - case NATIVE_WINDOW_SURFACE_TEXTURE_CLIENT: { // SurfaceTextureClient - SL_LOGV("Displaying on ANativeWindow of type NATIVE_WINDOW_SURFACE_TEXTURE_CLIENT"); - android::sp<android::SurfaceTextureClient> surfaceTextureClient( - static_cast<android::SurfaceTextureClient *>(nativeWindow)); - android::sp<android::ISurfaceTexture> nativeSurfaceTexture( - surfaceTextureClient->getISurfaceTexture()); - mp->mAVPlayer->setVideoSurfaceTexture(nativeSurfaceTexture); - result = SL_RESULT_SUCCESS; - } break; - case NATIVE_WINDOW_FRAMEBUFFER: // FramebufferNativeWindow - // fall through - default: - SL_LOGE("ANativeWindow * %p has unknown or unsupported concrete type %d", - nativeWindow, value); - result = SL_RESULT_PARAMETER_INVALID; - break; - } - } - return result; -} diff --git a/wilhelm/src/android/MediaPlayer_to_android.h b/wilhelm/src/android/MediaPlayer_to_android.h deleted file mode 100644 index 1b491cb8..00000000 --- a/wilhelm/src/android/MediaPlayer_to_android.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * 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. - */ - -#include <system/window.h> - -/************************************************************************************************** - * Player lifecycle - ****************************/ -extern XAresult android_Player_checkSourceSink(CMediaPlayer *mp); - -extern XAresult android_Player_create(CMediaPlayer *mp); - -extern XAresult android_Player_realize(CMediaPlayer *mp, SLboolean async); - -extern XAresult android_Player_destroy(CMediaPlayer *mp); - -extern XAresult android_Player_preDestroy(CMediaPlayer *mp); - - -/************************************************************************************************** - * Configuration - ****************************/ - -/** - * pre-conditions: - * pMediaPlayer != NULL - * pMediaPlayer->mAVPlayer != 0 (player is realized) - * nativeWindow can be NULL, but if NULL it is treated as an error - */ -extern SLresult android_Player_setNativeWindow(CMediaPlayer *pMediaPlayer, - ANativeWindow *nativeWindow); - -/** - * pre-conditions: - * pPlayItf != NULL - * pDurMsec, pPosMsec ! = NULL - * IObjectToObjectID( ((IPlay *) self)->mThis ) == XA_OBJECTID_MEDIAPLAYER - */ -extern XAresult android_Player_getDuration(IPlay *pPlayItf, SLmillisecond *pDurMsec); -extern XAresult android_Player_getPosition(IPlay *pPlayItf, SLmillisecond *pPosMsec); - -/** - * pre-condition: mp != NULL - */ -extern void android_Player_volumeUpdate(CMediaPlayer *mp); -extern void android_Player_usePlayEventMask(CMediaPlayer *mp); - -/************************************************************************************************** - * Playback control and events - ****************************/ -/** - * pre-condition: gp != 0 - */ -extern XAresult android_Player_setPlayState(const android::sp<android::GenericPlayer> &gp, - SLuint32 playState, - AndroidObjectState* pObjState); - -/** - * for all functions below: pre-condition: mp != NULL - */ -extern XAresult android_Player_seek(CMediaPlayer *mp, SLmillisecond posMsec); -extern XAresult android_Player_loop(CMediaPlayer *mp, SLboolean loopEnable); - - - -/************************************************************************************************** - * Buffer Queue events - ****************************/ - -/************************************************************************************************** - * Android Buffer Queue - ****************************/ - -/* must be called with a lock on mp->mThis */ -extern void android_Player_androidBufferQueue_clear_l(CMediaPlayer *mp); -/* must be called with a lock on mp->mThis */ -extern void android_Player_androidBufferQueue_onRefilled_l(CMediaPlayer *mp); diff --git a/wilhelm/src/android/OutputMix_to_android.cpp b/wilhelm/src/android/OutputMix_to_android.cpp deleted file mode 100644 index a7d11ef8..00000000 --- a/wilhelm/src/android/OutputMix_to_android.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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. - */ - -#include "sles_allinclusive.h" -//#include "math.h" -//#include "utils/RefBase.h" - -#include <system/audio.h> - -SLresult android_outputMix_create(COutputMix *om) { - SL_LOGV("Create outputMix=%p", om); - return SL_RESULT_SUCCESS; -} - - -SLresult android_outputMix_realize(COutputMix *om, SLboolean async) { - SLresult result = SL_RESULT_SUCCESS; - SL_LOGV("Realize outputMix=%p", om); - - // initialize effects - // initialize EQ - if (memcmp(SL_IID_EQUALIZER, &om->mEqualizer.mEqDescriptor.type, - sizeof(effect_uuid_t)) == 0) { - android_eq_init(AUDIO_SESSION_OUTPUT_MIX /*sessionId*/, &om->mEqualizer); - } - // initialize BassBoost - if (memcmp(SL_IID_BASSBOOST, &om->mBassBoost.mBassBoostDescriptor.type, - sizeof(effect_uuid_t)) == 0) { - android_bb_init(AUDIO_SESSION_OUTPUT_MIX /*sessionId*/, &om->mBassBoost); - } - // initialize PresetReverb - if (memcmp(SL_IID_PRESETREVERB, &om->mPresetReverb.mPresetReverbDescriptor.type, - sizeof(effect_uuid_t)) == 0) { - android_prev_init(&om->mPresetReverb); - } - // initialize EnvironmentalReverb - if (memcmp(SL_IID_ENVIRONMENTALREVERB, - &om->mEnvironmentalReverb.mEnvironmentalReverbDescriptor.type, - sizeof(effect_uuid_t)) == 0) { - android_erev_init(&om->mEnvironmentalReverb); - } - // initialize Virtualizer - if (memcmp(SL_IID_VIRTUALIZER, &om->mVirtualizer.mVirtualizerDescriptor.type, - sizeof(effect_uuid_t)) == 0) { - android_virt_init(AUDIO_SESSION_OUTPUT_MIX /*sessionId*/, - &om->mVirtualizer); - } - - return result; -} - - -SLresult android_outputMix_destroy(COutputMix *om) { - SL_LOGV("Destroy outputMix=%p", om); - return SL_RESULT_SUCCESS; -} diff --git a/wilhelm/src/android/OutputMix_to_android.h b/wilhelm/src/android/OutputMix_to_android.h deleted file mode 100644 index d15fd571..00000000 --- a/wilhelm/src/android/OutputMix_to_android.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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. - */ - - -extern SLresult android_outputMix_create(COutputMix *om); - -extern SLresult android_outputMix_realize(COutputMix *om, SLboolean async); - -extern SLresult android_outputMix_destroy(COutputMix *om); diff --git a/wilhelm/src/android/VideoCodec_to_android.cpp b/wilhelm/src/android/VideoCodec_to_android.cpp deleted file mode 100644 index 113bd8c9..00000000 --- a/wilhelm/src/android/VideoCodec_to_android.cpp +++ /dev/null @@ -1,199 +0,0 @@ -/* - * 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. - */ - -#include "sles_allinclusive.h" - -#include <media/IMediaPlayerService.h> -#include <media/stagefright/OMXClient.h> -#include <media/stagefright/OMXCodec.h> -#include <media/IOMX.h> -#include <media/stagefright/MediaDefs.h> - - -namespace android { - -// listed in same order as VideoCodecIds[] in file "../devices.c" with ANDROID defined -static const char *kVideoMimeTypes[] = { - MEDIA_MIMETYPE_VIDEO_MPEG2, - MEDIA_MIMETYPE_VIDEO_H263, - MEDIA_MIMETYPE_VIDEO_MPEG4, - MEDIA_MIMETYPE_VIDEO_AVC, - MEDIA_MIMETYPE_VIDEO_VPX -}; -// must == kMaxVideoDecoders -static const size_t kNbVideoMimeTypes = sizeof(kVideoMimeTypes) / sizeof(kVideoMimeTypes[0]); - -// codec capabilities in the following arrays maps to the mime types defined in kVideoMimeTypes -// CodecCapabilities is from OMXCodec.h -static Vector<CodecCapabilities> VideoDecoderCapabilities[kNbVideoMimeTypes]; -static XAuint32 VideoDecoderNbProfLevel[kNbVideoMimeTypes]; - -static XAuint32 NbSupportedDecoderTypes = 0; - - -XAuint32 convertOpenMaxIlToAl(OMX_U32 ilVideoProfileOrLevel) { - // For video codec profiles and levels, the number of trailing zeroes in OpenMAX IL - // are equal to the matching OpenMAX AL constant value plus 1, for example: - // XA_VIDEOPROFILE_H263_BACKWARDCOMPATIBLE ((XAuint32) 0x00000003) - // matches - // OMX_VIDEO_H263ProfileBackwardCompatible = 0x04 - return (XAuint32) (__builtin_ctz(ilVideoProfileOrLevel) + 1); -} - - -bool android_videoCodec_expose() { - SL_LOGV("android_videoCodec_expose()"); - - sp<IMediaPlayerService> service(IMediaDeathNotifier::getMediaPlayerService()); - if (service == NULL) { - // no need to SL_LOGE; getMediaPlayerService already will have done so - return false; - } - - sp<IOMX> omx(service->getOMX()); - if (omx.get() == NULL) { - ALOGE("android_videoCodec_expose() couldn't access OMX interface"); - return false; - } - - // used to check whether no codecs were found, which is a sign of failure - NbSupportedDecoderTypes = 0; - for (size_t m = 0 ; m < kNbVideoMimeTypes ; m++) { - // QueryCodecs is from OMXCodec.h - if (OK == QueryCodecs(omx, kVideoMimeTypes[m], true /* queryDecoders */, - true /* hwCodecOnly */, &VideoDecoderCapabilities[m])) { - if (VideoDecoderCapabilities[m].empty()) { - VideoDecoderNbProfLevel[m] = 0; - } else { - // get the number of profiles and levels for the first codec implementation - // for a given decoder ID / MIME type - Vector<CodecProfileLevel> &profileLevels = - VideoDecoderCapabilities[m].editItemAt(0).mProfileLevels; -#if 0 // Intentionally disabled example of making modifications to profile / level combinations - if (VideoDecoderIds[m] == XA_VIDEOCODEC_AVC) { - // remove non-core profile / level combinations - for (size_t i = 0, size = profileLevels.size(); i < size; ) { - CodecProfileLevel profileLevel = profileLevels.itemAt(i); - if (profileLevel.mProfile == XA_VIDEOPROFILE_AVC_BASELINE) { - // either skip past this item and don't change vector size - ++i; - } else { - // or remove this item, decrement the vector size, - // and next time through the loop check a different item at same index - profileLevels.removeAt(i); - --size; - } - } - } -#endif - if ((VideoDecoderNbProfLevel[m] = profileLevels.size()) > 0) { - NbSupportedDecoderTypes++; - } else { - VideoDecoderCapabilities[m].clear(); - } - } - } - } - - return (NbSupportedDecoderTypes > 0); -} - - -void android_videoCodec_deinit() { - SL_LOGV("android_videoCodec_deinit()"); - for (size_t m = 0 ; m < kNbVideoMimeTypes ; m++) { - VideoDecoderCapabilities[m].clear(); - } - // not needed - // memset(VideoDecoderNbProfLevel, 0, sizeof(VideoDecoderNbProfLevel)); - // NbSupportedDecoderTypes = 0; -} - - -XAuint32 android_videoCodec_getNbDecoders() { - return NbSupportedDecoderTypes; -} - - -void android_videoCodec_getDecoderIds(XAuint32 nbDecoders, XAuint32 *pDecoderIds) { - XAuint32 *pIds = pDecoderIds; - XAuint32 nbFound = 0; - for (size_t m = 0 ; m < kNbVideoMimeTypes ; m++) { - if (!VideoDecoderCapabilities[m].empty()) { - *pIds = VideoDecoderIds[m]; - pIds++; - nbFound++; - } - // range check: function can be called for fewer codecs than there are - if (nbFound == nbDecoders) { - break; - } - } -} - - -SLresult android_videoCodec_getProfileLevelCombinationNb(XAuint32 decoderId, XAuint32 *pNb) -{ - // translate a decoder ID to an index in the codec table - size_t decoderIndex = 0; - while (decoderIndex < kNbVideoMimeTypes) { - if (decoderId == VideoDecoderIds[decoderIndex]) { - *pNb = VideoDecoderNbProfLevel[decoderIndex]; - return XA_RESULT_SUCCESS; - } - decoderIndex++; - } - - // spec doesn't allow a decoder to report zero profile/level combinations - *pNb = 0; - return XA_RESULT_PARAMETER_INVALID; -} - - -SLresult android_videoCodec_getProfileLevelCombination(XAuint32 decoderId, XAuint32 plIndex, - XAVideoCodecDescriptor *pDescr) -{ - // translate a decoder ID to an index in the codec table - size_t decoderIndex = 0; - while (decoderIndex < kNbVideoMimeTypes) { - if (decoderId == VideoDecoderIds[decoderIndex]) { - // We only look at the first codec implementation for a given decoder ID / MIME type. - // OpenMAX AL doesn't let you expose the capabilities of multiple codec implementations. - if (!(plIndex < VideoDecoderCapabilities[decoderIndex].itemAt(0).mProfileLevels.size())) - { - // asking for invalid profile/level - return XA_RESULT_PARAMETER_INVALID; - } - // set the fields we know about - pDescr->codecId = decoderId; - pDescr->profileSetting = convertOpenMaxIlToAl(VideoDecoderCapabilities[decoderIndex]. - itemAt(0).mProfileLevels.itemAt(plIndex).mProfile); - pDescr->levelSetting = convertOpenMaxIlToAl(VideoDecoderCapabilities[decoderIndex]. - itemAt(0).mProfileLevels.itemAt(plIndex).mLevel); - // initialize the fields we don't know about - pDescr->maxWidth = 0; - pDescr->maxHeight = 0; - pDescr->maxFrameRate = 0; - pDescr->maxBitRate = 0; - pDescr->rateControlSupported = 0; - break; - } - decoderIndex++; - } - return (decoderIndex < kNbVideoMimeTypes) ? XA_RESULT_SUCCESS : XA_RESULT_PARAMETER_INVALID; -} - -} // namespace android diff --git a/wilhelm/src/android/VideoCodec_to_android.h b/wilhelm/src/android/VideoCodec_to_android.h deleted file mode 100644 index 4faa03c1..00000000 --- a/wilhelm/src/android/VideoCodec_to_android.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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. - */ - -namespace android { - -/************************************************************************** - * Important note: the functions below are helper functions for the - * implementation of the XAVideoDecoderCapabilitiesItf interface on - * Android. They are ONLY exposing the "hardware" video decoders - * as dynamically discovered on the platform. A hardware video decoder - * is defined as one where video decoding takes advantage of a hardware- - * specific feature of the platform, such as DSP or particular GPU. - * "Software" decoders, such as the ones available as default implementations - * in the Android tree, as not exposed here, but are rather listed in - * the CDD. - */ - -/* - * Initializes the list of supported video codecs, with their associated profiles and levels - * Return - * false if it failed to list the available codecs, true otherwise - */ -extern bool android_videoCodec_expose(); - -/* - * Frees all resources associated with the listing and query of the available video codecs - */ -extern void android_videoCodec_deinit(); - -/* - * Returns the number of video codecs supported on the platform. - * Returns 0 if android_videoCodec_expose() hasn't been called before (and returned true) - */ -extern XAuint32 android_videoCodec_getNbDecoders(); - -/* - * Retrieve the supported decoder IDs - * Pre-condition - * nbDecoders <= number of decoders - * pDecoderIds != NULL - * android_videoCodec_expose() has been called before (and returned true) - */ -extern void android_videoCodec_getDecoderIds(XAuint32 nbDecoders, XAuint32 *pDecoderIds); - -/* - * Retrieves the number of profile / level combinations for a given codec - * Pre-condition - * pNb != NULL - * android_videoCodec_expose() has been called before (and returned true) - * Return - * SL_RESULT_SUCCESS if the number of combinations was successfully retrieved and at least - * one profile/level is supported (*pNb > 0) - * SL_RESULT_PARAMETER_INVALID otherwise - */ -extern SLresult android_videoCodec_getProfileLevelCombinationNb(XAuint32 decoderId, XAuint32 *pNb); - -/* - * Retrieves the profile / level at index plIndex in the list of profile / level combinations - * supported by the given codec - * Pre-condition - * pDescr != NULL - * android_videoCodec_expose() has been called before (and returned true) - * Post-condition - * pDescr->codecId == decoderId - * Return - * SL_RESULT_SUCCESS if the profile/level was successfully retrieved - * SL_RESULT_PARAMETER_INVALID otherwise: invalid codec or invalid profile/level index - */ -extern SLresult android_videoCodec_getProfileLevelCombination(XAuint32 decoderId, - XAuint32 plIndex, XAVideoCodecDescriptor *pDescr); - -}; // namespace android diff --git a/wilhelm/src/android/android_AudioSfDecoder.cpp b/wilhelm/src/android/android_AudioSfDecoder.cpp deleted file mode 100644 index 1a50ccb5..00000000 --- a/wilhelm/src/android/android_AudioSfDecoder.cpp +++ /dev/null @@ -1,807 +0,0 @@ -/* - * 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. - */ - -//#define USE_LOG SLAndroidLogLevel_Verbose - -#include "sles_allinclusive.h" -#include "android/android_AudioSfDecoder.h" - -#include <binder/IServiceManager.h> -#include <media/stagefright/foundation/ADebug.h> - - -#define SIZE_CACHED_HIGH_BYTES 1000000 -#define SIZE_CACHED_MED_BYTES 700000 -#define SIZE_CACHED_LOW_BYTES 400000 - -namespace android { - -//-------------------------------------------------------------------------------------------------- -AudioSfDecoder::AudioSfDecoder(const AudioPlayback_Parameters* params) : GenericPlayer(params), - mDataSource(0), - mAudioSource(0), - mAudioSourceStarted(false), - mBitrate(-1), - mDurationUsec(ANDROID_UNKNOWN_TIME), - mDecodeBuffer(NULL), - mSeekTimeMsec(0), - // play event logic depends on the initial time being zero not ANDROID_UNKNOWN_TIME - mLastDecodedPositionUs(0) -{ - SL_LOGD("AudioSfDecoder::AudioSfDecoder()"); -} - - -AudioSfDecoder::~AudioSfDecoder() { - SL_LOGD("AudioSfDecoder::~AudioSfDecoder()"); -} - - -void AudioSfDecoder::preDestroy() { - GenericPlayer::preDestroy(); - SL_LOGD("AudioSfDecoder::preDestroy()"); - { - Mutex::Autolock _l(mBufferSourceLock); - - if (NULL != mDecodeBuffer) { - mDecodeBuffer->release(); - mDecodeBuffer = NULL; - } - - if ((mAudioSource != 0) && mAudioSourceStarted) { - mAudioSource->stop(); - mAudioSourceStarted = false; - } - } -} - - -//-------------------------------------------------- -void AudioSfDecoder::play() { - SL_LOGD("AudioSfDecoder::play"); - - GenericPlayer::play(); - (new AMessage(kWhatDecode, id()))->post(); -} - - -void AudioSfDecoder::getPositionMsec(int* msec) { - int64_t timeUsec = getPositionUsec(); - if (timeUsec == ANDROID_UNKNOWN_TIME) { - *msec = ANDROID_UNKNOWN_TIME; - } else { - *msec = timeUsec / 1000; - } -} - - -//-------------------------------------------------- -uint32_t AudioSfDecoder::getPcmFormatKeyCount() const { - return NB_PCMMETADATA_KEYS; -} - - -//-------------------------------------------------- -bool AudioSfDecoder::getPcmFormatKeySize(uint32_t index, uint32_t* pKeySize) { - if (index >= NB_PCMMETADATA_KEYS) { - return false; - } else { - *pKeySize = strlen(kPcmDecodeMetadataKeys[index]) +1; - return true; - } -} - - -//-------------------------------------------------- -bool AudioSfDecoder::getPcmFormatKeyName(uint32_t index, uint32_t keySize, char* keyName) { - uint32_t actualKeySize; - if (!getPcmFormatKeySize(index, &actualKeySize)) { - return false; - } - if (keySize < actualKeySize) { - return false; - } - strncpy(keyName, kPcmDecodeMetadataKeys[index], actualKeySize); - return true; -} - - -//-------------------------------------------------- -bool AudioSfDecoder::getPcmFormatValueSize(uint32_t index, uint32_t* pValueSize) { - if (index >= NB_PCMMETADATA_KEYS) { - *pValueSize = 0; - return false; - } else { - *pValueSize = sizeof(uint32_t); - return true; - } -} - - -//-------------------------------------------------- -bool AudioSfDecoder::getPcmFormatKeyValue(uint32_t index, uint32_t size, uint32_t* pValue) { - uint32_t valueSize = 0; - if (!getPcmFormatValueSize(index, &valueSize)) { - return false; - } else if (size != valueSize) { - // this ensures we are accessing mPcmFormatValues with a valid size for that index - SL_LOGE("Error retrieving metadata value at index %d: using size of %d, should be %d", - index, size, valueSize); - return false; - } else { - android::Mutex::Autolock autoLock(mPcmFormatLock); - *pValue = mPcmFormatValues[index]; - return true; - } -} - - -//-------------------------------------------------- -// Event handlers -// it is strictly verboten to call those methods outside of the event loop - -// Initializes the data and audio sources, and update the PCM format info -// post-condition: upon successful initialization based on the player data locator -// GenericPlayer::onPrepare() was called -// mDataSource != 0 -// mAudioSource != 0 -// mAudioSourceStarted == true -// All error returns from this method are via notifyPrepared(status) followed by "return". -void AudioSfDecoder::onPrepare() { - SL_LOGD("AudioSfDecoder::onPrepare()"); - Mutex::Autolock _l(mBufferSourceLock); - - { - android::Mutex::Autolock autoLock(mPcmFormatLock); - // Initialize the PCM format info with the known parameters before the start of the decode - mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_BITSPERSAMPLE] = SL_PCMSAMPLEFORMAT_FIXED_16; - mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_CONTAINERSIZE] = 16; - mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_ENDIANNESS] = SL_BYTEORDER_LITTLEENDIAN; - // initialization with the default values: they will be replaced by the actual values - // once the decoder has figured them out - mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_NUMCHANNELS] = UNKNOWN_NUMCHANNELS; - mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_SAMPLERATE] = UNKNOWN_SAMPLERATE; - mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_CHANNELMASK] = UNKNOWN_CHANNELMASK; - } - - //--------------------------------- - // Instantiate and initialize the data source for the decoder - sp<DataSource> dataSource; - - switch (mDataLocatorType) { - - case kDataLocatorNone: - SL_LOGE("AudioSfDecoder::onPrepare: no data locator set"); - notifyPrepared(MEDIA_ERROR_BASE); - return; - - case kDataLocatorUri: - dataSource = DataSource::CreateFromURI(mDataLocator.uriRef); - if (dataSource == NULL) { - SL_LOGE("AudioSfDecoder::onPrepare(): Error opening %s", mDataLocator.uriRef); - notifyPrepared(MEDIA_ERROR_BASE); - return; - } - break; - - case kDataLocatorFd: - { - // As FileSource unconditionally takes ownership of the fd and closes it, then - // we have to make a dup for FileSource if the app wants to keep ownership itself - int fd = mDataLocator.fdi.fd; - if (mDataLocator.fdi.mCloseAfterUse) { - mDataLocator.fdi.mCloseAfterUse = false; - } else { - fd = ::dup(fd); - } - dataSource = new FileSource(fd, mDataLocator.fdi.offset, mDataLocator.fdi.length); - status_t err = dataSource->initCheck(); - if (err != OK) { - notifyPrepared(err); - return; - } - break; - } - - // AndroidBufferQueue data source is handled by a subclass, - // which does not call up to this method. Hence, the missing case. - default: - TRESPASS(); - } - - //--------------------------------- - // Instantiate and initialize the decoder attached to the data source - sp<MediaExtractor> extractor = MediaExtractor::Create(dataSource); - if (extractor == NULL) { - SL_LOGE("AudioSfDecoder::onPrepare: Could not instantiate extractor."); - notifyPrepared(ERROR_UNSUPPORTED); - return; - } - - ssize_t audioTrackIndex = -1; - bool isRawAudio = false; - for (size_t i = 0; i < extractor->countTracks(); ++i) { - sp<MetaData> meta = extractor->getTrackMetaData(i); - - const char *mime; - CHECK(meta->findCString(kKeyMIMEType, &mime)); - - if (!strncasecmp("audio/", mime, 6)) { - if (isSupportedCodec(mime)) { - audioTrackIndex = i; - - if (!strcasecmp(MEDIA_MIMETYPE_AUDIO_RAW, mime)) { - isRawAudio = true; - } - break; - } - } - } - - if (audioTrackIndex < 0) { - SL_LOGE("AudioSfDecoder::onPrepare: Could not find a supported audio track."); - notifyPrepared(ERROR_UNSUPPORTED); - return; - } - - sp<MediaSource> source = extractor->getTrack(audioTrackIndex); - sp<MetaData> meta = source->getFormat(); - - // we can't trust the OMXCodec (if there is one) to issue a INFO_FORMAT_CHANGED so we want - // to have some meaningful values as soon as possible. - int32_t channelCount; - bool hasChannelCount = meta->findInt32(kKeyChannelCount, &channelCount); - int32_t sr; - bool hasSampleRate = meta->findInt32(kKeySampleRate, &sr); - - // first compute the duration - off64_t size; - int64_t durationUs; - int32_t durationMsec; - if (dataSource->getSize(&size) == OK - && meta->findInt64(kKeyDuration, &durationUs)) { - if (durationUs != 0) { - mBitrate = size * 8000000ll / durationUs; // in bits/sec - } else { - mBitrate = -1; - } - mDurationUsec = durationUs; - durationMsec = durationUs / 1000; - } else { - mBitrate = -1; - mDurationUsec = ANDROID_UNKNOWN_TIME; - durationMsec = ANDROID_UNKNOWN_TIME; - } - - // then assign the duration under the settings lock - { - Mutex::Autolock _l(mSettingsLock); - mDurationMsec = durationMsec; - } - - // the audio content is not raw PCM, so we need a decoder - if (!isRawAudio) { - OMXClient client; - CHECK_EQ(client.connect(), (status_t)OK); - - source = OMXCodec::Create( - client.interface(), meta, false /* createEncoder */, - source); - - if (source == NULL) { - SL_LOGE("AudioSfDecoder::onPrepare: Could not instantiate decoder."); - notifyPrepared(ERROR_UNSUPPORTED); - return; - } - - meta = source->getFormat(); - } - - - if (source->start() != OK) { - SL_LOGE("AudioSfDecoder::onPrepare: Failed to start source/decoder."); - notifyPrepared(MEDIA_ERROR_BASE); - return; - } - - //--------------------------------- - // The data source, and audio source (a decoder if required) are ready to be used - mDataSource = dataSource; - mAudioSource = source; - mAudioSourceStarted = true; - - if (!hasChannelCount) { - CHECK(meta->findInt32(kKeyChannelCount, &channelCount)); - } - - if (!hasSampleRate) { - CHECK(meta->findInt32(kKeySampleRate, &sr)); - } - // FIXME add code below once channel mask support is in, currently initialized to default - // value computed from the channel count - // if (!hasChannelMask) { - // CHECK(meta->findInt32(kKeyChannelMask, &channelMask)); - // } - - if (!wantPrefetch()) { - SL_LOGV("AudioSfDecoder::onPrepare: no need to prefetch"); - // doesn't need prefetching, notify good to go - mCacheStatus = kStatusHigh; - mCacheFill = 1000; - notifyStatus(); - notifyCacheFill(); - } - - { - android::Mutex::Autolock autoLock(mPcmFormatLock); - mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_SAMPLERATE] = sr; - mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_NUMCHANNELS] = channelCount; - mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_CHANNELMASK] = - channelCountToMask(channelCount); - } - - // at this point we have enough information about the source to create the sink that - // will consume the data - createAudioSink(); - - // signal successful completion of prepare - mStateFlags |= kFlagPrepared; - - GenericPlayer::onPrepare(); - SL_LOGD("AudioSfDecoder::onPrepare() done, mStateFlags=0x%x", mStateFlags); -} - - -void AudioSfDecoder::onPause() { - SL_LOGV("AudioSfDecoder::onPause()"); - GenericPlayer::onPause(); - pauseAudioSink(); -} - - -void AudioSfDecoder::onPlay() { - SL_LOGV("AudioSfDecoder::onPlay()"); - GenericPlayer::onPlay(); - startAudioSink(); -} - - -void AudioSfDecoder::onSeek(const sp<AMessage> &msg) { - SL_LOGV("AudioSfDecoder::onSeek"); - int64_t timeMsec; - CHECK(msg->findInt64(WHATPARAM_SEEK_SEEKTIME_MS, &timeMsec)); - - Mutex::Autolock _l(mTimeLock); - mStateFlags |= kFlagSeeking; - mSeekTimeMsec = timeMsec; - // don't set mLastDecodedPositionUs to ANDROID_UNKNOWN_TIME; getPositionUsec - // ignores mLastDecodedPositionUs while seeking, and substitutes the seek goal instead - - // nop for now - GenericPlayer::onSeek(msg); -} - - -void AudioSfDecoder::onLoop(const sp<AMessage> &msg) { - SL_LOGV("AudioSfDecoder::onLoop"); - int32_t loop; - CHECK(msg->findInt32(WHATPARAM_LOOP_LOOPING, &loop)); - - if (loop) { - //SL_LOGV("AudioSfDecoder::onLoop start looping"); - mStateFlags |= kFlagLooping; - } else { - //SL_LOGV("AudioSfDecoder::onLoop stop looping"); - mStateFlags &= ~kFlagLooping; - } - - // nop for now - GenericPlayer::onLoop(msg); -} - - -void AudioSfDecoder::onCheckCache(const sp<AMessage> &msg) { - //SL_LOGV("AudioSfDecoder::onCheckCache"); - bool eos; - CacheStatus_t status = getCacheRemaining(&eos); - - if (eos || status == kStatusHigh - || ((mStateFlags & kFlagPreparing) && (status >= kStatusEnough))) { - if (mStateFlags & kFlagPlaying) { - startAudioSink(); - } - mStateFlags &= ~kFlagBuffering; - - SL_LOGV("AudioSfDecoder::onCheckCache: buffering done."); - - if (mStateFlags & kFlagPreparing) { - //SL_LOGV("AudioSfDecoder::onCheckCache: preparation done."); - mStateFlags &= ~kFlagPreparing; - } - - if (mStateFlags & kFlagPlaying) { - (new AMessage(kWhatDecode, id()))->post(); - } - return; - } - - msg->post(100000); -} - - -void AudioSfDecoder::onDecode() { - SL_LOGV("AudioSfDecoder::onDecode"); - - //-------------------------------- Need to buffer some more before decoding? - bool eos; - if (mDataSource == 0) { - // application set play state to paused which failed, then set play state to playing - return; - } - - if (wantPrefetch() - && (getCacheRemaining(&eos) == kStatusLow) - && !eos) { - SL_LOGV("buffering more."); - - if (mStateFlags & kFlagPlaying) { - pauseAudioSink(); - } - mStateFlags |= kFlagBuffering; - (new AMessage(kWhatCheckCache, id()))->post(100000); - return; - } - - if (!(mStateFlags & (kFlagPlaying | kFlagBuffering | kFlagPreparing))) { - // don't decode if we're not buffering, prefetching or playing - //SL_LOGV("don't decode: not buffering, prefetching or playing"); - return; - } - - //-------------------------------- Decode - status_t err; - MediaSource::ReadOptions readOptions; - if (mStateFlags & kFlagSeeking) { - assert(mSeekTimeMsec != ANDROID_UNKNOWN_TIME); - readOptions.setSeekTo(mSeekTimeMsec * 1000); - } - - int64_t timeUsec = ANDROID_UNKNOWN_TIME; - { - Mutex::Autolock _l(mBufferSourceLock); - - if (NULL != mDecodeBuffer) { - // the current decoded buffer hasn't been rendered, drop it - mDecodeBuffer->release(); - mDecodeBuffer = NULL; - } - if (!mAudioSourceStarted) { - return; - } - err = mAudioSource->read(&mDecodeBuffer, &readOptions); - if (err == OK) { - // FIXME workaround apparent bug in AAC decoder: kKeyTime is 3 frames old if length is 0 - if (mDecodeBuffer->range_length() == 0) { - timeUsec = ANDROID_UNKNOWN_TIME; - } else { - CHECK(mDecodeBuffer->meta_data()->findInt64(kKeyTime, &timeUsec)); - } - } else { - // errors are handled below - } - } - - { - Mutex::Autolock _l(mTimeLock); - if (mStateFlags & kFlagSeeking) { - mStateFlags &= ~kFlagSeeking; - mSeekTimeMsec = ANDROID_UNKNOWN_TIME; - } - if (timeUsec != ANDROID_UNKNOWN_TIME) { - // Note that though we've decoded this position, we haven't rendered it yet. - // So a GetPosition called after this point will observe the advanced position, - // even though the PCM may not have been supplied to the sink. That's OK as - // we don't claim to provide AAC frame-accurate (let alone sample-accurate) GetPosition. - mLastDecodedPositionUs = timeUsec; - } - } - - //-------------------------------- Handle return of decode - if (err != OK) { - bool continueDecoding = false; - switch(err) { - case ERROR_END_OF_STREAM: - if (0 < mDurationUsec) { - Mutex::Autolock _l(mTimeLock); - mLastDecodedPositionUs = mDurationUsec; - } - // handle notification and looping at end of stream - if (mStateFlags & kFlagPlaying) { - notify(PLAYEREVENT_ENDOFSTREAM, 1, true /*async*/); - } - if (mStateFlags & kFlagLooping) { - seek(0); - // kick-off decoding again - continueDecoding = true; - } - break; - case INFO_FORMAT_CHANGED: - SL_LOGD("MediaSource::read encountered INFO_FORMAT_CHANGED"); - // reconfigure output - { - Mutex::Autolock _l(mBufferSourceLock); - hasNewDecodeParams(); - } - continueDecoding = true; - break; - case INFO_DISCONTINUITY: - SL_LOGD("MediaSource::read encountered INFO_DISCONTINUITY"); - continueDecoding = true; - break; - default: - SL_LOGE("MediaSource::read returned error %d", err); - break; - } - if (continueDecoding) { - if (NULL == mDecodeBuffer) { - (new AMessage(kWhatDecode, id()))->post(); - return; - } - } else { - return; - } - } - - //-------------------------------- Render - sp<AMessage> msg = new AMessage(kWhatRender, id()); - msg->post(); - -} - - -void AudioSfDecoder::onMessageReceived(const sp<AMessage> &msg) { - switch (msg->what()) { - case kWhatDecode: - onDecode(); - break; - - case kWhatRender: - onRender(); - break; - - case kWhatCheckCache: - onCheckCache(msg); - break; - - default: - GenericPlayer::onMessageReceived(msg); - break; - } -} - -//-------------------------------------------------- -// Prepared state, prefetch status notifications -void AudioSfDecoder::notifyPrepared(status_t prepareRes) { - assert(!(mStateFlags & (kFlagPrepared | kFlagPreparedUnsuccessfully))); - if (NO_ERROR == prepareRes) { - // The "then" fork is not currently used, but is kept here to make it easier - // to replace by a new signalPrepareCompletion(status) if we re-visit this later. - mStateFlags |= kFlagPrepared; - } else { - mStateFlags |= kFlagPreparedUnsuccessfully; - } - // Do not call the superclass onPrepare to notify, because it uses a default error - // status code but we can provide a more specific one. - // GenericPlayer::onPrepare(); - notify(PLAYEREVENT_PREPARED, (int32_t)prepareRes, true /*async*/); - SL_LOGD("AudioSfDecoder::onPrepare() done, mStateFlags=0x%x", mStateFlags); -} - - -void AudioSfDecoder::onNotify(const sp<AMessage> &msg) { - notif_cbf_t notifyClient; - void* notifyUser; - { - android::Mutex::Autolock autoLock(mNotifyClientLock); - if (NULL == mNotifyClient) { - return; - } else { - notifyClient = mNotifyClient; - notifyUser = mNotifyUser; - } - } - int32_t val; - if (msg->findInt32(PLAYEREVENT_PREFETCHSTATUSCHANGE, &val)) { - SL_LOGV("\tASfPlayer notifying %s = %d", PLAYEREVENT_PREFETCHSTATUSCHANGE, val); - notifyClient(kEventPrefetchStatusChange, val, 0, notifyUser); - } - else if (msg->findInt32(PLAYEREVENT_PREFETCHFILLLEVELUPDATE, &val)) { - SL_LOGV("\tASfPlayer notifying %s = %d", PLAYEREVENT_PREFETCHFILLLEVELUPDATE, val); - notifyClient(kEventPrefetchFillLevelUpdate, val, 0, notifyUser); - } - else if (msg->findInt32(PLAYEREVENT_ENDOFSTREAM, &val)) { - SL_LOGV("\tASfPlayer notifying %s = %d", PLAYEREVENT_ENDOFSTREAM, val); - notifyClient(kEventEndOfStream, val, 0, notifyUser); - } - else { - GenericPlayer::onNotify(msg); - } -} - - -//-------------------------------------------------- -// Private utility functions - -bool AudioSfDecoder::wantPrefetch() { - if (mDataSource != 0) { - return (mDataSource->flags() & DataSource::kWantsPrefetching); - } else { - // happens if an improper data locator was passed, if the media extractor couldn't be - // initialized, if there is no audio track in the media, if the OMX decoder couldn't be - // instantiated, if the source couldn't be opened, or if the MediaSource - // couldn't be started - SL_LOGV("AudioSfDecoder::wantPrefetch() tries to access NULL mDataSource"); - return false; - } -} - - -int64_t AudioSfDecoder::getPositionUsec() { - Mutex::Autolock _l(mTimeLock); - if (mStateFlags & kFlagSeeking) { - return mSeekTimeMsec * 1000; - } else { - return mLastDecodedPositionUs; - } -} - - -CacheStatus_t AudioSfDecoder::getCacheRemaining(bool *eos) { - sp<NuCachedSource2> cachedSource = - static_cast<NuCachedSource2 *>(mDataSource.get()); - - CacheStatus_t oldStatus = mCacheStatus; - - status_t finalStatus; - size_t dataRemaining = cachedSource->approxDataRemaining(&finalStatus); - *eos = (finalStatus != OK); - - CHECK_GE(mBitrate, 0); - - int64_t dataRemainingUs = dataRemaining * 8000000ll / mBitrate; - //SL_LOGV("AudioSfDecoder::getCacheRemaining: approx %.2f secs remaining (eos=%d)", - // dataRemainingUs / 1E6, *eos); - - if (*eos) { - // data is buffered up to the end of the stream, it can't get any better than this - mCacheStatus = kStatusHigh; - mCacheFill = 1000; - - } else { - if (mDurationUsec > 0) { - // known duration: - - // fill level is ratio of how much has been played + how much is - // cached, divided by total duration - int64_t currentPositionUsec = getPositionUsec(); - if (currentPositionUsec == ANDROID_UNKNOWN_TIME) { - // if we don't know where we are, assume the worst for the fill ratio - currentPositionUsec = 0; - } - if (mDurationUsec > 0) { - mCacheFill = (int16_t) ((1000.0 - * (double)(currentPositionUsec + dataRemainingUs) / mDurationUsec)); - } else { - mCacheFill = 0; - } - //SL_LOGV("cacheFill = %d", mCacheFill); - - // cache status is evaluated against duration thresholds - if (dataRemainingUs > DURATION_CACHED_HIGH_MS*1000) { - mCacheStatus = kStatusHigh; - //ALOGV("high"); - } else if (dataRemainingUs > DURATION_CACHED_MED_MS*1000) { - //ALOGV("enough"); - mCacheStatus = kStatusEnough; - } else if (dataRemainingUs < DURATION_CACHED_LOW_MS*1000) { - //ALOGV("low"); - mCacheStatus = kStatusLow; - } else { - mCacheStatus = kStatusIntermediate; - } - - } else { - // unknown duration: - - // cache status is evaluated against cache amount thresholds - // (no duration so we don't have the bitrate either, could be derived from format?) - if (dataRemaining > SIZE_CACHED_HIGH_BYTES) { - mCacheStatus = kStatusHigh; - } else if (dataRemaining > SIZE_CACHED_MED_BYTES) { - mCacheStatus = kStatusEnough; - } else if (dataRemaining < SIZE_CACHED_LOW_BYTES) { - mCacheStatus = kStatusLow; - } else { - mCacheStatus = kStatusIntermediate; - } - } - - } - - if (oldStatus != mCacheStatus) { - notifyStatus(); - } - - if (abs(mCacheFill - mLastNotifiedCacheFill) > mCacheFillNotifThreshold) { - notifyCacheFill(); - } - - return mCacheStatus; -} - - -void AudioSfDecoder::hasNewDecodeParams() { - - if ((mAudioSource != 0) && mAudioSourceStarted) { - sp<MetaData> meta = mAudioSource->getFormat(); - - int32_t channelCount; - CHECK(meta->findInt32(kKeyChannelCount, &channelCount)); - int32_t sr; - CHECK(meta->findInt32(kKeySampleRate, &sr)); - - // FIXME similar to onPrepare() - { - android::Mutex::Autolock autoLock(mPcmFormatLock); - SL_LOGV("format changed: old sr=%d, channels=%d; new sr=%d, channels=%d", - mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_SAMPLERATE], - mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_NUMCHANNELS], - sr, channelCount); - mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_NUMCHANNELS] = channelCount; - mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_SAMPLERATE] = sr; - mPcmFormatValues[ANDROID_KEY_INDEX_PCMFORMAT_CHANNELMASK] = - channelCountToMask(channelCount); - } - // there's no need to do a notify of PLAYEREVENT_CHANNEL_COUNT, - // because the only listener is for volume updates, and decoders don't support that - } - - // alert users of those params - updateAudioSink(); -} - -static const char* const kPlaybackOnlyCodecs[] = { MEDIA_MIMETYPE_AUDIO_AMR_NB, - MEDIA_MIMETYPE_AUDIO_AMR_WB }; -#define NB_PLAYBACK_ONLY_CODECS (sizeof(kPlaybackOnlyCodecs)/sizeof(kPlaybackOnlyCodecs[0])) - -bool AudioSfDecoder::isSupportedCodec(const char* mime) { - bool codecRequiresPermission = false; - for (unsigned int i = 0 ; i < NB_PLAYBACK_ONLY_CODECS ; i++) { - if (!strcasecmp(mime, kPlaybackOnlyCodecs[i])) { - codecRequiresPermission = true; - break; - } - } - if (codecRequiresPermission) { - // verify only the system can decode, for playback only - return checkCallingPermission( - String16("android.permission.ALLOW_ANY_CODEC_FOR_PLAYBACK")); - } else { - return true; - } -} - -} // namespace android diff --git a/wilhelm/src/android/android_AudioSfDecoder.h b/wilhelm/src/android/android_AudioSfDecoder.h deleted file mode 100644 index ae8e7f67..00000000 --- a/wilhelm/src/android/android_AudioSfDecoder.h +++ /dev/null @@ -1,151 +0,0 @@ -/* - * 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 AUDIO_SF_DECODER_H_ -#define AUDIO_SF_DECODER_H_ - -#include <media/stagefright/DataSource.h> -#include <media/stagefright/MediaSource.h> -#include <media/stagefright/FileSource.h> -#include <media/stagefright/MediaDefs.h> -#include <media/stagefright/MediaExtractor.h> -#include <media/stagefright/MetaData.h> -#include <media/stagefright/OMXClient.h> -#include <media/stagefright/OMXCodec.h> -#include "NuCachedSource2.h" -#include "ThrottledSource.h" - -#include "android_GenericPlayer.h" - -//-------------------------------------------------------------------------------------------------- -namespace android { - -// keep in sync with the entries of kPcmDecodeMetadataKeys[] -#define ANDROID_KEY_INDEX_PCMFORMAT_NUMCHANNELS 0 -#define ANDROID_KEY_INDEX_PCMFORMAT_SAMPLERATE 1 -#define ANDROID_KEY_INDEX_PCMFORMAT_BITSPERSAMPLE 2 -#define ANDROID_KEY_INDEX_PCMFORMAT_CONTAINERSIZE 3 -#define ANDROID_KEY_INDEX_PCMFORMAT_CHANNELMASK 4 -#define ANDROID_KEY_INDEX_PCMFORMAT_ENDIANNESS 5 - -// to keep in sync with the ANDROID_KEY_INDEX_PCMFORMAT_* constants in android_AudioSfDecoder.cpp -static const char* const kPcmDecodeMetadataKeys[] = { - ANDROID_KEY_PCMFORMAT_NUMCHANNELS, ANDROID_KEY_PCMFORMAT_SAMPLERATE, - ANDROID_KEY_PCMFORMAT_BITSPERSAMPLE, ANDROID_KEY_PCMFORMAT_CONTAINERSIZE, - ANDROID_KEY_PCMFORMAT_CHANNELMASK, ANDROID_KEY_PCMFORMAT_ENDIANNESS }; -#define NB_PCMMETADATA_KEYS (sizeof(kPcmDecodeMetadataKeys)/sizeof(kPcmDecodeMetadataKeys[0])) - -// abstract base class for AudioToCbRenderer and it's subclasses -class AudioSfDecoder : public GenericPlayer -{ -public: - - AudioSfDecoder(const AudioPlayback_Parameters* params); - virtual ~AudioSfDecoder(); - - virtual void preDestroy(); - - // overridden from GenericPlayer - virtual void play(); - virtual void getPositionMsec(int* msec); //msec != NULL, ANDROID_UNKNOWN_TIME if unknown - - uint32_t getPcmFormatKeyCount() const; - bool getPcmFormatKeySize(uint32_t index, uint32_t* pKeySize); - bool getPcmFormatKeyName(uint32_t index, uint32_t keySize, char* keyName); - bool getPcmFormatValueSize(uint32_t index, uint32_t* pValueSize); - bool getPcmFormatKeyValue(uint32_t index, uint32_t size, uint32_t* pValue); - -protected: - - enum { - kWhatDecode = 'deco', - kWhatRender = 'rend', - kWhatCheckCache = 'cach' - }; - - // Async event handlers (called from the AudioSfDecoder's event loop) - void onDecode(); - void onCheckCache(const sp<AMessage> &msg); - virtual void onRender() = 0; - - // Async event handlers (called from GenericPlayer's event loop) - virtual void onPrepare(); - virtual void onPlay(); - virtual void onPause(); - virtual void onSeek(const sp<AMessage> &msg); - virtual void onLoop(const sp<AMessage> &msg); - - // overridden from GenericPlayer - virtual void onNotify(const sp<AMessage> &msg); - virtual void onMessageReceived(const sp<AMessage> &msg); - - // to be implemented by subclasses of AudioSfDecoder to do something with the audio samples - // (called from GenericPlayer's event loop) - virtual void createAudioSink() = 0; - virtual void updateAudioSink() = 0; // called with mBufferSourceLock held - virtual void startAudioSink() = 0; - virtual void pauseAudioSink() = 0; - - sp<DataSource> mDataSource; // where the raw data comes from - sp<MediaSource> mAudioSource;// the decoder reading from the data source - // used to indicate mAudioSource was successfully started, but wasn't stopped - bool mAudioSourceStarted; - - // negative values indicate invalid value - int64_t mBitrate; // in bits/sec - int64_t mDurationUsec; // ANDROID_UNKNOWN_TIME if unknown - - // buffer passed from decoder to renderer - MediaBuffer *mDecodeBuffer; - - // mutex used to protect the decode buffer, the audio source and its running state - Mutex mBufferSourceLock; - - void notifyPrepared(status_t prepareRes); - - int64_t mSeekTimeMsec; - int64_t mLastDecodedPositionUs; // ANDROID_UNKNOWN_TIME if unknown - // mutex used for seek flag, seek time (mSeekTimeMsec), - // and last decoded position (mLastDecodedPositionUs) - Mutex mTimeLock; - - // informations that can be retrieved in the PCM format queries - // these values are only written in the event loop - uint32_t mPcmFormatValues[NB_PCMMETADATA_KEYS]; - // protects mPcmFormatValues - Mutex mPcmFormatLock; - - virtual bool advancesPositionInRealTime() const { return false; } - -private: - bool wantPrefetch(); - CacheStatus_t getCacheRemaining(bool *eos); - int64_t getPositionUsec(); // ANDROID_UNKNOWN_TIME if unknown - - // convenience function to update internal state when decoding parameters have changed, - // called with a lock on mBufferSourceLock - void hasNewDecodeParams(); - - static bool isSupportedCodec(const char* mime); - -private: - DISALLOW_EVIL_CONSTRUCTORS(AudioSfDecoder); - -}; - -} // namespace android - -#endif // AUDIO_SF_DECODER_H_ diff --git a/wilhelm/src/android/android_AudioToCbRenderer.cpp b/wilhelm/src/android/android_AudioToCbRenderer.cpp deleted file mode 100644 index 779d19f3..00000000 --- a/wilhelm/src/android/android_AudioToCbRenderer.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* - * 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. - */ - -//#define USE_LOG SLAndroidLogLevel_Verbose - -#include "sles_allinclusive.h" -#include "android/android_AudioToCbRenderer.h" - -#include <media/stagefright/foundation/ADebug.h> - -namespace android { - -//-------------------------------------------------------------------------------------------------- -AudioToCbRenderer::AudioToCbRenderer(const AudioPlayback_Parameters* params) : - AudioSfDecoder(params), - mDecodeCbf(NULL), - mDecodeUser(NULL) -{ - SL_LOGD("AudioToCbRenderer::AudioToCbRenderer()"); - -} - - -AudioToCbRenderer::~AudioToCbRenderer() { - SL_LOGD("AudioToCbRenderer::~AudioToCbRenderer()"); - -} - -void AudioToCbRenderer::setDataPushListener(const data_push_cbf_t pushCbf, CAudioPlayer* pushUser) { - mDecodeCbf = pushCbf; - mDecodeUser = pushUser; -} - -//-------------------------------------------------- -// Event handlers - -void AudioToCbRenderer::onRender() { - SL_LOGV("AudioToCbRenderer::onRender"); - - Mutex::Autolock _l(mBufferSourceLock); - - if (NULL == mDecodeBuffer) { - // nothing to render, move along - //SL_LOGV("AudioToCbRenderer::onRender NULL buffer, exiting"); - return; - } - - if (mStateFlags & kFlagPlaying) { - if (NULL != mDecodeCbf) { - size_t full = mDecodeBuffer->range_length(); - size_t consumed = 0; - size_t offset = 0; - while (offset < full) { - consumed = mDecodeCbf( - (const uint8_t *)mDecodeBuffer->data() - + offset + mDecodeBuffer->range_offset(), - mDecodeBuffer->range_length() - offset, - mDecodeUser); - offset += consumed; - //SL_LOGV("consumed=%u, offset=%u, full=%u", consumed, offset, full); - if (consumed == 0) { - // decoded data is not being consumed, skip this buffer - break; - } - } - } - (new AMessage(kWhatDecode, id()))->post(); - } - - mDecodeBuffer->release(); - mDecodeBuffer = NULL; - - updateOneShot(); -} - - -//-------------------------------------------------- -// Audio output -void AudioToCbRenderer::createAudioSink() { - SL_LOGD("AudioToCbRenderer::createAudioSink()"); -} - - -void AudioToCbRenderer::updateAudioSink() { - SL_LOGD("AudioToCbRenderer::updateAudioSink()"); -} - - -void AudioToCbRenderer::startAudioSink() { - SL_LOGD("AudioToCbRenderer::startAudioSink()"); -} - - -void AudioToCbRenderer::pauseAudioSink() { - SL_LOGD("AudioToCbRenderer::pauseAudioSink()"); -} - -} // namespace android diff --git a/wilhelm/src/android/android_AudioToCbRenderer.h b/wilhelm/src/android/android_AudioToCbRenderer.h deleted file mode 100644 index 782e76f3..00000000 --- a/wilhelm/src/android/android_AudioToCbRenderer.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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 AUDIO_TO_CB_RENDERER_H_ -#define AUDIO_TO_CB_RENDERER_H_ - -#include "android/android_AudioSfDecoder.h" - -//-------------------------------------------------------------------------------------------------- -namespace android { - -class AudioToCbRenderer : public AudioSfDecoder -{ -public: - - AudioToCbRenderer(const AudioPlayback_Parameters* params); - virtual ~AudioToCbRenderer(); - - void setDataPushListener(const data_push_cbf_t pushCbf, CAudioPlayer* pushUser); - -protected: - - // Async event handlers (called from GenericPlayer's event loop) - virtual void onRender(); - - // overridden from AudioSfDecoder - virtual void createAudioSink(); - virtual void updateAudioSink(); - virtual void startAudioSink(); - virtual void pauseAudioSink(); - -private: - - data_push_cbf_t mDecodeCbf; - CAudioPlayer* mDecodeUser; - -private: - DISALLOW_EVIL_CONSTRUCTORS(AudioToCbRenderer); - -}; - -} // namespace android - -#endif //AUDIO_TO_CB_RENDERER_H_ diff --git a/wilhelm/src/android/android_Effect.cpp b/wilhelm/src/android/android_Effect.cpp deleted file mode 100644 index a8e69add..00000000 --- a/wilhelm/src/android/android_Effect.cpp +++ /dev/null @@ -1,859 +0,0 @@ -/* - * 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. - */ - - -#include "sles_allinclusive.h" -#include "math.h" -#include "utils/RefBase.h" -#include <audio_effects/effect_bassboost.h> -#include <audio_effects/effect_equalizer.h> -#include <audio_effects/effect_environmentalreverb.h> -#include <audio_effects/effect_presetreverb.h> -#include <audio_effects/effect_virtualizer.h> - -#include <system/audio.h> - -static const int EQUALIZER_PARAM_SIZE_MAX = sizeof(effect_param_t) + 2 * sizeof(int32_t) - + EFFECT_STRING_LEN_MAX; - -static const int BASSBOOST_PARAM_SIZE_MAX = sizeof(effect_param_t) + 2 * sizeof(int32_t); - -static const int VIRTUALIZER_PARAM_SIZE_MAX = sizeof(effect_param_t) + 2 * sizeof(int32_t); - -static const int ENVREVERB_PARAM_SIZE_MAX_SINGLE = sizeof(effect_param_t) + 2 * sizeof(int32_t); - -static const int ENVREVERB_PARAM_SIZE_MAX_ALL = sizeof(effect_param_t) + sizeof(int32_t) - + sizeof(s_reverb_settings); - -static const int PRESETREVERB_PARAM_SIZE_MAX = sizeof(effect_param_t) + 2 * sizeof(int32_t); - -static inline SLuint32 KEY_FROM_GUID(SLInterfaceID pUuid) { - return pUuid->time_low; -} - - -//----------------------------------------------------------------------------- -uint32_t eq_paramSize(int32_t param) { - uint32_t size; - - switch (param) { - case EQ_PARAM_NUM_BANDS: - case EQ_PARAM_LEVEL_RANGE: - case EQ_PARAM_CUR_PRESET: - case EQ_PARAM_GET_NUM_OF_PRESETS: - size = sizeof(int32_t); - break; - case EQ_PARAM_BAND_LEVEL: - case EQ_PARAM_CENTER_FREQ: - case EQ_PARAM_BAND_FREQ_RANGE: - case EQ_PARAM_GET_BAND: - case EQ_PARAM_GET_PRESET_NAME: - size = 2 * sizeof(int32_t); - break; - default: - size = 2 * sizeof(int32_t); - SL_LOGE("Trying to use an unknown EQ parameter %d", param); - break; - } - return size; -} - -uint32_t eq_valueSize(int32_t param) { - uint32_t size; - - switch (param) { - case EQ_PARAM_NUM_BANDS: - case EQ_PARAM_CUR_PRESET: - case EQ_PARAM_GET_NUM_OF_PRESETS: - case EQ_PARAM_BAND_LEVEL: - case EQ_PARAM_GET_BAND: - size = sizeof(int16_t); - break; - case EQ_PARAM_LEVEL_RANGE: - size = 2 * sizeof(int16_t); - break; - case EQ_PARAM_CENTER_FREQ: - size = sizeof(int32_t); - break; - case EQ_PARAM_BAND_FREQ_RANGE: - size = 2 * sizeof(int32_t); - break; - case EQ_PARAM_GET_PRESET_NAME: - size = EFFECT_STRING_LEN_MAX; - break; - default: - size = sizeof(int32_t); - SL_LOGE("Trying to access an unknown EQ parameter %d", param); - break; - } - return size; -} - -//----------------------------------------------------------------------------- -/** - * returns the size in bytes of the value of each bass boost parameter - */ -uint32_t bb_valueSize(int32_t param) { - uint32_t size; - - switch (param) { - case BASSBOOST_PARAM_STRENGTH_SUPPORTED: - size = sizeof(int32_t); - break; - case BASSBOOST_PARAM_STRENGTH: - size = sizeof(int16_t); - break; - default: - size = sizeof(int32_t); - SL_LOGE("Trying to access an unknown BassBoost parameter %d", param); - break; - } - - return size; -} - -//----------------------------------------------------------------------------- -/** - * returns the size in bytes of the value of each virtualizer parameter - */ -uint32_t virt_valueSize(int32_t param) { - uint32_t size; - - switch (param) { - case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED: - size = sizeof(int32_t); - break; - case VIRTUALIZER_PARAM_STRENGTH: - size = sizeof(int16_t); - break; - default: - size = sizeof(int32_t); - SL_LOGE("Trying to access an unknown Virtualizer parameter %d", param); - break; - } - - return size; -} - -//----------------------------------------------------------------------------- -/** - * returns the size in bytes of the value of each environmental reverb parameter - */ -uint32_t erev_valueSize(int32_t param) { - uint32_t size; - - switch (param) { - case REVERB_PARAM_ROOM_LEVEL: - case REVERB_PARAM_ROOM_HF_LEVEL: - case REVERB_PARAM_REFLECTIONS_LEVEL: - case REVERB_PARAM_REVERB_LEVEL: - size = sizeof(int16_t); // millibel - break; - case REVERB_PARAM_DECAY_TIME: - case REVERB_PARAM_REFLECTIONS_DELAY: - case REVERB_PARAM_REVERB_DELAY: - size = sizeof(uint32_t); // milliseconds - break; - case REVERB_PARAM_DECAY_HF_RATIO: - case REVERB_PARAM_DIFFUSION: - case REVERB_PARAM_DENSITY: - size = sizeof(int16_t); // permille - break; - case REVERB_PARAM_PROPERTIES: - size = sizeof(s_reverb_settings); // struct of all reverb properties - break; - default: - size = sizeof(int32_t); - SL_LOGE("Trying to access an unknown Environmental Reverb parameter %d", param); - break; - } - - return size; -} - -//----------------------------------------------------------------------------- -android::status_t android_eq_getParam(android::sp<android::AudioEffect> pFx, - int32_t param, int32_t param2, void *pValue) -{ - android::status_t status; - uint32_t buf32[(EQUALIZER_PARAM_SIZE_MAX - 1) / sizeof(uint32_t) + 1]; - effect_param_t *p = (effect_param_t *)buf32; - - p->psize = eq_paramSize(param); - *(int32_t *)p->data = param; - if (p->psize == 2 * sizeof(int32_t)) { - *((int32_t *)p->data + 1) = param2; - } - p->vsize = eq_valueSize(param); - status = pFx->getParameter(p); - if (android::NO_ERROR == status) { - status = p->status; - if (android::NO_ERROR == status) { - memcpy(pValue, p->data + p->psize, p->vsize); - } - } - - return status; - } - - -//----------------------------------------------------------------------------- -android::status_t android_eq_setParam(android::sp<android::AudioEffect> pFx, - int32_t param, int32_t param2, void *pValue) -{ - android::status_t status; - uint32_t buf32[(EQUALIZER_PARAM_SIZE_MAX - 1) / sizeof(uint32_t) + 1]; - effect_param_t *p = (effect_param_t *)buf32; - - p->psize = eq_paramSize(param); - *(int32_t *)p->data = param; - if (p->psize == 2 * sizeof(int32_t)) { - *((int32_t *)p->data + 1) = param2; - } - p->vsize = eq_valueSize(param); - memcpy(p->data + p->psize, pValue, p->vsize); - status = pFx->setParameter(p); - if (android::NO_ERROR == status) { - status = p->status; - } - - return status; -} - -//----------------------------------------------------------------------------- -android::status_t android_bb_setParam(android::sp<android::AudioEffect> pFx, - int32_t param, void *pValue) { - - return android_fx_setParam(pFx, param, BASSBOOST_PARAM_SIZE_MAX, - pValue, bb_valueSize(param)); -} - -//----------------------------------------------------------------------------- -android::status_t android_bb_getParam(android::sp<android::AudioEffect> pFx, - int32_t param, void *pValue) { - - return android_fx_getParam(pFx, param, BASSBOOST_PARAM_SIZE_MAX, - pValue, bb_valueSize(param)); -} - -//----------------------------------------------------------------------------- -void android_bb_init(int sessionId, IBassBoost* ibb) { - SL_LOGV("session %d", sessionId); - - if (!android_fx_initEffectObj(sessionId, ibb->mBassBoostEffect, - &ibb->mBassBoostDescriptor.type)) - { - SL_LOGE("BassBoost effect initialization failed"); - return; - } - - // initialize strength - int16_t strength; - if (android::NO_ERROR == android_bb_getParam(ibb->mBassBoostEffect, - BASSBOOST_PARAM_STRENGTH, &strength)) { - ibb->mStrength = (SLpermille) strength; - } -} - - -//----------------------------------------------------------------------------- -void android_eq_init(int sessionId, IEqualizer* ieq) { - SL_LOGV("android_eq_init on session %d", sessionId); - - if (!android_fx_initEffectObj(sessionId, ieq->mEqEffect, &ieq->mEqDescriptor.type)) { - SL_LOGE("Equalizer effect initialization failed"); - return; - } - - // initialize number of bands, band level range, and number of presets - uint16_t num = 0; - if (android::NO_ERROR == android_eq_getParam(ieq->mEqEffect, EQ_PARAM_NUM_BANDS, 0, &num)) { - ieq->mNumBands = num; - } - int16_t range[2] = {0, 0}; - if (android::NO_ERROR == android_eq_getParam(ieq->mEqEffect, EQ_PARAM_LEVEL_RANGE, 0, range)) { - ieq->mBandLevelRangeMin = range[0]; - ieq->mBandLevelRangeMax = range[1]; - } - - SL_LOGV(" EQ init: num bands = %u, band range=[%d %d]mB", num, range[0], range[1]); - - // FIXME don't store presets names, they can be queried each time they're needed - // initialize preset number and names, store in IEngine - uint16_t numPresets = 0; - if (android::NO_ERROR == android_eq_getParam(ieq->mEqEffect, - EQ_PARAM_GET_NUM_OF_PRESETS, 0, &numPresets)) { - ieq->mThis->mEngine->mEqNumPresets = numPresets; - ieq->mNumPresets = numPresets; - } - - object_lock_exclusive(&ieq->mThis->mEngine->mObject); - char name[EFFECT_STRING_LEN_MAX]; - if ((0 < numPresets) && (NULL == ieq->mThis->mEngine->mEqPresetNames)) { - ieq->mThis->mEngine->mEqPresetNames = (char **)new char *[numPresets]; - for(uint32_t i = 0 ; i < numPresets ; i++) { - if (android::NO_ERROR == android_eq_getParam(ieq->mEqEffect, - EQ_PARAM_GET_PRESET_NAME, i, name)) { - ieq->mThis->mEngine->mEqPresetNames[i] = new char[strlen(name) + 1]; - strcpy(ieq->mThis->mEngine->mEqPresetNames[i], name); - SL_LOGV(" EQ init: presets = %u is %s", i, ieq->mThis->mEngine->mEqPresetNames[i]); - } - } - } - object_unlock_exclusive(&ieq->mThis->mEngine->mObject); - -} - - -//----------------------------------------------------------------------------- -void android_virt_init(int sessionId, IVirtualizer* ivi) { - SL_LOGV("android_virt_init on session %d", sessionId); - - if (!android_fx_initEffectObj(sessionId, ivi->mVirtualizerEffect, - &ivi->mVirtualizerDescriptor.type)) { - SL_LOGE("Virtualizer effect initialization failed"); - return; - } - - // initialize strength - int16_t strength; - if (android::NO_ERROR == android_virt_getParam(ivi->mVirtualizerEffect, - VIRTUALIZER_PARAM_STRENGTH, &strength)) { - ivi->mStrength = (SLpermille) strength; - } -} - -//----------------------------------------------------------------------------- -android::status_t android_virt_setParam(android::sp<android::AudioEffect> pFx, - int32_t param, void *pValue) { - - return android_fx_setParam(pFx, param, VIRTUALIZER_PARAM_SIZE_MAX, - pValue, virt_valueSize(param)); -} - -//----------------------------------------------------------------------------- -android::status_t android_virt_getParam(android::sp<android::AudioEffect> pFx, - int32_t param, void *pValue) { - - return android_fx_getParam(pFx, param, VIRTUALIZER_PARAM_SIZE_MAX, - pValue, virt_valueSize(param)); -} - - -//----------------------------------------------------------------------------- -void android_prev_init(IPresetReverb* ipr) { - SL_LOGV("session is implicitly %d (aux effect)", AUDIO_SESSION_OUTPUT_MIX); - - if (!android_fx_initEffectObj(AUDIO_SESSION_OUTPUT_MIX /*sessionId*/, - ipr->mPresetReverbEffect, &ipr->mPresetReverbDescriptor.type)) { - SL_LOGE("PresetReverb effect initialization failed"); - return; - } - - // initialize preset - uint16_t preset; - if (android::NO_ERROR == android_prev_getPreset(ipr->mPresetReverbEffect, &preset)) { - ipr->mPreset = preset; - // enable the effect if it has a preset loaded - ipr->mPresetReverbEffect->setEnabled(SL_REVERBPRESET_NONE != preset); - } -} - -//----------------------------------------------------------------------------- -android::status_t android_prev_setPreset(android::sp<android::AudioEffect> pFx, uint16_t preset) { - android::status_t status = android_fx_setParam(pFx, REVERB_PARAM_PRESET, - PRESETREVERB_PARAM_SIZE_MAX, &preset, sizeof(uint16_t)); - // enable the effect if the preset is different from SL_REVERBPRESET_NONE - pFx->setEnabled(SL_REVERBPRESET_NONE != preset); - return status; -} - -//----------------------------------------------------------------------------- -android::status_t android_prev_getPreset(android::sp<android::AudioEffect> pFx, uint16_t* preset) { - return android_fx_getParam(pFx, REVERB_PARAM_PRESET, PRESETREVERB_PARAM_SIZE_MAX, preset, - sizeof(uint16_t)); -} - - -//----------------------------------------------------------------------------- -void android_erev_init(IEnvironmentalReverb* ier) { - SL_LOGV("session is implicitly %d (aux effect)", AUDIO_SESSION_OUTPUT_MIX); - - if (!android_fx_initEffectObj(AUDIO_SESSION_OUTPUT_MIX /*sessionId*/, - ier->mEnvironmentalReverbEffect, &ier->mEnvironmentalReverbDescriptor.type)) { - SL_LOGE("EnvironmentalReverb effect initialization failed"); - return; - } - - // enable env reverb: other SL ES effects have an explicit SetEnabled() function, and the - // preset reverb state depends on the selected preset. - ier->mEnvironmentalReverbEffect->setEnabled(true); - - // initialize reverb properties - SLEnvironmentalReverbSettings properties; - if (android::NO_ERROR == android_erev_getParam(ier->mEnvironmentalReverbEffect, - REVERB_PARAM_PROPERTIES, &properties)) { - ier->mProperties = properties; - } -} - -//----------------------------------------------------------------------------- -android::status_t android_erev_setParam(android::sp<android::AudioEffect> pFx, - int32_t param, void *pValue) { - - // given the size difference between a single reverb property and the whole set of reverb - // properties, select which max size to pass to avoid allocating too much memory - if (param == REVERB_PARAM_PROPERTIES) { - return android_fx_setParam(pFx, param, ENVREVERB_PARAM_SIZE_MAX_ALL, - pValue, erev_valueSize(param)); - } else { - return android_fx_setParam(pFx, param, ENVREVERB_PARAM_SIZE_MAX_SINGLE, - pValue, erev_valueSize(param)); - } -} - -//----------------------------------------------------------------------------- -android::status_t android_erev_getParam(android::sp<android::AudioEffect> pFx, - int32_t param, void *pValue) { - - // given the size difference between a single reverb property and the whole set of reverb - // properties, select which max size to pass to avoid allocating too much memory - if (param == REVERB_PARAM_PROPERTIES) { - return android_fx_getParam(pFx, param, ENVREVERB_PARAM_SIZE_MAX_ALL, - pValue, erev_valueSize(param)); - } else { - return android_fx_getParam(pFx, param, ENVREVERB_PARAM_SIZE_MAX_SINGLE, - pValue, erev_valueSize(param)); - } -} - - -//----------------------------------------------------------------------------- -/** - * pre-condition: - * ap != NULL - * for media players: - * ap->mAPlayer != 0 - * ap->mAudioTrack == 0 - * for buffer queue players: - * ap->mAPlayer == 0 - * ap->mAudioTrack != 0 is optional; if no track yet then the setting is deferred - */ -android::status_t android_fxSend_attach(CAudioPlayer* ap, bool attach, - android::sp<android::AudioEffect> pFx, SLmillibel sendLevel) { - - if (pFx == 0) { - return android::INVALID_OPERATION; - } - - // There are 3 cases: - // mAPlayer != 0 && mAudioTrack == 0 means playing decoded audio - // mAPlayer == 0 && mAudioTrack != 0 means playing PCM audio - // mAPlayer == 0 && mAudioTrack == 0 means player not fully configured yet - // The asserts document and verify this. - if (ap->mAPlayer != 0) { - assert(ap->mAudioTrack == 0); - if (attach) { - ap->mAPlayer->attachAuxEffect(pFx->id()); - ap->mAPlayer->setAuxEffectSendLevel( sles_to_android_amplification(sendLevel) ); - } else { - ap->mAPlayer->attachAuxEffect(0); - } - return android::NO_ERROR; - } - - if (ap->mAudioTrack == 0) { - // the player doesn't have an AudioTrack at the moment, so store this info to use it - // when the AudioTrack becomes available - if (attach) { - ap->mAuxEffect = pFx; - } else { - ap->mAuxEffect.clear(); - } - // we keep track of the send level, independently of the current audio player level - ap->mAuxSendLevel = sendLevel - ap->mVolume.mLevel; - return android::NO_ERROR; - } - - if (attach) { - android::status_t status = ap->mAudioTrack->attachAuxEffect(pFx->id()); - //SL_LOGV("attachAuxEffect(%d) returned %d", pFx->id(), status); - if (android::NO_ERROR == status) { - status = - ap->mAudioTrack->setAuxEffectSendLevel( sles_to_android_amplification(sendLevel) ); - } - return status; - } else { - return ap->mAudioTrack->attachAuxEffect(0); - } -} - -//----------------------------------------------------------------------------- -/** - * pre-condition: - * ap != NULL - * ap->mOutputMix != NULL - */ -SLresult android_fxSend_attachToAux(CAudioPlayer* ap, SLInterfaceID pUuid, SLboolean attach, - SLmillibel sendLevel) { - COutputMix *outputMix = CAudioPlayer_GetOutputMix(ap); - ssize_t index = outputMix->mAndroidEffect.mEffects->indexOfKey(KEY_FROM_GUID(pUuid)); - - if (0 > index) { - SL_LOGE("invalid effect ID: no such effect attached to the OutputMix"); - return SL_RESULT_PARAMETER_INVALID; - } - - android::AudioEffect* pFx = outputMix->mAndroidEffect.mEffects->valueAt(index); - if (NULL == pFx) { - return SL_RESULT_RESOURCE_ERROR; - } - if (android::NO_ERROR == android_fxSend_attach( ap, (bool) attach, pFx, sendLevel) ) { - return SL_RESULT_SUCCESS; - } else { - return SL_RESULT_RESOURCE_ERROR; - } - -} - -//----------------------------------------------------------------------------- -/** - * pre-condition: - * ap != NULL - * for media players: - * ap->mAPlayer != 0 - * ap->mAudioTrack == 0 - * for buffer queue players: - * ap->mAPlayer == 0 - * ap->mAudioTrack != 0 is optional; if no track yet then the setting is deferred - */ -android::status_t android_fxSend_setSendLevel(CAudioPlayer* ap, SLmillibel sendLevel) { - // we keep track of the send level, independently of the current audio player level - ap->mAuxSendLevel = sendLevel - ap->mVolume.mLevel; - - if (ap->mAPlayer != 0) { - assert(ap->mAudioTrack == 0); - ap->mAPlayer->setAuxEffectSendLevel( sles_to_android_amplification(sendLevel) ); - return android::NO_ERROR; - } - - if (ap->mAudioTrack == 0) { - return android::NO_ERROR; - } - - return ap->mAudioTrack->setAuxEffectSendLevel( sles_to_android_amplification(sendLevel) ); -} - -//----------------------------------------------------------------------------- -android::status_t android_fx_setParam(android::sp<android::AudioEffect> pFx, - int32_t param, uint32_t paramSizeMax, void *pValue, uint32_t valueSize) -{ - - android::status_t status; - uint32_t buf32[(paramSizeMax - 1) / sizeof(uint32_t) + 1]; - effect_param_t *p = (effect_param_t *)buf32; - - p->psize = sizeof(int32_t); - *(int32_t *)p->data = param; - p->vsize = valueSize; - memcpy(p->data + p->psize, pValue, p->vsize); - status = pFx->setParameter(p); - if (android::NO_ERROR == status) { - status = p->status; - } - return status; -} - - -//----------------------------------------------------------------------------- -android::status_t android_fx_getParam(android::sp<android::AudioEffect> pFx, - int32_t param, uint32_t paramSizeMax, void *pValue, uint32_t valueSize) -{ - android::status_t status; - uint32_t buf32[(paramSizeMax - 1) / sizeof(uint32_t) + 1]; - effect_param_t *p = (effect_param_t *)buf32; - - p->psize = sizeof(int32_t); - *(int32_t *)p->data = param; - p->vsize = valueSize; - status = pFx->getParameter(p); - if (android::NO_ERROR == status) { - status = p->status; - if (android::NO_ERROR == status) { - memcpy(pValue, p->data + p->psize, p->vsize); - } - } - - return status; -} - - -//----------------------------------------------------------------------------- -SLresult android_fx_statusToResult(android::status_t status) { - - if ((android::INVALID_OPERATION == status) || (android::DEAD_OBJECT == status)) { - return SL_RESULT_CONTROL_LOST; - } else { - return SL_RESULT_SUCCESS; - } -} - - -//----------------------------------------------------------------------------- -bool android_fx_initEffectObj(int sessionId, android::sp<android::AudioEffect>& effect, - const effect_uuid_t *type) { - //SL_LOGV("android_fx_initEffectObj on session %d", sessionId); - - effect = new android::AudioEffect(type, EFFECT_UUID_NULL, - 0,// priority - 0,// effect callback - 0,// callback data - sessionId,// session ID - 0 );// output - - android::status_t status = effect->initCheck(); - if (android::NO_ERROR != status) { - effect.clear(); - SL_LOGE("Effect initCheck() returned %d", status); - return false; - } - - return true; -} - - -//----------------------------------------------------------------------------- -bool android_fx_initEffectDescriptor(const SLInterfaceID effectId, - effect_descriptor_t* fxDescrLoc) { - uint32_t numEffects = 0; - effect_descriptor_t descriptor; - bool foundEffect = false; - - // any effects? - android::status_t res = android::AudioEffect::queryNumberEffects(&numEffects); - if (android::NO_ERROR != res) { - SL_LOGE("unable to find any effects."); - goto effectError; - } - - // request effect in the effects? - for (uint32_t i=0 ; i < numEffects ; i++) { - res = android::AudioEffect::queryEffect(i, &descriptor); - if ((android::NO_ERROR == res) && - (0 == memcmp(effectId, &descriptor.type, sizeof(effect_uuid_t)))) { - SL_LOGV("found effect %d %s", i, descriptor.name); - foundEffect = true; - break; - } - } - if (foundEffect) { - memcpy(fxDescrLoc, &descriptor, sizeof(effect_descriptor_t)); - } else { - SL_LOGE("unable to find an implementation for the requested effect."); - goto effectError; - } - - return true; - -effectError: - // the requested effect wasn't found - memset(fxDescrLoc, 0, sizeof(effect_descriptor_t)); - - return false; -} - -//----------------------------------------------------------------------------- -SLresult android_genericFx_queryNumEffects(SLuint32 *pNumSupportedAudioEffects) { - - if (NULL == pNumSupportedAudioEffects) { - return SL_RESULT_PARAMETER_INVALID; - } - - android::status_t status = - android::AudioEffect::queryNumberEffects((uint32_t*)pNumSupportedAudioEffects); - - SLresult result = SL_RESULT_SUCCESS; - switch(status) { - case android::NO_ERROR: - result = SL_RESULT_SUCCESS; - break; - case android::PERMISSION_DENIED: - result = SL_RESULT_PERMISSION_DENIED; - break; - case android::NO_INIT: - result = SL_RESULT_RESOURCE_ERROR; - break; - case android::BAD_VALUE: - result = SL_RESULT_PARAMETER_INVALID; - break; - default: - result = SL_RESULT_INTERNAL_ERROR; - SL_LOGE("received invalid status %d from AudioEffect::queryNumberEffects()", status); - break; - } - return result; -} - - -//----------------------------------------------------------------------------- -SLresult android_genericFx_queryEffect(SLuint32 index, effect_descriptor_t* pDescriptor) { - - if (NULL == pDescriptor) { - return SL_RESULT_PARAMETER_INVALID; - } - - android::status_t status = - android::AudioEffect::queryEffect(index, pDescriptor); - - SLresult result = SL_RESULT_SUCCESS; - if (android::NO_ERROR != status) { - switch(status) { - case android::PERMISSION_DENIED: - result = SL_RESULT_PERMISSION_DENIED; - break; - case android::NO_INIT: - case android::INVALID_OPERATION: - result = SL_RESULT_RESOURCE_ERROR; - break; - case android::BAD_VALUE: - result = SL_RESULT_PARAMETER_INVALID; - break; - default: - result = SL_RESULT_INTERNAL_ERROR; - SL_LOGE("received invalid status %d from AudioEffect::queryNumberEffects()", status); - break; - } - // an error occurred, reset the effect descriptor - memset(pDescriptor, 0, sizeof(effect_descriptor_t)); - } - - return result; -} - - -//----------------------------------------------------------------------------- -SLresult android_genericFx_createEffect(IAndroidEffect* iae, SLInterfaceID pUuid, int sessionId) { - - SLresult result = SL_RESULT_SUCCESS; - - // does this effect already exist? - if (0 <= iae->mEffects->indexOfKey(KEY_FROM_GUID(pUuid))) { - return result; - } - - // create new effect - android::AudioEffect* pFx = new android::AudioEffect( - NULL, // not using type to create effect - (const effect_uuid_t*)pUuid, - 0,// priority - 0,// effect callback - 0,// callback data - sessionId, - 0 );// output - - // verify effect was successfully created before storing it - android::status_t status = pFx->initCheck(); - if (android::NO_ERROR != status) { - SL_LOGE("AudioEffect initCheck() returned %d, effect will not be stored", status); - delete pFx; - result = SL_RESULT_RESOURCE_ERROR; - } else { - SL_LOGV("AudioEffect successfully created on session %d", sessionId); - iae->mEffects->add(KEY_FROM_GUID(pUuid), pFx); - } - - return result; -} - - -//----------------------------------------------------------------------------- -SLresult android_genericFx_releaseEffect(IAndroidEffect* iae, SLInterfaceID pUuid) { - - ssize_t index = iae->mEffects->indexOfKey(KEY_FROM_GUID(pUuid)); - - if (0 > index) { - return SL_RESULT_PARAMETER_INVALID; - } else { - android::AudioEffect* pFx = iae->mEffects->valueAt(index); - delete pFx; - iae->mEffects->removeItem(index); - return SL_RESULT_SUCCESS; - } -} - - -//----------------------------------------------------------------------------- -SLresult android_genericFx_setEnabled(IAndroidEffect* iae, SLInterfaceID pUuid, SLboolean enabled) { - - ssize_t index = iae->mEffects->indexOfKey(KEY_FROM_GUID(pUuid)); - - if (0 > index) { - return SL_RESULT_PARAMETER_INVALID; - } else { - android::AudioEffect* pFx = iae->mEffects->valueAt(index); - android::status_t status = pFx->setEnabled(SL_BOOLEAN_TRUE == enabled); - return android_fx_statusToResult(status); - } -} - - -//----------------------------------------------------------------------------- -SLresult android_genericFx_isEnabled(IAndroidEffect* iae, SLInterfaceID pUuid, SLboolean *pEnabled) -{ - ssize_t index = iae->mEffects->indexOfKey(KEY_FROM_GUID(pUuid)); - - if (0 > index) { - return SL_RESULT_PARAMETER_INVALID; - } else { - android::AudioEffect* pFx = iae->mEffects->valueAt(index); - *pEnabled = (SLboolean) pFx->getEnabled(); - return SL_RESULT_SUCCESS; - } -} - - -//----------------------------------------------------------------------------- -SLresult android_genericFx_sendCommand(IAndroidEffect* iae, SLInterfaceID pUuid, - SLuint32 command, SLuint32 commandSize, void* pCommandData, - SLuint32 *replySize, void *pReplyData) { - - ssize_t index = iae->mEffects->indexOfKey(KEY_FROM_GUID(pUuid)); - - if (0 > index) { - return SL_RESULT_PARAMETER_INVALID; - } else { - android::AudioEffect* pFx = iae->mEffects->valueAt(index); - android::status_t status = pFx->command( - (uint32_t) command, - (uint32_t) commandSize, - pCommandData, - (uint32_t*)replySize, - pReplyData); - if (android::BAD_VALUE == status) { - return SL_RESULT_PARAMETER_INVALID; - } else { - return SL_RESULT_SUCCESS; - } - } -} - -//----------------------------------------------------------------------------- -/** - * returns true if the given effect id is present in the AndroidEffect interface - */ -bool android_genericFx_hasEffect(IAndroidEffect* iae, SLInterfaceID pUuid) { - return( 0 <= iae->mEffects->indexOfKey(KEY_FROM_GUID(pUuid))); -} diff --git a/wilhelm/src/android/android_Effect.h b/wilhelm/src/android/android_Effect.h deleted file mode 100644 index 6ca4b5a6..00000000 --- a/wilhelm/src/android/android_Effect.h +++ /dev/null @@ -1,136 +0,0 @@ -/* - * 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. - */ - -/************************************************************************************************** - * Equalizer functions - ****************************/ -extern void android_eq_init(int sessionId, IEqualizer* ieq); - -extern android::status_t android_eq_setParam(android::sp<android::AudioEffect> pFx, - int32_t param, int32_t param2, void *pValue); - -extern android::status_t android_eq_getParam(android::sp<android::AudioEffect> pFx, - int32_t param, int32_t param2, void *pValue); - -/************************************************************************************************** - * BassBoost functions - ****************************/ -extern void android_bb_init(int sessionId, IBassBoost* ibb); - -extern android::status_t android_bb_setParam(android::sp<android::AudioEffect> pFx, - int32_t param, void *pValue); - -extern android::status_t android_bb_getParam(android::sp<android::AudioEffect> pFx, - int32_t param, void *pValue); - -/************************************************************************************************** - * Virtualizer functions - ****************************/ -extern void android_virt_init(int sessionId, IVirtualizer* ivi); - -extern android::status_t android_virt_setParam(android::sp<android::AudioEffect> pFx, - int32_t param, void *pValue); - -extern android::status_t android_virt_getParam(android::sp<android::AudioEffect> pFx, - int32_t param, void *pValue); - -/************************************************************************************************** - * PresetReverb functions - ****************************/ -extern void android_prev_init(IPresetReverb* ipr); - -extern android::status_t android_prev_setPreset(android::sp<android::AudioEffect> pFx, - uint16_t preset); - -extern android::status_t android_prev_getPreset(android::sp<android::AudioEffect> pFx, - uint16_t* preset); - -/************************************************************************************************** - * EnvironmentalReverb functions - ****************************/ -extern void android_erev_init(IEnvironmentalReverb* ier); - -extern android::status_t android_erev_setParam(android::sp<android::AudioEffect> pFx, - int32_t param, void *pValue); - -extern android::status_t android_erev_getParam(android::sp<android::AudioEffect> pFx, - int32_t param, void *pValue); - -/************************************************************************************************** - * Generic Effect functions - ****************************/ -extern SLresult android_genericFx_queryNumEffects(SLuint32 *pNumSupportedAudioEffects); - -extern SLresult android_genericFx_queryEffect(SLuint32 index, effect_descriptor_t* pDescriptor); - -extern SLresult android_genericFx_createEffect(IAndroidEffect* iae, SLInterfaceID pUuid, - int sessionId); - -extern SLresult android_genericFx_releaseEffect(IAndroidEffect* iae, SLInterfaceID pUuid); - -extern SLresult android_genericFx_setEnabled(IAndroidEffect* iae, SLInterfaceID pUuid, - SLboolean enabled); - -extern SLresult android_genericFx_isEnabled(IAndroidEffect* iae, SLInterfaceID pUuid, - SLboolean *pEnabled); - -extern SLresult android_genericFx_sendCommand(IAndroidEffect* iae, SLInterfaceID pUuid, - SLuint32 command, SLuint32 commandSize, void* pCommandData, - SLuint32 *replySize, void *pReplyData); - -extern bool android_genericFx_hasEffect(IAndroidEffect* iae, SLInterfaceID pUuid); - - -/************************************************************************************************** - * EffectSend functions - ****************************/ -/** - * sendLevel is the total energy going to the send bus. This implies that the volume attenuation - * should be combined with the send level for the aux level to follow volume changes. - */ -extern android::status_t android_fxSend_attach(CAudioPlayer* ap, bool attach, - android::sp<android::AudioEffect> pFx, SLmillibel sendLevel); - -/** - * sendLevel is the total energy going to the send bus. This implies that the volume attenuation - * should be combined with the send level for the aux level to follow volume changes. - * This one is used by Android-specific APIs, not portable Khronos APIs. - */ -extern SLresult android_fxSend_attachToAux(CAudioPlayer* ap, SLInterfaceID pUuid, - SLboolean attach, SLmillibel sendLevel); - -/** - * sendLevel is the total energy going to the send bus. This implies that the volume attenuation - * should be combined with the send level for the aux level to follow volume changes. - */ -extern android::status_t android_fxSend_setSendLevel(CAudioPlayer* ap, SLmillibel sendLevel); - -/************************************************************************************************** - * Effect-agnostic functions - ****************************/ -extern android::status_t android_fx_setParam(android::sp<android::AudioEffect> pFx, - int32_t param, uint32_t paramSizeMax, void *pValue, uint32_t valueSize); - -extern android::status_t android_fx_getParam(android::sp<android::AudioEffect> pFx, - int32_t param, uint32_t paramSizeMax, void *pValue, uint32_t valueSize); - -extern SLresult android_fx_statusToResult(android::status_t status); - -extern bool android_fx_initEffectObj(int sessionId, android::sp<android::AudioEffect>& effect, - const effect_uuid_t *type); - -extern bool android_fx_initEffectDescriptor(const SLInterfaceID effectId, - effect_descriptor_t* fxDescrLoc); diff --git a/wilhelm/src/android/android_GenericMediaPlayer.cpp b/wilhelm/src/android/android_GenericMediaPlayer.cpp deleted file mode 100644 index 04f4f8e6..00000000 --- a/wilhelm/src/android/android_GenericMediaPlayer.cpp +++ /dev/null @@ -1,589 +0,0 @@ -/* - * 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. - */ - -//#define USE_LOG SLAndroidLogLevel_Verbose - -#include "sles_allinclusive.h" -#include "android_GenericMediaPlayer.h" - -#include <system/window.h> - -#include <media/IMediaPlayerService.h> -#include <media/stagefright/foundation/ADebug.h> -#include <media/mediaplayer.h> // media_event_type media_error_type media_info_type - -// default delay in Us used when reposting an event when the player is not ready to accept -// the command yet. This is for instance used when seeking on a MediaPlayer that's still preparing -#define DEFAULT_COMMAND_DELAY_FOR_REPOST_US (100*1000) // 100ms - -// table of prefixes for known distant protocols; these are immediately dispatched to mediaserver -static const char* const kDistantProtocolPrefix[] = { "http://", "https://", "rtsp://"}; -#define NB_DISTANT_PROTOCOLS (sizeof(kDistantProtocolPrefix)/sizeof(kDistantProtocolPrefix[0])) - -// is the specified URI a known distant protocol? -bool isDistantProtocol(const char *uri) -{ - for (unsigned int i = 0; i < NB_DISTANT_PROTOCOLS; i++) { - if (!strncasecmp(uri, kDistantProtocolPrefix[i], strlen(kDistantProtocolPrefix[i]))) { - return true; - } - } - return false; -} - -namespace android { - -//-------------------------------------------------------------------------------------------------- -MediaPlayerNotificationClient::MediaPlayerNotificationClient(GenericMediaPlayer* gmp) : - mGenericMediaPlayer(gmp), - mPlayerPrepared(PREPARE_NOT_STARTED) -{ - SL_LOGV("MediaPlayerNotificationClient::MediaPlayerNotificationClient()"); -} - -MediaPlayerNotificationClient::~MediaPlayerNotificationClient() { - SL_LOGV("MediaPlayerNotificationClient::~MediaPlayerNotificationClient()"); -} - -// Map a media_event_type enum (the msg of an IMediaPlayerClient::notify) to a string or NULL -static const char *media_event_type_to_string(media_event_type msg) -{ - switch (msg) { -#define _(code) case code: return #code; - _(MEDIA_NOP) - _(MEDIA_PREPARED) - _(MEDIA_PLAYBACK_COMPLETE) - _(MEDIA_BUFFERING_UPDATE) - _(MEDIA_SEEK_COMPLETE) - _(MEDIA_SET_VIDEO_SIZE) - _(MEDIA_TIMED_TEXT) - _(MEDIA_ERROR) - _(MEDIA_INFO) -#undef _ - default: - return NULL; - } -} - -// Map a media_error_type enum (the ext1 of a MEDIA_ERROR event) to a string or NULL -static const char *media_error_type_to_string(media_error_type err) -{ - switch (err) { -#define _(code, msg) case code: return msg; - _(MEDIA_ERROR_UNKNOWN, "Unknown media error") - _(MEDIA_ERROR_SERVER_DIED, "Server died") - _(MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK, "Not valid for progressive playback") -#undef _ - default: - return NULL; - } -} - -// Map a media_info_type enum (the ext1 of a MEDIA_INFO event) to a string or NULL -static const char *media_info_type_to_string(media_info_type info) -{ - switch (info) { -#define _(code, msg) case code: return msg; - _(MEDIA_INFO_UNKNOWN, "Unknown info") - _(MEDIA_INFO_VIDEO_TRACK_LAGGING, "Video track lagging") - _(MEDIA_INFO_BUFFERING_START, "Buffering start") - _(MEDIA_INFO_BUFFERING_END, "Buffering end") - _(MEDIA_INFO_NETWORK_BANDWIDTH, "Network bandwidth") - _(MEDIA_INFO_BAD_INTERLEAVING, "Bad interleaving") - _(MEDIA_INFO_NOT_SEEKABLE, "Not seekable") - _(MEDIA_INFO_METADATA_UPDATE, "Metadata update") -#undef _ - default: - return NULL; - } -} - -//-------------------------------------------------- -// IMediaPlayerClient implementation -void MediaPlayerNotificationClient::notify(int msg, int ext1, int ext2, const Parcel *obj) { - SL_LOGV("MediaPlayerNotificationClient::notify(msg=%s (%d), ext1=%d, ext2=%d)", - media_event_type_to_string((enum media_event_type) msg), msg, ext1, ext2); - - sp<GenericMediaPlayer> genericMediaPlayer(mGenericMediaPlayer.promote()); - if (genericMediaPlayer == NULL) { - SL_LOGW("MediaPlayerNotificationClient::notify after GenericMediaPlayer destroyed"); - return; - } - - switch ((media_event_type) msg) { - case MEDIA_PREPARED: - { - Mutex::Autolock _l(mLock); - if (PREPARE_IN_PROGRESS == mPlayerPrepared) { - mPlayerPrepared = PREPARE_COMPLETED_SUCCESSFULLY; - mPlayerPreparedCondition.signal(); - } else { - SL_LOGE("Unexpected MEDIA_PREPARED"); - } - } - break; - - case MEDIA_SET_VIDEO_SIZE: - // only send video size updates if the player was flagged as having video, to avoid - // sending video size updates of (0,0) - // We're running on a different thread than genericMediaPlayer's ALooper thread, - // so it would normally be racy to access fields within genericMediaPlayer. - // But in this case mHasVideo is const, so it is safe to access. - // Or alternatively, we could notify unconditionally and let it decide whether to handle. - if (genericMediaPlayer->mHasVideo && (ext1 != 0 || ext2 != 0)) { - genericMediaPlayer->notify(PLAYEREVENT_VIDEO_SIZE_UPDATE, - (int32_t)ext1 /*width*/, (int32_t)ext2 /*height*/, true /*async*/); - } - break; - - case MEDIA_SEEK_COMPLETE: - genericMediaPlayer->seekComplete(); - break; - - case MEDIA_PLAYBACK_COMPLETE: - genericMediaPlayer->notify(PLAYEREVENT_ENDOFSTREAM, 1, true /*async*/); - break; - - case MEDIA_BUFFERING_UPDATE: - // if we receive any out-of-range data, then clamp it to reduce further harm - if (ext1 < 0) { - SL_LOGE("MEDIA_BUFFERING_UPDATE %d%% < 0", ext1); - ext1 = 0; - } else if (ext1 > 100) { - SL_LOGE("MEDIA_BUFFERING_UPDATE %d%% > 100", ext1); - ext1 = 100; - } - // values received from Android framework for buffer fill level use percent, - // while SL/XA use permille, so does GenericPlayer - genericMediaPlayer->bufferingUpdate(ext1 * 10 /*fillLevelPerMille*/); - break; - - case MEDIA_ERROR: - { - SL_LOGV("MediaPlayerNotificationClient::notify(msg=MEDIA_ERROR, ext1=%s (%d), ext2=%d)", - media_error_type_to_string((media_error_type) ext1), ext1, ext2); - Mutex::Autolock _l(mLock); - if (PREPARE_IN_PROGRESS == mPlayerPrepared) { - mPlayerPrepared = PREPARE_COMPLETED_UNSUCCESSFULLY; - mPlayerPreparedCondition.signal(); - } else { - // inform client of errors after preparation - genericMediaPlayer->notify(PLAYEREVENT_ERRORAFTERPREPARE, ext1, true /*async*/); - } - } - break; - - case MEDIA_NOP: - case MEDIA_TIMED_TEXT: - break; - - case MEDIA_INFO: - SL_LOGV("MediaPlayerNotificationClient::notify(msg=MEDIA_INFO, ext1=%s (%d), ext2=%d)", - media_info_type_to_string((media_info_type) ext1), ext1, ext2); - switch (ext1) { - case MEDIA_INFO_VIDEO_TRACK_LAGGING: - SL_LOGV("MEDIA_INFO_VIDEO_TRACK_LAGGING by %d ms", ext1); - break; - case MEDIA_INFO_NETWORK_BANDWIDTH: - SL_LOGV("MEDIA_INFO_NETWORK_BANDWIDTH %d kbps", ext2); - break; - case MEDIA_INFO_UNKNOWN: - case MEDIA_INFO_BUFFERING_START: - case MEDIA_INFO_BUFFERING_END: - case MEDIA_INFO_BAD_INTERLEAVING: - case MEDIA_INFO_NOT_SEEKABLE: - case MEDIA_INFO_METADATA_UPDATE: - default: - break; - } - break; - - default: - break; - } - -} - -//-------------------------------------------------- -void MediaPlayerNotificationClient::beforePrepare() -{ - Mutex::Autolock _l(mLock); - assert(mPlayerPrepared == PREPARE_NOT_STARTED); - mPlayerPrepared = PREPARE_IN_PROGRESS; -} - -//-------------------------------------------------- -bool MediaPlayerNotificationClient::blockUntilPlayerPrepared() { - Mutex::Autolock _l(mLock); - assert(mPlayerPrepared != PREPARE_NOT_STARTED); - while (mPlayerPrepared == PREPARE_IN_PROGRESS) { - mPlayerPreparedCondition.wait(mLock); - } - assert(mPlayerPrepared == PREPARE_COMPLETED_SUCCESSFULLY || - mPlayerPrepared == PREPARE_COMPLETED_UNSUCCESSFULLY); - return mPlayerPrepared == PREPARE_COMPLETED_SUCCESSFULLY; -} - -//-------------------------------------------------------------------------------------------------- -GenericMediaPlayer::GenericMediaPlayer(const AudioPlayback_Parameters* params, bool hasVideo) : - GenericPlayer(params), - mHasVideo(hasVideo), - mSeekTimeMsec(0), - mVideoSurfaceTexture(0), - mPlayer(0), - mPlayerClient(new MediaPlayerNotificationClient(this)), - mPlayerDeathNotifier(new MediaPlayerDeathNotifier(mPlayerClient)) -{ - SL_LOGD("GenericMediaPlayer::GenericMediaPlayer()"); - -} - -GenericMediaPlayer::~GenericMediaPlayer() { - SL_LOGD("GenericMediaPlayer::~GenericMediaPlayer()"); -} - -void GenericMediaPlayer::preDestroy() { - // FIXME can't access mPlayer from outside the looper (no mutex!) so using mPreparedPlayer - sp<IMediaPlayer> player; - getPreparedPlayer(player); - if (player != NULL) { - player->stop(); - // causes CHECK failure in Nuplayer, but commented out in the subclass preDestroy - // randomly causes a NPE in StagefrightPlayer, heap corruption, or app hang - //player->setDataSource(NULL); - player->setVideoSurfaceTexture(NULL); - player->disconnect(); - // release all references to the IMediaPlayer - // FIXME illegal if not on looper - //mPlayer.clear(); - { - Mutex::Autolock _l(mPreparedPlayerLock); - mPreparedPlayer.clear(); - } - } - GenericPlayer::preDestroy(); -} - -//-------------------------------------------------- -// overridden from GenericPlayer -// pre-condition: -// msec != NULL -// post-condition -// *msec == -// ANDROID_UNKNOWN_TIME if position is unknown at time of query, -// or the current MediaPlayer position -void GenericMediaPlayer::getPositionMsec(int* msec) { - SL_LOGD("GenericMediaPlayer::getPositionMsec()"); - sp<IMediaPlayer> player; - getPreparedPlayer(player); - // To avoid deadlock, directly call the MediaPlayer object - if (player == 0 || player->getCurrentPosition(msec) != NO_ERROR) { - *msec = ANDROID_UNKNOWN_TIME; - } -} - -//-------------------------------------------------- -void GenericMediaPlayer::setVideoSurfaceTexture(const sp<ISurfaceTexture> &surfaceTexture) { - SL_LOGV("GenericMediaPlayer::setVideoSurfaceTexture()"); - // FIXME bug - race condition, should do in looper - if (mVideoSurfaceTexture.get() == surfaceTexture.get()) { - return; - } - if ((mStateFlags & kFlagPrepared) && (mPlayer != 0)) { - mPlayer->setVideoSurfaceTexture(surfaceTexture); - } - mVideoSurfaceTexture = surfaceTexture; -} - - -//-------------------------------------------------- -// Event handlers - -// blocks until mPlayer is prepared -void GenericMediaPlayer::onPrepare() { - SL_LOGD("GenericMediaPlayer::onPrepare()"); - // Attempt to prepare at most once, and only if there is a MediaPlayer - if (!(mStateFlags & (kFlagPrepared | kFlagPreparedUnsuccessfully)) && (mPlayer != 0)) { - if (mHasVideo) { - if (mVideoSurfaceTexture != 0) { - mPlayer->setVideoSurfaceTexture(mVideoSurfaceTexture); - } - } - mPlayer->setAudioStreamType(mPlaybackParams.streamType); - mPlayerClient->beforePrepare(); - mPlayer->prepareAsync(); - if (mPlayerClient->blockUntilPlayerPrepared()) { - mStateFlags |= kFlagPrepared; - afterMediaPlayerPreparedSuccessfully(); - } else { - mStateFlags |= kFlagPreparedUnsuccessfully; - } - } - GenericPlayer::onPrepare(); - SL_LOGD("GenericMediaPlayer::onPrepare() done, mStateFlags=0x%x", mStateFlags); -} - - -void GenericMediaPlayer::onPlay() { - SL_LOGD("GenericMediaPlayer::onPlay()"); - if (((mStateFlags & (kFlagPrepared | kFlagPlaying)) == kFlagPrepared) && (mPlayer != 0)) { - mPlayer->start(); - } - GenericPlayer::onPlay(); -} - - -void GenericMediaPlayer::onPause() { - SL_LOGD("GenericMediaPlayer::onPause()"); - if (!(~mStateFlags & (kFlagPrepared | kFlagPlaying)) && (mPlayer != 0)) { - mPlayer->pause(); - } - GenericPlayer::onPause(); -} - - -void GenericMediaPlayer::onSeekComplete() { - SL_LOGV("GenericMediaPlayer::onSeekComplete()"); - // did we initiate the seek? - if (!(mStateFlags & kFlagSeeking)) { - // no, are we looping? - if (mStateFlags & kFlagLooping) { - // yes, per OpenSL ES 1.0.1 and 1.1 do NOT report it to client - // notify(PLAYEREVENT_ENDOFSTREAM, 1, true /*async*/); - // no, well that's surprising, but it's probably just a benign race condition - } else { - SL_LOGW("Unexpected seek complete event ignored"); - } - } - GenericPlayer::onSeekComplete(); -} - - -/** - * pre-condition: WHATPARAM_SEEK_SEEKTIME_MS parameter value >= 0 - */ -void GenericMediaPlayer::onSeek(const sp<AMessage> &msg) { - SL_LOGV("GenericMediaPlayer::onSeek"); - int64_t timeMsec = ANDROID_UNKNOWN_TIME; - if (!msg->findInt64(WHATPARAM_SEEK_SEEKTIME_MS, &timeMsec)) { - // invalid command, drop it - return; - } - if ((mStateFlags & kFlagSeeking) && (timeMsec == mSeekTimeMsec) && - (timeMsec != ANDROID_UNKNOWN_TIME)) { - // already seeking to the same non-unknown time, cancel this command - return; - } else if (mStateFlags & kFlagPreparedUnsuccessfully) { - // discard seeks after unsuccessful prepare - } else if (!(mStateFlags & kFlagPrepared)) { - // we are not ready to accept a seek command at this time, retry later - msg->post(DEFAULT_COMMAND_DELAY_FOR_REPOST_US); - } else { - if (mPlayer != 0) { - mStateFlags |= kFlagSeeking; - mSeekTimeMsec = (int32_t)timeMsec; - // seek to unknown time is used by StreamPlayer after discontinuity - if (timeMsec == ANDROID_UNKNOWN_TIME) { - // FIXME simulate a MEDIA_SEEK_COMPLETE event in 250 ms; - // this is a terrible hack to make up for mediaserver not sending one - (new AMessage(kWhatSeekComplete, id()))->post(250000); - } else if (OK != mPlayer->seekTo(timeMsec)) { - mStateFlags &= ~kFlagSeeking; - mSeekTimeMsec = ANDROID_UNKNOWN_TIME; - // don't call updateOneShot because seek not yet done - } - } - } -} - - -void GenericMediaPlayer::onLoop(const sp<AMessage> &msg) { - SL_LOGV("GenericMediaPlayer::onLoop"); - int32_t loop = 0; - if (msg->findInt32(WHATPARAM_LOOP_LOOPING, &loop)) { - if (loop) { - mStateFlags |= kFlagLooping; - } else { - mStateFlags &= ~kFlagLooping; - } - // if we have a MediaPlayer then tell it now, otherwise we'll tell it after it's created - if (mPlayer != 0) { - (void) mPlayer->setLooping(loop); - } - } -} - - -void GenericMediaPlayer::onVolumeUpdate() { - SL_LOGD("GenericMediaPlayer::onVolumeUpdate()"); - if (mPlayer != 0) { - // use settings lock to read the volume settings - Mutex::Autolock _l(mSettingsLock); - mPlayer->setVolume(mAndroidAudioLevels.mFinalVolume[0], - mAndroidAudioLevels.mFinalVolume[1]); - } -} - - -void GenericMediaPlayer::onAttachAuxEffect(const sp<AMessage> &msg) { - SL_LOGD("GenericMediaPlayer::onAttachAuxEffect()"); - int32_t effectId = 0; - if (msg->findInt32(WHATPARAM_ATTACHAUXEFFECT, &effectId)) { - if (mPlayer != 0) { - status_t status; - status = mPlayer->attachAuxEffect(effectId); - // attachAuxEffect returns a status but we have no way to report it back to app - (void) status; - } - } -} - - -void GenericMediaPlayer::onSetAuxEffectSendLevel(const sp<AMessage> &msg) { - SL_LOGD("GenericMediaPlayer::onSetAuxEffectSendLevel()"); - float level = 0.0f; - if (msg->findFloat(WHATPARAM_SETAUXEFFECTSENDLEVEL, &level)) { - if (mPlayer != 0) { - status_t status; - status = mPlayer->setAuxEffectSendLevel(level); - // setAuxEffectSendLevel returns a status but we have no way to report it back to app - (void) status; - } - } -} - - -void GenericMediaPlayer::onBufferingUpdate(const sp<AMessage> &msg) { - int32_t fillLevel = 0; - if (msg->findInt32(WHATPARAM_BUFFERING_UPDATE, &fillLevel)) { - SL_LOGD("GenericMediaPlayer::onBufferingUpdate(fillLevel=%d)", fillLevel); - - Mutex::Autolock _l(mSettingsLock); - mCacheFill = fillLevel; - // handle cache fill update - if (mCacheFill - mLastNotifiedCacheFill >= mCacheFillNotifThreshold) { - notifyCacheFill(); - } - // handle prefetch status update - // compute how much time ahead of position is buffered - int durationMsec, positionMsec = -1; - if ((mStateFlags & kFlagPrepared) && (mPlayer != 0) - && (OK == mPlayer->getDuration(&durationMsec)) - && (OK == mPlayer->getCurrentPosition(&positionMsec))) { - if ((-1 != durationMsec) && (-1 != positionMsec)) { - // evaluate prefetch status based on buffer time thresholds - int64_t bufferedDurationMsec = (durationMsec * fillLevel / 100) - positionMsec; - CacheStatus_t newCacheStatus = mCacheStatus; - if (bufferedDurationMsec > DURATION_CACHED_HIGH_MS) { - newCacheStatus = kStatusHigh; - } else if (bufferedDurationMsec > DURATION_CACHED_MED_MS) { - newCacheStatus = kStatusEnough; - } else if (bufferedDurationMsec > DURATION_CACHED_LOW_MS) { - newCacheStatus = kStatusIntermediate; - } else if (bufferedDurationMsec == 0) { - newCacheStatus = kStatusEmpty; - } else { - newCacheStatus = kStatusLow; - } - - if (newCacheStatus != mCacheStatus) { - mCacheStatus = newCacheStatus; - notifyStatus(); - } - } - } - } else { - SL_LOGV("GenericMediaPlayer::onBufferingUpdate(fillLevel=unknown)"); - } -} - - -//-------------------------------------------------- -/** - * called from GenericMediaPlayer::onPrepare after the MediaPlayer mPlayer is prepared successfully - * pre-conditions: - * mPlayer != 0 - * mPlayer is prepared successfully - */ -void GenericMediaPlayer::afterMediaPlayerPreparedSuccessfully() { - SL_LOGV("GenericMediaPlayer::afterMediaPlayerPrepared()"); - assert(mPlayer != 0); - assert(mStateFlags & kFlagPrepared); - // Mark this player as prepared successfully, so safe to directly call getCurrentPosition - { - Mutex::Autolock _l(mPreparedPlayerLock); - assert(mPreparedPlayer == 0); - mPreparedPlayer = mPlayer; - } - // retrieve channel count - int32_t channelCount; - Parcel *reply = new Parcel(); - status_t status = mPlayer->getParameter(KEY_PARAMETER_AUDIO_CHANNEL_COUNT, reply); - if (status == NO_ERROR) { - channelCount = reply->readInt32(); - } else { - // FIXME MPEG-2 TS doesn't yet implement this key, so default to stereo - channelCount = 2; - } - if (UNKNOWN_NUMCHANNELS != channelCount) { - // now that we know the channel count, re-calculate the volumes - notify(PLAYEREVENT_CHANNEL_COUNT, channelCount, true /*async*/); - } else { - ALOGW("channel count is still unknown after prepare"); - } - delete reply; - // retrieve duration - { - int msec = 0; - if (OK == mPlayer->getDuration(&msec)) { - Mutex::Autolock _l(mSettingsLock); - mDurationMsec = msec; - } - } - // now that we have a MediaPlayer, set the looping flag - if (mStateFlags & kFlagLooping) { - (void) mPlayer->setLooping(1); - } - // when the MediaPlayer mPlayer is prepared, there is "sufficient data" in the playback buffers - // if the data source was local, and the buffers are considered full so we need to notify that - bool isLocalSource = true; - if (kDataLocatorUri == mDataLocatorType) { - isLocalSource = !isDistantProtocol(mDataLocator.uriRef); - } - if (isLocalSource) { - SL_LOGD("media player prepared on local source"); - { - Mutex::Autolock _l(mSettingsLock); - mCacheStatus = kStatusHigh; - mCacheFill = 1000; - notifyStatus(); - notifyCacheFill(); - } - } else { - SL_LOGD("media player prepared on non-local source"); - } -} - - -//-------------------------------------------------- -// If player is prepared successfully, set output parameter to that reference, otherwise NULL -void GenericMediaPlayer::getPreparedPlayer(sp<IMediaPlayer> &preparedPlayer) -{ - Mutex::Autolock _l(mPreparedPlayerLock); - preparedPlayer = mPreparedPlayer; -} - -} // namespace android diff --git a/wilhelm/src/android/android_GenericMediaPlayer.h b/wilhelm/src/android/android_GenericMediaPlayer.h deleted file mode 100644 index c0497baa..00000000 --- a/wilhelm/src/android/android_GenericMediaPlayer.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - * 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_GENERICMEDIAPLAYER_H__ -#define __ANDROID_GENERICMEDIAPLAYER_H__ - -#include "android_GenericPlayer.h" - -#include <binder/IServiceManager.h> -#include <gui/ISurfaceTexture.h> - - -//-------------------------------------------------------------------------------------------------- -namespace android { - -class GenericMediaPlayer; -class MediaPlayerNotificationClient : public BnMediaPlayerClient -{ -public: - MediaPlayerNotificationClient(GenericMediaPlayer* gmp); - - // IMediaPlayerClient implementation - virtual void notify(int msg, int ext1, int ext2, const Parcel *obj); - - // Call before enqueuing a prepare event - void beforePrepare(); - - // Call after enqueueing the prepare event; returns true if the prepare - // completed successfully, or false if it completed unsuccessfully - bool blockUntilPlayerPrepared(); - -protected: - virtual ~MediaPlayerNotificationClient(); - -private: - const wp<GenericMediaPlayer> mGenericMediaPlayer; - Mutex mLock; // protects mPlayerPrepared - Condition mPlayerPreparedCondition; // signalled when mPlayerPrepared is changed - enum { - PREPARE_NOT_STARTED, - PREPARE_IN_PROGRESS, - PREPARE_COMPLETED_SUCCESSFULLY, - PREPARE_COMPLETED_UNSUCCESSFULLY - } mPlayerPrepared; -}; - - -class MediaPlayerDeathNotifier : public IMediaDeathNotifier { -public: - MediaPlayerDeathNotifier(const sp<MediaPlayerNotificationClient> playerClient) : - mPlayerClient(playerClient) { - } - - void died() { - mPlayerClient->notify(MEDIA_ERROR, MEDIA_ERROR_SERVER_DIED, 0, NULL); - } - -protected: - virtual ~MediaPlayerDeathNotifier() { } - -private: - const sp<MediaPlayerNotificationClient> mPlayerClient; -}; - - -//-------------------------------------------------------------------------------------------------- -class GenericMediaPlayer : public GenericPlayer -{ -public: - - GenericMediaPlayer(const AudioPlayback_Parameters* params, bool hasVideo); - virtual ~GenericMediaPlayer(); - - virtual void preDestroy(); - - // overridden from GenericPlayer - virtual void getPositionMsec(int* msec); // ANDROID_UNKNOWN_TIME if unknown - - virtual void setVideoSurfaceTexture(const sp<ISurfaceTexture> &surfaceTexture); - -protected: - friend class MediaPlayerNotificationClient; - - // Async event handlers (called from GenericPlayer's event loop) - virtual void onPrepare(); - virtual void onPlay(); - virtual void onPause(); - virtual void onSeek(const sp<AMessage> &msg); - virtual void onLoop(const sp<AMessage> &msg); - virtual void onSeekComplete(); - virtual void onVolumeUpdate(); - virtual void onBufferingUpdate(const sp<AMessage> &msg); - virtual void onAttachAuxEffect(const sp<AMessage> &msg); - virtual void onSetAuxEffectSendLevel(const sp<AMessage> &msg); - - const bool mHasVideo; // const allows MediaPlayerNotificationClient::notify to safely access - int32_t mSeekTimeMsec; - - sp<ISurfaceTexture> mVideoSurfaceTexture; - - // only safe to access from within Realize and looper - sp<IMediaPlayer> mPlayer; - // Receives Android MediaPlayer events from mPlayer - const sp<MediaPlayerNotificationClient> mPlayerClient; - - // Receives notifications about death of media.player service - const sp<MediaPlayerDeathNotifier> mPlayerDeathNotifier; - - // Return a reference to the media player service, or ALOGE and return NULL after retries fail - static const sp<IMediaPlayerService> getMediaPlayerService() { - return IMediaDeathNotifier::getMediaPlayerService(); - } - -private: - DISALLOW_EVIL_CONSTRUCTORS(GenericMediaPlayer); - void afterMediaPlayerPreparedSuccessfully(); - -protected: // FIXME temporary - Mutex mPreparedPlayerLock; // protects mPreparedPlayer - sp<IMediaPlayer> mPreparedPlayer; // non-NULL if MediaPlayer exists and prepared, write once -private: - void getPreparedPlayer(sp<IMediaPlayer> &preparedPlayer); // safely read mPreparedPlayer - -}; - -} // namespace android - -// is the specified URI a known distant protocol? -bool isDistantProtocol(const char *uri); - -#endif /* __ANDROID_GENERICMEDIAPLAYER_H__ */ diff --git a/wilhelm/src/android/android_GenericPlayer.cpp b/wilhelm/src/android/android_GenericPlayer.cpp deleted file mode 100644 index 0fd975c7..00000000 --- a/wilhelm/src/android/android_GenericPlayer.cpp +++ /dev/null @@ -1,692 +0,0 @@ -/* - * 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. - */ - -//#define USE_LOG SLAndroidLogLevel_Verbose - -#include "sles_allinclusive.h" - -#include <media/stagefright/foundation/ADebug.h> -#include <sys/stat.h> - -namespace android { - -//-------------------------------------------------------------------------------------------------- -GenericPlayer::GenericPlayer(const AudioPlayback_Parameters* params) : - mDataLocatorType(kDataLocatorNone), - mNotifyClient(NULL), - mNotifyUser(NULL), - mStateFlags(0), - mPlaybackParams(*params), - mDurationMsec(ANDROID_UNKNOWN_TIME), - mCacheStatus(kStatusEmpty), - mCacheFill(0), - mLastNotifiedCacheFill(0), - mCacheFillNotifThreshold(100), - mEventFlags(0), - mMarkerPositionMs(ANDROID_UNKNOWN_TIME), - mPositionUpdatePeriodMs(1000), // per spec - mOneShotGeneration(0), - mDeliveredNewPosMs(ANDROID_UNKNOWN_TIME), - mObservedPositionMs(ANDROID_UNKNOWN_TIME) -{ - SL_LOGD("GenericPlayer::GenericPlayer()"); - - mLooper = new android::ALooper(); - - // Post-construction accesses need to be protected by mSettingsLock - mAndroidAudioLevels.mFinalVolume[0] = 1.0f; - mAndroidAudioLevels.mFinalVolume[1] = 1.0f; -} - - -GenericPlayer::~GenericPlayer() { - SL_LOGV("GenericPlayer::~GenericPlayer()"); - - resetDataLocator(); -} - - -void GenericPlayer::init(const notif_cbf_t cbf, void* notifUser) { - SL_LOGD("GenericPlayer::init()"); - - { - android::Mutex::Autolock autoLock(mNotifyClientLock); - mNotifyClient = cbf; - mNotifyUser = notifUser; - } - - mLooper->registerHandler(this); - mLooper->start(false /*runOnCallingThread*/, false /*canCallJava*/, PRIORITY_DEFAULT); -} - - -void GenericPlayer::preDestroy() { - SL_LOGD("GenericPlayer::preDestroy()"); - { - android::Mutex::Autolock autoLock(mNotifyClientLock); - mNotifyClient = NULL; - mNotifyUser = NULL; - } - - mLooper->stop(); - mLooper->unregisterHandler(id()); -} - - -void GenericPlayer::setDataSource(const char *uri) { - SL_LOGV("GenericPlayer::setDataSource(uri=%s)", uri); - resetDataLocator(); - - mDataLocator.uriRef = uri; - - mDataLocatorType = kDataLocatorUri; -} - - -void GenericPlayer::setDataSource(int fd, int64_t offset, int64_t length, bool closeAfterUse) { - SL_LOGV("GenericPlayer::setDataSource(fd=%d, offset=%lld, length=%lld, closeAfterUse=%s)", fd, - offset, length, closeAfterUse ? "true" : "false"); - resetDataLocator(); - - mDataLocator.fdi.fd = fd; - - struct stat sb; - int ret = fstat(fd, &sb); - if (ret != 0) { - SL_LOGE("GenericPlayer::setDataSource: fstat(%d) failed: %d, %s", fd, ret, strerror(errno)); - return; - } - - if (offset >= sb.st_size) { - SL_LOGE("SfPlayer::setDataSource: invalid offset"); - return; - } - mDataLocator.fdi.offset = offset; - - if (PLAYER_FD_FIND_FILE_SIZE == length) { - mDataLocator.fdi.length = sb.st_size; - } else if (offset + length > sb.st_size) { - mDataLocator.fdi.length = sb.st_size - offset; - } else { - mDataLocator.fdi.length = length; - } - - mDataLocator.fdi.mCloseAfterUse = closeAfterUse; - - mDataLocatorType = kDataLocatorFd; -} - - -void GenericPlayer::prepare() { - SL_LOGD("GenericPlayer::prepare()"); - // do not attempt prepare more than once - if (!(mStateFlags & (kFlagPrepared | kFlagPreparedUnsuccessfully))) { - sp<AMessage> msg = new AMessage(kWhatPrepare, id()); - msg->post(); - } -} - - -void GenericPlayer::play() { - SL_LOGD("GenericPlayer::play()"); - sp<AMessage> msg = new AMessage(kWhatPlay, id()); - msg->post(); -} - - -void GenericPlayer::pause() { - SL_LOGD("GenericPlayer::pause()"); - sp<AMessage> msg = new AMessage(kWhatPause, id()); - msg->post(); -} - - -void GenericPlayer::stop() { - SL_LOGD("GenericPlayer::stop()"); - (new AMessage(kWhatPause, id()))->post(); - - // after a stop, playback should resume from the start. - seek(0); -} - - -void GenericPlayer::seek(int64_t timeMsec) { - SL_LOGV("GenericPlayer::seek %lld", timeMsec); - if (timeMsec < 0 && timeMsec != ANDROID_UNKNOWN_TIME) { - SL_LOGE("GenericPlayer::seek error, can't seek to negative time %lldms", timeMsec); - return; - } - sp<AMessage> msg = new AMessage(kWhatSeek, id()); - msg->setInt64(WHATPARAM_SEEK_SEEKTIME_MS, timeMsec); - msg->post(); -} - - -void GenericPlayer::loop(bool loop) { - SL_LOGV("GenericPlayer::loop %s", loop ? "true" : "false"); - sp<AMessage> msg = new AMessage(kWhatLoop, id()); - msg->setInt32(WHATPARAM_LOOP_LOOPING, (int32_t)loop); - msg->post(); -} - - -void GenericPlayer::setBufferingUpdateThreshold(int16_t thresholdPercent) { - SL_LOGV("GenericPlayer::setBufferingUpdateThreshold %d", thresholdPercent); - sp<AMessage> msg = new AMessage(kWhatBuffUpdateThres, id()); - msg->setInt32(WHATPARAM_BUFFERING_UPDATETHRESHOLD_PERCENT, (int32_t)thresholdPercent); - msg->post(); -} - - -//-------------------------------------------------- -void GenericPlayer::getDurationMsec(int* msec) { - Mutex::Autolock _l(mSettingsLock); - *msec = mDurationMsec; -} - -//-------------------------------------------------- -void GenericPlayer::setVolume(float leftVol, float rightVol) -{ - { - Mutex::Autolock _l(mSettingsLock); - mAndroidAudioLevels.mFinalVolume[0] = leftVol; - mAndroidAudioLevels.mFinalVolume[1] = rightVol; - } - // send a message for the volume to be updated by the object which implements the volume - (new AMessage(kWhatVolumeUpdate, id()))->post(); -} - - -//-------------------------------------------------- -void GenericPlayer::attachAuxEffect(int32_t effectId) -{ - SL_LOGV("GenericPlayer::attachAuxEffect(id=%d)", effectId); - sp<AMessage> msg = new AMessage(kWhatAttachAuxEffect, id()); - msg->setInt32(WHATPARAM_ATTACHAUXEFFECT, effectId); - msg->post(); -} - - -//-------------------------------------------------- -void GenericPlayer::setAuxEffectSendLevel(float level) -{ - SL_LOGV("GenericPlayer::setAuxEffectSendLevel(level=%g)", level); - sp<AMessage> msg = new AMessage(kWhatSetAuxEffectSendLevel, id()); - msg->setFloat(WHATPARAM_SETAUXEFFECTSENDLEVEL, level); - msg->post(); -} - - -//-------------------------------------------------- -// Call after changing any of the IPlay settings related to SL_PLAYEVENT_* -void GenericPlayer::setPlayEvents(int32_t eventFlags, int32_t markerPositionMs, - int32_t positionUpdatePeriodMs) -{ - // Normalize ms that are within the valid unsigned range, but not in the int32_t range - if (markerPositionMs < 0) { - markerPositionMs = ANDROID_UNKNOWN_TIME; - } - if (positionUpdatePeriodMs < 0) { - positionUpdatePeriodMs = ANDROID_UNKNOWN_TIME; - } - // markers are delivered accurately, but new position updates are limited to every 100 ms - if (positionUpdatePeriodMs < 100) { - positionUpdatePeriodMs = 100; - } - sp<AMessage> msg = new AMessage(kWhatSetPlayEvents, id()); - msg->setInt32(WHATPARAM_SETPLAYEVENTS_FLAGS, eventFlags); - msg->setInt32(WHATPARAM_SETPLAYEVENTS_MARKER, markerPositionMs); - msg->setInt32(WHATPARAM_SETPLAYEVENTS_UPDATE, positionUpdatePeriodMs); - msg->post(); -} - - -//-------------------------------------------------- -/* - * post-condition: mDataLocatorType == kDataLocatorNone - * - */ -void GenericPlayer::resetDataLocator() { - SL_LOGV("GenericPlayer::resetDataLocator()"); - if (mDataLocatorType == kDataLocatorFd && mDataLocator.fdi.mCloseAfterUse) { - (void) ::close(mDataLocator.fdi.fd); - // would be redundant, as we're about to invalidate the union mDataLocator - //mDataLocator.fdi.fd = -1; - //mDataLocator.fdi.mCloseAfterUse = false; - } - mDataLocatorType = kDataLocatorNone; -} - - -void GenericPlayer::notify(const char* event, int data, bool async) { - SL_LOGV("GenericPlayer::notify(event=%s, data=%d, async=%s)", event, data, - async ? "true" : "false"); - sp<AMessage> msg = new AMessage(kWhatNotif, id()); - msg->setInt32(event, (int32_t)data); - if (async) { - msg->post(); - } else { - onNotify(msg); - } -} - - -void GenericPlayer::notify(const char* event, int data1, int data2, bool async) { - SL_LOGV("GenericPlayer::notify(event=%s, data1=%d, data2=%d, async=%s)", event, data1, data2, - async ? "true" : "false"); - sp<AMessage> msg = new AMessage(kWhatNotif, id()); - msg->setRect(event, 0, 0, (int32_t)data1, (int32_t)data2); - if (async) { - msg->post(); - } else { - onNotify(msg); - } -} - - -//-------------------------------------------------- -// AHandler implementation -void GenericPlayer::onMessageReceived(const sp<AMessage> &msg) { - SL_LOGV("GenericPlayer::onMessageReceived()"); - switch (msg->what()) { - case kWhatPrepare: - SL_LOGV("kWhatPrepare"); - onPrepare(); - break; - - case kWhatNotif: - SL_LOGV("kWhatNotif"); - onNotify(msg); - break; - - case kWhatPlay: - SL_LOGV("kWhatPlay"); - onPlay(); - break; - - case kWhatPause: - SL_LOGV("kWhatPause"); - onPause(); - break; - - case kWhatSeek: - SL_LOGV("kWhatSeek"); - onSeek(msg); - break; - - case kWhatLoop: - SL_LOGV("kWhatLoop"); - onLoop(msg); - break; - - case kWhatVolumeUpdate: - SL_LOGV("kWhatVolumeUpdate"); - onVolumeUpdate(); - break; - - case kWhatSeekComplete: - SL_LOGV("kWhatSeekComplete"); - onSeekComplete(); - break; - - case kWhatBufferingUpdate: - SL_LOGV("kWhatBufferingUpdate"); - onBufferingUpdate(msg); - break; - - case kWhatBuffUpdateThres: - SL_LOGV("kWhatBuffUpdateThres"); - onSetBufferingUpdateThreshold(msg); - break; - - case kWhatAttachAuxEffect: - SL_LOGV("kWhatAttachAuxEffect"); - onAttachAuxEffect(msg); - break; - - case kWhatSetAuxEffectSendLevel: - SL_LOGV("kWhatSetAuxEffectSendLevel"); - onSetAuxEffectSendLevel(msg); - break; - - case kWhatSetPlayEvents: - SL_LOGV("kWhatSetPlayEvents"); - onSetPlayEvents(msg); - break; - - case kWhatOneShot: - SL_LOGV("kWhatOneShot"); - onOneShot(msg); - break; - - default: - SL_LOGE("GenericPlayer::onMessageReceived unknown message %d", msg->what()); - TRESPASS(); - } -} - - -//-------------------------------------------------- -// Event handlers -// it is strictly verboten to call those methods outside of the event loop - -void GenericPlayer::onPrepare() { - SL_LOGV("GenericPlayer::onPrepare()"); - // Subclass is responsible for indicating whether prepare was successful or unsuccessful - // by updating mStateFlags accordingly. It must set exactly one of these two flags. - assert(!(mStateFlags & kFlagPrepared) != !(mStateFlags & kFlagPreparedUnsuccessfully)); - notify(PLAYEREVENT_PREPARED, mStateFlags & kFlagPrepared ? PLAYER_SUCCESS : PLAYER_FAILURE, - true /*async*/); - SL_LOGD("GenericPlayer::onPrepare() done, mStateFlags=0x%x", mStateFlags); -} - - -void GenericPlayer::onNotify(const sp<AMessage> &msg) { - SL_LOGV("GenericPlayer::onNotify()"); - notif_cbf_t notifClient; - void* notifUser; - { - android::Mutex::Autolock autoLock(mNotifyClientLock); - if (NULL == mNotifyClient) { - return; - } else { - notifClient = mNotifyClient; - notifUser = mNotifyUser; - } - } - - int32_t val1, val2; - if (msg->findInt32(PLAYEREVENT_PREFETCHSTATUSCHANGE, &val1)) { - SL_LOGV("GenericPlayer notifying %s = %d", PLAYEREVENT_PREFETCHSTATUSCHANGE, val1); - notifClient(kEventPrefetchStatusChange, val1, 0, notifUser); - // There is exactly one notification per message, hence "else if" instead of "if" - } else if (msg->findInt32(PLAYEREVENT_PREFETCHFILLLEVELUPDATE, &val1)) { - SL_LOGV("GenericPlayer notifying %s = %d", PLAYEREVENT_PREFETCHFILLLEVELUPDATE, val1); - notifClient(kEventPrefetchFillLevelUpdate, val1, 0, notifUser); - } else if (msg->findInt32(PLAYEREVENT_ENDOFSTREAM, &val1)) { - SL_LOGV("GenericPlayer notifying %s = %d", PLAYEREVENT_ENDOFSTREAM, val1); - notifClient(kEventEndOfStream, val1, 0, notifUser); - } else if (msg->findInt32(PLAYEREVENT_PREPARED, &val1)) { - SL_LOGV("GenericPlayer notifying %s = %d", PLAYEREVENT_PREPARED, val1); - notifClient(kEventPrepared, val1, 0, notifUser); - } else if (msg->findInt32(PLAYEREVENT_CHANNEL_COUNT, &val1)) { - SL_LOGV("GenericPlayer notifying %s = %d", PLAYEREVENT_CHANNEL_COUNT, val1); - notifClient(kEventChannelCount, val1, 0, notifUser); - } else if (msg->findRect(PLAYEREVENT_VIDEO_SIZE_UPDATE, &val1, &val2, &val1, &val2)) { - SL_LOGV("GenericPlayer notifying %s = %d, %d", PLAYEREVENT_VIDEO_SIZE_UPDATE, val1, val2); - notifClient(kEventHasVideoSize, val1, val2, notifUser); - } else if (msg->findInt32(PLAYEREVENT_PLAY, &val1)) { - SL_LOGV("GenericPlayer notifying %s = %d", PLAYEREVENT_PLAY, val1); - notifClient(kEventPlay, val1, 0, notifUser); - } else if (msg->findInt32(PLAYEREVENT_ERRORAFTERPREPARE, &val1)) { - SL_LOGV("GenericPlayer notifying %s = %d", PLAYEREVENT_ERRORAFTERPREPARE, val1); - notifClient(kEventErrorAfterPrepare, val1, 0, notifUser); - } else { - SL_LOGV("GenericPlayer notifying unknown"); - } -} - - -void GenericPlayer::onPlay() { - SL_LOGD("GenericPlayer::onPlay()"); - if ((mStateFlags & (kFlagPrepared | kFlagPlaying)) == kFlagPrepared) { - SL_LOGD("starting player"); - mStateFlags |= kFlagPlaying; - updateOneShot(); - } -} - - -void GenericPlayer::onPause() { - SL_LOGD("GenericPlayer::onPause()"); - if (!(~mStateFlags & (kFlagPrepared | kFlagPlaying))) { - SL_LOGV("pausing player"); - mStateFlags &= ~kFlagPlaying; - updateOneShot(); - } -} - - -void GenericPlayer::onSeek(const sp<AMessage> &msg) { - SL_LOGV("GenericPlayer::onSeek"); -} - - -void GenericPlayer::onLoop(const sp<AMessage> &msg) { - SL_LOGV("GenericPlayer::onLoop"); -} - - -void GenericPlayer::onVolumeUpdate() { - SL_LOGV("GenericPlayer::onVolumeUpdate"); -} - - -void GenericPlayer::onSeekComplete() { - SL_LOGD("GenericPlayer::onSeekComplete()"); - mStateFlags &= ~kFlagSeeking; - // avoid spurious or lost events caused by seeking past a marker - mDeliveredNewPosMs = ANDROID_UNKNOWN_TIME; - mObservedPositionMs = ANDROID_UNKNOWN_TIME; - updateOneShot(); -} - - -void GenericPlayer::onBufferingUpdate(const sp<AMessage> &msg) { - SL_LOGV("GenericPlayer::onBufferingUpdate"); -} - - -void GenericPlayer::onSetBufferingUpdateThreshold(const sp<AMessage> &msg) { - SL_LOGV("GenericPlayer::onSetBufferingUpdateThreshold"); - int32_t thresholdPercent = 0; - if (msg->findInt32(WHATPARAM_BUFFERING_UPDATETHRESHOLD_PERCENT, &thresholdPercent)) { - Mutex::Autolock _l(mSettingsLock); - mCacheFillNotifThreshold = (int16_t)thresholdPercent; - } -} - - -void GenericPlayer::onAttachAuxEffect(const sp<AMessage> &msg) { - SL_LOGV("GenericPlayer::onAttachAuxEffect()"); -} - - -void GenericPlayer::onSetAuxEffectSendLevel(const sp<AMessage> &msg) { - SL_LOGV("GenericPlayer::onSetAuxEffectSendLevel()"); -} - - -void GenericPlayer::onSetPlayEvents(const sp<AMessage> &msg) { - SL_LOGV("GenericPlayer::onSetPlayEvents()"); - int32_t eventFlags, markerPositionMs, positionUpdatePeriodMs; - if (msg->findInt32(WHATPARAM_SETPLAYEVENTS_FLAGS, &eventFlags) && - msg->findInt32(WHATPARAM_SETPLAYEVENTS_MARKER, &markerPositionMs) && - msg->findInt32(WHATPARAM_SETPLAYEVENTS_UPDATE, &positionUpdatePeriodMs)) { - mEventFlags = eventFlags; - mMarkerPositionMs = markerPositionMs; - mPositionUpdatePeriodMs = positionUpdatePeriodMs; - updateOneShot(); - } -} - - -void GenericPlayer::onOneShot(const sp<AMessage> &msg) { - SL_LOGV("GenericPlayer::onOneShot()"); - int32_t generation; - if (msg->findInt32(WHATPARAM_ONESHOT_GENERATION, &generation)) { - if (generation != mOneShotGeneration) { - SL_LOGV("GenericPlayer::onOneShot() generation %d cancelled; latest is %d", - generation, mOneShotGeneration); - return; - } - updateOneShot(); - } -} - - -//------------------------------------------------- -void GenericPlayer::notifyStatus() { - SL_LOGV("GenericPlayer::notifyStatus"); - notify(PLAYEREVENT_PREFETCHSTATUSCHANGE, (int32_t)mCacheStatus, true /*async*/); -} - - -void GenericPlayer::notifyCacheFill() { - SL_LOGV("GenericPlayer::notifyCacheFill"); - mLastNotifiedCacheFill = mCacheFill; - notify(PLAYEREVENT_PREFETCHFILLLEVELUPDATE, (int32_t)mLastNotifiedCacheFill, true/*async*/); -} - - -void GenericPlayer::seekComplete() { - SL_LOGV("GenericPlayer::seekComplete"); - sp<AMessage> msg = new AMessage(kWhatSeekComplete, id()); - msg->post(); -} - - -void GenericPlayer::bufferingUpdate(int16_t fillLevelPerMille) { - SL_LOGV("GenericPlayer::bufferingUpdate"); - sp<AMessage> msg = new AMessage(kWhatBufferingUpdate, id()); - msg->setInt32(WHATPARAM_BUFFERING_UPDATE, fillLevelPerMille); - msg->post(); -} - - -// For the meaning of positionMs, see comment in declaration at android_GenericPlayer.h -void GenericPlayer::updateOneShot(int positionMs) -{ - SL_LOGV("GenericPlayer::updateOneShot"); - - // nop until prepared - if (!(mStateFlags & kFlagPrepared)) { - return; - } - - // cancel any pending one-shot(s) - ++mOneShotGeneration; - - // don't restart one-shot if player is paused or stopped - if (!(mStateFlags & kFlagPlaying)) { - return; - } - - // get current player position in milliseconds - if (positionMs < 0) { - positionMs = ANDROID_UNKNOWN_TIME; - } - if (positionMs == ANDROID_UNKNOWN_TIME) { - getPositionMsec(&positionMs); - // normalize it - if (positionMs < 0) { - positionMs = ANDROID_UNKNOWN_TIME; - } - if (ANDROID_UNKNOWN_TIME == positionMs) { - // getPositionMsec is not working for some reason, give up - //ALOGV("Does anyone really know what time it is?"); - return; - } - } - - // if we observe the player position going backwards, even without without a seek, then recover - if (mObservedPositionMs != ANDROID_UNKNOWN_TIME && positionMs < mObservedPositionMs) { - mDeliveredNewPosMs = ANDROID_UNKNOWN_TIME; - mObservedPositionMs = positionMs; - } - - // delayUs is the expected delay between current position and marker; - // the default is infinity in case there are no upcoming marker(s) - int64_t delayUs = -1; - - // is there a marker? - if ((mEventFlags & SL_PLAYEVENT_HEADATMARKER) && (mMarkerPositionMs != ANDROID_UNKNOWN_TIME)) { - // check to see if we have observed the position passing through the marker - if (mObservedPositionMs <= mMarkerPositionMs && mMarkerPositionMs <= positionMs) { - notify(PLAYEREVENT_PLAY, (int32_t) SL_PLAYEVENT_HEADATMARKER, true /*async*/); - } else if (positionMs < mMarkerPositionMs) { - delayUs = (mMarkerPositionMs - positionMs) * 1000LL; - } - } - - // are periodic position updates needed? - if ((mEventFlags & SL_PLAYEVENT_HEADATNEWPOS) && - (mPositionUpdatePeriodMs != ANDROID_UNKNOWN_TIME)) { - // check to see if we have observed the position passing through a virtual marker, where the - // virtual marker is at the previously delivered new position plus position update period - int32_t virtualMarkerMs; - if (mDeliveredNewPosMs != ANDROID_UNKNOWN_TIME) { - virtualMarkerMs = mDeliveredNewPosMs + mPositionUpdatePeriodMs; - } else if (mObservedPositionMs != ANDROID_UNKNOWN_TIME) { - virtualMarkerMs = mObservedPositionMs + mPositionUpdatePeriodMs; - // pretend there has been an update in the past - mDeliveredNewPosMs = mObservedPositionMs; - } else { - virtualMarkerMs = positionMs + mPositionUpdatePeriodMs; - // pretend there has been an update in the past - mDeliveredNewPosMs = positionMs; - } - // nextVirtualMarkerMs will be set to the position of the next upcoming virtual marker - int32_t nextVirtualMarkerMs; - if (mObservedPositionMs <= virtualMarkerMs && virtualMarkerMs <= positionMs) { - // we did pass through the virtual marker, now compute the next virtual marker - mDeliveredNewPosMs = virtualMarkerMs; - nextVirtualMarkerMs = virtualMarkerMs + mPositionUpdatePeriodMs; - // re-synchronize if we missed an update - if (nextVirtualMarkerMs <= positionMs) { - SL_LOGW("Missed SL_PLAYEVENT_HEADATNEWPOS for position %d; current position %d", - nextVirtualMarkerMs, positionMs); - // try to catch up by setting next goal to current position plus update period - mDeliveredNewPosMs = positionMs; - nextVirtualMarkerMs = positionMs + mPositionUpdatePeriodMs; - } - notify(PLAYEREVENT_PLAY, (int32_t) SL_PLAYEVENT_HEADATNEWPOS, true /*async*/); - } else { - // we did not pass through the virtual marker yet, so use same marker again - nextVirtualMarkerMs = virtualMarkerMs; - } - // note that if arithmetic overflow occurred, nextVirtualMarkerMs will be negative - if (positionMs < nextVirtualMarkerMs) { - int64_t trialDelayUs; - trialDelayUs = (nextVirtualMarkerMs - positionMs) * 1000LL; - if (trialDelayUs > 0 && (delayUs == -1 || trialDelayUs < delayUs)) { - delayUs = trialDelayUs; - } - } - } - - // we have a new observed position - mObservedPositionMs = positionMs; - - // post the new one-shot message if needed - if (advancesPositionInRealTime() && delayUs >= 0) { - // 20 ms min delay to avoid near busy waiting - if (delayUs < 20000LL) { - delayUs = 20000LL; - } - // 1 minute max delay avoids indefinite memory leaks caused by cancelled one-shots - if (delayUs > 60000000LL) { - delayUs = 60000000LL; - } - //SL_LOGI("delayUs = %lld", delayUs); - sp<AMessage> msg = new AMessage(kWhatOneShot, id()); - msg->setInt32(WHATPARAM_ONESHOT_GENERATION, mOneShotGeneration); - msg->post(delayUs); - } - -} - -} // namespace android diff --git a/wilhelm/src/android/android_GenericPlayer.h b/wilhelm/src/android/android_GenericPlayer.h deleted file mode 100644 index bc52846b..00000000 --- a/wilhelm/src/android/android_GenericPlayer.h +++ /dev/null @@ -1,228 +0,0 @@ -/* - * 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_GENERICPLAYER_H__ -#define __ANDROID_GENERICPLAYER_H__ - -#include <media/stagefright/foundation/AHandler.h> -#include <media/stagefright/foundation/ALooper.h> -#include <media/stagefright/foundation/AMessage.h> - -//-------------------------------------------------------------------------------------------------- -/** - * Message parameters for AHandler messages, see list in GenericPlayer::kWhatxxx - */ -#define WHATPARAM_SEEK_SEEKTIME_MS "seekTimeMs" -#define WHATPARAM_LOOP_LOOPING "looping" -#define WHATPARAM_BUFFERING_UPDATE "bufferingUpdate" -#define WHATPARAM_BUFFERING_UPDATETHRESHOLD_PERCENT "buffUpdateThreshold" -#define WHATPARAM_ATTACHAUXEFFECT "attachAuxEffect" -#define WHATPARAM_SETAUXEFFECTSENDLEVEL "setAuxEffectSendLevel" -// Parameters for kWhatSetPlayEvents -#define WHATPARAM_SETPLAYEVENTS_FLAGS "setPlayEventsFlags" -#define WHATPARAM_SETPLAYEVENTS_MARKER "setPlayEventsMarker" -#define WHATPARAM_SETPLAYEVENTS_UPDATE "setPlayEventsUpdate" -// Parameters for kWhatOneShot (see explanation at definition of kWhatOneShot below) -#define WHATPARAM_ONESHOT_GENERATION "oneShotGeneration" - -namespace android { - -// abstract base class -class GenericPlayer : public AHandler -{ -public: - - enum { - kEventPrepared = 'prep', - kEventHasVideoSize = 'vsiz', - kEventPrefetchStatusChange = 'pfsc', - kEventPrefetchFillLevelUpdate = 'pflu', - kEventEndOfStream = 'eos', - kEventChannelCount = 'ccnt', - kEventPlay = 'play', // SL_PLAYEVENT_* - kEventErrorAfterPrepare = 'easp', // error after successful prepare - }; - - - GenericPlayer(const AudioPlayback_Parameters* params); - virtual ~GenericPlayer(); - - void init(const notif_cbf_t cbf, void* notifUser); - virtual void preDestroy(); - - void setDataSource(const char *uri); - void setDataSource(int fd, int64_t offset, int64_t length, bool closeAfterUse = false); - - void prepare(); - virtual void play(); - void pause(); - void stop(); - // timeMsec must be >= 0 or == ANDROID_UNKNOWN_TIME (used by StreamPlayer after discontinuity) - void seek(int64_t timeMsec); - void loop(bool loop); - void setBufferingUpdateThreshold(int16_t thresholdPercent); - - void getDurationMsec(int* msec); //msec != NULL, ANDROID_UNKNOWN_TIME if unknown - virtual void getPositionMsec(int* msec) = 0; //msec != NULL, ANDROID_UNKNOWN_TIME if unknown - - virtual void setVideoSurfaceTexture(const sp<ISurfaceTexture> &surfaceTexture) {} - - void setVolume(float leftVol, float rightVol); - void attachAuxEffect(int32_t effectId); - void setAuxEffectSendLevel(float level); - - // Call after changing any of the IPlay settings related to SL_PLAYEVENT_* - void setPlayEvents(int32_t eventFlags, int32_t markerPosition, int32_t positionUpdatePeriod); - -protected: - // mutex used for set vs use of volume, duration, and cache (fill, threshold) settings - Mutex mSettingsLock; - - void resetDataLocator(); - DataLocator2 mDataLocator; - int mDataLocatorType; - - // Constants used to identify the messages in this player's AHandler message loop - // in onMessageReceived() - enum { - kWhatPrepare = 'prep', // start preparation - kWhatNotif = 'noti', // send a notification to client - kWhatPlay = 'play', // start player - kWhatPause = 'paus', // pause or stop player - kWhatSeek = 'seek', // request a seek to specified position - kWhatSeekComplete = 'skcp', // seek request has completed - kWhatLoop = 'loop', // set the player's looping status - kWhatVolumeUpdate = 'volu', // set the channel gains to specified values - kWhatBufferingUpdate = 'bufu', - kWhatBuffUpdateThres = 'buut', - kWhatAttachAuxEffect = 'aaux', - kWhatSetAuxEffectSendLevel = 'saux', - kWhatSetPlayEvents = 'spev', // process new IPlay settings related to SL_PLAYEVENT_* - kWhatOneShot = 'ones', // deferred (non-0 timeout) handler for SL_PLAYEVENT_* - // As used here, "one-shot" is the software equivalent of a "retriggerable monostable - // multivibrator" from electronics. Briefly, a one-shot is a timer that can be triggered - // to fire at some point in the future. It is "retriggerable" because while the timer - // is active, it is possible to replace the current timeout value by a new value. - // This is done by cancelling the current timer (using a generation count), - // and then posting another timer with the new desired value. - }; - - // Send a notification to one of the event listeners - virtual void notify(const char* event, int data1, bool async); - virtual void notify(const char* event, int data1, int data2, bool async); - - // AHandler implementation - virtual void onMessageReceived(const sp<AMessage> &msg); - - // Async event handlers (called from GenericPlayer's event loop) - virtual void onPrepare(); - virtual void onNotify(const sp<AMessage> &msg); - virtual void onPlay(); - virtual void onPause(); - virtual void onSeek(const sp<AMessage> &msg); - virtual void onLoop(const sp<AMessage> &msg); - virtual void onVolumeUpdate(); - virtual void onSeekComplete(); - virtual void onBufferingUpdate(const sp<AMessage> &msg); - virtual void onSetBufferingUpdateThreshold(const sp<AMessage> &msg); - virtual void onAttachAuxEffect(const sp<AMessage> &msg); - virtual void onSetAuxEffectSendLevel(const sp<AMessage> &msg); - void onSetPlayEvents(const sp<AMessage> &msg); - void onOneShot(const sp<AMessage> &msg); - - // Convenience methods - // for async notifications of prefetch status and cache fill level, needs to be called - // with mSettingsLock locked - void notifyStatus(); - void notifyCacheFill(); - // for internal async notification to update state that the player is no longer seeking - void seekComplete(); - void bufferingUpdate(int16_t fillLevelPerMille); - - // Event notification from GenericPlayer to OpenSL ES / OpenMAX AL framework - notif_cbf_t mNotifyClient; - void* mNotifyUser; - // lock to protect mNotifyClient and mNotifyUser updates - Mutex mNotifyClientLock; - - // Bits for mStateFlags - enum { - kFlagPrepared = 1 << 0, // use only for successful preparation - kFlagPreparing = 1 << 1, - kFlagPlaying = 1 << 2, - kFlagBuffering = 1 << 3, - kFlagSeeking = 1 << 4, // set if we (not Stagefright) initiated a seek - kFlagLooping = 1 << 5, // set if looping is enabled - kFlagPreparedUnsuccessfully = 1 << 6, - }; - - // Only accessed from event loop, does not need a mutex - uint32_t mStateFlags; - - sp<ALooper> mLooper; - - const AudioPlayback_Parameters mPlaybackParams; - - // protected by mSettingsLock after construction - AndroidAudioLevels mAndroidAudioLevels; - - // protected by mSettingsLock - int32_t mDurationMsec; - - CacheStatus_t mCacheStatus; - int16_t mCacheFill; // cache fill level + played back level in permille - int16_t mLastNotifiedCacheFill; // last cache fill level communicated to the listener - int16_t mCacheFillNotifThreshold; // threshold in cache fill level for cache fill to be reported - - // Call any time any of the IPlay copies, current position, or play state changes, and - // supply the latest known position or ANDROID_UNKNOWN_TIME if position is unknown to caller. - void updateOneShot(int positionMs = ANDROID_UNKNOWN_TIME); - - virtual bool advancesPositionInRealTime() const { return true; } - -private: - - // Our copy of some important IPlay member variables, except in Android units - int32_t mEventFlags; - int32_t mMarkerPositionMs; - int32_t mPositionUpdatePeriodMs; - - // We need to be able to cancel any pending one-shot event(s) prior to posting - // a new one-shot. As AMessage does not currently support cancellation by - // "what" category, we simulate this by keeping a generation counter for - // one-shots. When a one-shot event is delivered, it checks to see if it is - // still the current one-shot. If not, it returns immediately, thus - // effectively cancelling itself. Note that counter wrap-around is possible - // but unlikely and benign. - int32_t mOneShotGeneration; - - // Play position at time of the most recently delivered SL_PLAYEVENT_HEADATNEWPOS, - // or ANDROID_UNKNOWN_TIME if a SL_PLAYEVENT_HEADATNEWPOS has never been delivered. - int32_t mDeliveredNewPosMs; - - // Play position most recently observed by updateOneShot, or ANDROID_UNKNOWN_TIME - // if the play position has never been observed. - int32_t mObservedPositionMs; - - DISALLOW_EVIL_CONSTRUCTORS(GenericPlayer); -}; - -} // namespace android - -extern void android_player_volumeUpdate(float *pVolumes /*[2]*/, const IVolume *volumeItf, - unsigned channelCount, float amplFromDirectLevel, const bool *audibilityFactors /*[2]*/); - -#endif /* __ANDROID_GENERICPLAYER_H__ */ diff --git a/wilhelm/src/android/android_LocAVPlayer.cpp b/wilhelm/src/android/android_LocAVPlayer.cpp deleted file mode 100644 index 90e7b5fe..00000000 --- a/wilhelm/src/android/android_LocAVPlayer.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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. - */ - -//#define USE_LOG SLAndroidLogLevel_Verbose - -#include "sles_allinclusive.h" -#include <media/IMediaPlayerService.h> -#include "android_LocAVPlayer.h" - - -namespace android { - -//-------------------------------------------------------------------------------------------------- -LocAVPlayer::LocAVPlayer(const AudioPlayback_Parameters* params, bool hasVideo) : - GenericMediaPlayer(params, hasVideo) -{ - SL_LOGD("LocAVPlayer::LocAVPlayer()"); - -} - - -LocAVPlayer::~LocAVPlayer() { - SL_LOGD("LocAVPlayer::~LocAVPlayer()"); - -} - - -//-------------------------------------------------- -// Event handlers -void LocAVPlayer::onPrepare() { - SL_LOGD("LocAVPlayer::onPrepare()"); - sp<IMediaPlayerService> mediaPlayerService(getMediaPlayerService()); - if (mediaPlayerService != NULL) { - switch (mDataLocatorType) { - case kDataLocatorUri: - mPlayer = mediaPlayerService->create(getpid(), mPlayerClient /*IMediaPlayerClient*/, - mPlaybackParams.sessionId); - if (mPlayer == NULL) { - SL_LOGE("media player service failed to create player by URI"); - } else if (mPlayer->setDataSource(mDataLocator.uriRef, NULL /*headers*/) != NO_ERROR) { - SL_LOGE("setDataSource failed"); - mPlayer.clear(); - } - break; - case kDataLocatorFd: - mPlayer = mediaPlayerService->create(getpid(), mPlayerClient /*IMediaPlayerClient*/, - mPlaybackParams.sessionId); - if (mPlayer == NULL) { - SL_LOGE("media player service failed to create player by FD"); - } else if (mPlayer->setDataSource(mDataLocator.fdi.fd, mDataLocator.fdi.offset, - mDataLocator.fdi.length) != NO_ERROR) { - SL_LOGE("setDataSource failed"); - mPlayer.clear(); - } - // Binder dups the fd for use by mediaserver, so if we own the fd then OK to close now - if (mDataLocator.fdi.mCloseAfterUse) { - (void) ::close(mDataLocator.fdi.fd); - mDataLocator.fdi.fd = -1; - mDataLocator.fdi.mCloseAfterUse = false; - } - break; - case kDataLocatorNone: - SL_LOGE("no data locator for MediaPlayer object"); - break; - default: - SL_LOGE("unsupported data locator %d for MediaPlayer object", mDataLocatorType); - break; - } - } - if (mPlayer == NULL) { - mStateFlags |= kFlagPreparedUnsuccessfully; - } - // blocks until mPlayer is prepared - GenericMediaPlayer::onPrepare(); - SL_LOGD("LocAVPlayer::onPrepare() done"); -} - -} // namespace android diff --git a/wilhelm/src/android/android_LocAVPlayer.h b/wilhelm/src/android/android_LocAVPlayer.h deleted file mode 100644 index da961fbb..00000000 --- a/wilhelm/src/android/android_LocAVPlayer.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ - -#include "android_GenericMediaPlayer.h" - -namespace android { - -//-------------------------------------------------------------------------------------------------- -class LocAVPlayer : public GenericMediaPlayer -{ -public: - LocAVPlayer(const AudioPlayback_Parameters* params, bool hasVideo); - virtual ~LocAVPlayer(); - -protected: - // overridden from AVPlayer - virtual void onPrepare(); - -private: - DISALLOW_EVIL_CONSTRUCTORS(LocAVPlayer); -}; - -} // namespace android diff --git a/wilhelm/src/android/android_StreamPlayer.cpp b/wilhelm/src/android/android_StreamPlayer.cpp deleted file mode 100644 index ade52807..00000000 --- a/wilhelm/src/android/android_StreamPlayer.cpp +++ /dev/null @@ -1,418 +0,0 @@ -/* - * 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. - */ - -//#define USE_LOG SLAndroidLogLevel_Verbose - -#include "sles_allinclusive.h" -#include "android_StreamPlayer.h" - -#include <media/IStreamSource.h> -#include <media/IMediaPlayerService.h> -#include <media/stagefright/foundation/ADebug.h> -#include <binder/IPCThreadState.h> - -#include "mpeg2ts/ATSParser.h" - -//-------------------------------------------------------------------------------------------------- -namespace android { - -StreamSourceAppProxy::StreamSourceAppProxy( - IAndroidBufferQueue *androidBufferQueue, - const sp<CallbackProtector> &callbackProtector, - // sp<StreamPlayer> would cause StreamPlayer's destructor to run during it's own - // construction. If you pass in a sp<> to 'this' inside a constructor, then first the - // refcount is increased from 0 to 1, then decreased from 1 to 0, which causes the object's - // destructor to run from inside it's own constructor. - StreamPlayer * /* const sp<StreamPlayer> & */ player) : - mBuffersHasBeenSet(false), - mAndroidBufferQueue(androidBufferQueue), - mCallbackProtector(callbackProtector), - mPlayer(player) -{ - SL_LOGV("StreamSourceAppProxy::StreamSourceAppProxy()"); -} - -StreamSourceAppProxy::~StreamSourceAppProxy() { - SL_LOGV("StreamSourceAppProxy::~StreamSourceAppProxy()"); - disconnect(); -} - -const SLuint32 StreamSourceAppProxy::kItemProcessed[NB_BUFFEREVENT_ITEM_FIELDS] = { - SL_ANDROID_ITEMKEY_BUFFERQUEUEEVENT, // item key - sizeof(SLuint32), // item size - SL_ANDROIDBUFFERQUEUEEVENT_PROCESSED // item data -}; - -//-------------------------------------------------- -// IStreamSource implementation -void StreamSourceAppProxy::setListener(const sp<IStreamListener> &listener) { - assert(listener != NULL); - Mutex::Autolock _l(mLock); - assert(mListener == NULL); - mListener = listener; -} - -void StreamSourceAppProxy::setBuffers(const Vector<sp<IMemory> > &buffers) { - Mutex::Autolock _l(mLock); - assert(!mBuffersHasBeenSet); - mBuffers = buffers; - mBuffersHasBeenSet = true; -} - -void StreamSourceAppProxy::onBufferAvailable(size_t index) { - //SL_LOGD("StreamSourceAppProxy::onBufferAvailable(%d)", index); - - { - Mutex::Autolock _l(mLock); - // assert not needed because if not set, size() will be zero and the CHECK_LT will also fail - // assert(mBuffersHasBeenSet); - CHECK_LT(index, mBuffers.size()); -#if 0 // enable if needed for debugging - sp<IMemory> mem = mBuffers.itemAt(index); - SLAint64 length = (SLAint64) mem->size(); -#endif - mAvailableBuffers.push_back(index); - //SL_LOGD("onBufferAvailable() now %d buffers available in queue", - // mAvailableBuffers.size()); - } - - // a new shared mem buffer is available: let's try to fill immediately - pullFromBuffQueue(); -} - -void StreamSourceAppProxy::receivedCmd_l(IStreamListener::Command cmd, const sp<AMessage> &msg) { - if (mListener != 0) { - mListener->issueCommand(cmd, false /* synchronous */, msg); - } -} - -void StreamSourceAppProxy::receivedBuffer_l(size_t buffIndex, size_t buffLength) { - if (mListener != 0) { - mListener->queueBuffer(buffIndex, buffLength); - } -} - -void StreamSourceAppProxy::disconnect() { - Mutex::Autolock _l(mLock); - mListener.clear(); - // Force binder to push the decremented reference count for sp<IStreamListener>. - // mediaserver and client both have sp<> to the other. When you decrement an sp<> - // reference count, binder doesn't push that to the other process immediately. - IPCThreadState::self()->flushCommands(); - mBuffers.clear(); - mBuffersHasBeenSet = false; - mAvailableBuffers.clear(); -} - -//-------------------------------------------------- -// consumption from ABQ: pull from the ABQ, and push to shared memory (media server) -void StreamSourceAppProxy::pullFromBuffQueue() { - - if (android::CallbackProtector::enterCbIfOk(mCallbackProtector)) { - - size_t bufferId; - void* bufferLoc; - size_t buffSize; - - slAndroidBufferQueueCallback callback = NULL; - void* pBufferContext, *pBufferData, *callbackPContext = NULL; - AdvancedBufferHeader *oldFront = NULL; - uint32_t dataSize /* , dataUsed */; - - // retrieve data from the buffer queue - interface_lock_exclusive(mAndroidBufferQueue); - - // can this read operation cause us to call the buffer queue callback - // (either because there was a command with no data, or all the data has been consumed) - bool queueCallbackCandidate = false; - - if (mAndroidBufferQueue->mState.count != 0) { - // SL_LOGD("nbBuffers in ABQ = %u, buffSize=%u",abq->mState.count, buffSize); - assert(mAndroidBufferQueue->mFront != mAndroidBufferQueue->mRear); - - oldFront = mAndroidBufferQueue->mFront; - AdvancedBufferHeader *newFront = &oldFront[1]; - - // consume events when starting to read data from a buffer for the first time - if (oldFront->mDataSizeConsumed == 0) { - // note this code assumes at most one event per buffer; see IAndroidBufferQueue_Enqueue - if (oldFront->mItems.mTsCmdData.mTsCmdCode & ANDROID_MP2TSEVENT_EOS) { - receivedCmd_l(IStreamListener::EOS); - // EOS has no associated data - queueCallbackCandidate = true; - } else if (oldFront->mItems.mTsCmdData.mTsCmdCode & ANDROID_MP2TSEVENT_DISCONTINUITY) { - receivedCmd_l(IStreamListener::DISCONTINUITY); - } else if (oldFront->mItems.mTsCmdData.mTsCmdCode & ANDROID_MP2TSEVENT_DISCON_NEWPTS) { - sp<AMessage> msg = new AMessage(); - msg->setInt64(IStreamListener::kKeyResumeAtPTS, - (int64_t)oldFront->mItems.mTsCmdData.mPts); - receivedCmd_l(IStreamListener::DISCONTINUITY, msg /*msg*/); - } else if (oldFront->mItems.mTsCmdData.mTsCmdCode - & ANDROID_MP2TSEVENT_FORMAT_CHANGE_FULL) { - sp<AMessage> msg = new AMessage(); - msg->setInt32( - IStreamListener::kKeyDiscontinuityMask, - ATSParser::DISCONTINUITY_FORMATCHANGE); - receivedCmd_l(IStreamListener::DISCONTINUITY, msg /*msg*/); - } else if (oldFront->mItems.mTsCmdData.mTsCmdCode - & ANDROID_MP2TSEVENT_FORMAT_CHANGE_VIDEO) { - sp<AMessage> msg = new AMessage(); - msg->setInt32( - IStreamListener::kKeyDiscontinuityMask, - ATSParser::DISCONTINUITY_VIDEO_FORMAT); - receivedCmd_l(IStreamListener::DISCONTINUITY, msg /*msg*/); - } - // note that here we are intentionally only supporting - // ANDROID_MP2TSEVENT_FORMAT_CHANGE_VIDEO, see IAndroidBufferQueue.c - - // some commands may introduce a time discontinuity, reevaluate position if needed - if (oldFront->mItems.mTsCmdData.mTsCmdCode & (ANDROID_MP2TSEVENT_DISCONTINUITY | - ANDROID_MP2TSEVENT_DISCON_NEWPTS | ANDROID_MP2TSEVENT_FORMAT_CHANGE_FULL)) { - const sp<StreamPlayer> player(mPlayer.promote()); - if (player != NULL) { - // FIXME see note at onSeek - player->seek(ANDROID_UNKNOWN_TIME); - } - } - oldFront->mItems.mTsCmdData.mTsCmdCode = ANDROID_MP2TSEVENT_NONE; - } - - { - // we're going to change the shared mem buffer queue, so lock it - Mutex::Autolock _l(mLock); - if (!mAvailableBuffers.empty()) { - bufferId = *mAvailableBuffers.begin(); - CHECK_LT(bufferId, mBuffers.size()); - sp<IMemory> mem = mBuffers.itemAt(bufferId); - bufferLoc = mem->pointer(); - buffSize = mem->size(); - - char *pSrc = ((char*)oldFront->mDataBuffer) + oldFront->mDataSizeConsumed; - if (oldFront->mDataSizeConsumed + buffSize < oldFront->mDataSize) { - // more available than requested, copy as much as requested - // consume data: 1/ copy to given destination - memcpy(bufferLoc, pSrc, buffSize); - // 2/ keep track of how much has been consumed - oldFront->mDataSizeConsumed += buffSize; - // 3/ notify shared mem listener that new data is available - receivedBuffer_l(bufferId, buffSize); - mAvailableBuffers.erase(mAvailableBuffers.begin()); - } else { - // requested as much available or more: consume the whole of the current - // buffer and move to the next - size_t consumed = oldFront->mDataSize - oldFront->mDataSizeConsumed; - //SL_LOGD("consuming rest of buffer: enqueueing=%u", consumed); - oldFront->mDataSizeConsumed = oldFront->mDataSize; - - // move queue to next - if (newFront == &mAndroidBufferQueue-> - mBufferArray[mAndroidBufferQueue->mNumBuffers + 1]) { - // reached the end, circle back - newFront = mAndroidBufferQueue->mBufferArray; - } - mAndroidBufferQueue->mFront = newFront; - mAndroidBufferQueue->mState.count--; - mAndroidBufferQueue->mState.index++; - - if (consumed > 0) { - // consume data: 1/ copy to given destination - memcpy(bufferLoc, pSrc, consumed); - // 2/ keep track of how much has been consumed - // here nothing to do because we are done with this buffer - // 3/ notify StreamPlayer that new data is available - receivedBuffer_l(bufferId, consumed); - mAvailableBuffers.erase(mAvailableBuffers.begin()); - } - - // data has been consumed, and the buffer queue state has been updated - // we will notify the client if applicable - queueCallbackCandidate = true; - } - } - - if (queueCallbackCandidate) { - if (mAndroidBufferQueue->mCallbackEventsMask & - SL_ANDROIDBUFFERQUEUEEVENT_PROCESSED) { - callback = mAndroidBufferQueue->mCallback; - // save callback data while under lock - callbackPContext = mAndroidBufferQueue->mContext; - pBufferContext = (void *)oldFront->mBufferContext; - pBufferData = (void *)oldFront->mDataBuffer; - dataSize = oldFront->mDataSize; - // here a buffer is only dequeued when fully consumed - //dataUsed = oldFront->mDataSizeConsumed; - } - } - //SL_LOGD("%d buffers available after reading from queue", mAvailableBuffers.size()); - if (!mAvailableBuffers.empty()) { - // there is still room in the shared memory, recheck later if we can pull - // data from the buffer queue and write it to shared memory - const sp<StreamPlayer> player(mPlayer.promote()); - if (player != NULL) { - player->queueRefilled(); - } - } - } - - } else { // empty queue - SL_LOGD("ABQ empty, starving!"); - } - - interface_unlock_exclusive(mAndroidBufferQueue); - - // notify client of buffer processed - if (NULL != callback) { - SLresult result = (*callback)(&mAndroidBufferQueue->mItf, callbackPContext, - pBufferContext, pBufferData, dataSize, - dataSize, /* dataUsed */ - // no messages during playback other than marking the buffer as processed - (const SLAndroidBufferItem*)(&kItemProcessed) /* pItems */, - NB_BUFFEREVENT_ITEM_FIELDS *sizeof(SLuint32) /* itemsLength */ ); - if (SL_RESULT_SUCCESS != result) { - // Reserved for future use - SL_LOGW("Unsuccessful result %d returned from AndroidBufferQueueCallback", result); - } - } - - mCallbackProtector->exitCb(); - } // enterCbIfOk -} - - -//-------------------------------------------------------------------------------------------------- -StreamPlayer::StreamPlayer(const AudioPlayback_Parameters* params, bool hasVideo, - IAndroidBufferQueue *androidBufferQueue, const sp<CallbackProtector> &callbackProtector) : - GenericMediaPlayer(params, hasVideo), - mAppProxy(new StreamSourceAppProxy(androidBufferQueue, callbackProtector, this)), - mStopForDestroyCompleted(false) -{ - SL_LOGD("StreamPlayer::StreamPlayer()"); -} - -StreamPlayer::~StreamPlayer() { - SL_LOGD("StreamPlayer::~StreamPlayer()"); - mAppProxy->disconnect(); -} - - -void StreamPlayer::onMessageReceived(const sp<AMessage> &msg) { - switch (msg->what()) { - case kWhatPullFromAbq: - onPullFromAndroidBufferQueue(); - break; - - case kWhatStopForDestroy: - onStopForDestroy(); - break; - - default: - GenericMediaPlayer::onMessageReceived(msg); - break; - } -} - - -void StreamPlayer::preDestroy() { - // FIXME NuPlayerDriver is currently not thread-safe, so stop() must be called by looper - (new AMessage(kWhatStopForDestroy, id()))->post(); - { - Mutex::Autolock _l(mStopForDestroyLock); - while (!mStopForDestroyCompleted) { - mStopForDestroyCondition.wait(mStopForDestroyLock); - } - } - // GenericMediaPlayer::preDestroy will repeat some of what we've done, but that's benign - GenericMediaPlayer::preDestroy(); -} - - -void StreamPlayer::onStopForDestroy() { - if (mPlayer != 0) { - mPlayer->stop(); - // causes CHECK failure in Nuplayer - //mPlayer->setDataSource(NULL); - mPlayer->setVideoSurfaceTexture(NULL); - mPlayer->disconnect(); - mPlayer.clear(); - { - // FIXME ugh make this a method - Mutex::Autolock _l(mPreparedPlayerLock); - mPreparedPlayer.clear(); - } - } - { - Mutex::Autolock _l(mStopForDestroyLock); - mStopForDestroyCompleted = true; - } - mStopForDestroyCondition.signal(); -} - - -/** - * Asynchronously notify the player that the queue is ready to be pulled from. - */ -void StreamPlayer::queueRefilled() { - // async notification that the ABQ was refilled: the player should pull from the ABQ, and - // and push to shared memory (to the media server) - (new AMessage(kWhatPullFromAbq, id()))->post(); -} - - -void StreamPlayer::appClear_l() { - // the user of StreamPlayer has cleared its AndroidBufferQueue: - // there's no clear() for the shared memory queue, so this is a no-op -} - - -//-------------------------------------------------- -// Event handlers -void StreamPlayer::onPrepare() { - SL_LOGD("StreamPlayer::onPrepare()"); - sp<IMediaPlayerService> mediaPlayerService(getMediaPlayerService()); - if (mediaPlayerService != NULL) { - mPlayer = mediaPlayerService->create(getpid(), mPlayerClient /*IMediaPlayerClient*/, - mPlaybackParams.sessionId); - if (mPlayer == NULL) { - SL_LOGE("media player service failed to create player by app proxy"); - } else if (mPlayer->setDataSource(mAppProxy /*IStreamSource*/) != NO_ERROR) { - SL_LOGE("setDataSource failed"); - mPlayer.clear(); - } - } - if (mPlayer == NULL) { - mStateFlags |= kFlagPreparedUnsuccessfully; - } - GenericMediaPlayer::onPrepare(); - SL_LOGD("StreamPlayer::onPrepare() done"); -} - - -void StreamPlayer::onPlay() { - SL_LOGD("StreamPlayer::onPlay()"); - // enqueue a message that will cause StreamAppProxy to consume from the queue (again if the - // player had starved the shared memory) - queueRefilled(); - - GenericMediaPlayer::onPlay(); -} - - -void StreamPlayer::onPullFromAndroidBufferQueue() { - SL_LOGD("StreamPlayer::onPullFromAndroidBufferQueue()"); - mAppProxy->pullFromBuffQueue(); -} - -} // namespace android diff --git a/wilhelm/src/android/android_StreamPlayer.h b/wilhelm/src/android/android_StreamPlayer.h deleted file mode 100644 index cb47dbd0..00000000 --- a/wilhelm/src/android/android_StreamPlayer.h +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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. - */ - -#include <media/IStreamSource.h> -#include <binder/IServiceManager.h> -#include "android/android_GenericMediaPlayer.h" - -// number of SLuint32 fields to store a buffer event message in an item, by mapping each -// to the item key (SLuint32), the item size (SLuint32), and the item data (mask on SLuint32) -#define NB_BUFFEREVENT_ITEM_FIELDS 3 - -//-------------------------------------------------------------------------------------------------- -namespace android { - -//-------------------------------------------------------------------------------------------------- -class StreamPlayer; - -class StreamSourceAppProxy : public BnStreamSource { -public: - StreamSourceAppProxy( - IAndroidBufferQueue *androidBufferQueue, - const sp<CallbackProtector> &callbackProtector, - StreamPlayer *player); - virtual ~StreamSourceAppProxy(); - - // store an item structure to indicate a processed buffer - static const SLuint32 kItemProcessed[NB_BUFFEREVENT_ITEM_FIELDS]; - - // IStreamSource implementation - virtual void setListener(const sp<IStreamListener> &listener); // mediaserver calls exactly once - virtual void setBuffers(const Vector<sp<IMemory> > &buffers); // mediaserver calls exactly once - virtual void onBufferAvailable(size_t index); - - // Consumption from ABQ - void pullFromBuffQueue(); - -private: - void receivedCmd_l(IStreamListener::Command cmd, const sp<AMessage> &msg = NULL); - void receivedBuffer_l(size_t buffIndex, size_t buffLength); - -public: - // Call at least once prior to releasing the last strong reference to this object. It causes - // the player to release all of its resources, similar to android.media.MediaPlayer disconnect. - void disconnect(); - -private: - // protects mListener, mBuffers, mBuffersHasBeenSet, and mAvailableBuffers - Mutex mLock; - - sp<IStreamListener> mListener; - // array of shared memory buffers - Vector<sp<IMemory> > mBuffers; - bool mBuffersHasBeenSet; - // list of available buffers in shared memory, identified by their index - List<size_t> mAvailableBuffers; - - // the Android Buffer Queue from which data is consumed and written to shared memory - IAndroidBufferQueue* const mAndroidBufferQueue; - - const sp<CallbackProtector> mCallbackProtector; - const wp<StreamPlayer> mPlayer; - - DISALLOW_EVIL_CONSTRUCTORS(StreamSourceAppProxy); -}; - - -//-------------------------------------------------------------------------------------------------- -class StreamPlayer : public GenericMediaPlayer -{ -public: - StreamPlayer(const AudioPlayback_Parameters* params, bool hasVideo, - IAndroidBufferQueue *androidBufferQueue, const sp<CallbackProtector> &callbackProtector); - virtual ~StreamPlayer(); - - // overridden from GenericPlayer - virtual void onMessageReceived(const sp<AMessage> &msg); - virtual void preDestroy(); - - void queueRefilled(); - // Called after AndroidBufferQueue::Clear. - // The "_l" indicates the caller still has it's (now empty) AndroidBufferQueue locked. - void appClear_l(); - -protected: - - enum { - // message to asynchronously notify mAppProxy it should try to pull from the Android - // Buffer Queue and push to shared memory (media server), either because the buffer queue - // was refilled, or because during playback, the shared memory buffers should remain - // filled to prevent it from draining (this can happen if the ABQ is not ready - // whenever a shared memory buffer becomes available) - kWhatPullFromAbq = 'plfq', - kWhatStopForDestroy = 's4ds' - }; - - const sp<StreamSourceAppProxy> mAppProxy; // application proxy for the shared memory source - - // overridden from GenericMediaPlayer - virtual void onPrepare(); - virtual void onPlay(); - - void onPullFromAndroidBufferQueue(); - -private: - void onStopForDestroy(); - - Mutex mStopForDestroyLock; - Condition mStopForDestroyCondition; - bool mStopForDestroyCompleted; - - DISALLOW_EVIL_CONSTRUCTORS(StreamPlayer); -}; - -} // namespace android diff --git a/wilhelm/src/android/android_defs.h b/wilhelm/src/android/android_defs.h deleted file mode 100644 index 85192263..00000000 --- a/wilhelm/src/android/android_defs.h +++ /dev/null @@ -1,210 +0,0 @@ -/* - * 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. - */ - - -/** - * Used to define the mapping from an OpenSL ES or OpenMAX AL object to an Android - * media framework object - */ -enum AndroidObjectType { - INVALID_TYPE =-1, - // audio player, playing from a URI or FD data source - AUDIOPLAYER_FROM_URIFD = 0, - // audio player, playing PCM buffers in a buffer queue data source - AUDIOPLAYER_FROM_PCM_BUFFERQUEUE = 1, - // audio player, playing transport stream packets in an Android buffer queue data source - AUDIOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE = 2, - // audio player, decoding from a URI or FD data source to a buffer queue data sink in PCM format - AUDIOPLAYER_FROM_URIFD_TO_PCM_BUFFERQUEUE = 3, - // audio video player, playing transport stream packets in an Android buffer queue data source - AUDIOVIDEOPLAYER_FROM_TS_ANDROIDBUFFERQUEUE = 4, - // audio video player, playing from a URI or FD data source - AUDIOVIDEOPLAYER_FROM_URIFD = 5, - // audio recorder, recording from an input device data source, streamed into a - // PCM buffer queue data sink - AUDIORECORDER_FROM_MIC_TO_PCM_BUFFERQUEUE = 6, - // audio player, decoding from an Android buffer queue with ADTS data, - // to a buffer queue data sink in PCM format - AUDIOPLAYER_FROM_ADTS_ABQ_TO_PCM_BUFFERQUEUE = 7, - NUM_AUDIOPLAYER_MAP_TYPES -}; - - -/** - * Used to define the states of the OpenSL ES / OpenMAX AL object initialization and preparation - * with regards to the Android-side of the data, in particular as affected by the play state. - */ -enum AndroidObjectState { - ANDROID_UNINITIALIZED = -1, // never called SetPlayState(PAUSED or PLAYING) - ANDROID_PREPARING, // currently preparing due to first SetPlayState(PAUSED or PLAYING) - ANDROID_READY, // preparation has completed, and will not be attempted again - // NUM_ANDROID_STATES // unused -}; - - -#define ANDROID_DEFAULT_OUTPUT_STREAM_TYPE AUDIO_STREAM_MUSIC - -#define PLAYER_FAILURE ((int32_t) android::UNKNOWN_ERROR) -#define PLAYER_SUCCESS ((int32_t) android::NO_ERROR) - -#define PLAYER_FD_FIND_FILE_SIZE ((int64_t)0xFFFFFFFFFFFFFFFFll) - -#define MPEG2_TS_PACKET_SIZE 188 -#define MPEG2_TS_PACKET_SYNC 0x47 - -struct AudioPlayback_Parameters { - audio_stream_type_t streamType; - int sessionId; -}; - -/** - * Structure to maintain the set of audio levels about a player - */ -struct AndroidAudioLevels { - /** - * Send level to aux effect, there's a single aux bus, so there's a single level - */ - // FIXME not used yet, will be used when supporting effects in OpenMAX AL - //SLmillibel mAuxSendLevel; - /** - * Attenuation factor derived from direct level - */ - // FIXME not used yet, will be used when supporting effects in OpenMAX AL - //float mAmplFromDirectLevel; - /** - * Android Left/Right volume - * The final volume of an Android AudioTrack or MediaPlayer is a stereo amplification - * (or attenuation) represented as a float from 0.0f to 1.0f - */ - float mFinalVolume[STEREO_CHANNELS]; -}; - - -/** - * Event notification callback from Android to SL ES framework - */ -typedef void (*notif_cbf_t)(int event, int data1, int data2, void* notifUser); - -/** - * Audio data push callback from Android objects to SL ES framework - */ -typedef size_t (*data_push_cbf_t)(const uint8_t *data, size_t size, CAudioPlayer* ap); - - -/** - * Events sent to mNotifyClient during prepare, prefetch, and playback - * used in APlayer::notify() and AMessage::findxxx() - */ -#define PLAYEREVENT_PREPARED "prep" -#define PLAYEREVENT_PREFETCHSTATUSCHANGE "prsc" -#define PLAYEREVENT_PREFETCHFILLLEVELUPDATE "pflu" -#define PLAYEREVENT_ENDOFSTREAM "eos" -#define PLAYEREVENT_VIDEO_SIZE_UPDATE "vsiz" -#define PLAYEREVENT_CHANNEL_COUNT "ccnt" // channel count is now known -#define PLAYEREVENT_PLAY "play" // SL_PLAYEVENT_* -#define PLAYEREVENT_ERRORAFTERPREPARE "easp" // error after successful prepare - - -/** - * Time value when time is unknown. Used for instance for duration or playback position - */ -#define ANDROID_UNKNOWN_TIME -1 - -/** - * Event mask for MPEG-2 TS events associated with TS data - */ -#define ANDROID_MP2TSEVENT_NONE ((SLuint32) 0x0) -// buffer is at End Of Stream -#define ANDROID_MP2TSEVENT_EOS ((SLuint32) 0x1) -// buffer marks a discontinuity with previous TS data, resume display as soon as possible -#define ANDROID_MP2TSEVENT_DISCONTINUITY ((SLuint32) 0x1 << 1) -// buffer marks a discontinuity with previous TS data, resume display upon reaching the -// associated presentation time stamp -#define ANDROID_MP2TSEVENT_DISCON_NEWPTS ((SLuint32) 0x1 << 2) -// buffer marks a format change with previous TS data, resume display as soon as possible -#define ANDROID_MP2TSEVENT_FORMAT_CHANGE_FULL ((SLuint32) 0x1 << 3) -#define ANDROID_MP2TSEVENT_FORMAT_CHANGE_VIDEO ((SLuint32) 0x1 << 4) - -/** - * Event mask for AAC ADTS events associated with ADTS data - */ -#define ANDROID_ADTSEVENT_NONE ANDROID_MP2TSEVENT_NONE -// buffer is at End Of Stream -#define ANDROID_ADTSEVENT_EOS ANDROID_MP2TSEVENT_EOS - -/** - * Types of buffers stored in Android Buffer Queues, see IAndroidBufferQueue.mBufferType - */ -enum AndroidBufferType_type { - kAndroidBufferTypeInvalid = ((SLuint16) 0x0), - kAndroidBufferTypeMpeg2Ts = ((SLuint16) 0x1), - kAndroidBufferTypeAacadts = ((SLuint16) 0x2), -}; - -/** - * MIME types required for data in Android Buffer Queues - */ -// The preferred MIME types for new applications are in ../../include/*/OpenMAXAL_Android.h -// The legacy MIME type used elsewhere in the Android framework for AAC ADTS is below: -#define ANDROID_MIME_AACADTS_ANDROID_FRAMEWORK "audio/aac-adts" - -/** - * Notification thresholds relative to content duration in the cache - */ -#define DURATION_CACHED_HIGH_MS 30000 // 30s -#define DURATION_CACHED_MED_MS 10000 // 10s -#define DURATION_CACHED_LOW_MS 2000 // 2s - - -namespace android { - -/** - * Prefetch cache status - */ -enum CacheStatus_t { - kStatusUnknown = -1, - kStatusEmpty = 0, - kStatusLow, - kStatusIntermediate, - kStatusEnough, - kStatusHigh -}; - -enum { - kDataLocatorNone = 'none', - kDataLocatorUri = 'uri', - kDataLocatorFd = 'fd', -}; - -struct FdInfo { - int fd; - int64_t offset; - int64_t length; - bool mCloseAfterUse; // whether to close fd after last reference to fd -}; - -// TODO currently used by SfPlayer, to replace by DataLocator2 -union DataLocator { - char* uri; - FdInfo fdi; -}; - -union DataLocator2 { - const char* uriRef; - FdInfo fdi; -}; - -} // namespace android diff --git a/wilhelm/src/android/android_prompts.h b/wilhelm/src/android/android_prompts.h deleted file mode 100644 index 9feeda10..00000000 --- a/wilhelm/src/android/android_prompts.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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. - */ - -//----------------------------------------------------------------------------- -// Android general purpose errors -//---------------------- -#define ERROR_SHOULDNT_BE_HERE_S \ - "Reached an invalid code path in %s" - -//----------------------------------------------------------------------------- -// Android AudioPlayer errors -//---------------------- -#define ERROR_PLAYERSTREAMTYPE_SET_UNKNOWN_TYPE \ - "Cannot set stream type: unknown or invalid stream type" -#define ERROR_PLAYERSTREAMTYPE_REALIZED \ - "Cannot set stream type: audio player already realized" -#define ERROR_PLAYERREALIZE_UNKNOWN_DATASOURCE_LOCATOR \ - "Cannot realize AudioPlayer: with unknown data source locator" -#define ERROR_PLAYERREALIZE_UNEXPECTED_OBJECT_TYPE_D \ - "Cannot realize AudioPlayer: unexpected object type \%d" -#define ERROR_PLAYERDESTROY_UNEXPECTED_OBJECT_TYPE_D \ - "Cannot destroy AudioPlayer: unexpected object type \%d" -#define ERROR_PLAYERSETPLAYSTATE_UNEXPECTED_OBJECT_TYPE_D \ - "Cannot set AudioPlayer playstate: unexpected object type \%d" -#define ERROR_PLAYERSETPLAYSTATE_INVALID_OBJECT_STATE_D \ - "Cannot set AudioPlayer playstate to %d: Android object in invalid state" -#define ERROR_PLAYER_NEW_NULL_TRACK \ - "Internal error: new AudioTrack shouldn't be NULL" -#define ERROR_PLAYER_PREFETCH_d \ - "Error (%d) encountered while prefetching" - -//----------------------------------------------------------------------------- -// Android AudioRecorder errors -//---------------------- -#define ERROR_RECORDER_SINK_MUST_BE_ANDROIDSIMPLEBUFFERQUEUE \ - "Cannot create AudioRecorder: data sink must be SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE" -#define ERROR_RECORDER_SINK_FORMAT_MUST_BE_PCM \ - "Cannot create AudioRecorder: data sink must be in PCM format" -#define ERROR_RECORDER_SOURCE_MUST_BE_IODEVICE \ - "Cannot create AudioRecorder: data source must be SL_DATALOCATOR_IODEVICE" -#define ERROR_RECORDER_IODEVICE_MUST_BE_AUDIOINPUT \ - "Cannot create AudioRecorder: data source device type must be SL_IODEVICE_AUDIOINPUT" -#define ERROR_RECORDER_INPUT_ID_MUST_BE_DEFAULT \ - "Cannot create AudioRecorder: data source device ID must be SL_DEFAULTDEVICEID_AUDIOINPUT" -#define ERROR_RECORDERPRESET_SET_UNKNOWN_PRESET \ - "Cannot set recording preset: unknown or invalid preset" -#define ERROR_RECORDERPRESET_REALIZED \ - "Cannot set recording preset: audio recorder already realized" - -//----------------------------------------------------------------------------- -// Android Configuration errors -//---------------------- -#define ERROR_CONFIG_UNKNOWN_KEY \ - "Configuration error: unknown key" -#define ERROR_CONFIG_VALUESIZE_TOO_LOW \ - "Configuration error: value size too low to store valid value" -#define ERROR_CONFIG_NULL_PARAM \ - "Configuration error: invalid NULL parameter" diff --git a/wilhelm/src/android/android_sles_conversions.h b/wilhelm/src/android/android_sles_conversions.h deleted file mode 100644 index 6a27dc0d..00000000 --- a/wilhelm/src/android/android_sles_conversions.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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. - */ - -#include "math.h" - -#include <system/audio.h> - -//----------------------------------------------------------------------------- -// Android to OpenSL ES -//---------------------- -static inline SLuint32 android_to_sles_streamType(int type) { - return (SLuint32) type; -} - - -static inline SLuint32 android_to_sles_sampleRate(uint32_t srHz) { - // convert to milliHertz - return (SLuint32) srHz*1000; -} - - -//----------------------------------------------------------------------------- -// OpenSL ES to Android -//---------------------- -static inline int sles_to_android_streamType(SLuint32 type) { - return (int)type; -} - - -static inline uint32_t sles_to_android_sampleRate(SLuint32 sampleRateMilliHertz) { - return (uint32_t)(sampleRateMilliHertz / 1000); -} - -static inline audio_format_t sles_to_android_sampleFormat(SLuint32 pcmFormat) { - switch (pcmFormat) { - case SL_PCMSAMPLEFORMAT_FIXED_16: - return AUDIO_FORMAT_PCM_16_BIT; - break; - case SL_PCMSAMPLEFORMAT_FIXED_8: - return AUDIO_FORMAT_PCM_8_BIT; - break; - case SL_PCMSAMPLEFORMAT_FIXED_20: - case SL_PCMSAMPLEFORMAT_FIXED_24: - case SL_PCMSAMPLEFORMAT_FIXED_28: - case SL_PCMSAMPLEFORMAT_FIXED_32: - default: - return AUDIO_FORMAT_INVALID; - } -} - - -static inline int sles_to_android_channelMaskIn(SLuint32 nbChannels, SLuint32 channelMask) { - // FIXME handle channel mask mapping between SL ES and Android - return audio_channel_in_mask_from_count(nbChannels); -} - - -static inline int sles_to_android_channelMaskOut(SLuint32 nbChannels, SLuint32 channelMask) { - // FIXME handle channel mask mapping between SL ES and Android - return audio_channel_out_mask_from_count(nbChannels); -} - - -static inline float sles_to_android_amplification(SLmillibel level) { - // FIXME use the FX Framework conversions - return pow(10, (float)level/2000); -} - - -static inline uint32_t channelCountToMask(uint32_t channelCount) -{ - // FIXME channel mask is not yet implemented by Stagefright, so use a reasonable default - // that is computed from the channel count - uint32_t channelMask; - switch (channelCount) { - case 1: - // see explanation in data.c re: default channel mask for mono - return SL_SPEAKER_FRONT_LEFT; - case 2: - return SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT; - default: - return UNKNOWN_CHANNELMASK; - } -} diff --git a/wilhelm/src/android/include/AacAdtsExtractor.h b/wilhelm/src/android/include/AacAdtsExtractor.h deleted file mode 100644 index a3c0973a..00000000 --- a/wilhelm/src/android/include/AacAdtsExtractor.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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 AAC_ADTS_EXTRACTOR_H_ -#define AAC_ADTS_EXTRACTOR_H_ - -#include <utils/Vector.h> - -#include <media/stagefright/foundation/ABuffer.h> -#include <media/stagefright/foundation/ADebug.h> -#include <media/stagefright/DataSource.h> -#include <media/stagefright/MediaBufferGroup.h> -#include <media/stagefright/MediaDefs.h> -#include <media/stagefright/MediaErrors.h> -#include <media/stagefright/MediaExtractor.h> -#include <media/stagefright/MediaSource.h> -#include <media/stagefright/MetaData.h> -#include <utils/String8.h> - -namespace android { - -struct AMessage; -class String8; - - -class AacAdtsSource : public MediaSource { -public: - AacAdtsSource(const sp<DataSource> &source, - const sp<MetaData> &meta, - //const Vector<uint64_t> &offset_vector, - int64_t frame_duration_us); - - virtual status_t start(MetaData *params = NULL); - virtual status_t stop(); - - virtual sp<MetaData> getFormat(); - - virtual status_t read( - MediaBuffer **buffer, const ReadOptions *options = NULL); - -protected: - virtual ~AacAdtsSource(); - -private: - static const size_t kMaxFrameSize; - sp<DataSource> mDataSource; - sp<MetaData> mMeta; - - off64_t mOffset; - int64_t mCurrentTimeUs; - bool mStarted; - MediaBufferGroup *mGroup; - - int64_t mFrameDurationUs; - - AacAdtsSource(const AacAdtsSource &); - AacAdtsSource &operator=(const AacAdtsSource &); -}; - - -class AacAdtsExtractor : public MediaExtractor { -public: - AacAdtsExtractor(const sp<DataSource> &source); - - virtual size_t countTracks(); - virtual sp<MediaSource> getTrack(size_t index); - virtual sp<MetaData> getTrackMetaData(size_t index, uint32_t flags); - - virtual sp<MetaData> getMetaData(); - -protected: - virtual ~AacAdtsExtractor(); - -private: - sp<DataSource> mDataSource; - sp<MetaData> mMeta; - status_t mInitCheck; - - int64_t mFrameDurationUs; - - AacAdtsExtractor(const AacAdtsExtractor &); - AacAdtsExtractor &operator=(const AacAdtsExtractor &); - -}; - -} // namespace android - -#endif // AAC_ADTS_EXTRACTOR_H_ diff --git a/wilhelm/src/android/include/AacBqToPcmCbRenderer.h b/wilhelm/src/android/include/AacBqToPcmCbRenderer.h deleted file mode 100644 index 62cbd6e9..00000000 --- a/wilhelm/src/android/include/AacBqToPcmCbRenderer.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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 AAC_BQ_TO_PCM_H_ -#define AAC_BQ_TO_PCM_H_ - -#include "android/android_AudioToCbRenderer.h" -#include "android/BufferQueueSource.h" -#include "android/include/AacAdtsExtractor.h" - -//-------------------------------------------------------------------------------------------------- -namespace android { - -// Class to receive AAC ADTS data through an Android Buffer Queue, decode it and output -// the PCM samples through a registered callback (just like its superclass, AudioToCbRenderer). -// The implementation mainly overrides AudioSfDecoder::onPrepare() for the specificities -// of the data source creation, but all other behavior remains the same (e.g. PCM format metadata) - -class AacBqToPcmCbRenderer : public AudioToCbRenderer -{ -public: - - AacBqToPcmCbRenderer(const AudioPlayback_Parameters* params, - IAndroidBufferQueue *androidBufferQueue); - virtual ~AacBqToPcmCbRenderer(); - - // verifies the given memory starts and ends on ADTS frame boundaries. - // This is for instance used whenever ADTS data is being enqueued through an - // SL / XA AndroidBufferQueue interface so only parseable ADTS data goes in - // the buffer queue, and no ADTS frame is stored across two buffers. - static SLresult validateBufferStartEndOnFrameBoundaries(void* data, size_t size); - -protected: - - // Async event handlers (called from GenericPlayer's event loop) - virtual void onPrepare(); - - -private: - const sp<BufferQueueSource> mBqSource; - -private: - DISALLOW_EVIL_CONSTRUCTORS(AacBqToPcmCbRenderer); - -}; - -} // namespace android - -#endif //AAC_BQ_TO_PCM_H_ diff --git a/wilhelm/src/android/util/AacAdtsExtractor.cpp b/wilhelm/src/android/util/AacAdtsExtractor.cpp deleted file mode 100644 index 4a175bf4..00000000 --- a/wilhelm/src/android/util/AacAdtsExtractor.cpp +++ /dev/null @@ -1,305 +0,0 @@ -/* - * 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. - */ - -#include "sllog.h" -#include <utils/Log.h> - -#include "android/include/AacAdtsExtractor.h" -#include "include/avc_utils.h" - - -namespace android { - -#define ADTS_HEADER_LENGTH 7 -// ADTS header size is 7, but frame size information ends on byte 6 (when counting from byte 1) -#define ADTS_HEADER_SIZE_UP_TO_FRAMESIZE 6 - -//////////////////////////////////////////////////////////////////////////////// - -// Returns the sample rate based on the sampling frequency index -static uint32_t get_sample_rate(const uint8_t sf_index) -{ - static const uint32_t sample_rates[] = - { - 96000, 88200, 64000, 48000, 44100, 32000, - 24000, 22050, 16000, 12000, 11025, 8000 - }; - - if (sf_index < sizeof(sample_rates) / sizeof(sample_rates[0])) { - return sample_rates[sf_index]; - } - - return 0; -} - -static size_t getFrameSize(const sp<DataSource> &source, off64_t offset) { - size_t frameSize = 0; - - uint8_t syncHeader[ADTS_HEADER_SIZE_UP_TO_FRAMESIZE]; - const uint8_t *syncword = syncHeader; - const uint8_t *header = syncHeader + 3; - - ssize_t readSize = source->readAt(offset, &syncHeader, ADTS_HEADER_SIZE_UP_TO_FRAMESIZE); - if (readSize == 0) { - // EOS is normal, not an error - SL_LOGV("AacAdtsExtractor::getFrameSize EOS"); - return 0; - } - if (readSize != ADTS_HEADER_SIZE_UP_TO_FRAMESIZE) { - SL_LOGE("AacAdtsExtractor:: getFrameSize() returns %d (syncword and header read error)", - (int) readSize); - return 0; - } - - if ((syncword[0] != 0xff) || ((syncword[1] & 0xf6) != 0xf0)) { - SL_LOGE("AacAdtsExtractor:: getFrameSize() returns 0 (syncword pb)"); - return 0; - } - - const uint8_t protectionAbsent = syncword[1] & 0x1; - - frameSize = (header[0] & 0x3) << 11 | header[1] << 3 | header[2] >> 5; - // the frame size read already contains the size of the ADTS header, so no need to add it here - - // protectionAbsent is 0 if there is CRC - static const size_t kAdtsHeaderLengthNoCrc = 7; - static const size_t kAdtsHeaderLengthWithCrc = 9; - size_t headSize = protectionAbsent ? kAdtsHeaderLengthNoCrc : kAdtsHeaderLengthWithCrc; - if (headSize > frameSize) { - SL_LOGE("AacAdtsExtractor:: getFrameSize() returns 0 (frameSize %u < headSize %u)", - frameSize, headSize); - return 0; - } - - //SL_LOGV("AacAdtsExtractor:: getFrameSize() returns %u", frameSize); - - return frameSize; -} - - -AacAdtsExtractor::AacAdtsExtractor(const sp<DataSource> &source) - : mDataSource(source), - mInitCheck(NO_INIT), - mFrameDurationUs(0) { - - // difference with framework's AAC Extractor: we have already validated the data - // upon enqueueing, so no need to sniff the data: - // String8 mimeType; - // float confidence; - // if (!SniffAAC(mDataSource, &mimeType, &confidence, NULL)) { - // return; - // } - - uint8_t profile, sf_index, channel, header[2]; - ssize_t readSize = mDataSource->readAt(2, &header, 2); - if (readSize != 2) { - SL_LOGE("Unable to determine sample rate"); - return; - } - - profile = (header[0] >> 6) & 0x3; - sf_index = (header[0] >> 2) & 0xf; - uint32_t sr = get_sample_rate(sf_index); - - if (sr == 0) { - SL_LOGE("Invalid sample rate"); - return; - } - channel = (header[0] & 0x1) << 2 | (header[1] >> 6); - - SL_LOGV("AacAdtsExtractor has found sr=%d channel=%d", sr, channel); - - // Never fails - mMeta = MakeAACCodecSpecificData(profile, sf_index, channel); - - // Round up and get the duration of each frame - mFrameDurationUs = (1024 * 1000000ll + (sr - 1)) / sr; - - off64_t streamSize; - if (mDataSource->getSize(&streamSize) == OK) { - off64_t offset = 0, numFrames = 0; - while (offset < streamSize) { - size_t frameSize; - if ((frameSize = getFrameSize(mDataSource, offset)) == 0) { - // Usually frameSize == 0 due to EOS is benign (and getFrameSize() doesn't SL_LOGE), - // but in this case we were told the total size of the data source and so an EOS - // should not happen. - SL_LOGE("AacAdtsExtractor() failed querying framesize at offset=%lld", offset); - return; - } - - offset += frameSize; - if (offset > streamSize) { - SL_LOGE("AacAdtsExtractor() frame of size %zu at offset=%lld is beyond EOF %lld", - frameSize, offset, streamSize); - return; - } - numFrames ++; - } - - // Compute total duration - int64_t duration = numFrames * mFrameDurationUs; - mMeta->setInt64(kKeyDuration, duration); - } - - // Any earlier "return" would leave mInitCheck as NO_INIT, causing later methods to fail quickly - mInitCheck = OK; - -} - - -AacAdtsExtractor::~AacAdtsExtractor() { -} - - -sp<MetaData> AacAdtsExtractor::getMetaData() { - sp<MetaData> meta = new MetaData; - - if (mInitCheck != OK) { - return meta; - } - - meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_AAC_ADTS); - - return meta; -} - - -size_t AacAdtsExtractor::countTracks() { - return mInitCheck == OK ? 1 : 0; -} - - -sp<MediaSource> AacAdtsExtractor::getTrack(size_t index) { - if (mInitCheck != OK || index != 0) { - return NULL; - } - - return new AacAdtsSource(mDataSource, mMeta, mFrameDurationUs); -} - - -sp<MetaData> AacAdtsExtractor::getTrackMetaData(size_t index, uint32_t flags) { - if (mInitCheck != OK || index != 0) { - return NULL; - } - - return mMeta; -} - - -//////////////////////////////////////////////////////////////////////////////// - -// 8192 = 2^13, 13bit AAC frame size (in bytes) -const size_t AacAdtsSource::kMaxFrameSize = 8192; - -AacAdtsSource::AacAdtsSource( - const sp<DataSource> &source, const sp<MetaData> &meta, - int64_t frame_duration_us) - : mDataSource(source), - mMeta(meta), - mOffset(0), - mCurrentTimeUs(0), - mStarted(false), - mGroup(NULL), - mFrameDurationUs(frame_duration_us) { -} - - -AacAdtsSource::~AacAdtsSource() { - if (mStarted) { - stop(); - } -} - - -status_t AacAdtsSource::start(MetaData *params) { - CHECK(!mStarted); - - mOffset = 0; - mCurrentTimeUs = 0; - mGroup = new MediaBufferGroup; - mGroup->add_buffer(new MediaBuffer(kMaxFrameSize)); - mStarted = true; - - return OK; -} - - -status_t AacAdtsSource::stop() { - CHECK(mStarted); - - delete mGroup; - mGroup = NULL; - - mStarted = false; - return OK; -} - - -sp<MetaData> AacAdtsSource::getFormat() { - return mMeta; -} - - -status_t AacAdtsSource::read( - MediaBuffer **out, const ReadOptions *options) { - *out = NULL; - - int64_t seekTimeUs; - ReadOptions::SeekMode mode; - if (options && options->getSeekTo(&seekTimeUs, &mode)) { - // difference with framework's AAC Extractor: no seeking - SL_LOGE("Can't seek in AAC ADTS buffer queue"); - } - - size_t frameSize, frameSizeWithoutHeader; - SL_LOGV("AacAdtsSource::read() offset=%lld", mOffset); - if ((frameSize = getFrameSize(mDataSource, mOffset)) == 0) { - // EOS is normal, not an error - SL_LOGV("AacAdtsSource::read() returns EOS"); - return ERROR_END_OF_STREAM; - } - - MediaBuffer *buffer; - status_t err = mGroup->acquire_buffer(&buffer); - if (err != OK) { - return err; - } - - frameSizeWithoutHeader = frameSize - ADTS_HEADER_LENGTH; - ssize_t readSize = mDataSource->readAt(mOffset + ADTS_HEADER_LENGTH, buffer->data(), - frameSizeWithoutHeader); - //SL_LOGV("AacAdtsSource::read() readAt returned %u bytes", readSize); - if (readSize != (ssize_t)frameSizeWithoutHeader) { - SL_LOGW("AacAdtsSource::read() readSize != frameSizeWithoutHeader"); - buffer->release(); - buffer = NULL; - return ERROR_IO; - } - - buffer->set_range(0, frameSizeWithoutHeader); - buffer->meta_data()->setInt64(kKeyTime, mCurrentTimeUs); - buffer->meta_data()->setInt32(kKeyIsSyncFrame, 1); - - mOffset += frameSize; - mCurrentTimeUs += mFrameDurationUs; - - *out = buffer; - return OK; -} - -} // namespace android diff --git a/wilhelm/src/assert.c b/wilhelm/src/assert.c deleted file mode 100644 index b3154220..00000000 --- a/wilhelm/src/assert.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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. - */ - -// Replace bionic/libc/stdlib/assert.c which logs to stderr with our version which does LOGF. -// To be effective, add CFLAGS += -UNDEBUG and explicitly link in assert.c in all build modules. - -#include <utils/Log.h> - -void __assert(const char *file, int line, const char *failedexpr) -{ - LOG_ALWAYS_FATAL("assertion \"%s\" failed: file \"%s\", line %d", failedexpr, file, line); - // not reached -} - -void __assert2(const char *file, int line, const char *func, const char *failedexpr) -{ - LOG_ALWAYS_FATAL("assertion \"%s\" failed: file \"%s\", line %d, function \"%s\"", - failedexpr, file, line, func); - // not reached -} diff --git a/wilhelm/src/attr.h b/wilhelm/src/attr.h deleted file mode 100644 index 31533a24..00000000 --- a/wilhelm/src/attr.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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. - */ - -// Attributes - -// bit indices, used for fast lookup into handler table - -#define ATTR_INDEX_GAIN 0 // volume: volume, stereo position, mute - // mute solo: channel mute, channel solo - // effect send: set direct level -#define ATTR_INDEX_TRANSPORT 1 // play: callback events mask, - // marker position, position update period - // (currently looping is done differently, not by attributes) - // recorder: duration limit, events mask, - // marker position, position update period -#define ATTR_INDEX_POSITION 2 // requested position (a.k.a. seek position) -#define ATTR_INDEX_BQ_ENQUEUE 3 // (buffer queue non-empty and in playing state) became true -#define ATTR_INDEX_ABQ_ENQUEUE 4 // Android buffer queue became non-empty and in playing state -#define ATTR_INDEX_PLAY_STATE 5 // play: play state -#define ATTR_INDEX_UNUSED6 6 // reserved for future use -#define ATTR_INDEX_UNUSED7 7 // reserved for future use -#define ATTR_INDEX_MAX 8 // total number of bits used so far - -// bit masks, used with unlock_exclusive_attributes - -#define ATTR_NONE 0 -#define ATTR_GAIN (1 << ATTR_INDEX_GAIN) -#define ATTR_TRANSPORT (1 << ATTR_INDEX_TRANSPORT) -#define ATTR_POSITION (1 << ATTR_INDEX_POSITION) -#define ATTR_BQ_ENQUEUE (1 << ATTR_INDEX_BQ_ENQUEUE) -#define ATTR_ABQ_ENQUEUE (1 << ATTR_INDEX_ABQ_ENQUEUE) -#define ATTR_PLAY_STATE (1 << ATTR_INDEX_PLAY_STATE) -#define ATTR_UNUSED6 (1 << ATTR_INDEX_UNUSED6) -#define ATTR_UNUSED7 (1 << ATTR_INDEX_UNUSED7) diff --git a/wilhelm/src/autogen/IID_to_MPH.c b/wilhelm/src/autogen/IID_to_MPH.c deleted file mode 100644 index c37d07e5..00000000 --- a/wilhelm/src/autogen/IID_to_MPH.c +++ /dev/null @@ -1,261 +0,0 @@ -/* - * 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. - */ - -// This file is automagically generated by hashgen, do not edit - -/** \file IID_to_MPH.c Interface ID to MPH mapping */ - -#include <SLES/OpenSLES.h> -#include "MPH.h" -#include <assert.h> -#include <string.h> - -extern const struct SLInterfaceID_ SL_IID_array[MPH_MAX]; - -/** \brief Map SLInterfaceID to its minimal perfect hash (MPH), or -1 if unknown */ - -int IID_to_MPH(const SLInterfaceID iid) -{ -#define MAX_HASH_VALUE 180 - static const unsigned char asso_values[] = - { - 35, 20, 54, 84, 181, 181, 59, 181, 181, 181, - 181, 181, 181, 181, 69, 181, 64, 44, 181, 181, - 181, 181, 39, 181, 54, 14, 181, 181, 14, 181, - 181, 125, 5, 181, 181, 181, 181, 181, 181, 181, - 127, 181, 181, 181, 9, 181, 112, 181, 181, 181, - 181, 181, 122, 181, 181, 181, 181, 181, 14, 100, - 181, 9, 24, 181, 50, 181, 181, 181, 181, 117, - 181, 181, 97, 85, 181, 181, 181, 181, 181, 181, - 181, 181, 181, 181, 181, 181, 117, 181, 19, 181, - 181, 181, 9, 181, 181, 181, 25, 181, 14, 102, - 181, 181, 181, 181, 181, 181, 181, 4, 181, 97, - 181, 181, 0, 181, 4, 92, 117, 181, 67, 45, - 181, 181, 110, 181, 181, 181, 72, 181, 40, 181, - 181, 181, 181, 181, 181, 102, 52, 181, 181, 181, - 181, 181, 57, 67, 181, 62, 181, 125, 181, 181, - 181, 181, 181, 82, 181, 181, 72, 181, 181, 65, - 5, 181, 32, 181, 181, 67, 120, 181, 181, 37, - 181, 57, 55, 181, 181, 47, 181, 45, 181, 181, - 181, 181, 7, 181, 17, 30, 181, 181, 181, 181, - 181, 181, 0, 181, 181, 181, 105, 32, 181, 181, - 181, 181, 181, 181, 181, 181, 115, 181, 181, 181, - 95, 32, 181, 181, 181, 22, 181, 181, 2, 181, - 181, 181, 181, 12, 10, 181, 181, 12, 181, 181, - 181, 181, 181, 181, 2, 181, 70, 181, 181, 181, - 10, 2, 181, 181, 70, 181, 120, 115, 181, 181, - 181, 80, 105, 100, 181, 181 - }; - static const signed char hash_to_MPH[] = { - MPH_ANDROIDEFFECTSEND, - -1, - MPH_XADYNAMICINTERFACEMANAGEMENT, - -1, - MPH_XAAUDIODECODERCAPABILITIES, - MPH_XALED, - -1, - MPH_XATHREADSYNC, - -1, - MPH_XAOUTPUTMIX, - MPH_MIDITIME, - -1, - MPH_XAIMAGECONTROLS, - -1, - MPH_AUDIOIODEVICECAPABILITIES, - MPH_MUTESOLO, - -1, - MPH_XAVOLUME, - -1, - MPH_ANDROIDCONFIGURATION, - MPH_XASNAPSHOT, - -1, - MPH_XAPLAY, - -1, - MPH_SEEK, - MPH_3DLOCATION, - -1, - MPH_XACONFIGEXTENSION, - -1, - MPH_XAIMAGEDECODERCAPABILITIES, - MPH_XACAMERACAPABILITIES, - -1, - MPH_3DMACROSCOPIC, - -1, - MPH_VIBRA, - MPH_XAIMAGEEFFECTS, - -1, - MPH_XAMETADATAEXTRACTION, - -1, - MPH_PRESETREVERB, - MPH_XAOBJECT, - -1, - MPH_RATEPITCH, - -1, - MPH_PITCH, - MPH_XAVIBRA, - -1, - MPH_XARADIO, - -1, - MPH_OUTPUTMIXEXT, - MPH_ENGINECAPABILITIES, - -1, - MPH_XAVIDEOPOSTPROCESSING, - -1, - MPH_3DCOMMIT, - MPH_XAVIDEODECODERCAPABILITIES, - -1, - MPH_METADATATRAVERSAL, - -1, - MPH_XASEEK, - MPH_AUDIODECODERCAPABILITIES, - -1, - MPH_DEVICEVOLUME, - -1, - MPH_OBJECT, - MPH_ENVIRONMENTALREVERB, - -1, - MPH_XARDS, - -1, - MPH_XAVIDEOENCODER, - MPH_OUTPUTMIX, - -1, - MPH_XADYNAMICSOURCE, - -1, - MPH_3DGROUPING, - MPH_XASTREAMINFORMATION, - -1, - MPH_XAPREFETCHSTATUS, - -1, - MPH_XAMETADATATRAVERSAL, - MPH_VIRTUALIZER, - -1, - MPH_BUFFERQUEUE, - -1, - MPH_ANDROIDBUFFERQUEUESOURCE, - MPH_PLAY, - -1, - MPH_XAMETADATAINSERTION, - -1, - MPH_XADEVICEVOLUME, - MPH_XAVIDEOENCODERCAPABILITIES, - -1, - MPH_ENGINE, - -1, - MPH_MIDIMUTESOLO, - MPH_XAEQUALIZER, - -1, - MPH_METADATAEXTRACTION, - -1, - -1, - MPH_XARECORD, - -1, - MPH_XAIMAGEENCODER, - -1, - -1, - MPH_VISUALIZATION, - -1, - MPH_XACAMERA, - -1, - -1, - MPH_BASSBOOST, - -1, - MPH_LED, - -1, - -1, - MPH_EFFECTSEND, - -1, - MPH_XAENGINE, - -1, - -1, - MPH_RECORD, - -1, - MPH_MIDIMESSAGE, - -1, - -1, - MPH_ANDROIDEFFECTCAPABILITIES, - -1, - MPH_3DSOURCE, - -1, - -1, - MPH_VOLUME, - -1, - MPH_XAAUDIOENCODERCAPABILITIES, - -1, - -1, - MPH_PLAYBACKRATE, - -1, - MPH_XAAUDIOIODEVICECAPABILITIES, - -1, - -1, - MPH_NULL, - -1, - MPH_ANDROIDEFFECT, - -1, - -1, - MPH_XAIMAGEENCODERCAPABILITIES, - -1, - MPH_XAPLAYBACKRATE, - -1, - -1, - MPH_MIDITEMPO, - -1, - MPH_DYNAMICSOURCE, - -1, - -1, - MPH_DYNAMICINTERFACEMANAGEMENT, - -1, - MPH_EQUALIZER, - -1, - -1, - MPH_XAAUDIOENCODER, - -1, - MPH_THREADSYNC, - -1, - -1, - MPH_PREFETCHSTATUS, - -1, - MPH_3DDOPPLER, - -1, - -1, - MPH_ANDROIDSIMPLEBUFFERQUEUE, - -1, - -1, - -1, - -1, - MPH_AUDIOENCODERCAPABILITIES, - -1, - -1, - -1, - -1, - MPH_AUDIOENCODER - }; - if (&SL_IID_array[0] <= iid && &SL_IID_array[MPH_MAX] > iid) - return iid - &SL_IID_array[0]; - if (NULL != iid) { - unsigned key = asso_values[((unsigned char *)iid)[8]] + - asso_values[((unsigned char *)iid)[0]]; - if (key <= MAX_HASH_VALUE) { - int MPH = hash_to_MPH[key]; - if (MPH >= 0) { - assert(MPH < MPH_MAX); - SLInterfaceID trial = &SL_IID_array[MPH]; - if (!memcmp(iid, trial, sizeof(struct SLInterfaceID_))) - return MPH; - } - } - } - return -1; -} diff --git a/wilhelm/src/autogen/MPH_to_3DGroup.h b/wilhelm/src/autogen/MPH_to_3DGroup.h deleted file mode 100644 index c0ecf01b..00000000 --- a/wilhelm/src/autogen/MPH_to_3DGroup.h +++ /dev/null @@ -1,6 +0,0 @@ -// This file is automagically generated by mphtogen, do not edit - -1, 3, -1, 2, 5, 4, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 diff --git a/wilhelm/src/autogen/MPH_to_AudioPlayer.h b/wilhelm/src/autogen/MPH_to_AudioPlayer.h deleted file mode 100644 index dbfa871d..00000000 --- a/wilhelm/src/autogen/MPH_to_AudioPlayer.h +++ /dev/null @@ -1,6 +0,0 @@ -// This file is automagically generated by mphtogen, do not edit - -1, 3, 4, 5, 16, 6, -1, -1, -1, -1, 17, 7, -1, 1, 18, 8, -1, -1, 19, 20, - -1, 10, 11, -1, -1, -1, -1, 9, -1, 0, -1, 21, 2, 23, 12, 22, 13, -1, 14, -1, - -1, 24, 25, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 diff --git a/wilhelm/src/autogen/MPH_to_AudioRecorder.h b/wilhelm/src/autogen/MPH_to_AudioRecorder.h deleted file mode 100644 index d4759dea..00000000 --- a/wilhelm/src/autogen/MPH_to_AudioRecorder.h +++ /dev/null @@ -1,6 +0,0 @@ -// This file is automagically generated by mphtogen, do not edit - -1, -1, -1, -1, -1, -1, -1, 3, -1, -1, 4, -1, -1, 1, 5, -1, -1, -1, -1, 6, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, 2, -1, -1, - -1, -1, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 diff --git a/wilhelm/src/autogen/MPH_to_Engine.h b/wilhelm/src/autogen/MPH_to_Engine.h deleted file mode 100644 index c3a9e235..00000000 --- a/wilhelm/src/autogen/MPH_to_Engine.h +++ /dev/null @@ -1,6 +0,0 @@ -// This file is automagically generated by mphtogen, do not edit - 8, -1, -1, -1, -1, -1, 6, -1, 7, 5, -1, -1, 9, 1, -1, -1, 2, 3, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, 4, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 12, -1, -1, -1, -1 diff --git a/wilhelm/src/autogen/MPH_to_LEDDevice.h b/wilhelm/src/autogen/MPH_to_LEDDevice.h deleted file mode 100644 index d315c8f1..00000000 --- a/wilhelm/src/autogen/MPH_to_LEDDevice.h +++ /dev/null @@ -1,6 +0,0 @@ -// This file is automagically generated by mphtogen, do not edit - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1, -1, -1, -1, - 2, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 diff --git a/wilhelm/src/autogen/MPH_to_Listener.h b/wilhelm/src/autogen/MPH_to_Listener.h deleted file mode 100644 index fbfc8da9..00000000 --- a/wilhelm/src/autogen/MPH_to_Listener.h +++ /dev/null @@ -1,6 +0,0 @@ -// This file is automagically generated by mphtogen, do not edit - -1, 2, -1, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 diff --git a/wilhelm/src/autogen/MPH_to_MediaPlayer.h b/wilhelm/src/autogen/MPH_to_MediaPlayer.h deleted file mode 100644 index 4b11c6a3..00000000 --- a/wilhelm/src/autogen/MPH_to_MediaPlayer.h +++ /dev/null @@ -1,6 +0,0 @@ -// This file is automagically generated by mphtogen, do not edit - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 2, -1, 6, -1, -1, -1, - 5, -1, 3, -1, -1, -1, -1, -1, -1, 4 diff --git a/wilhelm/src/autogen/MPH_to_MetadataExtractor.h b/wilhelm/src/autogen/MPH_to_MetadataExtractor.h deleted file mode 100644 index 9db501b5..00000000 --- a/wilhelm/src/autogen/MPH_to_MetadataExtractor.h +++ /dev/null @@ -1,6 +0,0 @@ -// This file is automagically generated by mphtogen, do not edit - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, -1, -1, -1, -1, -1, - -1, 3, 4, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 diff --git a/wilhelm/src/autogen/MPH_to_MidiPlayer.h b/wilhelm/src/autogen/MPH_to_MidiPlayer.h deleted file mode 100644 index 6d33f3cb..00000000 --- a/wilhelm/src/autogen/MPH_to_MidiPlayer.h +++ /dev/null @@ -1,6 +0,0 @@ -// This file is automagically generated by mphtogen, do not edit - -1, 3, 4, 5, 19, 6, -1, -1, -1, -1, 20, 7, -1, 1, 21, 8, -1, -1, 22, 23, - -1, 10, 11, 12, 15, 14, 13, 9, -1, 0, -1, 24, 2, 26, 16, 25, -1, -1, 17, -1, - -1, 27, 28, 18, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 diff --git a/wilhelm/src/autogen/MPH_to_OutputMix.h b/wilhelm/src/autogen/MPH_to_OutputMix.h deleted file mode 100644 index 5767d669..00000000 --- a/wilhelm/src/autogen/MPH_to_OutputMix.h +++ /dev/null @@ -1,6 +0,0 @@ -// This file is automagically generated by mphtogen, do not edit - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 9, -1, -1, 1, -1, -1, -1, -1, 4, 5, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 2, -1, -1, -1, -1, 6, -1, -1, -1, -1, - -1, 7, 10, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 diff --git a/wilhelm/src/autogen/MPH_to_Vibra.h b/wilhelm/src/autogen/MPH_to_Vibra.h deleted file mode 100644 index 269adb86..00000000 --- a/wilhelm/src/autogen/MPH_to_Vibra.h +++ /dev/null @@ -1,6 +0,0 @@ -// This file is automagically generated by mphtogen, do not edit - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 diff --git a/wilhelm/src/classes.c b/wilhelm/src/classes.c deleted file mode 100644 index bf707bd7..00000000 --- a/wilhelm/src/classes.c +++ /dev/null @@ -1,520 +0,0 @@ -/* - * 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. - */ - -/* Classes vs. interfaces */ - -#include "sles_allinclusive.h" - - -#if USE_PROFILES & USE_PROFILES_GAME - -// 3DGroup class - -static const struct iid_vtable _3DGroup_interfaces[INTERFACES_3DGroup] = { - {MPH_OBJECT, INTERFACE_IMPLICIT_PREREALIZE, offsetof(C3DGroup, mObject)}, - {MPH_DYNAMICINTERFACEMANAGEMENT, INTERFACE_IMPLICIT, - offsetof(C3DGroup, mDynamicInterfaceManagement)}, - {MPH_3DLOCATION, INTERFACE_IMPLICIT, offsetof(C3DGroup, m3DLocation)}, - {MPH_3DDOPPLER, INTERFACE_DYNAMIC_GAME, offsetof(C3DGroup, m3DDoppler)}, - {MPH_3DSOURCE, INTERFACE_EXPLICIT_GAME, offsetof(C3DGroup, m3DSource)}, - {MPH_3DMACROSCOPIC, INTERFACE_OPTIONAL, offsetof(C3DGroup, m3DMacroscopic)}, -}; - -static const ClassTable C3DGroup_class = { - _3DGroup_interfaces, - INTERFACES_3DGroup, - MPH_to_3DGroup, - "3DGroup", - sizeof(C3DGroup), - SL_OBJECTID_3DGROUP, - 0, // OpenMAX AL object ID - NULL, - NULL, - NULL, - C3DGroup_PreDestroy -}; - -#endif - - -// AudioPlayer class - -static const struct iid_vtable AudioPlayer_interfaces[INTERFACES_AudioPlayer] = { - {MPH_OBJECT, INTERFACE_IMPLICIT_PREREALIZE, offsetof(CAudioPlayer, mObject)}, - {MPH_DYNAMICINTERFACEMANAGEMENT, INTERFACE_IMPLICIT, - offsetof(CAudioPlayer, mDynamicInterfaceManagement)}, - {MPH_PLAY, INTERFACE_IMPLICIT, offsetof(CAudioPlayer, mPlay)}, - {MPH_3DDOPPLER, INTERFACE_DYNAMIC_GAME, offsetof(CAudioPlayer, m3DDoppler)}, - {MPH_3DGROUPING, INTERFACE_EXPLICIT_GAME, offsetof(CAudioPlayer, m3DGrouping)}, - {MPH_3DLOCATION, INTERFACE_EXPLICIT_GAME, offsetof(CAudioPlayer, m3DLocation)}, - {MPH_3DSOURCE, INTERFACE_EXPLICIT_GAME, offsetof(CAudioPlayer, m3DSource)}, - {MPH_BUFFERQUEUE, INTERFACE_EXPLICIT, offsetof(CAudioPlayer, mBufferQueue)}, - {MPH_EFFECTSEND, INTERFACE_EXPLICIT, offsetof(CAudioPlayer, mEffectSend)}, - {MPH_MUTESOLO, INTERFACE_EXPLICIT, offsetof(CAudioPlayer, mMuteSolo)}, - {MPH_METADATAEXTRACTION, INTERFACE_DYNAMIC, - offsetof(CAudioPlayer, mMetadataExtraction)}, - {MPH_METADATATRAVERSAL, INTERFACE_DYNAMIC_GAME_MUSIC, - offsetof(CAudioPlayer, mMetadataTraversal)}, - {MPH_PREFETCHSTATUS, INTERFACE_EXPLICIT, offsetof(CAudioPlayer, mPrefetchStatus)}, - {MPH_RATEPITCH, INTERFACE_DYNAMIC_GAME, offsetof(CAudioPlayer, mRatePitch)}, - {MPH_SEEK, INTERFACE_EXPLICIT, offsetof(CAudioPlayer, mSeek)}, - // The base Volume interface is explicit, but portions are only for Game and Music profiles - {MPH_VOLUME, INTERFACE_EXPLICIT, offsetof(CAudioPlayer, mVolume)}, - {MPH_3DMACROSCOPIC, INTERFACE_OPTIONAL, offsetof(CAudioPlayer, m3DMacroscopic)}, - {MPH_BASSBOOST, INTERFACE_DYNAMIC, offsetof(CAudioPlayer, mBassBoost)}, - {MPH_DYNAMICSOURCE, INTERFACE_OPTIONAL, offsetof(CAudioPlayer, mDynamicSource)}, - {MPH_ENVIRONMENTALREVERB, INTERFACE_DYNAMIC, - offsetof(CAudioPlayer, mEnvironmentalReverb)}, - {MPH_EQUALIZER, INTERFACE_DYNAMIC, offsetof(CAudioPlayer, mEqualizer)}, - {MPH_PITCH, INTERFACE_DYNAMIC_OPTIONAL, offsetof(CAudioPlayer, mPitch)}, - {MPH_PRESETREVERB, INTERFACE_DYNAMIC, offsetof(CAudioPlayer, mPresetReverb)}, - {MPH_PLAYBACKRATE, INTERFACE_DYNAMIC, offsetof(CAudioPlayer, mPlaybackRate)}, - {MPH_VIRTUALIZER, INTERFACE_DYNAMIC, offsetof(CAudioPlayer, mVirtualizer)}, - {MPH_VISUALIZATION, INTERFACE_OPTIONAL, offsetof(CAudioPlayer, mVisualization)}, -#ifdef ANDROID - {MPH_ANDROIDEFFECT, INTERFACE_EXPLICIT, offsetof(CAudioPlayer, mAndroidEffect)}, - {MPH_ANDROIDEFFECTSEND, INTERFACE_EXPLICIT, offsetof(CAudioPlayer, mAndroidEffectSend)}, - {MPH_ANDROIDCONFIGURATION, INTERFACE_EXPLICIT_PREREALIZE, - offsetof(CAudioPlayer, mAndroidConfiguration)}, - {MPH_ANDROIDBUFFERQUEUESOURCE, INTERFACE_EXPLICIT, offsetof(CAudioPlayer, mAndroidBufferQueue)}, -#endif -}; - -static const ClassTable CAudioPlayer_class = { - AudioPlayer_interfaces, - INTERFACES_AudioPlayer, - MPH_to_AudioPlayer, - "AudioPlayer", - sizeof(CAudioPlayer), - SL_OBJECTID_AUDIOPLAYER, - 0, // OpenMAX AL object ID - CAudioPlayer_Realize, - CAudioPlayer_Resume, - CAudioPlayer_Destroy, - CAudioPlayer_PreDestroy -}; - - -#if (USE_PROFILES & USE_PROFILES_OPTIONAL) || defined(ANDROID) - -// AudioRecorder class - -static const struct iid_vtable AudioRecorder_interfaces[INTERFACES_AudioRecorder] = { - {MPH_OBJECT, INTERFACE_IMPLICIT_PREREALIZE, offsetof(CAudioRecorder, mObject)}, - {MPH_DYNAMICINTERFACEMANAGEMENT, INTERFACE_IMPLICIT, - offsetof(CAudioRecorder, mDynamicInterfaceManagement)}, - {MPH_RECORD, INTERFACE_IMPLICIT, offsetof(CAudioRecorder, mRecord)}, - {MPH_AUDIOENCODER, INTERFACE_EXPLICIT, offsetof(CAudioRecorder, mAudioEncoder)}, - {MPH_BASSBOOST, INTERFACE_DYNAMIC_OPTIONAL, offsetof(CAudioRecorder, mBassBoost)}, - {MPH_DYNAMICSOURCE, INTERFACE_OPTIONAL, offsetof(CAudioRecorder, mDynamicSource)}, - {MPH_EQUALIZER, INTERFACE_DYNAMIC_OPTIONAL, offsetof(CAudioRecorder, mEqualizer)}, - {MPH_VISUALIZATION, INTERFACE_OPTIONAL, offsetof(CAudioRecorder, mVisualization)}, - {MPH_VOLUME, INTERFACE_OPTIONAL, offsetof(CAudioRecorder, mVolume)}, -#ifdef ANDROID - {MPH_ANDROIDSIMPLEBUFFERQUEUE, INTERFACE_EXPLICIT, offsetof(CAudioRecorder, mBufferQueue)}, - {MPH_ANDROIDCONFIGURATION, INTERFACE_EXPLICIT_PREREALIZE, - offsetof(CAudioRecorder, mAndroidConfiguration)}, -#endif -}; - -static const ClassTable CAudioRecorder_class = { - AudioRecorder_interfaces, - INTERFACES_AudioRecorder, - MPH_to_AudioRecorder, - "AudioRecorder", - sizeof(CAudioRecorder), - SL_OBJECTID_AUDIORECORDER, - 0, // OpenMAX AL object ID - CAudioRecorder_Realize, - CAudioRecorder_Resume, - CAudioRecorder_Destroy, - CAudioRecorder_PreDestroy -}; - -#endif - - -// Engine class - -static const struct iid_vtable Engine_interfaces[INTERFACES_Engine] = { - {MPH_OBJECT, INTERFACE_IMPLICIT_PREREALIZE, offsetof(CEngine, mObject)}, - {MPH_DYNAMICINTERFACEMANAGEMENT, INTERFACE_IMPLICIT, - offsetof(CEngine, mDynamicInterfaceManagement)}, - {MPH_ENGINE, INTERFACE_IMPLICIT, offsetof(CEngine, mEngine)}, - {MPH_ENGINECAPABILITIES, INTERFACE_IMPLICIT_BASE, offsetof(CEngine, mEngineCapabilities)}, - {MPH_THREADSYNC, INTERFACE_IMPLICIT_BASE, offsetof(CEngine, mThreadSync)}, - {MPH_AUDIOIODEVICECAPABILITIES, INTERFACE_IMPLICIT_BASE, - offsetof(CEngine, mAudioIODeviceCapabilities)}, - {MPH_AUDIODECODERCAPABILITIES, INTERFACE_EXPLICIT_BASE, - offsetof(CEngine, mAudioDecoderCapabilities)}, - {MPH_AUDIOENCODERCAPABILITIES, INTERFACE_EXPLICIT_BASE, - offsetof(CEngine, mAudioEncoderCapabilities)}, - {MPH_3DCOMMIT, INTERFACE_EXPLICIT_GAME, offsetof(CEngine, m3DCommit)}, - {MPH_DEVICEVOLUME, INTERFACE_OPTIONAL, offsetof(CEngine, mDeviceVolume)}, - {MPH_XAENGINE, INTERFACE_IMPLICIT, offsetof(CEngine, mXAEngine)}, -#ifdef ANDROID - {MPH_ANDROIDEFFECTCAPABILITIES, INTERFACE_EXPLICIT, - offsetof(CEngine, mAndroidEffectCapabilities)}, -#endif - {MPH_XAVIDEODECODERCAPABILITIES, INTERFACE_EXPLICIT, - offsetof(CEngine, mVideoDecoderCapabilities)}, -}; - -static const ClassTable CEngine_class = { - Engine_interfaces, - INTERFACES_Engine, - MPH_to_Engine, - "Engine", - sizeof(CEngine), - SL_OBJECTID_ENGINE, - XA_OBJECTID_ENGINE, - CEngine_Realize, - CEngine_Resume, - CEngine_Destroy, - CEngine_PreDestroy -}; - - -#if USE_PROFILES & USE_PROFILES_OPTIONAL - -// LEDDevice class - -static const struct iid_vtable LEDDevice_interfaces[INTERFACES_LEDDevice] = { - {MPH_OBJECT, INTERFACE_IMPLICIT_PREREALIZE, offsetof(CLEDDevice, mObject)}, - {MPH_DYNAMICINTERFACEMANAGEMENT, INTERFACE_IMPLICIT, - offsetof(CLEDDevice, mDynamicInterfaceManagement)}, - {MPH_LED, INTERFACE_IMPLICIT, offsetof(CLEDDevice, mLEDArray)}, -}; - -static const ClassTable CLEDDevice_class = { - LEDDevice_interfaces, - INTERFACES_LEDDevice, - MPH_to_LEDDevice, - "LEDDevice", - sizeof(CLEDDevice), - SL_OBJECTID_LEDDEVICE, - XA_OBJECTID_LEDDEVICE, - NULL, - NULL, - NULL, - NULL -}; - -#endif - - -#if USE_PROFILES & USE_PROFILES_GAME - -// Listener class - -static const struct iid_vtable Listener_interfaces[INTERFACES_Listener] = { - {MPH_OBJECT, INTERFACE_IMPLICIT_PREREALIZE, offsetof(CListener, mObject)}, - {MPH_DYNAMICINTERFACEMANAGEMENT, INTERFACE_IMPLICIT, - offsetof(CListener, mDynamicInterfaceManagement)}, - {MPH_3DDOPPLER, INTERFACE_DYNAMIC_GAME, offsetof(CListener, m3DDoppler)}, - {MPH_3DLOCATION, INTERFACE_EXPLICIT_GAME, offsetof(CListener, m3DLocation)}, -}; - -static const ClassTable CListener_class = { - Listener_interfaces, - INTERFACES_Listener, - MPH_to_Listener, - "Listener", - sizeof(CListener), - SL_OBJECTID_LISTENER, - 0, // OpenMAX AL object ID - NULL, - NULL, - NULL, - NULL -}; - -#endif - - -#if USE_PROFILES & (USE_PROFILES_GAME | USE_PROFILES_MUSIC) - -// MetadataExtractor class - -static const struct iid_vtable MetadataExtractor_interfaces[INTERFACES_MetadataExtractor] = { - {MPH_OBJECT, INTERFACE_IMPLICIT_PREREALIZE, offsetof(CMetadataExtractor, mObject)}, - {MPH_DYNAMICINTERFACEMANAGEMENT, INTERFACE_IMPLICIT, - offsetof(CMetadataExtractor, mDynamicInterfaceManagement)}, - {MPH_DYNAMICSOURCE, INTERFACE_IMPLICIT, offsetof(CMetadataExtractor, mDynamicSource)}, - {MPH_METADATAEXTRACTION, INTERFACE_IMPLICIT, offsetof(CMetadataExtractor, mMetadataExtraction)}, - {MPH_METADATATRAVERSAL, INTERFACE_IMPLICIT, offsetof(CMetadataExtractor, mMetadataTraversal)}, -}; - -static const ClassTable CMetadataExtractor_class = { - MetadataExtractor_interfaces, - INTERFACES_MetadataExtractor, - MPH_to_MetadataExtractor, - "MetadataExtractor", - sizeof(CMetadataExtractor), - SL_OBJECTID_METADATAEXTRACTOR, - XA_OBJECTID_METADATAEXTRACTOR, - NULL, - NULL, - NULL, - NULL -}; - -#endif - - -#if USE_PROFILES & USE_PROFILES_GAME - -// MidiPlayer class - -static const struct iid_vtable MidiPlayer_interfaces[INTERFACES_MidiPlayer] = { - {MPH_OBJECT, INTERFACE_IMPLICIT_PREREALIZE, offsetof(CMidiPlayer, mObject)}, - {MPH_DYNAMICINTERFACEMANAGEMENT, INTERFACE_IMPLICIT, - offsetof(CMidiPlayer, mDynamicInterfaceManagement)}, - {MPH_PLAY, INTERFACE_IMPLICIT, offsetof(CMidiPlayer, mPlay)}, - {MPH_3DDOPPLER, INTERFACE_DYNAMIC_GAME, offsetof(C3DGroup, m3DDoppler)}, - {MPH_3DGROUPING, INTERFACE_EXPLICIT_GAME, offsetof(CMidiPlayer, m3DGrouping)}, - {MPH_3DLOCATION, INTERFACE_EXPLICIT_GAME, offsetof(CMidiPlayer, m3DLocation)}, - {MPH_3DSOURCE, INTERFACE_EXPLICIT_GAME, offsetof(CMidiPlayer, m3DSource)}, - {MPH_BUFFERQUEUE, INTERFACE_EXPLICIT_GAME, offsetof(CMidiPlayer, mBufferQueue)}, - {MPH_EFFECTSEND, INTERFACE_EXPLICIT_GAME, offsetof(CMidiPlayer, mEffectSend)}, - {MPH_MUTESOLO, INTERFACE_EXPLICIT_GAME, offsetof(CMidiPlayer, mMuteSolo)}, - {MPH_METADATAEXTRACTION, INTERFACE_DYNAMIC_GAME, offsetof(CMidiPlayer, mMetadataExtraction)}, - {MPH_METADATATRAVERSAL, INTERFACE_DYNAMIC_GAME, offsetof(CMidiPlayer, mMetadataTraversal)}, - {MPH_MIDIMESSAGE, INTERFACE_EXPLICIT_GAME_PHONE, offsetof(CMidiPlayer, mMIDIMessage)}, - {MPH_MIDITIME, INTERFACE_EXPLICIT_GAME_PHONE, offsetof(CMidiPlayer, mMIDITime)}, - {MPH_MIDITEMPO, INTERFACE_EXPLICIT_GAME_PHONE, offsetof(CMidiPlayer, mMIDITempo)}, - {MPH_MIDIMUTESOLO, INTERFACE_EXPLICIT_GAME, offsetof(CMidiPlayer, mMIDIMuteSolo)}, - {MPH_PREFETCHSTATUS, INTERFACE_EXPLICIT_GAME_PHONE, offsetof(CMidiPlayer, mPrefetchStatus)}, - {MPH_SEEK, INTERFACE_EXPLICIT_GAME_PHONE, offsetof(CMidiPlayer, mSeek)}, - {MPH_VOLUME, INTERFACE_EXPLICIT_GAME_PHONE, offsetof(CMidiPlayer, mVolume)}, - {MPH_3DMACROSCOPIC, INTERFACE_OPTIONAL, offsetof(CMidiPlayer, m3DMacroscopic)}, - {MPH_BASSBOOST, INTERFACE_DYNAMIC_OPTIONAL, offsetof(CMidiPlayer, mBassBoost)}, - {MPH_DYNAMICSOURCE, INTERFACE_OPTIONAL, offsetof(CMidiPlayer, mDynamicSource)}, - {MPH_ENVIRONMENTALREVERB, INTERFACE_DYNAMIC_OPTIONAL, - offsetof(CMidiPlayer, mEnvironmentalReverb)}, - {MPH_EQUALIZER, INTERFACE_DYNAMIC_OPTIONAL, offsetof(CMidiPlayer, mEqualizer)}, - {MPH_PITCH, INTERFACE_DYNAMIC_OPTIONAL, offsetof(CMidiPlayer, mPitch)}, - {MPH_PRESETREVERB, INTERFACE_DYNAMIC_OPTIONAL, offsetof(CMidiPlayer, mPresetReverb)}, - {MPH_PLAYBACKRATE, INTERFACE_DYNAMIC_OPTIONAL, offsetof(CMidiPlayer, mPlaybackRate)}, - {MPH_VIRTUALIZER, INTERFACE_DYNAMIC_OPTIONAL, offsetof(CMidiPlayer, mVirtualizer)}, - {MPH_VISUALIZATION, INTERFACE_OPTIONAL, offsetof(CMidiPlayer, mVisualization)}, -}; - -static const ClassTable CMidiPlayer_class = { - MidiPlayer_interfaces, - INTERFACES_MidiPlayer, - MPH_to_MidiPlayer, - "MidiPlayer", - sizeof(CMidiPlayer), - SL_OBJECTID_MIDIPLAYER, - 0, // OpenMAX AL object ID - NULL, - NULL, - NULL, - NULL -}; - -#endif - - -// OutputMix class - -static const struct iid_vtable OutputMix_interfaces[INTERFACES_OutputMix] = { - {MPH_OBJECT, INTERFACE_IMPLICIT_PREREALIZE, offsetof(COutputMix, mObject)}, - {MPH_DYNAMICINTERFACEMANAGEMENT, INTERFACE_IMPLICIT, - offsetof(COutputMix, mDynamicInterfaceManagement)}, - {MPH_OUTPUTMIX, INTERFACE_IMPLICIT, offsetof(COutputMix, mOutputMix)}, -#ifdef USE_OUTPUTMIXEXT - {MPH_OUTPUTMIXEXT, INTERFACE_UNAVAILABLE, offsetof(COutputMix, mOutputMixExt)}, -#else - {MPH_OUTPUTMIXEXT, INTERFACE_UNAVAILABLE, 0}, -#endif - {MPH_ENVIRONMENTALREVERB, INTERFACE_DYNAMIC, - offsetof(COutputMix, mEnvironmentalReverb)}, - {MPH_EQUALIZER, INTERFACE_DYNAMIC, offsetof(COutputMix, mEqualizer)}, - {MPH_PRESETREVERB, INTERFACE_DYNAMIC, offsetof(COutputMix, mPresetReverb)}, - {MPH_VIRTUALIZER, INTERFACE_DYNAMIC, offsetof(COutputMix, mVirtualizer)}, - // The overall Volume interface is explicit optional, - // but portions of Volume are mandated only in Game and Music profiles - {MPH_VOLUME, INTERFACE_OPTIONAL, offsetof(COutputMix, mVolume)}, - {MPH_BASSBOOST, INTERFACE_DYNAMIC, offsetof(COutputMix, mBassBoost)}, - {MPH_VISUALIZATION, INTERFACE_OPTIONAL, offsetof(COutputMix, mVisualization)}, -#ifdef ANDROID - {MPH_ANDROIDEFFECT, INTERFACE_EXPLICIT, offsetof(COutputMix, mAndroidEffect)}, -#endif -}; - -static const ClassTable COutputMix_class = { - OutputMix_interfaces, - INTERFACES_OutputMix, - MPH_to_OutputMix, - "OutputMix", - sizeof(COutputMix), - SL_OBJECTID_OUTPUTMIX, - XA_OBJECTID_OUTPUTMIX, - COutputMix_Realize, - COutputMix_Resume, - COutputMix_Destroy, - COutputMix_PreDestroy -}; - - -#if USE_PROFILES & USE_PROFILES_OPTIONAL - -// Vibra class - -static const struct iid_vtable VibraDevice_interfaces[INTERFACES_VibraDevice] = { - {MPH_OBJECT, INTERFACE_IMPLICIT_PREREALIZE, offsetof(CVibraDevice, mObject)}, - {MPH_DYNAMICINTERFACEMANAGEMENT, INTERFACE_IMPLICIT, - offsetof(CVibraDevice, mDynamicInterfaceManagement)}, - {MPH_VIBRA, INTERFACE_IMPLICIT, offsetof(CVibraDevice, mVibra)}, -}; - -static const ClassTable CVibraDevice_class = { - VibraDevice_interfaces, - INTERFACES_VibraDevice, - MPH_to_Vibra, - "VibraDevice", - sizeof(CVibraDevice), - SL_OBJECTID_VIBRADEVICE, - XA_OBJECTID_VIBRADEVICE, - NULL, - NULL, - NULL, - NULL -}; - -#endif - - -// Media player class - -static const struct iid_vtable MediaPlayer_interfaces[INTERFACES_MediaPlayer] = { - {MPH_XAOBJECT, INTERFACE_IMPLICIT_PREREALIZE, offsetof(CMediaPlayer, mObject)}, - {MPH_XADYNAMICINTERFACEMANAGEMENT, INTERFACE_IMPLICIT, - offsetof(CMediaPlayer, mDynamicInterfaceManagement)}, - {MPH_XAPLAY, INTERFACE_IMPLICIT, offsetof(CMediaPlayer, mPlay)}, - {MPH_XASTREAMINFORMATION, INTERFACE_EXPLICIT, offsetof(CMediaPlayer, mStreamInfo)}, - {MPH_XAVOLUME, INTERFACE_IMPLICIT, offsetof(CMediaPlayer, mVolume)}, - {MPH_XASEEK, INTERFACE_EXPLICIT, offsetof(CMediaPlayer, mSeek)}, - {MPH_XAPREFETCHSTATUS, INTERFACE_EXPLICIT, offsetof(CMediaPlayer, mPrefetchStatus)}, -#ifdef ANDROID - {MPH_ANDROIDBUFFERQUEUESOURCE, INTERFACE_EXPLICIT, offsetof(CMediaPlayer, mAndroidBufferQueue)}, -#endif -}; - -static const ClassTable CMediaPlayer_class = { - MediaPlayer_interfaces, - INTERFACES_MediaPlayer, - MPH_to_MediaPlayer, - "MediaPlayer", - sizeof(CMediaPlayer), - 0, // OpenSL ES object ID - XA_OBJECTID_MEDIAPLAYER, - CMediaPlayer_Realize, - CMediaPlayer_Resume, - CMediaPlayer_Destroy, - CMediaPlayer_PreDestroy -}; - - -static const ClassTable * const slClasses[] = { - // Do not change order of these entries; they are in numerical order - &CEngine_class, -#if USE_PROFILES & USE_PROFILES_OPTIONAL - &CLEDDevice_class, - &CVibraDevice_class, -#else - NULL, - NULL, -#endif - &CAudioPlayer_class, -#if (USE_PROFILES & USE_PROFILES_OPTIONAL) || defined(ANDROID) - &CAudioRecorder_class, -#else - NULL, -#endif -#if USE_PROFILES & (USE_PROFILES_GAME | USE_PROFILES_PHONE) - &CMidiPlayer_class, -#else - NULL, -#endif -#if USE_PROFILES & USE_PROFILES_GAME - &CListener_class, - &C3DGroup_class, -#else - NULL, - NULL, -#endif - &COutputMix_class, -#if USE_PROFILES & (USE_PROFILES_GAME | USE_PROFILES_MUSIC) - &CMetadataExtractor_class -#else - NULL -#endif -}; - - -static const ClassTable * const xaClasses[] = { - &CEngine_class, -#if USE_PROFILES & USE_PROFILES_OPTIONAL - &CLEDDevice_class, - &CVibraDevice_class, -#else - NULL, - NULL, -#endif - &CMediaPlayer_class, -#if 1 - NULL, - NULL, -#else - &CMediaRecorder_class, - &CRadioDevice_class, -#endif - &COutputMix_class, -#if USE_PROFILES & (USE_PROFILES_GAME | USE_PROFILES_MUSIC) - &CMetadataExtractor_class, -#else - NULL, -#endif -#if 1 - NULL -#else - &CCameraDevice_class -#endif -}; - - -/* \brief Map SL_OBJECTID to class or NULL if object ID not supported */ - -LI_API const ClassTable *objectIDtoClass(SLuint32 objectID) -{ - // object ID is the engine and always present - assert(NULL != slClasses[0]); - SLuint32 slObjectID0 = slClasses[0]->mSLObjectID; - if ((slObjectID0 <= objectID) && ((slObjectID0 + sizeof(slClasses)/sizeof(slClasses[0])) > - objectID)) { - return slClasses[objectID - slObjectID0]; - } - assert(NULL != xaClasses[0]); - SLuint32 xaObjectID0 = xaClasses[0]->mXAObjectID; - if ((xaObjectID0 <= objectID) && ((xaObjectID0 + sizeof(xaClasses)/sizeof(xaClasses[0])) > - objectID)) { - return xaClasses[objectID - xaObjectID0]; - } - return NULL; -} diff --git a/wilhelm/src/classes.h b/wilhelm/src/classes.h deleted file mode 100644 index 5ccbbae9..00000000 --- a/wilhelm/src/classes.h +++ /dev/null @@ -1,345 +0,0 @@ -/* - * 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. - */ - -#ifdef ANDROID -#include "android/CallbackProtector.h" -#include "android/android_Effect.h" -#include "android/android_GenericPlayer.h" -#endif - -// Class structures - - -/*typedef*/ struct CAudioPlayer_struct { - IObject mObject; -#ifdef ANDROID -#define INTERFACES_AudioPlayer 30 // see MPH_to_AudioPlayer in MPH_to.c for list of interfaces -#else -#define INTERFACES_AudioPlayer 26 // see MPH_to_AudioPlayer in MPH_to.c for list of interfaces -#endif - SLuint8 mInterfaceStates2[INTERFACES_AudioPlayer - INTERFACES_Default]; - IDynamicInterfaceManagement mDynamicInterfaceManagement; - IPlay mPlay; - I3DDoppler m3DDoppler; - I3DGrouping m3DGrouping; - I3DLocation m3DLocation; - I3DSource m3DSource; - IBufferQueue mBufferQueue; - IEffectSend mEffectSend; - IMetadataExtraction mMetadataExtraction; - IMetadataTraversal mMetadataTraversal; - IPrefetchStatus mPrefetchStatus; - IRatePitch mRatePitch; - ISeek mSeek; - IVolume mVolume; - IMuteSolo mMuteSolo; -#ifdef ANDROID - IAndroidEffect mAndroidEffect; - IAndroidEffectSend mAndroidEffectSend; - IAndroidConfiguration mAndroidConfiguration; - IAndroidBufferQueue mAndroidBufferQueue; -#endif - // optional interfaces - I3DMacroscopic m3DMacroscopic; - IBassBoost mBassBoost; - IDynamicSource mDynamicSource; - IEnvironmentalReverb mEnvironmentalReverb; - IEqualizer mEqualizer; - IPitch mPitch; - IPresetReverb mPresetReverb; - IPlaybackRate mPlaybackRate; - IVirtualizer mVirtualizer; - IVisualization mVisualization; - // fields below are per-instance private fields not associated with an interface - DataLocatorFormat mDataSource; - DataLocatorFormat mDataSink; - // cached data for this instance - // Formerly at IMuteSolo - SLuint8 mMuteMask; // Mask for which channels are muted: bit 0=left, 1=right - SLuint8 mSoloMask; // Mask for which channels are soloed: bit 0=left, 1=right - SLuint8 mNumChannels; // initially UNKNOWN_NUMCHANNELS, then const once it is known, - // range 1 <= x <= 8 - // End of former IMuteSolo fields - SLuint32 mSampleRateMilliHz;// initially UNKNOWN_SAMPLERATE, then const once it is known - // Formerly at IEffectSend - /** - * Dry volume modified by effect send interfaces: SLEffectSendItf and SLAndroidEffectSendItf - */ - SLmillibel mDirectLevel; - // implementation-specific data for this instance -#ifdef USE_OUTPUTMIXEXT - Track *mTrack; - float mGains[STEREO_CHANNELS]; ///< Computed gain based on volume, mute, solo, stereo position - SLboolean mDestroyRequested; ///< Mixer to acknowledge application's call to Object::Destroy -#endif -#ifdef USE_SNDFILE - struct SndFile mSndFile; -#endif // USE_SNDFILE -#ifdef ANDROID - enum AndroidObjectType mAndroidObjType; - /** identifies the initialization and preparation state */ - enum AndroidObjectState mAndroidObjState; - /** identifies which group of effects ("session") this player belongs to */ - int mSessionId; - /** identifies the Android stream type playback will occur on */ - audio_stream_type_t mStreamType; - // FIXME consolidate the next several variables into one class to avoid placement new - /** plays the PCM data for this player */ - android::sp<android::AudioTrack> mAudioTrack; - android::sp<android::CallbackProtector> mCallbackProtector; - android::sp<android::GenericPlayer> mAPlayer; - /** aux effect the AudioTrack will be attached to if aux send enabled */ - android::sp<android::AudioEffect> mAuxEffect; - // FIXME all levels below need to be encapsulated in a field of type AndroidAudioLevels - /** send level to aux effect, there's a single aux bus, so there's a single level */ - SLmillibel mAuxSendLevel; - /** - * Attenuation factor derived from direct level - */ - float mAmplFromDirectLevel; - /** FIXME whether to call AudioTrack::start() at the next safe opportunity */ - bool mDeferredStart; -#endif -} /*CAudioPlayer*/; - - -/*typedef*/ struct CAudioRecorder_struct { - // mandated interfaces - IObject mObject; -#ifdef ANDROID -#define INTERFACES_AudioRecorder 11 // see MPH_to_AudioRecorder in MPH_to.c for list of interfaces -#else -#define INTERFACES_AudioRecorder 9 // see MPH_to_AudioRecorder in MPH_to.c for list of interfaces -#endif - SLuint8 mInterfaceStates2[INTERFACES_AudioRecorder - INTERFACES_Default]; - IDynamicInterfaceManagement mDynamicInterfaceManagement; - IRecord mRecord; - IAudioEncoder mAudioEncoder; - // optional interfaces - IBassBoost mBassBoost; - IDynamicSource mDynamicSource; - IEqualizer mEqualizer; - IVisualization mVisualization; - IVolume mVolume; -#ifdef ANDROID - IBufferQueue mBufferQueue; - IAndroidConfiguration mAndroidConfiguration; -#endif - // remaining are per-instance private fields not associated with an interface - DataLocatorFormat mDataSource; - DataLocatorFormat mDataSink; - // cached data for this instance - SLuint8 mNumChannels; // initially UNKNOWN_NUMCHANNELS, then const once it is known, - // range 1 <= x <= 8 - SLuint32 mSampleRateMilliHz;// initially UNKNOWN_SAMPLERATE, then const once it is known - // implementation-specific data for this instance -#ifdef ANDROID - enum AndroidObjectType mAndroidObjType; - android::AudioRecord *mAudioRecord; //FIXME candidate to be encapsulated in a ARecorder subclass - audio_source_t mRecordSource; //FIXME candidate to be encapsulated in a ARecorder subclass -#endif -} /*CAudioRecorder*/; - - -/*typedef*/ struct CEngine_struct { - // mandated implicit interfaces - IObject mObject; -#ifdef ANDROID -#define INTERFACES_Engine 13 // see MPH_to_Engine in MPH_to.c for list of interfaces -#else -#define INTERFACES_Engine 12 // see MPH_to_Engine in MPH_to.c for list of interfaces -#endif - SLuint8 mInterfaceStates2[INTERFACES_Engine - INTERFACES_Default]; - IDynamicInterfaceManagement mDynamicInterfaceManagement; - IEngine mEngine; - IEngineCapabilities mEngineCapabilities; - IThreadSync mThreadSync; - // mandated explicit interfaces - IAudioIODeviceCapabilities mAudioIODeviceCapabilities; - IAudioDecoderCapabilities mAudioDecoderCapabilities; - IAudioEncoderCapabilities mAudioEncoderCapabilities; - I3DCommit m3DCommit; - // optional interfaces - IDeviceVolume mDeviceVolume; - // OpenMAX AL mandated implicit interfaces - IXAEngine mXAEngine; -#ifdef ANDROID - IAndroidEffectCapabilities mAndroidEffectCapabilities; -#endif - // OpenMAX AL explicit interfaces - IVideoDecoderCapabilities mVideoDecoderCapabilities; - // remaining are per-instance private fields not associated with an interface - ThreadPool mThreadPool; // for asynchronous operations - pthread_t mSyncThread; -#if defined(ANDROID) - // FIXME number of presets will only be saved in IEqualizer, preset names will not be stored - SLuint32 mEqNumPresets; - char** mEqPresetNames; -#endif -} /*CEngine*/; - -typedef struct { - // mandated interfaces - IObject mObject; -#define INTERFACES_LEDDevice 3 // see MPH_to_LEDDevice in MPH_to.c for list of interfaces - SLuint8 mInterfaceStates2[INTERFACES_LEDDevice - INTERFACES_Default]; - IDynamicInterfaceManagement mDynamicInterfaceManagement; - ILEDArray mLEDArray; - // remaining are per-instance private fields not associated with an interface - SLuint32 mDeviceID; -} CLEDDevice; - -typedef struct { - // mandated interfaces - IObject mObject; -#define INTERFACES_Listener 4 // see MPH_to_Listener in MPH_to.c for list of interfaces - SLuint8 mInterfaceStates2[INTERFACES_Listener - INTERFACES_Default]; - IDynamicInterfaceManagement mDynamicInterfaceManagement; - I3DDoppler m3DDoppler; - I3DLocation m3DLocation; - // remaining are per-instance private fields not associated with an interface -} CListener; - -typedef struct { - // mandated interfaces - IObject mObject; -#define INTERFACES_MetadataExtractor 5 // see MPH_to_MetadataExtractor in MPH_to.c for list of - // interfaces - SLuint8 mInterfaceStates2[INTERFACES_MetadataExtractor - INTERFACES_Default]; - IDynamicInterfaceManagement mDynamicInterfaceManagement; - IDynamicSource mDynamicSource; - IMetadataExtraction mMetadataExtraction; - IMetadataTraversal mMetadataTraversal; - // remaining are per-instance private fields not associated with an interface -} CMetadataExtractor; - -typedef struct { - // mandated interfaces - IObject mObject; - -#define INTERFACES_MidiPlayer 29 // see MPH_to_MidiPlayer in MPH_to.c for list of interfaces - SLuint8 mInterfaceStates2[INTERFACES_MidiPlayer - INTERFACES_Default]; - IDynamicInterfaceManagement mDynamicInterfaceManagement; - IPlay mPlay; - I3DDoppler m3DDoppler; - I3DGrouping m3DGrouping; - I3DLocation m3DLocation; - I3DSource m3DSource; - IBufferQueue mBufferQueue; - IEffectSend mEffectSend; - IMetadataExtraction mMetadataExtraction; - IMetadataTraversal mMetadataTraversal; - IMIDIMessage mMIDIMessage; - IMIDITime mMIDITime; - IMIDITempo mMIDITempo; - IMIDIMuteSolo mMIDIMuteSolo; - IPrefetchStatus mPrefetchStatus; - ISeek mSeek; - IVolume mVolume; - IMuteSolo mMuteSolo; - // optional interfaces - I3DMacroscopic m3DMacroscopic; - IBassBoost mBassBoost; - IDynamicSource mDynamicSource; - IEnvironmentalReverb mEnvironmentalReverb; - IEqualizer mEqualizer; - IPitch mPitch; - IPresetReverb mPresetReverb; - IPlaybackRate mPlaybackRate; - IVirtualizer mVirtualizer; - IVisualization mVisualization; - // remaining are per-instance private fields not associated with an interface -} CMidiPlayer; - -/*typedef*/ struct COutputMix_struct { - // mandated interfaces - IObject mObject; -#ifdef ANDROID -#define INTERFACES_OutputMix 12 // see MPH_to_OutputMix in MPH_to.c for list of interfaces -#else -#define INTERFACES_OutputMix 11 // see MPH_to_OutputMix in MPH_to.c for list of interfaces -#endif - SLuint8 mInterfaceStates2[INTERFACES_OutputMix - INTERFACES_Default]; - IDynamicInterfaceManagement mDynamicInterfaceManagement; - IOutputMix mOutputMix; -#ifdef USE_OUTPUTMIXEXT - IOutputMixExt mOutputMixExt; -#endif - IEnvironmentalReverb mEnvironmentalReverb; - IEqualizer mEqualizer; - IPresetReverb mPresetReverb; - IVirtualizer mVirtualizer; - IVolume mVolume; - // optional interfaces - IBassBoost mBassBoost; - IVisualization mVisualization; -#ifdef ANDROID - IAndroidEffect mAndroidEffect; -#endif - // remaining are per-instance private fields not associated with an interface -} /*COutputMix*/; - -typedef struct { - // mandated interfaces - IObject mObject; -#define INTERFACES_VibraDevice 3 // see MPH_to_VibraDevice in MPH_to.c for list of interfaces - SLuint8 mInterfaceStates2[INTERFACES_VibraDevice - INTERFACES_Default]; - IDynamicInterfaceManagement mDynamicInterfaceManagement; - IVibra mVibra; - // remaining are per-instance private fields not associated with an interface - SLuint32 mDeviceID; -} CVibraDevice; - - -typedef struct CMediaPlayer_struct { - IObject mObject; -#ifdef ANDROID -#define INTERFACES_MediaPlayer 8 -#else -#define INTERFACES_MediaPlayer 7 -#endif - XAuint8 mInterfaceStates2[INTERFACES_MediaPlayer - INTERFACES_Default]; - IDynamicInterfaceManagement mDynamicInterfaceManagement; - IDynamicSource mDynamicSource; - IPlay mPlay; - IStreamInformation mStreamInfo; - IVolume mVolume; - ISeek mSeek; - IPrefetchStatus mPrefetchStatus; -#ifdef ANDROID - IAndroidBufferQueue mAndroidBufferQueue; -#endif - // fields below are per-instance private fields not associated with an interface - DataLocatorFormat mDataSource; - DataLocatorFormat mBankSource; - DataLocatorFormat mAudioSink; - DataLocatorFormat mImageVideoSink; - DataLocatorFormat mVibraSink; - DataLocatorFormat mLEDArraySink; - SLuint8 mNumChannels; // initially UNKNOWN_NUMCHANNELS, then const once it is known, - // range 1 <= x <= 8 -#ifdef ANDROID - android::sp<android::GenericPlayer> mAVPlayer; - android::sp<android::CallbackProtector> mCallbackProtector; - enum AndroidObjectType mAndroidObjType; - /** identifies the initialization and preparation state */ - enum AndroidObjectState mAndroidObjState; - /** identifies which group of effects ("session") this player belongs to */ - int mSessionId; - /** identifies the Android stream type playback will occur on */ - audio_stream_type_t mStreamType; -#endif -} CMediaPlayer; diff --git a/wilhelm/src/data.c b/wilhelm/src/data.c deleted file mode 100644 index 727b4849..00000000 --- a/wilhelm/src/data.c +++ /dev/null @@ -1,896 +0,0 @@ -/* - * 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. - */ - -/** Data locator, data format, data source, and data sink support */ - -#include "sles_allinclusive.h" - - -/** \brief Check a data locator and make local deep copy */ - -static SLresult checkDataLocator(const char *name, void *pLocator, DataLocator *pDataLocator, - SLuint32 allowedDataLocatorMask) -{ - assert(NULL != name && NULL != pDataLocator); - SLresult result = SL_RESULT_SUCCESS; - - SLuint32 locatorType; - if (NULL == pLocator) { - pDataLocator->mLocatorType = locatorType = SL_DATALOCATOR_NULL; - } else { - locatorType = *(SLuint32 *)pLocator; - switch (locatorType) { - - case SL_DATALOCATOR_ADDRESS: - pDataLocator->mAddress = *(SLDataLocator_Address *)pLocator; - // if length is greater than zero, then the address must be non-NULL - if ((0 < pDataLocator->mAddress.length) && (NULL == pDataLocator->mAddress.pAddress)) { - SL_LOGE("%s: pAddress=NULL", name); - result = SL_RESULT_PARAMETER_INVALID; - } - break; - - case SL_DATALOCATOR_BUFFERQUEUE: -#ifdef ANDROID - // This is an alias that is _not_ converted; the rest of the code must check for both - // locator types. That's because it is only an alias for audio players, not audio recorder - // objects so we have to remember the distinction. - case SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE: -#endif - pDataLocator->mBufferQueue = *(SLDataLocator_BufferQueue *)pLocator; - // number of buffers must be specified, there is no default value, and can't be too big - if (!((1 <= pDataLocator->mBufferQueue.numBuffers) && - (pDataLocator->mBufferQueue.numBuffers <= 255))) { - SL_LOGE("%s: numBuffers=%u", name, pDataLocator->mBufferQueue.numBuffers); - result = SL_RESULT_PARAMETER_INVALID; - } - break; - - case SL_DATALOCATOR_IODEVICE: - { - pDataLocator->mIODevice = *(SLDataLocator_IODevice *)pLocator; - SLuint32 deviceType = pDataLocator->mIODevice.deviceType; - SLObjectItf device = pDataLocator->mIODevice.device; - if (NULL != device) { - pDataLocator->mIODevice.deviceID = 0; - SLuint32 expectedObjectID; - switch (deviceType) { - case SL_IODEVICE_LEDARRAY: - expectedObjectID = SL_OBJECTID_LEDDEVICE; - break; - case SL_IODEVICE_VIBRA: - expectedObjectID = SL_OBJECTID_VIBRADEVICE; - break; - case XA_IODEVICE_CAMERA: - expectedObjectID = XA_OBJECTID_CAMERADEVICE; - break; - case XA_IODEVICE_RADIO: - expectedObjectID = XA_OBJECTID_RADIODEVICE; - break; - // audio input and audio output cannot be specified via objects - case SL_IODEVICE_AUDIOINPUT: - // case SL_IODEVICE_AUDIOOUTPUT: // does not exist in 1.0.1, added in 1.1 - default: - SL_LOGE("%s: deviceType=%u", name, deviceType); - pDataLocator->mIODevice.device = NULL; - expectedObjectID = 0; - result = SL_RESULT_PARAMETER_INVALID; - } - if (result == SL_RESULT_SUCCESS) { - // check that device has the correct object ID and is realized, - // and acquire a strong reference to it - result = AcquireStrongRef((IObject *) device, expectedObjectID); - if (SL_RESULT_SUCCESS != result) { - SL_LOGE("%s: locatorType=IODEVICE, but device field %p has wrong " \ - "object ID or is not realized", name, device); - pDataLocator->mIODevice.device = NULL; - } - } - } else { - SLuint32 deviceID = pDataLocator->mIODevice.deviceID; - switch (deviceType) { - case SL_IODEVICE_LEDARRAY: - if (SL_DEFAULTDEVICEID_LED != deviceID) { - SL_LOGE("%s: invalid LED deviceID=%u", name, deviceID); - result = SL_RESULT_PARAMETER_INVALID; - } - break; - case SL_IODEVICE_VIBRA: - if (SL_DEFAULTDEVICEID_VIBRA != deviceID) { - SL_LOGE("%s: invalid vibra deviceID=%u", name, deviceID); - result = SL_RESULT_PARAMETER_INVALID; - } - break; - case SL_IODEVICE_AUDIOINPUT: - if (SL_DEFAULTDEVICEID_AUDIOINPUT != deviceID) { - SL_LOGE("%s: invalid audio input deviceID=%u", name, deviceID); - result = SL_RESULT_PARAMETER_INVALID; - } - break; - case XA_IODEVICE_RADIO: - // no default device ID for radio; see Khronos bug XXXX - break; - case XA_IODEVICE_CAMERA: - if (XA_DEFAULTDEVICEID_CAMERA != deviceID) { - SL_LOGE("%s: invalid audio input deviceID=%u", name, deviceID); - result = XA_RESULT_PARAMETER_INVALID; - } - break; - // case SL_IODEVICE_AUDIOOUTPUT: - // does not exist in 1.0.1, added in 1.1 - // break; - default: - SL_LOGE("%s: deviceType=%u is invalid", name, deviceType); - result = SL_RESULT_PARAMETER_INVALID; - } - } - } - break; - - case SL_DATALOCATOR_MIDIBUFFERQUEUE: - pDataLocator->mMIDIBufferQueue = *(SLDataLocator_MIDIBufferQueue *)pLocator; - if (0 == pDataLocator->mMIDIBufferQueue.tpqn) { - pDataLocator->mMIDIBufferQueue.tpqn = 192; - } - // number of buffers must be specified, there is no default value, and can't be too big - if (!((1 <= pDataLocator->mMIDIBufferQueue.numBuffers) && - (pDataLocator->mMIDIBufferQueue.numBuffers <= 255))) { - SL_LOGE("%s: SLDataLocator_MIDIBufferQueue.numBuffers=%d", name, - pDataLocator->mMIDIBufferQueue.numBuffers); - result = SL_RESULT_PARAMETER_INVALID; - } - break; - - case SL_DATALOCATOR_OUTPUTMIX: - pDataLocator->mOutputMix = *(SLDataLocator_OutputMix *)pLocator; - // check that output mix object has the correct object ID and is realized, - // and acquire a strong reference to it - result = AcquireStrongRef((IObject *) pDataLocator->mOutputMix.outputMix, - SL_OBJECTID_OUTPUTMIX); - if (SL_RESULT_SUCCESS != result) { - SL_LOGE("%s: locatorType=SL_DATALOCATOR_OUTPUTMIX, but outputMix field %p does " \ - "not refer to an SL_OBJECTID_OUTPUTMIX or the output mix is not realized", \ - name, pDataLocator->mOutputMix.outputMix); - pDataLocator->mOutputMix.outputMix = NULL; - } - break; - - case XA_DATALOCATOR_NATIVEDISPLAY: - pDataLocator->mNativeDisplay = *(XADataLocator_NativeDisplay *)pLocator; - // hWindow is NDK C ANativeWindow * and hDisplay must be NULL - if (pDataLocator->mNativeDisplay.hWindow == NULL) { - SL_LOGE("%s: hWindow must be non-NULL ANativeWindow *", name); - result = SL_RESULT_PARAMETER_INVALID; - } - if (pDataLocator->mNativeDisplay.hDisplay != NULL) { - SL_LOGE("%s: hDisplay must be NULL, but is %p", name, - pDataLocator->mNativeDisplay.hDisplay); - result = SL_RESULT_PARAMETER_INVALID; - } - break; - - case SL_DATALOCATOR_URI: - { - pDataLocator->mURI = *(SLDataLocator_URI *)pLocator; - if (NULL == pDataLocator->mURI.URI) { - SL_LOGE("%s: invalid URI=NULL", name); - result = SL_RESULT_PARAMETER_INVALID; - } else { - // NTH verify URI address for validity - size_t len = strlen((const char *) pDataLocator->mURI.URI); - SLchar *myURI = (SLchar *) malloc(len + 1); - if (NULL == myURI) { - result = SL_RESULT_MEMORY_FAILURE; - } else { - memcpy(myURI, pDataLocator->mURI.URI, len + 1); - // Verify that another thread didn't change the NUL-terminator after we used it - // to determine length of string to copy. It's OK if the string became shorter. - if ('\0' != myURI[len]) { - free(myURI); - myURI = NULL; - result = SL_RESULT_PARAMETER_INVALID; - } - } - pDataLocator->mURI.URI = myURI; - } - } - break; - -#ifdef ANDROID - case SL_DATALOCATOR_ANDROIDFD: - { - pDataLocator->mFD = *(SLDataLocator_AndroidFD *)pLocator; - SL_LOGV("%s: fd=%d offset=%lld length=%lld", name, pDataLocator->mFD.fd, - pDataLocator->mFD.offset, pDataLocator->mFD.length); - // NTH check against process fd limit - if (0 > pDataLocator->mFD.fd) { - SL_LOGE("%s: fd=%d\n", name, pDataLocator->mFD.fd); - result = SL_RESULT_PARAMETER_INVALID; - } - break; - } - case SL_DATALOCATOR_ANDROIDBUFFERQUEUE: - { - pDataLocator->mABQ = *(SLDataLocator_AndroidBufferQueue*)pLocator; - // number of buffers must be specified, there is no default value, and can't be too big - if (!((1 <= pDataLocator->mBufferQueue.numBuffers) && - (pDataLocator->mBufferQueue.numBuffers <= 255))) { - SL_LOGE("%s: numBuffers=%u", name, pDataLocator->mABQ.numBuffers); - result = SL_RESULT_PARAMETER_INVALID; - } - break; - } -#endif - - case SL_DATALOCATOR_NULL: // a NULL pointer is allowed, but not a pointer to NULL - default: - SL_LOGE("%s: locatorType=%u", name, locatorType); - result = SL_RESULT_PARAMETER_INVALID; - } - - // Verify that another thread didn't change the locatorType field after we used it - // to determine sizeof struct to copy. - if ((SL_RESULT_SUCCESS == result) && (locatorType != pDataLocator->mLocatorType)) { - SL_LOGE("%s: locatorType changed from %u to %u", name, locatorType, - pDataLocator->mLocatorType); - result = SL_RESULT_PRECONDITIONS_VIOLATED; - } - - } - - // Verify that the data locator type is allowed in this context - if (SL_RESULT_SUCCESS == result) { - SLuint32 actualMask; - switch (locatorType) { - case SL_DATALOCATOR_NULL: - case SL_DATALOCATOR_URI: - case SL_DATALOCATOR_ADDRESS: - case SL_DATALOCATOR_IODEVICE: - case SL_DATALOCATOR_OUTPUTMIX: - case XA_DATALOCATOR_NATIVEDISPLAY: - case SL_DATALOCATOR_BUFFERQUEUE: - case SL_DATALOCATOR_MIDIBUFFERQUEUE: - actualMask = 1L << locatorType; - break; -#ifdef ANDROID - case SL_DATALOCATOR_ANDROIDFD: - case SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE: - case SL_DATALOCATOR_ANDROIDBUFFERQUEUE: - actualMask = 0x100L << (locatorType - SL_DATALOCATOR_ANDROIDFD); - break; -#endif - default: - assert(false); - actualMask = 0L; - break; - } - if (!(allowedDataLocatorMask & actualMask)) { - SL_LOGE("%s: data locator type 0x%x not allowed", name, locatorType); - result = SL_RESULT_CONTENT_UNSUPPORTED; - } - } - - return result; -} - - -/** \brief Free the local deep copy of a data locator */ - -static void freeDataLocator(DataLocator *pDataLocator) -{ - switch (pDataLocator->mLocatorType) { - case SL_DATALOCATOR_NULL: - case SL_DATALOCATOR_ADDRESS: - case SL_DATALOCATOR_BUFFERQUEUE: - case SL_DATALOCATOR_MIDIBUFFERQUEUE: - case XA_DATALOCATOR_NATIVEDISPLAY: - break; - case SL_DATALOCATOR_URI: - if (NULL != pDataLocator->mURI.URI) { - free(pDataLocator->mURI.URI); - pDataLocator->mURI.URI = NULL; - } - pDataLocator->mURI.URI = NULL; - break; - case SL_DATALOCATOR_IODEVICE: - if (NULL != pDataLocator->mIODevice.device) { - ReleaseStrongRef((IObject *) pDataLocator->mIODevice.device); - pDataLocator->mIODevice.device = NULL; - } - break; - case SL_DATALOCATOR_OUTPUTMIX: - if (NULL != pDataLocator->mOutputMix.outputMix) { - ReleaseStrongRef((IObject *) pDataLocator->mOutputMix.outputMix); - pDataLocator->mOutputMix.outputMix = NULL; - } - break; -#ifdef ANDROID - case SL_DATALOCATOR_ANDROIDBUFFERQUEUE: - case SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE: - case SL_DATALOCATOR_ANDROIDFD: - break; -#endif - default: - // an invalid data locator is caught earlier when making the copy - assert(false); - break; - } -} - - -/** \brief Check a data format and make local deep copy */ - -static SLresult checkDataFormat(const char *name, void *pFormat, DataFormat *pDataFormat, - SLuint32 allowedDataFormatMask) -{ - assert(NULL != name && NULL != pDataFormat); - SLresult result = SL_RESULT_SUCCESS; - - SLuint32 formatType; - if (NULL == pFormat) { - pDataFormat->mFormatType = formatType = SL_DATAFORMAT_NULL; - } else { - formatType = *(SLuint32 *)pFormat; - switch (formatType) { - - case SL_DATAFORMAT_PCM: - pDataFormat->mPCM = *(SLDataFormat_PCM *)pFormat; - do { - - // check the channel count - switch (pDataFormat->mPCM.numChannels) { - case 1: // mono - case 2: // stereo - break; - case 0: // unknown - result = SL_RESULT_PARAMETER_INVALID; - break; - default: // multi-channel - result = SL_RESULT_CONTENT_UNSUPPORTED; - break; - } - if (SL_RESULT_SUCCESS != result) { - SL_LOGE("%s: numChannels=%u", name, (unsigned) pDataFormat->mPCM.numChannels); - break; - } - - // check the sampling rate - switch (pDataFormat->mPCM.samplesPerSec) { - case SL_SAMPLINGRATE_8: - case SL_SAMPLINGRATE_11_025: - case SL_SAMPLINGRATE_12: - case SL_SAMPLINGRATE_16: - case SL_SAMPLINGRATE_22_05: - case SL_SAMPLINGRATE_24: - case SL_SAMPLINGRATE_32: - case SL_SAMPLINGRATE_44_1: - case SL_SAMPLINGRATE_48: - case SL_SAMPLINGRATE_64: - case SL_SAMPLINGRATE_88_2: - case SL_SAMPLINGRATE_96: - case SL_SAMPLINGRATE_192: - break; - case 0: - result = SL_RESULT_PARAMETER_INVALID; - break; - default: - result = SL_RESULT_CONTENT_UNSUPPORTED; - break; - } - if (SL_RESULT_SUCCESS != result) { - SL_LOGE("%s: samplesPerSec=%u", name, pDataFormat->mPCM.samplesPerSec); - break; - } - - // check the sample bit depth - switch (pDataFormat->mPCM.bitsPerSample) { - case SL_PCMSAMPLEFORMAT_FIXED_8: - case SL_PCMSAMPLEFORMAT_FIXED_16: - break; - case SL_PCMSAMPLEFORMAT_FIXED_20: - case SL_PCMSAMPLEFORMAT_FIXED_24: - case SL_PCMSAMPLEFORMAT_FIXED_28: - case SL_PCMSAMPLEFORMAT_FIXED_32: - result = SL_RESULT_CONTENT_UNSUPPORTED; - break; - default: - result = SL_RESULT_PARAMETER_INVALID; - break; - } - if (SL_RESULT_SUCCESS != result) { - SL_LOGE("%s: bitsPerSample=%u", name, pDataFormat->mPCM.bitsPerSample); - break; - } - - // check the container bit depth - if (pDataFormat->mPCM.containerSize < pDataFormat->mPCM.bitsPerSample) { - result = SL_RESULT_PARAMETER_INVALID; - } else if (pDataFormat->mPCM.containerSize != pDataFormat->mPCM.bitsPerSample) { - result = SL_RESULT_CONTENT_UNSUPPORTED; - } - if (SL_RESULT_SUCCESS != result) { - SL_LOGE("%s: containerSize=%u, bitsPerSample=%u", name, - (unsigned) pDataFormat->mPCM.containerSize, - (unsigned) pDataFormat->mPCM.bitsPerSample); - break; - } - - // check the channel mask - switch (pDataFormat->mPCM.channelMask) { - case SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT: - if (2 != pDataFormat->mPCM.numChannels) { - result = SL_RESULT_PARAMETER_INVALID; - } - break; - case SL_SPEAKER_FRONT_LEFT: - case SL_SPEAKER_FRONT_RIGHT: - case SL_SPEAKER_FRONT_CENTER: - if (1 != pDataFormat->mPCM.numChannels) { - result = SL_RESULT_PARAMETER_INVALID; - } - break; - case 0: - // The default of front left rather than center for mono may be non-intuitive, - // but the left channel is the first channel for stereo or multichannel content. - pDataFormat->mPCM.channelMask = pDataFormat->mPCM.numChannels == 2 ? - SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT : SL_SPEAKER_FRONT_LEFT; - break; - default: - result = SL_RESULT_PARAMETER_INVALID; - break; - } - if (SL_RESULT_SUCCESS != result) { - SL_LOGE("%s: channelMask=0x%x numChannels=%u", name, - pDataFormat->mPCM.channelMask, pDataFormat->mPCM.numChannels); - break; - } - - // check the endianness / byte order - switch (pDataFormat->mPCM.endianness) { - case SL_BYTEORDER_LITTLEENDIAN: - case SL_BYTEORDER_BIGENDIAN: - break; - // native is proposed but not yet in spec - default: - result = SL_RESULT_PARAMETER_INVALID; - break; - } - if (SL_RESULT_SUCCESS != result) { - SL_LOGE("%s: endianness=%u", name, (unsigned) pDataFormat->mPCM.endianness); - break; - } - - // here if all checks passed successfully - - } while(0); - break; - - case SL_DATAFORMAT_MIME: - pDataFormat->mMIME = *(SLDataFormat_MIME *)pFormat; - if (NULL != pDataFormat->mMIME.mimeType) { - // NTH check address for validity - size_t len = strlen((const char *) pDataFormat->mMIME.mimeType); - SLchar *myMIME = (SLchar *) malloc(len + 1); - if (NULL == myMIME) { - result = SL_RESULT_MEMORY_FAILURE; - } else { - memcpy(myMIME, pDataFormat->mMIME.mimeType, len + 1); - // make sure MIME string was not modified asynchronously - if ('\0' != myMIME[len]) { - free(myMIME); - myMIME = NULL; - result = SL_RESULT_PRECONDITIONS_VIOLATED; - } - } - pDataFormat->mMIME.mimeType = myMIME; - } - break; - - case XA_DATAFORMAT_RAWIMAGE: - pDataFormat->mRawImage = *(XADataFormat_RawImage *)pFormat; - switch (pDataFormat->mRawImage.colorFormat) { - case XA_COLORFORMAT_MONOCHROME: - case XA_COLORFORMAT_8BITRGB332: - case XA_COLORFORMAT_12BITRGB444: - case XA_COLORFORMAT_16BITARGB4444: - case XA_COLORFORMAT_16BITARGB1555: - case XA_COLORFORMAT_16BITRGB565: - case XA_COLORFORMAT_16BITBGR565: - case XA_COLORFORMAT_18BITRGB666: - case XA_COLORFORMAT_18BITARGB1665: - case XA_COLORFORMAT_19BITARGB1666: - case XA_COLORFORMAT_24BITRGB888: - case XA_COLORFORMAT_24BITBGR888: - case XA_COLORFORMAT_24BITARGB1887: - case XA_COLORFORMAT_25BITARGB1888: - case XA_COLORFORMAT_32BITBGRA8888: - case XA_COLORFORMAT_32BITARGB8888: - case XA_COLORFORMAT_YUV411PLANAR: - case XA_COLORFORMAT_YUV420PLANAR: - case XA_COLORFORMAT_YUV420SEMIPLANAR: - case XA_COLORFORMAT_YUV422PLANAR: - case XA_COLORFORMAT_YUV422SEMIPLANAR: - case XA_COLORFORMAT_YCBYCR: - case XA_COLORFORMAT_YCRYCB: - case XA_COLORFORMAT_CBYCRY: - case XA_COLORFORMAT_CRYCBY: - case XA_COLORFORMAT_YUV444INTERLEAVED: - case XA_COLORFORMAT_RAWBAYER8BIT: - case XA_COLORFORMAT_RAWBAYER10BIT: - case XA_COLORFORMAT_RAWBAYER8BITCOMPRESSED: - case XA_COLORFORMAT_L2: - case XA_COLORFORMAT_L4: - case XA_COLORFORMAT_L8: - case XA_COLORFORMAT_L16: - case XA_COLORFORMAT_L24: - case XA_COLORFORMAT_L32: - case XA_COLORFORMAT_18BITBGR666: - case XA_COLORFORMAT_24BITARGB6666: - case XA_COLORFORMAT_24BITABGR6666: - break; - case XA_COLORFORMAT_UNUSED: - default: - result = XA_RESULT_PARAMETER_INVALID; - SL_LOGE("%s: unsupported color format %d", name, - pDataFormat->mRawImage.colorFormat); - break; - } - // no checks for height, width, or stride - break; - - default: - result = SL_RESULT_PARAMETER_INVALID; - SL_LOGE("%s: formatType=%u", name, (unsigned) formatType); - break; - - } - - // make sure format type was not modified asynchronously - if ((SL_RESULT_SUCCESS == result) && (formatType != pDataFormat->mFormatType)) { - SL_LOGE("%s: formatType changed from %u to %u", name, formatType, - pDataFormat->mFormatType); - result = SL_RESULT_PRECONDITIONS_VIOLATED; - } - - } - - // Verify that the data format type is allowed in this context - if (SL_RESULT_SUCCESS == result) { - SLuint32 actualMask; - switch (formatType) { - case SL_DATAFORMAT_NULL: - case SL_DATAFORMAT_MIME: - case SL_DATAFORMAT_PCM: - case XA_DATAFORMAT_RAWIMAGE: - actualMask = 1L << formatType; - break; - default: - assert(false); - actualMask = 0L; - break; - } - if (!(allowedDataFormatMask & actualMask)) { - SL_LOGE("%s: data format %d not allowed", name, formatType); - result = SL_RESULT_CONTENT_UNSUPPORTED; - } - } - - return result; -} - - -/** \brief Check interface ID compatibility with respect to a particular source - * and sink data locator format - */ - -SLresult checkSourceSinkVsInterfacesCompatibility(const DataLocatorFormat *pSrcDataLocatorFormat, - const DataLocatorFormat *pSinkDataLocatorFormat, - const ClassTable *clazz, unsigned requiredMask) { - int index; - switch (pSrcDataLocatorFormat->mLocator.mLocatorType) { - case SL_DATALOCATOR_URI: -#ifdef ANDROID - case SL_DATALOCATOR_ANDROIDFD: -#endif - // URIs and FD can be sources when "playing" to an OutputMix or a Buffer Queue for decode - // so we don't prevent the retrieval of the BufferQueue interfaces for those sources - switch (pSinkDataLocatorFormat->mLocator.mLocatorType) { - case SL_DATALOCATOR_BUFFERQUEUE: -#ifdef ANDROID - case SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE: -#endif - break; - default: - // can't require SLBufferQueueItf or its alias SLAndroidSimpleBufferQueueItf - // if the data sink is not a buffer queue - index = clazz->mMPH_to_index[MPH_BUFFERQUEUE]; -#ifdef ANDROID - assert(index == clazz->mMPH_to_index[MPH_ANDROIDSIMPLEBUFFERQUEUE]); -#endif - if (0 <= index) { - if (requiredMask & (1 << index)) { - SL_LOGE("can't require SL_IID_BUFFERQUEUE " -#ifdef ANDROID - "or SL_IID_ANDROIDSIMPLEBUFFERQUEUE " -#endif - "with a non-buffer queue data sink"); - return SL_RESULT_FEATURE_UNSUPPORTED; - } - } - break; - } - break; - - case SL_DATALOCATOR_BUFFERQUEUE: -#ifdef ANDROID - case SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE: -#endif - // can't require SLSeekItf if data source is a buffer queue - index = clazz->mMPH_to_index[MPH_SEEK]; - if (0 <= index) { - if (requiredMask & (1 << index)) { - SL_LOGE("can't require SL_IID_SEEK with a buffer queue data source"); - return SL_RESULT_FEATURE_UNSUPPORTED; - } - } - // can't require SLMuteSoloItf if data source is a mono buffer queue - index = clazz->mMPH_to_index[MPH_MUTESOLO]; - if (0 <= index) { - if ((requiredMask & (1 << index)) && - (SL_DATAFORMAT_PCM == pSrcDataLocatorFormat->mFormat.mFormatType) && - (1 == pSrcDataLocatorFormat->mFormat.mPCM.numChannels)) { - SL_LOGE("can't require SL_IID_MUTESOLO with a mono buffer queue data source"); - return SL_RESULT_FEATURE_UNSUPPORTED; - } - } - break; - -#ifdef ANDROID - case SL_DATALOCATOR_ANDROIDBUFFERQUEUE: - // can't require SLSeekItf if data source is an Android buffer queue - index = clazz->mMPH_to_index[MPH_SEEK]; - if (0 <= index) { - if (requiredMask & (1 << index)) { - SL_LOGE("can't require SL_IID_SEEK with a SL_DATALOCATOR_ANDROIDBUFFERQUEUE "\ - "source"); - return SL_RESULT_FEATURE_UNSUPPORTED; - } - } - switch (pSinkDataLocatorFormat->mLocator.mLocatorType) { - // for use-case AAC decode from SLAndroidBufferQueueItf with AAC ADTS data - case SL_DATALOCATOR_BUFFERQUEUE: - case SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE: - break; - // for use-case audio playback from SLAndroidBufferQueueItf with MP2TS data - case SL_DATALOCATOR_OUTPUTMIX: - break; - default: - SL_LOGE("Invalid sink for SL_DATALOCATOR_ANDROIDBUFFERQUEUE source"); - return SL_RESULT_FEATURE_UNSUPPORTED; - break; - } - break; -#endif - case SL_DATALOCATOR_ADDRESS: - case SL_DATALOCATOR_MIDIBUFFERQUEUE: - case XA_DATALOCATOR_NATIVEDISPLAY: - // any special checks here??? - default: - // can't require SLBufferQueueItf or its alias SLAndroidSimpleBufferQueueItf - // if the data source is not a buffer queue - index = clazz->mMPH_to_index[MPH_BUFFERQUEUE]; -#ifdef ANDROID - assert(index == clazz->mMPH_to_index[MPH_ANDROIDSIMPLEBUFFERQUEUE]); -#endif - if (0 <= index) { - if (requiredMask & (1 << index)) { - SL_LOGE("can't require SL_IID_BUFFERQUEUE " -#ifdef ANDROID - "or SL_IID_ANDROIDSIMPLEBUFFERQUEUE " -#endif - "with a non-buffer queue data source"); - return SL_RESULT_FEATURE_UNSUPPORTED; - } - } - break; - } - return SL_RESULT_SUCCESS; -} - - -/** \brief Free the local deep copy of a data format */ - -static void freeDataFormat(DataFormat *pDataFormat) -{ - switch (pDataFormat->mFormatType) { - case SL_DATAFORMAT_MIME: - if (NULL != pDataFormat->mMIME.mimeType) { - free(pDataFormat->mMIME.mimeType); - pDataFormat->mMIME.mimeType = NULL; - } - break; - case SL_DATAFORMAT_PCM: - case XA_DATAFORMAT_RAWIMAGE: - case SL_DATAFORMAT_NULL: - break; - default: - // an invalid data format is caught earlier during the copy - assert(false); - break; - } -} - - -/** \brief Check a data source and make local deep copy */ - -SLresult checkDataSource(const char *name, const SLDataSource *pDataSrc, - DataLocatorFormat *pDataLocatorFormat, SLuint32 allowedDataLocatorMask, - SLuint32 allowedDataFormatMask) -{ - assert(NULL != name && NULL != pDataLocatorFormat); - pDataLocatorFormat->u.mSource.pLocator = &pDataLocatorFormat->mLocator; - pDataLocatorFormat->u.mSource.pFormat = &pDataLocatorFormat->mFormat; - - if (NULL == pDataSrc) { - pDataLocatorFormat->mLocator.mLocatorType = SL_DATALOCATOR_NULL; - pDataLocatorFormat->mFormat.mFormatType = SL_DATAFORMAT_NULL; - if ((allowedDataLocatorMask & DATALOCATOR_MASK_NULL) && - (allowedDataFormatMask & DATAFORMAT_MASK_NULL)) { - return SL_RESULT_SUCCESS; - } - SL_LOGE("%s: data source cannot be NULL", name); - return SL_RESULT_PARAMETER_INVALID; - } - SLDataSource myDataSrc = *pDataSrc; - SLresult result; - result = checkDataLocator(name, myDataSrc.pLocator, &pDataLocatorFormat->mLocator, - allowedDataLocatorMask); - if (SL_RESULT_SUCCESS != result) { - return result; - } - - switch (pDataLocatorFormat->mLocator.mLocatorType) { - case SL_DATALOCATOR_URI: - allowedDataFormatMask &= DATAFORMAT_MASK_MIME; - break; - case SL_DATALOCATOR_ADDRESS: - case SL_DATALOCATOR_BUFFERQUEUE: - allowedDataFormatMask &= DATAFORMAT_MASK_PCM; - break; - // Per the spec, the pFormat field is ignored in some cases - case SL_DATALOCATOR_IODEVICE: - myDataSrc.pFormat = NULL; - // fall through - case SL_DATALOCATOR_NULL: - case SL_DATALOCATOR_MIDIBUFFERQUEUE: - allowedDataFormatMask &= DATAFORMAT_MASK_NULL; - break; - case SL_DATALOCATOR_OUTPUTMIX: - case XA_DATALOCATOR_NATIVEDISPLAY: - allowedDataFormatMask = DATAFORMAT_MASK_NONE; - break; -#ifdef ANDROID - case SL_DATALOCATOR_ANDROIDFD: - allowedDataFormatMask &= DATAFORMAT_MASK_MIME; - break; - case SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE: - allowedDataFormatMask &= DATAFORMAT_MASK_PCM; - break; - case SL_DATALOCATOR_ANDROIDBUFFERQUEUE: - allowedDataFormatMask &= DATAFORMAT_MASK_MIME;; - break; -#endif - default: - // invalid data locator type is caught earlier - assert(false); - allowedDataFormatMask = DATAFORMAT_MASK_NONE; - break; - } - - result = checkDataFormat(name, myDataSrc.pFormat, &pDataLocatorFormat->mFormat, - allowedDataFormatMask); - if (SL_RESULT_SUCCESS != result) { - freeDataLocator(&pDataLocatorFormat->mLocator); - return result; - } - - return SL_RESULT_SUCCESS; -} - - -/** \brief Check a data sink and make local deep copy */ - -SLresult checkDataSink(const char *name, const SLDataSink *pDataSink, - DataLocatorFormat *pDataLocatorFormat, SLuint32 allowedDataLocatorMask, - SLuint32 allowedDataFormatMask) -{ - assert(NULL != name && NULL != pDataLocatorFormat); - pDataLocatorFormat->u.mSink.pLocator = &pDataLocatorFormat->mLocator; - pDataLocatorFormat->u.mSink.pFormat = &pDataLocatorFormat->mFormat; - - if (NULL == pDataSink) { - pDataLocatorFormat->mLocator.mLocatorType = SL_DATALOCATOR_NULL; - pDataLocatorFormat->mFormat.mFormatType = SL_DATAFORMAT_NULL; - if ((allowedDataLocatorMask & DATALOCATOR_MASK_NULL) && - (allowedDataFormatMask & DATAFORMAT_MASK_NULL)) { - return SL_RESULT_SUCCESS; - } - SL_LOGE("%s: data sink cannot be NULL", name); - return SL_RESULT_PARAMETER_INVALID; - } - SLDataSink myDataSink = *pDataSink; - SLresult result; - result = checkDataLocator(name, myDataSink.pLocator, &pDataLocatorFormat->mLocator, - allowedDataLocatorMask); - if (SL_RESULT_SUCCESS != result) { - return result; - } - - switch (pDataLocatorFormat->mLocator.mLocatorType) { - case SL_DATALOCATOR_URI: - allowedDataFormatMask &= DATAFORMAT_MASK_MIME; - break; - case SL_DATALOCATOR_ADDRESS: - case SL_DATALOCATOR_BUFFERQUEUE: - allowedDataFormatMask &= DATAFORMAT_MASK_PCM; - break; - // Per the spec, the pFormat field is ignored in some cases - case SL_DATALOCATOR_IODEVICE: - case SL_DATALOCATOR_OUTPUTMIX: - case XA_DATALOCATOR_NATIVEDISPLAY: - myDataSink.pFormat = NULL; - // fall through - case SL_DATALOCATOR_NULL: - case SL_DATALOCATOR_MIDIBUFFERQUEUE: - allowedDataFormatMask &= DATAFORMAT_MASK_NULL; - break; -#ifdef ANDROID - case SL_DATALOCATOR_ANDROIDFD: - allowedDataFormatMask = DATAFORMAT_MASK_NONE; - break; - case SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE: - allowedDataFormatMask &= DATAFORMAT_MASK_PCM; - break; - case SL_DATALOCATOR_ANDROIDBUFFERQUEUE: - allowedDataFormatMask = DATAFORMAT_MASK_NONE; - break; -#endif - default: - // invalid data locator type is caught earlier - assert(false); - allowedDataFormatMask = DATAFORMAT_MASK_NONE; - break; - } - - result = checkDataFormat(name, myDataSink.pFormat, &pDataLocatorFormat->mFormat, - allowedDataFormatMask); - if (SL_RESULT_SUCCESS != result) { - freeDataLocator(&pDataLocatorFormat->mLocator); - return result; - } - - return SL_RESULT_SUCCESS; -} - - -/** \brief Free the local deep copy of a data locator format */ - -void freeDataLocatorFormat(DataLocatorFormat *dlf) -{ - assert(NULL != dlf); - freeDataLocator(&dlf->mLocator); - freeDataFormat(&dlf->mFormat); -} diff --git a/wilhelm/src/data.h b/wilhelm/src/data.h deleted file mode 100644 index a5f7fafa..00000000 --- a/wilhelm/src/data.h +++ /dev/null @@ -1,115 +0,0 @@ -/* - * 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. - */ - -/* Our own merged version of SLDataSource and SLDataSink */ - -typedef union { - SLuint32 mLocatorType; - SLDataLocator_Address mAddress; - SLDataLocator_BufferQueue mBufferQueue; - SLDataLocator_IODevice mIODevice; - SLDataLocator_MIDIBufferQueue mMIDIBufferQueue; - SLDataLocator_OutputMix mOutputMix; - SLDataLocator_URI mURI; - XADataLocator_NativeDisplay mNativeDisplay; -#ifdef ANDROID - SLDataLocator_AndroidFD mFD; - SLDataLocator_AndroidBufferQueue mABQ; -#endif -} DataLocator; - -typedef union { - SLuint32 mFormatType; - SLDataFormat_PCM mPCM; - SLDataFormat_MIME mMIME; - XADataFormat_RawImage mRawImage; -} DataFormat; - -typedef struct { - union { - SLDataSource mSource; - SLDataSink mSink; - struct { - DataLocator *pLocator; - DataFormat *pFormat; - } mNeutral; - } u; - DataLocator mLocator; - DataFormat mFormat; -} DataLocatorFormat; - -#define SL_DATALOCATOR_NULL 0 // application specified a NULL value for pLocator - // (not a valid value for mLocatorType) -#define XA_DATALOCATOR_NULL SL_DATALOCATOR_NULL -#define SL_DATAFORMAT_NULL 0 // application specified a NULL value for pFormat - // (not a valid value for mLocatorType) -#define XA_DATAFORMAT_NULL SL_DATAFORMAT_NULL - -// bit masks used to configure the allowed data locators for a given data source or data sink -#define DATALOCATOR_MASK_NONE 0L -#define DATALOCATOR_MASK_NULL (1L << SL_DATALOCATOR_NULL) -#define DATALOCATOR_MASK_URI (1L << SL_DATALOCATOR_URI) -#define DATALOCATOR_MASK_ADDRESS (1L << SL_DATALOCATOR_ADDRESS) -#define DATALOCATOR_MASK_IODEVICE (1L << SL_DATALOCATOR_IODEVICE) -#define DATALOCATOR_MASK_OUTPUTMIX (1L << SL_DATALOCATOR_OUTPUTMIX) -#define DATALOCATOR_MASK_NATIVEDISPLAY (1L << XA_DATALOCATOR_NATIVEDISPLAY) -#define DATALOCATOR_MASK_BUFFERQUEUE (1L << SL_DATALOCATOR_BUFFERQUEUE) -#define DATALOCATOR_MASK_MIDIBUFFERQUEUE (1L << SL_DATALOCATOR_MIDIBUFFERQUEUE) -#define DATALOCATOR_MASK_ANDROIDFD \ - (0x100L << (SL_DATALOCATOR_ANDROIDFD - SL_DATALOCATOR_ANDROIDFD)) -#define DATALOCATOR_MASK_ANDROIDSIMPLEBUFFERQUEUE \ - (0x100L << (SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE - SL_DATALOCATOR_ANDROIDFD)) -#define DATALOCATOR_MASK_ANDROIDBUFFERQUEUE \ - (0x100L << (SL_DATALOCATOR_ANDROIDBUFFERQUEUE - SL_DATALOCATOR_ANDROIDFD)) -#define DATALOCATOR_MASK_ALL 0x7FFL - -// bit masks used to configure the allowed data formats for a given data source or data sink -#define DATAFORMAT_MASK_NONE 0L -#define DATAFORMAT_MASK_NULL (1L << SL_DATAFORMAT_NULL) -#define DATAFORMAT_MASK_MIME (1L << SL_DATAFORMAT_MIME) -#define DATAFORMAT_MASK_PCM (1L << SL_DATAFORMAT_PCM) -#define DATAFORMAT_MASK_RAWIMAGE (1L << XA_DATAFORMAT_RAWIMAGE) -#define DATAFORMAT_MASK_ALL 0xFL - -extern SLresult checkDataSource(const char *name, const SLDataSource *pDataSrc, - DataLocatorFormat *myDataSourceLocator, SLuint32 allowedDataLocatorMask, - SLuint32 allowedDataFormatMask); -extern SLresult checkDataSink(const char *name, const SLDataSink *pDataSink, - DataLocatorFormat *myDataSinkLocator, SLuint32 allowedDataLocatorMask, - SLuint32 allowedDataFormatMask); -extern SLresult checkSourceSinkVsInterfacesCompatibility( - const DataLocatorFormat *pSrcDataLocatorFormat, - const DataLocatorFormat *pSinkDataLocatorFormat, - const ClassTable *clazz, unsigned requiredMask); -extern void freeDataLocatorFormat(DataLocatorFormat *dlf); - - -/* For stream information storage */ -typedef struct { - XAuint32 domain; - union { - XAMediaContainerInformation containerInfo; - XAVideoStreamInformation videoInfo; - XAAudioStreamInformation audioInfo; - XAImageStreamInformation imageInfo; - XATimedTextStreamInformation textInfo; - XAMIDIStreamInformation midiInfo; - XAVendorStreamInformation vendorInfo; - }; -} StreamInfo; - -// FIXME a terrible hack until OpenMAX AL spec is updated -#define XA_DOMAINTYPE_CONTAINER 0 diff --git a/wilhelm/src/desktop/OutputMixExt.h b/wilhelm/src/desktop/OutputMixExt.h deleted file mode 100644 index aa4e3d90..00000000 --- a/wilhelm/src/desktop/OutputMixExt.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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. - */ - -/** \file OutputMixExt.h OutputMixExt interface */ - -#ifdef __cplusplus -extern "C" { -#endif -extern const SLInterfaceID SL_IID_OUTPUTMIXEXT; -#ifdef __cplusplus -} -#endif - -typedef const struct SLOutputMixExtItf_ * const * SLOutputMixExtItf; - -/** \brief v-table for IOutputMixExt */ - -struct SLOutputMixExtItf_ { - void (*FillBuffer)(SLOutputMixExtItf self, void *pBuffer, SLuint32 size); -}; - -/** \brief Track describes each PCM input source to OutputMix */ - -typedef struct { - struct BufferQueue_interface *mBufferQueue; - CAudioPlayer *mAudioPlayer; ///< Mixer examines this track if non-NULL - const void *mReader; ///< Pointer to next frame in BufferHeader.mBuffer - SLuint32 mAvail; ///< Number of available bytes in the current buffer - float mGains[STEREO_CHANNELS]; ///< Copied from CAudioPlayer::mGains - SLuint32 mFramesMixed; ///< Number of sample frames mixed from track; reset periodically -} Track; - -extern SLresult IOutputMixExt_checkAudioPlayerSourceSink(CAudioPlayer *thiz); -extern void audioPlayerGainUpdate(CAudioPlayer *thiz); -extern void IOutputMixExt_FillBuffer(SLOutputMixExtItf self, void *pBuffer, SLuint32 size); diff --git a/wilhelm/src/desktop/SDL.c b/wilhelm/src/desktop/SDL.c deleted file mode 100644 index edc27c91..00000000 --- a/wilhelm/src/desktop/SDL.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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. - */ - -/** \file SDL.c SDL platform implementation */ - -#include "sles_allinclusive.h" - - -/** \brief Called by SDL to fill the next audio output buffer */ - -static void SDLCALL SDL_callback(void *context, Uint8 *stream, int len) -{ - assert(len > 0); - IEngine *thisEngine = (IEngine *) context; - // A peek lock would be risky if output mixes are dynamic, so we use SDL_PauseAudio to - // temporarily disable callbacks during any change to the current output mix, and use a - // shared lock here - interface_lock_shared(thisEngine); - COutputMix *outputMix = thisEngine->mOutputMix; - interface_unlock_shared(thisEngine); - if (NULL != outputMix) { - SLOutputMixExtItf OutputMixExt = &outputMix->mOutputMixExt.mItf; - IOutputMixExt_FillBuffer(OutputMixExt, stream, (SLuint32) len); - } else { - memset(stream, 0, (size_t) len); - } -} - - -/** \brief Called during slCreateEngine to initialize SDL */ - -void SDL_open(IEngine *thisEngine) -{ - SDL_AudioSpec fmt; - fmt.freq = 44100; - fmt.format = AUDIO_S16; - fmt.channels = STEREO_CHANNELS; -#ifdef _WIN32 // FIXME Either a bug or a serious misunderstanding - fmt.samples = SndFile_BUFSIZE; -#else - fmt.samples = SndFile_BUFSIZE / sizeof(short); -#endif - fmt.callback = SDL_callback; - fmt.userdata = (void *) thisEngine; - - if (SDL_OpenAudio(&fmt, NULL) < 0) { - SL_LOGE("Unable to open audio: %s", SDL_GetError()); - exit(EXIT_FAILURE); - } -} - - -/** \brief Called during Object::Destroy for engine to shutdown SDL */ - -void SDL_close(void) -{ - SDL_CloseAudio(); -} diff --git a/wilhelm/src/desktop/SLSndFile.h b/wilhelm/src/desktop/SLSndFile.h deleted file mode 100644 index 87504bba..00000000 --- a/wilhelm/src/desktop/SLSndFile.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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. - */ - -/** \file SLSndFile.h libsndfile interface */ - -extern void SndFile_Callback(SLBufferQueueItf caller, void *pContext); -extern SLboolean SndFile_IsSupported(const SF_INFO *sfinfo); -extern SLresult SndFile_checkAudioPlayerSourceSink(CAudioPlayer *thiz); -extern void audioPlayerTransportUpdate(CAudioPlayer *thiz); -extern SLresult SndFile_Realize(CAudioPlayer *thiz); -extern void SndFile_Destroy(CAudioPlayer *thiz); diff --git a/wilhelm/src/desktop/SndFile.c b/wilhelm/src/desktop/SndFile.c deleted file mode 100644 index 91d0e03a..00000000 --- a/wilhelm/src/desktop/SndFile.c +++ /dev/null @@ -1,286 +0,0 @@ -/* - * 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. - */ - -/** \brief libsndfile integration */ - -#include "sles_allinclusive.h" - - -/** \brief Called by SndFile.c:audioPlayerTransportUpdate after a play state change or seek, - * and by IOutputMixExt::FillBuffer after each buffer is consumed. - */ - -void SndFile_Callback(SLBufferQueueItf caller, void *pContext) -{ - CAudioPlayer *thisAP = (CAudioPlayer *) pContext; - object_lock_peek(&thisAP->mObject); - SLuint32 state = thisAP->mPlay.mState; - object_unlock_peek(&thisAP->mObject); - if (SL_PLAYSTATE_PLAYING != state) { - return; - } - struct SndFile *thiz = &thisAP->mSndFile; - SLresult result; - pthread_mutex_lock(&thiz->mMutex); - if (thiz->mEOF) { - pthread_mutex_unlock(&thiz->mMutex); - return; - } - short *pBuffer = &thiz->mBuffer[thiz->mWhich * SndFile_BUFSIZE]; - if (++thiz->mWhich >= SndFile_NUMBUFS) { - thiz->mWhich = 0; - } - sf_count_t count; - count = sf_read_short(thiz->mSNDFILE, pBuffer, (sf_count_t) SndFile_BUFSIZE); - pthread_mutex_unlock(&thiz->mMutex); - bool headAtNewPos = false; - object_lock_exclusive(&thisAP->mObject); - slPlayCallback callback = thisAP->mPlay.mCallback; - void *context = thisAP->mPlay.mContext; - // make a copy of sample rate so we are absolutely sure we will not divide by zero - SLuint32 sampleRateMilliHz = thisAP->mSampleRateMilliHz; - if (UNKNOWN_SAMPLERATE != sampleRateMilliHz) { - // this will overflow after 49 days, but no fix possible as it's part of the API - thisAP->mPlay.mPosition = (SLuint32) (((long long) thisAP->mPlay.mFramesSinceLastSeek * - 1000000LL) / sampleRateMilliHz) + thisAP->mPlay.mLastSeekPosition; - // make a good faith effort for the mean time between "head at new position" callbacks to - // occur at the requested update period, but there will be jitter - SLuint32 frameUpdatePeriod = thisAP->mPlay.mFrameUpdatePeriod; - if ((0 != frameUpdatePeriod) && - (thisAP->mPlay.mFramesSincePositionUpdate >= frameUpdatePeriod) && - (SL_PLAYEVENT_HEADATNEWPOS & thisAP->mPlay.mEventFlags)) { - // if we overrun a requested update period, then reset the clock modulo the - // update period so that it appears to the application as one or more lost callbacks, - // but no additional jitter - if ((thisAP->mPlay.mFramesSincePositionUpdate -= thisAP->mPlay.mFrameUpdatePeriod) >= - frameUpdatePeriod) { - thisAP->mPlay.mFramesSincePositionUpdate %= frameUpdatePeriod; - } - headAtNewPos = true; - } - } - if (0 < count) { - object_unlock_exclusive(&thisAP->mObject); - SLuint32 size = (SLuint32) (count * sizeof(short)); - result = IBufferQueue_Enqueue(caller, pBuffer, size); - // not much we can do if the Enqueue fails, so we'll just drop the decoded data - if (SL_RESULT_SUCCESS != result) { - SL_LOGE("enqueue failed 0x%x", result); - } - } else { - thisAP->mPlay.mState = SL_PLAYSTATE_PAUSED; - thiz->mEOF = SL_BOOLEAN_TRUE; - // this would result in a non-monotonically increasing position, so don't do it - // thisAP->mPlay.mPosition = thisAP->mPlay.mDuration; - object_unlock_exclusive_attributes(&thisAP->mObject, ATTR_TRANSPORT); - } - // callbacks are called with mutex unlocked - if (NULL != callback) { - if (headAtNewPos) { - (*callback)(&thisAP->mPlay.mItf, context, SL_PLAYEVENT_HEADATNEWPOS); - } - } -} - - -/** \brief Check whether the supplied libsndfile format is supported by us */ - -SLboolean SndFile_IsSupported(const SF_INFO *sfinfo) -{ - switch (sfinfo->format & SF_FORMAT_TYPEMASK) { - case SF_FORMAT_WAV: - break; - default: - return SL_BOOLEAN_FALSE; - } - switch (sfinfo->format & SF_FORMAT_SUBMASK) { - case SF_FORMAT_PCM_U8: - case SF_FORMAT_PCM_16: - break; - default: - return SL_BOOLEAN_FALSE; - } - switch (sfinfo->samplerate) { - case 11025: - case 22050: - case 44100: - break; - default: - return SL_BOOLEAN_FALSE; - } - switch (sfinfo->channels) { - case 1: - case 2: - break; - default: - return SL_BOOLEAN_FALSE; - } - return SL_BOOLEAN_TRUE; -} - - -/** \brief Check whether the partially-constructed AudioPlayer is compatible with libsndfile */ - -SLresult SndFile_checkAudioPlayerSourceSink(CAudioPlayer *thiz) -{ - const SLDataSource *pAudioSrc = &thiz->mDataSource.u.mSource; - SLuint32 locatorType = *(SLuint32 *)pAudioSrc->pLocator; - SLuint32 formatType = *(SLuint32 *)pAudioSrc->pFormat; - switch (locatorType) { - case SL_DATALOCATOR_BUFFERQUEUE: -#ifdef ANDROID - case SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE: -#endif - break; - case SL_DATALOCATOR_URI: - { - SLDataLocator_URI *dl_uri = (SLDataLocator_URI *) pAudioSrc->pLocator; - SLchar *uri = dl_uri->URI; - if (NULL == uri) { - return SL_RESULT_PARAMETER_INVALID; - } - if (!strncmp((const char *) uri, "file:///", 8)) { - uri += 8; - } - switch (formatType) { - case SL_DATAFORMAT_NULL: // OK to omit the data format - case SL_DATAFORMAT_MIME: // we ignore a MIME type if specified - break; - case SL_DATAFORMAT_PCM: - case XA_DATAFORMAT_RAWIMAGE: - return SL_RESULT_CONTENT_UNSUPPORTED; - default: - // an invalid data format is detected earlier during the deep copy - assert(false); - return SL_RESULT_INTERNAL_ERROR; - } - thiz->mSndFile.mPathname = uri; - thiz->mBufferQueue.mNumBuffers = SndFile_NUMBUFS; - } - break; - default: - return SL_RESULT_CONTENT_UNSUPPORTED; - } - thiz->mSndFile.mWhich = 0; - thiz->mSndFile.mSNDFILE = NULL; - // thiz->mSndFile.mMutex is initialized only when there is a valid mSNDFILE - thiz->mSndFile.mEOF = SL_BOOLEAN_FALSE; - - return SL_RESULT_SUCCESS; -} - - -/** \brief Called with mutex unlocked for marker and position updates, and play state change */ - -void audioPlayerTransportUpdate(CAudioPlayer *audioPlayer) -{ - - if (NULL != audioPlayer->mSndFile.mSNDFILE) { - - object_lock_exclusive(&audioPlayer->mObject); - SLboolean empty = 0 == audioPlayer->mBufferQueue.mState.count; - // FIXME a made-up number that should depend on player state and prefetch status - audioPlayer->mPrefetchStatus.mLevel = 1000; - SLmillisecond pos = audioPlayer->mSeek.mPos; - if (SL_TIME_UNKNOWN != pos) { - audioPlayer->mSeek.mPos = SL_TIME_UNKNOWN; - // trim seek position to the current known duration - if (pos > audioPlayer->mPlay.mDuration) { - pos = audioPlayer->mPlay.mDuration; - } - audioPlayer->mPlay.mLastSeekPosition = pos; - audioPlayer->mPlay.mFramesSinceLastSeek = 0; - // seek postpones the next head at new position callback - audioPlayer->mPlay.mFramesSincePositionUpdate = 0; - } - object_unlock_exclusive(&audioPlayer->mObject); - - if (SL_TIME_UNKNOWN != pos) { - - // discard any enqueued buffers for the old position - IBufferQueue_Clear(&audioPlayer->mBufferQueue.mItf); - empty = SL_BOOLEAN_TRUE; - - pthread_mutex_lock(&audioPlayer->mSndFile.mMutex); - // FIXME why void? - (void) sf_seek(audioPlayer->mSndFile.mSNDFILE, (sf_count_t) (((long long) pos * - audioPlayer->mSndFile.mSfInfo.samplerate) / 1000LL), SEEK_SET); - audioPlayer->mSndFile.mEOF = SL_BOOLEAN_FALSE; - audioPlayer->mSndFile.mWhich = 0; - pthread_mutex_unlock(&audioPlayer->mSndFile.mMutex); - - } - - // FIXME only on seek or play state change (STOPPED, PAUSED) -> PLAYING - if (empty) { - SndFile_Callback(&audioPlayer->mBufferQueue.mItf, audioPlayer); - } - - } - -} - - -/** \brief Called by CAudioPlayer_Realize */ - -SLresult SndFile_Realize(CAudioPlayer *thiz) -{ - SLresult result = SL_RESULT_SUCCESS; - if (NULL != thiz->mSndFile.mPathname) { - thiz->mSndFile.mSfInfo.format = 0; - thiz->mSndFile.mSNDFILE = sf_open( - (const char *) thiz->mSndFile.mPathname, SFM_READ, &thiz->mSndFile.mSfInfo); - if (NULL == thiz->mSndFile.mSNDFILE) { - result = SL_RESULT_CONTENT_NOT_FOUND; - } else if (!SndFile_IsSupported(&thiz->mSndFile.mSfInfo)) { - sf_close(thiz->mSndFile.mSNDFILE); - thiz->mSndFile.mSNDFILE = NULL; - result = SL_RESULT_CONTENT_UNSUPPORTED; - } else { - int ok; - ok = pthread_mutex_init(&thiz->mSndFile.mMutex, (const pthread_mutexattr_t *) NULL); - assert(0 == ok); - SLBufferQueueItf bufferQueue = &thiz->mBufferQueue.mItf; - IBufferQueue *thisBQ = (IBufferQueue *) bufferQueue; - IBufferQueue_RegisterCallback(&thisBQ->mItf, SndFile_Callback, thiz); - thiz->mPrefetchStatus.mStatus = SL_PREFETCHSTATUS_SUFFICIENTDATA; - // this is the initial duration; will update when a new maximum position is detected - thiz->mPlay.mDuration = (SLmillisecond) (((long long) thiz->mSndFile.mSfInfo.frames * - 1000LL) / thiz->mSndFile.mSfInfo.samplerate); - thiz->mNumChannels = thiz->mSndFile.mSfInfo.channels; - thiz->mSampleRateMilliHz = thiz->mSndFile.mSfInfo.samplerate * 1000; -#ifdef USE_OUTPUTMIXEXT - thiz->mPlay.mFrameUpdatePeriod = ((long long) thiz->mPlay.mPositionUpdatePeriod * - (long long) thiz->mSampleRateMilliHz) / 1000000LL; -#endif - } - } - return result; -} - - -/** \brief Called by CAudioPlayer_Destroy */ - -void SndFile_Destroy(CAudioPlayer *thiz) -{ - if (NULL != thiz->mSndFile.mSNDFILE) { - sf_close(thiz->mSndFile.mSNDFILE); - thiz->mSndFile.mSNDFILE = NULL; - int ok; - ok = pthread_mutex_destroy(&thiz->mSndFile.mMutex); - assert(0 == ok); - } -} diff --git a/wilhelm/src/devices.c b/wilhelm/src/devices.c deleted file mode 100644 index 920dd5e2..00000000 --- a/wilhelm/src/devices.c +++ /dev/null @@ -1,250 +0,0 @@ -/* - * 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. - */ - -#include "sles_allinclusive.h" - -/* Device table (change this when you port!) */ - -static const SLAudioInputDescriptor AudioInputDescriptor_mic = { - (SLchar *) "mic", // deviceName - SL_DEVCONNECTION_INTEGRATED, // deviceConnection - SL_DEVSCOPE_ENVIRONMENT, // deviceScope - SL_DEVLOCATION_HANDSET, // deviceLocation - SL_BOOLEAN_TRUE, // isForTelephony - SL_SAMPLINGRATE_44_1, // minSampleRate - SL_SAMPLINGRATE_44_1, // maxSampleRate - SL_BOOLEAN_TRUE, // isFreqRangeContinuous - NULL, // samplingRatesSupported - 0, // numOfSamplingRatesSupported - 1 // maxChannels -}; - -const struct AudioInput_id_descriptor AudioInput_id_descriptors[] = { - {SL_DEFAULTDEVICEID_AUDIOINPUT, &AudioInputDescriptor_mic}, - {0, NULL} -}; - -static const SLAudioOutputDescriptor AudioOutputDescriptor_speaker = { - (SLchar *) "speaker", // deviceName - SL_DEVCONNECTION_INTEGRATED, // deviceConnection - SL_DEVSCOPE_USER, // deviceScope - SL_DEVLOCATION_HEADSET, // deviceLocation - SL_BOOLEAN_TRUE, // isForTelephony - SL_SAMPLINGRATE_44_1, // minSamplingRate - SL_SAMPLINGRATE_44_1, // maxSamplingRate - SL_BOOLEAN_TRUE, // isFreqRangeContinuous - NULL, // samplingRatesSupported - 0, // numOfSamplingRatesSupported - 2 // maxChannels -}; - -static const SLAudioOutputDescriptor AudioOutputDescriptor_headset = { - (SLchar *) "headset", - SL_DEVCONNECTION_ATTACHED_WIRED, - SL_DEVSCOPE_USER, - SL_DEVLOCATION_HEADSET, - SL_BOOLEAN_FALSE, - SL_SAMPLINGRATE_44_1, - SL_SAMPLINGRATE_44_1, - SL_BOOLEAN_TRUE, - NULL, - 0, - 2 -}; - -static const SLAudioOutputDescriptor AudioOutputDescriptor_handsfree = { - (SLchar *) "handsfree", - SL_DEVCONNECTION_INTEGRATED, - SL_DEVSCOPE_ENVIRONMENT, - SL_DEVLOCATION_HANDSET, - SL_BOOLEAN_FALSE, - SL_SAMPLINGRATE_44_1, - SL_SAMPLINGRATE_44_1, - SL_BOOLEAN_TRUE, - NULL, - 0, - 2 -}; - -const struct AudioOutput_id_descriptor AudioOutput_id_descriptors[] = { - {SL_DEFAULTDEVICEID_AUDIOOUTPUT, &AudioOutputDescriptor_speaker}, - {DEVICE_ID_HEADSET, &AudioOutputDescriptor_headset}, - {DEVICE_ID_HANDSFREE, &AudioOutputDescriptor_handsfree}, - {0, NULL} -}; - -static const SLLEDDescriptor SLLEDDescriptor_default = { - 32, // ledCount - 0, // primaryLED - ~0 // colorMask -}; - -const struct LED_id_descriptor LED_id_descriptors[] = { - {SL_DEFAULTDEVICEID_LED, &SLLEDDescriptor_default}, - {0, NULL} -}; - -static const SLVibraDescriptor SLVibraDescriptor_default = { - SL_BOOLEAN_TRUE, // supportsFrequency - SL_BOOLEAN_TRUE, // supportsIntensity - 20000, // minFrequency - 100000 // maxFrequency -}; - -const struct Vibra_id_descriptor Vibra_id_descriptors[] = { - {SL_DEFAULTDEVICEID_VIBRA, &SLVibraDescriptor_default}, - {0, NULL} -}; - -// should build this table from Caps table below - -static const SLuint32 Codec_IDs[] = { - SL_AUDIOCODEC_PCM, - SL_AUDIOCODEC_MP3, - SL_AUDIOCODEC_AMR, - SL_AUDIOCODEC_AMRWB, - SL_AUDIOCODEC_AMRWBPLUS, - SL_AUDIOCODEC_AAC, - SL_AUDIOCODEC_WMA, - SL_AUDIOCODEC_REAL, - SL_AUDIOCODEC_VORBIS -}; - -const SLuint32 * const Decoder_IDs = Codec_IDs; -const SLuint32 * const Encoder_IDs = Codec_IDs; - -// for ANDROID, must match size and order of kVideoMimeTypes -static const SLuint32 VideoCodecIds[] = { - XA_VIDEOCODEC_MPEG2, - XA_VIDEOCODEC_H263, - XA_VIDEOCODEC_MPEG4, - XA_VIDEOCODEC_AVC, -#ifndef ANDROID - XA_VIDEOCODEC_VC1, -#endif -#ifdef ANDROID - XA_ANDROID_VIDEOCODEC_VP8 -#endif -}; - -const SLuint32 * const VideoDecoderIds = VideoCodecIds; - -// for ANDROID, must == kNbVideoMimeTypes -const XAuint32 kMaxVideoDecoders = sizeof(VideoCodecIds) / sizeof(VideoCodecIds[0]); - -static const SLmilliHertz SamplingRates_A[] = { - SL_SAMPLINGRATE_8, - SL_SAMPLINGRATE_11_025, - SL_SAMPLINGRATE_12, - SL_SAMPLINGRATE_16, - SL_SAMPLINGRATE_22_05, - SL_SAMPLINGRATE_24, - SL_SAMPLINGRATE_32, - SL_SAMPLINGRATE_44_1, - SL_SAMPLINGRATE_48 -}; - -static const SLAudioCodecDescriptor CodecDescriptor_A = { - 2, // maxChannels - 8, // minBitsPerSample - 16, // maxBitsPerSample - SL_SAMPLINGRATE_8, // minSampleRate - SL_SAMPLINGRATE_48, // maxSampleRate - SL_BOOLEAN_FALSE, // isFreqRangeContinuous - (SLmilliHertz *) SamplingRates_A, - // pSampleRatesSupported; - sizeof(SamplingRates_A) / sizeof(SamplingRates_A[0]), - // numSampleRatesSupported - 1, // minBitRate - ~0, // maxBitRate - SL_BOOLEAN_TRUE, // isBitrateRangeContinuous - NULL, // pBitratesSupported - 0, // numBitratesSupported - SL_AUDIOPROFILE_PCM, // profileSetting - 0 // modeSetting -}; - -const CodecDescriptor DecoderDescriptors[] = { - {SL_AUDIOCODEC_PCM, &CodecDescriptor_A}, - {SL_AUDIOCODEC_MP3, &CodecDescriptor_A}, - {SL_AUDIOCODEC_AMR, &CodecDescriptor_A}, - {SL_AUDIOCODEC_AMRWB, &CodecDescriptor_A}, - {SL_AUDIOCODEC_AMRWBPLUS, &CodecDescriptor_A}, - {SL_AUDIOCODEC_AAC, &CodecDescriptor_A}, - {SL_AUDIOCODEC_WMA, &CodecDescriptor_A}, - {SL_AUDIOCODEC_REAL, &CodecDescriptor_A}, - {SL_AUDIOCODEC_VORBIS, &CodecDescriptor_A}, - {SL_AUDIOCODEC_NULL, NULL} -}; - -const CodecDescriptor EncoderDescriptors[] = { - {SL_AUDIOCODEC_PCM, &CodecDescriptor_A}, - {SL_AUDIOCODEC_MP3, &CodecDescriptor_A}, - {SL_AUDIOCODEC_AMR, &CodecDescriptor_A}, - {SL_AUDIOCODEC_AMRWB, &CodecDescriptor_A}, - {SL_AUDIOCODEC_AMRWBPLUS, &CodecDescriptor_A}, - {SL_AUDIOCODEC_AAC, &CodecDescriptor_A}, - {SL_AUDIOCODEC_WMA, &CodecDescriptor_A}, - {SL_AUDIOCODEC_REAL, &CodecDescriptor_A}, - {SL_AUDIOCODEC_VORBIS, &CodecDescriptor_A}, - {SL_AUDIOCODEC_NULL, NULL} -}; - - -/** \brief Helper shared by decoder and encoder */ - -SLresult GetCodecCapabilities(SLuint32 codecId, SLuint32 *pIndex, - SLAudioCodecDescriptor *pDescriptor, const CodecDescriptor *codecDescriptors) -{ - if (NULL == pIndex) { - return SL_RESULT_PARAMETER_INVALID; - } - const CodecDescriptor *cd = codecDescriptors; - SLuint32 index; - if (NULL == pDescriptor) { - for (index = 0 ; NULL != cd->mDescriptor; ++cd) { - if (cd->mCodecID == codecId) { - ++index; - } - } - *pIndex = index; - return SL_RESULT_SUCCESS; - } - index = *pIndex; - for ( ; NULL != cd->mDescriptor; ++cd) { - if (cd->mCodecID == codecId) { - if (0 == index) { - *pDescriptor = *cd->mDescriptor; -#if 0 // Temporary workaround for Khronos bug 6331 - if (0 < pDescriptor->numSampleRatesSupported) { - // The malloc is not in the 1.0.1 specification - SLmilliHertz *temp = (SLmilliHertz *) malloc(sizeof(SLmilliHertz) * - pDescriptor->numSampleRatesSupported); - assert(NULL != temp); - memcpy(temp, pDescriptor->pSampleRatesSupported, sizeof(SLmilliHertz) * - pDescriptor->numSampleRatesSupported); - pDescriptor->pSampleRatesSupported = temp; - } else { - pDescriptor->pSampleRatesSupported = NULL; - } -#endif - return SL_RESULT_SUCCESS; - } - --index; - } - } - return SL_RESULT_PARAMETER_INVALID; -} diff --git a/wilhelm/src/devices.h b/wilhelm/src/devices.h deleted file mode 100644 index bf2814ee..00000000 --- a/wilhelm/src/devices.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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. - */ - -#define DEVICE_ID_HEADSET 1 -#define DEVICE_ID_HANDSFREE 2 - -extern const struct AudioInput_id_descriptor { - SLuint32 id; - const SLAudioInputDescriptor *descriptor; -} AudioInput_id_descriptors[]; - -extern const struct AudioOutput_id_descriptor { - SLuint32 id; - const SLAudioOutputDescriptor *descriptor; -} AudioOutput_id_descriptors[]; - -extern const struct LED_id_descriptor { - SLuint32 id; - const SLLEDDescriptor *descriptor; -} LED_id_descriptors[]; - -extern const struct Vibra_id_descriptor { - SLuint32 id; - const SLVibraDescriptor *descriptor; -} Vibra_id_descriptors[]; - -// These are not in 1.0.1 header file -#define SL_AUDIOCODEC_NULL 0 -#define SL_AUDIOCODEC_VORBIS 9 - -/** \brief Associates a codec ID with a corresponding codec descriptor */ - -typedef struct { - SLuint32 mCodecID; ///< The codec ID - const SLAudioCodecDescriptor *mDescriptor; ///< The corresponding descriptor -} CodecDescriptor; - -#define MAX_DECODERS 9 ///< (sizeof(Decoder_IDs) / sizeof(Decoder_IDs[0])) -#define MAX_ENCODERS 9 ///< (sizeof(Encoder_IDs) / sizeof(Encoder_IDs[0])) - -extern const XAuint32 * const VideoDecoderIds; -#ifndef ANDROID -extern const XAuint32 kMaxVideoDecoders; -#endif - -// For now, but encoders might be different than decoders later -extern const SLuint32 * const Decoder_IDs, * const Encoder_IDs; - -extern const CodecDescriptor DecoderDescriptors[], EncoderDescriptors[]; - -extern SLresult GetCodecCapabilities(SLuint32 decoderId, SLuint32 *pIndex, - SLAudioCodecDescriptor *pDescriptor, - const CodecDescriptor *codecDescriptors); diff --git a/wilhelm/src/entry.c b/wilhelm/src/entry.c deleted file mode 100644 index 8ee04302..00000000 --- a/wilhelm/src/entry.c +++ /dev/null @@ -1,249 +0,0 @@ -/* - * 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. - */ - -/* Initial global entry points */ - -#include "sles_allinclusive.h" - -#ifdef ANDROID -#include <media/stagefright/DataSource.h> -#include <binder/ProcessState.h> -#endif - -/** \brief Internal code shared by slCreateEngine and xaCreateEngine */ - -LI_API SLresult liCreateEngine(SLObjectItf *pEngine, SLuint32 numOptions, - const SLEngineOption *pEngineOptions, SLuint32 numInterfaces, - const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired, - const ClassTable *pCEngine_class) -{ - SLresult result; - - int ok; - ok = pthread_mutex_lock(&theOneTrueMutex); - assert(0 == ok); - bool needToUnlockTheOneTrueMutex = true; - - do { - - if (NULL == pEngine) { - result = SL_RESULT_PARAMETER_INVALID; - break; - } - *pEngine = NULL; - - if ((0 < numOptions) && (NULL == pEngineOptions)) { - SL_LOGE("numOptions=%u and pEngineOptions=NULL", numOptions); - result = SL_RESULT_PARAMETER_INVALID; - break; - } - - // default values - SLboolean threadSafe = SL_BOOLEAN_TRUE; - SLboolean lossOfControlGlobal = SL_BOOLEAN_FALSE; - - // process engine options - SLuint32 i; - const SLEngineOption *option = pEngineOptions; - result = SL_RESULT_SUCCESS; - for (i = 0; i < numOptions; ++i, ++option) { - switch (option->feature) { - case SL_ENGINEOPTION_THREADSAFE: - threadSafe = SL_BOOLEAN_FALSE != (SLboolean) option->data; // normalize - break; - case SL_ENGINEOPTION_LOSSOFCONTROL: - lossOfControlGlobal = SL_BOOLEAN_FALSE != (SLboolean) option->data; // normalize - break; - default: - SL_LOGE("unknown engine option: feature=%u data=%u", - option->feature, option->data); - result = SL_RESULT_PARAMETER_INVALID; - break; - } - } - if (SL_RESULT_SUCCESS != result) { - break; - } - - unsigned exposedMask; - assert(NULL != pCEngine_class); - result = checkInterfaces(pCEngine_class, numInterfaces, - pInterfaceIds, pInterfaceRequired, &exposedMask, NULL); - if (SL_RESULT_SUCCESS != result) { - break; - } - - // if an engine already exists, then increment its ref count - CEngine *thiz = theOneTrueEngine; - if (NULL != thiz) { - assert(0 < theOneTrueRefCount); - ++theOneTrueRefCount; - - // In order to update the engine object, we need to lock it, - // but that would violate the lock order and potentially deadlock. - // So we unlock now and note that it should not be unlocked later. - ok = pthread_mutex_unlock(&theOneTrueMutex); - assert(0 == ok); - needToUnlockTheOneTrueMutex = false; - object_lock_exclusive(&thiz->mObject); - - // now expose additional interfaces not requested by the earlier engine create - const struct iid_vtable *x = pCEngine_class->mInterfaces; - SLuint8 *interfaceStateP = thiz->mObject.mInterfaceStates; - SLuint32 index; - for (index = 0; index < pCEngine_class->mInterfaceCount; ++index, ++x, - exposedMask >>= 1, ++interfaceStateP) { - switch (*interfaceStateP) { - case INTERFACE_EXPOSED: // previously exposed - break; - case INTERFACE_INITIALIZED: // not exposed during the earlier create - if (exposedMask & 1) { - const struct MPH_init *mi = &MPH_init_table[x->mMPH]; - BoolHook expose = mi->mExpose; - if ((NULL == expose) || (*expose)((char *) thiz + x->mOffset)) { - *interfaceStateP = INTERFACE_EXPOSED; - } - // FIXME log or report to application that expose hook failed - } - break; - case INTERFACE_UNINITIALIZED: // no init hook - break; - default: // impossible - assert(false); - break; - } - } - object_unlock_exclusive(&thiz->mObject); - // return the shared engine object - *pEngine = &thiz->mObject.mItf; - break; - } - - // here when creating the first engine reference - assert(0 == theOneTrueRefCount); - -#ifdef ANDROID - android::ProcessState::self()->startThreadPool(); - android::DataSource::RegisterDefaultSniffers(); -#endif - - thiz = (CEngine *) construct(pCEngine_class, exposedMask, NULL); - if (NULL == thiz) { - result = SL_RESULT_MEMORY_FAILURE; - break; - } - - // initialize fields not associated with an interface - // mThreadPool is initialized in CEngine_Realize - memset(&thiz->mThreadPool, 0, sizeof(ThreadPool)); - memset(&thiz->mSyncThread, 0, sizeof(pthread_t)); -#if defined(ANDROID) - thiz->mEqNumPresets = 0; - thiz->mEqPresetNames = NULL; -#endif - // initialize fields related to an interface - thiz->mObject.mLossOfControlMask = lossOfControlGlobal ? ~0 : 0; - thiz->mEngine.mLossOfControlGlobal = lossOfControlGlobal; - thiz->mEngineCapabilities.mThreadSafe = threadSafe; - IObject_Publish(&thiz->mObject); - theOneTrueEngine = thiz; - theOneTrueRefCount = 1; - // return the new engine object - *pEngine = &thiz->mObject.mItf; - - } while(0); - - if (needToUnlockTheOneTrueMutex) { - ok = pthread_mutex_unlock(&theOneTrueMutex); - assert(0 == ok); - } - - return result; -} - - -/** Internal function for slQuerySupportedEngineInterfaces and xaQuerySupportedEngineInterfaces */ - -LI_API SLresult liQueryNumSupportedInterfaces(SLuint32 *pNumSupportedInterfaces, - const ClassTable *clazz) -{ - SLresult result; - if (NULL == pNumSupportedInterfaces) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - assert(NULL != clazz); - SLuint32 count = 0; - SLuint32 i; - for (i = 0; i < clazz->mInterfaceCount; ++i) { - switch (clazz->mInterfaces[i].mInterface) { - case INTERFACE_IMPLICIT: - case INTERFACE_IMPLICIT_PREREALIZE: - case INTERFACE_EXPLICIT: - case INTERFACE_EXPLICIT_PREREALIZE: - case INTERFACE_DYNAMIC: - ++count; - break; - case INTERFACE_UNAVAILABLE: - break; - default: - assert(false); - break; - } - } - *pNumSupportedInterfaces = count; - result = SL_RESULT_SUCCESS; - } - return result; -} - - -/** Internal function for slQuerySupportedEngineInterfaces and xaQuerySupportedEngineInterfaces */ - -LI_API SLresult liQuerySupportedInterfaces(SLuint32 index, SLInterfaceID *pInterfaceId, - const ClassTable *clazz) -{ - SLresult result; - if (NULL == pInterfaceId) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - *pInterfaceId = NULL; - assert(NULL != clazz); - result = SL_RESULT_PARAMETER_INVALID; // will be reset later - SLuint32 i; - for (i = 0; i < clazz->mInterfaceCount; ++i) { - switch (clazz->mInterfaces[i].mInterface) { - case INTERFACE_IMPLICIT: - case INTERFACE_IMPLICIT_PREREALIZE: - case INTERFACE_EXPLICIT: - case INTERFACE_EXPLICIT_PREREALIZE: - case INTERFACE_DYNAMIC: - break; - case INTERFACE_UNAVAILABLE: - continue; - default: - assert(false); - break; - } - if (index == 0) { - *pInterfaceId = &SL_IID_array[clazz->mInterfaces[i].mMPH]; - result = SL_RESULT_SUCCESS; - break; - } - --index; - } - } - return result; -} diff --git a/wilhelm/src/handler_bodies.c b/wilhelm/src/handler_bodies.c deleted file mode 100644 index b1af8e00..00000000 --- a/wilhelm/src/handler_bodies.c +++ /dev/null @@ -1,177 +0,0 @@ -/* - * 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. - */ - -#include "sles_allinclusive.h" - -// Handlers should return a mask of the attributes which they actually handled, -// or ATTR_NONE if they did not completely handle the attribute change. - -#ifdef ANDROID - -// SL_OBJECTID_AUDIOPLAYER, ATTR_GAIN -unsigned handler_AudioPlayer_gain(IObject *thiz) -{ - CAudioPlayer *ap = (CAudioPlayer *) thiz; - android_audioPlayer_volumeUpdate(ap); - return ATTR_GAIN; -} - - -// SL_OBJECTID_OUTPUTMIX, ATTR_GAIN -unsigned handler_OutputMix_gain(IObject *thiz) -{ - // FIXME update gains on all players attached to this outputmix - SL_LOGD("[ FIXME: gain update on an SL_OBJECTID_OUTPUTMIX to be implemented ]"); - return ATTR_GAIN; -} - - -// SL_OBJECTID_MIDIPLAYER, ATTR_GAIN -unsigned handler_MidiPlayer_gain(IObject *thiz) -{ - SL_LOGD("[ FIXME: gain update on an SL_OBJECTID_MIDIPLAYER to be implemented ]"); - return ATTR_GAIN; -} - - -// XA_OBJECTID_MEDIAPLAYER, ATTR_GAIN -unsigned handler_MediaPlayer_gain(IObject *thiz) -{ - CMediaPlayer *mp = (CMediaPlayer *) thiz; - android_Player_volumeUpdate(mp); - return ATTR_GAIN; -} - - -// SL_OBJECTID_AUDIOPLAYER, ATTR_POSITION -unsigned handler_AudioPlayer_position(IObject *thiz) -{ - CAudioPlayer *ap; - ap = (CAudioPlayer *) thiz; - // FIXME provide means to return result for invalid use cases (e.g. buffer queue data source) - (void) android_audioPlayer_seek(ap, ap->mSeek.mPos); - return ATTR_POSITION; -} - - -// SL_OBJECTID_MIDIPLAYER, ATTR_POSITION -unsigned handler_MidiPlayer_position(IObject *thiz) -{ - SL_LOGD("[ FIXME: position update on an SL_OBJECTID_MIDIPLAYER to be implemented ]"); - return ATTR_POSITION; -} - - -// SL_OBJECTID_AUDIOPLAYER, ATTR_TRANSPORT -unsigned handler_AudioPlayer_transport(IObject *thiz) -{ - CAudioPlayer *ap = (CAudioPlayer *) thiz; - android_audioPlayer_usePlayEventMask(ap); - return ATTR_TRANSPORT; -} - - -// SL_OBJECTID_AUDIOPLAYER, ATTR_PLAY_STATE -unsigned handler_AudioPlayer_play_state(IObject *thiz) -{ - CAudioPlayer *ap = (CAudioPlayer *) thiz; - android_audioPlayer_setPlayState(ap); - return ATTR_PLAY_STATE; -} - - -// SL_OBJECTID_AUDIORECORDER, ATTR_TRANSPORT -unsigned handler_AudioRecorder_transport(IObject *thiz) -{ - CAudioRecorder* ar = (CAudioRecorder *) thiz; - android_audioRecorder_useRecordEventMask(ar); - return ATTR_TRANSPORT; -} - - -// XA_OBJECTID_MEDIAPLAYER, ATTR_TRANSPORT -unsigned handler_MediaPlayer_transport(IObject *thiz) -{ - CMediaPlayer *mp = (CMediaPlayer *) thiz; - android_Player_usePlayEventMask(mp); - return ATTR_TRANSPORT; -} - - -// XA_OBJECTID_MEDIAPLAYER, ATTR_PLAY_STATE -unsigned handler_MediaPlayer_play_state(IObject *thiz) -{ - CMediaPlayer *mp = (CMediaPlayer *) thiz; - android::GenericPlayer* avp = mp->mAVPlayer.get(); - if (avp != NULL) { - android_Player_setPlayState(avp, mp->mPlay.mState, &(mp->mAndroidObjState)); - } - return ATTR_PLAY_STATE; -} - - -// SL_OBJECTID_AUDIOPLAYER, ATTR_BQ_ENQUEUE -unsigned handler_AudioPlayer_bq_enqueue(IObject *thiz) -{ - // ( buffer queue count is non-empty and play state == PLAYING ) became true - CAudioPlayer *ap = (CAudioPlayer *) thiz; - assert(SL_PLAYSTATE_PLAYING == ap->mPlay.mState); - android_audioPlayer_bufferQueue_onRefilled_l(ap); - return ATTR_BQ_ENQUEUE; -} - - -// SL_OBJECTID_AUDIOPLAYER, ATTR_ABQ_ENQUEUE -unsigned handler_AudioPlayer_abq_enqueue(IObject *thiz) -{ - // (Android buffer queue count is non-empty and play state == PLAYING ) became true - CAudioPlayer *ap = (CAudioPlayer *) thiz; - assert(SL_PLAYSTATE_PLAYING == ap->mPlay.mState); - android_audioPlayer_androidBufferQueue_onRefilled_l(ap); - return ATTR_ABQ_ENQUEUE; -} - - -// XA_OBJECTID_MEDIAPLAYER, ATTR_ABQ_ENQUEUE -unsigned handler_MediaPlayer_abq_enqueue(IObject *thiz) -{ - CMediaPlayer* mp = (CMediaPlayer *)thiz; - if (SL_PLAYSTATE_PLAYING == mp->mPlay.mState) { - android_Player_androidBufferQueue_onRefilled_l(mp); - } - return ATTR_ABQ_ENQUEUE; -} - -// XA_OBJECTID_MEDIAPLAYER, ATTR_POSITION -unsigned handler_MediaPlayer_position(IObject *thiz) -{ - CMediaPlayer *mp = (CMediaPlayer *) thiz; - // FIXME provide means to return result for invalid use cases (e.g. buffer queue data source) - (void) android_Player_seek(mp, mp->mSeek.mPos); - return ATTR_POSITION; -} - -#else // !defined(ANDROID) - -// SL_OBJECTID_AUDIOPLAYER, ATTR_GAIN -unsigned handler_AudioPlayer_gain(IObject *thiz) -{ - CAudioPlayer *ap = (CAudioPlayer *) thiz; - audioPlayerGainUpdate(ap); - return ATTR_GAIN; -} - -#endif diff --git a/wilhelm/src/handlers.c b/wilhelm/src/handlers.c deleted file mode 100644 index d08c31a1..00000000 --- a/wilhelm/src/handlers.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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. - */ - -#include <SLES/OpenSLES.h> -#include <OMXAL/OpenMAXAL.h> -#include "attr.h" -#include "handlers.h" - -#define NULL 0 - -/* The entries in this table are sorted first by object ID, and second - * by attribute mask. The holes in the table are deliberate to permit - * direct lookup. Don't cross streams! - */ -const AttributeHandler handlerTable[1 + XA_OBJECTID_CAMERADEVICE + - (SL_OBJECTID_METADATAEXTRACTOR - SL_OBJECTID_ENGINE) + 1][ATTR_INDEX_MAX] = { - -// XA IDs map directly to table indices - - [XA_OBJECTID_MEDIAPLAYER] = { - [ATTR_INDEX_GAIN] = handler_MediaPlayer_gain, - [ATTR_INDEX_TRANSPORT] = handler_MediaPlayer_transport, - [ATTR_INDEX_POSITION] = handler_MediaPlayer_position, - [ATTR_INDEX_ABQ_ENQUEUE] = handler_MediaPlayer_abq_enqueue, - [ATTR_INDEX_PLAY_STATE] = handler_MediaPlayer_play_state}, - -// SL IDs need a little arithmetic to make them contiguous with XA IDs -#define _(id) ((id) - SL_OBJECTID_ENGINE + XA_OBJECTID_CAMERADEVICE + 1) - - [_(SL_OBJECTID_AUDIOPLAYER)] = { -#ifdef ANDROID - [ATTR_INDEX_GAIN] = handler_AudioPlayer_gain, -#endif - [ATTR_INDEX_TRANSPORT] = handler_AudioPlayer_transport, - [ATTR_INDEX_POSITION] = handler_AudioPlayer_position, - [ATTR_INDEX_BQ_ENQUEUE] = handler_AudioPlayer_bq_enqueue, - [ATTR_INDEX_ABQ_ENQUEUE] = handler_AudioPlayer_abq_enqueue, - [ATTR_INDEX_PLAY_STATE] = handler_AudioPlayer_play_state}, - - [_(SL_OBJECTID_AUDIORECORDER)] = { - [ATTR_INDEX_TRANSPORT] = handler_AudioRecorder_transport}, - - [_(SL_OBJECTID_MIDIPLAYER)] = { - [ATTR_INDEX_GAIN] = handler_MidiPlayer_gain, - [ATTR_INDEX_POSITION] = handler_MidiPlayer_position}, - - [_(SL_OBJECTID_OUTPUTMIX)] = { - [ATTR_INDEX_GAIN] = handler_OutputMix_gain}, - -}; diff --git a/wilhelm/src/handlers.h b/wilhelm/src/handlers.h deleted file mode 100644 index c66cbb29..00000000 --- a/wilhelm/src/handlers.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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 __handlers_h -#define __handlers_h - -#define IObject struct Object_interface -IObject; - -#ifdef __cplusplus -extern "C" { -#endif - -extern unsigned handler_MediaPlayer_gain(IObject *thiz); -#ifdef ANDROID -extern unsigned handler_MediaPlayer_transport(IObject *thiz); -extern unsigned handler_MediaPlayer_position(IObject *thiz); -extern unsigned handler_MediaPlayer_abq_enqueue(IObject *thiz); -extern unsigned handler_MediaPlayer_play_state(IObject *thiz); -extern unsigned handler_AudioPlayer_gain(IObject *thiz); -extern unsigned handler_AudioPlayer_transport(IObject *thiz); -extern unsigned handler_AudioPlayer_position(IObject *thiz); -extern unsigned handler_AudioPlayer_bq_enqueue(IObject *thiz); -extern unsigned handler_AudioPlayer_abq_enqueue(IObject *thiz); -extern unsigned handler_AudioPlayer_play_state(IObject *thiz); -extern unsigned handler_AudioRecorder_transport(IObject *thiz); -extern unsigned handler_MidiPlayer_gain(IObject *thiz); -extern unsigned handler_MidiPlayer_position(IObject *thiz); -extern unsigned handler_OutputMix_gain(IObject *thiz); -#else -#define handler_MediaPlayer_gain NULL -#define handler_MediaPlayer_transport NULL -#define handler_MediaPlayer_position NULL -#define handler_MediaPlayer_abq_enqueue NULL -#define handler_MediaPlayer_play_state NULL -#define handler_AudioPlayer_transport NULL -#define handler_AudioPlayer_position NULL -#define handler_AudioPlayer_bq_enqueue NULL -#define handler_AudioPlayer_abq_enqueue NULL -#define handler_AudioPlayer_play_state NULL -#define handler_AudioRecorder_transport NULL -#define handler_MidiPlayer_gain NULL -#define handler_MidiPlayer_position NULL -#define handler_OutputMix_gain NULL -#endif - -#ifdef __cplusplus -} -#endif - - -/* Table entry for an attribute update handler. - * - * If the Object ID table index matches the object's ID, and the attribute table index - * match any of the updated attributes, then the specified handler - * is called. The handler is called with the object's mutex locked, - * and should return with mutex locked. The handler returns a bitmask of the attributes which - * were actually handled. This is normally the same as the attribute index, - * but could be a subset (including 0) if the handler discovers that the - * update is too complex to be handled synchronously and so must - * be deferred to the sync thread. Note that this direct lookup table organization - * gives O(1) search. - */ - -typedef unsigned (*AttributeHandler)(IObject *thiz); - -extern const AttributeHandler handlerTable[][ATTR_INDEX_MAX]; - -#undef IObject - -#endif // !defined(__handlers_h) diff --git a/wilhelm/src/interfaces.c b/wilhelm/src/interfaces.c deleted file mode 100644 index b0cbd9d7..00000000 --- a/wilhelm/src/interfaces.c +++ /dev/null @@ -1,140 +0,0 @@ -/* - * 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. - */ - -// Map minimal perfect hash of an interface ID to its name - -#include <assert.h> -#include <string.h> -#include "MPH.h" - -const char * const interface_names[MPH_MAX] = { - - // OpenSL ES 1.0.1 interfaces - "3DCOMMIT", - "3DDOPPLER", - "3DGROUPING", - "3DLOCATION", - "3DMACROSCOPIC", - "3DSOURCE", - "AUDIODECODERCAPABILITIES", - "AUDIOENCODER", - "AUDIOENCODERCAPABILITIES", - "AUDIOIODEVICECAPABILITIES", - "BASSBOOST", - "BUFFERQUEUE", - "DEVICEVOLUME", - "DYNAMICINTERFACEMANAGEMENT", - "DYNAMICSOURCE", - "EFFECTSEND", - "ENGINE", - "ENGINECAPABILITIES", - "ENVIRONMENTALREVERB", - "EQUALIZER", - "LED", - "METADATAEXTRACTION", - "METADATATRAVERSAL", - "MIDIMESSAGE", - "MIDIMUTESOLO", - "MIDITEMPO", - "MIDITIME", - "MUTESOLO", - "NULL", - "OBJECT", - "OUTPUTMIX", - "PITCH", - "PLAY", - "PLAYBACKRATE", - "PREFETCHSTATUS", - "PRESETREVERB", - "RATEPITCH", - "RECORD", - "SEEK", - "THREADSYNC", - "VIBRA", - "VIRTUALIZER", - "VISUALIZATION", - "VOLUME", - - // Wilhelm desktop extended interfaces - "OUTPUTMIXEXT", - - // Android API level 9 extended interfaces - "ANDROIDEFFECT", - "ANDROIDEFFECTCAPABILITIES", - "ANDROIDEFFECTSEND", - "ANDROIDCONFIGURATION", - "ANDROIDSIMPLEBUFFERQUEUE", - - // Android API level 12 extended interfaces - "ANDROIDBUFFERQUEUESOURCE", - - // OpenMAX AL 1.0.1 interfaces - "XAAUDIODECODERCAPABILITIES", - "XAAUDIOENCODER", - "XAAUDIOENCODERCAPABILITIES", - "XAAUDIOIODEVICECAPABILITIES", - "XACAMERA", - "XACAMERACAPABILITIES", - "XACONFIGEXTENSION", - "XADEVICEVOLUME", - "XADYNAMICINTERFACEMANAGEMENT", - "XADYNAMICSOURCE", - "XAENGINE", - "XAEQUALIZER", - "XAIMAGECONTROLS", - "XAIMAGEDECODERCAPABILITIES", - "XAIMAGEEFFECTS", - "XAIMAGEENCODER", - "XAIMAGEENCODERCAPABILITIES", - "XALED", - "XAMETADATAEXTRACTION", - "XAMETADATAINSERTION", - "XAMETADATATRAVERSAL", - // "XANULL", - "XAOBJECT", - "XAOUTPUTMIX", - "XAPLAY", - "XAPLAYBACKRATE", - "XAPREFETCHSTATUS", - "XARADIO", - "XARDS", - "XARECORD", - "XASEEK", - "XASNAPSHOT", - "XASTREAMINFORMATION", - "XATHREADSYNC", - "XAVIBRA", - "XAVIDEODECODERCAPABILITIES", - "XAVIDEOENCODER", - "XAVIDEOENCODERCAPABILITIES", - "XAVIDEOPOSTPROCESSING", - "XAVOLUME", - -}; - - -/** Convert an MPH value to an MPH identifier */ - -void MPH_to_MPH_string(unsigned MPH, char buffer[40]) -{ - assert(MPH_MAX > MPH); - const char *infix; - infix = ""; - strcpy(buffer, "MPH"); - strcpy(&buffer[3], infix); - strcat(buffer, "_"); - strcat(buffer, interface_names[MPH]); -} diff --git a/wilhelm/src/itf/I3DCommit.c b/wilhelm/src/itf/I3DCommit.c deleted file mode 100644 index 7ad46012..00000000 --- a/wilhelm/src/itf/I3DCommit.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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. - */ - -/* 3DCommit implementation */ - -#include "sles_allinclusive.h" - - -static SLresult I3DCommit_Commit(SL3DCommitItf self) -{ - SL_ENTER_INTERFACE - - I3DCommit *thiz = (I3DCommit *) self; - IObject *thisObject = InterfaceToIObject(thiz); - object_lock_exclusive(thisObject); - if (thiz->mDeferred) { - SLuint32 myGeneration = thiz->mGeneration; - do { - ++thiz->mWaiting; - object_cond_wait(thisObject); - } while (thiz->mGeneration == myGeneration); - } - object_unlock_exclusive(thisObject); - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DCommit_SetDeferred(SL3DCommitItf self, SLboolean deferred) -{ - SL_ENTER_INTERFACE - - I3DCommit *thiz = (I3DCommit *) self; - IObject *thisObject = InterfaceToIObject(thiz); - object_lock_exclusive(thisObject); - thiz->mDeferred = SL_BOOLEAN_FALSE != deferred; // normalize - object_unlock_exclusive(thisObject); - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static const struct SL3DCommitItf_ I3DCommit_Itf = { - I3DCommit_Commit, - I3DCommit_SetDeferred -}; - -void I3DCommit_init(void *self) -{ - I3DCommit *thiz = (I3DCommit *) self; - thiz->mItf = &I3DCommit_Itf; - thiz->mDeferred = SL_BOOLEAN_FALSE; - thiz->mGeneration = 0; - thiz->mWaiting = 0; -} diff --git a/wilhelm/src/itf/I3DDoppler.c b/wilhelm/src/itf/I3DDoppler.c deleted file mode 100644 index 8a20f81c..00000000 --- a/wilhelm/src/itf/I3DDoppler.c +++ /dev/null @@ -1,161 +0,0 @@ -/* - * 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. - */ - -/* 3DDoppler implementation */ - -#include "sles_allinclusive.h" - - -static SLresult I3DDoppler_SetVelocityCartesian(SL3DDopplerItf self, const SLVec3D *pVelocity) -{ - SL_ENTER_INTERFACE - - if (NULL == pVelocity) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - I3DDoppler *thiz = (I3DDoppler *) self; - SLVec3D velocityCartesian = *pVelocity; - interface_lock_exclusive(thiz); - thiz->mVelocityCartesian = velocityCartesian; - thiz->mVelocityActive = CARTESIAN_SET_SPHERICAL_UNKNOWN; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DDoppler_SetVelocitySpherical(SL3DDopplerItf self, - SLmillidegree azimuth, SLmillidegree elevation, SLmillimeter speed) -{ - SL_ENTER_INTERFACE - - I3DDoppler *thiz = (I3DDoppler *) self; - interface_lock_exclusive(thiz); - thiz->mVelocitySpherical.mAzimuth = azimuth; - thiz->mVelocitySpherical.mElevation = elevation; - thiz->mVelocitySpherical.mSpeed = speed; - thiz->mVelocityActive = CARTESIAN_UNKNOWN_SPHERICAL_SET; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DDoppler_GetVelocityCartesian(SL3DDopplerItf self, SLVec3D *pVelocity) -{ - SL_ENTER_INTERFACE - - if (NULL == pVelocity) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - I3DDoppler *thiz = (I3DDoppler *) self; - interface_lock_exclusive(thiz); - for (;;) { - enum CartesianSphericalActive velocityActive = thiz->mVelocityActive; - switch (velocityActive) { - case CARTESIAN_COMPUTED_SPHERICAL_SET: - case CARTESIAN_SET_SPHERICAL_COMPUTED: // not in 1.0.1 - case CARTESIAN_SET_SPHERICAL_REQUESTED: // not in 1.0.1 - case CARTESIAN_SET_SPHERICAL_UNKNOWN: - { - SLVec3D velocityCartesian = thiz->mVelocityCartesian; - interface_unlock_exclusive(thiz); - *pVelocity = velocityCartesian; - } - break; - case CARTESIAN_UNKNOWN_SPHERICAL_SET: - thiz->mVelocityActive = CARTESIAN_REQUESTED_SPHERICAL_SET; - // fall through - case CARTESIAN_REQUESTED_SPHERICAL_SET: - // matched by cond_broadcast in case multiple requesters -#if 0 - interface_cond_wait(thiz); -#else - thiz->mVelocityActive = CARTESIAN_COMPUTED_SPHERICAL_SET; -#endif - continue; - default: - assert(SL_BOOLEAN_FALSE); - interface_unlock_exclusive(thiz); - pVelocity->x = 0; - pVelocity->y = 0; - pVelocity->z = 0; - break; - } - break; - } - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DDoppler_SetDopplerFactor(SL3DDopplerItf self, SLpermille dopplerFactor) -{ - SL_ENTER_INTERFACE - - I3DDoppler *thiz = (I3DDoppler *) self; - interface_lock_poke(thiz); - thiz->mDopplerFactor = dopplerFactor; - interface_unlock_poke(thiz); - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DDoppler_GetDopplerFactor(SL3DDopplerItf self, SLpermille *pDopplerFactor) -{ - SL_ENTER_INTERFACE - - if (NULL == pDopplerFactor) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - I3DDoppler *thiz = (I3DDoppler *) self; - interface_lock_peek(thiz); - SLpermille dopplerFactor = thiz->mDopplerFactor; - interface_unlock_peek(thiz); - *pDopplerFactor = dopplerFactor; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static const struct SL3DDopplerItf_ I3DDoppler_Itf = { - I3DDoppler_SetVelocityCartesian, - I3DDoppler_SetVelocitySpherical, - I3DDoppler_GetVelocityCartesian, - I3DDoppler_SetDopplerFactor, - I3DDoppler_GetDopplerFactor -}; - -void I3DDoppler_init(void *self) -{ - I3DDoppler *thiz = (I3DDoppler *) self; - thiz->mItf = &I3DDoppler_Itf; - thiz->mVelocityCartesian.x = 0; - thiz->mVelocityCartesian.y = 0; - thiz->mVelocityCartesian.z = 0; - memset(&thiz->mVelocitySpherical, 0x55, sizeof(thiz->mVelocitySpherical)); - thiz->mVelocityActive = CARTESIAN_SET_SPHERICAL_UNKNOWN; - thiz->mDopplerFactor = 1000; -} diff --git a/wilhelm/src/itf/I3DGrouping.c b/wilhelm/src/itf/I3DGrouping.c deleted file mode 100644 index 45172b3b..00000000 --- a/wilhelm/src/itf/I3DGrouping.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - * 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. - */ - -/* 3DGrouping implementation */ - -#include "sles_allinclusive.h" - - -static SLresult I3DGrouping_Set3DGroup(SL3DGroupingItf self, SLObjectItf group) -{ - SL_ENTER_INTERFACE - - // validate input parameters - C3DGroup *newGroup = (C3DGroup *) group; - result = SL_RESULT_SUCCESS; - if (NULL != newGroup) { - // check that new group has the correct object ID and is realized, and acquire a strong - // reference to it. FYI note that a deadlock will occur if application incorrectly - // specifies group as this audio player - result = AcquireStrongRef(&newGroup->mObject, SL_OBJECTID_3DGROUP); - // the new group is left unlocked, but it will be locked again below - } - if (SL_RESULT_SUCCESS == result) { - I3DGrouping *thiz = (I3DGrouping *) self; - IObject *thisObject = InterfaceToIObject(thiz); - unsigned id = thisObject->mInstanceID; - assert(0 != id); // player object must be published by this point - --id; - assert(MAX_INSTANCE > id); - unsigned mask = 1 << id; - interface_lock_exclusive(thiz); - C3DGroup *oldGroup = thiz->mGroup; - if (newGroup != oldGroup) { - // remove this object from the old group's set of objects - if (NULL != oldGroup) { - IObject *oldGroupObject = &oldGroup->mObject; - // note that we already have a strong reference to the old group - object_lock_exclusive(oldGroupObject); - assert(oldGroup->mMemberMask & mask); - oldGroup->mMemberMask &= ~mask; - ReleaseStrongRefAndUnlockExclusive(oldGroupObject); - } - // add this object to the new group's set of objects - if (NULL != newGroup) { - IObject *newGroupObject = &newGroup->mObject; - // we already have a strong reference to the new group, but we need to re-lock it - // so that we always lock objects in the same nesting order to prevent a deadlock - object_lock_exclusive(newGroupObject); - assert(!(newGroup->mMemberMask & mask)); - newGroup->mMemberMask |= mask; - object_unlock_exclusive(newGroupObject); - } - thiz->mGroup = newGroup; - } - interface_unlock_exclusive(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DGrouping_Get3DGroup(SL3DGroupingItf self, SLObjectItf *pGroup) -{ - SL_ENTER_INTERFACE - - if (NULL == pGroup) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - I3DGrouping *thiz = (I3DGrouping *) self; - interface_lock_shared(thiz); - C3DGroup *group = thiz->mGroup; - *pGroup = (NULL != group) ? &group->mObject.mItf : NULL; - interface_unlock_shared(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static const struct SL3DGroupingItf_ I3DGrouping_Itf = { - I3DGrouping_Set3DGroup, - I3DGrouping_Get3DGroup -}; - -void I3DGrouping_init(void *self) -{ - I3DGrouping *thiz = (I3DGrouping *) self; - thiz->mItf = &I3DGrouping_Itf; - thiz->mGroup = NULL; -} - -void I3DGrouping_deinit(void *self) -{ - I3DGrouping *thiz = (I3DGrouping *) self; - C3DGroup *group = thiz->mGroup; - if (NULL != group) { - unsigned mask = 1 << (InterfaceToIObject(thiz)->mInstanceID - 1); - IObject *groupObject = &group->mObject; - object_lock_exclusive(groupObject); - assert(group->mMemberMask & mask); - group->mMemberMask &= ~mask; - ReleaseStrongRefAndUnlockExclusive(groupObject); - } -} diff --git a/wilhelm/src/itf/I3DLocation.c b/wilhelm/src/itf/I3DLocation.c deleted file mode 100644 index c0eff3b4..00000000 --- a/wilhelm/src/itf/I3DLocation.c +++ /dev/null @@ -1,293 +0,0 @@ -/* - * 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. - */ - -/* 3DLocation implementation */ - -#include "sles_allinclusive.h" - - -static SLresult I3DLocation_SetLocationCartesian(SL3DLocationItf self, const SLVec3D *pLocation) -{ - SL_ENTER_INTERFACE - - if (NULL == pLocation) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - I3DLocation *thiz = (I3DLocation *) self; - SLVec3D locationCartesian = *pLocation; - interface_lock_exclusive(thiz); - thiz->mLocationCartesian = locationCartesian; - thiz->mLocationActive = CARTESIAN_SET_SPHERICAL_UNKNOWN; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DLocation_SetLocationSpherical(SL3DLocationItf self, - SLmillidegree azimuth, SLmillidegree elevation, SLmillimeter distance) -{ - SL_ENTER_INTERFACE - - if (!((-360000 <= azimuth) && (azimuth <= 360000) && - (-90000 <= elevation) && (elevation <= 90000) && - (0 <= distance) && (distance <= SL_MILLIMETER_MAX))) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - I3DLocation *thiz = (I3DLocation *) self; - interface_lock_exclusive(thiz); - thiz->mLocationSpherical.mAzimuth = azimuth; - thiz->mLocationSpherical.mElevation = elevation; - thiz->mLocationSpherical.mDistance = distance; - thiz->mLocationActive = CARTESIAN_UNKNOWN_SPHERICAL_SET; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DLocation_Move(SL3DLocationItf self, const SLVec3D *pMovement) -{ - SL_ENTER_INTERFACE - - if (NULL == pMovement) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - I3DLocation *thiz = (I3DLocation *) self; - SLVec3D movementCartesian = *pMovement; - interface_lock_exclusive(thiz); - for (;;) { - enum CartesianSphericalActive locationActive = thiz->mLocationActive; - switch (locationActive) { - case CARTESIAN_COMPUTED_SPHERICAL_SET: - case CARTESIAN_SET_SPHERICAL_COMPUTED: // not in 1.0.1 - case CARTESIAN_SET_SPHERICAL_REQUESTED: // not in 1.0.1 - case CARTESIAN_SET_SPHERICAL_UNKNOWN: - thiz->mLocationCartesian.x += movementCartesian.x; - thiz->mLocationCartesian.y += movementCartesian.y; - thiz->mLocationCartesian.z += movementCartesian.z; - thiz->mLocationActive = CARTESIAN_SET_SPHERICAL_UNKNOWN; - break; - case CARTESIAN_UNKNOWN_SPHERICAL_SET: - thiz->mLocationActive = CARTESIAN_REQUESTED_SPHERICAL_SET; - // fall through - case CARTESIAN_REQUESTED_SPHERICAL_SET: - // matched by cond_broadcast in case multiple requesters -#if 0 - interface_cond_wait(thiz); -#else - thiz->mLocationActive = CARTESIAN_COMPUTED_SPHERICAL_SET; -#endif - continue; - default: - assert(SL_BOOLEAN_FALSE); - break; - } - break; - } - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DLocation_GetLocationCartesian(SL3DLocationItf self, SLVec3D *pLocation) -{ - SL_ENTER_INTERFACE - - if (NULL == pLocation) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - I3DLocation *thiz = (I3DLocation *) self; - interface_lock_exclusive(thiz); - for (;;) { - enum CartesianSphericalActive locationActive = thiz->mLocationActive; - switch (locationActive) { - case CARTESIAN_COMPUTED_SPHERICAL_SET: - case CARTESIAN_SET_SPHERICAL_COMPUTED: // not in 1.0.1 - case CARTESIAN_SET_SPHERICAL_REQUESTED: // not in 1.0.1 - case CARTESIAN_SET_SPHERICAL_UNKNOWN: - { - SLVec3D locationCartesian = thiz->mLocationCartesian; - interface_unlock_exclusive(thiz); - *pLocation = locationCartesian; - } - break; - case CARTESIAN_UNKNOWN_SPHERICAL_SET: - thiz->mLocationActive = CARTESIAN_REQUESTED_SPHERICAL_SET; - // fall through - case CARTESIAN_REQUESTED_SPHERICAL_SET: - // matched by cond_broadcast in case multiple requesters -#if 0 - interface_cond_wait(thiz); -#else - thiz->mLocationActive = CARTESIAN_COMPUTED_SPHERICAL_SET; -#endif - continue; - default: - assert(SL_BOOLEAN_FALSE); - interface_unlock_exclusive(thiz); - pLocation->x = 0; - pLocation->y = 0; - pLocation->z = 0; - break; - } - break; - } - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DLocation_SetOrientationVectors(SL3DLocationItf self, - const SLVec3D *pFront, const SLVec3D *pAbove) -{ - SL_ENTER_INTERFACE - - if (NULL == pFront || NULL == pAbove) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - SLVec3D front = *pFront; - SLVec3D above = *pAbove; - // NTH Check for vectors close to zero or close to parallel - I3DLocation *thiz = (I3DLocation *) self; - interface_lock_exclusive(thiz); - thiz->mOrientationVectors.mFront = front; - thiz->mOrientationVectors.mAbove = above; - thiz->mOrientationActive = ANGLES_UNKNOWN_VECTORS_SET; - thiz->mRotatePending = SL_BOOLEAN_FALSE; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DLocation_SetOrientationAngles(SL3DLocationItf self, - SLmillidegree heading, SLmillidegree pitch, SLmillidegree roll) -{ - SL_ENTER_INTERFACE - - if (!((-360000 <= heading) && (heading <= 360000) && - (-90000 <= pitch) && (pitch <= 90000) && - (-360000 <= roll) && (roll <= 360000))) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - I3DLocation *thiz = (I3DLocation *) self; - interface_lock_exclusive(thiz); - thiz->mOrientationAngles.mHeading = heading; - thiz->mOrientationAngles.mPitch = pitch; - thiz->mOrientationAngles.mRoll = roll; - thiz->mOrientationActive = ANGLES_SET_VECTORS_UNKNOWN; - thiz->mRotatePending = SL_BOOLEAN_FALSE; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DLocation_Rotate(SL3DLocationItf self, SLmillidegree theta, const SLVec3D *pAxis) -{ - SL_ENTER_INTERFACE - - if (!((-360000 <= theta) && (theta <= 360000)) || (NULL == pAxis)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - SLVec3D axis = *pAxis; - // NTH Check that axis is not (close to) zero vector, length does not matter - I3DLocation *thiz = (I3DLocation *) self; - interface_lock_exclusive(thiz); - while (thiz->mRotatePending) -#if 0 - interface_cond_wait(thiz); -#else - break; -#endif - thiz->mTheta = theta; - thiz->mAxis = axis; - thiz->mRotatePending = SL_BOOLEAN_TRUE; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DLocation_GetOrientationVectors(SL3DLocationItf self, - SLVec3D *pFront, SLVec3D *pUp) -{ - SL_ENTER_INTERFACE - - if (NULL == pFront || NULL == pUp) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - I3DLocation *thiz = (I3DLocation *) self; - interface_lock_shared(thiz); - SLVec3D front = thiz->mOrientationVectors.mFront; - SLVec3D up = thiz->mOrientationVectors.mUp; - interface_unlock_shared(thiz); - *pFront = front; - *pUp = up; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static const struct SL3DLocationItf_ I3DLocation_Itf = { - I3DLocation_SetLocationCartesian, - I3DLocation_SetLocationSpherical, - I3DLocation_Move, - I3DLocation_GetLocationCartesian, - I3DLocation_SetOrientationVectors, - I3DLocation_SetOrientationAngles, - I3DLocation_Rotate, - I3DLocation_GetOrientationVectors -}; - -void I3DLocation_init(void *self) -{ - I3DLocation *thiz = (I3DLocation *) self; - thiz->mItf = &I3DLocation_Itf; - thiz->mLocationCartesian.x = 0; - thiz->mLocationCartesian.y = 0; - thiz->mLocationCartesian.z = 0; - memset(&thiz->mLocationSpherical, 0x55, sizeof(thiz->mLocationSpherical)); - thiz->mLocationActive = CARTESIAN_SET_SPHERICAL_UNKNOWN; - thiz->mOrientationAngles.mHeading = 0; - thiz->mOrientationAngles.mPitch = 0; - thiz->mOrientationAngles.mRoll = 0; - memset(&thiz->mOrientationVectors, 0x55, sizeof(thiz->mOrientationVectors)); - thiz->mOrientationActive = ANGLES_SET_VECTORS_UNKNOWN; - thiz->mTheta = 0x55555555; - thiz->mAxis.x = 0x55555555; - thiz->mAxis.y = 0x55555555; - thiz->mAxis.z = 0x55555555; - thiz->mRotatePending = SL_BOOLEAN_FALSE; -} diff --git a/wilhelm/src/itf/I3DMacroscopic.c b/wilhelm/src/itf/I3DMacroscopic.c deleted file mode 100644 index feb91e26..00000000 --- a/wilhelm/src/itf/I3DMacroscopic.c +++ /dev/null @@ -1,237 +0,0 @@ -/* - * 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. - */ - -/* 3DMacroscopic implementation */ - -#include "sles_allinclusive.h" - - -static SLresult I3DMacroscopic_SetSize(SL3DMacroscopicItf self, - SLmillimeter width, SLmillimeter height, SLmillimeter depth) -{ - SL_ENTER_INTERFACE - - if (!((0 <= width) && (width <= SL_MILLIMETER_MAX) && - (0 <= height) && (height <= SL_MILLIMETER_MAX) && - (0 <= depth) && (depth <= SL_MILLIMETER_MAX))) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - I3DMacroscopic *thiz = (I3DMacroscopic *) self; - interface_lock_exclusive(thiz); - thiz->mSize.mWidth = width; - thiz->mSize.mHeight = height; - thiz->mSize.mDepth = depth; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DMacroscopic_GetSize(SL3DMacroscopicItf self, - SLmillimeter *pWidth, SLmillimeter *pHeight, SLmillimeter *pDepth) -{ - SL_ENTER_INTERFACE - - if (NULL == pWidth || NULL == pHeight || NULL == pDepth) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - I3DMacroscopic *thiz = (I3DMacroscopic *) self; - interface_lock_shared(thiz); - SLmillimeter width = thiz->mSize.mWidth; - SLmillimeter height = thiz->mSize.mHeight; - SLmillimeter depth = thiz->mSize.mDepth; - interface_unlock_shared(thiz); - *pWidth = width; - *pHeight = height; - *pDepth = depth; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DMacroscopic_SetOrientationAngles(SL3DMacroscopicItf self, - SLmillidegree heading, SLmillidegree pitch, SLmillidegree roll) -{ - SL_ENTER_INTERFACE - - if (!((-360000 <= heading) && (heading <= 360000) && - (-90000 <= pitch) && (pitch <= 90000) && - (-360000 <= roll) && (roll <= 360000))) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - I3DMacroscopic *thiz = (I3DMacroscopic *) self; - interface_lock_exclusive(thiz); - thiz->mOrientationAngles.mHeading = heading; - thiz->mOrientationAngles.mPitch = pitch; - thiz->mOrientationAngles.mRoll = roll; - thiz->mOrientationActive = ANGLES_SET_VECTORS_UNKNOWN; - thiz->mRotatePending = SL_BOOLEAN_FALSE; - // ++thiz->mGeneration; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DMacroscopic_SetOrientationVectors(SL3DMacroscopicItf self, - const SLVec3D *pFront, const SLVec3D *pAbove) -{ - SL_ENTER_INTERFACE - - if (NULL == pFront || NULL == pAbove) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - I3DMacroscopic *thiz = (I3DMacroscopic *) self; - SLVec3D front = *pFront; - SLVec3D above = *pAbove; - // NTH Check for vectors close to zero or close to parallel - interface_lock_exclusive(thiz); - thiz->mOrientationVectors.mFront = front; - thiz->mOrientationVectors.mAbove = above; - thiz->mOrientationVectors.mUp = above; // wrong - thiz->mOrientationActive = ANGLES_UNKNOWN_VECTORS_SET; - thiz->mRotatePending = SL_BOOLEAN_FALSE; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DMacroscopic_Rotate(SL3DMacroscopicItf self, - SLmillidegree theta, const SLVec3D *pAxis) -{ - SL_ENTER_INTERFACE - - if (!((-360000 <= theta) && (theta <= 360000)) || NULL == pAxis) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - SLVec3D axis = *pAxis; - // NTH Check that axis is not (close to) zero vector, length does not matter - I3DMacroscopic *thiz = (I3DMacroscopic *) self; - interface_lock_exclusive(thiz); - while (thiz->mRotatePending) - interface_cond_wait(thiz); - thiz->mTheta = theta; - thiz->mAxis = axis; - thiz->mRotatePending = SL_BOOLEAN_TRUE; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DMacroscopic_GetOrientationVectors(SL3DMacroscopicItf self, - SLVec3D *pFront, SLVec3D *pUp) -{ - SL_ENTER_INTERFACE - - if (NULL == pFront || NULL == pUp) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - I3DMacroscopic *thiz = (I3DMacroscopic *) self; - interface_lock_exclusive(thiz); - for (;;) { - enum AnglesVectorsActive orientationActive = thiz->mOrientationActive; - switch (orientationActive) { - case ANGLES_COMPUTED_VECTORS_SET: // not in 1.0.1 - case ANGLES_REQUESTED_VECTORS_SET: // not in 1.0.1 - case ANGLES_UNKNOWN_VECTORS_SET: - case ANGLES_SET_VECTORS_COMPUTED: - { - SLVec3D front = thiz->mOrientationVectors.mFront; - SLVec3D up = thiz->mOrientationVectors.mUp; - interface_unlock_exclusive(thiz); - *pFront = front; - *pUp = up; - } - break; - case ANGLES_SET_VECTORS_UNKNOWN: - thiz->mOrientationActive = ANGLES_SET_VECTORS_REQUESTED; - // fall through - case ANGLES_SET_VECTORS_REQUESTED: - // matched by cond_broadcast in case multiple requesters -#if 0 - interface_cond_wait(thiz); -#else - thiz->mOrientationActive = ANGLES_SET_VECTORS_COMPUTED; -#endif - continue; - default: - interface_unlock_exclusive(thiz); - assert(SL_BOOLEAN_FALSE); - pFront->x = 0; - pFront->y = 0; - pFront->z = 0; - pUp->x = 0; - pUp->y = 0; - pUp->z = 0; - break; - } - break; - } - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static const struct SL3DMacroscopicItf_ I3DMacroscopic_Itf = { - I3DMacroscopic_SetSize, - I3DMacroscopic_GetSize, - I3DMacroscopic_SetOrientationAngles, - I3DMacroscopic_SetOrientationVectors, - I3DMacroscopic_Rotate, - I3DMacroscopic_GetOrientationVectors -}; - -void I3DMacroscopic_init(void *self) -{ - I3DMacroscopic *thiz = (I3DMacroscopic *) self; - thiz->mItf = &I3DMacroscopic_Itf; - thiz->mSize.mWidth = 0; - thiz->mSize.mHeight = 0; - thiz->mSize.mDepth = 0; - thiz->mOrientationAngles.mHeading = 0; - thiz->mOrientationAngles.mPitch = 0; - thiz->mOrientationAngles.mRoll = 0; - memset(&thiz->mOrientationVectors, 0x55, sizeof(thiz->mOrientationVectors)); - thiz->mOrientationVectors.mFront.x = 0; - thiz->mOrientationVectors.mFront.y = 0; - thiz->mOrientationVectors.mFront.z = -1000; - thiz->mOrientationVectors.mUp.x = 0; - thiz->mOrientationVectors.mUp.y = 1000; - thiz->mOrientationVectors.mUp.z = 0; - thiz->mOrientationVectors.mAbove.x = 0; - thiz->mOrientationVectors.mAbove.y = 0; - thiz->mOrientationVectors.mAbove.z = 0; - thiz->mOrientationActive = ANGLES_SET_VECTORS_COMPUTED; - thiz->mTheta = 0x55555555; - thiz->mAxis.x = 0x55555555; - thiz->mAxis.y = 0x55555555; - thiz->mAxis.z = 0x55555555; - thiz->mRotatePending = SL_BOOLEAN_FALSE; -} diff --git a/wilhelm/src/itf/I3DSource.c b/wilhelm/src/itf/I3DSource.c deleted file mode 100644 index fdc7d36c..00000000 --- a/wilhelm/src/itf/I3DSource.c +++ /dev/null @@ -1,313 +0,0 @@ -/* - * 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. - */ - -/* 3DSource implementation */ - -#include "sles_allinclusive.h" - - -static SLresult I3DSource_SetHeadRelative(SL3DSourceItf self, SLboolean headRelative) -{ - SL_ENTER_INTERFACE - - I3DSource *thiz = (I3DSource *) self; - interface_lock_poke(thiz); - thiz->mHeadRelative = SL_BOOLEAN_FALSE != headRelative; // normalize - interface_unlock_poke(thiz); - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DSource_GetHeadRelative(SL3DSourceItf self, SLboolean *pHeadRelative) -{ - SL_ENTER_INTERFACE - - if (NULL == pHeadRelative) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - I3DSource *thiz = (I3DSource *) self; - interface_lock_peek(thiz); - SLboolean headRelative = thiz->mHeadRelative; - interface_unlock_peek(thiz); - *pHeadRelative = headRelative; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DSource_SetRolloffDistances(SL3DSourceItf self, - SLmillimeter minDistance, SLmillimeter maxDistance) -{ - SL_ENTER_INTERFACE - - if (!((0 < minDistance) && (minDistance <= SL_MILLIMETER_MAX) && - (minDistance <= maxDistance) && (maxDistance <= SL_MILLIMETER_MAX))) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - I3DSource *thiz = (I3DSource *) self; - interface_lock_exclusive(thiz); - thiz->mMinDistance = minDistance; - thiz->mMaxDistance = maxDistance; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DSource_GetRolloffDistances(SL3DSourceItf self, - SLmillimeter *pMinDistance, SLmillimeter *pMaxDistance) -{ - SL_ENTER_INTERFACE - - if (NULL == pMinDistance || NULL == pMaxDistance) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - I3DSource *thiz = (I3DSource *) self; interface_lock_shared(thiz); - SLmillimeter minDistance = thiz->mMinDistance; - SLmillimeter maxDistance = thiz->mMaxDistance; - interface_unlock_shared(thiz); - *pMinDistance = minDistance; - *pMaxDistance = maxDistance; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DSource_SetRolloffMaxDistanceMute(SL3DSourceItf self, SLboolean mute) -{ - SL_ENTER_INTERFACE - - I3DSource *thiz = (I3DSource *) self; - interface_lock_poke(thiz); - thiz->mRolloffMaxDistanceMute = SL_BOOLEAN_FALSE != mute; // normalize - interface_unlock_poke(thiz); - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DSource_GetRolloffMaxDistanceMute(SL3DSourceItf self, SLboolean *pMute) -{ - SL_ENTER_INTERFACE - - if (NULL == pMute) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - I3DSource *thiz = (I3DSource *) self; - interface_lock_peek(thiz); - SLboolean mute = thiz->mRolloffMaxDistanceMute; - interface_unlock_peek(thiz); - *pMute = mute; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DSource_SetRolloffFactor(SL3DSourceItf self, SLpermille rolloffFactor) -{ - SL_ENTER_INTERFACE - - if (!((0 <= rolloffFactor) && (rolloffFactor <= 10000))) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - I3DSource *thiz = (I3DSource *) self; - interface_lock_poke(thiz); - thiz->mRolloffFactor = rolloffFactor; - interface_unlock_poke(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DSource_GetRolloffFactor(SL3DSourceItf self, SLpermille *pRolloffFactor) -{ - SL_ENTER_INTERFACE - - I3DSource *thiz = (I3DSource *) self; - interface_lock_peek(thiz); - SLpermille rolloffFactor = thiz->mRolloffFactor; - interface_unlock_peek(thiz); - *pRolloffFactor = rolloffFactor; - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DSource_SetRoomRolloffFactor(SL3DSourceItf self, SLpermille roomRolloffFactor) -{ - SL_ENTER_INTERFACE - - if (!((0 <= roomRolloffFactor) && (roomRolloffFactor <= 10000))) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - I3DSource *thiz = (I3DSource *) self; - interface_lock_poke(thiz); - thiz->mRoomRolloffFactor = roomRolloffFactor; - interface_unlock_poke(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DSource_GetRoomRolloffFactor(SL3DSourceItf self, SLpermille *pRoomRolloffFactor) -{ - SL_ENTER_INTERFACE - - I3DSource *thiz = (I3DSource *) self; - interface_lock_peek(thiz); - SLpermille roomRolloffFactor = thiz->mRoomRolloffFactor; - interface_unlock_peek(thiz); - *pRoomRolloffFactor = roomRolloffFactor; - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DSource_SetRolloffModel(SL3DSourceItf self, SLuint8 model) -{ - SL_ENTER_INTERFACE - - switch (model) { - case SL_ROLLOFFMODEL_LINEAR: - case SL_ROLLOFFMODEL_EXPONENTIAL: - { - I3DSource *thiz = (I3DSource *) self; - interface_lock_poke(thiz); - thiz->mDistanceModel = model; - interface_unlock_poke(thiz); - result = SL_RESULT_SUCCESS; - } - break; - default: - result = SL_RESULT_PARAMETER_INVALID; - break; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DSource_GetRolloffModel(SL3DSourceItf self, SLuint8 *pModel) -{ - SL_ENTER_INTERFACE - - I3DSource *thiz = (I3DSource *) self; - interface_lock_peek(thiz); - SLuint8 model = thiz->mDistanceModel; - interface_unlock_peek(thiz); - *pModel = model; - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DSource_SetCone(SL3DSourceItf self, SLmillidegree innerAngle, - SLmillidegree outerAngle, SLmillibel outerLevel) -{ - SL_ENTER_INTERFACE - - if (!((0 <= innerAngle) && (innerAngle <= 360000) && - (0 <= outerAngle) && (outerAngle <= 360000) && - (SL_MILLIBEL_MIN <= outerLevel) && (outerLevel <= 0))) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - I3DSource *thiz = (I3DSource *) self; - interface_lock_exclusive(thiz); - thiz->mConeInnerAngle = innerAngle; - thiz->mConeOuterAngle = outerAngle; - thiz->mConeOuterLevel = outerLevel; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult I3DSource_GetCone(SL3DSourceItf self, SLmillidegree *pInnerAngle, - SLmillidegree *pOuterAngle, SLmillibel *pOuterLevel) -{ - SL_ENTER_INTERFACE - - if (NULL == pInnerAngle || NULL == pOuterAngle || NULL == pOuterLevel) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - I3DSource *thiz = (I3DSource *) self; - interface_lock_shared(thiz); - SLmillidegree innerAngle = thiz->mConeInnerAngle; - SLmillidegree outerAngle = thiz->mConeOuterAngle; - SLmillibel outerLevel = thiz->mConeOuterLevel; - interface_unlock_shared(thiz); - *pInnerAngle = innerAngle; - *pOuterAngle = outerAngle; - *pOuterLevel = outerLevel; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static const struct SL3DSourceItf_ I3DSource_Itf = { - I3DSource_SetHeadRelative, - I3DSource_GetHeadRelative, - I3DSource_SetRolloffDistances, - I3DSource_GetRolloffDistances, - I3DSource_SetRolloffMaxDistanceMute, - I3DSource_GetRolloffMaxDistanceMute, - I3DSource_SetRolloffFactor, - I3DSource_GetRolloffFactor, - I3DSource_SetRoomRolloffFactor, - I3DSource_GetRoomRolloffFactor, - I3DSource_SetRolloffModel, - I3DSource_GetRolloffModel, - I3DSource_SetCone, - I3DSource_GetCone -}; - -void I3DSource_init(void *self) -{ - I3DSource *thiz = (I3DSource *) self; - thiz->mItf = &I3DSource_Itf; - thiz->mHeadRelative = SL_BOOLEAN_FALSE; - thiz->mRolloffMaxDistanceMute = SL_BOOLEAN_FALSE; - thiz->mMaxDistance = SL_MILLIMETER_MAX; - thiz->mMinDistance = 1000; - thiz->mConeInnerAngle = 360000; - thiz->mConeOuterAngle = 360000; - thiz->mConeOuterLevel = 0; - thiz->mRolloffFactor = 1000; - thiz->mRoomRolloffFactor = 0; - thiz->mDistanceModel = SL_ROLLOFFMODEL_EXPONENTIAL; -} diff --git a/wilhelm/src/itf/IAndroidBufferQueue.c b/wilhelm/src/itf/IAndroidBufferQueue.c deleted file mode 100644 index 289fbc42..00000000 --- a/wilhelm/src/itf/IAndroidBufferQueue.c +++ /dev/null @@ -1,591 +0,0 @@ -/* - * 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. - */ - -/* AndroidBufferQueue implementation */ - -//#define USE_LOG SLAndroidLogLevel_Verbose - -#include "sles_allinclusive.h" -// for AAC ADTS verification on enqueue: -#include "android/include/AacBqToPcmCbRenderer.h" - -/** - * Determine the state of the audio player or media player associated with a buffer queue. - * Note that PLAYSTATE and RECORDSTATE values are equivalent (where PLAYING == RECORDING). - */ - -static SLuint32 getAssociatedState(IAndroidBufferQueue *thiz) -{ - SLuint32 state; - switch (InterfaceToObjectID(thiz)) { - case XA_OBJECTID_MEDIAPLAYER: - state = ((CMediaPlayer *) thiz->mThis)->mPlay.mState; - break; - case SL_OBJECTID_AUDIOPLAYER: - state = ((CAudioPlayer *) thiz->mThis)->mPlay.mState; - break; - default: - // unreachable, but just in case we will assume it is stopped - assert(SL_BOOLEAN_FALSE); - state = SL_PLAYSTATE_STOPPED; - break; - } - return state; -} - - -/** - * parse and set the items associated with the given buffer, based on the buffer type, - * which determines the set of authorized items and format - */ -static SLresult setItems(SLuint32 dataLength, - const SLAndroidBufferItem *pItems, SLuint32 itemsLength, - SLuint16 bufferType, AdvancedBufferHeader *pBuff, bool *pEOS) -{ - // reset item structure based on type - switch (bufferType) { - case kAndroidBufferTypeMpeg2Ts: - pBuff->mItems.mTsCmdData.mTsCmdCode = ANDROID_MP2TSEVENT_NONE; - pBuff->mItems.mTsCmdData.mPts = 0; - break; - case kAndroidBufferTypeAacadts: - pBuff->mItems.mAdtsCmdData.mAdtsCmdCode = ANDROID_ADTSEVENT_NONE; - break; - case kAndroidBufferTypeInvalid: - default: - // shouldn't happen, but just in case clear out the item structure - memset(&pBuff->mItems, 0, sizeof(AdvancedBufferItems)); - return SL_RESULT_INTERNAL_ERROR; - } - - // process all items in the array; if no items then we break out of loop immediately - while (itemsLength > 0) { - - // remaining length must be large enough for one full item without any associated data - if (itemsLength < sizeof(SLAndroidBufferItem)) { - SL_LOGE("Partial item at end of array"); - return SL_RESULT_PARAMETER_INVALID; - } - itemsLength -= sizeof(SLAndroidBufferItem); - - // remaining length must be large enough for data with current item and alignment padding - SLuint32 itemDataSizeWithAlignmentPadding = (pItems->itemSize + 3) & ~3; - if (itemsLength < itemDataSizeWithAlignmentPadding) { - SL_LOGE("Partial item data at end of array"); - return SL_RESULT_PARAMETER_INVALID; - } - itemsLength -= itemDataSizeWithAlignmentPadding; - - // parse item data based on type - switch (bufferType) { - - case kAndroidBufferTypeMpeg2Ts: { - switch (pItems->itemKey) { - - case SL_ANDROID_ITEMKEY_EOS: - pBuff->mItems.mTsCmdData.mTsCmdCode |= ANDROID_MP2TSEVENT_EOS; - //SL_LOGD("Found EOS event=%d", pBuff->mItems.mTsCmdData.mTsCmdCode); - if (pItems->itemSize != 0) { - SL_LOGE("Invalid item parameter size %u for EOS", pItems->itemSize); - return SL_RESULT_PARAMETER_INVALID; - } - break; - - case SL_ANDROID_ITEMKEY_DISCONTINUITY: - if (pItems->itemSize == 0) { - pBuff->mItems.mTsCmdData.mTsCmdCode |= ANDROID_MP2TSEVENT_DISCONTINUITY; - //SL_LOGD("Found DISCONTINUITYevent=%d", pBuff->mItems.mTsCmdData.mTsCmdCode); - } else if (pItems->itemSize == sizeof(SLAuint64)) { - pBuff->mItems.mTsCmdData.mTsCmdCode |= ANDROID_MP2TSEVENT_DISCON_NEWPTS; - pBuff->mItems.mTsCmdData.mPts = *((SLAuint64*)pItems->itemData); - //SL_LOGD("Found PTS=%lld", pBuff->mItems.mTsCmdData.mPts); - } else { - SL_LOGE("Invalid item parameter size %u for MPEG-2 PTS", pItems->itemSize); - return SL_RESULT_PARAMETER_INVALID; - } - break; - - case SL_ANDROID_ITEMKEY_FORMAT_CHANGE: - // distinguish between a "full" format change and one where it says what changed - if (pItems->itemSize == 0) { - SL_LOGV("Received format change with no data == full format change"); - pBuff->mItems.mTsCmdData.mTsCmdCode |= ANDROID_MP2TSEVENT_FORMAT_CHANGE_FULL; - } else if (pItems->itemSize == sizeof(SLuint32)) { - XAuint32 formatData = *((XAuint32*)pItems->itemData); - // intentionally only supporting video change when reading which specific - // stream has changed, interpret other changes as full change - if (formatData == XA_ANDROID_FORMATCHANGE_ITEMDATA_VIDEO) { - pBuff->mItems.mTsCmdData.mTsCmdCode |= - ANDROID_MP2TSEVENT_FORMAT_CHANGE_VIDEO; - SL_LOGV("Received video format change"); - } else { - // note that we don't support specifying - // ANDROID_MP2TSEVENT_FORMAT_CHANGE_FULL by having all bits of - // the data mask set, we default to it with unsupported masks - SL_LOGE("Received format change with unsupported data, ignoring data"); - pBuff->mItems.mTsCmdData.mTsCmdCode |= - ANDROID_MP2TSEVENT_FORMAT_CHANGE_FULL; - } - } else { - SL_LOGE("Received format change with invalid data size, ignoring data"); - pBuff->mItems.mTsCmdData.mTsCmdCode |= ANDROID_MP2TSEVENT_FORMAT_CHANGE_FULL; - } - break; - - default: - // unknown item key - SL_LOGE("Unknown item key %u with size %u", pItems->itemKey, pItems->itemSize); - return SL_RESULT_PARAMETER_INVALID; - - }// switch (pItems->itemKey) - } break; - - case kAndroidBufferTypeAacadts: { - switch (pItems->itemKey) { - - case SL_ANDROID_ITEMKEY_EOS: - pBuff->mItems.mAdtsCmdData.mAdtsCmdCode |= ANDROID_ADTSEVENT_EOS; - if (pItems->itemSize != 0) { - SL_LOGE("Invalid item parameter size %u for EOS", pItems->itemSize); - return SL_RESULT_PARAMETER_INVALID; - } - break; - - default: - // unknown item key - SL_LOGE("Unknown item key %u with size %u", pItems->itemKey, pItems->itemSize); - return SL_RESULT_PARAMETER_INVALID; - - }// switch (pItems->itemKey) - } break; - - case kAndroidBufferTypeInvalid: - default: - // not reachable as we checked this earlier - return SL_RESULT_INTERNAL_ERROR; - - }// switch (bufferType) - - // skip past this item, including data with alignment padding - pItems = (SLAndroidBufferItem *) ((char *) pItems + - sizeof(SLAndroidBufferItem) + itemDataSizeWithAlignmentPadding); - } - - // now check for invalid combinations of items - switch (bufferType) { - - case kAndroidBufferTypeMpeg2Ts: { - // supported Mpeg2Ts commands are mutually exclusive - switch (pBuff->mItems.mTsCmdData.mTsCmdCode) { - // single items are allowed - case ANDROID_MP2TSEVENT_EOS: - if (dataLength > 0) { - SL_LOGE("Can't enqueue non-zero data with EOS"); - return SL_RESULT_PRECONDITIONS_VIOLATED; - } - *pEOS = true; - break; - case ANDROID_MP2TSEVENT_NONE: - case ANDROID_MP2TSEVENT_DISCONTINUITY: - case ANDROID_MP2TSEVENT_DISCON_NEWPTS: - case ANDROID_MP2TSEVENT_FORMAT_CHANGE_FULL: - case ANDROID_MP2TSEVENT_FORMAT_CHANGE_VIDEO: - break; - // no combinations are allowed - default: - SL_LOGE("Invalid combination of items"); - return SL_RESULT_PARAMETER_INVALID; - } - } break; - - case kAndroidBufferTypeAacadts: { - // only one item supported, and thus no combination check needed - if (pBuff->mItems.mAdtsCmdData.mAdtsCmdCode == ANDROID_ADTSEVENT_EOS) { - if (dataLength > 0) { - SL_LOGE("Can't enqueue non-zero data with EOS"); - return SL_RESULT_PRECONDITIONS_VIOLATED; - } - *pEOS = true; - } - } break; - - case kAndroidBufferTypeInvalid: - default: - // not reachable as we checked this earlier - return SL_RESULT_INTERNAL_ERROR; - } - - return SL_RESULT_SUCCESS; -} - - -static SLresult IAndroidBufferQueue_RegisterCallback(SLAndroidBufferQueueItf self, - slAndroidBufferQueueCallback callback, void *pContext) -{ - SL_ENTER_INTERFACE - - IAndroidBufferQueue *thiz = (IAndroidBufferQueue *) self; - - interface_lock_exclusive(thiz); - - // verify pre-condition that media object is in the SL_PLAYSTATE_STOPPED state - if (SL_PLAYSTATE_STOPPED == getAssociatedState(thiz)) { - thiz->mCallback = callback; - thiz->mContext = pContext; - result = SL_RESULT_SUCCESS; - - } else { - result = SL_RESULT_PRECONDITIONS_VIOLATED; - } - - interface_unlock_exclusive(thiz); - - SL_LEAVE_INTERFACE -} - - -static SLresult IAndroidBufferQueue_Clear(SLAndroidBufferQueueItf self) -{ - SL_ENTER_INTERFACE - result = SL_RESULT_SUCCESS; - - IAndroidBufferQueue *thiz = (IAndroidBufferQueue *) self; - - interface_lock_exclusive(thiz); - - // reset the queue pointers - thiz->mFront = &thiz->mBufferArray[0]; - thiz->mRear = &thiz->mBufferArray[0]; - // reset the queue state - thiz->mState.count = 0; - thiz->mState.index = 0; - - // object-specific behavior for a clear - switch (InterfaceToObjectID(thiz)) { - case SL_OBJECTID_AUDIOPLAYER: - android_audioPlayer_androidBufferQueue_clear_l((CAudioPlayer*) thiz->mThis); - break; - case XA_OBJECTID_MEDIAPLAYER: - android_Player_androidBufferQueue_clear_l((CMediaPlayer*) thiz->mThis); - break; - default: - result = SL_RESULT_PARAMETER_INVALID; - } - - interface_unlock_exclusive(thiz); - - SL_LEAVE_INTERFACE -} - - -static SLresult IAndroidBufferQueue_Enqueue(SLAndroidBufferQueueItf self, - void *pBufferContext, - void *pData, - SLuint32 dataLength, - const SLAndroidBufferItem *pItems, - SLuint32 itemsLength) -{ - SL_ENTER_INTERFACE - SL_LOGD("IAndroidBufferQueue_Enqueue pData=%p dataLength=%d", pData, dataLength); - - if ((dataLength > 0) && (NULL == pData)) { - SL_LOGE("Enqueue failure: non-zero data length %u but NULL data pointer", dataLength); - result = SL_RESULT_PARAMETER_INVALID; - } else if ((itemsLength > 0) && (NULL == pItems)) { - SL_LOGE("Enqueue failure: non-zero items length %u but NULL items pointer", itemsLength); - result = SL_RESULT_PARAMETER_INVALID; - } else if ((0 == dataLength) && (0 == itemsLength)) { - // no data and no msg - SL_LOGE("Enqueue failure: trying to enqueue buffer with no data and no items."); - result = SL_RESULT_PARAMETER_INVALID; - // Note that a non-NULL data pointer with zero data length is allowed. - // We track that data pointer as it moves through the queue - // to assist the application in accounting for data buffers. - // A non-NULL items pointer with zero items length is also allowed, but has no value. - } else { - IAndroidBufferQueue *thiz = (IAndroidBufferQueue *) self; - - // buffer size check, can be done outside of lock because buffer type can't change - switch (thiz->mBufferType) { - case kAndroidBufferTypeMpeg2Ts: - if (dataLength % MPEG2_TS_PACKET_SIZE == 0) { - // The downstream Stagefright MPEG-2 TS parser is sensitive to format errors, - // so do a quick sanity check beforehand on the first packet of the buffer. - // We don't check all the packets to avoid thrashing the data cache. - if ((dataLength > 0) && (*(SLuint8 *)pData != MPEG2_TS_PACKET_SYNC)) { - SL_LOGE("Error enqueueing MPEG-2 TS data: incorrect packet sync"); - result = SL_RESULT_CONTENT_CORRUPTED; - SL_LEAVE_INTERFACE - } - break; - } - SL_LOGE("Error enqueueing MPEG-2 TS data: size must be a multiple of %d (packet size)", - MPEG2_TS_PACKET_SIZE); - result = SL_RESULT_PARAMETER_INVALID; - SL_LEAVE_INTERFACE - break; - case kAndroidBufferTypeAacadts: - // zero dataLength is permitted in case of EOS command only - if (dataLength > 0) { - result = android::AacBqToPcmCbRenderer::validateBufferStartEndOnFrameBoundaries( - pData, dataLength); - if (SL_RESULT_SUCCESS != result) { - SL_LOGE("Error enqueueing ADTS data: data must start and end on frame " - "boundaries"); - SL_LEAVE_INTERFACE - } - } - break; - case kAndroidBufferTypeInvalid: - default: - result = SL_RESULT_PARAMETER_INVALID; - SL_LEAVE_INTERFACE - } - - interface_lock_exclusive(thiz); - - AdvancedBufferHeader *oldRear = thiz->mRear, *newRear; - if ((newRear = oldRear + 1) == &thiz->mBufferArray[thiz->mNumBuffers + 1]) { - newRear = thiz->mBufferArray; - } - if (thiz->mEOS) { - SL_LOGE("Can't enqueue after EOS"); - result = SL_RESULT_PRECONDITIONS_VIOLATED; - } else if (newRear == thiz->mFront) { - result = SL_RESULT_BUFFER_INSUFFICIENT; - } else { - // set oldRear->mItems based on items - result = setItems(dataLength, pItems, itemsLength, thiz->mBufferType, oldRear, - &thiz->mEOS); - if (SL_RESULT_SUCCESS == result) { - oldRear->mDataBuffer = pData; - oldRear->mDataSize = dataLength; - oldRear->mDataSizeConsumed = 0; - oldRear->mBufferContext = pBufferContext; - //oldRear->mBufferState = TBD; - thiz->mRear = newRear; - ++thiz->mState.count; - } - } - // set enqueue attribute if state is PLAYING and the first buffer is enqueued - interface_unlock_exclusive_attributes(thiz, ((SL_RESULT_SUCCESS == result) && - (1 == thiz->mState.count) && (SL_PLAYSTATE_PLAYING == getAssociatedState(thiz))) ? - ATTR_ABQ_ENQUEUE : ATTR_NONE); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IAndroidBufferQueue_GetState(SLAndroidBufferQueueItf self, - SLAndroidBufferQueueState *pState) -{ - SL_ENTER_INTERFACE - - // Note that GetState while a Clear is pending is equivalent to GetState before the Clear - - if (NULL == pState) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IAndroidBufferQueue *thiz = (IAndroidBufferQueue *) self; - - interface_lock_shared(thiz); - - pState->count = thiz->mState.count; - pState->index = thiz->mState.index; - - interface_unlock_shared(thiz); - - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IAndroidBufferQueue_SetCallbackEventsMask(SLAndroidBufferQueueItf self, - SLuint32 eventFlags) -{ - SL_ENTER_INTERFACE - - IAndroidBufferQueue *thiz = (IAndroidBufferQueue *) self; - interface_lock_exclusive(thiz); - // FIXME only supporting SL_ANDROIDBUFFERQUEUEEVENT_PROCESSED in this implementation - if (!(~(SL_ANDROIDBUFFERQUEUEEVENT_PROCESSED /* | others TBD */ ) & eventFlags)) { - thiz->mCallbackEventsMask = eventFlags; - result = SL_RESULT_SUCCESS; - } else { - result = SL_RESULT_FEATURE_UNSUPPORTED; - } - interface_unlock_exclusive(thiz); - - SL_LEAVE_INTERFACE -} - - -static SLresult IAndroidBufferQueue_GetCallbackEventsMask(SLAndroidBufferQueueItf self, - SLuint32 *pEventFlags) -{ - SL_ENTER_INTERFACE - - if (NULL == pEventFlags) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IAndroidBufferQueue *thiz = (IAndroidBufferQueue *) self; - interface_lock_shared(thiz); - SLuint32 callbackEventsMask = thiz->mCallbackEventsMask; - interface_unlock_shared(thiz); - *pEventFlags = callbackEventsMask; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static const struct SLAndroidBufferQueueItf_ IAndroidBufferQueue_Itf = { - IAndroidBufferQueue_RegisterCallback, - IAndroidBufferQueue_Clear, - IAndroidBufferQueue_Enqueue, - IAndroidBufferQueue_GetState, - IAndroidBufferQueue_SetCallbackEventsMask, - IAndroidBufferQueue_GetCallbackEventsMask -}; - - -void IAndroidBufferQueue_init(void *self) -{ - IAndroidBufferQueue *thiz = (IAndroidBufferQueue *) self; - thiz->mItf = &IAndroidBufferQueue_Itf; - - thiz->mState.count = 0; - thiz->mState.index = 0; - - thiz->mCallback = NULL; - thiz->mContext = NULL; - thiz->mCallbackEventsMask = SL_ANDROIDBUFFERQUEUEEVENT_PROCESSED; - - thiz->mBufferType = kAndroidBufferTypeInvalid; - thiz->mBufferArray = NULL; - thiz->mFront = NULL; - thiz->mRear = NULL; - thiz->mEOS = false; -} - - -void IAndroidBufferQueue_deinit(void *self) -{ - IAndroidBufferQueue *thiz = (IAndroidBufferQueue *) self; - if (NULL != thiz->mBufferArray) { - free(thiz->mBufferArray); - thiz->mBufferArray = NULL; - } -} - - -#if 0 -// Dump the contents of an IAndroidBufferQueue to the log. This is for debugging only, -// and is not a documented API. The associated object is locked throughout for atomicity, -// but the log entries may be interspersed with unrelated logs. - -void IAndroidBufferQueue_log(IAndroidBufferQueue *thiz) -{ - interface_lock_shared(thiz); - SL_LOGI("IAndroidBufferQueue %p:", thiz); - SL_LOGI(" mState.count=%u mState.index=%u mCallback=%p mContext=%p", - thiz->mState.count, thiz->mState.index, thiz->mCallback, thiz->mContext); - const char *bufferTypeString; - switch (thiz->mBufferType) { - case kAndroidBufferTypeInvalid: - bufferTypeString = "kAndroidBufferTypeInvalid"; - break; - case kAndroidBufferTypeMpeg2Ts: - bufferTypeString = "kAndroidBufferTypeMpeg2Ts"; - break; - case kAndroidBufferTypeAacadts: - bufferTypeString = "kAndroidBufferTypeAacadts"; - break; - default: - bufferTypeString = "unknown"; - break; - } - SL_LOGI(" mCallbackEventsMask=0x%x, mBufferType=0x%x (%s), mEOS=%s", - thiz->mCallbackEventsMask, - thiz->mBufferType, bufferTypeString, - thiz->mEOS ? "true" : "false"); - SL_LOGI(" mBufferArray=%p, mFront=%p (%u), mRear=%p (%u)", - thiz->mBufferArray, - thiz->mFront, thiz->mFront - thiz->mBufferArray, - thiz->mRear, thiz->mRear - thiz->mBufferArray); - SL_LOGI(" index mDataBuffer mDataSize mDataSizeConsumed mBufferContext mItems"); - const AdvancedBufferHeader *hdr; - for (hdr = thiz->mFront; hdr != thiz->mRear; ) { - SLuint32 i = hdr - thiz->mBufferArray; - char itemString[32]; - switch (thiz->mBufferType) { - case kAndroidBufferTypeMpeg2Ts: - switch (hdr->mItems.mTsCmdData.mTsCmdCode) { - case ANDROID_MP2TSEVENT_NONE: - strcpy(itemString, "NONE"); - break; - case ANDROID_MP2TSEVENT_EOS: - strcpy(itemString, "EOS"); - break; - case ANDROID_MP2TSEVENT_DISCONTINUITY: - strcpy(itemString, "DISCONTINUITY"); - break; - case ANDROID_MP2TSEVENT_DISCON_NEWPTS: - snprintf(itemString, sizeof(itemString), "NEWPTS %llu", - hdr->mItems.mTsCmdData.mPts); - break; - case ANDROID_MP2TSEVENT_FORMAT_CHANGE: - strcpy(itemString, "FORMAT_CHANGE"); - break; - default: - snprintf(itemString, sizeof(itemString), "0x%x", hdr->mItems.mTsCmdData.mTsCmdCode); - break; - } - break; - case kAndroidBufferTypeAacadts: - switch (hdr->mItems.mAdtsCmdData.mAdtsCmdCode) { - case ANDROID_ADTSEVENT_NONE: - strcpy(itemString, "NONE"); - break; - case ANDROID_ADTSEVENT_EOS: - strcpy(itemString, "EOS"); - break; - default: - snprintf(itemString, sizeof(itemString), "0x%x", - hdr->mItems.mAdtsCmdData.mAdtsCmdCode); - break; - } - break; - default: - strcpy(itemString, ""); - break; - } - SL_LOGI(" %5u %11p %9u %17u %14p %s", - i, hdr->mDataBuffer, hdr->mDataSize, hdr->mDataSizeConsumed, - hdr->mBufferContext, itemString); - // mBufferState - if (++hdr == &thiz->mBufferArray[thiz->mNumBuffers + 1]) { - hdr = thiz->mBufferArray; - } - } - interface_unlock_shared(thiz); -} - -#endif diff --git a/wilhelm/src/itf/IAndroidConfiguration.c b/wilhelm/src/itf/IAndroidConfiguration.c deleted file mode 100644 index bd4ed542..00000000 --- a/wilhelm/src/itf/IAndroidConfiguration.c +++ /dev/null @@ -1,108 +0,0 @@ -/* - * 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. - */ - -/* AndroidConfiguration implementation */ - -#include "sles_allinclusive.h" - - -static SLresult IAndroidConfiguration_SetConfiguration(SLAndroidConfigurationItf self, - const SLchar *configKey, - const void *pConfigValue, - SLuint32 valueSize) -{ - SL_ENTER_INTERFACE - - // object-specific code will check that valueSize is large enough for the key - if (NULL == configKey || NULL == pConfigValue || valueSize == 0) { - result = SL_RESULT_PARAMETER_INVALID; - - } else { - IAndroidConfiguration *thiz = (IAndroidConfiguration *) self; - interface_lock_exclusive(thiz); - - // route configuration to the appropriate object - switch (IObjectToObjectID((thiz)->mThis)) { - case SL_OBJECTID_AUDIORECORDER: - SL_LOGV("SetConfiguration issued for AudioRecorder key=%s valueSize=%u", - configKey, valueSize); - result = android_audioRecorder_setConfig((CAudioRecorder *) thiz->mThis, configKey, - pConfigValue, valueSize); - break; - case SL_OBJECTID_AUDIOPLAYER: - SL_LOGV("SetConfiguration issued for AudioPlayer key=%s valueSize=%u", - configKey, valueSize); - result = android_audioPlayer_setConfig((CAudioPlayer *) thiz->mThis, configKey, - pConfigValue, valueSize); - break; - default: - result = SL_RESULT_FEATURE_UNSUPPORTED; - break; - } - - interface_unlock_exclusive(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IAndroidConfiguration_GetConfiguration(SLAndroidConfigurationItf self, - const SLchar *configKey, - SLuint32 *pValueSize, - void *pConfigValue) -{ - SL_ENTER_INTERFACE - - // non-NULL pValueSize is required, but a NULL pConfigValue is allowed, so - // that we can report the actual value size without returning the value itself - if (NULL == configKey || NULL == pValueSize) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IAndroidConfiguration *thiz = (IAndroidConfiguration *) self; - interface_lock_exclusive(thiz); - - // route configuration request to the appropriate object - switch (IObjectToObjectID((thiz)->mThis)) { - case SL_OBJECTID_AUDIORECORDER: - result = android_audioRecorder_getConfig((CAudioRecorder *) thiz->mThis, configKey, - pValueSize, pConfigValue); - break; - case SL_OBJECTID_AUDIOPLAYER: - result = android_audioPlayer_getConfig((CAudioPlayer *) thiz->mThis, configKey, - pValueSize, pConfigValue); - default: - result = SL_RESULT_FEATURE_UNSUPPORTED; - break; - } - - interface_unlock_exclusive(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static const struct SLAndroidConfigurationItf_ IAndroidConfiguration_Itf = { - IAndroidConfiguration_SetConfiguration, - IAndroidConfiguration_GetConfiguration -}; - -void IAndroidConfiguration_init(void *self) -{ - IAndroidConfiguration *thiz = (IAndroidConfiguration *) self; - thiz->mItf = &IAndroidConfiguration_Itf; -} diff --git a/wilhelm/src/itf/IAndroidEffect.cpp b/wilhelm/src/itf/IAndroidEffect.cpp deleted file mode 100644 index f34cabdb..00000000 --- a/wilhelm/src/itf/IAndroidEffect.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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. - */ - -/* Android Effect implementation */ - -#include "sles_allinclusive.h" - -#include <system/audio.h> - -static SLresult IAndroidEffect_CreateEffect(SLAndroidEffectItf self, - SLInterfaceID effectImplementationId) { - - SL_ENTER_INTERFACE - - IAndroidEffect *thiz = (IAndroidEffect *) self; - if (SL_OBJECTID_AUDIOPLAYER == IObjectToObjectID(thiz->mThis)) { - CAudioPlayer *ap = (CAudioPlayer *)thiz->mThis; - if (ap->mAudioTrack != 0) { - result = android_genericFx_createEffect(thiz, effectImplementationId, ap->mSessionId); - } else { - result = SL_RESULT_RESOURCE_ERROR; - } - } else if (SL_OBJECTID_OUTPUTMIX == IObjectToObjectID(thiz->mThis)) { - result = android_genericFx_createEffect(thiz, effectImplementationId, - AUDIO_SESSION_OUTPUT_MIX); - } else { - // the interface itself is invalid because it is not attached to an AudioPlayer or - // an OutputMix - result = SL_RESULT_PARAMETER_INVALID; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IAndroidEffect_ReleaseEffect(SLAndroidEffectItf self, - SLInterfaceID effectImplementationId) { - - SL_ENTER_INTERFACE - - IAndroidEffect *thiz = (IAndroidEffect *) self; - result = android_genericFx_releaseEffect(thiz, effectImplementationId); - - SL_LEAVE_INTERFACE -} - - -static SLresult IAndroidEffect_SetEnabled(SLAndroidEffectItf self, - SLInterfaceID effectImplementationId, SLboolean enabled) { - - SL_ENTER_INTERFACE - - IAndroidEffect *thiz = (IAndroidEffect *) self; - result = android_genericFx_setEnabled(thiz, effectImplementationId, enabled); - - SL_LEAVE_INTERFACE -} - - -static SLresult IAndroidEffect_IsEnabled(SLAndroidEffectItf self, - SLInterfaceID effectImplementationId, SLboolean * pEnabled) { - - SL_ENTER_INTERFACE - - IAndroidEffect *thiz = (IAndroidEffect *) self; - result = android_genericFx_isEnabled(thiz, effectImplementationId, pEnabled); - - SL_LEAVE_INTERFACE -} - - -static SLresult IAndroidEffect_SendCommand(SLAndroidEffectItf self, - SLInterfaceID effectImplementationId, SLuint32 command, SLuint32 commandSize, - void* pCommand, SLuint32 *replySize, void *pReply) { - - SL_ENTER_INTERFACE - - IAndroidEffect *thiz = (IAndroidEffect *) self; - result = android_genericFx_sendCommand(thiz, effectImplementationId, command, commandSize, - pCommand, replySize, pReply); - - SL_LEAVE_INTERFACE -} - - -static const struct SLAndroidEffectItf_ IAndroidEffect_Itf = { - IAndroidEffect_CreateEffect, - IAndroidEffect_ReleaseEffect, - IAndroidEffect_SetEnabled, - IAndroidEffect_IsEnabled, - IAndroidEffect_SendCommand -}; - -void IAndroidEffect_init(void *self) -{ - IAndroidEffect *thiz = (IAndroidEffect *) self; - thiz->mItf = &IAndroidEffect_Itf; - thiz->mEffects = new android::KeyedVector<SLuint32, android::AudioEffect* >(); -} - -void IAndroidEffect_deinit(void *self) -{ - IAndroidEffect *thiz = (IAndroidEffect *) self; - if (NULL != thiz->mEffects) { - if (!thiz->mEffects->isEmpty()) { - for (size_t i = 0 ; i < thiz->mEffects->size() ; i++) { - delete thiz->mEffects->valueAt(i); - } - thiz->mEffects->clear(); - } - delete thiz->mEffects; - thiz->mEffects = NULL; - } -} diff --git a/wilhelm/src/itf/IAndroidEffectCapabilities.c b/wilhelm/src/itf/IAndroidEffectCapabilities.c deleted file mode 100644 index 923b6a71..00000000 --- a/wilhelm/src/itf/IAndroidEffectCapabilities.c +++ /dev/null @@ -1,139 +0,0 @@ -/* - * 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. - */ - -/* Android Effect Capabilities implementation */ - -#include "sles_allinclusive.h" - - -static SLresult IAndroidEffectCapabilities_QueryNumEffects(SLAndroidEffectCapabilitiesItf self, - SLuint32 * pNumSupportedAudioEffects) { - - SL_ENTER_INTERFACE - - if (NULL == pNumSupportedAudioEffects) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IAndroidEffectCapabilities *thiz = (IAndroidEffectCapabilities *) self; - interface_lock_shared(thiz); - - *pNumSupportedAudioEffects = thiz->mNumFx; - result = SL_RESULT_SUCCESS; - - interface_unlock_shared(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IAndroidEffectCapabilities_QueryEffect(SLAndroidEffectCapabilitiesItf self, - SLuint32 index, SLInterfaceID *pEffectType, SLInterfaceID *pEffectImplementation, - SLchar * pName, SLuint16 *pNameSize) { - - SL_ENTER_INTERFACE - - IAndroidEffectCapabilities *thiz = (IAndroidEffectCapabilities *) self; - if (index > thiz->mNumFx) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - interface_lock_shared(thiz); - if (NULL != pEffectType) { - *pEffectType = (SLInterfaceID) &thiz->mFxDescriptors[index].type; - } - if (NULL != pEffectImplementation) { - *pEffectImplementation = (SLInterfaceID) &thiz->mFxDescriptors[index].uuid; - } - if ((NULL != pName) && (0 < *pNameSize)) { - int len = strlen(thiz->mFxDescriptors[index].name); - strncpy((char*)pName, thiz->mFxDescriptors[index].name, - *pNameSize > len ? len : *pNameSize ); - *pNameSize = len; - } - interface_unlock_shared(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static const struct SLAndroidEffectCapabilitiesItf_ IAndroidEffectCapabilities_Itf = { - IAndroidEffectCapabilities_QueryNumEffects, - IAndroidEffectCapabilities_QueryEffect -}; - -void IAndroidEffectCapabilities_init(void *self) -{ - IAndroidEffectCapabilities *thiz = (IAndroidEffectCapabilities *) self; - thiz->mItf = &IAndroidEffectCapabilities_Itf; - - // This is the default initialization; fields will be updated when interface is exposed - thiz->mNumFx = 0; - thiz->mFxDescriptors = NULL; -} - -bool IAndroidEffectCapabilities_Expose(void *self) -{ - IAndroidEffectCapabilities *thiz = (IAndroidEffectCapabilities *) self; - SLuint32 numEffects = 0; - SLresult result = android_genericFx_queryNumEffects(&numEffects); - if (SL_RESULT_SUCCESS != result) { - SL_LOGE("android_genericFx_queryNumEffects %u", result); - return false; - } - thiz->mNumFx = numEffects; - SL_LOGV("Effect Capabilities has %d effects", thiz->mNumFx); - if (thiz->mNumFx > 0) { - thiz->mFxDescriptors = (effect_descriptor_t*) new effect_descriptor_t[thiz->mNumFx]; - for (SLuint32 i = 0 ; i < thiz->mNumFx ; i++) { - SLresult result2; - result2 = android_genericFx_queryEffect(i, &thiz->mFxDescriptors[i]); - if (SL_RESULT_SUCCESS != result2) { - SL_LOGE("Error (SLresult is %d) querying effect %d", result2, i); - // Remember the first failing result code, but keep going - if (SL_RESULT_SUCCESS == result) { - result = result2; - } - } else { - SL_LOGV("effect %d: type=%08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x name=%s", - i, - thiz->mFxDescriptors[i].type.timeLow, - thiz->mFxDescriptors[i].type.timeMid, - thiz->mFxDescriptors[i].type.timeHiAndVersion, - thiz->mFxDescriptors[i].type.clockSeq, - thiz->mFxDescriptors[i].type.node[0], - thiz->mFxDescriptors[i].type.node[1], - thiz->mFxDescriptors[i].type.node[2], - thiz->mFxDescriptors[i].type.node[3], - thiz->mFxDescriptors[i].type.node[4], - thiz->mFxDescriptors[i].type.node[5], - thiz->mFxDescriptors[i].name); - } - } - } - return SL_RESULT_SUCCESS == result; -} - -void IAndroidEffectCapabilities_deinit(void *self) -{ - IAndroidEffectCapabilities *thiz = (IAndroidEffectCapabilities *) self; - // free effect library data - if (NULL != thiz->mFxDescriptors) { - delete[] thiz->mFxDescriptors; - thiz->mFxDescriptors = NULL; - } -} diff --git a/wilhelm/src/itf/IAndroidEffectSend.c b/wilhelm/src/itf/IAndroidEffectSend.c deleted file mode 100644 index b0757530..00000000 --- a/wilhelm/src/itf/IAndroidEffectSend.c +++ /dev/null @@ -1,236 +0,0 @@ -/* - * 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. - */ - -/* AndroidEffectSend implementation */ - -#include "sles_allinclusive.h" - - -static SLresult IAndroidEffectSend_EnableEffectSend(SLAndroidEffectSendItf self, - SLInterfaceID effectImplementationId, SLboolean enable, SLmillibel initialLevel) -{ - SL_ENTER_INTERFACE - - //if (!((SL_MILLIBEL_MIN <= initialLevel) && (initialLevel <= 0))) { - // comparison (SL_MILLIBEL_MIN <= initialLevel) is always true due to range of SLmillibel - if (!(initialLevel <= 0)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IAndroidEffectSend *thiz = (IAndroidEffectSend *) self; - interface_lock_exclusive(thiz); - // is SLAndroidEffectSendItf on an AudioPlayer? - CAudioPlayer *ap = (SL_OBJECTID_AUDIOPLAYER == InterfaceToObjectID(thiz)) ? - (CAudioPlayer *) thiz->mThis : NULL; - if (NULL == ap) { - SL_LOGE("invalid interface: not attached to an AudioPlayer"); - result = SL_RESULT_PARAMETER_INVALID; - } else { - COutputMix *outputMix = CAudioPlayer_GetOutputMix(ap); - // the initial send level set here is the total energy on the aux bus, - // so it must take into account the player volume level - result = android_fxSend_attachToAux(ap, effectImplementationId, enable, - initialLevel + ap->mVolume.mLevel); - if (SL_RESULT_SUCCESS == result) { - // there currently is support for only one send bus, so there is a single send - // level and a single enable flag - thiz->mSendLevel = initialLevel; - thiz->mEnabled = enable; - } - } - interface_unlock_exclusive(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IAndroidEffectSend_IsEnabled(SLAndroidEffectSendItf self, - SLInterfaceID effectImplementationId, SLboolean *pEnable) -{ - SL_ENTER_INTERFACE - - if (NULL == pEnable) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IAndroidEffectSend *thiz = (IAndroidEffectSend *) self; - interface_lock_shared(thiz); - // there currently is support for only one send bus, so there is a single enable flag - SLboolean enable = thiz->mEnabled; - interface_unlock_shared(thiz); - *pEnable = enable; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IAndroidEffectSend_SetDirectLevel(SLAndroidEffectSendItf self, - SLmillibel directLevel) -{ - SL_ENTER_INTERFACE - - //if (!((SL_MILLIBEL_MIN <= directLevel) && (directLevel <= 0))) { - // comparison (SL_MILLIBEL_MIN <= directLevel) is always true due to range of SLmillibel - if (!(directLevel <= 0)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IAndroidEffectSend *thiz = (IAndroidEffectSend *) self; - interface_lock_exclusive(thiz); - CAudioPlayer *ap = (SL_OBJECTID_AUDIOPLAYER == InterfaceToObjectID(thiz)) ? - (CAudioPlayer *) thiz->mThis : NULL; - if (NULL != ap) { - SLmillibel oldDirectLevel = ap->mDirectLevel; - if (oldDirectLevel != directLevel) { - ap->mDirectLevel = directLevel; - ap->mAmplFromDirectLevel = sles_to_android_amplification(directLevel); - interface_unlock_exclusive_attributes(thiz, ATTR_GAIN); - } else { - interface_unlock_exclusive(thiz); - } - result = SL_RESULT_SUCCESS; - } else { - interface_unlock_exclusive(thiz); - SL_LOGE("invalid interface: not attached to an AudioPlayer"); - result = SL_RESULT_PARAMETER_INVALID; - } - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IAndroidEffectSend_GetDirectLevel(SLAndroidEffectSendItf self, - SLmillibel *pDirectLevel) -{ - SL_ENTER_INTERFACE - - if (NULL == pDirectLevel) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IAndroidEffectSend *thiz = (IAndroidEffectSend *) self; - interface_lock_shared(thiz); - CAudioPlayer *ap = (SL_OBJECTID_AUDIOPLAYER == InterfaceToObjectID(thiz)) ? - (CAudioPlayer *) thiz->mThis : NULL; - if (NULL != ap) { - *pDirectLevel = ap->mDirectLevel; - result = SL_RESULT_SUCCESS; - } else { - SL_LOGE("invalid interface: not attached to an AudioPlayer"); - result = SL_RESULT_PARAMETER_INVALID; - } - interface_unlock_shared(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IAndroidEffectSend_SetSendLevel(SLAndroidEffectSendItf self, - SLInterfaceID effectImplementationId, SLmillibel sendLevel) -{ - SL_ENTER_INTERFACE - - //if (!((SL_MILLIBEL_MIN <= sendLevel) && (sendLevel <= 0))) { - // comparison (SL_MILLIBEL_MIN <= sendLevel) is always true due to range of SLmillibel - if (!(sendLevel <= 0)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IAndroidEffectSend *thiz = (IAndroidEffectSend *) self; - interface_lock_exclusive(thiz); - // is SLAndroidEffectSendItf on an AudioPlayer? - CAudioPlayer *ap = (SL_OBJECTID_AUDIOPLAYER == InterfaceToObjectID(thiz)) ? - (CAudioPlayer *) thiz->mThis : NULL; - if (NULL == ap) { - SL_LOGE("invalid interface: not attached to an AudioPlayer"); - result = SL_RESULT_PARAMETER_INVALID; - } else { - COutputMix *outputMix = CAudioPlayer_GetOutputMix(ap); - if (android_genericFx_hasEffect(&outputMix->mAndroidEffect, effectImplementationId)) { - // the send level set here is the total energy on the aux bus, so it must take - // into account the player volume level - result = android_fxSend_setSendLevel(ap, sendLevel + ap->mVolume.mLevel); - } else { - SL_LOGE("trying to send to an effect not on this AudioPlayer's OutputMix"); - result = SL_RESULT_PARAMETER_INVALID; - } - if (SL_RESULT_SUCCESS == result) { - // there currently is support for only one send bus, so there is a single send - // level - thiz->mSendLevel = sendLevel; - } - } - interface_unlock_exclusive(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IAndroidEffectSend_GetSendLevel(SLAndroidEffectSendItf self, - SLInterfaceID effectImplementationId, SLmillibel *pSendLevel) -{ - SL_ENTER_INTERFACE - - if (NULL == pSendLevel) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IAndroidEffectSend *thiz = (IAndroidEffectSend *) self; - interface_lock_exclusive(thiz); - // is SLAndroidEffectSendItf on an AudioPlayer? - CAudioPlayer *ap = (SL_OBJECTID_AUDIOPLAYER == InterfaceToObjectID(thiz)) ? - (CAudioPlayer *) thiz->mThis : NULL; - if (NULL == ap) { - SL_LOGE("invalid interface: not attached to an AudioPlayer"); - result = SL_RESULT_PARAMETER_INVALID; - } else { - COutputMix *outputMix = CAudioPlayer_GetOutputMix(ap); - if (android_genericFx_hasEffect(&outputMix->mAndroidEffect, effectImplementationId)) { - result = SL_RESULT_SUCCESS; - } else { - SL_LOGE("trying to retrieve send level on an effect not on this AudioPlayer's \ -OutputMix"); - result = SL_RESULT_PARAMETER_INVALID; - } - if (SL_RESULT_SUCCESS == result) { - // there currently is support for only one send bus, so there is a single send - // level - *pSendLevel = thiz->mSendLevel; - } - } - interface_unlock_exclusive(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static const struct SLAndroidEffectSendItf_ IAndroidEffectSend_Itf = { - IAndroidEffectSend_EnableEffectSend, - IAndroidEffectSend_IsEnabled, - IAndroidEffectSend_SetDirectLevel, - IAndroidEffectSend_GetDirectLevel, - IAndroidEffectSend_SetSendLevel, - IAndroidEffectSend_GetSendLevel -}; - -void IAndroidEffectSend_init(void *self) -{ - IAndroidEffectSend *thiz = (IAndroidEffectSend *) self; - thiz->mItf = &IAndroidEffectSend_Itf; - thiz->mEnabled = SL_BOOLEAN_FALSE; - thiz->mSendLevel = SL_MILLIBEL_MIN; -} diff --git a/wilhelm/src/itf/IAudioDecoderCapabilities.c b/wilhelm/src/itf/IAudioDecoderCapabilities.c deleted file mode 100644 index c332a653..00000000 --- a/wilhelm/src/itf/IAudioDecoderCapabilities.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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. - */ - -/* AudioDecoderCapabilities implementation */ - -#include "sles_allinclusive.h" - - -static SLresult IAudioDecoderCapabilities_GetAudioDecoders(SLAudioDecoderCapabilitiesItf self, - SLuint32 *pNumDecoders, SLuint32 *pDecoderIds) -{ - SL_ENTER_INTERFACE - - if (NULL == pNumDecoders) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - result = SL_RESULT_SUCCESS; - if (NULL != pDecoderIds) { - SLuint32 numDecoders = *pNumDecoders; - if (numDecoders > MAX_DECODERS) { - numDecoders = MAX_DECODERS; - } else if (numDecoders < MAX_DECODERS) { - // FIXME starting in 1.1 this will be SL_RESULT_BUFFER_INSUFFICIENT - result = SL_RESULT_PARAMETER_INVALID; - } - memcpy(pDecoderIds, Decoder_IDs, numDecoders * sizeof(SLuint32)); - } - *pNumDecoders = MAX_DECODERS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IAudioDecoderCapabilities_GetAudioDecoderCapabilities( - SLAudioDecoderCapabilitiesItf self, SLuint32 decoderId, SLuint32 *pIndex, - SLAudioCodecDescriptor *pDescriptor) -{ - SL_ENTER_INTERFACE - - result = GetCodecCapabilities(decoderId, pIndex, pDescriptor, DecoderDescriptors); - - SL_LEAVE_INTERFACE -} - - -static const struct SLAudioDecoderCapabilitiesItf_ IAudioDecoderCapabilities_Itf = { - IAudioDecoderCapabilities_GetAudioDecoders, - IAudioDecoderCapabilities_GetAudioDecoderCapabilities -}; - -void IAudioDecoderCapabilities_init(void *self) -{ - IAudioDecoderCapabilities *thiz = (IAudioDecoderCapabilities *) self; - thiz->mItf = &IAudioDecoderCapabilities_Itf; -} diff --git a/wilhelm/src/itf/IAudioEncoder.c b/wilhelm/src/itf/IAudioEncoder.c deleted file mode 100644 index 511a0080..00000000 --- a/wilhelm/src/itf/IAudioEncoder.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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. - */ - -/* AudioEncoder implementation */ - -#include "sles_allinclusive.h" - - -static SLresult IAudioEncoder_SetEncoderSettings(SLAudioEncoderItf self, - SLAudioEncoderSettings *pSettings) -{ - SL_ENTER_INTERFACE - - if (NULL == pSettings) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IAudioEncoder *thiz = (IAudioEncoder *) self; - SLAudioEncoderSettings settings = *pSettings; - interface_lock_exclusive(thiz); - thiz->mSettings = settings; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IAudioEncoder_GetEncoderSettings(SLAudioEncoderItf self, - SLAudioEncoderSettings *pSettings) -{ - SL_ENTER_INTERFACE - - if (NULL == pSettings) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IAudioEncoder *thiz = (IAudioEncoder *) self; - interface_lock_shared(thiz); - SLAudioEncoderSettings settings = thiz->mSettings; - interface_unlock_shared(thiz); - *pSettings = settings; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static const struct SLAudioEncoderItf_ IAudioEncoder_Itf = { - IAudioEncoder_SetEncoderSettings, - IAudioEncoder_GetEncoderSettings -}; - -void IAudioEncoder_init(void *self) -{ - IAudioEncoder *thiz = (IAudioEncoder *) self; - thiz->mItf = &IAudioEncoder_Itf; - memset(&thiz->mSettings, 0, sizeof(SLAudioEncoderSettings)); -} diff --git a/wilhelm/src/itf/IAudioEncoderCapabilities.c b/wilhelm/src/itf/IAudioEncoderCapabilities.c deleted file mode 100644 index 3f45118a..00000000 --- a/wilhelm/src/itf/IAudioEncoderCapabilities.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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. - */ - -/* AudioEncoderCapabilities implementation */ - -#include "sles_allinclusive.h" - - -static SLresult IAudioEncoderCapabilities_GetAudioEncoders(SLAudioEncoderCapabilitiesItf self, - SLuint32 *pNumEncoders, SLuint32 *pEncoderIds) -{ - SL_ENTER_INTERFACE - - if (NULL == pNumEncoders) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - result = SL_RESULT_SUCCESS; - if (NULL != pEncoderIds) { - SLuint32 numEncoders = *pNumEncoders; - if (numEncoders > MAX_ENCODERS) { - numEncoders = MAX_ENCODERS; - } else if (numEncoders < MAX_ENCODERS) { - // FIXME starting in 1.1 this will be SL_RESULT_BUFFER_INSUFFICIENT - result = SL_RESULT_PARAMETER_INVALID; - } - memcpy(pEncoderIds, Encoder_IDs, numEncoders * sizeof(SLuint32)); - } - *pNumEncoders = MAX_ENCODERS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IAudioEncoderCapabilities_GetAudioEncoderCapabilities( - SLAudioEncoderCapabilitiesItf self, SLuint32 encoderId, SLuint32 *pIndex, - SLAudioCodecDescriptor *pDescriptor) -{ - SL_ENTER_INTERFACE - - result = GetCodecCapabilities(encoderId, pIndex, pDescriptor, - EncoderDescriptors); - - SL_LEAVE_INTERFACE -} - - -static const struct SLAudioEncoderCapabilitiesItf_ IAudioEncoderCapabilities_Itf = { - IAudioEncoderCapabilities_GetAudioEncoders, - IAudioEncoderCapabilities_GetAudioEncoderCapabilities -}; - -void IAudioEncoderCapabilities_init(void *self) -{ - IAudioEncoderCapabilities *thiz = (IAudioEncoderCapabilities *) self; - thiz->mItf = &IAudioEncoderCapabilities_Itf; -} diff --git a/wilhelm/src/itf/IAudioIODeviceCapabilities.c b/wilhelm/src/itf/IAudioIODeviceCapabilities.c deleted file mode 100644 index f667e984..00000000 --- a/wilhelm/src/itf/IAudioIODeviceCapabilities.c +++ /dev/null @@ -1,323 +0,0 @@ -/* - * 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. - */ - -#include "sles_allinclusive.h" - -/* AudioIODeviceCapabilities implementation */ - -// NTH make it platform-configurable - - -static SLresult IAudioIODeviceCapabilities_GetAvailableAudioInputs( - SLAudioIODeviceCapabilitiesItf self, SLint32 *pNumInputs, SLuint32 *pInputDeviceIDs) -{ - SL_ENTER_INTERFACE - - if (NULL == pNumInputs) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - result = SL_RESULT_SUCCESS; - if (NULL != pInputDeviceIDs) { - if (1 > *pNumInputs) { - result = SL_RESULT_BUFFER_INSUFFICIENT; - } else { - pInputDeviceIDs[0] = SL_DEFAULTDEVICEID_AUDIOINPUT; - } - } - *pNumInputs = 1; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IAudioIODeviceCapabilities_QueryAudioInputCapabilities( - SLAudioIODeviceCapabilitiesItf self, SLuint32 deviceID, SLAudioInputDescriptor *pDescriptor) -{ - SL_ENTER_INTERFACE - - if (NULL == pDescriptor) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - result = SL_RESULT_SUCCESS; - switch (deviceID) { - case SL_DEFAULTDEVICEID_AUDIOINPUT: - *pDescriptor = *AudioInput_id_descriptors[0].descriptor; - break; - default: - result = SL_RESULT_IO_ERROR; - break; - } - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IAudioIODeviceCapabilities_RegisterAvailableAudioInputsChangedCallback( - SLAudioIODeviceCapabilitiesItf self, slAvailableAudioInputsChangedCallback callback, - void *pContext) -{ - SL_ENTER_INTERFACE - - IAudioIODeviceCapabilities * thiz = (IAudioIODeviceCapabilities *) self; - interface_lock_exclusive(thiz); - thiz->mAvailableAudioInputsChangedCallback = callback; - thiz->mAvailableAudioInputsChangedContext = pContext; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static SLresult IAudioIODeviceCapabilities_GetAvailableAudioOutputs( - SLAudioIODeviceCapabilitiesItf self, SLint32 *pNumOutputs, SLuint32 *pOutputDeviceIDs) -{ - SL_ENTER_INTERFACE - - if (NULL == pNumOutputs) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - result = SL_RESULT_SUCCESS; - if (NULL != pOutputDeviceIDs) { - if (2 > *pNumOutputs) { - result = SL_RESULT_BUFFER_INSUFFICIENT; - // if 1 slot available, should still fill that - } else { - pOutputDeviceIDs[0] = DEVICE_ID_HEADSET; - pOutputDeviceIDs[1] = DEVICE_ID_HANDSFREE; - // SL_DEFAULTDEVICEID_AUDIOOUTPUT? - } - } - *pNumOutputs = 2; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IAudioIODeviceCapabilities_QueryAudioOutputCapabilities( - SLAudioIODeviceCapabilitiesItf self, SLuint32 deviceID, SLAudioOutputDescriptor *pDescriptor) -{ - SL_ENTER_INTERFACE - - if (NULL == pDescriptor) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - result = SL_RESULT_SUCCESS; - switch (deviceID) { - case DEVICE_ID_HEADSET: - *pDescriptor = *AudioOutput_id_descriptors[1].descriptor; - break; - case DEVICE_ID_HANDSFREE: - *pDescriptor = *AudioOutput_id_descriptors[2].descriptor; - break; - // SL_DEFAULTDEVICEID_AUDIOOUTPUT? - default: - result = SL_RESULT_IO_ERROR; - break; - } - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IAudioIODeviceCapabilities_RegisterAvailableAudioOutputsChangedCallback( - SLAudioIODeviceCapabilitiesItf self, slAvailableAudioOutputsChangedCallback callback, - void *pContext) -{ - SL_ENTER_INTERFACE - - IAudioIODeviceCapabilities * thiz = (IAudioIODeviceCapabilities *) self; - interface_lock_exclusive(thiz); - thiz->mAvailableAudioOutputsChangedCallback = callback; - thiz->mAvailableAudioOutputsChangedContext = pContext; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static SLresult IAudioIODeviceCapabilities_RegisterDefaultDeviceIDMapChangedCallback( - SLAudioIODeviceCapabilitiesItf self, slDefaultDeviceIDMapChangedCallback callback, - void *pContext) -{ - SL_ENTER_INTERFACE - - IAudioIODeviceCapabilities * thiz = (IAudioIODeviceCapabilities *) self; - interface_lock_exclusive(thiz); - thiz->mDefaultDeviceIDMapChangedCallback = callback; - thiz->mDefaultDeviceIDMapChangedContext = pContext; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static SLresult IAudioIODeviceCapabilities_GetAssociatedAudioInputs( - SLAudioIODeviceCapabilitiesItf self, SLuint32 deviceID, - SLint32 *pNumAudioInputs, SLuint32 *pAudioInputDeviceIDs) -{ - SL_ENTER_INTERFACE - - if (NULL == pNumAudioInputs) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - // Incomplete - *pNumAudioInputs = 0; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IAudioIODeviceCapabilities_GetAssociatedAudioOutputs( - SLAudioIODeviceCapabilitiesItf self, SLuint32 deviceID, - SLint32 *pNumAudioOutputs, SLuint32 *pAudioOutputDeviceIDs) -{ - SL_ENTER_INTERFACE - - if (NULL == pNumAudioOutputs) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - // Incomplete - *pNumAudioOutputs = 0; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IAudioIODeviceCapabilities_GetDefaultAudioDevices( - SLAudioIODeviceCapabilitiesItf self, SLuint32 defaultDeviceID, - SLint32 *pNumAudioDevices, SLuint32 *pAudioDeviceIDs) -{ - SL_ENTER_INTERFACE - - if (NULL == pNumAudioDevices) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - switch (defaultDeviceID) { - case SL_DEFAULTDEVICEID_AUDIOINPUT: - case SL_DEFAULTDEVICEID_AUDIOOUTPUT: - result = SL_RESULT_SUCCESS; - if (NULL != pAudioDeviceIDs) { - switch (defaultDeviceID) { - case SL_DEFAULTDEVICEID_AUDIOINPUT: - if (1 > *pNumAudioDevices) { - result = SL_RESULT_BUFFER_INSUFFICIENT; - } else { - pAudioDeviceIDs[0] = SL_DEFAULTDEVICEID_AUDIOINPUT; - } - *pNumAudioDevices = 1; - break; - case SL_DEFAULTDEVICEID_AUDIOOUTPUT: - if (2 > *pNumAudioDevices) { - result = SL_RESULT_BUFFER_INSUFFICIENT; - } else { - pAudioDeviceIDs[0] = DEVICE_ID_HEADSET; - pAudioDeviceIDs[1] = DEVICE_ID_HANDSFREE; - // should be capable of returning first item if 1 slot - } - *pNumAudioDevices = 2; - break; - default: - assert(SL_BOOLEAN_FALSE); - *pNumAudioDevices = 0; - break; - } - } - break; - default: - result = SL_RESULT_IO_ERROR; - break; - } - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IAudioIODeviceCapabilities_QuerySampleFormatsSupported( - SLAudioIODeviceCapabilitiesItf self, SLuint32 deviceID, SLmilliHertz samplingRate, - SLint32 *pSampleFormats, SLint32 *pNumOfSampleFormats) -{ - SL_ENTER_INTERFACE - - if (NULL == pNumOfSampleFormats) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - switch (deviceID) { - case SL_DEFAULTDEVICEID_AUDIOINPUT: - case SL_DEFAULTDEVICEID_AUDIOOUTPUT: - result = SL_RESULT_SUCCESS; - // incomplete - switch (samplingRate) { - case SL_SAMPLINGRATE_44_1: - break; - default: - result = SL_RESULT_IO_ERROR; - break; - } - if (NULL != pSampleFormats) { - if (1 > *pNumOfSampleFormats) - result = SL_RESULT_BUFFER_INSUFFICIENT; - // incomplete - pSampleFormats[0] = SL_PCMSAMPLEFORMAT_FIXED_16; - } - *pNumOfSampleFormats = 1; - break; - default: - result = SL_RESULT_IO_ERROR; - break; - } - } - - SL_LEAVE_INTERFACE -} - - -static const struct SLAudioIODeviceCapabilitiesItf_ IAudioIODeviceCapabilities_Itf = { - IAudioIODeviceCapabilities_GetAvailableAudioInputs, - IAudioIODeviceCapabilities_QueryAudioInputCapabilities, - IAudioIODeviceCapabilities_RegisterAvailableAudioInputsChangedCallback, - IAudioIODeviceCapabilities_GetAvailableAudioOutputs, - IAudioIODeviceCapabilities_QueryAudioOutputCapabilities, - IAudioIODeviceCapabilities_RegisterAvailableAudioOutputsChangedCallback, - IAudioIODeviceCapabilities_RegisterDefaultDeviceIDMapChangedCallback, - IAudioIODeviceCapabilities_GetAssociatedAudioInputs, - IAudioIODeviceCapabilities_GetAssociatedAudioOutputs, - IAudioIODeviceCapabilities_GetDefaultAudioDevices, - IAudioIODeviceCapabilities_QuerySampleFormatsSupported -}; - -void IAudioIODeviceCapabilities_init(void *self) -{ - IAudioIODeviceCapabilities *thiz = (IAudioIODeviceCapabilities *) self; - thiz->mItf = &IAudioIODeviceCapabilities_Itf; - thiz->mAvailableAudioInputsChangedCallback = NULL; - thiz->mAvailableAudioInputsChangedContext = NULL; - thiz->mAvailableAudioOutputsChangedCallback = NULL; - thiz->mAvailableAudioOutputsChangedContext = NULL; - thiz->mDefaultDeviceIDMapChangedCallback = NULL; - thiz->mDefaultDeviceIDMapChangedContext = NULL; -} diff --git a/wilhelm/src/itf/IBassBoost.c b/wilhelm/src/itf/IBassBoost.c deleted file mode 100644 index fcf2fc9c..00000000 --- a/wilhelm/src/itf/IBassBoost.c +++ /dev/null @@ -1,217 +0,0 @@ -/* - * 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. - */ - -/* BassBoost implementation */ - -#include "sles_allinclusive.h" -#ifdef ANDROID -#include <audio_effects/effect_bassboost.h> -#endif - -#define BASSBOOST_STRENGTH_MIN 0 -#define BASSBOOST_STRENGTH_MAX 1000 - - -#if defined(ANDROID) -/** - * returns true if this interface is not associated with an initialized BassBoost effect - */ -static inline bool NO_BASSBOOST(IBassBoost* v) { - return (v->mBassBoostEffect == 0); -} -#endif - - -static SLresult IBassBoost_SetEnabled(SLBassBoostItf self, SLboolean enabled) -{ - SL_ENTER_INTERFACE - - IBassBoost *thiz = (IBassBoost *) self; - interface_lock_exclusive(thiz); - thiz->mEnabled = (SLboolean) enabled; -#if !defined(ANDROID) - result = SL_RESULT_SUCCESS; -#else - if (NO_BASSBOOST(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = thiz->mBassBoostEffect->setEnabled((bool) thiz->mEnabled); - result = android_fx_statusToResult(status); - } -#endif - interface_unlock_exclusive(thiz); - - SL_LEAVE_INTERFACE -} - - -static SLresult IBassBoost_IsEnabled(SLBassBoostItf self, SLboolean *pEnabled) -{ - SL_ENTER_INTERFACE - - if (NULL == pEnabled) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IBassBoost *thiz = (IBassBoost *) self; - interface_lock_exclusive(thiz); - SLboolean enabled = thiz->mEnabled; -#if !defined(ANDROID) - *pEnabled = enabled; - result = SL_RESULT_SUCCESS; -#else - if (NO_BASSBOOST(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - *pEnabled = (SLboolean) thiz->mBassBoostEffect->getEnabled(); - result = SL_RESULT_SUCCESS; - } -#endif - interface_unlock_exclusive(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IBassBoost_SetStrength(SLBassBoostItf self, SLpermille strength) -{ - SL_ENTER_INTERFACE - - if ((BASSBOOST_STRENGTH_MIN > strength) || (BASSBOOST_STRENGTH_MAX < strength)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IBassBoost *thiz = (IBassBoost *) self; - interface_lock_exclusive(thiz); -#if !defined(ANDROID) - thiz->mStrength = strength; - result = SL_RESULT_SUCCESS; -#else - if (NO_BASSBOOST(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = - android_bb_setParam(thiz->mBassBoostEffect, BASSBOOST_PARAM_STRENGTH, &strength); - result = android_fx_statusToResult(status); - } -#endif - interface_unlock_exclusive(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IBassBoost_GetRoundedStrength(SLBassBoostItf self, SLpermille *pStrength) -{ - SL_ENTER_INTERFACE - - if (NULL == pStrength) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IBassBoost *thiz = (IBassBoost *) self; - interface_lock_exclusive(thiz); - SLpermille strength = thiz->mStrength;; -#if !defined(ANDROID) - result = SL_RESULT_SUCCESS; -#else - if (NO_BASSBOOST(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = - android_bb_getParam(thiz->mBassBoostEffect, BASSBOOST_PARAM_STRENGTH, &strength); - result = android_fx_statusToResult(status); - } -#endif - interface_unlock_exclusive(thiz); - *pStrength = strength; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IBassBoost_IsStrengthSupported(SLBassBoostItf self, SLboolean *pSupported) -{ - SL_ENTER_INTERFACE - - if (NULL == pSupported) { - result = SL_RESULT_PARAMETER_INVALID; - } else { -#if !defined(ANDROID) - *pSupported = SL_BOOLEAN_TRUE; - result = SL_RESULT_SUCCESS; -#else - IBassBoost *thiz = (IBassBoost *) self; - int32_t supported = 0; - interface_lock_exclusive(thiz); - if (NO_BASSBOOST(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = - android_bb_getParam(thiz->mBassBoostEffect, BASSBOOST_PARAM_STRENGTH_SUPPORTED, - &supported); - result = android_fx_statusToResult(status); - } - interface_unlock_exclusive(thiz); - *pSupported = (SLboolean) (supported != 0); -#endif - } - - SL_LEAVE_INTERFACE -} - - -static const struct SLBassBoostItf_ IBassBoost_Itf = { - IBassBoost_SetEnabled, - IBassBoost_IsEnabled, - IBassBoost_SetStrength, - IBassBoost_GetRoundedStrength, - IBassBoost_IsStrengthSupported -}; - -void IBassBoost_init(void *self) -{ - IBassBoost *thiz = (IBassBoost *) self; - thiz->mItf = &IBassBoost_Itf; - thiz->mEnabled = SL_BOOLEAN_FALSE; - thiz->mStrength = 0; -#if defined(ANDROID) - memset(&thiz->mBassBoostDescriptor, 0, sizeof(effect_descriptor_t)); - // placement new (explicit constructor) - (void) new (&thiz->mBassBoostEffect) android::sp<android::AudioEffect>(); -#endif -} - -void IBassBoost_deinit(void *self) -{ -#if defined(ANDROID) - IBassBoost *thiz = (IBassBoost *) self; - // explicit destructor - thiz->mBassBoostEffect.~sp(); -#endif -} - -bool IBassBoost_Expose(void *self) -{ -#if defined(ANDROID) - IBassBoost *thiz = (IBassBoost *) self; - if (!android_fx_initEffectDescriptor(SL_IID_BASSBOOST, &thiz->mBassBoostDescriptor)) { - SL_LOGE("BassBoost initialization failed."); - return false; - } -#endif - return true; -} diff --git a/wilhelm/src/itf/IBufferQueue.c b/wilhelm/src/itf/IBufferQueue.c deleted file mode 100644 index 95036942..00000000 --- a/wilhelm/src/itf/IBufferQueue.c +++ /dev/null @@ -1,209 +0,0 @@ -/* - * 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. - */ - -/* BufferQueue implementation */ - -#include "sles_allinclusive.h" - - -/** Determine the state of the audio player or audio recorder associated with a buffer queue. - * Note that PLAYSTATE and RECORDSTATE values are equivalent (where PLAYING == RECORDING). - */ - -static SLuint32 getAssociatedState(IBufferQueue *thiz) -{ - SLuint32 state; - switch (InterfaceToObjectID(thiz)) { - case SL_OBJECTID_AUDIOPLAYER: - state = ((CAudioPlayer *) thiz->mThis)->mPlay.mState; - break; - case SL_OBJECTID_AUDIORECORDER: - state = ((CAudioRecorder *) thiz->mThis)->mRecord.mState; - break; - default: - // unreachable, but just in case we will assume it is stopped - assert(SL_BOOLEAN_FALSE); - state = SL_PLAYSTATE_STOPPED; - break; - } - return state; -} - - -SLresult IBufferQueue_Enqueue(SLBufferQueueItf self, const void *pBuffer, SLuint32 size) -{ - SL_ENTER_INTERFACE - //SL_LOGV("IBufferQueue_Enqueue(%p, %p, %u)", self, pBuffer, size); - - // Note that Enqueue while a Clear is pending is equivalent to Enqueue followed by Clear - - if (NULL == pBuffer || 0 == size) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IBufferQueue *thiz = (IBufferQueue *) self; - interface_lock_exclusive(thiz); - BufferHeader *oldRear = thiz->mRear, *newRear; - if ((newRear = oldRear + 1) == &thiz->mArray[thiz->mNumBuffers + 1]) { - newRear = thiz->mArray; - } - if (newRear == thiz->mFront) { - result = SL_RESULT_BUFFER_INSUFFICIENT; - } else { - oldRear->mBuffer = pBuffer; - oldRear->mSize = size; - thiz->mRear = newRear; - ++thiz->mState.count; - result = SL_RESULT_SUCCESS; - } - // set enqueue attribute if state is PLAYING and the first buffer is enqueued - interface_unlock_exclusive_attributes(thiz, ((SL_RESULT_SUCCESS == result) && - (1 == thiz->mState.count) && (SL_PLAYSTATE_PLAYING == getAssociatedState(thiz))) ? - ATTR_BQ_ENQUEUE : ATTR_NONE); - } - SL_LEAVE_INTERFACE -} - - -SLresult IBufferQueue_Clear(SLBufferQueueItf self) -{ - SL_ENTER_INTERFACE - - result = SL_RESULT_SUCCESS; - IBufferQueue *thiz = (IBufferQueue *) self; - interface_lock_exclusive(thiz); - -#ifdef ANDROID - if (SL_OBJECTID_AUDIOPLAYER == InterfaceToObjectID(thiz)) { - CAudioPlayer *audioPlayer = (CAudioPlayer *) thiz->mThis; - // flush associated audio player - result = android_audioPlayer_bufferQueue_onClear(audioPlayer); - if (SL_RESULT_SUCCESS == result) { - thiz->mFront = &thiz->mArray[0]; - thiz->mRear = &thiz->mArray[0]; - thiz->mState.count = 0; - thiz->mState.playIndex = 0; - thiz->mSizeConsumed = 0; - } - } -#endif - -#ifdef USE_OUTPUTMIXEXT - // mixer might be reading from the front buffer, so tread carefully here - // NTH asynchronous cancel instead of blocking until mixer acknowledges - thiz->mClearRequested = SL_BOOLEAN_TRUE; - do { - interface_cond_wait(thiz); - } while (thiz->mClearRequested); -#endif - - interface_unlock_exclusive(thiz); - - SL_LEAVE_INTERFACE -} - - -static SLresult IBufferQueue_GetState(SLBufferQueueItf self, SLBufferQueueState *pState) -{ - SL_ENTER_INTERFACE - - // Note that GetState while a Clear is pending is equivalent to GetState before the Clear - - if (NULL == pState) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IBufferQueue *thiz = (IBufferQueue *) self; - SLBufferQueueState state; - interface_lock_shared(thiz); -#ifdef __cplusplus // FIXME Is this a compiler bug? - state.count = thiz->mState.count; - state.playIndex = thiz->mState.playIndex; -#else - state = thiz->mState; -#endif - interface_unlock_shared(thiz); - *pState = state; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -SLresult IBufferQueue_RegisterCallback(SLBufferQueueItf self, - slBufferQueueCallback callback, void *pContext) -{ - SL_ENTER_INTERFACE - - IBufferQueue *thiz = (IBufferQueue *) self; - interface_lock_exclusive(thiz); - // verify pre-condition that media object is in the SL_PLAYSTATE_STOPPED state - if (SL_PLAYSTATE_STOPPED == getAssociatedState(thiz)) { - thiz->mCallback = callback; - thiz->mContext = pContext; - result = SL_RESULT_SUCCESS; - } else { - result = SL_RESULT_PRECONDITIONS_VIOLATED; - } - interface_unlock_exclusive(thiz); - - SL_LEAVE_INTERFACE -} - - -static const struct SLBufferQueueItf_ IBufferQueue_Itf = { - IBufferQueue_Enqueue, - IBufferQueue_Clear, - IBufferQueue_GetState, - IBufferQueue_RegisterCallback -}; - -void IBufferQueue_init(void *self) -{ - IBufferQueue *thiz = (IBufferQueue *) self; - thiz->mItf = &IBufferQueue_Itf; - thiz->mState.count = 0; - thiz->mState.playIndex = 0; - thiz->mCallback = NULL; - thiz->mContext = NULL; - thiz->mNumBuffers = 0; - thiz->mClearRequested = SL_BOOLEAN_FALSE; - thiz->mArray = NULL; - thiz->mFront = NULL; - thiz->mRear = NULL; -#ifdef ANDROID - thiz->mSizeConsumed = 0; -#endif - BufferHeader *bufferHeader = thiz->mTypical; - unsigned i; - for (i = 0; i < BUFFER_HEADER_TYPICAL+1; ++i, ++bufferHeader) { - bufferHeader->mBuffer = NULL; - bufferHeader->mSize = 0; - } -} - - -/** \brief Interface deinitialization hook called by IObject::Destroy. - * Free the buffer queue, if it was larger than typical. - */ - -void IBufferQueue_deinit(void *self) -{ - IBufferQueue *thiz = (IBufferQueue *) self; - if ((NULL != thiz->mArray) && (thiz->mArray != thiz->mTypical)) { - free(thiz->mArray); - thiz->mArray = NULL; - } -} diff --git a/wilhelm/src/itf/IDeviceVolume.c b/wilhelm/src/itf/IDeviceVolume.c deleted file mode 100644 index bd9f0be9..00000000 --- a/wilhelm/src/itf/IDeviceVolume.c +++ /dev/null @@ -1,126 +0,0 @@ -/* - * 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. - */ - -/* DeviceVolume implementation */ - -#include "sles_allinclusive.h" - - -static SLresult IDeviceVolume_GetVolumeScale(SLDeviceVolumeItf self, SLuint32 deviceID, - SLint32 *pMinValue, SLint32 *pMaxValue, SLboolean *pIsMillibelScale) -{ - SL_ENTER_INTERFACE - - switch (deviceID) { - case SL_DEFAULTDEVICEID_AUDIOINPUT: - case SL_DEFAULTDEVICEID_AUDIOOUTPUT: - case DEVICE_ID_HEADSET: - case DEVICE_ID_HANDSFREE: - if (NULL != pMinValue) - *pMinValue = 0; - if (NULL != pMaxValue) - *pMaxValue = 10; - if (NULL != pIsMillibelScale) - *pIsMillibelScale = SL_BOOLEAN_FALSE; - result = SL_RESULT_SUCCESS; - break; - default: - result = SL_RESULT_PARAMETER_INVALID; - break; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IDeviceVolume_SetVolume(SLDeviceVolumeItf self, SLuint32 deviceID, SLint32 volume) -{ - SL_ENTER_INTERFACE - - switch (deviceID) { - // These are treated same as generic audio output for now - case DEVICE_ID_HEADSET: - case DEVICE_ID_HANDSFREE: - deviceID = SL_DEFAULTDEVICEID_AUDIOOUTPUT; - // fall through - case SL_DEFAULTDEVICEID_AUDIOINPUT: - case SL_DEFAULTDEVICEID_AUDIOOUTPUT: - { - IDeviceVolume *thiz = (IDeviceVolume *) self; - interface_lock_poke(thiz); - thiz->mVolume[~deviceID] = volume; - interface_unlock_poke(thiz); - result = SL_RESULT_SUCCESS; - } - break; - default: - result = SL_RESULT_PARAMETER_INVALID; - break; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IDeviceVolume_GetVolume(SLDeviceVolumeItf self, SLuint32 deviceID, SLint32 *pVolume) -{ - SL_ENTER_INTERFACE - - if (NULL == pVolume) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - switch (deviceID) { - // These are treated same as generic audio output for now - case DEVICE_ID_HEADSET: - case DEVICE_ID_HANDSFREE: - deviceID = SL_DEFAULTDEVICEID_AUDIOOUTPUT; - // fall through - case SL_DEFAULTDEVICEID_AUDIOINPUT: - case SL_DEFAULTDEVICEID_AUDIOOUTPUT: - { - IDeviceVolume *thiz = (IDeviceVolume *) self; - interface_lock_peek(thiz); - SLint32 volume = thiz->mVolume[~deviceID]; - interface_unlock_peek(thiz); - *pVolume = volume; - result = SL_RESULT_SUCCESS; - } - break; - default: - result = SL_RESULT_PARAMETER_INVALID; - break; - } - } - - SL_LEAVE_INTERFACE -} - - -static const struct SLDeviceVolumeItf_ IDeviceVolume_Itf = { - IDeviceVolume_GetVolumeScale, - IDeviceVolume_SetVolume, - IDeviceVolume_GetVolume -}; - -void IDeviceVolume_init(void *self) -{ - IDeviceVolume *thiz = (IDeviceVolume *) self; - thiz->mItf = &IDeviceVolume_Itf; - unsigned i; - for (i = 0; i < MAX_DEVICE; ++i) { - thiz->mVolume[i] = 10; - } -} diff --git a/wilhelm/src/itf/IDynamicInterfaceManagement.c b/wilhelm/src/itf/IDynamicInterfaceManagement.c deleted file mode 100644 index e810c855..00000000 --- a/wilhelm/src/itf/IDynamicInterfaceManagement.c +++ /dev/null @@ -1,470 +0,0 @@ -/* - * 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. - */ - -/* DynamicInterfaceManagement implementation */ - -#include "sles_allinclusive.h" - - -// Called by a worker thread to handle an asynchronous AddInterface. -// Parameter self is the DynamicInterface, and MPH specifies which interface to add. - -static void HandleAdd(void *self, void *ignored, int MPH) -{ - - // validate input parameters - IDynamicInterfaceManagement *thiz = (IDynamicInterfaceManagement *) self; - assert(NULL != thiz); - IObject *thisObject = InterfaceToIObject(thiz); - assert(NULL != thisObject); - assert(0 <= MPH && MPH < MPH_MAX); - const ClassTable *clazz = thisObject->mClass; - assert(NULL != clazz); - int index = clazz->mMPH_to_index[MPH]; - assert(0 <= index && index < (int) clazz->mInterfaceCount); - SLuint8 *interfaceStateP = &thisObject->mInterfaceStates[index]; - SLresult result; - - // check interface state - object_lock_exclusive(thisObject); - SLuint8 state = *interfaceStateP; - switch (state) { - - case INTERFACE_ADDING_1: // normal case - { - // change state to indicate we are now adding the interface - *interfaceStateP = INTERFACE_ADDING_2; - object_unlock_exclusive(thisObject); - - // this section runs with mutex unlocked - const struct iid_vtable *x = &clazz->mInterfaces[index]; - size_t offset = x->mOffset; - void *thisItf = (char *) thisObject + offset; - BoolHook expose = MPH_init_table[MPH].mExpose; - // call the optional expose hook - if ((NULL == expose) || (*expose)(thisItf)) { - result = SL_RESULT_SUCCESS; - } else { - result = SL_RESULT_FEATURE_UNSUPPORTED; - } - - // re-lock mutex to update state - object_lock_exclusive(thisObject); - assert(INTERFACE_ADDING_2 == *interfaceStateP); - if (SL_RESULT_SUCCESS == result) { - ((size_t *) thisItf)[0] ^= ~0; - state = INTERFACE_ADDED; - } else { - state = INTERFACE_INITIALIZED; - } - } - break; - - case INTERFACE_ADDING_1A: // operation was aborted while on work queue - result = SL_RESULT_OPERATION_ABORTED; - state = INTERFACE_INITIALIZED; - break; - - default: // impossible - assert(SL_BOOLEAN_FALSE); - result = SL_RESULT_INTERNAL_ERROR; - break; - - } - - // mutex is locked, update state - *interfaceStateP = state; - - // Make a copy of these, so we can call the callback with mutex unlocked - slDynamicInterfaceManagementCallback callback = thiz->mCallback; - void *context = thiz->mContext; - object_unlock_exclusive(thisObject); - - // Note that the mutex is unlocked during the callback - if (NULL != callback) { - const SLInterfaceID iid = &SL_IID_array[MPH]; // equal but not == to the original IID - (*callback)(&thiz->mItf, context, SL_DYNAMIC_ITF_EVENT_ASYNC_TERMINATION, result, iid); - } - -} - - -static SLresult IDynamicInterfaceManagement_AddInterface(SLDynamicInterfaceManagementItf self, - const SLInterfaceID iid, SLboolean async) -{ - SL_ENTER_INTERFACE - - // validate input parameters - if (NULL == iid) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IDynamicInterfaceManagement *thiz = (IDynamicInterfaceManagement *) self; - IObject *thisObject = InterfaceToIObject(thiz); - const ClassTable *clazz = thisObject->mClass; - int MPH, index; - if ((0 > (MPH = IID_to_MPH(iid))) || - // no need to check for an initialization hook - // (NULL == MPH_init_table[MPH].mInit) || - (0 > (index = clazz->mMPH_to_index[MPH]))) { - result = SL_RESULT_FEATURE_UNSUPPORTED; - } else { - assert(index < (int) clazz->mInterfaceCount); - SLuint8 *interfaceStateP = &thisObject->mInterfaceStates[index]; - - // check interface state - object_lock_exclusive(thisObject); - switch (*interfaceStateP) { - - case INTERFACE_INITIALIZED: // normal case - if (async) { - // Asynchronous: mark operation pending and cancellable - *interfaceStateP = INTERFACE_ADDING_1; - object_unlock_exclusive(thisObject); - - // this section runs with mutex unlocked - result = ThreadPool_add_ppi(&thisObject->mEngine->mThreadPool, HandleAdd, thiz, - NULL, MPH); - if (SL_RESULT_SUCCESS != result) { - // Engine was destroyed during add, or insufficient memory, - // so restore mInterfaceStates state to prior value - object_lock_exclusive(thisObject); - switch (*interfaceStateP) { - case INTERFACE_ADDING_1: // normal - case INTERFACE_ADDING_1A: // operation aborted while mutex unlocked - *interfaceStateP = INTERFACE_INITIALIZED; - break; - default: // unexpected - // leave state alone - break; - } - } - - } else { - // Synchronous: mark operation pending to prevent duplication - *interfaceStateP = INTERFACE_ADDING_2; - object_unlock_exclusive(thisObject); - - // this section runs with mutex unlocked - const struct iid_vtable *x = &clazz->mInterfaces[index]; - size_t offset = x->mOffset; - void *thisItf = (char *) thisObject + offset; - // call the optional expose hook - BoolHook expose = MPH_init_table[MPH].mExpose; - if ((NULL == expose) || (*expose)(thisItf)) { - result = SL_RESULT_SUCCESS; - } else { - result = SL_RESULT_FEATURE_UNSUPPORTED; - } - - // re-lock mutex to update state - object_lock_exclusive(thisObject); - assert(INTERFACE_ADDING_2 == *interfaceStateP); - if (SL_RESULT_SUCCESS == result) { - *interfaceStateP = INTERFACE_ADDED; - } else { - *interfaceStateP = INTERFACE_INITIALIZED; - } - } - - // mutex is still locked - break; - - default: // disallow adding of (partially) initialized interfaces - result = SL_RESULT_PRECONDITIONS_VIOLATED; - break; - - } - - object_unlock_exclusive(thisObject); - - } - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IDynamicInterfaceManagement_RemoveInterface( - SLDynamicInterfaceManagementItf self, const SLInterfaceID iid) -{ - SL_ENTER_INTERFACE - -#if USE_PROFILES & USE_PROFILES_BASE - // validate input parameters - if (NULL == iid) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IDynamicInterfaceManagement *thiz = (IDynamicInterfaceManagement *) self; - IObject *thisObject = InterfaceToIObject(thiz); - const ClassTable *clazz = thisObject->mClass; - int MPH, index; - if ((0 > (MPH = IID_to_MPH(iid))) || - // no need to check for an initialization hook - // (NULL == MPH_init_table[MPH].mInit) || - (0 > (index = clazz->mMPH_to_index[MPH]))) { - result = SL_RESULT_PRECONDITIONS_VIOLATED; - } else { - SLuint8 *interfaceStateP = &thisObject->mInterfaceStates[index]; - - // check interface state - object_lock_exclusive(thisObject); - switch (*interfaceStateP) { - - case INTERFACE_ADDED: // normal cases - case INTERFACE_SUSPENDED: - { - // Compute address of the interface - const struct iid_vtable *x = &clazz->mInterfaces[index]; - size_t offset = x->mOffset; - void *thisItf = (char *) thisObject + offset; - - // Mark operation pending (not necessary; remove is synchronous with mutex locked) - *interfaceStateP = INTERFACE_REMOVING; - - // Check if application ever called Object::GetInterface - unsigned mask = 1 << index; - if (thisObject->mGottenMask & mask) { - thisObject->mGottenMask &= ~mask; - // This trickery invalidates the v-table - ((size_t *) thisItf)[0] ^= ~0; - } - - // The remove hook is called with mutex locked - VoidHook remove = MPH_init_table[MPH].mRemove; - if (NULL != remove) { - (*remove)(thisItf); - } - result = SL_RESULT_SUCCESS; - - assert(INTERFACE_REMOVING == *interfaceStateP); - *interfaceStateP = INTERFACE_INITIALIZED; - } - - // mutex is still locked - break; - - default: - // disallow removal of non-dynamic interfaces, or interfaces which are - // currently being resumed (will not auto-cancel an asynchronous resume) - result = SL_RESULT_PRECONDITIONS_VIOLATED; - break; - - } - - object_unlock_exclusive(thisObject); - } - } -#else - result = SL_RESULT_FEATURE_UNSUPPORTED; -#endif - - SL_LEAVE_INTERFACE -} - - -// Called by a worker thread to handle an asynchronous ResumeInterface. -// Parameter self is the DynamicInterface, and MPH specifies which interface to resume. - -static void HandleResume(void *self, void *ignored, int MPH) -{ - - // validate input parameters - IDynamicInterfaceManagement *thiz = (IDynamicInterfaceManagement *) self; - assert(NULL != thiz); - IObject *thisObject = InterfaceToIObject(thiz); - assert(NULL != thisObject); - assert(0 <= MPH && MPH < MPH_MAX); - const ClassTable *clazz = thisObject->mClass; - assert(NULL != clazz); - int index = clazz->mMPH_to_index[MPH]; - assert(0 <= index && index < (int) clazz->mInterfaceCount); - SLuint8 *interfaceStateP = &thisObject->mInterfaceStates[index]; - SLresult result; - - // check interface state - object_lock_exclusive(thisObject); - SLuint8 state = *interfaceStateP; - switch (state) { - - case INTERFACE_RESUMING_1: // normal case - { - // change state to indicate we are now resuming the interface - *interfaceStateP = INTERFACE_RESUMING_2; - object_unlock_exclusive(thisObject); - - // this section runs with mutex unlocked - const struct iid_vtable *x = &clazz->mInterfaces[index]; - size_t offset = x->mOffset; - void *thisItf = (char *) thisObject + offset; - VoidHook resume = MPH_init_table[MPH].mResume; - if (NULL != resume) { - (*resume)(thisItf); - } - result = SL_RESULT_SUCCESS; - - // re-lock mutex to update state - object_lock_exclusive(thisObject); - assert(INTERFACE_RESUMING_2 == *interfaceStateP); - state = INTERFACE_ADDED; - } - break; - - case INTERFACE_RESUMING_1A: // operation was aborted while on work queue - result = SL_RESULT_OPERATION_ABORTED; - state = INTERFACE_SUSPENDED; - break; - - default: // impossible - assert(SL_BOOLEAN_FALSE); - result = SL_RESULT_INTERNAL_ERROR; - break; - - } - - // mutex is locked, update state - *interfaceStateP = state; - - // Make a copy of these, so we can call the callback with mutex unlocked - slDynamicInterfaceManagementCallback callback = thiz->mCallback; - void *context = thiz->mContext; - object_unlock_exclusive(thisObject); - - // Note that the mutex is unlocked during the callback - if (NULL != callback) { - const SLInterfaceID iid = &SL_IID_array[MPH]; // equal but not == to the original IID - (*callback)(&thiz->mItf, context, SL_DYNAMIC_ITF_EVENT_ASYNC_TERMINATION, result, iid); - } -} - - -static SLresult IDynamicInterfaceManagement_ResumeInterface(SLDynamicInterfaceManagementItf self, - const SLInterfaceID iid, SLboolean async) -{ - SL_ENTER_INTERFACE - - // validate input parameters - if (NULL == iid) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IDynamicInterfaceManagement *thiz = (IDynamicInterfaceManagement *) self; - IObject *thisObject = InterfaceToIObject(thiz); - const ClassTable *clazz = thisObject->mClass; - int MPH, index; - if ((0 > (MPH = IID_to_MPH(iid))) || - // no need to check for an initialization hook - // (NULL == MPH_init_table[MPH].mInit) || - (0 > (index = clazz->mMPH_to_index[MPH]))) { - result = SL_RESULT_PRECONDITIONS_VIOLATED; - } else { - assert(index < (int) clazz->mInterfaceCount); - SLuint8 *interfaceStateP = &thisObject->mInterfaceStates[index]; - - // check interface state - object_lock_exclusive(thisObject); - switch (*interfaceStateP) { - - case INTERFACE_SUSPENDED: // normal case - if (async) { - // Asynchronous: mark operation pending and cancellable - *interfaceStateP = INTERFACE_RESUMING_1; - object_unlock_exclusive(thisObject); - - // this section runs with mutex unlocked - result = ThreadPool_add_ppi(&thisObject->mEngine->mThreadPool, HandleResume, - thiz, NULL, MPH); - if (SL_RESULT_SUCCESS != result) { - // Engine was destroyed during resume, or insufficient memory, - // so restore mInterfaceStates state to prior value - object_lock_exclusive(thisObject); - switch (*interfaceStateP) { - case INTERFACE_RESUMING_1: // normal - case INTERFACE_RESUMING_1A: // operation aborted while mutex unlocked - *interfaceStateP = INTERFACE_SUSPENDED; - break; - default: // unexpected - // leave state alone - break; - } - } - - } else { - // Synchronous: mark operation pending to prevent duplication - *interfaceStateP = INTERFACE_RESUMING_2; - object_unlock_exclusive(thisObject); - - // this section runs with mutex unlocked - const struct iid_vtable *x = &clazz->mInterfaces[index]; - size_t offset = x->mOffset; - void *thisItf = (char *) thiz + offset; - VoidHook resume = MPH_init_table[MPH].mResume; - if (NULL != resume) { - (*resume)(thisItf); - } - result = SL_RESULT_SUCCESS; - - // re-lock mutex to update state - object_lock_exclusive(thisObject); - assert(INTERFACE_RESUMING_2 == *interfaceStateP); - *interfaceStateP = INTERFACE_ADDED; - } - - // mutex is now locked - break; - - default: // disallow resumption of non-suspended interfaces - result = SL_RESULT_PRECONDITIONS_VIOLATED; - break; - } - - object_unlock_exclusive(thisObject); - } - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IDynamicInterfaceManagement_RegisterCallback(SLDynamicInterfaceManagementItf self, - slDynamicInterfaceManagementCallback callback, void *pContext) -{ - SL_ENTER_INTERFACE - - IDynamicInterfaceManagement *thiz = (IDynamicInterfaceManagement *) self; - IObject *thisObject = InterfaceToIObject(thiz); - object_lock_exclusive(thisObject); - thiz->mCallback = callback; - thiz->mContext = pContext; - object_unlock_exclusive(thisObject); - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static const struct SLDynamicInterfaceManagementItf_ IDynamicInterfaceManagement_Itf = { - IDynamicInterfaceManagement_AddInterface, - IDynamicInterfaceManagement_RemoveInterface, - IDynamicInterfaceManagement_ResumeInterface, - IDynamicInterfaceManagement_RegisterCallback -}; - -void IDynamicInterfaceManagement_init(void *self) -{ - IDynamicInterfaceManagement *thiz = (IDynamicInterfaceManagement *) self; - thiz->mItf = &IDynamicInterfaceManagement_Itf; - thiz->mCallback = NULL; - thiz->mContext = NULL; -} diff --git a/wilhelm/src/itf/IDynamicSource.c b/wilhelm/src/itf/IDynamicSource.c deleted file mode 100644 index 8a97e528..00000000 --- a/wilhelm/src/itf/IDynamicSource.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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. - */ - -/* DynamicSource implementation */ - -#include "sles_allinclusive.h" - - -static SLresult IDynamicSource_SetSource(SLDynamicSourceItf self, SLDataSource *pDataSource) -{ - SL_ENTER_INTERFACE - - if (NULL == pDataSource) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IDynamicSource *thiz = (IDynamicSource *) self; -#if 0 - DataLocatorFormat myDataSource; - SLresult result; - result = checkDataSource("pDataSource", pDataSource, &myDataSource, DATALOCATOR_MASK_ALL, - DATAFORMAT_MASK_ALL); - // handle result here -#endif - // need to lock the object, as a change to source can impact most of object - IObject *thisObject = InterfaceToIObject(thiz); - object_lock_exclusive(thisObject); - // a bit of a simplification to say the least! (see Khronos bug 6728) - thiz->mDataSource = pDataSource; - object_unlock_exclusive(thisObject); - result = SL_RESULT_FEATURE_UNSUPPORTED; - } - - SL_LEAVE_INTERFACE -} - - -static const struct SLDynamicSourceItf_ IDynamicSource_Itf = { - IDynamicSource_SetSource -}; - -void IDynamicSource_init(void *self) -{ - IDynamicSource *thiz = (IDynamicSource *) self; - thiz->mItf = &IDynamicSource_Itf; - // mDataSource will be re-initialized later in the containing object constructor - thiz->mDataSource = NULL; -} diff --git a/wilhelm/src/itf/IEffectSend.c b/wilhelm/src/itf/IEffectSend.c deleted file mode 100644 index 9d88efa2..00000000 --- a/wilhelm/src/itf/IEffectSend.c +++ /dev/null @@ -1,331 +0,0 @@ -/* - * 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. - */ - -/* EffectSend implementation */ - -#include "sles_allinclusive.h" - - -/** \brief Maps AUX index to OutputMix interface index */ - -static const unsigned char AUX_to_MPH[AUX_MAX] = { - MPH_ENVIRONMENTALREVERB, - MPH_PRESETREVERB -}; - - -/** \brief This is a private function that validates the effect interface specified by the - * application when it calls EnableEffectSend, IsEnabled, SetSendLevel, or GetSendLevel. - * For the interface to be valid, it has to satisfy these requirements: - * - object is an audio player (MIDI player is not supported yet) - * - audio sink is an output mix - * - interface was exposed at object creation time or by DynamicInterface::AddInterface - * - interface was "gotten" with Object::GetInterface - */ - -static struct EnableLevel *getEnableLevel(IEffectSend *thiz, const void *pAuxEffect) -{ - // Make sure this effect send is on an audio player, not a MIDI player - CAudioPlayer *audioPlayer = (SL_OBJECTID_AUDIOPLAYER == InterfaceToObjectID(thiz)) ? - (CAudioPlayer *) thiz->mThis : NULL; - if (NULL == audioPlayer) { - return NULL; - } - // Get the output mix for this player - COutputMix *outputMix = CAudioPlayer_GetOutputMix(audioPlayer); - unsigned aux; - if (pAuxEffect == &outputMix->mEnvironmentalReverb.mItf) { - aux = AUX_ENVIRONMENTALREVERB; - } else if (pAuxEffect == &outputMix->mPresetReverb.mItf) { - aux = AUX_PRESETREVERB; - } else { - SL_LOGE("EffectSend on unknown aux effect %p", pAuxEffect); - return NULL; - } - assert(aux < AUX_MAX); - // Validate that the application has a valid interface for the effect. The interface must have - // been exposed at object creation time or by DynamicInterface::AddInterface, and it also must - // have been "gotten" with Object::GetInterface. - unsigned MPH = AUX_to_MPH[aux]; - int index = MPH_to_OutputMix[MPH]; - if (0 > index) { - SL_LOGE("EffectSend aux=%u MPH=%u", aux, MPH); - return NULL; - } - unsigned mask = 1 << index; - object_lock_shared(&outputMix->mObject); - SLuint32 state = outputMix->mObject.mInterfaceStates[index]; - mask &= outputMix->mObject.mGottenMask; - object_unlock_shared(&outputMix->mObject); - switch (state) { - case INTERFACE_EXPOSED: - case INTERFACE_ADDED: - case INTERFACE_SUSPENDED: - case INTERFACE_SUSPENDING: - case INTERFACE_RESUMING_1: - case INTERFACE_RESUMING_2: - if (mask) { - return &thiz->mEnableLevels[aux]; - } - SL_LOGE("EffectSend no GetInterface yet"); - break; - default: - SL_LOGE("EffectSend invalid interface state %u", state); - break; - } - return NULL; -} - -#if defined(ANDROID) -/** \brief This is a private function that translates an Android effect framework status code - * to the SL ES result code used in the EnableEffectSend() function of the SLEffectSendItf - * interface. - */ -static SLresult translateEnableFxSendError(android::status_t status) { - switch (status) { - case android::NO_ERROR: - return SL_RESULT_SUCCESS; - case android::INVALID_OPERATION: - case android::BAD_VALUE: - default: - SL_LOGE("EffectSend status %u", status); - return SL_RESULT_RESOURCE_ERROR; - } -} -#endif - - -static SLresult IEffectSend_EnableEffectSend(SLEffectSendItf self, - const void *pAuxEffect, SLboolean enable, SLmillibel initialLevel) -{ - SL_ENTER_INTERFACE - - //if (!((SL_MILLIBEL_MIN <= initialLevel) && (initialLevel <= 0))) { - // comparison (SL_MILLIBEL_MIN <= initialLevel) is always true due to range of SLmillibel - if (!(initialLevel <= 0)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEffectSend *thiz = (IEffectSend *) self; - struct EnableLevel *enableLevel = getEnableLevel(thiz, pAuxEffect); - if (NULL == enableLevel) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - interface_lock_exclusive(thiz); - enableLevel->mEnable = SL_BOOLEAN_FALSE != enable; // normalize - enableLevel->mSendLevel = initialLevel; -#if !defined(ANDROID) - result = SL_RESULT_SUCCESS; -#else - // TODO do not repeat querying of CAudioPlayer, done inside getEnableLevel() - CAudioPlayer *ap = (SL_OBJECTID_AUDIOPLAYER == InterfaceToObjectID(thiz)) ? - (CAudioPlayer *) thiz->mThis : NULL; - // note that if this was a MIDI player, getEnableLevel would have returned NULL - assert(NULL != ap); - // check which effect the send is attached to, attach and set level - COutputMix *outputMix = CAudioPlayer_GetOutputMix(ap); - // the initial send level set here is the total energy on the aux bus, - // so it must take into account the player volume level - if (pAuxEffect == &outputMix->mPresetReverb.mItf) { - result = translateEnableFxSendError(android_fxSend_attach(ap, (bool) enable, - outputMix->mPresetReverb.mPresetReverbEffect, - initialLevel + ap->mVolume.mLevel)); - } else if (pAuxEffect == &outputMix->mEnvironmentalReverb.mItf) { - result = translateEnableFxSendError(android_fxSend_attach(ap, (bool) enable, - outputMix->mEnvironmentalReverb.mEnvironmentalReverbEffect, - initialLevel + ap->mVolume.mLevel)); - } else { - SL_LOGE("EffectSend unknown aux effect %p", pAuxEffect); - result = SL_RESULT_PARAMETER_INVALID; - } -#endif - interface_unlock_exclusive(thiz); - } - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEffectSend_IsEnabled(SLEffectSendItf self, - const void *pAuxEffect, SLboolean *pEnable) -{ - SL_ENTER_INTERFACE - - if (NULL == pEnable) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEffectSend *thiz = (IEffectSend *) self; - struct EnableLevel *enableLevel = getEnableLevel(thiz, pAuxEffect); - if (NULL == enableLevel) { - *pEnable = SL_BOOLEAN_FALSE; - result = SL_RESULT_PARAMETER_INVALID; - } else { - interface_lock_shared(thiz); - SLboolean enable = enableLevel->mEnable; - interface_unlock_shared(thiz); - *pEnable = enable; - result = SL_RESULT_SUCCESS; - } - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEffectSend_SetDirectLevel(SLEffectSendItf self, SLmillibel directLevel) -{ - SL_ENTER_INTERFACE - - //if (!((SL_MILLIBEL_MIN <= directLevel) && (directLevel <= 0))) { - // comparison (SL_MILLIBEL_MIN <= directLevel) is always true due to range of SLmillibel - if (!(directLevel <= 0)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEffectSend *thiz = (IEffectSend *) self; - interface_lock_exclusive(thiz); - CAudioPlayer *ap = (SL_OBJECTID_AUDIOPLAYER == InterfaceToObjectID(thiz)) ? - (CAudioPlayer *) thiz->mThis : NULL; - if (NULL != ap) { - SLmillibel oldDirectLevel = ap->mDirectLevel; - if (oldDirectLevel != directLevel) { - ap->mDirectLevel = directLevel; -#if defined(ANDROID) - ap->mAmplFromDirectLevel = sles_to_android_amplification(directLevel); - interface_unlock_exclusive_attributes(thiz, ATTR_GAIN); -#else - interface_unlock_exclusive(thiz); -#endif - } else { - interface_unlock_exclusive(thiz); - } - } else { - // MIDI player is silently not supported - interface_unlock_exclusive(thiz); - } - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEffectSend_GetDirectLevel(SLEffectSendItf self, SLmillibel *pDirectLevel) -{ - SL_ENTER_INTERFACE - - if (NULL == pDirectLevel) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEffectSend *thiz = (IEffectSend *) self; - interface_lock_shared(thiz); - CAudioPlayer *ap = (SL_OBJECTID_AUDIOPLAYER == InterfaceToObjectID(thiz)) ? - (CAudioPlayer *) thiz->mThis : NULL; - if (NULL != ap) { - *pDirectLevel = ap->mDirectLevel; - } else { - // MIDI player is silently not supported - *pDirectLevel = 0; - } - interface_unlock_shared(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEffectSend_SetSendLevel(SLEffectSendItf self, const void *pAuxEffect, - SLmillibel sendLevel) -{ - SL_ENTER_INTERFACE - - //if (!((SL_MILLIBEL_MIN <= sendLevel) && (sendLevel <= 0))) { - // comparison (SL_MILLIBEL_MIN <= sendLevel) is always true due to range of SLmillibel - if (!(sendLevel <= 0)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEffectSend *thiz = (IEffectSend *) self; - struct EnableLevel *enableLevel = getEnableLevel(thiz, pAuxEffect); - if (NULL == enableLevel) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - result = SL_RESULT_SUCCESS; - // EnableEffectSend is exclusive, so this has to be also - interface_lock_exclusive(thiz); - enableLevel->mSendLevel = sendLevel; -#if defined(ANDROID) - CAudioPlayer *ap = (SL_OBJECTID_AUDIOPLAYER == InterfaceToObjectID(thiz)) ? - (CAudioPlayer *) thiz->mThis : NULL; - if (NULL != ap) { - // the send level set here is the total energy on the aux bus, so it must take - // into account the player volume level - result = android_fxSend_setSendLevel(ap, sendLevel + ap->mVolume.mLevel); - } -#endif - interface_unlock_exclusive(thiz); - - } - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEffectSend_GetSendLevel(SLEffectSendItf self, const void *pAuxEffect, - SLmillibel *pSendLevel) -{ - SL_ENTER_INTERFACE - - if (NULL == pSendLevel) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEffectSend *thiz = (IEffectSend *) self; - struct EnableLevel *enableLevel = getEnableLevel(thiz, pAuxEffect); - if (NULL == enableLevel) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - interface_lock_shared(thiz); - SLmillibel sendLevel = enableLevel->mSendLevel; - interface_unlock_shared(thiz); - *pSendLevel = sendLevel; - result = SL_RESULT_SUCCESS; - } - } - - SL_LEAVE_INTERFACE -} - - -static const struct SLEffectSendItf_ IEffectSend_Itf = { - IEffectSend_EnableEffectSend, - IEffectSend_IsEnabled, - IEffectSend_SetDirectLevel, - IEffectSend_GetDirectLevel, - IEffectSend_SetSendLevel, - IEffectSend_GetSendLevel -}; - -void IEffectSend_init(void *self) -{ - IEffectSend *thiz = (IEffectSend *) self; - thiz->mItf = &IEffectSend_Itf; - struct EnableLevel *enableLevel = thiz->mEnableLevels; - unsigned aux; - for (aux = 0; aux < AUX_MAX; ++aux, ++enableLevel) { - enableLevel->mEnable = SL_BOOLEAN_FALSE; - enableLevel->mSendLevel = SL_MILLIBEL_MIN; - } -} diff --git a/wilhelm/src/itf/IEngine.c b/wilhelm/src/itf/IEngine.c deleted file mode 100644 index 4b6d2b68..00000000 --- a/wilhelm/src/itf/IEngine.c +++ /dev/null @@ -1,1439 +0,0 @@ -/* - * 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. - */ - -/* Engine implementation */ - -#include "sles_allinclusive.h" - - -/* Utility functions */ - -static SLresult initializeBufferQueueMembers(CAudioPlayer *ap) { - // inline allocation of circular mArray, up to a typical max - if (BUFFER_HEADER_TYPICAL >= ap->mBufferQueue.mNumBuffers) { - ap->mBufferQueue.mArray = ap->mBufferQueue.mTypical; - } else { - // Avoid possible integer overflow during multiplication; this arbitrary - // maximum is big enough to not interfere with real applications, but - // small enough to not overflow. - if (ap->mBufferQueue.mNumBuffers >= 256) { - return SL_RESULT_MEMORY_FAILURE; - } - ap->mBufferQueue.mArray = (BufferHeader *) - malloc((ap->mBufferQueue.mNumBuffers + 1) * sizeof(BufferHeader)); - if (NULL == ap->mBufferQueue.mArray) { - return SL_RESULT_MEMORY_FAILURE; - } - } - ap->mBufferQueue.mFront = ap->mBufferQueue.mArray; - ap->mBufferQueue.mRear = ap->mBufferQueue.mArray; - return SL_RESULT_SUCCESS; -} - -#ifdef ANDROID -static SLresult initializeAndroidBufferQueueMembers(CAudioPlayer *ap) { - // Avoid possible integer overflow during multiplication; this arbitrary - // maximum is big enough to not interfere with real applications, but - // small enough to not overflow. - if (ap->mAndroidBufferQueue.mNumBuffers >= 256) { - return SL_RESULT_MEMORY_FAILURE; - } - ap->mAndroidBufferQueue.mBufferArray = (AdvancedBufferHeader *) - malloc( (ap->mAndroidBufferQueue.mNumBuffers + 1) * sizeof(AdvancedBufferHeader)); - if (NULL == ap->mAndroidBufferQueue.mBufferArray) { - return SL_RESULT_MEMORY_FAILURE; - } else { - - // initialize ABQ buffer type - // assert below has been checked in android_audioPlayer_checkSourceSink - assert(SL_DATAFORMAT_MIME == ap->mDataSource.mFormat.mFormatType); - switch(ap->mDataSource.mFormat.mMIME.containerType) { - case SL_CONTAINERTYPE_MPEG_TS: - ap->mAndroidBufferQueue.mBufferType = kAndroidBufferTypeMpeg2Ts; - break; - case SL_CONTAINERTYPE_AAC: - case SL_CONTAINERTYPE_RAW: { - const char* mime = (char*)ap->mDataSource.mFormat.mMIME.mimeType; - if ((mime != NULL) && !(strcasecmp(mime, (const char *)SL_ANDROID_MIME_AACADTS) && - strcasecmp(mime, ANDROID_MIME_AACADTS_ANDROID_FRAMEWORK))) { - ap->mAndroidBufferQueue.mBufferType = kAndroidBufferTypeAacadts; - } else { - ap->mAndroidBufferQueue.mBufferType = kAndroidBufferTypeInvalid; - SL_LOGE("CreateAudioPlayer: Invalid buffer type in Android Buffer Queue"); - return SL_RESULT_CONTENT_UNSUPPORTED; - } - } break; - default: - ap->mAndroidBufferQueue.mBufferType = kAndroidBufferTypeInvalid; - SL_LOGE("CreateAudioPlayer: Invalid buffer type in Android Buffer Queue"); - return SL_RESULT_CONTENT_UNSUPPORTED; - } - - ap->mAndroidBufferQueue.mFront = ap->mAndroidBufferQueue.mBufferArray; - ap->mAndroidBufferQueue.mRear = ap->mAndroidBufferQueue.mBufferArray; - } - - return SL_RESULT_SUCCESS; -} -#endif - - -static SLresult IEngine_CreateLEDDevice(SLEngineItf self, SLObjectItf *pDevice, SLuint32 deviceID, - SLuint32 numInterfaces, const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired) -{ - SL_ENTER_INTERFACE - -#if USE_PROFILES & USE_PROFILES_OPTIONAL - if ((NULL == pDevice) || (SL_DEFAULTDEVICEID_LED != deviceID)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - *pDevice = NULL; - unsigned exposedMask; - const ClassTable *pCLEDDevice_class = objectIDtoClass(SL_OBJECTID_LEDDEVICE); - if (NULL == pCLEDDevice_class) { - result = SL_RESULT_FEATURE_UNSUPPORTED; - } else { - result = checkInterfaces(pCLEDDevice_class, numInterfaces, pInterfaceIds, - pInterfaceRequired, &exposedMask, NULL); - } - if (SL_RESULT_SUCCESS == result) { - CLEDDevice *thiz = (CLEDDevice *) construct(pCLEDDevice_class, exposedMask, self); - if (NULL == thiz) { - result = SL_RESULT_MEMORY_FAILURE; - } else { - thiz->mDeviceID = deviceID; - IObject_Publish(&thiz->mObject); - // return the new LED object - *pDevice = &thiz->mObject.mItf; - } - } - } -#else - result = SL_RESULT_FEATURE_UNSUPPORTED; -#endif - - SL_LEAVE_INTERFACE -} - - -static SLresult IEngine_CreateVibraDevice(SLEngineItf self, SLObjectItf *pDevice, SLuint32 deviceID, - SLuint32 numInterfaces, const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired) -{ - SL_ENTER_INTERFACE - -#if USE_PROFILES & USE_PROFILES_OPTIONAL - if ((NULL == pDevice) || (SL_DEFAULTDEVICEID_VIBRA != deviceID)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - *pDevice = NULL; - unsigned exposedMask; - const ClassTable *pCVibraDevice_class = objectIDtoClass(SL_OBJECTID_VIBRADEVICE); - if (NULL == pCVibraDevice_class) { - result = SL_RESULT_FEATURE_UNSUPPORTED; - } else { - result = checkInterfaces(pCVibraDevice_class, numInterfaces, - pInterfaceIds, pInterfaceRequired, &exposedMask, NULL); - } - if (SL_RESULT_SUCCESS == result) { - CVibraDevice *thiz = (CVibraDevice *) construct(pCVibraDevice_class, exposedMask, self); - if (NULL == thiz) { - result = SL_RESULT_MEMORY_FAILURE; - } else { - thiz->mDeviceID = deviceID; - IObject_Publish(&thiz->mObject); - // return the new vibra object - *pDevice = &thiz->mObject.mItf; - } - } - } -#else - result = SL_RESULT_FEATURE_UNSUPPORTED; -#endif - - SL_LEAVE_INTERFACE -} - - -static SLresult IEngine_CreateAudioPlayer(SLEngineItf self, SLObjectItf *pPlayer, - SLDataSource *pAudioSrc, SLDataSink *pAudioSnk, SLuint32 numInterfaces, - const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired) -{ - SL_ENTER_INTERFACE - - if (NULL == pPlayer) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - *pPlayer = NULL; - unsigned exposedMask, requiredMask; - const ClassTable *pCAudioPlayer_class = objectIDtoClass(SL_OBJECTID_AUDIOPLAYER); - assert(NULL != pCAudioPlayer_class); - result = checkInterfaces(pCAudioPlayer_class, numInterfaces, - pInterfaceIds, pInterfaceRequired, &exposedMask, &requiredMask); - if (SL_RESULT_SUCCESS == result) { - - // Construct our new AudioPlayer instance - CAudioPlayer *thiz = (CAudioPlayer *) construct(pCAudioPlayer_class, exposedMask, self); - if (NULL == thiz) { - result = SL_RESULT_MEMORY_FAILURE; - } else { - - do { - - // Initialize private fields not associated with an interface - - // Default data source in case of failure in checkDataSource - thiz->mDataSource.mLocator.mLocatorType = SL_DATALOCATOR_NULL; - thiz->mDataSource.mFormat.mFormatType = SL_DATAFORMAT_NULL; - - // Default data sink in case of failure in checkDataSink - thiz->mDataSink.mLocator.mLocatorType = SL_DATALOCATOR_NULL; - thiz->mDataSink.mFormat.mFormatType = SL_DATAFORMAT_NULL; - - // Default is no per-channel mute or solo - thiz->mMuteMask = 0; - thiz->mSoloMask = 0; - - // Will be set soon for PCM buffer queues, or later by platform-specific code - // during Realize or Prefetch - thiz->mNumChannels = UNKNOWN_NUMCHANNELS; - thiz->mSampleRateMilliHz = UNKNOWN_SAMPLERATE; - - // More default values, in case destructor needs to be called early - thiz->mDirectLevel = 0; // no attenuation -#ifdef USE_OUTPUTMIXEXT - thiz->mTrack = NULL; - thiz->mGains[0] = 1.0f; - thiz->mGains[1] = 1.0f; - thiz->mDestroyRequested = SL_BOOLEAN_FALSE; -#endif -#ifdef USE_SNDFILE - thiz->mSndFile.mPathname = NULL; - thiz->mSndFile.mSNDFILE = NULL; - memset(&thiz->mSndFile.mSfInfo, 0, sizeof(SF_INFO)); - memset(&thiz->mSndFile.mMutex, 0, sizeof(pthread_mutex_t)); - thiz->mSndFile.mEOF = SL_BOOLEAN_FALSE; - thiz->mSndFile.mWhich = 0; - memset(thiz->mSndFile.mBuffer, 0, sizeof(thiz->mSndFile.mBuffer)); -#endif -#ifdef ANDROID - // placement new (explicit constructor) - // FIXME unnecessary once those fields are encapsulated in one class, rather - // than a structure - (void) new (&thiz->mAudioTrack) android::sp<android::AudioTrack>(); - (void) new (&thiz->mCallbackProtector) - android::sp<android::CallbackProtector>(); - (void) new (&thiz->mAuxEffect) android::sp<android::AudioEffect>(); - (void) new (&thiz->mAPlayer) android::sp<android::GenericPlayer>(); - // Android-specific POD fields are initialized in android_audioPlayer_create, - // and assume calloc or memset 0 during allocation -#endif - - // Check the source and sink parameters against generic constraints, - // and make a local copy of all parameters in case other application threads - // change memory concurrently. - - result = checkDataSource("pAudioSrc", pAudioSrc, &thiz->mDataSource, - DATALOCATOR_MASK_URI | DATALOCATOR_MASK_ADDRESS | - DATALOCATOR_MASK_BUFFERQUEUE -#ifdef ANDROID - | DATALOCATOR_MASK_ANDROIDFD | DATALOCATOR_MASK_ANDROIDSIMPLEBUFFERQUEUE - | DATALOCATOR_MASK_ANDROIDBUFFERQUEUE -#endif - , DATAFORMAT_MASK_MIME | DATAFORMAT_MASK_PCM); - - if (SL_RESULT_SUCCESS != result) { - break; - } - - result = checkDataSink("pAudioSnk", pAudioSnk, &thiz->mDataSink, - DATALOCATOR_MASK_OUTPUTMIX // for playback -#ifdef ANDROID - | DATALOCATOR_MASK_ANDROIDSIMPLEBUFFERQUEUE // for decode to a BQ - | DATALOCATOR_MASK_BUFFERQUEUE // for decode to a BQ -#endif - , DATAFORMAT_MASK_NULL -#ifdef ANDROID - | DATAFORMAT_MASK_PCM // for decode to PCM -#endif - ); - if (SL_RESULT_SUCCESS != result) { - break; - } - - // It would be unsafe to ever refer to the application pointers again - pAudioSrc = NULL; - pAudioSnk = NULL; - - // Check that the requested interfaces are compatible with data source and sink - result = checkSourceSinkVsInterfacesCompatibility(&thiz->mDataSource, - &thiz->mDataSink, pCAudioPlayer_class, requiredMask); - if (SL_RESULT_SUCCESS != result) { - break; - } - - // copy the buffer queue count from source locator (for playback) / from the - // sink locator (for decode on ANDROID build) to the buffer queue interface - // we have already range-checked the value down to a smaller width - SLuint16 nbBuffers = 0; - bool usesAdvancedBufferHeaders = false; - bool usesSimpleBufferQueue = false; - // creating an AudioPlayer which decodes AAC ADTS buffers to a PCM buffer queue - // will cause usesAdvancedBufferHeaders and usesSimpleBufferQueue to be true - switch (thiz->mDataSource.mLocator.mLocatorType) { - case SL_DATALOCATOR_BUFFERQUEUE: -#ifdef ANDROID - case SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE: -#endif - usesSimpleBufferQueue = true; - nbBuffers = (SLuint16) thiz->mDataSource.mLocator.mBufferQueue.numBuffers; - assert(SL_DATAFORMAT_PCM == thiz->mDataSource.mFormat.mFormatType); - thiz->mNumChannels = thiz->mDataSource.mFormat.mPCM.numChannels; - thiz->mSampleRateMilliHz = thiz->mDataSource.mFormat.mPCM.samplesPerSec; - break; -#ifdef ANDROID - case SL_DATALOCATOR_ANDROIDBUFFERQUEUE: - usesAdvancedBufferHeaders = true; - nbBuffers = (SLuint16) thiz->mDataSource.mLocator.mABQ.numBuffers; - thiz->mAndroidBufferQueue.mNumBuffers = nbBuffers; - break; -#endif - default: - nbBuffers = 0; - break; - } -#ifdef ANDROID - switch(thiz->mDataSink.mLocator.mLocatorType) { - case SL_DATALOCATOR_BUFFERQUEUE: - case SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE: - usesSimpleBufferQueue = true; - nbBuffers = thiz->mDataSink.mLocator.mBufferQueue.numBuffers; - assert(SL_DATAFORMAT_PCM == thiz->mDataSink.mFormat.mFormatType); - // FIXME The values specified by the app are meaningless. We get the - // real values from the decoder. But the data sink checks currently require - // that the app specify these useless values. Needs doc/fix. - // Instead use the "unknown" values, as needed by prepare completion. - // thiz->mNumChannels = thiz->mDataSink.mFormat.mPCM.numChannels; - // thiz->mSampleRateMilliHz = thiz->mDataSink.mFormat.mPCM.samplesPerSec; - thiz->mNumChannels = UNKNOWN_NUMCHANNELS; - thiz->mSampleRateMilliHz = UNKNOWN_SAMPLERATE; - break; - default: - // leave nbBuffers unchanged - break; - } -#endif - thiz->mBufferQueue.mNumBuffers = nbBuffers; - - // check the audio source and sink parameters against platform support -#ifdef ANDROID - result = android_audioPlayer_checkSourceSink(thiz); - if (SL_RESULT_SUCCESS != result) { - break; - } -#endif - -#ifdef USE_SNDFILE - result = SndFile_checkAudioPlayerSourceSink(thiz); - if (SL_RESULT_SUCCESS != result) { - break; - } -#endif - -#ifdef USE_OUTPUTMIXEXT - result = IOutputMixExt_checkAudioPlayerSourceSink(thiz); - if (SL_RESULT_SUCCESS != result) { - break; - } -#endif - - // Allocate memory for buffer queue - if (usesAdvancedBufferHeaders) { -#ifdef ANDROID - // locator is SL_DATALOCATOR_ANDROIDBUFFERQUEUE - result = initializeAndroidBufferQueueMembers(thiz); -#else - assert(false); -#endif - } - - if (usesSimpleBufferQueue) { - // locator is SL_DATALOCATOR_BUFFERQUEUE - // or SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE - result = initializeBufferQueueMembers(thiz); - } - - // used to store the data source of our audio player - thiz->mDynamicSource.mDataSource = &thiz->mDataSource.u.mSource; - - // platform-specific initialization -#ifdef ANDROID - android_audioPlayer_create(thiz); -#endif - - } while (0); - - if (SL_RESULT_SUCCESS != result) { - IObject_Destroy(&thiz->mObject.mItf); - } else { - IObject_Publish(&thiz->mObject); - // return the new audio player object - *pPlayer = &thiz->mObject.mItf; - } - - } - } - - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEngine_CreateAudioRecorder(SLEngineItf self, SLObjectItf *pRecorder, - SLDataSource *pAudioSrc, SLDataSink *pAudioSnk, SLuint32 numInterfaces, - const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired) -{ - SL_ENTER_INTERFACE - -#if (USE_PROFILES & USE_PROFILES_OPTIONAL) || defined(ANDROID) - if (NULL == pRecorder) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - *pRecorder = NULL; - unsigned exposedMask; - const ClassTable *pCAudioRecorder_class = objectIDtoClass(SL_OBJECTID_AUDIORECORDER); - if (NULL == pCAudioRecorder_class) { - result = SL_RESULT_FEATURE_UNSUPPORTED; - } else { - result = checkInterfaces(pCAudioRecorder_class, numInterfaces, - pInterfaceIds, pInterfaceRequired, &exposedMask, NULL); - } - - if (SL_RESULT_SUCCESS == result) { - - // Construct our new AudioRecorder instance - CAudioRecorder *thiz = (CAudioRecorder *) construct(pCAudioRecorder_class, exposedMask, - self); - if (NULL == thiz) { - result = SL_RESULT_MEMORY_FAILURE; - } else { - - do { - - // Initialize fields not associated with any interface - - // Default data source in case of failure in checkDataSource - thiz->mDataSource.mLocator.mLocatorType = SL_DATALOCATOR_NULL; - thiz->mDataSource.mFormat.mFormatType = SL_DATAFORMAT_NULL; - - // Default data sink in case of failure in checkDataSink - thiz->mDataSink.mLocator.mLocatorType = SL_DATALOCATOR_NULL; - thiz->mDataSink.mFormat.mFormatType = SL_DATAFORMAT_NULL; - - // These fields are set to real values by - // android_audioRecorder_checkSourceSinkSupport. Note that the data sink is - // always PCM buffer queue, so we know the channel count and sample rate early. - thiz->mNumChannels = UNKNOWN_NUMCHANNELS; - thiz->mSampleRateMilliHz = UNKNOWN_SAMPLERATE; -#ifdef ANDROID - thiz->mAudioRecord = NULL; - thiz->mRecordSource = AUDIO_SOURCE_DEFAULT; -#endif - - // Check the source and sink parameters, and make a local copy of all parameters - result = checkDataSource("pAudioSrc", pAudioSrc, &thiz->mDataSource, - DATALOCATOR_MASK_IODEVICE, DATAFORMAT_MASK_NULL); - if (SL_RESULT_SUCCESS != result) { - break; - } - result = checkDataSink("pAudioSnk", pAudioSnk, &thiz->mDataSink, - DATALOCATOR_MASK_URI -#ifdef ANDROID - | DATALOCATOR_MASK_ANDROIDSIMPLEBUFFERQUEUE -#endif - , DATAFORMAT_MASK_MIME | DATAFORMAT_MASK_PCM - ); - if (SL_RESULT_SUCCESS != result) { - break; - } - - // It would be unsafe to ever refer to the application pointers again - pAudioSrc = NULL; - pAudioSnk = NULL; - - // check the audio source and sink parameters against platform support -#ifdef ANDROID - result = android_audioRecorder_checkSourceSinkSupport(thiz); - if (SL_RESULT_SUCCESS != result) { - SL_LOGE("Cannot create AudioRecorder: invalid source or sink"); - break; - } -#endif - -#ifdef ANDROID - // Allocate memory for buffer queue - SLuint32 locatorType = thiz->mDataSink.mLocator.mLocatorType; - if (locatorType == SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE) { - thiz->mBufferQueue.mNumBuffers = - thiz->mDataSink.mLocator.mBufferQueue.numBuffers; - // inline allocation of circular Buffer Queue mArray, up to a typical max - if (BUFFER_HEADER_TYPICAL >= thiz->mBufferQueue.mNumBuffers) { - thiz->mBufferQueue.mArray = thiz->mBufferQueue.mTypical; - } else { - // Avoid possible integer overflow during multiplication; this arbitrary - // maximum is big enough to not interfere with real applications, but - // small enough to not overflow. - if (thiz->mBufferQueue.mNumBuffers >= 256) { - result = SL_RESULT_MEMORY_FAILURE; - break; - } - thiz->mBufferQueue.mArray = (BufferHeader *) malloc((thiz->mBufferQueue. - mNumBuffers + 1) * sizeof(BufferHeader)); - if (NULL == thiz->mBufferQueue.mArray) { - result = SL_RESULT_MEMORY_FAILURE; - break; - } - } - thiz->mBufferQueue.mFront = thiz->mBufferQueue.mArray; - thiz->mBufferQueue.mRear = thiz->mBufferQueue.mArray; - } -#endif - - // platform-specific initialization -#ifdef ANDROID - android_audioRecorder_create(thiz); -#endif - - } while (0); - - if (SL_RESULT_SUCCESS != result) { - IObject_Destroy(&thiz->mObject.mItf); - } else { - IObject_Publish(&thiz->mObject); - // return the new audio recorder object - *pRecorder = &thiz->mObject.mItf; - } - } - - } - - } -#else - result = SL_RESULT_FEATURE_UNSUPPORTED; -#endif - - SL_LEAVE_INTERFACE -} - - -static SLresult IEngine_CreateMidiPlayer(SLEngineItf self, SLObjectItf *pPlayer, - SLDataSource *pMIDISrc, SLDataSource *pBankSrc, SLDataSink *pAudioOutput, - SLDataSink *pVibra, SLDataSink *pLEDArray, SLuint32 numInterfaces, - const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired) -{ - SL_ENTER_INTERFACE - -#if USE_PROFILES & (USE_PROFILES_GAME | USE_PROFILES_PHONE) - if ((NULL == pPlayer) || (NULL == pMIDISrc) || (NULL == pAudioOutput)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - *pPlayer = NULL; - unsigned exposedMask; - const ClassTable *pCMidiPlayer_class = objectIDtoClass(SL_OBJECTID_MIDIPLAYER); - if (NULL == pCMidiPlayer_class) { - result = SL_RESULT_FEATURE_UNSUPPORTED; - } else { - result = checkInterfaces(pCMidiPlayer_class, numInterfaces, - pInterfaceIds, pInterfaceRequired, &exposedMask, NULL); - } - if (SL_RESULT_SUCCESS == result) { - CMidiPlayer *thiz = (CMidiPlayer *) construct(pCMidiPlayer_class, exposedMask, self); - if (NULL == thiz) { - result = SL_RESULT_MEMORY_FAILURE; - } else { -#if 0 - "pMIDISrc", pMIDISrc, URI | MIDIBUFFERQUEUE, NONE - "pBankSrc", pBanksrc, NULL | URI | ADDRESS, NULL - "pAudioOutput", pAudioOutput, OUTPUTMIX, NULL - "pVibra", pVibra, NULL | IODEVICE, NULL - "pLEDArray", pLEDArray, NULL | IODEVICE, NULL -#endif - // a fake value - why not use value from IPlay_init? what does CT check for? - thiz->mPlay.mDuration = 0; - IObject_Publish(&thiz->mObject); - // return the new MIDI player object - *pPlayer = &thiz->mObject.mItf; - } - } - } -#else - result = SL_RESULT_FEATURE_UNSUPPORTED; -#endif - - SL_LEAVE_INTERFACE -} - - -static SLresult IEngine_CreateListener(SLEngineItf self, SLObjectItf *pListener, - SLuint32 numInterfaces, const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired) -{ - SL_ENTER_INTERFACE - -#if USE_PROFILES & USE_PROFILES_GAME - if (NULL == pListener) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - *pListener = NULL; - unsigned exposedMask; - const ClassTable *pCListener_class = objectIDtoClass(SL_OBJECTID_LISTENER); - if (NULL == pCListener_class) { - result = SL_RESULT_FEATURE_UNSUPPORTED; - } else { - result = checkInterfaces(pCListener_class, numInterfaces, - pInterfaceIds, pInterfaceRequired, &exposedMask, NULL); - } - if (SL_RESULT_SUCCESS == result) { - CListener *thiz = (CListener *) construct(pCListener_class, exposedMask, self); - if (NULL == thiz) { - result = SL_RESULT_MEMORY_FAILURE; - } else { - IObject_Publish(&thiz->mObject); - // return the new 3D listener object - *pListener = &thiz->mObject.mItf; - } - } - } -#else - result = SL_RESULT_FEATURE_UNSUPPORTED; -#endif - - SL_LEAVE_INTERFACE -} - - -static SLresult IEngine_Create3DGroup(SLEngineItf self, SLObjectItf *pGroup, SLuint32 numInterfaces, - const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired) -{ - SL_ENTER_INTERFACE - -#if USE_PROFILES & USE_PROFILES_GAME - if (NULL == pGroup) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - *pGroup = NULL; - unsigned exposedMask; - const ClassTable *pC3DGroup_class = objectIDtoClass(SL_OBJECTID_3DGROUP); - if (NULL == pC3DGroup_class) { - result = SL_RESULT_FEATURE_UNSUPPORTED; - } else { - result = checkInterfaces(pC3DGroup_class, numInterfaces, - pInterfaceIds, pInterfaceRequired, &exposedMask, NULL); - } - if (SL_RESULT_SUCCESS == result) { - C3DGroup *thiz = (C3DGroup *) construct(pC3DGroup_class, exposedMask, self); - if (NULL == thiz) { - result = SL_RESULT_MEMORY_FAILURE; - } else { - thiz->mMemberMask = 0; - IObject_Publish(&thiz->mObject); - // return the new 3D group object - *pGroup = &thiz->mObject.mItf; - } - } - } -#else - result = SL_RESULT_FEATURE_UNSUPPORTED; -#endif - - SL_LEAVE_INTERFACE -} - - -static SLresult IEngine_CreateOutputMix(SLEngineItf self, SLObjectItf *pMix, SLuint32 numInterfaces, - const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired) -{ - SL_ENTER_INTERFACE - - if (NULL == pMix) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - *pMix = NULL; - unsigned exposedMask; - const ClassTable *pCOutputMix_class = objectIDtoClass(SL_OBJECTID_OUTPUTMIX); - assert(NULL != pCOutputMix_class); - result = checkInterfaces(pCOutputMix_class, numInterfaces, - pInterfaceIds, pInterfaceRequired, &exposedMask, NULL); - if (SL_RESULT_SUCCESS == result) { - COutputMix *thiz = (COutputMix *) construct(pCOutputMix_class, exposedMask, self); - if (NULL == thiz) { - result = SL_RESULT_MEMORY_FAILURE; - } else { -#ifdef ANDROID - android_outputMix_create(thiz); -#endif -#ifdef USE_SDL - IEngine *thisEngine = &thiz->mObject.mEngine->mEngine; - interface_lock_exclusive(thisEngine); - bool unpause = false; - if (NULL == thisEngine->mOutputMix) { - thisEngine->mOutputMix = thiz; - unpause = true; - } - interface_unlock_exclusive(thisEngine); -#endif - IObject_Publish(&thiz->mObject); -#ifdef USE_SDL - if (unpause) { - // Enable SDL_callback to be called periodically by SDL's internal thread - SDL_PauseAudio(0); - } -#endif - // return the new output mix object - *pMix = &thiz->mObject.mItf; - } - } - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEngine_CreateMetadataExtractor(SLEngineItf self, SLObjectItf *pMetadataExtractor, - SLDataSource *pDataSource, SLuint32 numInterfaces, const SLInterfaceID *pInterfaceIds, - const SLboolean *pInterfaceRequired) -{ - SL_ENTER_INTERFACE - -#if USE_PROFILES & (USE_PROFILES_GAME | USE_PROFILES_MUSIC) - if (NULL == pMetadataExtractor) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - *pMetadataExtractor = NULL; - unsigned exposedMask; - const ClassTable *pCMetadataExtractor_class = - objectIDtoClass(SL_OBJECTID_METADATAEXTRACTOR); - if (NULL == pCMetadataExtractor_class) { - result = SL_RESULT_FEATURE_UNSUPPORTED; - } else { - result = checkInterfaces(pCMetadataExtractor_class, numInterfaces, - pInterfaceIds, pInterfaceRequired, &exposedMask, NULL); - } - if (SL_RESULT_SUCCESS == result) { - CMetadataExtractor *thiz = (CMetadataExtractor *) - construct(pCMetadataExtractor_class, exposedMask, self); - if (NULL == thiz) { - result = SL_RESULT_MEMORY_FAILURE; - } else { -#if 0 - "pDataSource", pDataSource, NONE, NONE -#endif - IObject_Publish(&thiz->mObject); - // return the new metadata extractor object - *pMetadataExtractor = &thiz->mObject.mItf; - result = SL_RESULT_SUCCESS; - } - } - } -#else - result = SL_RESULT_FEATURE_UNSUPPORTED; -#endif - - SL_LEAVE_INTERFACE -} - - -static SLresult IEngine_CreateExtensionObject(SLEngineItf self, SLObjectItf *pObject, - void *pParameters, SLuint32 objectID, SLuint32 numInterfaces, - const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired) -{ - SL_ENTER_INTERFACE - - if (NULL == pObject) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - *pObject = NULL; - result = SL_RESULT_FEATURE_UNSUPPORTED; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEngine_QueryNumSupportedInterfaces(SLEngineItf self, - SLuint32 objectID, SLuint32 *pNumSupportedInterfaces) -{ - SL_ENTER_INTERFACE - - if (NULL == pNumSupportedInterfaces) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - const ClassTable *clazz = objectIDtoClass(objectID); - if (NULL == clazz) { - result = SL_RESULT_FEATURE_UNSUPPORTED; - } else { - SLuint32 count = 0; - SLuint32 i; - for (i = 0; i < clazz->mInterfaceCount; ++i) { - switch (clazz->mInterfaces[i].mInterface) { - case INTERFACE_IMPLICIT: - case INTERFACE_IMPLICIT_PREREALIZE: - case INTERFACE_EXPLICIT: - case INTERFACE_EXPLICIT_PREREALIZE: - case INTERFACE_DYNAMIC: - ++count; - break; - case INTERFACE_UNAVAILABLE: - break; - default: - assert(false); - break; - } - } - *pNumSupportedInterfaces = count; - result = SL_RESULT_SUCCESS; - } - } - - SL_LEAVE_INTERFACE; -} - - -static SLresult IEngine_QuerySupportedInterfaces(SLEngineItf self, - SLuint32 objectID, SLuint32 index, SLInterfaceID *pInterfaceId) -{ - SL_ENTER_INTERFACE - - if (NULL == pInterfaceId) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - *pInterfaceId = NULL; - const ClassTable *clazz = objectIDtoClass(objectID); - if (NULL == clazz) { - result = SL_RESULT_FEATURE_UNSUPPORTED; - } else { - result = SL_RESULT_PARAMETER_INVALID; // will be reset later - SLuint32 i; - for (i = 0; i < clazz->mInterfaceCount; ++i) { - switch (clazz->mInterfaces[i].mInterface) { - case INTERFACE_IMPLICIT: - case INTERFACE_IMPLICIT_PREREALIZE: - case INTERFACE_EXPLICIT: - case INTERFACE_EXPLICIT_PREREALIZE: - case INTERFACE_DYNAMIC: - break; - case INTERFACE_UNAVAILABLE: - continue; - default: - assert(false); - break; - } - if (index == 0) { - *pInterfaceId = &SL_IID_array[clazz->mInterfaces[i].mMPH]; - result = SL_RESULT_SUCCESS; - break; - } - --index; - } - } - } - - SL_LEAVE_INTERFACE -}; - - -static const char * const extensionNames[] = { -#ifdef ANDROID -#define _(n) #n -#define __(n) _(n) - "ANDROID_SDK_LEVEL_" __(PLATFORM_SDK_VERSION), -#undef _ -#undef __ -#else - "WILHELM_DESKTOP", -#endif -}; - - -static SLresult IEngine_QueryNumSupportedExtensions(SLEngineItf self, SLuint32 *pNumExtensions) -{ - SL_ENTER_INTERFACE - - if (NULL == pNumExtensions) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - *pNumExtensions = sizeof(extensionNames) / sizeof(extensionNames[0]); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEngine_QuerySupportedExtension(SLEngineItf self, - SLuint32 index, SLchar *pExtensionName, SLint16 *pNameLength) -{ - SL_ENTER_INTERFACE - - if (NULL == pNameLength) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - size_t actualNameLength; - unsigned numExtensions = sizeof(extensionNames) / sizeof(extensionNames[0]); - if (index >= numExtensions) { - actualNameLength = 0; - result = SL_RESULT_PARAMETER_INVALID; - } else { - const char *extensionName = extensionNames[index]; - actualNameLength = strlen(extensionName) + 1; - if (NULL == pExtensionName) { - // application is querying the name length in order to allocate a buffer - result = SL_RESULT_SUCCESS; - } else { - SLint16 availableNameLength = *pNameLength; - if (0 >= availableNameLength) { - // there is not even room for the terminating NUL - result = SL_RESULT_BUFFER_INSUFFICIENT; - } else if (actualNameLength > (size_t) availableNameLength) { - // "no invalid strings are written. That is, the null-terminator always exists" - memcpy(pExtensionName, extensionName, (size_t) availableNameLength - 1); - pExtensionName[(size_t) availableNameLength - 1] = '\0'; - result = SL_RESULT_BUFFER_INSUFFICIENT; - } else { - memcpy(pExtensionName, extensionName, actualNameLength); - result = SL_RESULT_SUCCESS; - } - } - } - *pNameLength = actualNameLength; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEngine_IsExtensionSupported(SLEngineItf self, - const SLchar *pExtensionName, SLboolean *pSupported) -{ - SL_ENTER_INTERFACE - - if (NULL == pSupported) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - SLboolean isSupported = SL_BOOLEAN_FALSE; - if (NULL == pExtensionName) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - unsigned numExtensions = sizeof(extensionNames) / sizeof(extensionNames[0]); - unsigned i; - for (i = 0; i < numExtensions; ++i) { - if (!strcmp((const char *) pExtensionName, extensionNames[i])) { - isSupported = SL_BOOLEAN_TRUE; - break; - } - } - result = SL_RESULT_SUCCESS; - } - *pSupported = isSupported; - } - - SL_LEAVE_INTERFACE -} - - -static const struct SLEngineItf_ IEngine_Itf = { - IEngine_CreateLEDDevice, - IEngine_CreateVibraDevice, - IEngine_CreateAudioPlayer, - IEngine_CreateAudioRecorder, - IEngine_CreateMidiPlayer, - IEngine_CreateListener, - IEngine_Create3DGroup, - IEngine_CreateOutputMix, - IEngine_CreateMetadataExtractor, - IEngine_CreateExtensionObject, - IEngine_QueryNumSupportedInterfaces, - IEngine_QuerySupportedInterfaces, - IEngine_QueryNumSupportedExtensions, - IEngine_QuerySupportedExtension, - IEngine_IsExtensionSupported -}; - -void IEngine_init(void *self) -{ - IEngine *thiz = (IEngine *) self; - thiz->mItf = &IEngine_Itf; - // mLossOfControlGlobal is initialized in slCreateEngine -#ifdef USE_SDL - thiz->mOutputMix = NULL; -#endif - thiz->mInstanceCount = 1; // ourself - thiz->mInstanceMask = 0; - thiz->mChangedMask = 0; - unsigned i; - for (i = 0; i < MAX_INSTANCE; ++i) { - thiz->mInstances[i] = NULL; - } - thiz->mShutdown = SL_BOOLEAN_FALSE; - thiz->mShutdownAck = SL_BOOLEAN_FALSE; -} - -void IEngine_deinit(void *self) -{ -} - - -// OpenMAX AL Engine - - -static XAresult IEngine_CreateCameraDevice(XAEngineItf self, XAObjectItf *pDevice, - XAuint32 deviceID, XAuint32 numInterfaces, const XAInterfaceID *pInterfaceIds, - const XAboolean *pInterfaceRequired) -{ - XA_ENTER_INTERFACE - - //IXAEngine *thiz = (IXAEngine *) self; - result = SL_RESULT_FEATURE_UNSUPPORTED; - - XA_LEAVE_INTERFACE -} - - -static XAresult IEngine_CreateRadioDevice(XAEngineItf self, XAObjectItf *pDevice, - XAuint32 numInterfaces, const XAInterfaceID *pInterfaceIds, - const XAboolean *pInterfaceRequired) -{ - XA_ENTER_INTERFACE - - //IXAEngine *thiz = (IXAEngine *) self; - result = SL_RESULT_FEATURE_UNSUPPORTED; - - XA_LEAVE_INTERFACE -} - - -static XAresult IXAEngine_CreateLEDDevice(XAEngineItf self, XAObjectItf *pDevice, XAuint32 deviceID, - XAuint32 numInterfaces, const XAInterfaceID *pInterfaceIds, - const XAboolean *pInterfaceRequired) -{ - // forward to OpenSL ES - return IEngine_CreateLEDDevice(&((CEngine *) ((IXAEngine *) self)->mThis)->mEngine.mItf, - (SLObjectItf *) pDevice, deviceID, numInterfaces, (const SLInterfaceID *) pInterfaceIds, - (const SLboolean *) pInterfaceRequired); -} - - -static XAresult IXAEngine_CreateVibraDevice(XAEngineItf self, XAObjectItf *pDevice, - XAuint32 deviceID, XAuint32 numInterfaces, const XAInterfaceID *pInterfaceIds, - const XAboolean *pInterfaceRequired) -{ - // forward to OpenSL ES - return IEngine_CreateVibraDevice(&((CEngine *) ((IXAEngine *) self)->mThis)->mEngine.mItf, - (SLObjectItf *) pDevice, deviceID, numInterfaces, (const SLInterfaceID *) pInterfaceIds, - (const SLboolean *) pInterfaceRequired); -} - - -static XAresult IEngine_CreateMediaPlayer(XAEngineItf self, XAObjectItf *pPlayer, - XADataSource *pDataSrc, XADataSource *pBankSrc, XADataSink *pAudioSnk, - XADataSink *pImageVideoSnk, XADataSink *pVibra, XADataSink *pLEDArray, - XAuint32 numInterfaces, const XAInterfaceID *pInterfaceIds, - const XAboolean *pInterfaceRequired) -{ - XA_ENTER_INTERFACE - - if (NULL == pPlayer) { - result = XA_RESULT_PARAMETER_INVALID; - } else { - *pPlayer = NULL; - unsigned exposedMask; - const ClassTable *pCMediaPlayer_class = objectIDtoClass(XA_OBJECTID_MEDIAPLAYER); - assert(NULL != pCMediaPlayer_class); - result = checkInterfaces(pCMediaPlayer_class, numInterfaces, - (const SLInterfaceID *) pInterfaceIds, pInterfaceRequired, &exposedMask, NULL); - if (XA_RESULT_SUCCESS == result) { - - // Construct our new MediaPlayer instance - CMediaPlayer *thiz = (CMediaPlayer *) construct(pCMediaPlayer_class, exposedMask, - &((CEngine *) ((IXAEngine *) self)->mThis)->mEngine.mItf); - if (NULL == thiz) { - result = XA_RESULT_MEMORY_FAILURE; - } else { - - do { - - // Initialize private fields not associated with an interface - - // Default data source in case of failure in checkDataSource - thiz->mDataSource.mLocator.mLocatorType = SL_DATALOCATOR_NULL; - thiz->mDataSource.mFormat.mFormatType = XA_DATAFORMAT_NULL; - - // Default andio and image sink in case of failure in checkDataSink - thiz->mAudioSink.mLocator.mLocatorType = XA_DATALOCATOR_NULL; - thiz->mAudioSink.mFormat.mFormatType = XA_DATAFORMAT_NULL; - thiz->mImageVideoSink.mLocator.mLocatorType = XA_DATALOCATOR_NULL; - thiz->mImageVideoSink.mFormat.mFormatType = XA_DATAFORMAT_NULL; - - // More default values, in case destructor needs to be called early - thiz->mNumChannels = UNKNOWN_NUMCHANNELS; - -#ifdef ANDROID - // placement new (explicit constructor) - // FIXME unnecessary once those fields are encapsulated in one class, rather - // than a structure - (void) new (&thiz->mAVPlayer) android::sp<android::GenericPlayer>(); - (void) new (&thiz->mCallbackProtector) - android::sp<android::CallbackProtector>(); - // Android-specific POD fields are initialized in android_Player_create, - // and assume calloc or memset 0 during allocation -#endif - - // Check the source and sink parameters against generic constraints - - result = checkDataSource("pDataSrc", (const SLDataSource *) pDataSrc, - &thiz->mDataSource, DATALOCATOR_MASK_URI -#ifdef ANDROID - | DATALOCATOR_MASK_ANDROIDFD - | DATALOCATOR_MASK_ANDROIDBUFFERQUEUE -#endif - , DATAFORMAT_MASK_MIME); - if (XA_RESULT_SUCCESS != result) { - break; - } - - result = checkDataSource("pBankSrc", (const SLDataSource *) pBankSrc, - &thiz->mBankSource, DATALOCATOR_MASK_NULL | DATALOCATOR_MASK_URI | - DATALOCATOR_MASK_ADDRESS, DATAFORMAT_MASK_NULL); - if (XA_RESULT_SUCCESS != result) { - break; - } - - result = checkDataSink("pAudioSnk", (const SLDataSink *) pAudioSnk, - &thiz->mAudioSink, DATALOCATOR_MASK_OUTPUTMIX, DATAFORMAT_MASK_NULL); - if (XA_RESULT_SUCCESS != result) { - break; - } - - result = checkDataSink("pImageVideoSnk", (const SLDataSink *) pImageVideoSnk, - &thiz->mImageVideoSink, - DATALOCATOR_MASK_NULL | DATALOCATOR_MASK_NATIVEDISPLAY, - DATAFORMAT_MASK_NULL); - if (XA_RESULT_SUCCESS != result) { - break; - } - - result = checkDataSink("pVibra", (const SLDataSink *) pVibra, &thiz->mVibraSink, - DATALOCATOR_MASK_NULL | DATALOCATOR_MASK_IODEVICE, - DATAFORMAT_MASK_NULL); - if (XA_RESULT_SUCCESS != result) { - break; - } - - result = checkDataSink("pLEDArray", (const SLDataSink *) pLEDArray, - &thiz->mLEDArraySink, DATALOCATOR_MASK_NULL | DATALOCATOR_MASK_IODEVICE, - DATAFORMAT_MASK_NULL); - if (XA_RESULT_SUCCESS != result) { - break; - } - - // Unsafe to ever refer to application pointers again - pDataSrc = NULL; - pBankSrc = NULL; - pAudioSnk = NULL; - pImageVideoSnk = NULL; - pVibra = NULL; - pLEDArray = NULL; - - // Check that the requested interfaces are compatible with the data source - // FIXME implement - - // check the source and sink parameters against platform support -#ifdef ANDROID - result = android_Player_checkSourceSink(thiz); - if (XA_RESULT_SUCCESS != result) { - break; - } -#endif - -#ifdef ANDROID - // AndroidBufferQueue-specific initialization - if (XA_DATALOCATOR_ANDROIDBUFFERQUEUE == - thiz->mDataSource.mLocator.mLocatorType) { - XAuint16 nbBuffers = (XAuint16) thiz->mDataSource.mLocator.mABQ.numBuffers; - - // Avoid possible integer overflow during multiplication; this arbitrary - // maximum is big enough to not interfere with real applications, but - // small enough to not overflow. - if (nbBuffers >= 256) { - result = SL_RESULT_MEMORY_FAILURE; - break; - } - - // initialize ABQ buffer type - // assert below has been checked in android_audioPlayer_checkSourceSink - assert(XA_DATAFORMAT_MIME == thiz->mDataSource.mFormat.mFormatType); - if (XA_CONTAINERTYPE_MPEG_TS == - thiz->mDataSource.mFormat.mMIME.containerType) { - thiz->mAndroidBufferQueue.mBufferType = kAndroidBufferTypeMpeg2Ts; - - // Set the container type for the StreamInformation interface - XAMediaContainerInformation *containerInfo = - (XAMediaContainerInformation*) - // always storing container info at index 0, as per spec - &(thiz->mStreamInfo.mStreamInfoTable.itemAt(0). - containerInfo); - containerInfo->containerType = XA_CONTAINERTYPE_MPEG_TS; - // there are no streams at this stage - containerInfo->numStreams = 0; - - } else { - thiz->mAndroidBufferQueue.mBufferType = kAndroidBufferTypeInvalid; - SL_LOGE("Invalid buffer type in Android Buffer Queue"); - result = SL_RESULT_CONTENT_UNSUPPORTED; - } - - // initialize ABQ memory - thiz->mAndroidBufferQueue.mBufferArray = (AdvancedBufferHeader *) - malloc( (nbBuffers + 1) * sizeof(AdvancedBufferHeader)); - if (NULL == thiz->mAndroidBufferQueue.mBufferArray) { - result = SL_RESULT_MEMORY_FAILURE; - break; - } else { - thiz->mAndroidBufferQueue.mFront = - thiz->mAndroidBufferQueue.mBufferArray; - thiz->mAndroidBufferQueue.mRear = - thiz->mAndroidBufferQueue.mBufferArray; - } - - thiz->mAndroidBufferQueue.mNumBuffers = nbBuffers; - - } -#endif - - // used to store the data source of our audio player - thiz->mDynamicSource.mDataSource = &thiz->mDataSource.u.mSource; - - // platform-specific initialization -#ifdef ANDROID - android_Player_create(thiz); -#endif - - } while (0); - - if (XA_RESULT_SUCCESS != result) { - IObject_Destroy(&thiz->mObject.mItf); - } else { - IObject_Publish(&thiz->mObject); - // return the new media player object - *pPlayer = (XAObjectItf) &thiz->mObject.mItf; - } - - } - } - - } - - XA_LEAVE_INTERFACE -} - - -static XAresult IEngine_CreateMediaRecorder(XAEngineItf self, XAObjectItf *pRecorder, - XADataSource *pAudioSrc, XADataSource *pImageVideoSrc, - XADataSink *pDataSnk, XAuint32 numInterfaces, const XAInterfaceID *pInterfaceIds, - const XAboolean *pInterfaceRequired) -{ - XA_ENTER_INTERFACE - - //IXAEngine *thiz = (IXAEngine *) self; - result = SL_RESULT_FEATURE_UNSUPPORTED; - -#if 0 - "pAudioSrc", pAudioSrc, - "pImageVideoSrc", pImageVideoSrc, - "pDataSink", pDataSnk, -#endif - - XA_LEAVE_INTERFACE -} - - -static XAresult IXAEngine_CreateOutputMix(XAEngineItf self, XAObjectItf *pMix, - XAuint32 numInterfaces, const XAInterfaceID *pInterfaceIds, - const XAboolean *pInterfaceRequired) -{ - // forward to OpenSL ES - return IEngine_CreateOutputMix(&((CEngine *) ((IXAEngine *) self)->mThis)->mEngine.mItf, - (SLObjectItf *) pMix, numInterfaces, (const SLInterfaceID *) pInterfaceIds, - (const SLboolean *) pInterfaceRequired); -} - - -static XAresult IXAEngine_CreateMetadataExtractor(XAEngineItf self, XAObjectItf *pMetadataExtractor, - XADataSource *pDataSource, XAuint32 numInterfaces, - const XAInterfaceID *pInterfaceIds, const XAboolean *pInterfaceRequired) -{ - // forward to OpenSL ES - return IEngine_CreateMetadataExtractor(&((CEngine *) ((IXAEngine *) self)->mThis)->mEngine.mItf, - (SLObjectItf *) pMetadataExtractor, (SLDataSource *) pDataSource, numInterfaces, - (const SLInterfaceID *) pInterfaceIds, (const SLboolean *) pInterfaceRequired); -} - - -static XAresult IXAEngine_CreateExtensionObject(XAEngineItf self, XAObjectItf *pObject, - void *pParameters, XAuint32 objectID, XAuint32 numInterfaces, - const XAInterfaceID *pInterfaceIds, const XAboolean *pInterfaceRequired) -{ - // forward to OpenSL ES - return IEngine_CreateExtensionObject(&((CEngine *) ((IXAEngine *) self)->mThis)->mEngine.mItf, - (SLObjectItf *) pObject, pParameters, objectID, numInterfaces, - (const SLInterfaceID *) pInterfaceIds, (const SLboolean *) pInterfaceRequired); -} - - -static XAresult IEngine_GetImplementationInfo(XAEngineItf self, XAuint32 *pMajor, XAuint32 *pMinor, - XAuint32 *pStep, /* XAuint32 nImplementationTextSize, */ const XAchar *pImplementationText) -{ - XA_ENTER_INTERFACE - - //IXAEngine *thiz = (IXAEngine *) self; - result = SL_RESULT_FEATURE_UNSUPPORTED; - - XA_LEAVE_INTERFACE -} - - -static XAresult IXAEngine_QuerySupportedProfiles(XAEngineItf self, XAint16 *pProfilesSupported) -{ - XA_ENTER_INTERFACE - - if (NULL == pProfilesSupported) { - result = XA_RESULT_PARAMETER_INVALID; - } else { -#if 1 - *pProfilesSupported = 0; - // the code below was copied from OpenSL ES and needs to be adapted for OpenMAX AL. -#else - // The generic implementation doesn't implement any of the profiles, they shouldn't be - // declared as supported. Also exclude the fake profiles BASE and OPTIONAL. - *pProfilesSupported = USE_PROFILES & - (USE_PROFILES_GAME | USE_PROFILES_MUSIC | USE_PROFILES_PHONE); -#endif - result = XA_RESULT_SUCCESS; - } - - XA_LEAVE_INTERFACE -} - - -static XAresult IXAEngine_QueryNumSupportedInterfaces(XAEngineItf self, XAuint32 objectID, - XAuint32 *pNumSupportedInterfaces) -{ - // forward to OpenSL ES - return IEngine_QueryNumSupportedInterfaces( - &((CEngine *) ((IXAEngine *) self)->mThis)->mEngine.mItf, objectID, - pNumSupportedInterfaces); -} - - -static XAresult IXAEngine_QuerySupportedInterfaces(XAEngineItf self, XAuint32 objectID, - XAuint32 index, XAInterfaceID *pInterfaceId) -{ - // forward to OpenSL ES - return IEngine_QuerySupportedInterfaces( - &((CEngine *) ((IXAEngine *) self)->mThis)->mEngine.mItf, objectID, index, - (SLInterfaceID *) pInterfaceId); -} - - -static XAresult IXAEngine_QueryNumSupportedExtensions(XAEngineItf self, XAuint32 *pNumExtensions) -{ - // forward to OpenSL ES - return IEngine_QueryNumSupportedExtensions( - &((CEngine *) ((IXAEngine *) self)->mThis)->mEngine.mItf, pNumExtensions); -} - - -static XAresult IXAEngine_QuerySupportedExtension(XAEngineItf self, XAuint32 index, - XAchar *pExtensionName, XAint16 *pNameLength) -{ - // forward to OpenSL ES - return IEngine_QuerySupportedExtension(&((CEngine *) ((IXAEngine *) self)->mThis)->mEngine.mItf, - index, pExtensionName, (SLint16 *) pNameLength); -} - - -static XAresult IXAEngine_IsExtensionSupported(XAEngineItf self, const XAchar *pExtensionName, - XAboolean *pSupported) -{ - // forward to OpenSL ES - return IEngine_IsExtensionSupported(&((CEngine *) ((IXAEngine *) self)->mThis)->mEngine.mItf, - pExtensionName, pSupported); -} - - -static XAresult IXAEngine_QueryLEDCapabilities(XAEngineItf self, XAuint32 *pIndex, - XAuint32 *pLEDDeviceID, XALEDDescriptor *pDescriptor) -{ - // forward to OpenSL ES EngineCapabilities - return (XAresult) IEngineCapabilities_QueryLEDCapabilities( - &((CEngine *) ((IXAEngine *) self)->mThis)->mEngineCapabilities.mItf, pIndex, - pLEDDeviceID, (SLLEDDescriptor *) pDescriptor); -} - - -static XAresult IXAEngine_QueryVibraCapabilities(XAEngineItf self, XAuint32 *pIndex, - XAuint32 *pVibraDeviceID, XAVibraDescriptor *pDescriptor) -{ - // forward to OpenSL ES EngineCapabilities - return (XAresult) IEngineCapabilities_QueryVibraCapabilities( - &((CEngine *) ((IXAEngine *) self)->mThis)->mEngineCapabilities.mItf, pIndex, - pVibraDeviceID, (SLVibraDescriptor *) pDescriptor); -} - - -// OpenMAX AL engine v-table - -static const struct XAEngineItf_ IXAEngine_Itf = { - IEngine_CreateCameraDevice, - IEngine_CreateRadioDevice, - IXAEngine_CreateLEDDevice, - IXAEngine_CreateVibraDevice, - IEngine_CreateMediaPlayer, - IEngine_CreateMediaRecorder, - IXAEngine_CreateOutputMix, - IXAEngine_CreateMetadataExtractor, - IXAEngine_CreateExtensionObject, - IEngine_GetImplementationInfo, - IXAEngine_QuerySupportedProfiles, - IXAEngine_QueryNumSupportedInterfaces, - IXAEngine_QuerySupportedInterfaces, - IXAEngine_QueryNumSupportedExtensions, - IXAEngine_QuerySupportedExtension, - IXAEngine_IsExtensionSupported, - IXAEngine_QueryLEDCapabilities, - IXAEngine_QueryVibraCapabilities -}; - - -void IXAEngine_init(void *self) -{ - IXAEngine *thiz = (IXAEngine *) self; - thiz->mItf = &IXAEngine_Itf; -} - - -void IXAEngine_deinit(void *self) -{ -} diff --git a/wilhelm/src/itf/IEngineCapabilities.c b/wilhelm/src/itf/IEngineCapabilities.c deleted file mode 100644 index 681d82d9..00000000 --- a/wilhelm/src/itf/IEngineCapabilities.c +++ /dev/null @@ -1,226 +0,0 @@ -/* - * 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. - */ - -/* EngineCapabilities implementation */ - -#include "sles_allinclusive.h" - - -static SLresult IEngineCapabilities_QuerySupportedProfiles( - SLEngineCapabilitiesItf self, SLuint16 *pProfilesSupported) -{ - SL_ENTER_INTERFACE - - if (NULL == pProfilesSupported) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - // The generic implementation doesn't implement any of the profiles, they shouldn't be - // declared as supported. Also exclude the fake profiles BASE and OPTIONAL. - *pProfilesSupported = USE_PROFILES & - (USE_PROFILES_GAME | USE_PROFILES_MUSIC | USE_PROFILES_PHONE); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEngineCapabilities_QueryAvailableVoices(SLEngineCapabilitiesItf self, - SLuint16 voiceType, SLint16 *pNumMaxVoices, SLboolean *pIsAbsoluteMax, SLint16 *pNumFreeVoices) -{ - SL_ENTER_INTERFACE - - switch (voiceType) { - case SL_VOICETYPE_2D_AUDIO: - case SL_VOICETYPE_MIDI: - case SL_VOICETYPE_3D_AUDIO: - case SL_VOICETYPE_3D_MIDIOUTPUT: - if (NULL != pNumMaxVoices) - *pNumMaxVoices = MAX_INSTANCE - 2; - if (NULL != pIsAbsoluteMax) - *pIsAbsoluteMax = SL_BOOLEAN_TRUE; - if (NULL != pNumFreeVoices) - *pNumFreeVoices = MAX_INSTANCE - 2; - result = SL_RESULT_SUCCESS; - break; - default: - result = SL_RESULT_PARAMETER_INVALID; - break; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEngineCapabilities_QueryNumberOfMIDISynthesizers( - SLEngineCapabilitiesItf self, SLint16 *pNum) -{ - SL_ENTER_INTERFACE - - if (NULL == pNum) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - *pNum = 1; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEngineCapabilities_QueryAPIVersion(SLEngineCapabilitiesItf self, - SLint16 *pMajor, SLint16 *pMinor, SLint16 *pStep) -{ - SL_ENTER_INTERFACE - - if (!(NULL != pMajor && NULL != pMinor && NULL != pStep)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - *pMajor = 1; - *pMinor = 0; - *pStep = 1; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -SLresult IEngineCapabilities_QueryLEDCapabilities(SLEngineCapabilitiesItf self, - SLuint32 *pIndex, SLuint32 *pLEDDeviceID, SLLEDDescriptor *pDescriptor) -{ - SL_ENTER_INTERFACE - - IEngineCapabilities *thiz = (IEngineCapabilities *) self; - const struct LED_id_descriptor *id_descriptor; - SLuint32 index; - if (NULL != pIndex) { - result = SL_RESULT_SUCCESS; - if (NULL != pLEDDeviceID || NULL != pDescriptor) { - index = *pIndex; - if (index >= thiz->mMaxIndexLED) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - id_descriptor = &LED_id_descriptors[index]; - if (NULL != pLEDDeviceID) - *pLEDDeviceID = id_descriptor->id; - if (NULL != pDescriptor) - *pDescriptor = *id_descriptor->descriptor; - } - } - *pIndex = thiz->mMaxIndexLED; - } else { - result = SL_RESULT_PARAMETER_INVALID; - if (NULL != pLEDDeviceID && NULL != pDescriptor) { - SLuint32 id = *pLEDDeviceID; - for (index = 0; index < thiz->mMaxIndexLED; ++index) { - id_descriptor = &LED_id_descriptors[index]; - if (id == id_descriptor->id) { - *pDescriptor = *id_descriptor->descriptor; - result = SL_RESULT_SUCCESS; - break; - } - } - } - } - - SL_LEAVE_INTERFACE -} - - -SLresult IEngineCapabilities_QueryVibraCapabilities(SLEngineCapabilitiesItf self, - SLuint32 *pIndex, SLuint32 *pVibraDeviceID, SLVibraDescriptor *pDescriptor) -{ - SL_ENTER_INTERFACE - - IEngineCapabilities *thiz = (IEngineCapabilities *) self; - const struct Vibra_id_descriptor *id_descriptor; - SLuint32 index; - if (NULL != pIndex) { - result = SL_RESULT_SUCCESS; - if (NULL != pVibraDeviceID || NULL != pDescriptor) { - index = *pIndex; - if (index >= thiz->mMaxIndexVibra) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - id_descriptor = &Vibra_id_descriptors[index]; - if (NULL != pVibraDeviceID) - *pVibraDeviceID = id_descriptor->id; - if (NULL != pDescriptor) - *pDescriptor = *id_descriptor->descriptor; - } - } - *pIndex = thiz->mMaxIndexVibra; - } else { - result = SL_RESULT_PARAMETER_INVALID; - if (NULL != pVibraDeviceID && NULL != pDescriptor) { - SLuint32 id = *pVibraDeviceID; - for (index = 0; index < thiz->mMaxIndexVibra; ++index) { - id_descriptor = &Vibra_id_descriptors[index]; - if (id == id_descriptor->id) { - *pDescriptor = *id_descriptor->descriptor; - result = SL_RESULT_SUCCESS; - break; - } - } - } - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEngineCapabilities_IsThreadSafe(SLEngineCapabilitiesItf self, - SLboolean *pIsThreadSafe) -{ - SL_ENTER_INTERFACE - - if (NULL == pIsThreadSafe) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEngineCapabilities *thiz = (IEngineCapabilities *) self; - *pIsThreadSafe = thiz->mThreadSafe; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static const struct SLEngineCapabilitiesItf_ IEngineCapabilities_Itf = { - IEngineCapabilities_QuerySupportedProfiles, - IEngineCapabilities_QueryAvailableVoices, - IEngineCapabilities_QueryNumberOfMIDISynthesizers, - IEngineCapabilities_QueryAPIVersion, - IEngineCapabilities_QueryLEDCapabilities, - IEngineCapabilities_QueryVibraCapabilities, - IEngineCapabilities_IsThreadSafe -}; - -void IEngineCapabilities_init(void *self) -{ - IEngineCapabilities *thiz = (IEngineCapabilities *) self; - thiz->mItf = &IEngineCapabilities_Itf; - // mThreadSafe is initialized in slCreateEngine - const struct LED_id_descriptor *id_descriptor_LED = LED_id_descriptors; - while (NULL != id_descriptor_LED->descriptor) - ++id_descriptor_LED; - thiz->mMaxIndexLED = id_descriptor_LED - LED_id_descriptors; - const struct Vibra_id_descriptor *id_descriptor_Vibra = Vibra_id_descriptors; - while (NULL != id_descriptor_Vibra->descriptor) - ++id_descriptor_Vibra; - thiz->mMaxIndexVibra = id_descriptor_Vibra - Vibra_id_descriptors; -} diff --git a/wilhelm/src/itf/IEnvironmentalReverb.c b/wilhelm/src/itf/IEnvironmentalReverb.c deleted file mode 100644 index 79b0290d..00000000 --- a/wilhelm/src/itf/IEnvironmentalReverb.c +++ /dev/null @@ -1,792 +0,0 @@ -/* - * 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. - */ - -/* EnvironmentalReverb implementation */ - -#include "sles_allinclusive.h" -#ifdef ANDROID -#include <audio_effects/effect_environmentalreverb.h> -#endif - -// Note: all Set operations use exclusive not poke, -// because SetEnvironmentalReverbProperties is exclusive. -// It is safe for the Get operations to use peek, -// on the assumption that the block copy will atomically -// replace each word of the block. - - -#if defined(ANDROID) -/** - * returns true if this interface is not associated with an initialized EnvironmentalReverb effect - */ -static inline bool NO_ENVREVERB(IEnvironmentalReverb* ier) { - return (ier->mEnvironmentalReverbEffect == 0); -} -#endif - - -static SLresult IEnvironmentalReverb_SetRoomLevel(SLEnvironmentalReverbItf self, SLmillibel room) -{ - SL_ENTER_INTERFACE - - //if (!(SL_MILLIBEL_MIN <= room && room <= 0)) { - // comparison (SL_MILLIBEL_MIN <= room) is always true due to range of SLmillibel - if (!(room <= 0)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEnvironmentalReverb *thiz = (IEnvironmentalReverb *) self; - interface_lock_exclusive(thiz); - thiz->mProperties.roomLevel = room; -#if !defined(ANDROID) - result = SL_RESULT_SUCCESS; -#else - if (NO_ENVREVERB(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = android_erev_setParam(thiz->mEnvironmentalReverbEffect, - REVERB_PARAM_ROOM_LEVEL, &room); - result = android_fx_statusToResult(status); - } -#endif - interface_unlock_exclusive(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEnvironmentalReverb_GetRoomLevel(SLEnvironmentalReverbItf self, SLmillibel *pRoom) -{ - SL_ENTER_INTERFACE - - if (NULL == pRoom) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEnvironmentalReverb *thiz = (IEnvironmentalReverb *) self; - interface_lock_shared(thiz); -#if 1 // !defined(ANDROID) - result = SL_RESULT_SUCCESS; -#else - if (NO_ENVREVERB(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = android_erev_getParam(thiz->mEnvironmentalReverbEffect, - REVERB_PARAM_ROOM_LEVEL, &thiz->mProperties.roomLevel); - result = android_fx_statusToResult(status); - } -#endif - *pRoom = thiz->mProperties.roomLevel; - - interface_unlock_shared(thiz); - - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEnvironmentalReverb_SetRoomHFLevel( - SLEnvironmentalReverbItf self, SLmillibel roomHF) -{ - SL_ENTER_INTERFACE - - //if (!(SL_MILLIBEL_MIN <= roomHF && roomHF <= 0)) { - // comparison (SL_MILLIBEL_MIN <= roomHF) is always true due to range of SLmillibel - if (!(roomHF <= 0)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEnvironmentalReverb *thiz = (IEnvironmentalReverb *) self; - interface_lock_exclusive(thiz); - thiz->mProperties.roomHFLevel = roomHF; -#if !defined(ANDROID) - result = SL_RESULT_SUCCESS; -#else - if (NO_ENVREVERB(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = android_erev_setParam(thiz->mEnvironmentalReverbEffect, - REVERB_PARAM_ROOM_HF_LEVEL, &roomHF); - result = android_fx_statusToResult(status); - } -#endif - interface_unlock_exclusive(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEnvironmentalReverb_GetRoomHFLevel( - SLEnvironmentalReverbItf self, SLmillibel *pRoomHF) -{ - SL_ENTER_INTERFACE - - if (NULL == pRoomHF) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEnvironmentalReverb *thiz = (IEnvironmentalReverb *) self; - interface_lock_shared(thiz); -#if 1 // !defined(ANDROID) - result = SL_RESULT_SUCCESS; -#else - if (NO_ENVREVERB(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = android_erev_getParam(thiz->mEnvironmentalReverbEffect, - REVERB_PARAM_ROOM_HF_LEVEL, &thiz->mProperties.roomHFLevel); - result = android_fx_statusToResult(status); - } -#endif - *pRoomHF = thiz->mProperties.roomHFLevel; - - interface_unlock_shared(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEnvironmentalReverb_SetDecayTime( - SLEnvironmentalReverbItf self, SLmillisecond decayTime) -{ - SL_ENTER_INTERFACE - - if (!(100 <= decayTime && decayTime <= 20000)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEnvironmentalReverb *thiz = (IEnvironmentalReverb *) self; - interface_lock_exclusive(thiz); - thiz->mProperties.decayTime = decayTime; -#if 1 // !defined(ANDROID) - result = SL_RESULT_SUCCESS; -#else - if (NO_ENVREVERB(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = android_erev_setParam(thiz->mEnvironmentalReverbEffect, - REVERB_PARAM_DECAY_TIME, &decayTime); - result = android_fx_statusToResult(status); - } -#endif - interface_unlock_exclusive(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEnvironmentalReverb_GetDecayTime( - SLEnvironmentalReverbItf self, SLmillisecond *pDecayTime) -{ - SL_ENTER_INTERFACE - - if (NULL == pDecayTime) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEnvironmentalReverb *thiz = (IEnvironmentalReverb *) self; - interface_lock_shared(thiz); -#if 1 // !defined(ANDROID) - result = SL_RESULT_SUCCESS; -#else - if (NO_ENVREVERB(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = android_erev_getParam(thiz->mEnvironmentalReverbEffect, - REVERB_PARAM_DECAY_TIME, &thiz->mProperties.decayTime); - result = android_fx_statusToResult(status); - } -#endif - *pDecayTime = thiz->mProperties.decayTime; - - interface_unlock_shared(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEnvironmentalReverb_SetDecayHFRatio( - SLEnvironmentalReverbItf self, SLpermille decayHFRatio) -{ - SL_ENTER_INTERFACE - - if (!(100 <= decayHFRatio && decayHFRatio <= 2000)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEnvironmentalReverb *thiz = (IEnvironmentalReverb *) self; - interface_lock_exclusive(thiz); - thiz->mProperties.decayHFRatio = decayHFRatio; -#if !defined(ANDROID) - result = SL_RESULT_SUCCESS; -#else - if (NO_ENVREVERB(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = android_erev_setParam(thiz->mEnvironmentalReverbEffect, - REVERB_PARAM_DECAY_HF_RATIO, &decayHFRatio); - result = android_fx_statusToResult(status); - } -#endif - interface_unlock_exclusive(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEnvironmentalReverb_GetDecayHFRatio( - SLEnvironmentalReverbItf self, SLpermille *pDecayHFRatio) -{ - SL_ENTER_INTERFACE - - if (NULL == pDecayHFRatio) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEnvironmentalReverb *thiz = (IEnvironmentalReverb *) self; - interface_lock_shared(thiz); -#if 1 // !defined(ANDROID) - result = SL_RESULT_SUCCESS; -#else - if (NO_ENVREVERB(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = android_erev_getParam(thiz->mEnvironmentalReverbEffect, - REVERB_PARAM_DECAY_HF_RATIO, &thiz->mProperties.decayHFRatio); - result = android_fx_statusToResult(status); - } -#endif - *pDecayHFRatio = thiz->mProperties.decayHFRatio; - - interface_unlock_shared(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEnvironmentalReverb_SetReflectionsLevel( - SLEnvironmentalReverbItf self, SLmillibel reflectionsLevel) -{ - SL_ENTER_INTERFACE - - //if (!(SL_MILLIBEL_MIN <= reflectionsLevel && reflectionsLevel <= 1000)) { - // comparison (SL_MILLIBEL_MIN <= reflectionsLevel) is always true due to range of SLmillibel - if (!(reflectionsLevel <= 1000)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEnvironmentalReverb *thiz = (IEnvironmentalReverb *) self; - interface_lock_exclusive(thiz); - thiz->mProperties.reflectionsLevel = reflectionsLevel; -#if !defined(ANDROID) - result = SL_RESULT_SUCCESS; -#else - if (NO_ENVREVERB(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = android_erev_setParam(thiz->mEnvironmentalReverbEffect, - REVERB_PARAM_REFLECTIONS_LEVEL, &reflectionsLevel); - result = android_fx_statusToResult(status); - } -#endif - interface_unlock_exclusive(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEnvironmentalReverb_GetReflectionsLevel( - SLEnvironmentalReverbItf self, SLmillibel *pReflectionsLevel) -{ - SL_ENTER_INTERFACE - - if (NULL == pReflectionsLevel) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEnvironmentalReverb *thiz = (IEnvironmentalReverb *) self; - interface_lock_shared(thiz); -#if 1 // !defined(ANDROID) - result = SL_RESULT_SUCCESS; -#else - if (NO_ENVREVERB(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = android_erev_getParam(thiz->mEnvironmentalReverbEffect, - REVERB_PARAM_REFLECTIONS_LEVEL, &thiz->mProperties.reflectionsLevel); - result = android_fx_statusToResult(status); - } -#endif - *pReflectionsLevel = thiz->mProperties.reflectionsLevel; - - interface_unlock_shared(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEnvironmentalReverb_SetReflectionsDelay( - SLEnvironmentalReverbItf self, SLmillisecond reflectionsDelay) -{ - SL_ENTER_INTERFACE - - if (!(/* 0 <= reflectionsDelay && */ reflectionsDelay <= 300)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEnvironmentalReverb *thiz = (IEnvironmentalReverb *) self; - interface_lock_exclusive(thiz); - thiz->mProperties.reflectionsDelay = reflectionsDelay; -#if !defined(ANDROID) - result = SL_RESULT_SUCCESS; -#else - if (NO_ENVREVERB(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = android_erev_setParam(thiz->mEnvironmentalReverbEffect, - REVERB_PARAM_REFLECTIONS_DELAY, &reflectionsDelay); - result = android_fx_statusToResult(status); - } -#endif - interface_unlock_exclusive(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEnvironmentalReverb_GetReflectionsDelay( - SLEnvironmentalReverbItf self, SLmillisecond *pReflectionsDelay) -{ - SL_ENTER_INTERFACE - - if (NULL == pReflectionsDelay) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEnvironmentalReverb *thiz = (IEnvironmentalReverb *) self; - interface_lock_shared(thiz); -#if 1 // !defined(ANDROID) - result = SL_RESULT_SUCCESS; -#else - if (NO_ENVREVERB(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = android_erev_getParam(thiz->mEnvironmentalReverbEffect, - REVERB_PARAM_REFLECTIONS_DELAY, &thiz->mProperties.reflectionsDelay); - result = android_fx_statusToResult(status); - } -#endif - *pReflectionsDelay = thiz->mProperties.reflectionsDelay; - - interface_unlock_shared(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEnvironmentalReverb_SetReverbLevel( - SLEnvironmentalReverbItf self, SLmillibel reverbLevel) -{ - SL_ENTER_INTERFACE - - //if (!(SL_MILLIBEL_MIN <= reverbLevel && reverbLevel <= 2000)) { - // comparison (SL_MILLIBEL_MIN <= reverbLevel) is always true due to range of SLmillibel - if (!(reverbLevel <= 2000)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEnvironmentalReverb *thiz = (IEnvironmentalReverb *) self; - interface_lock_exclusive(thiz); - thiz->mProperties.reverbLevel = reverbLevel; -#if !defined(ANDROID) - result = SL_RESULT_SUCCESS; -#else - if (NO_ENVREVERB(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = android_erev_setParam(thiz->mEnvironmentalReverbEffect, - REVERB_PARAM_REVERB_LEVEL, &reverbLevel); - result = android_fx_statusToResult(status); - } -#endif - interface_unlock_exclusive(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEnvironmentalReverb_GetReverbLevel( - SLEnvironmentalReverbItf self, SLmillibel *pReverbLevel) -{ - SL_ENTER_INTERFACE - - if (NULL == pReverbLevel) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEnvironmentalReverb *thiz = (IEnvironmentalReverb *) self; - interface_lock_shared(thiz); -#if 1 // !defined(ANDROID) - result = SL_RESULT_SUCCESS; -#else - if (NO_ENVREVERB(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = android_erev_getParam(thiz->mEnvironmentalReverbEffect, - REVERB_PARAM_REVERB_LEVEL, &thiz->mProperties.reverbLevel); - result = android_fx_statusToResult(status); - } -#endif - *pReverbLevel = thiz->mProperties.reverbLevel; - - interface_unlock_shared(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEnvironmentalReverb_SetReverbDelay( - SLEnvironmentalReverbItf self, SLmillisecond reverbDelay) -{ - SL_ENTER_INTERFACE - - if (!(/* 0 <= reverbDelay && */ reverbDelay <= 100)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEnvironmentalReverb *thiz = (IEnvironmentalReverb *) self; - interface_lock_exclusive(thiz); - thiz->mProperties.reverbDelay = reverbDelay; -#if !defined(ANDROID) - result = SL_RESULT_SUCCESS; -#else - if (NO_ENVREVERB(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = android_erev_setParam(thiz->mEnvironmentalReverbEffect, - REVERB_PARAM_REVERB_DELAY, &reverbDelay); - result = android_fx_statusToResult(status); - } -#endif - interface_unlock_exclusive(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEnvironmentalReverb_GetReverbDelay( - SLEnvironmentalReverbItf self, SLmillisecond *pReverbDelay) -{ - SL_ENTER_INTERFACE - - if (NULL == pReverbDelay) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEnvironmentalReverb *thiz = (IEnvironmentalReverb *) self; - interface_lock_shared(thiz); -#if 1 // !defined(ANDROID) - result = SL_RESULT_SUCCESS; -#else - if (NO_ENVREVERB(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = android_erev_getParam(thiz->mEnvironmentalReverbEffect, - REVERB_PARAM_REVERB_DELAY, &thiz->mProperties.reverbDelay); - result = android_fx_statusToResult(status); - } -#endif - *pReverbDelay = thiz->mProperties.reverbDelay; - - interface_unlock_shared(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEnvironmentalReverb_SetDiffusion( - SLEnvironmentalReverbItf self, SLpermille diffusion) -{ - SL_ENTER_INTERFACE - - if (!(0 <= diffusion && diffusion <= 1000)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEnvironmentalReverb *thiz = (IEnvironmentalReverb *) self; - interface_lock_exclusive(thiz); - thiz->mProperties.diffusion = diffusion; -#if !defined(ANDROID) - result = SL_RESULT_SUCCESS; -#else - if (NO_ENVREVERB(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = android_erev_setParam(thiz->mEnvironmentalReverbEffect, - REVERB_PARAM_DIFFUSION, &diffusion); - result = android_fx_statusToResult(status); - } -#endif - interface_unlock_exclusive(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEnvironmentalReverb_GetDiffusion(SLEnvironmentalReverbItf self, - SLpermille *pDiffusion) -{ - SL_ENTER_INTERFACE - - if (NULL == pDiffusion) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEnvironmentalReverb *thiz = (IEnvironmentalReverb *) self; - interface_lock_shared(thiz); -#if 1 // !defined(ANDROID) - result = SL_RESULT_SUCCESS; -#else - if (NO_ENVREVERB(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = android_erev_getParam(thiz->mEnvironmentalReverbEffect, - REVERB_PARAM_DIFFUSION, &thiz->mProperties.diffusion); - result = android_fx_statusToResult(status); - } -#endif - *pDiffusion = thiz->mProperties.diffusion; - - interface_unlock_shared(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEnvironmentalReverb_SetDensity(SLEnvironmentalReverbItf self, - SLpermille density) -{ - SL_ENTER_INTERFACE - - if (!(0 <= density && density <= 1000)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEnvironmentalReverb *thiz = (IEnvironmentalReverb *) self; - interface_lock_exclusive(thiz); - thiz->mProperties.density = density; -#if !defined(ANDROID) - result = SL_RESULT_SUCCESS; -#else - if (NO_ENVREVERB(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = android_erev_setParam(thiz->mEnvironmentalReverbEffect, - REVERB_PARAM_DENSITY, &density); - result = android_fx_statusToResult(status); - } -#endif - interface_unlock_exclusive(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEnvironmentalReverb_GetDensity(SLEnvironmentalReverbItf self, - SLpermille *pDensity) -{ - SL_ENTER_INTERFACE - - if (NULL == pDensity) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEnvironmentalReverb *thiz = (IEnvironmentalReverb *) self; - interface_lock_shared(thiz); -#if 1 // !defined(ANDROID) - result = SL_RESULT_SUCCESS; -#else - if (NO_ENVREVERB(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = android_erev_getParam(thiz->mEnvironmentalReverbEffect, - REVERB_PARAM_DENSITY, &thiz->mProperties.density); - result = android_fx_statusToResult(status); - } -#endif - *pDensity = thiz->mProperties.density; - - interface_unlock_shared(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEnvironmentalReverb_SetEnvironmentalReverbProperties(SLEnvironmentalReverbItf self, - const SLEnvironmentalReverbSettings *pProperties) -{ - SL_ENTER_INTERFACE - - // note that it's unnecessary to verify that any level stored inside the "properties" struct - // is >= SL_MILLIBEL_MIN before using it, due to range of SLmillibel - - result = SL_RESULT_PARAMETER_INVALID; - do { - if (NULL == pProperties) - break; - SLEnvironmentalReverbSettings properties = *pProperties; - if (!(properties.roomLevel <= 0)) - break; - if (!(properties.roomHFLevel <= 0)) - break; - if (!(100 <= properties.decayTime && properties.decayTime <= 20000)) - break; - if (!(100 <= properties.decayHFRatio && properties.decayHFRatio <= 2000)) - break; - if (!(properties.reflectionsLevel <= 1000)) - break; - if (!(/* 0 <= properties.reflectionsDelay && */ properties.reflectionsDelay <= 300)) - break; - if (!(properties.reverbLevel <= 2000)) - break; - if (!(/* 0 <= properties.reverbDelay && */ properties.reverbDelay <= 100)) - break; - if (!(0 <= properties.diffusion && properties.diffusion <= 1000)) - break; - if (!(0 <= properties.density && properties.density <= 1000)) - break; - IEnvironmentalReverb *thiz = (IEnvironmentalReverb *) self; - interface_lock_exclusive(thiz); - thiz->mProperties = properties; -#if !defined(ANDROID) - result = SL_RESULT_SUCCESS; -#else - if (NO_ENVREVERB(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = android_erev_setParam(thiz->mEnvironmentalReverbEffect, - REVERB_PARAM_PROPERTIES, &properties); - result = android_fx_statusToResult(status); - } -#endif - interface_unlock_exclusive(thiz); - } while (0); - - SL_LEAVE_INTERFACE -} - - -static SLresult IEnvironmentalReverb_GetEnvironmentalReverbProperties( - SLEnvironmentalReverbItf self, SLEnvironmentalReverbSettings *pProperties) -{ - SL_ENTER_INTERFACE - - if (NULL == pProperties) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEnvironmentalReverb *thiz = (IEnvironmentalReverb *) self; - interface_lock_shared(thiz); -#if 1 // !defined(ANDROID) - result = SL_RESULT_SUCCESS; -#else - if (NO_ENVREVERB(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = android_erev_getParam(thiz->mEnvironmentalReverbEffect, - REVERB_PARAM_PROPERTIES, &thiz->mProperties); - result = android_fx_statusToResult(status); - } -#endif - *pProperties = thiz->mProperties; - - interface_unlock_shared(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static const struct SLEnvironmentalReverbItf_ IEnvironmentalReverb_Itf = { - IEnvironmentalReverb_SetRoomLevel, - IEnvironmentalReverb_GetRoomLevel, - IEnvironmentalReverb_SetRoomHFLevel, - IEnvironmentalReverb_GetRoomHFLevel, - IEnvironmentalReverb_SetDecayTime, - IEnvironmentalReverb_GetDecayTime, - IEnvironmentalReverb_SetDecayHFRatio, - IEnvironmentalReverb_GetDecayHFRatio, - IEnvironmentalReverb_SetReflectionsLevel, - IEnvironmentalReverb_GetReflectionsLevel, - IEnvironmentalReverb_SetReflectionsDelay, - IEnvironmentalReverb_GetReflectionsDelay, - IEnvironmentalReverb_SetReverbLevel, - IEnvironmentalReverb_GetReverbLevel, - IEnvironmentalReverb_SetReverbDelay, - IEnvironmentalReverb_GetReverbDelay, - IEnvironmentalReverb_SetDiffusion, - IEnvironmentalReverb_GetDiffusion, - IEnvironmentalReverb_SetDensity, - IEnvironmentalReverb_GetDensity, - IEnvironmentalReverb_SetEnvironmentalReverbProperties, - IEnvironmentalReverb_GetEnvironmentalReverbProperties -}; - -static const SLEnvironmentalReverbSettings IEnvironmentalReverb_default = { - SL_MILLIBEL_MIN, // roomLevel - 0, // roomHFLevel - 1000, // decayTime - 500, // decayHFRatio - SL_MILLIBEL_MIN, // reflectionsLevel - 20, // reflectionsDelay - SL_MILLIBEL_MIN, // reverbLevel - 40, // reverbDelay - 1000, // diffusion - 1000 // density -}; - -void IEnvironmentalReverb_init(void *self) -{ - IEnvironmentalReverb *thiz = (IEnvironmentalReverb *) self; - thiz->mItf = &IEnvironmentalReverb_Itf; - thiz->mProperties = IEnvironmentalReverb_default; -#if defined(ANDROID) - memset(&thiz->mEnvironmentalReverbDescriptor, 0, sizeof(effect_descriptor_t)); - // placement new (explicit constructor) - (void) new (&thiz->mEnvironmentalReverbEffect) android::sp<android::AudioEffect>(); -#endif -} - -void IEnvironmentalReverb_deinit(void *self) -{ -#if defined(ANDROID) - IEnvironmentalReverb *thiz = (IEnvironmentalReverb *) self; - // explicit destructor - thiz->mEnvironmentalReverbEffect.~sp(); -#endif -} - -bool IEnvironmentalReverb_Expose(void *self) -{ -#if defined(ANDROID) - IEnvironmentalReverb *thiz = (IEnvironmentalReverb *) self; - if (!android_fx_initEffectDescriptor(SL_IID_ENVIRONMENTALREVERB, - &thiz->mEnvironmentalReverbDescriptor)) { - SL_LOGE("EnvironmentalReverb initialization failed."); - return false; - } -#endif - return true; -} diff --git a/wilhelm/src/itf/IEqualizer.c b/wilhelm/src/itf/IEqualizer.c deleted file mode 100644 index 14ff9654..00000000 --- a/wilhelm/src/itf/IEqualizer.c +++ /dev/null @@ -1,527 +0,0 @@ -/* - * 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. - */ - -/* Equalizer implementation */ - -#include "sles_allinclusive.h" -#ifdef ANDROID -#include <audio_effects/effect_equalizer.h> -#endif - -#define MAX_EQ_PRESETS 3 - -#if !defined(ANDROID) -static const struct EqualizerBand EqualizerBands[MAX_EQ_BANDS] = { - {1000, 1500, 2000}, - {2000, 3000, 4000}, - {4000, 5500, 7000}, - {7000, 8000, 9000} -}; - -static const struct EqualizerPreset { - const char *mName; - SLmillibel mLevels[MAX_EQ_BANDS]; -} EqualizerPresets[MAX_EQ_PRESETS] = { - {"Default", {0, 0, 0, 0}}, - {"Bass", {500, 200, 100, 0}}, - {"Treble", {0, 100, 200, 500}} -}; -#endif - - -#if defined(ANDROID) -/** - * returns true if this interface is not associated with an initialized Equalizer effect - */ -static inline bool NO_EQ(IEqualizer* v) { - return (v->mEqEffect == 0); -} -#endif - - -static SLresult IEqualizer_SetEnabled(SLEqualizerItf self, SLboolean enabled) -{ - SL_ENTER_INTERFACE - - IEqualizer *thiz = (IEqualizer *) self; - interface_lock_exclusive(thiz); - thiz->mEnabled = (SLboolean) enabled; -#if !defined(ANDROID) - result = SL_RESULT_SUCCESS; -#else - if (NO_EQ(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = - thiz->mEqEffect->setEnabled((bool) thiz->mEnabled); - result = android_fx_statusToResult(status); - } -#endif - interface_unlock_exclusive(thiz); - - SL_LEAVE_INTERFACE -} - - -static SLresult IEqualizer_IsEnabled(SLEqualizerItf self, SLboolean *pEnabled) -{ - SL_ENTER_INTERFACE - - if (NULL == pEnabled) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEqualizer *thiz = (IEqualizer *) self; - interface_lock_exclusive(thiz); - SLboolean enabled = thiz->mEnabled; - #if !defined(ANDROID) - *pEnabled = enabled; - result = SL_RESULT_SUCCESS; - #else - if (NO_EQ(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - *pEnabled = (SLboolean) thiz->mEqEffect->getEnabled(); - result = SL_RESULT_SUCCESS; - } - #endif - interface_unlock_exclusive(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEqualizer_GetNumberOfBands(SLEqualizerItf self, SLuint16 *pNumBands) -{ - SL_ENTER_INTERFACE - - if (NULL == pNumBands) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEqualizer *thiz = (IEqualizer *) self; - // Note: no lock, but OK because it is const - *pNumBands = thiz->mNumBands; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEqualizer_GetBandLevelRange(SLEqualizerItf self, SLmillibel *pMin, - SLmillibel *pMax) -{ - SL_ENTER_INTERFACE - - if (NULL == pMin && NULL == pMax) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEqualizer *thiz = (IEqualizer *) self; - // Note: no lock, but OK because it is const - if (NULL != pMin) - *pMin = thiz->mBandLevelRangeMin; - if (NULL != pMax) - *pMax = thiz->mBandLevelRangeMax; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEqualizer_SetBandLevel(SLEqualizerItf self, SLuint16 band, SLmillibel level) -{ - SL_ENTER_INTERFACE - - IEqualizer *thiz = (IEqualizer *) self; - if (!(thiz->mBandLevelRangeMin <= level && level <= thiz->mBandLevelRangeMax) || - (band >= thiz->mNumBands)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - interface_lock_exclusive(thiz); -#if !defined(ANDROID) - thiz->mLevels[band] = level; - thiz->mPreset = SL_EQUALIZER_UNDEFINED; - result = SL_RESULT_SUCCESS; -#else - if (NO_EQ(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = - android_eq_setParam(thiz->mEqEffect, EQ_PARAM_BAND_LEVEL, band, &level); - result = android_fx_statusToResult(status); - } -#endif - interface_unlock_exclusive(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEqualizer_GetBandLevel(SLEqualizerItf self, SLuint16 band, SLmillibel *pLevel) -{ - SL_ENTER_INTERFACE - - if (NULL == pLevel) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEqualizer *thiz = (IEqualizer *) self; - // const, no lock needed - if (band >= thiz->mNumBands) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - SLmillibel level = 0; - interface_lock_shared(thiz); -#if !defined(ANDROID) - level = thiz->mLevels[band]; - result = SL_RESULT_SUCCESS; -#else - if (NO_EQ(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = - android_eq_getParam(thiz->mEqEffect, EQ_PARAM_BAND_LEVEL, band, &level); - result = android_fx_statusToResult(status); - } -#endif - interface_unlock_shared(thiz); - *pLevel = level; - } - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEqualizer_GetCenterFreq(SLEqualizerItf self, SLuint16 band, SLmilliHertz *pCenter) -{ - SL_ENTER_INTERFACE - - if (NULL == pCenter) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEqualizer *thiz = (IEqualizer *) self; - if (band >= thiz->mNumBands) { - result = SL_RESULT_PARAMETER_INVALID; - } else { -#if !defined(ANDROID) - // Note: no lock, but OK because it is const - *pCenter = thiz->mBands[band].mCenter; - result = SL_RESULT_SUCCESS; -#else - SLmilliHertz center = 0; - interface_lock_shared(thiz); - if (NO_EQ(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = - android_eq_getParam(thiz->mEqEffect, EQ_PARAM_CENTER_FREQ, band, ¢er); - result = android_fx_statusToResult(status); - } - interface_unlock_shared(thiz); - *pCenter = center; -#endif - } - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEqualizer_GetBandFreqRange(SLEqualizerItf self, SLuint16 band, - SLmilliHertz *pMin, SLmilliHertz *pMax) -{ - SL_ENTER_INTERFACE - - if (NULL == pMin && NULL == pMax) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEqualizer *thiz = (IEqualizer *) self; - if (band >= thiz->mNumBands) { - result = SL_RESULT_PARAMETER_INVALID; - } else { -#if !defined(ANDROID) - // Note: no lock, but OK because it is const - if (NULL != pMin) - *pMin = thiz->mBands[band].mMin; - if (NULL != pMax) - *pMax = thiz->mBands[band].mMax; - result = SL_RESULT_SUCCESS; -#else - SLmilliHertz range[2] = {0, 0}; // SLmilliHertz is SLuint32 - interface_lock_shared(thiz); - if (NO_EQ(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = - android_eq_getParam(thiz->mEqEffect, EQ_PARAM_BAND_FREQ_RANGE, band, range); - result = android_fx_statusToResult(status); - } - interface_unlock_shared(thiz); - if (NULL != pMin) { - *pMin = range[0]; - } - if (NULL != pMax) { - *pMax = range[1]; - } -#endif - } - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEqualizer_GetBand(SLEqualizerItf self, SLmilliHertz frequency, SLuint16 *pBand) -{ - SL_ENTER_INTERFACE - - if (NULL == pBand) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEqualizer *thiz = (IEqualizer *) self; -#if !defined(ANDROID) - // search for band whose center frequency has the closest ratio to 1.0 - // assumes bands are unsorted (a pessimistic assumption) - // assumes bands can overlap (a pessimistic assumption) - // assumes a small number of bands, so no need for a fancier algorithm - const struct EqualizerBand *band; - float floatFreq = (float) frequency; - float bestRatio = 0.0; - SLuint16 bestBand = SL_EQUALIZER_UNDEFINED; - for (band = thiz->mBands; band < &thiz->mBands[thiz->mNumBands]; ++band) { - if (!(band->mMin <= frequency && frequency <= band->mMax)) - continue; - assert(band->mMin <= band->mCenter && band->mCenter <= band->mMax); - assert(band->mCenter != 0); - float ratio = frequency <= band->mCenter ? - floatFreq / band->mCenter : band->mCenter / floatFreq; - if (ratio > bestRatio) { - bestRatio = ratio; - bestBand = band - thiz->mBands; - } - } - *pBand = bestBand; - result = SL_RESULT_SUCCESS; -#else - uint16_t band = 0; - interface_lock_shared(thiz); - if (NO_EQ(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = - android_eq_getParam(thiz->mEqEffect, EQ_PARAM_GET_BAND, frequency, &band); - result = android_fx_statusToResult(status); - } - interface_unlock_shared(thiz); - *pBand = (SLuint16)band; -#endif - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEqualizer_GetCurrentPreset(SLEqualizerItf self, SLuint16 *pPreset) -{ - SL_ENTER_INTERFACE - - if (NULL == pPreset) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEqualizer *thiz = (IEqualizer *) self; - interface_lock_shared(thiz); -#if !defined(ANDROID) - SLuint16 preset = thiz->mPreset; - interface_unlock_shared(thiz); - *pPreset = preset; - result = SL_RESULT_SUCCESS; -#else - uint16_t preset = 0; - if (NO_EQ(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = - android_eq_getParam(thiz->mEqEffect, EQ_PARAM_CUR_PRESET, 0, &preset); - result = android_fx_statusToResult(status); - } - interface_unlock_shared(thiz); - - if (preset < 0) { - *pPreset = SL_EQUALIZER_UNDEFINED; - } else { - *pPreset = (SLuint16) preset; - } -#endif - - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEqualizer_UsePreset(SLEqualizerItf self, SLuint16 index) -{ - SL_ENTER_INTERFACE - SL_LOGV("Equalizer::UsePreset index=%u", index); - - IEqualizer *thiz = (IEqualizer *) self; - if (index >= thiz->mNumPresets) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - interface_lock_exclusive(thiz); -#if !defined(ANDROID) - SLuint16 band; - for (band = 0; band < thiz->mNumBands; ++band) - thiz->mLevels[band] = EqualizerPresets[index].mLevels[band]; - thiz->mPreset = index; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; -#else - if (NO_EQ(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = - android_eq_setParam(thiz->mEqEffect, EQ_PARAM_CUR_PRESET, 0, &index); - result = android_fx_statusToResult(status); - } - interface_unlock_shared(thiz); -#endif - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEqualizer_GetNumberOfPresets(SLEqualizerItf self, SLuint16 *pNumPresets) -{ - SL_ENTER_INTERFACE - - if (NULL == pNumPresets) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEqualizer *thiz = (IEqualizer *) self; - // Note: no lock, but OK because it is const - *pNumPresets = thiz->mNumPresets; - - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IEqualizer_GetPresetName(SLEqualizerItf self, SLuint16 index, const SLchar **ppName) -{ - SL_ENTER_INTERFACE - - if (NULL == ppName) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IEqualizer *thiz = (IEqualizer *) self; -#if !defined(ANDROID) - if (index >= thiz->mNumPresets) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - *ppName = (SLchar *) thiz->mPresets[index].mName; - result = SL_RESULT_SUCCESS; - } -#else - if (index >= thiz->mNumPresets) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - // FIXME query preset name rather than retrieve it from the engine. - // In SL ES 1.0.1, the strings must exist for the lifetime of the engine. - // Starting in 1.1, this will change and we don't need to hold onto the strings - // for so long as they will copied into application space. - *ppName = (SLchar *) thiz->mThis->mEngine->mEqPresetNames[index]; - result = SL_RESULT_SUCCESS; - } -#endif - } - - SL_LEAVE_INTERFACE -} - - -static const struct SLEqualizerItf_ IEqualizer_Itf = { - IEqualizer_SetEnabled, - IEqualizer_IsEnabled, - IEqualizer_GetNumberOfBands, - IEqualizer_GetBandLevelRange, - IEqualizer_SetBandLevel, - IEqualizer_GetBandLevel, - IEqualizer_GetCenterFreq, - IEqualizer_GetBandFreqRange, - IEqualizer_GetBand, - IEqualizer_GetCurrentPreset, - IEqualizer_UsePreset, - IEqualizer_GetNumberOfPresets, - IEqualizer_GetPresetName -}; - -void IEqualizer_init(void *self) -{ - IEqualizer *thiz = (IEqualizer *) self; - thiz->mItf = &IEqualizer_Itf; - thiz->mEnabled = SL_BOOLEAN_FALSE; - thiz->mPreset = SL_EQUALIZER_UNDEFINED; -#if 0 < MAX_EQ_BANDS - unsigned band; - for (band = 0; band < MAX_EQ_BANDS; ++band) - thiz->mLevels[band] = 0; -#endif - // const fields - thiz->mNumPresets = 0; - thiz->mNumBands = 0; -#if !defined(ANDROID) - thiz->mBands = EqualizerBands; - thiz->mPresets = EqualizerPresets; -#endif - thiz->mBandLevelRangeMin = 0; - thiz->mBandLevelRangeMax = 0; -#if defined(ANDROID) - memset(&thiz->mEqDescriptor, 0, sizeof(effect_descriptor_t)); - // placement new (explicit constructor) - (void) new (&thiz->mEqEffect) android::sp<android::AudioEffect>(); -#endif -} - -void IEqualizer_deinit(void *self) -{ -#if defined(ANDROID) - IEqualizer *thiz = (IEqualizer *) self; - // explicit destructor - thiz->mEqEffect.~sp(); -#endif -} - -bool IEqualizer_Expose(void *self) -{ -#if defined(ANDROID) - IEqualizer *thiz = (IEqualizer *) self; - if (!android_fx_initEffectDescriptor(SL_IID_EQUALIZER, &thiz->mEqDescriptor)) { - SL_LOGE("Equalizer initialization failed"); - thiz->mNumPresets = 0; - thiz->mNumBands = 0; - thiz->mBandLevelRangeMin = 0; - thiz->mBandLevelRangeMax = 0; - return false; - } -#endif - return true; -} diff --git a/wilhelm/src/itf/ILEDArray.c b/wilhelm/src/itf/ILEDArray.c deleted file mode 100644 index 57938cc4..00000000 --- a/wilhelm/src/itf/ILEDArray.c +++ /dev/null @@ -1,123 +0,0 @@ -/* - * 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. - */ - -/* LEDArray implementation */ - -#include "sles_allinclusive.h" - - -static SLresult ILEDArray_ActivateLEDArray(SLLEDArrayItf self, SLuint32 lightMask) -{ - SL_ENTER_INTERFACE - - ILEDArray *thiz = (ILEDArray *) self; - interface_lock_poke(thiz); - thiz->mLightMask = lightMask; - interface_unlock_poke(thiz); - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static SLresult ILEDArray_IsLEDArrayActivated(SLLEDArrayItf self, SLuint32 *pLightMask) -{ - SL_ENTER_INTERFACE - - if (NULL == pLightMask) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - ILEDArray *thiz = (ILEDArray *) self; - interface_lock_peek(thiz); - SLuint32 lightMask = thiz->mLightMask; - interface_unlock_peek(thiz); - *pLightMask = lightMask; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult ILEDArray_SetColor(SLLEDArrayItf self, SLuint8 index, const SLHSL *pColor) -{ - SL_ENTER_INTERFACE - - result = SL_RESULT_PARAMETER_INVALID; - do { - if (!(index < MAX_LED_COUNT) || NULL == pColor) - break; - SLHSL color = *pColor; - if (!(0 <= color.hue && color.hue <= 360000)) - break; - if (!(0 <= color.saturation && color.saturation <= 1000)) - break; - if (!(0 <= color.lightness && color.lightness <= 1000)) - break; - ILEDArray *thiz = (ILEDArray *) self; - // can't use poke because struct copy might not be atomic - interface_lock_exclusive(thiz); - thiz->mColors[index] = color; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - } while (0); - - SL_LEAVE_INTERFACE -} - - -static SLresult ILEDArray_GetColor(SLLEDArrayItf self, SLuint8 index, SLHSL *pColor) -{ - SL_ENTER_INTERFACE - - if (!(index < MAX_LED_COUNT) || NULL == pColor) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - ILEDArray *thiz = (ILEDArray *) self; - // can't use peek because struct copy might not be atomic - interface_lock_shared(thiz); - SLHSL color = thiz->mColors[index]; - interface_unlock_shared(thiz); - *pColor = color; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static const struct SLLEDArrayItf_ ILEDArray_Itf = { - ILEDArray_ActivateLEDArray, - ILEDArray_IsLEDArrayActivated, - ILEDArray_SetColor, - ILEDArray_GetColor -}; - -void ILEDArray_init(void *self) -{ - ILEDArray *thiz = (ILEDArray *) self; - thiz->mItf = &ILEDArray_Itf; - thiz->mLightMask = 0; - SLHSL *color = thiz->mColors; - SLuint8 index; - for (index = 0; index < MAX_LED_COUNT; ++index, ++color) { - color->hue = 0; // red, but per specification 1.0.1 pg. 259: "Default color is undefined." - color->saturation = 1000; - color->lightness = 1000; - } - // const - thiz->mCount = MAX_LED_COUNT; -} diff --git a/wilhelm/src/itf/IMIDIMessage.c b/wilhelm/src/itf/IMIDIMessage.c deleted file mode 100644 index 1657bc34..00000000 --- a/wilhelm/src/itf/IMIDIMessage.c +++ /dev/null @@ -1,132 +0,0 @@ -/* - * 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. - */ - -/* MIDIMessage implementation */ - -#include "sles_allinclusive.h" - - -static SLresult IMIDIMessage_SendMessage(SLMIDIMessageItf self, const SLuint8 *data, - SLuint32 length) -{ - SL_ENTER_INTERFACE - - if (NULL == data) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - //IMIDIMessage *thiz = (IMIDIMessage *) self; - result = SL_RESULT_FEATURE_UNSUPPORTED; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMIDIMessage_RegisterMetaEventCallback(SLMIDIMessageItf self, - slMetaEventCallback callback, void *pContext) -{ - SL_ENTER_INTERFACE - - IMIDIMessage *thiz = (IMIDIMessage *) self; - interface_lock_exclusive(thiz); - thiz->mMetaEventCallback = callback; - thiz->mMetaEventContext = pContext; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static SLresult IMIDIMessage_RegisterMIDIMessageCallback(SLMIDIMessageItf self, - slMIDIMessageCallback callback, void *pContext) -{ - SL_ENTER_INTERFACE - - IMIDIMessage *thiz = (IMIDIMessage *) self; - interface_lock_exclusive(thiz); - thiz->mMessageCallback = callback; - thiz->mMessageContext = pContext; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static SLresult IMIDIMessage_AddMIDIMessageCallbackFilter(SLMIDIMessageItf self, - SLuint32 messageType) -{ - SL_ENTER_INTERFACE - - switch (messageType) { - case SL_MIDIMESSAGETYPE_NOTE_ON_OFF: - case SL_MIDIMESSAGETYPE_POLY_PRESSURE: - case SL_MIDIMESSAGETYPE_CONTROL_CHANGE: - case SL_MIDIMESSAGETYPE_PROGRAM_CHANGE: - case SL_MIDIMESSAGETYPE_CHANNEL_PRESSURE: - case SL_MIDIMESSAGETYPE_PITCH_BEND: - case SL_MIDIMESSAGETYPE_SYSTEM_MESSAGE: - { - SLuint8 messageTypeMask = 1 << messageType; - IMIDIMessage *thiz = (IMIDIMessage *) self; - interface_lock_exclusive(thiz); - thiz->mMessageTypes |= messageTypeMask; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - } - break; - default: - result = SL_RESULT_PARAMETER_INVALID; - break; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMIDIMessage_ClearMIDIMessageCallbackFilter(SLMIDIMessageItf self) -{ - SL_ENTER_INTERFACE - - IMIDIMessage *thiz = (IMIDIMessage *) self; - interface_lock_exclusive(thiz); - thiz->mMessageTypes = 0; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static const struct SLMIDIMessageItf_ IMIDIMessage_Itf = { - IMIDIMessage_SendMessage, - IMIDIMessage_RegisterMetaEventCallback, - IMIDIMessage_RegisterMIDIMessageCallback, - IMIDIMessage_AddMIDIMessageCallbackFilter, - IMIDIMessage_ClearMIDIMessageCallbackFilter -}; - -void IMIDIMessage_init(void *self) -{ - IMIDIMessage *thiz = (IMIDIMessage *) self; - thiz->mItf = &IMIDIMessage_Itf; - thiz->mMetaEventCallback = NULL; - thiz->mMetaEventContext = NULL; - thiz->mMessageCallback = NULL; - thiz->mMessageContext = NULL; - thiz->mMessageTypes = 0; -} diff --git a/wilhelm/src/itf/IMIDIMuteSolo.c b/wilhelm/src/itf/IMIDIMuteSolo.c deleted file mode 100644 index ceb7d769..00000000 --- a/wilhelm/src/itf/IMIDIMuteSolo.c +++ /dev/null @@ -1,233 +0,0 @@ -/* - * 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. - */ - -/* MIDIMuteSolo implementation */ - -#include "sles_allinclusive.h" - - -static SLresult IMIDIMuteSolo_SetChannelMute(SLMIDIMuteSoloItf self, SLuint8 channel, - SLboolean mute) -{ - SL_ENTER_INTERFACE - - if (channel > 15) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IMIDIMuteSolo *thiz = (IMIDIMuteSolo *) self; - SLuint16 mask = 1 << channel; - interface_lock_exclusive(thiz); - if (mute) - thiz->mChannelMuteMask |= mask; - else - thiz->mChannelMuteMask &= ~mask; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMIDIMuteSolo_GetChannelMute(SLMIDIMuteSoloItf self, SLuint8 channel, - SLboolean *pMute) -{ - SL_ENTER_INTERFACE - - if (channel > 15 || (NULL == pMute)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IMIDIMuteSolo *thiz = (IMIDIMuteSolo *) self; - interface_lock_peek(thiz); - SLuint16 mask = thiz->mChannelMuteMask; - interface_unlock_peek(thiz); - *pMute = (mask >> channel) & 1; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMIDIMuteSolo_SetChannelSolo(SLMIDIMuteSoloItf self, SLuint8 channel, - SLboolean solo) -{ - SL_ENTER_INTERFACE - - if (channel > 15) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IMIDIMuteSolo *thiz = (IMIDIMuteSolo *) self; - SLuint16 mask = 1 << channel; - interface_lock_exclusive(thiz); - if (solo) - thiz->mChannelSoloMask |= mask; - else - thiz->mChannelSoloMask &= ~mask; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMIDIMuteSolo_GetChannelSolo(SLMIDIMuteSoloItf self, SLuint8 channel, - SLboolean *pSolo) -{ - SL_ENTER_INTERFACE - - if (channel > 15 || (NULL == pSolo)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IMIDIMuteSolo *thiz = (IMIDIMuteSolo *) self; - interface_lock_peek(thiz); - SLuint16 mask = thiz->mChannelSoloMask; - interface_unlock_peek(thiz); - *pSolo = (mask >> channel) & 1; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMIDIMuteSolo_GetTrackCount(SLMIDIMuteSoloItf self, SLuint16 *pCount) -{ - SL_ENTER_INTERFACE - - if (NULL == pCount) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IMIDIMuteSolo *thiz = (IMIDIMuteSolo *) self; - // const, so no lock needed - SLuint16 trackCount = thiz->mTrackCount; - *pCount = trackCount; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMIDIMuteSolo_SetTrackMute(SLMIDIMuteSoloItf self, SLuint16 track, SLboolean mute) -{ - SL_ENTER_INTERFACE - - IMIDIMuteSolo *thiz = (IMIDIMuteSolo *) self; - // const - if (!(track < thiz->mTrackCount)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - SLuint32 mask = 1 << track; - interface_lock_exclusive(thiz); - if (mute) - thiz->mTrackMuteMask |= mask; - else - thiz->mTrackMuteMask &= ~mask; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMIDIMuteSolo_GetTrackMute(SLMIDIMuteSoloItf self, SLuint16 track, SLboolean *pMute) -{ - SL_ENTER_INTERFACE - - IMIDIMuteSolo *thiz = (IMIDIMuteSolo *) self; - // const, no lock needed - if (!(track < thiz->mTrackCount) || NULL == pMute) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - interface_lock_peek(thiz); - SLuint32 mask = thiz->mTrackMuteMask; - interface_unlock_peek(thiz); - *pMute = (mask >> track) & 1; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMIDIMuteSolo_SetTrackSolo(SLMIDIMuteSoloItf self, SLuint16 track, SLboolean solo) -{ - SL_ENTER_INTERFACE - - IMIDIMuteSolo *thiz = (IMIDIMuteSolo *) self; - // const - if (!(track < thiz->mTrackCount)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - SLuint32 mask = 1 << track; interface_lock_exclusive(thiz); - if (solo) - thiz->mTrackSoloMask |= mask; - else - thiz->mTrackSoloMask &= ~mask; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMIDIMuteSolo_GetTrackSolo(SLMIDIMuteSoloItf self, SLuint16 track, SLboolean *pSolo) -{ - SL_ENTER_INTERFACE - - IMIDIMuteSolo *thiz = (IMIDIMuteSolo *) self; - // const, no lock needed - if (!(track < thiz->mTrackCount) || NULL == pSolo) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - interface_lock_peek(thiz); - SLuint32 mask = thiz->mTrackSoloMask; - interface_unlock_peek(thiz); - *pSolo = (mask >> track) & 1; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static const struct SLMIDIMuteSoloItf_ IMIDIMuteSolo_Itf = { - IMIDIMuteSolo_SetChannelMute, - IMIDIMuteSolo_GetChannelMute, - IMIDIMuteSolo_SetChannelSolo, - IMIDIMuteSolo_GetChannelSolo, - IMIDIMuteSolo_GetTrackCount, - IMIDIMuteSolo_SetTrackMute, - IMIDIMuteSolo_GetTrackMute, - IMIDIMuteSolo_SetTrackSolo, - IMIDIMuteSolo_GetTrackSolo -}; - -void IMIDIMuteSolo_init(void *self) -{ - IMIDIMuteSolo *thiz = (IMIDIMuteSolo *) self; - thiz->mItf = &IMIDIMuteSolo_Itf; - thiz->mChannelMuteMask = 0; - thiz->mChannelSoloMask = 0; - thiz->mTrackMuteMask = 0; - thiz->mTrackSoloMask = 0; - // const - thiz->mTrackCount = 32; // wrong -} diff --git a/wilhelm/src/itf/IMIDITempo.c b/wilhelm/src/itf/IMIDITempo.c deleted file mode 100644 index 831fda9e..00000000 --- a/wilhelm/src/itf/IMIDITempo.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * 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. - */ - -/* MIDITempo implementation */ - -#include "sles_allinclusive.h" - - -static SLresult IMIDITempo_SetTicksPerQuarterNote(SLMIDITempoItf self, SLuint32 tpqn) -{ - SL_ENTER_INTERFACE - - if (!(1 <= tpqn && tpqn <= 32767)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IMIDITempo *thiz = (IMIDITempo *) self; - interface_lock_poke(thiz); - thiz->mTicksPerQuarterNote = tpqn; - interface_unlock_poke(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMIDITempo_GetTicksPerQuarterNote(SLMIDITempoItf self, SLuint32 *pTpqn) -{ - SL_ENTER_INTERFACE - - if (NULL == pTpqn) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IMIDITempo *thiz = (IMIDITempo *) self; - interface_lock_peek(thiz); - SLuint32 ticksPerQuarterNote = thiz->mTicksPerQuarterNote; - interface_unlock_peek(thiz); - *pTpqn = ticksPerQuarterNote; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMIDITempo_SetMicrosecondsPerQuarterNote(SLMIDITempoItf self, SLmicrosecond uspqn) -{ - SL_ENTER_INTERFACE - - // spec says zero, is that correct? - if (!(1 <= uspqn && uspqn <= 16777215)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IMIDITempo *thiz = (IMIDITempo *) self; - interface_lock_poke(thiz); - thiz->mMicrosecondsPerQuarterNote = uspqn; - interface_unlock_poke(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMIDITempo_GetMicrosecondsPerQuarterNote(SLMIDITempoItf self, SLmicrosecond *uspqn) -{ - SL_ENTER_INTERFACE - - if (NULL == uspqn) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IMIDITempo *thiz = (IMIDITempo *) self; - interface_lock_peek(thiz); - SLuint32 microsecondsPerQuarterNote = thiz->mMicrosecondsPerQuarterNote; - interface_unlock_peek(thiz); - *uspqn = microsecondsPerQuarterNote; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static const struct SLMIDITempoItf_ IMIDITempo_Itf = { - IMIDITempo_SetTicksPerQuarterNote, - IMIDITempo_GetTicksPerQuarterNote, - IMIDITempo_SetMicrosecondsPerQuarterNote, - IMIDITempo_GetMicrosecondsPerQuarterNote -}; - -void IMIDITempo_init(void *self) -{ - IMIDITempo *thiz = (IMIDITempo *) self; - thiz->mItf = &IMIDITempo_Itf; - thiz->mTicksPerQuarterNote = 32; // wrong - thiz->mMicrosecondsPerQuarterNote = 100; // wrong -} diff --git a/wilhelm/src/itf/IMIDITime.c b/wilhelm/src/itf/IMIDITime.c deleted file mode 100644 index 312e4bc8..00000000 --- a/wilhelm/src/itf/IMIDITime.c +++ /dev/null @@ -1,136 +0,0 @@ -/* - * 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. - */ - -/* MIDITime implementation */ - -#include "sles_allinclusive.h" - - -static SLresult IMIDITime_GetDuration(SLMIDITimeItf self, SLuint32 *pDuration) -{ - SL_ENTER_INTERFACE - - if (NULL == pDuration) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IMIDITime *thiz = (IMIDITime *) self; - SLuint32 duration = thiz->mDuration; - *pDuration = duration; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMIDITime_SetPosition(SLMIDITimeItf self, SLuint32 position) -{ - SL_ENTER_INTERFACE - - IMIDITime *thiz = (IMIDITime *) self; - // const, no lock needed - if (!(position < thiz->mDuration)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - interface_lock_poke(thiz); - thiz->mPosition = position; - interface_unlock_poke(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMIDITime_GetPosition(SLMIDITimeItf self, SLuint32 *pPosition) -{ - SL_ENTER_INTERFACE - - if (NULL == pPosition) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IMIDITime *thiz = (IMIDITime *) self; - interface_lock_peek(thiz); - SLuint32 position = thiz->mPosition; - interface_unlock_peek(thiz); - *pPosition = position; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMIDITime_SetLoopPoints(SLMIDITimeItf self, SLuint32 startTick, SLuint32 numTicks) -{ - SL_ENTER_INTERFACE - - IMIDITime *thiz = (IMIDITime *) self; - // const, no lock needed - SLuint32 duration = thiz->mDuration; - if (!((startTick < duration) && (numTicks <= duration - startTick))) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - interface_lock_exclusive(thiz); - thiz->mStartTick = startTick; - thiz->mNumTicks = numTicks; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMIDITime_GetLoopPoints(SLMIDITimeItf self, SLuint32 *pStartTick, - SLuint32 *pNumTicks) -{ - SL_ENTER_INTERFACE - - if (NULL == pStartTick || NULL == pNumTicks) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IMIDITime *thiz = (IMIDITime *) self; - interface_lock_shared(thiz); - SLuint32 startTick = thiz->mStartTick; - SLuint32 numTicks = thiz->mNumTicks; - interface_unlock_shared(thiz); - *pStartTick = startTick; - *pNumTicks = numTicks; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static const struct SLMIDITimeItf_ IMIDITime_Itf = { - IMIDITime_GetDuration, - IMIDITime_SetPosition, - IMIDITime_GetPosition, - IMIDITime_SetLoopPoints, - IMIDITime_GetLoopPoints -}; - -void IMIDITime_init(void *self) -{ - IMIDITime *thiz = (IMIDITime *) self; - thiz->mItf = &IMIDITime_Itf; - thiz->mDuration = 0; - thiz->mPosition = 0; - thiz->mStartTick = 0; - thiz->mNumTicks = 0; -} diff --git a/wilhelm/src/itf/IMetadataExtraction.c b/wilhelm/src/itf/IMetadataExtraction.c deleted file mode 100644 index 1a6c24ee..00000000 --- a/wilhelm/src/itf/IMetadataExtraction.c +++ /dev/null @@ -1,205 +0,0 @@ -/* - * 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. - */ - -/* MetadataExtraction implementation */ - -#include "sles_allinclusive.h" - - -static SLresult IMetadataExtraction_GetItemCount(SLMetadataExtractionItf self, SLuint32 *pItemCount) -{ - SL_ENTER_INTERFACE - - if (NULL == pItemCount) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IMetadataExtraction *thiz = (IMetadataExtraction *) self; - if (SL_OBJECTID_AUDIOPLAYER == InterfaceToObjectID(thiz)) { -#ifdef ANDROID - result = android_audioPlayer_metadata_getItemCount((CAudioPlayer *)thiz->mThis, - pItemCount); -#else - result = SL_RESULT_FEATURE_UNSUPPORTED; -#endif - } else { - result = SL_RESULT_PARAMETER_INVALID; - } - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMetadataExtraction_GetKeySize(SLMetadataExtractionItf self, - SLuint32 index, SLuint32 *pKeySize) -{ - SL_ENTER_INTERFACE - - if (NULL == pKeySize) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IMetadataExtraction *thiz = (IMetadataExtraction *) self; - if (SL_OBJECTID_AUDIOPLAYER == InterfaceToObjectID(thiz)) { -#ifdef ANDROID - result = android_audioPlayer_metadata_getKeySize((CAudioPlayer *)thiz->mThis, - index, pKeySize); -#else - result = SL_RESULT_FEATURE_UNSUPPORTED; -#endif - } else { - result = SL_RESULT_PARAMETER_INVALID; - } - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMetadataExtraction_GetKey(SLMetadataExtractionItf self, - SLuint32 index, SLuint32 keySize, SLMetadataInfo *pKey) -{ - SL_ENTER_INTERFACE - - if (NULL == pKey) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IMetadataExtraction *thiz = (IMetadataExtraction *) self; - if (SL_OBJECTID_AUDIOPLAYER == InterfaceToObjectID(thiz)) { -#ifdef ANDROID - result = android_audioPlayer_metadata_getKey((CAudioPlayer *)thiz->mThis, - index, keySize, pKey); -#else - result = SL_RESULT_FEATURE_UNSUPPORTED; -#endif - } else { - result = SL_RESULT_PARAMETER_INVALID; - } - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMetadataExtraction_GetValueSize(SLMetadataExtractionItf self, - SLuint32 index, SLuint32 *pValueSize) -{ - SL_ENTER_INTERFACE - - if (NULL == pValueSize) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IMetadataExtraction *thiz = (IMetadataExtraction *) self; - if (SL_OBJECTID_AUDIOPLAYER == InterfaceToObjectID(thiz)) { -#ifdef ANDROID - result = android_audioPlayer_metadata_getValueSize((CAudioPlayer *)thiz->mThis, - index, pValueSize); -#else - result = SL_RESULT_FEATURE_UNSUPPORTED; -#endif - } else { - result = SL_RESULT_PARAMETER_INVALID; - } - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMetadataExtraction_GetValue(SLMetadataExtractionItf self, - SLuint32 index, SLuint32 valueSize, SLMetadataInfo *pValue) -{ - SL_ENTER_INTERFACE - - if (NULL == pValue) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IMetadataExtraction *thiz = (IMetadataExtraction *) self; - if (SL_OBJECTID_AUDIOPLAYER == InterfaceToObjectID(thiz)) { -#ifdef ANDROID - result = android_audioPlayer_metadata_getValue((CAudioPlayer *)thiz->mThis, - index, valueSize, pValue); -#else - result = SL_RESULT_FEATURE_UNSUPPORTED; -#endif - } else { - result = SL_RESULT_PARAMETER_INVALID; - } - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMetadataExtraction_AddKeyFilter(SLMetadataExtractionItf self, - SLuint32 keySize, const void *pKey, SLuint32 keyEncoding, - const SLchar *pValueLangCountry, SLuint32 valueEncoding, SLuint8 filterMask) -{ - SL_ENTER_INTERFACE - - if (NULL == pKey || NULL == pValueLangCountry || (filterMask & ~(SL_METADATA_FILTER_KEY | - SL_METADATA_FILTER_KEY | SL_METADATA_FILTER_KEY))) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IMetadataExtraction *thiz = (IMetadataExtraction *) self; - interface_lock_exclusive(thiz); - thiz->mKeySize = keySize; - thiz->mKey = pKey; - thiz->mKeyEncoding = keyEncoding; - thiz->mValueLangCountry = pValueLangCountry; // should make a local copy - thiz->mValueEncoding = valueEncoding; - thiz->mFilterMask = filterMask; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMetadataExtraction_ClearKeyFilter(SLMetadataExtractionItf self) -{ - SL_ENTER_INTERFACE - - IMetadataExtraction *thiz = (IMetadataExtraction *) self; - thiz->mKeyFilter = 0; - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static const struct SLMetadataExtractionItf_ IMetadataExtraction_Itf = { - IMetadataExtraction_GetItemCount, - IMetadataExtraction_GetKeySize, - IMetadataExtraction_GetKey, - IMetadataExtraction_GetValueSize, - IMetadataExtraction_GetValue, - IMetadataExtraction_AddKeyFilter, - IMetadataExtraction_ClearKeyFilter -}; - -void IMetadataExtraction_init(void *self) -{ - IMetadataExtraction *thiz = (IMetadataExtraction *) self; - thiz->mItf = &IMetadataExtraction_Itf; - thiz->mKeySize = 0; - thiz->mKey = NULL; - thiz->mKeyEncoding = 0 /*TBD*/; - thiz->mValueLangCountry = 0 /*TBD*/; - thiz->mValueEncoding = 0 /*TBD*/; - thiz->mFilterMask = 0 /*TBD*/; - thiz->mKeyFilter = 0; -} diff --git a/wilhelm/src/itf/IMetadataTraversal.c b/wilhelm/src/itf/IMetadataTraversal.c deleted file mode 100644 index 2432b9a7..00000000 --- a/wilhelm/src/itf/IMetadataTraversal.c +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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. - */ - -/* MetadataTraversal implementation */ - -#include "sles_allinclusive.h" - - -static SLresult IMetadataTraversal_SetMode(SLMetadataTraversalItf self, SLuint32 mode) -{ - SL_ENTER_INTERFACE - - switch (mode) { - case SL_METADATATRAVERSALMODE_ALL: - case SL_METADATATRAVERSALMODE_NODE: - { - IMetadataTraversal *thiz = (IMetadataTraversal *) self; - interface_lock_poke(thiz); - thiz->mMode = mode; - interface_unlock_poke(thiz); - result = SL_RESULT_SUCCESS; - } - break; - default: - result = SL_RESULT_PARAMETER_INVALID; - break; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMetadataTraversal_GetChildCount(SLMetadataTraversalItf self, SLuint32 *pCount) -{ - SL_ENTER_INTERFACE - - if (NULL == pCount) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IMetadataTraversal *thiz = (IMetadataTraversal *) self; - interface_lock_peek(thiz); - SLuint32 count = thiz->mCount; - interface_unlock_peek(thiz); - *pCount = count; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMetadataTraversal_GetChildMIMETypeSize( - SLMetadataTraversalItf self, SLuint32 index, SLuint32 *pSize) -{ - SL_ENTER_INTERFACE - - if (NULL == pSize) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IMetadataTraversal *thiz = (IMetadataTraversal *) self; - interface_lock_peek(thiz); - SLuint32 size = thiz->mSize; - interface_unlock_peek(thiz); - *pSize = size; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMetadataTraversal_GetChildInfo(SLMetadataTraversalItf self, SLuint32 index, - SLint32 *pNodeID, SLuint32 *pType, SLuint32 size, SLchar *pMimeType) -{ - SL_ENTER_INTERFACE - - //IMetadataTraversal *thiz = (IMetadataTraversal *) self; - result = SL_RESULT_FEATURE_UNSUPPORTED; - - SL_LEAVE_INTERFACE -} - - -static SLresult IMetadataTraversal_SetActiveNode(SLMetadataTraversalItf self, SLuint32 index) -{ - SL_ENTER_INTERFACE - - if (SL_NODE_PARENT == index) { - ; - } - IMetadataTraversal *thiz = (IMetadataTraversal *) self; - thiz->mIndex = index; - result = SL_RESULT_PARAMETER_INVALID; - - SL_LEAVE_INTERFACE -} - - -static const struct SLMetadataTraversalItf_ IMetadataTraversal_Itf = { - IMetadataTraversal_SetMode, - IMetadataTraversal_GetChildCount, - IMetadataTraversal_GetChildMIMETypeSize, - IMetadataTraversal_GetChildInfo, - IMetadataTraversal_SetActiveNode -}; - -void IMetadataTraversal_init(void *self) -{ - IMetadataTraversal *thiz = (IMetadataTraversal *) self; - thiz->mItf = &IMetadataTraversal_Itf; - thiz->mIndex = 0; - thiz->mMode = SL_METADATATRAVERSALMODE_NODE; - thiz->mCount = 0; - thiz->mSize = 0; -} diff --git a/wilhelm/src/itf/IMuteSolo.c b/wilhelm/src/itf/IMuteSolo.c deleted file mode 100644 index 46608e88..00000000 --- a/wilhelm/src/itf/IMuteSolo.c +++ /dev/null @@ -1,204 +0,0 @@ -/* - * 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. - */ - -/* MuteSolo implementation */ - -#include "sles_allinclusive.h" - - -static SLresult IMuteSolo_SetChannelMute(SLMuteSoloItf self, SLuint8 chan, SLboolean mute) -{ - SL_ENTER_INTERFACE - - IMuteSolo *thiz = (IMuteSolo *) self; - IObject *thisObject = thiz->mThis; - if (SL_OBJECTID_AUDIOPLAYER != IObjectToObjectID(thisObject)) { - result = SL_RESULT_FEATURE_UNSUPPORTED; - } else { - CAudioPlayer *ap = (CAudioPlayer *) thisObject; - interface_lock_exclusive(thiz); - SLuint8 numChannels = ap->mNumChannels; - if (1 >= numChannels) { - interface_unlock_exclusive(thiz); - result = SL_RESULT_FEATURE_UNSUPPORTED; - } else if (numChannels <= chan) { - interface_unlock_exclusive(thiz); - result = SL_RESULT_PARAMETER_INVALID; - } else { - SLuint8 mask = 1 << chan; - SLuint8 oldMuteMask = ap->mMuteMask; - if (mute) { - ap->mMuteMask |= mask; - } else { - ap->mMuteMask &= ~mask; - } - interface_unlock_exclusive_attributes(thiz, oldMuteMask != ap->mMuteMask ? ATTR_GAIN : - ATTR_NONE); - result = SL_RESULT_SUCCESS; - } - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMuteSolo_GetChannelMute(SLMuteSoloItf self, SLuint8 chan, SLboolean *pMute) -{ - SL_ENTER_INTERFACE - - if (NULL == pMute) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IMuteSolo *thiz = (IMuteSolo *) self; - IObject *thisObject = thiz->mThis; - if (SL_OBJECTID_AUDIOPLAYER != IObjectToObjectID(thisObject)) { - result = SL_RESULT_FEATURE_UNSUPPORTED; - } else { - CAudioPlayer *ap = (CAudioPlayer *) thisObject; - SLboolean mute; - interface_lock_shared(thiz); - SLuint8 numChannels = ap->mNumChannels; - if (1 >= numChannels) { - mute = SL_BOOLEAN_FALSE; - result = SL_RESULT_FEATURE_UNSUPPORTED; - } else if (numChannels <= chan) { - mute = SL_BOOLEAN_FALSE; - result = SL_RESULT_PARAMETER_INVALID; - } else { - SLuint8 mask = ap->mMuteMask; - mute = (SLboolean) ((mask >> chan) & 1); - result = SL_RESULT_SUCCESS; - } - interface_unlock_shared(thiz); - *pMute = mute; - } - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMuteSolo_SetChannelSolo(SLMuteSoloItf self, SLuint8 chan, SLboolean solo) -{ - SL_ENTER_INTERFACE - - IMuteSolo *thiz = (IMuteSolo *) self; - IObject *thisObject = thiz->mThis; - if (SL_OBJECTID_AUDIOPLAYER != IObjectToObjectID(thisObject)) { - result = SL_RESULT_FEATURE_UNSUPPORTED; - } else { - CAudioPlayer *ap = (CAudioPlayer *) thisObject; - interface_lock_exclusive(thiz); - SLuint8 numChannels = ap->mNumChannels; - if (1 >= numChannels) { - interface_unlock_exclusive(thiz); - result = SL_RESULT_FEATURE_UNSUPPORTED; - } else if (numChannels <= chan) { - interface_unlock_exclusive(thiz); - result = SL_RESULT_PARAMETER_INVALID; - } else { - SLuint8 mask = 1 << chan; - SLuint8 oldSoloMask = ap->mSoloMask; - if (solo) { - ap->mSoloMask |= mask; - } else { - ap->mSoloMask &= ~mask; - } - interface_unlock_exclusive_attributes(thiz, oldSoloMask != ap->mSoloMask ? ATTR_GAIN : - ATTR_NONE); - result = SL_RESULT_SUCCESS; - } - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMuteSolo_GetChannelSolo(SLMuteSoloItf self, SLuint8 chan, SLboolean *pSolo) -{ - SL_ENTER_INTERFACE - - if (NULL == pSolo) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IMuteSolo *thiz = (IMuteSolo *) self; - IObject *thisObject = thiz->mThis; - if (SL_OBJECTID_AUDIOPLAYER != IObjectToObjectID(thisObject)) { - result = SL_RESULT_FEATURE_UNSUPPORTED; - } else { - CAudioPlayer *ap = (CAudioPlayer *) thisObject; - SLboolean solo; - interface_lock_shared(thiz); - SLuint8 numChannels = ap->mNumChannels; - if (1 >= numChannels) { - solo = SL_BOOLEAN_FALSE; - result = SL_RESULT_FEATURE_UNSUPPORTED; - } else if (numChannels <= chan) { - solo = SL_BOOLEAN_FALSE; - result = SL_RESULT_PARAMETER_INVALID; - } else { - SLuint8 mask = ap->mSoloMask; - solo = (SLboolean) ((mask >> chan) & 1); - result = SL_RESULT_SUCCESS; - } - interface_unlock_shared(thiz); - *pSolo = solo; - } - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IMuteSolo_GetNumChannels(SLMuteSoloItf self, SLuint8 *pNumChannels) -{ - SL_ENTER_INTERFACE - - if (NULL == pNumChannels) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IMuteSolo *thiz = (IMuteSolo *) self; - IObject *thisObject = thiz->mThis; - if (SL_OBJECTID_AUDIOPLAYER != IObjectToObjectID(thisObject)) { - result = SL_RESULT_FEATURE_UNSUPPORTED; - } else { - CAudioPlayer *ap = (CAudioPlayer *) thisObject; - object_lock_shared(thisObject); - SLuint8 numChannels = ap->mNumChannels; - object_unlock_shared(thisObject); - *pNumChannels = numChannels; - // spec errata says to return 0 (== UNKNOWN_NUMCHANNELS) if channel count is unknown - result = SL_RESULT_SUCCESS; - } - } - - SL_LEAVE_INTERFACE -} - - -static const struct SLMuteSoloItf_ IMuteSolo_Itf = { - IMuteSolo_SetChannelMute, - IMuteSolo_GetChannelMute, - IMuteSolo_SetChannelSolo, - IMuteSolo_GetChannelSolo, - IMuteSolo_GetNumChannels -}; - -void IMuteSolo_init(void *self) -{ - IMuteSolo *thiz = (IMuteSolo *) self; - thiz->mItf = &IMuteSolo_Itf; -} diff --git a/wilhelm/src/itf/IObject.c b/wilhelm/src/itf/IObject.c deleted file mode 100644 index befe9390..00000000 --- a/wilhelm/src/itf/IObject.c +++ /dev/null @@ -1,825 +0,0 @@ -/* - * 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. - */ - -/* Object implementation */ - -#include "sles_allinclusive.h" - - -// Called by a worker thread to handle an asynchronous Object.Realize. -// Parameter self is the Object. - -static void HandleRealize(void *self, void *ignored, int unused) -{ - - // validate input parameters - IObject *thiz = (IObject *) self; - assert(NULL != thiz); - const ClassTable *clazz = thiz->mClass; - assert(NULL != clazz); - AsyncHook realize = clazz->mRealize; - SLresult result; - SLuint8 state; - - // check object state - object_lock_exclusive(thiz); - state = thiz->mState; - switch (state) { - - case SL_OBJECT_STATE_REALIZING_1: // normal case - if (NULL != realize) { - thiz->mState = SL_OBJECT_STATE_REALIZING_2; - // Note that the mutex is locked on entry to and exit from the realize hook, - // but the hook is permitted to temporarily unlock the mutex (e.g. for async). - result = (*realize)(thiz, SL_BOOLEAN_TRUE); - assert(SL_OBJECT_STATE_REALIZING_2 == thiz->mState); - state = SL_RESULT_SUCCESS == result ? SL_OBJECT_STATE_REALIZED : - SL_OBJECT_STATE_UNREALIZED; - } else { - result = SL_RESULT_SUCCESS; - state = SL_OBJECT_STATE_REALIZED; - } - break; - - case SL_OBJECT_STATE_REALIZING_1A: // operation was aborted while on work queue - result = SL_RESULT_OPERATION_ABORTED; - state = SL_OBJECT_STATE_UNREALIZED; - break; - - default: // impossible - assert(SL_BOOLEAN_FALSE); - result = SL_RESULT_INTERNAL_ERROR; - break; - - } - - // mutex is locked, update state - thiz->mState = state; - - // Make a copy of these, so we can call the callback with mutex unlocked - slObjectCallback callback = thiz->mCallback; - void *context = thiz->mContext; - object_unlock_exclusive(thiz); - - // Note that the mutex is unlocked during the callback - if (NULL != callback) { - (*callback)(&thiz->mItf, context, SL_OBJECT_EVENT_ASYNC_TERMINATION, result, state, NULL); - } -} - - -static SLresult IObject_Realize(SLObjectItf self, SLboolean async) -{ - SL_ENTER_INTERFACE - - IObject *thiz = (IObject *) self; - SLuint8 state; - const ClassTable *clazz = thiz->mClass; - bool isSharedEngine = false; - object_lock_exclusive(thiz); - // note that SL_OBJECTID_ENGINE and XA_OBJECTID_ENGINE map to same class - if (clazz == objectIDtoClass(SL_OBJECTID_ENGINE)) { - // important: the lock order is engine followed by theOneTrueMutex - int ok = pthread_mutex_lock(&theOneTrueMutex); - assert(0 == ok); - isSharedEngine = 1 < theOneTrueRefCount; - ok = pthread_mutex_unlock(&theOneTrueMutex); - assert(0 == ok); - } - state = thiz->mState; - // Reject redundant calls to Realize, except on a shared engine - if (SL_OBJECT_STATE_UNREALIZED != state) { - object_unlock_exclusive(thiz); - // redundant realize on the shared engine is permitted - if (isSharedEngine && (SL_OBJECT_STATE_REALIZED == state)) { - result = SL_RESULT_SUCCESS; - } else { - result = SL_RESULT_PRECONDITIONS_VIOLATED; - } - } else { - // Asynchronous: mark operation pending and cancellable - if (async && (SL_OBJECTID_ENGINE != clazz->mSLObjectID)) { - state = SL_OBJECT_STATE_REALIZING_1; - // Synchronous: mark operation pending and non-cancellable - } else { - state = SL_OBJECT_STATE_REALIZING_2; - } - thiz->mState = state; - switch (state) { - case SL_OBJECT_STATE_REALIZING_1: // asynchronous on non-Engine - object_unlock_exclusive(thiz); - assert(async); - result = ThreadPool_add_ppi(&thiz->mEngine->mThreadPool, HandleRealize, thiz, NULL, 0); - if (SL_RESULT_SUCCESS != result) { - // Engine was destroyed during realize, or insufficient memory - object_lock_exclusive(thiz); - thiz->mState = SL_OBJECT_STATE_UNREALIZED; - object_unlock_exclusive(thiz); - } - break; - case SL_OBJECT_STATE_REALIZING_2: // synchronous, or asynchronous on Engine - { - AsyncHook realize = clazz->mRealize; - // Note that the mutex is locked on entry to and exit from the realize hook, - // but the hook is permitted to temporarily unlock the mutex (e.g. for async). - result = (NULL != realize) ? (*realize)(thiz, async) : SL_RESULT_SUCCESS; - assert(SL_OBJECT_STATE_REALIZING_2 == thiz->mState); - state = (SL_RESULT_SUCCESS == result) ? SL_OBJECT_STATE_REALIZED : - SL_OBJECT_STATE_UNREALIZED; - thiz->mState = state; - slObjectCallback callback = thiz->mCallback; - void *context = thiz->mContext; - object_unlock_exclusive(thiz); - // asynchronous Realize on an Engine is actually done synchronously, but still has - // callback because there is no thread pool yet to do it asynchronously. - if (async && (NULL != callback)) { - (*callback)(&thiz->mItf, context, SL_OBJECT_EVENT_ASYNC_TERMINATION, result, state, - NULL); - } - } - break; - default: // impossible - object_unlock_exclusive(thiz); - assert(SL_BOOLEAN_FALSE); - break; - } - } - - SL_LEAVE_INTERFACE -} - - -// Called by a worker thread to handle an asynchronous Object.Resume. -// Parameter self is the Object. - -static void HandleResume(void *self, void *ignored, int unused) -{ - - // valid input parameters - IObject *thiz = (IObject *) self; - assert(NULL != thiz); - const ClassTable *clazz = thiz->mClass; - assert(NULL != clazz); - AsyncHook resume = clazz->mResume; - SLresult result; - SLuint8 state; - - // check object state - object_lock_exclusive(thiz); - state = thiz->mState; - switch (state) { - - case SL_OBJECT_STATE_RESUMING_1: // normal case - if (NULL != resume) { - thiz->mState = SL_OBJECT_STATE_RESUMING_2; - // Note that the mutex is locked on entry to and exit from the resume hook, - // but the hook is permitted to temporarily unlock the mutex (e.g. for async). - result = (*resume)(thiz, SL_BOOLEAN_TRUE); - assert(SL_OBJECT_STATE_RESUMING_2 == thiz->mState); - state = SL_RESULT_SUCCESS == result ? SL_OBJECT_STATE_REALIZED : - SL_OBJECT_STATE_SUSPENDED; - } else { - result = SL_RESULT_SUCCESS; - state = SL_OBJECT_STATE_REALIZED; - } - break; - - case SL_OBJECT_STATE_RESUMING_1A: // operation was aborted while on work queue - result = SL_RESULT_OPERATION_ABORTED; - state = SL_OBJECT_STATE_SUSPENDED; - break; - - default: // impossible - assert(SL_BOOLEAN_FALSE); - result = SL_RESULT_INTERNAL_ERROR; - break; - - } - - // mutex is unlocked, update state - thiz->mState = state; - - // Make a copy of these, so we can call the callback with mutex unlocked - slObjectCallback callback = thiz->mCallback; - void *context = thiz->mContext; - object_unlock_exclusive(thiz); - - // Note that the mutex is unlocked during the callback - if (NULL != callback) { - (*callback)(&thiz->mItf, context, SL_OBJECT_EVENT_ASYNC_TERMINATION, result, state, NULL); - } -} - - -static SLresult IObject_Resume(SLObjectItf self, SLboolean async) -{ - SL_ENTER_INTERFACE - - IObject *thiz = (IObject *) self; - const ClassTable *clazz = thiz->mClass; - SLuint8 state; - object_lock_exclusive(thiz); - state = thiz->mState; - // Reject redundant calls to Resume - if (SL_OBJECT_STATE_SUSPENDED != state) { - object_unlock_exclusive(thiz); - result = SL_RESULT_PRECONDITIONS_VIOLATED; - } else { - // Asynchronous: mark operation pending and cancellable - if (async) { - state = SL_OBJECT_STATE_RESUMING_1; - // Synchronous: mark operatio pending and non-cancellable - } else { - state = SL_OBJECT_STATE_RESUMING_2; - } - thiz->mState = state; - switch (state) { - case SL_OBJECT_STATE_RESUMING_1: // asynchronous - object_unlock_exclusive(thiz); - assert(async); - result = ThreadPool_add_ppi(&thiz->mEngine->mThreadPool, HandleResume, thiz, NULL, 0); - if (SL_RESULT_SUCCESS != result) { - // Engine was destroyed during resume, or insufficient memory - object_lock_exclusive(thiz); - thiz->mState = SL_OBJECT_STATE_SUSPENDED; - object_unlock_exclusive(thiz); - } - break; - case SL_OBJECT_STATE_RESUMING_2: // synchronous - { - AsyncHook resume = clazz->mResume; - // Note that the mutex is locked on entry to and exit from the resume hook, - // but the hook is permitted to temporarily unlock the mutex (e.g. for async). - result = (NULL != resume) ? (*resume)(thiz, SL_BOOLEAN_FALSE) : SL_RESULT_SUCCESS; - assert(SL_OBJECT_STATE_RESUMING_2 == thiz->mState); - thiz->mState = (SL_RESULT_SUCCESS == result) ? SL_OBJECT_STATE_REALIZED : - SL_OBJECT_STATE_SUSPENDED; - object_unlock_exclusive(thiz); - } - break; - default: // impossible - object_unlock_exclusive(thiz); - assert(SL_BOOLEAN_FALSE); - break; - } - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IObject_GetState(SLObjectItf self, SLuint32 *pState) -{ - SL_ENTER_INTERFACE - - if (NULL == pState) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IObject *thiz = (IObject *) self; - object_lock_shared(thiz); - SLuint8 state = thiz->mState; - object_unlock_shared(thiz); - // Re-map the realizing, resuming, and suspending states - switch (state) { - case SL_OBJECT_STATE_REALIZING_1: - case SL_OBJECT_STATE_REALIZING_1A: - case SL_OBJECT_STATE_REALIZING_2: - case SL_OBJECT_STATE_DESTROYING: // application shouldn't call GetState after Destroy - state = SL_OBJECT_STATE_UNREALIZED; - break; - case SL_OBJECT_STATE_RESUMING_1: - case SL_OBJECT_STATE_RESUMING_1A: - case SL_OBJECT_STATE_RESUMING_2: - case SL_OBJECT_STATE_SUSPENDING: - state = SL_OBJECT_STATE_SUSPENDED; - break; - case SL_OBJECT_STATE_UNREALIZED: - case SL_OBJECT_STATE_REALIZED: - case SL_OBJECT_STATE_SUSPENDED: - // These are the "official" object states, return them as is - break; - default: - assert(SL_BOOLEAN_FALSE); - break; - } - *pState = state; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - -static SLresult IObject_GetInterface(SLObjectItf self, const SLInterfaceID iid, void *pInterface) -{ - SL_ENTER_INTERFACE - - if (NULL == pInterface) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - void *interface = NULL; - if (NULL == iid) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IObject *thiz = (IObject *) self; - const ClassTable *clazz = thiz->mClass; - int MPH, index; - if ((0 > (MPH = IID_to_MPH(iid))) || - // no need to check for an initialization hook - // (NULL == MPH_init_table[MPH].mInit) || - (0 > (index = clazz->mMPH_to_index[MPH]))) { - result = SL_RESULT_FEATURE_UNSUPPORTED; - } else { - unsigned mask = 1 << index; - object_lock_exclusive(thiz); - if ((SL_OBJECT_STATE_REALIZED != thiz->mState) && - !(INTERFACE_PREREALIZE & clazz->mInterfaces[index].mInterface)) { - // Can't get interface on an unrealized object unless pre-realize is ok - result = SL_RESULT_PRECONDITIONS_VIOLATED; - } else if ((MPH_MUTESOLO == MPH) && (SL_OBJECTID_AUDIOPLAYER == - clazz->mSLObjectID) && (1 == ((CAudioPlayer *) thiz)->mNumChannels)) { - // Can't get the MuteSolo interface of an audio player if the channel count is - // mono, but _can_ get the MuteSolo interface if the channel count is unknown - result = SL_RESULT_FEATURE_UNSUPPORTED; - } else { - switch (thiz->mInterfaceStates[index]) { - case INTERFACE_EXPOSED: - case INTERFACE_ADDED: - interface = (char *) thiz + clazz->mInterfaces[index].mOffset; - // Note that interface has been gotten, - // for debugger and to detect incorrect use of interfaces - if (!(thiz->mGottenMask & mask)) { - thiz->mGottenMask |= mask; - // This trickery validates the v-table - ((size_t *) interface)[0] ^= ~0; - } - result = SL_RESULT_SUCCESS; - break; - // Can't get interface if uninitialized, initialized, suspended, - // suspending, resuming, adding, or removing - default: - result = SL_RESULT_FEATURE_UNSUPPORTED; - break; - } - } - object_unlock_exclusive(thiz); - } - } - *(void **)pInterface = interface; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IObject_RegisterCallback(SLObjectItf self, - slObjectCallback callback, void *pContext) -{ - SL_ENTER_INTERFACE - - IObject *thiz = (IObject *) self; - object_lock_exclusive(thiz); - thiz->mCallback = callback; - thiz->mContext = pContext; - object_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -/** \brief This is internal common code for Abort and Destroy. - * Note: called with mutex unlocked, and returns with mutex locked. - */ - -static void Abort_internal(IObject *thiz) -{ - const ClassTable *clazz = thiz->mClass; - bool anyAsync = false; - object_lock_exclusive(thiz); - - // Abort asynchronous operations on the object - switch (thiz->mState) { - case SL_OBJECT_STATE_REALIZING_1: // Realize - thiz->mState = SL_OBJECT_STATE_REALIZING_1A; - anyAsync = true; - break; - case SL_OBJECT_STATE_RESUMING_1: // Resume - thiz->mState = SL_OBJECT_STATE_RESUMING_1A; - anyAsync = true; - break; - case SL_OBJECT_STATE_REALIZING_1A: // Realize - case SL_OBJECT_STATE_REALIZING_2: - case SL_OBJECT_STATE_RESUMING_1A: // Resume - case SL_OBJECT_STATE_RESUMING_2: - anyAsync = true; - break; - case SL_OBJECT_STATE_DESTROYING: - assert(false); - break; - default: - break; - } - - // Abort asynchronous operations on interfaces - SLuint8 *interfaceStateP = thiz->mInterfaceStates; - unsigned index; - for (index = 0; index < clazz->mInterfaceCount; ++index, ++interfaceStateP) { - switch (*interfaceStateP) { - case INTERFACE_ADDING_1: // AddInterface - *interfaceStateP = INTERFACE_ADDING_1A; - anyAsync = true; - break; - case INTERFACE_RESUMING_1: // ResumeInterface - *interfaceStateP = INTERFACE_RESUMING_1A; - anyAsync = true; - break; - case INTERFACE_ADDING_1A: // AddInterface - case INTERFACE_ADDING_2: - case INTERFACE_RESUMING_1A: // ResumeInterface - case INTERFACE_RESUMING_2: - case INTERFACE_REMOVING: // not observable: RemoveInterface is synchronous & mutex locked - anyAsync = true; - break; - default: - break; - } - } - - // Wait until all asynchronous operations either complete normally or recognize the abort - while (anyAsync) { - object_unlock_exclusive(thiz); - // FIXME should use condition variable instead of polling - usleep(20000); - anyAsync = false; - object_lock_exclusive(thiz); - switch (thiz->mState) { - case SL_OBJECT_STATE_REALIZING_1: // state 1 means it cycled during the usleep window - case SL_OBJECT_STATE_RESUMING_1: - case SL_OBJECT_STATE_REALIZING_1A: - case SL_OBJECT_STATE_REALIZING_2: - case SL_OBJECT_STATE_RESUMING_1A: - case SL_OBJECT_STATE_RESUMING_2: - anyAsync = true; - break; - case SL_OBJECT_STATE_DESTROYING: - assert(false); - break; - default: - break; - } - interfaceStateP = thiz->mInterfaceStates; - for (index = 0; index < clazz->mInterfaceCount; ++index, ++interfaceStateP) { - switch (*interfaceStateP) { - case INTERFACE_ADDING_1: // state 1 means it cycled during the usleep window - case INTERFACE_RESUMING_1: - case INTERFACE_ADDING_1A: - case INTERFACE_ADDING_2: - case INTERFACE_RESUMING_1A: - case INTERFACE_RESUMING_2: - case INTERFACE_REMOVING: - anyAsync = true; - break; - default: - break; - } - } - } - - // At this point there are no pending asynchronous operations -} - - -static void IObject_AbortAsyncOperation(SLObjectItf self) -{ - SL_ENTER_INTERFACE_VOID - - IObject *thiz = (IObject *) self; - Abort_internal(thiz); - object_unlock_exclusive(thiz); - - SL_LEAVE_INTERFACE_VOID -} - - -void IObject_Destroy(SLObjectItf self) -{ - SL_ENTER_INTERFACE_VOID - - IObject *thiz = (IObject *) self; - // mutex is unlocked - Abort_internal(thiz); - // mutex is locked - const ClassTable *clazz = thiz->mClass; - PreDestroyHook preDestroy = clazz->mPreDestroy; - // The pre-destroy hook is called with mutex locked, and should block until it is safe to - // destroy. It is OK to unlock the mutex temporarily, as it long as it re-locks the mutex - // before returning. - if (NULL != preDestroy) { - predestroy_t okToDestroy = (*preDestroy)(thiz); - switch (okToDestroy) { - case predestroy_ok: - break; - case predestroy_error: - SL_LOGE("Object::Destroy(%p) not allowed", thiz); - // fall through - case predestroy_again: - object_unlock_exclusive(thiz); - // unfortunately Destroy doesn't return a result - SL_LEAVE_INTERFACE_VOID - // unreachable - default: - assert(false); - break; - } - } - thiz->mState = SL_OBJECT_STATE_DESTROYING; - VoidHook destroy = clazz->mDestroy; - // const, no lock needed - IEngine *thisEngine = &thiz->mEngine->mEngine; - unsigned i = thiz->mInstanceID; - assert(MAX_INSTANCE >= i); - // avoid a recursive lock on the engine when destroying the engine itself - if (thisEngine->mThis != thiz) { - interface_lock_exclusive(thisEngine); - } - // An unpublished object has a slot reserved, but the ID hasn't been chosen yet - assert(0 < thisEngine->mInstanceCount); - --thisEngine->mInstanceCount; - // If object is published, then remove it from exposure to sync thread and debugger - if (0 != i) { - --i; - unsigned mask = 1 << i; - assert(thisEngine->mInstanceMask & mask); - thisEngine->mInstanceMask &= ~mask; - assert(thisEngine->mInstances[i] == thiz); - thisEngine->mInstances[i] = NULL; - } - // avoid a recursive unlock on the engine when destroying the engine itself - if (thisEngine->mThis != thiz) { - interface_unlock_exclusive(thisEngine); - } - // The destroy hook is called with mutex locked - if (NULL != destroy) { - (*destroy)(thiz); - } - // Call the deinitializer for each currently initialized interface, - // whether it is implicit, explicit, optional, or dynamically added. - // The deinitializers are called in the reverse order that the - // initializers were called, so that IObject_deinit is called last. - unsigned index = clazz->mInterfaceCount; - const struct iid_vtable *x = &clazz->mInterfaces[index]; - SLuint8 *interfaceStateP = &thiz->mInterfaceStates[index]; - for ( ; index > 0; --index) { - --x; - size_t offset = x->mOffset; - void *thisItf = (char *) thiz + offset; - SLuint32 state = *--interfaceStateP; - switch (state) { - case INTERFACE_UNINITIALIZED: - break; - case INTERFACE_EXPOSED: // quiescent states - case INTERFACE_ADDED: - case INTERFACE_SUSPENDED: - // The remove hook is called with mutex locked - { - VoidHook remove = MPH_init_table[x->mMPH].mRemove; - if (NULL != remove) { - (*remove)(thisItf); - } - *interfaceStateP = INTERFACE_INITIALIZED; - } - // fall through - case INTERFACE_INITIALIZED: - { - VoidHook deinit = MPH_init_table[x->mMPH].mDeinit; - if (NULL != deinit) { - (*deinit)(thisItf); - } - *interfaceStateP = INTERFACE_UNINITIALIZED; - } - break; - case INTERFACE_ADDING_1: // active states indicate incorrect use of API - case INTERFACE_ADDING_1A: - case INTERFACE_ADDING_2: - case INTERFACE_RESUMING_1: - case INTERFACE_RESUMING_1A: - case INTERFACE_RESUMING_2: - case INTERFACE_REMOVING: - case INTERFACE_SUSPENDING: - SL_LOGE("Object::Destroy(%p) while interface %u active", thiz, index); - break; - default: - assert(SL_BOOLEAN_FALSE); - break; - } - } - // The mutex is unlocked and destroyed by IObject_deinit, which is the last deinitializer - memset(thiz, 0x55, clazz->mSize); // catch broken applications that continue using interfaces - // was ifdef USE_DEBUG but safer to do this unconditionally - free(thiz); - - if (SL_OBJECTID_ENGINE == clazz->mSLObjectID) { - CEngine_Destroyed((CEngine *) thiz); - } - - SL_LEAVE_INTERFACE_VOID -} - - -static SLresult IObject_SetPriority(SLObjectItf self, SLint32 priority, SLboolean preemptable) -{ - SL_ENTER_INTERFACE - -#if USE_PROFILES & USE_PROFILES_BASE - IObject *thiz = (IObject *) self; - object_lock_exclusive(thiz); - thiz->mPriority = priority; - thiz->mPreemptable = SL_BOOLEAN_FALSE != preemptable; // normalize - object_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; -#else - result = SL_RESULT_FEATURE_UNSUPPORTED; -#endif - - SL_LEAVE_INTERFACE -} - - -static SLresult IObject_GetPriority(SLObjectItf self, SLint32 *pPriority, SLboolean *pPreemptable) -{ - SL_ENTER_INTERFACE - -#if USE_PROFILES & USE_PROFILES_BASE - if (NULL == pPriority || NULL == pPreemptable) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IObject *thiz = (IObject *) self; - object_lock_shared(thiz); - SLint32 priority = thiz->mPriority; - SLboolean preemptable = thiz->mPreemptable; - object_unlock_shared(thiz); - *pPriority = priority; - *pPreemptable = preemptable; - result = SL_RESULT_SUCCESS; - } -#else - result = SL_RESULT_FEATURE_UNSUPPORTED; -#endif - - SL_LEAVE_INTERFACE -} - - -static SLresult IObject_SetLossOfControlInterfaces(SLObjectItf self, - SLint16 numInterfaces, SLInterfaceID *pInterfaceIDs, SLboolean enabled) -{ - SL_ENTER_INTERFACE - -#if USE_PROFILES & USE_PROFILES_BASE - result = SL_RESULT_SUCCESS; - if (0 < numInterfaces) { - SLuint32 i; - if (NULL == pInterfaceIDs) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IObject *thiz = (IObject *) self; - const ClassTable *clazz = thiz->mClass; - unsigned lossOfControlMask = 0; - // The cast is due to a typo in the spec, bug 6482 - for (i = 0; i < (SLuint32) numInterfaces; ++i) { - SLInterfaceID iid = pInterfaceIDs[i]; - if (NULL == iid) { - result = SL_RESULT_PARAMETER_INVALID; - goto out; - } - int MPH, index; - // We ignore without error any invalid MPH or index, but spec is unclear - if ((0 <= (MPH = IID_to_MPH(iid))) && - // no need to check for an initialization hook - // (NULL == MPH_init_table[MPH].mInit) || - (0 <= (index = clazz->mMPH_to_index[MPH]))) { - lossOfControlMask |= (1 << index); - } - } - object_lock_exclusive(thiz); - if (enabled) { - thiz->mLossOfControlMask |= lossOfControlMask; - } else { - thiz->mLossOfControlMask &= ~lossOfControlMask; - } - object_unlock_exclusive(thiz); - } - } -out: -#else - result = SL_RESULT_FEATURE_UNSUPPORTED; -#endif - - SL_LEAVE_INTERFACE -} - - -static const struct SLObjectItf_ IObject_Itf = { - IObject_Realize, - IObject_Resume, - IObject_GetState, - IObject_GetInterface, - IObject_RegisterCallback, - IObject_AbortAsyncOperation, - IObject_Destroy, - IObject_SetPriority, - IObject_GetPriority, - IObject_SetLossOfControlInterfaces -}; - - -/** \brief This must be the first initializer called for an object */ - -void IObject_init(void *self) -{ - IObject *thiz = (IObject *) self; - thiz->mItf = &IObject_Itf; - // initialized in construct: - // mClass - // mInstanceID - // mLossOfControlMask - // mEngine - // mInterfaceStates - thiz->mState = SL_OBJECT_STATE_UNREALIZED; - thiz->mGottenMask = 1; // IObject - thiz->mAttributesMask = 0; - thiz->mCallback = NULL; - thiz->mContext = NULL; -#if USE_PROFILES & USE_PROFILES_BASE - thiz->mPriority = SL_PRIORITY_NORMAL; - thiz->mPreemptable = SL_BOOLEAN_FALSE; -#endif - thiz->mStrongRefCount = 0; - int ok; - ok = pthread_mutex_init(&thiz->mMutex, (const pthread_mutexattr_t *) NULL); - assert(0 == ok); -#ifdef USE_DEBUG - memset(&thiz->mOwner, 0, sizeof(pthread_t)); - thiz->mFile = NULL; - thiz->mLine = 0; - thiz->mGeneration = 0; -#endif - ok = pthread_cond_init(&thiz->mCond, (const pthread_condattr_t *) NULL); - assert(0 == ok); -} - - -/** \brief This must be the last deinitializer called for an object */ - -void IObject_deinit(void *self) -{ - IObject *thiz = (IObject *) self; -#ifdef USE_DEBUG - assert(pthread_equal(pthread_self(), thiz->mOwner)); -#endif - int ok; - ok = pthread_cond_destroy(&thiz->mCond); - assert(0 == ok); - // equivalent to object_unlock_exclusive, but without the rigmarole - ok = pthread_mutex_unlock(&thiz->mMutex); - assert(0 == ok); - ok = pthread_mutex_destroy(&thiz->mMutex); - assert(0 == ok); - // redundant: thiz->mState = SL_OBJECT_STATE_UNREALIZED; -} - - -/** \brief Publish a new object after it is fully initialized. - * Publishing will expose the object to sync thread and debugger, - * and make it safe to return the SLObjectItf to the application. - */ - -void IObject_Publish(IObject *thiz) -{ - IEngine *thisEngine = &thiz->mEngine->mEngine; - interface_lock_exclusive(thisEngine); - // construct earlier reserved a pending slot, but did not choose the actual slot number - unsigned availMask = ~thisEngine->mInstanceMask; - assert(availMask); - unsigned i = ctz(availMask); - assert(MAX_INSTANCE > i); - assert(NULL == thisEngine->mInstances[i]); - thisEngine->mInstances[i] = thiz; - thisEngine->mInstanceMask |= 1 << i; - // avoid zero as a valid instance ID - thiz->mInstanceID = i + 1; - interface_unlock_exclusive(thisEngine); -} diff --git a/wilhelm/src/itf/IOutputMix.c b/wilhelm/src/itf/IOutputMix.c deleted file mode 100644 index 1594d7c5..00000000 --- a/wilhelm/src/itf/IOutputMix.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - * 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. - */ - -/* OutputMix implementation */ - -#include "sles_allinclusive.h" - - -static SLresult IOutputMix_GetDestinationOutputDeviceIDs(SLOutputMixItf self, - SLint32 *pNumDevices, SLuint32 *pDeviceIDs) -{ - SL_ENTER_INTERFACE - - if (NULL == pNumDevices) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - result = SL_RESULT_SUCCESS; - // The application can set pDeviceIDs == NULL in order to find out number of devices. - // Then the application can allocate a proper-sized device ID array and try again. - if (NULL != pDeviceIDs) { - if (1 > *pNumDevices) { - result = SL_RESULT_BUFFER_INSUFFICIENT; - } else { - pDeviceIDs[0] = SL_DEFAULTDEVICEID_AUDIOOUTPUT; - } - } - *pNumDevices = 1; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IOutputMix_RegisterDeviceChangeCallback(SLOutputMixItf self, - slMixDeviceChangeCallback callback, void *pContext) -{ - SL_ENTER_INTERFACE - - IOutputMix *thiz = (IOutputMix *) self; - interface_lock_exclusive(thiz); - thiz->mCallback = callback; - thiz->mContext = pContext; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static SLresult IOutputMix_ReRoute(SLOutputMixItf self, SLint32 numOutputDevices, - SLuint32 *pOutputDeviceIDs) -{ - SL_ENTER_INTERFACE - - if ((1 != numOutputDevices) || (NULL == pOutputDeviceIDs)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - switch (pOutputDeviceIDs[0]) { - case SL_DEFAULTDEVICEID_AUDIOOUTPUT: - case DEVICE_ID_HEADSET: - result = SL_RESULT_SUCCESS; - break; - default: - result = SL_RESULT_PARAMETER_INVALID; - break; - } - } - - SL_LEAVE_INTERFACE -} - - -static const struct SLOutputMixItf_ IOutputMix_Itf = { - IOutputMix_GetDestinationOutputDeviceIDs, - IOutputMix_RegisterDeviceChangeCallback, - IOutputMix_ReRoute -}; - -void IOutputMix_init(void *self) -{ - IOutputMix *thiz = (IOutputMix *) self; - thiz->mItf = &IOutputMix_Itf; - thiz->mCallback = NULL; - thiz->mContext = NULL; -} diff --git a/wilhelm/src/itf/IOutputMixExt.c b/wilhelm/src/itf/IOutputMixExt.c deleted file mode 100644 index 7a72d28c..00000000 --- a/wilhelm/src/itf/IOutputMixExt.c +++ /dev/null @@ -1,473 +0,0 @@ -/* - * 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. - */ - -/* OutputMixExt implementation */ - -#include "sles_allinclusive.h" -#include <math.h> - - -// OutputMixExt is used by SDL, but is not specific to or dependent on SDL - - -// stereo is a frame consisting of a pair of 16-bit PCM samples - -typedef struct { - short left; - short right; -} stereo; - - -/** \brief Summary of the gain, as an optimization for the mixer */ - -typedef enum { - GAIN_MUTE = 0, // mValue == 0.0f within epsilon - GAIN_UNITY = 1, // mValue == 1.0f within epsilon - GAIN_OTHER = 2 // 0.0f < mValue < 1.0f -} Summary; - - -/** \brief Check whether a track has any data for us to read */ - -static SLboolean track_check(Track *track) -{ - assert(NULL != track); - SLboolean trackHasData = SL_BOOLEAN_FALSE; - - CAudioPlayer *audioPlayer = track->mAudioPlayer; - if (NULL != audioPlayer) { - - // track is initialized - - // FIXME This lock could block and result in stuttering; - // a trylock with retry or lockless solution would be ideal - object_lock_exclusive(&audioPlayer->mObject); - assert(audioPlayer->mTrack == track); - - SLuint32 framesMixed = track->mFramesMixed; - if (0 != framesMixed) { - track->mFramesMixed = 0; - audioPlayer->mPlay.mFramesSinceLastSeek += framesMixed; - audioPlayer->mPlay.mFramesSincePositionUpdate += framesMixed; - } - - SLboolean doBroadcast = SL_BOOLEAN_FALSE; - const BufferHeader *oldFront; - - if (audioPlayer->mBufferQueue.mClearRequested) { - // application thread(s) that call BufferQueue::Clear while mixer is active - // will block synchronously until mixer acknowledges the Clear request - audioPlayer->mBufferQueue.mFront = &audioPlayer->mBufferQueue.mArray[0]; - audioPlayer->mBufferQueue.mRear = &audioPlayer->mBufferQueue.mArray[0]; - audioPlayer->mBufferQueue.mState.count = 0; - audioPlayer->mBufferQueue.mState.playIndex = 0; - audioPlayer->mBufferQueue.mClearRequested = SL_BOOLEAN_FALSE; - track->mReader = NULL; - track->mAvail = 0; - doBroadcast = SL_BOOLEAN_TRUE; - } - - if (audioPlayer->mDestroyRequested) { - // an application thread that calls Object::Destroy while mixer is active will block - // synchronously in the PreDestroy hook until mixer acknowledges the Destroy request - COutputMix *outputMix = CAudioPlayer_GetOutputMix(audioPlayer); - unsigned i = track - outputMix->mOutputMixExt.mTracks; - assert( /* 0 <= i && */ i < MAX_TRACK); - unsigned mask = 1 << i; - track->mAudioPlayer = NULL; - assert(outputMix->mOutputMixExt.mActiveMask & mask); - outputMix->mOutputMixExt.mActiveMask &= ~mask; - audioPlayer->mTrack = NULL; - audioPlayer->mDestroyRequested = SL_BOOLEAN_FALSE; - doBroadcast = SL_BOOLEAN_TRUE; - goto broadcast; - } - - switch (audioPlayer->mPlay.mState) { - - case SL_PLAYSTATE_PLAYING: // continue playing current track data - if (0 < track->mAvail) { - trackHasData = SL_BOOLEAN_TRUE; - break; - } - - // try to get another buffer from queue - oldFront = audioPlayer->mBufferQueue.mFront; - if (oldFront != audioPlayer->mBufferQueue.mRear) { - assert(0 < audioPlayer->mBufferQueue.mState.count); - track->mReader = oldFront->mBuffer; - track->mAvail = oldFront->mSize; - // note that the buffer stays on the queue while we are reading - audioPlayer->mPlay.mState = SL_PLAYSTATE_PLAYING; - trackHasData = SL_BOOLEAN_TRUE; - } else { - // no buffers on queue, so playable but not playing - // NTH should be able to call a desperation callback when completely starved, - // or call less often than every buffer based on high/low water-marks - } - - // copy gains from audio player to track - track->mGains[0] = audioPlayer->mGains[0]; - track->mGains[1] = audioPlayer->mGains[1]; - break; - - case SL_PLAYSTATE_STOPPING: // application thread(s) called Play::SetPlayState(STOPPED) - audioPlayer->mPlay.mPosition = (SLmillisecond) 0; - audioPlayer->mPlay.mFramesSinceLastSeek = 0; - audioPlayer->mPlay.mFramesSincePositionUpdate = 0; - audioPlayer->mPlay.mLastSeekPosition = 0; - audioPlayer->mPlay.mState = SL_PLAYSTATE_STOPPED; - // stop cancels a pending seek - audioPlayer->mSeek.mPos = SL_TIME_UNKNOWN; - oldFront = audioPlayer->mBufferQueue.mFront; - if (oldFront != audioPlayer->mBufferQueue.mRear) { - assert(0 < audioPlayer->mBufferQueue.mState.count); - track->mReader = oldFront->mBuffer; - track->mAvail = oldFront->mSize; - } - doBroadcast = SL_BOOLEAN_TRUE; - break; - - case SL_PLAYSTATE_STOPPED: // idle - case SL_PLAYSTATE_PAUSED: // idle - break; - - default: - assert(SL_BOOLEAN_FALSE); - break; - } - -broadcast: - if (doBroadcast) { - object_cond_broadcast(&audioPlayer->mObject); - } - - object_unlock_exclusive(&audioPlayer->mObject); - - } - - return trackHasData; - -} - - -/** \brief This is the track mixer: fill the specified 16-bit stereo PCM buffer */ - -void IOutputMixExt_FillBuffer(SLOutputMixExtItf self, void *pBuffer, SLuint32 size) -{ - SL_ENTER_INTERFACE_VOID - - // Force to be a multiple of a frame, assumes stereo 16-bit PCM - size &= ~3; - SLboolean mixBufferHasData = SL_BOOLEAN_FALSE; - IOutputMixExt *thiz = (IOutputMixExt *) self; - IObject *thisObject = thiz->mThis; - // This lock should never block, except when the application destroys the output mix object - object_lock_exclusive(thisObject); - unsigned activeMask; - // If the output mix is marked for destruction, then acknowledge the request - if (thiz->mDestroyRequested) { - IEngine *thisEngine = &thisObject->mEngine->mEngine; - interface_lock_exclusive(thisEngine); - assert(&thisEngine->mOutputMix->mObject == thisObject); - thisEngine->mOutputMix = NULL; - // Note we don't attempt to connect another output mix, even if there is one - interface_unlock_exclusive(thisEngine); - // Acknowledge the destroy request, and notify the pre-destroy hook - thiz->mDestroyRequested = SL_BOOLEAN_FALSE; - object_cond_broadcast(thisObject); - activeMask = 0; - } else { - activeMask = thiz->mActiveMask; - } - while (activeMask) { - unsigned i = ctz(activeMask); - assert(MAX_TRACK > i); - activeMask &= ~(1 << i); - Track *track = &thiz->mTracks[i]; - - // track is allocated - - if (!track_check(track)) { - continue; - } - - // track is playing - void *dstWriter = pBuffer; - unsigned desired = size; - SLboolean trackContributedToMix = SL_BOOLEAN_FALSE; - float gains[STEREO_CHANNELS]; - Summary summaries[STEREO_CHANNELS]; - unsigned channel; - for (channel = 0; channel < STEREO_CHANNELS; ++channel) { - float gain = track->mGains[channel]; - gains[channel] = gain; - Summary summary; - if (gain <= 0.001) { - summary = GAIN_MUTE; - } else if (gain >= 0.999) { - summary = GAIN_UNITY; - } else { - summary = GAIN_OTHER; - } - summaries[channel] = summary; - } - while (desired > 0) { - unsigned actual = desired; - if (track->mAvail < actual) { - actual = track->mAvail; - } - // force actual to be a frame multiple - if (actual > 0) { - assert(NULL != track->mReader); - stereo *mixBuffer = (stereo *) dstWriter; - const stereo *source = (const stereo *) track->mReader; - unsigned j; - if (GAIN_MUTE != summaries[0] || GAIN_MUTE != summaries[1]) { - if (mixBufferHasData) { - // apply gain during add - if (GAIN_UNITY != summaries[0] || GAIN_UNITY != summaries[1]) { - for (j = 0; j < actual; j += sizeof(stereo), ++mixBuffer, ++source) { - mixBuffer->left += (short) (source->left * track->mGains[0]); - mixBuffer->right += (short) (source->right * track->mGains[1]); - } - // no gain adjustment needed, so do a simple add - } else { - for (j = 0; j < actual; j += sizeof(stereo), ++mixBuffer, ++source) { - mixBuffer->left += source->left; - mixBuffer->right += source->right; - } - } - } else { - // apply gain during copy - if (GAIN_UNITY != summaries[0] || GAIN_UNITY != summaries[1]) { - for (j = 0; j < actual; j += sizeof(stereo), ++mixBuffer, ++source) { - mixBuffer->left = (short) (source->left * track->mGains[0]); - mixBuffer->right = (short) (source->right * track->mGains[1]); - } - // no gain adjustment needed, so do a simple copy - } else { - memcpy(dstWriter, track->mReader, actual); - } - } - trackContributedToMix = SL_BOOLEAN_TRUE; - } - dstWriter = (char *) dstWriter + actual; - desired -= actual; - track->mReader = (char *) track->mReader + actual; - track->mAvail -= actual; - if (track->mAvail == 0) { - IBufferQueue *bufferQueue = &track->mAudioPlayer->mBufferQueue; - interface_lock_exclusive(bufferQueue); - const BufferHeader *oldFront, *newFront, *rear; - oldFront = bufferQueue->mFront; - rear = bufferQueue->mRear; - // a buffer stays on queue while playing, so it better still be there - assert(oldFront != rear); - newFront = oldFront; - if (++newFront == &bufferQueue->mArray[bufferQueue->mNumBuffers + 1]) { - newFront = bufferQueue->mArray; - } - bufferQueue->mFront = (BufferHeader *) newFront; - assert(0 < bufferQueue->mState.count); - --bufferQueue->mState.count; - if (newFront != rear) { - // we don't acknowledge application requests between buffers - // within the same mixer frame - assert(0 < bufferQueue->mState.count); - track->mReader = newFront->mBuffer; - track->mAvail = newFront->mSize; - } - // else we would set play state to playable but not playing during next mixer - // frame if the queue is still empty at that time - ++bufferQueue->mState.playIndex; - slBufferQueueCallback callback = bufferQueue->mCallback; - void *context = bufferQueue->mContext; - interface_unlock_exclusive(bufferQueue); - // The callback function is called on each buffer completion - if (NULL != callback) { - (*callback)((SLBufferQueueItf) bufferQueue, context); - // Maybe it enqueued another buffer, or maybe it didn't. - // We will find out later during the next mixer frame. - } - } - // no lock, but safe because noone else updates this field - track->mFramesMixed += actual >> 2; // sizeof(short) * STEREO_CHANNELS - continue; - } - // we need more data: desired > 0 but actual == 0 - if (track_check(track)) { - continue; - } - // underflow: clear out rest of partial buffer (NTH synthesize comfort noise) - if (!mixBufferHasData && trackContributedToMix) { - memset(dstWriter, 0, actual); - } - break; - } - if (trackContributedToMix) { - mixBufferHasData = SL_BOOLEAN_TRUE; - } - } - object_unlock_exclusive(thisObject); - // No active tracks, so output silence - if (!mixBufferHasData) { - memset(pBuffer, 0, size); - } - - SL_LEAVE_INTERFACE_VOID -} - - -static const struct SLOutputMixExtItf_ IOutputMixExt_Itf = { - IOutputMixExt_FillBuffer -}; - -void IOutputMixExt_init(void *self) -{ - IOutputMixExt *thiz = (IOutputMixExt *) self; - thiz->mItf = &IOutputMixExt_Itf; - thiz->mActiveMask = 0; - Track *track = &thiz->mTracks[0]; - unsigned i; - for (i = 0; i < MAX_TRACK; ++i, ++track) { - track->mAudioPlayer = NULL; - } - thiz->mDestroyRequested = SL_BOOLEAN_FALSE; -} - - -/** \brief Called by Engine::CreateAudioPlayer to allocate a track */ - -SLresult IOutputMixExt_checkAudioPlayerSourceSink(CAudioPlayer *thiz) -{ - thiz->mTrack = NULL; - - // check the source for compatibility - switch (thiz->mDataSource.mLocator.mLocatorType) { - case SL_DATALOCATOR_BUFFERQUEUE: -#ifdef ANDROID - case SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE: -#endif - switch (thiz->mDataSource.mFormat.mFormatType) { - case SL_DATAFORMAT_PCM: -#ifdef USE_SDL - // SDL is hard-coded to 44.1 kHz, and there is no sample rate converter - if (SL_SAMPLINGRATE_44_1 != thiz->mDataSource.mFormat.mPCM.samplesPerSec) - return SL_RESULT_CONTENT_UNSUPPORTED; -#endif - break; - default: - break; - } - break; - default: - break; - } - - // check the sink for compatibility - const SLDataSink *pAudioSnk = &thiz->mDataSink.u.mSink; - Track *track = NULL; - switch (*(SLuint32 *)pAudioSnk->pLocator) { - case SL_DATALOCATOR_OUTPUTMIX: - { - // pAudioSnk->pFormat is ignored - IOutputMixExt *omExt = &((COutputMix *) ((SLDataLocator_OutputMix *) - pAudioSnk->pLocator)->outputMix)->mOutputMixExt; - // allocate an entry within OutputMix for this track - interface_lock_exclusive(omExt); - unsigned availMask = ~omExt->mActiveMask; - if (!availMask) { - interface_unlock_exclusive(omExt); - // All track slots full in output mix - return SL_RESULT_MEMORY_FAILURE; - } - unsigned i = ctz(availMask); - assert(MAX_TRACK > i); - omExt->mActiveMask |= 1 << i; - track = &omExt->mTracks[i]; - track->mAudioPlayer = NULL; // only field that is accessed before full initialization - interface_unlock_exclusive(omExt); - thiz->mTrack = track; - thiz->mGains[0] = 1.0f; - thiz->mGains[1] = 1.0f; - thiz->mDestroyRequested = SL_BOOLEAN_FALSE; - } - break; - default: - return SL_RESULT_CONTENT_UNSUPPORTED; - } - - assert(NULL != track); - track->mBufferQueue = &thiz->mBufferQueue; - track->mAudioPlayer = thiz; - track->mReader = NULL; - track->mAvail = 0; - track->mGains[0] = 1.0f; - track->mGains[1] = 1.0f; - track->mFramesMixed = 0; - return SL_RESULT_SUCCESS; -} - - -/** \brief Called when a gain-related field (mute, solo, volume, stereo position, etc.) updated */ - -void audioPlayerGainUpdate(CAudioPlayer *audioPlayer) -{ - SLboolean mute = audioPlayer->mVolume.mMute; - SLuint8 muteMask = audioPlayer->mMuteMask; - SLuint8 soloMask = audioPlayer->mSoloMask; - SLmillibel level = audioPlayer->mVolume.mLevel; - SLboolean enableStereoPosition = audioPlayer->mVolume.mEnableStereoPosition; - SLpermille stereoPosition = audioPlayer->mVolume.mStereoPosition; - - if (soloMask) { - muteMask |= ~soloMask; - } - if (mute || !(~muteMask & 3)) { - audioPlayer->mGains[0] = 0.0f; - audioPlayer->mGains[1] = 0.0f; - } else { - float playerGain = powf(10.0f, level / 2000.0f); - unsigned channel; - for (channel = 0; channel < STEREO_CHANNELS; ++channel) { - float gain; - if (muteMask & (1 << channel)) { - gain = 0.0f; - } else { - gain = playerGain; - if (enableStereoPosition) { - switch (channel) { - case 0: - if (stereoPosition > 0) { - gain *= (1000 - stereoPosition) / 1000.0f; - } - break; - case 1: - if (stereoPosition < 0) { - gain *= (1000 + stereoPosition) / 1000.0f; - } - break; - default: - assert(SL_BOOLEAN_FALSE); - break; - } - } - } - audioPlayer->mGains[channel] = gain; - } - } -} diff --git a/wilhelm/src/itf/IPitch.c b/wilhelm/src/itf/IPitch.c deleted file mode 100644 index 86729728..00000000 --- a/wilhelm/src/itf/IPitch.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - * 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. - */ - -/* Pitch implementation */ - -#include "sles_allinclusive.h" - - -static SLresult IPitch_SetPitch(SLPitchItf self, SLpermille pitch) -{ - SL_ENTER_INTERFACE - - IPitch *thiz = (IPitch *) self; - // const, so no lock needed - if (!(thiz->mMinPitch <= pitch && pitch <= thiz->mMaxPitch)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - interface_lock_poke(thiz); - thiz->mPitch = pitch; - interface_unlock_poke(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IPitch_GetPitch(SLPitchItf self, SLpermille *pPitch) -{ - SL_ENTER_INTERFACE - - if (NULL == pPitch) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IPitch *thiz = (IPitch *) self; - interface_lock_peek(thiz); - SLpermille pitch = thiz->mPitch; - interface_unlock_peek(thiz); - *pPitch = pitch; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IPitch_GetPitchCapabilities(SLPitchItf self, - SLpermille *pMinPitch, SLpermille *pMaxPitch) -{ - SL_ENTER_INTERFACE - - // per spec, each is optional, and does not require that at least one must be non-NULL -#if 0 - if (NULL == pMinPitch && NULL == pMaxPitch) - result = SL_RESULT_PARAMETER_INVALID; -#endif - IPitch *thiz = (IPitch *) self; - // const, so no lock needed - SLpermille minPitch = thiz->mMinPitch; - SLpermille maxPitch = thiz->mMaxPitch; - if (NULL != pMinPitch) - *pMinPitch = minPitch; - if (NULL != pMaxPitch) - *pMaxPitch = maxPitch; - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static const struct SLPitchItf_ IPitch_Itf = { - IPitch_SetPitch, - IPitch_GetPitch, - IPitch_GetPitchCapabilities -}; - -void IPitch_init(void *self) -{ - IPitch *thiz = (IPitch *) self; - thiz->mItf = &IPitch_Itf; - thiz->mPitch = 1000; - // const - thiz->mMinPitch = -500; - thiz->mMaxPitch = 2000; -} diff --git a/wilhelm/src/itf/IPlay.c b/wilhelm/src/itf/IPlay.c deleted file mode 100644 index 8e444635..00000000 --- a/wilhelm/src/itf/IPlay.c +++ /dev/null @@ -1,474 +0,0 @@ -/* - * 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. - */ - -/* Play implementation */ - -#include "sles_allinclusive.h" - - -static SLresult IPlay_SetPlayState(SLPlayItf self, SLuint32 state) -{ - SL_ENTER_INTERFACE - - switch (state) { - case SL_PLAYSTATE_STOPPED: - case SL_PLAYSTATE_PAUSED: - case SL_PLAYSTATE_PLAYING: - { - IPlay *thiz = (IPlay *) self; - unsigned attr = ATTR_NONE; - result = SL_RESULT_SUCCESS; -#ifdef USE_OUTPUTMIXEXT - CAudioPlayer *audioPlayer = (SL_OBJECTID_AUDIOPLAYER == InterfaceToObjectID(thiz)) ? - (CAudioPlayer *) thiz->mThis : NULL; -#endif - interface_lock_exclusive(thiz); - SLuint32 oldState = thiz->mState; - if (state != oldState) { -#ifdef USE_OUTPUTMIXEXT - for (;; interface_cond_wait(thiz)) { - - // We are comparing the old state (left) vs. new state (right). - // Note that the old state is 3 bits wide, but new state is only 2 bits wide. - // That is why the old state is on the left and new state is on the right. - switch ((oldState << 2) | state) { - - case (SL_PLAYSTATE_STOPPED << 2) | SL_PLAYSTATE_STOPPED: - case (SL_PLAYSTATE_PAUSED << 2) | SL_PLAYSTATE_PAUSED: - case (SL_PLAYSTATE_PLAYING << 2) | SL_PLAYSTATE_PLAYING: - // no-op, and unreachable due to earlier "if (state != oldState)" - break; - - case (SL_PLAYSTATE_STOPPED << 2) | SL_PLAYSTATE_PLAYING: - case (SL_PLAYSTATE_PAUSED << 2) | SL_PLAYSTATE_PLAYING: - attr = ATTR_PLAY_STATE; - // set enqueue attribute if queue is non-empty and state becomes PLAYING - if ((NULL != audioPlayer) && (audioPlayer->mBufferQueue.mFront != - audioPlayer->mBufferQueue.mRear)) { - // note that USE_OUTPUTMIXEXT does not support ATTR_ABQ_ENQUEUE - attr |= ATTR_BQ_ENQUEUE; - } - // fall through - - case (SL_PLAYSTATE_STOPPED << 2) | SL_PLAYSTATE_PAUSED: - case (SL_PLAYSTATE_PLAYING << 2) | SL_PLAYSTATE_PAUSED: - // easy - thiz->mState = state; - break; - - case (SL_PLAYSTATE_STOPPING << 2) | SL_PLAYSTATE_STOPPED: - // either spurious wakeup, or someone else requested same transition - continue; - - case (SL_PLAYSTATE_STOPPING << 2) | SL_PLAYSTATE_PAUSED: - case (SL_PLAYSTATE_STOPPING << 2) | SL_PLAYSTATE_PLAYING: - // wait for other guy to finish his transition, then retry ours - continue; - - case (SL_PLAYSTATE_PAUSED << 2) | SL_PLAYSTATE_STOPPED: - case (SL_PLAYSTATE_PLAYING << 2) | SL_PLAYSTATE_STOPPED: - // tell mixer to stop, then wait for mixer to acknowledge the request to stop - thiz->mState = SL_PLAYSTATE_STOPPING; - continue; - - default: - // unexpected state - assert(SL_BOOLEAN_FALSE); - result = SL_RESULT_INTERNAL_ERROR; - break; - - } - - break; - } -#else - // Here life looks easy for an Android, but there are other troubles in play land - thiz->mState = state; - attr = ATTR_PLAY_STATE; - // no need to set ATTR_BQ_ENQUEUE or ATTR_ABQ_ENQUEUE -#endif - } - // SL_LOGD("set play state %d", state); - interface_unlock_exclusive_attributes(thiz, attr); - } - break; - default: - result = SL_RESULT_PARAMETER_INVALID; - break; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IPlay_GetPlayState(SLPlayItf self, SLuint32 *pState) -{ - SL_ENTER_INTERFACE - - if (NULL == pState) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IPlay *thiz = (IPlay *) self; - interface_lock_shared(thiz); - SLuint32 state = thiz->mState; - interface_unlock_shared(thiz); - result = SL_RESULT_SUCCESS; -#ifdef USE_OUTPUTMIXEXT - switch (state) { - case SL_PLAYSTATE_STOPPED: // as is - case SL_PLAYSTATE_PAUSED: - case SL_PLAYSTATE_PLAYING: - break; - case SL_PLAYSTATE_STOPPING: // these states require re-mapping - state = SL_PLAYSTATE_STOPPED; - break; - default: // impossible - assert(SL_BOOLEAN_FALSE); - state = SL_PLAYSTATE_STOPPED; - result = SL_RESULT_INTERNAL_ERROR; - break; - } -#endif - *pState = state; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IPlay_GetDuration(SLPlayItf self, SLmillisecond *pMsec) -{ - SL_ENTER_INTERFACE - - if (NULL == pMsec) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - result = SL_RESULT_SUCCESS; - IPlay *thiz = (IPlay *) self; - // even though this is a getter, it can modify state due to caching - interface_lock_exclusive(thiz); - SLmillisecond duration = thiz->mDuration; -#ifdef ANDROID - if (SL_TIME_UNKNOWN == duration) { - SLmillisecond temp; - switch (InterfaceToObjectID(thiz)) { - case SL_OBJECTID_AUDIOPLAYER: - result = android_audioPlayer_getDuration(thiz, &temp); - break; - case XA_OBJECTID_MEDIAPLAYER: - result = android_Player_getDuration(thiz, &temp); - break; - default: - result = SL_RESULT_FEATURE_UNSUPPORTED; - break; - } - if (SL_RESULT_SUCCESS == result) { - duration = temp; - thiz->mDuration = duration; - } - } -#else - // will be set by containing AudioPlayer or MidiPlayer object at Realize, if known, - // otherwise the duration will be updated each time a new maximum position is detected -#endif - interface_unlock_exclusive(thiz); - *pMsec = duration; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IPlay_GetPosition(SLPlayItf self, SLmillisecond *pMsec) -{ - SL_ENTER_INTERFACE - - if (NULL == pMsec) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IPlay *thiz = (IPlay *) self; - SLmillisecond position; - interface_lock_shared(thiz); -#ifdef ANDROID - // Android does not use the mPosition field for audio and media players - // and doesn't cache the position - switch (IObjectToObjectID((thiz)->mThis)) { - case SL_OBJECTID_AUDIOPLAYER: - android_audioPlayer_getPosition(thiz, &position); - break; - case XA_OBJECTID_MEDIAPLAYER: - android_Player_getPosition(thiz, &position); - break; - default: - // we shouldn'be here - assert(SL_BOOLEAN_FALSE); - } -#else - // on other platforms we depend on periodic updates to the current position - position = thiz->mPosition; - // if a seek is pending, then lie about current position so the seek appears synchronous - if (SL_OBJECTID_AUDIOPLAYER == InterfaceToObjectID(thiz)) { - CAudioPlayer *audioPlayer = (CAudioPlayer *) thiz->mThis; - SLmillisecond pos = audioPlayer->mSeek.mPos; - if (SL_TIME_UNKNOWN != pos) { - position = pos; - } - } -#endif - interface_unlock_shared(thiz); - *pMsec = position; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IPlay_RegisterCallback(SLPlayItf self, slPlayCallback callback, void *pContext) -{ - SL_ENTER_INTERFACE - - IPlay *thiz = (IPlay *) self; - interface_lock_exclusive(thiz); - thiz->mCallback = callback; - thiz->mContext = pContext; - // omits _attributes b/c noone cares deeply enough about these fields to need quick notification - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static SLresult IPlay_SetCallbackEventsMask(SLPlayItf self, SLuint32 eventFlags) -{ - SL_ENTER_INTERFACE - - if (eventFlags & ~(SL_PLAYEVENT_HEADATEND | SL_PLAYEVENT_HEADATMARKER | - SL_PLAYEVENT_HEADATNEWPOS | SL_PLAYEVENT_HEADMOVING | SL_PLAYEVENT_HEADSTALLED)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IPlay *thiz = (IPlay *) self; - interface_lock_exclusive(thiz); - if (thiz->mEventFlags != eventFlags) { -#ifdef USE_OUTPUTMIXEXT - // enabling the "head at new position" play event will postpone the next update event - if (!(thiz->mEventFlags & SL_PLAYEVENT_HEADATNEWPOS) && - (eventFlags & SL_PLAYEVENT_HEADATNEWPOS)) { - thiz->mFramesSincePositionUpdate = 0; - } -#endif - thiz->mEventFlags = eventFlags; - interface_unlock_exclusive_attributes(thiz, ATTR_TRANSPORT); - } else { - interface_unlock_exclusive(thiz); - } - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IPlay_GetCallbackEventsMask(SLPlayItf self, SLuint32 *pEventFlags) -{ - SL_ENTER_INTERFACE - - if (NULL == pEventFlags) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IPlay *thiz = (IPlay *) self; - interface_lock_shared(thiz); - SLuint32 eventFlags = thiz->mEventFlags; - interface_unlock_shared(thiz); - *pEventFlags = eventFlags; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IPlay_SetMarkerPosition(SLPlayItf self, SLmillisecond mSec) -{ - SL_ENTER_INTERFACE - - if (SL_TIME_UNKNOWN == mSec) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IPlay *thiz = (IPlay *) self; - bool significant = false; - interface_lock_exclusive(thiz); - if (thiz->mMarkerPosition != mSec) { - thiz->mMarkerPosition = mSec; - if (thiz->mEventFlags & SL_PLAYEVENT_HEADATMARKER) { - significant = true; - } - } - if (significant) { - interface_unlock_exclusive_attributes(thiz, ATTR_TRANSPORT); - } else { - interface_unlock_exclusive(thiz); - } - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IPlay_ClearMarkerPosition(SLPlayItf self) -{ - SL_ENTER_INTERFACE - - IPlay *thiz = (IPlay *) self; - bool significant = false; - interface_lock_exclusive(thiz); - // clearing the marker position is equivalent to setting the marker to SL_TIME_UNKNOWN - if (thiz->mMarkerPosition != SL_TIME_UNKNOWN) { - thiz->mMarkerPosition = SL_TIME_UNKNOWN; - if (thiz->mEventFlags & SL_PLAYEVENT_HEADATMARKER) { - significant = true; - } - } - if (significant) { - interface_unlock_exclusive_attributes(thiz, ATTR_TRANSPORT); - } else { - interface_unlock_exclusive(thiz); - } - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static SLresult IPlay_GetMarkerPosition(SLPlayItf self, SLmillisecond *pMsec) -{ - SL_ENTER_INTERFACE - - if (NULL == pMsec) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IPlay *thiz = (IPlay *) self; - interface_lock_shared(thiz); - SLmillisecond markerPosition = thiz->mMarkerPosition; - interface_unlock_shared(thiz); - *pMsec = markerPosition; - if (SL_TIME_UNKNOWN == markerPosition) { - result = SL_RESULT_PRECONDITIONS_VIOLATED; - } else { - result = SL_RESULT_SUCCESS; - } - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IPlay_SetPositionUpdatePeriod(SLPlayItf self, SLmillisecond mSec) -{ - SL_ENTER_INTERFACE - - if (0 == mSec) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IPlay *thiz = (IPlay *) self; - bool significant = false; - interface_lock_exclusive(thiz); - if (thiz->mPositionUpdatePeriod != mSec) { - thiz->mPositionUpdatePeriod = mSec; -#ifdef USE_OUTPUTMIXEXT - if (SL_OBJECTID_AUDIOPLAYER == InterfaceToObjectID(thiz)) { - CAudioPlayer *audioPlayer = (CAudioPlayer *) thiz->mThis; - SLuint32 frameUpdatePeriod = ((long long) mSec * - (long long) audioPlayer->mSampleRateMilliHz) / 1000000LL; - if (0 == frameUpdatePeriod) { - frameUpdatePeriod = ~0; - } - thiz->mFrameUpdatePeriod = frameUpdatePeriod; - // setting a new update period postpones the next callback - thiz->mFramesSincePositionUpdate = 0; - } -#endif - if (thiz->mEventFlags & SL_PLAYEVENT_HEADATNEWPOS) { - significant = true; - } - } - if (significant) { - interface_unlock_exclusive_attributes(thiz, ATTR_TRANSPORT); - } else { - interface_unlock_exclusive(thiz); - } - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IPlay_GetPositionUpdatePeriod(SLPlayItf self, SLmillisecond *pMsec) -{ - SL_ENTER_INTERFACE - - if (NULL == pMsec) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IPlay *thiz = (IPlay *) self; - interface_lock_shared(thiz); - SLmillisecond positionUpdatePeriod = thiz->mPositionUpdatePeriod; - interface_unlock_shared(thiz); - *pMsec = positionUpdatePeriod; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static const struct SLPlayItf_ IPlay_Itf = { - IPlay_SetPlayState, - IPlay_GetPlayState, - IPlay_GetDuration, - IPlay_GetPosition, - IPlay_RegisterCallback, - IPlay_SetCallbackEventsMask, - IPlay_GetCallbackEventsMask, - IPlay_SetMarkerPosition, - IPlay_ClearMarkerPosition, - IPlay_GetMarkerPosition, - IPlay_SetPositionUpdatePeriod, - IPlay_GetPositionUpdatePeriod -}; - -void IPlay_init(void *self) -{ - IPlay *thiz = (IPlay *) self; - thiz->mItf = &IPlay_Itf; - thiz->mState = SL_PLAYSTATE_STOPPED; - thiz->mDuration = SL_TIME_UNKNOWN; // will be set by containing player object - thiz->mPosition = (SLmillisecond) 0; - thiz->mCallback = NULL; - thiz->mContext = NULL; - thiz->mEventFlags = 0; - thiz->mMarkerPosition = SL_TIME_UNKNOWN; - thiz->mPositionUpdatePeriod = 1000; // per spec -#ifdef USE_OUTPUTMIXEXT - thiz->mFrameUpdatePeriod = 0; // because we don't know the sample rate yet - thiz->mLastSeekPosition = 0; - thiz->mFramesSinceLastSeek = 0; - thiz->mFramesSincePositionUpdate = 0; -#endif -} diff --git a/wilhelm/src/itf/IPlaybackRate.c b/wilhelm/src/itf/IPlaybackRate.c deleted file mode 100644 index 092d13b7..00000000 --- a/wilhelm/src/itf/IPlaybackRate.c +++ /dev/null @@ -1,201 +0,0 @@ -/* - * 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. - */ - -/* PlaybackRate implementation */ - -#include "sles_allinclusive.h" - - -static SLresult IPlaybackRate_SetRate(SLPlaybackRateItf self, SLpermille rate) -{ - SL_ENTER_INTERFACE - - IPlaybackRate *thiz = (IPlaybackRate *) self; - // const, so no lock needed - if (!(thiz->mMinRate <= rate && rate <= thiz->mMaxRate)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - interface_lock_exclusive(thiz); -#ifdef ANDROID - CAudioPlayer *ap = (SL_OBJECTID_AUDIOPLAYER == InterfaceToObjectID(thiz)) ? - (CAudioPlayer *) thiz->mThis : NULL; - if (NULL != ap) { - result = android_audioPlayer_setPlaybackRateAndConstraints(ap, rate, thiz->mProperties); - } else { - result = SL_RESULT_FEATURE_UNSUPPORTED; - } -#else - result = SL_RESULT_SUCCESS; -#endif - if (SL_RESULT_SUCCESS == result) { - thiz->mRate = rate; - } - interface_unlock_exclusive(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IPlaybackRate_GetRate(SLPlaybackRateItf self, SLpermille *pRate) -{ - SL_ENTER_INTERFACE - - if (NULL == pRate) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IPlaybackRate *thiz = (IPlaybackRate *) self; - interface_lock_shared(thiz); - SLpermille rate = thiz->mRate; - interface_unlock_shared(thiz); - *pRate = rate; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IPlaybackRate_SetPropertyConstraints(SLPlaybackRateItf self, SLuint32 constraints) -{ - SL_ENTER_INTERFACE - - IPlaybackRate *thiz = (IPlaybackRate *) self; - if (constraints & ~(SL_RATEPROP_SILENTAUDIO | SL_RATEPROP_STAGGEREDAUDIO | - SL_RATEPROP_NOPITCHCORAUDIO | SL_RATEPROP_PITCHCORAUDIO)) { - result = SL_RESULT_PARAMETER_INVALID; - // const, so no lock needed - } else if (!(thiz->mCapabilities & constraints)) { - result = SL_RESULT_FEATURE_UNSUPPORTED; - } else { - interface_lock_exclusive(thiz); -#ifdef ANDROID - // verify property support before storing - CAudioPlayer *ap = (SL_OBJECTID_AUDIOPLAYER == InterfaceToObjectID(thiz)) ? - (CAudioPlayer *) thiz->mThis : NULL; - if (NULL != ap) { - result = android_audioPlayer_setPlaybackRateAndConstraints(ap, thiz->mRate, - constraints); - } else { - result = SL_RESULT_FEATURE_UNSUPPORTED; - } -#else - result = SL_RESULT_SUCCESS; -#endif - if (result == SL_RESULT_SUCCESS) { - thiz->mProperties = constraints; - } - interface_unlock_exclusive(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IPlaybackRate_GetProperties(SLPlaybackRateItf self, SLuint32 *pProperties) -{ - SL_ENTER_INTERFACE - - if (NULL == pProperties) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IPlaybackRate *thiz = (IPlaybackRate *) self; - interface_lock_shared(thiz); - SLuint32 properties = thiz->mProperties; - interface_unlock_shared(thiz); - *pProperties = properties; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IPlaybackRate_GetCapabilitiesOfRate(SLPlaybackRateItf self, - SLpermille rate, SLuint32 *pCapabilities) -{ - SL_ENTER_INTERFACE - - if (NULL == pCapabilities) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IPlaybackRate *thiz = (IPlaybackRate *) self; - SLuint32 capabilities; - // const, so no lock needed - if (!(thiz->mMinRate <= rate && rate <= thiz->mMaxRate)) { - capabilities = 0; - result = SL_RESULT_PARAMETER_INVALID; - } else { - capabilities = thiz->mCapabilities; - result = SL_RESULT_SUCCESS; - } - *pCapabilities = capabilities; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IPlaybackRate_GetRateRange(SLPlaybackRateItf self, SLuint8 index, - SLpermille *pMinRate, SLpermille *pMaxRate, SLpermille *pStepSize, SLuint32 *pCapabilities) -{ - SL_ENTER_INTERFACE - - // only one range - if (NULL == pMinRate || NULL == pMaxRate || NULL == pStepSize || NULL == pCapabilities || - (0 < index)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IPlaybackRate *thiz = (IPlaybackRate *) self; - // const, so no lock needed - SLpermille minRate = thiz->mMinRate; - SLpermille maxRate = thiz->mMaxRate; - SLpermille stepSize = thiz->mStepSize; - SLuint32 capabilities = thiz->mCapabilities; - *pMinRate = minRate; - *pMaxRate = maxRate; - *pStepSize = stepSize; - *pCapabilities = capabilities; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static const struct SLPlaybackRateItf_ IPlaybackRate_Itf = { - IPlaybackRate_SetRate, - IPlaybackRate_GetRate, - IPlaybackRate_SetPropertyConstraints, - IPlaybackRate_GetProperties, - IPlaybackRate_GetCapabilitiesOfRate, - IPlaybackRate_GetRateRange -}; - -void IPlaybackRate_init(void *self) -{ - IPlaybackRate *thiz = (IPlaybackRate *) self; - thiz->mItf = &IPlaybackRate_Itf; - thiz->mProperties = SL_RATEPROP_NOPITCHCORAUDIO; - thiz->mRate = 1000; - // const after initialization; these are default values which may be overwritten - // during object creation but will not be modified after that - // (e.g. for an Android AudioPlayer, see sles_to_android_audioPlayerCreate) - thiz->mMinRate = 1000; - thiz->mMaxRate = 1000; - thiz->mStepSize = 0; - thiz->mCapabilities = SL_RATEPROP_NOPITCHCORAUDIO; -} diff --git a/wilhelm/src/itf/IPrefetchStatus.c b/wilhelm/src/itf/IPrefetchStatus.c deleted file mode 100644 index 906ba77c..00000000 --- a/wilhelm/src/itf/IPrefetchStatus.c +++ /dev/null @@ -1,184 +0,0 @@ -/* - * 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. - */ - -/* PrefetchStatus implementation */ - -#include "sles_allinclusive.h" - - -static SLresult IPrefetchStatus_GetPrefetchStatus(SLPrefetchStatusItf self, SLuint32 *pStatus) -{ - SL_ENTER_INTERFACE - - if (NULL == pStatus) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IPrefetchStatus *thiz = (IPrefetchStatus *) self; - interface_lock_shared(thiz); - SLuint32 status = thiz->mStatus; - interface_unlock_shared(thiz); - *pStatus = status; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IPrefetchStatus_GetFillLevel(SLPrefetchStatusItf self, SLpermille *pLevel) -{ - SL_ENTER_INTERFACE - - if (NULL == pLevel) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IPrefetchStatus *thiz = (IPrefetchStatus *) self; - interface_lock_shared(thiz); - SLpermille level = thiz->mLevel; - interface_unlock_shared(thiz); - *pLevel = level; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IPrefetchStatus_RegisterCallback(SLPrefetchStatusItf self, - slPrefetchCallback callback, void *pContext) -{ - SL_ENTER_INTERFACE - - IPrefetchStatus *thiz = (IPrefetchStatus *) self; - interface_lock_exclusive(thiz); - thiz->mCallback = callback; - thiz->mContext = pContext; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static SLresult IPrefetchStatus_SetCallbackEventsMask(SLPrefetchStatusItf self, SLuint32 eventFlags) -{ - SL_ENTER_INTERFACE - - if (eventFlags & ~(SL_PREFETCHEVENT_STATUSCHANGE | SL_PREFETCHEVENT_FILLLEVELCHANGE)) { - result = SL_RESULT_PARAMETER_INVALID; - - } else { - IPrefetchStatus *thiz = (IPrefetchStatus *) self; - interface_lock_exclusive(thiz); - thiz->mCallbackEventsMask = eventFlags; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IPrefetchStatus_GetCallbackEventsMask(SLPrefetchStatusItf self, - SLuint32 *pEventFlags) -{ - SL_ENTER_INTERFACE - - if (NULL == pEventFlags) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IPrefetchStatus *thiz = (IPrefetchStatus *) self; - interface_lock_shared(thiz); - SLuint32 callbackEventsMask = thiz->mCallbackEventsMask; - interface_unlock_shared(thiz); - *pEventFlags = callbackEventsMask; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IPrefetchStatus_SetFillUpdatePeriod(SLPrefetchStatusItf self, SLpermille period) -{ - SL_ENTER_INTERFACE - - if (0 == period) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IPrefetchStatus *thiz = (IPrefetchStatus *) self; - interface_lock_exclusive(thiz); - thiz->mFillUpdatePeriod = period; -#ifdef ANDROID - if (SL_OBJECTID_AUDIOPLAYER == InterfaceToObjectID(thiz)) { - CAudioPlayer *ap = (CAudioPlayer *) thiz->mThis; - android_audioPlayer_setBufferingUpdateThresholdPerMille(ap, period); - } -#endif - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IPrefetchStatus_GetFillUpdatePeriod(SLPrefetchStatusItf self, SLpermille *pPeriod) -{ - SL_ENTER_INTERFACE - - if (NULL == pPeriod) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IPrefetchStatus *thiz = (IPrefetchStatus *) self; - interface_lock_shared(thiz); - SLpermille fillUpdatePeriod = thiz->mFillUpdatePeriod; - interface_unlock_shared(thiz); - *pPeriod = fillUpdatePeriod; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static const struct SLPrefetchStatusItf_ IPrefetchStatus_Itf = { - IPrefetchStatus_GetPrefetchStatus, - IPrefetchStatus_GetFillLevel, - IPrefetchStatus_RegisterCallback, - IPrefetchStatus_SetCallbackEventsMask, - IPrefetchStatus_GetCallbackEventsMask, - IPrefetchStatus_SetFillUpdatePeriod, - IPrefetchStatus_GetFillUpdatePeriod -}; - -void IPrefetchStatus_init(void *self) -{ - IPrefetchStatus *thiz = (IPrefetchStatus *) self; - thiz->mItf = &IPrefetchStatus_Itf; - thiz->mStatus = SL_PREFETCHSTATUS_UNDERFLOW; - thiz->mLevel = 0; - thiz->mCallback = NULL; - thiz->mContext = NULL; - thiz->mCallbackEventsMask = 0; - thiz->mFillUpdatePeriod = 100; -#ifdef ANDROID - thiz->mDeferredPrefetchCallback = NULL; - thiz->mDeferredPrefetchContext = NULL; - thiz->mDeferredPrefetchEvents = SL_PREFETCHEVENT_NONE; -#endif -} diff --git a/wilhelm/src/itf/IPresetReverb.c b/wilhelm/src/itf/IPresetReverb.c deleted file mode 100644 index 07214e59..00000000 --- a/wilhelm/src/itf/IPresetReverb.c +++ /dev/null @@ -1,134 +0,0 @@ -/* - * 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. - */ - -/* PresetReverb implementation */ - -#include "sles_allinclusive.h" - -#if defined(ANDROID) -/** - * returns true if this interface is not associated with an initialized PresetReverb effect - */ -static inline bool NO_PRESETREVERB(IPresetReverb* ipr) { - return (ipr->mPresetReverbEffect == 0); -} -#endif - -static SLresult IPresetReverb_SetPreset(SLPresetReverbItf self, SLuint16 preset) -{ - SL_ENTER_INTERFACE - - IPresetReverb *thiz = (IPresetReverb *) self; - switch (preset) { - case SL_REVERBPRESET_NONE: - case SL_REVERBPRESET_SMALLROOM: - case SL_REVERBPRESET_MEDIUMROOM: - case SL_REVERBPRESET_LARGEROOM: - case SL_REVERBPRESET_MEDIUMHALL: - case SL_REVERBPRESET_LARGEHALL: - case SL_REVERBPRESET_PLATE: - interface_lock_exclusive(thiz); - thiz->mPreset = preset; -#if !defined(ANDROID) - result = SL_RESULT_SUCCESS; -#else - if (NO_PRESETREVERB(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = android_prev_setPreset(thiz->mPresetReverbEffect, preset); - result = android_fx_statusToResult(status); - } -#endif - interface_unlock_exclusive(thiz); - break; - default: - result = SL_RESULT_PARAMETER_INVALID; - break; - } - - SL_LEAVE_INTERFACE -} - -static SLresult IPresetReverb_GetPreset(SLPresetReverbItf self, SLuint16 *pPreset) -{ - SL_ENTER_INTERFACE - - if (NULL == pPreset) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IPresetReverb *thiz = (IPresetReverb *) self; - interface_lock_shared(thiz); - SLuint16 preset = SL_REVERBPRESET_NONE; -#if 1 // !defined(ANDROID) - preset = thiz->mPreset; - result = SL_RESULT_SUCCESS; -#else - if (NO_PRESETREVERB(thiz)) { - preset = thiz->mPreset; - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = android_prev_getPreset(thiz->mPresetReverbEffect, &preset); - result = android_fx_statusToResult(status); - } - // OpenSL ES 1.0.1 spec and conformance test do not permit SL_RESULT_CONTROL_LOST - if (SL_RESULT_CONTROL_LOST == result) { - result = SL_RESULT_SUCCESS; - } -#endif - interface_unlock_shared(thiz); - *pPreset = preset; - } - - SL_LEAVE_INTERFACE -} - -static const struct SLPresetReverbItf_ IPresetReverb_Itf = { - IPresetReverb_SetPreset, - IPresetReverb_GetPreset -}; - -void IPresetReverb_init(void *self) -{ - IPresetReverb *thiz = (IPresetReverb *) self; - thiz->mItf = &IPresetReverb_Itf; - thiz->mPreset = SL_REVERBPRESET_NONE; -#if defined(ANDROID) - memset(&thiz->mPresetReverbDescriptor, 0, sizeof(effect_descriptor_t)); - // placement new (explicit constructor) - (void) new (&thiz->mPresetReverbEffect) android::sp<android::AudioEffect>(); -#endif -} - -void IPresetReverb_deinit(void *self) -{ -#if defined(ANDROID) - IPresetReverb *thiz = (IPresetReverb *) self; - // explicit destructor - thiz->mPresetReverbEffect.~sp(); -#endif -} - -bool IPresetReverb_Expose(void *self) -{ -#if defined(ANDROID) - IPresetReverb *thiz = (IPresetReverb *) self; - if (!android_fx_initEffectDescriptor(SL_IID_PRESETREVERB, &thiz->mPresetReverbDescriptor)) { - SL_LOGE("PresetReverb initialization failed."); - return false; - } -#endif - return true; -} diff --git a/wilhelm/src/itf/IRatePitch.c b/wilhelm/src/itf/IRatePitch.c deleted file mode 100644 index f83b5b40..00000000 --- a/wilhelm/src/itf/IRatePitch.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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. - */ - -/* RatePitch implementation */ - -#include "sles_allinclusive.h" - - -static SLresult IRatePitch_SetRate(SLRatePitchItf self, SLpermille rate) -{ - SL_ENTER_INTERFACE - - IRatePitch *thiz = (IRatePitch *) self; - if (!(thiz->mMinRate <= rate && rate <= thiz->mMaxRate)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - interface_lock_poke(thiz); - thiz->mRate = rate; - interface_unlock_poke(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IRatePitch_GetRate(SLRatePitchItf self, SLpermille *pRate) -{ - SL_ENTER_INTERFACE - - if (NULL == pRate) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IRatePitch *thiz = (IRatePitch *) self; - interface_lock_peek(thiz); - SLpermille rate = thiz->mRate; - interface_unlock_peek(thiz); - *pRate = rate; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IRatePitch_GetRatePitchCapabilities(SLRatePitchItf self, - SLpermille *pMinRate, SLpermille *pMaxRate) -{ - SL_ENTER_INTERFACE - - // per spec, each is optional, and does not require that at least one must be non-NULL -#if 0 - if (NULL == pMinRate && NULL == pMaxRate) - result = SL_RESULT_PARAMETER_INVALID; -#endif - IRatePitch *thiz = (IRatePitch *) self; - // const, so no lock required - SLpermille minRate = thiz->mMinRate; - SLpermille maxRate = thiz->mMaxRate; - if (NULL != pMinRate) - *pMinRate = minRate; - if (NULL != pMaxRate) - *pMaxRate = maxRate; - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static const struct SLRatePitchItf_ IRatePitch_Itf = { - IRatePitch_SetRate, - IRatePitch_GetRate, - IRatePitch_GetRatePitchCapabilities -}; - -void IRatePitch_init(void *self) -{ - IRatePitch *thiz = (IRatePitch *) self; - thiz->mItf = &IRatePitch_Itf; - thiz->mRate = 1000; - // const - thiz->mMinRate = 500; - thiz->mMaxRate = 2000; -} diff --git a/wilhelm/src/itf/IRecord.c b/wilhelm/src/itf/IRecord.c deleted file mode 100644 index 3ac3f0c2..00000000 --- a/wilhelm/src/itf/IRecord.c +++ /dev/null @@ -1,323 +0,0 @@ -/* - * 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. - */ - -/* Record implementation */ - -#include "sles_allinclusive.h" - - -static SLresult IRecord_SetRecordState(SLRecordItf self, SLuint32 state) -{ - SL_ENTER_INTERFACE - - switch (state) { - case SL_RECORDSTATE_STOPPED: - case SL_RECORDSTATE_PAUSED: - case SL_RECORDSTATE_RECORDING: - { - IRecord *thiz = (IRecord *) self; - interface_lock_exclusive(thiz); - thiz->mState = state; -#ifdef ANDROID - android_audioRecorder_setRecordState(InterfaceToCAudioRecorder(thiz), state); -#endif - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - } - break; - default: - result = SL_RESULT_PARAMETER_INVALID; - break; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IRecord_GetRecordState(SLRecordItf self, SLuint32 *pState) -{ - SL_ENTER_INTERFACE - - IRecord *thiz = (IRecord *) self; - if (NULL == pState) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - interface_lock_shared(thiz); - SLuint32 state = thiz->mState; - interface_unlock_shared(thiz); - *pState = state; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IRecord_SetDurationLimit(SLRecordItf self, SLmillisecond msec) -{ - SL_ENTER_INTERFACE - - IRecord *thiz = (IRecord *) self; - interface_lock_exclusive(thiz); - if (thiz->mDurationLimit != msec) { - thiz->mDurationLimit = msec; - interface_unlock_exclusive_attributes(thiz, ATTR_TRANSPORT); - } else { - interface_unlock_exclusive(thiz); - } - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static SLresult IRecord_GetPosition(SLRecordItf self, SLmillisecond *pMsec) -{ - SL_ENTER_INTERFACE - - if (NULL == pMsec) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IRecord *thiz = (IRecord *) self; - SLmillisecond position; - interface_lock_shared(thiz); -#ifdef ANDROID - // Android does not use the mPosition field for audio recorders - if (SL_OBJECTID_AUDIORECORDER == InterfaceToObjectID(thiz)) { - android_audioRecorder_getPosition(InterfaceToCAudioRecorder(thiz), &position); - } else { - position = thiz->mPosition; - } -#else - position = thiz->mPosition; -#endif - interface_unlock_shared(thiz); - *pMsec = position; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IRecord_RegisterCallback(SLRecordItf self, slRecordCallback callback, - void *pContext) -{ - SL_ENTER_INTERFACE - - IRecord *thiz = (IRecord *) self; - interface_lock_exclusive(thiz); - thiz->mCallback = callback; - thiz->mContext = pContext; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static SLresult IRecord_SetCallbackEventsMask(SLRecordItf self, SLuint32 eventFlags) -{ - SL_ENTER_INTERFACE - - if (eventFlags & ~( - SL_RECORDEVENT_HEADATLIMIT | - SL_RECORDEVENT_HEADATMARKER | - SL_RECORDEVENT_HEADATNEWPOS | - SL_RECORDEVENT_HEADMOVING | - SL_RECORDEVENT_HEADSTALLED | - SL_RECORDEVENT_BUFFER_FULL)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IRecord *thiz = (IRecord *) self; - interface_lock_exclusive(thiz); - if (thiz->mCallbackEventsMask != eventFlags) { - thiz->mCallbackEventsMask = eventFlags; - interface_unlock_exclusive_attributes(thiz, ATTR_TRANSPORT); - } else { - interface_unlock_exclusive(thiz); - } - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IRecord_GetCallbackEventsMask(SLRecordItf self, SLuint32 *pEventFlags) -{ - SL_ENTER_INTERFACE - - if (NULL == pEventFlags) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IRecord *thiz = (IRecord *) self; - interface_lock_shared(thiz); - SLuint32 callbackEventsMask = thiz->mCallbackEventsMask; - interface_unlock_shared(thiz); - *pEventFlags = callbackEventsMask; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IRecord_SetMarkerPosition(SLRecordItf self, SLmillisecond mSec) -{ - SL_ENTER_INTERFACE - - if (SL_TIME_UNKNOWN == mSec) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IRecord *thiz = (IRecord *) self; - bool significant = false; - interface_lock_exclusive(thiz); - if (thiz->mMarkerPosition != mSec) { - thiz->mMarkerPosition = mSec; - if (thiz->mCallbackEventsMask & SL_PLAYEVENT_HEADATMARKER) { - significant = true; - } - } - if (significant) { - interface_unlock_exclusive_attributes(thiz, ATTR_TRANSPORT); - } else { - interface_unlock_exclusive(thiz); - } - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IRecord_ClearMarkerPosition(SLRecordItf self) -{ - SL_ENTER_INTERFACE - - IRecord *thiz = (IRecord *) self; - bool significant = false; - interface_lock_exclusive(thiz); - // clearing the marker position is equivalent to setting the marker to SL_TIME_UNKNOWN - if (thiz->mMarkerPosition != SL_TIME_UNKNOWN) { - thiz->mMarkerPosition = SL_TIME_UNKNOWN; - if (thiz->mCallbackEventsMask & SL_PLAYEVENT_HEADATMARKER) { - significant = true; - } - } - if (significant) { - interface_unlock_exclusive_attributes(thiz, ATTR_TRANSPORT); - } else { - interface_unlock_exclusive(thiz); - } - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static SLresult IRecord_GetMarkerPosition(SLRecordItf self, SLmillisecond *pMsec) -{ - SL_ENTER_INTERFACE - - if (NULL == pMsec) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IRecord *thiz = (IRecord *) self; - interface_lock_shared(thiz); - SLmillisecond markerPosition = thiz->mMarkerPosition; - interface_unlock_shared(thiz); - *pMsec = markerPosition; - if (SL_TIME_UNKNOWN == markerPosition) { - result = SL_RESULT_PRECONDITIONS_VIOLATED; - } else { - result = SL_RESULT_SUCCESS; - } - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IRecord_SetPositionUpdatePeriod(SLRecordItf self, SLmillisecond mSec) -{ - SL_ENTER_INTERFACE - - if (0 == mSec) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IRecord *thiz = (IRecord *) self; - interface_lock_exclusive(thiz); - if (thiz->mPositionUpdatePeriod != mSec) { - thiz->mPositionUpdatePeriod = mSec; - interface_unlock_exclusive_attributes(thiz, ATTR_TRANSPORT); - } else { - interface_unlock_exclusive(thiz); - } - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IRecord_GetPositionUpdatePeriod(SLRecordItf self, SLmillisecond *pMsec) -{ - SL_ENTER_INTERFACE - - if (NULL == pMsec) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IRecord *thiz = (IRecord *) self; - interface_lock_shared(thiz); - SLmillisecond positionUpdatePeriod = thiz->mPositionUpdatePeriod; - interface_unlock_shared(thiz); - *pMsec = positionUpdatePeriod; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static const struct SLRecordItf_ IRecord_Itf = { - IRecord_SetRecordState, - IRecord_GetRecordState, - IRecord_SetDurationLimit, - IRecord_GetPosition, - IRecord_RegisterCallback, - IRecord_SetCallbackEventsMask, - IRecord_GetCallbackEventsMask, - IRecord_SetMarkerPosition, - IRecord_ClearMarkerPosition, - IRecord_GetMarkerPosition, - IRecord_SetPositionUpdatePeriod, - IRecord_GetPositionUpdatePeriod -}; - -void IRecord_init(void *self) -{ - IRecord *thiz = (IRecord *) self; - thiz->mItf = &IRecord_Itf; - thiz->mState = SL_RECORDSTATE_STOPPED; - thiz->mDurationLimit = 0; - thiz->mPosition = (SLmillisecond) 0; - thiz->mCallback = NULL; - thiz->mContext = NULL; - thiz->mCallbackEventsMask = 0; - thiz->mMarkerPosition = SL_TIME_UNKNOWN; - thiz->mPositionUpdatePeriod = 1000; // per spec -} diff --git a/wilhelm/src/itf/ISeek.c b/wilhelm/src/itf/ISeek.c deleted file mode 100644 index 3422ae1a..00000000 --- a/wilhelm/src/itf/ISeek.c +++ /dev/null @@ -1,146 +0,0 @@ -/* - * 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. - */ - -/* Seek implementation */ - -#include "sles_allinclusive.h" - - -static SLresult ISeek_SetPosition(SLSeekItf self, SLmillisecond pos, SLuint32 seekMode) -{ - SL_ENTER_INTERFACE - - switch (seekMode) { - case SL_SEEKMODE_FAST: - case SL_SEEKMODE_ACCURATE: - { - // maximum position is a special value that indicates a seek is not pending - if (SL_TIME_UNKNOWN == pos) { - pos = SL_TIME_UNKNOWN - 1; - } - ISeek *thiz = (ISeek *) self; - interface_lock_exclusive(thiz); - thiz->mPos = pos; - // at this point the seek is merely pending, so do not yet update other fields - interface_unlock_exclusive_attributes(thiz, ATTR_POSITION); - result = SL_RESULT_SUCCESS; - } - break; - default: - result = SL_RESULT_PARAMETER_INVALID; - break; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult ISeek_SetLoop(SLSeekItf self, SLboolean loopEnable, - SLmillisecond startPos, SLmillisecond endPos) -{ - SL_ENTER_INTERFACE - - if (!(startPos < endPos)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - ISeek *thiz = (ISeek *) self; - interface_lock_exclusive(thiz); -#ifdef ANDROID - if ((startPos != 0) && (endPos != SL_TIME_UNKNOWN)) { - result = SL_RESULT_FEATURE_UNSUPPORTED; - } else { - switch (IObjectToObjectID((thiz)->mThis)) { - case SL_OBJECTID_AUDIOPLAYER: { - CAudioPlayer *ap = InterfaceToCAudioPlayer(thiz); - if (NULL != ap) { - result = android_audioPlayer_loop(ap, loopEnable); - } else { - result = SL_RESULT_PARAMETER_INVALID; - } - break; - } - case XA_OBJECTID_MEDIAPLAYER: { - CMediaPlayer *mp = InterfaceToCMediaPlayer(thiz); - if (NULL != mp) { - result = android_Player_loop(mp, loopEnable); - } else { - result = SL_RESULT_PARAMETER_INVALID; - } - break; - } - default: { - result = SL_RESULT_PARAMETER_INVALID; - } - } - if (SL_RESULT_SUCCESS == result) { - thiz->mLoopEnabled = SL_BOOLEAN_FALSE != loopEnable; // normalize - // start and end positions already initialized to [0, end of stream] - /*thiz->mStartPos = 0; - thiz->mEndPos = (SLmillisecond) SL_TIME_UNKNOWN;*/ - } - } -#else - thiz->mLoopEnabled = SL_BOOLEAN_FALSE != loopEnable; // normalize - thiz->mStartPos = startPos; - thiz->mEndPos = endPos; - result = SL_RESULT_SUCCESS; -#endif - interface_unlock_exclusive(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult ISeek_GetLoop(SLSeekItf self, SLboolean *pLoopEnabled, - SLmillisecond *pStartPos, SLmillisecond *pEndPos) -{ - SL_ENTER_INTERFACE - - if (NULL == pLoopEnabled || NULL == pStartPos || NULL == pEndPos) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - ISeek *thiz = (ISeek *) self; - interface_lock_shared(thiz); - SLboolean loopEnabled = thiz->mLoopEnabled; - SLmillisecond startPos = thiz->mStartPos; - SLmillisecond endPos = thiz->mEndPos; - interface_unlock_shared(thiz); - *pLoopEnabled = loopEnabled; - *pStartPos = startPos; - *pEndPos = endPos; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static const struct SLSeekItf_ ISeek_Itf = { - ISeek_SetPosition, - ISeek_SetLoop, - ISeek_GetLoop -}; - -void ISeek_init(void *self) -{ - ISeek *thiz = (ISeek *) self; - thiz->mItf = &ISeek_Itf; - thiz->mPos = (SLmillisecond) SL_TIME_UNKNOWN; - thiz->mStartPos = (SLmillisecond) 0; - thiz->mEndPos = (SLmillisecond) SL_TIME_UNKNOWN; - thiz->mLoopEnabled = SL_BOOLEAN_FALSE; -} diff --git a/wilhelm/src/itf/IStreamInformation.c b/wilhelm/src/itf/IStreamInformation.c deleted file mode 100644 index d8da5a9b..00000000 --- a/wilhelm/src/itf/IStreamInformation.c +++ /dev/null @@ -1,321 +0,0 @@ -/* - * 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. - */ - -/* StreamInformation implementation */ - -#include "sles_allinclusive.h" - -static XAresult IStreamInformation_QueryMediaContainerInformation( XAStreamInformationItf self, - XAMediaContainerInformation * info /* [out] */) -{ - XA_ENTER_INTERFACE - - if (NULL == info) { - result = XA_RESULT_PARAMETER_INVALID; - XA_LEAVE_INTERFACE - } - -#ifdef ANDROID - IStreamInformation *thiz = (IStreamInformation *) self; - interface_lock_shared(thiz); - // always storing container info at index 0, as per spec - *info = thiz->mStreamInfoTable.itemAt(0).containerInfo; - interface_unlock_shared(thiz); - // even though the pointer to the media container info is returned, the values aren't set - // for the actual container in this version, they are simply initialized to defaults - // (see IStreamInformation_init) - result = XA_RESULT_SUCCESS; -#else - SL_LOGE("QueryMediaContainerInformation is unsupported"); - memset(info, 0, sizeof(XAMediaContainerInformation)); - result = XA_RESULT_FEATURE_UNSUPPORTED; -#endif - - XA_LEAVE_INTERFACE -} - - -static XAresult IStreamInformation_QueryStreamType( XAStreamInformationItf self, - XAuint32 streamIndex, /* [in] */ - XAuint32 *domain) /* [out] */ -{ - XA_ENTER_INTERFACE - - if (NULL == domain) { - result = XA_RESULT_PARAMETER_INVALID; - XA_LEAVE_INTERFACE; - } - -#ifndef ANDROID - *domain = XA_DOMAINTYPE_UNKNOWN; -#else - if (0 == streamIndex) { - // stream 0 is reserved for the container - result = XA_RESULT_PARAMETER_INVALID; - *domain = XA_DOMAINTYPE_UNKNOWN; - } else { - IStreamInformation *thiz = (IStreamInformation *) self; - - interface_lock_shared(thiz); - - XAuint32 nbStreams = thiz->mStreamInfoTable.itemAt(0).containerInfo.numStreams; - // streams in the container are numbered 1..nbStreams - if (streamIndex <= nbStreams) { - result = XA_RESULT_SUCCESS; - *domain = thiz->mStreamInfoTable.itemAt(streamIndex).domain; - } else { - SL_LOGE("Querying stream type for stream %d, only %d streams available", - streamIndex, nbStreams); - result = XA_RESULT_PARAMETER_INVALID; - } - - interface_unlock_shared(thiz); - } -#endif - - XA_LEAVE_INTERFACE -} - - -static XAresult IStreamInformation_QueryStreamInformation( XAStreamInformationItf self, - XAuint32 streamIndex, /* [in] */ - void * info) /* [out] */ -{ - XA_ENTER_INTERFACE - - if (NULL == info) { - result = XA_RESULT_PARAMETER_INVALID; - } else { - -#ifndef ANDROID - result = XA_RESULT_FEATURE_UNSUPPORTED; -#else - - IStreamInformation *thiz = (IStreamInformation *) self; - - interface_lock_shared(thiz); - - XAuint32 nbStreams = thiz->mStreamInfoTable.itemAt(0).containerInfo.numStreams; - // stream 0 is the container, and other streams in the container are numbered 1..nbStreams - if (streamIndex <= nbStreams) { - result = XA_RESULT_SUCCESS; - const StreamInfo& streamInfo = thiz->mStreamInfoTable.itemAt((size_t)streamIndex); - - switch (streamInfo.domain) { - case XA_DOMAINTYPE_CONTAINER: - *(XAMediaContainerInformation *)info = streamInfo.containerInfo; - break; - case XA_DOMAINTYPE_AUDIO: - *(XAAudioStreamInformation *)info = streamInfo.audioInfo; - break; - case XA_DOMAINTYPE_VIDEO: - *(XAVideoStreamInformation *)info = streamInfo.videoInfo; - break; - case XA_DOMAINTYPE_IMAGE: - *(XAImageStreamInformation *)info = streamInfo.imageInfo; - break; - case XA_DOMAINTYPE_TIMEDTEXT: - *(XATimedTextStreamInformation *)info = streamInfo.textInfo; - break; - case XA_DOMAINTYPE_MIDI: - *(XAMIDIStreamInformation *)info = streamInfo.midiInfo; - break; - case XA_DOMAINTYPE_VENDOR: - *(XAVendorStreamInformation *)info = streamInfo.vendorInfo; - break; - default: - SL_LOGE("StreamInformation::QueryStreamInformation index %u has " - "unknown domain %u", streamIndex, streamInfo.domain); - result = XA_RESULT_INTERNAL_ERROR; - break; - } - - } else { - SL_LOGE("Querying stream type for stream %d, only %d streams available", - streamIndex, nbStreams); - result = XA_RESULT_PARAMETER_INVALID; - } - - interface_unlock_shared(thiz); -#endif - - } - - XA_LEAVE_INTERFACE -} - - -static XAresult IStreamInformation_QueryStreamName( XAStreamInformationItf self, - XAuint32 streamIndex, /* [in] */ - XAuint16 * pNameSize, /* [in/out] */ - XAchar * pName) /* [out] */ -{ - XA_ENTER_INTERFACE - - if (NULL == pNameSize || streamIndex == 0) { - result = XA_RESULT_PARAMETER_INVALID; - } else { -#ifdef ANDROID - IStreamInformation *thiz = (IStreamInformation *) self; - interface_lock_shared(thiz); - - XAuint32 nbStreams = thiz->mStreamInfoTable.itemAt(0).containerInfo.numStreams; - // streams in the container are numbered 1..nbStreams - if (streamIndex <= nbStreams) { - char streamName[16]; // large enough for the fixed format in next line - snprintf(streamName, sizeof(streamName), "stream%u", streamIndex); - size_t actualNameLength = strlen(streamName); - if (NULL == pName) { - // application is querying the name length in order to allocate a buffer - result = XA_RESULT_SUCCESS; - } else { - SLuint16 availableNameLength = *pNameSize; - if (actualNameLength > availableNameLength) { - memcpy(pName, streamName, availableNameLength); - result = XA_RESULT_BUFFER_INSUFFICIENT; - } else if (actualNameLength == availableNameLength) { - memcpy(pName, streamName, availableNameLength); - result = XA_RESULT_SUCCESS; - } else { // actualNameLength < availableNameLength - memcpy(pName, streamName, actualNameLength + 1); - result = XA_RESULT_SUCCESS; - } - } - *pNameSize = actualNameLength; - } else { - result = XA_RESULT_PARAMETER_INVALID; - } - - interface_unlock_shared(thiz); -#else - SL_LOGE("unsupported XAStreamInformationItf function"); - result = XA_RESULT_FEATURE_UNSUPPORTED; -#endif - } - - XA_LEAVE_INTERFACE -} - - -static XAresult IStreamInformation_RegisterStreamChangeCallback( XAStreamInformationItf self, - xaStreamEventChangeCallback callback, /* [in] */ - void * pContext) /* [in] */ -{ - XA_ENTER_INTERFACE - - IStreamInformation *thiz = (IStreamInformation *) self; - - interface_lock_exclusive(thiz); - - thiz->mCallback = callback; - thiz->mContext = pContext; - result = SL_RESULT_SUCCESS; - - interface_unlock_exclusive(thiz); - - XA_LEAVE_INTERFACE -} - - -static XAresult IStreamInformation_QueryActiveStreams( XAStreamInformationItf self, - XAuint32 *numStreams, /* [in/out] */ - XAboolean *activeStreams) /* [out] */ -{ - XA_ENTER_INTERFACE - - if (NULL == numStreams) { - result = XA_RESULT_PARAMETER_INVALID; - XA_LEAVE_INTERFACE; - } - -#ifdef ANDROID - IStreamInformation *thiz = (IStreamInformation *) self; - interface_lock_shared(thiz); - - result = XA_RESULT_SUCCESS; - *numStreams = thiz->mStreamInfoTable.itemAt(0).containerInfo.numStreams; - activeStreams = thiz->mActiveStreams; - - interface_unlock_shared(thiz); -#else - result = SL_RESULT_FEATURE_UNSUPPORTED; -#endif - - XA_LEAVE_INTERFACE -} - - -static XAresult IStreamInformation_SetActiveStream( XAStreamInformationItf self, - XAuint32 streamNum, /* [in] */ - XAboolean active, /* [in] */ - XAboolean commitNow) /* [in] */ -{ - XA_ENTER_INTERFACE - - SL_LOGE("unsupported XAStreamInformationItf function"); - result = XA_RESULT_FEATURE_UNSUPPORTED; - - XA_LEAVE_INTERFACE -} - - -static const struct XAStreamInformationItf_ IStreamInformation_Itf = { - IStreamInformation_QueryMediaContainerInformation, - IStreamInformation_QueryStreamType, - IStreamInformation_QueryStreamInformation, - IStreamInformation_QueryStreamName, - IStreamInformation_RegisterStreamChangeCallback, - IStreamInformation_QueryActiveStreams, - IStreamInformation_SetActiveStream -}; - - -void IStreamInformation_init(void *self) -{ - SL_LOGV("IStreamInformation_init\n"); - IStreamInformation *thiz = (IStreamInformation *) self; - thiz->mItf = &IStreamInformation_Itf; - - thiz->mCallback = NULL; - thiz->mContext = NULL; - - for (int i=0 ; i < NB_SUPPORTED_STREAMS ; i++) { - thiz->mActiveStreams[i] = XA_BOOLEAN_FALSE; - } - -#ifdef ANDROID - // placement new constructor for C++ field within C struct - (void) new (&thiz->mStreamInfoTable) android::Vector<StreamInfo>(); - // initialize container info - StreamInfo contInf; - contInf.domain = XA_DOMAINTYPE_CONTAINER; - contInf.containerInfo.containerType = XA_CONTAINERTYPE_UNSPECIFIED; - contInf.containerInfo.mediaDuration = XA_TIME_UNKNOWN; - // FIXME shouldn't this be 1 ? - contInf.containerInfo.numStreams = 0; - // always storing container info at index 0, as per spec: here, the table was still empty - thiz->mStreamInfoTable.add(contInf); -#endif -} - - -void IStreamInformation_deinit(void *self) { -#ifdef ANDROID - IStreamInformation *thiz = (IStreamInformation *) self; - // explicit destructor - thiz->mStreamInfoTable.~Vector<StreamInfo>(); -#endif -} diff --git a/wilhelm/src/itf/IStreamInformation.cpp b/wilhelm/src/itf/IStreamInformation.cpp deleted file mode 100644 index 2141533e..00000000 --- a/wilhelm/src/itf/IStreamInformation.cpp +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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. - */ - -// Force compilation of code as C++ -#include "IStreamInformation.c" diff --git a/wilhelm/src/itf/IThreadSync.c b/wilhelm/src/itf/IThreadSync.c deleted file mode 100644 index 09d52dff..00000000 --- a/wilhelm/src/itf/IThreadSync.c +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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. - */ - -/* ThreadSync implementation */ - -#include "sles_allinclusive.h" - - -static SLresult IThreadSync_EnterCriticalSection(SLThreadSyncItf self) -{ - SL_ENTER_INTERFACE - - IThreadSync *thiz = (IThreadSync *) self; - interface_lock_exclusive(thiz); - for (;;) { - if (thiz->mInCriticalSection) { - if (!pthread_equal(thiz->mOwner, pthread_self())) { - ++thiz->mWaiting; - interface_cond_wait(thiz); - continue; - } - // nested locks are not allowed - result = SL_RESULT_PRECONDITIONS_VIOLATED; - break; - } - thiz->mInCriticalSection = SL_BOOLEAN_TRUE; - thiz->mOwner = pthread_self(); - result = SL_RESULT_SUCCESS; - break; - } - interface_unlock_exclusive(thiz); - - SL_LEAVE_INTERFACE -} - - -static SLresult IThreadSync_ExitCriticalSection(SLThreadSyncItf self) -{ - SL_ENTER_INTERFACE - - IThreadSync *thiz = (IThreadSync *) self; - interface_lock_exclusive(thiz); - if (!thiz->mInCriticalSection || !pthread_equal(thiz->mOwner, pthread_self())) { - result = SL_RESULT_PRECONDITIONS_VIOLATED; - } else { - thiz->mInCriticalSection = SL_BOOLEAN_FALSE; - memset(&thiz->mOwner, 0, sizeof(pthread_t)); - if (thiz->mWaiting) { - --thiz->mWaiting; - interface_cond_signal(thiz); - } - result = SL_RESULT_SUCCESS; - } - interface_unlock_exclusive(thiz); - - SL_LEAVE_INTERFACE -} - - -static const struct SLThreadSyncItf_ IThreadSync_Itf = { - IThreadSync_EnterCriticalSection, - IThreadSync_ExitCriticalSection -}; - -void IThreadSync_init(void *self) -{ - IThreadSync *thiz = (IThreadSync *) self; - thiz->mItf = &IThreadSync_Itf; - thiz->mInCriticalSection = SL_BOOLEAN_FALSE; - thiz->mWaiting = 0; - memset(&thiz->mOwner, 0, sizeof(pthread_t)); -} - -void IThreadSync_deinit(void *self) -{ - IThreadSync *thiz = (IThreadSync *) self; - if (thiz->mInCriticalSection) { - SL_LOGW("ThreadSync::EnterCriticalSection was active at Engine::Destroy"); - } -} diff --git a/wilhelm/src/itf/IVibra.c b/wilhelm/src/itf/IVibra.c deleted file mode 100644 index 67b10166..00000000 --- a/wilhelm/src/itf/IVibra.c +++ /dev/null @@ -1,157 +0,0 @@ -/* - * 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. - */ - -/* Vibra implementation */ - -#include "sles_allinclusive.h" - - -static SLresult IVibra_Vibrate(SLVibraItf self, SLboolean vibrate) -{ - SL_ENTER_INTERFACE - - IVibra *thiz = (IVibra *) self; - interface_lock_poke(thiz); - thiz->mVibrate = SL_BOOLEAN_FALSE != vibrate; // normalize - interface_unlock_poke(thiz); - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static SLresult IVibra_IsVibrating(SLVibraItf self, SLboolean *pVibrating) -{ - SL_ENTER_INTERFACE - - if (NULL == pVibrating) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IVibra *thiz = (IVibra *) self; - interface_lock_peek(thiz); - SLboolean vibrate = thiz->mVibrate; - interface_unlock_peek(thiz); - *pVibrating = vibrate; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IVibra_SetFrequency(SLVibraItf self, SLmilliHertz frequency) -{ - SL_ENTER_INTERFACE - - const SLVibraDescriptor *d = Vibra_id_descriptors[0].descriptor; - if (!d->supportsFrequency) { - result = SL_RESULT_PRECONDITIONS_VIOLATED; - } else if (!(d->minFrequency <= frequency && frequency <= d->maxFrequency)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IVibra *thiz = (IVibra *) self; - interface_lock_poke(thiz); - thiz->mFrequency = frequency; - interface_unlock_poke(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IVibra_GetFrequency(SLVibraItf self, SLmilliHertz *pFrequency) -{ - SL_ENTER_INTERFACE - - if (NULL == pFrequency) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IVibra *thiz = (IVibra *) self; - interface_lock_peek(thiz); - SLmilliHertz frequency = thiz->mFrequency; - interface_unlock_peek(thiz); - *pFrequency = frequency; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IVibra_SetIntensity(SLVibraItf self, SLpermille intensity) -{ - SL_ENTER_INTERFACE - - const SLVibraDescriptor *d = Vibra_id_descriptors[0].descriptor; - if (!d->supportsIntensity) { - result = SL_RESULT_PRECONDITIONS_VIOLATED; - } else if (!(0 <= intensity && intensity <= 1000)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IVibra *thiz = (IVibra *) self; - interface_lock_poke(thiz); - thiz->mIntensity = intensity; - interface_unlock_poke(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IVibra_GetIntensity(SLVibraItf self, SLpermille *pIntensity) -{ - SL_ENTER_INTERFACE - - if (NULL == pIntensity) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - const SLVibraDescriptor *d = Vibra_id_descriptors[0].descriptor; - if (!d->supportsIntensity) { - result = SL_RESULT_PRECONDITIONS_VIOLATED; - } else { - IVibra *thiz = (IVibra *) self; - interface_lock_peek(thiz); - SLpermille intensity = thiz->mIntensity; - interface_unlock_peek(thiz); - *pIntensity = intensity; - result = SL_RESULT_SUCCESS; - } - } - - SL_LEAVE_INTERFACE -} - - -static const struct SLVibraItf_ IVibra_Itf = { - IVibra_Vibrate, - IVibra_IsVibrating, - IVibra_SetFrequency, - IVibra_GetFrequency, - IVibra_SetIntensity, - IVibra_GetIntensity -}; - -void IVibra_init(void *self) -{ - IVibra *thiz = (IVibra *) self; - thiz->mItf = &IVibra_Itf; - thiz->mVibrate = SL_BOOLEAN_FALSE; - // next 2 values are undefined per spec - thiz->mFrequency = Vibra_id_descriptors[0].descriptor->minFrequency; - thiz->mIntensity = 1000; -} diff --git a/wilhelm/src/itf/IVideoDecoderCapabilities.cpp b/wilhelm/src/itf/IVideoDecoderCapabilities.cpp deleted file mode 100644 index c9649a99..00000000 --- a/wilhelm/src/itf/IVideoDecoderCapabilities.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/* - * 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. - */ - -/* VideoDecoderCapabilities implementation */ - -#include "sles_allinclusive.h" -#ifdef ANDROID -#include "android/VideoCodec_to_android.h" -#endif - - -static XAresult IVideoDecoderCapabilities_GetVideoDecoders(XAVideoDecoderCapabilitiesItf self, - XAuint32 *pNumDecoders, XAuint32 *pDecoderIds) -{ - XA_ENTER_INTERFACE - - if (NULL == pNumDecoders) { - result = XA_RESULT_PARAMETER_INVALID; - } else { - if (NULL == pDecoderIds) { - // If pDecoderIds is NULL, pNumDecoders returns the number of decoders available. -#ifdef ANDROID - *pNumDecoders = android::android_videoCodec_getNbDecoders(); -#else - *pNumDecoders = kMaxVideoDecoders; -#endif - - } else { - // If pDecodersIds is non-NULL, as an input pNumDecoders specifies the size of the - // pDecoderIds array and as an output it specifies the number of decoder IDs available - // within the pDecoderIds array. - XAuint32 numDecoders = *pNumDecoders; -#ifdef ANDROID - const XAuint32 androidNbDecoders = android::android_videoCodec_getNbDecoders(); - if (androidNbDecoders < numDecoders) { - *pNumDecoders = numDecoders = androidNbDecoders; - } - android::android_videoCodec_getDecoderIds(numDecoders, pDecoderIds); -#else - if (kMaxVideoDecoders < numDecoders) { - *pNumDecoders = numDecoders = kMaxVideoDecoders; - } - memcpy(pDecoderIds, VideoDecoderIds, numDecoders * sizeof(XAuint32)); -#endif - } - result = XA_RESULT_SUCCESS; - } - - XA_LEAVE_INTERFACE -} - - -static XAresult IVideoDecoderCapabilities_GetVideoDecoderCapabilities( - XAVideoDecoderCapabilitiesItf self, XAuint32 decoderId, XAuint32 *pIndex, - XAVideoCodecDescriptor *pDescriptor) -{ - XA_ENTER_INTERFACE - - if (NULL == pIndex) { - result = XA_RESULT_PARAMETER_INVALID; - } else { - if (NULL == pDescriptor) { - // pIndex returns the number of video decoders capability descriptions. -#ifdef ANDROID - result = android::android_videoCodec_getProfileLevelCombinationNb(decoderId, pIndex); -#else - // Generic implementation has zero profile/level combinations for all codecs, - // but this is not allowed per spec: - // "Each decoder must support at least one profile/mode pair - // and therefore have at least one Codec Descriptor." - *pIndex = 0; - SL_LOGE("Generic implementation has no video decoder capabilities"); - result = XA_RESULT_PARAMETER_INVALID; -#endif - } else { - // pIndex is an incrementing value used to enumerate capability descriptions. -#ifdef ANDROID - result = android::android_videoCodec_getProfileLevelCombination(decoderId, *pIndex, - pDescriptor); -#else - // For the generic implementation, any index >= 0 is out of range -#if 1 // not sure if this is needed, it's not being done for the Android case - pDescriptor->codecId = decoderId; -#endif - SL_LOGE("Generic implementation has no video decoder capabilities"); - result = XA_RESULT_PARAMETER_INVALID; -#endif - } - } - - XA_LEAVE_INTERFACE -} - - -static const struct XAVideoDecoderCapabilitiesItf_ IVideoDecoderCapabilities_Itf = { - IVideoDecoderCapabilities_GetVideoDecoders, - IVideoDecoderCapabilities_GetVideoDecoderCapabilities -}; - -void IVideoDecoderCapabilities_init(void *self) -{ - IVideoDecoderCapabilities *thiz = (IVideoDecoderCapabilities *) self; - thiz->mItf = &IVideoDecoderCapabilities_Itf; -} - - -bool IVideoDecoderCapabilities_expose(void *self) -{ -#ifdef ANDROID - // This is an Engine object interface, so we allocate the associated resources every time - // the interface is exposed on the Engine object and free them when the object is about - // to be destroyed (see IVideoDecoderCapabilities_deinit), not just once during the - // lifetime of the process. - return android::android_videoCodec_expose(); -#else - return false; -#endif -} - - -void IVideoDecoderCapabilities_deinit(void *self) -{ - SL_LOGV("IVideoDecoderCapabilities_deinit()"); -#ifdef ANDROID - android::android_videoCodec_deinit(); -#endif -} diff --git a/wilhelm/src/itf/IVirtualizer.c b/wilhelm/src/itf/IVirtualizer.c deleted file mode 100644 index c640811a..00000000 --- a/wilhelm/src/itf/IVirtualizer.c +++ /dev/null @@ -1,219 +0,0 @@ -/* - * 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. - */ - -/* Virtualizer implementation */ - -#include "sles_allinclusive.h" -#ifdef ANDROID -#include <audio_effects/effect_virtualizer.h> -#endif - -#define VIRTUALIZER_STRENGTH_MIN 0 -#define VIRTUALIZER_STRENGTH_MAX 1000 - - -#if defined(ANDROID) -/** - * returns true if this interface is not associated with an initialized Virtualizer effect - */ -static inline bool NO_VIRTUALIZER(IVirtualizer* v) { - return (v->mVirtualizerEffect == 0); -} -#endif - - -static SLresult IVirtualizer_SetEnabled(SLVirtualizerItf self, SLboolean enabled) -{ - SL_ENTER_INTERFACE - - IVirtualizer *thiz = (IVirtualizer *) self; - interface_lock_exclusive(thiz); - thiz->mEnabled = (SLboolean) enabled; -#if !defined(ANDROID) - result = SL_RESULT_SUCCESS; -#else - if (NO_VIRTUALIZER(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = - thiz->mVirtualizerEffect->setEnabled((bool) thiz->mEnabled); - result = android_fx_statusToResult(status); - } -#endif - interface_unlock_exclusive(thiz); - - SL_LEAVE_INTERFACE - -} - - -static SLresult IVirtualizer_IsEnabled(SLVirtualizerItf self, SLboolean *pEnabled) -{ - SL_ENTER_INTERFACE - - if (NULL == pEnabled) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IVirtualizer *thiz = (IVirtualizer *) self; - interface_lock_exclusive(thiz); - SLboolean enabled = thiz->mEnabled; -#if !defined(ANDROID) - *pEnabled = enabled; - result = SL_RESULT_SUCCESS; -#else - if (NO_VIRTUALIZER(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - *pEnabled = (SLboolean) thiz->mVirtualizerEffect->getEnabled(); - result = SL_RESULT_SUCCESS; - } -#endif - interface_unlock_exclusive(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IVirtualizer_SetStrength(SLVirtualizerItf self, SLpermille strength) -{ - SL_ENTER_INTERFACE - - if ((VIRTUALIZER_STRENGTH_MIN > strength) || (VIRTUALIZER_STRENGTH_MAX < strength)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IVirtualizer *thiz = (IVirtualizer *) self; - interface_lock_exclusive(thiz); -#if !defined(ANDROID) - thiz->mStrength = strength; - result = SL_RESULT_SUCCESS; -#else - if (NO_VIRTUALIZER(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = android_virt_setParam(thiz->mVirtualizerEffect, - VIRTUALIZER_PARAM_STRENGTH, &strength); - result = android_fx_statusToResult(status); - } -#endif - interface_unlock_exclusive(thiz); - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IVirtualizer_GetRoundedStrength(SLVirtualizerItf self, SLpermille *pStrength) -{ - SL_ENTER_INTERFACE - - if (NULL == pStrength) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IVirtualizer *thiz = (IVirtualizer *) self; - interface_lock_exclusive(thiz); - SLpermille strength = thiz->mStrength;; -#if !defined(ANDROID) - result = SL_RESULT_SUCCESS; -#else - if (NO_VIRTUALIZER(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = android_virt_getParam(thiz->mVirtualizerEffect, - VIRTUALIZER_PARAM_STRENGTH, &strength); - result = android_fx_statusToResult(status); - } -#endif - interface_unlock_exclusive(thiz); - *pStrength = strength; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IVirtualizer_IsStrengthSupported(SLVirtualizerItf self, SLboolean *pSupported) -{ - SL_ENTER_INTERFACE - - if (NULL == pSupported) { - result = SL_RESULT_PARAMETER_INVALID; - } else { -#if !defined(ANDROID) - *pSupported = SL_BOOLEAN_TRUE; - result = SL_RESULT_SUCCESS; -#else - IVirtualizer *thiz = (IVirtualizer *) self; - int32_t supported = 0; - interface_lock_exclusive(thiz); - if (NO_VIRTUALIZER(thiz)) { - result = SL_RESULT_CONTROL_LOST; - } else { - android::status_t status = - android_virt_getParam(thiz->mVirtualizerEffect, - VIRTUALIZER_PARAM_STRENGTH_SUPPORTED, &supported); - result = android_fx_statusToResult(status); - } - interface_unlock_exclusive(thiz); - *pSupported = (SLboolean) (supported != 0); -#endif - } - - SL_LEAVE_INTERFACE -} - - -static const struct SLVirtualizerItf_ IVirtualizer_Itf = { - IVirtualizer_SetEnabled, - IVirtualizer_IsEnabled, - IVirtualizer_SetStrength, - IVirtualizer_GetRoundedStrength, - IVirtualizer_IsStrengthSupported -}; - -void IVirtualizer_init(void *self) -{ - IVirtualizer *thiz = (IVirtualizer *) self; - thiz->mItf = &IVirtualizer_Itf; - thiz->mEnabled = SL_BOOLEAN_FALSE; - thiz->mStrength = 0; -#if defined(ANDROID) - memset(&thiz->mVirtualizerDescriptor, 0, sizeof(effect_descriptor_t)); - // placement new (explicit constructor) - (void) new (&thiz->mVirtualizerEffect) android::sp<android::AudioEffect>(); -#endif -} - -void IVirtualizer_deinit(void *self) -{ -#if defined(ANDROID) - IVirtualizer *thiz = (IVirtualizer *) self; - // explicit destructor - thiz->mVirtualizerEffect.~sp(); -#endif -} - -bool IVirtualizer_Expose(void *self) -{ -#if defined(ANDROID) - IVirtualizer *thiz = (IVirtualizer *) self; - if (!android_fx_initEffectDescriptor(SL_IID_VIRTUALIZER, &thiz->mVirtualizerDescriptor)) { - SL_LOGE("Virtualizer initialization failed."); - return false; - } -#endif - return true; -} diff --git a/wilhelm/src/itf/IVisualization.c b/wilhelm/src/itf/IVisualization.c deleted file mode 100644 index 6991d809..00000000 --- a/wilhelm/src/itf/IVisualization.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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. - */ - -/* Visualization implementation */ - -#include "sles_allinclusive.h" - - -static SLresult IVisualization_RegisterVisualizationCallback(SLVisualizationItf self, - slVisualizationCallback callback, void *pContext, SLmilliHertz rate) -{ - SL_ENTER_INTERFACE - - if (!(0 < rate && rate <= 20000)) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IVisualization *thiz = (IVisualization *) self; - interface_lock_exclusive(thiz); - thiz->mCallback = callback; - thiz->mContext = pContext; - thiz->mRate = rate; - interface_unlock_exclusive(thiz); - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IVisualization_GetMaxRate(SLVisualizationItf self, SLmilliHertz *pRate) -{ - SL_ENTER_INTERFACE - - if (NULL == pRate) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - *pRate = 20000; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static const struct SLVisualizationItf_ IVisualization_Itf = { - IVisualization_RegisterVisualizationCallback, - IVisualization_GetMaxRate -}; - -void IVisualization_init(void *self) -{ - IVisualization *thiz = (IVisualization *) self; - thiz->mItf = &IVisualization_Itf; - thiz->mCallback = NULL; - thiz->mContext = NULL; - thiz->mRate = 20000; -} diff --git a/wilhelm/src/itf/IVolume.c b/wilhelm/src/itf/IVolume.c deleted file mode 100644 index aaef4a99..00000000 --- a/wilhelm/src/itf/IVolume.c +++ /dev/null @@ -1,219 +0,0 @@ -/* - * 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. - */ - -/* Volume implementation */ - -#include "sles_allinclusive.h" - - -static SLresult IVolume_SetVolumeLevel(SLVolumeItf self, SLmillibel level) -{ - SL_ENTER_INTERFACE - - if (!((SL_MILLIBEL_MIN <= level) && (level <= PLATFORM_MILLIBEL_MAX_VOLUME))) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IVolume *thiz = (IVolume *) self; - interface_lock_exclusive(thiz); - SLmillibel oldLevel = thiz->mLevel; - if (oldLevel != level) { - thiz->mLevel = level; - interface_unlock_exclusive_attributes(thiz, ATTR_GAIN); - } else { - interface_unlock_exclusive(thiz); - } - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IVolume_GetVolumeLevel(SLVolumeItf self, SLmillibel *pLevel) -{ - SL_ENTER_INTERFACE - - if (NULL == pLevel) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IVolume *thiz = (IVolume *) self; - interface_lock_shared(thiz); - SLmillibel level = thiz->mLevel; - interface_unlock_shared(thiz); - *pLevel = level; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IVolume_GetMaxVolumeLevel(SLVolumeItf self, SLmillibel *pMaxLevel) -{ - SL_ENTER_INTERFACE - - if (NULL == pMaxLevel) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - *pMaxLevel = PLATFORM_MILLIBEL_MAX_VOLUME; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IVolume_SetMute(SLVolumeItf self, SLboolean mute) -{ - SL_ENTER_INTERFACE - - IVolume *thiz = (IVolume *) self; - mute = SL_BOOLEAN_FALSE != mute; // normalize - interface_lock_exclusive(thiz); - SLboolean oldMute = thiz->mMute; - if (oldMute != mute) { - thiz->mMute = (SLuint8) mute; - interface_unlock_exclusive_attributes(thiz, ATTR_GAIN); - } else { - interface_unlock_exclusive(thiz); - } - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static SLresult IVolume_GetMute(SLVolumeItf self, SLboolean *pMute) -{ - SL_ENTER_INTERFACE - - if (NULL == pMute) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IVolume *thiz = (IVolume *) self; - interface_lock_shared(thiz); - SLboolean mute = thiz->mMute; - interface_unlock_shared(thiz); - *pMute = mute; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IVolume_EnableStereoPosition(SLVolumeItf self, SLboolean enable) -{ - SL_ENTER_INTERFACE - - IVolume *thiz = (IVolume *) self; - enable = SL_BOOLEAN_FALSE != enable; // normalize - interface_lock_exclusive(thiz); - SLboolean oldEnable = thiz->mEnableStereoPosition; - if (oldEnable != enable) { - thiz->mEnableStereoPosition = (SLuint8) enable; - interface_unlock_exclusive_attributes(thiz, ATTR_GAIN); - } else { - interface_unlock_exclusive(thiz); - } - result = SL_RESULT_SUCCESS; - - SL_LEAVE_INTERFACE -} - - -static SLresult IVolume_IsEnabledStereoPosition(SLVolumeItf self, SLboolean *pEnable) -{ - SL_ENTER_INTERFACE - - if (NULL == pEnable) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IVolume *thiz = (IVolume *) self; - interface_lock_shared(thiz); - SLboolean enable = thiz->mEnableStereoPosition; - interface_unlock_shared(thiz); - *pEnable = enable; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IVolume_SetStereoPosition(SLVolumeItf self, SLpermille stereoPosition) -{ - SL_ENTER_INTERFACE - - if (!((-1000 <= stereoPosition) && (1000 >= stereoPosition))) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IVolume *thiz = (IVolume *) self; - interface_lock_exclusive(thiz); - SLpermille oldStereoPosition = thiz->mStereoPosition; - if (oldStereoPosition != stereoPosition) { - thiz->mStereoPosition = stereoPosition; - interface_unlock_exclusive_attributes(thiz, ATTR_GAIN); - } else { - interface_unlock_exclusive(thiz); - } - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static SLresult IVolume_GetStereoPosition(SLVolumeItf self, SLpermille *pStereoPosition) -{ - SL_ENTER_INTERFACE - - if (NULL == pStereoPosition) { - result = SL_RESULT_PARAMETER_INVALID; - } else { - IVolume *thiz = (IVolume *) self; - interface_lock_shared(thiz); - SLpermille stereoPosition = thiz->mStereoPosition; - interface_unlock_shared(thiz); - *pStereoPosition = stereoPosition; - result = SL_RESULT_SUCCESS; - } - - SL_LEAVE_INTERFACE -} - - -static const struct SLVolumeItf_ IVolume_Itf = { - IVolume_SetVolumeLevel, - IVolume_GetVolumeLevel, - IVolume_GetMaxVolumeLevel, - IVolume_SetMute, - IVolume_GetMute, - IVolume_EnableStereoPosition, - IVolume_IsEnabledStereoPosition, - IVolume_SetStereoPosition, - IVolume_GetStereoPosition -}; - -void IVolume_init(void *self) -{ - IVolume *thiz = (IVolume *) self; - thiz->mItf = &IVolume_Itf; - thiz->mLevel = 0; - thiz->mMute = SL_BOOLEAN_FALSE; - thiz->mEnableStereoPosition = SL_BOOLEAN_FALSE; - thiz->mStereoPosition = 0; -} diff --git a/wilhelm/src/itfstruct.h b/wilhelm/src/itfstruct.h deleted file mode 100644 index 36d75652..00000000 --- a/wilhelm/src/itfstruct.h +++ /dev/null @@ -1,678 +0,0 @@ -/* - * 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. - */ - -#ifdef ANDROID -#include "media/AudioEffect.h" -#include "hardware/audio_effect.h" -#endif - -/* Interface structures */ - -typedef struct Object_interface { - const struct SLObjectItf_ *mItf; // const - // field mThis would be redundant within an IObject, so we substitute mEngine - CEngine *mEngine; // const - const ClassTable *mClass; // const - SLuint32 mInstanceID; // const for debugger and for RPC, 0 means unpublished - slObjectCallback mCallback; - void *mContext; - unsigned mGottenMask; ///< bit-mask of interfaces exposed or added, then gotten - unsigned mLossOfControlMask; // interfaces with loss of control enabled - unsigned mAttributesMask; // attributes which have changed since last sync -#if USE_PROFILES & USE_PROFILES_BASE - SLint32 mPriority; -#endif - pthread_mutex_t mMutex; -#ifdef USE_DEBUG - // Only keep the pthread_t, not the kernel tid, because pthread_self() is very fast - // (typically just arithmetic on the stack pointer). But a gettid() is a kernel call - // and so too slow to do every time a mutex is acquired. However, we can determine - // the kernel tid from the pthread_t. - pthread_t mOwner; - const char *mFile; - int mLine; - volatile int32_t mGeneration; // read without a lock, incremented with a lock -#endif - pthread_cond_t mCond; - SLuint8 mState; // really SLuint32, but SLuint8 to save space -#if USE_PROFILES & USE_PROFILES_BASE - SLuint8 mPreemptable; // really SLboolean, but SLuint8 to save space -#else - SLuint8 mPadding; -#endif - SLuint8 mStrongRefCount; // number of strong references to this object - // (object cannot be destroyed as long as > 0, and referrers _prefer_ it stay in Realized state) - // for best alignment, do not add any fields here -#define INTERFACES_Default 1 - SLuint8 mInterfaceStates[INTERFACES_Default]; // state of each of interface - // do not add any fields here -} IObject; - -#include "locks.h" - -typedef struct { - const struct SL3DCommitItf_ *mItf; - IObject *mThis; - SLboolean mDeferred; - SLuint32 mGeneration; // incremented each master clock cycle - SLuint32 mWaiting; // number of threads waiting in Commit -} I3DCommit; - -enum CartesianSphericalActive { - CARTESIAN_COMPUTED_SPHERICAL_SET, - CARTESIAN_REQUESTED_SPHERICAL_SET, - CARTESIAN_UNKNOWN_SPHERICAL_SET, - CARTESIAN_SET_SPHERICAL_COMPUTED, // not in 1.0.1 - CARTESIAN_SET_SPHERICAL_REQUESTED, // not in 1.0.1 - CARTESIAN_SET_SPHERICAL_UNKNOWN -}; - -typedef struct { - const struct SL3DDopplerItf_ *mItf; - IObject *mThis; - // The API allows client to specify either Cartesian and spherical velocities. - // But an implementation will likely prefer one or the other. So for - // maximum portablity, we maintain both units and an indication of which - // unit was set most recently. In addition, we keep a flag saying whether - // the other unit has been derived yet. It can take significant time - // to compute the other unit, so this may be deferred to another thread. - // For this reason we also keep an indication of whether the secondary - // has been computed yet, and its accuracy. - // Though only one unit is primary at a time, a union is inappropriate: - // the application might read in both units (not in 1.0.1), - // and due to multi-threading concerns. - SLVec3D mVelocityCartesian; - struct { - SLmillidegree mAzimuth; - SLmillidegree mElevation; - SLmillidegree mSpeed; - } mVelocitySpherical; - enum CartesianSphericalActive mVelocityActive; - SLpermille mDopplerFactor; -} I3DDoppler; - -typedef struct { - const struct SL3DGroupingItf_ *mItf; - IObject *mThis; - C3DGroup *mGroup; // strong reference to associated group or NULL -} I3DGrouping; - -enum AnglesVectorsActive { - ANGLES_COMPUTED_VECTORS_SET, // not in 1.0.1 - ANGLES_REQUESTED_VECTORS_SET, // not in 1.0.1 - ANGLES_UNKNOWN_VECTORS_SET, - ANGLES_SET_VECTORS_COMPUTED, - ANGLES_SET_VECTORS_REQUESTED, - ANGLES_SET_VECTORS_UNKNOWN -}; - -typedef struct { - const struct SL3DLocationItf_ *mItf; - IObject *mThis; - SLVec3D mLocationCartesian; - struct { - SLmillidegree mAzimuth; - SLmillidegree mElevation; - SLmillimeter mDistance; - } mLocationSpherical; - enum CartesianSphericalActive mLocationActive; - struct { - SLmillidegree mHeading; - SLmillidegree mPitch; - SLmillidegree mRoll; - } mOrientationAngles; - struct { - SLVec3D mFront; - SLVec3D mAbove; - SLVec3D mUp; - } mOrientationVectors; - enum AnglesVectorsActive mOrientationActive; - // Rotations can be slow, so are deferred. - SLmillidegree mTheta; - SLVec3D mAxis; - SLboolean mRotatePending; -} I3DLocation; - -typedef struct { - const struct SL3DMacroscopicItf_ *mItf; - IObject *mThis; - struct { - SLmillimeter mWidth; - SLmillimeter mHeight; - SLmillimeter mDepth; - } mSize; - struct { - SLmillimeter mHeading; - SLmillimeter mPitch; - SLmillimeter mRoll; - } mOrientationAngles; - struct { - SLVec3D mFront; - SLVec3D mAbove; - SLVec3D mUp; - } mOrientationVectors; - enum AnglesVectorsActive mOrientationActive; - // Rotations can be slow, so are deferred. - SLmillidegree mTheta; - SLVec3D mAxis; - SLboolean mRotatePending; -} I3DMacroscopic; - -typedef struct { - const struct SL3DSourceItf_ *mItf; - IObject *mThis; - SLboolean mHeadRelative; - SLboolean mRolloffMaxDistanceMute; - SLmillimeter mMaxDistance; - SLmillimeter mMinDistance; - SLmillidegree mConeInnerAngle; - SLmillidegree mConeOuterAngle; - SLmillibel mConeOuterLevel; - SLpermille mRolloffFactor; - SLpermille mRoomRolloffFactor; - SLuint8 mDistanceModel; -} I3DSource; - -typedef struct { - const struct SLAudioDecoderCapabilitiesItf_ *mItf; - IObject *mThis; -} IAudioDecoderCapabilities; - -typedef struct { - const struct SLAudioEncoderItf_ *mItf; - IObject *mThis; - SLAudioEncoderSettings mSettings; -} IAudioEncoder; - -typedef struct { - const struct SLAudioEncoderCapabilitiesItf_ *mItf; - IObject *mThis; -} IAudioEncoderCapabilities; - -typedef struct { - const struct SLAudioIODeviceCapabilitiesItf_ *mItf; - IObject *mThis; - slAvailableAudioInputsChangedCallback mAvailableAudioInputsChangedCallback; - void *mAvailableAudioInputsChangedContext; - slAvailableAudioOutputsChangedCallback mAvailableAudioOutputsChangedCallback; - void *mAvailableAudioOutputsChangedContext; - slDefaultDeviceIDMapChangedCallback mDefaultDeviceIDMapChangedCallback; - void *mDefaultDeviceIDMapChangedContext; -} IAudioIODeviceCapabilities; - -typedef struct { - const struct SLBassBoostItf_ *mItf; - IObject *mThis; - SLboolean mEnabled; - SLpermille mStrength; -#if defined(ANDROID) - effect_descriptor_t mBassBoostDescriptor; - android::sp<android::AudioEffect> mBassBoostEffect; -#endif -} IBassBoost; - -typedef struct BufferQueue_interface { - const struct SLBufferQueueItf_ *mItf; - IObject *mThis; - SLBufferQueueState mState; - slBufferQueueCallback mCallback; - void *mContext; - // originally SLuint32, but range-checked down to SLuint16 - SLuint16 mNumBuffers; - /*SLboolean*/ SLuint16 mClearRequested; - BufferHeader *mArray; - BufferHeader *mFront, *mRear; -#ifdef ANDROID - SLuint32 mSizeConsumed; -#endif - // saves a malloc in the typical case -#define BUFFER_HEADER_TYPICAL 4 - BufferHeader mTypical[BUFFER_HEADER_TYPICAL+1]; -} IBufferQueue; - -#define MAX_DEVICE 2 // hard-coded array size for default in/out - -typedef struct { - const struct SLDeviceVolumeItf_ *mItf; - IObject *mThis; - SLint32 mVolume[MAX_DEVICE]; -} IDeviceVolume; - -typedef struct { - const struct SLDynamicInterfaceManagementItf_ *mItf; - IObject *mThis; - slDynamicInterfaceManagementCallback mCallback; - void *mContext; -} IDynamicInterfaceManagement; - -typedef struct { - const struct SLDynamicSourceItf_ *mItf; - IObject *mThis; - SLDataSource *mDataSource; -} IDynamicSource; - -// private - -struct EnableLevel { - SLboolean mEnable; - SLmillibel mSendLevel; -}; - -// indexes into IEffectSend.mEnableLevels - -#define AUX_ENVIRONMENTALREVERB 0 -#define AUX_PRESETREVERB 1 -#define AUX_MAX 2 - -typedef struct { - const struct SLEffectSendItf_ *mItf; - IObject *mThis; - struct EnableLevel mEnableLevels[AUX_MAX]; // wet enable and volume per effect type -} IEffectSend; - -typedef struct Engine_interface { - const struct SLEngineItf_ *mItf; - IObject *mThis; - SLboolean mLossOfControlGlobal; -#ifdef USE_SDL - COutputMix *mOutputMix; // SDL pulls PCM from an arbitrary IOutputMixExt -#endif - // Each engine is its own universe. - SLuint32 mInstanceCount; - unsigned mInstanceMask; // 1 bit per active object - unsigned mChangedMask; // objects which have changed since last sync -#define MAX_INSTANCE 32 // maximum active objects per engine, see mInstanceMask - IObject *mInstances[MAX_INSTANCE]; - SLboolean mShutdown; - SLboolean mShutdownAck; - // SLuint32 mVersion; // 0xXXYYZZ where XX=major, YY=minor, ZZ=step -} IEngine; - -typedef struct { - const struct SLEngineCapabilitiesItf_ *mItf; - IObject *mThis; - SLboolean mThreadSafe; - // const - SLuint32 mMaxIndexLED; - SLuint32 mMaxIndexVibra; -} IEngineCapabilities; - -typedef struct { - const struct SLEnvironmentalReverbItf_ *mItf; - IObject *mThis; - SLEnvironmentalReverbSettings mProperties; -#if defined(ANDROID) - effect_descriptor_t mEnvironmentalReverbDescriptor; - android::sp<android::AudioEffect> mEnvironmentalReverbEffect; -#endif -} IEnvironmentalReverb; - -struct EqualizerBand { - SLmilliHertz mMin; - SLmilliHertz mCenter; - SLmilliHertz mMax; -}; - -#if defined(ANDROID) -#define MAX_EQ_BANDS 0 -#else -#define MAX_EQ_BANDS 4 // compile-time limit, runtime limit may be smaller -#endif - -typedef struct { - const struct SLEqualizerItf_ *mItf; - IObject *mThis; - SLboolean mEnabled; - SLuint16 mPreset; -#if 0 < MAX_EQ_BANDS - SLmillibel mLevels[MAX_EQ_BANDS]; -#endif - // const to end of struct - SLuint16 mNumPresets; - SLuint16 mNumBands; -#if !defined(ANDROID) - const struct EqualizerBand *mBands; - const struct EqualizerPreset *mPresets; -#endif - SLmillibel mBandLevelRangeMin; - SLmillibel mBandLevelRangeMax; -#if defined(ANDROID) - effect_descriptor_t mEqDescriptor; - android::sp<android::AudioEffect> mEqEffect; -#endif -} IEqualizer; - -#define MAX_LED_COUNT 32 - -typedef struct { - const struct SLLEDArrayItf_ *mItf; - IObject *mThis; - SLuint32 mLightMask; - SLHSL mColors[MAX_LED_COUNT]; - // const - SLuint8 mCount; -} ILEDArray; - -typedef struct { - const struct SLMetadataExtractionItf_ *mItf; - IObject *mThis; - SLuint32 mKeySize; - const void *mKey; - SLuint32 mKeyEncoding; - const SLchar *mValueLangCountry; - SLuint32 mValueEncoding; - SLuint8 mFilterMask; - int mKeyFilter; -} IMetadataExtraction; - -typedef struct { - const struct SLMetadataTraversalItf_ *mItf; - IObject *mThis; - SLuint32 mIndex; - SLuint32 mMode; - SLuint32 mCount; - SLuint32 mSize; -} IMetadataTraversal; - -typedef struct { - const struct SLMIDIMessageItf_ *mItf; - IObject *mThis; - slMetaEventCallback mMetaEventCallback; - void *mMetaEventContext; - slMIDIMessageCallback mMessageCallback; - void *mMessageContext; - SLuint8 mMessageTypes; -} IMIDIMessage; - -typedef struct { - const struct SLMIDIMuteSoloItf_ *mItf; - IObject *mThis; - SLuint16 mChannelMuteMask; - SLuint16 mChannelSoloMask; - SLuint32 mTrackMuteMask; - SLuint32 mTrackSoloMask; - // const - SLuint16 mTrackCount; -} IMIDIMuteSolo; - -typedef struct { - const struct SLMIDITempoItf_ *mItf; - IObject *mThis; - SLuint32 mTicksPerQuarterNote; - SLuint32 mMicrosecondsPerQuarterNote; -} IMIDITempo; - -typedef struct { - const struct SLMIDITimeItf_ *mItf; - IObject *mThis; - SLuint32 mDuration; - SLuint32 mPosition; - SLuint32 mStartTick; - SLuint32 mNumTicks; -} IMIDITime; - -typedef struct { - const struct SLMuteSoloItf_ *mItf; - IObject *mThis; - // fields that were formerly here are now at CAudioPlayer -} IMuteSolo; - -#define MAX_TRACK 32 // see mActiveMask - -typedef struct { - const struct SLOutputMixItf_ *mItf; - IObject *mThis; - slMixDeviceChangeCallback mCallback; - void *mContext; -} IOutputMix; - -#ifdef USE_OUTPUTMIXEXT -typedef struct { - const struct SLOutputMixExtItf_ *mItf; - IObject *mThis; - unsigned mActiveMask; // 1 bit per active track - Track mTracks[MAX_TRACK]; - SLboolean mDestroyRequested; ///< Mixer to acknowledge application's call to Object::Destroy -} IOutputMixExt; -#endif - -typedef struct { - const struct SLPitchItf_ *mItf; - IObject *mThis; - SLpermille mPitch; - // const - SLpermille mMinPitch; - SLpermille mMaxPitch; -} IPitch; - -typedef struct Play_interface { - const struct SLPlayItf_ *mItf; - IObject *mThis; - SLuint32 mState; - // next 2 fields are read-only to application - SLmillisecond mDuration; - SLmillisecond mPosition; - slPlayCallback mCallback; - void *mContext; - SLuint32 mEventFlags; - // the ISeek trick of using a distinct value doesn't work here because it's readable by app - SLmillisecond mMarkerPosition; - SLmillisecond mPositionUpdatePeriod; // Zero means do not do position updates (FIXME ~0) -#ifdef USE_OUTPUTMIXEXT - SLuint32 mFrameUpdatePeriod; // mPositionUpdatePeriod in frame units - SLmillisecond mLastSeekPosition; // Last known accurate position, set at Seek - SLuint32 mFramesSinceLastSeek; // Frames mixed since last known accurate position - SLuint32 mFramesSincePositionUpdate; // Frames mixed since last position update callback -#endif -} IPlay; - -typedef struct { - const struct SLPlaybackRateItf_ *mItf; - IObject *mThis; - SLpermille mRate; - SLuint32 mProperties; - // const after initialization - SLpermille mMinRate; - SLpermille mMaxRate; - SLpermille mStepSize; - SLuint32 mCapabilities; -} IPlaybackRate; - -typedef struct { - const struct SLPrefetchStatusItf_ *mItf; - IObject *mThis; - SLuint32 mStatus; - SLpermille mLevel; - slPrefetchCallback mCallback; - void *mContext; - SLuint32 mCallbackEventsMask; - SLpermille mFillUpdatePeriod; -#ifdef ANDROID - /** FIXME used to call PrefetchStatus callback with object unlocked prior to return from API */ - slPrefetchCallback mDeferredPrefetchCallback; - void *mDeferredPrefetchContext; - SLuint32 mDeferredPrefetchEvents; -#endif -} IPrefetchStatus; - -typedef struct { - const struct SLPresetReverbItf_ *mItf; - IObject *mThis; - SLuint16 mPreset; -#if defined(ANDROID) - effect_descriptor_t mPresetReverbDescriptor; - android::sp<android::AudioEffect> mPresetReverbEffect; -#endif -} IPresetReverb; - -typedef struct { - const struct SLRatePitchItf_ *mItf; - IObject *mThis; - SLpermille mRate; - // const - SLpermille mMinRate; - SLpermille mMaxRate; -} IRatePitch; - -typedef struct { - const struct SLRecordItf_ *mItf; - IObject *mThis; - SLuint32 mState; - SLmillisecond mDurationLimit; - SLmillisecond mPosition; - slRecordCallback mCallback; - void *mContext; - SLuint32 mCallbackEventsMask; - SLmillisecond mMarkerPosition; - SLmillisecond mPositionUpdatePeriod; -} IRecord; - -typedef struct { - const struct SLSeekItf_ *mItf; - IObject *mThis; - SLmillisecond mPos; // mPos != SL_TIME_UNKNOWN means pending seek request - SLboolean mLoopEnabled; - SLmillisecond mStartPos; - SLmillisecond mEndPos; -} ISeek; - -typedef struct { - const struct SLThreadSyncItf_ *mItf; - IObject *mThis; - SLboolean mInCriticalSection; - SLuint32 mWaiting; // number of threads waiting - pthread_t mOwner; -} IThreadSync; - -typedef struct { - const struct SLVibraItf_ *mItf; - IObject *mThis; - SLboolean mVibrate; - SLmilliHertz mFrequency; - SLpermille mIntensity; -} IVibra; - -typedef struct { - const struct SLVirtualizerItf_ *mItf; - IObject *mThis; - SLboolean mEnabled; - SLpermille mStrength; -#if defined(ANDROID) - effect_descriptor_t mVirtualizerDescriptor; - android::sp<android::AudioEffect> mVirtualizerEffect; -#endif -} IVirtualizer; - -typedef struct { - const struct SLVisualizationItf_ *mItf; - IObject *mThis; - slVisualizationCallback mCallback; - void *mContext; - SLmilliHertz mRate; -} IVisualization; - -typedef struct /*Volume_interface*/ { - const struct SLVolumeItf_ *mItf; - IObject *mThis; - // Values as specified by the application - SLmillibel mLevel; - SLpermille mStereoPosition; - SLuint8 /*SLboolean*/ mMute; - SLuint8 /*SLboolean*/ mEnableStereoPosition; -} IVolume; - -typedef struct { - const struct XAEngineItf_ *mItf; - IObject *mThis; -} IXAEngine; - -#define NB_SUPPORTED_STREAMS 1 // only one (video) stream supported in this implementation -typedef struct { - const struct XAStreamInformationItf_ *mItf; - IObject *mThis; - xaStreamEventChangeCallback mCallback; - void *mContext; - XAboolean mActiveStreams[NB_SUPPORTED_STREAMS]; -#ifdef ANDROID - android::Vector<StreamInfo> mStreamInfoTable; -#endif -} IStreamInformation; - -typedef struct { - const struct XAVideoDecoderCapabilitiesItf_ *mItf; - IObject *mThis; -} IVideoDecoderCapabilities; - -/* Class structures */ - -/*typedef*/ struct C3DGroup_struct { - IObject mObject; -#define INTERFACES_3DGroup 6 // see MPH_to_3DGroup in MPH_to.c for list of interfaces - SLuint8 mInterfaceStates2[INTERFACES_3DGroup - INTERFACES_Default]; - IDynamicInterfaceManagement mDynamicInterfaceManagement; - I3DLocation m3DLocation; - I3DDoppler m3DDoppler; - I3DSource m3DSource; - I3DMacroscopic m3DMacroscopic; - // remaining are per-instance private fields not associated with an interface - unsigned mMemberMask; // set of member objects -} /*C3DGroup*/; - -#ifdef ANDROID - -// FIXME Move these into the I... section above - -typedef struct { - const struct SLAndroidEffectItf_ *mItf; - IObject *mThis; - android::KeyedVector<SLuint32, android::AudioEffect* > *mEffects; -} IAndroidEffect; - -typedef struct { - const struct SLAndroidEffectCapabilitiesItf_ *mItf; - IObject *mThis; - SLuint32 mNumFx; - effect_descriptor_t* mFxDescriptors; -} IAndroidEffectCapabilities; - -typedef struct { - const struct SLAndroidEffectSendItf_ *mItf; - IObject *mThis; - // only one send per interface for now (1 bus) - SLboolean mEnabled; - SLmillibel mSendLevel; //android::KeyedVector<SLuint32, SLmillibel> mSendLevels; -} IAndroidEffectSend; - -typedef struct { - const struct SLAndroidConfigurationItf_ *mItf; - IObject *mThis; -} IAndroidConfiguration; - -typedef struct { - const struct SLAndroidBufferQueueItf_ *mItf; - IObject *mThis; - SLAndroidBufferQueueState mState; - slAndroidBufferQueueCallback mCallback; - SLuint32 mCallbackEventsMask; - void *mContext; - SLuint16 mNumBuffers; - AndroidBufferType_type mBufferType; - AdvancedBufferHeader *mBufferArray; - AdvancedBufferHeader *mFront, *mRear; - bool mEOS; // whether EOS has been enqueued; never reset -} IAndroidBufferQueue; - -#endif diff --git a/wilhelm/src/locks.c b/wilhelm/src/locks.c deleted file mode 100644 index d95c23a2..00000000 --- a/wilhelm/src/locks.c +++ /dev/null @@ -1,322 +0,0 @@ -/* - * 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. - */ - -#include "sles_allinclusive.h" -#include <bionic_pthread.h> - - -// Use this macro to validate a pthread_t before passing it into __pthread_gettid. -// One of the common reasons for deadlock is trying to lock a mutex for an object -// which has been destroyed (which does memset to 0x00 or 0x55 as the final step). -// To avoid crashing with a SIGSEGV right before we're about to log a deadlock warning, -// we check that the pthread_t is probably valid. Note that it is theoretically -// possible for something to look like a valid pthread_t but not actually be valid. -// So we might still crash, but only in the case where a deadlock was imminent anyway. -#define LIKELY_VALID(ptr) (((ptr) != (pthread_t) 0) && ((((size_t) (ptr)) & 3) == 0)) - - -/** \brief Exclusively lock an object */ - -#ifdef USE_DEBUG -void object_lock_exclusive_(IObject *thiz, const char *file, int line) -{ - int ok; - ok = pthread_mutex_trylock(&thiz->mMutex); - if (0 != ok) { - // not android_atomic_acquire_load because we don't care about relative load/load ordering - int32_t oldGeneration = thiz->mGeneration; - // wait up to a total of 250 ms - static const unsigned backoffs[] = {10, 20, 30, 40, 50, 100}; - unsigned i = 0; - for (;;) { - // the Android version is in ms not timespec, and isn't named pthread_mutex_timedlock_np - ok = pthread_mutex_lock_timeout_np(&thiz->mMutex, backoffs[i]); - if (0 == ok) { - break; - } - if (EBUSY == ok) { - // this is the expected return value for timeout, and will be handled below - } else if (EDEADLK == ok) { - // we don't use the kind of mutex that can return this error, but just in case - SL_LOGE("%s:%d: recursive lock detected", file, line); - } else { - // some other return value - SL_LOGE("%s:%d: pthread_mutex_lock_timeout_np returned %d", file, line, ok); - } - // is anyone else making forward progress? - int32_t newGeneration = thiz->mGeneration; - if (newGeneration != oldGeneration) { - // if we ever see forward progress then lock without timeout (more efficient) - goto forward_progress; - } - // no, then continue trying to lock but with increasing timeouts - if (++i >= (sizeof(backoffs) / sizeof(backoffs[0]))) { - // the extra block avoids a C++ compiler error about goto past initialization - { - pthread_t me = pthread_self(); - pthread_t owner = thiz->mOwner; - // unlikely, but this could result in a memory fault if owner is corrupt - pid_t ownerTid = LIKELY_VALID(owner) ? __pthread_gettid(owner) : -1; - SL_LOGW("%s:%d: pthread %p (tid %d) sees object %p was locked by pthread %p" - " (tid %d) at %s:%d\n", file, line, *(void **)&me, gettid(), thiz, - *(void **)&owner, ownerTid, thiz->mFile, thiz->mLine); - } -forward_progress: - // attempt one more time without timeout; maybe this time we will be successful - ok = pthread_mutex_lock(&thiz->mMutex); - assert(0 == ok); - break; - } - } - } - // here if mutex was successfully locked - pthread_t zero; - memset(&zero, 0, sizeof(pthread_t)); - if (0 != memcmp(&zero, &thiz->mOwner, sizeof(pthread_t))) { - pthread_t me = pthread_self(); - pthread_t owner = thiz->mOwner; - pid_t ownerTid = LIKELY_VALID(owner) ? __pthread_gettid(owner) : -1; - if (pthread_equal(pthread_self(), owner)) { - SL_LOGE("%s:%d: pthread %p (tid %d) sees object %p was recursively locked by pthread" - " %p (tid %d) at %s:%d\n", file, line, *(void **)&me, gettid(), thiz, - *(void **)&owner, ownerTid, thiz->mFile, thiz->mLine); - } else { - SL_LOGE("%s:%d: pthread %p (tid %d) sees object %p was left unlocked in unexpected" - " state by pthread %p (tid %d) at %s:%d\n", file, line, *(void **)&me, gettid(), - thiz, *(void **)&owner, ownerTid, thiz->mFile, thiz->mLine); - } - assert(false); - } - thiz->mOwner = pthread_self(); - thiz->mFile = file; - thiz->mLine = line; - // not android_atomic_inc because we are already holding a mutex - ++thiz->mGeneration; -} -#else -void object_lock_exclusive(IObject *thiz) -{ - int ok; - ok = pthread_mutex_lock(&thiz->mMutex); - assert(0 == ok); -} -#endif - - -/** \brief Exclusively unlock an object and do not report any updates */ - -#ifdef USE_DEBUG -void object_unlock_exclusive_(IObject *thiz, const char *file, int line) -{ - assert(pthread_equal(pthread_self(), thiz->mOwner)); - assert(NULL != thiz->mFile); - assert(0 != thiz->mLine); - memset(&thiz->mOwner, 0, sizeof(pthread_t)); - thiz->mFile = file; - thiz->mLine = line; - int ok; - ok = pthread_mutex_unlock(&thiz->mMutex); - assert(0 == ok); -} -#else -void object_unlock_exclusive(IObject *thiz) -{ - int ok; - ok = pthread_mutex_unlock(&thiz->mMutex); - assert(0 == ok); -} -#endif - - -/** \brief Exclusively unlock an object and report updates to the specified bit-mask of - * attributes - */ - -#ifdef USE_DEBUG -void object_unlock_exclusive_attributes_(IObject *thiz, unsigned attributes, - const char *file, int line) -#else -void object_unlock_exclusive_attributes(IObject *thiz, unsigned attributes) -#endif -{ - -#ifdef USE_DEBUG - assert(pthread_equal(pthread_self(), thiz->mOwner)); - assert(NULL != thiz->mFile); - assert(0 != thiz->mLine); -#endif - - int ok; - - // make SL object IDs be contiguous with XA object IDs - SLuint32 objectID = IObjectToObjectID(thiz); - SLuint32 index = objectID; - if ((XA_OBJECTID_ENGINE <= index) && (index <= XA_OBJECTID_CAMERADEVICE)) { - ; - } else if ((SL_OBJECTID_ENGINE <= index) && (index <= SL_OBJECTID_METADATAEXTRACTOR)) { - index -= SL_OBJECTID_ENGINE - XA_OBJECTID_CAMERADEVICE - 1; - } else { - assert(false); - index = 0; - } - - // first synchronously handle updates to attributes here, while object is still locked. - // This appears to be a loop, but actually typically runs through the loop only once. - unsigned asynchronous = attributes; - while (attributes) { - // this sequence is carefully crafted to be O(1); tread carefully when making changes - unsigned bit = ctz(attributes); - // ATTR_INDEX_MAX == next bit position after the last attribute - assert(ATTR_INDEX_MAX > bit); - // compute the entry in the handler table using object ID and bit number - AttributeHandler handler = handlerTable[index][bit]; - if (NULL != handler) { - asynchronous &= ~(*handler)(thiz); - } - attributes &= ~(1 << bit); - } - - // any remaining attributes are handled asynchronously in the sync thread - if (asynchronous) { - unsigned oldAttributesMask = thiz->mAttributesMask; - thiz->mAttributesMask = oldAttributesMask | asynchronous; - if (oldAttributesMask) { - asynchronous = ATTR_NONE; - } - } - -#ifdef ANDROID - // FIXME hack to safely handle a post-unlock PrefetchStatus callback and/or AudioTrack::start() - slPrefetchCallback prefetchCallback = NULL; - void *prefetchContext = NULL; - SLuint32 prefetchEvents = SL_PREFETCHEVENT_NONE; - android::sp<android::AudioTrack> audioTrack; - if (SL_OBJECTID_AUDIOPLAYER == objectID) { - CAudioPlayer *ap = (CAudioPlayer *) thiz; - prefetchCallback = ap->mPrefetchStatus.mDeferredPrefetchCallback; - prefetchContext = ap->mPrefetchStatus.mDeferredPrefetchContext; - prefetchEvents = ap->mPrefetchStatus.mDeferredPrefetchEvents; - ap->mPrefetchStatus.mDeferredPrefetchCallback = NULL; - // clearing these next two fields is not required, but avoids stale data during debugging - ap->mPrefetchStatus.mDeferredPrefetchContext = NULL; - ap->mPrefetchStatus.mDeferredPrefetchEvents = SL_PREFETCHEVENT_NONE; - if (ap->mDeferredStart) { - audioTrack = ap->mAudioTrack; - ap->mDeferredStart = false; - } - } -#endif - -#ifdef USE_DEBUG - memset(&thiz->mOwner, 0, sizeof(pthread_t)); - thiz->mFile = file; - thiz->mLine = line; -#endif - ok = pthread_mutex_unlock(&thiz->mMutex); - assert(0 == ok); - -#ifdef ANDROID - // FIXME call the prefetch status callback while not holding the mutex on AudioPlayer - if (NULL != prefetchCallback) { - // note these are synchronous by the application's thread as it is about to return from API - assert(prefetchEvents != SL_PREFETCHEVENT_NONE); - CAudioPlayer *ap = (CAudioPlayer *) thiz; - // spec requires separate callbacks for each event - if (SL_PREFETCHEVENT_STATUSCHANGE & prefetchEvents) { - (*prefetchCallback)(&ap->mPrefetchStatus.mItf, prefetchContext, - SL_PREFETCHEVENT_STATUSCHANGE); - } - if (SL_PREFETCHEVENT_FILLLEVELCHANGE & prefetchEvents) { - (*prefetchCallback)(&ap->mPrefetchStatus.mItf, prefetchContext, - SL_PREFETCHEVENT_FILLLEVELCHANGE); - } - } - - // call AudioTrack::start() while not holding the mutex on AudioPlayer - if (audioTrack != 0) { - audioTrack->start(); - audioTrack.clear(); - } -#endif - - // first update to this interface since previous sync - if (ATTR_NONE != asynchronous) { - unsigned id = thiz->mInstanceID; - if (0 != id) { - --id; - assert(MAX_INSTANCE > id); - IEngine *thisEngine = &thiz->mEngine->mEngine; - // FIXME atomic or here - interface_lock_exclusive(thisEngine); - thisEngine->mChangedMask |= 1 << id; - interface_unlock_exclusive(thisEngine); - } - } - -} - - -/** \brief Wait on the condition variable associated with the object; see pthread_cond_wait */ - -#ifdef USE_DEBUG -void object_cond_wait_(IObject *thiz, const char *file, int line) -{ - // note that this will unlock the mutex, so we have to clear the owner - assert(pthread_equal(pthread_self(), thiz->mOwner)); - assert(NULL != thiz->mFile); - assert(0 != thiz->mLine); - memset(&thiz->mOwner, 0, sizeof(pthread_t)); - thiz->mFile = file; - thiz->mLine = line; - // alas we don't know the new owner's identity - int ok; - ok = pthread_cond_wait(&thiz->mCond, &thiz->mMutex); - assert(0 == ok); - // restore my ownership - thiz->mOwner = pthread_self(); - thiz->mFile = file; - thiz->mLine = line; -} -#else -void object_cond_wait(IObject *thiz) -{ - int ok; - ok = pthread_cond_wait(&thiz->mCond, &thiz->mMutex); - assert(0 == ok); -} -#endif - - -/** \brief Signal the condition variable associated with the object; see pthread_cond_signal */ - -void object_cond_signal(IObject *thiz) -{ - int ok; - ok = pthread_cond_signal(&thiz->mCond); - assert(0 == ok); -} - - -/** \brief Broadcast the condition variable associated with the object; - * see pthread_cond_broadcast - */ - -void object_cond_broadcast(IObject *thiz) -{ - int ok; - ok = pthread_cond_broadcast(&thiz->mCond); - assert(0 == ok); -} diff --git a/wilhelm/src/locks.h b/wilhelm/src/locks.h deleted file mode 100644 index eed3dcc0..00000000 --- a/wilhelm/src/locks.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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. - */ - -/** \file locks.h Mutual exclusion and condition variables */ - -#ifdef USE_DEBUG -extern void object_lock_exclusive_(IObject *thiz, const char *file, int line); -extern void object_unlock_exclusive_(IObject *thiz, const char *file, int line); -extern void object_unlock_exclusive_attributes_(IObject *thiz, unsigned attr, - const char *file, int line); -extern void object_cond_wait_(IObject *thiz, const char *file, int line); -#else -extern void object_lock_exclusive(IObject *thiz); -extern void object_unlock_exclusive(IObject *thiz); -extern void object_unlock_exclusive_attributes(IObject *thiz, unsigned attr); -extern void object_cond_wait(IObject *thiz); -#endif -extern void object_cond_signal(IObject *thiz); -extern void object_cond_broadcast(IObject *thiz); - -#ifdef USE_DEBUG -#define object_lock_exclusive(thiz) object_lock_exclusive_((thiz), __FILE__, __LINE__) -#define object_unlock_exclusive(thiz) object_unlock_exclusive_((thiz), __FILE__, __LINE__) -#define object_unlock_exclusive_attributes(thiz, attr) \ - object_unlock_exclusive_attributes_((thiz), (attr), __FILE__, __LINE__) -#define object_cond_wait(thiz) object_cond_wait_((thiz), __FILE__, __LINE__) -#endif - -// Currently shared locks are implemented as exclusive, but don't count on it - -#define object_lock_shared(thiz) object_lock_exclusive(thiz) -#define object_unlock_shared(thiz) object_unlock_exclusive(thiz) - -// Currently interface locks are actually on whole object, but don't count on it. -// These operations are undefined on IObject, as it lacks an mThis. -// If you have an IObject, then use the object_ functions instead. - -#define interface_lock_exclusive(thiz) object_lock_exclusive(InterfaceToIObject(thiz)) -#define interface_unlock_exclusive(thiz) object_unlock_exclusive(InterfaceToIObject(thiz)) -#define interface_unlock_exclusive_attributes(thiz, attr) \ - object_unlock_exclusive_attributes(InterfaceToIObject(thiz), (attr)) -#define interface_lock_shared(thiz) object_lock_shared(InterfaceToIObject(thiz)) -#define interface_unlock_shared(thiz) object_unlock_shared(InterfaceToIObject(thiz)) -#define interface_cond_wait(thiz) object_cond_wait(InterfaceToIObject(thiz)) -#define interface_cond_signal(thiz) object_cond_signal(InterfaceToIObject(thiz)) -#define interface_cond_broadcast(thiz) object_cond_broadcast(InterfaceToIObject(thiz)) - -// Peek and poke are an optimization for small atomic fields that don't "matter". -// Don't use for struct, as struct copy might not be atomic. -// On uniprocessor they can be no-ops, on SMP they could be memory barriers but locks are easier. - -#define object_lock_peek(thiz) object_lock_shared(thiz) -#define object_unlock_peek(thiz) object_unlock_shared(thiz) -#define interface_lock_poke(thiz) interface_lock_exclusive(thiz) -#define interface_unlock_poke(thiz) interface_unlock_exclusive(thiz) -#define interface_lock_peek(thiz) interface_lock_shared(thiz) -#define interface_unlock_peek(thiz) interface_unlock_shared(thiz) diff --git a/wilhelm/src/objects/C3DGroup.c b/wilhelm/src/objects/C3DGroup.c deleted file mode 100644 index ad3afeea..00000000 --- a/wilhelm/src/objects/C3DGroup.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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. - */ - -/** \file C3DGroup.c C3DGroup class */ - -#include "sles_allinclusive.h" - - -/** \brief Hook called by Object::Destroy before a 3D group is about to be destroyed */ - -predestroy_t C3DGroup_PreDestroy(void *self) -{ - C3DGroup *thiz = (C3DGroup *) self; - // See design document for explanation - if (0 == thiz->mMemberMask) { - return predestroy_ok; - } - SL_LOGE("Object::Destroy(%p) for 3DGroup ignored; mMemberMask=0x%x", thiz, thiz->mMemberMask); - return predestroy_error; -} diff --git a/wilhelm/src/objects/CAudioPlayer.c b/wilhelm/src/objects/CAudioPlayer.c deleted file mode 100644 index dcad95a5..00000000 --- a/wilhelm/src/objects/CAudioPlayer.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * 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. - */ - -/** \file CAudioPlayer.c AudioPlayer class */ - -#include "sles_allinclusive.h" - - -/** \brief Hook called by Object::Realize when an audio player is realized */ - -SLresult CAudioPlayer_Realize(void *self, SLboolean async) -{ - CAudioPlayer *thiz = (CAudioPlayer *) self; - SLresult result = SL_RESULT_SUCCESS; - -#ifdef ANDROID - result = android_audioPlayer_realize(thiz, async); -#endif - -#ifdef USE_SNDFILE - result = SndFile_Realize(thiz); -#endif - - // At this point the channel count and sample rate might still be unknown, - // depending on the data source and the platform implementation. - // If they are unknown here, then they will be determined during prefetch. - - return result; -} - - -/** \brief Hook called by Object::Resume when an audio player is resumed */ - -SLresult CAudioPlayer_Resume(void *self, SLboolean async) -{ - return SL_RESULT_SUCCESS; -} - - -/** \brief Hook called by Object::Destroy when an audio player is destroyed */ - -void CAudioPlayer_Destroy(void *self) -{ - CAudioPlayer *thiz = (CAudioPlayer *) self; -#ifdef ANDROID - android_audioPlayer_destroy(thiz); -#endif - freeDataLocatorFormat(&thiz->mDataSource); - freeDataLocatorFormat(&thiz->mDataSink); -#ifdef USE_SNDFILE - SndFile_Destroy(thiz); -#endif -} - - -/** \brief Hook called by Object::Destroy before an audio player is about to be destroyed */ - -predestroy_t CAudioPlayer_PreDestroy(void *self) -{ - CAudioPlayer *thiz = (CAudioPlayer *) self; -#ifdef ANDROID - android_audioPlayer_preDestroy(thiz); -#endif - -#ifdef USE_OUTPUTMIXEXT - // Safe to proceed immediately if a track has not yet been assigned - Track *track = thiz->mTrack; - if (NULL == track) { - return predestroy_ok; - } - CAudioPlayer *audioPlayer = track->mAudioPlayer; - if (NULL == audioPlayer) { - return predestroy_ok; - } - assert(audioPlayer == thiz); - // Request the mixer thread to unlink this audio player's track - thiz->mDestroyRequested = true; - while (thiz->mDestroyRequested) { - object_cond_wait(self); - } - // Mixer thread has acknowledged the request -#endif - return predestroy_ok; -} - - -/** \brief Given an audio player, return its data sink, which is guaranteed to be a non-NULL output - * mix. This function is used by effect send. - */ - -COutputMix *CAudioPlayer_GetOutputMix(CAudioPlayer *audioPlayer) -{ - assert(NULL != audioPlayer); - assert(SL_DATALOCATOR_OUTPUTMIX == audioPlayer->mDataSink.mLocator.mLocatorType); - SLObjectItf outputMix = audioPlayer->mDataSink.mLocator.mOutputMix.outputMix; - assert(NULL != outputMix); - return (COutputMix *) outputMix; -} diff --git a/wilhelm/src/objects/CAudioRecorder.c b/wilhelm/src/objects/CAudioRecorder.c deleted file mode 100644 index 956e9872..00000000 --- a/wilhelm/src/objects/CAudioRecorder.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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. - */ - -/* \file CAudioRecorder.c AudioRecorder class */ - -#include "sles_allinclusive.h" - - -/** \brief Hook called by Object::Realize when an audio recorder is realized */ - -SLresult CAudioRecorder_Realize(void *self, SLboolean async) -{ - SLresult result = SL_RESULT_SUCCESS; - -#ifdef ANDROID - CAudioRecorder *thiz = (CAudioRecorder *) self; - result = android_audioRecorder_realize(thiz, async); -#endif - - return result; -} - - -/** \brief Hook called by Object::Resume when an audio recorder is resumed */ - -SLresult CAudioRecorder_Resume(void *self, SLboolean async) -{ - return SL_RESULT_SUCCESS; -} - - -/** \brief Hook called by Object::Destroy when an audio recorder is destroyed */ - -void CAudioRecorder_Destroy(void *self) -{ - CAudioRecorder *thiz = (CAudioRecorder *) self; - freeDataLocatorFormat(&thiz->mDataSource); - freeDataLocatorFormat(&thiz->mDataSink); -#ifdef ANDROID - android_audioRecorder_destroy(thiz); -#endif -} - - -/** \brief Hook called by Object::Destroy before an audio recorder is about to be destroyed */ - -predestroy_t CAudioRecorder_PreDestroy(void *self) -{ - return predestroy_ok; -} diff --git a/wilhelm/src/objects/CEngine.c b/wilhelm/src/objects/CEngine.c deleted file mode 100644 index c7c5b42a..00000000 --- a/wilhelm/src/objects/CEngine.c +++ /dev/null @@ -1,187 +0,0 @@ -/* - * 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. - */ - -/** \file CEngine.c Engine class */ - -#include "sles_allinclusive.h" - - -/* This implementation supports at most one engine, identical for both OpenSL ES and OpenMAX AL */ - -CEngine *theOneTrueEngine = NULL; -pthread_mutex_t theOneTrueMutex = PTHREAD_MUTEX_INITIALIZER; -unsigned theOneTrueRefCount = 0; -// incremented by slCreateEngine or xaCreateEngine, decremented by Object::Destroy on engine - - -/** \brief Called by dlopen when .so is loaded */ - -__attribute__((constructor)) static void onDlOpen(void) -{ -} - - -/** \brief Called by dlclose when .so is unloaded */ - -__attribute__((destructor)) static void onDlClose(void) -{ - // a memory barrier would be sufficient, but the mutex is easier - (void) pthread_mutex_lock(&theOneTrueMutex); - if ((NULL != theOneTrueEngine) || (0 < theOneTrueRefCount)) { - SL_LOGE("Object::Destroy omitted for engine %p", theOneTrueEngine); - } - (void) pthread_mutex_unlock(&theOneTrueMutex); -} - - -/** \brief Hook called by Object::Realize when an engine is realized */ - -SLresult CEngine_Realize(void *self, SLboolean async) -{ - CEngine *thiz = (CEngine *) self; - SLresult result; -#ifndef ANDROID - // create the sync thread - int err = pthread_create(&thiz->mSyncThread, (const pthread_attr_t *) NULL, sync_start, thiz); - result = err_to_result(err); - if (SL_RESULT_SUCCESS != result) - return result; -#endif - // initialize the thread pool for asynchronous operations - result = ThreadPool_init(&thiz->mThreadPool, 0, 0); - if (SL_RESULT_SUCCESS != result) { - thiz->mEngine.mShutdown = SL_BOOLEAN_TRUE; - (void) pthread_join(thiz->mSyncThread, (void **) NULL); - return result; - } -#ifdef USE_SDL - SDL_open(&thiz->mEngine); -#endif - return SL_RESULT_SUCCESS; -} - - -/** \brief Hook called by Object::Resume when an engine is resumed */ - -SLresult CEngine_Resume(void *self, SLboolean async) -{ - return SL_RESULT_SUCCESS; -} - - -/** \brief Hook called by Object::Destroy when an engine is destroyed */ - -void CEngine_Destroy(void *self) -{ - CEngine *thiz = (CEngine *) self; - - // Verify that there are no extant objects - unsigned instanceCount = thiz->mEngine.mInstanceCount; - unsigned instanceMask = thiz->mEngine.mInstanceMask; - if ((0 < instanceCount) || (0 != instanceMask)) { - SL_LOGE("Object::Destroy(%p) for engine ignored; %u total active objects", - thiz, instanceCount); - while (0 != instanceMask) { - unsigned i = ctz(instanceMask); - assert(MAX_INSTANCE > i); - SL_LOGE("Object::Destroy(%p) for engine ignored; active object ID %u at %p", - thiz, i + 1, thiz->mEngine.mInstances[i]); - instanceMask &= ~(1 << i); - } - } - - // If engine was created but not realized, there will be no sync thread yet - pthread_t zero; - memset(&zero, 0, sizeof(pthread_t)); - if (0 != memcmp(&zero, &thiz->mSyncThread, sizeof(pthread_t))) { - - // Announce to the sync thread that engine is shutting down; it polls so should see it soon - thiz->mEngine.mShutdown = SL_BOOLEAN_TRUE; - // Wait for the sync thread to acknowledge the shutdown - while (!thiz->mEngine.mShutdownAck) { - object_cond_wait(&thiz->mObject); - } - // The sync thread should have exited by now, so collect it by joining - (void) pthread_join(thiz->mSyncThread, (void **) NULL); - - } - - // Shutdown the thread pool used for asynchronous operations (there should not be any) - ThreadPool_deinit(&thiz->mThreadPool); - -#if defined(ANDROID) - // free equalizer preset names - if (NULL != thiz->mEqPresetNames) { - for (unsigned i = 0; i < thiz->mEqNumPresets; ++i) { - if (NULL != thiz->mEqPresetNames[i]) { - delete[] thiz->mEqPresetNames[i]; - thiz->mEqPresetNames[i] = NULL; - } - } - delete[] thiz->mEqPresetNames; - thiz->mEqPresetNames = NULL; - } - thiz->mEqNumPresets = 0; -#endif - -#ifdef USE_SDL - SDL_close(); -#endif - -} - - -/** \brief Hook called by Object::Destroy before an engine is about to be destroyed */ - -predestroy_t CEngine_PreDestroy(void *self) -{ - predestroy_t ret; - (void) pthread_mutex_lock(&theOneTrueMutex); - assert(self == theOneTrueEngine); - switch (theOneTrueRefCount) { - case 0: - assert(false); - ret = predestroy_error; - break; - case 1: - ret = predestroy_ok; - break; - default: - --theOneTrueRefCount; - ret = predestroy_again; - break; - } - (void) pthread_mutex_unlock(&theOneTrueMutex); - return ret; -} - - -/** \brief Called by IObject::Destroy after engine is destroyed. The parameter refers to the - * previous engine, which is now undefined memory. - */ - -void CEngine_Destroyed(CEngine *self) -{ - int ok; - ok = pthread_mutex_lock(&theOneTrueMutex); - assert(0 == ok); - assert(self == theOneTrueEngine); - theOneTrueEngine = NULL; - assert(1 == theOneTrueRefCount); - theOneTrueRefCount = 0; - ok = pthread_mutex_unlock(&theOneTrueMutex); - assert(0 == ok); -} diff --git a/wilhelm/src/objects/CMediaPlayer.c b/wilhelm/src/objects/CMediaPlayer.c deleted file mode 100644 index f77720e1..00000000 --- a/wilhelm/src/objects/CMediaPlayer.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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. - */ - -/** \file CMediaPlayer.c MediaPlayer class */ - -#include "sles_allinclusive.h" - -#ifdef ANDROID -#include "android/android_GenericMediaPlayer.h" -using namespace android; -#endif - - -XAresult CMediaPlayer_Realize(void *self, XAboolean async) -{ - XAresult result = XA_RESULT_SUCCESS; - -#ifdef ANDROID - CMediaPlayer *thiz = (CMediaPlayer *) self; - - // realize player - result = android_Player_realize(thiz, async); -#endif - - return result; -} - -XAresult CMediaPlayer_Resume(void *self, XAboolean async) -{ - return XA_RESULT_SUCCESS; -} - - -/** \brief Hook called by Object::Destroy when a media player is destroyed */ - -void CMediaPlayer_Destroy(void *self) -{ - CMediaPlayer *thiz = (CMediaPlayer *) self; - freeDataLocatorFormat(&thiz->mDataSource); - freeDataLocatorFormat(&thiz->mBankSource); - freeDataLocatorFormat(&thiz->mAudioSink); - freeDataLocatorFormat(&thiz->mImageVideoSink); - freeDataLocatorFormat(&thiz->mVibraSink); - freeDataLocatorFormat(&thiz->mLEDArraySink); -#ifdef ANDROID - android_Player_destroy(thiz); -#endif -} - - -predestroy_t CMediaPlayer_PreDestroy(void *self) -{ -#ifdef ANDROID - CMediaPlayer *thiz = (CMediaPlayer *) self; - android_Player_preDestroy(thiz); -#endif - return predestroy_ok; -} diff --git a/wilhelm/src/objects/COutputMix.c b/wilhelm/src/objects/COutputMix.c deleted file mode 100644 index 340da0ba..00000000 --- a/wilhelm/src/objects/COutputMix.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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. - */ - -/* \file COutputMix.c OutputMix class */ - -#include "sles_allinclusive.h" - - -/** \brief Hook called by Object::Realize when an output mix is realized */ - -SLresult COutputMix_Realize(void *self, SLboolean async) -{ - SLresult result = SL_RESULT_SUCCESS; - -#ifdef ANDROID - COutputMix *thiz = (COutputMix *) self; - result = android_outputMix_realize(thiz, async); -#endif - - return result; -} - - -/** \brief Hook called by Object::Resume when an output mix is resumed */ - -SLresult COutputMix_Resume(void *self, SLboolean async) -{ - return SL_RESULT_SUCCESS; -} - - -/** \brief Hook called by Object::Destroy when an output mix is destroyed */ - -void COutputMix_Destroy(void *self) -{ -#ifdef ANDROID - COutputMix *thiz = (COutputMix *) self; - android_outputMix_destroy(thiz); -#endif -} - - -/** \brief Hook called by Object::Destroy before an output mix is about to be destroyed */ - -predestroy_t COutputMix_PreDestroy(void *self) -{ - // Ignore destroy requests if there are any players attached to this output mix - COutputMix *outputMix = (COutputMix *) self; - // See design document for explanation - if (0 == outputMix->mObject.mStrongRefCount) { -#ifdef USE_OUTPUTMIXEXT - // We only support a single active output mix per engine, so check if this is the active mix - IEngine *thisEngine = &outputMix->mObject.mEngine->mEngine; - interface_lock_exclusive(thisEngine); - bool thisIsTheActiveOutputMix = false; - if (outputMix == thisEngine->mOutputMix) { - thisIsTheActiveOutputMix = true; - } - interface_unlock_exclusive(thisEngine); - if (thisIsTheActiveOutputMix) { - // Tell the asynchronous mixer callback that we want to destroy the output mix - outputMix->mOutputMixExt.mDestroyRequested = true; - while (outputMix->mOutputMixExt.mDestroyRequested) { - object_cond_wait(&outputMix->mObject); - } -#ifdef USE_SDL - // Mixer callback has acknowledged our request and unlinked output mix from engine. - // Disable SDL_callback from being called periodically by SDL's internal thread. - SDL_PauseAudio(1); -#endif - } -#endif - return predestroy_ok; - } - SL_LOGE("Object::Destroy(%p) for OutputMix ignored; %u players attached", outputMix, - outputMix->mObject.mStrongRefCount); - return predestroy_error; -} diff --git a/wilhelm/src/platform.h b/wilhelm/src/platform.h deleted file mode 100644 index 1a2b5b43..00000000 --- a/wilhelm/src/platform.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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. - */ - -/** \file platform.h Platform-specific configuration constants */ - -#if defined(ANDROID) || defined(USE_SDL) -#define PLATFORM_MILLIBEL_MAX_VOLUME 0 // No more than unity gain -#else -#define PLATFORM_MILLIBEL_MAX_VOLUME SL_MILLIBEL_MAX -#endif diff --git a/wilhelm/src/sl_entry.c b/wilhelm/src/sl_entry.c deleted file mode 100644 index 41f33f7e..00000000 --- a/wilhelm/src/sl_entry.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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. - */ - -#include "sles_allinclusive.h" - -/** \brief slCreateEngine Function */ - -SL_API SLresult SLAPIENTRY slCreateEngine(SLObjectItf *pEngine, SLuint32 numOptions, - const SLEngineOption *pEngineOptions, SLuint32 numInterfaces, - const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired) -{ - SL_ENTER_GLOBAL - - result = liCreateEngine(pEngine, numOptions, pEngineOptions, numInterfaces, pInterfaceIds, - pInterfaceRequired, objectIDtoClass(SL_OBJECTID_ENGINE)); - - SL_LEAVE_GLOBAL -} - - - -/** \brief slQueryNumSupportedEngineInterfaces Function */ - -SL_API SLresult SLAPIENTRY slQueryNumSupportedEngineInterfaces(SLuint32 *pNumSupportedInterfaces) -{ - SL_ENTER_GLOBAL - - result = liQueryNumSupportedInterfaces(pNumSupportedInterfaces, - objectIDtoClass(SL_OBJECTID_ENGINE)); - - SL_LEAVE_GLOBAL -} - - - - -/** \brief slQuerySupportedEngineInterfaces Function */ - -SL_API SLresult SLAPIENTRY slQuerySupportedEngineInterfaces(SLuint32 index, - SLInterfaceID *pInterfaceId) -{ - SL_ENTER_GLOBAL - - result = liQuerySupportedInterfaces(index, pInterfaceId, objectIDtoClass(SL_OBJECTID_ENGINE)); - - SL_LEAVE_GLOBAL -} diff --git a/wilhelm/src/sl_iid.c b/wilhelm/src/sl_iid.c deleted file mode 100644 index 02078997..00000000 --- a/wilhelm/src/sl_iid.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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. - */ - -#include "sles_allinclusive.h" - -#ifdef __cplusplus -extern "C" { -#endif - -// OpenSL ES 1.0.1 interfaces -const SLInterfaceID SL_IID_3DCOMMIT = &SL_IID_array[MPH_3DCOMMIT]; -const SLInterfaceID SL_IID_3DDOPPLER = &SL_IID_array[MPH_3DDOPPLER]; -const SLInterfaceID SL_IID_3DGROUPING = &SL_IID_array[MPH_3DGROUPING]; -const SLInterfaceID SL_IID_3DLOCATION = &SL_IID_array[MPH_3DLOCATION]; -const SLInterfaceID SL_IID_3DMACROSCOPIC = &SL_IID_array[MPH_3DMACROSCOPIC]; -const SLInterfaceID SL_IID_3DSOURCE = &SL_IID_array[MPH_3DSOURCE]; -const SLInterfaceID SL_IID_AUDIODECODERCAPABILITIES = &SL_IID_array[MPH_AUDIODECODERCAPABILITIES]; -const SLInterfaceID SL_IID_AUDIOENCODER = &SL_IID_array[MPH_AUDIOENCODER]; -const SLInterfaceID SL_IID_AUDIOENCODERCAPABILITIES = &SL_IID_array[MPH_AUDIOENCODERCAPABILITIES]; -const SLInterfaceID SL_IID_AUDIOIODEVICECAPABILITIES = &SL_IID_array[MPH_AUDIOIODEVICECAPABILITIES]; -const SLInterfaceID SL_IID_BASSBOOST = &SL_IID_array[MPH_BASSBOOST]; -const SLInterfaceID SL_IID_BUFFERQUEUE = &SL_IID_array[MPH_BUFFERQUEUE]; -const SLInterfaceID SL_IID_DEVICEVOLUME = &SL_IID_array[MPH_DEVICEVOLUME]; -const SLInterfaceID SL_IID_DYNAMICINTERFACEMANAGEMENT = - &SL_IID_array[MPH_DYNAMICINTERFACEMANAGEMENT]; -const SLInterfaceID SL_IID_DYNAMICSOURCE = &SL_IID_array[MPH_DYNAMICSOURCE]; -const SLInterfaceID SL_IID_EFFECTSEND = &SL_IID_array[MPH_EFFECTSEND]; -const SLInterfaceID SL_IID_ENGINE = &SL_IID_array[MPH_ENGINE]; -const SLInterfaceID SL_IID_ENGINECAPABILITIES = &SL_IID_array[MPH_ENGINECAPABILITIES]; -const SLInterfaceID SL_IID_ENVIRONMENTALREVERB = &SL_IID_array[MPH_ENVIRONMENTALREVERB]; -const SLInterfaceID SL_IID_EQUALIZER = &SL_IID_array[MPH_EQUALIZER]; -const SLInterfaceID SL_IID_LED = &SL_IID_array[MPH_LED]; -const SLInterfaceID SL_IID_METADATAEXTRACTION = &SL_IID_array[MPH_METADATAEXTRACTION]; -const SLInterfaceID SL_IID_METADATATRAVERSAL = &SL_IID_array[MPH_METADATATRAVERSAL]; -const SLInterfaceID SL_IID_MIDIMESSAGE = &SL_IID_array[MPH_MIDIMESSAGE]; -const SLInterfaceID SL_IID_MIDIMUTESOLO = &SL_IID_array[MPH_MIDIMUTESOLO]; -const SLInterfaceID SL_IID_MIDITEMPO = &SL_IID_array[MPH_MIDITEMPO]; -const SLInterfaceID SL_IID_MIDITIME = &SL_IID_array[MPH_MIDITIME]; -const SLInterfaceID SL_IID_MUTESOLO = &SL_IID_array[MPH_MUTESOLO]; -const SLInterfaceID SL_IID_NULL = &SL_IID_array[MPH_NULL]; -const SLInterfaceID SL_IID_OBJECT = &SL_IID_array[MPH_OBJECT]; -const SLInterfaceID SL_IID_OUTPUTMIX = &SL_IID_array[MPH_OUTPUTMIX]; -const SLInterfaceID SL_IID_PITCH = &SL_IID_array[MPH_PITCH]; -const SLInterfaceID SL_IID_PLAY = &SL_IID_array[MPH_PLAY]; -const SLInterfaceID SL_IID_PLAYBACKRATE = &SL_IID_array[MPH_PLAYBACKRATE]; -const SLInterfaceID SL_IID_PREFETCHSTATUS = &SL_IID_array[MPH_PREFETCHSTATUS]; -const SLInterfaceID SL_IID_PRESETREVERB = &SL_IID_array[MPH_PRESETREVERB]; -const SLInterfaceID SL_IID_RATEPITCH = &SL_IID_array[MPH_RATEPITCH]; -const SLInterfaceID SL_IID_RECORD = &SL_IID_array[MPH_RECORD]; -const SLInterfaceID SL_IID_SEEK = &SL_IID_array[MPH_SEEK]; -const SLInterfaceID SL_IID_THREADSYNC = &SL_IID_array[MPH_THREADSYNC]; -const SLInterfaceID SL_IID_VIBRA = &SL_IID_array[MPH_VIBRA]; -const SLInterfaceID SL_IID_VIRTUALIZER = &SL_IID_array[MPH_VIRTUALIZER]; -const SLInterfaceID SL_IID_VISUALIZATION = &SL_IID_array[MPH_VISUALIZATION]; -const SLInterfaceID SL_IID_VOLUME = &SL_IID_array[MPH_VOLUME]; - -// Wilhelm desktop extended interfaces -extern const SLInterfaceID SL_IID_OUTPUTMIXEXT; -const SLInterfaceID SL_IID_OUTPUTMIXEXT = &SL_IID_array[MPH_OUTPUTMIXEXT]; - -// Android API level 9 extended interfaces -const SLInterfaceID SL_IID_ANDROIDEFFECT = &SL_IID_array[MPH_ANDROIDEFFECT]; -const SLInterfaceID SL_IID_ANDROIDEFFECTCAPABILITIES = &SL_IID_array[MPH_ANDROIDEFFECTCAPABILITIES]; -const SLInterfaceID SL_IID_ANDROIDEFFECTSEND = &SL_IID_array[MPH_ANDROIDEFFECTSEND]; -const SLInterfaceID SL_IID_ANDROIDCONFIGURATION = &SL_IID_array[MPH_ANDROIDCONFIGURATION]; -const SLInterfaceID SL_IID_ANDROIDSIMPLEBUFFERQUEUE = &SL_IID_array[MPH_ANDROIDSIMPLEBUFFERQUEUE]; - -// Android API level 12 extended interfaces -// GUID and MPH are shared by SL and XA -const SLInterfaceID SL_IID_ANDROIDBUFFERQUEUESOURCE = &SL_IID_array[MPH_ANDROIDBUFFERQUEUESOURCE]; - -#ifdef __cplusplus -} -#endif diff --git a/wilhelm/src/sles.c b/wilhelm/src/sles.c deleted file mode 100644 index 5c4d3eb2..00000000 --- a/wilhelm/src/sles.c +++ /dev/null @@ -1,555 +0,0 @@ -/* - * 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. - */ - -/* OpenSL ES private and global functions not associated with an interface or class */ - -#include "sles_allinclusive.h" - - -/** \brief Return true if the specified interface exists and has been initialized for this object. - * Returns false if the class does not support this kind of interface, or the class supports the - * interface but this particular object has not had the interface exposed at object creation time - * or by DynamicInterface::AddInterface. Note that the return value is not affected by whether - * the application has requested access to the interface with Object::GetInterface. Assumes on - * entry that the object is locked for either shared or exclusive access. - */ - -bool IsInterfaceInitialized(IObject *thiz, unsigned MPH) -{ - assert(NULL != thiz); - assert( /* (MPH_MIN <= MPH) && */ (MPH < (unsigned) MPH_MAX)); - const ClassTable *clazz = thiz->mClass; - assert(NULL != clazz); - int index; - if (0 > (index = clazz->mMPH_to_index[MPH])) { - return false; - } - assert(MAX_INDEX >= clazz->mInterfaceCount); - assert(clazz->mInterfaceCount > (unsigned) index); - switch (thiz->mInterfaceStates[index]) { - case INTERFACE_EXPOSED: - case INTERFACE_ADDED: - return true; - default: - return false; - } -} - - -/** \brief Map an IObject to it's "object ID" (which is really a class ID) */ - -SLuint32 IObjectToObjectID(IObject *thiz) -{ - assert(NULL != thiz); - // Note this returns the OpenSL ES object ID in preference to the OpenMAX AL if both available - const ClassTable *clazz = thiz->mClass; - assert(NULL != clazz); - SLuint32 id = clazz->mSLObjectID; - if (!id) { - id = clazz->mXAObjectID; - } - return id; -} - - -/** \brief Acquire a strong reference to an object. - * Check that object has the specified "object ID" (which is really a class ID) and is in the - * realized state. If so, then acquire a strong reference to it and return true. - * Otherwise return false. - */ - -SLresult AcquireStrongRef(IObject *object, SLuint32 expectedObjectID) -{ - if (NULL == object) { - return SL_RESULT_PARAMETER_INVALID; - } - // NTH additional validity checks on address here - SLresult result; - object_lock_exclusive(object); - SLuint32 actualObjectID = IObjectToObjectID(object); - if (expectedObjectID != actualObjectID) { - SL_LOGE("object %p has object ID %u but expected %u", object, actualObjectID, - expectedObjectID); - result = SL_RESULT_PARAMETER_INVALID; - } else if (SL_OBJECT_STATE_REALIZED != object->mState) { - SL_LOGE("object %p with object ID %u is not realized", object, actualObjectID); - result = SL_RESULT_PRECONDITIONS_VIOLATED; - } else { - ++object->mStrongRefCount; - result = SL_RESULT_SUCCESS; - } - object_unlock_exclusive(object); - return result; -} - - -/** \brief Release a strong reference to an object. - * Entry condition: the object is locked. - * Exit condition: the object is unlocked. - * Finishes the destroy if needed. - */ - -void ReleaseStrongRefAndUnlockExclusive(IObject *object) -{ -#ifdef USE_DEBUG - assert(pthread_equal(pthread_self(), object->mOwner)); -#endif - assert(0 < object->mStrongRefCount); - if ((0 == --object->mStrongRefCount) && (SL_OBJECT_STATE_DESTROYING == object->mState)) { - // FIXME do the destroy here - merge with IDestroy - // but can't do this until we move Destroy to the sync thread - // as Destroy is now a blocking operation, and to avoid a race - } else { - object_unlock_exclusive(object); - } -} - - -/** \brief Release a strong reference to an object. - * Entry condition: the object is unlocked. - * Exit condition: the object is unlocked. - * Finishes the destroy if needed. - */ - -void ReleaseStrongRef(IObject *object) -{ - assert(NULL != object); - object_lock_exclusive(object); - ReleaseStrongRefAndUnlockExclusive(object); -} - - -/** \brief Convert POSIX pthread error code to OpenSL ES result code */ - -SLresult err_to_result(int err) -{ - if (EAGAIN == err || ENOMEM == err) { - return SL_RESULT_RESOURCE_ERROR; - } - if (0 != err) { - return SL_RESULT_INTERNAL_ERROR; - } - return SL_RESULT_SUCCESS; -} - - -/** \brief Check the interface IDs passed into a Create operation */ - -SLresult checkInterfaces(const ClassTable *clazz, SLuint32 numInterfaces, - const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired, - unsigned *pExposedMask, unsigned *pRequiredMask) -{ - assert(NULL != clazz && NULL != pExposedMask); - // Initially no interfaces are exposed - unsigned exposedMask = 0; - unsigned requiredMask = 0; - const struct iid_vtable *interfaces = clazz->mInterfaces; - SLuint32 interfaceCount = clazz->mInterfaceCount; - SLuint32 i; - // Expose all implicit interfaces - for (i = 0; i < interfaceCount; ++i) { - switch (interfaces[i].mInterface) { - case INTERFACE_IMPLICIT: - case INTERFACE_IMPLICIT_PREREALIZE: - // there must be an initialization hook present - if (NULL != MPH_init_table[interfaces[i].mMPH].mInit) { - exposedMask |= 1 << i; - } - break; - case INTERFACE_EXPLICIT: - case INTERFACE_DYNAMIC: - case INTERFACE_UNAVAILABLE: - case INTERFACE_EXPLICIT_PREREALIZE: - break; - default: - assert(false); - break; - } - } - if (0 < numInterfaces) { - if (NULL == pInterfaceIds || NULL == pInterfaceRequired) { - return SL_RESULT_PARAMETER_INVALID; - } - bool anyRequiredButUnsupported = false; - // Loop for each requested interface - for (i = 0; i < numInterfaces; ++i) { - SLInterfaceID iid = pInterfaceIds[i]; - if (NULL == iid) { - return SL_RESULT_PARAMETER_INVALID; - } - SLboolean isRequired = pInterfaceRequired[i]; - int MPH, index; - if ((0 > (MPH = IID_to_MPH(iid))) || - // there must be an initialization hook present - (NULL == MPH_init_table[MPH].mInit) || - (0 > (index = clazz->mMPH_to_index[MPH])) || - (INTERFACE_UNAVAILABLE == interfaces[index].mInterface)) { - // Here if interface was not found, or is not available for this object type - if (isRequired) { - // Application said it required the interface, so give up - SL_LOGE("class %s interface %u required but unavailable MPH=%d", - clazz->mName, i, MPH); - anyRequiredButUnsupported = true; - } - // Application said it didn't really need the interface, so ignore with warning - SL_LOGW("class %s interface %u requested but unavailable MPH=%d", - clazz->mName, i, MPH); - continue; - } - if (isRequired) { - requiredMask |= (1 << index); - } - // The requested interface was both found and available, so expose it - exposedMask |= (1 << index); - // Note that we ignore duplicate requests, including equal and aliased IDs - } - if (anyRequiredButUnsupported) { - return SL_RESULT_FEATURE_UNSUPPORTED; - } - } - *pExposedMask = exposedMask; - if (NULL != pRequiredMask) { - *pRequiredMask = requiredMask; - } - return SL_RESULT_SUCCESS; -} - - -/* Interface initialization hooks */ - -extern void - I3DCommit_init(void *), - I3DDoppler_init(void *), - I3DGrouping_init(void *), - I3DLocation_init(void *), - I3DMacroscopic_init(void *), - I3DSource_init(void *), - IAndroidConfiguration_init(void *), - IAndroidEffect_init(void *), - IAndroidEffectCapabilities_init(void *), - IAndroidEffectSend_init(void *), - IAndroidBufferQueue_init(void *), - IAudioDecoderCapabilities_init(void *), - IAudioEncoder_init(void *), - IAudioEncoderCapabilities_init(void *), - IAudioIODeviceCapabilities_init(void *), - IBassBoost_init(void *), - IBufferQueue_init(void *), - IDeviceVolume_init(void *), - IDynamicInterfaceManagement_init(void *), - IDynamicSource_init(void *), - IEffectSend_init(void *), - IEngine_init(void *), - IEngineCapabilities_init(void *), - IEnvironmentalReverb_init(void *), - IEqualizer_init(void *), - ILEDArray_init(void *), - IMIDIMessage_init(void *), - IMIDIMuteSolo_init(void *), - IMIDITempo_init(void *), - IMIDITime_init(void *), - IMetadataExtraction_init(void *), - IMetadataTraversal_init(void *), - IMuteSolo_init(void *), - IObject_init(void *), - IOutputMix_init(void *), - IOutputMixExt_init(void *), - IPitch_init(void *), - IPlay_init(void *), - IPlaybackRate_init(void *), - IPrefetchStatus_init(void *), - IPresetReverb_init(void *), - IRatePitch_init(void *), - IRecord_init(void *), - ISeek_init(void *), - IThreadSync_init(void *), - IVibra_init(void *), - IVirtualizer_init(void *), - IVisualization_init(void *), - IVolume_init(void *); - -extern void - I3DGrouping_deinit(void *), - IAndroidEffect_deinit(void *), - IAndroidEffectCapabilities_deinit(void *), - IAndroidBufferQueue_deinit(void *), - IBassBoost_deinit(void *), - IBufferQueue_deinit(void *), - IEngine_deinit(void *), - IEnvironmentalReverb_deinit(void *), - IEqualizer_deinit(void *), - IObject_deinit(void *), - IPresetReverb_deinit(void *), - IThreadSync_deinit(void *), - IVirtualizer_deinit(void *); - -extern bool - IAndroidEffectCapabilities_Expose(void *), - IBassBoost_Expose(void *), - IEnvironmentalReverb_Expose(void *), - IEqualizer_Expose(void *), - IPresetReverb_Expose(void *), - IVirtualizer_Expose(void *); - -extern void - IXAEngine_init(void *), - IStreamInformation_init(void*), - IVideoDecoderCapabilities_init(void *); - -extern void - IXAEngine_deinit(void *), - IStreamInformation_deinit(void *), - IVideoDecoderCapabilities_deinit(void *); - -extern bool - IVideoDecoderCapabilities_expose(void *); - -#if !(USE_PROFILES & USE_PROFILES_MUSIC) -#define IDynamicSource_init NULL -#define IMetadataTraversal_init NULL -#define IVisualization_init NULL -#endif - -#if !(USE_PROFILES & USE_PROFILES_GAME) -#define I3DCommit_init NULL -#define I3DDoppler_init NULL -#define I3DGrouping_init NULL -#define I3DLocation_init NULL -#define I3DMacroscopic_init NULL -#define I3DSource_init NULL -#define IMIDIMessage_init NULL -#define IMIDIMuteSolo_init NULL -#define IMIDITempo_init NULL -#define IMIDITime_init NULL -#define IPitch_init NULL -#define IRatePitch_init NULL -#define I3DGrouping_deinit NULL -#endif - -#if !(USE_PROFILES & USE_PROFILES_BASE) -#define IAudioDecoderCapabilities_init NULL -#define IAudioEncoderCapabilities_init NULL -#define IAudioEncoder_init NULL -#define IAudioIODeviceCapabilities_init NULL -#define IDeviceVolume_init NULL -#define IEngineCapabilities_init NULL -#define IThreadSync_init NULL -#define IThreadSync_deinit NULL -#endif - -#if !(USE_PROFILES & USE_PROFILES_OPTIONAL) -#define ILEDArray_init NULL -#define IVibra_init NULL -#endif - -#ifndef ANDROID -#define IAndroidConfiguration_init NULL -#define IAndroidEffect_init NULL -#define IAndroidEffectCapabilities_init NULL -#define IAndroidEffectSend_init NULL -#define IAndroidEffect_deinit NULL -#define IAndroidEffectCapabilities_deinit NULL -#define IAndroidEffectCapabilities_Expose NULL -#define IAndroidBufferQueue_init NULL -#define IStreamInformation_init NULL -#define IAndroidBufferQueue_deinit NULL -#define IStreamInformation_deinit NULL -#endif - -#ifndef USE_OUTPUTMIXEXT -#define IOutputMixExt_init NULL -#endif - - -/*static*/ const struct MPH_init MPH_init_table[MPH_MAX] = { - { /* MPH_3DCOMMIT, */ I3DCommit_init, NULL, NULL, NULL, NULL }, - { /* MPH_3DDOPPLER, */ I3DDoppler_init, NULL, NULL, NULL, NULL }, - { /* MPH_3DGROUPING, */ I3DGrouping_init, NULL, I3DGrouping_deinit, NULL, NULL }, - { /* MPH_3DLOCATION, */ I3DLocation_init, NULL, NULL, NULL, NULL }, - { /* MPH_3DMACROSCOPIC, */ I3DMacroscopic_init, NULL, NULL, NULL, NULL }, - { /* MPH_3DSOURCE, */ I3DSource_init, NULL, NULL, NULL, NULL }, - { /* MPH_AUDIODECODERCAPABILITIES, */ IAudioDecoderCapabilities_init, NULL, NULL, NULL, NULL }, - { /* MPH_AUDIOENCODER, */ IAudioEncoder_init, NULL, NULL, NULL, NULL }, - { /* MPH_AUDIOENCODERCAPABILITIES, */ IAudioEncoderCapabilities_init, NULL, NULL, NULL, NULL }, - { /* MPH_AUDIOIODEVICECAPABILITIES, */ IAudioIODeviceCapabilities_init, NULL, NULL, NULL, - NULL }, - { /* MPH_BASSBOOST, */ IBassBoost_init, NULL, IBassBoost_deinit, IBassBoost_Expose, NULL }, - { /* MPH_BUFFERQUEUE, */ IBufferQueue_init, NULL, IBufferQueue_deinit, NULL, NULL }, - { /* MPH_DEVICEVOLUME, */ IDeviceVolume_init, NULL, NULL, NULL, NULL }, - { /* MPH_DYNAMICINTERFACEMANAGEMENT, */ IDynamicInterfaceManagement_init, NULL, NULL, NULL, - NULL }, - { /* MPH_DYNAMICSOURCE, */ IDynamicSource_init, NULL, NULL, NULL, NULL }, - { /* MPH_EFFECTSEND, */ IEffectSend_init, NULL, NULL, NULL, NULL }, - { /* MPH_ENGINE, */ IEngine_init, NULL, IEngine_deinit, NULL, NULL }, - { /* MPH_ENGINECAPABILITIES, */ IEngineCapabilities_init, NULL, NULL, NULL, NULL }, - { /* MPH_ENVIRONMENTALREVERB, */ IEnvironmentalReverb_init, NULL, IEnvironmentalReverb_deinit, - IEnvironmentalReverb_Expose, NULL }, - { /* MPH_EQUALIZER, */ IEqualizer_init, NULL, IEqualizer_deinit, IEqualizer_Expose, NULL }, - { /* MPH_LED, */ ILEDArray_init, NULL, NULL, NULL, NULL }, - { /* MPH_METADATAEXTRACTION, */ IMetadataExtraction_init, NULL, NULL, NULL, NULL }, - { /* MPH_METADATATRAVERSAL, */ IMetadataTraversal_init, NULL, NULL, NULL, NULL }, - { /* MPH_MIDIMESSAGE, */ IMIDIMessage_init, NULL, NULL, NULL, NULL }, - { /* MPH_MIDITIME, */ IMIDITime_init, NULL, NULL, NULL, NULL }, - { /* MPH_MIDITEMPO, */ IMIDITempo_init, NULL, NULL, NULL, NULL }, - { /* MPH_MIDIMUTESOLO, */ IMIDIMuteSolo_init, NULL, NULL, NULL, NULL }, - { /* MPH_MUTESOLO, */ IMuteSolo_init, NULL, NULL, NULL, NULL }, - { /* MPH_NULL, */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_OBJECT, */ IObject_init, NULL, IObject_deinit, NULL, NULL }, - { /* MPH_OUTPUTMIX, */ IOutputMix_init, NULL, NULL, NULL, NULL }, - { /* MPH_PITCH, */ IPitch_init, NULL, NULL, NULL, NULL }, - { /* MPH_PLAY, */ IPlay_init, NULL, NULL, NULL, NULL }, - { /* MPH_PLAYBACKRATE, */ IPlaybackRate_init, NULL, NULL, NULL, NULL }, - { /* MPH_PREFETCHSTATUS, */ IPrefetchStatus_init, NULL, NULL, NULL, NULL }, - { /* MPH_PRESETREVERB, */ IPresetReverb_init, NULL, IPresetReverb_deinit, - IPresetReverb_Expose, NULL }, - { /* MPH_RATEPITCH, */ IRatePitch_init, NULL, NULL, NULL, NULL }, - { /* MPH_RECORD, */ IRecord_init, NULL, NULL, NULL, NULL }, - { /* MPH_SEEK, */ ISeek_init, NULL, NULL, NULL, NULL }, - { /* MPH_THREADSYNC, */ IThreadSync_init, NULL, IThreadSync_deinit, NULL, NULL }, - { /* MPH_VIBRA, */ IVibra_init, NULL, NULL, NULL, NULL }, - { /* MPH_VIRTUALIZER, */ IVirtualizer_init, NULL, IVirtualizer_deinit, IVirtualizer_Expose, - NULL }, - { /* MPH_VISUALIZATION, */ IVisualization_init, NULL, NULL, NULL, NULL }, - { /* MPH_VOLUME, */ IVolume_init, NULL, NULL, NULL, NULL }, -// Wilhelm desktop extended interfaces - { /* MPH_OUTPUTMIXEXT, */ IOutputMixExt_init, NULL, NULL, NULL, NULL }, -// Android API level 9 extended interfaces - { /* MPH_ANDROIDEFFECT */ IAndroidEffect_init, NULL, IAndroidEffect_deinit, NULL, NULL }, - { /* MPH_ANDROIDEFFECTCAPABILITIES */ IAndroidEffectCapabilities_init, NULL, - IAndroidEffectCapabilities_deinit, IAndroidEffectCapabilities_Expose, NULL }, - { /* MPH_ANDROIDEFFECTSEND */ IAndroidEffectSend_init, NULL, NULL, NULL, NULL }, - { /* MPH_ANDROIDCONFIGURATION */ IAndroidConfiguration_init, NULL, NULL, NULL, NULL }, - { /* MPH_ANDROIDSIMPLEBUFFERQUEUE */ IBufferQueue_init /* alias */, NULL, NULL, NULL, NULL }, -// Android API level 10 extended interfaces - { /* MPH_ANDROIDBUFFERQUEUESOURCE */ IAndroidBufferQueue_init, NULL, IAndroidBufferQueue_deinit, - NULL, NULL }, -// OpenMAX AL 1.0.1 interfaces - { /* MPH_XAAUDIODECODERCAPABILITIES */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XAAUDIOENCODER */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XAAUDIOENCODERCAPABILITIES */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XAAUDIOIODEVICECAPABILITIES */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XACAMERA */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XACAMERACAPABILITIES */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XACONFIGEXTENSION */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XADEVICEVOLUME */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XADYNAMICINTERFACEMANAGEMENT 59 */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XADYNAMICSOURCE */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XAENGINE */ IXAEngine_init, NULL, IXAEngine_deinit, NULL, NULL }, - { /* MPH_XAEQUALIZER */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XAIMAGECONTROLS */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XAIMAGEDECODERCAPABILITIES */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XAIMAGEEFFECTS */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XAIMAGEENCODER */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XAIMAGEENCODERCAPABILITIES */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XALED */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XAMETADATAEXTRACTION */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XAMETADATAINSERTION */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XAMETADATATRAVERSAL */ NULL, NULL, NULL, NULL, NULL }, -// { /* MPH_XANULL */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XAOBJECT */ IObject_init, NULL, IObject_deinit, NULL, NULL }, - { /* MPH_XAOUTPUTMIX */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XAPLAY */ IPlay_init, NULL, NULL, NULL, NULL }, - { /* MPH_XAPLAYBACKRATE */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XAPREFETCHSTATUS, */ IPrefetchStatus_init, NULL, NULL, NULL, NULL }, - { /* MPH_XARADIO */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XARDS */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XARECORD */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XASEEK */ ISeek_init, NULL, NULL, NULL, NULL }, - { /* MPH_XASNAPSHOT */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XASTREAMINFORMATION */ IStreamInformation_init, NULL, IStreamInformation_deinit, - NULL, NULL }, - { /* MPH_XATHREADSYNC */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XAVIBRA */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XAVIDEODECODERCAPABILITIES */ IVideoDecoderCapabilities_init, NULL, - IVideoDecoderCapabilities_deinit, IVideoDecoderCapabilities_expose, NULL }, - { /* MPH_XAVIDEOENCODER */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XAVIDEOENCODERCAPABILITIES */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XAVIDEOPOSTPROCESSING */ NULL, NULL, NULL, NULL, NULL }, - { /* MPH_XAVOLUME, */ IVolume_init, NULL, NULL, NULL, NULL }, -}; - - -/** \brief Construct a new instance of the specified class, exposing selected interfaces */ - -IObject *construct(const ClassTable *clazz, unsigned exposedMask, SLEngineItf engine) -{ - IObject *thiz; - // Do not change this to malloc; we depend on the object being memset to zero - thiz = (IObject *) calloc(1, clazz->mSize); - if (NULL != thiz) { - SL_LOGV("construct %s at %p", clazz->mName, thiz); - unsigned lossOfControlMask = 0; - // a NULL engine means we are constructing the engine - IEngine *thisEngine = (IEngine *) engine; - if (NULL == thisEngine) { - // thisEngine = &((CEngine *) thiz)->mEngine; - thiz->mEngine = (CEngine *) thiz; - } else { - thiz->mEngine = (CEngine *) thisEngine->mThis; - interface_lock_exclusive(thisEngine); - if (MAX_INSTANCE <= thisEngine->mInstanceCount) { - SL_LOGE("Too many objects"); - interface_unlock_exclusive(thisEngine); - free(thiz); - return NULL; - } - // pre-allocate a pending slot, but don't assign bit from mInstanceMask yet - ++thisEngine->mInstanceCount; - assert(((unsigned) ~0) != thisEngine->mInstanceMask); - interface_unlock_exclusive(thisEngine); - // const, no lock needed - if (thisEngine->mLossOfControlGlobal) { - lossOfControlMask = ~0; - } - } - thiz->mLossOfControlMask = lossOfControlMask; - thiz->mClass = clazz; - const struct iid_vtable *x = clazz->mInterfaces; - SLuint8 *interfaceStateP = thiz->mInterfaceStates; - SLuint32 index; - for (index = 0; index < clazz->mInterfaceCount; ++index, ++x, exposedMask >>= 1) { - SLuint8 state; - // initialize all interfaces with init hooks, even if not exposed - const struct MPH_init *mi = &MPH_init_table[x->mMPH]; - VoidHook init = mi->mInit; - if (NULL != init) { - void *self = (char *) thiz + x->mOffset; - // IObject does not have an mThis, so [1] is not always defined - if (index) { - ((IObject **) self)[1] = thiz; - } - // call the initialization hook - (*init)(self); - // IObject does not require a call to GetInterface - if (index) { - // This trickery invalidates the v-table until GetInterface - ((size_t *) self)[0] ^= ~0; - } - // if interface is exposed, also call the optional expose hook - BoolHook expose; - state = (exposedMask & 1) && ((NULL == (expose = mi->mExpose)) || (*expose)(self)) ? - INTERFACE_EXPOSED : INTERFACE_INITIALIZED; - // FIXME log or report to application if an expose hook on a - // required explicit interface fails at creation time - } else { - state = INTERFACE_UNINITIALIZED; - } - *interfaceStateP++ = state; - } - // note that the new object is not yet published; creator must call IObject_Publish - } - return thiz; -} diff --git a/wilhelm/src/sles_allinclusive.h b/wilhelm/src/sles_allinclusive.h deleted file mode 100644 index a2022426..00000000 --- a/wilhelm/src/sles_allinclusive.h +++ /dev/null @@ -1,460 +0,0 @@ -/* - * 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. - */ - -/** \file sles_allinclusive.h Everything including the kitchen sink */ - -#include <SLES/OpenSLES.h> -#include <OMXAL/OpenMAXAL.h> -#ifdef ANDROID -#include <SLES/OpenSLES_Android.h> -#include <OMXAL/OpenMAXAL_Android.h> -#endif -#include <stddef.h> // offsetof -#include <stdlib.h> // malloc -#include <string.h> // memcmp -#include <strings.h> -#include <stdio.h> // debugging -#include <assert.h> // debugging -#include <pthread.h> -#include <unistd.h> // usleep -#include <errno.h> - -#ifndef __cplusplus -typedef int bool; -#ifndef false -#define false 0 -#endif -#ifndef true -#define true 1 -#endif -#endif - -// The OpenSLES.h definitions of SL_PROFILES_... have casts, so are unusable by preprocessor -#define USE_PROFILES_PHONE 0x1 // == SL_PROFILES_PHONE -#define USE_PROFILES_MUSIC 0x2 // == SL_PROFILES_MUSIC -#define USE_PROFILES_GAME 0x4 // == SL_PROFILES_GAME -// Pseudo profiles, used to decide whether to include code for incomplete or untested features -// Features that are not in union of all profiles: audio recorder, LED, Vibra -#define USE_PROFILES_OPTIONAL 0x8 -// Features that are in the intersection of all profiles: -// object priorities, preemption, loss of control, device configuration -#define USE_PROFILES_BASE 0x10 - -#include "MPH.h" -#include "MPH_to.h" -#include "devices.h" -#include "ut/OpenSLESUT.h" -#include "ThreadPool.h" - -typedef struct CEngine_struct CEngine; -typedef struct CAudioPlayer_struct CAudioPlayer; -typedef struct CAudioRecorder_struct CAudioRecorder; -typedef struct C3DGroup_struct C3DGroup; -typedef struct COutputMix_struct COutputMix; - -#ifdef USE_SNDFILE -#include <sndfile.h> -#include "desktop/SLSndFile.h" -#endif // USE_SNDFILE - -#ifdef USE_SDL -#include <SDL/SDL_audio.h> -#endif // USE_SDL - -#define STEREO_CHANNELS 2 - -/** - * Constants to define unknown property values - */ -#define UNKNOWN_NUMCHANNELS 0 -#define UNKNOWN_SAMPLERATE 0 -#define UNKNOWN_CHANNELMASK 0 - -#ifdef ANDROID -#include <utils/Log.h> -#include <utils/KeyedVector.h> -#include "media/AudioSystem.h" -#include "media/mediarecorder.h" -#include "media/AudioRecord.h" -#include "media/AudioTrack.h" -#include "media/mediaplayer.h" -#include <utils/String8.h> -#define ANDROID_SL_MILLIBEL_MAX 0 -#include "android/android_sles_conversions.h" -#include "android/android_defs.h" -#endif - -#ifdef USE_OUTPUTMIXEXT -#include "desktop/OutputMixExt.h" -#endif - -#include "sllog.h" - -typedef enum { - predestroy_error, // Application should not be calling destroy now - predestroy_ok, // OK to destroy object now - predestroy_again // Application did nothing wrong, but should destroy again to be effective -} predestroy_t; - -// Hook functions - -typedef void (*VoidHook)(void *self); -//typedef SLresult (*ResultHook)(void *self); -typedef SLresult (*AsyncHook)(void *self, SLboolean async); -typedef bool (*BoolHook)(void *self); -typedef predestroy_t (*PreDestroyHook)(void *self); - -// Describes how an interface is related to a given class, used in iid_vtable::mInterface - -#define INTERFACE_IMPLICIT 0 // no need for application to request prior to GetInterface -#define INTERFACE_EXPLICIT 1 // must be requested explicitly during object creation -#define INTERFACE_DYNAMIC 2 // can be requested after object creation -#define INTERFACE_UNAVAILABLE 3 // this interface is not available on objects of this class -#define INTERFACE_IMPLICIT_PREREALIZE 4 // implicit, and can call GetInterface before Realize -#define INTERFACE_EXPLICIT_PREREALIZE 5 // explicit, and can call GetInterface before Realize -// 6 and 7 are reserved for the meaningless DYNAMIC_PREREALIZE and UNAVAILABLE_PREREALIZE -// note that INTERFACE_OPTIONAL is always re-mapped to one of the above -#define INTERFACE_PREREALIZE 4 // bit-mask to test for calling GetInterface before Realize - -// Profile-specific interfaces - -#if USE_PROFILES & USE_PROFILES_BASE -#define INTERFACE_IMPLICIT_BASE INTERFACE_IMPLICIT -#define INTERFACE_EXPLICIT_BASE INTERFACE_EXPLICIT -#else -#define INTERFACE_IMPLICIT_BASE INTERFACE_UNAVAILABLE -#define INTERFACE_EXPLICIT_BASE INTERFACE_UNAVAILABLE -#endif - -#if USE_PROFILES & USE_PROFILES_GAME -#define INTERFACE_DYNAMIC_GAME INTERFACE_DYNAMIC -#define INTERFACE_EXPLICIT_GAME INTERFACE_EXPLICIT -#else -#define INTERFACE_DYNAMIC_GAME INTERFACE_OPTIONAL -#define INTERFACE_EXPLICIT_GAME INTERFACE_OPTIONAL -#endif - -#if USE_PROFILES & USE_PROFILES_MUSIC -#define INTERFACE_DYNAMIC_MUSIC INTERFACE_DYNAMIC -#else -#define INTERFACE_DYNAMIC_MUSIC INTERFACE_OPTIONAL -#endif - -#if USE_PROFILES & (USE_PROFILES_GAME | USE_PROFILES_MUSIC) -#define INTERFACE_DYNAMIC_GAME_MUSIC INTERFACE_DYNAMIC -#define INTERFACE_EXPLICIT_GAME_MUSIC INTERFACE_EXPLICIT -#else -#define INTERFACE_DYNAMIC_GAME_MUSIC INTERFACE_OPTIONAL -#define INTERFACE_EXPLICIT_GAME_MUSIC INTERFACE_OPTIONAL -#endif - -#if USE_PROFILES & (USE_PROFILES_GAME | USE_PROFILES_PHONE) -#define INTERFACE_EXPLICIT_GAME_PHONE INTERFACE_EXPLICIT -#else -#define INTERFACE_EXPLICIT_GAME_PHONE INTERFACE_OPTIONAL -#endif - -#if USE_PROFILES & USE_PROFILES_OPTIONAL -#define INTERFACE_OPTIONAL INTERFACE_EXPLICIT -#define INTERFACE_DYNAMIC_OPTIONAL INTERFACE_DYNAMIC -#else -#define INTERFACE_OPTIONAL INTERFACE_UNAVAILABLE -#define INTERFACE_DYNAMIC_OPTIONAL INTERFACE_UNAVAILABLE -#endif - -// Describes how an interface is related to a given object - -#define INTERFACE_UNINITIALIZED 0 ///< not available -#define INTERFACE_INITIALIZED 1 ///< not requested at object creation time -#define INTERFACE_EXPOSED 2 ///< requested at object creation time -#define INTERFACE_ADDING_1 3 ///< part 1 of asynchronous AddInterface, pending -#define INTERFACE_ADDING_2 4 ///< synchronous AddInterface, or part 2 of asynchronous -#define INTERFACE_ADDED 5 ///< AddInterface has completed -#define INTERFACE_REMOVING 6 ///< unlocked phase of (synchronous) RemoveInterface -#define INTERFACE_SUSPENDING 7 ///< suspend in progress -#define INTERFACE_SUSPENDED 8 ///< suspend has completed -#define INTERFACE_RESUMING_1 9 ///< part 1 of asynchronous ResumeInterface, pending -#define INTERFACE_RESUMING_2 10 ///< synchronous ResumeInterface, or part 2 of asynchronous -#define INTERFACE_ADDING_1A 11 ///< part 1 of asynchronous AddInterface, aborted -#define INTERFACE_RESUMING_1A 12 ///< part 1 of asynchronous ResumeInterface, aborted - - -// Maps an interface ID to its offset within the class that exposes it - -struct iid_vtable { - unsigned char mMPH; // primary MPH for this interface, does not include any aliases - unsigned char mInterface; // relationship of interface to this class - /*size_t*/ unsigned short mOffset; -}; - -// Per-class const data shared by all instances of the same class - -typedef struct { - const struct iid_vtable *mInterfaces; // maps interface index to info about that interface - SLuint32 mInterfaceCount; // number of possible interfaces - const signed char *mMPH_to_index; - const char * const mName; - size_t mSize; - // OpenSL ES and OpenMAX AL object IDs come from different ranges, and some objects such as - // Engine, Output Mix, LED, and Vibra belong to both APIs, so we keep both object IDs - SLuint16 mSLObjectID; // OpenSL ES object ID - XAuint16 mXAObjectID; // OpenMAX AL object ID - // hooks - AsyncHook mRealize; // called with mutex locked; can temporarily unlock mutex (for async) - AsyncHook mResume; // called with mutex locked; can temporarily unlock mutex (for async) - VoidHook mDestroy; // called with mutex locked and must keep mutex locked throughout - PreDestroyHook mPreDestroy; // called with mutex locked; can temporarily unlock mutex (for wait) -} ClassTable; - -// BufferHeader describes each element of a BufferQueue, other than the data -typedef struct { - const void *mBuffer; - SLuint32 mSize; -} BufferHeader; - -#ifdef ANDROID -// Holds information about all commands that can be passed alongside an MPEG-2 TS buffer -// Is used with buffers of type kAndroidBufferTypeMpeg2Ts -typedef struct { - SLuint32 mTsCmdCode; - SLAuint64 mPts; -} Mpeg2TsCommands; - -// Holds information about all commands that can be passed alongside an AAC ADTS buffer -// Is used with buffers of type kAndroidBufferTypeAacadts -typedef struct { - SLuint32 mAdtsCmdCode; -} AdtsCommands; - -// Union of the different structures to hold items stored in an AdvancedBufferHeader -// when an item comes from an AndroidBufferQueue as the data source, it's a command -// when an item is output to an AndroidBufferQueue as the data sink, it's a message (or metadata) -typedef union { - Mpeg2TsCommands mTsCmdData; - AdtsCommands mAdtsCmdData; -} AdvancedBufferItems; - -// AdvancedBufferHeader describes each element of an AndroidBufferQueue, other than the data -// and associated messages -typedef struct { - const void *mDataBuffer; - SLuint32 mDataSize; - SLuint32 mDataSizeConsumed; - AdvancedBufferItems mItems; - const void *mBufferContext; - // mBufferState will be used for the other ABQ events we'll support in the future - // SLuint32 mBufferState; -} AdvancedBufferHeader; -#endif - -#ifdef USE_SNDFILE - -#define SndFile_BUFSIZE 512 // in 16-bit samples -#define SndFile_NUMBUFS 2 - -struct SndFile { - // save URI also? - SLchar *mPathname; - SNDFILE *mSNDFILE; - SF_INFO mSfInfo; - pthread_mutex_t mMutex; // protects mSNDFILE only - SLboolean mEOF; // sf_read returned zero sample frames - SLuint32 mWhich; // which buffer to use next - short mBuffer[SndFile_BUFSIZE * SndFile_NUMBUFS]; -}; - -#endif // USE_SNDFILE - -#include "data.h" -#include "itfstruct.h" -#include "classes.h" - -struct MPH_init { - VoidHook mInit; // called first to initialize the interface, right after object is allocated - // Each interface is initialized regardless whether it is exposed to application. - VoidHook mResume; // called to resume interface after suspension, not currently used - VoidHook mDeinit; // called last when object is about to be destroyed - BoolHook mExpose; // called after initialization, only if interface is exposed to application - VoidHook mRemove; // called by DynamicInterfaceManager::RemoveInterface, and prior to mDeinit - // will need a suspend hook when suspend is implemented -}; - -extern /*static*/ int IID_to_MPH(const SLInterfaceID iid); -extern /*static*/ const struct MPH_init MPH_init_table[MPH_MAX]; -extern SLresult checkInterfaces(const ClassTable *clazz, - SLuint32 numInterfaces, const SLInterfaceID *pInterfaceIds, - const SLboolean *pInterfaceRequired, unsigned *pExposedMask, unsigned *pRequiredMask); -extern IObject *construct(const ClassTable *clazz, - unsigned exposedMask, SLEngineItf engine); -extern const ClassTable *objectIDtoClass(SLuint32 objectID); -extern const struct SLInterfaceID_ SL_IID_array[MPH_MAX]; -extern SLuint32 IObjectToObjectID(IObject *object); -extern void IObject_Publish(IObject *thiz); -extern void IObject_Destroy(SLObjectItf self); - -// Map an interface to it's "object ID" (which is really a class ID). -// Note: this operation is undefined on IObject, as it lacks an mThis. -// If you have an IObject, then use IObjectToObjectID directly. - -#define InterfaceToObjectID(thiz) IObjectToObjectID((thiz)->mThis) - -// Map an interface to it's corresponding IObject. -// Note: this operation is undefined on IObject, as it lacks an mThis. -// If you have an IObject, then you're done -- you already have what you need. - -#define InterfaceToIObject(thiz) ((thiz)->mThis) - -#define InterfaceToCAudioPlayer(thiz) (((CAudioPlayer*)InterfaceToIObject(thiz))) - -#define InterfaceToCAudioRecorder(thiz) (((CAudioRecorder*)InterfaceToIObject(thiz))) - -#define InterfaceToCAudioRecorder(thiz) (((CAudioRecorder*)InterfaceToIObject(thiz))) - -#define InterfaceToCMediaPlayer(thiz) (((CMediaPlayer*)InterfaceToIObject(thiz))) - -#ifdef ANDROID -#include "android/MediaPlayer_to_android.h" -#include "android/OutputMix_to_android.h" -#include "android/AudioPlayer_to_android.h" -#include "android/AudioRecorder_to_android.h" -#endif - -extern predestroy_t C3DGroup_PreDestroy(void *self); - -extern SLresult CAudioPlayer_Realize(void *self, SLboolean async); -extern SLresult CAudioPlayer_Resume(void *self, SLboolean async); -extern void CAudioPlayer_Destroy(void *self); -extern predestroy_t CAudioPlayer_PreDestroy(void *self); - -extern SLresult CAudioRecorder_Realize(void *self, SLboolean async); -extern SLresult CAudioRecorder_Resume(void *self, SLboolean async); -extern void CAudioRecorder_Destroy(void *self); -extern predestroy_t CAudioRecorder_PreDestroy(void *self); - -extern SLresult CEngine_Realize(void *self, SLboolean async); -extern SLresult CEngine_Resume(void *self, SLboolean async); -extern void CEngine_Destroy(void *self); -extern predestroy_t CEngine_PreDestroy(void *self); -extern void CEngine_Destroyed(CEngine *self); - -extern SLresult COutputMix_Realize(void *self, SLboolean async); -extern SLresult COutputMix_Resume(void *self, SLboolean async); -extern void COutputMix_Destroy(void *self); -extern predestroy_t COutputMix_PreDestroy(void *self); - -extern SLresult CMediaPlayer_Realize(void *self, SLboolean async); -extern SLresult CMediaPlayer_Resume(void *self, SLboolean async); -extern void CMediaPlayer_Destroy(void *self); -extern predestroy_t CMediaPlayer_PreDestroy(void *self); - -#ifdef USE_SDL -extern void SDL_open(IEngine *thisEngine); -extern void SDL_close(void); -#endif - -#define SL_OBJECT_STATE_REALIZING_1 ((SLuint32) 0x4) // async realize on work queue -#define SL_OBJECT_STATE_REALIZING_2 ((SLuint32) 0x5) // sync realize, or async realize hook -#define SL_OBJECT_STATE_RESUMING_1 ((SLuint32) 0x6) // async resume on work queue -#define SL_OBJECT_STATE_RESUMING_2 ((SLuint32) 0x7) // sync resume, or async resume hook -#define SL_OBJECT_STATE_SUSPENDING ((SLuint32) 0x8) // suspend in progress -#define SL_OBJECT_STATE_REALIZING_1A ((SLuint32) 0x9) // abort while async realize on work queue -#define SL_OBJECT_STATE_RESUMING_1A ((SLuint32) 0xA) // abort while async resume on work queue -#define SL_OBJECT_STATE_DESTROYING ((SLuint32) 0xB) // destroy object when no strong references - -#ifdef USE_OUTPUTMIXEXT -#define SL_PLAYSTATE_STOPPING ((SLuint32) 0x4) // Play::Stop while PLAYING -// If we needed it, could have PLAYING mean mixer is currently reading from front buffer, -// while PLAYABLE would mean application requested PLAYING, but buffer queue is empty -#endif - -#ifndef ANDROID -extern void *sync_start(void *arg); -#endif -extern SLresult err_to_result(int err); - -#ifdef __GNUC__ -#define ctz __builtin_ctz -#else -extern unsigned ctz(unsigned); -#endif -extern const char * const interface_names[MPH_MAX]; -#include "platform.h" -#include "attr.h" -#include "handlers.h" -#include "trace.h" - -#ifdef USE_SNDFILE -extern void audioPlayerTransportUpdate(CAudioPlayer *audioPlayer); -#endif - -extern SLresult IBufferQueue_Enqueue(SLBufferQueueItf self, const void *pBuffer, SLuint32 size); -extern SLresult IBufferQueue_Clear(SLBufferQueueItf self); -extern SLresult IBufferQueue_RegisterCallback(SLBufferQueueItf self, - slBufferQueueCallback callback, void *pContext); - -extern bool IsInterfaceInitialized(IObject *thiz, unsigned MPH); -extern SLresult AcquireStrongRef(IObject *object, SLuint32 expectedObjectID); -extern void ReleaseStrongRef(IObject *object); -extern void ReleaseStrongRefAndUnlockExclusive(IObject *object); - -extern COutputMix *CAudioPlayer_GetOutputMix(CAudioPlayer *audioPlayer); -extern SLresult IEngineCapabilities_QueryLEDCapabilities(SLEngineCapabilitiesItf self, - SLuint32 *pIndex, SLuint32 *pLEDDeviceID, SLLEDDescriptor *pDescriptor); -extern SLresult IEngineCapabilities_QueryVibraCapabilities(SLEngineCapabilitiesItf self, - SLuint32 *pIndex, SLuint32 *pVibraDeviceID, SLVibraDescriptor *pDescriptor); - -extern CEngine *theOneTrueEngine; -extern pthread_mutex_t theOneTrueMutex; -extern unsigned theOneTrueRefCount; - -extern LI_API SLresult liCreateEngine(SLObjectItf *pEngine, SLuint32 numOptions, - const SLEngineOption *pEngineOptions, SLuint32 numInterfaces, - const SLInterfaceID *pInterfaceIds, const SLboolean *pInterfaceRequired, - const ClassTable *pCEngine_class); -extern LI_API SLresult liQueryNumSupportedInterfaces(SLuint32 *pNumSupportedInterfaces, - const ClassTable *clazz); -extern LI_API SLresult liQuerySupportedInterfaces(SLuint32 index, SLInterfaceID *pInterfaceId, - const ClassTable *clazz); - -// The EnqueueAsyncCallback macros provide a safe way to asynchronously call an application-level -// callback handler that is permitted to do almost anything, including block. This is intended -// primarily for "notification" callbacks such as play head progress. Do not use for callbacks -// which must be synchronous, such as buffer queue completions. The enqueue may fail if -// the callback queue is full. This almost always indicates an application error such as blocking -// for an excessive time within a callback handler or requesting too frequent callbacks. The -// recommended recovery is to either retry later, or log a warning or error as appropriate. -// If the callback absolutely must be called, then you should be calling it directly instead. -// Example usage: -// CAudioPlayer *ap; -// SLresult result = EnqueueAsyncCallback_ppi(ap, playCallback, &ap->mPlay.mItf, playContext, -// SL_PLAYEVENT_HEADATEND); -// if (SL_RESULT_SUCCESS != result) { -// ALOGW("Callback %p(%p, %p, SL_PLAYEVENT_HEADATEND) dropped", playCallback, &ap->mPlay.mItf, -// playContext); -// } -// which replaces: -// (*playCallback)(&ap->mPlay.mItf, playContext, SL_PLAYEVENT_HEADATEND); -#define EnqueueAsyncCallback_ppi(object, handler, p1, p2, i1) \ - ThreadPool_add_ppi(&(object)->mObject.mEngine->mThreadPool, \ - (ClosureHandler_ppi) (handler), (p1), (p2), (i1)) -#define EnqueueAsyncCallback_ppii(object, handler, p1, p2, i1, i2) \ - ThreadPool_add_ppii(&(object)->mObject.mEngine->mThreadPool, \ - (ClosureHandler_ppii) (handler), (p1), (p2), (i1), (i2)) -#define EnqueueAsyncCallback_piipp(object, handler, p1, i1, i2, p2, p3) \ - ThreadPool_add_piipp(&(object)->mObject.mEngine->mThreadPool, \ - (ClosureHandler_piipp) (handler), (p1), (i1), (i2), (p2), (p3)) - -#define SL_PREFETCHEVENT_NONE ((SLuint32) 0) // placeholder for non-existent SL_PREFETCHEVENT_* diff --git a/wilhelm/src/sllog.c b/wilhelm/src/sllog.c deleted file mode 100644 index 4364499f..00000000 --- a/wilhelm/src/sllog.c +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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. - */ - -#include "sles_allinclusive.h" - -#ifdef ANDROID -/** \brief Log messages are prefixed by this tag */ -const char slLogTag[] = "libOpenSLES"; -#endif - -#if 0 -// There is no support for configuring the logging level at runtime. -// If that was needed, it could be done like this: -// #define SL_LOGx(...) do { if (slLogLevel <= ...) ... } while (0) - -/** \brief Default runtime log level */ - -SLAndroidLogLevel slLogLevel = USE_LOG_RUNTIME; - -/** \brief Set the runtime log level */ - -SL_API void SLAPIENTRY slAndroidSetLogLevel(SLAndroidLogLevel logLevel) -{ - // Errors can't be disabled - if (logLevel > SLAndroidLogLevel_Error) - logLevel = SLAndroidLogLevel_Error; - slLogLevel = logLevel; -} -#endif diff --git a/wilhelm/src/sllog.h b/wilhelm/src/sllog.h deleted file mode 100644 index dd8f201d..00000000 --- a/wilhelm/src/sllog.h +++ /dev/null @@ -1,121 +0,0 @@ -/* - * 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. - */ - -// Logging - -// In order of decreasing priority, the log priority levels are: -// Assert -// E(rror) -// W(arn) -// I(nfo) -// D(ebug) -// V(erbose) -// Debug and verbose are usually compiled out except during development. - -/** These values match the definitions in system/core/include/cutils/log.h */ -#define SLAndroidLogLevel_Unknown 0 -#define SLAndroidLogLevel_Default 1 -#define SLAndroidLogLevel_Verbose 2 -#define SLAndroidLogLevel_Debug 3 -#define SLAndroidLogLevel_Info 4 -#define SLAndroidLogLevel_Warn 5 -#define SLAndroidLogLevel_Error 6 -#define SLAndroidLogLevel_Fatal 7 -#define SLAndroidLogLevel_Silent 8 - -// USE_LOG is the minimum log priority level that is enabled at build time. -// It is configured in Android.mk but can be overridden per source file. -#ifndef USE_LOG -#define USE_LOG SLAndroidLogLevel_Info -#endif - - -#ifdef ANDROID - -// The usual Android LOGx macros are not available, so we use the lower-level APIs. -extern const char slLogTag[]; - -// can't disable SL_LOGF -#define SL_LOGF(...) __android_log_print(SLAndroidLogLevel_Fatal, slLogTag, __VA_ARGS__) - -#if (USE_LOG <= SLAndroidLogLevel_Error) -#define SL_LOGE(...) __android_log_print(SLAndroidLogLevel_Error, slLogTag, __VA_ARGS__) -#else -#define SL_LOGE(...) do { } while (0) -#endif - -#if (USE_LOG <= SLAndroidLogLevel_Warn) -#define SL_LOGW(...) __android_log_print(SLAndroidLogLevel_Warn, slLogTag, __VA_ARGS__) -#else -#define SL_LOGW(...) do { } while (0) -#endif - -#if (USE_LOG <= SLAndroidLogLevel_Info) -#define SL_LOGI(...) __android_log_print(SLAndroidLogLevel_Info, slLogTag, __VA_ARGS__) -#else -#define SL_LOGI(...) do { } while (0) -#endif - -#if (USE_LOG <= SLAndroidLogLevel_Debug) -#define SL_LOGD(...) __android_log_print(SLAndroidLogLevel_Debug, slLogTag, __VA_ARGS__) -#else -#define SL_LOGD(...) do { } while (0) -#endif - -#if (USE_LOG <= SLAndroidLogLevel_Verbose) -#define SL_LOGV(...) __android_log_print(SLAndroidLogLevel_Verbose, slLogTag, __VA_ARGS__) -#else -#define SL_LOGV(...) do { } while (0) -#endif - -#else // !defined(ANDROID) - -#if (USE_LOG <= SLAndroidLogLevel_Error) -#define SL_LOGE(...) do { fprintf(stderr, "SL_LOGE: %s:%s:%d ", __FILE__, __FUNCTION__, __LINE__); \ - fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); } while(0) -#else -#define SL_LOGE(...) do { } while (0) -#endif - -#if (USE_LOG <= SLAndroidLogLevel_Warn) -#define SL_LOGW(...) do { fprintf(stderr, "SL_LOGW: %s:%s:%d ", __FILE__, __FUNCTION__, __LINE__); \ - fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); } while(0) -#else -#define SL_LOGW(...) do { } while (0) -#endif - -#if (USE_LOG <= SLAndroidLogLevel_Info) -#define SL_LOGI(...) do { fprintf(stderr, "SL_LOGI: %s:%s:%d ", __FILE__, __FUNCTION__, __LINE__); \ - fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); } while(0) -#else -#define SL_LOGI(...) do { } while (0) -#endif - -#if (USE_LOG <= SLAndroidLogLevel_Debug) -#define SL_LOGD(...) do { fprintf(stderr, "SL_LOGD: %s:%s:%d ", __FILE__, __FUNCTION__, __LINE__); \ - fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); } while(0) -#else -#define SL_LOGD(...) do { } while (0) -#endif - -#if (USE_LOG <= SLAndroidLogLevel_Verbose) -#define SL_LOGV(...) do { fprintf(stderr, "SL_LOGV: %s:%s:%d ", __FILE__, __FUNCTION__, __LINE__); \ - fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); } while(0) -#else -#define SL_LOGV(...) do { } while (0) -#endif - -#endif // ANDROID diff --git a/wilhelm/src/sync.c b/wilhelm/src/sync.c deleted file mode 100644 index 14acc697..00000000 --- a/wilhelm/src/sync.c +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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. - */ - -/* sync */ - -#include "sles_allinclusive.h" - - -/** \brief Sync thread. - * The sync thread runs periodically to synchronize audio state between - * the application and platform-specific device driver; for best results - * it should run about every graphics frame (e.g. 20 Hz to 50 Hz). - */ - -void *sync_start(void *arg) -{ - CEngine *thiz = (CEngine *) arg; - for (;;) { - - // FIXME should be driven by cond_signal rather than polling, - // or at least make the poll interval longer or configurable - usleep(20000*5); - - object_lock_exclusive(&thiz->mObject); - if (thiz->mEngine.mShutdown) { - thiz->mEngine.mShutdownAck = SL_BOOLEAN_TRUE; - // broadcast not signal, because this condition is also used for other purposes - object_cond_broadcast(&thiz->mObject); - object_unlock_exclusive(&thiz->mObject); - break; - } - if (thiz->m3DCommit.mWaiting) { - thiz->m3DCommit.mWaiting = 0; - ++thiz->m3DCommit.mGeneration; - // There might be more than one thread blocked in Commit, so wake them all - object_cond_broadcast(&thiz->mObject); - // here is where we would process the enqueued 3D commands - } - // unsigned instanceMask = thiz->mEngine.mInstanceMask; // for debugger - unsigned changedMask = thiz->mEngine.mChangedMask; - thiz->mEngine.mChangedMask = 0; - object_unlock_exclusive(&thiz->mObject); - - // now we know which objects exist, and which of those have changes - - unsigned combinedMask = changedMask /* | instanceMask for debugger */; - while (combinedMask) { - unsigned i = ctz(combinedMask); - assert(MAX_INSTANCE > i); - combinedMask &= ~(1 << i); - IObject *instance = (IObject *) thiz->mEngine.mInstances[i]; - // Could be NULL during construct or destroy - if (NULL == instance) { - continue; - } - - object_lock_exclusive(instance); - unsigned attributesMask = instance->mAttributesMask; - instance->mAttributesMask = 0; - - switch (IObjectToObjectID(instance)) { - case SL_OBJECTID_AUDIOPLAYER: - // do something here - object_unlock_exclusive(instance); -#ifdef USE_SNDFILE - if (attributesMask & (ATTR_POSITION | ATTR_TRANSPORT)) { - CAudioPlayer *audioPlayer = (CAudioPlayer *) instance; - audioPlayerTransportUpdate(audioPlayer); - } -#endif - break; - - default: - object_unlock_exclusive(instance); - break; - } - } - } - return NULL; -} diff --git a/wilhelm/src/trace.c b/wilhelm/src/trace.c deleted file mode 100644 index 32ab0803..00000000 --- a/wilhelm/src/trace.c +++ /dev/null @@ -1,154 +0,0 @@ -/* - * 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. - */ - -/* trace debugging */ - -#include "sles_allinclusive.h" - -#ifdef USE_TRACE - -// This should be the only global variable -static unsigned slTraceEnabled = SL_TRACE_DEFAULT; - - -void slTraceSetEnabled(unsigned enabled) -{ - slTraceEnabled = enabled; -} - - -void slTraceEnterGlobal(const char *function) -{ - if (SL_TRACE_ENTER & slTraceEnabled) { - SL_LOGD("Entering %s", function); - } -} - - -void slTraceLeaveGlobal(const char *function, SLresult result) -{ - if (SL_RESULT_SUCCESS == result) { - if (SL_TRACE_LEAVE_SUCCESS & slTraceEnabled) { - SL_LOGD("Leaving %s", function); - } - } else { - if (SL_TRACE_LEAVE_FAILURE & slTraceEnabled) { - const char *str = slesutResultToString(result); - if (NULL != str) { - SL_LOGW("Leaving %s (%s)", function, str); - } else { - SL_LOGW("Leaving %s (0x%X)", function, result); - } - } - } -} - - -void slTraceEnterInterface(const char *function) -{ - if (!(SL_TRACE_ENTER & slTraceEnabled)) { - return; - } - if (*function == 'I') { - ++function; - } - const char *underscore = function; - while (*underscore != '\0') { - if (*underscore == '_') { - if (/*(strcmp(function, "BufferQueue_Enqueue") && - strcmp(function, "BufferQueue_GetState") && - strcmp(function, "OutputMixExt_FillBuffer")) &&*/ - true) { - SL_LOGD("Entering %.*s::%s", (int) (underscore - function), function, - &underscore[1]); - } - return; - } - ++underscore; - } - SL_LOGV("Entering %s", function); -} - - -void slTraceLeaveInterface(const char *function, SLresult result) -{ - if (!((SL_TRACE_LEAVE_SUCCESS | SL_TRACE_LEAVE_FAILURE) & slTraceEnabled)) { - return; - } - if (*function == 'I') { - ++function; - } - const char *underscore = function; - while (*underscore != '\0') { - if (*underscore == '_') { - break; - } - ++underscore; - } - if (SL_RESULT_SUCCESS == result) { - if (SL_TRACE_LEAVE_SUCCESS & slTraceEnabled) { - if (*underscore == '_') { - SL_LOGD("Leaving %.*s::%s", (int) (underscore - function), function, - &underscore[1]); - } else { - SL_LOGD("Leaving %s", function); - } - } - } else { - if (SL_TRACE_LEAVE_FAILURE & slTraceEnabled) { - const char *str = slesutResultToString(result); - if (*underscore == '_') { - if (NULL != str) { - SL_LOGW("Leaving %.*s::%s (%s)", (int) (underscore - function), function, - &underscore[1], str); - } else { - SL_LOGW("Leaving %.*s::%s (0x%X)", (int) (underscore - function), function, - &underscore[1], result); - } - } else { - if (NULL != str) { - SL_LOGW("Leaving %s (%s)", function, str); - } else { - SL_LOGW("Leaving %s (0x%X)", function, result); - } - } - } - } -} - - -void slTraceEnterInterfaceVoid(const char *function) -{ - if (SL_TRACE_ENTER & slTraceEnabled) { - slTraceEnterInterface(function); - } -} - - -void slTraceLeaveInterfaceVoid(const char *function) -{ - if (SL_TRACE_LEAVE_VOID & slTraceEnabled) { - slTraceLeaveInterface(function, SL_RESULT_SUCCESS); - } -} - -#else - -void slTraceSetEnabled(unsigned enabled) -{ -} - -#endif // USE_TRACE diff --git a/wilhelm/src/trace.h b/wilhelm/src/trace.h deleted file mode 100644 index 242a4093..00000000 --- a/wilhelm/src/trace.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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. - */ - -// Trace debugging - -// Always defined, but may be a no-op if trace support is disabled at compile-time -extern void slTraceSetEnabled(unsigned enabled); - -#define SL_TRACE_ENTER 0x1 -#define SL_TRACE_LEAVE_FAILURE 0x2 -#define SL_TRACE_LEAVE_VOID 0x4 -#define SL_TRACE_LEAVE_SUCCESS 0x8 -#define SL_TRACE_LEAVE (SL_TRACE_LEAVE_FAILURE | SL_TRACE_LEAVE_VOID | \ - SL_TRACE_LEAVE_SUCCESS) -#define SL_TRACE_ALL (SL_TRACE_ENTER | SL_TRACE_LEAVE) -#ifndef SL_TRACE_DEFAULT -#define SL_TRACE_DEFAULT (SL_TRACE_LEAVE_FAILURE) -#endif - -#ifndef USE_TRACE - -#define SL_ENTER_GLOBAL SLresult result; -#define SL_LEAVE_GLOBAL return result; -#define SL_ENTER_INTERFACE SLresult result; -#define SL_LEAVE_INTERFACE return result; -#define SL_ENTER_INTERFACE_VOID -#define SL_LEAVE_INTERFACE_VOID return; - -#define XA_ENTER_GLOBAL XAresult result; -#define XA_LEAVE_GLOBAL return result; -#define XA_ENTER_INTERFACE XAresult result; -#define XA_LEAVE_INTERFACE return result; - -#else - -extern void slTraceEnterGlobal(const char *function); -extern void slTraceLeaveGlobal(const char *function, SLresult result); -extern void slTraceEnterInterface(const char *function); -extern void slTraceLeaveInterface(const char *function, SLresult result); -extern void slTraceEnterInterfaceVoid(const char *function); -extern void slTraceLeaveInterfaceVoid(const char *function); -#define SL_ENTER_GLOBAL SLresult result; slTraceEnterGlobal(__FUNCTION__); -#define SL_LEAVE_GLOBAL slTraceLeaveGlobal(__FUNCTION__, result); return result; -#define SL_ENTER_INTERFACE SLresult result; slTraceEnterInterface(__FUNCTION__); -#define SL_LEAVE_INTERFACE slTraceLeaveInterface(__FUNCTION__, result); return result; -#define SL_ENTER_INTERFACE_VOID slTraceEnterInterfaceVoid(__FUNCTION__); -#define SL_LEAVE_INTERFACE_VOID slTraceLeaveInterfaceVoid(__FUNCTION__); return; - -#define XA_ENTER_GLOBAL XAresult result; slTraceEnterGlobal(__FUNCTION__); -#define XA_LEAVE_GLOBAL slTraceLeaveGlobal(__FUNCTION__, result); return result; -#define XA_ENTER_INTERFACE XAresult result; slTraceEnterInterface(__FUNCTION__); -#define XA_LEAVE_INTERFACE slTraceLeaveInterface(__FUNCTION__, result); return result; - -#endif diff --git a/wilhelm/src/ut/OpenSLESUT.c b/wilhelm/src/ut/OpenSLESUT.c deleted file mode 100644 index d6c2114b..00000000 --- a/wilhelm/src/ut/OpenSLESUT.c +++ /dev/null @@ -1,153 +0,0 @@ -/* - * 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. - */ - -/** \file OpenSLESUT.c OpenSL ES Utility Toolkit */ - -#include <SLES/OpenSLES.h> -#ifdef ANDROID -#include <SLES/OpenSLES_Android.h> -#endif -#include "OpenSLESUT.h" -#include <stdio.h> -#include <string.h> - - -/** \brief Maps an interface ID to its display name */ - -typedef struct -{ - const SLInterfaceID *iid; ///< The interface ID - const char *name; ///< The display name -} Pair; - -// ## is token concatenation e.g. a##b becomes ab -// # is stringize operator to convert a symbol to a string constant e.g. #a becomes "a" - -#define _(x) { &SL_IID_##x, #x } - -/** \brief Array of mappings from interface IDs to display names */ - -static Pair pairs[] = { - _(3DCOMMIT), - _(3DDOPPLER), - _(3DGROUPING), - _(3DLOCATION), - _(3DMACROSCOPIC), - _(3DSOURCE), - _(AUDIODECODERCAPABILITIES), - _(AUDIOENCODER), - _(AUDIOENCODERCAPABILITIES), - _(AUDIOIODEVICECAPABILITIES), - _(BASSBOOST), - _(BUFFERQUEUE), - _(DEVICEVOLUME), - _(DYNAMICINTERFACEMANAGEMENT), - _(DYNAMICSOURCE), - _(EFFECTSEND), - _(ENGINE), - _(ENGINECAPABILITIES), - _(ENVIRONMENTALREVERB), - _(EQUALIZER), - _(LED), - _(METADATAEXTRACTION), - _(METADATATRAVERSAL), - _(MIDIMESSAGE), - _(MIDIMUTESOLO), - _(MIDITEMPO), - _(MIDITIME), - _(MUTESOLO), - _(NULL), - _(OBJECT), - _(OUTPUTMIX), - _(PITCH), - _(PLAY), - _(PLAYBACKRATE), - _(PREFETCHSTATUS), - _(PRESETREVERB), - _(RATEPITCH), - _(RECORD), - _(SEEK), - _(THREADSYNC), - _(VIBRA), - _(VIRTUALIZER), - _(VISUALIZATION), - _(VOLUME), -#if 0 // ifdef USE_OUTPUTMIXEXT - _(OUTPUTMIXEXT), -#endif -#ifdef ANDROID - _(ANDROIDEFFECT), - _(ANDROIDEFFECTCAPABILITIES), - _(ANDROIDEFFECTSEND), - _(ANDROIDCONFIGURATION), - _(ANDROIDSIMPLEBUFFERQUEUE) -#endif -}; - - -/** \brief Print an interface ID in human-readable format */ - -void slesutPrintIID(SLInterfaceID iid) -{ - Pair *p; - const Pair *end = &pairs[sizeof(pairs)/sizeof(pairs[0])]; - for (p = pairs; p != end; ++p) { - if (!memcmp(*p->iid, iid, sizeof(struct SLInterfaceID_))) { - printf("SL_IID_%s = ", p->name); - break; - } - } - printf( - "{ 0x%08X, 0x%04X, 0x%04X, 0x%04X, { 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X } }\n", - (unsigned) iid->time_low, iid->time_mid, iid->time_hi_and_version, iid->clock_seq, - iid->node[0], iid->node[1], iid->node[2], iid->node[3], iid->node[4], iid->node[5]); -} - - -/** \brief Print an array of interface IDs in human-readable format, - * including whether they are required or optional - */ - -void slesutPrintIIDs(SLInterfaceID *pInterfaceIds, SLboolean *pInterfaceRequired, - unsigned numInterfaces) -{ - unsigned i; - for (i = 0; i < numInterfaces; ++i) { - printf("interfaces[%u]=", i); - slesutPrintIID(pInterfaceIds[i]); - printf(" %s\n", (unsigned) pInterfaceRequired[i] ? "required" : "optional"); - } -} - - -/** \brief Convert an object ID to a string or NULL. */ - -const char *slesutObjectIDToString(SLuint32 objectID) -{ - static const char * const objectIDstrings[10] = { - "SL_OBJECTID_ENGINE", - "SL_OBJECTID_LEDDEVICE", - "SL_OBJECTID_VIBRADEVICE", - "SL_OBJECTID_AUDIOPLAYER", - "SL_OBJECTID_AUDIORECORDER", - "SL_OBJECTID_MIDIPLAYER", - "SL_OBJECTID_LISTENER", - "SL_OBJECTID_3DGROUP", - "SL_OBJECTID_OUTPUTMIX", - "SL_OBJECTID_METADATAEXTRACTOR" - }; - return (0x1001 <= objectID) && (objectID <= 0x100A) ? objectIDstrings[objectID - 0x1001] : NULL; -} diff --git a/wilhelm/src/ut/OpenSLESUT.h b/wilhelm/src/ut/OpenSLESUT.h deleted file mode 100644 index 59f38ceb..00000000 --- a/wilhelm/src/ut/OpenSLESUT.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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. - */ - -/** \file OpenSLESUT.h OpenSL ES Utility Toolkit */ - -#ifdef __cplusplus -extern "C" { -#endif - -extern void slesutPrintIID(SLInterfaceID iid); -extern const char *slesutResultToString(SLresult result); -extern const char *slesutObjectIDToString(SLuint32 objectID); - -#ifdef __cplusplus -} -#endif diff --git a/wilhelm/src/ut/slesutResult.c b/wilhelm/src/ut/slesutResult.c deleted file mode 100644 index 03c0f70f..00000000 --- a/wilhelm/src/ut/slesutResult.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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. - */ - -#include <stdlib.h> -#include <SLES/OpenSLES.h> -#include "OpenSLESUT.h" - - -/** \brief Maximum result return code */ - -#define SLESUT_RESULT_MAX (SL_RESULT_CONTROL_LOST + 1) - -/** \brief Array of strings correponding to each result code */ - -static const char * const slesutResultStrings[SLESUT_RESULT_MAX] = { - "SL_RESULT_SUCCESS", - "SL_RESULT_PRECONDITIONS_VIOLATED", - "SL_RESULT_PARAMETER_INVALID", - "SL_RESULT_MEMORY_FAILURE", - "SL_RESULT_RESOURCE_ERROR", - "SL_RESULT_RESOURCE_LOST", - "SL_RESULT_IO_ERROR", - "SL_RESULT_BUFFER_INSUFFICIENT", - "SL_RESULT_CONTENT_CORRUPTED", - "SL_RESULT_CONTENT_UNSUPPORTED", - "SL_RESULT_CONTENT_NOT_FOUND", - "SL_RESULT_PERMISSION_DENIED", - "SL_RESULT_FEATURE_UNSUPPORTED", - "SL_RESULT_INTERNAL_ERROR", - "SL_RESULT_UNKNOWN_ERROR", - "SL_RESULT_OPERATION_ABORTED", - "SL_RESULT_CONTROL_LOST" -}; - - -/** \brief Convert a result code to a string or NULL. */ - -const char *slesutResultToString(SLresult result) -{ - // note that SLresult is unsigned - return result < SLESUT_RESULT_MAX ? slesutResultStrings[result] : NULL; -} diff --git a/wilhelm/src/xa_entry.c b/wilhelm/src/xa_entry.c deleted file mode 100644 index b1cddd54..00000000 --- a/wilhelm/src/xa_entry.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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. - */ - -#include "sles_allinclusive.h" - -/** \brief xaCreateEngine Function */ - -XA_API XAresult XAAPIENTRY xaCreateEngine(XAObjectItf *pEngine, XAuint32 numOptions, - const XAEngineOption *pEngineOptions, XAuint32 numInterfaces, - const XAInterfaceID *pInterfaceIds, const XAboolean *pInterfaceRequired) -{ - XA_ENTER_GLOBAL - - result = liCreateEngine((SLObjectItf *) pEngine, numOptions, - (const SLEngineOption *) pEngineOptions, numInterfaces, - (const SLInterfaceID *) pInterfaceIds, (const SLboolean *) pInterfaceRequired, - objectIDtoClass(XA_OBJECTID_ENGINE)); - - XA_LEAVE_GLOBAL -} - - -/** \brief xaQueryNumSupportedEngineInterfaces Function */ - -XA_API XAresult XAAPIENTRY xaQueryNumSupportedEngineInterfaces(XAuint32 *pNumSupportedInterfaces) -{ - XA_ENTER_GLOBAL - - result = liQueryNumSupportedInterfaces(pNumSupportedInterfaces, - objectIDtoClass(XA_OBJECTID_ENGINE)); - - XA_LEAVE_GLOBAL -} - - -/** \brief xaQuerySupportedEngineInterfaces Function */ - -XA_API XAresult XAAPIENTRY xaQuerySupportedEngineInterfaces(XAuint32 index, - XAInterfaceID *pInterfaceId) -{ - XA_ENTER_GLOBAL - - result = liQuerySupportedInterfaces(index, (SLInterfaceID *) pInterfaceId, - objectIDtoClass(XA_OBJECTID_ENGINE)); - - XA_LEAVE_GLOBAL -} diff --git a/wilhelm/src/xa_iid.c b/wilhelm/src/xa_iid.c deleted file mode 100644 index 0f51ae59..00000000 --- a/wilhelm/src/xa_iid.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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. - */ - -#include "sles_allinclusive.h" - -#ifdef __cplusplus -extern "C" { -#endif - -// OpenMAX AL 1.0.1 interfaces - -const XAInterfaceID XA_IID_AUDIODECODERCAPABILITIES = - (XAInterfaceID) &SL_IID_array[MPH_XAAUDIODECODERCAPABILITIES]; -const XAInterfaceID XA_IID_AUDIOENCODER = (XAInterfaceID) &SL_IID_array[MPH_XAAUDIOENCODER]; -const XAInterfaceID XA_IID_AUDIOENCODERCAPABILITIES = - (XAInterfaceID) &SL_IID_array[MPH_XAAUDIOENCODERCAPABILITIES]; -const XAInterfaceID XA_IID_AUDIOIODEVICECAPABILITIES = - (XAInterfaceID) &SL_IID_array[MPH_XAAUDIOIODEVICECAPABILITIES]; -const XAInterfaceID XA_IID_CAMERA = (XAInterfaceID) &SL_IID_array[MPH_XACAMERA]; -const XAInterfaceID XA_IID_CAMERACAPABILITIES = - (XAInterfaceID) &SL_IID_array[MPH_XACAMERACAPABILITIES]; -const XAInterfaceID XA_IID_CONFIGEXTENSION = (XAInterfaceID) &SL_IID_array[MPH_XACONFIGEXTENSION]; -const XAInterfaceID XA_IID_DEVICEVOLUME = (XAInterfaceID) &SL_IID_array[MPH_XADEVICEVOLUME]; -const XAInterfaceID XA_IID_DYNAMICINTERFACEMANAGEMENT = - (XAInterfaceID) &SL_IID_array[MPH_XADYNAMICINTERFACEMANAGEMENT]; -const XAInterfaceID XA_IID_DYNAMICSOURCE = (XAInterfaceID) &SL_IID_array[MPH_XADYNAMICSOURCE]; -const XAInterfaceID XA_IID_ENGINE = (XAInterfaceID) &SL_IID_array[MPH_XAENGINE]; -const XAInterfaceID XA_IID_EQUALIZER = (XAInterfaceID) &SL_IID_array[MPH_XAEQUALIZER]; -const XAInterfaceID XA_IID_IMAGECONTROLS = (XAInterfaceID) &SL_IID_array[MPH_XAIMAGECONTROLS]; -const XAInterfaceID XA_IID_IMAGEDECODERCAPABILITIES = - (XAInterfaceID) &SL_IID_array[MPH_XAIMAGEDECODERCAPABILITIES]; -const XAInterfaceID XA_IID_IMAGEEFFECTS = (XAInterfaceID) &SL_IID_array[MPH_XAIMAGEEFFECTS]; -const XAInterfaceID XA_IID_IMAGEENCODER = (XAInterfaceID) &SL_IID_array[MPH_XAIMAGEENCODER]; -const XAInterfaceID XA_IID_IMAGEENCODERCAPABILITIES = - (XAInterfaceID) &SL_IID_array[MPH_XAIMAGEENCODERCAPABILITIES]; -const XAInterfaceID XA_IID_LED = (XAInterfaceID) &SL_IID_array[MPH_XALED]; -const XAInterfaceID XA_IID_METADATAEXTRACTION = - (XAInterfaceID) &SL_IID_array[MPH_XAMETADATAEXTRACTION]; -const XAInterfaceID XA_IID_METADATAINSERTION = - (XAInterfaceID) &SL_IID_array[MPH_XAMETADATAINSERTION]; -const XAInterfaceID XA_IID_METADATATRAVERSAL = - (XAInterfaceID) &SL_IID_array[MPH_XAMETADATATRAVERSAL]; -const XAInterfaceID XA_IID_NULL = (XAInterfaceID) &SL_IID_array[MPH_XANULL]; -const XAInterfaceID XA_IID_OBJECT = (XAInterfaceID) &SL_IID_array[MPH_XAOBJECT]; -const XAInterfaceID XA_IID_OUTPUTMIX = (XAInterfaceID) &SL_IID_array[MPH_XAOUTPUTMIX]; -const XAInterfaceID XA_IID_PLAY = (XAInterfaceID) &SL_IID_array[MPH_XAPLAY]; -const XAInterfaceID XA_IID_PLAYBACKRATE = (XAInterfaceID) &SL_IID_array[MPH_XAPLAYBACKRATE]; -const XAInterfaceID XA_IID_PREFETCHSTATUS = (XAInterfaceID) &SL_IID_array[MPH_XAPREFETCHSTATUS]; -const XAInterfaceID XA_IID_RADIO = (XAInterfaceID) &SL_IID_array[MPH_XARADIO]; -const XAInterfaceID XA_IID_RDS = (XAInterfaceID) &SL_IID_array[MPH_XARDS]; -const XAInterfaceID XA_IID_RECORD = (XAInterfaceID) &SL_IID_array[MPH_XARECORD]; -const XAInterfaceID XA_IID_SEEK = (XAInterfaceID) &SL_IID_array[MPH_XASEEK]; -const XAInterfaceID XA_IID_SNAPSHOT = (XAInterfaceID) &SL_IID_array[MPH_XASNAPSHOT]; -const XAInterfaceID XA_IID_STREAMINFORMATION = - (XAInterfaceID) &SL_IID_array[MPH_XASTREAMINFORMATION]; -const XAInterfaceID XA_IID_THREADSYNC = (XAInterfaceID) &SL_IID_array[MPH_XATHREADSYNC]; -const XAInterfaceID XA_IID_VIBRA = (XAInterfaceID) &SL_IID_array[MPH_XAVIBRA]; -const XAInterfaceID XA_IID_VIDEODECODERCAPABILITIES = - (XAInterfaceID) &SL_IID_array[MPH_XAVIDEODECODERCAPABILITIES]; -const XAInterfaceID XA_IID_VIDEOENCODER = (XAInterfaceID) &SL_IID_array[MPH_XAVIDEOENCODER]; -const XAInterfaceID XA_IID_VIDEOENCODERCAPABILITIES = - (XAInterfaceID) &SL_IID_array[MPH_XAVIDEOENCODERCAPABILITIES]; -const XAInterfaceID XA_IID_VIDEOPOSTPROCESSING = - (XAInterfaceID) &SL_IID_array[MPH_XAVIDEOPOSTPROCESSING]; -const XAInterfaceID XA_IID_VOLUME = (XAInterfaceID) &SL_IID_array[MPH_XAVOLUME]; - -// OpenMAX AL 1.0.1 Android API level 12 extended interfaces -// GUID and MPH are shared by SL and XA -const XAInterfaceID XA_IID_ANDROIDBUFFERQUEUESOURCE = - (XAInterfaceID) &SL_IID_array[MPH_ANDROIDBUFFERQUEUESOURCE]; - -#ifdef __cplusplus -} -#endif diff --git a/wilhelm/tests/Android.mk b/wilhelm/tests/Android.mk deleted file mode 100644 index 9818656f..00000000 --- a/wilhelm/tests/Android.mk +++ /dev/null @@ -1,39 +0,0 @@ -# Build the unit tests. -LOCAL_PATH:= $(call my-dir) -include $(CLEAR_VARS) - -test_src_files := \ - mimeUri_test.cpp \ - -shared_libraries := \ - libutils \ - libOpenSLES \ - libstlport - -static_libraries := \ - libgtest \ - libgtest_main - -c_includes := \ - bionic \ - bionic/libstdc++/include \ - external/gtest/include \ - $(call include-path-for, wilhelm) \ - external/stlport/stlport - -module_tags := tests - -$(foreach file,$(test_src_files), \ - $(eval include $(CLEAR_VARS)) \ - $(eval LOCAL_SHARED_LIBRARIES := $(shared_libraries)) \ - $(eval LOCAL_STATIC_LIBRARIES := $(static_libraries)) \ - $(eval LOCAL_C_INCLUDES := $(c_includes)) \ - $(eval LOCAL_SRC_FILES := $(file)) \ - $(eval LOCAL_MODULE := libopenslestests) \ - $(eval LOCAL_MODULE_PATH := $(TARGET_OUT_DATA)/nativetest) \ - $(eval LOCAL_MODULE_TAGS := $(module_tags)) \ - $(eval include $(BUILD_EXECUTABLE)) \ -) - -# Build the manual test programs. -include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/wilhelm/tests/automated/Android.mk b/wilhelm/tests/automated/Android.mk deleted file mode 100644 index 76a2401b..00000000 --- a/wilhelm/tests/automated/Android.mk +++ /dev/null @@ -1,39 +0,0 @@ -# Build the unit tests. -LOCAL_PATH:= $(call my-dir) -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - bionic \ - bionic/libstdc++/include \ - external/gtest/include \ - $(call include-path-for, wilhelm) \ - external/stlport/stlport \ - $(call include-path-for, wilhelm-ut) - -LOCAL_SRC_FILES:= \ - BufferQueue_test.cpp - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES \ - libstlport - -LOCAL_STATIC_LIBRARIES := \ - libOpenSLESUT \ - libgtest - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX - #LOCAL_SHARED_LIBRARIES += librt -endif - -LOCAL_MODULE:= BufferQueue_test - -LOCAL_MODULE_PATH := $(TARGET_OUT_DATA)/nativetest - -include $(BUILD_EXECUTABLE) - -# Build the manual test programs. -include $(call all-subdir-makefiles) diff --git a/wilhelm/tests/automated/BufferQueue_test.cpp b/wilhelm/tests/automated/BufferQueue_test.cpp deleted file mode 100644 index 123e481a..00000000 --- a/wilhelm/tests/automated/BufferQueue_test.cpp +++ /dev/null @@ -1,473 +0,0 @@ -/* - * 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. - */ - -/** \file BufferQueue_test.cpp */ - -#define LOG_NDEBUG 0 -#define LOG_TAG "BufferQueue_test" - -#ifdef ANDROID -#include <utils/Log.h> -#else -#define ALOGV printf -#endif - -#include <assert.h> -#include <math.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <SLES/OpenSLES.h> -#include "OpenSLESUT.h" -#include <gtest/gtest.h> - -typedef struct { - short left; - short right; -} stereo; - -// volume of sine wave in range 0.0 to 1.0 -static float gVolume = 1.0f; - -// 1 second of stereo audio at 44.1 kHz -static stereo stereoBuffer1[44100 * 1]; -static const SLuint32 invalidNumBuffers[] = { 0, 0xFFFFFFFF, 0x80000000, 0x10002, 0x102, - 0x101, 0x100 }; -static const SLuint32 validNumBuffers[] = { 1, 2, 3, 4, 5, 6, 7, 8, 255 }; - -//----------------------------------------------------------------- -/* Checks for error. If any errors exit the application! */ -void CheckErr(SLresult res) { - if (SL_RESULT_SUCCESS != res) { - const char *str = slesutResultToString(res); - if (NULL == str) - str = "unknown"; - fprintf(stderr, "CheckErr failure: %s (0x%x), exiting\n", str, res); - //Fail the test case - FAIL(); - } -} - -static const SLInterfaceID ids[1] = { SL_IID_BUFFERQUEUE }; -static const SLboolean flags[1] = { SL_BOOLEAN_TRUE }; -static const SLInterfaceID ids_mutesolo[2] = { SL_IID_BUFFERQUEUE, SL_IID_MUTESOLO }; -static const SLboolean flags_mutesolo[2] = { SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE }; -static const SLInterfaceID ids_seek[2] = { SL_IID_BUFFERQUEUE, SL_IID_SEEK }; -static const SLboolean flags_seek[2] = { SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE }; - -// The fixture for testing class BufferQueue -class TestBufferQueue: public ::testing::Test { -public: - SLresult res; - SLObjectItf outputmixObject; - SLObjectItf engineObject; - - SLDataSource audiosrc; - SLDataSink audiosnk; - SLDataFormat_PCM pcm; - SLDataLocator_OutputMix locator_outputmix; - SLDataLocator_BufferQueue locator_bufferqueue; - SLBufferQueueItf playerBufferQueue; - SLBufferQueueState bufferqueueState; - SLPlayItf playerPlay; - SLObjectItf playerObject; - SLEngineItf engineEngine; - SLuint32 playerState; - -protected: - TestBufferQueue() { - } - - virtual ~TestBufferQueue() { - - } - - /*Test setup*/ - virtual void SetUp() { - - // create engine - res = slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL); - CheckErr(res); - res = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE); - CheckErr(res); - res = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine); - CheckErr(res); - - // create output mix - res = (*engineEngine)->CreateOutputMix(engineEngine, &outputmixObject, 0, NULL, NULL); - CheckErr(res); - res = (*outputmixObject)->Realize(outputmixObject, SL_BOOLEAN_FALSE); - CheckErr(res); - - locator_bufferqueue.locatorType = SL_DATALOCATOR_BUFFERQUEUE; - locator_bufferqueue.numBuffers = 0; - locator_outputmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; - locator_outputmix.outputMix = outputmixObject; - - pcm.formatType = SL_DATAFORMAT_PCM; - pcm.numChannels = 2; - pcm.samplesPerSec = SL_SAMPLINGRATE_44_1; - pcm.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_16; - pcm.containerSize = 16; - pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT; - pcm.endianness = SL_BYTEORDER_LITTLEENDIAN; - - audiosrc.pLocator = &locator_bufferqueue; - audiosrc.pFormat = &pcm; - audiosnk.pLocator = &locator_outputmix; - audiosnk.pFormat = NULL; - - // initialize the test tone to be a sine sweep from 441 Hz to 882 Hz - unsigned nframes = sizeof(stereoBuffer1) / sizeof(stereoBuffer1[0]); - float nframes_ = (float) nframes; - SLuint32 i; - for (i = 0; i < nframes; ++i) { - float i_ = (float) i; - float pcm_ = sin((i_ * (1.0f + 0.5f * (i_ / nframes_)) * 0.01 * M_PI * 2.0)); - int pcm = (int) (pcm_ * 32766.0 * gVolume); - ASSERT_TRUE(-32768 <= pcm && pcm <= 32767) << "pcm out of bound " << pcm; - stereoBuffer1[i].left = pcm; - stereoBuffer1[nframes - 1 - i].right = pcm; - } - } - - virtual void TearDown() { - // Clean up the mixer and the engine - // (must be done in that order, and after player destroyed) - if (outputmixObject){ - (*outputmixObject)->Destroy(outputmixObject); - outputmixObject = NULL; - } - if (engineObject){ - (*engineObject)->Destroy(engineObject); - engineObject = NULL; - } - } - - void DestroyPlayer() { - if (playerObject){ - //printf("destroy player\n"); - (*playerObject)->Destroy(playerObject); - playerObject = NULL; - } - } - - /* Test case for creating audio player with various invalid values for numBuffers*/ - void InvalidBuffer() { - - for (unsigned i = 0; i < sizeof(invalidNumBuffers) / sizeof(invalidNumBuffers[0]); ++i) { - SLuint32 numBuffers = invalidNumBuffers[i]; - - locator_bufferqueue.numBuffers = numBuffers; - //printf("create audio player - invalid\n"); - SLresult result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, - &audiosrc, &audiosnk, 1, ids, flags); - ASSERT_EQ(SL_RESULT_PARAMETER_INVALID, result); - ASSERT_EQ(NULL, playerObject); - - } - } - - /*Prepare the buffer*/ - void PrepareValidBuffer(SLuint32 numBuffers) { - - locator_bufferqueue.numBuffers = numBuffers; - //printf("create audio player - valid\n"); - res = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audiosrc, &audiosnk, - 1, ids, flags); - CheckErr(res); - res = (*playerObject)->Realize(playerObject, SL_BOOLEAN_FALSE); - CheckErr(res); - // get the play interface - res = (*playerObject)->GetInterface(playerObject, SL_IID_PLAY, &playerPlay); - CheckErr(res); - // verify that player is initially stopped - res = (*playerPlay)->GetPlayState(playerPlay, &playerState); - CheckErr(res); - ASSERT_EQ(SL_PLAYSTATE_STOPPED, playerState); - - // get the buffer queue interface - res = (*playerObject)->GetInterface(playerObject, SL_IID_BUFFERQUEUE, &playerBufferQueue); - CheckErr(res); - - // verify that buffer queue is initially empty - res = (*playerBufferQueue)->GetState(playerBufferQueue, &bufferqueueState); - CheckErr(res); - ASSERT_EQ((SLuint32) 0, bufferqueueState.count); - ASSERT_EQ((SLuint32) 0, bufferqueueState.playIndex); - } - - void EnqueueMaxBuffer(SLuint32 numBuffers) { - SLuint32 j; - - for (j = 0; j < numBuffers; ++j) { - res = (*playerBufferQueue)->Enqueue(playerBufferQueue, "test", 4); - CheckErr(res); - // verify that each buffer is enqueued properly and increments the buffer count - res = (*playerBufferQueue)->GetState(playerBufferQueue, &bufferqueueState); - CheckErr(res); - ASSERT_EQ(j + 1, bufferqueueState.count); - ASSERT_EQ((SLuint32) 0, bufferqueueState.playIndex); - } - } - - void EnqueueExtraBuffer(SLuint32 numBuffers) { - // enqueue one more buffer and make sure it fails - res = (*playerBufferQueue)->Enqueue(playerBufferQueue, "test", 4); - ASSERT_EQ(SL_RESULT_BUFFER_INSUFFICIENT, res); - // verify that the failed enqueue did not affect the buffer count - res = (*playerBufferQueue)->GetState(playerBufferQueue, &bufferqueueState); - CheckErr(res); - ASSERT_EQ(numBuffers, bufferqueueState.count); - ASSERT_EQ((SLuint32) 0, bufferqueueState.playIndex); - } - - void SetPlayerState(SLuint32 state) { - res = (*playerPlay)->SetPlayState(playerPlay, state); - CheckErr(res); - //verify the state can set correctly - GetPlayerState(state); - } - - void GetPlayerState(SLuint32 state) { - res = (*playerPlay)->GetPlayState(playerPlay, &playerState); - CheckErr(res); - ASSERT_EQ(state, playerState); - } - - void ClearQueue() { - // now clear the buffer queue - res = (*playerBufferQueue)->Clear(playerBufferQueue); - CheckErr(res); - // make sure the clear works - res = (*playerBufferQueue)->GetState(playerBufferQueue, &bufferqueueState); - CheckErr(res); - ASSERT_EQ((SLuint32) 0, bufferqueueState.count); - ASSERT_EQ((SLuint32) 0, bufferqueueState.playIndex); - } - - void CheckBufferCount(SLuint32 ExpectedCount, SLuint32 ExpectedPlayIndex) { - // changing the play state should not affect the buffer count - res = (*playerBufferQueue)->GetState(playerBufferQueue, &bufferqueueState); - CheckErr(res); - ASSERT_EQ(ExpectedCount, bufferqueueState.count); - ASSERT_EQ(ExpectedPlayIndex, bufferqueueState.playIndex); - } - - void PlayBufferQueue() { - // enqueue a buffer - res = (*playerBufferQueue)->Enqueue(playerBufferQueue, stereoBuffer1, - sizeof(stereoBuffer1)); - CheckErr(res); - // set play state to playing - res = (*playerPlay)->SetPlayState(playerPlay, SL_PLAYSTATE_PLAYING); - CheckErr(res); - // state should be playing immediately after enqueue - res = (*playerPlay)->GetPlayState(playerPlay, &playerState); - CheckErr(res); - ASSERT_EQ(SL_PLAYSTATE_PLAYING, playerState); - // buffer should still be on the queue - res = (*playerBufferQueue)->GetState(playerBufferQueue, &bufferqueueState); - CheckErr(res); - ASSERT_EQ((SLuint32) 1, bufferqueueState.count); - ASSERT_EQ((SLuint32) 0, bufferqueueState.playIndex); - //ALOGV("Before 1.5 sec"); - // wait 1.5 seconds - usleep(1500000); - //ALOGV("After 1.5 sec"); - // state should still be playing - res = (*playerPlay)->GetPlayState(playerPlay, &playerState); - //ALOGV("GetPlayState"); - CheckErr(res); - ASSERT_EQ(SL_PLAYSTATE_PLAYING, playerState); - // buffer should be removed from the queue - res = (*playerBufferQueue)->GetState(playerBufferQueue, &bufferqueueState); - CheckErr(res); - ASSERT_EQ((SLuint32) 0, bufferqueueState.count); - ASSERT_EQ((SLuint32) 1, bufferqueueState.playIndex); - //ALOGV("TestEnd"); - } -}; - -TEST_F(TestBufferQueue, testInvalidBuffer){ - //ALOGV("Test Fixture: InvalidBuffer"); - InvalidBuffer(); -} - -TEST_F(TestBufferQueue, testMuteSolo) { - // create audio player with buffer queue data source in stereo PCM format and ask for mute solo - locator_bufferqueue.numBuffers = 1; - SLresult result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audiosrc, - &audiosnk, 2, ids_mutesolo, flags_mutesolo); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - ASSERT_TRUE(NULL != playerObject); - DestroyPlayer(); - // create audio player with buffer queue data source in mono PCM format and ask for mute solo - pcm.numChannels = 1; - pcm.channelMask = SL_SPEAKER_FRONT_CENTER; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audiosrc, &audiosnk, - 2, ids_mutesolo, flags_mutesolo); - ASSERT_EQ(SL_RESULT_FEATURE_UNSUPPORTED, result); - ASSERT_EQ(NULL, playerObject); - DestroyPlayer(); -} - -TEST_F(TestBufferQueue, testSeek) { - // can create audio player with buffer queue data source and ask for seek - locator_bufferqueue.numBuffers = 1; - SLresult result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, - &audiosrc, &audiosnk, 2, ids_seek, flags_seek); - ASSERT_EQ(SL_RESULT_FEATURE_UNSUPPORTED, result); - ASSERT_EQ(NULL, playerObject); - DestroyPlayer(); -} - -TEST_F(TestBufferQueue, testValidBuffer) { - for (unsigned i = 0; i < sizeof(validNumBuffers) / sizeof(validNumBuffers[0]); ++i) { - SLuint32 numBuffers = validNumBuffers[i]; - PrepareValidBuffer(numBuffers); - DestroyPlayer(); - } -} - -TEST_F(TestBufferQueue, testEnqueueMaxBuffer) { - for (unsigned i = 0; i < sizeof(validNumBuffers) / sizeof(validNumBuffers[0]); ++i) { - SLuint32 numBuffers = validNumBuffers[i]; - PrepareValidBuffer(numBuffers); - EnqueueMaxBuffer(numBuffers); - DestroyPlayer(); - } -} - -TEST_F(TestBufferQueue, testEnqueueExtraBuffer) { - for (unsigned i = 0; i < sizeof(validNumBuffers) / sizeof(validNumBuffers[0]); ++i) { - SLuint32 numBuffers = validNumBuffers[i]; - PrepareValidBuffer(numBuffers); - EnqueueMaxBuffer(numBuffers); - EnqueueExtraBuffer(numBuffers); - GetPlayerState(SL_PLAYSTATE_STOPPED); - DestroyPlayer(); - } -} - -TEST_F(TestBufferQueue, testEnqueueAtStopped) { - for (unsigned i = 0; i < sizeof(validNumBuffers) / sizeof(validNumBuffers[0]); ++i) { - SLuint32 numBuffers = validNumBuffers[i]; - PrepareValidBuffer(numBuffers); - SetPlayerState(SL_PLAYSTATE_STOPPED); - EnqueueMaxBuffer(numBuffers); - CheckBufferCount(numBuffers, (SLuint32) 0); - DestroyPlayer(); - } -} - -TEST_F(TestBufferQueue, testEnqueueAtPaused) { - for (unsigned i = 0; i < sizeof(validNumBuffers) / sizeof(validNumBuffers[0]); ++i) { - SLuint32 numBuffers = validNumBuffers[i]; - PrepareValidBuffer(numBuffers); - SetPlayerState(SL_PLAYSTATE_PAUSED); - EnqueueMaxBuffer(numBuffers); - CheckBufferCount(numBuffers, (SLuint32) 0); - DestroyPlayer(); - } -} - -TEST_F(TestBufferQueue, testClearQueue) { - for (unsigned i = 0; i < sizeof(validNumBuffers) / sizeof(validNumBuffers[0]); ++i) { - SLuint32 numBuffers = validNumBuffers[i]; - PrepareValidBuffer(numBuffers); - EnqueueMaxBuffer(numBuffers); - ClearQueue(); - DestroyPlayer(); - } -} - -TEST_F(TestBufferQueue, testStateTransitionEmptyQueue) { - static const SLuint32 newStates[] = { - SL_PLAYSTATE_PAUSED, // paused -> paused - SL_PLAYSTATE_STOPPED, // paused -> stopped - SL_PLAYSTATE_PAUSED, // stopped -> paused - SL_PLAYSTATE_PLAYING, // paused -> playing - SL_PLAYSTATE_PLAYING, // playing -> playing - SL_PLAYSTATE_STOPPED, // playing -> stopped - SL_PLAYSTATE_STOPPED, // stopped -> stopped - SL_PLAYSTATE_PLAYING, // stopped -> playing - SL_PLAYSTATE_PAUSED // playing -> paused - }; - - for (unsigned i = 0; i < sizeof(validNumBuffers) / sizeof(validNumBuffers[0]); ++i) { - SLuint32 numBuffers = validNumBuffers[i]; - SLuint32 j; - - PrepareValidBuffer(numBuffers); - /* Set initial state to paused*/ - SetPlayerState(SL_PLAYSTATE_PAUSED); - - for (j = 0; j < sizeof(newStates) / sizeof(newStates[0]); ++j) { - SetPlayerState(newStates[j]); - CheckBufferCount((SLuint32) 0, (SLuint32) 0); - } - DestroyPlayer(); - } -} - -TEST_F(TestBufferQueue, testStateTransitionNonEmptyQueue) { - static const SLuint32 newStates[] = { - SL_PLAYSTATE_PAUSED, // paused -> paused - SL_PLAYSTATE_STOPPED, // paused -> stopped - SL_PLAYSTATE_STOPPED, // stopped -> stopped - SL_PLAYSTATE_PAUSED // stopped -> paused - }; - - for (unsigned i = 0; i < sizeof(validNumBuffers) / sizeof(validNumBuffers[0]); ++i) { - SLuint32 numBuffers = validNumBuffers[i]; - SLuint32 j; - - /* Prepare the player */ - PrepareValidBuffer(numBuffers); - EnqueueMaxBuffer(numBuffers); - SetPlayerState(SL_PLAYSTATE_PAUSED); - - for (j = 0; j < sizeof(newStates) / sizeof(newStates[0]); ++j) { - SetPlayerState(newStates[j]); - CheckBufferCount(numBuffers, (SLuint32) 0); - } - DestroyPlayer(); - } -} - -TEST_F(TestBufferQueue, testStatePlayBuffer){ - for (unsigned i = 0; i < sizeof(validNumBuffers) / sizeof(validNumBuffers[0]); ++i) { - SLuint32 numBuffers = validNumBuffers[i]; - PrepareValidBuffer(numBuffers); - PlayBufferQueue(); - DestroyPlayer(); - } -} - -int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); -#if 1 // temporary workaround if hardware volume control is not working - const char *VOLUME = getenv("BufferQueue_test_VOLUME"); - if (NULL != VOLUME) { - float volume = atof(VOLUME); - if (volume >= 0.0f && volume <= 1.0f) { - gVolume = volume; - } - } -#endif - return RUN_ALL_TESTS(); -} diff --git a/wilhelm/tests/examples/Android.mk b/wilhelm/tests/examples/Android.mk deleted file mode 100644 index d16164ed..00000000 --- a/wilhelm/tests/examples/Android.mk +++ /dev/null @@ -1,325 +0,0 @@ -LOCAL_PATH:= $(call my-dir) - -# slesTest_recBuffQueue - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - slesTestRecBuffQueue.cpp - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_MODULE:= slesTest_recBuffQueue - -include $(BUILD_EXECUTABLE) - -# slesTest_playFdPath - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - slesTestPlayFdPath.cpp - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_MODULE:= slesTest_playFdPath - -include $(BUILD_EXECUTABLE) - -# slesTest_feedback - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - slesTestFeedback.cpp - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX - #LOCAL_SHARED_LIBRARIES += librt -endif - -LOCAL_CFLAGS += -UNDEBUG - -LOCAL_MODULE:= slesTest_feedback - -include $(BUILD_EXECUTABLE) - -# slesTest_sawtoothBufferQueue - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - slesTestSawtoothBufferQueue.cpp - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX - #LOCAL_SHARED_LIBRARIES += librt -endif - -LOCAL_MODULE:= slesTest_sawtoothBufferQueue - -include $(BUILD_EXECUTABLE) - -# slesTest_eqFdPath - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - slesTestEqFdPath.cpp - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_MODULE:= slesTest_eqFdPath - -include $(BUILD_EXECUTABLE) - -# slesTest_eqOutputPath - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - slesTestEqOutputPath.cpp - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_MODULE:= slesTest_eqOutputPath - -include $(BUILD_EXECUTABLE) - -# slesTest_bassboostPath - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - slesTestBassBoostPath.cpp - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_MODULE:= slesTest_bassboostPath - -include $(BUILD_EXECUTABLE) - -# slesTest_virtualizer - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - slesTestVirtualizerPath.cpp - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_MODULE:= slesTest_virtualizer - -include $(BUILD_EXECUTABLE) - -# slesTest_effectCapabilities - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - slesTestEffectCapabilities.cpp - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_MODULE:= slesTest_effectCapabilities - -include $(BUILD_EXECUTABLE) - -# slesTest_sendToPresetReverb - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - slesTestSendToPresetReverb.cpp - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_MODULE:= slesTest_sendToPresetReverb - -include $(BUILD_EXECUTABLE) - -# slesTest_decodeToBuffQueue - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - slesTestDecodeToBuffQueue.cpp - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_MODULE:= slesTest_decodeToBuffQueue - -include $(BUILD_EXECUTABLE) - -################### -# slesTestDecodeAac - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - slesTestDecodeAac.cpp - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -LOCAL_STATIC_LIBRARIES := libcpustats - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_CFLAGS += -UNDEBUG - -LOCAL_MODULE:= slesTest_decodeAac - -include $(BUILD_EXECUTABLE) - -####################################### -# OpenMAX AL example code - -# xaVideoDecoderCapabilities - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - xaVideoDecoderCapabilities.cpp - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenMAXAL - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_MODULE:= xaVideoDecoderCapabilities - -include $(BUILD_EXECUTABLE) diff --git a/wilhelm/tests/examples/slesTestBassBoostPath.cpp b/wilhelm/tests/examples/slesTestBassBoostPath.cpp deleted file mode 100644 index 96c33521..00000000 --- a/wilhelm/tests/examples/slesTestBassBoostPath.cpp +++ /dev/null @@ -1,294 +0,0 @@ -/* - * 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. - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <sys/time.h> -#include <fcntl.h> - -#include <SLES/OpenSLES.h> -#ifdef ANDROID -#include <SLES/OpenSLES_Android.h> -#endif - - -#define MAX_NUMBER_INTERFACES 3 - -#define TIME_S_BETWEEN_BB_ON_OFF 3 - -//----------------------------------------------------------------- -/* Exits the application if an error is encountered */ -#define ExitOnError(x) ExitOnErrorFunc(x,__LINE__) - -void ExitOnErrorFunc( SLresult result , int line) -{ - if (SL_RESULT_SUCCESS != result) { - fprintf(stderr, "%u error code encountered at line %d, exiting\n", result, line); - exit(EXIT_FAILURE); - } -} - - -//----------------------------------------------------------------- - -/* Play an audio path by opening a file descriptor on that path */ -void TestBassBoostPathFromFD(SLObjectItf sl, const char* path, int16_t boostStrength, bool alwaysOn) -{ - SLresult result; - SLEngineItf EngineItf; - - /* Objects this application uses: one player and an ouput mix */ - SLObjectItf player, outputMix; - - /* Source of audio data to play */ - SLDataSource audioSource; -#ifdef ANDROID - SLDataLocator_AndroidFD locatorFd; -#else - SLDataLocator_URI locatorUri; -#endif - SLDataFormat_MIME mime; - - /* Data sinks for the audio player */ - SLDataSink audioSink; - SLDataLocator_OutputMix locator_outputmix; - - /* Interfaces for the audio player */ - SLPlayItf playItf; - SLPrefetchStatusItf prefetchItf; - SLBassBoostItf bbItf; - - SLboolean required[MAX_NUMBER_INTERFACES]; - SLInterfaceID iidArray[MAX_NUMBER_INTERFACES]; - - /* Get the SL Engine Interface which is implicit */ - result = (*sl)->GetInterface(sl, SL_IID_ENGINE, (void*)&EngineItf); - ExitOnError(result); - - /* Initialize arrays required[] and iidArray[] */ - for (int i=0 ; i < MAX_NUMBER_INTERFACES ; i++) { - required[i] = SL_BOOLEAN_FALSE; - iidArray[i] = SL_IID_NULL; - } - - /* ------------------------------------------------------ */ - /* Configuration of the output mix */ - - /* Create Output Mix object to be used by the player */ - result = (*EngineItf)->CreateOutputMix(EngineItf, &outputMix, 1, iidArray, required); - ExitOnError(result); - - /* Realize the Output Mix object in synchronous mode */ - result = (*outputMix)->Realize(outputMix, SL_BOOLEAN_FALSE); - ExitOnError(result); - - /* Setup the data sink structure */ - locator_outputmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; - locator_outputmix.outputMix = outputMix; - audioSink.pLocator = (void*)&locator_outputmix; - audioSink.pFormat = NULL; - - /* ------------------------------------------------------ */ - /* Configuration of the player */ - - /* Set arrays required[] and iidArray[] for required interfaces */ - /* (SLPlayItf is implicit) */ - required[0] = SL_BOOLEAN_TRUE; - iidArray[0] = SL_IID_PREFETCHSTATUS; - required[1] = SL_BOOLEAN_TRUE; - iidArray[1] = SL_IID_BASSBOOST; - -#ifdef ANDROID - /* Setup the data source structure for the URI */ - locatorFd.locatorType = SL_DATALOCATOR_ANDROIDFD; - int fd = open(path, O_RDONLY); - if (fd == -1) { - ExitOnError(SL_RESULT_RESOURCE_ERROR); - } - locatorFd.fd = (SLint32) fd; - locatorFd.length = SL_DATALOCATOR_ANDROIDFD_USE_FILE_SIZE; - locatorFd.offset = 0; -#else - locatorUri.locatorType = SL_DATALOCATOR_URI; - locatorUri.URI = (SLchar *) path; -#endif - - mime.formatType = SL_DATAFORMAT_MIME; - /* this is how ignored mime information is specified, according to OpenSL ES spec - * in 9.1.6 SLDataFormat_MIME and 8.23 SLMetadataTraversalItf GetChildInfo */ - mime.mimeType = (SLchar*)NULL; - mime.containerType = SL_CONTAINERTYPE_UNSPECIFIED; - - audioSource.pFormat = (void*)&mime; -#ifdef ANDROID - audioSource.pLocator = (void*)&locatorFd; -#else - audioSource.pLocator = (void*)&locatorUri; -#endif - - /* Create the audio player */ - result = (*EngineItf)->CreateAudioPlayer(EngineItf, &player, &audioSource, &audioSink, 2, - iidArray, required); - ExitOnError(result); - - /* Realize the player in synchronous mode. */ - result = (*player)->Realize(player, SL_BOOLEAN_FALSE); ExitOnError(result); - fprintf(stdout, "URI example: after Realize\n"); - - /* Get the SLPlayItf, SLPrefetchStatusItf and SLBassBoostItf interfaces for the player */ - result = (*player)->GetInterface(player, SL_IID_PLAY, (void*)&playItf); - ExitOnError(result); - - result = (*player)->GetInterface(player, SL_IID_PREFETCHSTATUS, (void*)&prefetchItf); - ExitOnError(result); - - result = (*player)->GetInterface(player, SL_IID_BASSBOOST, (void*)&bbItf); - ExitOnError(result); - - fprintf(stdout, "Player configured\n"); - - /* ------------------------------------------------------ */ - /* Playback and test */ - - /* Start the data prefetching by setting the player to the paused state */ - result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PAUSED ); - ExitOnError(result); - - /* Wait until there's data to play */ - SLuint32 prefetchStatus = SL_PREFETCHSTATUS_UNDERFLOW; - while (prefetchStatus != SL_PREFETCHSTATUS_SUFFICIENTDATA) { - usleep(100 * 1000); - (*prefetchItf)->GetPrefetchStatus(prefetchItf, &prefetchStatus); - ExitOnError(result); - } - - /* Get duration */ - SLmillisecond durationInMsec = SL_TIME_UNKNOWN; - result = (*playItf)->GetDuration(playItf, &durationInMsec); - ExitOnError(result); - if (durationInMsec == SL_TIME_UNKNOWN) { - durationInMsec = 5000; - } - - /* Start playback */ - fprintf(stdout, "Starting to play\n"); - result = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_PLAYING ); - ExitOnError(result); - - /* Configure BassBoost */ - SLboolean strengthSupported = SL_BOOLEAN_FALSE; - result = (*bbItf)->IsStrengthSupported(bbItf, &strengthSupported); - ExitOnError(result); - if (SL_BOOLEAN_FALSE == strengthSupported) { - fprintf(stdout, "BassBoost strength is not supported on this platform. Too bad!\n"); - } else { - fprintf(stdout, "BassBoost strength is supported, setting strength to %d\n", boostStrength); - result = (*bbItf)->SetStrength(bbItf, boostStrength); - ExitOnError(result); - } - - SLpermille strength = 0; - result = (*bbItf)->GetRoundedStrength(bbItf, &strength); - ExitOnError(result); - fprintf(stdout, "Rounded strength of boost = %d\n", strength); - - - /* Switch BassBoost on/off every TIME_S_BETWEEN_BB_ON_OFF seconds unless always on */ - SLboolean previousEnabled = SL_BOOLEAN_FALSE; - for(unsigned int j=0 ; j<(durationInMsec/(1000*TIME_S_BETWEEN_BB_ON_OFF)) ; j++) { - SLboolean enabled; - result = (*bbItf)->IsEnabled(bbItf, &enabled); - ExitOnError(result); - enabled = alwaysOn || !enabled; - if (enabled != previousEnabled) { - result = (*bbItf)->SetEnabled(bbItf, enabled); - ExitOnError(result); - previousEnabled = enabled; - if (SL_BOOLEAN_TRUE == enabled) { - fprintf(stdout, "BassBoost on\n"); - } else { - fprintf(stdout, "BassBoost off\n"); - } - } - usleep(TIME_S_BETWEEN_BB_ON_OFF * 1000 * 1000); - } - - /* Make sure player is stopped */ - fprintf(stdout, "Stopping playback\n"); - result = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED); - ExitOnError(result); - - /* Destroy the player */ - (*player)->Destroy(player); - - /* Destroy Output Mix object */ - (*outputMix)->Destroy(outputMix); - -#ifdef ANDROID - close(fd); -#endif -} - -//----------------------------------------------------------------- -int main(int argc, char* const argv[]) -{ - const char *programName = argv[0]; - SLresult result; - SLObjectItf sl; - - fprintf(stdout, "OpenSL ES test %s: exercises SLBassBoostItf ", programName); - fprintf(stdout, "and AudioPlayer with SLDataLocator_AndroidFD source / OutputMix sink\n"); - fprintf(stdout, "Plays the sound file designated by the given path, "); - fprintf(stdout, "and applies a bass boost effect of the specified strength,\n"); - fprintf(stdout, "where strength is a integer value between 0 and 1000.\n"); - fprintf(stdout, "Every %d seconds, the BassBoost will be turned on and off,\n", - TIME_S_BETWEEN_BB_ON_OFF); - fprintf(stdout, "unless the --always-on option is specified before the path.\n"); - - bool alwaysOn = false; - if (argc >= 2 && !strcmp(argv[1], "--always-on")) { - alwaysOn = true; - --argc; - ++argv; - } - - if (argc < 3) { - fprintf(stdout, "Usage: \t%s [--always-on] path bass_boost_strength\n", programName); - fprintf(stdout, "Example: \"%s /sdcard/my.mp3 1000\" \n", programName); - exit(EXIT_FAILURE); - } - - SLEngineOption EngineOption[] = { - {(SLuint32) SL_ENGINEOPTION_THREADSAFE, (SLuint32) SL_BOOLEAN_TRUE} - }; - - result = slCreateEngine( &sl, 1, EngineOption, 0, NULL, NULL); - ExitOnError(result); - - /* Realizing the SL Engine in synchronous mode. */ - result = (*sl)->Realize(sl, SL_BOOLEAN_FALSE); - ExitOnError(result); - - // intentionally not checking that argv[2], the bassboost strength, is between 0 and 1000 - TestBassBoostPathFromFD(sl, argv[1], (int16_t)atoi(argv[2]), alwaysOn); - - /* Shutdown OpenSL ES */ - (*sl)->Destroy(sl); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/examples/slesTestDecodeAac.cpp b/wilhelm/tests/examples/slesTestDecodeAac.cpp deleted file mode 100644 index 1a51bb0b..00000000 --- a/wilhelm/tests/examples/slesTestDecodeAac.cpp +++ /dev/null @@ -1,897 +0,0 @@ -/* - * 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. - */ - -/* AAC ADTS Decode Test - -First run the program from shell: - # slesTestDecodeAac /sdcard/myFile.adts - -Expected output: - OpenSL ES test slesTestDecodeAac: decodes a file containing AAC ADTS data - Player created - Player realized - Enqueueing initial empty buffers to receive decoded PCM data 0 1 - Enqueueing initial full buffers of encoded ADTS data 0 1 - Starting to decode - Frame counters: encoded=4579 decoded=4579 - -These use adb on host to retrieve the decoded file: - % adb pull /sdcard/myFile.adts.raw myFile.raw - -How to examine the output with Audacity: - Project / Import raw data - Select myFile.raw file, then click Open button - Choose these options: - Signed 16-bit PCM - Little-endian - 1 Channel (Mono) / 2 Channels (Stereo) based on the PCM information obtained when decoding - Sample rate based on the PCM information obtained when decoding - Click Import button - -*/ - -#define QUERY_METADATA - -#include <assert.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <sys/time.h> -#include <fcntl.h> -#include <pthread.h> -#include <sys/mman.h> -#include <sys/stat.h> -#include <unistd.h> -#include <cpustats/CentralTendencyStatistics.h> - -#include <SLES/OpenSLES.h> -#include <SLES/OpenSLES_Android.h> - -/* Explicitly requesting SL_IID_ANDROIDBUFFERQUEUE and SL_IID_ANDROIDSIMPLEBUFFERQUEUE - * on the AudioPlayer object for decoding, and - * SL_IID_METADATAEXTRACTION for retrieving the format of the decoded audio. - */ -#define NUM_EXPLICIT_INTERFACES_FOR_PLAYER 4 - -/* Number of decoded samples produced by one AAC frame; defined by the standard */ -#define SAMPLES_PER_AAC_FRAME 1024 -/* Size of the encoded AAC ADTS buffer queue */ -#define NB_BUFFERS_IN_ADTS_QUEUE 2 // 2 to 4 is typical - -/* Size of the decoded PCM buffer queue */ -#define NB_BUFFERS_IN_PCM_QUEUE 2 // 2 to 4 is typical -/* Size of each PCM buffer in the queue */ -#define BUFFER_SIZE_IN_BYTES (2*sizeof(short)*SAMPLES_PER_AAC_FRAME) - -/* Local storage for decoded PCM audio data */ -int8_t pcmData[NB_BUFFERS_IN_PCM_QUEUE * BUFFER_SIZE_IN_BYTES]; - -/* destination for decoded data */ -static FILE* outputFp; - -#ifdef QUERY_METADATA -/* metadata key index for the PCM format information we want to retrieve */ -static int channelCountKeyIndex = -1; -static int sampleRateKeyIndex = -1; -static int bitsPerSampleKeyIndex = -1; -static int containerSizeKeyIndex = -1; -static int channelMaskKeyIndex = -1; -static int endiannessKeyIndex = -1; -/* size of the struct to retrieve the PCM format metadata values: the values we're interested in - * are SLuint32, but it is saved in the data field of a SLMetadataInfo, hence the larger size. - * Note that this size is queried and displayed at l.XXX for demonstration/test purposes. - * */ -#define PCM_METADATA_VALUE_SIZE 32 -/* used to query metadata values */ -static SLMetadataInfo *pcmMetaData = NULL; -/* we only want to query / display the PCM format once */ -static bool formatQueried = false; -#endif - -/* to signal to the test app that the end of the encoded ADTS stream has been reached */ -bool eos = false; -bool endOfEncodedStream = false; - -void *ptr; -unsigned char *frame; -size_t filelen; -size_t encodedFrames = 0; -size_t encodedSamples = 0; -size_t decodedFrames = 0; -size_t decodedSamples = 0; -size_t totalEncodeCompletions = 0; // number of Enqueue completions received -CentralTendencyStatistics frameStats; -size_t pauseFrame = 0; // pause after this many decoded frames, zero means don't pause -SLboolean createRaw = SL_BOOLEAN_TRUE; // whether to create a .raw file containing PCM data - -/* constant to identify a buffer context which is the end of the stream to decode */ -static const int kEosBufferCntxt = 1980; // a magic value we can compare against - -/* protects shared variables */ -pthread_mutex_t eosLock = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t eosCondition = PTHREAD_COND_INITIALIZER; - -// These are extensions to OpenMAX AL 1.0.1 values - -#define PREFETCHSTATUS_UNKNOWN ((SLuint32) 0) -#define PREFETCHSTATUS_ERROR ((SLuint32) (-1)) - -// Mutex and condition shared with main program to protect prefetch_status - -static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; -SLuint32 prefetch_status = PREFETCHSTATUS_UNKNOWN; - -/* used to detect errors likely to have occured when the OpenSL ES framework fails to open - * a resource, for instance because a file URI is invalid, or an HTTP server doesn't respond. - */ -#define PREFETCHEVENT_ERROR_CANDIDATE \ - (SL_PREFETCHEVENT_STATUSCHANGE | SL_PREFETCHEVENT_FILLLEVELCHANGE) - -//----------------------------------------------------------------- -/* Exits the application if an error is encountered */ -#define ExitOnError(x) ExitOnErrorFunc(x,__LINE__) - -void ExitOnErrorFunc( SLresult result , int line) -{ - if (SL_RESULT_SUCCESS != result) { - fprintf(stderr, "Error code %u encountered at line %d, exiting\n", result, line); - exit(EXIT_FAILURE); - } -} - -//----------------------------------------------------------------- -/* Callback for "prefetch" events, here used to detect audio resource opening errors */ -void PrefetchEventCallback(SLPrefetchStatusItf caller, void *pContext, SLuint32 event) -{ - // pContext is unused here, so we pass NULL - assert(pContext == NULL); - SLpermille level = 0; - SLresult result; - result = (*caller)->GetFillLevel(caller, &level); - ExitOnError(result); - SLuint32 status; - result = (*caller)->GetPrefetchStatus(caller, &status); - ExitOnError(result); - printf("prefetch level=%d status=0x%x event=%d\n", level, status, event); - SLuint32 new_prefetch_status; - if ((PREFETCHEVENT_ERROR_CANDIDATE == (event & PREFETCHEVENT_ERROR_CANDIDATE)) - && (level == 0) && (status == SL_PREFETCHSTATUS_UNDERFLOW)) { - printf("PrefetchEventCallback: Error while prefetching data, exiting\n"); - new_prefetch_status = PREFETCHSTATUS_ERROR; - } else if (event == SL_PREFETCHEVENT_STATUSCHANGE) { - new_prefetch_status = status; - } else { - return; - } - int ok; - ok = pthread_mutex_lock(&mutex); - assert(ok == 0); - prefetch_status = new_prefetch_status; - ok = pthread_cond_signal(&cond); - assert(ok == 0); - ok = pthread_mutex_unlock(&mutex); - assert(ok == 0); -} - -//----------------------------------------------------------------- -/* Structure for passing information to callback function */ -typedef struct CallbackCntxt_ { -#ifdef QUERY_METADATA - SLMetadataExtractionItf metaItf; -#endif - SLPlayItf playItf; - SLint8* pDataBase; // Base address of local audio data storage - SLint8* pData; // Current address of local audio data storage -} CallbackCntxt; - -// used to notify when SL_PLAYEVENT_HEADATEND event is received -static pthread_mutex_t head_mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_cond_t head_cond = PTHREAD_COND_INITIALIZER; -static SLboolean head_atend = SL_BOOLEAN_FALSE; - -//----------------------------------------------------------------- -/* Callback for SLPlayItf through which we receive the SL_PLAYEVENT_HEADATEND event */ -void PlayCallback(SLPlayItf caller, void *pContext, SLuint32 event) { - SLmillisecond position; - SLresult res = (*caller)->GetPosition(caller, &position); - ExitOnError(res); - if (event & SL_PLAYEVENT_HEADATMARKER) { - printf("SL_PLAYEVENT_HEADATMARKER position=%u ms\n", position); - } - if (event & SL_PLAYEVENT_HEADATNEWPOS) { - printf("SL_PLAYEVENT_HEADATNEWPOS position=%u ms\n", position); - } - if (event & SL_PLAYEVENT_HEADATEND) { - printf("SL_PLAYEVENT_HEADATEND position=%u ms, all decoded data has been received\n", - position); - pthread_mutex_lock(&head_mutex); - head_atend = SL_BOOLEAN_TRUE; - pthread_cond_signal(&head_cond); - pthread_mutex_unlock(&head_mutex); - } -} - -//----------------------------------------------------------------- -/* Callback for AndroidBufferQueueItf through which we supply ADTS buffers */ -SLresult AndroidBufferQueueCallback( - SLAndroidBufferQueueItf caller, - void *pCallbackContext, /* input */ - void *pBufferContext, /* input */ - void *pBufferData, /* input */ - SLuint32 dataSize, /* input */ - SLuint32 dataUsed, /* input */ - const SLAndroidBufferItem *pItems,/* input */ - SLuint32 itemsLength /* input */) -{ - // mutex on all global variables - pthread_mutex_lock(&eosLock); - SLresult res; - - // for demonstration purposes: - // verify what type of information was enclosed in the processed buffer - if (NULL != pBufferContext) { - if (&kEosBufferCntxt == pBufferContext) { - fprintf(stdout, "EOS was processed\n"); - } - } - - ++totalEncodeCompletions; - if (endOfEncodedStream) { - // we continue to receive acknowledgement after each buffer was processed - if (pBufferContext == (void *) &kEosBufferCntxt) { - printf("Received EOS completion after EOS\n"); - } else if (pBufferContext == NULL) { - printf("Received ADTS completion after EOS\n"); - } else { - fprintf(stderr, "Received acknowledgement after EOS with unexpected context %p\n", - pBufferContext); - } - } else if (filelen == 0) { - // signal EOS to the decoder rather than just starving it - printf("Enqueue EOS: encoded frames=%u, decoded frames=%u\n", encodedFrames, decodedFrames); - printf("You should now see %u ADTS completion%s followed by 1 EOS completion\n", - NB_BUFFERS_IN_ADTS_QUEUE - 1, NB_BUFFERS_IN_ADTS_QUEUE != 2 ? "s" : ""); - SLAndroidBufferItem msgEos; - msgEos.itemKey = SL_ANDROID_ITEMKEY_EOS; - msgEos.itemSize = 0; - // EOS message has no parameters, so the total size of the message is the size of the key - // plus the size of itemSize, both SLuint32 - res = (*caller)->Enqueue(caller, (void *)&kEosBufferCntxt /*pBufferContext*/, - NULL /*pData*/, 0 /*dataLength*/, - &msgEos /*pMsg*/, - sizeof(SLuint32)*2 /*msgLength*/); - ExitOnError(res); - endOfEncodedStream = true; - // verify that we are at start of an ADTS frame - } else if (!(filelen < 7 || frame[0] != 0xFF || (frame[1] & 0xF0) != 0xF0)) { - if (pBufferContext != NULL) { - fprintf(stderr, "Received acknowledgement before EOS with unexpected context %p\n", - pBufferContext); - } - unsigned framelen = ((frame[3] & 3) << 11) | (frame[4] << 3) | (frame[5] >> 5); - if (framelen <= filelen) { - // push more data to the queue - res = (*caller)->Enqueue(caller, NULL /*pBufferContext*/, - frame, framelen, NULL, 0); - ExitOnError(res); - frame += framelen; - filelen -= framelen; - ++encodedFrames; - encodedSamples += SAMPLES_PER_AAC_FRAME; - frameStats.sample(framelen); - } else { - fprintf(stderr, - "partial ADTS frame at EOF discarded; offset=%u, framelen=%u, filelen=%u\n", - frame - (unsigned char *) ptr, framelen, filelen); - frame += filelen; - filelen = 0; - } - } else { - fprintf(stderr, "corrupt ADTS frame encountered; offset=%u, filelen=%u\n", - frame - (unsigned char *) ptr, filelen); - frame += filelen; - filelen = 0; - } - pthread_mutex_unlock(&eosLock); - - return SL_RESULT_SUCCESS; -} - -//----------------------------------------------------------------- -/* Callback for decoding buffer queue events */ -void DecPlayCallback( - SLAndroidSimpleBufferQueueItf queueItf, - void *pContext) -{ - // mutex on all global variables - pthread_mutex_lock(&eosLock); - - CallbackCntxt *pCntxt = (CallbackCntxt*)pContext; - - /* Save the decoded data to output file */ - if (outputFp != NULL && fwrite(pCntxt->pData, 1, BUFFER_SIZE_IN_BYTES, outputFp) - < BUFFER_SIZE_IN_BYTES) { - fprintf(stderr, "Error writing to output file"); - } - - /* Re-enqueue the now empty buffer */ - SLresult res; - res = (*queueItf)->Enqueue(queueItf, pCntxt->pData, BUFFER_SIZE_IN_BYTES); - ExitOnError(res); - - /* Increase data pointer by buffer size, with circular wraparound */ - pCntxt->pData += BUFFER_SIZE_IN_BYTES; - if (pCntxt->pData >= pCntxt->pDataBase + (NB_BUFFERS_IN_PCM_QUEUE * BUFFER_SIZE_IN_BYTES)) { - pCntxt->pData = pCntxt->pDataBase; - } - - // Note: adding a sleep here or any sync point is a way to slow down the decoding, or - // synchronize it with some other event, as the OpenSL ES framework will block until the - // buffer queue callback return to proceed with the decoding. - -#ifdef QUERY_METADATA - /* Example: query of the decoded PCM format */ - if (!formatQueried) { - /* memory to receive the PCM format metadata */ - union { - SLMetadataInfo pcmMetaData; - char withData[PCM_METADATA_VALUE_SIZE]; - } u; - res = (*pCntxt->metaItf)->GetValue(pCntxt->metaItf, sampleRateKeyIndex, - PCM_METADATA_VALUE_SIZE, &u.pcmMetaData); ExitOnError(res); - // Note: here we could verify the following: - // u.pcmMetaData->encoding == SL_CHARACTERENCODING_BINARY - // u.pcmMetaData->size == sizeof(SLuint32) - // but the call was successful for the PCM format keys, so those conditions are implied - printf("sample rate = %d\n", *((SLuint32*)u.pcmMetaData.data)); - res = (*pCntxt->metaItf)->GetValue(pCntxt->metaItf, channelCountKeyIndex, - PCM_METADATA_VALUE_SIZE, &u.pcmMetaData); ExitOnError(res); - printf("channel count = %d\n", *((SLuint32*)u.pcmMetaData.data)); - res = (*pCntxt->metaItf)->GetValue(pCntxt->metaItf, bitsPerSampleKeyIndex, - PCM_METADATA_VALUE_SIZE, &u.pcmMetaData); ExitOnError(res); - printf("bits per sample = %d bits\n", *((SLuint32*)u.pcmMetaData.data)); - res = (*pCntxt->metaItf)->GetValue(pCntxt->metaItf, containerSizeKeyIndex, - PCM_METADATA_VALUE_SIZE, &u.pcmMetaData); ExitOnError(res); - printf("container size = %d bits\n", *((SLuint32*)u.pcmMetaData.data)); - res = (*pCntxt->metaItf)->GetValue(pCntxt->metaItf, channelMaskKeyIndex, - PCM_METADATA_VALUE_SIZE, &u.pcmMetaData); ExitOnError(res); - printf("channel mask = 0x%X (0x3=front left | front right, 0x4=front center)\n", - *((SLuint32*)u.pcmMetaData.data)); - res = (*pCntxt->metaItf)->GetValue(pCntxt->metaItf, endiannessKeyIndex, - PCM_METADATA_VALUE_SIZE, &u.pcmMetaData); ExitOnError(res); - printf("endianness = %d (1=big, 2=little)\n", *((SLuint32*)u.pcmMetaData.data)); - formatQueried = true; - } -#endif - - ++decodedFrames; - decodedSamples += SAMPLES_PER_AAC_FRAME; - - /* Periodically ask for position and duration */ - if ((decodedFrames % 1000 == 0) || endOfEncodedStream) { - SLmillisecond position; - res = (*pCntxt->playItf)->GetPosition(pCntxt->playItf, &position); - ExitOnError(res); - SLmillisecond duration; - res = (*pCntxt->playItf)->GetDuration(pCntxt->playItf, &duration); - ExitOnError(res); - if (duration == SL_TIME_UNKNOWN) { - printf("After %u encoded %u decoded frames: position is %u ms, duration is " - "unknown as expected\n", - encodedFrames, decodedFrames, position); - } else { - printf("After %u encoded %u decoded frames: position is %u ms, duration is " - "surprisingly %u ms\n", - encodedFrames, decodedFrames, position, duration); - } - } - - if (endOfEncodedStream && decodedSamples >= encodedSamples) { - eos = true; - pthread_cond_signal(&eosCondition); - } - pthread_mutex_unlock(&eosLock); -} - -//----------------------------------------------------------------- - -/* Decode an audio path by opening a file descriptor on that path */ -void TestDecToBuffQueue( SLObjectItf sl, const char *path, int fd) -{ - // check what kind of object it is - int ok; - struct stat statbuf; - ok = fstat(fd, &statbuf); - if (ok < 0) { - perror(path); - return; - } - - // verify that's it is a file - if (!S_ISREG(statbuf.st_mode)) { - fprintf(stderr, "%s: not an ordinary file\n", path); - return; - } - - // map file contents into memory to make it easier to access the ADTS frames directly - ptr = mmap(NULL, statbuf.st_size, PROT_READ, MAP_FILE | MAP_PRIVATE, fd, (off_t) 0); - if (ptr == MAP_FAILED) { - perror(path); - return; - } - frame = (unsigned char *) ptr; - filelen = statbuf.st_size; - - // create PCM .raw file - if (createRaw) { - size_t len = strlen((const char *) path); - char* outputPath = (char*) malloc(len + 4 + 1); // save room to concatenate ".raw" - if (NULL == outputPath) { - ExitOnError(SL_RESULT_RESOURCE_ERROR); - } - memcpy(outputPath, path, len + 1); - strcat(outputPath, ".raw"); - outputFp = fopen(outputPath, "w"); - if (NULL == outputFp) { - // issue an error message, but continue the decoding anyway - perror(outputPath); - } - } else { - outputFp = NULL; - } - - SLresult res; - SLEngineItf EngineItf; - - /* Objects this application uses: one audio player */ - SLObjectItf player; - - /* Interfaces for the audio player */ - SLPlayItf playItf; -#ifdef QUERY_METADATA - /* to retrieve the decoded PCM format */ - SLMetadataExtractionItf mdExtrItf; -#endif - /* to retrieve the PCM samples */ - SLAndroidSimpleBufferQueueItf decBuffQueueItf; - /* to queue the AAC data to decode */ - SLAndroidBufferQueueItf aacBuffQueueItf; - /* for prefetch status */ - SLPrefetchStatusItf prefetchItf; - - SLboolean required[NUM_EXPLICIT_INTERFACES_FOR_PLAYER]; - SLInterfaceID iidArray[NUM_EXPLICIT_INTERFACES_FOR_PLAYER]; - - /* Get the SL Engine Interface which is implicit */ - res = (*sl)->GetInterface(sl, SL_IID_ENGINE, (void*)&EngineItf); - ExitOnError(res); - - /* Initialize arrays required[] and iidArray[] */ - unsigned int i; - for (i=0 ; i < NUM_EXPLICIT_INTERFACES_FOR_PLAYER ; i++) { - required[i] = SL_BOOLEAN_FALSE; - iidArray[i] = SL_IID_NULL; - } - - /* ------------------------------------------------------ */ - /* Configuration of the player */ - - /* Request the AndroidSimpleBufferQueue interface */ - required[0] = SL_BOOLEAN_TRUE; - iidArray[0] = SL_IID_ANDROIDSIMPLEBUFFERQUEUE; - /* Request the AndroidBufferQueue interface */ - required[1] = SL_BOOLEAN_TRUE; - iidArray[1] = SL_IID_ANDROIDBUFFERQUEUESOURCE; - /* Request the PrefetchStatus interface */ - required[2] = SL_BOOLEAN_TRUE; - iidArray[2] = SL_IID_PREFETCHSTATUS; -#ifdef QUERY_METADATA - /* Request the MetadataExtraction interface */ - required[3] = SL_BOOLEAN_TRUE; - iidArray[3] = SL_IID_METADATAEXTRACTION; -#endif - - /* Setup the data source for queueing AAC buffers of ADTS data */ - SLDataLocator_AndroidBufferQueue loc_srcAbq = { - SL_DATALOCATOR_ANDROIDBUFFERQUEUE /*locatorType*/, - NB_BUFFERS_IN_ADTS_QUEUE /*numBuffers*/}; - SLDataFormat_MIME format_srcMime = { - SL_DATAFORMAT_MIME /*formatType*/, - SL_ANDROID_MIME_AACADTS /*mimeType*/, - SL_CONTAINERTYPE_RAW /*containerType*/}; - SLDataSource decSource = {&loc_srcAbq /*pLocator*/, &format_srcMime /*pFormat*/}; - - /* Setup the data sink, a buffer queue for buffers of PCM data */ - SLDataLocator_AndroidSimpleBufferQueue loc_destBq = { - SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE/*locatorType*/, - NB_BUFFERS_IN_PCM_QUEUE /*numBuffers*/ }; - - /* declare we're decoding to PCM, the parameters after that need to be valid, - but are ignored, the decoded format will match the source */ - SLDataFormat_PCM format_destPcm = { /*formatType*/ SL_DATAFORMAT_PCM, /*numChannels*/ 1, - /*samplesPerSec*/ SL_SAMPLINGRATE_8, /*pcm.bitsPerSample*/ SL_PCMSAMPLEFORMAT_FIXED_16, - /*/containerSize*/ 16, /*channelMask*/ SL_SPEAKER_FRONT_LEFT, - /*endianness*/ SL_BYTEORDER_LITTLEENDIAN }; - SLDataSink decDest = {&loc_destBq /*pLocator*/, &format_destPcm /*pFormat*/}; - - /* Create the audio player */ - res = (*EngineItf)->CreateAudioPlayer(EngineItf, &player, &decSource, &decDest, -#ifdef QUERY_METADATA - NUM_EXPLICIT_INTERFACES_FOR_PLAYER, -#else - NUM_EXPLICIT_INTERFACES_FOR_PLAYER - 1, -#endif - iidArray, required); - ExitOnError(res); - printf("Player created\n"); - - /* Realize the player in synchronous mode. */ - res = (*player)->Realize(player, SL_BOOLEAN_FALSE); - ExitOnError(res); - printf("Player realized\n"); - - /* Get the play interface which is implicit */ - res = (*player)->GetInterface(player, SL_IID_PLAY, (void*)&playItf); - ExitOnError(res); - - /* Enable callback when position passes through a marker (SL_PLAYEVENT_HEADATMARKER) */ - res = (*playItf)->SetMarkerPosition(playItf, 5000); - ExitOnError(res); - - /* Enable callback for periodic position updates (SL_PLAYEVENT_HEADATNEWPOS) */ - res = (*playItf)->SetPositionUpdatePeriod(playItf, 3000); - ExitOnError(res); - - /* Use the play interface to set up a callback for the SL_PLAYEVENT_HEAD* events */ - res = (*playItf)->SetCallbackEventsMask(playItf, - SL_PLAYEVENT_HEADATMARKER | SL_PLAYEVENT_HEADATNEWPOS | SL_PLAYEVENT_HEADATEND); - ExitOnError(res); - res = (*playItf)->RegisterCallback(playItf, PlayCallback /*callback*/, NULL /*pContext*/); - ExitOnError(res); - - /* Get the position before prefetch; should be zero */ - SLmillisecond position; - res = (*playItf)->GetPosition(playItf, &position); - ExitOnError(res); - if (position == 0) { - printf("The position before prefetch is zero as expected\n"); - } else if (position == SL_TIME_UNKNOWN) { - printf("That's surprising the position before prefetch is unknown"); - } else { - printf("That's surprising the position before prefetch is %u ms\n", position); - } - - /* Get the duration before prefetch; should be unknown */ - SLmillisecond duration; - res = (*playItf)->GetDuration(playItf, &duration); - ExitOnError(res); - if (duration == SL_TIME_UNKNOWN) { - printf("The duration before prefetch is unknown as expected\n"); - } else { - printf("That's surprising the duration before prefetch is %u ms\n", duration); - } - - /* Get the buffer queue interface which was explicitly requested */ - res = (*player)->GetInterface(player, SL_IID_ANDROIDSIMPLEBUFFERQUEUE, (void*)&decBuffQueueItf); - ExitOnError(res); - - /* Get the Android buffer queue interface which was explicitly requested */ - res = (*player)->GetInterface(player, SL_IID_ANDROIDBUFFERQUEUESOURCE, (void*)&aacBuffQueueItf); - ExitOnError(res); - - /* Get the prefetch status interface which was explicitly requested */ - res = (*player)->GetInterface(player, SL_IID_PREFETCHSTATUS, (void*)&prefetchItf); - ExitOnError(res); - -#ifdef QUERY_METADATA - /* Get the metadata extraction interface which was explicitly requested */ - res = (*player)->GetInterface(player, SL_IID_METADATAEXTRACTION, (void*)&mdExtrItf); - ExitOnError(res); -#endif - - /* ------------------------------------------------------ */ - /* Initialize the callback and its context for the buffer queue of the decoded PCM */ - CallbackCntxt sinkCntxt; - sinkCntxt.playItf = playItf; -#ifdef QUERY_METADATA - sinkCntxt.metaItf = mdExtrItf; -#endif - sinkCntxt.pDataBase = (int8_t*)&pcmData; - sinkCntxt.pData = sinkCntxt.pDataBase; - res = (*decBuffQueueItf)->RegisterCallback(decBuffQueueItf, DecPlayCallback, &sinkCntxt); - ExitOnError(res); - - /* Enqueue buffers to map the region of memory allocated to store the decoded data */ - printf("Enqueueing initial empty buffers to receive decoded PCM data"); - for(i = 0 ; i < NB_BUFFERS_IN_PCM_QUEUE ; i++) { - printf(" %d", i); - res = (*decBuffQueueItf)->Enqueue(decBuffQueueItf, sinkCntxt.pData, BUFFER_SIZE_IN_BYTES); - ExitOnError(res); - sinkCntxt.pData += BUFFER_SIZE_IN_BYTES; - if (sinkCntxt.pData >= sinkCntxt.pDataBase + - (NB_BUFFERS_IN_PCM_QUEUE * BUFFER_SIZE_IN_BYTES)) { - sinkCntxt.pData = sinkCntxt.pDataBase; - } - } - printf("\n"); - - /* ------------------------------------------------------ */ - /* Initialize the callback for prefetch errors, if we can't open the resource to decode */ - res = (*prefetchItf)->RegisterCallback(prefetchItf, PrefetchEventCallback, NULL); - ExitOnError(res); - res = (*prefetchItf)->SetCallbackEventsMask(prefetchItf, PREFETCHEVENT_ERROR_CANDIDATE); - ExitOnError(res); - - /* Initialize the callback for the Android buffer queue of the encoded data */ - res = (*aacBuffQueueItf)->RegisterCallback(aacBuffQueueItf, AndroidBufferQueueCallback, NULL); - ExitOnError(res); - - /* Enqueue the content of our encoded data before starting to play, - we don't want to starve the player initially */ - printf("Enqueueing initial full buffers of encoded ADTS data"); - for (i=0 ; i < NB_BUFFERS_IN_ADTS_QUEUE ; i++) { - if (filelen < 7 || frame[0] != 0xFF || (frame[1] & 0xF0) != 0xF0) { - printf("\ncorrupt ADTS frame encountered; offset %zu bytes\n", - frame - (unsigned char *) ptr); - // Note that prefetch will detect this error soon when it gets a premature EOF - break; - } - unsigned framelen = ((frame[3] & 3) << 11) | (frame[4] << 3) | (frame[5] >> 5); - printf(" %d (%u bytes)", i, framelen); - res = (*aacBuffQueueItf)->Enqueue(aacBuffQueueItf, NULL /*pBufferContext*/, - frame, framelen, NULL, 0); - ExitOnError(res); - frame += framelen; - filelen -= framelen; - ++encodedFrames; - encodedSamples += SAMPLES_PER_AAC_FRAME; - frameStats.sample(framelen); - } - printf("\n"); - -#ifdef QUERY_METADATA - /* ------------------------------------------------------ */ - /* Get and display the metadata key names for the decoder */ - // This is for test / demonstration purposes only where we discover the key and value sizes - // of a PCM decoder. An application that would want to directly get access to those values - // can make assumptions about the size of the keys and their matching values (all SLuint32), - // but it should not make assumptions about the key indices as these are subject to change. - // Note that we don't get the metadata values yet; that happens in the first decode callback. - SLuint32 itemCount; - res = (*mdExtrItf)->GetItemCount(mdExtrItf, &itemCount); - ExitOnError(res); - printf("itemCount=%u\n", itemCount); - SLuint32 keySize, valueSize; - SLMetadataInfo *keyInfo, *value; - for(i=0 ; i<itemCount ; i++) { - keyInfo = NULL; keySize = 0; - value = NULL; valueSize = 0; - res = (*mdExtrItf)->GetKeySize(mdExtrItf, i, &keySize); - ExitOnError(res); - res = (*mdExtrItf)->GetValueSize(mdExtrItf, i, &valueSize); - ExitOnError(res); - keyInfo = (SLMetadataInfo*) malloc(keySize); - if (NULL != keyInfo) { - res = (*mdExtrItf)->GetKey(mdExtrItf, i, keySize, keyInfo); - ExitOnError(res); - printf("key[%d] size=%d, name=%s \tvalue size=%d encoding=0x%X langCountry=%s\n", - i, keyInfo->size, keyInfo->data, valueSize, keyInfo->encoding, - keyInfo->langCountry); - /* find out the key index of the metadata we're interested in */ - if (!strcmp((char*)keyInfo->data, ANDROID_KEY_PCMFORMAT_NUMCHANNELS)) { - channelCountKeyIndex = i; - } else if (!strcmp((char*)keyInfo->data, ANDROID_KEY_PCMFORMAT_SAMPLERATE)) { - sampleRateKeyIndex = i; - } else if (!strcmp((char*)keyInfo->data, ANDROID_KEY_PCMFORMAT_BITSPERSAMPLE)) { - bitsPerSampleKeyIndex = i; - } else if (!strcmp((char*)keyInfo->data, ANDROID_KEY_PCMFORMAT_CONTAINERSIZE)) { - containerSizeKeyIndex = i; - } else if (!strcmp((char*)keyInfo->data, ANDROID_KEY_PCMFORMAT_CHANNELMASK)) { - channelMaskKeyIndex = i; - } else if (!strcmp((char*)keyInfo->data, ANDROID_KEY_PCMFORMAT_ENDIANNESS)) { - endiannessKeyIndex = i; - } else { - printf("Unknown key %s ignored\n", (char *)keyInfo->data); - } - free(keyInfo); - } - } - if (channelCountKeyIndex != -1) { - printf("Key %s is at index %d\n", - ANDROID_KEY_PCMFORMAT_NUMCHANNELS, channelCountKeyIndex); - } else { - fprintf(stderr, "Unable to find key %s\n", ANDROID_KEY_PCMFORMAT_NUMCHANNELS); - } - if (sampleRateKeyIndex != -1) { - printf("Key %s is at index %d\n", - ANDROID_KEY_PCMFORMAT_SAMPLERATE, sampleRateKeyIndex); - } else { - fprintf(stderr, "Unable to find key %s\n", ANDROID_KEY_PCMFORMAT_SAMPLERATE); - } - if (bitsPerSampleKeyIndex != -1) { - printf("Key %s is at index %d\n", - ANDROID_KEY_PCMFORMAT_BITSPERSAMPLE, bitsPerSampleKeyIndex); - } else { - fprintf(stderr, "Unable to find key %s\n", ANDROID_KEY_PCMFORMAT_BITSPERSAMPLE); - } - if (containerSizeKeyIndex != -1) { - printf("Key %s is at index %d\n", - ANDROID_KEY_PCMFORMAT_CONTAINERSIZE, containerSizeKeyIndex); - } else { - fprintf(stderr, "Unable to find key %s\n", ANDROID_KEY_PCMFORMAT_CONTAINERSIZE); - } - if (channelMaskKeyIndex != -1) { - printf("Key %s is at index %d\n", - ANDROID_KEY_PCMFORMAT_CHANNELMASK, channelMaskKeyIndex); - } else { - fprintf(stderr, "Unable to find key %s\n", ANDROID_KEY_PCMFORMAT_CHANNELMASK); - } - if (endiannessKeyIndex != -1) { - printf("Key %s is at index %d\n", - ANDROID_KEY_PCMFORMAT_ENDIANNESS, endiannessKeyIndex); - } else { - fprintf(stderr, "Unable to find key %s\n", ANDROID_KEY_PCMFORMAT_ENDIANNESS); - } -#endif - - // set the player's state to paused, to start prefetching - printf("Setting play state to PAUSED\n"); - res = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_PAUSED); - ExitOnError(res); - - // wait for prefetch status callback to indicate either sufficient data or error - printf("Awaiting prefetch complete\n"); - pthread_mutex_lock(&mutex); - while (prefetch_status == PREFETCHSTATUS_UNKNOWN) { - pthread_cond_wait(&cond, &mutex); - } - pthread_mutex_unlock(&mutex); - if (prefetch_status == PREFETCHSTATUS_ERROR) { - fprintf(stderr, "Error during prefetch, exiting\n"); - goto destroyRes; - } - printf("Prefetch is complete\n"); - - /* ------------------------------------------------------ */ - /* Start decoding */ - printf("Starting to decode\n"); - res = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_PLAYING); - ExitOnError(res); - - /* Decode until the end of the stream is reached */ - printf("Awaiting notification that all encoded buffers have been enqueued\n"); - pthread_mutex_lock(&eosLock); - while (!eos) { - if (pauseFrame > 0) { - if (decodedFrames >= pauseFrame) { - pauseFrame = 0; - printf("Pausing after decoded frame %u for 10 seconds\n", decodedFrames); - pthread_mutex_unlock(&eosLock); - res = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_PAUSED); - ExitOnError(res); - sleep(10); - printf("Resuming\n"); - res = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_PLAYING); - ExitOnError(res); - pthread_mutex_lock(&eosLock); - } else { - pthread_mutex_unlock(&eosLock); - usleep(10*1000); - pthread_mutex_lock(&eosLock); - } - } else { - pthread_cond_wait(&eosCondition, &eosLock); - } - } - pthread_mutex_unlock(&eosLock); - printf("All encoded buffers have now been enqueued, but there's still more to do\n"); - - /* This just means done enqueueing; there may still more data in decode queue! */ - pthread_mutex_lock(&head_mutex); - while (!head_atend) { - pthread_cond_wait(&head_cond, &head_mutex); - } - pthread_mutex_unlock(&head_mutex); - printf("Decode is now finished\n"); - - pthread_mutex_lock(&eosLock); - printf("Frame counters: encoded=%u decoded=%u\n", encodedFrames, decodedFrames); - printf("Sample counters: encoded=%u decoded=%u\n", encodedSamples, decodedSamples); - printf("Total encode completions received: actual=%u, expected=%u\n", - totalEncodeCompletions, encodedFrames+1/*EOS*/); - pthread_mutex_unlock(&eosLock); - - /* Get the final position and duration */ - res = (*playItf)->GetPosition(playItf, &position); - ExitOnError(res); - res = (*playItf)->GetDuration(playItf, &duration); - ExitOnError(res); - if (duration == SL_TIME_UNKNOWN) { - printf("The final position is %u ms, duration is unknown\n", position); - } else { - printf("The final position is %u ms, duration is %u ms\n", position, duration); - } - - printf("Frame length statistics:\n"); - printf(" n = %u frames\n", frameStats.n()); - printf(" mean = %.1f bytes\n", frameStats.mean()); - printf(" minimum = %.1f bytes\n", frameStats.minimum()); - printf(" maximum = %.1f bytes\n", frameStats.maximum()); - printf(" stddev = %.1f bytes\n", frameStats.stddev()); - - /* ------------------------------------------------------ */ - /* End of decoding */ - -destroyRes: - /* Destroy the AudioPlayer object */ - (*player)->Destroy(player); - - if (outputFp != NULL) { - fclose(outputFp); - } - - // unmap the ADTS AAC file from memory - ok = munmap(ptr, statbuf.st_size); - if (0 != ok) { - perror(path); - } -} - -//----------------------------------------------------------------- -int main(int argc, char* const argv[]) -{ - SLresult res; - SLObjectItf sl; - - printf("OpenSL ES test %s: decodes a file containing AAC ADTS data\n", argv[0]); - - if (argc != 2) { - printf("Usage: \t%s source_file\n", argv[0]); - printf("Example: \"%s /sdcard/myFile.adts\n", argv[0]); - exit(EXIT_FAILURE); - } - - // open pathname of encoded ADTS AAC file to get a file descriptor - int fd; - fd = open(argv[1], O_RDONLY); - if (fd < 0) { - perror(argv[1]); - return EXIT_FAILURE; - } - - SLEngineOption EngineOption[] = { - {(SLuint32) SL_ENGINEOPTION_THREADSAFE, (SLuint32) SL_BOOLEAN_TRUE} - }; - - res = slCreateEngine( &sl, 1, EngineOption, 0, NULL, NULL); - ExitOnError(res); - - /* Realizing the SL Engine in synchronous mode. */ - res = (*sl)->Realize(sl, SL_BOOLEAN_FALSE); - ExitOnError(res); - - TestDecToBuffQueue(sl, argv[1], fd); - - /* Shutdown OpenSL ES */ - (*sl)->Destroy(sl); - - // close the file - (void) close(fd); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/examples/slesTestDecodeToBuffQueue.cpp b/wilhelm/tests/examples/slesTestDecodeToBuffQueue.cpp deleted file mode 100644 index 77980289..00000000 --- a/wilhelm/tests/examples/slesTestDecodeToBuffQueue.cpp +++ /dev/null @@ -1,567 +0,0 @@ -/* - * 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. - */ - -/* Audio Decode Test - -First run the program from shell: - # slesTest_decodeToBuffQueue /sdcard/myFile.mp3 4 - -These use adb on host to retrieve the decoded file: - % adb pull /sdcard/myFile.mp3.raw myFile.raw - -How to examine the output with Audacity: - Project / Import raw data - Select myFile.raw file, then click Open button - Choose these options: - Signed 16-bit PCM - Little-endian - 1 Channel (Mono) / 2 Channels (Stereo) based on the selected file - Sample rate same as the selected file - Click Import button - -*/ - - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <sys/time.h> -#include <fcntl.h> -#include <utils/threads.h> - -#include <SLES/OpenSLES.h> -#include <SLES/OpenSLES_Android.h> - -/* Explicitly requesting SL_IID_ANDROIDSIMPLEBUFFERQUEUE and SL_IID_PREFETCHSTATUS - * on the AudioPlayer object for decoding, SL_IID_METADATAEXTRACTION for retrieving the - * format of the decoded audio */ -#define NUM_EXPLICIT_INTERFACES_FOR_PLAYER 3 - -/* Size of the decode buffer queue */ -#define NB_BUFFERS_IN_QUEUE 4 -/* Size of each buffer in the queue */ -#define BUFFER_SIZE_IN_SAMPLES 1152 // number of samples per MP3 frame -#define BUFFER_SIZE_IN_BYTES (2*BUFFER_SIZE_IN_SAMPLES) - -/* Local storage for decoded audio data */ -int8_t pcmData[NB_BUFFERS_IN_QUEUE * BUFFER_SIZE_IN_BYTES]; - -/* destination for decoded data */ -static FILE* gFp; - -/* to display the number of decode iterations */ -static int counter=0; - -/* metadata key index for the PCM format information we want to retrieve */ -static int channelCountKeyIndex = -1; -static int sampleRateKeyIndex = -1; -/* size of the struct to retrieve the PCM format metadata values: the values we're interested in - * are SLuint32, but it is saved in the data field of a SLMetadataInfo, hence the larger size. - * Nate that this size is queried and displayed at l.452 for demonstration/test purposes. - * */ -#define PCM_METADATA_VALUE_SIZE 32 -/* used to query metadata values */ -static SLMetadataInfo *pcmMetaData = NULL; -/* we only want to query / display the PCM format once */ -static bool formatQueried = false; - -/* to signal to the test app the end of the stream to decode has been reached */ -bool eos = false; -android::Mutex eosLock; -android::Condition eosCondition; - -/* used to detect errors likely to have occured when the OpenSL ES framework fails to open - * a resource, for instance because a file URI is invalid, or an HTTP server doesn't respond. - */ -#define PREFETCHEVENT_ERROR_CANDIDATE \ - (SL_PREFETCHEVENT_STATUSCHANGE | SL_PREFETCHEVENT_FILLLEVELCHANGE) - -//----------------------------------------------------------------- -/* Exits the application if an error is encountered */ -#define ExitOnError(x) ExitOnErrorFunc(x,__LINE__) - -void ExitOnErrorFunc( SLresult result , int line) -{ - if (SL_RESULT_SUCCESS != result) { - fprintf(stderr, "Error code %u encountered at line %d, exiting\n", result, line); - exit(EXIT_FAILURE); - } -} - -/* Used to signal prefetching failures */ -bool prefetchError = false; - -//----------------------------------------------------------------- -/* Structure for passing information to callback function */ -typedef struct CallbackCntxt_ { - SLPlayItf playItf; - SLMetadataExtractionItf metaItf; - SLuint32 size; - SLint8* pDataBase; // Base address of local audio data storage - SLint8* pData; // Current address of local audio data storage -} CallbackCntxt; - -//----------------------------------------------------------------- -void SignalEos() { - android::Mutex::Autolock autoLock(eosLock); - eos = true; - eosCondition.signal(); -} - -//----------------------------------------------------------------- -/* Callback for "prefetch" events, here used to detect audio resource opening errors */ -void PrefetchEventCallback( SLPrefetchStatusItf caller, void *pContext, SLuint32 event) -{ - SLpermille level = 0; - SLresult result; - result = (*caller)->GetFillLevel(caller, &level); - ExitOnError(result); - SLuint32 status; - //fprintf(stdout, "PrefetchEventCallback: received event %u\n", event); - result = (*caller)->GetPrefetchStatus(caller, &status); - ExitOnError(result); - if ((PREFETCHEVENT_ERROR_CANDIDATE == (event & PREFETCHEVENT_ERROR_CANDIDATE)) - && (level == 0) && (status == SL_PREFETCHSTATUS_UNDERFLOW)) { - fprintf(stdout, "PrefetchEventCallback: Error while prefetching data, exiting\n"); - prefetchError = true; - SignalEos(); - } -} - -/* Callback for "playback" events, i.e. event happening during decoding */ -void DecProgressCallback( - SLPlayItf caller, - void *pContext, - SLuint32 event) -{ - SLresult result; - SLmillisecond msec; - result = (*caller)->GetPosition(caller, &msec); - ExitOnError(result); - - if (SL_PLAYEVENT_HEADATEND & event) { - fprintf(stdout, "SL_PLAYEVENT_HEADATEND current position=%u ms\n", msec); - SignalEos(); - } - - if (SL_PLAYEVENT_HEADATNEWPOS & event) { - fprintf(stdout, "SL_PLAYEVENT_HEADATNEWPOS current position=%u ms\n", msec); - } - - if (SL_PLAYEVENT_HEADATMARKER & event) { - fprintf(stdout, "SL_PLAYEVENT_HEADATMARKER current position=%u ms\n", msec); - } -} - -//----------------------------------------------------------------- -/* Callback for decoding buffer queue events */ -void DecPlayCallback( - SLAndroidSimpleBufferQueueItf queueItf, - void *pContext) -{ - counter++; - - CallbackCntxt *pCntxt = (CallbackCntxt*)pContext; - - if (counter % 1000 == 0) { - SLmillisecond msec; - SLresult result = (*pCntxt->playItf)->GetPosition(pCntxt->playItf, &msec); - ExitOnError(result); - printf("DecPlayCallback called (iteration %d): current position=%u ms\n", counter, msec); - } - - /* Save the decoded data */ - if (fwrite(pCntxt->pDataBase, 1, BUFFER_SIZE_IN_BYTES, gFp) < BUFFER_SIZE_IN_BYTES) { - fprintf(stdout, "Error writing to output file, signaling EOS\n"); - SignalEos(); - return; - } - - /* Increase data pointer by buffer size */ - pCntxt->pData += BUFFER_SIZE_IN_BYTES; - - if (pCntxt->pData >= pCntxt->pDataBase + (NB_BUFFERS_IN_QUEUE * BUFFER_SIZE_IN_BYTES)) { - pCntxt->pData = pCntxt->pDataBase; - } - - ExitOnError( (*queueItf)->Enqueue(queueItf, pCntxt->pDataBase, BUFFER_SIZE_IN_BYTES) ); - // Note: adding a sleep here or any sync point is a way to slow down the decoding, or - // synchronize it with some other event, as the OpenSL ES framework will block until the - // buffer queue callback return to proceed with the decoding. - -#if 0 - /* Example: buffer queue state display */ - SLAndroidSimpleBufferQueueState decQueueState; - ExitOnError( (*queueItf)->GetState(queueItf, &decQueueState) ); - - fprintf(stderr, "\DecBufferQueueCallback now has pCntxt->pData=%p queue: " - "count=%u playIndex=%u\n", - pCntxt->pData, decQueueState.count, decQueueState.index); -#endif - -#if 0 - /* Example: display duration in callback where we use the callback context for the SLPlayItf*/ - SLmillisecond durationInMsec = SL_TIME_UNKNOWN; - SLresult result = (*pCntxt->playItf)->GetDuration(pCntxt->playItf, &durationInMsec); - ExitOnError(result); - if (durationInMsec == SL_TIME_UNKNOWN) { - fprintf(stdout, "Content duration is unknown (in dec callback)\n"); - } else { - fprintf(stdout, "Content duration is %ums (in dec callback)\n", - durationInMsec); - } -#endif - -#if 0 - /* Example: display position in callback where we use the callback context for the SLPlayItf*/ - SLmillisecond posMsec = SL_TIME_UNKNOWN; - SLresult result = (*pCntxt->playItf)->GetPosition(pCntxt->playItf, &posMsec); - ExitOnError(result); - if (posMsec == SL_TIME_UNKNOWN) { - fprintf(stdout, "Content position is unknown (in dec callback)\n"); - } else { - fprintf(stdout, "Content position is %ums (in dec callback)\n", - posMsec); - } -#endif - - /* Example: query of the decoded PCM format */ - if (formatQueried) { - return; - } - SLresult res = (*pCntxt->metaItf)->GetValue(pCntxt->metaItf, sampleRateKeyIndex, - PCM_METADATA_VALUE_SIZE, pcmMetaData); ExitOnError(res); - // Note: here we could verify the following: - // pcmMetaData->encoding == SL_CHARACTERENCODING_BINARY - // pcmMetaData->size == sizeof(SLuint32) - // but the call was successful for the PCM format keys, so those conditions are implied - fprintf(stdout, "sample rate = %dHz, ", *((SLuint32*)pcmMetaData->data)); - res = (*pCntxt->metaItf)->GetValue(pCntxt->metaItf, channelCountKeyIndex, - PCM_METADATA_VALUE_SIZE, pcmMetaData); ExitOnError(res); - fprintf(stdout, " channel count = %d\n", *((SLuint32*)pcmMetaData->data)); - formatQueried = true; -} - -//----------------------------------------------------------------- - -/* Decode an audio path by opening a file descriptor on that path */ -void TestDecToBuffQueue( SLObjectItf sl, const char* path) -{ - size_t len = strlen((const char *) path); - char* outputPath = (char*) malloc(len + 4 + 1); // save room to concatenate ".raw" - if (NULL == outputPath) { - ExitOnError(SL_RESULT_RESOURCE_ERROR); - } - memcpy(outputPath, path, len + 1); - strcat(outputPath, ".raw"); - gFp = fopen(outputPath, "w"); - if (NULL == gFp) { - ExitOnError(SL_RESULT_RESOURCE_ERROR); - } - - SLresult result; - SLEngineItf EngineItf; - - /* Objects this application uses: one audio player */ - SLObjectItf player; - - /* Interfaces for the audio player */ - SLAndroidSimpleBufferQueueItf decBuffQueueItf; - SLPrefetchStatusItf prefetchItf; - SLPlayItf playItf; - SLMetadataExtractionItf mdExtrItf; - - /* Source of audio data for the decoding */ - SLDataSource decSource; - SLDataLocator_URI decUri; - SLDataFormat_MIME decMime; - - /* Data sink for decoded audio */ - SLDataSink decDest; - SLDataLocator_AndroidSimpleBufferQueue decBuffQueue; - SLDataFormat_PCM pcm; - - SLboolean required[NUM_EXPLICIT_INTERFACES_FOR_PLAYER]; - SLInterfaceID iidArray[NUM_EXPLICIT_INTERFACES_FOR_PLAYER]; - - /* Get the SL Engine Interface which is implicit */ - result = (*sl)->GetInterface(sl, SL_IID_ENGINE, (void*)&EngineItf); - ExitOnError(result); - - /* Initialize arrays required[] and iidArray[] */ - for (int i=0 ; i < NUM_EXPLICIT_INTERFACES_FOR_PLAYER ; i++) { - required[i] = SL_BOOLEAN_FALSE; - iidArray[i] = SL_IID_NULL; - } - - /* allocate memory to receive the PCM format metadata */ - if (!pcmMetaData) { - pcmMetaData = (SLMetadataInfo*) malloc(PCM_METADATA_VALUE_SIZE); - } - - formatQueried = false; - - /* ------------------------------------------------------ */ - /* Configuration of the player */ - - /* Request the AndroidSimpleBufferQueue interface */ - required[0] = SL_BOOLEAN_TRUE; - iidArray[0] = SL_IID_ANDROIDSIMPLEBUFFERQUEUE; - /* Request the PrefetchStatus interface */ - required[1] = SL_BOOLEAN_TRUE; - iidArray[1] = SL_IID_PREFETCHSTATUS; - /* Request the PrefetchStatus interface */ - required[2] = SL_BOOLEAN_TRUE; - iidArray[2] = SL_IID_METADATAEXTRACTION; - - /* Setup the data source */ - decUri.locatorType = SL_DATALOCATOR_URI; - decUri.URI = (SLchar*)path; - decMime.formatType = SL_DATAFORMAT_MIME; - /* this is how ignored mime information is specified, according to OpenSL ES spec - * in 9.1.6 SLDataFormat_MIME and 8.23 SLMetadataTraversalItf GetChildInfo */ - decMime.mimeType = (SLchar*)NULL; - decMime.containerType = SL_CONTAINERTYPE_UNSPECIFIED; - decSource.pLocator = (void *) &decUri; - decSource.pFormat = (void *) &decMime; - - /* Setup the data sink */ - decBuffQueue.locatorType = SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE; - decBuffQueue.numBuffers = NB_BUFFERS_IN_QUEUE; - /* set up the format of the data in the buffer queue */ - pcm.formatType = SL_DATAFORMAT_PCM; - // FIXME valid value required but currently ignored - pcm.numChannels = 1; - pcm.samplesPerSec = SL_SAMPLINGRATE_8; - pcm.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_16; - pcm.containerSize = 16; - pcm.channelMask = SL_SPEAKER_FRONT_LEFT; - pcm.endianness = SL_BYTEORDER_LITTLEENDIAN; - - decDest.pLocator = (void *) &decBuffQueue; - decDest.pFormat = (void * ) &pcm; - - /* Create the audio player */ - result = (*EngineItf)->CreateAudioPlayer(EngineItf, &player, &decSource, &decDest, - NUM_EXPLICIT_INTERFACES_FOR_PLAYER, iidArray, required); - ExitOnError(result); - fprintf(stdout, "Player created\n"); - - /* Realize the player in synchronous mode. */ - result = (*player)->Realize(player, SL_BOOLEAN_FALSE); - ExitOnError(result); - fprintf(stdout, "Player realized\n"); - - /* Get the play interface which is implicit */ - result = (*player)->GetInterface(player, SL_IID_PLAY, (void*)&playItf); - ExitOnError(result); - - /* Set up the player callback to get events during the decoding */ - // FIXME currently ignored - result = (*playItf)->SetMarkerPosition(playItf, 2000); - ExitOnError(result); - result = (*playItf)->SetPositionUpdatePeriod(playItf, 500); - ExitOnError(result); - result = (*playItf)->SetCallbackEventsMask(playItf, - SL_PLAYEVENT_HEADATMARKER | SL_PLAYEVENT_HEADATNEWPOS | SL_PLAYEVENT_HEADATEND); - ExitOnError(result); - result = (*playItf)->RegisterCallback(playItf, DecProgressCallback, NULL); - ExitOnError(result); - fprintf(stdout, "Play callback registered\n"); - - /* Get the buffer queue interface which was explicitly requested */ - result = (*player)->GetInterface(player, SL_IID_ANDROIDSIMPLEBUFFERQUEUE, - (void*)&decBuffQueueItf); - ExitOnError(result); - - /* Get the prefetch status interface which was explicitly requested */ - result = (*player)->GetInterface(player, SL_IID_PREFETCHSTATUS, (void*)&prefetchItf); - ExitOnError(result); - - /* Get the metadata extraction interface which was explicitly requested */ - result = (*player)->GetInterface(player, SL_IID_METADATAEXTRACTION, (void*)&mdExtrItf); - ExitOnError(result); - - /* ------------------------------------------------------ */ - /* Initialize the callback and its context for the decoding buffer queue */ - CallbackCntxt cntxt; - cntxt.playItf = playItf; - cntxt.metaItf = mdExtrItf; - cntxt.pDataBase = (int8_t*)&pcmData; - cntxt.pData = cntxt.pDataBase; - cntxt.size = sizeof(pcmData); - result = (*decBuffQueueItf)->RegisterCallback(decBuffQueueItf, DecPlayCallback, &cntxt); - ExitOnError(result); - - /* Enqueue buffers to map the region of memory allocated to store the decoded data */ - fprintf(stdout,"Enqueueing buffer "); - for(int i = 0 ; i < NB_BUFFERS_IN_QUEUE ; i++) { - fprintf(stdout,"%d ", i); - result = (*decBuffQueueItf)->Enqueue(decBuffQueueItf, cntxt.pData, BUFFER_SIZE_IN_BYTES); - ExitOnError(result); - cntxt.pData += BUFFER_SIZE_IN_BYTES; - } - fprintf(stdout,"\n"); - cntxt.pData = cntxt.pDataBase; - - /* ------------------------------------------------------ */ - /* Initialize the callback for prefetch errors, if we can't open the resource to decode */ - result = (*prefetchItf)->RegisterCallback(prefetchItf, PrefetchEventCallback, &prefetchItf); - ExitOnError(result); - result = (*prefetchItf)->SetCallbackEventsMask(prefetchItf, PREFETCHEVENT_ERROR_CANDIDATE); - ExitOnError(result); - - /* ------------------------------------------------------ */ - /* Prefetch the data so we can get information about the format before starting to decode */ - /* 1/ cause the player to prefetch the data */ - result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PAUSED ); - ExitOnError(result); - /* 2/ block until data has been prefetched */ - SLuint32 prefetchStatus = SL_PREFETCHSTATUS_UNDERFLOW; - SLuint32 timeOutIndex = 50; // time out prefetching after 5s - while ((prefetchStatus != SL_PREFETCHSTATUS_SUFFICIENTDATA) && (timeOutIndex > 0) && - !prefetchError) { - usleep(10 * 1000); - (*prefetchItf)->GetPrefetchStatus(prefetchItf, &prefetchStatus); - timeOutIndex--; - } - if (timeOutIndex == 0 || prefetchError) { - fprintf(stderr, "Failure to prefetch data in time, exiting\n"); - ExitOnError(SL_RESULT_CONTENT_NOT_FOUND); - } - - /* ------------------------------------------------------ */ - /* Display duration */ - SLmillisecond durationInMsec = SL_TIME_UNKNOWN; - result = (*playItf)->GetDuration(playItf, &durationInMsec); - ExitOnError(result); - if (durationInMsec == SL_TIME_UNKNOWN) { - fprintf(stdout, "Content duration is unknown\n"); - } else { - fprintf(stdout, "Content duration is %ums\n", durationInMsec); - } - - /* ------------------------------------------------------ */ - /* Display the metadata obtained from the decoder */ - // This is for test / demonstration purposes only where we discover the key and value sizes - // of a PCM decoder. An application that would want to directly get access to those values - // can make assumptions about the size of the keys and their matching values (all SLuint32) - SLuint32 itemCount; - result = (*mdExtrItf)->GetItemCount(mdExtrItf, &itemCount); - SLuint32 i, keySize, valueSize; - SLMetadataInfo *keyInfo, *value; - for(i=0 ; i<itemCount ; i++) { - keyInfo = NULL; keySize = 0; - value = NULL; valueSize = 0; - result = (*mdExtrItf)->GetKeySize(mdExtrItf, i, &keySize); - ExitOnError(result); - result = (*mdExtrItf)->GetValueSize(mdExtrItf, i, &valueSize); - ExitOnError(result); - keyInfo = (SLMetadataInfo*) malloc(keySize); - if (NULL != keyInfo) { - result = (*mdExtrItf)->GetKey(mdExtrItf, i, keySize, keyInfo); - ExitOnError(result); - fprintf(stdout, "key[%d] size=%d, name=%s \tvalue size=%d \n", - i, keyInfo->size, keyInfo->data, valueSize); - /* find out the key index of the metadata we're interested in */ - if (!strcmp((char*)keyInfo->data, ANDROID_KEY_PCMFORMAT_NUMCHANNELS)) { - channelCountKeyIndex = i; - } else if (!strcmp((char*)keyInfo->data, ANDROID_KEY_PCMFORMAT_SAMPLERATE)) { - sampleRateKeyIndex = i; - } - free(keyInfo); - } - } - if (channelCountKeyIndex != -1) { - fprintf(stdout, "Key %s is at index %d\n", - ANDROID_KEY_PCMFORMAT_NUMCHANNELS, channelCountKeyIndex); - } else { - fprintf(stderr, "Unable to find key %s\n", ANDROID_KEY_PCMFORMAT_NUMCHANNELS); - } - if (sampleRateKeyIndex != -1) { - fprintf(stdout, "Key %s is at index %d\n", - ANDROID_KEY_PCMFORMAT_SAMPLERATE, sampleRateKeyIndex); - } else { - fprintf(stderr, "Unable to find key %s\n", ANDROID_KEY_PCMFORMAT_SAMPLERATE); - } - - /* ------------------------------------------------------ */ - /* Start decoding */ - result = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_PLAYING); - ExitOnError(result); - fprintf(stdout, "Starting to decode\n"); - - /* Decode until the end of the stream is reached */ - { - android::Mutex::Autolock autoLock(eosLock); - while (!eos) { - eosCondition.wait(eosLock); - } - } - fprintf(stdout, "EOS signaled\n"); - - /* ------------------------------------------------------ */ - /* End of decoding */ - - /* Stop decoding */ - result = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED); - ExitOnError(result); - fprintf(stdout, "Stopped decoding\n"); - - /* Destroy the AudioPlayer object */ - (*player)->Destroy(player); - - fclose(gFp); - - free(pcmMetaData); - pcmMetaData = NULL; -} - -//----------------------------------------------------------------- -int main(int argc, char* const argv[]) -{ - SLresult result; - SLObjectItf sl; - - fprintf(stdout, "OpenSL ES test %s: exercises SLPlayItf and SLAndroidSimpleBufferQueueItf ", - argv[0]); - fprintf(stdout, "on an AudioPlayer object to decode a URI to PCM\n"); - - if (argc != 2) { - fprintf(stdout, "Usage: \t%s source_file\n", argv[0]); - fprintf(stdout, "Example: \"%s /sdcard/myFile.mp3\n", argv[0]); - exit(EXIT_FAILURE); - } - - SLEngineOption EngineOption[] = { - {(SLuint32) SL_ENGINEOPTION_THREADSAFE, (SLuint32) SL_BOOLEAN_TRUE} - }; - - result = slCreateEngine( &sl, 1, EngineOption, 0, NULL, NULL); - ExitOnError(result); - - /* Realizing the SL Engine in synchronous mode. */ - result = (*sl)->Realize(sl, SL_BOOLEAN_FALSE); - ExitOnError(result); - - TestDecToBuffQueue(sl, argv[1]); - - /* Shutdown OpenSL ES */ - (*sl)->Destroy(sl); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/examples/slesTestEffectCapabilities.cpp b/wilhelm/tests/examples/slesTestEffectCapabilities.cpp deleted file mode 100644 index 494a027a..00000000 --- a/wilhelm/tests/examples/slesTestEffectCapabilities.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/* - * 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. - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <sys/time.h> -#include <fcntl.h> - -#include <SLES/OpenSLES.h> -#include <SLES/OpenSLES_Android.h> - - -#define MAX_NUMBER_INTERFACES 1 - -#define GUID_DISPLAY_LENGTH 35 -#define FX_NAME_LENGTH 64 - -static int testMode; -//----------------------------------------------------------------- -/* Exits the application if an error is encountered */ -#define ExitOnError(x) ExitOnErrorFunc(x,__LINE__) - -void ExitOnErrorFunc( SLresult result , int line) -{ - if (SL_RESULT_SUCCESS != result) { - fprintf(stderr, "%u error code encountered at line %d, exiting\n", result, line); - exit(EXIT_FAILURE); - } -} - -//----------------------------------------------------------------- -void guidToString(const SLInterfaceID guid, char *str) { - if ((NULL == guid) || (NULL == str)) { - return; - } - snprintf(str, GUID_DISPLAY_LENGTH, "%08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x", - guid->time_low, - guid->time_mid, - guid->time_hi_and_version, - guid->clock_seq, - guid->node[0], - guid->node[1], - guid->node[2], - guid->node[3], - guid->node[4], - guid->node[5]); -} - -//----------------------------------------------------------------- - -/* Query available effects on Android */ -void TestGenericFxCapabilities( ) -{ - - SLresult result; - SLObjectItf sl; - - /* ------------------------------------------------------ */ - /* Engine configuration and creation */ - - SLEngineOption EngineOption[] = { - {(SLuint32) SL_ENGINEOPTION_THREADSAFE, (SLuint32) SL_BOOLEAN_TRUE} - }; - - SLboolean required[MAX_NUMBER_INTERFACES]; - SLInterfaceID iidArray[MAX_NUMBER_INTERFACES]; - - /* Initialize arrays required[] and iidArray[] */ - for (int i=0 ; i < MAX_NUMBER_INTERFACES ; i++) { - required[i] = SL_BOOLEAN_FALSE; - iidArray[i] = SL_IID_NULL; - } - - iidArray[0] = SL_IID_ANDROIDEFFECTCAPABILITIES; - required[0] = SL_BOOLEAN_TRUE; - - - result = slCreateEngine( &sl, 1, EngineOption, 1, iidArray, required); - ExitOnError(result); - - /* Realizing the SL Engine in synchronous mode. */ - result = (*sl)->Realize(sl, SL_BOOLEAN_FALSE); - ExitOnError(result); - - - SLEngineItf EngineItf; - SLAndroidEffectCapabilitiesItf EffectLibItf; - - /* Get the SL Engine interface which is implicit */ - result = (*sl)->GetInterface(sl, SL_IID_ENGINE, (void*)&EngineItf); - ExitOnError(result); - - /* Get the Android Effect Capabilities interface */ - result = (*sl)->GetInterface(sl, SL_IID_ANDROIDEFFECTCAPABILITIES, (void*)&EffectLibItf); - ExitOnError(result); - - /* ------------------------------------------------------ */ - /* Query the effect library */ - - SLuint32 nbEffects = 0; - result = (*EffectLibItf)->QueryNumEffects(EffectLibItf, &nbEffects); - ExitOnError(result); - fprintf(stdout, "Effect library contains %d effects:\n", nbEffects); - - SLchar effectName[FX_NAME_LENGTH+1]; - SLuint16 effectNameLength = FX_NAME_LENGTH; - char typeString[GUID_DISPLAY_LENGTH]; - char implString[GUID_DISPLAY_LENGTH]; - - SLInterfaceID effectType, effectImplementation; - for (SLuint32 i = 0 ; i < nbEffects ; i++ ) { - fprintf(stdout,"- effect %d: ", i); - memset(effectName, 'Z', FX_NAME_LENGTH+1); - effectNameLength = FX_NAME_LENGTH; - result = (*EffectLibItf)->QueryEffect(EffectLibItf, i, - &effectType, &effectImplementation, effectName, &effectNameLength); - if ('Z' != effectName[FX_NAME_LENGTH]) { - fprintf(stderr, "QueryEffect wrote beyond end of buffer\n"); - continue; - } - ExitOnError(result); - printf("length=%u ", effectNameLength); - if (FX_NAME_LENGTH < effectNameLength) { - printf(" (>max) "); - effectNameLength = FX_NAME_LENGTH; - } - guidToString(effectType, typeString); - guidToString(effectImplementation, implString); - effectName[FX_NAME_LENGTH - 1] = '\0'; - fprintf(stdout, " type=%s, impl=%s name=%.*s \n", typeString, implString, effectNameLength, - effectName); - } - - /* Shutdown OpenSL ES */ - (*sl)->Destroy(sl); -} - -//----------------------------------------------------------------- -int main(int argc, char* const argv[]) -{ - SLresult result; - SLObjectItf sl; - - fprintf(stdout, "OpenSL ES test %s: exercises SLAndroidEffectCapabilitiesItf.\n", argv[0]); - - TestGenericFxCapabilities(); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/examples/slesTestEqFdPath.cpp b/wilhelm/tests/examples/slesTestEqFdPath.cpp deleted file mode 100644 index 4d5a80fb..00000000 --- a/wilhelm/tests/examples/slesTestEqFdPath.cpp +++ /dev/null @@ -1,338 +0,0 @@ -/* - * 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. - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <sys/time.h> -#include <fcntl.h> - -#include <SLES/OpenSLES.h> -#ifdef ANDROID -#include <SLES/OpenSLES_Android.h> -#endif - - -#define MAX_NUMBER_INTERFACES 3 - -#define TIME_S_BETWEEN_EQ_ON_OFF 3 - -//----------------------------------------------------------------- -/* Exits the application if an error is encountered */ -#define ExitOnError(x) ExitOnErrorFunc(x,__LINE__) - -void ExitOnErrorFunc( SLresult result , int line) -{ - if (SL_RESULT_SUCCESS != result) { - fprintf(stderr, "%u error code encountered at line %d, exiting\n", result, line); - exit(EXIT_FAILURE); - } -} - - -//----------------------------------------------------------------- - -/* Play an audio path by opening a file descriptor on that path */ -void TestEQPathFromFD( SLObjectItf sl, const char* path -#ifdef ANDROID - , SLAint64 offset, SLAint64 size -#endif - , bool alwaysOn - ) -{ - SLresult result; - SLEngineItf EngineItf; - - /* Objects this application uses: one player and an ouput mix */ - SLObjectItf player, outputMix; - - /* Source of audio data to play */ - SLDataSource audioSource; -#ifdef ANDROID - SLDataLocator_AndroidFD locatorFd; -#else - SLDataLocator_URI locatorUri; -#endif - SLDataFormat_MIME mime; - - /* Data sinks for the audio player */ - SLDataSink audioSink; - SLDataLocator_OutputMix locator_outputmix; - - /* Play and PrefetchStatus interfaces for the audio player */ - SLPlayItf playItf; - SLPrefetchStatusItf prefetchItf; - SLEqualizerItf eqItf; - - SLboolean required[MAX_NUMBER_INTERFACES]; - SLInterfaceID iidArray[MAX_NUMBER_INTERFACES]; - - /* Get the SL Engine Interface which is implicit */ - result = (*sl)->GetInterface(sl, SL_IID_ENGINE, (void*)&EngineItf); - ExitOnError(result); - - /* Initialize arrays required[] and iidArray[] */ - for (int i=0 ; i < MAX_NUMBER_INTERFACES ; i++) { - required[i] = SL_BOOLEAN_FALSE; - iidArray[i] = SL_IID_NULL; - } - - /* ------------------------------------------------------ */ - /* Configuration of the output mix */ - - /* Create Output Mix object to be used by the player */ - result = (*EngineItf)->CreateOutputMix(EngineItf, &outputMix, 1, iidArray, required); - ExitOnError(result); - - /* Realize the Output Mix object in synchronous mode */ - result = (*outputMix)->Realize(outputMix, SL_BOOLEAN_FALSE); - ExitOnError(result); - - /* Setup the data sink structure */ - locator_outputmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; - locator_outputmix.outputMix = outputMix; - audioSink.pLocator = (void*)&locator_outputmix; - audioSink.pFormat = NULL; - - /* ------------------------------------------------------ */ - /* Configuration of the player */ - - /* Set arrays required[] and iidArray[] for SLPrefetchStatusItf interfaces */ - /* (SLPlayItf is implicit) */ - required[0] = SL_BOOLEAN_TRUE; - iidArray[0] = SL_IID_PREFETCHSTATUS; - required[1] = SL_BOOLEAN_TRUE; - iidArray[1] = SL_IID_EQUALIZER; - - /* Setup the data source structure for the URI */ -#ifdef ANDROID - locatorFd.locatorType = SL_DATALOCATOR_ANDROIDFD; - int fd = open(path, O_RDONLY); - if (fd == -1) { - ExitOnError(SL_RESULT_RESOURCE_ERROR); - } - locatorFd.fd = (SLint32) fd; - locatorFd.length = size; - locatorFd.offset = offset; -#else - locatorUri.locatorType = SL_DATALOCATOR_URI; - locatorUri.URI = (SLchar *) path; -#endif - - mime.formatType = SL_DATAFORMAT_MIME; - /* this is how ignored mime information is specified, according to OpenSL ES spec - * in 9.1.6 SLDataFormat_MIME and 8.23 SLMetadataTraversalItf GetChildInfo */ - mime.mimeType = (SLchar*)NULL; - mime.containerType = SL_CONTAINERTYPE_UNSPECIFIED; - - audioSource.pFormat = (void*)&mime; -#ifdef ANDROID - audioSource.pLocator = (void*)&locatorFd; -#else - audioSource.pLocator = (void*)&locatorUri; -#endif - - /* Create the audio player */ - result = (*EngineItf)->CreateAudioPlayer(EngineItf, &player, &audioSource, &audioSink, 2, - iidArray, required); - ExitOnError(result); - - /* Realize the player in synchronous mode. */ - result = (*player)->Realize(player, SL_BOOLEAN_FALSE); ExitOnError(result); - fprintf(stdout, "URI example: after Realize\n"); - - /* Get the SLPlayItf, SLPrefetchStatusItf and SLAndroidStreamTypeItf interfaces for the player*/ - result = (*player)->GetInterface(player, SL_IID_PLAY, (void*)&playItf); - ExitOnError(result); - - result = (*player)->GetInterface(player, SL_IID_PREFETCHSTATUS, (void*)&prefetchItf); - ExitOnError(result); - - result = (*player)->GetInterface(player, SL_IID_EQUALIZER, (void*)&eqItf); - ExitOnError(result); - - fprintf(stdout, "Player configured\n"); - - /* ------------------------------------------------------ */ - /* Playback and test */ - - /* Start the data prefetching by setting the player to the paused state */ - result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PAUSED ); - ExitOnError(result); - - /* Wait until there's data to play */ - SLuint32 prefetchStatus = SL_PREFETCHSTATUS_UNDERFLOW; - while (prefetchStatus != SL_PREFETCHSTATUS_SUFFICIENTDATA) { - usleep(100 * 1000); - (*prefetchItf)->GetPrefetchStatus(prefetchItf, &prefetchStatus); - ExitOnError(result); - } - - /* Get duration */ - SLmillisecond durationInMsec = SL_TIME_UNKNOWN; - result = (*playItf)->GetDuration(playItf, &durationInMsec); - ExitOnError(result); - if (durationInMsec == SL_TIME_UNKNOWN) { - durationInMsec = 5000; - } - - /* Start playback */ - fprintf(stdout, "Starting to play\n"); - result = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_PLAYING ); - ExitOnError(result); - - /* Configure EQ */ - SLuint16 nbPresets, preset, nbBands = 0; - result = (*eqItf)->GetNumberOfBands(eqItf, &nbBands); - ExitOnError(result); - result = (*eqItf)->GetNumberOfPresets(eqItf, &nbPresets); - ExitOnError(result); - /* Start from a preset */ - preset = nbPresets > 2 ? 2 : 0; - result = (*eqItf)->UsePreset(eqItf, preset); - - preset = 1977; - result = (*eqItf)->GetCurrentPreset(eqItf, &preset); - ExitOnError(result); - if (SL_EQUALIZER_UNDEFINED == preset) { - fprintf(stderr, "Using SL_EQUALIZER_UNDEFINED preset, unexpected here!\n"); - } else { - fprintf(stdout, "Using preset %d\n", preset); - } - - /* Tweak it so it's obvious it gets turned on/off later */ - SLmillibel minLevel, maxLevel = 0; - result = (*eqItf)->GetBandLevelRange(eqItf, &minLevel, &maxLevel); - ExitOnError(result); - fprintf(stdout, "Band level range = %dmB to %dmB\n", minLevel, maxLevel); - - SLuint16 b = 0; - for(b = 0 ; b < nbBands/2 ; b++) { - result = (*eqItf)->SetBandLevel(eqItf, b, minLevel); - ExitOnError(result); - } - for(b = nbBands/2 ; b < nbBands ; b++) { - result = (*eqItf)->SetBandLevel(eqItf, b, maxLevel); - ExitOnError(result); - } - - SLmillibel level = 0; - for(b = 0 ; b < nbBands ; b++) { - result = (*eqItf)->GetBandLevel(eqItf, b, &level); - ExitOnError(result); - fprintf(stdout, "Band %d level = %dmB\n", b, level); - } - - /* Switch EQ on/off every TIME_S_BETWEEN_EQ_ON_OFF seconds unless always on */ - SLboolean previousEnabled = SL_BOOLEAN_FALSE; - for(unsigned int j=0 ; j<(durationInMsec/(1000*TIME_S_BETWEEN_EQ_ON_OFF)) ; j++) { - SLboolean enabled; - result = (*eqItf)->IsEnabled(eqItf, &enabled); - ExitOnError(result); - enabled = alwaysOn || !enabled; - if (enabled != previousEnabled) { - result = (*eqItf)->SetEnabled(eqItf, enabled); - ExitOnError(result); - previousEnabled = enabled; - if (SL_BOOLEAN_TRUE == enabled) { - fprintf(stdout, "EQ on\n"); - } else { - fprintf(stdout, "EQ off\n"); - } - } - usleep(TIME_S_BETWEEN_EQ_ON_OFF * 1000 * 1000); - } - - /* Make sure player is stopped */ - fprintf(stdout, "Stopping playback\n"); - result = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED); - ExitOnError(result); - - /* Destroy the player */ - (*player)->Destroy(player); - - /* Destroy Output Mix object */ - (*outputMix)->Destroy(outputMix); - -#ifdef ANDROID - close(fd); -#endif -} - -//----------------------------------------------------------------- -int main(int argc, char* const argv[]) -{ - const char *programName = argv[0]; - SLresult result; - SLObjectItf sl; - - fprintf(stdout, "OpenSL ES test %s: exercises SLEqualizerItf ", programName); - fprintf(stdout, "and AudioPlayer with SLDataLocator_AndroidFD source / OutputMix sink\n"); - fprintf(stdout, "Plays the sound file designated by the given path, "); - fprintf(stdout, "starting at the specified offset, and using the specified length.\n"); - fprintf(stdout, "Omit the length of the file for it to be computed by the system.\n"); - fprintf(stdout, "Every %d seconds, the EQ will be turned on and off,\n", - TIME_S_BETWEEN_EQ_ON_OFF); - fprintf(stdout, "unless the --always-on option is specified before the path.\n"); - - bool alwaysOn = false; - if (argc >= 2 && !strcmp(argv[1], "--always-on")) { - alwaysOn = true; - --argc; - ++argv; - } - -#ifdef ANDROID - if (argc < 3) -#else - if (argc < 1) -#endif - { - fprintf(stdout, "Usage: \t%s [--always-on] path offsetInBytes [sizeInBytes]\n", - programName); - fprintf(stdout, "Example: \"%s /sdcard/my.mp3 0 344460\" \n", programName); - exit(EXIT_FAILURE); - } - - SLEngineOption EngineOption[] = { - {(SLuint32) SL_ENGINEOPTION_THREADSAFE, (SLuint32) SL_BOOLEAN_TRUE} - }; - - result = slCreateEngine( &sl, 1, EngineOption, 0, NULL, NULL); - ExitOnError(result); - - /* Realizing the SL Engine in synchronous mode. */ - result = (*sl)->Realize(sl, SL_BOOLEAN_FALSE); - ExitOnError(result); - -#ifdef ANDROID - if (argc == 3) { - fprintf(stdout, "\nno file size given, using SL_DATALOCATOR_ANDROIDFD_USE_FILE_SIZE\n\n"); - TestEQPathFromFD(sl, argv[1], (SLAint64)atoi(argv[2]), - SL_DATALOCATOR_ANDROIDFD_USE_FILE_SIZE, alwaysOn); - } else { - TestEQPathFromFD(sl, argv[1], (SLAint64)atoi(argv[2]), (SLAint64)atoi(argv[3]), alwaysOn); - } -#else - TestEQPathFromFD(sl, argv[1]); -#endif - - /* Shutdown OpenSL ES */ - (*sl)->Destroy(sl); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/examples/slesTestEqOutputPath.cpp b/wilhelm/tests/examples/slesTestEqOutputPath.cpp deleted file mode 100644 index 072cd962..00000000 --- a/wilhelm/tests/examples/slesTestEqOutputPath.cpp +++ /dev/null @@ -1,339 +0,0 @@ -/* - * 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. - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <sys/time.h> -#include <fcntl.h> - -#include <SLES/OpenSLES.h> -#ifdef ANDROID -#include <SLES/OpenSLES_Android.h> -#endif - - -#define MAX_NUMBER_INTERFACES 3 - -#define TIME_S_BETWEEN_EQ_ON_OFF 3 - -//----------------------------------------------------------------- -/* Exits the application if an error is encountered */ -#define ExitOnError(x) ExitOnErrorFunc(x,__LINE__) - -void ExitOnErrorFunc( SLresult result , int line) -{ - if (SL_RESULT_SUCCESS != result) { - fprintf(stderr, "%u error code encountered at line %d, exiting\n", result, line); - exit(EXIT_FAILURE); - } -} - - -//----------------------------------------------------------------- - -/* Play an audio path by opening a file descriptor on that path */ -void TestEQPathFromFD( SLObjectItf sl, const char* path -#ifdef ANDROID - , SLAint64 offset, SLAint64 size -#endif - , bool alwaysOn - ) -{ - SLresult result; - SLEngineItf EngineItf; - - /* Objects this application uses: one player and an ouput mix */ - SLObjectItf player, outputMix; - - /* Source of audio data to play */ - SLDataSource audioSource; -#ifdef ANDROID - SLDataLocator_AndroidFD locatorFd; -#else - SLDataLocator_URI locatorUri; -#endif - SLDataFormat_MIME mime; - - /* Data sinks for the audio player */ - SLDataSink audioSink; - SLDataLocator_OutputMix locator_outputmix; - - /* Play and PrefetchStatus interfaces for the audio player */ - SLPlayItf playItf; - SLPrefetchStatusItf prefetchItf; - - /* Effect interface for the output mix */ - SLEqualizerItf eqOutputItf; - - SLboolean required[MAX_NUMBER_INTERFACES]; - SLInterfaceID iidArray[MAX_NUMBER_INTERFACES]; - - /* Get the SL Engine Interface which is implicit */ - result = (*sl)->GetInterface(sl, SL_IID_ENGINE, (void*)&EngineItf); - ExitOnError(result); - - /* Initialize arrays required[] and iidArray[] */ - for (int i=0 ; i < MAX_NUMBER_INTERFACES ; i++) { - required[i] = SL_BOOLEAN_FALSE; - iidArray[i] = SL_IID_NULL; - } - - /* ------------------------------------------------------ */ - /* Configuration of the output mix */ - - /* Set arrays required[] and iidArray[] for SLEqualizerItf interface */ - required[0] = SL_BOOLEAN_TRUE; - iidArray[0] = SL_IID_EQUALIZER; - - /* Create Output Mix object to be used by the player */ - result = (*EngineItf)->CreateOutputMix(EngineItf, &outputMix, 1, iidArray, required); - ExitOnError(result); - - /* Realize the Output Mix object in synchronous mode */ - result = (*outputMix)->Realize(outputMix, SL_BOOLEAN_FALSE); - ExitOnError(result); - - /* Get the SLEqualizerItf interface */ - result = (*outputMix)->GetInterface(outputMix, SL_IID_EQUALIZER, (void*)&eqOutputItf); - - /* Setup the data sink structure */ - locator_outputmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; - locator_outputmix.outputMix = outputMix; - audioSink.pLocator = (void*)&locator_outputmix; - audioSink.pFormat = NULL; - - /* ------------------------------------------------------ */ - /* Configuration of the player */ - - /* Set arrays required[] and iidArray[] for SLPrefetchStatusItf interfaces */ - /* (SLPlayItf is implicit) */ - required[0] = SL_BOOLEAN_TRUE; - iidArray[0] = SL_IID_PREFETCHSTATUS; - - /* Setup the data source structure for the URI */ -#ifdef ANDROID - locatorFd.locatorType = SL_DATALOCATOR_ANDROIDFD; - int fd = open(path, O_RDONLY); - if (fd == -1) { - ExitOnError(SL_RESULT_RESOURCE_ERROR); - } - locatorFd.fd = (SLint32) fd; - locatorFd.length = size; - locatorFd.offset = offset; -#else - locatorUri.locatorType = SL_DATALOCATOR_URI; - locatorUri.URI = (SLchar *) path; -#endif - - mime.formatType = SL_DATAFORMAT_MIME; - /* this is how ignored mime information is specified, according to OpenSL ES spec - * in 9.1.6 SLDataFormat_MIME and 8.23 SLMetadataTraversalItf GetChildInfo */ - mime.mimeType = (SLchar*)NULL; - mime.containerType = SL_CONTAINERTYPE_UNSPECIFIED; - - audioSource.pFormat = (void*)&mime; -#ifdef ANDROID - audioSource.pLocator = (void*)&locatorFd; -#else - audioSource.pLocator = (void*)&locatorUri; -#endif - - /* Create the audio player */ - result = (*EngineItf)->CreateAudioPlayer(EngineItf, &player, &audioSource, &audioSink, 1, - iidArray, required); - ExitOnError(result); - - /* Realize the player in synchronous mode. */ - result = (*player)->Realize(player, SL_BOOLEAN_FALSE); ExitOnError(result); - fprintf(stdout, "URI example: after Realize\n"); - - /* Get the SLPlayItf, SLPrefetchStatusItf and SLAndroidStreamTypeItf interfaces for the player*/ - result = (*player)->GetInterface(player, SL_IID_PLAY, (void*)&playItf); - ExitOnError(result); - - result = (*player)->GetInterface(player, SL_IID_PREFETCHSTATUS, (void*)&prefetchItf); - ExitOnError(result); - - fprintf(stdout, "Player configured\n"); - - /* ------------------------------------------------------ */ - /* Playback and test */ - - /* Start the data prefetching by setting the player to the paused state */ - result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PAUSED ); - ExitOnError(result); - - /* Wait until there's data to play */ - SLuint32 prefetchStatus = SL_PREFETCHSTATUS_UNDERFLOW; - while (prefetchStatus != SL_PREFETCHSTATUS_SUFFICIENTDATA) { - usleep(100 * 1000); - (*prefetchItf)->GetPrefetchStatus(prefetchItf, &prefetchStatus); - ExitOnError(result); - } - - /* Get duration */ - SLmillisecond durationInMsec = SL_TIME_UNKNOWN; - result = (*playItf)->GetDuration(playItf, &durationInMsec); - ExitOnError(result); - if (durationInMsec == SL_TIME_UNKNOWN) { - durationInMsec = 5000; - } - - /* Start playback */ - fprintf(stdout, "Starting to play\n"); - result = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_PLAYING ); - ExitOnError(result); - - /* Configure EQ */ - SLuint16 nbPresets, preset, nbBands = 0; - result = (*eqOutputItf)->GetNumberOfBands(eqOutputItf, &nbBands); - ExitOnError(result); - result = (*eqOutputItf)->GetNumberOfPresets(eqOutputItf, &nbPresets); - ExitOnError(result); - /* Start from a preset */ - preset = nbPresets > 2 ? 2 : 0; - result = (*eqOutputItf)->UsePreset(eqOutputItf, preset); - - preset = 1977; - result = (*eqOutputItf)->GetCurrentPreset(eqOutputItf, &preset); - ExitOnError(result); - if (SL_EQUALIZER_UNDEFINED == preset) { - fprintf(stderr, "Using SL_EQUALIZER_UNDEFINED preset, unexpected here!\n"); - } else { - fprintf(stdout, "Using preset %d\n", preset); - } - - /* Tweak it so it's obvious it gets turned on/off later */ - SLmillibel minLevel, maxLevel = 0; - result = (*eqOutputItf)->GetBandLevelRange(eqOutputItf, &minLevel, &maxLevel); - ExitOnError(result); - fprintf(stdout, "Band level range = %dmB to %dmB\n", minLevel, maxLevel); - - SLuint16 b = 0; - for(b = 0 ; b < nbBands/2 ; b++) { - result = (*eqOutputItf)->SetBandLevel(eqOutputItf, b, minLevel); - ExitOnError(result); - } - for(b = nbBands/2 ; b < nbBands ; b++) { - result = (*eqOutputItf)->SetBandLevel(eqOutputItf, b, maxLevel); - ExitOnError(result); - } - - SLmillibel level = 0; - for(b = 0 ; b < nbBands ; b++) { - result = (*eqOutputItf)->GetBandLevel(eqOutputItf, b, &level); - ExitOnError(result); - fprintf(stdout, "Band %d level = %dmB\n", b, level); - } - - /* Switch EQ on/off every TIME_S_BETWEEN_EQ_ON_OFF seconds unless always on */ - SLboolean previousEnabled = SL_BOOLEAN_FALSE; - for(unsigned int j=0 ; j<(durationInMsec/(1000*TIME_S_BETWEEN_EQ_ON_OFF)) ; j++) { - SLboolean enabled; - result = (*eqOutputItf)->IsEnabled(eqOutputItf, &enabled); - ExitOnError(result); - enabled = alwaysOn || !enabled; - if (enabled != previousEnabled) { - result = (*eqOutputItf)->SetEnabled(eqOutputItf, enabled); - ExitOnError(result); - previousEnabled = enabled; - if (SL_BOOLEAN_TRUE == enabled) { - fprintf(stdout, "EQ on\n"); - } else { - fprintf(stdout, "EQ off\n"); - } - } - usleep(TIME_S_BETWEEN_EQ_ON_OFF * 1000 * 1000); - } - - /* Make sure player is stopped */ - fprintf(stdout, "Stopping playback\n"); - result = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED); - ExitOnError(result); - - /* Destroy the player */ - (*player)->Destroy(player); - - /* Destroy Output Mix object */ - (*outputMix)->Destroy(outputMix); - -#ifdef ANDROID - close(fd); -#endif -} - -//----------------------------------------------------------------- -int main(int argc, char* const argv[]) -{ - const char *programName = argv[0]; - SLresult result; - SLObjectItf sl; - - fprintf(stdout, "OpenSL ES test %s: exercises SLEqualizerItf ", programName); - fprintf(stdout, "on an OutputMix object\n"); - fprintf(stdout, "Plays the sound file designated by the given path, "); - fprintf(stdout, "starting at the specified offset, and using the specified length.\n"); - fprintf(stdout, "Omit the length of the file for it to be computed by the system.\n"); - fprintf(stdout, "Every %d seconds, the EQ will be turned on and off,\n", - TIME_S_BETWEEN_EQ_ON_OFF); - fprintf(stdout, "unless the --always-on option is specified before the path.\n"); - - bool alwaysOn = false; - if (argc >= 2 && !strcmp(argv[1], "--always-on")) { - alwaysOn = true; - --argc; - ++argv; - } - -#ifdef ANDROID - if (argc < 3) { - fprintf(stdout, "Usage: \t%s [--always-on] path offsetInBytes [sizeInBytes]\n", - programName); - fprintf(stdout, "Example: \"%s /sdcard/my.mp3 0 344460\" \n", programName); - exit(EXIT_FAILURE); - } -#endif - - SLEngineOption EngineOption[] = { - {(SLuint32) SL_ENGINEOPTION_THREADSAFE, (SLuint32) SL_BOOLEAN_TRUE} - }; - - result = slCreateEngine( &sl, 1, EngineOption, 0, NULL, NULL); - ExitOnError(result); - - /* Realizing the SL Engine in synchronous mode. */ - result = (*sl)->Realize(sl, SL_BOOLEAN_FALSE); - ExitOnError(result); - -#ifdef ANDROID - if (argc == 3) { - fprintf(stdout, "\nno file size given, using SL_DATALOCATOR_ANDROIDFD_USE_FILE_SIZE\n\n"); - TestEQPathFromFD(sl, argv[1], (SLAint64)atoi(argv[2]), - SL_DATALOCATOR_ANDROIDFD_USE_FILE_SIZE, alwaysOn); - } else { - TestEQPathFromFD(sl, argv[1], (SLAint64)atoi(argv[2]), (SLAint64)atoi(argv[3]), alwaysOn); - } -#else - TestEQPathFromFD(sl, argv[1], alwaysOn); -#endif - - /* Shutdown OpenSL ES */ - (*sl)->Destroy(sl); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/examples/slesTestFeedback.cpp b/wilhelm/tests/examples/slesTestFeedback.cpp deleted file mode 100644 index 80d9d327..00000000 --- a/wilhelm/tests/examples/slesTestFeedback.cpp +++ /dev/null @@ -1,425 +0,0 @@ -/* - * 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. - */ - -// Test program to record from default audio input and playback to default audio output. -// It will generate feedback (Larsen effect) if played through on-device speakers, -// or acts as a delay if played through headset. - -#include <SLES/OpenSLES.h> -#include <SLES/OpenSLES_Android.h> -#include <assert.h> -#include <pthread.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#define ASSERT_EQ(x, y) do { if ((x) == (y)) ; else { fprintf(stderr, "0x%x != 0x%x\n", \ - (unsigned) (x), (unsigned) (y)); assert((x) == (y)); } } while (0) - -// default values -static SLuint32 rxBufCount = 2; // -r# -static SLuint32 txBufCount = 2; // -t# -static SLuint32 bufSizeInFrames = 512; // -f# -static SLuint32 channels = 1; // -c# -static SLuint32 sampleRate = 44100; // -s# -static SLuint32 exitAfterSeconds = 60; // -e# -static SLuint32 freeBufCount = 0; // calculated -static SLuint32 bufSizeInBytes = 0; // calculated - -// Storage area for the buffer queues -static char **rxBuffers; -static char **txBuffers; -static char **freeBuffers; - -// Buffer indices -static SLuint32 rxFront; // oldest recording -static SLuint32 rxRear; // next to be recorded -static SLuint32 txFront; // oldest playing -static SLuint32 txRear; // next to be played -static SLuint32 freeFront; // oldest free -static SLuint32 freeRear; // next to be freed - -static SLAndroidSimpleBufferQueueItf recorderBufferQueue; -static SLBufferQueueItf playerBufferQueue; - -static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; - -// Called after audio recorder fills a buffer with data -static void recorderCallback(SLAndroidSimpleBufferQueueItf caller, void *context) -{ - SLresult result; - - pthread_mutex_lock(&mutex); - - // We should only be called when a recording buffer is done - assert(rxFront <= rxBufCount); - assert(rxRear <= rxBufCount); - assert(rxFront != rxRear); - char *buffer = rxBuffers[rxFront]; - - // Remove buffer from record queue - if (++rxFront > rxBufCount) { - rxFront = 0; - } - - // Enqueue the just-filled buffer for the player - result = (*playerBufferQueue)->Enqueue(playerBufferQueue, buffer, bufSizeInBytes); - if (SL_RESULT_SUCCESS == result) { - - // There was room in the play queue, update our model of it - assert(txFront <= txBufCount); - assert(txRear <= txBufCount); - SLuint32 txRearNext = txRear+1; - if (txRearNext > txBufCount) { - txRearNext = 0; - } - assert(txRearNext != txFront); - txBuffers[txRear] = buffer; - txRear = txRearNext; - - } else { - - // Here if record has a filled buffer to play, but play queue is full. - assert(SL_RESULT_BUFFER_INSUFFICIENT == result); - write(1, "?", 1); - - // We could either try again later, or discard. For now we discard and re-use buffer. - // Enqueue this same buffer for the recorder to fill again. - result = (*recorderBufferQueue)->Enqueue(recorderBufferQueue, buffer, bufSizeInBytes); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - - // Update our model of the record queue - SLuint32 rxRearNext = rxRear+1; - if (rxRearNext > rxBufCount) { - rxRearNext = 0; - } - assert(rxRearNext != rxFront); - rxBuffers[rxRear] = buffer; - rxRear = rxRearNext; - - } - - pthread_mutex_unlock(&mutex); -} - - -// Called after audio player empties a buffer of data -static void playerCallback(SLBufferQueueItf caller, void *context) -{ - SLresult result; - - pthread_mutex_lock(&mutex); - - // Get the buffer that just finished playing - assert(txFront <= txBufCount); - assert(txRear <= txBufCount); - assert(txFront != txRear); - char *buffer = txBuffers[txFront]; - if (++txFront > txBufCount) { - txFront = 0; - } - - // First try to enqueue the free buffer for recording - result = (*recorderBufferQueue)->Enqueue(recorderBufferQueue, buffer, bufSizeInBytes); - if (SL_RESULT_SUCCESS == result) { - - // There was room in the record queue, update our model of it - assert(rxFront <= rxBufCount); - assert(rxRear <= rxBufCount); - SLuint32 rxRearNext = rxRear+1; - if (rxRearNext > rxBufCount) { - rxRearNext = 0; - } - assert(rxRearNext != rxFront); - rxBuffers[rxRear] = buffer; - rxRear = rxRearNext; - - } else { - - // Here if record queue is full - assert(SL_RESULT_BUFFER_INSUFFICIENT == result); - - // Instead enqueue the free buffer on the free queue - assert(freeFront <= freeBufCount); - assert(freeRear <= freeBufCount); - SLuint32 freeRearNext = freeRear+1; - if (freeRearNext > freeBufCount) { - freeRearNext = 0; - } - // There must always be room in the free queue - assert(freeRearNext != freeFront); - freeBuffers[freeRear] = buffer; - freeRear = freeRearNext; - - } - - pthread_mutex_unlock(&mutex); -} - -// Main program -int main(int argc, char **argv) -{ - // process command-line options - int i; - for (i = 1; i < argc; ++i) { - char *arg = argv[i]; - if (arg[0] != '-') { - break; - } - // -r# number of slots in receive buffer queue - if (!strncmp(arg, "-r", 2)) { - rxBufCount = atoi(&arg[2]); - if (rxBufCount < 1 || rxBufCount > 16) { - fprintf(stderr, "%s: unusual receive buffer queue size (%u buffers)\n", argv[0], - (unsigned) rxBufCount); - } - // -t# number of slots in transmit buffer queue - } else if (!strncmp(arg, "-t", 2)) { - txBufCount = atoi(&arg[2]); - if (txBufCount < 1 || txBufCount > 16) { - fprintf(stderr, "%s: unusual transmit buffer queue size (%u buffers)\n", argv[0], - (unsigned) txBufCount); - } - // -f# size of each buffer in frames - } else if (!strncmp(arg, "-f", 2)) { - bufSizeInFrames = atoi(&arg[2]); - if (bufSizeInFrames == 0) { - fprintf(stderr, "%s: unusual buffer size (%u frames)\n", argv[0], - (unsigned) bufSizeInFrames); - } - // -c1 mono or -c2 stereo - } else if (!strncmp(arg, "-c", 2)) { - channels = atoi(&arg[2]); - if (channels < 1 || channels > 2) { - fprintf(stderr, "%s: unusual channel count ignored (%u)\n", argv[0], - (unsigned) channels); - channels = 2; - } - // -s# sample rate in Hz - } else if (!strncmp(arg, "-s", 2)) { - sampleRate = atoi(&arg[2]); - switch (sampleRate) { - case 8000: - case 11025: - case 12000: - case 16000: - case 22050: - case 24000: - case 32000: - case 44100: - case 48000: - break; - default: - fprintf(stderr, "%s: unusual sample rate (%u Hz)\n", argv[0], - (unsigned) sampleRate); - break; - } - // -e# exit after this many seconds - } else if (!strncmp(arg, "-e", 2)) { - exitAfterSeconds = atoi(&arg[2]); - } else - fprintf(stderr, "%s: unknown option %s\n", argv[0], arg); - } - // no other arguments allowed - if (i < argc) { - fprintf(stderr, "usage: %s -r# -t# -f# -s# -c#\n", argv[0]); - fprintf(stderr, " -r# receive buffer queue count for microphone input, default 1\n"); - fprintf(stderr, " -t# transmit buffer queue count for speaker output, default 2\n"); - fprintf(stderr, " -f# number of frames per buffer, default 512\n"); - fprintf(stderr, " -s# sample rate in Hz, default 44100\n"); - fprintf(stderr, " -c1 mono\n"); - fprintf(stderr, " -c2 stereo, default\n"); - } - // compute total free buffers as -r plus -t - freeBufCount = rxBufCount + txBufCount; - // compute buffer size - bufSizeInBytes = channels * bufSizeInFrames * sizeof(short); - - // Initialize free buffers - freeBuffers = (char **) calloc(freeBufCount+1, sizeof(char *)); - unsigned j; - for (j = 0; j < freeBufCount; ++j) { - freeBuffers[j] = (char *) malloc(bufSizeInBytes); - } - freeFront = 0; - freeRear = freeBufCount; - freeBuffers[j] = NULL; - - // Initialize record queue - rxBuffers = (char **) calloc(rxBufCount+1, sizeof(char *)); - rxFront = 0; - rxRear = 0; - - // Initialize play queue - txBuffers = (char **) calloc(txBufCount+1, sizeof(char *)); - txFront = 0; - txRear = 0; - - SLresult result; - - // create engine - SLObjectItf engineObject; - result = slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - SLEngineItf engineEngine; - result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - - // create output mix - SLObjectItf outputmixObject; - result = (*engineEngine)->CreateOutputMix(engineEngine, &outputmixObject, 0, NULL, NULL); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - result = (*outputmixObject)->Realize(outputmixObject, SL_BOOLEAN_FALSE); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - - // create an audio player with buffer queue source and output mix sink - SLDataSource audiosrc; - SLDataSink audiosnk; - SLDataFormat_PCM pcm; - SLDataLocator_OutputMix locator_outputmix; - SLDataLocator_BufferQueue locator_bufferqueue_tx; - locator_bufferqueue_tx.locatorType = SL_DATALOCATOR_BUFFERQUEUE; - locator_bufferqueue_tx.numBuffers = txBufCount; - locator_outputmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; - locator_outputmix.outputMix = outputmixObject; - pcm.formatType = SL_DATAFORMAT_PCM; - pcm.numChannels = channels; - pcm.samplesPerSec = sampleRate * 1000; - pcm.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_16; - pcm.containerSize = 16; - pcm.channelMask = channels == 1 ? SL_SPEAKER_FRONT_CENTER : - (SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT); - pcm.endianness = SL_BYTEORDER_LITTLEENDIAN; - audiosrc.pLocator = &locator_bufferqueue_tx; - audiosrc.pFormat = &pcm; - audiosnk.pLocator = &locator_outputmix; - audiosnk.pFormat = NULL; - SLObjectItf playerObject = NULL; - SLObjectItf recorderObject = NULL; - SLInterfaceID ids_tx[1] = {SL_IID_BUFFERQUEUE}; - SLboolean flags_tx[1] = {SL_BOOLEAN_TRUE}; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audiosrc, &audiosnk, - 1, ids_tx, flags_tx); - if (SL_RESULT_CONTENT_UNSUPPORTED == result) { - fprintf(stderr, "Could not create audio player (result %x), check sample rate\n", result); - goto cleanup; - } - ASSERT_EQ(SL_RESULT_SUCCESS, result); - result = (*playerObject)->Realize(playerObject, SL_BOOLEAN_FALSE); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - SLPlayItf playerPlay; - result = (*playerObject)->GetInterface(playerObject, SL_IID_PLAY, &playerPlay); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - result = (*playerObject)->GetInterface(playerObject, SL_IID_BUFFERQUEUE, &playerBufferQueue); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - result = (*playerBufferQueue)->RegisterCallback(playerBufferQueue, playerCallback, NULL); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - result = (*playerPlay)->SetPlayState(playerPlay, SL_PLAYSTATE_PLAYING); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - - // Create an audio recorder with microphone device source and buffer queue sink. - // The buffer queue as sink is an Android-specific extension. - - SLDataLocator_IODevice locator_iodevice; - SLDataLocator_AndroidSimpleBufferQueue locator_bufferqueue_rx; - locator_iodevice.locatorType = SL_DATALOCATOR_IODEVICE; - locator_iodevice.deviceType = SL_IODEVICE_AUDIOINPUT; - locator_iodevice.deviceID = SL_DEFAULTDEVICEID_AUDIOINPUT; - locator_iodevice.device = NULL; - audiosrc.pLocator = &locator_iodevice; - audiosrc.pFormat = NULL; - locator_bufferqueue_rx.locatorType = SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE; - locator_bufferqueue_rx.numBuffers = rxBufCount; - audiosnk.pLocator = &locator_bufferqueue_rx; - audiosnk.pFormat = &pcm; - { - SLInterfaceID ids_rx[1] = {SL_IID_ANDROIDSIMPLEBUFFERQUEUE}; - SLboolean flags_rx[1] = {SL_BOOLEAN_TRUE}; - result = (*engineEngine)->CreateAudioRecorder(engineEngine, &recorderObject, &audiosrc, - &audiosnk, 1, ids_rx, flags_rx); - if (SL_RESULT_SUCCESS != result) { - fprintf(stderr, "Could not create audio recorder (result %x), " - "check sample rate and channel count\n", result); - goto cleanup; - } - } - ASSERT_EQ(SL_RESULT_SUCCESS, result); - result = (*recorderObject)->Realize(recorderObject, SL_BOOLEAN_FALSE); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - SLRecordItf recorderRecord; - result = (*recorderObject)->GetInterface(recorderObject, SL_IID_RECORD, &recorderRecord); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - result = (*recorderObject)->GetInterface(recorderObject, SL_IID_ANDROIDSIMPLEBUFFERQUEUE, - &recorderBufferQueue); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - result = (*recorderBufferQueue)->RegisterCallback(recorderBufferQueue, recorderCallback, NULL); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - - // Enqueue some empty buffers for the recorder - for (j = 0; j < rxBufCount; ++j) { - - // allocate a free buffer - assert(freeFront != freeRear); - char *buffer = freeBuffers[freeFront]; - if (++freeFront > freeBufCount) { - freeFront = 0; - } - - // put on record queue - SLuint32 rxRearNext = rxRear + 1; - if (rxRearNext > rxBufCount) { - rxRearNext = 0; - } - assert(rxRearNext != rxFront); - rxBuffers[rxRear] = buffer; - rxRear = rxRearNext; - result = (*recorderBufferQueue)->Enqueue(recorderBufferQueue, - buffer, bufSizeInBytes); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - } - - // Kick off the recorder - result = (*recorderRecord)->SetRecordState(recorderRecord, SL_RECORDSTATE_RECORDING); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - - // Wait patiently - do { - usleep(1000000); - write(1, ".", 1); - SLBufferQueueState playerBQState; - result = (*playerBufferQueue)->GetState(playerBufferQueue, &playerBQState); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - SLAndroidSimpleBufferQueueState recorderBQState; - result = (*recorderBufferQueue)->GetState(recorderBufferQueue, &recorderBQState); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - } while (--exitAfterSeconds); - - // Tear down the objects and exit -cleanup: - if (NULL != playerObject) { - (*playerObject)->Destroy(playerObject); - } - if (NULL != recorderObject) { - (*recorderObject)->Destroy(recorderObject); - } - (*outputmixObject)->Destroy(outputmixObject); - (*engineObject)->Destroy(engineObject); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/examples/slesTestPlayFdPath.cpp b/wilhelm/tests/examples/slesTestPlayFdPath.cpp deleted file mode 100644 index 92532a78..00000000 --- a/wilhelm/tests/examples/slesTestPlayFdPath.cpp +++ /dev/null @@ -1,231 +0,0 @@ -/* - * 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. - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <sys/time.h> -#include <fcntl.h> - -#include <SLES/OpenSLES.h> -#include <SLES/OpenSLES_Android.h> - - -#define MAX_NUMBER_INTERFACES 3 - -#define TEST_MUTE 0 -#define TEST_SOLO 1 - -static int testMode; -//----------------------------------------------------------------- -/* Exits the application if an error is encountered */ -#define ExitOnError(x) ExitOnErrorFunc(x,__LINE__) - -void ExitOnErrorFunc( SLresult result , int line) -{ - if (SL_RESULT_SUCCESS != result) { - fprintf(stdout, "%u error code encountered at line %d, exiting\n", result, line); - exit(EXIT_FAILURE); - } -} - - -//----------------------------------------------------------------- - -/* Play an audio path by opening a file descriptor on that path */ -void TestPlayPathFromFD( SLObjectItf sl, const char* path, SLAint64 offset, SLAint64 size) -{ - SLresult result; - SLEngineItf EngineItf; - - /* Objects this application uses: one player and an ouput mix */ - SLObjectItf player, outputMix; - - /* Source of audio data to play */ - SLDataSource audioSource; - SLDataLocator_AndroidFD locatorFd; - SLDataFormat_MIME mime; - - /* Data sinks for the audio player */ - SLDataSink audioSink; - SLDataLocator_OutputMix locator_outputmix; - - /* Play and PrefetchStatus interfaces for the audio player */ - SLPlayItf playItf; - SLPrefetchStatusItf prefetchItf; - - SLboolean required[MAX_NUMBER_INTERFACES]; - SLInterfaceID iidArray[MAX_NUMBER_INTERFACES]; - - /* Get the SL Engine Interface which is implicit */ - result = (*sl)->GetInterface(sl, SL_IID_ENGINE, (void*)&EngineItf); - ExitOnError(result); - - /* Initialize arrays required[] and iidArray[] */ - for (int i=0 ; i < MAX_NUMBER_INTERFACES ; i++) { - required[i] = SL_BOOLEAN_FALSE; - iidArray[i] = SL_IID_NULL; - } - - /* ------------------------------------------------------ */ - /* Configuration of the output mix */ - - /* Create Output Mix object to be used by the player */ - result = (*EngineItf)->CreateOutputMix(EngineItf, &outputMix, 0, iidArray, required); - ExitOnError(result); - - /* Realize the Output Mix object in synchronous mode */ - result = (*outputMix)->Realize(outputMix, SL_BOOLEAN_FALSE); - ExitOnError(result); - - /* Setup the data sink structure */ - locator_outputmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; - locator_outputmix.outputMix = outputMix; - audioSink.pLocator = (void*)&locator_outputmix; - audioSink.pFormat = NULL; - - /* ------------------------------------------------------ */ - /* Configuration of the player */ - - /* Set arrays required[] and iidArray[] for SLPrefetchStatusItf interfaces */ - /* (SLPlayItf is implicit) */ - required[0] = SL_BOOLEAN_TRUE; - iidArray[0] = SL_IID_PREFETCHSTATUS; - - /* Setup the data source structure for the URI */ - locatorFd.locatorType = SL_DATALOCATOR_ANDROIDFD; - int fd = open(path, O_RDONLY); - if (fd == -1) { - perror(path); - exit(EXIT_FAILURE); - } - locatorFd.fd = (SLint32) fd; - locatorFd.length = size; - locatorFd.offset = offset; - - mime.formatType = SL_DATAFORMAT_MIME; - /* this is how ignored mime information is specified, according to OpenSL ES spec - * in 9.1.6 SLDataFormat_MIME and 8.23 SLMetadataTraversalItf GetChildInfo */ - mime.mimeType = (SLchar*)NULL; - mime.containerType = SL_CONTAINERTYPE_UNSPECIFIED; - - audioSource.pFormat = (void*)&mime; - audioSource.pLocator = (void*)&locatorFd; - - /* Create the audio player */ - result = (*EngineItf)->CreateAudioPlayer(EngineItf, &player, &audioSource, &audioSink, 1, - iidArray, required); - ExitOnError(result); - - /* Realize the player in synchronous mode. */ - result = (*player)->Realize(player, SL_BOOLEAN_FALSE); ExitOnError(result); - fprintf(stdout, "URI example: after Realize\n"); - - /* Get the SLPlayItf, SLPrefetchStatusItf and SLAndroidStreamTypeItf interfaces for the player*/ - result = (*player)->GetInterface(player, SL_IID_PLAY, (void*)&playItf); - ExitOnError(result); - - result = (*player)->GetInterface(player, SL_IID_PREFETCHSTATUS, (void*)&prefetchItf); - ExitOnError(result); - - fprintf(stdout, "Player configured\n"); - - /* ------------------------------------------------------ */ - /* Playback and test */ - - /* Start the data prefetching by setting the player to the paused state */ - result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PAUSED ); - ExitOnError(result); - - /* Wait until there's data to play */ - SLuint32 prefetchStatus = SL_PREFETCHSTATUS_UNDERFLOW; - while (prefetchStatus != SL_PREFETCHSTATUS_SUFFICIENTDATA) { - usleep(100 * 1000); - (*prefetchItf)->GetPrefetchStatus(prefetchItf, &prefetchStatus); - ExitOnError(result); - } - - /* Get duration */ - SLmillisecond durationInMsec = SL_TIME_UNKNOWN; - result = (*playItf)->GetDuration(playItf, &durationInMsec); - ExitOnError(result); - if (durationInMsec == SL_TIME_UNKNOWN) { - durationInMsec = 5000; - } - - /* Start playback */ - result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PLAYING ); - ExitOnError(result); - - usleep(durationInMsec * 1000); - - /* Make sure player is stopped */ - fprintf(stdout, "Stopping playback\n"); - result = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED); - ExitOnError(result); - - /* Destroy the player */ - (*player)->Destroy(player); - - /* Destroy Output Mix object */ - (*outputMix)->Destroy(outputMix); - - close(fd); -} - -//----------------------------------------------------------------- -int main(int argc, char* const argv[]) -{ - SLresult result; - SLObjectItf sl; - - fprintf(stdout, "OpenSL ES test %s: exercises SLPlayItf ", argv[0]); - fprintf(stdout, "and AudioPlayer with SLDataLocator_AndroidFD source / OutputMix sink\n"); - fprintf(stdout, "Plays the sound file designated by the given path, "); - fprintf(stdout, "starting at the specified offset, and using the specified length.\n"); - fprintf(stdout, "Omit the length of the file for it to be computed by the system.\n"); - - if (argc < 3) { - fprintf(stdout, "Usage: \t%s path offsetInBytes [sizeInBytes]\n", argv[0]); - fprintf(stdout, "Example: \"%s /sdcard/my.mp3 0 344460\" \n", argv[0]); - exit(EXIT_FAILURE); - } - - SLEngineOption EngineOption[] = { - {(SLuint32) SL_ENGINEOPTION_THREADSAFE, (SLuint32) SL_BOOLEAN_TRUE} - }; - - result = slCreateEngine( &sl, 1, EngineOption, 0, NULL, NULL); - ExitOnError(result); - - /* Realizing the SL Engine in synchronous mode. */ - result = (*sl)->Realize(sl, SL_BOOLEAN_FALSE); - ExitOnError(result); - - if (argc == 3) { - fprintf(stdout, "no file size given, using SL_DATALOCATOR_ANDROIDFD_USE_FILE_SIZE\n"); - TestPlayPathFromFD(sl, argv[1], (SLAint64)atoi(argv[2]), - SL_DATALOCATOR_ANDROIDFD_USE_FILE_SIZE); - } else { - TestPlayPathFromFD(sl, argv[1], (SLAint64)atoi(argv[2]), (SLAint64)atoi(argv[3])); - } - - /* Shutdown OpenSL ES */ - (*sl)->Destroy(sl); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/examples/slesTestRecBuffQueue.cpp b/wilhelm/tests/examples/slesTestRecBuffQueue.cpp deleted file mode 100644 index 16ba1b45..00000000 --- a/wilhelm/tests/examples/slesTestRecBuffQueue.cpp +++ /dev/null @@ -1,382 +0,0 @@ -/* - * 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. - */ - -/* Audio Record Test - -First run the program from shell: - # slesTest_recBuffQueue /sdcard/myrec.raw 4 - -These use adb on host to retrive the file: - % adb pull /sdcard/myrec.raw myrec.raw - -How to examine the output with Audacity: - Project / Import raw data - Select myrec.raw file, then click Open button - Choose these options: - Signed 16-bit PCM - Little-endian - 1 Channel (Mono) - Sample rate 22050 Hz - Click Import button - -*/ - - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <sys/time.h> -#include <fcntl.h> - -#include <SLES/OpenSLES.h> -#include <SLES/OpenSLES_Android.h> - -/* Preset number to use for recording */ -SLuint32 presetValue = SL_ANDROID_RECORDING_PRESET_NONE; - -/* Explicitly requesting SL_IID_ANDROIDSIMPLEBUFFERQUEUE and SL_IID_ANDROIDCONFIGURATION - * on the AudioRecorder object */ -#define NUM_EXPLICIT_INTERFACES_FOR_RECORDER 2 - -/* Size of the recording buffer queue */ -#define NB_BUFFERS_IN_QUEUE 1 -/* Size of each buffer in the queue */ -#define BUFFER_SIZE_IN_SAMPLES 1024 -#define BUFFER_SIZE_IN_BYTES (2*BUFFER_SIZE_IN_SAMPLES) - -/* Local storage for Audio data */ -int8_t pcmData[NB_BUFFERS_IN_QUEUE * BUFFER_SIZE_IN_BYTES]; - -/* destination for recorded data */ -static FILE* gFp; - -//----------------------------------------------------------------- -/* Exits the application if an error is encountered */ -#define ExitOnError(x) ExitOnErrorFunc(x,__LINE__) - -void ExitOnErrorFunc( SLresult result , int line) -{ - if (SL_RESULT_SUCCESS != result) { - fprintf(stdout, "%u error code encountered at line %d, exiting\n", result, line); - exit(EXIT_FAILURE); - } -} - -//----------------------------------------------------------------- -/* Structure for passing information to callback function */ -typedef struct CallbackCntxt_ { - SLPlayItf playItf; - SLuint32 size; - SLint8* pDataBase; // Base address of local audio data storage - SLint8* pData; // Current address of local audio data storage -} CallbackCntxt; - - -//----------------------------------------------------------------- -/* Callback for recording buffer queue events */ -void RecCallback( - SLRecordItf caller, - void *pContext, - SLuint32 event) -{ - if (SL_RECORDEVENT_HEADATNEWPOS & event) { - SLmillisecond pMsec = 0; - (*caller)->GetPosition(caller, &pMsec); - fprintf(stdout, "SL_RECORDEVENT_HEADATNEWPOS current position=%ums\n", pMsec); - } - - if (SL_RECORDEVENT_HEADATMARKER & event) { - SLmillisecond pMsec = 0; - (*caller)->GetPosition(caller, &pMsec); - fprintf(stdout, "SL_RECORDEVENT_HEADATMARKER current position=%ums\n", pMsec); - } -} - -//----------------------------------------------------------------- -/* Callback for recording buffer queue events */ -void RecBufferQueueCallback( - SLAndroidSimpleBufferQueueItf queueItf, - void *pContext) -{ - //fprintf(stdout, "RecBufferQueueCallback called\n"); - - CallbackCntxt *pCntxt = (CallbackCntxt*)pContext; - - /* Save the recorded data */ - fwrite(pCntxt->pDataBase, BUFFER_SIZE_IN_BYTES, 1, gFp); - - /* Increase data pointer by buffer size */ - pCntxt->pData += BUFFER_SIZE_IN_BYTES; - - if (pCntxt->pData >= pCntxt->pDataBase + (NB_BUFFERS_IN_QUEUE * BUFFER_SIZE_IN_BYTES)) { - pCntxt->pData = pCntxt->pDataBase; - } - - ExitOnError( (*queueItf)->Enqueue(queueItf, pCntxt->pDataBase, BUFFER_SIZE_IN_BYTES) ); - - SLAndroidSimpleBufferQueueState recQueueState; - ExitOnError( (*queueItf)->GetState(queueItf, &recQueueState) ); - - /*fprintf(stderr, "\tRecBufferQueueCallback now has pCntxt->pData=%p queue: " - "count=%u playIndex=%u\n", - pCntxt->pData, recQueueState.count, recQueueState.index);*/ -} - -//----------------------------------------------------------------- - -/* Play an audio path by opening a file descriptor on that path */ -void TestRecToBuffQueue( SLObjectItf sl, const char* path, SLAint64 durationInSeconds) -{ - gFp = fopen(path, "w"); - if (NULL == gFp) { - ExitOnError(SL_RESULT_RESOURCE_ERROR); - } - - SLresult result; - SLEngineItf EngineItf; - - /* Objects this application uses: one audio recorder */ - SLObjectItf recorder; - - /* Interfaces for the audio recorder */ - SLAndroidSimpleBufferQueueItf recBuffQueueItf; - SLRecordItf recordItf; - SLAndroidConfigurationItf configItf; - - /* Source of audio data for the recording */ - SLDataSource recSource; - SLDataLocator_IODevice ioDevice; - - /* Data sink for recorded audio */ - SLDataSink recDest; - SLDataLocator_AndroidSimpleBufferQueue recBuffQueue; - SLDataFormat_PCM pcm; - - SLboolean required[NUM_EXPLICIT_INTERFACES_FOR_RECORDER]; - SLInterfaceID iidArray[NUM_EXPLICIT_INTERFACES_FOR_RECORDER]; - - /* Get the SL Engine Interface which is implicit */ - result = (*sl)->GetInterface(sl, SL_IID_ENGINE, (void*)&EngineItf); - ExitOnError(result); - - /* Initialize arrays required[] and iidArray[] */ - for (int i=0 ; i < NUM_EXPLICIT_INTERFACES_FOR_RECORDER ; i++) { - required[i] = SL_BOOLEAN_FALSE; - iidArray[i] = SL_IID_NULL; - } - - - /* ------------------------------------------------------ */ - /* Configuration of the recorder */ - - /* Request the AndroidSimpleBufferQueue and AndroidConfiguration interfaces */ - required[0] = SL_BOOLEAN_TRUE; - iidArray[0] = SL_IID_ANDROIDSIMPLEBUFFERQUEUE; - required[1] = SL_BOOLEAN_TRUE; - iidArray[1] = SL_IID_ANDROIDCONFIGURATION; - - /* Setup the data source */ - ioDevice.locatorType = SL_DATALOCATOR_IODEVICE; - ioDevice.deviceType = SL_IODEVICE_AUDIOINPUT; - ioDevice.deviceID = SL_DEFAULTDEVICEID_AUDIOINPUT; - ioDevice.device = NULL; - recSource.pLocator = (void *) &ioDevice; - recSource.pFormat = NULL; - - /* Setup the data sink */ - recBuffQueue.locatorType = SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE; - recBuffQueue.numBuffers = NB_BUFFERS_IN_QUEUE; - /* set up the format of the data in the buffer queue */ - pcm.formatType = SL_DATAFORMAT_PCM; - pcm.numChannels = 1; - pcm.samplesPerSec = SL_SAMPLINGRATE_22_05; - pcm.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_16; - pcm.containerSize = 16; - pcm.channelMask = SL_SPEAKER_FRONT_LEFT; - pcm.endianness = SL_BYTEORDER_LITTLEENDIAN; - - recDest.pLocator = (void *) &recBuffQueue; - recDest.pFormat = (void * ) &pcm; - - /* Create the audio recorder */ - result = (*EngineItf)->CreateAudioRecorder(EngineItf, &recorder, &recSource, &recDest, - NUM_EXPLICIT_INTERFACES_FOR_RECORDER, iidArray, required); - ExitOnError(result); - fprintf(stdout, "Recorder created\n"); - - /* Get the Android configuration interface which is explicit */ - result = (*recorder)->GetInterface(recorder, SL_IID_ANDROIDCONFIGURATION, (void*)&configItf); - ExitOnError(result); - - /* Use the configuration interface to configure the recorder before it's realized */ - if (presetValue != SL_ANDROID_RECORDING_PRESET_NONE) { - result = (*configItf)->SetConfiguration(configItf, SL_ANDROID_KEY_RECORDING_PRESET, - &presetValue, sizeof(SLuint32)); - ExitOnError(result); - fprintf(stdout, "Recorder parameterized with preset %u\n", presetValue); - } else { - printf("Using default record preset\n"); - } - - SLuint32 presetRetrieved = SL_ANDROID_RECORDING_PRESET_NONE; - SLuint32 presetSize = 2*sizeof(SLuint32); // intentionally too big - result = (*configItf)->GetConfiguration(configItf, SL_ANDROID_KEY_RECORDING_PRESET, - &presetSize, (void*)&presetRetrieved); - ExitOnError(result); - if (presetValue == SL_ANDROID_RECORDING_PRESET_NONE) { - printf("The default record preset appears to be %u\n", presetRetrieved); - } else if (presetValue != presetRetrieved) { - fprintf(stderr, "Error retrieving recording preset as %u instead of %u\n", presetRetrieved, - presetValue); - ExitOnError(SL_RESULT_INTERNAL_ERROR); - } - - /* Realize the recorder in synchronous mode. */ - result = (*recorder)->Realize(recorder, SL_BOOLEAN_FALSE); - ExitOnError(result); - fprintf(stdout, "Recorder realized\n"); - - /* Get the record interface which is implicit */ - result = (*recorder)->GetInterface(recorder, SL_IID_RECORD, (void*)&recordItf); - ExitOnError(result); - - /* Set up the recorder callback to get events during the recording */ - result = (*recordItf)->SetMarkerPosition(recordItf, 2000); - ExitOnError(result); - result = (*recordItf)->SetPositionUpdatePeriod(recordItf, 500); - ExitOnError(result); - result = (*recordItf)->SetCallbackEventsMask(recordItf, - SL_RECORDEVENT_HEADATMARKER | SL_RECORDEVENT_HEADATNEWPOS); - ExitOnError(result); - result = (*recordItf)->RegisterCallback(recordItf, RecCallback, NULL); - ExitOnError(result); - fprintf(stdout, "Recorder callback registered\n"); - - /* Get the buffer queue interface which was explicitly requested */ - result = (*recorder)->GetInterface(recorder, SL_IID_ANDROIDSIMPLEBUFFERQUEUE, - (void*)&recBuffQueueItf); - ExitOnError(result); - - /* ------------------------------------------------------ */ - /* Initialize the callback and its context for the recording buffer queue */ - CallbackCntxt cntxt; - cntxt.pDataBase = (int8_t*)&pcmData; - cntxt.pData = cntxt.pDataBase; - cntxt.size = sizeof(pcmData); - result = (*recBuffQueueItf)->RegisterCallback(recBuffQueueItf, RecBufferQueueCallback, &cntxt); - ExitOnError(result); - - /* Enqueue buffers to map the region of memory allocated to store the recorded data */ - fprintf(stdout,"Enqueueing buffer "); - for(int i = 0 ; i < NB_BUFFERS_IN_QUEUE ; i++) { - fprintf(stdout,"%d ", i); - result = (*recBuffQueueItf)->Enqueue(recBuffQueueItf, cntxt.pData, BUFFER_SIZE_IN_BYTES); - ExitOnError(result); - cntxt.pData += BUFFER_SIZE_IN_BYTES; - } - fprintf(stdout,"\n"); - cntxt.pData = cntxt.pDataBase; - - /* ------------------------------------------------------ */ - /* Start recording */ - result = (*recordItf)->SetRecordState(recordItf, SL_RECORDSTATE_RECORDING); - ExitOnError(result); - fprintf(stdout, "Starting to record\n"); - - /* Record for at least a second */ - if (durationInSeconds < 1) { - durationInSeconds = 1; - } - usleep(durationInSeconds * 1000 * 1000); - - /* ------------------------------------------------------ */ - /* End of recording */ - - /* Stop recording */ - result = (*recordItf)->SetRecordState(recordItf, SL_RECORDSTATE_STOPPED); - ExitOnError(result); - fprintf(stdout, "Stopped recording\n"); - - /* Destroy the AudioRecorder object */ - (*recorder)->Destroy(recorder); - - fclose(gFp); -} - -//----------------------------------------------------------------- -int main(int argc, char* const argv[]) -{ - SLresult result; - SLObjectItf sl; - - const char *prog = argv[0]; - fprintf(stdout, "OpenSL ES test %s: exercises SLRecordItf and SLAndroidSimpleBufferQueueItf ", - prog); - fprintf(stdout, "on an AudioRecorder object\n"); - - int i; - for (i = 1; i < argc; ++i) { - const char *arg = argv[i]; - if (arg[0] != '-') { - break; - } - switch (arg[1]) { - case 'p': // preset number - presetValue = atoi(&arg[2]); - break; - default: - fprintf(stderr, "%s: unknown option %s\n", prog, arg); - break; - } - } - - if (argc-i < 2) { - printf("Usage: \t%s [-p#] destination_file duration_in_seconds\n", prog); - printf(" -p# is the preset value which defaults to SL_ANDROID_RECORDING_PRESET_NONE\n"); - printf(" possible values are:\n"); - printf(" -p%d SL_ANDROID_RECORDING_PRESET_NONE\n", - SL_ANDROID_RECORDING_PRESET_NONE); - printf(" -p%d SL_ANDROID_RECORDING_PRESET_GENERIC\n", - SL_ANDROID_RECORDING_PRESET_GENERIC); - printf(" -p%d SL_ANDROID_RECORDING_PRESET_CAMCORDER\n", - SL_ANDROID_RECORDING_PRESET_CAMCORDER); - printf(" -p%d SL_ANDROID_RECORDING_PRESET_VOICE_RECOGNITION\n", - SL_ANDROID_RECORDING_PRESET_VOICE_RECOGNITION); - printf(" -p%d SL_ANDROID_RECORDING_PRESET_VOICE_COMMUNICATION\n", - SL_ANDROID_RECORDING_PRESET_VOICE_COMMUNICATION); - printf("Example: \"%s /sdcard/myrec.raw 4\" \n", prog); - exit(EXIT_FAILURE); - } - - SLEngineOption EngineOption[] = { - {(SLuint32) SL_ENGINEOPTION_THREADSAFE, (SLuint32) SL_BOOLEAN_TRUE} - }; - - result = slCreateEngine( &sl, 1, EngineOption, 0, NULL, NULL); - ExitOnError(result); - - /* Realizing the SL Engine in synchronous mode. */ - result = (*sl)->Realize(sl, SL_BOOLEAN_FALSE); - ExitOnError(result); - - TestRecToBuffQueue(sl, argv[i], (SLAint64)atoi(argv[i+1])); - - /* Shutdown OpenSL ES */ - (*sl)->Destroy(sl); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/examples/slesTestSawtoothBufferQueue.cpp b/wilhelm/tests/examples/slesTestSawtoothBufferQueue.cpp deleted file mode 100644 index ccca77f6..00000000 --- a/wilhelm/tests/examples/slesTestSawtoothBufferQueue.cpp +++ /dev/null @@ -1,296 +0,0 @@ -/* - * 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. - */ - -/* - * Copyright (c) 2009 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this - * software and /or associated documentation files (the "Materials "), to deal in the - * Materials without restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies of the Materials, - * and to permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS IN THE - * MATERIALS. - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <sys/time.h> - - -#include <SLES/OpenSLES.h> - - -#define MAX_NUMBER_INTERFACES 3 - -/* Local storage for Audio data in 16 bit words */ -#define AUDIO_DATA_STORAGE_SIZE 4096 * 100 -/* Audio data buffer size in 16 bit words. 8 data segments are used in -this simple example */ -#define AUDIO_DATA_BUFFER_SIZE 4096/8 - -/* Checks for error. If any errors exit the application! */ -void CheckErr( SLresult res ) -{ - if ( res != SL_RESULT_SUCCESS ) - { - fprintf(stdout, "%u SL failure, exiting\n", res); - exit(EXIT_FAILURE); - } - else { - //fprintf(stdout, "%d SL success, proceeding...\n", res); - } -} - -/* Structure for passing information to callback function */ -typedef struct CallbackCntxt_ { - SLPlayItf playItf; - SLint16* pDataBase; // Base adress of local audio data storage - SLint16* pData; // Current adress of local audio data storage - SLuint32 size; -} CallbackCntxt; - -/* Local storage for Audio data */ -SLint16 pcmData[AUDIO_DATA_STORAGE_SIZE]; - -/* Callback for Buffer Queue events */ -void BufferQueueCallback( - SLBufferQueueItf queueItf, - void *pContext) -{ - //fprintf(stdout, "BufferQueueCallback called\n"); - SLresult res; - //fprintf(stdout, " pContext=%p\n", pContext); - CallbackCntxt *pCntxt = (CallbackCntxt*)pContext; - - if(pCntxt->pData < (pCntxt->pDataBase + pCntxt->size)) - { - //fprintf(stdout, "callback: before enqueue\n"); - res = (*queueItf)->Enqueue(queueItf, (void*) pCntxt->pData, - 2 * AUDIO_DATA_BUFFER_SIZE); /* Size given in bytes. */ - CheckErr(res); - /* Increase data pointer by buffer size */ - pCntxt->pData += AUDIO_DATA_BUFFER_SIZE; - } - //fprintf(stdout, "end of BufferQueueCallback()\n"); -} - -/* Play some audio from a buffer queue */ -void TestPlaySawtoothBufferQueue( SLObjectItf sl ) -{ - SLEngineItf EngineItf; - - SLint32 numOutputs = 0; - SLuint32 deviceID = 0; - - SLresult res; - - SLDataSource audioSource; - SLDataLocator_BufferQueue bufferQueue; - SLDataFormat_PCM pcm; - - SLDataSink audioSink; - SLDataLocator_OutputMix locator_outputmix; - - SLObjectItf player; - SLPlayItf playItf; - SLBufferQueueItf bufferQueueItf; - SLBufferQueueState state; - - SLObjectItf OutputMix; - SLVolumeItf volumeItf; - - int i; - - SLboolean required[MAX_NUMBER_INTERFACES]; - SLInterfaceID iidArray[MAX_NUMBER_INTERFACES]; - - /* Callback context for the buffer queue callback function */ - CallbackCntxt cntxt; - - /* Get the SL Engine Interface which is implicit */ - res = (*sl)->GetInterface(sl, SL_IID_ENGINE, (void*)&EngineItf); - CheckErr(res); - - /* Initialize arrays required[] and iidArray[] */ - for (i=0;i<MAX_NUMBER_INTERFACES;i++) - { - required[i] = SL_BOOLEAN_FALSE; - iidArray[i] = SL_IID_NULL; - } - - // Set arrays required[] and iidArray[] for VOLUME interface - required[0] = SL_BOOLEAN_TRUE; - iidArray[0] = SL_IID_VOLUME; - // Create Output Mix object to be used by player - res = (*EngineItf)->CreateOutputMix(EngineItf, &OutputMix, 0, - iidArray, required); CheckErr(res); - - // Realizing the Output Mix object in synchronous mode. - res = (*OutputMix)->Realize(OutputMix, SL_BOOLEAN_FALSE); - CheckErr(res); - -#if 0 - res = (*OutputMix)->GetInterface(OutputMix, SL_IID_VOLUME, - (void*)&volumeItf); CheckErr(res); -#endif - - /* Setup the data source structure for the buffer queue */ - bufferQueue.locatorType = SL_DATALOCATOR_BUFFERQUEUE; - bufferQueue.numBuffers = 4; /* Four buffers in our buffer queue */ - - /* Setup the format of the content in the buffer queue */ - pcm.formatType = SL_DATAFORMAT_PCM; - pcm.numChannels = 1;//2; - pcm.samplesPerSec = SL_SAMPLINGRATE_44_1; - pcm.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_16; - pcm.containerSize = 16; - pcm.channelMask = SL_SPEAKER_FRONT_LEFT;// | SL_SPEAKER_FRONT_RIGHT; - pcm.endianness = SL_BYTEORDER_LITTLEENDIAN; - - audioSource.pFormat = (void *)&pcm; - audioSource.pLocator = (void *)&bufferQueue; - - /* Setup the data sink structure */ - locator_outputmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; - locator_outputmix.outputMix = OutputMix; - audioSink.pLocator = (void *)&locator_outputmix; - audioSink.pFormat = NULL; - - /* Initialize the audio data to play */ - unsigned int j; - for (j = 0; j < sizeof(pcmData)/sizeof(pcmData[0]); ++j) { - pcmData[j] = j*(100 + j / 200);// % 1000; - } - - /* Initialize the context for Buffer queue callbacks */ - cntxt.pDataBase = /*(void*)&*/pcmData; - cntxt.pData = cntxt.pDataBase; - cntxt.size = sizeof(pcmData) / 2; - - /* Set arrays required[] and iidArray[] for SEEK interface - (PlayItf is implicit) */ - required[0] = SL_BOOLEAN_TRUE; - iidArray[0] = SL_IID_BUFFERQUEUE; - - /* Create the music player */ - res = (*EngineItf)->CreateAudioPlayer(EngineItf, &player, - &audioSource, &audioSink, 1, iidArray, required); CheckErr(res); - fprintf(stdout, "bufferQueue example: after CreateAudioPlayer\n"); - - /* Realizing the player in synchronous mode. */ - res = (*player)->Realize(player, SL_BOOLEAN_FALSE); CheckErr(res); - fprintf(stdout, "bufferQueue example: after Realize\n"); - - /* Get seek and play interfaces */ - res = (*player)->GetInterface(player, SL_IID_PLAY, (void*)&playItf); - CheckErr(res); - fprintf(stdout, "bufferQueue example: after GetInterface(PLAY)\n"); - - res = (*player)->GetInterface(player, SL_IID_BUFFERQUEUE, - (void*)&bufferQueueItf); CheckErr(res); - - /* Setup to receive buffer queue event callbacks */ - res = (*bufferQueueItf)->RegisterCallback(bufferQueueItf, - BufferQueueCallback, &cntxt); CheckErr(res); - -#if 0 - /* Before we start set volume to -3dB (-300mB) */ - res = (*volumeItf)->SetVolumeLevel(volumeItf, -300); CheckErr(res); -#endif - - /* Enqueue a few buffers to get the ball rolling */ - res = (*bufferQueueItf)->Enqueue(bufferQueueItf, cntxt.pData, - 2 * AUDIO_DATA_BUFFER_SIZE); /* Size given in bytes. */ - CheckErr(res); - cntxt.pData += AUDIO_DATA_BUFFER_SIZE; - - res = (*bufferQueueItf)->Enqueue(bufferQueueItf, cntxt.pData, - 2 * AUDIO_DATA_BUFFER_SIZE); /* Size given in bytes. */ - CheckErr(res); - cntxt.pData += AUDIO_DATA_BUFFER_SIZE; - - res = (*bufferQueueItf)->Enqueue(bufferQueueItf, cntxt.pData, - 2 * AUDIO_DATA_BUFFER_SIZE); /* Size given in bytes. */ - CheckErr(res); - cntxt.pData += AUDIO_DATA_BUFFER_SIZE; - - /* Play the PCM samples using a buffer queue */ - fprintf(stdout, "bufferQueue example: starting to play\n"); - res = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PLAYING ); - CheckErr(res); - - /* Wait until the PCM data is done playing, the buffer queue callback - will continue to queue buffers until the entire PCM data has been - played. This is indicated by waiting for the count member of the - SLBufferQueueState to go to zero. - */ - res = (*bufferQueueItf)->GetState(bufferQueueItf, &state); - CheckErr(res); - - // while (state.playIndex < 100) { - while (state.count) { - usleep(10000); - (*bufferQueueItf)->GetState(bufferQueueItf, &state); - } - - /* Make sure player is stopped */ - res = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED); - CheckErr(res); - /* Destroy the player */ - (*player)->Destroy(player); - - /* Destroy Output Mix object */ - (*OutputMix)->Destroy(OutputMix); -} - - - -int main(int argc, char* const argv[]) -{ - SLresult res; - SLObjectItf sl; - - SLEngineOption EngineOption[] = { - {(SLuint32) SL_ENGINEOPTION_THREADSAFE, - (SLuint32) SL_BOOLEAN_TRUE}}; - - res = slCreateEngine( &sl, 1, EngineOption, 0, NULL, NULL); - CheckErr(res); - /* Realizing the SL Engine in synchronous mode. */ - res = (*sl)->Realize(sl, SL_BOOLEAN_FALSE); CheckErr(res); - - /* Run the test */ - TestPlaySawtoothBufferQueue(sl); - - /* Shutdown OpenSL ES */ - (*sl)->Destroy(sl); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/examples/slesTestSendToPresetReverb.cpp b/wilhelm/tests/examples/slesTestSendToPresetReverb.cpp deleted file mode 100644 index 5b68ef6e..00000000 --- a/wilhelm/tests/examples/slesTestSendToPresetReverb.cpp +++ /dev/null @@ -1,387 +0,0 @@ -/* - * 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. - */ - -#include <assert.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <sys/time.h> -#include <fcntl.h> - -#include <SLES/OpenSLES.h> -#ifdef ANDROID -#include <SLES/OpenSLES_Android.h> -#endif - - -#define MAX_NUMBER_INTERFACES 4 - -#define TIME_S_BETWEEN_SETTING_CHANGE 3 - -//----------------------------------------------------------------- -/* Exits the application if an error is encountered */ -#define ExitOnError(x) ExitOnErrorFunc(x,__LINE__) - -void ExitOnErrorFunc( SLresult result , int line) -{ - if (SL_RESULT_SUCCESS != result) { - fprintf(stderr, "%u error code encountered at line %d, exiting\n", result, line); - exit(EXIT_FAILURE); - } -} - -// Prefetch status callback - -#define PREFETCHEVENT_ERROR_CANDIDATE \ - (SL_PREFETCHEVENT_STATUSCHANGE | SL_PREFETCHEVENT_FILLLEVELCHANGE) - -SLboolean errorInPrefetchCallback = SL_BOOLEAN_FALSE; - -void prefetch_callback(SLPrefetchStatusItf caller, void *context, SLuint32 event) -{ - SLresult result; - assert(context == NULL); - SLpermille level; - result = (*caller)->GetFillLevel(caller, &level); - ExitOnError(result); - SLuint32 status; - result = (*caller)->GetPrefetchStatus(caller, &status); - ExitOnError(result); - if ((PREFETCHEVENT_ERROR_CANDIDATE == (event & PREFETCHEVENT_ERROR_CANDIDATE)) - && (level == 0) && (status == SL_PREFETCHSTATUS_UNDERFLOW)) { - errorInPrefetchCallback = SL_BOOLEAN_TRUE; - } -} - -//----------------------------------------------------------------- - -/* Play an audio path and feed a global reverb */ -void TestSendToPresetReverb( SLObjectItf sl, const char* path, int preset, SLmillibel directLevel, - SLmillibel sendLevel, bool alwaysOn, bool useFd, bool loop) -{ - SLresult result; - SLEngineItf EngineItf; - - /* Objects this application uses: one player and an ouput mix */ - SLObjectItf player, outputMix; - - /* Source of audio data to play */ - SLDataSource audioSource; -#ifdef ANDROID - SLDataLocator_AndroidFD locatorFd; -#endif - SLDataLocator_URI locatorUri; - SLDataFormat_MIME mime; - - /* Data sinks for the audio player */ - SLDataSink audioSink; - SLDataLocator_OutputMix locator_outputmix; - - /* Interfaces for the audio player */ - SLPlayItf playItf; - SLPrefetchStatusItf prefetchItf; - SLEffectSendItf effectSendItf; - SLSeekItf seekItf; - - /* Interface for the output mix */ - SLPresetReverbItf reverbItf; - - SLboolean required[MAX_NUMBER_INTERFACES]; - SLInterfaceID iidArray[MAX_NUMBER_INTERFACES]; - - /* Get the SL Engine Interface which is implicit */ - result = (*sl)->GetInterface(sl, SL_IID_ENGINE, (void*)&EngineItf); - ExitOnError(result); - - /* Initialize arrays required[] and iidArray[] */ - for (int i=0 ; i < MAX_NUMBER_INTERFACES ; i++) { - required[i] = SL_BOOLEAN_FALSE; - iidArray[i] = SL_IID_NULL; - } - - /* ------------------------------------------------------ */ - /* Configuration of the output mix */ - - /* Set arrays required[] and iidArray[] for required interfaces */ - required[0] = SL_BOOLEAN_TRUE; - iidArray[0] = SL_IID_PRESETREVERB; - - /* Create Output Mix object to be used by the player */ - result = (*EngineItf)->CreateOutputMix(EngineItf, &outputMix, 1, iidArray, required); - ExitOnError(result); - - /* Realize the Output Mix object in synchronous mode */ - result = (*outputMix)->Realize(outputMix, SL_BOOLEAN_FALSE); - ExitOnError(result); - - /* Get the SLPresetReverbItf for the output mix */ - result = (*outputMix)->GetInterface(outputMix, SL_IID_PRESETREVERB, (void*)&reverbItf); - ExitOnError(result); - - /* Setup the data sink structure */ - locator_outputmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; - locator_outputmix.outputMix = outputMix; - audioSink.pLocator = (void*)&locator_outputmix; - audioSink.pFormat = NULL; - - /* Select the reverb preset */ - fprintf(stdout, "\nUsing preset "); - switch(preset) { - case SL_REVERBPRESET_NONE: - fprintf(stdout, "SL_REVERBPRESET_NONE, don't expect to hear reverb\n"); - break; - case SL_REVERBPRESET_SMALLROOM: fprintf(stdout, "SL_REVERBPRESET_SMALLROOM\n"); break; - case SL_REVERBPRESET_MEDIUMROOM: fprintf(stdout, "SL_REVERBPRESET_MEDIUMROOM\n"); break; - case SL_REVERBPRESET_LARGEROOM: fprintf(stdout, "SL_REVERBPRESET_LARGEROOM\n"); break; - case SL_REVERBPRESET_MEDIUMHALL: fprintf(stdout, "SL_REVERBPRESET_MEDIUMHALL\n"); break; - case SL_REVERBPRESET_LARGEHALL: fprintf(stdout, "SL_REVERBPRESET_LARGEHALL\n"); break; - case SL_REVERBPRESET_PLATE: fprintf(stdout, "SL_REVERBPRESET_PLATE\n"); break; - default: - fprintf(stdout, "unknown, use at your own risk\n"); break; - } - result = (*reverbItf)->SetPreset(reverbItf, preset); - ExitOnError(result); - - /* ------------------------------------------------------ */ - /* Configuration of the player */ - - /* Set arrays required[] and iidArray[] for required interfaces */ - /* (SLPlayItf is implicit) */ - required[0] = SL_BOOLEAN_TRUE; - iidArray[0] = SL_IID_PREFETCHSTATUS; - required[1] = SL_BOOLEAN_TRUE; - iidArray[1] = SL_IID_EFFECTSEND; - required[2] = SL_BOOLEAN_TRUE; - iidArray[2] = SL_IID_SEEK; - - locatorUri.locatorType = SL_DATALOCATOR_URI; - locatorUri.URI = (SLchar *) path; - audioSource.pLocator = (void*)&locatorUri; - if (useFd) { -#ifdef ANDROID - /* Setup the data source structure for the URI */ - locatorFd.locatorType = SL_DATALOCATOR_ANDROIDFD; - int fd = open(path, O_RDONLY); - if (fd == -1) { - perror(path); - exit(EXIT_FAILURE); - } - locatorFd.fd = (SLint32) fd; - locatorFd.length = SL_DATALOCATOR_ANDROIDFD_USE_FILE_SIZE; - locatorFd.offset = 0; - audioSource.pLocator = (void*)&locatorFd; -#else - fprintf(stderr, "option --fd is not supported\n"); -#endif - } - - mime.formatType = SL_DATAFORMAT_MIME; - /* this is how ignored mime information is specified, according to OpenSL ES spec - * in 9.1.6 SLDataFormat_MIME and 8.23 SLMetadataTraversalItf GetChildInfo */ - mime.mimeType = (SLchar*)NULL; - mime.containerType = SL_CONTAINERTYPE_UNSPECIFIED; - - audioSource.pFormat = (void*)&mime; - - /* Create the audio player */ - result = (*EngineItf)->CreateAudioPlayer(EngineItf, &player, &audioSource, &audioSink, 3, - iidArray, required); - ExitOnError(result); - - /* Realize the player in synchronous mode. */ - result = (*player)->Realize(player, SL_BOOLEAN_FALSE); ExitOnError(result); - fprintf(stdout, "URI example: after Realize\n"); - - /* Get the SLPlayItf, SLPrefetchStatusItf and SLEffectSendItf interfaces for the player*/ - result = (*player)->GetInterface(player, SL_IID_PLAY, (void*)&playItf); - ExitOnError(result); - - result = (*player)->GetInterface(player, SL_IID_PREFETCHSTATUS, (void*)&prefetchItf); - ExitOnError(result); - result = (*prefetchItf)->RegisterCallback(prefetchItf, prefetch_callback, NULL); - ExitOnError(result); - result = (*prefetchItf)->SetCallbackEventsMask(prefetchItf, - SL_PREFETCHEVENT_STATUSCHANGE | SL_PREFETCHEVENT_FILLLEVELCHANGE); - ExitOnError(result); - - result = (*player)->GetInterface(player, SL_IID_EFFECTSEND, (void*)&effectSendItf); - ExitOnError(result); - - result = (*player)->GetInterface(player, SL_IID_SEEK, (void*)&seekItf); - ExitOnError(result); - - fprintf(stdout, "Player configured\n"); - - /* ------------------------------------------------------ */ - /* Playback and test */ - - /* Start the data prefetching by setting the player to the paused state */ - result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PAUSED ); - ExitOnError(result); - - /* Wait until there's data to play */ - SLuint32 prefetchStatus = SL_PREFETCHSTATUS_UNDERFLOW; - while (prefetchStatus != SL_PREFETCHSTATUS_SUFFICIENTDATA) { - if (errorInPrefetchCallback) { - fprintf(stderr, "Error during prefetch, exiting\n"); - exit(EXIT_FAILURE); - } - usleep(100 * 1000); - (*prefetchItf)->GetPrefetchStatus(prefetchItf, &prefetchStatus); - ExitOnError(result); - } - - /* Get duration */ - SLmillisecond durationInMsec = SL_TIME_UNKNOWN; - result = (*playItf)->GetDuration(playItf, &durationInMsec); - ExitOnError(result); - if (durationInMsec == SL_TIME_UNKNOWN) { - printf("Duration unknown, assuming 10 seconds\n"); - durationInMsec = 10000; - } else { - printf("Duration is %.1f seconds\n", durationInMsec / 1000.0); - } - - /* Feed the output mix' reverb from the audio player using the given send level */ - result = (*effectSendItf)->EnableEffectSend(effectSendItf, reverbItf, SL_BOOLEAN_TRUE, - sendLevel); - ExitOnError(result); - - result = (*effectSendItf)->SetDirectLevel(effectSendItf, directLevel); - ExitOnError(result); - fprintf(stdout, "Set direct level to %dmB\n", directLevel); - - result = (*effectSendItf)->SetSendLevel(effectSendItf, reverbItf, sendLevel); - ExitOnError(result); - fprintf(stdout, "Set send level to %dmB\n", sendLevel); - - /* Enable looping */ - if (loop) { - result = (*seekItf)->SetLoop(seekItf, SL_BOOLEAN_TRUE, (SLmillisecond) 0, SL_TIME_UNKNOWN); - ExitOnError(result); - } - - /* Start playback */ - result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PLAYING ); - ExitOnError(result); - - /* Disable preset reverb every TIME_S_BETWEEN_SETTING_CHANGE seconds unless always on */ - SLboolean previousEnabled = SL_BOOLEAN_FALSE; - SLuint32 playState; - for (;;) { - result = (*playItf)->GetPlayState(playItf, &playState); - ExitOnError(result); - if (playState != SL_PLAYSTATE_PLAYING) - break; - SLboolean enabled; - enabled = alwaysOn || !previousEnabled; - if (enabled != previousEnabled) { - result = (*reverbItf)->SetPreset(reverbItf, enabled ? preset : SL_REVERBPRESET_NONE); - fprintf(stdout, "SetPreset(%d)=%d\n", enabled ? preset : SL_REVERBPRESET_NONE, result); - ExitOnError(result); - previousEnabled = enabled; - if (enabled) { - fprintf(stdout, "Reverb on\n"); - } else { - fprintf(stdout, "Reverb off\n"); - } - } - usleep(TIME_S_BETWEEN_SETTING_CHANGE * 1000 * 1000); - } - - /* Make sure player is stopped */ - assert(playState == SL_PLAYSTATE_STOPPED); -#if 0 - fprintf(stdout, "Stopping playback\n"); - result = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED); - ExitOnError(result); -#endif - - /* Destroy the player */ - (*player)->Destroy(player); - - /* Destroy Output Mix object */ - (*outputMix)->Destroy(outputMix); - -#ifdef ANDROID - if (useFd) - close(locatorFd.fd); -#endif -} - -//----------------------------------------------------------------- -int main(int argc, char* const argv[]) -{ - const char *programName = argv[0]; - SLresult result; - SLObjectItf sl; - - fprintf(stdout, "OpenSL ES test %s: exercises SLEffectSendItf ", programName); - fprintf(stdout, "on AudioPlayer and SLPresetReverbItf on OutputMix.\n"); - fprintf(stdout, "Plays the sound file designated by the given path, "); - fprintf(stdout, "and sends a specified amount of energy to a global reverb\n"); - fprintf(stdout, "(sendLevel in mB), with a given direct level (in mB).\n"); - fprintf(stdout, "Every %d seconds, the reverb is turned on and off,\n", - TIME_S_BETWEEN_SETTING_CHANGE); - fprintf(stdout, "unless the --always-on option is specified before the path.\n"); - - bool alwaysOn = false; - bool useFd = false; - bool loop = false; - int i; - for (i = 1; i < argc; ++i) { - const char *arg = argv[i]; - if (arg[0] != '-') - break; - if (!strcmp(arg, "--always-on")) { - alwaysOn = true; - } else if (!strcmp(arg, "--fd")) { - useFd = true; - } else if (!strcmp(arg, "--loop")) { - loop = true; - } else { - fprintf(stderr, "unknown option %s ignored\n", arg); - } - } - - if (argc - i != 4) { - fprintf(stdout, "Usage: \t%s [--always-on] [--fd] [--loop] path preset directLevel " - "sendLevel\n", programName); - fprintf(stdout, "Example: \"%s /sdcard/my.mp3 6 -2000 0\" \n", programName); - exit(EXIT_FAILURE); - } - - SLEngineOption EngineOption[] = { - {(SLuint32) SL_ENGINEOPTION_THREADSAFE, (SLuint32) SL_BOOLEAN_TRUE} - }; - - result = slCreateEngine( &sl, 1, EngineOption, 0, NULL, NULL); - ExitOnError(result); - - /* Realizing the SL Engine in synchronous mode. */ - result = (*sl)->Realize(sl, SL_BOOLEAN_FALSE); - ExitOnError(result); - - // intentionally not checking that levels are of correct value - TestSendToPresetReverb(sl, argv[i], atoi(argv[i+1]), (SLmillibel)atoi(argv[i+2]), - (SLmillibel)atoi(argv[i+3]), alwaysOn, useFd, loop); - - /* Shutdown OpenSL ES */ - (*sl)->Destroy(sl); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/examples/slesTestVirtualizerPath.cpp b/wilhelm/tests/examples/slesTestVirtualizerPath.cpp deleted file mode 100644 index e6b01b8d..00000000 --- a/wilhelm/tests/examples/slesTestVirtualizerPath.cpp +++ /dev/null @@ -1,296 +0,0 @@ -/* - * 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. - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <sys/time.h> -#include <fcntl.h> - -#include <SLES/OpenSLES.h> -#ifdef ANDROID -#include <SLES/OpenSLES_Android.h> -#endif - - -#define MAX_NUMBER_INTERFACES 3 - -#define TIME_S_BETWEEN_VIRT_ON_OFF 3 - -//----------------------------------------------------------------- -/* Exits the application if an error is encountered */ -#define ExitOnError(x) ExitOnErrorFunc(x,__LINE__) - -void ExitOnErrorFunc( SLresult result , int line) -{ - if (SL_RESULT_SUCCESS != result) { - fprintf(stderr, "%u error code encountered at line %d, exiting\n", result, line); - exit(EXIT_FAILURE); - } -} - - -//----------------------------------------------------------------- - -/* Play an audio path by opening a file descriptor on that path */ -void TestVirtualizerPathFromFD( SLObjectItf sl, const char* path, int16_t virtStrength, - bool alwaysOn) -{ - SLresult result; - SLEngineItf EngineItf; - - /* Objects this application uses: one player and an ouput mix */ - SLObjectItf player, outputMix; - - /* Source of audio data to play */ - SLDataSource audioSource; -#ifdef ANDROID - SLDataLocator_AndroidFD locatorFd; -#else - SLDataLocator_URI locatorUri; -#endif - SLDataFormat_MIME mime; - - /* Data sinks for the audio player */ - SLDataSink audioSink; - SLDataLocator_OutputMix locator_outputmix; - - /* Play and PrefetchStatus interfaces for the audio player */ - SLPlayItf playItf; - SLPrefetchStatusItf prefetchItf; - SLVirtualizerItf virtItf; - - SLboolean required[MAX_NUMBER_INTERFACES]; - SLInterfaceID iidArray[MAX_NUMBER_INTERFACES]; - - /* Get the SL Engine Interface which is implicit */ - result = (*sl)->GetInterface(sl, SL_IID_ENGINE, (void*)&EngineItf); - ExitOnError(result); - - /* Initialize arrays required[] and iidArray[] */ - for (int i=0 ; i < MAX_NUMBER_INTERFACES ; i++) { - required[i] = SL_BOOLEAN_FALSE; - iidArray[i] = SL_IID_NULL; - } - - /* ------------------------------------------------------ */ - /* Configuration of the output mix */ - - /* Create Output Mix object to be used by the player */ - result = (*EngineItf)->CreateOutputMix(EngineItf, &outputMix, 0, iidArray, required); - ExitOnError(result); - - /* Realize the Output Mix object in synchronous mode */ - result = (*outputMix)->Realize(outputMix, SL_BOOLEAN_FALSE); - ExitOnError(result); - - /* Setup the data sink structure */ - locator_outputmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; - locator_outputmix.outputMix = outputMix; - audioSink.pLocator = (void*)&locator_outputmix; - audioSink.pFormat = NULL; - - /* ------------------------------------------------------ */ - /* Configuration of the player */ - - /* Set arrays required[] and iidArray[] for SLPrefetchStatusItf interfaces */ - /* (SLPlayItf is implicit) */ - required[0] = SL_BOOLEAN_TRUE; - iidArray[0] = SL_IID_PREFETCHSTATUS; - required[1] = SL_BOOLEAN_TRUE; - iidArray[1] = SL_IID_VIRTUALIZER; - -#ifdef ANDROID - /* Setup the data source structure for the URI */ - locatorFd.locatorType = SL_DATALOCATOR_ANDROIDFD; - int fd = open(path, O_RDONLY); - if (fd == -1) { - ExitOnError(SL_RESULT_RESOURCE_ERROR); - } - locatorFd.fd = (SLint32) fd; - locatorFd.length = SL_DATALOCATOR_ANDROIDFD_USE_FILE_SIZE; - locatorFd.offset = 0; -#else - locatorUri.locatorType = SL_DATALOCATOR_URI; - locatorUri.URI = (SLchar *) path; -#endif - - mime.formatType = SL_DATAFORMAT_MIME; - /* this is how ignored mime information is specified, according to OpenSL ES spec - * in 9.1.6 SLDataFormat_MIME and 8.23 SLMetadataTraversalItf GetChildInfo */ - mime.mimeType = (SLchar*)NULL; - mime.containerType = SL_CONTAINERTYPE_UNSPECIFIED; - - audioSource.pFormat = (void*)&mime; -#ifdef ANDROID - audioSource.pLocator = (void*)&locatorFd; -#else - audioSource.pLocator = (void*)&locatorUri; -#endif - - /* Create the audio player */ - result = (*EngineItf)->CreateAudioPlayer(EngineItf, &player, &audioSource, &audioSink, 2, - iidArray, required); - ExitOnError(result); - - /* Realize the player in synchronous mode. */ - result = (*player)->Realize(player, SL_BOOLEAN_FALSE); ExitOnError(result); - fprintf(stdout, "URI example: after Realize\n"); - - /* Get the SLPlayItf, SLPrefetchStatusItf and SLAndroidStreamTypeItf interfaces for the player*/ - result = (*player)->GetInterface(player, SL_IID_PLAY, (void*)&playItf); - ExitOnError(result); - - result = (*player)->GetInterface(player, SL_IID_PREFETCHSTATUS, (void*)&prefetchItf); - ExitOnError(result); - - result = (*player)->GetInterface(player, SL_IID_VIRTUALIZER, (void*)&virtItf); - ExitOnError(result); - - fprintf(stdout, "Player configured\n"); - - /* ------------------------------------------------------ */ - /* Playback and test */ - - /* Start the data prefetching by setting the player to the paused state */ - result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PAUSED ); - ExitOnError(result); - - /* Wait until there's data to play */ - SLuint32 prefetchStatus = SL_PREFETCHSTATUS_UNDERFLOW; - while (prefetchStatus != SL_PREFETCHSTATUS_SUFFICIENTDATA) { - usleep(100 * 1000); - (*prefetchItf)->GetPrefetchStatus(prefetchItf, &prefetchStatus); - ExitOnError(result); - } - - /* Get duration */ - SLmillisecond durationInMsec = SL_TIME_UNKNOWN; - result = (*playItf)->GetDuration(playItf, &durationInMsec); - ExitOnError(result); - if (durationInMsec == SL_TIME_UNKNOWN) { - durationInMsec = 5000; - } - - /* Start playback */ - fprintf(stdout, "Starting to play\n"); - result = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_PLAYING ); - ExitOnError(result); - - /* Configure Virtualizer */ - SLboolean strengthSupported = SL_BOOLEAN_FALSE; - result = (*virtItf)->IsStrengthSupported(virtItf, &strengthSupported); - ExitOnError(result); - if (SL_BOOLEAN_FALSE == strengthSupported) { - fprintf(stdout, "Virtualizer strength is not supported on this platform. Too bad!\n"); - } else { - fprintf(stdout, "Virtualizer strength is supported, setting strength to %d\n", - virtStrength); - result = (*virtItf)->SetStrength(virtItf, virtStrength); - ExitOnError(result); - } - - SLpermille strength = 0; - result = (*virtItf)->GetRoundedStrength(virtItf, &strength); - ExitOnError(result); - fprintf(stdout, "Rounded strength of virt = %d\n", strength); - - - /* Switch Virtualizer on/off every TIME_S_BETWEEN_VIRT_ON_OFF seconds unless always on */ - SLboolean previousEnabled = SL_BOOLEAN_FALSE; - for(unsigned int j=0 ; j<(durationInMsec/(1000*TIME_S_BETWEEN_VIRT_ON_OFF)) ; j++) { - SLboolean enabled; - result = (*virtItf)->IsEnabled(virtItf, &enabled); - ExitOnError(result); - enabled = alwaysOn || !enabled; - if (enabled != previousEnabled) { - result = (*virtItf)->SetEnabled(virtItf, enabled); - ExitOnError(result); - previousEnabled = enabled; - if (SL_BOOLEAN_TRUE == enabled) { - fprintf(stdout, "Virtualizer on\n"); - } else { - fprintf(stdout, "Virtualizer off\n"); - } - } - usleep(TIME_S_BETWEEN_VIRT_ON_OFF * 1000 * 1000); - } - - /* Make sure player is stopped */ - fprintf(stdout, "Stopping playback\n"); - result = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED); - ExitOnError(result); - - /* Destroy the player */ - (*player)->Destroy(player); - - /* Destroy Output Mix object */ - (*outputMix)->Destroy(outputMix); - -#ifdef ANDROID - close(fd); -#endif -} - -//----------------------------------------------------------------- -int main(int argc, char* const argv[]) -{ - const char *programName = argv[0]; - SLresult result; - SLObjectItf sl; - - fprintf(stdout, "OpenSL ES test %s: exercises SLVirtualizerItf ", programName); - fprintf(stdout, "and AudioPlayer with SLDataLocator_AndroidFD source / OutputMix sink\n"); - fprintf(stdout, "Plays the sound file designated by the given path, "); - fprintf(stdout, "and applies a virtualization effect of the specified strength,\n"); - fprintf(stdout, "where strength is an integer value between 0 and 1000.\n"); - fprintf(stdout, "Every %d seconds, the Virtualizer will be turned on and off,\n", - TIME_S_BETWEEN_VIRT_ON_OFF); - fprintf(stdout, "unless the --always-on option is specified before the path.\n"); - - bool alwaysOn = false; - if (argc >= 2 && !strcmp(argv[1], "--always-on")) { - alwaysOn = true; - --argc; - ++argv; - } - - if (argc < 3) { - fprintf(stdout, "Usage: \t%s [--always-on] path virtualization_strength\n", programName); - fprintf(stdout, "Example: \"%s /sdcard/my.mp3 1000\" \n", programName); - exit(EXIT_FAILURE); - } - - SLEngineOption EngineOption[] = { - {(SLuint32) SL_ENGINEOPTION_THREADSAFE, (SLuint32) SL_BOOLEAN_TRUE} - }; - - result = slCreateEngine( &sl, 1, EngineOption, 0, NULL, NULL); - ExitOnError(result); - - /* Realizing the SL Engine in synchronous mode. */ - result = (*sl)->Realize(sl, SL_BOOLEAN_FALSE); - ExitOnError(result); - - // intentionally not checking that argv[2], the virtualizer strength, is between 0 and 1000 - TestVirtualizerPathFromFD(sl, argv[1], (int16_t)atoi(argv[2]), alwaysOn); - - /* Shutdown OpenSL ES */ - (*sl)->Destroy(sl); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/examples/xaVideoDecoderCapabilities.cpp b/wilhelm/tests/examples/xaVideoDecoderCapabilities.cpp deleted file mode 100644 index 67d73732..00000000 --- a/wilhelm/tests/examples/xaVideoDecoderCapabilities.cpp +++ /dev/null @@ -1,314 +0,0 @@ -/* - * 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. - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <sys/time.h> -#include <fcntl.h> - -#include <OMXAL/OpenMAXAL.h> -#include <OMXAL/OpenMAXAL_Android.h> // for VP8 definitions - -#define NUM_ENGINE_INTERFACES 1 - -char unknown[50]; - -//----------------------------------------------------------------- -/* Exits the application if an error is encountered */ -#define ExitOnError(x) ExitOnErrorFunc(x,__LINE__) - -void ExitOnErrorFunc( XAresult result , int line) -{ - if (XA_RESULT_SUCCESS != result) { - fprintf(stderr, "Error %u encountered at line %d, exiting\n", result, line); - exit(EXIT_FAILURE); - } -} - -const char* videoCodecIdToString(XAuint32 decoderId) { - switch(decoderId) { - case XA_VIDEOCODEC_MPEG2: return "XA_VIDEOCODEC_MPEG2"; break; - case XA_VIDEOCODEC_H263: return "XA_VIDEOCODEC_H263"; break; - case XA_VIDEOCODEC_MPEG4: return "XA_VIDEOCODEC_MPEG4"; break; - case XA_VIDEOCODEC_AVC: return "XA_VIDEOCODEC_AVC"; break; - case XA_VIDEOCODEC_VC1: return "XA_VIDEOCODEC_VC1"; break; - case XA_ANDROID_VIDEOCODEC_VP8: return "XA_ANDROID_VIDEOCODEC_VP8"; break; - default: - sprintf(unknown, "Video codec %d unknown to OpenMAX AL", decoderId); - return unknown; - } -} - -// Use a table of [integer, string] entries to map an integer to a string - -typedef struct { - XAuint32 id; - const char *string; -} id_to_string_t; - -const char *id_to_string(XAuint32 id, const id_to_string_t *table, size_t numEntries) -{ - size_t i; - for (i = 0; i < numEntries; ++i) { - if (id == table[i].id) { - return table[i].string; - } - } - return "Unknown"; -} - -// Use a table of [integer, table] entries to map a pair of integers to a string - -typedef struct { - XAuint32 id1; - const id_to_string_t *id2_table; - size_t id2_numEntries; -} id_pair_to_string_t; - -const char *id_pair_to_string(XAuint32 id1, XAuint32 id2, const id_pair_to_string_t *table, - size_t numEntries) -{ - size_t i; - for (i = 0; i < numEntries; ++i) { - if (id1 == table[i].id1) { - return id_to_string(id2, table[i].id2_table, table[i].id2_numEntries); - } - } - return "Unknown"; -} - -// Map a video codec and profile to string - -const char *videoProfileToString(XAuint32 codec, XAuint32 profile) { - // http://en.wikipedia.org/wiki/H.262/MPEG-2_Part_2 - static const id_to_string_t MPEG2[] = { - {XA_VIDEOPROFILE_MPEG2_SIMPLE, "Simple"}, - {XA_VIDEOPROFILE_MPEG2_MAIN, "Main"}, - {XA_VIDEOPROFILE_MPEG2_422, "4:2:2"}, - {XA_VIDEOPROFILE_MPEG2_SNR, "SNR Scalable"}, - {XA_VIDEOPROFILE_MPEG2_SPATIAL, "Spatially Scalable"}, - {XA_VIDEOPROFILE_MPEG2_HIGH, "High"}, - }, H263[] = { - {XA_VIDEOPROFILE_H263_BASELINE, "baseline"}, - {XA_VIDEOPROFILE_H263_H320CODING, "H320 coding"}, - {XA_VIDEOPROFILE_H263_BACKWARDCOMPATIBLE, "backwards compatible"}, - {XA_VIDEOPROFILE_H263_ISWV2, "isw v2"}, - {XA_VIDEOPROFILE_H263_ISWV3, "isw v3"}, - {XA_VIDEOPROFILE_H263_HIGHCOMPRESSION, "high compression"}, - {XA_VIDEOPROFILE_H263_INTERNET, "internet"}, - {XA_VIDEOPROFILE_H263_INTERLACE, "interlace"}, - {XA_VIDEOPROFILE_H263_HIGHLATENCY, "high latency"}, - }, MPEG4[] = { - {XA_VIDEOPROFILE_MPEG4_SIMPLE, "simple"}, - {XA_VIDEOPROFILE_MPEG4_SIMPLESCALABLE, "simple scalable"}, - {XA_VIDEOPROFILE_MPEG4_CORE, "core"}, - {XA_VIDEOPROFILE_MPEG4_MAIN, "main"}, - {XA_VIDEOPROFILE_MPEG4_NBIT, "nbit"}, - {XA_VIDEOPROFILE_MPEG4_SCALABLETEXTURE, "scalable texture"}, - {XA_VIDEOPROFILE_MPEG4_SIMPLEFACE, "simple face"}, - {XA_VIDEOPROFILE_MPEG4_SIMPLEFBA, "simple fba"}, - {XA_VIDEOPROFILE_MPEG4_BASICANIMATED, "basic animated"}, - {XA_VIDEOPROFILE_MPEG4_HYBRID, "hybrid"}, - {XA_VIDEOPROFILE_MPEG4_ADVANCEDREALTIME, "advanced realtime"}, - {XA_VIDEOPROFILE_MPEG4_CORESCALABLE, "core scalable"}, - {XA_VIDEOPROFILE_MPEG4_ADVANCEDCODING, "advanced coding"}, - {XA_VIDEOPROFILE_MPEG4_ADVANCEDCORE, "advanced core"}, - {XA_VIDEOPROFILE_MPEG4_ADVANCEDSCALABLE, "advanced scalable"}, - // FIXME OpenMAX AL is out-of-date with respect to OpenMAX IL - {16, "advanced simple"}, - }, AVC[] = { - {XA_VIDEOPROFILE_AVC_BASELINE, "Baseline"}, - {XA_VIDEOPROFILE_AVC_MAIN, "Main"}, - {XA_VIDEOPROFILE_AVC_EXTENDED, "Extended"}, - {XA_VIDEOPROFILE_AVC_HIGH, "High"}, - {XA_VIDEOPROFILE_AVC_HIGH10, "High 10"}, - {XA_VIDEOPROFILE_AVC_HIGH422, "High 4:2:2"}, - {XA_VIDEOPROFILE_AVC_HIGH444, "High 4:4:4"}, - }, VC1[] = { - // FIXME sic should be XA_VIDEOPROFILE_* - {XA_VIDEOLEVEL_VC1_SIMPLE, "simple"}, - {XA_VIDEOLEVEL_VC1_MAIN, "main"}, - {XA_VIDEOLEVEL_VC1_ADVANCED, "advanced"}, - }; - static const id_pair_to_string_t table[] = { - {XA_VIDEOCODEC_MPEG2, MPEG2, sizeof(MPEG2) / sizeof(MPEG2[0])}, - {XA_VIDEOCODEC_H263, H263, sizeof(H263) / sizeof(H263[0])}, - {XA_VIDEOCODEC_MPEG4, MPEG4, sizeof(MPEG4) / sizeof(MPEG4[0])}, - {XA_VIDEOCODEC_AVC, AVC, sizeof(AVC) / sizeof(AVC[0])}, - {XA_VIDEOCODEC_VC1, VC1, sizeof(VC1) / sizeof(VC1[0])}, - }; - return id_pair_to_string(codec, profile, table, sizeof(table) / sizeof(table[0])); -} - -// Map a video codec and level to string - -const char* videoLevelToString(XAuint32 codec, XAuint32 level) { - static const id_to_string_t MPEG2[] = { - {XA_VIDEOLEVEL_MPEG2_LL, "Low"}, - {XA_VIDEOLEVEL_MPEG2_ML, "Main"}, - {XA_VIDEOLEVEL_MPEG2_H14, "H-14"}, - {XA_VIDEOLEVEL_MPEG2_HL, "High"}, - }, H263[]= { - {XA_VIDEOLEVEL_H263_10, "10"}, - {XA_VIDEOLEVEL_H263_20, "20"}, - {XA_VIDEOLEVEL_H263_30, "30"}, - {XA_VIDEOLEVEL_H263_40, "40"}, - {XA_VIDEOLEVEL_H263_45, "45"}, - {XA_VIDEOLEVEL_H263_50, "50"}, - {XA_VIDEOLEVEL_H263_60, "60"}, - {XA_VIDEOLEVEL_H263_70, "70"}, - }, MPEG4[] = { - {XA_VIDEOLEVEL_MPEG4_0, "0"}, - {XA_VIDEOLEVEL_MPEG4_0b, "0b"}, - {XA_VIDEOLEVEL_MPEG4_1, "1"}, - {XA_VIDEOLEVEL_MPEG4_2, "2"}, - {XA_VIDEOLEVEL_MPEG4_3, "3"}, - {XA_VIDEOLEVEL_MPEG4_4, "4"}, - {XA_VIDEOLEVEL_MPEG4_4a, "4a"}, - // FIXME OpenMAX AL is out-of-date with respect to OpenMAX IL - {8, "5"}, - }, AVC[] = { - {XA_VIDEOLEVEL_AVC_1, "1"}, - {XA_VIDEOLEVEL_AVC_1B, "1B"}, - {XA_VIDEOLEVEL_AVC_11, "1.1"}, - {XA_VIDEOLEVEL_AVC_12, "1.2"}, - {XA_VIDEOLEVEL_AVC_13, "1.3"}, - {XA_VIDEOLEVEL_AVC_2, "2"}, - {XA_VIDEOLEVEL_AVC_21, "2.1"}, - {XA_VIDEOLEVEL_AVC_22, "2.2"}, - {XA_VIDEOLEVEL_AVC_3, "3"}, - {XA_VIDEOLEVEL_AVC_31, "3.1"}, - {XA_VIDEOLEVEL_AVC_32, "3.2"}, - {XA_VIDEOLEVEL_AVC_4, "4"}, - {XA_VIDEOLEVEL_AVC_41, "4.1"}, - {XA_VIDEOLEVEL_AVC_42, "4.2"}, - {XA_VIDEOLEVEL_AVC_5, "5"}, - {XA_VIDEOLEVEL_AVC_51, "5.1"}, - }, VC1[] = { - {XA_VIDEOLEVEL_VC1_LOW, "Low"}, - {XA_VIDEOLEVEL_VC1_MEDIUM, "Medium"}, - {XA_VIDEOLEVEL_VC1_HIGH, "High"}, - {XA_VIDEOLEVEL_VC1_L0, "L0"}, - {XA_VIDEOLEVEL_VC1_L1, "L1"}, - {XA_VIDEOLEVEL_VC1_L2, "L2"}, - {XA_VIDEOLEVEL_VC1_L3, "L3"}, - {XA_VIDEOLEVEL_VC1_L4, "L4"}, - }; - static const id_pair_to_string_t table[] = { - {XA_VIDEOCODEC_MPEG2, MPEG2, sizeof(MPEG2) / sizeof(MPEG2[0])}, - {XA_VIDEOCODEC_H263, H263, sizeof(H263) / sizeof(H263[0])}, - {XA_VIDEOCODEC_MPEG4, MPEG4, sizeof(MPEG4) / sizeof(MPEG4[0])}, - {XA_VIDEOCODEC_AVC, AVC, sizeof(AVC) / sizeof(AVC[0])}, - {XA_VIDEOCODEC_VC1, VC1, sizeof(VC1) / sizeof(VC1[0])}, - }; - return id_pair_to_string(codec, level, table, sizeof(table) / sizeof(table[0])); -} - -//----------------------------------------------------------------- -void TestVideoDecoderCapabilities() { - - XAObjectItf xa; - XAresult res; - - /* parameters for the OpenMAX AL engine creation */ - XAEngineOption EngineOption[] = { - {(XAuint32) XA_ENGINEOPTION_THREADSAFE, (XAuint32) XA_BOOLEAN_TRUE} - }; - XAInterfaceID itfIidArray[NUM_ENGINE_INTERFACES] = { XA_IID_VIDEODECODERCAPABILITIES }; - XAboolean itfRequired[NUM_ENGINE_INTERFACES] = { XA_BOOLEAN_TRUE }; - - /* create OpenMAX AL engine */ - res = xaCreateEngine( &xa, 1, EngineOption, NUM_ENGINE_INTERFACES, itfIidArray, itfRequired); - ExitOnError(res); - - /* realize the engine in synchronous mode. */ - res = (*xa)->Realize(xa, XA_BOOLEAN_FALSE); ExitOnError(res); - - /* Get the video decoder capabilities interface which was explicitly requested */ - XAVideoDecoderCapabilitiesItf decItf; - res = (*xa)->GetInterface(xa, XA_IID_VIDEODECODERCAPABILITIES, (void*)&decItf); - ExitOnError(res); - - /* Query the platform capabilities */ - XAuint32 numDecoders = 0; - XAuint32 *decoderIds = NULL; - - /* -> Number of decoders */ - res = (*decItf)->GetVideoDecoders(decItf, &numDecoders, NULL); ExitOnError(res); - fprintf(stdout, "Found %d video decoders\n", numDecoders); - if (0 == numDecoders) { - fprintf(stderr, "0 video decoders is not an acceptable number, exiting\n"); - goto destroyRes; - } - - /* -> Decoder list */ - decoderIds = (XAuint32 *) malloc(numDecoders * sizeof(XAuint32)); - res = (*decItf)->GetVideoDecoders(decItf, &numDecoders, decoderIds); ExitOnError(res); - fprintf(stdout, "Decoders:\n"); - for(XAuint32 i = 0 ; i < numDecoders ; i++) { - fprintf(stdout, "decoder %d is %s\n", i, videoCodecIdToString(decoderIds[i])); - } - - /* -> Decoder capabilities */ - /* for each decoder */ - for(XAuint32 i = 0 ; i < numDecoders ; i++) { - XAuint32 nbCombinations = 0; - /* get the number of profile / level combinations */ - res = (*decItf)->GetVideoDecoderCapabilities(decItf, decoderIds[i], &nbCombinations, NULL); - ExitOnError(res); - fprintf(stdout, "decoder %s has %d profile/level combinations:\n\t", - videoCodecIdToString(decoderIds[i]), nbCombinations); - /* display the profile / level combinations */ - for(XAuint32 pl = 0 ; pl < nbCombinations ; pl++) { - XAVideoCodecDescriptor decDescriptor; - XAuint32 decoder = decoderIds[i]; - res = (*decItf)->GetVideoDecoderCapabilities(decItf, decoder, &pl, &decDescriptor); - ExitOnError(res); - XAuint32 profile = decDescriptor.profileSetting; - XAuint32 level = decDescriptor.levelSetting; - fprintf(stdout, "%u/%u ", profile, level); - ExitOnError(res); - printf("(%s/%s) ", videoProfileToString(decoder, profile), - videoLevelToString(decoder, level)); - } - fprintf(stdout, "\n"); - } - -destroyRes: - free(decoderIds); - - /* shutdown OpenMAX AL */ - (*xa)->Destroy(xa); -} - - -//----------------------------------------------------------------- -int main(int argc, char* const argv[]) -{ - XAresult result; - XAObjectItf sl; - - fprintf(stdout, "OpenMAX AL test %s: exercises SLAudioDecoderCapabiltiesItf ", argv[0]); - fprintf(stdout, "and displays the list of supported video decoders, and for each, lists the "); - fprintf(stdout, "profile / levels combinations, that map to the constants defined in "); - fprintf(stdout, "\"XA_VIDEOPROFILE and XA_VIDEOLEVEL\" section of the specification\n\n"); - - TestVideoDecoderCapabilities(); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/listening/Android.mk b/wilhelm/tests/listening/Android.mk deleted file mode 100644 index 8b165d12..00000000 --- a/wilhelm/tests/listening/Android.mk +++ /dev/null @@ -1,49 +0,0 @@ -LOCAL_PATH:= $(call my-dir) - -# - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - seekTorture.c - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_MODULE:= slesTest_seekTorture - -include $(BUILD_EXECUTABLE) - -# - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - slesTest_playMuteSolo.cpp - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_MODULE:= slesTest_playMuteSolo - -include $(BUILD_EXECUTABLE) diff --git a/wilhelm/tests/listening/seekTorture.c b/wilhelm/tests/listening/seekTorture.c deleted file mode 100644 index 25dbd9b1..00000000 --- a/wilhelm/tests/listening/seekTorture.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - * 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. - */ - -// This test program tortures the seek APIs by positioning "randomly" in a file. -// It needs as input a permuted .wav and .map produced by the permute tool. - -#include <SLES/OpenSLES.h> -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> - -#define ASSERT_EQ(x, y) assert((x) == (y)) - -int main(int argc, char **argv) -{ - if (argc != 3) { - fprintf(stderr, "usage: %s file.wav file.map\n", argv[0]); - fprintf(stderr, " where file.wav and file.map are created by the permute tool\n"); - return EXIT_FAILURE; - } - - SLresult result; - - // create engine - SLObjectItf engineObject; - result = slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - SLEngineItf engineEngine; - result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - - // create output mix - SLObjectItf outputmixObject; - result = (*engineEngine)->CreateOutputMix(engineEngine, &outputmixObject, 0, NULL, NULL); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - result = (*outputmixObject)->Realize(outputmixObject, SL_BOOLEAN_FALSE); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - - // create an audio player with URI source and output mix sink - SLDataSource audiosrc; - SLDataSink audiosnk; - SLDataLocator_OutputMix locator_outputmix; - SLDataLocator_URI locator_uri; - SLDataFormat_MIME mime; - locator_uri.locatorType = SL_DATALOCATOR_URI; - locator_uri.URI = (SLchar *) argv[1]; - locator_outputmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; - locator_outputmix.outputMix = outputmixObject; - mime.formatType = SL_DATAFORMAT_MIME; - mime.mimeType = (SLchar *) NULL; - mime.containerType = SL_CONTAINERTYPE_UNSPECIFIED; - audiosrc.pLocator = &locator_uri; - audiosrc.pFormat = &mime; - audiosnk.pLocator = &locator_outputmix; - audiosnk.pFormat = NULL; - SLObjectItf playerObject; - SLInterfaceID ids[1] = {SL_IID_SEEK}; - SLboolean flags[1] = {SL_BOOLEAN_TRUE}; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audiosrc, &audiosnk, - 1, ids, flags); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - result = (*playerObject)->Realize(playerObject, SL_BOOLEAN_FALSE); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - SLPlayItf playerPlay; - result = (*playerObject)->GetInterface(playerObject, SL_IID_PLAY, &playerPlay); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - SLSeekItf playerSeek; - result = (*playerObject)->GetInterface(playerObject, SL_IID_SEEK, &playerSeek); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - SLmillisecond duration; - result = (*playerPlay)->GetDuration(playerPlay, &duration); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - result = (*playerPlay)->SetPlayState(playerPlay, SL_PLAYSTATE_PAUSED); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - result = (*playerPlay)->GetDuration(playerPlay, &duration); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - result = (*playerPlay)->SetPlayState(playerPlay, SL_PLAYSTATE_PLAYING); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - -#if 1 - // play back a file in permuted order using the seek map - FILE *fp_map = fopen(argv[2], "r"); - if (fp_map != NULL) { - unsigned position, duration; - while (fscanf(fp_map, "%u %u", &position, &duration) == 2) { - printf("%u %u\n", position, duration); - result = (*playerSeek)->SetPosition(playerSeek, (SLmillisecond) position, - SL_SEEKMODE_ACCURATE); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - if (duration > 0) - usleep(duration * 1000); - } - } -#else - set_conio_terminal_mode(); - - // loop repeatedly, inflicting seek pain each cycle - for (;;) { - if (kbhit()) { - switch (getch()) { - case 'q': - goto out; - } - } - SLmillisecond delay = 100 + (rand() & 8191); - printf("sleep %u\n", (unsigned) delay); - usleep(delay * 1000); - SLmillisecond newPos = duration * ((rand() & 65535) / 65536.0); - printf("seek %u\n", (unsigned) newPos); - result = (*playerSeek)->SetPosition(playerSeek, newPos, SL_SEEKMODE_ACCURATE); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - SLmillisecond nowPos; - result = (*playerPlay)->GetPosition(playerPlay, &nowPos); - ASSERT_EQ(SL_RESULT_SUCCESS, result); - printf("now %u\n", (unsigned) newPos); - } -out: -#endif - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/listening/slesTest_playMuteSolo.cpp b/wilhelm/tests/listening/slesTest_playMuteSolo.cpp deleted file mode 100644 index a342b224..00000000 --- a/wilhelm/tests/listening/slesTest_playMuteSolo.cpp +++ /dev/null @@ -1,412 +0,0 @@ -/* - * 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. - */ - -#include <assert.h> -#include <pthread.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <sys/time.h> - -#include <SLES/OpenSLES.h> - - -#define MAX_NUMBER_INTERFACES 3 - -#define TEST_MUTE 0 -#define TEST_SOLO 1 - -typedef struct { - int testMode; - SLPlayItf playItf; - SLMuteSoloItf muteSoloItf; -} Context; - -//----------------------------------------------------------------- -/* Exits the application if an error is encountered */ -#define ExitOnError(x) ExitOnErrorFunc(x,__LINE__) - -void ExitOnErrorFunc( SLresult result , int line) -{ - if (SL_RESULT_SUCCESS != result) { - fprintf(stdout, "%u error code encountered at line %d, exiting\n", result, line); - exit(EXIT_FAILURE); - } -} - -// These are extensions to OpenSL ES 1.0.1 values - -#define SL_PREFETCHSTATUS_UNKNOWN 0 -#define SL_PREFETCHSTATUS_ERROR (-1) - -// Mutex and condition shared with main program to protect prefetch_status - -static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; -SLuint32 prefetch_status = SL_PREFETCHSTATUS_UNKNOWN; - -/* used to detect errors likely to have occured when the OpenSL ES framework fails to open - * a resource, for instance because a file URI is invalid, or an HTTP server doesn't respond. - */ -#define PREFETCHEVENT_ERROR_CANDIDATE \ - (SL_PREFETCHEVENT_STATUSCHANGE | SL_PREFETCHEVENT_FILLLEVELCHANGE) - -// Prefetch status callback - -void prefetch_callback(SLPrefetchStatusItf caller, void *context, SLuint32 event) -{ - SLresult result; - assert(context == NULL); - SLpermille level; - result = (*caller)->GetFillLevel(caller, &level); - assert(SL_RESULT_SUCCESS == result); - SLuint32 status; - result = (*caller)->GetPrefetchStatus(caller, &status); - assert(SL_RESULT_SUCCESS == result); - SLuint32 new_prefetch_status; - if ((event & PREFETCHEVENT_ERROR_CANDIDATE) == PREFETCHEVENT_ERROR_CANDIDATE - && level == 0 && status == SL_PREFETCHSTATUS_UNDERFLOW) { - new_prefetch_status = SL_PREFETCHSTATUS_ERROR; - } else if (event == SL_PREFETCHEVENT_STATUSCHANGE && - status == SL_PREFETCHSTATUS_SUFFICIENTDATA) { - new_prefetch_status = status; - } else { - return; - } - int ok; - ok = pthread_mutex_lock(&mutex); - assert(ok == 0); - prefetch_status = new_prefetch_status; - ok = pthread_cond_signal(&cond); - assert(ok == 0); - ok = pthread_mutex_unlock(&mutex); - assert(ok == 0); -} - -//----------------------------------------------------------------- -/* PlayItf callback for an audio player, will be called for every SL_PLAYEVENT_HEADATNEWPOS event */ -void PlayEventCallback( SLPlayItf caller, void *pContext, SLuint32 event) -{ - Context *context = (Context *) pContext; - SLPlayItf playItf = context->playItf; - SLMuteSoloItf muteSolo = context->muteSoloItf; - SLuint8 numChannels = 0; - SLresult res = (*muteSolo)->GetNumChannels(muteSolo, &numChannels); ExitOnError(res); - //fprintf(stdout, "Content has %d channel(s)\n", numChannels); - SLmillisecond position; - res = (*playItf)->GetPosition(playItf, &position); ExitOnError(res); - printf("position=%u\n", (unsigned) position); - - switch (context->testMode) { - case TEST_MUTE: { - //--------------------------------------------------- - if (numChannels > 1) { // SLMuteSoloItf only works if more than one channel - SLboolean leftMuted = SL_BOOLEAN_TRUE; - res = (*muteSolo)->GetChannelMute(muteSolo, 0, &leftMuted); ExitOnError(res); - // swap channel mute - res = (*muteSolo)->SetChannelMute(muteSolo, 0, - leftMuted == SL_BOOLEAN_TRUE ? SL_BOOLEAN_FALSE : SL_BOOLEAN_TRUE); - ExitOnError(res); - res = (*muteSolo)->SetChannelMute(muteSolo, 1, - leftMuted == SL_BOOLEAN_TRUE ? SL_BOOLEAN_TRUE : SL_BOOLEAN_FALSE); - ExitOnError(res); - if (leftMuted == SL_BOOLEAN_TRUE) { // we've swapped the channel mute above - fprintf(stdout, "channel 0: playing, channel 1: muted\n"); - } else { - fprintf(stdout, "channel 0: muted, channel 1: playing\n"); - } - } - } break; - - case TEST_SOLO: { - //--------------------------------------------------- - if (numChannels > 1) { // SLMuteSoloItf only works if more than one channel - SLboolean leftSoloed = SL_BOOLEAN_TRUE; - res = (*muteSolo)->GetChannelSolo(muteSolo, 0, &leftSoloed); ExitOnError(res); - // swap channel solo - res = (*muteSolo)->SetChannelSolo(muteSolo, 0, - leftSoloed == SL_BOOLEAN_TRUE ? SL_BOOLEAN_FALSE : SL_BOOLEAN_TRUE); - ExitOnError(res); - res = (*muteSolo)->SetChannelSolo(muteSolo, 1, - leftSoloed == SL_BOOLEAN_TRUE ? SL_BOOLEAN_TRUE : SL_BOOLEAN_FALSE); - ExitOnError(res); - if (leftSoloed == SL_BOOLEAN_TRUE) { // we've swapped the channel solo above - fprintf(stdout, "channel 0: normal, channel 1: soloed\n"); - } else { - fprintf(stdout, "channel 0: soloed, channel 1: normal\n"); - } - } - } break; - - default: - break; - } -} - -//----------------------------------------------------------------- - -/* Play an audio URIs, mute and solo channels */ -void TestPlayUri( SLObjectItf sl, const char* path) -{ - SLresult result; - SLEngineItf EngineItf; - - /* Objects this application uses: one player and an output mix */ - SLObjectItf player, outputMix; - - /* Source of audio data to play */ - SLDataSource audioSource; - SLDataLocator_URI uri; - SLDataFormat_MIME mime; - - /* Data sinks for the audio player */ - SLDataSink audioSink; - SLDataLocator_OutputMix locator_outputmix; - - /* Play, Volume and PrefetchStatus interfaces for the audio player */ - SLPlayItf playItf; - SLMuteSoloItf muteSoloItf; - SLPrefetchStatusItf prefetchItf; - - SLboolean required[MAX_NUMBER_INTERFACES]; - SLInterfaceID iidArray[MAX_NUMBER_INTERFACES]; - - /* Get the SL Engine Interface which is implicit */ - result = (*sl)->GetInterface(sl, SL_IID_ENGINE, (void*)&EngineItf); - ExitOnError(result); - - /* Initialize arrays required[] and iidArray[] */ - for (int i=0 ; i < MAX_NUMBER_INTERFACES ; i++) { - required[i] = SL_BOOLEAN_FALSE; - iidArray[i] = SL_IID_NULL; - } - - /* ------------------------------------------------------ */ - /* Configuration of the output mix */ - - /* Create Output Mix object to be used by the player */ - result = (*EngineItf)->CreateOutputMix(EngineItf, &outputMix, 0, iidArray, required); - ExitOnError(result); - - /* Realize the Output Mix object in synchronous mode */ - result = (*outputMix)->Realize(outputMix, SL_BOOLEAN_FALSE); - ExitOnError(result); - - /* Setup the data sink structure */ - locator_outputmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; - locator_outputmix.outputMix = outputMix; - audioSink.pLocator = (void*)&locator_outputmix; - audioSink.pFormat = NULL; - - /* ------------------------------------------------------ */ - /* Configuration of the player */ - - /* Set arrays required[] and iidArray[] for SLMuteSoloItf and SLPrefetchStatusItf interfaces */ - /* (SLPlayItf is implicit) */ - required[0] = SL_BOOLEAN_TRUE; - iidArray[0] = SL_IID_MUTESOLO; - required[1] = SL_BOOLEAN_TRUE; - iidArray[1] = SL_IID_PREFETCHSTATUS; - - /* Setup the data source structure for the URI */ - uri.locatorType = SL_DATALOCATOR_URI; - uri.URI = (SLchar*) path; - mime.formatType = SL_DATAFORMAT_MIME; - /* this is how ignored mime information is specified, according to OpenSL ES spec - * in 9.1.6 SLDataFormat_MIME and 8.23 SLMetadataTraversalItf GetChildInfo */ - mime.mimeType = (SLchar*)NULL; - mime.containerType = SL_CONTAINERTYPE_UNSPECIFIED; - - audioSource.pFormat = (void*)&mime; - audioSource.pLocator = (void*)&uri; - - /* Create the audio player */ - result = (*EngineItf)->CreateAudioPlayer(EngineItf, &player, &audioSource, &audioSink, 2, - iidArray, required); - ExitOnError(result); - - /* Realize the player in synchronous mode. */ - result = (*player)->Realize(player, SL_BOOLEAN_FALSE); ExitOnError(result); - fprintf(stdout, "URI example: after Realize\n"); - - /* Get the SLPlayItf, SLPrefetchStatusItf and SLMuteSoloItf interfaces for the player */ - result = (*player)->GetInterface(player, SL_IID_PLAY, (void*)&playItf); - ExitOnError(result); - - // get the prefetch status interface - result = (*player)->GetInterface(player, SL_IID_PREFETCHSTATUS, (void*)&prefetchItf); - ExitOnError(result); - - // enable prefetch status callbacks - result = (*prefetchItf)->RegisterCallback(prefetchItf, prefetch_callback, NULL); - assert(SL_RESULT_SUCCESS == result); - result = (*prefetchItf)->SetCallbackEventsMask(prefetchItf, - SL_PREFETCHEVENT_STATUSCHANGE | SL_PREFETCHEVENT_FILLLEVELCHANGE); - assert(SL_RESULT_SUCCESS == result); - - // get the mute solo interface - result = (*player)->GetInterface(player, SL_IID_MUTESOLO, (void*)&muteSoloItf); - ExitOnError(result); - - // Attempt to get the duration before it is necessarily known. - // This should always return successfully. - // The reported duration may be either - // a particular duration or SL_TIME_UNKNOWN, depending on the platform. - SLmillisecond duration; - result = (*playItf)->GetDuration(playItf, &duration); - ExitOnError(result); - printf("GetDuration after Realize but before pre-fetch: result=%u, duration=%u\n", - result, duration); - - // Attempt to get the channel count before it is necessarily known. - // This should either return successfully with a specific value (e.g. 1 or 2), - // or return zero, depending on whether the channel count is known yet. - SLuint8 numChannels = 123; - result = (*muteSoloItf)->GetNumChannels(muteSoloItf, &numChannels); - printf("GetNumChannels after Realize but before pre-fetch: result=%u, numChannels=%u\n", - result, numChannels); - if (result != SL_RESULT_PRECONDITIONS_VIOLATED) { - ExitOnError(result); - } else { - printf("Warning: returning SL_RESULT_PRECONDITIONS_VIOLATED for unknown channel count is " - "obsolete; now it should return SL_RESULT_SUCCESS and zero count if unknown\n"); - } - - /* Initialize a context for use by the play event callback */ - Context context; - context.playItf = playItf; - context.muteSoloItf = muteSoloItf; - context.testMode = TEST_MUTE; - - /* Setup to receive playback events on position updates */ - result = (*playItf)->RegisterCallback(playItf, PlayEventCallback, (void *) &context); - ExitOnError(result); - result = (*playItf)->SetCallbackEventsMask(playItf, SL_PLAYEVENT_HEADATNEWPOS); - ExitOnError(result); - result = (*playItf)->SetPositionUpdatePeriod(playItf, 1000); - ExitOnError(result); - - fprintf(stdout, "Player configured\n"); - - /* ------------------------------------------------------ */ - /* Playback and test */ - - /* Start the data prefetching by setting the player to the paused state */ - result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PAUSED ); - ExitOnError(result); - - // wait for prefetch status callback to indicate either sufficient data or error - pthread_mutex_lock(&mutex); - while (prefetch_status == SL_PREFETCHSTATUS_UNKNOWN) { - pthread_cond_wait(&cond, &mutex); - } - pthread_mutex_unlock(&mutex); - if (prefetch_status == SL_PREFETCHSTATUS_ERROR) { - fprintf(stderr, "Error during prefetch, exiting\n"); - goto destroyKillKill; - } - - /* Query the duration */ - result = (*playItf)->GetDuration(playItf, &duration); - printf("GetDuration after Realize and after pre-fetch: result=%u, duration=%u\n", - result, duration); - ExitOnError(result); - - /* Query the number of channels */ - numChannels = 123; - result = (*muteSoloItf)->GetNumChannels(muteSoloItf, &numChannels); - printf("GetNumChannels after Realize and after pre-fetch: result=%u, numChannels=%u\n", - result, numChannels); - ExitOnError(result); - fprintf(stdout, "Content has %d channel(s)\n", numChannels); - - if (numChannels == 1) { - fprintf(stdout, "SLMuteSolotItf only works one content with more than one channel. Bye\n"); - goto destroyKillKill; - } else { - /* Mute left channel */ - result = (*muteSoloItf)->SetChannelMute(muteSoloItf, 0, SL_BOOLEAN_TRUE); - ExitOnError(result); - result = (*muteSoloItf)->SetChannelMute(muteSoloItf, 1, SL_BOOLEAN_FALSE); - ExitOnError(result); - } - - /* Run the test for 10s */ - /* see PlayEventCallback() for more of the test of the SLMuteSoloItf interface */ - fprintf(stdout, "\nTesting mute functionality:\n"); - context.testMode = TEST_MUTE; - result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PLAYING ); ExitOnError(result); - usleep( 5 * 1000 * 1000); - result = (*muteSoloItf)->SetChannelMute(muteSoloItf, 0, SL_BOOLEAN_FALSE); ExitOnError(result); - result = (*muteSoloItf)->SetChannelMute(muteSoloItf, 1, SL_BOOLEAN_FALSE); ExitOnError(result); - fprintf(stdout, "\nTesting solo functionality:\n"); - context.testMode = TEST_SOLO; - usleep( 5 * 1000 * 1000); - - /* Make sure player is stopped */ - fprintf(stdout, "Stopping playback\n"); - result = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED); - ExitOnError(result); - -destroyKillKill: - - /* Destroy the players */ - (*player)->Destroy(player); - - /* Destroy Output Mix object */ - (*outputMix)->Destroy(outputMix); -} - -//----------------------------------------------------------------- -int main(int argc, char* const argv[]) -{ - SLresult result; - SLObjectItf sl; - - fprintf(stdout, "OpenSL ES test %s: exercises SLPlayItf, SLVolumeItf, SLMuteSoloItf\n", - argv[0]); - fprintf(stdout, "and AudioPlayer with SLDataLocator_URI source / OutputMix sink\n"); - fprintf(stdout, "Plays a sound and alternates the muting of the channels (for 5s).\n"); - fprintf(stdout, " and then alternates the solo\'ing of the channels (for 5s).\n"); - fprintf(stdout, "Stops after 10s\n"); - - if (argc == 1) { - fprintf(stdout, "Usage: \t%s url\n", argv[0]); - fprintf(stdout, "Example: \"%s /sdcard/my.mp3\"\n", argv[0]); - exit(EXIT_FAILURE); - } - - SLEngineOption EngineOption[] = { - {(SLuint32) SL_ENGINEOPTION_THREADSAFE, (SLuint32) SL_BOOLEAN_TRUE} - }; - - result = slCreateEngine( &sl, 1, EngineOption, 0, NULL, NULL); - ExitOnError(result); - - /* Realizing the SL Engine in synchronous mode. */ - result = (*sl)->Realize(sl, SL_BOOLEAN_FALSE); - ExitOnError(result); - - if (argc > 1) { - TestPlayUri(sl, argv[1]); - } - - /* Shutdown OpenSL ES */ - (*sl)->Destroy(sl); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/mimeUri/Android.mk b/wilhelm/tests/mimeUri/Android.mk deleted file mode 100644 index ac2ed884..00000000 --- a/wilhelm/tests/mimeUri/Android.mk +++ /dev/null @@ -1,209 +0,0 @@ -LOCAL_PATH:= $(call my-dir) - -# slesTest_playStates - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - slesTest_playStates.cpp - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -LOCAL_CFLAGS += -UNDEBUG - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_MODULE:= slesTest_playStates - -include $(BUILD_EXECUTABLE) - -# slesTest_playStreamType - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - slesTestPlayStreamType.cpp - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -LOCAL_CFLAGS += -UNDEBUG - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_MODULE:= slesTest_playStreamType - -include $(BUILD_EXECUTABLE) - -# slesTest_playUri - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - slesTestPlayUri.cpp - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -LOCAL_CFLAGS += -UNDEBUG - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_MODULE:= slesTest_playUri - -include $(BUILD_EXECUTABLE) - -# slesTest_loopUri - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - slesTestLoopUri.cpp - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -LOCAL_CFLAGS += -UNDEBUG - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_MODULE:= slesTest_loopUri - -include $(BUILD_EXECUTABLE) - -# slesTest_playUri2 - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - slesTestPlayUri2.cpp - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -LOCAL_CFLAGS += -UNDEBUG - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_MODULE:= slesTest_playUri2 - -include $(BUILD_EXECUTABLE) - -# slesTest_slowDownUri - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - slesTestSlowDownUri.cpp - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -LOCAL_CFLAGS += -UNDEBUG - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_MODULE:= slesTest_slowDownUri - -include $(BUILD_EXECUTABLE) - -# slesTest_manyPlayers - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - slesTestManyPlayers.cpp - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -LOCAL_CFLAGS += -UNDEBUG - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_MODULE:= slesTest_manyPlayers - -include $(BUILD_EXECUTABLE) - -# slesTest_getPositionUri - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - slesTestGetPositionUri.cpp - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -LOCAL_CFLAGS += -UNDEBUG - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_MODULE:= slesTest_getPositionUri - -include $(BUILD_EXECUTABLE) diff --git a/wilhelm/tests/mimeUri/slesTestGetPositionUri.cpp b/wilhelm/tests/mimeUri/slesTestGetPositionUri.cpp deleted file mode 100644 index bb29bc5e..00000000 --- a/wilhelm/tests/mimeUri/slesTestGetPositionUri.cpp +++ /dev/null @@ -1,346 +0,0 @@ -/* - * 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. - */ - -#include <stdlib.h> -#include <stdio.h> -#include <unistd.h> -#include <utils/threads.h> - -#include <SLES/OpenSLES.h> - -/* tolerance in ms for this test in time difference between reported position and time since - * playback was requested to start. This is reasonable for a local file. - */ -#define TIME_TOLERANCE_MS 600 - -/* explicitly requesting SL_IID_VOLUME and SL_IID_PREFETCHSTATUS - * on the AudioPlayer object */ -#define NUM_EXPLICIT_INTERFACES_FOR_PLAYER 2 - -/* used to detect errors likely to have occured when the OpenSL ES framework fails to open - * a resource, for instance because a file URI is invalid, or an HTTP server doesn't respond. */ -#define PREFETCHEVENT_ERROR_CANDIDATE \ - (SL_PREFETCHEVENT_STATUSCHANGE | SL_PREFETCHEVENT_FILLLEVELCHANGE) - -/* to signal to the test app the end of the stream to decode has been reached */ -bool eos = false; -android::Mutex eosLock; -android::Condition eosCondition; - -//----------------------------------------------------------------- -//* Exits the application if an error is encountered */ -#define CheckErr(x) ExitOnErrorFunc(x,__LINE__) - -void ExitOnErrorFunc( SLresult result , int line) -{ - if (SL_RESULT_SUCCESS != result) { - fprintf(stderr, "%u error code encountered at line %d, exiting\n", result, line); - exit(EXIT_FAILURE); - } -} - -bool prefetchError = false; - -//----------------------------------------------------------------- -void SignalEos() { - android::Mutex::Autolock autoLock(eosLock); - eos = true; - eosCondition.signal(); -} - -//----------------------------------------------------------------- -/* PrefetchStatusItf callback for an audio player */ -void PrefetchEventCallback( SLPrefetchStatusItf caller, void *pContext, SLuint32 event) -{ - SLpermille level = 0; - SLresult res = (*caller)->GetFillLevel(caller, &level); CheckErr(res); - SLuint32 status; - //fprintf(stdout, "PrefetchEventCallback: received event %u\n", event); - res = (*caller)->GetPrefetchStatus(caller, &status); CheckErr(res); - if ((PREFETCHEVENT_ERROR_CANDIDATE == (event & PREFETCHEVENT_ERROR_CANDIDATE)) - && (level == 0) && (status == SL_PREFETCHSTATUS_UNDERFLOW)) { - fprintf(stdout, "PrefetchEventCallback: Error while prefetching data, exiting\n"); - prefetchError = true; - return; - } - if (event & SL_PREFETCHEVENT_FILLLEVELCHANGE) { - fprintf(stdout, "PrefetchEventCallback: Buffer fill level is = %d\n", level); - } - if (event & SL_PREFETCHEVENT_STATUSCHANGE) { - fprintf(stdout, "PrefetchEventCallback: Prefetch Status is = %u\n", status); - } -} - - -//----------------------------------------------------------------- -/* PlayItf callback for playback events */ -void PlayEventCallback( - SLPlayItf caller, - void *pContext, - SLuint32 event) -{ - SLmillisecond posMsec = SL_TIME_UNKNOWN; - SLresult res; - if (SL_PLAYEVENT_HEADATEND & event) { - fprintf(stdout, "SL_PLAYEVENT_HEADATEND reached\n"); -#if 0 - res = (*caller)->GetPosition(caller, &posMsec); CheckErr(res); - fprintf(stdout, "after getPosition in SL_PLAYEVENT_HEADATEND handler\n"); - if (posMsec == SL_TIME_UNKNOWN) { - fprintf(stderr, "Error: position is SL_TIME_UNKNOWN at SL_PLAYEVENT_HEADATEND\n"); - } else { - fprintf(stdout, "position is %d at SL_PLAYEVENT_HEADATEND\n", posMsec); - } - // FIXME compare position against duration -#endif - SignalEos(); - } - - if (SL_PLAYEVENT_HEADATNEWPOS & event) { - res = (*caller)->GetPosition(caller, &posMsec); CheckErr(res); - fprintf(stdout, "SL_PLAYEVENT_HEADATNEWPOS current position=%ums\n", posMsec); - } - - if (SL_PLAYEVENT_HEADATMARKER & event) { - res = (*caller)->GetPosition(caller, &posMsec); CheckErr(res); - fprintf(stdout, "SL_PLAYEVENT_HEADATMARKER current position=%ums\n", posMsec); - } -} - - -//----------------------------------------------------------------- - -/* Play some audio from a URI and regularly query the position */ -void TestGetPositionUri( SLObjectItf sl, const char* path) -{ - SLEngineItf EngineItf; - - SLint32 numOutputs = 0; - SLuint32 deviceID = 0; - - SLresult res; - - SLDataSource audioSource; - SLDataLocator_URI uri; - SLDataFormat_MIME mime; - - SLDataSink audioSink; - SLDataLocator_OutputMix locator_outputmix; - - SLObjectItf player; - SLPlayItf playItf; - SLVolumeItf volItf; - SLPrefetchStatusItf prefetchItf; - - SLObjectItf OutputMix; - - /* variables for the duration and position tests */ - SLuint16 counter = 0; - SLmillisecond posInMsec = SL_TIME_UNKNOWN; - SLmillisecond durationInMsec = SL_TIME_UNKNOWN; - - SLboolean required[NUM_EXPLICIT_INTERFACES_FOR_PLAYER]; - SLInterfaceID iidArray[NUM_EXPLICIT_INTERFACES_FOR_PLAYER]; - - /* Get the SL Engine Interface which is implicit */ - res = (*sl)->GetInterface(sl, SL_IID_ENGINE, (void*)&EngineItf); - CheckErr(res); - - /* Initialize arrays required[] and iidArray[] */ - for (int i=0 ; i < NUM_EXPLICIT_INTERFACES_FOR_PLAYER ; i++) { - required[i] = SL_BOOLEAN_FALSE; - iidArray[i] = SL_IID_NULL; - } - - // Set arrays required[] and iidArray[] for VOLUME and PREFETCHSTATUS interface - required[0] = SL_BOOLEAN_TRUE; - iidArray[0] = SL_IID_VOLUME; - required[1] = SL_BOOLEAN_TRUE; - iidArray[1] = SL_IID_PREFETCHSTATUS; - // Create Output Mix object to be used by player - res = (*EngineItf)->CreateOutputMix(EngineItf, &OutputMix, 0, - iidArray, required); CheckErr(res); - - // Realizing the Output Mix object in synchronous mode. - res = (*OutputMix)->Realize(OutputMix, SL_BOOLEAN_FALSE); - CheckErr(res); - - /* Setup the data source structure for the URI */ - uri.locatorType = SL_DATALOCATOR_URI; - uri.URI = (SLchar*) path; - mime.formatType = SL_DATAFORMAT_MIME; - mime.mimeType = (SLchar*)NULL; - mime.containerType = SL_CONTAINERTYPE_UNSPECIFIED; - - audioSource.pFormat = (void *)&mime; - audioSource.pLocator = (void *)&uri; - - /* Setup the data sink structure */ - locator_outputmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; - locator_outputmix.outputMix = OutputMix; - audioSink.pLocator = (void *)&locator_outputmix; - audioSink.pFormat = NULL; - - /* Create the audio player */ - res = (*EngineItf)->CreateAudioPlayer(EngineItf, &player, &audioSource, &audioSink, - NUM_EXPLICIT_INTERFACES_FOR_PLAYER, iidArray, required); CheckErr(res); - - /* Realizing the player in synchronous mode. */ - res = (*player)->Realize(player, SL_BOOLEAN_FALSE); CheckErr(res); - fprintf(stdout, "URI example: after Realize\n"); - - /* Get interfaces */ - res = (*player)->GetInterface(player, SL_IID_PLAY, (void*)&playItf); - CheckErr(res); - - res = (*player)->GetInterface(player, SL_IID_VOLUME, (void*)&volItf); - CheckErr(res); - - res = (*player)->GetInterface(player, SL_IID_PREFETCHSTATUS, (void*)&prefetchItf); - CheckErr(res); - res = (*prefetchItf)->RegisterCallback(prefetchItf, PrefetchEventCallback, &prefetchItf); - CheckErr(res); - res = (*prefetchItf)->SetCallbackEventsMask(prefetchItf, - SL_PREFETCHEVENT_FILLLEVELCHANGE | SL_PREFETCHEVENT_STATUSCHANGE); - CheckErr(res); - - /* Configure fill level updates every 5 percent */ - res = (*prefetchItf)->SetFillUpdatePeriod(prefetchItf, 50); CheckErr(res); - - /* Set up the player callback to get events during the decoding */ - res = (*playItf)->SetMarkerPosition(playItf, 2000); - CheckErr(res); - res = (*playItf)->SetPositionUpdatePeriod(playItf, 500); - CheckErr(res); - res = (*playItf)->SetCallbackEventsMask(playItf, - SL_PLAYEVENT_HEADATMARKER | SL_PLAYEVENT_HEADATNEWPOS | SL_PLAYEVENT_HEADATEND); - CheckErr(res); - res = (*playItf)->RegisterCallback(playItf, PlayEventCallback, NULL); - CheckErr(res); - - /* Set the player volume */ - res = (*volItf)->SetVolumeLevel( volItf, -300); - CheckErr(res); - - /* Play the URI */ - /* first cause the player to prefetch the data */ - fprintf(stdout, "Setting the player to PAUSED to cause it to prefetch the data\n"); - res = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PAUSED ); CheckErr(res); - - usleep(100 * 1000); - /* wait until there's data to play */ - SLuint32 prefetchStatus = SL_PREFETCHSTATUS_UNDERFLOW; - SLuint32 timeOutIndex = 100; // 10s - while ((prefetchStatus != SL_PREFETCHSTATUS_SUFFICIENTDATA) && (timeOutIndex > 0) && - !prefetchError) { - usleep(100 * 1000); - (*prefetchItf)->GetPrefetchStatus(prefetchItf, &prefetchStatus); - timeOutIndex--; - } - - if (timeOutIndex == 0 || prefetchError) { - fprintf(stderr, "We're done waiting, failed to prefetch data in time, exiting\n"); - goto destroyRes; - } - - /* Display duration */ - res = (*playItf)->GetDuration(playItf, &durationInMsec); CheckErr(res); - if (durationInMsec == SL_TIME_UNKNOWN) { - fprintf(stderr, "Error: Content duration is unknown after prefetch completed, exiting\n"); - goto destroyRes; - } else { - fprintf(stdout, "Content duration is %u ms (after prefetch completed)\n", durationInMsec); - } - - fprintf(stdout, "Setting the player to PLAYING\n"); - res = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PLAYING ); CheckErr(res); - - /* Test GetPosition every second */ - while ((counter*1000) < durationInMsec) { - counter++; - usleep(1 * 1000 * 1000); //1s - res = (*playItf)->GetPosition(playItf, &posInMsec); CheckErr(res); - if (posInMsec == SL_TIME_UNKNOWN) { - fprintf(stderr, "Error: position is SL_TIME_UNKNOWN %ds after start, exiting\n", - counter); - goto destroyRes; - } else { - fprintf(stderr, "position is %dms %ds after start\n", posInMsec, counter); - } - // this test would probably deserve to be improved by relying on drift relative to - // a clock, as the operations between two consecutive sleep() are taking time as well - // and can add up - if (((SLint32)posInMsec > (counter*1000 + TIME_TOLERANCE_MS)) || - ((SLint32)posInMsec < (counter*1000 - TIME_TOLERANCE_MS))) { - fprintf(stderr, "Error: position drifted too much, exiting\n"); - goto destroyRes; - } - } - - /* Play until the end of file is reached */ - { - android::Mutex::Autolock autoLock(eosLock); - while (!eos) { - eosCondition.wait(eosLock); - } - } - fprintf(stdout, "EOS signaled, stopping playback\n"); - res = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED); CheckErr(res); - -destroyRes: - - /* Destroy the player */ - fprintf(stdout, "Destroying the player\n"); - (*player)->Destroy(player); - - /* Destroy Output Mix object */ - (*OutputMix)->Destroy(OutputMix); -} - -//----------------------------------------------------------------- -int main(int argc, char* const argv[]) -{ - SLresult res; - SLObjectItf sl; - - fprintf(stdout, "OpenSL ES test %s: exercises SLPlayItf", argv[0]); - fprintf(stdout, "and AudioPlayer with SLDataLocator_URI source / OutputMix sink\n"); - fprintf(stdout, "Plays a sound and requests position at various times\n\n"); - - if (argc == 1) { - fprintf(stdout, "Usage: %s path \n\t%s url\n", argv[0], argv[0]); - fprintf(stdout, "Example: \"%s /sdcard/my.mp3\" or \"%s file:///sdcard/my.mp3\"\n", - argv[0], argv[0]); - exit(EXIT_FAILURE); - } - - SLEngineOption EngineOption[] = { - {(SLuint32) SL_ENGINEOPTION_THREADSAFE, - (SLuint32) SL_BOOLEAN_TRUE}}; - - res = slCreateEngine( &sl, 1, EngineOption, 0, NULL, NULL); - CheckErr(res); - /* Realizing the SL Engine in synchronous mode. */ - res = (*sl)->Realize(sl, SL_BOOLEAN_FALSE); - CheckErr(res); - - TestGetPositionUri(sl, argv[1]); - - /* Shutdown OpenSL ES */ - (*sl)->Destroy(sl); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/mimeUri/slesTestLoopUri.cpp b/wilhelm/tests/mimeUri/slesTestLoopUri.cpp deleted file mode 100644 index dab0a8ea..00000000 --- a/wilhelm/tests/mimeUri/slesTestLoopUri.cpp +++ /dev/null @@ -1,321 +0,0 @@ -/* - * 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. - */ - -#include <assert.h> -#include <pthread.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <sys/time.h> - -#include <SLES/OpenSLES.h> - - -#define MAX_NUMBER_INTERFACES 2 - -#define REPETITIONS 4 - -// These are extensions to OpenSL ES 1.0.1 values - -#define SL_PREFETCHSTATUS_UNKNOWN 0 -#define SL_PREFETCHSTATUS_ERROR (-1) - -// Mutex and condition shared with main program to protect prefetch_status - -static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; -SLuint32 prefetch_status = SL_PREFETCHSTATUS_UNKNOWN; - -/* used to detect errors likely to have occured when the OpenSL ES framework fails to open - * a resource, for instance because a file URI is invalid, or an HTTP server doesn't respond. - */ -#define PREFETCHEVENT_ERROR_CANDIDATE \ - (SL_PREFETCHEVENT_STATUSCHANGE | SL_PREFETCHEVENT_FILLLEVELCHANGE) - -//----------------------------------------------------------------- -//* Exits the application if an error is encountered */ -#define CheckErr(x) ExitOnErrorFunc(x,__LINE__) - -void ExitOnErrorFunc( SLresult result , int line) -{ - if (SL_RESULT_SUCCESS != result) { - fprintf(stderr, "%u error code encountered at line %d, exiting\n", result, line); - exit(EXIT_FAILURE); - } -} - -//----------------------------------------------------------------- -/* PrefetchStatusItf callback for an audio player */ -void PrefetchEventCallback( SLPrefetchStatusItf caller, void *pContext, SLuint32 event) -{ - SLresult result; - // pContext is unused here, so we pass NULL - assert(pContext == NULL); - SLpermille level = 0; - result = (*caller)->GetFillLevel(caller, &level); - CheckErr(result); - SLuint32 status; - result = (*caller)->GetPrefetchStatus(caller, &status); - CheckErr(result); - if (event & SL_PREFETCHEVENT_FILLLEVELCHANGE) { - fprintf(stdout, "\t\tPrefetchEventCallback: Buffer fill level is = %d\n", level); - } - if (event & SL_PREFETCHEVENT_STATUSCHANGE) { - fprintf(stdout, "\t\tPrefetchEventCallback: Prefetch Status is = %u\n", status); - } - SLuint32 new_prefetch_status; - if ((event & PREFETCHEVENT_ERROR_CANDIDATE) == PREFETCHEVENT_ERROR_CANDIDATE - && (level == 0) && (status == SL_PREFETCHSTATUS_UNDERFLOW)) { - fprintf(stdout, "\t\tPrefetchEventCallback: Error while prefetching data, exiting\n"); - new_prefetch_status = SL_PREFETCHSTATUS_ERROR; - } else if (event == SL_PREFETCHEVENT_STATUSCHANGE && - status == SL_PREFETCHSTATUS_SUFFICIENTDATA) { - new_prefetch_status = status; - } else { - return; - } - int ok; - ok = pthread_mutex_lock(&mutex); - assert(ok == 0); - prefetch_status = new_prefetch_status; - ok = pthread_cond_signal(&cond); - assert(ok == 0); - ok = pthread_mutex_unlock(&mutex); - assert(ok == 0); -} - - -//----------------------------------------------------------------- -/* PlayItf callback for playback events */ -void PlayEventCallback( - SLPlayItf caller, - void *pContext, - SLuint32 event) -{ - // pContext is unused here, so we pass NULL - assert(NULL == pContext); - if (SL_PLAYEVENT_HEADATEND == event) { - printf("SL_PLAYEVENT_HEADATEND reached\n"); - } else { - fprintf(stderr, "Unexpected play event 0x%x", event); - } -} - - -//----------------------------------------------------------------- - -/* Play some music from a URI */ -void TestLoopUri( SLObjectItf sl, const char* path) -{ - SLEngineItf EngineItf; - - SLint32 numOutputs = 0; - SLuint32 deviceID = 0; - - SLresult res; - - SLDataSource audioSource; - SLDataLocator_URI uri; - SLDataFormat_MIME mime; - - SLDataSink audioSink; - SLDataLocator_OutputMix locator_outputmix; - - SLObjectItf player; - SLPlayItf playItf; - SLSeekItf seekItf; - SLPrefetchStatusItf prefetchItf; - - SLObjectItf OutputMix; - - SLboolean required[MAX_NUMBER_INTERFACES]; - SLInterfaceID iidArray[MAX_NUMBER_INTERFACES]; - - /* Get the SL Engine Interface which is implicit */ - res = (*sl)->GetInterface(sl, SL_IID_ENGINE, (void*)&EngineItf); - CheckErr(res); - - /* Initialize arrays required[] and iidArray[] */ - for (int i=0 ; i < MAX_NUMBER_INTERFACES ; i++) { - required[i] = SL_BOOLEAN_FALSE; - iidArray[i] = SL_IID_NULL; - } - - required[0] = SL_BOOLEAN_TRUE; - iidArray[0] = SL_IID_VOLUME; - // Create Output Mix object to be used by player - res = (*EngineItf)->CreateOutputMix(EngineItf, &OutputMix, 0, - iidArray, required); CheckErr(res); - - // Realizing the Output Mix object in synchronous mode. - res = (*OutputMix)->Realize(OutputMix, SL_BOOLEAN_FALSE); - CheckErr(res); - - /* Setup the data source structure for the URI */ - uri.locatorType = SL_DATALOCATOR_URI; - uri.URI = (SLchar*) path; - mime.formatType = SL_DATAFORMAT_MIME; - mime.mimeType = (SLchar*)NULL; - mime.containerType = SL_CONTAINERTYPE_UNSPECIFIED; - - audioSource.pFormat = (void *)&mime; - audioSource.pLocator = (void *)&uri; - - /* Setup the data sink structure */ - locator_outputmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; - locator_outputmix.outputMix = OutputMix; - audioSink.pLocator = (void *)&locator_outputmix; - audioSink.pFormat = NULL; - - /* Create the audio player */ - required[0] = SL_BOOLEAN_TRUE; - iidArray[0] = SL_IID_SEEK; - required[1] = SL_BOOLEAN_TRUE; - iidArray[1] = SL_IID_PREFETCHSTATUS; - res = (*EngineItf)->CreateAudioPlayer(EngineItf, &player, &audioSource, &audioSink, - MAX_NUMBER_INTERFACES, iidArray, required); CheckErr(res); - - /* Realizing the player in synchronous mode. */ - res = (*player)->Realize(player, SL_BOOLEAN_FALSE); CheckErr(res); - fprintf(stdout, "URI example: after Realize\n"); - - /* Get interfaces */ - res = (*player)->GetInterface(player, SL_IID_PLAY, (void*)&playItf); - CheckErr(res); - - res = (*player)->GetInterface(player, SL_IID_SEEK, (void*)&seekItf); - CheckErr(res); - - res = (*player)->GetInterface(player, SL_IID_PREFETCHSTATUS, (void*)&prefetchItf); - CheckErr(res); - res = (*prefetchItf)->RegisterCallback(prefetchItf, PrefetchEventCallback, NULL); - CheckErr(res); - res = (*prefetchItf)->SetCallbackEventsMask(prefetchItf, - SL_PREFETCHEVENT_FILLLEVELCHANGE | SL_PREFETCHEVENT_STATUSCHANGE); - CheckErr(res); - - /* Configure fill level updates every 5 percent */ - (*prefetchItf)->SetFillUpdatePeriod(prefetchItf, 50); - - /* Set up the player callback to get head-at-end events */ - res = (*playItf)->SetCallbackEventsMask(playItf, SL_PLAYEVENT_HEADATEND); - CheckErr(res); - res = (*playItf)->RegisterCallback(playItf, PlayEventCallback, NULL); - CheckErr(res); - - /* Display duration */ - SLmillisecond durationInMsec = SL_TIME_UNKNOWN; - res = (*playItf)->GetDuration(playItf, &durationInMsec); - CheckErr(res); - if (durationInMsec == SL_TIME_UNKNOWN) { - fprintf(stdout, "Content duration is unknown (before starting to prefetch)\n"); - } else { - fprintf(stdout, "Content duration is %u ms (before starting to prefetch)\n", - durationInMsec); - } - - /* Loop on the whole of the content */ - res = (*seekItf)->SetLoop(seekItf, SL_BOOLEAN_TRUE, 0, SL_TIME_UNKNOWN); - CheckErr(res); - - /* Play the URI */ - /* first cause the player to prefetch the data */ - res = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PAUSED ); - CheckErr(res); - - // wait for prefetch status callback to indicate either sufficient data or error - pthread_mutex_lock(&mutex); - while (prefetch_status == SL_PREFETCHSTATUS_UNKNOWN) { - pthread_cond_wait(&cond, &mutex); - } - pthread_mutex_unlock(&mutex); - if (prefetch_status == SL_PREFETCHSTATUS_ERROR) { - fprintf(stderr, "Error during prefetch, exiting\n"); - goto destroyRes; - } - - /* Display duration again, */ - res = (*playItf)->GetDuration(playItf, &durationInMsec); - CheckErr(res); - if (durationInMsec == SL_TIME_UNKNOWN) { - fprintf(stdout, "Content duration is unknown (after prefetch completed)\n"); - } else { - fprintf(stdout, "Content duration is %u ms (after prefetch completed)\n", durationInMsec); - } - - /* Start playing */ - fprintf(stdout, "starting to play\n"); - res = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PLAYING ); - CheckErr(res); - - /* Wait as long as the duration of the content, times the repetitions, - * before stopping the loop */ - usleep( (REPETITIONS-1) * durationInMsec * 1100); - res = (*seekItf)->SetLoop(seekItf, SL_BOOLEAN_FALSE, 0, SL_TIME_UNKNOWN); - CheckErr(res); - fprintf(stdout, "As of now, stopped looping (sound shouldn't repeat from now on)\n"); - /* wait some more to make sure it doesn't repeat */ - usleep(durationInMsec * 1000); - - /* Stop playback */ - fprintf(stdout, "stopping playback\n"); - res = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED); - CheckErr(res); - -destroyRes: - - /* Destroy the player */ - (*player)->Destroy(player); - - /* Destroy Output Mix object */ - (*OutputMix)->Destroy(OutputMix); -} - -//----------------------------------------------------------------- -int main(int argc, char* const argv[]) -{ - SLresult res; - SLObjectItf sl; - - fprintf(stdout, "OpenSL ES test %s: exercises SLPlayItf, SLSeekItf ", argv[0]); - fprintf(stdout, "and AudioPlayer with SLDataLocator_URI source / OutputMix sink\n"); - fprintf(stdout, "Plays a sound and loops it %d times.\n\n", REPETITIONS); - - if (argc == 1) { - fprintf(stdout, "Usage: \n\t%s path \n\t%s url\n", argv[0], argv[0]); - fprintf(stdout, "Example: \"%s /sdcard/my.mp3\" or \"%s file:///sdcard/my.mp3\"\n", - argv[0], argv[0]); - exit(EXIT_FAILURE); - } - - SLEngineOption EngineOption[] = { - {(SLuint32) SL_ENGINEOPTION_THREADSAFE, - (SLuint32) SL_BOOLEAN_TRUE}}; - - res = slCreateEngine( &sl, 1, EngineOption, 0, NULL, NULL); - CheckErr(res); - /* Realizing the SL Engine in synchronous mode. */ - res = (*sl)->Realize(sl, SL_BOOLEAN_FALSE); - CheckErr(res); - - TestLoopUri(sl, argv[1]); - - /* Shutdown OpenSL ES */ - (*sl)->Destroy(sl); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/mimeUri/slesTestManyPlayers.cpp b/wilhelm/tests/mimeUri/slesTestManyPlayers.cpp deleted file mode 100644 index cb45a3c0..00000000 --- a/wilhelm/tests/mimeUri/slesTestManyPlayers.cpp +++ /dev/null @@ -1,346 +0,0 @@ -/* - * 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. - */ - -#include <stdlib.h> -#include <stdio.h> -#include <unistd.h> -//#include <sys/time.h> - -#include <SLES/OpenSLES.h> - - -#define MAX_NUMBER_INTERFACES 2 -#define MAX_NUMBER_PLAYERS 40 - -#define PREFETCHEVENT_ERROR_CANDIDATE \ - (SL_PREFETCHEVENT_STATUSCHANGE | SL_PREFETCHEVENT_FILLLEVELCHANGE) - -/* the OpenSL ES engine from which we create all other resources */ -SLObjectItf slEngine; -SLEngineItf engineItf; -SLObjectItf outputMix; - -SLboolean required[MAX_NUMBER_INTERFACES]; -SLInterfaceID iidArray[MAX_NUMBER_INTERFACES]; - -SLObjectItf audioPlayer[MAX_NUMBER_PLAYERS]; -bool validplayer[MAX_NUMBER_PLAYERS]; -int playerNum[MAX_NUMBER_PLAYERS]; -SLPlayItf playItfs[MAX_NUMBER_PLAYERS]; -SLVolumeItf volItfs[MAX_NUMBER_PLAYERS]; -SLPrefetchStatusItf prefetchItfs[MAX_NUMBER_PLAYERS]; - -SLDataSource audioSource; -SLDataLocator_URI uri; -SLDataFormat_MIME mime; - -SLDataSink audioSink; -SLDataLocator_OutputMix locator_outputmix; - - -//----------------------------------------------------------------- -//* Exits the application if an error is encountered */ -#define CheckErr(x) ExitOnErrorFunc(x, -1, __LINE__) -#define CheckErrPlyr(x, id) ExitOnErrorFunc(x, id, __LINE__) - -void ExitOnErrorFunc( SLresult result, int playerId, int line) -{ - if (SL_RESULT_SUCCESS != result) { - if (playerId == -1) { - fprintf(stderr, "Error %u code encountered at line %d, exiting\n", result, line); - } else { - fprintf(stderr, "Error %u code encountered at line %d for player %d, exiting\n", - result, line, playerId); - } - exit(EXIT_FAILURE); - } -} - -//----------------------------------------------------------------- -/* PrefetchStatusItf callback for an audio player */ -void PrefetchEventCallback( SLPrefetchStatusItf caller, void *pContext, SLuint32 event) -{ - SLresult res; - SLpermille level = 0; - int* pPlayerId = (int*)pContext; - res = (*caller)->GetFillLevel(caller, &level); CheckErrPlyr(res, *pPlayerId); - SLuint32 status; - //fprintf(stdout, "PrefetchEventCallback: received event %u\n", event); - res = (*caller)->GetPrefetchStatus(caller, &status); CheckErrPlyr(res, *pPlayerId); - if ((PREFETCHEVENT_ERROR_CANDIDATE == (event & PREFETCHEVENT_ERROR_CANDIDATE)) - && (level == 0) && (status == SL_PREFETCHSTATUS_UNDERFLOW)) { - fprintf(stdout, "PrefetchEventCallback: Error while prefetching data for player %d, " - "exiting\n", *pPlayerId); - exit(EXIT_FAILURE); - } - if (event & SL_PREFETCHEVENT_FILLLEVELCHANGE) { - fprintf(stdout, "PrefetchEventCallback: Buffer fill level is = %d for player %d\n", - level, *pPlayerId); - } - if (event & SL_PREFETCHEVENT_STATUSCHANGE) { - fprintf(stdout, "PrefetchEventCallback: Prefetch Status is = %u for player %d\n", - status, *pPlayerId); - } -} - - -//----------------------------------------------------------------- -/* PlayItf callback for playback events */ -void PlayEventCallback( - SLPlayItf caller, - void *pContext, - SLuint32 event) -{ - SLresult res; - int* pPlayerId = (int*)pContext; - if (SL_PLAYEVENT_HEADATEND & event) { - fprintf(stdout, "SL_PLAYEVENT_HEADATEND reached for player %d\n", *pPlayerId); - //SignalEos(); - } - - if (SL_PLAYEVENT_HEADATNEWPOS & event) { - SLmillisecond pMsec = 0; - res = (*caller)->GetPosition(caller, &pMsec); CheckErrPlyr(res, *pPlayerId); - fprintf(stdout, "SL_PLAYEVENT_HEADATNEWPOS current position=%ums for player %d\n", - pMsec, *pPlayerId); - } - - if (SL_PLAYEVENT_HEADATMARKER & event) { - SLmillisecond pMsec = 0; - res = (*caller)->GetPosition(caller, &pMsec); CheckErrPlyr(res, *pPlayerId); - fprintf(stdout, "SL_PLAYEVENT_HEADATMARKER current position=%ums for player %d\n", - pMsec, *pPlayerId); - } -} - - -//----------------------------------------------------------------- -void TestSetup(const char* path) { - SLint32 numOutputs = 0; - SLuint32 deviceID = 0; - SLresult res; - - /* Create the engine */ - SLEngineOption EngineOption[] = { - {(SLuint32) SL_ENGINEOPTION_THREADSAFE, - (SLuint32) SL_BOOLEAN_TRUE}}; - - res = slCreateEngine( &slEngine, 1, EngineOption, 0, NULL, NULL); - CheckErr(res); - /* Realizing the SL Engine in synchronous mode. */ - res = (*slEngine)->Realize(slEngine, SL_BOOLEAN_FALSE); - CheckErr(res); - /* Get the SL Engine Interface which is implicit */ - res = (*slEngine)->GetInterface(slEngine, SL_IID_ENGINE, (void*)&engineItf); - CheckErr(res); - - /* Create Output Mix object to be used by player */ - res = (*engineItf)->CreateOutputMix(engineItf, &outputMix, 0, - iidArray, required); CheckErr(res); - /* Realizing the Output Mix object in synchronous mode. */ - res = (*outputMix)->Realize(outputMix, SL_BOOLEAN_FALSE); - CheckErr(res); - - /* Setup the data source structure for the URI */ - // the syntax below is more future-proof than the individual field initialization - // with regards to OpenSL ES 1.1 but adds scary compilation warnings - //uri = { SL_DATALOCATOR_URI /*locatorType*/, (SLchar*) path /*URI*/ }; - //mime = { /*formatType*/ SL_DATAFORMAT_MIME, /*mimeType*/ (SLchar*)NULL, - // /*containerType*/ SL_CONTAINERTYPE_UNSPECIFIED }; - uri.locatorType = SL_DATALOCATOR_URI; - uri.URI = (SLchar*) path; - mime.formatType = SL_DATAFORMAT_MIME; - mime.mimeType = (SLchar*)NULL; - mime.containerType = SL_CONTAINERTYPE_UNSPECIFIED; - - audioSource.pFormat = (void *)&mime; - audioSource.pLocator = (void *)&uri; - - /* Setup the data sink structure */ - locator_outputmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; - locator_outputmix.outputMix = outputMix; - audioSink.pLocator = (void *)&locator_outputmix; - audioSink.pFormat = NULL; - - /* Initialize arrays required[] and iidArray[] */ - for (int i=0 ; i < MAX_NUMBER_INTERFACES ; i++) { - required[i] = SL_BOOLEAN_FALSE; - iidArray[i] = SL_IID_NULL; - } - /* Set arrays required[] and iidArray[] for VOLUME and PREFETCHSTATUS interface */ - required[0] = SL_BOOLEAN_TRUE; - iidArray[0] = SL_IID_VOLUME; - required[1] = SL_BOOLEAN_TRUE; - iidArray[1] = SL_IID_PREFETCHSTATUS; - - fprintf(stdout, "TestSetup(%s) completed\n", path); -} - - -//----------------------------------------------------------------- -void TestTeardown() { - /* Destroy Output Mix object */ - (*outputMix)->Destroy(outputMix); - - /* Shutdown OpenSL ES */ - (*slEngine)->Destroy(slEngine); -} - - -//----------------------------------------------------------------- -/** - * Create a player and, if the creation is successful, - * configure it, and start playing. - */ -void CreatePlayer(int playerId) { - SLresult res; - playerNum[playerId] = playerId; - - /* Create the audio player */ - res = (*engineItf)->CreateAudioPlayer(engineItf, &audioPlayer[playerId], - &audioSource, &audioSink, MAX_NUMBER_INTERFACES, iidArray, required); - if (SL_RESULT_SUCCESS != res) { - // do not abort the test, just flag the player as not a candidate for destruction - fprintf(stdout, "CreateAudioPlayer for player %d failed\n", playerId); - validplayer[playerId] = false; - return; - } - validplayer[playerId] = true; - - /* Realizing the player in synchronous mode. */ - res = (*audioPlayer[playerId])->Realize(audioPlayer[playerId], SL_BOOLEAN_FALSE); - if (SL_RESULT_SUCCESS != res) { - // do not abort the test, just stop the player initialization here - fprintf(stdout, "Realize for player %d failed\n", playerId); - // this player is still a candidate for destruction - return; - } - // after this point, any failure is a test failure - - /* Get interfaces */ - res = (*audioPlayer[playerId])->GetInterface(audioPlayer[playerId], SL_IID_PLAY, - (void*)&playItfs[playerId]); - CheckErrPlyr(res, playerId); - - res = (*audioPlayer[playerId])->GetInterface(audioPlayer[playerId], SL_IID_VOLUME, - (void*)&volItfs[playerId]); - CheckErrPlyr(res, playerId); - - res = (*audioPlayer[playerId])->GetInterface(audioPlayer[playerId], SL_IID_PREFETCHSTATUS, - (void*)&prefetchItfs[playerId]); - CheckErrPlyr(res, playerId); - res = (*prefetchItfs[playerId])->RegisterCallback(prefetchItfs[playerId], PrefetchEventCallback, - &playerNum[playerId]); - CheckErrPlyr(res, playerId); - res = (*prefetchItfs[playerId])->SetCallbackEventsMask(prefetchItfs[playerId], - SL_PREFETCHEVENT_FILLLEVELCHANGE | SL_PREFETCHEVENT_STATUSCHANGE); - CheckErrPlyr(res, playerId); - - /* Set the player volume */ - res = (*volItfs[playerId])->SetVolumeLevel( volItfs[playerId], -300); - CheckErrPlyr(res, playerId); - - /* Set up the player callback to get events during the decoding */ - res = (*playItfs[playerId])->SetMarkerPosition(playItfs[playerId], 2000); - CheckErrPlyr(res, playerId); - res = (*playItfs[playerId])->SetPositionUpdatePeriod(playItfs[playerId], 500); - CheckErrPlyr(res, playerId); - res = (*playItfs[playerId])->SetCallbackEventsMask(playItfs[playerId], - SL_PLAYEVENT_HEADATMARKER | SL_PLAYEVENT_HEADATNEWPOS | SL_PLAYEVENT_HEADATEND); - CheckErrPlyr(res, playerId); - res = (*playItfs[playerId])->RegisterCallback(playItfs[playerId], PlayEventCallback, - &playerNum[playerId]); - CheckErrPlyr(res, playerId); - - /* Configure fill level updates every 5 percent */ - (*prefetchItfs[playerId])->SetFillUpdatePeriod(prefetchItfs[playerId], 50); - - /* Play the URI */ - /* first cause the player to prefetch the data */ - fprintf(stdout, "Setting player %d to PAUSED\n", playerId); - res = (*playItfs[playerId])->SetPlayState( playItfs[playerId], SL_PLAYSTATE_PAUSED ); - CheckErrPlyr(res, playerId); - /* wait until there's data to play */ - SLuint32 prefetchStatus = SL_PREFETCHSTATUS_UNDERFLOW; - SLuint32 timeOutIndex = 10; // 1s, should be enough for a local file - while ((prefetchStatus != SL_PREFETCHSTATUS_SUFFICIENTDATA) && (timeOutIndex > 0)) { - usleep(100 * 1000); - res = (*prefetchItfs[playerId])->GetPrefetchStatus(prefetchItfs[playerId], &prefetchStatus); - CheckErrPlyr(res, playerId); - timeOutIndex--; - } - - if (timeOutIndex == 0) { - fprintf(stderr, "Prefetch timed out for player %d\n", playerId); - return; - } - res = (*playItfs[playerId])->SetPlayState( playItfs[playerId], SL_PLAYSTATE_PLAYING ); - CheckErrPlyr(res, playerId); - - /* Display duration */ - SLmillisecond durationInMsec = SL_TIME_UNKNOWN; - res = (*playItfs[playerId])->GetDuration(playItfs[playerId], &durationInMsec); - CheckErrPlyr(res, playerId); - if (durationInMsec == SL_TIME_UNKNOWN) { - fprintf(stdout, "Content duration is unknown for player %d\n", playerId); - } else { - fprintf(stdout, "Content duration is %u ms for player %d\n", durationInMsec, playerId); - } -} - -//----------------------------------------------------------------- -void DestroyPlayer(int playerId) { - fprintf(stdout, "About to destroy player %d\n", playerId); - /* Destroy the player */ - (*audioPlayer[playerId])->Destroy(audioPlayer[playerId]); -} - - -//----------------------------------------------------------------- -int main(int argc, char* const argv[]) -{ - fprintf(stdout, "OpenSL ES test %s: creates and destroys as many ", argv[0]); - fprintf(stdout, "AudioPlayer objects as possible (max=%d)\n\n", MAX_NUMBER_PLAYERS); - - if (argc == 1) { - fprintf(stdout, "Usage: %s path \n\t%s url\n", argv[0], argv[0]); - fprintf(stdout, "Example: \"%s /sdcard/my.mp3\" or \"%s file:///sdcard/my.mp3\"\n", - argv[0], argv[0]); - exit(EXIT_FAILURE); - } - - TestSetup(argv[1]); - - for (int i=0 ; i<MAX_NUMBER_PLAYERS ; i++) { - CreatePlayer(i); - } - fprintf(stdout, "After creating %d AudioPlayers\n", MAX_NUMBER_PLAYERS); - - /* Wait for an arbitrary amount of time. if playing a long file, the players will still - be playing while the destructions start. */ - usleep(10*1000*1000); // 10s - - for (int i=0 ; i<MAX_NUMBER_PLAYERS ; i++) { - if (validplayer[i]) { - DestroyPlayer(i); - } - } - fprintf(stdout, "After destroying valid players among %d AudioPlayers\n", MAX_NUMBER_PLAYERS); - - TestTeardown(); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/mimeUri/slesTestPlayStreamType.cpp b/wilhelm/tests/mimeUri/slesTestPlayStreamType.cpp deleted file mode 100644 index 8987c456..00000000 --- a/wilhelm/tests/mimeUri/slesTestPlayStreamType.cpp +++ /dev/null @@ -1,271 +0,0 @@ -/* - * 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. - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <sys/time.h> - -#include <SLES/OpenSLES.h> -#ifdef ANDROID -#include <SLES/OpenSLES_Android.h> -#endif - - -#define MAX_NUMBER_INTERFACES 2 - - -//----------------------------------------------------------------- -/* Exits the application if an error is encountered */ -#define ExitOnError(x) ExitOnErrorFunc(x,__LINE__) - -void ExitOnErrorFunc( SLresult result , int line) -{ - if (SL_RESULT_SUCCESS != result) { - fprintf(stdout, "%u error code encountered at line %d, exiting\n", result, line); - exit(EXIT_FAILURE); - } -} - - -//----------------------------------------------------------------- - -/* Play an audio URIs on the given stream type */ -void TestStreamTypeConfiguration( SLObjectItf sl, const char* path, const SLint32 type) -{ - SLresult result; - SLEngineItf EngineItf; - - /* Objects this application uses: one player and an ouput mix */ - SLObjectItf player, outputMix; - - /* Source of audio data to play */ - SLDataSource audioSource; - SLDataLocator_URI uri; - SLDataFormat_MIME mime; - - /* Data sinks for the audio player */ - SLDataSink audioSink; - SLDataLocator_OutputMix locator_outputmix; - - /* Play, Volume and AndroidStreamType interfaces for the audio player */ - SLPlayItf playItf; - SLPrefetchStatusItf prefetchItf; -#ifdef ANDROID - SLAndroidConfigurationItf configItf; -#endif - - SLboolean required[MAX_NUMBER_INTERFACES]; - SLInterfaceID iidArray[MAX_NUMBER_INTERFACES]; - - /* Get the SL Engine Interface which is implicit */ - result = (*sl)->GetInterface(sl, SL_IID_ENGINE, (void*)&EngineItf); - ExitOnError(result); - - /* Initialize arrays required[] and iidArray[] */ - for (int i=0 ; i < MAX_NUMBER_INTERFACES ; i++) { - required[i] = SL_BOOLEAN_FALSE; - iidArray[i] = SL_IID_NULL; - } - - /* ------------------------------------------------------ */ - /* Configuration of the output mix */ - - /* Create Output Mix object to be used by the player */ - result = (*EngineItf)->CreateOutputMix(EngineItf, &outputMix, 0, iidArray, required); - ExitOnError(result); - - /* Realize the Output Mix object in synchronous mode */ - result = (*outputMix)->Realize(outputMix, SL_BOOLEAN_FALSE); - ExitOnError(result); - - /* Setup the data sink structure */ - locator_outputmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; - locator_outputmix.outputMix = outputMix; - audioSink.pLocator = (void*)&locator_outputmix; - audioSink.pFormat = NULL; - - /* ------------------------------------------------------ */ - /* Configuration of the player */ - - /* Set arrays required[] and iidArray[] for SLAndroidConfigurationItf interfaces */ - /* (SLPlayItf is implicit) */ - required[0] = SL_BOOLEAN_TRUE; - iidArray[0] = SL_IID_PREFETCHSTATUS; -#ifdef ANDROID - required[1] = SL_BOOLEAN_TRUE; - iidArray[1] = SL_IID_ANDROIDCONFIGURATION; -#endif - - - /* Setup the data source structure for the URI */ - uri.locatorType = SL_DATALOCATOR_URI; - uri.URI = (SLchar*) path; - mime.formatType = SL_DATAFORMAT_MIME; - /* this is how ignored mime information is specified, according to OpenSL ES spec - * in 9.1.6 SLDataFormat_MIME and 8.23 SLMetadataTraversalItf GetChildInfo */ - mime.mimeType = (SLchar*)NULL; - mime.containerType = SL_CONTAINERTYPE_UNSPECIFIED; - - audioSource.pFormat = (void*)&mime; - audioSource.pLocator = (void*)&uri; - - /* Create the audio player */ - result = (*EngineItf)->CreateAudioPlayer(EngineItf, &player, &audioSource, &audioSink, - MAX_NUMBER_INTERFACES, iidArray, required); - ExitOnError(result); - - /* Retrieve the configuration interface before the player is realized so its resources - * can be configured. - */ -#ifdef ANDROID - result = (*player)->GetInterface(player, SL_IID_ANDROIDCONFIGURATION, (void*)&configItf); - ExitOnError(result); - - /* Set the Android audio stream type on the player */ - result = (*configItf)->SetConfiguration(configItf, - SL_ANDROID_KEY_STREAM_TYPE, &type, sizeof(SLint32)); - if (SL_RESULT_PARAMETER_INVALID == result) { - fprintf(stderr, "invalid stream type %d\n", type); - } else { - ExitOnError(result); - } -#endif - - /* Realize the player in synchronous mode. */ - result = (*player)->Realize(player, SL_BOOLEAN_FALSE); ExitOnError(result); - fprintf(stdout, "URI example: after Realize\n"); - - /* Get the SLPlayItf, SLPrefetchStatusItf and SLAndroidConfigurationItf interfaces for player */ - result = (*player)->GetInterface(player, SL_IID_PLAY, (void*)&playItf); - ExitOnError(result); - - result = (*player)->GetInterface(player, SL_IID_PREFETCHSTATUS, (void*)&prefetchItf); - ExitOnError(result); - - fprintf(stdout, "Player configured\n"); - - /* ------------------------------------------------------ */ - /* Playback and test */ - - /* Start the data prefetching by setting the player to the paused state */ - result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PAUSED ); - ExitOnError(result); - - /* Wait until there's data to play */ - SLuint32 prefetchStatus = SL_PREFETCHSTATUS_UNDERFLOW; - while (prefetchStatus != SL_PREFETCHSTATUS_SUFFICIENTDATA) { - usleep(100 * 1000); - (*prefetchItf)->GetPrefetchStatus(prefetchItf, &prefetchStatus); - ExitOnError(result); - } - - /* Get duration */ - SLmillisecond durationInMsec = SL_TIME_UNKNOWN; - result = (*playItf)->GetDuration(playItf, &durationInMsec); - ExitOnError(result); - if (durationInMsec == SL_TIME_UNKNOWN) { - durationInMsec = 5000; - } - - /* Start playback */ - result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PLAYING ); - ExitOnError(result); - - usleep((durationInMsec/2) * 1000); - -#ifdef ANDROID - /* Get the stream type during playback */ - SLint32 currentType = -1; - SLuint32 valueSize = sizeof(SLint32) * 2; // trying too big on purpose - result = (*configItf)->GetConfiguration(configItf, - SL_ANDROID_KEY_STREAM_TYPE, &valueSize, NULL); - ExitOnError(result); - if (valueSize != sizeof(SLint32)) { - fprintf(stderr, "ERROR: size for stream type is %u, should be %u\n", - valueSize, sizeof(SLint32)); - } - result = (*configItf)->GetConfiguration(configItf, - SL_ANDROID_KEY_STREAM_TYPE, &valueSize, ¤tType); - ExitOnError(result); - if (currentType != type) { - fprintf(stderr, "ERROR: stream type is %u, should be %u\n", currentType, type); - } -#endif - - usleep((durationInMsec/2) * 1000); - - /* Make sure player is stopped */ - fprintf(stdout, "Stopping playback\n"); - result = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED); - ExitOnError(result); - -#ifdef ANDROID - /* Try again to get the stream type, just in case it changed behind our back */ - result = (*configItf)->GetConfiguration(configItf, - SL_ANDROID_KEY_STREAM_TYPE, &valueSize, ¤tType); - ExitOnError(result); - if (currentType != type) { - fprintf(stderr, "ERROR: stream type is %u, should be %u\n", currentType, type); - } -#endif - - /* Destroy the player */ - (*player)->Destroy(player); - - /* Destroy Output Mix object */ - (*outputMix)->Destroy(outputMix); -} - -//----------------------------------------------------------------- -int main(int argc, char* const argv[]) -{ - SLresult result; - SLObjectItf sl; - - fprintf(stdout, "OpenSL ES test %s: exercises SLPlayItf, SLAndroidConfigurationItf\n", - argv[0]); - fprintf(stdout, "and AudioPlayer with SLDataLocator_URI source / OutputMix sink\n"); - fprintf(stdout, "Plays a sound on the specified android stream type\n"); - - if (argc < 3) { - fprintf(stdout, "Usage: \t%s url stream_type\n", argv[0]); - fprintf(stdout, " where stream_type is one of the SL_ANDROID_STREAM_ constants.\n"); - fprintf(stdout, "Example: \"%s /sdcard/my.mp3 5\" \n", argv[0]); - fprintf(stdout, "Stream type %d is the default (media or music), %d is notifications\n", - SL_ANDROID_STREAM_MEDIA, SL_ANDROID_STREAM_NOTIFICATION); - return EXIT_FAILURE; - } - - SLEngineOption EngineOption[] = { - {(SLuint32) SL_ENGINEOPTION_THREADSAFE, (SLuint32) SL_BOOLEAN_TRUE} - }; - - result = slCreateEngine( &sl, 1, EngineOption, 0, NULL, NULL); - ExitOnError(result); - - /* Realizing the SL Engine in synchronous mode. */ - result = (*sl)->Realize(sl, SL_BOOLEAN_FALSE); - ExitOnError(result); - - TestStreamTypeConfiguration(sl, argv[1], (SLint32)atoi(argv[2])); - - /* Shutdown OpenSL ES */ - (*sl)->Destroy(sl); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/mimeUri/slesTestPlayUri.cpp b/wilhelm/tests/mimeUri/slesTestPlayUri.cpp deleted file mode 100644 index 19fcb53c..00000000 --- a/wilhelm/tests/mimeUri/slesTestPlayUri.cpp +++ /dev/null @@ -1,355 +0,0 @@ -/* - * 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. - */ - -/* - * Copyright (c) 2009 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this - * software and /or associated documentation files (the "Materials "), to deal in the - * Materials without restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies of the Materials, - * and to permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS IN THE - * MATERIALS. - */ - -#include <stdlib.h> -#include <stdio.h> -//#include <string.h> -#include <unistd.h> -//#include <sys/time.h> - -#include <SLES/OpenSLES.h> - -//#define TEST_VOLUME_ITF -//#define TEST_COLD_START - -#define MAX_NUMBER_INTERFACES 2 - -#define PREFETCHEVENT_ERROR_CANDIDATE \ - (SL_PREFETCHEVENT_STATUSCHANGE | SL_PREFETCHEVENT_FILLLEVELCHANGE) - -//----------------------------------------------------------------- -//* Exits the application if an error is encountered */ -#define CheckErr(x) ExitOnErrorFunc(x,__LINE__) - -void ExitOnErrorFunc( SLresult result , int line) -{ - if (SL_RESULT_SUCCESS != result) { - fprintf(stderr, "%u error code encountered at line %d, exiting\n", result, line); - exit(EXIT_FAILURE); - } -} - -bool prefetchError = false; - -//----------------------------------------------------------------- -/* PrefetchStatusItf callback for an audio player */ -void PrefetchEventCallback( SLPrefetchStatusItf caller, void *pContext, SLuint32 event) -{ - SLpermille level = 0; - SLresult result; - result = (*caller)->GetFillLevel(caller, &level); - CheckErr(result); - SLuint32 status; - //fprintf(stdout, "PrefetchEventCallback: received event %u\n", event); - result = (*caller)->GetPrefetchStatus(caller, &status); - CheckErr(result); - if ((PREFETCHEVENT_ERROR_CANDIDATE == (event & PREFETCHEVENT_ERROR_CANDIDATE)) - && (level == 0) && (status == SL_PREFETCHSTATUS_UNDERFLOW)) { - fprintf(stdout, "PrefetchEventCallback: Error while prefetching data, exiting\n"); - prefetchError = true; - } - if (event & SL_PREFETCHEVENT_FILLLEVELCHANGE) { - fprintf(stdout, "PrefetchEventCallback: Buffer fill level is = %d\n", level); - } - if (event & SL_PREFETCHEVENT_STATUSCHANGE) { - fprintf(stdout, "PrefetchEventCallback: Prefetch Status is = %u\n", status); - } -} - - -//----------------------------------------------------------------- -/* PlayItf callback for playback events */ -void PlayEventCallback( - SLPlayItf caller, - void *pContext, - SLuint32 event) -{ - if (SL_PLAYEVENT_HEADATEND & event) { - fprintf(stdout, "SL_PLAYEVENT_HEADATEND reached\n"); - //SignalEos(); - } - - if (SL_PLAYEVENT_HEADATNEWPOS & event) { - SLmillisecond pMsec = 0; - (*caller)->GetPosition(caller, &pMsec); - fprintf(stdout, "SL_PLAYEVENT_HEADATNEWPOS current position=%ums\n", pMsec); - } - - if (SL_PLAYEVENT_HEADATMARKER & event) { - SLmillisecond pMsec = 0; - (*caller)->GetPosition(caller, &pMsec); - fprintf(stdout, "SL_PLAYEVENT_HEADATMARKER current position=%ums\n", pMsec); - } -} - - -//----------------------------------------------------------------- - -/* Play some music from a URI */ -void TestPlayUri( SLObjectItf sl, const char* path) -{ - SLEngineItf EngineItf; - - SLint32 numOutputs = 0; - SLuint32 deviceID = 0; - - SLresult res; - - SLDataSource audioSource; - SLDataLocator_URI uri; - SLDataFormat_MIME mime; - - SLDataSink audioSink; - SLDataLocator_OutputMix locator_outputmix; - - SLObjectItf player; - SLPlayItf playItf; - SLVolumeItf volItf; - SLPrefetchStatusItf prefetchItf; - - SLObjectItf OutputMix; - - SLboolean required[MAX_NUMBER_INTERFACES]; - SLInterfaceID iidArray[MAX_NUMBER_INTERFACES]; - - /* Get the SL Engine Interface which is implicit */ - res = (*sl)->GetInterface(sl, SL_IID_ENGINE, (void*)&EngineItf); - CheckErr(res); - - /* Initialize arrays required[] and iidArray[] */ - for (int i=0 ; i < MAX_NUMBER_INTERFACES ; i++) { - required[i] = SL_BOOLEAN_FALSE; - iidArray[i] = SL_IID_NULL; - } - - // Set arrays required[] and iidArray[] for VOLUME and PREFETCHSTATUS interface - required[0] = SL_BOOLEAN_TRUE; - iidArray[0] = SL_IID_VOLUME; - required[1] = SL_BOOLEAN_TRUE; - iidArray[1] = SL_IID_PREFETCHSTATUS; - // Create Output Mix object to be used by player - res = (*EngineItf)->CreateOutputMix(EngineItf, &OutputMix, 0, - iidArray, required); CheckErr(res); - - // Realizing the Output Mix object in synchronous mode. - res = (*OutputMix)->Realize(OutputMix, SL_BOOLEAN_FALSE); - CheckErr(res); - - /* Setup the data source structure for the URI */ - uri.locatorType = SL_DATALOCATOR_URI; - uri.URI = (SLchar*) path; - mime.formatType = SL_DATAFORMAT_MIME; - mime.mimeType = (SLchar*)NULL; - mime.containerType = SL_CONTAINERTYPE_UNSPECIFIED; - - audioSource.pFormat = (void *)&mime; - audioSource.pLocator = (void *)&uri; - - /* Setup the data sink structure */ - locator_outputmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; - locator_outputmix.outputMix = OutputMix; - audioSink.pLocator = (void *)&locator_outputmix; - audioSink.pFormat = NULL; - - /* Create the audio player */ - res = (*EngineItf)->CreateAudioPlayer(EngineItf, &player, &audioSource, &audioSink, - MAX_NUMBER_INTERFACES, iidArray, required); CheckErr(res); - - /* Realizing the player in synchronous mode. */ - res = (*player)->Realize(player, SL_BOOLEAN_FALSE); CheckErr(res); - fprintf(stdout, "URI example: after Realize\n"); - - /* Get interfaces */ - res = (*player)->GetInterface(player, SL_IID_PLAY, (void*)&playItf); - CheckErr(res); - - res = (*player)->GetInterface(player, SL_IID_VOLUME, (void*)&volItf); - CheckErr(res); - - res = (*player)->GetInterface(player, SL_IID_PREFETCHSTATUS, (void*)&prefetchItf); - CheckErr(res); - res = (*prefetchItf)->RegisterCallback(prefetchItf, PrefetchEventCallback, &prefetchItf); - CheckErr(res); - res = (*prefetchItf)->SetCallbackEventsMask(prefetchItf, - SL_PREFETCHEVENT_FILLLEVELCHANGE | SL_PREFETCHEVENT_STATUSCHANGE); - CheckErr(res); - - /* Configure fill level updates every 5 percent */ - (*prefetchItf)->SetFillUpdatePeriod(prefetchItf, 50); - - /* Set up the player callback to get events during the decoding */ - res = (*playItf)->SetMarkerPosition(playItf, 2000); - CheckErr(res); - res = (*playItf)->SetPositionUpdatePeriod(playItf, 500); - CheckErr(res); - res = (*playItf)->SetCallbackEventsMask(playItf, - SL_PLAYEVENT_HEADATMARKER | SL_PLAYEVENT_HEADATNEWPOS | SL_PLAYEVENT_HEADATEND); - CheckErr(res); - res = (*playItf)->RegisterCallback(playItf, PlayEventCallback, NULL); - CheckErr(res); - - /* Display duration */ - SLmillisecond durationInMsec = SL_TIME_UNKNOWN; - res = (*playItf)->GetDuration(playItf, &durationInMsec); - CheckErr(res); - if (durationInMsec == SL_TIME_UNKNOWN) { - fprintf(stdout, "Content duration is unknown (before starting to prefetch)\n"); - } else { - fprintf(stdout, "Content duration is %u ms (before starting to prefetch)\n", - durationInMsec); - } - - /* Set the player volume */ - res = (*volItf)->SetVolumeLevel( volItf, -300); - CheckErr(res); - - /* Play the URI */ - /* first cause the player to prefetch the data */ - fprintf(stdout, "Before set to PAUSED\n"); - res = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PAUSED ); - fprintf(stdout, "After set to PAUSED\n"); - CheckErr(res); - - usleep(100 * 1000); - /* wait until there's data to play */ - //SLpermille fillLevel = 0; - SLuint32 prefetchStatus = SL_PREFETCHSTATUS_UNDERFLOW; - SLuint32 timeOutIndex = 100; // 10s - while ((prefetchStatus != SL_PREFETCHSTATUS_SUFFICIENTDATA) && (timeOutIndex > 0) && - !prefetchError) { - usleep(100 * 1000); - (*prefetchItf)->GetPrefetchStatus(prefetchItf, &prefetchStatus); - timeOutIndex--; - } - - if (timeOutIndex == 0 || prefetchError) { - fprintf(stderr, "We\'re done waiting, failed to prefetch data in time, exiting\n"); - goto destroyRes; - } - - /* Display duration again, */ - res = (*playItf)->GetDuration(playItf, &durationInMsec); - CheckErr(res); - if (durationInMsec == SL_TIME_UNKNOWN) { - fprintf(stdout, "Content duration is unknown (after prefetch completed)\n"); - } else { - fprintf(stdout, "Content duration is %u ms (after prefetch completed)\n", durationInMsec); - } - - fprintf(stdout, "URI example: starting to play\n"); - res = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PLAYING ); - CheckErr(res); - -#ifdef TEST_VOLUME_ITF - usleep(5*1000 * 1000); - fprintf(stdout, "setting vol to 0\n"); - (*volItf)->SetVolumeLevel( volItf, 0); - usleep(3*1000 * 1000); - fprintf(stdout, "setting vol to -20dB\n"); - (*volItf)->SetVolumeLevel( volItf, -2000); - usleep(3*1000 * 1000); - fprintf(stdout, "mute\n"); - (*volItf)->SetMute( volItf, SL_BOOLEAN_TRUE); - usleep(3*1000 * 1000); - fprintf(stdout, "setting vol to 0dB while muted\n"); - (*volItf)->SetVolumeLevel( volItf, 0); - usleep(3*1000 * 1000); - fprintf(stdout, "unmuting\n"); - (*volItf)->SetMute( volItf, SL_BOOLEAN_FALSE); - usleep(3*1000 * 1000); -#endif - -#ifndef TEST_COLD_START - usleep(durationInMsec * 1000); -#else - /* Wait as long as the duration of the content before stopping */ - /* Experiment: wait for the duration + 200ms: with a cold start of the audio hardware, we */ - /* won't see the SL_PLAYEVENT_HEADATEND event, due to hw wake up induced latency, but */ - /* with a warm start it will be received. */ - usleep((durationInMsec + 200) * 1000); -#endif - - /* Make sure player is stopped */ - fprintf(stdout, "URI example: stopping playback\n"); - res = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED); - CheckErr(res); - -destroyRes: - - /* Destroy the player */ - (*player)->Destroy(player); - - /* Destroy Output Mix object */ - (*OutputMix)->Destroy(OutputMix); -} - -//----------------------------------------------------------------- -int main(int argc, char* const argv[]) -{ - SLresult res; - SLObjectItf sl; - - fprintf(stdout, "OpenSL ES test %s: exercises SLPlayItf, SLVolumeItf ", argv[0]); - fprintf(stdout, "and AudioPlayer with SLDataLocator_URI source / OutputMix sink\n"); - fprintf(stdout, "Plays a sound and stops after its reported duration\n\n"); - - if (argc == 1) { - fprintf(stdout, "Usage: %s path \n\t%s url\n", argv[0], argv[0]); - fprintf(stdout, "Example: \"%s /sdcard/my.mp3\" or \"%s file:///sdcard/my.mp3\"\n", - argv[0], argv[0]); - exit(EXIT_FAILURE); - } - - SLEngineOption EngineOption[] = { - {(SLuint32) SL_ENGINEOPTION_THREADSAFE, - (SLuint32) SL_BOOLEAN_TRUE}}; - - res = slCreateEngine( &sl, 1, EngineOption, 0, NULL, NULL); - CheckErr(res); - /* Realizing the SL Engine in synchronous mode. */ - res = (*sl)->Realize(sl, SL_BOOLEAN_FALSE); - CheckErr(res); - - TestPlayUri(sl, argv[1]); - - /* Shutdown OpenSL ES */ - (*sl)->Destroy(sl); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/mimeUri/slesTestPlayUri2.cpp b/wilhelm/tests/mimeUri/slesTestPlayUri2.cpp deleted file mode 100644 index 9b84b659..00000000 --- a/wilhelm/tests/mimeUri/slesTestPlayUri2.cpp +++ /dev/null @@ -1,288 +0,0 @@ -/* - * 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. - */ - -#include <stdlib.h> -#include <stdio.h> -#include <unistd.h> - -#include <SLES/OpenSLES.h> - - -#define MAX_NUMBER_INTERFACES 3 - - -//----------------------------------------------------------------- -/* Exits the application if an error is encountered */ -void ExitOnError( SLresult result ) -{ - if (SL_RESULT_SUCCESS != result) { - fprintf(stdout, "%u error code encountered, exiting\n", result); - exit(EXIT_FAILURE); - } -} - -//----------------------------------------------------------------- -/* PlayItf callback for an audio player */ -void PlayEventCallback( SLPlayItf caller, void *pContext, SLuint32 event) -{ - fprintf(stdout, "PlayEventCallback event = "); - if (event & SL_PLAYEVENT_HEADATEND) { - fprintf(stdout, "SL_PLAYEVENT_HEADATEND "); - } - if (event & SL_PLAYEVENT_HEADATMARKER) { - fprintf(stdout, "SL_PLAYEVENT_HEADATMARKER "); - } - if (event & SL_PLAYEVENT_HEADATNEWPOS) { - fprintf(stdout, "SL_PLAYEVENT_HEADATNEWPOS "); - } - if (event & SL_PLAYEVENT_HEADMOVING) { - fprintf(stdout, "SL_PLAYEVENT_HEADMOVING "); - } - if (event & SL_PLAYEVENT_HEADSTALLED) { - fprintf(stdout, "SL_PLAYEVENT_HEADSTALLED"); - } - fprintf(stdout, "\n"); -} - -//----------------------------------------------------------------- - -/* Play two audio URIs, pan them left and right */ -void TestPlayUri( SLObjectItf sl, const char* path, const char* path2) -{ - SLresult result; - SLEngineItf EngineItf; - - /* Objects this application uses: two players and an ouput mix */ - SLObjectItf player, player2, outputMix; - - /* Source of audio data to play, we'll reuse the same source for two different players */ - SLDataSource audioSource; - SLDataLocator_URI uri; - SLDataFormat_MIME mime; - - /* Data sinks for the two audio players */ - SLDataSink audioSink; - SLDataLocator_OutputMix locator_outputmix; - - /* Play, Volume and PrefetchStatus interfaces for the audio players */ - SLPlayItf playItf, playItf2; - SLVolumeItf volItf, volItf2; - SLPrefetchStatusItf prefetchItf, prefetchItf2; - - SLboolean required[MAX_NUMBER_INTERFACES]; - SLInterfaceID iidArray[MAX_NUMBER_INTERFACES]; - - /* Get the SL Engine Interface which is implicit */ - result = (*sl)->GetInterface(sl, SL_IID_ENGINE, (void*)&EngineItf); - ExitOnError(result); - - /* Initialize arrays required[] and iidArray[] */ - for (int i=0 ; i < MAX_NUMBER_INTERFACES ; i++) { - required[i] = SL_BOOLEAN_FALSE; - iidArray[i] = SL_IID_NULL; - } - /* Set arrays required[] and iidArray[] for SLVolumeItf and SLPrefetchStatusItf interfaces */ - /* (SLPlayItf is implicit) */ - required[0] = SL_BOOLEAN_TRUE; - iidArray[0] = SL_IID_VOLUME; - required[1] = SL_BOOLEAN_TRUE; - iidArray[1] = SL_IID_PREFETCHSTATUS; - - /* ------------------------------------------------------ */ - /* Configuration of the output mix */ - - /* Create Output Mix object to be used each player */ - result = (*EngineItf)->CreateOutputMix(EngineItf, &outputMix, 0, iidArray, required); - ExitOnError(result); - - /* Realize the Output Mix object in synchronous mode */ - result = (*outputMix)->Realize(outputMix, SL_BOOLEAN_FALSE); - ExitOnError(result); - - /* Setup the data sink structure */ - locator_outputmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; - locator_outputmix.outputMix = outputMix; - audioSink.pLocator = (void *)&locator_outputmix; - audioSink.pFormat = NULL; - - /* ------------------------------------------------------ */ - /* Configuration of the players */ - - /* Setup the data source structure for the first URI */ - uri.locatorType = SL_DATALOCATOR_URI; - uri.URI = (SLchar*) path; - mime.formatType = SL_DATAFORMAT_MIME; - /* this is how ignored mime information is specified, according to OpenSL ES spec - * in 9.1.6 SLDataFormat_MIME and 8.23 SLMetadataTraversalItf GetChildInfo */ - mime.mimeType = (SLchar*)NULL; - mime.containerType = SL_CONTAINERTYPE_UNSPECIFIED; - - audioSource.pFormat = (void *)&mime; - audioSource.pLocator = (void *)&uri; - - /* Create the first audio player */ - result = (*EngineItf)->CreateAudioPlayer(EngineItf, &player, &audioSource, &audioSink, 2, - iidArray, required); - ExitOnError(result); - - /* Create the second audio player with a different path for its data source */ - uri.URI = (SLchar*) path2; - audioSource.pLocator = (void *)&uri; - result = (*EngineItf)->CreateAudioPlayer(EngineItf, &player2, &audioSource, &audioSink, 2, - iidArray, required); - ExitOnError(result); - - /* Realize the players in synchronous mode. */ - result = (*player)->Realize(player, SL_BOOLEAN_FALSE); ExitOnError(result); - result = (*player)->Realize(player2, SL_BOOLEAN_FALSE); ExitOnError(result); - //fprintf(stdout, "URI example: after Realize\n"); - - /* Get the SLPlayItf, SLVolumeItf and SLPrefetchStatusItf interfaces for each player */ - result = (*player)->GetInterface(player, SL_IID_PLAY, (void*)&playItf); - ExitOnError(result); - result = (*player)->GetInterface(player2, SL_IID_PLAY, (void*)&playItf2); - ExitOnError(result); - - result = (*player)->GetInterface(player, SL_IID_VOLUME, (void*)&volItf); - ExitOnError(result); - result = (*player2)->GetInterface(player2, SL_IID_VOLUME, (void*)&volItf2); - ExitOnError(result); - - result = (*player)->GetInterface(player, SL_IID_PREFETCHSTATUS, (void*)&prefetchItf); - ExitOnError(result); - result = (*player2)->GetInterface(player2, SL_IID_PREFETCHSTATUS, (void*)&prefetchItf2); - ExitOnError(result); - - /* Setup to receive playback events */ - result = (*playItf)->RegisterCallback(playItf, PlayEventCallback, &playItf); - ExitOnError(result); - result = (*playItf)->SetCallbackEventsMask(playItf, - SL_PLAYEVENT_HEADATEND| SL_PLAYEVENT_HEADATMARKER | SL_PLAYEVENT_HEADATNEWPOS - | SL_PLAYEVENT_HEADMOVING | SL_PLAYEVENT_HEADSTALLED); - ExitOnError(result); - - /* Set the player volume */ - result = (*volItf)->SetVolumeLevel( volItf, -300); - ExitOnError(result); - /* Pan the first player to the left */ - result = (*volItf)->EnableStereoPosition( volItf, SL_BOOLEAN_TRUE); ExitOnError(result); - result = (*volItf)->SetStereoPosition( volItf, -1000); ExitOnError(result); - /* Pan the second player to the right */ - result = (*volItf2)->EnableStereoPosition( volItf2, SL_BOOLEAN_TRUE); ExitOnError(result); - result = (*volItf2)->SetStereoPosition( volItf2, 1000); ExitOnError(result); - - /* ------------------------------------------------------ */ - /* Playback */ - - /* Start the data prefetching by setting the players to the paused state */ - result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PAUSED ); - ExitOnError(result); - result = (*playItf2)->SetPlayState( playItf2, SL_PLAYSTATE_PAUSED ); - ExitOnError(result); - - /* wait until there's data to play */ - SLuint32 prefetchStatus = SL_PREFETCHSTATUS_UNDERFLOW; - while (prefetchStatus != SL_PREFETCHSTATUS_SUFFICIENTDATA) { - usleep(100 * 1000); - (*prefetchItf)->GetPrefetchStatus(prefetchItf, &prefetchStatus); - } - prefetchStatus = SL_PREFETCHSTATUS_UNDERFLOW; - while (prefetchStatus != SL_PREFETCHSTATUS_SUFFICIENTDATA) { - usleep(100 * 1000); - (*prefetchItf2)->GetPrefetchStatus(prefetchItf2, &prefetchStatus); - } - - result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PLAYING ); - ExitOnError(result); - - /* Wait 2s before starting the second player */ - usleep(2000 * 1000); - fprintf(stdout, "URI example: starting to play %s\n", path2); - result = (*playItf2)->SetPlayState( playItf2, SL_PLAYSTATE_PLAYING ); - ExitOnError(result); - - /* Display duration */ - SLmillisecond durationInMsec = SL_TIME_UNKNOWN; - result = (*playItf)->GetDuration(playItf, &durationInMsec); - ExitOnError(result); - if (durationInMsec == SL_TIME_UNKNOWN) { - fprintf(stdout, "Content duration of first URI is unknown\n"); - } else { - fprintf(stdout, "Content duration of first URI is %u ms\n", durationInMsec); - } - - /* Wait as long as the duration of the first URI + 2s before stopping */ - if (durationInMsec == SL_TIME_UNKNOWN) { - durationInMsec = 5000; /* arbitrary time when duration is unknown */ - } - usleep((durationInMsec + 2000) * 1000); - - /* Make sure player is stopped */ - fprintf(stdout, "URI example: stopping playback\n"); - result = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED); - ExitOnError(result); - result = (*playItf2)->SetPlayState(playItf2, SL_PLAYSTATE_STOPPED); - ExitOnError(result); - - /* Destroy the players */ - (*player)->Destroy(player); - (*player2)->Destroy(player2); - - /* Destroy Output Mix object */ - (*outputMix)->Destroy(outputMix); -} - -//----------------------------------------------------------------- -int main(int argc, char* const argv[]) -{ - SLresult result; - SLObjectItf sl; - - fprintf(stdout, "OpenSL ES test %s: exercises SLPlayItf, SLVolumeItf (incl. stereo position) ", - argv[0]); - fprintf(stdout, "and AudioPlayer with SLDataLocator_URI source / OutputMix sink\n"); - fprintf(stdout, "Plays two sounds (or twice the same) and pans them left and right."); - fprintf(stdout, "Stops after the end of the first + 2s\n"); - - if (argc == 1) { - fprintf(stdout, "Usage: \n\t%s url1 url2 \n\t%s url\n", argv[0], argv[0]); - fprintf(stdout, "Example: \"%s /sdcard/my.mp3 http://blabla/my.wav\" ", argv[0]); - fprintf(stdout, "or \"%s file:///sdcard/my.mp3\"\n", argv[0]); - exit(EXIT_FAILURE); - } - - SLEngineOption EngineOption[] = { - {(SLuint32) SL_ENGINEOPTION_THREADSAFE, (SLuint32) SL_BOOLEAN_TRUE} - }; - - result = slCreateEngine( &sl, 1, EngineOption, 0, NULL, NULL); - ExitOnError(result); - - /* Realizing the SL Engine in synchronous mode. */ - result = (*sl)->Realize(sl, SL_BOOLEAN_FALSE); - ExitOnError(result); - - if (argc == 2) { - TestPlayUri(sl, argv[1], argv[1]); - } else if (argc == 3) { - TestPlayUri(sl, argv[1], argv[2]); - } - - /* Shutdown OpenSL ES */ - (*sl)->Destroy(sl); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/mimeUri/slesTestSlowDownUri.cpp b/wilhelm/tests/mimeUri/slesTestSlowDownUri.cpp deleted file mode 100644 index 0c2dc7e7..00000000 --- a/wilhelm/tests/mimeUri/slesTestSlowDownUri.cpp +++ /dev/null @@ -1,428 +0,0 @@ -/* - * 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. - */ - -#include <assert.h> -#include <pthread.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <sys/time.h> - -#include <SLES/OpenSLES.h> - - -#define MAX_NUMBER_INTERFACES 3 - -#define REPETITIONS 4 // 4 repetitions, but will stop the looping before the end - -#define INITIAL_RATE 2000 // 2x normal playback speed - -// These are extensions to OpenSL ES 1.0.1 values - -#define SL_PREFETCHSTATUS_UNKNOWN 0 -#define SL_PREFETCHSTATUS_ERROR (-1) - -// Mutex and condition shared with main program to protect prefetch_status - -static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; -SLuint32 prefetch_status = SL_PREFETCHSTATUS_UNKNOWN; - -/* used to detect errors likely to have occured when the OpenSL ES framework fails to open - * a resource, for instance because a file URI is invalid, or an HTTP server doesn't respond. - */ -#define PREFETCHEVENT_ERROR_CANDIDATE \ - (SL_PREFETCHEVENT_STATUSCHANGE | SL_PREFETCHEVENT_FILLLEVELCHANGE) - -//----------------------------------------------------------------- -//* Exits the application if an error is encountered */ -#define CheckErr(x) ExitOnErrorFunc(x,__LINE__) - -void ExitOnErrorFunc( SLresult result , int line) -{ - if (SL_RESULT_SUCCESS != result) { - fprintf(stderr, "%u error code encountered at line %d, exiting\n", result, line); - exit(EXIT_FAILURE); - } -} - -//----------------------------------------------------------------- -/* PlayItf callback for an audio player */ -void PlayEventCallback( SLPlayItf caller, void *pContext, SLuint32 event) -{ - fprintf(stdout, "PlayEventCallback event = "); - if (event & SL_PLAYEVENT_HEADATEND) { - fprintf(stdout, "SL_PLAYEVENT_HEADATEND \n"); - /* slow playback down by 2x for next loop, if possible */ - SLpermille minRate, maxRate, stepSize, rate = 1000; - SLuint32 capa; - assert(NULL != pContext); - SLPlaybackRateItf pRateItf = (SLPlaybackRateItf)pContext; - SLresult res = (*pRateItf)->GetRate(pRateItf, &rate); CheckErr(res); - res = (*pRateItf)->GetRateRange(pRateItf, 0, &minRate, &maxRate, &stepSize, &capa); - CheckErr(res); - fprintf(stdout, "old rate = %d, minRate=%d, maxRate=%d\n", rate, minRate, maxRate); - rate /= 2; - if (rate < minRate) { - rate = minRate; - } - fprintf(stdout, "new rate = %d\n", rate); - res = (*pRateItf)->SetRate(pRateItf, rate); CheckErr(res); - if (res == SL_RESULT_FEATURE_UNSUPPORTED) { - fprintf(stderr, "new playback rate %d per mille is unsupported\n", rate); - } else { - CheckErr(res); - } - } - if (event & SL_PLAYEVENT_HEADATMARKER) { - fprintf(stdout, "SL_PLAYEVENT_HEADATMARKER "); - } - if (event & SL_PLAYEVENT_HEADATNEWPOS) { - fprintf(stdout, "SL_PLAYEVENT_HEADATNEWPOS "); - } - if (event & SL_PLAYEVENT_HEADMOVING) { - fprintf(stdout, "SL_PLAYEVENT_HEADMOVING "); - } - if (event & SL_PLAYEVENT_HEADSTALLED) { - fprintf(stdout, "SL_PLAYEVENT_HEADSTALLED"); - } - fprintf(stdout, "\n"); -} - -//----------------------------------------------------------------- -/* PrefetchStatusItf callback for an audio player */ -void PrefetchEventCallback( SLPrefetchStatusItf caller, void *pContext, SLuint32 event) -{ - //fprintf(stdout, "\t\tPrefetchEventCallback: received event %u\n", event); - SLresult result; - assert(pContext == NULL); - SLpermille level = 0; - result = (*caller)->GetFillLevel(caller, &level); - CheckErr(result); - SLuint32 status; - result = (*caller)->GetPrefetchStatus(caller, &status); - CheckErr(result); - if (event & SL_PREFETCHEVENT_FILLLEVELCHANGE) { - fprintf(stdout, "\t\tPrefetchEventCallback: Buffer fill level is = %d\n", level); - } - if (event & SL_PREFETCHEVENT_STATUSCHANGE) { - fprintf(stdout, "\t\tPrefetchEventCallback: Prefetch Status is = %u\n", status); - } - SLuint32 new_prefetch_status; - if ((event & PREFETCHEVENT_ERROR_CANDIDATE) == PREFETCHEVENT_ERROR_CANDIDATE - && level == 0 && status == SL_PREFETCHSTATUS_UNDERFLOW) { - fprintf(stdout, "\t\tPrefetchEventCallback: Error while prefetching data, exiting\n"); - new_prefetch_status = SL_PREFETCHSTATUS_ERROR; - } else if (event == SL_PREFETCHEVENT_STATUSCHANGE && - status == SL_PREFETCHSTATUS_SUFFICIENTDATA) { - new_prefetch_status = status; - } else { - return; - } - int ok; - ok = pthread_mutex_lock(&mutex); - assert(ok == 0); - prefetch_status = new_prefetch_status; - ok = pthread_cond_signal(&cond); - assert(ok == 0); - ok = pthread_mutex_unlock(&mutex); - assert(ok == 0); -} - -// Display rate capabilities in a nicely formatted way - -void printCapabilities(SLuint32 capabilities) -{ - bool needBar = false; - printf("0x%x (", capabilities); -#define _(x) \ - if (capabilities & SL_RATEPROP_##x) { \ - if (needBar) \ - printf("|"); \ - printf("SL_RATEPROP_" #x); \ - needBar = true; \ - capabilities &= ~SL_RATEPROP_##x; \ - } - _(SILENTAUDIO) - _(STAGGEREDAUDIO) - _(NOPITCHCORAUDIO) - _(PITCHCORAUDIO) - if (capabilities != 0) { - if (needBar) - printf("|"); - printf("0x%x", capabilities); - needBar = true; - } - if (!needBar) - printf("N/A"); - printf(")"); -} - -//----------------------------------------------------------------- - -/* Play some music from a URI */ -void TestSlowDownUri( SLObjectItf sl, const char* path) -{ - SLEngineItf EngineItf; - - SLint32 numOutputs = 0; - SLuint32 deviceID = 0; - - SLresult res; - - SLDataSource audioSource; - SLDataLocator_URI uri; - SLDataFormat_MIME mime; - - SLDataSink audioSink; - SLDataLocator_OutputMix locator_outputmix; - - SLObjectItf player; - SLPlayItf playItf; - SLSeekItf seekItf; - SLPrefetchStatusItf prefetchItf; - SLPlaybackRateItf rateItf; - - SLObjectItf OutputMix; - - SLboolean required[MAX_NUMBER_INTERFACES]; - SLInterfaceID iidArray[MAX_NUMBER_INTERFACES]; - - /* Get the SL Engine Interface which is implicit */ - res = (*sl)->GetInterface(sl, SL_IID_ENGINE, (void*)&EngineItf); CheckErr(res); - - /* Initialize arrays required[] and iidArray[] */ - for (int i=0 ; i < MAX_NUMBER_INTERFACES ; i++) { - required[i] = SL_BOOLEAN_FALSE; - iidArray[i] = SL_IID_NULL; - } - - required[0] = SL_BOOLEAN_TRUE; - iidArray[0] = SL_IID_VOLUME; - // Create Output Mix object to be used by player - res = (*EngineItf)->CreateOutputMix(EngineItf, &OutputMix, 0, - iidArray, required); CheckErr(res); - - // Realizing the Output Mix object in synchronous mode. - res = (*OutputMix)->Realize(OutputMix, SL_BOOLEAN_FALSE); CheckErr(res); - - /* Setup the data source structure for the URI */ - uri.locatorType = SL_DATALOCATOR_URI; - uri.URI = (SLchar*) path; - mime.formatType = SL_DATAFORMAT_MIME; - mime.mimeType = (SLchar*)NULL; - mime.containerType = SL_CONTAINERTYPE_UNSPECIFIED; - - audioSource.pFormat = (void *)&mime; - audioSource.pLocator = (void *)&uri; - - /* Setup the data sink structure */ - locator_outputmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; - locator_outputmix.outputMix = OutputMix; - audioSink.pLocator = (void *)&locator_outputmix; - audioSink.pFormat = NULL; - - /******************************************************/ - /* Create the audio player */ - required[0] = SL_BOOLEAN_TRUE; - iidArray[0] = SL_IID_SEEK; - required[1] = SL_BOOLEAN_TRUE; - iidArray[1] = SL_IID_PREFETCHSTATUS; - required[2] = SL_BOOLEAN_TRUE; - iidArray[2] = SL_IID_PLAYBACKRATE; - res = (*EngineItf)->CreateAudioPlayer(EngineItf, &player, &audioSource, &audioSink, - MAX_NUMBER_INTERFACES, iidArray, required); CheckErr(res); - - /* Realizing the player in synchronous mode. */ - res = (*player)->Realize(player, SL_BOOLEAN_FALSE); CheckErr(res); - fprintf(stdout, "URI example: after Realize\n"); - - /* Get interfaces */ - res = (*player)->GetInterface(player, SL_IID_PLAY, (void*)&playItf); CheckErr(res); - - res = (*player)->GetInterface(player, SL_IID_SEEK, (void*)&seekItf); CheckErr(res); - - res = (*player)->GetInterface(player, SL_IID_PLAYBACKRATE, (void*)&rateItf); CheckErr(res); - - res = (*player)->GetInterface(player, SL_IID_PREFETCHSTATUS, (void*)&prefetchItf); - CheckErr(res); - res = (*prefetchItf)->RegisterCallback(prefetchItf, PrefetchEventCallback, NULL); - CheckErr(res); - res = (*prefetchItf)->SetCallbackEventsMask(prefetchItf, - SL_PREFETCHEVENT_FILLLEVELCHANGE | SL_PREFETCHEVENT_STATUSCHANGE); CheckErr(res); - - /* Configure fill level updates every 5 percent */ - (*prefetchItf)->SetFillUpdatePeriod(prefetchItf, 50); CheckErr(res); - - /* Display duration */ - SLmillisecond durationInMsec = SL_TIME_UNKNOWN; - res = (*playItf)->GetDuration(playItf, &durationInMsec); CheckErr(res); - if (durationInMsec == SL_TIME_UNKNOWN) { - fprintf(stdout, "Content duration is unknown (before starting to prefetch)\n"); - } else { - fprintf(stdout, "Content duration is %u ms (before starting to prefetch)\n", - durationInMsec); - } - - /* Loop on the whole of the content */ - res = (*seekItf)->SetLoop(seekItf, SL_BOOLEAN_TRUE, 0, SL_TIME_UNKNOWN); CheckErr(res); - - /* Set up marker and position callbacks */ - res = (*playItf)->RegisterCallback(playItf, PlayEventCallback, (void *) rateItf); CheckErr(res); - res = (*playItf)->SetCallbackEventsMask(playItf, - SL_PLAYEVENT_HEADATEND | SL_PLAYEVENT_HEADATMARKER | SL_PLAYEVENT_HEADATNEWPOS); - res = (*playItf)->SetMarkerPosition(playItf, 1500); CheckErr(res); - res = (*playItf)->SetPositionUpdatePeriod(playItf, 500); CheckErr(res); - - /* Get the default rate */ - SLpermille rate = 1234; - res = (*rateItf)->GetRate(rateItf, &rate); CheckErr(res); - printf("default rate = %d per mille\n", rate); - assert(1000 == rate); - - /* Get the default rate properties */ - SLuint32 properties = 0; - res = (*rateItf)->GetProperties(rateItf, &properties); CheckErr(res); - printf("default rate properties: "); - printCapabilities(properties); - printf("\n"); - assert(SL_RATEPROP_NOPITCHCORAUDIO == properties); - - /* Get all supported playback rate ranges */ - SLuint8 index; - for (index = 0; ; ++index) { - SLpermille minRate, maxRate, stepSize; - SLuint32 capabilities; - res = (*rateItf)->GetRateRange(rateItf, index, &minRate, &maxRate, &stepSize, &capabilities); - if (res == SL_RESULT_PARAMETER_INVALID) { - if (index == 0) { - fprintf(stderr, "implementation supports no rate ranges\n"); - } - break; - } - CheckErr(res); - if (index == 255) { - fprintf(stderr, "implementation supports way too many rate ranges, I'm giving up\n"); - break; - } - printf("range[%u]: min=%d, max=%d, capabilities=", index, minRate, maxRate); - printCapabilities(capabilities); - printf("\n"); - } - - /* Change the playback rate before playback */ - res = (*rateItf)->SetRate(rateItf, INITIAL_RATE); - if (res == SL_RESULT_FEATURE_UNSUPPORTED || res == SL_RESULT_PARAMETER_INVALID) { - fprintf(stderr, "initial playback rate %d per mille is unsupported\n", INITIAL_RATE); - } else { - CheckErr(res); - } - - /******************************************************/ - /* Play the URI */ - /* first cause the player to prefetch the data */ - res = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PAUSED ); CheckErr(res); - - // wait for prefetch status callback to indicate either sufficient data or error - pthread_mutex_lock(&mutex); - while (prefetch_status == SL_PREFETCHSTATUS_UNKNOWN) { - pthread_cond_wait(&cond, &mutex); - } - pthread_mutex_unlock(&mutex); - if (prefetch_status == SL_PREFETCHSTATUS_ERROR) { - fprintf(stderr, "Error during prefetch, exiting\n"); - goto destroyRes; - } - - /* Display duration again, */ - res = (*playItf)->GetDuration(playItf, &durationInMsec); CheckErr(res); - if (durationInMsec == SL_TIME_UNKNOWN) { - fprintf(stdout, "Content duration is unknown (after prefetch completed)\n"); - } else { - fprintf(stdout, "Content duration is %u ms (after prefetch completed)\n", durationInMsec); - } - - /* Start playing */ - fprintf(stdout, "starting to play\n"); - res = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PLAYING ); CheckErr(res); - - /* Wait as long as the duration of the content, times the repetitions, - * before stopping the loop */ -#if 1 - usleep( (REPETITIONS-1) * durationInMsec * 1100); -#else - int ii; - for (ii = 0; ii < REPETITIONS; ++ii) { - usleep(durationInMsec * 1100); - PlayEventCallback(playItf, (void *) rateItf, SL_PLAYEVENT_HEADATEND); - } -#endif - - res = (*seekItf)->SetLoop(seekItf, SL_BOOLEAN_FALSE, 0, SL_TIME_UNKNOWN); CheckErr(res); - fprintf(stdout, "As of now, stopped looping (sound shouldn't repeat from now on)\n"); - /* wait some more to make sure it doesn't repeat */ - usleep(durationInMsec * 1000); - - /* Stop playback */ - fprintf(stdout, "stopping playback\n"); - res = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED); CheckErr(res); - -destroyRes: - - /* Destroy the player */ - (*player)->Destroy(player); - - /* Destroy Output Mix object */ - (*OutputMix)->Destroy(OutputMix); -} - -//----------------------------------------------------------------- -int main(int argc, char* const argv[]) -{ - SLresult res; - SLObjectItf sl; - - fprintf(stdout, "OpenSL ES test %s: exercises SLPlayItf, SLSeekItf, SLPlaybackRateItf\n", - argv[0]); - fprintf(stdout, "and AudioPlayer with SLDataLocator_URI source / OutputMix sink\n"); - fprintf(stdout, "Plays a sound and loops it %d times while changing the \n", REPETITIONS); - fprintf(stdout, "playback rate each time.\n\n"); - - if (argc == 1) { - fprintf(stdout, "Usage: \n\t%s path \n\t%s url\n", argv[0], argv[0]); - fprintf(stdout, "Example: \"%s /sdcard/my.mp3\" or \"%s file:///sdcard/my.mp3\"\n", - argv[0], argv[0]); - return EXIT_FAILURE; - } - - SLEngineOption EngineOption[] = { - {(SLuint32) SL_ENGINEOPTION_THREADSAFE, - (SLuint32) SL_BOOLEAN_TRUE}}; - - res = slCreateEngine( &sl, 1, EngineOption, 0, NULL, NULL); - CheckErr(res); - /* Realizing the SL Engine in synchronous mode. */ - res = (*sl)->Realize(sl, SL_BOOLEAN_FALSE); - CheckErr(res); - - TestSlowDownUri(sl, argv[1]); - - /* Shutdown OpenSL ES */ - (*sl)->Destroy(sl); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/mimeUri/slesTest_playStates.cpp b/wilhelm/tests/mimeUri/slesTest_playStates.cpp deleted file mode 100644 index 040be9f6..00000000 --- a/wilhelm/tests/mimeUri/slesTest_playStates.cpp +++ /dev/null @@ -1,241 +0,0 @@ -/* - * 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. - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <sys/time.h> - -#include <SLES/OpenSLES.h> - - -#define MAX_NUMBER_INTERFACES 2 - -#define TEST_MUTE 0 -#define TEST_SOLO 1 - -static int testMode; -//----------------------------------------------------------------- -/* Exits the application if an error is encountered */ -#define ExitOnError(x) ExitOnErrorFunc(x,__LINE__) - -void ExitOnErrorFunc( SLresult result , int line) -{ - if (SL_RESULT_SUCCESS != result) { - fprintf(stdout, "%u error code encountered at line %d, exiting\n", result, line); - exit(EXIT_FAILURE); - } -} - - -//----------------------------------------------------------------- - -/* Play an audio URIs, play, pause, stop */ -void TestPlayUri( SLObjectItf sl, const char* path) -{ - SLresult result; - SLEngineItf EngineItf; - - /* Objects this application uses: one player and an ouput mix */ - SLObjectItf player, outputMix; - - /* Source of audio data to play */ - SLDataSource audioSource; - SLDataLocator_URI uri; - SLDataFormat_MIME mime; - - /* Data sinks for the audio player */ - SLDataSink audioSink; - SLDataLocator_OutputMix locator_outputmix; - - /* Play, Volume and PrefetchStatus interfaces for the audio player */ - SLPlayItf playItf; - SLMuteSoloItf muteSoloItf; - SLPrefetchStatusItf prefetchItf; - - SLboolean required[MAX_NUMBER_INTERFACES]; - SLInterfaceID iidArray[MAX_NUMBER_INTERFACES]; - - /* Get the SL Engine Interface which is implicit */ - result = (*sl)->GetInterface(sl, SL_IID_ENGINE, (void*)&EngineItf); - ExitOnError(result); - - /* Initialize arrays required[] and iidArray[] */ - for (int i=0 ; i < MAX_NUMBER_INTERFACES ; i++) { - required[i] = SL_BOOLEAN_FALSE; - iidArray[i] = SL_IID_NULL; - } - - /* ------------------------------------------------------ */ - /* Configuration of the output mix */ - - /* Create Output Mix object to be used by the player */ - result = (*EngineItf)->CreateOutputMix(EngineItf, &outputMix, 0, iidArray, required); - ExitOnError(result); - - /* Realize the Output Mix object in synchronous mode */ - result = (*outputMix)->Realize(outputMix, SL_BOOLEAN_FALSE); - ExitOnError(result); - - /* Setup the data sink structure */ - locator_outputmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; - locator_outputmix.outputMix = outputMix; - audioSink.pLocator = (void*)&locator_outputmix; - audioSink.pFormat = NULL; - - /* ------------------------------------------------------ */ - /* Configuration of the player */ - - /* Set arrays required[] and iidArray[] for SLMuteSoloItf and SLPrefetchStatusItf interfaces */ - /* (SLPlayItf is implicit) */ - required[0] = SL_BOOLEAN_TRUE; - iidArray[0] = SL_IID_MUTESOLO; - required[1] = SL_BOOLEAN_TRUE; - iidArray[1] = SL_IID_PREFETCHSTATUS; - - /* Setup the data source structure for the URI */ - uri.locatorType = SL_DATALOCATOR_URI; - uri.URI = (SLchar*) path; - mime.formatType = SL_DATAFORMAT_MIME; - /* this is how ignored mime information is specified, according to OpenSL ES spec - * in 9.1.6 SLDataFormat_MIME and 8.23 SLMetadataTraversalItf GetChildInfo */ - mime.mimeType = (SLchar*)NULL; - mime.containerType = SL_CONTAINERTYPE_UNSPECIFIED; - - audioSource.pFormat = (void*)&mime; - audioSource.pLocator = (void*)&uri; - - /* Create the audio player */ - result = (*EngineItf)->CreateAudioPlayer(EngineItf, &player, &audioSource, &audioSink, - MAX_NUMBER_INTERFACES, iidArray, required); - ExitOnError(result); - - /* Realize the player in synchronous mode. */ - result = (*player)->Realize(player, SL_BOOLEAN_FALSE); ExitOnError(result); - fprintf(stdout, "URI example: after Realize\n"); - - /* Get the SLPlayItf, SLPrefetchStatusItf and SLMuteSoloItf interfaces for the player */ - result = (*player)->GetInterface(player, SL_IID_PLAY, (void*)&playItf); - ExitOnError(result); - - result = (*player)->GetInterface(player, SL_IID_PREFETCHSTATUS, (void*)&prefetchItf); - ExitOnError(result); - - result = (*player)->GetInterface(player, SL_IID_MUTESOLO, (void*)&muteSoloItf); - ExitOnError(result); - - - fprintf(stdout, "Player configured\n"); - - /* ------------------------------------------------------ */ - /* Playback and test */ - - /* Start the data prefetching by setting the player to the paused state */ - result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PAUSED ); - ExitOnError(result); - - /* Wait until there's data to play */ - SLuint32 prefetchStatus = SL_PREFETCHSTATUS_UNDERFLOW; - while (prefetchStatus != SL_PREFETCHSTATUS_SUFFICIENTDATA) { - usleep(100 * 1000); - (*prefetchItf)->GetPrefetchStatus(prefetchItf, &prefetchStatus); - } - - - /* Testing play states */ - /* let it play for 2s */ - fprintf(stdout, "----- Playing\n"); - result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PLAYING ); - ExitOnError(result); - usleep(2 * 1000 * 1000); - - /* pause for 1s*/ - fprintf(stdout, "----- Pausing (1s)\n"); - result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PAUSED ); - ExitOnError(result); - usleep(2 * 1000 * 1000); - - /* resume */ - fprintf(stdout, "----- Playing (2s, should have resumed where it paused)\n"); - result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PLAYING ); - ExitOnError(result); - usleep(2 * 1000 * 1000); - - /* stop */ - fprintf(stdout, "----- Stopping\n"); - result = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED); - ExitOnError(result); - - /* play for 2s */ - fprintf(stdout, "----- Playing (2s, should have started from the beginning\n"); - result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PLAYING ); - ExitOnError(result); - usleep(2 * 1000 * 1000); - - /* stop */ - fprintf(stdout, "----- Stopping\n"); - result = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED); - ExitOnError(result); - -destroyKillKill: - - /* Destroy the players */ - (*player)->Destroy(player); - - /* Destroy Output Mix object */ - (*outputMix)->Destroy(outputMix); -} - -//----------------------------------------------------------------- -int main(int argc, char* const argv[]) -{ - SLresult result; - SLObjectItf sl; - - fprintf(stdout, "OpenSL ES test %s: exercises SLPlayItf, SLVolumeItf, SLMuteSoloItf\n", - argv[0]); - fprintf(stdout, "and AudioPlayer with SLDataLocator_URI source / OutputMix sink\n"); - fprintf(stdout, "Plays a sound and alternates the muting of the channels (for 5s).\n"); - fprintf(stdout, " and then alternates the solo\'ing of the channels (for 5s).\n"); - fprintf(stdout, "Stops after 10s\n"); - - if (argc == 1) { - fprintf(stdout, "Usage: \t%s url\n", argv[0]); - fprintf(stdout, "Example: \"%s /sdcard/my.mp3\"\n", argv[0]); - exit(EXIT_FAILURE); - } - - SLEngineOption EngineOption[] = { - {(SLuint32) SL_ENGINEOPTION_THREADSAFE, (SLuint32) SL_BOOLEAN_TRUE} - }; - - result = slCreateEngine( &sl, 1, EngineOption, 0, NULL, NULL); - ExitOnError(result); - - /* Realizing the SL Engine in synchronous mode. */ - result = (*sl)->Realize(sl, SL_BOOLEAN_FALSE); - ExitOnError(result); - - if (argc > 1) { - TestPlayUri(sl, argv[1]); - } - - /* Shutdown OpenSL ES */ - (*sl)->Destroy(sl); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/mimeUri_test.cpp b/wilhelm/tests/mimeUri_test.cpp deleted file mode 100644 index ded5d5c9..00000000 --- a/wilhelm/tests/mimeUri_test.cpp +++ /dev/null @@ -1,317 +0,0 @@ -/* - * 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. - */ - -/* - * Copyright (c) 2009 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this - * software and /or associated documentation files (the "Materials "), to deal in the - * Materials without restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies of the Materials, - * and to permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS IN THE - * MATERIALS. - */ - -#define LOG_NDEBUG 0 -#define LOG_TAG "slesTestPlayUri" - -#include <utils/Log.h> -#include <getopt.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <sys/time.h> -#include <gtest/gtest.h> -#include <SLES/OpenSLES.h> - - -#define MAX_NUMBER_INTERFACES 3 -#define MAX_NUMBER_OUTPUT_DEVICES 6 - -//The expected playback duration -const int MP3_DURATION = 71030; //71 secs - - -//----------------------------------------------------------------- -/* Checks for error. If any errors exit the application! */ -void CheckErr( SLresult res ) -{ - if ( res != SL_RESULT_SUCCESS ) { - fprintf(stderr, "%u SL failure, exiting\n", res); - //Fail the test case - ASSERT_TRUE(false); - } -} - -//----------------------------------------------------------------- -/* PrefetchStatusItf callback for an audio player */ -void PrefetchEventCallback( SLPrefetchStatusItf caller, void *pContext, SLuint32 event) -{ - SLpermille level = 0; - (*caller)->GetFillLevel(caller, &level); - SLuint32 status; - fprintf(stdout, "\t\tPrefetchEventCallback: received event %u\n", event); - (*caller)->GetPrefetchStatus(caller, &status); - if ((event & (SL_PREFETCHEVENT_STATUSCHANGE|SL_PREFETCHEVENT_FILLLEVELCHANGE)) - && (level == 0) && (status == SL_PREFETCHSTATUS_UNDERFLOW)) { - fprintf(stderr, "\t\tPrefetchEventCallback: Error while prefetching data, exiting\n"); - ASSERT_TRUE(false); - } - if (event & SL_PREFETCHEVENT_FILLLEVELCHANGE) { - fprintf(stdout, "\t\tPrefetchEventCallback: Buffer fill level is = %d\n", level); - } - if (event & SL_PREFETCHEVENT_STATUSCHANGE) { - fprintf(stdout, "\t\tPrefetchEventCallback: Prefetch Status is = %u\n", status); - } - -} - - -//----------------------------------------------------------------- - -/* Play some music from a URI */ -void TestPlayUri( SLObjectItf sl, const char* path) -{ - SLEngineItf EngineItf; - - SLint32 numOutputs = 0; - SLuint32 deviceID = 0; - - SLresult res; - - SLDataSource audioSource; - SLDataLocator_URI uri; - SLDataFormat_MIME mime; - - SLDataSink audioSink; - SLDataLocator_OutputMix locator_outputmix; - - SLObjectItf player; - SLPlayItf playItf; - SLVolumeItf volItf; - SLPrefetchStatusItf prefetchItf; - - SLObjectItf OutputMix; - - SLboolean required[MAX_NUMBER_INTERFACES]; - SLInterfaceID iidArray[MAX_NUMBER_INTERFACES]; - - /* Get the SL Engine Interface which is implicit */ - res = (*sl)->GetInterface(sl, SL_IID_ENGINE, (void*)&EngineItf); - CheckErr(res); - - /* Initialize arrays required[] and iidArray[] */ - for (int i=0 ; i < MAX_NUMBER_INTERFACES ; i++) { - required[i] = SL_BOOLEAN_FALSE; - iidArray[i] = SL_IID_NULL; - } - - // Set arrays required[] and iidArray[] for VOLUME and PREFETCHSTATUS interface - required[0] = SL_BOOLEAN_TRUE; - iidArray[0] = SL_IID_VOLUME; - required[1] = SL_BOOLEAN_TRUE; - iidArray[1] = SL_IID_PREFETCHSTATUS; - // Create Output Mix object to be used by player - res = (*EngineItf)->CreateOutputMix(EngineItf, &OutputMix, 0, - iidArray, required); CheckErr(res); - - // Realizing the Output Mix object in synchronous mode. - res = (*OutputMix)->Realize(OutputMix, SL_BOOLEAN_FALSE); - CheckErr(res); - - /* Setup the data source structure for the URI */ - uri.locatorType = SL_DATALOCATOR_URI; - uri.URI = (SLchar*) path; - mime.formatType = SL_DATAFORMAT_MIME; - mime.mimeType = (SLchar*)NULL; - mime.containerType = SL_CONTAINERTYPE_UNSPECIFIED; - - audioSource.pFormat = (void *)&mime; - audioSource.pLocator = (void *)&uri; - - /* Setup the data sink structure */ - locator_outputmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; - locator_outputmix.outputMix = OutputMix; - audioSink.pLocator = (void *)&locator_outputmix; - audioSink.pFormat = NULL; - - /* Create the audio player */ - res = (*EngineItf)->CreateAudioPlayer(EngineItf, &player, - &audioSource, &audioSink, 2, iidArray, required); CheckErr(res); - - /* Realizing the player in synchronous mode. */ - res = (*player)->Realize(player, SL_BOOLEAN_FALSE); CheckErr(res); - - /* Get interfaces */ - res = (*player)->GetInterface(player, SL_IID_PLAY, (void*)&playItf); - CheckErr(res); - - res = (*player)->GetInterface(player, SL_IID_VOLUME, (void*)&volItf); - CheckErr(res); - - res = (*player)->GetInterface(player, SL_IID_PREFETCHSTATUS, (void*)&prefetchItf); - CheckErr(res); - res = (*prefetchItf)->RegisterCallback(prefetchItf, PrefetchEventCallback, &prefetchItf); - CheckErr(res); - res = (*prefetchItf)->SetCallbackEventsMask(prefetchItf, - SL_PREFETCHEVENT_FILLLEVELCHANGE | SL_PREFETCHEVENT_STATUSCHANGE); - - /* Display duration */ - SLmillisecond durationInMsec = SL_TIME_UNKNOWN; - res = (*playItf)->GetDuration(playItf, &durationInMsec); - CheckErr(res); - - /* Set the player volume */ - res = (*volItf)->SetVolumeLevel( volItf, -300); - CheckErr(res); - - /* Play the URI */ - /* first cause the player to prefetch the data */ - res = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PAUSED ); - CheckErr(res); - - /* wait until there's data to play */ - //SLpermille fillLevel = 0; - SLuint32 prefetchStatus = SL_PREFETCHSTATUS_UNDERFLOW; - SLuint32 timeOutIndex = 100; // 10s - while ((prefetchStatus != SL_PREFETCHSTATUS_SUFFICIENTDATA) && (timeOutIndex > 0)) { - usleep(100 * 1000); - (*prefetchItf)->GetPrefetchStatus(prefetchItf, &prefetchStatus); - timeOutIndex--; - } - - if (timeOutIndex == 0) { - fprintf(stderr, "Error: Failed to prefetch data in time, exiting\n"); - ASSERT_TRUE(false); - // goto destroyRes; - } - - /* Display duration again, */ - res = (*playItf)->GetDuration(playItf, &durationInMsec); - CheckErr(res); - if (durationInMsec == SL_TIME_UNKNOWN) { - fprintf(stderr, "Error: GetDuration returned SL_TIME_UNKNOWN (after prefetch completed)\n"); - ASSERT_TRUE(false); - } - SLint32 durationDiffMsec = durationInMsec - MP3_DURATION; - if (durationDiffMsec < 0) { durationDiffMsec *= -1; } - if (durationDiffMsec > (MP3_DURATION/20)) { - fprintf(stderr, "Error: GetDuration returned %d, more than 5percent off from expected %d\n", - durationInMsec, MP3_DURATION); - ASSERT_TRUE(false); - } - - res = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PLAYING ); - CheckErr(res); - - /* Play for the song duration*/ - usleep(MP3_DURATION * 1000); - - /* Validate the play position*/ - SLmillisecond currentPositionInMsec = SL_TIME_UNKNOWN; - res = (*playItf)->GetPosition(playItf, ¤tPositionInMsec); - CheckErr(res); - if (currentPositionInMsec == SL_TIME_UNKNOWN) { - fprintf(stderr, "Error: GetPosition returns SL_TIME_UNKNOWN after expected duration\n"); - ASSERT_TRUE(false); - } else if ( currentPositionInMsec <= 0 || - currentPositionInMsec > (MP3_DURATION * 1.1) ){ - fprintf(stderr, "Error: GetPosition returns %i, should be expected duration for test\n", - (int) currentPositionInMsec); - ASSERT_TRUE(false); - } - - /* Make sure player is stopped */ - res = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED); - CheckErr(res); - -destroyRes: - - /* Destroy the player */ - (*player)->Destroy(player); - - /* Destroy Output Mix object */ - (*OutputMix)->Destroy(OutputMix); - - fprintf(stdout, "End of test reached\n"); -} - - -// The fixture for testing class MimeUri -class MimeUri: public ::testing::Test { -public: - SLresult res; - SLObjectItf sl; - -protected: - MimeUri() { - // You can do set-up work for each test here. - SLEngineOption EngineOption[] = { { (SLuint32) SL_ENGINEOPTION_THREADSAFE, - (SLuint32) SL_BOOLEAN_TRUE } }; - - res = slCreateEngine(&sl, 1, EngineOption, 0, NULL, NULL); - CheckErr(res); - - /* Realizing the SL Engine in synchronous mode. */ - res = (*sl)->Realize(sl, SL_BOOLEAN_FALSE); - CheckErr(res); - } - - virtual ~MimeUri() { - // You can do clean-up work that doesn't throw exceptions here. - (*sl)->Destroy(sl); - } - - virtual void SetUp() { - // Code here will be called immediately after the constructor (right - // before each test). - - } - - virtual void TearDown() { - // Code here will be called immediately after each test (right - // before the destructor). - - } -}; - -TEST_F(MimeUri, testPlayAbsPath){ - TestPlayUri(sl, "/sdcard/media_api/music/MP3_256kbps_2ch.mp3"); -} - -TEST_F(MimeUri, testPlayfilePath){ - TestPlayUri(sl, "file:///sdcard/media_api/music/MP3_256kbps_2ch.mp3"); -} - -//----------------------------------------------------------------- -int main(int argc, char **argv) -{ - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/wilhelm/tests/native-media/Android.mk b/wilhelm/tests/native-media/Android.mk deleted file mode 100644 index 73d7ec8b..00000000 --- a/wilhelm/tests/native-media/Android.mk +++ /dev/null @@ -1,18 +0,0 @@ -LOCAL_PATH:= $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_SRC_FILES := \ - src/com/example/nativemedia/NativeMedia.java \ - src/com/example/nativemedia/MyGLSurfaceView.java - -LOCAL_PACKAGE_NAME := native-media -LOCAL_CERTIFICATE := platform - -LOCAL_JNI_SHARED_LIBRARIES := libnative-media-jni - -include $(BUILD_PACKAGE) - -include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/wilhelm/tests/native-media/AndroidManifest.xml b/wilhelm/tests/native-media/AndroidManifest.xml deleted file mode 100644 index ab94d1d7..00000000 --- a/wilhelm/tests/native-media/AndroidManifest.xml +++ /dev/null @@ -1,20 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.example.nativemedia"> - - <uses-feature android:glEsVersion="0x00020000" /> - - <application android:icon="@drawable/icon" android:label="@string/app_name"> - <activity android:name=".NativeMedia" - android:label="@string/app_name"> - <intent-filter> - <action android:name="android.intent.action.MAIN" /> - <category android:name="android.intent.category.LAUNCHER" /> - </intent-filter> - </activity> - - </application> - - -<uses-permission android:name="android.permission.INTERNET"></uses-permission> -</manifest> diff --git a/wilhelm/tests/native-media/jni/Android.mk b/wilhelm/tests/native-media/jni/Android.mk deleted file mode 100644 index ad5e806a..00000000 --- a/wilhelm/tests/native-media/jni/Android.mk +++ /dev/null @@ -1,15 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests -LOCAL_MODULE := libnative-media-jni -LOCAL_SRC_FILES := native-media-jni.c -LOCAL_CFLAGS += -I$(call include-path-for, wilhelm) -LOCAL_CFLAGS += -UNDEBUG - -LOCAL_PRELINK_MODULE := false -LOCAL_SHARED_LIBRARIES += libutils libOpenMAXAL libandroid - - -include $(BUILD_SHARED_LIBRARY) diff --git a/wilhelm/tests/native-media/jni/native-media-jni.c b/wilhelm/tests/native-media/jni/native-media-jni.c deleted file mode 100644 index 6d7ec286..00000000 --- a/wilhelm/tests/native-media/jni/native-media-jni.c +++ /dev/null @@ -1,543 +0,0 @@ -/* - * 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. - */ - -#include <assert.h> -#include <jni.h> -#include <pthread.h> -#include <string.h> -//#define LOG_NDEBUG 0 -#define LOG_TAG "NativeMedia" -#include <utils/Log.h> - -#include <OMXAL/OpenMAXAL.h> -#include <OMXAL/OpenMAXAL_Android.h> - -#include <android/native_window_jni.h> - -// engine interfaces -static XAObjectItf engineObject = NULL; -static XAEngineItf engineEngine = NULL; - -// output mix interfaces -static XAObjectItf outputMixObject = NULL; - -// streaming media player interfaces -static XAObjectItf playerObj = NULL; -static XAPlayItf playerPlayItf = NULL; -static XAAndroidBufferQueueItf playerBQItf = NULL; -static XAStreamInformationItf playerStreamInfoItf = NULL; -static XAVolumeItf playerVolItf = NULL; - -// number of required interfaces for the MediaPlayer creation -#define NB_MAXAL_INTERFACES 3 // XAAndroidBufferQueueItf, XAStreamInformationItf and XAPlayItf - -// video sink for the player -static ANativeWindow* theNativeWindow; - -// number of buffers in our buffer queue, an arbitrary number -#define NB_BUFFERS 16 - -// we're streaming MPEG-2 transport stream data, operate on transport stream block size -#define MPEG2_TS_BLOCK_SIZE 188 - -// number of MPEG-2 transport stream blocks per buffer, an arbitrary number -#define BLOCKS_PER_BUFFER 20 - -// determines how much memory we're dedicating to memory caching -#define BUFFER_SIZE (BLOCKS_PER_BUFFER*MPEG2_TS_BLOCK_SIZE) - -// where we cache in memory the data to play -// note this memory is re-used by the buffer queue callback -char dataCache[BUFFER_SIZE * NB_BUFFERS]; - -// handle of the file to play -FILE *file; - -// has the app reached the end of the file -jboolean reachedEof = JNI_FALSE; - -// constant to identify a buffer context which is the end of the stream to decode -static const int kEosBufferCntxt = 1980; // a magic value we can compare against - -// for mutual exclusion between callback thread and application thread(s) -pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t cond = PTHREAD_COND_INITIALIZER; - -// whether a discontinuity is in progress -jboolean discontinuity = JNI_FALSE; - -static jboolean enqueueInitialBuffers(jboolean discontinuity); - -// Callback for XAPlayItf through which we receive the XA_PLAYEVENT_HEADATEND event */ -void PlayCallback(XAPlayItf caller, void *pContext, XAuint32 event) { - if (event & XA_PLAYEVENT_HEADATEND) { - ALOGV("XA_PLAYEVENT_HEADATEND received, all MP2TS data has been decoded\n"); - } -} - -// AndroidBufferQueueItf callback for an audio player -XAresult AndroidBufferQueueCallback( - XAAndroidBufferQueueItf caller, - void *pCallbackContext, /* input */ - void *pBufferContext, /* input */ - void *pBufferData, /* input */ - XAuint32 dataSize, /* input */ - XAuint32 dataUsed, /* input */ - const XAAndroidBufferItem *pItems,/* input */ - XAuint32 itemsLength /* input */) -{ - XAresult res; - int ok; - - // pCallbackContext was specified as NULL at RegisterCallback and is unused here - assert(NULL == pCallbackContext); - - // note there is never any contention on this mutex unless a discontinuity request is active - ok = pthread_mutex_lock(&mutex); - assert(0 == ok); - - // was a discontinuity requested? - if (discontinuity) { - // FIXME sorry, can't rewind after EOS - if (!reachedEof) { - // clear the buffer queue - res = (*playerBQItf)->Clear(playerBQItf); - assert(XA_RESULT_SUCCESS == res); - // rewind the data source so we are guaranteed to be at an appropriate point - rewind(file); - // Enqueue the initial buffers, with a discontinuity indicator on first buffer - (void) enqueueInitialBuffers(JNI_TRUE); - } - // acknowledge the discontinuity request - discontinuity = JNI_FALSE; - ok = pthread_cond_signal(&cond); - assert(0 == ok); - goto exit; - } - - if ((pBufferData == NULL) && (pBufferContext != NULL)) { - const int processedCommand = *(int *)pBufferContext; - if (kEosBufferCntxt == processedCommand) { - ALOGV("EOS was processed\n"); - // our buffer with the EOS message has been consumed - assert(0 == dataSize); - goto exit; - } - } - - // pBufferData is a pointer to a buffer that we previously Enqueued - assert(BUFFER_SIZE == dataSize); - assert(dataCache <= (char *) pBufferData && (char *) pBufferData < - &dataCache[BUFFER_SIZE * NB_BUFFERS]); - assert(0 == (((char *) pBufferData - dataCache) % BUFFER_SIZE)); - -#if 0 - // sample code to use the XAVolumeItf - XAAndroidBufferQueueState state; - (*caller)->GetState(caller, &state); - switch (state.index) { - case 300: - (*playerVolItf)->SetVolumeLevel(playerVolItf, -600); // -6dB - ALOGV("setting volume to -6dB"); - break; - case 400: - (*playerVolItf)->SetVolumeLevel(playerVolItf, -1200); // -12dB - ALOGV("setting volume to -12dB"); - break; - case 500: - (*playerVolItf)->SetVolumeLevel(playerVolItf, 0); // full volume - ALOGV("setting volume to 0dB (full volume)"); - break; - case 600: - (*playerVolItf)->SetMute(playerVolItf, XA_BOOLEAN_TRUE); // mute - ALOGV("muting player"); - break; - case 700: - (*playerVolItf)->SetMute(playerVolItf, XA_BOOLEAN_FALSE); // unmute - ALOGV("unmuting player"); - break; - case 800: - (*playerVolItf)->SetStereoPosition(playerVolItf, -1000); - (*playerVolItf)->EnableStereoPosition(playerVolItf, XA_BOOLEAN_TRUE); - ALOGV("pan sound to the left (hard-left)"); - break; - case 900: - (*playerVolItf)->EnableStereoPosition(playerVolItf, XA_BOOLEAN_FALSE); - ALOGV("disabling stereo position"); - break; - default: - break; - } -#endif - - // don't bother trying to read more data once we've hit EOF - if (reachedEof) { - goto exit; - } - - size_t nbRead; - // note we do call fread from multiple threads, but never concurrently - nbRead = fread(pBufferData, BUFFER_SIZE, 1, file); - if (nbRead > 0) { - assert(1 == nbRead); - res = (*caller)->Enqueue(caller, NULL /*pBufferContext*/, - pBufferData /*pData*/, - nbRead * BUFFER_SIZE /*dataLength*/, - NULL /*pMsg*/, - 0 /*msgLength*/); - assert(XA_RESULT_SUCCESS == res); - } else { - // signal EOS - XAAndroidBufferItem msgEos[1]; - msgEos[0].itemKey = XA_ANDROID_ITEMKEY_EOS; - msgEos[0].itemSize = 0; - // EOS message has no parameters, so the total size of the message is the size of the key - // plus the size if itemSize, both XAuint32 - res = (*caller)->Enqueue(caller, (void *)&kEosBufferCntxt /*pBufferContext*/, - NULL /*pData*/, 0 /*dataLength*/, - msgEos /*pMsg*/, - // FIXME == sizeof(BufferItem)? */ - sizeof(XAuint32)*2 /*msgLength*/); - assert(XA_RESULT_SUCCESS == res); - reachedEof = JNI_TRUE; - } - -exit: - ok = pthread_mutex_unlock(&mutex); - assert(0 == ok); - return XA_RESULT_SUCCESS; -} - - -void StreamChangeCallback (XAStreamInformationItf caller, - XAuint32 eventId, - XAuint32 streamIndex, - void * pEventData, - void * pContext ) -{ - ALOGV("StreamChangeCallback called for stream %u", streamIndex); - // pContext was specified as NULL at RegisterStreamChangeCallback and is unused here - assert(NULL == pContext); - switch (eventId) { - case XA_STREAMCBEVENT_PROPERTYCHANGE: { - /** From spec 1.0.1: - "This event indicates that stream property change has occurred. - The streamIndex parameter identifies the stream with the property change. - The pEventData parameter for this event is not used and shall be ignored." - */ - - XAresult res; - XAuint32 domain; - res = (*caller)->QueryStreamType(caller, streamIndex, &domain); - assert(XA_RESULT_SUCCESS == res); - switch (domain) { - case XA_DOMAINTYPE_VIDEO: { - XAVideoStreamInformation videoInfo; - res = (*caller)->QueryStreamInformation(caller, streamIndex, &videoInfo); - assert(XA_RESULT_SUCCESS == res); - ALOGI("Found video size %u x %u, codec ID=%u, frameRate=%u, bitRate=%u, duration=%u ms", - videoInfo.width, videoInfo.height, videoInfo.codecId, videoInfo.frameRate, - videoInfo.bitRate, videoInfo.duration); - } break; - default: - fprintf(stderr, "Unexpected domain %u\n", domain); - break; - } - } break; - default: - fprintf(stderr, "Unexpected stream event ID %u\n", eventId); - break; - } -} - - -// create the engine and output mix objects -void Java_com_example_nativemedia_NativeMedia_createEngine(JNIEnv* env, jclass clazz) -{ - XAresult res; - - // create engine - res = xaCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL); - assert(XA_RESULT_SUCCESS == res); - - // realize the engine - res = (*engineObject)->Realize(engineObject, XA_BOOLEAN_FALSE); - assert(XA_RESULT_SUCCESS == res); - - // get the engine interface, which is needed in order to create other objects - res = (*engineObject)->GetInterface(engineObject, XA_IID_ENGINE, &engineEngine); - assert(XA_RESULT_SUCCESS == res); - - // create output mix - res = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 0, NULL, NULL); - assert(XA_RESULT_SUCCESS == res); - - // realize the output mix - res = (*outputMixObject)->Realize(outputMixObject, XA_BOOLEAN_FALSE); - assert(XA_RESULT_SUCCESS == res); - -} - - -// Enqueue the initial buffers, and optionally signal a discontinuity in the first buffer -static jboolean enqueueInitialBuffers(jboolean discontinuity) -{ - - /* Fill our cache */ - size_t nbRead; - nbRead = fread(dataCache, BUFFER_SIZE, NB_BUFFERS, file); - if (nbRead <= 0) { - // could be premature EOF or I/O error - ALOGE("Error filling cache, exiting\n"); - return JNI_FALSE; - } - assert(1 <= nbRead && nbRead <= NB_BUFFERS); - ALOGV("Initially queueing %u buffers of %u bytes each", nbRead, BUFFER_SIZE); - - /* Enqueue the content of our cache before starting to play, - we don't want to starve the player */ - size_t i; - for (i = 0; i < nbRead; i++) { - XAresult res; - if (discontinuity) { - // signal discontinuity - XAAndroidBufferItem items[1]; - items[0].itemKey = XA_ANDROID_ITEMKEY_DISCONTINUITY; - items[0].itemSize = 0; - // DISCONTINUITY message has no parameters, - // so the total size of the message is the size of the key - // plus the size if itemSize, both XAuint32 - res = (*playerBQItf)->Enqueue(playerBQItf, NULL /*pBufferContext*/, - dataCache + i*BUFFER_SIZE, BUFFER_SIZE, items /*pMsg*/, - // FIXME == sizeof(BufferItem)? */ - sizeof(XAuint32)*2 /*msgLength*/); - discontinuity = JNI_FALSE; - } else { - res = (*playerBQItf)->Enqueue(playerBQItf, NULL /*pBufferContext*/, - dataCache + i*BUFFER_SIZE, BUFFER_SIZE, NULL, 0); - } - assert(XA_RESULT_SUCCESS == res); - } - - return JNI_TRUE; -} - - -// create streaming media player -jboolean Java_com_example_nativemedia_NativeMedia_createStreamingMediaPlayer(JNIEnv* env, - jclass clazz, jstring filename) -{ - XAresult res; - - // convert Java string to UTF-8 - const char *utf8 = (*env)->GetStringUTFChars(env, filename, NULL); - assert(NULL != utf8); - - // open the file to play - file = fopen(utf8, "rb"); - if (file == NULL) { - ALOGE("Failed to open %s", utf8); - return JNI_FALSE; - } - - // configure data source - XADataLocator_AndroidBufferQueue loc_abq = { XA_DATALOCATOR_ANDROIDBUFFERQUEUE, NB_BUFFERS }; - XADataFormat_MIME format_mime = { - XA_DATAFORMAT_MIME, XA_ANDROID_MIME_MP2TS, XA_CONTAINERTYPE_MPEG_TS }; - XADataSource dataSrc = {&loc_abq, &format_mime}; - - // configure audio sink - XADataLocator_OutputMix loc_outmix = { XA_DATALOCATOR_OUTPUTMIX, outputMixObject }; - XADataSink audioSnk = { &loc_outmix, NULL }; - - // configure image video sink - XADataLocator_NativeDisplay loc_nd = { - XA_DATALOCATOR_NATIVEDISPLAY, // locatorType - // the video sink must be an ANativeWindow created from a Surface or SurfaceTexture - (void*)theNativeWindow, // hWindow - // must be NULL - NULL // hDisplay - }; - XADataSink imageVideoSink = {&loc_nd, NULL}; - - // declare interfaces to use - XAboolean required[NB_MAXAL_INTERFACES] - = {XA_BOOLEAN_TRUE, XA_BOOLEAN_TRUE, XA_BOOLEAN_TRUE}; - XAInterfaceID iidArray[NB_MAXAL_INTERFACES] - = {XA_IID_PLAY, XA_IID_ANDROIDBUFFERQUEUESOURCE, - XA_IID_STREAMINFORMATION}; - - - // create media player - res = (*engineEngine)->CreateMediaPlayer(engineEngine, &playerObj, &dataSrc, - NULL, &audioSnk, &imageVideoSink, NULL, NULL, - NB_MAXAL_INTERFACES /*XAuint32 numInterfaces*/, - iidArray /*const XAInterfaceID *pInterfaceIds*/, - required /*const XAboolean *pInterfaceRequired*/); - assert(XA_RESULT_SUCCESS == res); - - // release the Java string and UTF-8 - (*env)->ReleaseStringUTFChars(env, filename, utf8); - - // realize the player - res = (*playerObj)->Realize(playerObj, XA_BOOLEAN_FALSE); - assert(XA_RESULT_SUCCESS == res); - - // get the play interface - res = (*playerObj)->GetInterface(playerObj, XA_IID_PLAY, &playerPlayItf); - assert(XA_RESULT_SUCCESS == res); - - // get the stream information interface (for video size) - res = (*playerObj)->GetInterface(playerObj, XA_IID_STREAMINFORMATION, &playerStreamInfoItf); - assert(XA_RESULT_SUCCESS == res); - - // get the volume interface - res = (*playerObj)->GetInterface(playerObj, XA_IID_VOLUME, &playerVolItf); - assert(XA_RESULT_SUCCESS == res); - - // get the Android buffer queue interface - res = (*playerObj)->GetInterface(playerObj, XA_IID_ANDROIDBUFFERQUEUESOURCE, &playerBQItf); - assert(XA_RESULT_SUCCESS == res); - - // specify which events we want to be notified of - res = (*playerBQItf)->SetCallbackEventsMask(playerBQItf, XA_ANDROIDBUFFERQUEUEEVENT_PROCESSED); - - // use the play interface to set up a callback for the XA_PLAYEVENT_HEADATEND event */ - res = (*playerPlayItf)->SetCallbackEventsMask(playerPlayItf, XA_PLAYEVENT_HEADATEND); - assert(XA_RESULT_SUCCESS == res); - res = (*playerPlayItf)->RegisterCallback(playerPlayItf, - PlayCallback /*callback*/, NULL /*pContext*/); - assert(XA_RESULT_SUCCESS == res); - - // register the callback from which OpenMAX AL can retrieve the data to play - res = (*playerBQItf)->RegisterCallback(playerBQItf, AndroidBufferQueueCallback, NULL); - assert(XA_RESULT_SUCCESS == res); - - // we want to be notified of the video size once it's found, so we register a callback for that - res = (*playerStreamInfoItf)->RegisterStreamChangeCallback(playerStreamInfoItf, - StreamChangeCallback, NULL); - - // enqueue the initial buffers - if (!enqueueInitialBuffers(JNI_FALSE)) { - return JNI_FALSE; - } - - // prepare the player - res = (*playerPlayItf)->SetPlayState(playerPlayItf, XA_PLAYSTATE_PAUSED); - assert(XA_RESULT_SUCCESS == res); - - // set the volume - res = (*playerVolItf)->SetVolumeLevel(playerVolItf, 0);//-300); - assert(XA_RESULT_SUCCESS == res); - - // start the playback - res = (*playerPlayItf)->SetPlayState(playerPlayItf, XA_PLAYSTATE_PLAYING); - assert(XA_RESULT_SUCCESS == res); - - return JNI_TRUE; -} - - -// set the playing state for the streaming media player -void Java_com_example_nativemedia_NativeMedia_setPlayingStreamingMediaPlayer(JNIEnv* env, - jclass clazz, jboolean isPlaying) -{ - XAresult res; - - // make sure the streaming media player was created - if (NULL != playerPlayItf) { - - // set the player's state - res = (*playerPlayItf)->SetPlayState(playerPlayItf, isPlaying ? - XA_PLAYSTATE_PLAYING : XA_PLAYSTATE_PAUSED); - assert(XA_RESULT_SUCCESS == res); - - } - -} - - -// shut down the native media system -void Java_com_example_nativemedia_NativeMedia_shutdown(JNIEnv* env, jclass clazz) -{ - // destroy streaming media player object, and invalidate all associated interfaces - if (playerObj != NULL) { - (*playerObj)->Destroy(playerObj); - playerObj = NULL; - playerPlayItf = NULL; - playerBQItf = NULL; - playerStreamInfoItf = NULL; - playerVolItf = NULL; - } - - // destroy output mix object, and invalidate all associated interfaces - if (outputMixObject != NULL) { - (*outputMixObject)->Destroy(outputMixObject); - outputMixObject = NULL; - } - - // destroy engine object, and invalidate all associated interfaces - if (engineObject != NULL) { - (*engineObject)->Destroy(engineObject); - engineObject = NULL; - engineEngine = NULL; - } - - // close the file - if (file != NULL) { - fclose(file); - file = NULL; - } - - // make sure we don't leak native windows - if (theNativeWindow != NULL) { - ANativeWindow_release(theNativeWindow); - theNativeWindow = NULL; - } -} - - -// set the surface -void Java_com_example_nativemedia_NativeMedia_setSurface(JNIEnv *env, jclass clazz, jobject surface) -{ - // obtain a native window from a Java surface - theNativeWindow = ANativeWindow_fromSurface(env, surface); -} - - -// rewind the streaming media player -void Java_com_example_nativemedia_NativeMedia_rewindStreamingMediaPlayer(JNIEnv *env, jclass clazz) -{ - XAresult res; - - // make sure the streaming media player was created - if (NULL != playerBQItf && NULL != file) { - // first wait for buffers currently in queue to be drained - int ok; - ok = pthread_mutex_lock(&mutex); - assert(0 == ok); - discontinuity = JNI_TRUE; - // wait for discontinuity request to be observed by buffer queue callback - // FIXME sorry, can't rewind after EOS - while (discontinuity && !reachedEof) { - ok = pthread_cond_wait(&cond, &mutex); - assert(0 == ok); - } - ok = pthread_mutex_unlock(&mutex); - assert(0 == ok); - } - -} diff --git a/wilhelm/tests/native-media/res/drawable/icon.png b/wilhelm/tests/native-media/res/drawable/icon.png Binary files differdeleted file mode 100644 index a07c69fa..00000000 --- a/wilhelm/tests/native-media/res/drawable/icon.png +++ /dev/null diff --git a/wilhelm/tests/native-media/res/layout/main.xml b/wilhelm/tests/native-media/res/layout/main.xml deleted file mode 100644 index d303b196..00000000 --- a/wilhelm/tests/native-media/res/layout/main.xml +++ /dev/null @@ -1,127 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:orientation="vertical" - android:layout_width="fill_parent" - android:layout_height="fill_parent" - > -<TextView - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:text="@string/hello" - /> -<TextView - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:text="@string/source_select" - /> -<Spinner - android:id="@+id/source_spinner" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:text="@string/source_prompt" - /> -<TextView - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:text="@string/sink_select" - /> -<Spinner - android:id="@+id/sink_spinner" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:text="@string/sink_prompt" - /> - -<LinearLayout - android:orientation="horizontal" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - > - <Button - android:id="@+id/start_java" - android:text="@string/start_java" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - /> - <Button - android:id="@+id/start_native" - android:text="@string/start_native" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - /> -</LinearLayout> - -<LinearLayout - android:orientation="horizontal" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - > - <Button - android:id="@+id/rewind_java" - android:text="@string/rewind_java" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - /> - <Button - android:id="@+id/rewind_native" - android:text="@string/rewind_native" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - /> -</LinearLayout> - -<LinearLayout - android:orientation="horizontal" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - > - <TextView - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:text="S1" - /> - <SurfaceView - android:id="@+id/surfaceview1" - android:layout_width="320px" - android:layout_height="240px" - /> - <TextView - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:text="S2" - /> - <SurfaceView - android:id="@+id/surfaceview2" - android:layout_width="400px" - android:layout_height="224px" - /> -</LinearLayout> - -<LinearLayout - android:orientation="horizontal" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - > - <TextView - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:text="ST1" - /> - <com.example.nativemedia.MyGLSurfaceView - android:id="@+id/glsurfaceview1" - android:layout_width="320px" - android:layout_height="240px" - /> - <TextView - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:text="ST2" - /> - <com.example.nativemedia.MyGLSurfaceView - android:id="@+id/glsurfaceview2" - android:layout_width="320px" - android:layout_height="240px" - /> -</LinearLayout> - -</LinearLayout> diff --git a/wilhelm/tests/native-media/res/values/strings.xml b/wilhelm/tests/native-media/res/values/strings.xml deleted file mode 100644 index 2b5207e3..00000000 --- a/wilhelm/tests/native-media/res/values/strings.xml +++ /dev/null @@ -1,32 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<resources> - <string name="hello">Hello, Android, using native media!</string> - <string name="app_name">NativeMedia</string> - - <string name="start_java">Start/Pause Java MediaPlayer</string> - <string name="start_native">Start/Pause native MediaPlayer</string> - - <string name="rewind_java">Rewind Java MediaPlayer</string> - <string name="rewind_native">Rewind native MediaPlayer</string> - - <string name="source_select">Please select the media source</string> - <string name="source_prompt">Media source</string> - <string-array name="source_array"> - <item>/sdcard/Videos/bar.ts</item> - <item>http://iphoned5.akamai.com.edgesuite.net/mhbarron/nasatv/nasatv_1500.m3u8</item> - <item>http://iphone.video.hsn.com/iPhone_high.m3u8</item> - <item>http://mlbsegqa.mlb.com/mlbam/dev/build84/2010/10/29/test1/master_wired.m3u8</item> - <item>/sdcard/Videos/mpeg4_qvga_24fps.3gp</item> - <item>/sdcard/Videos/burnAfterReading.m4v</item> - </string-array> - - <string name="sink_select">Please select the video sink</string> - <string name="sink_prompt">Video sink</string> - <string-array name="sink_array"> - <item>Surface 1</item> - <item>Surface 2</item> - <item>SurfaceTexture 1</item> - <item>SurfaceTexture 2</item> - </string-array> - -</resources> diff --git a/wilhelm/tests/native-media/src/com/example/nativemedia/MyGLSurfaceView.java b/wilhelm/tests/native-media/src/com/example/nativemedia/MyGLSurfaceView.java deleted file mode 100644 index 688bea75..00000000 --- a/wilhelm/tests/native-media/src/com/example/nativemedia/MyGLSurfaceView.java +++ /dev/null @@ -1,348 +0,0 @@ -/* - * 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. - */ - -package com.example.nativemedia; - -import android.graphics.SurfaceTexture; -import android.util.Log; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.FloatBuffer; - -import javax.microedition.khronos.egl.EGLConfig; -import javax.microedition.khronos.opengles.GL10; - -import android.view.MotionEvent; -import android.content.Context; - -import android.opengl.GLES20; -import android.opengl.GLSurfaceView; -import android.opengl.Matrix; - -import android.hardware.SensorManager; -import android.hardware.SensorEvent; -import android.hardware.SensorEventListener; -import android.hardware.Sensor; - -// Remove once surfacetexture timestamps are in -import java.lang.System; - -import android.util.AttributeSet; - -public class MyGLSurfaceView extends GLSurfaceView { - - MyRenderer mRenderer; - - public MyGLSurfaceView(Context context) { - super(context, null); - } - - public MyGLSurfaceView(Context context, AttributeSet attributeSet) { - super(context, attributeSet); - init(context); - } - - private void init(Context context) { - setEGLContextClientVersion(2); - mRenderer = new MyRenderer(context); - setRenderer(mRenderer); - } - - @Override - public void onPause() { - super.onPause(); - } - - @Override - public void onResume() { - super.onResume(); - } - - public SurfaceTexture getSurfaceTexture() { - return mRenderer.getSurfaceTexture(); - } -} - -class MyRenderer implements GLSurfaceView.Renderer, SurfaceTexture.OnFrameAvailableListener { - private Context mContext; - - public MyRenderer(Context context) { - mContext = context; - - mVertices = ByteBuffer.allocateDirect(mVerticesData.length - * FLOAT_SIZE_BYTES).order(ByteOrder.nativeOrder()).asFloatBuffer(); - mVertices.put(mVerticesData).position(0); - - Matrix.setIdentityM(mSTMatrix, 0); - Matrix.setIdentityM(mMMatrix, 0); - Matrix.rotateM(mMMatrix, 0, 20, 0, 1, 0); - } - - public void onDrawFrame(GL10 glUnused) { - synchronized(this) { - if (updateSurface) { - mSurface.updateTexImage(); - - mSurface.getTransformMatrix(mSTMatrix); - updateSurface = false; - } - } - - // Ignore the passed-in GL10 interface, and use the GLES20 - // class's static methods instead. - GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); - GLES20.glUseProgram(mProgram); - checkGlError("glUseProgram"); - - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTextureID); - - mVertices.position(VERTICES_DATA_POS_OFFSET); - GLES20.glVertexAttribPointer(maPositionHandle, 3, GLES20.GL_FLOAT, false, - VERTICES_DATA_STRIDE_BYTES, mVertices); - checkGlError("glVertexAttribPointer maPosition"); - GLES20.glEnableVertexAttribArray(maPositionHandle); - checkGlError("glEnableVertexAttribArray maPositionHandle"); - - mVertices.position(VERTICES_DATA_UV_OFFSET); - GLES20.glVertexAttribPointer(maTextureHandle, 3, GLES20.GL_FLOAT, false, - VERTICES_DATA_STRIDE_BYTES, mVertices); - checkGlError("glVertexAttribPointer maTextureHandle"); - GLES20.glEnableVertexAttribArray(maTextureHandle); - checkGlError("glEnableVertexAttribArray maTextureHandle"); - - Matrix.multiplyMM(mMVPMatrix, 0, mVMatrix, 0, mMMatrix, 0); - Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mMVPMatrix, 0); - - GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0); - GLES20.glUniformMatrix4fv(muSTMatrixHandle, 1, false, mSTMatrix, 0); - - GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); - checkGlError("glDrawArrays"); - } - - public void onSurfaceChanged(GL10 glUnused, int width, int height) { - // Ignore the passed-in GL10 interface, and use the GLES20 - // class's static methods instead. - GLES20.glViewport(0, 0, width, height); - mRatio = (float) width / height; - Matrix.frustumM(mProjMatrix, 0, -mRatio, mRatio, -1, 1, 3, 7); - } - - public void onSurfaceCreated(GL10 glUnused, EGLConfig config) { - // Ignore the passed-in GL10 interface, and use the GLES20 - // class's static methods instead. - - /* Set up alpha blending and an Android background color */ - GLES20.glEnable(GLES20.GL_BLEND); - GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); - GLES20.glClearColor(0.643f, 0.776f, 0.223f, 1.0f); - - /* Set up shaders and handles to their variables */ - mProgram = createProgram(mVertexShader, mFragmentShader); - if (mProgram == 0) { - return; - } - maPositionHandle = GLES20.glGetAttribLocation(mProgram, "aPosition"); - checkGlError("glGetAttribLocation aPosition"); - if (maPositionHandle == -1) { - throw new RuntimeException("Could not get attrib location for aPosition"); - } - maTextureHandle = GLES20.glGetAttribLocation(mProgram, "aTextureCoord"); - checkGlError("glGetAttribLocation aTextureCoord"); - if (maTextureHandle == -1) { - throw new RuntimeException("Could not get attrib location for aTextureCoord"); - } - - muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix"); - checkGlError("glGetUniformLocation uMVPMatrix"); - if (muMVPMatrixHandle == -1) { - throw new RuntimeException("Could not get attrib location for uMVPMatrix"); - } - - muSTMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uSTMatrix"); - checkGlError("glGetUniformLocation uSTMatrix"); - if (muMVPMatrixHandle == -1) { - throw new RuntimeException("Could not get attrib location for uSTMatrix"); - } - - checkGlError("glGetUniformLocation uCRatio"); - if (muMVPMatrixHandle == -1) { - throw new RuntimeException("Could not get attrib location for uCRatio"); - } - - /* - * Create our texture. This has to be done each time the - * surface is created. - */ - - int[] textures = new int[1]; - GLES20.glGenTextures(1, textures, 0); - - mTextureID = textures[0]; - GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTextureID); - checkGlError("glBindTexture mTextureID"); - - // Can't do mipmapping with camera source - GLES20.glTexParameterf(GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, - GLES20.GL_NEAREST); - GLES20.glTexParameterf(GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, - GLES20.GL_LINEAR); - // Clamp to edge is the only option - GLES20.glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S, - GLES20.GL_CLAMP_TO_EDGE); - GLES20.glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T, - GLES20.GL_CLAMP_TO_EDGE); - checkGlError("glTexParameteri mTextureID"); - - /* - * Create the SurfaceTexture that will feed this textureID, and pass it to the camera - */ - - mSurface = new SurfaceTexture(mTextureID); - mSurface.setOnFrameAvailableListener(this); - - Matrix.setLookAtM(mVMatrix, 0, 0, 0, 4f, 0f, 0f, 0f, 0f, 1.0f, 0.0f); - - synchronized(this) { - updateSurface = false; - } - } - - synchronized public void onFrameAvailable(SurfaceTexture surface) { - /* For simplicity, SurfaceTexture calls here when it has new - * data available. Call may come in from some random thread, - * so let's be safe and use synchronize. No OpenGL calls can be done here. - */ - updateSurface = true; - //Log.v(TAG, "onFrameAvailable " + surface.getTimestamp()); - } - - private int loadShader(int shaderType, String source) { - int shader = GLES20.glCreateShader(shaderType); - if (shader != 0) { - GLES20.glShaderSource(shader, source); - GLES20.glCompileShader(shader); - int[] compiled = new int[1]; - GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0); - if (compiled[0] == 0) { - Log.e(TAG, "Could not compile shader " + shaderType + ":"); - Log.e(TAG, GLES20.glGetShaderInfoLog(shader)); - GLES20.glDeleteShader(shader); - shader = 0; - } - } - return shader; - } - - private int createProgram(String vertexSource, String fragmentSource) { - int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource); - if (vertexShader == 0) { - return 0; - } - int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource); - if (pixelShader == 0) { - return 0; - } - - int program = GLES20.glCreateProgram(); - if (program != 0) { - GLES20.glAttachShader(program, vertexShader); - checkGlError("glAttachShader"); - GLES20.glAttachShader(program, pixelShader); - checkGlError("glAttachShader"); - GLES20.glLinkProgram(program); - int[] linkStatus = new int[1]; - GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0); - if (linkStatus[0] != GLES20.GL_TRUE) { - Log.e(TAG, "Could not link program: "); - Log.e(TAG, GLES20.glGetProgramInfoLog(program)); - GLES20.glDeleteProgram(program); - program = 0; - } - } - return program; - } - - private void checkGlError(String op) { - int error; - while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) { - Log.e(TAG, op + ": glError " + error); - throw new RuntimeException(op + ": glError " + error); - } - } - - private static final int FLOAT_SIZE_BYTES = 4; - private static final int VERTICES_DATA_STRIDE_BYTES = 5 * FLOAT_SIZE_BYTES; - private static final int VERTICES_DATA_POS_OFFSET = 0; - private static final int VERTICES_DATA_UV_OFFSET = 3; - private final float[] mVerticesData = { - // X, Y, Z, U, V - -1.0f, -1.0f, 0, 0.f, 0.f, - 1.0f, -1.0f, 0, 1.f, 0.f, - -1.0f, 1.0f, 0, 0.f, 1.f, - 1.0f, 1.0f, 0, 1.f, 1.f, - }; - - private FloatBuffer mVertices; - - private final String mVertexShader = - "uniform mat4 uMVPMatrix;\n" + - "uniform mat4 uSTMatrix;\n" + - "attribute vec4 aPosition;\n" + - "attribute vec4 aTextureCoord;\n" + - "varying vec2 vTextureCoord;\n" + - "void main() {\n" + - " gl_Position = uMVPMatrix * aPosition;\n" + - " vTextureCoord = (uSTMatrix * aTextureCoord).xy;\n" + - "}\n"; - - private final String mFragmentShader = - "#extension GL_OES_EGL_image_external : require\n" + - "precision mediump float;\n" + - "varying vec2 vTextureCoord;\n" + - "uniform samplerExternalOES sTexture;\n" + - "void main() {\n" + - " gl_FragColor = texture2D(sTexture, vTextureCoord);\n" + - "}\n"; - - private float[] mMVPMatrix = new float[16]; - private float[] mProjMatrix = new float[16]; - private float[] mMMatrix = new float[16]; - private float[] mVMatrix = new float[16]; - private float[] mSTMatrix = new float[16]; - - private int mProgram; - private int mTextureID; - private int muMVPMatrixHandle; - private int muSTMatrixHandle; - private int maPositionHandle; - private int maTextureHandle; - - private float mRatio = 1.0f; - private SurfaceTexture mSurface; - private boolean updateSurface = false; - - private static final String TAG = "MyRenderer"; - - // Magic key - private static final int GL_TEXTURE_EXTERNAL_OES = 0x8D65; - - public SurfaceTexture getSurfaceTexture() { - return mSurface; - } -} diff --git a/wilhelm/tests/native-media/src/com/example/nativemedia/NativeMedia.java b/wilhelm/tests/native-media/src/com/example/nativemedia/NativeMedia.java deleted file mode 100644 index 816d01f3..00000000 --- a/wilhelm/tests/native-media/src/com/example/nativemedia/NativeMedia.java +++ /dev/null @@ -1,399 +0,0 @@ -/* - * 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. - */ - -package com.example.nativemedia; - -import android.app.Activity; -import android.graphics.SurfaceTexture; -import android.media.MediaPlayer; -import android.os.Bundle; -import android.util.Log; -import android.view.Surface; -import android.view.SurfaceHolder; -import android.view.SurfaceView; -import android.view.View; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.Button; -import android.widget.Spinner; -import java.io.IOException; - -import android.content.Context; - -import android.graphics.SurfaceTexture; - -import android.media.MediaPlayer.OnPreparedListener; -import android.media.MediaPlayer; - -public class NativeMedia extends Activity { - static final String TAG = "NativeMedia"; - - String mSourceString = null; - String mSinkString = null; - - // member variables for Java media player - MediaPlayer mMediaPlayer; - boolean mMediaPlayerIsPrepared = false; - SurfaceView mSurfaceView1; - SurfaceHolder mSurfaceHolder1; - - // member variables for native media player - boolean mIsPlayingStreaming = false; - SurfaceView mSurfaceView2; - SurfaceHolder mSurfaceHolder2; - - VideoSink mSelectedVideoSink; - VideoSink mJavaMediaPlayerVideoSink; - VideoSink mNativeMediaPlayerVideoSink; - - SurfaceHolderVideoSink mSurfaceHolder1VideoSink, mSurfaceHolder2VideoSink; - GLViewVideoSink mGLView1VideoSink, mGLView2VideoSink; - - /** Called when the activity is first created. */ - @Override - public void onCreate(Bundle icicle) { - super.onCreate(icicle); - setContentView(R.layout.main); - - mGLView1 = (MyGLSurfaceView) findViewById(R.id.glsurfaceview1); - mGLView2 = (MyGLSurfaceView) findViewById(R.id.glsurfaceview2); - - //setContentView(mGLView); - //setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); - - // initialize native media system - createEngine(); - - // set up the Surface 1 video sink - mSurfaceView1 = (SurfaceView) findViewById(R.id.surfaceview1); - mSurfaceHolder1 = mSurfaceView1.getHolder(); - - mSurfaceHolder1.addCallback(new SurfaceHolder.Callback() { - - public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { - Log.v(TAG, "surfaceChanged format=" + format + ", width=" + width + ", height=" + - height); - } - - public void surfaceCreated(SurfaceHolder holder) { - Log.v(TAG, "surfaceCreated"); - setSurface(holder.getSurface()); - } - - public void surfaceDestroyed(SurfaceHolder holder) { - Log.v(TAG, "surfaceDestroyed"); - } - - }); - - // set up the Surface 2 video sink - mSurfaceView2 = (SurfaceView) findViewById(R.id.surfaceview2); - mSurfaceHolder2 = mSurfaceView2.getHolder(); - - mSurfaceHolder2.addCallback(new SurfaceHolder.Callback() { - - public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { - Log.v(TAG, "surfaceChanged format=" + format + ", width=" + width + ", height=" + - height); - } - - public void surfaceCreated(SurfaceHolder holder) { - Log.v(TAG, "surfaceCreated"); - setSurface(holder.getSurface()); - } - - public void surfaceDestroyed(SurfaceHolder holder) { - Log.v(TAG, "surfaceDestroyed"); - } - - }); - - // create Java media player - mMediaPlayer = new MediaPlayer(); - - // set up Java media player listeners - mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { - - public void onPrepared(MediaPlayer mediaPlayer) { - int width = mediaPlayer.getVideoWidth(); - int height = mediaPlayer.getVideoHeight(); - Log.v(TAG, "onPrepared width=" + width + ", height=" + height); - if (width != 0 && height != 0 && mJavaMediaPlayerVideoSink != null) { - mJavaMediaPlayerVideoSink.setFixedSize(width, height); - } - mMediaPlayerIsPrepared = true; - mediaPlayer.start(); - } - - }); - - mMediaPlayer.setOnVideoSizeChangedListener(new MediaPlayer.OnVideoSizeChangedListener() { - - public void onVideoSizeChanged(MediaPlayer mediaPlayer, int width, int height) { - Log.v(TAG, "onVideoSizeChanged width=" + width + ", height=" + height); - if (width != 0 && height != 0 && mJavaMediaPlayerVideoSink != null) { - mJavaMediaPlayerVideoSink.setFixedSize(width, height); - } - } - - }); - - // initialize content source spinner - Spinner sourceSpinner = (Spinner) findViewById(R.id.source_spinner); - ArrayAdapter<CharSequence> sourceAdapter = ArrayAdapter.createFromResource( - this, R.array.source_array, android.R.layout.simple_spinner_item); - sourceAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - sourceSpinner.setAdapter(sourceAdapter); - sourceSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - - public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { - mSourceString = parent.getItemAtPosition(pos).toString(); - Log.v(TAG, "onItemSelected " + mSourceString); - } - - public void onNothingSelected(AdapterView parent) { - Log.v(TAG, "onNothingSelected"); - mSourceString = null; - } - - }); - - // initialize video sink spinner - Spinner sinkSpinner = (Spinner) findViewById(R.id.sink_spinner); - ArrayAdapter<CharSequence> sinkAdapter = ArrayAdapter.createFromResource( - this, R.array.sink_array, android.R.layout.simple_spinner_item); - sinkAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - sinkSpinner.setAdapter(sinkAdapter); - sinkSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - - public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { - mSinkString = parent.getItemAtPosition(pos).toString(); - Log.v(TAG, "onItemSelected " + mSinkString); - if ("Surface 1".equals(mSinkString)) { - if (mSurfaceHolder1VideoSink == null) { - mSurfaceHolder1VideoSink = new SurfaceHolderVideoSink(mSurfaceHolder1); - } - mSelectedVideoSink = mSurfaceHolder1VideoSink; - } else if ("Surface 2".equals(mSinkString)) { - if (mSurfaceHolder2VideoSink == null) { - mSurfaceHolder2VideoSink = new SurfaceHolderVideoSink(mSurfaceHolder2); - } - mSelectedVideoSink = mSurfaceHolder2VideoSink; - } else if ("SurfaceTexture 1".equals(mSinkString)) { - if (mGLView1VideoSink == null) { - mGLView1VideoSink = new GLViewVideoSink(mGLView1); - } - mSelectedVideoSink = mGLView1VideoSink; - } else if ("SurfaceTexture 2".equals(mSinkString)) { - if (mGLView2VideoSink == null) { - mGLView2VideoSink = new GLViewVideoSink(mGLView2); - } - mSelectedVideoSink = mGLView2VideoSink; - } - } - - public void onNothingSelected(AdapterView parent) { - Log.v(TAG, "onNothingSelected"); - mSinkString = null; - mSelectedVideoSink = null; - } - - }); - - // initialize button click handlers - - // Java MediaPlayer start/pause - - ((Button) findViewById(R.id.start_java)).setOnClickListener(new View.OnClickListener() { - - public void onClick(View view) { - if (mJavaMediaPlayerVideoSink == null) { - if (mSelectedVideoSink == null) { - return; - } - mSelectedVideoSink.useAsSinkForJava(mMediaPlayer); - mJavaMediaPlayerVideoSink = mSelectedVideoSink; - } - if (!mMediaPlayerIsPrepared) { - if (mSourceString != null) { - try { - mMediaPlayer.setDataSource(mSourceString); - } catch (IOException e) { - Log.e(TAG, "IOException " + e); - } - mMediaPlayer.prepareAsync(); - } - } else if (mMediaPlayer.isPlaying()) { - mMediaPlayer.pause(); - } else { - mMediaPlayer.start(); - } - } - - }); - - // native MediaPlayer start/pause - - ((Button) findViewById(R.id.start_native)).setOnClickListener(new View.OnClickListener() { - - boolean created = false; - public void onClick(View view) { - if (!created) { - if (mNativeMediaPlayerVideoSink == null) { - if (mSelectedVideoSink == null) { - return; - } - mSelectedVideoSink.useAsSinkForNative(); - mNativeMediaPlayerVideoSink = mSelectedVideoSink; - } - if (mSourceString != null) { - created = createStreamingMediaPlayer(mSourceString); - } - } - if (created) { - mIsPlayingStreaming = !mIsPlayingStreaming; - setPlayingStreamingMediaPlayer(mIsPlayingStreaming); - } - } - - }); - - // Java MediaPlayer rewind - - ((Button) findViewById(R.id.rewind_java)).setOnClickListener(new View.OnClickListener() { - - public void onClick(View view) { - if (mMediaPlayerIsPrepared) { - mMediaPlayer.seekTo(0); - } - } - - }); - - // native MediaPlayer rewind - - ((Button) findViewById(R.id.rewind_native)).setOnClickListener(new View.OnClickListener() { - - public void onClick(View view) { - if (mNativeMediaPlayerVideoSink != null) { - rewindStreamingMediaPlayer(); - } - } - - }); - - } - - /** Called when the activity is about to be paused. */ - @Override - protected void onPause() - { - mIsPlayingStreaming = false; - setPlayingStreamingMediaPlayer(false); - mGLView1.onPause(); - mGLView2.onPause(); - super.onPause(); - } - - @Override - protected void onResume() { - super.onResume(); - mGLView1.onResume(); - mGLView2.onResume(); - } - - /** Called when the activity is about to be destroyed. */ - @Override - protected void onDestroy() - { - shutdown(); - super.onDestroy(); - } - - private MyGLSurfaceView mGLView1, mGLView2; - - /** Native methods, implemented in jni folder */ - public static native void createEngine(); - public static native boolean createStreamingMediaPlayer(String filename); - public static native void setPlayingStreamingMediaPlayer(boolean isPlaying); - public static native void shutdown(); - public static native void setSurface(Surface surface); - public static native void rewindStreamingMediaPlayer(); - - /** Load jni .so on initialization */ - static { - System.loadLibrary("native-media-jni"); - } - - // VideoSink abstracts out the difference between Surface and SurfaceTexture - // aka SurfaceHolder and GLSurfaceView - static abstract class VideoSink { - - abstract void setFixedSize(int width, int height); - abstract void useAsSinkForJava(MediaPlayer mediaPlayer); - abstract void useAsSinkForNative(); - - } - - static class SurfaceHolderVideoSink extends VideoSink { - - private final SurfaceHolder mSurfaceHolder; - - SurfaceHolderVideoSink(SurfaceHolder surfaceHolder) { - mSurfaceHolder = surfaceHolder; - } - - void setFixedSize(int width, int height) { - mSurfaceHolder.setFixedSize(width, height); - } - - void useAsSinkForJava(MediaPlayer mediaPlayer) { - mediaPlayer.setDisplay(mSurfaceHolder); - } - - void useAsSinkForNative() { - setSurface(mSurfaceHolder.getSurface()); - } - - } - - static class GLViewVideoSink extends VideoSink { - - private final MyGLSurfaceView mMyGLSurfaceView; - - GLViewVideoSink(MyGLSurfaceView myGLSurfaceView) { - mMyGLSurfaceView = myGLSurfaceView; - } - - void setFixedSize(int width, int height) { - } - - void useAsSinkForJava(MediaPlayer mediaPlayer) { - SurfaceTexture st = mMyGLSurfaceView.getSurfaceTexture(); - Surface s = new Surface(st); - mediaPlayer.setSurface(s); - s.release(); - } - - void useAsSinkForNative() { - Surface surface = new Surface(mMyGLSurfaceView.getSurfaceTexture()); - setSurface(surface); - surface.release(); - } - - } - -} diff --git a/wilhelm/tests/sandbox/Android.mk b/wilhelm/tests/sandbox/Android.mk deleted file mode 100644 index 4f39385d..00000000 --- a/wilhelm/tests/sandbox/Android.mk +++ /dev/null @@ -1,467 +0,0 @@ -LOCAL_PATH:= $(call my-dir) - -# intbufq - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - intbufq.c \ - getch.c - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX - #LOCAL_SHARED_LIBRARIES += librt -endif - -LOCAL_CFLAGS += -UNDEBUG - -LOCAL_MODULE:= slesTest_intbufq - -include $(BUILD_EXECUTABLE) - -# multiplay - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - multiplay.c - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_CFLAGS += -UNDEBUG - -LOCAL_MODULE:= slesTest_multiplay - -include $(BUILD_EXECUTABLE) - -# engine - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) \ - $(call include-path-for, wilhelm-ut) - -LOCAL_SRC_FILES:= \ - engine.c - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -LOCAL_STATIC_LIBRARIES := \ - libOpenSLESUT - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_CFLAGS += -UNDEBUG - -LOCAL_MODULE:= slesTest_engine - -include $(BUILD_EXECUTABLE) - -# object - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) \ - $(call include-path-for, wilhelm-ut) - -LOCAL_SRC_FILES:= \ - object.c - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -LOCAL_STATIC_LIBRARIES := \ - libOpenSLESUT - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_CFLAGS += -UNDEBUG - -LOCAL_MODULE:= slesTest_object - -include $(BUILD_EXECUTABLE) - -# configbq - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - configbq.c - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_CFLAGS += -UNDEBUG - -LOCAL_MODULE:= slesTest_configbq - -include $(BUILD_EXECUTABLE) - -# reverb - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - reverb.c - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -LOCAL_STATIC_LIBRARIES := \ - libOpenSLESUT - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_CFLAGS += -UNDEBUG - -LOCAL_MODULE:= slesTest_reverb - -include $(BUILD_EXECUTABLE) - -# srcsink - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - srcsink.c - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -LOCAL_STATIC_LIBRARIES := \ - libOpenSLESUT - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_CFLAGS += -UNDEBUG - -LOCAL_MODULE:= slesTest_srcsink - -include $(BUILD_EXECUTABLE) - -# outputmix - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) \ - $(call include-path-for, wilhelm-ut) - -LOCAL_SRC_FILES:= \ - outputmix.c - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -LOCAL_STATIC_LIBRARIES := \ - libOpenSLESUT - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_CFLAGS += -UNDEBUG - -LOCAL_MODULE:= slesTest_outputmix - -include $(BUILD_EXECUTABLE) - -# urimime - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - urimime.c - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -LOCAL_STATIC_LIBRARIES := \ - libOpenSLESUT - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_CFLAGS += -UNDEBUG - -LOCAL_MODULE:= slesTest_urimime - -include $(BUILD_EXECUTABLE) - -# dim - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - dim.c - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -LOCAL_STATIC_LIBRARIES := \ - libOpenSLESUT - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_CFLAGS += -UNDEBUG - -LOCAL_MODULE:= slesTest_dim - -include $(BUILD_EXECUTABLE) - -# multithread - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - multithread.c - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -LOCAL_STATIC_LIBRARIES := \ - libOpenSLESUT - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_CFLAGS += -UNDEBUG - -LOCAL_MODULE:= slesTest_multithread - -include $(BUILD_EXECUTABLE) - -# playbq - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - playbq.c - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -LOCAL_STATIC_LIBRARIES := \ - libOpenSLESUT \ - libsndfile - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_CFLAGS += -UNDEBUG - -LOCAL_MODULE:= slesTest_playbq - -# commented out because libsndfile is not yet standard -#include $(BUILD_EXECUTABLE) - -# monkey - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - monkey.c - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -LOCAL_STATIC_LIBRARIES := \ - libOpenSLESUT - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_CFLAGS += -UNDEBUG - -LOCAL_MODULE:= slesTest_monkey - -include $(BUILD_EXECUTABLE) - -# xa - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - xa.c - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenMAXAL - -LOCAL_STATIC_LIBRARIES := \ - libOpenSLESUT - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_CFLAGS += -UNDEBUG - -LOCAL_MODULE:= slesTest_xa - -include $(BUILD_EXECUTABLE) - -# dual - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - dual.c - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES \ - libOpenMAXAL - -LOCAL_STATIC_LIBRARIES := \ - libOpenSLESUT - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_CFLAGS += -UNDEBUG - -LOCAL_MODULE:= slesTest_dual - -include $(BUILD_EXECUTABLE) - -# xaplay - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - xaplay.c nativewindow.cpp - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenMAXAL \ - libgui \ - libbinder \ - libandroid - -LOCAL_STATIC_LIBRARIES := \ - libOpenSLESUT - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_CFLAGS += -UNDEBUG - -LOCAL_MODULE:= xaplay - -include $(BUILD_EXECUTABLE) diff --git a/wilhelm/tests/sandbox/configbq.c b/wilhelm/tests/sandbox/configbq.c deleted file mode 100644 index 3ae1a0aa..00000000 --- a/wilhelm/tests/sandbox/configbq.c +++ /dev/null @@ -1,223 +0,0 @@ -/* - * 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. - */ - -// Test various buffer queue configurations - -#include <assert.h> -#include <math.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> - -#include <SLES/OpenSLES.h> - -typedef struct { - SLuint8 numChannels; - SLuint32 milliHz; - SLuint8 bitsPerSample; -} PCM; - -PCM formats[] = { - {1, SL_SAMPLINGRATE_8, 8}, - {2, SL_SAMPLINGRATE_8, 8}, - {1, SL_SAMPLINGRATE_8, 16}, - {2, SL_SAMPLINGRATE_8, 16}, - {1, SL_SAMPLINGRATE_11_025, 8}, - {2, SL_SAMPLINGRATE_11_025, 8}, - {1, SL_SAMPLINGRATE_11_025, 16}, - {2, SL_SAMPLINGRATE_11_025, 16}, - {1, SL_SAMPLINGRATE_12, 8}, - {2, SL_SAMPLINGRATE_12, 8}, - {1, SL_SAMPLINGRATE_12, 16}, - {2, SL_SAMPLINGRATE_12, 16}, - {1, SL_SAMPLINGRATE_16, 8}, - {2, SL_SAMPLINGRATE_16, 8}, - {1, SL_SAMPLINGRATE_16, 16}, - {2, SL_SAMPLINGRATE_16, 16}, - {1, SL_SAMPLINGRATE_22_05, 8}, - {2, SL_SAMPLINGRATE_22_05, 8}, - {1, SL_SAMPLINGRATE_22_05, 16}, - {2, SL_SAMPLINGRATE_22_05, 16}, - {1, SL_SAMPLINGRATE_24, 8}, - {2, SL_SAMPLINGRATE_24, 8}, - {1, SL_SAMPLINGRATE_24, 16}, - {2, SL_SAMPLINGRATE_24, 16}, - {1, SL_SAMPLINGRATE_32, 8}, - {2, SL_SAMPLINGRATE_32, 8}, - {1, SL_SAMPLINGRATE_32, 16}, - {2, SL_SAMPLINGRATE_32, 16}, - {1, SL_SAMPLINGRATE_44_1, 8}, - {2, SL_SAMPLINGRATE_44_1, 8}, - {1, SL_SAMPLINGRATE_44_1, 16}, - {2, SL_SAMPLINGRATE_44_1, 16}, - {1, SL_SAMPLINGRATE_48, 8}, - {2, SL_SAMPLINGRATE_48, 8}, - {1, SL_SAMPLINGRATE_48, 16}, - {2, SL_SAMPLINGRATE_48, 16}, - {0, 0, 0} -}; - -int main(int argc, char **argv) -{ - SLresult result; - SLObjectItf engineObject; - - // create engine - result = slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL); - assert(SL_RESULT_SUCCESS == result); - SLEngineItf engineEngine; - result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine); - assert(SL_RESULT_SUCCESS == result); - - // create output mix - SLObjectItf outputMixObject; - result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 0, NULL, NULL); - assert(SL_RESULT_SUCCESS == result); - result = (*outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - - // loop over all formats - PCM *format; - float hzLeft = 440.0; // A440 (Concert A) - float hzRight = 440.0; - for (format = formats; format->numChannels; ++format) { - - printf("Channels: %d, sample rate: %u, bits: %u\n", format->numChannels, - format->milliHz / 1000, format->bitsPerSample); - - // configure audio source - SLDataLocator_BufferQueue loc_bufq; - loc_bufq.locatorType = SL_DATALOCATOR_BUFFERQUEUE; - loc_bufq.numBuffers = 1; - SLDataFormat_PCM format_pcm; - format_pcm.formatType = SL_DATAFORMAT_PCM; - format_pcm.numChannels = format->numChannels; - format_pcm.samplesPerSec = format->milliHz; - format_pcm.bitsPerSample = format->bitsPerSample; - format_pcm.containerSize = format->bitsPerSample; - format_pcm.channelMask = 0; - format_pcm.endianness = SL_BYTEORDER_LITTLEENDIAN; - SLDataSource audioSrc; - audioSrc.pLocator = &loc_bufq; - audioSrc.pFormat = &format_pcm; - - // configure audio sink - SLDataLocator_OutputMix loc_outmix; - loc_outmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; - loc_outmix.outputMix = outputMixObject; - SLDataSink audioSnk; - audioSnk.pLocator = &loc_outmix; - audioSnk.pFormat = NULL; - - // create audio player - SLuint32 numInterfaces = 1; - SLInterfaceID ids[1]; - SLboolean req[1]; - ids[0] = SL_IID_BUFFERQUEUE; - req[0] = SL_BOOLEAN_TRUE; - SLObjectItf playerObject; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audioSrc, - &audioSnk, numInterfaces, ids, req); - if (SL_RESULT_SUCCESS != result) { - printf("failed %u\n", result); - continue; - } - - // realize the player - result = (*playerObject)->Realize(playerObject, SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - - // generate a sine wave buffer, ascending in half-steps for each format -#define N (44100*4) - static unsigned char buffer[N]; - unsigned i; - for (i = 0; i < N; ) { - float seconds = (((i * 8) / (format->bitsPerSample * format->numChannels)) * 1000.0) / - format->milliHz; - short sampleLeft = sin(seconds * M_PI_2 * hzLeft) * 32767.0; - short sampleRight = sin(seconds * M_PI_2 * hzRight) * 32767.0; - if (2 == format->numChannels) { - if (8 == format->bitsPerSample) { - buffer[i++] = (sampleLeft + 32768) >> 8; - buffer[i++] = (sampleRight + 32768) >> 8; - } else { - assert(16 == format->bitsPerSample); - buffer[i++] = sampleLeft & 0xFF; - buffer[i++] = sampleLeft >> 8; - buffer[i++] = sampleRight & 0xFF; - buffer[i++] = sampleRight >> 8; - } - } else { - assert(1 == format->numChannels); - // cast to int and divide by 2 are needed to prevent overflow - short sampleMono = ((int) sampleLeft + (int) sampleRight) / 2; - if (8 == format->bitsPerSample) { - buffer[i++] = (sampleMono + 32768) >> 8; - } else { - assert(16 == format->bitsPerSample); - buffer[i++] = sampleMono & 0xFF; - buffer[i++] = sampleMono >> 8; - } - } - if (seconds >= 1.0f) - break; - } - - // get the buffer queue interface and enqueue a buffer - SLBufferQueueItf playerBufferQueue; - result = (*playerObject)->GetInterface(playerObject, SL_IID_BUFFERQUEUE, - &playerBufferQueue); - assert(SL_RESULT_SUCCESS == result); - result = (*playerBufferQueue)->Enqueue(playerBufferQueue, buffer, i); - assert(SL_RESULT_SUCCESS == result); - - // get the play interface - SLPlayItf playerPlay; - result = (*playerObject)->GetInterface(playerObject, SL_IID_PLAY, &playerPlay); - assert(SL_RESULT_SUCCESS == result); - - // set the player's state to playing - result = (*playerPlay)->SetPlayState(playerPlay, SL_PLAYSTATE_PLAYING); - assert(SL_RESULT_SUCCESS == result); - - // wait for the buffer to be played - for (;;) { - SLBufferQueueState state; - result = (*playerBufferQueue)->GetState(playerBufferQueue, &state); - assert(SL_RESULT_SUCCESS == result); - if (state.count == 0) - break; - usleep(20000); - } - - // destroy audio player - (*playerObject)->Destroy(playerObject); - - //usleep(1000000); - hzLeft *= 1.05946309; // twelfth root of 2 - hzRight /= 1.05946309; - } - - // destroy output mix - (*outputMixObject)->Destroy(outputMixObject); - - // destroy engine - (*engineObject)->Destroy(engineObject); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/sandbox/dim.c b/wilhelm/tests/sandbox/dim.c deleted file mode 100644 index 8e815df9..00000000 --- a/wilhelm/tests/sandbox/dim.c +++ /dev/null @@ -1,156 +0,0 @@ -/* - * 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. - */ - -// Test dynamic interface management - -#include <assert.h> -#include <math.h> -#include <stdio.h> -#include <stdlib.h> - -#include <SLES/OpenSLES.h> -#ifdef ANDROID -#include <SLES/OpenSLES_Android.h> -#endif - -int main(int argc, char **argv) -{ - if (argc != 1) { - fprintf(stderr, "usage: %s\n", argv[0]); - return EXIT_FAILURE; - } - - SLresult result; - SLObjectItf engineObject; - - // create engine - result = slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL); - assert(SL_RESULT_SUCCESS == result); - SLEngineItf engineEngine; - result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine); - assert(SL_RESULT_SUCCESS == result); - - // create output mix - SLObjectItf outputMixObject; - result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 0, NULL, NULL); - assert(SL_RESULT_SUCCESS == result); - - // get the dynamic interface management interface for output mix, before realize - SLDynamicInterfaceManagementItf outputMixDIM; - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_DYNAMICINTERFACEMANAGEMENT, - &outputMixDIM); - assert(SL_RESULT_PRECONDITIONS_VIOLATED == result); - assert(NULL == outputMixDIM); - - // realize output mix - result = (*outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - - // get the dynamic interface management interface for output mix, after realize - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_DYNAMICINTERFACEMANAGEMENT, - &outputMixDIM); - assert(SL_RESULT_SUCCESS == result); - assert(NULL != outputMixDIM); - - // register callback - result = (*outputMixDIM)->RegisterCallback(outputMixDIM, NULL, NULL); - assert(SL_RESULT_SUCCESS == result); - - // get environmental reverb interface, before add or resume - SLEnvironmentalReverbItf outputMixEnvironmentalReverb; - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_ENVIRONMENTALREVERB, - &outputMixEnvironmentalReverb); - assert(SL_RESULT_FEATURE_UNSUPPORTED == result); - assert(NULL == outputMixEnvironmentalReverb); - - // resume environmental reverb interface - result = (*outputMixDIM)->ResumeInterface(outputMixDIM, SL_IID_ENVIRONMENTALREVERB, - SL_BOOLEAN_FALSE); - assert(SL_RESULT_PRECONDITIONS_VIOLATED == result); - - // get environmental reverb interface, after resume but before add - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_ENVIRONMENTALREVERB, - &outputMixEnvironmentalReverb); - assert(SL_RESULT_FEATURE_UNSUPPORTED == result); - assert(NULL == outputMixEnvironmentalReverb); - - // add environmental reverb interface - result = (*outputMixDIM)->AddInterface(outputMixDIM, SL_IID_ENVIRONMENTALREVERB, - SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - - // get environmental reverb interface, after add - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_ENVIRONMENTALREVERB, - &outputMixEnvironmentalReverb); - assert(SL_RESULT_SUCCESS == result); - assert(NULL != outputMixEnvironmentalReverb); - - // add environmental reverb interface again - result = (*outputMixDIM)->AddInterface(outputMixDIM, SL_IID_ENVIRONMENTALREVERB, - SL_BOOLEAN_FALSE); - assert(SL_RESULT_PRECONDITIONS_VIOLATED == result); - - // resume environmental reverb interface - result = (*outputMixDIM)->ResumeInterface(outputMixDIM, SL_IID_ENVIRONMENTALREVERB, - SL_BOOLEAN_FALSE); - assert(SL_RESULT_PRECONDITIONS_VIOLATED == result); - - // remove environmental reverb interface (FIXME not yet implemented) - result = (*outputMixDIM)->RemoveInterface(outputMixDIM, SL_IID_ENVIRONMENTALREVERB); - assert((SL_RESULT_SUCCESS == result) || (SL_RESULT_FEATURE_UNSUPPORTED == result)); - - // FIXME once remove is implemented we can try this - if (SL_RESULT_SUCCESS == result) { - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_ENVIRONMENTALREVERB, - &outputMixEnvironmentalReverb); - assert(SL_RESULT_PRECONDITIONS_VIOLATED == result); - assert(NULL == outputMixEnvironmentalReverb); - result = (*outputMixDIM)->RemoveInterface(outputMixDIM, SL_IID_ENVIRONMENTALREVERB); - assert(SL_RESULT_PRECONDITIONS_VIOLATED == result); - result = (*outputMixDIM)->AddInterface(outputMixDIM, SL_IID_ENVIRONMENTALREVERB, - SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_ENVIRONMENTALREVERB, - &outputMixEnvironmentalReverb); - assert(SL_RESULT_SUCCESS == result); - assert(NULL != outputMixEnvironmentalReverb); - } - - // get non-sensical play interface, before add - SLPlayItf outputMixPlay; - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_PLAY, &outputMixPlay); - assert(SL_RESULT_FEATURE_UNSUPPORTED == result); - assert(NULL == outputMixPlay); - - // add play interface - result = (*outputMixDIM)->AddInterface(outputMixDIM, SL_IID_PLAY, SL_BOOLEAN_FALSE); - assert(SL_RESULT_FEATURE_UNSUPPORTED == result); - - // get play interface should still fail - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_PLAY, &outputMixPlay); - assert(SL_RESULT_FEATURE_UNSUPPORTED == result); - assert(NULL == outputMixPlay); - - // destroy output mix - (*outputMixObject)->Destroy(outputMixObject); - - // destroy engine - (*engineObject)->Destroy(engineObject); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/sandbox/dual.c b/wilhelm/tests/sandbox/dual.c deleted file mode 100644 index c3da1ff6..00000000 --- a/wilhelm/tests/sandbox/dual.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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. - */ - -// Dual engine test - -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> -#include <SLES/OpenSLES.h> -#include <OMXAL/OpenMAXAL.h> - -int main(int argc, char **argv) -{ - XAresult xaResult; - XAObjectItf xaEngineObject; - - SLresult slResult; - SLObjectItf slEngineObject; - - printf("xaCreateEngine\n"); - xaResult = xaCreateEngine(&xaEngineObject, 0, NULL, 0, NULL, NULL); - printf("xaResult = %d\n", xaResult); - assert(XA_RESULT_SUCCESS == xaResult); - printf("xaEngineObject = %p\n", xaEngineObject); - - printf("realize xaEngineObject\n"); - xaResult = (*xaEngineObject)->Realize(xaEngineObject, XA_BOOLEAN_FALSE); - printf("xaResult = %d\n", xaResult); - - printf("GetInterface for XA_IID_ENGINE\n"); - XAEngineItf xaEngineEngine; - xaResult = (*xaEngineObject)->GetInterface(xaEngineObject, XA_IID_ENGINE, &xaEngineEngine); - printf("xaResult = %d\n", xaResult); - printf("xaEngineEngine = %p\n", xaEngineEngine); - assert(XA_RESULT_SUCCESS == xaResult); - - printf("slCreateEngine\n"); - slResult = slCreateEngine(&slEngineObject, 0, NULL, 0, NULL, NULL); - printf("slResult = %d\n", slResult); - assert(SL_RESULT_SUCCESS == slResult); - printf("slEngineObject = %p\n", slEngineObject); - - printf("realize slEngineObject\n"); - slResult = (*slEngineObject)->Realize(slEngineObject, SL_BOOLEAN_FALSE); - printf("slResult = %d\n", slResult); - - printf("GetInterface for SL_IID_ENGINE\n"); - SLEngineItf slEngineEngine; - slResult = (*slEngineObject)->GetInterface(slEngineObject, SL_IID_ENGINE, &slEngineEngine); - printf("slResult = %d\n", slResult); - printf("slEngineEngine = %p\n", slEngineEngine); - assert(SL_RESULT_SUCCESS == slResult); - - printf("destroying xaEngineObject\n"); - (*xaEngineObject)->Destroy(xaEngineObject); - - printf("destroying slEngineObject\n"); - (*slEngineObject)->Destroy(slEngineObject); - - printf("exit\n"); - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/sandbox/engine.c b/wilhelm/tests/sandbox/engine.c deleted file mode 100644 index f18ea91e..00000000 --- a/wilhelm/tests/sandbox/engine.c +++ /dev/null @@ -1,172 +0,0 @@ -/* - * 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. - */ - -#include <SLES/OpenSLES.h> -#include "OpenSLESUT.h" -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -int main(int argc, char **argv) -{ - printf("Get number of available engine interfaces\n"); - SLresult result; - SLuint32 numSupportedInterfaces = 12345; - result = slQueryNumSupportedEngineInterfaces(&numSupportedInterfaces); - assert(SL_RESULT_SUCCESS == result); - result = slQueryNumSupportedEngineInterfaces(NULL); - assert(SL_RESULT_PARAMETER_INVALID == result); - - printf("Engine number of supported interfaces %u\n", numSupportedInterfaces); - SLInterfaceID *engine_ids = calloc(numSupportedInterfaces+1, sizeof(SLInterfaceID)); - assert(engine_ids != NULL); - SLboolean *engine_req = calloc(numSupportedInterfaces+1, sizeof(SLboolean)); - assert(engine_req != NULL); - - printf("Display the ID of each available interface\n"); - SLuint32 index; - for (index = 0; index < numSupportedInterfaces + 1; ++index) { - SLInterfaceID interfaceID; - memset(&interfaceID, 0x55, sizeof(interfaceID)); - result = slQuerySupportedEngineInterfaces(index, &interfaceID); - if (index < numSupportedInterfaces) { - assert(SL_RESULT_SUCCESS == result); - printf("interface[%u] ", index); - slesutPrintIID(interfaceID); - engine_ids[index] = interfaceID; - engine_req[index] = SL_BOOLEAN_TRUE; - } else { - assert(SL_RESULT_PARAMETER_INVALID == result); - } - result = slQuerySupportedEngineInterfaces(index, NULL); - assert(SL_RESULT_PARAMETER_INVALID == result); - } - - printf("Create an engine and request all available interfaces\n"); - SLObjectItf engineObject; - if (0 < numSupportedInterfaces) { - printf("Create engine with numSupportedInterfaces > 0 but NULL pointers\n"); - result = slCreateEngine(&engineObject, 0, NULL, numSupportedInterfaces, engine_ids, NULL); - assert(SL_RESULT_PARAMETER_INVALID == result); - assert(NULL == engineObject); - result = slCreateEngine(&engineObject, 0, NULL, numSupportedInterfaces, NULL, engine_req); - assert(SL_RESULT_PARAMETER_INVALID == result); - assert(NULL == engineObject); - } - - printf("Create engine with no place to return the new engine object\n"); - result = slCreateEngine(NULL, 0, NULL, numSupportedInterfaces, engine_ids, engine_req); - assert(SL_RESULT_PARAMETER_INVALID == result); - - printf("Create engine with NULL interface pointer\n"); - SLInterfaceID null_id[1] = {NULL}; - SLboolean null_req[1] = {SL_BOOLEAN_FALSE}; - result = slCreateEngine(&engineObject, 0, NULL, 1, null_id, null_req); - assert(SL_RESULT_PARAMETER_INVALID == result); - assert(NULL == engineObject); - - printf("Create an engine with numOptions > 0 but NULL pointer\n"); - result = slCreateEngine(&engineObject, 1, NULL, 0, NULL, NULL); - assert(SL_RESULT_PARAMETER_INVALID == result); - assert(NULL == engineObject); - SLEngineOption options[2]; - options[0].feature = 0x12345; - options[0].data = 0; - - printf("Create engine with non-sensical option\n"); - result = slCreateEngine(&engineObject, 1, options, 0, NULL, NULL); - assert(SL_RESULT_PARAMETER_INVALID == result); - assert(NULL == engineObject); - - printf("Create an engine and require non-sensical volume interface\n"); - engine_ids[numSupportedInterfaces] = SL_IID_VOLUME; - engine_req[numSupportedInterfaces] = SL_BOOLEAN_TRUE; - result = slCreateEngine(&engineObject, 0, NULL, numSupportedInterfaces+1, engine_ids, - engine_req); - assert(SL_RESULT_FEATURE_UNSUPPORTED == result); - assert(NULL == engineObject); - - printf("Create an engine and politely request a non-sensical interface with options\n"); - engine_req[numSupportedInterfaces] = SL_BOOLEAN_FALSE; - options[0].feature = SL_ENGINEOPTION_THREADSAFE; - options[0].data = (SLuint32) SL_BOOLEAN_TRUE; - options[1].feature = SL_ENGINEOPTION_LOSSOFCONTROL; - options[1].data = (SLuint32) SL_BOOLEAN_FALSE; - result = slCreateEngine(&engineObject, 2, options, numSupportedInterfaces+1, engine_ids, - engine_req); - assert(SL_RESULT_SUCCESS == result); - printf("Engine object %p\n", engineObject); - - printf("Get each available interface before realization\n"); - for (index = 0; index < numSupportedInterfaces; ++index) { - void *interface = NULL; - // Use the interface ID as returned by slQuerySupportedEngineInterfaces - result = (*engineObject)->GetInterface(engineObject, engine_ids[index], &interface); - assert(SL_RESULT_SUCCESS == result || SL_RESULT_PRECONDITIONS_VIOLATED == result); - if (SL_RESULT_SUCCESS == result) { - printf("interface available pre-realize: "); - slesutPrintIID(engine_ids[index]); - } - } - - printf("Destroy engine before realization\n"); - (*engineObject)->Destroy(engineObject); - - printf("Create engine again\n"); - result = slCreateEngine(&engineObject, 0, NULL, numSupportedInterfaces, engine_ids, engine_req); - assert(SL_RESULT_SUCCESS == result); - printf("Engine object %p\n", engineObject); - - printf("Realize the engine\n"); - result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - - printf("Get each available interface after realization\n"); - for (index = 0; index < numSupportedInterfaces; ++index) { - void *interface = NULL; - result = (*engineObject)->GetInterface(engineObject, engine_ids[index], &interface); - assert(SL_RESULT_SUCCESS == result); - printf("interface[%u] %p\n", index, interface); - // Use a copy of the interface ID to make sure lookup is not purely relying on address - void *interface_again = NULL; - struct SLInterfaceID_ copy = *engine_ids[index]; - result = (*engineObject)->GetInterface(engineObject, ©, &interface_again); - assert(SL_RESULT_SUCCESS == result); - // Calling GetInterface multiple times should return the same interface - assert(interface_again == interface); - } - - SLObjectItf engineObject2; -#if 0 - printf("Create too many engines\n"); - result = slCreateEngine(&engineObject2, 0, NULL, 0, NULL, NULL); - assert(SL_RESULT_RESOURCE_ERROR == result); - assert(NULL == engineObject2); -#endif - - printf("Destroy engine\n"); - (*engineObject)->Destroy(engineObject); - - printf("Now should be able to create another engine\n"); - result = slCreateEngine(&engineObject2, 0, NULL, 0, NULL, NULL); - assert(SL_RESULT_SUCCESS == result); - - printf("Exit without destroying engine -- examine log for expected error message\n"); - free(engine_ids); - free(engine_req); - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/sandbox/getch.c b/wilhelm/tests/sandbox/getch.c deleted file mode 100644 index 446770a1..00000000 --- a/wilhelm/tests/sandbox/getch.c +++ /dev/null @@ -1,65 +0,0 @@ -/* -C non-blocking keyboard input -http://stackoverflow.com/questions/448944/c-non-blocking-keyboard-input -*/ - -#include <stdlib.h> -#include <string.h> -#include <sys/select.h> -#include <termios.h> -#include <unistd.h> -#include "getch.h" - -struct termios orig_termios; - -void reset_terminal_mode() -{ - tcsetattr(0, TCSANOW, &orig_termios); -} - -void set_conio_terminal_mode() -{ - struct termios new_termios; - - /* take two copies - one for now, one for later */ - tcgetattr(0, &orig_termios); - memcpy(&new_termios, &orig_termios, sizeof(new_termios)); - - /* register cleanup handler, and set the new terminal mode */ - atexit(reset_terminal_mode); - cfmakeraw(&new_termios); - new_termios.c_oflag |= OPOST; - tcsetattr(0, TCSANOW, &new_termios); -} - -int kbhit() -{ - struct timeval tv = { 0L, 0L }; - fd_set fds; - FD_ZERO(&fds); // not in original posting to stackoverflow - FD_SET(0, &fds); - return select(1, &fds, NULL, NULL, &tv); -} - -int getch() -{ - int r; - unsigned char c; - if ((r = read(0, &c, sizeof(c))) < 0) { - return r; - } else { - return c; - } -} - -#if 0 -int main(int argc, char *argv[]) -{ - set_conio_terminal_mode(); - - while (!kbhit()) { - /* do some work */ - } - (void)getch(); /* consume the character */ -} -#endif diff --git a/wilhelm/tests/sandbox/getch.h b/wilhelm/tests/sandbox/getch.h deleted file mode 100644 index 802c3f45..00000000 --- a/wilhelm/tests/sandbox/getch.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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. - */ - -extern int kbhit(); -extern int getch(void); -extern void set_conio_terminal_mode(void); diff --git a/wilhelm/tests/sandbox/intbufq.c b/wilhelm/tests/sandbox/intbufq.c deleted file mode 100644 index e06685f1..00000000 --- a/wilhelm/tests/sandbox/intbufq.c +++ /dev/null @@ -1,281 +0,0 @@ -/* - * 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. - */ - -/* interactive buffer queue test program */ - -#ifdef ANDROID -#define USE_ANDROID_SIMPLE_BUFFER_QUEUE // change to #undef for compatibility testing -#endif - -#include <assert.h> -#include <math.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <SLES/OpenSLES.h> -#ifdef USE_ANDROID_SIMPLE_BUFFER_QUEUE -#include <SLES/OpenSLES_Android.h> -#endif -#include "getch.h" - -#ifdef USE_ANDROID_SIMPLE_BUFFER_QUEUE -#define DATALOCATOR_BUFFERQUEUE SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE -#define IID_BUFFERQUEUE SL_IID_ANDROIDSIMPLEBUFFERQUEUE -#define BufferQueueItf SLAndroidSimpleBufferQueueItf -#define BufferQueueState SLAndroidSimpleBufferQueueState -#define INDEX index -#else -#define DATALOCATOR_BUFFERQUEUE SL_DATALOCATOR_BUFFERQUEUE -#define IID_BUFFERQUEUE SL_IID_BUFFERQUEUE -#define BufferQueueItf SLBufferQueueItf -#define BufferQueueState SLBufferQueueState -#define INDEX playIndex -#endif - -#define checkResult(r) do { if ((r) != SL_RESULT_SUCCESS) fprintf(stderr, "error %d at %s:%d\n", \ - (int) r, __FILE__, __LINE__); } while (0) - -typedef struct { - short left; - short right; -} frame_t; - -#define SINE_FRAMES (44100*5) -frame_t sine[SINE_FRAMES]; - -#define SQUARE_FRAMES (44100*5) -frame_t square[SQUARE_FRAMES]; - -#define SAWTOOTH_FRAMES (44100*5) -frame_t sawtooth[SAWTOOTH_FRAMES]; - -#define HALF_FRAMES (44100*5) -frame_t half[HALF_FRAMES]; - -BufferQueueItf expectedCaller = NULL; -void *expectedContext = NULL; - -static void callback(BufferQueueItf caller, void *context) -{ - putchar('.'); - if (caller != expectedCaller) - printf("caller %p expected %p\r\n", caller, expectedCaller); - if (context != expectedContext) - printf("context %p expected %p\r\n", context, expectedContext); - fflush(stdout); -} - -int main(int argc, char **argv) -{ - SLresult result; - - // create engine - SLObjectItf engineObject; - result = slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL); - checkResult(result); - result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE); - checkResult(result); - SLEngineItf engineEngine; - result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine); - checkResult(result); - - // create output mix - SLObjectItf outputmixObject; - result = (*engineEngine)->CreateOutputMix(engineEngine, &outputmixObject, 0, NULL, NULL); - checkResult(result); - result = (*outputmixObject)->Realize(outputmixObject, SL_BOOLEAN_FALSE); - checkResult(result); - - // create audio player - SLDataSource audiosrc; - SLDataSink audiosnk; - SLDataFormat_PCM pcm; - SLDataLocator_OutputMix locator_outputmix; - SLDataLocator_BufferQueue locator_bufferqueue; - locator_bufferqueue.locatorType = DATALOCATOR_BUFFERQUEUE; - locator_bufferqueue.numBuffers = 255; - locator_outputmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; - locator_outputmix.outputMix = outputmixObject; - pcm.formatType = SL_DATAFORMAT_PCM; - pcm.numChannels = 2; - pcm.samplesPerSec = SL_SAMPLINGRATE_44_1; - pcm.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_16; - pcm.containerSize = 16; - pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT; - pcm.endianness = SL_BYTEORDER_LITTLEENDIAN; - audiosrc.pLocator = &locator_bufferqueue; - audiosrc.pFormat = &pcm; - audiosnk.pLocator = &locator_outputmix; - audiosnk.pFormat = NULL; - SLObjectItf playerObject; - SLInterfaceID ids[2] = {IID_BUFFERQUEUE, SL_IID_MUTESOLO}; - SLboolean flags[2] = {SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE}; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audiosrc, &audiosnk, - 2, ids, flags); - checkResult(result); - result = (*playerObject)->Realize(playerObject, SL_BOOLEAN_FALSE); - checkResult(result); - SLPlayItf playerPlay; - result = (*playerObject)->GetInterface(playerObject, SL_IID_PLAY, &playerPlay); - checkResult(result); - BufferQueueItf playerBufferqueue; - result = (*playerObject)->GetInterface(playerObject, IID_BUFFERQUEUE, &playerBufferqueue); - checkResult(result); - SLMuteSoloItf playerMuteSolo; - result = (*playerObject)->GetInterface(playerObject, SL_IID_MUTESOLO, &playerMuteSolo); - checkResult(result); - SLuint8 numChannels = 123; - result = (*playerMuteSolo)->GetNumChannels(playerMuteSolo, &numChannels); - assert(2 == numChannels); - SLuint32 state; - state = SL_PLAYSTATE_PLAYING; - result = (*playerPlay)->SetPlayState(playerPlay, state); - checkResult(result); - - unsigned i; - float pi2 = 3.14*2; - float hz = 441; - float sr = 44100; - for (i = 0; i < SINE_FRAMES; ++i) { - sine[i].left = sin((float) (i / (sr / hz)) * pi2 ) * 32000.0; - sine[i].right = sine[i].left; - } - for (i = 0; i < SQUARE_FRAMES; ++i) { - square[i].left = (i % (unsigned) (sr / hz)) < 50 ? 32767 : -32768; - square[i].right = square[i].left; - } - for (i = 0; i < SAWTOOTH_FRAMES; ++i) { - sawtooth[i].left = ((((int) (i % (unsigned) (sr / hz))) - 50) / 100.0) * 60000.0 - 30000.0; - sawtooth[i].right = sawtooth[i].left; - } - for (i = 0; i < HALF_FRAMES; ++i) { - half[i].left = sine[i].left; - half[i].right = sawtooth[i].right / 2; - } - - set_conio_terminal_mode(); - int in_count = 0; - unsigned count = 0; - for (;;) { - usleep(10000); - if (kbhit()) { - frame_t *buffer; - unsigned size; - BufferQueueState bufqstate; - int ch = getch(); - switch (ch) { - case '0' ... '9': - if (in_count) { - count = count * 10 + (ch - '0'); - } else { - count = ch - '0'; - in_count = 1; - } - continue; - case 'i': - buffer = sine; - size = sizeof(sine); - goto enqueue; - case 'q': - buffer = square; - size = sizeof(square); - goto enqueue; - case 'h': - buffer = half; - size = sizeof(half); - goto enqueue; - case 'r': - if (in_count) { - expectedCaller = playerBufferqueue; - expectedContext = (void *) count; - } else { - expectedCaller = NULL; - expectedContext = (void *) NULL; - } - result = (*playerBufferqueue)->RegisterCallback(playerBufferqueue, in_count ? - callback : NULL, expectedContext); - checkResult(result); - break; - case 'a': - buffer = sawtooth; - size = sizeof(sawtooth); -enqueue: - for (i = 0; i < (in_count ? count : 1); ++i) { - result = (*playerBufferqueue)->Enqueue(playerBufferqueue, buffer, size); - checkResult(result); - } - break; - case 'c': - result = (*playerBufferqueue)->Clear(playerBufferqueue); - checkResult(result); - putchar('\r'); - result = (*playerBufferqueue)->GetState(playerBufferqueue, &bufqstate); - checkResult(result); - if (bufqstate.count != 0) - printf("\rcount=%u\r\n", (unsigned) bufqstate.count); -#if 0 - putchar('\r'); - putchar('\n'); -#endif - fflush(stdout); - break; - case 'g': - result = (*playerBufferqueue)->GetState(playerBufferqueue, &bufqstate); - checkResult(result); - printf("\rplayIndex=%u\r\n", (unsigned) bufqstate.INDEX); - printf("count=%u\r\n", (unsigned) bufqstate.count); - break; - case 'p': - state = SL_PLAYSTATE_PAUSED; - goto setplaystate; - case 's': - state = SL_PLAYSTATE_STOPPED; - goto setplaystate; - case 'P': - state = SL_PLAYSTATE_PLAYING; -setplaystate: - result = (*playerPlay)->SetPlayState(playerPlay, state); - checkResult(result); - SLuint32 newstate; - result = (*playerPlay)->GetPlayState(playerPlay, &newstate); - checkResult(result); - if (newstate != state) - printf("\rSetPlayState(%u) -> GetPlayState(%u)\r\n", (unsigned) state, - (unsigned) newstate); -#if 0 - putchar('\r'); - putchar('\n'); - fflush(stdout); -#endif - checkResult(result); - break; - case 'x': - goto out; - default: - putchar('?'); - fflush(stdout); - break; - } - in_count = 0; - } - } - -out: - (*playerObject)->Destroy(playerObject); - (*outputmixObject)->Destroy(outputmixObject); - (*engineObject)->Destroy(engineObject); - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/sandbox/monkey.c b/wilhelm/tests/sandbox/monkey.c deleted file mode 100644 index 49193c88..00000000 --- a/wilhelm/tests/sandbox/monkey.c +++ /dev/null @@ -1,302 +0,0 @@ -/* - * 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. - */ - -// single-threaded, single-player monkey test - -#include <SLES/OpenSLES.h> -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -typedef enum { - STATE_UNCHANGED, - STATE_INITIAL, - STATE_NONEXISTENT, - STATE_CREATED, - STATE_REALIZED, - STATE_PAUSED, - STATE_PLAYING, - STATE_STOPPED, - STATE_ERROR, -// STATE_IDLE, // after Stop, then sleep for 3 seconds - STATE_TERMINAL -} State_t; - -typedef struct { - SLObjectItf mObject; - SLPlayItf mPlay; - SLSeekItf mSeek; -} Player_t, *Player_pt; - -typedef State_t (*Action_pt)(Player_pt player); - -SLObjectItf engineObject; -SLEngineItf engineEngine; -SLObjectItf outputMixObject; -int countTransitions = 0; -int maxTransitions = 10; - -State_t actionPause(Player_pt p) -{ - assert(NULL != p->mPlay); - SLresult result = (*p->mPlay)->SetPlayState(p->mPlay, SL_PLAYSTATE_PAUSED); - assert(SL_RESULT_SUCCESS == result); - return STATE_PAUSED; -} - -State_t actionPlay(Player_pt p) -{ - assert(NULL != p->mPlay); - SLresult result = (*p->mPlay)->SetPlayState(p->mPlay, SL_PLAYSTATE_PLAYING); - assert(SL_RESULT_SUCCESS == result); - return STATE_PLAYING; -} - -State_t actionStop(Player_pt p) -{ - assert(NULL != p->mPlay); - SLresult result = (*p->mPlay)->SetPlayState(p->mPlay, SL_PLAYSTATE_STOPPED); - assert(SL_RESULT_SUCCESS == result); - return STATE_STOPPED; -} - -State_t actionRewind(Player_pt p) -{ - assert(NULL != p->mSeek); - SLresult result = (*p->mSeek)->SetPosition(p->mSeek, (SLmillisecond) 0, SL_SEEKMODE_FAST); - assert(SL_RESULT_SUCCESS == result); - return STATE_UNCHANGED; -} - -State_t actionDestroy(Player_pt p) -{ - assert(NULL != p->mObject); - (*p->mObject)->Destroy(p->mObject); - p->mObject = NULL; - p->mPlay = NULL; - p->mSeek = NULL; - return STATE_NONEXISTENT; -} - -State_t actionCreate(Player_pt p) -{ - // configure audio source - SLDataLocator_URI loc_uri; - loc_uri.locatorType = SL_DATALOCATOR_URI; - loc_uri.URI = (SLchar *) "wav/frog.wav"; - SLDataFormat_MIME format_mime; - format_mime.formatType = SL_DATAFORMAT_MIME; - format_mime.mimeType = NULL; - format_mime.containerType = SL_CONTAINERTYPE_UNSPECIFIED; - SLDataSource audioSrc; - audioSrc.pLocator = &loc_uri; - audioSrc.pFormat = &format_mime; - // configure audio sink - SLDataLocator_OutputMix loc_outmix; - loc_outmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; - loc_outmix.outputMix = outputMixObject; - SLDataSink audioSnk; - audioSnk.pLocator = &loc_outmix; - audioSnk.pFormat = NULL; - // create audio player - SLInterfaceID ids[1] = {SL_IID_SEEK}; - SLboolean req[1] = {SL_BOOLEAN_TRUE}; - SLresult result = (*engineEngine)->CreateAudioPlayer(engineEngine, &p->mObject, &audioSrc, - &audioSnk, 1, ids, req); - if (SL_RESULT_SUCCESS != result) - return STATE_ERROR; - return STATE_CREATED; -} - -State_t actionRealize(Player_pt p) -{ - assert(NULL != p->mObject); - // realize the player - SLresult result = (*p->mObject)->Realize(p->mObject, SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - // get interfaces - result = (*p->mObject)->GetInterface(p->mObject, SL_IID_PLAY, &p->mPlay); - assert(SL_RESULT_SUCCESS == result); - result = (*p->mObject)->GetInterface(p->mObject, SL_IID_SEEK, &p->mSeek); - assert(SL_RESULT_SUCCESS == result); - return STATE_REALIZED; -} - -State_t actionSleep(Player_pt p) -{ - unsigned us = 1000 + (rand() & 0xFFFFF); - usleep(us); - return STATE_UNCHANGED; -} - -#if 0 -State_t actionSleep3(Player_pt p) -{ - sleep(3); - return STATE_IDLE; -} -#endif - -State_t actionTerminateIfDone(Player_pt p) -{ - if (countTransitions >= maxTransitions) { - assert(NULL == p->mObject); - // clean up output mix and engine - assert(NULL != outputMixObject); - (*outputMixObject)->Destroy(outputMixObject); - outputMixObject = NULL; - assert(NULL != engineObject); - (*engineObject)->Destroy(engineObject); - engineObject = NULL; - return STATE_TERMINAL; - } else - return STATE_UNCHANGED; -} - -State_t actionInitialize(Player_pt p) -{ - // create engine - SLresult result = slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL); - assert(SL_RESULT_SUCCESS == result); - result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine); - assert(SL_RESULT_SUCCESS == result); - - // create output mix - result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 0, NULL, NULL); - assert(SL_RESULT_SUCCESS == result); - result = (*outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - - return STATE_NONEXISTENT; -} - -typedef struct { - State_t mEntryState; - Action_pt mAction; - unsigned mProbability; - const char *mActionName; - unsigned mCount; -} Transition_t; - -Transition_t transitionTable[] = { -#define _(entryState, action, probability) {entryState, action, probability, #action, 0}, - _(STATE_INITIAL, actionInitialize, 1) - _(STATE_CREATED, actionDestroy, 1) - _(STATE_CREATED, actionRealize, 1) - _(STATE_CREATED, actionSleep, 1) - _(STATE_NONEXISTENT, actionCreate, 1) - _(STATE_NONEXISTENT, actionSleep, 1) - _(STATE_PAUSED, actionDestroy, 1) - _(STATE_PAUSED, actionPause, 1) - _(STATE_PAUSED, actionPlay, 1) - _(STATE_PAUSED, actionRewind, 1) - _(STATE_PAUSED, actionSleep, 1) - _(STATE_PAUSED, actionStop, 1) - _(STATE_PLAYING, actionDestroy, 1) - _(STATE_PLAYING, actionPause, 1) - _(STATE_PLAYING, actionPlay, 1) - _(STATE_PLAYING, actionRewind, 1) - _(STATE_PLAYING, actionSleep, 1) - _(STATE_PLAYING, actionStop, 1) - _(STATE_REALIZED, actionDestroy, 1) - _(STATE_REALIZED, actionPause, 1) - _(STATE_REALIZED, actionPlay, 1) - _(STATE_REALIZED, actionSleep, 1) - _(STATE_REALIZED, actionStop, 1) - _(STATE_STOPPED, actionDestroy, 1) - _(STATE_STOPPED, actionPause, 1) - _(STATE_STOPPED, actionPlay, 1) - _(STATE_STOPPED, actionRewind, 1) - _(STATE_STOPPED, actionSleep, 1) - _(STATE_STOPPED, actionStop, 1) -// _(STATE_STOPPED, actionSleep3, 1) -// _(STATE_IDLE, actionDestroy, 1) - _(STATE_NONEXISTENT, actionTerminateIfDone, 1) -}; - -int main(int argc, char **argv) -{ - int i; - for (i = 1; i < argc; ++i) { - char *arg = argv[i]; - if (arg[0] != '-') - break; - if (!strncmp(arg, "-m", 2)) { - maxTransitions = atoi(&arg[2]); - } else { - fprintf(stderr, "Unknown option %s\n", arg); - } - } - unsigned possibleTransitions = sizeof(transitionTable) / sizeof(transitionTable[0]); - Player_t player; - player.mObject = NULL; - player.mPlay = NULL; - player.mSeek = NULL; - State_t currentState = STATE_INITIAL; - while (STATE_TERMINAL != currentState) { - unsigned matchingTransitions = 0; - unsigned totalProbability = 0; - for (i = 0; i < (int) possibleTransitions; ++i) { - if (currentState != transitionTable[i].mEntryState) - continue; - ++matchingTransitions; - totalProbability += transitionTable[i].mProbability; - } - if (matchingTransitions == 0) { - fprintf(stderr, "No matching transitions in state %d\n", currentState); - assert(SL_BOOLEAN_FALSE); - break; - } - if (totalProbability == 0) { - fprintf(stderr, "Found at least one matching transition in state %d, " - "but with probability 0\n", currentState); - assert(SL_BOOLEAN_FALSE); - break; - } - unsigned choice = (rand() & 0x7FFFFFFF) % totalProbability; - totalProbability = 0; - for (i = 0; i < (int) possibleTransitions; ++i) { - if (currentState != transitionTable[i].mEntryState) - continue; - totalProbability += transitionTable[i].mProbability; - if (totalProbability <= choice) - continue; - ++transitionTable[i].mCount; - ++countTransitions; - printf("[%d] Selecting transition %s in state %d for the %u time\n", countTransitions, - transitionTable[i].mActionName, currentState, transitionTable[i].mCount); - State_t nextState = (*transitionTable[i].mAction)(&player); - if (STATE_UNCHANGED != nextState) - currentState = nextState; - goto found; - } - fprintf(stderr, "This shouldn't happen\n"); - assert(SL_BOOLEAN_FALSE); -found: - ; - } - for (i = 0; i < (int) possibleTransitions; ++i) { - printf("state %d action %s count %u\n", - transitionTable[i].mEntryState, - transitionTable[i].mActionName, - transitionTable[i].mCount); - } - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/sandbox/multiplay.c b/wilhelm/tests/sandbox/multiplay.c deleted file mode 100644 index e4f42ce7..00000000 --- a/wilhelm/tests/sandbox/multiplay.c +++ /dev/null @@ -1,285 +0,0 @@ -/* - * 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. - */ - -// multiplay is a command-line test app that plays multiple files randomly - -#include <SLES/OpenSLES.h> -#include <assert.h> -#include <string.h> -#include <stdlib.h> -#include <stdio.h> -#include <unistd.h> - -// Describes the state of one player - -typedef struct { - SLObjectItf mPlayerObject; - SLPlayItf mPlayerPlay; - SLSeekItf mPlayerSeek; - SLPrefetchStatusItf mPlayerPrefetchStatus; - SLVolumeItf mPlayerVolume; - SLmillisecond mPlayerDuration; - SLboolean mPlayerErrorInCallback; - SLboolean mPlayerErrorReported; -} Player; - -// Strings corresponding to result codes; FIXME should move to a common test library - -static const char *result_strings[] = { - "SUCCESS", - "PRECONDITIONS_VIOLATED", - "PARAMETER_INVALID", - "MEMORY_FAILURE", - "RESOURCE_ERROR", - "RESOURCE_LOST", - "IO_ERROR", - "BUFFER_INSUFFICIENT", - "CONTENT_CORRUPTED", - "CONTENT_UNSUPPORTED", - "CONTENT_NOT_FOUND", - "PERMISSION_DENIED", - "FEATURE_UNSUPPORTED", - "INTERNAL_ERROR", - "UNKNOWN_ERROR", - "OPERATION_ABORTED", - "CONTROL_LOST" -}; - -// Convert result to string; FIXME should move to common test library - -static const char *result_to_string(SLresult result) -{ - static char buffer[32]; - if ( /* result >= 0 && */ result < sizeof(result_strings) / sizeof(result_strings[0])) - return result_strings[result]; - sprintf(buffer, "%d", (int) result); - return buffer; -} - -// Compare result against expected and exit suddenly if wrong - -void check2(SLresult result, int line) -{ - if (SL_RESULT_SUCCESS != result) { - fprintf(stderr, "error %s at line %d\n", result_to_string(result), line); - exit(EXIT_FAILURE); - } -} - -// Same as above but automatically adds the source code line number - -#define check(result) check2(result, __LINE__) - -// Prefetch status callback - -#define PREFETCHEVENT_ERROR_CANDIDATE \ - (SL_PREFETCHEVENT_STATUSCHANGE | SL_PREFETCHEVENT_FILLLEVELCHANGE) - -void prefetch_callback(SLPrefetchStatusItf caller, void *context, SLuint32 event) -{ - SLresult result; - assert(context != NULL); - Player *p = (Player *) context; - assert(p->mPlayerPrefetchStatus == caller); - SLpermille level; - result = (*caller)->GetFillLevel(caller, &level); - check(result); - SLuint32 status; - result = (*caller)->GetPrefetchStatus(caller, &status); - check(result); - //fprintf(stderr, "PrefetchEventCallback: received event %u, level %u, status %u\n", - // event, level, status); - if ((PREFETCHEVENT_ERROR_CANDIDATE == (event & PREFETCHEVENT_ERROR_CANDIDATE)) - && (level == 0) && (status == SL_PREFETCHSTATUS_UNDERFLOW)) { - p->mPlayerErrorInCallback = SL_BOOLEAN_TRUE; - } -} - -// Main program - -int main(int argc, char **argv) -{ - int i; - const char *arg; - int numPlayers = 0; - int playTimeInMilliseconds = 0; // default to run forever - SLmillibel mixVolumeLevel = 0; - for (i = 1; i < argc; ++i) { - arg = argv[i]; - if (arg[0] != '-') - break; - if (!strncmp(arg, "-n", 2)) - numPlayers = atoi(&arg[2]); - else if (!strncmp(arg, "-v", 2)) - mixVolumeLevel = atoi(&arg[2]); - else if (!strncmp(arg, "-t", 2)) - playTimeInMilliseconds = atoi(&arg[2]) * 1000; - else - fprintf(stderr, "unknown option: %s\n", arg); - } - int numPathnames = argc - i; - if (numPathnames <= 0) { - fprintf(stderr, "usage: %s file.wav ...\n", argv[0]); - return EXIT_FAILURE; - } - if (numPlayers <= 0) { - numPlayers = numPathnames; - } - Player *players = (Player *) calloc(numPlayers, sizeof(Player)); - assert(NULL != players); - char **pathnames = &argv[i]; - SLresult result; - - // engine - const SLInterfaceID engine_ids[] = {SL_IID_ENGINE}; - const SLboolean engine_req[] = {SL_BOOLEAN_TRUE}; - SLObjectItf engineObject; - result = slCreateEngine(&engineObject, 0, NULL, 1, engine_ids, engine_req); - check(result); - result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE); - check(result); - SLEngineItf engineEngine; - result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine); - check(result); - - // mixer - const SLInterfaceID mix_ids[] = {SL_IID_VOLUME}; - const SLboolean mix_req[] = {SL_BOOLEAN_TRUE}; - SLObjectItf mixObject; - result = (*engineEngine)->CreateOutputMix(engineEngine, &mixObject, 0, mix_ids, mix_req); - check(result); - result = (*mixObject)->Realize(mixObject, SL_BOOLEAN_FALSE); - check(result); -#if 0 - SLVolumeItf mixVolume; - result = (*mixObject)->GetInterface(mixObject, SL_IID_VOLUME, &mixVolume); - check(result); - SLmillibel mixVolumeLevelDefault; - result = (*mixVolume)->GetVolumeLevel(mixVolume, &mixVolumeLevelDefault); - check(result); - printf("default mix volume level = %d\n", mixVolumeLevelDefault); -#endif - - printf("numPathnames=%d\n", numPathnames); - printf("numPlayers=%d\n", numPlayers); - Player *p; - - // create all the players - for (i = 0; i < numPlayers; ++i) { - const SLInterfaceID player_ids[] = - {SL_IID_PLAY, SL_IID_VOLUME, SL_IID_SEEK, SL_IID_PREFETCHSTATUS}; - const SLboolean player_req[] = - {SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE}; - p = &players[i]; - SLDataLocator_URI locURI = {SL_DATALOCATOR_URI, (SLchar *) pathnames[i % numPathnames]}; - SLDataFormat_MIME dfMIME = {SL_DATAFORMAT_MIME, NULL, SL_CONTAINERTYPE_UNSPECIFIED}; - SLDataSource audioSrc = {&locURI, &dfMIME}; - SLDataLocator_OutputMix locOutputMix = {SL_DATALOCATOR_OUTPUTMIX, mixObject}; - SLDataSink audioSnk = {&locOutputMix, NULL}; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &p->mPlayerObject, &audioSrc, - &audioSnk, sizeof(player_ids)/sizeof(player_ids[0]), player_ids, player_req); - check(result); - result = (*p->mPlayerObject)->Realize(p->mPlayerObject, SL_BOOLEAN_FALSE); - check(result); - result = (*p->mPlayerObject)->GetInterface(p->mPlayerObject, SL_IID_PLAY, &p->mPlayerPlay); - check(result); - result = (*p->mPlayerObject)->GetInterface(p->mPlayerObject, SL_IID_VOLUME, - &p->mPlayerVolume); - check(result); - result = (*p->mPlayerObject)->GetInterface(p->mPlayerObject, SL_IID_SEEK, &p->mPlayerSeek); - check(result); - result = (*p->mPlayerObject)->GetInterface(p->mPlayerObject, SL_IID_PREFETCHSTATUS, - &p->mPlayerPrefetchStatus); - check(result); - result = (*p->mPlayerPrefetchStatus)->RegisterCallback(p->mPlayerPrefetchStatus, - prefetch_callback, p); - check(result); - result = (*p->mPlayerPrefetchStatus)->SetCallbackEventsMask(p->mPlayerPrefetchStatus, - SL_PREFETCHEVENT_STATUSCHANGE | SL_PREFETCHEVENT_FILLLEVELCHANGE); - check(result); - } - - // now loop randomly doing things to the players - for (;;) { - SLmillisecond delay = 100 + (rand() & 1023); - printf("sleep %u\n", (unsigned) delay); - usleep(delay * 1000); - i = (rand() & 0x7FFFFFFF) % numPlayers; - p = &players[i]; - if (p->mPlayerErrorReported) - continue; - printf("player %d (%s): ", i, pathnames[i]); - if (p->mPlayerErrorInCallback && !p->mPlayerErrorReported) { - printf("error, "); - p->mPlayerErrorReported = SL_BOOLEAN_TRUE; - } - result = (*p->mPlayerPlay)->GetDuration(p->mPlayerPlay, &p->mPlayerDuration); - check(result); - if (p->mPlayerDuration == SL_TIME_UNKNOWN) { - printf("duration unknown, "); - } else { - printf("duration %d ms, ", (int) p->mPlayerDuration); - } - SLuint32 state; - result = (*p->mPlayerPlay)->GetPlayState(p->mPlayerPlay, &state); - check(result); - printf("state = "); - switch (state) { - case SL_PLAYSTATE_STOPPED: - printf("STOPPED"); - break; - case SL_PLAYSTATE_PAUSED: - printf("PAUSED"); - break; - case SL_PLAYSTATE_PLAYING: - printf("PLAYING"); - break; - default: - printf("%u", (unsigned) state); - break; - } - printf("\n"); - if (state == SL_PLAYSTATE_STOPPED || state == SL_PLAYSTATE_PAUSED) { - SLmillibel volumeLevel = -((rand() & 0x7FFFFFFF) % ((SL_MILLIBEL_MIN + 1) / 10)); - printf("volume %d\n", volumeLevel); - result = (*p->mPlayerVolume)->SetVolumeLevel(p->mPlayerVolume, volumeLevel); - check(result); - result = (*p->mPlayerVolume)->EnableStereoPosition(p->mPlayerVolume, SL_BOOLEAN_TRUE); - check(result); - SLpermille stereoPosition = ((rand() & 0x7FFFFFFF) % 2001) - 1000; - printf("position %d\n", stereoPosition); - result = (*p->mPlayerVolume)->SetStereoPosition(p->mPlayerVolume, stereoPosition); - check(result); - if (state != SL_PLAYSTATE_STOPPED) { - result = (*p->mPlayerSeek)->SetPosition(p->mPlayerSeek, 0, SL_SEEKMODE_FAST); - check(result); - } - result = (*p->mPlayerPlay)->SetPlayState(p->mPlayerPlay, SL_PLAYSTATE_PLAYING); - check(result); - } - if ((playTimeInMilliseconds > 0) && ((playTimeInMilliseconds -= delay) < 0)) - break; - } - - for (i = 0; i < numPlayers; ++i) { - SLObjectItf playerObject = players[i].mPlayerObject; - (*playerObject)->Destroy(playerObject); - } - (*mixObject)->Destroy(mixObject); - (*engineObject)->Destroy(engineObject); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/sandbox/multithread.c b/wilhelm/tests/sandbox/multithread.c deleted file mode 100644 index b161656b..00000000 --- a/wilhelm/tests/sandbox/multithread.c +++ /dev/null @@ -1,194 +0,0 @@ -/* - * 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. - */ - -// Multiple threads create and destroy objects - -#include <SLES/OpenSLES.h> -#include <assert.h> -#include <pthread.h> -//#include <string.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> - -typedef struct { - SLuint32 mObjectID; - SLchar *mURI; - SLEngineItf mEngineEngine; - SLObjectItf mMixObject; - SLuint32 mCounter; -} ThreadArgument; - -volatile int timeToExit = 0; -#define MAX_THREAD 10 -pthread_t threads[MAX_THREAD]; -ThreadArgument thread_args[MAX_THREAD]; - -pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; - -void *thread_start(void *param) -{ - //pthread_mutex_lock(&mutex); - //pthread_mutex_unlock(&mutex); - ThreadArgument *ta = (ThreadArgument *) param; - - while (!timeToExit) { - SLresult result; - - ++ta->mCounter; - switch (ta->mObjectID) { - case SL_OBJECTID_OUTPUTMIX: - { - SLObjectItf myMixObject; - result = (*ta->mEngineEngine)->CreateOutputMix(ta->mEngineEngine, &myMixObject, 0, NULL, - NULL); - assert(SL_RESULT_SUCCESS == result); - result = (*myMixObject)->Realize(myMixObject, SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - (*myMixObject)->Destroy(myMixObject); - } - break; - - case SL_OBJECTID_AUDIOPLAYER: - { - SLDataLocator_URI locURI = {SL_DATALOCATOR_URI, ta->mURI}; - SLDataFormat_MIME dfMIME = {SL_DATAFORMAT_MIME, NULL, SL_CONTAINERTYPE_UNSPECIFIED}; - SLDataSource audioSrc = {&locURI, &dfMIME}; - SLDataLocator_OutputMix locOutputMix = {SL_DATALOCATOR_OUTPUTMIX, ta->mMixObject}; - SLDataSink audioSnk = {&locOutputMix, NULL}; - SLObjectItf myPlayerObject; - result = (*ta->mEngineEngine)->CreateAudioPlayer(ta->mEngineEngine, &myPlayerObject, - &audioSrc, &audioSnk, 0, NULL, NULL); - assert(SL_RESULT_SUCCESS == result); - result = (*myPlayerObject)->Realize(myPlayerObject, SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - SLPlayItf playerPlay; - result = (*myPlayerObject)->GetInterface(myPlayerObject, SL_IID_PLAY, &playerPlay); - assert(SL_RESULT_SUCCESS == result); - result = (*playerPlay)->SetPlayState(playerPlay, SL_PLAYSTATE_PAUSED); - assert(SL_RESULT_SUCCESS == result); - usleep(1000 + (rand() & 0xFFF)); - //usleep(1000); - //sleep(1); - (*myPlayerObject)->Destroy(myPlayerObject); - } - break; - - default: - break; - - } - //usleep(100000); - //break; - } - - return NULL; -} - - -//const char * const uris[4] = {"wav/frog.wav", "wav/bach.wav", "wav/8days.wav", "wav/help16.wav"}; -const char * const uris[4] = {"wav/frog.wav", "wav/frog.wav", "wav/frog.wav", "wav/frog.wav"}; - -// Main program - -int main(int argc, char **argv) -{ - SLresult result; - - // create engine - SLObjectItf engineObject; - result = slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL); - assert(SL_RESULT_SUCCESS == result); - result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - SLEngineItf engineEngine; - result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine); - assert(SL_RESULT_SUCCESS == result); - - // create output mix - SLObjectItf mixObject; - result = (*engineEngine)->CreateOutputMix(engineEngine, &mixObject, 0, NULL, NULL); - assert(SL_RESULT_SUCCESS == result); - result = (*mixObject)->Realize(mixObject, SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - - // create threads - int i; - int ok; - for (i = 0; i < MAX_THREAD; ++i) { - ThreadArgument *ta = &thread_args[i]; - int r = rand(); - switch (r & 1) { -#if 0 - case 0: - ta->mObjectID = SL_OBJECTID_OUTPUTMIX; - ta->mURI = NULL; - ta->mEngineEngine = engineEngine; - ta->mMixObject = NULL; - ta->mCounter = 0; - break; - case 1: -#endif - default: - ta->mObjectID = SL_OBJECTID_AUDIOPLAYER; - ta->mURI = (SLchar *) uris[(r >> 1) & 3]; - ta->mEngineEngine = engineEngine; - ta->mMixObject = mixObject; - ta->mCounter = 0; - break; - } - //pthread_mutex_lock(&mutex); - //pthread_mutex_unlock(&mutex); - ok = pthread_create(&threads[i], (const pthread_attr_t *) NULL, thread_start, - &thread_args[i]); - assert(0 == ok); - } - - // let it run for a while - int j; - for (j = 0; j < 100; ++j) { - sleep(1); - for (i = 0; i < MAX_THREAD; ++i) { - ThreadArgument *ta = &thread_args[i]; - printf("[%d]=%u ", j, ta->mCounter); - } - printf("\n"); - } - - // signal threads that they should exit - timeToExit = 1; - - for (j = 0; j < 3; ++j) { - sleep(1); - for (i = 0; i < MAX_THREAD; ++i) { - ThreadArgument *ta = &thread_args[i]; - printf("[%d]=%u ", j, ta->mCounter); - } - printf("\n"); - } - - // now wait for the threads to actually exit - for (i = 0; i < MAX_THREAD; ++i) { - ok = pthread_join(threads[i], NULL); - assert(0 == ok); - } - - // tear down objects - (*mixObject)->Destroy(mixObject); - (*engineObject)->Destroy(engineObject); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/sandbox/nativewindow.cpp b/wilhelm/tests/sandbox/nativewindow.cpp deleted file mode 100644 index 9f5b6ae9..00000000 --- a/wilhelm/tests/sandbox/nativewindow.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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. - */ - -// Copied from frameworks/base/cmds/stagefright/stream.cpp - -// Note to NDK developers who happen to see this: this module uses Android internal platform APIs -// that are not part of the NDK supported APIs, and are subject to change at any time. - -#include <binder/ProcessState.h> -#include <gui/Surface.h> -#include <gui/SurfaceComposerClient.h> -#include <utils/String8.h> - -#include "nativewindow.h" - -#if 1 -#include <assert.h> -#define CHECK assert -#define CHECK_EQ(a,b) CHECK((a)==(b)) -#else -#include <media/stagefright/foundation/ADebug.h> -#endif - -namespace android { - -sp<Surface> gSurface; -sp<SurfaceComposerClient> gComposerClient; -sp<SurfaceControl> gControl; - -ANativeWindow *getNativeWindow_() -{ -#if 0 - android::ProcessState::self()->startThreadPool(); -#endif - - sp<SurfaceComposerClient> composerClient = new SurfaceComposerClient; - CHECK_EQ(composerClient->initCheck(), (status_t)OK); - - sp<SurfaceControl> control = - composerClient->createSurface( - String8("A Surface"), - 0, - 1280, - 800, - PIXEL_FORMAT_RGB_565, - 0); - - CHECK(control != NULL); - CHECK(control->isValid()); - - SurfaceComposerClient::openGlobalTransaction(); - CHECK_EQ(control->setLayer(30000), (status_t)OK); - CHECK_EQ(control->show(), (status_t)OK); - SurfaceComposerClient::closeGlobalTransaction(); - - sp<Surface> surface = control->getSurface(); - CHECK(surface != NULL); - - gSurface = surface; - gComposerClient = composerClient; - gControl = control; - // composerClient->dispose() at exit - return surface.get(); -} - -void disposeNativeWindow_() -{ - gComposerClient->dispose(); -} - -} // namespace android - -ANativeWindow *getNativeWindow() -{ - return android::getNativeWindow_(); -} - -void disposeNativeWindow() -{ - android::disposeNativeWindow_(); -} diff --git a/wilhelm/tests/sandbox/nativewindow.h b/wilhelm/tests/sandbox/nativewindow.h deleted file mode 100644 index 24c93999..00000000 --- a/wilhelm/tests/sandbox/nativewindow.h +++ /dev/null @@ -1,12 +0,0 @@ -#include <android/native_window_jni.h> - -#ifdef __cplusplus -extern "C" { -#endif - -extern ANativeWindow *getNativeWindow(); -extern void disposeNativeWindow(); - -#ifdef __cplusplus -} -#endif diff --git a/wilhelm/tests/sandbox/object.c b/wilhelm/tests/sandbox/object.c deleted file mode 100644 index 6c44700c..00000000 --- a/wilhelm/tests/sandbox/object.c +++ /dev/null @@ -1,181 +0,0 @@ -/* - * 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. - */ - -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <SLES/OpenSLES.h> -#include "OpenSLESUT.h" - -int main(int arg, char **argv) -{ - SLresult result; - - printf("Create engine\n"); - SLObjectItf engineObject; - // create engine - result = slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL); - assert(SL_RESULT_SUCCESS == result); - result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - SLEngineItf engineEngine; - result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine); - assert(SL_RESULT_SUCCESS == result); - SLuint32 i; - // loop through both valid and invalid object IDs - SLuint32 objectID; - // Test object IDs from one less than the first valid object - // ID, up to one more than the last valid object ID. This way - // we can test for both valid and invalid object IDs at both - // ends. If more objects are added, be sure to update the macros. -#define FIRST_VALID SL_OBJECTID_ENGINE -#define LAST_VALID SL_OBJECTID_METADATAEXTRACTOR - for (objectID = FIRST_VALID - 1; objectID <= LAST_VALID + 1; ++objectID) { - printf("object ID %x", objectID); - const char *string = slesutObjectIDToString(objectID); - if (NULL != string) - printf(" (%s)", string); - printf(":\n"); - result = (*engineEngine)->QueryNumSupportedInterfaces(engineEngine, objectID, NULL); - assert(SL_RESULT_PARAMETER_INVALID == result); - SLuint32 numSupportedInterfaces = 12345; - result = (*engineEngine)->QueryNumSupportedInterfaces(engineEngine, objectID, - &numSupportedInterfaces); - SLInterfaceID interfaceID; - if (SL_RESULT_FEATURE_UNSUPPORTED == result) { - printf(" unsupported\n"); - result = (*engineEngine)->QuerySupportedInterfaces(engineEngine, objectID, 0, - &interfaceID); - assert(SL_RESULT_FEATURE_UNSUPPORTED == result); - assert(NULL == interfaceID); - continue; - } - assert(SL_RESULT_SUCCESS == result); - printf("numSupportedInterfaces %u\n", numSupportedInterfaces); - for (i = 0; i < numSupportedInterfaces + 1; ++i) { - result = (*engineEngine)->QuerySupportedInterfaces(engineEngine, objectID, i, NULL); - assert(SL_RESULT_PARAMETER_INVALID == result); - result = (*engineEngine)->QuerySupportedInterfaces(engineEngine, objectID, i, - &interfaceID); - if (i < numSupportedInterfaces) { - assert(SL_RESULT_SUCCESS == result); - printf(" interface %u ", i); - slesutPrintIID(interfaceID); - } else { - assert(SL_RESULT_PARAMETER_INVALID == result); - } - } - } - // query number of extensions - result = (*engineEngine)->QueryNumSupportedExtensions(engineEngine, NULL); - assert(SL_RESULT_PARAMETER_INVALID == result); - SLuint32 numExtensions = 0x12345; - result = (*engineEngine)->QueryNumSupportedExtensions(engineEngine, &numExtensions); - assert(SL_RESULT_SUCCESS == result); - printf("numExtensions = %u\n", numExtensions); - // query names of the extensions - for (i = 0; i < numExtensions + 1; ++i) { - SLchar extensionName[32]; - result = (*engineEngine)->QuerySupportedExtension(engineEngine, i, extensionName, NULL); - assert(SL_RESULT_PARAMETER_INVALID == result); - SLint16 nameLength = -1; - result = (*engineEngine)->QuerySupportedExtension(engineEngine, i, NULL, &nameLength); - if (i < numExtensions) { - assert(SL_RESULT_SUCCESS == result); - printf(" extension[%u] length = %u\n", i, nameLength); - } else { - assert(SL_RESULT_PARAMETER_INVALID == result); - assert(0 == nameLength); - } - memset(extensionName, 'X', sizeof(extensionName)); - nameLength = -1; - result = (*engineEngine)->QuerySupportedExtension(engineEngine, i, extensionName, - &nameLength); - if (i < numExtensions) { - assert(SL_RESULT_BUFFER_INSUFFICIENT == result); - } else { - assert(SL_RESULT_PARAMETER_INVALID == result); - } - assert('X' == extensionName[0]); - nameLength = 0; - result = (*engineEngine)->QuerySupportedExtension(engineEngine, i, extensionName, - &nameLength); - if (i < numExtensions) { - assert(SL_RESULT_BUFFER_INSUFFICIENT == result); - } else { - assert(SL_RESULT_PARAMETER_INVALID == result); - } - assert('X' == extensionName[0]); - nameLength = 1; - result = (*engineEngine)->QuerySupportedExtension(engineEngine, i, extensionName, - &nameLength); - if (i < numExtensions) { - assert(SL_RESULT_BUFFER_INSUFFICIENT == result); - assert('\0' == extensionName[0]); - } else { - assert(SL_RESULT_PARAMETER_INVALID == result); - } - assert('X' == extensionName[1]); - nameLength = sizeof(extensionName); - result = (*engineEngine)->QuerySupportedExtension(engineEngine, i, extensionName, - &nameLength); - if (i < numExtensions) { - assert(SL_RESULT_SUCCESS == result); - assert((1 <= nameLength) && (nameLength <= (SLint16) sizeof(extensionName))); - printf(" extension[%u] = \"%.*s\"\n", i, nameLength, extensionName); - } else { - assert(SL_RESULT_PARAMETER_INVALID == result); - assert(0 == nameLength); - } - } - // check if extension is supported - SLboolean isSupported = SL_BOOLEAN_TRUE; - result = (*engineEngine)->IsExtensionSupported(engineEngine, NULL, &isSupported); - assert(SL_RESULT_PARAMETER_INVALID == result); - assert(SL_BOOLEAN_FALSE == isSupported); - SLchar *unsupportedExt = (SLchar *) "fish"; - result = (*engineEngine)->IsExtensionSupported(engineEngine, unsupportedExt, NULL); - assert(SL_RESULT_PARAMETER_INVALID == result); - isSupported = SL_BOOLEAN_TRUE; - result = (*engineEngine)->IsExtensionSupported(engineEngine, unsupportedExt, &isSupported); - assert(SL_RESULT_SUCCESS == result); - assert(SL_BOOLEAN_FALSE == isSupported); - SLchar *supportedExt; -#ifdef ANDROID - // whereas the implementation uses PLATFORM_SDK_VERSION, use a hard-coded value here - // so that we're actually testing for a particular expected value - supportedExt = (SLchar *) "ANDROID_SDK_LEVEL_13"; -#else - supportedExt = (SLchar *) "WILHELM_DESKTOP"; -#endif - isSupported = SL_BOOLEAN_FALSE; - result = (*engineEngine)->IsExtensionSupported(engineEngine, supportedExt, &isSupported); - assert(SL_RESULT_SUCCESS == result); - assert(SL_BOOLEAN_TRUE == isSupported); - // create an extension object with no place to put the new object - result = (*engineEngine)->CreateExtensionObject(engineEngine, NULL, NULL, 0x123, 0, NULL, NULL); - assert(SL_RESULT_PARAMETER_INVALID == result); - // create an extension object, which is unsupported - SLObjectItf extensionObject; - result = (*engineEngine)->CreateExtensionObject(engineEngine, &extensionObject, NULL, 0x123, 0, - NULL, NULL); - assert(SL_RESULT_FEATURE_UNSUPPORTED == result); - assert(NULL == extensionObject); - // destroy engine - (*engineObject)->Destroy(engineObject); - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/sandbox/outputmix.c b/wilhelm/tests/sandbox/outputmix.c deleted file mode 100644 index 0e8263e3..00000000 --- a/wilhelm/tests/sandbox/outputmix.c +++ /dev/null @@ -1,198 +0,0 @@ -/* - * 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. - */ - -// output mix interface tests - -#include <SLES/OpenSLES.h> -#include "OpenSLESUT.h" -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -int main(int argc, char **argv) -{ - // create engine - SLObjectItf engineObject; - SLresult result; - result = slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL); - assert(SL_RESULT_SUCCESS == result); - printf("Engine object %p\n", engineObject); - // realize engine - result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - // get engine interface - SLEngineItf engineEngine; - result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine); - assert(SL_RESULT_SUCCESS == result); - // query supported interfaces on output mix object ID and display their IDs - SLuint32 numSupportedInterfaces; - result = (*engineEngine)->QueryNumSupportedInterfaces(engineEngine, SL_OBJECTID_OUTPUTMIX, - &numSupportedInterfaces); - assert(SL_RESULT_SUCCESS == result); - printf("Output mix supports %u interfaces:\n", numSupportedInterfaces); - SLuint32 i; - for (i = 0; i < numSupportedInterfaces; ++i) { - SLInterfaceID interfaceID; - result = (*engineEngine)->QuerySupportedInterfaces(engineEngine, SL_OBJECTID_OUTPUTMIX, i, - &interfaceID); - assert(SL_RESULT_SUCCESS == result); - printf(" [%u] = ", i); - slesutPrintIID(interfaceID); - } - // create output mix, with no place to put the new object - result = (*engineEngine)->CreateOutputMix(engineEngine, NULL, 0, NULL, NULL); - assert(SL_RESULT_PARAMETER_INVALID == result); - // create output mix, requesting no explicit interfaces - SLObjectItf outputMixObject; - result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 0, NULL, NULL); - assert(SL_RESULT_SUCCESS == result); - printf("Output mix object %p\n", outputMixObject); - // get object interface before realization - SLObjectItf outputMixObject2; - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_OBJECT, &outputMixObject2); - assert(SL_RESULT_SUCCESS == result); - assert(outputMixObject2 == outputMixObject); - // get any other interface before realization should fail - SLOutputMixItf outputMixOutputMix; - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_OUTPUTMIX, - &outputMixOutputMix); - assert(SL_RESULT_PRECONDITIONS_VIOLATED == result); - // realize the output mix - result = (*outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - // get each expected implicit interface - outputMixObject2 = NULL; - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_OBJECT, &outputMixObject2); - assert(SL_RESULT_SUCCESS == result); - assert(outputMixObject2 == outputMixObject); - SLDynamicInterfaceManagementItf outputMixDynamicInterfaceManagement; - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_DYNAMICINTERFACEMANAGEMENT, - &outputMixDynamicInterfaceManagement); - assert((SL_RESULT_SUCCESS == result) || (SL_RESULT_FEATURE_UNSUPPORTED) == result); - if (SL_RESULT_SUCCESS == result) { - printf("Output mix supports dynamic interface management\n"); - } else { - printf("Output mix does not support dynamic interface management\n"); - } - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_OUTPUTMIX, - &outputMixOutputMix); - assert(SL_RESULT_SUCCESS == result); - // get explicit and optional interfaces should fail since not requested at creation - SLEnvironmentalReverbItf outputMixEnvironmentalReverb; - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_ENVIRONMENTALREVERB, - &outputMixEnvironmentalReverb); - assert(SL_RESULT_FEATURE_UNSUPPORTED == result); - SLEqualizerItf outputMixEqualizer; - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_EQUALIZER, - &outputMixEqualizer); - assert(SL_RESULT_FEATURE_UNSUPPORTED == result); - SLPresetReverbItf outputMixPresetReverb; - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_PRESETREVERB, - &outputMixPresetReverb); - assert(SL_RESULT_FEATURE_UNSUPPORTED == result); - SLVirtualizerItf outputMixVirtualizer; - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_VIRTUALIZER, - &outputMixVirtualizer); - assert(SL_RESULT_FEATURE_UNSUPPORTED == result); - SLVolumeItf outputMixVolume; - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_VOLUME, - &outputMixVolume); - assert(SL_RESULT_FEATURE_UNSUPPORTED == result); - SLBassBoostItf outputMixBassBoost; - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_BASSBOOST, - &outputMixBassBoost); - assert(SL_RESULT_FEATURE_UNSUPPORTED == result); - SLVisualizationItf outputMixVisualization; - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_VISUALIZATION, - &outputMixVisualization); - assert(SL_RESULT_FEATURE_UNSUPPORTED == result); - // destroy output mix - (*outputMixObject)->Destroy(outputMixObject); - // re-create output mix, this time requesting implicit interfaces as "hard" requirements (must - // be there), and explicit interfaces as "soft" requirements (OK if not available) - SLInterfaceID ids[10] = {SL_IID_OBJECT, SL_IID_DYNAMICINTERFACEMANAGEMENT, SL_IID_OUTPUTMIX, - SL_IID_ENVIRONMENTALREVERB, SL_IID_EQUALIZER, SL_IID_PRESETREVERB, SL_IID_VIRTUALIZER, - SL_IID_VOLUME, SL_IID_BASSBOOST, SL_IID_VISUALIZATION}; - SLboolean req[10] = {SL_BOOLEAN_TRUE, SL_BOOLEAN_FALSE /*SL_BOOLEAN_TRUE*/, SL_BOOLEAN_TRUE, - SL_BOOLEAN_TRUE/*FALSE*/, SL_BOOLEAN_FALSE, SL_BOOLEAN_FALSE, SL_BOOLEAN_FALSE, - SL_BOOLEAN_FALSE, SL_BOOLEAN_FALSE, SL_BOOLEAN_FALSE}; - result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 10, ids, req); - assert(SL_RESULT_SUCCESS == result); - printf("Output mix object %p\n", outputMixObject); - // realize the output mix - result = (*outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - // get implicit interfaces - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_OBJECT, - &outputMixObject2); - assert(SL_RESULT_SUCCESS == result); - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_DYNAMICINTERFACEMANAGEMENT, - &outputMixDynamicInterfaceManagement); - assert((SL_RESULT_SUCCESS == result) || (SL_RESULT_FEATURE_UNSUPPORTED) == result); - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_OUTPUTMIX, - &outputMixOutputMix); - assert(SL_RESULT_SUCCESS == result); - // get explicit and optional interfaces should succeed since they were requested at creation - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_ENVIRONMENTALREVERB, - &outputMixEnvironmentalReverb); - assert(SL_RESULT_SUCCESS == result); - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_EQUALIZER, - &outputMixEqualizer); - assert(SL_RESULT_SUCCESS == result); - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_PRESETREVERB, - &outputMixPresetReverb); - assert(SL_RESULT_SUCCESS == result); - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_VIRTUALIZER, - &outputMixVirtualizer); - assert(SL_RESULT_SUCCESS == result); - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_VOLUME, - &outputMixVolume); - assert((SL_RESULT_SUCCESS == result) || (SL_RESULT_FEATURE_UNSUPPORTED) == result); - if (SL_RESULT_SUCCESS == result) { - printf("Output mix supports volume\n"); - } else { - printf("Output mix does not support volume\n"); - } - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_BASSBOOST, - &outputMixBassBoost); - assert(SL_RESULT_SUCCESS == result); - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_VISUALIZATION, - &outputMixVisualization); - assert((SL_RESULT_SUCCESS == result) || (SL_RESULT_FEATURE_UNSUPPORTED) == result); - if (SL_RESULT_SUCCESS == result) { - printf("Output mix supports visualization\n"); - } else { - printf("Output mix does not support visualization\n"); - } - // use the OutputMix interface on output mix object, in order to get code coverage - SLint32 numDevices = 1; - SLuint32 deviceIDs[1]; - result = (*outputMixOutputMix)->GetDestinationOutputDeviceIDs(outputMixOutputMix, &numDevices, - deviceIDs); - assert(SL_RESULT_SUCCESS == result); - assert(1 == numDevices); - assert(SL_DEFAULTDEVICEID_AUDIOOUTPUT == deviceIDs[0]); - result = (*outputMixOutputMix)->RegisterDeviceChangeCallback(outputMixOutputMix, NULL, NULL); - assert(SL_RESULT_SUCCESS == result); - result = (*outputMixOutputMix)->ReRoute(outputMixOutputMix, 1, deviceIDs); - assert(SL_RESULT_SUCCESS == result); - // destroy output mix - (*outputMixObject)->Destroy(outputMixObject); - // destroy engine - (*engineObject)->Destroy(engineObject); - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/sandbox/playbq.c b/wilhelm/tests/sandbox/playbq.c deleted file mode 100644 index c0f71a7a..00000000 --- a/wilhelm/tests/sandbox/playbq.c +++ /dev/null @@ -1,464 +0,0 @@ -/* - * 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. - */ - -// Play an audio file using buffer queue - -#include <assert.h> -#include <math.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> -#include <unistd.h> - -#include <SLES/OpenSLES.h> -#ifdef ANDROID -#include "sndfile.h" -#else -#include <sndfile.h> -#endif - -#define max(a, b) ((a) > (b) ? (a) : (b)) -#define min(a, b) ((a) < (b) ? (a) : (b)) - -unsigned numBuffers = 2; -int framesPerBuffer = 512; -SNDFILE *sndfile; -SF_INFO sfinfo; -unsigned which; // which buffer to use next -SLboolean eof; // whether we have hit EOF on input yet -short *buffers; -SLuint32 byteOrder; // desired to use for PCM buffers -SLuint32 nativeByteOrder; // of platform -SLuint32 bitsPerSample = 16; - -// swap adjacent bytes; this would normally be in <unistd.h> but is missing here -static void swab(const void *from, void *to, ssize_t n) -{ - // from and to as char pointers - const char *from_ch = (const char *) from; - char *to_ch = (char *) to; - // note that we don't swap the last odd byte - while (n >= 2) { - to_ch[0] = from_ch[1]; - to_ch[1] = from_ch[0]; - to_ch += 2; - from_ch += 2; - n -= 2; - } -} - -// squeeze 16-bit signed PCM samples down to 8-bit unsigned PCM samples by truncation; no dithering -static void squeeze(const short *from, unsigned char *to, ssize_t n) -{ - // note that we don't squeeze the last odd byte - while (n >= 2) { - *to++ = (*from++ + 32768) >> 8; - n -= 2; - } -} - -// This callback is called each time a buffer finishes playing - -static void callback(SLBufferQueueItf bufq, void *param) -{ - assert(NULL == param); - if (!eof) { - short *buffer = &buffers[framesPerBuffer * sfinfo.channels * which]; - sf_count_t count; - count = sf_readf_short(sndfile, buffer, (sf_count_t) framesPerBuffer); - if (0 >= count) { - eof = SL_BOOLEAN_TRUE; - } else { - SLuint32 nbytes = count * sfinfo.channels * sizeof(short); - if (byteOrder != nativeByteOrder) { - swab(buffer, buffer, nbytes); - } - if (bitsPerSample == 8) { - squeeze(buffer, (unsigned char *) buffer, nbytes); - nbytes /= 2; - } - SLresult result = (*bufq)->Enqueue(bufq, buffer, nbytes); - assert(SL_RESULT_SUCCESS == result); - if (++which >= numBuffers) - which = 0; - } - } -} - -int main(int argc, char **argv) -{ - // Determine the native byte order (SL_BYTEORDER_NATIVE not available until 1.1) - union { - short s; - char c[2]; - } u; - u.s = 0x1234; - if (u.c[0] == 0x34) { - nativeByteOrder = SL_BYTEORDER_LITTLEENDIAN; - } else if (u.c[0] == 0x12) { - nativeByteOrder = SL_BYTEORDER_BIGENDIAN; - } else { - fprintf(stderr, "Unable to determine native byte order\n"); - return EXIT_FAILURE; - } - byteOrder = nativeByteOrder; - - SLboolean enableReverb = SL_BOOLEAN_FALSE; - SLpermille initialRate = 0; - SLpermille finalRate = 0; - SLpermille deltaRate = 1; - SLmillisecond deltaRateMs = 0; - - // process command-line options - int i; - for (i = 1; i < argc; ++i) { - char *arg = argv[i]; - if (arg[0] != '-') { - break; - } - if (!strcmp(arg, "-b")) { - byteOrder = SL_BYTEORDER_BIGENDIAN; - } else if (!strcmp(arg, "-l")) { - byteOrder = SL_BYTEORDER_LITTLEENDIAN; - } else if (!strcmp(arg, "-8")) { - bitsPerSample = 8; - } else if (!strncmp(arg, "-f", 2)) { - framesPerBuffer = atoi(&arg[2]); - } else if (!strncmp(arg, "-n", 2)) { - numBuffers = atoi(&arg[2]); - } else if (!strncmp(arg, "-p", 2)) { - initialRate = atoi(&arg[2]); - } else if (!strncmp(arg, "-P", 2)) { - finalRate = atoi(&arg[2]); - } else if (!strncmp(arg, "-q", 2)) { - deltaRate = atoi(&arg[2]); - // deltaRate is a magnitude, so take absolute value - if (deltaRate < 0) { - deltaRate = -deltaRate; - } - } else if (!strncmp(arg, "-Q", 2)) { - deltaRateMs = atoi(&arg[2]); - } else if (!strcmp(arg, "-r")) { - enableReverb = SL_BOOLEAN_TRUE; - } else { - fprintf(stderr, "option %s ignored\n", arg); - } - } - - if (argc - i != 1) { - fprintf(stderr, "usage: [-b/l] [-8] [-f#] [-n#] [-p#] [-r] %s filename\n", argv[0]); - fprintf(stderr, " -b force big-endian byte order (default is native byte order)\n"); - fprintf(stderr, " -l force little-endian byte order (default is native byte order)\n"); - fprintf(stderr, " -8 output 8-bits per sample (default is 16-bits per sample)\n"); - fprintf(stderr, " -f# frames per buffer (default 512)\n"); - fprintf(stderr, " -n# number of buffers (default 2)\n"); - fprintf(stderr, " -p# initial playback rate in per mille (default 1000)\n"); - fprintf(stderr, " -P# final playback rate in per mille (default same as -p#)\n"); - fprintf(stderr, " -q# magnitude of playback rate changes in per mille (default 1)\n"); - fprintf(stderr, " -Q# period between playback rate changes in ms (default 50)\n"); - fprintf(stderr, " -r enable reverb (default disabled)\n"); - return EXIT_FAILURE; - } - - const char *filename = argv[i]; - //memset(&sfinfo, 0, sizeof(SF_INFO)); - sfinfo.format = 0; - sndfile = sf_open(filename, SFM_READ, &sfinfo); - if (NULL == sndfile) { - perror(filename); - return EXIT_FAILURE; - } - - // verify the file format - switch (sfinfo.channels) { - case 1: - case 2: - break; - default: - fprintf(stderr, "unsupported channel count %d\n", sfinfo.channels); - goto close_sndfile; - } - - switch (sfinfo.samplerate) { - case 8000: - case 11025: - case 12000: - case 16000: - case 22050: - case 24000: - case 32000: - case 44100: - case 48000: - break; - default: - fprintf(stderr, "unsupported sample rate %d\n", sfinfo.samplerate); - goto close_sndfile; - } - - switch (sfinfo.format & SF_FORMAT_TYPEMASK) { - case SF_FORMAT_WAV: - break; - default: - fprintf(stderr, "unsupported format type 0x%x\n", sfinfo.format & SF_FORMAT_TYPEMASK); - goto close_sndfile; - } - - switch (sfinfo.format & SF_FORMAT_SUBMASK) { - case SF_FORMAT_PCM_16: - case SF_FORMAT_PCM_U8: - case SF_FORMAT_ULAW: - case SF_FORMAT_ALAW: - case SF_FORMAT_IMA_ADPCM: - break; - default: - fprintf(stderr, "unsupported sub-format 0x%x\n", sfinfo.format & SF_FORMAT_SUBMASK); - goto close_sndfile; - } - - buffers = (short *) malloc(framesPerBuffer * sfinfo.channels * sizeof(short) * numBuffers); - - // create engine - SLresult result; - SLObjectItf engineObject; - result = slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL); - assert(SL_RESULT_SUCCESS == result); - SLEngineItf engineEngine; - result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine); - assert(SL_RESULT_SUCCESS == result); - - // create output mix - SLObjectItf outputMixObject; - SLInterfaceID ids[1] = {SL_IID_ENVIRONMENTALREVERB}; - SLboolean req[1] = {SL_BOOLEAN_TRUE}; - result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, enableReverb ? 1 : 0, - ids, req); - assert(SL_RESULT_SUCCESS == result); - result = (*outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - - // configure environmental reverb on output mix - SLEnvironmentalReverbItf mixEnvironmentalReverb = NULL; - if (enableReverb) { - result = (*outputMixObject)->GetInterface(outputMixObject, SL_IID_ENVIRONMENTALREVERB, - &mixEnvironmentalReverb); - assert(SL_RESULT_SUCCESS == result); - SLEnvironmentalReverbSettings settings = SL_I3DL2_ENVIRONMENT_PRESET_STONECORRIDOR; - result = (*mixEnvironmentalReverb)->SetEnvironmentalReverbProperties(mixEnvironmentalReverb, - &settings); - assert(SL_RESULT_SUCCESS == result); - } - - // configure audio source - SLDataLocator_BufferQueue loc_bufq; - loc_bufq.locatorType = SL_DATALOCATOR_BUFFERQUEUE; - loc_bufq.numBuffers = numBuffers; - SLDataFormat_PCM format_pcm; - format_pcm.formatType = SL_DATAFORMAT_PCM; - format_pcm.numChannels = sfinfo.channels; - format_pcm.samplesPerSec = sfinfo.samplerate * 1000; - format_pcm.bitsPerSample = bitsPerSample; - format_pcm.containerSize = format_pcm.bitsPerSample; - format_pcm.channelMask = 1 == format_pcm.numChannels ? SL_SPEAKER_FRONT_CENTER : - SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT; - format_pcm.endianness = byteOrder; - SLDataSource audioSrc; - audioSrc.pLocator = &loc_bufq; - audioSrc.pFormat = &format_pcm; - - // configure audio sink - SLDataLocator_OutputMix loc_outmix; - loc_outmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; - loc_outmix.outputMix = outputMixObject; - SLDataSink audioSnk; - audioSnk.pLocator = &loc_outmix; - audioSnk.pFormat = NULL; - - // create audio player - SLInterfaceID ids2[3] = {SL_IID_BUFFERQUEUE, SL_IID_PLAYBACKRATE, SL_IID_EFFECTSEND}; - SLboolean req2[3] = {SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE}; - SLObjectItf playerObject; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audioSrc, - &audioSnk, enableReverb ? 3 : 2, ids2, req2); - if (SL_RESULT_SUCCESS != result) { - fprintf(stderr, "can't create audio player\n"); - goto no_player; - } - - // realize the player - result = (*playerObject)->Realize(playerObject, SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - - // get the effect send interface and enable effect send reverb for this player - if (enableReverb) { - SLEffectSendItf playerEffectSend; - result = (*playerObject)->GetInterface(playerObject, SL_IID_EFFECTSEND, &playerEffectSend); - assert(SL_RESULT_SUCCESS == result); - result = (*playerEffectSend)->EnableEffectSend(playerEffectSend, mixEnvironmentalReverb, - SL_BOOLEAN_TRUE, (SLmillibel) 0); - assert(SL_RESULT_SUCCESS == result); - } - - // get the playback rate interface and configure the rate - SLPlaybackRateItf playerPlaybackRate; - result = (*playerObject)->GetInterface(playerObject, SL_IID_PLAYBACKRATE, &playerPlaybackRate); - assert(SL_RESULT_SUCCESS == result); - SLpermille defaultRate; - result = (*playerPlaybackRate)->GetRate(playerPlaybackRate, &defaultRate); - assert(SL_RESULT_SUCCESS == result); - SLuint32 defaultProperties; - result = (*playerPlaybackRate)->GetProperties(playerPlaybackRate, &defaultProperties); - assert(SL_RESULT_SUCCESS == result); - printf("default playback rate %d per mille, properties 0x%x\n", defaultRate, defaultProperties); - if (initialRate <= 0) { - initialRate = defaultRate; - } - if (finalRate <= 0) { - finalRate = initialRate; - } - SLpermille currentRate = defaultRate; - if (finalRate == initialRate) { - deltaRate = 0; - } else if (finalRate < initialRate) { - deltaRate = -deltaRate; - } - if (initialRate != defaultRate) { - result = (*playerPlaybackRate)->SetRate(playerPlaybackRate, initialRate); - if (SL_RESULT_FEATURE_UNSUPPORTED == result) { - fprintf(stderr, "initial playback rate %d is unsupported\n", initialRate); - deltaRate = 0; - } else if (SL_RESULT_PARAMETER_INVALID == result) { - fprintf(stderr, "initial playback rate %d is invalid\n", initialRate); - deltaRate = 0; - } else { - assert(SL_RESULT_SUCCESS == result); - currentRate = initialRate; - } - } - - // get the play interface - SLPlayItf playerPlay; - result = (*playerObject)->GetInterface(playerObject, SL_IID_PLAY, &playerPlay); - assert(SL_RESULT_SUCCESS == result); - - // get the buffer queue interface - SLBufferQueueItf playerBufferQueue; - result = (*playerObject)->GetInterface(playerObject, SL_IID_BUFFERQUEUE, - &playerBufferQueue); - assert(SL_RESULT_SUCCESS == result); - - // loop until EOF or no more buffers - for (which = 0; which < numBuffers; ++which) { - short *buffer = &buffers[framesPerBuffer * sfinfo.channels * which]; - sf_count_t frames = framesPerBuffer; - sf_count_t count; - count = sf_readf_short(sndfile, buffer, frames); - if (0 >= count) { - eof = SL_BOOLEAN_TRUE; - break; - } - - // enqueue a buffer - SLuint32 nbytes = count * sfinfo.channels * sizeof(short); - if (byteOrder != nativeByteOrder) { - swab(buffer, buffer, nbytes); - } - if (bitsPerSample == 8) { - squeeze(buffer, (unsigned char *) buffer, nbytes); - nbytes /= 2; - } - result = (*playerBufferQueue)->Enqueue(playerBufferQueue, buffer, nbytes); - assert(SL_RESULT_SUCCESS == result); - } - if (which >= numBuffers) { - which = 0; - } - - // register a callback on the buffer queue - result = (*playerBufferQueue)->RegisterCallback(playerBufferQueue, callback, NULL); - assert(SL_RESULT_SUCCESS == result); - - // set the player's state to playing - result = (*playerPlay)->SetPlayState(playerPlay, SL_PLAYSTATE_PLAYING); - assert(SL_RESULT_SUCCESS == result); - - // get the initial time - struct timespec prevTs; - clock_gettime(CLOCK_MONOTONIC, &prevTs); - long elapsedNs = 0; - long deltaRateNs = deltaRateMs * 1000000; - - // wait until the buffer queue is empty - SLBufferQueueState bufqstate; - for (;;) { - result = (*playerBufferQueue)->GetState(playerBufferQueue, &bufqstate); - assert(SL_RESULT_SUCCESS == result); - if (0 >= bufqstate.count) { - break; - } - if (deltaRate == 0) { - sleep(1); - } else { - struct timespec curTs; - clock_gettime(CLOCK_MONOTONIC, &curTs); - elapsedNs += (curTs.tv_sec - prevTs.tv_sec) * 1000000000 + - // this term can be negative - (curTs.tv_nsec - prevTs.tv_nsec); - prevTs = curTs; - if (elapsedNs < deltaRateNs) { - usleep((deltaRateNs - elapsedNs) / 1000); - continue; - } - elapsedNs -= deltaRateNs; - SLpermille nextRate = currentRate + deltaRate; - result = (*playerPlaybackRate)->SetRate(playerPlaybackRate, nextRate); - if (SL_RESULT_SUCCESS != result) { - fprintf(stderr, "next playback rate %d is unsupported\n", nextRate); - } else if (SL_RESULT_PARAMETER_INVALID == result) { - fprintf(stderr, "next playback rate %d is invalid\n", nextRate); - } else { - assert(SL_RESULT_SUCCESS == result); - } - currentRate = nextRate; - if (currentRate >= max(initialRate, finalRate)) { - currentRate = max(initialRate, finalRate); - deltaRate = -abs(deltaRate); - } else if (currentRate <= min(initialRate, finalRate)) { - currentRate = min(initialRate, finalRate); - deltaRate = abs(deltaRate); - } - } - } - - // destroy audio player - (*playerObject)->Destroy(playerObject); - -no_player: - - // destroy output mix - (*outputMixObject)->Destroy(outputMixObject); - - // destroy engine - (*engineObject)->Destroy(engineObject); - -close_sndfile: - - (void) sf_close(sndfile); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/sandbox/reverb.c b/wilhelm/tests/sandbox/reverb.c deleted file mode 100644 index 86ea6689..00000000 --- a/wilhelm/tests/sandbox/reverb.c +++ /dev/null @@ -1,664 +0,0 @@ -/* - * 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. - */ - -// Demonstrate environmental reverb and preset reverb on an output mix and audio player - -#include <SLES/OpenSLES.h> -#include <assert.h> -#include <pthread.h> -#include <string.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> - -#define bool int -#define false 0 -#define true 1 - -// Table of I3DL2 named environmental reverb settings - -typedef struct { - const char *mName; - SLEnvironmentalReverbSettings mSettings; -} Pair; - -#define _(name) {#name, SL_I3DL2_ENVIRONMENT_PRESET_##name}, - -Pair pairs[] = { - _(DEFAULT) - _(GENERIC) - _(PADDEDCELL) - _(ROOM) - _(BATHROOM) - _(LIVINGROOM) - _(STONEROOM) - _(AUDITORIUM) - _(CONCERTHALL) - _(CAVE) - _(ARENA) - _(HANGAR) - _(CARPETEDHALLWAY) - _(HALLWAY) - _(STONECORRIDOR) - _(ALLEY) - _(FOREST) - _(CITY) - _(MOUNTAINS) - _(QUARRY) - _(PLAIN) - _(PARKINGLOT) - _(SEWERPIPE) - _(UNDERWATER) - _(SMALLROOM) - _(MEDIUMROOM) - _(LARGEROOM) - _(MEDIUMHALL) - _(LARGEHALL) - _(PLATE) -}; - -// Parameters for preset reverb on output mix -bool outputMixPresetItfRequested = false; -SLuint16 outputMixPresetNumber = ~0; - -// Parameters for environmental reverb on output mix -bool outputMixEnvironmentalItfRequested = false; -char *outputMixEnvironmentalName = NULL; -SLEnvironmentalReverbSettings outputMixEnvironmentalSettings; - -// Parameters for preset reverb on audio player (not supported) -bool playerPresetItfRequested = false; -SLuint16 playerPresetNumber = ~0; - -// Parameters for environmental reverb on audio player (not supported) -bool playerEnvironmentalItfRequested = false; -char *playerEnvironmentalName = NULL; -SLEnvironmentalReverbSettings playerEnvironmentalSettings; - -// Compare two environmental reverb settings structures. -// Returns true if the settings are identical, or false if they are different. - -bool slesutCompareEnvironmentalReverbSettings( - const SLEnvironmentalReverbSettings *settings1, - const SLEnvironmentalReverbSettings *settings2) -{ - return - (settings1->roomLevel == settings2->roomLevel) && - (settings1->roomHFLevel == settings2->roomHFLevel) && - (settings1->decayTime == settings2->decayTime) && - (settings1->decayHFRatio == settings2->decayHFRatio) && - (settings1->reflectionsLevel == settings2->reflectionsLevel) && - (settings1->reflectionsDelay == settings2->reflectionsDelay) && - (settings1->reverbLevel == settings2->reverbLevel) && - (settings1->reverbDelay == settings2->reverbDelay) && - (settings1->diffusion == settings2->diffusion) && - (settings1->density == settings2->density); -} - -// Print an environmental reverb settings structure. - -void slesutPrintEnvironmentalReverbSettings(const SLEnvironmentalReverbSettings *settings) -{ - printf("roomLevel: %d\n", settings->roomLevel); - printf("roomHFLevel: %d\n", settings->roomHFLevel); - printf("decayTime: %d\n", settings->decayTime); - printf("decayHFRatio: %d\n", settings->decayHFRatio); - printf("reflectionsLevel: %d\n", settings->reflectionsLevel); - printf("reflectionsDelay: %d\n", settings->reflectionsDelay); - printf("reverbLevel: %d\n", settings->reverbLevel); - printf("reverbDelay: %d\n", settings->reverbDelay); - printf("diffusion: %d\n", settings->diffusion); - printf("density: %d\n", settings->density); -} - -// Lookup environmental reverb settings by name - -const SLEnvironmentalReverbSettings *lookupEnvName(const char *name) -{ - unsigned j; - for (j = 0; j < sizeof(pairs) / sizeof(pairs[0]); ++j) { - if (!strcasecmp(name, pairs[j].mName)) { - return &pairs[j].mSettings; - } - } - return NULL; -} - -// Print all available environmental reverb names - -void printEnvNames(void) -{ - unsigned j; - bool needSpace = false; - bool needNewline = false; - unsigned lineLen = 0; - for (j = 0; j < sizeof(pairs) / sizeof(pairs[0]); ++j) { - const char *name = pairs[j].mName; - unsigned nameLen = strlen(name); - if (lineLen + (needSpace ? 1 : 0) + nameLen > 72) { - putchar('\n'); - needSpace = false; - needNewline = false; - lineLen = 0; - } - if (needSpace) { - putchar(' '); - ++lineLen; - } - fputs(name, stdout); - lineLen += nameLen; - needSpace = true; - needNewline = true; - } - if (needNewline) { - putchar('\n'); - } -} - -// These are extensions to OpenSL ES 1.0.1 values - -#define SL_PREFETCHSTATUS_UNKNOWN 0 -#define SL_PREFETCHSTATUS_ERROR (-1) - -// Mutex and condition shared with main program to protect prefetch_status - -static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; -SLuint32 prefetch_status = SL_PREFETCHSTATUS_UNKNOWN; - -/* used to detect errors likely to have occured when the OpenSL ES framework fails to open - * a resource, for instance because a file URI is invalid, or an HTTP server doesn't respond. - */ -#define PREFETCHEVENT_ERROR_CANDIDATE \ - (SL_PREFETCHEVENT_STATUSCHANGE | SL_PREFETCHEVENT_FILLLEVELCHANGE) - -// Prefetch status callback - -void prefetch_callback(SLPrefetchStatusItf caller, void *context, SLuint32 event) -{ - SLresult result; - assert(context == NULL); - SLpermille level; - result = (*caller)->GetFillLevel(caller, &level); - assert(SL_RESULT_SUCCESS == result); - SLuint32 status; - result = (*caller)->GetPrefetchStatus(caller, &status); - assert(SL_RESULT_SUCCESS == result); - SLuint32 new_prefetch_status; - if ((event & PREFETCHEVENT_ERROR_CANDIDATE) == PREFETCHEVENT_ERROR_CANDIDATE - && level == 0 && status == SL_PREFETCHSTATUS_UNDERFLOW) { - new_prefetch_status = SL_PREFETCHSTATUS_ERROR; - } else if (event == SL_PREFETCHEVENT_STATUSCHANGE && - status == SL_PREFETCHSTATUS_SUFFICIENTDATA) { - new_prefetch_status = status; - } else { - return; - } - int ok; - ok = pthread_mutex_lock(&mutex); - assert(ok == 0); - prefetch_status = new_prefetch_status; - ok = pthread_cond_signal(&cond); - assert(ok == 0); - ok = pthread_mutex_unlock(&mutex); - assert(ok == 0); -} - -// Main program - -int main(int argc, char **argv) -{ - SLresult result; - bool loop = false; - - // process command line parameters - char *prog = argv[0]; - int i; - for (i = 1; i < argc; ++i) { - char *arg = argv[i]; - if (arg[0] != '-') - break; - bool bad = false; // whether the option string is invalid - if (!strncmp(arg, "--mix-preset", 12)) { - if ('\0' == arg[12]) { - outputMixPresetItfRequested = true; - } else if ('=' == arg[12]) { - outputMixPresetNumber = atoi(&arg[13]); - outputMixPresetItfRequested = true; - } else { - bad = true; - } - } else if (!strncmp(arg, "--mix-name", 10)) { - if ('\0' == arg[10]) { - outputMixEnvironmentalItfRequested = true; - } else if ('=' == arg[10]) { - outputMixEnvironmentalName = &arg[11]; - outputMixEnvironmentalItfRequested = true; - } else { - bad = true; - } - } else if (!strncmp(arg, "--player-preset", 15)) { - if ('\0' == arg[15]) { - playerPresetItfRequested = true; - } else if ('=' == arg[15]) { - playerPresetNumber = atoi(&arg[16]); - playerPresetItfRequested = true; - } else { - bad = true; - } - } else if (!strncmp(arg, "--player-name", 13)) { - if ('\0' == arg[13]) { - playerEnvironmentalItfRequested = true; - } else if ('=' == arg[13]) { - playerEnvironmentalName = &arg[14]; - playerEnvironmentalItfRequested = true; - } else { - bad = true; - } - } else if (!strcmp(arg, "--loop")) { - loop = true; - } else { - bad = true; - } - if (bad) { - fprintf(stderr, "%s: unknown option %s ignored\n", prog, arg); - } - } - if (argc - i != 1) { - fprintf(stderr, "usage: %s --mix-preset=# --mix-name=I3DL2 --player-preset=# " - "--player-name=I3DL2 --loop filename\n", prog); - return EXIT_FAILURE; - } - char *pathname = argv[i]; - - const SLEnvironmentalReverbSettings *envSettings; - if (NULL != outputMixEnvironmentalName) { - envSettings = lookupEnvName(outputMixEnvironmentalName); - if (NULL == envSettings) { - fprintf(stderr, "%s: output mix environmental reverb name %s not found, " - "available names are:\n", prog, outputMixEnvironmentalName); - printEnvNames(); - return EXIT_FAILURE; - } - outputMixEnvironmentalSettings = *envSettings; - } - if (NULL != playerEnvironmentalName) { - envSettings = lookupEnvName(playerEnvironmentalName); - if (NULL == envSettings) { - fprintf(stderr, "%s: player environmental reverb name %s not found, " - "available names are:\n", prog, playerEnvironmentalName); - printEnvNames(); - return EXIT_FAILURE; - } - playerEnvironmentalSettings = *envSettings; - } - - // create engine - SLObjectItf engineObject; - result = slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL); - assert(SL_RESULT_SUCCESS == result); - result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - SLEngineItf engineEngine; - result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine); - assert(SL_RESULT_SUCCESS == result); - - // create output mix - SLInterfaceID mix_ids[2]; - SLboolean mix_req[2]; - SLuint32 count = 0; - if (outputMixPresetItfRequested) { - mix_req[count] = SL_BOOLEAN_TRUE; - mix_ids[count++] = SL_IID_PRESETREVERB; - } - if (outputMixEnvironmentalItfRequested) { - mix_req[count] = SL_BOOLEAN_TRUE; - mix_ids[count++] = SL_IID_ENVIRONMENTALREVERB; - } - SLObjectItf mixObject; - result = (*engineEngine)->CreateOutputMix(engineEngine, &mixObject, count, mix_ids, mix_req); - assert(SL_RESULT_SUCCESS == result); - result = (*mixObject)->Realize(mixObject, SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - - // configure preset reverb on output mix - SLPresetReverbItf outputMixPresetReverb; - if (outputMixPresetItfRequested) { - result = (*mixObject)->GetInterface(mixObject, SL_IID_PRESETREVERB, &outputMixPresetReverb); - assert(SL_RESULT_SUCCESS == result); - SLuint16 getPresetReverb = 12345; - result = (*outputMixPresetReverb)->GetPreset(outputMixPresetReverb, &getPresetReverb); - assert(SL_RESULT_SUCCESS == result); - printf("Output mix default preset reverb number = %u\n", getPresetReverb); - if (outputMixPresetNumber != ((SLuint16) ~0)) { - result = (*outputMixPresetReverb)->SetPreset(outputMixPresetReverb, - outputMixPresetNumber); - if (SL_RESULT_SUCCESS == result) { - result = (*outputMixPresetReverb)->GetPreset(outputMixPresetReverb, - &getPresetReverb); - assert(SL_RESULT_SUCCESS == result); - assert(getPresetReverb == outputMixPresetNumber); - printf("Output mix preset reverb successfully changed to %u\n", - outputMixPresetNumber); - } else { - printf("Unable to set output mix preset reverb to %u, result=%u\n", - outputMixPresetNumber, result); - } - } - } - - // configure environmental reverb on output mix - SLEnvironmentalReverbItf outputMixEnvironmentalReverb; - if (outputMixEnvironmentalItfRequested) { - result = (*mixObject)->GetInterface(mixObject, SL_IID_ENVIRONMENTALREVERB, - &outputMixEnvironmentalReverb); - assert(SL_RESULT_SUCCESS == result); - SLEnvironmentalReverbSettings getSettings; - result = (*outputMixEnvironmentalReverb)->GetEnvironmentalReverbProperties( - outputMixEnvironmentalReverb, &getSettings); - assert(SL_RESULT_SUCCESS == result); - printf("Output mix default environmental reverb settings\n"); - printf("------------------------------------------------\n"); - slesutPrintEnvironmentalReverbSettings(&getSettings); - printf("\n"); - if (outputMixEnvironmentalName != NULL) { - result = (*outputMixEnvironmentalReverb)->SetEnvironmentalReverbProperties( - outputMixEnvironmentalReverb, &outputMixEnvironmentalSettings); - assert(SL_RESULT_SUCCESS == result); - printf("Output mix new environmental reverb settings\n"); - printf("--------------------------------------------\n"); - slesutPrintEnvironmentalReverbSettings(&outputMixEnvironmentalSettings); - printf("\n"); - result = (*outputMixEnvironmentalReverb)->GetEnvironmentalReverbProperties( - outputMixEnvironmentalReverb, &getSettings); - assert(SL_RESULT_SUCCESS == result); - printf("Output mix read environmental reverb settings\n"); - printf("--------------------------------------------\n"); - slesutPrintEnvironmentalReverbSettings(&getSettings); - printf("\n"); - if (!slesutCompareEnvironmentalReverbSettings(&getSettings, - &outputMixEnvironmentalSettings)) { - printf("Warning: new and read are different; check details above\n"); - } else { - printf("New and read match, life is good\n"); - } - } - } - - // create audio player - SLDataLocator_URI locURI = {SL_DATALOCATOR_URI, (SLchar *) pathname}; - SLDataFormat_MIME dfMIME = {SL_DATAFORMAT_MIME, NULL, SL_CONTAINERTYPE_UNSPECIFIED}; - SLDataSource audioSrc = {&locURI, &dfMIME}; - SLDataLocator_OutputMix locOutputMix = {SL_DATALOCATOR_OUTPUTMIX, mixObject}; - SLDataSink audioSnk = {&locOutputMix, NULL}; - SLInterfaceID player_ids[5]; - SLboolean player_req[5]; - count = 0; - if (playerPresetItfRequested) { - player_req[count] = SL_BOOLEAN_TRUE; - player_ids[count++] = SL_IID_PRESETREVERB; - } - if (playerEnvironmentalItfRequested) { - player_req[count] = SL_BOOLEAN_TRUE; - player_ids[count++] = SL_IID_ENVIRONMENTALREVERB; - } - if (outputMixPresetItfRequested || outputMixEnvironmentalItfRequested) { - player_req[count] = SL_BOOLEAN_TRUE; - player_ids[count++] = SL_IID_EFFECTSEND; - } - if (loop) { - player_req[count] = SL_BOOLEAN_TRUE; - player_ids[count++] = SL_IID_SEEK; - } - player_req[count] = SL_BOOLEAN_TRUE; - player_ids[count++] = SL_IID_PREFETCHSTATUS; - SLObjectItf playerObject; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audioSrc, - &audioSnk, count, player_ids, player_req); - assert(SL_RESULT_SUCCESS == result); - - // realize audio player - result = (*playerObject)->Realize(playerObject, SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - - // if reverb is on output mix (aux effect), then enable it for this player - if (outputMixPresetItfRequested || outputMixEnvironmentalItfRequested) { - SLEffectSendItf playerEffectSend; - result = (*playerObject)->GetInterface(playerObject, SL_IID_EFFECTSEND, &playerEffectSend); - assert(SL_RESULT_SUCCESS == result); - SLboolean enabled; - SLmillibel directLevel; - SLmillibel sendLevel; - if (outputMixPresetItfRequested) { - result = (*playerEffectSend)->IsEnabled(playerEffectSend, outputMixPresetReverb, - &enabled); - assert(SL_RESULT_SUCCESS == result); - printf("Output mix preset reverb: player effect send default enabled = %s\n", - enabled ? "true" : "false"); - directLevel = 12345; - result = (*playerEffectSend)->GetDirectLevel(playerEffectSend, &directLevel); - assert(SL_RESULT_SUCCESS == result); - printf("Output mix preset reverb: player effect send default direct level = %d\n", - directLevel); - sendLevel = 12345; - result = (*playerEffectSend)->GetSendLevel(playerEffectSend, outputMixPresetReverb, - &sendLevel); - assert(SL_RESULT_SUCCESS == result); - printf("Output mix preset reverb: player effect send default send level = %d\n", - sendLevel); - if (outputMixPresetNumber != ((SLuint16) ~0)) { - result = (*playerEffectSend)->EnableEffectSend(playerEffectSend, - outputMixPresetReverb, SL_BOOLEAN_TRUE, (SLmillibel) 0); - assert(SL_RESULT_SUCCESS == result); - result = (*playerEffectSend)->IsEnabled(playerEffectSend, outputMixPresetReverb, - &enabled); - assert(SL_RESULT_SUCCESS == result); - directLevel = 12345; - result = (*playerEffectSend)->GetDirectLevel(playerEffectSend, &directLevel); - assert(SL_RESULT_SUCCESS == result); - sendLevel = 12345; - result = (*playerEffectSend)->GetSendLevel(playerEffectSend, outputMixPresetReverb, - &sendLevel); - assert(SL_RESULT_SUCCESS == result); - printf("Output mix preset reverb: player effect send new enabled = %s, direct level" - " = %d, send level = %d\n", enabled ? "true" : "false", directLevel, sendLevel); - } - } - if (outputMixEnvironmentalItfRequested) { - if (outputMixEnvironmentalName != NULL) { - result = (*playerEffectSend)->IsEnabled(playerEffectSend, - outputMixEnvironmentalReverb, &enabled); - assert(SL_RESULT_SUCCESS == result); - printf("Output mix environmental reverb: player effect send default enabled = %s\n", - enabled ? "true" : "false"); - directLevel = 12345; - result = (*playerEffectSend)->GetDirectLevel(playerEffectSend, &directLevel); - assert(SL_RESULT_SUCCESS == result); - printf("Output mix environmental reverb: player effect send default direct level" - " = %d\n", directLevel); - sendLevel = 12345; - result = (*playerEffectSend)->GetSendLevel(playerEffectSend, - outputMixEnvironmentalReverb, &sendLevel); - assert(SL_RESULT_SUCCESS == result); - printf("Output mix environmental reverb: player effect send default send level" - " = %d\n", sendLevel); - result = (*playerEffectSend)->EnableEffectSend(playerEffectSend, - outputMixEnvironmentalReverb, SL_BOOLEAN_TRUE, (SLmillibel) 0); - assert(SL_RESULT_SUCCESS == result); - result = (*playerEffectSend)->IsEnabled(playerEffectSend, - outputMixEnvironmentalReverb, &enabled); - assert(SL_RESULT_SUCCESS == result); - directLevel = 12345; - result = (*playerEffectSend)->GetDirectLevel(playerEffectSend, &directLevel); - assert(SL_RESULT_SUCCESS == result); - sendLevel = 12345; - result = (*playerEffectSend)->GetSendLevel(playerEffectSend, - outputMixEnvironmentalReverb, &sendLevel); - assert(SL_RESULT_SUCCESS == result); - printf("Output mix environmental reverb: player effect send new enabled = %s, " - "direct level = %d, send level = %d\n", enabled ? "true" : "false", - directLevel, sendLevel); - } - } - } - - // configure preset reverb on player - SLPresetReverbItf playerPresetReverb; - if (playerPresetItfRequested) { - result = (*playerObject)->GetInterface(playerObject, SL_IID_PRESETREVERB, - &playerPresetReverb); - assert(SL_RESULT_SUCCESS == result); - SLuint16 getPresetReverb = 12345; - result = (*playerPresetReverb)->GetPreset(playerPresetReverb, &getPresetReverb); - if (SL_RESULT_SUCCESS == result) { - printf("Player default preset reverb %u\n", getPresetReverb); - if (playerPresetNumber != ((SLuint16) ~0)) { - result = (*playerPresetReverb)->SetPreset(playerPresetReverb, playerPresetNumber); - if (SL_RESULT_SUCCESS == result) { - result = (*playerPresetReverb)->GetPreset(playerPresetReverb, &getPresetReverb); - assert(SL_RESULT_SUCCESS == result); - assert(getPresetReverb == playerPresetNumber); - printf("Player preset reverb successfully changed to %u\n", playerPresetNumber); - } else { - printf("Unable to set player preset reverb to %u, result=%u\n", - playerPresetNumber, result); - } - } - } else { - printf("Unable to get player default preset reverb, result=%u\n", result); - } - } - - // configure environmental reverb on player - SLEnvironmentalReverbItf playerEnvironmentalReverb; - if (playerEnvironmentalItfRequested) { - result = (*playerObject)->GetInterface(playerObject, SL_IID_ENVIRONMENTALREVERB, - &playerEnvironmentalReverb); - assert(SL_RESULT_SUCCESS == result); - SLEnvironmentalReverbSettings getSettings; - memset(&getSettings, 0, sizeof(getSettings)); - result = (*playerEnvironmentalReverb)->GetEnvironmentalReverbProperties( - playerEnvironmentalReverb, &getSettings); - if (SL_RESULT_SUCCESS == result) { - printf("Player default environmental reverb settings\n"); - printf("--------------------------------------------\n"); - slesutPrintEnvironmentalReverbSettings(&getSettings); - printf("\n"); - if (playerEnvironmentalName != NULL) { - result = (*playerEnvironmentalReverb)->SetEnvironmentalReverbProperties( - playerEnvironmentalReverb, &playerEnvironmentalSettings); - assert(SL_RESULT_SUCCESS == result); - printf("Player new environmental reverb settings\n"); - printf("----------------------------------------\n"); - slesutPrintEnvironmentalReverbSettings(&playerEnvironmentalSettings); - printf("\n"); - result = (*playerEnvironmentalReverb)->GetEnvironmentalReverbProperties( - playerEnvironmentalReverb, &getSettings); - assert(SL_RESULT_SUCCESS == result); - printf("Player read environmental reverb settings\n"); - printf("-----------------------------------------\n"); - slesutPrintEnvironmentalReverbSettings(&getSettings); - printf("\n"); - if (!slesutCompareEnvironmentalReverbSettings(&getSettings, - &playerEnvironmentalSettings)) { - printf("Warning: new and read are different; check details above\n"); - } else { - printf("New and read match, life is good\n"); - } - } - } else { - printf("Unable to get player default environmental reverb properties, result=%u\n", - result); - } - } - - // get the play interface - SLPlayItf playerPlay; - result = (*playerObject)->GetInterface(playerObject, SL_IID_PLAY, &playerPlay); - assert(SL_RESULT_SUCCESS == result); - - // get the prefetch status interface - SLPrefetchStatusItf playerPrefetchStatus; - result = (*playerObject)->GetInterface(playerObject, SL_IID_PREFETCHSTATUS, - &playerPrefetchStatus); - assert(SL_RESULT_SUCCESS == result); - - // enable prefetch status callbacks - result = (*playerPrefetchStatus)->RegisterCallback(playerPrefetchStatus, prefetch_callback, - NULL); - assert(SL_RESULT_SUCCESS == result); - result = (*playerPrefetchStatus)->SetCallbackEventsMask(playerPrefetchStatus, - SL_PREFETCHEVENT_STATUSCHANGE | SL_PREFETCHEVENT_FILLLEVELCHANGE); - assert(SL_RESULT_SUCCESS == result); - - // set play state to paused to enable pre-fetch so we can get a more reliable duration - result = (*playerPlay)->SetPlayState(playerPlay, SL_PLAYSTATE_PAUSED); - assert(SL_RESULT_SUCCESS == result); - - // wait for prefetch status callback to indicate either sufficient data or error - pthread_mutex_lock(&mutex); - while (prefetch_status == SL_PREFETCHSTATUS_UNKNOWN) { - pthread_cond_wait(&cond, &mutex); - } - pthread_mutex_unlock(&mutex); - if (prefetch_status == SL_PREFETCHSTATUS_ERROR) { - fprintf(stderr, "Error during prefetch, exiting\n"); - goto destroyRes; - } - - // get the duration - SLmillisecond duration; - result = (*playerPlay)->GetDuration(playerPlay, &duration); - assert(SL_RESULT_SUCCESS == result); - if (SL_TIME_UNKNOWN == duration) { - printf("duration: unknown\n"); - } else { - printf("duration: %.1f seconds\n", duration / 1000.0); - } - - // enable looping - if (loop) { - SLSeekItf playerSeek; - result = (*playerObject)->GetInterface(playerObject, SL_IID_SEEK, &playerSeek); - assert(SL_RESULT_SUCCESS == result); - result = (*playerSeek)->SetLoop(playerSeek, SL_BOOLEAN_TRUE, (SLmillisecond) 0, - SL_TIME_UNKNOWN); - assert(SL_RESULT_SUCCESS == result); - } - - // start audio playing - result = (*playerPlay)->SetPlayState(playerPlay, SL_PLAYSTATE_PLAYING); - assert(SL_RESULT_SUCCESS == result); - - // wait for audio to finish playing - SLuint32 state; - for (;;) { - result = (*playerPlay)->GetPlayState(playerPlay, &state); - assert(SL_RESULT_SUCCESS == result); - if (SL_PLAYSTATE_PLAYING != state) - break; - usleep(1000000); - } - assert(SL_PLAYSTATE_PAUSED == state); - -destroyRes: - // cleanup objects - (*playerObject)->Destroy(playerObject); - (*mixObject)->Destroy(mixObject); - (*engineObject)->Destroy(engineObject); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/sandbox/srcsink.c b/wilhelm/tests/sandbox/srcsink.c deleted file mode 100644 index 201aa453..00000000 --- a/wilhelm/tests/sandbox/srcsink.c +++ /dev/null @@ -1,220 +0,0 @@ -/* - * 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. - */ - -// Test various combinations of data sources and sinks - -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> -#include <SLES/OpenSLES.h> - -int main(int argc, char **argv) -{ - SLresult result; - SLObjectItf engineObject; - - // create engine - result = slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL); - assert(SL_RESULT_SUCCESS == result); - SLEngineItf engineEngine; - result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine); - assert(SL_RESULT_SUCCESS == result); - - // configure a typical audio source of 44.1 kHz stereo 16-bit little endian - SLDataLocator_BufferQueue loc_bufq; - loc_bufq.locatorType = SL_DATALOCATOR_BUFFERQUEUE; - loc_bufq.numBuffers = 1; - SLDataFormat_PCM format_pcm; - format_pcm.formatType = SL_DATAFORMAT_PCM; - format_pcm.numChannels = 2; - format_pcm.samplesPerSec = SL_SAMPLINGRATE_44_1; - format_pcm.bitsPerSample = 16; - format_pcm.containerSize = 16; - format_pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT; - format_pcm.endianness = SL_BYTEORDER_LITTLEENDIAN; - SLDataSource audioSrc; - audioSrc.pLocator = &loc_bufq; - audioSrc.pFormat = &format_pcm; - - // configure audio sink - SLDataLocator_OutputMix loc_outmix; - loc_outmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; - loc_outmix.outputMix = NULL; - SLDataSink audioSnk; - audioSnk.pLocator = &loc_outmix; - audioSnk.pFormat = NULL; - - // create audio player using a NULL output mix - SLInterfaceID ids[1] = {SL_IID_BUFFERQUEUE}; - SLboolean req[1] = {SL_BOOLEAN_TRUE}; - SLObjectItf playerObject; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audioSrc, - &audioSnk, 1, ids, req); - assert(SL_RESULT_PARAMETER_INVALID == result); - assert(NULL == playerObject); - - // create audio player using an engine as the output mix - loc_outmix.outputMix = engineObject; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audioSrc, - &audioSnk, 1, ids, req); - assert(SL_RESULT_PARAMETER_INVALID == result); - assert(NULL == playerObject); - - // create output mix but don't realize it yet - SLObjectItf outputMixObject; - result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 0, NULL, NULL); - assert(SL_RESULT_SUCCESS == result); - - // create audio player using the unrealized output mix - loc_outmix.outputMix = outputMixObject; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audioSrc, - &audioSnk, 1, ids, req); - assert(SL_RESULT_PRECONDITIONS_VIOLATED == result); - assert(NULL == playerObject); - - // now realize the output mix - result = (*outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - - // create audio player using the realized output mix - // and a bogus data format for the sink (ignored per spec) - audioSnk.pFormat = (void *) 0xDEADBEEF; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audioSrc, - &audioSnk, 1, ids, req); - assert(SL_RESULT_SUCCESS == result); - assert(NULL != playerObject); - audioSnk.pFormat = NULL; - - // destroy player - (*playerObject)->Destroy(playerObject); - - // now try to create audio player using various unusual parameters - - // number of channels - format_pcm.numChannels = 0; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audioSrc, - &audioSnk, 1, ids, req); - assert(SL_RESULT_PARAMETER_INVALID == result); - assert(NULL == playerObject); - format_pcm.numChannels = 3; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audioSrc, - &audioSnk, 1, ids, req); - assert(SL_RESULT_CONTENT_UNSUPPORTED == result); - assert(NULL == playerObject); - format_pcm.numChannels = 2; - - // sample rate - format_pcm.samplesPerSec = 0; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audioSrc, - &audioSnk, 1, ids, req); - assert(SL_RESULT_PARAMETER_INVALID == result); - assert(NULL == playerObject); - format_pcm.samplesPerSec = 1000; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audioSrc, - &audioSnk, 1, ids, req); - assert(SL_RESULT_CONTENT_UNSUPPORTED == result); - assert(NULL == playerObject); - format_pcm.samplesPerSec = SL_SAMPLINGRATE_44_1; - - // bits per sample - format_pcm.bitsPerSample = 17; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audioSrc, - &audioSnk, 1, ids, req); - assert(SL_RESULT_PARAMETER_INVALID == result); - assert(NULL == playerObject); - format_pcm.bitsPerSample = 24; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audioSrc, - &audioSnk, 1, ids, req); - assert(SL_RESULT_CONTENT_UNSUPPORTED == result); - assert(NULL == playerObject); - format_pcm.bitsPerSample = 16; - - // container size - format_pcm.containerSize = 8; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audioSrc, - &audioSnk, 1, ids, req); - assert(SL_RESULT_PARAMETER_INVALID == result); - assert(NULL == playerObject); - format_pcm.containerSize = 32; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audioSrc, - &audioSnk, 1, ids, req); - assert(SL_RESULT_CONTENT_UNSUPPORTED == result); - assert(NULL == playerObject); - format_pcm.containerSize = 16; - - // channel mask - format_pcm.channelMask = 0; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audioSrc, - &audioSnk, 1, ids, req); - assert(SL_RESULT_SUCCESS == result); - assert(NULL != playerObject); - (*playerObject)->Destroy(playerObject); - format_pcm.channelMask = SL_SPEAKER_FRONT_CENTER; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audioSrc, - &audioSnk, 1, ids, req); - assert(SL_RESULT_PARAMETER_INVALID == result); - assert(NULL == playerObject); - format_pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT | - SL_SPEAKER_FRONT_CENTER; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audioSrc, - &audioSnk, 1, ids, req); - assert(SL_RESULT_PARAMETER_INVALID == result); - assert(NULL == playerObject); - format_pcm.numChannels = 1; - format_pcm.channelMask = 0; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audioSrc, - &audioSnk, 1, ids, req); - assert(SL_RESULT_SUCCESS == result); - assert(NULL != playerObject); - (*playerObject)->Destroy(playerObject); - format_pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audioSrc, - &audioSnk, 1, ids, req); - assert(SL_RESULT_PARAMETER_INVALID == result); - assert(NULL == playerObject); - format_pcm.numChannels = 2; - - // endianness - format_pcm.endianness = SL_BYTEORDER_BIGENDIAN; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audioSrc, - &audioSnk, 1, ids, req); -#ifdef ANDROID // known bug on SDL - assert(SL_RESULT_CONTENT_UNSUPPORTED == result); - assert(NULL == playerObject); -#else - if (SL_RESULT_CONTENT_UNSUPPORTED != result) { - printf("ERROR: expected SL_RESULT_CONTENT_UNSUPPORTED\n"); - if (NULL != playerObject) - (*playerObject)->Destroy(playerObject); - } -#endif - format_pcm.endianness = 0; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audioSrc, - &audioSnk, 1, ids, req); - assert(SL_RESULT_PARAMETER_INVALID == result); - assert(NULL == playerObject); - format_pcm.endianness = SL_BYTEORDER_LITTLEENDIAN; - - // destroy output mix - (*outputMixObject)->Destroy(outputMixObject); - - // destroy engine - (*engineObject)->Destroy(engineObject); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/sandbox/streamSource/Android.mk b/wilhelm/tests/sandbox/streamSource/Android.mk deleted file mode 100644 index bdaccc69..00000000 --- a/wilhelm/tests/sandbox/streamSource/Android.mk +++ /dev/null @@ -1,26 +0,0 @@ -LOCAL_PATH:= $(call my-dir) - -# slesTest_playStream - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES:= \ - $(call include-path-for, wilhelm) - -LOCAL_SRC_FILES:= \ - slesTestPlayStream.cpp - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libOpenSLES - -ifeq ($(TARGET_OS),linux) - LOCAL_CFLAGS += -DXP_UNIX -endif - -LOCAL_MODULE:= slesTest_playStream - - -include $(BUILD_EXECUTABLE) diff --git a/wilhelm/tests/sandbox/streamSource/slesTestPlayStream.cpp b/wilhelm/tests/sandbox/streamSource/slesTestPlayStream.cpp deleted file mode 100644 index 7ce17c55..00000000 --- a/wilhelm/tests/sandbox/streamSource/slesTestPlayStream.cpp +++ /dev/null @@ -1,413 +0,0 @@ -/* - * 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. - */ - - -#include <stdlib.h> -#include <stdio.h> -//#include <string.h> -#include <unistd.h> -//#include <sys/time.h> - -#include <SLES/OpenSLES.h> -#include <SLES/OpenSLES_Android.h> - -//#define TEST_DISPLAY_FIRST_BUFFER_ITEM -//#define TEST_CLEAR -//#define TEST_PTS - -#define MAX_NUMBER_INTERFACES 2 - -#define PREFETCHEVENT_ERROR_CANDIDATE \ - (SL_PREFETCHEVENT_STATUSCHANGE | SL_PREFETCHEVENT_FILLLEVELCHANGE) - -#define NB_BUFFERS 16 -#define MPEG2_TS_BLOCK_SIZE 188 -#define BUFFER_SIZE (20*MPEG2_TS_BLOCK_SIZE) -#define DISCONTINUITY_MAGIC 1977 - -/* Where we store the data to play */ -char dataCache[BUFFER_SIZE * NB_BUFFERS]; -/* From where we read the data to play */ -FILE *file; -/* Has the app reached the end of the file */ -bool reachedEof = false; -/* Special discontinuity buffer context */ -int myDiscBufferContext = DISCONTINUITY_MAGIC; - -/* structure to store my discontinuity with PTS command */ -typedef struct { - SLuint32 discKey; // identifies the item - SLuint32 discSize; - SLAuint64 discPts; -} DiscPts; - -//----------------------------------------------------------------- -/* Exits the application if an error is encountered */ -#define CheckErr(x) ExitOnErrorFunc(x,__LINE__) - -void ExitOnErrorFunc( SLresult result , int line) -{ - if (SL_RESULT_SUCCESS != result) { - fprintf(stderr, "%u error code encountered at line %d, exiting\n", result, line); - exit(EXIT_FAILURE); - } -} - -bool prefetchError = false; - -//----------------------------------------------------------------- -/* AndroidBufferQueueItf callback for an audio player */ -SLresult AndroidBufferQueueCallback( - SLAndroidBufferQueueItf caller, - void *pCallbackContext, /* input */ - void *pBufferContext, /* input */ - void *pBufferData, /* input */ - SLuint32 dataSize, /* input */ - SLuint32 dataUsed, /* input */ - const SLAndroidBufferItem *pItems, /* input */ - SLuint32 itemsLength /* input */) -{ - // assert(BUFFER_SIZE <= dataSize); - - //-------------------------------------------------------------------------------- - // this section is for testing only, this is NOT an example of how to use the API - // to play a .ts file, but rather shows more ways to exercise the API - //-------------------------------------------------------------------------------- - SLAndroidBufferQueueState state; - (*caller)->GetState(caller, &state); - //fprintf(stdout, "ABQ state count=%lu, index=%lu\n", state.count, state.index); - - // just to test, clear the queue to see what happens - if (state.index == 500) { -#ifdef TEST_CLEAR - (*caller)->Clear(caller); - // we've cleared the queue, and have introduced a discontinuity, so signal it - SLAndroidBufferItem msgDiscontinuity; - msgDiscontinuity.itemKey = SL_ANDROID_ITEMKEY_DISCONTINUITY; - msgDiscontinuity.itemSize = 0; - // message has no parameters, so the total size of the message is the size of the key - // plus the size if itemSize, both SLuint32 - (*caller)->Enqueue(caller, (void*)&myDiscBufferContext /*pBufferContext*/, - NULL /*pData*/, 0 /*dataLength*/, - &msgDiscontinuity /*pMsg*/, - sizeof(SLuint32)*2 /*msgLength*/); - // we've cleared the queue, it's now empty: let's rebuffer a bit so playback doesn't starve - size_t nbRead = fread((void*)dataCache, 1, BUFFER_SIZE*(NB_BUFFERS/2), file); - if (nbRead == BUFFER_SIZE*(NB_BUFFERS/2)) { - for (int i=0 ; i < NB_BUFFERS/2 ; i++) { - SLresult res = (*caller)->Enqueue(caller, NULL /*pBufferContext*/, - dataCache + i*BUFFER_SIZE, - BUFFER_SIZE, NULL, 0); - CheckErr(res); - } - } -#endif -#ifdef TEST_PTS - DiscPts msgDiscontinuity = { SL_ANDROID_ITEMKEY_DISCONTINUITY, - sizeof(SLAuint64), 15*90*1000 /*15s in 90kHz clock */ }; - // enqueue discontinuity message with our PTS - (*caller)->Enqueue(caller, (void*)&myDiscBufferContext /*pBufferContext*/, - NULL /*pData*/, 0 /*dataLength*/, - (SLAndroidBufferItem*)&msgDiscontinuity, - sizeof(DiscPts) ); - fprintf(stdout, "rendering will resume at 15s mark"); - -#endif - return SL_RESULT_SUCCESS; - } - //-------------------------------------------------------------------------------- - // end of test only section - //-------------------------------------------------------------------------------- - else { - -#ifdef TEST_DISPLAY_FIRST_BUFFER_ITEM - // display item data (only parsing first item) - if (itemsLength !=0) { - fprintf(stdout, "item key=0x%lx size=%lu data=0x%lx\n", - pItems->itemKey, pItems->itemSize, *((SLuint32*)&pItems->itemData)); - } -#endif - - // pBufferData can be null if the last consumed buffer contained only a command - // just like we do for signalling DISCONTINUITY (above) or EOS (below) - if ((pBufferContext != NULL) && (*((int*)pBufferContext) == DISCONTINUITY_MAGIC)) { - fprintf(stdout, "Successfully detected my discontinuity buffer having been consumed\n"); - } - if (pBufferData != NULL) { - size_t nbRead = fread((void*)pBufferData, 1, BUFFER_SIZE, file); - if (nbRead > 0) { - (*caller)->Enqueue(caller, NULL /*pBufferContext*/, - pBufferData /*pData*/, - nbRead /*dataLength*/, - NULL /*pMsg*/, - 0 /*msgLength*/); - } else if (!reachedEof) { - // signal EOS - SLAndroidBufferItem msgEos; - msgEos.itemKey = SL_ANDROID_ITEMKEY_EOS; - msgEos.itemSize = 0; - // EOS message has no parameters, so the total size of the message is the size of - // the key plus the size if itemSize, both SLuint32 - (*caller)->Enqueue(caller, NULL /*pBufferContext*/, - NULL /*pData*/, 0 /*dataLength*/, - &msgEos /*pMsg*/, - sizeof(SLuint32)*2 /*msgLength*/); - reachedEof = true; - } - } - - return SL_RESULT_SUCCESS; - } -} - - -//----------------------------------------------------------------- - -/* Play some music from a URI */ -void TestPlayStream( SLObjectItf sl, const char* path) -{ - SLEngineItf EngineItf; - - SLint32 numOutputs = 0; - SLuint32 deviceID = 0; - - SLresult res; - - SLDataSource audioSource; - SLDataLocator_AndroidBufferQueue streamLocator; - SLDataFormat_MIME mime; - - SLDataSink audioSink; - SLDataLocator_OutputMix locator_outputmix; - - SLObjectItf player; - SLPlayItf playItf; - SLVolumeItf volItf; - SLAndroidBufferQueueItf abqItf; - - SLObjectItf OutputMix; - - SLboolean required[MAX_NUMBER_INTERFACES]; - SLInterfaceID iidArray[MAX_NUMBER_INTERFACES]; - - int playTimeInSec = 60; - - file = fopen(path, "rb"); - - /* Get the SL Engine Interface which is implicit */ - res = (*sl)->GetInterface(sl, SL_IID_ENGINE, (void*)&EngineItf); - CheckErr(res); - - /* Initialize arrays required[] and iidArray[] */ - for (int i=0 ; i < MAX_NUMBER_INTERFACES ; i++) { - required[i] = SL_BOOLEAN_FALSE; - iidArray[i] = SL_IID_NULL; - } - - // Set arrays required[] and iidArray[] for VOLUME and PREFETCHSTATUS interface - required[0] = SL_BOOLEAN_TRUE; - iidArray[0] = SL_IID_VOLUME; - required[1] = SL_BOOLEAN_TRUE; - iidArray[1] = SL_IID_ANDROIDBUFFERQUEUESOURCE; - // Create Output Mix object to be used by player - res = (*EngineItf)->CreateOutputMix(EngineItf, &OutputMix, 0, - iidArray, required); CheckErr(res); - - // Realizing the Output Mix object in synchronous mode. - res = (*OutputMix)->Realize(OutputMix, SL_BOOLEAN_FALSE); - CheckErr(res); - - /* Setup the data source structure for the URI */ - streamLocator.locatorType = SL_DATALOCATOR_ANDROIDBUFFERQUEUE; - streamLocator.numBuffers = NB_BUFFERS; - mime.formatType = SL_DATAFORMAT_MIME; - mime.mimeType = (SLchar *) "video/mp2ts";//(SLchar*)NULL; - mime.containerType = SL_CONTAINERTYPE_MPEG_TS; - - audioSource.pFormat = (void *)&mime; - audioSource.pLocator = (void *)&streamLocator; - - /* Setup the data sink structure */ - locator_outputmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; - locator_outputmix.outputMix = OutputMix; - audioSink.pLocator = (void *)&locator_outputmix; - audioSink.pFormat = NULL; - - /* Create the audio player */ - res = (*EngineItf)->CreateAudioPlayer(EngineItf, &player, &audioSource, &audioSink, - MAX_NUMBER_INTERFACES, iidArray, required); CheckErr(res); - - /* Realizing the player in synchronous mode. */ - res = (*player)->Realize(player, SL_BOOLEAN_FALSE); CheckErr(res); - fprintf(stdout, "URI example: after Realize\n"); - - /* Get interfaces */ - res = (*player)->GetInterface(player, SL_IID_PLAY, (void*)&playItf); CheckErr(res); - - res = (*player)->GetInterface(player, SL_IID_VOLUME, (void*)&volItf); CheckErr(res); - - res = (*player)->GetInterface(player, SL_IID_ANDROIDBUFFERQUEUESOURCE, (void*)&abqItf); - CheckErr(res); - - res = (*abqItf)->RegisterCallback(abqItf, AndroidBufferQueueCallback, - // context is not used in the example, but can be used to track who registered - // the buffer queue callback - NULL /*pContext*/); CheckErr(res); - - res = (*abqItf)->SetCallbackEventsMask(abqItf, SL_ANDROIDBUFFERQUEUEEVENT_PROCESSED); - CheckErr(res); - - /* Display duration */ - SLmillisecond durationInMsec = SL_TIME_UNKNOWN; - res = (*playItf)->GetDuration(playItf, &durationInMsec); - CheckErr(res); - if (durationInMsec == SL_TIME_UNKNOWN) { - fprintf(stdout, "Content duration is unknown (before starting to prefetch)\n"); - } else { - fprintf(stdout, "Content duration is %u ms (before starting to prefetch)\n", - durationInMsec); - } - - /* Set the player volume */ - res = (*volItf)->SetVolumeLevel( volItf, 0);//-300); - CheckErr(res); - - - /* Play the URI */ - /* first cause the player to prefetch the data */ - fprintf(stdout, "Before set to PAUSED\n"); - res = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PAUSED ); - fprintf(stdout, "After set to PAUSED\n"); - CheckErr(res); - - /* Fill our cache */ - if (fread(dataCache, 1, BUFFER_SIZE * NB_BUFFERS, file) <= 0) { - fprintf(stderr, "Error filling cache, exiting\n"); - goto destroyRes; - } - /* Enqueue the content of our cache before starting to play, - * we don't want to starve the player */ - for (int i=0 ; i < NB_BUFFERS ; i++) { - res = (*abqItf)->Enqueue(abqItf, NULL /*pBufferContext*/, - dataCache + i*BUFFER_SIZE, BUFFER_SIZE, NULL, 0); - CheckErr(res); - } - -#if 0 // used to test ABQ starving where only one buffer is enqueued before playback - /* Fill our cache */ - if (fread(dataCache, 1, BUFFER_SIZE * 1, file) <= 0) { - fprintf(stderr, "Error filling cache, exiting\n"); - goto destroyRes; - } - /* Enqueue the content of our cache before starting to play, - * we don't want to starve the player */ - for (int i=0 ; i < 1 ; i++) { - res = (*abqItf)->Enqueue(abqItf, dataCache + i*BUFFER_SIZE, BUFFER_SIZE, NULL, 0); - CheckErr(res); - } -#endif - /* wait until there's data to play */ - //SLpermille fillLevel = 0; - /* - SLuint32 prefetchStatus = SL_PREFETCHSTATUS_UNDERFLOW; - SLuint32 timeOutIndex = 2; - while ((prefetchStatus != SL_PREFETCHSTATUS_SUFFICIENTDATA) && (timeOutIndex > 0) && - !prefetchError) { - usleep(1 * 1000 * 1000); // 1s - //(*prefetchItf)->GetPrefetchStatus(prefetchItf, &prefetchStatus); - timeOutIndex--; - } - - if (timeOutIndex == 0 || prefetchError) { - fprintf(stderr, "We\'re done waiting, failed to prefetch data in time, exiting\n"); - goto destroyRes; - } -*/ - - /* Display duration again, */ -/* res = (*playItf)->GetDuration(playItf, &durationInMsec); - CheckErr(res); - if (durationInMsec == SL_TIME_UNKNOWN) { - fprintf(stdout, "Content duration is unknown (after prefetch completed)\n"); - } else { - fprintf(stdout, "Content duration is %lu ms (after prefetch completed)\n", durationInMsec); - } -*/ - - fprintf(stdout, "URI example: starting to play\n"); - res = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PLAYING ); - CheckErr(res); - - /* Wait as long as the duration of the content before stopping */ - fprintf(stdout, "Letting playback go on for %d sec\n", playTimeInSec); - usleep(playTimeInSec /*s*/ * 1000 * 1000); - - - /* Make sure player is stopped */ - fprintf(stdout, "URI example: stopping playback\n"); - res = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED); - CheckErr(res); - - fprintf(stdout, "sleeping to verify playback stopped\n"); - usleep(2 /*s*/ * 1000 * 1000); - -destroyRes: - - /* Destroy the player */ - (*player)->Destroy(player); - - /* Destroy Output Mix object */ - (*OutputMix)->Destroy(OutputMix); - - fclose(file); -} - -//----------------------------------------------------------------- -int main(int argc, char* const argv[]) -{ - SLresult res; - SLObjectItf sl; - - fprintf(stdout, "OpenSL ES test %s: exercises SLPlayItf, SLVolumeItf, SLAndroidBufferQueue \n", - argv[0]); - fprintf(stdout, "and AudioPlayer with SL_DATALOCATOR_ANDROIDBUFFERQUEUE source / OutputMix " - "sink\n"); - fprintf(stdout, "Plays a sound and stops after its reported duration\n\n"); - - if (argc == 1) { - fprintf(stdout, "Usage: %s path \n", argv[0]); - fprintf(stdout, "Example: \"%s /sdcard/my.ts\n", - argv[0], argv[0]); - exit(EXIT_FAILURE); - } - - SLEngineOption EngineOption[] = { - {(SLuint32) SL_ENGINEOPTION_THREADSAFE, - (SLuint32) SL_BOOLEAN_TRUE}}; - - res = slCreateEngine( &sl, 1, EngineOption, 0, NULL, NULL); - CheckErr(res); - /* Realizing the SL Engine in synchronous mode. */ - res = (*sl)->Realize(sl, SL_BOOLEAN_FALSE); - CheckErr(res); - - TestPlayStream(sl, argv[1]); - - /* Shutdown OpenSL ES */ - (*sl)->Destroy(sl); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/sandbox/urimime.c b/wilhelm/tests/sandbox/urimime.c deleted file mode 100644 index 20784bcd..00000000 --- a/wilhelm/tests/sandbox/urimime.c +++ /dev/null @@ -1,164 +0,0 @@ -/* - * 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. - */ - -// Test audio player configurations with URI data source and MIME data format - -#include <assert.h> -#include <math.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> - -#include <SLES/OpenSLES.h> -#ifdef ANDROID -#include <SLES/OpenSLES_Android.h> -#endif - -int main(int argc, char **argv) -{ - if (argc != 2) { - fprintf(stderr, "usage: %s URI\n", argv[0]); - return EXIT_FAILURE; - } - - SLresult result; - SLObjectItf engineObject; - - // create engine - result = slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL); - assert(SL_RESULT_SUCCESS == result); - SLEngineItf engineEngine; - result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine); - assert(SL_RESULT_SUCCESS == result); - - // create output mix - SLObjectItf outputMixObject; - result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 0, NULL, NULL); - assert(SL_RESULT_SUCCESS == result); - result = (*outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - - // configure audio source - SLDataLocator_URI loc_uri; - loc_uri.locatorType = SL_DATALOCATOR_URI; - loc_uri.URI = (SLchar *) argv[1]; - SLDataFormat_MIME format_mime; - format_mime.formatType = SL_DATAFORMAT_MIME; - format_mime.mimeType = NULL; - format_mime.containerType = SL_CONTAINERTYPE_UNSPECIFIED; - SLDataSource audioSrc; - audioSrc.pLocator = &loc_uri; - audioSrc.pFormat = &format_mime; - - // configure audio sink - SLDataLocator_OutputMix loc_outmix; - loc_outmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; - loc_outmix.outputMix = outputMixObject; - SLDataSink audioSnk; - audioSnk.pLocator = &loc_outmix; - audioSnk.pFormat = NULL; - - // create audio player, requesting a buffer queue interface - SLuint32 numInterfaces = 1; - SLInterfaceID ids[1]; - SLboolean req[1]; - ids[0] = SL_IID_BUFFERQUEUE; - req[0] = SL_BOOLEAN_TRUE; - SLObjectItf playerObject; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audioSrc, - &audioSnk, numInterfaces, ids, req); - assert(SL_RESULT_FEATURE_UNSUPPORTED == result); - assert(NULL == playerObject); -#ifdef ANDROID - ids[0] = SL_IID_ANDROIDSIMPLEBUFFERQUEUE; - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audioSrc, - &audioSnk, numInterfaces, ids, req); - assert(SL_RESULT_FEATURE_UNSUPPORTED == result); - assert(NULL == playerObject); -#endif - - // create audio player, without requesting a buffer queue interface - result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audioSrc, - &audioSnk, 0, NULL, NULL); - assert(SL_RESULT_SUCCESS == result); - - // realize the player - result = (*playerObject)->Realize(playerObject, SL_BOOLEAN_FALSE); - assert(SL_RESULT_SUCCESS == result); - - // get the play interface - SLPlayItf playerPlay; - result = (*playerObject)->GetInterface(playerObject, SL_IID_PLAY, &playerPlay); - assert(SL_RESULT_SUCCESS == result); - - // get the buffer queue interface - SLBufferQueueItf playerBufferQueue; - result = (*playerObject)->GetInterface(playerObject, SL_IID_BUFFERQUEUE, &playerBufferQueue); - assert(SL_RESULT_FEATURE_UNSUPPORTED == result); - assert(NULL == playerBufferQueue); -#ifdef ANDROID - SLAndroidSimpleBufferQueueItf playerAndroidSimpleBufferQueue; - result = (*playerObject)->GetInterface(playerObject, SL_IID_ANDROIDSIMPLEBUFFERQUEUE, - &playerAndroidSimpleBufferQueue); - assert(SL_RESULT_FEATURE_UNSUPPORTED == result); - assert(NULL == playerAndroidSimpleBufferQueue); -#endif - - // get the player duration - SLmillisecond duration; - result = (*playerPlay)->GetDuration(playerPlay, &duration); - assert(SL_RESULT_SUCCESS == result); - if (SL_TIME_UNKNOWN == duration) - printf("Duration: unknown\n"); - else - printf("Duration: %.1f\n", duration / 1000.0f); - - // set the player's state to playing - result = (*playerPlay)->SetPlayState(playerPlay, SL_PLAYSTATE_PLAYING); - assert(SL_RESULT_SUCCESS == result); - - // wait for the playback to finish - for (;;) { - SLuint32 playState; - result = (*playerPlay)->GetPlayState(playerPlay, &playState); - assert(SL_RESULT_SUCCESS == result); - if (SL_PLAYSTATE_PLAYING != playState) { - break; - } - usleep(10000); - } - - // get the player duration - result = (*playerPlay)->GetDuration(playerPlay, &duration); - assert(SL_RESULT_SUCCESS == result); - if (SL_TIME_UNKNOWN == duration) - printf("Duration: unknown\n"); - else - printf("Duration: %.1f\n", duration / 1000.0f); - - // destroy audio player - (*playerObject)->Destroy(playerObject); - - // destroy output mix - (*outputMixObject)->Destroy(outputMixObject); - - // destroy engine - (*engineObject)->Destroy(engineObject); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/sandbox/xa.c b/wilhelm/tests/sandbox/xa.c deleted file mode 100644 index c44191a3..00000000 --- a/wilhelm/tests/sandbox/xa.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - * 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. - */ - -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> -#include <OMXAL/OpenMAXAL.h> -#include <OMXAL/OpenMAXAL_Android.h> - -int main(int argc, char **argv) -{ - XAresult result; - XAObjectItf engineObject; - printf("xaCreateEngine\n"); - result = xaCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL); - printf("result = %d\n", result); - assert(XA_RESULT_SUCCESS == result); - printf("engineObject = %p\n", engineObject); - printf("realize\n"); - result = (*engineObject)->Realize(engineObject, XA_BOOLEAN_FALSE); - printf("result = %d\n", result); - printf("GetInterface for ENGINE\n"); - XAEngineItf engineEngine; - result = (*engineObject)->GetInterface(engineObject, XA_IID_ENGINE, &engineEngine); - printf("result = %d\n", result); - printf("engineEngine = %p\n", engineEngine); - assert(XA_RESULT_SUCCESS == result); - - XAObjectItf outputMixObject; - printf("CreateOutputMix"); - result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 0, NULL, NULL); - printf("result = %d, outputMixObject=%p\n", result, outputMixObject); - result = (*outputMixObject)->Realize(outputMixObject, XA_BOOLEAN_FALSE); - printf("result = %d\n", result); - - XAObjectItf deviceObject; - printf("CreateCameraDevice\n"); - result = (*engineEngine)->CreateCameraDevice(engineEngine, &deviceObject, - XA_DEFAULTDEVICEID_CAMERA, 0, NULL, NULL); - printf("result = %d, deviceObject=%p\n", result, deviceObject); - - printf("CreateRadioDevice\n"); - result = (*engineEngine)->CreateRadioDevice(engineEngine, &deviceObject, 0, NULL, NULL); - printf("result = %d, deviceObject=%p\n", result, deviceObject); - - printf("CreateLEDDevice\n"); - result = (*engineEngine)->CreateLEDDevice(engineEngine, &deviceObject, XA_DEFAULTDEVICEID_LED, - 0, NULL, NULL); - printf("result = %d, deviceObject=%p\n", result, deviceObject); - - printf("CreateVibraDevice\n"); - result = (*engineEngine)->CreateVibraDevice(engineEngine, &deviceObject, - XA_DEFAULTDEVICEID_VIBRA, 0, NULL, NULL); - printf("result = %d, deviceObject=%p\n", result, deviceObject); - - printf("CreateMediaPlayer\n"); - XAObjectItf playerObject; -#if 1 - XADataLocator_AndroidBufferQueue locABQ; - memset(&locABQ, 0, sizeof(locABQ)); - locABQ.locatorType = XA_DATALOCATOR_ANDROIDBUFFERQUEUE; -#else - XADataLocator_URI locUri; - locUri.locatorType = XA_DATALOCATOR_URI; - locUri.URI = (XAchar *) "/sdcard/hello.wav"; -#endif - XADataFormat_MIME fmtMime; - fmtMime.formatType = XA_DATAFORMAT_MIME; - fmtMime.mimeType = NULL; - fmtMime.containerType = XA_CONTAINERTYPE_UNSPECIFIED; - XADataSource dataSrc; -#if 1 - dataSrc.pLocator = &locABQ; -#else - dataSrc.pLocator = &locUri; -#endif - dataSrc.pFormat = &fmtMime; - XADataSink audioSnk; - XADataLocator_OutputMix locOM; - locOM.locatorType = XA_DATALOCATOR_OUTPUTMIX; - locOM.outputMix = outputMixObject; - audioSnk.pLocator = &locOM; - audioSnk.pFormat = NULL; - XADataLocator_NativeDisplay locND; - locND.locatorType = XA_DATALOCATOR_NATIVEDISPLAY; - locND.hWindow = NULL; - locND.hDisplay = NULL; - XADataSink imageVideoSink; - imageVideoSink.pLocator = &locND; - imageVideoSink.pFormat = NULL; - result = (*engineEngine)->CreateMediaPlayer(engineEngine, &playerObject, &dataSrc, NULL, - &audioSnk, &imageVideoSink, NULL, NULL, 0, NULL, NULL); - printf("result = %d, playerObject=%p\n", result, playerObject); - result = (*playerObject)->Realize(playerObject, XA_BOOLEAN_FALSE); - printf("result = %d\n", result); - - printf("GetInterface for PLAY\n"); - XAPlayItf playerPlay; - result = (*playerObject)->GetInterface(playerObject, XA_IID_PLAY, &playerPlay); - printf("result = %d\n", result); - printf("playerPlay = %p\n", playerPlay); - assert(XA_RESULT_SUCCESS == result); - - printf("SetPlayState to PLAYING\n"); - result = (*playerPlay)->SetPlayState(playerPlay, XA_PLAYSTATE_PLAYING); - printf("result = %d\n", result); - assert(XA_RESULT_SUCCESS == result); - - printf("destroying media player\n"); - (*playerObject)->Destroy(playerObject); - - printf("destroying output mix\n"); - (*outputMixObject)->Destroy(outputMixObject); - - printf("destroying engine\n"); - (*engineObject)->Destroy(engineObject); - printf("exit\n"); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tests/sandbox/xaplay.c b/wilhelm/tests/sandbox/xaplay.c deleted file mode 100644 index a93f9823..00000000 --- a/wilhelm/tests/sandbox/xaplay.c +++ /dev/null @@ -1,865 +0,0 @@ -/* - * 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. - */ - -// OpenMAX AL MediaPlayer command-line player - -#include <assert.h> -#include <pthread.h> -#include <stdio.h> -#include <stdlib.h> -#include <fcntl.h> -#include <sys/mman.h> -#include <sys/stat.h> -#include <unistd.h> -#include <OMXAL/OpenMAXAL.h> -#include <OMXAL/OpenMAXAL_Android.h> -#include "nativewindow.h" - -#define MPEG2TS_PACKET_SIZE 188 // MPEG-2 transport stream packet size in bytes -#define PACKETS_PER_BUFFER 20 // Number of MPEG-2 transport stream packets per buffer - -#define NB_BUFFERS 2 // Number of buffers in Android buffer queue - -// MPEG-2 transport stream packet -typedef struct { - char data[MPEG2TS_PACKET_SIZE]; -} MPEG2TS_Packet; - -// Globals shared between main thread and buffer queue callback -MPEG2TS_Packet *packets; -size_t totalPackets; // total number of packets in input file -size_t numPackets; // number of packets to play, defaults to totalPackets - firstPacket -size_t curPacket; // current packet index -size_t discPacket; // discontinuity packet index, defaults to no discontinuity requested -size_t afterDiscPacket; // packet index to switch to after the discontinuity -size_t firstPacket; // first packet index to be played, defaults to zero -size_t lastPacket; // last packet index to be played -size_t formatPacket; // format change packet index, defaults to no format change requested -XAmillisecond seekPos = XA_TIME_UNKNOWN; // seek to this position initially -int pauseMs = -1; // pause after this many ms into playback -XAboolean forceCallbackFailure = XA_BOOLEAN_FALSE; // force callback failures occasionally -XAboolean sentEOS = XA_BOOLEAN_FALSE; // whether we have enqueued EOS yet - -// These are extensions to OpenMAX AL 1.0.1 values - -#define PREFETCHSTATUS_UNKNOWN ((XAuint32) 0) -#define PREFETCHSTATUS_ERROR ((XAuint32) (-1)) - -// Mutex and condition shared with main program to protect prefetch_status - -static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; -XAuint32 prefetch_status = PREFETCHSTATUS_UNKNOWN; - -/* used to detect errors likely to have occured when the OpenMAX AL framework fails to open - * a resource, for instance because a file URI is invalid, or an HTTP server doesn't respond. - */ -#define PREFETCHEVENT_ERROR_CANDIDATE \ - (XA_PREFETCHEVENT_STATUSCHANGE | XA_PREFETCHEVENT_FILLLEVELCHANGE) - -// stream event change callback -void streamEventChangeCallback(XAStreamInformationItf caller, XAuint32 eventId, - XAuint32 streamIndex, void *pEventData, void *pContext) -{ - // context parameter is specified as NULL and is unused here - assert(NULL == pContext); - switch (eventId) { - case XA_STREAMCBEVENT_PROPERTYCHANGE: - printf("XA_STREAMCBEVENT_PROPERTYCHANGE on stream index %u, pEventData %p\n", streamIndex, - pEventData); - break; - default: - printf("Unknown stream event ID %u\n", eventId); - break; - } -} - -// prefetch status callback -void prefetchStatusCallback(XAPrefetchStatusItf caller, void *pContext, XAuint32 event) -{ - // pContext is unused here, so we pass NULL - assert(pContext == NULL); - XApermille level = 0; - XAresult result; - result = (*caller)->GetFillLevel(caller, &level); - assert(XA_RESULT_SUCCESS == result); - XAuint32 status; - result = (*caller)->GetPrefetchStatus(caller, &status); - assert(XA_RESULT_SUCCESS == result); - if (event & XA_PREFETCHEVENT_FILLLEVELCHANGE) { - printf("PrefetchEventCallback: Buffer fill level is = %d\n", level); - } - if (event & XA_PREFETCHEVENT_STATUSCHANGE) { - printf("PrefetchEventCallback: Prefetch Status is = %u\n", status); - } - XAuint32 new_prefetch_status; - if ((PREFETCHEVENT_ERROR_CANDIDATE == (event & PREFETCHEVENT_ERROR_CANDIDATE)) - && (level == 0) && (status == XA_PREFETCHSTATUS_UNDERFLOW)) { - printf("PrefetchEventCallback: Error while prefetching data, exiting\n"); - new_prefetch_status = PREFETCHSTATUS_ERROR; - } else if (event == XA_PREFETCHEVENT_STATUSCHANGE) { - new_prefetch_status = status; - } else { - return; - } - int ok; - ok = pthread_mutex_lock(&mutex); - assert(ok == 0); - prefetch_status = new_prefetch_status; - ok = pthread_cond_signal(&cond); - assert(ok == 0); - ok = pthread_mutex_unlock(&mutex); - assert(ok == 0); -} - -// playback event callback -void playEventCallback(XAPlayItf caller, void *pContext, XAuint32 event) -{ - // pContext is unused here, so we pass NULL - assert(NULL == pContext); - - XAresult result; - XAmillisecond position; - result = (*caller)->GetPosition(caller, &position); - assert(XA_RESULT_SUCCESS == result); - - if (XA_PLAYEVENT_HEADATEND & event) { - printf("XA_PLAYEVENT_HEADATEND current position=%u ms\n", position); - } - - if (XA_PLAYEVENT_HEADATNEWPOS & event) { - printf("XA_PLAYEVENT_HEADATNEWPOS current position=%u ms\n", position); - } - - if (XA_PLAYEVENT_HEADATMARKER & event) { - printf("XA_PLAYEVENT_HEADATMARKER current position=%u ms\n", position); - } -} - -// Android buffer queue callback -XAresult bufferQueueCallback( - XAAndroidBufferQueueItf caller, - void *pCallbackContext, - void *pBufferContext, - void *pBufferData, - XAuint32 dataSize, - XAuint32 dataUsed, - const XAAndroidBufferItem *pItems, - XAuint32 itemsLength) -{ - XAPlayItf playerPlay = (XAPlayItf) pCallbackContext; - // enqueue the .ts data directly from mapped memory, so ignore the empty buffer pBufferData - if (curPacket <= lastPacket) { - static const XAAndroidBufferItem discontinuity = {XA_ANDROID_ITEMKEY_DISCONTINUITY, 0}; - static const XAAndroidBufferItem eos = {XA_ANDROID_ITEMKEY_EOS, 0}; - static const XAAndroidBufferItem formatChange = {XA_ANDROID_ITEMKEY_FORMAT_CHANGE, 0}; - const XAAndroidBufferItem *items; - XAuint32 itemSize; - // compute number of packets to be enqueued in this buffer - XAuint32 packetsThisBuffer = lastPacket - curPacket; - if (packetsThisBuffer > PACKETS_PER_BUFFER) { - packetsThisBuffer = PACKETS_PER_BUFFER; - } - // last packet? this should only happen once - if (curPacket == lastPacket) { - if (sentEOS) { - printf("buffer completion callback after EOS\n"); - return XA_RESULT_SUCCESS; - } - printf("sending EOS\n"); - items = &eos; - itemSize = sizeof(eos); - sentEOS = XA_BOOLEAN_TRUE; - // discontinuity requested? - } else if (curPacket == discPacket) { - printf("sending discontinuity at packet %zu, then resuming at packet %zu\n", discPacket, - afterDiscPacket); - items = &discontinuity; - itemSize = sizeof(discontinuity); - curPacket = afterDiscPacket; - // format change requested? - } else if (curPacket == formatPacket) { - printf("sending format change"); - items = &formatChange; - itemSize = sizeof(formatChange); - // pure data with no items - } else { - items = NULL; - itemSize = 0; - } - XAresult result; - // enqueue the optional data and optional items; there is always at least one or the other - assert(packetsThisBuffer > 0 || itemSize > 0); - result = (*caller)->Enqueue(caller, NULL, &packets[curPacket], - sizeof(MPEG2TS_Packet) * packetsThisBuffer, items, itemSize); - assert(XA_RESULT_SUCCESS == result); - curPacket += packetsThisBuffer; - // display position periodically - if (curPacket % 1000 == 0) { - XAmillisecond position; - result = (*playerPlay)->GetPosition(playerPlay, &position); - assert(XA_RESULT_SUCCESS == result); - printf("Position after enqueueing packet %u: %u ms\n", curPacket, position); - } - } - if (forceCallbackFailure && (curPacket % 1230 == 0)) { - return (XAresult) curPacket; - } else { - return XA_RESULT_SUCCESS; - } -} - -// convert a domain type to string -static const char *domainToString(XAuint32 domain) -{ - switch (domain) { - case 0: // FIXME There's a private declaration '#define XA_DOMAINTYPE_CONTAINER 0' in src/data.h - // but we don't have access to it. Plan to file a bug with Khronos about this symbol. - return "media container"; -#define _(x) case x: return #x; - _(XA_DOMAINTYPE_AUDIO) - _(XA_DOMAINTYPE_VIDEO) - _(XA_DOMAINTYPE_IMAGE) - _(XA_DOMAINTYPE_TIMEDTEXT) - _(XA_DOMAINTYPE_MIDI) - _(XA_DOMAINTYPE_VENDOR) - _(XA_DOMAINTYPE_UNKNOWN) -#undef _ - default: - return "unknown"; - } -} - -// main program -int main(int argc, char **argv) -{ - const char *prog = argv[0]; - int i; - - XAboolean abq = XA_BOOLEAN_FALSE; // use AndroidBufferQueue, default is URI - XAboolean looping = XA_BOOLEAN_FALSE; - for (i = 1; i < argc; ++i) { - const char *arg = argv[i]; - if (arg[0] != '-') - break; - switch (arg[1]) { - case 'a': - abq = XA_BOOLEAN_TRUE; - break; - case 'c': - forceCallbackFailure = XA_BOOLEAN_TRUE; - break; - case 'd': - discPacket = atoi(&arg[2]); - break; - case 'D': - afterDiscPacket = atoi(&arg[2]); - break; - case 'f': - firstPacket = atoi(&arg[2]); - break; - case 'F': - formatPacket = atoi(&arg[2]); - break; - case 'l': - looping = XA_BOOLEAN_TRUE; - break; - case 'n': - numPackets = atoi(&arg[2]); - break; - case 'p': - pauseMs = atoi(&arg[2]); - break; - case 's': - seekPos = atoi(&arg[2]); - break; - default: - fprintf(stderr, "%s: unknown option %s\n", prog, arg); - break; - } - } - - // check that exactly one URI was specified - if (argc - i != 1) { - fprintf(stderr, "usage: %s [-a] [-c] [-d#] [-D#] [-f#] [-F#] [-l] [-n#] [-p#] [-s#] uri\n", - prog); - fprintf(stderr, " -a Use Android buffer queue to supply data, default is URI\n"); - fprintf(stderr, " -c Force callback to return an error randomly, for debugging only\n"); - fprintf(stderr, " -d# Packet index to insert a discontinuity, default is none\n"); - fprintf(stderr, " -D# Packet index to switch to after the discontinuity\n"); - fprintf(stderr, " -f# First packet index, defaults to 0\n"); - fprintf(stderr, " -F# Packet index to insert a format change, default is none\n"); - fprintf(stderr, " -l Enable looping, for URI only\n"); - fprintf(stderr, " -n# Number of packets to enqueue\n"); - fprintf(stderr, " -p# Pause playback for 5 seconds after this many milliseconds\n"); - fprintf(stderr, " -s# Seek position in milliseconds, for URI only\n"); - return EXIT_FAILURE; - } - const char *uri = argv[i]; - - // for AndroidBufferQueue, interpret URI as a filename and open - int fd = -1; - if (abq) { - fd = open(uri, O_RDONLY); - if (fd < 0) { - perror(uri); - goto close; - } - int ok; - struct stat statbuf; - ok = fstat(fd, &statbuf); - if (ok < 0) { - perror(uri); - goto close; - } - if (!S_ISREG(statbuf.st_mode)) { - fprintf(stderr, "%s: not an ordinary file\n", uri); - goto close; - } - void *ptr; - ptr = mmap(NULL, statbuf.st_size, PROT_READ, MAP_FILE | MAP_PRIVATE, fd, (off_t) 0); - if (ptr == MAP_FAILED) { - perror(uri); - goto close; - } - size_t filelen = statbuf.st_size; - if ((filelen % MPEG2TS_PACKET_SIZE) != 0) { - fprintf(stderr, "%s: warning file length %zu is not a multiple of %d\n", uri, filelen, - MPEG2TS_PACKET_SIZE); - } - packets = (MPEG2TS_Packet *) ptr; - totalPackets = filelen / MPEG2TS_PACKET_SIZE; - printf("%s has %zu total packets\n", uri, totalPackets); - if (firstPacket >= totalPackets) { - fprintf(stderr, "-f%zu ignored\n", firstPacket); - firstPacket = 0; - } - if (numPackets == 0) { - numPackets = totalPackets - firstPacket; - } else if (firstPacket + numPackets > totalPackets) { - fprintf(stderr, "-n%zu ignored\n", numPackets); - numPackets = totalPackets - firstPacket; - } - lastPacket = firstPacket + numPackets; - if (discPacket != 0 && (discPacket < firstPacket || discPacket >= lastPacket)) { - fprintf(stderr, "-d%zu ignored\n", discPacket); - discPacket = 0; - } - if (afterDiscPacket < firstPacket || afterDiscPacket >= lastPacket) { - fprintf(stderr, "-D%zu ignored\n", afterDiscPacket); - afterDiscPacket = 0; - } - if (formatPacket != 0 && (formatPacket < firstPacket || formatPacket >= lastPacket)) { - fprintf(stderr, "-F%zu ignored\n", formatPacket); - formatPacket = 0; - } - } - - ANativeWindow *nativeWindow; - - XAresult result; - XAObjectItf engineObject; - - // create engine - result = xaCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL); - assert(XA_RESULT_SUCCESS == result); - result = (*engineObject)->Realize(engineObject, XA_BOOLEAN_FALSE); - assert(XA_RESULT_SUCCESS == result); - XAEngineItf engineEngine; - result = (*engineObject)->GetInterface(engineObject, XA_IID_ENGINE, &engineEngine); - assert(XA_RESULT_SUCCESS == result); - - // create output mix - XAObjectItf outputMixObject; - result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 0, NULL, NULL); - assert(XA_RESULT_SUCCESS == result); - result = (*outputMixObject)->Realize(outputMixObject, XA_BOOLEAN_FALSE); - assert(XA_RESULT_SUCCESS == result); - - // configure media source - XADataLocator_URI locUri; - locUri.locatorType = XA_DATALOCATOR_URI; - locUri.URI = (XAchar *) uri; - XADataFormat_MIME fmtMime; - fmtMime.formatType = XA_DATAFORMAT_MIME; - if (abq) { - fmtMime.mimeType = (XAchar *) XA_ANDROID_MIME_MP2TS; - fmtMime.containerType = XA_CONTAINERTYPE_MPEG_TS; - } else { - fmtMime.mimeType = NULL; - fmtMime.containerType = XA_CONTAINERTYPE_UNSPECIFIED; - } - XADataLocator_AndroidBufferQueue locABQ; - locABQ.locatorType = XA_DATALOCATOR_ANDROIDBUFFERQUEUE; - locABQ.numBuffers = NB_BUFFERS; - XADataSource dataSrc; - if (abq) { - dataSrc.pLocator = &locABQ; - } else { - dataSrc.pLocator = &locUri; - } - dataSrc.pFormat = &fmtMime; - - // configure audio sink - XADataLocator_OutputMix locOM; - locOM.locatorType = XA_DATALOCATOR_OUTPUTMIX; - locOM.outputMix = outputMixObject; - XADataSink audioSnk; - audioSnk.pLocator = &locOM; - audioSnk.pFormat = NULL; - - // configure video sink - nativeWindow = getNativeWindow(); - XADataLocator_NativeDisplay locND; - locND.locatorType = XA_DATALOCATOR_NATIVEDISPLAY; - locND.hWindow = nativeWindow; - locND.hDisplay = NULL; - XADataSink imageVideoSink; - imageVideoSink.pLocator = &locND; - imageVideoSink.pFormat = NULL; - - // create media player - XAObjectItf playerObject; - XAInterfaceID ids[4] = {XA_IID_STREAMINFORMATION, XA_IID_PREFETCHSTATUS, XA_IID_SEEK, - XA_IID_ANDROIDBUFFERQUEUESOURCE}; - XAboolean req[4] = {XA_BOOLEAN_TRUE, XA_BOOLEAN_TRUE, XA_BOOLEAN_FALSE, XA_BOOLEAN_TRUE}; - result = (*engineEngine)->CreateMediaPlayer(engineEngine, &playerObject, &dataSrc, NULL, - &audioSnk, nativeWindow != NULL ? &imageVideoSink : NULL, NULL, NULL, abq ? 4 : 3, ids, - req); - assert(XA_RESULT_SUCCESS == result); - - // realize the player - result = (*playerObject)->Realize(playerObject, XA_BOOLEAN_FALSE); - assert(XA_RESULT_SUCCESS == result); - - // get the play interface - XAPlayItf playerPlay; - result = (*playerObject)->GetInterface(playerObject, XA_IID_PLAY, &playerPlay); - assert(XA_RESULT_SUCCESS == result); - - if (abq) { - - // get the Android buffer queue interface - XAAndroidBufferQueueItf playerAndroidBufferQueue; - result = (*playerObject)->GetInterface(playerObject, XA_IID_ANDROIDBUFFERQUEUESOURCE, - &playerAndroidBufferQueue); - assert(XA_RESULT_SUCCESS == result); - - // register the buffer queue callback - result = (*playerAndroidBufferQueue)->RegisterCallback(playerAndroidBufferQueue, - bufferQueueCallback, (void *) playerPlay); - assert(XA_RESULT_SUCCESS == result); - result = (*playerAndroidBufferQueue)->SetCallbackEventsMask(playerAndroidBufferQueue, - XA_ANDROIDBUFFERQUEUEEVENT_PROCESSED); - assert(XA_RESULT_SUCCESS == result); - - // set the player's state to paused, to start prefetching - printf("start early prefetch\n"); - result = (*playerPlay)->SetPlayState(playerPlay, XA_PLAYSTATE_PAUSED); - assert(XA_RESULT_SUCCESS == result); - - // enqueue the initial buffers until buffer queue is full - XAuint32 packetsThisBuffer; - for (curPacket = firstPacket; curPacket < lastPacket; curPacket += packetsThisBuffer) { - // handle the unlikely case of a very short .ts - packetsThisBuffer = lastPacket - curPacket; - if (packetsThisBuffer > PACKETS_PER_BUFFER) { - packetsThisBuffer = PACKETS_PER_BUFFER; - } - result = (*playerAndroidBufferQueue)->Enqueue(playerAndroidBufferQueue, NULL, - &packets[curPacket], MPEG2TS_PACKET_SIZE * packetsThisBuffer, NULL, 0); - if (XA_RESULT_BUFFER_INSUFFICIENT == result) { - printf("Enqueued initial %u packets in %u buffers\n", curPacket - firstPacket, - (curPacket - firstPacket + PACKETS_PER_BUFFER - 1) / PACKETS_PER_BUFFER); - break; - } - assert(XA_RESULT_SUCCESS == result); - } - - } - - // get the stream information interface - XAStreamInformationItf playerStreamInformation; - result = (*playerObject)->GetInterface(playerObject, XA_IID_STREAMINFORMATION, - &playerStreamInformation); - assert(XA_RESULT_SUCCESS == result); - - // register the stream event change callback - result = (*playerStreamInformation)->RegisterStreamChangeCallback(playerStreamInformation, - streamEventChangeCallback, NULL); - assert(XA_RESULT_SUCCESS == result); - - // get the prefetch status interface - XAPrefetchStatusItf playerPrefetchStatus; - result = (*playerObject)->GetInterface(playerObject, XA_IID_PREFETCHSTATUS, - &playerPrefetchStatus); - assert(XA_RESULT_SUCCESS == result); - - // register prefetch status callback - result = (*playerPrefetchStatus)->RegisterCallback(playerPrefetchStatus, prefetchStatusCallback, - NULL); - assert(XA_RESULT_SUCCESS == result); - result = (*playerPrefetchStatus)->SetCallbackEventsMask(playerPrefetchStatus, - XA_PREFETCHEVENT_FILLLEVELCHANGE | XA_PREFETCHEVENT_STATUSCHANGE); - assert(XA_RESULT_SUCCESS == result); - - // get the seek interface for seeking and/or looping - if (looping || seekPos != XA_TIME_UNKNOWN) { - XASeekItf playerSeek; - result = (*playerObject)->GetInterface(playerObject, XA_IID_SEEK, &playerSeek); - assert(XA_RESULT_SUCCESS == result); - if (seekPos != XA_TIME_UNKNOWN) { - result = (*playerSeek)->SetPosition(playerSeek, seekPos, XA_SEEKMODE_ACCURATE); - if (XA_RESULT_FEATURE_UNSUPPORTED == result) { - fprintf(stderr, "-s%u (seek to initial position) is unsupported\n", seekPos); - } else { - assert(XA_RESULT_SUCCESS == result); - } - } - if (looping) { - result = (*playerSeek)->SetLoop(playerSeek, XA_BOOLEAN_TRUE, (XAmillisecond) 0, - XA_TIME_UNKNOWN); - if (XA_RESULT_FEATURE_UNSUPPORTED) { - fprintf(stderr, "-l (looping) is unsupported\n"); - } else { - assert(XA_RESULT_SUCCESS == result); - } - } - } - - // register play event callback - result = (*playerPlay)->RegisterCallback(playerPlay, playEventCallback, NULL); - assert(XA_RESULT_SUCCESS == result); - result = (*playerPlay)->SetCallbackEventsMask(playerPlay, - XA_PLAYEVENT_HEADATEND | XA_PLAYEVENT_HEADATMARKER | XA_PLAYEVENT_HEADATNEWPOS); - assert(XA_RESULT_SUCCESS == result); - - // set a marker - result = (*playerPlay)->SetMarkerPosition(playerPlay, 5000); - assert(XA_RESULT_SUCCESS == result); - - // set position update period - result = (*playerPlay)->SetPositionUpdatePeriod(playerPlay, 2000); - assert(XA_RESULT_SUCCESS == result); - - // get the position before prefetch - XAmillisecond position; - result = (*playerPlay)->GetPosition(playerPlay, &position); - assert(XA_RESULT_SUCCESS == result); - printf("Position before prefetch: %u ms\n", position); - - // get the duration before prefetch - XAmillisecond duration; - result = (*playerPlay)->GetDuration(playerPlay, &duration); - assert(XA_RESULT_SUCCESS == result); - if (XA_TIME_UNKNOWN == duration) - printf("Duration before prefetch: unknown as expected\n"); - else - printf("Duration before prefetch: %.1f (surprise!)\n", duration / 1000.0f); - - // set the player's state to paused, to start prefetching - printf("start prefetch\n"); - result = (*playerPlay)->SetPlayState(playerPlay, XA_PLAYSTATE_PAUSED); - assert(XA_RESULT_SUCCESS == result); - - // wait for prefetch status callback to indicate either sufficient data or error - pthread_mutex_lock(&mutex); - while (prefetch_status == PREFETCHSTATUS_UNKNOWN) { - pthread_cond_wait(&cond, &mutex); - } - pthread_mutex_unlock(&mutex); - if (prefetch_status == PREFETCHSTATUS_ERROR) { - fprintf(stderr, "Error during prefetch, exiting\n"); - goto destroyRes; - } - - // get the position after prefetch - result = (*playerPlay)->GetPosition(playerPlay, &position); - assert(XA_RESULT_SUCCESS == result); - printf("Position after prefetch: %u ms\n", position); - - // get duration again, now it should be known for the file source or unknown for TS - result = (*playerPlay)->GetDuration(playerPlay, &duration); - assert(XA_RESULT_SUCCESS == result); - if (duration == XA_TIME_UNKNOWN) { - printf("Duration after prefetch: unknown (expected for TS, unexpected for file)\n"); - } else { - printf("Duration after prefetch: %u ms (expected for file, unexpected for TS)\n", duration); - } - - // query for media container information - result = (*playerStreamInformation)->QueryMediaContainerInformation(playerStreamInformation, - NULL); - assert(XA_RESULT_PARAMETER_INVALID == result); - XAMediaContainerInformation mediaContainerInformation; - // this verifies it is filling in all the fields - memset(&mediaContainerInformation, 0x55, sizeof(XAMediaContainerInformation)); - result = (*playerStreamInformation)->QueryMediaContainerInformation(playerStreamInformation, - &mediaContainerInformation); - assert(XA_RESULT_SUCCESS == result); - printf("Media container information:\n"); - printf(" containerType = %u\n", mediaContainerInformation.containerType); - printf(" mediaDuration = %u\n", mediaContainerInformation.mediaDuration); - printf(" numStreams = %u\n", mediaContainerInformation.numStreams); - - // Now query for each the streams. Note that stream indices go up to and including - // mediaContainerInformation.numStreams, because stream 0 is the container itself, - // while stream 1 to mediaContainerInformation.numStreams are the contained streams. - XAuint32 numStreams = mediaContainerInformation.numStreams; - XAuint32 streamIndex; - for (streamIndex = 0; streamIndex <= mediaContainerInformation.numStreams; ++streamIndex) { - XAuint32 domain; - XAuint16 nameSize; - XAchar name[64]; - printf("stream[%u]:\n", streamIndex); - if (streamIndex == 0) { - result = (*playerStreamInformation)->QueryStreamType(playerStreamInformation, - streamIndex, &domain); - assert(XA_RESULT_PARAMETER_INVALID == result); - result = (*playerStreamInformation)->QueryStreamInformation(playerStreamInformation, - streamIndex, &mediaContainerInformation); - //assert(XA_RESULT_PARAMETER_INVALID == result); - nameSize = sizeof(name); - result = (*playerStreamInformation)->QueryStreamName(playerStreamInformation, -streamIndex, &nameSize, name); - //assert(XA_RESULT_PARAMETER_INVALID == result); - continue; - } - result = (*playerStreamInformation)->QueryStreamType(playerStreamInformation, streamIndex, - NULL); - assert(XA_RESULT_PARAMETER_INVALID == result); - domain = 12345; - result = (*playerStreamInformation)->QueryStreamType(playerStreamInformation, streamIndex, - &domain); - assert(XA_RESULT_SUCCESS == result); - printf(" QueryStreamType: domain = 0x%X (%s)\n", domain, domainToString(domain)); - nameSize = sizeof(name); - result = (*playerStreamInformation)->QueryStreamName(playerStreamInformation, streamIndex, - &nameSize, name); -#if 0 - assert(XA_RESULT_SUCCESS == result); - assert(sizeof(name) >= nameSize); - if (sizeof(name) != nameSize) { - assert('\0' == name[nameSize]); - } - printf(" QueryStreamName: nameSize=%u, name=\"%.*s\"\n", nameSize, nameSize, name); - result = (*playerStreamInformation)->QueryStreamInformation(playerStreamInformation, - streamIndex, NULL); - assert(XA_RESULT_PARAMETER_INVALID == result); -#endif - - printf(" QueryStreamInformation:\n"); - switch (domain) { -#if 0 - case 0: // FIXME container - result = (*playerStreamInformation)->QueryStreamInformation(playerStreamInformation, -streamIndex, &mediaContainerInformation); - assert(XA_RESULT_SUCCESS == result); - printf(" containerType = %u (1=unspecified)\n", - mediaContainerInformation.containerType); - printf(" mediaDuration = %u\n", mediaContainerInformation.mediaDuration); - printf(" numStreams = %u\n", mediaContainerInformation.numStreams); - break; -#endif - case XA_DOMAINTYPE_AUDIO: { - XAAudioStreamInformation audioStreamInformation; - memset(&audioStreamInformation, 0x55, sizeof(XAAudioStreamInformation)); - result = (*playerStreamInformation)->QueryStreamInformation(playerStreamInformation, - streamIndex, &audioStreamInformation); - assert(XA_RESULT_PARAMETER_INVALID == result); - printf(" codecId = %u\n", audioStreamInformation.codecId); - printf(" channels = %u\n", audioStreamInformation.channels); - printf(" sampleRate = %u\n", audioStreamInformation.sampleRate); - printf(" bitRate = %u\n", audioStreamInformation.bitRate); - printf(" langCountry = \"%s\"\n", audioStreamInformation.langCountry); - printf(" duration = %u\n", audioStreamInformation.duration); - } break; - case XA_DOMAINTYPE_VIDEO: { - XAVideoStreamInformation videoStreamInformation; - result = (*playerStreamInformation)->QueryStreamInformation(playerStreamInformation, - streamIndex, &videoStreamInformation); - assert(XA_RESULT_SUCCESS == result); - printf(" codecId = %u\n", videoStreamInformation.codecId); - printf(" width = %u\n", videoStreamInformation.width); - printf(" height = %u\n", videoStreamInformation.height); - printf(" frameRate = %u\n", videoStreamInformation.frameRate); - printf(" bitRate = %u\n", videoStreamInformation.bitRate); - printf(" duration = %u\n", videoStreamInformation.duration); - } break; - case XA_DOMAINTYPE_IMAGE: { - XAImageStreamInformation imageStreamInformation; - result = (*playerStreamInformation)->QueryStreamInformation(playerStreamInformation, - streamIndex, &imageStreamInformation); - assert(XA_RESULT_SUCCESS == result); - printf(" codecId = %u\n", imageStreamInformation.codecId); - printf(" width = %u\n", imageStreamInformation.width); - printf(" height = %u\n", imageStreamInformation.height); - printf(" presentationDuration = %u\n", imageStreamInformation.presentationDuration); - } break; - case XA_DOMAINTYPE_TIMEDTEXT: { - XATimedTextStreamInformation timedTextStreamInformation; - result = (*playerStreamInformation)->QueryStreamInformation(playerStreamInformation, - streamIndex, &timedTextStreamInformation); - assert(XA_RESULT_SUCCESS == result); - printf(" layer = %u\n", timedTextStreamInformation.layer); - printf(" width = %u\n", timedTextStreamInformation.width); - printf(" height = %u\n", timedTextStreamInformation.height); - printf(" tx = %u\n", timedTextStreamInformation.tx); - printf(" ty = %u\n", timedTextStreamInformation.ty); - printf(" bitrate = %u\n", timedTextStreamInformation.bitrate); - printf(" langCountry = \"%s\"\n", timedTextStreamInformation.langCountry); - printf(" duration = %u\n", timedTextStreamInformation.duration); - } break; - case XA_DOMAINTYPE_MIDI: { - XAMIDIStreamInformation midiStreamInformation; - result = (*playerStreamInformation)->QueryStreamInformation(playerStreamInformation, - streamIndex, &midiStreamInformation); - assert(XA_RESULT_SUCCESS == result); - printf(" channels = %u\n", midiStreamInformation.channels); - printf(" tracks = %u\n", midiStreamInformation.tracks); - printf(" bankType = %u\n", midiStreamInformation.bankType); - printf(" langCountry = \"%s\"\n", midiStreamInformation.langCountry); - printf(" duration = %u\n", midiStreamInformation.duration); - } break; - case XA_DOMAINTYPE_VENDOR: { - XAVendorStreamInformation vendorStreamInformation; - result = (*playerStreamInformation)->QueryStreamInformation(playerStreamInformation, - streamIndex, &vendorStreamInformation); - assert(XA_RESULT_SUCCESS == result); - printf(" VendorStreamInfo = %p\n", vendorStreamInformation.VendorStreamInfo); - } break; - case XA_DOMAINTYPE_UNKNOWN: { - // "It is not possible to query Information for streams identified as - // XA_DOMAINTYPE_UNKNOWN, any attempt to do so shall return a result of - // XA_RESULT_CONTENT_UNSUPPORTED." - char big[256]; - result = (*playerStreamInformation)->QueryStreamInformation(playerStreamInformation, - streamIndex, &big); - assert(XA_RESULT_CONTENT_UNSUPPORTED == result); - } break; - default: - break; - } - - } - // Try one more stream index beyond the valid range - XAuint32 domain; - result = (*playerStreamInformation)->QueryStreamType(playerStreamInformation, streamIndex, - &domain); - assert(XA_RESULT_PARAMETER_INVALID == result); - XATimedTextStreamInformation big; - result = (*playerStreamInformation)->QueryStreamInformation(playerStreamInformation, - streamIndex, &big); - assert(XA_RESULT_PARAMETER_INVALID == result); - - printf("QueryActiveStreams:\n"); - result = (*playerStreamInformation)->QueryActiveStreams(playerStreamInformation, NULL, NULL); - assert(XA_RESULT_PARAMETER_INVALID == result); - XAuint32 numStreams1 = 0x12345678; - result = (*playerStreamInformation)->QueryActiveStreams(playerStreamInformation, &numStreams1, - NULL); - assert(XA_RESULT_SUCCESS == result); - printf(" numStreams = %u\n", numStreams1); - XAboolean *activeStreams = calloc(numStreams1 + 1, sizeof(XAboolean)); - assert(NULL != activeStreams); - printf(" active stream(s) ="); - XAuint32 numStreams2 = numStreams1; - result = (*playerStreamInformation)->QueryActiveStreams(playerStreamInformation, &numStreams2, - activeStreams); - assert(XA_RESULT_SUCCESS == result); - assert(numStreams2 == numStreams1); - for (streamIndex = 0; streamIndex <= numStreams1; ++streamIndex) { - if (activeStreams[streamIndex]) - printf(" %u", streamIndex); - } - printf("\n"); - - // SetActiveStream is untested - - // start playing - printf("starting to play\n"); - result = (*playerPlay)->SetPlayState(playerPlay, XA_PLAYSTATE_PLAYING); - assert(XA_RESULT_SUCCESS == result); - - // continue playing until end of media - for (;;) { - XAuint32 status; - result = (*playerPlay)->GetPlayState(playerPlay, &status); - assert(XA_RESULT_SUCCESS == result); - if (status == XA_PLAYSTATE_PAUSED) - break; - assert(status == XA_PLAYSTATE_PLAYING); - usleep(100000); - if (pauseMs >= 0) { - result = (*playerPlay)->GetPosition(playerPlay, &position); - assert(XA_RESULT_SUCCESS == result); - if (position >= pauseMs) { - printf("Pausing for 5 seconds at position %u\n", position); - result = (*playerPlay)->SetPlayState(playerPlay, XA_PLAYSTATE_PAUSED); - assert(XA_RESULT_SUCCESS == result); - sleep(5); - // FIXME clear ABQ queue here - result = (*playerPlay)->SetPlayState(playerPlay, XA_PLAYSTATE_PLAYING); - assert(XA_RESULT_SUCCESS == result); - pauseMs = -1; - } - } - } - - // wait a bit more in case of additional callbacks - printf("end of media\n"); - sleep(3); - - // get final position - result = (*playerPlay)->GetPosition(playerPlay, &position); - assert(XA_RESULT_SUCCESS == result); - printf("Position at end: %u ms\n", position); - - // get duration again, now it should be known - result = (*playerPlay)->GetDuration(playerPlay, &duration); - assert(XA_RESULT_SUCCESS == result); - if (duration == XA_TIME_UNKNOWN) { - printf("Duration at end: unknown\n"); - } else { - printf("Duration at end: %u ms\n", duration); - } - -destroyRes: - - // destroy the player - (*playerObject)->Destroy(playerObject); - - // destroy the output mix - (*outputMixObject)->Destroy(outputMixObject); - - // destroy the engine - (*engineObject)->Destroy(engineObject); - -#if 0 - if (nativeWindow != NULL) { - ANativeWindow_release(nativeWindow); - } -#endif - -close: - if (fd >= 0) { - (void) close(fd); - } - - disposeNativeWindow(); - - return EXIT_SUCCESS; -} diff --git a/wilhelm/tools/hashgen/MPH.h b/wilhelm/tools/hashgen/MPH.h deleted file mode 120000 index 1411433f..00000000 --- a/wilhelm/tools/hashgen/MPH.h +++ /dev/null @@ -1 +0,0 @@ -../../src/MPH.h
\ No newline at end of file diff --git a/wilhelm/tools/hashgen/Makefile b/wilhelm/tools/hashgen/Makefile deleted file mode 100644 index 525e2f9b..00000000 --- a/wilhelm/tools/hashgen/Makefile +++ /dev/null @@ -1,65 +0,0 @@ -all : IID_to_MPH.c - -install : IID_to_MPH.c - cp IID_to_MPH.c ../../src/autogen - -CFLAGS = -I../../include -g -DNDEBUG - -%.o : %.c - gcc -c -o $@ $(CFLAGS) $< - -IID_to_MPH.c : part1.c part2.c part3.c part4.c part5.c part6.c part7.c part8.c - $(RM) $@ - cat part1.c part2.c part3.c part4.c part5.c part6.c part7.c part8.c >> $@ - -# part1.c is human-generated - -part2.c : part23in.c - $(RM) $@ - grep '#define MAX_HASH_VALUE' part23in.c > $@ - -part3.c : part23in.c - $(RM) $@ -# was 26,54p - sed -n '/static const unsigned .* asso_values.. =/,/^ };/p' < part23in.c >> $@ - -# part4.c is human-generated - -part5.c : part5gen - ./part5gen > $@ - -# part6.c is human-generated - -part7.c : part23in.c hash.sed -# was 55p - sed -n '/return.*asso_values/p' < part23in.c | sed -f hash.sed >> $@ - -# part8.c is human_generated - -part23in.c : part23in.gperf - gperf --null-strings --readonly-tables --compare-lengths part23in.gperf > part23in.c - -part23in.gperf : frag1 - ./frag1 > part23in.gperf - -frag1 : frag1.o OpenSLES_IID.o - gcc -o $@ $(CFLAGS) frag1.o OpenSLES_IID.o - -part5gen.c : frag2.c part23in.c frag3.c - $(RM) $@ - cp frag2.c $@ - grep '#define MAX_HASH_VALUE' part23in.c >> $@ -# was 81,156p - sed -n '/static const char . const wordlist.. =/,/^ };/p' < part23in.c >> $@ - cat frag3.c >> $@ - -part5gen : part5gen.o OpenSLES_IID.o interfaces.o - gcc -o $@ $(CFLAGS) part5gen.o OpenSLES_IID.o interfaces.o - -clean : - $(RM) part5gen frag1 *.o - $(RM) part23in.gperf part5gen.c part23in.c - $(RM) part2.c part3.c part5.c part7.c - -distclean : clean - $(RM) IID_to_MPH.c diff --git a/wilhelm/tools/hashgen/OpenSLES_IID.c b/wilhelm/tools/hashgen/OpenSLES_IID.c deleted file mode 120000 index 01c15ccb..00000000 --- a/wilhelm/tools/hashgen/OpenSLES_IID.c +++ /dev/null @@ -1 +0,0 @@ -../../src/OpenSLES_IID.c
\ No newline at end of file diff --git a/wilhelm/tools/hashgen/README.txt b/wilhelm/tools/hashgen/README.txt deleted file mode 100644 index 8ec523d5..00000000 --- a/wilhelm/tools/hashgen/README.txt +++ /dev/null @@ -1,17 +0,0 @@ -This re-generates the file IID_to_MPH.c using gperf. -You need to do this after modifying either OpenSLES_IID.c or MPH.c. - -Prerequisites: - * GNU make - * GNU gperf perfect hash generator - -Usage: -Type 'make'. -Diff the old file in ../../src/autogen vs. the newly generated IID_to_MPH.c here. -If the differences look OK, then copy the new IID_to_MPH.c back to - its stable location in ../../src/autogen using 'make install'. -Build and test the usage of the new IID. -Then do 'make clean' or 'make distclean' here. - -hashgen is known to work on Linux with GNU gperf 3.0.3 and GNU sed -version 4.2.1. There are reports of problems on Mac OS X. diff --git a/wilhelm/tools/hashgen/frag1.c b/wilhelm/tools/hashgen/frag1.c deleted file mode 100644 index 5424ed60..00000000 --- a/wilhelm/tools/hashgen/frag1.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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. - */ - -// This program prepares the input to gperf for hashing IIDs - -#include <SLES/OpenSLES.h> -#include "MPH.h" -#include <stdio.h> -#include <stdlib.h> - -extern const struct SLInterfaceID_ SL_IID_array[MPH_MAX]; - -int main(int argc, char **argv) -{ - int MPH; - const struct SLInterfaceID_ *x = SL_IID_array; - for (MPH = 0; MPH < MPH_MAX; ++MPH, ++x) { - unsigned char *y = (unsigned char *) x; - unsigned k; - printf("\""); - for (k = 0; k < sizeof(struct SLInterfaceID_); ++k) - printf("\\x%02X", y[k]); - printf("\"\n"); - } - return EXIT_SUCCESS; -} diff --git a/wilhelm/tools/hashgen/frag2.c b/wilhelm/tools/hashgen/frag2.c deleted file mode 100644 index 6880f37c..00000000 --- a/wilhelm/tools/hashgen/frag2.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <SLES/OpenSLES.h> -#include "MPH.h" -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - diff --git a/wilhelm/tools/hashgen/frag3.c b/wilhelm/tools/hashgen/frag3.c deleted file mode 100644 index 99eb3a0a..00000000 --- a/wilhelm/tools/hashgen/frag3.c +++ /dev/null @@ -1,35 +0,0 @@ - -extern const struct SLInterfaceID_ SL_IID_array[MPH_MAX]; -extern const char * const interface_names[MPH_MAX]; -extern void MPH_to_MPH_string(unsigned MPH, char buffer[40]); - -int main(int argc, char **argv) -{ - int i; - for (i = 0; i <= MAX_HASH_VALUE; ++i) { - const char *x = wordlist[i]; - if (!x) { - printf(" -1"); - } else { - const struct SLInterfaceID_ *xx = SL_IID_array; - unsigned MPH; - for (MPH = 0; MPH < MPH_MAX; ++MPH, ++xx) { - if (!memcmp(x, xx, 16)) { - char buffer[40]; - buffer[39] = 'x'; - MPH_to_MPH_string(MPH, buffer); - assert('x' == buffer[39]); - printf(" %s", buffer); - goto out; - } - } - printf(" (-1)"); -out: - ; - } - if (i < MAX_HASH_VALUE) - printf(","); - printf("\n"); - } - return EXIT_SUCCESS; -} diff --git a/wilhelm/tools/hashgen/hash.sed b/wilhelm/tools/hashgen/hash.sed deleted file mode 100644 index 536e9014..00000000 --- a/wilhelm/tools/hashgen/hash.sed +++ /dev/null @@ -1,3 +0,0 @@ -s/return/ unsigned key =/ -s/(unsigned char)str/((unsigned char *)iid)/g -s/ + / +\n / diff --git a/wilhelm/tools/hashgen/interfaces.c b/wilhelm/tools/hashgen/interfaces.c deleted file mode 120000 index 4b75b6a5..00000000 --- a/wilhelm/tools/hashgen/interfaces.c +++ /dev/null @@ -1 +0,0 @@ -../../src/interfaces.c
\ No newline at end of file diff --git a/wilhelm/tools/hashgen/part1.c b/wilhelm/tools/hashgen/part1.c deleted file mode 100644 index e4097beb..00000000 --- a/wilhelm/tools/hashgen/part1.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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. - */ - -// This file is automagically generated by hashgen, do not edit - -/** \file IID_to_MPH.c Interface ID to MPH mapping */ - -#include <SLES/OpenSLES.h> -#include "MPH.h" -#include <assert.h> -#include <string.h> - -extern const struct SLInterfaceID_ SL_IID_array[MPH_MAX]; - -/** \brief Map SLInterfaceID to its minimal perfect hash (MPH), or -1 if unknown */ - -int IID_to_MPH(const SLInterfaceID iid) -{ diff --git a/wilhelm/tools/hashgen/part4.c b/wilhelm/tools/hashgen/part4.c deleted file mode 100644 index 272bcecf..00000000 --- a/wilhelm/tools/hashgen/part4.c +++ /dev/null @@ -1 +0,0 @@ - static const signed char hash_to_MPH[] = { diff --git a/wilhelm/tools/hashgen/part6.c b/wilhelm/tools/hashgen/part6.c deleted file mode 100644 index e639143b..00000000 --- a/wilhelm/tools/hashgen/part6.c +++ /dev/null @@ -1,4 +0,0 @@ - }; - if (&SL_IID_array[0] <= iid && &SL_IID_array[MPH_MAX] > iid) - return iid - &SL_IID_array[0]; - if (NULL != iid) { diff --git a/wilhelm/tools/hashgen/part8.c b/wilhelm/tools/hashgen/part8.c deleted file mode 100644 index 79a88ab6..00000000 --- a/wilhelm/tools/hashgen/part8.c +++ /dev/null @@ -1,12 +0,0 @@ - if (key <= MAX_HASH_VALUE) { - int MPH = hash_to_MPH[key]; - if (MPH >= 0) { - assert(MPH < MPH_MAX); - SLInterfaceID trial = &SL_IID_array[MPH]; - if (!memcmp(iid, trial, sizeof(struct SLInterfaceID_))) - return MPH; - } - } - } - return -1; -} diff --git a/wilhelm/tools/mphtogen/MPH.h b/wilhelm/tools/mphtogen/MPH.h deleted file mode 120000 index 1411433f..00000000 --- a/wilhelm/tools/mphtogen/MPH.h +++ /dev/null @@ -1 +0,0 @@ -../../src/MPH.h
\ No newline at end of file diff --git a/wilhelm/tools/mphtogen/MPH_to.c b/wilhelm/tools/mphtogen/MPH_to.c deleted file mode 120000 index e362396e..00000000 --- a/wilhelm/tools/mphtogen/MPH_to.c +++ /dev/null @@ -1 +0,0 @@ -../../src/MPH_to.c
\ No newline at end of file diff --git a/wilhelm/tools/mphtogen/MPH_to.h b/wilhelm/tools/mphtogen/MPH_to.h deleted file mode 120000 index 9513f115..00000000 --- a/wilhelm/tools/mphtogen/MPH_to.h +++ /dev/null @@ -1 +0,0 @@ -../../src/MPH_to.h
\ No newline at end of file diff --git a/wilhelm/tools/mphtogen/Makefile b/wilhelm/tools/mphtogen/Makefile deleted file mode 100644 index c6a6fb28..00000000 --- a/wilhelm/tools/mphtogen/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -DIR = ../../src/autogen -ALL = $(DIR)/MPH_to_3DGroup.h $(DIR)/MPH_to_AudioPlayer.h $(DIR)/MPH_to_AudioRecorder.h \ - $(DIR)/MPH_to_Engine.h $(DIR)/MPH_to_LEDDevice.h $(DIR)/MPH_to_Listener.h \ - $(DIR)/MPH_to_MetadataExtractor.h $(DIR)/MPH_to_MidiPlayer.h $(DIR)/MPH_to_OutputMix.h \ - $(DIR)/MPH_to_Vibra.h - -$(ALL) : mphtogen - ./mphtogen - -mphtogen : mphtogen.c MPH_to.c MPH.h MPH_to.h -# Add -DANDROID if both (a) building for Android, and (b) not -# using -DUSE_DESIGNATED_INITIALIZERS in ../../src/Android.mk - gcc -o $@ -DUSE_DESIGNATED_INITIALIZERS mphtogen.c MPH_to.c - -clean : - $(RM) mphtogen diff --git a/wilhelm/tools/mphtogen/README.txt b/wilhelm/tools/mphtogen/README.txt deleted file mode 100644 index 4ff0a099..00000000 --- a/wilhelm/tools/mphtogen/README.txt +++ /dev/null @@ -1,11 +0,0 @@ -This re-generates the file MPH_to_*.h. -You need to do this after modifying any of the MPH-related files. - -Prerequisites: - * GNU make - -Usage: -Type 'make'. -Diff the new files in ../../src/autogen vs. the new ones as sanity check. -Build and test using the new header files. -Then do 'make clean' here. diff --git a/wilhelm/tools/mphtogen/mphtogen.c b/wilhelm/tools/mphtogen/mphtogen.c deleted file mode 100644 index 91492021..00000000 --- a/wilhelm/tools/mphtogen/mphtogen.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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. - */ - -// Generate the MPH_to_*.h tables for C compilers that don't support designated initializers - -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> -#include "MPH.h" -#include "MPH_to.h" - -static void convert(const signed char MPH_to[MPH_MAX], const char *filename) -{ - FILE *fp = fopen(filename, "w"); - assert(NULL != fp); - fputs("// This file is automagically generated by mphtogen, do not edit\n", fp); - unsigned i; - unsigned len = 0; - for (i = 0; i < MPH_MAX; ++i) { - if (len > 0) { - fputc(',', fp); - ++len; - } - if (len > 78) { - fputc('\n', fp); - len = 0; - } - fprintf(fp, "%3d", MPH_to[i]); - len += 3; - } - if (len > 0) { - fputc('\n', fp); - } - fclose(fp); -} - -#define _(x) convert(MPH_to_##x, "../../src/autogen/MPH_to_" #x ".h"); - -int main(int argc, char **argv) -{ - _(3DGroup) - _(AudioPlayer) - _(AudioRecorder) - _(Engine) - _(LEDDevice) - _(Listener) - _(MetadataExtractor) - _(MidiPlayer) - _(OutputMix) - _(Vibra) - _(MediaPlayer) - return EXIT_SUCCESS; -} diff --git a/wilhelm/tools/permute/Makefile b/wilhelm/tools/permute/Makefile deleted file mode 100644 index 65ed44d5..00000000 --- a/wilhelm/tools/permute/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -permute : permute.c - gcc -o $@ -Wall permute.c -lsndfile - -clean : - $(RM) $@ diff --git a/wilhelm/tools/permute/permute.c b/wilhelm/tools/permute/permute.c deleted file mode 100644 index 4b6522ed..00000000 --- a/wilhelm/tools/permute/permute.c +++ /dev/null @@ -1,342 +0,0 @@ -/* - * 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. - */ - -/** Permute is a host tool to randomly permute an audio file. - * It takes as input an ordinary .wav file and produces as output a - * permuted .wav file and .map which can be given the seek torture test - * located in seekTorture.c. A build prerequisite is libsndfile; - * see installation instructions at http://www.mega-nerd.com/libsndfile/ - * The format of the .map file is a sequence of lines, each of which is: - * seek_position_in_ms duration_in_ms - */ - - -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sndfile.h> - - -/** Global variables */ - -// command line options - -// mean length of each segment of the permutation, in seconds -static double meanSegmentLengthSeconds = 5.0; -// minimum length of each segment of the permutation, in seconds -static double minSegmentLengthSeconds = 1.0; - - -/** Describes each contiguous segment generated */ - -typedef struct { - unsigned mFrameStart; - unsigned mFrameLength; - unsigned mPermutedStart; -} Segment; - - -/** Global state during the split phase */ - -typedef struct { - // derived from command line options combined with file properties - unsigned mMinSegmentLengthFrames; - //unsigned mMeanSegmentLengthFrames; - unsigned mSegmentMax; // maximum number of segments allowed - unsigned mSegmentCount; // number of segments generated so far - Segment *mSegmentArray; // storage for the segments [max] -} State; - - -/** Called by qsort as the comparison handler */ - -static int qsortCompare(const void *x, const void *y) -{ - const Segment *x_ = (Segment *) x; - const Segment *y_ = (Segment *) y; - return x_->mFrameStart - y_->mFrameStart; -} - - -/** Split the specified range of frames, using the allowed budget of segments. - * Returns the actual number of segments consumed. - */ - -static unsigned split(State *s, unsigned frameStart, unsigned frameLength, unsigned segmentBudget) -{ - if (frameLength <= 0) - return 0; - assert(segmentBudget > 0); - if ((frameLength <= s->mMinSegmentLengthFrames*2) || (segmentBudget <= 1)) { - assert(s->mSegmentCount < s->mSegmentMax); - Segment *seg = &s->mSegmentArray[s->mSegmentCount++]; - seg->mFrameStart = frameStart; - seg->mFrameLength = frameLength; - seg->mPermutedStart = ~0; - return 1; - } - // slop is how much wiggle room we have to play with - unsigned slop = frameLength - s->mMinSegmentLengthFrames*2; - assert(slop > 0); - // choose a random cut point within the slop region - unsigned r = rand() & 0x7FFFFFFF; - unsigned cut = r % slop; - unsigned leftStart = frameStart; - unsigned leftLength = s->mMinSegmentLengthFrames + cut; - unsigned rightStart = frameStart + leftLength; - unsigned rightLength = s->mMinSegmentLengthFrames + (slop - cut); - assert(leftLength + rightLength == frameLength); - // process the two sides in random order - assert(segmentBudget >= 2); - unsigned used; - if (leftLength <= rightLength) { - used = split(s, leftStart, leftLength, segmentBudget / 2); - used += split(s, rightStart, rightLength, segmentBudget - used); - } else { - used = split(s, rightStart, rightLength, segmentBudget / 2); - used += split(s, leftStart, leftLength, segmentBudget - used); - } - assert(used >= 2); - assert(used <= segmentBudget); - return used; -} - - -/** Permute the specified input file */ - -void permute(char *path_in) -{ - - // Open the file using libsndfile - SNDFILE *sf_in; - SF_INFO sfinfo_in; - sfinfo_in.format = 0; - sf_in = sf_open(path_in, SFM_READ, &sfinfo_in); - if (NULL == sf_in) { - perror(path_in); - return; - } - - // Check if it is a supported file format: must be WAV - unsigned type = sfinfo_in.format & SF_FORMAT_TYPEMASK; - switch (type) { - case SF_FORMAT_WAV: - break; - default: - fprintf(stderr, "%s: unsupported type 0x%X\n", path_in, type); - goto out; - } - - // Must be 16-bit signed or 8-bit unsigned PCM - unsigned subtype = sfinfo_in.format & SF_FORMAT_SUBMASK; - unsigned sampleSizeIn = 0; - switch (subtype) { - case SF_FORMAT_PCM_16: - sampleSizeIn = 2; - break; - case SF_FORMAT_PCM_U8: - sampleSizeIn = 1; - break; - default: - fprintf(stderr, "%s: unsupported subtype 0x%X\n", path_in, subtype); - goto out; - } - // always read shorts - unsigned sampleSizeRead = 2; - - // Must be little-endian - unsigned endianness = sfinfo_in.format & SF_FORMAT_ENDMASK; - switch (endianness) { - case SF_ENDIAN_FILE: - case SF_ENDIAN_LITTLE: - break; - default: - fprintf(stderr, "%s: unsupported endianness 0x%X\n", path_in, endianness); - goto out; - } - - // Must be a known sample rate - switch (sfinfo_in.samplerate) { - case 8000: - case 11025: - case 16000: - case 22050: - case 32000: - case 44100: - case 48000: - break; - default: - fprintf(stderr, "%s: unsupported sample rate %d\n", path_in, sfinfo_in.samplerate); - goto out; - } - - // Must be either stereo or mono - unsigned frameSizeIn = 0; - unsigned frameSizeRead = 0; - switch (sfinfo_in.channels) { - case 1: - case 2: - frameSizeIn = sampleSizeIn * sfinfo_in.channels; - frameSizeRead = sampleSizeRead * sfinfo_in.channels; - break; - default: - fprintf(stderr, "%s: unsupported channels %d\n", path_in, sfinfo_in.channels); - goto out; - } - - // Duration must be known - switch (sfinfo_in.frames) { - case (sf_count_t) 0: - case (sf_count_t) ~0: - fprintf(stderr, "%s: unsupported frames %d\n", path_in, (int) sfinfo_in.frames); - goto out; - default: - break; - } - - // Allocate space to hold the audio data, based on duration - double durationSeconds = (double) sfinfo_in.frames / (double) sfinfo_in.samplerate; - State s; - s.mMinSegmentLengthFrames = minSegmentLengthSeconds * sfinfo_in.samplerate; - if (s.mMinSegmentLengthFrames <= 0) - s.mMinSegmentLengthFrames = 1; - s.mSegmentMax = durationSeconds / meanSegmentLengthSeconds; - if (s.mSegmentMax <= 0) - s.mSegmentMax = 1; - s.mSegmentCount = 0; - s.mSegmentArray = (Segment *) malloc(sizeof(Segment) * s.mSegmentMax); - assert(s.mSegmentArray != NULL); - unsigned used; - used = split(&s, 0, sfinfo_in.frames, s.mSegmentMax); - assert(used <= s.mSegmentMax); - assert(used == s.mSegmentCount); - - // now permute the segments randomly using a bad algorithm - unsigned i; - for (i = 0; i < used; ++i) { - unsigned r = rand() & 0x7FFFFFFF; - unsigned j = r % used; - if (j != i) { - Segment temp = s.mSegmentArray[i]; - s.mSegmentArray[i] = s.mSegmentArray[j]; - s.mSegmentArray[j] = temp; - } - } - - // read the entire file into memory - void *ptr = malloc(sfinfo_in.frames * frameSizeRead); - assert(NULL != ptr); - sf_count_t count; - count = sf_readf_short(sf_in, ptr, sfinfo_in.frames); - if (count != sfinfo_in.frames) { - fprintf(stderr, "%s: expected to read %d frames but actually read %d frames\n", path_in, - (int) sfinfo_in.frames, (int) count); - goto out; - } - - // Create a permuted output file - char *path_out = malloc(strlen(path_in) + 8); - assert(path_out != NULL); - strcpy(path_out, path_in); - strcat(path_out, ".wav"); - SNDFILE *sf_out; - SF_INFO sfinfo_out; - memset(&sfinfo_out, 0, sizeof(SF_INFO)); - sfinfo_out.samplerate = sfinfo_in.samplerate; - sfinfo_out.channels = sfinfo_in.channels; - sfinfo_out.format = sfinfo_in.format; - sf_out = sf_open(path_out, SFM_WRITE, &sfinfo_out); - if (sf_out == NULL) { - perror(path_out); - goto out; - } - unsigned permutedStart = 0; - for (i = 0; i < used; ++i) { - s.mSegmentArray[i].mPermutedStart = permutedStart; - count = sf_writef_short(sf_out, &((short *) ptr)[sfinfo_in.channels * s.mSegmentArray[i] - .mFrameStart], s.mSegmentArray[i].mFrameLength); - if (count != s.mSegmentArray[i].mFrameLength) { - fprintf(stderr, "%s: expected to write %d frames but actually wrote %d frames\n", - path_out, (int) s.mSegmentArray[i].mFrameLength, (int) count); - break; - } - permutedStart += s.mSegmentArray[i].mFrameLength; - } - assert(permutedStart == sfinfo_in.frames); - sf_close(sf_out); - - // now create a seek map to let us play this back in a reasonable order - qsort((void *) s.mSegmentArray, used, sizeof(Segment), qsortCompare); - char *path_map = malloc(strlen(path_in) + 8); - assert(path_map != NULL); - strcpy(path_map, path_in); - strcat(path_map, ".map"); - FILE *fp_map = fopen(path_map, "w"); - if (fp_map == NULL) { - perror(path_map); - } else { - for (i = 0; i < used; ++i) - fprintf(fp_map, "%u %u\n", (unsigned) ((s.mSegmentArray[i].mPermutedStart * 1000.0) / - sfinfo_in.samplerate), (unsigned) ((s.mSegmentArray[i].mFrameLength * 1000.0) / - sfinfo_in.samplerate)); - fclose(fp_map); - } - -out: - // Close the input file - sf_close(sf_in); -} - - -// main program - -int main(int argc, char **argv) -{ - int i; - for (i = 1; i < argc; ++i) { - char *arg = argv[i]; - - // process command line options - if (!strncmp(arg, "-m", 2)) { - double mval = atof(&arg[2]); - if (mval >= 0.1 && mval <= 1000.0) - minSegmentLengthSeconds = mval; - else - fprintf(stderr, "%s: invalid value %s\n", argv[0], arg); - continue; - } - if (!strncmp(arg, "-s", 2)) { - double sval = atof(&arg[2]); - if (sval >= 0.1 && sval <= 1000.0) - meanSegmentLengthSeconds = sval; - else - fprintf(stderr, "%s: invalid value %s\n", argv[0], arg); - continue; - } - if (!strncmp(arg, "-r", 2)) { - srand(atoi(&arg[2])); - continue; - } - if (meanSegmentLengthSeconds < minSegmentLengthSeconds) - meanSegmentLengthSeconds = minSegmentLengthSeconds * 2.0; - - // Permute the file - permute(arg); - - } - return EXIT_SUCCESS; -} diff --git a/wilhelm/tools/permute/readme.txt b/wilhelm/tools/permute/readme.txt deleted file mode 100644 index 44f41593..00000000 --- a/wilhelm/tools/permute/readme.txt +++ /dev/null @@ -1 +0,0 @@ -See comments at top of permute.c for information on how to build and use. |