1

私はビデオストリーミング用に NPAPI を使用しています。

ただし、Mac Safari (Mt.Lion、v6.0.2) では、読み込み時に CPU 使用率が高くなります (7~80%)。Chrome または FireFox は正常です。

NPNFuncs.invalidaterect 関数を呼び出すと思います。

int16_t PLUGINAPI::handleEvent(void* event)
{
    NPCocoaEvent* cocoaEvent = (NPCocoaEvent*)event;
    ScriptablePluginObject* pObject = (ScriptablePluginObject*)m_pScriptableObject;


    if(cocoaEvent->type == NPCocoaEventDrawRect) {
        CGContextRef cgContext = cocoaEvent->data.draw.context;

        if(!cgContext)
            return true;

        //Add rect and translate the video
        CGContextAddRect(cgContext, CGRectMake (0, 0, m_Window->width, m_Window->height));
        CGContextTranslateCTM(cgContext, 0, m_Window->height);
        CGContextScaleCTM(cgContext, 1.0, -1.0);

        //Display the video here
        if(pObject && pObject->m_pNpapiPlugin) 
            pObject->m_pNpapiPlugin->WEBVIEWER_DisplayFrame(cgContext, m_Window->width, m_Window->height);

        //Fulsh cgcontextref
        CGContextFlush(cgContext);

        //Generate DrawRect event
        NPRect rect = {0, 0, m_Window->height, m_Window->width};
        NPNFuncs.invalidaterect(m_pNPInstance, &rect);
        NPNFuncs.forceredraw(m_pNPInstance);

    } else {

        if(pObject && pObject->m_pNpapiPlugin)
            pObject->m_pNpapiPlugin->WEBVIEWER_SendEvent(cocoaEvent);
    }

    return true;
}

プラグイン描画の別の方法はありますか? または、この問題の解決策が必要です。

4

1 に答える 1

1

できるだけ早く再描画するように指示しています!

NPNFuncs.invalidaterect(m_pNPInstance, &rect);
NPNFuncs.forceredraw(m_pNPInstance);

これを呼び出すと、別の描画イベントがトリガーされます。Safari はおそらく他のブラウザーよりも高速に再描画されるため、CPU を大量に使用している可能性があります。基本的にあなたが言っているのは「描くたびにすぐに描き直せ!」ということです。

描画ハンドラーから invalidateRect と forceRedraw を呼び出す代わりに (これは決して行うべきではありません!)、タイマーを設定します。1 秒あたり 60 フレーム以上を描画している場合、ほとんどのディスプレイはその速度でしか更新されないため、おそらく CPU サイクルを浪費していることに注意してください。通常、ほとんどの場合、最大値として 30 fps をお勧めしますが、それはユーザーとビデオ カードの間です。

于 2012-11-24T15:48:30.640 に答える