Skip to content

Commit

Permalink
demo: support externally specified device
Browse files Browse the repository at this point in the history
Fix for intel#20

Default device is /dev/dri/renderD128. If other device is desired
user can run docker with '-e DEVICE=/dev/dri/XXX'.

Signed-off-by: Dmitry Rogozhkin <[email protected]>
  • Loading branch information
dvrogozh committed May 28, 2020
1 parent fd56bbf commit 3837130
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 12 deletions.
10 changes: 10 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ See `Content Attribution`_ for the copyright info for the above video. See
`Container volumes (adding your content, access logs, etc.) <doc/howto.rst#container-volumes-adding-your-content-access-logs-etc>`_
for how to add your own content to the demo.

If your system has multiple GPU devices, you can specify the one you want to
ren demo on with the ``DEVICE`` environment variable (default one is
``/dev/dri/renderD128``)::

docker run -it \
$(env | grep -E '_proxy=' | sed 's/^/-e /') \
-e DEVICE=${DEVICE:-/dev/dri/renderD128} \
--privileged --network=host \
intel-media-delivery demo streams

ffmpeg demo mode
~~~~~~~~~~~~~~~~

Expand Down
8 changes: 5 additions & 3 deletions assets/demo
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ function start_nginx() {
fi
}

nginx_opts="env DEVICE=${DEVICE}"

if tty -s; then
{
if [ $_exit -eq 1 ]; then
Expand All @@ -239,7 +241,7 @@ if tty -s; then
echo "select-layout tiled"
} >> /home/user/.tmux.conf

start_nginx
start_nginx -g "$nginx_opts;"
tmux attach
else
echo "note: not running under tty"
Expand All @@ -252,12 +254,12 @@ else
echo "note: starting up nginx server and specified client"
echo "note: full-scale demo mode requires access to terminal"
echo -ne "$goto_tty_note"
start_nginx
start_nginx -g "$nginx_opts;"
$client
else
echo "note: starting up nginx server"
echo "note: request streaming from host or other system in the network"
echo -ne "$goto_tty_note"
start_nginx -g "daemon off;"
start_nginx -g "daemon off; $nginx_opts;"
fi
fi
5 changes: 5 additions & 0 deletions assets/demo-setup
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

if [[ ! ( -n "$DEVICE" && "$DEVICE" =~ /dev/dri/ && -e $DEVICE ) ]]; then
echo "error: device not availabe: $DEVICE"
exit -1
fi

video_grps=($(ls -g /dev/dri/renderD* | awk '{print $3}' | uniq))

