Move the get_chunk and the get_header functions from vss.c to afh.c.
[paraslash.git] / afh.c
1 /*
2  * Copyright (C) 2008 Andre Noll <maan@systemlinux.org>
3  *
4  * Licensed under the GPL v2. For licencing details see COPYING.
5  */
6
7 /** \file afh.c Paraslash's standalone audio format handler tool. */
8
9 #include <dirent.h>
10
11 #include "para.h"
12 #include "string.h"
13 #include "afh.cmdline.h"
14 #include "fd.h"
15 #include "afh.h"
16 #include "error.h"
17
18 static struct afh_args_info conf;
19 /** The list of all status items */
20 const char *status_item_list[] = {STATUS_ITEM_ARRAY};
21
22 INIT_AFH_ERRLISTS;
23 INIT_STDERR_LOGGING(conf.loglevel_arg)
24
25 int main(int argc, char **argv)
26 {
27         int i, ret;
28         void *audio_file_data;
29         size_t audio_file_size;
30         struct afh_info afhi;
31
32         afh_cmdline_parser(argc, argv, &conf);
33         HANDLE_VERSION_FLAG("afh", conf);
34         ret = -E_AFH_SYNTAX;
35         if (conf.inputs_num != 1)
36                 goto out;
37         afh_init();
38         ret = mmap_full_file(conf.inputs[0], O_RDONLY, &audio_file_data,
39                 &audio_file_size, NULL);
40         if (ret < 0)
41                 goto out;
42         ret = compute_afhi(conf.inputs[0], audio_file_data, audio_file_size, &afhi);
43         if (ret < 0)
44                 goto out;
45         printf("%s: %dkbit/s\n" /* bitrate */
46                 "%s: %s\n" /* format */
47                 "%s: %dHz\n" /* frequency */
48                 "%s: %d\n" /* channels */
49                 "%s: %lu\n" /* seconds total */
50                 "%s" /* tag info */
51                 "%s: %lu: %lu\n" /* chunk time */
52                 "%s: %lu\n", /* num chunks */
53                 status_item_list[SI_BITRATE], afhi.bitrate,
54                 status_item_list[SI_FORMAT], audio_format_name(ret),
55                 status_item_list[SI_FREQUENCY], afhi.frequency,
56                 status_item_list[SI_CHANNELS], afhi.channels,
57                 status_item_list[SI_SECONDS_TOTAL], afhi.seconds_total,
58                 afhi.info_string,
59                 status_item_list[SI_CHUNK_TIME], (long unsigned)afhi.chunk_tv.tv_sec,
60                         (long unsigned)afhi.chunk_tv.tv_usec,
61                 status_item_list[SI_NUM_CHUNKS], afhi.chunks_total
62         );
63         ret = 1;
64         if (!conf.chunk_table_given)
65                 goto out;
66         printf("chunk_table: ");
67         for (i = 0; i <= afhi.chunks_total; i++)
68                 printf("%u ", afhi.chunk_table[i]);
69         printf("\n");
70         ret = 1;
71 out:
72         if (ret < 0)
73                 PARA_ERROR_LOG("%s\n", para_strerror(-ret));
74         return ret < 0? EXIT_FAILURE : EXIT_SUCCESS;
75 }