annotate rsodec.c @ 6409:fe8fadaf5fb6 libavformat

Reindent
author mstorsjo
date Wed, 25 Aug 2010 13:31:33 +0000
parents ab5b82b7b8e6
children 4aaed59641ff
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6288
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
1 /*
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
2 * RSO demuxer
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
3 * Copyright (c) 2001 Fabrice Bellard (original AU code)
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
4 * Copyright (c) 2010 Rafael Carre
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
5 *
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
6 * This file is part of FFmpeg.
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
7 *
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
12 *
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
16 * Lesser General Public License for more details.
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
17 *
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
21 */
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
22
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
23 #include "libavutil/intreadwrite.h"
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
24 #include "avformat.h"
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
25 #include "internal.h"
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
26 #include "raw.h"
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
27 #include "riff.h"
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
28 #include "rso.h"
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
29
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
30 static int rso_read_header(AVFormatContext *s, AVFormatParameters *ap)
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
31 {
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
32 ByteIOContext *pb = s->pb;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
33 int id, rate, bps;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
34 unsigned int size;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
35 enum CodecID codec;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
36 AVStream *st;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
37
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
38 id = get_be16(pb);
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
39 size = get_be16(pb);
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
40 rate = get_be16(pb);
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
41 get_be16(pb); /* play mode ? (0x0000 = don't loop) */
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
42
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
43 codec = ff_codec_get_id(ff_codec_rso_tags, id);
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
44
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
45 if (codec == CODEC_ID_ADPCM_IMA_WAV) {
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
46 av_log(s, AV_LOG_ERROR, "ADPCM in RSO not implemented\n");
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
47 return AVERROR_PATCHWELCOME;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
48 }
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
49
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
50 bps = av_get_bits_per_sample(codec);
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
51 if (!bps) {
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
52 av_log_ask_for_sample(s, "could not determine bits per sample\n");
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
53 return AVERROR_INVALIDDATA;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
54 }
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
55
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
56 /* now we are ready: build format streams */
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
57 st = av_new_stream(s, 0);
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
58 if (!st)
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
59 return AVERROR(ENOMEM);
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
60
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
61 st->duration = (size * 8) / bps;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
62 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
63 st->codec->codec_tag = id;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
64 st->codec->codec_id = codec;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
65 st->codec->channels = 1;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
66 st->codec->sample_rate = rate;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
67
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
68 av_set_pts_info(st, 64, 1, rate);
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
69
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
70 return 0;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
71 }
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
72
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
73 #define BLOCK_SIZE 1024 /* in samples */
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
74
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
75 static int rso_read_packet(AVFormatContext *s, AVPacket *pkt)
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
76 {
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
77 int bps = av_get_bits_per_sample(s->streams[0]->codec->codec_id);
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
78 int ret = av_get_packet(s->pb, pkt, BLOCK_SIZE * bps >> 3);
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
79
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
80 if (ret < 0)
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
81 return ret;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
82
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
83 pkt->stream_index = 0;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
84
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
85 /* note: we need to modify the packet size here to handle the last packet */
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
86 pkt->size = ret;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
87
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
88 return 0;
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
89 }
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
90
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
91 AVInputFormat rso_demuxer = {
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
92 .name = "rso",
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
93 .long_name = NULL_IF_CONFIG_SMALL("Lego Mindstorms RSO format"),
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
94 .extensions = "rso",
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
95 .priv_data_size = 0,
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
96 .read_probe = NULL, /* no magic value in this format */
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
97 .read_header = rso_read_header,
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
98 .read_packet = rso_read_packet,
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
99 .read_close = NULL,
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
100 .read_seek = pcm_read_seek,
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
101 .codec_tag = (const AVCodecTag* const []){ff_codec_rso_tags, 0},
ab5b82b7b8e6 Lego Mindstorms RSO muxer and demuxer.
cehoyos
parents:
diff changeset
102 };