4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
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
28 #include "avc1394control.h"
30 #include "transportque.inc"
32 AVC1394Control::AVC1394Control()
37 void AVC1394Control::initialize()
41 current_command = COMMAND_NONE;
44 device_lock = new Mutex("AVC1394Control::device_lock");
47 handle = raw1394_get_handle();
49 handle = raw1394_new_handle();
51 //printf("AVC1394Control::initialize(): 1\n");
54 //printf("AVC1394Control::initialize(): 2\n");
57 //printf("AVC1394Control::initialize(): 3\n");
58 fprintf(stderr, "AVC1394Control::initialize(): Not Compatable!\n");
62 //printf("AVC1394Control::initialize(): 4\n");
63 fprintf(stderr, "AVC1394Control::initialize(): couldn't get handle\n");
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);
75 for(i = 0; i < raw1394_get_nodecount(handle); i++)
77 if(rom1394_get_directory(handle, i, &rom_dir) < 0)
79 //printf("AVC1394Control::initialize(): 6\n");
80 fprintf(stderr, "AVC1394Control::initialize(): node %d\n", i);
81 // raw1394_destroy_handle(handle);
85 if((rom1394_get_node_type(&rom_dir) == ROM1394_NODE_TYPE_AVC) &&
86 avc1394_check_subunit_type(handle, i, AVC1394_SUBUNIT_TYPE_VCR))
88 //printf("AVC1394Control::initialize(): 7\n");
96 //printf("AVC1394Control::initialize(): 8\n");
97 fprintf(stderr, "AVC1394Control::initialize(): No AV/C Devices\n");
98 // raw1394_destroy_handle(handle);
104 AVC1394Control::~AVC1394Control()
106 if(handle) raw1394_destroy_handle(handle);
108 if(device_lock) delete device_lock;
112 void AVC1394Control::play()
114 //printf("AVC1394Control::play(): 1\n");
115 device_lock->lock("AVC1394Control::play");
116 avc1394_vcr_play(handle, device);
117 device_lock->unlock();
120 void AVC1394Control::stop()
122 //printf("AVC1394Control::stop(): 1\n");
123 device_lock->lock("AVC1394Control::stop");
124 avc1394_vcr_stop(handle, device);
125 device_lock->unlock();
128 void AVC1394Control::reverse()
130 //printf("AVC1394Control::reverse(): 1\n");
131 device_lock->lock("AVC1394Control::reverse");
132 avc1394_vcr_reverse(handle, device);
133 device_lock->unlock();
136 void AVC1394Control::rewind()
138 //printf("AVC1394Control::rewind(): 1\n");
139 device_lock->lock("AVC1394Control::rewind");
140 avc1394_vcr_rewind(handle, device);
141 device_lock->unlock();
144 void AVC1394Control::fforward()
146 //printf("AVC1394Control::fforward(): 1\n");
147 device_lock->lock("AVC1394Control::fforward");
148 avc1394_vcr_forward(handle, device);
149 device_lock->unlock();
152 void AVC1394Control::pause()
154 //printf("AVC1394Control::pause(): 1\n");
155 device_lock->lock("AVC1394Control::pause");
156 avc1394_vcr_pause(handle, device);
157 device_lock->unlock();
160 void AVC1394Control::record()
162 //printf("AVC1394Control::record(): 1\n");
163 device_lock->lock("AVC1394Control::record");
164 avc1394_vcr_record(handle, device);
165 device_lock->unlock();
168 void AVC1394Control::eject()
170 //printf("AVC1394Control::eject(): 1\n");
171 device_lock->lock("AVC1394Control::eject");
172 avc1394_vcr_eject(handle, device);
173 device_lock->unlock();
176 void AVC1394Control::get_status()
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));
185 char *AVC1394Control::timecode()
187 device_lock->lock("AVC1394Control::timecode");
188 avc1394_vcr_get_timecode2(handle, device, text_return);
189 device_lock->unlock();
193 void AVC1394Control::seek(const char *time)
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();