Exemplo n.º 1
0
void modify_test() {
	double start_time, end_time;
	int built = false;

	Read_Buffer(input_file);
	// B+tree initialize
	BPlusTree_Init();
	// MaxChildNumber				
	printf("input depth: ");
	int depth;
	scanf("%d", &depth);
	int maxCh = 2;
	while (1) {
		int leaves = 1, i;
		for (i = 0; i < depth; i++) {
			leaves *= maxCh;
			if (leaves > TotalRecords) break;
		}
		if (leaves > TotalRecords) break;
		maxCh++;
	}
	printf("Desired depth = %d, calculated maxChildNumber = %d\n", depth, maxCh);
	BPlusTree_SetMaxChildNumber(maxCh);
	// build
	built = true;
	start_time = clock();
	Read_Data_And_Insert();
	end_time = clock();
	printf("Valid Records inserted on B+tree = %d\n", validRecords);
	printf("Total number of B+tree nodes = %d\n", BPlusTree_GetTotalNodes());
	printf("Build B+tree costs %lf s\n", (end_time - start_time) / CLOCKS_PER_SEC);
	// modify
	start_time = clock();
	int key, i, j;
	srand((unsigned)time(NULL));
	int mod_num = 10;
	for (i = 0; i < mod_num; i++) {
		new_key = keys[rand() % key_num];
		new_len = 10;
		for (j = 0; j < new_len; j++) new_st[j] = 'a' + rand() % 26;

		char* value = (char*)malloc(sizeof(char) * strlen(new_st));
		strcpy(value, new_st);
		int pos = BPlusTree_Find(new_key);
		if (pos != -1) { // found
			if (File_Modify(pos, new_key, new_st)) { // file modify success
				BPlusTree_Modify(new_key, value);
				//printf("Modify success.\n");
			} else {
				//printf("Modify failed, the new value is too long to store in file\n");
			}
		} else {
			printf("Modify failed, do not have the given key on B+tree.\n");
		}
	}
	end_time = clock();
	printf("modify %d elements, average cost is %lf s\n", mod_num, (end_time - start_time) / CLOCKS_PER_SEC / mod_num); 
	BPlusTree_Destroy();
}
OMX_ERRORTYPE EmptyBufferDone(OMX_IN OMX_HANDLETYPE hComponent,
                              OMX_IN OMX_PTR pAppData,
                              OMX_IN OMX_BUFFERHEADERTYPE* pBuffer)
{
    int readBytes =0;

    /* To remove warning for unused variable to keep prototype same */
    (void)pAppData;

    ebd_cnt++;
    used_ip_buf_cnt--;
    pthread_mutex_lock(&etb_lock);
    if(!etb_done)
    {
        DEBUG_PRINT("\n*********************************************\n");
        DEBUG_PRINT("Wait till first set of buffers are given to component\n");
        DEBUG_PRINT("\n*********************************************\n");
        etb_done++;
        pthread_mutex_unlock(&etb_lock);
        etb_wait_for_event();
    }
    else
    {
        pthread_mutex_unlock(&etb_lock);
    }


    if(bInputEosReached)
    {
        DEBUG_PRINT("\n*********************************************\n");
        DEBUG_PRINT("   EBD::EOS on input port\n ");
        DEBUG_PRINT("*********************************************\n");
        return OMX_ErrorNone;
    }else if (bFlushing == true) {
      DEBUG_PRINT("omx_evrc13_adec_test: bFlushing is set to TRUE used_ip_buf_cnt=%d\n",used_ip_buf_cnt);
      if (used_ip_buf_cnt == 0) {
        bFlushing = false;
      } else {
        DEBUG_PRINT("omx_evrc13_adec_test: more buffer to come back used_ip_buf_cnt=%d\n",used_ip_buf_cnt);
        return OMX_ErrorNone;
      }
    }

    if((readBytes = Read_Buffer(pBuffer)) > 0) {
        pBuffer->nFilledLen = readBytes;
        used_ip_buf_cnt++;
        OMX_EmptyThisBuffer(hComponent,pBuffer);
    }
    else{
        pBuffer->nFlags |= OMX_BUFFERFLAG_EOS;
        used_ip_buf_cnt++;
        bInputEosReached = true;
        pBuffer->nFilledLen = 0;
        OMX_EmptyThisBuffer(hComponent,pBuffer);
        DEBUG_PRINT("EBD..Either EOS or Some Error while reading file\n");
    }
    return OMX_ErrorNone;
}
Exemplo n.º 3
0
void delete_test() {
	double start_time, end_time;
	int built = false;

	Read_Buffer(input_file);
	// B+tree initialize
	BPlusTree_Init();
	// MaxChildNumber				
	printf("input depth: ");
	int depth;
	scanf("%d", &depth);
	int maxCh = 2;
	while (1) {
		int leaves = 1, i;
		for (i = 0; i < depth; i++) {
			leaves *= maxCh;
			if (leaves > TotalRecords) break;
		}
		if (leaves > TotalRecords) break;
		maxCh++;
	}
	printf("Desired depth = %d, calculated maxChildNumber = %d\n", depth, maxCh);
	BPlusTree_SetMaxChildNumber(maxCh);
	// build
	built = true;
	start_time = clock();
	Read_Data_And_Insert();
	end_time = clock();
	printf("Valid Records inserted on B+tree = %d\n", validRecords);
	printf("Total number of B+tree nodes = %d\n", BPlusTree_GetTotalNodes());
	printf("Build B+tree costs %lf s\n", (end_time - start_time) / CLOCKS_PER_SEC);
	// delete
	start_time = clock();
	int key, i;
	srand((unsigned)time(NULL));
	int del_num = 10;
	for (i = 0; i < del_num; i++) {
		key = keys[rand() % key_num];
		int pos = BPlusTree_Find(key);
		if (pos != -1) { // found
			File_Delete(pos);
			BPlusTree_Delete(key);
			//printf("Delete success.\n");
		} else {
			//printf("Delete failed, do not have the given key on B+tree.\n");
		}
	}
	end_time = clock();
	printf("delete %d elements, average cost is %lf s\n", del_num, (end_time - start_time) / CLOCKS_PER_SEC / del_num); 
	BPlusTree_Destroy();
}
Exemplo n.º 4
0
void query_range_test() {
	double start_time, end_time;
	int built = false;

	Read_Buffer(input_file);
	// B+tree initialize
	BPlusTree_Init();
	// MaxChildNumber				
	printf("input depth: ");
	int depth;
	scanf("%d", &depth);
	int maxCh = 2;
	while (1) {
		int leaves = 1, i;
		for (i = 0; i < depth; i++) {
			leaves *= maxCh;
			if (leaves > TotalRecords) break;
		}
		if (leaves > TotalRecords) break;
		maxCh++;
	}
	printf("Desired depth = %d, calculated maxChildNumber = %d\n", depth, maxCh);
	BPlusTree_SetMaxChildNumber(maxCh);
	// build
	built = true;
	start_time = clock();
	Read_Data_And_Insert();
	end_time = clock();
	printf("Valid Records inserted on B+tree = %d\n", validRecords);
	printf("Total number of B+tree nodes = %d\n", BPlusTree_GetTotalNodes());
	printf("Build B+tree costs %lf s\n", (end_time - start_time) / CLOCKS_PER_SEC);
	// query
	start_time = clock();
	int key, i;
	srand((unsigned)time(NULL));
	int query_num = 10;
	for (i = 0; i < query_num; i++) {
		int r = ((long long)(rand() % MAX_KEY) * (rand() % MAX_KEY)) % MAX_KEY + 1;
		int l = ((long long)(rand() % MAX_KEY) * (rand() % MAX_KEY)) % r + 1;
		printf("range = (%d, %d)\n", l, r);
		BPlusTree_Query_Range(l, r);
	}
	end_time = clock();
	printf("query %d ranges, average cost is %lf s\n", query_num, (end_time - start_time) / CLOCKS_PER_SEC / query_num); 
	BPlusTree_Destroy();
}
Exemplo n.º 5
0
void build_test() {
	double start_time, end_time, tot_time = 0;
	int built = false;
	
	// MaxChildNumber				
	printf("input depth: ");
	int depth;
	scanf("%d", &depth);
	int maxCh = 2;
	while (1) {
		int leaves = 1, i;
		for (i = 0; i < depth; i++) {
			leaves *= maxCh;
			if (leaves > TotalRecords) break;
		}
		if (leaves > TotalRecords) break;
		maxCh++;
	}
	printf("Desired depth = %d, calculated maxChildNumber = %d\n", depth, maxCh);
	BPlusTree_SetMaxChildNumber(maxCh);

	// build
	int build_num = 10, i;
	for (i = 0; i < build_num; i++) {
		printf("=============== %d ==========\n", i);
		// read buffer
		Read_Buffer(input_file);
		start_time = clock();
		// B+tree initialize
		BPlusTree_Init();
		// args
		built = false;
		validRecords = 0;
		key_num = 0;
		// build
		built = true;
		Read_Data_And_Insert();
		end_time = clock();
		tot_time += (end_time - start_time);
		printf("Valid Records inserted on B+tree = %d\n", validRecords);
		printf("Total number of B+tree nodes = %d\n", BPlusTree_GetTotalNodes());
		printf("this time costs %lf s\n\n", (end_time - start_time) / CLOCKS_PER_SEC);
		BPlusTree_Destroy();
	}
	printf("build %d times, average cost is %lf s\n", build_num, tot_time / CLOCKS_PER_SEC / build_num); 
}
Exemplo n.º 6
0
OMX_ERRORTYPE EmptyBufferDone(OMX_IN OMX_HANDLETYPE hComponent,
                              OMX_IN OMX_PTR pAppData,
                              OMX_IN OMX_BUFFERHEADERTYPE* pBuffer)
{
    int readBytes =0;


    DEBUG_PRINT("\nFunction %s cnt[%d]\n", __FUNCTION__, ebd_cnt);
    ebd_cnt++;
    used_ip_buf_cnt--;
    if(bInputEosReached) {
        DEBUG_PRINT("\n*********************************************\n");
    DEBUG_PRINT("   EBD::EOS on input port\n ");
    DEBUG_PRINT("   TBD:::De Init the open max here....!!!\n");
    DEBUG_PRINT("*********************************************\n");
        if(tunnel)
            event_complete();
        return OMX_ErrorNone;
    }    else if (bFlushing == true) {
        DEBUG_PRINT("omx_aac_adec_test: bFlushing is set to TRUE used_ip_buf_cnt=%d\n",used_ip_buf_cnt);
      if (used_ip_buf_cnt == 0) {
        //fseek(inputBufferFile, 0, 0);
        bFlushing = false;
      } else {
        DEBUG_PRINT("omx_aac_adec_test: more buffer to come back used_ip_buf_cnt=%d\n",used_ip_buf_cnt);
        return OMX_ErrorNone;
      }
    }

    if((readBytes = Read_Buffer(pBuffer)) > 0) {
        pBuffer->nFilledLen = readBytes;
        used_ip_buf_cnt++;
        OMX_EmptyThisBuffer(hComponent,pBuffer);
    }
    else{
      pBuffer->nFlags |= OMX_BUFFERFLAG_EOS;
            bInputEosReached = true;
        pBuffer->nFilledLen = 0;
        OMX_EmptyThisBuffer(hComponent,pBuffer);
        DEBUG_PRINT("EBD..Either EOS or Some Error while reading file\n");
    }
    return OMX_ErrorNone;
}
Exemplo n.º 7
0
int Play_Decoder()
{
    int i;
    int Size=0;
    DEBUG_PRINT("Inside %s \n", __FUNCTION__);
    OMX_ERRORTYPE ret;
    OMX_STATETYPE state;
    unsigned int bufCnt=0;
#ifdef PCM_PLAYBACK
        struct msm_audio_pcm_config drv_pcm_config;
#endif  // PCM_PLAYBACK

    DEBUG_PRINT("sizeof[%d]\n", sizeof(OMX_BUFFERHEADERTYPE));

    /* open the i/p and o/p files based on the video file format passed */
    if(open_audio_file()) {
        DEBUG_PRINT("\n Returning -1");
    return -1;
    }
    /* Query the decoder input min buf requirements */
    CONFIG_VERSION_SIZE(inputportFmt);

    /* Port for which the Client needs to obtain info */
    inputportFmt.nPortIndex = portParam.nStartPortNumber;

    OMX_GetParameter(aac_dec_handle,OMX_IndexParamPortDefinition,&inputportFmt);
    DEBUG_PRINT ("\nDec: Input Buffer Count %d\n", inputportFmt.nBufferCountMin);
    DEBUG_PRINT ("\nDec: Input Buffer Size %d\n", inputportFmt.nBufferSize);

    if(OMX_DirInput != inputportFmt.eDir) {
        DEBUG_PRINT ("\nDec: Expect Input Port\n");
    return -1;
    }

if(tunnel == 0)
{
    /* Query the decoder outport's min buf requirements */
    CONFIG_VERSION_SIZE(outputportFmt);
    /* Port for which the Client needs to obtain info */
    outputportFmt.nPortIndex = portParam.nStartPortNumber + 1;

    OMX_GetParameter(aac_dec_handle,OMX_IndexParamPortDefinition,&outputportFmt);
    DEBUG_PRINT ("\nDec: Output Buffer Count %d\n", outputportFmt.nBufferCountMin);
    DEBUG_PRINT ("\nDec: Output Buffer Size %d\n", outputportFmt.nBufferSize);

    if(OMX_DirOutput != outputportFmt.eDir) {
        DEBUG_PRINT ("\nDec: Expect Output Port\n");
    return -1;
    }
}

    CONFIG_VERSION_SIZE(aacparam);


    aacparam.nPortIndex   =  0;
    aacparam.nChannels    =  channels; //2 ; /* 1-> mono 2-> stereo*/
    aacparam.nBitRate     =  samplerate; //SAMPLE_RATE;
    aacparam.nSampleRate  =  samplerate; //SAMPLE_RATE;
    aacparam.eChannelMode =  OMX_AUDIO_ChannelModeStereo;
    if (sbr_ps_enabled == 0 )
        aacparam.eAACProfile = OMX_AUDIO_AACObjectLC;
    else if (sbr_ps_enabled == 1 )
        aacparam.eAACProfile = OMX_AUDIO_AACObjectHE;
    else if (sbr_ps_enabled == 2 )
        aacparam.eAACProfile = OMX_AUDIO_AACObjectHE_PS;
    aacparam.eAACStreamFormat    =  OMX_AUDIO_AACStreamFormatMP2ADTS;
    OMX_SetParameter(aac_dec_handle,OMX_IndexParamAudioAac,&aacparam);


#ifdef PCM_PLAYBACK
if(pcmplayback == 1)
{
          DEBUG_PRINT(" open pcm device \n");
          m_pcmdrv_fd = open("/dev/msm_pcm_out", O_RDWR);
          if (m_pcmdrv_fd < 0) {
            DEBUG_PRINT("Play_Decoder: cannot open audio device");

          }
          DEBUG_PRINT(" Play_Decoder: open pcm device successfull\n");
}
#endif  // PCM_PLAYBACK


#ifdef PCM_PLAYBACK
if(pcmplayback == 1)
{
        DEBUG_PRINT("configure Driver for PCM playback \n");
        ioctl(m_pcmdrv_fd, AUDIO_GET_CONFIG, &drv_pcm_config);
        drv_pcm_config.sample_rate = samplerate; //SAMPLE_RATE; //m_adec_param.nSampleRate;
        drv_pcm_config.channel_count = channels; //STEREO;
       // drv_pcm_config.in_buf_size  = OMX_AAC_OUTPUT_BUFFER_SIZE ;
        ioctl(m_pcmdrv_fd, AUDIO_SET_CONFIG, &drv_pcm_config);
      //  ioctl(m_pcmdrv_fd, AUDIO_START, 0);
}
#endif //PCM_PLAYBACK


    DEBUG_PRINT ("\nOMX_SendCommand Decoder -> IDLE\n");
    OMX_SendCommand(aac_dec_handle, OMX_CommandStateSet, OMX_StateIdle,0);
    /* wait_for_event(); should not wait here event complete status will
       not come until enough buffer are allocated */

    input_buf_cnt = inputportFmt.nBufferCountMin + 5;
    DEBUG_PRINT("Transition to Idle State succesful...\n");
    /* Allocate buffer on decoder's i/p port */
    error = Allocate_Buffer(aac_dec_handle, &pInputBufHdrs, inputportFmt.nPortIndex,
                            input_buf_cnt, inputportFmt.nBufferSize);
    if (error != OMX_ErrorNone) {
        DEBUG_PRINT ("\nOMX_AllocateBuffer Input buffer error\n");
    return -1;
    }
    else {
        DEBUG_PRINT ("\nOMX_AllocateBuffer Input buffer success\n");
    }

if(tunnel == 0)
{
    output_buf_cnt = outputportFmt.nBufferCountMin ;

    /* Allocate buffer on decoder's O/Pp port */
    error = Allocate_Buffer(aac_dec_handle, &pOutputBufHdrs, outputportFmt.nPortIndex,
                            output_buf_cnt, outputportFmt.nBufferSize);
    if (error != OMX_ErrorNone) {
        DEBUG_PRINT ("\nOMX_AllocateBuffer Output buffer error\n");
    return -1;
    }
    else {
        DEBUG_PRINT ("\nOMX_AllocateBuffer Output buffer success\n");
    }
}

    wait_for_event();


if (tunnel == 1)
{
    DEBUG_PRINT ("\nOMX_SendCommand to enable TUNNEL MODE during IDLE\n");
    OMX_SendCommand(aac_dec_handle, OMX_CommandPortDisable,1,0);
    wait_for_event();
}

    DEBUG_PRINT ("\nOMX_SendCommand Decoder -> Executing\n");
    OMX_SendCommand(aac_dec_handle, OMX_CommandStateSet, OMX_StateExecuting,0);
    wait_for_event();

    DEBUG_PRINT(" Start sending OMX_emptythisbuffer\n");
    for (i = 0;i < input_buf_cnt;i++) {
        DEBUG_PRINT ("\nOMX_EmptyThisBuffer on Input buf no.%d\n",i);
        pInputBufHdrs[i]->nInputPortIndex = 0;
        Size = Read_Buffer(pInputBufHdrs[i]);
        if(Size <=0 ){
          DEBUG_PRINT("NO DATA READ\n");
        }
        pInputBufHdrs[i]->nFilledLen = Size;
        pInputBufHdrs[i]->nInputPortIndex = 0;
        used_ip_buf_cnt++;
        ret = OMX_EmptyThisBuffer(aac_dec_handle, pInputBufHdrs[i]);
        if (OMX_ErrorNone != ret) {
            DEBUG_PRINT("OMX_EmptyThisBuffer failed with result %d\n", ret);
        }
        else {
            DEBUG_PRINT("OMX_EmptyThisBuffer success!\n");
        }
    }

    // wait for port settings changed event
    wait_for_event();
    DEBUG_PRINT("************************************");
    DEBUG_PRINT("RECIEVED EVENT PORT SETTINGS CHANGED EVENT\n");
    DEBUG_PRINT("******************************************\n");

    DEBUG_PRINT("************************************");
    DEBUG_PRINT("NOW SENDING FLUSH CMD\n");
    DEBUG_PRINT("******************************************\n");
    OMX_SendCommand(aac_dec_handle, OMX_CommandFlush, 1, 0);

    wait_for_event();
    DEBUG_PRINT("************************************");
    DEBUG_PRINT("RECIEVED FLUSH EVENT CMPL\n");
    DEBUG_PRINT("******************************************\n");

    // Send DISABLE command
    OMX_SendCommand(aac_dec_handle, OMX_CommandPortDisable, 1, 0);

    DEBUG_PRINT("******************************************\n");
    DEBUG_PRINT("FREEING BUFFERS output_buf_cnt=%d\n",output_buf_cnt);
    DEBUG_PRINT("******************************************\n");
    // Free output Buffer
    for(bufCnt=0; bufCnt < output_buf_cnt; ++bufCnt) {
        OMX_FreeBuffer(aac_dec_handle, 1, pOutputBufHdrs[bufCnt]);
    }

    // wait for Disable event to come back
    wait_for_event();
    DEBUG_PRINT("******************************************\n");
    DEBUG_PRINT("DISABLE EVENT RECD\n");
    DEBUG_PRINT("******************************************\n");

        // Send Enable command
    OMX_SendCommand(aac_dec_handle, OMX_CommandPortEnable, 1, 0);

    // AllocateBuffers
    DEBUG_PRINT("******************************************\n");
    DEBUG_PRINT("ALLOC BUFFER AFTER PORT REENABLE");
    DEBUG_PRINT("******************************************\n");
    /* Allocate buffer on decoder's o/p port */
    error = Allocate_Buffer(aac_dec_handle, &pOutputBufHdrs, outputportFmt.nPortIndex,
                            output_buf_cnt, outputportFmt.nBufferSize);
    if (error != OMX_ErrorNone) {
        DEBUG_PRINT ("\nOMX_AllocateBuffer Output buffer error output_buf_cnt=%d\n",output_buf_cnt);
        return -1;
    }
    else
    {
        DEBUG_PRINT ("\nOMX_AllocateBuffer Output buffer success output_buf_cnt=%d\n",output_buf_cnt);
    }

    DEBUG_PRINT("******************************************\n");
    DEBUG_PRINT("ENABLE EVENTiHANDLER RECD\n");
    DEBUG_PRINT("******************************************\n");
    // wait for enable event to come back
    wait_for_event();

    DEBUG_PRINT("******************************************\n");
    DEBUG_PRINT("FTB after PORT RENABLE\n");
    DEBUG_PRINT("******************************************\n");
    for(i=0; i < output_buf_cnt; i++) {
        DEBUG_PRINT ("\nOMX_FillThisBuffer on output buf no.%d\n",i);
        pOutputBufHdrs[i]->nOutputPortIndex = 1;
        //pOutputBufHdrs[i]->nFlags &= ~OMX_BUFFERFLAG_EOS;
        ret = OMX_FillThisBuffer(aac_dec_handle, pOutputBufHdrs[i]);
        if (OMX_ErrorNone != ret) {
            DEBUG_PRINT("OMX_FillThisBuffer failed with result %d\n", ret);
    }
        else {
            DEBUG_PRINT("OMX_FillThisBuffer success!\n");
    }
    }

    return 0;
}
int Play_Decoder()
{
    int i;
    int Size=0;
    DEBUG_PRINT("Inside %s \n", __FUNCTION__);
    OMX_ERRORTYPE ret;
    OMX_INDEXTYPE index;

    DEBUG_PRINT("sizeof[%d]\n", sizeof(OMX_BUFFERHEADERTYPE));

    /* open the i/p and o/p files based on the video file format passed */
    if(open_audio_file()) {
        DEBUG_PRINT("\n Returning -1");
    return -1;
    }

    /*  Configuration of Input Port definition */

    /* Query the decoder input min buf requirements */
    CONFIG_VERSION_SIZE(inputportFmt);

    /* Port for which the Client needs to obtain info */
    inputportFmt.nPortIndex = portParam.nStartPortNumber;

    OMX_GetParameter(aac_dec_handle,OMX_IndexParamPortDefinition,&inputportFmt);
    DEBUG_PRINT ("\nDec: Input Buffer Count %lu\n", inputportFmt.nBufferCountMin);
    DEBUG_PRINT ("\nDec: Input Buffer Size %lu\n", inputportFmt.nBufferSize);

    if(OMX_DirInput != inputportFmt.eDir) {
        DEBUG_PRINT ("\nDec: Expect Input Port\n");
    return -1;
    }

    inputportFmt.nBufferCountActual = inputportFmt.nBufferCountMin + 5;
    OMX_SetParameter(aac_dec_handle,OMX_IndexParamPortDefinition,&inputportFmt);
    OMX_GetExtensionIndex(aac_dec_handle,"OMX.Qualcomm.index.audio.sessionId",&index);
    OMX_GetParameter(aac_dec_handle,index,&streaminfoparam);
#ifdef AUDIOV2
    session_id = streaminfoparam.sessionId;
	devmgr_fd = open("/data/omx_devmgr", O_WRONLY);
	if(devmgr_fd >= 0)
	{
		control = 0;
		write_devctlcmd(devmgr_fd, "-cmd=register_session_rx -sid=", session_id);
	}
	else
	{
		/*control = msm_mixer_open("/dev/snd/controlC0", 0);
		if(control < 0)
		printf("ERROR opening the device\n");
		device_id = msm_get_device(device);
		device_id = 2;
		DEBUG_PRINT ("\ndevice_id = %d\n",device_id);
		DEBUG_PRINT("\nsession_id = %d\n",session_id);
		if (msm_en_device(device_id, 1))
		{
			perror("could not enable device\n");
			return -1;
		}

		if (msm_route_stream(1,session_id,device_id, 1))
		{
			perror("could not set stream routing\n");
			return -1;
		}
		*/
	}
#endif
    /*  Configuration of Ouput Port definition */

    /* Query the decoder outport's min buf requirements */
    CONFIG_VERSION_SIZE(outputportFmt);
    /* Port for which the Client needs to obtain info */
    outputportFmt.nPortIndex = portParam.nStartPortNumber + 1;

    OMX_GetParameter(aac_dec_handle,OMX_IndexParamPortDefinition,&outputportFmt);
    DEBUG_PRINT ("\nDec: Output Buffer Count %lu\n", outputportFmt.nBufferCountMin);
    DEBUG_PRINT ("\nDec: Output Buffer Size %lu\n", outputportFmt.nBufferSize);

    if(OMX_DirOutput != outputportFmt.eDir) {
        DEBUG_PRINT ("\nDec: Expect Output Port\n");
    return -1;
    }

    outputportFmt.nBufferCountActual = outputportFmt.nBufferCountMin + 3;
    OMX_SetParameter(aac_dec_handle,OMX_IndexParamPortDefinition,&outputportFmt);

    CONFIG_VERSION_SIZE(aacparam);
    aacparam.nPortIndex   =  0;
    aacparam.nChannels    =  channels; //2 ; /* 1-> mono 2-> stereo*/
    aacparam.nBitRate     =  samplerate; //SAMPLE_RATE;
    aacparam.nSampleRate  =  samplerate; //SAMPLE_RATE;
    aacparam.eChannelMode =  OMX_AUDIO_ChannelModeStereo;
    if (sbr_ps_enabled == 0 )
        aacparam.eAACProfile = OMX_AUDIO_AACObjectLC;
    else if (sbr_ps_enabled == 1 )
        aacparam.eAACProfile = OMX_AUDIO_AACObjectHE;
    else if (sbr_ps_enabled == 2 )
        aacparam.eAACProfile = OMX_AUDIO_AACObjectHE_PS;
    aacparam.eAACStreamFormat    =  OMX_AUDIO_AACStreamFormatMP2ADTS;
    OMX_SetParameter(aac_dec_handle,OMX_IndexParamAudioAac,&aacparam);


    DEBUG_PRINT ("\nOMX_SendCommand Decoder -> IDLE\n");
    OMX_SendCommand(aac_dec_handle, OMX_CommandStateSet, OMX_StateIdle,0);
    /* wait_for_event(); should not wait here event complete status will
       not come until enough buffer are allocated */

    input_buf_cnt = inputportFmt.nBufferCountActual; //  inputportFmt.nBufferCountMin + 5;
    DEBUG_PRINT("Transition to Idle State succesful...\n");
    /* Allocate buffer on decoder's i/p port */
    error = Allocate_Buffer(aac_dec_handle, &pInputBufHdrs, inputportFmt.nPortIndex,
                            input_buf_cnt, inputportFmt.nBufferSize);
    if (error != OMX_ErrorNone) {
        DEBUG_PRINT ("\nOMX_AllocateBuffer Input buffer error\n");
    return -1;
    }
    else {
        DEBUG_PRINT ("\nOMX_AllocateBuffer Input buffer success\n");
    }

    output_buf_cnt = outputportFmt.nBufferCountActual; // outputportFmt.nBufferCountMin ;

    /* Allocate buffer on decoder's O/Pp port */
    error = Allocate_Buffer(aac_dec_handle, &pOutputBufHdrs, outputportFmt.nPortIndex,
                            output_buf_cnt, outputportFmt.nBufferSize);
    if (error != OMX_ErrorNone) {
        DEBUG_PRINT ("\nOMX_AllocateBuffer Output buffer error\n");
    return -1;
    }
    else {
        DEBUG_PRINT ("\nOMX_AllocateBuffer Output buffer success\n");
    }

    wait_for_event();


    DEBUG_PRINT ("\nOMX_SendCommand Decoder -> Executing\n");
    OMX_SendCommand(aac_dec_handle, OMX_CommandStateSet, OMX_StateExecuting,0);
    wait_for_event();

    DEBUG_PRINT(" Start sending OMX_FILLthisbuffer\n");
    for(i=0; i < output_buf_cnt; i++) {
        DEBUG_PRINT ("\nOMX_FillThisBuffer on output buf no.%d\n",i);
        pOutputBufHdrs[i]->nOutputPortIndex = 1;
        pOutputBufHdrs[i]->nFlags = 0;
        ret = OMX_FillThisBuffer(aac_dec_handle, pOutputBufHdrs[i]);
        if (OMX_ErrorNone != ret) {
            DEBUG_PRINT("OMX_FillThisBuffer failed with result %d\n", ret);
        }
        else {
            DEBUG_PRINT("OMX_FillThisBuffer success!\n");
        }
    }

    DEBUG_PRINT(" Start sending OMX_emptythisbuffer\n");
    for (i = 0;i < input_buf_cnt;i++) {
        DEBUG_PRINT ("\nOMX_EmptyThisBuffer on Input buf no.%d\n",i);
        pInputBufHdrs[i]->nInputPortIndex = 0;
        Size = Read_Buffer(pInputBufHdrs[i]);
        if(Size <=0 ){
          DEBUG_PRINT("NO DATA READ\n");
          //bInputEosReached = true;
          bEosOnInputBuf = true;
          pInputBufHdrs[i]->nFlags= OMX_BUFFERFLAG_EOS;
        }
        pInputBufHdrs[i]->nFilledLen = Size;
        pInputBufHdrs[i]->nInputPortIndex = 0;
        used_ip_buf_cnt++;
        ret = OMX_EmptyThisBuffer(aac_dec_handle, pInputBufHdrs[i]);
        if (OMX_ErrorNone != ret) {
            DEBUG_PRINT("OMX_EmptyThisBuffer failed with result %d\n", ret);
        }
        else {
            DEBUG_PRINT("OMX_EmptyThisBuffer success!\n");
        }
        if(Size <=0 ){
            break;//eos reached
        }
    }
    pthread_mutex_lock(&etb_lock);
    if(etb_done)
    {
        DEBUG_PRINT("Component is waiting for EBD to be released.\n");
        etb_event_complete();
    }
    else
    {
        DEBUG_PRINT("\n****************************\n");
        DEBUG_PRINT("EBD not yet happened ...\n");
        DEBUG_PRINT("\n****************************\n");
        etb_done++;
    }
    pthread_mutex_unlock(&etb_lock);
    while(1)
    {
        wait_for_event();
        if(bOutputEosReached)
        {
            bReconfigureOutputPort = 0;
            printf("bOutputEosReached breaking\n");
            break;
        }
        else
        {
            if(bReconfigureOutputPort)
               process_portreconfig();
        }
    }
    return 0;
}
Exemplo n.º 9
0
void MainLoop() {
    double start_time, end_time;
    struct timespec start,end;
    long long unsigned int diff_time;
    int built1 = false;
    int built2 = false;
                        // args
                      built2 = false;
                        validRecords = 0;
    // B+tree initialize
    BPlusTree_Init();
    while (1) {
        ShowHelp();
        int request;
        scanf("%d", &request);
        switch (request) {
            case 0: {
                        long long unsigned int total = 0;
                        if (built2 == true) {
                            printf("You have built the B+tree\n");
                            break;
                        }
                        buffer2 = Read_Buffer(buffer2,input_file2);
                        built2 = true;
                        clock_gettime(CLOCK_REALTIME,&start);
                        Read_Data_And_Insert(buffer2);
                        clock_gettime(CLOCK_REALTIME,&end);
                        diff_time = BILLION * (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec);
                        total += diff_time;

                       // BPlusTree_Print();

                        printf("Valid Records inserted on B+tree = %d\n", validRecords);
                        printf("Total number of B+tree nodes = %d\n", BPlusTree_GetTotalNodes());
                        printf("Build B+tree costs %llu ms\n",total /1000000);
                        printf("Total number of split_count  = %d\n", BPlusTree_GetSplitCount());
                        printf("Node size %lu byte\n",sizeof(struct BPlusTreeNode));
 
                        break;
                    }
            case 1: {
                        // Set Depth
                        printf("input depth: ");
                        int depth;
                        scanf("%d", &depth);
                        int maxCh = 2;
                        while (1) {
                            int leaves = 1, i;
                            for (i = 0; i < depth; i++) {
                                leaves *= maxCh;
                                if (leaves > TotalRecords) break;
                            }
                            if (leaves > TotalRecords) break;
                            maxCh++;
                        }
                        printf("Desired depth = %d, calculated maxChildNumber = %d\n", depth, maxCh);
                        BPlusTree_SetMaxChildNumber(maxCh);
                        break;
                    }
            case 2: {
                        // Set MaxChildNumber
                        printf("input MaxChildNumber: ");
                        int maxCh;
                        scanf("%d", &maxCh);
                        BPlusTree_SetMaxChildNumber(maxCh);
                        break;
                    }
            case 3: {
                        long long unsigned int total = 0 ;
                        // Build B+tree
                        if (built1 == true) {
                            printf("You have built the B+tree\n");
                            break;
                        }
                        buffer = Read_Buffer(buffer,input_file);
                        built1 = true;
                        clock_gettime(CLOCK_REALTIME,&start);
                        Read_Data_And_Insert(buffer);
                        clock_gettime(CLOCK_REALTIME,&end);
                        diff_time = BILLION * (end.tv_sec - start.tv_sec) + end.tv_nsec - start.tv_nsec;
                        total += diff_time;

                        printf("Valid Records inserted on B+tree = %d\n", validRecords);
                        printf("Total number of B+tree nodes = %d\n", BPlusTree_GetTotalNodes());
                        printf("Build B+tree costs %llu ms\n",total /1000000);
                        printf("Total number of split_count  = %d\n", BPlusTree_GetSplitCount());
                        //        BPlusTree_Print();
                        break;
                    }
            case 4: {
                        long long unsigned int total = 0;
                        buffer2 = Read_Buffer(buffer2,input_file2);
                        total = Read_Data_And_Search(buffer2);

                        printf(" Total time %llu ms\n", total / CLOCKS_PER_SEC);
                        break;
                    }
            case 5: {
                        // Query on a range [l, r]
                        printf("input range [l, r]: ");
                        int l, r;
                        scanf("%d %d", &l, &r);
                        if (l > r) {
                            printf("input illegal\n");
                            break;
                        }
                        start_time = clock();
                        BPlusTree_Query_Range(l, r);
                        end_time = clock();
                        printf("Query on a range, costs %lf s\n", (end_time - start_time) / CLOCKS_PER_SEC);
                        break;
                    }
            case 7:{
                       long long unsigned int total = 0;

                       buffer2 = Read_Buffer(buffer2,input_file2);
                       total = Read_Data_And_Delete(buffer2);
            //            BPlusTree_Print();
                       printf("Total time costs %llu ms\n",total /1000000);
                       break;

                   }/*
                       {
                   // Modify value on a key
                   case 9:{
                   int num,j,value;
                   double total,temp;
                   char s[] = "dkdka";
                   value = 4;
                   total = 0;
                   temp = 0;
                   for(j=1; j<=4; j++)
                   {
                   start_time = clock();
                   BPlusTree_Insert(j,0,s);
                   end_time = clock();
                   total += end_time - start_time;

                   validRecords++;
                   }
                   BPlusTree_Print();
                   printf("Valid Records inserted on B+tree = %d\n", validRecords);
                   printf("Total number of B+tree nodes = %d\n", BPlusTree_GetTotalNodes());
                   printf("Build B+tree costs %lf s\n", (end_time - start_time) / CLOCKS_PER_SEC);
                   printf("Total time %lf s\n",total/ CLOCKS_PER_SEC);
                   printf("Total number of split_count : %d\n",BPlusTree_GetSplitCount());
                   break;

                   }
                   */
            case 10: return;
            default: break;

        }
        }

    }
