aRts audio server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
4.1KB

  1. /*
  2. Copyright (C) 2000 Stefan Westerfeld
  3. stefan@space.twc.de
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public License
  13. along with this library; see the file COPYING.LIB. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. #include "playtofile.h"
  18. #include "kmedia2.h"
  19. #include "debug.h"
  20. #include "dynamicrequest.h"
  21. #include "connect.h"
  22. #include "flowsystem.h"
  23. #include <ctype.h>
  24. #include <iostream>
  25. using namespace Arts;
  26. using namespace std;
  27. /* copypasted from simplesoundserver_impl.cc */
  28. PlayObject createPlayObject(const string& filename)
  29. {
  30. string objectType = "";
  31. /*
  32. * figure out extension (as lowercased letters)
  33. */
  34. string extension = "";
  35. bool extensionok = false;
  36. string::const_reverse_iterator i;
  37. for(i = filename.rbegin(); i != filename.rend() && !extensionok; i++)
  38. {
  39. if(*i == '.')
  40. extensionok = true;
  41. else
  42. extension = (char)tolower(*i) + extension;
  43. }
  44. /*
  45. * query trader for PlayObjects which support this
  46. */
  47. if(extensionok)
  48. {
  49. arts_debug("search playobject, extension = %s",extension.c_str());
  50. TraderQuery query;
  51. query.supports("Interface","Arts::PlayObject");
  52. query.supports("Extension",extension);
  53. vector<TraderOffer> *offers = query.query();
  54. if(!offers->empty())
  55. objectType = offers->front().interfaceName(); // first offer
  56. delete offers;
  57. }
  58. /*
  59. * create a PlayObject and connect it
  60. */
  61. if(!objectType.empty())
  62. {
  63. arts_debug("creating %s to play file", objectType.c_str());
  64. PlayObject result = SubClass(objectType);
  65. if(result.loadMedia(filename))
  66. {
  67. result._node()->start();
  68. return result;
  69. }
  70. else arts_warning("couldn't load file %s", filename.c_str());
  71. }
  72. else arts_warning("file format extension %s unsupported",extension.c_str());
  73. return PlayObject::null();
  74. }
  75. /*
  76. * This is an example for dumping things to a file. It demonstates, that
  77. *
  78. * a) you can use all aRts objects in a non-realtime environment (i.e.
  79. * the time in the PlayObject will pass much faster than the outside
  80. * time when dumping things to a file)
  81. *
  82. * b) complayObjectnents will be dynamically loaded as needed
  83. *
  84. * c) you need to do small tricks to get the signal flow going when you are
  85. * not having audio modules around
  86. *
  87. * d) by implementing aRts modules, you can easily grab and insert data from/to
  88. * arbitary non-aRts sources - for instance, a wave editor might implement
  89. * own modules to get the wave from/to memory
  90. */
  91. int main(int argc, char **argv)
  92. {
  93. Dispatcher d;
  94. if(argc != 2 && argc != 3)
  95. {
  96. cerr << "usage: playtofile <inputfile> [ <outputfile> ]" << endl;
  97. exit(1);
  98. }
  99. PlayObject playObject = createPlayObject(argv[1]);
  100. if(playObject.isNull())
  101. {
  102. cerr << "can't read inputfile " << argv[1] << endl;
  103. exit(1);
  104. }
  105. playObject.play();
  106. PlayToFile playToFile;
  107. if(argc == 3) playToFile.filename(argv[2]);
  108. connect(playObject, "left", playToFile,"left");
  109. connect(playObject, "right", playToFile,"right");
  110. // <ignore the following lines>
  111. // special case when using mpeglib, do tell it not to block (internal
  112. // interface) - we also put an usleep here to ensure that the threads
  113. // and everything is fully initialized as soon as we start
  114. usleep(100000);
  115. if(playObject._base()->_isCompatibleWith("DecoderBaseObject"))
  116. if(!DynamicRequest(playObject).method("_set_blocking").param(true).invoke())
  117. cerr << "mpeglib, and blocking attribute can't be changed?" << endl;
  118. // </ignore>
  119. playToFile.start();
  120. while(playObject.state() != posIdle)
  121. playToFile.goOn();
  122. return 0;
  123. }