Mercurial > mplayer.hg
annotate libao2/ao_mpegpes.c @ 9286:1ffb2f7db3a0
sync
author | nicolas |
---|---|
date | Wed, 05 Feb 2003 21:00:36 +0000 |
parents | c9b1b73339da |
children | 382534a5a830 |
rev | line source |
---|---|
2708 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
7472
c4434bdf6e51
tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents:
7164
diff
changeset
|
3 #include <string.h> |
8594 | 4 #ifdef DVB_HEAD |
5 #define HAVE_DVB 1 | |
6 #endif | |
7 | |
6856 | 8 #ifdef HAVE_DVB |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
9 #include <sys/ioctl.h> |
6856 | 10 #endif |
2708 | 11 |
5060 | 12 #include "../config.h" |
13 | |
2708 | 14 #include "audio_out.h" |
15 #include "audio_out_internal.h" | |
16 | |
17 #include "afmt.h" | |
18 | |
7161 | 19 #include "../mp_msg.h" |
20 | |
4792 | 21 #ifdef HAVE_DVB |
8594 | 22 #ifndef HAVE_DVB_HEAD |
4792 | 23 #include <ost/audio.h> |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
24 audioMixer_t dvb_mixer={255,255}; |
8594 | 25 #else |
26 #include </linux/dvb/audio.h> | |
27 audio_mixer_t dvb_mixer={255,255}; | |
28 #endif | |
7609 | 29 #endif |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
30 extern int vo_mpegpes_fd; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
31 extern int vo_mpegpes_fd2; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
32 |
7164 | 33 #include <errno.h> |
34 | |
2708 | 35 static ao_info_t info = |
36 { | |
4792 | 37 #ifdef HAVE_DVB |
38 "DVB audio output", | |
39 #else | |
40 "Mpeg-PES audio output", | |
41 #endif | |
2708 | 42 "mpegpes", |
43 "A'rpi", | |
44 "" | |
45 }; | |
46 | |
47 LIBAO_EXTERN(mpegpes) | |
48 | |
49 | |
50 // to set/get/query special features/parameters | |
51 static int control(int cmd,int arg){ | |
4792 | 52 #ifdef HAVE_DVB |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
53 switch(cmd){ |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
54 case AOCONTROL_GET_VOLUME: |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
55 if(vo_mpegpes_fd2>=0){ |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
56 ((ao_control_vol_t*)(arg))->left=dvb_mixer.volume_left/2.56; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
57 ((ao_control_vol_t*)(arg))->right=dvb_mixer.volume_right/2.56; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
58 return CONTROL_OK; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
59 } |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
60 return CONTROL_ERROR; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
61 case AOCONTROL_SET_VOLUME: |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
62 if(vo_mpegpes_fd2>=0){ |
5060 | 63 dvb_mixer.volume_left=((ao_control_vol_t*)(arg))->left*2.56; |
64 dvb_mixer.volume_right=((ao_control_vol_t*)(arg))->right*2.56; | |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
65 if(dvb_mixer.volume_left>255) dvb_mixer.volume_left=255; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
66 if(dvb_mixer.volume_right>255) dvb_mixer.volume_right=255; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
67 // printf("Setting DVB volume: %d ; %d \n",dvb_mixer.volume_left,dvb_mixer.volume_right); |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
68 if ( (ioctl(vo_mpegpes_fd2,AUDIO_SET_MIXER, &dvb_mixer) < 0)){ |
7161 | 69 mp_msg(MSGT_AO, MSGL_ERR, "DVB audio set mixer failed: %s\n", |
70 strerror(errno)); | |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
71 return CONTROL_ERROR; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
72 } |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
73 return CONTROL_OK; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
74 } |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
75 return CONTROL_ERROR; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
76 } |
4792 | 77 #endif |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
78 return CONTROL_UNKNOWN; |
2708 | 79 } |
80 | |
4331 | 81 static int freq=0; |
4300
4ebab79785b7
passing samplerate to LPCM writer - 44, 32 and 96khz are also supported from now
arpi
parents:
3095
diff
changeset
|
82 static int freq_id=0; |
4ebab79785b7
passing samplerate to LPCM writer - 44, 32 and 96khz are also supported from now
arpi
parents:
3095
diff
changeset
|
83 |
2708 | 84 // open & setup audio device |
85 // return: 1=success 0=fail | |
86 static int init(int rate,int channels,int format,int flags){ | |
87 | |
7607 | 88 #ifdef HAVE_DVB |
89 if(vo_mpegpes_fd2<0) return 0; // couldn't open audio dev | |
90 #else | |
91 if(vo_mpegpes_fd<0) return 0; // no file | |
92 #endif | |
93 | |
94 ao_data.channels=2; | |
3095 | 95 ao_data.outburst=2000; |
7607 | 96 switch(format){ |
97 case AFMT_S16_LE: | |
98 case AFMT_S16_BE: | |
99 case AFMT_MPEG: | |
9265 | 100 case AFMT_AC3: |
7607 | 101 ao_data.format=format; |
102 break; | |
103 default: | |
104 ao_data.format=AFMT_S16_BE; | |
105 } | |
4300
4ebab79785b7
passing samplerate to LPCM writer - 44, 32 and 96khz are also supported from now
arpi
parents:
3095
diff
changeset
|
106 |
7607 | 107 retry: |
4300
4ebab79785b7
passing samplerate to LPCM writer - 44, 32 and 96khz are also supported from now
arpi
parents:
3095
diff
changeset
|
108 switch(rate){ |
4ebab79785b7
passing samplerate to LPCM writer - 44, 32 and 96khz are also supported from now
arpi
parents:
3095
diff
changeset
|
109 case 48000: freq_id=0;break; |
4ebab79785b7
passing samplerate to LPCM writer - 44, 32 and 96khz are also supported from now
arpi
parents:
3095
diff
changeset
|
110 case 96000: freq_id=1;break; |
4ebab79785b7
passing samplerate to LPCM writer - 44, 32 and 96khz are also supported from now
arpi
parents:
3095
diff
changeset
|
111 case 44100: freq_id=2;break; |
4ebab79785b7
passing samplerate to LPCM writer - 44, 32 and 96khz are also supported from now
arpi
parents:
3095
diff
changeset
|
112 case 32000: freq_id=3;break; |
4ebab79785b7
passing samplerate to LPCM writer - 44, 32 and 96khz are also supported from now
arpi
parents:
3095
diff
changeset
|
113 default: |
7607 | 114 mp_msg(MSGT_AO, MSGL_ERR, "ao_mpegpes: %d Hz not supported, try to resample...\n",rate); |
115 #if 0 | |
116 if(rate>48000) rate=96000; else | |
117 if(rate>44100) rate=48000; else | |
118 if(rate>32000) rate=44100; else | |
119 rate=32000; | |
120 goto retry; | |
121 #else | |
122 rate=48000; freq_id=0; | |
123 #endif | |
4300
4ebab79785b7
passing samplerate to LPCM writer - 44, 32 and 96khz are also supported from now
arpi
parents:
3095
diff
changeset
|
124 } |
2708 | 125 |
7607 | 126 ao_data.bps=rate*2*2; |
127 freq=ao_data.samplerate=rate; | |
128 | |
2708 | 129 return 1; |
130 } | |
131 | |
132 // close audio device | |
133 static void uninit(){ | |
134 | |
135 } | |
136 | |
137 // stop playing and empty buffers (for seeking/pause) | |
138 static void reset(){ | |
139 | |
140 } | |
141 | |
142 // stop playing, keep buffers (for pause) | |
143 static void audio_pause() | |
144 { | |
145 // for now, just call reset(); | |
146 reset(); | |
147 } | |
148 | |
149 // resume playing, after audio_pause() | |
150 static void audio_resume() | |
151 { | |
152 } | |
153 | |
154 void send_pes_packet(unsigned char* data,int len,int id,int timestamp); | |
4300
4ebab79785b7
passing samplerate to LPCM writer - 44, 32 and 96khz are also supported from now
arpi
parents:
3095
diff
changeset
|
155 void send_lpcm_packet(unsigned char* data,int len,int id,int timestamp,int freq_id); |
2708 | 156 extern int vo_pts; |
157 | |
158 // return: how many bytes can be played without blocking | |
159 static int get_space(){ | |
4331 | 160 float x=(float)(vo_pts-ao_data.pts)/90000.0; |
2708 | 161 int y; |
7607 | 162 // printf("vo_pts: %5.3f ao_pts: %5.3f\n",vo_pts/90000.0,ao_data.pts/90000.0); |
2708 | 163 if(x<=0) return 0; |
4331 | 164 y=freq*4*x;y/=ao_data.outburst;y*=ao_data.outburst; |
165 if(y>32000) y=32000; | |
2708 | 166 // printf("diff: %5.3f -> %d \n",x,y); |
167 return y; | |
168 } | |
169 | |
170 // plays 'len' bytes of 'data' | |
171 // it should round it down to outburst*n | |
172 // return: number of bytes played | |
173 static int play(void* data,int len,int flags){ | |
7607 | 174 // printf("\nao_mpegpes: play(%d) freq=%d\n",len,freq_id); |
3095 | 175 if(ao_data.format==AFMT_MPEG) |
176 send_pes_packet(data,len,0x1C0,ao_data.pts); | |
2708 | 177 else { |
178 int i; | |
179 unsigned short *s=data; | |
4300
4ebab79785b7
passing samplerate to LPCM writer - 44, 32 and 96khz are also supported from now
arpi
parents:
3095
diff
changeset
|
180 // if(len>2000) len=2000; |
4305 | 181 // printf("ao_mpegpes: len=%d \n",len); |
9265 | 182 if(ao_data.format==AFMT_S16_LE || ao_data.format==AFMT_AC3) |
7607 | 183 for(i=0;i<len/2;i++) s[i]=(s[i]>>8)|(s[i]<<8); // le<->be |
4300
4ebab79785b7
passing samplerate to LPCM writer - 44, 32 and 96khz are also supported from now
arpi
parents:
3095
diff
changeset
|
184 send_lpcm_packet(data,len,0xA0,ao_data.pts,freq_id); |
2708 | 185 } |
186 return len; | |
187 } | |
188 | |
3095 | 189 // return: delay in seconds between first and last sample in buffer |
190 static float get_delay(){ | |
2708 | 191 |
3095 | 192 return 0.0; |
2708 | 193 } |