Mercurial > libavformat.hg
annotate nuv.c @ 1265:613fdf995af0 libavformat
read and use index (based on a patch by John Donaghy on the 23-03-2006 '[Ffmpeg-devel] dvr-ms seek help request')
author | michael |
---|---|
date | Wed, 23 Aug 2006 17:07:01 +0000 |
parents | 6a5e58d2114b |
children | 0899bfe4105c |
rev | line source |
---|---|
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
1 /* |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
2 * NuppelVideo demuxer. |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
3 * Copyright (c) 2006 Reimar Doeffinger. |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
4 * |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
5 * This library is free software; you can redistribute it and/or |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
6 * modify it under the terms of the GNU Lesser General Public |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
7 * License as published by the Free Software Foundation; either |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
8 * version 2 of the License, or (at your option) any later version. |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
9 * |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
10 * This library is distributed in the hope that it will be useful, |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
13 * Lesser General Public License for more details. |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
14 * |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
15 * You should have received a copy of the GNU Lesser General Public |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
16 * License along with this library; if not, write to the Free Software |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
18 */ |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
19 #include "avformat.h" |
1172
6a5e58d2114b
move common stuff from avienc.c and wav.c to new file riff.c
mru
parents:
1169
diff
changeset
|
20 #include "riff.h" |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
21 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
22 typedef struct { |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
23 int v_id; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
24 int a_id; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
25 } NUVContext; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
26 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
27 typedef enum { |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
28 NUV_VIDEO = 'V', |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
29 NUV_EXTRADATA = 'D', |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
30 NUV_AUDIO = 'A', |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
31 NUV_SEEKP = 'R', |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
32 NUV_MYTHEXT = 'X' |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
33 } frametype_t; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
34 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
35 static int nuv_probe(AVProbeData *p) { |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
36 if (p->buf_size < 12) |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
37 return 0; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
38 if (!memcmp(p->buf, "NuppelVideo", 12)) |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
39 return AVPROBE_SCORE_MAX; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
40 if (!memcmp(p->buf, "MythTVVideo", 12)) |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
41 return AVPROBE_SCORE_MAX; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
42 return 0; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
43 } |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
44 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
45 //! little macro to sanitize packet size |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
46 #define PKTSIZE(s) (s & 0xffffff) |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
47 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
48 /** |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
49 * \brief read until we found all data needed for decoding |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
50 * \param vst video stream of which to change parameters |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
51 * \param ast video stream of which to change parameters |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
52 * \param myth set if this is a MythTVVideo format file |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
53 * \return 1 if all required codec data was found |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
54 */ |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
55 static int get_codec_data(ByteIOContext *pb, AVStream *vst, |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
56 AVStream *ast, int myth) { |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
57 frametype_t frametype; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
58 if (!vst && !myth) |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
59 return 1; // no codec data needed |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
60 while (!url_feof(pb)) { |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
61 int size, subtype; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
62 frametype = get_byte(pb); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
63 switch (frametype) { |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
64 case NUV_EXTRADATA: |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
65 subtype = get_byte(pb); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
66 url_fskip(pb, 6); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
67 size = PKTSIZE(get_le32(pb)); |
1064
bd570485d419
Avoid crash if there is a rtjpeg quant header but no video stream in file
reimar
parents:
1044
diff
changeset
|
68 if (vst && subtype == 'R') { |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
69 vst->codec->extradata_size = size; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
70 vst->codec->extradata = av_malloc(size); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
71 get_buffer(pb, vst->codec->extradata, size); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
72 size = 0; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
73 if (!myth) |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
74 return 1; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
75 } |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
76 break; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
77 case NUV_MYTHEXT: |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
78 url_fskip(pb, 7); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
79 size = PKTSIZE(get_le32(pb)); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
80 if (size != 128 * 4) |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
81 break; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
82 get_le32(pb); // version |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
83 if (vst) { |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
84 vst->codec->codec_tag = get_le32(pb); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
85 vst->codec->codec_id = |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
86 codec_get_id(codec_bmp_tags, vst->codec->codec_tag); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
87 } else |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
88 url_fskip(pb, 4); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
89 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
90 if (ast) { |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
91 ast->codec->codec_tag = get_le32(pb); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
92 ast->codec->sample_rate = get_le32(pb); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
93 ast->codec->bits_per_sample = get_le32(pb); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
94 ast->codec->channels = get_le32(pb); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
95 ast->codec->codec_id = |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
96 wav_codec_get_id(ast->codec->codec_tag, |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
97 ast->codec->bits_per_sample); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
98 } else |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
99 url_fskip(pb, 4 * 4); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
100 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
101 size -= 6 * 4; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
102 url_fskip(pb, size); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
103 return 1; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
104 case NUV_SEEKP: |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
105 size = 11; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
106 break; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
107 default: |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
108 url_fskip(pb, 7); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
109 size = PKTSIZE(get_le32(pb)); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
110 break; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
111 } |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
112 url_fskip(pb, size); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
113 } |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
114 return 0; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
115 } |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
116 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
117 static int nuv_header(AVFormatContext *s, AVFormatParameters *ap) { |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
118 NUVContext *ctx = (NUVContext *)s->priv_data; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
119 ByteIOContext *pb = &s->pb; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
120 char id_string[12], version_string[5]; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
121 double aspect, fps; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
122 int is_mythtv, width, height, v_packs, a_packs; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
123 int stream_nr = 0; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
124 AVStream *vst = NULL, *ast = NULL; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
125 get_buffer(pb, id_string, 12); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
126 is_mythtv = !memcmp(id_string, "MythTVVideo", 12); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
127 get_buffer(pb, version_string, 5); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
128 url_fskip(pb, 3); // padding |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
129 width = get_le32(pb); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
130 height = get_le32(pb); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
131 get_le32(pb); // unused, "desiredwidth" |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
132 get_le32(pb); // unused, "desiredheight" |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
133 get_byte(pb); // 'P' == progressive, 'I' == interlaced |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
134 url_fskip(pb, 3); // padding |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
135 aspect = av_int2dbl(get_le64(pb)); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
136 fps = av_int2dbl(get_le64(pb)); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
137 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
138 // number of packets per stream type, -1 means unknown, e.g. streaming |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
139 v_packs = get_le32(pb); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
140 a_packs = get_le32(pb); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
141 get_le32(pb); // text |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
142 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
143 get_le32(pb); // keyframe distance (?) |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
144 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
145 if (v_packs) { |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
146 ctx->v_id = stream_nr++; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
147 vst = av_new_stream(s, ctx->v_id); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
148 vst->codec->codec_type = CODEC_TYPE_VIDEO; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
149 vst->codec->codec_id = CODEC_ID_NUV; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
150 vst->codec->codec_tag = MKTAG('R', 'J', 'P', 'G'); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
151 vst->codec->width = width; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
152 vst->codec->height = height; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
153 vst->codec->bits_per_sample = 10; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
154 vst->codec->sample_aspect_ratio = av_d2q(aspect, 10000); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
155 vst->r_frame_rate = av_d2q(1.0 / fps, 10000); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
156 av_set_pts_info(vst, 32, 1, 1000); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
157 } else |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
158 ctx->v_id = -1; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
159 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
160 if (a_packs) { |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
161 ctx->a_id = stream_nr++; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
162 ast = av_new_stream(s, ctx->a_id); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
163 ast->codec->codec_type = CODEC_TYPE_AUDIO; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
164 ast->codec->codec_id = CODEC_ID_PCM_S16LE; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
165 ast->codec->channels = 2; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
166 ast->codec->sample_rate = 44100; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
167 ast->codec->bit_rate = 2 * 2 * 44100 * 8; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
168 ast->codec->block_align = 2 * 2; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
169 ast->codec->bits_per_sample = 16; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
170 av_set_pts_info(ast, 32, 1, 1000); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
171 } else |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
172 ctx->a_id = -1; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
173 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
174 get_codec_data(pb, vst, ast, is_mythtv); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
175 return 0; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
176 } |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
177 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
178 #define HDRSIZE 12 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
179 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
180 static int nuv_packet(AVFormatContext *s, AVPacket *pkt) { |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
181 NUVContext *ctx = (NUVContext *)s->priv_data; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
182 ByteIOContext *pb = &s->pb; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
183 uint8_t hdr[HDRSIZE]; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
184 frametype_t frametype; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
185 int ret, size; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
186 while (!url_feof(pb)) { |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
187 ret = get_buffer(pb, hdr, HDRSIZE); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
188 if (ret <= 0) |
1109
725b291bf94f
read_packet return value must be < 0 when no packet is returned, including EOF.
reimar
parents:
1064
diff
changeset
|
189 return ret ? ret : -1; |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
190 frametype = hdr[0]; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
191 size = PKTSIZE(LE_32(&hdr[8])); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
192 switch (frametype) { |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
193 case NUV_VIDEO: |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
194 case NUV_EXTRADATA: |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
195 if (ctx->v_id < 0) { |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
196 av_log(s, AV_LOG_ERROR, "Video packet in file without video stream!\n"); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
197 url_fskip(pb, size); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
198 break; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
199 } |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
200 ret = av_new_packet(pkt, HDRSIZE + size); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
201 if (ret < 0) |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
202 return ret; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
203 pkt->pos = url_ftell(pb); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
204 pkt->pts = LE_32(&hdr[4]); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
205 pkt->stream_index = ctx->v_id; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
206 memcpy(pkt->data, hdr, HDRSIZE); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
207 ret = get_buffer(pb, pkt->data + HDRSIZE, size); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
208 return ret; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
209 case NUV_AUDIO: |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
210 if (ctx->a_id < 0) { |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
211 av_log(s, AV_LOG_ERROR, "Audio packet in file without audio stream!\n"); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
212 url_fskip(pb, size); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
213 break; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
214 } |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
215 ret = av_get_packet(pb, pkt, size); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
216 pkt->pts = LE_32(&hdr[4]); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
217 pkt->stream_index = ctx->a_id; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
218 return ret; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
219 case NUV_SEEKP: |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
220 // contains no data, size value is invalid |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
221 break; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
222 default: |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
223 url_fskip(pb, size); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
224 break; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
225 } |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
226 } |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
227 return AVERROR_IO; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
228 } |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
229 |
1169 | 230 AVInputFormat nuv_demuxer = { |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
231 "nuv", |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
232 "NuppelVideo format", |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
233 sizeof(NUVContext), |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
234 nuv_probe, |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
235 nuv_header, |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
236 nuv_packet, |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
237 NULL, |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
238 NULL, |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
239 }; |