1
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2024-12-04 14:46:30 -05:00

Cleanup: Migrated Opus support to new metadata_xiph

This commit is contained in:
Philipp Schafft 2022-03-16 01:00:39 +00:00
parent e169a7d020
commit 873e462035

View File

@ -7,7 +7,7 @@
* *
* Copyright 2012, David Richards, Mozilla Foundation, * Copyright 2012, David Richards, Mozilla Foundation,
* and others (see AUTHORS for details). * and others (see AUTHORS for details).
* Copyright 2014-2018, Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>, * Copyright 2014-2022, Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>,
*/ */
@ -21,6 +21,7 @@
#include <string.h> #include <string.h>
#include <ogg/ogg.h> #include <ogg/ogg.h>
#include "metadata_xiph.h"
#include "format_opus.h" #include "format_opus.h"
#include "stats.h" #include "stats.h"
#include "refbuf.h" #include "refbuf.h"
@ -37,19 +38,6 @@ static void opus_codec_free (ogg_state_t *ogg_info, ogg_codec_t *codec)
free(codec); free(codec);
} }
static uint32_t __read_header_u32be_unaligned(const unsigned char *in)
{
uint32_t ret = 0;
ret += in[3];
ret <<= 8;
ret += in[2];
ret <<= 8;
ret += in[1];
ret <<= 8;
ret += in[0];
return ret;
}
static void __handle_header_opushead(ogg_state_t *ogg_info, ogg_packet *packet) static void __handle_header_opushead(ogg_state_t *ogg_info, ogg_packet *packet)
{ {
if (packet->bytes < 19) { if (packet->bytes < 19) {
@ -63,17 +51,12 @@ static void __handle_header_opushead(ogg_state_t *ogg_info, ogg_packet *packet)
} }
stats_event_args(ogg_info->mount, "audio_channels", "%ld", (long int)packet->packet[9]); stats_event_args(ogg_info->mount, "audio_channels", "%ld", (long int)packet->packet[9]);
stats_event_args(ogg_info->mount, "audio_samplerate", "%ld", (long int)__read_header_u32be_unaligned(packet->packet+12)); stats_event_args(ogg_info->mount, "audio_samplerate", "%ld", (long int)metadata_xiph_read_u32be_unaligned(packet->packet+12));
} }
static void __handle_header_opustags(ogg_state_t *ogg_info, ogg_packet *packet, format_plugin_t *plugin) static void __handle_header_opustags(ogg_state_t *ogg_info, ogg_packet *packet, format_plugin_t *plugin)
{ {
size_t comments;
size_t next;
size_t left = packet->bytes; size_t left = packet->bytes;
size_t buflen = 0;
char *buf = NULL;
char *buf_new;
const void *p = packet->packet; const void *p = packet->packet;
if (packet->bytes < 16) { if (packet->bytes < 16) {
@ -85,77 +68,11 @@ static void __handle_header_opustags(ogg_state_t *ogg_info, ogg_packet *packet,
p += 8; p += 8;
left -= 8; left -= 8;
/* Now the vendor string follows. We just skip it. */
next = __read_header_u32be_unaligned(p);
p += 4;
left -= 4;
if (left < (next + 4)) {
ICECAST_LOG_WARN("Bad Opus header: corrupted OpusTags header.");
return;
}
p += next;
left -= next;
/* Next is the comment counter. */
comments = __read_header_u32be_unaligned(p);
p += 4;
left -= 4;
/* Ok, next (comments) blocks follows, each composed of 4 byte length followed by the data */
if (left < (comments * 4)) {
ICECAST_LOG_WARN("Bad Opus header: corrupted OpusTags header.");
return;
}
vorbis_comment_clear(&plugin->vc); vorbis_comment_clear(&plugin->vc);
vorbis_comment_init(&plugin->vc); vorbis_comment_init(&plugin->vc);
if (!metadata_xiph_read_vorbis_comments(&plugin->vc, p, left)) {
while (comments) { ICECAST_LOG_WARN("Bad Opus header: corrupted OpusTags header.");
next = __read_header_u32be_unaligned(p);
p += 4;
left -= 4;
if (left < next) {
if (buf)
free(buf);
vorbis_comment_clear(&plugin->vc);
vorbis_comment_init(&plugin->vc);
ICECAST_LOG_WARN("Bad Opus header: corrupted OpusTags header.");
return;
}
if ((next + 1) > buflen) {
buf_new = realloc(buf, next + 1);
if (buf_new) {
buf = buf_new;
buflen = next + 1;
}
}
if (buflen >= (next + 1)) {
memcpy(buf, p, next);
buf[next] = 0;
vorbis_comment_add(&plugin->vc, buf);
}
p += next;
left -= next;
comments--;
if (comments && left < 4) {
if (buf)
free(buf);
vorbis_comment_clear(&plugin->vc);
vorbis_comment_init(&plugin->vc);
ICECAST_LOG_WARN("Bad Opus header: corrupted OpusTags header.");
return;
}
} }
if (buf)
free(buf);
ogg_info->log_metadata = 1; ogg_info->log_metadata = 1;
} }