X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavdevice%2Foss_audio.c;h=af46ea890b68d42ce61091b48737a2b43a6e11fa;hb=8fe7b6443fe8721215f1abac3b854cd52092c909;hp=f3edbdbef0ccb01685ed31162bbfa27544ca89d6;hpb=d3298350bba0d5bdb43485356aa752528ec48d11;p=ffmpeg diff --git a/libavdevice/oss_audio.c b/libavdevice/oss_audio.c index f3edbdbef0c..af46ea890b6 100644 --- a/libavdevice/oss_audio.c +++ b/libavdevice/oss_audio.c @@ -2,20 +2,20 @@ * Linux audio play and grab interface * Copyright (c) 2000, 2001 Fabrice Bellard * - * This file is part of FFmpeg. + * This file is part of Libav. * - * FFmpeg is free software; you can redistribute it and/or + * Libav is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * FFmpeg is distributed in the hope that it will be useful, + * Libav is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software + * License along with Libav; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -37,12 +37,14 @@ #include #include "libavutil/log.h" +#include "libavutil/opt.h" #include "libavcodec/avcodec.h" #include "libavformat/avformat.h" #define AUDIO_BLOCK_SIZE 4096 typedef struct { + AVClass *class; int fd; int sample_rate; int channels; @@ -216,15 +218,17 @@ static int audio_read_header(AVFormatContext *s1, AVFormatParameters *ap) AVStream *st; int ret; - if (ap->sample_rate <= 0 || ap->channels <= 0) - return -1; +#if FF_API_FORMAT_PARAMETERS + if (ap->sample_rate > 0) + s->sample_rate = ap->sample_rate; + if (ap->channels > 0) + s->channels = ap->channels; +#endif st = av_new_stream(s1, 0); if (!st) { return AVERROR(ENOMEM); } - s->sample_rate = ap->sample_rate; - s->channels = ap->channels; ret = audio_open(s1, 0, s1->filename); if (ret < 0) { @@ -232,7 +236,7 @@ static int audio_read_header(AVFormatContext *s1, AVFormatParameters *ap) } /* take real parameters */ - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = s->codec_id; st->codec->sample_rate = s->sample_rate; st->codec->channels = s->channels; @@ -251,12 +255,12 @@ static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt) if ((ret=av_new_packet(pkt, s->frame_size)) < 0) return ret; - ret = read(s->fd, pkt->data, pkt->size); + ret = read(s->fd, pkt->data, pkt->size); if (ret <= 0){ av_free_packet(pkt); pkt->size = 0; if (ret<0) return AVERROR(errno); - else return AVERROR(EOF); + else return AVERROR_EOF; } pkt->size = ret; @@ -293,7 +297,20 @@ static int audio_read_close(AVFormatContext *s1) } #if CONFIG_OSS_INDEV -AVInputFormat oss_demuxer = { +static const AVOption options[] = { + { "sample_rate", "", offsetof(AudioData, sample_rate), FF_OPT_TYPE_INT, {.dbl = 48000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, + { "channels", "", offsetof(AudioData, channels), FF_OPT_TYPE_INT, {.dbl = 2}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, + { NULL }, +}; + +static const AVClass oss_demuxer_class = { + .class_name = "OSS demuxer", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + +AVInputFormat ff_oss_demuxer = { "oss", NULL_IF_CONFIG_SMALL("Open Sound System capture"), sizeof(AudioData), @@ -302,11 +319,12 @@ AVInputFormat oss_demuxer = { audio_read_packet, audio_read_close, .flags = AVFMT_NOFILE, + .priv_class = &oss_demuxer_class, }; #endif #if CONFIG_OSS_OUTDEV -AVOutputFormat oss_muxer = { +AVOutputFormat ff_oss_muxer = { "oss", NULL_IF_CONFIG_SMALL("Open Sound System playback"), "", @@ -315,11 +333,7 @@ AVOutputFormat oss_muxer = { /* XXX: we make the assumption that the soundcard accepts this format */ /* XXX: find better solution with "preinit" method, needed also in other formats */ -#if HAVE_BIGENDIAN - CODEC_ID_PCM_S16BE, -#else - CODEC_ID_PCM_S16LE, -#endif + AV_NE(CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE), CODEC_ID_NONE, audio_write_header, audio_write_packet,