1 /*
2 * SAUCE header parser
3 * Copyright (c) 2010 Peter Ross <pross@xvid.org>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * SAUCE header parser
25 */
26
31
33 {
36 int datatype, filetype,
t1,
t2, nb_comments;
38
41 return -1;
42 if (memcmp(buf, "SAUCE00", 7))
43 return -1;
44
45 #define GET_SAUCE_META(name,size) \
46 if (avio_read(pb, buf, size) == size && buf[0]) { \
47 buf[size] = 0; \
48 av_dict_set(&avctx->metadata, name, buf, 0); \
49 }
50
64
65 if (got_width && datatype && filetype) {
66 if ((datatype == 1 && filetype <=2) || (datatype == 5 && filetype == 255) || datatype == 6) {
67 if (t1) {
69 *got_width = 1;
70 }
71 if (get_height && t2)
73 } else if (datatype == 5) {
74 if (filetype) {
76 *got_width = 1;
77 }
78 if (get_height && t2)
80 }
81 }
82
83 *fsize -= 128;
84
85 if (nb_comments > 0) {
86 avio_seek(pb, start_pos - 64*nb_comments - 5, SEEK_SET);
87 if (
avio_read(pb, buf, 5) == 5 && !memcmp(buf,
"COMNT", 5)) {
88 int i;
89 char *str =
av_malloc(65*nb_comments + 1);
90 *fsize -= 64*nb_comments + 5;
91 if (!str)
92 return 0;
93 for (i = 0; i < nb_comments; i++) {
95 break;
96 str[65*i + 64] = '\n';
97 }
98 str[65*i] = 0;
100 }
101 }
102
103 return 0;
104 }