gui: Remove pointless error message for invalid command line options.
[paraslash.git] / ogg_afh.c
1 /*
2  * Copyright (C) 2004-2011 Andre Noll <maan@systemlinux.org>
3  *
4  * Licensed under the GPL v2. For licencing details see COPYING.
5  */
6
7 /** \file ogg_afh.c Audio format handler for ogg/vorbis files. */
8
9 #include <vorbis/codec.h>
10 #include <regex.h>
11
12 #include "para.h"
13 #include "afh.h"
14 #include "error.h"
15 #include "string.h"
16 #include "ogg_afh_common.h"
17
18 struct private_vorbis_data {
19         vorbis_info vi;
20         vorbis_comment vc;
21 };
22
23 static int vorbis_packet_callback(ogg_packet *packet, int packet_num,
24                 struct afh_info *afhi, void *private_data)
25 {
26         struct private_vorbis_data *pvd = private_data;
27
28         if (vorbis_synthesis_headerin(&pvd->vi, &pvd->vc, packet) < 0)
29                 return -E_VORBIS;
30         if (packet_num == 0) {
31                 if (pvd->vi.rate == 0)
32                         return -E_VORBIS;
33                 afhi->channels = pvd->vi.channels;
34                 afhi->frequency = pvd->vi.rate;
35                 afhi->bitrate = pvd->vi.bitrate_nominal / 1000;
36                 PARA_DEBUG_LOG("channels: %i, sampling rate: %i, bitrate: %i\n",
37                         afhi->channels, afhi->frequency, afhi->bitrate);
38                 return 1;
39         }
40         if (packet_num == 1)
41                 return 1; /* we also want to have packet #2 */
42         afhi->tags.artist = para_strdup(vorbis_comment_query(&pvd->vc, "artist", 0));
43         afhi->tags.title = para_strdup(vorbis_comment_query(&pvd->vc, "title", 0));
44         afhi->tags.album = para_strdup(vorbis_comment_query(&pvd->vc, "album", 0));
45         afhi->tags.year = para_strdup(vorbis_comment_query(&pvd->vc, "year", 0));
46         afhi->tags.comment = para_strdup(vorbis_comment_query(&pvd->vc, "comment", 0));
47         return 0;
48 }
49
50 static int ogg_vorbis_get_file_info(char *map, size_t numbytes, __a_unused int fd,
51                 struct afh_info *afhi)
52 {
53         int ret;
54         struct private_vorbis_data pvd;
55         struct ogg_afh_callback_info vorbis_callback_info = {
56                 .packet_callback = vorbis_packet_callback,
57                 .private_data = &pvd,
58         };
59
60         vorbis_info_init(&pvd.vi);
61         vorbis_comment_init(&pvd.vc);
62         ret = ogg_get_file_info(map, numbytes, afhi, &vorbis_callback_info);
63         vorbis_info_clear(&pvd.vi);
64         vorbis_comment_clear(&pvd.vc);
65         return ret;
66 }
67
68 static const char* ogg_suffixes[] = {"ogg", NULL};
69
70 /**
71  * The init function of the ogg vorbis audio format handler.
72  *
73  * \param afh Pointer to the struct to initialize.
74  */
75 void ogg_init(struct audio_format_handler *afh)
76 {
77         afh->get_file_info = ogg_vorbis_get_file_info,
78         afh->suffixes = ogg_suffixes;
79 }