Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions include/tinycompress/compress_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "sound/compress_offload.h"
#include "tinycompress.h"

#define COMPRESS_OPS_V2 0xadcc0002 /* version 2 magic */

/*
* struct compress_ops:
* ops structure containing ops corresponding to exposed
Expand All @@ -16,14 +18,13 @@
* done in compress_hw.c
*/
struct compress_ops {
unsigned int magic; /* version of this structure */
void *(*open_by_name)(const char *name,
unsigned int flags, struct compr_config *config);
void (*close)(void *compress_data);
int (*get_hpointer)(void *compress_data,
unsigned int *avail, struct timespec *tstamp);
unsigned long long *avail, struct timespec *tstamp);
int (*get_tstamp)(void *compress_data,
unsigned int *samples, unsigned int *sampling_rate);
int (*get_tstamp64)(void *compress_data,
unsigned long long *samples, unsigned int *sampling_rate);
int (*write)(void *compress_data, const void *buf, size_t size);
int (*read)(void *compress_data, void *buf, size_t size);
Expand Down
12 changes: 12 additions & 0 deletions include/tinycompress/tinycompress.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ int compress_get_hpointer(struct compress *compress,
unsigned int *avail, struct timespec *tstamp);


/*
* compress_get_hpointe64r: get the hw timestamp
* return 0 on success, negative on error
*
* @compress: compress stream on which query is made
* @avail: buffer availble for write/read, in bytes
* @tstamp: hw time
*/
int compress_get_hpointer64(struct compress *compress,
unsigned long long *avail, struct timespec *tstamp);


