亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? pa_unix.c

?? 一個任天堂掌上游戲機NDS的源代碼
?? C
?? 第 1 頁 / 共 3 頁
字號:
 */

#define SCHEDULER_POLICY         SCHED_RR
#define WATCHDOG_MAX_SECONDS    (3)
#define WATCHDOG_INTERVAL_USEC  (1000000)

static int PaHost_CanaryProc( PaHostSoundControl   *pahsc )
{
    int   result = 0;

#ifdef GNUSTEP
    GSRegisterCurrentThread(); /* SB20010904 */
#endif

    while( pahsc->pahsc_CanaryRun) {
      usleep( WATCHDOG_INTERVAL_USEC );
      gettimeofday( &pahsc->pahsc_CanaryTime, NULL );
    }

    DBUG(("PaHost_CanaryProc: exiting.\n"));

#ifdef GNUSTEP
    GSUnregisterCurrentThread();  /* SB20010904 */
#endif

    return result;
}

/*******************************************************************************************
 * Monitor audio thread and lower its it if it hogs the CPU.
 * To prevent getting killed, the audio thread must update a
 * variable with a timer value.
 * If the value is not recent enough, then the
 * thread will get killed.
 */

static PaError PaHost_WatchDogProc( PaHostSoundControl   *pahsc )
{
    struct sched_param    schp = { 0 };
    int                   maxPri;

#ifdef GNUSTEP
    GSRegisterCurrentThread(); /* SB20010904 */
#endif

/* Run at a priority level above audio thread so we can still run if it hangs. */
/* Rise more than 1 because of rumored off-by-one scheduler bugs. */
    schp.sched_priority = pahsc->pahsc_AudioPriority + 4;
    maxPri = sched_get_priority_max(SCHEDULER_POLICY);
    if( schp.sched_priority > maxPri ) schp.sched_priority = maxPri;

    if (sched_setscheduler(0, SCHEDULER_POLICY, &schp) != 0)
    {
        ERR_RPT(("PaHost_WatchDogProc: cannot set watch dog priority!\n"));
        goto killAudio;
    }

    /* Compare watchdog time with audio and canary thread times. */
    /* Sleep for a while or until thread cancelled. */
    while( pahsc->pahsc_WatchDogRun )
    {

        int              delta;
        struct timeval   currentTime;

        usleep( WATCHDOG_INTERVAL_USEC );
        gettimeofday( &currentTime, NULL );

        /* If audio thread is not advancing, then it must be hung so kill it. */
        delta = currentTime.tv_sec - pahsc->pahsc_EntryTime.tv_sec;
        DBUG(("PaHost_WatchDogProc: audio delta = %d\n", delta ));
        if( delta > WATCHDOG_MAX_SECONDS )
        {
            goto killAudio;
        }

        /* If canary died, then lower audio priority and halt canary. */
        delta = currentTime.tv_sec - pahsc->pahsc_CanaryTime.tv_sec;
        if( delta > WATCHDOG_MAX_SECONDS )
        {
            ERR_RPT(("PaHost_WatchDogProc: canary died!\n"));
            goto lowerAudio;
        }
    }

    DBUG(("PaHost_WatchDogProc: exiting.\n"));
#ifdef GNUSTEP
    GSUnregisterCurrentThread();  /* SB20010904 */
#endif
    return 0;

lowerAudio:
    {
        struct sched_param    schat = { 0 };
        if( sched_setscheduler(pahsc->pahsc_AudioThreadPID, SCHED_OTHER, &schat) != 0)
        {
            ERR_RPT(("PaHost_WatchDogProc: failed to lower audio priority. errno = %d\n", errno ));
            /* Fall through into killing audio thread. */
        }
        else
        {
            ERR_RPT(("PaHost_WatchDogProc: lowered audio priority to prevent hogging of CPU.\n"));
            goto cleanup;
        }
    }

killAudio:
    ERR_RPT(("PaHost_WatchDogProc: killing hung audio thread!\n"));
    pthread_kill( pahsc->pahsc_AudioThread, SIGKILL );

cleanup:
    pahsc->pahsc_CanaryRun = 0;
    DBUG(("PaHost_WatchDogProc: cancel Canary\n"));
    pthread_cancel( pahsc->pahsc_CanaryThread );
    DBUG(("PaHost_WatchDogProc: join Canary\n"));
    pthread_join( pahsc->pahsc_CanaryThread, NULL );
    DBUG(("PaHost_WatchDogProc: forget Canary\n"));
    pahsc->pahsc_IsCanaryThreadValid = 0;

#ifdef GNUSTEP
    GSUnregisterCurrentThread();  /* SB20010904 */
#endif
    return 0;
}

