add missing GPL information in guicast program files
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / avc1394control.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 // Based off of the dvcont test app included with libavc1394.
23 // (Originally written by Jason Howard [And based off of gscanbus],
24 // adapted to libavc1394 by Dan Dennedy <dan@dennedy.org>. Released under
25 // the GPL.)
26
27 #ifdef HAVE_FIREWIRE
28 #include "avc1394control.h"
29 #include "mutex.h"
30 #include "transportque.inc"
31
32 AVC1394Control::AVC1394Control()
33 {
34         initialize();
35 }
36
37 void AVC1394Control::initialize()
38 {
39         int i;
40
41         current_command = COMMAND_NONE;
42         device = -1;
43
44         device_lock = new Mutex("AVC1394Control::device_lock");
45
46 #ifdef RAW1394_V_0_8
47         handle = raw1394_get_handle();
48 #else
49         handle = raw1394_new_handle();
50 #endif
51 //printf("AVC1394Control::initialize(): 1\n");
52         if(!handle)
53         {
54 //printf("AVC1394Control::initialize(): 2\n");
55                 if(!errno)
56                 {
57 //printf("AVC1394Control::initialize(): 3\n");
58                         fprintf(stderr, "AVC1394Control::initialize(): Not Compatable!\n");
59                 }
60                 else
61                 {
62 //printf("AVC1394Control::initialize(): 4\n");
63                         fprintf(stderr, "AVC1394Control::initialize(): couldn't get handle\n");
64                 }
65                 return;
66         }
67
68         if(raw1394_set_port(handle, 0) < 0) {
69 //printf("AVC1394Control::initialize(): 5\n");
70                 perror("AVC1394Control::initialize(): couldn't set port");
71 //              raw1394_destroy_handle(handle);
72                 return;
73         }
74
75         for(i = 0; i < raw1394_get_nodecount(handle); i++)
76         {
77                 if(rom1394_get_directory(handle, i, &rom_dir) < 0)
78                 {
79 //printf("AVC1394Control::initialize(): 6\n");
80                         fprintf(stderr, "AVC1394Control::initialize(): node %d\n", i);
81 //                      raw1394_destroy_handle(handle);
82                         return;
83                 }
84
85                 if((rom1394_get_node_type(&rom_dir) == ROM1394_NODE_TYPE_AVC) &&
86                         avc1394_check_subunit_type(handle, i, AVC1394_SUBUNIT_TYPE_VCR))
87                 {
88 //printf("AVC1394Control::initialize(): 7\n");
89                         device = i;
90                         break;
91                 }
92         }
93
94         if(device == -1)
95         {
96 //printf("AVC1394Control::initialize(): 8\n");
97                 fprintf(stderr, "AVC1394Control::initialize(): No AV/C Devices\n");
98 //              raw1394_destroy_handle(handle);
99                 return;
100         }
101
102 }
103
104 AVC1394Control::~AVC1394Control()
105 {
106         if(handle) raw1394_destroy_handle(handle);
107
108         if(device_lock) delete device_lock;
109
110 }
111
112 void AVC1394Control::play()
113 {
114 //printf("AVC1394Control::play(): 1\n");
115         device_lock->lock("AVC1394Control::play");
116         avc1394_vcr_play(handle, device);
117         device_lock->unlock();
118 }
119
120 void AVC1394Control::stop()
121 {
122 //printf("AVC1394Control::stop(): 1\n");
123         device_lock->lock("AVC1394Control::stop");
124         avc1394_vcr_stop(handle, device);
125         device_lock->unlock();
126 }
127
128 void AVC1394Control::reverse()
129 {
130 //printf("AVC1394Control::reverse(): 1\n");
131         device_lock->lock("AVC1394Control::reverse");
132         avc1394_vcr_reverse(handle, device);
133         device_lock->unlock();
134 }
135
136 void AVC1394Control::rewind()
137 {
138 //printf("AVC1394Control::rewind(): 1\n");
139         device_lock->lock("AVC1394Control::rewind");
140         avc1394_vcr_rewind(handle, device);
141         device_lock->unlock();
142 }
143
144 void AVC1394Control::fforward()
145 {
146 //printf("AVC1394Control::fforward(): 1\n");
147         device_lock->lock("AVC1394Control::fforward");
148         avc1394_vcr_forward(handle, device);
149         device_lock->unlock();
150 }
151
152 void AVC1394Control::pause()
153 {
154 //printf("AVC1394Control::pause(): 1\n");
155         device_lock->lock("AVC1394Control::pause");
156         avc1394_vcr_pause(handle, device);
157         device_lock->unlock();
158 }
159
160 void AVC1394Control::record()
161 {
162 //printf("AVC1394Control::record(): 1\n");
163         device_lock->lock("AVC1394Control::record");
164         avc1394_vcr_record(handle, device);
165         device_lock->unlock();
166 }
167
168 void AVC1394Control::eject()
169 {
170 //printf("AVC1394Control::eject(): 1\n");
171         device_lock->lock("AVC1394Control::eject");
172         avc1394_vcr_eject(handle, device);
173         device_lock->unlock();
174 }
175
176 void AVC1394Control::get_status()
177 {
178 //printf("AVC1394Control::get_status(): 1\n");
179         device_lock->lock("Control::get_status");
180         status = avc1394_vcr_status(handle, device);
181         device_lock->unlock();
182 //      printf("Status: %s\n", avc1394_vcr_decode_status(status));
183 }
184
185 char *AVC1394Control::timecode()
186 {
187         device_lock->lock("AVC1394Control::timecode");
188         avc1394_vcr_get_timecode2(handle, device, text_return);
189         device_lock->unlock();
190         return text_return;
191 }
192
193 void AVC1394Control::seek(const char *time)
194 {
195 //printf("AVC1394Control::seek(): 1\n");
196         device_lock->lock("AVC1394Control::seek");
197         // Cast to work around missing const for avc1394_vcr_seek_timecode() in
198         // system header <libavc1394/avc1394_vcr.h>
199         avc1394_vcr_seek_timecode(handle, device, const_cast<char*>(time));
200         device_lock->unlock();
201 }
202 #endif