From f44b4db93f7ab7a1cad98271f84f1c1717405a65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Thu, 3 Jul 2008 16:56:34 +0200 Subject: Rewrite demux_real and demux_realaudio for style. Also try to simplify frame buffer allocation. --HG-- extra : transplant_source : %B6%B5o%A8%24%E1%F5B%D2%D8%08%F8%DE%E7%9E%B6%B8C%A4j --- src/demuxers/demux_real.c | 679 +++++++++++++++++++---------------------- src/demuxers/demux_realaudio.c | 102 +++---- 2 files changed, 358 insertions(+), 423 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_real.c b/src/demuxers/demux_real.c index 48bf24969..f258fd73a 100644 --- a/src/demuxers/demux_real.c +++ b/src/demuxers/demux_real.c @@ -58,12 +58,10 @@ #include "real_common.h" #define FOURCC_TAG BE_FOURCC -#define RMF_TAG FOURCC_TAG('.', 'R', 'M', 'F') #define PROP_TAG FOURCC_TAG('P', 'R', 'O', 'P') #define MDPR_TAG FOURCC_TAG('M', 'D', 'P', 'R') #define CONT_TAG FOURCC_TAG('C', 'O', 'N', 'T') #define DATA_TAG FOURCC_TAG('D', 'A', 'T', 'A') -#define INDX_TAG FOURCC_TAG('I', 'N', 'D', 'X') #define RA_TAG FOURCC_TAG('.', 'r', 'a', 0xfd) #define VIDO_TAG FOURCC_TAG('V', 'I', 'D', 'O') @@ -176,6 +174,18 @@ typedef struct { demux_class_t demux_class; } demux_real_class_t; +static int is_indx_tag(const void *ptr) { + return memcmp(ptr, "INDX", 4) == 0; +} + +static int is_data_tag(const void *ptr) { + return memcmp(ptr, "DATA", 4) == 0; +} + +static int is_rmf_tag(const void *ptr) { + return memcmp(ptr, ".RMF", 4) == 0; +} + static void real_parse_index(demux_real_t *this) { off_t next_index_chunk = this->index_start; @@ -183,8 +193,6 @@ static void real_parse_index(demux_real_t *this) { unsigned char index_chunk_header[INDEX_CHUNK_HEADER_SIZE]; unsigned char index_record[INDEX_RECORD_SIZE]; int i; - unsigned int entries, stream_num; - real_index_entry_t **index; while(next_index_chunk) { lprintf("reading index chunk at %"PRIX64"\n", next_index_chunk); @@ -200,70 +208,68 @@ static void real_parse_index(demux_real_t *this) { } /* Check chunk is actually an index chunk */ - if(_X_BE_32(&index_chunk_header[0]) == INDX_TAG) { - unsigned short version; + if(!is_indx_tag(&index_chunk_header[0])) { + lprintf("expected index chunk found chunk type: %.4s\n", &index_chunk_header[0]); + break; + } - /* Check version */ - version = _X_BE_16(&index_chunk_header[8]); - if(version != 0) { - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "demux_real: unknown object version in INDX: 0x%04x\n", version); - break; - } + /* Check version */ + const uint16_t version = _X_BE_16(&index_chunk_header[8]); + if(version != 0) { + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, + "demux_real: unknown object version in INDX: 0x%04x\n", version); + break; + } - /* Read data from header */ - entries = _X_BE_32(&index_chunk_header[10]); - stream_num = _X_BE_16(&index_chunk_header[14]); - next_index_chunk = _X_BE_32(&index_chunk_header[16]); - - /* Find which stream this index is for */ - index = NULL; - for(i = 0; i < this->num_video_streams; i++) { - if(stream_num == this->video_streams[i].mdpr->stream_number) { - index = &this->video_streams[i].index; - this->video_streams[i].index_entries = entries; - lprintf("found index chunk for video stream with num %d\n", stream_num); - break; - } + /* Read data from header */ + const uint32_t entries = _X_BE_32(&index_chunk_header[10]); + const uint16_t stream_num = _X_BE_16(&index_chunk_header[14]); + next_index_chunk = _X_BE_32(&index_chunk_header[16]); + + /* Find which stream this index is for */ + real_index_entry_t **index = NULL; + for(i = 0; i < this->num_video_streams; i++) { + if(stream_num == this->video_streams[i].mdpr->stream_number) { + index = &this->video_streams[i].index; + this->video_streams[i].index_entries = entries; + lprintf("found index chunk for video stream with num %d\n", stream_num); + break; } + } - if(!index) { - for(i = 0; i < this->num_audio_streams; i++) { - if(stream_num == this->audio_streams[i].mdpr->stream_number) { - index = &this->audio_streams[i].index; - this->audio_streams[i].index_entries = entries; - lprintf("found index chunk for audio stream with num %d\n", stream_num); - break; - } - } + if(!index) { + for(i = 0; i < this->num_audio_streams; i++) { + if(stream_num == this->audio_streams[i].mdpr->stream_number) { + index = &this->audio_streams[i].index; + this->audio_streams[i].index_entries = entries; + lprintf("found index chunk for audio stream with num %d\n", stream_num); + break; + } } + } - if(index && entries) - /* Allocate memory for index */ - *index = calloc(entries, sizeof(real_index_entry_t)); + if(index && entries) + /* Allocate memory for index */ + *index = calloc(entries, sizeof(real_index_entry_t)); - if(index && entries && *index) { - /* Read index */ - for(i = 0; i < entries; i++) { - if(this->input->read(this->input, index_record, INDEX_RECORD_SIZE) - != INDEX_RECORD_SIZE) { - lprintf("index record not read\n"); - free(*index); - *index = NULL; - break; - } - - (*index)[i].timestamp = _X_BE_32(&index_record[2]); - (*index)[i].offset = _X_BE_32(&index_record[6]); - (*index)[i].packetno = _X_BE_32(&index_record[10]); - } - } else { - lprintf("unused index chunk with %d entries for stream num %d\n", - entries, stream_num); + if(index && entries && *index) { + /* Read index */ + for(i = 0; i < entries; i++) { + if(this->input->read(this->input, index_record, INDEX_RECORD_SIZE) + != INDEX_RECORD_SIZE) { + lprintf("index record not read\n"); + free(*index); + *index = NULL; + break; + } + + (*index)[i].timestamp = _X_BE_32(&index_record[2]); + (*index)[i].offset = _X_BE_32(&index_record[6]); + (*index)[i].packetno = _X_BE_32(&index_record[10]); } } else { - lprintf("expected index chunk found chunk type: %.4s\n", &index_chunk_header[0]); - break; + lprintf("unused index chunk with %d entries for stream num %d\n", + entries, stream_num); } } @@ -325,17 +331,12 @@ static void real_free_mdpr (mdpr_t *mdpr) { static void real_parse_audio_specific_data (demux_real_t *this, real_stream_t * stream, - uint8_t * data, int len) + uint8_t * data) { - int coded_frame_size; - int codec_data_length; - int coded_frame_size2; - int subpacket_size; - - coded_frame_size = _X_BE_32 (data+24); - codec_data_length = _X_BE_16 (data+40); - coded_frame_size2 = _X_BE_16 (data+42); - subpacket_size = _X_BE_16 (data+44); + const uint32_t coded_frame_size = _X_BE_32 (data+24); + const uint16_t codec_data_length = _X_BE_16 (data+40); + const uint16_t coded_frame_size2 = _X_BE_16 (data+42); + const uint16_t subpacket_size = _X_BE_16 (data+44); stream->sps = subpacket_size; stream->w = coded_frame_size2; @@ -365,15 +366,15 @@ static void real_parse_audio_specific_data (demux_real_t *this, "demux_real: error, i don't handle buf type 0x%08x\n", stream->buf_type); } - if (stream->sps) { - stream->frame_size = stream->w / stream->sps * stream->h * stream->sps; - stream->frame_buffer = xine_xmalloc (stream->frame_size); - stream->frame_num_bytes = 0; - } else { - stream->frame_size = stream->w * stream->h; - stream->frame_buffer = xine_xmalloc (stream->frame_size); - stream->frame_num_bytes = 0; - } + /* + * when stream->sps is set it used to do this: + * stream->frame_size = stream->w / stream->sps * stream->h * stream->sps; + * but it looks pointless? the compiler will probably optimise it away, I suppose? + */ + stream->frame_size = stream->w * stream->h; + + stream->frame_buffer = calloc(stream->frame_size, 1); + stream->frame_num_bytes = 0; stream->sub_packet_cnt = 0; xprintf (this->stream->xine, XINE_VERBOSITY_LOG, @@ -387,37 +388,35 @@ static void real_parse_headers (demux_real_t *this) { char preamble[PREAMBLE_SIZE]; unsigned int chunk_type = 0; unsigned int chunk_size; - unsigned short version; - unsigned char *chunk_buffer; - int field_size; - int stream_ptr; - unsigned char data_chunk_header[DATA_CHUNK_HEADER_SIZE]; - unsigned char signature[REAL_SIGNATURE_SIZE]; - - this->data_start = 0; - this->data_size = 0; - this->num_video_streams = 0; - this->num_audio_streams = 0; if (INPUT_IS_SEEKABLE(this->input)) this->input->seek (this->input, 0, SEEK_SET); - if (this->input->read(this->input, signature, REAL_SIGNATURE_SIZE) != - REAL_SIGNATURE_SIZE) { + { + uint8_t signature[REAL_SIGNATURE_SIZE]; + if (this->input->read(this->input, signature, REAL_SIGNATURE_SIZE) != + REAL_SIGNATURE_SIZE) { + + lprintf ("signature not read\n"); + this->status = DEMUX_FINISHED; + return; + } + + if ( !is_rmf_tag(signature) ) { + this->status = DEMUX_FINISHED; + lprintf ("signature not found '%.4s'\n", signature); + return; + } - lprintf ("signature not read\n"); - this->status = DEMUX_FINISHED; - return; + /* skip to the start of the first chunk and start traversing */ + chunk_size = _X_BE_32(&signature[4]); } - if (_X_BE_32(signature) != RMF_TAG) { - this->status = DEMUX_FINISHED; - lprintf ("signature not found '%.4s'\n", signature); - return; - } + this->data_start = 0; + this->data_size = 0; + this->num_video_streams = 0; + this->num_audio_streams = 0; - /* skip to the start of the first chunk and start traversing */ - chunk_size = _X_BE_32(&signature[4]); this->input->seek(this->input, chunk_size-8, SEEK_CUR); /* iterate through chunks and gather information until the first DATA @@ -438,183 +437,175 @@ static void real_parse_headers (demux_real_t *this) { case PROP_TAG: case MDPR_TAG: case CONT_TAG: - - chunk_size -= PREAMBLE_SIZE; - chunk_buffer = malloc(chunk_size); - if (this->input->read(this->input, chunk_buffer, chunk_size) != - chunk_size) { - free (chunk_buffer); - this->status = DEMUX_FINISHED; - return; - } + { + chunk_size -= PREAMBLE_SIZE; + uint8_t *const chunk_buffer = malloc(chunk_size); + if (this->input->read(this->input, chunk_buffer, chunk_size) != + chunk_size) { + free (chunk_buffer); + this->status = DEMUX_FINISHED; + return; + } - version = _X_BE_16(&chunk_buffer[0]); + uint16_t version = _X_BE_16(&chunk_buffer[0]); - if (chunk_type == PROP_TAG) { + if (chunk_type == PROP_TAG) { - if(version != 0) { - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "demuxe_real: unknown object version in PROP: 0x%04x\n", version); - free(chunk_buffer); - this->status = DEMUX_FINISHED; - return; - } + if(version != 0) { + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, + "demuxe_real: unknown object version in PROP: 0x%04x\n", version); + free(chunk_buffer); + this->status = DEMUX_FINISHED; + return; + } - this->duration = _X_BE_32(&chunk_buffer[22]); - this->index_start = _X_BE_32(&chunk_buffer[30]); - this->data_start = _X_BE_32(&chunk_buffer[34]); - this->avg_bitrate = _X_BE_32(&chunk_buffer[6]); + this->duration = _X_BE_32(&chunk_buffer[22]); + this->index_start = _X_BE_32(&chunk_buffer[30]); + this->data_start = _X_BE_32(&chunk_buffer[34]); + this->avg_bitrate = _X_BE_32(&chunk_buffer[6]); - lprintf("PROP: duration: %d ms\n", this->duration); - lprintf("PROP: index start: %"PRIX64"\n", this->index_start); - lprintf("PROP: data start: %"PRIX64"\n", this->data_start); - lprintf("PROP: average bit rate: %"PRId64"\n", this->avg_bitrate); + lprintf("PROP: duration: %d ms\n", this->duration); + lprintf("PROP: index start: %"PRIX64"\n", this->index_start); + lprintf("PROP: data start: %"PRIX64"\n", this->data_start); + lprintf("PROP: average bit rate: %"PRId64"\n", this->avg_bitrate); - if (this->avg_bitrate<1) - this->avg_bitrate = 1; + if (this->avg_bitrate<1) + this->avg_bitrate = 1; - _x_stream_info_set(this->stream, XINE_STREAM_INFO_BITRATE, + _x_stream_info_set(this->stream, XINE_STREAM_INFO_BITRATE, this->avg_bitrate); - } else if (chunk_type == MDPR_TAG) { - - mdpr_t *mdpr; - uint32_t fourcc; - - if (version != 0) { - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "demux_real: unknown object version in MDPR: 0x%04x\n", version); - free(chunk_buffer); - continue; - } + } else if (chunk_type == MDPR_TAG) { + if (version != 0) { + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, + "demux_real: unknown object version in MDPR: 0x%04x\n", version); + free(chunk_buffer); + continue; + } - mdpr = real_parse_mdpr (chunk_buffer); - - lprintf ("parsing type specific data...\n"); - if(!strcmp(mdpr->mime_type, "audio/X-MP3-draft-00")) { - lprintf ("mpeg layer 3 audio detected...\n"); - - fourcc = ME_FOURCC('a', 'd', 'u', 0x55); - this->audio_streams[this->num_audio_streams].fourcc = fourcc; - this->audio_streams[this->num_audio_streams].buf_type = _x_formattag_to_buf_audio(fourcc); - this->audio_streams[this->num_audio_streams].index = NULL; - this->audio_streams[this->num_audio_streams].mdpr = mdpr; - this->num_audio_streams++; - } else if(_X_BE_32(mdpr->type_specific_data) == RA_TAG) { - int version, len; - - if(this->num_audio_streams == MAX_AUDIO_STREAMS) { - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "demux_real: maximum number of audio stream exceeded\n"); - goto unknown; - } + mdpr_t *const mdpr = real_parse_mdpr (chunk_buffer); + + lprintf ("parsing type specific data...\n"); + if(!strcmp(mdpr->mime_type, "audio/X-MP3-draft-00")) { + lprintf ("mpeg layer 3 audio detected...\n"); + + static const uint32_t fourcc = ME_FOURCC('a', 'd', 'u', 0x55); + this->audio_streams[this->num_audio_streams].fourcc = fourcc; + this->audio_streams[this->num_audio_streams].buf_type = _x_formattag_to_buf_audio(fourcc); + this->audio_streams[this->num_audio_streams].index = NULL; + this->audio_streams[this->num_audio_streams].mdpr = mdpr; + this->num_audio_streams++; + } else if(_X_BE_32(mdpr->type_specific_data) == RA_TAG) { + if(this->num_audio_streams == MAX_AUDIO_STREAMS) { + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, + "demux_real: maximum number of audio stream exceeded\n"); + goto unknown; + } - version = _X_BE_16(mdpr->type_specific_data + 4); + const uint16_t version = _X_BE_16(mdpr->type_specific_data + 4); - lprintf("audio version %d detected\n", version); + lprintf("audio version %d detected\n", version); - switch(version) { + char *fourcc_ptr = NULL; + switch(version) { case 3: /* Version 3 header stores fourcc after meta info - cheat by reading backwards from the * end of the header instead of having to parse it all */ - fourcc = _X_ME_32(mdpr->type_specific_data + mdpr->type_specific_len - 5); + fourcc_ptr = mdpr->type_specific_data + mdpr->type_specific_len - 5; break; - case 4: - len = *(mdpr->type_specific_data + 56); - fourcc = _X_ME_32(mdpr->type_specific_data + 58 + len); + case 4: { + const uint8_t len = *(mdpr->type_specific_data + 56); + fourcc_ptr = mdpr->type_specific_data + 58 + len; + } break; case 5: - fourcc = _X_ME_32(mdpr->type_specific_data + 66); + fourcc_ptr = mdpr->type_specific_data + 66; break; default: lprintf("unsupported audio header version %d\n", version); goto unknown; - } + } - lprintf("fourcc = %.4s\n", (char *) &fourcc); + lprintf("fourcc = %.4s\n", fourcc_ptr); - this->audio_streams[this->num_audio_streams].fourcc = fourcc; - this->audio_streams[this->num_audio_streams].buf_type = _x_formattag_to_buf_audio(fourcc); - this->audio_streams[this->num_audio_streams].index = NULL; - this->audio_streams[this->num_audio_streams].mdpr = mdpr; + const uint32_t fourcc = _X_ME_32(fourcc_ptr); - real_parse_audio_specific_data (this, - &this->audio_streams[this->num_audio_streams], - mdpr->type_specific_data, - mdpr->type_specific_len); - this->num_audio_streams++; + this->audio_streams[this->num_audio_streams].fourcc = fourcc; + this->audio_streams[this->num_audio_streams].buf_type = _x_formattag_to_buf_audio(fourcc); + this->audio_streams[this->num_audio_streams].index = NULL; + this->audio_streams[this->num_audio_streams].mdpr = mdpr; - } else if(_X_BE_32(mdpr->type_specific_data + 4) == VIDO_TAG) { + real_parse_audio_specific_data (this, + &this->audio_streams[this->num_audio_streams], + mdpr->type_specific_data); + this->num_audio_streams++; - if(this->num_video_streams == MAX_VIDEO_STREAMS) { - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "demux_real: maximum number of video stream exceeded\n"); - goto unknown; - } + } else if(_X_BE_32(mdpr->type_specific_data + 4) == VIDO_TAG) { + + if(this->num_video_streams == MAX_VIDEO_STREAMS) { + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, + "demux_real: maximum number of video stream exceeded\n"); + goto unknown; + } - lprintf ("video detected\n"); - fourcc = _X_ME_32(mdpr->type_specific_data + 8); - lprintf("fourcc = %.4s\n", (char *) &fourcc); + lprintf ("video detected\n"); + const uint32_t fourcc = _X_ME_32(mdpr->type_specific_data + 8); + lprintf("fourcc = %.4s\n", (char *) &fourcc); - this->video_streams[this->num_video_streams].fourcc = fourcc; - this->video_streams[this->num_video_streams].buf_type = _x_fourcc_to_buf_video(fourcc); - this->video_streams[this->num_video_streams].format = _X_BE_32(mdpr->type_specific_data + 30); - this->video_streams[this->num_video_streams].index = NULL; - this->video_streams[this->num_video_streams].mdpr = mdpr; + this->video_streams[this->num_video_streams].fourcc = fourcc; + this->video_streams[this->num_video_streams].buf_type = _x_fourcc_to_buf_video(fourcc); + this->video_streams[this->num_video_streams].format = _X_BE_32(mdpr->type_specific_data + 30); + this->video_streams[this->num_video_streams].index = NULL; + this->video_streams[this->num_video_streams].mdpr = mdpr; - this->num_video_streams++; + this->num_video_streams++; - } else { - lprintf("unrecognised type specific data\n"); + } else { + lprintf("unrecognised type specific data\n"); -unknown: - real_free_mdpr(mdpr); - } + unknown: + real_free_mdpr(mdpr); + } - } else if (chunk_type == CONT_TAG) { + } else if (chunk_type == CONT_TAG) { - if(version != 0) { - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "demux_real: unknown object version in CONT: 0x%04x\n", version); - free(chunk_buffer); - continue; - } + if(version != 0) { + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, + "demux_real: unknown object version in CONT: 0x%04x\n", version); + free(chunk_buffer); + continue; + } - stream_ptr = 2; - - /* load the title string */ - field_size = _X_BE_16(&chunk_buffer[stream_ptr]); - stream_ptr += 2; - _x_meta_info_n_set(this->stream, XINE_META_INFO_TITLE, - &chunk_buffer[stream_ptr], field_size); - stream_ptr += field_size; - - /* load the author string */ - field_size = _X_BE_16(&chunk_buffer[stream_ptr]); - stream_ptr += 2; - _x_meta_info_n_set(this->stream, XINE_META_INFO_ARTIST, - &chunk_buffer[stream_ptr], field_size); - stream_ptr += field_size; - - /* load the copyright string as the year */ - field_size = _X_BE_16(&chunk_buffer[stream_ptr]); - stream_ptr += 2; - _x_meta_info_n_set(this->stream, XINE_META_INFO_YEAR, - &chunk_buffer[stream_ptr], field_size); - stream_ptr += field_size; - - /* load the comment string */ - field_size = _X_BE_16(&chunk_buffer[stream_ptr]); - stream_ptr += 2; - _x_meta_info_n_set(this->stream, XINE_META_INFO_COMMENT, - &chunk_buffer[stream_ptr], field_size); - stream_ptr += field_size; - } + int stream_ptr = 2; +#define SET_METADATA_STRING(type) \ + do { \ + const uint16_t field_size = _X_BE_16(&chunk_buffer[stream_ptr]); \ + stream_ptr += 2; \ + _x_meta_info_n_set(this->stream, type, \ + &chunk_buffer[stream_ptr], field_size); \ + stream_ptr += field_size; \ + } while(0) + + /* load the title string */ + SET_METADATA_STRING(XINE_META_INFO_TITLE); + + /* load the author string */ + SET_METADATA_STRING(XINE_META_INFO_ARTIST); + + /* load the copyright string as the year */ + SET_METADATA_STRING(XINE_META_INFO_YEAR); + + /* load the comment string */ + SET_METADATA_STRING(XINE_META_INFO_COMMENT); + } - free(chunk_buffer); + free(chunk_buffer); + } break; - case DATA_TAG: + case DATA_TAG: { + uint8_t data_chunk_header[DATA_CHUNK_HEADER_SIZE]; + if (this->input->read(this->input, data_chunk_header, DATA_CHUNK_HEADER_SIZE) != DATA_CHUNK_HEADER_SIZE) { this->status = DEMUX_FINISHED; @@ -622,7 +613,7 @@ unknown: } /* check version */ - version = _X_BE_16(&data_chunk_header[0]); + const uint16_t version = _X_BE_16(&data_chunk_header[0]); if(version != 0) { xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "demux_real: unknown object version in DATA: 0x%04x\n", version); @@ -633,7 +624,8 @@ unknown: this->current_data_chunk_packet_count = _X_BE_32(&data_chunk_header[2]); this->next_data_chunk_offset = _X_BE_32(&data_chunk_header[6]); this->data_chunk_size = chunk_size; - break; + } + break; default: /* this should not occur, but in case it does, skip the chunk */ @@ -649,16 +641,9 @@ unknown: real_parse_index(this); /* Simple stream selection case - 0/1 audio/video streams */ - if(this->num_video_streams == 1) - this->video_stream = &this->video_streams[0]; - else - this->video_stream = NULL; + this->video_stream = (this->num_video_streams == 1) ? &this->video_streams[0] : NULL; + this->audio_stream = (this->num_audio_streams == 1) ? &this->audio_streams[0] : NULL; - if(this->num_audio_streams == 1) - this->audio_stream = &this->audio_streams[0]; - else - this->audio_stream = NULL; - /* In the case of multiple audio/video streams select the first streams found in the file */ if((this->num_video_streams > 1) || (this->num_audio_streams > 1)) { @@ -698,15 +683,13 @@ unknown: while((offset < len) && ((!this->video_stream && (this->num_video_streams > 0)) || (!this->audio_stream && (this->num_audio_streams > 0)))) { - uint32_t id; - int i, stream; + int i; /* Check for end of the data chunk */ - if(((id = _X_BE_32(&search_buffer[offset])) == DATA_TAG) || - (id == INDX_TAG)) - break; + if (is_indx_tag(&search_buffer[offset]) || is_data_tag(&search_buffer[offset])) + break; - stream = _X_BE_16(&search_buffer[offset + 4]); + const int stream = _X_BE_16(&search_buffer[offset + 4]); for(i = 0; !this->video_stream && (i < this->num_video_streams); i++) { if(stream == this->video_streams[i].mdpr->stream_number) { @@ -740,14 +723,12 @@ unknown: /* Send headers and set meta info */ if(this->video_stream) { - buf_element_t *buf; - /* Check for recognised codec*/ if(!this->video_stream->buf_type) this->video_stream->buf_type = BUF_VIDEO_UNKNOWN; /* Send header */ - buf = this->video_fifo->buffer_pool_alloc(this->video_fifo); + buf_element_t *const buf = this->video_fifo->buffer_pool_alloc(this->video_fifo); buf->content = buf->mem; memcpy(buf->content, this->video_stream->mdpr->type_specific_data, @@ -780,10 +761,9 @@ unknown: /* Send headers */ if(this->audio_fifo) { - mdpr_t *mdpr = this->audio_stream->mdpr; - buf_element_t *buf; + mdpr_t *const mdpr = this->audio_stream->mdpr; - buf = this->audio_fifo->buffer_pool_alloc (this->audio_fifo); + buf_element_t *buf = this->audio_fifo->buffer_pool_alloc (this->audio_fifo); buf->type = this->audio_stream->buf_type; buf->decoder_flags = BUF_FLAG_HEADER|BUF_FLAG_FRAME_END; @@ -793,7 +773,7 @@ unknown: * The second is the codec initialisation data found at the end of * the type specific data for the audio stream */ if(buf->type == BUF_AUDIO_AAC) { - int version = _X_BE_16(mdpr->type_specific_data + 4); + const uint16_t version = _X_BE_16(mdpr->type_specific_data + 4); if(version != 5) { xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, @@ -954,9 +934,7 @@ static int demux_real_parse_references( demux_real_t *this) { #define PTS_VIDEO 1 static void check_newpts (demux_real_t *this, int64_t pts, int video, int preview) { - int64_t diff; - - diff = pts - this->last_pts[video]; + const int64_t diff = pts - this->last_pts[video]; lprintf ("check_newpts %"PRId64"\n", pts); if (!preview && pts && @@ -1062,19 +1040,14 @@ static int demux_real_send_chunk(demux_plugin_t *this_gen) { demux_real_t *this = (demux_real_t *) this_gen; char header[DATA_PACKET_HEADER_SIZE]; - int stream, size, keyframe, input_time = 0; - unsigned short version; - uint32_t id, timestamp; - int64_t pts; - off_t offset, input_length = 0; + int keyframe, input_time = 0; int normpos = 0; - read_next_packet: if(this->reference_mode) return demux_real_parse_references(this); /* load a header from wherever the stream happens to be pointing */ - if ( (size=this->input->read(this->input, header, DATA_PACKET_HEADER_SIZE)) != + if ( this->input->read(this->input, header, DATA_PACKET_HEADER_SIZE) != DATA_PACKET_HEADER_SIZE) { xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, @@ -1085,15 +1058,14 @@ static int demux_real_send_chunk(demux_plugin_t *this_gen) { } /* Check to see if we've gone past the end of the data chunk */ - if(((id = _X_BE_32(&header[0])) == DATA_TAG) || - (id == INDX_TAG)) { + if (is_indx_tag(&header[0]) || is_data_tag(&header[0])) { lprintf("finished reading data chunk\n"); this->status = DEMUX_FINISHED; return this->status; } /* check version */ - version = _X_BE_16(&header[0]); + const uint16_t version = _X_BE_16(&header[0]); if(version > 1) { xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "demux_real: unknown object version in data packet: 0x%04x\n", version); @@ -1102,11 +1074,11 @@ static int demux_real_send_chunk(demux_plugin_t *this_gen) { } /* read the packet information */ - stream = _X_BE_16(&header[4]); - offset = this->input->get_current_pos(this->input); - size = _X_BE_16(&header[2]) - DATA_PACKET_HEADER_SIZE; - timestamp= _X_BE_32(&header[6]); - pts = (int64_t) timestamp * 90; + const uint16_t stream = _X_BE_16(&header[4]); + const off_t offset = this->input->get_current_pos(this->input); + uint16_t size = _X_BE_16(&header[2]) - DATA_PACKET_HEADER_SIZE; + const uint32_t timestamp= _X_BE_32(&header[6]); + int64_t pts = (int64_t) timestamp * 90; /* Data packet header with version 1 contains 1 extra byte */ if(version == 0) @@ -1121,11 +1093,9 @@ static int demux_real_send_chunk(demux_plugin_t *this_gen) { if (this->video_stream && (stream == this->video_stream->mdpr->stream_number)) { - int vpkg_header, vpkg_length, vpkg_offset; int vpkg_seqnum = -1; int vpkg_subseq = 0; buf_element_t *buf; - int n, fragment_size; uint32_t decoder_flags; lprintf ("video chunk detected.\n"); @@ -1140,21 +1110,20 @@ static int demux_real_send_chunk(demux_plugin_t *this_gen) { * bit 6: 1=short header (only one block?) */ - vpkg_header = stream_read_char (this); size--; + const int vpkg_header = stream_read_char (this); size--; lprintf ("vpkg_hdr: %02x (size=%d)\n", vpkg_header, size); + int vpkg_length, vpkg_offset; if (0x40==(vpkg_header&0xc0)) { /* * seems to be a very short header * 2 bytes, purpose of the second byte yet unknown */ - int bummer; - - bummer = stream_read_char (this); size--; + const int bummer = stream_read_char (this); lprintf ("bummer == %02X\n",bummer); vpkg_offset = 0; - vpkg_length = size; + vpkg_length = --size; } else { @@ -1215,9 +1184,8 @@ static int demux_real_send_chunk(demux_plugin_t *this_gen) { input_time = (int)((int64_t) this->input->get_current_pos(this->input) * 8 * 1000 / this->avg_bitrate); - if(this->data_start && this->data_chunk_size) - input_length = this->data_start + 18 + this->data_chunk_size; - if( input_length ) + const off_t input_length = this->data_start + 18 + this->data_chunk_size; + if( input_length > 18 ) normpos = (int)((double) this->input->get_current_pos(this->input) * 65535 / input_length); check_newpts (this, pts, PTS_VIDEO, 0); @@ -1262,13 +1230,17 @@ static int demux_real_send_chunk(demux_plugin_t *this_gen) { * calc size of fragment */ - if ((vpkg_header & 0xc0) == 0x080) + int fragment_size; + switch(vpkg_header & 0xc0) { + case 0x80: fragment_size = vpkg_offset; - else { - if (0x00 == (vpkg_header&0xc0)) - fragment_size = size; - else - fragment_size = vpkg_length; + break; + case 0x00: + fragment_size = size; + break; + default: + fragment_size = vpkg_length; + break; } lprintf ("fragment size is %d\n", fragment_size); @@ -1276,14 +1248,11 @@ static int demux_real_send_chunk(demux_plugin_t *this_gen) { * read fragment_size bytes of data */ - n = fragment_size; + int n = fragment_size; while(n) { buf = this->video_fifo->buffer_pool_alloc(this->video_fifo); - if(n>buf->max_size) - buf->size = buf->max_size; - else - buf->size = n; + buf->size = MIN(n, buf->max_size); buf->decoder_flags = decoder_flags; decoder_flags &= ~BUF_FLAG_FRAME_START; @@ -1367,12 +1336,9 @@ static int demux_real_send_chunk(demux_plugin_t *this_gen) { input_time = (int)((int64_t) this->input->get_current_pos(this->input) * 8 * 1000 / this->avg_bitrate); - if(this->data_start && this->data_chunk_size) - input_length = this->data_start + 18 + this->data_chunk_size; - else - input_length = 0; + const off_t input_length = this->data_start + 18 + this->data_chunk_size; - if( input_length ) + if( input_length > 18 ) normpos = (int)((double) this->input->get_current_pos(this->input) * 65535 / input_length); check_newpts (this, pts, PTS_AUDIO, 0); @@ -1380,13 +1346,14 @@ static int demux_real_send_chunk(demux_plugin_t *this_gen) { /* Each packet of AAC is made up of several AAC frames preceded by a * header defining the size of the frames */ if(this->audio_stream->buf_type == BUF_AUDIO_AAC) { - int i, frames, *sizes; + int i; /* Upper 4 bits of second byte is frame count */ - frames = (stream_read_word(this) & 0xf0) >> 4; + const int frames = (stream_read_word(this) & 0xf0) >> 4; /* 2 bytes per frame size */ - sizes = calloc(frames, sizeof(int)); + int sizes[frames]; + for(i = 0; i < frames; i++) sizes[i] = stream_read_word(this); @@ -1398,15 +1365,12 @@ static int demux_real_send_chunk(demux_plugin_t *this_gen) { xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "demux_real: failed to read AAC frame\n"); - free(sizes); this->status = DEMUX_FINISHED; return this->status; } pts = 0; /* Only set pts on first frame */ } - - free(sizes); } else if (this->audio_stream->buf_type == BUF_AUDIO_COOK || this->audio_stream->buf_type == BUF_AUDIO_ATRK || this->audio_stream->buf_type == BUF_AUDIO_28_8 || @@ -1497,18 +1461,10 @@ discard: /* check if it's time to reload */ if (!this->current_data_chunk_packet_count && this->next_data_chunk_offset) { - char preamble[PREAMBLE_SIZE]; unsigned char data_chunk_header[DATA_CHUNK_HEADER_SIZE]; /* seek to the next DATA chunk offset */ - this->input->seek(this->input, this->next_data_chunk_offset, SEEK_SET); - - /* load the DATA chunk preamble */ - if (this->input->read(this->input, preamble, PREAMBLE_SIZE) != - PREAMBLE_SIZE) { - this->status = DEMUX_FINISHED; - return this->status; - } + this->input->seek(this->input, this->next_data_chunk_offset + PREAMBLE_SIZE, SEEK_SET); /* load the rest of the DATA chunk header */ if (this->input->read(this->input, data_chunk_header, @@ -1647,21 +1603,16 @@ static void demux_real_dispose (demux_plugin_t *this_gen) { for(i = 0; i < this->num_video_streams; i++) { real_free_mdpr(this->video_streams[i].mdpr); - if(this->video_streams[i].index) - free(this->video_streams[i].index); + free(this->video_streams[i].index); } for(i = 0; i < this->num_audio_streams; i++) { real_free_mdpr(this->audio_streams[i].mdpr); - if(this->audio_streams[i].index) - free(this->audio_streams[i].index); - if(this->audio_streams[i].frame_buffer) - free(this->audio_streams[i].frame_buffer); + free(this->audio_streams[i].index); + free(this->audio_streams[i].frame_buffer); } - if(this->fragment_tab) - free(this->fragment_tab); - + free(this->fragment_tab); free(this); } @@ -1688,21 +1639,27 @@ static int demux_real_get_optional_data(demux_plugin_t *this_gen, } /* help function to discover stream type. returns: + * -1 if couldn't read * 0 if not known. * 1 if normal stream. * 2 if reference stream. */ -static int real_check_stream_type(uint8_t *buf, int len) +static int real_check_stream_type(input_plugin_t *input) { - if ((buf[0] == 0x2e) - && (buf[1] == 'R') - && (buf[2] == 'M') - && (buf[3] == 'F')) + uint8_t buf[1024]; + off_t len = _x_demux_read_header(input, buf, sizeof(buf)); + + if ( len < 4 ) + return -1; + + if ( memcmp(buf, "\x2eRMF", 4) == 0 ) return 1; - buf[len] = '\0'; - if( strstr(buf,"pnm://") || strstr(buf,"rtsp://") || strstr(buf,"") || - !strncmp(buf,"http://",7) ) +#define my_strnstr(haystack, haystacklen, needle) \ + memmem(haystack, haystacklen, needle, sizeof(needle)) + + if( my_strnstr(buf, len, "pnm://") || my_strnstr(buf, len, "rtsp://") || + my_strnstr(buf, len, "") || !strncmp(buf, "http://", MIN(7, len)) ) return 2; return 0; @@ -1711,32 +1668,24 @@ static int real_check_stream_type(uint8_t *buf, int len) static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *stream, input_plugin_t *input) { - demux_real_t *this; - uint8_t buf[1024+1]; - int len, stream_type=0; - - switch (stream->content_detection_method) { - - case METHOD_BY_CONTENT:{ + /* discover stream type */ + const int stream_type = real_check_stream_type(input); - if (! (len = _x_demux_read_header(input, buf, 1024)) ) - return NULL; + if ( stream_type < 0 ) + return NULL; - lprintf ("read 4 bytes: %02x %02x %02x %02x\n", - buf[0], buf[1], buf[2], buf[3]); + switch (stream->content_detection_method) { - if (!(stream_type = real_check_stream_type(buf,len))) + case METHOD_BY_CONTENT: + if ( stream_type < 1 ) return NULL; - } - - lprintf ("by content accepted.\n"); - break; + + lprintf ("by content accepted.\n"); + break; case METHOD_BY_EXTENSION: { - const char *extensions, *mrl; - - mrl = input->get_mrl (input); - extensions = class_gen->get_extensions (class_gen); + const char *const mrl = input->get_mrl (input); + const char *const extensions = class_gen->get_extensions (class_gen); lprintf ("by extension '%s'\n", mrl); @@ -1755,17 +1704,11 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *str return NULL; } - - this = calloc(1, sizeof(demux_real_t)); + demux_real_t *this = calloc(1, sizeof(demux_real_t)); this->stream = stream; this->input = input; - /* discover stream type */ - if(!stream_type) - if ( (len = _x_demux_read_header(this->input, buf, 1024)) ) - stream_type = real_check_stream_type(buf,len); - if(stream_type == 2){ this->reference_mode = 1; lprintf("reference stream detected\n"); @@ -1812,9 +1755,7 @@ static void class_dispose (demux_class_t *this_gen) { } static void *init_class (xine_t *xine, void *data) { - demux_real_class_t *this; - - this = calloc(1, sizeof(demux_real_class_t)); + demux_real_class_t *const this = calloc(1, sizeof(demux_real_class_t)); this->demux_class.open_plugin = open_plugin; this->demux_class.get_description = get_description; diff --git a/src/demuxers/demux_realaudio.c b/src/demuxers/demux_realaudio.c index bc132adae..5b713cb60 100644 --- a/src/demuxers/demux_realaudio.c +++ b/src/demuxers/demux_realaudio.c @@ -64,7 +64,9 @@ typedef struct { off_t data_start; off_t data_size; - int sps, cfs, w, h; + uint32_t cfs; + uint16_t w, h; + int frame_len; int frame_size; uint8_t *frame_buffer; @@ -77,27 +79,22 @@ typedef struct { } demux_ra_class_t; /* Map flavour to bytes per second */ -static int sipr_fl2bps[4] = {813, 1062, 625, 2000}; // 6.5, 8.5, 5, 16 kbit per second +static const int sipr_fl2bps[4] = {813, 1062, 625, 2000}; // 6.5, 8.5, 5, 16 kbit per second /* returns 1 if the RealAudio file was opened successfully, 0 otherwise */ static int open_ra_file(demux_ra_t *this) { - unsigned char file_header[RA_FILE_HEADER_PREV_SIZE], len; - unsigned short version; - off_t offset; - + uint8_t file_header[RA_FILE_HEADER_PREV_SIZE]; /* check the signature */ if (_x_demux_read_header(this->input, file_header, RA_FILE_HEADER_PREV_SIZE) != RA_FILE_HEADER_PREV_SIZE) return 0; - if ((file_header[0] != '.') || - (file_header[1] != 'r') || - (file_header[2] != 'a')) + if ( memcmp(file_header, ".ra", 3) != 0 ) return 0; /* read version */ - version = _X_BE_16(&file_header[0x04]); + const uint16_t version = _X_BE_16(&file_header[0x04]); /* read header size according to version */ if (version == 3) @@ -118,6 +115,7 @@ static int open_ra_file(demux_ra_t *this) { return 0; } + off_t offset; /* read header data according to version */ if((version == 3) && (this->header_size >= 32)) { this->data_size = _X_BE_32(&this->header[0x12]); @@ -147,31 +145,37 @@ static int open_ra_file(demux_ra_t *this) { } /* Read title */ - len = this->header[offset]; - if(len && ((offset+len+2) < this->header_size)) { - _x_meta_info_n_set(this->stream, XINE_META_INFO_TITLE, - &this->header[offset+1], len); - offset += len+1; - } else - offset++; + { + const uint8_t len = this->header[offset]; + if(len && ((offset+len+2) < this->header_size)) { + _x_meta_info_n_set(this->stream, XINE_META_INFO_TITLE, + &this->header[offset+1], len); + offset += len+1; + } else + offset++; + } /* Author */ - len = this->header[offset]; - if(len && ((offset+len+1) < this->header_size)) { - _x_meta_info_n_set(this->stream, XINE_META_INFO_ARTIST, - &this->header[offset+1], len); - offset += len+1; - } else - offset++; + { + const uint8_t len = this->header[offset]; + if(len && ((offset+len+1) < this->header_size)) { + _x_meta_info_n_set(this->stream, XINE_META_INFO_ARTIST, + &this->header[offset+1], len); + offset += len+1; + } else + offset++; + } /* Copyright/Date */ - len = this->header[offset]; - if(len && ((offset+len) <= this->header_size)) { - _x_meta_info_n_set(this->stream, XINE_META_INFO_YEAR, - &this->header[offset+1], len); - offset += len+1; - } else - offset++; + { + const uint8_t len = this->header[offset]; + if(len && ((offset+len) <= this->header_size)) { + _x_meta_info_n_set(this->stream, XINE_META_INFO_YEAR, + &this->header[offset+1], len); + offset += len+1; + } else + offset++; + } /* Fourcc for version 3 comes after meta info */ if(version == 3) { @@ -193,17 +197,16 @@ static int open_ra_file(demux_ra_t *this) { this->audio_type = _x_formattag_to_buf_audio(this->fourcc); if (version == 4) { - this->sps = _X_BE_16 (this->header+44); + const uint16_t sps = _X_BE_16 (this->header+44) ? : 1; this->w = _X_BE_16 (this->header+42); this->h = _X_BE_16 (this->header+40); this->cfs = _X_BE_32 (this->header+24); - if (this->sps) { - this->frame_size = this->sps * this->h * this->sps; - this->frame_buffer = xine_xmalloc (this->frame_size); - } else { - this->frame_size = this->w * this->h; - this->frame_buffer = xine_xmalloc (this->frame_size); - } + + this->frame_len = this->w * this->h; + this->frame_size = this->frame_len * sps; + + this->frame_buffer = calloc(this->frame_size, 1); + _x_assert(this->frame_buffer != NULL); if (this->audio_type == BUF_AUDIO_28_8 || this->audio_type == BUF_AUDIO_SIPRO) this->block_align = this->cfs; @@ -227,7 +230,6 @@ static int demux_ra_send_chunk(demux_plugin_t *this_gen) { demux_ra_t *this = (demux_ra_t *) this_gen; off_t current_normpos = 0; - int64_t current_pts; /* just load data chunks from wherever the stream happens to be * pointing; issue a DEMUX_FINISHED status if EOF is reached */ @@ -235,7 +237,7 @@ static int demux_ra_send_chunk(demux_plugin_t *this_gen) { current_normpos = (int)( (double) (this->input->get_current_pos (this->input) - this->data_start) * 65535 / this->data_size ); - current_pts = 0; /* let the engine sort out the pts for now */ + const int64_t current_pts = 0; /* let the engine sort out the pts for now */ if (this->seek_flag) { _x_demux_control_newpts(this->stream, current_pts, BUF_FLAG_SEEK); @@ -243,26 +245,21 @@ static int demux_ra_send_chunk(demux_plugin_t *this_gen) { } if (this->audio_type == BUF_AUDIO_28_8 || this->audio_type == BUF_AUDIO_SIPRO) { - uint8_t * buffer; - - buffer = this->frame_buffer; if (this->audio_type == BUF_AUDIO_SIPRO) { - int len = this->h * this->w; - if(this->input->read(this->input, this->frame_buffer, len) < len) { + if(this->input->read(this->input, this->frame_buffer, this->frame_len) < this->frame_len) { xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "demux_realaudio: failed to read audio chunk\n"); this->status = DEMUX_FINISHED; return this->status; } - demux_real_sipro_swap (this->frame_buffer, len * 2 / 96); + demux_real_sipro_swap (this->frame_buffer, this->frame_len * 2 / 96); } else { int x, y; - int pos; for (y = 0; y < this->h; y++) for (x = 0; x < this->h / 2; x++) { - pos = x * 2 * this->w + y * this->cfs; + const int pos = x * 2 * this->w + y * this->cfs; if(this->input->read(this->input, this->frame_buffer + pos, this->cfs) < this->cfs) { xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, @@ -275,7 +272,7 @@ static int demux_ra_send_chunk(demux_plugin_t *this_gen) { } _x_demux_send_data(this->audio_fifo, - buffer, this->frame_size, + this->frame_buffer, this->frame_size, current_pts, this->audio_type, 0, current_normpos, current_pts / 90, 0, 0); } else if(_x_demux_read_send_data(this->audio_fifo, this->input, this->block_align, @@ -310,10 +307,7 @@ static void demux_ra_send_headers(demux_plugin_t *this_gen) { buf->type = this->audio_type; buf->decoder_flags = BUF_FLAG_HEADER|BUF_FLAG_FRAME_END; - if(this->header_size > buf->max_size) - buf->size = buf->max_size; - else - buf->size = this->header_size; + buf->size = MIN(this->header_size, buf->max_size); memcpy(buf->content, this->header, buf->size); -- cgit v1.2.3 From 2de9ee797a52d7e4066468956c00740d0855db1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Fri, 4 Jul 2008 15:24:30 +0200 Subject: Use calloc to allocate the memory area for the YUV planes. --HG-- extra : transplant_source : %00%23%8FM%AA%B88C%FEA%7E%2C%D3%F5%29%8F%28%AC%D7_ --- src/xine-utils/color.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/xine-utils/color.c b/src/xine-utils/color.c index 0b9cf0188..f5ebf6c00 100644 --- a/src/xine-utils/color.c +++ b/src/xine-utils/color.c @@ -159,18 +159,14 @@ void (*yuy2_to_yv12) * and height passed to it. The width must be divisible by 2. */ void init_yuv_planes(yuv_planes_t *yuv_planes, int width, int height) { - - int plane_size; - memset (yuv_planes, 0, sizeof (yuv_planes)); yuv_planes->row_width = width; yuv_planes->row_count = height; - plane_size = yuv_planes->row_width * yuv_planes->row_count; - yuv_planes->y = xine_xmalloc(plane_size); - yuv_planes->u = xine_xmalloc(plane_size); - yuv_planes->v = xine_xmalloc(plane_size); + yuv_planes->y = calloc(width, height); + yuv_planes->u = calloc(width, height); + yuv_planes->v = calloc(width, height); } /* -- cgit v1.2.3 From b627f62de4dbc6c3b56126bf26be0de7ad4f65d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Fri, 4 Jul 2008 15:25:28 +0200 Subject: Use calloc to allocate the lists of audio and video ports. --HG-- extra : transplant_source : T6%E7%60%7F%D4%60%C8l4%9AX%97%86hrR%AD%13%C0 --- src/xine-engine/post.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/xine-engine/post.c b/src/xine-engine/post.c index 4d8032bc0..af791c1f7 100644 --- a/src/xine-engine/post.c +++ b/src/xine-engine/post.c @@ -30,13 +30,10 @@ void _x_post_init(post_plugin_t *post, int num_audio_inputs, int num_video_inputs) { - int audio_inputs_size = (num_audio_inputs + 1) * sizeof(xine_audio_port_t *); - int video_inputs_size = (num_video_inputs + 1) * sizeof(xine_video_port_t *); - post->input = xine_list_new(); post->output = xine_list_new(); - post->xine_post.audio_input = (xine_audio_port_t **)xine_xmalloc(audio_inputs_size); - post->xine_post.video_input = (xine_video_port_t **)xine_xmalloc(video_inputs_size); + post->xine_post.audio_input = calloc(num_audio_inputs + 1, sizeof(xine_audio_port_t *)); + post->xine_post.audio_input = calloc(num_video_inputs + 1, sizeof(xine_video_port_t *)); } -- cgit v1.2.3 From 53d779e680b56506f5e882fe777206ef45e0ff79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Fri, 4 Jul 2008 15:25:46 +0200 Subject: Use calloc to allocate the area for the OSD. --HG-- extra : transplant_source : %99%9B%D5%B3Ro%87%BFV%E9%2BY%AA%83QE/%CD%5D%ED --- src/xine-engine/osd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/xine-engine/osd.c b/src/xine-engine/osd.c index 36ce47e44..05acd4779 100644 --- a/src/xine-engine/osd.c +++ b/src/xine-engine/osd.c @@ -145,7 +145,7 @@ static osd_object_t *XINE_MALLOC osd_new_object (osd_renderer_t *this, int width osd->width = width; osd->height = height; - osd->area = xine_xmalloc( width * height ); + osd->area = calloc(width, height); osd->x1 = width; osd->y1 = height; -- cgit v1.2.3 From 9c387686faaecae77027f0df541ddaf66fb78897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Fri, 4 Jul 2008 15:36:39 +0200 Subject: Add a _x_is_fourcc() inline function to wrap around memcmp(). This should be simpler and faster for the compiler to optimise rather than a _X_[BLM]E_32 macro and a comparison. --HG-- extra : transplant_source : %C7%1C%16%17N%3Bh%9B%EB%AA%00%A9%F1%15%C8%CB%8A%99%EE%7D --- src/xine-engine/buffer.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/xine-engine/buffer.h b/src/xine-engine/buffer.h index 5e43028e8..34e6f7c1d 100644 --- a/src/xine-engine/buffer.h +++ b/src/xine-engine/buffer.h @@ -39,6 +39,7 @@ extern "C" { #include "config.h" #endif +#include #include #include #include @@ -672,6 +673,10 @@ void _x_bmiheader_le2me( xine_bmiheader *bih ) XINE_PROTECTED; /* convert xine_waveformatex struct from little endian */ void _x_waveformatex_le2me( xine_waveformatex *wavex ) XINE_PROTECTED; +static inline _x_is_fourcc(void *ptr, void *tag) { + return memcmp(ptr, tag, 4) == 0; +} + #ifdef __cplusplus } #endif -- cgit v1.2.3 From f18dc23c1d5d3b947d43fe18b53d1a0ced918ad6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Fri, 4 Jul 2008 15:42:48 +0200 Subject: Use the new _x_is_fourcc() funtion to check for FOURCC tags in files. --HG-- extra : transplant_source : %B5%96xd%99U%EC%7Cr%ABB%A8%26l%08%99L3o%F6 --- src/demuxers/demux_aiff.c | 4 ++-- src/demuxers/demux_aud.c | 2 +- src/demuxers/demux_film.c | 4 ++-- src/demuxers/demux_real.c | 20 ++++---------------- src/demuxers/demux_snd.c | 4 +--- src/demuxers/demux_tta.c | 2 +- src/demuxers/demux_vqa.c | 4 ++-- src/demuxers/demux_wc3movie.c | 10 +++++----- 8 files changed, 18 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_aiff.c b/src/demuxers/demux_aiff.c index 6f8953a90..273992f64 100644 --- a/src/demuxers/demux_aiff.c +++ b/src/demuxers/demux_aiff.c @@ -115,8 +115,8 @@ static int open_aiff_file(demux_aiff_t *this) { return 0; /* check the signature */ - if ((_X_BE_32(&signature[0]) != FORM_TAG) || - (_X_BE_32(&signature[8]) != AIFF_TAG)) + if( !_x_is_fourcc(&signature[0], "FORM") || + !_x_is_fourcc(&signature[8], "AIFF") ) return 0; /* file is qualified; skip over the header bytes in the stream */ diff --git a/src/demuxers/demux_aud.c b/src/demuxers/demux_aud.c index b99c67806..7730de1fa 100644 --- a/src/demuxers/demux_aud.c +++ b/src/demuxers/demux_aud.c @@ -143,7 +143,7 @@ static int demux_aud_send_chunk(demux_plugin_t *this_gen) { } /* validate the chunk */ - if (_X_LE_32(&chunk_preamble[4]) != 0x0000DEAF) { + if (!_x_is_fourcc(&chunk_preamble[4], "\xAF\xDE\x00\x00")) { this->status = DEMUX_FINISHED; return this->status; } diff --git a/src/demuxers/demux_film.c b/src/demuxers/demux_film.c index 27986d9e1..dcd57f76c 100644 --- a/src/demuxers/demux_film.c +++ b/src/demuxers/demux_film.c @@ -141,9 +141,9 @@ static int open_film_file(demux_film_t *film) { return 0; /* FILM signature correct? */ - if (strncmp(scratch, "FILM", 4)) { + if (!_x_is_fourcc(scratch, "FILM")) return 0; - } + llprintf(DEBUG_FILM_LOAD, "found 'FILM' signature\n"); /* file is qualified; skip over the header bytes in the stream */ diff --git a/src/demuxers/demux_real.c b/src/demuxers/demux_real.c index f258fd73a..957cd5caa 100644 --- a/src/demuxers/demux_real.c +++ b/src/demuxers/demux_real.c @@ -174,18 +174,6 @@ typedef struct { demux_class_t demux_class; } demux_real_class_t; -static int is_indx_tag(const void *ptr) { - return memcmp(ptr, "INDX", 4) == 0; -} - -static int is_data_tag(const void *ptr) { - return memcmp(ptr, "DATA", 4) == 0; -} - -static int is_rmf_tag(const void *ptr) { - return memcmp(ptr, ".RMF", 4) == 0; -} - static void real_parse_index(demux_real_t *this) { off_t next_index_chunk = this->index_start; @@ -208,7 +196,7 @@ static void real_parse_index(demux_real_t *this) { } /* Check chunk is actually an index chunk */ - if(!is_indx_tag(&index_chunk_header[0])) { + if(!_x_is_fourcc(&index_chunk_header[0], "INDX")) { lprintf("expected index chunk found chunk type: %.4s\n", &index_chunk_header[0]); break; } @@ -402,7 +390,7 @@ static void real_parse_headers (demux_real_t *this) { return; } - if ( !is_rmf_tag(signature) ) { + if ( !_x_is_fourcc(signature, ".RMF") ) { this->status = DEMUX_FINISHED; lprintf ("signature not found '%.4s'\n", signature); return; @@ -686,7 +674,7 @@ static void real_parse_headers (demux_real_t *this) { int i; /* Check for end of the data chunk */ - if (is_indx_tag(&search_buffer[offset]) || is_data_tag(&search_buffer[offset])) + if (_x_is_fourcc(&search_buffer[offset], "INDX") || _x_is_fourcc(&search_buffer[offset], "DATA")) break; const int stream = _X_BE_16(&search_buffer[offset + 4]); @@ -1058,7 +1046,7 @@ static int demux_real_send_chunk(demux_plugin_t *this_gen) { } /* Check to see if we've gone past the end of the data chunk */ - if (is_indx_tag(&header[0]) || is_data_tag(&header[0])) { + if (_x_is_fourcc(&header[0], "INDX") || _x_is_fourcc(&header[0], "DATA")) { lprintf("finished reading data chunk\n"); this->status = DEMUX_FINISHED; return this->status; diff --git a/src/demuxers/demux_snd.c b/src/demuxers/demux_snd.c index 51a4315e5..b98b66758 100644 --- a/src/demuxers/demux_snd.c +++ b/src/demuxers/demux_snd.c @@ -42,8 +42,6 @@ #define SND_HEADER_SIZE 24 #define PCM_BLOCK_ALIGN 1024 -/* this is the big-endian hex value '.snd' */ -#define snd_TAG 0x2E736E64 typedef struct { demux_plugin_t demux_plugin; @@ -83,7 +81,7 @@ static int open_snd_file(demux_snd_t *this) { return 0; /* check the signature */ - if (_X_BE_32(&header[0]) != snd_TAG) + if ( !_x_is_fourcc(&header[0], ".snd") ) return 0; /* file is qualified; skip over the header bytes in the stream */ diff --git a/src/demuxers/demux_tta.c b/src/demuxers/demux_tta.c index 8e0595bda..68305a444 100644 --- a/src/demuxers/demux_tta.c +++ b/src/demuxers/demux_tta.c @@ -72,7 +72,7 @@ static int open_tta_file(demux_tta_t *this) { if (_x_demux_read_header(this->input, peek, 4) != 4) return 0; - if ( _X_BE_32(peek) != FOURCC_32('T', 'T', 'A', '1') ) + if ( !_x_is_fourcc(peek, "TTA1") ) return 0; if ( this->input->read(this->input, this->header.buffer, sizeof(this->header)) != sizeof(this->header) ) diff --git a/src/demuxers/demux_vqa.c b/src/demuxers/demux_vqa.c index ae0fd8231..5fb8273dd 100644 --- a/src/demuxers/demux_vqa.c +++ b/src/demuxers/demux_vqa.c @@ -96,8 +96,8 @@ static int open_vqa_file(demux_vqa_t *this) { return 0; /* check for the VQA signatures */ - if ((_X_BE_32(&scratch[0]) != FORM_TAG) || - (_X_BE_32(&scratch[8]) != WVQA_TAG)) + if (!_x_is_fourcc(&scratch[0], "FORM") || + !_x_is_fourcc(&scratch[8], "WVQA") ) return 0; /* file is qualified; skip to the start of the VQA header */ diff --git a/src/demuxers/demux_wc3movie.c b/src/demuxers/demux_wc3movie.c index 64ae431fb..7750c3e0e 100644 --- a/src/demuxers/demux_wc3movie.c +++ b/src/demuxers/demux_wc3movie.c @@ -357,9 +357,9 @@ static int open_mve_file(demux_mve_t *this) { if (_x_demux_read_header(this->input, header, WC3_HEADER_SIZE) != WC3_HEADER_SIZE) return 0; - if ((_X_BE_32(&header[0]) != FORM_TAG) || - (_X_BE_32(&header[8]) != MOVE_TAG) || - (_X_BE_32(&header[12]) != PC_TAG)) + if ( !_x_is_fourcc(&header[0], "FORM") || + !_x_is_fourcc(&header[8], "MOVE") || + !_x_is_fourcc(&header[12], "_PC_") ) return 0; /* file is qualified */ @@ -402,8 +402,8 @@ static int open_mve_file(demux_mve_t *this) { return 0; } - if ((_X_BE_32(&preamble[0]) != PALT_TAG) || - (_X_BE_32(&preamble[4]) != PALETTE_CHUNK_SIZE)) { + if ( !_x_is_fourcc(&preamble[0], "PALT") || + (_X_BE_32(&preamble[4]) != PALETTE_CHUNK_SIZE)) { xine_log(this->stream->xine, XINE_LOG_MSG, _("demux_wc3movie: There was a problem while loading palette chunks\n")); free (this->palettes); -- cgit v1.2.3 From 4084042931dd3c3b312836faa2744585a8ff8e82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Fri, 4 Jul 2008 15:45:36 +0200 Subject: Simplify signature checks, especially for OggFLAC files. Use memcmp over the signature rather than checking byte by byte. --HG-- extra : transplant_source : %B3%8B%EE%85%B9%11%B0%10po%D9%17%CD%034%FC%F5%90%95%92 --- src/demuxers/demux_ogg.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_ogg.c b/src/demuxers/demux_ogg.c index 16e6c40d9..2cbba982f 100644 --- a/src/demuxers/demux_ogg.c +++ b/src/demuxers/demux_ogg.c @@ -1020,7 +1020,7 @@ static void decode_dshow_header (demux_ogg_t *this, const int stream_num, ogg_pa this->si[stream_num]->headers = 0; /* header is sent below */ - if ( (_X_LE_32(&op->packet[96]) == 0x05589f80) && (op->bytes >= 184)) { + if ( _x_is_fourcc(&op->packet[96], "\x05\x58\x9f\x80") && (op->bytes >= 184)) { buf_element_t *buf; xine_bmiheader bih; @@ -1079,7 +1079,7 @@ static void decode_dshow_header (demux_ogg_t *this, const int stream_num, ogg_pa this->ignore_keyframes = 1; - } else if (_X_LE_32(&op->packet[96]) == 0x05589F81) { + } else if (_x_is_fourcc(&op->packet[96], "\x05\x58\x9f\x81")) { #if 0 /* FIXME: no test streams */ @@ -1198,23 +1198,23 @@ static void decode_flac_header (demux_ogg_t *this, const int stream_num, ogg_pac buf_element_t *buf; xine_waveformatex wave; - /* Packet type */ - _x_assert(op->packet[0] == 0x7F); - - /* OggFLAC signature */ - _x_assert(op->packet[1] == 'F'); _x_assert(op->packet[2] == 'L'); - _x_assert(op->packet[3] == 'A'); _x_assert(op->packet[4] == 'C'); + static const uint8_t flac_signature_1[] = + { + /* Packet type */ + 0x7F, + /* OggFLAC signature */ + 'F', 'L', 'A', 'C', + /* Version: only 1.0 supported */ + 1, 0 + }; + static const uint8_t flac_signature_2[] = "fLaC"; - /* Version: supported only 1.0 */ - _x_assert(op->packet[5] == 1); _x_assert(op->packet[6] == 0); + _x_assert(memcmp(&op->packet[0], flac_signature_1, sizeof(flac_signature_1)) == 0); + _x_assert(memcmp(&op->packet[9], flac_signature_2, sizeof(flac_signature_2)) == 0); /* Header count */ this->si[stream_num]->headers = 0/*_X_BE_16(&op->packet[7]) +1*/; - /* fLaC signature */ - _x_assert(op->packet[9] == 'f'); _x_assert(op->packet[10] == 'L'); - _x_assert(op->packet[11] == 'a'); _x_assert(op->packet[12] == 'C'); - _x_parse_flac_metadata_header(&op->packet[13], &header); switch ( header.blocktype ) { @@ -1929,11 +1929,7 @@ static int detect_ogg_content (int detection_method, demux_class_t *class_gen, if (_x_demux_read_header(input, buf, 4) != 4) return 0; - if ((buf[0] == 'O') && (buf[1] == 'g') && (buf[2] == 'g') && - (buf[3] == 'S')) - return 1; - else - return 0; + return _x_is_fourcc(buf, "OggS"); } case METHOD_BY_EXTENSION: { -- cgit v1.2.3 From c2a8075feb8af0f1e53279df298b2fb3fbbf270a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Fri, 4 Jul 2008 15:47:00 +0200 Subject: Cleanup code style and use the new _x_is_fourcc() function. --HG-- extra : transplant_source : %CB%BE%C4%81%A4%F8%C9.%3E%3B%EFa%2A%3E%1E%5B%B4%B0%25t --- src/demuxers/demux_4xm.c | 49 ++++++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_4xm.c b/src/demuxers/demux_4xm.c index c264e4421..a02a4b597 100644 --- a/src/demuxers/demux_4xm.c +++ b/src/demuxers/demux_4xm.c @@ -125,25 +125,15 @@ static float get_le_float(unsigned char *buffer) * This function is called from the _open() function of this demuxer. * It returns 1 if 4xm file was opened successfully. */ static int open_fourxm_file(demux_fourxm_t *fourxm) { - unsigned char preview[12]; - int header_size; - unsigned char *header; - int i; - unsigned int fourcc_tag; - unsigned int size; - unsigned int current_track; - unsigned int audio_type; - unsigned int total_frames; - float fps; /* the file signature will be in the first 12 bytes */ if (_x_demux_read_header(fourxm->input, preview, 12) != 12) return 0; /* check for the signature tags */ - if ((_X_LE_32(&preview[0]) != RIFF_TAG) || - (_X_LE_32(&preview[8]) != _4XMV_TAG)) + if (!_x_is_fourcc(&preview[0], "RIFF") || + !_x_is_fourcc(&preview[8], "4XMV")) return 0; /* file is qualified; skip over the header bytes in the stream */ @@ -152,13 +142,13 @@ static int open_fourxm_file(demux_fourxm_t *fourxm) { /* fetch the LIST-HEAD header */ if (fourxm->input->read(fourxm->input, preview, 12) != 12) return 0; - if ((_X_LE_32(&preview[0]) != LIST_TAG) || - (_X_LE_32(&preview[8]) != HEAD_TAG)) + if (!_x_is_fourcc(&preview[0], "LIST") || + !_x_is_fourcc(&preview[8], "HEAD") ) return 0; /* read the whole header */ - header_size = _X_LE_32(&preview[4]) - 4; - header = malloc(header_size); + const uint32_t header_size = _X_LE_32(&preview[4]) - 4; + uint8_t *const header = malloc(header_size); if (!header || fourxm->input->read(fourxm->input, header, header_size) != header_size) { free(header); return 0; @@ -171,12 +161,13 @@ static int open_fourxm_file(demux_fourxm_t *fourxm) { fourxm->video_pts_inc = 0; /* take the lazy approach and search for any and all vtrk and strk chunks */ + int i; for (i = 0; i < header_size - 8; i++) { - fourcc_tag = _X_LE_32(&header[i]); - size = _X_LE_32(&header[i + 4]); + const uint32_t fourcc_tag = _X_LE_32(&header[i]); + const uint32_t size = _X_LE_32(&header[i + 4]); if (fourcc_tag == std__TAG) { - fps = get_le_float(&header[i + 12]); + const float fps = get_le_float(&header[i + 12]); fourxm->video_pts_inc = (int64_t)(90000.0 / fps); } else if (fourcc_tag == vtrk_TAG) { /* check that there is enough data */ @@ -184,7 +175,7 @@ static int open_fourxm_file(demux_fourxm_t *fourxm) { free(header); return 0; } - total_frames = _X_LE_32(&header[i + 24]); + const uint32_t total_frames = _X_LE_32(&header[i + 24]); fourxm->duration_in_ms = total_frames; fourxm->duration_in_ms *= fourxm->video_pts_inc; fourxm->duration_in_ms /= 90000; @@ -198,7 +189,7 @@ static int open_fourxm_file(demux_fourxm_t *fourxm) { free(header); return 0; } - current_track = _X_LE_32(&header[i + 8]); + const uint32_t current_track = _X_LE_32(&header[i + 8]); if (current_track + 1 > fourxm->track_count) { fourxm->track_count = current_track + 1; fourxm->tracks = realloc(fourxm->tracks, @@ -212,7 +203,7 @@ static int open_fourxm_file(demux_fourxm_t *fourxm) { fourxm->tracks[current_track].channels = _X_LE_32(&header[i + 36]); fourxm->tracks[current_track].sample_rate = _X_LE_32(&header[i + 40]); fourxm->tracks[current_track].bits = _X_LE_32(&header[i + 44]); - audio_type = _X_LE_32(&header[i + 12]); + const uint32_t audio_type = _X_LE_32(&header[i + 12]); if (audio_type == 0) fourxm->tracks[current_track].audio_type = BUF_AUDIO_LPCM_LE; else if (audio_type == 1) @@ -239,20 +230,18 @@ static int demux_fourxm_send_chunk(demux_plugin_t *this_gen) { demux_fourxm_t *this = (demux_fourxm_t *) this_gen; buf_element_t *buf = NULL; - unsigned int fourcc_tag; - unsigned int size; - unsigned char header[8]; unsigned int remaining_bytes; unsigned int current_track; /* read the next header */ + uint8_t header[8]; if (this->input->read(this->input, header, 8) != 8) { this->status = DEMUX_FINISHED; return this->status; } - fourcc_tag = _X_LE_32(&header[0]); - size = _X_LE_32(&header[4]); + const uint32_t fourcc_tag = _X_LE_32(&header[0]); + const uint32_t size = _X_LE_32(&header[4]); switch (fourcc_tag) { @@ -491,10 +480,8 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *str switch (stream->content_detection_method) { case METHOD_BY_EXTENSION: { - const char *extensions, *mrl; - - mrl = input->get_mrl (input); - extensions = class_gen->get_extensions (class_gen); + const char *const mrl = input->get_mrl (input); + const char *const extensions = class_gen->get_extensions (class_gen); if (!_x_demux_check_extension (mrl, extensions)) { free (this); -- cgit v1.2.3 From e658d8485c47059959ea8b1b2b0342b7d017d5d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Fri, 4 Jul 2008 15:47:29 +0200 Subject: Use the new _x_is_fourcc() function and also memcmp(). --HG-- extra : transplant_source : %F8H%5B%D0%15z%0E%22%CC.%84%E6%ADA/%FF%0F%81%BCS --- src/demuxers/demux_aac.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_aac.c b/src/demuxers/demux_aac.c index 63c787bc7..b8e6ec5c4 100644 --- a/src/demuxers/demux_aac.c +++ b/src/demuxers/demux_aac.c @@ -95,8 +95,7 @@ static int open_aac_file(demux_aac_t *this) { return 0; /* Check for an ADIF header - should be at the start of the file */ - if ((peak[0] == 'A') && (peak[1] == 'D') && - (peak[2] == 'I') && (peak[3] == 'F')) { + if (_x_is_fourcc(peak, "AIDF")) { lprintf("found ADIF header\n"); return 1; } @@ -134,9 +133,7 @@ static int open_aac_file(demux_aac_t *this) { if ((frame_size > 0) && (data_start+frame_size < MAX_PREVIEW_SIZE-1) && /* first 28 bits must be identical */ - (peak[data_start ] ==peak[data_start+frame_size ]) && - (peak[data_start+1] ==peak[data_start+frame_size+1]) && - (peak[data_start+2] ==peak[data_start+frame_size+2]) && + memcmp(&peak[data_start], &peak[data_start+frame_size], 4) == 0 && (peak[data_start+3]>>4==peak[data_start+frame_size+3]>>4)) { lprintf("found second ADTS header\n"); -- cgit v1.2.3 From a5fea58eeaff30d4bb4464c619af9d49faf425ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Fri, 4 Jul 2008 15:49:21 +0200 Subject: Improve header processing and misc cleanups. When processing the header, read the whole 12-bytes block at once, then use _x_is_fourcc() to check for the signatures, and only then try to find the size. --HG-- extra : transplant_source : %B8%90%00%DAJ%7F%3F%E4%00%05%07z%3D%C5%02%03v%A8%B4C --- src/demuxers/demux_eawve.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_eawve.c b/src/demuxers/demux_eawve.c index 58ce4520f..7a21635cb 100644 --- a/src/demuxers/demux_eawve.c +++ b/src/demuxers/demux_eawve.c @@ -78,16 +78,16 @@ typedef struct { */ static uint32_t read_arbitary(input_plugin_t *input){ - uint8_t size, byte; - int i; - uint32_t word; + uint8_t size; if (input->read(input, (void*)&size, 1) != 1) { return 0; } - word = 0; + uint32_t word = 0; + int i; for (i=0;iread(input, (void*)&byte, 1) != 1) { return 0; } @@ -104,33 +104,25 @@ static uint32_t read_arbitary(input_plugin_t *input){ */ static int process_header(demux_eawve_t *this){ - int inHeader; - uint32_t blockid, size; + uint8_t header[12]; if (this->input->get_current_pos(this->input) != 0) this->input->seek(this->input, 0, SEEK_SET); - if (this->input->read(this->input, (void*)&blockid, 4) != 4) { - return 0; - } - if (be2me_32(blockid) != FOURCC_TAG('S', 'C', 'H', 'l')) { + if (this->input->read(this->input, header, sizeof(header)) != sizeof(header)) return 0; - } - if (this->input->read(this->input, (void*)&size, 4) != 4) { + if (!_x_is_fourcc(&header[0], "SCHl")) return 0; - } - size = le2me_32(size); - if (this->input->read(this->input, (void*)&blockid, 4) != 4) { - return 0; - } - if (be2me_32(blockid) != FOURCC_TAG('P', 'T', '\0', '\0')) { + if (!_x_is_fourcc(&header[8], "PT\0\0")) { lprintf("PT header missing\n"); return 0; } - inHeader = 1; + const uint32_t size = _X_LE_32(&header[4]); + + int inHeader = 1; while (inHeader) { int inSubheader; uint8_t byte; -- cgit v1.2.3 From ee4a1c92793179af16cd4a9b6c2a75e00ab45beb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Fri, 4 Jul 2008 15:50:15 +0200 Subject: Use id3.h functions to check for ID3 tags. Rather than checking for the ID3 signature manually use id3_istag() function. Also use the _X_BE_32_synchsafe function rather than re-implementing it again. Use memcmp() to look for MPC signature. --HG-- extra : transplant_source : %3A%8CE%9B%B6%BC%CBm%DA%A4%26M%A0%CC%C5OV%1C%93%01 --- src/demuxers/demux_mpc.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_mpc.c b/src/demuxers/demux_mpc.c index e00a50ea3..9b27e5954 100644 --- a/src/demuxers/demux_mpc.c +++ b/src/demuxers/demux_mpc.c @@ -47,6 +47,7 @@ #include "buffer.h" #include "bswap.h" #include "group_audio.h" +#include "id3.h" /* Note that the header is actually 25 bytes long, so we'd only read 28 * (because of byte swapping we have to round up to nearest multiple of 4) @@ -89,17 +90,13 @@ static int open_mpc_file(demux_mpc_t *this) { /* TODO: non-seeking version */ if (INPUT_IS_SEEKABLE(this->input)) { /* Check for id3v2 tag */ - if ((this->header[0] == 'I') || - (this->header[1] == 'D') || - (this->header[2] == '3')) { + if (id3v2_istag(this->header)) { lprintf("found id3v2 header\n"); /* Read tag size */ - id3v2_size = (this->header[6] << 21) + - (this->header[7] << 14) + - (this->header[8] << 7) + - this->header[9] + 10; + + id3v2_size = _X_BE_32_synchsafe(&this->header[6]) + 10; /* Add footer size if one is present */ if (this->header[5] & 0x10) @@ -118,9 +115,7 @@ static int open_mpc_file(demux_mpc_t *this) { } /* Validate signature - We only support SV 7.x at the moment */ - if ((this->header[0] != 'M') || - (this->header[1] != 'P') || - (this->header[2] != '+') || + if ( memcmp(this->header, "MP+", 3) != 0 || ((this->header[3]&0x0f) != 0x07)) return 0; -- cgit v1.2.3 From 74a89aa56a2339eff12aef13330c9a43850de5d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Fri, 4 Jul 2008 15:54:44 +0200 Subject: Use memcmp() instead of manual comparison of bytes when checking signatures. When it make sense, use _x_is_fourcc() too. --HG-- extra : transplant_source : %A7%AA%1D%B1%EE3%BF%2C%BCn%2B%3Dt%2Bi%E6%80%8ERm --- src/demuxers/demux_nsf.c | 6 +----- src/demuxers/demux_nsv.c | 17 +++++------------ src/demuxers/demux_rawdv.c | 3 +-- src/demuxers/demux_roq.c | 6 +++--- src/demuxers/demux_smjpeg.c | 20 +++++++------------- src/demuxers/demux_str.c | 30 +++++++++++++++--------------- src/demuxers/demux_voc.c | 4 ++-- 7 files changed, 34 insertions(+), 52 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_nsf.c b/src/demuxers/demux_nsf.c index 557adf28d..60d5049d9 100644 --- a/src/demuxers/demux_nsf.c +++ b/src/demuxers/demux_nsf.c @@ -97,11 +97,7 @@ static int open_nsf_file(demux_nsf_t *this) { return 0; /* check for the signature */ - if ((header[0] != 'N') || - (header[1] != 'E') || - (header[2] != 'S') || - (header[3] != 'M') || - (header[4] != 0x1A)) + if (memcmp(header, "NESM\x1A", 5) != 0) return 0; this->total_songs = header[6]; diff --git a/src/demuxers/demux_nsv.c b/src/demuxers/demux_nsv.c index 71046b039..42d31ca14 100644 --- a/src/demuxers/demux_nsv.c +++ b/src/demuxers/demux_nsv.c @@ -50,7 +50,6 @@ #define FOURCC_TAG BE_FOURCC #define NSVf_TAG FOURCC_TAG('N', 'S', 'V', 'f') #define NSVs_TAG FOURCC_TAG('N', 'S', 'V', 's') -#define NONE_TAG FOURCC_TAG('N', 'O', 'N', 'E') #define BEEF 0xEFBE @@ -256,17 +255,11 @@ static int open_nsv_file(demux_nsv_t *this) { return 0; /* check for a 'NSV' signature */ - if ((preview[0] != 'N') || - (preview[1] != 'S') || - (preview[2] != 'V')) - { - if ((preview[0] != 'Z') || - (preview[1] != 0) || - (preview[2] != '9')) - return 0; + if ( memcmp(preview, "Z\09", 3) == 0) { this->is_ultravox = preview[3]; this->ultravox_first = 1; - } + } else if ( memcmp(preview, "NSV", 3) != 0 ) + return 0; lprintf("NSV file detected, ultravox=%d\n", this->is_ultravox); @@ -302,13 +295,13 @@ static int open_nsv_file(demux_nsv_t *this) { return 0; this->video_fourcc = _X_ME_32(&preview[4]); - if (_X_BE_32(&preview[4]) == NONE_TAG) + if (_x_is_fourcc(&preview[4], "NONE")) this->video_type = 0; else this->video_type = _x_fourcc_to_buf_video(this->video_fourcc); this->audio_fourcc = _X_ME_32(&preview[8]); - if (_X_BE_32(&preview[8]) == NONE_TAG) + if (_x_is_fourcc(&preview[8], "NONE")) this->audio_type = 0; else this->audio_type = _x_formattag_to_buf_audio(this->audio_fourcc); diff --git a/src/demuxers/demux_rawdv.c b/src/demuxers/demux_rawdv.c index 848f871c8..17dd52225 100644 --- a/src/demuxers/demux_rawdv.c +++ b/src/demuxers/demux_rawdv.c @@ -374,8 +374,7 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *str } /* DIF (DV) movie file */ - if (!((buf[0] == 0x1f) && (buf[1] == 0x07) && (buf[2] == 00) && - (buf[4] ^ 0x01))) { + if (memcmp(buf, "\x1F\x07\x00", 3) != 0 && !(buf[4] ^ 0x01)) { free (this); return NULL; } diff --git a/src/demuxers/demux_roq.c b/src/demuxers/demux_roq.c index ea68609f2..df2fb76a5 100644 --- a/src/demuxers/demux_roq.c +++ b/src/demuxers/demux_roq.c @@ -47,7 +47,6 @@ #include "bswap.h" #include "group_games.h" -#define RoQ_MAGIC_NUMBER 0x1084 #define RoQ_CHUNK_PREAMBLE_SIZE 8 #define RoQ_AUDIO_SAMPLE_RATE 22050 @@ -93,8 +92,9 @@ static int open_roq_file(demux_roq_t *this) { return 0; /* check for the RoQ magic numbers */ - if ((_X_LE_16(&preamble[0]) != RoQ_MAGIC_NUMBER) || - (_X_LE_32(&preamble[2]) != 0xFFFFFFFF)) + static const uint8_t RoQ_MAGIC_STRING[] = + { 0x10, 0x84, 0xFF, 0xFF, 0xFF, 0xFF }; + if( memcmp(preamble, RoQ_MAGIC_STRING, sizeof(RoQ_MAGIC_STRING)) != 0 ) return 0; this->bih.biSize = sizeof(xine_bmiheader); diff --git a/src/demuxers/demux_smjpeg.c b/src/demuxers/demux_smjpeg.c index 8857f90fd..aacd55503 100644 --- a/src/demuxers/demux_smjpeg.c +++ b/src/demuxers/demux_smjpeg.c @@ -55,7 +55,6 @@ #define vidD_TAG FOURCC_TAG('v', 'i', 'd', 'D') #define APCM_TAG FOURCC_TAG('A', 'P', 'C', 'M') -#define SMJPEG_SIGNATURE_SIZE 8 /* 16 is the max size of a header chunk (the video header) */ #define SMJPEG_VIDEO_HEADER_SIZE 16 #define SMJPEG_AUDIO_HEADER_SIZE 12 @@ -98,23 +97,18 @@ static int open_smjpeg_file(demux_smjpeg_t *this) { unsigned char header_chunk[SMJPEG_HEADER_CHUNK_MAX_SIZE]; unsigned int audio_codec = 0; - if (_x_demux_read_header(this->input, signature, SMJPEG_SIGNATURE_SIZE) != - SMJPEG_SIGNATURE_SIZE) + static const uint8_t SMJPEG_SIGNATURE[8] = + { 0x00, 0x0A, 'S', 'M', 'J', 'P', 'E', 'G' }; + + if (_x_demux_read_header(this->input, signature, sizeof(SMJPEG_SIGNATURE)) != + sizeof(SMJPEG_SIGNATURE)) return 0; - /* check for the SMJPEG signature */ - if ((signature[0] != 0x00) || - (signature[1] != 0x0A) || - (signature[2] != 'S') || - (signature[3] != 'M') || - (signature[4] != 'J') || - (signature[5] != 'P') || - (signature[6] != 'E') || - (signature[7] != 'G')) + if (memcmp(signature, SMJPEG_SIGNATURE, sizeof(SMJPEG_SIGNATURE)) != 0) return 0; /* file is qualified; jump over the header + version to the duration */ - this->input->seek(this->input, SMJPEG_SIGNATURE_SIZE + 4, SEEK_SET); + this->input->seek(this->input, sizeof(SMJPEG_SIGNATURE) + 4, SEEK_SET); if (this->input->read(this->input, header_chunk, 4) != 4) return 0; this->duration = _X_BE_32(&header_chunk[0]); diff --git a/src/demuxers/demux_str.c b/src/demuxers/demux_str.c index 1e750f183..a49084ba7 100644 --- a/src/demuxers/demux_str.c +++ b/src/demuxers/demux_str.c @@ -139,20 +139,16 @@ #define CD_RAW_SECTOR_SIZE 2352 +static const uint8_t STR_MAGIC = + { 0x60, 0x01, 0x01, 0x80 }; #define STR_MAX_CHANNELS 32 -#define STR_MAGIC (0x80010160) - #define CDXA_TYPE_MASK 0x0E #define CDXA_TYPE_DATA 0x08 #define CDXA_TYPE_AUDIO 0x04 #define CDXA_TYPE_VIDEO 0x02 #define CDXA_SUBMODE_EOF 0x80 /* set if EOF */ -#define FOURCC_TAG BE_FOURCC -#define RIFF_TAG FOURCC_TAG('R', 'I', 'F', 'F') -#define CDXA_TAG FOURCC_TAG('C', 'D', 'X', 'A') - /* FIXME */ #define FRAME_DURATION 45000 @@ -198,8 +194,8 @@ static int open_str_file(demux_str_t *this) { } /* check for STR with a RIFF header */ - if ((_X_BE_32(&check_bytes[0]) == RIFF_TAG) && - (_X_BE_32(&check_bytes[8]) == CDXA_TAG)) + if ( _x_is_fourcc(&check_bytes[0], "RIFF") && + _x_is_fourcc(&check_bytes[8], "CDXA") ) local_offset = 0x2C; else local_offset = 0; @@ -216,16 +212,20 @@ static int open_str_file(demux_str_t *this) { check_bytes[local_offset + 0x13]); /* check for 12-byte sync marker */ - if ((_X_BE_32(&check_bytes[local_offset + 0]) != 0x00FFFFFF) || - (_X_BE_32(&check_bytes[local_offset + 4]) != 0xFFFFFFFF) || - (_X_BE_32(&check_bytes[local_offset + 8]) != 0xFFFFFF00)) { + static const uint8_t sync_marker[12] = + { 0x00, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0xFF, 0xFF, 0X00 + }; + if ( memcmp(&check_bytes[local_offset], + sync_marker, sizeof(sync_marker)) != 0 ) { lprintf("sector %d sync error\n", sector); return 0; } /* the 32 bits starting at 0x10 and at 0x14 should be the same */ - if (_X_BE_32(&check_bytes[local_offset + 0x10]) != - _X_BE_32(&check_bytes[local_offset + 0x14])) { + if (memcmp(&check_bytes[local_offset + 0x10], + &check_bytes[local_offset + 0x14], 4) != 0) { lprintf("sector %d control bits copy error\n", sector); return 0; } @@ -244,7 +244,7 @@ static int open_str_file(demux_str_t *this) { case CDXA_TYPE_VIDEO: /* first time we have seen video/data in this channel? */ if ((!(this->channel_type[channel] & CDXA_TYPE_DATA)) && - (_X_LE_32(&check_bytes[local_offset + 0x18]) == STR_MAGIC)) { + (_x_is_fourcc(&check_bytes[local_offset + 0x18], STR_MAGIC))) { /* mark this channel as having video data */ this->channel_type[channel] |= CDXA_TYPE_VIDEO; @@ -345,7 +345,7 @@ static int demux_str_send_chunk(demux_plugin_t *this_gen) { case CDXA_TYPE_DATA: /* video chunk */ - if (_X_LE_32(§or[0x18]) != STR_MAGIC || + if (!_x_is_fourcc(§or[0x18], STR_MAGIC) || channel != this->default_video_channel) { return 0; } diff --git a/src/demuxers/demux_voc.c b/src/demuxers/demux_voc.c index 1d6277186..e825f6869 100644 --- a/src/demuxers/demux_voc.c +++ b/src/demuxers/demux_voc.c @@ -85,7 +85,7 @@ static int open_voc_file(demux_voc_t *this) { return 0; /* check the signature */ - if (strncmp(header, VOC_SIGNATURE, strlen(VOC_SIGNATURE)) != 0) + if (memcmp(header, VOC_SIGNATURE, sizeof(VOC_SIGNATURE)-1) != 0) return 0; /* file is qualified */ @@ -106,7 +106,7 @@ static int open_voc_file(demux_voc_t *this) { } /* assemble 24-bit, little endian length */ - this->data_size = preamble[1] | (preamble[2] << 8) | (preamble[3] << 16); + this->data_size = _X_LE_24(&preamble[1]); /* get the next 2 bytes (re-use preamble bytes) */ if (this->input->read(this->input, preamble, 2) != 2) -- cgit v1.2.3 From fb7a3757ee5a4ba0dba313148734592a55093f96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Fri, 4 Jul 2008 16:10:40 +0200 Subject: Cleanup code style, use memmem() to find the start of a frame. Cleanup the code to follow the new code style, and in particuar use memmem() to identify the start of a frame rather than trying to look for it manually byte by byte. --HG-- extra : transplant_source : H%E8-%9D%AA%3A%40%FE%E6%ACE%F0%11G%BA%C6%FA%C4w%96 --- src/demuxers/demux_yuv4mpeg2.c | 72 +++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_yuv4mpeg2.c b/src/demuxers/demux_yuv4mpeg2.c index ca8234d96..2387fc7a7 100644 --- a/src/demuxers/demux_yuv4mpeg2.c +++ b/src/demuxers/demux_yuv4mpeg2.c @@ -197,21 +197,13 @@ static int open_yuv4mpeg2_file(demux_yuv4mpeg2_t *this) { this->frame_pts_inc = (90000 * this->fps_d) / this->fps_n; /* finally, look for the first frame */ - while ((header_ptr - header) < (Y4M_HEADER_BYTES - 4)) { - if((header_ptr[0] == 'F') && - (header_ptr[1] == 'R') && - (header_ptr[2] == 'A') && - (header_ptr[3] == 'M') && - (header_ptr[4] == 'E')) { - this->data_start = header_ptr - header; - break; - } else - header_ptr++; - } - + char *data_start_ptr = memmem(header_ptr, Y4M_HEADER_BYTES, "FRAME", 5); + /* make sure the first frame was found */ - if(!this->data_start) + if ( !data_start_ptr ) return 0; + + this->data_start = data_start_ptr - header; /* compute size of all frames */ if (INPUT_IS_SEEKABLE(this->input)) { @@ -228,29 +220,26 @@ static int open_yuv4mpeg2_file(demux_yuv4mpeg2_t *this) { static int demux_yuv4mpeg2_send_chunk(demux_plugin_t *this_gen) { demux_yuv4mpeg2_t *this = (demux_yuv4mpeg2_t *) this_gen; - buf_element_t *buf = NULL; - unsigned char preamble[Y4M_FRAME_SIGNATURE_SIZE]; - int bytes_remaining; - off_t current_file_pos; - int64_t pts; - /* validate that this is an actual frame boundary */ - if (this->input->read(this->input, preamble, Y4M_FRAME_SIGNATURE_SIZE) != - Y4M_FRAME_SIGNATURE_SIZE) { - this->status = DEMUX_FINISHED; - return this->status; - } - if (memcmp(preamble, Y4M_FRAME_SIGNATURE, Y4M_FRAME_SIGNATURE_SIZE) != - 0) { - this->status = DEMUX_FINISHED; - return this->status; + { + uint8_t preamble[Y4M_FRAME_SIGNATURE_SIZE]; + if (this->input->read(this->input, preamble, Y4M_FRAME_SIGNATURE_SIZE) != + Y4M_FRAME_SIGNATURE_SIZE) { + this->status = DEMUX_FINISHED; + return this->status; + } + if (memcmp(preamble, Y4M_FRAME_SIGNATURE, Y4M_FRAME_SIGNATURE_SIZE) != + 0) { + this->status = DEMUX_FINISHED; + return this->status; + } } /* load and dispatch the raw frame */ - bytes_remaining = this->frame_size; - current_file_pos = + int bytes_remaining = this->frame_size; + off_t current_file_pos = this->input->get_current_pos(this->input) - this->data_start; - pts = current_file_pos; + int64_t pts = current_file_pos; pts /= (this->frame_size + Y4M_FRAME_SIGNATURE_SIZE); pts *= this->frame_pts_inc; @@ -261,17 +250,14 @@ static int demux_yuv4mpeg2_send_chunk(demux_plugin_t *this_gen) { } while(bytes_remaining) { - buf = this->video_fifo->buffer_pool_alloc (this->video_fifo); + buf_element_t *buf = this->video_fifo->buffer_pool_alloc (this->video_fifo); buf->type = BUF_VIDEO_I420; if( this->data_size ) buf->extra_info->input_normpos = (int)((double) current_file_pos * 65535 / this->data_size); buf->extra_info->input_time = pts / 90; buf->pts = pts; - if (bytes_remaining > buf->max_size) - buf->size = buf->max_size; - else - buf->size = bytes_remaining; + buf->size = MIN(bytes_remaining, buf->max_size); bytes_remaining -= buf->size; if (this->input->read(this->input, buf->content, buf->size) != @@ -291,7 +277,6 @@ static int demux_yuv4mpeg2_send_chunk(demux_plugin_t *this_gen) { static void demux_yuv4mpeg2_send_headers(demux_plugin_t *this_gen) { demux_yuv4mpeg2_t *this = (demux_yuv4mpeg2_t *) this_gen; - buf_element_t *buf; this->video_fifo = this->stream->video_fifo; this->audio_fifo = this->stream->audio_fifo; @@ -310,7 +295,7 @@ static void demux_yuv4mpeg2_send_headers(demux_plugin_t *this_gen) { _x_demux_control_start(this->stream); /* send init info to decoders */ - buf = this->video_fifo->buffer_pool_alloc (this->video_fifo); + buf_element_t *buf = this->video_fifo->buffer_pool_alloc (this->video_fifo); buf->decoder_flags = BUF_FLAG_HEADER|BUF_FLAG_STDHEADER|BUF_FLAG_FRAMERATE| BUF_FLAG_FRAME_END; buf->decoder_info[0] = this->frame_pts_inc; /* initial video step */ @@ -400,10 +385,7 @@ static int demux_yuv4mpeg2_get_optional_data(demux_plugin_t *this_gen, static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *stream, input_plugin_t *input) { - - demux_yuv4mpeg2_t *this; - - this = calloc(1, sizeof(demux_yuv4mpeg2_t)); + demux_yuv4mpeg2_t *this = calloc(1, sizeof(demux_yuv4mpeg2_t)); this->stream = stream; this->input = input; @@ -422,10 +404,8 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *str switch (stream->content_detection_method) { case METHOD_BY_EXTENSION: { - const char *extensions, *mrl; - - mrl = input->get_mrl (input); - extensions = class_gen->get_extensions (class_gen); + const char *const mrl = input->get_mrl (input); + const char *const extensions = class_gen->get_extensions (class_gen); if (!_x_demux_check_extension (mrl, extensions)) { free (this); -- cgit v1.2.3 From 6f5ca26f2fe317b558edb034813010166de89185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Fri, 4 Jul 2008 16:11:59 +0200 Subject: Simplify switch_buf return values. --HG-- extra : transplant_source : v%FE%E4L9%A7x%2B%F41%2B%12P%06%A8%12%DC%ED%3A%84 --- src/demuxers/demux_yuv_frames.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_yuv_frames.c b/src/demuxers/demux_yuv_frames.c index f53ca78ee..c5ca363ed 100644 --- a/src/demuxers/demux_yuv_frames.c +++ b/src/demuxers/demux_yuv_frames.c @@ -70,8 +70,6 @@ static int demux_yuv_frames_get_status (demux_plugin_t *this_gen) { } static int switch_buf(demux_yuv_frames_t *this , buf_element_t *buf){ - int result = 0; - if (!buf) return 0; @@ -88,8 +86,7 @@ static int switch_buf(demux_yuv_frames_t *this , buf_element_t *buf){ case BUF_VIDEO_I420: case BUF_VIDEO_YUY2: this->video_fifo->put(this->video_fifo, buf); - result = 1; /* 1, we still should read audio */ - break; + return 1; /* 1, we still should read audio */ case BUF_AUDIO_LPCM_LE: if (!_x_stream_info_get(this->stream, XINE_STREAM_INFO_HAS_VIDEO)) _x_demux_control_newpts(this->stream, buf->pts, 0); @@ -100,7 +97,7 @@ static int switch_buf(demux_yuv_frames_t *this , buf_element_t *buf){ buf->free_buffer(buf); } - return result; + return 0; } static int demux_yuv_frames_send_chunk (demux_plugin_t *this_gen){ -- cgit v1.2.3 From 3610d5b8dbdee81b15c0b09f5e7b35dbd3a05be2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Fri, 4 Jul 2008 16:21:23 +0200 Subject: Update code style. Mark sizes as constant. Don't call strlen() in loops, move the pointer instead. --HG-- extra : transplant_source : 9%7Bm%83%99%13Q%0EI%7B%F3%DB%7BEb%C6%D1%29dR --- src/libspucmml/xine_cmml_decoder.c | 99 +++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 55 deletions(-) (limited to 'src') diff --git a/src/libspucmml/xine_cmml_decoder.c b/src/libspucmml/xine_cmml_decoder.c index 206d8c567..1a8f65e14 100644 --- a/src/libspucmml/xine_cmml_decoder.c +++ b/src/libspucmml/xine_cmml_decoder.c @@ -88,14 +88,13 @@ static void video_frame_format_change_callback (void *user_data, const xine_even static void update_font_size (spucmml_decoder_t *this) { - static int sizes[SUBTITLE_SIZE_NUM][4] = { + static const int sizes[SUBTITLE_SIZE_NUM][4] = { { 16, 16, 16, 20 }, /* SUBTITLE_SIZE_SMALL */ { 16, 16, 20, 24 }, /* SUBTITLE_SIZE_NORMAL */ { 16, 20, 24, 32 }, /* SUBTITLE_SIZE_LARGE */ }; - int *vec = sizes[this->subtitle_size]; - int y; + const int *const vec = sizes[this->subtitle_size]; if( this->cached_width >= 512 ) this->font_size = vec[3]; @@ -108,7 +107,7 @@ static void update_font_size (spucmml_decoder_t *this) { this->line_height = this->font_size + 10; - y = this->cached_height - (SUB_MAX_TEXT * this->line_height) - 5; + int y = this->cached_height - (SUB_MAX_TEXT * this->line_height) - 5; if(((y - this->vertical_offset) >= 0) && ((y - this->vertical_offset) <= this->cached_height)) y -= this->vertical_offset; @@ -137,83 +136,80 @@ static void update_font_size (spucmml_decoder_t *this) { } static int get_width(spucmml_decoder_t *this, char* text) { - size_t i=0; - int width=0,w,dummy; - char letter[2]={0, 0}; + int width=0; + + while (1) + switch (*text) { + case '\0': + llprintf(LOG_WIDTH, "get_width returning width of %d\n", width); + return width; - while (i<=strlen(text)) { - switch (text[i]) { case '<': - if (!strncmp("", text+i, 3)) { + if (!strncmp("", text, 3)) { /*Do somethink to enable BOLD typeface*/ - i=i+3; + text += 3; break; - } else if (!strncmp("", text+i, 3)) { + } else if (!strncmp("", text, 3)) { /*Do somethink to disable BOLD typeface*/ - i=i+4; + text += 4; break; - } else if (!strncmp("", text+i, 3)) { + } else if (!strncmp("", text, 3)) { /*Do somethink to enable italics typeface*/ - i=i+3; + text += 3; break; - } else if (!strncmp("", text+i, 3)) { + } else if (!strncmp("", text, 3)) { /*Do somethink to disable italics typeface*/ - i=i+4; + text += 4; break; - } else if (!strncmp("", text+i, 3)) { + } else if (!strncmp("", text, 3)) { /*Do somethink to disable typing fixme - no teststreams*/ - i=i+6; + text += 6; break; - } else if (!strncmp("", text+i, 3)) { + } else if (!strncmp("", text, 3)) { /*Do somethink to enable typing fixme - no teststreams*/ - i=i+7; + text += 7; break; } default: - letter[0]=text[i]; - this->stream->osd_renderer->get_text_size(this->osd, letter, &w, &dummy); - width=width+w; - i++; + { + int w, dummy; + const char letter[2] = { *text, '\0' }; + this->stream->osd_renderer->get_text_size(this->osd, letter, &w, &dummy); + width += w; + text++; + } } - } - - llprintf(LOG_WIDTH, "get_width returning width of %d\n", width); - - return width; } static void render_line(spucmml_decoder_t *this, int x, int y, char* text) { - size_t i=0; - int w,dummy; - char letter[2]={0,0}; + while (*text != '\0') { + int w, dummy; + const char letter[2] = { *text, '\0' }; - while (i<=strlen(text)) { - letter[0]=text[i]; this->stream->osd_renderer->render_text(this->osd, x, y, letter, OSD_TEXT1); this->stream->osd_renderer->get_text_size(this->osd, letter, &w, &dummy); - x=x+w; - i++; + x += w; + text++; } } static void draw_subtitle(spucmml_decoder_t *this, int64_t sub_start) { - int line, y; - int font_size; - this->stream->osd_renderer->filled_rect (this->osd, 0, 0, this->cached_width-1, this->line_height * SUB_MAX_TEXT - 1, 0); - y = (SUB_MAX_TEXT - this->lines) * this->line_height; - font_size = this->font_size; + const int y = (SUB_MAX_TEXT - this->lines) * this->line_height; + int font_size = this->font_size; this->stream->osd_renderer->set_encoding(this->osd, this->class->src_encoding); + int line; + for (line=0; linelines; line++) { - int w,x; + int x; while(1) { - w=get_width( this, this->text[line]); + const int w = get_width( this, this->text[line]); x = (this->cached_width - w) / 2; if( w > this->cached_width && font_size > 16 ) { @@ -242,14 +238,13 @@ static void draw_subtitle(spucmml_decoder_t *this, int64_t sub_start) { static void spudec_decode_data (spu_decoder_t *this_gen, buf_element_t *buf) { spucmml_decoder_t *this = (spucmml_decoder_t *) this_gen; - char *str; xml_node_t *packet_xml_root; char * anchor_text = NULL; lprintf("CMML packet seen\n"); - str = (char *) buf->content; + char *str = (char *) buf->content; /* parse the CMML */ @@ -440,11 +435,8 @@ static void update_osd_font(void *this_gen, xine_cfg_entry_t *entry) } static spu_decoder_t *spucmml_class_open_plugin (spu_decoder_class_t *class_gen, xine_stream_t *stream) { - spucmml_class_t *class = (spucmml_class_t *)class_gen; - spucmml_decoder_t *this ; - - this = (spucmml_decoder_t *) calloc(1, sizeof(spucmml_decoder_t)); + spucmml_decoder_t *this = (spucmml_decoder_t *) calloc(1, sizeof(spucmml_decoder_t)); this->spu_decoder.decode_data = spudec_decode_data; this->spu_decoder.reset = spudec_reset; @@ -454,7 +446,7 @@ static spu_decoder_t *spucmml_class_open_plugin (spu_decoder_class_t *class_gen, this->spu_decoder.set_button = NULL; this->spu_decoder.dispose = spudec_dispose; - this->class = class; + this->class = class_gen; this->stream = stream; this->event_queue = xine_event_new_queue (this->stream); @@ -505,10 +497,7 @@ static void update_src_encoding(void *this_gen, xine_cfg_entry_t *entry) } static void *init_spu_decoder_plugin (xine_t *xine, void *data) { - - spucmml_class_t *this ; - - this = (spucmml_class_t *) calloc(1, sizeof(spucmml_class_t)); + spucmml_class_t *this = (spucmml_class_t *) calloc(1, sizeof(spucmml_class_t)); this->class.open_plugin = spucmml_class_open_plugin; this->class.get_identifier = spucmml_class_get_identifier; -- cgit v1.2.3 From 1277177277eb14e7da35331b34af5e4b442a60cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Fri, 4 Jul 2008 16:24:03 +0200 Subject: Update code style. --HG-- extra : transplant_source : %D0%D6%EB%ACQ%28%9B1i%21%A4%8F%BB%A3%CF%5E%BC%CB%5E%A3 --- src/libspudec/xine_spu_decoder.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/libspudec/xine_spu_decoder.c b/src/libspudec/xine_spu_decoder.c index c604686e9..e63bdf8b9 100644 --- a/src/libspudec/xine_spu_decoder.c +++ b/src/libspudec/xine_spu_decoder.c @@ -68,11 +68,9 @@ static const clut_t default_clut[] = { }; static void spudec_decode_data (spu_decoder_t *this_gen, buf_element_t *buf) { - uint32_t stream_id; - spudec_seq_t *cur_seq; spudec_decoder_t *this = (spudec_decoder_t *) this_gen; - stream_id = buf->type & 0x1f ; - cur_seq = &this->spudec_stream_state[stream_id].ra_seq; + const uint8_t stream_id = buf->type & 0x1f ; + spudec_seq_t *cur_seq = &this->spudec_stream_state[stream_id].ra_seq; #ifdef LOG_DEBUG printf("libspudec:got buffer type = %x\n", buf->type); @@ -177,7 +175,6 @@ static void spudec_discontinuity (spu_decoder_t *this_gen) { static void spudec_dispose (spu_decoder_t *this_gen) { spudec_decoder_t *this = (spudec_decoder_t *) this_gen; - int i; video_overlay_manager_t *ovl_manager = this->stream->video_out->get_overlay_manager (this->stream->video_out); if( this->menu_handle >= 0 ) @@ -185,6 +182,7 @@ static void spudec_dispose (spu_decoder_t *this_gen) { this->menu_handle); this->menu_handle = -1; + int i; for (i=0; i < MAX_STREAMS; i++) { if( this->spudec_stream_state[i].overlay_handle >= 0 ) ovl_manager->free_handle(ovl_manager, @@ -225,11 +223,9 @@ static void spudec_set_button (spu_decoder_t *this_gen, int32_t button, int32_t * when video_overlay does menus */ video_overlay_manager_t *ovl_manager; - video_overlay_event_t *overlay_event = NULL; - vo_overlay_t *overlay = NULL; - overlay_event = calloc(1, sizeof(video_overlay_event_t)); + video_overlay_event_t *overlay_event = calloc(1, sizeof(video_overlay_event_t)); + vo_overlay_t *overlay = calloc(1, sizeof(vo_overlay_t)); - overlay = calloc(1, sizeof(vo_overlay_t)); /* FIXME: Watch out for threads. We should really put a lock on this * because events is a different thread than decode_data */ @@ -313,7 +309,6 @@ static void spudec_set_button (spu_decoder_t *this_gen, int32_t button, int32_t static spu_decoder_t *open_plugin (spu_decoder_class_t *class_gen, xine_stream_t *stream) { spudec_decoder_t *this ; - int i; this = (spudec_decoder_t *) calloc(1, sizeof (spudec_decoder_t)); @@ -337,6 +332,8 @@ static spu_decoder_t *open_plugin (spu_decoder_class_t *class_gen, xine_stream_t this->ovl_caps = stream->video_out->get_capabilities(stream->video_out); this->output_open = 0; this->last_event_vpts = 0; + + int i; for (i=0; i < MAX_STREAMS; i++) { this->spudec_stream_state[i].ra_seq.complete = 1; this->spudec_stream_state[i].overlay_handle = -1; -- cgit v1.2.3 From b8ebc2774eb55dd0799fc3496ff0bc01bd516f72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Fri, 4 Jul 2008 16:24:55 +0200 Subject: Simplify code and update code style. With this change a lot of variables now result unused, as before they were only assigned after declaration. --HG-- extra : transplant_source : S%D1%AF%8B%F9%C12%16%B2%F7%F0%A6zpA%5C%C7%12%AE%E8 --- src/libspudvb/xine_spudvb_decoder.c | 494 ++++++++++++++++-------------------- 1 file changed, 219 insertions(+), 275 deletions(-) (limited to 'src') diff --git a/src/libspudvb/xine_spudvb_decoder.c b/src/libspudvb/xine_spudvb_decoder.c index 40d2a205a..957374799 100644 --- a/src/libspudvb/xine_spudvb_decoder.c +++ b/src/libspudvb/xine_spudvb_decoder.c @@ -28,6 +28,7 @@ #include "pthread.h" #include #include "xine_internal.h" +#include "bswap.h" #include "osd.h" #define MAX_REGIONS 7 @@ -144,28 +145,24 @@ static void update_region (dvb_spu_decoder_t * this, int region_id, int region_w /* reject invalid sizes and set some limits ! */ if ( region_width<=0 || region_height<=0 || region_width>720 || region_height>576 ) { - if ( reg->img ) { - free( reg->img ); - reg->img = NULL; - } + free( reg->img ); + reg->img = NULL; #ifdef LOG printf("SPUDVB: rejected region %d = %dx%d\n", region_id, region_width, region_height ); #endif return; } - if ( reg->width*reg->heightwidth*reg->height) < (region_width*region_height) ) { #ifdef LOG printf("SPUDVB: update size of region %d = %dx%d\n", region_id, region_width, region_height); #endif - if ( reg->img ) { - free( reg->img ); - reg->img = NULL; - } + free( reg->img ); + reg->img = NULL; } if ( !reg->img ) { - if ( !(reg->img=xine_xmalloc(region_width*region_height)) ) { + if ( !(reg->img=malloc(region_width*region_height)) ) { lprintf( "can't allocate mem for region %d\n", region_id ); return; } @@ -188,10 +185,9 @@ static void update_region (dvb_spu_decoder_t * this, int region_id, int region_w static void do_plot (dvb_spu_decoder_t * this, int r, int x, int y, unsigned char pixel) { - int i; - dvbsub_func_t *dvbsub = this->dvbsub; + dvbsub_func_t *const dvbsub = this->dvbsub; - i = (y * dvbsub->regions[r].width) + x; + const int i = (y * dvbsub->regions[r].width) + x; /* do some clipping */ if ( i<(dvbsub->regions[r].width*dvbsub->regions[r].height) ) { dvbsub->regions[r].img[i] = pixel; @@ -204,7 +200,7 @@ static void plot (dvb_spu_decoder_t * this, int r, int run_length, unsigned char dvbsub_func_t *dvbsub = this->dvbsub; - int x2 = dvbsub->x + run_length; + const int x2 = dvbsub->x + run_length; while (dvbsub->x < x2) { do_plot (this, r, dvbsub->x, dvbsub->y, pixel); @@ -212,97 +208,90 @@ static void plot (dvb_spu_decoder_t * this, int r, int run_length, unsigned char } } -static unsigned char next_nibble (dvb_spu_decoder_t * this) +static uint8_t next_nibble (dvb_spu_decoder_t * this) { - unsigned char x; dvbsub_func_t *dvbsub = this->dvbsub; - if (dvbsub->nibble_flag == 0) { - x = (dvbsub->buf[dvbsub->i] & 0xf0) >> 4; - dvbsub->nibble_flag = 1; - } - else { - x = (dvbsub->buf[dvbsub->i++] & 0x0f); - dvbsub->nibble_flag = 0; - } - return (x); + dvbsub->nibble_flag = !dvbsub->nibble_flag; + + if (dvbsub->nibble_flag) /* Inverted! */ + return (dvbsub->buf[dvbsub->i] & 0xf0) >> 4; + else + return (dvbsub->buf[dvbsub->i++] & 0x0f); } static void decode_4bit_pixel_code_string (dvb_spu_decoder_t * this, int r, int object_id, int ofs, int n) { - int next_bits, switch_1, switch_2, switch_3, run_length, pixel_code; - - dvbsub_func_t *dvbsub = this->dvbsub; - - int bits; - unsigned int data; - int j; + dvbsub_func_t *const dvbsub = this->dvbsub; if (dvbsub->in_scanline == 0) { dvbsub->in_scanline = 1; } dvbsub->nibble_flag = 0; - j = dvbsub->i + n; + const int j = dvbsub->i + n; while (dvbsub->i < j) { - bits = 0; - pixel_code = 0; - next_bits = next_nibble (this); + int bits = 0; + const uint8_t next_bits = next_nibble (this); if (next_bits != 0) { - pixel_code = next_bits; + const uint8_t pixel_code = next_bits; plot (this, r, 1, pixel_code); bits += 4; } else { bits += 4; - data = next_nibble (this); - switch_1 = (data & 0x08) >> 3; + const uint8_t data = next_nibble (this); + const uint8_t switch_1 = (data & 0x08) >> 3; bits++; if (switch_1 == 0) { - run_length = (data & 0x07); + const uint8_t run_length = (data & 0x07); bits += 3; if (run_length != 0) { - plot (this, r, run_length + 2, pixel_code); + plot (this, r, run_length + 2, 0); } else { break; } } else { - switch_2 = (data & 0x04) >> 2; + const uint8_t switch_2 = (data & 0x04) >> 2; bits++; if (switch_2 == 0) { - run_length = (data & 0x03); + const uint8_t run_length = (data & 0x03); bits += 2; - pixel_code = next_nibble (this); + const uint8_t pixel_code = next_nibble (this); bits += 4; plot (this, r, run_length + 4, pixel_code); } else { - switch_3 = (data & 0x03); + const uint8_t switch_3 = (data & 0x03); bits += 2; switch (switch_3) { case 0: - plot (this, r, 1, pixel_code); + plot (this, r, 1, 0); break; case 1: - plot (this, r, 2, pixel_code); + plot (this, r, 2, 0); break; case 2: - run_length = next_nibble (this); - bits += 4; - pixel_code = next_nibble (this); - bits += 4; - plot (this, r, run_length + 9, pixel_code); + { + const uint8_t run_length = next_nibble (this); + bits += 4; + const uint8_t pixel_code = next_nibble (this); + bits += 4; + plot (this, r, run_length + 9, pixel_code); + } break; case 3: - run_length = next_nibble (this); - run_length = (run_length << 4) | next_nibble (this); - bits += 8; - pixel_code = next_nibble (this); - bits += 4; - plot (this, r, run_length + 25, pixel_code); + { + uint8_t run_length = next_nibble (this); + run_length = (run_length << 4) | next_nibble (this); + bits += 8; + const uint8_t pixel_code = next_nibble (this); + bits += 4; + plot (this, r, run_length + 25, pixel_code); + } } } } @@ -337,41 +326,31 @@ static void set_clut(dvb_spu_decoder_t *this,int CLUT_id,int CLUT_entry_id,int Y } static void process_CLUT_definition_segment(dvb_spu_decoder_t *this) { - int page_id, - segment_length, - CLUT_id, - CLUT_version_number; - - int CLUT_entry_id, - CLUT_flag_8_bit, - CLUT_flag_4_bit, - CLUT_flag_2_bit, - full_range_flag, - Y_value, - Cr_value, - Cb_value, - T_value; dvbsub_func_t *dvbsub = this->dvbsub; - int j; - - page_id=(dvbsub->buf[dvbsub->i]<<8)|dvbsub->buf[dvbsub->i+1]; dvbsub->i+=2; - segment_length=(dvbsub->buf[dvbsub->i]<<8)|dvbsub->buf[dvbsub->i+1]; dvbsub->i+=2; - j=dvbsub->i+segment_length; + const uint16_t page_id= _X_BE_16(&dvbsub->buf[dvbsub->i]); + dvbsub->i+=2; + const uint16_t segment_length= _X_BE_16(&dvbsub->buf[dvbsub->i]); + dvbsub->i+=2; + const int j=dvbsub->i+segment_length; - CLUT_id=dvbsub->buf[dvbsub->i++]; - CLUT_version_number=(dvbsub->buf[dvbsub->i]&0xf0)>>4; + const uint8_t CLUT_id=dvbsub->buf[dvbsub->i++]; + const uint8_t CLUT_version_number=(dvbsub->buf[dvbsub->i]&0xf0)>>4; dvbsub->i++; while (dvbsub->i < j) { - CLUT_entry_id=dvbsub->buf[dvbsub->i++]; + const uint8_t CLUT_entry_id=dvbsub->buf[dvbsub->i++]; - CLUT_flag_2_bit=(dvbsub->buf[dvbsub->i]&0x80)>>7; - CLUT_flag_4_bit=(dvbsub->buf[dvbsub->i]&0x40)>>6; - CLUT_flag_8_bit=(dvbsub->buf[dvbsub->i]&0x20)>>5; - full_range_flag=dvbsub->buf[dvbsub->i]&1; + const uint8_t CLUT_flag_2_bit=(dvbsub->buf[dvbsub->i]&0x80)>>7; + const uint8_t CLUT_flag_4_bit=(dvbsub->buf[dvbsub->i]&0x40)>>6; + const uint8_t CLUT_flag_8_bit=(dvbsub->buf[dvbsub->i]&0x20)>>5; + const uint8_t full_range_flag=dvbsub->buf[dvbsub->i]&1; dvbsub->i++; + int Y_value, + Cr_value, + Cb_value, + T_value; if (full_range_flag==1) { Y_value=dvbsub->buf[dvbsub->i++]; Cr_value=dvbsub->buf[dvbsub->i++]; @@ -390,17 +369,14 @@ static void process_CLUT_definition_segment(dvb_spu_decoder_t *this) { static void process_pixel_data_sub_block (dvb_spu_decoder_t * this, int r, int o, int ofs, int n) { - int data_type; - int j; - dvbsub_func_t *dvbsub = this->dvbsub; - j = dvbsub->i + n; + const int j = dvbsub->i + n; dvbsub->x = (dvbsub->regions[r].object_pos[o]) >> 16; dvbsub->y = ((dvbsub->regions[r].object_pos[o]) & 0xffff) + ofs; while (dvbsub->i < j) { - data_type = dvbsub->buf[dvbsub->i++]; + const uint8_t data_type = dvbsub->buf[dvbsub->i++]; switch (data_type) { case 0: @@ -423,18 +399,14 @@ static void process_pixel_data_sub_block (dvb_spu_decoder_t * this, int r, int o static void process_page_composition_segment (dvb_spu_decoder_t * this) { - int segment_length; - int region_id, region_x, region_y; - int j; - int r; dvbsub_func_t *dvbsub = this->dvbsub; - dvbsub->page.page_id = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + dvbsub->page.page_id = _X_BE_16(&dvbsub->buf[dvbsub->i]); dvbsub->i += 2; - segment_length = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + const uint16_t segment_length = _X_BE_16(&dvbsub->buf[dvbsub->i]); dvbsub->i += 2; - j = dvbsub->i + segment_length; + const int j = dvbsub->i + segment_length; dvbsub->page.page_time_out = dvbsub->buf[dvbsub->i++]; @@ -442,6 +414,7 @@ static void process_page_composition_segment (dvb_spu_decoder_t * this) dvbsub->page.page_state = (dvbsub->buf[dvbsub->i] & 0x0c) >> 2; dvbsub->i++; if (dvbsub->page.page_state==2) { + int r; for (r=0; rpage.regions[r].is_visible = 0; } @@ -450,11 +423,11 @@ static void process_page_composition_segment (dvb_spu_decoder_t * this) } while (dvbsub->i < j) { - region_id = dvbsub->buf[dvbsub->i++]; + const uint8_t region_id = dvbsub->buf[dvbsub->i++]; dvbsub->i++; /* reserved */ - region_x = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + const uint16_t region_x = _X_BE_16(&dvbsub->buf[dvbsub->i]); dvbsub->i += 2; - region_y = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + const uint16_t region_y = _X_BE_16(&dvbsub->buf[dvbsub->i]); dvbsub->i += 2; dvbsub->page.regions[region_id].x = region_x; @@ -465,36 +438,29 @@ static void process_page_composition_segment (dvb_spu_decoder_t * this) static void process_region_composition_segment (dvb_spu_decoder_t * this) { - int segment_length, - region_id, - region_version_number, - region_fill_flag, region_width, region_height, region_level_of_compatibility, region_depth, CLUT_id, region_8_bit_pixel_code, region_4_bit_pixel_code, region_2_bit_pixel_code; - int object_id, object_type, object_provider_flag, object_x, object_y, foreground_pixel_code, background_pixel_code; - int j; - int o; dvbsub_func_t *dvbsub = this->dvbsub; - dvbsub->page.page_id = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + dvbsub->page.page_id = _X_BE_16(&dvbsub->buf[dvbsub->i]); dvbsub->i += 2; - segment_length = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + const uint16_t segment_length = _X_BE_16(&dvbsub->buf[dvbsub->i]); dvbsub->i += 2; - j = dvbsub->i + segment_length; + const int j = dvbsub->i + segment_length; - region_id = dvbsub->buf[dvbsub->i++]; - region_version_number = (dvbsub->buf[dvbsub->i] & 0xf0) >> 4; - region_fill_flag = (dvbsub->buf[dvbsub->i] & 0x08) >> 3; + const uint8_t region_id = dvbsub->buf[dvbsub->i++]; + const uint8_t region_version_number = (dvbsub->buf[dvbsub->i] & 0xf0) >> 4; + const uint8_t region_fill_flag = (dvbsub->buf[dvbsub->i] & 0x08) >> 3; dvbsub->i++; - region_width = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + const uint16_t region_width = _X_BE_16(&dvbsub->buf[dvbsub->i]); dvbsub->i += 2; - region_height = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + const uint16_t region_height = _X_BE_16(&dvbsub->buf[dvbsub->i]); dvbsub->i += 2; - region_level_of_compatibility = (dvbsub->buf[dvbsub->i] & 0xe0) >> 5; - region_depth = (dvbsub->buf[dvbsub->i] & 0x1c) >> 2; + const uint8_t region_level_of_compatibility = (dvbsub->buf[dvbsub->i] & 0xe0) >> 5; + const uint8_t region_depth = (dvbsub->buf[dvbsub->i] & 0x1c) >> 2; dvbsub->i++; - CLUT_id = dvbsub->buf[dvbsub->i++]; - region_8_bit_pixel_code = dvbsub->buf[dvbsub->i++]; - region_4_bit_pixel_code = (dvbsub->buf[dvbsub->i] & 0xf0) >> 4; - region_2_bit_pixel_code = (dvbsub->buf[dvbsub->i] & 0x0c) >> 2; + const uint8_t CLUT_id = dvbsub->buf[dvbsub->i++]; + const uint8_t region_8_bit_pixel_code = dvbsub->buf[dvbsub->i++]; + const uint8_t region_4_bit_pixel_code = (dvbsub->buf[dvbsub->i] & 0xf0) >> 4; + const uint8_t region_2_bit_pixel_code = (dvbsub->buf[dvbsub->i] & 0x0c) >> 2; dvbsub->i++; if(region_id>=MAX_REGIONS) @@ -508,25 +474,28 @@ static void process_region_composition_segment (dvb_spu_decoder_t * this) dvbsub->regions[region_id].objects_start = dvbsub->i; dvbsub->regions[region_id].objects_end = j; - for (o = 0; o < 65536; o++) { - dvbsub->regions[region_id].object_pos[o] = 0xffffffff; + { + int o; + for (o = 0; o < 65536; o++) { + dvbsub->regions[region_id].object_pos[o] = 0xffffffff; + } } while (dvbsub->i < j) { - object_id = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + const uint16_t object_id = _X_BE_16(&dvbsub->buf[dvbsub->i]); dvbsub->i += 2; - object_type = (dvbsub->buf[dvbsub->i] & 0xc0) >> 6; - object_provider_flag = (dvbsub->buf[dvbsub->i] & 0x30) >> 4; - object_x = ((dvbsub->buf[dvbsub->i] & 0x0f) << 8) | dvbsub->buf[dvbsub->i + 1]; + const uint8_t object_type = (dvbsub->buf[dvbsub->i] & 0xc0) >> 6; + const uint8_t object_provider_flag = (dvbsub->buf[dvbsub->i] & 0x30) >> 4; + const uint16_t object_x = ((dvbsub->buf[dvbsub->i] & 0x0f) << 8) | dvbsub->buf[dvbsub->i + 1]; dvbsub->i += 2; - object_y = ((dvbsub->buf[dvbsub->i] & 0x0f) << 8) | dvbsub->buf[dvbsub->i + 1]; + const uint16_t object_y = ((dvbsub->buf[dvbsub->i] & 0x0f) << 8) | dvbsub->buf[dvbsub->i + 1]; dvbsub->i += 2; dvbsub->regions[region_id].object_pos[object_id] = (object_x << 16) | object_y; if ((object_type == 0x01) || (object_type == 0x02)) { - foreground_pixel_code = dvbsub->buf[dvbsub->i++]; - background_pixel_code = dvbsub->buf[dvbsub->i++]; + const uint8_t foreground_pixel_code = dvbsub->buf[dvbsub->i++]; + const uint8_t background_pixel_code = dvbsub->buf[dvbsub->i++]; } } @@ -534,49 +503,45 @@ static void process_region_composition_segment (dvb_spu_decoder_t * this) static void process_object_data_segment (dvb_spu_decoder_t * this) { - int segment_length, object_id, object_version_number, object_coding_method, non_modifying_colour_flag; - - int top_field_data_block_length, bottom_field_data_block_length; - dvbsub_func_t *dvbsub = this->dvbsub; - int j; - int old_i; - int r; - dvbsub->page.page_id = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; dvbsub->i += 2; - segment_length = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + const uint16_t segment_length = _X_BE_16(&dvbsub->buf[dvbsub->i]); dvbsub->i += 2; - j = dvbsub->i + segment_length; + const int j = dvbsub->i + segment_length; - object_id = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; + const uint16_t object_id = _X_BE_16(&dvbsub->buf[dvbsub->i]); dvbsub->i += 2; dvbsub->curr_obj = object_id; - object_version_number = (dvbsub->buf[dvbsub->i] & 0xf0) >> 4; - object_coding_method = (dvbsub->buf[dvbsub->i] & 0x0c) >> 2; - non_modifying_colour_flag = (dvbsub->buf[dvbsub->i] & 0x02) >> 1; + const uint8_t object_version_number = (dvbsub->buf[dvbsub->i] & 0xf0) >> 4; + const uint8_t object_coding_method = (dvbsub->buf[dvbsub->i] & 0x0c) >> 2; + const uint8_t non_modifying_colour_flag = (dvbsub->buf[dvbsub->i] & 0x02) >> 1; dvbsub->i++; - old_i = dvbsub->i; + if ( object_coding_method != 0 ) + return; + + const int old_i = dvbsub->i; + int r; for (r = 0; r < MAX_REGIONS; r++) { /* If this object is in this region... */ - if (dvbsub->regions[r].img) { - if (dvbsub->regions[r].object_pos[object_id] != 0xffffffff) { - dvbsub->i = old_i; - if (object_coding_method == 0) { - top_field_data_block_length = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; - dvbsub->i += 2; - bottom_field_data_block_length = (dvbsub->buf[dvbsub->i] << 8) | dvbsub->buf[dvbsub->i + 1]; - dvbsub->i += 2; - - process_pixel_data_sub_block (this, r, object_id, 0, top_field_data_block_length); - - process_pixel_data_sub_block (this, r, object_id, 1, bottom_field_data_block_length); - } - } - } + if (!dvbsub->regions[r].img) + continue; + + if (dvbsub->regions[r].object_pos[object_id] == 0xffffffff) + continue; + + dvbsub->i = old_i; + + const uint16_t top_field_data_block_length = _X_BE_16(&dvbsub->buf[dvbsub->i]); + dvbsub->i += 2; + const uint16_t bottom_field_data_block_length = _X_BE_16(&dvbsub->buf[dvbsub->i]); + dvbsub->i += 2; + + process_pixel_data_sub_block (this, r, object_id, 0, top_field_data_block_length); + process_pixel_data_sub_block (this, r, object_id, 1, bottom_field_data_block_length); } } @@ -603,38 +568,37 @@ static void* dvbsub_timer_func(void *this_gen) { dvb_spu_decoder_t *this = (dvb_spu_decoder_t *) this_gen; pthread_mutex_lock(&this->dvbsub_osd_mutex); - int i; /* If we're cancelled via pthread_cancel, unlock the mutex */ pthread_cleanup_push(unlock_mutex_cancellation_func, &this->dvbsub_osd_mutex); - while(1) - { + while(1) { /* Record the current timeout, and wait - note that pthread_cond_timedwait will unlock the mutex on entry, and lock it on exit */ struct timespec timeout = this->dvbsub_hide_timeout; - int result = pthread_cond_timedwait(&this->dvbsub_restart_timeout, - &this->dvbsub_osd_mutex, - &this->dvbsub_hide_timeout); - if(result == ETIMEDOUT && - timeout.tv_sec == this->dvbsub_hide_timeout.tv_sec && - timeout.tv_nsec == this->dvbsub_hide_timeout.tv_nsec) - { - /* We timed out, and no-one changed the timeout underneath us. - Hide the OSD, then wait until we're signalled. */ - if(this && this->stream && this->stream->osd_renderer) - { - for ( i=0; idvbsub->regions[i].osd ) { - this->stream->osd_renderer->hide( this->dvbsub->regions[i].osd, 0 ); + const int result = pthread_cond_timedwait(&this->dvbsub_restart_timeout, + &this->dvbsub_osd_mutex, + &this->dvbsub_hide_timeout); + if(result != ETIMEDOUT || + timeout.tv_sec != this->dvbsub_hide_timeout.tv_sec || + timeout.tv_nsec != this->dvbsub_hide_timeout.tv_nsec) + continue; + + /* We timed out, and no-one changed the timeout underneath us. + Hide the OSD, then wait until we're signalled. */ + if(this && this->stream && this->stream->osd_renderer) { + int i; + for ( i=0; idvbsub->regions[i].osd ) + continue; + + this->stream->osd_renderer->hide( this->dvbsub->regions[i].osd, 0 ); #ifdef LOG - printf("SPUDVB: thread hiding = %d\n",i); + printf("SPUDVB: thread hiding = %d\n",i); #endif - } - } } - pthread_cond_wait(&this->dvbsub_restart_timeout, &this->dvbsub_osd_mutex); } + pthread_cond_wait(&this->dvbsub_restart_timeout, &this->dvbsub_osd_mutex); } pthread_cleanup_pop(1); @@ -654,26 +618,29 @@ static void downscale_region_image( region_t *reg, unsigned char *dest, int dest static void draw_subtitles (dvb_spu_decoder_t * this) { - int r; - int display=0; int64_t dum; - int dest_width=0, dest_height, reg_width; + int dest_width=0, dest_height; this->stream->video_out->status(this->stream->video_out, NULL, &dest_width, &dest_height, &dum); - unsigned char tmp[dest_width*576]; - unsigned char *reg; if ( !dest_width ) return; /* render all regions onto the page */ - for ( r=0; rdvbsub->page.regions[r].is_visible ) - display++; + { + int r; + int display = 0; + for ( r=0; rdvbsub->page.regions[r].is_visible ) { + display = 1; + break; + } + } + if ( !display ) + return; } - if ( !display ) - return; + int r; for (r = 0; r < MAX_REGIONS; r++) { if (this->dvbsub->regions[r].img) { if (this->dvbsub->page.regions[r].is_visible && !this->dvbsub->regions[r].empty) { @@ -682,6 +649,10 @@ static void draw_subtitles (dvb_spu_decoder_t * this) continue; /* clear osd */ this->stream->osd_renderer->clear( this->dvbsub->regions[r].osd ); + + uint8_t *reg; + int reg_width; + uint8_t tmp[dest_width*576]; if (this->dvbsub->regions[r].width>dest_width) { downscale_region_image(&this->dvbsub->regions[r], tmp, dest_width); reg = tmp; @@ -731,12 +702,6 @@ static void draw_subtitles (dvb_spu_decoder_t * this) static void spudec_decode_data (spu_decoder_t * this_gen, buf_element_t * buf) { dvb_spu_decoder_t *this = (dvb_spu_decoder_t *) this_gen; - int new_i; - int data_identifier, subtitle_stream_id; - int segment_length, segment_type; - int PES_header_data_length; - int PES_packet_length; - int i; if((buf->type & 0xffff0000)!=BUF_SPU_DVB) return; @@ -746,6 +711,7 @@ static void spudec_decode_data (spu_decoder_t * this_gen, buf_element_t * buf) if (buf->decoder_info[2] == 0) { /* Hide the osd - note that if the timeout thread times out, it'll rehide, which is harmless */ pthread_mutex_lock(&this->dvbsub_osd_mutex); + int i; for ( i=0; idvbsub->regions[i].osd ) this->stream->osd_renderer->hide( this->dvbsub->regions[i].osd, 0 ); @@ -779,12 +745,12 @@ static void spudec_decode_data (spu_decoder_t * this_gen, buf_element_t * buf) * because buf->pts could be too far in future and metronom won't accept * further backwards pts (see metronom_got_spu_packet) */ if (buf->pts) { - metronom_t *metronom = this->stream->metronom; - int64_t vpts_offset = metronom->get_option( metronom, METRONOM_VPTS_OFFSET ); - int64_t spu_offset = metronom->get_option( metronom, METRONOM_SPU_OFFSET ); - int64_t vpts = (int64_t)(buf->pts)+vpts_offset+spu_offset; - metronom_clock_t *clock = this->stream->xine->clock; - int64_t curvpts = clock->get_current_time( clock ); + metronom_t *const metronom = this->stream->metronom; + const int64_t vpts_offset = metronom->get_option( metronom, METRONOM_VPTS_OFFSET ); + const int64_t spu_offset = metronom->get_option( metronom, METRONOM_SPU_OFFSET ); + const int64_t vpts = (int64_t)(buf->pts)+vpts_offset+spu_offset; + metronom_clock_t *const clock = this->stream->xine->clock; + const int64_t curvpts = clock->get_current_time( clock ); /* if buf->pts is unreliable, show page asap (better than nothing) */ #ifdef LOG printf("SPUDVB: spu_vpts=%lld - current_vpts=%lld\n", vpts, curvpts); @@ -797,56 +763,55 @@ static void spudec_decode_data (spu_decoder_t * this_gen, buf_element_t * buf) /* process the pes section */ - PES_packet_length = this->pes_pkt_size; + const int PES_packet_length = this->pes_pkt_size; - this->dvbsub->buf = this->pes_pkt; + this->dvbsub->buf = this->pes_pkt; - PES_header_data_length = 0; - this->dvbsub->i = 0; + int PES_header_data_length = 0; + this->dvbsub->i = 0; - data_identifier = this->dvbsub->buf[this->dvbsub->i++]; - subtitle_stream_id = this->dvbsub->buf[this->dvbsub->i++]; + const uint8_t data_identifier = this->dvbsub->buf[this->dvbsub->i++]; + const uint8_t subtitle_stream_id = this->dvbsub->buf[this->dvbsub->i++]; - while (this->dvbsub->i <= (PES_packet_length)) { - /* SUBTITLING SEGMENT */ - this->dvbsub->i++; - segment_type = this->dvbsub->buf[this->dvbsub->i++]; + while (this->dvbsub->i <= (PES_packet_length)) { + /* SUBTITLING SEGMENT */ + this->dvbsub->i++; + const uint8_t segment_type = this->dvbsub->buf[this->dvbsub->i++]; - this->dvbsub->page.page_id = (this->dvbsub->buf[this->dvbsub->i] << 8) | this->dvbsub->buf[this->dvbsub->i + 1]; - segment_length = (this->dvbsub->buf[this->dvbsub->i + 2] << 8) | this->dvbsub->buf[this->dvbsub->i + 3]; - new_i = this->dvbsub->i + segment_length + 4; + this->dvbsub->page.page_id = (this->dvbsub->buf[this->dvbsub->i] << 8) | this->dvbsub->buf[this->dvbsub->i + 1]; + const uint16_t segment_length = _X_BE_16(&this->dvbsub->buf[this->dvbsub->i + 2]); + const int new_i = this->dvbsub->i + segment_length + 4; - /* only process complete segments */ - if(new_i > (this->pes_pkt_wrptr - this->pes_pkt)) - break; - /* verify we've the right segment */ - if(this->dvbsub->page.page_id==this->spu_descriptor->comp_page_id){ - /* SEGMENT_DATA_FIELD */ - switch (segment_type & 0xff) { - case 0x10: - process_page_composition_segment (this); - break; - case 0x11: - process_region_composition_segment (this); - break; - case 0x12: - process_CLUT_definition_segment(this); - break; - case 0x13: - process_object_data_segment (this); - break; - case 0x80: /* Page is now completely rendered */ - draw_subtitles( this ); - break; - default: - return; - break; - } - } - this->dvbsub->i = new_i; - } + /* only process complete segments */ + if(new_i > (this->pes_pkt_wrptr - this->pes_pkt)) + break; - return; + /* verify we've the right segment */ + if(this->dvbsub->page.page_id==this->spu_descriptor->comp_page_id){ + /* SEGMENT_DATA_FIELD */ + switch (segment_type) { + case 0x10: + process_page_composition_segment (this); + break; + case 0x11: + process_region_composition_segment (this); + break; + case 0x12: + process_CLUT_definition_segment(this); + break; + case 0x13: + process_object_data_segment (this); + break; + case 0x80: /* Page is now completely rendered */ + draw_subtitles( this ); + break; + default: + return; + break; + } + } + this->dvbsub->i = new_i; + } } static void spudec_reset (spu_decoder_t * this_gen) @@ -872,42 +837,30 @@ static void spudec_discontinuity (spu_decoder_t * this_gen) static void spudec_dispose (spu_decoder_t * this_gen) { dvb_spu_decoder_t *this = (dvb_spu_decoder_t *) this_gen; - int i; pthread_cancel(this->dvbsub_timer_thread); pthread_join(this->dvbsub_timer_thread, NULL); pthread_mutex_destroy(&this->dvbsub_osd_mutex); pthread_cond_destroy(&this->dvbsub_restart_timeout); - if(this->spu_descriptor){ - free(this->spu_descriptor); - this->spu_descriptor=NULL; - } + free(this->spu_descriptor); + this->spu_descriptor=NULL; + int i; for ( i=0; idvbsub->regions[i].img ) - free( this->dvbsub->regions[i].img ); + free( this->dvbsub->regions[i].img ); if ( this->dvbsub->regions[i].osd ) this->stream->osd_renderer->free_object( this->dvbsub->regions[i].osd ); } - if (this->pes_pkt) - free (this->pes_pkt); - - if (this->dvbsub) - free (this->dvbsub); - + free (this->pes_pkt); + free (this->dvbsub); free (this); } static spu_decoder_t *dvb_spu_class_open_plugin (spu_decoder_class_t * class_gen, xine_stream_t * stream) { - - int i; - dvb_spu_decoder_t *this; - dvb_spu_class_t *class = (dvb_spu_class_t *) class_gen; - - this = calloc(1, sizeof (dvb_spu_decoder_t)); + dvb_spu_decoder_t *this = calloc(1, sizeof (dvb_spu_decoder_t)); this->spu_decoder.decode_data = spudec_decode_data; this->spu_decoder.reset = spudec_reset; @@ -916,7 +869,7 @@ static spu_decoder_t *dvb_spu_class_open_plugin (spu_decoder_class_t * class_gen this->spu_decoder.get_interact_info = NULL; this->spu_decoder.set_button = NULL; - this->class = class; + this->class = class_gen; this->stream = stream; this->pes_pkt = calloc(65, 1024); @@ -924,13 +877,6 @@ static spu_decoder_t *dvb_spu_class_open_plugin (spu_decoder_class_t * class_gen this->dvbsub = calloc(1, sizeof (dvbsub_func_t)); - for (i = 0; i < MAX_REGIONS; i++) { - this->dvbsub->page.regions[i].is_visible = 0; - this->dvbsub->regions[i].img = NULL; - this->dvbsub->regions[i].osd = NULL; - this->dvbsub->regions[i].CLUT_id = 0; - } - pthread_mutex_init(&this->dvbsub_osd_mutex, NULL); pthread_cond_init(&this->dvbsub_restart_timeout, NULL); this->dvbsub_hide_timeout.tv_nsec = 0; @@ -957,9 +903,7 @@ static char *dvb_spu_class_get_description (spu_decoder_class_t * this) static void *init_spu_decoder_plugin (xine_t * xine, void *data) { - - dvb_spu_class_t *this; - this = calloc(1, sizeof (dvb_spu_class_t)); + dvb_spu_class_t *this = calloc(1, sizeof (dvb_spu_class_t)); this->class.open_plugin = dvb_spu_class_open_plugin; this->class.get_identifier = dvb_spu_class_get_identifier; -- cgit v1.2.3 From 9c5977f1fb284f47eb12c8b8da87f291fd0f5a8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Fri, 4 Jul 2008 16:26:37 +0200 Subject: Simplify code and update code style. --HG-- extra : transplant_source : i%86L%8F_h%1D%DDv%DF%E4%2B%906%8B%FBM%87h%2A --- src/libsputext/demux_sputext.c | 818 +++++++++++++++++----------------- src/libsputext/xine_sputext_decoder.c | 83 ++-- 2 files changed, 452 insertions(+), 449 deletions(-) (limited to 'src') diff --git a/src/libsputext/demux_sputext.c b/src/libsputext/demux_sputext.c index 741d0612b..3e9efb079 100644 --- a/src/libsputext/demux_sputext.c +++ b/src/libsputext/demux_sputext.c @@ -146,8 +146,6 @@ static inline void trail_space(char *s) { */ static char *read_line_from_input(demux_sputext_t *this, char *line, off_t len) { off_t nread = 0; - char *s; - int linelen; if ((len - this->buflen) > 512) { if((nread = this->input->read(this->input, @@ -160,11 +158,11 @@ static char *read_line_from_input(demux_sputext_t *this, char *line, off_t len) this->buflen += nread; this->buf[this->buflen] = '\0'; - s = strchr(this->buf, '\n'); + char *s = strchr(this->buf, '\n'); if (line && (s || this->buflen)) { - linelen = s ? (s - this->buf) + 1 : this->buflen; + size_t linelen = s ? (s - this->buf) + 1 : this->buflen; memcpy(line, this->buf, linelen); line[linelen] = '\0'; @@ -183,13 +181,12 @@ static subtitle_t *sub_read_line_sami(demux_sputext_t *this, subtitle_t *current static char line[LINE_LEN + 1]; static char *s = NULL; - char text[LINE_LEN + 1], *p, *q; - int state; + char text[LINE_LEN + 1]; - p = NULL; + char *p = NULL; current->lines = current->start = 0; current->end = -1; - state = 0; + int state = 0; /* read the first line */ if (!s) @@ -229,14 +226,16 @@ static subtitle_t *sub_read_line_sami(demux_sputext_t *this, subtitle_t *current continue; case 4: /* get current->end or skip */ - q = strstr (s, "Start="); - if (q) { - current->end = strtol (q + 6, &q, 0) / 10 - 1; - *p = '\0'; trail_space (text); - if (text[0] != '\0') - current->text[current->lines++] = strdup (text); - if (current->lines > 0) { state = 99; break; } - state = 0; continue; + { + char *q = strstr (s, "Start="); + if (q) { + current->end = strtol (q + 6, &q, 0) / 10 - 1; + *p = '\0'; trail_space (text); + if (text[0] != '\0') + current->text[current->lines++] = strdup (text); + if (current->lines > 0) { state = 99; break; } + state = 0; continue; + } } s = strchr (s, '>'); if (s) { s++; state = 3; continue; } @@ -254,7 +253,7 @@ static subtitle_t *sub_read_line_sami(demux_sputext_t *this, subtitle_t *current static char *sub_readtext(char *source, char **dest) { - int len=0; + size_t len=0; char *p=source; while ( !eol(*p) && *p!= '|' ) { @@ -274,8 +273,6 @@ static subtitle_t *sub_read_line_microdvd(demux_sputext_t *this, subtitle_t *cur char line[LINE_LEN + 1]; char line2[LINE_LEN + 1]; - char *p, *next; - int i; memset (current, 0, sizeof(subtitle_t)); @@ -286,9 +283,10 @@ static subtitle_t *sub_read_line_microdvd(demux_sputext_t *this, subtitle_t *cur (sscanf (line, "{%ld}{%ld}%" LINE_LEN_QUOT "[^\r\n]", &(current->start), &(current->end),line2) !=3) ); - p=line2; + char *p=line2; - next=p, i=0; + char *next=p; + size_t i=0; while ((next =sub_readtext (next, &(current->text[i])))) { if (current->text[i]==ERR) return ERR; i++; @@ -304,28 +302,30 @@ static subtitle_t *sub_read_line_microdvd(demux_sputext_t *this, subtitle_t *cur } static subtitle_t *sub_read_line_subviewer(demux_sputext_t *this, subtitle_t *current) { - char line[LINE_LEN + 1]; - int a1,a2,a3,a4,b1,b2,b3,b4; - char *p=NULL, *q=NULL; - int len; memset (current, 0, sizeof(subtitle_t)); while (1) { if (!read_line_from_input(this, line, LINE_LEN)) return NULL; - if (sscanf (line, "%d:%d:%d.%d,%d:%d:%d.%d",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4) < 8) { - if (sscanf (line, "%d:%d:%d,%d,%d:%d:%d,%d",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4) < 8) - continue; + + { + int a1,a2,a3,a4,b1,b2,b3,b4; + if (sscanf (line, "%d:%d:%d.%d,%d:%d:%d.%d",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4) < 8) { + if (sscanf (line, "%d:%d:%d,%d,%d:%d:%d,%d",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4) < 8) + continue; + } + + current->start = a1*360000+a2*6000+a3*100+a4; + current->end = b1*360000+b2*6000+b3*100+b4; } - current->start = a1*360000+a2*6000+a3*100+a4; - current->end = b1*360000+b2*6000+b3*100+b4; - + if (!read_line_from_input(this, line, LINE_LEN)) return NULL; - p=q=line; + char *p = line, *q = line; for (current->lines=1; current->lines <= SUB_MAX_TEXT; current->lines++) { + size_t len; for (q=p,len=0; *p && *p!='\r' && *p!='\n' && *p!='|' && strncasecmp(p,"[br]",4); p++,len++); current->text[current->lines-1] = strndup(q, len); if (!current->text[current->lines-1]) return ERR; @@ -340,25 +340,27 @@ static subtitle_t *sub_read_line_subviewer(demux_sputext_t *this, subtitle_t *cu } static subtitle_t *sub_read_line_subrip(demux_sputext_t *this,subtitle_t *current) { - char line[LINE_LEN + 1]; - int a1,a2,a3,a4,b1,b2,b3,b4; - int i,end_sub; - memset(current,0,sizeof(subtitle_t)); - do { - if(!read_line_from_input(this,line,LINE_LEN)) - return NULL; - i = sscanf(line,"%d:%d:%d%*[,.]%d --> %d:%d:%d%*[,.]%d",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4); - } while(i < 8); - current->start = a1*360000+a2*6000+a3*100+a4/10; - current->end = b1*360000+b2*6000+b3*100+b4/10; - i=0; - end_sub=0; + + { + int a1,a2,a3,a4,b1,b2,b3,b4,i; + do { + char line[LINE_LEN + 1]; + if(!read_line_from_input(this,line,LINE_LEN)) + return NULL; + i = sscanf(line,"%d:%d:%d%*[,.]%d --> %d:%d:%d%*[,.]%d",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4); + } while(i < 8); + current->start = a1*360000+a2*6000+a3*100+a4/10; + current->end = b1*360000+b2*6000+b3*100+b4/10; + } + + int i=0; + int end_sub=0; do { char *p; /* pointer to the curently read char */ - char temp_line[SUB_BUFSIZE]; /* subtitle line that will be transfered to current->text[i] */ - int temp_index; /* ... and its index wich 'points' to the first EMPTY place -> last read char is at temp_index-1 if temp_index>0 */ - temp_line[SUB_BUFSIZE-1]='\0'; /* just in case... */ + char line[LINE_LEN + 1]; + char temp_line[SUB_BUFSIZE] = { 0, }; /* subtitle line that will be transfered to current->text[i] */ + size_t temp_index; /* ... and its index wich 'points' to the first EMPTY place -> last read char is at temp_index-1 if temp_index>0 */ if(!read_line_from_input(this,line,LINE_LEN)) { if(i) break; /* if something was read, transmit it */ @@ -408,9 +410,6 @@ static subtitle_t *sub_read_line_subrip(demux_sputext_t *this,subtitle_t *curren static subtitle_t *sub_read_line_vplayer(demux_sputext_t *this,subtitle_t *current) { char line[LINE_LEN + 1]; - int a1,a2,a3,b1,b2,b3; - char *p=NULL, *next, *p2; - int i; memset (current, 0, sizeof(subtitle_t)); @@ -428,24 +427,32 @@ static subtitle_t *sub_read_line_vplayer(demux_sputext_t *this,subtitle_t *curre this->next_line[0] = '\0'; return NULL; } - if( (sscanf( line, "%d:%d:%d:", &a1, &a2, &a3) < 3) || - (sscanf( this->next_line, "%d:%d:%d:", &b1, &b2, &b3) < 3) ) - continue; - current->start = a1*360000+a2*6000+a3*100; - current->end = b1*360000+b2*6000+b3*100; + + { + int a1,a2,a3,b1,b2,b3; + if( (sscanf( line, "%d:%d:%d:", &a1, &a2, &a3) < 3) || + (sscanf( this->next_line, "%d:%d:%d:", &b1, &b2, &b3) < 3) ) + continue; + current->start = a1*360000+a2*6000+a3*100; + current->end = b1*360000+b2*6000+b3*100; + } + if ((current->end - current->start) > LINE_LEN) current->end = current->start + LINE_LEN; /* not too long though. */ /* teraz czas na wkopiowanie stringu */ - p=line; + char *p=line; /* finds the body of the subtitle_t */ - for (i=0; i<3; i++){ - p2=strchr( p, ':'); - if( p2 == NULL ) break; - p=p2+1; - } + { + int i; + for (i=0; i<3; i++){ + char *p2=strchr( p, ':'); + if( p2 == NULL ) break; + p=p2+1; + } + } - next=p; - i=0; + char *next=p; + int i=0; while( (next = sub_readtext( next, &(current->text[i]))) ) { if (current->text[i]==ERR) return ERR; @@ -467,35 +474,40 @@ static subtitle_t *sub_read_line_rt(demux_sputext_t *this,subtitle_t *current) { * I couldn't check it since DTD is not included. * WARNING: full XML parses can be required for proper parsing */ - char line[LINE_LEN + 1]; - int a1,a2,a3,a4,b1,b2,b3,b4; - char *p=NULL,*next=NULL; - int i,len,plen; - memset (current, 0, sizeof(subtitle_t)); while (!current->text[0]) { + char line[LINE_LEN + 1]; if (!read_line_from_input(this, line, LINE_LEN)) return NULL; + + char *p = line; /* * TODO: it seems that format of time is not easily determined, it may be 1:12, 1:12.0 or 0:1:12.0 * to describe the same moment in time. Maybe there are even more formats in use. */ - if ((len=sscanf (line, "