Mercurial > mplayer.hg
annotate stream/ai_alsa1x.c @ 23891:542d4cda34c3
Fix wrong return type in darwin VCD code
author | reimar |
---|---|
date | Sun, 29 Jul 2007 12:41:22 +0000 |
parents | 64d82a45a05d |
children | 8fe8b0d9deec |
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 |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
7 #include <alsa/asoundlib.h> |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
8 #include "audio_in.h" |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
9 #include "mp_msg.h" |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
11775
diff
changeset
|
10 #include "help_mp.h" |
7060
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
11 |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
12 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
|
13 { |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
14 snd_pcm_hw_params_t *params; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
15 snd_pcm_sw_params_t *swparams; |
11775 | 16 snd_pcm_uframes_t buffer_size, period_size; |
7060
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
17 int err; |
11775 | 18 int dir; |
7060
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) { |
16905
c3762297a9d1
changes from MSGTR_MPDEMUX_AIALSA1X_* to MSGTR_MPDEMUX_AIALSA_* since they are the same messages
ptt
parents:
16882
diff
changeset
|
26 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_PcmBrokenConfig); |
7060
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 } |
11775 | 29 |
7060
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
30 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
|
31 SND_PCM_ACCESS_RW_INTERLEAVED); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
32 if (err < 0) { |
16905
c3762297a9d1
changes from MSGTR_MPDEMUX_AIALSA1X_* to MSGTR_MPDEMUX_AIALSA_* since they are the same messages
ptt
parents:
16882
diff
changeset
|
33 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_UnavailableAccessType); |
7060
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
34 return -1; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
35 } |
11775 | 36 |
7060
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
37 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
|
38 if (err < 0) { |
16905
c3762297a9d1
changes from MSGTR_MPDEMUX_AIALSA1X_* to MSGTR_MPDEMUX_AIALSA_* since they are the same messages
ptt
parents:
16882
diff
changeset
|
39 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_UnavailableSampleFmt); |
7060
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
40 return -1; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
41 } |
11775 | 42 |
7060
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
43 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
|
44 if (err < 0) { |
11775 | 45 snd_pcm_hw_params_get_channels(params, &ai->channels); |
16905
c3762297a9d1
changes from MSGTR_MPDEMUX_AIALSA1X_* to MSGTR_MPDEMUX_AIALSA_* since they are the same messages
ptt
parents:
16882
diff
changeset
|
46 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_UnavailableChanCount, |
7060
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
47 ai->channels); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
48 } else { |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
49 ai->channels = ai->req_channels; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
50 } |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
51 |
11775 | 52 dir = 0; |
53 rate = ai->req_samplerate; | |
54 err = snd_pcm_hw_params_set_rate_near(ai->alsa.handle, params, &rate, &dir); | |
55 if (err < 0) { | |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
11775
diff
changeset
|
56 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA1X_CannotSetSamplerate); |
11775 | 57 } |
7060
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
58 ai->samplerate = rate; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
59 |
11775 | 60 dir = 0; |
7060
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
61 ai->alsa.buffer_time = 1000000; |
11775 | 62 err = snd_pcm_hw_params_set_buffer_time_near(ai->alsa.handle, params, |
63 &ai->alsa.buffer_time, &dir); | |
64 if (err < 0) { | |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
11775
diff
changeset
|
65 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA1X_CannotSetBufferTime); |
11775 | 66 } |
67 | |
68 dir = 0; | |
7060
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
69 ai->alsa.period_time = ai->alsa.buffer_time / 4; |
11775 | 70 err = snd_pcm_hw_params_set_period_time_near(ai->alsa.handle, params, |
71 &ai->alsa.period_time, &dir); | |
72 if (err < 0) { | |
16882
dfbe8cd0e081
libmpdemux translatables to help_mp part 1 / mp_msg calls / try 2
reynaldo
parents:
11775
diff
changeset
|
73 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA1X_CannotSetPeriodTime); |
11775 | 74 } |
75 | |
7060
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
76 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
|
77 if (err < 0) { |
16905
c3762297a9d1
changes from MSGTR_MPDEMUX_AIALSA1X_* to MSGTR_MPDEMUX_AIALSA_* since they are the same messages
ptt
parents:
16882
diff
changeset
|
78 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_CannotInstallHWParams, snd_strerror(err)); |
7060
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
79 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
|
80 return -1; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
81 } |
11775 | 82 |
83 dir = -1; | |
84 snd_pcm_hw_params_get_period_size(params, &period_size, &dir); | |
85 snd_pcm_hw_params_get_buffer_size(params, &buffer_size); | |
86 ai->alsa.chunk_size = period_size; | |
87 if (period_size == buffer_size) { | |
16905
c3762297a9d1
changes from MSGTR_MPDEMUX_AIALSA1X_* to MSGTR_MPDEMUX_AIALSA_* since they are the same messages
ptt
parents:
16882
diff
changeset
|
88 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_PeriodEqualsBufferSize, ai->alsa.chunk_size, (long)buffer_size); |
7060
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 } |
11775 | 91 |
7060
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
92 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
|
93 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
|
94 assert(err >= 0); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
95 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
|
96 assert(err >= 0); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
97 |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
98 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
|
99 assert(err >= 0); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
100 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
|
101 assert(err >= 0); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
102 |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
103 assert(err >= 0); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
104 if (snd_pcm_sw_params(ai->alsa.handle, swparams) < 0) { |
16905
c3762297a9d1
changes from MSGTR_MPDEMUX_AIALSA1X_* to MSGTR_MPDEMUX_AIALSA_* since they are the same messages
ptt
parents:
16882
diff
changeset
|
105 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_CannotInstallSWParams); |
7060
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
106 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
|
107 return -1; |
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 |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
110 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
|
111 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
|
112 } |
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 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
|
115 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
|
116 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
|
117 ai->samplesize = ai->alsa.bits_per_sample; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
118 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
|
119 |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
120 return 0; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
121 } |
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 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
|
124 { |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
125 int err; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
126 |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
127 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
|
128 if (err < 0) { |
16905
c3762297a9d1
changes from MSGTR_MPDEMUX_AIALSA1X_* to MSGTR_MPDEMUX_AIALSA_* since they are the same messages
ptt
parents:
16882
diff
changeset
|
129 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_ErrorOpeningAudio, snd_strerror(err)); |
7060
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
130 return -1; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
131 } |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
132 |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
133 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
|
134 |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
135 if (err < 0) { |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
136 return -1; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
137 } |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
138 |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
139 err = ai_alsa_setup(ai); |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
140 |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
141 return err; |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
142 } |
b14880a6cccb
new v4l capture patch by Jindrich Makovicka <makovick@kmlinux.fjfi.cvut.cz>:
arpi
parents:
diff
changeset
|
143 |
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
|
144 #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
|
145 #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
|
146 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
|
147 (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
|
148 (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
|
149 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
|
150 --(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
|
151 (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
|
152 } \ |
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 } 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
|
154 #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
|
155 |
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 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
|
157 { |
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 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
|
159 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
|
160 |
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 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
|
162 if ((res = snd_pcm_status(ai->alsa.handle, status))<0) { |
16905
c3762297a9d1
changes from MSGTR_MPDEMUX_AIALSA1X_* to MSGTR_MPDEMUX_AIALSA_* since they are the same messages
ptt
parents:
16882
diff
changeset
|
163 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_AlsaStatusError, snd_strerror(res)); |
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
|
164 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
|
165 } |
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 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
|
167 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
|
168 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
|
169 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
|
170 timersub(&now, &tstamp, &diff); |
16905
c3762297a9d1
changes from MSGTR_MPDEMUX_AIALSA1X_* to MSGTR_MPDEMUX_AIALSA_* since they are the same messages
ptt
parents:
16882
diff
changeset
|
171 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_AlsaXRUN, |
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
|
172 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
|
173 if (mp_msg_test(MSGT_TV, MSGL_V)) { |
16905
c3762297a9d1
changes from MSGTR_MPDEMUX_AIALSA1X_* to MSGTR_MPDEMUX_AIALSA_* since they are the same messages
ptt
parents:
16882
diff
changeset
|
174 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_AlsaStatus); |
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
|
175 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
|
176 } |
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
|
177 if ((res = snd_pcm_prepare(ai->alsa.handle))<0) { |
16905
c3762297a9d1
changes from MSGTR_MPDEMUX_AIALSA1X_* to MSGTR_MPDEMUX_AIALSA_* since they are the same messages
ptt
parents:
16882
diff
changeset
|
178 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_AlsaXRUNPrepareError, snd_strerror(res)); |
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
|
179 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
|
180 } |
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
|
181 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
|
182 } |
16905
c3762297a9d1
changes from MSGTR_MPDEMUX_AIALSA1X_* to MSGTR_MPDEMUX_AIALSA_* since they are the same messages
ptt
parents:
16882
diff
changeset
|
183 mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_AlsaReadWriteError); |
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
|
184 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
|
185 } |