summaryrefslogtreecommitdiff
path: root/src/demuxers/demux_flac.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/demuxers/demux_flac.c')
-rw-r--r--src/demuxers/demux_flac.c126
1 files changed, 35 insertions, 91 deletions
diff --git a/src/demuxers/demux_flac.c b/src/demuxers/demux_flac.c
index f52da4d03..b4c5427c5 100644
--- a/src/demuxers/demux_flac.c
+++ b/src/demuxers/demux_flac.c
@@ -15,15 +15,13 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
*/
/*
* FLAC File Demuxer by Mike Melanson (melanson@pcisys.net)
* For more information on the FLAC file format, visit:
* http://flac.sourceforge.net/
- *
- * $Id: demux_flac.c,v 1.17 2007/03/29 16:52:23 dgp85 Exp $
*/
#ifdef HAVE_CONFIG_H
@@ -42,10 +40,10 @@
#define LOG
*/
-#include "xine_internal.h"
-#include "xineutils.h"
-#include "compat.h"
-#include "demux.h"
+#include <xine/xine_internal.h>
+#include <xine/xineutils.h>
+#include <xine/compat.h>
+#include <xine/demux.h>
#include "bswap.h"
#include "group_audio.h"
@@ -82,6 +80,7 @@ typedef struct {
* It returns 1 if flac file was opened successfully. */
static int open_flac_file(demux_flac_t *flac) {
+ uint32_t signature;
unsigned char preamble[10];
unsigned int block_length;
unsigned char buffer[FLAC_SEEKPOINT_SIZE];
@@ -90,41 +89,27 @@ 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, &signature, 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);
+ if ( id3v2_istag(signature) ) {
+ id3v2_parse_tag(flac->input, flac->stream, signature);
- flac->input->seek(flac->input, id3size, SEEK_SET);
-
- if ( flac->input->read(flac->input, preamble, 4) != 4 )
+ if ( flac->input->read(flac->input, &signature, 4) != 4 )
return 0;
- } else
- flac->input->seek(flac->input, 4, SEEK_SET);
+ }
/* validate signature */
- if ((preamble[0] != 'f') || (preamble[1] != 'L') ||
- (preamble[2] != 'a') || (preamble[3] != 'C'))
+ if ( signature != ME_FOURCC('f', 'L', 'a', 'C') )
return 0;
/* loop through the metadata blocks; use a do-while construct since there
@@ -153,11 +138,11 @@ static int open_flac_file(demux_flac_t *flac) {
flac->streaminfo + sizeof(xine_waveformatex),
FLAC_STREAMINFO_SIZE) != FLAC_STREAMINFO_SIZE)
return 0;
- flac->sample_rate = BE_32(&streaminfo[10]);
+ flac->sample_rate = _X_BE_32(&streaminfo[10]);
flac->channels = ((flac->sample_rate >> 9) & 0x07) + 1;
flac->bits_per_sample = ((flac->sample_rate >> 4) & 0x1F) + 1;
flac->sample_rate >>= 12;
- flac->total_samples = BE_64(&streaminfo[10]) & UINT64_C(0x0FFFFFFFFF); /* 36 bits */
+ flac->total_samples = _X_BE_64(&streaminfo[10]) & UINT64_C(0x0FFFFFFFFF); /* 36 bits */
lprintf ("%d Hz, %d bits, %d channels, %"PRId64" total samples\n",
flac->sample_rate, flac->bits_per_sample,
flac->channels, flac->total_samples);
@@ -179,15 +164,15 @@ static int open_flac_file(demux_flac_t *flac) {
case 3:
lprintf ("SEEKTABLE metadata, %d bytes\n", block_length);
flac->seekpoint_count = block_length / FLAC_SEEKPOINT_SIZE;
- flac->seekpoints = xine_xmalloc(flac->seekpoint_count *
- sizeof(flac_seekpoint_t));
+ flac->seekpoints = xine_xcalloc(flac->seekpoint_count,
+ sizeof(flac_seekpoint_t));
for (i = 0; i < flac->seekpoint_count; i++) {
if (flac->input->read(flac->input, buffer, FLAC_SEEKPOINT_SIZE) != FLAC_SEEKPOINT_SIZE)
return 0;
- flac->seekpoints[i].sample_number = BE_64(&buffer[0]);
+ flac->seekpoints[i].sample_number = _X_BE_64(&buffer[0]);
lprintf (" %d: sample %"PRId64", ", i, flac->seekpoints[i].sample_number);
- flac->seekpoints[i].offset = BE_64(&buffer[8]);
- flac->seekpoints[i].size = BE_16(&buffer[16]);
+ flac->seekpoints[i].offset = _X_BE_64(&buffer[8]);
+ flac->seekpoints[i].size = _X_BE_16(&buffer[16]);
lprintf ("@ 0x%"PRIX64", size = %d bytes, ",
flac->seekpoints[i].offset, flac->seekpoints[i].size);
flac->seekpoints[i].pts = flac->seekpoints[i].sample_number;
@@ -205,9 +190,8 @@ static int open_flac_file(demux_flac_t *flac) {
lprintf ("VORBIS_COMMENT metadata\n");
{
char comments[block_length];
- void *ptr = comments;
- uint32_t length, user_comment_list_length;
- int cn;
+ char *ptr = comments;
+ uint32_t length, user_comment_list_length, cn;
char *comment;
char c;
@@ -215,15 +199,15 @@ static int open_flac_file(demux_flac_t *flac) {
int tracknumber = -1;
int tracktotal = -1;
- length = LE_32(ptr);
+ length = _X_LE_32(ptr);
ptr += 4 + length;
- user_comment_list_length = LE_32(ptr);
+ user_comment_list_length = _X_LE_32(ptr);
ptr += 4;
cn = 0;
for (; cn < user_comment_list_length; cn++) {
- length = LE_32(ptr);
+ length = _X_LE_32(ptr);
ptr += 4;
comment = (char*) ptr;
@@ -455,12 +439,6 @@ static int demux_flac_seek (demux_plugin_t *this_gen,
return this->status;
}
-static void demux_flac_dispose (demux_plugin_t *this_gen) {
- demux_flac_t *this = (demux_flac_t *) this_gen;
-
- free(this->seekpoints);
-}
-
static int demux_flac_get_status (demux_plugin_t *this_gen) {
demux_flac_t *this = (demux_flac_t *) this_gen;
@@ -504,7 +482,7 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *str
this->demux_plugin.send_headers = demux_flac_send_headers;
this->demux_plugin.send_chunk = demux_flac_send_chunk;
this->demux_plugin.seek = demux_flac_seek;
- this->demux_plugin.dispose = demux_flac_dispose;
+ this->demux_plugin.dispose = default_demux_plugin_dispose;
this->demux_plugin.get_status = demux_flac_get_status;
this->demux_plugin.get_stream_length = demux_flac_get_stream_length;
this->demux_plugin.get_capabilities = demux_flac_get_capabilities;
@@ -515,19 +493,7 @@ 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);
-
- if (!_x_demux_check_extension (mrl, extensions)) {
- free (this);
- return NULL;
- }
- }
- /* falling through is intended */
-
+ case METHOD_BY_MRL:
case METHOD_BY_CONTENT:
case METHOD_EXPLICIT:
@@ -546,39 +512,17 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *str
return &this->demux_plugin;
}
-static const char *get_description (demux_class_t *this_gen) {
- return "Free Lossless Audio Codec (flac) demux plugin";
-}
-
-static const char *get_identifier (demux_class_t *this_gen) {
- return "FLAC";
-}
-
-static const char *get_extensions (demux_class_t *this_gen) {
- return "flac";
-}
-
-static const char *get_mimetypes (demux_class_t *this_gen) {
- return NULL;
-}
-
-static void class_dispose (demux_class_t *this_gen) {
- demux_flac_class_t *this = (demux_flac_class_t *) this_gen;
-
- free (this);
-}
-
void *demux_flac_init_plugin (xine_t *xine, void *data) {
demux_flac_class_t *this;
this = xine_xmalloc (sizeof (demux_flac_class_t));
this->demux_class.open_plugin = open_plugin;
- this->demux_class.get_description = get_description;
- this->demux_class.get_identifier = get_identifier;
- this->demux_class.get_mimetypes = get_mimetypes;
- this->demux_class.get_extensions = get_extensions;
- this->demux_class.dispose = class_dispose;
+ this->demux_class.description = N_("Free Lossless Audio Codec (flac) demux plugin");
+ this->demux_class.identifier = "FLAC";
+ this->demux_class.mimetypes = NULL;
+ this->demux_class.extensions = "flac";
+ this->demux_class.dispose = default_demux_class_dispose;
return this;
}