Mercurial > libavformat.hg
annotate mtv.c @ 1794:11c57b75bccd libavformat
fix dts adjusting
author | bcoudurier |
---|---|
date | Wed, 14 Feb 2007 14:54:20 +0000 |
parents | 64a44155a525 |
children | cf1622476eb7 |
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 | |
27 #include "avformat.h" | |
28 #include "bswap.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; // | |
49 unsigned int audio_subsegments; ///< audio subsegments on one segment | |
50 | |
51 uint8_t audio_packet_count; | |
52 | |
53 } MTVDemuxContext; | |
54 | |
55 static int mtv_probe(AVProbeData *p) | |
56 { | |
57 if(p->buf_size < 3) | |
58 return 0; | |
59 | |
60 /* Magic is 'AMV' */ | |
61 | |
62 if(*(p->buf) != 'A' || *(p->buf+1) != 'M' || *(p->buf+2) != 'V') | |
63 return 0; | |
64 | |
65 return AVPROBE_SCORE_MAX; | |
66 } | |
67 | |
68 static int mtv_read_header(AVFormatContext *s, AVFormatParameters *ap) | |
69 { | |
70 MTVDemuxContext *mtv = s->priv_data; | |
71 ByteIOContext *pb = &s->pb; | |
72 AVStream *st; | |
73 | |
74 | |
75 url_fskip(pb, 3); | |
76 mtv->file_size = get_le32(pb); | |
77 mtv->segments = get_le32(pb); | |
78 url_fskip(pb, 32); | |
79 mtv->audio_identifier = get_le24(pb); | |
80 mtv->audio_br = get_le16(pb); | |
81 mtv->img_colorfmt = get_le24(pb); | |
82 mtv->img_bpp = get_byte(pb); | |
83 mtv->img_width = get_le16(pb); | |
84 mtv->img_height = get_le16(pb); | |
85 mtv->img_segment_size = get_le16(pb); | |
86 url_fskip(pb, 4); | |
87 mtv->audio_subsegments = get_le16(pb); | |
88 mtv->video_fps = (mtv->audio_br / 4) / mtv->audio_subsegments; | |
89 | |
90 /* FIXME Add sanity check here */ | |
91 | |
92 /* first packet is allways audio*/ | |
93 | |
94 mtv->audio_packet_count = 1; | |
95 | |
96 /* all systems go! init decoders */ | |
97 | |
98 /* video - raw rgb565 */ | |
99 | |
100 st = av_new_stream(s, VIDEO_SID); | |
101 if(!st) | |
102 return AVERROR_NOMEM; | |
103 | |
104 av_set_pts_info(st, 64, 1, mtv->video_fps); | |
105 st->codec->codec_type = CODEC_TYPE_VIDEO; | |
106 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
|
107 st->codec->codec_tag = MKTAG('R', 'G', 'B', mtv->img_bpp); |
1380 | 108 st->codec->width = mtv->img_width; |
109 st->codec->height = mtv->img_height; | |
110 st->codec->bits_per_sample = mtv->img_bpp; | |
111 st->codec->sample_rate = mtv->video_fps; | |
112 | |
113 /* audio - mp3 */ | |
114 | |
115 st = av_new_stream(s, AUDIO_SID); | |
116 if(!st) | |
117 return AVERROR_NOMEM; | |
118 | |
119 av_set_pts_info(st, 64, 1, AUDIO_SAMPLING_RATE); | |
120 st->codec->codec_type = CODEC_TYPE_AUDIO; | |
121 st->codec->codec_id = CODEC_ID_MP3; | |
122 st->codec->bit_rate = mtv->audio_br; | |
123 st->need_parsing=1; | |
124 | |
125 /* Jump over header */ | |
126 | |
127 if(url_fseek(pb, MTV_HEADER_SIZE, SEEK_SET) != MTV_HEADER_SIZE) | |
128 return AVERROR_IO; | |
129 | |
130 return(0); | |
131 | |
132 } | |
133 | |
134 static int mtv_read_packet(AVFormatContext *s, AVPacket *pkt) | |
135 { | |
136 MTVDemuxContext *mtv = s->priv_data; | |
137 ByteIOContext *pb = &s->pb; | |
138 int ret; | |
139 #ifndef WORDS_BIGENDIAN | |
140 int i; | |
141 #endif | |
142 | |
143 ret = 0; | |
144 | |
145 if(mtv->audio_subsegments >= mtv->audio_packet_count) | |
146 { | |
147 url_fskip(pb, MTV_AUDIO_PADDING_SIZE); | |
148 | |
149 ret = av_get_packet(pb, pkt, MTV_ASUBCHUNK_DATA_SIZE); | |
150 if(ret != MTV_ASUBCHUNK_DATA_SIZE) | |
151 return AVERROR_IO; | |
152 | |
153 mtv->audio_packet_count++; | |
154 pkt->stream_index = AUDIO_SID; | |
155 | |
156 }else | |
157 { | |
158 ret = av_get_packet(pb, pkt, mtv->img_segment_size); | |
159 if(ret != mtv->img_segment_size) | |
160 return AVERROR_IO; | |
161 | |
162 #ifndef WORDS_BIGENDIAN | |
163 | |
164 /* pkt->data is GGGRRRR BBBBBGGG | |
165 * and we need RRRRRGGG GGGBBBBB | |
166 * for PIX_FMT_RGB565 so here we | |
167 * just swap bytes as they come | |
168 */ | |
169 | |
170 for(i=0;i<mtv->img_segment_size/2;i++) | |
171 *((uint16_t *)pkt->data+i) = bswap_16(*((uint16_t *)pkt->data+i)); | |
172 #endif | |
173 mtv->audio_packet_count = 1; | |
174 pkt->stream_index = VIDEO_SID; | |
175 } | |
176 | |
177 return(ret); | |
178 } | |
179 | |
180 AVInputFormat mtv_demuxer = { | |
181 "MTV", | |
182 "MTV format", | |
183 sizeof(MTVDemuxContext), | |
184 mtv_probe, | |
185 mtv_read_header, | |
186 mtv_read_packet, | |
187 }; |