예제 #1
0
파일: server.c 프로젝트: roguehit/aos2
void* server_thread (void* t)
{
/* shared memory segment id           */
int MyKey;
int reqMemSegID;             
int resMemSegID;
/* shared memory flags                */
int shmFlags;               
    
/*pointer to the queue			*/
struct queue *request_ring;
struct queue *response_ring;


/*Keys to request & response structures*/
int REQ_KEY,RES_KEY;     

/*Get the Thread ID */
int tid =  (int)(int*)t;
MyKey   =  (int)message_box->client[tid];  
printf("Servicing Client with Process ID %d, Thread ID %d\n",(int)MyKey,tid);

/*Get the keys for both rings*/
REQ_KEY = ftok(".", (int) MyKey * 0xAA );    
RES_KEY = ftok(".", (int) MyKey * 0x33 );

/*Should not happen*/
assert(REQ_KEY != RES_KEY);

#if 1
/*---------------------------------------*/
/* Create shared memory segment          */
/* Give everyone read/write permissions. */
/*---------------------------------------*/

shmFlags = IPC_CREAT | SHM_PERM;
/*Request ring creation*/
 if ( (reqMemSegID = 
  shmget(REQ_KEY, SHM_SIZE, shmFlags)) < 0 )
   {
       perror("SERVER: shmget");
       exit(EXIT_FAILURE);
   }
printf("Created shared location for request ring buffer\n");
/*Response ring creation*/
if ( (resMemSegID = 
  shmget(RES_KEY, SHM_SIZE, shmFlags)) < 0 )
   {
       perror("SERVER: shmget");
       exit(EXIT_FAILURE);
   }
printf("Created shared location for response ring buffer\n");

/*-------------------------------------------*/
/* Attach the segment to the process's data  */
/* space at an address                       */
/* selected by the system.                   */
/*-------------------------------------------*/
/*Changed by Pradeep*/
shmFlags = 0;
/*Get Request Ring*/
if ( (request_ring = 
      shmat(reqMemSegID, NULL, shmFlags)) == 
  (void *) -1 )
   {
       perror("SERVER: shmat");
       exit(EXIT_FAILURE);
   }
printf("Request Ring buffer attached to process\n");
/*Get Response Ring*/
if ( (response_ring = 
      shmat(resMemSegID, NULL, shmFlags)) == 
  (void *) -1 )
   {
       perror("SERVER: shmat");
       exit(EXIT_FAILURE);
   }
printf("Response Ring buffer attached to process\n");


while(1){
	if(is_empty(request_ring))
	{
		//pthread_cond_wait(&cond_thread, &mutex_thread);
		sleep(1);
	}
	else if(!is_empty(request_ring))
	{	
		printf("Got a request, Dequeuing it \n");	
		Task temp = dequeue(request_ring);
		compute_mod(&temp);
		printf("Computed Mod\n");
		
	        enqueue(response_ring,temp);
	}
}
/*------------------------------------------------*/
/* Call shmdt() to detach shared memory segment.  */
/*------------------------------------------------*/
   if ( shmdt(request_ring) < 0 )
   {
       perror("SERVER: shmdt");
       exit(EXIT_FAILURE);
   }

  if ( shmdt(response_ring) < 0 )
   {
       perror("SERVER: shmdt");
       exit(EXIT_FAILURE);
   }

    

/*--------------------------------------------------*/
/* Call shmctl to remove shared memory segment.     */
/*--------------------------------------------------*/
   if (shmctl(reqMemSegID, IPC_RMID, NULL) < 0)
   {
       perror("SERVER: shmctl");
       exit(EXIT_FAILURE);
   }

  if (shmctl(resMemSegID, IPC_RMID, NULL) < 0)
   {
       perror("SERVER: shmctl");
       exit(EXIT_FAILURE);
   }
 

   exit(EXIT_SUCCESS);
#endif
}  /* end of main() */
void CLS_DlgStreamPusher::audio_display(struct_stream_info *_pstrct_streaminfo)
{
	if (audio_callback_time == 0){
		TRACE("audio_callback_time == 0");
		return;
	}
	int i, i_start, x, y1, y, ys, delay, n, nb_display_channels;
	int ch, channels, h, h2, bgcolor, fgcolor;
	int16_t time_diff;
	int rdft_bits, nb_freq;

	for (rdft_bits = 1; (1 << rdft_bits) < 2 * _pstrct_streaminfo->m_height; rdft_bits++)
		;
	nb_freq = 1 << (rdft_bits - 1);

	/* compute display index : center on currently output samples */
	channels = _pstrct_streaminfo->m_audio_tgt.channels;
	nb_display_channels = channels;
	if (!_pstrct_streaminfo->m_paused) {
		int data_used = _pstrct_streaminfo->m_show_mode == SHOW_MODE_WAVES ? _pstrct_streaminfo->m_width : (2 * nb_freq);
		n = 2 * channels;
		delay = _pstrct_streaminfo->m_audio_write_buf_size;
		delay /= n;

		/* to be more precise, we take into account the time spent since
		the last buffer computation */
		if (audio_callback_time) {
			time_diff = av_gettime() - audio_callback_time;
			delay -= (time_diff * _pstrct_streaminfo->m_audio_tgt.freq) / 1000000;
		}

		delay += 2 * data_used;
		if (delay < data_used)
			delay = data_used;

		i_start = x = compute_mod(_pstrct_streaminfo->m_sample_array_index - delay * channels, SAMPLE_ARRAY_SIZE);
		if (_pstrct_streaminfo->m_show_mode == SHOW_MODE_WAVES) {
			h = INT_MIN;
			for (i = 0; i < 1000; i += channels) {
				int idx = (SAMPLE_ARRAY_SIZE + x - i) % SAMPLE_ARRAY_SIZE;
				int a = _pstrct_streaminfo->m_sample_array[idx];
				int b = _pstrct_streaminfo->m_sample_array[(idx + 4 * channels) % SAMPLE_ARRAY_SIZE];
				int c = _pstrct_streaminfo->m_sample_array[(idx + 5 * channels) % SAMPLE_ARRAY_SIZE];
				int d = _pstrct_streaminfo->m_sample_array[(idx + 9 * channels) % SAMPLE_ARRAY_SIZE];
				int score = a - d;
				if (h < score && (b ^ c) < 0) {
					h = score;
					i_start = idx;
				}
			}
		}

		_pstrct_streaminfo->m_audio_last_i_start = i_start;
	}


	//背景色
	bgcolor = SDL_MapRGB(_pstrct_streaminfo->m_screen_surface->format, 0x00, 0x00, 0x00);
	if (_pstrct_streaminfo->m_show_mode == SHOW_MODE_WAVES) {
		SDL_Rect sdl_rect;
		_pstrct_streaminfo->m_xleft = 0;
		_pstrct_streaminfo->m_ytop = 0;
		sdl_rect.x = _pstrct_streaminfo->m_xleft;
		sdl_rect.y = _pstrct_streaminfo->m_ytop;
		sdl_rect.w = _pstrct_streaminfo->m_width;
		sdl_rect.h = _pstrct_streaminfo->m_height;

		fill_rec(_pstrct_streaminfo->m_screen_surface, _pstrct_streaminfo->m_xleft, _pstrct_streaminfo->m_ytop, _pstrct_streaminfo->m_width, _pstrct_streaminfo->m_height,bgcolor);

		fgcolor = SDL_MapRGB(_pstrct_streaminfo->m_screen_surface->format, 0xff, 0xff, 0xff);

		/* total height for one channel */
		h = _pstrct_streaminfo->m_height / nb_display_channels;
		/* graph height / 2 */
		h2 = (h * 9) / 20;
		for (ch = 0; ch < nb_display_channels; ch++) {
			i = i_start + ch;
			y1 = _pstrct_streaminfo->m_ytop + ch * h + (h / 2); /* position of center line */
			for (x = 0; x < _pstrct_streaminfo->m_width; x++) {
				y = (_pstrct_streaminfo->m_sample_array[i] * h2) >> 15;
				if (y < 0) {
					y = -y;
					ys = y1 - y;
				}
				else {
					ys = y1;
				}

				fill_rec(_pstrct_streaminfo->m_screen_surface, _pstrct_streaminfo->m_xleft + x, ys, 1, y, fgcolor);

				i += channels;
				if (i >= SAMPLE_ARRAY_SIZE)
					i -= SAMPLE_ARRAY_SIZE;
			}
		}

		fgcolor = SDL_MapRGB(_pstrct_streaminfo->m_screen_surface->format, 0x00, 0x00, 0xff);

		for (ch = 1; ch < nb_display_channels; ch++) {
			y = _pstrct_streaminfo->m_ytop + ch * h;

			fill_rec(_pstrct_streaminfo->m_screen_surface, _pstrct_streaminfo->m_xleft, y, _pstrct_streaminfo->m_width, 1, fgcolor);
		}
		if (SDL_UpdateWindowSurface(_pstrct_streaminfo->m_show_screen) != 0){
			TRACE("SDL_UpdateWindowSurface ERR");
		}
		//SDL_CreateRGBSurface();
		SDL_UpdateTexture(_pstrct_streaminfo->m_sdlTexture, NULL, _pstrct_streaminfo->m_screen_surface->pixels, _pstrct_streaminfo->m_screen_surface->pitch);
		SDL_RenderClear(_pstrct_streaminfo->m_sdlRenderer);
		SDL_RenderCopy(_pstrct_streaminfo->m_sdlRenderer, _pstrct_streaminfo->m_sdlTexture, &sdl_rect, &sdl_rect);
		SDL_RenderPresent(_pstrct_streaminfo->m_sdlRenderer);
	}
예제 #3
0
파일: server.c 프로젝트: roguehit/aos3
static xmlrpc_value *
calculate_modexp(xmlrpc_env *   const env,
           xmlrpc_value * const param_array,
           void *         const serverInfo,
           void *         const channelInfo) {

   int i = 0;
   Task temp;
   xmlrpc_value * retval;

   xmlrpc_value * arrayP;	
	
   xmlrpc_decompose_value(env, param_array, "(A)", &arrayP);

   size_t size = xmlrpc_array_size(env, arrayP);

	if (env->fault_occurred)
		retval = NULL;
	else 
	{

		for (i = 0; i < size && !env->fault_occurred; ++i) 
		{
			xmlrpc_value * strctP;
			strctP = xmlrpc_array_get_item(env, arrayP, i);
			if (!env->fault_occurred) 
			{
				if(i == 0)
				{
					const char * str1;
					size_t str1_len;
					xmlrpc_read_string_lp(env, strctP, &str1_len, &str1);				
	
					//xmlrpc_int32 curly;
					//xmlrpc_decompose_value(env, strctP, "(s)",&ip[0]);
					strcpy(temp._clientid, str1);
				}
				else
				{
					const char * str1;
					size_t str1_len;
					xmlrpc_read_string_lp(env, strctP, &str1_len, &str1);				
				
					if(i == 1)
					strcpy(temp.p,str1);
				
					else if(i == 2)
					strcpy(temp.m,str1);

				}
			}
		}
	}

    xmlrpc_DECREF(arrayP);

    if (env->fault_occurred)
        return NULL;

    printf("Received: %s %s %s\n",temp._clientid,temp.p,temp.m);

    /* Add our two numbers. */
   // z = x + y;

    /* Sometimes, make it look hard (so client can see what it's like
       to do an RPC that takes a while).
    */
    compute_mod(&temp);
  
    xmlrpc_value *arr = xmlrpc_array_new(env);
    xmlrpc_value *v1 = xmlrpc_build_value(env, "s", temp.response);
    xmlrpc_array_append_item (env,arr,v1);

    /* Return our result. */
    return xmlrpc_build_value(env,"(A)", arr);
}