Skip to content

Commit

Permalink
Working with mmalvideosink
Browse files Browse the repository at this point in the history
  • Loading branch information
reinzor committed Feb 15, 2019
1 parent 489d76d commit ff317f4
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 49 deletions.
6 changes: 0 additions & 6 deletions cfg/rpi/etc/systemd/system/[email protected]/override.conf

This file was deleted.

45 changes: 45 additions & 0 deletions install.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash

# Install system dependencies
sudo apt-get -y update
sudo apt-get -y install git \
libgstreamer-plugins-base1.0-dev \
gstreamer1.0-plugins-base-apps \
gstreamer1.0-tools \
gstreamer1.0-plugins-good \
gstreamer1.0-plugins-bad \
python-pip

# Install python dependencies
sudo -H pip install -r requirements.txt

# Build & Install Gstreamer MMAL
git clone https://github.com/reinzor/gst-mmal /tmp/gst-mmal
cd /tmp/gst-mmal
LDFLAGS='-L/opt/vc/lib' CPPFLAGS='-I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux' ./autogen.sh --disable-gtk-doc
make
sudo make install

# Build & Install Gstreamer OMX
git clone https://github.com/reinzor/gst-omx /tmp/gst-omx
cd /tmp/gst-omx
git checkout 1.10.4
LDFLAGS='-L/opt/vc/lib' CFLAGS='-I/opt/vc/include -I/opt/vc/include/IL -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/IL' CPPFLAGS='-I/opt/vc/include -I/opt/vc/include/IL -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/IL' ./autogen.sh --disable-gtk-doc --with-omx-target=rpi
make
sudo make install

# Create videos folder and download sample video
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
wget https://github.com/reinzor/videowall/releases/download/0/big_buck_bunny_720p_30mb.mp4 -O $SCRIPT_DIR/videos/videos/big_buck_bunny_720p_30mb.mp4

# Setup paths in bashrc
echo "source $SCRIPT_DIR/setup.bash" >> ~/.bashrc

# Show installation done message
echo "======="
echo ""
echo "Installation complete, please source your ~/.bashrc and type the following command:"
echo ""
echo " gst-launch-1.0 -v filesrc location=$SCRIPT_DIR/videos/big_buck_bunny_720p_30mb.mp4 ! qtdemux ! h264parse ! omxh264dec ! videocrop bottom=10 ! mmalvideosink"
echo ""
echo "======"
3 changes: 2 additions & 1 deletion scripts/client
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
import argparse
import logging
import os
from argparse import ArgumentParser

from videowall.client import Client
Expand All @@ -11,7 +12,7 @@ if __name__ == '__main__':
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('player_platform', choices=get_player_platform_strings())
parser.add_argument('ifname', choices=get_ifnames())
parser.add_argument('--media_path', default='~/Videos')
parser.add_argument('--media_path', default=os.path.join(os.path.dirname(os.path.realpath(__file__)), "../videos"))
parser.add_argument('--verbose', action='store_true')
parser.add_argument('--server_broadcast_port', type=validate_positive_int_argument, default=2000)
parser.add_argument('--server_play_broadcast_port', type=validate_positive_int_argument, default=2001)
Expand Down
3 changes: 1 addition & 2 deletions setup.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export PYTHONPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"/src
export DISPLAY=:0
export GST_DEBUG=1

export GST_PLUGIN_PATH=/usr/local/lib/gstreamer-1.0:/usr/lib/arm-linux-gnueabihf/gstreamer-1.0
8 changes: 2 additions & 6 deletions src/videowall/gi_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
gi.require_version('GLib', '2.0')
gi.require_version('Gst', '1.0')
gi.require_version('GstNet', '1.0')
gi.require_version('Gdk', '3.0')
gi.require_version('Gtk', '3.0')
gi.require_version('GstVideo', '1.0')

from gi.repository import GLib, Gst, GstNet, GObject, Gdk, Gtk
from gi.repository import GdkX11, GstVideo # For window.get_xid(), xvimagesink.set_window_handle()
from gi.repository import GLib, Gst, GstNet, GObject

