• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavdevice/sndio_enc.c

Go to the documentation of this file.
00001 /*
00002  * sndio play and grab interface
00003  * Copyright (c) 2010 Jacob Meuser
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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     /* XXX: we make the assumption that the soundcard accepts this format */
00084     /* XXX: find better solution with "preinit" method, needed also in
00085        other formats */
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 };

Generated on Fri Feb 22 2013 07:24:30 for FFmpeg by  doxygen 1.7.1