cmusatyalab / openrtist

Live video frames from the camera are stylized to look like famous paintings.
Apache License 2.0
25 stars 20 forks source link

Fix GHC 9th floor screensaver demo #8

Closed junjuew closed 6 years ago

junjuew commented 6 years ago

To fix the 9th floor screensaver demo, following changes are implemented:

  1. In the new implementation, the openrtist client.py writes style-transferred image stream to a linux pipe. A screensaver script launches mpv to display images from the pipe. When the screensaver script is killed (due to user wake-up or switching among screensavers), mpv no longer reads from the pipe and the pipe becomes broken. client.py exits gracefully due to pipe broken error.
  2. stream_for_screensaver.py will re-launch client.py after it exits. client.py would wait for a pipe reader, before writing style-transferred stream into the pipe. Such exit-and-launch loop is used to make sure no single image is half written/read. Since we are not encoding the image, there is no way to know in the program if an image is half written/read.
  3. client.py used to have a queue without explicit capacity that holds the results that have not been displayed. This behavior goes against the intuition that we only care about the most recent frame. I've modified the queue to have a capacity of 1, so that undisplayed results will be overwritten once a new frame comes.
  4. It does not make sense to hard code the openrtist server ip into config.py. config.py should better be used for parameters that do not usually change. I moved the server ip into a cmd argument.
junjuew commented 6 years ago

The screensaver demo on 9th floor has been running smoothly without problem for a few days. I'm more confident about this pull request now.