152a38012Sejakowatz /*********************************************************************** 252a38012Sejakowatz * AUTHOR: Marcus Overhagen 352a38012Sejakowatz * FILE: MediaRoster.cpp 452a38012Sejakowatz * DESCR: 552a38012Sejakowatz ***********************************************************************/ 652a38012Sejakowatz #include <MediaRoster.h> 752a38012Sejakowatz #include <Locker.h> 852a38012Sejakowatz #include <Message.h> 952a38012Sejakowatz #include <Messenger.h> 1052a38012Sejakowatz #include <StopWatch.h> 1152a38012Sejakowatz #include <OS.h> 1252a38012Sejakowatz #include <String.h> 1352a38012Sejakowatz #include <TimeSource.h> 1452a38012Sejakowatz #include "debug.h" 153620737cSbeveloper #include "TStack.h" 1652a38012Sejakowatz #include "PortPool.h" 171299bfb2Sbeveloper #include "SystemTimeSource.h" 180a483e72SIngo Weinhold #include "ServerInterface.h" 19f4925104Sbeveloper #include "DataExchange.h" 2016b7eea4Sbeveloper #include "DormantNodeManager.h" 21f4925104Sbeveloper #include "Notifications.h" 2252a38012Sejakowatz 23f4925104Sbeveloper namespace BPrivate { namespace media { 24f4925104Sbeveloper extern team_id team; 253620737cSbeveloper } } // BPrivate::media 263620737cSbeveloper 273620737cSbeveloper using namespace BPrivate::media; 2852a38012Sejakowatz 2952a38012Sejakowatz // the BMediaRoster destructor is private, 3052a38012Sejakowatz // but _DefaultDeleter is a friend class of 3152a38012Sejakowatz // the BMediaRoster an thus can delete it 3252a38012Sejakowatz class _DefaultDeleter 3352a38012Sejakowatz { 3452a38012Sejakowatz public: 356396865dSbeveloper ~_DefaultDeleter() 366396865dSbeveloper { 376396865dSbeveloper if (BMediaRoster::_sDefault) { 386396865dSbeveloper BMediaRoster::_sDefault->Lock(); 396396865dSbeveloper BMediaRoster::_sDefault->Quit(); 406396865dSbeveloper } 416396865dSbeveloper } 426396865dSbeveloper } _deleter; 4352a38012Sejakowatz 443620737cSbeveloper namespace BPrivate { namespace media { namespace mediaroster { 4552a38012Sejakowatz 4652a38012Sejakowatz status_t GetNode(node_type type, media_node * out_node, int32 * out_input_id = NULL, BString * out_input_name = NULL); 4752a38012Sejakowatz status_t SetNode(node_type type, const media_node *node, const dormant_node_info *info = NULL, const media_input *input = NULL); 483620737cSbeveloper status_t GetAllOutputs(const media_node & node, Stack<media_output> *stack); 493620737cSbeveloper status_t GetAllInputs(const media_node & node, Stack<media_input> *stack); 503620737cSbeveloper status_t PublishOutputs(const media_node & node, Stack<media_output> *stack); 513620737cSbeveloper status_t PublishInputs(const media_node & node, Stack<media_input> *stack); 5252a38012Sejakowatz 533620737cSbeveloper status_t 543620737cSbeveloper GetNode(node_type type, media_node * out_node, int32 * out_input_id, BString * out_input_name) 5552a38012Sejakowatz { 5652a38012Sejakowatz if (out_node == NULL) 5752a38012Sejakowatz return B_BAD_VALUE; 5852a38012Sejakowatz 598c6a6096Sbeveloper server_get_node_request request; 608c6a6096Sbeveloper server_get_node_reply reply; 6152a38012Sejakowatz status_t rv; 6252a38012Sejakowatz 638c6a6096Sbeveloper request.type = type; 649e9417d2Sbeveloper request.team = team; 658c6a6096Sbeveloper rv = QueryServer(SERVER_GET_NODE, &request, sizeof(request), &reply, sizeof(reply)); 668c6a6096Sbeveloper if (rv != B_OK) 678c6a6096Sbeveloper return rv; 6852a38012Sejakowatz 6952a38012Sejakowatz *out_node = reply.node; 7052a38012Sejakowatz if (out_input_id) 7152a38012Sejakowatz *out_input_id = reply.input_id; 7252a38012Sejakowatz if (out_input_name) 7352a38012Sejakowatz *out_input_name = reply.input_name; 748c6a6096Sbeveloper return rv; 7552a38012Sejakowatz } 7652a38012Sejakowatz 773620737cSbeveloper status_t 783620737cSbeveloper SetNode(node_type type, const media_node *node, const dormant_node_info *info, const media_input *input) 7952a38012Sejakowatz { 808c6a6096Sbeveloper server_set_node_request request; 818c6a6096Sbeveloper server_set_node_reply reply; 8252a38012Sejakowatz 838c6a6096Sbeveloper request.type = type; 848c6a6096Sbeveloper request.use_node = node ? true : false; 8552a38012Sejakowatz if (node) 868c6a6096Sbeveloper request.node = *node; 878c6a6096Sbeveloper request.use_dni = info ? true : false; 8852a38012Sejakowatz if (info) 898c6a6096Sbeveloper request.dni = *info; 908c6a6096Sbeveloper request.use_input = input ? true : false; 9152a38012Sejakowatz if (input) 928c6a6096Sbeveloper request.input = *input; 9352a38012Sejakowatz 948c6a6096Sbeveloper return QueryServer(SERVER_SET_NODE, &request, sizeof(request), &reply, sizeof(reply)); 9552a38012Sejakowatz } 9652a38012Sejakowatz 973620737cSbeveloper status_t 983620737cSbeveloper GetAllOutputs(const media_node & node, Stack<media_output> *stack) 993620737cSbeveloper { 1003620737cSbeveloper int32 cookie; 1013620737cSbeveloper status_t rv; 1023620737cSbeveloper status_t result; 1033620737cSbeveloper 1043620737cSbeveloper result = B_OK; 1053620737cSbeveloper cookie = 0; 1063620737cSbeveloper for (;;) { 1073620737cSbeveloper producer_get_next_output_request request; 1083620737cSbeveloper producer_get_next_output_reply reply; 1093620737cSbeveloper request.cookie = cookie; 1100caff283Sbeveloper rv = QueryPort(node.port, PRODUCER_GET_NEXT_OUTPUT, &request, sizeof(request), &reply, sizeof(reply)); 1113620737cSbeveloper if (rv != B_OK) 1123620737cSbeveloper break; 1133620737cSbeveloper cookie = reply.cookie; 1143620737cSbeveloper if (!stack->Push(reply.output)) { 115*353b9f6bSbeveloper FATAL("GetAllOutputs: stack->Push failed\n"); 1163620737cSbeveloper result = B_ERROR; 1173620737cSbeveloper } 1183620737cSbeveloper } 1193620737cSbeveloper 1203620737cSbeveloper producer_dispose_output_cookie_request request; 1213620737cSbeveloper producer_dispose_output_cookie_reply reply; 1220caff283Sbeveloper QueryPort(node.port, PRODUCER_DISPOSE_OUTPUT_COOKIE, &request, sizeof(request), &reply, sizeof(reply)); 1233620737cSbeveloper 1243620737cSbeveloper return result; 1253620737cSbeveloper } 1263620737cSbeveloper 1273620737cSbeveloper status_t 1283620737cSbeveloper GetAllInputs(const media_node & node, Stack<media_input> *stack) 1293620737cSbeveloper { 1303620737cSbeveloper int32 cookie; 1313620737cSbeveloper status_t rv; 1323620737cSbeveloper status_t result; 1333620737cSbeveloper 1343620737cSbeveloper result = B_OK; 1353620737cSbeveloper cookie = 0; 1363620737cSbeveloper for (;;) { 1373620737cSbeveloper consumer_get_next_input_request request; 1383620737cSbeveloper consumer_get_next_input_reply reply; 1393620737cSbeveloper request.cookie = cookie; 1400caff283Sbeveloper rv = QueryPort(node.port, CONSUMER_GET_NEXT_INPUT, &request, sizeof(request), &reply, sizeof(reply)); 1413620737cSbeveloper if (rv != B_OK) 1423620737cSbeveloper break; 1433620737cSbeveloper cookie = reply.cookie; 1443620737cSbeveloper if (!stack->Push(reply.input)) { 145*353b9f6bSbeveloper FATAL("GetAllInputs: stack->Push failed\n"); 1463620737cSbeveloper result = B_ERROR; 1473620737cSbeveloper } 1483620737cSbeveloper } 1493620737cSbeveloper 1503620737cSbeveloper consumer_dispose_input_cookie_request request; 1513620737cSbeveloper consumer_dispose_input_cookie_reply reply; 1520caff283Sbeveloper QueryPort(node.port, CONSUMER_DISPOSE_INPUT_COOKIE, &request, sizeof(request), &reply, sizeof(reply)); 1533620737cSbeveloper 1543620737cSbeveloper return result; 1553620737cSbeveloper } 1563620737cSbeveloper 1573620737cSbeveloper status_t 1583620737cSbeveloper PublishOutputs(const media_node & node, Stack<media_output> *stack) 1593620737cSbeveloper { 1603620737cSbeveloper server_publish_outputs_request request; 1613620737cSbeveloper server_publish_outputs_reply reply; 1623620737cSbeveloper media_output *output; 1633620737cSbeveloper media_output *outputs; 1643620737cSbeveloper int32 count; 165a7b41a96Sbeveloper status_t rv; 1663620737cSbeveloper 1673620737cSbeveloper count = stack->CountItems(); 1683620737cSbeveloper TRACE("PublishOutputs: publishing %ld\n", count); 1693620737cSbeveloper 1703620737cSbeveloper request.node = node; 1713620737cSbeveloper request.count = count; 1723620737cSbeveloper if (count > MAX_OUTPUTS) { 1733620737cSbeveloper void *start_addr; 1743620737cSbeveloper size_t size; 1753620737cSbeveloper size = ((count * sizeof(media_output)) + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1); 1763620737cSbeveloper request.area = create_area("publish outputs", &start_addr, B_ANY_ADDRESS, size, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA); 1773620737cSbeveloper if (request.area < B_OK) { 178*353b9f6bSbeveloper FATAL("PublishOutputs: failed to create area, %#lx\n", request.area); 1793620737cSbeveloper return (status_t)request.area; 1803620737cSbeveloper } 1813620737cSbeveloper outputs = static_cast<media_output *>(start_addr); 1823620737cSbeveloper } else { 1833620737cSbeveloper request.area = -1; 1843620737cSbeveloper outputs = request.outputs; 1853620737cSbeveloper } 1863620737cSbeveloper TRACE("PublishOutputs: area %#lx\n", request.area); 1873620737cSbeveloper 1883620737cSbeveloper for (int32 i = 0; i != count; i++) { 1893620737cSbeveloper stack->GetPointerAt(i, &output); 1903620737cSbeveloper outputs[i] = *output; 1913620737cSbeveloper } 1923620737cSbeveloper 193a7b41a96Sbeveloper rv = QueryServer(SERVER_PUBLISH_OUTPUTS, &request, sizeof(request), &reply, sizeof(reply)); 194a7b41a96Sbeveloper 195a7b41a96Sbeveloper if (request.area != -1) 196a7b41a96Sbeveloper delete_area(request.area); 197a7b41a96Sbeveloper 198a7b41a96Sbeveloper return rv; 1993620737cSbeveloper } 2003620737cSbeveloper 2013620737cSbeveloper status_t 2023620737cSbeveloper PublishInputs(const media_node & node, Stack<media_input> *stack) 2033620737cSbeveloper { 2043620737cSbeveloper server_publish_inputs_request request; 2053620737cSbeveloper server_publish_inputs_reply reply; 2063620737cSbeveloper media_input *input; 2073620737cSbeveloper media_input *inputs; 2083620737cSbeveloper int32 count; 209a7b41a96Sbeveloper status_t rv; 2103620737cSbeveloper 2113620737cSbeveloper count = stack->CountItems(); 2123620737cSbeveloper TRACE("PublishInputs: publishing %ld\n", count); 2133620737cSbeveloper 2143620737cSbeveloper request.node = node; 2153620737cSbeveloper request.count = count; 2163620737cSbeveloper if (count > MAX_INPUTS) { 2173620737cSbeveloper void *start_addr; 2183620737cSbeveloper size_t size; 2193620737cSbeveloper size = ((count * sizeof(media_input)) + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1); 2203620737cSbeveloper request.area = create_area("publish inputs", &start_addr, B_ANY_ADDRESS, size, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA); 2213620737cSbeveloper if (request.area < B_OK) { 222*353b9f6bSbeveloper FATAL("PublishInputs: failed to create area, %#lx\n", request.area); 2233620737cSbeveloper return (status_t)request.area; 2243620737cSbeveloper } 2253620737cSbeveloper inputs = static_cast<media_input *>(start_addr); 2263620737cSbeveloper } else { 2273620737cSbeveloper request.area = -1; 2283620737cSbeveloper inputs = request.inputs; 2293620737cSbeveloper } 2303620737cSbeveloper TRACE("PublishInputs: area %#lx\n", request.area); 2313620737cSbeveloper 2323620737cSbeveloper for (int32 i = 0; i != count; i++) { 2333620737cSbeveloper stack->GetPointerAt(i, &input); 2343620737cSbeveloper inputs[i] = *input; 2353620737cSbeveloper } 2363620737cSbeveloper 237a7b41a96Sbeveloper rv = QueryServer(SERVER_PUBLISH_INPUTS, &request, sizeof(request), &reply, sizeof(reply)); 238a7b41a96Sbeveloper 239a7b41a96Sbeveloper if (request.area != -1) 240a7b41a96Sbeveloper delete_area(request.area); 241a7b41a96Sbeveloper 242a7b41a96Sbeveloper return rv; 2433620737cSbeveloper } 2443620737cSbeveloper 2453620737cSbeveloper } } } // namespace BPrivate::media::mediaroster 2463620737cSbeveloper 2473620737cSbeveloper using namespace BPrivate::media::mediaroster; 24852a38012Sejakowatz 24952a38012Sejakowatz /************************************************************* 25052a38012Sejakowatz * public BMediaRoster 25152a38012Sejakowatz *************************************************************/ 25252a38012Sejakowatz 25352a38012Sejakowatz status_t 25452a38012Sejakowatz BMediaRoster::GetVideoInput(media_node * out_node) 25552a38012Sejakowatz { 25652a38012Sejakowatz CALLED(); 2573620737cSbeveloper return GetNode(VIDEO_INPUT, out_node); 25852a38012Sejakowatz } 25952a38012Sejakowatz 26052a38012Sejakowatz 26152a38012Sejakowatz status_t 26252a38012Sejakowatz BMediaRoster::GetAudioInput(media_node * out_node) 26352a38012Sejakowatz { 26452a38012Sejakowatz CALLED(); 2653620737cSbeveloper return GetNode(AUDIO_INPUT, out_node); 26652a38012Sejakowatz } 26752a38012Sejakowatz 26852a38012Sejakowatz 26952a38012Sejakowatz status_t 27052a38012Sejakowatz BMediaRoster::GetVideoOutput(media_node * out_node) 27152a38012Sejakowatz { 27252a38012Sejakowatz CALLED(); 2733620737cSbeveloper return GetNode(VIDEO_OUTPUT, out_node); 27452a38012Sejakowatz } 27552a38012Sejakowatz 27652a38012Sejakowatz 27752a38012Sejakowatz status_t 27852a38012Sejakowatz BMediaRoster::GetAudioMixer(media_node * out_node) 27952a38012Sejakowatz { 28052a38012Sejakowatz CALLED(); 2813620737cSbeveloper return GetNode(AUDIO_MIXER, out_node); 28252a38012Sejakowatz } 28352a38012Sejakowatz 28452a38012Sejakowatz 28552a38012Sejakowatz status_t 28652a38012Sejakowatz BMediaRoster::GetAudioOutput(media_node * out_node) 28752a38012Sejakowatz { 28852a38012Sejakowatz CALLED(); 2893620737cSbeveloper return GetNode(AUDIO_OUTPUT, out_node); 29052a38012Sejakowatz } 29152a38012Sejakowatz 29252a38012Sejakowatz 29352a38012Sejakowatz status_t 29452a38012Sejakowatz BMediaRoster::GetAudioOutput(media_node * out_node, 29552a38012Sejakowatz int32 * out_input_id, 29652a38012Sejakowatz BString * out_input_name) 29752a38012Sejakowatz { 29852a38012Sejakowatz CALLED(); 2993620737cSbeveloper return GetNode(AUDIO_OUTPUT_EX, out_node, out_input_id, out_input_name); 30052a38012Sejakowatz } 30152a38012Sejakowatz 30252a38012Sejakowatz 30352a38012Sejakowatz status_t 30452a38012Sejakowatz BMediaRoster::GetTimeSource(media_node * out_node) 30552a38012Sejakowatz { 30652a38012Sejakowatz CALLED(); 3073620737cSbeveloper return GetNode(TIME_SOURCE, out_node); 30852a38012Sejakowatz } 30952a38012Sejakowatz 31052a38012Sejakowatz 31152a38012Sejakowatz status_t 31252a38012Sejakowatz BMediaRoster::SetVideoInput(const media_node & producer) 31352a38012Sejakowatz { 31452a38012Sejakowatz CALLED(); 3153620737cSbeveloper return SetNode(VIDEO_INPUT, &producer); 31652a38012Sejakowatz } 31752a38012Sejakowatz 31852a38012Sejakowatz 31952a38012Sejakowatz status_t 32052a38012Sejakowatz BMediaRoster::SetVideoInput(const dormant_node_info & producer) 32152a38012Sejakowatz { 32252a38012Sejakowatz CALLED(); 3233620737cSbeveloper return SetNode(VIDEO_INPUT, NULL, &producer); 32452a38012Sejakowatz } 32552a38012Sejakowatz 32652a38012Sejakowatz 32752a38012Sejakowatz status_t 32852a38012Sejakowatz BMediaRoster::SetAudioInput(const media_node & producer) 32952a38012Sejakowatz { 33052a38012Sejakowatz CALLED(); 3313620737cSbeveloper return SetNode(AUDIO_INPUT, &producer); 33252a38012Sejakowatz } 33352a38012Sejakowatz 33452a38012Sejakowatz 33552a38012Sejakowatz status_t 33652a38012Sejakowatz BMediaRoster::SetAudioInput(const dormant_node_info & producer) 33752a38012Sejakowatz { 33852a38012Sejakowatz CALLED(); 3393620737cSbeveloper return SetNode(AUDIO_INPUT, NULL, &producer); 34052a38012Sejakowatz } 34152a38012Sejakowatz 34252a38012Sejakowatz 34352a38012Sejakowatz status_t 34452a38012Sejakowatz BMediaRoster::SetVideoOutput(const media_node & consumer) 34552a38012Sejakowatz { 34652a38012Sejakowatz CALLED(); 3473620737cSbeveloper return SetNode(VIDEO_OUTPUT, &consumer); 34852a38012Sejakowatz } 34952a38012Sejakowatz 35052a38012Sejakowatz 35152a38012Sejakowatz status_t 35252a38012Sejakowatz BMediaRoster::SetVideoOutput(const dormant_node_info & consumer) 35352a38012Sejakowatz { 35452a38012Sejakowatz CALLED(); 3553620737cSbeveloper return SetNode(VIDEO_OUTPUT, NULL, &consumer); 35652a38012Sejakowatz } 35752a38012Sejakowatz 35852a38012Sejakowatz 35952a38012Sejakowatz status_t 36052a38012Sejakowatz BMediaRoster::SetAudioOutput(const media_node & consumer) 36152a38012Sejakowatz { 36252a38012Sejakowatz CALLED(); 3633620737cSbeveloper return SetNode(AUDIO_OUTPUT, &consumer); 36452a38012Sejakowatz } 36552a38012Sejakowatz 36652a38012Sejakowatz 36752a38012Sejakowatz status_t 36852a38012Sejakowatz BMediaRoster::SetAudioOutput(const media_input & input_to_output) 36952a38012Sejakowatz { 37052a38012Sejakowatz CALLED(); 3713620737cSbeveloper return SetNode(AUDIO_OUTPUT, NULL, NULL, &input_to_output); 37252a38012Sejakowatz } 37352a38012Sejakowatz 37452a38012Sejakowatz 37552a38012Sejakowatz status_t 37652a38012Sejakowatz BMediaRoster::SetAudioOutput(const dormant_node_info & consumer) 37752a38012Sejakowatz { 37852a38012Sejakowatz CALLED(); 3793620737cSbeveloper return SetNode(AUDIO_OUTPUT, NULL, &consumer); 38052a38012Sejakowatz } 38152a38012Sejakowatz 38252a38012Sejakowatz 38352a38012Sejakowatz status_t 38452a38012Sejakowatz BMediaRoster::GetNodeFor(media_node_id node, 38552a38012Sejakowatz media_node * clone) 38652a38012Sejakowatz { 3879e9417d2Sbeveloper CALLED(); 3889e9417d2Sbeveloper if (clone == NULL) 3899e9417d2Sbeveloper return B_BAD_VALUE; 3909e9417d2Sbeveloper if (node <= 0) 3919e9417d2Sbeveloper return B_MEDIA_BAD_NODE; 3929e9417d2Sbeveloper 3939e9417d2Sbeveloper server_get_node_for_request request; 3949e9417d2Sbeveloper server_get_node_for_reply reply; 3959e9417d2Sbeveloper status_t rv; 3969e9417d2Sbeveloper 3979e9417d2Sbeveloper request.nodeid = node; 3989e9417d2Sbeveloper request.team = team; 3999e9417d2Sbeveloper 4009e9417d2Sbeveloper rv = QueryServer(SERVER_GET_NODE_FOR, &request, sizeof(request), &reply, sizeof(reply)); 4019e9417d2Sbeveloper if (rv != B_OK) 4029e9417d2Sbeveloper return rv; 4039e9417d2Sbeveloper 4049e9417d2Sbeveloper *clone = reply.clone; 4059e9417d2Sbeveloper return B_OK; 40652a38012Sejakowatz } 40752a38012Sejakowatz 40852a38012Sejakowatz 40952a38012Sejakowatz status_t 41052a38012Sejakowatz BMediaRoster::GetSystemTimeSource(media_node * clone) 41152a38012Sejakowatz { 41252a38012Sejakowatz CALLED(); 4133620737cSbeveloper return GetNode(SYSTEM_TIME_SOURCE, clone); 41452a38012Sejakowatz } 41552a38012Sejakowatz 41652a38012Sejakowatz 41752a38012Sejakowatz status_t 41852a38012Sejakowatz BMediaRoster::ReleaseNode(const media_node & node) 41952a38012Sejakowatz { 4209e9417d2Sbeveloper CALLED(); 4219e9417d2Sbeveloper if (node.node <= 0) 4229e9417d2Sbeveloper return B_MEDIA_BAD_NODE; 42352a38012Sejakowatz 4249e9417d2Sbeveloper server_release_node_request request; 4259e9417d2Sbeveloper server_release_node_reply reply; 4269e9417d2Sbeveloper 4279e9417d2Sbeveloper request.node = node; 4289e9417d2Sbeveloper request.team = team; 4299e9417d2Sbeveloper 4309e9417d2Sbeveloper return QueryServer(SERVER_RELEASE_NODE, &request, sizeof(request), &reply, sizeof(reply)); 4319e9417d2Sbeveloper } 43252a38012Sejakowatz 43352a38012Sejakowatz 43452a38012Sejakowatz BTimeSource * 43552a38012Sejakowatz BMediaRoster::MakeTimeSourceFor(const media_node & for_node) 43652a38012Sejakowatz { 4371299bfb2Sbeveloper BROKEN(); 4381299bfb2Sbeveloper return new _SysTimeSource(); // XXX fix this 43952a38012Sejakowatz } 44052a38012Sejakowatz 44152a38012Sejakowatz 44252a38012Sejakowatz status_t 44352a38012Sejakowatz BMediaRoster::Connect(const media_source & from, 44452a38012Sejakowatz const media_destination & to, 44552a38012Sejakowatz media_format * io_format, 44652a38012Sejakowatz media_output * out_output, 44752a38012Sejakowatz media_input * out_input) 44852a38012Sejakowatz { 449eae26d3dSbeveloper return BMediaRoster::Connect(from, to, io_format, out_output, out_input, 0); 450eae26d3dSbeveloper } 451eae26d3dSbeveloper 452eae26d3dSbeveloper 453eae26d3dSbeveloper status_t 454eae26d3dSbeveloper BMediaRoster::Connect(const media_source & from, 455eae26d3dSbeveloper const media_destination & to, 456eae26d3dSbeveloper media_format * io_format, 457eae26d3dSbeveloper media_output * out_output, 458eae26d3dSbeveloper media_input * out_input, 459eae26d3dSbeveloper uint32 in_flags, 460eae26d3dSbeveloper void * _reserved) 461eae26d3dSbeveloper { 46252a38012Sejakowatz CALLED(); 46352a38012Sejakowatz if (io_format == NULL || out_output == NULL || out_input == NULL) 46452a38012Sejakowatz return B_BAD_VALUE; 4659e9417d2Sbeveloper if (from == media_source::null) { 466*353b9f6bSbeveloper FATAL("BMediaRoster::Connect: media_source invalid\n"); 46752a38012Sejakowatz return B_MEDIA_BAD_SOURCE; 4689e9417d2Sbeveloper } 4699e9417d2Sbeveloper if (to == media_destination::null) { 470*353b9f6bSbeveloper FATAL("BMediaRoster::Connect: media_destination invalid\n"); 47152a38012Sejakowatz return B_MEDIA_BAD_DESTINATION; 4729e9417d2Sbeveloper } 47352a38012Sejakowatz 47452a38012Sejakowatz status_t rv; 4758c6a6096Sbeveloper producer_format_proposal_request request1; 4768c6a6096Sbeveloper producer_format_proposal_reply reply1; 47752a38012Sejakowatz 47852a38012Sejakowatz // BBufferProducer::FormatProposal 4798c6a6096Sbeveloper request1.output = from; 4808c6a6096Sbeveloper request1.format = *io_format; 4818c6a6096Sbeveloper rv = QueryPort(from.port, PRODUCER_FORMAT_PROPOSAL, &request1, sizeof(request1), &reply1, sizeof(reply1)); 4828c6a6096Sbeveloper if (rv != B_OK) { 483*353b9f6bSbeveloper FATAL("BMediaRoster::Connect: aborted after BBufferProducer::FormatProposal, status = %#lx\n",rv); 48452a38012Sejakowatz return rv; 48552a38012Sejakowatz } 4868c6a6096Sbeveloper // reply1.format now contains the format proposed by the producer 4878c6a6096Sbeveloper 4888c6a6096Sbeveloper consumer_accept_format_request request2; 4898c6a6096Sbeveloper consumer_accept_format_reply reply2; 4908c6a6096Sbeveloper 4918c6a6096Sbeveloper // BBufferConsumer::AcceptFormat 4928c6a6096Sbeveloper request2.dest = to; 4938c6a6096Sbeveloper request2.format = reply1.format; 4948c6a6096Sbeveloper rv = QueryPort(to.port, CONSUMER_ACCEPT_FORMAT, &request2, sizeof(request2), &reply2, sizeof(reply2)); 4958c6a6096Sbeveloper if (rv != B_OK) { 496*353b9f6bSbeveloper FATAL("BMediaRoster::Connect: aborted after BBufferConsumer::AcceptFormat, status = %#lx\n",rv); 4978c6a6096Sbeveloper return rv; 4988c6a6096Sbeveloper } 4998c6a6096Sbeveloper // reply2.format now contains the format accepted by the consumer 5008c6a6096Sbeveloper 5018c6a6096Sbeveloper // BBufferProducer::PrepareToConnect 5028c6a6096Sbeveloper producer_prepare_to_connect_request request3; 5038c6a6096Sbeveloper producer_prepare_to_connect_reply reply3; 5048c6a6096Sbeveloper 5058c6a6096Sbeveloper request3.source = from; 5068c6a6096Sbeveloper request3.destination = to; 5078c6a6096Sbeveloper request3.format = reply2.format; 5088c6a6096Sbeveloper strcpy(request3.name, "XXX some default name"); // XXX fix this 5098c6a6096Sbeveloper rv = QueryPort(from.port, PRODUCER_PREPARE_TO_CONNECT, &request3, sizeof(request3), &reply3, sizeof(reply3)); 5108c6a6096Sbeveloper if (rv != B_OK) { 511*353b9f6bSbeveloper FATAL("BMediaRoster::Connect: aborted after BBufferProducer::PrepareToConnect, status = %#lx\n",rv); 5128c6a6096Sbeveloper return rv; 5138c6a6096Sbeveloper } 5148c6a6096Sbeveloper // reply3.format is still our pretty media format 5158c6a6096Sbeveloper // reply3.out_source the real source to be used for the connection 5168c6a6096Sbeveloper // reply3.name the name BBufferConsumer::Connected will see in the outInput->name argument 5178c6a6096Sbeveloper 5188c6a6096Sbeveloper // BBufferConsumer::Connected 5198c6a6096Sbeveloper consumer_connected_request request4; 5208c6a6096Sbeveloper consumer_connected_reply reply4; 5218c6a6096Sbeveloper status_t con_status; 5228c6a6096Sbeveloper 5238c6a6096Sbeveloper request4.producer = reply3.out_source; 5248c6a6096Sbeveloper request4.where = to; 5258c6a6096Sbeveloper request4.with_format = reply3.format; 5268c6a6096Sbeveloper con_status = QueryPort(to.port, CONSUMER_CONNECTED, &request4, sizeof(request4), &reply4, sizeof(reply4)); 5278c6a6096Sbeveloper if (con_status != B_OK) { 528*353b9f6bSbeveloper FATAL("BMediaRoster::Connect: aborting after BBufferConsumer::Connected, status = %#lx\n",con_status); 5298c6a6096Sbeveloper // we do NOT return here! 5308c6a6096Sbeveloper } 5318c6a6096Sbeveloper // con_status contains the status code to be supplied to BBufferProducer::Connect's status argument 5328c6a6096Sbeveloper // reply4.input contains the media_input that describes the connection from the consumer point of view 5338c6a6096Sbeveloper 5348c6a6096Sbeveloper // BBufferProducer::Connect 5358c6a6096Sbeveloper producer_connect_request request5; 5368c6a6096Sbeveloper producer_connect_reply reply5; 5378c6a6096Sbeveloper 5388c6a6096Sbeveloper request5.error = con_status; 5398c6a6096Sbeveloper request5.source = reply3.out_source; 5408c6a6096Sbeveloper request5.destination = reply4.input.destination; 5418c6a6096Sbeveloper request5.format = reply3.format; // XXX reply4.input.format ??? 5428c6a6096Sbeveloper strcpy(request5.name, reply4.input.name); 5430caff283Sbeveloper rv = QueryPort(reply4.input.source.port, PRODUCER_CONNECT, &request5, sizeof(request5), &reply5, sizeof(reply5)); 5448c6a6096Sbeveloper if (con_status != B_OK) { 545*353b9f6bSbeveloper FATAL("BMediaRoster::Connect: aborted\n"); 5468c6a6096Sbeveloper return con_status; 5478c6a6096Sbeveloper } 5488c6a6096Sbeveloper if (rv != B_OK) { 549*353b9f6bSbeveloper FATAL("BMediaRoster::Connect: aborted after BBufferProducer::Connect, status = %#lx\n",rv); 5508c6a6096Sbeveloper return rv; 5518c6a6096Sbeveloper } 5528c6a6096Sbeveloper // reply5.name contains the name assigned to the connection by the producer 5538c6a6096Sbeveloper 5548c6a6096Sbeveloper // find the output node 5558c6a6096Sbeveloper // XXX isn't there a easier way? 5568c6a6096Sbeveloper media_node sourcenode; 5578c6a6096Sbeveloper GetNodeFor(NodeIDFor(from.port), &sourcenode); 5588c6a6096Sbeveloper ReleaseNode(sourcenode); 5598c6a6096Sbeveloper 5608c6a6096Sbeveloper // initilize connection info 5618c6a6096Sbeveloper *io_format = reply3.format; 5628c6a6096Sbeveloper *out_input = reply4.input; 5638c6a6096Sbeveloper out_output->node = sourcenode; 5648c6a6096Sbeveloper out_output->source = reply4.input.source; 5658c6a6096Sbeveloper out_output->destination = reply4.input.destination; 5668c6a6096Sbeveloper out_output->format = reply4.input.format; 5678c6a6096Sbeveloper strcpy(out_output->name, reply5.name); 5688c6a6096Sbeveloper 5698c6a6096Sbeveloper // the connection is now made 5708c6a6096Sbeveloper 5718c6a6096Sbeveloper 5728c6a6096Sbeveloper // XXX register connection with server 5739e9417d2Sbeveloper // XXX we should just send a notification, instead of republishing all endpoints 5749e9417d2Sbeveloper Stack<media_output> outstack; 5759e9417d2Sbeveloper Stack<media_input> instack; 5769e9417d2Sbeveloper if (B_OK == GetAllOutputs(out_output->node , &outstack)) 5779e9417d2Sbeveloper PublishOutputs(out_output->node , &outstack); 5789e9417d2Sbeveloper if (B_OK == GetAllInputs(out_input->node , &instack)) 5799e9417d2Sbeveloper PublishInputs(out_input->node, &instack); 5808c6a6096Sbeveloper 5818c6a6096Sbeveloper 5828c6a6096Sbeveloper // XXX if (mute) BBufferProducer::EnableOutput(false) 5839e9417d2Sbeveloper if (in_flags & B_CONNECT_MUTED) { 5849e9417d2Sbeveloper } 5858c6a6096Sbeveloper 5868c6a6096Sbeveloper 5879e9417d2Sbeveloper // send a notification 5889e9417d2Sbeveloper BPrivate::media::notifications::ConnectionMade(*out_input, *out_output, *io_format); 5899e9417d2Sbeveloper 5908c6a6096Sbeveloper return B_OK; 5918c6a6096Sbeveloper }; 59252a38012Sejakowatz 59352a38012Sejakowatz 59452a38012Sejakowatz status_t 5959e9417d2Sbeveloper BMediaRoster::Disconnect(media_node_id source_nodeid, 59652a38012Sejakowatz const media_source & source, 5979e9417d2Sbeveloper media_node_id destination_nodeid, 59852a38012Sejakowatz const media_destination & destination) 59952a38012Sejakowatz { 6009e9417d2Sbeveloper CALLED(); 6019e9417d2Sbeveloper if (source_nodeid <= 0) { 602*353b9f6bSbeveloper FATAL("BMediaRoster::Disconnect: source media_node_id invalid\n"); 6039e9417d2Sbeveloper return B_MEDIA_BAD_SOURCE; 6049e9417d2Sbeveloper } 6059e9417d2Sbeveloper if (destination_nodeid <= 0) { 606*353b9f6bSbeveloper FATAL("BMediaRoster::Disconnect: source media_node_id invalid\n"); 6079e9417d2Sbeveloper return B_MEDIA_BAD_DESTINATION; 6089e9417d2Sbeveloper } 6099e9417d2Sbeveloper if (source == media_source::null) { 610*353b9f6bSbeveloper FATAL("BMediaRoster::Disconnect: media_source invalid\n"); 6119e9417d2Sbeveloper return B_MEDIA_BAD_SOURCE; 6129e9417d2Sbeveloper } 6139e9417d2Sbeveloper if (destination == media_destination::null) { 614*353b9f6bSbeveloper FATAL("BMediaRoster::Disconnect: media_destination invalid\n"); 6159e9417d2Sbeveloper return B_MEDIA_BAD_DESTINATION; 6169e9417d2Sbeveloper } 6179e9417d2Sbeveloper 6189e9417d2Sbeveloper producer_disconnect_request request2; 6199e9417d2Sbeveloper producer_disconnect_reply reply2; 6209e9417d2Sbeveloper consumer_disconnected_request request1; 6219e9417d2Sbeveloper consumer_disconnected_reply reply1; 6229e9417d2Sbeveloper status_t rv1, rv2; 6239e9417d2Sbeveloper 6249e9417d2Sbeveloper // XXX we should ask the server if this connection really exists 6259e9417d2Sbeveloper 6269e9417d2Sbeveloper request1.source = source; 6279e9417d2Sbeveloper request1.destination = destination; 6289e9417d2Sbeveloper request2.source = source; 6299e9417d2Sbeveloper request2.destination = destination; 6309e9417d2Sbeveloper 6319e9417d2Sbeveloper rv1 = QueryPort(source.port, PRODUCER_DISCONNECT, &request1, sizeof(request1), &reply1, sizeof(reply1)); 6329e9417d2Sbeveloper rv2 = QueryPort(destination.port, CONSUMER_DISCONNECTED, &request2, sizeof(request2), &reply2, sizeof(reply2)); 6339e9417d2Sbeveloper 6349e9417d2Sbeveloper // XXX unregister connection with server 6359e9417d2Sbeveloper // XXX we should just send a notification, instead of republishing all endpoints 6369e9417d2Sbeveloper Stack<media_output> outstack; 6379e9417d2Sbeveloper Stack<media_input> instack; 6389e9417d2Sbeveloper media_node sourcenode; 6399e9417d2Sbeveloper media_node destnode; 6409e9417d2Sbeveloper if (B_OK == GetNodeFor(source_nodeid, &sourcenode)) { 6419e9417d2Sbeveloper if (B_OK == GetAllOutputs(sourcenode , &outstack)) 6429e9417d2Sbeveloper PublishOutputs(sourcenode , &outstack); 6439e9417d2Sbeveloper ReleaseNode(sourcenode); 644*353b9f6bSbeveloper } else FATAL("BMediaRoster::Disconnect: source GetNodeFor failed\n"); 6459e9417d2Sbeveloper if (B_OK == GetNodeFor(destination_nodeid, &destnode)) { 6469e9417d2Sbeveloper if (B_OK == GetAllInputs(destnode , &instack)) 6479e9417d2Sbeveloper PublishInputs(destnode, &instack); 6489e9417d2Sbeveloper ReleaseNode(destnode); 649*353b9f6bSbeveloper } else FATAL("BMediaRoster::Disconnect: dest GetNodeFor failed\n"); 6509e9417d2Sbeveloper 6519e9417d2Sbeveloper 6529e9417d2Sbeveloper // send a notification 6539e9417d2Sbeveloper BPrivate::media::notifications::ConnectionBroken(source, destination); 6549e9417d2Sbeveloper 6559e9417d2Sbeveloper return (rv1 != B_OK || rv2 != B_OK) ? B_ERROR : B_OK; 65652a38012Sejakowatz } 65752a38012Sejakowatz 65852a38012Sejakowatz 65952a38012Sejakowatz status_t 66052a38012Sejakowatz BMediaRoster::StartNode(const media_node & node, 66152a38012Sejakowatz bigtime_t at_performance_time) 66252a38012Sejakowatz { 66352a38012Sejakowatz CALLED(); 6649e9417d2Sbeveloper if (node.node <= 0) 66552a38012Sejakowatz return B_MEDIA_BAD_NODE; 66652a38012Sejakowatz 6676396865dSbeveloper node_start_command command; 6686396865dSbeveloper command.performance_time = at_performance_time; 66952a38012Sejakowatz 6706396865dSbeveloper return SendToPort(node.port, NODE_START, &command, sizeof(command)); 67152a38012Sejakowatz } 67252a38012Sejakowatz 67352a38012Sejakowatz 67452a38012Sejakowatz status_t 67552a38012Sejakowatz BMediaRoster::StopNode(const media_node & node, 67652a38012Sejakowatz bigtime_t at_performance_time, 67752a38012Sejakowatz bool immediate) 67852a38012Sejakowatz { 67952a38012Sejakowatz CALLED(); 6809e9417d2Sbeveloper if (node.node <= 0) 68152a38012Sejakowatz return B_MEDIA_BAD_NODE; 68252a38012Sejakowatz 6836396865dSbeveloper node_stop_command command; 6846396865dSbeveloper command.performance_time = at_performance_time; 6856396865dSbeveloper command.immediate = immediate; 68652a38012Sejakowatz 6876396865dSbeveloper return SendToPort(node.port, NODE_STOP, &command, sizeof(command)); 68852a38012Sejakowatz } 68952a38012Sejakowatz 69052a38012Sejakowatz 69152a38012Sejakowatz status_t 69252a38012Sejakowatz BMediaRoster::SeekNode(const media_node & node, 69352a38012Sejakowatz bigtime_t to_media_time, 69452a38012Sejakowatz bigtime_t at_performance_time) 69552a38012Sejakowatz { 69652a38012Sejakowatz CALLED(); 6979e9417d2Sbeveloper if (node.node <= 0) 69852a38012Sejakowatz return B_MEDIA_BAD_NODE; 69952a38012Sejakowatz 7006396865dSbeveloper node_seek_command command; 7016396865dSbeveloper command.media_time = to_media_time; 7026396865dSbeveloper command.performance_time = at_performance_time; 70352a38012Sejakowatz 7046396865dSbeveloper return SendToPort(node.port, NODE_SEEK, &command, sizeof(command)); 70552a38012Sejakowatz } 70652a38012Sejakowatz 70752a38012Sejakowatz 70852a38012Sejakowatz status_t 70952a38012Sejakowatz BMediaRoster::StartTimeSource(const media_node & node, 71052a38012Sejakowatz bigtime_t at_real_time) 71152a38012Sejakowatz { 71252a38012Sejakowatz CALLED(); 7139e9417d2Sbeveloper if (node.node <= 0) 71452a38012Sejakowatz return B_MEDIA_BAD_NODE; 71552a38012Sejakowatz if ((node.kind & B_TIME_SOURCE) == 0) 71652a38012Sejakowatz return B_MEDIA_BAD_NODE; 71752a38012Sejakowatz 71852a38012Sejakowatz BTimeSource::time_source_op_info msg; 71952a38012Sejakowatz msg.op = BTimeSource::B_TIMESOURCE_START; 72052a38012Sejakowatz msg.real_time = at_real_time; 72152a38012Sejakowatz 72252a38012Sejakowatz return write_port(node.port, TIMESOURCE_OP, &msg, sizeof(msg)); 72352a38012Sejakowatz } 72452a38012Sejakowatz 72552a38012Sejakowatz 72652a38012Sejakowatz status_t 72752a38012Sejakowatz BMediaRoster::StopTimeSource(const media_node & node, 72852a38012Sejakowatz bigtime_t at_real_time, 72952a38012Sejakowatz bool immediate) 73052a38012Sejakowatz { 73152a38012Sejakowatz CALLED(); 7329e9417d2Sbeveloper if (node.node <= 0) 73352a38012Sejakowatz return B_MEDIA_BAD_NODE; 73452a38012Sejakowatz if ((node.kind & B_TIME_SOURCE) == 0) 73552a38012Sejakowatz return B_MEDIA_BAD_NODE; 73652a38012Sejakowatz 73752a38012Sejakowatz BTimeSource::time_source_op_info msg; 73852a38012Sejakowatz msg.op = immediate ? BTimeSource::B_TIMESOURCE_STOP_IMMEDIATELY : BTimeSource::B_TIMESOURCE_STOP; 73952a38012Sejakowatz msg.real_time = at_real_time; 74052a38012Sejakowatz 74152a38012Sejakowatz return write_port(node.port, TIMESOURCE_OP, &msg, sizeof(msg)); 74252a38012Sejakowatz } 74352a38012Sejakowatz 74452a38012Sejakowatz 74552a38012Sejakowatz status_t 74652a38012Sejakowatz BMediaRoster::SeekTimeSource(const media_node & node, 74752a38012Sejakowatz bigtime_t to_performance_time, 74852a38012Sejakowatz bigtime_t at_real_time) 74952a38012Sejakowatz { 75052a38012Sejakowatz CALLED(); 7519e9417d2Sbeveloper if (node.node <= 0) 75252a38012Sejakowatz return B_MEDIA_BAD_NODE; 75352a38012Sejakowatz if ((node.kind & B_TIME_SOURCE) == 0) 75452a38012Sejakowatz return B_MEDIA_BAD_NODE; 75552a38012Sejakowatz 75652a38012Sejakowatz BTimeSource::time_source_op_info msg; 75752a38012Sejakowatz msg.op = BTimeSource::B_TIMESOURCE_SEEK; 75852a38012Sejakowatz msg.real_time = at_real_time; 75952a38012Sejakowatz msg.performance_time = to_performance_time; 76052a38012Sejakowatz 76152a38012Sejakowatz return write_port(node.port, TIMESOURCE_OP, &msg, sizeof(msg)); 76252a38012Sejakowatz } 76352a38012Sejakowatz 76452a38012Sejakowatz 76552a38012Sejakowatz status_t 76652a38012Sejakowatz BMediaRoster::SyncToNode(const media_node & node, 76752a38012Sejakowatz bigtime_t at_time, 76852a38012Sejakowatz bigtime_t timeout) 76952a38012Sejakowatz { 77052a38012Sejakowatz UNIMPLEMENTED(); 77152a38012Sejakowatz return B_ERROR; 77252a38012Sejakowatz } 77352a38012Sejakowatz 77452a38012Sejakowatz 77552a38012Sejakowatz status_t 77652a38012Sejakowatz BMediaRoster::SetRunModeNode(const media_node & node, 77752a38012Sejakowatz BMediaNode::run_mode mode) 77852a38012Sejakowatz { 77952a38012Sejakowatz CALLED(); 7809e9417d2Sbeveloper if (node.node <= 0) 78152a38012Sejakowatz return B_MEDIA_BAD_NODE; 78252a38012Sejakowatz 783dfb2ad61Sbeveloper node_set_run_mode_command msg; 78452a38012Sejakowatz msg.mode = mode; 78552a38012Sejakowatz 78652a38012Sejakowatz return write_port(node.port, NODE_SET_RUN_MODE, &msg, sizeof(msg)); 78752a38012Sejakowatz } 78852a38012Sejakowatz 78952a38012Sejakowatz 79052a38012Sejakowatz status_t 79152a38012Sejakowatz BMediaRoster::PrerollNode(const media_node & node) 79252a38012Sejakowatz { 79352a38012Sejakowatz CALLED(); 7949e9417d2Sbeveloper if (node.node <= 0) 79552a38012Sejakowatz return B_MEDIA_BAD_NODE; 79652a38012Sejakowatz 79752a38012Sejakowatz char dummy; 79852a38012Sejakowatz return write_port(node.port, NODE_PREROLL, &dummy, sizeof(dummy)); 79952a38012Sejakowatz } 80052a38012Sejakowatz 80152a38012Sejakowatz 80252a38012Sejakowatz status_t 80352a38012Sejakowatz BMediaRoster::RollNode(const media_node & node, 80452a38012Sejakowatz bigtime_t startPerformance, 80552a38012Sejakowatz bigtime_t stopPerformance, 80652a38012Sejakowatz bigtime_t atMediaTime) 80752a38012Sejakowatz { 80852a38012Sejakowatz UNIMPLEMENTED(); 80952a38012Sejakowatz return B_ERROR; 81052a38012Sejakowatz } 81152a38012Sejakowatz 81252a38012Sejakowatz 81352a38012Sejakowatz status_t 81452a38012Sejakowatz BMediaRoster::SetProducerRunModeDelay(const media_node & node, 81552a38012Sejakowatz bigtime_t delay, 81652a38012Sejakowatz BMediaNode::run_mode mode) 81752a38012Sejakowatz { 81852a38012Sejakowatz UNIMPLEMENTED(); 81952a38012Sejakowatz return B_ERROR; 82052a38012Sejakowatz } 82152a38012Sejakowatz 82252a38012Sejakowatz 82352a38012Sejakowatz status_t 82452a38012Sejakowatz BMediaRoster::SetProducerRate(const media_node & producer, 82552a38012Sejakowatz int32 numer, 82652a38012Sejakowatz int32 denom) 82752a38012Sejakowatz { 82852a38012Sejakowatz CALLED(); 82952a38012Sejakowatz if (producer.node == 0) 83052a38012Sejakowatz return B_MEDIA_BAD_NODE; 83152a38012Sejakowatz if ((producer.kind & B_BUFFER_PRODUCER) == 0) 83252a38012Sejakowatz return B_MEDIA_BAD_NODE; 83352a38012Sejakowatz 834dfb2ad61Sbeveloper producer_set_play_rate_request msg; 835dfb2ad61Sbeveloper producer_set_play_rate_reply reply; 83652a38012Sejakowatz status_t rv; 83752a38012Sejakowatz int32 code; 83852a38012Sejakowatz 83952a38012Sejakowatz msg.numer = numer; 84052a38012Sejakowatz msg.denom = denom; 84152a38012Sejakowatz msg.reply_port = _PortPool->GetPort(); 84252a38012Sejakowatz rv = write_port(producer.node, PRODUCER_SET_PLAY_RATE, &msg, sizeof(msg)); 84352a38012Sejakowatz if (rv != B_OK) { 84452a38012Sejakowatz _PortPool->PutPort(msg.reply_port); 84552a38012Sejakowatz return rv; 84652a38012Sejakowatz } 84752a38012Sejakowatz rv = read_port(msg.reply_port, &code, &reply, sizeof(reply)); 84852a38012Sejakowatz _PortPool->PutPort(msg.reply_port); 84952a38012Sejakowatz return (rv < B_OK) ? rv : reply.result; 85052a38012Sejakowatz } 85152a38012Sejakowatz 85252a38012Sejakowatz 85352a38012Sejakowatz /* Nodes will have available inputs/outputs as long as they are capable */ 85452a38012Sejakowatz /* of accepting more connections. The node may create an additional */ 85552a38012Sejakowatz /* output or input as the currently available is taken into usage. */ 85652a38012Sejakowatz status_t 85752a38012Sejakowatz BMediaRoster::GetLiveNodeInfo(const media_node & node, 85852a38012Sejakowatz live_node_info * out_live_info) 85952a38012Sejakowatz { 8609e9417d2Sbeveloper CALLED(); 8619e9417d2Sbeveloper if (out_live_info == NULL) 8629e9417d2Sbeveloper return B_BAD_VALUE; 8639e9417d2Sbeveloper if (node.node <= 0) 8649e9417d2Sbeveloper return B_MEDIA_BAD_NODE; 8659e9417d2Sbeveloper 8669e9417d2Sbeveloper server_get_live_node_info_request request; 8679e9417d2Sbeveloper server_get_live_node_info_reply reply; 8689e9417d2Sbeveloper status_t rv; 8699e9417d2Sbeveloper 8709e9417d2Sbeveloper request.node = node; 8719e9417d2Sbeveloper 8721299bfb2Sbeveloper rv = QueryServer(SERVER_GET_LIVE_NODE_INFO, &request, sizeof(request), &reply, sizeof(reply)); 8739e9417d2Sbeveloper if (rv != B_OK) 8749e9417d2Sbeveloper return rv; 8759e9417d2Sbeveloper 8769e9417d2Sbeveloper *out_live_info = reply.live_info; 8779e9417d2Sbeveloper return B_OK; 87852a38012Sejakowatz } 87952a38012Sejakowatz 88052a38012Sejakowatz 88152a38012Sejakowatz status_t 88252a38012Sejakowatz BMediaRoster::GetLiveNodes(live_node_info * out_live_nodes, 88352a38012Sejakowatz int32 * io_total_count, 88452a38012Sejakowatz const media_format * has_input, 88552a38012Sejakowatz const media_format * has_output, 88652a38012Sejakowatz const char * name, 88752a38012Sejakowatz uint64 node_kinds) 88852a38012Sejakowatz { 8899e9417d2Sbeveloper CALLED(); 8909e9417d2Sbeveloper if (out_live_nodes == NULL || io_total_count == NULL) 8919e9417d2Sbeveloper return B_BAD_VALUE; 8929e9417d2Sbeveloper if (*io_total_count <= 0) 8939e9417d2Sbeveloper return B_BAD_VALUE; 8949e9417d2Sbeveloper 8959e9417d2Sbeveloper // XXX we also support the wildcard search as GetDormantNodes does. This needs to be documented 8969e9417d2Sbeveloper 8979e9417d2Sbeveloper server_get_live_nodes_request request; 8989e9417d2Sbeveloper server_get_live_nodes_reply reply; 8999e9417d2Sbeveloper status_t rv; 9009e9417d2Sbeveloper 9019e9417d2Sbeveloper request.maxcount = *io_total_count; 9029e9417d2Sbeveloper request.has_input = (bool) has_input; 9039e9417d2Sbeveloper if (has_input) 9049e9417d2Sbeveloper request.inputformat = *has_input; // XXX we should not make a flat copy of media_format 9059e9417d2Sbeveloper request.has_output = (bool) has_output; 9069e9417d2Sbeveloper if (has_output) 9079e9417d2Sbeveloper request.outputformat = *has_output; // XXX we should not make a flat copy of media_format 9089e9417d2Sbeveloper request.has_name = (bool) name; 9099e9417d2Sbeveloper if (name) { 9109e9417d2Sbeveloper int len = strlen(name); 9119e9417d2Sbeveloper len = min_c(len, (int)sizeof(request.name) - 1); 9129e9417d2Sbeveloper memcpy(request.name, name, len); 9139e9417d2Sbeveloper request.name[len] = 0; 9149e9417d2Sbeveloper } 9159e9417d2Sbeveloper request.require_kinds = node_kinds; 9169e9417d2Sbeveloper 9179e9417d2Sbeveloper rv = QueryServer(SERVER_GET_LIVE_NODES, &request, sizeof(request), &reply, sizeof(reply)); 9189e9417d2Sbeveloper if (rv != B_OK) { 919*353b9f6bSbeveloper FATAL("BMediaRoster::GetLiveNodes failed\n"); 9201299bfb2Sbeveloper *io_total_count = 0; 9219e9417d2Sbeveloper return rv; 9229e9417d2Sbeveloper } 9239e9417d2Sbeveloper 9249e9417d2Sbeveloper if (reply.count > MAX_LIVE_INFO) { 9259e9417d2Sbeveloper live_node_info *live_info; 9269e9417d2Sbeveloper area_id clone; 9279e9417d2Sbeveloper 9289e9417d2Sbeveloper clone = clone_area("live_node_info clone", reinterpret_cast<void **>(&live_info), B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA, reply.area); 9299e9417d2Sbeveloper if (clone < B_OK) { 930*353b9f6bSbeveloper FATAL("BMediaRoster::GetLiveNodes failed to clone area, %#lx\n", clone); 9319e9417d2Sbeveloper delete_area(reply.area); 9321299bfb2Sbeveloper *io_total_count = 0; 93352a38012Sejakowatz return B_ERROR; 93452a38012Sejakowatz } 93552a38012Sejakowatz 9369e9417d2Sbeveloper for (int32 i = 0; i < reply.count; i++) { 9379e9417d2Sbeveloper out_live_nodes[i] = live_info[i]; 9389e9417d2Sbeveloper } 9399e9417d2Sbeveloper 9409e9417d2Sbeveloper delete_area(clone); 9419e9417d2Sbeveloper delete_area(reply.area); 9429e9417d2Sbeveloper } else { 9439e9417d2Sbeveloper for (int32 i = 0; i < reply.count; i++) { 9449e9417d2Sbeveloper out_live_nodes[i] = reply.live_info[i]; 9459e9417d2Sbeveloper } 9469e9417d2Sbeveloper } 9479e9417d2Sbeveloper *io_total_count = reply.count; 9489e9417d2Sbeveloper 9499e9417d2Sbeveloper return B_OK; 9509e9417d2Sbeveloper } 9519e9417d2Sbeveloper 95252a38012Sejakowatz 95352a38012Sejakowatz status_t 95452a38012Sejakowatz BMediaRoster::GetFreeInputsFor(const media_node & node, 95552a38012Sejakowatz media_input * out_free_inputs, 95652a38012Sejakowatz int32 buf_num_inputs, 95752a38012Sejakowatz int32 * out_total_count, 95852a38012Sejakowatz media_type filter_type) 95952a38012Sejakowatz { 9603620737cSbeveloper CALLED(); 9619e9417d2Sbeveloper if (node.node <= 0 || (node.kind & B_BUFFER_CONSUMER) == 0) 9623620737cSbeveloper return B_MEDIA_BAD_NODE; 9633620737cSbeveloper if (out_free_inputs == NULL || out_total_count == NULL) 9643620737cSbeveloper return B_BAD_VALUE; 9653620737cSbeveloper 9663620737cSbeveloper Stack<media_input> stack; 9673620737cSbeveloper media_input *input; 9683620737cSbeveloper status_t rv; 9693620737cSbeveloper 9701299bfb2Sbeveloper *out_total_count = 0; 9711299bfb2Sbeveloper 9723620737cSbeveloper rv = GetAllInputs(node, &stack); 9733620737cSbeveloper if (B_OK != rv) 9743620737cSbeveloper return rv; 9753620737cSbeveloper 9763620737cSbeveloper for (int32 i = 0; stack.GetPointerAt(i, &input); i++) { 9773620737cSbeveloper if (filter_type != B_MEDIA_UNKNOWN_TYPE && filter_type != input->format.type) 9783620737cSbeveloper continue; // media_type used, but doesn't match 9793620737cSbeveloper if (input->source != media_source::null) 9803620737cSbeveloper continue; // consumer source already connected 9813620737cSbeveloper out_free_inputs[i] = *input; 9823620737cSbeveloper *out_total_count += 1; 9833620737cSbeveloper buf_num_inputs -= 1; 9843620737cSbeveloper if (buf_num_inputs == 0) 9853620737cSbeveloper break; 9863620737cSbeveloper } 9873620737cSbeveloper 9883620737cSbeveloper PublishInputs(node, &stack); 9893620737cSbeveloper return B_OK; 99052a38012Sejakowatz } 99152a38012Sejakowatz 99252a38012Sejakowatz 99352a38012Sejakowatz status_t 99452a38012Sejakowatz BMediaRoster::GetConnectedInputsFor(const media_node & node, 99552a38012Sejakowatz media_input * out_active_inputs, 99652a38012Sejakowatz int32 buf_num_inputs, 99752a38012Sejakowatz int32 * out_total_count) 99852a38012Sejakowatz { 9993620737cSbeveloper CALLED(); 10009e9417d2Sbeveloper if (node.node <= 0 || (node.kind & B_BUFFER_CONSUMER) == 0) 10013620737cSbeveloper return B_MEDIA_BAD_NODE; 10023620737cSbeveloper if (out_active_inputs == NULL || out_total_count == NULL) 10033620737cSbeveloper return B_BAD_VALUE; 10043620737cSbeveloper 10053620737cSbeveloper Stack<media_input> stack; 10063620737cSbeveloper media_input *input; 10073620737cSbeveloper status_t rv; 10083620737cSbeveloper 10091299bfb2Sbeveloper *out_total_count = 0; 10101299bfb2Sbeveloper 10113620737cSbeveloper rv = GetAllInputs(node, &stack); 10123620737cSbeveloper if (B_OK != rv) 10133620737cSbeveloper return rv; 10143620737cSbeveloper 10153620737cSbeveloper for (int32 i = 0; stack.GetPointerAt(i, &input); i++) { 10163620737cSbeveloper if (input->source == media_source::null) 10173620737cSbeveloper continue; // consumer source not connected 10183620737cSbeveloper out_active_inputs[i] = *input; 10193620737cSbeveloper *out_total_count += 1; 10203620737cSbeveloper buf_num_inputs -= 1; 10213620737cSbeveloper if (buf_num_inputs == 0) 10223620737cSbeveloper break; 10233620737cSbeveloper } 10243620737cSbeveloper 10253620737cSbeveloper PublishInputs(node, &stack); 10263620737cSbeveloper return B_OK; 102752a38012Sejakowatz } 102852a38012Sejakowatz 102952a38012Sejakowatz 103052a38012Sejakowatz status_t 103152a38012Sejakowatz BMediaRoster::GetAllInputsFor(const media_node & node, 103252a38012Sejakowatz media_input * out_inputs, 103352a38012Sejakowatz int32 buf_num_inputs, 103452a38012Sejakowatz int32 * out_total_count) 103552a38012Sejakowatz { 103652a38012Sejakowatz CALLED(); 10379e9417d2Sbeveloper if (node.node <= 0 || (node.kind & B_BUFFER_CONSUMER) == 0) 103852a38012Sejakowatz return B_MEDIA_BAD_NODE; 103952a38012Sejakowatz if (out_inputs == NULL || out_total_count == NULL) 104052a38012Sejakowatz return B_BAD_VALUE; 104152a38012Sejakowatz 10423620737cSbeveloper Stack<media_input> stack; 10433620737cSbeveloper media_input *input; 104452a38012Sejakowatz status_t rv; 104552a38012Sejakowatz 10461299bfb2Sbeveloper *out_total_count = 0; 10471299bfb2Sbeveloper 10483620737cSbeveloper rv = GetAllInputs(node, &stack); 10493620737cSbeveloper if (B_OK != rv) 10503620737cSbeveloper return rv; 10513620737cSbeveloper 10523620737cSbeveloper for (int32 i = 0; stack.GetPointerAt(i, &input); i++) { 10533620737cSbeveloper out_inputs[i] = *input; 105452a38012Sejakowatz *out_total_count += 1; 10553620737cSbeveloper buf_num_inputs -= 1; 10563620737cSbeveloper if (buf_num_inputs == 0) 10573620737cSbeveloper break; 105852a38012Sejakowatz } 105952a38012Sejakowatz 10603620737cSbeveloper PublishInputs(node, &stack); 10613620737cSbeveloper return B_OK; 106252a38012Sejakowatz } 106352a38012Sejakowatz 106452a38012Sejakowatz 106552a38012Sejakowatz status_t 106652a38012Sejakowatz BMediaRoster::GetFreeOutputsFor(const media_node & node, 106752a38012Sejakowatz media_output * out_free_outputs, 106852a38012Sejakowatz int32 buf_num_outputs, 106952a38012Sejakowatz int32 * out_total_count, 107052a38012Sejakowatz media_type filter_type) 107152a38012Sejakowatz { 10723620737cSbeveloper CALLED(); 10739e9417d2Sbeveloper if (node.node <= 0 || (node.kind & B_BUFFER_PRODUCER) == 0) 10743620737cSbeveloper return B_MEDIA_BAD_NODE; 10753620737cSbeveloper if (out_free_outputs == NULL || out_total_count == NULL) 10763620737cSbeveloper return B_BAD_VALUE; 10773620737cSbeveloper 10783620737cSbeveloper Stack<media_output> stack; 10793620737cSbeveloper media_output *output; 10803620737cSbeveloper status_t rv; 10813620737cSbeveloper 10821299bfb2Sbeveloper *out_total_count = 0; 10831299bfb2Sbeveloper 10843620737cSbeveloper rv = GetAllOutputs(node, &stack); 10853620737cSbeveloper if (B_OK != rv) 10863620737cSbeveloper return rv; 10873620737cSbeveloper 10883620737cSbeveloper for (int32 i = 0; stack.GetPointerAt(i, &output); i++) { 10893620737cSbeveloper if (filter_type != B_MEDIA_UNKNOWN_TYPE && filter_type != output->format.type) 10903620737cSbeveloper continue; // media_type used, but doesn't match 10913620737cSbeveloper if (output->destination != media_destination::null) 10923620737cSbeveloper continue; // producer destination already connected 10933620737cSbeveloper out_free_outputs[i] = *output; 10943620737cSbeveloper *out_total_count += 1; 10953620737cSbeveloper buf_num_outputs -= 1; 10963620737cSbeveloper if (buf_num_outputs == 0) 10973620737cSbeveloper break; 10983620737cSbeveloper } 10993620737cSbeveloper 11003620737cSbeveloper PublishOutputs(node, &stack); 11013620737cSbeveloper return B_OK; 110252a38012Sejakowatz } 110352a38012Sejakowatz 110452a38012Sejakowatz 110552a38012Sejakowatz status_t 110652a38012Sejakowatz BMediaRoster::GetConnectedOutputsFor(const media_node & node, 110752a38012Sejakowatz media_output * out_active_outputs, 110852a38012Sejakowatz int32 buf_num_outputs, 110952a38012Sejakowatz int32 * out_total_count) 111052a38012Sejakowatz { 11113620737cSbeveloper CALLED(); 11129e9417d2Sbeveloper if (node.node <= 0 || (node.kind & B_BUFFER_PRODUCER) == 0) 11133620737cSbeveloper return B_MEDIA_BAD_NODE; 11143620737cSbeveloper if (out_active_outputs == NULL || out_total_count == NULL) 11153620737cSbeveloper return B_BAD_VALUE; 11163620737cSbeveloper 11173620737cSbeveloper Stack<media_output> stack; 11183620737cSbeveloper media_output *output; 11193620737cSbeveloper status_t rv; 11203620737cSbeveloper 11211299bfb2Sbeveloper *out_total_count = 0; 11221299bfb2Sbeveloper 11233620737cSbeveloper rv = GetAllOutputs(node, &stack); 11243620737cSbeveloper if (B_OK != rv) 11253620737cSbeveloper return rv; 11263620737cSbeveloper 11273620737cSbeveloper for (int32 i = 0; stack.GetPointerAt(i, &output); i++) { 11283620737cSbeveloper if (output->destination == media_destination::null) 11293620737cSbeveloper continue; // producer destination not connected 11303620737cSbeveloper out_active_outputs[i] = *output; 11313620737cSbeveloper *out_total_count += 1; 11323620737cSbeveloper buf_num_outputs -= 1; 11333620737cSbeveloper if (buf_num_outputs == 0) 11343620737cSbeveloper break; 11353620737cSbeveloper } 11363620737cSbeveloper 11373620737cSbeveloper PublishOutputs(node, &stack); 11383620737cSbeveloper return B_OK; 113952a38012Sejakowatz } 114052a38012Sejakowatz 114152a38012Sejakowatz 114252a38012Sejakowatz status_t 114352a38012Sejakowatz BMediaRoster::GetAllOutputsFor(const media_node & node, 114452a38012Sejakowatz media_output * out_outputs, 114552a38012Sejakowatz int32 buf_num_outputs, 114652a38012Sejakowatz int32 * out_total_count) 114752a38012Sejakowatz { 114852a38012Sejakowatz CALLED(); 11499e9417d2Sbeveloper if (node.node <= 0 || (node.kind & B_BUFFER_PRODUCER) == 0) 115052a38012Sejakowatz return B_MEDIA_BAD_NODE; 115152a38012Sejakowatz if (out_outputs == NULL || out_total_count == NULL) 115252a38012Sejakowatz return B_BAD_VALUE; 115352a38012Sejakowatz 11543620737cSbeveloper Stack<media_output> stack; 11553620737cSbeveloper media_output *output; 115652a38012Sejakowatz status_t rv; 115752a38012Sejakowatz 11581299bfb2Sbeveloper *out_total_count = 0; 11591299bfb2Sbeveloper 11603620737cSbeveloper rv = GetAllOutputs(node, &stack); 11613620737cSbeveloper if (B_OK != rv) 11623620737cSbeveloper return rv; 11633620737cSbeveloper 11643620737cSbeveloper for (int32 i = 0; stack.GetPointerAt(i, &output); i++) { 11653620737cSbeveloper out_outputs[i] = *output; 116652a38012Sejakowatz *out_total_count += 1; 11673620737cSbeveloper buf_num_outputs -= 1; 11683620737cSbeveloper if (buf_num_outputs == 0) 11693620737cSbeveloper break; 117052a38012Sejakowatz } 117152a38012Sejakowatz 11723620737cSbeveloper PublishOutputs(node, &stack); 11733620737cSbeveloper return B_OK; 117452a38012Sejakowatz } 117552a38012Sejakowatz 117652a38012Sejakowatz 117752a38012Sejakowatz status_t 117852a38012Sejakowatz BMediaRoster::StartWatching(const BMessenger & where) 117952a38012Sejakowatz { 1180eae26d3dSbeveloper CALLED(); 1181eae26d3dSbeveloper if (!where.IsValid()) { 1182*353b9f6bSbeveloper FATAL("BMediaRoster::StartWatching: messenger invalid!\n"); 1183eae26d3dSbeveloper return B_BAD_VALUE; 1184eae26d3dSbeveloper } 1185f4925104Sbeveloper return BPrivate::media::notifications::Register(where, media_node::null, B_MEDIA_WILDCARD); 118652a38012Sejakowatz } 118752a38012Sejakowatz 118852a38012Sejakowatz 118952a38012Sejakowatz status_t 119052a38012Sejakowatz BMediaRoster::StartWatching(const BMessenger & where, 119152a38012Sejakowatz int32 notificationType) 119252a38012Sejakowatz { 1193eae26d3dSbeveloper CALLED(); 1194eae26d3dSbeveloper if (!where.IsValid()) { 1195*353b9f6bSbeveloper FATAL("BMediaRoster::StartWatching: messenger invalid!\n"); 1196eae26d3dSbeveloper return B_BAD_VALUE; 1197eae26d3dSbeveloper } 1198f4925104Sbeveloper if (false == BPrivate::media::notifications::IsValidNotificationRequest(false, notificationType)) { 1199*353b9f6bSbeveloper FATAL("BMediaRoster::StartWatching: notificationType invalid!\n"); 1200eae26d3dSbeveloper return B_BAD_VALUE; 1201eae26d3dSbeveloper } 1202f4925104Sbeveloper return BPrivate::media::notifications::Register(where, media_node::null, notificationType); 120352a38012Sejakowatz } 120452a38012Sejakowatz 120552a38012Sejakowatz 120652a38012Sejakowatz status_t 120752a38012Sejakowatz BMediaRoster::StartWatching(const BMessenger & where, 120852a38012Sejakowatz const media_node & node, 120952a38012Sejakowatz int32 notificationType) 121052a38012Sejakowatz { 1211eae26d3dSbeveloper CALLED(); 1212eae26d3dSbeveloper if (!where.IsValid()) { 1213*353b9f6bSbeveloper FATAL("BMediaRoster::StartWatching: messenger invalid!\n"); 1214eae26d3dSbeveloper return B_BAD_VALUE; 1215eae26d3dSbeveloper } 12169e9417d2Sbeveloper if (node.node <= 0) { 1217*353b9f6bSbeveloper FATAL("BMediaRoster::StartWatching: node invalid!\n"); 1218eae26d3dSbeveloper return B_MEDIA_BAD_NODE; 1219eae26d3dSbeveloper } 1220f4925104Sbeveloper if (false == BPrivate::media::notifications::IsValidNotificationRequest(true, notificationType)) { 1221*353b9f6bSbeveloper FATAL("BMediaRoster::StartWatching: notificationType invalid!\n"); 1222eae26d3dSbeveloper return B_BAD_VALUE; 1223eae26d3dSbeveloper } 1224f4925104Sbeveloper return BPrivate::media::notifications::Register(where, node, notificationType); 122552a38012Sejakowatz } 122652a38012Sejakowatz 122752a38012Sejakowatz 122852a38012Sejakowatz status_t 122952a38012Sejakowatz BMediaRoster::StopWatching(const BMessenger & where) 123052a38012Sejakowatz { 1231eae26d3dSbeveloper CALLED(); 1232eae26d3dSbeveloper // messenger may already be invalid, so we don't check this 1233f4925104Sbeveloper return BPrivate::media::notifications::Unregister(where, media_node::null, B_MEDIA_WILDCARD); 123452a38012Sejakowatz } 123552a38012Sejakowatz 123652a38012Sejakowatz 123752a38012Sejakowatz status_t 123852a38012Sejakowatz BMediaRoster::StopWatching(const BMessenger & where, 123952a38012Sejakowatz int32 notificationType) 124052a38012Sejakowatz { 1241eae26d3dSbeveloper CALLED(); 1242eae26d3dSbeveloper // messenger may already be invalid, so we don't check this 1243f4925104Sbeveloper if (false == BPrivate::media::notifications::IsValidNotificationRequest(false, notificationType)) { 1244*353b9f6bSbeveloper FATAL("BMediaRoster::StopWatching: notificationType invalid!\n"); 1245eae26d3dSbeveloper return B_BAD_VALUE; 1246eae26d3dSbeveloper } 1247f4925104Sbeveloper return BPrivate::media::notifications::Unregister(where, media_node::null, notificationType); 124852a38012Sejakowatz } 124952a38012Sejakowatz 125052a38012Sejakowatz 125152a38012Sejakowatz status_t 125252a38012Sejakowatz BMediaRoster::StopWatching(const BMessenger & where, 125352a38012Sejakowatz const media_node & node, 125452a38012Sejakowatz int32 notificationType) 125552a38012Sejakowatz { 1256eae26d3dSbeveloper CALLED(); 1257eae26d3dSbeveloper // messenger may already be invalid, so we don't check this 12589e9417d2Sbeveloper if (node.node <= 0) { 1259*353b9f6bSbeveloper FATAL("BMediaRoster::StopWatching: node invalid!\n"); 1260eae26d3dSbeveloper return B_MEDIA_BAD_NODE; 1261eae26d3dSbeveloper } 1262f4925104Sbeveloper if (false == BPrivate::media::notifications::IsValidNotificationRequest(true, notificationType)) { 1263*353b9f6bSbeveloper FATAL("BMediaRoster::StopWatching: notificationType invalid!\n"); 1264eae26d3dSbeveloper return B_BAD_VALUE; 1265eae26d3dSbeveloper } 1266f4925104Sbeveloper return BPrivate::media::notifications::Unregister(where, node, notificationType); 126752a38012Sejakowatz } 126852a38012Sejakowatz 126952a38012Sejakowatz 127052a38012Sejakowatz status_t 127152a38012Sejakowatz BMediaRoster::RegisterNode(BMediaNode * node) 127252a38012Sejakowatz { 127352a38012Sejakowatz CALLED(); 127452a38012Sejakowatz if (node == NULL) 127552a38012Sejakowatz return B_BAD_VALUE; 127652a38012Sejakowatz 12773620737cSbeveloper status_t rv; 12789e9417d2Sbeveloper BMediaAddOn *addon; 12799e9417d2Sbeveloper int32 addon_flavor_id; 12809e9417d2Sbeveloper media_addon_id addon_id; 12813620737cSbeveloper 12829e9417d2Sbeveloper addon_flavor_id = 0; 12839e9417d2Sbeveloper addon = node->AddOn(&addon_flavor_id); 12849e9417d2Sbeveloper addon_id = addon ? addon->AddonID() : -1; 128552a38012Sejakowatz 12869e9417d2Sbeveloper server_register_node_request request; 12879e9417d2Sbeveloper server_register_node_reply reply; 12889e9417d2Sbeveloper 12899e9417d2Sbeveloper request.addon_id = addon_id; 12909e9417d2Sbeveloper request.addon_flavor_id = addon_flavor_id; 12919e9417d2Sbeveloper strcpy(request.name, node->Name()); 12929e9417d2Sbeveloper request.kinds = node->Kinds(); 12939e9417d2Sbeveloper request.port = node->ControlPort(); 12949e9417d2Sbeveloper request.team = team; 12959e9417d2Sbeveloper 12961299bfb2Sbeveloper TRACE("BMediaRoster::RegisterNode: sending SERVER_REGISTER_NODE: port %ld, kinds %#Lx, team %ld, name '%s'\n", request.port, request.kinds, request.team, request.name); 12971299bfb2Sbeveloper 12989e9417d2Sbeveloper rv = QueryServer(SERVER_REGISTER_NODE, &request, sizeof(request), &reply, sizeof(reply)); 12999e9417d2Sbeveloper if (rv != B_OK) { 1300*353b9f6bSbeveloper FATAL("BMediaRoster::RegisterNode: failed to register node %s (error %#lx)\n", node->Name(), rv); 13019e9417d2Sbeveloper return rv; 13029e9417d2Sbeveloper } 13039e9417d2Sbeveloper 13049e9417d2Sbeveloper // we are a friend class of BMediaNode and initilize this member variable 13059e9417d2Sbeveloper node->fNodeID = reply.nodeid; 13069e9417d2Sbeveloper ASSERT(reply.nodeid == node->Node().node); 13079e9417d2Sbeveloper ASSERT(reply.nodeid == node->ID()); 13089e9417d2Sbeveloper 13099e9417d2Sbeveloper // call the callback 13109e9417d2Sbeveloper node->NodeRegistered(); 13113620737cSbeveloper 1312570f7d04Sbeveloper /* 13133620737cSbeveloper // register existing inputs and outputs with the 13143620737cSbeveloper // media_server, this allows GetLiveNodes() to work 13153620737cSbeveloper // with created, but unconnected nodes. 13163620737cSbeveloper if (node->Kinds() & B_BUFFER_PRODUCER) { 13173620737cSbeveloper Stack<media_output> stack; 13183620737cSbeveloper if (B_OK == GetAllOutputs(node->Node(), &stack)) 13193620737cSbeveloper PublishOutputs(node->Node(), &stack); 13203620737cSbeveloper } else if (node->Kinds() & B_BUFFER_CONSUMER) { 13213620737cSbeveloper Stack<media_input> stack; 13223620737cSbeveloper if (B_OK == GetAllInputs(node->Node(), &stack)) 13233620737cSbeveloper PublishInputs(node->Node(), &stack); 13243620737cSbeveloper } 1325570f7d04Sbeveloper */ 1326570f7d04Sbeveloper 13271299bfb2Sbeveloper BPrivate::media::notifications::NodesCreated(&reply.nodeid, 1); 1328570f7d04Sbeveloper /* 1329570f7d04Sbeveloper TRACE("BMediaRoster::RegisterNode: registered node name '%s', id %ld, addon %ld, flavor %ld\n", node->Name(), node->ID(), addon_id, addon_flavor_id); 1330570f7d04Sbeveloper TRACE("BMediaRoster::RegisterNode: node this %p\n", node); 1331570f7d04Sbeveloper TRACE("BMediaRoster::RegisterNode: node fConsumerThis %p\n", node->fConsumerThis); 1332570f7d04Sbeveloper TRACE("BMediaRoster::RegisterNode: node fProducerThis %p\n", node->fProducerThis); 1333570f7d04Sbeveloper TRACE("BMediaRoster::RegisterNode: node fFileInterfaceThis %p\n", node->fFileInterfaceThis); 1334570f7d04Sbeveloper TRACE("BMediaRoster::RegisterNode: node fControllableThis %p\n", node->fControllableThis); 1335570f7d04Sbeveloper TRACE("BMediaRoster::RegisterNode: node fTimeSourceThis %p\n", node->fTimeSourceThis); 1336570f7d04Sbeveloper */ 13379e9417d2Sbeveloper 13389e9417d2Sbeveloper return B_OK; 133952a38012Sejakowatz } 134052a38012Sejakowatz 134152a38012Sejakowatz 134252a38012Sejakowatz status_t 134352a38012Sejakowatz BMediaRoster::UnregisterNode(BMediaNode * node) 134452a38012Sejakowatz { 13459e9417d2Sbeveloper CALLED(); 13469e9417d2Sbeveloper if (node == NULL) 13479e9417d2Sbeveloper return B_BAD_VALUE; 13489e9417d2Sbeveloper 13499e9417d2Sbeveloper if (node->fRefCount != 0) { 1350*353b9f6bSbeveloper FATAL("BMediaRoster::UnregisterNode: Warning node name '%s' has local reference count of %ld\n", node->Name(), node->fRefCount); 13519e9417d2Sbeveloper // no return here, we continue and unregister! 13529e9417d2Sbeveloper } 13539e9417d2Sbeveloper if (node->ID() == -2) { 1354*353b9f6bSbeveloper FATAL("BMediaRoster::UnregisterNode: Warning node name '%s' already unregistered\n", node->Name()); 13559e9417d2Sbeveloper return B_OK; 13569e9417d2Sbeveloper } 13579e9417d2Sbeveloper 13589e9417d2Sbeveloper server_unregister_node_request request; 13599e9417d2Sbeveloper server_unregister_node_reply reply; 13609e9417d2Sbeveloper status_t rv; 13619e9417d2Sbeveloper 13629e9417d2Sbeveloper request.nodeid = node->ID(); 13639e9417d2Sbeveloper request.team = team; 13649e9417d2Sbeveloper 13651299bfb2Sbeveloper // send a notification 13661299bfb2Sbeveloper BPrivate::media::notifications::NodesDeleted(&request.nodeid, 1); 13671299bfb2Sbeveloper 13689e9417d2Sbeveloper rv = QueryServer(SERVER_UNREGISTER_NODE, &request, sizeof(request), &reply, sizeof(reply)); 13699e9417d2Sbeveloper if (rv != B_OK) { 1370*353b9f6bSbeveloper FATAL("BMediaRoster::UnregisterNode: failed to unregister node name '%s' (error %#lx)\n", node->Name(), rv); 13719e9417d2Sbeveloper return rv; 13729e9417d2Sbeveloper } 13739e9417d2Sbeveloper 13749e9417d2Sbeveloper if (reply.addon_id != -1) 13759e9417d2Sbeveloper _DormantNodeManager->PutAddon(reply.addon_id); 13769e9417d2Sbeveloper 13771299bfb2Sbeveloper // we are a friend class of BMediaNode and invalidate this member variable 13789e9417d2Sbeveloper node->fNodeID = -2; 13799e9417d2Sbeveloper 13809e9417d2Sbeveloper return B_OK; 138152a38012Sejakowatz } 138252a38012Sejakowatz 138352a38012Sejakowatz 138452a38012Sejakowatz // thread safe for multiple calls to Roster() 138552a38012Sejakowatz /* static */ BMediaRoster * 138652a38012Sejakowatz BMediaRoster::Roster(status_t* out_error) 138752a38012Sejakowatz { 138852a38012Sejakowatz static BLocker locker("BMediaRoster::Roster locker"); 138952a38012Sejakowatz locker.Lock(); 139052a38012Sejakowatz if (_sDefault == NULL) { 139152a38012Sejakowatz _sDefault = new BMediaRoster(); 139252a38012Sejakowatz if (out_error != NULL) 139352a38012Sejakowatz *out_error = B_OK; 139452a38012Sejakowatz } else { 139552a38012Sejakowatz if (out_error != NULL) 139652a38012Sejakowatz *out_error = B_OK; 139752a38012Sejakowatz } 139852a38012Sejakowatz locker.Unlock(); 139952a38012Sejakowatz return _sDefault; 140052a38012Sejakowatz } 140152a38012Sejakowatz 140252a38012Sejakowatz 140352a38012Sejakowatz // won't create it if there isn't one 140452a38012Sejakowatz // not thread safe if you call Roster() at the same time 140552a38012Sejakowatz /* static */ BMediaRoster * 140652a38012Sejakowatz BMediaRoster::CurrentRoster() 140752a38012Sejakowatz { 140852a38012Sejakowatz return _sDefault; 140952a38012Sejakowatz } 141052a38012Sejakowatz 141152a38012Sejakowatz 141252a38012Sejakowatz status_t 141352a38012Sejakowatz BMediaRoster::SetTimeSourceFor(media_node_id node, 141452a38012Sejakowatz media_node_id time_source) 141552a38012Sejakowatz { 141652a38012Sejakowatz UNIMPLEMENTED(); 141752a38012Sejakowatz return B_ERROR; 141852a38012Sejakowatz } 141952a38012Sejakowatz 142052a38012Sejakowatz 142152a38012Sejakowatz status_t 142252a38012Sejakowatz BMediaRoster::GetParameterWebFor(const media_node & node, 142352a38012Sejakowatz BParameterWeb ** out_web) 142452a38012Sejakowatz { 142552a38012Sejakowatz UNIMPLEMENTED(); 142652a38012Sejakowatz return B_ERROR; 142752a38012Sejakowatz } 142852a38012Sejakowatz 142952a38012Sejakowatz 143052a38012Sejakowatz status_t 143152a38012Sejakowatz BMediaRoster::StartControlPanel(const media_node & node, 143252a38012Sejakowatz BMessenger * out_messenger) 143352a38012Sejakowatz { 143452a38012Sejakowatz UNIMPLEMENTED(); 143552a38012Sejakowatz return B_ERROR; 143652a38012Sejakowatz } 143752a38012Sejakowatz 143852a38012Sejakowatz 143952a38012Sejakowatz status_t 144052a38012Sejakowatz BMediaRoster::GetDormantNodes(dormant_node_info * out_info, 144152a38012Sejakowatz int32 * io_count, 144252a38012Sejakowatz const media_format * has_input /* = NULL */, 144352a38012Sejakowatz const media_format * has_output /* = NULL */, 144452a38012Sejakowatz const char * name /* = NULL */, 144552a38012Sejakowatz uint64 require_kinds /* = NULL */, 144652a38012Sejakowatz uint64 deny_kinds /* = NULL */) 144752a38012Sejakowatz { 144852a38012Sejakowatz CALLED(); 144952a38012Sejakowatz if (out_info == NULL) 145052a38012Sejakowatz return B_BAD_VALUE; 145152a38012Sejakowatz if (io_count == NULL) 145252a38012Sejakowatz return B_BAD_VALUE; 145352a38012Sejakowatz if (*io_count <= 0) 145452a38012Sejakowatz return B_BAD_VALUE; 145552a38012Sejakowatz 145652a38012Sejakowatz xfer_server_get_dormant_nodes msg; 145752a38012Sejakowatz port_id port; 145852a38012Sejakowatz status_t rv; 145952a38012Sejakowatz 146052a38012Sejakowatz port = find_port("media_server port"); 146152a38012Sejakowatz if (port <= B_OK) 146252a38012Sejakowatz return B_ERROR; 146352a38012Sejakowatz 146452a38012Sejakowatz msg.maxcount = *io_count; 146552a38012Sejakowatz msg.has_input = (bool) has_input; 146652a38012Sejakowatz if (has_input) 146752a38012Sejakowatz msg.inputformat = *has_input; // XXX we should not make a flat copy of media_format 146852a38012Sejakowatz msg.has_output = (bool) has_output; 146952a38012Sejakowatz if (has_output) 147052a38012Sejakowatz msg.outputformat = *has_output;; // XXX we should not make a flat copy of media_format 147152a38012Sejakowatz msg.has_name = (bool) name; 147252a38012Sejakowatz if (name) { 14739e9417d2Sbeveloper int len = strlen(name); 14749e9417d2Sbeveloper len = min_c(len, (int)sizeof(msg.name) - 1); 147552a38012Sejakowatz memcpy(msg.name, name, len); 147652a38012Sejakowatz msg.name[len] = 0; 147752a38012Sejakowatz } 147852a38012Sejakowatz msg.require_kinds = require_kinds; 147952a38012Sejakowatz msg.deny_kinds = deny_kinds; 148052a38012Sejakowatz msg.reply_port = _PortPool->GetPort(); 148152a38012Sejakowatz 148252a38012Sejakowatz rv = write_port(port, SERVER_GET_DORMANT_NODES, &msg, sizeof(msg)); 148352a38012Sejakowatz if (rv != B_OK) { 148452a38012Sejakowatz _PortPool->PutPort(msg.reply_port); 148552a38012Sejakowatz return rv; 148652a38012Sejakowatz } 148752a38012Sejakowatz 148852a38012Sejakowatz xfer_server_get_dormant_nodes_reply reply; 148952a38012Sejakowatz int32 code; 149052a38012Sejakowatz 149152a38012Sejakowatz rv = read_port(msg.reply_port, &code, &reply, sizeof(reply)); 149252a38012Sejakowatz if (rv < B_OK) { 149352a38012Sejakowatz _PortPool->PutPort(msg.reply_port); 149452a38012Sejakowatz return rv; 149552a38012Sejakowatz } 149652a38012Sejakowatz 149752a38012Sejakowatz *io_count = reply.count; 149852a38012Sejakowatz 149952a38012Sejakowatz if (*io_count > 0) { 150052a38012Sejakowatz rv = read_port(msg.reply_port, &code, out_info, *io_count * sizeof(dormant_node_info)); 150152a38012Sejakowatz if (rv < B_OK) 150252a38012Sejakowatz reply.result = rv; 150352a38012Sejakowatz } 150452a38012Sejakowatz _PortPool->PutPort(msg.reply_port); 150552a38012Sejakowatz 150652a38012Sejakowatz return reply.result; 150752a38012Sejakowatz } 150852a38012Sejakowatz 150952a38012Sejakowatz 151052a38012Sejakowatz status_t 151152a38012Sejakowatz BMediaRoster::InstantiateDormantNode(const dormant_node_info & in_info, 151252a38012Sejakowatz media_node * out_node, 151352a38012Sejakowatz uint32 flags /* currently B_FLAVOR_IS_GLOBAL or B_FLAVOR_IS_LOCAL */ ) 151452a38012Sejakowatz { 151552a38012Sejakowatz CALLED(); 151652a38012Sejakowatz if ((flags & (B_FLAVOR_IS_GLOBAL | B_FLAVOR_IS_LOCAL)) == 0) { 151752a38012Sejakowatz printf("Error: BMediaRoster::InstantiateDormantNode called without flags\n"); 151852a38012Sejakowatz return B_BAD_VALUE; 151952a38012Sejakowatz } 152052a38012Sejakowatz if (out_node == 0) 152152a38012Sejakowatz return B_BAD_VALUE; 152252a38012Sejakowatz 152352a38012Sejakowatz // XXX we should not trust the values passed in by the user, 152452a38012Sejakowatz // XXX and ask the server to determine where to insta 152552a38012Sejakowatz 1526e0207628Sbeveloper 1527e0207628Sbeveloper // XXX SOMETHING IS VERY WRONG HERE 1528e0207628Sbeveloper // if ((in_info.flavor_flags & B_FLAVOR_IS_GLOBAL) == 0 && (flags & B_FLAVOR_IS_LOCAL)) { 1529e0207628Sbeveloper if (flags & B_FLAVOR_IS_LOCAL) { 153052a38012Sejakowatz return InstantiateDormantNode(in_info,out_node); 153152a38012Sejakowatz } 153252a38012Sejakowatz 1533e0207628Sbeveloper // XXX SOMETHING IS VERY WRONG HERE 1534e0207628Sbeveloper // if ((in_info.flavor_flags & B_FLAVOR_IS_GLOBAL) || (flags & B_FLAVOR_IS_GLOBAL)) { 1535e0207628Sbeveloper if (flags & B_FLAVOR_IS_GLOBAL) { 153652a38012Sejakowatz // forward this request into the media_addon_server, 153752a38012Sejakowatz // which in turn will call InstantiateDormantNode() 153852a38012Sejakowatz // to create it there localy 15398c6a6096Sbeveloper addonserver_instantiate_dormant_node_request request; 15408c6a6096Sbeveloper addonserver_instantiate_dormant_node_reply reply; 154152a38012Sejakowatz status_t rv; 1542f4925104Sbeveloper 1543f4925104Sbeveloper request.info = in_info; 1544f4925104Sbeveloper rv = QueryAddonServer(ADDONSERVER_INSTANTIATE_DORMANT_NODE, &request, sizeof(request), &reply, sizeof(reply)); 1545f4925104Sbeveloper if (rv == B_OK) { 154652a38012Sejakowatz *out_node = reply.node; 1547f4925104Sbeveloper } 1548f4925104Sbeveloper return rv; 154952a38012Sejakowatz } 155052a38012Sejakowatz 1551e0207628Sbeveloper // XXX SOMETHING IS VERY WRONG HERE 15525edd2016Sbeveloper printf("Error: BMediaRoster::InstantiateDormantNode addon_id %d, flavor_id %d, flags %#08lx\n", (int)in_info.addon, (int)in_info.flavor_id, flags); 155352a38012Sejakowatz 155452a38012Sejakowatz return B_ERROR; 155552a38012Sejakowatz } 155652a38012Sejakowatz 155752a38012Sejakowatz 155852a38012Sejakowatz status_t 155952a38012Sejakowatz BMediaRoster::InstantiateDormantNode(const dormant_node_info & in_info, 156052a38012Sejakowatz media_node * out_node) 156152a38012Sejakowatz { 156216b7eea4Sbeveloper CALLED(); 156352a38012Sejakowatz 156452a38012Sejakowatz // to instantiate a dormant node in the current address space, we need to 156552a38012Sejakowatz // either load the add-on from file and create a new BMediaAddOn class, or 156652a38012Sejakowatz // reuse the cached BMediaAddOn from a previous call 156752a38012Sejakowatz // call BMediaAddOn::InstantiateNodeFor() 156852a38012Sejakowatz // and cache the BMediaAddOn after that for later reuse. 156952a38012Sejakowatz // BeOS R5 does not seem to delete it when the application quits 157052a38012Sejakowatz // if B_FLAVOR_IS_GLOBAL, we need to use the BMediaAddOn object that 157152a38012Sejakowatz // resides in the media_addon_server 157252a38012Sejakowatz 157352a38012Sejakowatz // RegisterNode() is called automatically for nodes instantiated from add-ons 157452a38012Sejakowatz 157516b7eea4Sbeveloper //XXX TEST! 157616b7eea4Sbeveloper BMediaAddOn *addon; 157716b7eea4Sbeveloper BMediaNode *node; 157816b7eea4Sbeveloper BMessage config; 157916b7eea4Sbeveloper status_t out_error; 15808c6a6096Sbeveloper status_t rv; 158116b7eea4Sbeveloper addon = _DormantNodeManager->GetAddon(in_info.addon); 158216b7eea4Sbeveloper if (!addon) { 158316b7eea4Sbeveloper printf("BMediaRoster::InstantiateDormantNode: GetAddon failed\n"); 158452a38012Sejakowatz return B_ERROR; 158552a38012Sejakowatz } 15861299bfb2Sbeveloper flavor_info temp; // XXX fix this! 15871299bfb2Sbeveloper temp.name = "XXX flavor_info name"; 15881299bfb2Sbeveloper temp.info = "XXX flavor_info info"; 158916b7eea4Sbeveloper temp.internal_id = in_info.flavor_id; 159016b7eea4Sbeveloper node = addon->InstantiateNodeFor(&temp, &config, &out_error); 159116b7eea4Sbeveloper if (!node) { 159216b7eea4Sbeveloper printf("BMediaRoster::InstantiateDormantNode: InstantiateNodeFor failed\n"); 159316b7eea4Sbeveloper _DormantNodeManager->PutAddon(in_info.addon); 159416b7eea4Sbeveloper return B_ERROR; 159516b7eea4Sbeveloper } 15968c6a6096Sbeveloper rv = RegisterNode(node); 15978c6a6096Sbeveloper if (rv != B_OK) { 15988c6a6096Sbeveloper printf("BMediaRoster::InstantiateDormantNode: RegisterNode failed\n"); 15998c6a6096Sbeveloper delete node; 16008c6a6096Sbeveloper _DormantNodeManager->PutAddon(in_info.addon); 16018c6a6096Sbeveloper return B_ERROR; 16028c6a6096Sbeveloper } 16038c6a6096Sbeveloper 16048c6a6096Sbeveloper // XXX we must remember in_info.addon and call 16058c6a6096Sbeveloper // XXX _DormantNodeManager->PutAddon when the 16068c6a6096Sbeveloper // XXX node is unregistered 16079e9417d2Sbeveloper // should be handled by RegisterNode() and UnegisterNode() now 16088c6a6096Sbeveloper 160916b7eea4Sbeveloper *out_node = node->Node(); 161016b7eea4Sbeveloper return B_OK; 161116b7eea4Sbeveloper } 161252a38012Sejakowatz 161352a38012Sejakowatz 161452a38012Sejakowatz status_t 161552a38012Sejakowatz BMediaRoster::GetDormantNodeFor(const media_node & node, 161652a38012Sejakowatz dormant_node_info * out_info) 161752a38012Sejakowatz { 161885dfab2bSbeveloper CALLED(); 161985dfab2bSbeveloper if (out_info == NULL) 162085dfab2bSbeveloper return B_BAD_VALUE; 162185dfab2bSbeveloper if (node.node <= 0) 162285dfab2bSbeveloper return B_MEDIA_BAD_NODE; 162352a38012Sejakowatz 162485dfab2bSbeveloper server_get_dormant_node_for_request request; 162585dfab2bSbeveloper server_get_dormant_node_for_reply reply; 162685dfab2bSbeveloper status_t rv; 162785dfab2bSbeveloper 162885dfab2bSbeveloper request.node = node; 162985dfab2bSbeveloper 16301299bfb2Sbeveloper rv = QueryServer(SERVER_GET_DORMANT_NODE_FOR, &request, sizeof(request), &reply, sizeof(reply)); 163185dfab2bSbeveloper if (rv != B_OK) 163285dfab2bSbeveloper return rv; 163385dfab2bSbeveloper 163485dfab2bSbeveloper *out_info = reply.node_info; 163585dfab2bSbeveloper return B_OK; 163652a38012Sejakowatz } 163752a38012Sejakowatz 163852a38012Sejakowatz 163952a38012Sejakowatz status_t 164052a38012Sejakowatz BMediaRoster::GetDormantFlavorInfoFor(const dormant_node_info & in_dormant, 164152a38012Sejakowatz dormant_flavor_info * out_flavor) 164252a38012Sejakowatz { 164352a38012Sejakowatz CALLED(); 164452a38012Sejakowatz 164552a38012Sejakowatz xfer_server_get_dormant_flavor_info msg; 164652a38012Sejakowatz xfer_server_get_dormant_flavor_info_reply *reply; 164752a38012Sejakowatz port_id port; 164852a38012Sejakowatz status_t rv; 164952a38012Sejakowatz int32 code; 165052a38012Sejakowatz 165152a38012Sejakowatz port = find_port("media_server port"); 165252a38012Sejakowatz if (port <= B_OK) 165352a38012Sejakowatz return B_ERROR; 165452a38012Sejakowatz 165552a38012Sejakowatz reply = (xfer_server_get_dormant_flavor_info_reply *) malloc(16000); 165652a38012Sejakowatz if (reply == 0) 165752a38012Sejakowatz return B_ERROR; 165852a38012Sejakowatz 165952a38012Sejakowatz msg.addon = in_dormant.addon; 166052a38012Sejakowatz msg.flavor_id = in_dormant.flavor_id; 166152a38012Sejakowatz msg.reply_port = _PortPool->GetPort(); 166252a38012Sejakowatz rv = write_port(port, SERVER_GET_DORMANT_FLAVOR_INFO, &msg, sizeof(msg)); 166352a38012Sejakowatz if (rv != B_OK) { 166452a38012Sejakowatz free(reply); 166552a38012Sejakowatz _PortPool->PutPort(msg.reply_port); 166652a38012Sejakowatz return rv; 166752a38012Sejakowatz } 166852a38012Sejakowatz rv = read_port(msg.reply_port, &code, reply, 16000); 166952a38012Sejakowatz _PortPool->PutPort(msg.reply_port); 167052a38012Sejakowatz 167152a38012Sejakowatz if (rv < B_OK) { 167252a38012Sejakowatz free(reply); 167352a38012Sejakowatz return rv; 167452a38012Sejakowatz } 167552a38012Sejakowatz 167652a38012Sejakowatz if (reply->result == B_OK) 167752a38012Sejakowatz rv = out_flavor->Unflatten(reply->dfi_type, &reply->dfi, reply->dfi_size); 167852a38012Sejakowatz else 167952a38012Sejakowatz rv = reply->result; 168052a38012Sejakowatz 168152a38012Sejakowatz free(reply); 168252a38012Sejakowatz return rv; 168352a38012Sejakowatz } 168452a38012Sejakowatz 168552a38012Sejakowatz 168652a38012Sejakowatz status_t 168752a38012Sejakowatz BMediaRoster::GetLatencyFor(const media_node & producer, 168852a38012Sejakowatz bigtime_t * out_latency) 168952a38012Sejakowatz { 169052a38012Sejakowatz UNIMPLEMENTED(); 169152a38012Sejakowatz *out_latency = 0; 169252a38012Sejakowatz return B_ERROR; 169352a38012Sejakowatz } 169452a38012Sejakowatz 169552a38012Sejakowatz 169652a38012Sejakowatz status_t 169752a38012Sejakowatz BMediaRoster::GetInitialLatencyFor(const media_node & producer, 169852a38012Sejakowatz bigtime_t * out_latency, 169952a38012Sejakowatz uint32 * out_flags) 170052a38012Sejakowatz { 170152a38012Sejakowatz UNIMPLEMENTED(); 170252a38012Sejakowatz *out_latency = 0; 170352a38012Sejakowatz *out_flags = 0; 170452a38012Sejakowatz return B_ERROR; 170552a38012Sejakowatz } 170652a38012Sejakowatz 170752a38012Sejakowatz 170852a38012Sejakowatz status_t 170952a38012Sejakowatz BMediaRoster::GetStartLatencyFor(const media_node & time_source, 171052a38012Sejakowatz bigtime_t * out_latency) 171152a38012Sejakowatz { 171252a38012Sejakowatz UNIMPLEMENTED(); 171352a38012Sejakowatz *out_latency = 0; 171452a38012Sejakowatz return B_ERROR; 171552a38012Sejakowatz } 171652a38012Sejakowatz 171752a38012Sejakowatz 171852a38012Sejakowatz status_t 171952a38012Sejakowatz BMediaRoster::GetFileFormatsFor(const media_node & file_interface, 172052a38012Sejakowatz media_file_format * out_formats, 172152a38012Sejakowatz int32 * io_num_infos) 172252a38012Sejakowatz { 172352a38012Sejakowatz UNIMPLEMENTED(); 172452a38012Sejakowatz return B_ERROR; 172552a38012Sejakowatz } 172652a38012Sejakowatz 172752a38012Sejakowatz 172852a38012Sejakowatz status_t 172952a38012Sejakowatz BMediaRoster::SetRefFor(const media_node & file_interface, 173052a38012Sejakowatz const entry_ref & file, 173152a38012Sejakowatz bool create_and_truncate, 173252a38012Sejakowatz bigtime_t * out_length) /* if create is false */ 173352a38012Sejakowatz { 173452a38012Sejakowatz UNIMPLEMENTED(); 173552a38012Sejakowatz return B_ERROR; 173652a38012Sejakowatz } 173752a38012Sejakowatz 173852a38012Sejakowatz 173952a38012Sejakowatz status_t 174052a38012Sejakowatz BMediaRoster::GetRefFor(const media_node & node, 174152a38012Sejakowatz entry_ref * out_file, 174252a38012Sejakowatz BMimeType * mime_type) 174352a38012Sejakowatz { 174452a38012Sejakowatz UNIMPLEMENTED(); 174552a38012Sejakowatz return B_ERROR; 174652a38012Sejakowatz } 174752a38012Sejakowatz 174852a38012Sejakowatz 174952a38012Sejakowatz status_t 175052a38012Sejakowatz BMediaRoster::SniffRefFor(const media_node & file_interface, 175152a38012Sejakowatz const entry_ref & file, 175252a38012Sejakowatz BMimeType * mime_type, 175352a38012Sejakowatz float * out_capability) 175452a38012Sejakowatz { 175552a38012Sejakowatz UNIMPLEMENTED(); 175652a38012Sejakowatz return B_ERROR; 175752a38012Sejakowatz } 175852a38012Sejakowatz 175952a38012Sejakowatz 176052a38012Sejakowatz /* This is the generic "here's a file, now can someone please play it" interface */ 176152a38012Sejakowatz status_t 176252a38012Sejakowatz BMediaRoster::SniffRef(const entry_ref & file, 176352a38012Sejakowatz uint64 require_node_kinds, /* if you need an EntityInterface or BufferConsumer or something */ 176452a38012Sejakowatz dormant_node_info * out_node, 176552a38012Sejakowatz BMimeType * mime_type) 176652a38012Sejakowatz { 176752a38012Sejakowatz UNIMPLEMENTED(); 176852a38012Sejakowatz return B_ERROR; 176952a38012Sejakowatz } 177052a38012Sejakowatz 177152a38012Sejakowatz 177252a38012Sejakowatz status_t 177352a38012Sejakowatz BMediaRoster::GetDormantNodeForType(const BMimeType & type, 177452a38012Sejakowatz uint64 require_node_kinds, 177552a38012Sejakowatz dormant_node_info * out_node) 177652a38012Sejakowatz { 177752a38012Sejakowatz UNIMPLEMENTED(); 177852a38012Sejakowatz return B_ERROR; 177952a38012Sejakowatz } 178052a38012Sejakowatz 178152a38012Sejakowatz 178252a38012Sejakowatz status_t 178352a38012Sejakowatz BMediaRoster::GetReadFileFormatsFor(const dormant_node_info & in_node, 178452a38012Sejakowatz media_file_format * out_read_formats, 178552a38012Sejakowatz int32 in_read_count, 178652a38012Sejakowatz int32 * out_read_count) 178752a38012Sejakowatz { 178852a38012Sejakowatz UNIMPLEMENTED(); 178952a38012Sejakowatz return B_ERROR; 179052a38012Sejakowatz } 179152a38012Sejakowatz 179252a38012Sejakowatz 179352a38012Sejakowatz status_t 179452a38012Sejakowatz BMediaRoster::GetWriteFileFormatsFor(const dormant_node_info & in_node, 179552a38012Sejakowatz media_file_format * out_write_formats, 179652a38012Sejakowatz int32 in_write_count, 179752a38012Sejakowatz int32 * out_write_count) 179852a38012Sejakowatz { 179952a38012Sejakowatz UNIMPLEMENTED(); 180052a38012Sejakowatz return B_ERROR; 180152a38012Sejakowatz } 180252a38012Sejakowatz 180352a38012Sejakowatz 180452a38012Sejakowatz status_t 180552a38012Sejakowatz BMediaRoster::GetFormatFor(const media_output & output, 180652a38012Sejakowatz media_format * io_format, 180752a38012Sejakowatz uint32 flags) 180852a38012Sejakowatz { 180952a38012Sejakowatz UNIMPLEMENTED(); 181052a38012Sejakowatz return B_ERROR; 181152a38012Sejakowatz } 181252a38012Sejakowatz 181352a38012Sejakowatz 181452a38012Sejakowatz status_t 181552a38012Sejakowatz BMediaRoster::GetFormatFor(const media_input & input, 181652a38012Sejakowatz media_format * io_format, 181752a38012Sejakowatz uint32 flags) 181852a38012Sejakowatz { 181952a38012Sejakowatz UNIMPLEMENTED(); 182052a38012Sejakowatz return B_ERROR; 182152a38012Sejakowatz } 182252a38012Sejakowatz 182352a38012Sejakowatz 182452a38012Sejakowatz status_t 182552a38012Sejakowatz BMediaRoster::GetFormatFor(const media_node & node, 182652a38012Sejakowatz media_format * io_format, 182752a38012Sejakowatz float quality) 182852a38012Sejakowatz { 182952a38012Sejakowatz UNIMPLEMENTED(); 183052a38012Sejakowatz return B_ERROR; 183152a38012Sejakowatz } 183252a38012Sejakowatz 183352a38012Sejakowatz 183452a38012Sejakowatz ssize_t 183552a38012Sejakowatz BMediaRoster::GetNodeAttributesFor(const media_node & node, 183652a38012Sejakowatz media_node_attribute * outArray, 183752a38012Sejakowatz size_t inMaxCount) 183852a38012Sejakowatz { 183952a38012Sejakowatz UNIMPLEMENTED(); 184052a38012Sejakowatz return B_ERROR; 184152a38012Sejakowatz } 184252a38012Sejakowatz 184352a38012Sejakowatz 184452a38012Sejakowatz media_node_id 184552a38012Sejakowatz BMediaRoster::NodeIDFor(port_id source_or_destination_port) 184652a38012Sejakowatz { 18479e9417d2Sbeveloper CALLED(); 18489e9417d2Sbeveloper 18499e9417d2Sbeveloper server_node_id_for_request request; 18509e9417d2Sbeveloper server_node_id_for_reply reply; 18519e9417d2Sbeveloper status_t rv; 18529e9417d2Sbeveloper 18539e9417d2Sbeveloper request.port = source_or_destination_port; 18549e9417d2Sbeveloper 18559e9417d2Sbeveloper rv = QueryServer(SERVER_NODE_ID_FOR, &request, sizeof(request), &reply, sizeof(reply)); 18569e9417d2Sbeveloper if (rv != B_OK) { 1857*353b9f6bSbeveloper FATAL("BMediaRoster::NodeIDFor: failed (error %#lx)\n", rv); 18589e9417d2Sbeveloper return -1; 18599e9417d2Sbeveloper } 18609e9417d2Sbeveloper 18619e9417d2Sbeveloper return reply.nodeid; 186252a38012Sejakowatz } 186352a38012Sejakowatz 186452a38012Sejakowatz 186552a38012Sejakowatz status_t 186652a38012Sejakowatz BMediaRoster::GetInstancesFor(media_addon_id addon, 186752a38012Sejakowatz int32 flavor, 186852a38012Sejakowatz media_node_id * out_id, 186952a38012Sejakowatz int32 * io_count) 187052a38012Sejakowatz { 187185dfab2bSbeveloper CALLED(); 187285dfab2bSbeveloper if (out_id == NULL || io_count == NULL) 187385dfab2bSbeveloper return B_BAD_VALUE; 187485dfab2bSbeveloper if (*io_count <= 0) 187585dfab2bSbeveloper return B_BAD_VALUE; 187685dfab2bSbeveloper 187785dfab2bSbeveloper server_get_instances_for_request request; 187885dfab2bSbeveloper server_get_instances_for_reply reply; 187985dfab2bSbeveloper status_t rv; 188085dfab2bSbeveloper 188185dfab2bSbeveloper request.maxcount = *io_count; 188285dfab2bSbeveloper request.addon_id = addon; 188385dfab2bSbeveloper request.addon_flavor_id = flavor; 188485dfab2bSbeveloper 188585dfab2bSbeveloper rv = QueryServer(SERVER_GET_INSTANCES_FOR, &request, sizeof(request), &reply, sizeof(reply)); 188685dfab2bSbeveloper if (rv != B_OK) { 1887*353b9f6bSbeveloper FATAL("BMediaRoster::GetLiveNodes failed\n"); 188885dfab2bSbeveloper return rv; 188952a38012Sejakowatz } 189052a38012Sejakowatz 189185dfab2bSbeveloper *io_count = reply.count; 189285dfab2bSbeveloper if (reply.count > 0) 189385dfab2bSbeveloper memcpy(out_id, reply.node_id, sizeof(media_node_id) * reply.count); 189485dfab2bSbeveloper 189585dfab2bSbeveloper return B_OK; 189685dfab2bSbeveloper } 189752a38012Sejakowatz 189852a38012Sejakowatz 189952a38012Sejakowatz status_t 190052a38012Sejakowatz BMediaRoster::SetRealtimeFlags(uint32 in_enabled) 190152a38012Sejakowatz { 190252a38012Sejakowatz UNIMPLEMENTED(); 190352a38012Sejakowatz return B_ERROR; 190452a38012Sejakowatz } 190552a38012Sejakowatz 190652a38012Sejakowatz 190752a38012Sejakowatz status_t 190852a38012Sejakowatz BMediaRoster::GetRealtimeFlags(uint32 * out_enabled) 190952a38012Sejakowatz { 191052a38012Sejakowatz UNIMPLEMENTED(); 191152a38012Sejakowatz return B_ERROR; 191252a38012Sejakowatz } 191352a38012Sejakowatz 191452a38012Sejakowatz 191552a38012Sejakowatz ssize_t 191652a38012Sejakowatz BMediaRoster::AudioBufferSizeFor(int32 channel_count, 191752a38012Sejakowatz uint32 sample_format, 191852a38012Sejakowatz float frame_rate, 191952a38012Sejakowatz bus_type bus_kind) 192052a38012Sejakowatz { 192152a38012Sejakowatz UNIMPLEMENTED(); 192252a38012Sejakowatz return 4096; 192352a38012Sejakowatz } 192452a38012Sejakowatz 192552a38012Sejakowatz 192652a38012Sejakowatz /* Use MediaFlags to inquire about specific features of the Media Kit. */ 192752a38012Sejakowatz /* Returns < 0 for "not present", positive size for output data size. */ 192852a38012Sejakowatz /* 0 means that the capability is present, but no data about it. */ 192952a38012Sejakowatz /* static */ ssize_t 193052a38012Sejakowatz BMediaRoster::MediaFlags(media_flags cap, 193152a38012Sejakowatz void * buf, 193252a38012Sejakowatz size_t maxSize) 193352a38012Sejakowatz { 193452a38012Sejakowatz UNIMPLEMENTED(); 193552a38012Sejakowatz return 0; 193652a38012Sejakowatz } 193752a38012Sejakowatz 193852a38012Sejakowatz 193952a38012Sejakowatz /* BLooper overrides */ 194052a38012Sejakowatz /* virtual */ void 194152a38012Sejakowatz BMediaRoster::MessageReceived(BMessage * message) 194252a38012Sejakowatz { 19436396865dSbeveloper // media_server plays ping-pong with the BMediaRosters 19446396865dSbeveloper // to detect dead teams. Normal communication uses ports. 19456396865dSbeveloper static BMessage pong('PONG'); 19466396865dSbeveloper if (message->what == 'PING') { 19476396865dSbeveloper message->SendReply(&pong, static_cast<BHandler *>(NULL), 2000000); 19486396865dSbeveloper return; 19496396865dSbeveloper } 19506396865dSbeveloper 19516396865dSbeveloper printf("BMediaRoster::MessageReceived: unknown message!\n"); 19526396865dSbeveloper message->PrintToStream(); 195352a38012Sejakowatz } 195452a38012Sejakowatz 195552a38012Sejakowatz /* virtual */ bool 195652a38012Sejakowatz BMediaRoster::QuitRequested() 195752a38012Sejakowatz { 195852a38012Sejakowatz UNIMPLEMENTED(); 195952a38012Sejakowatz return true; 196052a38012Sejakowatz } 196152a38012Sejakowatz 196252a38012Sejakowatz /* virtual */ BHandler * 196352a38012Sejakowatz BMediaRoster::ResolveSpecifier(BMessage *msg, 196452a38012Sejakowatz int32 index, 196552a38012Sejakowatz BMessage *specifier, 196652a38012Sejakowatz int32 form, 196752a38012Sejakowatz const char *property) 196852a38012Sejakowatz { 196952a38012Sejakowatz UNIMPLEMENTED(); 197052a38012Sejakowatz return 0; 197152a38012Sejakowatz } 197252a38012Sejakowatz 197352a38012Sejakowatz 197452a38012Sejakowatz /* virtual */ status_t 197552a38012Sejakowatz BMediaRoster::GetSupportedSuites(BMessage *data) 197652a38012Sejakowatz { 197752a38012Sejakowatz UNIMPLEMENTED(); 197852a38012Sejakowatz return B_ERROR; 197952a38012Sejakowatz } 198052a38012Sejakowatz 198152a38012Sejakowatz 198252a38012Sejakowatz BMediaRoster::~BMediaRoster() 198352a38012Sejakowatz { 198452a38012Sejakowatz CALLED(); 19856396865dSbeveloper 19866396865dSbeveloper // unregister this application with the media server 19876396865dSbeveloper server_unregister_app_request request; 19886396865dSbeveloper server_unregister_app_reply reply; 19896396865dSbeveloper request.team = team; 19906396865dSbeveloper QueryServer(SERVER_UNREGISTER_APP, &request, sizeof(request), &reply, sizeof(reply)); 199152a38012Sejakowatz } 199252a38012Sejakowatz 199352a38012Sejakowatz 199452a38012Sejakowatz /************************************************************* 199552a38012Sejakowatz * private BMediaRoster 199652a38012Sejakowatz *************************************************************/ 199752a38012Sejakowatz 199852a38012Sejakowatz // deprecated call 199952a38012Sejakowatz status_t 200052a38012Sejakowatz BMediaRoster::SetOutputBuffersFor(const media_source & output, 200152a38012Sejakowatz BBufferGroup * group, 200252a38012Sejakowatz bool will_reclaim ) 200352a38012Sejakowatz { 200452a38012Sejakowatz UNIMPLEMENTED(); 20059e9417d2Sbeveloper debugger("BMediaRoster::SetOutputBuffersFor missing\n"); 200652a38012Sejakowatz return B_ERROR; 200752a38012Sejakowatz } 200852a38012Sejakowatz 200952a38012Sejakowatz 201052a38012Sejakowatz /* FBC stuffing (Mmmh, Stuffing!) */ 201152a38012Sejakowatz status_t BMediaRoster::_Reserved_MediaRoster_0(void *) { return B_ERROR; } 201252a38012Sejakowatz status_t BMediaRoster::_Reserved_MediaRoster_1(void *) { return B_ERROR; } 201352a38012Sejakowatz status_t BMediaRoster::_Reserved_MediaRoster_2(void *) { return B_ERROR; } 201452a38012Sejakowatz status_t BMediaRoster::_Reserved_MediaRoster_3(void *) { return B_ERROR; } 201552a38012Sejakowatz status_t BMediaRoster::_Reserved_MediaRoster_4(void *) { return B_ERROR; } 201652a38012Sejakowatz status_t BMediaRoster::_Reserved_MediaRoster_5(void *) { return B_ERROR; } 201752a38012Sejakowatz status_t BMediaRoster::_Reserved_MediaRoster_6(void *) { return B_ERROR; } 201852a38012Sejakowatz status_t BMediaRoster::_Reserved_MediaRoster_7(void *) { return B_ERROR; } 201952a38012Sejakowatz 202052a38012Sejakowatz 202152a38012Sejakowatz BMediaRoster::BMediaRoster() : 20226396865dSbeveloper BLooper("_BMediaRoster_", B_URGENT_DISPLAY_PRIORITY, B_LOOPER_PORT_DEFAULT_CAPACITY) 202352a38012Sejakowatz { 202452a38012Sejakowatz CALLED(); 20256396865dSbeveloper 20266396865dSbeveloper // start the looper 20276396865dSbeveloper Run(); 20286396865dSbeveloper 20296396865dSbeveloper // register this application with the media server 20306396865dSbeveloper server_register_app_request request; 20316396865dSbeveloper server_register_app_reply reply; 20326396865dSbeveloper request.team = team; 20336396865dSbeveloper request.messenger = BMessenger(NULL, this); 20346396865dSbeveloper QueryServer(SERVER_REGISTER_APP, &request, sizeof(request), &reply, sizeof(reply)); 203552a38012Sejakowatz } 203652a38012Sejakowatz 20376396865dSbeveloper 203852a38012Sejakowatz /* static */ status_t 203952a38012Sejakowatz BMediaRoster::ParseCommand(BMessage & reply) 204052a38012Sejakowatz { 204152a38012Sejakowatz UNIMPLEMENTED(); 204252a38012Sejakowatz return B_ERROR; 204352a38012Sejakowatz } 204452a38012Sejakowatz 204552a38012Sejakowatz 204652a38012Sejakowatz status_t 204752a38012Sejakowatz BMediaRoster::GetDefaultInfo(media_node_id for_default, 204852a38012Sejakowatz BMessage & out_config) 204952a38012Sejakowatz { 205052a38012Sejakowatz UNIMPLEMENTED(); 205152a38012Sejakowatz return B_ERROR; 205252a38012Sejakowatz } 205352a38012Sejakowatz 205452a38012Sejakowatz 205552a38012Sejakowatz 205652a38012Sejakowatz status_t 205752a38012Sejakowatz BMediaRoster::SetRunningDefault(media_node_id for_default, 205852a38012Sejakowatz const media_node & node) 205952a38012Sejakowatz { 206052a38012Sejakowatz UNIMPLEMENTED(); 206152a38012Sejakowatz return B_ERROR; 206252a38012Sejakowatz } 206352a38012Sejakowatz 206452a38012Sejakowatz 206552a38012Sejakowatz /************************************************************* 206652a38012Sejakowatz * static BMediaRoster variables 206752a38012Sejakowatz *************************************************************/ 206852a38012Sejakowatz 206952a38012Sejakowatz bool BMediaRoster::_isMediaServer; 207052a38012Sejakowatz port_id BMediaRoster::_mReplyPort; 207152a38012Sejakowatz int32 BMediaRoster::_mReplyPortRes; 207252a38012Sejakowatz int32 BMediaRoster::_mReplyPortUnavailCount; 207352a38012Sejakowatz BMediaRoster * BMediaRoster::_sDefault = NULL; 207452a38012Sejakowatz 2075