Mercurial > mplayer.hg
annotate libao2/ao_jack.c @ 15285:39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
Patch by kiriuja mplayer-patches at en-directo net
author | reimar |
---|---|
date | Thu, 28 Apr 2005 14:43:19 +0000 |
parents | ae563b0f4d46 |
children | 904787c80946 |
rev | line source |
---|---|
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
1 /* |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
2 * ao_jack - JACK audio output driver for MPlayer |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
3 * |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
4 * Kamil Strzelecki < esack at browarek.net > |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
5 * |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
6 * This driver is distribuited under terms of GPL |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
7 * |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
8 * It uses bio2jack (http://bio2jack.sf.net/). |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
9 * |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
10 */ |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
11 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
12 #include <stdio.h> |
13889
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
13 #include <jack/jack.h> |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
14 |
14479 | 15 #include "config.h" |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
16 #include "audio_out.h" |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
17 #include "audio_out_internal.h" |
14245 | 18 #include "libaf/af_format.h" |
14123 | 19 #include "mp_msg.h" |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
20 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
21 //#include "bio2jack.h" |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
22 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
23 static int driver = 0; |
13889
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
24 long latency = 0; |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
25 long approx_bytes_in_jackd = 0; |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
26 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
27 //bio2jack stuff: |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
28 #define ERR_SUCCESS 0 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
29 #define ERR_OPENING_JACK 1 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
30 #define ERR_RATE_MISMATCH 2 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
31 #define ERR_BYTES_PER_FRAME_INVALID 3 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
32 enum status_enum { PLAYING, PAUSED, STOPPED, CLOSED, RESET }; |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
33 void JACK_Init(void); |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
34 int JACK_Open(int* deviceID, unsigned int bits_per_sample, unsigned long *rate, int channels); |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
35 int JACK_Close(int deviceID); /* return 0 for success */ |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
36 void JACK_Reset(int deviceID); /* free all buffered data and reset several values in the device */ |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
37 long JACK_Write(int deviceID, char *data, unsigned long bytes); /* returns the number of bytes written */ |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
38 long JACK_GetJackLatency(int deviceID); /* return the latency in milliseconds of jack */ |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
39 int JACK_SetState(int deviceID, enum status_enum state); /* playing, paused, stopped */ |
13889
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
40 int JACK_SetAllVolume(int deviceID, unsigned int volume); |
13012
2d188ebe0f3b
Update ao_jack for new bio2jack API, improve check in configure.
diego
parents:
12702
diff
changeset
|
41 int JACK_SetVolumeForChannel(int deviceID, unsigned int channel, unsigned int volume); |
2d188ebe0f3b
Update ao_jack for new bio2jack API, improve check in configure.
diego
parents:
12702
diff
changeset
|
42 void JACK_GetVolumeForChannel(int deviceID, unsigned int channel, unsigned int *volume); |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
43 // |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
44 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
45 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
46 static ao_info_t info = |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
47 { |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
48 "JACK audio output", |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
49 "jack", |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
50 "Kamil Strzelecki <esack@browarek.net>", |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
51 "" |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
52 }; |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
53 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
54 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
55 LIBAO_EXTERN(jack) |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
56 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
57 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
58 static int control(int cmd, void *arg) |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
59 { |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
60 switch(cmd) { |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
61 case AOCONTROL_GET_VOLUME: |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
62 { |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
63 ao_control_vol_t *vol = (ao_control_vol_t *)arg; |
13012
2d188ebe0f3b
Update ao_jack for new bio2jack API, improve check in configure.
diego
parents:
12702
diff
changeset
|
64 unsigned int l, r; |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
65 |
13012
2d188ebe0f3b
Update ao_jack for new bio2jack API, improve check in configure.
diego
parents:
12702
diff
changeset
|
66 JACK_GetVolumeForChannel(driver, 0, &l); |
2d188ebe0f3b
Update ao_jack for new bio2jack API, improve check in configure.
diego
parents:
12702
diff
changeset
|
67 JACK_GetVolumeForChannel(driver, 1, &r); |
12702
b6d1267f189e
1000l in GET_VOLUME. Fix by Lu Ran, hephooey (at) fastmail (dot) fm.
reimar
parents:
12662
diff
changeset
|
68 vol->left = (float )l; |
b6d1267f189e
1000l in GET_VOLUME. Fix by Lu Ran, hephooey (at) fastmail (dot) fm.
reimar
parents:
12662
diff
changeset
|
69 vol->right = (float )r; |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
70 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
71 return CONTROL_OK; |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
72 } |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
73 case AOCONTROL_SET_VOLUME: |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
74 { |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
75 ao_control_vol_t *vol = (ao_control_vol_t *)arg; |
13012
2d188ebe0f3b
Update ao_jack for new bio2jack API, improve check in configure.
diego
parents:
12702
diff
changeset
|
76 unsigned int l = (int )vol->left, |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
77 r = (int )vol->right, |
13889
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
78 avg_vol = (l + r) / 2, |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
79 err = 0; |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
80 |
13889
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
81 switch (ao_data.channels) { |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
82 case 6: |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
83 if((err = JACK_SetVolumeForChannel(driver, 5, avg_vol))) { |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
84 mp_msg(MSGT_AO, MSGL_ERR, |
13889
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
85 "AO: [Jack] Setting lfe volume failed, error %d\n",err); |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
86 return CONTROL_ERROR; |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
87 } |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
88 case 5: |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
89 if((err = JACK_SetVolumeForChannel(driver, 4, avg_vol))) { |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
90 mp_msg(MSGT_AO, MSGL_ERR, |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
91 "AO: [Jack] Setting center volume failed, error %d\n",err); |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
92 return CONTROL_ERROR; |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
93 } |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
94 case 4: |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
95 if((err = JACK_SetVolumeForChannel(driver, 3, r))) { |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
96 mp_msg(MSGT_AO, MSGL_ERR, |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
97 "AO: [Jack] Setting rear right volume failed, error %d\n",err); |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
98 return CONTROL_ERROR; |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
99 } |
13889
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
100 case 3: |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
101 if((err = JACK_SetVolumeForChannel(driver, 2, l))) { |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
102 mp_msg(MSGT_AO, MSGL_ERR, |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
103 "AO: [Jack] Setting rear left volume failed, error %d\n",err); |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
104 return CONTROL_ERROR; |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
105 } |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
106 case 2: |
13012
2d188ebe0f3b
Update ao_jack for new bio2jack API, improve check in configure.
diego
parents:
12702
diff
changeset
|
107 if((err = JACK_SetVolumeForChannel(driver, 1, r))) { |
2d188ebe0f3b
Update ao_jack for new bio2jack API, improve check in configure.
diego
parents:
12702
diff
changeset
|
108 mp_msg(MSGT_AO, MSGL_ERR, |
2d188ebe0f3b
Update ao_jack for new bio2jack API, improve check in configure.
diego
parents:
12702
diff
changeset
|
109 "AO: [Jack] Setting right volume failed, error %d\n",err); |
2d188ebe0f3b
Update ao_jack for new bio2jack API, improve check in configure.
diego
parents:
12702
diff
changeset
|
110 return CONTROL_ERROR; |
2d188ebe0f3b
Update ao_jack for new bio2jack API, improve check in configure.
diego
parents:
12702
diff
changeset
|
111 } |
13889
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
112 case 1: |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
113 if((err = JACK_SetVolumeForChannel(driver, 0, l))) { |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
114 mp_msg(MSGT_AO, MSGL_ERR, |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
115 "AO: [Jack] Setting left volume failed, error %d\n",err); |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
116 return CONTROL_ERROR; |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
117 } |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
118 } |
13012
2d188ebe0f3b
Update ao_jack for new bio2jack API, improve check in configure.
diego
parents:
12702
diff
changeset
|
119 |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
120 return CONTROL_OK; |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
121 } |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
122 } |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
123 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
124 return(CONTROL_UNKNOWN); |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
125 } |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
126 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
127 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
128 static int init(int rate_hz, int channels, int format, int flags) |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
129 { |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
130 int err, m, frag_spec; |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
131 unsigned long rate; |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
132 unsigned int bits_per_sample; |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
133 |
13889
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
134 unsigned long jack_port_flags=JackPortIsPhysical; |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
135 unsigned int jack_port_name_count=0; |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
136 const char *jack_port_name=NULL; |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
137 |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
138 mp_msg(MSGT_AO, MSGL_INFO, "AO: [Jack] Initialising library.\n"); |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
139 JACK_Init(); |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
140 |
13889
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
141 if (ao_subdevice) { |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
142 jack_port_flags = 0; |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
143 jack_port_name_count = 1; |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
144 jack_port_name = ao_subdevice; |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
145 mp_msg(MSGT_AO, MSGL_INFO, "AO: [Jack] Trying to use jack device:%s.\n", ao_subdevice); |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
146 } |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
147 |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
148 switch (format) { |
14245 | 149 case AF_FORMAT_U8: |
150 case AF_FORMAT_S8: | |
151 format = AF_FORMAT_U8; | |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
152 bits_per_sample = 8; |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
153 m = 1; |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
154 break; |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
155 default: |
15009
ae563b0f4d46
endianness fix by Chris White <chriswhite at gentoo dot org>
diego
parents:
14479
diff
changeset
|
156 format = AF_FORMAT_S16_NE; |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
157 bits_per_sample = 16; |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
158 m = 2; |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
159 break; |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
160 } |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
161 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
162 rate = rate_hz; |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
163 |
13889
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
164 err = JACK_OpenEx(&driver, bits_per_sample, &rate, channels, channels, |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
165 &jack_port_name, jack_port_name_count, jack_port_flags); |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
166 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
167 /* if sample rates doesn't match try to open device with jack's rate and |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
168 * let mplayer convert it (rate now contains that which jackd use) */ |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
169 if(err == ERR_RATE_MISMATCH) { |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
170 mp_msg(MSGT_AO, MSGL_INFO, |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
171 "AO: [Jack] Sample rate mismatch, trying to resample.\n"); |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
172 |
13889
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
173 err = JACK_OpenEx(&driver, bits_per_sample, &rate, channels, channels, |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
174 &jack_port_name, jack_port_name_count, jack_port_flags); |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
175 } |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
176 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
177 /* any other error */ |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
178 if(err != ERR_SUCCESS) { |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
179 mp_msg(MSGT_AO, MSGL_ERR, |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
180 "AO: [Jack] JACK_Open() failed, error %d\n", err); |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
181 return 0; |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
182 } |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
183 |
13889
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
184 err = JACK_SetAllVolume(driver, 100); |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
185 if(err != ERR_SUCCESS) { |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
186 // This is not fatal, but would be peculiar... |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
187 mp_msg(MSGT_AO, MSGL_ERR, |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
188 "AO: [Jack] JACK_SetAllVolume() failed, error %d\n", err); |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
189 } |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
190 |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
191 latency = JACK_GetJackLatency(driver); |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
192 |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
193 ao_data.format = format; |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
194 ao_data.channels = channels; |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
195 ao_data.samplerate = rate; |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
196 ao_data.bps = ( rate * channels * m ); |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
197 |
13889
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
198 // Rather rough way to find out the rough number of bytes buffered |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
199 approx_bytes_in_jackd = JACK_GetJackBufferedBytes(driver) * 2; |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
200 |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
201 mp_msg(MSGT_AO, MSGL_INFO, |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
202 "AO: [Jack] OK. I'm ready to go (%d Hz/%d channels/%d bit)\n", |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
203 ao_data.samplerate, ao_data.channels, bits_per_sample); |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
204 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
205 return 1; |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
206 } |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
207 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
208 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
209 static void uninit(int immed) |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
210 { |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
211 int errval = 0; |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
212 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
213 if((errval = JACK_Close(driver))) |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
214 mp_msg(MSGT_AO, MSGL_ERR, |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
215 "AO: [Jack] error closing device, error %d\n", errval); |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
216 } |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
217 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
218 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
219 static int play(void* data,int len,int flags) |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
220 { |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
221 return JACK_Write(driver, data, len); |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
222 } |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
223 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
224 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
225 static void audio_pause() |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
226 { |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
227 JACK_SetState(driver, PAUSED); |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
228 } |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
229 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
230 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
231 static void audio_resume() |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
232 { |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
233 JACK_SetState(driver, PLAYING); |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
234 } |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
235 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
236 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
237 static void reset() |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
238 { |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
239 JACK_Reset(driver); |
13889
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
240 latency = JACK_GetJackLatency(driver); |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
241 // Rather rough way to find out the rough number of bytes buffered |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
242 approx_bytes_in_jackd = JACK_GetJackBufferedBytes(driver) * 2; |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
243 } |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
244 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
245 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
246 static int get_space() |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
247 { |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
248 return JACK_GetBytesFreeSpace(driver); |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
249 } |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
250 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
251 |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
252 static float get_delay() |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
253 { |
13889
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
254 float ret = 0; |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
255 ret = (JACK_GetBytesStored(driver) + approx_bytes_in_jackd + latency) / (float)ao_data.bps; |
adb9a0d74ca0
Improved A-V sync, patch by Ed Wildgoose [lists(at)wildgooses<dot>com].
reimar
parents:
13012
diff
changeset
|
256 return ret; |
12662
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
257 } |
05d46af5e2bf
JACK audio support through bio2jack by Kamil Strzelecki <esack@o2.pl>
alex
parents:
diff
changeset
|
258 |