FFmpeg
Loading...
Searching...
No Matches
oss_enc.c
Go to the documentation of this file.
1/*
2 * Linux audio grab interface
3 * Copyright (c) 2000, 2001 Fabrice Bellard
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 "config.h"
23
24#if HAVE_UNISTD_H
25#include <unistd.h>
26#endif
27#include <fcntl.h>
28#include <sys/ioctl.h>
29#include <sys/soundcard.h>
30
31#include "libavutil/internal.h"
32
33#include "avdevice.h"
35#include "libavformat/mux.h"
36
37#include "oss.h"
38
40{
42 AVStream *st;
43 int ret;
44
45 st = s1->streams[0];
46 s->sample_rate = st->codecpar->sample_rate;
47 s->channels = st->codecpar->ch_layout.nb_channels;
48 ret = ff_oss_audio_open(s1, 1, s1->url);
49 if (ret < 0) {
50 return AVERROR(EIO);
51 } else {
52 return 0;
53 }
54}
55
57{
59 const uint8_t *buf = pkt->data;
60 int len, ret;
61 int size= pkt->size;
62
63 while (size > 0) {
64 len = FFMIN(OSS_AUDIO_BLOCK_SIZE - s->buffer_ptr, size);
65 memcpy(s->buffer + s->buffer_ptr, buf, len);
66 s->buffer_ptr += len;
67 if (s->buffer_ptr >= OSS_AUDIO_BLOCK_SIZE) {
68 for(;;) {
69 ret = write(s->fd, s->buffer, OSS_AUDIO_BLOCK_SIZE);
70 if (ret > 0)
71 break;
72 if (ret < 0 && (errno != EAGAIN && errno != EINTR))
73 return AVERROR(EIO);
74 }
75 s->buffer_ptr = 0;
76 }
77 buf += len;
78 size -= len;
79 }
80 return 0;
81}
82
84{
86
88 return 0;
89}
90
91static const AVClass oss_muxer_class = {
92 .class_name = "OSS outdev",
93 .item_name = av_default_item_name,
94 .version = LIBAVUTIL_VERSION_INT,
96};
97
99 .p.name = "oss",
100 .p.long_name = NULL_IF_CONFIG_SMALL("OSS (Open Sound System) playback"),
101 .priv_data_size = sizeof(OSSAudioData),
102 /* XXX: we make the assumption that the soundcard accepts this format */
103 /* XXX: find better solution with "preinit" method, needed also in
104 other formats */
106 .p.video_codec = AV_CODEC_ID_NONE,
107 .write_header = audio_write_header,
108 .write_packet = audio_write_packet,
109 .write_trailer = audio_write_trailer,
110 .p.flags = AVFMT_NOFILE,
111 .p.priv_class = &oss_muxer_class,
112};
const FFOutputFormat ff_oss_muxer
Definition oss_enc.c:98
static av_cold int audio_write_header(AVFormatContext *s1)
Definition alsa_enc.c:52
static int audio_write_packet(AVFormatContext *s1, AVPacket *pkt)
Definition alsa_enc.c:85
Main libavdevice API header.
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition avformat.h:488
#define s(width, name)
Definition cbs_vp9.c:198
static AVPacket * pkt
@ AV_CODEC_ID_PCM_S16LE
Definition codec_id.h:330
@ AV_CODEC_ID_NONE
Definition codec_id.h:48
@ AV_CODEC_ID_PCM_S16BE
Definition codec_id.h:331
#define AVERROR(e)
Definition error.h:45
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
@ AV_CLASS_CATEGORY_DEVICE_AUDIO_OUTPUT
Definition log.h:43
#define FFMIN(a, b)
Definition macros.h:49
#define AV_NE(be, le)
Definition macros.h:33
int ff_oss_audio_open(AVFormatContext *s1, int is_output, const char *audio_device)
Definition oss.c:40
int ff_oss_audio_close(OSSAudioData *s)
Definition oss.c:137
#define OSS_AUDIO_BLOCK_SIZE
Definition oss.h:27
static int audio_write_trailer(AVFormatContext *s1)
Definition oss_enc.c:83
static int audio_write_packet(AVFormatContext *s1, AVPacket *pkt)
Definition oss_enc.c:56
static const AVClass oss_muxer_class
Definition oss_enc.c:91
static int audio_write_header(AVFormatContext *s1)
Definition oss_enc.c:39
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
Definition log.h:76
AVChannelLayout ch_layout
The channel layout and number of channels.
Definition codec_par.h:207
int sample_rate
The number of audio samples per second.
Definition codec_par.h:213
Format I/O context.
Definition avformat.h:1333
char * url
input or output URL.
Definition avformat.h:1449
void * priv_data
Format private data.
Definition avformat.h:1361
AVStream ** streams
A list of all streams in the file.
Definition avformat.h:1401
This structure stores compressed data.
Definition packet.h:580
Stream structure.
Definition avformat.h:766
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:789
int size
int len