vlc_meta.h 5.72 KB
Newer Older
1
/*****************************************************************************
2
 * vlc_meta.h: Stream meta-data
3
 *****************************************************************************
4
 * Copyright (C) 2004 the VideoLAN team
5
 * $Id$
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
Antoine Cellerier's avatar
Antoine Cellerier committed
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 23 24 25 26 27
 *****************************************************************************/

#ifndef _VLC_META_H
#define _VLC_META_H 1

/* VLC meta name */
28
#define VLC_META_INFO_CAT           N_("Meta-information")
29 30 31 32 33
#define VLC_META_TITLE              N_("Title")
#define VLC_META_AUTHOR             N_("Author")
#define VLC_META_ARTIST             N_("Artist")
#define VLC_META_GENRE              N_("Genre")
#define VLC_META_COPYRIGHT          N_("Copyright")
34 35
#define VLC_META_COLLECTION         N_("Album/movie/show title")
#define VLC_META_SEQ_NUM            N_("Track number/position in set")
36 37 38 39
#define VLC_META_DESCRIPTION        N_("Description")
#define VLC_META_RATING             N_("Rating")
#define VLC_META_DATE               N_("Date")
#define VLC_META_SETTING            N_("Setting")
40
#define VLC_META_URL                N_("URL")
41
#define VLC_META_LANGUAGE           N_("Language")
42
#define VLC_META_NOW_PLAYING        N_("Now Playing")
43
#define VLC_META_PUBLISHER          N_("Publisher")
44 45

#define VLC_META_CDDB_ARTIST        N_("CDDB Artist")
46
#define VLC_META_CDDB_CATEGORY      N_("CDDB Category")
47 48 49
#define VLC_META_CDDB_DISCID        N_("CDDB Disc ID")
#define VLC_META_CDDB_EXT_DATA      N_("CDDB Extended Data")
#define VLC_META_CDDB_GENRE         N_("CDDB Genre")
50
#define VLC_META_CDDB_YEAR          N_("CDDB Year")
51 52 53 54 55 56 57 58 59 60 61
#define VLC_META_CDDB_TITLE         N_("CDDB Title")

#define VLC_META_CDTEXT_ARRANGER    N_("CD-Text Arranger")
#define VLC_META_CDTEXT_COMPOSER    N_("CD-Text Composer")
#define VLC_META_CDTEXT_DISCID      N_("CD-Text Disc ID")
#define VLC_META_CDTEXT_GENRE       N_("CD-Text Genre")
#define VLC_META_CDTEXT_MESSAGE     N_("CD-Text Message")
#define VLC_META_CDTEXT_SONGWRITER  N_("CD-Text Songwriter")
#define VLC_META_CDTEXT_PERFORMER   N_("CD-Text Performer")
#define VLC_META_CDTEXT_TITLE       N_("CD-Text Title")

62 63 64 65 66
#define VLC_META_ISO_APPLICATION_ID N_("ISO-9660 Application ID")
#define VLC_META_ISO_PREPARER       N_("ISO-9660 Preparer")
#define VLC_META_ISO_PUBLISHER      N_("ISO-9660 Publisher")
#define VLC_META_ISO_VOLUME         N_("ISO-9660 Volume")
#define VLC_META_ISO_VOLUMESET      N_("ISO-9660 Volume Set")
67

68 69 70 71 72 73 74 75 76 77
#define VLC_META_CODEC_NAME         N_("Codec Name")
#define VLC_META_CODEC_DESCRIPTION  N_("Codec Description")

struct vlc_meta_t
{
    /* meta name/value pairs */
    int     i_meta;
    char    **name;
    char    **value;

78
    /* track meta information */
79 80 81 82 83 84
    int         i_track;
    vlc_meta_t  **track;
};

static inline vlc_meta_t *vlc_meta_New( void )
{
85
    vlc_meta_t *m = (vlc_meta_t*)malloc( sizeof( vlc_meta_t ) );
86 87 88 89 90 91 92 93 94 95

    m->i_meta = 0;
    m->name   = NULL;
    m->value  = NULL;

    m->i_track= 0;
    m->track  = NULL;

    return m;
}
96

97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
static inline void vlc_meta_Delete( vlc_meta_t *m )
{
    int i;
    for( i = 0; i < m->i_meta; i++ )
    {
        free( m->name[i] );
        free( m->value[i] );
    }
    if( m->name ) free( m->name );
    if( m->value ) free( m->value );

    for( i = 0; i < m->i_track; i++ )
    {
        vlc_meta_Delete( m->track[i] );
    }
    if( m->track ) free( m->track );
    free( m );
}
115

116 117
static inline void vlc_meta_Add( vlc_meta_t *m,
                                 const char *name, const char *value )
118
{
119 120
    m->name  = (char**)realloc( m->name, sizeof(char*) * ( m->i_meta + 1 ) );
    m->name[m->i_meta] = strdup( name );
121

122 123
    m->value = (char**)realloc( m->value, sizeof(char*) * ( m->i_meta + 1 ) );
    m->value[m->i_meta] = strdup( value );
124

125
    m->i_meta++;
126 127 128 129 130 131 132 133 134 135 136 137 138
}

static inline vlc_meta_t *vlc_meta_Duplicate( vlc_meta_t *src )
{
    vlc_meta_t *dst = vlc_meta_New();
    int i;
    for( i = 0; i < src->i_meta; i++ )
    {
        vlc_meta_Add( dst, src->name[i], src->value[i] );
    }
    for( i = 0; i < src->i_track; i++ )
    {
        vlc_meta_t *tk = vlc_meta_Duplicate( src->track[i] );
139 140 141

        dst->track = (vlc_meta_t**)realloc( dst->track, sizeof( vlc_meta_t* ) * (dst->i_track+1) );
        dst->track[dst->i_track++] = tk;
142 143 144 145
    }
    return dst;
}

146 147 148 149 150 151 152
static inline void vlc_meta_Merge( vlc_meta_t *dst, vlc_meta_t *src )
{
    int i, j;
    for( i = 0; i < src->i_meta; i++ )
    {
        /* Check if dst contains the entry */
        for( j = 0; j < dst->i_meta; j++ )
153 154 155 156 157 158 159 160 161
        {
            if( !strcmp( src->name[i], dst->name[j] ) ) break;
        }
        if( j < dst->i_meta )
        {
            if( dst->value[j] ) free( dst->value[j] );
            dst->value[j] = strdup( src->value[i] );
        }
        else vlc_meta_Add( dst, src->name[i], src->value[i] );
162 163
    }
}
164

165
static inline char *vlc_meta_GetValue( vlc_meta_t *m, const char *name )
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
{
    int i;

    for( i = 0; i < m->i_meta; i++ )
    {
        if( !strcmp( m->name[i], name ) )
        {
            char *value = NULL;
            if( m->value[i] ) value = strdup( m->value[i] );
            return value;
        }
    }
    return NULL;
}

181
#endif