25 #include "flowsystem.h"
26 #include "audiosubsys.h"
27 #include "dynamicrequest.h"
28 #include "kdatarequest_impl.h"
29 #include "kioinputstream_impl.h"
30 #include "kaudioconverter.moc"
39 #include <kmimetype.h>
40 #include <tdeapplication.h>
44 KAudioConverter::KAudioConverter()
50 KAudioConverter::~KAudioConverter()
55 bool KAudioConverter::setup(
int samplingRate)
57 string backupAudioIO = Arts::AudioSubSystem::the()->audioIO();
58 int backupSamplingRate = Arts::AudioSubSystem::the()->samplingRate();
60 Arts::AudioSubSystem::the()->audioIO(
"null");
61 Arts::AudioSubSystem::the()->samplingRate(samplingRate);
63 if(!Arts::AudioSubSystem::the()->
open())
65 Arts::AudioSubSystem::the()->audioIO(backupAudioIO);
66 Arts::AudioSubSystem::the()->samplingRate(backupSamplingRate);
74 void KAudioConverter::slotMimeType(
const TQString &mimeType)
76 m_mimeType = mimeType;
80 void KAudioConverter::requestPlayObject(
const KURL &url)
82 string queryInterface =
"Arts::PlayObject";
84 Arts::TDEIOInputStream inputStream;
88 Arts::TDEIOInputStream_impl *inputStreamImpl =
new Arts::TDEIOInputStream_impl();
89 inputStream = Arts::TDEIOInputStream::_from_base(inputStreamImpl);
91 TQObject::connect(inputStreamImpl, TQ_SIGNAL(mimeTypeFound(
const TQString &)), TQ_SLOT(slotMimeType(
const TQString &)));
93 inputStream.openURL(url.
url().latin1());
94 inputStream.streamStart();
99 queryInterface =
"Arts::StreamPlayObject";
103 KMimeType::Ptr mimetype = KMimeType::findByURL(url);
104 m_mimeType = mimetype->name();
107 Arts::TraderQuery query;
108 query.supports(
"Interface", queryInterface);
109 query.supports(
"MimeType",
string(m_mimeType.latin1()));
113 vector<Arts::TraderOffer> *offers = query.query();
115 objectType = offers->front().interfaceName();
119 if(objectType.empty())
127 Arts::StreamPlayObject result = Arts::SubClass(objectType);
128 result.streamMedia(inputStream);
129 result._node()->start();
131 m_incoming =
new KPlayObject(result,
true);
135 Arts::PlayObject result = Arts::SubClass(objectType);
137 if(result.loadMedia(
string(TQFile::encodeName(url.
path()))))
139 result._node()->start();
140 m_incoming =
new KPlayObject(result,
false);
147 void KAudioConverter::start()
149 if(m_started || !m_incoming)
154 emit rawStreamStart();
158 Arts::KDataRequest_impl *requestImpl =
new Arts::KDataRequest_impl();
159 m_request = Arts::KDataRequest::_from_base(requestImpl);
161 Arts::connect(m_incoming->object(),
"left", m_request,
"left");
162 Arts::connect(m_incoming->object(),
"right", m_request,
"right");
164 TQObject::connect(requestImpl, TQ_SIGNAL(newBlockSize(
long)), TQ_SIGNAL(newBlockSize(
long)));
165 TQObject::connect(requestImpl, TQ_SIGNAL(newBlockPointer(
long)), TQ_SIGNAL(newBlockPointer(
long)));
166 TQObject::connect(requestImpl, TQ_SIGNAL(newData()), TQ_SIGNAL(newData()));
171 if(m_incoming->object()._base()->_isCompatibleWith(
"DecoderBaseObject"))
172 if(!Arts::DynamicRequest(m_incoming->object()).method(
"_set_blocking").param(
true).invoke())
173 cerr <<
"mpeglib, and blocking attribute can't be changed?" <<
endl;
181 while(m_incoming->state() != Arts::posIdle)
187 void KAudioConverter::stop()
189 if(!m_started || !m_incoming)
193 m_request.streamEnd();
197 emit rawStreamFinished();
TQString url(int _trailing=0, int encoding_hint=0) const
kndbgstream & endl(kndbgstream &s)
const TDEShortcut & open()