Mercurial > mplayer.hg
annotate libmpdemux/yuv4mpeg.c @ 32085:d947ba580cc9
Add required #includes to fix 'make checkheaders'.
author | diego |
---|---|
date | Sat, 11 Sep 2010 22:31:29 +0000 |
parents | 32725ca88fed |
children | b24236587d70 |
rev | line source |
---|---|
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
1 /* |
26744
8e5f8d682700
10l: Revert license header cleanup on imported files.
diego
parents:
26742
diff
changeset
|
2 * yuv4mpeg.c: Functions for reading and writing "new" YUV4MPEG streams |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
3 * |
26744
8e5f8d682700
10l: Revert license header cleanup on imported files.
diego
parents:
26742
diff
changeset
|
4 * Copyright (C) 2001 Matthew J. Marjanovic <maddog@mir.com> |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
5 * |
26745
3e373afedba2
Mark files that were imported from the MJPEG Tools suite as such.
diego
parents:
26744
diff
changeset
|
6 * This file is part of the MJPEG Tools package (mjpeg.sourceforge.net). |
26744
8e5f8d682700
10l: Revert license header cleanup on imported files.
diego
parents:
26742
diff
changeset
|
7 * Ported to mplayer by Rik Snel <rsnel@cube.dyndns.org> |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
8 * |
26744
8e5f8d682700
10l: Revert license header cleanup on imported files.
diego
parents:
26742
diff
changeset
|
9 * This program is free software; you can redistribute it and/or |
8e5f8d682700
10l: Revert license header cleanup on imported files.
diego
parents:
26742
diff
changeset
|
10 * modify it under the terms of the GNU General Public License |
8e5f8d682700
10l: Revert license header cleanup on imported files.
diego
parents:
26742
diff
changeset
|
11 * as published by the Free Software Foundation; either version 2 |
8e5f8d682700
10l: Revert license header cleanup on imported files.
diego
parents:
26742
diff
changeset
|
12 * of the License, or (at your option) any later version. |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
13 * |
26744
8e5f8d682700
10l: Revert license header cleanup on imported files.
diego
parents:
26742
diff
changeset
|
14 * This program is distributed in the hope that it will be useful, |
8e5f8d682700
10l: Revert license header cleanup on imported files.
diego
parents:
26742
diff
changeset
|
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
8e5f8d682700
10l: Revert license header cleanup on imported files.
diego
parents:
26742
diff
changeset
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8e5f8d682700
10l: Revert license header cleanup on imported files.
diego
parents:
26742
diff
changeset
|
17 * GNU General Public License for more details. |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
18 * |
26744
8e5f8d682700
10l: Revert license header cleanup on imported files.
diego
parents:
26742
diff
changeset
|
19 * You should have received a copy of the GNU General Public License |
8e5f8d682700
10l: Revert license header cleanup on imported files.
diego
parents:
26742
diff
changeset
|
20 * along with this program; if not, write to the Free Software |
8e5f8d682700
10l: Revert license header cleanup on imported files.
diego
parents:
26742
diff
changeset
|
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
8e5f8d682700
10l: Revert license header cleanup on imported files.
diego
parents:
26742
diff
changeset
|
22 * |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
23 */ |
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 "config.h" |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
26 |
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 <stdio.h> |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
29 #include <stdlib.h> |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
30 #include <string.h> |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
31 #include "yuv4mpeg.h" |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
32 #include "yuv4mpeg_intern.h" |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
33 #include "mp_msg.h" |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
34 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
35 static int _y4mparam_allow_unknown_tags = 1; /* default is forgiveness */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
36 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
37 static void *(*_y4m_alloc)(size_t bytes) = malloc; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
38 static void (*_y4m_free)(void *ptr) = free; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
39 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
40 int y4m_allow_unknown_tags(int yn) { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
41 int old = _y4mparam_allow_unknown_tags; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
42 if (yn >= 0) _y4mparam_allow_unknown_tags = (yn) ? 1 : 0; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
43 return old; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
44 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
45 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
46 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
47 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
48 /************************************************************************* |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
49 * |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
50 * Convenience functions for fd read/write |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
51 * |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
52 * - guaranteed to transfer entire payload (or fail) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
53 * - returns: |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
54 * 0 on complete success |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
55 * +(# of remaining bytes) on eof (for y4m_read) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
56 * -(# of rem. bytes) on error (and ERRNO should be set) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26745
diff
changeset
|
57 * |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
58 *************************************************************************/ |
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 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
61 ssize_t y4m_read(stream_t *s, char *buf, size_t len) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
62 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
63 ssize_t n; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
64 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
65 while (len > 0) { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
66 n = stream_read(s, buf, len); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
67 if (n <= 0) { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
68 /* return amount left to read */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
69 if (n == 0) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
70 return len; /* n == 0 --> eof */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
71 else |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
72 return -len; /* n < 0 --> error */ |
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 buf += n; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
75 len -= n; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
76 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
77 return 0; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
78 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
79 |
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 #if 0 /* not needed */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
82 ssize_t y4m_write(int fd, char *buf, size_t len) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
83 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
84 ssize_t n; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
85 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
86 while (len > 0) { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
87 n = write(fd, buf, len); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
88 if (n < 0) return -len; /* return amount left to write */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
89 buf += n; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
90 len -= n; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
91 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
92 return 0; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
93 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
94 #endif |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
95 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
96 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
97 /************************************************************************* |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
98 * |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
99 * "Extra tags" handling |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
100 * |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
101 *************************************************************************/ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
102 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
103 |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
14429
diff
changeset
|
104 static char *y4m_new_xtag(void) |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
105 { |
18366 | 106 return _y4m_alloc(Y4M_MAX_XTAG_SIZE); |
3786
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 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
109 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
110 void y4m_init_xtag_list(y4m_xtag_list_t *xtags) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
111 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
112 int i; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
113 xtags->count = 0; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
114 for (i = 0; i < Y4M_MAX_XTAGS; i++) { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
115 xtags->tags[i] = NULL; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
116 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
117 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
118 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
119 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
120 void y4m_fini_xtag_list(y4m_xtag_list_t *xtags) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
121 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
122 int i; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
123 for (i = 0; i < Y4M_MAX_XTAGS; i++) { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
124 if (xtags->tags[i] != NULL) { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
125 _y4m_free(xtags->tags[i]); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
126 xtags->tags[i] = NULL; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
127 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
128 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
129 xtags->count = 0; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
130 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
131 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
132 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
133 void y4m_copy_xtag_list(y4m_xtag_list_t *dest, const y4m_xtag_list_t *src) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
134 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
135 int i; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
136 for (i = 0; i < src->count; i++) { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26745
diff
changeset
|
137 if (dest->tags[i] == NULL) |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
138 dest->tags[i] = y4m_new_xtag(); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
139 strncpy(dest->tags[i], src->tags[i], Y4M_MAX_XTAG_SIZE); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
140 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
141 dest->count = src->count; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
142 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
143 |
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 |
24859
f9495196e2d8
Disable function that is only used in disabled code, fixes warning:
diego
parents:
19614
diff
changeset
|
146 #if 0 |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
147 static int y4m_snprint_xtags(char *s, int maxn, y4m_xtag_list_t *xtags) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
148 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
149 int i, room; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26745
diff
changeset
|
150 |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
151 for (i = 0, room = maxn - 1; i < xtags->count; i++) { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
152 int n = snprintf(s, room + 1, " %s", xtags->tags[i]); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
153 if ((n < 0) || (n > room)) return Y4M_ERR_HEADER; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
154 s += n; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
155 room -= n; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
156 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
157 s[0] = '\n'; /* finish off header with newline */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
158 s[1] = '\0'; /* ...and end-of-string */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
159 return Y4M_OK; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
160 } |
24859
f9495196e2d8
Disable function that is only used in disabled code, fixes warning:
diego
parents:
19614
diff
changeset
|
161 #endif |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
162 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
163 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
164 int y4m_xtag_count(const y4m_xtag_list_t *xtags) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
165 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
166 return xtags->count; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
167 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
168 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
169 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
170 const char *y4m_xtag_get(const y4m_xtag_list_t *xtags, int n) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
171 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
172 if (n >= xtags->count) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
173 return NULL; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
174 else |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
175 return xtags->tags[n]; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
176 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
177 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
178 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
179 int y4m_xtag_add(y4m_xtag_list_t *xtags, const char *tag) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
180 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
181 if (xtags->count >= Y4M_MAX_XTAGS) return Y4M_ERR_XXTAGS; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
182 if (xtags->tags[xtags->count] == NULL) { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
183 xtags->tags[xtags->count] = y4m_new_xtag(); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
184 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
185 strncpy(xtags->tags[xtags->count], tag, Y4M_MAX_XTAG_SIZE); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
186 (xtags->count)++; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
187 return Y4M_OK; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
188 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
189 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
190 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
191 int y4m_xtag_remove(y4m_xtag_list_t *xtags, int n) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
192 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
193 int i; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
194 char *q; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
195 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
196 if ((n < 0) || (n >= xtags->count)) return Y4M_ERR_RANGE; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
197 q = xtags->tags[n]; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
198 for (i = n; i < (xtags->count - 1); i++) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
199 xtags->tags[i] = xtags->tags[i+1]; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
200 xtags->tags[i] = q; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
201 (xtags->count)--; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
202 return Y4M_OK; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
203 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
204 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
205 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
206 int y4m_xtag_clearlist(y4m_xtag_list_t *xtags) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
207 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
208 xtags->count = 0; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
209 return Y4M_OK; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
210 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
211 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
212 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
213 int y4m_xtag_addlist(y4m_xtag_list_t *dest, const y4m_xtag_list_t *src) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
214 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
215 int i, j; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
216 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
217 if ((dest->count + src->count) > Y4M_MAX_XTAGS) return Y4M_ERR_XXTAGS; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
218 for (i = dest->count, j = 0; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
219 j < src->count; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
220 i++, j++) { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26745
diff
changeset
|
221 if (dest->tags[i] == NULL) |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
222 dest->tags[i] = y4m_new_xtag(); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
223 strncpy(dest->tags[i], src->tags[i], Y4M_MAX_XTAG_SIZE); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
224 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
225 dest->count += src->count; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
226 return Y4M_OK; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26745
diff
changeset
|
227 } |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
228 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
229 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
230 /************************************************************************* |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
231 * |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
232 * Creators/destructors for y4m_*_info_t structures |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
233 * |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
234 *************************************************************************/ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
235 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
236 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
237 void y4m_init_stream_info(y4m_stream_info_t *info) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
238 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
239 if (info == NULL) return; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
240 /* initialize info */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
241 info->width = Y4M_UNKNOWN; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
242 info->height = Y4M_UNKNOWN; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
243 info->interlace = Y4M_UNKNOWN; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
244 info->framerate = y4m_fps_UNKNOWN; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
245 info->sampleaspect = y4m_sar_UNKNOWN; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
246 y4m_init_xtag_list(&(info->x_tags)); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
247 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
248 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
249 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
250 void y4m_copy_stream_info(y4m_stream_info_t *dest, y4m_stream_info_t *src) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
251 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
252 if ((dest == NULL) || (src == NULL)) return; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
253 /* copy info */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
254 dest->width = src->width; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
255 dest->height = src->height; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
256 dest->interlace = src->interlace; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
257 dest->framerate = src->framerate; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
258 dest->sampleaspect = src->sampleaspect; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
259 y4m_copy_xtag_list(&(dest->x_tags), &(src->x_tags)); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
260 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
261 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
262 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
263 void y4m_fini_stream_info(y4m_stream_info_t *info) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
264 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
265 if (info == NULL) return; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
266 y4m_fini_xtag_list(&(info->x_tags)); |
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 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
269 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
270 void y4m_si_set_width(y4m_stream_info_t *si, int width) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
271 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
272 si->width = width; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
273 si->framelength = (si->height * si->width) * 3 / 2; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
274 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
275 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
276 int y4m_si_get_width(y4m_stream_info_t *si) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
277 { return si->width; } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
278 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
279 void y4m_si_set_height(y4m_stream_info_t *si, int height) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
280 { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26745
diff
changeset
|
281 si->height = height; |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
282 si->framelength = (si->height * si->width) * 3 / 2; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
283 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
284 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
285 int y4m_si_get_height(y4m_stream_info_t *si) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
286 { return si->height; } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
287 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
288 void y4m_si_set_interlace(y4m_stream_info_t *si, int interlace) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
289 { si->interlace = interlace; } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
290 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
291 int y4m_si_get_interlace(y4m_stream_info_t *si) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
292 { return si->interlace; } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
293 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
294 void y4m_si_set_framerate(y4m_stream_info_t *si, y4m_ratio_t framerate) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
295 { si->framerate = framerate; } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
296 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
297 y4m_ratio_t y4m_si_get_framerate(y4m_stream_info_t *si) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
298 { return si->framerate; } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
299 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
300 void y4m_si_set_sampleaspect(y4m_stream_info_t *si, y4m_ratio_t sar) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
301 { si->sampleaspect = sar; } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
302 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
303 y4m_ratio_t y4m_si_get_sampleaspect(y4m_stream_info_t *si) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
304 { return si->sampleaspect; } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
305 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
306 int y4m_si_get_framelength(y4m_stream_info_t *si) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
307 { return si->framelength; } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
308 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
309 y4m_xtag_list_t *y4m_si_xtags(y4m_stream_info_t *si) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
310 { return &(si->x_tags); } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
311 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
312 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
313 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
314 void y4m_init_frame_info(y4m_frame_info_t *info) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
315 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
316 if (info == NULL) return; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
317 /* initialize info */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
318 y4m_init_xtag_list(&(info->x_tags)); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
319 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
320 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
321 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
322 void y4m_copy_frame_info(y4m_frame_info_t *dest, y4m_frame_info_t *src) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
323 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
324 if ((dest == NULL) || (src == NULL)) return; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
325 /* copy info */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
326 y4m_copy_xtag_list(&(dest->x_tags), &(src->x_tags)); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
327 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
328 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
329 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
330 void y4m_fini_frame_info(y4m_frame_info_t *info) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
331 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
332 if (info == NULL) return; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
333 y4m_fini_xtag_list(&(info->x_tags)); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
334 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
335 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
336 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
337 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
338 /************************************************************************* |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
339 * |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26745
diff
changeset
|
340 * Tag parsing |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
341 * |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
342 *************************************************************************/ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
343 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
344 int y4m_parse_stream_tags(char *s, y4m_stream_info_t *i) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
345 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
346 char *token, *value; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
347 char tag; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
348 int err; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
349 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
350 /* parse fields */ |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26745
diff
changeset
|
351 for (token = strtok(s, Y4M_DELIM); |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26745
diff
changeset
|
352 token != NULL; |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
353 token = strtok(NULL, Y4M_DELIM)) { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
354 if (token[0] == '\0') continue; /* skip empty strings */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
355 tag = token[0]; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
356 value = token + 1; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
357 switch (tag) { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
358 case 'W': /* width */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
359 i->width = atoi(value); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
360 if (i->width <= 0) return Y4M_ERR_RANGE; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
361 break; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
362 case 'H': /* height */ |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26745
diff
changeset
|
363 i->height = atoi(value); |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
364 if (i->height <= 0) return Y4M_ERR_RANGE; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
365 break; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
366 case 'F': /* frame rate (fps) */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
367 if ((err = y4m_parse_ratio(&(i->framerate), value)) != Y4M_OK) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
368 return err; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
369 if (i->framerate.n < 0) return Y4M_ERR_RANGE; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
370 break; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
371 case 'I': /* interlacing */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
372 switch (value[0]) { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
373 case 'p': i->interlace = Y4M_ILACE_NONE; break; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
374 case 't': i->interlace = Y4M_ILACE_TOP_FIRST; break; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
375 case 'b': i->interlace = Y4M_ILACE_BOTTOM_FIRST; break; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
376 case '?': |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
377 default: |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
378 i->interlace = Y4M_UNKNOWN; break; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
379 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
380 break; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
381 case 'A': /* sample (pixel) aspect ratio */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
382 if ((err = y4m_parse_ratio(&(i->sampleaspect), value)) != Y4M_OK) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
383 return err; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
384 if (i->sampleaspect.n < 0) return Y4M_ERR_RANGE; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
385 break; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
386 case 'X': /* 'X' meta-tag */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
387 if ((err = y4m_xtag_add(&(i->x_tags), token)) != Y4M_OK) return err; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
388 break; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
389 default: |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
390 /* possible error on unknown options */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
391 if (_y4mparam_allow_unknown_tags) { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
392 /* unknown tags ok: store in xtag list and warn... */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
393 if ((err = y4m_xtag_add(&(i->x_tags), token)) != Y4M_OK) return err; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
394 mp_msg(MSGT_DEMUX, MSGL_WARN, "Unknown stream tag encountered: '%s'\n", token); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
395 } else { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
396 /* unknown tags are *not* ok */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
397 return Y4M_ERR_BADTAG; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
398 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
399 break; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
400 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
401 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
402 /* Error checking... width and height must be known since we can't |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
403 * parse without them |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
404 */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
405 if( i->width == Y4M_UNKNOWN || i->height == Y4M_UNKNOWN ) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
406 return Y4M_ERR_HEADER; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
407 /* ta da! done. */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
408 return Y4M_OK; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
409 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
410 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
411 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
412 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
413 static int y4m_parse_frame_tags(char *s, y4m_frame_info_t *i) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
414 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
415 char *token, *value; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
416 char tag; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
417 int err; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
418 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
419 /* parse fields */ |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26745
diff
changeset
|
420 for (token = strtok(s, Y4M_DELIM); |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26745
diff
changeset
|
421 token != NULL; |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
422 token = strtok(NULL, Y4M_DELIM)) { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
423 if (token[0] == '\0') continue; /* skip empty strings */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
424 tag = token[0]; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
425 value = token + 1; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
426 switch (tag) { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
427 case 'X': /* 'X' meta-tag */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
428 if ((err = y4m_xtag_add(&(i->x_tags), token)) != Y4M_OK) return err; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
429 break; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
430 default: |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
431 /* possible error on unknown options */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
432 if (_y4mparam_allow_unknown_tags) { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
433 /* unknown tags ok: store in xtag list and warn... */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
434 if ((err = y4m_xtag_add(&(i->x_tags), token)) != Y4M_OK) return err; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
435 mp_msg(MSGT_DEMUX, MSGL_WARN, "Unknown frame tag encountered: '%s'\n", token); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
436 } else { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
437 /* unknown tags are *not* ok */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
438 return Y4M_ERR_BADTAG; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
439 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
440 break; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
441 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
442 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
443 /* ta da! done. */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
444 return Y4M_OK; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
445 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
446 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
447 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
448 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
449 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
450 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
451 /************************************************************************* |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
452 * |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
453 * Read/Write stream header |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
454 * |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
455 *************************************************************************/ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
456 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
457 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
458 int y4m_read_stream_header(stream_t *s, y4m_stream_info_t *i) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
459 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
460 char line[Y4M_LINE_MAX]; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
461 char *p; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
462 int n; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
463 int err; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
464 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
465 /* read the header line */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
466 for (n = 0, p = line; n < Y4M_LINE_MAX; n++, p++) { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26745
diff
changeset
|
467 if (y4m_read(s, p, 1)) |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
468 return Y4M_ERR_SYSTEM; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
469 if (*p == '\n') { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
470 *p = '\0'; /* Replace linefeed by end of string */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
471 break; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
472 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
473 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
474 if (n >= Y4M_LINE_MAX) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
475 return Y4M_ERR_HEADER; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
476 /* look for keyword in header */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
477 if (strncmp(line, Y4M_MAGIC, strlen(Y4M_MAGIC))) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
478 return Y4M_ERR_MAGIC; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
479 if ((err = y4m_parse_stream_tags(line + strlen(Y4M_MAGIC), i)) != Y4M_OK) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
480 return err; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
481 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
482 i->framelength = (i->height * i->width) * 3 / 2; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
483 return Y4M_OK; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
484 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
485 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
486 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
487 #if 0 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
488 int y4m_write_stream_header(int fd, y4m_stream_info_t *i) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
489 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
490 char s[Y4M_LINE_MAX+1]; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
491 int n; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
492 int err; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
493 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
494 y4m_ratio_reduce(&(i->framerate)); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
495 y4m_ratio_reduce(&(i->sampleaspect)); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
496 n = snprintf(s, sizeof(s), "%s W%d H%d F%d:%d I%s A%d:%d", |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
497 Y4M_MAGIC, |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
498 i->width, |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
499 i->height, |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
500 i->framerate.n, i->framerate.d, |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
501 (i->interlace == Y4M_ILACE_NONE) ? "p" : |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
502 (i->interlace == Y4M_ILACE_TOP_FIRST) ? "t" : |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
503 (i->interlace == Y4M_ILACE_BOTTOM_FIRST) ? "b" : "?", |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
504 i->sampleaspect.n, i->sampleaspect.d); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
505 if ((n < 0) || (n > Y4M_LINE_MAX)) return Y4M_ERR_HEADER; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26745
diff
changeset
|
506 if ((err = y4m_snprint_xtags(s + n, sizeof(s) - n - 1, &(i->x_tags))) |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26745
diff
changeset
|
507 != Y4M_OK) |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
508 return err; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
509 /* non-zero on error */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
510 return (y4m_write(fd, s, strlen(s)) ? Y4M_ERR_SYSTEM : Y4M_OK); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
511 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
512 #endif |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
513 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
514 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
515 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
516 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
517 /************************************************************************* |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
518 * |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
519 * Read/Write frame header |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
520 * |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
521 *************************************************************************/ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
522 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
523 int y4m_read_frame_header(stream_t *s, y4m_frame_info_t *i) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
524 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
525 char line[Y4M_LINE_MAX]; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
526 char *p; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
527 int n; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
528 ssize_t remain; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26745
diff
changeset
|
529 |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
530 /* This is more clever than read_stream_header... |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
531 Try to read "FRAME\n" all at once, and don't try to parse |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
532 if nothing else is there... |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
533 */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
534 remain = y4m_read(s, line, sizeof(Y4M_FRAME_MAGIC)); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
535 if (remain != 0) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
536 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
537 /* A clean EOF should end exactly at a frame-boundary */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
538 if( remain == sizeof(Y4M_FRAME_MAGIC) ) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
539 return Y4M_ERR_EOF; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
540 else |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
541 return Y4M_ERR_SYSTEM; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
542 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
543 if (strncmp(line, Y4M_FRAME_MAGIC, sizeof(Y4M_FRAME_MAGIC)-1)) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
544 return Y4M_ERR_MAGIC; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
545 if (line[sizeof(Y4M_FRAME_MAGIC)-1] == '\n') |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
546 return Y4M_OK; /* done -- no tags: that was the end-of-line. */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
547 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
548 if (line[sizeof(Y4M_FRAME_MAGIC)-1] != Y4M_DELIM[0]) { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
549 return Y4M_ERR_MAGIC; /* wasn't a space -- what was it? */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
550 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
551 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
552 /* proceed to get the tags... (overwrite the magic) */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
553 for (n = 0, p = line; n < Y4M_LINE_MAX; n++, p++) { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
554 if (y4m_read(s, p, 1)) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
555 return Y4M_ERR_SYSTEM; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
556 if (*p == '\n') { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
557 *p = '\0'; /* Replace linefeed by end of string */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
558 break; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
559 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
560 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
561 if (n >= Y4M_LINE_MAX) return Y4M_ERR_HEADER; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
562 /* non-zero on error */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
563 return y4m_parse_frame_tags(line, i); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
564 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
565 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
566 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
567 #if 0 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
568 int y4m_write_frame_header(int fd, y4m_frame_info_t *i) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
569 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
570 char s[Y4M_LINE_MAX+1]; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
571 int n; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
572 int err; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26745
diff
changeset
|
573 |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
574 n = snprintf(s, sizeof(s), "%s", Y4M_FRAME_MAGIC); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
575 if ((n < 0) || (n > Y4M_LINE_MAX)) return Y4M_ERR_HEADER; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26745
diff
changeset
|
576 if ((err = y4m_snprint_xtags(s + n, sizeof(s) - n - 1, &(i->x_tags))) |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26745
diff
changeset
|
577 != Y4M_OK) |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
578 return err; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
579 /* non-zero on error */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
580 return (y4m_write(fd, s, strlen(s)) ? Y4M_ERR_SYSTEM : Y4M_OK); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
581 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
582 #endif |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
583 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
584 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
585 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
586 /************************************************************************* |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
587 * |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
588 * Read/Write entire frame |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
589 * |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
590 *************************************************************************/ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
591 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26745
diff
changeset
|
592 int y4m_read_frame(stream_t *s, y4m_stream_info_t *si, |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
593 y4m_frame_info_t *fi, unsigned char *yuv[3]) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
594 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
595 int err; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
596 int w = si->width; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
597 int h = si->height; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26745
diff
changeset
|
598 |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
599 /* Read frame header */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
600 if ((err = y4m_read_frame_header(s, fi)) != Y4M_OK) return err; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
601 /* Read luminance scanlines */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
602 if (y4m_read(s, yuv[0], w*h)) return Y4M_ERR_SYSTEM; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
603 /* Read chrominance scanlines */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
604 if (y4m_read(s, yuv[1], w*h/4)) return Y4M_ERR_SYSTEM; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
605 if (y4m_read(s, yuv[2], w*h/4)) return Y4M_ERR_SYSTEM; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
606 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
607 return Y4M_OK; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
608 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
609 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
610 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
611 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
612 #if 0 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26745
diff
changeset
|
613 int y4m_write_frame(int fd, y4m_stream_info_t *si, |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
614 y4m_frame_info_t *fi, unsigned char *yuv[3]) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
615 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
616 int err; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
617 int w = si->width; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
618 int h = si->height; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
619 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
620 /* Write frame header */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
621 if ((err = y4m_write_frame_header(fd, fi)) != Y4M_OK) return err; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
622 /* Write luminance,chrominance scanlines */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
623 if (y4m_write(fd, yuv[0], w*h) || |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
624 y4m_write(fd, yuv[1], w*h/4) || |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
625 y4m_write(fd, yuv[2], w*h/4)) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
626 return Y4M_ERR_SYSTEM; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
627 return Y4M_OK; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
628 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
629 #endif |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
630 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
631 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
632 /************************************************************************* |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
633 * |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
634 * Read/Write entire frame, (de)interleaved (to)from two separate fields |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
635 * |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
636 *************************************************************************/ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
637 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
638 #if 0 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
639 int y4m_read_fields(int fd, y4m_stream_info_t *si, y4m_frame_info_t *fi, |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26745
diff
changeset
|
640 unsigned char *upper_field[3], |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
641 unsigned char *lower_field[3]) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
642 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
643 int i, y, err; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
644 int width = si->width; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
645 int height = si->height; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26745
diff
changeset
|
646 |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
647 /* Read frame header */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
648 if ((err = y4m_read_frame_header(fd, fi)) != Y4M_OK) return err; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
649 /* Read Y', Cb, and Cr planes */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
650 for (i = 0; i < 3; i++) { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
651 unsigned char *srctop = upper_field[i]; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
652 unsigned char *srcbot = lower_field[i]; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
653 /* alternately write one line from each */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
654 for (y = 0; y < height; y += 2) { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
655 if (y4m_read(fd, srctop, width)) return Y4M_ERR_SYSTEM; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
656 srctop += width; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
657 if (y4m_read(fd, srcbot, width)) return Y4M_ERR_SYSTEM; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
658 srcbot += width; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
659 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
660 /* for chroma, width/height are half as big */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
661 if (i == 0) { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
662 width /= 2; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
663 height /= 2; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
664 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
665 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
666 return Y4M_OK; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
667 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
668 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
669 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
670 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
671 int y4m_write_fields(int fd, y4m_stream_info_t *si, y4m_frame_info_t *fi, |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26745
diff
changeset
|
672 unsigned char *upper_field[3], |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
673 unsigned char *lower_field[3]) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
674 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
675 int i, y, err; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
676 int width = si->width; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
677 int height = si->height; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
678 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
679 /* Write frame header */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
680 if ((err = y4m_write_frame_header(fd, fi)) != Y4M_OK) return err; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
681 /* Write Y', Cb, and Cr planes */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
682 for (i = 0; i < 3; i++) { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
683 unsigned char *srctop = upper_field[i]; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
684 unsigned char *srcbot = lower_field[i]; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
685 /* alternately write one line from each */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
686 for (y = 0; y < height; y += 2) { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
687 if (y4m_write(fd, srctop, width)) return Y4M_ERR_SYSTEM; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
688 srctop += width; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
689 if (y4m_write(fd, srcbot, width)) return Y4M_ERR_SYSTEM; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
690 srcbot += width; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
691 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
692 /* for chroma, width/height are half as big */ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
693 if (i == 0) { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
694 width /= 2; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
695 height /= 2; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
696 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
697 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
698 return Y4M_OK; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
699 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
700 #endif |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
701 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
702 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
703 /************************************************************************* |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
704 * |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
705 * Handy logging of stream info |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
706 * |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
707 *************************************************************************/ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
708 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
709 void y4m_log_stream_info(const char *prefix, y4m_stream_info_t *i) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
710 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
711 char s[256]; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
712 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
713 snprintf(s, sizeof(s), " frame size: "); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
714 if (i->width == Y4M_UNKNOWN) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
715 snprintf(s+strlen(s), sizeof(s)-strlen(s), "(?)x"); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
716 else |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
717 snprintf(s+strlen(s), sizeof(s)-strlen(s), "%dx", i->width); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
718 if (i->height == Y4M_UNKNOWN) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
719 snprintf(s+strlen(s), sizeof(s)-strlen(s), "(?) pixels "); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
720 else |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
721 snprintf(s+strlen(s), sizeof(s)-strlen(s), "%d pixels ", i->height); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
722 if (i->framelength == Y4M_UNKNOWN) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
723 snprintf(s+strlen(s), sizeof(s)-strlen(s), "(? bytes)"); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
724 else |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
725 snprintf(s+strlen(s), sizeof(s)-strlen(s), "(%d bytes)", i->framelength); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
726 mp_msg(MSGT_DEMUX, MSGL_V, "%s%s\n", prefix, s); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
727 if ((i->framerate.n == 0) && (i->framerate.d == 0)) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
728 mp_msg(MSGT_DEMUX, MSGL_V, "%s frame rate: ??? fps\n", prefix); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
729 else |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
730 mp_msg(MSGT_DEMUX, MSGL_V, "%s frame rate: %d/%d fps (~%f)\n", prefix, |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26745
diff
changeset
|
731 i->framerate.n, i->framerate.d, |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
732 (double) i->framerate.n / (double) i->framerate.d); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
733 mp_msg(MSGT_DEMUX, MSGL_V, "%s interlace: %s\n", prefix, |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
734 (i->interlace == Y4M_ILACE_NONE) ? "none/progressive" : |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
735 (i->interlace == Y4M_ILACE_TOP_FIRST) ? "top-field-first" : |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
736 (i->interlace == Y4M_ILACE_BOTTOM_FIRST) ? "bottom-field-first" : |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
737 "anyone's guess"); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
738 if ((i->sampleaspect.n == 0) && (i->sampleaspect.d == 0)) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
739 mp_msg(MSGT_DEMUX, MSGL_V, "%ssample aspect ratio: ?:?\n", prefix); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
740 else |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
741 mp_msg(MSGT_DEMUX, MSGL_V, "%ssample aspect ratio: %d:%d\n", prefix, |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
742 i->sampleaspect.n, i->sampleaspect.d); |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
743 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
744 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
745 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
746 /************************************************************************* |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
747 * |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
748 * Convert error code to string |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
749 * |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
750 *************************************************************************/ |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
751 |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
752 const char *y4m_strerr(int err) |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
753 { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
754 switch (err) { |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
755 case Y4M_OK: return "no error"; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
756 case Y4M_ERR_RANGE: return "parameter out of range"; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
757 case Y4M_ERR_SYSTEM: return "stream ended unexpectedly (failed read/write)"; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
758 case Y4M_ERR_HEADER: return "bad stream or frame header"; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
759 case Y4M_ERR_BADTAG: return "unknown header tag"; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
760 case Y4M_ERR_MAGIC: return "bad header magic"; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
761 case Y4M_ERR_XXTAGS: return "too many xtags"; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
762 case Y4M_ERR_EOF: return "end-of-file"; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26745
diff
changeset
|
763 default: |
3786
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
764 return "unknown error code"; |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
765 } |
7ebf504c92d6
yuv4mpeg2 (mjpegtools) support by Rik Snel <rsnel@cube.dyndns.org>
arpi
parents:
diff
changeset
|
766 } |