1 /********************************************************************
3 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
5 * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. *
6 * PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
8 * THE Ogg123 SOURCE CODE IS (C) COPYRIGHT 2000-2001 *
9 * by Stan Seibert <volsung@xiph.org> AND OTHER CONTRIBUTORS *
10 * http://www.xiph.org/ *
12 ********************************************************************
14 last mod: $Id: buffer.h,v 1.6 2002/06/02 03:07:10 volsung Exp $
16 ********************************************************************/
18 /* A generic circular buffer interface with the ability to buffer
19 actions (conceptually) between bytes in the buffer.*/
26 #include <ogg/os_types.h>
29 struct action_t
; /* forward declaration */
31 /* buffer_write_func(void *data, int nbytes, int eos, void *arg) */
32 typedef int (*buffer_write_func_t
) (void *, int, int, void *);
36 /* generic buffer interface */
38 buffer_write_func_t write_func
;
40 /* pthread variables */
43 pthread_mutex_t mutex
;
45 pthread_cond_t playback_cond
; /* signalled when playback can continue */
46 pthread_cond_t write_cond
; /* signalled when more data can be written
49 /* buffer info (constant) */
50 int audio_chunk_size
; /* write data to audio device in this chunk size,
52 long prebuffer_size
; /* number of bytes to prebuffer */
53 long size
; /* buffer size, for reference */
55 int cancel_flag
; /* When set, the playback thread should exit */
57 /* ----- Everything after this point is protected by mutex ----- */
59 /* buffering state variables */
66 long curfill
; /* how much the buffer is currently filled */
67 long start
; /* offset in buffer of start of available data */
68 ogg_int64_t position
; /* How many bytes have we output so far */
69 ogg_int64_t position_end
; /* Position right after end of data */
71 struct action_t
*actions
; /* Queue actions to perform */
72 char buffer
[1]; /* The buffer itself. It's more than one byte. */
76 /* action_func(buf_t *buf, void *arg) */
77 typedef void (*action_func_t
) (buf_t
*, void *);
79 typedef struct action_t
{
81 action_func_t action_func
;
83 struct action_t
*next
;
87 typedef struct buffer_stats_t
{
90 double prebuffer_fill
;
97 /* --- Buffer allocation --- */
99 buf_t
*buffer_create (long size
, long prebuffer
,
100 buffer_write_func_t write_func
, void *arg
,
101 int audio_chunk_size
);
103 void buffer_reset (buf_t
*buf
);
104 void buffer_destroy (buf_t
*buf
);
106 /* --- Buffer thread control --- */
107 int buffer_thread_start (buf_t
*buf
);
108 void buffer_thread_pause (buf_t
*buf
);
109 void buffer_thread_unpause (buf_t
*buf
);
110 void buffer_thread_kill (buf_t
*buf
);
112 /* --- Data buffering functions --- */
113 void buffer_submit_data (buf_t
*buf
, char *data
, long nbytes
);
114 size_t buffer_get_data (buf_t
*buf
, char *data
, long nbytes
);
116 void buffer_mark_eos (buf_t
*buf
);
117 void buffer_abort_write (buf_t
*buf
);
119 /* --- Action buffering functions --- */
120 void buffer_action_now (buf_t
*buf
, action_func_t action_func
,
122 void buffer_insert_action_at_end (buf_t
*buf
, action_func_t action_func
,
124 void buffer_append_action_at_end (buf_t
*buf
, action_func_t action_func
,
126 void buffer_insert_action_at (buf_t
*buf
, action_func_t action_func
,
127 void *action_arg
, ogg_int64_t position
);
128 void buffer_append_action_at (buf_t
*buf
, action_func_t action_func
,
129 void *action_arg
, ogg_int64_t position
);
131 /* --- Buffer status functions --- */
132 void buffer_wait_for_empty (buf_t
*buf
);
133 long buffer_full (buf_t
*buf
);
134 buffer_stats_t
*buffer_statistics (buf_t
*buf
);
136 #endif /* __BUFFER_H__ */