Recognizes if input is ogg or not.
[xiph.git] / vorbis-tools / ogg123 / buffer.h
bloba174617bb69f1f0de540350518f9b11af2034d76
1 /********************************************************************
2 * *
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. *
7 * *
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/ *
11 * *
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.*/
21 #ifndef __BUFFER_H__
22 #define __BUFFER_H__
24 #include <stdlib.h>
25 #include <pthread.h>
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 *);
34 typedef struct buf_t
36 /* generic buffer interface */
37 void *write_arg;
38 buffer_write_func_t write_func;
40 /* pthread variables */
41 pthread_t thread;
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
47 to the buffer */
49 /* buffer info (constant) */
50 int audio_chunk_size; /* write data to audio device in this chunk size,
51 if possible */
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 */
60 int prebuffering;
61 int paused;
62 int eos;
63 int abort_write;
65 /* buffer data */
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. */
73 } buf_t;
76 /* action_func(buf_t *buf, void *arg) */
77 typedef void (*action_func_t) (buf_t *, void *);
79 typedef struct action_t {
80 ogg_int64_t position;
81 action_func_t action_func;
82 void *arg;
83 struct action_t *next;
84 } action_t;
87 typedef struct buffer_stats_t {
88 long size;
89 double fill;
90 double prebuffer_fill;
91 int prebuffering;
92 int paused;
93 int eos;
94 } buffer_stats_t;
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 int 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,
121 void *action_arg);
122 void buffer_insert_action_at_end (buf_t *buf, action_func_t action_func,
123 void *action_arg);
124 void buffer_append_action_at_end (buf_t *buf, action_func_t action_func,
125 void *action_arg);
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__ */