aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cubeb_audiotrack.c
diff options
context:
space:
mode:
authorMatthew Gregan <[email protected]>2014-11-28 15:56:44 +1300
committerMatthew Gregan <[email protected]>2014-11-28 15:56:57 +1300
commit14d97931da6435d10aa4dcb444896af0314372f4 (patch)
treeb2c68ecd9c10906ae1cf1c8e88a9067b457e0071 /src/cubeb_audiotrack.c
parent2339a62d56fe2d29ed1ea624c36a93a1e424d2a9 (diff)
downloadcubeb-14d97931da6435d10aa4dcb444896af0314372f4.tar.gz
cubeb-14d97931da6435d10aa4dcb444896af0314372f4.zip
clarify and clean up handling of optional functions in the API. fixes #46.
Diffstat (limited to 'src/cubeb_audiotrack.c')
-rw-r--r--src/cubeb_audiotrack.c149
1 files changed, 71 insertions, 78 deletions
diff --git a/src/cubeb_audiotrack.c b/src/cubeb_audiotrack.c
index e2c65d7..e296e1d 100644
--- a/src/cubeb_audiotrack.c
+++ b/src/cubeb_audiotrack.c
@@ -35,14 +35,14 @@
* call dlsym to get the symbol |mangled_name|, handle the error and store the
* pointer in |pointer|. Because depending on Android version, we want different
* symbols, not finding a symbol is not an error. */
-#define DLSYM_DLERROR(mangled_name, pointer, lib) \
- do { \
- pointer = dlsym(lib, mangled_name); \
- if (!pointer) { \
+#define DLSYM_DLERROR(mangled_name, pointer, lib) \
+ do { \
+ pointer = dlsym(lib, mangled_name); \
+ if (!pointer) { \
ALOG("error while loading %stm: %stm\n", mangled_name, dlerror()); \
- } else { \
- ALOG("%stm: OK", mangled_name); \
- } \
+ } else { \
+ ALOG("%stm: OK", mangled_name); \
+ } \
} while(0);
static struct cubeb_ops const audiotrack_ops;
@@ -50,28 +50,28 @@ void audiotrack_destroy(cubeb * context);
void audiotrack_stream_destroy(cubeb_stream * stream);
struct AudioTrack {
- /* only available on ICS and later. The second int paramter is in fact of type audio_stream_type_t. */
+ /* only available on ICS and later. The second int paramter is in fact of type audio_stream_type_t. */
/* static */ status_t (*get_min_frame_count)(int* frame_count, int stream_type, uint32_t rate);
- /* if we have a recent ctor, but can't find the above symbol, we
- * can get the minimum frame count with this signature, and we are
- * running gingerbread. */
+ /* if we have a recent ctor, but can't find the above symbol, we
+ * can get the minimum frame count with this signature, and we are
+ * running gingerbread. */
/* static */ status_t (*get_min_frame_count_gingerbread)(int* frame_count, int stream_type, uint32_t rate);
- /* if this symbol is not availble, and the next one is, we know
- * we are on a Froyo (Android 2.2) device. */
- void* (*ctor)(void* instance, int, unsigned int, int, int, int, unsigned int, void (*)(int, void*, void*), void*, int, int);
- void* (*ctor_froyo)(void* instance, int, unsigned int, int, int, int, unsigned int, void (*)(int, void*, void*), void*, int);
- void* (*dtor)(void* instance);
- void (*start)(void* instance);
- void (*pause)(void* instance);
- uint32_t (*latency)(void* instance);
- status_t (*check)(void* instance);
- status_t (*get_position)(void* instance, uint32_t* position);
- /* only used on froyo. */
+ /* if this symbol is not availble, and the next one is, we know
+ * we are on a Froyo (Android 2.2) device. */
+ void* (*ctor)(void* instance, int, unsigned int, int, int, int, unsigned int, void (*)(int, void*, void*), void*, int, int);
+ void* (*ctor_froyo)(void* instance, int, unsigned int, int, int, int, unsigned int, void (*)(int, void*, void*), void*, int);
+ void* (*dtor)(void* instance);
+ void (*start)(void* instance);
+ void (*pause)(void* instance);
+ uint32_t (*latency)(void* instance);
+ status_t (*check)(void* instance);
+ status_t (*get_position)(void* instance, uint32_t* position);
+ /* only used on froyo. */
/* static */ int (*get_output_frame_count)(int* frame_count, int stream);
/* static */ int (*get_output_latency)(uint32_t* latency, int stream);
/* static */ int (*get_output_samplingrate)(int* samplerate, int stream);
- status_t (*set_marker_position)(void* instance, unsigned int);
- status_t (*set_volume)(void* instance, float left, float right);
+ status_t (*set_marker_position)(void* instance, unsigned int);
+ status_t (*set_volume)(void* instance, float left, float right);
};
struct cubeb {
@@ -97,44 +97,44 @@ audiotrack_refill(int event, void* user, void* info)
{
cubeb_stream * stream = user;
switch (event) {
- case EVENT_MORE_DATA: {
- long got = 0;
- struct Buffer * b = (struct Buffer*)info;
+ case EVENT_MORE_DATA: {
+ long got = 0;
+ struct Buffer * b = (struct Buffer*)info;
- if (stream->draining) {
- return;
- }
-
- got = stream->data_callback(stream, stream->user_ptr, b->raw, b->frameCount);
+ if (stream->draining) {
+ return;
+ }
- stream->written += got;
+ got = stream->data_callback(stream, stream->user_ptr, b->raw, b->frameCount);
- if (got != (long)b->frameCount) {
- uint32_t p;
- stream->draining = 1;
- /* set a marker so we are notified when the are done draining, that is,
- * when every frame has been played by android. */
- stream->context->klass.set_marker_position(stream->instance, stream->written);
- }
+ stream->written += got;
- break;
+ if (got != (long)b->frameCount) {
+ uint32_t p;
+ stream->draining = 1;
+ /* set a marker so we are notified when the are done draining, that is,
+ * when every frame has been played by android. */
+ stream->context->klass.set_marker_position(stream->instance, stream->written);
}
- case EVENT_UNDERRUN:
- ALOG("underrun in cubeb backend.");
- break;
- case EVENT_LOOP_END:
- assert(0 && "We don't support the loop feature of audiotrack.");
- break;
- case EVENT_MARKER:
- assert(stream->draining);
- stream->state_callback(stream, stream->user_ptr, CUBEB_STATE_DRAINED);
- break;
- case EVENT_NEW_POS:
- assert(0 && "We don't support the setPositionUpdatePeriod feature of audiotrack.");
- break;
- case EVENT_BUFFER_END:
- assert(0 && "Should not happen.");
- break;
+
+ break;
+ }
+ case EVENT_UNDERRUN:
+ ALOG("underrun in cubeb backend.");
+ break;
+ case EVENT_LOOP_END:
+ assert(0 && "We don't support the loop feature of audiotrack.");
+ break;
+ case EVENT_MARKER:
+ assert(stream->draining);
+ stream->state_callback(stream, stream->user_ptr, CUBEB_STATE_DRAINED);
+ break;
+ case EVENT_NEW_POS:
+ assert(0 && "We don't support the setPositionUpdatePeriod feature of audiotrack.");
+ break;
+ case EVENT_BUFFER_END:
+ assert(0 && "Should not happen.");
+ break;
}
}
@@ -256,12 +256,12 @@ audiotrack_init(cubeb ** context, char const * context_name)
/* check that we have a combination of symbol that makes sense */
c = &ctx->klass;
if(!((c->ctor || c->ctor_froyo) && /* at least on ctor. */
- c->dtor && c->latency && c->check &&
- /* at least one way to get the minimum frame count to request. */
- ((c->get_output_frame_count && c->get_output_latency && c->get_output_samplingrate) ||
- c->get_min_frame_count ||
- c->get_min_frame_count_gingerbread) &&
- c->start && c->pause && c->get_position && c->set_marker_position)) {
+ c->dtor && c->latency && c->check &&
+ /* at least one way to get the minimum frame count to request. */
+ ((c->get_output_frame_count && c->get_output_latency && c->get_output_samplingrate) ||
+ c->get_min_frame_count ||
+ c->get_min_frame_count_gingerbread) &&
+ c->start && c->pause && c->get_position && c->set_marker_position)) {
ALOG("Could not find all the symbols we need.");
audiotrack_destroy(ctx);
return CUBEB_ERROR;
@@ -286,7 +286,7 @@ audiotrack_get_max_channel_count(cubeb * ctx, uint32_t * max_channels)
assert(ctx && max_channels);
/* The android mixer handles up to two channels, see
- http://androidxref.com/4.2.2_r1/xref/frameworks/av/services/audioflinger/AudioFlinger.h#67 */
+ http://androidxref.com/4.2.2_r1/xref/frameworks/av/services/audioflinger/AudioFlinger.h#67 */
*max_channels = 2;
return CUBEB_OK;
@@ -297,10 +297,10 @@ audiotrack_get_min_latency(cubeb * ctx, cubeb_stream_params params, uint32_t * l
{
/* We always use the lowest latency possible when using this backend (see
* audiotrack_stream_init), so this value is not going to be used. */
- int rv;
+ int r;
- rv = audiotrack_get_min_frame_count(ctx, &params, (int *)latency_ms);
- if (rv != CUBEB_OK) {
+ r = audiotrack_get_min_frame_count(ctx, &params, (int *)latency_ms);
+ if (r != CUBEB_OK) {
return CUBEB_ERROR;
}
@@ -313,11 +313,11 @@ audiotrack_get_min_latency(cubeb * ctx, cubeb_stream_params params, uint32_t * l
static int
audiotrack_get_preferred_sample_rate(cubeb * ctx, uint32_t * rate)
{
- status_t rv;
+ status_t r;
- rv = ctx->klass.get_output_samplingrate((int32_t *)rate, 3 /* MUSIC */);
+ r = ctx->klass.get_output_samplingrate((int32_t *)rate, 3 /* MUSIC */);
- return rv == 0 ? CUBEB_OK : CUBEB_ERROR;
+ return r == 0 ? CUBEB_OK : CUBEB_ERROR;
}
void
@@ -483,13 +483,6 @@ audiotrack_stream_set_volume(cubeb_stream * stream, float volume)
return CUBEB_OK;
}
-int
-audiotrack_stream_set_panning(cubeb_stream * stream, float panning)
-{
- assert(false && "not implemented.");
- return CUBEB_OK;
-}
-
static struct cubeb_ops const audiotrack_ops = {
.init = audiotrack_init,
.get_backend_id = audiotrack_get_backend_id,
@@ -504,7 +497,7 @@ static struct cubeb_ops const audiotrack_ops = {
.stream_get_position = audiotrack_stream_get_position,
.stream_get_latency = audiotrack_stream_get_latency,
.stream_set_volume = audiotrack_stream_set_volume,
- .stream_set_panning = audiotrack_stream_set_panning,
+ .stream_set_panning = NULL,
.stream_get_current_device = NULL,
.stream_device_destroy = NULL,
.stream_register_device_changed_callback = NULL