mplib_s.h

Go to the documentation of this file.
00001 /*
00002  * mplib - a library that enables you to edit ID3 tags
00003  *
00004  * Copyright (c) 2001,2002,2003,2004,2005,2006 Stefan Podkowinski
00005  *               2006                          Michal Kowalczuk
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without 
00009  * modification, are permitted provided that the following conditions are met:
00010  *
00011  * * Redistributions of source code must retain the above copyright notice, this
00012  *   list of conditions and the following disclaimer.
00013  * * Redistributions in binary form must reproduce the above copyright notice,
00014  *   this list of conditions and the following disclaimer in the documentation
00015  *   and/or other materials provided with the distribution.
00016  * * Neither the name of the author nor the names of its contributors
00017  *   may be used to endorse or promote products derived from this software
00018  *   without specific prior written permission.
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00021  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00022  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00023  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00024  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00025  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00026  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00027  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00028  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00029  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00030  * POSSIBILITY OF SUCH DAMAGE.
00031  */
00032 
00033 #include "mplib.h"
00034 
00035 #ifndef __MPLIB_S_H
00036 #define __MPLIB_S_H
00037 
00038 #undef __BEGIN_DECLS
00039 #undef __END_DECLS
00040 #ifdef __cplusplus
00041 # define __BEGIN_DECLS extern "C" {
00042 # define __END_DECLS }
00043 #else
00044 # define __BEGIN_DECLS /* empty */
00045 # define __END_DECLS /* empty */
00046 #endif
00047 
00048 
00049 __BEGIN_DECLS
00050 
00051 
00052 /************************************/
00053 /*              Members             */
00054 /************************************/
00055 
00056 /* Bitrates br_[version]_[layer] ) */
00057 const static int br_1_1[16] = { -1, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, 0 };
00058 const static int br_1_2[16] = { -1, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, 0 };
00059 const static int br_1_3[16] = { -1, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 0 };
00060 const static int br_2_1[16] = { -1, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, 0 };
00061 const static int br_2_2[16] = { -1, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, 0 };
00062 const static int br_2_3[16] = { -1, 8, 16, 24, 32, 64, 80, 56, 64, 128, 160, 112, 128, 256, 320, 0 };
00063 
00064 #define GLL 148
00065 const static char *genre_list[GLL] = 
00066 { "Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", "Grunge", "Hip-Hop", "Jazz",
00067   "Metal", "New Age", "Oldies", "Other", "Pop", "R&B", "Rap", "Reggae", "Rock", "Techno",
00068   "Industrial", "Alternative", "Ska", "Death Metal", "Pranks", "Soundtrack", "Euro-Techno",
00069   "Ambient", "Trip-Hop", "Vocal", "Jazz+Funk", "Fusion", "Trance", "Classical", "Instrumental",
00070   "Acid", "House", "Game", "Sound Clip", "Gospel", "Noise", "Alternative Rock", "Bass", "Soul", "Punk",
00071   "Space", "Meditative", "Instrumental Pop", "Instrumental Rock", "Ethnic", "Gothic", "Darkwave",
00072   "Techno-Industrial", "Electronic", "Pop-Folk", "Eurodance", "Dream", "Southern Rock", "Comedy", 
00073   "Cult", "Gangsta Rap", "Top 40", "Christian Rap", "Pop/Funk", "Jungle", "Native American", "Cabaret",
00074   "New Wave", "Psychedelic", "Rave", "Showtunes", "Trailer", "Lo-Fi", "Tribal", "Acid Punk",
00075   "Acid Jazz", "Polka", "Retro", "Musical", "Rock & Roll", "Hard Rock", "Folk", "Folk/Rock", 
00076   "National Folk", "Swing", "Fast-Fusion", "Bebob", "Latin", "Revival", "Celtic", "Bluegrass",
00077   "Avantgarde", "Gothic Rock", "Progressive Rock", "Psychedelic Rock", "Symphonic Rock", "Slow Rock",
00078   "Big Band", "Chorus", "Easy Listening", "Acoustic", "Humour", "Speech", "Chanson", "Opera",
00079   "Chamber Music", "Sonata", "Symphony", "Booty Bass", "Primus", "Porn Groove", "Satire", "Slow Jam",
00080   "Club", "Tango", "Samba", "Folklore", "Ballad", "Power Ballad", "Rythmic Soul", "Freestyle",
00081   "Duet", "Punk Rock", "Drum Solo", "A Cappella", "Euro-House", "Dance Hall", "Goa", "Drum & Bass",
00082   "Club-House", "Hardcore", "Terror", "Indie", "BritPop", "Negerpunk", "Polsk Punk", "Beat",
00083   "Christian Gangsta Rap", "Heavy Metal", "Black Metal", "Crossover", "Contemporary Christian",
00084   "Christian Rock", "Merengue", "Salsa", "Trash Metal", "Anime", "JPop", "Synthpop" };
00085 
00086 
00087 /************************************/
00088 /*               Macros             */
00089 /************************************/
00090 
00091 #define frame_is_read_only(id3v2_frame__) ((id3v2_frame__->status_flag >> 4) & 1)
00092 #define frame_preserve_on_tag_altered(id3v2_frame__) ((id3v2_frame__->status_flag >> 6) & 1)
00093 #define frame_preserve_on_file_altered(id3v2_frame__) ((id3v2_frame__->status_flag >> 5) & 1)
00094 
00095 #define frame_has_group_information(id3v2_frame__) ((id3v2_frame__->format_flag >> 6) & 1)
00096 #define frame_is_compressed(id3v2_frame__) ((id3v2_frame__->format_flag >> 3) & 1)
00097 #define frame_is_encrypted(id3v2_frame__) ((id3v2_frame__->format_flag >> 2) & 1)
00098 #define frame_is_unsynchronised(id3v2_frame__) ((id3v2_frame__->format_flag >> 1) & 1)
00099 #define frame_has_data_length_indicator(id3v2_frame__) (id3v2_frame__->format_flag & 1)
00100 
00101 
00102 /************************************/
00103 /*         Static functions         */
00104 /************************************/
00105 
00106 
00107 /* Gets the v1/v2 tag */
00108 static id3v1_tag *id3v1_get_tag(size_t (*read_func)(void *, size_t, void *),
00109                 off_t (*lseek_func)(off_t, int, void *),
00110                 void *arg);
00111 static id3v2_tag *id3v2_get_tag(size_t (*read_func)(void *, size_t, void *),
00112                 off_t (*lseek_func)(off_t, int, void *),
00113                 void *arg);
00114 
00115 /* Adds v1/v2 Tag to file */
00116 static int id3v1_add_tag(int, id3v1_tag*);
00117 static int id3v2_add_tag(int, id3v2_tag*, id3v2_tag*);
00118 
00119 /* Removes v1/v2 Tag from file */
00120 static int id3v1_del_tag(int);
00121 static int id3v2_del_tag(int, id3v2_tag*);
00122 
00123 /* Truncates the fields of the tag to the proper lengths */
00124 static int id3v1_truncate_tag(id3v1_tag*);
00125 
00126 /* Returns 1 or 0 whether arg 1 is just filled up with space (0x20) or not */
00127 static int id3_is_only_space(char*, int);
00128 
00129 /* Gets all frame names available in the tag */
00130 static char **id3v2_get_names(id3v2_tag*);
00131 
00132 /* Gets the content of the given field in the tag on the specified position. */
00133 static id3_content* id3v2_get_content_at_pos(id3v2_tag*, const char*, int);
00134 static id3_content* id3v1_get_content(id3v1_tag*, int);
00135 
00136 /* Gets the number of available frames */
00137 static int id3_get_no_frames(id3v2_tag*);
00138 
00139 /* Returns string of the frames content */
00140 /* static char* extract_frame_data(char *, int); */
00141 
00142 /* Removes a frame from the frame list */
00143 static int id3_remove_frame(id3v2_frame_list *, id3v2_frame *);
00144 
00145 /* Adds a new frame to the list */
00146 static int id3_add_frame(id3v2_frame_list *, char *, char *, int);
00147 
00148 /* Lookups a frame by his identifier on the given position */
00149 static id3v2_frame* id3_lookup_frame(id3v2_frame_list *, const char *, const int);
00150 
00151 /* Sync functions */
00152 static long id3_unsync(unsigned char*, long);
00153 static long id3_sync(unsigned char*, long);
00154 static unsigned int id3_unsync32(unsigned char*, int);
00155 static unsigned char* id3_sync32(unsigned int);
00156 
00157 static int id3_lseek_syncword(int);
00158 static int id3_lseek_syncword_r(int, unsigned char *, int);
00159 
00160 /* Gets a new allocated v1 or v2 tag */
00161 static id3_tag* id3v1_alloc_tag(void);
00162 static id3_tag* id3v2_alloc_tag(void);
00163 
00164 /* free functions */
00165 static void id3v1_free_tag(id3v1_tag*);
00166 static void id3v2_free_tag(id3v2_tag*);
00167 
00168 /* read and lseek wrappers for memory */
00169 size_t read_mem(void *dest, size_t nbytes, void *varg);
00170 off_t lseek_mem(off_t offset, int whence, void *varg);
00171 
00172 /* read and lseek wrappers for files */
00173 size_t read_file(void *dest, size_t nbytes, void *varg);
00174 off_t lseek_file(off_t offset, int whence, void *varg);
00175 
00176 __END_DECLS
00177 
00178 #endif /* __MPLIB_S_H */