annotate iss.c @ 6025:fd7fc7d79630 libavformat

Take ff_write_chained in use in the mov rtp hinter and in the rtsp muxer
author mstorsjo
date Fri, 21 May 2010 07:08:29 +0000
parents 178de7695c6c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4244
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
1 /*
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
2 * ISS (.iss) file demuxer
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
3 * Copyright (c) 2008 Jaikrishnan Menon <realityman@gmx.net>
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
4 *
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
5 * This file is part of FFmpeg.
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
6 *
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
11 *
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
15 * Lesser General Public License for more details.
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
16 *
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
20 */
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
21
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
22 /**
5969
178de7695c6c Remove explicit filename from Doxygen @file commands.
diego
parents: 5910
diff changeset
23 * @file
4244
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
24 * Funcom ISS file demuxer
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
25 * @author Jaikrishnan Menon
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
26 * for more information on the .iss file format, visit:
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
27 * http://wiki.multimedia.cx/index.php?title=FunCom_ISS
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
28 */
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
29
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
30 #include "avformat.h"
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
31 #include "libavutil/avstring.h"
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
32
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
33 #define ISS_SIG "IMA_ADPCM_Sound"
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
34 #define ISS_SIG_LEN 15
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
35 #define MAX_TOKEN_SIZE 20
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
36
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
37 typedef struct {
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
38 int packet_size;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
39 int sample_start_pos;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
40 } IssDemuxContext;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
41
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
42 static void get_token(ByteIOContext *s, char *buf, int maxlen)
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
43 {
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
44 int i = 0;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
45 char c;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
46
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
47 while ((c = get_byte(s))) {
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
48 if(c == ' ')
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
49 break;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
50 if (i < maxlen-1)
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
51 buf[i++] = c;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
52 }
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
53
4282
ef4f40b555b7 fix header parsing, the NULL terminated File ID is followed by a space
stefang
parents: 4244
diff changeset
54 if(!c)
ef4f40b555b7 fix header parsing, the NULL terminated File ID is followed by a space
stefang
parents: 4244
diff changeset
55 get_byte(s);
ef4f40b555b7 fix header parsing, the NULL terminated File ID is followed by a space
stefang
parents: 4244
diff changeset
56
4244
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
57 buf[i] = 0; /* Ensure null terminated, but may be truncated */
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
58 }
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
59
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
60 static int iss_probe(AVProbeData *p)
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
61 {
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
62 if (strncmp(p->buf, ISS_SIG, ISS_SIG_LEN))
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
63 return 0;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
64
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
65 return AVPROBE_SCORE_MAX;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
66 }
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
67
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
68 static av_cold int iss_read_header(AVFormatContext *s, AVFormatParameters *ap)
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
69 {
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
70 IssDemuxContext *iss = s->priv_data;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
71 ByteIOContext *pb = s->pb;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
72 AVStream *st;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
73 char token[MAX_TOKEN_SIZE];
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
74 int stereo, rate_divisor;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
75
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
76 get_token(pb, token, sizeof(token)); //"IMA_ADPCM_Sound"
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
77 get_token(pb, token, sizeof(token)); //packet size
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
78 sscanf(token, "%d", &iss->packet_size);
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
79 get_token(pb, token, sizeof(token)); //File ID
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
80 get_token(pb, token, sizeof(token)); //out size
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
81 get_token(pb, token, sizeof(token)); //stereo
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
82 sscanf(token, "%d", &stereo);
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
83 get_token(pb, token, sizeof(token)); //Unknown1
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
84 get_token(pb, token, sizeof(token)); //RateDivisor
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
85 sscanf(token, "%d", &rate_divisor);
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
86 get_token(pb, token, sizeof(token)); //Unknown2
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
87 get_token(pb, token, sizeof(token)); //Version ID
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
88 get_token(pb, token, sizeof(token)); //Size
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
89
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
90 iss->sample_start_pos = url_ftell(pb);
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
91
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
92 st = av_new_stream(s, 0);
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
93 if (!st)
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
94 return AVERROR(ENOMEM);
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 4331
diff changeset
95 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
4244
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
96 st->codec->codec_id = CODEC_ID_ADPCM_IMA_ISS;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
97 st->codec->channels = stereo ? 2 : 1;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
98 st->codec->sample_rate = 44100;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
99 if(rate_divisor > 0)
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
100 st->codec->sample_rate /= rate_divisor;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
101 st->codec->bits_per_coded_sample = 4;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
102 st->codec->bit_rate = st->codec->channels * st->codec->sample_rate
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
103 * st->codec->bits_per_coded_sample;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
104 st->codec->block_align = iss->packet_size;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
105 av_set_pts_info(st, 32, 1, st->codec->sample_rate);
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
106
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
107 return 0;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
108 }
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
109
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
110 static int iss_read_packet(AVFormatContext *s, AVPacket *pkt)
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
111 {
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
112 IssDemuxContext *iss = s->priv_data;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
113 int ret = av_get_packet(s->pb, pkt, iss->packet_size);
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
114
4283
7795d5d87484 return an error if we can not get a full packet,
stefang
parents: 4282
diff changeset
115 if(ret != iss->packet_size)
7795d5d87484 return an error if we can not get a full packet,
stefang
parents: 4282
diff changeset
116 return AVERROR(EIO);
4244
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
117
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
118 pkt->stream_index = 0;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
119 pkt->pts = url_ftell(s->pb) - iss->sample_start_pos;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
120 if(s->streams[0]->codec->channels > 0)
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
121 pkt->pts /= s->streams[0]->codec->channels*2;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
122 return 0;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
123 }
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
124
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
125 AVInputFormat iss_demuxer = {
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
126 "ISS",
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
127 NULL_IF_CONFIG_SMALL("Funcom ISS format"),
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
128 sizeof(IssDemuxContext),
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
129 iss_probe,
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
130 iss_read_header,
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
131 iss_read_packet,
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
132 };
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
133