[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

help for a beginner



I have asked this question to the mailist byt i don't know if i don't
explain well or simply people don't answer (or maybe don't arrive the
question to them).
The situation is the following:
I have to port a linux program to a real time. The part we are
interested in fo the linux program consists of an graphic interface and
a function that capts images from one camera. For capture video, simply
i make a while loop of this function capture. Like this:
do{ 
  AcquerirImageGdk(&capt_d, &tempbuf, VID_STREAMING);
  while (gdk-events_pending()) gtk_main_interaction_do(1);
}while (!finAcquisitionSequence && finLecutreSequence);

What i want to do is the following. I am thinking in make an periodic
rttask with this function AcquerirImageGdk(...) because like this way i
will control the frequency of image acquisition.
The important part of the function is at the end of the mail(
principally the function capture, the rest is to save the images...) and
it's the one i want to port to rtlinux.
It's no necessary to understand all this.
What i really want to know is the following:
-If i try to make this. From the rt task, is possible  to use all this
kind of structures and functions of the videocard driver,etc...? and how
i have to do to access all this libraries and functions.
-I think that if it's possible to make this task like a rt periodic
task, it will be a module. How i will start the execution of the task
from the linux task?
-How i will take the three paraleters that i need for the function,
considering that two of these are pointers to structures?
Principally these are the questions but i will be agreed to ALL help and
ideas if you think that i am not in the correct way.

If it's not clear my questions please tell me and i will rewrite
better...

Thank you

int AcquerirImageGdk(capture_device * pcapt_d,struct v4l2_buffer 
*pbuf,int streaming)
{
  int l,nbPlanes;
  static char init=1;
  static clock_t tempsFin=0;
  int tempsAttente;
  static Display *display;
  static XImage *ximg[STREAMBUFS];
  char  *ptrChar;
  int  *ptrInt;
  static char tabChar[FORMAT_X*FORMAT_Y*2];
  static unsigned char tabunsignedChar[FORMAT_X*FORMAT_Y/2];
  int ELL_QUADR;
  //int bidule;

  struct timeval time_out1,time_out0;
  struct timeval time_track1,time_track0;
  struct timeval time_controlPTZ1,time_controlPTZ0;
  struct timeval time_getPTZ1,time_getPTZ0;
  struct timezone tz;


  gettimeofday(&time_out0,&tz);


  if (init) {
    init_eviG21(&evi,&parametres_commande);
    fprintf(stderr,"taille_axe = %d \n",parametres_commande.taille_axe);

    display = GDK_GC_XDISPLAY(AireImage->Gc());
    nbPlanes = DisplayPlanes(display,0);
    printf("nb plans : %d\n",nbPlanes);
    init=false;
  }


  int tx =  pcapt_d->width;
  int ty =  pcapt_d->height;


  if (capture_dq (pcapt_d, pbuf, streaming))
    {
      fprintf(stderr,"numero buffer %d \n",pbuf->index);
      ptrInt = (int*)pcapt_d->vimage[pbuf->index].data;
      ptImage = tabunsignedChar;//(unsigned char 
*)malloc(FORMAT_X*240*sizeof(char));
      ptrChar = tabChar;
      for (l=0;l<ty;l+=2) {
        for (int c=0;c<tx;c++) {
          *(ptrChar++) = *(ptrInt++) ;// il lit une trame sur l'image
precedente
          *(ptrChar+tx) = *(ptrInt) ;
          *(ptImage++) = *(ptrInt) ;
        }
        ptrChar += tx;
      }

      ptImage = tabunsignedChar;  // on met le pointeur au debut !!!
    if (enable_track)
        {
          gettimeofday(&time_getPTZ0,&tz);
          evi.zoom = DonnePositionZoom();
          evi.focus = DonnePositionFocus();
          gettimeofday(&time_getPTZ1,&tz);
        }
    }

  AireImage->AfficheImage((unsigned char*)tabChar, 0,0,tx,ty);



  
//gdk_draw_gray_image(AireImage->w()->window,AireImage->Gc(),0,0,tx,ty,GDK_RGB_DITHER_NORMAL,(unsigned 
char*)ptrInt,tx);

  gettimeofday(&time_out1,&tz);
  fprintf(stderr,"Temps boucle = %.1f ms. (tracking = %.2f ms.
PTZcontrol = 
%.2f ms. PTZget = %.2f ms.)\n",
          
(1000000*(time_out1.tv_sec-time_out0.tv_sec)+time_out1.tv_usec-time_out0.tv_usec)/1000.,
          
(1000000*(time_track1.tv_sec-time_track0.tv_sec)+time_track1.tv_usec-time_track0.tv_usec)/1000.,
          
(1000000*(time_controlPTZ1.tv_sec-time_controlPTZ0.tv_sec)+time_controlPTZ1.tv_usec-time_controlPTZ0.tv_usec)/1000.,
          
(1000000*(time_getPTZ1.tv_sec-time_getPTZ0.tv_sec)+time_getPTZ1.tv_usec-time_getPTZ0.tv_usec)/1000.
          );
  parametres_commande.temps_boucle = 
(1000000*(time_out1.tv_sec-time_out0.tv_sec)+time_out1.tv_usec-time_out0.tv_usec)/1000.;


  return 0;
}