/*
* compress_get_tstamp: get the raw hw timestamp
* return 0 on success, negative on error
Expand Down
35 changes: 32 additions & 3 deletions src/lib/compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
#include <dlfcn.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <sys/errno.h>
#include <sys/time.h>
#include "tinycompress/tinycompress.h"
#include "tinycompress/compress_ops.h"
Expand Down Expand Up @@ -136,14 +138,20 @@ static int populate_compress_plugin_ops(struct compress *compress, const char *n
return ret;
}

compress->ops = dlsym(dl_hdl, "compress_plugin_ops");
compress->ops = dlsym(dl_hdl, "compress_plugin_mops");
err = dlerror();
if (err) {
fprintf(stderr, "%s: dlsym to ops failed, err = '%s'\n",
__func__, err);
dlclose(dl_hdl);
return ret;
}
if (compress->ops->magic != COMPRESS_OPS_V2) {
fprintf(stderr, "%s: dlsym to ops failed, bad magic (%08x)\n",
__func__, compress->ops->magic);
dlclose(dl_hdl);
return -ENXIO;
}
compress->dl_hdl = dl_hdl;
return 0;
}
Expand Down Expand Up @@ -195,20 +203,41 @@ void compress_close(struct compress *compress)

int compress_get_hpointer(struct compress *compress,
unsigned int *avail, struct timespec *tstamp)
{
unsigned long long _avail;
int ret;

ret = compress->ops->get_hpointer(compress->data, &_avail, tstamp);
if (ret >= 0) {
if (_avail > UINT_MAX)
_avail = UINT_MAX;
*avail = (unsigned int)_avail;
}
return ret;
}

int compress_get_hpointer64(struct compress *compress,
unsigned long long *avail, struct timespec *tstamp)
{
return compress->ops->get_hpointer(compress->data, avail, tstamp);
}

int compress_get_tstamp(struct compress *compress,
unsigned int *samples, unsigned int *sampling_rate)
{
return compress->ops->get_tstamp(compress->data, samples, sampling_rate);
unsigned long long _samples;
int ret;

ret = compress->ops->get_tstamp(compress->data, &_samples, sampling_rate);
if (ret >= 0)
*samples = (unsigned int)_samples;
return ret;
}

int compress_get_tstamp64(struct compress *compress,
unsigned long long *samples, unsigned int *sampling_rate)
{
return compress->ops->get_tstamp64(compress->data, samples, sampling_rate);
return compress->ops->get_tstamp(compress->data, samples, sampling_rate);
}

int compress_write(struct compress *compress, const void *buf, unsigned int size)
Expand Down
51 changes: 29 additions & 22 deletions src/lib/compress_hw.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,19 @@ static void compress_hw_close(void *data)
}

static void compress_hw_avail64_from_32(struct snd_compr_avail64 *avail64,
const struct snd_compr_avail *avail32) {
avail64->avail = avail32->avail;

avail64->tstamp.byte_offset = avail32->tstamp.byte_offset;
avail64->tstamp.copied_total = avail32->tstamp.copied_total;
avail64->tstamp.pcm_frames = avail32->tstamp.pcm_frames;
avail64->tstamp.pcm_io_frames = avail32->tstamp.pcm_io_frames;
avail64->tstamp.sampling_rate = avail32->tstamp.sampling_rate;
const struct snd_compr_avail *avail32)
{
avail64->avail = avail32->avail;

avail64->tstamp.byte_offset = avail32->tstamp.byte_offset;
avail64->tstamp.copied_total = avail32->tstamp.copied_total;
avail64->tstamp.pcm_frames = avail32->tstamp.pcm_frames;
avail64->tstamp.pcm_io_frames = avail32->tstamp.pcm_io_frames;
avail64->tstamp.sampling_rate = avail32->tstamp.sampling_rate;
}

static int compress_hw_get_hpointer(void *data,
unsigned int *avail, struct timespec *tstamp)
unsigned long long *avail, struct timespec *tstamp)
{
struct compress_hw_data *compress = (struct compress_hw_data *)data;
struct snd_compr_avail kavail32;
Expand All @@ -262,23 +263,19 @@ static int compress_hw_get_hpointer(void *data,

if (0 == kavail64.tstamp.sampling_rate)
return oops(compress, ENODATA, "sample rate unknown");
*avail = (unsigned int)kavail64.avail;
*avail = kavail64.avail;
time = kavail64.tstamp.pcm_io_frames / kavail64.tstamp.sampling_rate;
tstamp->tv_sec = time;
time = kavail64.tstamp.pcm_io_frames % kavail64.tstamp.sampling_rate;
tstamp->tv_nsec = time * 1000000000 / kavail64.tstamp.sampling_rate;
return 0;
}

static int compress_hw_get_tstamp(void *data,
unsigned int *samples, unsigned int *sampling_rate)
static int compress_hw_get_tstamp_32(struct compress_hw_data *compress,
unsigned long long *samples, unsigned int *sampling_rate)
{
struct compress_hw_data *compress = (struct compress_hw_data *)data;
struct snd_compr_tstamp ktstamp;

if (!is_compress_hw_ready(compress))
return oops(compress, ENODEV, "device not ready");

if (ioctl(compress->fd, SNDRV_COMPRESS_TSTAMP, &ktstamp))
return oops(compress, errno, "cannot get tstamp");

Expand All @@ -287,15 +284,11 @@ static int compress_hw_get_tstamp(void *data,
return 0;
}

static int compress_hw_get_tstamp64(void *data,
static int compress_hw_get_tstamp_64(struct compress_hw_data *compress,
unsigned long long *samples, unsigned int *sampling_rate)
{
struct compress_hw_data *compress = (struct compress_hw_data *)data;
struct snd_compr_tstamp64 ktstamp;

if (!is_compress_hw_ready(compress))
return oops(compress, ENODEV, "device not ready");

if (ioctl(compress->fd, SNDRV_COMPRESS_TSTAMP64, &ktstamp))
return oops(compress, errno, "cannot get tstamp64");

Expand All @@ -304,6 +297,20 @@ static int compress_hw_get_tstamp64(void *data,
return 0;
}

static int compress_hw_get_tstamp(void *data,
unsigned long long *samples, unsigned int *sampling_rate)
{
struct compress_hw_data *compress = (struct compress_hw_data *)data;

if (!is_compress_hw_ready(compress))
return oops(compress, ENODEV, "device not ready");

if (get_compress_hw_version(compress) >= SNDRV_PROTOCOL_VERSION(0, 4, 0))
return compress_hw_get_tstamp_64(compress, samples, sampling_rate);
else
return compress_hw_get_tstamp_32(compress, samples, sampling_rate);
}

static int compress_hw_write(void *data, const void *buf, size_t size)
{
struct compress_hw_data *compress = (struct compress_hw_data *)data;
Expand Down Expand Up @@ -640,11 +647,11 @@ static int compress_hw_set_codec_params(void *data, struct snd_codec *codec)
}

struct compress_ops compress_hw_ops = {
.magic = COMPRESS_OPS_V2,
.open_by_name = compress_hw_open_by_name,
.close = compress_hw_close,
.get_hpointer = compress_hw_get_hpointer,
.get_tstamp = compress_hw_get_tstamp,
.get_tstamp64 = compress_hw_get_tstamp64,
.write = compress_hw_write,
.read = compress_hw_read,
.start = compress_hw_start,
Expand Down