⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zl5011xcetqueue.c

📁 Zalink50114----TDMoIP芯片驱动源码
💻 C
📖 第 1 页 / 共 3 页
字号:
                           seqDiff = seq - settings->prevSeq;
                           seqDiff >>= 8;

                           /* work out how many packets are not being accepted into the queue.
                              If more than 10% of the number of packets played out in the interval
                              are not accepted then consider the queue to be empty */
                           discardedPkts = (late - settings->prevLate) +  (early - settings->prevEarly);

                           if (discardedPkts > (seqDiff / 10))
                           {
                              if (zl5011xCetQueueExtraDebug == context)
                              {
                                 OS_LOG_MSG("queue : empty -> length %08X, discards %d, pkts %d" ZL5011X_NEWLINE,
                                       avgLength, discardedPkts, seqDiff, 0, 0, 0);
                              }

                              /* the queue is empty - check that it was also empty for
                                 the last interval before taking further action */
                              if (settings->prevEmpty == ZL5011X_TRUE)
                              {
                                 settings->prevEmpty = ZL5011X_FALSE;

                                 /* need to reset the queue */
                                 status = zl5011xTfqResetQueue(zl5011xParams, context);

                                 if (status == ZL5011X_OK)
                                 {
                                    /* clear the prev adjustment count */
                                    settings->prevAdjusts = 0;

                                    /* how much to adjust the queue by following a reset */
                                    settings->currPktAdjust = settings->resetPktAdjust;

                                    if (zl5011xCetQueueExtraDebug == context)
                                    {
                                       OS_LOG_MSG("queue : ctxt %3d reset, adjust %d pkts" ZL5011X_NEWLINE,
                                             context, settings->resetPktAdjust, 0, 0, 0, 0);
                                    }
                                 }
                              }
                              else
                              {
                                 /* only consider resetting the queue if there are 2
                                    consecutive intervals in which the queue length is 0 */
                                 settings->prevEmpty = ZL5011X_TRUE;
                              }
                           }
                           else
                           {
                              /* if the queue needs to be adjusted following reset, do that
                                 before assessing whether the queue needs adjusting from a
                                 packet loss point of view */
                              if (settings->currPktAdjust == 0)
                              {
                                 /* the queue is not empty, so reset the empty flag */
                                 settings->prevEmpty = ZL5011X_FALSE;

                                 /* if no early or late increment happens, then it means
                                    that the packet that caused the underrun was lost */
                                 if (early != settings->prevEarly)
                                 {
                                    /* going to reduce the queue so check that haven't been making continual
                                       adjustments and would be better off issuing a reset */
                                    settings->prevAdjusts--;

                                    if (settings->prevAdjusts < -(Sint32T)ZL5011X_CET_QUEUE_MAX_CONSECUTIVE_ADJUSTS)
                                    {
                                       /* need to reset the queue */
                                       status = zl5011xTfqResetQueue(zl5011xParams, context);

                                       /* how much to adjust the queue by following a reset */
                                       settings->currPktAdjust = settings->resetPktAdjust;

                                       if (zl5011xCetQueueExtraDebug == context)
                                       {
                                          OS_LOG_MSG("queue : ctxt %3d reset (adjust cnt = %d), adjust %d pkts" ZL5011X_NEWLINE,
                                                context, settings->prevAdjusts, settings->resetPktAdjust, 0, 0, 0);
                                       }

                                       /* clear the prev adjustment count */
                                       settings->prevAdjusts = 0;
                                    }
                                    else
                                    {
                                       /* queue seems to be running a bit high, so reduce it */
                                       status = zl5011xTfqReduceQueueDepth(zl5011xParams, context, ZL5011X_TRUE, 0);

                                       if (zl5011xCetQueueExtraDebug == context)
                                       {
                                          OS_LOG_MSG("queue : ctxt %3d reduce" ZL5011X_NEWLINE,
                                                context, 0, 0, 0, 0, 0);
                                       }
                                    }
                                 }
                                 else
                                 {
                                    if (late != settings->prevLate)
                                    {
                                       /* going to extend the queue so check that haven't been making continual
                                          adjustments and would be better off issuing a reset */
                                       settings->prevAdjusts++;

                                       if (settings->prevAdjusts > ZL5011X_CET_QUEUE_MAX_CONSECUTIVE_ADJUSTS)
                                       {
                                          /* need to reset the queue */
                                          status = zl5011xTfqResetQueue(zl5011xParams, context);

                                          /* how much to adjust the queue by following a reset */
                                          settings->currPktAdjust = settings->resetPktAdjust;

                                          if (zl5011xCetQueueExtraDebug == context)
                                          {
                                             OS_LOG_MSG("queue : ctxt %3d reset (adjust cnt = %d), adjust %d pkts" ZL5011X_NEWLINE,
                                                   context, settings->prevAdjusts, settings->resetPktAdjust, 0, 0, 0);
                                          }

                                          /* clear the prev adjustment count */
                                          settings->prevAdjusts = 0;
                                       }
                                       else
                                       {
                                          /* queue seems to be running a bit low, so extend it */
                                          status = zl5011xTfqExtendQueueDepth(zl5011xParams, context, ZL5011X_TRUE, 0);

                                          if (zl5011xCetQueueExtraDebug == context)
                                          {
                                             OS_LOG_MSG("queue : ctxt %3d extend" ZL5011X_NEWLINE,
                                                   context, 0, 0, 0, 0, 0);
                                          }
                                       }
                                    }
                                    else
                                    {
                                       /* no adjustment this interval */
                                       settings->prevAdjusts = 0;
                                    }
                                 }
                              }
                              else
                              {
                                 /* still adjusting the queue depth following a reset */
                                 if (settings->currPktAdjust < 0)
                                 {
                                    status = zl5011xTfqReduceQueueDepth(zl5011xParams, context, ZL5011X_TRUE, 0);

                                    if (status == ZL5011X_OK)
                                    {
                                       settings->currPktAdjust++;
                                    }
                                 }
                                 else
                                 {
                                    status = zl5011xTfqExtendQueueDepth(zl5011xParams, context, ZL5011X_TRUE, 0);

                                    if (status == ZL5011X_OK)
                                    {
                                       settings->currPktAdjust--;
                                    }
                                 }
                              }
                           }

                           settings->prevLate = late;
                           settings->prevEarly = early;
                           settings->prevUnderrun = underrun;
                        }
                        break;

                     default:
                        settings->state = ZL5011X_CET_QUEUE_STATE_INIT;
                        break;
                  }
               }
               else
               {
                  /* no adjustment this interval */
                  settings->prevAdjusts = 0;
               }

               settings->prevSeq = seq;
            }

            if (status != ZL5011X_OK)
            {
               ZL5011X_TRACE_CONTEXT(ZL5011X_CET_FN_ID, context,
                     "zl5011xCetQueueHandler: ctxt %d, status %d",
                     context, status, 0, 0, 0, 0);
            }
         }
         else
         {
            settings->state = ZL5011X_CET_QUEUE_STATE_INIT;
         }
      }
   }
}

/*******************************************************************************

 Function:
    zl5011xCetStatusFlagHandler

 Description:
   Function used to post changes in the status flags from the master. The
   flags are in the packet header and any changes are detected (mask applied) and
   sent to the application, since this represents a change in state at the master.

 Inputs:
   zl5011xParams      Pointer to the structure for this device instance.
   stream            stream that this flag change is for
   flags             new state of the flags from the master

 Outputs:
   None

 Returns:
   zlStatusE

*******************************************************************************/

zlStatusE zl5011xCetStatusFlagHandler(zl5011xParamsS *zl5011xParams, Uint32T stream, Uint32T flags)
{
   zl5011xCetStatusMsgS msg;
   zlStatusE status = ZL5011X_OK;

   msg.zl5011xParams = zl5011xParams;
   msg.stream = stream;
   msg.statusType = ZL5011X_CET_STATUS_FLAG_CHANGE;
   msg.remoteFlags = flags;

   if (OS_MSG_Q_SEND(zl5011xCetExtensionTable->clockStatusQueueId, (char *)&msg, sizeof(zl5011xCetStatusMsgS),
         OS_NO_WAIT, 0) == OS_ERROR)
   {
       status = ZL5011X_ERROR;

       ZL5011X_TRACE(ZL5011X_CET_FN_ID,
            "zl5011xCetStatusFlagHandler: ERROR queueing",
            0,0,0,0,0,0);
   }

   return status;
}

/*******************************************************************************

 Function:
    zl5011xCetStatusStateHandler

 Description:
   Function used to post changes in the clock recovery state.

 Inputs:
   zl5011xParams      Pointer to the structure for this device instance.
   stream            stream that this flag change is for
   state             new state of the clock recovery

 Outputs:
   None

 Returns:
   zlStatusE

*******************************************************************************/

zlStatusE zl5011xCetStatusStateHandler(zl5011xParamsS *zl5011xParams, Uint32T stream, zl5011xCetStatusE state)
{
   zl5011xCetStatusMsgS msg;
   zlStatusE status = ZL5011X_OK;

   msg.zl5011xParams = zl5011xParams;
   msg.stream = stream;
   msg.statusType = ZL5011X_CET_STATUS_STATE_CHANGE;
   msg.cetStatus = state;

   if (OS_MSG_Q_SEND(zl5011xCetExtensionTable->clockStatusQueueId, (char *)&msg, sizeof(zl5011xCetStatusMsgS),
         OS_NO_WAIT, 0) == OS_ERROR)
   {
       status = ZL5011X_ERROR;

       ZL5011X_TRACE(ZL5011X_CET_FN_ID,
            "zl5011xCetStatusStateHandler: ERROR queueing",
            0,0,0,0,0,0);
   }

   return status;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -