Skip to content

Commit c200fca

Browse files
committed
Make audio/video playback tests available to bazel build.
We can use these to validate that a/v calls on tox at least work on localhost connections.
1 parent f0ae031 commit c200fca

File tree

4 files changed

+81
-18
lines changed

4 files changed

+81
-18
lines changed

BUILD.bazel

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ scala_library(
143143
"src/test/java/im/tox/tox4j/ToxCoreTestBase.scala",
144144
"src/test/java/im/tox/tox4j/av/callbacks/audio/AudioGenerator.scala",
145145
"src/test/java/im/tox/tox4j/av/callbacks/audio/AudioGenerators.scala",
146+
"src/test/java/im/tox/tox4j/av/callbacks/audio/AudioPlayback.scala",
146147
"src/test/java/im/tox/tox4j/av/callbacks/video/ArithmeticVideoGenerator.scala",
147148
"src/test/java/im/tox/tox4j/av/callbacks/video/RgbVideoGenerator.scala",
148149
"src/test/java/im/tox/tox4j/av/callbacks/video/TextImageGenerator.scala",
@@ -245,3 +246,74 @@ scala_library(
245246
"@com_google_guava_guava//jar",
246247
],
247248
) for src in glob(["src/test/java/im/tox/tox4j/impl/jni/codegen/Jni*.scala"])]
249+
250+
scala_binary(
251+
name = "AudioPlaybackShow",
252+
testonly = True,
253+
srcs = [
254+
"src/tools/java/im/tox/tox4j/av/callbacks/audio/AudioPlaybackShow.scala",
255+
],
256+
main_class = "im.tox.tox4j.av.callbacks.audio.AudioPlaybackShow",
257+
resources = glob([
258+
"src/test/resources/**/*",
259+
]),
260+
deps = [
261+
":jvm-toxcore-c",
262+
":test_lib",
263+
"//jvm-toxcore-api",
264+
],
265+
)
266+
267+
scala_test(
268+
name = "AudioReceiveFrameCallbackShow",
269+
size = "small",
270+
srcs = ["src/tools/java/im/tox/tox4j/av/callbacks/audio/AudioReceiveFrameCallbackShow.scala"],
271+
data = [":native"],
272+
jvm_flags = ["-Djava.library.path=jvm-toxcore-c"],
273+
resources = glob([
274+
"src/test/resources/**/*",
275+
]),
276+
tags = ["manual"],
277+
deps = [
278+
":jvm-toxcore-c",
279+
":test_lib",
280+
"//jvm-toxcore-api",
281+
"//third_party/scala:com_typesafe_scala_logging_scala_logging",
282+
"@io_bazel_rules_scala//scala/scalatest",
283+
"@log4j_log4j//jar",
284+
"@org_jetbrains_annotations//jar",
285+
"@org_slf4j_slf4j_api//jar",
286+
"@org_slf4j_slf4j_log4j12//jar",
287+
],
288+
)
289+
290+
scala_test(
291+
name = "VideoReceiveFrameCallbackShow",
292+
size = "small",
293+
srcs = [
294+
"src/tools/java/im/tox/tox4j/av/callbacks/video/ConsoleVideoDisplay.scala",
295+
"src/tools/java/im/tox/tox4j/av/callbacks/video/GuiVideoDisplay.scala",
296+
"src/tools/java/im/tox/tox4j/av/callbacks/video/RgbVideoDisplay.scala",
297+
"src/tools/java/im/tox/tox4j/av/callbacks/video/VideoDisplay.scala",
298+
"src/tools/java/im/tox/tox4j/av/callbacks/video/VideoReceiveFrameCallbackShow.scala",
299+
],
300+
data = [":native"],
301+
jvm_flags = ["-Djava.library.path=jvm-toxcore-c"],
302+
resources = glob([
303+
"src/test/resources/**/*",
304+
]),
305+
tags = ["manual"],
306+
deps = [
307+
":jvm-toxcore-c",
308+
":test_lib",
309+
"//jvm-toxcore-api",
310+
"//third_party/scala:com_chuusai_shapeless",
311+
"//third_party/scala:com_typesafe_scala_logging_scala_logging",
312+
"@io_bazel_rules_scala//scala/scalatest",
313+
"@log4j_log4j//jar",
314+
"@org_jetbrains_annotations//jar",
315+
"@org_scala_lang_modules_scala_swing//jar",
316+
"@org_slf4j_slf4j_api//jar",
317+
"@org_slf4j_slf4j_log4j12//jar",
318+
],
319+
)

src/tools/java/im/tox/tox4j/av/callbacks/audio/AudioPlaybackShow.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package im.tox.tox4j.av.callbacks.audio
22

33
import im.tox.tox4j.av.data.{ AudioLength, SampleCount, SamplingRate }
4-
import jline.TerminalFactory
5-
import org.scalatest.FunSuite
64

