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
|
|
|
|
*/
|
|
|
|
|
2008-11-02 14:12:52 +01:00
|
|
|
#ifndef MPD_PIPE_H
|
|
|
|
#define MPD_PIPE_H
|
2004-05-07 17:58:04 +02:00
|
|
|
|
2008-10-08 10:49:16 +02:00
|
|
|
#include <stddef.h>
|
2008-11-02 16:55:43 +01:00
|
|
|
#include <stdint.h>
|
2008-10-08 11:03:39 +02:00
|
|
|
#include <stdbool.h>
|
2008-10-08 10:49:16 +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-11-02 16:55:43 +01:00
|
|
|
struct audio_format;
|
|
|
|
|
2008-11-02 14:15:47 +01:00
|
|
|
struct music_chunk {
|
2008-09-29 15:49:29 +02:00
|
|
|
uint16_t chunkSize;
|
|
|
|
uint16_t bitRate;
|
2008-04-12 06:18:54 +02:00
|
|
|
float times;
|
2008-04-12 06:13:24 +02:00
|
|
|
char data[CHUNK_SIZE];
|
2008-11-02 14:15:47 +01:00
|
|
|
};
|
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.
|
|
|
|
*/
|
2008-11-02 14:15:47 +01:00
|
|
|
struct music_pipe {
|
|
|
|
struct music_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 */
|
2008-10-08 11:03:39 +02:00
|
|
|
bool lazy;
|
2008-04-15 07:57:22 +02:00
|
|
|
|
2008-10-08 10:49:16 +02:00
|
|
|
struct notify *notify;
|
2008-08-26 08:41:05 +02:00
|
|
|
};
|
|
|
|
|
2008-11-02 14:15:47 +01:00
|
|
|
extern struct music_pipe ob;
|
2004-05-07 17:58:04 +02:00
|
|
|
|
2008-10-08 10:49:16 +02:00
|
|
|
void
|
2008-11-02 14:18:34 +01:00
|
|
|
music_pipe_init(unsigned int size, struct notify *notify);
|
2008-03-26 11:38:12 +01:00
|
|
|
|
2008-11-02 14:18:34 +01:00
|
|
|
void music_pipe_free(void);
|
2008-04-12 06:18:38 +02:00
|
|
|
|
2008-11-02 14:18:34 +01:00
|
|
|
void music_pipe_clear(void);
|
2004-05-18 05:37:55 +02:00
|
|
|
|
2008-11-02 14:18:34 +01:00
|
|
|
void music_pipe_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.
|
|
|
|
*/
|
2008-11-02 14:18:34 +01:00
|
|
|
void music_pipe_set_lazy(bool lazy);
|
2008-04-15 07:57:22 +02:00
|
|
|
|
2008-11-02 16:55:53 +01:00
|
|
|
static inline unsigned
|
|
|
|
music_pipe_size(void)
|
|
|
|
{
|
|
|
|
return ob.size;
|
|
|
|
}
|
|
|
|
|
2008-04-12 06:12:47 +02:00
|
|
|
/** is the buffer empty? */
|
2008-11-02 14:18:34 +01:00
|
|
|
static inline bool music_pipe_is_empty(void)
|
2008-10-12 00:42:22 +02:00
|
|
|
{
|
|
|
|
return ob.begin == ob.end;
|
|
|
|
}
|
2008-04-12 06:12:47 +02:00
|
|
|
|
2008-11-02 16:55:53 +01:00
|
|
|
static inline bool
|
|
|
|
music_pipe_head_is(unsigned i)
|
|
|
|
{
|
|
|
|
return !music_pipe_is_empty() && ob.begin == i;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned
|
|
|
|
music_pipe_tail_index(void)
|
|
|
|
{
|
|
|
|
return ob.end;
|
|
|
|
}
|
|
|
|
|
2008-11-02 14:18:34 +01:00
|
|
|
void music_pipe_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-11-02 14:18:34 +01:00
|
|
|
unsigned int music_pipe_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-11-02 14:18:34 +01:00
|
|
|
unsigned music_pipe_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-11-02 14:18:34 +01:00
|
|
|
int music_pipe_absolute(const unsigned relative);
|
2008-04-12 06:12:42 +02:00
|
|
|
|
2008-11-02 14:15:47 +01:00
|
|
|
struct music_chunk *
|
2008-11-02 14:18:34 +01:00
|
|
|
music_pipe_get_chunk(const unsigned i);
|
2008-04-12 06:13:11 +02:00
|
|
|
|
2008-11-02 16:55:53 +01:00
|
|
|
static inline struct music_chunk *
|
|
|
|
music_pipe_peek(void)
|
|
|
|
{
|
|
|
|
if (music_pipe_is_empty())
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return music_pipe_get_chunk(ob.begin);
|
|
|
|
}
|
|
|
|
|
2008-08-26 08:27:05 +02:00
|
|
|
/**
|
|
|
|
* Append a data block to the buffer.
|
|
|
|
*
|
|
|
|
* @return the number of bytes actually written
|
|
|
|
*/
|
2008-11-02 14:18:34 +01:00
|
|
|
size_t music_pipe_append(const void *data, size_t datalen,
|
2008-11-02 16:55:43 +01:00
|
|
|
const struct audio_format *audio_format,
|
2008-11-02 14:18:34 +01:00
|
|
|
float data_time, uint16_t bitRate);
|
2004-05-07 17:58:04 +02:00
|
|
|
|
2008-11-02 14:18:34 +01:00
|
|
|
void music_pipe_skip(unsigned num);
|
2008-04-12 06:18:19 +02:00
|
|
|
|
2004-05-07 17:58:04 +02:00
|
|
|
#endif
|