regen pidl all: rm epan/dissectors/pidl/*-stamp; pushd epan/dissectors/pidl/ && make...
[wireshark-sm.git] / wiretap / mp4.c
blob40b08cf1a9b8889f58dc2c6455924a76dfab1af8
1 /* mp4.c
3 * MP4 (ISO/IEC 14496-12) file format decoder for the Wiretap library.
5 * Wiretap Library
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
10 #include "mp4.h"
12 #include <string.h>
14 #include "file_wrappers.h"
15 #include "wtap-int.h"
17 static const uint8_t mp4_magic[] = { 'f', 't', 'y', 'p' };
18 static const uint8_t mp4_magic_sidx[] = { 's', 'i', 'd', 'x' };
19 static const uint8_t mp4_magic_styp[] = { 's', 't', 'y', 'p' };
21 static int mp4_file_type_subtype = -1;
23 void register_mp4(void);
25 wtap_open_return_val
26 mp4_open(wtap *wth, int *err, char **err_info)
28 char magic_buf[8];
29 int bytes_read;
31 bytes_read = file_read(magic_buf, sizeof (magic_buf), wth->fh);
33 if (bytes_read < 0) {
34 *err = file_error(wth->fh, err_info);
35 return WTAP_OPEN_ERROR;
37 if (bytes_read == 0)
38 return WTAP_OPEN_NOT_MINE;
40 if (bytes_read == sizeof (magic_buf) &&
41 memcmp(magic_buf + 4, mp4_magic, sizeof (mp4_magic)) &&
42 memcmp(magic_buf + 4, mp4_magic_sidx, sizeof (mp4_magic_sidx)) &&
43 memcmp(magic_buf + 4, mp4_magic_styp, sizeof (mp4_magic_styp)))
44 return WTAP_OPEN_NOT_MINE;
46 if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
47 return WTAP_OPEN_ERROR;
49 wth->file_type_subtype = mp4_file_type_subtype;
50 wth->file_encap = WTAP_ENCAP_MP4;
51 wth->file_tsprec = WTAP_TSPREC_SEC;
52 wth->subtype_read = wtap_full_file_read;
53 wth->subtype_seek_read = wtap_full_file_seek_read;
54 wth->snapshot_length = 0;
56 return WTAP_OPEN_MINE;
59 static const struct supported_block_type mp4_blocks_supported[] = {
61 * This is a file format that we dissect, so we provide
62 * only one "packet" with the file's contents, and don't
63 * support any options.
65 { WTAP_BLOCK_PACKET, ONE_BLOCK_SUPPORTED, NO_OPTIONS_SUPPORTED }
68 static const struct file_type_subtype_info mp4_info = {
69 "MP4 media", "mp4", "mp4", NULL,
70 false, BLOCKS_SUPPORTED(mp4_blocks_supported),
71 NULL, NULL, NULL
74 void register_mp4(void)
76 mp4_file_type_subtype = wtap_register_file_type_subtype(&mp4_info);
79 * Register name for backwards compatibility with the
80 * wtap_filetypes table in Lua.
82 wtap_register_backwards_compatibility_lua_name("MP4",
83 mp4_file_type_subtype);
87 * Editor modelines - https://www.wireshark.org/tools/modelines.html
89 * Local variables:
90 * c-basic-offset: 8
91 * tab-width: 8
92 * indent-tabs-mode: t
93 * End:
95 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
96 * :indentSize=8:tabSize=8:noTabs=false: