PageRenderTime 67ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/Gear.cpp

https://github.com/sofian/spike-gstreamer-dataflow
C++ | 197 lines | 115 code | 33 blank | 49 comment | 23 complexity | eccfee761e2e0e7484e0801dfeb9abef MD5 | raw file
  1. /* Gear.cpp
  2. * Copyright (C) 2004 Mathieu Guindon, Julien Keable
  3. * This file is part of Drone.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program 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
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. #include "Gear.h"
  20. #include "Plug.h"
  21. #include <algorithm>
  22. Gear::Gear(GstElement* element) :
  23. _ready(false),
  24. _element(element)
  25. {
  26. ASSERT_ERROR( element );
  27. GstIterator* it;
  28. GstIteratorResult result = GST_ITERATOR_OK;
  29. GValue value = G_VALUE_INIT;
  30. it = gst_element_iterate_sink_pads(_element);
  31. while ( (result = gst_iterator_next(it, &value)) == GST_ITERATOR_OK)
  32. {
  33. GstPad* pad = GST_PAD_CAST(g_value_peek_pointer(&value));
  34. std::cout << gst_pad_get_name(pad) << std::endl;
  35. addPlug(new PlugIn<AbstractType>(pad, this, gst_pad_get_name(pad), true, new AbstractType()));
  36. gst_object_unref(pad);
  37. g_value_unset(&value);
  38. }
  39. gst_iterator_free(it);
  40. it = gst_element_iterate_src_pads(_element);
  41. while ( (result = gst_iterator_next(it, &value)) == GST_ITERATOR_OK)
  42. {
  43. GstPad* pad = GST_PAD_CAST(g_value_peek_pointer(&value));
  44. std::cout << gst_pad_get_name(pad) << std::endl;
  45. addPlug(new PlugOut<AbstractType>(pad, this, gst_pad_get_name(pad), true, new AbstractType()));
  46. gst_object_unref(pad);
  47. g_value_unset(&value);
  48. }
  49. gst_iterator_free(it);
  50. gst_object_ref(GST_OBJECT(_element));
  51. }
  52. Gear::~Gear()
  53. {
  54. for (std::list<AbstractPlug*>::iterator it=_plugs.begin(); it != _plugs.end(); ++it)
  55. delete (*it);
  56. gst_object_unref(GST_OBJECT(_element));
  57. }
  58. void Gear::prePlay()
  59. {
  60. internalPrePlay();
  61. }
  62. void Gear::postPlay()
  63. {
  64. internalPostPlay();
  65. }
  66. void Gear::init()
  67. {
  68. // std::cout << "__________________________________________" << std::endl;
  69. // std::cout << _type << std::endl;
  70. // std::cout << "------------------------------------------" << std::endl;
  71. for (std::list<AbstractPlug*>::iterator it=_plugs.begin(); it != _plugs.end(); ++it)
  72. (*it)->init();
  73. //call the virtual method
  74. internalInit();
  75. }
  76. /**
  77. * Calls the destructor for the plug and remove it
  78. * from the gear plugs
  79. *
  80. * @param plug the plug to delete
  81. */
  82. void Gear::deletePlug(AbstractPlug *plug)
  83. {
  84. delete plug;
  85. _plugs.remove(plug);
  86. }
  87. /**
  88. * Adds the specified AbstractPlug to the Gear.
  89. * This method will fail if a plug with the same name already
  90. * exist for this gear.
  91. *
  92. * @param plug the plug to add
  93. *
  94. * @return Success : pointer on the specified plug
  95. * Error : null
  96. * @see AbstractPlug
  97. */
  98. AbstractPlug* Gear::addPlug(AbstractPlug* plug)
  99. {
  100. if (!plug)
  101. return NULL;
  102. // if (!isPlugNameUnique(plug->name()))
  103. // return NULL;
  104. /*
  105. //if plug is input, add only plug for main type
  106. if (plug->inOut()==IN)
  107. _plugs.push_back(plug);
  108. else
  109. //add main plug and plugs for its subType
  110. addPlugAndSubPlugs(plug,0);
  111. */
  112. _plugs.push_back(plug);
  113. return plug;
  114. }
  115. void Gear::getInputs(std::list<AbstractPlug*> &inputs) const
  116. {
  117. inputs.clear();
  118. for (std::list<AbstractPlug*>::const_iterator it=_plugs.begin(); it != _plugs.end(); ++it)
  119. {
  120. if ((*it)->inOut() == IN )
  121. inputs.push_back(*it);
  122. }
  123. }
  124. void Gear::getOutputs(std::list<AbstractPlug*> &outputs) const
  125. {
  126. outputs.clear();
  127. for (std::list<AbstractPlug*>::const_iterator it=_plugs.begin(); it != _plugs.end(); ++it)
  128. {
  129. if ((*it)->inOut() == OUT)
  130. outputs.push_back(*it);
  131. }
  132. }
  133. AbstractPlug* Gear::getInput(std::string name) const
  134. {
  135. std::list<AbstractPlug*> inputs;
  136. getInputs(inputs);
  137. int (*pf)(int)=tolower;
  138. std::string nameAlower=name;
  139. transform(nameAlower.begin(), nameAlower.end(), nameAlower.begin(), pf);
  140. for (std::list<AbstractPlug*>::const_iterator it = inputs.begin();it!=inputs.end();++it)
  141. {
  142. std::string nameBlower=(*it)->name();
  143. transform(nameBlower.begin(), nameBlower.end(), nameBlower.begin(), pf);
  144. if (nameAlower == nameBlower)
  145. return(*it);
  146. }
  147. return NULL;
  148. }
  149. AbstractPlug* Gear::getOutput(std::string name) const
  150. {
  151. std::list<AbstractPlug*> outputs;
  152. getOutputs(outputs);
  153. int (*pf)(int)=tolower;
  154. std::string nameAlower=name;
  155. transform(nameAlower.begin(), nameAlower.end(), nameAlower.begin(), pf);
  156. for (std::list<AbstractPlug*>::const_iterator it = outputs.begin();it!=outputs.end();++it)
  157. {
  158. std::string nameBlower=(*it)->name();
  159. transform(nameBlower.begin(), nameBlower.end(), nameBlower.begin(), pf);
  160. if (nameAlower == nameBlower)
  161. return(*it);
  162. }
  163. return NULL;
  164. }