3 * Copyright (c) 2006 Reimar Doeffinger.
5 * This file is part of FFmpeg.
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.
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.
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
37 static int nuv_probe(AVProbeData *p) {
38 if (!memcmp(p->buf, "NuppelVideo", 12))
39 return AVPROBE_SCORE_MAX;
40 if (!memcmp(p->buf, "MythTVVideo", 12))
41 return AVPROBE_SCORE_MAX;
45 //! little macro to sanitize packet size
46 #define PKTSIZE(s) (s & 0xffffff)
49 * \brief read until we found all data needed for decoding
50 * \param vst video stream of which to change parameters
51 * \param ast video stream of which to change parameters
52 * \param myth set if this is a MythTVVideo format file
53 * \return 1 if all required codec data was found
55 static int get_codec_data(ByteIOContext *pb, AVStream *vst,
56 AVStream *ast, int myth) {
57 frametype_t frametype;
59 return 1; // no codec data needed
60 while (!url_feof(pb)) {
62 frametype = get_byte(pb);
65 subtype = get_byte(pb);
67 size = PKTSIZE(get_le32(pb));
68 if (vst && subtype == 'R') {
69 vst->codec->extradata_size = size;
70 vst->codec->extradata = av_malloc(size);
71 get_buffer(pb, vst->codec->extradata, size);
79 size = PKTSIZE(get_le32(pb));
82 get_le32(pb); // version
84 vst->codec->codec_tag = get_le32(pb);
85 vst->codec->codec_id =
86 codec_get_id(codec_bmp_tags, vst->codec->codec_tag);
91 ast->codec->codec_tag = get_le32(pb);
92 ast->codec->sample_rate = get_le32(pb);
93 ast->codec->bits_per_sample = get_le32(pb);
94 ast->codec->channels = get_le32(pb);
95 ast->codec->codec_id =
96 wav_codec_get_id(ast->codec->codec_tag,
97 ast->codec->bits_per_sample);
98 ast->need_parsing = AVSTREAM_PARSE_FULL;
100 url_fskip(pb, 4 * 4);
110 size = PKTSIZE(get_le32(pb));
118 static int nuv_header(AVFormatContext *s, AVFormatParameters *ap) {
119 NUVContext *ctx = s->priv_data;
120 ByteIOContext *pb = &s->pb;
121 char id_string[12], version_string[5];
123 int is_mythtv, width, height, v_packs, a_packs;
125 AVStream *vst = NULL, *ast = NULL;
126 get_buffer(pb, id_string, 12);
127 is_mythtv = !memcmp(id_string, "MythTVVideo", 12);
128 get_buffer(pb, version_string, 5);
129 url_fskip(pb, 3); // padding
130 width = get_le32(pb);
131 height = get_le32(pb);
132 get_le32(pb); // unused, "desiredwidth"
133 get_le32(pb); // unused, "desiredheight"
134 get_byte(pb); // 'P' == progressive, 'I' == interlaced
135 url_fskip(pb, 3); // padding
136 aspect = av_int2dbl(get_le64(pb));
137 fps = av_int2dbl(get_le64(pb));
139 // number of packets per stream type, -1 means unknown, e.g. streaming
140 v_packs = get_le32(pb);
141 a_packs = get_le32(pb);
142 get_le32(pb); // text
144 get_le32(pb); // keyframe distance (?)
147 ctx->v_id = stream_nr++;
148 vst = av_new_stream(s, ctx->v_id);
149 vst->codec->codec_type = CODEC_TYPE_VIDEO;
150 vst->codec->codec_id = CODEC_ID_NUV;
151 vst->codec->codec_tag = MKTAG('R', 'J', 'P', 'G');
152 vst->codec->width = width;
153 vst->codec->height = height;
154 vst->codec->bits_per_sample = 10;
155 vst->codec->sample_aspect_ratio = av_d2q(aspect, 10000);
156 vst->r_frame_rate = av_d2q(fps, 60000);
157 av_set_pts_info(vst, 32, 1, 1000);
162 ctx->a_id = stream_nr++;
163 ast = av_new_stream(s, ctx->a_id);
164 ast->codec->codec_type = CODEC_TYPE_AUDIO;
165 ast->codec->codec_id = CODEC_ID_PCM_S16LE;
166 ast->codec->channels = 2;
167 ast->codec->sample_rate = 44100;
168 ast->codec->bit_rate = 2 * 2 * 44100 * 8;
169 ast->codec->block_align = 2 * 2;
170 ast->codec->bits_per_sample = 16;
171 av_set_pts_info(ast, 32, 1, 1000);
175 get_codec_data(pb, vst, ast, is_mythtv);
181 static int nuv_packet(AVFormatContext *s, AVPacket *pkt) {
182 NUVContext *ctx = s->priv_data;
183 ByteIOContext *pb = &s->pb;
184 uint8_t hdr[HDRSIZE];
185 frametype_t frametype;
187 while (!url_feof(pb)) {
188 ret = get_buffer(pb, hdr, HDRSIZE);
190 return ret ? ret : -1;
192 size = PKTSIZE(AV_RL32(&hdr[8]));
197 av_log(s, AV_LOG_ERROR, "Video packet in file without video stream!\n");
201 ret = av_new_packet(pkt, HDRSIZE + size);
204 pkt->pos = url_ftell(pb);
205 pkt->pts = AV_RL32(&hdr[4]);
206 pkt->stream_index = ctx->v_id;
207 memcpy(pkt->data, hdr, HDRSIZE);
208 ret = get_buffer(pb, pkt->data + HDRSIZE, size);
212 av_log(s, AV_LOG_ERROR, "Audio packet in file without audio stream!\n");
216 ret = av_get_packet(pb, pkt, size);
217 pkt->pts = AV_RL32(&hdr[4]);
218 pkt->stream_index = ctx->a_id;
221 // contains no data, size value is invalid
231 AVInputFormat nuv_demuxer = {
233 "NuppelVideo format",