diff --git a/spa/include/spa/event.h b/spa/include/spa/event.h index 2d28dc4e2..2b9c32d74 100644 --- a/spa/include/spa/event.h +++ b/spa/include/spa/event.h @@ -27,6 +27,7 @@ extern "C" { typedef struct _SpaEvent SpaEvent; #include +#include /** * SpaEventType: @@ -35,10 +36,11 @@ typedef struct _SpaEvent SpaEvent; * @SPA_EVENT_TYPE_STOPPED: emited when the STOP command completes * @SPA_EVENT_TYPE_CAN_PULL_OUTPUT: emited when an async node has output that can be pulled * @SPA_EVENT_TYPE_CAN_PUSH_INPUT: emited when more data can be pushed to an async node - * @SPA_EVENT_TYPE_PULL_INPUT: emited when data needs to be provided on an input + * @SPA_EVENT_TYPE_PULL_INPUT: emited when data needs to be provided on an input. data points to + * buffer to fill. * @SPA_EVENT_TYPE_ALLOC_OUTPUT: emited when an output buffer needs to be allocated - * @SPA_EVENT_TYPE_ADD_POLL: emited when a pollfd should be added - * @SPA_EVENT_TYPE_REMOVE_POLL: emited when a pollfd should be removed + * @SPA_EVENT_TYPE_ADD_POLL: emited when a pollfd should be added. data points to #SpaPollItem + * @SPA_EVENT_TYPE_REMOVE_POLL: emited when a pollfd should be removed. data points to #SpaPollItem * @SPA_EVENT_TYPE_DRAINED: emited when DRAIN command completed * @SPA_EVENT_TYPE_MARKER: emited when MARK command completed * @SPA_EVENT_TYPE_ERROR: emited when error occured @@ -69,55 +71,6 @@ struct _SpaEvent { size_t size; }; -/** - * SpaPollFd: - * @fd: a file descriptor - * @events: events to watch - * @revents: events after poll - */ -typedef struct { - int fd; - short events; - short revents; -} SpaPollFd; - - -/** - * SpaPollNotifyData: - * @user_data: user data - * @fds: array of file descriptors - * @n_fds: number of elements in @fds - * @now: the current time - * @timeout: the next desired wakeup time relative to @now - * - * Data passed to #SpaPollNotify. - */ -typedef struct { - void *user_data; - SpaPollFd *fds; - unsigned int n_fds; - uint64_t now; - uint64_t timeout; -} SpaPollNotifyData; - -typedef int (*SpaPollNotify) (SpaPollNotifyData *data); - -/** - * SpaPollItem: - * @fds: array of file descriptors to watch - * @n_fds: number of elements in @fds - * @callback: callback called when there was activity on any of @fds - * @user_data: user data - */ -typedef struct { - SpaPollFd *fds; - unsigned int n_fds; - SpaPollNotify idle_cb; - SpaPollNotify before_cb; - SpaPollNotify after_cb; - void *user_data; -} SpaPollItem; - #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/spa/include/spa/node.h b/spa/include/spa/node.h index 7d6c1792b..1e58d78eb 100644 --- a/spa/include/spa/node.h +++ b/spa/include/spa/node.h @@ -35,6 +35,21 @@ typedef struct _SpaNode SpaNode; #include #include +/** + * SpaPortFormatFlags: + * @SPA_PORT_FORMAT_FLAG_NONE: no flags + * @SPA_PORT_FORMAT_FLAG_TEST_ONLY: just check if the format is accepted + * @SPA_PORT_FORMAT_FLAG_FIXATE: fixate the non-optional unset fields + * @SPA_PORT_FORMAT_FLAG_NEAREST: allow set fields to be rounded to the + * nearest allowed field value. + */ +typedef enum { + SPA_PORT_FORMAT_FLAG_NONE = 0, + SPA_PORT_FORMAT_FLAG_TEST_ONLY = (1 << 0), + SPA_PORT_FORMAT_FLAG_FIXATE = (1 << 1), + SPA_PORT_FORMAT_FLAG_NEAREST = (1 << 2), +} SpaPortFormatFlags; + /** * SpaInputFlags: * @SPA_INPUT_FLAG_NONE: no flag @@ -267,7 +282,7 @@ struct _SpaNode { * SpaNode::port_set_format: * @handle: a #SpaHandle * @port_id: the port to configure - * @test_only: only check if the format is accepted + * @flags: flags * @format: a #SpaFormat with the format * * Set a format on @port_id of @node. @@ -283,10 +298,10 @@ struct _SpaNode { * #SPA_RESULT_WRONG_PROPERTY_TYPE when the type or size of a property * is not correct. */ - SpaResult (*port_set_format) (SpaHandle *handle, - uint32_t port_id, - bool test_only, - const SpaFormat *format); + SpaResult (*port_set_format) (SpaHandle *handle, + uint32_t port_id, + SpaPortFormatFlags flags, + const SpaFormat *format); /** * SpaNode::port_get_format: * @handle: a #SpaHandle diff --git a/spa/include/spa/poll.h b/spa/include/spa/poll.h new file mode 100644 index 000000000..afa21947a --- /dev/null +++ b/spa/include/spa/poll.h @@ -0,0 +1,83 @@ +/* Simple Plugin API + * Copyright (C) 2016 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SPA_POLL_H__ +#define __SPA_POLL_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct _SpaEvent SpaEvent; + +#include + +/** + * SpaPollFd: + * @fd: a file descriptor + * @events: events to watch + * @revents: events after poll + */ +typedef struct { + int fd; + short events; + short revents; +} SpaPollFd; + +/** + * SpaPollNotifyData: + * @user_data: user data + * @fds: array of file descriptors + * @n_fds: number of elements in @fds + * @now: the current time + * @timeout: the next desired wakeup time relative to @now + * + * Data passed to #SpaPollNotify. + */ +typedef struct { + void *user_data; + SpaPollFd *fds; + unsigned int n_fds; + uint64_t now; + uint64_t timeout; +} SpaPollNotifyData; + +typedef int (*SpaPollNotify) (SpaPollNotifyData *data); + +/** + * SpaPollItem: + * @fds: array of file descriptors to watch + * @n_fds: number of elements in @fds + * @callback: callback called when there was activity on any of @fds + * @user_data: user data + */ +typedef struct { + SpaPollFd *fds; + unsigned int n_fds; + SpaPollNotify idle_cb; + SpaPollNotify before_cb; + SpaPollNotify after_cb; + void *user_data; +} SpaPollItem; + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __SPA_POLL_H__ */ diff --git a/spa/plugins/alsa/alsa-sink.c b/spa/plugins/alsa/alsa-sink.c index 38bc18a77..849e36c44 100644 --- a/spa/plugins/alsa/alsa-sink.c +++ b/spa/plugins/alsa/alsa-sink.c @@ -365,10 +365,10 @@ spa_alsa_sink_node_port_enum_formats (SpaHandle *handle, } static SpaResult -spa_alsa_sink_node_port_set_format (SpaHandle *handle, - uint32_t port_id, - bool test_only, - const SpaFormat *format) +spa_alsa_sink_node_port_set_format (SpaHandle *handle, + uint32_t port_id, + SpaPortFormatFlags flags, + const SpaFormat *format) { SpaALSASink *this = (SpaALSASink *) handle; SpaResult res; @@ -387,8 +387,6 @@ spa_alsa_sink_node_port_set_format (SpaHandle *handle, if ((res = spa_audio_raw_format_parse (format, &this->current_format)) < 0) return res; - printf ("format %d\n", this->current_format.info.rate); - this->have_format = true; return SPA_RESULT_OK; diff --git a/spa/plugins/audiomixer/audiomixer.c b/spa/plugins/audiomixer/audiomixer.c index 4aab33801..f0b0c7ab4 100644 --- a/spa/plugins/audiomixer/audiomixer.c +++ b/spa/plugins/audiomixer/audiomixer.c @@ -330,10 +330,10 @@ spa_audiomixer_node_port_enum_formats (SpaHandle *handle, } static SpaResult -spa_audiomixer_node_port_set_format (SpaHandle *handle, - uint32_t port_id, - bool test_only, - const SpaFormat *format) +spa_audiomixer_node_port_set_format (SpaHandle *handle, + uint32_t port_id, + SpaPortFormatFlags flags, + const SpaFormat *format) { SpaAudioMixer *this = (SpaAudioMixer *) handle; SpaResult res; diff --git a/spa/plugins/audiotestsrc/audiotestsrc.c b/spa/plugins/audiotestsrc/audiotestsrc.c index 267b775ab..a8e655aee 100644 --- a/spa/plugins/audiotestsrc/audiotestsrc.c +++ b/spa/plugins/audiotestsrc/audiotestsrc.c @@ -307,10 +307,10 @@ spa_audiotestsrc_node_port_enum_formats (SpaHandle *handle, } static SpaResult -spa_audiotestsrc_node_port_set_format (SpaHandle *handle, - uint32_t port_id, - bool test_only, - const SpaFormat *format) +spa_audiotestsrc_node_port_set_format (SpaHandle *handle, + uint32_t port_id, + SpaPortFormatFlags flags, + const SpaFormat *format) { SpaAudioTestSrc *this = (SpaAudioTestSrc *) handle; SpaResult res; diff --git a/spa/plugins/ffmpeg/ffmpeg-dec.c b/spa/plugins/ffmpeg/ffmpeg-dec.c index 81f77bab1..8afa77c10 100644 --- a/spa/plugins/ffmpeg/ffmpeg-dec.c +++ b/spa/plugins/ffmpeg/ffmpeg-dec.c @@ -278,10 +278,10 @@ spa_ffmpeg_dec_node_port_enum_formats (SpaHandle *handle, } static SpaResult -spa_ffmpeg_dec_node_port_set_format (SpaHandle *handle, - uint32_t port_id, - bool test_only, - const SpaFormat *format) +spa_ffmpeg_dec_node_port_set_format (SpaHandle *handle, + uint32_t port_id, + SpaPortFormatFlags flags, + const SpaFormat *format) { SpaFFMpegDec *this = (SpaFFMpegDec *) handle; SpaFFMpegState *state; @@ -315,7 +315,7 @@ spa_ffmpeg_dec_node_port_set_format (SpaHandle *handle, } else return SPA_RESULT_INVALID_MEDIA_TYPE; - if (!test_only) { + if (!(flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY)) { memcpy (tf, f, fs); state->current_format = tf; } diff --git a/spa/plugins/ffmpeg/ffmpeg-enc.c b/spa/plugins/ffmpeg/ffmpeg-enc.c index b5a4ac177..d4a79f656 100644 --- a/spa/plugins/ffmpeg/ffmpeg-enc.c +++ b/spa/plugins/ffmpeg/ffmpeg-enc.c @@ -278,10 +278,10 @@ spa_ffmpeg_enc_node_port_enum_formats (SpaHandle *handle, } static SpaResult -spa_ffmpeg_enc_node_port_set_format (SpaHandle *handle, - uint32_t port_id, - bool test_only, - const SpaFormat *format) +spa_ffmpeg_enc_node_port_set_format (SpaHandle *handle, + uint32_t port_id, + SpaPortFormatFlags flags, + const SpaFormat *format) { SpaFFMpegEnc *this = (SpaFFMpegEnc *) handle; SpaFFMpegState *state; @@ -315,7 +315,7 @@ spa_ffmpeg_enc_node_port_set_format (SpaHandle *handle, } else return SPA_RESULT_INVALID_MEDIA_TYPE; - if (!test_only) { + if (!(flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY)) { memcpy (tf, f, fs); state->current_format = tf; } diff --git a/spa/plugins/v4l2/v4l2-source.c b/spa/plugins/v4l2/v4l2-source.c index dd52f474c..de08c4ed7 100644 --- a/spa/plugins/v4l2/v4l2-source.c +++ b/spa/plugins/v4l2/v4l2-source.c @@ -331,10 +331,10 @@ spa_v4l2_source_node_port_enum_formats (SpaHandle *handle, } static SpaResult -spa_v4l2_source_node_port_set_format (SpaHandle *handle, - uint32_t port_id, - bool test_only, - const SpaFormat *format) +spa_v4l2_source_node_port_set_format (SpaHandle *handle, + uint32_t port_id, + SpaPortFormatFlags flags, + const SpaFormat *format) { SpaV4l2Source *this = (SpaV4l2Source *) handle; SpaV4l2State *state; @@ -368,10 +368,10 @@ spa_v4l2_source_node_port_set_format (SpaHandle *handle, } else return SPA_RESULT_INVALID_MEDIA_TYPE; - if (spa_v4l2_set_format (this, f, test_only) < 0) + if (spa_v4l2_set_format (this, f, flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY) < 0) return SPA_RESULT_INVALID_MEDIA_TYPE; - if (!test_only) { + if (!(flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY)) { memcpy (tf, f, fs); state->current_format = tf; } diff --git a/spa/plugins/volume/volume.c b/spa/plugins/volume/volume.c index 007acbe5d..9c501c097 100644 --- a/spa/plugins/volume/volume.c +++ b/spa/plugins/volume/volume.c @@ -288,10 +288,10 @@ spa_volume_node_port_enum_formats (SpaHandle *handle, } static SpaResult -spa_volume_node_port_set_format (SpaHandle *handle, - uint32_t port_id, - bool test_only, - const SpaFormat *format) +spa_volume_node_port_set_format (SpaHandle *handle, + uint32_t port_id, + SpaPortFormatFlags flags, + const SpaFormat *format) { SpaVolume *this = (SpaVolume *) handle; SpaResult res; diff --git a/spa/plugins/xv/xv-sink.c b/spa/plugins/xv/xv-sink.c index 203a4978a..b8a5dd556 100644 --- a/spa/plugins/xv/xv-sink.c +++ b/spa/plugins/xv/xv-sink.c @@ -317,10 +317,10 @@ spa_xv_sink_node_port_enum_formats (SpaHandle *handle, } static SpaResult -spa_xv_sink_node_port_set_format (SpaHandle *handle, - uint32_t port_id, - bool test_only, - const SpaFormat *format) +spa_xv_sink_node_port_set_format (SpaHandle *handle, + uint32_t port_id, + SpaPortFormatFlags flags, + const SpaFormat *format) { SpaXvSink *this = (SpaXvSink *) handle; SpaResult res; @@ -351,10 +351,10 @@ spa_xv_sink_node_port_set_format (SpaHandle *handle, } else return SPA_RESULT_INVALID_MEDIA_TYPE; - if (spa_xv_set_format (this, f, test_only) < 0) + if (spa_xv_set_format (this, f, flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY) < 0) return SPA_RESULT_INVALID_MEDIA_TYPE; - if (!test_only) { + if (!(flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY)) { memcpy (tf, f, fs); this->current_format = tf; }