Skip to content

Instantly share code, notes, and snippets.

@drinkcat
Last active December 26, 2015 07:49
Show Gist options
  • Save drinkcat/7117431 to your computer and use it in GitHub Desktop.
Save drinkcat/7117431 to your computer and use it in GitHub Desktop.
CRAS allow 32-bit client to communicate with 64-bit server
# Generate cras/src/test.h that dumps the structures size and field relative offsets
awk 's && /};/ { s = 0; print; }
s { gsub(/[;\[].*$/, ""); gsub(/^.* \**/, ""); print "printf(\" "$0" @ %ld\\n\", (long)&(s." $0 ")-(long)&s);"; }
/^struct [^ ]* {$/ { s=1; print "{ struct " $2 " s; printf(\"sizeof("$2")=%zu\\n\", sizeof(s));" }
' common/cras_iodev_info.h common/cras_messages.h common/cras_types.h common/cras_shm.h > test.h
Then, add in cras/src/libcras/cras_client.c:
int cras_client_create(struct cras_client **client)
{
#include "../test.h"
...
diff --git a/cras/src/alsa_plugin/pcm_cras.c b/cras/src/alsa_plugin/pcm_cras.c
index 09ca39d..7ce80db 100644
--- a/cras/src/alsa_plugin/pcm_cras.c
+++ b/cras/src/alsa_plugin/pcm_cras.c
@@ -37,8 +37,8 @@ struct snd_pcm_cras {
struct cras_client *client;
int capture_sample_index;
int playback_sample_index;
- struct timespec capture_sample_time;
- struct timespec playback_sample_time;
+ struct cras_timespec capture_sample_time;
+ struct cras_timespec playback_sample_time;
};
/* Frees all resources allocated during use. */
@@ -120,8 +120,8 @@ static int pcm_cras_process_cb(struct cras_client *client,
uint8_t *capture_samples,
uint8_t *playback_samples,
unsigned int nframes,
- const struct timespec *capture_ts,
- const struct timespec *playback_ts,
+ const struct cras_timespec *capture_ts,
+ const struct cras_timespec *playback_ts,
void *arg)
{
snd_pcm_ioplug_t *io;
@@ -132,7 +132,7 @@ static int pcm_cras_process_cb(struct cras_client *client,
size_t chan, frame_bytes, sample_bytes;
int rc;
uint8_t *samples;
- const struct timespec *sample_time;
+ const struct cras_timespec *sample_time;
samples = capture_samples ? : playback_samples;
sample_time = capture_ts ? : playback_ts;
@@ -305,7 +305,7 @@ static int snd_pcm_cras_delay(snd_pcm_ioplug_t *io, snd_pcm_sframes_t *delayp)
snd_pcm_uframes_t limit;
int rc;
struct snd_pcm_cras *pcm_cras;
- struct timespec latency;
+ struct cras_timespec latency;
pcm_cras = (struct snd_pcm_cras *)io->private_data;
diff --git a/cras/src/common/cras_audio_format.c b/cras/src/common/cras_audio_format.c
index c869f97..fe411bf 100644
--- a/cras/src/common/cras_audio_format.c
+++ b/cras/src/common/cras_audio_format.c
@@ -11,8 +11,8 @@
/* Create an audio format structure. */
struct cras_audio_format *cras_audio_format_create(snd_pcm_format_t format,
- size_t frame_rate,
- size_t num_channels)
+ aligned_uint64_t frame_rate,
+ aligned_uint64_t num_channels)
{
struct cras_audio_format *fmt;
diff --git a/cras/src/common/cras_fmt_conv.c b/cras/src/common/cras_fmt_conv.c
index ae5f5aa..fb6d052 100644
--- a/cras/src/common/cras_fmt_conv.c
+++ b/cras/src/common/cras_fmt_conv.c
@@ -6,6 +6,7 @@
/* For now just use speex, can add more resamplers later. */
#include <speex/speex_resampler.h>
#include <syslog.h>
+#define syslog(...) do {} while(0)
#include "cras_fmt_conv.h"
#include "cras_types.h"
diff --git a/cras/src/common/cras_iodev_info.h b/cras/src/common/cras_iodev_info.h
index c3e1b9a..38a98b1 100644
--- a/cras/src/common/cras_iodev_info.h
+++ b/cras/src/common/cras_iodev_info.h
@@ -9,6 +9,27 @@
#include <stddef.h>
#include <sys/time.h>
+typedef uint64_t __attribute__((aligned(8))) aligned_uint64_t;
+typedef int64_t __attribute__((aligned(8))) aligned_int64_t;
+
+struct cras_timespec {
+ aligned_int64_t tv_sec;
+ aligned_int64_t tv_nsec;
+};
+
+/*static inline void cras_timespec_to_timespec(struct timespec* tp, const struct cras_timespec* ctp) {
+ tp->tv_sec = ctp->tv_sec;
+ tp->tv_nsec = ctp->tv_nsec;
+}*/
+
+static inline int cras_clock_gettime(clockid_t clk_id, struct cras_timespec *ctp) {
+ struct timespec tp;
+ int ret = clock_gettime(clk_id, &tp);
+ ctp->tv_sec = tp.tv_sec;
+ ctp->tv_nsec = tp.tv_nsec;
+ return ret;
+}
+
#define CRAS_IODEV_NAME_BUFFER_SIZE 64
#define CRAS_NODE_TYPE_BUFFER_SIZE 32
#define CRAS_NODE_NAME_BUFFER_SIZE 64
@@ -37,12 +58,12 @@ struct cras_iodev_info {
struct cras_ionode_info {
uint32_t iodev_idx;
uint32_t ionode_idx;
- size_t priority;
+ aligned_uint64_t priority;
int plugged;
int active;
- struct timeval plugged_time;
+ struct { aligned_int64_t tv_sec; aligned_int64_t tv_usec; } plugged_time;
unsigned int volume;
- long capture_gain;
+ aligned_int64_t capture_gain;
char type[CRAS_NODE_TYPE_BUFFER_SIZE];
char name[CRAS_NODE_NAME_BUFFER_SIZE];
};
diff --git a/cras/src/common/cras_messages.h b/cras/src/common/cras_messages.h
index 6b3e688..967f5d6 100644
--- a/cras/src/common/cras_messages.h
+++ b/cras/src/common/cras_messages.h
@@ -50,15 +50,15 @@ enum CRAS_CLIENT_MESSAGE_ID {
/* Messages that control the server. These are sent from the client to affect
* and action on the server. */
struct cras_server_message {
- size_t length;
- enum CRAS_SERVER_MESSAGE_ID id;
+ aligned_uint64_t length;
+ enum CRAS_SERVER_MESSAGE_ID __attribute__((aligned(8))) id;
};
/* Messages that control the client. These are sent from the server to affect
* and action on the client. */
struct cras_client_message {
- size_t length;
- enum CRAS_CLIENT_MESSAGE_ID id;
+ aligned_uint64_t length;
+ enum CRAS_CLIENT_MESSAGE_ID __attribute__((aligned(8))) id;
};
/*
@@ -68,13 +68,13 @@ struct cras_client_message {
/* Sent by a client to connect a stream to the server. */
struct cras_connect_message {
struct cras_server_message header;
- size_t proto_version;
+ aligned_uint64_t proto_version;
enum CRAS_STREAM_DIRECTION direction; /* input/output/unified */
cras_stream_id_t stream_id; /* unique id for this stream */
enum CRAS_STREAM_TYPE stream_type; /* media, or call, etc. */
- size_t buffer_frames; /* Buffer size in frames. */
- size_t cb_threshold; /* callback client when this much is left */
- size_t min_cb_level; /* don't callback unless this much is avail */
+ aligned_uint64_t buffer_frames; /* Buffer size in frames. */
+ aligned_uint64_t cb_threshold; /* callback client when this much is left */
+ aligned_uint64_t min_cb_level; /* don't callback unless this much is avail */
uint32_t flags;
struct cras_audio_format format; /* rate, channels, sample size */
};
@@ -82,9 +82,9 @@ static inline void cras_fill_connect_message(struct cras_connect_message *m,
enum CRAS_STREAM_DIRECTION direction,
cras_stream_id_t stream_id,
enum CRAS_STREAM_TYPE stream_type,
- size_t buffer_frames,
- size_t cb_threshold,
- size_t min_cb_level,
+ aligned_uint64_t buffer_frames,
+ aligned_uint64_t cb_threshold,
+ aligned_uint64_t min_cb_level,
uint32_t flags,
struct cras_audio_format format)
{
@@ -134,11 +134,11 @@ static inline void fill_cras_switch_stream_type_iodev(
/* Set the system volume. */
struct cras_set_system_volume {
struct cras_server_message header;
- size_t volume;
+ aligned_uint64_t volume;
};
static inline void cras_fill_set_system_volume(
struct cras_set_system_volume *m,
- size_t volume)
+ aligned_uint64_t volume)
{
m->volume = volume;
m->header.id = CRAS_SERVER_SET_SYSTEM_VOLUME;
@@ -148,11 +148,11 @@ static inline void cras_fill_set_system_volume(
/* Sets the capture gain. */
struct cras_set_system_capture_gain {
struct cras_server_message header;
- long gain;
+ aligned_int64_t gain;
};
static inline void cras_fill_set_system_capture_gain(
struct cras_set_system_capture_gain *m,
- long gain)
+ aligned_int64_t gain)
{
m->gain = gain;
m->header.id = CRAS_SERVER_SET_SYSTEM_CAPTURE_GAIN;
@@ -284,12 +284,12 @@ static inline void cras_fill_dump_audio_thread(
/* Reply from the server indicating that the client has connected. */
struct cras_client_connected {
struct cras_client_message header;
- size_t client_id;
+ aligned_uint64_t client_id;
key_t shm_key;
};
static inline void cras_fill_client_connected(
struct cras_client_connected *m,
- size_t client_id,
+ aligned_uint64_t client_id,
key_t shm_key)
{
m->client_id = client_id;
@@ -306,7 +306,7 @@ struct cras_client_stream_connected {
struct cras_audio_format format;
int input_shm_key;
int output_shm_key;
- size_t shm_max_size;
+ aligned_uint64_t shm_max_size;
};
static inline void cras_fill_client_stream_connected(
struct cras_client_stream_connected *m,
@@ -315,7 +315,7 @@ static inline void cras_fill_client_stream_connected(
struct cras_audio_format format,
int input_shm_key,
int output_shm_key,
- size_t shm_max_size)
+ aligned_uint64_t shm_max_size)
{
m->err = err;
m->stream_id = stream_id;
@@ -356,7 +356,7 @@ enum CRAS_AUDIO_MESSAGE_ID {
struct audio_message {
enum CRAS_AUDIO_MESSAGE_ID id;
int error;
- size_t frames; /* number of samples per channel */
+ aligned_uint64_t frames; /* number of samples per channel */
};
#endif /* CRAS_MESSAGES_H_ */
diff --git a/cras/src/common/cras_shm.h b/cras/src/common/cras_shm.h
index cb66799..44ee69e 100644
--- a/cras/src/common/cras_shm.h
+++ b/cras/src/common/cras_shm.h
@@ -49,17 +49,17 @@ struct cras_audio_shm_config {
*/
struct cras_audio_shm_area {
struct cras_audio_shm_config config;
- size_t read_buf_idx; /* use buffer A or B */
- size_t write_buf_idx;
- size_t read_offset[CRAS_NUM_SHM_BUFFERS];
- size_t write_offset[CRAS_NUM_SHM_BUFFERS];
+ aligned_uint64_t read_buf_idx; /* use buffer A or B */
+ aligned_uint64_t write_buf_idx;
+ aligned_uint64_t read_offset[CRAS_NUM_SHM_BUFFERS];
+ aligned_uint64_t write_offset[CRAS_NUM_SHM_BUFFERS];
int write_in_progress[CRAS_NUM_SHM_BUFFERS];
float volume_scaler;
- size_t mute;
- size_t callback_pending;
- size_t num_overruns;
- size_t num_cb_timeouts;
- struct timespec ts;
+ aligned_uint64_t mute;
+ aligned_uint64_t callback_pending;
+ aligned_uint64_t num_overruns;
+ aligned_uint64_t num_cb_timeouts;
+ struct cras_timespec ts;
uint8_t samples[];
};
@@ -75,7 +75,7 @@ struct cras_audio_shm {
/* Get a pointer to the buffer at idx. */
static inline uint8_t *cras_shm_buff_for_idx(struct cras_audio_shm *shm,
- size_t idx)
+ aligned_uint64_t idx)
{
assert_on_compile_is_power_of_2(CRAS_NUM_SHM_BUFFERS);
idx = idx & CRAS_SHM_BUFFERS_MASK;
@@ -147,8 +147,8 @@ uint8_t *cras_shm_get_writeable_frames(struct cras_audio_shm *shm,
* copied from the returned buffer.
*/
static inline int16_t *cras_shm_get_readable_frames(struct cras_audio_shm *shm,
- size_t offset,
- size_t *frames)
+ aligned_uint64_t offset,
+ aligned_uint64_t *frames)
{
unsigned buf_idx = shm->area->read_buf_idx & CRAS_SHM_BUFFERS_MASK;
unsigned read_offset, write_offset, final_offset;
@@ -179,9 +179,9 @@ static inline int16_t *cras_shm_get_readable_frames(struct cras_audio_shm *shm,
}
/* How many bytes are queued? */
-static inline size_t cras_shm_get_bytes_queued(struct cras_audio_shm *shm)
+static inline aligned_uint64_t cras_shm_get_bytes_queued(struct cras_audio_shm *shm)
{
- size_t total, i;
+ aligned_uint64_t total, i;
const unsigned used_size = shm->config.used_size;
total = 0;
@@ -200,7 +200,7 @@ static inline size_t cras_shm_get_bytes_queued(struct cras_audio_shm *shm)
/* How many frames are queued? */
static inline int cras_shm_get_frames(struct cras_audio_shm *shm)
{
- size_t bytes;
+ aligned_uint64_t bytes;
bytes = cras_shm_get_bytes_queued(shm);
if (bytes % shm->config.frame_bytes != 0)
@@ -210,9 +210,9 @@ static inline int cras_shm_get_frames(struct cras_audio_shm *shm)
/* How many frames in the current buffer? */
static inline
-size_t cras_shm_get_frames_in_curr_buffer(struct cras_audio_shm *shm)
+aligned_uint64_t cras_shm_get_frames_in_curr_buffer(struct cras_audio_shm *shm)
{
- size_t buf_idx = shm->area->read_buf_idx & CRAS_SHM_BUFFERS_MASK;
+ aligned_uint64_t buf_idx = shm->area->read_buf_idx & CRAS_SHM_BUFFERS_MASK;
unsigned read_offset, write_offset;
const unsigned used_size = shm->config.used_size;
@@ -228,13 +228,13 @@ size_t cras_shm_get_frames_in_curr_buffer(struct cras_audio_shm *shm)
/* Return 1 if there is an empty buffer in the list. */
static inline int cras_shm_is_buffer_available(struct cras_audio_shm *shm)
{
- size_t buf_idx = shm->area->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
+ aligned_uint64_t buf_idx = shm->area->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
return (shm->area->write_offset[buf_idx] == 0);
}
/* How many are available to be written? */
-static inline size_t cras_shm_get_num_writeable(struct cras_audio_shm *shm)
+static inline aligned_uint64_t cras_shm_get_num_writeable(struct cras_audio_shm *shm)
{
/* Not allowed to write to a buffer twice. */
if (!cras_shm_is_buffer_available(shm))
@@ -246,8 +246,8 @@ static inline size_t cras_shm_get_num_writeable(struct cras_audio_shm *shm)
/* Flags an overrun if writing would cause one. */
static inline void cras_shm_check_write_overrun(struct cras_audio_shm *shm)
{
- size_t write_buf_idx = shm->area->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
- size_t read_buf_idx = shm->area->read_buf_idx & CRAS_SHM_BUFFERS_MASK;
+ aligned_uint64_t write_buf_idx = shm->area->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
+ aligned_uint64_t read_buf_idx = shm->area->read_buf_idx & CRAS_SHM_BUFFERS_MASK;
if (!shm->area->write_in_progress[write_buf_idx]) {
if (write_buf_idx != read_buf_idx)
@@ -260,9 +260,9 @@ static inline void cras_shm_check_write_overrun(struct cras_audio_shm *shm)
/* Increment the write pointer for the current buffer. */
static inline
-void cras_shm_buffer_written(struct cras_audio_shm *shm, size_t frames)
+void cras_shm_buffer_written(struct cras_audio_shm *shm, aligned_uint64_t frames)
{
- size_t buf_idx = shm->area->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
+ aligned_uint64_t buf_idx = shm->area->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
shm->area->write_offset[buf_idx] += frames * shm->config.frame_bytes;
shm->area->read_offset[buf_idx] = 0;
@@ -271,7 +271,7 @@ void cras_shm_buffer_written(struct cras_audio_shm *shm, size_t frames)
/* Returns the number of frames that have been written to the current buffer. */
static inline unsigned int cras_shm_frames_written(struct cras_audio_shm *shm)
{
- size_t buf_idx = shm->area->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
+ aligned_uint64_t buf_idx = shm->area->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
return shm->area->write_offset[buf_idx] / shm->config.frame_bytes;
}
@@ -279,7 +279,7 @@ static inline unsigned int cras_shm_frames_written(struct cras_audio_shm *shm)
/* Signals the writing to this buffer is complete and moves to the next one. */
static inline void cras_shm_buffer_write_complete(struct cras_audio_shm *shm)
{
- size_t buf_idx = shm->area->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
+ aligned_uint64_t buf_idx = shm->area->write_buf_idx & CRAS_SHM_BUFFERS_MASK;
shm->area->write_in_progress[buf_idx] = 0;
@@ -291,10 +291,10 @@ static inline void cras_shm_buffer_write_complete(struct cras_audio_shm *shm)
/* Increment the read pointer. If it goes past the write pointer for this
* buffer, move to the next buffer. */
static inline
-void cras_shm_buffer_read(struct cras_audio_shm *shm, size_t frames)
+void cras_shm_buffer_read(struct cras_audio_shm *shm, aligned_uint64_t frames)
{
- size_t buf_idx = shm->area->read_buf_idx & CRAS_SHM_BUFFERS_MASK;
- size_t remainder;
+ aligned_uint64_t buf_idx = shm->area->read_buf_idx & CRAS_SHM_BUFFERS_MASK;
+ aligned_uint64_t remainder;
struct cras_audio_shm_area *area = shm->area;
struct cras_audio_shm_config *config = &shm->config;
@@ -336,13 +336,13 @@ static inline float cras_shm_get_volume_scaler(struct cras_audio_shm *shm)
}
/* Indicates that the stream should be muted/unmuted */
-static inline void cras_shm_set_mute(struct cras_audio_shm *shm, size_t mute)
+static inline void cras_shm_set_mute(struct cras_audio_shm *shm, aligned_uint64_t mute)
{
shm->area->mute = !!mute;
}
/* Returns the mute state of the stream. 0 if not muted, non-zero if muted. */
-static inline size_t cras_shm_get_mute(struct cras_audio_shm *shm)
+static inline aligned_uint64_t cras_shm_get_mute(struct cras_audio_shm *shm)
{
return shm->area->mute;
}
diff --git a/cras/src/common/cras_types.h b/cras/src/common/cras_types.h
index 1c42822..44e5ba4 100644
--- a/cras/src/common/cras_types.h
+++ b/cras/src/common/cras_types.h
@@ -58,13 +58,13 @@ enum CRAS_STREAM_TYPE {
/* Audio format. */
struct cras_audio_format {
snd_pcm_format_t format;
- size_t frame_rate; /* Hz */
- size_t num_channels;
+ aligned_uint64_t frame_rate; /* Hz */
+ aligned_uint64_t num_channels;
};
/* Information about a client attached to the server. */
struct cras_attached_client_info {
- size_t id;
+ aligned_uint64_t id;
pid_t pid;
uid_t uid;
gid_t gid;
@@ -72,7 +72,7 @@ struct cras_attached_client_info {
/* Each ionode has a unique id. The top 32 bits are the device index, lower 32
* are the node index. */
-typedef uint64_t cras_node_id_t;
+typedef aligned_uint64_t cras_node_id_t;
static inline cras_node_id_t cras_make_node_id(uint32_t dev_index,
uint32_t node_index)
@@ -126,22 +126,22 @@ static inline uint32_t node_index_of(cras_node_id_t id)
* num_active_streams - Number of streams currently playing or recording
* audio.
* last_active_stream_time - Time the last stream was removed. Can be used
- * to determine how long audio has been idle.
+ * to determine how aligned_int64_t audio has been idle.
*/
#define CRAS_SERVER_STATE_VERSION 1
struct cras_server_state {
unsigned state_version;
- size_t volume;
- long min_volume_dBFS;
- long max_volume_dBFS;
+ aligned_uint64_t volume;
+ aligned_int64_t min_volume_dBFS;
+ aligned_int64_t max_volume_dBFS;
int mute;
int user_mute;
int mute_locked;
- long capture_gain;
+ aligned_int64_t capture_gain;
int capture_mute;
int capture_mute_locked;
- long min_capture_gain;
- long max_capture_gain;
+ aligned_int64_t min_capture_gain;
+ aligned_int64_t max_capture_gain;
unsigned num_streams_attached;
unsigned num_output_devs;
unsigned num_input_devs;
@@ -157,7 +157,7 @@ struct cras_server_state {
struct cras_attached_client_info client_info[CRAS_MAX_ATTACHED_CLIENTS];
unsigned update_count;
unsigned num_active_streams;
- struct timespec last_active_stream_time;
+ struct cras_timespec last_active_stream_time;
};
/* Actions for card add/remove/change. */
@@ -192,8 +192,8 @@ struct cras_alsa_card_info {
/* Create an audio format structure. */
struct cras_audio_format *cras_audio_format_create(snd_pcm_format_t format,
- size_t frame_rate,
- size_t num_channels);
+ aligned_uint64_t frame_rate,
+ aligned_uint64_t num_channels);
/* Destroy an audio format struct created with cras_audio_format_crate. */
void cras_audio_format_destroy(struct cras_audio_format *fmt);
@@ -201,7 +201,7 @@ void cras_audio_format_destroy(struct cras_audio_format *fmt);
/* Returns the number of bytes per sample.
* This is bits per smaple / 8 * num_channels.
*/
-static inline size_t cras_get_format_bytes(const struct cras_audio_format *fmt)
+static inline aligned_uint64_t cras_get_format_bytes(const struct cras_audio_format *fmt)
{
const int bytes = snd_pcm_format_physical_width(fmt->format) / 8;
return (size_t)bytes * fmt->num_channels;
diff --git a/cras/src/common/cras_util.h b/cras/src/common/cras_util.h
index 1a6941d..1a9d7d1 100644
--- a/cras/src/common/cras_util.h
+++ b/cras/src/common/cras_util.h
@@ -52,9 +52,9 @@ descriptor, put it in *fd, otherwise set *fd to -1. */
int cras_recv_with_fd(int sockfd, const void *buf, size_t len, int *fd);
/* This must be written a million times... */
-static inline void subtract_timespecs(const struct timespec *end,
- const struct timespec *beg,
- struct timespec *diff)
+static inline void subtract_timespecs(const struct cras_timespec *end,
+ const struct cras_timespec *beg,
+ struct cras_timespec *diff)
{
diff->tv_sec = end->tv_sec - beg->tv_sec;
diff->tv_nsec = end->tv_nsec - beg->tv_nsec;
@@ -78,8 +78,8 @@ static inline int timeval_after(const struct timeval *a,
}
/* Returns true if timespec a is after timespec b */
-static inline int timespec_after(const struct timespec *a,
- const struct timespec *b)
+static inline int timespec_after(const struct cras_timespec *a,
+ const struct cras_timespec *b)
{
return (a->tv_sec > b->tv_sec) ||
(a->tv_sec == b->tv_sec && a->tv_nsec > b->tv_nsec);
diff --git a/cras/src/libcras/cras_client.c b/cras/src/libcras/cras_client.c
index 1f7f21b..3b44c0c 100644
--- a/cras/src/libcras/cras_client.c
+++ b/cras/src/libcras/cras_client.c
@@ -32,6 +32,7 @@
#include <sys/types.h>
#include <sys/un.h>
#include <syslog.h>
+#define syslog(...) do {} while(0)
#include <unistd.h>
#include "cras_client.h"
@@ -604,8 +605,8 @@ static int handle_unified_request(struct client_stream *stream,
struct cras_stream_params *config;
uint8_t *captured_frames = NULL;
uint8_t *playback_frames = NULL;
- struct timespec *capture_ts = NULL;
- struct timespec *playback_ts = NULL;
+ struct cras_timespec *capture_ts = NULL;
+ struct cras_timespec *playback_ts = NULL;
int frames;
int rc = 0;
unsigned int server_frames = num_frames;
@@ -1791,7 +1792,7 @@ long cras_client_get_system_max_capture_gain(struct cras_client *client)
}
unsigned cras_client_get_num_active_streams(struct cras_client *client,
- struct timespec *ts)
+ struct cras_timespec *ts)
{
unsigned num_streams, version;
@@ -1803,7 +1804,7 @@ read_active_streams_again:
num_streams = client->server_state->num_active_streams;
if (ts) {
if (num_streams)
- clock_gettime(CLOCK_MONOTONIC, ts);
+ cras_clock_gettime(CLOCK_MONOTONIC, ts);
else
*ts = client->server_state->last_active_stream_time;
}
@@ -2069,30 +2070,30 @@ int cras_client_format_bytes_per_frame(struct cras_audio_format *fmt)
return cras_get_format_bytes(fmt);
}
-int cras_client_calc_playback_latency(const struct timespec *sample_time,
- struct timespec *delay)
+int cras_client_calc_playback_latency(const struct cras_timespec *sample_time,
+ struct cras_timespec *delay)
{
- struct timespec now;
+ struct cras_timespec now;
if (delay == NULL)
return -EINVAL;
- clock_gettime(CLOCK_MONOTONIC, &now);
+ cras_clock_gettime(CLOCK_MONOTONIC, &now);
/* for output return time until sample is played (t - now) */
subtract_timespecs(sample_time, &now, delay);
return 0;
}
-int cras_client_calc_capture_latency(const struct timespec *sample_time,
- struct timespec *delay)
+int cras_client_calc_capture_latency(const struct cras_timespec *sample_time,
+ struct cras_timespec *delay)
{
- struct timespec now;
+ struct cras_timespec now;
if (delay == NULL)
return -EINVAL;
- clock_gettime(CLOCK_MONOTONIC, &now);
+ cras_clock_gettime(CLOCK_MONOTONIC, &now);
/* For input want time since sample read (now - t) */
subtract_timespecs(&now, sample_time, delay);
diff --git a/cras/src/libcras/cras_client.h b/cras/src/libcras/cras_client.h
index d497f25..1f2e1e8 100644
--- a/cras/src/libcras/cras_client.h
+++ b/cras/src/libcras/cras_client.h
@@ -35,7 +35,7 @@ typedef int (*cras_playback_cb_t)(struct cras_client *client,
cras_stream_id_t stream_id,
uint8_t *samples,
size_t frames,
- const struct timespec *sample_time,
+ const struct cras_timespec *sample_time,
void *user_arg);
/* Callback for audio received and/or transmitted.
@@ -56,8 +56,8 @@ typedef int (*cras_unified_cb_t)(struct cras_client *client,
uint8_t *captured_samples,
uint8_t *playback_samples,
unsigned int frames,
- const struct timespec *captured_time,
- const struct timespec *playback_time,
+ const struct cras_timespec *captured_time,
+ const struct cras_timespec *playback_time,
void *user_arg);
/* Callback for handling errors. */
@@ -496,7 +496,7 @@ long cras_client_get_system_max_capture_gain(struct cras_client *client);
* The number of active streams.
*/
unsigned cras_client_get_num_active_streams(struct cras_client *client,
- struct timespec *ts);
+ struct cras_timespec *ts);
/* Gets the id of the output node currently selected
* Args:
@@ -542,8 +542,8 @@ int cras_client_format_bytes_per_frame(struct cras_audio_format *fmt);
* Returns:
* 0 on success, -EINVAL if delay is NULL.
*/
-int cras_client_calc_playback_latency(const struct timespec *sample_time,
- struct timespec *delay);
+int cras_client_calc_playback_latency(const struct cras_timespec *sample_time,
+ struct cras_timespec *delay);
/* For capture returns the latency of the next frame to be read from the buffer
* (based on when it was captured). Only valid when called from the audio
@@ -554,8 +554,8 @@ int cras_client_calc_playback_latency(const struct timespec *sample_time,
* Returns:
* 0 on success, -EINVAL if delay is NULL.
*/
-int cras_client_calc_capture_latency(const struct timespec *sample_time,
- struct timespec *delay);
+int cras_client_calc_capture_latency(const struct cras_timespec *sample_time,
+ struct cras_timespec *delay);
/* Set the volume of the given output node. Only for output nodes.
* Args:
diff --git a/cras/src/tests/cras_test_client.c b/cras/src/tests/cras_test_client.c
index a371071..f39d5d7 100644
--- a/cras/src/tests/cras_test_client.c
+++ b/cras/src/tests/cras_test_client.c
@@ -30,7 +30,7 @@ static uint8_t *file_buf;
static size_t file_buf_size;
static size_t file_buf_read_offset;
static int pipefd[2];
-static struct timespec last_latency;
+static struct cras_timespec last_latency;
static int show_latency;
static float last_rms_sqr_sum;
static int last_rms_size;
@@ -103,8 +103,8 @@ static int got_samples(struct cras_client *client,
uint8_t *captured_samples,
uint8_t *playback_samples,
unsigned int frames,
- const struct timespec *captured_time,
- const struct timespec *playback_time,
+ const struct cras_timespec *captured_time,
+ const struct cras_timespec *playback_time,
void *user_arg)
{
int *fd = (int *)user_arg;
@@ -158,8 +158,8 @@ static int put_samples(struct cras_client *client,
uint8_t *captured_samples,
uint8_t *playback_samples,
unsigned int frames,
- const struct timespec *captured_time,
- const struct timespec *playback_time,
+ const struct cras_timespec *captured_time,
+ const struct cras_timespec *playback_time,
void *user_arg)
{
size_t this_size, decoded;
@@ -215,8 +215,8 @@ static int unified_samples(struct cras_client *client,
uint8_t *captured_samples,
uint8_t *playback_samples,
unsigned int frames,
- const struct timespec *captured_time,
- const struct timespec *playback_time,
+ const struct cras_timespec *captured_time,
+ const struct cras_timespec *playback_time,
void *user_arg)
{
unsigned int frame_bytes;
@@ -279,7 +279,7 @@ static void print_node_info(const struct cras_ionode_info *nodes, int num_nodes,
printf("\t%u:%u\t%4zu %5g %7s %10ld\t%-16s%c%s\n",
nodes[i].iodev_idx,
nodes[i].ionode_idx,
- nodes[i].priority,
+ (size_t)nodes[i].priority,
is_input ? nodes[i].capture_gain / 100.0
: (double) nodes[i].volume,
nodes[i].plugged ? "yes" : "no",
@@ -346,14 +346,14 @@ static void print_attached_client_list(struct cras_client *client)
printf("\tID\tpid\tuid\n");
for (i = 0; i < num_clients; i++)
printf("\t%zu\t%d\t%d\n",
- clients[i].id,
+ (size_t)clients[i].id,
clients[i].pid,
clients[i].gid);
}
static void print_active_stream_info(struct cras_client *client)
{
- struct timespec ts;
+ struct cras_timespec ts;
unsigned num_streams;
num_streams = cras_client_get_num_active_streams(client, &ts);
common="common/cras_shm.h common/cras_messages.h common/cras_iodev_info.h \
common/cras_types.h common/cras_audio_format.c"
# Replace size_t/long by fixed-size integers corresponding to their
# respective sizes on x86_64, aligned on 8-byte boundaries
sed -i -e 's/uint64_t[ \t]/aligned_uint64_t /g
s/size_t[ \t]/aligned_uint64_t /g
s/long[ \t]/aligned_int64_t /g' $common
# Hack to make sure sizeof(struct cras_server/client_message) is a
# multiple of 8
sed -i -e \
's/\(enum CRAS_CLIENT_MESSAGE_ID\) id;/\1 __attribute__((aligned(8))) id;/
s/\(enum CRAS_SERVER_MESSAGE_ID\) id;/\1 __attribute__((aligned(8))) id;/' \
common/cras_messages.h
# Disable syslog to remove warnings about printf formats
sed -i -e '/#include <syslog.h>/a \
#define syslog(...) do \{\} while(0)' \
common/cras_fmt_conv.c libcras/cras_client.c
# Replace timespec/timeval
sed -i -e 's/struct timespec[ \t]/struct cras_timespec /g
s/clock_gettime(/cras_clock_gettime(/' \
$common common/cras_util.h \
libcras/cras_client.h libcras/cras_client.c \
alsa_plugin/pcm_cras.c tests/cras_test_client.c
sed -i -e \
's/struct timeval/struct { aligned_int64_t tv_sec; aligned_int64_t tv_usec; }/' \
common/cras_iodev_info.h
# Add aligned integer definition, and wrapper allowing to replace timespec
# by generic cras_timespec
awk '/^#include <sys\/time.h>$/ {
print;
while ((getline line < "/dev/fd/3") > 0)
print line
next
};1' common/cras_iodev_info.h > common/cras_iodev_info.h.new 3<<END
typedef uint64_t __attribute__((aligned(8))) aligned_uint64_t;
typedef int64_t __attribute__((aligned(8))) aligned_int64_t;
struct cras_timespec {
aligned_int64_t tv_sec;
aligned_int64_t tv_nsec;
};
static inline int cras_clock_gettime(clockid_t clk_id, struct cras_timespec *ctp) {
struct timespec tp;
int ret = clock_gettime(clk_id, &tp);
ctp->tv_sec = tp.tv_sec;
ctp->tv_nsec = tp.tv_nsec;
return ret;
}
END
mv common/cras_iodev_info.h.new common/cras_iodev_info.h
# Restore uncorrectly replaced timespec, add 2 necessary casts
sed -i -e 's/struct cras_timespec sleep_ts;/struct timespec sleep_ts;/
s/nodes\[i\].priority/(size_t)nodes[i].priority/
s/clients\[i\].id/(size_t)clients[i].id/' tests/cras_test_client.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment