Skip to content

Commit b11341b

Browse files
committed
Map PaStream to PaUtilStreamRepresentation
This change tells the compiler that a PaStream is really a PaUtilStreamRepresentation. Note the struct is still opaque to users, as they do not have access to the definition of that struct. The upside is reduced need for casts in the PortAudio implementation, as well as a possibly nicer debugging experience, as debuggers will now understand the contents of a PaStream. The downside is the typedef is now slightly uglier as it names a type that only the implementation is supposed to know about. This is purely cosmetic though as users do not have access to the definition of the struct.
1 parent 0d8c084 commit b11341b

File tree

6 files changed

+30
-46
lines changed

6 files changed

+30
-46
lines changed

include/portaudio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ PaError Pa_IsFormatSupported( const PaStreamParameters *inputParameters,
636636
Pa_GetStreamTime, Pa_GetStreamCpuLoad
637637
638638
*/
639-
typedef struct PaStream PaStream;
639+
typedef struct PaUtilStreamRepresentation PaStream;
640640

641641

642642
/** Can be passed as the framesPerBuffer parameter to Pa_OpenStream()

src/common/pa_front.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ static int FindHostApi( PaDeviceIndex device, int *hostSpecificDeviceIndex )
307307

308308
static void AddOpenStream( PaStream* stream )
309309
{
310-
((PaUtilStreamRepresentation*)stream)->nextOpenStream = firstOpenStream_;
311-
firstOpenStream_ = (PaUtilStreamRepresentation*)stream;
310+
(stream)->nextOpenStream = firstOpenStream_;
311+
firstOpenStream_ = stream;
312312
}
313313

314314

@@ -1372,7 +1372,7 @@ PaError PaUtil_ValidateStreamPointer( PaStream* stream )
13721372

13731373
if( stream == NULL ) return paBadStreamPtr;
13741374

1375-
if( ((PaUtilStreamRepresentation*)stream)->magic != PA_STREAM_MAGIC )
1375+
if( (stream)->magic != PA_STREAM_MAGIC )
13761376
return paBadStreamPtr;
13771377

13781378
return paNoError;
@@ -1394,7 +1394,7 @@ PaError Pa_CloseStream( PaStream* stream )
13941394

13951395
if( result == paNoError )
13961396
{
1397-
interface = PA_STREAM_INTERFACE(stream);
1397+
interface = stream->streamInterface;
13981398

13991399
/* abort the stream if it isn't stopped */
14001400
result = interface->IsStopped( stream );
@@ -1423,14 +1423,14 @@ PaError Pa_SetStreamFinishedCallback( PaStream *stream, PaStreamFinishedCallback
14231423

14241424
if( result == paNoError )
14251425
{
1426-
result = PA_STREAM_INTERFACE(stream)->IsStopped( stream );
1426+
result = stream->streamInterface->IsStopped( stream );
14271427
if( result == 0 )
14281428
{
14291429
result = paStreamIsNotStopped ;
14301430
}
14311431
if( result == 1 )
14321432
{
1433-
PA_STREAM_REP( stream )->streamFinishedCallback = streamFinishedCallback;
1433+
stream->streamFinishedCallback = streamFinishedCallback;
14341434
result = paNoError;
14351435
}
14361436
}
@@ -1451,14 +1451,14 @@ PaError Pa_StartStream( PaStream *stream )
14511451

14521452
if( result == paNoError )
14531453
{
1454-
result = PA_STREAM_INTERFACE(stream)->IsStopped( stream );
1454+
result = stream->streamInterface->IsStopped( stream );
14551455
if( result == 0 )
14561456
{
14571457
result = paStreamIsNotStopped ;
14581458
}
14591459
else if( result == 1 )
14601460
{
1461-
result = PA_STREAM_INTERFACE(stream)->Start( stream );
1461+
result = stream->streamInterface->Start( stream );
14621462
}
14631463
}
14641464

@@ -1477,10 +1477,10 @@ PaError Pa_StopStream( PaStream *stream )
14771477

14781478
if( result == paNoError )
14791479
{
1480-
result = PA_STREAM_INTERFACE(stream)->IsStopped( stream );
1480+
result = stream->streamInterface->IsStopped( stream );
14811481
if( result == 0 )
14821482
{
1483-
result = PA_STREAM_INTERFACE(stream)->Stop( stream );
1483+
result = stream->streamInterface->Stop( stream );
14841484
}
14851485
else if( result == 1 )
14861486
{
@@ -1503,10 +1503,10 @@ PaError Pa_AbortStream( PaStream *stream )
15031503

15041504
if( result == paNoError )
15051505
{
1506-
result = PA_STREAM_INTERFACE(stream)->IsStopped( stream );
1506+
result = stream->streamInterface->IsStopped( stream );
15071507
if( result == 0 )
15081508
{
1509-
result = PA_STREAM_INTERFACE(stream)->Abort( stream );
1509+
result = stream->streamInterface->Abort( stream );
15101510
}
15111511
else if( result == 1 )
15121512
{
@@ -1528,7 +1528,7 @@ PaError Pa_IsStreamStopped( PaStream *stream )
15281528
PA_LOGAPI(("\tPaStream* stream: 0x%p\n", stream ));
15291529

15301530
if( result == paNoError )
1531-
result = PA_STREAM_INTERFACE(stream)->IsStopped( stream );
1531+
result = stream->streamInterface->IsStopped( stream );
15321532

15331533
PA_LOGAPI_EXIT_PAERROR( "Pa_IsStreamStopped", result );
15341534

@@ -1544,7 +1544,7 @@ PaError Pa_IsStreamActive( PaStream *stream )
15441544
PA_LOGAPI(("\tPaStream* stream: 0x%p\n", stream ));
15451545

15461546
if( result == paNoError )
1547-
result = PA_STREAM_INTERFACE(stream)->IsActive( stream );
1547+
result = stream->streamInterface->IsActive( stream );
15481548

15491549

15501550
PA_LOGAPI_EXIT_PAERROR( "Pa_IsStreamActive", result );
@@ -1571,7 +1571,7 @@ const PaStreamInfo* Pa_GetStreamInfo( PaStream *stream )
15711571
}
15721572
else
15731573
{
1574-
result = &PA_STREAM_REP( stream )->streamInfo;
1574+
result = &stream->streamInfo;
15751575

15761576
PA_LOGAPI(("Pa_GetStreamInfo returned:\n" ));
15771577
PA_LOGAPI(("\tconst PaStreamInfo*: 0x%p:\n", result ));
@@ -1607,7 +1607,7 @@ PaTime Pa_GetStreamTime( PaStream *stream )
16071607
}
16081608
else
16091609
{
1610-
result = PA_STREAM_INTERFACE(stream)->GetTime( stream );
1610+
result = stream->streamInterface->GetTime( stream );
16111611

16121612
PA_LOGAPI(("Pa_GetStreamTime returned:\n" ));
16131613
PA_LOGAPI(("\tPaTime: %g\n", result ));
@@ -1637,7 +1637,7 @@ double Pa_GetStreamCpuLoad( PaStream* stream )
16371637
}
16381638
else
16391639
{
1640-
result = PA_STREAM_INTERFACE(stream)->GetCpuLoad( stream );
1640+
result = stream->streamInterface->GetCpuLoad( stream );
16411641

16421642
PA_LOGAPI(("Pa_GetStreamCpuLoad returned:\n" ));
16431643
PA_LOGAPI(("\tdouble: %g\n", result ));
@@ -1670,10 +1670,10 @@ PaError Pa_ReadStream( PaStream* stream,
16701670
}
16711671
else
16721672
{
1673-
result = PA_STREAM_INTERFACE(stream)->IsStopped( stream );
1673+
result = stream->streamInterface->IsStopped( stream );
16741674
if( result == 0 )
16751675
{
1676-
result = PA_STREAM_INTERFACE(stream)->Read( stream, buffer, frames );
1676+
result = stream->streamInterface->Read( stream, buffer, frames );
16771677
}
16781678
else if( result == 1 )
16791679
{
@@ -1710,10 +1710,10 @@ PaError Pa_WriteStream( PaStream* stream,
17101710
}
17111711
else
17121712
{
1713-
result = PA_STREAM_INTERFACE(stream)->IsStopped( stream );
1713+
result = stream->streamInterface->IsStopped( stream );
17141714
if( result == 0 )
17151715
{
1716-
result = PA_STREAM_INTERFACE(stream)->Write( stream, buffer, frames );
1716+
result = stream->streamInterface->Write( stream, buffer, frames );
17171717
}
17181718
else if( result == 1 )
17191719
{
@@ -1745,7 +1745,7 @@ signed long Pa_GetStreamReadAvailable( PaStream* stream )
17451745
}
17461746
else
17471747
{
1748-
result = PA_STREAM_INTERFACE(stream)->GetReadAvailable( stream );
1748+
result = stream->streamInterface->GetReadAvailable( stream );
17491749

17501750
PA_LOGAPI(("Pa_GetStreamReadAvailable returned:\n" ));
17511751
PA_LOGAPI(("\tPaError: %d ( %s )\n", result, Pa_GetErrorText( result ) ));
@@ -1774,7 +1774,7 @@ signed long Pa_GetStreamWriteAvailable( PaStream* stream )
17741774
}
17751775
else
17761776
{
1777-
result = PA_STREAM_INTERFACE(stream)->GetWriteAvailable( stream );
1777+
result = stream->streamInterface->GetWriteAvailable( stream );
17781778

17791779
PA_LOGAPI(("Pa_GetStreamWriteAvailable returned:\n" ));
17801780
PA_LOGAPI(("\tPaError: %d ( %s )\n", result, Pa_GetErrorText( result ) ));

src/common/pa_stream.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -182,22 +182,6 @@ void PaUtil_TerminateStreamRepresentation( PaUtilStreamRepresentation *streamRep
182182
PaError PaUtil_ValidateStreamPointer( PaStream *stream );
183183

184184

185-
/** Cast an opaque stream pointer into a pointer to a PaUtilStreamRepresentation.
186-
187-
@see PaUtilStreamRepresentation
188-
*/
189-
#define PA_STREAM_REP( stream )\
190-
((PaUtilStreamRepresentation*) (stream) )
191-
192-
193-
/** Cast an opaque stream pointer into a pointer to a PaUtilStreamInterface.
194-
195-
@see PaUtilStreamRepresentation, PaUtilStreamInterface
196-
*/
197-
#define PA_STREAM_INTERFACE( stream )\
198-
PA_STREAM_REP( (stream) )->streamInterface
199-
200-
201185

202186
#ifdef __cplusplus
203187
}

src/hostapi/alsa/pa_linux_alsa.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4651,8 +4651,8 @@ static PaError GetAlsaStreamPointer( PaStream* s, PaAlsaStream** stream )
46514651
PA_ENSURE( PaUtil_GetHostApiRepresentation( &hostApi, paALSA ) );
46524652
alsaHostApi = (PaAlsaHostApiRepresentation*)hostApi;
46534653

4654-
PA_UNLESS( PA_STREAM_REP( s )->streamInterface == &alsaHostApi->callbackStreamInterface
4655-
|| PA_STREAM_REP( s )->streamInterface == &alsaHostApi->blockingStreamInterface,
4654+
PA_UNLESS( s->streamInterface == &alsaHostApi->callbackStreamInterface
4655+
|| s->streamInterface == &alsaHostApi->blockingStreamInterface,
46564656
paIncompatibleStreamHostApi );
46574657

46584658
*stream = (PaAlsaStream*)s;

src/hostapi/asio/pa_asio.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4215,8 +4215,8 @@ static PaError GetAsioStreamPointer( PaAsioStream **stream, PaStream *s )
42154215

42164216
asioHostApi = (PaAsioHostApiRepresentation*)hostApi;
42174217

4218-
if( PA_STREAM_REP( s )->streamInterface == &asioHostApi->callbackStreamInterface
4219-
|| PA_STREAM_REP( s )->streamInterface == &asioHostApi->blockingStreamInterface )
4218+
if( s->streamInterface == &asioHostApi->callbackStreamInterface
4219+
|| s->streamInterface == &asioHostApi->blockingStreamInterface )
42204220
{
42214221
/* s is an ASIO stream */
42224222
*stream = (PaAsioStream *)s;

src/hostapi/wmme/pa_win_wmme.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3966,8 +3966,8 @@ static PaError GetWinMMEStreamPointer( PaWinMmeStream **stream, PaStream *s )
39663966
/* note, the following would be easier if there was a generic way of testing
39673967
that a stream belongs to a specific host API */
39683968

3969-
if( PA_STREAM_REP( s )->streamInterface == &winMmeHostApi->callbackStreamInterface
3970-
|| PA_STREAM_REP( s )->streamInterface == &winMmeHostApi->blockingStreamInterface )
3969+
if( s->streamInterface == &winMmeHostApi->callbackStreamInterface
3970+
|| s->streamInterface == &winMmeHostApi->blockingStreamInterface )
39713971
{
39723972
/* s is a WinMME stream */
39733973
*stream = (PaWinMmeStream *)s;

0 commit comments

Comments
 (0)