00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <stdint.h>
00023 #include <sndio.h>
00024
00025 #include "avdevice.h"
00026 #include "sndio_common.h"
00027
00028 static av_cold int audio_write_header(AVFormatContext *s1)
00029 {
00030 SndioData *s = s1->priv_data;
00031 AVStream *st;
00032 int ret;
00033
00034 st = s1->streams[0];
00035 s->sample_rate = st->codec->sample_rate;
00036 s->channels = st->codec->channels;
00037
00038 ret = ff_sndio_open(s1, 1, s1->filename);
00039
00040 return ret;
00041 }
00042
00043 static int audio_write_packet(AVFormatContext *s1, AVPacket *pkt)
00044 {
00045 SndioData *s = s1->priv_data;
00046 uint8_t *buf= pkt->data;
00047 int size = pkt->size;
00048 int len, ret;
00049
00050 while (size > 0) {
00051 len = FFMIN(s->buffer_size - s->buffer_offset, size);
00052 memcpy(s->buffer + s->buffer_offset, buf, len);
00053 buf += len;
00054 size -= len;
00055 s->buffer_offset += len;
00056 if (s->buffer_offset >= s->buffer_size) {
00057 ret = sio_write(s->hdl, s->buffer, s->buffer_size);
00058 if (ret == 0 || sio_eof(s->hdl))
00059 return AVERROR(EIO);
00060 s->softpos += ret;
00061 s->buffer_offset = 0;
00062 }
00063 }
00064
00065 return 0;
00066 }
00067
00068 static int audio_write_trailer(AVFormatContext *s1)
00069 {
00070 SndioData *s = s1->priv_data;
00071
00072 sio_write(s->hdl, s->buffer, s->buffer_offset);
00073
00074 ff_sndio_close(s);
00075
00076 return 0;
00077 }
00078
00079 AVOutputFormat ff_sndio_muxer = {
00080 .name = "sndio",
00081 .long_name = NULL_IF_CONFIG_SMALL("sndio audio playback"),
00082 .priv_data_size = sizeof(SndioData),
00083
00084
00085
00086 .audio_codec = AV_NE(CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE),
00087 .video_codec = CODEC_ID_NONE,
00088 .write_header = audio_write_header,
00089 .write_packet = audio_write_packet,
00090 .write_trailer = audio_write_trailer,
00091 .flags = AVFMT_NOFILE,
00092 };