r286: Heroine Virutal's official release 1.2.0
[cinelerra_cv/ct.git] / hvirtual / cinelerra / avc1394control.C
blob1258829a3082318b78d9a40e6a67793519741a13
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;
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();
94         avc1394_vcr_play(handle, device);
95         device_lock->unlock();
98 void AVC1394Control::stop()
100 //printf("AVC1394Control::stop(): 1\n");
101         device_lock->lock();
102         avc1394_vcr_stop(handle, device);
103         device_lock->unlock();
106 void AVC1394Control::reverse()
108 //printf("AVC1394Control::reverse(): 1\n");
109         device_lock->lock();
110         avc1394_vcr_reverse(handle, device);
111         device_lock->unlock();
114 void AVC1394Control::rewind()
116 //printf("AVC1394Control::rewind(): 1\n");
117         device_lock->lock();
118         avc1394_vcr_rewind(handle, device);
119         device_lock->unlock();
122 void AVC1394Control::fforward()
124 //printf("AVC1394Control::fforward(): 1\n");
125         device_lock->lock();
126         avc1394_vcr_forward(handle, device);
127         device_lock->unlock();
130 void AVC1394Control::pause()
132 //printf("AVC1394Control::pause(): 1\n");
133         device_lock->lock();
134         avc1394_vcr_pause(handle, device);
135         device_lock->unlock();
138 void AVC1394Control::record()
140 //printf("AVC1394Control::record(): 1\n");
141         device_lock->lock();
142         avc1394_vcr_record(handle, device);
143         device_lock->unlock();
146 void AVC1394Control::eject()
148 //printf("AVC1394Control::eject(): 1\n");
149         device_lock->lock();
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();
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 //printf("AVC1394Control::timecode(): 1\n");
166         char *text;
167         text = (char *) malloc(12);
168         device_lock->lock();
169         text = avc1394_vcr_get_timecode(handle, device);
170         device_lock->unlock();
171         return text;
174 void AVC1394Control::seek(char *time)
176 //printf("AVC1394Control::seek(): 1\n");
177         device_lock->lock();
178         avc1394_vcr_seek_timecode(handle, device, time);
179         device_lock->unlock();