Mercurial > libavformat.hg
annotate nuv.c @ 4847:22aad159263c libavformat
cosmetics: Align output columns.
author | diego |
---|---|
date | Fri, 10 Apr 2009 15:16:11 +0000 |
parents | d99a060db4a4 |
children | 33a244b7ca65 |
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. |
4251
77e0c7511d41
cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents:
4201
diff
changeset
|
3 * Copyright (c) 2006 Reimar Doeffinger |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
4 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1172
diff
changeset
|
5 * This file is part of FFmpeg. |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1172
diff
changeset
|
6 * |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1172
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
9 * License as published by the Free Software Foundation; either |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1172
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
11 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1172
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
16 * |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1172
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
20 */ |
4201
7d2f3f1b68d8
Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents:
4077
diff
changeset
|
21 |
7d2f3f1b68d8
Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents:
4077
diff
changeset
|
22 #include "libavutil/intreadwrite.h" |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
23 #include "avformat.h" |
1172
6a5e58d2114b
move common stuff from avienc.c and wav.c to new file riff.c
mru
parents:
1169
diff
changeset
|
24 #include "riff.h" |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
25 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
26 typedef struct { |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
27 int v_id; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
28 int a_id; |
2536 | 29 int rtjpg_video; |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
30 } NUVContext; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
31 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
32 typedef enum { |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
33 NUV_VIDEO = 'V', |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
34 NUV_EXTRADATA = 'D', |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
35 NUV_AUDIO = 'A', |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
36 NUV_SEEKP = 'R', |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
37 NUV_MYTHEXT = 'X' |
4077 | 38 } nuv_frametype; |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
39 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
40 static int nuv_probe(AVProbeData *p) { |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
41 if (!memcmp(p->buf, "NuppelVideo", 12)) |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
42 return AVPROBE_SCORE_MAX; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
43 if (!memcmp(p->buf, "MythTVVideo", 12)) |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
44 return AVPROBE_SCORE_MAX; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
45 return 0; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
46 } |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
47 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
48 //! little macro to sanitize packet size |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
49 #define PKTSIZE(s) (s & 0xffffff) |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
50 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
51 /** |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
52 * \brief read until we found all data needed for decoding |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
53 * \param vst video stream of which to change parameters |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
54 * \param ast video stream of which to change parameters |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
55 * \param myth set if this is a MythTVVideo format file |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
56 * \return 1 if all required codec data was found |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
57 */ |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
58 static int get_codec_data(ByteIOContext *pb, AVStream *vst, |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
59 AVStream *ast, int myth) { |
4077 | 60 nuv_frametype frametype; |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
61 if (!vst && !myth) |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
62 return 1; // no codec data needed |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
63 while (!url_feof(pb)) { |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
64 int size, subtype; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
65 frametype = get_byte(pb); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
66 switch (frametype) { |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
67 case NUV_EXTRADATA: |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
68 subtype = get_byte(pb); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
69 url_fskip(pb, 6); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
70 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
|
71 if (vst && subtype == 'R') { |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
72 vst->codec->extradata_size = size; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
73 vst->codec->extradata = av_malloc(size); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
74 get_buffer(pb, vst->codec->extradata, size); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
75 size = 0; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
76 if (!myth) |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
77 return 1; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
78 } |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
79 break; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
80 case NUV_MYTHEXT: |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
81 url_fskip(pb, 7); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
82 size = PKTSIZE(get_le32(pb)); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
83 if (size != 128 * 4) |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
84 break; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
85 get_le32(pb); // version |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
86 if (vst) { |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
87 vst->codec->codec_tag = get_le32(pb); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
88 vst->codec->codec_id = |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
89 codec_get_id(codec_bmp_tags, vst->codec->codec_tag); |
2552 | 90 if (vst->codec->codec_tag == MKTAG('R', 'J', 'P', 'G')) |
91 vst->codec->codec_id = CODEC_ID_NUV; | |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
92 } else |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
93 url_fskip(pb, 4); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
94 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
95 if (ast) { |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
96 ast->codec->codec_tag = get_le32(pb); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
97 ast->codec->sample_rate = get_le32(pb); |
3908
1d3d17de20ba
Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents:
3759
diff
changeset
|
98 ast->codec->bits_per_coded_sample = get_le32(pb); |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
99 ast->codec->channels = get_le32(pb); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
100 ast->codec->codec_id = |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
101 wav_codec_get_id(ast->codec->codec_tag, |
3908
1d3d17de20ba
Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents:
3759
diff
changeset
|
102 ast->codec->bits_per_coded_sample); |
2100 | 103 ast->need_parsing = AVSTREAM_PARSE_FULL; |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
104 } else |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
105 url_fskip(pb, 4 * 4); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
106 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
107 size -= 6 * 4; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
108 url_fskip(pb, size); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
109 return 1; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
110 case NUV_SEEKP: |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
111 size = 11; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
112 break; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
113 default: |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
114 url_fskip(pb, 7); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
115 size = PKTSIZE(get_le32(pb)); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
116 break; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
117 } |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
118 url_fskip(pb, size); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
119 } |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
120 return 0; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
121 } |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
122 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
123 static int nuv_header(AVFormatContext *s, AVFormatParameters *ap) { |
2006 | 124 NUVContext *ctx = s->priv_data; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2552
diff
changeset
|
125 ByteIOContext *pb = s->pb; |
4822
a751c4815d2d
Do not uselessly read version string into a buffer.
reimar
parents:
4820
diff
changeset
|
126 char id_string[12]; |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
127 double aspect, fps; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
128 int is_mythtv, width, height, v_packs, a_packs; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
129 int stream_nr = 0; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
130 AVStream *vst = NULL, *ast = NULL; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
131 get_buffer(pb, id_string, 12); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
132 is_mythtv = !memcmp(id_string, "MythTVVideo", 12); |
4822
a751c4815d2d
Do not uselessly read version string into a buffer.
reimar
parents:
4820
diff
changeset
|
133 url_fskip(pb, 5); // version string |
1044
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 width = get_le32(pb); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
136 height = get_le32(pb); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
137 get_le32(pb); // unused, "desiredwidth" |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
138 get_le32(pb); // unused, "desiredheight" |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
139 get_byte(pb); // 'P' == progressive, 'I' == interlaced |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
140 url_fskip(pb, 3); // padding |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
141 aspect = av_int2dbl(get_le64(pb)); |
3598
50106b4dd6ba
Fix handling of old nuv files where an aspect of 1 actually means 4/3
reimar
parents:
3597
diff
changeset
|
142 if (aspect > 0.9999 && aspect < 1.0001) |
50106b4dd6ba
Fix handling of old nuv files where an aspect of 1 actually means 4/3
reimar
parents:
3597
diff
changeset
|
143 aspect = 4.0 / 3.0; |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
144 fps = av_int2dbl(get_le64(pb)); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
145 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
146 // number of packets per stream type, -1 means unknown, e.g. streaming |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
147 v_packs = get_le32(pb); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
148 a_packs = get_le32(pb); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
149 get_le32(pb); // text |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
150 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
151 get_le32(pb); // keyframe distance (?) |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
152 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
153 if (v_packs) { |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
154 ctx->v_id = stream_nr++; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
155 vst = av_new_stream(s, ctx->v_id); |
3401 | 156 if (!vst) |
157 return AVERROR(ENOMEM); | |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
158 vst->codec->codec_type = CODEC_TYPE_VIDEO; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
159 vst->codec->codec_id = CODEC_ID_NUV; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
160 vst->codec->width = width; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
161 vst->codec->height = height; |
3908
1d3d17de20ba
Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents:
3759
diff
changeset
|
162 vst->codec->bits_per_coded_sample = 10; |
3759
27537074f2a9
convert every muxer/demuxer to write/read sample_aspect_ratio from/to
aurel
parents:
3598
diff
changeset
|
163 vst->sample_aspect_ratio = av_d2q(aspect * height / width, 10000); |
1749
3711f46dcb98
10l to whoever wrote this (wrong fps, fixes nirvana.nuv)
michael
parents:
1673
diff
changeset
|
164 vst->r_frame_rate = av_d2q(fps, 60000); |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
165 av_set_pts_info(vst, 32, 1, 1000); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
166 } else |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
167 ctx->v_id = -1; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
168 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
169 if (a_packs) { |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
170 ctx->a_id = stream_nr++; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
171 ast = av_new_stream(s, ctx->a_id); |
3401 | 172 if (!ast) |
173 return AVERROR(ENOMEM); | |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
174 ast->codec->codec_type = CODEC_TYPE_AUDIO; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
175 ast->codec->codec_id = CODEC_ID_PCM_S16LE; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
176 ast->codec->channels = 2; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
177 ast->codec->sample_rate = 44100; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
178 ast->codec->bit_rate = 2 * 2 * 44100 * 8; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
179 ast->codec->block_align = 2 * 2; |
3908
1d3d17de20ba
Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents:
3759
diff
changeset
|
180 ast->codec->bits_per_coded_sample = 16; |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
181 av_set_pts_info(ast, 32, 1, 1000); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
182 } else |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
183 ctx->a_id = -1; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
184 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
185 get_codec_data(pb, vst, ast, is_mythtv); |
3547
771cf9f79fd6
10l, fix nuv_header for the case when there is no video stream.
reimar
parents:
3424
diff
changeset
|
186 ctx->rtjpg_video = vst && vst->codec->codec_id == CODEC_ID_NUV; |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
187 return 0; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
188 } |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
189 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
190 #define HDRSIZE 12 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
191 |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
192 static int nuv_packet(AVFormatContext *s, AVPacket *pkt) { |
2006 | 193 NUVContext *ctx = s->priv_data; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2552
diff
changeset
|
194 ByteIOContext *pb = s->pb; |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
195 uint8_t hdr[HDRSIZE]; |
4077 | 196 nuv_frametype frametype; |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
197 int ret, size; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
198 while (!url_feof(pb)) { |
2536 | 199 int copyhdrsize = ctx->rtjpg_video ? HDRSIZE : 0; |
4683
d12f0e989bd5
Set AVPacket pos also for audio packets in nuv demuxer.
reimar
parents:
4251
diff
changeset
|
200 uint64_t pos = url_ftell(pb); |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
201 ret = get_buffer(pb, hdr, HDRSIZE); |
4820
bb26039e5f8c
Error out also when reading nuv header returns with partial data and return
reimar
parents:
4712
diff
changeset
|
202 if (ret < HDRSIZE) |
bb26039e5f8c
Error out also when reading nuv header returns with partial data and return
reimar
parents:
4712
diff
changeset
|
203 return ret < 0 ? ret : AVERROR(EIO); |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
204 frametype = hdr[0]; |
1673 | 205 size = PKTSIZE(AV_RL32(&hdr[8])); |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
206 switch (frametype) { |
2536 | 207 case NUV_EXTRADATA: |
208 if (!ctx->rtjpg_video) { | |
209 url_fskip(pb, size); | |
210 break; | |
211 } | |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
212 case NUV_VIDEO: |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
213 if (ctx->v_id < 0) { |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
214 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
|
215 url_fskip(pb, size); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
216 break; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
217 } |
2536 | 218 ret = av_new_packet(pkt, copyhdrsize + size); |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
219 if (ret < 0) |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
220 return ret; |
4685
98242eba0332
Mark all packets from nuv demuxer as keyframes in order to make seeking work.
reimar
parents:
4683
diff
changeset
|
221 // HACK: we have no idea if it is a keyframe, |
98242eba0332
Mark all packets from nuv demuxer as keyframes in order to make seeking work.
reimar
parents:
4683
diff
changeset
|
222 // but if we mark none seeking will not work at all. |
98242eba0332
Mark all packets from nuv demuxer as keyframes in order to make seeking work.
reimar
parents:
4683
diff
changeset
|
223 pkt->flags |= PKT_FLAG_KEY; |
4683
d12f0e989bd5
Set AVPacket pos also for audio packets in nuv demuxer.
reimar
parents:
4251
diff
changeset
|
224 pkt->pos = pos; |
1673 | 225 pkt->pts = AV_RL32(&hdr[4]); |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
226 pkt->stream_index = ctx->v_id; |
2536 | 227 memcpy(pkt->data, hdr, copyhdrsize); |
228 ret = get_buffer(pb, pkt->data + copyhdrsize, size); | |
4840
d99a060db4a4
Fix memleak in nuv demuxer: free packet already allocated packet when
reimar
parents:
4839
diff
changeset
|
229 if (ret < 0) { |
d99a060db4a4
Fix memleak in nuv demuxer: free packet already allocated packet when
reimar
parents:
4839
diff
changeset
|
230 av_free_packet(pkt); |
d99a060db4a4
Fix memleak in nuv demuxer: free packet already allocated packet when
reimar
parents:
4839
diff
changeset
|
231 return ret; |
d99a060db4a4
Fix memleak in nuv demuxer: free packet already allocated packet when
reimar
parents:
4839
diff
changeset
|
232 } |
4839
bab1f7903289
Correctly set packet size for partial video packets in nuv demuxer.
reimar
parents:
4823
diff
changeset
|
233 if (ret < size) |
bab1f7903289
Correctly set packet size for partial video packets in nuv demuxer.
reimar
parents:
4823
diff
changeset
|
234 av_shrink_packet(pkt, copyhdrsize + ret); |
4823 | 235 return 0; |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
236 case NUV_AUDIO: |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
237 if (ctx->a_id < 0) { |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
238 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
|
239 url_fskip(pb, size); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
240 break; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
241 } |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
242 ret = av_get_packet(pb, pkt, size); |
4685
98242eba0332
Mark all packets from nuv demuxer as keyframes in order to make seeking work.
reimar
parents:
4683
diff
changeset
|
243 pkt->flags |= PKT_FLAG_KEY; |
4683
d12f0e989bd5
Set AVPacket pos also for audio packets in nuv demuxer.
reimar
parents:
4251
diff
changeset
|
244 pkt->pos = pos; |
1673 | 245 pkt->pts = AV_RL32(&hdr[4]); |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
246 pkt->stream_index = ctx->a_id; |
4823 | 247 if (ret < 0) return ret; |
248 return 0; | |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
249 case NUV_SEEKP: |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
250 // contains no data, size value is invalid |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
251 break; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
252 default: |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
253 url_fskip(pb, size); |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
254 break; |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
255 } |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
256 } |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2100
diff
changeset
|
257 return AVERROR(EIO); |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
258 } |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
259 |
1169 | 260 AVInputFormat nuv_demuxer = { |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
261 "nuv", |
3424
7a0230981402
Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents:
3401
diff
changeset
|
262 NULL_IF_CONFIG_SMALL("NuppelVideo format"), |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
263 sizeof(NUVContext), |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
264 nuv_probe, |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
265 nuv_header, |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
266 nuv_packet, |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
267 NULL, |
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
268 NULL, |
4712
2809dfd4c881
Enable generic index creation and seeking for NUV demuxer.
reimar
parents:
4685
diff
changeset
|
269 .flags = AVFMT_GENERIC_INDEX, |
1044
3aeb079a7e74
NuppelVideo/MythTVVideo support, including rtjpeg decoder
reimar
parents:
diff
changeset
|
270 }; |