2 * Copyright (C) 2008 Andre Noll <maan@tuebingen.mpg.de>
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"
20 static struct afh_args_info conf
;
24 INIT_STDERR_LOGGING(loglevel
)
26 static void print_info(int audio_format_num
, struct afh_info
*afhi
)
30 afh_get_afhi_txt(audio_format_num
, afhi
, &msg
);
35 static void print_chunk_table(struct afh_info
*afhi
)
39 if (conf
.parser_friendly_given
) {
40 printf("chunk_table: ");
41 for (i
= 0; i
<= afhi
->chunks_total
; i
++)
42 printf("%u ", afhi
->chunk_table
[i
]);
46 for (i
= 1; i
<= afhi
->chunks_total
; i
++) {
48 long unsigned from
, to
;
49 tv_scale(i
- 1, &afhi
->chunk_tv
, &tv
);
51 tv_scale(i
, &afhi
->chunk_tv
, &tv
);
53 printf("%d [%lu.%03lu - %lu.%03lu] %u - %u (%u)\n", i
- 1,
54 from
/ 1000, from
% 1000, to
/ 1000, to
% 1000,
55 afhi
->chunk_table
[i
- 1], afhi
->chunk_table
[i
],
56 afhi
->chunk_table
[i
] - afhi
->chunk_table
[i
- 1]);
60 __noreturn
static void print_help_and_die(void)
62 struct ggo_help h
= DEFINE_GGO_HELP(afh
);
63 int d
= conf
.detailed_help_given
;
64 unsigned flags
= d
? GPH_STANDARD_FLAGS_DETAILED
: GPH_STANDARD_FLAGS
;
66 ggo_print_help(&h
, flags
);
67 printf("supported audio formats: %s\n", AUDIO_FORMAT_HANDLERS
);
72 * The main function of para_afh.
74 * \param argc Usual argument count.
75 * \param argv Usual argument vector.
77 * \return \p EXIT_FAILURE or \p EXIT_SUCCESS.
79 int main(int argc
, char **argv
)
81 int i
, ret
, audio_format_num
, fd
;
82 void *audio_file_data
;
83 size_t audio_file_size
;
86 afh_cmdline_parser(argc
, argv
, &conf
);
87 loglevel
= get_loglevel_by_name(conf
.loglevel_arg
);
88 version_handle_flag("afh", conf
.version_given
);
89 if (conf
.help_given
|| conf
.detailed_help_given
)
93 if (conf
.inputs_num
== 0)
95 for (i
= 0; i
< conf
.inputs_num
; i
++) {
97 ret
= mmap_full_file(conf
.inputs
[i
], O_RDONLY
, &audio_file_data
,
98 &audio_file_size
, &fd
);
100 PARA_ERROR_LOG("failed to mmap \"%s\"\n", conf
.inputs
[i
]);
103 ret
= compute_afhi(conf
.inputs
[i
], audio_file_data
, audio_file_size
,
106 audio_format_num
= ret
;
107 printf("File %d: %s\n", i
+ 1, conf
.inputs
[i
]);
108 print_info(audio_format_num
, &afhi
);
109 if (conf
.chunk_table_given
)
110 print_chunk_table(&afhi
);
115 ret2
= para_munmap(audio_file_data
, audio_file_size
);
116 if (ret2
< 0 && ret
>= 0)
123 PARA_ERROR_LOG("%s\n", para_strerror(-ret
));
124 return ret
< 0? EXIT_FAILURE
: EXIT_SUCCESS
;