annotate libao2/ao_dxr2.c @ 26849:ad7c6de88369

Link codec-cfg programs against mp_msg-mencoder.o instead of mp_msg.o. The latter can pick up GUI dependencies.
author diego
date Tue, 27 May 2008 09:04:47 +0000
parents d576b679747b
children 9e739bdb049c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6074
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
1 #include <math.h>
6069
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
2 #include <stdio.h>
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
3 #include <stdlib.h>
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
4 #include <sys/ioctl.h>
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
5 #include <inttypes.h>
6074
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
6 #include <dxr2ioctl.h>
14123
a92101a7eb49 Make include paths consistent.
diego
parents: 14056
diff changeset
7 #include "config.h"
a92101a7eb49 Make include paths consistent.
diego
parents: 14056
diff changeset
8 #include "mp_msg.h"
a92101a7eb49 Make include paths consistent.
diego
parents: 14056
diff changeset
9 #include "help_mp.h"
21372
1767c271d710 Remove bswap.h, use libavutil/bswap.h instead.
diego
parents: 19164
diff changeset
10 #include "libavutil/common.h"
21507
fa99b3d31d13 Hack around libavutil/bswap.h compilation problems due to always_inline undefined.
reimar
parents: 21372
diff changeset
11 #include "mpbswap.h"
6069
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
12
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
13 #include "audio_out.h"
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
14 #include "audio_out_internal.h"
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
15 #include "libaf/af_format.h"
19151
ce6ad55eb7a2 use new mpeg_packetizer helpers
ben
parents: 18915
diff changeset
16 #include "libmpdemux/mpeg_packetizer.h"
6069
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
17
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
18
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
19 static ao_info_t info =
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
20 {
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
21 "DXR2 audio output",
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
22 "dxr2",
15755
b1b06adc5cd3 Fix email address
ranma
parents: 14245
diff changeset
23 "Tobias Diedrich <ranma+mplayer@tdiedrich.de>",
6069
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
24 ""
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
25 };
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
26
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
27 LIBAO_EXTERN(dxr2)
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
28
6074
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
29 static int volume=19;
19164
39d60ed7edfe use mpeg packetizer helpers for sending lpcm packets
ben
parents: 19151
diff changeset
30 static int last_freq_id = -1;
6074
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
31 extern int dxr2_fd;
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
32
6069
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
33 // to set/get/query special features/parameters
9633
12b1790038b0 64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents: 6111
diff changeset
34 static int control(int cmd,void *arg){
6074
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
35 switch(cmd){
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
36 case AOCONTROL_GET_VOLUME:
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
37 if(dxr2_fd > 0) {
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
38 ao_control_vol_t* vol = (ao_control_vol_t*)arg;
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
39 vol->left = vol->right = volume * 19.0 / 100.0;
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
40 return CONTROL_OK;
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
41 }
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
42 return CONTROL_ERROR;
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
43 case AOCONTROL_SET_VOLUME:
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
44 if(dxr2_fd > 0) {
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
45 dxr2_oneArg_t v;
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
46 float diff;
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
47 ao_control_vol_t* vol = (ao_control_vol_t*)arg;
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
48 // We need this trick because the volume stepping is often too small
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
49 diff = ((vol->left+vol->right) / 2 - (volume*19.0/100.0)) * 19.0 / 100.0;
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
50 v.arg = volume + (diff > 0 ? ceil(diff) : floor(diff));
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
51 if(v.arg > 19) v.arg = 19;
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
52 if(v.arg < 0) v.arg = 0;
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
53 if(v.arg != volume) {
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
54 volume = v.arg;
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
55 if( ioctl(dxr2_fd,DXR2_IOC_SET_AUDIO_VOLUME,&v) < 0) {
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12145
diff changeset
56 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_DXR2_SetVolFailed,volume);
6074
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
57 return CONTROL_ERROR;
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
58 }
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
59 }
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
60 return CONTROL_OK;
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
61 }
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
62 return CONTROL_ERROR;
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
63 }
6069
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
64 return CONTROL_UNKNOWN;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
65 }
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
66
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
67 static int freq=0;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
68 static int freq_id=0;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
69
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
70 // open & setup audio device
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
71 // return: 1=success 0=fail
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
72 static int init(int rate,int channels,int format,int flags){
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
73
6111
582960ab7cc7 Workaround the bug in x11 vo's (if it's one) wich let a window in the way
albeu
parents: 6074
diff changeset
74 if(dxr2_fd <= 0)
582960ab7cc7 Workaround the bug in x11 vo's (if it's one) wich let a window in the way
albeu
parents: 6074
diff changeset
75 return 0;
582960ab7cc7 Workaround the bug in x11 vo's (if it's one) wich let a window in the way
albeu
parents: 6074
diff changeset
76
19164
39d60ed7edfe use mpeg packetizer helpers for sending lpcm packets
ben
parents: 19151
diff changeset
77 last_freq_id = -1;
39d60ed7edfe use mpeg packetizer helpers for sending lpcm packets
ben
parents: 19151
diff changeset
78
6069
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
79 ao_data.outburst=2048;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
80 ao_data.samplerate=rate;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
81 ao_data.channels=channels;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
82 ao_data.buffersize=2048;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
83 ao_data.bps=rate*4;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
84 ao_data.format=format;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
85 freq=rate;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
86
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
87 switch(rate){
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
88 case 48000:
6074
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
89 freq_id=DXR2_AUDIO_FREQ_48;
6069
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
90 break;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
91 case 96000:
6074
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
92 freq_id=DXR2_AUDIO_FREQ_96;
6069
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
93 break;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
94 case 44100:
6074
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
95 freq_id=DXR2_AUDIO_FREQ_441;
6069
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
96 break;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
97 case 32000:
6074
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
98 freq_id=DXR2_AUDIO_FREQ_32;
6069
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
99 break;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
100 case 22050:
6074
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
101 freq_id=DXR2_AUDIO_FREQ_2205;
6069
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
102 break;
6074
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
103 #ifdef DXR2_AUDIO_FREQ_24
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
104 // This is not yet in the dxr2 driver CVS
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
105 // you can get the patch at
17064
a6ad13d29a70 Link was a bit dated (but still working :-))
ranma
parents: 15755
diff changeset
106 // http://www.tdiedrich.de/~ranma/patches/dxr2.pcm1723.20020513
6069
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
107 case 24000:
6074
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
108 freq_id=DXR2_AUDIO_FREQ_24;
6069
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
109 break;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
110 case 64000:
6074
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
111 freq_id=DXR2_AUDIO_FREQ_64;
6069
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
112 break;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
113 case 88200:
6074
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
114 freq_id=DXR2_AUDIO_FREQ_882;
6069
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
115 break;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
116 #endif
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
117 default:
13383
c1955840883d mp_msg transition of unmaintained audio output drivers.
ivo
parents: 12145
diff changeset
118 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_DXR2_UnsupSamplerate,rate);
6069
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
119 return 0;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
120 }
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
121
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
122 return 1;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
123 }
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
124
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
125 // close audio device
12145
99798c3cdb93 uninit immed flag
alex
parents: 9633
diff changeset
126 static void uninit(int immed){
6069
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
127
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
128 }
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
129
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
130 // stop playing and empty buffers (for seeking/pause)
18915
99e20a22d5d0 modifies function declarations without parameters from ()
reynaldo
parents: 17064
diff changeset
131 static void reset(void){
6069
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
132
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
133 }
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
134
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
135 // stop playing, keep buffers (for pause)
18915
99e20a22d5d0 modifies function declarations without parameters from ()
reynaldo
parents: 17064
diff changeset
136 static void audio_pause(void)
6069
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
137 {
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
138 // for now, just call reset();
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
139 reset();
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
140 }
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
141
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
142 // resume playing, after audio_pause()
18915
99e20a22d5d0 modifies function declarations without parameters from ()
reynaldo
parents: 17064
diff changeset
143 static void audio_resume(void)
6069
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
144 {
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
145 }
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
146
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
147 extern int vo_pts;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
148 // return: how many bytes can be played without blocking
18915
99e20a22d5d0 modifies function declarations without parameters from ()
reynaldo
parents: 17064
diff changeset
149 static int get_space(void){
6069
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
150 float x=(float)(vo_pts-ao_data.pts)/90000.0;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
151 int y;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
152 if(x<=0) return 0;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
153 y=freq*4*x;y/=ao_data.outburst;y*=ao_data.outburst;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
154 if(y>32768) y=32768;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
155 return y;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
156 }
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
157
19164
39d60ed7edfe use mpeg packetizer helpers for sending lpcm packets
ben
parents: 19151
diff changeset
158 static void dxr2_send_lpcm_packet(unsigned char* data,int len,int id,unsigned int timestamp,int freq_id)
39d60ed7edfe use mpeg packetizer helpers for sending lpcm packets
ben
parents: 19151
diff changeset
159 {
25673
d576b679747b Write functions used by send_mpeg_*_packet may _not_ modify data
reimar
parents: 21507
diff changeset
160 extern int write_dxr2(const unsigned char *data, int len);
19164
39d60ed7edfe use mpeg packetizer helpers for sending lpcm packets
ben
parents: 19151
diff changeset
161
39d60ed7edfe use mpeg packetizer helpers for sending lpcm packets
ben
parents: 19151
diff changeset
162 if(dxr2_fd < 0) {
39d60ed7edfe use mpeg packetizer helpers for sending lpcm packets
ben
parents: 19151
diff changeset
163 mp_msg(MSGT_AO,MSGL_ERR,"DXR2 fd is not valid\n");
39d60ed7edfe use mpeg packetizer helpers for sending lpcm packets
ben
parents: 19151
diff changeset
164 return;
39d60ed7edfe use mpeg packetizer helpers for sending lpcm packets
ben
parents: 19151
diff changeset
165 }
39d60ed7edfe use mpeg packetizer helpers for sending lpcm packets
ben
parents: 19151
diff changeset
166
39d60ed7edfe use mpeg packetizer helpers for sending lpcm packets
ben
parents: 19151
diff changeset
167 if(last_freq_id != freq_id) {
39d60ed7edfe use mpeg packetizer helpers for sending lpcm packets
ben
parents: 19151
diff changeset
168 ioctl(dxr2_fd, DXR2_IOC_SET_AUDIO_SAMPLE_FREQUENCY, &freq_id);
39d60ed7edfe use mpeg packetizer helpers for sending lpcm packets
ben
parents: 19151
diff changeset
169 last_freq_id = freq_id;
39d60ed7edfe use mpeg packetizer helpers for sending lpcm packets
ben
parents: 19151
diff changeset
170 }
39d60ed7edfe use mpeg packetizer helpers for sending lpcm packets
ben
parents: 19151
diff changeset
171
39d60ed7edfe use mpeg packetizer helpers for sending lpcm packets
ben
parents: 19151
diff changeset
172 send_mpeg_lpcm_packet (data, len, id, timestamp, freq_id, write_dxr2);
39d60ed7edfe use mpeg packetizer helpers for sending lpcm packets
ben
parents: 19151
diff changeset
173 }
39d60ed7edfe use mpeg packetizer helpers for sending lpcm packets
ben
parents: 19151
diff changeset
174
6069
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
175 // plays 'len' bytes of 'data'
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
176 // it should round it down to outburst*n
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
177 // return: number of bytes played
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
178 static int play(void* data,int len,int flags){
25673
d576b679747b Write functions used by send_mpeg_*_packet may _not_ modify data
reimar
parents: 21507
diff changeset
179 extern int write_dxr2(const unsigned char *data, int len);
19151
ce6ad55eb7a2 use new mpeg_packetizer helpers
ben
parents: 18915
diff changeset
180
6069
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
181 // MPEG and AC3 don't work :-(
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
182 if(ao_data.format==AF_FORMAT_MPEG2)
19151
ce6ad55eb7a2 use new mpeg_packetizer helpers
ben
parents: 18915
diff changeset
183 send_mpeg_ps_packet (data, len, 0xC0, ao_data.pts, 2, write_dxr2);
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14123
diff changeset
184 else if(ao_data.format==AF_FORMAT_AC3)
19151
ce6ad55eb7a2 use new mpeg_packetizer helpers
ben
parents: 18915
diff changeset
185 send_mpeg_ps_packet (data, len, 0x80, ao_data.pts, 2, write_dxr2);
6069
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
186 else {
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
187 int i;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
188 //unsigned short *s=data;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
189 uint16_t *s=data;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
190 #ifndef WORDS_BIGENDIAN
6074
10a30eebafaf Applied patch from Tobias Diedrich <ranma@gmx.at>, added volume setting
albeu
parents: 6069
diff changeset
191 for(i=0;i<len/2;i++) s[i] = bswap_16(s[i]);
6069
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
192 #endif
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
193 dxr2_send_lpcm_packet(data,len,0xA0,ao_data.pts-10000,freq_id);
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
194 }
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
195 return len;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
196 }
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
197
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
198 // return: delay in seconds between first and last sample in buffer
18915
99e20a22d5d0 modifies function declarations without parameters from ()
reynaldo
parents: 17064
diff changeset
199 static float get_delay(void){
6069
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
200
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
201 return 0.0;
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
202 }
8e88e92fe331 Initial support for dxr2. Based on patch from Tobias Diedrich <ranma@gmx.at>.
albeu
parents:
diff changeset
203