int StartFeed (struct dvb_demux_feed* Feed)
{
    struct dvb_demux*                   DvbDemux        = Feed->demux;
    struct dmxdev_filter*               Filter          = (struct dmxdev_filter*)Feed->feed.ts.priv;
    struct dmx_pes_filter_params*       Params          = &Filter->params.pes;
    struct DeviceContext_s*             Context         = (struct DeviceContext_s*)DvbDemux->priv;
    struct DvbContext_s*                DvbContext      = Context->DvbContext;
    int                                 Result          = 0;
    int                                 i;
    unsigned int                        Video           = false;
    unsigned int                        Audio           = false;
#ifdef __TDT__
    struct DeviceContext_s *AvContext = NULL;
#endif

    DVB_DEBUG ("(demux%d)\n", Context->Id);

    /* either numRunningFeeds == 0 and reset_tsm == 1 or reset_tsm > 1 */
#ifdef __TDT__
	// fix recoding freezer on tuner0 and demux1/2 or tuner1 and demux0/2 or tuner2 and demux0/1
	int tsm_reset = 1;
	
	for (i = 0; i < DVB_MAX_DEVICES_PER_ADAPTER; i++)
	{
	    struct DeviceContext_s* DeviceContext = &DvbContext->DeviceContext[i];
	    if(DeviceContext->numRunningFeeds != 0)
	    	tsm_reset = 0;
	}
	
	if (tsm_reset && reset_tsm)
	{
	    printk(KERN_WARNING "reset_tsm: %d numRunningFeeds: %d => calling stm_tsm_init(1)\n", reset_tsm, Context->numRunningFeeds);
	    stm_tsm_init(1);
	}
#else
    if (Context->numRunningFeeds == 0 && reset_tsm)
    {
        printk(KERN_WARNING "reset_tsm: %d numRunningFeeds: %d => calling stm_tsm_init(1)\n", reset_tsm, Context->numRunningFeeds);
        stm_tsm_init(1);
    }
#endif

#if defined(ADB_BOX)//tutaj
 if (glowica == SINGLE) {
            
 if ((Context->pPtiSession->source==DMX_SOURCE_FRONT1)&&(StartFeed_!=NULL)) StartFeed_(Feed);
           
         }
         else if (glowica == TWIN) {
if ((Context->pPtiSession->source==DMX_SOURCE_FRONT2)&&(StartFeed_!=NULL)) StartFeed_(Feed);
           
         }
#endif

#ifdef __TDT__
#ifdef no_subtitles
  if ((Feed->type == DMX_TYPE_TS) && (Feed->pes_type > DMX_TS_PES_OTHER))
    {
      DVB_DEBUG ("pes_type %d > %d (OTHER)>\n", Feed->pes_type,
                 DMX_TS_PES_OTHER);
      return -EINVAL;
    }
#endif
  DVB_DEBUG("t = %d, pt = %d, pid = %d\n", Feed->type, Feed->pes_type, Feed->pid);
#endif

    switch (Feed->type)
    {
        case DMX_TYPE_TS:
            if (Feed->pes_type > DMX_TS_PES_OTHER)
                return -EINVAL;

            for (i = 0; i < DVB_MAX_DEVICES_PER_ADAPTER; i++)
            {
                if (Feed->pes_type == AudioId[i])
                {
                    Audio       = true;
                    break;
                }
                if (Feed->pes_type == VideoId[i])
                {
                    Video       = true;
                    break;
                }
            }
#ifdef __TDT__
          AvContext = &Context->DvbContext->DeviceContext[i];
          //fix freeze if record starts in background
          //AvContext->DemuxContext      = Context;

          //videotext & subtitles (other)
          if ((Feed->pes_type == DMX_TS_PES_TELETEXT) ||
              (Feed->pes_type == DMX_TS_PES_OTHER))
            {
              mutex_lock (&(DvbContext->Lock));

              Context->numRunningFeeds++;
              //printk("%s:%d numRunningFeeds: %d\n", __func__,__LINE__,Context->numRunningFeeds);

              stpti_start_feed (Feed, Context);
              mutex_unlock (&(DvbContext->Lock));

              break;
            }
#endif

            if (!Audio && !Video)
            {
#ifdef __TDT__
		DVB_DEBUG ("pes_type = %d\n<\n", Feed->pes_type);
#endif
                /*mutex_unlock (&(DvbContext->Lock));  This doesn't look right we haven't taken it yet*/
                return 0;
            }

            mutex_lock (&(DvbContext->Lock));
#ifndef __TDT__
            if ((Video && !Context->VideoOpenWrite) || (Audio && !Context->AudioOpenWrite))
            {
                mutex_unlock (&(DvbContext->Lock));
                return -EBADF;
            }
#endif
            if ((Context->Playback == NULL) && (Context->SyncContext->Playback == NULL))
            {
                Result      = DvbPlaybackCreate (&Context->Playback);
                if (Result < 0)
                {
                    mutex_unlock (&(DvbContext->Lock));
                    return Result;
                }
                Context->SyncContext->Playback      = Context->Playback;
                if (Context->PlaySpeed != DVB_SPEED_NORMAL_PLAY)
                {
                    Result      = VideoIoctlSetSpeed (Context, Context->PlaySpeed);
                    if (Result < 0)
#ifdef __TDT__
                    {
                        mutex_unlock (&(DvbContext->Lock));
                        return Result;
                    }
#else
                        return Result;
#endif
                }
#ifdef __TDT__
		        if ((Context->VideoPlayInterval.start != DVB_TIME_NOT_BOUNDED) ||
                            (Context->VideoPlayInterval.end   != DVB_TIME_NOT_BOUNDED))
		        {
                    Result = VideoIoctlSetPlayInterval (Context, &Context->AudioPlayInterval);
		            if (Result < 0)
                            {
                  	        mutex_unlock (&(DvbContext->Lock));
                  	        return Result;
                            }
		        }
#endif
            }
            else if (Context->Playback == NULL)
                Context->Playback               = Context->SyncContext->Playback;
            else if (Context->SyncContext->Playback == NULL)
                Context->SyncContext->Playback  = Context->Playback;
            else if (Context->Playback != Context->SyncContext->Playback)
                DVB_ERROR ("Context playback not equal to sync context playback\n");

            if (Context->DemuxStream == NULL)
            {
                Result      = DvbPlaybackAddDemux (Context->Playback, Context->DemuxContext->Id, &Context->DemuxStream);
                if (Result < 0)
                {
                    mutex_unlock (&(DvbContext->Lock));
                    return Result;
                }
            }

#ifdef __TDT__
	        if (Video)
	        {

			Context->numRunningFeeds++;
                       //printk("%s:%d numRunningFeeds: %d\n", __func__,__LINE__,Context->numRunningFeeds);

		       stpti_start_feed (Feed, Context);

		       if(Feed->ts_type & TS_DECODER)
		          VideoIoctlSetId (AvContext, Feed->pid);
	        }
	        else if (Audio)
	        {

		        Context->numRunningFeeds++;
			//printk("%s:%d numRunningFeeds: %d\n", __func__,__LINE__,Context->numRunningFeeds);

		       stpti_start_feed (Feed, Context);

		       if(Feed->ts_type & TS_DECODER)
		          AudioIoctlSetId (AvContext, Feed->pid);
	        }
#else
            if (Video)
            {
                struct DeviceContext_s* VideoContext    = &Context->DvbContext->DeviceContext[i];

                VideoContext->DemuxContext      = Context;
                VideoIoctlSetId (VideoContext, Feed->pid | (Params->flags & DMX_FILTER_BY_PRIORITY_MASK));
                VideoIoctlPlay (VideoContext);
                if ((Context->VideoPlayInterval.start != DVB_TIME_NOT_BOUNDED) ||
                    (Context->VideoPlayInterval.end   != DVB_TIME_NOT_BOUNDED))
                    VideoIoctlSetPlayInterval (Context, &Context->AudioPlayInterval);
            }
            else
            {
                struct DeviceContext_s*         AudioContext    = &Context->DvbContext->DeviceContext[i];

                AudioContext->DemuxContext      = Context;
                AudioIoctlSetId (AudioContext, Feed->pid | (Params->flags & DMX_FILTER_BY_PRIORITY_MASK));
                AudioIoctlPlay (AudioContext);
                if ((Context->AudioPlayInterval.start != DVB_TIME_NOT_BOUNDED) ||
                    (Context->AudioPlayInterval.end   != DVB_TIME_NOT_BOUNDED))
                    AudioIoctlSetPlayInterval (Context, &Context->AudioPlayInterval);
            }
#endif
            mutex_unlock (&(DvbContext->Lock));

            break;
        case DMX_TYPE_SEC:
#ifdef __TDT__
            //DVB_DEBUG ("feed type = SEC\n");

            mutex_lock (&(DvbContext->Lock));

	    Context->numRunningFeeds++;
            //printk("%s:%d numRunningFeeds: %d\n", __func__,__LINE__,Context->numRunningFeeds);

            stpti_start_feed (Feed, Context);
            mutex_unlock (&(DvbContext->Lock));
#endif
            break;
        default:
#ifdef __TDT
	        DVB_DEBUG ("< (type = %d unknown\n", Feed->type);
#endif
            return -EINVAL;
    }

    return 0;
}
Beispiel #2
0
void ptiInit ( struct DeviceContext_s *pContext )
{
#if defined(UFS912) || defined(UFS913) || defined(SPARK) || defined(SPARK7162) || defined(ATEVIO7500) || defined(HS7810A) || defined(HS7110) || defined(ATEMIO520) || defined(ATEMIO530) || defined(VITAMIN_HD5000)
  unsigned long start = 0xfe230000;
#else
  unsigned long start = 0x19230000;
#endif

  struct PtiSession *pSession;
  int tag;
  int i;

#if defined(ADB_BOX)
	if((TSIS_mode[0] == 0) || (strcmp("serial", TSIS_mode) == 0))
		{
		printk("TsinMode = SERIAL\n");
		TsinMode = SERIAL;
		}
		else if(strcmp("parallel", TSIS_mode) == 0)
		{
		printk("TsinMode = PARALLEL\n");
		TsinMode = PARALLEL;
		} 
	
	if((TSIS_mode[0] == 0) || (strcmp("single", NIMS) == 0))
		{
		printk("NIMS = SINGLE\n");
		glowica = SINGLE;
		}
		else if(strcmp("twin", NIMS) == 0)
		{
		printk("NIMS = TWIN\n");
		glowica = TWIN;
		} 
#endif

  printk ( "%s context = %p, demux = %p\n",  __FUNCTION__,
           pContext, &pContext->DvbDemux);

  if ( pContext->pPtiSession != NULL )
  {
    printk("PTI ERROR: attempted to initialize a device context with an existing session\n");
    return;
  }

  if(!ptiInitialized)
  {
    // the function is called for the first time
    // perform common PTI initialization

    /*
     * ioremap the pti address space
     */
    pti.pti_io = (unsigned int)ioremap ( start, 0xFFFF );

    /*
     * Setup the transport stream merger based on the configuration
     */
    stm_tsm_init (  /*config */ 1 );

#if defined(TF7700) || defined(UFS922) || defined(UFC960) || defined(FORTIS_HDBOX) || defined(HL101) || defined(VIP1_V2) || defined(VIP2_V1) || defined(CUBEREVO) || defined(CUBEREVO_MINI2) || defined(CUBEREVO_MINI) || defined(CUBEREVO_250HD) || defined(CUBEREVO_2000HD) || defined(CUBEREVO_9500HD) || defined(CUBEREVO_MINI_FTA) || defined(ATEVIO7500) || defined(IPBOX9900) || defined(IPBOX99) || defined(IPBOX55) || defined(ADB_BOX) || defined(UFS913)
    pti_hal_init ( &pti, &pContext->DvbDemux, demultiplexDvbPackets, 2);
#elif defined(SPARK7162)	
    pti_hal_init ( &pti, &pContext->DvbDemux, demultiplexDvbPackets, 3);
#else
    pti_hal_init ( &pti, &pContext->DvbDemux, demultiplexDvbPackets, 1);
#endif

#if defined(FORTIS_HDBOX) || defined(UFS912) || defined(SPARK) || defined(HS7810A) || defined(HS7110) || defined(ATEMIO520) || defined(ATEMIO530) || defined(VITAMIN_HD5000) || defined(SAGEMCOM88)
    stv090x_register_frontend(&pContext->DvbContext->DvbAdapter);
#elif defined(HL101) || defined(VIP1_V2) || defined(VIP2_V1) || defined(IPBOX9900) || defined(IPBOX99) || defined(IPBOX55) || defined(ADB_BOX)
    fe_core_register_frontend( &pContext->DvbContext->DvbAdapter);
#elif defined(CUBEREVO) || defined(CUBEREVO_MINI2) || defined(CUBEREVO_MINI) || defined(CUBEREVO_250HD) || defined(CUBEREVO_2000HD) || defined(CUBEREVO_9500HD) || defined(CUBEREVO_MINI_FTA)
    socket_register_adapter(&pContext->DvbContext->DvbAdapter);
#elif defined(OCTAGON1008)
    avl2108_register_frontend( &pContext->DvbContext->DvbAdapter);
#elif defined(ATEVIO7500)
    socket_register_adapter(&pContext->DvbContext->DvbAdapter);
#elif defined(SPARK7162)
    spark7162_register_frontend( &pContext->DvbContext->DvbAdapter);
#elif defined(UFC960)
    fe_core_register_frontend( &pContext->DvbContext->DvbAdapter);
#elif defined(UFS922)
    cx24116_register_frontend( &pContext->DvbContext->DvbAdapter);
    avl2108_register_frontend( &pContext->DvbContext->DvbAdapter);
#elif defined(UFS913)
    socket_register_adapter(&pContext->DvbContext->DvbAdapter);
#else
    cx24116_register_frontend( &pContext->DvbContext->DvbAdapter);
#endif
    ptiInitialized = 1;
  }

  /*
   * Allocate the session structure
   */
  pSession = ( struct PtiSession * ) kmalloc ( sizeof ( struct PtiSession ), GFP_KERNEL );

  if ( !pSession )
    return;

  memset ( ( void * ) pSession, 0, sizeof ( *pSession ) );

  pSession->num_pids = 0;

  // get new session handle
  tag = convert_source(sessionCounter + DMX_SOURCE_FRONT0);
  pSession->session = pti_hal_get_new_session_handle(tag, &pContext->DvbDemux);

  // get new descrambler handle
  pSession->descrambler = pti_hal_get_new_descrambler(pSession->session);
  pSession->descramblers[0] = pSession->descrambler;
  for(i=1;i<NUMBER_OF_DESCRAMBLERS;i++)
  	pSession->descramblers[i] = pti_hal_get_new_descrambler(pSession->session);

  printk("Descrambler Handler = %d\n", pSession->descrambler);
  for(i=0;i<8192;i++)
  	pSession->descramblerForPid[i] = 0;

  pContext->pPtiSession = pSession;

  sessionCounter++;

  return;
}