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