alsa-audio.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 Libav.
  7. *
  8. * Libav 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. * Libav 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 Libav; 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_AUDIO_H
  29. #define AVDEVICE_ALSA_AUDIO_H
  30. #include <alsa/asoundlib.h>
  31. #include "config.h"
  32. #include "libavformat/avformat.h"
  33. #include "libavutil/log.h"
  34. /* XXX: we make the assumption that the soundcard accepts this format */
  35. /* XXX: find better solution with "preinit" method, needed also in
  36. other formats */
  37. #define DEFAULT_CODEC_ID AV_NE(CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE)
  38. typedef struct {
  39. AVClass *class;
  40. snd_pcm_t *h;
  41. int frame_size; ///< preferred size for reads and writes
  42. int period_size; ///< bytes per sample * channels
  43. int sample_rate; ///< sample rate set by user
  44. int channels; ///< number of channels set by user
  45. void (*reorder_func)(const void *, void *, int);
  46. void *reorder_buf;
  47. int reorder_buf_size; ///< in frames
  48. } AlsaData;
  49. /**
  50. * Open an ALSA PCM.
  51. *
  52. * @param s media file handle
  53. * @param mode either SND_PCM_STREAM_CAPTURE or SND_PCM_STREAM_PLAYBACK
  54. * @param sample_rate in: requested sample rate;
  55. * out: actually selected sample rate
  56. * @param channels number of channels
  57. * @param codec_id in: requested CodecID or CODEC_ID_NONE;
  58. * out: actually selected CodecID, changed only if
  59. * CODEC_ID_NONE was requested
  60. *
  61. * @return 0 if OK, AVERROR_xxx on error
  62. */
  63. int ff_alsa_open(AVFormatContext *s, snd_pcm_stream_t mode,
  64. unsigned int *sample_rate,
  65. int channels, enum CodecID *codec_id);
  66. /**
  67. * Close the ALSA PCM.
  68. *
  69. * @param s1 media file handle
  70. *
  71. * @return 0
  72. */
  73. int ff_alsa_close(AVFormatContext *s1);
  74. /**
  75. * Try to recover from ALSA buffer underrun.
  76. *
  77. * @param s1 media file handle
  78. * @param err error code reported by the previous ALSA call
  79. *
  80. * @return 0 if OK, AVERROR_xxx on error
  81. */
  82. int ff_alsa_xrun_recover(AVFormatContext *s1, int err);
  83. int ff_alsa_extend_reorder_buf(AlsaData *s, int size);
  84. #endif /* AVDEVICE_ALSA_AUDIO_H */