2 * Linux audio grab interface
3 * Copyright (c) 2000, 2001 Fabrice Bellard
5 * This file is part of Libav.
7 * Libav is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * Libav is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with Libav; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <soundcard.h>
27 #include <sys/soundcard.h>
32 #include <sys/ioctl.h>
34 #include "libavutil/internal.h"
36 #include "libavcodec/avcodec.h"
38 #include "libavformat/avformat.h"
39 #include "libavformat/internal.h"
43 static int audio_write_header(AVFormatContext *s1)
45 OSSAudioData *s = s1->priv_data;
50 s->sample_rate = st->codec->sample_rate;
51 s->channels = st->codec->channels;
52 ret = ff_oss_audio_open(s1, 1, s1->filename);
60 static int audio_write_packet(AVFormatContext *s1, AVPacket *pkt)
62 OSSAudioData *s = s1->priv_data;
65 uint8_t *buf= pkt->data;
68 len = FFMIN(OSS_AUDIO_BLOCK_SIZE - s->buffer_ptr, size);
69 memcpy(s->buffer + s->buffer_ptr, buf, len);
71 if (s->buffer_ptr >= OSS_AUDIO_BLOCK_SIZE) {
73 ret = write(s->fd, s->buffer, OSS_AUDIO_BLOCK_SIZE);
76 if (ret < 0 && (errno != EAGAIN && errno != EINTR))
87 static int audio_write_trailer(AVFormatContext *s1)
89 OSSAudioData *s = s1->priv_data;
91 ff_oss_audio_close(s);
95 AVOutputFormat ff_oss_muxer = {
97 .long_name = NULL_IF_CONFIG_SMALL("OSS (Open Sound System) playback"),
98 .priv_data_size = sizeof(OSSAudioData),
99 /* XXX: we make the assumption that the soundcard accepts this format */
100 /* XXX: find better solution with "preinit" method, needed also in
102 .audio_codec = AV_NE(AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE),
103 .video_codec = AV_CODEC_ID_NONE,
104 .write_header = audio_write_header,
105 .write_packet = audio_write_packet,
106 .write_trailer = audio_write_trailer,
107 .flags = AVFMT_NOFILE,