Skip to content
This repository was archived by the owner on May 3, 2021. It is now read-only.

Optimization from @rovarma#1

Open
cboulay wants to merge 24 commits into
psmoveservice:masterfrom
rovarma:optimization
Open

Optimization from @rovarma#1
cboulay wants to merge 24 commits into
psmoveservice:masterfrom
rovarma:optimization

Conversation

@cboulay

@cboulay cboulay commented Jan 23, 2016

Copy link
Copy Markdown
Collaborator

No description provided.

thp and others added 24 commits January 10, 2014 20:55
Fixed compilation with MiNGW64.
Created set_parameters function in ps3eyedriver to expose set_<parm>
Fixes for GCC (homebrew and mingw).

Fixes for GCC (homebrew and mingw).

Fixes an issue in Win 8.1 where PS3Eye shows up as two devices, presumably camera and microphone. Microphone cannot be opened with libusb so check for lack of err in opening device.

Fix debug macro. Add debug target to sdl example.

SDL example closes camera when quiting.

Added Green balance.

Exposed paramter getters through ps3eyedriver
…ndle_events_timeout_completed with a 50ms timeout. Internally libusb_handle_events calls libusb_handle_events_timeout_completed with a 60sec timeout. On rare occasions lib usb on Windows can stall waiting for an event to complete, resulting in a 60sec wait before the video stream recovers. Realistically, 50ms is more than long enough to wait.
Switch usb event polling from using libusb_handle_events to libusb_ha…
…and to timeEndPeriod(1) at PS3EYECam::stop(). I hope this improves PS3EYEDriver->libusb performance in Windows.
Added windows-only calls to timeBeginPeriod(1) at PS3EYECam::start() …
Added windows-only calls to timeBeginPeriod(1) at PS3EYECam::start() …
Increase timer resolution in Windows so libusb calls can return faster.
Conflicts:
	sdl/main.cpp
	src/ps3eye.cpp
	src/ps3eye.h
…latform-specific primites; Win32 API on windows, pthreads for everything else.

Optimized PS3EyeDriver performance
   - Increased the number of concurrent USB transfers active from 2 to 8. I've tested this on three different machines (low, medium, high spec), and this seems to hit the sweet spot for raw USB performance (max throughput)
   - Removed timeBeginPeriod/timeEndPeriod calls (they were not needed)
   - Each camera now gets its own libusb_context. This is needed to make sure that libusb_handle_event calls will only affect a single device.
   - Each camera is now updated in its own thread (libusb_handle_event); clients no longer need to call handleEvents (it has been removed)
   - There is now a per-camera frame queue. Internally it's implemented as a ring buffer; the camera update thread (producer) writes to *head*, the client (consumer) reads from *tail*. If no data is available, the consumer will block and if the buffer is full, the producer (camera update thread) will block.

API changes
   - PS3EYECam::isNewFrame() has been removed
   - PS3EYECam::getLastFramePointer has been renamed to PS3EYECam::getFrame. This function blocks if no frame is available and now returns a malloc'd copy of the frame; the client is responsible for free'ing the buffer when done with it.
   - PS3EYECam::getDevices has been removed; use PS3EYECam::getDeviceCount and PS3EYECam::createDevice instead

PS3EYEDriver C-wrapper changes (PS3EyeDriver.cpp)
   - Removed the yuv buffer management; there is no longer a need for it since the ps3eye driver now always returns a single frame
   - yuv422_buffer_t is now a simple wrapper around the buffer returned by  PS3EYECam::getFrame. It's purely responsible for making sure the frame is free'd when it's no longer needed

With this, it's now possible to update the PS3Eye at 60 FPS, independent of the number of cameras in the system. The only limiting factor should be how fast your client is; if it can't handle 60 FPS, the camera/usb performance will also degrade.
…s full; if the buffer is full it will wait a max of 1 seconds for a slot to become available, after which it will overwrite the last frame. This is to prevent deadlocks/stalls when the consumer is not calling Frame::Dequeue (because it's setting camera parameters, for example), but IS caling (sync) libusb functions
…YECam::init()

- Default size of the frame queue is now 2 (instead of 16) to increase responsiveness
- FrameQueue::Enqueue will no longer block if there is no room in the buffer (instead will overwrite the previous frame). This allows the service to degrade gracefully: if the consumer is not fast enough (< Camera FPS), it will miss frames, but if it is fast enough (>= Camera FPS), it will see everything.
cboulay pushed a commit that referenced this pull request Jul 3, 2016
Changes to support building opencv test project in OS X.
@rovarma rovarma deleted the optimization branch July 9, 2016 11:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants