Esempio n. 1
0
sdb_location *find_sdb_deep(sdb_record_t *parent_sdb, sdb_location *found_sdb, unsigned int base, unsigned int *idx, unsigned int qty, unsigned int venId, unsigned int devId)
{
     sdb_record_t *record = parent_sdb;
     int records = record->interconnect.sdb_records;
     int i;
     DBPRINT1("base 0x%08x par 0x%08x\n", base, (unsigned int)(unsigned char*)parent_sdb);
     for (i = 0; i < records; ++i, ++record) {
         if (record->empty.record_type == SDB_BRIDGE) {

            if (record->bridge.sdb_component.product.vendor_id.low == venId &&
            record->bridge.sdb_component.product.device_id == devId) {
               DBPRINT1("Target BRG at base 0x%08x 0x%08x  entry %u\n", base, base+record->bridge.sdb_component.addr_first.low, *idx);
               found_sdb[(*idx)].sdb = record;
               found_sdb[(*idx)].adr = base;
               (*idx)++;
            }  
            find_sdb_deep((sdb_record_t *)(base+record->bridge.sdb_child.low), found_sdb, base+record->bridge.sdb_component.addr_first.low, idx, qty, venId, devId);
         }

         if (record->empty.record_type == SDB_DEVICE) {
            if (record->device.sdb_component.product.vendor_id.low == venId &&
            record->device.sdb_component.product.device_id == devId) {
               DBPRINT1("Target DEV at 0x%08x\n", base + record->device.sdb_component.addr_first.low);
               found_sdb[(*idx)].sdb = record;
               found_sdb[(*idx)].adr = base;
               (*idx)++;
            }
         }
         if(*idx >= qty) return found_sdb;
      }
     
     return found_sdb;
}
Esempio n. 2
0
/* ============================================================================================= */
SCODE VencMaster_LoadConfig(HANDLE hVencMObject)
{
	TMasterInfo *ptMasterInfo = (TMasterInfo *)(hVencMObject);

	if (ptMasterInfo == NULL)
		return S_FAIL;

	DBPRINT1("[VENC_MASTER] XmlWrapper read config %s \n", ptMasterInfo->szConfigFile);
	if (XmlWrapper_ReadFile_UsrDefFunc(ptMasterInfo->szConfigFile, ptMasterInfo->hXMLWrapperObj, ptMasterInfo) != S_OK) {
		fprintf(stderr, "[VENC_MASTER] XmlWrapper reload config fail! \n");
		return S_FAIL;
	}

	if (XmlWrapper_Reset(ptMasterInfo->hXMLWrapperObj) != S_OK)  {
		DBPRINT0("[VENC_MASTER] XmlWrapper read config fail! \n");
		return S_FAIL;
	}

	VencMaster_ResPLReConfig(ptMasterInfo);
	VencMaster_WBReConfig(ptMasterInfo);
	VencMaster_CCReConfig(ptMasterInfo);
	VencMaster_TMReConfig(ptMasterInfo);
	VencMaster_BlackClampReConfig(ptMasterInfo);
	VencMaster_DeImpulseReConfig(ptMasterInfo);
	VencMaster_CEReConfig(ptMasterInfo);
	VencMaster_GammaTableReConfig(ptMasterInfo);
	VencMaster_AEReConfig(ptMasterInfo);
	VencMaster_AFReConfig(ptMasterInfo);
	VencMaster_ImgAdjReConfig(ptMasterInfo);
	VencMaster_WDRReConfig(ptMasterInfo);
	return S_OK;
}
Esempio n. 3
0
/* ============================================================================================= */
SCODE Venc_Stop(HANDLE hVencObject)
{
    TVencInfo *ptVencInfo = (TVencInfo *)(hVencObject);
    DWORD	dwCurId;

	if (ptVencInfo->hMsgReaderObj != NULL) {
	    VencMessage_Stop(ptVencInfo->hMsgReaderObj);
		DBPRINT0("[VENC] Message handler stop\n");
	}
#if defined(_VMA_IBPE)
	if (ptVencInfo->hMotionProcObj != NULL) {
	    VencMotion_Stop(ptVencInfo->hMotionProcObj);
	    DBPRINT0("[VENC] Motion sending process stop\n");
	}
#endif
    for (dwCurId = 0; dwCurId < ptVencInfo->tVencCfgPath.dwEncoderTotalNum; dwCurId++) {
    	if (ptVencInfo->phEncoderProcObj[dwCurId] != NULL) {
	#if 0
		    VencEncoder_Stop(ptVencInfo->hEncoderProcObj[dwCurId]);
	#endif
		VencEncoder_Stop(ptVencInfo->phEncoderProcObj[dwCurId]);	
		    DBPRINT1("[VENC] Encoder process %u stop\n", dwCurId);
    	}
	}

#if defined(_VPL_VOC)
	if (ptVencInfo->hDisplayProcObj != NULL) {
	    VencDisplay_Stop(ptVencInfo->hDisplayProcObj);
	    DBPRINT0("[VENC] Display process stop\n");
	}
#endif

	if (ptVencInfo->hVideoInProcObj != NULL) {
	    VencVideoIn_Stop(ptVencInfo->hVideoInProcObj);
	    DBPRINT0("[VENC] VideoIn process stop\n");
	}

	if (ptVencInfo->hMasterProcObj != NULL) {
		VencMaster_Stop(ptVencInfo->hMasterProcObj);
		DBPRINT0("[VENC] Master process stop\n");
	}

    return S_OK;
}
Esempio n. 4
0
static void perform_idle_server_maintenance(apr_pool_t *p)
{
    int i;
    int idle_count;
    worker_score *ws;
    int free_length;
    int free_slots[MAX_SPAWN_RATE];
    int last_non_dead;
    int total_non_dead;

    /* initialize the free_list */
    free_length = 0;

    idle_count = 0;
    last_non_dead = -1;
    total_non_dead = 0;

    for (i = 0; i < ap_threads_limit; ++i) {
        int status;

        if (i >= ap_max_workers_limit && free_length == idle_spawn_rate)
            break;
        ws = &ap_scoreboard_image->servers[0][i];
        status = ws->status;
        if (status == WORKER_DEAD) {
            /* try to keep children numbers as low as possible */
            if (free_length < idle_spawn_rate) {
                free_slots[free_length] = i;
                ++free_length;
            }
        }
        else if (status == WORKER_IDLE_KILL) {
            /* If it is already marked to die, skip it */
            continue;
        }
        else {
            /* We consider a starting server as idle because we started it
            * at least a cycle ago, and if it still hasn't finished starting
            * then we're just going to swamp things worse by forking more.
            * So we hopefully won't need to fork more if we count it.
            * This depends on the ordering of SERVER_READY and SERVER_STARTING.
            */
            if (status <= WORKER_READY) {
                ++ idle_count;
            }

            ++total_non_dead;
            last_non_dead = i;
        }
    }
    DBPRINT2("Total: %d Idle Count: %d  \r", total_non_dead, idle_count);
    ap_max_workers_limit = last_non_dead + 1;
    if (idle_count > ap_threads_max_free) {
        /* kill off one child... we use the pod because that'll cause it to
        * shut down gracefully, in case it happened to pick up a request
        * while we were counting
        */
        idle_spawn_rate = 1;
        ap_update_child_status_from_indexes(0, last_non_dead, WORKER_IDLE_KILL,
                                            (request_rec *) NULL);
        DBPRINT1("\nKilling idle thread: %d\n", last_non_dead);
    }
    else if (idle_count < ap_threads_min_free) {
        /* terminate the free list */
        if (free_length == 0) {
            /* only report this condition once */
            static int reported = 0;

            if (!reported) {
                ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf, APLOGNO(00220)
                    "server reached MaxRequestWorkers setting, consider"
                    " raising the MaxRequestWorkers setting");
                reported = 1;
            }
            idle_spawn_rate = 1;
        }
        else {
            if (idle_spawn_rate >= 8) {
                ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf, APLOGNO(00221)
                    "server seems busy, (you may need "
                    "to increase StartServers, or Min/MaxSpareServers), "
                    "spawning %d children, there are %d idle, and "
                    "%d total children", idle_spawn_rate,
                    idle_count, total_non_dead);
            }
            DBPRINT0("\n");
            for (i = 0; i < free_length; ++i) {
                DBPRINT1("Spawning additional thread slot: %d\n", free_slots[i]);
                make_child(ap_server_conf, free_slots[i]);
            }
            /* the next time around we want to spawn twice as many if this
            * wasn't good enough, but not if we've just done a graceful
            */
            if (hold_off_on_exponential_spawning) {
                --hold_off_on_exponential_spawning;
            }
            else if (idle_spawn_rate < MAX_SPAWN_RATE) {
                idle_spawn_rate *= 2;
            }
        }
    }
    else {
        idle_spawn_rate = 1;
    }
}
Esempio n. 5
0
/*static */
void worker_main(void *arg)
{
    ap_listen_rec *lr, *first_lr, *last_lr = NULL;
    apr_pool_t *ptrans;
    apr_allocator_t *allocator;
    apr_bucket_alloc_t *bucket_alloc;
    conn_rec *current_conn;
    apr_status_t stat = APR_EINIT;
    ap_sb_handle_t *sbh;
    apr_thread_t *thd = NULL;
    apr_os_thread_t osthd;

    int my_worker_num = (int)arg;
    apr_socket_t *csd = NULL;
    int requests_this_child = 0;
    apr_socket_t *sd = NULL;
    fd_set main_fds;

    int sockdes;
    int srv;
    struct timeval tv;
    int wouldblock_retry;

    osthd = apr_os_thread_current();
    apr_os_thread_put(&thd, &osthd, pmain);

    tv.tv_sec = 1;
    tv.tv_usec = 0;

    apr_allocator_create(&allocator);
    apr_allocator_max_free_set(allocator, ap_max_mem_free);

    apr_pool_create_ex(&ptrans, pmain, NULL, allocator);
    apr_allocator_owner_set(allocator, ptrans);
    apr_pool_tag(ptrans, "transaction");

    bucket_alloc = apr_bucket_alloc_create_ex(allocator);

    atomic_inc (&worker_thread_count);

    while (!die_now) {
        /*
        * (Re)initialize this child to a pre-connection state.
        */
        current_conn = NULL;
        apr_pool_clear(ptrans);

        if ((ap_max_requests_per_child > 0
            && requests_this_child++ >= ap_max_requests_per_child)) {
            DBPRINT1 ("\n**Thread slot %d is shutting down", my_worker_num);
            clean_child_exit(0, my_worker_num, ptrans, bucket_alloc);
        }

        ap_update_child_status_from_indexes(0, my_worker_num, WORKER_READY,
                                            (request_rec *) NULL);

        /*
        * Wait for an acceptable connection to arrive.
        */

        for (;;) {
            if (shutdown_pending || restart_pending || (ap_scoreboard_image->servers[0][my_worker_num].status == WORKER_IDLE_KILL)) {
                DBPRINT1 ("\nThread slot %d is shutting down\n", my_worker_num);
                clean_child_exit(0, my_worker_num, ptrans, bucket_alloc);
            }

            /* Check the listen queue on all sockets for requests */
            memcpy(&main_fds, &listenfds, sizeof(fd_set));
            srv = select(listenmaxfd + 1, &main_fds, NULL, NULL, &tv);

            if (srv <= 0) {
                if (srv < 0) {
                    ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf, APLOGNO(00217)
                        "select() failed on listen socket");
                    apr_thread_yield();
                }
                continue;
            }

            /* remember the last_lr we searched last time around so that
            we don't end up starving any particular listening socket */
            if (last_lr == NULL) {
                lr = ap_listeners;
            }
            else {
                lr = last_lr->next;
                if (!lr)
                    lr = ap_listeners;
            }
            first_lr = lr;
            do {
                apr_os_sock_get(&sockdes, lr->sd);
                if (FD_ISSET(sockdes, &main_fds))
                    goto got_listener;
                lr = lr->next;
                if (!lr)
                    lr = ap_listeners;
            } while (lr != first_lr);
            /* if we get here, something unexpected happened. Go back
            into the select state and try again.
            */
            continue;
        got_listener:
            last_lr = lr;
            sd = lr->sd;

            wouldblock_retry = MAX_WB_RETRIES;

            while (wouldblock_retry) {
                if ((stat = apr_socket_accept(&csd, sd, ptrans)) == APR_SUCCESS) {
                    break;
                }
                else {
                    /* if the error is a wouldblock then maybe we were too
                        quick try to pull the next request from the listen
                        queue.  Try a few more times then return to our idle
                        listen state. */
                    if (!APR_STATUS_IS_EAGAIN(stat)) {
                        break;
                    }

                    if (wouldblock_retry--) {
                        apr_thread_yield();
                    }
                }
            }

            /* If we got a new socket, set it to non-blocking mode and process
                it.  Otherwise handle the error. */
            if (stat == APR_SUCCESS) {
                apr_socket_opt_set(csd, APR_SO_NONBLOCK, 0);
#ifdef DBINFO_ON
                if (wouldblock_retry < MAX_WB_RETRIES) {
                    retry_success++;
                    avg_retries += (MAX_WB_RETRIES-wouldblock_retry);
                }
#endif
                break;       /* We have a socket ready for reading */
            }
            else {
#ifdef DBINFO_ON
                if (APR_STATUS_IS_EAGAIN(stat)) {
                        would_block++;
                        retry_fail++;
                }
                else if (
#else
                if (APR_STATUS_IS_EAGAIN(stat) ||
#endif
                    APR_STATUS_IS_ECONNRESET(stat) ||
                    APR_STATUS_IS_ETIMEDOUT(stat) ||
                    APR_STATUS_IS_EHOSTUNREACH(stat) ||
                    APR_STATUS_IS_ENETUNREACH(stat)) {
                        ;
                }
#ifdef USE_WINSOCK
                else if (APR_STATUS_IS_ENETDOWN(stat)) {
                       /*
                        * When the network layer has been shut down, there
                        * is not much use in simply exiting: the parent
                        * would simply re-create us (and we'd fail again).
                        * Use the CHILDFATAL code to tear the server down.
                        * @@@ Martin's idea for possible improvement:
                        * A different approach would be to define
                        * a new APEXIT_NETDOWN exit code, the reception
                        * of which would make the parent shutdown all
                        * children, then idle-loop until it detected that
                        * the network is up again, and restart the children.
                        * Ben Hyde noted that temporary ENETDOWN situations
                        * occur in mobile IP.
                        */
                        ap_log_error(APLOG_MARK, APLOG_EMERG, stat, ap_server_conf, APLOGNO(00218)
                            "apr_socket_accept: giving up.");
                        clean_child_exit(APEXIT_CHILDFATAL, my_worker_num, ptrans,
                                         bucket_alloc);
                }
#endif
                else {
                        ap_log_error(APLOG_MARK, APLOG_ERR, stat, ap_server_conf, APLOGNO(00219)
                            "apr_socket_accept: (client socket)");
                        clean_child_exit(1, my_worker_num, ptrans, bucket_alloc);
                }
            }
        }

        ap_create_sb_handle(&sbh, ptrans, 0, my_worker_num);
        /*
        * We now have a connection, so set it up with the appropriate
        * socket options, file descriptors, and read/write buffers.
        */
        current_conn = ap_run_create_connection(ptrans, ap_server_conf, csd,
                                                my_worker_num, sbh,
                                                bucket_alloc);
        if (current_conn) {
            current_conn->current_thread = thd;
            ap_process_connection(current_conn, csd);
            ap_lingering_close(current_conn);
        }
        request_count++;
    }
    clean_child_exit(0, my_worker_num, ptrans, bucket_alloc);
}
Esempio n. 6
0
/* ============================================================================================= */
SCODE Venc_Initial(HANDLE *phVencObject, TVencInitOpt tVencInitOpt)
{	
    TVencInfo *ptVencInfo = (TVencInfo *)malloc(sizeof(TVencInfo));
	TMasterInitOpt	tMasterInitOpt;
    TVideoInInitOpt tVideoInInitOpt;
    TEncoderInitOpt tEncoderInitOpt;
#if 0    
    TFRCtrlOptions tFRCtrlOptions;
#endif
#ifdef	_VMA_IBPE
	TMotionInitOpt	tMotionInitOpt;
#endif
#ifdef _VPL_VOC
	TDisplayInitOpt tDisplayInitOpt;
#endif	
	DWORD	dwBitStreamSize;
    DWORD	dwCurId;

    if (ptVencInfo == NULL) {
        return ERR_OUT_OF_MEMORY;
    }
    memset(ptVencInfo, 0, sizeof(TVencInfo));
    *phVencObject = (HANDLE)(ptVencInfo);

    if (tVencInitOpt.dwDevNum >= MAX_HW_CHANNELNUM) {
        DBPRINT1("[VENC] Error device number %u !!\n", tVencInitOpt.dwDevNum);
        DBPRINT1("[VENC] The Mozart only supports device 0~%d !!\n", (MAX_HW_CHANNELNUM-1));
        return S_FAIL;
    }
    DBPRINT1("[VENC] Device number %u !!\n", tVencInitOpt.dwDevNum);

    if (!tVencInitOpt.szConfigFile) {
        ptVencInfo->szConfigFile = DEFAULT_CONFIG_FILE;
    }
    else {
        ptVencInfo->szConfigFile = tVencInitOpt.szConfigFile;
    }

    if (access(ptVencInfo->szConfigFile, F_OK) != 0) {
        DBPRINT1("[VENC] Configuration file %s not exist!!\n", ptVencInfo->szConfigFile);
        return S_FAIL;
    }
    DBPRINT1("[VENC] Configuration file %s\n", ptVencInfo->szConfigFile);

    // Create semaphore for thread communicate with critical section variables
    if (sem_init(&(ptVencInfo->smOptions), 0, 1) != 0) {
    	return S_FAIL;
    }

	g_bTerminate = FALSE;

    // Initial memmgr
    if (VencApp_InitMemMgr(&(ptVencInfo->hMemMgrObj)) != S_OK) {
        fprintf(stderr, "[VENC] Initial MemMgr object fail !!\n");
        return S_FAIL;
    }

    // Initial XmlWrapper Instance 
    if (VencApp_InitXmlWrapper(&(ptVencInfo->hXMLWrapperObj)) != S_OK) {
        fprintf(stderr, "[VENC] Initial XMLWrapper object fail !!\n");
        return S_FAIL;
    }

	// read all process config setting about thread create
	if (VencApp_ParseVencConfig(ptVencInfo) != S_OK) {
        DBPRINT0("[VENC] parse venc config fail !!\n");
		return S_FAIL;
	}

	// parse all needed information like MaxFrameSize, CaptureSize ...
	if (VencApp_GetInitNeedInfo(ptVencInfo) != S_OK) {
        DBPRINT0("[VENC] get init need info fail !!\n");
		return S_FAIL;
	}
#if 0	
	#if defined(_MT9P031) ||  defined( _OV5653) || defined(_AR0331)
		//printf("[venc_app](%d)Hello!!\n",__LINE__);
		ptVencInfo->tCapabilityRec.dwVideoMaxWidth = ptVencInfo->tCapabilityRec.dwVideoCapWidth;
		ptVencInfo->tCapabilityRec.dwVideoMaxHeight = ptVencInfo->tCapabilityRec.dwVideoCapHeight;
	#endif
		
	#if defined(_5M2MSWITCH)
	   ptVencInfo->tCapabilityRec.dwVideoMaxWidth = 2560;
	   ptVencInfo->tCapabilityRec.dwVideoMaxHeight = 1920;
	#elif defined(_3M2MSWITCH)
	   ptVencInfo->tCapabilityRec.dwVideoMaxWidth = 2048;
	   ptVencInfo->tCapabilityRec.dwVideoMaxHeight = 1536;
	#endif		
#endif
#if !defined(_5M2MSWITCH) && !defined(_3M2MSWITCH)	   
	if (ptVencInfo->tCapabilityRec.dwVideoMaxWidth > ptVencInfo->tCapabilityRec.dwVideoCapWidth)
	{
		ptVencInfo->tCapabilityRec.dwVideoMaxWidth = ptVencInfo->tCapabilityRec.dwVideoCapWidth; 
	}
	
	if (ptVencInfo->tCapabilityRec.dwVideoMaxHeight > ptVencInfo->tCapabilityRec.dwVideoCapHeight)
	{
		ptVencInfo->tCapabilityRec.dwVideoMaxHeight = ptVencInfo->tCapabilityRec.dwVideoCapHeight;
	}
#endif
	
#if 1
	printf("[VENC] Capability - dwBufNum = %u\n", ptVencInfo->tCapabilityRec.dwBufNum);
	printf("[VENC] Capability - dwVideoMaxWidth = %u\n", ptVencInfo->tCapabilityRec.dwVideoMaxWidth);
	printf("[VENC] Capability - dwVideoMaxHeight = %u\n", ptVencInfo->tCapabilityRec.dwVideoMaxHeight);
	printf("[VENC] Capability - capture resolution W x H: %u x %u\n", ptVencInfo->tCapabilityRec.dwVideoCapWidth, ptVencInfo->tCapabilityRec.dwVideoCapHeight);
	printf("[VENC] Capability - sensor in resolution W x H: %u x %u\n", ptVencInfo->tCapabilityRec.dwVideoInWidth, ptVencInfo->tCapabilityRec.dwVideoInHeight);
	printf("[VENC] Capability - Interlace or Progressive? %s\n", (ptVencInfo->tCapabilityRec.bInterlaceScan)? "Interlace": "Progressive");
#endif


	// decide bitstream size here, match the past defined case
	if (ptVencInfo->tCapabilityRec.dwVideoMaxWidth >= 1280) {
		dwBitStreamSize = 1024 * 1024;
	} else {
		dwBitStreamSize = 720 * 480;
	}
    // Initial Video Master process
    if (ptVencInfo->tVencCfgPath.bMasterEnable == TRUE) {
	    tMasterInitOpt.dwDevNum = tVencInitOpt.dwDevNum;
	    tMasterInitOpt.dwCallbackInstance = (DWORD)ptVencInfo;
	    tMasterInitOpt.szConfigFile = ptVencInfo->tVencCfgPath.szMasterConfigFile;
	    tMasterInitOpt.hMemMgrObj = ptVencInfo->hMemMgrObj;
	    tMasterInitOpt.tInitNeedInfo.dwVideoMaxWidth = ptVencInfo->tCapabilityRec.dwVideoMaxWidth;
	    tMasterInitOpt.tInitNeedInfo.dwVideoMaxHeight = ptVencInfo->tCapabilityRec.dwVideoMaxHeight;
	    tMasterInitOpt.tInitNeedInfo.dwVideoCapWidth = ptVencInfo->tCapabilityRec.dwVideoCapWidth;
	    tMasterInitOpt.tInitNeedInfo.dwVideoCapHeight = ptVencInfo->tCapabilityRec.dwVideoCapHeight;
	    tMasterInitOpt.tInitNeedInfo.dwVideoInWidth = ptVencInfo->tCapabilityRec.dwVideoInWidth;
	    tMasterInitOpt.tInitNeedInfo.dwVideoInHeight = ptVencInfo->tCapabilityRec.dwVideoInHeight;
	    tMasterInitOpt.tInitNeedInfo.dwBufNum = ptVencInfo->tCapabilityRec.dwBufNum;
	    tMasterInitOpt.tInitNeedInfo.szSensorConfigFile = ptVencInfo->tVencCfgPath.szSensorConfigFile;
	    tMasterInitOpt.tInitNeedInfo.dwVICOutputDRAMLoc = ptVencInfo->tVencCfgPath.tDRAMParam.dwVICOutputDRAMLoc;
	    if (VencMaster_Initial(&(ptVencInfo->hMasterProcObj), tMasterInitOpt) != S_OK) {
	    	printf("[VENC] VencMaster_Initial fail !!\n");
	    	exit(0);
	    }
	   	printf("[VENC] VencMaster_Initial successful !!\n");
    }

	// Initial Video Input process
    if (ptVencInfo->tVencCfgPath.bVideoInEnable == TRUE) {
	    tVideoInInitOpt.dwDevNum = tVencInitOpt.dwDevNum;
	    tVideoInInitOpt.dwCallbackInstance = (DWORD)ptVencInfo;
	    tVideoInInitOpt.szConfigFile = ptVencInfo->tVencCfgPath.szVideoInConfigFile;
	    tVideoInInitOpt.hMemMgrObj = ptVencInfo->hMemMgrObj;
	    VencMaster_GetVideoCapHandle(ptVencInfo->hMasterProcObj, &tVideoInInitOpt.hVideoCapObj);
	    VencMaster_GetUARTIRCutFD(ptVencInfo->hMasterProcObj, &tVideoInInitOpt.fdIRCutUART);
	    VencMaster_GetIRCutFD(ptVencInfo->hMasterProcObj, &tVideoInInitOpt.fdIRCut);
	    tVideoInInitOpt.dwSharedBufferMinorNum = ptVencInfo->tVencCfgPath.dwSharedBufferMinorNum;
	    tVideoInInitOpt.tInitNeedInfo.dwVideoMaxWidth = ptVencInfo->tCapabilityRec.dwVideoMaxWidth;
	    tVideoInInitOpt.tInitNeedInfo.dwVideoMaxHeight = ptVencInfo->tCapabilityRec.dwVideoMaxHeight;
	    tVideoInInitOpt.tInitNeedInfo.dwVideoCapWidth = ptVencInfo->tCapabilityRec.dwVideoCapWidth;
	    tVideoInInitOpt.tInitNeedInfo.dwVideoCapHeight = ptVencInfo->tCapabilityRec.dwVideoCapHeight;
	    tVideoInInitOpt.tInitNeedInfo.dwVideoInWidth = ptVencInfo->tCapabilityRec.dwVideoInWidth;
	    tVideoInInitOpt.tInitNeedInfo.dwVideoInHeight = ptVencInfo->tCapabilityRec.dwVideoInHeight;
	    tVideoInInitOpt.tInitNeedInfo.dwLDCRefFrameDRAMLoc = ptVencInfo->tVencCfgPath.tDRAMParam.dwLDCRefFrameDRAMLoc;
	    tVideoInInitOpt.tInitNeedInfo.dwDMACOutputDRAMLoc = ptVencInfo->tVencCfgPath.tDRAMParam.dwDMACOutputDRAMLoc;
		tVideoInInitOpt.tInitNeedInfo.dwVICOutputDRAMLoc = ptVencInfo->tVencCfgPath.tDRAMParam.dwVICOutputDRAMLoc;
		if (ptVencInfo->tVencCfgPath.bDisplayEnable == TRUE)
		{
			tVideoInInitOpt.dwOutputSharedBufferNum = 9;
		}
		else
		{
			tVideoInInitOpt.dwOutputSharedBufferNum = 4;
		}
		if (VencVideoIn_Initial(&(ptVencInfo->hVideoInProcObj), tVideoInInitOpt) != S_OK) {
	    	printf("[VENC] VencVideoIn_Initial fail !!\n");
	    	exit(0);
	    }
	  
	    printf("[VENC] VencVideoIn_Initial successful !!\n");
	}

    ptVencInfo->phEncoderProcObj = (HANDLE *)malloc(sizeof(HANDLE)*ptVencInfo->tVencCfgPath.dwEncoderTotalNum);
    for (dwCurId = 0; dwCurId < ptVencInfo->tVencCfgPath.dwEncoderTotalNum ; dwCurId++)
    {
		ptVencInfo->phEncoderProcObj[dwCurId]=NULL;
    }
    // Initial Video Encoder process
    for (dwCurId = 0; dwCurId < ptVencInfo->tVencCfgPath.dwEncoderTotalNum; dwCurId++) {
	    tEncoderInitOpt.hMemMgrObj = ptVencInfo->hMemMgrObj;
	    tEncoderInitOpt.dwCallbackInstance = (DWORD)ptVencInfo;
	    tEncoderInitOpt.dwSharedBufferMinorNum = ptVencInfo->tVencCfgPath.dwSharedBufferMinorNum;
	    tEncoderInitOpt.szConfigFile = ptVencInfo->tVencCfgPath.pszEncoderConfigFile[dwCurId];
	    tEncoderInitOpt.dwCurId = dwCurId;
		tEncoderInitOpt.dwVideoResolutionFormatIndex = vfUserDef1 + dwCurId;
		if (tEncoderInitOpt.dwVideoResolutionFormatIndex == vfNum)
		{
			tEncoderInitOpt.dwVideoResolutionFormatIndex = vfUserDef1;
			printf("[VENC][Warnning][encoder %d] The video resolution format index is upper bound!! Reset as %d\n", dwCurId, vfUserDef1);
		}
	    tEncoderInitOpt.tInitNeedInfo.dwVideoMaxWidth = ptVencInfo->tCapabilityRec.dwVideoMaxWidth;
	    tEncoderInitOpt.tInitNeedInfo.dwVideoMaxHeight = ptVencInfo->tCapabilityRec.dwVideoMaxHeight;
	 
	    tEncoderInitOpt.tInitNeedInfo.dwVideoCapWidth = ptVencInfo->tCapabilityRec.dwVideoCapWidth;
	    tEncoderInitOpt.tInitNeedInfo.dwVideoCapHeight = ptVencInfo->tCapabilityRec.dwVideoCapHeight;
	    tEncoderInitOpt.tInitNeedInfo.dwBitStreamSize = dwBitStreamSize;
	    tEncoderInitOpt.tInitNeedInfo.dwIREOutput0DRAMLoc = ptVencInfo->tVencCfgPath.tDRAMParam.dwIREOutput0DRAMLoc;
	    tEncoderInitOpt.tInitNeedInfo.dwIREOutput1DRAMLoc = ptVencInfo->tVencCfgPath.tDRAMParam.dwIREOutput1DRAMLoc;
	    tEncoderInitOpt.tInitNeedInfo.dwBitStreamOutputDRAMLoc = ptVencInfo->tVencCfgPath.tDRAMParam.dwBitStreamOutputDRAMLoc;
	    tEncoderInitOpt.tInitNeedInfo.dwMp4VBusNum = ptVencInfo->tVencCfgPath.tDRAMParam.dwMp4VBusNum;
	    tEncoderInitOpt.tInitNeedInfo.dwH264BusNum = ptVencInfo->tVencCfgPath.tDRAMParam.dwH264BusNum;
	    tEncoderInitOpt.tInitNeedInfo.dwSVCBusNum = ptVencInfo->tVencCfgPath.tDRAMParam.dwSVCBusNum;
	    tEncoderInitOpt.tInitNeedInfo.bInterlaceScan = ptVencInfo->tCapabilityRec.bInterlaceScan;
	    tEncoderInitOpt.tInitNeedInfo.dwMaxCapFrameRate = ptVencInfo->tCapabilityRec.dwMaxCapFrameRate;
	    tEncoderInitOpt.tInitNeedInfo.bCMOSSensor = ptVencInfo->tCapabilityRec.bCMOSSensor;
	    tEncoderInitOpt.tInitNeedInfo.dwVideoCodecInitMask = ptVencInfo->tCapabilityRec.dwVideoCodecInitMask;
		#if 0
	    if (VencEncoder_Initial(&(ptVencInfo->hEncoderProcObj[dwCurId]), tEncoderInitOpt) != S_OK) {
	    	printf("[VENC] VencEncoder_Initial fail !!\n");
	    	exit(0);
	    }
		#endif	
		if (VencEncoder_Initial(&(ptVencInfo->phEncoderProcObj[dwCurId]), tEncoderInitOpt) != S_OK) {
	    	printf("[VENC] VencEncoder_Initial fail !!\n");
	    	exit(0);
	    }
		//printf("[VENC_APP](%d)ptVencInfo->phEncoderProcObj[%d]=%p\n",__LINE__,dwCurId,ptVencInfo->phEncoderProcObj[dwCurId]);
		
	   	printf("[VENC] VencEncoder_Initial successful !!\n");
		
    }
    #if 0
	for (dwCurId = 0; dwCurId < ptVencInfo->tVencCfgPath.dwEncoderTotalNum; dwCurId++) {
		printf("[VENC_APP](%d) ptVencInfo->phEncoderProcObj[%d]=%p\n",__LINE__,dwCurId,ptVencInfo->phEncoderProcObj[dwCurId]);
	}
#endif


#if defined(_VMA_IBPE)
	// Initial Motion Sending process
    if (ptVencInfo->tVencCfgPath.bMotionEnable == TRUE) {
	    tMotionInitOpt.dwCallbackInstance = (DWORD)ptVencInfo;
	    tMotionInitOpt.szConfigFile = ptVencInfo->tVencCfgPath.szMotionConfigFile;
	    tMotionInitOpt.hMemMgrObj = ptVencInfo->hMemMgrObj;
	    tMotionInitOpt.dwSharedBufferMinorNum = ptVencInfo->tVencCfgPath.dwSharedBufferMinorNum;
	    tMotionInitOpt.tInitNeedInfo.dwVideoMaxWidth = ptVencInfo->tCapabilityRec.dwVideoMaxWidth;
	    tMotionInitOpt.tInitNeedInfo.dwVideoMaxHeight = ptVencInfo->tCapabilityRec.dwVideoMaxHeight;
	    tMotionInitOpt.tInitNeedInfo.dwVideoCapWidth = ptVencInfo->tCapabilityRec.dwVideoCapWidth;
	    tMotionInitOpt.tInitNeedInfo.dwVideoCapHeight = ptVencInfo->tCapabilityRec.dwVideoCapHeight;
	    tMotionInitOpt.tInitNeedInfo.dwBitStreamSize = dwBitStreamSize;
	    tMotionInitOpt.tInitNeedInfo.dwMotionSnapshotOutputDRAMLoc = ptVencInfo->tVencCfgPath.tDRAMParam.dwMotionSnapshotOutputDRAMLoc;
	    tMotionInitOpt.tInitNeedInfo.dwVideoCodecInitMask = ptVencInfo->tCapabilityRec.dwVideoCodecInitMask;	
		if (VencMotion_Initial(&(ptVencInfo->hMotionProcObj), tMotionInitOpt) != S_OK) {
	    	printf("[VENC] VencMotion_Initial fail !!\n");
	    	exit(0);
	    }
	   	printf("[VENC] VencMotion_Initial successful !!\n");
	}
#endif

#if defined(_VPL_VOC)
	// Initial Video Display process
    if (ptVencInfo->tVencCfgPath.bDisplayEnable == TRUE) {
	    tDisplayInitOpt.dwDevNum = tVencInitOpt.dwDevNum;
	    tDisplayInitOpt.dwCallbackInstance = (DWORD)ptVencInfo;
	    tDisplayInitOpt.dwSharedBufferMinorNum = ptVencInfo->tVencCfgPath.dwSharedBufferMinorNum;
	    tDisplayInitOpt.szConfigFile = ptVencInfo->tVencCfgPath.szDisplayConfigFile;
	    tDisplayInitOpt.hMemMgrObj = ptVencInfo->hMemMgrObj;
	    tDisplayInitOpt.tInitNeedInfo.dwVideoMaxWidth = ptVencInfo->tCapabilityRec.dwVideoMaxWidth;
	    tDisplayInitOpt.tInitNeedInfo.dwVideoMaxHeight = ptVencInfo->tCapabilityRec.dwVideoMaxHeight;
	    tDisplayInitOpt.tInitNeedInfo.dwVideoCapWidth = ptVencInfo->tCapabilityRec.dwVideoCapWidth;
	    tDisplayInitOpt.tInitNeedInfo.dwVideoCapHeight = ptVencInfo->tCapabilityRec.dwVideoCapHeight;
	    tDisplayInitOpt.tInitNeedInfo.dwVideoInWidth = ptVencInfo->tCapabilityRec.dwVideoInWidth;
	    tDisplayInitOpt.tInitNeedInfo.dwVideoInHeight = ptVencInfo->tCapabilityRec.dwVideoInHeight;
	    tDisplayInitOpt.tInitNeedInfo.dwVOCOutputDRAMLoc = ptVencInfo->tVencCfgPath.tDRAMParam.dwVOCOutputDRAMLoc;
	    if (VencDisplay_Initial(&(ptVencInfo->hDisplayProcObj), tDisplayInitOpt) != S_OK) {
	    	printf("[VENC] VencDisplay_Initial fail !!\n");
	    	exit(0);
	    }
	   	printf("[VENC] VencDisplay_Initial successful !!\n");
	}
#endif
	
    Venc_LoadConfig(ptVencInfo);

    if (tVencInitOpt.szCommandFIFO == NULL) {
        tVencInitOpt.szCommandFIFO = DEFAULT_COMMAND_FIFO;
    }
	DBPRINT1("[VENC] CommandFIFO path = %s\n", tVencInitOpt.szCommandFIFO);

	// Initial Message process
    VencMessage_Initial(ptVencInfo, tVencInitOpt.szCommandFIFO);

    return S_OK;
}
Esempio n. 7
0
/* ============================================================================================= */
SCODE Venc_Release(HANDLE *phVencObject)
{
    TVencInfo *ptVencInfo = (TVencInfo *)(*phVencObject);
    DWORD	dwCurId;
	
	if (ptVencInfo->hMsgReaderObj != NULL) 
	{
		VencMessage_Release(&ptVencInfo->hMsgReaderObj);
	}
	
	for (dwCurId = 0; dwCurId < ptVencInfo->tVencCfgPath.dwEncoderTotalNum; dwCurId++) 
	{
		if (ptVencInfo->phEncoderProcObj[dwCurId] != NULL) {
		    VencEncoder_Release(&ptVencInfo->phEncoderProcObj[dwCurId]);
		    DBPRINT1("[VENC] Encoder process %u release\n", dwCurId);
		}
	}

	for (dwCurId = 0; dwCurId < ptVencInfo->tVencCfgPath.dwEncoderTotalNum; dwCurId++) 
	{
		if (ptVencInfo->tVencCfgPath.pszEncoderConfigFile[dwCurId] != NULL)
		{
			free(ptVencInfo->tVencCfgPath.pszEncoderConfigFile[dwCurId]);		
			ptVencInfo->tVencCfgPath.pszEncoderConfigFile[dwCurId]=NULL;
		}
	}
	if (ptVencInfo->tVencCfgPath.pszEncoderConfigFile != NULL)
	{
		free(ptVencInfo->tVencCfgPath.pszEncoderConfigFile);
		ptVencInfo->tVencCfgPath.pszEncoderConfigFile = NULL;
	}

	if (ptVencInfo->pdwCurrSwitch != NULL)
	{
		free(ptVencInfo->pdwCurrSwitch);
		ptVencInfo->pdwCurrSwitch = NULL;
	}
	if (ptVencInfo->tVencCfgPath.szCapabilityPath != NULL)
	{
	    free(ptVencInfo->tVencCfgPath.szCapabilityPath);
	    ptVencInfo->tVencCfgPath.szCapabilityPath = NULL;
	}
	if (ptVencInfo->tVencCfgPath.szSensorConfigFile != NULL)
	{
	    free(ptVencInfo->tVencCfgPath.szSensorConfigFile);
	    ptVencInfo->tVencCfgPath.szSensorConfigFile = NULL;
	}
	if (ptVencInfo->tVencCfgPath.szMasterConfigFile != NULL)
	{
	    free(ptVencInfo->tVencCfgPath.szMasterConfigFile);
	    ptVencInfo->tVencCfgPath.szMasterConfigFile = NULL;
	}
	
	if (ptVencInfo->tVencCfgPath.szMotionConfigFile != NULL)
	{
	    free(ptVencInfo->tVencCfgPath.szMotionConfigFile);
	    ptVencInfo->tVencCfgPath.szMotionConfigFile = NULL;
	}
	
	if (ptVencInfo->tVencCfgPath.szDisplayConfigFile != NULL)
	{
		free( ptVencInfo->tVencCfgPath.szDisplayConfigFile);
		ptVencInfo->tVencCfgPath.szDisplayConfigFile = NULL;
	}
	
	if (ptVencInfo->tVencCfgPath.szVideoInConfigFile != NULL)
	{
		free(ptVencInfo->tVencCfgPath.szVideoInConfigFile);
		ptVencInfo->tVencCfgPath.szVideoInConfigFile = NULL;
	}
	
	
#if defined(_VMA_IBPE)
	if (ptVencInfo->hMotionProcObj != NULL) {
    	VencMotion_Release(&ptVencInfo->hMotionProcObj);
    	DBPRINT0("[VENC] Motion sending process release\n");	
	}
#endif
#if defined(_VPL_VOC)
	if (ptVencInfo->hDisplayProcObj != NULL) {
	    VencDisplay_Release(&ptVencInfo->hDisplayProcObj);
	    DBPRINT0("[VENC] Display process release\n");
	}
#endif
	if (ptVencInfo->tCapabilityRec.szSensorName != NULL )
	{
		free(ptVencInfo->tCapabilityRec.szSensorName);
		ptVencInfo->tCapabilityRec.szSensorName = NULL;
		DBPRINT0("[VENC] ptVencInfo->tCapabilityRec.szSensorName release\n");
	}
	if (ptVencInfo->hVideoInProcObj != NULL) {
	    VencVideoIn_Release(&ptVencInfo->hVideoInProcObj);
	    DBPRINT0("[VENC] VideoIn process release\n");
	}

	if (ptVencInfo->hMasterProcObj != NULL) {
		VencMaster_Release(&ptVencInfo->hMasterProcObj);
	    DBPRINT0("[VENC] Master process release\n");
	}
    
	// release Venc initial parts, it should be release last
	if (ptVencInfo->hXMLWrapperObj != NULL)
		XmlWrapper_Release(&(ptVencInfo->hXMLWrapperObj));

	if (ptVencInfo->hMemMgrObj != NULL)
		MemMgr_Release(&ptVencInfo->hMemMgrObj);
	
	sem_destroy(&(ptVencInfo->smOptions));
	
	if (ptVencInfo) free(ptVencInfo);
	
	*phVencObject = NULL;
  
    return S_OK;
}
Esempio n. 8
0
/* ========================================================================== */
void VencEncoder_Mp4VApplyOpt(HANDLE hObject)
{
    TEncoderInfo *ptEncoderInfo = (TEncoderInfo *) hObject;
	SCODE scRet;
	TMp4VOptRec *ptMp4VOptRec = &(ptEncoderInfo->tMp4VOptRec);
	TMp4VEncOptions tMp4VEncOpt;    

	if (ptMp4VOptRec->bQualityGroup == TRUE) {
		if (ptMp4VOptRec->dwBitrate > 0)
		{
			tMp4VEncOpt.eOptionFlags = VIDEO_CHANGE_BITRATE;
			tMp4VEncOpt.adwUserData[0] = ptMp4VOptRec->dwBitrate;
			if (ptEncoderInfo->hMp4VEncObj != NULL)
			{
				scRet = Mp4VEnc_SetOptions(ptEncoderInfo->hMp4VEncObj, &tMp4VEncOpt);
				assert(scRet == S_OK);

				DBPRINT1("[VENC_ENCODER] Set MPEG4 Bitrate %u\n", tMp4VEncOpt.adwUserData[0]);
			}

			tMp4VEncOpt.eOptionFlags = VIDEO_SET_RATE_CONTROL; 
			tMp4VEncOpt.adwUserData[0] = ptMp4VOptRec->ercfMPEG4QualityType;
			if (ptEncoderInfo->hMp4VEncObj!=NULL)
			{
				scRet = Mp4VEnc_SetOptions(ptEncoderInfo->hMp4VEncObj, &tMp4VEncOpt);
				assert(scRet == S_OK);

				DBPRINT1("[VENC_ENCODER] Set MPEG4 RateCtrl: %d\n", tMp4VEncOpt.adwUserData[0]);
			}
		}
		ptMp4VOptRec->bBitrate = FALSE;
		ptMp4VOptRec->bSetRateControl = FALSE;

		//	    if (ptMp4VOptRec->bQuant == TRUE) { // Venc_SlaveApp_SetMPEG4Quant
		tMp4VEncOpt.eOptionFlags = VIDEO_CHANGE_QUANT;        
		tMp4VEncOpt.adwUserData[0] = ptMp4VOptRec->dwQuant;
		if (ptEncoderInfo->hMp4VEncObj != NULL) 
		{
			scRet = Mp4VEnc_SetOptions(ptEncoderInfo->hMp4VEncObj, &tMp4VEncOpt);
			assert(scRet == S_OK);

			DBPRINT1("[VENC_ENCODER] Set MPEG4 Quant %u\n",tMp4VEncOpt.adwUserData[0]);
		}
		ptMp4VOptRec->bQuant = FALSE;
		//	    }
		ptMp4VOptRec->bQualityGroup = FALSE;
	}

	if (ptMp4VOptRec->bForceIntra == TRUE) {
		tMp4VEncOpt.eOptionFlags = VIDEO_FORCE_INTRA;
		if (ptEncoderInfo->hMp4VEncObj != NULL)
		{
			scRet = Mp4VEnc_SetOptions(ptEncoderInfo->hMp4VEncObj, &tMp4VEncOpt);
			assert(scRet == S_OK);
			DBPRINT0("[VENC_ENCODER] Set MPEG4 ForceIntra\n");
		}
		ptMp4VOptRec->bForceIntra = FALSE;
	}

	if (ptMp4VOptRec->bIntraInterval == TRUE) {
		// call force intra first
		tMp4VEncOpt.eOptionFlags = VIDEO_FORCE_INTRA;
		if (ptEncoderInfo->hMp4VEncObj != NULL)
		{
			scRet = Mp4VEnc_SetOptions(ptEncoderInfo->hMp4VEncObj, &tMp4VEncOpt);
			assert(scRet == S_OK);
			DBPRINT0("[VENC_ENCODER] Set MPEG4 ForceIntra\n");
		}
		// call change interval
		tMp4VEncOpt.eOptionFlags = VIDEO_CHANGE_INTRA_INTERVAL;        
		tMp4VEncOpt.adwUserData[0] = ptMp4VOptRec->dwIntraInterval;
		if (ptEncoderInfo->hMp4VEncObj != NULL)
		{
			scRet = Mp4VEnc_SetOptions(ptEncoderInfo->hMp4VEncObj, &tMp4VEncOpt);
			assert(scRet == S_OK);
			DBPRINT1("[VENC_ENCODER] Set MPEG4 IntraInterval %u\n",tMp4VEncOpt.adwUserData[0]);
		}
		ptMp4VOptRec->bIntraInterval = FALSE;
	}
}