aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-12-18 21:52:30 +0000
committerChristian Grothoff <christian@grothoff.org>2009-12-18 21:52:30 +0000
commit8bb11f7c6a642203663e97b659371fcaaa3e7182 (patch)
treecbf13b4bec4d04b662ff183e264d686cb1ea4da4
parentf9c4fb9fd41ba11a258a6193b9529fc2ef6a2f13 (diff)
downloadlibextractor-8bb11f7c6a642203663e97b659371fcaaa3e7182.tar.gz
libextractor-8bb11f7c6a642203663e97b659371fcaaa3e7182.zip
riff
-rw-r--r--src/plugins/Makefile.am19
-rw-r--r--src/plugins/riff_extractor.c (renamed from src/plugins/riffextractor.c)99
2 files changed, 41 insertions, 77 deletions
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index 156a1b5..252a73d 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -91,6 +91,7 @@ plugin_LTLIBRARIES = \
91 libextractor_ps.la \ 91 libextractor_ps.la \
92 libextractor_qt.la \ 92 libextractor_qt.la \
93 libextractor_real.la \ 93 libextractor_real.la \
94 libextractor_riff.la \
94 $(rpm) \ 95 $(rpm) \
95 libextractor_tar.la \ 96 libextractor_tar.la \
96 $(thumbgtk) \ 97 $(thumbgtk) \
@@ -263,6 +264,14 @@ libextractor_real_la_SOURCES = \
263libextractor_real_la_LDFLAGS = \ 264libextractor_real_la_LDFLAGS = \
264 $(PLUGINFLAGS) 265 $(PLUGINFLAGS)
265 266
267libextractor_riff_la_SOURCES = \
268 riff_extractor.c
269libextractor_riff_la_LDFLAGS = \
270 $(PLUGINFLAGS)
271libextractor_riff_la_LIBADD = \
272 $(LE_LIBINTL) \
273 -lm
274
266libextractor_rpm_la_SOURCES = \ 275libextractor_rpm_la_SOURCES = \
267 rpm_extractor.c 276 rpm_extractor.c
268libextractor_rpm_la_LDFLAGS = \ 277libextractor_rpm_la_LDFLAGS = \
@@ -319,7 +328,6 @@ OLD_LIBS = \
319 $(extrampeg) \ 328 $(extrampeg) \
320 libextractor_nsf.la \ 329 libextractor_nsf.la \
321 libextractor_nsfe.la \ 330 libextractor_nsfe.la \
322 libextractor_riff.la \
323 libextractor_s3m.la \ 331 libextractor_s3m.la \
324 libextractor_sid.la \ 332 libextractor_sid.la \
325 libextractor_tar.la \ 333 libextractor_tar.la \
@@ -350,15 +358,6 @@ libextractor_id3v24_la_LIBADD = \
350 $(top_builddir)/src/common/libextractor_common.la 358 $(top_builddir)/src/common/libextractor_common.la
351 359
352 360
353libextractor_riff_la_SOURCES = \
354 riffextractor.c
355libextractor_riff_la_LDFLAGS = \
356 $(PLUGINFLAGS)
357libextractor_riff_la_LIBADD = \
358 $(top_builddir)/src/main/libextractor.la \
359 $(LE_LIBINTL) \
360 -lm
361
362libextractor_sid_la_SOURCES = \ 361libextractor_sid_la_SOURCES = \
363 sidextractor.c 362 sidextractor.c
364libextractor_sid_la_LDFLAGS = \ 363libextractor_sid_la_LDFLAGS = \
diff --git a/src/plugins/riffextractor.c b/src/plugins/riff_extractor.c
index 9b68b48..f6cd7f6 100644
--- a/src/plugins/riffextractor.c
+++ b/src/plugins/riff_extractor.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of libextractor. 2 This file is part of libextractor.
3 (C) 2004 Vidyut Samanta and Christian Grothoff 3 (C) 2004, 2009 Vidyut Samanta and Christian Grothoff
4 4
5 libextractor is free software; you can redistribute it and/or modify 5 libextractor is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -30,49 +30,12 @@
30#include "extractor.h" 30#include "extractor.h"
31#include <math.h> 31#include <math.h>
32 32
33static void
34addKeyword (struct EXTRACTOR_Keywords **list,
35 char *keyword, EXTRACTOR_KeywordType type)
36{
37 EXTRACTOR_KeywordList *next;
38 next = malloc (sizeof (EXTRACTOR_KeywordList));
39 next->next = *list;
40 next->keyword = keyword;
41 next->keywordType = type;
42 *list = next;
43}
44
45
46#ifdef FIXME
47static struct EXTRACTOR_Keywords *
48riffparse_INFO (char *buffer, size_t size, struct EXTRACTOR_Keywords *prev)
49{
50 size_t c = 0;
51 char *word;
52
53 if (size < 64)
54 return prev;
55 c = 8;
56 while ((c < size) && isprint (buffer[c]))
57 c++;
58 if (c > 8)
59 {
60 word = malloc (c + 1 - 8);
61 memcpy (word, &buffer[8], c - 8);
62 word[c - 8] = '\0';
63 addKeyword (&prev, word, EXTRACTOR_UNKNOWN); /* eh, what exactly is it */
64 }
65 return prev;
66}
67#endif
68
69
70/** 33/**
71 * Read the specified number of bytes as a little-endian (least 34 * Read the specified number of bytes as a little-endian (least
72 * significant byte first) integer. 35 * significant byte first) integer.
73 */ 36 */
74static unsigned int 37static unsigned int
75fread_le (char *data) 38fread_le (const char *data)
76{ 39{
77 int x; 40 int x;
78 unsigned int result = 0; 41 unsigned int result = 0;
@@ -92,11 +55,15 @@ round_double (double num)
92 return floor (num + 0.5); 55 return floor (num + 0.5);
93} 56}
94 57
58#define ADD(s,t) do { if (0 != (ret = proc (proc_cls, "riff", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen(s)+1))) goto FINISH; } while (0)
59
95/* video/x-msvideo */ 60/* video/x-msvideo */
96struct EXTRACTOR_Keywords * 61int
97libextractor_riff_extract (char *filename, 62EXTRACTOR_riff_extract (const char *xdata,
98 char *xdata, 63 size_t xsize,
99 size_t xsize, struct EXTRACTOR_Keywords *prev) 64 EXTRACTOR_MetaDataProcessor proc,
65 void *proc_cls,
66 const char *options)
100{ 67{
101 unsigned int blockLen; 68 unsigned int blockLen;
102 unsigned int fps; 69 unsigned int fps;
@@ -105,20 +72,18 @@ libextractor_riff_extract (char *filename,
105 unsigned int width; 72 unsigned int width;
106 unsigned int height; 73 unsigned int height;
107 char codec[5]; 74 char codec[5];
108 char *format; 75 char format[256];
76 int ret;
109 77
110 if (xsize < 32) 78 if (xsize < 32)
111 return prev; 79 return 0;
112
113 if ((memcmp (&xdata[0], 80 if ((memcmp (&xdata[0],
114 "RIFF", 4) != 0) || (memcmp (&xdata[8], "AVI ", 4) != 0)) 81 "RIFF", 4) != 0) || (memcmp (&xdata[8], "AVI ", 4) != 0))
115 return prev; 82 return 0;
116
117 if (memcmp (&xdata[12], "LIST", 4) != 0) 83 if (memcmp (&xdata[12], "LIST", 4) != 0)
118 return prev; 84 return 0;
119 if (memcmp (&xdata[20], "hdrlavih", 8) != 0) 85 if (memcmp (&xdata[20], "hdrlavih", 8) != 0)
120 return prev; 86 return 0;
121
122 87
123 blockLen = fread_le (&xdata[28]); 88 blockLen = fread_le (&xdata[28]);
124 89
@@ -128,31 +93,31 @@ libextractor_riff_extract (char *filename,
128 * 1000 / fps); 93 * 1000 / fps);
129 width = fread_le (&xdata[64]); 94 width = fread_le (&xdata[64]);
130 height = fread_le (&xdata[68]); 95 height = fread_le (&xdata[68]);
131
132
133 /* pos: begin of video stream header */ 96 /* pos: begin of video stream header */
134 pos = blockLen + 32; 97 pos = blockLen + 32;
135 98
136 if ((pos < blockLen) || (pos + 32 > xsize) || (pos > xsize)) 99 if ((pos < blockLen) || (pos + 32 > xsize) || (pos > xsize))
137 return prev; 100 return 0;
138
139 if (memcmp (&xdata[pos], "LIST", 4) != 0) 101 if (memcmp (&xdata[pos], "LIST", 4) != 0)
140 return prev; 102 return 0;
141 blockLen = fread_le (&xdata[pos + 4]); 103 blockLen = fread_le (&xdata[pos + 4]);
142 if (memcmp (&xdata[pos + 8], "strlstrh", 8) != 0) 104 if (memcmp (&xdata[pos + 8], "strlstrh", 8) != 0)
143 return prev; 105 return 0;
144 if (memcmp (&xdata[pos + 20], "vids", 4) != 0) 106 if (memcmp (&xdata[pos + 20], "vids", 4) != 0)
145 return prev; 107 return 0;
108 ret = 0;
146 /* pos + 24: video stream header */ 109 /* pos + 24: video stream header */
147 memcpy (codec, &xdata[pos + 24], 4); 110 memcpy (codec, &xdata[pos + 24], 4);
148 codec[4] = '\0'; 111 codec[4] = '\0';
149 112 snprintf (format,
150 format = malloc (256); 113 sizeof(format),
151 snprintf (format, 256, _("codec: %s, %u fps, %u ms"), codec, fps, duration); 114 _("codec: %s, %u fps, %u ms"), codec, fps, duration);
152 addKeyword (&prev, format, EXTRACTOR_FORMAT); 115 ADD (format, EXTRACTOR_METATYPE_FORMAT);
153 format = malloc (256); 116 snprintf (format,
154 snprintf (format, 256, "%ux%u", width, height); 117 sizeof(format),
155 addKeyword (&prev, format, EXTRACTOR_SIZE); 118 "%ux%u", width, height);
156 addKeyword (&prev, strdup ("video/x-msvideo"), EXTRACTOR_MIMETYPE); 119 ADD (format, EXTRACTOR_METATYPE_IMAGE_DIMENSIONS);
157 return prev; 120 ADD ("video/x-msvideo", EXTRACTOR_METATYPE_MIMETYPE);
121 FINISH:
122 return ret;
158} 123}