Exemplo n.º 1
0
static int
init_v4l (struct vdIn *vd)
{
  int f;
  int erreur = 0;
  int err;
  if ((vd->fd = open (vd->videodevice, O_RDWR)) == -1)
  {
    //exit_fatal ("ERROR opening V4L interface");
    printf("ERROR opening V4L interface\n");
    return -1;
  }

  if (ioctl (vd->fd, VIDIOCGCAP, &(vd->videocap)) == -1)
  {
    //exit_fatal ("Couldn't get videodevice capability");
     printf("Couldn't get videodevice capability");
    return -1;
  }

  printf ("Camera found: %s \n", vd->videocap.name);
  snprintf (vd->cameraname, 32, "%s", vd->videocap.name);

  erreur = GetVideoPict (vd);
   if (ioctl (vd->fd, VIDIOCGCHAN, &vd->videochan) == -1)
    {
      printf ("Hmm did not support Video_channel\n");
      vd->cameratype = UNOW;
    }
  else
    {
    if (vd->videochan.name){
      printf ("Bridge found: %s \n", vd->videochan.name);
      snprintf (vd->bridge, 9, "%s", vd->videochan.name);
      vd->cameratype = GetStreamId (vd->videochan.name);
      spcaPrintParam (vd->fd,&vd->videoparam);
      }
      else
      {
       printf ("Bridge not found not a spca5xx Webcam Probing the hardware !!\n");
      vd->cameratype = UNOW;
      }
    }
   printf ("StreamId: %d  Camera\n", vd->cameratype);
/* probe all available palette and size */
   if (probePalette(vd ) < 0) {
	  //exit_fatal ("could't probe video palette Abort !");
	  printf ("could't probe video palette Abort !\n");
	  return -1;
	  }
   if (probeSize(vd ) < 0) {
	  //exit_fatal ("could't probe video size Abort !");
	  printf ("could't probe video size Abort !\n");
	  return -1;
	  
	  }

/* now check if the needed setting match the available
	if not find a new set and populate the change */
	 err = check_palettesize(vd);
	 printf (" Format asked %d check %d\n",vd->formatIn, err);	
  vd->videopict.palette = vd->formatIn;
  vd->videopict.depth = GetDepth (vd->formatIn);
  vd->bppIn = GetDepth (vd->formatIn);
  
   vd->framesizeIn = (vd->hdrwidth * vd->hdrheight * vd->bppIn) >> 3;
   
  erreur = SetVideoPict (vd);
  erreur = GetVideoPict (vd);
  if (vd->formatIn != vd->videopict.palette ||
      vd->bppIn != vd->videopict.depth) {
    //exit_fatal ("could't set video palette Abort !");
    printf ("could't set video palette Abort !\n");
	  return -1;
    
    }
  if (erreur < 0){
  
    printf ("could't set video palette Abort !\n");
	  return -1;
	  }

  if (vd->grabMethod)
    {
      printf (" grabbing method default MMAP asked \n");
      // MMAP VIDEO acquisition
      memset (&(vd->videombuf), 0, sizeof (vd->videombuf));
      if (ioctl (vd->fd, VIDIOCGMBUF, &(vd->videombuf)) < 0)
	{
	  perror (" init VIDIOCGMBUF FAILED\n");
	}
      printf ("VIDIOCGMBUF size %d  frames %d  offets[0]=%d offsets[1]=%d\n",
	      vd->videombuf.size, vd->videombuf.frames,
	      vd->videombuf.offsets[0], vd->videombuf.offsets[1]);
      vd->pFramebuffer =
	(unsigned char *) mmap (0, vd->videombuf.size, PROT_READ | PROT_WRITE,
				MAP_SHARED, vd->fd, 0);
      vd->mmapsize = vd->videombuf.size;
      vd->vmmap.height = vd->hdrheight;
      vd->vmmap.width = vd->hdrwidth;
      vd->vmmap.format = vd->formatIn;
      for (f = 0; f < vd->videombuf.frames; f++)
	{
	  vd->vmmap.frame = f;
	  if (ioctl (vd->fd, VIDIOCMCAPTURE, &(vd->vmmap)))
	    {
	      perror ("cmcapture");
	    }
	}
      vd->vmmap.frame = 0;
    }
  else
    {
      /* read method */
      /* allocate the read buffer */
      vd->pFramebuffer =
	(unsigned char *) realloc (vd->pFramebuffer, (size_t) vd->framesizeIn);
      printf (" grabbing method READ asked \n");
      if (ioctl (vd->fd, VIDIOCGWIN, &(vd->videowin)) < 0)
	perror ("VIDIOCGWIN failed \n");
      vd->videowin.height = vd->hdrheight;
      vd->videowin.width = vd->hdrwidth;
      if (ioctl (vd->fd, VIDIOCSWIN, &(vd->videowin)) < 0)
	perror ("VIDIOCSWIN failed \n");
      printf ("VIDIOCSWIN height %d  width %d \n",
	      vd->videowin.height, vd->videowin.width);
    }
  vd->frame_cour = 0;
  return erreur;
}
Exemplo n.º 2
0
/***************************************
 * Play
 *	RTMP event listener
 **************************************/
