1 #include <string.h> 2 #include <Application.h> 3 #include <MediaRoster.h> 4 #include <TimeSource.h> 5 #include "ConsumerNode.h" 6 #include "ProducerNode.h" 7 #include "misc.h" 8 9 BMediaRoster *roster; 10 ProducerNode *producer; 11 ConsumerNode *consumer; 12 status_t rv; 13 14 int main() 15 { 16 out("Basic BBufferProducer, BBufferConsumer, BMediaRoster test\n"); 17 out("for OpenBeOS by Marcus Overhagen <Marcus@Overhagen.de>\n\n"); 18 out("Creating BApplication now\n"); 19 BApplication app("application/x-vnd.OpenBeOS-NodeTest"); 20 21 out("Creating MediaRoster\n"); 22 roster = BMediaRoster::Roster(); 23 val(roster); 24 25 out("Creating ProducerNode\n"); 26 producer = new ProducerNode(); 27 val(producer); 28 29 out("Creating ConsumerNode\n"); 30 consumer = new ConsumerNode(); 31 val(consumer); 32 33 out("Registering ProducerNode\n"); 34 rv = roster->RegisterNode(producer); 35 val(rv); 36 37 out("Registering ConsumerNode\n"); 38 rv = roster->RegisterNode(consumer); 39 val(rv); 40 41 media_node sourceNode; 42 media_node destinationNode; 43 44 out("Calling producer->Node()\n"); 45 sourceNode = producer->Node(); 46 47 out("Calling consumer->Node()\n"); 48 destinationNode = consumer->Node(); 49 50 51 live_node_info live_nodes[100]; 52 int32 live_count; 53 media_format liveformat; 54 memset(&liveformat, 0, sizeof(liveformat)); 55 56 liveformat.type = B_MEDIA_RAW_AUDIO; 57 58 out("Calling GetLiveNodes(), has_input = B_MEDIA_RAW_AUDIO\n"); 59 live_count = 100; 60 rv = roster->GetLiveNodes(live_nodes, &live_count, &liveformat); 61 val(rv); 62 out("Found %ld\n",live_count); 63 64 out("Calling GetLiveNodes(), has_output = B_MEDIA_RAW_AUDIO\n"); 65 live_count = 100; 66 rv = roster->GetLiveNodes(live_nodes, &live_count, NULL, &liveformat); 67 val(rv); 68 out("Found %ld\n",live_count); 69 70 out("Calling GetLiveNodes(), has_input = has_output = B_MEDIA_RAW_AUDIO\n"); 71 live_count = 100; 72 rv = roster->GetLiveNodes(live_nodes, &live_count, &liveformat, &liveformat); 73 val(rv); 74 out("Found %ld\n",live_count); 75 76 liveformat.type = B_MEDIA_RAW_VIDEO; 77 78 out("Calling GetLiveNodes(), has_input = B_MEDIA_RAW_VIDEO\n"); 79 live_count = 100; 80 rv = roster->GetLiveNodes(live_nodes, &live_count, &liveformat); 81 val(rv); 82 out("Found %ld\n",live_count); 83 84 out("Calling GetLiveNodes(), has_output = B_MEDIA_RAW_VIDEO\n"); 85 live_count = 100; 86 rv = roster->GetLiveNodes(live_nodes, &live_count, NULL, &liveformat); 87 val(rv); 88 out("Found %ld\n",live_count); 89 90 out("Calling GetLiveNodes(), has_input = has_output = B_MEDIA_RAW_VIDEO\n"); 91 live_count = 100; 92 rv = roster->GetLiveNodes(live_nodes, &live_count, &liveformat, &liveformat); 93 val(rv); 94 out("Found %ld\n",live_count); 95 96 97 media_output output; 98 media_input input; 99 media_output outputs[2]; 100 media_input inputs[2]; 101 int32 count; 102 103 out("Calling GetAllOutputsFor(source)\n"); 104 rv = roster->GetAllOutputsFor(sourceNode,outputs,2,&count); 105 val(rv); 106 out("Found %ld\n",count); 107 rv = (count == 1) ? B_OK : B_ERROR; 108 val(rv); 109 110 out("Calling GetAllInputsFor(destination)\n"); 111 rv = roster->GetAllInputsFor(destinationNode,inputs,2,&count); 112 val(rv); 113 out("Found %ld\n",count); 114 rv = (count == 1) ? B_OK : B_ERROR; 115 val(rv); 116 117 out("Calling GetAllInputsFor(source) (should fail)\n"); 118 rv = roster->GetAllInputsFor(sourceNode,inputs,2,&count); 119 val(rv); 120 out("Found %ld\n",count); 121 122 out("Calling GetAllOutputsFor(destination) (should fail)\n"); 123 rv = roster->GetAllOutputsFor(destinationNode,outputs,2,&count); 124 val(rv); 125 out("Found %ld\n",count); 126 127 out("Calling GetConnectedOutputsFor(source)\n"); 128 rv = roster->GetConnectedOutputsFor(sourceNode,outputs,2,&count); 129 val(rv); 130 out("Found %ld\n",count); 131 rv = (count == 0) ? B_OK : B_ERROR; 132 val(rv); 133 134 out("Calling GetConnectedInputsFor(destination)\n"); 135 rv = roster->GetConnectedInputsFor(destinationNode,inputs,2,&count); 136 val(rv); 137 out("Found %ld\n",count); 138 rv = (count == 0) ? B_OK : B_ERROR; 139 val(rv); 140 141 out("Calling GetConnectedInputsFor(source) (should fail)\n"); 142 rv = roster->GetConnectedInputsFor(sourceNode,inputs,2,&count); 143 val(rv); 144 out("Found %ld\n",count); 145 146 out("Calling GetConnectedOutputsFor(destination) (should fail)\n"); 147 rv = roster->GetConnectedOutputsFor(destinationNode,outputs,2,&count); 148 val(rv); 149 out("Found %ld\n",count); 150 151 out("Calling GetFreeOutputsFor(source)\n"); 152 rv = roster->GetFreeOutputsFor(sourceNode,&output,1,&count,B_MEDIA_RAW_AUDIO); 153 val(rv); 154 out("Found %ld\n",count); 155 rv = (count == 1) ? B_OK : B_ERROR; 156 val(rv); 157 158 out("Calling GetFreeInputsFor(destination)\n"); 159 rv = roster->GetFreeInputsFor(destinationNode,&input,1,&count,B_MEDIA_RAW_AUDIO); 160 val(rv); 161 out("Found %ld\n",count); 162 rv = (count == 1) ? B_OK : B_ERROR; 163 val(rv); 164 165 out("Calling GetFreeOutputsFor(destination) (should fail)\n"); 166 rv = roster->GetFreeOutputsFor(destinationNode,outputs,2,&count,B_MEDIA_RAW_AUDIO); 167 val(rv); 168 out("Found %ld\n",count); 169 170 out("Calling GetFreeInputsFor(source) (should fail)\n"); 171 rv = roster->GetFreeInputsFor(sourceNode,inputs,2,&count,B_MEDIA_RAW_AUDIO); 172 val(rv); 173 out("Found %ld\n",count); 174 175 media_format format; 176 format.type = B_MEDIA_RAW_AUDIO; 177 format.u.raw_audio = media_raw_audio_format::wildcard; 178 179 out("Connecting nodes\n"); 180 rv = roster->Connect(output.source, input.destination, &format, &output, &input); 181 val(rv); 182 183 out("Prerolling Producer()\n"); 184 rv = roster->PrerollNode(sourceNode); 185 val(rv); 186 187 out("Prerolling Consumer\n"); 188 rv = roster->PrerollNode(destinationNode); 189 val(rv); 190 191 bigtime_t time1; 192 bigtime_t time2; 193 bigtime_t start; 194 195 out("Getting Producer startlatency\n"); 196 rv = roster->GetStartLatencyFor(destinationNode, &time1); 197 val(rv); 198 199 out("Getting Consumer startlatency\n"); 200 rv = roster->GetStartLatencyFor(sourceNode, &time2); 201 val(rv); 202 203 start = max_c(time1,time2) + producer->TimeSource()->PerformanceTimeFor(BTimeSource::RealTime() + 2000000); 204 205 out("Starting Consumer in 2 sec\n"); 206 rv = roster->StartNode(destinationNode, start); 207 val(rv); 208 209 out("Starting Producer in 2 sec\n"); 210 rv = roster->StartNode(sourceNode, start); 211 val(rv); 212 213 out("########################## PRESS ENTER TO QUIT ##########################\n"); 214 getchar(); 215 216 media_node_id sourceNodeID; 217 media_node_id destinationNodeID; 218 219 out("Calling producer->ID()\n"); 220 sourceNodeID = producer->ID(); 221 222 out("Calling consumer->ID()\n"); 223 destinationNodeID = consumer->ID(); 224 225 out("Stopping Producer()\n"); 226 rv = roster->StopNode(sourceNode, 0, true); 227 val(rv); 228 229 out("Stopping Consumer\n"); 230 rv = roster->StopNode(destinationNode, 0, true); 231 val(rv); 232 233 out("Disconnecting nodes\n"); 234 rv = roster->Disconnect(sourceNodeID, output.source, destinationNodeID, input.destination); 235 val(rv); 236 237 out("Unregistering ProducerNode\n"); 238 rv = roster->UnregisterNode(producer); 239 val(rv); 240 241 out("Unregistering ConsumerNode\n"); 242 rv = roster->UnregisterNode(consumer); 243 val(rv); 244 245 out("Releasing ProducerNode\n"); 246 rv = (producer->Release() == NULL) ? B_OK : B_ERROR; 247 val(rv); 248 249 out("Releasing ConsumerNode\n"); 250 rv = (consumer->Release() == NULL) ? B_OK : B_ERROR; 251 val(rv); 252 253 return 0; 254 } 255 256