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