Skip to content

Commit

Permalink
Fixed decoder state logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mondain committed Apr 6, 2022
1 parent b8e7607 commit 3a2cb95
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/main/java/org/red5/server/net/protocol/RTMPDecodeState.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

package org.red5.server.net.protocol;

import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;

/**
* Represents current decode state of the protocol.
*/
Expand All @@ -22,9 +20,6 @@ private enum State {
DESTROYED; // Decoding is no longer required
}

// atomic updater the current amount buffered
private final static AtomicIntegerFieldUpdater<RTMPDecodeState> amountUpdater = AtomicIntegerFieldUpdater.newUpdater(RTMPDecodeState.class, "decoderBufferAmount");

/**
* Session id to which this decoding state belongs.
*/
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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;
}

Expand Down

0 comments on commit 3a2cb95

Please sign in to comment.