Ejemplo n.º 1
0
AVSTerminate::~AVSTerminate()
{
  WINE_LOADER *cur_loader = first_loader;
  int i = 0;
  DEBUG_PRINTF("Call terminate!!!\n");

  if (cur_loader)
    do {
      DEBUG_PRINTF("Count %d\n", i++);

      if (cur_loader->avs_pipes[PIPE_LOADER_WRITE].hpipe != -1)
      {
        send_cmd(cur_loader->avs_pipes[PIPE_LOADER_WRITE].hpipe,
                 UNLOAD_AVS_SCRIPT, NULL, 0);
        DEBUG_PRINTF("UNLOAD_AVS_SCRIPT try\n");
      }

      if (cur_loader->avs_pipes[PIPE_LOADER_WRITE].hpipe != -1)
      {
        send_cmd(cur_loader->avs_pipes[PIPE_LOADER_WRITE].hpipe,
                 UNLOAD_AVS_LOADER, NULL, 0);
        DEBUG_PRINTF("UNLOAD_AVS_LOADER try\n");
      }

      deinit_pipes(cur_loader->avs_pipes, CMD_PIPE_NUM);
    } while((cur_loader = (WINE_LOADER*)cur_loader->next_wine_loader) != NULL);
}
Ejemplo n.º 2
0
bool open_pipes(AVS_PIPES *avsp, int num)
{
  int i;
  for (i = 0; i < num; i++)
  {
    DEBUG_PRINTF("avsfilter : try to open %s fifo\n", avsp[i].pipename);
    if ((avsp[i].hpipe = open(avsp[i].pipename, avsp[i].flags)) == -1)
    {
      DEBUG_PRINTF_RED("avsfilter : failed open errno %d\n", errno);
      deinit_pipe(&avsp[i]);
      deinit_pipes(avsp, i);
      return false;
    }
  }

  DEBUG_PRINTF("all pipes open ok\n");

  return true;
}
Ejemplo n.º 3
0
bool init_pipes (AVS_PIPES *avsp, int num, FILE *pfile)
{
  int i;
  for (i = 0; i < num; i++)
  {
    char sname[MAX_PATH];

    if (fscanf(pfile, "%s\n", sname) != 1) DEBUG_PRINTF_RED("fscanf error\n");
    else if (!(avsp[i].pipename = strnew(sname))) DEBUG_PRINTF_RED("strnew error\n");
    else if (remove(avsp[i].pipename)) DEBUG_PRINTF_RED("error remove file\n");
    else if (mkfifo(avsp[i].pipename, 0600))
     DEBUG_PRINTF_RED("mkfifo error create fifo file %s, errno %d\n",
	         avsp[i].pipename, errno);
    else continue;

    deinit_pipes(avsp, i);
    return false;
  }

  return true;
}
// Main function with event loop
int main(void)
{
	int n = -1;
	int count = 0;
	static bc_buf_ptr_t buf_pa;
	int dev_fd;
	unsigned long chunkSize;

	printf("Initializing egl..\n\n");
	if( 0 == initEGL(0)) //No profiling
	{	
		printf("EGL init failed");
		goto exitNone;
	}
	
	//Also initialise the pipes
	n = initPipes(&initAttrib);
	if(n) 	{ 		goto exitPipes; 	}

	//Initialise CMEM allocator - TODO check err status
	mem_cmem_init();
	//Allocate mem
	chunkSize = initAttrib.widthPixels* 
							initAttrib.heightPixels* 
							initAttrib.bytesPerPixel*  
							initAttrib.numBuffers;
	if(mem_cmem_alloc( chunkSize, &virtualAddress, &physicalAddress )) {goto exitCMEMInit;}

	paArray = (unsigned long*)malloc(initAttrib.numBuffers * sizeof(unsigned long));
	freeArray = (unsigned long*)malloc(initAttrib.numBuffers * sizeof(unsigned long));	
	if(!paArray || !freeArray) {goto exitCMEMAlloc;}

	for(count = 0; count < initAttrib.numBuffers; count++)
	{
		paArray[count]  = physicalAddress + count*(chunkSize/initAttrib.numBuffers);
		freeArray[count] = 0;
	}
	//TODO - give the allocated buffers back to requestor via answer
	//write_init_buffer_pipe();
	
	init_view();

	//Loop reading new data and rendering, till something happens
	//TODO - exit cleanly using last msg
	while(read_pipe() != -1)
	{
		render(bcbuf.index);
		
		//TODO - clean up message passing
		//if( write_pipe() != sizeof(GstBufferClassBuffer *))
		{	
			printf("Error Writing into Init Queue\n");
			//TODO - try again n times ?
			break;
		}
	}
exit:
	release_view();
	deInitEGL();
exitCMEMAlloc:
	mem_cmem_free( virtualAddress);
exitPipes:	
	if(paArray) free(paArray);
	if(freeArray) free(freeArray);
	deinit_pipes();
exitCMEMInit:
	mem_cmem_deinit();
exitNone:
	return 0;
}
Ejemplo n.º 5
0
bool avs_start(FilterInfo *info, FilterInfo *avisynth_info,
               char *fname, AVS_PIPES *avs_pipes)
{
 DEBUG_PRINTF("avsfilter : avs_start()\n");
 DEBUG_PRINTF("avsfilter : %X %X %s %X\n",
              avs_pipes[PIPE_LOADER_WRITE].hpipe,
              avs_pipes[PIPE_FILTER_WRITE].hpipe,
              fname, info);
 DEBUG_PRINTF("avsfilter : avs_start info : frameIncrement %lu totalDuration %llu\n",
              info->frameIncrement, info->totalDuration);

 ADV_Info aii, aio;
 aii.width = info->width;
 aii.height = info->height;
 aii.nb_frames = info->totalDuration / info->frameIncrement;
 aii.encoding = 1;
 aii.codec = 0;
 aii.fps1000 = ADM_Fps1000FromUs(info->frameIncrement);
 aii.orgFrame = 0;
 DEBUG_PRINTF("avsfilter : send ADV_Info to avsloader [fps1000 = %d, nb_frames = %d]\n", aii.fps1000, aii.nb_frames);
 if (!send_cmd(avs_pipes[PIPE_LOADER_WRITE].hpipe,
                LOAD_AVS_SCRIPT, fname,
                strlen(fname) + sizeof("\0")) ||
      !send_cmd(avs_pipes[PIPE_FILTER_WRITE].hpipe,
                SET_CLIP_PARAMETER, &aii,
                sizeof(aii)))
  {
    DEBUG_PRINTF_RED("avsfilter : cannot set script name or set clip parameters\n");
    deinit_pipes(avs_pipes, CMD_PIPE_NUM);
    return false;
  }

  // get avisynth frame info
  PIPE_MSG_HEADER msg;
  if (!receive_cmd(avs_pipes[PIPE_LOADER_READ].hpipe,
                   &msg) ||
      msg.avs_cmd != SET_CLIP_PARAMETER ||
      !receive_data(avs_pipes[PIPE_LOADER_READ].hpipe,
                    &msg, &aio))
  {
    DEBUG_PRINTF_RED("avsfilter : cannot receive avisynth clip parameters\n");
    deinit_pipes(avs_pipes, CMD_PIPE_NUM);
    return false;
  }

  DEBUG_PRINTF("avsfilter : receive ADV_Info from avsloader [fps1000 = %d, nb_frames = %d]\n", aio.fps1000, aio.nb_frames);
  avisynth_info->width = aio.width;
  avisynth_info->height = aio.height;
  avisynth_info->frameIncrement = ADM_UsecFromFps1000(aio.fps1000);
  avisynth_info->totalDuration = aio.nb_frames * avisynth_info->frameIncrement;

  // correct avisynth_info for span of frames, calculate fps change metrics
/*  float k_fps;
  k_fps = float(avisynth_info->frameIncrement) / float(info->frameIncrement);
  DEBUG_PRINTF("avsfilter : FPS change metrics %f\n", k_fps);
  avisynth_info->nb_frames = int (info->nb_frames * k_fps);
  avisynth_info->orgFrame = int (info->orgFrame * k_fps);
  DEBUG_PRINTF("avsfilter : Calculate new span for avisynth script [%d - %d]\n",
               avisynth_info->orgFrame,avisynth_info->orgFrame + avisynth_info->nb_frames);*/
  return true;
}
Ejemplo n.º 6
0
bool wine_start(char *wine_app, char *avsloader, AVS_PIPES *avs_pipes, int pipe_timeout)
{
  char sname[MAX_PATH];
  struct stat st;
  sprintf(sname, "%s %s %d", wine_app, avsloader, pipe_timeout);

  FILE *pfile = popen(sname, "r");
  if (!pfile)
  {
   DEBUG_PRINTF_RED("avsfilter : popen failed, errno %d, failed start app is : [%s]\n", errno, sname);
   return false;
  }

  if (fscanf(pfile, "%s\n", sname) != 1 ||
      stat(sname, &st) ||
      !S_ISDIR(st.st_mode))
  {
    DEBUG_PRINTF_RED("avsfilter : tmpdirname [%s] failed, errno %d[stat %d isdir %d]\n", sname, errno, stat(sname, &st), S_ISDIR(st.st_mode));
    pclose(pfile);
    return false;
  }

  DEBUG_PRINTF("avsfilter : good tmpdirname %s\n", sname);

  if (!init_pipes(avs_pipes, CMD_PIPE_NUM, pfile))
  {
    DEBUG_PRINTF_RED("init_pipes failed\n");
    pclose(pfile);
    return false;
  }

  time_t t = time(NULL);
  DEBUG_PRINTF("avsfilter : precreate thread time %s\n",
         ctime(&t));
  pthread_t thread;
  TPARSER tp = { avs_pipes, pfile };

  open_pipes_ok = false;

  if (pthread_create(&thread, NULL, parse_wine_stdout, &tp))
  {
    DEBUG_PRINTF_RED("Cannot pthread started...Errno %d\n",errno);
    deinit_pipes(avs_pipes, CMD_PIPE_NUM);
    return false;
  }

  t = time(NULL);
  DEBUG_PRINTF("avsfilter : preopen time %s\n",
         ctime(&t));

  if (!open_pipes(avs_pipes, CMD_PIPE_NUM) || wine_loader_down)
  {
    open_pipes_ok = true;
    DEBUG_PRINTF_RED("open_pipes failed\n");
    deinit_pipes(avs_pipes, CMD_PIPE_NUM);
    return false;
  }

  open_pipes_ok = true;

  if (pipe_test_filter (avs_pipes[PIPE_LOADER_READ].hpipe,
                        avs_pipes[PIPE_FILTER_WRITE].hpipe))
  {
    DEBUG_PRINTF("avsfilter : test pipe to filter ok\n");

    if (pipe_test_filter (avs_pipes[PIPE_LOADER_READ].hpipe,
                          avs_pipes[PIPE_LOADER_WRITE].hpipe))
    {
      DEBUG_PRINTF("avsfilter : test pipe to loader ok\n");
    }
    else
      goto error_pipe_test;
  }
  else
  {
    error_pipe_test:
    DEBUG_PRINTF_RED("Error test read/write pipes\n");
    deinit_pipes(avs_pipes, CMD_PIPE_NUM);
    return false;
  }

  DEBUG_PRINTF("wine start is ok\n");
  return true;
}