From acc4fdcdaadd347e9cfb8489d1189a13eaefa54c Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Sat, 13 Jun 2020 14:01:36 +0900 Subject: [PATCH 1/4] ctl: elem_value: split function with two argument into the one with single argument Signed-off-by: Takashi Sakamoto --- src/ctl/alsactl.map | 6 +- src/ctl/elem-value.c | 118 ++++++++++++++++++++++----------------- src/ctl/elem-value.h | 15 +++-- tests/alsactl-elem-value | 6 +- 4 files changed, 85 insertions(+), 60 deletions(-) diff --git a/src/ctl/alsactl.map b/src/ctl/alsactl.map index e82c35fb..396eafd9 100644 --- a/src/ctl/alsactl.map +++ b/src/ctl/alsactl.map @@ -79,8 +79,10 @@ ALSA_GOBJECT_0_0_0 { "alsactl_elem_value_get_enum"; "alsactl_elem_value_set_bytes"; "alsactl_elem_value_get_bytes"; - "alsactl_elem_value_set_iec60958"; - "alsactl_elem_value_get_iec60958"; + "alsactl_elem_value_set_iec60958_user_data"; + "alsactl_elem_value_get_iec60958_user_data"; + "alsactl_elem_value_set_iec60958_channel_status"; + "alsactl_elem_value_get_iec60958_channel_status"; "alsactl_elem_value_set_int64"; "alsactl_elem_value_get_int64"; "alsactl_elem_value_equal"; diff --git a/src/ctl/elem-value.c b/src/ctl/elem-value.c index 95040aee..a37227b4 100644 --- a/src/ctl/elem-value.c +++ b/src/ctl/elem-value.c @@ -283,22 +283,16 @@ void alsactl_elem_value_get_bytes(ALSACtlElemValue *self, } /** - * alsactl_elem_value_set_iec60958: + * alsactl_elem_value_set_iec60958_channel_status: * @self: A #ALSACtlElemValue. - * @channel_status: (array length=channel_status_length)(nullable): The array of - * byte data for channel status bits in IEC 60958. - * @channel_status_length: The number of bytes in channel_status argument, up - * to 24. - * @user_data: (array length=user_data_length)(nullable): The array of byte data - * for user data bits in IEC 60958. - * @user_data_length: The number of bytes in user_data argument, up to 147. + * @status: (array length=length): The array of byte data for channel status + * bits in IEC 60958. + * @length: The number of bytes in channel_status argument, up to 24. * - * Copy a pair of array for channel status and user data of IEC 60958 into - * internal storage. + * Copy the given channel status of IEC 60958 into internal storage. */ -void alsactl_elem_value_set_iec60958(ALSACtlElemValue *self, - const guint8 *channel_status, gsize channel_status_length, - const guint8 *user_data, gsize user_data_length) +void alsactl_elem_value_set_iec60958_channel_status(ALSACtlElemValue *self, + const guint8 *status, gsize length) { ALSACtlElemValuePrivate *priv; struct snd_ctl_elem_value *value; @@ -308,38 +302,47 @@ void alsactl_elem_value_set_iec60958(ALSACtlElemValue *self, priv = alsactl_elem_value_get_instance_private(self); value = &priv->value; - if (channel_status != NULL) { - channel_status_length = MIN(channel_status_length, - G_N_ELEMENTS(value->value.iec958.status)); - for (i = 0; i < channel_status_length; ++i) - value->value.iec958.status[i] = channel_status[i]; - } + length = MIN(length, G_N_ELEMENTS(value->value.iec958.status)); + for (i = 0; i < length; ++i) + value->value.iec958.status[i] = status[i]; +} - if (user_data != NULL) { - user_data_length = MIN(user_data_length, - G_N_ELEMENTS(value->value.iec958.subcode)); - for (i = 0; i < user_data_length; ++i) - value->value.iec958.subcode[i] = user_data[i]; - } +/** + * alsactl_elem_value_get_iec60958_channel_status: + * @self: A #ALSACtlElemValue. + * @status: (array length=length)(inout): The array of byte data for channel + * status bits for IEC 60958 element. + * @length: The number of bytes in status argument, up to 24. + * + * Copy channel status of IEC 60958 from internal storage. + */ +void alsactl_elem_value_get_iec60958_channel_status(ALSACtlElemValue *self, + guint8 *const *status, gsize *length) +{ + ALSACtlElemValuePrivate *priv; + struct snd_ctl_elem_value *value; + int i; + + g_return_if_fail(ALSACTL_IS_ELEM_VALUE(self)); + priv = alsactl_elem_value_get_instance_private(self); + value = &priv->value; + + *length = MIN(*length, G_N_ELEMENTS(value->value.iec958.status)); + for (i = 0; i < *length; ++i) + (*status)[i] = value->value.iec958.status[i]; } /** - * alsactl_elem_value_get_iec60958: + * alsactl_elem_value_set_iec60958_user_data: * @self: A #ALSACtlElemValue. - * @channel_status: (array length=channel_status_length)(inout)(nullable): The - * array of byte data for channel status bits in IEC 60958. - * @channel_status_length: The number of bytes in channel_status argument, up - * to 24. - * @user_data: (array length=user_data_length)(inout)(nullable): The array of - * byte data for user data bits in IEC 60958. - * @user_data_length: The number of bytes in user_data argument, up to 147. + * @data: (array length=length): The array of byte data for user data bits in + * IEC 60958. + * @length: The number of bytes in data argument, up to 147. * - * Copy a pair of array for channel status and user data of IEC 60958 from - * internal storage. + * Copy the given user data of IEC 60958 into internal storage. */ -void alsactl_elem_value_get_iec60958(ALSACtlElemValue *self, - guint8 *const *channel_status, gsize *channel_status_length, - guint8 *const *user_data, gsize *user_data_length) +void alsactl_elem_value_set_iec60958_user_data(ALSACtlElemValue *self, + const guint8 *data, gsize length) { ALSACtlElemValuePrivate *priv; struct snd_ctl_elem_value *value; @@ -349,19 +352,34 @@ void alsactl_elem_value_get_iec60958(ALSACtlElemValue *self, priv = alsactl_elem_value_get_instance_private(self); value = &priv->value; - if (channel_status != NULL) { - *channel_status_length = MIN(*channel_status_length, - G_N_ELEMENTS(value->value.iec958.status)); - for (i = 0; i < *channel_status_length; ++i) - (*channel_status)[i] = value->value.iec958.status[i]; - } + length = MIN(length, G_N_ELEMENTS(value->value.iec958.subcode)); + for (i = 0; i < length; ++i) + value->value.iec958.subcode[i] = data[i]; +} - if (user_data != NULL) { - *user_data_length = MIN(*user_data_length, - G_N_ELEMENTS(value->value.iec958.subcode)); - for (i = 0; i < *user_data_length; ++i) - (*user_data)[i] = value->value.iec958.subcode[i]; - } +/** + * alsactl_elem_value_get_iec60958_user_data: + * @self: A #ALSACtlElemValue. + * @data: (array length=length)(inout): The array of byte data for user data + * bits in IEC 60958. + * @length: The number of bytes in user_data argument, up to 147. + * + * Copy user data of IEC 60958 from internal storage. + */ +void alsactl_elem_value_get_iec60958_user_data(ALSACtlElemValue *self, + guint8 *const *data, gsize *length) +{ + ALSACtlElemValuePrivate *priv; + struct snd_ctl_elem_value *value; + int i; + + g_return_if_fail(ALSACTL_IS_ELEM_VALUE(self)); + priv = alsactl_elem_value_get_instance_private(self); + value = &priv->value; + + *length = MIN(*length, G_N_ELEMENTS(value->value.iec958.subcode)); + for (i = 0; i < *length; ++i) + (*data)[i] = value->value.iec958.subcode[i]; } /** diff --git a/src/ctl/elem-value.h b/src/ctl/elem-value.h index cf7e14bf..5e554edd 100644 --- a/src/ctl/elem-value.h +++ b/src/ctl/elem-value.h @@ -69,12 +69,15 @@ void alsactl_elem_value_set_bytes(ALSACtlElemValue *self, void alsactl_elem_value_get_bytes(ALSACtlElemValue *self, guint8 *const *values, gsize *value_count); -void alsactl_elem_value_set_iec60958(ALSACtlElemValue *self, - const guint8 *channel_status, gsize channel_status_length, - const guint8 *user_data, gsize user_data_length); -void alsactl_elem_value_get_iec60958(ALSACtlElemValue *self, - guint8 *const *channel_status, gsize *channel_status_length, - guint8 *const *user_data, gsize *user_data_length); +void alsactl_elem_value_set_iec60958_channel_status(ALSACtlElemValue *self, + const guint8 *status, gsize length); +void alsactl_elem_value_get_iec60958_channel_status(ALSACtlElemValue *self, + guint8 *const *status, gsize *length); + +void alsactl_elem_value_set_iec60958_user_data(ALSACtlElemValue *self, + const guint8 *data, gsize length); +void alsactl_elem_value_get_iec60958_user_data(ALSACtlElemValue *self, + guint8 *const *data, gsize *length); void alsactl_elem_value_set_int64(ALSACtlElemValue *self, const gint64 *values, gsize value_count); diff --git a/tests/alsactl-elem-value b/tests/alsactl-elem-value index 119fb142..4d1e8f7a 100644 --- a/tests/alsactl-elem-value +++ b/tests/alsactl-elem-value @@ -23,8 +23,10 @@ methods = ( 'get_enum', 'set_bytes', 'get_bytes', - 'set_iec60958', - 'get_iec60958', + 'set_iec60958_user_data', + 'get_iec60958_user_data', + 'set_iec60958_channel_status', + 'get_iec60958_channel_status', 'set_int64', 'get_int64', 'equal', From 441b59fccf2105d3f6471abb61e1db773d42f19b Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Sat, 13 Jun 2020 14:01:36 +0900 Subject: [PATCH 2/4] timer: event: add constructor The constructor is convenient for any test. Signed-off-by: Takashi Sakamoto --- src/timer/alsatimer.map | 1 + src/timer/event.c | 12 ++++++++++++ src/timer/event.h | 2 ++ 3 files changed, 15 insertions(+) diff --git a/src/timer/alsatimer.map b/src/timer/alsatimer.map index f8113048..2ee9c1fe 100644 --- a/src/timer/alsatimer.map +++ b/src/timer/alsatimer.map @@ -64,6 +64,7 @@ ALSA_GOBJECT_0_0_0 { "alsatimer_event_data_tstamp_get_val"; "alsatimer_event_get_type"; + "alsatimer_event_new"; "alsatimer_event_get_tick_data"; "alsatimer_event_get_tstamp_data"; local: diff --git a/src/timer/event.c b/src/timer/event.c index ace15960..1a8c1698 100644 --- a/src/timer/event.c +++ b/src/timer/event.c @@ -19,6 +19,18 @@ ALSATimerEvent *timer_event_copy(const ALSATimerEvent *self) G_DEFINE_BOXED_TYPE(ALSATimerEvent, alsatimer_event, timer_event_copy, g_free) +/** + * alsatimer_event_new: + * + * Allocate and return the instance of #ALSATimerEvent. + * + * Returns: A #ALSATimerEvent. + */ +ALSATimerEvent *alsatimer_event_new() +{ + return g_malloc0(sizeof(ALSATimerEvent)); +} + /** * alsatimer_event_get_tick_data: * @self: A #ALSATimerEvent. diff --git a/src/timer/event.h b/src/timer/event.h index db8ef65f..de7c629d 100644 --- a/src/timer/event.h +++ b/src/timer/event.h @@ -19,6 +19,8 @@ typedef union { GType alsatimer_event_get_type() G_GNUC_CONST; +ALSATimerEvent *alsatimer_event_new(); + void alsatimer_event_get_tick_data(ALSATimerEvent *self, const ALSATimerEventDataTick **tick); From f9ad3b094892d5d5260a70ad69bdd8a7c41940a1 Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Sat, 13 Jun 2020 14:01:36 +0900 Subject: [PATCH 3/4] timer: event_data_tstamp: unify two arguments to single argument for timestamp Signed-off-by: Takashi Sakamoto --- src/timer/event-data-tstamp.c | 11 ++++++----- src/timer/event-data-tstamp.h | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/timer/event-data-tstamp.c b/src/timer/event-data-tstamp.c index 8cd09fb2..a1a307a9 100644 --- a/src/timer/event-data-tstamp.c +++ b/src/timer/event-data-tstamp.c @@ -36,16 +36,17 @@ void alsatimer_event_data_tstamp_get_event(ALSATimerEventDataTstamp *self, /** * alsatimer_event_data_tstamp_get_tstamp: * @self: A #ALSATimerEventDataTstamp. - * @tv_sec: (out): The seconds part of timestamp. - * @tv_nsec: (out): The nanoseconds part of timestamp. + * @tstamp: (array fixed-size=2)(inout): The array with two elements for the + * seconds and nanoseconds part of timestamp when the instance queues + * the timestamp event. * * Get the seconds and nanoseconds part for the timestamp event. */ void alsatimer_event_data_tstamp_get_tstamp(ALSATimerEventDataTstamp *self, - guint *tv_sec, guint *tv_nsec) + gint64 *const tstamp[2]) { - *tv_sec = (guint)self->tstamp.tv_sec; - *tv_nsec = (guint)self->tstamp.tv_nsec; + (*tstamp)[0] = (gint64)self->tstamp.tv_sec; + (*tstamp)[1] = (gint64)self->tstamp.tv_nsec; } /** diff --git a/src/timer/event-data-tstamp.h b/src/timer/event-data-tstamp.h index c3d9bf6c..53e19140 100644 --- a/src/timer/event-data-tstamp.h +++ b/src/timer/event-data-tstamp.h @@ -21,7 +21,7 @@ void alsatimer_event_data_tstamp_get_event(ALSATimerEventDataTstamp *self, ALSATimerEventType *event); void alsatimer_event_data_tstamp_get_tstamp(ALSATimerEventDataTstamp *self, - guint *tv_sec, guint *tv_nsec); + gint64 *const tstamp[2]); void alsatimer_event_data_tstamp_get_val(ALSATimerEventDataTstamp *self, guint *val); From 622762c26b8e6b8e1cd408fbe2e422448e45a625 Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Sat, 13 Jun 2020 14:01:36 +0900 Subject: [PATCH 4/4] timer: instance_status: unify two arguments to single argument for timestamp Signed-off-by: Takashi Sakamoto --- src/timer/instance-status.c | 18 ++++++++++-------- src/timer/instance-status.h | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/timer/instance-status.c b/src/timer/instance-status.c index 3685b139..16ee34c2 100644 --- a/src/timer/instance-status.c +++ b/src/timer/instance-status.c @@ -18,6 +18,7 @@ */ struct _ALSATimerInstanceStatusPrivate { struct snd_timer_status status; + gint64 tstamp[2]; }; G_DEFINE_TYPE_WITH_PRIVATE(ALSATimerInstanceStatus, alsatimer_instance_status, G_TYPE_OBJECT) @@ -103,24 +104,25 @@ static void alsatimer_instance_status_init(ALSATimerInstanceStatus *self) /** * alsatimer_instance_status_get_tstamp: * @self: A #ALSATimerInstanceStatus. - * @tv_sec: (out): The second part of timestamp. - * @tv_nsec: (out): The nano second part of timerstamp. + * @tstamp: (array fixed-size=2)(out)(transfer none): The array with two + * elements for the seconds and nanoseconds parts of timestamp + * when the instance queues the latest event. * - * Get timestamp for the latest update. + * Get timestamp for the latest event. */ void alsatimer_instance_status_get_tstamp(ALSATimerInstanceStatus *self, - guint *tv_sec, guint *tv_nsec) + const gint64 *tstamp[2]) { ALSATimerInstanceStatusPrivate *priv; g_return_if_fail(ALSATIMER_IS_INSTANCE_STATUS(self)); - g_return_if_fail(tv_sec != NULL); - g_return_if_fail(tv_nsec != NULL); + g_return_if_fail(tstamp != NULL); priv = alsatimer_instance_status_get_instance_private(self); - *tv_sec = (guint)priv->status.tstamp.tv_sec; - *tv_nsec = (guint)priv->status.tstamp.tv_nsec; + priv->tstamp[0] = (gint64)priv->status.tstamp.tv_sec; + priv->tstamp[1] = (gint64)priv->status.tstamp.tv_nsec; + *tstamp = (const gint64 *)&priv->tstamp; } void timer_instance_status_refer_private(ALSATimerInstanceStatus *self, diff --git a/src/timer/instance-status.h b/src/timer/instance-status.h index 41d895bb..13bd4177 100644 --- a/src/timer/instance-status.h +++ b/src/timer/instance-status.h @@ -46,7 +46,7 @@ struct _ALSATimerInstanceStatusClass { GType alsatimer_instance_status_get_type() G_GNUC_CONST; void alsatimer_instance_status_get_tstamp(ALSATimerInstanceStatus *self, - guint *tv_sec, guint *tv_nsec); + const gint64 *tstamp[2]); G_END_DECLS