Mercurial > libavformat.hg
annotate mtv.c @ 3694:191f342eb840 libavformat
Fix small typo.
author | diego |
---|---|
date | Tue, 05 Aug 2008 21:46:10 +0000 |
parents | a741556d452c |
children | 1d3d17de20ba |
rev | line source |
---|---|
1380 | 1 /* |
2 * mtv demuxer | |
3 * Copyright (c) 2006 Reynaldo H. Verdejo Pinochet | |
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 mtv.c | |
24 * MTV demuxer. | |
25 */ | |
26 | |
3286 | 27 #include "libavutil/bswap.h" |
1380 | 28 #include "avformat.h" |
29 | |
30 #define MTV_ASUBCHUNK_DATA_SIZE 500 | |
31 #define MTV_HEADER_SIZE 512 | |
32 #define MTV_AUDIO_PADDING_SIZE 12 | |
33 #define AUDIO_SAMPLING_RATE 44100 | |
34 #define VIDEO_SID 0 | |
35 #define AUDIO_SID 1 | |
36 | |
37 typedef struct MTVDemuxContext { | |
38 | |
39 unsigned int file_size; ///< filesize, not always right | |
40 unsigned int segments; ///< number of 512 byte segments | |
41 unsigned int audio_identifier; ///< 'MP3' on all files I have seen | |
42 unsigned int audio_br; ///< bitrate of audio chanel (mp3) | |
43 unsigned int img_colorfmt; ///< frame colorfmt rgb 565/555 | |
44 unsigned int img_bpp; ///< frame bits per pixel | |
45 unsigned int img_width; // | |
46 unsigned int img_height; // | |
47 unsigned int img_segment_size; ///< size of image segment | |
48 unsigned int video_fps; // | |
3532
a741556d452c
Change mtv_read_packet so it does not break after seeking (displaying a shifted image).
reimar
parents:
3531
diff
changeset
|
49 unsigned int full_segment_size; |
1380 | 50 |
51 } MTVDemuxContext; | |
52 | |
53 static int mtv_probe(AVProbeData *p) | |
54 { | |
55 /* Magic is 'AMV' */ | |
56 | |
57 if(*(p->buf) != 'A' || *(p->buf+1) != 'M' || *(p->buf+2) != 'V') | |
58 return 0; | |
59 | |
60 return AVPROBE_SCORE_MAX; | |
61 } | |
62 | |
63 static int mtv_read_header(AVFormatContext *s, AVFormatParameters *ap) | |
64 { | |
65 MTVDemuxContext *mtv = s->priv_data; | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2274
diff
changeset
|
66 ByteIOContext *pb = s->pb; |
1380 | 67 AVStream *st; |
3532
a741556d452c
Change mtv_read_packet so it does not break after seeking (displaying a shifted image).
reimar
parents:
3531
diff
changeset
|
68 unsigned int audio_subsegments; |
1380 | 69 |
70 | |
71 url_fskip(pb, 3); | |
72 mtv->file_size = get_le32(pb); | |
73 mtv->segments = get_le32(pb); | |
74 url_fskip(pb, 32); | |
75 mtv->audio_identifier = get_le24(pb); | |
76 mtv->audio_br = get_le16(pb); | |
77 mtv->img_colorfmt = get_le24(pb); | |
78 mtv->img_bpp = get_byte(pb); | |
79 mtv->img_width = get_le16(pb); | |
80 mtv->img_height = get_le16(pb); | |
81 mtv->img_segment_size = get_le16(pb); | |
82 url_fskip(pb, 4); | |
3532
a741556d452c
Change mtv_read_packet so it does not break after seeking (displaying a shifted image).
reimar
parents:
3531
diff
changeset
|
83 audio_subsegments = get_le16(pb); |
a741556d452c
Change mtv_read_packet so it does not break after seeking (displaying a shifted image).
reimar
parents:
3531
diff
changeset
|
84 mtv->full_segment_size = |
a741556d452c
Change mtv_read_packet so it does not break after seeking (displaying a shifted image).
reimar
parents:
3531
diff
changeset
|
85 audio_subsegments * (MTV_AUDIO_PADDING_SIZE + MTV_ASUBCHUNK_DATA_SIZE) + |
a741556d452c
Change mtv_read_packet so it does not break after seeking (displaying a shifted image).
reimar
parents:
3531
diff
changeset
|
86 mtv->img_segment_size; |
a741556d452c
Change mtv_read_packet so it does not break after seeking (displaying a shifted image).
reimar
parents:
3531
diff
changeset
|
87 mtv->video_fps = (mtv->audio_br / 4) / audio_subsegments; |
1380 | 88 |
89 /* FIXME Add sanity check here */ | |
90 | |
91 /* all systems go! init decoders */ | |
92 | |
93 /* video - raw rgb565 */ | |
94 | |
95 st = av_new_stream(s, VIDEO_SID); | |
96 if(!st) | |
2273
7eb456c4ed8a
Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents:
2023
diff
changeset
|
97 return AVERROR(ENOMEM); |
1380 | 98 |
99 av_set_pts_info(st, 64, 1, mtv->video_fps); | |
100 st->codec->codec_type = CODEC_TYPE_VIDEO; | |
101 st->codec->codec_id = CODEC_ID_RAWVIDEO; | |
1449
64a44155a525
now we set codec_tag, still have to figure out how to handle flipping
reynaldo
parents:
1380
diff
changeset
|
102 st->codec->codec_tag = MKTAG('R', 'G', 'B', mtv->img_bpp); |
1380 | 103 st->codec->width = mtv->img_width; |
104 st->codec->height = mtv->img_height; | |
105 st->codec->bits_per_sample = mtv->img_bpp; | |
106 st->codec->sample_rate = mtv->video_fps; | |
107 | |
108 /* audio - mp3 */ | |
109 | |
110 st = av_new_stream(s, AUDIO_SID); | |
111 if(!st) | |
2273
7eb456c4ed8a
Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents:
2023
diff
changeset
|
112 return AVERROR(ENOMEM); |
1380 | 113 |
114 av_set_pts_info(st, 64, 1, AUDIO_SAMPLING_RATE); | |
115 st->codec->codec_type = CODEC_TYPE_AUDIO; | |
116 st->codec->codec_id = CODEC_ID_MP3; | |
117 st->codec->bit_rate = mtv->audio_br; | |
2023 | 118 st->need_parsing = AVSTREAM_PARSE_FULL; |
1380 | 119 |
120 /* Jump over header */ | |
121 | |
122 if(url_fseek(pb, MTV_HEADER_SIZE, SEEK_SET) != MTV_HEADER_SIZE) | |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
123 return AVERROR(EIO); |
1380 | 124 |
3278 | 125 return 0; |
1380 | 126 |
127 } | |
128 | |
129 static int mtv_read_packet(AVFormatContext *s, AVPacket *pkt) | |
130 { | |
131 MTVDemuxContext *mtv = s->priv_data; | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2274
diff
changeset
|
132 ByteIOContext *pb = s->pb; |
1380 | 133 int ret; |
134 #ifndef WORDS_BIGENDIAN | |
135 int i; | |
136 #endif | |
137 | |
138 ret = 0; | |
139 | |
3532
a741556d452c
Change mtv_read_packet so it does not break after seeking (displaying a shifted image).
reimar
parents:
3531
diff
changeset
|
140 if((url_ftell(pb) - s->data_offset + mtv->img_segment_size) % mtv->full_segment_size) |
1380 | 141 { |
142 url_fskip(pb, MTV_AUDIO_PADDING_SIZE); | |
143 | |
144 ret = av_get_packet(pb, pkt, MTV_ASUBCHUNK_DATA_SIZE); | |
145 if(ret != MTV_ASUBCHUNK_DATA_SIZE) | |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
146 return AVERROR(EIO); |
1380 | 147 |
3531
296caaa22429
Fix pkt->pos to really point at start of packet for mtv audio packets.
reimar
parents:
3424
diff
changeset
|
148 pkt->pos -= MTV_AUDIO_PADDING_SIZE; |
1380 | 149 pkt->stream_index = AUDIO_SID; |
150 | |
151 }else | |
152 { | |
153 ret = av_get_packet(pb, pkt, mtv->img_segment_size); | |
154 if(ret != mtv->img_segment_size) | |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
155 return AVERROR(EIO); |
1380 | 156 |
157 #ifndef WORDS_BIGENDIAN | |
158 | |
159 /* pkt->data is GGGRRRR BBBBBGGG | |
160 * and we need RRRRRGGG GGGBBBBB | |
161 * for PIX_FMT_RGB565 so here we | |
162 * just swap bytes as they come | |
163 */ | |
164 | |
165 for(i=0;i<mtv->img_segment_size/2;i++) | |
166 *((uint16_t *)pkt->data+i) = bswap_16(*((uint16_t *)pkt->data+i)); | |
167 #endif | |
168 pkt->stream_index = VIDEO_SID; | |
169 } | |
170 | |
3278 | 171 return ret; |
1380 | 172 } |
173 | |
174 AVInputFormat mtv_demuxer = { | |
175 "MTV", | |
3424
7a0230981402
Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents:
3286
diff
changeset
|
176 NULL_IF_CONFIG_SMALL("MTV format"), |
1380 | 177 sizeof(MTVDemuxContext), |
178 mtv_probe, | |
179 mtv_read_header, | |
180 mtv_read_packet, | |
181 }; |