Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / shudmp.C
1 /*
2  * This program is free software; you can redistribute it and/or modify it
3  * under the terms of the GNU General Public License as published
4  * by the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful, but
8  * WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10  * General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public
13  * License along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
15  * USA
16  */
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <fcntl.h>
22 #include <error.h>
23 #include <signal.h>
24
25 #include <libusb-1.0/libusb.h>
26
27 #define SHUTTLE_INTERFACE 0
28
29 libusb_device_handle *devsh = 0;
30 int claimed = -1;
31
32 void usb_done()
33 {
34         if( devsh ) {
35                 if( claimed > 0 ) {
36                         int sh_iface = SHUTTLE_INTERFACE;
37                         libusb_release_interface(devsh, sh_iface);
38                         libusb_attach_kernel_driver(devsh, sh_iface);
39                         claimed = 0;
40                 }
41                 libusb_close(devsh);
42                 devsh = 0;
43         }
44         if( claimed >= 0 ) {
45                 libusb_exit(0);
46                 claimed = -1;
47         }
48 }
49
50 void usb_probe()
51 {
52         int ret = libusb_init(0);
53         if( ret < 0 ) return;
54         claimed = 0;
55         devsh = libusb_open_device_with_vid_pid(0, 0x0b33, 0x0030);
56         if( devsh ) {
57                 int sh_iface = SHUTTLE_INTERFACE;
58                 libusb_detach_kernel_driver(devsh, sh_iface);
59                 ret = libusb_claim_interface(devsh, sh_iface);
60                 if( ret >= 0 ) claimed = 1;
61         }
62         if( !claimed )
63                 usb_done();
64 }
65
66 int done = 0;
67 void sigint(int n) { done = 1; }
68
69 int main(int ac, char **av)
70 {
71         setbuf(stdout, 0);
72         usb_probe();
73         if( claimed > 0 ) {
74                 signal(SIGINT, sigint);
75                 while( !done ) {
76                         int len = 0;
77                         static const int IN_ENDPOINT = 0x81;
78                         unsigned char dat[5];
79                         int ret = libusb_interrupt_transfer(devsh,
80                                         IN_ENDPOINT, dat, sizeof(dat), &len, 100);
81                         if( ret != 0 ) {
82                                 if( ret == LIBUSB_ERROR_TIMEOUT ) continue;
83                                 printf("error: %s\n", libusb_strerror((libusb_error)ret));
84                                 sleep(1);  continue;
85                         }
86                         printf("shuttle: ");
87                         for( int i=0; i<len; ++i ) printf(" %02x", dat[i]);
88                         printf("\n");
89                 }
90         }
91         usb_done();
92         return 0;
93 }
94