Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ jobs:
with:
file: docker/jvm.Dockerfile
tags: toxchat/jvm-toxcore-c:jvm

ktlint:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- run: curl -sSLO https://github.com/pinterest/ktlint/releases/download/1.1.1/ktlint && chmod a+x ktlint
- run: ./ktlint
263 changes: 141 additions & 122 deletions lib/src/main/java/im/tox/tox4j/av/ToxAv.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,136 +29,155 @@ import java.io.Closeable
* forcibly terminated without notifying peers.
*/
interface ToxAv : Closeable {
/**
* Start new A/V session. There can only be only one session per Tox instance.
*
* @param tox A compatible ToxCore implementation.
* @return the new A/V session.
* @throws ToxavNewException
*/
fun create(tox: ToxCore): ToxAv

/**
* Start new A/V session. There can only be only one session per Tox instance.
*
* @param tox A compatible ToxCore implementation.
* @return the new A/V session.
*/
// @throws[ToxavNewException]
fun create(tox: ToxCore): ToxAv
/**
* Releases all resources associated with the A/V session.
*
* If any calls were ongoing, these will be forcibly terminated without notifying peers. After
* calling this function, no other functions may be called and the av pointer becomes invalid.
*/
override fun close(): Unit

/**
* Releases all resources associated with the A/V session.
*
* If any calls were ongoing, these will be forcibly terminated without notifying peers. After
* calling this function, no other functions may be called and the av pointer becomes invalid.
*/
override fun close(): Unit
/** Returns the interval in milliseconds when the next [[iterate]] call should be. */
val iterationInterval: Int

/** Returns the interval in milliseconds when the next [[iterate]] call should be. */
val iterationInterval: Int
/**
* Main loop for the session. This function needs to be called in intervals of
* [[iterationInterval]] milliseconds. It is best called in the separate thread from
* [[ToxCore.iterate]].
*/
fun <S> iterate(
handler: ToxAvEventListener<S>,
state: S,
): S

/**
* Main loop for the session. This function needs to be called in intervals of
* [[iterationInterval]] milliseconds. It is best called in the separate thread from
* [[ToxCore.iterate]].
*/
fun <S> iterate(handler: ToxAvEventListener<S>, state: S): S
/**
* Call a friend. This will start ringing the friend.
*
* It is the client's responsibility to stop ringing after a certain timeout, if such behaviour is
* desired. If the client does not stop ringing, the library will not stop until the friend is
* disconnected.
*
* @param friendNumber The friend number of the friend that should be called.
* @param audioBitRate Audio bit rate in Kb/sec. Set this to 0 to disable audio sending.
* @param videoBitRate Video bit rate in Kb/sec. Set this to 0 to disable video sending.
* @throws ToxavCallException
*/
fun call(
friendNumber: ToxFriendNumber,
audioBitRate: BitRate,
videoBitRate: BitRate,
): Unit

/**
* Call a friend. This will start ringing the friend.
*
* It is the client's responsibility to stop ringing after a certain timeout, if such behaviour is
* desired. If the client does not stop ringing, the library will not stop until the friend is
* disconnected.
*
* @param friendNumber The friend number of the friend that should be called.
* @param audioBitRate Audio bit rate in Kb/sec. Set this to 0 to disable audio sending.
* @param videoBitRate Video bit rate in Kb/sec. Set this to 0 to disable video sending.
*/
// @throws[ToxavCallException]
fun call(friendNumber: ToxFriendNumber, audioBitRate: BitRate, videoBitRate: BitRate): Unit
/**
* Accept an incoming call.
*
* If answering fails for any reason, the call will still be pending and it is possible to try and
* answer it later.
*
* @param friendNumber The friend number of the friend that is calling.
* @param audioBitRate Audio bit rate in Kb/sec. Set this to 0 to disable audio sending.
* @param videoBitRate Video bit rate in Kb/sec. Set this to 0 to disable video sending.
* @throws ToxavAnswerException
*/
fun answer(
friendNumber: ToxFriendNumber,
audioBitRate: BitRate,
videoBitRate: BitRate,
): Unit

/**
* Accept an incoming call.
*
* If answering fails for any reason, the call will still be pending and it is possible to try and
* answer it later.
*
* @param friendNumber The friend number of the friend that is calling.
* @param audioBitRate Audio bit rate in Kb/sec. Set this to 0 to disable audio sending.
* @param videoBitRate Video bit rate in Kb/sec. Set this to 0 to disable video sending.
*/
// @throws[ToxavAnswerException]
fun answer(friendNumber: ToxFriendNumber, audioBitRate: BitRate, videoBitRate: BitRate): Unit
/**
* Sends a call control command to a friend.
*
* @param friendNumber The friend number of the friend to send the call control to.
* @param control The control command to send.
* @throws ToxavCallControlException
*/
fun callControl(
friendNumber: ToxFriendNumber,
control: ToxavCallControl,
): Unit

/**
* Sends a call control command to a friend.
*
* @param friendNumber The friend number of the friend to send the call control to.
* @param control The control command to send.
*/
// @throws[ToxavCallControlException]
fun callControl(friendNumber: ToxFriendNumber, control: ToxavCallControl): Unit
/**
* Set the audio bit rate to be used in subsequent audio frames.
*
* @param friendNumber The friend number of the friend for which to set the audio bit rate.
* @param audioBitRate The new audio bit rate in Kb/sec. Set to 0 to disable audio sending. Pass
* -1 to leave unchanged.
* @throws ToxavBitRateSetException
*/
fun setAudioBitRate(
friendNumber: ToxFriendNumber,
audioBitRate: BitRate,
): Unit

/**
* Set the audio bit rate to be used in subsequent audio frames.
*
* @param friendNumber The friend number of the friend for which to set the audio bit rate.
* @param audioBitRate The new audio bit rate in Kb/sec. Set to 0 to disable audio sending. Pass
* -1 to leave unchanged.
*/
// @throws[ToxavBitRateSetException]
fun setAudioBitRate(friendNumber: ToxFriendNumber, audioBitRate: BitRate): Unit
/**
* Set the video bit rate to be used in subsequent audio frames.
*
* @param friendNumber The friend number of the friend for which to set the audio bit rate.
* @param videoBitRate The new video bit rate in Kb/sec. Set to 0 to disable video sending. Pass
* -1 to leave unchanged.
* @throws ToxavBitRateSetException
*/
fun setVideoBitRate(
friendNumber: ToxFriendNumber,
videoBitRate: BitRate,
): Unit

/**
* Set the video bit rate to be used in subsequent audio frames.
*
* @param friendNumber The friend number of the friend for which to set the audio bit rate.
* @param videoBitRate The new video bit rate in Kb/sec. Set to 0 to disable video sending. Pass
* -1 to leave unchanged.
*/
// @throws[ToxavBitRateSetException]
fun setVideoBitRate(friendNumber: ToxFriendNumber, videoBitRate: BitRate): Unit
/**
* Send an audio frame to a friend.
*
* The expected format of the PCM data is: [s1c1][s1c2][...][s2c1][s2c2][...]... Meaning: sample 1
* for channel 1, sample 1 for channel 2, ... For mono audio, this has no meaning, every sample is
* subsequent. For stereo, this means the expected format is LRLRLR... with samples for left and
* right alternating.
*
* @param friendNumber The friend number of the friend to which to send an audio frame.
* @param pcm An array of audio samples. The size of this array must be sample_count * channels.
* @param sampleCount Number of samples in this frame in milliseconds. Valid numbers here are
* ((sample rate) * (audio length) / 1000), where audio length can be 2.5, 5, 10, 20, 40 or 60
* milliseconds.
* @param channels Number of audio channels. Supported values are 1 and 2.
* @param samplingRate Audio sampling rate used in this frame in Hz. Valid sampling rates are
* 8000, 12000, 16000, 24000, or 48000.
* @throws ToxavSendFrameException
*/
fun audioSendFrame(
friendNumber: ToxFriendNumber,
pcm: ShortArray,
sampleCount: SampleCount,
channels: AudioChannels,
samplingRate: SamplingRate,
): Unit

/**
* Send an audio frame to a friend.
*
* The expected format of the PCM data is: [s1c1][s1c2][...][s2c1][s2c2][...]... Meaning: sample 1
* for channel 1, sample 1 for channel 2, ... For mono audio, this has no meaning, every sample is
* subsequent. For stereo, this means the expected format is LRLRLR... with samples for left and
* right alternating.
*
* @param friendNumber The friend number of the friend to which to send an audio frame.
* @param pcm An array of audio samples. The size of this array must be sample_count * channels.
* @param sampleCount Number of samples in this frame in milliseconds. Valid numbers here are
* ((sample rate) * (audio length) / 1000), where audio length can be 2.5, 5, 10, 20, 40 or 60
* milliseconds.
* @param channels Number of audio channels. Supported values are 1 and 2.
* @param samplingRate Audio sampling rate used in this frame in Hz. Valid sampling rates are
* 8000, 12000, 16000, 24000, or 48000.
*/
// @throws[ToxavSendFrameException]
fun audioSendFrame(
friendNumber: ToxFriendNumber,
pcm: ShortArray,
sampleCount: SampleCount,
channels: AudioChannels,
samplingRate: SamplingRate
): Unit

/**
* Send a video frame to a friend.
*
* Y - plane should be of size: height * width U - plane should be of size: (height/2) * (width/2)
* V - plane should be of size: (height/2) * (width/2)
*
* @param friendNumber The friend number of the friend to which to send a video frame.
* @param width Width of the frame in pixels.
* @param height Height of the frame in pixels.
* @param y Y (Luminance) plane data.
* @param u U (Chroma) plane data.
* @param v V (Chroma) plane data.
*/
// @throws[ToxavSendFrameException]
fun videoSendFrame(
friendNumber: ToxFriendNumber,
width: Int,
height: Int,
y: ByteArray,
u: ByteArray,
v: ByteArray
): Unit
/**
* Send a video frame to a friend.
*
* Y - plane should be of size: height * width U - plane should be of size: (height/2) * (width/2)
* V - plane should be of size: (height/2) * (width/2)
*
* @param friendNumber The friend number of the friend to which to send a video frame.
* @param width Width of the frame in pixels.
* @param height Height of the frame in pixels.
* @param y Y (Luminance) plane data.
* @param u U (Chroma) plane data.
* @param v V (Chroma) plane data.
* @throws ToxavSendFrameException
*/
fun videoSendFrame(
friendNumber: ToxFriendNumber,
width: Int,
height: Int,
y: ByteArray,
u: ByteArray,
v: ByteArray,
): Unit
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import im.tox.tox4j.core.data.ToxFriendNumber
* point core suggests new bit rates.
*/
interface AudioBitRateCallback<ToxCoreState> {
/**
* @param friendNumber The friend number of the friend for which to set the audio bit rate.
* @param audioBitRate Suggested maximum audio bit rate in Kb/sec.
*/
fun audioBitRate(
friendNumber: ToxFriendNumber,
audioBitRate: BitRate,
state: ToxCoreState
): ToxCoreState = state
/**
* @param friendNumber The friend number of the friend for which to set the audio bit rate.
* @param audioBitRate Suggested maximum audio bit rate in Kb/sec.
*/
fun audioBitRate(
friendNumber: ToxFriendNumber,
audioBitRate: BitRate,
state: ToxCoreState,
): ToxCoreState = state
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import im.tox.tox4j.core.data.ToxFriendNumber

/** Called when an audio frame is received. */
interface AudioReceiveFrameCallback<ToxCoreState> {
/**
* @param friendNumber The friend number of the friend who sent an audio frame.
* @param pcm An array of audio samples (sample_count * channels elements).
* @param channels Number of audio channels.
* @param samplingRate Sampling rate used in this frame.
*/
fun audioReceiveFrame(
friendNumber: ToxFriendNumber,
pcm: ShortArray,
channels: AudioChannels,
samplingRate: SamplingRate,
state: ToxCoreState
): ToxCoreState = state
/**
* @param friendNumber The friend number of the friend who sent an audio frame.
* @param pcm An array of audio samples (sample_count * channels elements).
* @param channels Number of audio channels.
* @param samplingRate Sampling rate used in this frame.
*/
fun audioReceiveFrame(
friendNumber: ToxFriendNumber,
pcm: ShortArray,
channels: AudioChannels,
samplingRate: SamplingRate,
state: ToxCoreState,
): ToxCoreState = state
}
22 changes: 11 additions & 11 deletions lib/src/main/java/im/tox/tox4j/av/callbacks/CallCallback.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import im.tox.tox4j.core.data.ToxFriendNumber

/** Triggered when a friend calls us. */
interface CallCallback<ToxCoreState> {
/**
* @param friendNumber The friend number from which the call is incoming.
* @param audioEnabled True if friend is sending audio.
* @param videoEnabled True if friend is sending video.
*/
fun call(
friendNumber: ToxFriendNumber,
audioEnabled: Boolean,
videoEnabled: Boolean,
state: ToxCoreState
): ToxCoreState = state
/**
* @param friendNumber The friend number from which the call is incoming.
* @param audioEnabled True if friend is sending audio.
* @param videoEnabled True if friend is sending video.
*/
fun call(
friendNumber: ToxFriendNumber,
audioEnabled: Boolean,
videoEnabled: Boolean,
state: ToxCoreState,
): ToxCoreState = state
}
22 changes: 11 additions & 11 deletions lib/src/main/java/im/tox/tox4j/av/callbacks/CallStateCallback.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import java.util.EnumSet

/** Called when the call state changes. */
interface CallStateCallback<ToxCoreState> {
/**
* @param friendNumber The friend number this call state change is for.
* @param callState A set of ToxCallState values comprising the new call state. Although this is a
* Collection (therefore might actually be a List), this is effectively a Set. Any
* [[ToxavFriendCallState]] value is contained exactly 0 or 1 times.
*/
fun callState(
friendNumber: ToxFriendNumber,
callState: EnumSet<ToxavFriendCallState>,
state: ToxCoreState
): ToxCoreState = state
/**
* @param friendNumber The friend number this call state change is for.
* @param callState A set of ToxCallState values comprising the new call state. Although this is a
* Collection (therefore might actually be a List), this is effectively a Set. Any
* [[ToxavFriendCallState]] value is contained exactly 0 or 1 times.
*/
fun callState(
friendNumber: ToxFriendNumber,
callState: EnumSet<ToxavFriendCallState>,
state: ToxCoreState,
): ToxCoreState = state
}
Loading