~medibuntu-maintainers/mplayer/medibuntu.precise

« back to all changes in this revision

Viewing changes to stream/ai_alsa1x.c

  • Committer: Gauvain Pocentek
  • Date: 2012-03-06 11:59:12 UTC
  • mfrom: (66.1.15 precise)
  • Revision ID: gauvain@pocentek.net-20120306115912-h9d6kt9j0l532oo5
* Merge from Ubuntu:
  - put back faac support
  - recommends apport-hooks-medibuntu
  - change Maintainer, Uploaders & Vcs-* fields.
* New upstream snapshot
* upload to unstable
* Build against external libmpeg2
* drop 51_FTBFS_arm.patch again
* no longer build depend on libcdparanoia-dev on the Hurd
* Fix FTBFS on the hurd.
  Thanks to Samuel Thibault <sthibault@debian.org> (Closes: #654974)
* Fix FTBFS on arm
* New upstream snapshot, Closes: #650339, #643621, #481807
* Imported Upstream version 1.0~rc4+svn34492
* Bump standards version
* Bump dependency on libav >= 4:0.8~, Closes: #653887
* Fix build-indep
* Build mplayer-gui again, Closes: #568514
* Drop debian/all-lang-config-mak.sh, no longer needed
* include .dfsg1 in version number
* remove get-orig-source target
* no longer prune compiler flags from the environment
* No longer advertise nor build 3fdx, mga and dxr3 backends,
  Closes: #496106, #442181, #533546
* beautify mplayer version identification string
* Brown paperbag upload.
* Next try to fix build failure on sparce after recent binutils change.
* Brown paperbag upload.
* Really fix build failure on sparc after recent binutils change.
* Properly set Replaces/Conflicts on mplayer2{,-dbg} to avoid
  file overwrite errors.
* Adjust versioning of mplayer listed in the mplayer-dbg's Depends field.
* Fix build failure on sparc after recent binutils change.
* Urgency medium bumped because of RC-level bugfix
  and speeding up x264 transition.
* Update to my @debian.org email.
* Upload to unstable
* Enable joystick support on Linux only, Closes: #638408
* Rebuild fixes toolchain issue on arm, Closes: #637077
* New upstream snapshot
* following the discussion started by Diego Biurrun <diego@biurrun.de>
  in debian-devel, I have prepared a new packaging of 'mplayer'
  (with code that comes from CVS)
* the upstream tar.bz cannot be distributed by Debian, since it contains
   CSS code; so I am repackaging it 
* I have tried my best to address all known issues:
  - the package contains the detailed Copyright made by Diego Biurrun 
  - the package does not contain CSS code, or  AFAIK other code on which 
     there is active patent enforcement
  - there is a script  debian/cvs-changelog.sh  that shows all changes
     done to files included in this source.
    This should comply with GPLv2 sec 2.a  (in spirit if not in letter)
    For this reason, the source code contains CVS directories.
* needs   make (>= 3.80) for 'html-chunked-$(1)' in DOCS/xml/Makefile

* some corrections, as suggested Diego Biurrun
  - binary codecs should go into /usr/lib/codecs (upstream default)
  - better template 'mplayer/install_codecs'
  - an empty 'font=' in mplayer.conf breaks mplayer: postinst corrected
* correction in 'mplayer/cfgnote'
* better mplayer.postinst and mplayer.config

* New upstream release
* better debian/copyright file
* do not ship a skin
* New upstream release
* changed DEB_BUILD_OPTIONS to DEB_BUILD_CONFIGURE ,
  DEB_BUILD_OPTIONS is used as in debian policy
* use gcc-3.4
* changed xlibs-dev to a long list of dependencies, for Debian/etch
* try to adhere to  http://www.mplayerhq.hu/DOCS/tech/binary-packaging.txt
  (see README.Debian for details)
* removed dependency on xlibmesa-dev, disabled opengl
* New upstream release
* Simon McVittie <hacks@pseudorandom.co.uk> wonderful work:
- Work around Debian bug #267442 (glibc's sys/uio.h and gcc's altivec.h have
  conflicting uses for __vector) by re-ordering #includes
- Fix potential symlink attack in ./configure
- Disable support for binary codecs on platforms for which those codecs
  aren't available; also disable the corresponding Debconf note when it's
  inappropriate
- Changed Build-Depends: so it works in pbuilder
- Explicitly build-depend on libjpeg62-dev, libfontconfig1-dev,
  libungif4-dev 
- Tweak debian/rules to avoid certain errors being ignored
- Use --language=all
* provide a target  'debian/rules get-orig-source' 
  that recreates the orig.tar.gz ; then use the above orig.tar.gz
