コード例 #1
0
ファイル: Queue.c プロジェクト: hamiltop/CultOfSkaro
/** Code to test this Queue implementation
This code is only included for example purposes and to ensure that 
this implementation works in all situations

This code at present is not exhaustive.

STEPS:
- Test 1
  -# Push some integers onto the Queue inplace of pointers.
  -# Pop all of the elements off the queue to make sure that they match
- Test2 
  -# TODO 

\todo Write a more exhaustive test 

*/
int QueueTest()
{
	Queue queue;
	void* ary[10];

	QueueInit( &queue, ary, 10 );

	// Test 1
	{
		{
			int i;
			for( i = 0 ; i < 10 ; i++ )
				QueuePush( &queue, (void*) i ); 
		}

		if(QueueIsFull(&queue) != TRUE)
			return 1;

		{
			int i;
			for( i = 0 ; i < 10 ; i++ )
			{
				int val = (int) QueuePop( &queue );
				if(val != i)
					return 2;
			}		
		}
		
		if(QueueIsEmpty(&queue) != TRUE)
			return 3;

		if(QueueIsFull(&queue) != FALSE)
			return 4;
	}


	// Test 2
	{
		QueuePush( &queue, (void*) 1234); 
		if((int)QueueFront(&queue) != 1234)
			return 5;
	}


	return 0;
}
コード例 #2
0
ファイル: Queue.c プロジェクト: godspeed1989/misc
BOOLEAN QueueInsert (PQueue Queue, QUEUE_DAT_T Entry)
{
	if (QueueIsFull(Queue) == TRUE)
		return FALSE;
	Queue->Data[Queue->Tail] = Entry;
	Queue->Tail = (Queue->Tail + 1) % Queue->Size;
	Queue->Used++;
	return TRUE;
}
コード例 #3
0
ファイル: queue.c プロジェクト: zinuzoid/zAgriRobotMCU
unsigned char QueueInsert(ZQUEUE* q,unsigned char item)
{
	if(!QueueIsFull(q))
	{
		q->item[q->tail]=item;
		q->tail=(q->tail+1)%QUEUE_MAX;
		return 1;
	}
	return 0;
}
コード例 #4
0
ファイル: Queue.c プロジェクト: OliverLew/DataStructure
/**
 * @brief 
 * @param Q 
 * @param X 
 * 
 * 
 */
