2645
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
2770
|
3
|
2921
|
4 #include <linux/em8300.h>
|
2770
|
5 #include <sys/ioctl.h>
|
2645
|
6 #include <unistd.h>
|
2770
|
7 #include <sys/time.h>
|
2645
|
8 #include <sys/types.h>
|
2770
|
9 #include <sys/stat.h>
|
|
10 #include <fcntl.h>
|
2645
|
11
|
|
12 #include "../config.h"
|
|
13
|
|
14 #include "afmt.h"
|
|
15
|
|
16 #include "audio_out.h"
|
|
17 #include "audio_out_internal.h"
|
|
18
|
2770
|
19 extern int verbose;
|
2645
|
20
|
|
21 static ao_info_t info =
|
|
22 {
|
|
23 "DXR3/H+ audio out",
|
|
24 "dxr3",
|
|
25 "David Holm <dholm@iname.com>",
|
|
26 ""
|
|
27 };
|
|
28
|
|
29 LIBAO_EXTERN(dxr3)
|
|
30
|
|
31 // there are some globals:
|
|
32 // ao_samplerate
|
|
33 // ao_channels
|
|
34 // ao_format
|
|
35 // ao_bps
|
|
36 // ao_outburst
|
|
37 // ao_buffersize
|
|
38
|
2921
|
39 //static char *em8300_ma="/dev/em8300_ma";
|
2770
|
40 static audio_buf_info dxr3_buf_info;
|
2921
|
41 static int fd_control = 0, fd_audio = 0;
|
2770
|
42
|
2645
|
43 // to set/get/query special features/parameters
|
|
44 static int control(int cmd,int arg)
|
|
45 {
|
|
46 switch(cmd)
|
|
47 {
|
|
48 case AOCONTROL_QUERY_FORMAT:
|
|
49 return CONTROL_TRUE;
|
|
50 case AOCONTROL_GET_VOLUME:
|
|
51 case AOCONTROL_SET_VOLUME:
|
2770
|
52 return CONTROL_OK;
|
|
53 return CONTROL_ERROR;
|
2645
|
54 }
|
2770
|
55 return CONTROL_UNKNOWN;
|
2645
|
56 }
|
|
57
|
|
58 // open & setup audio device
|
|
59 // return: 1=success 0=fail
|
|
60 static int init(int rate,int channels,int format,int flags)
|
|
61 {
|
2921
|
62 int ioval;
|
|
63 fd_audio = open( "/dev/em8300_ma", O_WRONLY );
|
|
64 if( fd_audio < 0 )
|
|
65 {
|
|
66 printf("Can't open audio device /dev/em8300_ma -> nosound\n");
|
|
67 return 0;
|
|
68 }
|
2770
|
69
|
2921
|
70 fd_control = open( "/dev/em8300", O_WRONLY );
|
|
71 if( fd_control < 0 )
|
2770
|
72 {
|
2921
|
73 printf("Can't open em8300 control /dev/em8300\n");
|
2770
|
74 return 0;
|
|
75 }
|
|
76
|
|
77 ao_format = format;
|
2921
|
78 ioctl (fd_audio, SNDCTL_DSP_SETFMT, &ao_format);
|
2770
|
79 if(format == AFMT_AC3 && ao_format != AFMT_AC3)
|
|
80 {
|
2921
|
81 printf("Can't set audio device /dev/em8300_ma to AC3 output\n");
|
2770
|
82 return 0;
|
|
83 }
|
|
84 printf("audio_setup: sample format: %s (requested: %s)\n",
|
|
85 audio_out_format_name(ao_format), audio_out_format_name(format));
|
|
86
|
|
87 if(format != AFMT_AC3)
|
|
88 {
|
|
89 ao_channels=channels-1;
|
2921
|
90 ioctl (fd_audio, SNDCTL_DSP_STEREO, &ao_channels);
|
2770
|
91
|
|
92 // set rate
|
|
93 ao_samplerate=rate;
|
2921
|
94 ioctl (fd_audio, SNDCTL_DSP_SPEED, &ao_samplerate);
|
2770
|
95 printf("audio_setup: using %d Hz samplerate (requested: %d)\n",ao_samplerate,rate);
|
|
96 }
|
|
97
|
2921
|
98 if(ioctl(fd_audio, SNDCTL_DSP_GETOSPACE, &dxr3_buf_info)==-1){
|
2770
|
99 int r=0;
|
|
100 printf("audio_setup: driver doesn't support SNDCTL_DSP_GETOSPACE :-(\n");
|
2921
|
101 if(ioctl(fd_audio, SNDCTL_DSP_GETBLKSIZE, &r)==-1){
|
2770
|
102 printf("audio_setup: %d bytes/frag (config.h)\n",ao_outburst);
|
|
103 } else {
|
|
104 ao_outburst=r;
|
|
105 printf("audio_setup: %d bytes/frag (GETBLKSIZE)\n",ao_outburst);
|
|
106 }
|
|
107 } else {
|
|
108 printf("audio_setup: frags: %3d/%d (%d bytes/frag) free: %6d\n",
|
|
109 dxr3_buf_info.fragments, dxr3_buf_info.fragstotal, dxr3_buf_info.fragsize, dxr3_buf_info.bytes);
|
|
110 if(ao_buffersize==-1) ao_buffersize=dxr3_buf_info.bytes;
|
|
111 ao_outburst=dxr3_buf_info.fragsize;
|
|
112 }
|
|
113
|
|
114 if(ao_buffersize==-1){
|
|
115 // Measuring buffer size:
|
|
116 void* data;
|
|
117 ao_buffersize=0;
|
|
118 #ifdef HAVE_AUDIO_SELECT
|
|
119 data=malloc(ao_outburst); memset(data,0,ao_outburst);
|
|
120 while(ao_buffersize<0x40000){
|
|
121 fd_set rfds;
|
|
122 struct timeval tv;
|
2921
|
123 FD_ZERO(&rfds); FD_SET(fd_audio,&rfds);
|
2770
|
124 tv.tv_sec=0; tv.tv_usec = 0;
|
2921
|
125 if(!select(fd_audio+1, NULL, &rfds, NULL, &tv)) break;
|
|
126 write(fd_audio,data,ao_outburst);
|
2770
|
127 ao_buffersize+=ao_outburst;
|
2645
|
128 }
|
2770
|
129 free(data);
|
|
130 if(ao_buffersize==0){
|
|
131 printf("\n *** Your audio driver DOES NOT support select() ***\n");
|
|
132 printf("Recompile mplayer with #undef HAVE_AUDIO_SELECT in config.h !\n\n");
|
|
133 return 0;
|
|
134 }
|
|
135 #endif
|
|
136 }
|
2645
|
137
|
2921
|
138 ioval = EM8300_PLAYMODE_PLAY;
|
|
139 ioctl( fd_control, EM8300_IOCTL_SET_PLAYMODE, &ioval );
|
|
140 close( fd_control );
|
2770
|
141
|
|
142 return 1;
|
2645
|
143 }
|
|
144
|
|
145 // close audio device
|
|
146 static void uninit()
|
|
147 {
|
2921
|
148 ioctl(fd_audio, SNDCTL_DSP_RESET, NULL);
|
|
149 close( fd_audio );
|
2645
|
150 }
|
|
151
|
|
152 // stop playing and empty buffers (for seeking/pause)
|
|
153 static void reset()
|
|
154 {
|
|
155 uninit();
|
2921
|
156 if(fd_audio<0)
|
2770
|
157 {
|
2645
|
158 printf("\nFatal error: *** CANNOT RE-OPEN / RESET AUDIO DEVICE ***\n");
|
2770
|
159 return;
|
|
160 }
|
|
161
|
2921
|
162 ioctl (fd_audio, SNDCTL_DSP_SETFMT, &ao_format);
|
2770
|
163 if(ao_format != AFMT_AC3)
|
|
164 {
|
2921
|
165 ioctl (fd_audio, SNDCTL_DSP_STEREO, &ao_channels);
|
|
166 ioctl (fd_audio, SNDCTL_DSP_SPEED, &ao_samplerate);
|
2770
|
167 }
|
2645
|
168 }
|
|
169
|
|
170 // stop playing, keep buffers (for pause)
|
|
171 static void audio_pause()
|
|
172 {
|
|
173 // for now, just call reset();
|
|
174 reset();
|
|
175 }
|
|
176
|
|
177 // resume playing, after audio_pause()
|
|
178 static void audio_resume()
|
|
179 {
|
|
180 }
|
|
181
|
|
182
|
|
183 // return: how many bytes can be played without blocking
|
|
184 static int get_space()
|
|
185 {
|
2921
|
186 if(ioctl(fd_audio, SNDCTL_DSP_GETOSPACE, &dxr3_buf_info)!=-1)
|
2770
|
187 return (dxr3_buf_info.fragments*dxr3_buf_info.fragsize);
|
2921
|
188 return 0;
|
2645
|
189 }
|
|
190
|
|
191 static int play(void* data,int len,int flags)
|
|
192 {
|
2921
|
193 ioctl( fd_audio, EM8300_IOCTL_AUDIO_SETPTS, &ao_pts );
|
|
194 return write(fd_audio,data,len);
|
2645
|
195 }
|
|
196
|
|
197 // return: how many unplayed bytes are in the buffer
|
|
198 static int get_delay()
|
|
199 {
|
2770
|
200 int r=0;
|
2921
|
201 ioctl(fd_audio, SNDCTL_DSP_GETODELAY, &r);
|
|
202 return r;
|
2645
|
203 }
|
|
204
|