/*******************************************************************************************/
static void PaHost_StopWatchDog( PaHostSoundControl   *pahsc )
{
/* Cancel WatchDog thread if there is one. */
    if( pahsc->pahsc_IsWatchDogThreadValid )
    {
        pahsc->pahsc_WatchDogRun = 0;
        DBUG(("PaHost_StopWatchDog: cancel WatchDog\n"));
        pthread_cancel( pahsc->pahsc_WatchDogThread );
        pthread_join( pahsc->pahsc_WatchDogThread, NULL );
        pahsc->pahsc_IsWatchDogThreadValid = 0;
    }
/* Cancel Canary thread if there is one. */
    if( pahsc->pahsc_IsCanaryThreadValid )
    {
        pahsc->pahsc_CanaryRun = 0;
        DBUG(("PaHost_StopWatchDog: cancel Canary\n"));
        pthread_cancel( pahsc->pahsc_CanaryThread );
        DBUG(("PaHost_StopWatchDog: join Canary\n"));
        pthread_join( pahsc->pahsc_CanaryThread, NULL );
        pahsc->pahsc_IsCanaryThreadValid = 0;
    }
}

/*******************************************************************************************/
static PaError PaHost_StartWatchDog( PaHostSoundControl   *pahsc )
{
    int      hres;
    PaError  result = 0;

    /* The watch dog watches for these timer updates */
    gettimeofday( &pahsc->pahsc_EntryTime, NULL );
    gettimeofday( &pahsc->pahsc_CanaryTime, NULL );

    /* Launch a canary thread to detect priority abuse. */
    pahsc->pahsc_CanaryRun = 1;
    hres = pthread_create(&(pahsc->pahsc_CanaryThread),
                      NULL /*pthread_attr_t * attr*/,
                      (pthread_function_t)PaHost_CanaryProc, pahsc);
    if( hres != 0 )
    {
        pahsc->pahsc_IsCanaryThreadValid = 0;
        result = paHostError;
        sPaHostError = hres;
        goto error;
    }
    pahsc->pahsc_IsCanaryThreadValid = 1;

    /* Launch a watchdog thread to prevent runaway audio thread. */
    pahsc->pahsc_WatchDogRun = 1;
    hres = pthread_create(&(pahsc->pahsc_WatchDogThread),
                      NULL /*pthread_attr_t * attr*/,
                      (pthread_function_t)PaHost_WatchDogProc, pahsc);
    if( hres != 0 )
    {
        pahsc->pahsc_IsWatchDogThreadValid = 0;
        result = paHostError;
        sPaHostError = hres;
        goto error;
    }
    pahsc->pahsc_IsWatchDogThreadValid = 1;
    return result;

error:
    PaHost_StopWatchDog( pahsc );
    return result;
}

/*******************************************************************************************
 * Bump priority of audio thread if running with superuser priveledges.
 * if priority bumped then launch a watchdog.
 */
static PaError PaHost_BoostPriority( internalPortAudioStream *past )
{
    PaHostSoundControl  *pahsc;
    PaError              result = paNoError;
    struct sched_param   schp = { 0 };

    pahsc = (PaHostSoundControl *) past->past_DeviceData;
    if( pahsc == NULL ) return paInternalError;

    pahsc->pahsc_AudioThreadPID = getpid();
    DBUG(("PaHost_BoostPriority: audio PID = %d\n", pahsc->pahsc_AudioThreadPID ));

    /* Choose a priority in the middle of the range. */
    pahsc->pahsc_AudioPriority = (sched_get_priority_max(SCHEDULER_POLICY) -
                                  sched_get_priority_min(SCHEDULER_POLICY)) / 2;
    schp.sched_priority = pahsc->pahsc_AudioPriority;

    if (sched_setscheduler(0, SCHEDULER_POLICY, &schp) != 0)
    {
        DBUG(("PortAudio: only superuser can use real-time priority.\n"));
    }
    else
    {
        DBUG(("PortAudio: audio callback priority set to level %d!\n", schp.sched_priority));
        /* We are running at high priority so we should have a watchdog in case audio goes wild. */
        result = PaHost_StartWatchDog( pahsc );
    }

    return result;
}

