Mercurial > libavformat.hg
comparison sauce.c @ 6270:b6f0ef0c9d3a libavformat
Add ff_sauce_read()
author | pross |
---|---|
date | Sun, 18 Jul 2010 08:05:04 +0000 |
parents | |
children | 5f0bde61870e |
comparison
equal
deleted
inserted
replaced
6269:b5afd13d8352 | 6270:b6f0ef0c9d3a |
---|---|
1 /* | |
2 * @file | |
3 * SAUCE header parser | |
4 * Copyright (c) 2010 Peter Ross <pross@xvid.org> | |
5 * | |
6 * This file is part of FFmpeg. | |
7 * | |
8 * FFmpeg is free software; you can redistribute it and/or | |
9 * modify it under the terms of the GNU Lesser General Public | |
10 * License as published by the Free Software Foundation; either | |
11 * version 2.1 of the License, or (at your option) any later version. | |
12 * | |
13 * FFmpeg is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * Lesser General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU Lesser General Public | |
19 * License along with FFmpeg; if not, write to the Free Software | |
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
21 */ | |
22 | |
23 #include "libavutil/intreadwrite.h" | |
24 #include "avformat.h" | |
25 #include "sauce.h" | |
26 | |
27 int ff_sauce_read(AVFormatContext *avctx, uint64_t *fsize, int *got_width, int get_height) | |
28 { | |
29 ByteIOContext *pb = avctx->pb; | |
30 char buf[36]; | |
31 int datatype, filetype, t1, t2, nb_comments, flags; | |
32 uint64_t start_pos = url_fsize(pb) - 128; | |
33 | |
34 url_fseek(pb, start_pos, SEEK_SET); | |
35 if (get_buffer(pb, buf, 7) != 7) | |
36 return -1; | |
37 if (memcmp(buf, "SAUCE00", 7)) | |
38 return -1; | |
39 | |
40 #define GET_SAUCE_META(name,size) \ | |
41 if (get_buffer(pb, buf, size) == size && buf[0]) { \ | |
42 buf[size] = 0; \ | |
43 av_metadata_set2(&avctx->metadata, name, buf, 0); \ | |
44 } | |
45 | |
46 GET_SAUCE_META("title", 35) | |
47 GET_SAUCE_META("artist", 20) | |
48 GET_SAUCE_META("publisher", 20) | |
49 GET_SAUCE_META("date", 8) | |
50 url_fskip(pb, 4); | |
51 datatype = get_byte(pb); | |
52 filetype = get_byte(pb); | |
53 t1 = get_le16(pb); | |
54 t2 = get_le16(pb); | |
55 nb_comments = get_byte(pb); | |
56 flags = get_byte(pb); | |
57 url_fskip(pb, 4); | |
58 GET_SAUCE_META("encoder", 22); | |
59 | |
60 if (got_width && datatype && filetype) { | |
61 if ((datatype == 1 && filetype <=2) || (datatype == 5 && filetype == 255) || datatype == 6) { | |
62 if (t1) { | |
63 avctx->streams[0]->codec->width = t1<<3; | |
64 *got_width = 1; | |
65 } | |
66 if (get_height && t2) | |
67 avctx->streams[0]->codec->height = t2<<4; | |
68 } else if (datatype == 5) { | |
69 if (filetype > 1) { | |
70 avctx->streams[0]->codec->width = (filetype == 1 ? t1 : filetype) << 4; | |
71 *got_width = 1; | |
72 } | |
73 if (get_height && t2) | |
74 avctx->streams[0]->codec->height = t2<<4; | |
75 } | |
76 } | |
77 | |
78 *fsize -= 128; | |
79 | |
80 if (nb_comments > 0) { | |
81 url_fseek(pb, start_pos - 64*nb_comments - 5, SEEK_SET); | |
82 if (get_buffer(pb, buf, 5) == 5 && !memcmp(buf, "COMNT", 5)) { | |
83 int i; | |
84 char *str = av_malloc(65*nb_comments + 1); | |
85 *fsize -= 64*nb_comments + 5; | |
86 if (!str) | |
87 return 0; | |
88 for (i = 0; i < nb_comments; i++) { | |
89 if (get_buffer(pb, str + 65*i, 64) != 64) | |
90 break; | |
91 str[65*i + 64] = '\n'; | |
92 } | |
93 str[65*i] = 0; | |
94 av_metadata_set2(&avctx->metadata, "comment", str, AV_METADATA_DONT_STRDUP_VAL); | |
95 } | |
96 } | |
97 | |
98 return 0; | |
99 } |