2 * sndio play and grab interface
3 * Copyright (c) 2010 Jacob Meuser
5 * This file is part of FFmpeg.
7 * FFmpeg 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 * FFmpeg 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 FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #include "sndio_common.h"
28 static av_cold
int audio_write_header(AVFormatContext
*s1
)
30 SndioData
*s
= s1
->priv_data
;
35 s
->sample_rate
= st
->codec
->sample_rate
;
36 s
->channels
= st
->codec
->channels
;
38 ret
= ff_sndio_open(s1
, 1, s1
->filename
);
43 static int audio_write_packet(AVFormatContext
*s1
, AVPacket
*pkt
)
45 SndioData
*s
= s1
->priv_data
;
46 uint8_t *buf
= pkt
->data
;
51 len
= FFMIN(s
->buffer_size
- s
->buffer_offset
, size
);
52 memcpy(s
->buffer
+ s
->buffer_offset
, buf
, len
);
55 s
->buffer_offset
+= len
;
56 if (s
->buffer_offset
>= s
->buffer_size
) {
57 ret
= sio_write(s
->hdl
, s
->buffer
, s
->buffer_size
);
58 if (ret
== 0 || sio_eof(s
->hdl
))
68 static int audio_write_trailer(AVFormatContext
*s1
)
70 SndioData
*s
= s1
->priv_data
;
72 sio_write(s
->hdl
, s
->buffer
, s
->buffer_offset
);
79 static const AVClass sndio_muxer_class
= {
80 .class_name
= "sndio outdev",
81 .item_name
= av_default_item_name
,
82 .version
= LIBAVUTIL_VERSION_INT
,
83 .category
= AV_CLASS_CATEGORY_DEVICE_AUDIO_OUTPUT
,
86 AVOutputFormat ff_sndio_muxer
= {
88 .long_name
= NULL_IF_CONFIG_SMALL("sndio audio playback"),
89 .priv_data_size
= sizeof(SndioData
),
90 /* XXX: we make the assumption that the soundcard accepts this format */
91 /* XXX: find better solution with "preinit" method, needed also in
93 .audio_codec
= AV_NE(AV_CODEC_ID_PCM_S16BE
, AV_CODEC_ID_PCM_S16LE
),
94 .video_codec
= AV_CODEC_ID_NONE
,
95 .write_header
= audio_write_header
,
96 .write_packet
= audio_write_packet
,
97 .write_trailer
= audio_write_trailer
,
98 .flags
= AVFMT_NOFILE
,
99 .priv_class
= &sndio_muxer_class
,