mod_musicindex  1.4.1
playlist-mp3.c File Reference

MP3 files management system. More...

#include "playlist.h"
#include "playlist-mp3.h"
#include <mad.h>
#include <id3tag.h>
#include <ctype.h>

Go to the source code of this file.

Data Structures

struct  xing
 xing header structure More...

Macros

#define INPUT_BUFFER_SIZE   16*1024
 Input buffer size used by libmad subsystem.
#define MAD_AVERAGE_FRAMES   10
 Number of frames to read before doing average calculations for VBR files.
#define DO_FAST_CALC   1
 Whether we should read the whole file and get accurate bitrate/length or not.
#define XING_MAGIC1   ( ('X' << 24) | ('i' << 16) | ('n' << 8) | 'g' )
 XING magic header.
#define XING_MAGIC2   ( ('I' << 24) | ('n' << 16) | ('f' << 8) | 'o' )
 XING magic header.

Enumerations

enum  { XING_FRAMES = 0x00000001L, XING_BYTES = 0x00000002L, XING_TOC = 0x00000004L, XING_SCALE = 0x00000008L }
 xing fields enumeration More...

Functions

static short xing_parse (struct xing *xing, struct mad_bitptr ptr, unsigned short bitlen)
 Parse Xing VBR headers.
static short mpg123_mp3_ext_check (const char *const filename)
 Checks for valid MP3 filename extension.
static id3_utf8_t * utf8_id3tag_findframe (struct id3_tag *tag, const char *const frameid, unsigned short index)
 Converts an id3tag string in utf8.
mu_entmake_mp3_entry (request_rec *r, apr_pool_t *pool, FILE *const in, const char *const filename)
 Fills in the information fields about MP3 data.

Detailed Description

MP3 files management system.

Author
Regis Boudin
Thibaut Varene
Version
Revision:
1010
Date
2003-2009

This file contains everything needed to produce music entries from MP3 files.
Some pieces of code are based on xmms mpg123 and mad plugins.
DEV NOTE: As one might guess, MP3 files are a real mess :P

Todo:
Find out if we trash "detect by content".

Definition in file playlist-mp3.c.

Macro Definition Documentation

#define DO_FAST_CALC   1

Whether we should read the whole file and get accurate bitrate/length or not.

Definition at line 46 of file playlist-mp3.c.

Referenced by make_mp3_entry().

#define INPUT_BUFFER_SIZE   16*1024

Input buffer size used by libmad subsystem.

Definition at line 44 of file playlist-mp3.c.

Referenced by make_mp3_entry().

#define MAD_AVERAGE_FRAMES   10

Number of frames to read before doing average calculations for VBR files.

Definition at line 45 of file playlist-mp3.c.

Referenced by make_mp3_entry().

#define XING_MAGIC1   ( ('X' << 24) | ('i' << 16) | ('n' << 8) | 'g' )

XING magic header.

Definition at line 47 of file playlist-mp3.c.

Referenced by xing_parse().

#define XING_MAGIC2   ( ('I' << 24) | ('n' << 16) | ('f' << 8) | 'o' )

XING magic header.

Definition at line 48 of file playlist-mp3.c.

Referenced by xing_parse().

Enumeration Type Documentation

anonymous enum

xing fields enumeration

Enumerator:
XING_FRAMES 
XING_BYTES 
XING_TOC 
XING_SCALE 

Definition at line 60 of file playlist-mp3.c.

Function Documentation

mu_ent* make_mp3_entry ( request_rec *  r,
apr_pool_t pool,
FILE *const  in,
const char *const  filename 
)

Fills in the information fields about MP3 data.

This function reads the id3 tags (using libid3tag0) from the MP3 file in and fills in the struct mu_ent fields accordingly.

Parameters
poolPool
inMP3 file to parse (closed on normal exit)
filenamecurrent filename
rApache request_rec struct to handle log writings (debugging)
Bug:
Some VBR files are reported as "bitrate: 0".
Returns
When possible, struct mu_ent correctly set up, file stream closed.

Definition at line 252 of file playlist-mp3.c.

References mu_ent::album, apr_pstrdup, mu_ent::artist, mu_ent::bitrate, xing::bytes, mu_ent::date, DO_FAST_CALC, EF_VBR, mu_ent::filetype, mu_ent::flags, xing::frames, mu_ent::freq, FT_MP3, mu_ent::genre, INPUT_BUFFER_SIZE, mu_ent::length, MAD_AVERAGE_FRAMES, MI_QUICKPL, mi_rdebug, mpg123_mp3_ext_check(), mu_ent::mtime, musicindex_module, NEW_ENT, mu_config::options, mu_ent::posn, mu_ent::size, mu_ent::title, mu_ent::track, utf8_id3tag_findframe(), and xing_parse().

static short mpg123_mp3_ext_check ( const char *const  filename)
inlinestatic

Checks for valid MP3 filename extension.

Parameters
filenameThe filename to check.
Returns
FALSE when the extension is correct, TRUE otherwise.

Definition at line 181 of file playlist-mp3.c.

References FALSE, and TRUE.

Referenced by make_mp3_entry().

static id3_utf8_t* utf8_id3tag_findframe ( struct id3_tag *  tag,
const char *const  frameid,
unsigned short  index 
)
static

Converts an id3tag string in utf8.

This function reads the id3tag from an MP3 file (if any) and converts the result in the utf8 standard format. It handles V1/V2 genres correctly.

Warning
Allocates memory. Don't forget to free().
Bug:
FIXME bracketed genre.
Parameters
tagThe tag struct to parse
frameidThe type of tag data searched
indexThe id3tag index value
Returns
When possible, an utf8_t string, NULL otherwise.

Definition at line 205 of file playlist-mp3.c.

Referenced by make_mp3_entry().

static short xing_parse ( struct xing xing,
struct mad_bitptr  ptr,
unsigned short  bitlen 
)
static

Parse Xing VBR headers.

This function comes from xmms-mad plugin.

Parameters
xingXing structure to populate.
ptrmad_bitptr struct.
bitlenbit size.
Returns
0 on success, -1 otherwise.

Definition at line 116 of file playlist-mp3.c.

References xing::bytes, xing::flags, xing::frames, xing::scale, xing::toc, XING_BYTES, XING_FRAMES, XING_MAGIC1, XING_MAGIC2, XING_SCALE, and XING_TOC.

Referenced by make_mp3_entry().