1 /*****************************************************************************
2 * info.c : CD digital audio input information routines
3 *****************************************************************************
4 * Copyright (C) 2004 the VideoLAN team
7 * Authors: Rocky Bernstein <rocky@panix.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
25 #include <vlc_input.h>
26 #include <vlc_access.h>
28 #include <vlc_playlist.h>
32 #include <cdio/cdio.h>
33 #include <cdio/cd_types.h>
34 #include <cdio/logging.h>
35 #include <cdio/util.h>
36 #include <libvcd/info.h>
37 #include <libvcd/logging.h>
40 MetaInfoAddStr(access_t *p_access, char *psz_cat,
41 char *title, const char *psz)
43 vcdplayer_t *p_vcdplayer = (vcdplayer_t *) p_access->p_sys;
45 dbg_print( INPUT_DBG_META, "cat %s, field: %s: %s", psz_cat, title, psz);
46 input_Control( p_vcdplayer->p_input, INPUT_ADD_INFO, psz_cat, title, "%s",
53 MetaInfoAddNum(access_t *p_access, char *psz_cat, char *title, int num)
55 vcdplayer_t *p_vcdplayer = (vcdplayer_t *) p_access->p_sys;
56 dbg_print( INPUT_DBG_META, "cat %s, field %s: %d", psz_cat, title, num);
57 input_Control( p_vcdplayer->p_input, INPUT_ADD_INFO, psz_cat, title,
62 MetaInfoAddHex(access_t *p_access, char *psz_cat, char *title, int hex)
64 vcdplayer_t *p_vcdplayer = (vcdplayer_t *) p_access->p_sys;
65 dbg_print( INPUT_DBG_META, "cat %s, field %s: %d", psz_cat, title, hex);
66 input_Control( p_vcdplayer->p_input, INPUT_ADD_INFO, psz_cat, title,
70 #define addstr(title, str) \
71 MetaInfoAddStr( p_access, psz_cat, title, str );
73 #define addnum(title, num) \
74 MetaInfoAddNum( p_access, psz_cat, title, num );
76 #define addhex(title, hex) \
77 MetaInfoAddHex( p_access, psz_cat, title, hex );
80 VCDMetaInfo( access_t *p_access, /*const*/ char *psz_mrl )
82 vcdplayer_t *p_vcdplayer = (vcdplayer_t *) p_access->p_sys;
83 unsigned int i_entries = vcdinfo_get_num_entries(p_vcdplayer->vcd);
84 unsigned int last_entry = 0;
90 addstr( _("VCD Format"), vcdinfo_get_format_version_str(p_vcdplayer->vcd) );
91 addstr( _("Album"), vcdinfo_get_album_id(p_vcdplayer->vcd));
92 addstr( _("Application"), vcdinfo_get_application_id(p_vcdplayer->vcd) );
93 addstr( _("Preparer"), vcdinfo_get_preparer_id(p_vcdplayer->vcd) );
94 addnum( _("Vol #"), vcdinfo_get_volume_num(p_vcdplayer->vcd) );
95 addnum( _("Vol max #"), vcdinfo_get_volume_count(p_vcdplayer->vcd) );
96 addstr( _("Volume Set"), vcdinfo_get_volumeset_id(p_vcdplayer->vcd) );
97 addstr( _("Volume"), vcdinfo_get_volume_id(p_vcdplayer->vcd) );
98 addstr( _("Publisher"), vcdinfo_get_publisher_id(p_vcdplayer->vcd) );
99 addstr( _("System Id"), vcdinfo_get_system_id(p_vcdplayer->vcd) );
100 addnum( "LIDs", vcdinfo_get_num_LIDs(p_vcdplayer->vcd) );
101 addnum( _("Entries"), vcdinfo_get_num_entries(p_vcdplayer->vcd) );
102 addnum( _("Segments"), vcdinfo_get_num_segments(p_vcdplayer->vcd) );
103 addnum( _("Tracks"), vcdinfo_get_num_tracks(p_vcdplayer->vcd) );
105 /* Spit out track information. Could also include MSF info.
106 Also build title table.
110 for( i_track = 1 ; i_track < p_vcdplayer->i_tracks ; i_track++ ) {
112 unsigned int audio_type = vcdinfo_get_track_audio_type(p_vcdplayer->vcd,
114 uint32_t i_secsize = vcdinfo_get_track_sect_count(p_vcdplayer->vcd, i_track);
116 snprintf(psz_cat, sizeof(psz_cat), "Track %d", i_track);
117 if (p_vcdplayer->b_svd) {
118 addnum(_("Audio Channels"),
119 vcdinfo_audio_type_num_channels(p_vcdplayer->vcd, audio_type) );
122 addnum(_("First Entry Point"), last_entry );
123 for ( ; last_entry < i_entries
124 && vcdinfo_get_track(p_vcdplayer->vcd, last_entry) == i_track;
126 addnum(_("Last Entry Point"), last_entry-1 );
127 addnum(_("Track size (in sectors)"), i_secsize );
132 for( i_lid = 1 ; i_lid <= p_vcdplayer->i_lids ; i_lid++ ) {
133 PsdListDescriptor_t pxd;
135 snprintf(psz_cat, sizeof(psz_cat), "LID %d", i_lid);
136 if (vcdinfo_lid_get_pxd(p_vcdplayer->vcd, &pxd, i_lid)) {
137 switch (pxd.descriptor_type) {
138 case PSD_TYPE_END_LIST:
139 addstr(_("type"), _("end"));
141 case PSD_TYPE_PLAY_LIST:
142 addstr(_("type"), _("play list"));
143 addnum("items", vcdinf_pld_get_noi(pxd.pld));
144 addhex("next", vcdinf_pld_get_next_offset(pxd.pld));
145 addhex("previous", vcdinf_pld_get_prev_offset(pxd.pld));
146 addhex("return", vcdinf_pld_get_return_offset(pxd.pld));
147 addnum("wait time", vcdinf_get_wait_time(pxd.pld));
149 case PSD_TYPE_SELECTION_LIST:
150 case PSD_TYPE_EXT_SELECTION_LIST:
152 PSD_TYPE_SELECTION_LIST == pxd.descriptor_type
153 ? _("extended selection list")
154 : _("selection list")
156 addhex("default", vcdinf_psd_get_default_offset(pxd.psd));
157 addhex("loop count", vcdinf_get_loop_count(pxd.psd));
158 addhex("next", vcdinf_psd_get_next_offset(pxd.psd));
159 addhex("previous", vcdinf_psd_get_prev_offset(pxd.psd));
160 addhex("return", vcdinf_psd_get_return_offset(pxd.psd));
161 addhex("rejected", vcdinf_psd_get_lid_rejected(pxd.psd));
162 addhex("time-out offset", vcdinf_get_timeout_offset(pxd.psd));
163 addnum("time-out time", vcdinf_get_timeout_time(pxd.psd));
166 addstr(_("type"), _("unknown type"));
173 if ( CDIO_INVALID_TRACK != i_track )
176 VCDFormatStr( p_access, p_vcdplayer,
177 config_GetPsz( p_access, MODULE_STRING "-title-format" ),
178 psz_mrl, &(p_vcdplayer->play_item) );
180 input_Control( p_vcdplayer->p_input, INPUT_SET_NAME, psz_name );
185 #define add_format_str_info(val) \
187 const char *str = strdup(val); \
192 strncat(tp, str, TEMP_STR_LEN-(tp-temp_str)); \
195 saw_control_prefix = VLC_FALSE; \
199 #define add_format_num_info( val, fmt ) \
203 sprintf(num_str, fmt, val); \
204 len = strlen(num_str); \
207 strncat(tp, num_str, TEMP_STR_LEN-(tp-temp_str)); \
210 saw_control_prefix = VLC_FALSE; \
214 Take a format string and expand escape sequences, that is sequences that
215 begin with %, with information from the current VCD.
216 The expanded string is returned. Here is a list of escape sequences:
218 %A : The album information
219 %C : The VCD volume count - the number of CD's in the collection.
220 %c : The VCD volume num - the number of the CD in the collection.
221 %F : The VCD Format, e.g. VCD 1.0, VCD 1.1, VCD 2.0, or SVCD
222 %I : The current entry/segment/playback type, e.g. ENTRY, TRACK, SEGMENT...
223 %L : The playlist ID prefixed with " LID" if it exists
225 %N : The current number of the %I - a decimal number
226 %P : The publisher ID
228 %S : If we are in a segment (menu), the kind of segment
229 %T : The track number
230 %V : The volume set ID
232 A number between 1 and the volume count.
236 VCDFormatStr(const access_t *p_access, vcdplayer_t *p_vcdplayer,
237 const char format_str[], const char *mrl,
238 const vcdinfo_itemid_t *itemid)
240 #define TEMP_STR_SIZE 256
241 #define TEMP_STR_LEN (TEMP_STR_SIZE-1)
242 static char temp_str[TEMP_STR_SIZE];
244 char * tp = temp_str;
245 vlc_bool_t saw_control_prefix = VLC_FALSE;
246 size_t format_len = strlen(format_str);
248 memset(temp_str, 0, TEMP_STR_SIZE);
250 for (i=0; i<format_len; i++) {
252 if (!saw_control_prefix && format_str[i] != '%') {
253 *tp++ = format_str[i];
254 saw_control_prefix = VLC_FALSE;
258 switch(format_str[i]) {
260 if (saw_control_prefix) {
263 saw_control_prefix = !saw_control_prefix;
266 add_format_str_info(vcdinfo_strip_trail(vcdinfo_get_album_id(p_vcdplayer->vcd),
271 add_format_num_info(vcdinfo_get_volume_num(p_vcdplayer->vcd), "%d");
275 add_format_num_info(vcdinfo_get_volume_count(p_vcdplayer->vcd), "%d");
279 add_format_str_info(vcdinfo_get_format_version_str(p_vcdplayer->vcd));
284 switch (itemid->type) {
285 case VCDINFO_ITEM_TYPE_TRACK:
286 strncat(tp, _("Track"), TEMP_STR_LEN-(tp-temp_str));
287 tp += strlen(_("Track"));
289 case VCDINFO_ITEM_TYPE_ENTRY:
290 strncat(tp, _("Entry"), TEMP_STR_LEN-(tp-temp_str));
291 tp += strlen(_("Entry"));
293 case VCDINFO_ITEM_TYPE_SEGMENT:
294 strncat(tp, _("Segment"), TEMP_STR_LEN-(tp-temp_str));
295 tp += strlen(_("Segment"));
297 case VCDINFO_ITEM_TYPE_LID:
298 strncat(tp, _("List ID"), TEMP_STR_LEN-(tp-temp_str));
299 tp += strlen(_("List ID"));
301 case VCDINFO_ITEM_TYPE_SPAREID2:
302 strncat(tp, _("Navigation"), TEMP_STR_LEN-(tp-temp_str));
303 tp += strlen(_("Navigation"));
309 saw_control_prefix = VLC_FALSE;
314 if (vcdplayer_pbc_is_on(p_vcdplayer)) {
316 sprintf(num_str, "%s %d", _("List ID"), p_vcdplayer->i_lid);
317 strncat(tp, num_str, TEMP_STR_LEN-(tp-temp_str));
318 tp += strlen(num_str);
320 saw_control_prefix = VLC_FALSE;
324 add_format_str_info(mrl);
328 add_format_num_info(itemid->num, "%d");
332 add_format_str_info(vcdinfo_get_preparer_id(p_vcdplayer->vcd));
336 add_format_str_info(vcdinfo_get_publisher_id(p_vcdplayer->vcd));
340 if ( VCDINFO_ITEM_TYPE_SEGMENT==itemid->type ) {
341 char seg_type_str[30];
343 sprintf(seg_type_str, " %s",
344 vcdinfo_video_type2str(p_vcdplayer->vcd, itemid->num));
345 strncat(tp, seg_type_str, TEMP_STR_LEN-(tp-temp_str));
346 tp += strlen(seg_type_str);
348 saw_control_prefix = VLC_FALSE;
352 add_format_num_info(p_vcdplayer->i_track, "%d");
356 add_format_str_info(vcdinfo_get_volumeset_id(p_vcdplayer->vcd));
360 add_format_str_info(vcdinfo_get_volume_id(p_vcdplayer->vcd));
365 *tp++ = format_str[i];
366 saw_control_prefix = VLC_FALSE;
369 return strdup(temp_str);
373 VCDUpdateTitle( access_t *p_access )
376 vcdplayer_t *p_vcdplayer= (vcdplayer_t *)p_access->p_sys;
378 unsigned int psz_mrl_max = strlen(VCD_MRL_PREFIX)
379 + strlen(p_vcdplayer->psz_source) + sizeof("@E999")+3;
380 char *psz_mrl = malloc( psz_mrl_max );
385 snprintf(psz_mrl, psz_mrl_max, "%s%s",
386 VCD_MRL_PREFIX, p_vcdplayer->psz_source);
387 psz_name = VCDFormatStr( p_access, p_vcdplayer,
388 config_GetPsz( p_access, MODULE_STRING
390 psz_mrl, &(p_vcdplayer->play_item) );
391 input_Control( p_vcdplayer->p_input, INPUT_SET_NAME, psz_name );