~ubuntu-branches/ubuntu/breezy/kdemultimedia/breezy

« back to all changes in this revision

Viewing changes to akode/lib/auto_sink.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2005-03-24 04:48:58 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050324044858-8ff88o9jxej6ii3d
Tags: 4:3.4.0-0ubuntu3
Add kubuntu_02_hide_arts_menu_entries.diff to hide artsbuilder and artscontrol k-menu entries

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  aKode: Auto-Sink
 
2
 
 
3
    Copyright (C) 2004 Allan Sandfeld Jensen <kde@carewolf.com>
 
4
 
 
5
    This library is free software; you can redistribute it and/or
 
6
    modify it under the terms of the GNU Library General Public
 
7
    License as published by the Free Software Foundation; either
 
8
    version 2 of the License, or (at your option) any later version.
 
9
 
 
10
    This library is distributed in the hope that it will be useful,
 
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
    Library General Public License for more details.
 
14
 
 
15
    You should have received a copy of the GNU Library General Public License
 
16
    along with this library; see the file COPYING.LIB.  If not, write to
 
17
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
18
    Boston, MA 02111-1307, USA.
 
19
*/
 
20
 
 
21
#include "audioframe.h"
 
22
#include "auto_sink.h"
 
23
 
 
24
#include <iostream>
 
25
 
 
26
namespace aKode {
 
27
 
 
28
extern "C" { AutoSinkPlugin auto_sink; }
 
29
 
 
30
struct AutoSink::private_data
 
31
{
 
32
    private_data() : sink(0) {};
 
33
    SinkPluginHandler plugin_handler;
 
34
    Sink* sink;
 
35
 
 
36
    bool tryOpen(const string plugin) {
 
37
        if (plugin_handler.load(plugin)) {
 
38
            sink = plugin_handler.openSink();
 
39
            if (sink) {
 
40
                if (sink->open())
 
41
                    return true;
 
42
                delete sink;
 
43
                sink = 0;
 
44
            }
 
45
            plugin_handler.unload();
 
46
        } else
 
47
            std::cout << "auto_sink: Could not load " << plugin << std::endl;
 
48
        return false;
 
49
    }
 
50
};
 
51
 
 
52
AutoSink::AutoSink()
 
53
{
 
54
    m_data = new private_data;
 
55
}
 
56
 
 
57
AutoSink::~AutoSink()
 
58
{
 
59
    delete m_data;
 
60
}
 
61
 
 
62
bool AutoSink::open()
 
63
{
 
64
    // Try Polypaudio
 
65
    if (m_data->tryOpen("polyp")) return true;
 
66
    // Try Jack
 
67
    if (m_data->tryOpen("jack")) return true;
 
68
    // Try ALSA
 
69
    if (m_data->tryOpen("alsa")) return true;
 
70
    // Try OSS
 
71
    if (m_data->tryOpen("oss")) return true;
 
72
    // Fail
 
73
    return false;
 
74
}
 
75
 
 
76
int AutoSink::setAudioConfiguration(const AudioConfiguration* config)
 
77
{
 
78
    if (!m_data->sink)
 
79
        return -1;
 
80
    else
 
81
        return m_data->sink->setAudioConfiguration(config);
 
82
}
 
83
 
 
84
const AudioConfiguration* AutoSink::audioConfiguration() const
 
85
{
 
86
    if (!m_data->sink)
 
87
        return 0;
 
88
    else
 
89
        return m_data->sink->audioConfiguration();
 
90
}
 
91
 
 
92
bool AutoSink::writeFrame(AudioFrame* frame)
 
93
{
 
94
    if (!m_data->sink)
 
95
        return false;
 
96
    else
 
97
        return m_data->sink->writeFrame(frame);
 
98
}
 
99
 
 
100
} // namespace