annotate ffmpeg/libavdevice/sndio_enc.c @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents 6840f77b83aa
children
rev   line source
yading@10 1 /*
yading@10 2 * sndio play and grab interface
yading@10 3 * Copyright (c) 2010 Jacob Meuser
yading@10 4 *
yading@10 5 * This file is part of FFmpeg.
yading@10 6 *
yading@10 7 * FFmpeg is free software; you can redistribute it and/or
yading@10 8 * modify it under the terms of the GNU Lesser General Public
yading@10 9 * License as published by the Free Software Foundation; either
yading@10 10 * version 2.1 of the License, or (at your option) any later version.
yading@10 11 *
yading@10 12 * FFmpeg is distributed in the hope that it will be useful,
yading@10 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@10 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@10 15 * Lesser General Public License for more details.
yading@10 16 *
yading@10 17 * You should have received a copy of the GNU Lesser General Public
yading@10 18 * License along with FFmpeg; if not, write to the Free Software
yading@10 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@10 20 */
yading@10 21
yading@10 22 #include <stdint.h>
yading@10 23 #include <sndio.h>
yading@10 24
yading@10 25 #include "avdevice.h"
yading@10 26 #include "sndio_common.h"
yading@10 27
yading@10 28 static av_cold int audio_write_header(AVFormatContext *s1)
yading@10 29 {
yading@10 30 SndioData *s = s1->priv_data;
yading@10 31 AVStream *st;
yading@10 32 int ret;
yading@10 33
yading@10 34 st = s1->streams[0];
yading@10 35 s->sample_rate = st->codec->sample_rate;
yading@10 36 s->channels = st->codec->channels;
yading@10 37
yading@10 38 ret = ff_sndio_open(s1, 1, s1->filename);
yading@10 39
yading@10 40 return ret;
yading@10 41 }
yading@10 42
yading@10 43 static int audio_write_packet(AVFormatContext *s1, AVPacket *pkt)
yading@10 44 {
yading@10 45 SndioData *s = s1->priv_data;
yading@10 46 uint8_t *buf= pkt->data;
yading@10 47 int size = pkt->size;
yading@10 48 int len, ret;
yading@10 49
yading@10 50 while (size > 0) {
yading@10 51 len = FFMIN(s->buffer_size - s->buffer_offset, size);
yading@10 52 memcpy(s->buffer + s->buffer_offset, buf, len);
yading@10 53 buf += len;
yading@10 54 size -= len;
yading@10 55 s->buffer_offset += len;
yading@10 56 if (s->buffer_offset >= s->buffer_size) {
yading@10 57 ret = sio_write(s->hdl, s->buffer, s->buffer_size);
yading@10 58 if (ret == 0 || sio_eof(s->hdl))
yading@10 59 return AVERROR(EIO);
yading@10 60 s->softpos += ret;
yading@10 61 s->buffer_offset = 0;
yading@10 62 }
yading@10 63 }
yading@10 64
yading@10 65 return 0;
yading@10 66 }
yading@10 67
yading@10 68 static int audio_write_trailer(AVFormatContext *s1)
yading@10 69 {
yading@10 70 SndioData *s = s1->priv_data;
yading@10 71
yading@10 72 sio_write(s->hdl, s->buffer, s->buffer_offset);
yading@10 73
yading@10 74 ff_sndio_close(s);
yading@10 75
yading@10 76 return 0;
yading@10 77 }
yading@10 78
yading@10 79 AVOutputFormat ff_sndio_muxer = {
yading@10 80 .name = "sndio",
yading@10 81 .long_name = NULL_IF_CONFIG_SMALL("sndio audio playback"),
yading@10 82 .priv_data_size = sizeof(SndioData),
yading@10 83 /* XXX: we make the assumption that the soundcard accepts this format */
yading@10 84 /* XXX: find better solution with "preinit" method, needed also in
yading@10 85 other formats */
yading@10 86 .audio_codec = AV_NE(AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE),
yading@10 87 .video_codec = AV_CODEC_ID_NONE,
yading@10 88 .write_header = audio_write_header,
yading@10 89 .write_packet = audio_write_packet,
yading@10 90 .write_trailer = audio_write_trailer,
yading@10 91 .flags = AVFMT_NOFILE,
yading@10 92 };