2 * Copyright (C) 2008-2013 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file afh.c Paraslash's standalone audio format handler tool. */
13 #include "afh.cmdline.h"
19 static struct afh_args_info conf
;
23 INIT_STDERR_LOGGING(loglevel
)
25 static void print_info(int audio_format_num
, struct afh_info
*afhi
)
29 afh_get_afhi_txt(audio_format_num
, afhi
, &msg
);
34 static void print_chunk_table(struct afh_info
*afhi
)
38 if (conf
.parser_friendly_given
) {
39 printf("chunk_table: ");
40 for (i
= 0; i
<= afhi
->chunks_total
; i
++)
41 printf("%u ", afhi
->chunk_table
[i
]);
45 for (i
= 1; i
<= afhi
->chunks_total
; i
++) {
47 long unsigned from
, to
;
48 tv_scale(i
- 1, &afhi
->chunk_tv
, &tv
);
50 tv_scale(i
, &afhi
->chunk_tv
, &tv
);
52 printf("%d [%lu.%03lu - %lu.%03lu] %u - %u (%u)\n", i
- 1,
53 from
/ 1000, from
% 1000, to
/ 1000, to
% 1000,
54 afhi
->chunk_table
[i
- 1], afhi
->chunk_table
[i
],
55 afhi
->chunk_table
[i
] - afhi
->chunk_table
[i
- 1]);
60 * The main function of para_afh.
62 * \param argc Usual argument count.
63 * \param argv Usual argument vector.
65 * \return \p EXIT_FAILURE or \p EXIT_SUCCESS.
67 int main(int argc
, char **argv
)
69 int i
, ret
, audio_format_num
, fd
;
70 void *audio_file_data
;
71 size_t audio_file_size
;
74 afh_cmdline_parser(argc
, argv
, &conf
);
75 loglevel
= get_loglevel_by_name(conf
.loglevel_arg
);
76 HANDLE_VERSION_FLAG("afh", conf
);
78 if (conf
.inputs_num
== 0)
81 for (i
= 0; i
< conf
.inputs_num
; i
++) {
83 ret
= mmap_full_file(conf
.inputs
[i
], O_RDONLY
, &audio_file_data
,
84 &audio_file_size
, &fd
);
86 PARA_ERROR_LOG("failed to mmap \"%s\"\n", conf
.inputs
[i
]);
89 ret
= compute_afhi(conf
.inputs
[i
], audio_file_data
, audio_file_size
,
94 audio_format_num
= ret
;
95 printf("File %d: %s\n", i
+ 1, conf
.inputs
[i
]);
96 print_info(audio_format_num
, &afhi
);
97 if (conf
.chunk_table_given
)
98 print_chunk_table(&afhi
);
101 ret2
= para_munmap(audio_file_data
, audio_file_size
);
102 if (ret2
< 0 && ret
>= 0)
109 PARA_ERROR_LOG("%s\n", para_strerror(-ret
));
110 return ret
< 0? EXIT_FAILURE
: EXIT_SUCCESS
;