_ = Gst, GstNet, GObject, GLib, Gdk, Gtk, GdkX11, GstVideo
_ = Gst, GstNet, GObject, GLib
43 changes: 9 additions & 34 deletions src/videowall/player/player_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import threading
import time

from videowall.gi_version import GstNet, Gst, Gdk, Gtk
from videowall.gi_version import GstNet, Gst, GObject
from videowall.util import validate_ip_port

from .player_exceptions import PlayerException
Expand All @@ -23,18 +23,6 @@ def __init__(self, platform, clock_ip, clock_port, use_local_clock=False):
if not issubclass(platform, PlayerPlatform):
raise PlayerException("Invalid player platform {}, available platforms: {}".format(platform,
get_player_platforms()))
# Set-up window
screen = Gdk.Screen.get_default()
self._screen_width = screen.get_width()
self._screen_height = screen.get_height()
self._window = Gtk.Window(Gtk.WindowType.TOPLEVEL)
self._window.set_title("PlayerClient")
self._window.set_default_size(self._screen_width, self._screen_height)
self._window.fullscreen()
self._movie_view = Gtk.DrawingArea()
self._window.add(self._movie_view)
self._window.show_all()

self._use_local_clock = use_local_clock

if not self._use_local_clock:
Expand All @@ -51,22 +39,18 @@ def __init__(self, platform, clock_ip, clock_port, use_local_clock=False):
self._pipeline = None

def run_player_thread():
Gtk.main()
GObject.MainLoop().run()

self._gobject_thread = threading.Thread(target=run_player_thread)
self._gobject_thread.start()

self._platform = platform

logger.info("Player constructed for window (%dx%d) and clock server (%s:%d)", self._screen_width,
self._screen_height, clock_ip, clock_port)
logger.info("Player constructed (platform=%s, clock_ip=%s, clock_port=%s, use_local_clock=%s)", platform, clock_ip, clock_port, use_local_clock)

def _construct_pipeline(self, filename, videocrop_config, text_overlay, time_overlay):
real_path = os.path.realpath(os.path.expanduser(filename))

if os.environ.get('DISPLAY') is None:
raise PlayerException("No $DISPLAY environment variable is set, the ximagesink will not work")

launch_cmd = ""
if os.path.isfile(real_path):
launch_cmd += "filesrc location={}".format(real_path)
Expand Down Expand Up @@ -96,32 +80,23 @@ def _construct_pipeline(self, filename, videocrop_config, text_overlay, time_ove
launch_cmd += ' ! textoverlay text="{}\n{}"'.format("%s not found" % filename, text_overlay)
launch_cmd += " ! videoconvert"

launch_cmd += " ! videoscale add-borders=false ! video/x-raw,width=%d,height=%d" % (self._screen_width, self._screen_height)
launch_cmd += " ! ximagesink" # or ! fakesink sync=true # sync required for realtime playback
if self._platform == PlayerPlatformPC:
launch_cmd += " ! ximagesink" # or ! fakesink sync=true # sync required for realtime playback
else:
launch_cmd += " ! mmalvideosink"

logger.debug("gst-launch-1.0 -v %s", launch_cmd)
self._pipeline = Gst.parse_launch(launch_cmd)

self._pipeline.get_bus().enable_sync_message_emission()
self._pipeline.get_bus().add_signal_watch()

self._pipeline.get_bus().connect('sync-message::element', self._on_bus_sync_msg)

def _destroy_pipeline(self):
if self._pipeline is not None:
self._pipeline.set_state(Gst.State.NULL)
self._pipeline = None

def _on_bus_sync_msg(self, bus, msg):
if msg is not None:
sink = msg.src
sink.set_property("force-aspect-ratio", True)
sink.set_window_handle(self._movie_view.get_property('window').get_xid())

def close(self):
self.stop()
Gtk.main_quit()
logger.info("Waiting for the GTK Thread to join ..")
GObject.MainLoop().quit()
logger.info("Waiting for the GObject Thread to join ..")
self._gobject_thread.join()

def play(self, filename, base_time_nsecs, videocrop_config, text_overlay, time_overlay):
Expand Down
1 change: 1 addition & 0 deletions videos/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*

0 comments on commit ff317f4

Please sign in to comment.