StreamProviderI.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
19  * @author
20  * @date
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #pragma once
25 
26 #include <string>
27 
32 
34 #include <VisionX/interface/components/StreamProvider.h>
35 
36 #include <Image/ByteImage.h>
37 
38 extern "C"
39 {
40 #include <libswscale/swscale.h>
41 #include <x264.h>
42 }
43 
44 
45 #define NUMBER_OF_COMPRESSIONRATES \
46  3 //should hold the number of compression rates (the compression rates are defined in the enum ::Stream::CompressionRate)
47 
48 namespace Stream
49 {
50  /**
51  * This class realizes the StreamProviderImageProcessorInterface-SliceInterface and is a subclass of visionx::ImageProcessor.
52  * On tablet-side the methods of this class can be called through an Ice-Proxy.
53  */
55  public StreamProviderImageProcessorInterface,
57  {
58 
59  public:
61  {
62  public:
64  };
65 
66  /// @see PropertyUser::createPropertyDefinitions()
69  {
72  }
73 
75 
76  void stopCapture(const ::Ice::Current& = Ice::emptyCurrent) override;
77  /** starts the capture for the given source */
78  bool startCapture(const ::Ice::Current& = Ice::emptyCurrent) override;
79 
80  void getImageInformation(int& imageWidth,
81  int& imageHeight,
82  int& imageType,
83  const Ice::Current& c = Ice::emptyCurrent) override;
84  int getNumberOfImages(const ::Ice::Current& = Ice::emptyCurrent) override;
85  void setCompressionRate(::Stream::CompressionRate = COMPRESSIONHIGH,
86  const ::Ice::Current& = Ice::emptyCurrent) override;
87  CodecType getCodecType(const Ice::Current&) override;
88 
89 
90  /* Inherited from ImageProcessor. */
91  void onInitImageProcessor() override;
92  void onConnectImageProcessor() override;
93  virtual void onDisConnectImageProcessor();
94  void onExitImageProcessor() override;
95  void process() override;
96 
97  /// Executes a single cycle of the encoding process.
98  void step(const Ice::Current& = Ice::emptyCurrent);
99 
100 
101  std::string getDefaultName() const override;
102 
103  void onStartRecording(const ::Ice::Current& = Ice::emptyCurrent) override;
104 
105 
106  private:
107  // Pushes the given image into the given appsrc, helper method for pushNewImages().
108  void
109  calculateFps(); // Calcuates the current fps for the streamSources (as (80% old:20% new) weighted medium).
111  fpsCalculator; // Task calcualting the fps.
112 
113 
114  bool capturing = false;
115  std::string imageProviderProxyName;
116  visionx::ImageProviderInterfacePrx imageProviderProxy;
117  visionx::ImageFormatInfo imageFormat;
118  int numberImages;
119  int imgWidth;
120  int imgHeight;
121  int imgType;
122  int encodedImgHeight;
123 
124  CByteImage **ppInputImages, *pImageForEncoder;
125  using CByteImagePtr = std::shared_ptr<CByteImage>;
126  using ImageContainer = std::vector<CByteImagePtr>;
127 
128  x264_param_t param;
129  float fps;
130  x264_t* encoder;
131  x264_picture_t pic_in, pic_out;
132  SwsContext* convertCtx;
133  int frameCounter = 0;
134  Stream::StreamListenerInterfacePrx listener;
135  };
136 
138 } // namespace Stream
Stream::StreamProviderI::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: StreamProviderI.cpp:249
Stream::StreamProviderI::stopCapture
void stopCapture(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: StreamProviderI.cpp:283
visionx::ImageProcessor
The ImageProcessor class provides an interface for access to ImageProviders via Ice and shared memory...
Definition: ImageProcessor.h:98
Stream::StreamProviderI::getImageInformation
void getImageInformation(int &imageWidth, int &imageHeight, int &imageType, const Ice::Current &c=Ice::emptyCurrent) override
Definition: StreamProviderI.cpp:324
Stream::StreamProviderI::onDisConnectImageProcessor
virtual void onDisConnectImageProcessor()
Is called if a dependency of the object got lost (crash, network error, stopped, ....
Definition: StreamProviderI.cpp:166
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
PeriodicTask.h
Stream::StreamProviderI::onStartRecording
void onStartRecording(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: StreamProviderI.cpp:347
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
Stream::StreamProviderI::step
void step(const Ice::Current &=Ice::emptyCurrent)
Executes a single cycle of the encoding process.
RunningTask.h
IceInternal::Handle
Definition: forward_declarations.h:8
Stream::StreamProviderI::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: StreamProviderI.h:68
Stream::StreamProviderI::onInitImageProcessor
void onInitImageProcessor() override
Is called once initialization of the ManagedIceObject is done.
Definition: StreamProviderI.cpp:77
Stream::StreamProviderI::startCapture
bool startCapture(const ::Ice::Current &=Ice::emptyCurrent) override
starts the capture for the given source
Definition: StreamProviderI.cpp:255
ImageProcessor.h
Stream::StreamProviderI::StreamProviderPropertyDefinitions::StreamProviderPropertyDefinitions
StreamProviderPropertyDefinitions(std::string prefix)
Definition: StreamProviderI.cpp:41
Stream::StreamProviderI::getCodecType
CodecType getCodecType(const Ice::Current &) override
Definition: StreamProviderI.cpp:305
Stream
Definition: StreamProviderI.cpp:38
Stream::StreamProviderI::process
void process() override
Process the vision component.
Definition: StreamProviderI.cpp:193
Stream::StreamProviderI::StreamProviderPropertyDefinitions
Definition: StreamProviderI.h:60
Stream::StreamProviderI::onExitImageProcessor
void onExitImageProcessor() override
Is called once the component terminates.
Definition: StreamProviderI.cpp:188
Component.h
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
Stream::StreamProviderI::StreamProviderI
StreamProviderI()
Definition: StreamProviderI.cpp:65
IceUtil::Handle< class PropertyDefinitionContainer >
visionx::ImageProcessorPropertyDefinitions
Definition: ImageProcessor.h:61
Stream::StreamProviderI::getNumberOfImages
int getNumberOfImages(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: StreamProviderI.cpp:335
Stream::StreamProviderI
This class realizes the StreamProviderImageProcessorInterface-SliceInterface and is a subclass of vis...
Definition: StreamProviderI.h:54
Stream::StreamProviderI::onConnectImageProcessor
void onConnectImageProcessor() override
Is called once all dependencies of the object have been resolved and Ice connection is established.
Definition: StreamProviderI.cpp:97
Logging.h
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
Stream::StreamProviderI::setCompressionRate
void setCompressionRate(::Stream::CompressionRate=COMPRESSIONHIGH, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: StreamProviderI.cpp:341