public bool CanSendPacket(RtmpMessage message, long pending) { IRtmpEvent body = message.body; if (!(body is VideoData)) { return(true); } VideoData data = body as VideoData; FrameType frameType = data.FrameType; bool flag = false; switch (this._state) { case FrameDropperState.SEND_ALL: return(true); case FrameDropperState.SEND_INTERFRAMES: if (frameType != FrameType.KEYFRAME) { if (frameType == FrameType.INTERFRAME) { flag = true; } return(flag); } if (pending == 0L) { this._state = FrameDropperState.SEND_ALL; } return(true); case FrameDropperState.SEND_KEYFRAMES: flag = frameType == FrameType.KEYFRAME; if (flag && (pending == 0L)) { this._state = FrameDropperState.SEND_KEYFRAMES_CHECK; } return(flag); case FrameDropperState.SEND_KEYFRAMES_CHECK: flag = frameType == FrameType.KEYFRAME; if (flag && (pending == 0L)) { this._state = FrameDropperState.SEND_INTERFRAMES; } return(flag); } return(flag); }
public bool CanSendPacket(RtmpMessage message, long pending) { IRtmpEvent packet = message.body; if (!(packet is VideoData)) { // We currently only drop video packets. return true; } VideoData video = packet as VideoData; FrameType type = video.FrameType; bool result = false; switch (_state) { case FrameDropperState.SEND_ALL: // All packets will be sent. result = true; break; case FrameDropperState.SEND_INTERFRAMES: // Only keyframes and interframes will be sent. if (type == FrameType.Keyframe) { if (pending == 0) { // Send all frames from now on. _state = FrameDropperState.SEND_ALL; } result = true; } else if (type == FrameType.Interframe) { result = true; } break; case FrameDropperState.SEND_KEYFRAMES: // Only keyframes will be sent. result = (type == FrameType.Keyframe); if (result && pending == 0) { // Maybe switch back to SEND_INTERFRAMES after the next keyframe _state = FrameDropperState.SEND_KEYFRAMES_CHECK; } break; case FrameDropperState.SEND_KEYFRAMES_CHECK: // Only keyframes will be sent. result = (type == FrameType.Keyframe); if (result && pending == 0) { // Continue with sending interframes as well _state = FrameDropperState.SEND_INTERFRAMES; } break; default: break; } return result; }
public void DropPacket(RtmpMessage message) { IRtmpEvent body = message.body; if (body is VideoData) { VideoData data = body as VideoData; FrameType frameType = data.FrameType; switch (this._state) { case FrameDropperState.SEND_ALL: if (frameType != FrameType.DISPOSABLE_INTERFRAME) { if (frameType == FrameType.INTERFRAME) { this._state = FrameDropperState.SEND_KEYFRAMES; } else if (frameType == FrameType.KEYFRAME) { this._state = FrameDropperState.SEND_KEYFRAMES; } break; } break; case FrameDropperState.SEND_INTERFRAMES: if (frameType != FrameType.INTERFRAME) { if (frameType == FrameType.KEYFRAME) { this._state = FrameDropperState.SEND_KEYFRAMES; } break; } this._state = FrameDropperState.SEND_KEYFRAMES_CHECK; break; case FrameDropperState.SEND_KEYFRAMES_CHECK: if (frameType == FrameType.KEYFRAME) { this._state = FrameDropperState.SEND_KEYFRAMES; } break; } } }
public bool CanSendPacket(RtmpMessage message, long pending) { IRtmpEvent packet = message.body; if (!(packet is VideoData)) { // We currently only drop video packets. return(true); } VideoData video = packet as VideoData; FrameType type = video.FrameType; bool result = false; switch (_state) { case FrameDropperState.SEND_ALL: // All packets will be sent. result = true; break; case FrameDropperState.SEND_INTERFRAMES: // Only keyframes and interframes will be sent. if (type == FrameType.Keyframe) { if (pending == 0) { // Send all frames from now on. _state = FrameDropperState.SEND_ALL; } result = true; } else if (type == FrameType.Interframe) { result = true; } break; case FrameDropperState.SEND_KEYFRAMES: // Only keyframes will be sent. result = (type == FrameType.Keyframe); if (result && pending == 0) { // Maybe switch back to SEND_INTERFRAMES after the next keyframe _state = FrameDropperState.SEND_KEYFRAMES_CHECK; } break; case FrameDropperState.SEND_KEYFRAMES_CHECK: // Only keyframes will be sent. result = (type == FrameType.Keyframe); if (result && pending == 0) { // Continue with sending interframes as well _state = FrameDropperState.SEND_INTERFRAMES; } break; default: break; } return(result); }
public void Reset(FrameDropperState state) { _state = state; }
public void DropPacket(RtmpMessage message) { IRtmpEvent packet = message.body; if (!(packet is VideoData)) { // Only check video packets. return; } VideoData video = packet as VideoData; FrameType type = video.FrameType; switch (_state) { case FrameDropperState.SEND_ALL: if (type == FrameType.DisposableInterframe) { // Remain in state, packet is safe to drop. return; } else if (type == FrameType.Interframe) { // Drop all frames until the next keyframe. _state = FrameDropperState.SEND_KEYFRAMES; return; } else if (type == FrameType.Keyframe) { // Drop all frames until the next keyframe. _state = FrameDropperState.SEND_KEYFRAMES; return; } break; case FrameDropperState.SEND_INTERFRAMES: if (type == FrameType.Interframe) { // Drop all frames until the next keyframe. _state = FrameDropperState.SEND_KEYFRAMES_CHECK; return; } else if (type == FrameType.Keyframe) { // Drop all frames until the next keyframe. _state = FrameDropperState.SEND_KEYFRAMES; return; } break; case FrameDropperState.SEND_KEYFRAMES: // Remain in state. break; case FrameDropperState.SEND_KEYFRAMES_CHECK: if (type == FrameType.Keyframe) { // Switch back to sending keyframes, but don't move to SEND_INTERFRAMES afterwards. _state = FrameDropperState.SEND_KEYFRAMES; return; } break; default: break; } }