mirror of
https://gitlab.xiph.org/xiph/icecast-server.git
synced 2024-12-04 14:46:30 -05:00
Update: Created a stub function to handle all FLAC BLOCKs
This commit is contained in:
parent
c80fd692b2
commit
e0ed27bc4f
@ -51,16 +51,16 @@ typedef struct {
|
|||||||
} flac_block_t;
|
} flac_block_t;
|
||||||
|
|
||||||
/* returns true if parse was ok, false on error */
|
/* returns true if parse was ok, false on error */
|
||||||
static bool flac_parse_block(flac_block_t *block, const ogg_packet * packet)
|
static bool flac_parse_block(flac_block_t *block, const ogg_packet * packet, size_t offset)
|
||||||
{
|
{
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
uint32_t len;
|
uint32_t len;
|
||||||
|
|
||||||
/* check header length */
|
/* check header length */
|
||||||
if (packet->bytes <= 4)
|
if ((size_t)packet->bytes <= (4 + offset))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
type = packet->packet[0];
|
type = packet->packet[offset];
|
||||||
|
|
||||||
/* 0xFF is the sync code for a FRAME not a block */
|
/* 0xFF is the sync code for a FRAME not a block */
|
||||||
if (type == 0xFF)
|
if (type == 0xFF)
|
||||||
@ -78,18 +78,18 @@ static bool flac_parse_block(flac_block_t *block, const ogg_packet * packet)
|
|||||||
|
|
||||||
block->type = type;
|
block->type = type;
|
||||||
|
|
||||||
len = (unsigned char)packet->packet[1];
|
len = (unsigned char)packet->packet[1 + offset];
|
||||||
len <<= 8;
|
len <<= 8;
|
||||||
len |= (unsigned char)packet->packet[2];
|
len |= (unsigned char)packet->packet[2 + offset];
|
||||||
len <<= 8;
|
len <<= 8;
|
||||||
len |= (unsigned char)packet->packet[3];
|
len |= (unsigned char)packet->packet[3 + offset];
|
||||||
|
|
||||||
/* check Ogg packet size vs. self-sync size */
|
/* check Ogg packet size vs. self-sync size */
|
||||||
if (packet->bytes != (len + 4))
|
if ((size_t)packet->bytes != (len + 4 + offset))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
block->len = len;
|
block->len = len;
|
||||||
block->data = packet->packet + 4;
|
block->data = packet->packet + 4 + offset;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -126,6 +126,11 @@ static const char * flac_block_type_to_name(flac_block_type_t type)
|
|||||||
return "<unknown>";
|
return "<unknown>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void flac_handle_block(ogg_state_t *ogg_info, ogg_codec_t *codec, const flac_block_t *block)
|
||||||
|
{
|
||||||
|
ICECAST_LOG_DEBUG("Found header of type %s%s with %zu bytes of data", flac_block_type_to_name(block->type), block->last ? "(last)" : "", block->len);
|
||||||
|
}
|
||||||
|
|
||||||
static void flac_codec_free (ogg_state_t *ogg_info, ogg_codec_t *codec)
|
static void flac_codec_free (ogg_state_t *ogg_info, ogg_codec_t *codec)
|
||||||
{
|
{
|
||||||
ICECAST_LOG_DEBUG("freeing FLAC codec");
|
ICECAST_LOG_DEBUG("freeing FLAC codec");
|
||||||
@ -134,7 +139,6 @@ static void flac_codec_free (ogg_state_t *ogg_info, ogg_codec_t *codec)
|
|||||||
free(codec);
|
free(codec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Here, we just verify the page is ok and then add it to the queue */
|
/* Here, we just verify the page is ok and then add it to the queue */
|
||||||
static refbuf_t *process_flac_page (ogg_state_t *ogg_info, ogg_codec_t *codec, ogg_page *page, format_plugin_t *plugin)
|
static refbuf_t *process_flac_page (ogg_state_t *ogg_info, ogg_codec_t *codec, ogg_page *page, format_plugin_t *plugin)
|
||||||
{
|
{
|
||||||
@ -151,8 +155,8 @@ static refbuf_t *process_flac_page (ogg_state_t *ogg_info, ogg_codec_t *codec, o
|
|||||||
while (ogg_stream_packetout(&codec->os, &packet)) {
|
while (ogg_stream_packetout(&codec->os, &packet)) {
|
||||||
flac_block_t block;
|
flac_block_t block;
|
||||||
|
|
||||||
if (flac_parse_block(&block, &packet)) {
|
if (flac_parse_block(&block, &packet, 0)) {
|
||||||
ICECAST_LOG_DEBUG("Found header of type %s%s with %zu bytes of data", flac_block_type_to_name(block.type), block.last ? "(last)" : "", block.len);
|
flac_handle_block(ogg_info, codec, &block);
|
||||||
|
|
||||||
if (block.last) {
|
if (block.last) {
|
||||||
codec->headers = 0;
|
codec->headers = 0;
|
||||||
@ -196,6 +200,7 @@ ogg_codec_t *initial_flac_page (format_plugin_t *plugin, ogg_page *page)
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
unsigned char *parse = packet.packet;
|
unsigned char *parse = packet.packet;
|
||||||
|
flac_block_t block;
|
||||||
|
|
||||||
if (page->header_len + page->body_len != 79)
|
if (page->header_len + page->body_len != 79)
|
||||||
break;
|
break;
|
||||||
@ -214,6 +219,9 @@ ogg_codec_t *initial_flac_page (format_plugin_t *plugin, ogg_page *page)
|
|||||||
codec->headers = 1;
|
codec->headers = 1;
|
||||||
codec->name = "FLAC";
|
codec->name = "FLAC";
|
||||||
|
|
||||||
|
if (flac_parse_block(&block, &packet, 13))
|
||||||
|
flac_handle_block(ogg_info, codec, &block);
|
||||||
|
|
||||||
format_ogg_attach_header(ogg_info, page);
|
format_ogg_attach_header(ogg_info, page);
|
||||||
return codec;
|
return codec;
|
||||||
} while (0);
|
} while (0);
|
||||||
|
Loading…
Reference in New Issue
Block a user