~ubuntu-branches/ubuntu/jaunty/xvidcap/jaunty-proposed

« back to all changes in this revision

Viewing changes to ffmpeg/libavformat/au.c

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2008-02-25 15:47:12 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080225154712-qvr11ekcea4c9ry8
Tags: 1.1.6-0.1ubuntu1
* Merge from debian-multimedia (LP: #120003), Ubuntu Changes:
 - For ffmpeg-related build-deps, remove cvs from package names.
 - Standards-Version 3.7.3
 - Maintainer Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
2
 
 * AU encoder and decoder
 
1
/*
 
2
 * AU muxer and demuxer
3
3
 * Copyright (c) 2001 Fabrice Bellard.
4
4
 *
5
 
 * This library is free software; you can redistribute it and/or
 
5
 * This file is part of FFmpeg.
 
6
 *
 
7
 * FFmpeg is free software; you can redistribute it and/or
6
8
 * modify it under the terms of the GNU Lesser General Public
7
9
 * License as published by the Free Software Foundation; either
8
 
 * version 2 of the License, or (at your option) any later version.
 
10
 * version 2.1 of the License, or (at your option) any later version.
9
11
 *
10
 
 * This library is distributed in the hope that it will be useful,
 
12
 * FFmpeg is distributed in the hope that it will be useful,
11
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
15
 * Lesser General Public License for more details.
14
16
 *
15
17
 * You should have received a copy of the GNU Lesser General Public
16
 
 * License along with this library; if not, write to the Free Software
17
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
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
18
20
 */
19
21
 
20
22
/*
26
28
 */
27
29
 
28
30
#include "avformat.h"
29
 
#include "avi.h"
 
31
#include "allformats.h"
 
32
#include "riff.h"
30
33
 
31
34
/* if we don't know the size in advance */
32
35
#define AU_UNKOWN_SIZE ((uint32_t)(~0))
33
36
 
34
37
/* The ffmpeg codecs we support, and the IDs they have in the file */
35
 
static const CodecTag codec_au_tags[] = {
 
38
static const AVCodecTag codec_au_tags[] = {
36
39
    { CODEC_ID_PCM_MULAW, 1 },
37
40
    { CODEC_ID_PCM_S16BE, 3 },
38
41
    { CODEC_ID_PCM_ALAW, 27 },
39
42
    { 0, 0 },
40
43
};
41
44
 
 
45
#ifdef CONFIG_MUXERS
42
46
/* AUDIO_FILE header */
43
47
static int put_au_header(ByteIOContext *pb, AVCodecContext *enc)
44
48
{
45
49
    if(!enc->codec_tag)
46
 
       enc->codec_tag = codec_get_tag(codec_au_tags, enc->codec_id);
47
 
    if(!enc->codec_tag)
48
50
        return -1;
49
51
    put_tag(pb, ".snd");       /* magic number */
50
52
    put_be32(pb, 24);           /* header size */
62
64
    s->priv_data = NULL;
63
65
 
64
66
    /* format header */
65
 
    if (put_au_header(pb, &s->streams[0]->codec) < 0) {
 
67
    if (put_au_header(pb, s->streams[0]->codec) < 0) {
66
68
        return -1;
67
69
    }
68
70
 
71
73
    return 0;
72
74
}
73
75
 
74
 
static int au_write_packet(AVFormatContext *s, int stream_index_ptr,
75
 
                           const uint8_t *buf, int size, int64_t pts)
 
76
static int au_write_packet(AVFormatContext *s, AVPacket *pkt)
76
77
{
77
78
    ByteIOContext *pb = &s->pb;
78
 
    put_buffer(pb, buf, size);
 
79
    put_buffer(pb, pkt->data, pkt->size);
79
80
    return 0;
80
81
}
81
82
 
97
98
 
98
99
    return 0;
99
100
}
 
101
#endif //CONFIG_MUXERS
100
102
 
101
103
static int au_probe(AVProbeData *p)
102
104
{
112
114
 
113
115
/* au input */
114
116
static int au_read_header(AVFormatContext *s,
115
 
                           AVFormatParameters *ap)
 
117
                          AVFormatParameters *ap)
116
118
{
117
119
    int size;
118
120
    unsigned int tag;
126
128
        return -1;
127
129
    size = get_be32(pb); /* header size */
128
130
    get_be32(pb); /* data size */
129
 
    
 
131
 
130
132
    id = get_be32(pb);
131
133
    rate = get_be32(pb);
132
134
    channels = get_be32(pb);
133
 
    
 
135
 
134
136
    codec = codec_get_id(codec_au_tags, id);
135
137
 
136
138
    if (size >= 24) {
142
144
    st = av_new_stream(s, 0);
143
145
    if (!st)
144
146
        return -1;
145
 
    st->codec.codec_type = CODEC_TYPE_AUDIO;
146
 
    st->codec.codec_tag = id;
147
 
    st->codec.codec_id = codec;
148
 
    st->codec.channels = channels;
149
 
    st->codec.sample_rate = rate;
 
147
    st->codec->codec_type = CODEC_TYPE_AUDIO;
 
148
    st->codec->codec_tag = id;
 
149
    st->codec->codec_id = codec;
 
150
    st->codec->channels = channels;
 
151
    st->codec->sample_rate = rate;
 
152
    av_set_pts_info(st, 64, 1, rate);
150
153
    return 0;
151
154
}
152
155
 
158
161
    int ret;
159
162
 
160
163
    if (url_feof(&s->pb))
161
 
        return -EIO;
162
 
    if (av_new_packet(pkt, MAX_SIZE))
163
 
        return -EIO;
 
164
        return AVERROR_IO;
 
165
    ret= av_get_packet(&s->pb, pkt, MAX_SIZE);
 
166
    if (ret < 0)
 
167
        return AVERROR_IO;
164
168
    pkt->stream_index = 0;
165
169
 
166
 
    ret = get_buffer(&s->pb, pkt->data, pkt->size);
167
 
    if (ret < 0)
168
 
        av_free_packet(pkt);
169
170
    /* note: we need to modify the packet size here to handle the last
170
171
       packet */
171
172
    pkt->size = ret;
177
178
    return 0;
178
179
}
179
180
 
180
 
static AVInputFormat au_iformat = {
 
181
#ifdef CONFIG_AU_DEMUXER
 
182
AVInputFormat au_demuxer = {
181
183
    "au",
182
184
    "SUN AU Format",
183
185
    0,
185
187
    au_read_header,
186
188
    au_read_packet,
187
189
    au_read_close,
 
190
    pcm_read_seek,
 
191
    .codec_tag= (const AVCodecTag*[]){codec_au_tags, 0},
188
192
};
 
193
#endif
189
194
 
190
 
static AVOutputFormat au_oformat = {
 
195
#ifdef CONFIG_AU_MUXER
 
196
AVOutputFormat au_muxer = {
191
197
    "au",
192
198
    "SUN AU Format",
193
199
    "audio/basic",
198
204
    au_write_header,
199
205
    au_write_packet,
200
206
    au_write_trailer,
 
207
    .codec_tag= (const AVCodecTag*[]){codec_au_tags, 0},
201
208
};
202
 
 
203
 
int au_init(void)
204
 
{
205
 
    av_register_input_format(&au_iformat);
206
 
    av_register_output_format(&au_oformat);
207
 
    return 0;
208
 
}
 
209
#endif //CONFIG_AU_MUXER