1 |
/* avdevicemusicsubunit.cpp |
---|
2 |
* Copyright (C) 2004 by Pieter Palmers |
---|
3 |
* |
---|
4 |
* This file is part of FreeBob. |
---|
5 |
* |
---|
6 |
* FreeBob 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 |
* FreeBob is distributed in the hope that it will be useful, |
---|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 |
* GNU General Public License for more details. |
---|
14 |
* |
---|
15 |
* You should have received a copy of the GNU General Public License |
---|
16 |
* along with FreeBob; if not, write to the Free Software |
---|
17 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
---|
18 |
* MA 02111-1307 USA. |
---|
19 |
*/ |
---|
20 |
#include <errno.h> |
---|
21 |
#include <libavc1394/avc1394.h> |
---|
22 |
#include <libavc1394/avc1394_vcr.h> |
---|
23 |
#include "debugmodule.h" |
---|
24 |
#include "avdevice.h" |
---|
25 |
#include "avdevicesubunit.h" |
---|
26 |
#include "avdevicemusicsubunit.h" |
---|
27 |
#include "avmusicstatusdescriptor.h" |
---|
28 |
#include "avmusicidentifierdescriptor.h" |
---|
29 |
|
---|
30 |
#define CORRECT_INTEGER_ENDIANNESS(value) (((((value)>>8) & 0xFF)) | ((((value)) & 0xFF)<<8)) |
---|
31 |
|
---|
32 |
void AvDeviceMusicSubunit::test() { |
---|
33 |
unsigned char byte; |
---|
34 |
quadlet_t request[6]; |
---|
35 |
quadlet_t *response; |
---|
36 |
|
---|
37 |
unsigned char opcr=0; |
---|
38 |
|
---|
39 |
debugPrint(DEBUG_LEVEL_SUBUNIT,"AvDeviceMusicSubunit: Serial bus iso output plug connections:\n"); |
---|
40 |
for(opcr=0;opcr<0x1E;opcr++) { |
---|
41 |
request[0] = AVC1394_CTYPE_STATUS | ((iTarget & 0x1F) << 19) | ((iId & 0x07) << 16) |
---|
42 |
| (0x1A << 8) | 0xFF; |
---|
43 |
//request[1] = ((iTarget & 0x1F) << 27) | ((iId & 0x07) << 24) | 0x00FF7F; |
---|
44 |
request[1]=0xFFFEFF00 | opcr; |
---|
45 |
response = cParent->avcExecuteTransaction(request, 2, 4); |
---|
46 |
if ((response != NULL) && ((response[0]&0xFF000000)==0x0C000000)) { |
---|
47 |
unsigned char output_status=(response[0]&0xE0) >> 5; |
---|
48 |
unsigned char conv=(response[0]&0x10) >> 4; |
---|
49 |
unsigned char signal_status=(response[0]&0x0F); |
---|
50 |
|
---|
51 |
unsigned int signal_source=((response[1]>>16)&0xFFFF); |
---|
52 |
unsigned int signal_destination=((response[1])&0xFFFF); |
---|
53 |
debugPrint(DEBUG_LEVEL_SUBUNIT," oPCR %d: output_status=%d,conv=%d,signal_status=%d,signal_source=0x%04X,signal_destination=0x%04X\n",opcr,output_status,conv,signal_status,signal_source,signal_destination); |
---|
54 |
} |
---|
55 |
} |
---|
56 |
debugPrint(DEBUG_LEVEL_SUBUNIT,"AvDeviceMusicSubunit: Serial bus external output plug connections:\n"); |
---|
57 |
for(opcr=0x80;opcr<0x9E;opcr++) { |
---|
58 |
request[0] = AVC1394_CTYPE_STATUS | ((iTarget & 0x1F) << 19) | ((iId & 0x07) << 16) |
---|
59 |
| (0x1A << 8) | 0xFF; |
---|
60 |
//request[1] = ((iTarget & 0x1F) << 27) | ((iId & 0x07) << 24) | 0x00FF7F; |
---|
61 |
request[1]=0xFFFEFF00 | opcr; |
---|
62 |
response = cParent->avcExecuteTransaction(request, 2, 4); |
---|
63 |
if ((response != NULL) && ((response[0]&0xFF000000)==0x0C000000)) { |
---|
64 |
unsigned char output_status=(response[0]&0xE0) >> 5; |
---|
65 |
unsigned char conv=(response[0]&0x10) >> 4; |
---|
66 |
unsigned char signal_status=(response[0]&0x0F); |
---|
67 |
|
---|
68 |
unsigned int signal_source=((response[1]>>16)&0xFFFF); |
---|
69 |
unsigned int signal_destination=((response[1])&0xFFFF); |
---|
70 |
debugPrint(DEBUG_LEVEL_SUBUNIT," oPCR %02X: output_status=%d,conv=%d,signal_status=%d,signal_source=0x%04X,signal_destination=0x%04X\n",opcr,output_status,conv,signal_status,signal_source,signal_destination); |
---|
71 |
} |
---|
72 |
} |
---|
73 |
|
---|
74 |
} |
---|
75 |
void AvDeviceMusicSubunit::printMusicPlugConfigurations() { |
---|
76 |
unsigned char byte; |
---|
77 |
quadlet_t request[6]; |
---|
78 |
quadlet_t *response; |
---|
79 |
|
---|
80 |
unsigned int subunit_plug_id; |
---|
81 |
|
---|
82 |
debugPrint(DEBUG_LEVEL_SUBUNIT,"AvDeviceMusicSubunit: Source Plug configurations:\n"); |
---|
83 |
|
---|
84 |
for (subunit_plug_id=0;subunit_plug_id < getNbSourcePlugs() ;subunit_plug_id++) { |
---|
85 |
// get source plug configure status |
---|
86 |
request[0] = AVC1394_CTYPE_STATUS | ((iTarget & 0x1F) << 19) | ((iId & 0x07) << 16) |
---|
87 |
| (0x43 << 8) | subunit_plug_id; |
---|
88 |
request[1] = 0xFFFFFF00; |
---|
89 |
request[2] = 0x0000FFFF; |
---|
90 |
request[3] = 0xFFFFFFFF; |
---|
91 |
response = cParent->avcExecuteTransaction(request, 1, 4); |
---|
92 |
if (response != NULL) { |
---|
93 |
|
---|
94 |
unsigned int start_of_music_plug_ID=CORRECT_INTEGER_ENDIANNESS(response[1]); |
---|
95 |
unsigned int end_of_music_plug_ID=CORRECT_INTEGER_ENDIANNESS(response[1]>>16); |
---|
96 |
|
---|
97 |
debugPrint(DEBUG_LEVEL_SUBUNIT," Subunit source plug %d: start_of_music_plug_ID=%d, end_of_music_plug_ID=%d\n",subunit_plug_id,start_of_music_plug_ID,end_of_music_plug_ID); |
---|
98 |
|
---|
99 |
unsigned char *table_pointer=((unsigned char *)response)+8; |
---|
100 |
|
---|
101 |
for(unsigned int i=0;i<(end_of_music_plug_ID-start_of_music_plug_ID)+1;i++) { |
---|
102 |
unsigned char music_plug_type=(*(table_pointer)) & 0xFF; |
---|
103 |
unsigned int music_plug_ID=((*(table_pointer+1))<<8)+((*(table_pointer+2))); |
---|
104 |
unsigned int stream_position=((*(table_pointer+3))<<8)+((*(table_pointer+4))); |
---|
105 |
|
---|
106 |
debugPrint(DEBUG_LEVEL_SUBUNIT," %02d: Type=0x%02X, ID=%02d, Position=0x%04X\n",i+start_of_music_plug_ID,music_plug_type,music_plug_ID,stream_position); |
---|
107 |
|
---|
108 |
table_pointer+=5; |
---|
109 |
} |
---|
110 |
} |
---|
111 |
} |
---|
112 |
|
---|
113 |
debugPrint(DEBUG_LEVEL_SUBUNIT,"AvDeviceMusicSubunit: Destination Plug configurations:\n"); |
---|
114 |
for (subunit_plug_id=0;subunit_plug_id < getNbDestinationPlugs() ;subunit_plug_id++) { |
---|
115 |
// get source plug configure status |
---|
116 |
request[0] = AVC1394_CTYPE_STATUS | ((iTarget & 0x1F) << 19) | ((iId & 0x07) << 16) |
---|
117 |
| (0x42 << 8) | subunit_plug_id; |
---|
118 |
request[1] = 0xFFFFFF00; |
---|
119 |
request[2] = 0x0000FFFF; |
---|
120 |
request[3] = 0xFFFFFFFF; |
---|
121 |
response = cParent->avcExecuteTransaction(request, 1, 4); |
---|
122 |
if (response != NULL) { |
---|
123 |
|
---|
124 |
unsigned int start_of_music_plug_ID=CORRECT_INTEGER_ENDIANNESS(response[1]); |
---|
125 |
unsigned int end_of_music_plug_ID=CORRECT_INTEGER_ENDIANNESS(response[1]>>16); |
---|
126 |
|
---|
127 |
debugPrint(DEBUG_LEVEL_SUBUNIT," Subunit destination plug %d: start_of_music_plug_ID=%d, end_of_music_plug_ID=%d\n",subunit_plug_id,start_of_music_plug_ID,end_of_music_plug_ID); |
---|
128 |
|
---|
129 |
unsigned char *table_pointer=((unsigned char *)response)+8; |
---|
130 |
|
---|
131 |
for(unsigned int i=0;i<(end_of_music_plug_ID-start_of_music_plug_ID)+1;i++) { |
---|
132 |
unsigned char music_plug_type=(*(table_pointer)) & 0xFF; |
---|
133 |
unsigned int music_plug_ID=((*(table_pointer+1))<<8)+((*(table_pointer+2))); |
---|
134 |
unsigned int stream_position=((*(table_pointer+3))<<8)+((*(table_pointer+4))); |
---|
135 |
|
---|
136 |
debugPrint(DEBUG_LEVEL_SUBUNIT," %02d: Type=0x%02X, ID=%02d, Position=0x%04X\n",i+start_of_music_plug_ID,music_plug_type,music_plug_ID,stream_position); |
---|
137 |
|
---|
138 |
table_pointer+=5; |
---|
139 |
} |
---|
140 |
} |
---|
141 |
} |
---|
142 |
|
---|
143 |
} |
---|
144 |
|
---|
145 |
void AvDeviceMusicSubunit::printMusicPlugInfo() { |
---|
146 |
unsigned char byte; |
---|
147 |
quadlet_t request[6]; |
---|
148 |
quadlet_t *response; |
---|
149 |
|
---|
150 |
debugPrint(DEBUG_LEVEL_SUBUNIT,"AvDeviceMusicSubunit: Plug Information\n"); |
---|
151 |
|
---|
152 |
// get music plug info (verified & working) |
---|
153 |
request[0] = AVC1394_CTYPE_STATUS | ((iTarget & 0x1F) << 19) | ((iId & 0x07) << 16) |
---|
154 |
| (0xC0 << 8) | 0xFF; |
---|
155 |
response = cParent->avcExecuteTransaction(request, 1, 4); |
---|
156 |
|
---|
157 |
if (response != NULL) { |
---|
158 |
unsigned char *buffer=(unsigned char *) response; |
---|
159 |
buffer += 4; |
---|
160 |
unsigned char nb_items=*buffer; |
---|
161 |
buffer += 1; |
---|
162 |
for (unsigned int i=0;i<nb_items;i++) { |
---|
163 |
unsigned int nb_output_plugs=CORRECT_INTEGER_ENDIANNESS(*((unsigned int *)(buffer + 3))); |
---|
164 |
unsigned int nb_input_plugs=CORRECT_INTEGER_ENDIANNESS(*((unsigned int *)(buffer + 1))); |
---|
165 |
debugPrint(DEBUG_LEVEL_SUBUNIT," Music plug type 0x%02X: %d input plugs / %d output plugs\n",*buffer,nb_input_plugs,nb_output_plugs) |
---|
166 |
buffer +=5; |
---|
167 |
} |
---|
168 |
} |
---|
169 |
|
---|
170 |
} |
---|
171 |
|
---|
172 |
|
---|
173 |
AvDeviceMusicSubunit::AvDeviceMusicSubunit(AvDevice *parent, unsigned char id) : AvDeviceSubunit(parent,0x0C,id) |
---|
174 |
{ |
---|
175 |
debugPrint (DEBUG_LEVEL_SUBUNIT,"AvDeviceMusicSubunit: id=%02X constructor\n",id); |
---|
176 |
bValid=false; |
---|
177 |
|
---|
178 |
// parse descriptors |
---|
179 |
cStatusDescriptor=NULL; |
---|
180 |
cIdentifierDescriptor=NULL; |
---|
181 |
|
---|
182 |
cStatusDescriptor = new AvMusicStatusDescriptor(parent,id); |
---|
183 |
|
---|
184 |
if(cStatusDescriptor) { |
---|
185 |
cStatusDescriptor->printCapabilities(); |
---|
186 |
} else { |
---|
187 |
debugPrint (DEBUG_LEVEL_SUBUNIT,"AvDeviceMusicSubunit: could not create AvMusicStatusDescriptor object\n"); |
---|
188 |
} |
---|
189 |
|
---|
190 |
cIdentifierDescriptor = new AvMusicIdentifierDescriptor(parent,id); |
---|
191 |
if(cIdentifierDescriptor) { |
---|
192 |
cIdentifierDescriptor->printCapabilities(); |
---|
193 |
|
---|
194 |
} else { |
---|
195 |
debugPrint (DEBUG_LEVEL_SUBUNIT,"AvDeviceMusicSubunit: could not create AvMusicIdentifierDescriptor object\n"); |
---|
196 |
} |
---|
197 |
|
---|
198 |
bValid=true; |
---|
199 |
|
---|
200 |
} |
---|
201 |
|
---|
202 |
AvDeviceMusicSubunit::~AvDeviceMusicSubunit() |
---|
203 |
{ |
---|
204 |
if(cStatusDescriptor) delete cStatusDescriptor; |
---|
205 |
if(cIdentifierDescriptor) delete cIdentifierDescriptor; |
---|
206 |
} |
---|