test_gstreamer1.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import os
  2. import infra.basetest
  3. class TestGstreamer1(infra.basetest.BRTest):
  4. # This test creates a full, yet simple, Gstreamer pipeline which
  5. # encodes/decodes a video, using only plugins from Base and Good
  6. # packages. It will use Tesseract OCR to validate the final
  7. # output. The DejaVu font package is also installed, in order to
  8. # have few fonts for the Pango plugin.
  9. config = \
  10. """
  11. BR2_arm=y
  12. BR2_cortex_a9=y
  13. BR2_ARM_ENABLE_VFP=y
  14. BR2_TOOLCHAIN_EXTERNAL=y
  15. BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y
  16. BR2_PACKAGE_DEJAVU=y
  17. BR2_PACKAGE_GSTREAMER1=y
  18. BR2_PACKAGE_GST1_PLUGINS_BASE=y
  19. BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_OGG=y
  20. BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_PANGO=y
  21. BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_THEORA=y
  22. BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_VIDEOTESTSRC=y
  23. BR2_PACKAGE_GST1_PLUGINS_GOOD=y
  24. BR2_PACKAGE_GST1_PLUGINS_GOOD_PNG=y
  25. BR2_PACKAGE_GST1_PLUGINS_GOOD_PLUGIN_MULTIFILE=y
  26. BR2_PACKAGE_TESSERACT_OCR=y
  27. BR2_PACKAGE_TESSERACT_OCR_LANG_ENG=y
  28. BR2_TARGET_ROOTFS_CPIO=y
  29. # BR2_TARGET_ROOTFS_TAR is not set
  30. """
  31. def test_run(self):
  32. cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
  33. self.emulator.boot(arch="armv7",
  34. kernel="builtin",
  35. options=["-initrd", cpio_file])
  36. self.emulator.login()
  37. video_file = "videotest.ogg"
  38. num_frames = 10
  39. msg_prefix = "Hello Buildroot:"
  40. # We check the main program can execute.
  41. self.assertRunOk("gst-launch-1.0 --version")
  42. # We check we can list installed plugins.
  43. self.assertRunOk("gst-inspect-1.0")
  44. # We check we can query one of the plugin we requested.
  45. self.assertRunOk("gst-inspect-1.0 theoraenc")
  46. # We create a Ogg/Theora video file. We use the "videotestsrc"
  47. # with the ball animation which will create a small file. We
  48. # add a time overlay with a message. We encode with the Theora
  49. # codec and store everything in an Ogg container file.
  50. enc_pipeline = \
  51. f"videotestsrc num-buffers={num_frames} pattern=ball ! " \
  52. f"timeoverlay text=\"{msg_prefix}\" font-desc=\"Sans, 24\" ! " \
  53. f"theoraenc ! oggmux ! filesink location={video_file}"
  54. cmd = f"gst-launch-1.0 -v {enc_pipeline}"
  55. self.assertRunOk(cmd, timeout=15)
  56. # We decode our previous video file and store each frame in a
  57. # PNG image file.
  58. dec_pipeline = \
  59. f"filesrc location={video_file} ! " \
  60. "decodebin ! videoconvert ! pngenc ! " \
  61. "multifilesink index=1 location=frame%02d.png"
  62. cmd = f"gst-launch-1.0 -v {dec_pipeline}"
  63. self.assertRunOk(cmd)
  64. # We extract the text from our last image.
  65. img_file = f"frame{num_frames}.png"
  66. cmd = f"tesseract {img_file} output"
  67. self.assertRunOk(cmd)
  68. # We check we have our initial message.
  69. out, ret = self.emulator.run("cat output.txt")
  70. self.assertEqual(ret, 0)
  71. self.assertTrue(out[0].startswith(msg_prefix))