centos build workarounds
[goodguy/history.git] / cinelerra-5.0 / 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 #include "avc1394control.h"
28 #include "mutex.h"
29 #include "transportque.inc"
30
31 AVC1394Control::AVC1394Control()
32 {
33         initialize();
34 }
35
36 void AVC1394Control::initialize()
37 {
38         int i;
39
40         current_command = COMMAND_NONE;
41         device = -1;
42
43         device_lock = new Mutex("AVC1394Control::device_lock");
44
45 #ifdef RAW1394_V_0_8
46         handle = raw1394_get_handle();
47 #else
48         handle = raw1394_new_handle();
49 #endif
50 //printf("AVC1394Control::initialize(): 1\n");
51         if(!handle)
52         {
53 //printf("AVC1394Control::initialize(): 2\n");
54                 if(!errno)
55                 {
56 //printf("AVC1394Control::initialize(): 3\n");
57                         fprintf(stderr, "AVC1394Control::initialize(): Not Compatable!\n");
58                 } 
59                 else 
60                 {
61 //printf("AVC1394Control::initialize(): 4\n");
62                         fprintf(stderr, "AVC1394Control::initialize(): couldn't get handle\n");
63                 }
64                 return;
65         }
66
67         if(raw1394_set_port(handle, 0) < 0) {
68 //printf("AVC1394Control::initialize(): 5\n");
69                 perror("AVC1394Control::initialize(): couldn't set port");
70 //              raw1394_destroy_handle(handle);
71                 return;
72         }
73
74         for(i = 0; i < raw1394_get_nodecount(handle); i++)
75         {
76                 if(rom1394_get_directory(handle, i, &rom_dir) < 0)
77                 {
78 //printf("AVC1394Control::initialize(): 6\n");
79                         fprintf(stderr, "AVC1394Control::initialize(): node %d\n", i);
80 //                      raw1394_destroy_handle(handle);
81                         return;
82                 }
83                 
84                 if((rom1394_get_node_type(&rom_dir) == ROM1394_NODE_TYPE_AVC) &&
85                         avc1394_check_subunit_type(handle, i, AVC1394_SUBUNIT_TYPE_VCR))
86                 {
87 //printf("AVC1394Control::initialize(): 7\n");
88                         device = i;
89                         break;
90                 }
91         }
92
93         if(device == -1)
94         {
95 //printf("AVC1394Control::initialize(): 8\n");
96                 fprintf(stderr, "AVC1394Control::initialize(): No AV/C Devices\n");
97 //              raw1394_destroy_handle(handle);
98                 return;
99         }
100
101 }
102
103 AVC1394Control::~AVC1394Control()
104 {
105         if(handle) raw1394_destroy_handle(handle);
106
107         if(device_lock) delete device_lock;
108
109 }
110
111 void AVC1394Control::play()
112 {
113 //printf("AVC1394Control::play(): 1\n");
114         device_lock->lock("AVC1394Control::play");
115         avc1394_vcr_play(handle, device);
116         device_lock->unlock();
117 }
118
119 void AVC1394Control::stop()
120 {
121 //printf("AVC1394Control::stop(): 1\n");
122         device_lock->lock("AVC1394Control::stop");
123         avc1394_vcr_stop(handle, device);
124         device_lock->unlock();
125 }
126
127 void AVC1394Control::reverse()
128 {
129 //printf("AVC1394Control::reverse(): 1\n");
130         device_lock->lock("AVC1394Control::reverse");
131         avc1394_vcr_reverse(handle, device);
132         device_lock->unlock();
133 }
134
135 void AVC1394Control::rewind()
136 {
137 //printf("AVC1394Control::rewind(): 1\n");
138         device_lock->lock("AVC1394Control::rewind");
139         avc1394_vcr_rewind(handle, device);
140         device_lock->unlock();
141 }
142
143 void AVC1394Control::fforward()
144 {
145 //printf("AVC1394Control::fforward(): 1\n");
146         device_lock->lock("AVC1394Control::fforward");
147         avc1394_vcr_forward(handle, device);
148         device_lock->unlock();
149 }
150
151 void AVC1394Control::pause()
152 {
153 //printf("AVC1394Control::pause(): 1\n");
154         device_lock->lock("AVC1394Control::pause");
155         avc1394_vcr_pause(handle, device);
156         device_lock->unlock();
157 }
158
159 void AVC1394Control::record()
160 {
161 //printf("AVC1394Control::record(): 1\n");
162         device_lock->lock("AVC1394Control::record");
163         avc1394_vcr_record(handle, device);
164         device_lock->unlock();
165 }
166
167 void AVC1394Control::eject()
168 {
169 //printf("AVC1394Control::eject(): 1\n");
170         device_lock->lock("AVC1394Control::eject");
171         avc1394_vcr_eject(handle, device);
172         device_lock->unlock();
173 }
174
175 void AVC1394Control::get_status()
176 {
177 //printf("AVC1394Control::get_status(): 1\n");
178         device_lock->lock("Control::get_status");
179         status = avc1394_vcr_status(handle, device);
180         device_lock->unlock();
181 //      printf("Status: %s\n", avc1394_vcr_decode_status(status));
182 }
183
184 char *AVC1394Control::timecode()
185 {
186         device_lock->lock("AVC1394Control::timecode");
187         avc1394_vcr_get_timecode2(handle, device, text_return);
188         device_lock->unlock();
189         return text_return;
190 }
191
192 void AVC1394Control::seek(const char *time)
193 {
194 //printf("AVC1394Control::seek(): 1\n");
195         device_lock->lock("AVC1394Control::seek");
196         avc1394_vcr_seek_timecode(handle, device, (char*)time);
197         device_lock->unlock();
198 }