Exemplo n.º 10
0
void MainLoop() {
	double start_time, end_time;
	int built = false;

	// Read data to buffer
	Read_Buffer(input_file);
	// B+tree initialize
	BPlusTree_Init();
	while (1) {
		ShowHelp();
		int request;
		scanf("%d", &request);
		switch (request) {
			case 0: {
				// Read data to buffer
				if (buffer != NULL) free(buffer);
				Read_Buffer(input_file);
				// B+tree initialize
				BPlusTree_Init();
				// args
				built = false;
				validRecords = 0;
				break;
			}
			case 1: {
				// Set Depth
				printf("input depth: ");
				int depth;
				scanf("%d", &depth);
				int maxCh = 2;
				while (1) {
					int leaves = 1, i;
					for (i = 0; i < depth; i++) {
						leaves *= maxCh;
						if (leaves > TotalRecords) break;
					}
					if (leaves > TotalRecords) break;
					maxCh++;
				}
				printf("Desired depth = %d, calculated maxChildNumber = %d\n", depth, maxCh);
				BPlusTree_SetMaxChildNumber(maxCh);
				break;
			}
			case 2: {
				// Set MaxChildNumber
				printf("input MaxChildNumber: ");
				int maxCh;
				scanf("%d", &maxCh);
				BPlusTree_SetMaxChildNumber(maxCh);
				break;
			}
			case 3: {
				// Build B+tree
				if (built == true) {
					printf("You have built the B+tree\n");
					break;
				}
				built = true;
				start_time = clock();
				Read_Data_And_Insert();
				end_time = clock();
				printf("Valid Records inserted on B+tree = %d\n", validRecords);
				printf("Total number of B+tree nodes = %d\n", BPlusTree_GetTotalNodes());
				printf("Build B+tree costs %lf s\n", (end_time - start_time) / CLOCKS_PER_SEC);
				break;
			}
			case 4: {
				// Query on a key
				printf("input the key: ");
				int key;
				scanf("%d", &key);
				start_time = clock();
				BPlusTree_Query_Key(key);
				end_time = clock();
				printf("Query on a key, costs %lf s\n", (end_time - start_time) / CLOCKS_PER_SEC);
				break;
			}
			case 5: {
				// Query on a range [l, r]
				printf("input range [l, r]: ");
				int l, r;
				scanf("%d %d", &l, &r);
				if (l > r) {
					printf("input illegal\n");
					break;
				}
				start_time = clock();
				BPlusTree_Query_Range(l, r);
				end_time = clock();
				printf("Query on a range, costs %lf s\n", (end_time - start_time) / CLOCKS_PER_SEC);
				break;
			}
			case 6: {
				// Modify value on a key
				printf("input (key, value): ");
				scanf("%d %s", &new_key, new_st);
				char* value = (char*)malloc(sizeof(char) * strlen(new_st));
				strcpy(value, new_st);
				start_time = clock();
				int pos = BPlusTree_Find(new_key);
				if (pos != -1) { // found
					if (File_Modify(pos, new_key, new_st)) { // file modify success
						BPlusTree_Modify(new_key, value);
						printf("Modify success.\n");
					} else {
						printf("Modify failed, the new value is too long to store in file\n");
					}
				} else {
					printf("Modify failed, do not have the given key on B+tree.\n");
				}
				end_time = clock();
				printf("Modify value on a key, costs %lf s\n", (end_time - start_time) / CLOCKS_PER_SEC);
				break;
			}
			case 7: {
				// Delete value on a key
				printf("input key: ");
				int key;
				scanf("%d", &key);
				start_time = clock();
				int pos = BPlusTree_Find(key);
				if (pos != -1) { // found
					File_Delete(pos);
					BPlusTree_Delete(key);
					printf("Delete success.\n");
				} else {
					printf("Delete failed, do not have the given key on B+tree.\n");
				}
				end_time = clock();
				printf("Delete value on a key, costs %lf s\n", (end_time - start_time) / CLOCKS_PER_SEC);
				break;
			}
			case 8: {
				printf("input (key, value): ");
				scanf("%d %s", &new_key, new_st);
				char* value = (char*)malloc(sizeof(char) * new_len);
				strcpy(value, new_st);

				int pos = BPlusTree_Find(new_key);
				if (pos == -1) {
					new_pos = File_Insert(new_key, new_st);
					keys[key_num++] = new_key;
					BPlusTree_Insert(new_key, new_pos, value);
					validRecords++;
					printf("Insert success.\n");
				} else {
					printf("Insert failed, the key already exist.\n");
				}
				break;
			}
			case 9: return;
			default: break;
		}
	}
	BPlusTree_Destroy();
}