summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDiego 'Flameeyes' Pettenò <flameeyes@gmail.com>2008-07-04 15:54:44 +0200
committerDiego 'Flameeyes' Pettenò <flameeyes@gmail.com>2008-07-04 15:54:44 +0200
commit74a89aa56a2339eff12aef13330c9a43850de5d1 (patch)
tree2bae2bce424c0ebdfcb6e1f1b32b90a3fce51c75 /src
parentee4a1c92793179af16cd4a9b6c2a75e00ab45beb (diff)
downloadxine-lib-74a89aa56a2339eff12aef13330c9a43850de5d1.tar.gz
xine-lib-74a89aa56a2339eff12aef13330c9a43850de5d1.tar.bz2
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
Diffstat (limited to 'src')
-rw-r--r--src/demuxers/demux_nsf.c6
-rw-r--r--src/demuxers/demux_nsv.c17
-rw-r--r--src/demuxers/demux_rawdv.c3
-rw-r--r--src/demuxers/demux_roq.c6
-rw-r--r--src/demuxers/demux_smjpeg.c20
-rw-r--r--src/demuxers/demux_str.c30
-rw-r--r--src/demuxers/demux_voc.c4
7 files changed, 34 insertions, 52 deletions
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(&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_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)