From 65eb62aa24880b02b99dd5297b159da1b1ba6d9d Mon Sep 17 00:00:00 2001 From: Stefan Eilemann Date: Fri, 26 Feb 2016 09:10:08 +0100 Subject: [PATCH 1/3] Make window list expandable and increase key hole --- apps/DesktopStreamer/MainWindow.ui | 63 ++++++++++++++++-------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/apps/DesktopStreamer/MainWindow.ui b/apps/DesktopStreamer/MainWindow.ui index a1de92e..a9bb405 100644 --- a/apps/DesktopStreamer/MainWindow.ui +++ b/apps/DesktopStreamer/MainWindow.ui @@ -7,7 +7,7 @@ 0 0 350 - 402 + 700 @@ -30,6 +30,28 @@ QLayout::SetMinimumSize + + + + QListView::LeftToRight + + + true + + + + 0 + 0 + + + + QListView::ListMode + + + true + + + @@ -50,33 +72,14 @@ 6 - - - - QListView::LeftToRight - - - true - - - QListView::Fixed - - - QListView::ListMode - - - true - - - - + Hostname - + @@ -104,35 +107,35 @@ - + Streamname - + - Desktop interaction + Interaction - + true - + Max frame rate - + @@ -154,7 +157,7 @@ - + @@ -191,7 +194,7 @@ - + From 236b417a5617e970d7285b3daac2cb96fed04c97 Mon Sep 17 00:00:00 2001 From: Stefan Eilemann Date: Fri, 26 Feb 2016 11:20:44 +0100 Subject: [PATCH 2/3] Cleanups --- apps/DesktopStreamer/MainWindow.cpp | 23 +++++++---------------- apps/DesktopStreamer/MainWindow.h | 7 ++----- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/apps/DesktopStreamer/MainWindow.cpp b/apps/DesktopStreamer/MainWindow.cpp index 0a3b3e1..a5e3436 100644 --- a/apps/DesktopStreamer/MainWindow.cpp +++ b/apps/DesktopStreamer/MainWindow.cpp @@ -69,7 +69,6 @@ typedef __int32 int32_t; #endif #define SHARE_DESKTOP_UPDATE_DELAY 1 -#define SERVUS_BROWSE_DELAY 100 #define FRAME_RATE_AVERAGE_NUM_FRAMES 10 #define CURSOR_IMAGE_FILE ":/cursor.png" #define CURSOR_IMAGE_SIZE 20 @@ -81,13 +80,9 @@ const std::vector< std::pair< QString, QString > > defaultHosts = { }; MainWindow::MainWindow() - : _stream( 0 ) - , _cursor( QImage( CURSOR_IMAGE_FILE ).scaled( + : _cursor( QImage( CURSOR_IMAGE_FILE ).scaled( CURSOR_IMAGE_SIZE * devicePixelRatio(), CURSOR_IMAGE_SIZE * devicePixelRatio(), Qt::KeepAspectRatio )) -#ifdef DEFLECT_USE_SERVUS - , _servus( deflect::Server::serviceName ) -#endif { setupUi( this ); @@ -141,6 +136,8 @@ MainWindow::MainWindow() connect( &_updateTimer, &QTimer::timeout, this, &MainWindow::_update ); } +MainWindow::~MainWindow() {} + void MainWindow::_startStreaming() { if( _stream ) @@ -152,8 +149,9 @@ void MainWindow::_startStreaming() else streamHost = _hostnameComboBox->currentData().toString(); - _stream = new deflect::Stream( _streamnameLineEdit->text().toStdString(), - streamHost.toStdString( )); + _stream.reset( + new deflect::Stream( _streamnameLineEdit->text().toStdString(), + streamHost.toStdString( ))); if( !_stream->isConnected( )) { _handleStreamingError( "Could not connect to host" ); @@ -176,9 +174,6 @@ void MainWindow::_startStreaming() #ifdef __APPLE__ _napSuspender.suspend(); -#endif -#ifdef DEFLECT_USE_SERVUS - _browseTimer.stop(); #endif _updateTimer.start( SHARE_DESKTOP_UPDATE_DELAY ); } @@ -187,9 +182,7 @@ void MainWindow::_stopStreaming() { _updateTimer.stop(); _statusbar->clearMessage(); - - delete _stream; - _stream = 0; + _stream.reset(); #ifdef __APPLE__ _napSuspender.resume(); @@ -199,10 +192,8 @@ void MainWindow::_stopStreaming() void MainWindow::_handleStreamingError( const QString& errorMessage ) { - std::cerr << errorMessage.toStdString() << std::endl; QMessageBox::warning( this, "Error", errorMessage, QMessageBox::Ok, QMessageBox::Ok ); - _stopStreaming(); } diff --git a/apps/DesktopStreamer/MainWindow.h b/apps/DesktopStreamer/MainWindow.h index 86ac5ab..578736e 100644 --- a/apps/DesktopStreamer/MainWindow.h +++ b/apps/DesktopStreamer/MainWindow.h @@ -60,6 +60,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindow public: MainWindow(); + ~MainWindow(); protected: void closeEvent( QCloseEvent* event ) final; @@ -71,7 +72,7 @@ private slots: void _openAboutWidget(); private: - deflect::Stream* _stream; + std::unique_ptr< deflect::Stream > _stream; QImage _cursor; QTimer _updateTimer; @@ -87,10 +88,6 @@ private slots: #ifdef __APPLE__ AppNapSuspender _napSuspender; #endif -#ifdef DEFLECT_USE_SERVUS - QTimer _browseTimer; - servus::Servus _servus; -#endif void _startStreaming(); void _stopStreaming(); From 7e7a3e071f42ab5d474544e1f076194a518649ac Mon Sep 17 00:00:00 2001 From: Stefan Eilemann Date: Fri, 26 Feb 2016 11:42:46 +0100 Subject: [PATCH 3/3] Keep streaming --- apps/DesktopStreamer/MainWindow.cpp | 119 +++++++++++++--------------- apps/DesktopStreamer/MainWindow.h | 1 + apps/DesktopStreamer/MainWindow.ui | 12 +-- doc/Changelog.md | 6 +- 4 files changed, 68 insertions(+), 70 deletions(-) diff --git a/apps/DesktopStreamer/MainWindow.cpp b/apps/DesktopStreamer/MainWindow.cpp index a5e3436..f00930f 100644 --- a/apps/DesktopStreamer/MainWindow.cpp +++ b/apps/DesktopStreamer/MainWindow.cpp @@ -69,6 +69,7 @@ typedef __int32 int32_t; #endif #define SHARE_DESKTOP_UPDATE_DELAY 1 +#define FAILURE_UPDATE_DELAY 100 #define FRAME_RATE_AVERAGE_NUM_FRAMES 10 #define CURSOR_IMAGE_FILE ":/cursor.png" #define CURSOR_IMAGE_SIZE 20 @@ -140,38 +141,6 @@ MainWindow::~MainWindow() {} void MainWindow::_startStreaming() { - if( _stream ) - return; - - QString streamHost; - if( _hostnameComboBox->findText( _hostnameComboBox->currentText( )) == -1 ) - streamHost = _hostnameComboBox->currentText(); - else - streamHost = _hostnameComboBox->currentData().toString(); - - _stream.reset( - new deflect::Stream( _streamnameLineEdit->text().toStdString(), - streamHost.toStdString( ))); - if( !_stream->isConnected( )) - { - _handleStreamingError( "Could not connect to host" ); - return; - } - -#ifdef DEFLECT_USE_QT5MACEXTRAS - _windowIndex = _listView->currentIndex(); - if( !_windowIndex.isValid( )) - { - _handleStreamingError( "No window to stream is selected" ); - return; - } -#endif - -#ifdef STREAM_EVENTS_SUPPORTED - if( _desktopInteractionCheckBox->isChecked( )) - _stream->registerForEvents(); -#endif - #ifdef __APPLE__ _napSuspender.suspend(); #endif @@ -180,25 +149,30 @@ void MainWindow::_startStreaming() void MainWindow::_stopStreaming() { - _updateTimer.stop(); - _statusbar->clearMessage(); _stream.reset(); + if( _streamButton->isChecked( )) + _updateTimer.start( FAILURE_UPDATE_DELAY ); + else + { + _updateTimer.stop(); + _statusbar->clearMessage(); #ifdef __APPLE__ - _napSuspender.resume(); + _napSuspender.resume(); #endif - _streamButton->setChecked( false ); + _streamButton->setChecked( false ); + } } void MainWindow::_handleStreamingError( const QString& errorMessage ) { - QMessageBox::warning( this, "Error", errorMessage, QMessageBox::Ok, - QMessageBox::Ok ); + _statusbar->showMessage( errorMessage ); _stopStreaming(); } void MainWindow::closeEvent( QCloseEvent* closeEvt ) { + _streamButton->setChecked( false ); _stopStreaming(); QMainWindow::closeEvent( closeEvt ); } @@ -213,23 +187,60 @@ void MainWindow::_shareDesktop( const bool set ) void MainWindow::_update() { - if( _stream->isRegisteredForEvents( )) + if( _streamButton->isChecked( )) + { + _checkStream(); _processStreamEvents(); - _shareDesktopUpdate(); + _shareDesktopUpdate(); + } + else + _stopStreaming(); +} + +void MainWindow::_checkStream() +{ + if( _stream ) + return; + + QString streamHost; + if( _hostnameComboBox->findText( _hostnameComboBox->currentText( )) == -1 ) + streamHost = _hostnameComboBox->currentText(); + else + streamHost = _hostnameComboBox->currentData().toString(); + + _stream.reset( + new deflect::Stream( _streamnameLineEdit->text().toStdString(), + streamHost.toStdString( ))); + if( !_stream->isConnected( )) + { + _handleStreamingError( "Could not connect to host" ); + return; + } + +#ifdef DEFLECT_USE_QT5MACEXTRAS + _windowIndex = _listView->currentIndex(); + if( !_windowIndex.isValid( )) + { + _handleStreamingError( "No window to stream is selected" ); + return; + } +#endif + +#ifdef STREAM_EVENTS_SUPPORTED + if( _desktopInteractionCheckBox->isChecked( )) + _stream->registerForEvents(); +#endif } void MainWindow::_processStreamEvents() { - while( _stream->hasEvent( )) + while( _stream && _stream->isRegisteredForEvents() && _stream->hasEvent( )) { const deflect::Event& wallEvent = _stream->getEvent(); // Once registered for events they must be consumed, otherwise they // queue up. Until unregister is implemented, just ignore them. if( !_desktopInteractionCheckBox->checkState( )) break; -#ifndef NDEBUG - std::cout << "----------" << std::endl; -#endif switch( wallEvent.type ) { case deflect::Event::EVT_CLOSE: @@ -293,7 +304,7 @@ void MainWindow::_shareDesktopUpdate() if( pixmap.isNull( )) { - _handleStreamingError( "Got NULL desktop pixmap" ); + _handleStreamingError( "Got no pixmap for desktop or window" ); return; } QImage image = pixmap.toImage(); @@ -316,7 +327,7 @@ void MainWindow::_shareDesktopUpdate() _stream->finishFrame(); if( !success ) { - _handleStreamingError( "Streaming failure, connection closed." ); + _handleStreamingError( "Streaming failure, connection closed" ); return; } @@ -394,10 +405,6 @@ void MainWindow::_sendMousePressEvent( const float x, const float y ) CGPoint point; point.x = _windowRect.topLeft().x() + x * _windowRect.width(); point.y = _windowRect.topLeft().y() + y * _windowRect.height(); -#ifndef NDEBUG - std::cout << "Press " << point.x << ", " << point.y << " (" - << x << ", " << y << ")"<< std::endl; -#endif sendMouseEvent( kCGEventLeftMouseDown, kCGMouseButtonLeft, point ); } @@ -406,10 +413,6 @@ void MainWindow::_sendMouseMoveEvent( const float x, const float y ) CGPoint point; point.x = _windowRect.topLeft().x() + x * _windowRect.width(); point.y = _windowRect.topLeft().y() + y * _windowRect.height(); -#ifndef NDEBUG - std::cout << "Move " << point.x << ", " << point.y << " (" - << x << ", " << y << ")"<< std::endl; -#endif sendMouseEvent( kCGEventMouseMoved, kCGMouseButtonLeft, point ); } @@ -418,10 +421,6 @@ void MainWindow::_sendMouseReleaseEvent( const float x, const float y ) CGPoint point; point.x = _windowRect.topLeft().x() + x * _windowRect.width(); point.y = _windowRect.topLeft().y() + y * _windowRect.height(); -#ifndef NDEBUG - std::cout << "Release " << point.x << ", " << point.y << " (" - << x << ", " << y << ")"<< std::endl; -#endif sendMouseEvent( kCGEventLeftMouseUp, kCGMouseButtonLeft, point ); } @@ -432,10 +431,6 @@ void MainWindow::_sendMouseDoubleClickEvent( const float x, const float y ) point.y = _windowRect.topLeft().y() + y * _windowRect.height(); CGEventRef event = CGEventCreateMouseEvent( 0, kCGEventLeftMouseDown, point, kCGMouseButtonLeft ); -#ifndef NDEBUG - std::cout << "Double click " << point.x << ", " << point.y << " (" - << x << ", " << y << ")"<< std::endl; -#endif CGEventSetIntegerValueField( event, kCGMouseEventClickState, 2 ); CGEventPost( kCGHIDEventTap, event ); diff --git a/apps/DesktopStreamer/MainWindow.h b/apps/DesktopStreamer/MainWindow.h index 578736e..a892c69 100644 --- a/apps/DesktopStreamer/MainWindow.h +++ b/apps/DesktopStreamer/MainWindow.h @@ -91,6 +91,7 @@ private slots: void _startStreaming(); void _stopStreaming(); + void _checkStream(); void _handleStreamingError( const QString& errorMessage ); void _processStreamEvents(); void _shareDesktopUpdate(); diff --git a/apps/DesktopStreamer/MainWindow.ui b/apps/DesktopStreamer/MainWindow.ui index a9bb405..b872d89 100644 --- a/apps/DesktopStreamer/MainWindow.ui +++ b/apps/DesktopStreamer/MainWindow.ui @@ -32,18 +32,18 @@ - - QListView::LeftToRight - - - true - 0 0 + + QListView::LeftToRight + + + true + QListView::ListMode diff --git a/doc/Changelog.md b/doc/Changelog.md index e9aab5a..4762aba 100644 --- a/doc/Changelog.md +++ b/doc/Changelog.md @@ -2,6 +2,8 @@ Changelog {#Changelog} ============ ## Deflect 0.9 (git master) +* [76](https://github.com/BlueBrain/Deflect/pull/76): + DesktopStreamer: Try to recover from streaming errors ### 0.9.1 (03-12-2015) * [66](https://github.com/BlueBrain/Deflect/pull/66): @@ -13,8 +15,8 @@ Changelog {#Changelog} * [65](https://github.com/BlueBrain/Deflect/pull/65): QmlStreamer: New 'streamname' command line option. * [64](https://github.com/BlueBrain/Deflect/pull/64): - QmlStreamer: Fix event forwarding, implement wheel event support -* [60](https://github.com/BlueBrain/Deflect/pull/60): + QmlStreamer: Fix event forwarding, implement wheel event support +* [60](https://github.com/BlueBrain/Deflect/pull/60): Improved DesktopStreamer: removed selection rectangle, editable list of stream hostnames