Translation system changes part 2: replace macros by strings
[mplayer.git] / stream / cdinfo.c
blob48e970c72b0cd60e74acd117c7abca15085f3ed7
1 /*
2 * CD Info
3 * by Bertrand Baudet <bertrand_baudet@yahoo.com>
4 * (C) 2002, MPlayer team.
5 */
7 #include "config.h"
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include "mp_msg.h"
13 #include "help_mp.h"
14 #include "cdd.h"
16 /*******************************************************************************************************************
18 * xmcd parser, cd info list
20 *******************************************************************************************************************/
22 cd_info_t*
23 cd_info_new(void) {
24 cd_info_t *cd_info = NULL;
26 cd_info = malloc(sizeof(cd_info_t));
27 if( cd_info==NULL ) {
28 mp_tmsg(MSGT_DEMUX, MSGL_ERR, "Memory allocation failed.\n");
29 return NULL;
32 memset(cd_info, 0, sizeof(cd_info_t));
34 return cd_info;
37 void
38 cd_info_free(cd_info_t *cd_info) {
39 cd_track_t *cd_track, *cd_track_next;
40 if( cd_info==NULL ) return;
41 if( cd_info->artist!=NULL ) free(cd_info->artist);
42 if( cd_info->album!=NULL ) free(cd_info->album);
43 if( cd_info->genre!=NULL ) free(cd_info->genre);
45 cd_track_next = cd_info->first;
46 while( cd_track_next!=NULL ) {
47 cd_track = cd_track_next;
48 cd_track_next = cd_track->next;
49 if( cd_track->name!=NULL ) free(cd_track->name);
50 free(cd_track);
54 cd_track_t*
55 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) {
56 cd_track_t *cd_track;
58 if( cd_info==NULL || track_name==NULL ) return NULL;
60 cd_track = malloc(sizeof(cd_track_t));
61 if( cd_track==NULL ) {
62 mp_tmsg(MSGT_DEMUX, MSGL_ERR, "Memory allocation failed.\n");
63 return NULL;
65 memset(cd_track, 0, sizeof(cd_track_t));
67 cd_track->name = malloc(strlen(track_name)+1);
68 if( cd_track->name==NULL ) {
69 mp_tmsg(MSGT_DEMUX, MSGL_ERR, "Memory allocation failed.\n");
70 free(cd_track);
71 return NULL;
73 strcpy(cd_track->name, track_name);
74 cd_track->track_nb = track_nb;
75 cd_track->min = min;
76 cd_track->sec = sec;
77 cd_track->msec = msec;
78 cd_track->frame_begin = frame_begin;
79 cd_track->frame_length = frame_length;
81 if( cd_info->first==NULL ) {
82 cd_info->first = cd_track;
84 if( cd_info->last!=NULL ) {
85 cd_info->last->next = cd_track;
88 cd_track->prev = cd_info->last;
90 cd_info->last = cd_track;
91 cd_info->current = cd_track;
93 cd_info->nb_tracks++;
95 return cd_track;
98 cd_track_t*
99 cd_info_get_track(cd_info_t *cd_info, unsigned int track_nb) {
100 cd_track_t *cd_track=NULL;
102 if( cd_info==NULL ) return NULL;
104 cd_track = cd_info->first;
105 while( cd_track!=NULL ) {
106 if( cd_track->track_nb==track_nb ) {
107 return cd_track;
109 cd_track = cd_track->next;
111 return NULL;
114 void
115 cd_info_debug(cd_info_t *cd_info) {
116 cd_track_t *current_track;
117 mp_msg(MSGT_DEMUX, MSGL_INFO, "================ CD INFO === start =========\n");
118 if( cd_info==NULL ) {
119 mp_msg(MSGT_DEMUX, MSGL_INFO, "cd_info is NULL\n");
120 return;
122 mp_msg(MSGT_DEMUX, MSGL_INFO, " artist=[%s]\n", cd_info->artist);
123 mp_msg(MSGT_DEMUX, MSGL_INFO, " album=[%s]\n", cd_info->album);
124 mp_msg(MSGT_DEMUX, MSGL_INFO, " genre=[%s]\n", cd_info->genre);
125 mp_msg(MSGT_DEMUX, MSGL_INFO, " nb_tracks=%d\n", cd_info->nb_tracks);
126 mp_msg(MSGT_DEMUX, MSGL_INFO, " length= %2d:%02d.%02d\n", cd_info->min, cd_info->sec, cd_info->msec);
128 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CDDB_INFO_ARTIST=%s\n", cd_info->artist);
129 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CDDB_INFO_ALBUM=%s\n", cd_info->album);
130 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CDDB_INFO_GENRE=%s\n", cd_info->genre);
131 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CDDB_INFO_LENGTH_MSF=%02d:%02d.%02d\n", cd_info->min, cd_info->sec, cd_info->msec);
132 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CDDB_INFO_TRACKS=%d\n", cd_info->nb_tracks);
134 current_track = cd_info->first;
135 while( current_track!=NULL ) {
136 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);
137 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CDDB_INFO_TRACK_%d_NAME=%s\n", current_track->track_nb, current_track->name);
138 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);
139 current_track = current_track->next;
141 mp_msg(MSGT_DEMUX, MSGL_INFO, "================ CD INFO === end =========\n");