* rewrote some parts of debian/rules
* don't clean and recompile docs if upstream ships them
* mplayer-doc was shipping too much stuff
* translated man pages where not installed properly
* compile with libdv4-dev
* correct README.Debian
* Forgot build-dep on libtheora
* Must not depend on libxvidcore
* New upstream release
* new release.
* rc1 to become 0.90
* new pre-release
* new pre-release
* gtk bug fixed.
* new release.
* version bumped
* 0.60 pre2 release
* 0.60 pre-release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * This file is part of MPlayer.
3
 
 *
4
 
 * MPlayer is free software; you can redistribute it and/or modify
5
 
 * it under the terms of the GNU General Public License as published by
6
 
 * the Free Software Foundation; either version 2 of the License, or
7
 
 * (at your option) any later version.
8
 
 *
9
 
 * MPlayer is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
 * GNU General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU General Public License along
15
 
 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16
 
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
 
 */
18
 
 
19
 
#include <stdio.h>
20
 
#include <stdlib.h>
21
 
#include <sys/time.h>
22
 
#include <alloca.h>
23
 
 
24
 
#include "config.h"
25
 
 
26
 
#include <alsa/asoundlib.h>
27
 
#include "audio_in.h"
28
 
#include "mp_msg.h"
29
 
#include "help_mp.h"
30
 
 
31
 
int ai_alsa_setup(audio_in_t *ai)
32
 
{
33
 
    snd_pcm_hw_params_t *params;
34
 
    snd_pcm_sw_params_t *swparams;
35
 
    snd_pcm_uframes_t buffer_size, period_size;
36
 
    int err;
37
 
    int dir;
38
 
    unsigned int rate;
39
 
 
40
 
    snd_pcm_hw_params_alloca(&params);
41
 
    snd_pcm_sw_params_alloca(&swparams);
42
 
 
43
 
    err = snd_pcm_hw_params_any(ai->alsa.handle, params);
44
 
    if (err < 0) {
45
 
        mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_PcmBrokenConfig);
46
 
        return -1;
47
 
    }
48
 
 
49
 
    err = snd_pcm_hw_params_set_access(ai->alsa.handle, params,
50
 
                                       SND_PCM_ACCESS_RW_INTERLEAVED);
51
 
    if (err < 0) {
52
 
        mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_UnavailableAccessType);
53
 
        return -1;
54
 
    }
55
 
 
56
 
    err = snd_pcm_hw_params_set_format(ai->alsa.handle, params, SND_PCM_FORMAT_S16_LE);
57
 
    if (err < 0) {
58
 
        mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_UnavailableSampleFmt);
59
 
        return -1;
60
 
    }
61
 
 
62
 
    err = snd_pcm_hw_params_set_channels(ai->alsa.handle, params, ai->req_channels);
63
 
    if (err < 0) {
64
 
        snd_pcm_hw_params_get_channels(params, &ai->channels);
65
 
        mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_UnavailableChanCount,
66
 
               ai->channels);
67
 
    } else {
68
 
        ai->channels = ai->req_channels;
69
 
    }
70
 
 
71
 
    dir = 0;
72
 
    rate = ai->req_samplerate;
73
 
    err = snd_pcm_hw_params_set_rate_near(ai->alsa.handle, params, &rate, &dir);
74
 
    if (err < 0) {
75
 
        mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA1X_CannotSetSamplerate);
76
 
    }
77
 
    ai->samplerate = rate;
78
 
 
79
 
    dir = 0;
80
 
    ai->alsa.buffer_time = 1000000;
81
 
    err = snd_pcm_hw_params_set_buffer_time_near(ai->alsa.handle, params,
82
 
                                                 &ai->alsa.buffer_time, &dir);
83
 
    if (err < 0) {
84
 
        mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA1X_CannotSetBufferTime);
85
 
    }
86
 
 
87
 
    dir = 0;
88
 
    ai->alsa.period_time = ai->alsa.buffer_time / 4;
89
 
    err = snd_pcm_hw_params_set_period_time_near(ai->alsa.handle, params,
90
 
                                                 &ai->alsa.period_time, &dir);
91
 
    if (err < 0) {
92
 
        mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA1X_CannotSetPeriodTime);
93
 
    }
94
 
 
95
 
    err = snd_pcm_hw_params(ai->alsa.handle, params);
96
 
    if (err < 0) {
97
 
        mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_CannotInstallHWParams, snd_strerror(err));
98
 
        snd_pcm_hw_params_dump(params, ai->alsa.log);
99
 
        return -1;
100
 
    }
101
 
 
102
 
    dir = -1;
103
 
    snd_pcm_hw_params_get_period_size(params, &period_size, &dir);
104
 
    snd_pcm_hw_params_get_buffer_size(params, &buffer_size);
105
 
    ai->alsa.chunk_size = period_size;
106
 
    if (period_size == buffer_size) {
107
 
        mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_PeriodEqualsBufferSize, ai->alsa.chunk_size, (long)buffer_size);
108
 
        return -1;
109
 
    }
110
 
 
111
 
    snd_pcm_sw_params_current(ai->alsa.handle, swparams);
112
 
    err = snd_pcm_sw_params_set_sleep_min(ai->alsa.handle, swparams,0);
113
 
    err = snd_pcm_sw_params_set_avail_min(ai->alsa.handle, swparams, ai->alsa.chunk_size);
114
 
 
115
 
    err = snd_pcm_sw_params_set_start_threshold(ai->alsa.handle, swparams, 0);
116
 
    err = snd_pcm_sw_params_set_stop_threshold(ai->alsa.handle, swparams, buffer_size);
117
 
 
118
 
    if (snd_pcm_sw_params(ai->alsa.handle, swparams) < 0) {
119
 
        mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_CannotInstallSWParams);
120
 
        snd_pcm_sw_params_dump(swparams, ai->alsa.log);
121
 
        return -1;
122
 
    }
123
 
 
124
 
    if (mp_msg_test(MSGT_TV, MSGL_V)) {
125
 
        snd_pcm_dump(ai->alsa.handle, ai->alsa.log);
126
 
    }
127
 
 
128
 
    ai->alsa.bits_per_sample = snd_pcm_format_physical_width(SND_PCM_FORMAT_S16_LE);
129
 
    ai->alsa.bits_per_frame = ai->alsa.bits_per_sample * ai->channels;
130
 
    ai->blocksize = ai->alsa.chunk_size * ai->alsa.bits_per_frame / 8;
131
 
    ai->samplesize = ai->alsa.bits_per_sample;
132
 
    ai->bytes_per_sample = ai->alsa.bits_per_sample/8;
133
 
 
134
 
    return 0;
135
 
}
136
 
 
137
 
int ai_alsa_init(audio_in_t *ai)
138
 
{
139
 
    int err;
140
 
 
141
 
    err = snd_pcm_open(&ai->alsa.handle, ai->alsa.device, SND_PCM_STREAM_CAPTURE, 0);
142
 
    if (err < 0) {
143
 
        mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_ErrorOpeningAudio, snd_strerror(err));
144
 
        return -1;
145
 
    }
146
 
 
147
 
    err = snd_output_stdio_attach(&ai->alsa.log, stderr, 0);
148
 
 
149
 
    if (err < 0) {
150
 
        return -1;
151
 
    }
152
 
 
153
 
    err = ai_alsa_setup(ai);
154
 
 
155
 
    return err;
156
 
}
157
 
 
158
 
#ifndef timersub
159
 
#define timersub(a, b, result) \
160
 
do { \
161
 
        (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
162
 
        (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
163
 
        if ((result)->tv_usec < 0) { \
164
 
                --(result)->tv_sec; \
165
 
                (result)->tv_usec += 1000000; \
166
 
        } \
167
 
} while (0)
168
 
#endif
169
 
 
170
 
int ai_alsa_xrun(audio_in_t *ai)
171
 
{
172
 
    snd_pcm_status_t *status;
173
 
    int res;
174
 
 
175
 
    snd_pcm_status_alloca(&status);
176
 
    if ((res = snd_pcm_status(ai->alsa.handle, status))<0) {
177
 
        mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_AlsaStatusError, snd_strerror(res));
178
 
        return -1;
179
 
    }
180
 
    if (snd_pcm_status_get_state(status) == SND_PCM_STATE_XRUN) {
181
 
        struct timeval now, diff, tstamp;
182
 
        gettimeofday(&now, 0);
183
 
        snd_pcm_status_get_trigger_tstamp(status, &tstamp);
184
 
        timersub(&now, &tstamp, &diff);
185
 
        mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_AlsaXRUN,
186
 
               diff.tv_sec * 1000 + diff.tv_usec / 1000.0);
187
 
        if (mp_msg_test(MSGT_TV, MSGL_V)) {
188
 
            mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_AlsaStatus);
189
 
            snd_pcm_status_dump(status, ai->alsa.log);
190
 
        }
191
 
        if ((res = snd_pcm_prepare(ai->alsa.handle))<0) {
192
 
            mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_AlsaXRUNPrepareError, snd_strerror(res));
193
 
            return -1;
194
 
        }
195
 
        return 0;               /* ok, data should be accepted again */
196
 
    }
197
 
    mp_msg(MSGT_TV, MSGL_ERR, MSGTR_MPDEMUX_AIALSA_AlsaReadWriteError);
198
 
    return -1;
199
 
}