annotate libao2/ao_mpegpes.c @ 7156:3e5e0e7c6e5e

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