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