Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Livestream 'lockup' with slow computer #21

Open
mungewell opened this issue Mar 23, 2016 · 3 comments
Open

Livestream 'lockup' with slow computer #21

mungewell opened this issue Mar 23, 2016 · 3 comments
Assignees

Comments

@mungewell
Copy link
Contributor

I am seeing a problem when running on a slow computer (namely a Raspberry Pi), it seems that the image decode is not faster enough and at some point lags so far behind that the camera gives up - closing the connection and leaving the app hanging.

Looking at profiling the code it seems that there is just 1 call to liburl2 which returns a pointer to a 'never ending bowl' from which we read the image frames from in turn.
screenshot_2016-03-23_00-13-54

There is a time stamp in the common header, and mention in the API that:

The client may not display all the JPEG because of the decoding time. In that case, the
client should skip some JPEG images.

I think this is the solution, but can't quite understand (it's late night here :-) how to evaluate the frame rate/time stamp to decide we're running too far behind. The solution will probably fit here:

    if common['payload_type']==1:
       payload = payload_header(data)
+      if payload['timestamp"] : #??? not sure how to eval "much too late"
+         # running too slow, skip displaying this frame
+         read(payload['jpeg_data_size'] + payload['padding_size'])
+         continue
       image_file = io.BytesIO(incoming.read(payload['jpeg_data_size']))
       incoming_image = pygame.image.load(image_file).convert()
       if options.zoom:
          incoming_image = pygame.transform.scale(incoming_image, \
             (infoObject.current_w, infoObject.current_h))
       incoming.read(payload['padding_size'])
@Bloodevil Bloodevil self-assigned this Mar 23, 2016
@mungewell
Copy link
Contributor Author

Had a little more of a think about this over my lunch hour;
KAPP9.PDF

Problem with RaspPi (running pygameLiveView) is primarily that the 'receive' is held up by the 'decode/display' resulting in an ever increasing queue of frames in the pipe. There is also the issue of delay in TCP/IP pipeline, but that should be comparatively small.
We could compare rolling average fps (last 'x' frames) for 'capture' vs 'display', and skip if we're ever slower. This probably wouldn't recover any lag after it had been introduced.

@mungewell
Copy link
Contributor Author

Seems to be working now...
https://www.youtube.com/edit?o=U&video_id=xR3gAfu4Hfw

@krisrok
Copy link

krisrok commented May 22, 2016

man you need to learn how to put links on the interwebs :D

your youtube link links to some 404 github url and the link's text is the non-public url to the video. it should read instead https://www.youtube.com/watch?v=xR3gAfu4Hfw

also on your youtube video the links back to your forked repo is cut off and is another github 404. https://github.com/mungewell/sony_camera_api would be the right one.

link issues aside i'm glad you've managed to get a smooth live stream working as i'm working on something similar :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants