2 * Copyright (c) 1999-2000, Eric Moon.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions, and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include "route_app_io.h"
36 #include <MediaDefs.h>
37 #include <MediaNode.h>
38 #include <MediaRoster.h>
40 #include "NodeManager.h"
42 #include "NodeSetIOContext.h"
44 __BEGIN_CORTEX_NAMESPACE
46 // -------------------------------------------------------- //
48 const char* const _NODE_SET_ELEMENT
= "cortex_node_set";
49 const char* const _UI_STATE_ELEMENT
= "cortex_ui_state";
51 const char* const _DORMANT_NODE_ELEMENT
= "dormant_node";
52 const char* const _KIND_ELEMENT
= "kind";
53 const char* const _FLAVOR_ID_ELEMENT
= "flavor_id";
54 const char* const _CYCLE_ELEMENT
= "cycle";
55 const char* const _FLAG_ELEMENT
= "flag";
56 const char* const _RUN_MODE_ELEMENT
= "run_mode";
57 const char* const _TIME_SOURCE_ELEMENT
= "time_source";
58 const char* const _RECORDING_DELAY_ELEMENT
= "recording_delay";
59 const char* const _CONNECTION_ELEMENT
= "connection";
60 const char* const _OUTPUT_ELEMENT
= "output";
61 const char* const _INPUT_ELEMENT
= "input";
62 const char* const _NODE_GROUP_ELEMENT
= "node_group";
63 const char* const _NAME_ELEMENT
= "name";
64 const char* const _REF_ELEMENT
= "ref";
65 const char* const _LIVE_NODE_ELEMENT
= "live_node";
67 const char* const _AUDIO_INPUT_KEY
= "AUDIO_INPUT";
68 const char* const _AUDIO_OUTPUT_KEY
= "AUDIO_OUTPUT";
69 const char* const _AUDIO_MIXER_KEY
= "AUDIO_MIXER";
70 const char* const _VIDEO_INPUT_KEY
= "VIDEO_INPUT";
71 const char* const _VIDEO_OUTPUT_KEY
= "VIDEO_OUTPUT";
73 __END_CORTEX_NAMESPACE
75 // -------------------------------------------------------- //
76 __USE_CORTEX_NAMESPACE
77 // -------------------------------------------------------- //
79 void __CORTEX_NAMESPACE__
_write_simple(
82 ExportContext
& context
) {
84 context
.beginElement(element
);
85 context
.beginContent();
86 context
.writeString(value
);
90 void __CORTEX_NAMESPACE__
_write_node_kinds(
92 ExportContext
& context
) {
94 if(kinds
& B_BUFFER_PRODUCER
)
95 _write_simple(_KIND_ELEMENT
, "B_BUFFER_PRODUCER", context
);
96 if(kinds
& B_BUFFER_CONSUMER
)
97 _write_simple(_KIND_ELEMENT
, "B_BUFFER_CONSUMER", context
);
98 if(kinds
& B_TIME_SOURCE
)
99 _write_simple(_KIND_ELEMENT
, "B_TIME_SOURCE", context
);
100 if(kinds
& B_CONTROLLABLE
)
101 _write_simple(_KIND_ELEMENT
, "B_CONTROLLABLE", context
);
102 if(kinds
& B_FILE_INTERFACE
)
103 _write_simple(_KIND_ELEMENT
, "B_FILE_INTERFACE", context
);
104 if(kinds
& B_ENTITY_INTERFACE
)
105 _write_simple(_KIND_ELEMENT
, "B_ENTITY_INTERFACE", context
);
106 if(kinds
& B_PHYSICAL_INPUT
)
107 _write_simple(_KIND_ELEMENT
, "B_PHYSICAL_INPUT", context
);
108 if(kinds
& B_PHYSICAL_OUTPUT
)
109 _write_simple(_KIND_ELEMENT
, "B_PHYSICAL_OUTPUT", context
);
110 if(kinds
& B_SYSTEM_MIXER
)
111 _write_simple(_KIND_ELEMENT
, "B_SYSTEM_MIXER", context
);
114 void __CORTEX_NAMESPACE__
_read_node_kind(
117 ImportContext
& context
) {
119 if(!strcmp(data
, "B_BUFFER_PRODUCER"))
120 ioKind
|= B_BUFFER_PRODUCER
;
121 else if(!strcmp(data
, "B_BUFFER_CONSUMER"))
122 ioKind
|= B_BUFFER_CONSUMER
;
123 else if(!strcmp(data
, "B_TIME_SOURCE"))
124 ioKind
|= B_TIME_SOURCE
;
125 else if(!strcmp(data
, "B_CONTROLLABLE"))
126 ioKind
|= B_CONTROLLABLE
;
127 else if(!strcmp(data
, "B_FILE_INTERFACE"))
128 ioKind
|= B_FILE_INTERFACE
;
129 else if(!strcmp(data
, "B_ENTITY_INTERFACE"))
130 ioKind
|= B_ENTITY_INTERFACE
;
131 else if(!strcmp(data
, "B_PHYSICAL_INPUT"))
132 ioKind
|= B_PHYSICAL_INPUT
;
133 else if(!strcmp(data
, "B_PHYSICAL_OUTPUT"))
134 ioKind
|= B_PHYSICAL_OUTPUT
;
135 else if(!strcmp(data
, "B_SYSTEM_MIXER"))
136 ioKind
|= B_SYSTEM_MIXER
;
139 err
<< "_read_noderef_kind(): unknown node kind '" << data
<< "'\n";
140 context
.reportWarning(err
.String());
144 // fills in either key or outName/kind for the provided
145 // node. If the given node is one of the default system nodes,
146 // an appropriate 'preset' key value will be returned.
148 status_t __CORTEX_NAMESPACE__
_get_node_signature(
149 const NodeManager
* manager
,
150 const NodeSetIOContext
* context
,
161 status_t err
= manager
->getNodeRef(node
, &ref
);
164 "!!! ConnectionIO::_getNodeSignature(): node %" B_PRId32
165 " not found\n", node
));
169 // check against system-default nodes
170 if(ref
== manager
->audioInputNode()) {
171 outKey
= _AUDIO_INPUT_KEY
;
174 else if(ref
== manager
->audioOutputNode()) {
175 outKey
= _AUDIO_OUTPUT_KEY
;
178 else if(ref
== manager
->audioMixerNode()) {
179 outKey
= _AUDIO_MIXER_KEY
;
182 else if(ref
== manager
->videoInputNode()) {
183 outKey
= _VIDEO_INPUT_KEY
;
186 else if(ref
== manager
->videoOutputNode()) {
187 outKey
= _VIDEO_OUTPUT_KEY
;
191 // check context for a key (found if the node has already
194 err
= context
->getKeyFor(node
, &key
);
200 // return name/kind signature
201 outName
= ref
->name();
202 outKind
= ref
->kind();
207 // given a name and kind, looks for a matching node
209 status_t __CORTEX_NAMESPACE__
_match_node_signature(
212 media_node_id
* outNode
) {
214 // fetch matching nodes
215 BMediaRoster
* roster
= BMediaRoster::Roster();
216 const int32 bufferSize
= 64;
217 live_node_info buffer
[bufferSize
];
218 int32 count
= bufferSize
;
219 status_t err
= roster
->GetLiveNodes(
225 kind
); // is this argument supported yet? +++++
230 for(int32 n
= 0; n
< count
; ++n
) {
231 PRINT(("# %" B_PRId32
"\n", buffer
[n
].node
.node
));
232 if((buffer
[n
].node
.kind
& kind
) != kind
) {
233 PRINT(("# - kind mismatch\n"));
237 *outNode
= buffer
[n
].node
.node
;
241 return B_NAME_NOT_FOUND
;
244 // given a key, looks for a system-default node
246 status_t __CORTEX_NAMESPACE__
_match_system_node_key(
248 const NodeManager
* manager
,
249 media_node_id
* outNode
) {
251 if(!strcmp(key
, _AUDIO_INPUT_KEY
)) {
252 if(manager
->audioInputNode()) {
253 *outNode
= manager
->audioInputNode()->id();
256 return B_NAME_NOT_FOUND
;
258 else if(!strcmp(key
, _AUDIO_OUTPUT_KEY
)) {
259 if(manager
->audioOutputNode()) {
260 *outNode
= manager
->audioOutputNode()->id();
263 return B_NAME_NOT_FOUND
;
265 else if(!strcmp(key
, _AUDIO_MIXER_KEY
)) {
266 if(manager
->audioMixerNode()) {
267 *outNode
= manager
->audioMixerNode()->id();
270 return B_NAME_NOT_FOUND
;
272 else if(!strcmp(key
, _VIDEO_INPUT_KEY
)) {
273 if(manager
->videoInputNode()) {
274 *outNode
= manager
->videoInputNode()->id();
277 return B_NAME_NOT_FOUND
;
279 else if(!strcmp(key
, _VIDEO_OUTPUT_KEY
)) {
280 if(manager
->videoOutputNode()) {
281 *outNode
= manager
->videoOutputNode()->id();
284 return B_NAME_NOT_FOUND
;
286 return B_NAME_NOT_FOUND
;
289 // adds mappings for the simple string-content elements to the
290 // given document type
292 void __CORTEX_NAMESPACE__
_add_string_elements(
293 XML::DocumentType
* docType
) {
295 docType
->addMapping(new Mapping
<StringContent
>(_NAME_ELEMENT
));
296 docType
->addMapping(new Mapping
<StringContent
>(_KIND_ELEMENT
));
297 docType
->addMapping(new Mapping
<StringContent
>(_FLAG_ELEMENT
));
298 docType
->addMapping(new Mapping
<StringContent
>(_FLAVOR_ID_ELEMENT
));
299 docType
->addMapping(new Mapping
<StringContent
>(_CYCLE_ELEMENT
));
300 docType
->addMapping(new Mapping
<StringContent
>(_RUN_MODE_ELEMENT
));
301 docType
->addMapping(new Mapping
<StringContent
>(_TIME_SOURCE_ELEMENT
));
302 docType
->addMapping(new Mapping
<StringContent
>(_RECORDING_DELAY_ELEMENT
));
303 docType
->addMapping(new Mapping
<StringContent
>(_REF_ELEMENT
));
306 // END -- route_app_io.cpp --