FFmpeg: libavdevice/oss_enc.c Source File

FFmpeg
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 "libavcodec/avcodec.h"
34 
35 #include "avdevice.h"
36 #include "libavformat/internal.h"
37 
38 #include "oss.h"
39 
40  static int audio_write_header(AVFormatContext *s1)
41 {
42  OSSAudioData *s = s1->priv_data;
43  AVStream *st;
44  int ret;
45 
46  st = s1->streams[0];
47  s->sample_rate = st->codecpar->sample_rate;
48  s->channels = st->codecpar->channels;
49  ret = ff_oss_audio_open(s1, 1, s1->url);
50  if (ret < 0) {
51  return AVERROR(EIO);
52  } else {
53  return 0;
54  }
55 }
56 
57  static int audio_write_packet(AVFormatContext *s1, AVPacket *pkt)
58 {
59  OSSAudioData *s = s1->priv_data;
60  int len, ret;
61  int size= pkt->size;
62  uint8_t *buf= pkt->data;
63 
64  while (size > 0) {
65  len = FFMIN(OSS_AUDIO_BLOCK_SIZE - s->buffer_ptr, size);
66  memcpy(s->buffer + s->buffer_ptr, buf, len);
67  s->buffer_ptr += len;
68  if (s->buffer_ptr >= OSS_AUDIO_BLOCK_SIZE) {
69  for(;;) {
70  ret = write(s->fd, s->buffer, OSS_AUDIO_BLOCK_SIZE);
71  if (ret > 0)
72  break;
73  if (ret < 0 && (errno != EAGAIN && errno != EINTR))
74  return AVERROR(EIO);
75  }
76  s->buffer_ptr = 0;
77  }
78  buf += len;
79  size -= len;
80  }
81  return 0;
82 }
83 
84  static int audio_write_trailer(AVFormatContext *s1)
85 {
86  OSSAudioData *s = s1->priv_data;
87 
88  ff_oss_audio_close(s);
89  return 0;
90 }
91 
92  static const AVClass oss_muxer_class = {
93  .class_name = "OSS muxer",
94  .item_name = av_default_item_name,
95  .version = LIBAVUTIL_VERSION_INT,
96  .category = AV_CLASS_CATEGORY_DEVICE_AUDIO_OUTPUT,
97 };
98 
99  AVOutputFormat ff_oss_muxer = {
100  .name = "oss",
101  .long_name = NULL_IF_CONFIG_SMALL("OSS (Open Sound System) playback"),
102  .priv_data_size = sizeof(OSSAudioData),
103  /* XXX: we make the assumption that the soundcard accepts this format */
104  /* XXX: find better solution with "preinit" method, needed also in
105  other formats */
106  .audio_codec = AV_NE(AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE),
107  .video_codec = AV_CODEC_ID_NONE,
108  .write_header = audio_write_header,
109  .write_packet = audio_write_packet,
110  .write_trailer = audio_write_trailer,
111  .flags = AVFMT_NOFILE,
112  .priv_class = &oss_muxer_class,
113 };
audio_write_trailer
static int audio_write_trailer(AVFormatContext *s1)
Definition: oss_enc.c:84
s
const char * s
Definition: avisynth_c.h:768
OSSAudioData
Definition: oss.h:28
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVPacket::size
int size
Definition: avcodec.h:1431
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
ff_oss_muxer
AVOutputFormat ff_oss_muxer
Definition: oss_enc.c:99
pkt
static AVPacket pkt
Definition: demuxing_decoding.c:54
OSSAudioData::buffer
uint8_t buffer[OSS_AUDIO_BLOCK_SIZE]
Definition: oss.h:36
AVFormatContext
Format I/O context.
Definition: avformat.h:1342
AVClass::class_name
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
uint8_t
Definition: audio_convert.c:194
AV_NE
#define AV_NE(be, le)
Definition: common.h:50
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1410
OSSAudioData::channels
int channels
Definition: oss.h:32
AVPacket::data
uint8_t * data
Definition: avcodec.h:1430
OSS_AUDIO_BLOCK_SIZE
#define OSS_AUDIO_BLOCK_SIZE
Definition: oss.h:26
size
ptrdiff_t size
Definition: opengl_enc.c:101
ff_oss_audio_open
int ff_oss_audio_open(AVFormatContext *s1, int is_output, const char *audio_device)
Definition: oss.c:40
avdevice.h
Main libavdevice API header.
AVERROR
#define AVERROR(e)
Definition: error.h:43
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
AVFormatContext::url
char * url
input or output URL.
Definition: avformat.h:1438
internal.h
common internal API header
FFMIN
#define FFMIN(a, b)
Definition: common.h:96
AVOutputFormat::name
const char * name
Definition: avformat.h:507
AVStream
Stream structure.
Definition: avformat.h:873
avcodec.h
Libavcodec external API header.
OSSAudioData::fd
int fd
Definition: oss.h:30
buf
void * buf
Definition: avisynth_c.h:690
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
audio_write_packet
static int audio_write_packet(AVFormatContext *s1, AVPacket *pkt)
Definition: oss_enc.c:57
s1
#define s1
Definition: regdef.h:38
OSSAudioData::buffer_ptr
int buffer_ptr
Definition: oss.h:37
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: avcodec.h:3994
audio_write_header
static int audio_write_header(AVFormatContext *s1)
Definition: oss_enc.c:40
AVFMT_NOFILE
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:465
ff_oss_audio_close
int ff_oss_audio_close(OSSAudioData *s)
Definition: oss.c:135
len
int len
Definition: vorbis_enc_data.h:452
AVFormatContext::priv_data
void * priv_data
Format private data.
Definition: avformat.h:1370
AVCodecParameters::channels
int channels
Audio only.
Definition: avcodec.h:3990
oss_muxer_class
static const AVClass oss_muxer_class
Definition: oss_enc.c:92
OSSAudioData::sample_rate
int sample_rate
Definition: oss.h:31
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1020
AVPacket
This structure stores compressed data.
Definition: avcodec.h:1407

Generated on Sun May 13 2018 02:03:59 for FFmpeg by   doxygen 1.8.6

AltStyle によって変換されたページ (->オリジナル) /