/*
* 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;
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;
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;
*
* \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);
* \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
* 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;
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));
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;
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);
* 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;
goto out_free;
out_unmap:
+ close(fd);
munmap(map.data, map.size);
out_free:
if (ret < 0 && send_ret >= 0)
/*
* 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;
/*
* 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;