| 1 | /* This file is part of the KDE project.
|
|---|
| 2 |
|
|---|
| 3 | Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 |
|
|---|
| 5 | This library is free software: you can redistribute it and/or modify
|
|---|
| 6 | it under the terms of the GNU Lesser General Public License as published by
|
|---|
| 7 | the Free Software Foundation, either version 2.1 or 3 of the License.
|
|---|
| 8 |
|
|---|
| 9 | This library is distributed in the hope that it will be useful,
|
|---|
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 12 | GNU Lesser General Public License for more details.
|
|---|
| 13 |
|
|---|
| 14 | You should have received a copy of the GNU Lesser General Public License
|
|---|
| 15 | along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 16 | */
|
|---|
| 17 |
|
|---|
| 18 | #include "audioconnection.h"
|
|---|
| 19 | #include "medianode.h"
|
|---|
| 20 | #include "audionode.h"
|
|---|
| 21 | #include "audiograph.h"
|
|---|
| 22 |
|
|---|
| 23 | QT_BEGIN_NAMESPACE
|
|---|
| 24 |
|
|---|
| 25 | namespace Phonon
|
|---|
| 26 | {
|
|---|
| 27 | namespace QT7
|
|---|
| 28 | {
|
|---|
| 29 |
|
|---|
| 30 | AudioConnection::AudioConnection()
|
|---|
| 31 | : m_source(0), m_sourceAudioNode(0), m_sourceOutputBus(0),
|
|---|
| 32 | m_sink(0), m_sinkAudioNode(0), m_sinkInputBus(0),
|
|---|
| 33 | m_sourceChannelLayout(0), m_sinkChannelLayout(0),
|
|---|
| 34 | m_hasSourceSpecification(false), m_hasSinkSpecification(false), m_connected(false)
|
|---|
| 35 | {}
|
|---|
| 36 |
|
|---|
| 37 | AudioConnection::AudioConnection(MediaNode *source, int output, MediaNode *sink, int input)
|
|---|
| 38 | : m_source(source), m_sourceAudioNode(source->m_audioNode), m_sourceOutputBus(output),
|
|---|
| 39 | m_sink(sink), m_sinkAudioNode(sink->m_audioNode), m_sinkInputBus(input),
|
|---|
| 40 | m_sourceChannelLayout(0), m_sinkChannelLayout(0),
|
|---|
| 41 | m_hasSourceSpecification(false), m_hasSinkSpecification(false), m_connected(false)
|
|---|
| 42 | {}
|
|---|
| 43 |
|
|---|
| 44 | AudioConnection::AudioConnection(MediaNode *sink)
|
|---|
| 45 | : m_source(0), m_sourceAudioNode(0), m_sourceOutputBus(0),
|
|---|
| 46 | m_sink(sink), m_sinkAudioNode(sink->m_audioNode), m_sinkInputBus(0),
|
|---|
| 47 | m_sourceChannelLayout(0), m_sinkChannelLayout(0), m_connected(false)
|
|---|
| 48 | {}
|
|---|
| 49 |
|
|---|
| 50 | AudioConnection::AudioConnection(AudioNode *source, int output, AudioNode *sink, int input)
|
|---|
| 51 | : m_source(0), m_sourceAudioNode(source), m_sourceOutputBus(output),
|
|---|
| 52 | m_sink(0), m_sinkAudioNode(sink), m_sinkInputBus(input),
|
|---|
| 53 | m_sourceChannelLayout(0), m_sinkChannelLayout(0),
|
|---|
| 54 | m_hasSourceSpecification(false), m_hasSinkSpecification(false), m_connected(false)
|
|---|
| 55 | {}
|
|---|
| 56 |
|
|---|
| 57 | AudioConnection::AudioConnection(AudioNode *sink)
|
|---|
| 58 | : m_source(0), m_sourceAudioNode(0), m_sourceOutputBus(0),
|
|---|
| 59 | m_sink(0), m_sinkAudioNode(sink), m_sinkInputBus(0),
|
|---|
| 60 | m_sourceChannelLayout(0), m_sinkChannelLayout(0), m_connected(false)
|
|---|
| 61 | {}
|
|---|
| 62 |
|
|---|
| 63 | AudioConnection::~AudioConnection()
|
|---|
| 64 | {
|
|---|
| 65 | freeMemoryAllocations();
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | void AudioConnection::freeMemoryAllocations()
|
|---|
| 69 | {
|
|---|
| 70 | if (m_sinkChannelLayout && m_sourceChannelLayout != m_sinkChannelLayout)
|
|---|
| 71 | free(m_sinkChannelLayout);
|
|---|
| 72 | if (m_sourceChannelLayout)
|
|---|
| 73 | free(m_sourceChannelLayout);
|
|---|
| 74 | m_sinkChannelLayout = 0;
|
|---|
| 75 | m_sourceChannelLayout = 0;
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | bool AudioConnection::updateStreamSpecification()
|
|---|
| 79 | {
|
|---|
| 80 | m_hasSourceSpecification = false;
|
|---|
| 81 | m_hasSinkSpecification = false;
|
|---|
| 82 | freeMemoryAllocations();
|
|---|
| 83 |
|
|---|
| 84 | bool updateOk;
|
|---|
| 85 | if (m_sourceAudioNode){
|
|---|
| 86 | updateOk = m_sourceAudioNode->fillInStreamSpecification(this, AudioNode::Source);
|
|---|
| 87 | if (!updateOk)
|
|---|
| 88 | return false;
|
|---|
| 89 | updateOk = m_sourceAudioNode->setStreamSpecification(this, AudioNode::Source);
|
|---|
| 90 | if (!updateOk)
|
|---|
| 91 | return false;
|
|---|
| 92 | }
|
|---|
| 93 | updateOk = m_sinkAudioNode->fillInStreamSpecification(this, AudioNode::Sink);
|
|---|
| 94 | if (!updateOk)
|
|---|
| 95 | return false;
|
|---|
| 96 | updateOk = m_sinkAudioNode->setStreamSpecification(this, AudioNode::Sink);
|
|---|
| 97 | if (!updateOk)
|
|---|
| 98 | return false;
|
|---|
| 99 | return true;
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | bool AudioConnection::connect(AudioGraph *graph)
|
|---|
| 103 | {
|
|---|
| 104 | if (m_connected || !m_sourceAudioNode)
|
|---|
| 105 | return true;
|
|---|
| 106 |
|
|---|
| 107 | DEBUG_AUDIO_GRAPH("Connection" << int(this) << "connect"
|
|---|
| 108 | << int(m_sourceAudioNode) << m_sourceOutputBus << "->"
|
|---|
| 109 | << int(m_sinkAudioNode) << m_sinkInputBus)
|
|---|
| 110 |
|
|---|
| 111 | AUNode sourceOut = m_sourceAudioNode->getOutputAUNode();
|
|---|
| 112 | AUNode sinkIn = m_sinkAudioNode->getInputAUNode();
|
|---|
| 113 | OSStatus err = AUGraphConnectNodeInput(graph->audioGraphRef(), sourceOut, m_sourceOutputBus, sinkIn, m_sinkInputBus);
|
|---|
| 114 | m_connected = (err == noErr) ? true : false;
|
|---|
| 115 | return m_connected;
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | bool AudioConnection::disconnect(AudioGraph *graph)
|
|---|
| 119 | {
|
|---|
| 120 | if (!m_connected || !m_sourceAudioNode)
|
|---|
| 121 | return true;
|
|---|
| 122 |
|
|---|
| 123 | DEBUG_AUDIO_GRAPH("Connection" << int(this) << "disconnect"
|
|---|
| 124 | << int(m_sourceAudioNode) << m_sourceOutputBus << "->"
|
|---|
| 125 | << int(m_sinkAudioNode) << m_sinkInputBus)
|
|---|
| 126 |
|
|---|
| 127 | AUNode sinkIn = m_sinkAudioNode->getInputAUNode();
|
|---|
| 128 | AUGraphDisconnectNodeInput(graph->audioGraphRef(), sinkIn, m_sinkInputBus);
|
|---|
| 129 | m_connected = false;
|
|---|
| 130 | return true;
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | void AudioConnection::invalidate()
|
|---|
| 134 | {
|
|---|
| 135 | m_connected = false;
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | bool AudioConnection::isBetween(MediaNode *source, MediaNode *sink){
|
|---|
| 139 | return (source == m_source) && (sink == m_sink);
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | bool AudioConnection::isValid(){
|
|---|
| 143 | return (m_sourceAudioNode != 0);
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | bool AudioConnection::isSinkOnly(){
|
|---|
| 147 | return (m_sourceAudioNode == 0) && (m_sinkAudioNode != 0);
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | }} //namespace Phonon::QT7
|
|---|
| 151 |
|
|---|
| 152 | QT_END_NAMESPACE
|
|---|