| 1 | /*
|
|---|
| 2 | * Copyright (c) 2013 Jan Vesely
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @addtogroup audio
|
|---|
| 30 | * @brief HelenOS sound server
|
|---|
| 31 | * @{
|
|---|
| 32 | */
|
|---|
| 33 | /** @file
|
|---|
| 34 | */
|
|---|
| 35 |
|
|---|
| 36 | #ifndef AUDIO_DATA_H_
|
|---|
| 37 | #define AUDIO_DATA_H_
|
|---|
| 38 |
|
|---|
| 39 | #include <adt/list.h>
|
|---|
| 40 | #include <atomic.h>
|
|---|
| 41 | #include <errno.h>
|
|---|
| 42 | #include <fibril_synch.h>
|
|---|
| 43 | #include <pcm/format.h>
|
|---|
| 44 |
|
|---|
| 45 | typedef struct {
|
|---|
| 46 | const void *data;
|
|---|
| 47 | size_t size;
|
|---|
| 48 | pcm_format_t format;
|
|---|
| 49 | atomic_t refcount;
|
|---|
| 50 | } audio_data_t;
|
|---|
| 51 |
|
|---|
| 52 | typedef struct {
|
|---|
| 53 | list_t list;
|
|---|
| 54 | size_t bytes;
|
|---|
| 55 | size_t frames;
|
|---|
| 56 | fibril_mutex_t guard;
|
|---|
| 57 | } audio_pipe_t;
|
|---|
| 58 |
|
|---|
| 59 | audio_data_t * audio_data_create(const void *data, size_t size,
|
|---|
| 60 | pcm_format_t format);
|
|---|
| 61 | void audio_data_addref(audio_data_t *adata);
|
|---|
| 62 | void audio_data_unref(audio_data_t *adata);
|
|---|
| 63 |
|
|---|
| 64 | void audio_pipe_init(audio_pipe_t *pipe);
|
|---|
| 65 | void audio_pipe_fini(audio_pipe_t *pipe);
|
|---|
| 66 |
|
|---|
| 67 | int audio_pipe_push(audio_pipe_t *pipe, audio_data_t *data);
|
|---|
| 68 | audio_data_t *audio_pipe_pop(audio_pipe_t *pipe);
|
|---|
| 69 |
|
|---|
| 70 | ssize_t audio_pipe_mix_data(audio_pipe_t *pipe, void *buffer, size_t size,
|
|---|
| 71 | const pcm_format_t *f);
|
|---|
| 72 |
|
|---|
| 73 | static inline size_t audio_pipe_bytes(audio_pipe_t *pipe)
|
|---|
| 74 | {
|
|---|
| 75 | assert(pipe);
|
|---|
| 76 | return pipe->bytes;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | static inline size_t audio_pipe_frames(audio_pipe_t *pipe)
|
|---|
| 80 | {
|
|---|
| 81 | assert(pipe);
|
|---|
| 82 | return pipe->frames;
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | static inline int audio_pipe_push_data(audio_pipe_t *pipe,
|
|---|
| 86 | const void *data, size_t size, pcm_format_t f)
|
|---|
| 87 | {
|
|---|
| 88 | audio_data_t *adata = audio_data_create(data, size, f);
|
|---|
| 89 | if (adata) {
|
|---|
| 90 | const int ret = audio_pipe_push(pipe, adata);
|
|---|
| 91 | audio_data_unref(adata);
|
|---|
| 92 | return ret;
|
|---|
| 93 | }
|
|---|
| 94 | return ENOMEM;
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 | #endif
|
|---|
| 99 |
|
|---|
| 100 | /**
|
|---|
| 101 | * @}
|
|---|
| 102 | */
|
|---|