FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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_SOUNDCARD_H
25 #include <soundcard.h>
26 #else
27 #include <sys/soundcard.h>
28 #endif
29 
30 #if HAVE_UNISTD_H
31 #include <unistd.h>
32 #endif
33 #include <fcntl.h>
34 #include <sys/ioctl.h>
35 
36 #include "libavutil/internal.h"
37 
38 #include "libavcodec/avcodec.h"
39 
40 #include "avdevice.h"
41 #include "libavformat/internal.h"
42 
43 #include "oss.h"
44 
46 {
47  OSSAudioData *s = s1->priv_data;
48  AVStream *st;
49  int ret;
50 
51  st = s1->streams[0];
53  s->channels = st->codecpar->channels;
54  ret = ff_oss_audio_open(s1, 1, s1->filename);
55  if (ret < 0) {
56  return AVERROR(EIO);
57  } else {
58  return 0;
59  }
60 }
61 
63 {
64  OSSAudioData *s = s1->priv_data;
65  int len, ret;
66  int size= pkt->size;
67  uint8_t *buf= pkt->data;
68 
69  while (size > 0) {
70  len = FFMIN(OSS_AUDIO_BLOCK_SIZE - s->buffer_ptr, size);
71  memcpy(s->buffer + s->buffer_ptr, buf, len);
72  s->buffer_ptr += len;
73  if (s->buffer_ptr >= OSS_AUDIO_BLOCK_SIZE) {
74  for(;;) {
75  ret = write(s->fd, s->buffer, OSS_AUDIO_BLOCK_SIZE);
76  if (ret > 0)
77  break;
78  if (ret < 0 && (errno != EAGAIN && errno != EINTR))
79  return AVERROR(EIO);
80  }
81  s->buffer_ptr = 0;
82  }
83  buf += len;
84  size -= len;
85  }
86  return 0;
87 }
88 
90 {
91  OSSAudioData *s = s1->priv_data;
92 
94  return 0;
95 }
96 
97 static const AVClass oss_muxer_class = {
98  .class_name = "OSS muxer",
99  .item_name = av_default_item_name,
100  .version = LIBAVUTIL_VERSION_INT,
102 };
103 
105  .name = "oss",
106  .long_name = NULL_IF_CONFIG_SMALL("OSS (Open Sound System) playback"),
107  .priv_data_size = sizeof(OSSAudioData),
108  /* XXX: we make the assumption that the soundcard accepts this format */
109  /* XXX: find better solution with "preinit" method, needed also in
110  other formats */
112  .video_codec = AV_CODEC_ID_NONE,
113  .write_header = audio_write_header,
114  .write_packet = audio_write_packet,
115  .write_trailer = audio_write_trailer,
116  .flags = AVFMT_NOFILE,
117  .priv_class = &oss_muxer_class,
118 };
static int audio_write_trailer(AVFormatContext *s1)
Definition: oss_enc.c:89
const char * s
Definition: avisynth_c.h:631
#define LIBAVUTIL_VERSION_INT
Definition: version.h:70
int size
Definition: avcodec.h:1581
AVOutputFormat ff_oss_muxer
Definition: oss_enc.c:104
static AVPacket pkt
uint8_t buffer[OSS_AUDIO_BLOCK_SIZE]
Definition: oss.h:36
Format I/O context.
Definition: avformat.h:1325
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
uint8_t
#define AV_NE(be, le)
Definition: common.h:50
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1393
int channels
Definition: oss.h:32
uint8_t * data
Definition: avcodec.h:1580
#define OSS_AUDIO_BLOCK_SIZE
Definition: oss.h:26
ptrdiff_t size
Definition: opengl_enc.c:101
int ff_oss_audio_open(AVFormatContext *s1, int is_output, const char *audio_device)
Definition: oss.c:45
Main libavdevice API header.
av_default_item_name
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
common internal API header
char filename[1024]
input or output filename
Definition: avformat.h:1401
#define FFMIN(a, b)
Definition: common.h:96
const char * name
Definition: avformat.h:522
Stream structure.
Definition: avformat.h:876
Libavcodec external API header.
int fd
Definition: oss.h:30
void * buf
Definition: avisynth_c.h:553
Describe the class of an AVClass context structure.
Definition: log.h:67
static int audio_write_packet(AVFormatContext *s1, AVPacket *pkt)
Definition: oss_enc.c:62
#define s1
Definition: regdef.h:38
int buffer_ptr
Definition: oss.h:37
int sample_rate
Audio only.
Definition: avcodec.h:4032
static int audio_write_header(AVFormatContext *s1)
Definition: oss_enc.c:45
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:476
int ff_oss_audio_close(OSSAudioData *s)
Definition: oss.c:140
int len
void * priv_data
Format private data.
Definition: avformat.h:1353
int channels
Audio only.
Definition: avcodec.h:4028
static const AVClass oss_muxer_class
Definition: oss_enc.c:97
int sample_rate
Definition: oss.h:31
AVCodecParameters * codecpar
Definition: avformat.h:1006
This structure stores compressed data.
Definition: avcodec.h:1557