diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2019-05-05 12:34:01 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2019-05-06 03:42:13 +0200 |
commit | 6eda8a85b84c4e661a8763429ae1978f8da7f9dd (patch) | |
tree | 5169e1bf6779f7442235f36a206a91e224cda05d /video-ps3eye/PS3EYEDriver/urb.hpp | |
parent | 12dfd6dcf60d9fefef7f8723fb9bc5a21fdb5b61 (diff) |
video/ps3eye: WIP
Diffstat (limited to 'video-ps3eye/PS3EYEDriver/urb.hpp')
-rw-r--r-- | video-ps3eye/PS3EYEDriver/urb.hpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/video-ps3eye/PS3EYEDriver/urb.hpp b/video-ps3eye/PS3EYEDriver/urb.hpp new file mode 100644 index 00000000..3bee3919 --- /dev/null +++ b/video-ps3eye/PS3EYEDriver/urb.hpp @@ -0,0 +1,63 @@ +#pragma once + +#include <memory> +#include <cstdint> +#include <mutex> + +struct FrameQueue; +struct libusb_device; +struct libusb_transfer; +struct libusb_device_handle; + +#ifdef _WIN32 +# define USB_CALLBACK __stdcall +#else +# define USB_CALLBACK +#endif + +struct URBDesc +{ + URBDesc() = default; + ~URBDesc(); + + bool start_transfers(libusb_device_handle *handle, uint32_t curr_frame_size); + void free_transfers(); + void close_transfers(); + + FrameQueue& queue() { return *frame_queue; } + +private: + enum { + TRANSFER_SIZE = 65536, + NUM_TRANSFERS = 5, + }; + + /* packet types when moving from iso buf to frame buf */ + enum gspca_packet_type { + DISCARD_PACKET, + FIRST_PACKET, + INTER_PACKET, + LAST_PACKET, + }; + + std::shared_ptr<FrameQueue> frame_queue; + std::mutex num_active_transfers_mutex; + std::condition_variable num_active_transfers_condition; + + gspca_packet_type last_packet_type = DISCARD_PACKET; + libusb_transfer* xfers[NUM_TRANSFERS] {}; + uint8_t* cur_frame_start = nullptr; + uint32_t cur_frame_data_len = 0; + uint32_t frame_size = 0; + uint32_t last_pts = 0; + uint16_t last_fid = 0; + uint8_t transfer_buffer[TRANSFER_SIZE * NUM_TRANSFERS]; + uint8_t num_active_transfers = 0; + bool teardown = false; + + int transfer_cancelled(); + void frame_add(enum gspca_packet_type packet_type, const uint8_t *data, int len); + void pkt_scan(uint8_t *data, int len); + static uint8_t find_ep(struct libusb_device *device); + static void USB_CALLBACK transfer_completed_callback(struct libusb_transfer *xfr); +}; |