/*1* ALSA input and output2* Copyright (c) 2007 Luca Abeni ( lucabe72 email it )3* Copyright (c) 2007 Benoit Fouet ( benoit fouet free fr )4*5* This file is part of FFmpeg.6*7* FFmpeg is free software; you can redistribute it and/or8* modify it under the terms of the GNU Lesser General Public9* License as published by the Free Software Foundation; either10* version 2.1 of the License, or (at your option) any later version.11*12* FFmpeg is distributed in the hope that it will be useful,13* but WITHOUT ANY WARRANTY; without even the implied warranty of14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU15* Lesser General Public License for more details.16*17* You should have received a copy of the GNU Lesser General Public18* License along with FFmpeg; if not, write to the Free Software19* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA20*/2122/**23* @file24* ALSA input and output: definitions and structures25* @author Luca Abeni ( lucabe72 email it )26* @author Benoit Fouet ( benoit fouet free fr )27*/2829#ifndef AVDEVICE_ALSA_H30#define AVDEVICE_ALSA_H3132#include <alsa/asoundlib.h>33#include "config.h"34#include "libavutil/log.h"35#include "timefilter.h"36#include "avdevice.h"3738/* XXX: we make the assumption that the soundcard accepts this format */39/* XXX: find better solution with "preinit" method, needed also in40other formats */41#define DEFAULT_CODEC_ID AV_NE(AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE)4243typedef void (*ff_reorder_func)(const void *, void *, int);4445#define ALSA_BUFFER_SIZE_MAX 655364647typedef struct AlsaData {48AVClass *class;49snd_pcm_t *h;50int frame_size; ///< bytes per sample * channels51int period_size; ///< preferred size for reads and writes, in frames52int sample_rate; ///< sample rate set by user53int channels; ///< number of channels set by user54int last_period;55TimeFilter *timefilter;56void (*reorder_func)(const void *, void *, int);57void *reorder_buf;58int reorder_buf_size; ///< in frames59int64_t timestamp; ///< current timestamp, without latency applied.60} AlsaData;6162/**63* Open an ALSA PCM.64*65* @param s media file handle66* @param mode either SND_PCM_STREAM_CAPTURE or SND_PCM_STREAM_PLAYBACK67* @param sample_rate in: requested sample rate;68* out: actually selected sample rate69* @param channels number of channels70* @param codec_id in: requested AVCodecID or AV_CODEC_ID_NONE;71* out: actually selected AVCodecID, changed only if72* AV_CODEC_ID_NONE was requested73*74* @return 0 if OK, AVERROR_xxx on error75*/76av_warn_unused_result77int ff_alsa_open(AVFormatContext *s, snd_pcm_stream_t mode,78unsigned int *sample_rate,79int channels, enum AVCodecID *codec_id);8081/**82* Close the ALSA PCM.83*84* @param s1 media file handle85*86* @return 087*/88int ff_alsa_close(AVFormatContext *s1);8990/**91* Try to recover from ALSA buffer underrun.92*93* @param s1 media file handle94* @param err error code reported by the previous ALSA call95*96* @return 0 if OK, AVERROR_xxx on error97*/98av_warn_unused_result99int ff_alsa_xrun_recover(AVFormatContext *s1, int err);100101av_warn_unused_result102int ff_alsa_extend_reorder_buf(AlsaData *s, int size);103104av_warn_unused_result105int ff_alsa_get_device_list(AVDeviceInfoList *device_list, snd_pcm_stream_t stream_type);106107#endif /* AVDEVICE_ALSA_H */108109110