summaryrefslogtreecommitdiff
path: root/src/demuxers
diff options
context:
space:
mode:
Diffstat (limited to 'src/demuxers')
-rw-r--r--src/demuxers/demux_4xm.c49
-rw-r--r--src/demuxers/demux_aac.c7
-rw-r--r--src/demuxers/demux_aiff.c4
-rw-r--r--src/demuxers/demux_aud.c2
-rw-r--r--src/demuxers/demux_eawve.c30
-rw-r--r--src/demuxers/demux_film.c4
-rw-r--r--src/demuxers/demux_mpc.c15
-rw-r--r--src/demuxers/demux_nsf.c6
-rw-r--r--src/demuxers/demux_nsv.c17
-rw-r--r--src/demuxers/demux_ogg.c34
-rw-r--r--src/demuxers/demux_rawdv.c3
-rw-r--r--src/demuxers/demux_real.c20
-rw-r--r--src/demuxers/demux_roq.c6
-rw-r--r--src/demuxers/demux_smjpeg.c20
-rw-r--r--src/demuxers/demux_snd.c4
-rw-r--r--src/demuxers/demux_str.c30
-rw-r--r--src/demuxers/demux_tta.c2
-rw-r--r--src/demuxers/demux_voc.c4
-rw-r--r--src/demuxers/demux_vqa.c4
-rw-r--r--src/demuxers/demux_wc3movie.c10
-rw-r--r--src/demuxers/demux_yuv4mpeg2.c72
-rw-r--r--src/demuxers/demux_yuv_frames.c7
22 files changed, 131 insertions, 219 deletions
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);
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");
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_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;i<size;i++) {
+ uint8_t byte;
if (input->read(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;
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_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;
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_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: {
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_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_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_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_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(&sector[0x18]) != STR_MAGIC ||
+ if (!_x_is_fourcc(&sector[0x18], STR_MAGIC) ||
channel != this->default_video_channel) {
return 0;
}
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_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)
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);
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);
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){