StreamReceiver.h
Go to the documentation of this file.
1 /**
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * 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, see <http://www.gnu.org/licenses/>.
17  *
18  * @package TabletTeleoperation::ArmarXObjects::StreamReceiver
19  * @author Mirko Waechter ( mirko dot waechter at kit dot edu )
20  * @date 2013
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #pragma once
26 
27 
30 #include <VisionX/interface/components/StreamProvider.h>
32 
33 extern "C"
34 {
35  class _GstElement;
36  using GstElement = _GstElement;
37 }
38 
39 extern "C" {
40 #include <libavcodec/avcodec.h>
41 #include <libswscale/swscale.h>
42 }
43 
44 namespace armarx
45 {
46 
47 
48  using ImageMap = std::map<std::string, CByteImage*>;
49  /**
50  * @class StreamReceiver
51  * @brief A brief description
52  *
53  * Detailed Description
54  */
56  virtual public armarx::Component,
57  public Stream::StreamListenerInterface
58  {
59  public:
62  {
63  public:
66  {
67  defineOptionalProperty<std::string>("UsedStreamProvider", "StreamProvider", "Names of the StreamProvider that is to be used");
68  // defineOptionalProperty<std::string>("UsedSources", "Camera,Test", "Names of sources that are to be used of the StreamProvider. Seperated by comma, space or tab");
69  }
70  };
71 
72  /**
73  * @see armarx::ManagedIceObject::getDefaultName()
74  */
75  virtual std::string getDefaultName() const
76  {
77  return "StreamReceiver";
78  }
79 
80  /**
81  * @brief getImages retreives the next buffered images for all streams.
82  * @param imagesOut map of already allocated images in correct size
83  */
84  void getImages(std::vector<CByteImage*>& imagesOut);
85 
86  /**
87  * @brief getNumberOfImages can be called after the component was initialized.
88  * @return the number of provided images
89  */
90  int getNumberOfImages();
91 
92 
93  void getImageInformation(int& imageWidth, int& imageHeight, int& imageType);
94 
95 
96  protected:
97  /**
98  * @see armarx::ManagedIceObject::onInitComponent()
99  */
100  virtual void onInitComponent();
101 
102  /**
103  * @see armarx::ManagedIceObject::onConnectComponent()
104  */
105  virtual void onConnectComponent();
106 
107  /**
108  * @see armarx::ManagedIceObject::onDisconnectComponent()
109  */
110  virtual void onDisconnectComponent();
111 
112  /**
113  * @see armarx::ManagedIceObject::onExitComponent()
114  */
115  virtual void onExitComponent();
116 
117 
118  /**
119  * @see PropertyUser::createPropertyDefinitions()
120  */
122  {
126  }
127  private:
128 
129  void receive();
130  void store();
131 
132  class StreamElements;
133  using StreamElementsPtr = std::shared_ptr<StreamElements>;
134  struct StreamElements : Stream::StreamMetaData
135  {
136  public:
137  StreamElements(std::string streamName, int streamID, Stream::StreamProviderPrx streamProvider);
138  GstElement* pipeline;
139  GstElement* appsrc;
140  GstElement* appsink;
141  std::stringstream pipelineString;
142  armarx::Mutex mutex;
143  int fetchedChunks;
144  IceUtil::Time lastFPSCheck;
145  int framesSinceLastFPSCheck;
147  Stream::StreamProviderPrx streamProvider;
148  void receive();
149  int receivedIndex;
150  int realPosition;
151  int streamID;
152 
153  boost::mutex mutexPulling;
154 
155  };
156  using StreamSourceMap = boost::unordered_map<std::string, StreamElementsPtr>;
157  StreamReceiver::StreamElementsPtr getStreamElements(std::string streamName);
158  void getImageFormat(StreamElementsPtr elem, int& height, int& width);
159 
160 
161  Stream::StreamProviderPrx streamProvider;
162  // PeriodicTask<StreamReceiver>::pointer_type taskReceive;
164  StreamSourceMap streamSources;
165 
166 
167  int numberImages;
168 
169  IceUtil::Time start;
170  long transferredBits;
171  // GstElement* appsrc;
172  // GstElement* appsink;
173  // GstElement* pipeline;
174  float bandwidth_kbps;
175  Mutex pipelineMutex;
176  Stream::CodecType codec;
177 
178  IceUtil::Time lastReceiveTimestamp;
179 
180 
181  // StreamListenerInterface interface
182  public:
183  void reportNewStreamData(const Stream::DataChunk& chunk, const Ice::Current&);
184 
185  AVCodec* m_decoder;
186  AVCodecContext* m_decoderContext;
188  AVFrame* m_picture;
189  AVPacket m_packet;
193  };
195 }
196 
armarx::StreamReceiver::onExitComponent
virtual void onExitComponent()
Definition: StreamReceiver.cpp:321
armarx::StreamReceiver::m_got_picture
int m_got_picture
Definition: StreamReceiver.h:187
armarx::StreamReceiver::decodedImageMutex
Mutex decodedImageMutex
Definition: StreamReceiver.h:190
armarx::StreamReceiver::getImageInformation
void getImageInformation(int &imageWidth, int &imageHeight, int &imageType)
Definition: StreamReceiver.cpp:554
armarx::ImageMap
std::map< std::string, CByteImage * > ImageMap
Definition: StreamReceiver.h:48
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
PeriodicTask.h
armarx::StreamReceiver::pCombinedDecodedImage
CByteImage * pCombinedDecodedImage
Definition: StreamReceiver.h:192
armarx::StreamReceiver::getDefaultName
virtual std::string getDefaultName() const
Definition: StreamReceiver.h:75
armarx::StreamReceiver::getImages
void getImages(std::vector< CByteImage * > &imagesOut)
getImages retreives the next buffered images for all streams.
Definition: StreamReceiver.cpp:453
armarx::PeriodicTask::pointer_type
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
Definition: PeriodicTask.h:67
armarx::StreamReceiver::ppDecodedImages
CByteImage ** ppDecodedImages
Definition: StreamReceiver.h:192
IceInternal::Handle< StreamReceiver >
armarx::StreamReceiver::m_decoderContext
AVCodecContext * m_decoderContext
Definition: StreamReceiver.h:186
armarx::StreamReceiver::getNumberOfImages
int getNumberOfImages()
getNumberOfImages can be called after the component was initialized.
Definition: StreamReceiver.cpp:548
armarx::StreamReceiver::StreamReceiverPropertyDefinitions
Definition: StreamReceiver.h:60
armarx::StreamReceiver::streamDecodeMutex
Mutex streamDecodeMutex
Definition: StreamReceiver.h:191
StreamProviderI.h
armarx::StreamReceiver::reportNewStreamData
void reportNewStreamData(const Stream::DataChunk &chunk, const Ice::Current &)
Definition: StreamReceiver.cpp:364
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
armarx::StreamReceiver::onConnectComponent
virtual void onConnectComponent()
Definition: StreamReceiver.cpp:116
armarx::StreamReceiver
A brief description.
Definition: StreamReceiver.h:55
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
GstElement
_GstElement GstElement
Definition: StreamReceiver.h:36
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::StreamReceiver::m_packet
AVPacket m_packet
Definition: StreamReceiver.h:189
armarx::Mutex
boost::mutex Mutex
Definition: Synchronization.h:131
armarx::StreamReceiver::m_picture
AVFrame * m_picture
Definition: StreamReceiver.h:188
armarx::StreamReceiver::m_decoder
AVCodec * m_decoder
Definition: StreamReceiver.h:185
armarx::PeriodicTask
Definition: ArmarXManager.h:70
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
armarx::StreamReceiver::onDisconnectComponent
virtual void onDisconnectComponent()
Definition: StreamReceiver.cpp:236
armarx::StreamReceiver::StreamReceiverPropertyDefinitions::StreamReceiverPropertyDefinitions
StreamReceiverPropertyDefinitions(std::string prefix)
Definition: StreamReceiver.h:64
armarx::StreamReceiver::onInitComponent
virtual void onInitComponent()
Definition: StreamReceiver.cpp:53
armarx::StreamReceiver::createPropertyDefinitions
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions()
Definition: StreamReceiver.h:121
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28