/*******************************************************************************************/
static PaError Pa_AudioThreadProc( internalPortAudioStream   *past )
{
    PaError      result;
    PaHostSoundControl             *pahsc;
    ssize_t      bytes_read, bytes_written;

    pahsc = (PaHostSoundControl *) past->past_DeviceData;
    if( pahsc == NULL ) return paInternalError;

#ifdef GNUSTEP
    GSRegisterCurrentThread(); /* SB20010904 */
#endif

    result = PaHost_BoostPriority( past );
    if( result < 0 ) goto error;

    past->past_IsActive = 1;
    DBUG(("entering thread.\n"));

    while( (past->past_StopNow == 0) && (past->past_StopSoon == 0) )
    {
        /* Read data from device */
        if(pahsc->pahsc_NativeInputBuffer)
        {
            unsigned int totalread = 0;
            DBUG(("Pa_AudioThreadProc: attempt to read %d bytes\n", pahsc->pahsc_BytesPerInputBuffer));
            do
            {
                bytes_read = read(pahsc->pahsc_InputHandle,
                    (char *)pahsc->pahsc_NativeInputBuffer + totalread,
                    pahsc->pahsc_BytesPerInputBuffer - totalread);

                if (bytes_read < 0)
                {
                    ERR_RPT(("PortAudio: read interrupted!\n"));
                    break;
                }

                totalread += bytes_read;
            } while( totalread < pahsc->pahsc_BytesPerInputBuffer);
        }

        /* Convert 16 bit native data to user data and call user routine. */
        DBUG(("converting...\n"));
        Pa_StartUsageCalculation( past );
        result = Pa_CallConvertInt16( past,
                                      pahsc->pahsc_NativeInputBuffer,
                                      pahsc->pahsc_NativeOutputBuffer );
        Pa_EndUsageCalculation( past );
        if( result != 0)
        {
            DBUG(("hmm, Pa_CallConvertInt16() says: %d. i'm bailing.\n",
                  result));
            break;
        }

        /* Write data to device. */
        if( pahsc->pahsc_NativeOutputBuffer )
        {
            unsigned int totalwritten = 0;
            do
            {
                bytes_written = write(pahsc->pahsc_OutputHandle,
                    (void *)pahsc->pahsc_NativeOutputBuffer,
                    pahsc->pahsc_BytesPerOutputBuffer);
                if( bytes_written < 0 )
                {
                    ERR_RPT(("PortAudio: write interrupted!"));
                    break;
                }

                totalwritten += bytes_written;
            } while( totalwritten < pahsc->pahsc_BytesPerOutputBuffer);
        }

        Pa_UpdateStreamTime(pahsc);
    }
    DBUG(("Pa_AudioThreadProc: left audio loop.\n"));

    past->past_IsActive = 0;
    PaHost_StopWatchDog( pahsc );

error:
    DBUG(("leaving audio thread.\n"));
#ifdef GNUSTEP
    GSUnregisterCurrentThread();  /* SB20010904 */
#endif
    return result;
}

/*************************************************************************
** Determine minimum number of buffers required for this host based
** on minimum latency. Latency can be optionally set by user by setting
** an environment variable. For example, to set latency to 200 msec, put:
**
**    set PA_MIN_LATENCY_MSEC=200
**
** in the cshrc file.
*/
#define PA_LATENCY_ENV_NAME  ("PA_MIN_LATENCY_MSEC")

