From 3a2cb95b141f3fddf43f519d2c66c84026533f1b Mon Sep 17 00:00:00 2001 From: Paul Gregoire Date: Wed, 6 Apr 2022 12:17:17 -0700 Subject: [PATCH] Fixed decoder state logic --- .../red5/server/net/protocol/RTMPDecodeState.java | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/red5/server/net/protocol/RTMPDecodeState.java b/src/main/java/org/red5/server/net/protocol/RTMPDecodeState.java index f728f05e..e4d82585 100644 --- a/src/main/java/org/red5/server/net/protocol/RTMPDecodeState.java +++ b/src/main/java/org/red5/server/net/protocol/RTMPDecodeState.java @@ -7,8 +7,6 @@ package org.red5.server.net.protocol; -import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; - /** * Represents current decode state of the protocol. */ @@ -22,9 +20,6 @@ private enum State { DESTROYED; // Decoding is no longer required } - // atomic updater the current amount buffered - private final static AtomicIntegerFieldUpdater amountUpdater = AtomicIntegerFieldUpdater.newUpdater(RTMPDecodeState.class, "decoderBufferAmount"); - /** * Session id to which this decoding state belongs. */ @@ -54,14 +49,13 @@ public int getDecoderBufferAmount() { } /** - * Specifies buffer decoding amount + * Specifies buffer decoding amount needed. * * @param amount Buffer decoding amount */ public void bufferDecoding(int amount) { - if (amountUpdater.addAndGet(this, amount) > 0) { - decoderState = State.BUFFER; - } + decoderState = State.BUFFER; + decoderBufferAmount = amount; } /** @@ -85,12 +79,11 @@ public boolean canStartDecoding(int remaining) { * Starts decoding. Sets state to "ready" and clears buffer amount. */ public void startDecoding() { - amountUpdater.set(this, 0); decoderState = State.OK; + decoderBufferAmount = 0; } public void stopDecoding() { - amountUpdater.lazySet(this, 0); decoderState = State.DESTROYED; }