comparison libao2/ao_sndio.c @ 36466:9824daf4a867

Simpler/more robust cleanup code.
author reimar
date Tue, 31 Dec 2013 15:31:15 +0000
parents 273702710048
children 645cbd086d2b
comparison
equal deleted inserted replaced
36465:273702710048 36466:9824daf4a867
110 par.pchan = channels; 110 par.pchan = channels;
111 par.appbufsz = par.rate * 250 / 1000; /* 250ms buffer */ 111 par.appbufsz = par.rate * 250 / 1000; /* 250ms buffer */
112 par.round = par.rate * 10 / 1000; /* 10ms block size */ 112 par.round = par.rate * 10 / 1000; /* 10ms block size */
113 if (!sio_setpar(hdl, &par)) { 113 if (!sio_setpar(hdl, &par)) {
114 mp_msg(MSGT_AO, MSGL_ERR, "ao2: couldn't set params\n"); 114 mp_msg(MSGT_AO, MSGL_ERR, "ao2: couldn't set params\n");
115 goto bad_close; 115 goto err_out;
116 } 116 }
117 if (!sio_getpar(hdl, &par)) { 117 if (!sio_getpar(hdl, &par)) {
118 mp_msg(MSGT_AO, MSGL_ERR, "ao2: couldn't get params\n"); 118 mp_msg(MSGT_AO, MSGL_ERR, "ao2: couldn't get params\n");
119 goto bad_close; 119 goto err_out;
120 } 120 }
121 if (par.bps != SIO_BPS(par.bits)) { 121 if (par.bps != SIO_BPS(par.bits)) {
122 mp_msg(MSGT_AO, MSGL_ERR, "ao2: unsupported format\n"); 122 mp_msg(MSGT_AO, MSGL_ERR, "ao2: unsupported format\n");
123 goto bad_close; 123 goto err_out;
124 } 124 }
125 pfds = calloc(sio_nfds(hdl), sizeof(*pfds)); 125 pfds = calloc(sio_nfds(hdl), sizeof(*pfds));
126 if (pfds == NULL) { 126 if (pfds == NULL) {
127 mp_msg(MSGT_AO, MSGL_ERR, "ao2: couldn't allocate poll fds\n"); 127 mp_msg(MSGT_AO, MSGL_ERR, "ao2: couldn't allocate poll fds\n");
128 goto bad_close; 128 goto err_out;
129 } 129 }
130 bpf = par.bps * par.pchan; 130 bpf = par.bps * par.pchan;
131 ao_data.format = af_bits2fmt(8 * par.bps); 131 ao_data.format = af_bits2fmt(8 * par.bps);
132 ao_data.format |= par.sig ? AF_FORMAT_SI : AF_FORMAT_US; 132 ao_data.format |= par.sig ? AF_FORMAT_SI : AF_FORMAT_US;
133 if (par.bits > 8) 133 if (par.bits > 8)
145 * data in the buffer to not underrun 145 * data in the buffer to not underrun
146 */ 146 */
147 delay = 0; 147 delay = 0;
148 if (!sio_start(hdl)) { 148 if (!sio_start(hdl)) {
149 mp_msg(MSGT_AO, MSGL_ERR, "ao2: init: couldn't start\n"); 149 mp_msg(MSGT_AO, MSGL_ERR, "ao2: init: couldn't start\n");
150 goto bad_free; 150 goto err_out;
151 } 151 }
152 return 1; 152 return 1;
153 bad_free: 153 err_out:
154 free(pfds); 154 free(pfds);
155 pfds = NULL; 155 pfds = NULL;
156 bad_close:
157 sio_close(hdl); 156 sio_close(hdl);
158 hdl = NULL; 157 hdl = NULL;
159 return 0; 158 return 0;
160 } 159 }
161 160
164 */ 163 */
165 static void uninit(int immed) 164 static void uninit(int immed)
166 { 165 {
167 if (hdl) 166 if (hdl)
168 sio_close(hdl); 167 sio_close(hdl);
169 if (pfds) 168 hdl = NULL;
170 free(pfds); 169 free(pfds);
170 pfds = NULL;
171 } 171 }
172 172
173 /* 173 /*
174 * stop playing and prepare to restart 174 * stop playing and prepare to restart
175 */ 175 */