alsa.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * ALSA input and output
  3. * Copyright (c) 2007 Luca Abeni ( lucabe72 email it )
  4. * Copyright (c) 2007 Benoit Fouet ( benoit fouet free fr )
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. /**
  23. * @file
  24. * ALSA input and output: definitions and structures
  25. * @author Luca Abeni ( lucabe72 email it )
  26. * @author Benoit Fouet ( benoit fouet free fr )
  27. */
  28. #ifndef AVDEVICE_ALSA_H
  29. #define AVDEVICE_ALSA_H
  30. #include <alsa/asoundlib.h>
  31. #include "config.h"
  32. #include "libavutil/log.h"
  33. #include "timefilter.h"
  34. #include "avdevice.h"
  35. /* XXX: we make the assumption that the soundcard accepts this format */
  36. /* XXX: find better solution with "preinit" method, needed also in
  37. other formats */
  38. #define DEFAULT_CODEC_ID AV_NE(AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE)
  39. typedef void (*ff_reorder_func)(const void *, void *, int);
  40. #define ALSA_BUFFER_SIZE_MAX 131072
  41. typedef struct AlsaData {
  42. AVClass *class;
  43. snd_pcm_t *h;
  44. int frame_size; ///< bytes per sample * channels
  45. int period_size; ///< preferred size for reads and writes, in frames
  46. int sample_rate; ///< sample rate set by user
  47. int channels; ///< number of channels set by user
  48. int last_period;
  49. TimeFilter *timefilter;
  50. void (*reorder_func)(const void *, void *, int);
  51. void *reorder_buf;
  52. int reorder_buf_size; ///< in frames
  53. int64_t timestamp; ///< current timestamp, without latency applied.
  54. AVPacket *pkt;
  55. } AlsaData;
  56. /**
  57. * Open an ALSA PCM.
  58. *
  59. * @param s media file handle
  60. * @param mode either SND_PCM_STREAM_CAPTURE or SND_PCM_STREAM_PLAYBACK
  61. * @param sample_rate in: requested sample rate;
  62. * out: actually selected sample rate
  63. * @param channels number of channels
  64. * @param codec_id in: requested AVCodecID or AV_CODEC_ID_NONE;
  65. * out: actually selected AVCodecID, changed only if
  66. * AV_CODEC_ID_NONE was requested
  67. *
  68. * @return 0 if OK, AVERROR_xxx on error
  69. */
  70. av_warn_unused_result
  71. int ff_alsa_open(AVFormatContext *s, snd_pcm_stream_t mode,
  72. unsigned int *sample_rate,
  73. int channels, enum AVCodecID *codec_id);
  74. /**
  75. * Close the ALSA PCM.
  76. *
  77. * @param s1 media file handle
  78. *
  79. * @return 0
  80. */
  81. int ff_alsa_close(AVFormatContext *s1);
  82. /**
  83. * Try to recover from ALSA buffer underrun.
  84. *
  85. * @param s1 media file handle
  86. * @param err error code reported by the previous ALSA call
  87. *
  88. * @return 0 if OK, AVERROR_xxx on error
  89. */
  90. av_warn_unused_result
  91. int ff_alsa_xrun_recover(AVFormatContext *s1, int err);
  92. av_warn_unused_result
  93. int ff_alsa_extend_reorder_buf(AlsaData *s, int size);
  94. av_warn_unused_result
  95. int ff_alsa_get_device_list(AVDeviceInfoList *device_list, snd_pcm_stream_t stream_type);
  96. #endif /* AVDEVICE_ALSA_H */