void MultiConf::NetStream::doPlay(std::wstring& url,RTMPMediaStream::Listener* listener)
{
	RTMPMediaStream *stream = NULL;

	//Log
	Log("-Play stream [%d,%ls]\n",GetStreamId(),url.c_str());

	//Check  if already in use
	if (opened)
	{
		//Send error
		fireOnNetStreamStatus(RTMP::Netstream::Failed,L"Stream already in use");
		//Noting found
		Error("Stream #%d already in use\n", GetStreamId());
		//Exit
		return;
	}

	//Skip the type part "flv:" inserted by FMS
	size_t i = url.find(L":",0);

	//If not found
	if (i==std::wstring::npos)
		//from the begining
		i = 0;
	else
		//Skip
		i++;

	//Get the next "/"
	size_t j = url.find(L"/",i);

	//Check if found
	if (j==std::wstring::npos)
	{
		//Send error
		fireOnNetStreamStatus(RTMP::Netstream::Play::Failed,L"Wrong format stream name");
		//Noting found
		Error("Wrong format stream name\n");
		//Exit
		return;
	}
	//Get type
	std::wstring type = url.substr(i,j-i);

	//Get token
	std::wstring token = url.substr(j+1,url.length()-j);

	//Check app name
	if (type.compare(L"participant")==0)
	{
		//Get participant stream
		stream = conf->ConsumeParticipantOutputToken(token);
		//Wait for intra
		SetWaitIntra(true);
		//And rewrite
		SetRewriteTimestamps(true);
	} else if (type.compare(L"watcher")==0) {
		//Get broadcast stream
		stream = conf->ConsumeBroadcastToken(token);
		//Wait for intra
		SetWaitIntra(true);
		//And rewrite
		SetRewriteTimestamps(true);
	} else {
		//Log
		Error("-Application type name incorrect [%ls]\n",type.c_str());
		//Send error
		fireOnNetStreamStatus(RTMP::Netstream::Play::Failed,L"Type invalid");
		//Nothing done
		return;
	}

	//Check if found
	if (!stream)
	{
		//Send error
		fireOnNetStreamStatus(RTMP::Netstream::Play::StreamNotFound,L"Token invalid");
		//Exit
		return;
	}

	//Opened
	opened = true;

	//Send reseted status
	fireOnNetStreamStatus(RTMP::Netstream::Play::Reset,L"Playback reset");
	//Send play status
	fireOnNetStreamStatus(RTMP::Netstream::Play::Start,L"Playback started");

	//Add listener
	AddMediaListener(listener);
	//Attach
	Attach(stream);
}
Exemplo n.º 3
0
/***************************************
 * Publish
 *	RTMP event listener
 **************************************/
void MultiConf::NetStream::doPublish(std::wstring& url)
{
	//Log
	Log("-Publish stream [%ls]\n",url.c_str());

	//Check  if already in use
	if (opened)
	{
		//Send error
		fireOnNetStreamStatus(RTMP::Netstream::Failed,L"Stream already in use");
		//Noting found
		Error("Stream #%d already in use\n", GetStreamId());
		//Exit
		return;
	}

	//Skip the type part "flv:" inserted by FMS
	size_t i = url.find(L":",0);

	//If not found
	if (i==std::wstring::npos)
		//from the begining
		i = 0;
	else
		//Skip
		i++;

	//Get the next "/"
	size_t j = url.find(L"/",i);

	//Check if found
	if (j==std::wstring::npos)
	{
		//Send error
		fireOnNetStreamStatus(RTMP::Netstream::Publish::BadName,L"Wrong format stream name");
		//Noting found
		Error("Wrong format stream name\n");
		//Exit
		return;
	}
	//Get type
	std::wstring type = url.substr(i,j-i);

	//Get token
	std::wstring token = url.substr(j+1,url.length()-j);

	//Check app name
	if (!type.compare(L"participant")==0)
	{
		//Log
		Error("-Application type name incorrect [%ls]\n",type.c_str());
		//Send error
		fireOnNetStreamStatus(RTMP::Netstream::Publish::BadName,L"Type invalid");
		//Nothing done
		return;
	}

	//Get participant stream
	RTMPMediaStream::Listener *listener = conf->ConsumeParticipantInputToken(token);

	//Check if found
	if (!listener)
	{
		//Send error
		fireOnNetStreamStatus(RTMP::Netstream::Publish::BadName,L"Token invalid");
		//Exit
		return;
	}

	//Opened
	opened = true;

	//Add this as listener
	AddMediaListener(listener);

	//Send publish notification
	fireOnNetStreamStatus(RTMP::Netstream::Publish::Start,L"Publish started");
}
 CPVRStream* CStreamProperties::GetStreamById(unsigned int iPhysicalId) const
 {
   int position = GetStreamId(iPhysicalId);
   return position != -1 ? &m_streamVector->at(position) : NULL;
 }