75
@SuppressWarnings(Array("org.wartremover.warts.While"))
8-
final class AudioPlaybackShow extends FunSuite {
6+
object AudioPlaybackShow {
97

108
private val audio = AudioGenerators.default
119

@@ -14,8 +12,8 @@ final class AudioPlaybackShow extends FunSuite {
1412
private val frameSize = SampleCount(audioLength, samplingRate)
1513
private val playback = new AudioPlayback(samplingRate)
1614

17-
test("main") {
18-
val terminalWidth = TerminalFactory.get.getWidth
15+
def main(args: Array[String]) {
16+
val terminalWidth = 190
1917

2018
System.out.print("\u001b[2J")
2119

src/tools/java/im/tox/tox4j/av/callbacks/audio/AudioReceiveFrameCallbackShow.scala

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ import im.tox.tox4j.core.data.ToxFriendNumber
1212
import im.tox.tox4j.core.enums.ToxConnection
1313
import im.tox.tox4j.testing.ToxExceptionChecks
1414
import im.tox.tox4j.testing.autotest.AutoTestSuite
15-
import jline.TerminalFactory
1615
import org.slf4j.LoggerFactory
1716

1817
import scala.annotation.tailrec
19-
import scalaz.concurrent.Future
2018

2119
/**
2220
* This test name does not end in "Test" so it won't be run by the CI build. This is
@@ -29,6 +27,7 @@ import scalaz.concurrent.Future
2927
final class AudioReceiveFrameCallbackShow extends AutoTestSuite with ToxExceptionChecks {
3028

3129
private val logger = Logger(LoggerFactory.getLogger(getClass))
30+
private val terminalWidth = 190
3231

3332
override def maxParticipantCount: Int = 2
3433

@@ -110,11 +109,6 @@ final class AudioReceiveFrameCallbackShow extends AutoTestSuite with ToxExceptio
110109
state.addTask(sendFrame(friendNumber))
111110
}
112111

113-
override def bitRateStatus(friendNumber: ToxFriendNumber, audioBitRate: BitRate, videoBitRate: BitRate)(state: State): State = {
114-
debug(state, s"Bit rate in call with ${state.id(friendNumber)} should change to $audioBitRate for audio and $videoBitRate for video")
115-
state
116-
}
117-
118112
// There is no stack recursion here, it pushes thunks of itself for deferred execution.
119113
@SuppressWarnings(Array("org.wartremover.warts.Recursion"))
120114
def waitForPlayback(length: Int)(state: State): State = {
@@ -157,15 +151,14 @@ final class AudioReceiveFrameCallbackShow extends AutoTestSuite with ToxExceptio
157151
assert(receivedPcm.length == expectedPcm.length)
158152

159153
if (displayWave) {
160-
val width = TerminalFactory.get.getWidth
161154
if (t == 0) {
162155
System.out.print("\u001b[2J")
163156
}
164157
System.out.print("\u001b[H")
165158
System.out.println("Received:")
166-
System.out.println(AudioPlayback.showWave(receivedPcm, width))
159+
System.out.println(AudioPlayback.showWave(receivedPcm, terminalWidth))
167160
System.out.println("Expected:")
168-
System.out.println(AudioPlayback.showWave(expectedPcm, width))
161+
System.out.println(AudioPlayback.showWave(expectedPcm, terminalWidth))
169162
}
170163

171164
playback.play(receivedPcm)
@@ -182,7 +175,7 @@ final class AudioReceiveFrameCallbackShow extends AutoTestSuite with ToxExceptio
182175
val queue = new ArrayBlockingQueue[Option[(Int, Array[Short])]](audioLength / frameSize / 2)
183176

184177
// Start a thread to consume the frames.
185-
Future(playFrames(queue)).unsafeStart
178+
new Thread { override def run() { playFrames(queue) } }.start
186179

187180
queue
188181
}

src/tools/java/im/tox/tox4j/av/callbacks/video/GuiVideoDisplay.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import java.awt.image.{ BufferedImage, DataBufferByte }
55
import java.io.File
66
import javax.imageio.ImageIO
77
import javax.swing.border.EtchedBorder
8-
import javax.swing.{ BorderFactory, ImageIcon }
8+
import javax.swing.{ BorderFactory, ImageIcon, JDialog }
99

1010
import com.typesafe.scalalogging.Logger
1111
import im.tox.tox4j.av.callbacks.video.GuiVideoDisplay.{ UI, newImage }
@@ -69,7 +69,7 @@ object GuiVideoDisplay {
6969
BufferedImage.TYPE_INT_RGB
7070
)
7171

72-
dialog.self.paint(image.getGraphics)
72+
dialog.self.asInstanceOf[JDialog].paint(image.getGraphics)
7373

7474
ImageIO.write(image, "jpg", new File(capturePath, f"$frameNumber%03d.jpg"))
7575
}

0 commit comments

Comments
 (0)