FFmpeg
Loading...
Searching...
No Matches
dsicin.c
Go to the documentation of this file.
1/*
2 * Delphine Software International CIN File Demuxer
3 * Copyright (c) 2006 Gregory Montoir (cyx@users.sourceforge.net)
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
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
20 */
21
22/**
23 * @file
24 * Delphine Software International CIN file demuxer
25 */
26
29#include "avformat.h"
30#include "demux.h"
31#include "internal.h"
32#include "avio_internal.h"
33
34
44
52
62
63
64static int cin_probe(const AVProbeData *p)
65{
66 /* header starts with this special marker */
67 if (AV_RL32(&p->buf[0]) != 0x55AA0000)
68 return 0;
69
70 /* for accuracy, check some header field values */
71 if (AV_RL32(&p->buf[12]) != 22050 || p->buf[16] != 16 || p->buf[17] != 0)
72 return 0;
73
74 return AVPROBE_SCORE_MAX;
75}
76
78 CinFileHeader *hdr = &cin->file_header;
79
80 if (avio_rl32(pb) != 0x55AA0000)
82
83 hdr->video_frame_size = avio_rl32(pb);
86 hdr->audio_frequency = avio_rl32(pb);
87 hdr->audio_bits = avio_r8(pb);
88 hdr->audio_stereo = avio_r8(pb);
89 hdr->audio_frame_size = avio_rl16(pb);
90
91 if (hdr->audio_frequency != 22050 || hdr->audio_bits != 16 || hdr->audio_stereo != 0)
93
94 return 0;
95}
96
98{
99 int rc;
100 CinDemuxContext *cin = s->priv_data;
101 CinFileHeader *hdr = &cin->file_header;
102 AVIOContext *pb = s->pb;
103 AVStream *st;
104
105 rc = cin_read_file_header(cin, pb);
106 if (rc)
107 return rc;
108
109 cin->video_stream_pts = 0;
110 cin->audio_stream_pts = 0;
111 cin->audio_buffer_size = 0;
112
113 /* initialize the video decoder stream */
115 if (!st)
116 return AVERROR(ENOMEM);
117
118 avpriv_set_pts_info(st, 32, 1, 12);
119 cin->video_stream_index = st->index;
122 st->codecpar->codec_tag = 0; /* no fourcc */
123 st->codecpar->width = hdr->video_frame_width;
125
126 /* initialize the audio decoder stream */
128 if (!st)
129 return AVERROR(ENOMEM);
130
131 avpriv_set_pts_info(st, 32, 1, 22050);
132 cin->audio_stream_index = st->index;
135 st->codecpar->codec_tag = 0; /* no tag */
137 st->codecpar->sample_rate = 22050;
142
143 return 0;
144}
145
147 CinFrameHeader *hdr = &cin->frame_header;
148
149 hdr->video_frame_type = avio_r8(pb);
150 hdr->audio_frame_type = avio_r8(pb);
151 hdr->pal_colors_count = avio_rl16(pb);
152 hdr->video_frame_size = avio_rl32(pb);
153 hdr->audio_frame_size = avio_rl32(pb);
154
155 if (avio_feof(pb) || pb->error)
156 return pb->error ? pb->error : AVERROR_INVALIDDATA;
157
158 if (avio_rl32(pb) != 0xAA55AA55)
159 return AVERROR_INVALIDDATA;
160 if (hdr->video_frame_size < 0 || hdr->audio_frame_size < 0)
161 return AVERROR_INVALIDDATA;
162
163 return 0;
164}
165
167{
168 CinDemuxContext *cin = s->priv_data;
169 AVIOContext *pb = s->pb;
170 CinFrameHeader *hdr = &cin->frame_header;
171 int rc, palette_type;
172 int64_t pkt_size;
173 int ret;
174
175 if (cin->audio_buffer_size == 0) {
176 rc = cin_read_frame_header(cin, pb);
177 if (rc)
178 return rc;
179
180 if ((int16_t)hdr->pal_colors_count < 0) {
181 hdr->pal_colors_count = -(int16_t)hdr->pal_colors_count;
182 palette_type = 1;
183 } else {
184 palette_type = 0;
185 }
186
187 /* palette and video packet */
188 pkt_size = (palette_type + 3LL) * hdr->pal_colors_count + hdr->video_frame_size;
189 if (pkt_size + 4 > INT_MAX)
190 return AVERROR_INVALIDDATA;
191
192 pkt_size = ffio_limit(pb, pkt_size);
193
194 ret = av_new_packet(pkt, 4 + pkt_size);
195 if (ret < 0)
196 return ret;
197
198 pkt->stream_index = cin->video_stream_index;
199 pkt->pts = cin->video_stream_pts++;
200
201 pkt->data[0] = palette_type;
202 pkt->data[1] = hdr->pal_colors_count & 0xFF;
203 pkt->data[2] = hdr->pal_colors_count >> 8;
204 pkt->data[3] = hdr->video_frame_type;
205
206 ret = avio_read(pb, &pkt->data[4], pkt_size);
207 if (ret < 0) {
208 return ret;
209 }
210 if (ret < pkt_size)
211 av_shrink_packet(pkt, 4 + ret);
212
213 /* sound buffer will be processed on next read_packet() call */
215 return 0;
216 }
217
218 /* audio packet */
219 ret = av_get_packet(pb, pkt, cin->audio_buffer_size);
220 if (ret < 0)
221 return ret;
222
223 pkt->stream_index = cin->audio_stream_index;
224 pkt->pts = cin->audio_stream_pts;
225 pkt->duration = cin->audio_buffer_size - (pkt->pts == 0);
226 cin->audio_stream_pts += pkt->duration;
227 cin->audio_buffer_size = 0;
228 return 0;
229}
230
232 .p.name = "dsicin",
233 .p.long_name = NULL_IF_CONFIG_SMALL("Delphine Software International CIN"),
234 .priv_data_size = sizeof(CinDemuxContext),
238};
const FFInputFormat ff_dsicin_demuxer
Definition dsicin.c:231
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition avformat.c:834
Main libavformat public API header.
#define AVPROBE_SCORE_MAX
maximum score
Definition avformat.h:483
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
Allocate and read the payload of a packet and initialize its fields with default values.
Definition utils.c:98
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition aviobuf.c:349
unsigned int avio_rl16(AVIOContext *s)
Definition aviobuf.c:717
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition aviobuf.c:615
unsigned int avio_rl32(AVIOContext *s)
Definition aviobuf.c:733
int avio_r8(AVIOContext *s)
Definition aviobuf.c:606
int ffio_limit(AVIOContext *s, int size)
Definition aviobuf.c:1064
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
#define s(width, name)
Definition cbs_vp9.c:198
static int read_probe(const AVProbeData *p)
Definition cdg.c:30
Public libavutil channel layout APIs header.
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static AVPacket * pkt
static int cin_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition dsicin.c:166
static int cin_probe(const AVProbeData *p)
Definition dsicin.c:64
static int cin_read_header(AVFormatContext *s)
Definition dsicin.c:97
static int cin_read_frame_header(CinDemuxContext *cin, AVIOContext *pb)
Definition dsicin.c:146
static int cin_read_file_header(CinDemuxContext *cin, AVIOContext *pb)
Definition dsicin.c:77
static int read_header(FFV1Context *f, RangeCoder *c)
Definition ffv1dec.c:578
@ AV_CODEC_ID_DSICINVIDEO
Definition codec_id.h:144
@ AV_CODEC_ID_DSICINAUDIO
Definition codec_id.h:479
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
Definition packet.c:113
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition packet.c:98
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#define AV_CHANNEL_LAYOUT_MONO
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define AV_RL32(p)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
An AVChannelLayout holds information about the channel layout of audio data.
int nb_channels
Number of channels in this layout.
int height
The height of the video frame in pixels.
Definition codec_par.h:150
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition codec_par.h:113
AVChannelLayout ch_layout
The channel layout and number of channels.
Definition codec_par.h:207
int width
The width of the video frame in pixels.
Definition codec_par.h:143
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition codec_par.h:99
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition codec_par.h:61
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition codec_par.h:57
int sample_rate
The number of audio samples per second.
Definition codec_par.h:213
Format I/O context.
Definition avformat.h:1333
Bytestream IO Context.
Definition avio.h:160
int error
contains the error code or 0 if no error happened
Definition avio.h:239
This structure stores compressed data.
Definition packet.h:580
This structure contains the data a format has to probe a file.
Definition avformat.h:471
Stream structure.
Definition avformat.h:766
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:789
int index
stream index in AVFormatContext
Definition avformat.h:772
int video_stream_index
Definition dsicin.c:55
int audio_buffer_size
Definition dsicin.c:60
CinFileHeader file_header
Definition dsicin.c:56
int64_t video_stream_pts
Definition dsicin.c:58
int audio_stream_index
Definition dsicin.c:54
int64_t audio_stream_pts
Definition dsicin.c:57
CinFrameHeader frame_header
Definition dsicin.c:59
int audio_stereo
Definition dsicin.c:41
int video_frame_height
Definition dsicin.c:38
int video_frame_size
Definition dsicin.c:36
int video_frame_width
Definition dsicin.c:37
int audio_frame_size
Definition dsicin.c:42
int audio_frequency
Definition dsicin.c:39
int audio_bits
Definition dsicin.c:40
int pal_colors_count
Definition dsicin.c:48
int video_frame_type
Definition dsicin.c:47
int audio_frame_size
Definition dsicin.c:49
int audio_frame_type
Definition dsicin.c:46
int video_frame_size
Definition dsicin.c:50