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