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 
28 #include <Image/ByteImage.h>
29 
34 
36 #include <VisionX/interface/components/StreamProvider.h>
37 
38 extern "C" {
39 #include <x264.h>
40 #include <libswscale/swscale.h>
41 }
42 
43 
44 
45 #define NUMBER_OF_COMPRESSIONRATES 3 //should hold the number of compression rates (the compression rates are defined in the enum ::Stream::CompressionRate)
46 
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:
62  {
63  public:
65  };
66 
67 
68  /// @see PropertyUser::createPropertyDefinitions()
70  {
74  }
76 
77  void stopCapture(const ::Ice::Current& = Ice::emptyCurrent) override;
78  /** starts the capture for the given source */
79  bool startCapture(const ::Ice::Current& = Ice::emptyCurrent) override;
80 
81  void getImageInformation(int& imageWidth, int& imageHeight, int& imageType, const Ice::Current& c = Ice::emptyCurrent) override;
82  int getNumberOfImages(const ::Ice::Current& = Ice::emptyCurrent) override;
83  void setCompressionRate(::Stream::CompressionRate = COMPRESSIONHIGH, const ::Ice::Current& = Ice::emptyCurrent) override;
84  CodecType getCodecType(const Ice::Current&) override;
85 
86 
87  /* Inherited from ImageProcessor. */
88  void onInitImageProcessor() override;
89  void onConnectImageProcessor() override;
90  virtual void onDisConnectImageProcessor();
91  void onExitImageProcessor() override;
92  void process() override;
93 
94  /// Executes a single cycle of the encoding process.
95  void step(const Ice::Current& = Ice::emptyCurrent);
96 
97 
98  std::string getDefaultName() const override;
99 
100  void onStartRecording(const ::Ice::Current& = Ice::emptyCurrent) override;
101 
102 
103 
104  private:
105 
106  // Pushes the given image into the given appsrc, helper method for pushNewImages().
107  void calculateFps(); // Calcuates the current fps for the streamSources (as (80% old:20% new) weighted medium).
108  armarx::PeriodicTask<StreamProviderI>::pointer_type fpsCalculator; // Task calcualting the fps.
109 
110 
111  bool capturing = false;
112  std::string imageProviderProxyName;
113  visionx::ImageProviderInterfacePrx imageProviderProxy;
114  visionx::ImageFormatInfo imageFormat;
115  int numberImages;
116  int imgWidth;
117  int imgHeight;
118  int imgType;
119  int encodedImgHeight;
120 
121  CByteImage** ppInputImages, * pImageForEncoder;
122  using CByteImagePtr = std::shared_ptr<CByteImage>;
123  using ImageContainer = std::vector<CByteImagePtr>;
124 
125  x264_param_t param;
126  float fps;
127  x264_t* encoder;
128  x264_picture_t pic_in, pic_out;
129  SwsContext* convertCtx;
130  int frameCounter = 0;
131  Stream::StreamListenerInterfacePrx listener;
132  };
134 }
Stream::StreamProviderI::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: StreamProviderI.cpp:230
Stream::StreamProviderI::stopCapture
void stopCapture(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: StreamProviderI.cpp:257
visionx::ImageProcessor
The ImageProcessor class provides an interface for access to ImageProviders via Ice and shared memory...
Definition: ImageProcessor.h:87
Stream::StreamProviderI::getImageInformation
void getImageInformation(int &imageWidth, int &imageHeight, int &imageType, const Ice::Current &c=Ice::emptyCurrent) override
Definition: StreamProviderI.cpp:304
Stream::StreamProviderI::onDisConnectImageProcessor
virtual void onDisConnectImageProcessor()
Is called if a dependency of the object got lost (crash, network error, stopped, ....
Definition: StreamProviderI.cpp:154
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
PeriodicTask.h
Stream::StreamProviderI::onStartRecording
void onStartRecording(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: StreamProviderI.cpp:322
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
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:69
Stream::StreamProviderI::onInitImageProcessor
void onInitImageProcessor() override
Is called once initialization of the ManagedIceObject is done.
Definition: StreamProviderI.cpp:72
Stream::StreamProviderI::startCapture
bool startCapture(const ::Ice::Current &=Ice::emptyCurrent) override
starts the capture for the given source
Definition: StreamProviderI.cpp:237
ImageProcessor.h
Stream::StreamProviderI::StreamProviderPropertyDefinitions::StreamProviderPropertyDefinitions
StreamProviderPropertyDefinitions(std::string prefix)
Definition: StreamProviderI.cpp:42
Stream::StreamProviderI::getCodecType
CodecType getCodecType(const Ice::Current &) override
Definition: StreamProviderI.cpp:280
Stream
Definition: StreamProviderI.cpp:39
Stream::StreamProviderI::process
void process() override
Process the vision component.
Definition: StreamProviderI.cpp:181
Stream::StreamProviderI::StreamProviderPropertyDefinitions
Definition: StreamProviderI.h:60
Stream::StreamProviderI::onExitImageProcessor
void onExitImageProcessor() override
Is called once the component terminates.
Definition: StreamProviderI.cpp:175
Component.h
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
Stream::StreamProviderI::StreamProviderI
StreamProviderI()
Definition: StreamProviderI.cpp:60
IceUtil::Handle< class PropertyDefinitionContainer >
visionx::ImageProcessorPropertyDefinitions
Definition: ImageProcessor.h:61
Stream::StreamProviderI::getNumberOfImages
int getNumberOfImages(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: StreamProviderI.cpp:311
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:91
Logging.h
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
Stream::StreamProviderI::setCompressionRate
void setCompressionRate(::Stream::CompressionRate=COMPRESSIONHIGH, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: StreamProviderI.cpp:316