aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/mp4_extractor.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/mp4_extractor.c')
-rw-r--r--src/plugins/mp4_extractor.c207
1 files changed, 207 insertions, 0 deletions
diff --git a/src/plugins/mp4_extractor.c b/src/plugins/mp4_extractor.c
new file mode 100644
index 0000000..f486a89
--- /dev/null
+++ b/src/plugins/mp4_extractor.c
@@ -0,0 +1,207 @@
1/*
2 This file is part of libextractor.
3 (C) 2012 Christian Grothoff
4
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
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 libextractor is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with libextractor; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 */
20
21/**
22 * @file plugins/mp4_extractor.c
23 * @brief plugin to support MP4 files
24 * @author Christian Grothoff
25 */
26#include "platform.h"
27#include "extractor.h"
28#include <mp4v2/mp4v2.h>
29
30
31/**
32 * Callback invoked by libmp4v2 to open the file.
33 * We cheated and passed our extractor context as
34 * the filename (fingers crossed) and will simply
35 * return it again to make it the handle.
36 *
37 * @param name "filename" to open
38 * @param open mode, only reading allowed
39 * @return NULL if the file is not opened for reading
40 */
41static void*
42open_cb (const char *name,
43 MP4FileMode mode)
44{
45 void *ecp;
46
47 if (FILEMODE_READ != mode)
48 return NULL;
49 if (1 != sscanf (name, "%p", &ecp))
50 return NULL;
51 return ecp;
52}
53
54
55/**
56 * Seek callback for libmp4v2.
57 *
58 * @param handle the 'struct EXTRACTOR_ExtractContext'
59 * @param pos target seek position (relative or absolute?)
60 * @return true on failure, false on success
61 */
62static int
63seek_cb (void *handle,
64 int64_t pos)
65{
66 struct EXTRACTOR_ExtractContext *ec = handle;
67
68 fprintf (stderr, "Seek: %lld!\n", (long long) pos);
69 if (-1 ==
70 ec->seek (ec->cls,
71 pos,
72 SEEK_CUR))
73 return true; /* failure */
74 return false;
75}
76
77
78/**
79 * Read callback for libmp4v2.
80 *
81 * @param handle the 'struct EXTRACTOR_ExtractContext'
82 * @param buffer where to write data read
83 * @param size desired number of bytes to read
84 * @param nin where to write number of bytes read
85 * @param maxChunkSize some chunk size (ignored)
86 * @return true on failure, false on success
87 */
88static int
89read_cb (void *handle,
90 void *buffer,
91 int64_t size,
92 int64_t *nin,
93 int64_t maxChunkSize)
94{
95 struct EXTRACTOR_ExtractContext *ec = handle;
96 void *buf;
97 ssize_t ret;
98
99 fprintf (stderr, "read!\n");
100 *nin = 0;
101 if (-1 ==
102 (ret = ec->read (ec->cls,
103 &buf,
104 size)))
105 return true; /* failure */
106 memcpy (buffer, buf, ret);
107 *nin = ret;
108 return false; /* success */
109}
110
111
112/**
113 * Write callback for libmp4v2.
114 *
115 * @param handle the 'struct EXTRACTOR_ExtractContext'
116 * @param buffer data to write
117 * @param size desired number of bytes to write
118 * @param nin where to write number of bytes written
119 * @param maxChunkSize some chunk size (ignored)
120 * @return true on failure (always fails)
121 */
122static int
123write_cb (void *handle,
124 const void *buffer,
125 int64_t size,
126 int64_t *nout,
127 int64_t maxChunkSize)
128{
129 fprintf (stderr, "Write!?\n");
130 return true; /* failure */
131}
132
133
134/**
135 * Write callback for libmp4v2. Does nothing.
136 *
137 * @param handle the 'struct EXTRACTOR_ExtractContext'
138 * @return false on success (always succeeds)
139 */
140static int
141close_cb (void *handle)
142{
143 fprintf (stderr, "Close!\n");
144 return false; /* success */
145}
146
147
148#if 0
149/**
150 * Wrapper to replace 'stat64' call by libmp4v2.
151 */
152int
153stat_cb (const char * path,
154 struct stat64 * buf)
155{
156 void *ecp;
157 struct EXTRACTOR_ExtractContext *ec;
158
159 fprintf (stderr, "stat!\n");
160 if (1 != sscanf (path, "%p", &ecp))
161 {
162 errno = EINVAL;
163 return -1;
164 }
165 ec = ecp;
166 memset (buf, 0, sizeof (struct stat));
167 buf->st_size = ec->get_size (ec->cls);
168 return 0;
169}
170#endif
171
172
173/**
174 * Main entry method for the MP4 extraction plugin.
175 *
176 * @param ec extraction context provided to the plugin
177 */
178void
179EXTRACTOR_mp4_extract_method (struct EXTRACTOR_ExtractContext *ec)
180{
181 MP4FileProvider fp;
182 MP4FileHandle mp4;
183 const MP4Tags *tags;
184 char ecp[128];
185 void *dl;
186
187 if (1)
188 return; /* plugin is known not to work yet;
189 see issue 138 filed against MP4v2 lib */
190 snprintf (ecp, sizeof (ecp), "%p", ec);
191 fp.open = &open_cb;
192 fp.seek = &seek_cb;
193 fp.read = &read_cb;
194 fp.write = &write_cb;
195 fp.close = &close_cb;
196 if (NULL == (mp4 = MP4ReadProvider (ecp,
197 &fp)))
198 return;
199 tags = MP4TagsAlloc ();
200 if (MP4TagsFetch (tags, mp4))
201 {
202 fprintf (stderr, "got tags!\n");
203 }
204 MP4Close (mp4, 0);
205}
206
207/* end of mp4_extractor.c */