From da3ea6b27d13821320b39094d591e958739d44cb Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 8 Aug 2021 22:09:28 +0200 Subject: [PATCH] mp4: Make non-public functions static. It's generally a good thing to reduce the scope to the compilation unit where possible. Static functions also reduce the number of symbols and help the compiler to optimize the generated code. --- mp4.c | 70 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/mp4.c b/mp4.c index 58838d55..9368a790 100644 --- a/mp4.c +++ b/mp4.c @@ -14,7 +14,7 @@ int32_t mp4ff_total_tracks(const mp4ff_t * f) return f->total_tracks; } -int32_t mp4ff_read_data(mp4ff_t * f, void *data, uint32_t size) +static int32_t mp4ff_read_data(mp4ff_t * f, void *data, uint32_t size) { int32_t result = 1; @@ -45,7 +45,7 @@ static int32_t mp4ff_atom_get_size(const int8_t * data) return (int32_t) result; } -uint64_t mp4ff_read_int64(mp4ff_t * f) +static uint64_t mp4ff_read_int64(mp4ff_t * f) { uint8_t data[8]; uint64_t result = 0; @@ -324,7 +324,7 @@ static uint8_t mp4ff_atom_name_to_type(const int8_t a, const int8_t b, } /* read atom header, return atom size, atom size is with header included */ -uint64_t mp4ff_atom_read_header(mp4ff_t * f, uint8_t * atom_type, +static uint64_t mp4ff_atom_read_header(mp4ff_t * f, uint8_t * atom_type, uint8_t * header_size) { uint64_t size; @@ -350,7 +350,7 @@ uint64_t mp4ff_atom_read_header(mp4ff_t * f, uint8_t * atom_type, return size; } -int64_t mp4ff_position(const mp4ff_t * f) +static int64_t mp4ff_position(const mp4ff_t * f) { return f->current_position; } @@ -381,7 +381,7 @@ static int need_parse_when_meta_only(uint8_t atom_type) } } -int32_t mp4ff_set_position(mp4ff_t * f, const int64_t position) +static int32_t mp4ff_set_position(mp4ff_t * f, const int64_t position) { f->stream->seek(f->stream->user_data, position); f->current_position = position; @@ -404,14 +404,14 @@ static void mp4ff_track_add(mp4ff_t * f) memset(f->track[f->total_tracks - 1], 0, sizeof (mp4ff_track_t)); } -uint8_t mp4ff_read_char(mp4ff_t * f) +static uint8_t mp4ff_read_char(mp4ff_t * f) { uint8_t output; mp4ff_read_data(f, &output, 1); return output; } -uint32_t mp4ff_read_int24(mp4ff_t * f) +static uint32_t mp4ff_read_int24(mp4ff_t * f) { uint32_t result; uint32_t a, b, c; @@ -426,7 +426,7 @@ uint32_t mp4ff_read_int24(mp4ff_t * f) return (uint32_t) result; } -uint32_t mp4ff_read_int32(mp4ff_t * f) +static uint32_t mp4ff_read_int32(mp4ff_t * f) { uint32_t result; uint32_t a, b, c, d; @@ -630,7 +630,7 @@ static int32_t mp4ff_read_stco(mp4ff_t * f) return 0; } -uint16_t mp4ff_read_int16(mp4ff_t * f) +static uint16_t mp4ff_read_int16(mp4ff_t * f) { uint32_t result; uint32_t a, b; @@ -644,7 +644,7 @@ uint16_t mp4ff_read_int16(mp4ff_t * f) return (uint16_t) result; } -uint32_t mp4ff_read_mp4_descr_length(mp4ff_t * f) +static uint32_t mp4ff_read_mp4_descr_length(mp4ff_t * f) { uint8_t b; uint8_t numBytes = 0; @@ -900,7 +900,7 @@ static const char *ID3v1GenreList[] = { "Anime", "JPop", "SynthPop", }; -const char *mp4ff_meta_index_to_genre(uint32_t idx) +static const char *mp4ff_meta_index_to_genre(uint32_t idx) { if (idx > 0 && idx <= sizeof (ID3v1GenreList) / sizeof (ID3v1GenreList[0])) { return ID3v1GenreList[idx - 1]; @@ -909,7 +909,7 @@ const char *mp4ff_meta_index_to_genre(uint32_t idx) } } -char *mp4ff_read_string(mp4ff_t * f, uint32_t length) +static char *mp4ff_read_string(mp4ff_t * f, uint32_t length) { char *str = (char *) malloc(length + 1); if (str != 0) { @@ -1170,7 +1170,7 @@ static int32_t mp4ff_read_mdhd(mp4ff_t * f) return 1; } -int32_t mp4ff_parse_metadata(mp4ff_t * f, const int32_t size) +static int32_t mp4ff_parse_metadata(mp4ff_t * f, const int32_t size) { uint64_t subsize, sumsize = 0; uint8_t atom_type; @@ -1212,7 +1212,7 @@ static int32_t mp4ff_read_meta(mp4ff_t * f, const uint64_t size) return 0; } -int32_t mp4ff_atom_read(mp4ff_t * f, const int32_t size, +static int32_t mp4ff_atom_read(mp4ff_t * f, const int32_t size, const uint8_t atom_type) { uint64_t dest_position = mp4ff_position(f) + size - 8; @@ -1252,7 +1252,7 @@ int32_t mp4ff_atom_read(mp4ff_t * f, const int32_t size, } /* parse atoms that are sub atoms of other atoms */ -int32_t parse_sub_atoms(mp4ff_t * f, const uint64_t total_size, int meta_only) +static int32_t parse_sub_atoms(mp4ff_t * f, const uint64_t total_size, int meta_only) { uint64_t size; uint8_t atom_type = 0; @@ -1288,7 +1288,7 @@ int32_t parse_sub_atoms(mp4ff_t * f, const uint64_t total_size, int meta_only) } /* parse root atoms */ -int32_t parse_atoms(mp4ff_t * f, int meta_only) +static int32_t parse_atoms(mp4ff_t * f, int meta_only) { uint64_t size; uint8_t atom_type = 0; @@ -1371,7 +1371,7 @@ mp4ff_t *mp4ff_open_read(mp4ff_callback_t * f) return ff; } -int32_t mp4ff_tag_delete(mp4ff_metadata_t * tags) +static int32_t mp4ff_tag_delete(mp4ff_metadata_t * tags) { uint32_t i; @@ -1539,7 +1539,7 @@ int32_t mp4ff_set_sample_position(mp4ff_t * f, const int32_t track, return 0; } -int32_t mp4ff_audio_frame_size(const mp4ff_t * f, const int32_t track, +static int32_t mp4ff_audio_frame_size(const mp4ff_t * f, const int32_t track, const int32_t sample) { int32_t bytes; @@ -1694,7 +1694,7 @@ typedef struct { #define stricmp strcasecmp -membuffer *membuffer_create(void) +static membuffer *membuffer_create(void) { const unsigned initial_size = 256; @@ -1707,7 +1707,7 @@ membuffer *membuffer_create(void) return buf; } -unsigned membuffer_write(membuffer * buf, const void *ptr, unsigned bytes) +static unsigned membuffer_write(membuffer * buf, const void *ptr, unsigned bytes) { unsigned dest_size = buf->written + bytes; @@ -1738,18 +1738,18 @@ unsigned membuffer_write(membuffer * buf, const void *ptr, unsigned bytes) #define membuffer_write_data membuffer_write -unsigned membuffer_write_atom_name(membuffer * buf, const char *data) +static unsigned membuffer_write_atom_name(membuffer * buf, const char *data) { return membuffer_write_data(buf, data, 4) == 4 ? 1 : 0; } -unsigned membuffer_write_int16(membuffer * buf, uint16_t data) +static unsigned membuffer_write_int16(membuffer * buf, uint16_t data) { uint8_t temp[2] = { (uint8_t) (data >> 8), (uint8_t) data }; return membuffer_write_data(buf, temp, 2); } -unsigned membuffer_write_int32(membuffer * buf, uint32_t data) +static unsigned membuffer_write_int32(membuffer * buf, uint32_t data) { uint8_t temp[4] = { (uint8_t) (data >> 24), (uint8_t) (data >> 16), (uint8_t) (data >> 8), (uint8_t) data }; @@ -1796,7 +1796,7 @@ static uint32_t myatoi(const char *param) return param ? atoi(param) : 0; } -uint32_t mp4ff_meta_genre_to_index(const char *genrestr) +static uint32_t mp4ff_meta_genre_to_index(const char *genrestr) { unsigned n; for (n = 0; n < sizeof (ID3v1GenreList) / sizeof (ID3v1GenreList[0]); n++) { @@ -1889,24 +1889,24 @@ static void membuffer_write_custom_tag(membuffer * buf, const char *name, membuffer_write_data(buf, value, strlen(value)); } -unsigned membuffer_error(const membuffer * buf) +static unsigned membuffer_error(const membuffer * buf) { return buf->error; } -void membuffer_free(membuffer * buf) +static void membuffer_free(membuffer * buf) { if (buf->data) free(buf->data); free(buf); } -unsigned membuffer_get_size(const membuffer * buf) +static unsigned membuffer_get_size(const membuffer * buf) { return buf->written; } -void *membuffer_detach(membuffer * buf) +static void *membuffer_detach(membuffer * buf) { void *ret; @@ -2018,7 +2018,7 @@ static uint32_t create_ilst(const mp4ff_metadata_t * data, void **out_buffer, return 1; } -void membuffer_write_atom(membuffer * buf, const char *name, unsigned size, +static void membuffer_write_atom(membuffer * buf, const char *name, unsigned size, const void *data) { membuffer_write_int32(buf, size + 8); @@ -2026,17 +2026,17 @@ void membuffer_write_atom(membuffer * buf, const char *name, unsigned size, membuffer_write_data(buf, data, size); } -void *membuffer_get_ptr(const membuffer * buf) +static void *membuffer_get_ptr(const membuffer * buf) { return buf->data; } -void membuffer_set_error(membuffer * buf) +static void membuffer_set_error(membuffer * buf) { buf->error = 1; } -unsigned membuffer_transfer_from_file(membuffer * buf, mp4ff_t * src, +static unsigned membuffer_transfer_from_file(membuffer * buf, mp4ff_t * src, unsigned bytes) { unsigned oldsize; @@ -2238,7 +2238,7 @@ static uint32_t modify_moov(mp4ff_t * f, const mp4ff_metadata_t * data, return 1; } -int32_t mp4ff_write_data(mp4ff_t * f, void *data, uint32_t size) +static int32_t mp4ff_write_data(mp4ff_t * f, void *data, uint32_t size) { int32_t result = 1; @@ -2249,7 +2249,7 @@ int32_t mp4ff_write_data(mp4ff_t * f, void *data, uint32_t size) return result; } -int32_t mp4ff_write_int32(mp4ff_t * f, const uint32_t data) +static int32_t mp4ff_write_int32(mp4ff_t * f, const uint32_t data) { uint32_t result; uint32_t a, b, c, d; @@ -2266,7 +2266,7 @@ int32_t mp4ff_write_int32(mp4ff_t * f, const uint32_t data) return mp4ff_write_data(f, (uint8_t *) & result, sizeof (result)); } -int32_t mp4ff_truncate(mp4ff_t * f) +static int32_t mp4ff_truncate(mp4ff_t * f) { return f->stream->truncate(f->stream->user_data); } -- 2.39.5