music_pipe: add tag pointer to the music_chunk struct
Each music chunk can now carry a tag object. Decoder plugins which support it (e.g. oggvorbis) may use this to inject decoded tags into their output.
This commit is contained in:
parent
fcc11bc9d8
commit
c7a374bdcb
28
src/pipe.c
28
src/pipe.c
|
@ -19,6 +19,7 @@
|
||||||
#include "pipe.h"
|
#include "pipe.h"
|
||||||
#include "notify.h"
|
#include "notify.h"
|
||||||
#include "audio_format.h"
|
#include "audio_format.h"
|
||||||
|
#include "tag.h"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
@ -30,12 +31,14 @@ static void
|
||||||
music_chunk_init(struct music_chunk *chunk)
|
music_chunk_init(struct music_chunk *chunk)
|
||||||
{
|
{
|
||||||
chunk->length = 0;
|
chunk->length = 0;
|
||||||
|
chunk->tag = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
music_chunk_free(struct music_chunk *chunk)
|
music_chunk_free(struct music_chunk *chunk)
|
||||||
{
|
{
|
||||||
(void)chunk;
|
if (chunk->tag != NULL)
|
||||||
|
tag_free(chunk->tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -263,6 +266,29 @@ size_t music_pipe_append(const void *data0, size_t datalen,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool music_pipe_tag(const struct tag *tag)
|
||||||
|
{
|
||||||
|
struct music_chunk *chunk;
|
||||||
|
|
||||||
|
chunk = music_pipe_get_chunk(music_pipe.end);
|
||||||
|
if (chunk->length > 0 || chunk->tag != NULL) {
|
||||||
|
/* this chunk is not empty; allocate a new chunk,
|
||||||
|
because chunk.tag refers to the beginning of the
|
||||||
|
chunk data */
|
||||||
|
unsigned next = successor(music_pipe.end);
|
||||||
|
if (music_pipe.begin == next)
|
||||||
|
/* no chunks available */
|
||||||
|
return false;
|
||||||
|
|
||||||
|
output_buffer_expand(next);
|
||||||
|
chunk = music_pipe_get_chunk(next);
|
||||||
|
assert(chunk->length == 0 && chunk->tag == NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
chunk->tag = tag_dup(tag);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void music_pipe_skip(unsigned num)
|
void music_pipe_skip(unsigned num)
|
||||||
{
|
{
|
||||||
int i = music_pipe_absolute(num);
|
int i = music_pipe_absolute(num);
|
||||||
|
|
14
src/pipe.h
14
src/pipe.h
|
@ -42,6 +42,14 @@ struct music_chunk {
|
||||||
/** the time stamp within the song */
|
/** the time stamp within the song */
|
||||||
float times;
|
float times;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An optional tag associated with this chunk (and the
|
||||||
|
* following chunks); appears at song boundaries. The tag
|
||||||
|
* object is owned by this chunk, and must be freed when this
|
||||||
|
* chunk is deinitialized in music_chunk_free()
|
||||||
|
*/
|
||||||
|
struct tag *tag;
|
||||||
|
|
||||||
/** the data (probably PCM) */
|
/** the data (probably PCM) */
|
||||||
char data[CHUNK_SIZE];
|
char data[CHUNK_SIZE];
|
||||||
};
|
};
|
||||||
|
@ -148,6 +156,12 @@ size_t music_pipe_append(const void *data, size_t datalen,
|
||||||
const struct audio_format *audio_format,
|
const struct audio_format *audio_format,
|
||||||
float data_time, uint16_t bit_rate);
|
float data_time, uint16_t bit_rate);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a tag. This is usually called when a new song within a stream
|
||||||
|
* begins.
|
||||||
|
*/
|
||||||
|
bool music_pipe_tag(const struct tag *tag);
|
||||||
|
|
||||||
void music_pipe_skip(unsigned num);
|
void music_pipe_skip(unsigned num);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue