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

Remove spare whitespace on blank lines.

This commit is contained in:
Joseph Wallace 2015-11-21 15:05:44 -05:00
parent e4258bfad3
commit 9de8fe483d

View File

@ -81,7 +81,7 @@ struct ebml_st {
ebml_read_mode output_state; ebml_read_mode output_state;
ebml_parsing_state parse_state; ebml_parsing_state parse_state;
unsigned long long copy_len; unsigned long long copy_len;
int cluster_start; int cluster_start;
ebml_keyframe_status cluster_starts_with_keyframe; ebml_keyframe_status cluster_starts_with_keyframe;
int flush_cluster; int flush_cluster;
@ -91,12 +91,12 @@ struct ebml_st {
int input_position; int input_position;
unsigned char *input_buffer; unsigned char *input_buffer;
int header_size; int header_size;
int header_position; int header_position;
int header_read_position; int header_read_position;
unsigned char *header; unsigned char *header;
unsigned long long keyframe_track_number; unsigned long long keyframe_track_number;
unsigned long long parsing_track_number; unsigned long long parsing_track_number;
int parsing_track_is_video; int parsing_track_is_video;
@ -149,7 +149,7 @@ int format_ebml_get_plugin(source_t *source)
source->format = plugin; source->format = plugin;
ebml_source_state->ebml = ebml_create(); ebml_source_state->ebml = ebml_create();
return 0; return 0;
} }
@ -244,7 +244,7 @@ static refbuf_t *ebml_get_buffer(source_t *source)
/* ICECAST_LOG_DEBUG("EBML: generated refbuf, size %i : %hhi %hhi %hhi", /* ICECAST_LOG_DEBUG("EBML: generated refbuf, size %i : %hhi %hhi %hhi",
* read_bytes, refbuf->data[0], refbuf->data[1], refbuf->data[2]); * read_bytes, refbuf->data[0], refbuf->data[1], refbuf->data[2]);
*/ */
if (chunk_type == EBML_CHUNK_CLUSTER_START) if (chunk_type == EBML_CHUNK_CLUSTER_START)
{ {
refbuf->sync_point = 1; refbuf->sync_point = 1;
@ -296,7 +296,6 @@ static int ebml_create_client_data(source_t *source, client_t *client)
return 0; return 0;
} }
static void ebml_free_client_data (client_t *client) static void ebml_free_client_data (client_t *client)
{ {
@ -307,7 +306,6 @@ static void ebml_free_client_data (client_t *client)
client->format_data = NULL; client->format_data = NULL;
} }
static void ebml_write_buf_to_file_fail (source_t *source) static void ebml_write_buf_to_file_fail (source_t *source)
{ {
ICECAST_LOG_WARN("Write to dump file failed, disabling"); ICECAST_LOG_WARN("Write to dump file failed, disabling");
@ -315,7 +313,6 @@ static void ebml_write_buf_to_file_fail (source_t *source)
source->dumpfile = NULL; source->dumpfile = NULL;
} }
static void ebml_write_buf_to_file (source_t *source, refbuf_t *refbuf) static void ebml_write_buf_to_file (source_t *source, refbuf_t *refbuf)
{ {
@ -338,7 +335,6 @@ static void ebml_write_buf_to_file (source_t *source, refbuf_t *refbuf)
} }
/* internal ebml parsing */ /* internal ebml parsing */
static void ebml_destroy(ebml_t *ebml) static void ebml_destroy(ebml_t *ebml)
@ -363,7 +359,7 @@ static ebml_t *ebml_create()
ebml->input_buffer = calloc(1, EBML_SLICE_SIZE); ebml->input_buffer = calloc(1, EBML_SLICE_SIZE);
ebml->cluster_start = -1; ebml->cluster_start = -1;
ebml->keyframe_track_number = EBML_UNKNOWN; ebml->keyframe_track_number = EBML_UNKNOWN;
ebml->parsing_track_number = EBML_UNKNOWN; ebml->parsing_track_number = EBML_UNKNOWN;
ebml->parsing_track_is_video = 0; ebml->parsing_track_is_video = 0;
@ -382,7 +378,7 @@ static int ebml_read_space(ebml_t *ebml)
switch (ebml->output_state) { switch (ebml->output_state) {
case EBML_STATE_READING_HEADER: case EBML_STATE_READING_HEADER:
if (ebml->header_size != 0) { if (ebml->header_size != 0) {
/* The header can be read */ /* The header can be read */
return ebml->header_size; return ebml->header_size;
@ -391,22 +387,22 @@ static int ebml_read_space(ebml_t *ebml)
return 0; return 0;
} }
break; break;
case EBML_STATE_READING_CLUSTERS: case EBML_STATE_READING_CLUSTERS:
if (ebml->cluster_start > 0) { if (ebml->cluster_start > 0) {
/* return up until just before a new cluster starts */ /* return up until just before a new cluster starts */
read_space = ebml->cluster_start; read_space = ebml->cluster_start;
} else { } else {
if (ebml->position == EBML_SLICE_SIZE) { if (ebml->position == EBML_SLICE_SIZE) {
/* The current cluster fills the buffer, /* The current cluster fills the buffer,
* we have no choice but to start flushing it. * we have no choice but to start flushing it.
*/ */
ebml->flush_cluster = 1; ebml->flush_cluster = 1;
} }
if (ebml->flush_cluster) { if (ebml->flush_cluster) {
/* return what we have */ /* return what we have */
read_space = ebml->position; read_space = ebml->position;
@ -420,7 +416,7 @@ static int ebml_read_space(ebml_t *ebml)
return read_space; return read_space;
} }
ICECAST_LOG_ERROR("EBML: Invalid parser read state"); ICECAST_LOG_ERROR("EBML: Invalid parser read state");
return 0; return 0;
} }
@ -437,7 +433,7 @@ static int ebml_read(ebml_t *ebml, char *buffer, int len, ebml_chunk_type *chunk
int read_space; int read_space;
int to_read; int to_read;
*chunk_type = EBML_CHUNK_HEADER; *chunk_type = EBML_CHUNK_HEADER;
if (len < 1) { if (len < 1) {
@ -446,7 +442,7 @@ static int ebml_read(ebml_t *ebml, char *buffer, int len, ebml_chunk_type *chunk
switch (ebml->output_state) { switch (ebml->output_state) {
case EBML_STATE_READING_HEADER: case EBML_STATE_READING_HEADER:
if (ebml->header_size != 0) if (ebml->header_size != 0)
{ {
/* Can read a chunk of the header */ /* Can read a chunk of the header */
@ -460,9 +456,9 @@ static int ebml_read(ebml_t *ebml, char *buffer, int len, ebml_chunk_type *chunk
memcpy(buffer, ebml->header, to_read); memcpy(buffer, ebml->header, to_read);
ebml->header_read_position += to_read; ebml->header_read_position += to_read;
*chunk_type = EBML_CHUNK_HEADER; *chunk_type = EBML_CHUNK_HEADER;
if (ebml->header_read_position == ebml->header_size) { if (ebml->header_read_position == ebml->header_size) {
ebml->output_state = EBML_STATE_READING_CLUSTERS; ebml->output_state = EBML_STATE_READING_CLUSTERS;
} }
@ -470,17 +466,17 @@ static int ebml_read(ebml_t *ebml, char *buffer, int len, ebml_chunk_type *chunk
/* The header's not ready yet */ /* The header's not ready yet */
return 0; return 0;
} }
break; break;
case EBML_STATE_READING_CLUSTERS: case EBML_STATE_READING_CLUSTERS:
*chunk_type = EBML_CHUNK_CLUSTER_CONTINUE; *chunk_type = EBML_CHUNK_CLUSTER_CONTINUE;
read_space = ebml->position; read_space = ebml->position;
if (ebml->cluster_start == 0) { if (ebml->cluster_start == 0) {
/* new cluster is starting now */ /* new cluster is starting now */
if (ebml->cluster_starts_with_keyframe != EBML_KEYFRAME_DOES_NOT_START_CLUSTER) { if (ebml->cluster_starts_with_keyframe != EBML_KEYFRAME_DOES_NOT_START_CLUSTER) {
/* If we positively identified the first video frame as a non-keyframe, /* If we positively identified the first video frame as a non-keyframe,
* don't use this cluster as a sync point. Since some files lack * don't use this cluster as a sync point. Since some files lack
@ -490,7 +486,7 @@ static int ebml_read(ebml_t *ebml, char *buffer, int len, ebml_chunk_type *chunk
*/ */
*chunk_type = EBML_CHUNK_CLUSTER_START; *chunk_type = EBML_CHUNK_CLUSTER_START;
} }
/* mark end of cluster */ /* mark end of cluster */
ebml->cluster_start = -1; ebml->cluster_start = -1;
} else if (ebml->cluster_start > 0) { } else if (ebml->cluster_start > 0) {
@ -509,7 +505,7 @@ static int ebml_read(ebml_t *ebml, char *buffer, int len, ebml_chunk_type *chunk
} }
memcpy(buffer, ebml->buffer, to_read); memcpy(buffer, ebml->buffer, to_read);
/* Shift unread data down to the start of the buffer */ /* Shift unread data down to the start of the buffer */
memmove(ebml->buffer, ebml->buffer + to_read, ebml->position - to_read); memmove(ebml->buffer, ebml->buffer + to_read, ebml->position - to_read);
ebml->position -= to_read; ebml->position -= to_read;
@ -517,7 +513,7 @@ static int ebml_read(ebml_t *ebml, char *buffer, int len, ebml_chunk_type *chunk
if (ebml->cluster_start > 0) { if (ebml->cluster_start > 0) {
ebml->cluster_start -= to_read; ebml->cluster_start -= to_read;
} }
break; break;
} }
@ -561,56 +557,56 @@ static int ebml_wrote(ebml_t *ebml, int len)
char *track_number_id = "\xD7"; char *track_number_id = "\xD7";
char *track_type_id = "\x83"; char *track_type_id = "\x83";
char *simple_block_id = "\xA3"; char *simple_block_id = "\xA3";
ebml->input_position += len; ebml->input_position += len;
end_of_buffer = ebml->input_buffer + ebml->input_position; end_of_buffer = ebml->input_buffer + ebml->input_position;
while (processing) { while (processing) {
/*ICECAST_LOG_DEBUG("Parse State: %i", ebml->parse_state);*/ /*ICECAST_LOG_DEBUG("Parse State: %i", ebml->parse_state);*/
switch (ebml->parse_state) { switch (ebml->parse_state) {
case EBML_STATE_PARSING_HEADER: case EBML_STATE_PARSING_HEADER:
case EBML_STATE_PARSING_CLUSTERS: case EBML_STATE_PARSING_CLUSTERS:
if (ebml->parse_state == EBML_STATE_PARSING_HEADER) { if (ebml->parse_state == EBML_STATE_PARSING_HEADER) {
copy_state = EBML_STATE_COPYING_TO_HEADER; copy_state = EBML_STATE_COPYING_TO_HEADER;
} else { } else {
copy_state = EBML_STATE_COPYING_TO_DATA; copy_state = EBML_STATE_COPYING_TO_DATA;
} }
tag_length = ebml_parse_tag(ebml->input_buffer + cursor, tag_length = ebml_parse_tag(ebml->input_buffer + cursor,
end_of_buffer, &payload_length); end_of_buffer, &payload_length);
if (tag_length > 0) { if (tag_length > 0) {
if (payload_length == EBML_UNKNOWN) { if (payload_length == EBML_UNKNOWN) {
/* Parse all children for tags we can't skip */ /* Parse all children for tags we can't skip */
payload_length = 0; payload_length = 0;
} }
/* Recognize tags of interest */ /* Recognize tags of interest */
if (tag_length > 4) { if (tag_length > 4) {
if (!memcmp(ebml->input_buffer + cursor, segment_id, 4)) { if (!memcmp(ebml->input_buffer + cursor, segment_id, 4)) {
/* Parse all Segment children */ /* Parse all Segment children */
payload_length = 0; payload_length = 0;
} else if (!memcmp(ebml->input_buffer + cursor, tracks_id, 4)) { } else if (!memcmp(ebml->input_buffer + cursor, tracks_id, 4)) {
/* Parse all Tracks children */ /* Parse all Tracks children */
payload_length = 0; payload_length = 0;
} }
} }
if (tag_length > 1) { if (tag_length > 1) {
if (!memcmp(ebml->input_buffer + cursor, simple_block_id, 1)) { if (!memcmp(ebml->input_buffer + cursor, simple_block_id, 1)) {
/* Probe SimpleBlock header for the keyframe status */ /* Probe SimpleBlock header for the keyframe status */
if (ebml->cluster_starts_with_keyframe == EBML_KEYFRAME_UNKNOWN) { if (ebml->cluster_starts_with_keyframe == EBML_KEYFRAME_UNKNOWN) {
track_number_length = ebml_parse_var_int(ebml->input_buffer + cursor + tag_length, track_number_length = ebml_parse_var_int(ebml->input_buffer + cursor + tag_length,
end_of_buffer, &track_number); end_of_buffer, &track_number);
if (track_number_length == 0) { if (track_number_length == 0) {
/* Wait for more data */ /* Wait for more data */
processing = 0; processing = 0;
@ -618,14 +614,14 @@ static int ebml_wrote(ebml_t *ebml, int len)
return -1; return -1;
} else if (track_number == ebml->keyframe_track_number) { } else if (track_number == ebml->keyframe_track_number) {
/* this block belongs to the video track */ /* this block belongs to the video track */
/* skip the 16-bit timecode for now, read the flags byte */ /* skip the 16-bit timecode for now, read the flags byte */
if (cursor + tag_length + track_number_length + 2 >= ebml->input_position) { if (cursor + tag_length + track_number_length + 2 >= ebml->input_position) {
/* Wait for more data */ /* Wait for more data */
processing = 0; processing = 0;
} else { } else {
flags = ebml->input_buffer[cursor + tag_length + track_number_length + 2]; flags = ebml->input_buffer[cursor + tag_length + track_number_length + 2];
if (flags & 0x80) { if (flags & 0x80) {
/* "keyframe" flag is set */ /* "keyframe" flag is set */
ebml->cluster_starts_with_keyframe = EBML_KEYFRAME_STARTS_CLUSTER; ebml->cluster_starts_with_keyframe = EBML_KEYFRAME_STARTS_CLUSTER;
@ -635,22 +631,22 @@ static int ebml_wrote(ebml_t *ebml, int len)
/* ICECAST_LOG_DEBUG("Found non-keyframe in track %hhu", track_number); */ /* ICECAST_LOG_DEBUG("Found non-keyframe in track %hhu", track_number); */
} }
} }
} }
} }
} else if (!memcmp(ebml->input_buffer + cursor, track_entry_id, 1)) { } else if (!memcmp(ebml->input_buffer + cursor, track_entry_id, 1)) {
/* Parse all TrackEntry children; reset the state */ /* Parse all TrackEntry children; reset the state */
payload_length = 0; payload_length = 0;
ebml->parsing_track_number = EBML_UNKNOWN; ebml->parsing_track_number = EBML_UNKNOWN;
ebml->parsing_track_is_video = 0; ebml->parsing_track_is_video = 0;
} else if (!memcmp(ebml->input_buffer + cursor, track_number_id, 1)) { } else if (!memcmp(ebml->input_buffer + cursor, track_number_id, 1)) {
/* Probe TrackNumber for value */ /* Probe TrackNumber for value */
value_length = ebml_parse_sized_int(ebml->input_buffer + cursor + tag_length, value_length = ebml_parse_sized_int(ebml->input_buffer + cursor + tag_length,
end_of_buffer, payload_length, 0, &data_value); end_of_buffer, payload_length, 0, &data_value);
if (value_length == 0) { if (value_length == 0) {
/* Wait for more data */ /* Wait for more data */
processing = 0; processing = 0;
@ -660,12 +656,12 @@ static int ebml_wrote(ebml_t *ebml, int len)
ebml->parsing_track_number = data_value; ebml->parsing_track_number = data_value;
ebml_check_track(ebml); ebml_check_track(ebml);
} }
} else if (!memcmp(ebml->input_buffer + cursor, track_type_id, 1)) { } else if (!memcmp(ebml->input_buffer + cursor, track_type_id, 1)) {
/* Probe TrackType for a video flag */ /* Probe TrackType for a video flag */
value_length = ebml_parse_sized_int(ebml->input_buffer + cursor + tag_length, value_length = ebml_parse_sized_int(ebml->input_buffer + cursor + tag_length,
end_of_buffer, payload_length, 0, &data_value); end_of_buffer, payload_length, 0, &data_value);
if (value_length == 0) { if (value_length == 0) {
/* Wait for more data */ /* Wait for more data */
processing = 0; processing = 0;
@ -678,20 +674,20 @@ static int ebml_wrote(ebml_t *ebml, int len)
ebml_check_track(ebml); ebml_check_track(ebml);
} }
} }
} }
} }
/* Take appropriate next action */ /* Take appropriate next action */
if (!memcmp(ebml->input_buffer + cursor, cluster_id, 4)) { if (!memcmp(ebml->input_buffer + cursor, cluster_id, 4)) {
/* Found a cluster */ /* Found a cluster */
ebml->parse_state = EBML_STATE_START_CLUSTER; ebml->parse_state = EBML_STATE_START_CLUSTER;
} else if (processing) { } else if (processing) {
/* Non-cluster tag, copy it & children into buffer */ /* Non-cluster tag, copy it & children into buffer */
ebml->copy_len = tag_length + payload_length; ebml->copy_len = tag_length + payload_length;
ebml->parse_state = copy_state; ebml->parse_state = copy_state;
} }
} else if (tag_length == 0) { } else if (tag_length == 0) {
@ -704,7 +700,7 @@ static int ebml_wrote(ebml_t *ebml, int len)
return -1; return -1;
} }
break; break;
case EBML_STATE_START_CLUSTER: case EBML_STATE_START_CLUSTER:
/* found a cluster; wait to process it until /* found a cluster; wait to process it until
* any previous cluster tag has been flushed * any previous cluster tag has been flushed
@ -716,55 +712,55 @@ static int ebml_wrote(ebml_t *ebml, int len)
ebml->flush_cluster = 1; ebml->flush_cluster = 1;
processing = 0; processing = 0;
} else { } else {
tag_length = ebml_parse_tag(ebml->input_buffer + cursor, tag_length = ebml_parse_tag(ebml->input_buffer + cursor,
end_of_buffer, &payload_length); end_of_buffer, &payload_length);
/* The header has been fully read by now, publish its size. */ /* The header has been fully read by now, publish its size. */
ebml->header_size = ebml->header_position; ebml->header_size = ebml->header_position;
/* Mark this potential sync point, prepare probe */ /* Mark this potential sync point, prepare probe */
ebml->cluster_start = ebml->position; ebml->cluster_start = ebml->position;
ebml->cluster_starts_with_keyframe = EBML_KEYFRAME_UNKNOWN; ebml->cluster_starts_with_keyframe = EBML_KEYFRAME_UNKNOWN;
/* Buffer data to give us time to probe for keyframes, etc. */ /* Buffer data to give us time to probe for keyframes, etc. */
ebml->flush_cluster = 0; ebml->flush_cluster = 0;
/* Copy cluster tag to read buffer */ /* Copy cluster tag to read buffer */
ebml->copy_len = tag_length; ebml->copy_len = tag_length;
ebml->parse_state = EBML_STATE_COPYING_TO_DATA; ebml->parse_state = EBML_STATE_COPYING_TO_DATA;
} }
break; break;
case EBML_STATE_COPYING_TO_HEADER: case EBML_STATE_COPYING_TO_HEADER:
case EBML_STATE_COPYING_TO_DATA: case EBML_STATE_COPYING_TO_DATA:
to_copy = ebml->input_position - cursor; to_copy = ebml->input_position - cursor;
if (to_copy > ebml->copy_len) { if (to_copy > ebml->copy_len) {
to_copy = ebml->copy_len; to_copy = ebml->copy_len;
} }
if (ebml->parse_state == EBML_STATE_COPYING_TO_HEADER) { if (ebml->parse_state == EBML_STATE_COPYING_TO_HEADER) {
if ((ebml->header_position + to_copy) > EBML_HEADER_MAX_SIZE) { if ((ebml->header_position + to_copy) > EBML_HEADER_MAX_SIZE) {
ICECAST_LOG_ERROR("EBML Header too large, failing"); ICECAST_LOG_ERROR("EBML Header too large, failing");
return -1; return -1;
} }
memcpy(ebml->header + ebml->header_position, ebml->input_buffer + cursor, to_copy); memcpy(ebml->header + ebml->header_position, ebml->input_buffer + cursor, to_copy);
ebml->header_position += to_copy; ebml->header_position += to_copy;
} else if (ebml->parse_state == EBML_STATE_COPYING_TO_DATA) { } else if (ebml->parse_state == EBML_STATE_COPYING_TO_DATA) {
if ((ebml->position + to_copy) > EBML_SLICE_SIZE) { if ((ebml->position + to_copy) > EBML_SLICE_SIZE) {
to_copy = EBML_SLICE_SIZE - ebml->position; to_copy = EBML_SLICE_SIZE - ebml->position;
} }
memcpy(ebml->buffer + ebml->position, ebml->input_buffer + cursor, to_copy); memcpy(ebml->buffer + ebml->position, ebml->input_buffer + cursor, to_copy);
ebml->position += to_copy; ebml->position += to_copy;
} }
/* ICECAST_LOG_DEBUG("Copied %i of %hhu", to_copy, ebml->copy_len); */ /* ICECAST_LOG_DEBUG("Copied %i of %hhu", to_copy, ebml->copy_len); */
cursor += to_copy; cursor += to_copy;
ebml->copy_len -= to_copy; ebml->copy_len -= to_copy;
if (ebml->copy_len == 0) { if (ebml->copy_len == 0) {
/* resume parsing */ /* resume parsing */
if (ebml->parse_state == EBML_STATE_COPYING_TO_HEADER) { if (ebml->parse_state == EBML_STATE_COPYING_TO_HEADER) {
@ -776,22 +772,22 @@ static int ebml_wrote(ebml_t *ebml, int len)
/* wait for more data */ /* wait for more data */
processing = 0; processing = 0;
} }
break; break;
default: default:
processing = 0; processing = 0;
} }
} }
/* Shift unprocessed data down to the start of the buffer */ /* Shift unprocessed data down to the start of the buffer */
memmove(ebml->input_buffer, ebml->input_buffer + cursor, ebml->input_position - cursor); memmove(ebml->input_buffer, ebml->input_buffer + cursor, ebml->input_position - cursor);
ebml->input_position -= cursor; ebml->input_position -= cursor;
return len; return len;
} }
static inline void ebml_check_track(ebml_t *ebml) static inline void ebml_check_track(ebml_t *ebml)
@ -799,7 +795,7 @@ static inline void ebml_check_track(ebml_t *ebml)
if (ebml->keyframe_track_number == EBML_UNKNOWN if (ebml->keyframe_track_number == EBML_UNKNOWN
&& ebml->parsing_track_is_video && ebml->parsing_track_is_video
&& ebml->parsing_track_number != EBML_UNKNOWN) { && ebml->parsing_track_number != EBML_UNKNOWN) {
ebml->keyframe_track_number = ebml->parsing_track_number; ebml->keyframe_track_number = ebml->parsing_track_number;
ICECAST_LOG_DEBUG("Identified track #%ffu as the video track", ebml->keyframe_track_number); ICECAST_LOG_DEBUG("Identified track #%ffu as the video track", ebml->keyframe_track_number);
} }
@ -824,23 +820,23 @@ static int ebml_parse_tag(unsigned char *buffer,
int type_length; int type_length;
int size_length; int size_length;
unsigned long long value; unsigned long long value;
*payload_length = 0; *payload_length = 0;
/* read past the type tag */ /* read past the type tag */
type_length = ebml_parse_var_int(buffer, buffer_end, &value); type_length = ebml_parse_var_int(buffer, buffer_end, &value);
if (type_length <= 0) { if (type_length <= 0) {
return type_length; return type_length;
} }
/* read the length tag */ /* read the length tag */
size_length = ebml_parse_var_int(buffer + type_length, buffer_end, payload_length); size_length = ebml_parse_var_int(buffer + type_length, buffer_end, payload_length);
if (size_length <= 0) { if (size_length <= 0) {
return size_length; return size_length;
} }
return type_length + size_length; return type_length + size_length;
} }
@ -859,14 +855,14 @@ static int ebml_parse_var_int(unsigned char *buffer,
unsigned char mask = 0x80; unsigned char mask = 0x80;
unsigned long long value; unsigned long long value;
unsigned long long unknown_marker; unsigned long long unknown_marker;
if (buffer >= buffer_end) { if (buffer >= buffer_end) {
return 0; return 0;
} }
/* find the length marker bit in the first byte */ /* find the length marker bit in the first byte */
value = buffer[0]; value = buffer[0];
while (mask) { while (mask) {
if (value & mask) { if (value & mask) {
value = value & ~mask; value = value & ~mask;
@ -876,26 +872,26 @@ static int ebml_parse_var_int(unsigned char *buffer,
size++; size++;
mask = mask >> 1; mask = mask >> 1;
} }
/* catch malformed number (no prefix) */ /* catch malformed number (no prefix) */
if (mask == 0) { if (mask == 0) {
ICECAST_LOG_DEBUG("Corrupt var-int"); ICECAST_LOG_DEBUG("Corrupt var-int");
return -1; return -1;
} }
/* catch number bigger than parsing buffer */ /* catch number bigger than parsing buffer */
if (buffer + size - 1 >= buffer_end) { if (buffer + size - 1 >= buffer_end) {
return 0; return 0;
} }
/* read remaining bytes of (big-endian) number */ /* read remaining bytes of (big-endian) number */
for (i = 1; i < size; i++) { for (i = 1; i < size; i++) {
value = (value << 8) + buffer[i]; value = (value << 8) + buffer[i];
unknown_marker = (unknown_marker << 8) + 0xFF; unknown_marker = (unknown_marker << 8) + 0xFF;
} }
/* catch special "unknown" length */ /* catch special "unknown" length */
if (value == unknown_marker) { if (value == unknown_marker) {
*out_value = EBML_UNKNOWN; *out_value = EBML_UNKNOWN;
} else { } else {
@ -905,7 +901,7 @@ static int ebml_parse_var_int(unsigned char *buffer,
/* /*
ICECAST_LOG_DEBUG("Varint: value %lli, unknown %llu, mask %hhu, size %i", value, unknown_marker, mask, size); ICECAST_LOG_DEBUG("Varint: value %lli, unknown %llu, mask %hhu, size %i", value, unknown_marker, mask, size);
*/ */
return size; return size;
} }
@ -923,27 +919,27 @@ static int ebml_parse_sized_int(unsigned char *buffer,
{ {
long long value; long long value;
int i; int i;
if (len < 1 || len > 8) { if (len < 1 || len > 8) {
ICECAST_LOG_DEBUG("Sized int of %i bytes", len); ICECAST_LOG_DEBUG("Sized int of %i bytes", len);
return -1; return -1;
} }
if (buffer + len >= buffer_end) { if (buffer + len >= buffer_end) {
return 0; return 0;
} }
if (is_signed && ((signed char) buffer[0]) < 0) { if (is_signed && ((signed char) buffer[0]) < 0) {
value = -1; value = -1;
} else { } else {
value = 0; value = 0;
} }
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
value = (value << 8) + ((unsigned char) buffer[i]); value = (value << 8) + ((unsigned char) buffer[i]);
} }
*out_value = value; *out_value = value;
return len; return len;
} }