int Pa_GetMinNumBuffers( int framesPerBuffer, double framesPerSecond )
{
    int minBuffers;
    int minLatencyMsec = MIN_LATENCY_MSEC;
    char *minLatencyText = getenv(PA_LATENCY_ENV_NAME);
    if( minLatencyText != NULL )
    {
        PRINT(("PA_MIN_LATENCY_MSEC = %s\n", minLatencyText ));
        minLatencyMsec = atoi( minLatencyText );
        if( minLatencyMsec < 1 ) minLatencyMsec = 1;
        else if( minLatencyMsec > 5000 ) minLatencyMsec = 5000;
    }

    minBuffers = (int) ((minLatencyMsec * framesPerSecond) / ( 1000.0 * framesPerBuffer ));
    if( minBuffers < 2 ) minBuffers = 2;
    return minBuffers;
}

/*******************************************************************/
PaError PaHost_OpenStream( internalPortAudioStream   *past )
{
    PaError          result = paNoError;
    PaHostSoundControl *pahsc;
    unsigned int     minNumBuffers;
    internalPortAudioDevice *pad;
    DBUG(("PaHost_OpenStream() called.\n" ));

    /* Allocate and initialize host data. */
    pahsc = (PaHostSoundControl *) malloc(sizeof(PaHostSoundControl));
    if( pahsc == NULL )
    {
        result = paInsufficientMemory;
        goto error;
    }
    memset( pahsc, 0, sizeof(PaHostSoundControl) );
    past->past_DeviceData = (void *) pahsc;

    pahsc->pahsc_OutputHandle = BAD_DEVICE_ID; /* No device currently opened. */
    pahsc->pahsc_InputHandle = BAD_DEVICE_ID;
    pahsc->pahsc_IsAudioThreadValid = 0;
    pahsc->pahsc_IsWatchDogThreadValid = 0;

    /* Allocate native buffers. */
    pahsc->pahsc_BytesPerInputBuffer = past->past_FramesPerUserBuffer *
                                       past->past_NumInputChannels * sizeof(short);

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
www.欧美色图| 精品入口麻豆88视频| 久久综合网色—综合色88| 综合久久综合久久| 91啪九色porn原创视频在线观看| 精品久久久久久久人人人人传媒| 天天综合网 天天综合色| 欧美综合亚洲图片综合区| 欧美国产精品劲爆| 国产久卡久卡久卡久卡视频精品| 日韩一区二区三区免费看| 亚洲午夜免费福利视频| 欧美二区三区的天堂| 夜夜精品浪潮av一区二区三区| av电影在线观看一区| 亚洲欧美另类久久久精品 | 136国产福利精品导航| 国产一区二区精品久久99| 久久亚洲欧美国产精品乐播| 丁香婷婷综合网| 亚洲色图制服诱惑| 欧美亚洲愉拍一区二区| 免费人成在线不卡| 国产精品午夜春色av| 色偷偷久久人人79超碰人人澡| 亚洲女同女同女同女同女同69| 在线观看欧美日本| 国产一区二区三区综合| 亚洲欧洲性图库| 91精品国产一区二区三区| 国产一区二区免费在线| 成人免费一区二区三区在线观看| 欧美在线一区二区| 国产传媒日韩欧美成人| 亚洲国产精品一区二区www| 精品人伦一区二区色婷婷| 91麻豆蜜桃一区二区三区| 欧美aa在线视频| 亚洲一区二区三区影院| 欧美国产精品劲爆| 精品av综合导航| 日韩亚洲欧美高清| 欧美一区二区三区免费| 99久久99久久久精品齐齐| 国产成人啪免费观看软件 | 日韩精品影音先锋| 884aa四虎影成人精品一区| 91香蕉视频mp4| av网站免费线看精品| 国产91综合网| 国产乱国产乱300精品| 国产久卡久卡久卡久卡视频精品| 日本午夜精品视频在线观看| 亚洲韩国一区二区三区| 日韩美女久久久| 亚洲欧美激情在线| 亚洲gay无套男同| 亚洲444eee在线观看| 亚洲国产精品人人做人人爽| 亚洲国产精品久久艾草纯爱| 偷偷要91色婷婷| 蜜臂av日日欢夜夜爽一区| 蜜桃视频在线观看一区| 国产一区二区三区观看| 91色porny蝌蚪| 日韩三级免费观看| 欧美激情一区二区三区不卡 | 偷拍亚洲欧洲综合| 免费成人在线观看| 色妹子一区二区| 久久这里只有精品视频网| 久久色在线观看| 亚洲黄色小说网站| 青娱乐精品视频| 国产成人免费视频网站高清观看视频| 国产成人aaaa| 欧美在线观看一区| 欧美亚洲国产怡红院影院| 7878成人国产在线观看| 国产精品久久久久aaaa樱花| 午夜视频一区在线观看| 91色porny蝌蚪| 国产欧美日韩不卡免费| 亚洲国产欧美另类丝袜| 国产999精品久久| 日韩欧美123| 日韩不卡手机在线v区| 91免费精品国自产拍在线不卡| 91精品国产综合久久福利软件| 日韩理论在线观看| 99精品视频中文字幕| 国产视频一区二区在线| 韩国欧美国产1区| 亚洲综合丁香婷婷六月香| 欧美一级二级三级蜜桃| 亚洲国产aⅴ成人精品无吗| 91无套直看片红桃| 亚洲一区av在线| 这里是久久伊人| 日本sm残虐另类| 日韩免费视频一区| 久88久久88久久久| 亚洲精品一区二区三区99| 蜜桃久久av一区| 国产欧美一区二区精品仙草咪| 国产麻豆欧美日韩一区| 国产日本亚洲高清| 99国产麻豆精品| 亚洲成人免费观看| 久久综合久久鬼色中文字| 国产成人av电影在线| 一区二区三区欧美在线观看| 欧美剧情片在线观看| 韩国精品一区二区| 国产精品欧美一区喷水| 欧美性生活久久| 国产激情偷乱视频一区二区三区| 亚洲日本va午夜在线影院| 欧美日韩国产高清一区| 国产成人在线免费| 视频一区欧美日韩| 国产日韩视频一区二区三区| 欧美性猛交xxxx乱大交退制版| 久久国产三级精品| 亚洲精品一二三四区| 久久亚洲精品国产精品紫薇| 欧美这里有精品| 色综合天天做天天爱| 激情综合网最新| 午夜视频一区二区三区| 亚洲综合视频在线| 国产精品久久国产精麻豆99网站| 成人午夜看片网址| 奇米影视在线99精品| 91精品免费在线观看| 国产精品综合视频| 日韩精品一区第一页| 亚洲图片你懂的| 精品国精品自拍自在线| 欧美视频一区二区三区在线观看| 卡一卡二国产精品| 午夜电影网一区| 久久亚洲私人国产精品va媚药| 在线观看日韩国产| 成人免费看片app下载| 久久国产精品色婷婷| 五月婷婷激情综合| 午夜不卡在线视频| 亚洲第一精品在线| 一区二区三区四区五区视频在线观看| 久久午夜色播影院免费高清| 欧美一二三四区在线| 91丨porny丨在线| 亚洲一二三四久久| 捆绑紧缚一区二区三区视频| 九九久久精品视频| 国产jizzjizz一区二区| 国产毛片精品国产一区二区三区| 久久精品国产精品青草| 日韩精品三区四区| 国产裸体歌舞团一区二区| 蜜桃精品视频在线| 国产乱码字幕精品高清av| 国产麻豆成人传媒免费观看| caoporen国产精品视频| 91网站在线播放| 8v天堂国产在线一区二区| www精品美女久久久tv| 亚洲精品中文字幕在线观看| 国内精品国产成人| 国产电影精品久久禁18| 日本精品裸体写真集在线观看| 91精品国产综合久久久蜜臀粉嫩| 亚洲精品一区二区三区福利| 亚洲精品五月天| 蜜桃视频免费观看一区| 97精品超碰一区二区三区| 91精品免费观看| 亚洲人成影院在线观看| 狠狠久久亚洲欧美| 91免费视频大全| 久久久久久久久久久电影| 蜜桃视频在线观看一区| 日韩高清一区在线| 五月激情综合婷婷| 欧美色图天堂网| 91丨九色丨蝌蚪富婆spa| 99久久婷婷国产精品综合| 色婷婷av一区二区三区软件| 99天天综合性| 国产欧美日韩中文久久| 国产麻豆精品视频| 久久人人97超碰com| 看片的网站亚洲| 久久综合狠狠综合久久综合88| 亚洲va韩国va欧美va| 国产精品456露脸| 激情六月婷婷久久| 粉嫩av亚洲一区二区图片| 成人av综合在线|