Mercurial > mplayer.hg
comparison libmpdemux/cdinfo.c @ 7430:4304d0980a62
Moved all the cdinfo specific from cddb to a standalone file, so
if no network, cdda can still be compiled.
author | bertrand |
---|---|
date | Tue, 17 Sep 2002 19:49:57 +0000 |
parents | |
children | 32e2c59c8e86 |
comparison
equal
deleted
inserted
replaced
7429:7a221aaf7012 | 7430:4304d0980a62 |
---|---|
1 /* | |
2 * CD Info | |
3 * by Bertrand Baudet <bertrand_baudet@yahoo.com> | |
4 * (C) 2002, MPlayer team. | |
5 */ | |
6 | |
7 #include "config.h" | |
8 | |
9 #if defined(HAVE_CDDA) | |
10 | |
11 #include <stdio.h> | |
12 #include <stdlib.h> | |
13 #include <string.h> | |
14 | |
15 #include "cdd.h" | |
16 | |
17 /******************************************************************************************************************* | |
18 * | |
19 * xmcd parser, cd info list | |
20 * | |
21 *******************************************************************************************************************/ | |
22 | |
23 cd_info_t* | |
24 cd_info_new() { | |
25 cd_info_t *cd_info = NULL; | |
26 | |
27 cd_info = (cd_info_t*)malloc(sizeof(cd_info_t)); | |
28 if( cd_info==NULL ) { | |
29 printf("Memory allocation failed\n"); | |
30 return NULL; | |
31 } | |
32 | |
33 memset(cd_info, 0, sizeof(cd_info_t)); | |
34 | |
35 return cd_info; | |
36 } | |
37 | |
38 void | |
39 cd_info_free(cd_info_t *cd_info) { | |
40 cd_track_t *cd_track, *cd_track_next; | |
41 if( cd_info==NULL ) return; | |
42 if( cd_info->artist!=NULL ) free(cd_info->artist); | |
43 if( cd_info->album!=NULL ) free(cd_info->album); | |
44 if( cd_info->genre!=NULL ) free(cd_info->genre); | |
45 | |
46 cd_track_next = cd_info->first; | |
47 while( cd_track_next!=NULL ) { | |
48 cd_track = cd_track_next; | |
49 cd_track_next = cd_track->next; | |
50 if( cd_track->name!=NULL ) free(cd_track->name); | |
51 free(cd_track); | |
52 } | |
53 } | |
54 | |
55 cd_track_t* | |
56 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) { | |
57 cd_track_t *cd_track; | |
58 | |
59 if( cd_info==NULL || track_name==NULL ) return NULL; | |
60 | |
61 cd_track = (cd_track_t*)malloc(sizeof(cd_track_t)); | |
62 if( cd_track==NULL ) { | |
63 printf("Memory allocation failed\n"); | |
64 return NULL; | |
65 } | |
66 memset(cd_track, 0, sizeof(cd_track_t)); | |
67 | |
68 cd_track->name = (char*)malloc(strlen(track_name)+1); | |
69 if( cd_track->name==NULL ) { | |
70 printf("Memory allocation failed\n"); | |
71 free(cd_track); | |
72 return NULL; | |
73 } | |
74 strcpy(cd_track->name, track_name); | |
75 cd_track->track_nb = track_nb; | |
76 cd_track->min = min; | |
77 cd_track->sec = sec; | |
78 cd_track->msec = msec; | |
79 cd_track->frame_begin = frame_begin; | |
80 cd_track->frame_length = frame_length; | |
81 | |
82 if( cd_info->first==NULL ) { | |
83 cd_info->first = cd_track; | |
84 } | |
85 if( cd_info->last!=NULL ) { | |
86 cd_info->last->next = cd_track; | |
87 } | |
88 | |
89 cd_track->prev = cd_info->last; | |
90 | |
91 cd_info->last = cd_track; | |
92 cd_info->current = cd_track; | |
93 | |
94 cd_info->nb_tracks++; | |
95 | |
96 return cd_track; | |
97 } | |
98 | |
99 cd_track_t* | |
100 cd_info_get_track(cd_info_t *cd_info, unsigned int track_nb) { | |
101 cd_track_t *cd_track=NULL; | |
102 | |
103 if( cd_info==NULL ) return NULL; | |
104 | |
105 cd_track = cd_info->first; | |
106 while( cd_track!=NULL ) { | |
107 if( cd_track->track_nb==track_nb ) { | |
108 return cd_track; | |
109 } | |
110 cd_track = cd_track->next; | |
111 } | |
112 return NULL; | |
113 } | |
114 | |
115 void | |
116 cd_info_debug(cd_info_t *cd_info) { | |
117 cd_track_t *current_track; | |
118 printf("================ CD INFO === start =========\n"); | |
119 if( cd_info==NULL ) { | |
120 printf("cd_info is NULL\n"); | |
121 return; | |
122 } | |
123 printf(" artist=[%s]\n", cd_info->artist); | |
124 printf(" album=[%s]\n", cd_info->album); | |
125 printf(" genre=[%s]\n", cd_info->genre); | |
126 printf(" nb_tracks=%d\n", cd_info->nb_tracks); | |
127 printf(" length= %2d:%02d.%02d\n", cd_info->min, cd_info->sec, cd_info->msec); | |
128 current_track = cd_info->first; | |
129 while( current_track!=NULL ) { | |
130 printf(" #%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); | |
131 current_track = current_track->next; | |
132 } | |
133 printf("================ CD INFO === end =========\n"); | |
134 } | |
135 | |
136 #endif |