Revision 15d59d2c

View differences:

Changelog
79 79
- Bink version 'b' audio and video decoder
80 80
- Bitmap Brothers JV playback system
81 81
- Apple HTTP Live Streaming protocol handler
82
- sndio support for playback and record
82 83

  
83 84

  
84 85
version 0.6:
configure
1094 1094
    sdl
1095 1095
    sdl_video_size
1096 1096
    setmode
1097
    sndio_h
1097 1098
    socklen_t
1098 1099
    soundcard_h
1099 1100
    poll_h
......
1433 1434
libdc1394_indev_deps="libdc1394"
1434 1435
oss_indev_deps_any="soundcard_h sys_soundcard_h"
1435 1436
oss_outdev_deps_any="soundcard_h sys_soundcard_h"
1437
sndio_indev_deps="sndio_h"
1438
sndio_outdev_deps="sndio_h"
1436 1439
v4l_indev_deps="linux_videodev_h"
1437 1440
v4l2_indev_deps_any="linux_videodev2_h sys_videoio_h"
1438 1441
vfwcap_indev_deps="capCreateCaptureWindow vfwcap_defines"
......
2912 2915
  check_header dev/video/bktr/ioctl_bt848.h; } ||
2913 2916
check_header dev/ic/bt8xx.h
2914 2917

  
2918
check_header sndio.h
2915 2919
check_header sys/soundcard.h
2916 2920
check_header soundcard.h
2917 2921

  
......
2919 2923

  
2920 2924
enabled jack_indev && check_lib2 jack/jack.h jack_client_open -ljack
2921 2925

  
2926
enabled_any sndio_indev sndio_outdev && check_lib2 sndio.h sio_open -lsndio
2927

  
2922 2928
enabled x11grab                         &&
2923 2929
check_header X11/Xlib.h                 &&
2924 2930
check_header X11/extensions/XShm.h      &&
doc/indevs.texi
129 129
For more information about OSS see:
130 130
@url{http://manuals.opensound.com/usersguide/dsp.html}
131 131

  
132
@section sndio
133

  
134
sndio input device.
135

  
136
To enable this input device during configuration you need libsndio
137
installed on your system.
138

  
139
The filename to provide to the input device is the device node
140
representing the sndio input device, and is usually set to
141
@file{/dev/audio0}.
142

  
143
For example to grab from @file{/dev/audio0} using @file{ffmpeg} use the
144
command:
145
@example
146
ffmpeg -f sndio -i /dev/audio0 /tmp/oss.wav
147
@end example
148

  
132 149
@section video4linux and video4linux2
133 150

  
134 151
Video4Linux and Video4Linux2 input video devices.
doc/outdevs.texi
26 26

  
27 27
OSS (Open Sound System) output device.
28 28

  
29
@section sndio
30

  
31
sndio audio output device.
32

  
29 33
@c man end OUTPUT DEVICES
libavdevice/Makefile
17 17
OBJS-$(CONFIG_JACK_INDEV)                += jack_audio.o
18 18
OBJS-$(CONFIG_OSS_INDEV)                 += oss_audio.o
19 19
OBJS-$(CONFIG_OSS_OUTDEV)                += oss_audio.o
20
OBJS-$(CONFIG_SNDIO_INDEV)               += sndio_common.o sndio_dec.o
21
OBJS-$(CONFIG_SNDIO_OUTDEV)              += sndio_common.o sndio_enc.o
20 22
OBJS-$(CONFIG_V4L2_INDEV)                += v4l2.o
21 23
OBJS-$(CONFIG_V4L_INDEV)                 += v4l.o
22 24
OBJS-$(CONFIG_VFWCAP_INDEV)              += vfwcap.o
......
26 28
OBJS-$(CONFIG_LIBDC1394_INDEV)           += libdc1394.o
27 29

  
28 30
SKIPHEADERS-$(HAVE_ALSA_ASOUNDLIB_H)     += alsa-audio.h
31
SKIPHEADERS-$(HAVE_SNDIO_H)              += sndio_common.h
29 32

  
30 33
include $(SUBDIR)../subdir.mak
libavdevice/alldevices.c
44 44
    REGISTER_INDEV    (DV1394, dv1394);
45 45
    REGISTER_INDEV    (JACK, jack);
46 46
    REGISTER_INOUTDEV (OSS, oss);
47
    REGISTER_INOUTDEV (SNDIO, sndio);
47 48
    REGISTER_INDEV    (V4L2, v4l2);
48 49
    REGISTER_INDEV    (V4L, v4l);
49 50
    REGISTER_INDEV    (VFWCAP, vfwcap);
libavdevice/avdevice.h
22 22
#include "libavutil/avutil.h"
23 23

  
24 24
#define LIBAVDEVICE_VERSION_MAJOR 52
25
#define LIBAVDEVICE_VERSION_MINOR  2
26
#define LIBAVDEVICE_VERSION_MICRO  3
25
#define LIBAVDEVICE_VERSION_MINOR  3
26
#define LIBAVDEVICE_VERSION_MICRO  0
27 27

  
28 28
#define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \
29 29
                                               LIBAVDEVICE_VERSION_MINOR, \
libavdevice/sndio_common.c
1
/*
2
 * sndio play and grab interface
3
 * Copyright (c) 2010 Jacob Meuser
4
 *
5
 * This file is part of Libav.
6
 *
7
 * Libav 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
 * Libav 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 Libav; 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 "libavformat/avformat.h"
26

  
27
#include "sndio_common.h"
28

  
29
static inline void movecb(void *addr, int delta)
30
{
31
    SndioData *s = addr;
32

  
33
    s->hwpos += delta * s->channels * s->bps;
34
}
35

  
36
av_cold int ff_sndio_open(AVFormatContext *s1, int is_output,
37
                          const char *audio_device)
38
{
39
    SndioData *s = s1->priv_data;
40
    struct sio_hdl *hdl;
41
    struct sio_par par;
42

  
43
    hdl = sio_open(audio_device, is_output ? SIO_PLAY : SIO_REC, 0);
44
    if (!hdl) {
45
        av_log(s1, AV_LOG_ERROR, "Could not open sndio device\n");
46
        return AVERROR(EIO);
47
    }
48

  
49
    sio_initpar(&par);
50

  
51
    par.bits = 16;
52
    par.sig  = 1;
53
    par.le   = SIO_LE_NATIVE;
54

  
55
    if (is_output)
56
        par.pchan = s->channels;
57
    else
58
        par.rchan = s->channels;
59
    par.rate = s->sample_rate;
60

  
61
    if (!sio_setpar(hdl, &par) || !sio_getpar(hdl, &par)) {
62
        av_log(s1, AV_LOG_ERROR, "Impossible to set sndio parameters, "
63
               "channels: %d sample rate: %d\n", s->channels, s->sample_rate);
64
        goto fail;
65
    }
66

  
67
    if (par.bits != 16 || par.sig != 1 || par.le != SIO_LE_NATIVE ||
68
        (is_output  && (par.pchan != s->channels)) ||
69
        (!is_output && (par.rchan != s->channels)) ||
70
        (par.rate != s->sample_rate)) {
71
        av_log(s1, AV_LOG_ERROR, "Could not set appropriate sndio parameters, "
72
               "channels: %d sample rate: %d\n", s->channels, s->sample_rate);
73
        goto fail;
74
    }
75

  
76
    s->buffer_size = par.round * par.bps *
77
                     (is_output ? par.pchan : par.rchan);
78

  
79
    if (is_output) {
80
        s->buffer = av_malloc(s->buffer_size);
81
        if (!s->buffer) {
82
            av_log(s1, AV_LOG_ERROR, "Could not allocate buffer\n");
83
            goto fail;
84
        }
85
    }
86

  
87
    s->codec_id    = par.le ? CODEC_ID_PCM_S16LE : CODEC_ID_PCM_S16BE;
88
    s->channels    = is_output ? par.pchan : par.rchan;
89
    s->sample_rate = par.rate;
90
    s->bps         = par.bps;
91

  
92
    sio_onmove(hdl, movecb, s);
93

  
94
    if (!sio_start(hdl)) {
95
        av_log(s1, AV_LOG_ERROR, "Could not start sndio\n");
96
        goto fail;
97
    }
98

  
99
    s->hdl = hdl;
100

  
101
    return 0;
102

  
103
fail:
104
    av_freep(&s->buffer);
105

  
106
    if (hdl)
107
        sio_close(hdl);
108

  
109
    return AVERROR(EIO);
110
}
111

  
112
int ff_sndio_close(SndioData *s)
113
{
114
    av_freep(&s->buffer);
115

  
116
    if (s->hdl)
117
        sio_close(s->hdl);
118

  
119
    return 0;
120
}
libavdevice/sndio_common.h
1
/*
2
 * sndio play and grab interface
3
 * Copyright (c) 2010 Jacob Meuser
4
 *
5
 * This file is part of Libav.
6
 *
7
 * Libav 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
 * Libav 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 Libav; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
 */
21

  
22
#ifndef AVDEVICE_SNDIO_COMMON_H
23
#define AVDEVICE_SNDIO_COMMON_H
24

  
25
#include <stdint.h>
26
#include <sndio.h>
27

  
28
#include "libavformat/avformat.h"
29

  
30
typedef struct {
31
    struct sio_hdl *hdl;
32
    enum CodecID codec_id;
33
    int64_t hwpos;
34
    int64_t softpos;
35
    uint8_t *buffer;
36
    int bps;
37
    int buffer_size;
38
    int buffer_offset;
39
    int channels;
40
    int sample_rate;
41
} SndioData;
42

  
43
int ff_sndio_open(AVFormatContext *s1, int is_output, const char *audio_device);
44
int ff_sndio_close(SndioData *s);
45

  
46
#endif /* AVDEVICE_SNDIO_COMMON_H */
libavdevice/sndio_dec.c
1
/*
2
 * sndio play and grab interface
3
 * Copyright (c) 2010 Jacob Meuser
4
 *
5
 * This file is part of Libav.
6
 *
7
 * Libav 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
 * Libav 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 Libav; 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 "libavformat/avformat.h"
26

  
27
#include "sndio_common.h"
28

  
29
static av_cold int audio_read_header(AVFormatContext *s1,
30
                                     AVFormatParameters *ap)
31
{
32
    SndioData *s = s1->priv_data;
33
    AVStream *st;
34
    int ret;
35

  
36
    if (ap->sample_rate <= 0 || ap->channels <= 0)
37
        return AVERROR(EINVAL);
38

  
39
    st = av_new_stream(s1, 0);
40
    if (!st)
41
        return AVERROR(ENOMEM);
42

  
43
    s->sample_rate = ap->sample_rate;
44
    s->channels    = ap->channels;
45

  
46
    ret = ff_sndio_open(s1, 0, s1->filename);
47
    if (ret < 0)
48
        return ret;
49

  
50
    /* take real parameters */
51
    st->codec->codec_type  = AVMEDIA_TYPE_AUDIO;
52
    st->codec->codec_id    = s->codec_id;
53
    st->codec->sample_rate = s->sample_rate;
54
    st->codec->channels    = s->channels;
55

  
56
    av_set_pts_info(st, 64, 1, 1000000);  /* 64 bits pts in us */
57

  
58
    return 0;
59
}
60

  
61
static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)
62
{
63
    SndioData *s = s1->priv_data;
64
    int64_t bdelay, cur_time;
65
    int ret;
66

  
67
    if ((ret = av_new_packet(pkt, s->buffer_size)) < 0)
68
        return ret;
69

  
70
    ret = sio_read(s->hdl, pkt->data, pkt->size);
71
    if (ret == 0 || sio_eof(s->hdl)) {
72
        av_free_packet(pkt);
73
        return AVERROR_EOF;
74
    }
75

  
76
    pkt->size   = ret;
77
    s->softpos += ret;
78

  
79
    /* compute pts of the start of the packet */
80
    cur_time = av_gettime();
81

  
82
    bdelay = ret + s->hwpos - s->softpos;
83

  
84
    /* convert to pts */
85
    pkt->pts = cur_time - ((bdelay * 1000000) /
86
        (s->bps * s->channels * s->sample_rate));
87

  
88
    return 0;
89
}
90

  
91
static av_cold int audio_read_close(AVFormatContext *s1)
92
{
93
    SndioData *s = s1->priv_data;
94

  
95
    ff_sndio_close(s);
96

  
97
    return 0;
98
}
99

  
100
AVInputFormat ff_sndio_demuxer = {
101
    .name           = "sndio",
102
    .long_name      = NULL_IF_CONFIG_SMALL("sndio audio capture"),
103
    .priv_data_size = sizeof(SndioData),
104
    .read_header    = audio_read_header,
105
    .read_packet    = audio_read_packet,
106
    .read_close     = audio_read_close,
107
    .flags          = AVFMT_NOFILE,
108
};
libavdevice/sndio_enc.c
1
/*
2
 * sndio play and grab interface
3
 * Copyright (c) 2010 Jacob Meuser
4
 *
5
 * This file is part of Libav.
6
 *
7
 * Libav 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
 * Libav 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 Libav; 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 "libavformat/avformat.h"
26

  
27
#include "sndio_common.h"
28

  
29
static av_cold int audio_write_header(AVFormatContext *s1)
30
{
31
    SndioData *s = s1->priv_data;
32
    AVStream *st;
33
    int ret;
34

  
35
    st             = s1->streams[0];
36
    s->sample_rate = st->codec->sample_rate;
37
    s->channels    = st->codec->channels;
38

  
39
    ret = ff_sndio_open(s1, 1, s1->filename);
40

  
41
    return ret;
42
}
43

  
44
static int audio_write_packet(AVFormatContext *s1, AVPacket *pkt)
45
{
46
    SndioData *s = s1->priv_data;
47
    uint8_t *buf= pkt->data;
48
    int size = pkt->size;
49
    int len, ret;
50

  
51
    while (size > 0) {
52
        len = s->buffer_size - s->buffer_offset;
53
        if (len > size)
54
            len = size;
55
        memcpy(s->buffer + s->buffer_offset, buf, len);
56
        buf  += len;
57
        size -= len;
58
        s->buffer_offset += len;
59
        if (s->buffer_offset >= s->buffer_size) {
60
            ret = sio_write(s->hdl, s->buffer, s->buffer_size);
61
            if (ret == 0 || sio_eof(s->hdl))
62
                return AVERROR(EIO);
63
            s->softpos      += ret;
64
            s->buffer_offset = 0;
65
        }
66
    }
67

  
68
    return 0;
69
}
70

  
71
static int audio_write_trailer(AVFormatContext *s1)
72
{
73
    SndioData *s = s1->priv_data;
74

  
75
    sio_write(s->hdl, s->buffer, s->buffer_offset);
76

  
77
    ff_sndio_close(s);
78

  
79
    return 0;
80
}
81

  
82
AVOutputFormat ff_sndio_muxer = {
83
    .name           = "sndio",
84
    .long_name      = NULL_IF_CONFIG_SMALL("sndio audio playback"),
85
    .priv_data_size = sizeof(SndioData),
86
    /* XXX: we make the assumption that the soundcard accepts this format */
87
    /* XXX: find better solution with "preinit" method, needed also in
88
       other formats */
89
    .audio_codec    = AV_NE(CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE),
90
    .video_codec    = CODEC_ID_NONE,
91
    .write_header   = audio_write_header,
92
    .write_packet   = audio_write_packet,
93
    .write_trailer  = audio_write_trailer,
94
    .flags          = AVFMT_NOFILE,
95
};

Also available in: Unified diff