Commit f1ce96db authored by Kateryna Kostiuk's avatar Kateryna Kostiuk

video: support client and daemon input

This patch allows to choose at runtime if video input will be
from client or from daemon.

Change-Id: I77db3e13803e4cf0c28fc5a81f6df9002df96670
parent 3216662a
...@@ -54,39 +54,47 @@ namespace jami { namespace video { ...@@ -54,39 +54,47 @@ namespace jami { namespace video {
static constexpr unsigned default_grab_width = 640; static constexpr unsigned default_grab_width = 640;
static constexpr unsigned default_grab_height = 480; static constexpr unsigned default_grab_height = 480;
VideoInput::VideoInput() VideoInput::VideoInput(VideoInputMode inputMode)
: VideoGenerator::VideoGenerator() : VideoGenerator::VideoGenerator()
#if !VIDEO_CLIENT_INPUT
, sink_ {Manager::instance().createSinkClient("local")}
, loop_(std::bind(&VideoInput::setup, this), , loop_(std::bind(&VideoInput::setup, this),
std::bind(&VideoInput::process, this), std::bind(&VideoInput::process, this),
std::bind(&VideoInput::cleanup, this)) std::bind(&VideoInput::cleanup, this))
{
inputMode_ = inputMode;
if (inputMode_ == VideoInputMode::Undefined) {
#if (defined(__ANDROID__) || defined(RING_UWP) || (defined(TARGET_OS_IOS) && TARGET_OS_IOS))
inputMode_ = VideoInputMode::ManagedByClient;
#else
inputMode_ = VideoInputMode::ManagedByDaemon;
#endif #endif
{} }
if (inputMode_ == VideoInputMode::ManagedByDaemon) {
sink_ = Manager::instance().createSinkClient("local");
}
}
VideoInput::~VideoInput() VideoInput::~VideoInput()
{ {
isStopped_ = true; isStopped_ = true;
#if VIDEO_CLIENT_INPUT if (videoManagedByClient()) {
emitSignal<DRing::VideoSignal::StopCapture>(); emitSignal<DRing::VideoSignal::StopCapture>();
capturing_ = false; capturing_ = false;
#else return;
}
loop_.join(); loop_.join();
#endif
} }
void void
VideoInput::startLoop() VideoInput::startLoop()
{ {
#if VIDEO_CLIENT_INPUT if (videoManagedByClient()) {
switchDevice(); switchDevice();
#else return;
}
if (!loop_.isRunning()) if (!loop_.isRunning())
loop_.start(); loop_.start();
#endif
} }
#if VIDEO_CLIENT_INPUT
void void
VideoInput::switchDevice() VideoInput::switchDevice()
{ {
...@@ -104,13 +112,26 @@ VideoInput::switchDevice() ...@@ -104,13 +112,26 @@ VideoInput::switchDevice()
} }
int VideoInput::getWidth() const int VideoInput::getWidth() const
{ return decOpts_.width; } {
if (videoManagedByClient()) {
return decOpts_.width;
}
return decoder_->getWidth();
}
int VideoInput::getHeight() const int VideoInput::getHeight() const
{ return decOpts_.height; } {
if (videoManagedByClient()) {
return decOpts_.height;
}
return decoder_->getHeight();
}
AVPixelFormat VideoInput::getPixelFormat() const AVPixelFormat VideoInput::getPixelFormat() const
{ {
if (!videoManagedByClient()) {
return decoder_->getPixelFormat();
}
int format; int format;
std::stringstream ss; std::stringstream ss;
ss << decOpts_.format; ss << decOpts_.format;
...@@ -118,8 +139,6 @@ AVPixelFormat VideoInput::getPixelFormat() const ...@@ -118,8 +139,6 @@ AVPixelFormat VideoInput::getPixelFormat() const
return (AVPixelFormat)format; return (AVPixelFormat)format;
} }
#else
void void
VideoInput::setRotation(int angle) VideoInput::setRotation(int angle)
{ {
...@@ -273,17 +292,6 @@ VideoInput::deleteDecoder() ...@@ -273,17 +292,6 @@ VideoInput::deleteDecoder()
decoder_.reset(); decoder_.reset();
} }
int VideoInput::getWidth() const
{ return decoder_->getWidth(); }
int VideoInput::getHeight() const
{ return decoder_->getHeight(); }
AVPixelFormat VideoInput::getPixelFormat() const
{ return decoder_->getPixelFormat(); }
#endif
void VideoInput::clearOptions() void VideoInput::clearOptions()
{ {
decOpts_ = {}; decOpts_ = {};
...@@ -293,11 +301,10 @@ void VideoInput::clearOptions() ...@@ -293,11 +301,10 @@ void VideoInput::clearOptions()
bool bool
VideoInput::isCapturing() const noexcept VideoInput::isCapturing() const noexcept
{ {
#if VIDEO_CLIENT_INPUT if (videoManagedByClient()) {
return capturing_; return capturing_;
#else }
return loop_.isRunning(); return loop_.isRunning();
#endif
} }
bool bool
...@@ -509,10 +516,10 @@ VideoInput::getParams() const ...@@ -509,10 +516,10 @@ VideoInput::getParams() const
MediaStream MediaStream
VideoInput::getInfo() const VideoInput::getInfo() const
{ {
#if !VIDEO_CLIENT_INPUT if (!videoManagedByClient()) {
if (decoder_) if (decoder_)
return decoder_->getStream("v:local"); return decoder_->getStream("v:local");
#endif }
auto opts = futureDecOpts_.get(); auto opts = futureDecOpts_.get();
rational<int> fr(opts.framerate.numerator(), opts.framerate.denominator()); rational<int> fr(opts.framerate.numerator(), opts.framerate.denominator());
return MediaStream("v:local", av_get_pix_fmt(opts.pixel_format.c_str()), return MediaStream("v:local", av_get_pix_fmt(opts.pixel_format.c_str()),
......
...@@ -48,16 +48,12 @@ namespace jami { namespace video { ...@@ -48,16 +48,12 @@ namespace jami { namespace video {
class SinkClient; class SinkClient;
#if (defined(__ANDROID__) || defined(RING_UWP) || (defined(TARGET_OS_IOS) && TARGET_OS_IOS)) enum class VideoInputMode {ManagedByClient, ManagedByDaemon, Undefined};
#define VIDEO_CLIENT_INPUT 1
#else
#define VIDEO_CLIENT_INPUT 0
#endif
class VideoInput : public VideoGenerator, public std::enable_shared_from_this<VideoInput> class VideoInput : public VideoGenerator, public std::enable_shared_from_this<VideoInput>
{ {
public: public:
VideoInput(); VideoInput(VideoInputMode inputMode = VideoInputMode::Undefined);
~VideoInput(); ~VideoInput();
// as VideoGenerator // as VideoGenerator
...@@ -107,10 +103,8 @@ private: ...@@ -107,10 +103,8 @@ private:
bool isCapturing() const noexcept; bool isCapturing() const noexcept;
void startLoop(); void startLoop();
#if VIDEO_CLIENT_INPUT
void switchDevice(); void switchDevice();
bool capturing_ {false}; bool capturing_ {false};
#else
void createDecoder(); void createDecoder();
void deleteDecoder(); void deleteDecoder();
std::unique_ptr<MediaDecoder> decoder_; std::unique_ptr<MediaDecoder> decoder_;
...@@ -127,7 +121,10 @@ private: ...@@ -127,7 +121,10 @@ private:
int rotation_ {0}; int rotation_ {0};
std::shared_ptr<AVBufferRef> displayMatrix_; std::shared_ptr<AVBufferRef> displayMatrix_;
void setRotation(int angle); void setRotation(int angle);
#endif VideoInputMode inputMode_;
inline bool videoManagedByClient() const {
return inputMode_ == VideoInputMode::ManagedByClient;
}
}; };
}} // namespace jami::video }} // namespace jami::video
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment