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