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
38extern "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
48namespace 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:
65
66 /// @see PropertyUser::createPropertyDefinitions()
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
constexpr T c
void onStartRecording(const ::Ice::Current &=Ice::emptyCurrent) override
bool startCapture(const ::Ice::Current &=Ice::emptyCurrent) override
starts the capture for the given source
void onConnectImageProcessor() override
Is called once all dependencies of the object have been resolved and Ice connection is established.
void setCompressionRate(::Stream::CompressionRate=COMPRESSIONHIGH, const ::Ice::Current &=Ice::emptyCurrent) override
void step(const Ice::Current &=Ice::emptyCurrent)
Executes a single cycle of the encoding process.
void onExitImageProcessor() override
Is called once the component terminates.
int getNumberOfImages(const ::Ice::Current &=Ice::emptyCurrent) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void process() override
Process the vision component.
CodecType getCodecType(const Ice::Current &) override
void onInitImageProcessor() override
Is called once initialization of the ManagedIceObject is done.
void stopCapture(const ::Ice::Current &=Ice::emptyCurrent) override
void getImageInformation(int &imageWidth, int &imageHeight, int &imageType, const Ice::Current &c=Ice::emptyCurrent) override
std::string getDefaultName() const override
Retrieve default name of component.
virtual void onDisConnectImageProcessor()
Is called if a dependency of the object got lost (crash, network error, stopped, ....
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.
The ImageProcessor class provides an interface for access to ImageProviders via Ice and shared memory...
IceInternal::Handle< StreamProviderI > StreamProviderIPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.