vo_corevideo.h: Add standard multiple inclusion guards
[mplayer/glamo.git] / stream / cdinfo.c
blobcc42bf11e4deff6cefd9be388b4c5d03fdb5fe1a
1 /*
2 * CD Info
4 * Copyright (C) 2002 Bertrand Baudet <bertrand_baudet@yahoo.com>
6 * This file is part of MPlayer.
8 * MPlayer is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * MPlayer is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "config.h"
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include "mp_msg.h"
29 #include "cdd.h"
31 /*******************************************************************************************************************
33 * xmcd parser, cd info list
35 *******************************************************************************************************************/
37 cd_info_t*
38 cd_info_new(void) {
39 cd_info_t *cd_info = NULL;
41 cd_info = malloc(sizeof(cd_info_t));
42 if( cd_info==NULL ) {
43 mp_tmsg(MSGT_DEMUX, MSGL_ERR, "Memory allocation failed.\n");
44 return NULL;
47 memset(cd_info, 0, sizeof(cd_info_t));
49 return cd_info;
52 void
53 cd_info_free(cd_info_t *cd_info) {
54 cd_track_t *cd_track, *cd_track_next;
55 if( cd_info==NULL ) return;
56 if( cd_info->artist!=NULL ) free(cd_info->artist);
57 if( cd_info->album!=NULL ) free(cd_info->album);
58 if( cd_info->genre!=NULL ) free(cd_info->genre);
60 cd_track_next = cd_info->first;
61 while( cd_track_next!=NULL ) {
62 cd_track = cd_track_next;
63 cd_track_next = cd_track->next;
64 if( cd_track->name!=NULL ) free(cd_track->name);
65 free(cd_track);
69 cd_track_t*
70 cd_info_add_track(cd_info_t *cd_info, char *track_name, unsigned int track_nb, unsigned int min, unsigned int sec, unsigned int msec, unsigned long frame_begin, unsigned long frame_length) {
71 cd_track_t *cd_track;
73 if( cd_info==NULL || track_name==NULL ) return NULL;
75 cd_track = malloc(sizeof(cd_track_t));
76 if( cd_track==NULL ) {
77 mp_tmsg(MSGT_DEMUX, MSGL_ERR, "Memory allocation failed.\n");
78 return NULL;
80 memset(cd_track, 0, sizeof(cd_track_t));
82 cd_track->name = malloc(strlen(track_name)+1);
83 if( cd_track->name==NULL ) {
84 mp_tmsg(MSGT_DEMUX, MSGL_ERR, "Memory allocation failed.\n");
85 free(cd_track);
86 return NULL;
88 strcpy(cd_track->name, track_name);
89 cd_track->track_nb = track_nb;
90 cd_track->min = min;
91 cd_track->sec = sec;
92 cd_track->msec = msec;
93 cd_track->frame_begin = frame_begin;
94 cd_track->frame_length = frame_length;
96 if( cd_info->first==NULL ) {
97 cd_info->first = cd_track;
99 if( cd_info->last!=NULL ) {
100 cd_info->last->next = cd_track;
103 cd_track->prev = cd_info->last;
105 cd_info->last = cd_track;
106 cd_info->current = cd_track;
108 cd_info->nb_tracks++;
110 return cd_track;
113 cd_track_t*
114 cd_info_get_track(cd_info_t *cd_info, unsigned int track_nb) {
115 cd_track_t *cd_track=NULL;
117 if( cd_info==NULL ) return NULL;
119 cd_track = cd_info->first;
120 while( cd_track!=NULL ) {
121 if( cd_track->track_nb==track_nb ) {
122 return cd_track;
124 cd_track = cd_track->next;
126 return NULL;
129 void
130 cd_info_debug(cd_info_t *cd_info) {
131 cd_track_t *current_track;
132 mp_msg(MSGT_DEMUX, MSGL_INFO, "================ CD INFO === start =========\n");
133 if( cd_info==NULL ) {
134 mp_msg(MSGT_DEMUX, MSGL_INFO, "cd_info is NULL\n");
135 return;
137 mp_msg(MSGT_DEMUX, MSGL_INFO, " artist=[%s]\n", cd_info->artist);
138 mp_msg(MSGT_DEMUX, MSGL_INFO, " album=[%s]\n", cd_info->album);
139 mp_msg(MSGT_DEMUX, MSGL_INFO, " genre=[%s]\n", cd_info->genre);
140 mp_msg(MSGT_DEMUX, MSGL_INFO, " nb_tracks=%d\n", cd_info->nb_tracks);
141 mp_msg(MSGT_DEMUX, MSGL_INFO, " length= %2d:%02d.%02d\n", cd_info->min, cd_info->sec, cd_info->msec);
143 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CDDB_INFO_ARTIST=%s\n", cd_info->artist);
144 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CDDB_INFO_ALBUM=%s\n", cd_info->album);
145 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CDDB_INFO_GENRE=%s\n", cd_info->genre);
146 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CDDB_INFO_LENGTH_MSF=%02d:%02d.%02d\n", cd_info->min, cd_info->sec, cd_info->msec);
147 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CDDB_INFO_TRACKS=%d\n", cd_info->nb_tracks);
149 current_track = cd_info->first;
150 while( current_track!=NULL ) {
151 mp_msg(MSGT_DEMUX, MSGL_INFO, " #%2d %2d:%02d.%02d @ %7ld\t[%s] \n", current_track->track_nb, current_track->min, current_track->sec, current_track->msec, current_track->frame_begin, current_track->name);
152 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CDDB_INFO_TRACK_%d_NAME=%s\n", current_track->track_nb, current_track->name);
153 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CDDB_INFO_TRACK_%d_MSF=%02d:%02d.%02d\n", current_track->track_nb, current_track->min, current_track->sec, current_track->msec);
154 current_track = current_track->next;
156 mp_msg(MSGT_DEMUX, MSGL_INFO, "================ CD INFO === end =========\n");