if [ ${#video_grps[@]} -eq 0 ]; then
Expand Down
8 changes: 7 additions & 1 deletion doc/man/demo.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ No interaction from host or other system is required. Example:
`-<n>` option is useful for demo purposes. With it solution pretends to have <n> copies of
each input stream. Execute 'demo -4 streams' to explore the difference.
OPTIONS
-------
--help::
Expand All @@ -57,6 +56,13 @@ help::
streams::
Print available streams
ENVIRONMENT VARIABLES
---------------------

DEVICE::
GPU device to run the demo on. Default device is '/dev/dri/renderD128'.
Can be overwritten by externally set environment variable.

SEE ALSO
--------
link:demo-ffmpeg.asciidoc[demo-ffmpeg]
Expand Down
4 changes: 4 additions & 0 deletions doc/man/demo.env.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ DEMO_STREAM_TYPES::
Colon separated streaming types supported by the demo, i.e. `<type>`
in the following address: `http://localhost:8080/vod/<type>/<stream>.index.m3u8`

DEVICE::
GPU device to run the demo on. Default device is '/dev/dri/renderD128'.
Can be overwritten by externally set environment variable.

SEE ALSO
--------
link:demo-bash.asciidoc[demo-bash]
Expand Down
7 changes: 4 additions & 3 deletions solutions/cdn/nginx-trigger-streaming.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ log() {
}

addlog "$0 $@: start"
addlog "$0 $@: DEVICE=${DEVICE}"

source /etc/demo.env

Expand Down Expand Up @@ -122,7 +123,7 @@ function run() {

if [ "$type" = "vod/avc" ]; then
cmd=(ffmpeg
-hwaccel qsv -hwaccel_device /dev/dri/renderD128
-hwaccel qsv -hwaccel_device $DEVICE
-c:v h264_qsv -re -i $to_play -c:a copy
-c:v h264_qsv -preset medium -profile:v high -b:v 3000000 -extbrc 1 -b_strategy 1 -bf 7 -refs 5 -vsync 0
-f hls -hls_time 10 -hls_playlist_type event
Expand All @@ -132,7 +133,7 @@ if [ "$type" = "vod/avc" ]; then
-var_stream_map 'v:0,a:0' stream_%v.m3u8)
elif [ "$type" = "vod/hevc" ]; then
cmd=(ffmpeg
-hwaccel qsv -hwaccel_device /dev/dri/renderD128
-hwaccel qsv -hwaccel_device $DEVICE
-c:v h264_qsv -re -i $to_play -c:a copy
-c:v hevc_qsv -preset medium -profile:v main -b:v 3000000 -extbrc 1 -refs 5 -vsync 0
-f hls -hls_time 10 -hls_playlist_type event
Expand All @@ -143,7 +144,7 @@ elif [ "$type" = "vod/hevc" ]; then
elif [ "$type" = "vod/abr" ]; then
# This is not tuned placeholder for ABR transcoding
cmd=(ffmpeg
-hwaccel qsv -hwaccel_device /dev/dri/renderD128
-hwaccel qsv -hwaccel_device $DEVICE
-c:v h264_qsv -re -i $to_play
-filter_complex '[v:0]split=2[o1][s2];[s2]scale_qsv=w=640:h=-1[o2]'
-map [o1] -c:v h264_qsv -b:v 5M
Expand Down
6 changes: 3 additions & 3 deletions solutions/cdn/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ http {
add_header Cache-Control no-cache;

rewrite_by_lua_block {
os.execute( "/usr/bin/bash -c \"source /etc/demo.env; nginx-trigger-streaming.sh " .. ngx.var.uri .. ";\"")
os.execute( "/usr/bin/bash -c \"source /etc/demo.env; export DEVICE=" .. os.getenv("DEVICE") .. "; nginx-trigger-streaming.sh " .. ngx.var.uri .. ";\"")
}
}

Expand All @@ -75,7 +75,7 @@ http {
add_header Cache-Control no-cache;

rewrite_by_lua_block {
os.execute( "/usr/bin/bash -c \"source /etc/demo.env; nginx-trigger-streaming.sh " .. ngx.var.uri .. ";\"")
os.execute( "/usr/bin/bash -c \"source /etc/demo.env; export DEVICE=" .. os.getenv("DEVICE") .. "; nginx-trigger-streaming.sh " .. ngx.var.uri .. ";\"")
}
}

Expand All @@ -87,7 +87,7 @@ http {
add_header Cache-Control no-cache;

rewrite_by_lua_block {
os.execute( "/usr/bin/bash -c \"source /etc/demo.env; nginx-trigger-streaming.sh " .. ngx.var.uri .. ";\"")
os.execute( "/usr/bin/bash -c \"source /etc/demo.env; export DEVICE=" .. os.getenv("DEVICE") .. "; nginx-trigger-streaming.sh " .. ngx.var.uri .. ";\"")
}
}
}
Expand Down
1 change: 1 addition & 0 deletions solutions/cdn/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,5 @@ done
echo "export PYTHONUSERBASE=\$DEMO_PREFIX"
echo "export MANPATH=\$DEMO_PREFIX/share/man:\$MANPATH"
echo "export LIBVA_DRIVER_NAME=iHD"
echo "export DEVICE=\${DEVICE:-/dev/dri/renderD128}"
} > /etc/demo.env
3 changes: 2 additions & 1 deletion solutions/edge/nginx-trigger-streaming.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ log() {
}

addlog "$0 $@: start"
addlog "$0 $@: DEVICE=$DEVICE"

source /etc/demo.env

Expand Down Expand Up @@ -119,7 +120,7 @@ function run() {

if [ "$type" = "vod/avc" ]; then
cmd=(ffmpeg
-hwaccel qsv -hwaccel_device /dev/dri/renderD128
-hwaccel qsv -hwaccel_device $DEVICE
-c:v h264_qsv -re -i $to_play
-c:v h264_qsv -preset medium -profile:v high -b:v 3000000 -extbrc 1 -b_strategy 1 -bf 7 -refs 5 -vsync 0
-c:a copy -f flv rtmp://localhost:1935/$type/$stream)
Expand Down
2 changes: 1 addition & 1 deletion solutions/edge/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ http {
add_header Cache-Control no-cache;

rewrite_by_lua_block {
os.execute( "/usr/bin/bash -c \"source /etc/demo.env; nginx-trigger-streaming.sh " .. ngx.var.uri .. ";\"")
os.execute( "/usr/bin/bash -c \"source /etc/demo.env; export DEVICE=" .. os.getenv("DEVICE") .. "; nginx-trigger-streaming.sh " .. ngx.var.uri .. ";\"")
}
}

Expand Down
1 change: 1 addition & 0 deletions solutions/edge/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ done
echo "export PYTHONUSERBASE=\$DEMO_PREFIX"
echo "export MANPATH=\$DEMO_PREFIX/share/man:\$MANPATH"
echo "export LIBVA_DRIVER_NAME=iHD"
echo "export DEVICE=\${DEVICE:-/dev/dri/renderD128}"
} > /etc/demo.env
6 changes: 6 additions & 0 deletions tests/demo.bats
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ load utils
[ $status -eq 255 ]
}

@test "demo no such device" {
run docker_run_opts "-e DEVICE=/dev/dri/nodevice" whoami
print_output
[ $status -eq 255 ]
}

#################
# demo help tests
#################
Expand Down

0 comments on commit 3837130

Please sign in to comment.