synchronized boolean acceptFrame(
        @NotNull VP8Frame frame,
        int incomingIndex,
        int externalTargetIndex, long receivedMs)
    {
        // We make local copies of the externalTemporalLayerIdTarget and the
        // externalEncodingTarget (as they may be updated by some other
        // thread).
        int externalTemporalLayerIdTarget
            = RtpLayerDesc.getTidFromIndex(externalTargetIndex);
        int externalEncodingIdTarget
            = RtpLayerDesc.getEidFromIndex(externalTargetIndex);
        if (externalEncodingIdTarget != internalEncodingIdTarget)
        {
            // The externalEncodingIdTarget has changed since accept last
            // run; perhaps we should request a keyframe.
            internalEncodingIdTarget = externalEncodingIdTarget;
            if (externalEncodingIdTarget > SUSPENDED_ENCODING_ID)
            {
                needsKeyframe = true;
            }
        }
        if (externalEncodingIdTarget < 0
            || externalTemporalLayerIdTarget < 0)
        {
            // We stop forwarding immediately. We will need a keyframe in order
            // to resume.
            currentEncodingId = SUSPENDED_ENCODING_ID;
            return false;
        }
        int temporalLayerIdOfFrame = frame.getTemporalLayer();
        if (temporalLayerIdOfFrame < 0)
        {
            // temporal scalability is not enabled. Pretend that
            // this is the base temporal layer.
            temporalLayerIdOfFrame = 0;
        }
        int encodingId = RtpLayerDesc.getEidFromIndex(incomingIndex);
        if (frame.isKeyframe())
        {
            logger.debug(() -> "Quality filter got keyframe for stream "
                    + frame.getSsrc());
            return acceptKeyframe(encodingId, receivedMs);
        }
        else if (currentEncodingId > SUSPENDED_ENCODING_ID)
        {
            if (isOutOfSwitchingPhase(receivedMs) && isPossibleToSwitch(encodingId))
            {
                // XXX(george) i've noticed some "rogue" base layer keyframes
                // that trigger this. what happens is the client sends a base
                // layer key frame, the bridge switches to that layer because
                // for all it knows it may be the only keyframe sent by the
                // client engine. then the bridge notices that packets from the
                // higher quality streams are flowing and execution ends-up
                // here. it is a mystery why the engine is "leaking" base layer
                // key frames
                needsKeyframe = true;
            }
            if (encodingId != currentEncodingId)
            {
                // for non-keyframes, we can't route anything but the current encoding
                return false;
            }
            // This branch reads the {@link #currentEncodingId} and it
            // filters packets based on their temporal layer.
            if (currentEncodingId > externalEncodingIdTarget)
            {
                // pending downscale, decrease the frame rate until we
                // downscale.
                return temporalLayerIdOfFrame < 1;
            }
            else if (currentEncodingId < externalEncodingIdTarget)
            {
                // pending upscale, increase the frame rate until we upscale.
                return true;
            }
            else
            {
                // The currentSpatialLayerId matches exactly the target
                // currentSpatialLayerId.
                return temporalLayerIdOfFrame <= externalTemporalLayerIdTarget;
            }
        }
        else
        {
            // In this branch we're not processing a keyframe and the
            // currentSpatialLayerId is in suspended state, which means we need
            // a keyframe to start streaming again. Reaching this point also
            // means that we want to forward something (because both
            // externalEncodingIdTarget and externalTemporalLayerIdTarget
            // are greater than 0) so we set the request keyframe flag.
            // assert needsKeyframe == true;
            return false;
        }
    }
synchronized boolean acceptFrame(
        @NotNull VP8Frame frame,
        int incomingIndex,
        int externalTargetIndex, long receivedMs)
    {
       
       
       
        int externalTemporalLayerIdTarget
            = RtpLayerDesc.getTidFromIndex(externalTargetIndex);
        int externalEncodingIdTarget
            = RtpLayerDesc.getEidFromIndex(externalTargetIndex);
        if (externalEncodingIdTarget != internalEncodingIdTarget)
        {
           
           
            internalEncodingIdTarget = externalEncodingIdTarget;
            if (externalEncodingIdTarget > SUSPENDED_ENCODING_ID)
            {
                needsKeyframe = true;
            }
        }
        if (externalEncodingIdTarget < 0
            || externalTemporalLayerIdTarget < 0)
        {
           
           
            currentEncodingId = SUSPENDED_ENCODING_ID;
            return false;
        }
        int temporalLayerIdOfFrame = frame.getTemporalLayer();
        if (temporalLayerIdOfFrame < 0)
        {
           
           
            temporalLayerIdOfFrame = 0;
        }
        int encodingId = RtpLayerDesc.getEidFromIndex(incomingIndex);
        if (frame.isKeyframe())
        {
            logger.debug(() -> "Quality filter got keyframe for stream "
                    + frame.getSsrc());
            return acceptKeyframe(encodingId, receivedMs);
        }
        else if (currentEncodingId > SUSPENDED_ENCODING_ID)
        {
            if (isOutOfSwitchingPhase(receivedMs) && isPossibleToSwitch(encodingId))
            {
               
               
               
               
               
               
               
               
                needsKeyframe = true;
            }
            if (encodingId != currentEncodingId)
            {
               
                return false;
            }
           
           
            if (currentEncodingId > externalEncodingIdTarget)
            {
               
               
                return temporalLayerIdOfFrame < 1;
            }
            else if (currentEncodingId < externalEncodingIdTarget)
            {
               
                return true;
            }
            else
            {
               
               
                return temporalLayerIdOfFrame <= externalTemporalLayerIdTarget;
            }
        }
        else
        {
           
           
           
           
           
           
           
            return false;
        }
    }
synchronized boolean acceptframe( @notnull vp8frame frame, int incomingindex, int externaltargetindex, long receivedms) { int externaltemporallayeridtarget = rtplayerdesc.gettidfromindex(externaltargetindex); int externalencodingidtarget = rtplayerdesc.geteidfromindex(externaltargetindex); if (externalencodingidtarget != internalencodingidtarget) { internalencodingidtarget = externalencodingidtarget; if (externalencodingidtarget > suspended_encoding_id) { needskeyframe = true; } } if (externalencodingidtarget < 0 || externaltemporallayeridtarget < 0) { currentencodingid = suspended_encoding_id; return false; } int temporallayeridofframe = frame.gettemporallayer(); if (temporallayeridofframe < 0) { temporallayeridofframe = 0; } int encodingid = rtplayerdesc.geteidfromindex(incomingindex); if (frame.iskeyframe()) { logger.debug(() -> "quality filter got keyframe for stream " + frame.getssrc()); return acceptkeyframe(encodingid, receivedms); } else if (currentencodingid > suspended_encoding_id) { if (isoutofswitchingphase(receivedms) && ispossibletoswitch(encodingid)) { needskeyframe = true; } if (encodingid != currentencodingid) { return false; } if (currentencodingid > externalencodingidtarget) { return temporallayeridofframe < 1; } else if (currentencodingid < externalencodingidtarget) { return true; } else { return temporallayeridofframe <= externaltemporallayeridtarget; } } else { return false; } }