48e2f01c |
1 | /* |
2 | * Copyright (C) 2013 nu774 |
3 | * For conditions of distribution and use, see copyright notice in COPYING |
4 | */ |
5 | #ifndef M4AF_H |
6 | #define M4AF_H |
7 | |
8 | #define M4AF_FOURCC(a,b,c,d) (((a)<<24)|((b)<<16)|((c)<<8)|(d)) |
9 | |
10 | enum m4af_error_code { |
e4bbeeb0 |
11 | M4AF_IO_ERROR = -1, |
12 | M4AF_NO_MEMORY = -2, |
13 | M4AF_FORMAT_ERROR = -3, |
14 | M4AF_NOT_SUPPORTED = -4, |
48e2f01c |
15 | }; |
16 | |
17 | enum m4af_itmf_tag { |
18 | M4AF_TAG_TITLE = M4AF_FOURCC('\xa9','n','a','m'), |
19 | M4AF_TAG_ARTIST = M4AF_FOURCC('\xa9','A','R','T'), |
20 | M4AF_TAG_ALBUM = M4AF_FOURCC('\xa9','a','l','b'), |
21 | M4AF_TAG_GENRE = M4AF_FOURCC('\xa9','g','e','n'), |
22 | M4AF_TAG_DATE = M4AF_FOURCC('\xa9','d','a','y'), |
23 | M4AF_TAG_COMPOSER = M4AF_FOURCC('\xa9','w','r','t'), |
24 | M4AF_TAG_GROUPING = M4AF_FOURCC('\xa9','g','r','p'), |
25 | M4AF_TAG_COMMENT = M4AF_FOURCC('\xa9','c','m','t'), |
26 | M4AF_TAG_LYRICS = M4AF_FOURCC('\xa9','l','y','r'), |
27 | M4AF_TAG_TOOL = M4AF_FOURCC('\xa9','t','o','o'), |
28 | M4AF_TAG_ALBUM_ARTIST = M4AF_FOURCC('a','A','R','T'), |
29 | M4AF_TAG_TRACK = M4AF_FOURCC('t','r','k','n'), |
30 | M4AF_TAG_DISK = M4AF_FOURCC('d','i','s','k'), |
31 | M4AF_TAG_GENRE_ID3 = M4AF_FOURCC('g','n','r','e'), |
32 | M4AF_TAG_TEMPO = M4AF_FOURCC('t','m','p','o'), |
33 | M4AF_TAG_DESCRIPTION = M4AF_FOURCC('d','e','s','c'), |
34 | M4AF_TAG_LONG_DESCRIPTION = M4AF_FOURCC('l','d','e','s'), |
35 | M4AF_TAG_COPYRIGHT = M4AF_FOURCC('c','p','r','t'), |
36 | M4AF_TAG_COMPILATION = M4AF_FOURCC('c','p','i','l'), |
37 | M4AF_TAG_ARTWORK = M4AF_FOURCC('c','o','v','r'), |
38 | }; |
39 | |
40 | enum m4af_itmf_type_code { |
41 | M4AF_IMPLICIT = 0, |
42 | M4AF_UTF8 = 1, |
43 | M4AF_GIF = 12, |
44 | M4AF_JPEG = 13, |
45 | M4AF_PNG = 14, |
46 | M4AF_INTEGER = 21, |
47 | }; |
48 | |
49 | enum m4af_codec_type { |
50 | M4AF_CODEC_MP4A = M4AF_FOURCC('m','p','4','a'), |
51 | M4AF_CODEC_ALAC = M4AF_FOURCC('a','l','a','c'), |
52 | M4AF_CODEC_TEXT = M4AF_FOURCC('t','e','x','t'), |
53 | }; |
54 | |
d317e29d |
55 | enum m4af_priming_mode { |
56 | M4AF_PRIMING_MODE_ITUNSMPB = 1, |
57 | M4AF_PRIMING_MODE_EDTS = 2, |
58 | M4AF_PRIMING_MODE_BOTH = 3 |
59 | }; |
60 | |
e4bbeeb0 |
61 | typedef int (*m4af_read_callback)(void *cookie, void *buffer, uint32_t size); |
48e2f01c |
62 | typedef int (*m4af_write_callback)(void *cookie, const void *data, |
63 | uint32_t size); |
64 | typedef int (*m4af_seek_callback)(void *cookie, int64_t off, int whence); |
65 | typedef int64_t (*m4af_tell_callback)(void *cookie); |
66 | |
67 | typedef struct m4af_io_callbacks_t { |
e4bbeeb0 |
68 | m4af_read_callback read; |
48e2f01c |
69 | m4af_write_callback write; |
70 | m4af_seek_callback seek; |
71 | m4af_tell_callback tell; |
72 | } m4af_io_callbacks_t; |
73 | |
e4bbeeb0 |
74 | typedef struct m4af_itmf_entry_t { |
75 | uint32_t fcc; |
76 | char *name; |
77 | uint32_t type_code; |
78 | char *data; |
79 | uint32_t data_size; |
80 | } m4af_itmf_entry_t; |
48e2f01c |
81 | |
e4bbeeb0 |
82 | typedef struct m4af_ctx_t m4af_ctx_t; |
48e2f01c |
83 | |
48e2f01c |
84 | |
e4bbeeb0 |
85 | m4af_ctx_t *m4af_create(uint32_t codec, uint32_t timescale, |
86 | m4af_io_callbacks_t *io, void *io_cookie); |
48e2f01c |
87 | |
e4bbeeb0 |
88 | int m4af_begin_write(m4af_ctx_t *ctx); |
48e2f01c |
89 | |
fb2b3635 |
90 | int m4af_finalize(m4af_ctx_t *ctx, int optimize); |
48e2f01c |
91 | |
e4bbeeb0 |
92 | void m4af_teardown(m4af_ctx_t **ctx); |
48e2f01c |
93 | |
e4bbeeb0 |
94 | int m4af_write_sample(m4af_ctx_t *ctx, uint32_t track_idx, const void *data, |
95 | uint32_t size, uint32_t duration); |
48e2f01c |
96 | |
e4bbeeb0 |
97 | int m4af_set_decoder_specific_info(m4af_ctx_t *ctx, uint32_t track_idx, |
98 | uint8_t *data, uint32_t size); |
48e2f01c |
99 | |
2f6fc566 |
100 | void m4af_set_vbr_mode(m4af_ctx_t *ctx, uint32_t track_idx, int is_vbr); |
101 | |
e4bbeeb0 |
102 | void m4af_set_priming(m4af_ctx_t *ctx, uint32_t track_idx, |
48e2f01c |
103 | uint32_t encoder_delay, uint32_t padding); |
104 | |
d317e29d |
105 | void m4af_set_priming_mode(m4af_ctx_t *ctx, int mode); |
106 | |
e4bbeeb0 |
107 | void m4af_set_fixed_frame_duration(m4af_ctx_t *ctx, uint32_t track_idx, |
108 | uint32_t length); |
48e2f01c |
109 | |
e4bbeeb0 |
110 | int m4af_add_itmf_long_tag(m4af_ctx_t *ctx, const char *name, |
111 | const char *data); |
48e2f01c |
112 | |
e4bbeeb0 |
113 | int m4af_add_itmf_short_tag(m4af_ctx_t *ctx, uint32_t fcc, uint32_t type_code, |
114 | const void *data, uint32_t data_size); |
48e2f01c |
115 | |
e4bbeeb0 |
116 | int m4af_add_itmf_string_tag(m4af_ctx_t *ctx, uint32_t fcc, const char *data); |
48e2f01c |
117 | |
e4bbeeb0 |
118 | int m4af_add_itmf_int8_tag(m4af_ctx_t *ctx, uint32_t fcc, int value); |
48e2f01c |
119 | |
e4bbeeb0 |
120 | int m4af_add_itmf_int16_tag(m4af_ctx_t *ctx, uint32_t fcc, int value); |
c5c45908 |
121 | |
e4bbeeb0 |
122 | int m4af_add_itmf_int32_tag(m4af_ctx_t *ctx, uint32_t fcc, uint32_t value); |
48e2f01c |
123 | |
e4bbeeb0 |
124 | int m4af_add_itmf_int64_tag(m4af_ctx_t *ctx, uint32_t fcc, uint64_t value); |
48e2f01c |
125 | |
e4bbeeb0 |
126 | int m4af_add_itmf_track_tag(m4af_ctx_t *ctx, int track, int total); |
48e2f01c |
127 | |
e4bbeeb0 |
128 | int m4af_add_itmf_disk_tag(m4af_ctx_t *ctx, int disk, int total); |
48e2f01c |
129 | |
e4bbeeb0 |
130 | int m4af_add_itmf_genre_tag(m4af_ctx_t *ctx, int genre); |
48e2f01c |
131 | #endif |