sndio_enc.c
Go to the documentation of this file.
1 /*
2  * sndio play and grab interface
3  * Copyright (c) 2010 Jacob Meuser
4  *
5  * This file is part of FFmpeg.
6  *
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.
11  *
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.
16  *
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
20  */
21 
22 #include <stdint.h>
23 #include <sndio.h>
24 
25 #include "avdevice.h"
26 #include "sndio_common.h"
27 
29 {
30  SndioData *s = s1->priv_data;
31  AVStream *st;
32  int ret;
33 
34  st = s1->streams[0];
35  s->sample_rate = st->codec->sample_rate;
36  s->channels = st->codec->channels;
37 
38  ret = ff_sndio_open(s1, 1, s1->filename);
39 
40  return ret;
41 }
42 
44 {
45  SndioData *s = s1->priv_data;
46  uint8_t *buf= pkt->data;
47  int size = pkt->size;
48  int len, ret;
49 
50  while (size > 0) {
51  len = FFMIN(s->buffer_size - s->buffer_offset, size);
52  memcpy(s->buffer + s->buffer_offset, buf, len);
53  buf += len;
54  size -= 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))
59  return AVERROR(EIO);
60  s->softpos += ret;
61  s->buffer_offset = 0;
62  }
63  }
64 
65  return 0;
66 }
67 
69 {
70  SndioData *s = s1->priv_data;
71 
72  sio_write(s->hdl, s->buffer, s->buffer_offset);
73 
74  ff_sndio_close(s);
75 
76  return 0;
77 }
78 
80  .name = "sndio",
81  .long_name = NULL_IF_CONFIG_SMALL("sndio audio playback"),
82  .priv_data_size = sizeof(SndioData),
83  /* XXX: we make the assumption that the soundcard accepts this format */
84  /* XXX: find better solution with "preinit" method, needed also in
85  other formats */
87  .video_codec = AV_CODEC_ID_NONE,
88  .write_header = audio_write_header,
89  .write_packet = audio_write_packet,
90  .write_trailer = audio_write_trailer,
91  .flags = AVFMT_NOFILE,
92 };
const char * s
Definition: avisynth_c.h:668
int channels
Definition: sndio_common.h:41
struct SndioData SndioData
int ff_sndio_close(SndioData *s)
Definition: sndio_common.c:112
Format I/O context.
Definition: avformat.h:944
static int audio_write_trailer(AVFormatContext *s1)
Definition: sndio_enc.c:68
uint8_t
#define av_cold
Definition: attributes.h:78
int sample_rate
Definition: sndio_common.h:42
static AVPacket pkt
Definition: demuxing.c:56
#define AV_NE(be, le)
Definition: common.h:44
AVStream ** streams
Definition: avformat.h:992
uint8_t * data
Main libavdevice API header.
uint8_t * buffer
Definition: sndio_common.h:37
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int size
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:662
char filename[1024]
input or output filename
Definition: avformat.h:994
#define FFMIN(a, b)
Definition: common.h:58
ret
Definition: avfilter.c:821
const char * name
Definition: avformat.h:378
Stream structure.
Definition: avformat.h:643
int sample_rate
samples per second
int buffer_size
Definition: sndio_common.h:39
void * buf
Definition: avisynth_c.h:594
int buffer_offset
Definition: sndio_common.h:40
#define s1
Definition: regdef.h:38
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
int64_t softpos
Definition: sndio_common.h:36
struct sio_hdl * hdl
Definition: sndio_common.h:33
av_cold int ff_sndio_open(AVFormatContext *s1, int is_output, const char *audio_device)
Definition: sndio_common.c:36
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:345
static av_cold int audio_write_header(AVFormatContext *s1)
Definition: sndio_enc.c:28
int len
int channels
number of audio channels
AVOutputFormat ff_sndio_muxer
Definition: sndio_enc.c:79
void * priv_data
Format private data.
Definition: avformat.h:964
static int audio_write_packet(AVFormatContext *s1, AVPacket *pkt)
Definition: sndio_enc.c:43
This structure stores compressed data.