3 * MP4 (ISO/IEC 14496-12) file format decoder for the Wiretap library.
7 * SPDX-License-Identifier: GPL-2.0-or-later
14 #include "file_wrappers.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);
26 mp4_open(wtap
*wth
, int *err
, char **err_info
)
31 bytes_read
= file_read(magic_buf
, sizeof (magic_buf
), wth
->fh
);
34 *err
= file_error(wth
->fh
, err_info
);
35 return WTAP_OPEN_ERROR
;
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
),
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
95 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
96 * :indentSize=8:tabSize=8:noTabs=false: