aboutsummaryrefslogtreecommitdiffstats
path: root/libav/audio.c
diff options
context:
space:
mode:
authorFabrice Bellard <fabrice@bellard.org>2002-05-20 16:31:13 +0000
committerFabrice Bellard <fabrice@bellard.org>2002-05-20 16:31:13 +0000
commitc9a65ca8c306071b3c359b56a384a1594cd505df (patch)
treea33c4b156673f2c1404042501c1cebaae6a35457 /libav/audio.c
parentdb7f1f95acc050bb5ddf62b0008eab8c8305d369 (diff)
downloadffmpeg-c9a65ca8c306071b3c359b56a384a1594cd505df.tar.gz
converted to new API
Originally committed as revision 547 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libav/audio.c')
-rw-r--r--libav/audio.c50
1 files changed, 24 insertions, 26 deletions
diff --git a/libav/audio.c b/libav/audio.c
index ab9e4757d2..d271ae7ec3 100644
--- a/libav/audio.c
+++ b/libav/audio.c
@@ -147,21 +147,15 @@ static int audio_close(AudioData *s)
/* sound output support */
static int audio_write_header(AVFormatContext *s1)
{
- AudioData *s;
+ AudioData *s = s1->priv_data;
AVStream *st;
int ret;
- s = av_mallocz(sizeof(AudioData));
- if (!s)
- return -ENOMEM;
- s1->priv_data = s;
-
st = s1->streams[0];
s->sample_rate = st->codec.sample_rate;
s->channels = st->codec.channels;
ret = audio_open(s, 1);
if (ret < 0) {
- av_free(s);
return -EIO;
} else {
return 0;
@@ -201,7 +195,6 @@ static int audio_write_trailer(AVFormatContext *s1)
AudioData *s = s1->priv_data;
audio_close(s);
- av_free(s);
return 0;
}
@@ -209,31 +202,23 @@ static int audio_write_trailer(AVFormatContext *s1)
static int audio_read_header(AVFormatContext *s1, AVFormatParameters *ap)
{
- AudioData *s;
+ AudioData *s = s1->priv_data;
AVStream *st;
int ret;
if (!ap || ap->sample_rate <= 0 || ap->channels <= 0)
return -1;
- s = av_mallocz(sizeof(AudioData));
- if (!s)
- return -ENOMEM;
- st = av_mallocz(sizeof(AVStream));
+ st = av_new_stream(s1, 0);
if (!st) {
- av_free(s);
return -ENOMEM;
}
- s1->priv_data = s;
- s1->nb_streams = 1;
- s1->streams[0] = st;
s->sample_rate = ap->sample_rate;
s->channels = ap->channels;
ret = audio_open(s, 0);
if (ret < 0) {
av_free(st);
- av_free(s);
return -EIO;
} else {
/* take real parameters */
@@ -284,15 +269,26 @@ static int audio_read_close(AVFormatContext *s1)
AudioData *s = s1->priv_data;
audio_close(s);
- av_free(s);
return 0;
}
-AVFormat audio_device_format = {
+AVInputFormat audio_in_format = {
+ "audio_device",
+ "audio grab and output",
+ sizeof(AudioData),
+ NULL,
+ audio_read_header,
+ audio_read_packet,
+ audio_read_close,
+ flags: AVFMT_NOFILE,
+};
+
+AVOutputFormat audio_out_format = {
"audio_device",
"audio grab and output",
"",
"",
+ sizeof(AudioData),
/* XXX: we make the assumption that the soundcard accepts this format */
/* XXX: find better solution with "preinit" method, needed also in
other formats */
@@ -305,10 +301,12 @@ AVFormat audio_device_format = {
audio_write_header,
audio_write_packet,
audio_write_trailer,
-
- audio_read_header,
- audio_read_packet,
- audio_read_close,
- NULL,
- AVFMT_NOFILE,
+ flags: AVFMT_NOFILE,
};
+
+int audio_init(void)
+{
+ av_register_input_format(&audio_in_format);
+ av_register_output_format(&audio_out_format);
+ return 0;
+}