source: mainline/uspace/srv/audio/hound/audio_data.h@ 498ced1

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 498ced1 was 498ced1, checked in by Jiří Zárevúcky <jiri.zarevucky@…>, 7 years ago

Unify reference counting and remove some unnecessary instances of <atomic.h>

  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[23878dc]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>
[498ced1]40#include <refcount.h>
[d988ef2]41#include <errno.h>
42#include <fibril_synch.h>
43#include <pcm/format.h>
[23878dc]44
[c799138]45/** Reference counted audio buffer */
[23878dc]46typedef struct {
[231c770]47 /** Audio data */
[902dd4b]48 void *data;
[c799138]49 /** Size of the buffer pointer to by data */
[23878dc]50 size_t size;
[c799138]51 /** Format of the audio data */
[5029c788]52 pcm_format_t format;
[c799138]53 /** Reference counter */
[498ced1]54 atomic_refcount_t refcount;
[23878dc]55} audio_data_t;
56
[c799138]57/** Audio data pipe structure */
[d988ef2]58typedef struct {
[c799138]59 /** List of audio data buffers */
[d988ef2]60 list_t list;
[c799138]61 /** Total size of all buffers */
[d988ef2]62 size_t bytes;
[c799138]63 /** Total frames stored in all buffers */
[d988ef2]64 size_t frames;
[c799138]65 /** List access synchronization */
[d988ef2]66 fibril_mutex_t guard;
67} audio_pipe_t;
68
[902dd4b]69audio_data_t *audio_data_create(void *data, size_t size,
[5029c788]70 pcm_format_t format);
[d988ef2]71void audio_data_addref(audio_data_t *adata);
[5029c788]72void audio_data_unref(audio_data_t *adata);
73
[d988ef2]74void audio_pipe_init(audio_pipe_t *pipe);
75void audio_pipe_fini(audio_pipe_t *pipe);
76
[b7fd2a0]77errno_t audio_pipe_push(audio_pipe_t *pipe, audio_data_t *data);
[d988ef2]78audio_data_t *audio_pipe_pop(audio_pipe_t *pipe);
79
[541eb67]80size_t audio_pipe_mix_data(audio_pipe_t *pipe, void *buffer, size_t size,
[d988ef2]81 const pcm_format_t *f);
82
[c799138]83/**
84 * Total bytes getter.
85 * @param pipe The audio pipe.
86 * @return Total size of buffer stored in the pipe.
87 */
[d988ef2]88static inline size_t audio_pipe_bytes(audio_pipe_t *pipe)
89{
90 assert(pipe);
91 return pipe->bytes;
92}
93
[c799138]94/**
95 * Total bytes getter.
96 * @param pipe The audio pipe.
97 * @return Total number of frames stored in the pipe.
98 */
[d988ef2]99static inline size_t audio_pipe_frames(audio_pipe_t *pipe)
100{
101 assert(pipe);
102 return pipe->frames;
103}
104
[c799138]105/**
106 * Push data form buffer directly to pipe.
107 * @param pipe The target pipe.
108 * @param data audio buffer.
109 * @param size size of the @p data buffer
110 * @param f format of the audio data.
111 * @return Error code.
112 *
113 * Reference counted buffer is created automatically.
114 */
[b7fd2a0]115static inline errno_t audio_pipe_push_data(audio_pipe_t *pipe,
[902dd4b]116 void *data, size_t size, pcm_format_t f)
[d988ef2]117{
118 audio_data_t *adata = audio_data_create(data, size, f);
119 if (adata) {
[b7fd2a0]120 const errno_t ret = audio_pipe_push(pipe, adata);
[d988ef2]121 audio_data_unref(adata);
122 return ret;
123 }
124 return ENOMEM;
125}
126
127
[23878dc]128#endif
129
130/**
131 * @}
132 */
Note: See TracBrowser for help on using the repository browser.