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 {
35 char buf[36];
36 int datatype, filetype, t1, t2, nb_comments;
38
39 if (start_pos < 128)
41
42 start_pos -= 128;
43
46 return -1;
47 if (memcmp(buf, "SAUCE00", 7))
48 return -1;
49
50 #define GET_SAUCE_META(name,size) \
51 if (avio_read(pb, buf, size) == size && buf[0]) { \
52 buf[size] = 0; \
53 av_dict_set(&avctx->metadata, name, buf, 0); \
54 }
55
69
70 if (got_width && datatype && filetype) {
71 if ((datatype == 1 && filetype <=2) || (datatype == 5 && filetype == 255) || datatype == 6) {
72 if (t1) {
74 *got_width = 1;
75 }
78 } else if (datatype == 5) {
79 if (filetype) {
81 *got_width = 1;
82 }
85 }
86 }
87
89
90 if (nb_comments > 0) {
91 avio_seek(pb, start_pos - 64*nb_comments - 5, SEEK_SET);
92 if (
avio_read(pb, buf, 5) == 5 && !memcmp(buf,
"COMNT", 5)) {
94 char *str =
av_malloc(65*nb_comments + 1);
95 *
fsize -= 64*nb_comments + 5;
96 if (!str)
97 return 0;
98 for (
i = 0;
i < nb_comments;
i++) {
100 break;
101 str[65*
i + 64] =
'\n';
102 }
105 }
106 }
107
108 return 0;
109 }