From 54af64d5c7612dee367fd9ddfec3d5db62ff14f3 Mon Sep 17 00:00:00 2001 From: Stas Sergeev Date: Mon, 28 May 2007 23:10:20 +0400 Subject: Add an x86_64-specific version of rdtsc(). --- src/xine-utils/monitor.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/xine-utils/monitor.c b/src/xine-utils/monitor.c index 1a348087c..fa3bcc779 100644 --- a/src/xine-utils/monitor.c +++ b/src/xine-utils/monitor.c @@ -64,13 +64,20 @@ int xine_profiler_allocate_slot (const char *label) { } -#if defined(ARCH_X86) || defined(ARCH_X86_64) +#if defined(ARCH_X86_32) __inline__ unsigned long long int rdtsc(void) { unsigned long long int x; __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); return x; } +#elif defined(ARCH_X86_64) +__inline__ unsigned long long int rdtsc(void) +{ + unsigned long long int a, d; + __asm__ volatile (".byte 0x0f, 0x31" : "=a" (a), "=d" (d)); + return (d << 32) | (a & 0xffffffff); +} #endif void xine_profiler_start_count (int id) { -- cgit v1.2.3 From 27dd2b43eaf2f6748f3f7b42d395d9e6ad628142 Mon Sep 17 00:00:00 2001 From: Stas Sergeev Date: Mon, 28 May 2007 23:24:23 +0400 Subject: Replaced the hardcoded opcodes with "rdtsc" notation, make the rdtsc() function static. --- src/xine-utils/monitor.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/xine-utils/monitor.c b/src/xine-utils/monitor.c index fa3bcc779..c0cfd6179 100644 --- a/src/xine-utils/monitor.c +++ b/src/xine-utils/monitor.c @@ -65,17 +65,17 @@ int xine_profiler_allocate_slot (const char *label) { #if defined(ARCH_X86_32) -__inline__ unsigned long long int rdtsc(void) +static __inline__ unsigned long long int rdtsc(void) { unsigned long long int x; - __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); + __asm__ volatile ("rdtsc\n\t" : "=A" (x)); return x; } #elif defined(ARCH_X86_64) -__inline__ unsigned long long int rdtsc(void) +static __inline__ unsigned long long int rdtsc(void) { unsigned long long int a, d; - __asm__ volatile (".byte 0x0f, 0x31" : "=a" (a), "=d" (d)); + __asm__ volatile ("rdtsc\n\t" : "=a" (a), "=d" (d)); return (d << 32) | (a & 0xffffffff); } #endif -- cgit v1.2.3 From ea7a46ad29a0fccea3062948152cb0ac79dd8f86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 29 May 2007 18:44:21 +0200 Subject: Correctly parse ID3 tags, and avoid skipping over them manually. This reduces again the amount of troublesome FLAC files. --- src/demuxers/demux_flac.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_flac.c b/src/demuxers/demux_flac.c index f52da4d03..3c343bdf2 100644 --- a/src/demuxers/demux_flac.c +++ b/src/demuxers/demux_flac.c @@ -90,37 +90,24 @@ static int open_flac_file(demux_flac_t *flac) { flac->seekpoints = NULL; - /* fetch the file signature, get enough bytes so that id3 can also - be skipped and/or parsed */ - if (_x_demux_read_header(flac->input, preamble, 10) != 10) + /* fetch the file signature, 4 bytes will read both the fLaC + * signature and the */ + if (_x_demux_read_header(flac->input, preamble, 4) != 4) return 0; + flac->input->seek(flac->input, 4, SEEK_SET); + /* Unfortunately some FLAC files have an ID3 flag prefixed on them * before the actual FLAC headers... these are barely legal, but * users use them and want them working, so check and skip the ID3 * tag if present. */ if ( id3v2_istag(preamble) ) { - uint32_t id3size; - - /* First 3 bytes are the ID3 signature as above, then comes two bytes - * encoding the major and minor version of ID3 used, that we can ignore - * as long as we don't try to read the metadata; after those there's a - * single byte with flags that depends on the ID3 version used; and now - * after all that stuff, there's the size of the rest of the tag, which - * is encoded as four bytes.. but only 7 out of 8 bits of every byte is - * used... don't ask. - */ - id3size = id3v2_tagsize(&preamble[6]); - id3v2_parse_tag(flac->input, flac->stream, preamble); - flac->input->seek(flac->input, id3size, SEEK_SET); - if ( flac->input->read(flac->input, preamble, 4) != 4 ) return 0; - } else - flac->input->seek(flac->input, 4, SEEK_SET); + } /* validate signature */ if ((preamble[0] != 'f') || (preamble[1] != 'L') || -- cgit v1.2.3 From ff9e139950744f8d5b2fab434079e6d20ea6b678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 29 May 2007 18:45:24 +0200 Subject: Add a comment about id3v2_istag function and remove id3v2_tagsize function (was used by demux_flac only). --- src/demuxers/id3.h | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/demuxers/id3.h b/src/demuxers/id3.h index 9d08f6817..9b86ec94e 100644 --- a/src/demuxers/id3.h +++ b/src/demuxers/id3.h @@ -170,6 +170,10 @@ int id3v2_parse_tag(input_plugin_t *input, xine_stream_t *stream, int8_t *mp3_frame_header); +/** + * @brief Checks if the given buffer is an ID3 tag preamble + * @param ptr Pointer to the first 10 bytes of the ID3 tag + */ static inline int id3v2_istag(uint8_t *ptr) { return (ptr[0] == 'I') && @@ -177,12 +181,4 @@ static inline int id3v2_istag(uint8_t *ptr) { (ptr[2] == '3'); } -static inline uint32_t id3v2_tagsize(uint8_t *ptr) { - return - ((uint32_t)ptr[0] << 21) + - ((uint32_t)ptr[1] << 14) + - ((uint32_t)ptr[2] << 7) + - (uint32_t)ptr[3]; -} - #endif /* ID3_H */ -- cgit v1.2.3 From a24f42fed5ffe89e6af38b6139ed93e46ea15411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 29 May 2007 18:45:59 +0200 Subject: Print the invalid header flags when found. --- src/demuxers/id3.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/demuxers/id3.c b/src/demuxers/id3.c index b707166b6..e5d767b1e 100644 --- a/src/demuxers/id3.c +++ b/src/demuxers/id3.c @@ -379,7 +379,7 @@ int id3v22_parse_tag(input_plugin_t *input, if (tag_header.flags & ID3V22_ZERO_FLAG) { /* invalid flags */ xprintf(stream->xine, XINE_VERBOSITY_DEBUG, - "id3: invalid header flags\n"); + "id3: invalid header flags (%02x)\n", tag_header.flags); input->seek (input, tag_header.size - pos, SEEK_CUR); return 0; } @@ -573,7 +573,7 @@ int id3v23_parse_tag(input_plugin_t *input, if (tag_header.flags & ID3V23_ZERO_FLAG) { /* invalid flags */ xprintf(stream->xine, XINE_VERBOSITY_DEBUG, - "id3: invalid header flags\n"); + "id3: invalid header flags (%02x)\n", tag_header.flags); input->seek (input, tag_header.size - pos, SEEK_CUR); return 0; } @@ -824,7 +824,7 @@ int id3v24_parse_tag(input_plugin_t *input, if (tag_header.flags & ID3V24_ZERO_FLAG) { /* invalid flags */ xprintf(stream->xine, XINE_VERBOSITY_DEBUG, - "id3: invalid header flags\n"); + "id3: invalid header flags (%02x)\n", tag_header.flags); input->seek (input, tag_header.size - pos, SEEK_CUR); return 0; } -- cgit v1.2.3 From 2861970659c962900b7ba9093cc5df9640116842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 29 May 2007 18:46:20 +0200 Subject: Fix typo reporting ID3v2.4 tags as ID3v2.3. --- src/demuxers/id3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/demuxers/id3.c b/src/demuxers/id3.c index e5d767b1e..e9ed43d4d 100644 --- a/src/demuxers/id3.c +++ b/src/demuxers/id3.c @@ -898,7 +898,7 @@ int id3v2_parse_tag(input_plugin_t *input, break; case 4: - xprintf(stream->xine, XINE_VERBOSITY_LOG, "ID3V2.3 tag\n"); + xprintf(stream->xine, XINE_VERBOSITY_LOG, "ID3V2.4 tag\n"); result = id3v24_parse_tag(input, stream, mp3_frame_header); break; -- cgit v1.2.3 From dcd3bdb0ea6df1a110f317ad4d8995653d9ba5a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 29 May 2007 19:00:05 +0200 Subject: Use the integer versions of Speex decoding functions, this avoids an iteration over the decoded frames to transform them to integer, and also avoids an improper saturation. --- src/libxineadec/xine_speex_decoder.c | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/libxineadec/xine_speex_decoder.c b/src/libxineadec/xine_speex_decoder.c index b729dc3bb..034e726a6 100644 --- a/src/libxineadec/xine_speex_decoder.c +++ b/src/libxineadec/xine_speex_decoder.c @@ -72,8 +72,6 @@ typedef struct speex_decoder_s { SpeexStereoState stereo; int expect_metadata; - float output[MAX_FRAME_SIZE]; - int header_count; xine_stream_t *stream; @@ -296,9 +294,8 @@ static void speex_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { for (j = 0; j < this->nframes; j++) { int ret; int bitrate; - ogg_int16_t * ptr = audio_buffer->mem; - ret = speex_decode (this->st, &this->bits, this->output); + ret = speex_decode_int (this->st, &this->bits, audio_buffer->mem); if (ret==-1) break; @@ -312,27 +309,13 @@ static void speex_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { } if (this->channels == 2) { - speex_decode_stereo (this->output, this->frame_size, &this->stereo); + speex_decode_stereo_int (audio_buffer->mem, this->frame_size, &this->stereo); } speex_decoder_ctl (this->st, SPEEX_GET_BITRATE, &bitrate); if (bitrate <= 1) bitrate = 16000; /* assume 16 kbit */ _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE, bitrate); - /*PCM saturation (just in case)*/ - for (i=0; i < this->frame_size * this->channels; i++) - { - if (this->output[i]>32000.0) - this->output[i]=32000.0; - else if (this->output[i]<-32000.0) - this->output[i]=-32000.0; - } - - /*Convert to short and play */ - for (i=0; i< this->frame_size * this->channels; i++) { - *ptr++ = (ogg_int16_t)this->output[i]; - } - audio_buffer->vpts = this->pts; this->pts=0; audio_buffer->num_frames = this->frame_size; -- cgit v1.2.3 From b681e2018ab1e212195aa5dfa1fb03cb69533e62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 29 May 2007 19:08:15 +0200 Subject: Actually id3v2_tagsize was used by demux_mpgaudio and demux_aac; but as it makes little sense, move BE_*_synchsafe functions from id3.c to id3.h and declare them inline, then BE_32_synchsafe can be replaced to id3v2_tagsize as drop in. --- src/demuxers/demux_aac.c | 2 +- src/demuxers/demux_mpgaudio.c | 3 +-- src/demuxers/id3.c | 32 -------------------------------- src/demuxers/id3.h | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/demuxers/demux_aac.c b/src/demuxers/demux_aac.c index ab71e8382..1775a4e0e 100644 --- a/src/demuxers/demux_aac.c +++ b/src/demuxers/demux_aac.c @@ -84,7 +84,7 @@ static int open_aac_file(demux_aac_t *this) { /* Check if there's an ID3v2 tag at the start */ if ( id3v2_istag(peak) ) { - id3size = id3v2_tagsize(&peak[6]); + id3size = BE_32_synchsafe(&peak[6]); this->input->seek(this->input, 4, SEEK_SET); diff --git a/src/demuxers/demux_mpgaudio.c b/src/demuxers/demux_mpgaudio.c index 31b2d33ff..f675e227a 100644 --- a/src/demuxers/demux_mpgaudio.c +++ b/src/demuxers/demux_mpgaudio.c @@ -697,8 +697,7 @@ static int detect_mpgaudio_file(input_plugin_t *input) { * id3v2 are not specific to mp3 files, * flac files can contain id3v2 tags */ - uint8_t *ptr = &buf[6]; - uint32_t tag_size = id3v2_tagsize(ptr); + uint32_t tag_size = BE_32_synchsafe(&buf[6]); lprintf("try to skip id3v2 tag (%d bytes)\n", tag_size); if ((10 + tag_size) >= preview_len) { lprintf("cannot skip id3v2 tag\n"); diff --git a/src/demuxers/id3.c b/src/demuxers/id3.c index e9ed43d4d..a59eb6259 100644 --- a/src/demuxers/id3.c +++ b/src/demuxers/id3.c @@ -227,38 +227,6 @@ static int id3v2_parse_genre(char* dest, char *src, int len) { return 1; } -#if 0 -/* parse an unsynchronized 16bits integer */ -static uint16_t BE_16_synchsafe(uint8_t buf[2]) { - return ((uint16_t)(buf[0] & 0x7F) << 7) | - (uint16_t)(buf[1] & 0x7F); -} -#endif - -/* parse an unsynchronized 24bits integer */ -static uint32_t BE_24_synchsafe(uint8_t buf[3]) { - return ((uint32_t)(buf[0] & 0x7F) << 14) | - ((uint32_t)(buf[1] & 0x7F) << 7) | - (uint32_t)(buf[2] & 0x7F); -} - -/* parse an unsynchronized 32bits integer */ -static uint32_t BE_32_synchsafe(uint8_t buf[4]) { - return ((uint32_t)(buf[0] & 0x7F) << 21) | - ((uint32_t)(buf[1] & 0x7F) << 14) | - ((uint32_t)(buf[2] & 0x7F) << 7) | - (uint32_t)(buf[3] & 0x7F); -} - -/* parse an unsynchronized 35bits integer */ -static uint32_t BE_35_synchsafe(uint8_t buf[5]) { - return ((uint32_t)(buf[0] & 0x07) << 28) | - ((uint32_t)(buf[1] & 0x7F) << 21) | - ((uint32_t)(buf[2] & 0x7F) << 14) | - ((uint32_t)(buf[3] & 0x7F) << 7) | - (uint32_t)(buf[4] & 0x7F); -} - static int id3v2_parse_header(input_plugin_t *input, uint8_t *mp3_frame_header, id3v2_header_t *tag_header) { uint8_t buf[6]; diff --git a/src/demuxers/id3.h b/src/demuxers/id3.h index 9b86ec94e..b8f0984b1 100644 --- a/src/demuxers/id3.h +++ b/src/demuxers/id3.h @@ -181,4 +181,36 @@ static inline int id3v2_istag(uint8_t *ptr) { (ptr[2] == '3'); } +#if 0 +/* parse an unsynchronized 16bits integer */ +static inline uint16_t BE_16_synchsafe(uint8_t buf[2]) { + return ((uint16_t)(buf[0] & 0x7F) << 7) | + (uint16_t)(buf[1] & 0x7F); +} +#endif + +/* parse an unsynchronized 24bits integer */ +static inline uint32_t BE_24_synchsafe(uint8_t buf[3]) { + return ((uint32_t)(buf[0] & 0x7F) << 14) | + ((uint32_t)(buf[1] & 0x7F) << 7) | + (uint32_t)(buf[2] & 0x7F); +} + +/* parse an unsynchronized 32bits integer */ +static inline uint32_t BE_32_synchsafe(uint8_t buf[4]) { + return ((uint32_t)(buf[0] & 0x7F) << 21) | + ((uint32_t)(buf[1] & 0x7F) << 14) | + ((uint32_t)(buf[2] & 0x7F) << 7) | + (uint32_t)(buf[3] & 0x7F); +} + +/* parse an unsynchronized 35bits integer */ +static inline uint32_t BE_35_synchsafe(uint8_t buf[5]) { + return ((uint32_t)(buf[0] & 0x07) << 28) | + ((uint32_t)(buf[1] & 0x7F) << 21) | + ((uint32_t)(buf[2] & 0x7F) << 14) | + ((uint32_t)(buf[3] & 0x7F) << 7) | + (uint32_t)(buf[4] & 0x7F); +} + #endif /* ID3_H */ -- cgit v1.2.3