Beispiel #1
0
bool CDispatcherContext::create_thread_pool()
{        
    try
    {                                    
        // 创建线程池
        // 只有CThread::before_start返回false,create才会返回false
        _thread_pool = new CSendThreadPool;
        _thread_pool->create(_thread_count, this);
        DISPATCHER_LOG_INFO("Sender thread number is %d.\n", _thread_pool->get_thread_count());

        CSendThread** send_thread = _thread_pool->get_thread_array();
        uint16_t thread_count = _thread_pool->get_thread_count();
        for (uint16_t i=0; i<thread_count; ++i)
        {                        
            send_thread[i]->wakeup();
        }

        return true;
    }
    catch (sys::CSyscallException& syscall_ex)
    {
        delete _thread_pool;
        DISPATCHER_LOG_ERROR("Failed to create thread pool: %s.\n", syscall_ex.str().c_str());
    }

    return false;
}
Beispiel #2
0
DISPATCHER_NAMESPACE_BEGIN

bool check_sender_info(const SenderInfo& sender_info)
{
    //sender_info.key
    //sender_info.ip_node
    //sender_info.queue_size
    //sender_info.resend_times
    //sender_info.reconnect_times
    //sender_info.reply_handler

    if (0 == sender_info.queue_size)
    {
        DISPATCHER_LOG_ERROR("Invalid %s.\n", sender_info_tostring(sender_info).c_str());
        return false;
    }

    return true;
}
Beispiel #3
0
mfxStatus MFX_DISP_HANDLE::LoadSelectedDLL(const msdk_disp_char *pPath, eMfxImplType implType,
                                           mfxIMPL impl, mfxIMPL implInterface)
{
    mfxStatus mfxRes = MFX_ERR_NONE;

    // check error(s)
    if ((MFX_LIB_SOFTWARE != implType) &&
        (MFX_LIB_HARDWARE != implType))
    {
        DISPATCHER_LOG_ERROR((("implType == %s, should be either MFX_LIB_SOFTWARE ot MFX_LIB_HARDWARE\n"), DispatcherLog_GetMFXImplString(implType).c_str()));
        loadStatus = MFX_ERR_ABORTED;
        return loadStatus;
    }
    // only exact types of implementation is allowed
    if (!(impl & MFX_IMPL_AUDIO) &&
        (MFX_IMPL_SOFTWARE != impl) &&
        (MFX_IMPL_HARDWARE != impl) &&
        (MFX_IMPL_HARDWARE2 != impl) &&
        (MFX_IMPL_HARDWARE3 != impl) &&
        (MFX_IMPL_HARDWARE4 != impl))
    {
        DISPATCHER_LOG_ERROR((("invalid implementation impl == %s\n"), DispatcherLog_GetMFXImplString(impl).c_str()));
        loadStatus = MFX_ERR_ABORTED;
        return loadStatus;
    }        

    // close the handle before initialization
    Close();

    // save the library's type
    this->implType = implType;
    this->impl = impl;
    this->implInterface = implInterface;

    {
        DISPATCHER_LOG_BLOCK(("invoking LoadLibrary(%S)\n", MSDK2WIDE(pPath)));
        // load the DLL into the memory
        hModule = MFX::mfx_dll_load(pPath);
        
        if (hModule)
        {
            int i;

            DISPATCHER_LOG_OPERATION({
                msdk_disp_char modulePath[1024];
                GetModuleFileNameW((HMODULE)hModule, modulePath, sizeof(modulePath)/sizeof(modulePath[0]));
                DISPATCHER_LOG_INFO((("loaded module %S\n"), MSDK2WIDE(modulePath)))
            });

            if (impl & MFX_IMPL_AUDIO)
            {
                // load audio functions: pointers to exposed functions
                for (i = 0; i < eAudioFuncTotal; i += 1)
                {
                    // construct correct name of the function - remove "_a" postfix

                    mfxFunctionPointer pProc = (mfxFunctionPointer) MFX::mfx_dll_get_addr(hModule, APIAudioFunc[i].pName);
    #ifdef ANDROID
                    // on Android very first call to dlsym may fail
                    if (!pProc) pProc = (mfxFunctionPointer) MFX::mfx_dll_get_addr(hModule, APIAudioFunc[i].pName);
    #endif
                    if (pProc)
                    {
                        // function exists in the library,
                        // save the pointer.
                        callAudioTable[i] = pProc;
                    }
                    else
                    {
                        // The library doesn't contain the function
                        DISPATCHER_LOG_WRN((("Can't find API function \"%s\"\n"), APIAudioFunc[i].pName));
                        if (apiVersion.Version >= APIAudioFunc[i].apiVersion.Version)
                        {
                            DISPATCHER_LOG_ERROR((("\"%s\" is required for API %u.%u\n"), APIAudioFunc[i].pName, apiVersion.Major, apiVersion.Minor));
                            mfxRes = MFX_ERR_UNSUPPORTED;
                            break;
                        }
                    }
                }
            }
            else
            {
                // load video functions: pointers to exposed functions
                for (i = 0; i < eVideoFuncTotal; i += 1)
                {
                    mfxFunctionPointer pProc = (mfxFunctionPointer) MFX::mfx_dll_get_addr(hModule, APIFunc[i].pName);
    #ifdef ANDROID
                    // on Android very first call to dlsym may fail
                    if (!pProc) pProc = (mfxFunctionPointer) MFX::mfx_dll_get_addr(hModule, APIFunc[i].pName);
    #endif
                    if (pProc)
                    {
                        // function exists in the library,
                        // save the pointer.
                        callTable[i] = pProc;
                    }
                    else
                    {
                        // The library doesn't contain the function
                        DISPATCHER_LOG_WRN((("Can't find API function \"%s\"\n"), APIFunc[i].pName));
                        if (apiVersion.Version >= APIFunc[i].apiVersion.Version)
                        {
                            DISPATCHER_LOG_ERROR((("\"%s\" is required for API %u.%u\n"), APIFunc[i].pName, apiVersion.Major, apiVersion.Minor));
                            mfxRes = MFX_ERR_UNSUPPORTED;
                            break;
                        }
                    }
                }
            }
        }
        else
        {
Beispiel #4
0
int main(int argc, const char *argv[], bool bUsePrefix)
{
    std::auto_ptr<MFX_DISP_HANDLE> allocatedHandle;
    MFX_DISP_HANDLE *pHandle;
    mfxIMPL impl = MFX_IMPL_AUTO;
    mfxVersion ver = {0, 0};
    int i;

    if ((2 == argc) &&
        ('?' == argv[1][0]))
    {
        printf("USAGE: %s -[s|h] [-v<version>]\n", argv[0]);
        printf("Where:\n");
        printf("    -s  - use MFX_IMPL_SOFTWARE dispatching type (optional).\n");
        printf("    -h  - use MFX_IMPL_HARDWARE dispatching type (optional).\n");
        printf("    -ha - use MFX_IMPL_HARDWARE_ANY dispatching type (optional).\n");
        printf("    -h2 - use MFX_IMPL_HARDWARE2 dispatching type (optional).\n");
        printf("    -h3 - use MFX_IMPL_HARDWARE2 dispatching type (optional).\n");
        printf("    -h4 - use MFX_IMPL_HARDWARE2 dispatching type (optional).\n");
        printf("    -v - use specified API version (optional).\n");
        printf("         <version> can be required in X.Y format\n");
        return -1;
    }

    // parse parameters
    for (i = 1; i < argc; i += 1)
    {
        if ('-' == argv[i][0])
        {
            switch (argv[i][1])
            {
            // use MFX_IMPL_SOFTWARE dispatching type
            case 's':
            case 'S':
                impl = MFX_IMPL_SOFTWARE;
                break;

            // use MFX_IMPL_HARDWARE dispatching type
            case 'h':
            case 'H':
            {
                switch (argv[i][2])
                {
                    case 'a':impl = MFX_IMPL_HARDWARE_ANY;break;
                    case '2':impl = MFX_IMPL_HARDWARE2;break;
                    case '3':impl = MFX_IMPL_HARDWARE3;break;
                    case '4':impl = MFX_IMPL_HARDWARE4;break;
                    default :impl = MFX_IMPL_HARDWARE;break;
                }

                break;
            }
                
            // read specified API version
            case 'v':
            case 'V':
            {
                int x = 2;

                // read major version
                while (('0' <= argv[i][x]) &&
                       ('9' >= argv[i][x]))
                {
                    ver.Major = ver.Major * 10 + (argv[i][x] - '0');
                    x += 1;
                }
                // skip delimiter
                if (argv[i][x])
                {
                    x += 1;
                }
                // read minor version
                while (('0' <= argv[i][x]) &&
                       ('9' >= argv[i][x]))
                {
                    ver.Minor = ver.Minor * 10 + (argv[i][x] - '0');
                    x += 1;
                }
            }
            break;

            default:
                DISPATCHER_LOG_ERROR(("unknown parameter %s. Specify ? flag for help.\n", argv[i]));
                break;
            }
        }
        else
        {
            DISPATCHER_LOG_ERROR(("unknown parameter %s. Specify ? flag for help.\n", argv[i]));
        }
    }

    DISPATCHER_LOG_INFO(("current platform: %s\n", cPlatform));
    DISPATCHER_LOG_INFO(("implementation: %s\n", DispatcherLog_GetMFXImplString(impl).c_str()));

    sdk_library library;

    if (bUsePrefix)
    {
        if (MFX_ERR_NONE == DISPATCHER_EXPOSED_PREFIX(MFXInit)(impl, ver.Version?&ver:NULL, (mfxSession*)&pHandle))
        {
            DISPATCHER_EXPOSED_PREFIX(MFXClose)((mfxSession)pHandle);
        }
    }
    else
    {
        if (MFX_ERR_NONE == MFXInit(impl, ver.Version?&ver:NULL, (mfxSession*)&pHandle))
        {
            MFXClose((mfxSession)pHandle);
        }
    }

    DISPATCHER_LOG_INFO(("DISPRESULT: platform=%-5s impl=%-21s ver=%d.%d : %s\n"
        , cPlatform
        , DispatcherLog_GetMFXImplString(impl).c_str()
        , ver.Major , ver.Minor 
        , library.GetPath().empty()? "NOT FOUND" : library.GetPath().c_str()));

    return 0;

} // int main(int argc, const char *argv[])