Skip to content

Commit 6db14ea

Browse files
author
Raphael Dumusc
committed
Stream constructors use the DEFLECT_ID and DEFLECT_HOST ENV_VARs
1 parent b0a304e commit 6db14ea

22 files changed

+390
-136
lines changed

apps/DesktopStreamer/MainWindow.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,22 @@ MainWindow::MainWindow()
8080
{
8181
setupUi( this );
8282

83-
connect( _hostnameComboBox, &QComboBox::currentTextChanged,
83+
connect( _hostComboBox, &QComboBox::currentTextChanged,
8484
[&]( const QString& text )
8585
{
8686
_streamButton->setEnabled( !text.isEmpty( ));
8787
_listView->setEnabled( !text.isEmpty( ));
8888
});
8989

9090
for( const auto& entry : defaultHosts )
91-
_hostnameComboBox->addItem( entry.first, entry.second );
91+
_hostComboBox->addItem( entry.first, entry.second );
9292

9393
// no default host selected initially
94-
_hostnameComboBox->setCurrentIndex( -1 );
94+
_hostComboBox->setCurrentIndex( -1 );
9595

9696
char hostname[256] = { 0 };
9797
gethostname( hostname, 256 );
98-
_streamnameLineEdit->setText( QString( "%1" ).arg( hostname ));
98+
_streamIdLineEdit->setText( QString( "%1" ).arg( hostname ));
9999

100100
#ifdef DEFLECT_USE_QT5MACEXTRAS
101101
_listView->setModel( new DesktopWindowsModel );
@@ -195,13 +195,13 @@ void MainWindow::_updateStreams()
195195
continue;
196196
}
197197

198-
const std::string name = index.isValid() ?
198+
const std::string appName = index.isValid() ?
199199
_listView->model()->data( index, Qt::DisplayRole ).
200200
toString().toStdString() : std::string();
201-
const std::string streamName = std::to_string( ++_streamID ) +
202-
" " + name + " - " +
203-
_streamnameLineEdit->text().toStdString();
204-
StreamPtr stream( new Stream( *this, index, streamName, host ));
201+
const std::string streamId = std::to_string( ++_streamID ) +
202+
" " + appName + " - " +
203+
_streamIdLineEdit->text().toStdString();
204+
StreamPtr stream( new Stream( *this, index, streamId, host ));
205205

206206
if( !stream->isConnected( ))
207207
{
@@ -235,7 +235,7 @@ void MainWindow::_updateStreams()
235235
{
236236
const QPersistentModelIndex index; // default == use desktop
237237
StreamPtr stream( new Stream( *this, index,
238-
_streamnameLineEdit->text().toStdString(),
238+
_streamIdLineEdit->text().toStdString(),
239239
host ));
240240
if( stream->isConnected( ))
241241
{
@@ -332,10 +332,10 @@ void MainWindow::_regulateFrameRate()
332332
std::string MainWindow::_getStreamHost() const
333333
{
334334
QString streamHost;
335-
if( _hostnameComboBox->findText(_hostnameComboBox->currentText( )) == -1 )
336-
streamHost = _hostnameComboBox->currentText();
335+
if( _hostComboBox->findText(_hostComboBox->currentText( )) == -1 )
336+
streamHost = _hostComboBox->currentText();
337337
else
338-
streamHost = _hostnameComboBox->currentData().toString();
338+
streamHost = _hostComboBox->currentData().toString();
339339
return streamHost.toStdString();
340340
}
341341

apps/DesktopStreamer/MainWindow.ui

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
</widget>
5959
</item>
6060
<item row="0" column="1">
61-
<widget class="QComboBox" name="_hostnameComboBox">
61+
<widget class="QComboBox" name="_hostComboBox">
6262
<property name="sizePolicy">
6363
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
6464
<horstretch>0</horstretch>
@@ -173,7 +173,7 @@
173173
</widget>
174174
</item>
175175
<item row="3" column="1">
176-
<widget class="QLineEdit" name="_streamnameLineEdit">
176+
<widget class="QLineEdit" name="_streamIdLineEdit">
177177
<property name="sizePolicy">
178178
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
179179
<horstretch>0</horstretch>
@@ -261,7 +261,7 @@
261261
<connection>
262262
<sender>_streamButton</sender>
263263
<signal>toggled(bool)</signal>
264-
<receiver>_streamnameLineEdit</receiver>
264+
<receiver>_streamIdLineEdit</receiver>
265265
<slot>setDisabled(bool)</slot>
266266
<hints>
267267
<hint type="sourcelabel">
@@ -277,7 +277,7 @@
277277
<connection>
278278
<sender>_streamButton</sender>
279279
<signal>toggled(bool)</signal>
280-
<receiver>_hostnameComboBox</receiver>
280+
<receiver>_hostComboBox</receiver>
281281
<slot>setDisabled(bool)</slot>
282282
<hints>
283283
<hint type="sourcelabel">

apps/DesktopStreamer/Stream.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757
#define CURSOR_IMAGE_SIZE 20
5858

5959
Stream::Stream( const MainWindow& parent, const QPersistentModelIndex window,
60-
const std::string& name, const std::string& host )
61-
: deflect::Stream( name, host )
60+
const std::string& id, const std::string& host )
61+
: deflect::Stream( id, host )
6262
, _parent( parent )
6363
, _window( window )
6464
, _cursor( QImage( CURSOR_IMAGE_FILE ).scaled(

apps/DesktopStreamer/Stream.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Stream : public deflect::Stream
5252
public:
5353
/** Construct a new stream for the given desktop window. */
5454
Stream( const MainWindow& parent, const QPersistentModelIndex window,
55-
const std::string& name, const std::string& host );
55+
const std::string& id, const std::string& host );
5656
~Stream();
5757

5858
/**

apps/QmlStreamer/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ int main( int argc, char** argv )
3838
"qrc:/qml/gui.qml" );
3939
parser.addOption( qmlFileOption );
4040

41-
QCommandLineOption streamHostOption( "host", "Stream target hostname "
41+
QCommandLineOption streamHostOption( "host", "Stream target host "
4242
"(default: localhost)",
43-
"hostname", "localhost" );
43+
"host", "localhost" );
4444
parser.addOption( streamHostOption );
4545

4646
// note: the 'name' command line option is already taken by QCoreApplication

apps/SimpleStreamer/main.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757
bool deflectInteraction = false;
5858
bool deflectCompressImage = true;
5959
unsigned int deflectCompressionQuality = 75;
60-
char* deflectHostname = NULL;
61-
std::string deflectStreamName = "SimpleStreamer";
60+
char* deflectHost = NULL;
61+
std::string deflectStreamId = "SimpleStreamer";
6262
deflect::Stream* deflectStream = NULL;
6363

6464
void syntax( char* app );
@@ -78,7 +78,7 @@ int main( int argc, char** argv )
7878
{
7979
readCommandLineArguments( argc, argv );
8080

81-
if( deflectHostname == NULL )
81+
if( deflectHost == NULL )
8282
syntax( argv[0] );
8383

8484
initGLWindow( argc, argv );
@@ -101,7 +101,7 @@ void readCommandLineArguments( int argc, char** argv )
101101
case 'n':
102102
if( i + 1 < argc )
103103
{
104-
deflectStreamName = argv[i+1];
104+
deflectStreamId = argv[i+1];
105105
++i;
106106
}
107107
break;
@@ -116,7 +116,7 @@ void readCommandLineArguments( int argc, char** argv )
116116
}
117117
}
118118
else if( i == argc - 1 )
119-
deflectHostname = argv[i];
119+
deflectHost = argv[i];
120120
}
121121
}
122122

@@ -147,7 +147,7 @@ void initGLWindow( int argc, char** argv )
147147

148148
void initDeflectStream()
149149
{
150-
deflectStream = new deflect::Stream( deflectStreamName, deflectHostname );
150+
deflectStream = new deflect::Stream( deflectStreamId, deflectHost );
151151
if( !deflectStream->isConnected( ))
152152
{
153153
std::cerr << "Could not connect to host!" << std::endl;
@@ -166,11 +166,11 @@ void initDeflectStream()
166166

167167
void syntax( char* app )
168168
{
169-
std::cerr << "syntax: " << app << " [options] <hostname>" << std::endl;
169+
std::cerr << "syntax: " << app << " [options] <host>" << std::endl;
170170
std::cerr << "options:" << std::endl;
171-
std::cerr << " -n <stream name> set stream name (default SimpleStreamer)" << std::endl;
172-
std::cerr << " -i enable interaction events (default disabled)" << std::endl;
173-
std::cerr << " -u enable uncompressed streaming (default disabled)" << std::endl;
171+
std::cerr << " -n <stream id> set stream identifier (default: 'SimpleStreamer')" << std::endl;
172+
std::cerr << " -i enable interaction events (default: OFF)" << std::endl;
173+
std::cerr << " -u enable uncompressed streaming (default: OFF)" << std::endl;
174174

175175
exit( 1 );
176176
}

deflect/ServerWorker.cpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ ServerWorker::~ServerWorker()
8181
// We still want to remove this source so that the stream does not get stuck
8282
// if other senders are still active / resp. the window gets closed if no
8383
// more senders contribute to it.
84-
if( !_streamUri.isEmpty( ))
85-
emit removeStreamSource( _streamUri, _sourceId );
84+
if( !_streamId.isEmpty( ))
85+
emit removeStreamSource( _streamId, _sourceId );
8686

8787
if( _tcpSocket->state() == QAbstractSocket::ConnectedState )
8888
_sendQuit();
@@ -103,7 +103,7 @@ void ServerWorker::initConnection()
103103

104104
void ServerWorker::closeConnection( const QString uri )
105105
{
106-
if( uri != _streamUri )
106+
if( uri != _streamId )
107107
return;
108108

109109
Event closeEvent;
@@ -116,7 +116,7 @@ void ServerWorker::closeConnection( const QString uri )
116116
void ServerWorker::replyToEventRegistration( const QString uri,
117117
const bool success )
118118
{
119-
if( uri != _streamUri )
119+
if( uri != _streamId )
120120
return;
121121

122122
_registeredToEvents = success;
@@ -196,39 +196,38 @@ void ServerWorker::_handleMessage( const MessageHeader& messageHeader,
196196
const QString uri( messageHeader.uri );
197197
if( uri.isEmpty( ))
198198
{
199-
std::cerr << "Warning: rejecting streamer with empty uri"
200-
<< std::endl;
201-
closeConnection( _streamUri );
199+
std::cerr << "Warning: rejecting streamer with empty id" << std::endl;
200+
closeConnection( _streamId );
202201
return;
203202
}
204-
if( uri != _streamUri &&
203+
if( uri != _streamId &&
205204
messageHeader.type != MESSAGE_TYPE_PIXELSTREAM_OPEN )
206205
{
207-
std::cerr << "Warning: ingnoring message with incorrect stream uri: '"
206+
std::cerr << "Warning: ingnoring message with incorrect stream id: '"
208207
<< messageHeader.uri << "', expected: '"
209-
<< _streamUri.toStdString() << "'" << std::endl;
208+
<< _streamId.toStdString() << "'" << std::endl;
210209
return;
211210
}
212211

213212
switch( messageHeader.type )
214213
{
215214
case MESSAGE_TYPE_QUIT:
216-
emit removeStreamSource( _streamUri, _sourceId );
217-
_streamUri = QString();
215+
emit removeStreamSource( _streamId, _sourceId );
216+
_streamId = QString();
218217
break;
219218

220219
case MESSAGE_TYPE_PIXELSTREAM_OPEN:
221-
if( !_streamUri.isEmpty( ))
220+
if( !_streamId.isEmpty( ))
222221
{
223222
std::cerr << "Warning: PixelStream already opened!" << std::endl;
224223
return;
225224
}
226-
_streamUri = uri;
227-
emit addStreamSource( _streamUri, _sourceId );
225+
_streamId = uri;
226+
emit addStreamSource( _streamId, _sourceId );
228227
break;
229228

230229
case MESSAGE_TYPE_PIXELSTREAM_FINISH_FRAME:
231-
emit receivedFrameFinished( _streamUri, _sourceId );
230+
emit receivedFrameFinished( _streamId, _sourceId );
232231
break;
233232

234233
case MESSAGE_TYPE_PIXELSTREAM:
@@ -239,7 +238,7 @@ void ServerWorker::_handleMessage( const MessageHeader& messageHeader,
239238
{
240239
const SizeHints* hints =
241240
reinterpret_cast< const SizeHints* >( byteArray.data( ));
242-
emit receivedSizeHints( _streamUri, SizeHints( *hints ));
241+
emit receivedSizeHints( _streamId, SizeHints( *hints ));
243242
break;
244243
}
245244

@@ -251,7 +250,7 @@ void ServerWorker::_handleMessage( const MessageHeader& messageHeader,
251250
{
252251
const bool exclusive =
253252
(messageHeader.type == MESSAGE_TYPE_BIND_EVENTS_EX);
254-
emit registerToEvents( _streamUri, exclusive, this );
253+
emit registerToEvents( _streamId, exclusive, this );
255254
}
256255
break;
257256

@@ -272,7 +271,7 @@ void ServerWorker::_handlePixelStreamMessage( const QByteArray& byteArray )
272271
byteArray.right( byteArray.size() - sizeof( SegmentParameters ));
273272
segment.imageData = imageData;
274273

275-
emit( receivedSegment( _streamUri, _sourceId, segment ));
274+
emit( receivedSegment( _streamId, _sourceId, segment ));
276275
}
277276

278277
void ServerWorker::_sendProtocolVersion()

deflect/ServerWorker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private slots:
9292
private:
9393
QTcpSocket* _tcpSocket;
9494

95-
QString _streamUri;
95+
QString _streamId;
9696
int _sourceId;
9797

9898
bool _registeredToEvents;

deflect/Socket.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ namespace deflect
5656

5757
const unsigned short Socket::defaultPortNumber = DEFAULT_PORT_NUMBER;
5858

59-
Socket::Socket( const std::string& hostname, const unsigned short port )
60-
: _socket( new QTcpSocket( ))
59+
Socket::Socket( const std::string& host, const unsigned short port )
60+
: _host( host )
61+
, _socket( new QTcpSocket( ))
6162
, _remoteProtocolVersion( INVALID_NETWORK_PROTOCOL_VERSION )
6263
{
6364
// disable warnings which occur if no QCoreApplication is present during
@@ -69,7 +70,7 @@ Socket::Socket( const std::string& hostname, const unsigned short port )
6970
log->setEnabled( QtWarningMsg, false );
7071
}
7172

72-
_connect( hostname, port );
73+
_connect( host, port );
7374

7475
QObject::connect( _socket, &QTcpSocket::disconnected,
7576
this, &Socket::disconnected );
@@ -80,6 +81,11 @@ Socket::~Socket()
8081
delete _socket;
8182
}
8283

84+
const std::string& Socket::getHost() const
85+
{
86+
return _host;
87+
}
88+
8389
bool Socket::isConnected() const
8490
{
8591
return _socket->state() == QTcpSocket::ConnectedState;
@@ -182,17 +188,17 @@ bool Socket::_receiveHeader( MessageHeader& messageHeader )
182188
return stream.status() == QDataStream::Ok;
183189
}
184190

185-
bool Socket::_connect( const std::string& hostname, const unsigned short port )
191+
bool Socket::_connect( const std::string& host, const unsigned short port )
186192
{
187193
// make sure we're disconnected
188194
_socket->disconnectFromHost();
189195

190196
// open connection
191-
_socket->connectToHost( hostname.c_str(), port );
197+
_socket->connectToHost( host.c_str(), port );
192198

193199
if( !_socket->waitForConnected( RECEIVE_TIMEOUT_MS ))
194200
{
195-
std::cerr << "could not connect to host " << hostname << ":" << port
201+
std::cerr << "could not connect to host " << host << ":" << port
196202
<< std::endl;
197203
return false;
198204
}
@@ -201,7 +207,7 @@ bool Socket::_connect( const std::string& hostname, const unsigned short port )
201207
if( _checkProtocolVersion( ))
202208
return true;
203209

204-
std::cerr << "Protocol version check failed for host: " << hostname << ":"
210+
std::cerr << "Protocol version check failed for host: " << host << ":"
205211
<< port << std::endl;
206212
_socket->disconnectFromHost();
207213
return false;

0 commit comments

Comments
 (0)