Mercurial > mplayer.hg
annotate libao2/ao_sgi.c @ 15398:d023cd60d530
1.872: vf_detc parameter names fixed. (already in prev commit)
1.873: better explanation of N-pass encoding
author | kraymer |
---|---|
date | Tue, 10 May 2005 14:25:07 +0000 |
parents | d313f591d1a4 |
children | 27a2bc4aad72 |
rev | line source |
---|---|
2451 | 1 /* |
2 ao_sgi - sgi/irix output plugin for MPlayer | |
3 | |
4 22oct2001 oliver.schoenbrunner@jku.at | |
5 | |
6 */ | |
7 | |
8 #include <stdio.h> | |
9 #include <stdlib.h> | |
10 #include <dmedia/audio.h> | |
11 | |
12 #include "audio_out.h" | |
13 #include "audio_out_internal.h" | |
14123 | 14 #include "mp_msg.h" |
15 #include "help_mp.h" | |
2451 | 16 |
17 static ao_info_t info = | |
18 { | |
19 "sgi audio output", | |
20 "sgi", | |
13549 | 21 "Oliver Schoenbrunner", |
2451 | 22 "" |
23 }; | |
24 | |
25 LIBAO_EXTERN(sgi) | |
26 | |
27 | |
28 static ALconfig ao_config; | |
29 static ALport ao_port; | |
11323 | 30 static int sample_rate; |
31 static int queue_size; | |
2451 | 32 |
33 // to set/get/query special features/parameters | |
9633
12b1790038b0
64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents:
3095
diff
changeset
|
34 static int control(int cmd, void *arg){ |
2451 | 35 |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
36 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_SGI_INFO); |
2451 | 37 |
38 return -1; | |
39 } | |
40 | |
41 // open & setup audio device | |
42 // return: 1=success 0=fail | |
43 static int init(int rate, int channels, int format, int flags) { | |
14249 | 44 |
14264 | 45 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_SGI_InitInfo, rate, (channels > 1) ? "Stereo" : "Mono", af_fmt2str_short(format)); |
2451 | 46 |
47 { /* from /usr/share/src/dmedia/audio/setrate.c */ | |
48 | |
49 int fd; | |
50 int rv; | |
51 double frate; | |
52 ALpv x[2]; | |
53 | |
54 rv = alGetResourceByName(AL_SYSTEM, "out.analog", AL_DEVICE_TYPE); | |
55 if (!rv) { | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
56 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_SGI_InvalidDevice); |
2451 | 57 return 0; |
58 } | |
59 | |
60 frate = rate; | |
11323 | 61 |
2451 | 62 x[0].param = AL_RATE; |
63 x[0].value.ll = alDoubleToFixed(rate); | |
64 x[1].param = AL_MASTER_CLOCK; | |
65 x[1].value.i = AL_CRYSTAL_MCLK_TYPE; | |
66 | |
67 if (alSetParams(rv,x, 2)<0) { | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
68 mp_msg(MSGT_AO, MSGL_WARN, MSGTR_AO_SGI_CantSetParms_Samplerate, alGetErrorString(oserror())); |
2451 | 69 } |
70 | |
71 if (x[0].sizeOut < 0) { | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
72 mp_msg(MSGT_AO, MSGL_WARN, MSGTR_AO_SGI_CantSetAlRate); |
2451 | 73 } |
74 | |
75 if (alGetParams(rv,x, 1)<0) { | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
76 mp_msg(MSGT_AO, MSGL_WARN, MSGTR_AO_SGI_CantGetParms, alGetErrorString(oserror())); |
2451 | 77 } |
78 | |
79 if (frate != alFixedToDouble(x[0].value.ll)) { | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
80 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_SGI_SampleRateInfo, alFixedToDouble(x[0].value.ll), frate); |
2451 | 81 } |
11323 | 82 sample_rate = (int)frate; |
2451 | 83 } |
84 | |
3095 | 85 ao_data.buffersize=131072; |
86 ao_data.outburst = ao_data.buffersize/16; | |
87 ao_data.channels = channels; | |
2451 | 88 |
89 ao_config = alNewConfig(); | |
90 | |
91 if (!ao_config) { | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
92 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_SGI_InitConfigError, alGetErrorString(oserror())); |
2451 | 93 return 0; |
94 } | |
95 | |
96 if(channels == 2) alSetChannels(ao_config, AL_STEREO); | |
97 else alSetChannels(ao_config, AL_MONO); | |
98 | |
99 alSetWidth(ao_config, AL_SAMPLE_16); | |
100 alSetSampFmt(ao_config, AL_SAMPFMT_TWOSCOMP); | |
101 alSetQueueSize(ao_config, 48000); | |
102 | |
103 if (alSetDevice(ao_config, AL_DEFAULT_OUTPUT) < 0) { | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
104 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_SGI_InitConfigError, alGetErrorString(oserror())); |
2451 | 105 return 0; |
106 } | |
107 | |
108 ao_port = alOpenPort("mplayer", "w", ao_config); | |
109 | |
110 if (!ao_port) { | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
111 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_SGI_InitOpenAudioFailed, alGetErrorString(oserror())); |
2451 | 112 return 0; |
113 } | |
114 | |
115 // printf("ao_sgi, init: port %d config %d\n", ao_port, ao_config); | |
11323 | 116 queue_size = alGetQueueSize(ao_config); |
2451 | 117 return 1; |
118 | |
119 } | |
120 | |
121 // close audio device | |
12145 | 122 static void uninit(int immed) { |
2451 | 123 |
124 /* TODO: samplerate should be set back to the value before mplayer was started! */ | |
125 | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
126 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_SGI_Uninit); |
2451 | 127 |
128 if (ao_port) { | |
14849
d313f591d1a4
aos should respect the immed uninit flag (quit immediatly vs waiting till file
reimar
parents:
14264
diff
changeset
|
129 if (!immed) |
2451 | 130 while(alGetFilled(ao_port) > 0) sginap(1); |
131 alClosePort(ao_port); | |
132 alFreeConfig(ao_config); | |
133 } | |
134 | |
135 } | |
136 | |
137 // stop playing and empty buffers (for seeking/pause) | |
138 static void reset() { | |
139 | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
140 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_SGI_Reset); |
2451 | 141 |
142 } | |
143 | |
144 // stop playing, keep buffers (for pause) | |
145 static void audio_pause() { | |
146 | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
147 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_SGI_PauseInfo); |
2451 | 148 |
149 } | |
150 | |
151 // resume playing, after audio_pause() | |
152 static void audio_resume() { | |
153 | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
154 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_SGI_ResumeInfo); |
2451 | 155 |
156 } | |
157 | |
158 // return: how many bytes can be played without blocking | |
159 static int get_space() { | |
160 | |
161 // printf("ao_sgi, get_space: (ao_outburst %d)\n", ao_outburst); | |
162 // printf("ao_sgi, get_space: alGetFillable [%d] \n", alGetFillable(ao_port)); | |
163 | |
3095 | 164 return alGetFillable(ao_port)*(2*ao_data.channels); |
2451 | 165 |
166 } | |
167 | |
168 | |
169 // plays 'len' bytes of 'data' | |
170 // it should round it down to outburst*n | |
171 // return: number of bytes played | |
172 static int play(void* data, int len, int flags) { | |
173 | |
174 // printf("ao_sgi, play: len %d flags %d (%d %d)\n", len, flags, ao_port, ao_config); | |
175 // printf("channels %d\n", ao_channels); | |
176 | |
3095 | 177 alWriteFrames(ao_port, data, len/(2*ao_data.channels)); |
2451 | 178 |
179 return len; | |
180 | |
181 } | |
182 | |
3095 | 183 // return: delay in seconds between first and last sample in buffer |
184 static float get_delay(){ | |
2451 | 185 |
186 // printf("ao_sgi, get_delay: (ao_buffersize %d)\n", ao_buffersize); | |
187 | |
11323 | 188 //return 0; |
189 return (float)queue_size/((float)sample_rate); | |
2451 | 190 } |
191 | |
192 | |
193 | |
194 | |
195 | |
196 |