summaryrefslogtreecommitdiffstats
path: root/akode/akodeplay/akodeplay.cpp
blob: c10a69eb019b5a1b9c5e92780b1297d04a4e636c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*  aKode-utils: akodeplay

    Copyright (C) 2005 Allan Sandfeld Jensen <kde@carewolf.com>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#include <iostream>

#include "../lib/akodelib.h"
#include "../lib/player.h"
#include "../lib/sink.h"
#include "../lib/decoder.h"

#include <cstdlib>

#ifdef HAVE_GNU_GETOPT
  #include <getopt.h>
#else
  #include <unistd.h>
#endif

using namespace std;
using namespace aKode;

void usage() {
    cout << "Usage: akodeplay [-s sink] [-r resampler] [-d decoder] filenames.." << endl;
}

void list_sinks() {
    cout << "Available sinks:" << endl;
    list<string> sinks = SinkPluginHandler::listSinkPlugins();
    for(list<string>::const_iterator s = sinks.begin(); s != sinks.end(); s++)
        cout << "\t" << *s << endl;
}

void list_decoders() {
    cout << "Available decoders:" << endl;
    list<string> plugins = DecoderPluginHandler::listDecoderPlugins();
    for(list<string>::const_iterator s = plugins.begin(); s != plugins.end(); s++)
        cout << "\t" << *s << endl;
}

#ifdef HAVE_GNU_GETOPT
static struct option longoptions[] = {
    {"resampler", 1, 0, 'r'},
    {"decoder", 1, 0, 'd'},
    {"sink", 1, 0, 's'},
    {0, 0, 0, 0}
};
#endif

int main(int argc, char** argv) {
    const char* resampler_plugin = 0;
    const char* decoder_plugin = 0;
    const char* sink_plugin = 0;
    const char* filename = 0;

    if (argc <= 1) {
        usage();
        exit(1);
    }

    int opt;
#ifdef HAVE_GNU_GETOPT
    while ((opt = getopt_long(argc, argv,  "r:d:s:", longoptions, 0)) != -1)
#else
    while ((opt = getopt(argc, argv,  "r:d:s:")) != -1)
#endif
    {
        switch (opt) {
            case 'r':
                resampler_plugin = ::optarg;
                continue;
            case 'd':
                decoder_plugin = ::optarg;
                continue;
            case 's':
                sink_plugin = ::optarg;
                continue;
            default:
                usage();
                exit(1);
        }
    }

    aKode::Player player;

    if (!sink_plugin) sink_plugin = "auto";

    if (decoder_plugin)
        player.setDecoderPlugin(decoder_plugin);

    if (resampler_plugin)
        player.setResamplerPlugin(resampler_plugin);

    if (!player.open(sink_plugin)) {
        cout << "Could not load sink-plugin: " << sink_plugin << endl;
        list_sinks();
        exit(1);
    }

    while (::optind < argc) {
        filename = argv[::optind++];

        if (!player.load(filename)) {
            cout << "Could not load file: " << filename << endl;
            exit(1);
        }

        player.play();
        player.wait();
        /*
        player.play();
        player.wait();
        player.play();
        player.wait();
*/
        player.unload();
    }
    player.close();

    return 0;
}