public class AudioConsumerUtils
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
private java.nio.ByteBuffer |
buffer
Audio data buffer
|
private static int |
BYTES_PER_SAMPLE
Bytes per sample for 16-bit audio
|
private AgoraRtcConn |
conn
RTC connection instance
|
private int |
consumedFrameCount
Number of consumed frames
|
private static int |
INTERVAL_ONE_FRAME
Interval for one frame in milliseconds
|
private static int |
INTERVAL_PCM_INTERRUPT
Interval for PCM interrupt in milliseconds
|
private boolean |
isDirectSend
Whether to use direct send mode
|
private long |
lastSendTimestamp
Timestamp of last send operation
|
private int |
numOfChannels
Number of audio channels
|
private int |
oneFrameSize
Size of one frame in bytes
|
private int |
sampleRate
Sample rate in Hz
|
private static int |
START_BY_MAX_FRAME_SIZE
Maximum frame size for starting cache
|
private static int |
START_BY_MIN_FRAME_SIZE
Minimum frame size for starting cache
|
private int |
startCacheDataSize
Initial cache data size
|
private long |
startedTimestamp
Timestamp when consumption started
|
| Constructor and Description |
|---|
AudioConsumerUtils(AgoraRtcConn conn,
int numOfChannels,
int sampleRate)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clear the cache.
|
int |
consume()
Consume data from the cache and return consume frame count.
|
private int |
directConsume()
Consumes data directly without buffering.
|
private byte[] |
extractData(int size,
long currentTime)
Extract data from the buffer.
|
private int |
getBufferSize()
Gets the current buffer size.
|
int |
getOneFrameSize()
Gets the size of one frame in bytes.
|
int |
getRemainingCacheDurationInMs()
Gets the remaining cache duration in milliseconds.
|
int |
getSamplesPerChannel(int dataSize)
Calculate samples per channel.
|
void |
pushPcmData(byte[] data)
Push pcm data into the cache.
|
void |
release()
Releases all resources and clears the buffer.
|
private int |
sendPcmData(byte[] data)
Sends PCM data to the RTC connection.
|
private int |
undirectConsume()
Consumes data from the cache with buffering.
|
private static final int START_BY_MAX_FRAME_SIZE
private static final int START_BY_MIN_FRAME_SIZE
private static final int INTERVAL_ONE_FRAME
private static final int INTERVAL_PCM_INTERRUPT
private static final int BYTES_PER_SAMPLE
private AgoraRtcConn conn
private final int numOfChannels
private final int sampleRate
private final int oneFrameSize
private int startCacheDataSize
private java.nio.ByteBuffer buffer
private long startedTimestamp
private long lastSendTimestamp
private int consumedFrameCount
private final boolean isDirectSend
public AudioConsumerUtils(AgoraRtcConn conn, int numOfChannels, int sampleRate)
conn - The AgoraRtcConn.numOfChannels - The number of channels.sampleRate - The sample rate.public int getOneFrameSize()
public int getSamplesPerChannel(int dataSize)
dataSize - The data size.public void pushPcmData(byte[] data)
data - The pcm data.public int consume()
private int directConsume()
private int undirectConsume()
private byte[] extractData(int size,
long currentTime)
size - The size of the data.currentTime - The current time.private int sendPcmData(byte[] data)
data - PCM data to sendprivate int getBufferSize()
public int getRemainingCacheDurationInMs()
public void clear()
public void release()