Mercurial > mplayer.hg
annotate libmpdemux/ai_alsa1x.c @ 10300:134e4332f550
solaris fix by Gtz Waschk <waschk@informatik.uni-rostock.de>
author | alex |
---|---|
date | Tue, 17 Jun 2003 22:28:29 +0000 |
parents | d12421dd1265 |
children | 31f12f99118b |
rev | line source |
---|---|
7213
13fcab6fde41
audio in layer is used only bu tvi_v4l, don't compile for others.
arpi
parents:
7070
diff
changeset
|
1 #include <stdio.h> |
13fcab6fde41
audio in layer is used only bu tvi_v4l, don't compile for others.
arpi
parents:
7070
diff
changeset
|
2 #include <stdlib.h> |
7586
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
3 #include <sys/time.h> |
7213
13fcab6fde41
audio in layer is used only bu tvi_v4l, don't compile for others.
arpi
parents:
7070
diff
changeset
|
4 |
7060
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
5 #include "config.h" |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
6 |
7213
13fcab6fde41
audio in layer is used only bu tvi_v4l, don't compile for others.
arpi
parents:
7070
diff
changeset
|
7 #if defined(USE_TV) && defined(HAVE_TV_V4L) && defined(HAVE_ALSA9) |
13fcab6fde41
audio in layer is used only bu tvi_v4l, don't compile for others.
arpi
parents:
7070
diff
changeset
|
8 |
7060
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
9 #include <alsa/asoundlib.h> |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
10 #include "audio_in.h" |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
11 #include "mp_msg.h" |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
12 |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
13 int ai_alsa_setup(audio_in_t *ai) |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
14 { |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
15 snd_pcm_hw_params_t *params; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
16 snd_pcm_sw_params_t *swparams; |
7586
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
17 int buffer_size; |
7060
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
18 int err; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
19 unsigned int rate; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
20 |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
21 snd_pcm_hw_params_alloca(¶ms); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
22 snd_pcm_sw_params_alloca(&swparams); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
23 |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
24 err = snd_pcm_hw_params_any(ai->alsa.handle, params); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
25 if (err < 0) { |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
26 mp_msg(MSGT_TV, MSGL_ERR, "Broken configuration for this PCM: no configurations available\n"); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
27 return -1; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
28 } |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
29 err = snd_pcm_hw_params_set_access(ai->alsa.handle, params, |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
30 SND_PCM_ACCESS_RW_INTERLEAVED); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
31 if (err < 0) { |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
32 mp_msg(MSGT_TV, MSGL_ERR, "Access type not available\n"); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
33 return -1; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
34 } |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
35 err = snd_pcm_hw_params_set_format(ai->alsa.handle, params, SND_PCM_FORMAT_S16_LE); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
36 if (err < 0) { |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
37 mp_msg(MSGT_TV, MSGL_ERR, "Sample format not available\n"); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
38 return -1; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
39 } |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
40 err = snd_pcm_hw_params_set_channels(ai->alsa.handle, params, ai->req_channels); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
41 if (err < 0) { |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
42 ai->channels = snd_pcm_hw_params_get_channels(params); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
43 mp_msg(MSGT_TV, MSGL_ERR, "Channel count not available - reverting to default: %d\n", |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
44 ai->channels); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
45 } else { |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
46 ai->channels = ai->req_channels; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
47 } |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
48 |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
49 err = snd_pcm_hw_params_set_rate_near(ai->alsa.handle, params, ai->req_samplerate, 0); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
50 assert(err >= 0); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
51 rate = err; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
52 ai->samplerate = rate; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
53 |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
54 ai->alsa.buffer_time = 1000000; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
55 ai->alsa.buffer_time = snd_pcm_hw_params_set_buffer_time_near(ai->alsa.handle, params, |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
56 ai->alsa.buffer_time, 0); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
57 assert(ai->alsa.buffer_time >= 0); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
58 ai->alsa.period_time = ai->alsa.buffer_time / 4; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
59 ai->alsa.period_time = snd_pcm_hw_params_set_period_time_near(ai->alsa.handle, params, |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
60 ai->alsa.period_time, 0); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
61 assert(ai->alsa.period_time >= 0); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
62 err = snd_pcm_hw_params(ai->alsa.handle, params); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
63 if (err < 0) { |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
64 mp_msg(MSGT_TV, MSGL_ERR, "Unable to install hw params:"); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
65 snd_pcm_hw_params_dump(params, ai->alsa.log); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
66 return -1; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
67 } |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
68 ai->alsa.chunk_size = snd_pcm_hw_params_get_period_size(params, 0); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
69 buffer_size = snd_pcm_hw_params_get_buffer_size(params); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
70 if (ai->alsa.chunk_size == buffer_size) { |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
71 mp_msg(MSGT_TV, MSGL_ERR, "Can't use period equal to buffer size (%u == %lu)\n", ai->alsa.chunk_size, (long)buffer_size); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
72 return -1; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
73 } |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
74 snd_pcm_sw_params_current(ai->alsa.handle, swparams); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
75 err = snd_pcm_sw_params_set_sleep_min(ai->alsa.handle, swparams,0); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
76 assert(err >= 0); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
77 err = snd_pcm_sw_params_set_avail_min(ai->alsa.handle, swparams, ai->alsa.chunk_size); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
78 assert(err >= 0); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
79 |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
80 err = snd_pcm_sw_params_set_start_threshold(ai->alsa.handle, swparams, 0); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
81 assert(err >= 0); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
82 err = snd_pcm_sw_params_set_stop_threshold(ai->alsa.handle, swparams, buffer_size); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
83 assert(err >= 0); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
84 |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
85 assert(err >= 0); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
86 if (snd_pcm_sw_params(ai->alsa.handle, swparams) < 0) { |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
87 mp_msg(MSGT_TV, MSGL_ERR, "unable to install sw params:\n"); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
88 snd_pcm_sw_params_dump(swparams, ai->alsa.log); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
89 return -1; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
90 } |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
91 |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
92 if (mp_msg_test(MSGT_TV, MSGL_V)) { |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
93 snd_pcm_dump(ai->alsa.handle, ai->alsa.log); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
94 } |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
95 |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
96 ai->alsa.bits_per_sample = snd_pcm_format_physical_width(SND_PCM_FORMAT_S16_LE); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
97 ai->alsa.bits_per_frame = ai->alsa.bits_per_sample * ai->channels; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
98 ai->blocksize = ai->alsa.chunk_size * ai->alsa.bits_per_frame / 8; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
99 ai->samplesize = ai->alsa.bits_per_sample; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
100 ai->bytes_per_sample = ai->alsa.bits_per_sample/8; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
101 |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
102 return 0; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
103 } |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
104 |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
105 int ai_alsa_init(audio_in_t *ai) |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
106 { |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
107 int err; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
108 |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
109 err = snd_pcm_open(&ai->alsa.handle, ai->alsa.device, SND_PCM_STREAM_CAPTURE, 0); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
110 if (err < 0) { |
7070
aaac9080b8a3
v4l capture update by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
arpi
parents:
7060
diff
changeset
|
111 mp_msg(MSGT_TV, MSGL_ERR, "Error opening audio: %s\n", snd_strerror(err)); |
7060
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
112 return -1; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
113 } |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
114 |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
115 err = snd_output_stdio_attach(&ai->alsa.log, stderr, 0); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
116 |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
117 if (err < 0) { |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
118 return -1; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
119 } |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
120 |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
121 err = ai_alsa_setup(ai); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
122 |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
123 return err; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
124 } |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
125 |
7586
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
126 #ifndef timersub |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
127 #define timersub(a, b, result) \ |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
128 do { \ |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
129 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
130 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
131 if ((result)->tv_usec < 0) { \ |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
132 --(result)->tv_sec; \ |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
133 (result)->tv_usec += 1000000; \ |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
134 } \ |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
135 } while (0) |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
136 #endif |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
137 |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
138 int ai_alsa_xrun(audio_in_t *ai) |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
139 { |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
140 snd_pcm_status_t *status; |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
141 int res; |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
142 |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
143 snd_pcm_status_alloca(&status); |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
144 if ((res = snd_pcm_status(ai->alsa.handle, status))<0) { |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
145 mp_msg(MSGT_TV, MSGL_ERR, "ALSA status error: %s", snd_strerror(res)); |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
146 return -1; |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
147 } |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
148 if (snd_pcm_status_get_state(status) == SND_PCM_STATE_XRUN) { |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
149 struct timeval now, diff, tstamp; |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
150 gettimeofday(&now, 0); |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
151 snd_pcm_status_get_trigger_tstamp(status, &tstamp); |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
152 timersub(&now, &tstamp, &diff); |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
153 mp_msg(MSGT_TV, MSGL_ERR, "ALSA xrun!!! (at least %.3f ms long)\n", |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
154 diff.tv_sec * 1000 + diff.tv_usec / 1000.0); |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
155 if (mp_msg_test(MSGT_TV, MSGL_V)) { |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
156 mp_msg(MSGT_TV, MSGL_ERR, "ALSA Status:\n"); |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
157 snd_pcm_status_dump(status, ai->alsa.log); |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
158 } |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
159 if ((res = snd_pcm_prepare(ai->alsa.handle))<0) { |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
160 mp_msg(MSGT_TV, MSGL_ERR, "ALSA xrun: prepare error: %s", snd_strerror(res)); |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
161 return -1; |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
162 } |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
163 return 0; /* ok, data should be accepted again */ |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
164 } |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
165 mp_msg(MSGT_TV, MSGL_ERR, "ALSA read/write error"); |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
166 return -1; |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
167 } |
d12421dd1265
this patch adds an ability to recover from audio buffer cross-run by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>
alex
parents:
7213
diff
changeset
|
168 |
7060
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
169 #endif /* HAVE_ALSA9 */ |