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
32#include <VisionX/interface/components/StreamProvider.h>
33
34extern "C"
35{
36 class _GstElement;
37 using GstElement = _GstElement;
38}
39
40extern "C"
41{
42#include <libavcodec/avcodec.h>
43#include <libswscale/swscale.h>
44}
45
46namespace armarx
47{
48
49
50 using ImageMap = std::map<std::string, CByteImage*>;
51
52 /**
53 * @class StreamReceiver
54 * @brief A brief description
55 *
56 * Detailed Description
57 */
58 class StreamReceiver : virtual public armarx::Component, public Stream::StreamListenerInterface
59 {
60 public:
62 {
63 public:
66 {
68 "UsedStreamProvider",
69 "StreamProvider",
70 "Names of the StreamProvider that is to be used");
71 // defineOptionalProperty<std::string>("UsedSources", "Camera,Test", "Names of sources that are to be used of the StreamProvider. Seperated by comma, space or tab");
72 }
73 };
74
75 /**
76 * @see armarx::ManagedIceObject::getDefaultName()
77 */
78 virtual std::string
80 {
81 return "StreamReceiver";
82 }
83
84 /**
85 * @brief getImages retreives the next buffered images for all streams.
86 * @param imagesOut map of already allocated images in correct size
87 */
88 void getImages(std::vector<CByteImage*>& imagesOut);
89
90 /**
91 * @brief getNumberOfImages can be called after the component was initialized.
92 * @return the number of provided images
93 */
95
96
97 void getImageInformation(int& imageWidth, int& imageHeight, int& imageType);
98
99
100 protected:
101 /**
102 * @see armarx::ManagedIceObject::onInitComponent()
103 */
104 virtual void onInitComponent();
105
106 /**
107 * @see armarx::ManagedIceObject::onConnectComponent()
108 */
109 virtual void onConnectComponent();
110
111 /**
112 * @see armarx::ManagedIceObject::onDisconnectComponent()
113 */
114 virtual void onDisconnectComponent();
115
116 /**
117 * @see armarx::ManagedIceObject::onExitComponent()
118 */
119 virtual void onExitComponent();
120
121 /**
122 * @see PropertyUser::createPropertyDefinitions()
123 */
130
131 private:
132 void receive();
133 void store();
134
135 class StreamElements;
136 using StreamElementsPtr = std::shared_ptr<StreamElements>;
137
138 struct StreamElements : Stream::StreamMetaData
139 {
140 public:
141 StreamElements(std::string streamName,
142 int streamID,
143 Stream::StreamProviderPrx streamProvider);
144 GstElement* pipeline;
145 GstElement* appsrc;
146 GstElement* appsink;
147 std::stringstream pipelineString;
148 armarx::Mutex mutex;
149 int fetchedChunks;
150 IceUtil::Time lastFPSCheck;
151 int framesSinceLastFPSCheck;
153 Stream::StreamProviderPrx streamProvider;
154 void receive();
155 int receivedIndex;
156 int realPosition;
157 int streamID;
158
159 boost::mutex mutexPulling;
160 };
161
162 using StreamSourceMap = boost::unordered_map<std::string, StreamElementsPtr>;
163 StreamReceiver::StreamElementsPtr getStreamElements(std::string streamName);
164 void getImageFormat(StreamElementsPtr elem, int& height, int& width);
165
166
167 Stream::StreamProviderPrx streamProvider;
168 // PeriodicTask<StreamReceiver>::pointer_type taskReceive;
170 StreamSourceMap streamSources;
171
172
173 int numberImages;
174
175 IceUtil::Time start;
176 long transferredBits;
177 // GstElement* appsrc;
178 // GstElement* appsink;
179 // GstElement* pipeline;
180 float bandwidth_kbps;
181 Mutex pipelineMutex;
182 Stream::CodecType codec;
183
184 IceUtil::Time lastReceiveTimestamp;
185
186
187 // StreamListenerInterface interface
188 public:
189 void reportNewStreamData(const Stream::DataChunk& chunk, const Ice::Current&);
190
191 AVCodec* m_decoder;
192 AVCodecContext* m_decoderContext;
194 AVFrame* m_picture;
195 AVPacket m_packet;
199 };
200
202} // namespace armarx
_GstElement GstElement
Default component property definition container.
Definition Component.h:70
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition Component.h:94
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
A brief description.
void getImageInformation(int &imageWidth, int &imageHeight, int &imageType)
AVCodecContext * m_decoderContext
CByteImage ** ppDecodedImages
void getImages(std::vector< CByteImage * > &imagesOut)
getImages retreives the next buffered images for all streams.
virtual void onInitComponent()
void reportNewStreamData(const Stream::DataChunk &chunk, const Ice::Current &)
virtual void onDisconnectComponent()
virtual void onConnectComponent()
virtual void onExitComponent()
CByteImage * pCombinedDecodedImage
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions()
int getNumberOfImages()
getNumberOfImages can be called after the component was initialized.
virtual std::string getDefaultName() const
boost::mutex Mutex
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::map< std::string, CByteImage * > ImageMap
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
IceInternal::Handle< StreamReceiver > StreamReceiverPtr