r1014: Enable horizontal scrolling with the mouse wheel by pressing Ctrl.
[cinelerra_cv/ct.git] / cinelerra / avc1394control.C
blobfc508e2ef0489f5a27de76ea3c91e973a3a6a30f
1 // Based off of the dvcont test app included with libavc1394.
2 // (Originally written by Jason Howard [And based off of gscanbus],
3 // adapted to libavc1394 by Dan Dennedy <dan@dennedy.org>. Released under
4 // the GPL.)
6 #include "avc1394control.h"
7 #include "mutex.h"
8 #include "transportque.inc"
10 AVC1394Control::AVC1394Control()
12         initialize();
15 void AVC1394Control::initialize()
17         int i;
19         current_command = COMMAND_NONE;
20         device = -1;
22         device_lock = new Mutex("AVC1394Control::device_lock");
24 #ifdef RAW1394_V_0_8
25         handle = raw1394_get_handle();
26 #else
27         handle = raw1394_new_handle();
28 #endif
29 //printf("AVC1394Control::initialize(): 1\n");
30         if(!handle)
31         {
32 //printf("AVC1394Control::initialize(): 2\n");
33                 if(!errno)
34                 {
35 //printf("AVC1394Control::initialize(): 3\n");
36                         fprintf(stderr, "AVC1394Control::initialize(): Not Compatable!\n");
37                 } 
38                 else 
39                 {
40 //printf("AVC1394Control::initialize(): 4\n");
41                         fprintf(stderr, "AVC1394Control::initialize(): couldn't get handle\n");
42                 }
43                 return;
44         }
46         if(raw1394_set_port(handle, 0) < 0) {
47 //printf("AVC1394Control::initialize(): 5\n");
48                 perror("AVC1394Control::initialize(): couldn't set port");
49 //              raw1394_destroy_handle(handle);
50                 return;
51         }
53         for(i = 0; i < raw1394_get_nodecount(handle); i++)
54         {
55                 if(rom1394_get_directory(handle, i, &rom_dir) < 0)
56                 {
57 //printf("AVC1394Control::initialize(): 6\n");
58                         fprintf(stderr, "AVC1394Control::initialize(): node %d\n", i);
59 //                      raw1394_destroy_handle(handle);
60                         return;
61                 }
62                 
63                 if((rom1394_get_node_type(&rom_dir) == ROM1394_NODE_TYPE_AVC) &&
64                         avc1394_check_subunit_type(handle, i, AVC1394_SUBUNIT_TYPE_VCR))
65                 {
66 //printf("AVC1394Control::initialize(): 7\n");
67                         device = i;
68                         break;
69                 }
70         }
72         if(device == -1)
73         {
74 //printf("AVC1394Control::initialize(): 8\n");
75                 fprintf(stderr, "AVC1394Control::initialize(): No AV/C Devices\n");
76 //              raw1394_destroy_handle(handle);
77                 return;
78         }
82 AVC1394Control::~AVC1394Control()
84         if(handle) raw1394_destroy_handle(handle);
86         if(device_lock) delete device_lock;
90 void AVC1394Control::play()
92 //printf("AVC1394Control::play(): 1\n");
93         device_lock->lock("AVC1394Control::play");
94         avc1394_vcr_play(handle, device);
95         device_lock->unlock();
98 void AVC1394Control::stop()
100 //printf("AVC1394Control::stop(): 1\n");
101         device_lock->lock("AVC1394Control::stop");
102         avc1394_vcr_stop(handle, device);
103         device_lock->unlock();
106 void AVC1394Control::reverse()
108 //printf("AVC1394Control::reverse(): 1\n");
109         device_lock->lock("AVC1394Control::reverse");
110         avc1394_vcr_reverse(handle, device);
111         device_lock->unlock();
114 void AVC1394Control::rewind()
116 //printf("AVC1394Control::rewind(): 1\n");
117         device_lock->lock("AVC1394Control::rewind");
118         avc1394_vcr_rewind(handle, device);
119         device_lock->unlock();
122 void AVC1394Control::fforward()
124 //printf("AVC1394Control::fforward(): 1\n");
125         device_lock->lock("AVC1394Control::fforward");
126         avc1394_vcr_forward(handle, device);
127         device_lock->unlock();
130 void AVC1394Control::pause()
132 //printf("AVC1394Control::pause(): 1\n");
133         device_lock->lock("AVC1394Control::pause");
134         avc1394_vcr_pause(handle, device);
135         device_lock->unlock();
138 void AVC1394Control::record()
140 //printf("AVC1394Control::record(): 1\n");
141         device_lock->lock("AVC1394Control::record");
142         avc1394_vcr_record(handle, device);
143         device_lock->unlock();
146 void AVC1394Control::eject()
148 //printf("AVC1394Control::eject(): 1\n");
149         device_lock->lock("AVC1394Control::eject");
150         avc1394_vcr_eject(handle, device);
151         device_lock->unlock();
154 void AVC1394Control::get_status()
156 //printf("AVC1394Control::get_status(): 1\n");
157         device_lock->lock("Control::get_status");
158         status = avc1394_vcr_status(handle, device);
159         device_lock->unlock();
160 //      printf("Status: %s\n", avc1394_vcr_decode_status(status));
163 char *AVC1394Control::timecode()
165         device_lock->lock("AVC1394Control::timecode");
166         avc1394_vcr_get_timecode2(handle, device, text_return);
167         device_lock->unlock();
168         return text_return;
171 void AVC1394Control::seek(char *time)
173 //printf("AVC1394Control::seek(): 1\n");
174         device_lock->lock("AVC1394Control::seek");
175         avc1394_vcr_seek_timecode(handle, device, time);
176         device_lock->unlock();