annotate stream/cdinfo.c @ 25630:bdb0a9df0025

Codecdata must always be malloc'd, fixes free being called with an invalid pointer when freeing codecdata.
author reimar
date Wed, 09 Jan 2008 07:18:14 +0000
parents 0cbea23f0628
children 663103eea455
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7430
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
1 /*
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
2 * CD Info
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
3 * by Bertrand Baudet <bertrand_baudet@yahoo.com>
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
4 * (C) 2002, MPlayer team.
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
5 */
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
6
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
7 #include "config.h"
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
8
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
9 #include <stdio.h>
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
10 #include <stdlib.h>
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
11 #include <string.h>
16967
32e2c59c8e86 [TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents: 7430
diff changeset
12 #include "mp_msg.h"
32e2c59c8e86 [TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents: 7430
diff changeset
13 #include "help_mp.h"
7430
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
14 #include "cdd.h"
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
15
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
16 /*******************************************************************************************************************
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
17 *
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
18 * xmcd parser, cd info list
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
19 *
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
20 *******************************************************************************************************************/
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
21
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
22 cd_info_t*
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
23 cd_info_new() {
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
24 cd_info_t *cd_info = NULL;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
25
19062
83c3afeab35d drops casts from void * on malloc/calloc from libmpdemux code
reynaldo
parents: 16967
diff changeset
26 cd_info = malloc(sizeof(cd_info_t));
7430
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
27 if( cd_info==NULL ) {
16967
32e2c59c8e86 [TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents: 7430
diff changeset
28 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MemAllocFailed);
7430
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
29 return NULL;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
30 }
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
31
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
32 memset(cd_info, 0, sizeof(cd_info_t));
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
33
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
34 return cd_info;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
35 }
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
36
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
37 void
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
38 cd_info_free(cd_info_t *cd_info) {
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
39 cd_track_t *cd_track, *cd_track_next;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
40 if( cd_info==NULL ) return;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
41 if( cd_info->artist!=NULL ) free(cd_info->artist);
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
42 if( cd_info->album!=NULL ) free(cd_info->album);
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
43 if( cd_info->genre!=NULL ) free(cd_info->genre);
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
44
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
45 cd_track_next = cd_info->first;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
46 while( cd_track_next!=NULL ) {
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
47 cd_track = cd_track_next;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
48 cd_track_next = cd_track->next;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
49 if( cd_track->name!=NULL ) free(cd_track->name);
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
50 free(cd_track);
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
51 }
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
52 }
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
53
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
54 cd_track_t*
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
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) {
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
56 cd_track_t *cd_track;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
57
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
58 if( cd_info==NULL || track_name==NULL ) return NULL;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
59
19062
83c3afeab35d drops casts from void * on malloc/calloc from libmpdemux code
reynaldo
parents: 16967
diff changeset
60 cd_track = malloc(sizeof(cd_track_t));
7430
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
61 if( cd_track==NULL ) {
16967
32e2c59c8e86 [TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents: 7430
diff changeset
62 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MemAllocFailed);
7430
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
63 return NULL;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
64 }
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
65 memset(cd_track, 0, sizeof(cd_track_t));
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
66
19062
83c3afeab35d drops casts from void * on malloc/calloc from libmpdemux code
reynaldo
parents: 16967
diff changeset
67 cd_track->name = malloc(strlen(track_name)+1);
7430
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
68 if( cd_track->name==NULL ) {
16967
32e2c59c8e86 [TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents: 7430
diff changeset
69 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MemAllocFailed);
7430
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
70 free(cd_track);
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
71 return NULL;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
72 }
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
73 strcpy(cd_track->name, track_name);
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
74 cd_track->track_nb = track_nb;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
75 cd_track->min = min;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
76 cd_track->sec = sec;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
77 cd_track->msec = msec;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
78 cd_track->frame_begin = frame_begin;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
79 cd_track->frame_length = frame_length;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
80
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
81 if( cd_info->first==NULL ) {
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
82 cd_info->first = cd_track;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
83 }
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
84 if( cd_info->last!=NULL ) {
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
85 cd_info->last->next = cd_track;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
86 }
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
87
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
88 cd_track->prev = cd_info->last;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
89
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
90 cd_info->last = cd_track;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
91 cd_info->current = cd_track;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
92
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
93 cd_info->nb_tracks++;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
94
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
95 return cd_track;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
96 }
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
97
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
98 cd_track_t*
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
99 cd_info_get_track(cd_info_t *cd_info, unsigned int track_nb) {
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
100 cd_track_t *cd_track=NULL;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
101
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
102 if( cd_info==NULL ) return NULL;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
103
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
104 cd_track = cd_info->first;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
105 while( cd_track!=NULL ) {
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
106 if( cd_track->track_nb==track_nb ) {
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
107 return cd_track;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
108 }
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
109 cd_track = cd_track->next;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
110 }
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
111 return NULL;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
112 }
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
113
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
114 void
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
115 cd_info_debug(cd_info_t *cd_info) {
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
116 cd_track_t *current_track;
25374
0cbea23f0628 Replace printf with mp_msg.
ulion
parents: 19287
diff changeset
117 mp_msg(MSGT_DEMUX, MSGL_INFO, "================ CD INFO === start =========\n");
7430
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
118 if( cd_info==NULL ) {
25374
0cbea23f0628 Replace printf with mp_msg.
ulion
parents: 19287
diff changeset
119 mp_msg(MSGT_DEMUX, MSGL_INFO, "cd_info is NULL\n");
7430
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
120 return;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
121 }
25374
0cbea23f0628 Replace printf with mp_msg.
ulion
parents: 19287
diff changeset
122 mp_msg(MSGT_DEMUX, MSGL_INFO, " artist=[%s]\n", cd_info->artist);
0cbea23f0628 Replace printf with mp_msg.
ulion
parents: 19287
diff changeset
123 mp_msg(MSGT_DEMUX, MSGL_INFO, " album=[%s]\n", cd_info->album);
0cbea23f0628 Replace printf with mp_msg.
ulion
parents: 19287
diff changeset
124 mp_msg(MSGT_DEMUX, MSGL_INFO, " genre=[%s]\n", cd_info->genre);
0cbea23f0628 Replace printf with mp_msg.
ulion
parents: 19287
diff changeset
125 mp_msg(MSGT_DEMUX, MSGL_INFO, " nb_tracks=%d\n", cd_info->nb_tracks);
0cbea23f0628 Replace printf with mp_msg.
ulion
parents: 19287
diff changeset
126 mp_msg(MSGT_DEMUX, MSGL_INFO, " length= %2d:%02d.%02d\n", cd_info->min, cd_info->sec, cd_info->msec);
7430
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
127 current_track = cd_info->first;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
128 while( current_track!=NULL ) {
25374
0cbea23f0628 Replace printf with mp_msg.
ulion
parents: 19287
diff changeset
129 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);
7430
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
130 current_track = current_track->next;
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
131 }
25374
0cbea23f0628 Replace printf with mp_msg.
ulion
parents: 19287
diff changeset
132 mp_msg(MSGT_DEMUX, MSGL_INFO, "================ CD INFO === end =========\n");
7430
4304d0980a62 Moved all the cdinfo specific from cddb to a standalone file, so
bertrand
parents:
diff changeset
133 }