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