2004-05-07 17:58:04 +02:00
|
|
|
/* the Music Player Daemon (MPD)
|
2007-04-05 05:22:33 +02:00
|
|
|
* Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com)
|
2004-05-07 17:58:04 +02:00
|
|
|
* This project's homepage is: http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OUTPUT_BUFFER_H
|
|
|
|
#define OUTPUT_BUFFER_H
|
|
|
|
|
2008-08-26 08:27:05 +02:00
|
|
|
#include "notify.h"
|
2008-08-26 08:27:06 +02:00
|
|
|
#include "audio_format.h"
|
2004-05-07 17:58:04 +02:00
|
|
|
|
2008-04-12 06:13:17 +02:00
|
|
|
/* pick 1020 since its devisible for 8,16,24, and 32-bit audio */
|
|
|
|
#define CHUNK_SIZE 1020
|
|
|
|
|
2008-04-12 06:13:24 +02:00
|
|
|
typedef struct _OutputBufferChunk {
|
2008-04-12 06:18:54 +02:00
|
|
|
mpd_uint16 chunkSize;
|
|
|
|
mpd_uint16 bitRate;
|
|
|
|
float times;
|
2008-04-12 06:13:24 +02:00
|
|
|
char data[CHUNK_SIZE];
|
2008-04-13 03:16:27 +02:00
|
|
|
} ob_chunk;
|
2008-04-12 06:13:24 +02:00
|
|
|
|
2008-04-12 06:08:35 +02:00
|
|
|
/**
|
|
|
|
* A ring set of buffers where the decoder appends data after the end,
|
|
|
|
* and the player consumes data from the beginning.
|
|
|
|
*/
|
2004-05-07 17:58:04 +02:00
|
|
|
typedef struct _OutputBuffer {
|
2008-04-13 03:16:27 +02:00
|
|
|
ob_chunk *chunks;
|
2008-04-12 06:08:35 +02:00
|
|
|
|
2008-04-12 06:18:04 +02:00
|
|
|
unsigned int size;
|
|
|
|
|
2008-04-12 06:08:35 +02:00
|
|
|
/** the index of the first decoded chunk */
|
2008-04-12 06:18:28 +02:00
|
|
|
unsigned int volatile begin;
|
2008-04-12 06:08:35 +02:00
|
|
|
|
|
|
|
/** the index after the last decoded chunk */
|
2008-04-12 06:18:28 +02:00
|
|
|
unsigned int volatile end;
|
2008-04-12 06:08:35 +02:00
|
|
|
|
2008-04-15 07:57:22 +02:00
|
|
|
/** non-zero if the player thread should only we woken up if
|
|
|
|
the buffer becomes non-empty */
|
|
|
|
int lazy;
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
AudioFormat audioFormat;
|
2008-08-26 08:27:05 +02:00
|
|
|
|
|
|
|
Notify *notify;
|
2004-05-07 17:58:04 +02:00
|
|
|
} OutputBuffer;
|
|
|
|
|
2008-08-26 08:27:05 +02:00
|
|
|
void ob_init(unsigned int size, Notify *notify);
|
2008-03-26 11:38:12 +01:00
|
|
|
|
2008-04-13 03:16:27 +02:00
|
|
|
void ob_free(void);
|
2008-04-12 06:18:38 +02:00
|
|
|
|
2008-04-13 03:16:27 +02:00
|
|
|
void ob_clear(void);
|
2004-05-18 05:37:55 +02:00
|
|
|
|
2008-04-13 03:16:27 +02:00
|
|
|
void ob_flush(void);
|
2004-05-07 21:11:43 +02:00
|
|
|
|
2008-04-15 07:57:22 +02:00
|
|
|
/**
|
|
|
|
* When a chunk is decoded, we wake up the player thread to tell him
|
|
|
|
* about it. In "lazy" mode, we only wake him up when the buffer was
|
|
|
|
* previously empty, i.e. when the player thread has really been
|
|
|
|
* waiting for us.
|
|
|
|
*/
|
|
|
|
void ob_set_lazy(int lazy);
|
|
|
|
|
2008-04-12 06:12:47 +02:00
|
|
|
/** is the buffer empty? */
|
2008-04-13 03:16:27 +02:00
|
|
|
int ob_is_empty(void);
|
2008-04-12 06:12:47 +02:00
|
|
|
|
2008-04-13 03:16:27 +02:00
|
|
|
void ob_shift(void);
|
2008-04-12 06:13:51 +02:00
|
|
|
|
2008-04-12 06:12:53 +02:00
|
|
|
/**
|
|
|
|
* what is the position of the specified chunk number, relative to
|
|
|
|
* the first chunk in use?
|
|
|
|
*/
|
2008-04-13 03:16:27 +02:00
|
|
|
unsigned int ob_relative(const unsigned i);
|
2008-04-12 06:12:53 +02:00
|
|
|
|
2008-04-12 06:11:41 +02:00
|
|
|
/** determine the number of decoded chunks */
|
2008-04-13 03:16:27 +02:00
|
|
|
unsigned ob_available(void);
|
2008-04-12 06:11:41 +02:00
|
|
|
|
2008-04-12 06:12:42 +02:00
|
|
|
/**
|
|
|
|
* Get the absolute index of the nth used chunk after the first one.
|
|
|
|
* Returns -1 if there is no such chunk.
|
|
|
|
*/
|
2008-04-13 03:16:27 +02:00
|
|
|
int ob_absolute(const unsigned relative);
|
2008-04-12 06:12:42 +02:00
|
|
|
|
2008-04-13 03:16:27 +02:00
|
|
|
ob_chunk * ob_get_chunk(const unsigned i);
|
2008-04-12 06:13:11 +02:00
|
|
|
|
2008-08-26 08:27:05 +02:00
|
|
|
/**
|
|
|
|
* Append a data block to the buffer.
|
|
|
|
*
|
|
|
|
* @return the number of bytes actually written
|
|
|
|
*/
|
|
|
|
size_t ob_append(const void *data, size_t datalen,
|
|
|
|
float data_time, mpd_uint16 bitRate);
|
2004-05-07 17:58:04 +02:00
|
|
|
|
2008-04-13 03:16:27 +02:00
|
|
|
void ob_skip(unsigned num);
|
2008-04-12 06:18:19 +02:00
|
|
|
|
2004-05-07 17:58:04 +02:00
|
|
|
#endif
|
2008-08-26 08:27:05 +02:00
|
|
|
|