Mercurial > mplayer.hg
annotate libao2/ao_mpegpes.c @ 19260:afc63a0f266f
How to encode movies for PSP
author | gpoirier |
---|---|
date | Sun, 30 Jul 2006 20:33:59 +0000 |
parents | 5500b7fa33c0 |
children | 3a998ae2f952 |
rev | line source |
---|---|
2708 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
7472
c4434bdf6e51
tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents:
7164
diff
changeset
|
3 #include <string.h> |
19184
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
4 #include <sys/types.h> |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
5 #include <sys/stat.h> |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
6 #include <fcntl.h> |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
7 #include <unistd.h> |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
8 #include <inttypes.h> |
9411 | 9 |
14123 | 10 #include "config.h" |
9411 | 11 |
12 #ifdef HAVE_DVB_HEAD | |
8594 | 13 #define HAVE_DVB 1 |
14 #endif | |
15 | |
6856 | 16 #ifdef HAVE_DVB |
19215
64264df4c4e1
include sys/poll.h only when HAVE_DVB[_HEAD] is set
nicodvb
parents:
19184
diff
changeset
|
17 #include <sys/poll.h> |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
18 #include <sys/ioctl.h> |
6856 | 19 #endif |
2708 | 20 |
21 #include "audio_out.h" | |
22 #include "audio_out_internal.h" | |
23 | |
14245 | 24 #include "libaf/af_format.h" |
19184
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
25 #include "libmpdemux/mpeg_packetizer.h" |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
26 #include "subopt-helper.h" |
2708 | 27 |
14123 | 28 #include "mp_msg.h" |
29 #include "help_mp.h" | |
7161 | 30 |
4792 | 31 #ifdef HAVE_DVB |
8594 | 32 #ifndef HAVE_DVB_HEAD |
4792 | 33 #include <ost/audio.h> |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
34 audioMixer_t dvb_mixer={255,255}; |
8594 | 35 #else |
9411 | 36 #include <linux/dvb/audio.h> |
8594 | 37 audio_mixer_t dvb_mixer={255,255}; |
38 #endif | |
7609 | 39 #endif |
19184
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
40 |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
41 #define true 1 |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
42 #define false 0 |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
43 |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
44 extern int vo_mpegpes_fd; |
19184
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
45 int vo_mpegpes_fd2 = -1; |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
46 |
7164 | 47 #include <errno.h> |
48 | |
2708 | 49 static ao_info_t info = |
50 { | |
4792 | 51 #ifdef HAVE_DVB |
52 "DVB audio output", | |
53 #else | |
54 "Mpeg-PES audio output", | |
55 #endif | |
2708 | 56 "mpegpes", |
57 "A'rpi", | |
58 "" | |
59 }; | |
60 | |
61 LIBAO_EXTERN(mpegpes) | |
62 | |
63 | |
64 // to set/get/query special features/parameters | |
9633
12b1790038b0
64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents:
9411
diff
changeset
|
65 static int control(int cmd,void *arg){ |
4792 | 66 #ifdef HAVE_DVB |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
67 switch(cmd){ |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
68 case AOCONTROL_GET_VOLUME: |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
69 if(vo_mpegpes_fd2>=0){ |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
70 ((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
|
71 ((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
|
72 return CONTROL_OK; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
73 } |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
74 return CONTROL_ERROR; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
75 case AOCONTROL_SET_VOLUME: |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
76 if(vo_mpegpes_fd2>=0){ |
5060 | 77 dvb_mixer.volume_left=((ao_control_vol_t*)(arg))->left*2.56; |
78 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
|
79 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
|
80 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
|
81 // 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
|
82 if ( (ioctl(vo_mpegpes_fd2,AUDIO_SET_MIXER, &dvb_mixer) < 0)){ |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
83 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_MPEGPES_CantSetMixer, |
7161 | 84 strerror(errno)); |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
85 return CONTROL_ERROR; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
86 } |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
87 return CONTROL_OK; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
88 } |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
89 return CONTROL_ERROR; |
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
90 } |
4792 | 91 #endif |
4788
d678ce495a75
Moved HW dependent mixer stuff to libao and removed master switch
anders
parents:
4331
diff
changeset
|
92 return CONTROL_UNKNOWN; |
2708 | 93 } |
94 | |
4331 | 95 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
|
96 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
|
97 |
19184
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
98 #ifdef HAVE_DVB |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
99 static int init_device(int card) |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
100 { |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
101 char ao_file[30]; |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
102 #ifndef HAVE_DVB_HEAD |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
103 mp_msg(MSGT_VO,MSGL_INFO, "Opening /dev/ost/audio\n"); |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
104 sprintf(ao_file, "/dev/ost/audio"); |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
105 #else |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
106 mp_msg(MSGT_VO,MSGL_INFO, "Opening /dev/dvb/adapter%d/audio0\n", card); |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
107 sprintf(ao_file, "/dev/dvb/adapter%d/audio0", card); |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
108 #endif |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
109 if((vo_mpegpes_fd2 = open(ao_file,O_RDWR|O_NONBLOCK)) < 0) |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
110 { |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
111 perror("DVB AUDIO DEVICE: "); |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
112 return -1; |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
113 } |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
114 if( (ioctl(vo_mpegpes_fd2,AUDIO_SELECT_SOURCE, AUDIO_SOURCE_MEMORY) < 0)) |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
115 { |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
116 perror("DVB AUDIO SELECT SOURCE: "); |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
117 return -1; |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
118 } |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
119 if((ioctl(vo_mpegpes_fd2,AUDIO_PLAY) < 0)) |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
120 { |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
121 perror("DVB AUDIO PLAY: "); |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
122 return -1; |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
123 } |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
124 if((ioctl(vo_mpegpes_fd2,AUDIO_SET_AV_SYNC, true) < 0)) |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
125 { |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
126 perror("DVB AUDIO SET AV SYNC: "); |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
127 return -1; |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
128 } |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
129 //FIXME: in vo_mpegpes audio was inited as MUTEd |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
130 if((ioctl(vo_mpegpes_fd2,AUDIO_SET_MUTE, false) < 0)) |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
131 { |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
132 perror("DVB AUDIO SET MUTE: "); |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
133 return -1; |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
134 } |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
135 return vo_mpegpes_fd2; |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
136 } |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
137 #endif |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
138 |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
139 static int preinit(const char *arg) |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
140 { |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
141 int card = 1; |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
142 char *ao_file = NULL; |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
143 |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
144 opt_t subopts[] = { |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
145 {"card", OPT_ARG_INT, &card, NULL}, |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
146 {"file", OPT_ARG_MSTRZ, &ao_file, NULL}, |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
147 {NULL} |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
148 }; |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
149 |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
150 if(subopt_parse(ao_subdevice, subopts) != 0) |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
151 { |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
152 mp_msg(MSGT_VO, MSGL_ERR, "AO_MPEGPES, Unrecognized options\n"); |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
153 return -1; |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
154 } |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
155 if((card < 1) || (card > 4)) |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
156 { |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
157 mp_msg(MSGT_VO, MSGL_ERR, "DVB card number must be between 1 and 4\n"); |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
158 return -1; |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
159 } |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
160 card--; |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
161 |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
162 #ifdef HAVE_DVB |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
163 if(!ao_file) |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
164 return init_device(card); |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
165 #else |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
166 if(!ao_file) |
19222
5500b7fa33c0
if HAVE_DVB isn't set don't fall back to outputting audiograb.mpg by default, fail instead
nicodvb
parents:
19215
diff
changeset
|
167 return vo_mpegpes_fd; //video fd |
19184
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
168 #endif |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
169 |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
170 vo_mpegpes_fd2=open(ao_file,O_WRONLY|O_CREAT,0666); |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
171 if(vo_mpegpes_fd2<0) |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
172 { |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
173 perror("ao_mpegpes"); |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
174 return -1; |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
175 } |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
176 return vo_mpegpes_fd2; |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
177 } |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
178 |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
179 static int my_ao_write(unsigned char* data,int len){ |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
180 int orig_len = len; |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
181 #ifdef HAVE_DVB |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
182 #define NFD 1 |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
183 struct pollfd pfd[NFD]; |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
184 |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
185 pfd[0].fd = vo_mpegpes_fd2; |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
186 pfd[0].events = POLLOUT; |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
187 |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
188 while(len>0){ |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
189 if(poll(pfd,NFD,1)){ |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
190 if(pfd[0].revents & POLLOUT){ |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
191 int ret=write(vo_mpegpes_fd2,data,len); |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
192 if(ret<=0){ |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
193 perror("write"); |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
194 usleep(0); |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
195 } else { |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
196 len-=ret; |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
197 data+=ret; |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
198 } |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
199 } else usleep(1000); |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
200 } |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
201 } |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
202 |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
203 #else |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
204 if(vo_mpegpes_fd2<0) return 0; // no file |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
205 write(vo_mpegpes_fd2,data,len); // write to file |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
206 #endif |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
207 return orig_len; |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
208 } |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
209 |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
210 |
2708 | 211 // open & setup audio device |
212 // return: 1=success 0=fail | |
213 static int init(int rate,int channels,int format,int flags){ | |
19184
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
214 if(preinit(NULL)<0) return 0; |
7607 | 215 |
216 ao_data.channels=2; | |
3095 | 217 ao_data.outburst=2000; |
7607 | 218 switch(format){ |
14245 | 219 case AF_FORMAT_S16_LE: |
220 case AF_FORMAT_S16_BE: | |
221 case AF_FORMAT_MPEG2: | |
222 case AF_FORMAT_AC3: | |
7607 | 223 ao_data.format=format; |
224 break; | |
225 default: | |
14245 | 226 ao_data.format=AF_FORMAT_S16_BE; |
7607 | 227 } |
4300
4ebab79785b7
passing samplerate to LPCM writer - 44, 32 and 96khz are also supported from now
arpi
parents:
3095
diff
changeset
|
228 |
7607 | 229 retry: |
4300
4ebab79785b7
passing samplerate to LPCM writer - 44, 32 and 96khz are also supported from now
arpi
parents:
3095
diff
changeset
|
230 switch(rate){ |
4ebab79785b7
passing samplerate to LPCM writer - 44, 32 and 96khz are also supported from now
arpi
parents:
3095
diff
changeset
|
231 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
|
232 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
|
233 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
|
234 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
|
235 default: |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
236 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_MPEGPES_UnsupSamplerate, rate); |
7607 | 237 #if 0 |
238 if(rate>48000) rate=96000; else | |
239 if(rate>44100) rate=48000; else | |
240 if(rate>32000) rate=44100; else | |
241 rate=32000; | |
242 goto retry; | |
243 #else | |
244 rate=48000; freq_id=0; | |
245 #endif | |
4300
4ebab79785b7
passing samplerate to LPCM writer - 44, 32 and 96khz are also supported from now
arpi
parents:
3095
diff
changeset
|
246 } |
2708 | 247 |
7607 | 248 ao_data.bps=rate*2*2; |
249 freq=ao_data.samplerate=rate; | |
250 | |
2708 | 251 return 1; |
252 } | |
253 | |
254 // close audio device | |
12145 | 255 static void uninit(int immed){ |
2708 | 256 |
257 } | |
258 | |
259 // stop playing and empty buffers (for seeking/pause) | |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
14245
diff
changeset
|
260 static void reset(void){ |
2708 | 261 |
262 } | |
263 | |
264 // stop playing, keep buffers (for pause) | |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
14245
diff
changeset
|
265 static void audio_pause(void) |
2708 | 266 { |
267 // for now, just call reset(); | |
268 reset(); | |
269 } | |
270 | |
271 // resume playing, after audio_pause() | |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
14245
diff
changeset
|
272 static void audio_resume(void) |
2708 | 273 { |
274 } | |
275 | |
276 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
|
277 void send_lpcm_packet(unsigned char* data,int len,int id,int timestamp,int freq_id); |
2708 | 278 extern int vo_pts; |
279 | |
280 // return: how many bytes can be played without blocking | |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
14245
diff
changeset
|
281 static int get_space(void){ |
4331 | 282 float x=(float)(vo_pts-ao_data.pts)/90000.0; |
2708 | 283 int y; |
19184
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
284 //FIXME: is it correct? |
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
285 if(vo_mpegpes_fd < 0) return 32000; //not using -vo mpegpes |
7607 | 286 // printf("vo_pts: %5.3f ao_pts: %5.3f\n",vo_pts/90000.0,ao_data.pts/90000.0); |
2708 | 287 if(x<=0) return 0; |
4331 | 288 y=freq*4*x;y/=ao_data.outburst;y*=ao_data.outburst; |
289 if(y>32000) y=32000; | |
2708 | 290 // printf("diff: %5.3f -> %d \n",x,y); |
291 return y; | |
292 } | |
293 | |
294 // plays 'len' bytes of 'data' | |
295 // it should round it down to outburst*n | |
296 // return: number of bytes played | |
297 static int play(void* data,int len,int flags){ | |
7607 | 298 // printf("\nao_mpegpes: play(%d) freq=%d\n",len,freq_id); |
14245 | 299 if(ao_data.format==AF_FORMAT_MPEG2) |
19184
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
300 send_mpeg_pes_packet (data, len, 0x1C0, ao_data.pts, 1, my_ao_write); |
2708 | 301 else { |
302 int i; | |
303 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
|
304 // if(len>2000) len=2000; |
4305 | 305 // printf("ao_mpegpes: len=%d \n",len); |
14245 | 306 if(ao_data.format==AF_FORMAT_S16_LE || ao_data.format==AF_FORMAT_AC3) |
7607 | 307 for(i=0;i<len/2;i++) s[i]=(s[i]>>8)|(s[i]<<8); // le<->be |
19184
3f2de7ba8aa0
split the incestous intercourse between ao_mpegpes and vo_mpegpes; now the devices can be used separately
nicodvb
parents:
17566
diff
changeset
|
308 send_mpeg_lpcm_packet(data, len, 0xA0, ao_data.pts, freq_id, my_ao_write); |
2708 | 309 } |
310 return len; | |
311 } | |
312 | |
3095 | 313 // return: delay in seconds between first and last sample in buffer |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
14245
diff
changeset
|
314 static float get_delay(void){ |
2708 | 315 |
3095 | 316 return 0.0; |
2708 | 317 } |