⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pa_skeleton.c

📁 mediastreamer2是开源的网络传输媒体流的库
💻 C
📖 第 1 页 / 共 2 页
字号:
        inputSampleFormat = hostInputSampleFormat = paInt16; /* Surpress 'uninitialised var' warnings. */    }    if( outputParameters )    {        outputChannelCount = outputParameters->channelCount;        outputSampleFormat = outputParameters->sampleFormat;                /* unless alternate device specification is supported, reject the use of            paUseHostApiSpecificDeviceSpecification */        if( outputParameters->device == paUseHostApiSpecificDeviceSpecification )            return paInvalidDevice;        /* check that output device can support inputChannelCount */        if( outputChannelCount > hostApi->deviceInfos[ outputParameters->device ]->maxOutputChannels )            return paInvalidChannelCount;        /* validate outputStreamInfo */        if( outputParameters->hostApiSpecificStreamInfo )            return paIncompatibleHostApiSpecificStreamInfo; /* this implementation doesn't use custom stream info */        /* IMPLEMENT ME - establish which  host formats are available */        hostOutputSampleFormat =            PaUtil_SelectClosestAvailableFormat( paInt16 /* native formats */, outputSampleFormat );    }    else    {        outputChannelCount = 0;        outputSampleFormat = hostOutputSampleFormat = paInt16; /* Surpress 'uninitialized var' warnings. */    }    /*        IMPLEMENT ME:        ( the following two checks are taken care of by PaUtil_InitializeBufferProcessor() FIXME - checks needed? )            - check that input device can support inputSampleFormat, or that                we have the capability to convert from outputSampleFormat to                a native format            - check that output device can support outputSampleFormat, or that                we have the capability to convert from outputSampleFormat to                a native format            - if a full duplex stream is requested, check that the combination                of input and output parameters is supported            - check that the device supports sampleRate            - alter sampleRate to a close allowable rate if possible / necessary            - validate suggestedInputLatency and suggestedOutputLatency parameters,                use default values where necessary    */    /* validate platform specific flags */    if( (streamFlags & paPlatformSpecificFlags) != 0 )        return paInvalidFlag; /* unexpected platform specific flag */    stream = (PaSkeletonStream*)PaUtil_AllocateMemory( sizeof(PaSkeletonStream) );    if( !stream )    {        result = paInsufficientMemory;        goto error;    }    if( streamCallback )    {        PaUtil_InitializeStreamRepresentation( &stream->streamRepresentation,                                               &skeletonHostApi->callbackStreamInterface, streamCallback, userData );    }    else    {        PaUtil_InitializeStreamRepresentation( &stream->streamRepresentation,                                               &skeletonHostApi->blockingStreamInterface, streamCallback, userData );    }    PaUtil_InitializeCpuLoadMeasurer( &stream->cpuLoadMeasurer, sampleRate );    /* we assume a fixed host buffer size in this example, but the buffer processor        can also support bounded and unknown host buffer sizes by passing         paUtilBoundedHostBufferSize or paUtilUnknownHostBufferSize instead of        paUtilFixedHostBufferSize below. */            result =  PaUtil_InitializeBufferProcessor( &stream->bufferProcessor,              inputChannelCount, inputSampleFormat, hostInputSampleFormat,              outputChannelCount, outputSampleFormat, hostOutputSampleFormat,              sampleRate, streamFlags, framesPerBuffer,              framesPerHostBuffer, paUtilFixedHostBufferSize,              streamCallback, userData );    if( result != paNoError )        goto error;    /*        IMPLEMENT ME: initialise the following fields with estimated or actual        values.    */    stream->streamRepresentation.streamInfo.inputLatency =            PaUtil_GetBufferProcessorInputLatency(&stream->bufferProcessor);    stream->streamRepresentation.streamInfo.outputLatency =            PaUtil_GetBufferProcessorOutputLatency(&stream->bufferProcessor);    stream->streamRepresentation.streamInfo.sampleRate = sampleRate;        /*        IMPLEMENT ME:            - additional stream setup + opening    */    stream->framesPerHostCallback = framesPerHostBuffer;    *s = (PaStream*)stream;    return result;error:    if( stream )        PaUtil_FreeMemory( stream );    return result;}/*    ExampleHostProcessingLoop() illustrates the kind of processing which may    occur in a host implementation. */static void ExampleHostProcessingLoop( void *inputBuffer, void *outputBuffer, void *userData ){    PaSkeletonStream *stream = (PaSkeletonStream*)userData;    PaStreamCallbackTimeInfo timeInfo = {0,0,0}; /* IMPLEMENT ME */    int callbackResult;    unsigned long framesProcessed;        PaUtil_BeginCpuLoadMeasurement( &stream->cpuLoadMeasurer );        /*        IMPLEMENT ME:            - generate timing information            - handle buffer slips    */    /*        If you need to byte swap or shift inputBuffer to convert it into a        portaudio format, do it here.    */    PaUtil_BeginBufferProcessing( &stream->bufferProcessor, &timeInfo, 0 /* IMPLEMENT ME: pass underflow/overflow flags when necessary */ );    /*        depending on whether the host buffers are interleaved, non-interleaved        or a mixture, you will want to call PaUtil_SetInterleaved*Channels(),        PaUtil_SetNonInterleaved*Channel() or PaUtil_Set*Channel() here.    */        PaUtil_SetInputFrameCount( &stream->bufferProcessor, 0 /* default to host buffer size */ );    PaUtil_SetInterleavedInputChannels( &stream->bufferProcessor,            0, /* first channel of inputBuffer is channel 0 */            inputBuffer,            0 ); /* 0 - use inputChannelCount passed to init buffer processor */    PaUtil_SetOutputFrameCount( &stream->bufferProcessor, 0 /* default to host buffer size */ );    PaUtil_SetInterleavedOutputChannels( &stream->bufferProcessor,            0, /* first channel of outputBuffer is channel 0 */            outputBuffer,            0 ); /* 0 - use outputChannelCount passed to init buffer processor */    /* you must pass a valid value of callback result to PaUtil_EndBufferProcessing()        in general you would pass paContinue for normal operation, and        paComplete to drain the buffer processor's internal output buffer.        You can check whether the buffer processor's output buffer is empty        using PaUtil_IsBufferProcessorOuputEmpty( bufferProcessor )    */    callbackResult = paContinue;    framesProcessed = PaUtil_EndBufferProcessing( &stream->bufferProcessor, &callbackResult );        /*        If you need to byte swap or shift outputBuffer to convert it to        host format, do it here.    */    PaUtil_EndCpuLoadMeasurement( &stream->cpuLoadMeasurer, framesProcessed );    if( callbackResult == paContinue )    {        /* nothing special to do */    }    else if( callbackResult == paAbort )    {        /* IMPLEMENT ME - finish playback immediately  */        /* once finished, call the finished callback */        if( stream->streamRepresentation.streamFinishedCallback != 0 )            stream->streamRepresentation.streamFinishedCallback( stream->streamRepresentation.userData );    }    else    {        /* User callback has asked us to stop with paComplete or other non-zero value */        /* IMPLEMENT ME - finish playback once currently queued audio has completed  */        /* once finished, call the finished callback */        if( stream->streamRepresentation.streamFinishedCallback != 0 )            stream->streamRepresentation.streamFinishedCallback( stream->streamRepresentation.userData );    }}/*    When CloseStream() is called, the multi-api layer ensures that    the stream has already been stopped or aborted.*/static PaError CloseStream( PaStream* s ){    PaError result = paNoError;    PaSkeletonStream *stream = (PaSkeletonStream*)s;    /*        IMPLEMENT ME:            - additional stream closing + cleanup    */    PaUtil_TerminateBufferProcessor( &stream->bufferProcessor );    PaUtil_TerminateStreamRepresentation( &stream->streamRepresentation );    PaUtil_FreeMemory( stream );    return result;}static PaError StartStream( PaStream *s ){    PaError result = paNoError;    PaSkeletonStream *stream = (PaSkeletonStream*)s;    PaUtil_ResetBufferProcessor( &stream->bufferProcessor );    /* IMPLEMENT ME, see portaudio.h for required behavior */    /* suppress unused function warning. the code in ExampleHostProcessingLoop or       something similar should be implemented to feed samples to and from the       host after StartStream() is called.    */    (void) ExampleHostProcessingLoop;    return result;}static PaError StopStream( PaStream *s ){    PaError result = paNoError;    PaSkeletonStream *stream = (PaSkeletonStream*)s;    /* suppress unused variable warnings */    (void) stream;    /* IMPLEMENT ME, see portaudio.h for required behavior */    return result;}static PaError AbortStream( PaStream *s ){    PaError result = paNoError;    PaSkeletonStream *stream = (PaSkeletonStream*)s;    /* suppress unused variable warnings */    (void) stream;        /* IMPLEMENT ME, see portaudio.h for required behavior */    return result;}static PaError IsStreamStopped( PaStream *s ){    PaSkeletonStream *stream = (PaSkeletonStream*)s;    /* suppress unused variable warnings */    (void) stream;        /* IMPLEMENT ME, see portaudio.h for required behavior */    return 0;}static PaError IsStreamActive( PaStream *s ){    PaSkeletonStream *stream = (PaSkeletonStream*)s;    /* suppress unused variable warnings */    (void) stream;        /* IMPLEMENT ME, see portaudio.h for required behavior */    return 0;}static PaTime GetStreamTime( PaStream *s ){    PaSkeletonStream *stream = (PaSkeletonStream*)s;    /* suppress unused variable warnings */    (void) stream;        /* IMPLEMENT ME, see portaudio.h for required behavior*/    return 0;}static double GetStreamCpuLoad( PaStream* s ){    PaSkeletonStream *stream = (PaSkeletonStream*)s;    return PaUtil_GetCpuLoad( &stream->cpuLoadMeasurer );}/*    As separate stream interfaces are used for blocking and callback    streams, the following functions can be guaranteed to only be called    for blocking streams.*/static PaError ReadStream( PaStream* s,                           void *buffer,                           unsigned long frames ){    PaSkeletonStream *stream = (PaSkeletonStream*)s;    /* suppress unused variable warnings */    (void) buffer;    (void) frames;    (void) stream;        /* IMPLEMENT ME, see portaudio.h for required behavior*/    return paNoError;}static PaError WriteStream( PaStream* s,                            const void *buffer,                            unsigned long frames ){    PaSkeletonStream *stream = (PaSkeletonStream*)s;    /* suppress unused variable warnings */    (void) buffer;    (void) frames;    (void) stream;        /* IMPLEMENT ME, see portaudio.h for required behavior*/    return paNoError;}static signed long GetStreamReadAvailable( PaStream* s ){    PaSkeletonStream *stream = (PaSkeletonStream*)s;    /* suppress unused variable warnings */    (void) stream;        /* IMPLEMENT ME, see portaudio.h for required behavior*/    return 0;}static signed long GetStreamWriteAvailable( PaStream* s ){    PaSkeletonStream *stream = (PaSkeletonStream*)s;    /* suppress unused variable warnings */    (void) stream;        /* IMPLEMENT ME, see portaudio.h for required behavior*/    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -