1 |
/* avdevicemusicsubunit.cpp |
---|
2 |
* Copyright (C) 2004,05 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 "avdevice.h" |
---|
24 |
#include "avdevicesubunit.h" |
---|
25 |
#include "avdevicemusicsubunit.h" |
---|
26 |
#include "avmusicstatusdescriptor.h" |
---|
27 |
#include "avmusicidentifierdescriptor.h" |
---|
28 |
#include "avpluginfoblock.h" |
---|
29 |
#include "avclusterinfoblock.h" |
---|
30 |
|
---|
31 |
#define CORRECT_INTEGER_ENDIANNESS(value) (((((value)>>8) & 0xFF)) | ((((value)) & 0xFF)<<8)) |
---|
32 |
|
---|
33 |
void AvDeviceMusicSubunit::test() { |
---|
34 |
// unsigned char byte; |
---|
35 |
quadlet_t request[6]; |
---|
36 |
quadlet_t *response; |
---|
37 |
|
---|
38 |
unsigned char ipcr=0; |
---|
39 |
|
---|
40 |
debugPrint(DEBUG_LEVEL_SUBUNIT,"AvDeviceMusicSubunit: Input Select status (iso channels):\n"); |
---|
41 |
for(ipcr=0;ipcr<0x1E;ipcr++) { |
---|
42 |
request[0] = AVC1394_CTYPE_STATUS | ((iTarget & 0x1F) << 19) | ((iId & 0x07) << 16) |
---|
43 |
| (0x1B << 8) | 0xFF; |
---|
44 |
//request[1] = ((iTarget & 0x1F) << 27) | ((iId & 0x07) << 24) | 0x00FF7F; |
---|
45 |
request[1]=0xFFFFFFFF; |
---|
46 |
request[2]= (ipcr<<24)| 0xFFFEFF; |
---|
47 |
response = cParent->avcExecuteTransaction(request, 3, 4); |
---|
48 |
|
---|
49 |
if ((response != NULL) && ((response[0]&0xFF000000)==0x0C000000)) { |
---|
50 |
unsigned char output_status=(response[1]&0xF0000000) >> 28; |
---|
51 |
unsigned char output_plug=(response[1]&0xFF); |
---|
52 |
unsigned char input_plug=((response[2]>>24)&0xFF); |
---|
53 |
|
---|
54 |
unsigned int node_id=((response[1]>>8)&0xFFFF); |
---|
55 |
unsigned int signal_destination=((response[2]>>8)&0xFFFF); |
---|
56 |
debugPrint(DEBUG_LEVEL_SUBUNIT," iPCR %d: output_status=0x%01X,node_id=%02d,output_plug=0x%02X,input_plug=0x%02X,signal_destination=0x%04X\n",ipcr,output_status,node_id,output_plug,input_plug,signal_destination); |
---|
57 |
} |
---|
58 |
} |
---|
59 |
} |
---|
60 |
|
---|
61 |
|
---|
62 |
void AvDeviceMusicSubunit::printMusicPlugConfigurations() { |
---|
63 |
// unsigned char byte; |
---|
64 |
quadlet_t request[6]; |
---|
65 |
quadlet_t *response; |
---|
66 |
|
---|
67 |
unsigned int subunit_plug_id; |
---|
68 |
|
---|
69 |
debugPrint(DEBUG_LEVEL_SUBUNIT,"AvDeviceMusicSubunit: Source Plug configurations:\n"); |
---|
70 |
|
---|
71 |
for (subunit_plug_id=0;subunit_plug_id < getNbSourcePlugs() ;subunit_plug_id++) { |
---|
72 |
// get source plug configure status |
---|
73 |
request[0] = AVC1394_CTYPE_STATUS | ((iTarget & 0x1F) << 19) | ((iId & 0x07) << 16) |
---|
74 |
| (0x43 << 8) | subunit_plug_id; |
---|
75 |
request[1] = 0xFFFFFF00; |
---|
76 |
request[2] = 0x0000FFFF; |
---|
77 |
request[3] = 0xFFFFFFFF; |
---|
78 |
response = cParent->avcExecuteTransaction(request, 1, 4); |
---|
79 |
if (response != NULL) { |
---|
80 |
|
---|
81 |
unsigned int start_of_music_plug_ID=CORRECT_INTEGER_ENDIANNESS(response[1]); |
---|
82 |
unsigned int end_of_music_plug_ID=CORRECT_INTEGER_ENDIANNESS(response[1]>>16); |
---|
83 |
|
---|
84 |
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); |
---|
85 |
|
---|
86 |
unsigned char *table_pointer=((unsigned char *)response)+8; |
---|
87 |
|
---|
88 |
for(unsigned int i=0;i<(end_of_music_plug_ID-start_of_music_plug_ID)+1;i++) { |
---|
89 |
unsigned char music_plug_type=(*(table_pointer)) & 0xFF; |
---|
90 |
unsigned int music_plug_ID=((*(table_pointer+1))<<8)+((*(table_pointer+2))); |
---|
91 |
unsigned int stream_position=((*(table_pointer+3))<<8)+((*(table_pointer+4))); |
---|
92 |
|
---|
93 |
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); |
---|
94 |
|
---|
95 |
table_pointer+=5; |
---|
96 |
} |
---|
97 |
} |
---|
98 |
} |
---|
99 |
|
---|
100 |
debugPrint(DEBUG_LEVEL_SUBUNIT,"AvDeviceMusicSubunit: Destination Plug configurations:\n"); |
---|
101 |
for (subunit_plug_id=0;subunit_plug_id < getNbDestinationPlugs() ;subunit_plug_id++) { |
---|
102 |
// get source plug configure status |
---|
103 |
request[0] = AVC1394_CTYPE_STATUS | ((iTarget & 0x1F) << 19) | ((iId & 0x07) << 16) |
---|
104 |
| (0x42 << 8) | subunit_plug_id; |
---|
105 |
request[1] = 0xFFFFFF00; |
---|
106 |
request[2] = 0x0000FFFF; |
---|
107 |
request[3] = 0xFFFFFFFF; |
---|
108 |
response = cParent->avcExecuteTransaction(request, 1, 4); |
---|
109 |
if (response != NULL) { |
---|
110 |
|
---|
111 |
unsigned int start_of_music_plug_ID=CORRECT_INTEGER_ENDIANNESS(response[1]); |
---|
112 |
unsigned int end_of_music_plug_ID=CORRECT_INTEGER_ENDIANNESS(response[1]>>16); |
---|
113 |
|
---|
114 |
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); |
---|
115 |
|
---|
116 |
unsigned char *table_pointer=((unsigned char *)response)+8; |
---|
117 |
|
---|
118 |
for(unsigned int i=0;i<(end_of_music_plug_ID-start_of_music_plug_ID)+1;i++) { |
---|
119 |
unsigned char music_plug_type=(*(table_pointer)) & 0xFF; |
---|
120 |
unsigned int music_plug_ID=((*(table_pointer+1))<<8)+((*(table_pointer+2))); |
---|
121 |
unsigned int stream_position=((*(table_pointer+3))<<8)+((*(table_pointer+4))); |
---|
122 |
|
---|
123 |
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); |
---|
124 |
|
---|
125 |
table_pointer+=5; |
---|
126 |
} |
---|
127 |
} |
---|
128 |
} |
---|
129 |
|
---|
130 |
} |
---|
131 |
|
---|
132 |
void AvDeviceMusicSubunit::printMusicPlugInfo() { |
---|
133 |
// unsigned char byte; |
---|
134 |
quadlet_t request[6]; |
---|
135 |
quadlet_t *response; |
---|
136 |
|
---|
137 |
debugPrint(DEBUG_LEVEL_SUBUNIT,"AvDeviceMusicSubunit: Plug Information\n"); |
---|
138 |
|
---|
139 |
// get music plug info (verified & working) |
---|
140 |
request[0] = AVC1394_CTYPE_STATUS | ((iTarget & 0x1F) << 19) | ((iId & 0x07) << 16) |
---|
141 |
| (0xC0 << 8) | 0xFF; |
---|
142 |
response = cParent->avcExecuteTransaction(request, 1, 4); |
---|
143 |
|
---|
144 |
if (response != NULL) { |
---|
145 |
unsigned char *buffer=(unsigned char *) response; |
---|
146 |
buffer += 4; |
---|
147 |
unsigned char nb_items=*buffer; |
---|
148 |
buffer += 1; |
---|
149 |
for (unsigned int i=0;i<nb_items;i++) { |
---|
150 |
unsigned int nb_output_plugs=CORRECT_INTEGER_ENDIANNESS(*((unsigned int *)(buffer + 3))); |
---|
151 |
unsigned int nb_input_plugs=CORRECT_INTEGER_ENDIANNESS(*((unsigned int *)(buffer + 1))); |
---|
152 |
debugPrint(DEBUG_LEVEL_SUBUNIT," Music plug type 0x%02X: %d input plugs / %d output plugs\n",*buffer,nb_input_plugs,nb_output_plugs); |
---|
153 |
buffer +=5; |
---|
154 |
} |
---|
155 |
} |
---|
156 |
|
---|
157 |
} |
---|
158 |
|
---|
159 |
void AvDeviceMusicSubunit::printSourcePlugConnections(unsigned char plug) { |
---|
160 |
if(cStatusDescriptor) { |
---|
161 |
AvPlugInfoBlock *plugInfo=cStatusDescriptor->getSourcePlugInfoBlock(plug); |
---|
162 |
|
---|
163 |
if(plugInfo) { |
---|
164 |
plugInfo->printConnections(); |
---|
165 |
} else { |
---|
166 |
debugPrint (DEBUG_LEVEL_SUBUNIT,"AvDeviceMusicSubunit: could not find source plug 0x%02X in the descriptor.\n",plug); |
---|
167 |
} |
---|
168 |
|
---|
169 |
|
---|
170 |
} else { |
---|
171 |
debugPrint (DEBUG_LEVEL_SUBUNIT,"AvDeviceMusicSubunit: no Status Descriptor present!\n"); |
---|
172 |
} |
---|
173 |
|
---|
174 |
} |
---|
175 |
|
---|
176 |
|
---|
177 |
|
---|
178 |
AvDeviceMusicSubunit::AvDeviceMusicSubunit(AvDevice *parent, unsigned char id) : AvDeviceSubunit(parent,0x0C,id) |
---|
179 |
{ |
---|
180 |
setDebugLevel( DEBUG_LEVEL_ALL ); |
---|
181 |
|
---|
182 |
debugPrint (DEBUG_LEVEL_SUBUNIT,"AvDeviceMusicSubunit: id=%02X constructor\n",id); |
---|
183 |
bValid=false; |
---|
184 |
|
---|
185 |
// parse descriptors |
---|
186 |
cStatusDescriptor=NULL; |
---|
187 |
cIdentifierDescriptor=NULL; |
---|
188 |
|
---|
189 |
cStatusDescriptor = new AvMusicStatusDescriptor(parent,id); |
---|
190 |
|
---|
191 |
if(cStatusDescriptor) { |
---|
192 |
cStatusDescriptor->printCapabilities(); |
---|
193 |
} else { |
---|
194 |
debugPrint (DEBUG_LEVEL_SUBUNIT,"AvDeviceMusicSubunit: could not create AvMusicStatusDescriptor object\n"); |
---|
195 |
} |
---|
196 |
|
---|
197 |
cIdentifierDescriptor = new AvMusicIdentifierDescriptor(parent,id); |
---|
198 |
if(cIdentifierDescriptor) { |
---|
199 |
cIdentifierDescriptor->printCapabilities(); |
---|
200 |
|
---|
201 |
} else { |
---|
202 |
debugPrint (DEBUG_LEVEL_SUBUNIT,"AvDeviceMusicSubunit: could not create AvMusicIdentifierDescriptor object\n"); |
---|
203 |
} |
---|
204 |
|
---|
205 |
bValid=true; |
---|
206 |
|
---|
207 |
} |
---|
208 |
|
---|
209 |
AvDeviceMusicSubunit::~AvDeviceMusicSubunit() |
---|
210 |
{ |
---|
211 |
if(cStatusDescriptor) delete cStatusDescriptor; |
---|
212 |
if(cIdentifierDescriptor) delete cIdentifierDescriptor; |
---|
213 |
} |
---|