Mercurial > mplayer.hg
annotate libmpdemux/demux_y4m.c @ 31673:cb6e9b6d8811
Reindent.
author | reimar |
---|---|
date | Thu, 15 Jul 2010 18:18:15 +0000 |
parents | b240cee8506d |
children | c08363dc5320 |
rev | line source |
---|---|
29238
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25707
diff
changeset
|
1 /* |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25707
diff
changeset
|
2 * Y4M file parser |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25707
diff
changeset
|
3 * copyright (c) 2001 Rik Snel |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25707
diff
changeset
|
4 * (using yuv4mpeg*.[ch] from mjpeg.sourceforge.net) |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25707
diff
changeset
|
5 * (derived from demux_viv.c) |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25707
diff
changeset
|
6 * older YUV4MPEG (used by xawtv) support by Alex Beregszaszi |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25707
diff
changeset
|
7 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25707
diff
changeset
|
8 * This file is part of MPlayer. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25707
diff
changeset
|
9 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25707
diff
changeset
|
10 * MPlayer is free software; you can redistribute it and/or modify |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25707
diff
changeset
|
11 * it under the terms of the GNU General Public License as published by |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25707
diff
changeset
|
12 * the Free Software Foundation; either version 2 of the License, or |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25707
diff
changeset
|
13 * (at your option) any later version. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25707
diff
changeset
|
14 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25707
diff
changeset
|
15 * MPlayer is distributed in the hope that it will be useful, |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25707
diff
changeset
|
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25707
diff
changeset
|
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25707
diff
changeset
|
18 * GNU General Public License for more details. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25707
diff
changeset
|
19 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25707
diff
changeset
|
20 * You should have received a copy of the GNU General Public License along |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25707
diff
changeset
|
21 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25707
diff
changeset
|
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25707
diff
changeset
|
23 */ |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
24 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
25 #include <stdio.h> |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
26 #include <stdlib.h> |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
27 #include <unistd.h> |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
28 #include <string.h> /* strtok */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
29 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
30 #include "config.h" |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
31 #include "mp_msg.h" |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
32 #include "help_mp.h" |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
33 #include "yuv4mpeg.h" |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
34 |
22605
4d81dbdf46b9
Add explicit location for headers from the stream/ directory.
diego
parents:
21421
diff
changeset
|
35 //#include "stream/stream.h" |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
36 #include "demuxer.h" |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
37 #include "stheader.h" |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
38 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
39 typedef struct { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
40 int framenum; |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
41 y4m_stream_info_t* si; |
3789
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
42 int is_older; |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
43 } y4m_priv_t; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
44 |
16175 | 45 static int y4m_check_file(demuxer_t* demuxer){ |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
46 int orig_pos = stream_tell(demuxer->stream); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
47 char buf[10]; |
3789
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
48 y4m_priv_t* priv; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
49 |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
50 mp_msg(MSGT_DEMUX, MSGL_V, "Checking for YUV4MPEG2\n"); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
51 |
15817 | 52 if(stream_read(demuxer->stream, buf, 9)!=9) |
53 return 0; | |
54 | |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
55 buf[9] = 0; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
56 |
3789
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
57 if (strncmp("YUV4MPEG2", buf, 9) && strncmp("YUV4MPEG ", buf, 9)) { |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
58 return 0; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
59 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
60 |
3789
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
61 demuxer->priv = malloc(sizeof(y4m_priv_t)); |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
62 priv = demuxer->priv; |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
63 |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
64 priv->is_older = 0; |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
65 |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
66 if (!strncmp("YUV4MPEG ", buf, 9)) |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
67 { |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
68 mp_msg(MSGT_DEMUX, MSGL_V, "Found older YUV4MPEG format (used by xawtv)\n"); |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
69 priv->is_older = 1; |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
70 } |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
71 |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
72 mp_msg(MSGT_DEMUX,MSGL_DBG2,"Success: YUV4MPEG2\n"); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
73 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
74 stream_seek(demuxer->stream, orig_pos); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
75 |
16175 | 76 return DEMUXER_TYPE_Y4M; |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
77 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
78 |
30928 | 79 static void read_streaminfo(demuxer_t *demuxer); |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
80 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
81 // return value: |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
82 // 0 = EOF or no stream found |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
83 // 1 = successfully read a packet |
16175 | 84 static int demux_y4m_fill_buffer(demuxer_t *demux, demux_stream_t *dsds) { |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
85 demux_stream_t *ds=demux->video; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
86 demux_packet_t *dp; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
87 y4m_priv_t *priv=demux->priv; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
88 y4m_frame_info_t fi; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
89 unsigned char *buf[3]; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
90 int err, size; |
30928 | 91 int nextc; |
92 | |
93 nextc = stream_read_char(demux->stream); | |
94 stream_skip(demux->stream, -1); | |
95 if (nextc == 'Y') { | |
96 read_streaminfo(demux); | |
97 demux->seekable = 0; | |
98 } | |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
99 |
9654
ee7203b48e7c
fix crash on streams with frame tags, patch by Brett Kosinski <brettk@frodo.dyn.gno.org>
alex
parents:
5810
diff
changeset
|
100 y4m_init_frame_info(&fi); |
ee7203b48e7c
fix crash on streams with frame tags, patch by Brett Kosinski <brettk@frodo.dyn.gno.org>
alex
parents:
5810
diff
changeset
|
101 |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
102 demux->filepos=stream_tell(demux->stream); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
103 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
104 size = ((sh_video_t*)ds->sh)->disp_w*((sh_video_t*)ds->sh)->disp_h; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
105 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
106 dp = new_demux_packet(3*size/2); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
107 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
108 /* swap U and V components */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
109 buf[0] = dp->buffer; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
110 buf[1] = dp->buffer + 5*size/4; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
111 buf[2] = dp->buffer + size; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
112 |
3789
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
113 if (priv->is_older) |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
114 { |
3790 | 115 int c; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
116 |
3790 | 117 c = stream_read_char(demux->stream); /* F */ |
118 if (c == -256) | |
119 return 0; /* EOF */ | |
120 if (c != 'F') | |
121 { | |
3863 | 122 mp_msg(MSGT_DEMUX, MSGL_V, "Bad frame at %d\n", (int)stream_tell(demux->stream)-1); |
3790 | 123 return 0; |
124 } | |
125 stream_skip(demux->stream, 5); /* RAME\n */ | |
3789
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
126 stream_read(demux->stream, buf[0], size); |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
127 stream_read(demux->stream, buf[1], size/4); |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
128 stream_read(demux->stream, buf[2], size/4); |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
129 } |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
130 else |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
131 { |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
132 if ((err=y4m_read_frame(demux->stream, priv->si, &fi, buf)) != Y4M_OK) { |
31398 | 133 mp_msg(MSGT_DEMUX, MSGL_ERR, "error reading frame %s\n", y4m_strerr(err)); |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
134 return 0; |
3789
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
135 } |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
136 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
137 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
138 /* This seems to be the right way to calculate the presentation time stamp */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
139 dp->pts=(float)priv->framenum/((sh_video_t*)ds->sh)->fps; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
140 priv->framenum++; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
141 dp->pos=demux->filepos; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
142 dp->flags=0; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
143 ds_add_packet(ds, dp); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
144 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
145 return 1; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
146 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
147 |
30928 | 148 static void read_streaminfo(demuxer_t *demuxer) |
149 { | |
150 y4m_priv_t *priv = demuxer->priv; | |
151 sh_video_t *sh = demuxer->video->sh; | |
3800 | 152 y4m_ratio_t ratio; |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
153 int err; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
154 |
3789
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
155 if (priv->is_older) |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
156 { |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
157 char buf[4]; |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
158 int frame_rate_code; |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
159 |
3789
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
160 stream_skip(demuxer->stream, 8); /* YUV4MPEG */ |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
161 stream_skip(demuxer->stream, 1); /* space */ |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
162 stream_read(demuxer->stream, (char *)&buf[0], 3); |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
163 buf[3] = 0; |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
164 sh->disp_w = atoi(buf); |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
165 stream_skip(demuxer->stream, 1); /* space */ |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
166 stream_read(demuxer->stream, (char *)&buf[0], 3); |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
167 buf[3] = 0; |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
168 sh->disp_h = atoi(buf); |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
169 stream_skip(demuxer->stream, 1); /* space */ |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
170 stream_read(demuxer->stream, (char *)&buf[0], 1); |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
171 buf[1] = 0; |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
172 frame_rate_code = atoi(buf); |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
173 stream_skip(demuxer->stream, 1); /* new-line */ |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
174 |
3789
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
175 if (!sh->fps) |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
176 { |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
177 /* values from xawtv */ |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
178 switch(frame_rate_code) |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
179 { |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
180 case 1: |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
181 sh->fps = 23.976f; |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
182 break; |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
183 case 2: |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
184 sh->fps = 24.0f; |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
185 break; |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
186 case 3: |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
187 sh->fps = 25.0f; |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
188 break; |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
189 case 4: |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
190 sh->fps = 29.97f; |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
191 break; |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
192 case 5: |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
193 sh->fps = 30.0f; |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
194 break; |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
195 case 6: |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
196 sh->fps = 50.0f; |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
197 break; |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
198 case 7: |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
199 sh->fps = 59.94f; |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
200 break; |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
201 case 8: |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
202 sh->fps = 60.0f; |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
203 break; |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
204 default: |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
205 sh->fps = 25.0f; |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
206 } |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
207 } |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
208 sh->frametime = 1.0f/sh->fps; |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
209 } |
3789
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
210 else |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
211 { |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
212 y4m_init_stream_info(priv->si); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
213 if ((err=y4m_read_stream_header(demuxer->stream, priv->si)) != Y4M_OK) |
3789
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
214 mp_msg(MSGT_DEMUXER, MSGL_FATAL, "error parsing YUV4MPEG header: %s\n", y4m_strerr(err)); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
215 |
3789
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
216 if(!sh->fps) { |
3800 | 217 ratio = y4m_si_get_framerate(priv->si); |
218 if (ratio.d != 0) | |
219 sh->fps=(float)ratio.n/(float)ratio.d; | |
3789
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
220 else |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
221 sh->fps=15.0f; |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
222 } |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
223 sh->frametime=1.0f/sh->fps; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
224 |
3800 | 225 ratio = y4m_si_get_sampleaspect(priv->si); |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
226 |
3789
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
227 sh->disp_w = y4m_si_get_width(priv->si); |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
228 sh->disp_h = y4m_si_get_height(priv->si); |
12529
74968e3440ff
fix bug reported by Leonardo Giordani: sh->aspect is not pixel aspect but movie aspect
rik
parents:
9654
diff
changeset
|
229 |
74968e3440ff
fix bug reported by Leonardo Giordani: sh->aspect is not pixel aspect but movie aspect
rik
parents:
9654
diff
changeset
|
230 if (ratio.d != 0 && ratio.n != 0) |
74968e3440ff
fix bug reported by Leonardo Giordani: sh->aspect is not pixel aspect but movie aspect
rik
parents:
9654
diff
changeset
|
231 sh->aspect = (float)(sh->disp_w*ratio.n)/(float)(sh->disp_h*ratio.d); |
74968e3440ff
fix bug reported by Leonardo Giordani: sh->aspect is not pixel aspect but movie aspect
rik
parents:
9654
diff
changeset
|
232 |
3863 | 233 demuxer->seekable = 0; |
3789
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
234 } |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
235 |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
236 sh->format = mmioFOURCC('Y', 'V', '1', '2'); |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
237 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
238 sh->bih->biSize=40; |
3789
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
239 sh->bih->biWidth = sh->disp_w; |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
240 sh->bih->biHeight = sh->disp_h; |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
241 sh->bih->biPlanes=3; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
242 sh->bih->biBitCount=12; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
243 sh->bih->biCompression=sh->format; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
244 sh->bih->biSizeImage=sh->bih->biWidth*sh->bih->biHeight*3/2; /* YV12 */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
245 |
30928 | 246 mp_msg(MSGT_DEMUX, MSGL_INFO, "YUV4MPEG2 Video stream %d size: display: %dx%d, codec: %ux%u\n", |
247 demuxer->video->id, sh->disp_w, sh->disp_h, sh->bih->biWidth, | |
248 sh->bih->biHeight); | |
249 } | |
250 | |
251 static demuxer_t* demux_open_y4m(demuxer_t* demuxer){ | |
252 y4m_priv_t* priv = demuxer->priv; | |
253 sh_video_t* sh=new_sh_video(demuxer,0); | |
254 | |
255 priv->framenum = 0; | |
256 priv->si = malloc(sizeof(y4m_stream_info_t)); | |
257 | |
258 sh->bih=calloc(1, sizeof(BITMAPINFOHEADER)); | |
259 | |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
260 demuxer->video->sh=sh; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
261 sh->ds=demuxer->video; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
262 demuxer->video->id=0; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
263 |
30928 | 264 read_streaminfo(demuxer); |
16175 | 265 |
266 return demuxer; | |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
267 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
268 |
17636 | 269 static void demux_seek_y4m(demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags) { |
3863 | 270 sh_video_t* sh = demuxer->video->sh; |
271 y4m_priv_t* priv = demuxer->priv; | |
272 int rel_seek_frames = sh->fps*rel_seek_secs; | |
273 int size = 3*sh->disp_w*sh->disp_h/2; | |
274 off_t curr_pos = stream_tell(demuxer->stream); | |
275 | |
276 if (priv->framenum + rel_seek_frames < 0) rel_seek_frames = -priv->framenum; | |
277 | |
278 //printf("seektoframe=%d rel_seek_secs=%f seektooffset=%ld\n", priv->framenum + rel_seek_frames, rel_seek_secs, curr_pos + rel_seek_frames*(size+6)); | |
279 //printf("framenum=%d, curr_pos=%ld, currpos/(size+6)=%f\n", priv->framenum, curr_pos, (float)curr_pos/(float)(size+6)); | |
280 priv->framenum += rel_seek_frames; | |
281 | |
282 if (priv->is_older) { | |
283 /* Well this is easy: every frame takes up size+6 bytes | |
284 * in the stream and we may assume that the stream pointer | |
285 * is always at the beginning of a frame. | |
286 * framenum is the number of the frame that is about to be | |
287 * demuxed (counting from ONE (see demux_open_y4m)) */ | |
288 stream_seek(demuxer->stream, curr_pos + rel_seek_frames*(size+6)); | |
289 } else { | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
290 /* should never come here, because seeking for YUV4MPEG2 |
3863 | 291 * is disabled. */ |
292 mp_msg(MSGT_DEMUX, MSGL_WARN, "Seeking for YUV4MPEG2 not yet implemented!\n"); | |
293 } | |
294 } | |
295 | |
16175 | 296 static void demux_close_y4m(demuxer_t *demuxer) |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
297 { |
3800 | 298 y4m_priv_t* priv = demuxer->priv; |
5810 | 299 |
300 if(!priv) | |
301 return; | |
3789
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
302 if (!priv->is_older) |
811b2e1ff030
added support for older YUV4MPEG format (used by xawtv)
alex
parents:
3786
diff
changeset
|
303 y4m_fini_stream_info(((y4m_priv_t*)demuxer->priv)->si); |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
304 free(((y4m_priv_t*)demuxer->priv)->si); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
305 free(demuxer->priv); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
306 return; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
307 } |
16175 | 308 |
309 | |
25707
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
22605
diff
changeset
|
310 const demuxer_desc_t demuxer_desc_y4m = { |
16175 | 311 "YUV4MPEG2 demuxer", |
312 "y4m", | |
313 "YUV4MPEG2", | |
314 "Rik snel", | |
315 "", | |
316 DEMUXER_TYPE_Y4M, | |
317 1, // safe autodetect | |
318 y4m_check_file, | |
319 demux_y4m_fill_buffer, | |
320 demux_open_y4m, | |
321 demux_close_y4m, | |
322 demux_seek_y4m, | |
323 NULL | |
324 }; |