void QueueEnqueue(Queue Q, ElementType X)
{
    if (QueueIsFull(Q))
    {
        fprintf(stderr, "Enqueue: queue if full!\n");
        exit(1);
    }
    Q->rear = succ(Q->rear, Q);
    Q->array[Q->rear] = X;
    Q->size++;
}
コード例 #5
0
ファイル: Queue.c プロジェクト: hamiltop/CultOfSkaro
/** Appends a data element onto the back of the Queue
	The current index of the back of the Queue is held 
	in the Queue::back field. To append a value onto the back
	of the Queue the Queue::back field is incremented by one 
	and then the new data value is inserted into the data
	array at that new index location. If the incrementing of 
	the Queue::back index causes it to roll off the end of the 
	array, then the Queue::back is set back to 0.

	This function also checks to see if the Queue is already 
	full. If it is full, then this function returns FALSE.
	This function will return TRUE if the insertion was 
	successful. 

\param Q The Queue to perform this function on
\param X The data to be appended to the back of the Queue
\return Returns TRUE if insertion was successful, FALSE otherwise
*/
int QueuePush(Queue* Q, void* X ) 
{
	if(QueueIsFull(Q)) 
		return FALSE;

	Q->back++;
	if(Q->back >= Q->capacity)
		Q->back = 0;

	Q->data[Q->back] = X;
	Q->size++;	
	
	return TRUE;
}
コード例 #6
0
ファイル: 8tree.c プロジェクト: 18616378431/myCode
//添加元素,即节点
BOOL AddItem(const Item * pi,Tree * ptree)
{
	Node * new_node;//新节点
	Pair look;
	
	//初始化查找到的与输入相同的节点look
	/*look.parent = NULL;
	look.child = NULL;*/

	if(TreeIsFull(ptree))//判断树是否已满
	{
		fprintf(stderr,"Tree is full.\n");
		return FALSE;
	}
	if((look = SeekItem(pi,ptree)).child != NULL)//在树中查找目标项目
	{
		fprintf(stderr,"Attempted to add duplicate item\n");
		//如果树中已经存在相应节点,则将新同名元素添加到已有节点列表的末尾
		if(QueueIsFull(look.child->queue))//判断当前节点列表是否已满
		{
			fprintf(stderr,"Current node's queue is full.\n");
			return FALSE;
		}
		EnQueue(*pi,look.child->queue);
	}
	else
	{
		new_node = MakeNode(pi);//创建新节点,成功返回新节点,否则返回NULL
		if(new_node == NULL)//创建失败,返回false
		{
			fprintf(stderr,"Couldn't create node!\n");
			return FALSE;
		}
		//节点创建成功,向树中添加节点
		ptree->size++;//树的大小加1
		if(ptree->root == NULL)//如果树为空
		{
			ptree->root = new_node;
		}
		else
		{
			AddNode(new_node,ptree->root);//找到新节点应该添加到的位置
		}
	}
	return TRUE;
}
コード例 #7
0
ファイル: use_q.c プロジェクト: celine80/sites
int main(void)
{
    Queue line;
    Item temp;
    char ch;

    InitializeQueue(&line);
    puts("Testing the Queue interface. Type a to add a value,");
    puts("type d to delete a value, and type q to quit.");
    while ((ch = getchar()) != 'q')
    {
        if (ch != 'a' && ch != 'd')   /* ignore other input */
            continue; 
        if ( ch == 'a')
        {
            printf("Integer to add: ");
            scanf("%d", &temp);
            if (!QueueIsFull(&line))
            {
                printf("Putting %d into queue\n", temp);
                EnQueue(temp,&line);
            }
           else
               puts("Queue is full!");
        }
        else
        {
            if (QueueIsEmpty(&line))
                puts("Nothing to delete!");
            else
            {
                 DeQueue(&temp,&line);
                 printf("Removing %d from queue\n", temp);
            }
        }
        printf("%d items in queue\n", QueueItemCount(&line));
        puts("Type a to add, d to delete, q to quit:");
    }
    EmptyTheQueue(&line);
    puts("Bye!");

    return 0;
}
コード例 #8
0
ファイル: use_q.c プロジェクト: ludwig123/ADT
int main(void)
{
    Queue line;
    Item temp;
    char ch;
    
    InitializeQueue(&line);
    puts("testing the queue interface. type a to  a value");
    puts("type d to delete a value, and type q tp quit.");
    while ((ch = getchar()) != 'q')
    {
        while (ch != 'a' && ch != 'd')
            continue;
        if (ch == 'a')
        {
            printf("integer to add: ");
            scanf("%d",&temp);
            if (!QueueIsFull(&line)) //添加前确认一下队列
            {
                printf("putting %d into queue\n", temp); //重复输入的内容,确认一遍
                EnQueue(temp, &line);
            }
        }
        else
        {
            if (QueueIsEmpty(&line))
                puts("nothing to delete!");
            else
            {
                DeQueue(&temp, &line);
                printf("removing %d from queue\n",temp);
            }
        }
        printf("%d item in queue\n",QueueItemCount(&line));
        puts("type a to add, d to delete, q to quit: ");
    }
    EmptyTheQueue(&line);
    puts("bye!");
    
    return 0;
}
コード例 #9
0
ファイル: queue2.c プロジェクト: Ricky-Hao/C-Primer-Plus-Demo
bool EnQueue(Item item, Queue *pq)
{
	Node *pnew;

	if (QueueIsFull(pq))
		return false;
	pnew = (Node *)malloc(sizeof(Node));
	if (pnew == NULL)
	{
		fprintf(stderr, "Unable to allocate memory!\n");
		exit(1);
	}
	CopyToNode(item, pnew);
	pnew->next = NULL;
	if (QueueIsEmpty(pq))
		pq->front = pnew;		//项目位于队列首端
	else
		pq->rear->next = pnew;
	pq->rear = pnew;
	pq->items++;
	return true;
}
コード例 #10
0
ファイル: 8list.c プロジェクト: 18616378431/myCode
BOOL EnQueue(Item item,Queue * pq)
{
	Qnode * pnew;
	
	if(QueueIsFull(pq))
		return FALSE;
	pnew = (Qnode *)malloc(sizeof(Qnode));
	if(pnew == NULL)
	{
		fprintf(stderr,"Unable allocate memory!\n");
		exit(1);
	}
	CopyToNode(item,pnew);
	pnew->next = NULL;
	if(QueueIsEmpty(pq))
		pq->head = pnew;
	else
		pq->end->next = pnew;
	pq->end = pnew;
	pq->items++;
	return TRUE;
}
コード例 #11
0
ファイル: mall.c プロジェクト: ludwig123/ADT
int main(void)
{
    Queue line;
    Item temp;   //关于顾客的数据
    int hours;   //模拟的小时数
    int perhours;  //每小时的平均顾客数
    long cycle, cyclelimit; //循环计数器,计数器的上界
    long turnaways = 0;  //因队列已满而被拒绝的顾客数量
    long customers = 0;  //被加入队列的顾客数
    long served = 0;
    long sum_line = 0;  //累计的队列长度
    long wait_time = 0;  //从当前到Sigmund空闲所需的时间
    double min_per_cust;
    long line_wait = 0;
    
    InitializeQueue(&line);
    srand(time(0));
    puts("case study: sigmund lander's advice booth");
    puts("enter the number of simulation hours: ");
    scanf("%d",&hours);
    cyclelimit = MIN_PER_HR * hours;
    puts("enter the average number of customers per hour: ");
    scanf("%d",&perhours);
    min_per_cust = MIN_PER_HR / perhours;
    
    for (cycle = 0; cycle < cyclelimit; cycle++)
    {
        if (newcustomer(min_per_cust))
        {
         if (QueueIsFull(&line))  //如果队列是满的
            turnaways++;
            else  //如果队列不是满的
            {
                customers++;
                temp = customertime(cycle);
                EnQueue(temp, &line);
            }
        }
        
        if (wait_time <= 0 && !QueueIsEmpty(&line)) //如果不需要等待,且队列不是空的;意味着只有一个人!
        {
            DeQueue(&temp, &line);
            wait_time = temp.processtime;
            line_wait += cycle - temp.arrive;
            served++;
        }
        if (wait_time > 0)
            wait_time--;
        sum_line += QueueItemCount(&line);
    }
    
    if (customers > 0)
    {
        printf("customer acccepted: %ld\n",customers);
        printf("customer served:%ld\n",served);
        printf(   "turnaways: %ld\n",turnaways);
        printf("average queue size: %.2f\n",(double)sum_line / cyclelimit);
        printf(" average wait time: %.2f minutes\n",(double)line_wait / served);
    }
    else
        puts("no customer!");
    EmptyTheQueue(&line);
    puts("BYE!");
    
    return 0;
}
コード例 #12
0
//读取包进程
void *ReadAvData(void *arg)
{
	if(!arg)
		return NULL;

	AvManager *manager = (AvManager*)arg;

	int size = 0;
	double cur_pos = 0;
	void *data = NULL;
	long avsize = 0;

	for(;;)
	{
		//先处理命令,命令可以改变状态
		switch(manager->avCommand)
		{
		case PAUSE_CMD:
			manager->avState = PAUSE;
			break;
		case PLAY_CMD:
			manager->avState = PLAY;
			break;
		case STOP_CMD:
			manager->avState = STOP;
			break;
		}
		//命令已经修改完毕状态,使命已经完成,恢复默认
		manager->avCommand = NONE_CMD;

		//如果是停止状态,则表示人为停止
		if(manager->avState == STOP)
		{
			manager->autoEnd = FALSE;
			break;
		}

		if(manager->avSeek)
		{
			cur_pos = CrroectAvPos(manager,manager->avPos);
			manager->playerClock = cur_pos;
			manager->avSeek = SeekPositon(cur_pos,0) >= 0;
		}

		//如果是快进,清空所有

		if(manager->avSeek)
		{
			if(manager->playAudio)
				QueueBufferFlush(manager->MediaAudio);
			if(manager->playVideo)
			{
				QueueBufferFlush(manager->MediaVideo);
				QueueBufferFlush(manager->MediaPicture);
			}
		}

		if(QueueIsFull(manager))
		{
			usSleep(DEFAULT_AV_WAIT);
			continue;			
		}

		//如果队列没满,则开始读包
		data = ExtractStream();

		if(!data)
		{
			if(GetError())
			{
				manager->autoEnd = TRUE;
				break;				
			}
		}
		else
			SendDataToAvQueue(manager,data);

		if(!manager->avSeek && RenderOver(manager) == 0)
		{
			manager->autoEnd = TRUE;
			break;
		}

		if(manager->playAudio)
		{
			double diff = AV_DIFF_DURATION(manager->playerClock,manager->duration);

			if(diff <= 0.5 && diff >= -0.5)
			{
				manager->autoEnd = TRUE;
				break;
			}
		}

		//如果当前状态是SEEK,那么你到此必须还原SEEK的上一次状态
		if(manager->avSeek)
		{
			usSleep(DEFAULT_AV_WAIT*10);
			manager->avSeek = FALSE;
		}
	}

	Manager.already = FALSE;

	if(manager->autoEnd)
	{
		pthread_mutex_lock(&actionMutex);
		printf("av stop!\n");
		manager->avState = STOP;
		printf("clear queure\n");

		if(manager->playAudio)
		{
			if(ParseQueueBufferLength(manager->MediaAudio) > 0)
				UninitQueueBuffer(manager->MediaAudio);
			pthread_join(manager->renderAudio,NULL);
		}

		if(Manager.playVideo)
		{
			if(ParseQueueBufferLength(manager->MediaVideo) > 0)
				UninitQueueBuffer(manager->MediaVideo);
			pthread_join(manager->renderVideo,NULL);
			if(ParseQueueBufferLength(manager->MediaPicture) > 0)
				UninitQueueBuffer(manager->MediaPicture);
			pthread_join(manager->synProcess,NULL);
		}
		printf("unload waveengine\n");
		manager->managerEnd = TRUE;
		UnitWaveEngine();
		printf("unload scale\n");
		DeInitScaleEngine();
		printf("close file\n");
		CloseOcxByOCX();
		printf("render over!\n");
		pthread_mutex_unlock(&actionMutex);
	}

	printf("ready to quit player!\n");

	while(!manager->managerEnd)
		usSleep(DEFAULT_AV_WAIT);

	if(manager->autoEnd)
		manager->ManagerOver = TRUE;

	printf("quit player!\n");

	Manager.playerClock = 0;
	Manager.duration = 0;

	return NULL;
}
コード例 #13
0
int main(int argc, char *argv[])
{
	// tweaked by SungboKang ///////////////////////////////////////////////////
	int frameCnt = 0;
	int tempSeparateH264FileNumber = 0;
	int thread_id;
	pthread_t controlThread;
	////////////////////////////////////////////////////////////////////////////

	char *			pImgBuff;
	SOCKET			StreamSock;
	char			strQuery[MAX_QUERY];

	int				AppKey;
	unsigned long	DaemonId = 0;
	int				ScanMode = SCAN_RAW_MODE;

	int				idx = 0;
	long			nRead;
	int				ImageSize;
	int				nRetCode;
	
	char			tmp_img_file[_MAX_PATH];
	
	SytJesVideoCodecTypeEnum current_codec;
	
#ifdef DECODER_ON
	Cffm4l ffm4l;
#endif
	
	int First_IFrame_Flag = 0;

	pImgBuff = (char*)malloc(MAX_PACK_SIZE);
	if(pImgBuff == NULL)
		return -1;

	
#ifdef DECODER_ON
	if (ffm4l.CreateFfm4lDecoder(CODEC_ID_H264)!=FFM4L_COMMON_SUCCESS)
	{
		printf("ffmpeg Create failed\n");
		free(pImgBuff);
		
		return -1;
	}
#endif

	current_codec = JES_VIDEO_CODEC_H264;
	setuped_codec = JES_VIDEO_CODEC_H264;

	SOCK_STARTUP();

	//=============================================================================
	//Get FlexWATCH System Information
// 	printf("FwSysGetCgiWp\n");
// 	memset(pImgBuff, 0, MAX_PACK_SIZE);
// 	nRead = FwSysGetCgiWp(VSMID, TARGET_IPADDR, TARGET_PORT, FW_USER_ID, FW_PASS_WD, pImgBuff, MAX_PACK_SIZE, wp_domain, wp_port);
// 	if(nRead > 0)
// 		printf("FwSysGetCgiWp=[%s]\n",pImgBuff);
	//=============================================================================

	//=============================================================================
	//Open Cgi Stream 
	AppKey = rand();

#ifdef __HEADER_STREAM_MODE_SUPPORT
	sprintf(	strQuery,
				STREAM_CGI_FMT_V30, 
				VSMID, 
				AppKey,
				"0",	// Port Id List (0,1,2,3)
				0x00, // 0x00 = Normal Mode, 0x0f = Header Only Mode 
				PAUSE_TIME, 
				FWCGI_VERSION);

#else	// Normal Mode Only 
	sprintf(	strQuery,
				STREAM_CGI_FMT_V30, 
				VSMID, 
				AppKey,
				"0,1",	// Port Id List (0,1,2,3)
				PAUSE_TIME, 
				FWCGI_VERSION);
#endif

	StreamSock = FwOpenGetCgiWp(TARGET_IPADDR, TARGET_PORT, FW_USER_ID, FW_PASS_WD, strQuery, OPEN_TIMEOUT, wp_domain, wp_port);
	if(StreamSock == INVALID_SOCKET)
	{
		SOCK_CLEANUP();
		free(pImgBuff);
		return 0;
	}
	//=============================================================================

	//=============================================================================
	
	// tweaked by SungboKang ////
	thread_id = pthread_create(&controlThread, NULL, Control_thread_function, NULL); // make the control thread
	if(thread_id < 0) // when thread creating doesnt work properly
	{
		perror("thread control creation error\n");
		exit(-1);
	}

	// if playlist file exists already, wipe it out and make a new one
	sprintf(tmp_img_file, PLAYLIST_FILENAME);
	if(!FileExist(tmp_img_file))
	{
		WriteM3U8("#EXTM3U");
		sprintf(tmp_img_file, "#EXT-X-TARGETDURATION:%d", FRAMECOUNT/30);
		WriteM3U8(tmp_img_file);
		WriteM3U8("#EXT-X-MEDIA-SEQUENCE:0");
	}

	#ifdef USE_FFMPEG_LIBRARY
	// Initialize ffmpeg library
	av_register_all();

	#endif
	/////////////////////////////
	
	// tweaked by GJ Yang
	// printf("%c[2J%c[0;0H",27,27);
	/////////////////////////////
	// Get Cgi Stream
	//for(idx=0 ; idx < RECV_IMAGE_CNT ; idx++)
	while(1)
	{
		// tweaked by GJ Yang
		// printf("Getting frame...\n");
		// printf("%c[s",27);fflush(stdout); //save the cursor location
		// printf("%c[%d;%dH",27, 31, 2);fflush(stdout);
		// printf("\033[%dmGetting frame...%2d\033[0m for",42, frameCnt);
		// printf("  \033[%dmVIDEO%d.h264\033[0m\n", 41, tempSeparateH264FileNumber);
		// printf("%c[u",27);	fflush(stdout);//restore the cursor locarion
		///////////////////////////////////
		
		nRetCode = FwRcvCgiStream(StreamSock, pImgBuff, MAX_PACK_SIZE, &ImageSize, &ScanMode, &DaemonId);
		
		/******************************** CODE ADDED BY SEYEON TECH START **********************************/
			p_jpeg_usr_t	pJesHeader;    // oject of the class that contains the header information
			unsigned short	JesHeaderSize; //
			char*			pH264Image;
			int				H264FrameSize;

			pJesHeader = (p_jpeg_usr_t)pImgBuff; // magic code

//			pJesHeader->start_of_jpg[0] : It mean JPEG or H.264
//			pJesHeader->start_of_jpg[1] : It mean Sequence Number 0,1,2,3... 

			JesHeaderSize = (unsigned short)(ntohs(pJesHeader->usr_length) + 2) + 1; // previously 2 // added 1 // IT WORKS!!!

			// tweaked by GJ Yang
			// printf("################################ Header Size: %d\n", JesHeaderSize);
			////////////////////////////////////
			
			// modify here remove the first 0x00 always
			// look at research log, june 20, 2012
			H264FrameSize = ImageSize - JesHeaderSize;
			pH264Image = pImgBuff + JesHeaderSize + 1;

		/******************************** CODE ADDED BY SEYEON TECH END ***********************************/

		if( nRetCode < 0 )
		{
			// tweaked by GJ Yang ///////////////////
			// printf("%c[%d;%dH",27, 32, 2);fflush(stdout);
			// printf("\033[%dmGetCgiStream Error=%d\033[0m\n", 41, nRetCode);
			////////////////////////////////////////
		}
		else
#ifdef DECODER_ON
		{
			sprintf(tmp_img_file, "img%d_3_%02d.raw",__LINE__, idx);
			
			if(IsJesPacketVideo((pjpeg_usr_t)pImgBuff) )
			{
				current_codec = GetVideoCodecTypeOfJesPacket((pjpeg_usr_t)pImgBuff);
				
				if(current_codec == setuped_codec) 
				{
					if(current_codec == JES_VIDEO_CODEC_JPEG)	
						Decoding(&ffm4l, (pjpeg_usr_t)pImgBuff, tmp_img_file);				
					else if(current_codec == JES_VIDEO_CODEC_H264)
					{
						if(IsJesPacketVideoH264IFrame((pjpeg_usr_t)pImgBuff) ) 
						{
							if(First_IFrame_Flag == 0)
								First_IFrame_Flag = 1;
						}
						else if(First_IFrame_Flag == 0)
							continue;
					
						Decoding(&ffm4l, (pjpeg_usr_t)pImgBuff, tmp_img_file);
					}
						
				}
				else if(current_codec != setuped_codec) 
				{
					CodecChange(&ffm4l, current_codec);
									

				}
			}
		}	
#else
		{				
			if(IsJesPacketVideo((pjpeg_usr_t)pImgBuff) ) 
			{
				if (GetVideoCodecTypeOfJesPacket((pjpeg_usr_t)pImgBuff) == JES_VIDEO_CODEC_JPEG)
					sprintf(tmp_img_file, "img%d_3_%02d.jpg",__LINE__, idx);	
				else if(GetVideoCodecTypeOfJesPacket((pjpeg_usr_t)pImgBuff) == JES_VIDEO_CODEC_H264) 
				{
					if(IsJesPacketVideoH264IFrame((pjpeg_usr_t)pImgBuff) ) 
					{
						if(First_IFrame_Flag == 0)
							First_IFrame_Flag = 1;
					}
					else if(First_IFrame_Flag == 0)
						continue;
					
					// sprintf(tmp_img_file, "img%d_3_%02d.264",__LINE__, idx);	// original function call. saves one frame into one file
					// sprintf(tmp_img_file, "VIDEO.h264"); // new function call. saves many frames into one file	
					
					// tweaked by SungboKang //
					sprintf(tmp_img_file, "VIDEO%d.h264", tempSeparateH264FileNumber); // newer function call. saves many frames into numbered files	
					///////////////////////////
				}
				// SavePacket(pImgBuff, tmp_img_file, ImageSize); // original function call. saves one frame into one file WITH HEADER DATA
				SavePacket(pH264Image, tmp_img_file, H264FrameSize); // new function call. saves a frame without the JES headers
				frameCnt++;
			}
		}
	
		// tweaked by SungboKang ///////////////////////////////////////////////////////////////////////
		// assume that a IP Camera sends 30 frames at any circumstances.
		// In here, it runs every 10 second(300 frames) to make a separate H264 file
		if(frameCnt == FRAMECOUNT)
		{
			while(QueueIsFull()); // waits till the queue is not full
			Enqueue(tempSeparateH264FileNumber); // put data into the queue

			tempSeparateH264FileNumber = (tempSeparateH264FileNumber + 1) % MAX_QUEUE_N;
			// tempSeparateH264FileNumber = tempSeparateH264FileNumber + 1;

			// If the next file numbered with 'tempSeparateH264FileNumber' exists, wipe it out
			// It is probable to have a flaw related to authority.
			// In addition, FileExist() works for files up to 2GB only
			sprintf(tmp_img_file, "VIDEO%d.h264", tempSeparateH264FileNumber);
			if(FileExist(tmp_img_file))
			{
				if(remove(tmp_img_file) < 0)
				{
					printf("%s file removing error\n", tmp_img_file);
					exit(-1);
				}
			}

			frameCnt = 0;
			
			First_IFrame_Flag = 0; // initialize Iframe checker

			// makes 30 h264 files then quit looping
			// It should be less than MAX_QUEUE_N, otherwise working infinitely
			// if(tempSeparateH264FileNumber == (MAX_QUEUE_N-1))
				// break;			
		}
		////////////////////////////////////////////////////////////////////////////////////////////////
#endif
	}
	//=============================================================================

	//=============================================================================
	// Control Cgi Stream

	memset(pImgBuff, 0, MAX_PACK_SIZE);

	//=============================================================================
	// Set Stream as Normal mode ( Header + Image )
//	nRead = TestStCtrCgiV30Wp(VSMID, AppKey, DaemonId, "Normal", "0,1,2,3", PAUSE_TIME,TARGET_IPADDR, TARGET_PORT, FW_USER_ID, FW_PASS_WD, pImgBuff, MAX_PACK_SIZE, wp_domain, wp_port);

	//=============================================================================
	// Set Stream as Header mode (Header Only)
//	nRead = FwStCtrCgiV30Wp(VSMID, AppKey, DaemonId, "Header", "0,1,2,3", PAUSE_TIME,TARGET_IPADDR, TARGET_PORT, FW_USER_ID, FW_PASS_WD, pImgBuff, MAX_PACK_SIZE, wp_domain, wp_port);

	//=============================================================================
	// Add Camera 3,4 --> PortId (2,3)
//	nRead = TestStCtrCgiV30Wp(VSMID, AppKey, DaemonId, "Add", "2,3", PAUSE_TIME,TARGET_IPADDR, TARGET_PORT, FW_USER_ID, FW_PASS_WD, pImgBuff, MAX_PACK_SIZE, wp_domain, wp_port);

	//=============================================================================
	// Remove Camera 2 --> PortId (1)
//	nRead = TestStCtrCgiV30Wp(VSMID, AppKey, DaemonId, "Remove", "1", PAUSE_TIME,TARGET_IPADDR, TARGET_PORT, FW_USER_ID, FW_PASS_WD, pImgBuff, MAX_PACK_SIZE, wp_domain, wp_port);

	//=============================================================================
	// Set pause time 1000 msec
//	nRead = TestStCtrCgiV30Wp(VSMID, AppKey, DaemonId, "Set", NULL, 100,TARGET_IPADDR, TARGET_PORT, FW_USER_ID, FW_PASS_WD, pImgBuff, MAX_PACK_SIZE, wp_domain, wp_port);

	//=============================================================================
	// Get Cgi Stream
#if 0
	for(idx=0 ; idx < RECV_IMAGE_CNT ; idx++)
	{

		sprintf(tmp_img_file, "img%d_3_%02d.jpg",__LINE__, idx);
#ifdef WIN32
		tmp_img_filep=fopen(tmp_img_file, "wb");
#else
		tmp_img_filep=fopen(tmp_img_file, "wb");
#endif
		nRetCode = FwRcvCgiStream(StreamSock, pImgBuff, MAX_PACK_SIZE, &ImageSize, &ScanMode, &DaemonId);
		if( nRetCode < 0 )
		{
			printf("GetCgiStream Error=%d\n", nRetCode);
		}
		else
		{
//			printf("-------- Jpeg Header --------\n");
//			PrintJpegHeader(pImgBuff);
			printf("DaemondId  : 0x%08lx\n", DaemonId);
			printf("FwModId(0~): 0x%04x\n", GET_FW_STREAM_MOD_ID( nRetCode ));
			printf("PortId(0~3): 0x%04x\n", GET_FW_STREAM_PORT_ID( nRetCode ));
			fwrite(pImgBuff, sizeof(char), ImageSize, tmp_img_filep);
		}
		fclose(tmp_img_filep);
	}
	//=============================================================================
#endif

	//=============================================================================
	// Close Cgi Stream
	FwCloseCgiWp(StreamSock);
	//=============================================================================

//	nRead = TestCamGetCgiV30Wp(VSMID, TARGET_IPADDR, TARGET_PORT, 0, FW_USER_ID, FW_PASS_WD, pImgBuff, MAX_PACK_SIZE, wp_domain, wp_port);
//	if(nRead > 0)
//		printf("FwSysGetCgiWp=[%s]\n",pImgBuff);

	// tweaked by SungboKang //////////////////////////////////////////////////
	setControlThreadEndFlag(TRUE);
	pthread_join(controlThread, NULL); // wait for the control thread

	// WriteM3U8("#EXT-X-ENDLIST");
	///////////////////////////////////////////////////////////////////////////

	SOCK_CLEANUP();
	free(pImgBuff);
	
	return 0;
}