annotate dsicin.c @ 5130:b26fba4bb776 libavformat

actually define AVSEEK_FLAG_FRAME as described in avformat_seek_file() doc
author aurel
date Mon, 10 Aug 2009 20:48:05 +0000
parents 49c1d3b27727
children 6ba79753bdd4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1378
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
1 /*
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
2 * Delphine Software International CIN File Demuxer
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
3 * Copyright (c) 2006 Gregory Montoir (cyx@users.sourceforge.net)
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
4 *
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
5 * This file is part of FFmpeg.
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
6 *
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
11 *
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
15 * Lesser General Public License for more details.
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
16 *
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
20 */
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
21
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
22 /**
4331
49c1d3b27727 Use full internal pathname in doxygen @file directives.
diego
parents: 4201
diff changeset
23 * @file libavformat/dsicin.c
1378
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
24 * Delphine Software International CIN file demuxer
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
25 */
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
26
4201
7d2f3f1b68d8 Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents: 3908
diff changeset
27 #include "libavutil/intreadwrite.h"
1378
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
28 #include "avformat.h"
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
29
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
30
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
31 typedef struct CinFileHeader {
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
32 int video_frame_size;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
33 int video_frame_width;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
34 int video_frame_height;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
35 int audio_frequency;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
36 int audio_bits;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
37 int audio_stereo;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
38 int audio_frame_size;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
39 } CinFileHeader;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
40
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
41 typedef struct CinFrameHeader {
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
42 int audio_frame_type;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
43 int video_frame_type;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
44 int pal_colors_count;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
45 int audio_frame_size;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
46 int video_frame_size;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
47 } CinFrameHeader;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
48
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
49 typedef struct CinDemuxContext {
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
50 int audio_stream_index;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
51 int video_stream_index;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
52 CinFileHeader file_header;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
53 int64_t audio_stream_pts;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
54 int64_t video_stream_pts;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
55 CinFrameHeader frame_header;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
56 int audio_buffer_size;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
57 } CinDemuxContext;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
58
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
59
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
60 static int cin_probe(AVProbeData *p)
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
61 {
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
62 /* header starts with this special marker */
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1378
diff changeset
63 if (AV_RL32(&p->buf[0]) != 0x55AA0000)
1378
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
64 return 0;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
65
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
66 /* for accuracy, check some header field values */
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1378
diff changeset
67 if (AV_RL32(&p->buf[12]) != 22050 || p->buf[16] != 16 || p->buf[17] != 0)
1378
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
68 return 0;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
69
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
70 return AVPROBE_SCORE_MAX;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
71 }
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
72
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
73 static int cin_read_file_header(CinDemuxContext *cin, ByteIOContext *pb) {
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
74 CinFileHeader *hdr = &cin->file_header;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
75
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
76 if (get_le32(pb) != 0x55AA0000)
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
77 return AVERROR_INVALIDDATA;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
78
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
79 hdr->video_frame_size = get_le32(pb);
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
80 hdr->video_frame_width = get_le16(pb);
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
81 hdr->video_frame_height = get_le16(pb);
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
82 hdr->audio_frequency = get_le32(pb);
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
83 hdr->audio_bits = get_byte(pb);
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
84 hdr->audio_stereo = get_byte(pb);
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
85 hdr->audio_frame_size = get_le16(pb);
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
86
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
87 if (hdr->audio_frequency != 22050 || hdr->audio_bits != 16 || hdr->audio_stereo != 0)
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
88 return AVERROR_INVALIDDATA;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
89
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
90 return 0;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
91 }
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
92
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
93 static int cin_read_header(AVFormatContext *s, AVFormatParameters *ap)
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
94 {
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
95 int rc;
2006
2f0154760e5f Get rid of unnecessary pointer casts.
diego
parents: 2001
diff changeset
96 CinDemuxContext *cin = s->priv_data;
1378
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
97 CinFileHeader *hdr = &cin->file_header;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2274
diff changeset
98 ByteIOContext *pb = s->pb;
1378
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
99 AVStream *st;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
100
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
101 rc = cin_read_file_header(cin, pb);
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
102 if (rc)
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
103 return rc;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
104
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
105 cin->video_stream_pts = 0;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
106 cin->audio_stream_pts = 0;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
107 cin->audio_buffer_size = 0;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
108
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
109 /* initialize the video decoder stream */
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
110 st = av_new_stream(s, 0);
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
111 if (!st)
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2006
diff changeset
112 return AVERROR(ENOMEM);
1378
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
113
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
114 av_set_pts_info(st, 32, 1, 12);
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
115 cin->video_stream_index = st->index;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
116 st->codec->codec_type = CODEC_TYPE_VIDEO;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
117 st->codec->codec_id = CODEC_ID_DSICINVIDEO;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
118 st->codec->codec_tag = 0; /* no fourcc */
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
119 st->codec->width = hdr->video_frame_width;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
120 st->codec->height = hdr->video_frame_height;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
121
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
122 /* initialize the audio decoder stream */
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
123 st = av_new_stream(s, 0);
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
124 if (!st)
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2006
diff changeset
125 return AVERROR(ENOMEM);
1378
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
126
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
127 av_set_pts_info(st, 32, 1, 22050);
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
128 cin->audio_stream_index = st->index;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
129 st->codec->codec_type = CODEC_TYPE_AUDIO;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
130 st->codec->codec_id = CODEC_ID_DSICINAUDIO;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
131 st->codec->codec_tag = 0; /* no tag */
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
132 st->codec->channels = 1;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
133 st->codec->sample_rate = 22050;
3908
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3424
diff changeset
134 st->codec->bits_per_coded_sample = 16;
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3424
diff changeset
135 st->codec->bit_rate = st->codec->sample_rate * st->codec->bits_per_coded_sample * st->codec->channels;
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3424
diff changeset
136 st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample;
1378
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
137
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
138 return 0;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
139 }
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
140
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
141 static int cin_read_frame_header(CinDemuxContext *cin, ByteIOContext *pb) {
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
142 CinFrameHeader *hdr = &cin->frame_header;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
143
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
144 hdr->video_frame_type = get_byte(pb);
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
145 hdr->audio_frame_type = get_byte(pb);
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
146 hdr->pal_colors_count = get_le16(pb);
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
147 hdr->video_frame_size = get_le32(pb);
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
148 hdr->audio_frame_size = get_le32(pb);
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
149
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
150 if (url_feof(pb) || url_ferror(pb))
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
151 return AVERROR(EIO);
1378
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
152
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
153 if (get_le32(pb) != 0xAA55AA55)
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
154 return AVERROR_INVALIDDATA;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
155
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
156 return 0;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
157 }
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
158
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
159 static int cin_read_packet(AVFormatContext *s, AVPacket *pkt)
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
160 {
2006
2f0154760e5f Get rid of unnecessary pointer casts.
diego
parents: 2001
diff changeset
161 CinDemuxContext *cin = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2274
diff changeset
162 ByteIOContext *pb = s->pb;
1378
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
163 CinFrameHeader *hdr = &cin->frame_header;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
164 int rc, palette_type, pkt_size;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
165
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
166 if (cin->audio_buffer_size == 0) {
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
167 rc = cin_read_frame_header(cin, pb);
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
168 if (rc)
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
169 return rc;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
170
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
171 if ((int16_t)hdr->pal_colors_count < 0) {
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
172 hdr->pal_colors_count = -(int16_t)hdr->pal_colors_count;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
173 palette_type = 1;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
174 } else {
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
175 palette_type = 0;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
176 }
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
177
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
178 /* palette and video packet */
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
179 pkt_size = (palette_type + 3) * hdr->pal_colors_count + hdr->video_frame_size;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
180
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
181 if (av_new_packet(pkt, 4 + pkt_size))
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2006
diff changeset
182 return AVERROR(ENOMEM);
1378
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
183
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
184 pkt->stream_index = cin->video_stream_index;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
185 pkt->pts = cin->video_stream_pts++;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
186
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
187 pkt->data[0] = palette_type;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
188 pkt->data[1] = hdr->pal_colors_count & 0xFF;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
189 pkt->data[2] = hdr->pal_colors_count >> 8;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
190 pkt->data[3] = hdr->video_frame_type;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
191
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
192 if (get_buffer(pb, &pkt->data[4], pkt_size) != pkt_size)
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
193 return AVERROR(EIO);
1378
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
194
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
195 /* sound buffer will be processed on next read_packet() call */
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
196 cin->audio_buffer_size = hdr->audio_frame_size;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
197 return 0;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
198 }
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
199
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
200 /* audio packet */
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
201 if (av_new_packet(pkt, cin->audio_buffer_size))
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2006
diff changeset
202 return AVERROR(ENOMEM);
1378
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
203
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
204 pkt->stream_index = cin->audio_stream_index;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
205 pkt->pts = cin->audio_stream_pts;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
206 cin->audio_stream_pts += cin->audio_buffer_size * 2 / cin->file_header.audio_frame_size;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
207
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
208 if (get_buffer(pb, pkt->data, cin->audio_buffer_size) != cin->audio_buffer_size)
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
209 return AVERROR(EIO);
1378
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
210
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
211 cin->audio_buffer_size = 0;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
212 return 0;
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
213 }
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
214
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
215 AVInputFormat dsicin_demuxer = {
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
216 "dsicin",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 2771
diff changeset
217 NULL_IF_CONFIG_SMALL("Delphine Software International CIN format"),
1378
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
218 sizeof(CinDemuxContext),
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
219 cin_probe,
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
220 cin_read_header,
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
221 cin_read_packet,
a32812bb5bcf support for Delphine Software .cin files demuxing / audio and video decoding, by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
diff changeset
222 };