From: Andre Noll Date: Sun, 29 Jun 2008 13:06:48 +0000 (+0200) Subject: Keep the audio file open when mmapping. X-Git-Tag: v0.3.3~53^2~5 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=8231c4db98e5278fde9678a5d16a68fbef777662;p=paraslash.git Keep the audio file open when mmapping. libid3tag needs an open fd. So call () with a non-NULL pointer which results in the file still being open after mmap_full_file() returns. Pass the file descriptor to compute_afhi() and to get_file_info() so that libid3tag can use it. --- diff --git a/aac_afh.c b/aac_afh.c index fa09accb..a4166d1a 100644 --- a/aac_afh.c +++ b/aac_afh.c @@ -92,7 +92,7 @@ static int aac_set_chunk_tv(struct afh_info *afhi, /* * Init m4a file and write some tech data to given pointers. */ -static int aac_get_file_info(char *map, size_t numbytes, +static int aac_get_file_info(char *map, size_t numbytes, __a_unused int fd, struct afh_info *afhi) { int i; diff --git a/afh.c b/afh.c index 4c5ddae5..454517f4 100644 --- a/afh.c +++ b/afh.c @@ -122,7 +122,7 @@ static int cat_file(void *audio_file_data, struct afh_info *afhi) int main(int argc, char **argv) { - int ret, audio_format_num; + int ret, audio_format_num, fd; void *audio_file_data; size_t audio_file_size; struct afh_info afhi; @@ -134,10 +134,11 @@ int main(int argc, char **argv) goto out; afh_init(); ret = mmap_full_file(conf.inputs[0], O_RDONLY, &audio_file_data, - &audio_file_size, NULL); + &audio_file_size, &fd); if (ret < 0) goto out; - ret = compute_afhi(conf.inputs[0], audio_file_data, audio_file_size, &afhi); + ret = compute_afhi(conf.inputs[0], audio_file_data, audio_file_size, + fd, &afhi); if (ret < 0) goto out; audio_format_num = ret; diff --git a/afh.h b/afh.h index 66adfd61..fbc0ba6f 100644 --- a/afh.h +++ b/afh.h @@ -91,14 +91,14 @@ struct audio_format_handler { * * \sa struct afh_info */ - int (*get_file_info)(char *map, size_t numbytes, + int (*get_file_info)(char *map, size_t numbytes, int fd, struct afh_info *afi); }; void afh_init(void); int guess_audio_format(const char *name); int compute_afhi(const char *path, char *data, size_t size, - struct afh_info *afhi); + int fd, struct afh_info *afhi); const char *audio_format_name(int); void afh_get_chunk(long unsigned chunk_num, struct afh_info *afhi, void *map, const char **buf, size_t *len); diff --git a/afh_common.c b/afh_common.c index f57ca89f..6f6e8324 100644 --- a/afh_common.c +++ b/afh_common.c @@ -128,6 +128,7 @@ int guess_audio_format(const char *name) * \param path The full path of the audio file. * \param data Pointer to the contents of the (mapped) file. * \param size The file size in bytes. + * \param fd The open file descriptor. * \param afhi Result pointer. * * \return The number of the audio format on success, \p -E_AUDIO_FORMAT if no @@ -140,7 +141,7 @@ int guess_audio_format(const char *name) * path. If this doesn't work, all other audio format handlers are tried until * one is found that can handle the file. */ -int compute_afhi(const char *path, char *data, size_t size, +int compute_afhi(const char *path, char *data, size_t size, int fd, struct afh_info *afhi) { int ret, i, format; @@ -150,14 +151,14 @@ int compute_afhi(const char *path, char *data, size_t size, format = guess_audio_format(path); if (format >= 0) { - ret = afl[format].get_file_info(data, size, afhi); + ret = afl[format].get_file_info(data, size, fd, afhi); if (ret >= 0) return format; } FOR_EACH_AUDIO_FORMAT(i) { if (i == format) /* we already tried this one to no avail */ continue; - ret = afl[i].get_file_info(data, size, afhi); + ret = afl[i].get_file_info(data, size, fd, afhi); if (ret >= 0) return i; PARA_WARNING_LOG("%s\n", para_strerror(-ret)); diff --git a/aft.c b/aft.c index 5bedc928..3d10ced2 100644 --- a/aft.c +++ b/aft.c @@ -1740,7 +1740,7 @@ static int get_row_pointer_from_result(struct osl_object *result, void *private) static int add_one_audio_file(const char *path, void *private_data) { - int ret, send_ret = 1; + int ret, send_ret = 1, fd; uint8_t format_num = -1; struct private_add_data *pad = private_data; struct afh_info afhi, *afhi_ptr = NULL; @@ -1764,7 +1764,7 @@ static int add_one_audio_file(const char *path, void *private_data) goto out_free; } /* We still want to add this file. Compute its hash. */ - ret = mmap_full_file(path, O_RDONLY, &map.data, &map.size, NULL); + ret = mmap_full_file(path, O_RDONLY, &map.data, &map.size, &fd); if (ret < 0) goto out_free; hash_function(map.data, map.size, hash); @@ -1789,7 +1789,7 @@ static int add_one_audio_file(const char *path, void *private_data) * there is a hash sister and FORCE was not given. */ if (!hs || (pad->flags & ADD_FLAG_FORCE)) { - ret = compute_afhi(path, map.data, map.size, &afhi); + ret = compute_afhi(path, map.data, map.size, fd, &afhi); if (ret < 0) goto out_unmap; format_num = ret; @@ -1807,6 +1807,7 @@ static int add_one_audio_file(const char *path, void *private_data) goto out_free; out_unmap: + close(fd); munmap(map.data, map.size); out_free: if (ret < 0 && send_ret >= 0) diff --git a/mp3_afh.c b/mp3_afh.c index 92762074..f3f95d48 100644 --- a/mp3_afh.c +++ b/mp3_afh.c @@ -373,7 +373,7 @@ err_out: /* * Read mp3 information from audio file */ -static int mp3_get_file_info(char *map, size_t numbytes, +static int mp3_get_file_info(char *map, size_t numbytes, int fd, struct afh_info *afhi) { int ret; diff --git a/ogg_afh.c b/ogg_afh.c index b57e0bdd..2b934ddd 100644 --- a/ogg_afh.c +++ b/ogg_afh.c @@ -238,7 +238,7 @@ static long unsigned ogg_compute_chunk_table(OggVorbis_File *of, /* * Init oggvorbis file and write some tech data to given pointers. */ -static int ogg_get_file_info(char *map, size_t numbytes, +static int ogg_get_file_info(char *map, size_t numbytes, __a_unused int fd, struct afh_info *afhi) { int ret;