Lines Matching refs:compress

84 struct compress {  struct
96 static int oops(struct compress *compress, int e, const char *fmt, ...) in oops() argument
102 vsnprintf(compress->error, COMPR_ERR_MAX, fmt, ap); in oops()
104 sz = strlen(compress->error); in oops()
106 snprintf(compress->error + sz, COMPR_ERR_MAX - sz, in oops()
113 const char *compress_get_error(struct compress *compress) in compress_get_error() argument
115 return compress->error; in compress_get_error()
117 static struct compress bad_compress = {
121 int is_compress_running(struct compress *compress) in is_compress_running() argument
123 return ((compress->fd > 0) && compress->running) ? 1 : 0; in is_compress_running()
126 int is_compress_ready(struct compress *compress) in is_compress_ready() argument
128 return (compress->fd > 0) ? 1 : 0; in is_compress_ready()
131 static int get_compress_version(struct compress *compress) in get_compress_version() argument
135 if (ioctl(compress->fd, SNDRV_COMPRESS_IOCTL_VERSION, &version)) { in get_compress_version()
136 oops(compress, errno, "cant read version"); in get_compress_version()
142 static bool _is_codec_supported(struct compress *compress, struct compr_config *config, in _is_codec_supported() argument
156 oops(compress, ENXIO, "this codec is not supported"); in _is_codec_supported()
161 oops(compress, EINVAL, "requested fragment size %d is below min supported %d", in _is_codec_supported()
166 oops(compress, EINVAL, "requested fragment size %d is above max supported %d", in _is_codec_supported()
171 oops(compress, EINVAL, "requested fragments %d are below min supported %d", in _is_codec_supported()
176 oops(compress, EINVAL, "requested fragments %d are above max supported %d", in _is_codec_supported()
215 struct compress *compress_open(unsigned int card, unsigned int device, in compress_open()
218 struct compress *compress; in compress_open() local
228 compress = calloc(1, sizeof(struct compress)); in compress_open()
229 if (!compress) { in compress_open()
234 compress->next_track = 0; in compress_open()
235 compress->gapless_metadata = 0; in compress_open()
236 compress->config = calloc(1, sizeof(*config)); in compress_open()
237 if (!compress->config) in compress_open()
242 compress->max_poll_wait_ms = DEFAULT_MAX_POLL_WAIT_MS; in compress_open()
244 compress->flags = flags; in compress_open()
251 compress->fd = open(fn, O_RDONLY); in compress_open()
253 compress->fd = open(fn, O_WRONLY); in compress_open()
255 if (compress->fd < 0) { in compress_open()
260 if (ioctl(compress->fd, SNDRV_COMPRESS_GET_CAPS, &caps)) { in compress_open()
261 oops(compress, errno, "cannot get device caps"); in compress_open()
275 if (_is_codec_supported(compress, config, &caps) == false) { in compress_open()
276 oops(compress, errno, "codec not supported\n"); in compress_open()
281 memcpy(compress->config, config, sizeof(*compress->config)); in compress_open()
284 if (ioctl(compress->fd, SNDRV_COMPRESS_SET_PARAMS, &params)) { in compress_open()
289 return compress; in compress_open()
292 close(compress->fd); in compress_open()
293 compress->fd = -1; in compress_open()
295 free(compress->config); in compress_open()
297 free(compress); in compress_open()
301 void compress_close(struct compress *compress) in compress_close() argument
303 if (compress == &bad_compress) in compress_close()
306 if (compress->fd >= 0) in compress_close()
307 close(compress->fd); in compress_close()
308 compress->running = 0; in compress_close()
309 compress->fd = -1; in compress_close()
310 free(compress->config); in compress_close()
311 free(compress); in compress_close()
314 int compress_get_hpointer(struct compress *compress, in compress_get_hpointer() argument
320 if (!is_compress_ready(compress)) in compress_get_hpointer()
321 return oops(compress, ENODEV, "device not ready"); in compress_get_hpointer()
323 if (ioctl(compress->fd, SNDRV_COMPRESS_AVAIL, &kavail)) in compress_get_hpointer()
324 return oops(compress, errno, "cannot get avail"); in compress_get_hpointer()
326 return oops(compress, ENODATA, "sample rate unknown"); in compress_get_hpointer()
335 int compress_get_tstamp(struct compress *compress, in compress_get_tstamp() argument
340 if (!is_compress_ready(compress)) in compress_get_tstamp()
341 return oops(compress, ENODEV, "device not ready"); in compress_get_tstamp()
343 if (ioctl(compress->fd, SNDRV_COMPRESS_TSTAMP, &ktstamp)) in compress_get_tstamp()
344 return oops(compress, errno, "cannot get tstamp"); in compress_get_tstamp()
351 int compress_write(struct compress *compress, const void *buf, unsigned int size) in compress_write() argument
358 const unsigned int frag_size = compress->config->fragment_size; in compress_write()
360 if (!(compress->flags & COMPRESS_IN)) in compress_write()
361 return oops(compress, EINVAL, "Invalid flag set"); in compress_write()
362 if (!is_compress_ready(compress)) in compress_write()
363 return oops(compress, ENODEV, "device not ready"); in compress_write()
364 fds.fd = compress->fd; in compress_write()
369 if (ioctl(compress->fd, SNDRV_COMPRESS_AVAIL, &avail)) in compress_write()
370 return oops(compress, errno, "cannot get avail"); in compress_write()
377 if (compress->nonblocking) in compress_write()
380 ret = poll(&fds, 1, compress->max_poll_wait_ms); in compress_write()
382 return oops(compress, EIO, "poll returned error!"); in compress_write()
389 return oops(compress, errno, "poll error"); in compress_write()
399 written = write(compress->fd, cbuf, to_write); in compress_write()
404 return oops(compress, errno, "write failed!"); in compress_write()
413 int compress_read(struct compress *compress, void *buf, unsigned int size) in compress_read() argument
420 const unsigned int frag_size = compress->config->fragment_size; in compress_read()
422 if (!(compress->flags & COMPRESS_OUT)) in compress_read()
423 return oops(compress, EINVAL, "Invalid flag set"); in compress_read()
424 if (!is_compress_ready(compress)) in compress_read()
425 return oops(compress, ENODEV, "device not ready"); in compress_read()
426 fds.fd = compress->fd; in compress_read()
430 if (ioctl(compress->fd, SNDRV_COMPRESS_AVAIL, &avail)) in compress_read()
431 return oops(compress, errno, "cannot get avail"); in compress_read()
437 if (compress->nonblocking) in compress_read()
440 ret = poll(&fds, 1, compress->max_poll_wait_ms); in compress_read()
442 return oops(compress, EIO, "poll returned error!"); in compress_read()
449 return oops(compress, errno, "poll error"); in compress_read()
459 num_read = read(compress->fd, cbuf, to_read); in compress_read()
464 return oops(compress, errno, "read failed!"); in compress_read()
474 int compress_start(struct compress *compress) in compress_start() argument
476 if (!is_compress_ready(compress)) in compress_start()
477 return oops(compress, ENODEV, "device not ready"); in compress_start()
478 if (ioctl(compress->fd, SNDRV_COMPRESS_START)) in compress_start()
479 return oops(compress, errno, "cannot start the stream"); in compress_start()
480 compress->running = 1; in compress_start()
485 int compress_stop(struct compress *compress) in compress_stop() argument
487 if (!is_compress_running(compress)) in compress_stop()
488 return oops(compress, ENODEV, "device not ready"); in compress_stop()
489 if (ioctl(compress->fd, SNDRV_COMPRESS_STOP)) in compress_stop()
490 return oops(compress, errno, "cannot stop the stream"); in compress_stop()
494 int compress_pause(struct compress *compress) in compress_pause() argument
496 if (!is_compress_running(compress)) in compress_pause()
497 return oops(compress, ENODEV, "device not ready"); in compress_pause()
498 if (ioctl(compress->fd, SNDRV_COMPRESS_PAUSE)) in compress_pause()
499 return oops(compress, errno, "cannot pause the stream"); in compress_pause()
503 int compress_resume(struct compress *compress) in compress_resume() argument
505 if (ioctl(compress->fd, SNDRV_COMPRESS_RESUME)) in compress_resume()
506 return oops(compress, errno, "cannot resume the stream"); in compress_resume()
510 int compress_drain(struct compress *compress) in compress_drain() argument
512 if (!is_compress_running(compress)) in compress_drain()
513 return oops(compress, ENODEV, "device not ready"); in compress_drain()
514 if (ioctl(compress->fd, SNDRV_COMPRESS_DRAIN)) in compress_drain()
515 return oops(compress, errno, "cannot drain the stream"); in compress_drain()
519 int compress_partial_drain(struct compress *compress) in compress_partial_drain() argument
521 if (!is_compress_running(compress)) in compress_partial_drain()
522 return oops(compress, ENODEV, "device not ready"); in compress_partial_drain()
524 if (!compress->next_track) in compress_partial_drain()
525 return oops(compress, EPERM, "next track not signalled"); in compress_partial_drain()
526 if (ioctl(compress->fd, SNDRV_COMPRESS_PARTIAL_DRAIN)) in compress_partial_drain()
527 return oops(compress, errno, "cannot drain the stream\n"); in compress_partial_drain()
528 compress->next_track = 0; in compress_partial_drain()
532 int compress_next_track(struct compress *compress) in compress_next_track() argument
534 if (!is_compress_running(compress)) in compress_next_track()
535 return oops(compress, ENODEV, "device not ready"); in compress_next_track()
537 if (!compress->gapless_metadata) in compress_next_track()
538 return oops(compress, EPERM, "metadata not set"); in compress_next_track()
539 if (ioctl(compress->fd, SNDRV_COMPRESS_NEXT_TRACK)) in compress_next_track()
540 return oops(compress, errno, "cannot set next track\n"); in compress_next_track()
541 compress->next_track = 1; in compress_next_track()
542 compress->gapless_metadata = 0; in compress_next_track()
546 int compress_set_gapless_metadata(struct compress *compress, in compress_set_gapless_metadata() argument
552 if (!is_compress_ready(compress)) in compress_set_gapless_metadata()
553 return oops(compress, ENODEV, "device not ready"); in compress_set_gapless_metadata()
555 version = get_compress_version(compress); in compress_set_gapless_metadata()
560 return oops(compress, ENXIO, "gapless apis not supported in kernel"); in compress_set_gapless_metadata()
564 if (ioctl(compress->fd, SNDRV_COMPRESS_SET_METADATA, &metadata)) in compress_set_gapless_metadata()
565 return oops(compress, errno, "can't set metadata for stream\n"); in compress_set_gapless_metadata()
569 if (ioctl(compress->fd, SNDRV_COMPRESS_SET_METADATA, &metadata)) in compress_set_gapless_metadata()
570 return oops(compress, errno, "can't set metadata for stream\n"); in compress_set_gapless_metadata()
571 compress->gapless_metadata = 1; in compress_set_gapless_metadata()
576 int compress_set_next_track_param(struct compress *compress, in compress_set_next_track_param() argument
579 if (!is_compress_running(compress)) in compress_set_next_track_param()
580 return oops(compress, ENODEV, "device not ready"); in compress_set_next_track_param()
582 if (ioctl(compress->fd, SNDRV_COMPRESS_SET_NEXT_TRACK_PARAM, codec_options)) in compress_set_next_track_param()
583 return oops(compress, errno, "cannot set next track params\n"); in compress_set_next_track_param()
613 void compress_set_max_poll_wait(struct compress *compress, int milliseconds) in compress_set_max_poll_wait() argument
615 compress->max_poll_wait_ms = milliseconds; in compress_set_max_poll_wait()
618 void compress_nonblock(struct compress *compress, int nonblock) in compress_nonblock() argument
620 compress->nonblocking = !!nonblock; in compress_nonblock()
623 int compress_wait(struct compress *compress, int timeout_ms) in compress_wait() argument
628 fds.fd = compress->fd; in compress_wait()
634 return oops(compress, EIO, "poll returned error!"); in compress_wait()
639 return oops(compress, ETIME, "poll timed out"); in compress_wait()
641 return oops(compress, errno, "poll error"); in compress_wait()
643 return oops(compress, EIO, "poll signalled unhandled event"); in compress_wait()
647 int compress_get_metadata(struct compress *compress, in compress_get_metadata() argument
650 if (!is_compress_ready(compress)) in compress_get_metadata()
651 return oops(compress, ENODEV, "device not ready"); in compress_get_metadata()
653 version = get_compress_version(compress); in compress_get_metadata()
657 if (ioctl(compress->fd, SNDRV_COMPRESS_GET_METADATA, mdata)) { in compress_get_metadata()
658 return oops(compress, errno, "can't get metadata for stream\n"); in compress_get_metadata()
663 int compress_set_metadata(struct compress *compress, in compress_set_metadata() argument
667 if (!is_compress_ready(compress)) in compress_set_metadata()
668 return oops(compress, ENODEV, "device not ready"); in compress_set_metadata()
670 version = get_compress_version(compress); in compress_set_metadata()
674 if (ioctl(compress->fd, SNDRV_COMPRESS_SET_METADATA, mdata)) { in compress_set_metadata()
675 return oops(compress, errno, "can't set metadata for stream\n"); in compress_set_metadata()