• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • arts
 

arts

  • arts
  • kde
kaudioconverter.cpp
1  /*
2 
3  Copyright (C) 2002 Nikolas Zimmermann <wildfox@kde.org>
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., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 
20  */
21 
22 #include "config.h"
23 #include "artskde.h"
24 #include "connect.h"
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"
31 
32 #include <iostream>
33 
34 #include <tqfile.h>
35 #include <tqtimer.h>
36 
37 #include <kurl.h>
38 #include <kdebug.h>
39 #include <kmimetype.h>
40 #include <tdeapplication.h>
41 
42 using namespace std;
43 
44 KAudioConverter::KAudioConverter()
45 {
46  m_incoming = 0;
47  m_started = false;
48 }
49 
50 KAudioConverter::~KAudioConverter()
51 {
52  delete m_incoming;
53 }
54 
55 bool KAudioConverter::setup(int samplingRate)
56 {
57  string backupAudioIO = Arts::AudioSubSystem::the()->audioIO();
58  int backupSamplingRate = Arts::AudioSubSystem::the()->samplingRate();
59 
60  Arts::AudioSubSystem::the()->audioIO("null");
61  Arts::AudioSubSystem::the()->samplingRate(samplingRate);
62 
63  if(!Arts::AudioSubSystem::the()->open())
64  {
65  Arts::AudioSubSystem::the()->audioIO(backupAudioIO);
66  Arts::AudioSubSystem::the()->samplingRate(backupSamplingRate);
67 
68  return false;
69  }
70 
71  return true;
72 }
73 
74 void KAudioConverter::slotMimeType(const TQString &mimeType)
75 {
76  m_mimeType = mimeType;
77  kapp->exit_loop();
78 }
79 
80 void KAudioConverter::requestPlayObject(const KURL &url)
81 {
82  string queryInterface = "Arts::PlayObject";
83 
84  Arts::TDEIOInputStream inputStream;
85 
86  if(!url.isLocalFile())
87  {
88  Arts::TDEIOInputStream_impl *inputStreamImpl = new Arts::TDEIOInputStream_impl();
89  inputStream = Arts::TDEIOInputStream::_from_base(inputStreamImpl);
90 
91  TQObject::connect(inputStreamImpl, TQT_SIGNAL(mimeTypeFound(const TQString &)), TQT_SLOT(slotMimeType(const TQString &)));
92 
93  inputStream.openURL(url.url().latin1());
94  inputStream.streamStart();
95 
96  // ugly hacks.. :/
97  kapp->enter_loop();
98 
99  queryInterface = "Arts::StreamPlayObject";
100  }
101  else
102  {
103  KMimeType::Ptr mimetype = KMimeType::findByURL(url);
104  m_mimeType = mimetype->name();
105  }
106 
107  Arts::TraderQuery query;
108  query.supports("Interface", queryInterface);
109  query.supports("MimeType", string(m_mimeType.latin1()));
110 
111  string objectType;
112 
113  vector<Arts::TraderOffer> *offers = query.query();
114  if(!offers->empty())
115  objectType = offers->front().interfaceName(); // first offer
116 
117  delete offers;
118 
119  if(objectType.empty())
120  {
121  m_incoming = 0;
122  return;
123  }
124 
125  if(!url.isLocalFile())
126  {
127  Arts::StreamPlayObject result = Arts::SubClass(objectType);
128  result.streamMedia(inputStream);
129  result._node()->start();
130 
131  m_incoming = new KPlayObject(result, true);
132  }
133  else
134  {
135  Arts::PlayObject result = Arts::SubClass(objectType);
136 
137  if(result.loadMedia(string(TQFile::encodeName(url.path()))))
138  {
139  result._node()->start();
140  m_incoming = new KPlayObject(result, false);
141  }
142  else
143  m_incoming = 0;
144  }
145 }
146 
147 void KAudioConverter::start()
148 {
149  if(m_started || !m_incoming)
150  return;
151 
152  m_started = true;
153 
154  emit rawStreamStart();
155 
156  m_incoming->play();
157 
158  Arts::KDataRequest_impl *requestImpl = new Arts::KDataRequest_impl();
159  m_request = Arts::KDataRequest::_from_base(requestImpl);
160 
161  Arts::connect(m_incoming->object(), "left", m_request, "left");
162  Arts::connect(m_incoming->object(), "right", m_request, "right");
163 
164  TQObject::connect(requestImpl, TQT_SIGNAL(newBlockSize(long)), TQT_SIGNAL(newBlockSize(long)));
165  TQObject::connect(requestImpl, TQT_SIGNAL(newBlockPointer(long)), TQT_SIGNAL(newBlockPointer(long)));
166  TQObject::connect(requestImpl, TQT_SIGNAL(newData()), TQT_SIGNAL(newData()));
167 
168  // Special mpeglib case
169  // TODO: needed at all??
170  usleep(100000);
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;
174 
175  m_request.start();
176 
177  // TODO: Maybe do this async, using TQTimer::singleShot
178  // But jowenn i think jowenn is right -> this would
179  // lead to problems in slotNewData() when accessing the data
180  // (could already be overwritten...)
181  while(m_incoming->state() != Arts::posIdle)
182  m_request.goOn();
183 
184  stop();
185 }
186 
187 void KAudioConverter::stop()
188 {
189  if(!m_started || !m_incoming)
190  return;
191 
192  m_incoming->halt();
193  m_request.streamEnd();
194 
195  m_started = false;
196 
197  emit rawStreamFinished();
198 }
KURL
std
TDEStdAccel::open
const TDEShortcut & open()
KURL::isLocalFile
bool isLocalFile() const
KURL::url
TQString url(int _trailing=0, int encoding_hint=0) const
KURL::path
TQString path() const
endl
kndbgstream & endl(kndbgstream &s)

arts

Skip menu "arts"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

arts

Skip menu "arts"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for arts by doxygen 1.8.8
This website is maintained by Timothy Pearson.