mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-11 18:34:58 +01:00
BugFix: change Device of DeviceSource with different resolution
This commit is contained in:
@@ -369,6 +369,11 @@ DeviceSource::DeviceSource(uint64_t id) : StreamSource(id), unplugged_(false)
|
||||
}
|
||||
|
||||
DeviceSource::~DeviceSource()
|
||||
{
|
||||
unsetDevice();
|
||||
}
|
||||
|
||||
void DeviceSource::unsetDevice()
|
||||
{
|
||||
// unregister this device source from a Device handler
|
||||
auto h = std::find_if(Device::manager().handles_.begin(), Device::manager().handles_.end(), hasConnectedSource(this));
|
||||
@@ -398,11 +403,18 @@ DeviceSource::~DeviceSource()
|
||||
|
||||
void DeviceSource::setDevice(const std::string &devicename)
|
||||
{
|
||||
if (device_.compare(devicename) == 0)
|
||||
return;
|
||||
|
||||
// instanciate and wait for monitor initialization if not already initialized
|
||||
std::mutex mtx;
|
||||
std::unique_lock<std::mutex> lck(mtx);
|
||||
Device::manager().monitor_initialization_.wait(lck, Device::initialized);
|
||||
|
||||
// if changing device
|
||||
if (!device_.empty())
|
||||
unsetDevice();
|
||||
|
||||
// remember device name
|
||||
device_ = devicename;
|
||||
|
||||
@@ -449,11 +461,14 @@ void DeviceSource::setDevice(const std::string &devicename)
|
||||
|
||||
pipeline << " ! videoconvert";
|
||||
|
||||
// resize render buffer
|
||||
// delete and reset render buffer to enforce re-init of StreamSource
|
||||
if (renderbuffer_)
|
||||
renderbuffer_->resize(best.width, best.height);
|
||||
delete renderbuffer_;
|
||||
renderbuffer_ = nullptr;
|
||||
|
||||
// new stream
|
||||
if (stream_)
|
||||
delete stream_;
|
||||
stream_ = h->stream = new Stream;
|
||||
|
||||
// open gstreamer
|
||||
|
||||
@@ -33,6 +33,7 @@ public:
|
||||
private:
|
||||
std::string device_;
|
||||
std::atomic<bool> unplugged_;
|
||||
void unsetDevice();
|
||||
};
|
||||
|
||||
struct DeviceConfig {
|
||||
|
||||
30
Source.cpp
30
Source.cpp
@@ -492,6 +492,9 @@ void Source::attach(FrameBuffer *renderbuffer)
|
||||
delete renderbuffer_;
|
||||
renderbuffer_ = renderbuffer;
|
||||
|
||||
// only first time initialization
|
||||
if ( mode_ == UNINITIALIZED ) {
|
||||
|
||||
// create the surfaces to draw the frame buffer in the views
|
||||
rendersurface_ = new FrameBufferSurface(renderbuffer_, blendingshader_);
|
||||
groups_[View::RENDERING]->attach(rendersurface_);
|
||||
@@ -518,20 +521,31 @@ void Source::attach(FrameBuffer *renderbuffer)
|
||||
if (symbol_) {
|
||||
overlays_[View::MIXING]->attach( symbol_ );
|
||||
overlays_[View::LAYER]->attach( symbol_ );
|
||||
// hack to place the symbols in the corner independently of aspect ratio
|
||||
symbol_->translation_.x += 0.1f * (renderbuffer_->aspectRatio()-1.f);
|
||||
}
|
||||
|
||||
// hack to place the initials in the corner independently of aspect ratio
|
||||
initial_0_->translation_.x -= renderbuffer_->aspectRatio();
|
||||
initial_1_->translation_.x -= renderbuffer_->aspectRatio();
|
||||
|
||||
// add lock icon to views (displayed on front)
|
||||
groups_[View::LAYER]->attach( locker_ );
|
||||
groups_[View::MIXING]->attach( locker_ );
|
||||
groups_[View::GEOMETRY]->attach( locker_ );
|
||||
groups_[View::TEXTURE]->attach( locker_ );
|
||||
|
||||
// make the source visible
|
||||
setMode(VISIBLE);
|
||||
}
|
||||
else {
|
||||
rendersurface_->setFrameBuffer(renderbuffer_);
|
||||
mixingsurface_->setFrameBuffer(renderbuffer_);
|
||||
}
|
||||
|
||||
// if a symbol is available
|
||||
if (symbol_)
|
||||
// hack to place the symbols in the corner independently of aspect ratio
|
||||
symbol_->translation_.x = 1.1f * (renderbuffer_->aspectRatio()-1.f);
|
||||
|
||||
// hack to place the initials in the corner independently of aspect ratio
|
||||
initial_0_->translation_.x = 0.2f - renderbuffer_->aspectRatio();
|
||||
initial_1_->translation_.x = 0.4f - renderbuffer_->aspectRatio();
|
||||
|
||||
// scale all icon nodes to match aspect ratio
|
||||
for (int v = View::MIXING; v < View::INVALID; v++) {
|
||||
NodeSet::iterator node;
|
||||
@@ -546,10 +560,6 @@ void Source::attach(FrameBuffer *renderbuffer)
|
||||
delete maskbuffer_;
|
||||
maskbuffer_ = new FrameBuffer( glm::vec3(0.5) * renderbuffer->resolution() );
|
||||
|
||||
// make the source visible
|
||||
if ( mode_ == UNINITIALIZED )
|
||||
setMode(VISIBLE);
|
||||
|
||||
// request update
|
||||
need_update_ = true;
|
||||
}
|
||||
|
||||
@@ -119,10 +119,10 @@ void StreamSource::init()
|
||||
// once the texture of media player is created
|
||||
if (stream_->texture() != Resource::getTextureBlack()) {
|
||||
|
||||
// get the texture index from media player, apply it to the media surface
|
||||
// get the texture index from stream, apply it to the surface
|
||||
texturesurface_->setTextureIndex( stream_->texture() );
|
||||
|
||||
// create Frame buffer matching size of media player
|
||||
// create Frame buffer matching size of stream
|
||||
float height = float(stream_->width()) / stream_->aspectRatio();
|
||||
FrameBuffer *renderbuffer = new FrameBuffer(stream_->width(), (uint)height, FrameBuffer::FrameBuffer_alpha);
|
||||
|
||||
@@ -196,7 +196,6 @@ guint64 StreamSource::playtime () const
|
||||
{
|
||||
if ( stream_ )
|
||||
return stream_->position();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user