@@ -3478,8 +3478,9 @@ void RtApiAsio :: closeStream()
3478
3478
stream_.deviceBuffer = 0 ;
3479
3479
}
3480
3480
3481
- stream_.mode = UNINITIALIZED;
3482
- stream_.state = STREAM_CLOSED;
3481
+ clearStreamInfo ();
3482
+ // stream_.mode = UNINITIALIZED;
3483
+ // stream_.state = STREAM_CLOSED;
3483
3484
}
3484
3485
3485
3486
bool stopThreadCalled = false ;
@@ -3494,9 +3495,11 @@ RtAudioErrorType RtApiAsio :: startStream()
3494
3495
return error ( RTAUDIO_WARNING );
3495
3496
}
3496
3497
3498
+ /*
3497
3499
#if defined( HAVE_GETTIMEOFDAY )
3498
3500
gettimeofday( &stream_.lastTickTimestamp, NULL );
3499
3501
#endif
3502
+ */
3500
3503
3501
3504
AsioHandle *handle = (AsioHandle *) stream_.apiHandle ;
3502
3505
ASIOError result = ASIOStart ();
@@ -4648,8 +4651,8 @@ void RtApiWasapi::closeStream( void )
4648
4651
stream_.deviceBuffer = 0 ;
4649
4652
}
4650
4653
4651
- // update stream state
4652
- stream_.state = STREAM_CLOSED;
4654
+ clearStreamInfo ();
4655
+ // stream_.state = STREAM_CLOSED;
4653
4656
}
4654
4657
4655
4658
// -----------------------------------------------------------------------------
@@ -4664,10 +4667,12 @@ RtAudioErrorType RtApiWasapi::startStream( void )
4664
4667
return error ( RTAUDIO_WARNING );
4665
4668
}
4666
4669
4670
+ /*
4667
4671
#if defined( HAVE_GETTIMEOFDAY )
4668
4672
gettimeofday( &stream_.lastTickTimestamp, NULL );
4669
4673
#endif
4670
-
4674
+ */
4675
+
4671
4676
// update stream state
4672
4677
stream_.state = STREAM_RUNNING;
4673
4678
@@ -6495,21 +6500,27 @@ void RtApiDs :: closeStream()
6495
6500
stream_.deviceBuffer = 0 ;
6496
6501
}
6497
6502
6498
- stream_.mode = UNINITIALIZED;
6499
- stream_.state = STREAM_CLOSED;
6503
+ clearStreamInfo ();
6504
+ // stream_.mode = UNINITIALIZED;
6505
+ // stream_.state = STREAM_CLOSED;
6500
6506
}
6501
6507
6502
6508
RtAudioErrorType RtApiDs :: startStream()
6503
6509
{
6504
- if ( stream_.state == STREAM_RUNNING ) {
6505
- errorText_ = " RtApiDs::startStream(): the stream is already running!" ;
6510
+ if ( stream_.state != STREAM_STOPPED ) {
6511
+ if ( stream_.state == STREAM_RUNNING )
6512
+ errorText_ = " RtApiDs::startStream(): the stream is already running!" ;
6513
+ else if ( stream_.state == STREAM_STOPPING || stream_.state == STREAM_CLOSED )
6514
+ errorText_ = " RtApiDs::startStream(): the stream is stopping or closed!" ;
6506
6515
return error ( RTAUDIO_WARNING );
6507
6516
}
6508
6517
6518
+ /*
6509
6519
#if defined( HAVE_GETTIMEOFDAY )
6510
6520
gettimeofday( &stream_.lastTickTimestamp, NULL );
6511
6521
#endif
6512
-
6522
+ */
6523
+
6513
6524
DsHandle *handle = (DsHandle *) stream_.apiHandle ;
6514
6525
6515
6526
// Increase scheduler frequency on lesser windows (a side-effect of
@@ -6560,8 +6571,11 @@ RtAudioErrorType RtApiDs :: startStream()
6560
6571
6561
6572
RtAudioErrorType RtApiDs :: stopStream()
6562
6573
{
6563
- if ( stream_.state == STREAM_STOPPED ) {
6564
- errorText_ = " RtApiDs::stopStream(): the stream is already stopped!" ;
6574
+ if ( stream_.state != STREAM_RUNNING && stream_.state != STREAM_STOPPING ) {
6575
+ if ( stream_.state == STREAM_STOPPED )
6576
+ errorText_ = " RtApiDs::stopStream(): the stream is already stopped!" ;
6577
+ else if ( stream_.state == STREAM_CLOSED )
6578
+ errorText_ = " RtApiDs::stopStream(): the stream is closed!" ;
6565
6579
return error ( RTAUDIO_WARNING );
6566
6580
}
6567
6581
@@ -6663,8 +6677,11 @@ RtAudioErrorType RtApiDs :: stopStream()
6663
6677
6664
6678
RtAudioErrorType RtApiDs :: abortStream()
6665
6679
{
6666
- if ( stream_.state == STREAM_STOPPED ) {
6667
- errorText_ = " RtApiDs::abortStream(): the stream is already stopped!" ;
6680
+ if ( stream_.state != STREAM_RUNNING ) {
6681
+ if ( stream_.state == STREAM_STOPPED )
6682
+ errorText_ = " RtApiDs::abortStream(): the stream is already stopped!" ;
6683
+ else if ( stream_.state == STREAM_STOPPING || stream_.state == STREAM_CLOSED )
6684
+ errorText_ = " RtApiDs::abortStream(): the stream is stopping or closed!" ;
6668
6685
return error ( RTAUDIO_WARNING );
6669
6686
}
6670
6687
@@ -8199,25 +8216,31 @@ void RtApiAlsa :: closeStream()
8199
8216
stream_.deviceBuffer = 0 ;
8200
8217
}
8201
8218
8202
- stream_.mode = UNINITIALIZED;
8203
- stream_.state = STREAM_CLOSED;
8219
+ clearStreamInfo ();
8220
+ // stream_.mode = UNINITIALIZED;
8221
+ // stream_.state = STREAM_CLOSED;
8204
8222
}
8205
8223
8206
8224
RtAudioErrorType RtApiAlsa :: startStream()
8207
8225
{
8208
8226
// This method calls snd_pcm_prepare if the device isn't already in that state.
8209
8227
8210
- if ( stream_.state == STREAM_RUNNING ) {
8211
- errorText_ = " RtApiAlsa::startStream(): the stream is already running!" ;
8228
+ if ( stream_.state != STREAM_STOPPED ) {
8229
+ if ( stream_.state == STREAM_RUNNING )
8230
+ errorText_ = " RtApiAlsa::startStream(): the stream is already running!" ;
8231
+ else if ( stream_.state == STREAM_STOPPING || stream_.state == STREAM_CLOSED )
8232
+ errorText_ = " RtApiAlsa::startStream(): the stream is stopping or closed!" ;
8212
8233
return error ( RTAUDIO_WARNING );
8213
8234
}
8214
8235
8215
8236
MUTEX_LOCK ( &stream_.mutex );
8216
8237
8238
+ /*
8217
8239
#if defined( HAVE_GETTIMEOFDAY )
8218
8240
gettimeofday( &stream_.lastTickTimestamp, NULL );
8219
8241
#endif
8220
-
8242
+ */
8243
+
8221
8244
int result = 0 ;
8222
8245
snd_pcm_state_t state;
8223
8246
AlsaHandle *apiInfo = (AlsaHandle *) stream_.apiHandle ;
@@ -8260,8 +8283,11 @@ RtAudioErrorType RtApiAlsa :: startStream()
8260
8283
8261
8284
RtAudioErrorType RtApiAlsa :: stopStream()
8262
8285
{
8263
- if ( stream_.state == STREAM_STOPPED ) {
8264
- errorText_ = " RtApiAlsa::stopStream(): the stream is already stopped!" ;
8286
+ if ( stream_.state != STREAM_RUNNING && stream_.state != STREAM_STOPPING ) {
8287
+ if ( stream_.state == STREAM_STOPPED )
8288
+ errorText_ = " RtApiAlsa::stopStream(): the stream is already stopped!" ;
8289
+ else if ( stream_.state == STREAM_CLOSED )
8290
+ errorText_ = " RtApiAlsa::stopStream(): the stream is closed!" ;
8265
8291
return error ( RTAUDIO_WARNING );
8266
8292
}
8267
8293
@@ -8302,8 +8328,11 @@ RtAudioErrorType RtApiAlsa :: stopStream()
8302
8328
8303
8329
RtAudioErrorType RtApiAlsa :: abortStream()
8304
8330
{
8305
- if ( stream_.state == STREAM_STOPPED ) {
8306
- errorText_ = " RtApiAlsa::abortStream(): the stream is already stopped!" ;
8331
+ if ( stream_.state != STREAM_RUNNING ) {
8332
+ if ( stream_.state == STREAM_STOPPED )
8333
+ errorText_ = " RtApiAlsa::abortStream(): the stream is already stopped!" ;
8334
+ else if ( stream_.state == STREAM_STOPPING || stream_.state == STREAM_CLOSED )
8335
+ errorText_ = " RtApiAlsa::abortStream(): the stream is stopping or closed!" ;
8307
8336
return error ( RTAUDIO_WARNING );
8308
8337
}
8309
8338
@@ -8874,8 +8903,9 @@ void RtApiPulse::closeStream( void )
8874
8903
stream_.userBuffer [1 ] = 0 ;
8875
8904
}
8876
8905
8877
- stream_.state = STREAM_CLOSED;
8878
- stream_.mode = UNINITIALIZED;
8906
+ clearStreamInfo ();
8907
+ // stream_.state = STREAM_CLOSED;
8908
+ // stream_.mode = UNINITIALIZED;
8879
8909
}
8880
8910
8881
8911
void RtApiPulse::callbackEvent ( void )
@@ -8972,23 +9002,24 @@ void RtApiPulse::callbackEvent( void )
8972
9002
8973
9003
RtAudioErrorType RtApiPulse::startStream ( void )
8974
9004
{
8975
- PulseAudioHandle *pah = static_cast <PulseAudioHandle *>( stream_.apiHandle );
8976
-
8977
- if ( stream_.state == STREAM_CLOSED ) {
8978
- errorText_ = " RtApiPulse::startStream(): the stream is not open!" ;
8979
- return error ( RTAUDIO_INVALID_USE );
8980
- }
8981
- if ( stream_.state == STREAM_RUNNING ) {
8982
- errorText_ = " RtApiPulse::startStream(): the stream is already running!" ;
9005
+ if ( stream_.state != STREAM_STOPPED ) {
9006
+ if ( stream_.state == STREAM_RUNNING )
9007
+ errorText_ = " RtApiPulse::startStream(): the stream is already running!" ;
9008
+ else if ( stream_.state == STREAM_STOPPING || stream_.state == STREAM_CLOSED )
9009
+ errorText_ = " RtApiPulse::startStream(): the stream is stopping or closed!" ;
8983
9010
return error ( RTAUDIO_WARNING );
8984
9011
}
9012
+
9013
+ PulseAudioHandle *pah = static_cast <PulseAudioHandle *>( stream_.apiHandle );
8985
9014
8986
9015
MUTEX_LOCK ( &stream_.mutex );
8987
9016
9017
+ /*
8988
9018
#if defined( HAVE_GETTIMEOFDAY )
8989
9019
gettimeofday( &stream_.lastTickTimestamp, NULL );
8990
9020
#endif
8991
-
9021
+ */
9022
+
8992
9023
stream_.state = STREAM_RUNNING;
8993
9024
8994
9025
pah->runnable = true ;
@@ -8999,16 +9030,15 @@ RtAudioErrorType RtApiPulse::startStream( void )
8999
9030
9000
9031
RtAudioErrorType RtApiPulse::stopStream ( void )
9001
9032
{
9002
- PulseAudioHandle *pah = static_cast <PulseAudioHandle *>( stream_.apiHandle );
9003
-
9004
- if ( stream_.state == STREAM_CLOSED ) {
9005
- errorText_ = " RtApiPulse::stopStream(): the stream is not open!" ;
9006
- return error ( RTAUDIO_INVALID_USE );
9007
- }
9008
- if ( stream_.state == STREAM_STOPPED ) {
9009
- errorText_ = " RtApiPulse::stopStream(): the stream is already stopped!" ;
9033
+ if ( stream_.state != STREAM_RUNNING && stream_.state != STREAM_STOPPING ) {
9034
+ if ( stream_.state == STREAM_STOPPED )
9035
+ errorText_ = " RtApiPulse::stopStream(): the stream is already stopped!" ;
9036
+ else if ( stream_.state == STREAM_CLOSED )
9037
+ errorText_ = " RtApiPulse::stopStream(): the stream is closed!" ;
9010
9038
return error ( RTAUDIO_WARNING );
9011
9039
}
9040
+
9041
+ PulseAudioHandle *pah = static_cast <PulseAudioHandle *>( stream_.apiHandle );
9012
9042
9013
9043
stream_.state = STREAM_STOPPED;
9014
9044
MUTEX_LOCK ( &stream_.mutex );
@@ -9034,16 +9064,15 @@ RtAudioErrorType RtApiPulse::stopStream( void )
9034
9064
9035
9065
RtAudioErrorType RtApiPulse::abortStream ( void )
9036
9066
{
9037
- PulseAudioHandle *pah = static_cast <PulseAudioHandle*>( stream_.apiHandle );
9038
-
9039
- if ( stream_.state == STREAM_CLOSED ) {
9040
- errorText_ = " RtApiPulse::abortStream(): the stream is not open!" ;
9041
- return error ( RTAUDIO_INVALID_USE );
9042
- }
9043
- if ( stream_.state == STREAM_STOPPED ) {
9044
- errorText_ = " RtApiPulse::abortStream(): the stream is already stopped!" ;
9067
+ if ( stream_.state != STREAM_RUNNING ) {
9068
+ if ( stream_.state == STREAM_STOPPED )
9069
+ errorText_ = " RtApiPulse::abortStream(): the stream is already stopped!" ;
9070
+ else if ( stream_.state == STREAM_STOPPING || stream_.state == STREAM_CLOSED )
9071
+ errorText_ = " RtApiPulse::abortStream(): the stream is stopping or closed!" ;
9045
9072
return error ( RTAUDIO_WARNING );
9046
9073
}
9074
+
9075
+ PulseAudioHandle *pah = static_cast <PulseAudioHandle*>( stream_.apiHandle );
9047
9076
9048
9077
stream_.state = STREAM_STOPPED;
9049
9078
MUTEX_LOCK ( &stream_.mutex );
@@ -10022,22 +10051,28 @@ void RtApiOss :: closeStream()
10022
10051
stream_.deviceBuffer = 0 ;
10023
10052
}
10024
10053
10025
- stream_.mode = UNINITIALIZED;
10026
- stream_.state = STREAM_CLOSED;
10054
+ clearStreamInfo ();
10055
+ // stream_.mode = UNINITIALIZED;
10056
+ // stream_.state = STREAM_CLOSED;
10027
10057
}
10028
10058
10029
10059
RtAudioErrorType RtApiOss :: startStream()
10030
10060
{
10031
- if ( stream_.state == STREAM_RUNNING ) {
10032
- errorText_ = " RtApiOss::startStream(): the stream is already running!" ;
10061
+ if ( stream_.state != STREAM_STOPPED ) {
10062
+ if ( stream_.state == STREAM_RUNNING )
10063
+ errorText_ = " RtApiOss::startStream(): the stream is already running!" ;
10064
+ else if ( stream_.state == STREAM_STOPPING || stream_.state == STREAM_CLOSED )
10065
+ errorText_ = " RtApiOss::startStream(): the stream is stopping or closed!" ;
10033
10066
return error ( RTAUDIO_WARNING );
10034
10067
}
10035
10068
10036
10069
MUTEX_LOCK ( &stream_.mutex );
10037
10070
10071
+ /*
10038
10072
#if defined( HAVE_GETTIMEOFDAY )
10039
10073
gettimeofday( &stream_.lastTickTimestamp, NULL );
10040
10074
#endif
10075
+ */
10041
10076
10042
10077
stream_.state = STREAM_RUNNING;
10043
10078
@@ -10053,8 +10088,11 @@ RtAudioErrorType RtApiOss :: startStream()
10053
10088
10054
10089
RtAudioErrorType RtApiOss :: stopStream()
10055
10090
{
10056
- if ( stream_.state == STREAM_STOPPED ) {
10057
- errorText_ = " RtApiOss::stopStream(): the stream is already stopped!" ;
10091
+ if ( stream_.state != STREAM_RUNNING && stream_.state != STREAM_STOPPING ) {
10092
+ if ( stream_.state == STREAM_STOPPED )
10093
+ errorText_ = " RtApiOss::stopStream(): the stream is already stopped!" ;
10094
+ else if ( stream_.state == STREAM_CLOSED )
10095
+ errorText_ = " RtApiOss::stopStream(): the stream is closed!" ;
10058
10096
return error ( RTAUDIO_WARNING );
10059
10097
}
10060
10098
@@ -10123,8 +10161,11 @@ RtAudioErrorType RtApiOss :: stopStream()
10123
10161
10124
10162
RtAudioErrorType RtApiOss :: abortStream()
10125
10163
{
10126
- if ( stream_.state == STREAM_STOPPED ) {
10127
- errorText_ = " RtApiOss::abortStream(): the stream is already stopped!" ;
10164
+ if ( stream_.state != STREAM_RUNNING ) {
10165
+ if ( stream_.state == STREAM_STOPPED )
10166
+ errorText_ = " RtApiOss::abortStream(): the stream is already stopped!" ;
10167
+ else if ( stream_.state == STREAM_STOPPING || stream_.state == STREAM_CLOSED )
10168
+ errorText_ = " RtApiOss::abortStream(): the stream is stopping or closed!" ;
10128
10169
return error ( RTAUDIO_WARNING );
10129
10170
}
10130
10171
0 commit comments