From 34c721444214fe3e783ecc57b3eb4627b1a18b77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 8 Apr 2009 21:17:03 +0000 Subject: [PATCH] * BParameterWeb::StartWatching() now just calls BMediaRoster::StartWatching() as on Dano - since the functionality is already there, those two functions aren't really needed, though, so we could remove them again. * Cleaned up DataExchange.h, and added basic reply/request structs for anything that needs an area. * BControllable now uses a helper class ReceiveTransfer to deal with requests with areas. * Major style cleanup of MediaRoster.cpp, though one could still bury some hours there... git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30045 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/media/DataExchange.h | 1011 +++++------ src/kits/media/Controllable.cpp | 338 ++-- src/kits/media/MediaRoster.cpp | 2444 ++++++++++++++------------ src/kits/media/ParameterWeb.cpp | 25 +- 4 files changed, 1950 insertions(+), 1868 deletions(-) diff --git a/headers/private/media/DataExchange.h b/headers/private/media/DataExchange.h index 63d92a2f13..6616c9212f 100644 --- a/headers/private/media/DataExchange.h +++ b/headers/private/media/DataExchange.h @@ -1,8 +1,9 @@ /* * Copyright 2002, Marcus Overhagen. All rights reserved. + * Copyright 2009, Axel Dörfler, axeld@pinc-software.de. + * * Distributed under the terms of the MIT License. */ - #ifndef _DATA_EXCHANGE_H #define _DATA_EXCHANGE_H @@ -15,6 +16,7 @@ #include #include + namespace BPrivate { namespace media { namespace dataexchange { @@ -29,39 +31,50 @@ status_t QueryServer(BMessage &request, BMessage &reply); // Raw data based data exchange with the media_server status_t SendToServer(int32 msgcode, command_data *msg, int size); -status_t QueryServer(int32 msgcode, request_data *request, int requestsize, reply_data *reply, int replysize); +status_t QueryServer(int32 msgcode, request_data *request, int requestsize, + reply_data *reply, int replysize); // Raw data based data exchange with the media_addon_server status_t SendToAddonServer(int32 msgcode, command_data *msg, int size); -status_t QueryAddonServer(int32 msgcode, request_data *request, int requestsize, reply_data *reply, int replysize); +status_t QueryAddonServer(int32 msgcode, request_data *request, int requestSize, + reply_data *reply, int replysize); // Raw data based data exchange with any (media node control-) port -status_t SendToPort(port_id sendport, int32 msgcode, command_data *msg, int size); -status_t QueryPort(port_id requestport, int32 msgcode, request_data *request, int requestsize, reply_data *reply, int replysize); +status_t SendToPort(port_id sendport, int32 msgcode, command_data *msg, + int size); +status_t QueryPort(port_id requestport, int32 msgcode, request_data *request, + int requestsize, reply_data *reply, int replysize); // The base struct used for all raw requests -struct request_data -{ - port_id reply_port; +struct request_data { + port_id reply_port; status_t SendReply(status_t result, reply_data *reply, int replysize) const; }; // The base struct used for all raw replys -struct reply_data -{ - status_t result; +struct reply_data { + status_t result; }; // The base struct used for all raw commands (asynchronous, no answer) -struct command_data -{ +struct command_data { // yes, it's empty ;) }; -}; // dataexchange -}; // media -}; // BPrivate +// The base struct used for all requests using an area +struct area_request_data : request_data { + area_id area; +}; + +// The base struct used for all replies using an area +struct area_reply_data : reply_data { + area_id area; +}; + +} // namespace dataexchange +} // namespace media +} // namespace BPrivate using namespace BPrivate::media::dataexchange; @@ -82,7 +95,6 @@ enum { MEDIA_ADDON_SERVER_PLAY_MEDIA = '_TRU' }; - // Raw port based communication enum { ADDONSERVER_RESCAN_MEDIAADDON_FLAVORS = 0x50, @@ -196,40 +208,41 @@ enum { * but we can assign it to an xfer_entry_ref and send this one, * when we receive it we can assign it to a normal entry_ref */ -struct xfer_entry_ref -{ +struct xfer_entry_ref { public: xfer_entry_ref() - { - device = -1; - directory = -1; - name[0] = 0; - } + { + device = -1; + directory = -1; + name[0] = 0; + } + operator entry_ref() const - { - entry_ref ref(device, directory, name); - return ref; - } - void operator=(const entry_ref &ref) - { - device = ref.device; - directory = ref.directory; - if(ref.name) - strcpy(name, ref.name); - else - name[0] = 0; - } + { + entry_ref ref(device, directory, name); + return ref; + } + + xfer_entry_ref& operator=(const entry_ref& ref) + { + device = ref.device; + directory = ref.directory; + if (ref.name) + strcpy(name, ref.name); + else + name[0] = 0; + + return *this; + } + private: dev_t device; ino_t directory; - char name[B_FILE_NAME_LENGTH]; // == 256 bytes + char name[B_FILE_NAME_LENGTH]; }; - - // used by SERVER_GET_NODE and SERVER_SET_NODE -enum node_type -{ +enum node_type { VIDEO_INPUT, AUDIO_INPUT, VIDEO_OUTPUT, @@ -241,835 +254,695 @@ enum node_type }; // used by SERVER_PUBLISH_INPUTS and SERVER_PUBLISH_OUTPUTS -enum -{ +enum { MAX_OUTPUTS = 8, MAX_INPUTS = 8, }; // used by SERVER_GET_LIVE_NODES -enum -{ +enum { MAX_LIVE_INFO = 16, }; // used by SERVER_GET_INSTANCES_FOR -enum -{ +enum { MAX_NODE_ID = 4000, }; // used by SERVER_GET_READERS -enum -{ +enum { MAX_READERS = 40, }; -struct addonserver_instantiate_dormant_node_request : public request_data -{ - media_addon_id addonid; - int32 flavorid; - team_id creator_team; +struct addonserver_instantiate_dormant_node_request : request_data { + media_addon_id addonid; + int32 flavorid; + team_id creator_team; }; -struct addonserver_instantiate_dormant_node_reply : public reply_data -{ - media_node node; +struct addonserver_instantiate_dormant_node_reply : reply_data { + media_node node; }; -struct server_set_node_request : public request_data -{ - node_type type; - bool use_node; - media_node node; - bool use_dni; - dormant_node_info dni; - bool use_input; - media_input input; +struct server_set_node_request : request_data { + node_type type; + bool use_node; + media_node node; + bool use_dni; + dormant_node_info dni; + bool use_input; + media_input input; }; -struct server_set_node_reply : public reply_data -{ +struct server_set_node_reply : reply_data { }; -struct server_get_node_request : public request_data -{ - node_type type; - team_id team; +struct server_get_node_request : request_data { + node_type type; + team_id team; }; -struct server_get_node_reply : public reply_data -{ - media_node node; +struct server_get_node_reply : public reply_data { + media_node node; // for AUDIO_OUTPUT_EX - char input_name[B_MEDIA_NAME_LENGTH]; - int32 input_id; + char input_name[B_MEDIA_NAME_LENGTH]; + int32 input_id; }; -struct producer_format_proposal_request : public request_data -{ - media_source output; - media_format format; +struct producer_format_proposal_request : public request_data { + media_source output; + media_format format; }; -struct producer_format_proposal_reply : public reply_data -{ - media_format format; +struct producer_format_proposal_reply : reply_data { + media_format format; }; -struct producer_prepare_to_connect_request : public request_data -{ - media_source source; - media_destination destination; - media_format format; - char name[B_MEDIA_NAME_LENGTH]; +struct producer_prepare_to_connect_request : request_data { + media_source source; + media_destination destination; + media_format format; + char name[B_MEDIA_NAME_LENGTH]; }; -struct producer_prepare_to_connect_reply : public reply_data -{ - media_format format; - media_source out_source; - char name[B_MEDIA_NAME_LENGTH]; +struct producer_prepare_to_connect_reply : reply_data { + media_format format; + media_source out_source; + char name[B_MEDIA_NAME_LENGTH]; }; -struct producer_connect_request : public request_data -{ - status_t error; - media_source source; - media_destination destination; - media_format format; - char name[B_MEDIA_NAME_LENGTH]; +struct producer_connect_request : request_data { + status_t error; + media_source source; + media_destination destination; + media_format format; + char name[B_MEDIA_NAME_LENGTH]; }; -struct producer_connect_reply : public reply_data -{ - char name[B_MEDIA_NAME_LENGTH]; +struct producer_connect_reply : reply_data { + char name[B_MEDIA_NAME_LENGTH]; }; -struct producer_disconnect_request : public request_data -{ - media_source source; - media_destination destination; +struct producer_disconnect_request : request_data { + media_source source; + media_destination destination; }; -struct producer_disconnect_reply : public reply_data -{ +struct producer_disconnect_reply : reply_data { }; -struct producer_format_suggestion_requested_request : public request_data -{ - media_type type; - int32 quality; +struct producer_format_suggestion_requested_request : request_data { + media_type type; + int32 quality; }; -struct producer_format_suggestion_requested_reply : public reply_data -{ - media_format format; +struct producer_format_suggestion_requested_reply : reply_data { + media_format format; }; -struct producer_set_play_rate_request : public request_data -{ - int32 numer; - int32 denom; +struct producer_set_play_rate_request : request_data { + int32 numer; + int32 denom; }; -struct producer_set_play_rate_reply : public reply_data -{ +struct producer_set_play_rate_reply : reply_data { }; -struct producer_get_initial_latency_request : public request_data -{ +struct producer_get_initial_latency_request : request_data { }; -struct producer_get_initial_latency_reply : public reply_data -{ - bigtime_t initial_latency; - uint32 flags; +struct producer_get_initial_latency_reply : reply_data { + bigtime_t initial_latency; + uint32 flags; }; -struct producer_get_latency_request : public request_data -{ +struct producer_get_latency_request : request_data { }; -struct producer_get_latency_reply : public reply_data -{ - bigtime_t latency; +struct producer_get_latency_reply : reply_data { + bigtime_t latency; }; -struct producer_set_buffer_group_command : public command_data -{ - media_source source; - media_destination destination; - void *user_data; - int32 change_tag; - int32 buffer_count; - media_buffer_id buffers[1]; +struct producer_set_buffer_group_command : command_data { + media_source source; + media_destination destination; + void* user_data; + int32 change_tag; + int32 buffer_count; + media_buffer_id buffers[1]; }; -struct producer_format_change_requested_command : public command_data -{ - media_source source; - media_destination destination; - media_format format; - void *user_data; - int32 change_tag; +struct producer_format_change_requested_command : command_data { + media_source source; + media_destination destination; + media_format format; + void* user_data; + int32 change_tag; }; -struct producer_video_clipping_changed_command : public command_data -{ - media_source source; - media_destination destination; +struct producer_video_clipping_changed_command : command_data { + media_source source; + media_destination destination; media_video_display_info display; - void *user_data; - int32 change_tag; - int32 short_count; - int16 shorts[1]; + void* user_data; + int32 change_tag; + int32 short_count; + int16 shorts[1]; }; -struct producer_additional_buffer_requested_command : public command_data -{ - media_source source; - media_buffer_id prev_buffer; - bigtime_t prev_time; - bool has_seek_tag; - media_seek_tag prev_tag; +struct producer_additional_buffer_requested_command : command_data { + media_source source; + media_buffer_id prev_buffer; + bigtime_t prev_time; + bool has_seek_tag; + media_seek_tag prev_tag; }; -struct producer_latency_changed_command : public command_data -{ - media_source source; - media_destination destination; - bigtime_t latency; - uint32 flags; +struct producer_latency_changed_command : command_data { + media_source source; + media_destination destination; + bigtime_t latency; + uint32 flags; }; -struct producer_enable_output_command : public command_data -{ - media_source source; - media_destination destination; - bool enabled; - void *user_data; - int32 change_tag; +struct producer_enable_output_command : command_data { + media_source source; + media_destination destination; + bool enabled; + void* user_data; + int32 change_tag; }; -struct producer_late_notice_received_command : public command_data -{ - media_source source; - bigtime_t how_much; - bigtime_t performance_time; +struct producer_late_notice_received_command : command_data { + media_source source; + bigtime_t how_much; + bigtime_t performance_time; }; -struct producer_set_run_mode_delay_command : public command_data -{ - BMediaNode::run_mode mode; - bigtime_t delay; +struct producer_set_run_mode_delay_command : command_data { + BMediaNode::run_mode mode; + bigtime_t delay; }; -struct consumer_accept_format_request : public request_data -{ - media_destination dest; - media_format format; +struct consumer_accept_format_request : request_data { + media_destination dest; + media_format format; }; -struct consumer_accept_format_reply : public reply_data -{ - media_format format; +struct consumer_accept_format_reply : reply_data { + media_format format; }; -struct consumer_connected_request : public request_data -{ - media_input input; +struct consumer_connected_request : request_data { + media_input input; }; -struct consumer_connected_reply : public reply_data -{ - media_input input; +struct consumer_connected_reply : reply_data { + media_input input; }; -struct server_publish_inputs_request : public request_data -{ - media_node node; - int32 count; +struct server_publish_inputs_request : request_data { + media_node node; + int32 count; area_id area; // if count > MAX_INPUTS, inputs are in the area // area is created in the library, and also deleted // in the library after the reply has been received media_input inputs[MAX_INPUTS]; }; -struct server_publish_inputs_reply : public reply_data -{ +struct server_publish_inputs_reply : reply_data { }; -struct server_publish_outputs_request : public request_data -{ - media_node node; - int32 count; - area_id area; // if count > MAX_OUTPUTS, outputs are in the area - // area is created in the library, and also deleted - // in the library after the reply has been received +struct server_publish_outputs_request : area_request_data { + media_node node; + int32 count; + // if count > MAX_OUTPUTS, outputs are in the area + // area is created in the library, and also deleted + // in the library after the reply has been received media_output outputs[MAX_OUTPUTS]; }; -struct server_publish_outputs_reply : public reply_data -{ +struct server_publish_outputs_reply : reply_data { }; -struct producer_get_next_output_request : public request_data -{ - int32 cookie; +struct producer_get_next_output_request : request_data { + int32 cookie; }; -struct producer_get_next_output_reply : public reply_data +struct producer_get_next_output_reply : reply_data { - int32 cookie; - media_output output; + int32 cookie; + media_output output; }; -struct producer_dispose_output_cookie_request : public request_data +struct producer_dispose_output_cookie_request : request_data { - int32 cookie; + int32 cookie; }; -struct producer_dispose_output_cookie_reply : public reply_data -{ +struct producer_dispose_output_cookie_reply : reply_data { }; -struct consumer_get_next_input_request : public request_data -{ - int32 cookie; +struct consumer_get_next_input_request : request_data { + int32 cookie; }; -struct consumer_get_next_input_reply : public reply_data -{ - int32 cookie; - media_input input; +struct consumer_get_next_input_reply : reply_data { + int32 cookie; + media_input input; }; -struct consumer_dispose_input_cookie_request : public request_data -{ - int32 cookie; +struct consumer_dispose_input_cookie_request : request_data { + int32 cookie; }; -struct consumer_dispose_input_cookie_reply : public reply_data -{ +struct consumer_dispose_input_cookie_reply : reply_data { }; -struct consumer_disconnected_request : public request_data -{ - media_source source; - media_destination destination; +struct consumer_disconnected_request : request_data { + media_source source; + media_destination destination; }; -struct consumer_disconnected_reply : public reply_data -{ +struct consumer_disconnected_reply : reply_data { }; -struct consumer_buffer_received_command : public command_data -{ - media_buffer_id buffer; - media_header header; +struct consumer_buffer_received_command : command_data { + media_buffer_id buffer; + media_header header; }; -struct consumer_producer_data_status_command : public command_data -{ - media_destination for_whom; - int32 status; - bigtime_t at_performance_time; +struct consumer_producer_data_status_command : command_data { + media_destination for_whom; + int32 status; + bigtime_t at_performance_time; }; -struct consumer_get_latency_for_request : public request_data -{ - media_destination for_whom; +struct consumer_get_latency_for_request : request_data { + media_destination for_whom; }; -struct consumer_get_latency_for_reply : public reply_data -{ - bigtime_t latency; - media_node_id timesource; +struct consumer_get_latency_for_reply : reply_data { + bigtime_t latency; + media_node_id timesource; }; -struct consumer_format_changed_request : public request_data -{ - media_source producer; - media_destination consumer; - int32 change_tag; - media_format format; +struct consumer_format_changed_request : request_data { + media_source producer; + media_destination consumer; + int32 change_tag; + media_format format; }; -struct consumer_format_changed_reply : public reply_data -{ +struct consumer_format_changed_reply : reply_data { }; -struct consumer_seek_tag_requested_request : public request_data -{ - media_destination destination; - bigtime_t target_time; - uint32 flags; +struct consumer_seek_tag_requested_request : request_data { + media_destination destination; + bigtime_t target_time; + uint32 flags; }; -struct consumer_seek_tag_requested_reply : public reply_data -{ - media_seek_tag seek_tag; - bigtime_t tagged_time; - uint32 flags; +struct consumer_seek_tag_requested_reply : reply_data { + media_seek_tag seek_tag; + bigtime_t tagged_time; + uint32 flags; }; -struct server_register_app_request : public request_data -{ - team_id team; - BMessenger messenger; +struct server_register_app_request : request_data { + team_id team; + BMessenger messenger; }; -struct server_register_app_reply : public reply_data -{ +struct server_register_app_reply : reply_data { }; -struct server_unregister_app_request : public request_data -{ - team_id team; +struct server_unregister_app_request : request_data { + team_id team; }; -struct server_unregister_app_reply : public reply_data -{ +struct server_unregister_app_reply : reply_data { }; -struct server_set_node_creator_request : public request_data -{ - media_node_id node; - team_id creator; +struct server_set_node_creator_request : request_data { + media_node_id node; + team_id creator; }; -struct server_set_node_creator_reply : public reply_data -{ +struct server_set_node_creator_reply : reply_data { }; -struct server_change_addon_flavor_instances_count_request : public request_data -{ - media_addon_id addonid; - int32 flavorid; - int32 delta; // must be +1 or -1 - team_id team; +struct server_change_addon_flavor_instances_count_request : request_data { + media_addon_id addonid; + int32 flavorid; + int32 delta; // must be +1 or -1 + team_id team; }; -struct server_change_addon_flavor_instances_count_reply : public reply_data -{ +struct server_change_addon_flavor_instances_count_reply : reply_data { }; -struct server_register_node_request : public request_data -{ - media_addon_id addon_id; - int32 addon_flavor_id; - char name[B_MEDIA_NAME_LENGTH]; - uint64 kinds; - port_id port; - team_id team; +struct server_register_node_request : request_data { + media_addon_id addon_id; + int32 addon_flavor_id; + char name[B_MEDIA_NAME_LENGTH]; + uint64 kinds; + port_id port; + team_id team; }; -struct server_register_node_reply : public reply_data -{ - media_node_id nodeid; +struct server_register_node_reply : reply_data { + media_node_id nodeid; }; -struct server_unregister_node_request : public request_data -{ - media_node_id nodeid; - team_id team; +struct server_unregister_node_request : request_data { + media_node_id nodeid; + team_id team; }; -struct server_unregister_node_reply : public reply_data -{ - media_addon_id addonid; - int32 flavorid; +struct server_unregister_node_reply : reply_data { + media_addon_id addonid; + int32 flavorid; }; -struct server_get_live_node_info_request : public request_data -{ - media_node node; +struct server_get_live_node_info_request : request_data { + media_node node; }; -struct server_get_live_node_info_reply : public reply_data -{ - live_node_info live_info; +struct server_get_live_node_info_reply : reply_data { + live_node_info live_info; }; -struct server_get_live_nodes_request : public request_data -{ - int32 maxcount; - bool has_input; - bool has_output; - bool has_name; - media_format inputformat; - media_format outputformat; - char name[B_MEDIA_NAME_LENGTH + 1]; // 1 for a trailing "*" - uint64 require_kinds; +struct server_get_live_nodes_request : request_data { + int32 maxcount; + bool has_input; + bool has_output; + bool has_name; + media_format inputformat; + media_format outputformat; + char name[B_MEDIA_NAME_LENGTH + 1]; + // +1 for a trailing "*" + uint64 require_kinds; }; -struct server_get_live_nodes_reply : public reply_data -{ - int32 count; - area_id area; // if count > MAX_LIVE_INFO, live_node_infos are in the area - // area is created in the server, but deleted in the library - live_node_info live_info[MAX_LIVE_INFO]; +struct server_get_live_nodes_reply : area_reply_data { + int32 count; + // if count > MAX_LIVE_INFO, live_node_infos are in the area + // area is created in the server, but deleted in the library + live_node_info live_info[MAX_LIVE_INFO]; }; -struct server_node_id_for_request : public request_data -{ - port_id port; +struct server_node_id_for_request : request_data { + port_id port; }; -struct server_node_id_for_reply : public reply_data -{ - media_node_id nodeid; +struct server_node_id_for_reply : reply_data { + media_node_id nodeid; }; -struct server_get_node_for_request : public request_data -{ - media_node_id nodeid; - team_id team; +struct server_get_node_for_request : request_data { + media_node_id nodeid; + team_id team; }; -struct server_get_node_for_reply : public reply_data -{ - media_node clone; +struct server_get_node_for_reply : reply_data { + media_node clone; }; -struct server_release_node_request : public request_data -{ - media_node node; - team_id team; +struct server_release_node_request : request_data { + media_node node; + team_id team; }; -struct server_release_node_reply : public reply_data -{ +struct server_release_node_reply : reply_data { }; -struct server_get_dormant_node_for_request : public request_data -{ - media_node node; +struct server_get_dormant_node_for_request : request_data { + media_node node; }; -struct server_get_dormant_node_for_reply : public reply_data -{ - dormant_node_info node_info; +struct server_get_dormant_node_for_reply : reply_data { + dormant_node_info node_info; }; -struct server_get_instances_for_request : public request_data -{ - int32 maxcount; - media_addon_id addon_id; - int32 addon_flavor_id; +struct server_get_instances_for_request : request_data { + int32 maxcount; + media_addon_id addon_id; + int32 addon_flavor_id; }; -struct server_get_instances_for_reply : public reply_data -{ - int32 count; - media_node_id node_id[MAX_NODE_ID]; // no area here, MAX_NODE_ID is really large +struct server_get_instances_for_reply : reply_data { + int32 count; + media_node_id node_id[MAX_NODE_ID]; + // no area here, MAX_NODE_ID is really large }; -struct server_rescan_defaults_command : public command_data -{ +struct server_rescan_defaults_command : command_data { }; -struct addonserver_rescan_mediaaddon_flavors_command : public command_data -{ - media_addon_id addonid; +struct addonserver_rescan_mediaaddon_flavors_command : command_data { + media_addon_id addonid; }; -struct server_register_mediaaddon_request : public request_data -{ - xfer_entry_ref ref; // a ref to the file +struct server_register_mediaaddon_request : request_data { + xfer_entry_ref ref; }; -struct server_register_mediaaddon_reply : public reply_data -{ - media_addon_id addonid; +struct server_register_mediaaddon_reply : reply_data { + media_addon_id addonid; }; -struct server_unregister_mediaaddon_command : public command_data -{ - media_addon_id addonid; +struct server_unregister_mediaaddon_command : command_data { + media_addon_id addonid; }; -struct server_get_mediaaddon_ref_request : public request_data -{ - media_addon_id addonid; +struct server_get_mediaaddon_ref_request : request_data { + media_addon_id addonid; }; -struct server_get_mediaaddon_ref_reply : public reply_data -{ - xfer_entry_ref ref; // a ref to the file +struct server_get_mediaaddon_ref_reply : reply_data { + xfer_entry_ref ref; }; -struct server_get_shared_buffer_area_request : public request_data -{ +struct server_get_shared_buffer_area_request : request_data { }; -struct server_get_shared_buffer_area_reply : public reply_data -{ - area_id area; +struct server_get_shared_buffer_area_reply : area_reply_data { }; -struct server_register_buffer_request : public request_data -{ - team_id team; - //either info.buffer is != 0, or the area, size, offset is used - buffer_clone_info info; +struct server_register_buffer_request : request_data { + team_id team; + buffer_clone_info info; + // either info.buffer is != 0, or the area, size, offset is used }; -struct server_register_buffer_reply : public reply_data -{ - buffer_clone_info info; +struct server_register_buffer_reply : reply_data { + buffer_clone_info info; }; -struct server_unregister_buffer_command : public command_data -{ - team_id team; - media_buffer_id bufferid; +struct server_unregister_buffer_command : command_data { + team_id team; + media_buffer_id bufferid; }; -struct server_rewindtypes_request : public request_data -{ +struct server_rewindtypes_request : request_data { }; -struct server_rewindtypes_reply : public reply_data -{ - int32 count; - area_id area; +struct server_rewindtypes_reply : area_reply_data { + int32 count; }; -struct server_rewindrefs_request : public request_data -{ - char type[B_MEDIA_NAME_LENGTH]; +struct server_rewindrefs_request : request_data { + char type[B_MEDIA_NAME_LENGTH]; }; -struct server_rewindrefs_reply : public reply_data -{ - int32 count; - area_id area; +struct server_rewindrefs_reply : area_reply_data { + int32 count; }; -struct server_getreffor_request : public request_data -{ - char type[B_MEDIA_NAME_LENGTH]; - char item[B_MEDIA_NAME_LENGTH]; +struct server_getreffor_request : request_data { + char type[B_MEDIA_NAME_LENGTH]; + char item[B_MEDIA_NAME_LENGTH]; }; -struct server_getreffor_reply : public reply_data -{ - xfer_entry_ref ref; // a ref to the file +struct server_getreffor_reply : reply_data { + xfer_entry_ref ref; }; -struct server_setreffor_request : public request_data -{ - char type[B_MEDIA_NAME_LENGTH]; - char item[B_MEDIA_NAME_LENGTH]; - xfer_entry_ref ref; // a ref to the file +struct server_setreffor_request : request_data { + char type[B_MEDIA_NAME_LENGTH]; + char item[B_MEDIA_NAME_LENGTH]; + xfer_entry_ref ref; }; -struct server_setreffor_reply : public reply_data -{ +struct server_setreffor_reply : reply_data { }; -struct server_removereffor_request : public request_data -{ - char type[B_MEDIA_NAME_LENGTH]; - char item[B_MEDIA_NAME_LENGTH]; - xfer_entry_ref ref; // a ref to the file +struct server_removereffor_request : request_data { + char type[B_MEDIA_NAME_LENGTH]; + char item[B_MEDIA_NAME_LENGTH]; + xfer_entry_ref ref; }; -struct server_removereffor_reply : public reply_data -{ +struct server_removereffor_reply : reply_data { }; -struct server_removeitem_request : public request_data -{ - char type[B_MEDIA_NAME_LENGTH]; - char item[B_MEDIA_NAME_LENGTH]; +struct server_removeitem_request : request_data { + char type[B_MEDIA_NAME_LENGTH]; + char item[B_MEDIA_NAME_LENGTH]; }; -struct server_removeitem_reply : public reply_data -{ +struct server_removeitem_reply : reply_data { }; -struct server_get_decoder_for_format_request : public request_data -{ - media_format format; +struct server_get_decoder_for_format_request : request_data { + media_format format; }; -struct server_get_decoder_for_format_reply : public reply_data -{ - xfer_entry_ref ref; // a ref to the decoder +struct server_get_decoder_for_format_reply : reply_data { + xfer_entry_ref ref; + // a ref to the decoder }; -struct server_get_readers_request : public request_data -{ +struct server_get_readers_request : request_data { }; -struct server_get_readers_reply : public reply_data -{ - xfer_entry_ref ref[MAX_READERS]; // a list of refs to the reader - int32 count; +struct server_get_readers_reply : reply_data { + xfer_entry_ref ref[MAX_READERS]; + // a list of refs to the reader + int32 count; }; -struct node_request_completed_command : public command_data -{ - media_request_info info; +struct node_request_completed_command : command_data { + media_request_info info; }; -struct node_start_command : public command_data -{ - bigtime_t performance_time; +struct node_start_command : command_data { + bigtime_t performance_time; }; -struct node_stop_command : public command_data -{ - bigtime_t performance_time; - bool immediate; +struct node_stop_command : command_data { + bigtime_t performance_time; + bool immediate; }; -struct node_seek_command : public command_data -{ - bigtime_t media_time; - bigtime_t performance_time; +struct node_seek_command : command_data { + bigtime_t media_time; + bigtime_t performance_time; }; -struct node_set_run_mode_command : public command_data -{ - BMediaNode::run_mode mode; +struct node_set_run_mode_command : command_data { + BMediaNode::run_mode mode; }; -struct node_time_warp_command : public command_data -{ - bigtime_t at_real_time; - bigtime_t to_performance_time; +struct node_time_warp_command : command_data { + bigtime_t at_real_time; + bigtime_t to_performance_time; }; -struct node_set_timesource_command : public command_data -{ - media_node_id timesource_id; +struct node_set_timesource_command : command_data { + media_node_id timesource_id; }; -struct node_get_timesource_request : public request_data -{ +struct node_get_timesource_request : request_data { }; -struct node_get_timesource_reply : public reply_data -{ - media_node_id timesource_id; +struct node_get_timesource_reply : reply_data { + media_node_id timesource_id; }; -struct node_final_release_command : public command_data -{ +struct node_final_release_command : command_data { }; -struct timesource_add_slave_node_command : public command_data -{ - media_node node; +struct timesource_add_slave_node_command : command_data { + media_node node; }; -struct timesource_remove_slave_node_command : public command_data -{ - media_node node; +struct timesource_remove_slave_node_command : command_data { + media_node node; }; -struct timesource_get_start_latency_request : public request_data -{ +struct timesource_get_start_latency_request : request_data { }; -struct timesource_get_start_latency_reply : public reply_data -{ - bigtime_t start_latency; +struct timesource_get_start_latency_reply : reply_data { + bigtime_t start_latency; }; -struct fileinterface_set_ref_request : public request_data -{ - dev_t device; - ino_t directory; - char name[B_FILE_NAME_LENGTH]; - bigtime_t duration; - bool create; +struct fileinterface_set_ref_request : request_data { + dev_t device; + ino_t directory; + char name[B_FILE_NAME_LENGTH]; + bigtime_t duration; + bool create; }; -struct fileinterface_set_ref_reply : public reply_data -{ - bigtime_t duration; +struct fileinterface_set_ref_reply : reply_data { + bigtime_t duration; }; -struct fileinterface_get_ref_request : public request_data -{ +struct fileinterface_get_ref_request : request_data { }; -struct fileinterface_get_ref_reply : public reply_data -{ - dev_t device; - ino_t directory; - char name[B_FILE_NAME_LENGTH]; - char mimetype[256]; +struct fileinterface_get_ref_reply : reply_data { + dev_t device; + ino_t directory; + char name[B_FILE_NAME_LENGTH]; + char mimetype[B_MIME_TYPE_LENGTH]; }; -struct fileinterface_sniff_ref_request : public request_data -{ - dev_t device; - ino_t directory; - char name[B_FILE_NAME_LENGTH]; +struct fileinterface_sniff_ref_request : request_data { + dev_t device; + ino_t directory; + char name[B_FILE_NAME_LENGTH]; }; -struct fileinterface_sniff_ref_reply : public reply_data -{ - char mimetype[256]; - float capability; +struct fileinterface_sniff_ref_reply : reply_data { + char mimetype[B_MIME_TYPE_LENGTH]; + float capability; }; -struct controllable_get_parameter_web_request : public request_data -{ - area_id area; - int32 maxsize; +struct controllable_get_parameter_web_request : area_request_data { + int32 max_size; }; -struct controllable_get_parameter_web_reply : public reply_data -{ - type_code code; - int32 size; // = -1: parameter web data too large, = 0: no p.w., > 0: flattened p.w. data +struct controllable_get_parameter_web_reply : reply_data { + type_code code; + int32 size; + // = -1: parameter web data too large, + // = 0: no p.w., > 0: flattened p.w. data }; #define MAX_PARAMETER_DATA (B_MEDIA_MESSAGE_SIZE - 100) -struct controllable_get_parameter_data_request : public request_data -{ - int32 parameter_id; - size_t requestsize; - area_id area; //if area != -1, data is too large and must be passed in the area +struct controllable_get_parameter_data_request : area_request_data { + int32 parameter_id; + size_t request_size; }; -struct controllable_get_parameter_data_reply : public reply_data -{ - bigtime_t last_change; - char rawdata[MAX_PARAMETER_DATA]; - size_t size; +struct controllable_get_parameter_data_reply : reply_data { + bigtime_t last_change; + char raw_data[MAX_PARAMETER_DATA]; + size_t size; }; -struct controllable_set_parameter_data_request : public request_data -{ - int32 parameter_id; - bigtime_t when; - area_id area; //if area != -1, data is too large and is passed in the area - size_t size; - char rawdata[MAX_PARAMETER_DATA]; +struct controllable_set_parameter_data_request : area_request_data { + int32 parameter_id; + bigtime_t when; + size_t size; + char raw_data[MAX_PARAMETER_DATA]; }; -struct controllable_set_parameter_data_reply : public reply_data -{ +struct controllable_set_parameter_data_reply : reply_data { }; -struct controllable_start_control_panel_request : public request_data -{ - media_node node; +struct controllable_start_control_panel_request : request_data { + media_node node; }; -struct controllable_start_control_panel_reply : public reply_data -{ - team_id team; +struct controllable_start_control_panel_reply : reply_data { + team_id team; }; #endif // _DATA_EXCHANGE_H diff --git a/src/kits/media/Controllable.cpp b/src/kits/media/Controllable.cpp index 784411f879..18c17906b4 100644 --- a/src/kits/media/Controllable.cpp +++ b/src/kits/media/Controllable.cpp @@ -1,3 +1,8 @@ +/* + * Copyright 2009, Axel Dörfler, axeld@pinc-software.de. + * Distributed under the terms of the MIT license. + */ + /* * Copyright (c) 2002, 2003 Marcus Overhagen * @@ -35,32 +40,82 @@ #include "DataExchange.h" #include "Notifications.h" -/************************************************************* - * protected BControllable - *************************************************************/ + +namespace BPrivate { namespace media { + +/*! A helper class for the communication with the media server that + takes care of large buffers that need an area. +*/ +class ReceiveTransfer { +public: + ReceiveTransfer(const area_request_data& request, const void* smallBuffer) + { + if (request.area == -1 && smallBuffer != NULL) { + // small data transfer uses buffer in reply + fArea = -1; + fData = const_cast(smallBuffer); + // The caller is actually responsible to enforce the const; + // we don't touch the data. + } else { + // large data transfer, clone area + fArea = clone_area("get parameter data clone", &fData, + B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA, request.area); + if (fArea < B_OK) { + ERROR("BControllabe: cloning area failed: %s\n", + strerror(fArea)); + fData = NULL; + } + } + } + + ~ReceiveTransfer() + { + if (fArea >= B_OK) + delete_area(fArea); + } + + status_t InitCheck() const + { + return fData != NULL ? B_OK : fArea; + } + + void* Data() const + { + return fData; + } + +private: + area_id fArea; + void* fData; +}; + +} // namespace media +} // namespace BPrivate + +using BPrivate::media::ReceiveTransfer; + + +// #pragma mark - protected + BControllable::~BControllable() { CALLED(); if (fSem > 0) delete_sem(fSem); - if (fWeb) - delete fWeb; + + delete fWeb; } -/************************************************************* - * public BControllable - *************************************************************/ -BParameterWeb * +// #pragma mark - public + + +BParameterWeb* BControllable::Web() { CALLED(); - BParameterWeb *temp; - LockParameterWeb(); - temp = fWeb; - UnlockParameterWeb(); - return temp; + return fWeb; } @@ -68,20 +123,21 @@ bool BControllable::LockParameterWeb() { CALLED(); - status_t rv; if (fSem <= 0) return false; + if (atomic_add(&fBen, 1) > 0) { - while (B_INTERRUPTED == (rv = acquire_sem(fSem))) - ; - return rv == B_OK; + status_t status; + do { + status = acquire_sem(fSem); + } while (status == B_INTERRUPTED); + + return status == B_OK; } + return true; } -/************************************************************* - * protected BControllable - *************************************************************/ void BControllable::UnlockParameterWeb() @@ -89,14 +145,18 @@ BControllable::UnlockParameterWeb() CALLED(); if (fSem <= 0) return; + if (atomic_add(&fBen, -1) > 1) release_sem(fSem); } -BControllable::BControllable() : - BMediaNode("this one is never called"), - fWeb(0), +// #pragma mark - protected + + +BControllable::BControllable() + : BMediaNode("this one is never called"), + fWeb(NULL), fSem(create_sem(0, "BControllable lock")), fBen(0) { @@ -107,19 +167,22 @@ BControllable::BControllable() : status_t -BControllable::SetParameterWeb(BParameterWeb *web) +BControllable::SetParameterWeb(BParameterWeb* web) { CALLED(); - BParameterWeb *old; + LockParameterWeb(); - old = fWeb; + BParameterWeb* old = fWeb; fWeb = web; - if (fWeb) - fWeb->fNode = Node(); // initialize BParameterWeb member variable - + if (fWeb != NULL) { + // initialize BParameterWeb member variable + fWeb->fNode = Node(); + } + UnlockParameterWeb(); - if (old != web && web != 0) + + if (old != web && web != NULL) BPrivate::media::notifications::WebChanged(Node()); delete old; return B_OK; @@ -127,122 +190,124 @@ BControllable::SetParameterWeb(BParameterWeb *web) status_t -BControllable::HandleMessage(int32 message, const void *data, size_t size) +BControllable::HandleMessage(int32 message, const void* data, size_t size) { PRINT(4, "BControllable::HandleMessage %#lx, node %ld\n", message, ID()); - status_t rv; switch (message) { case CONTROLLABLE_GET_PARAMETER_DATA: { - const controllable_get_parameter_data_request *request = static_cast(data); + const controllable_get_parameter_data_request& request + = *static_cast( + data); controllable_get_parameter_data_reply reply; - area_id area; - void *data; - - if (request->area == -1) { - // small data transfer uses buffer in reply - area = -1; - data = reply.rawdata; - } else { - // large data transfer, clone area - area = clone_area("get parameter data clone", &data, B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA, request->area); - if (area < B_OK) { - ERROR("CONTROLLABLE_GET_PARAMETER_DATA cloning area failed\n"); - request->SendReply(B_NO_MEMORY, &reply, sizeof(reply)); - return B_OK; - } + + ReceiveTransfer transfer(request, reply.raw_data); + if (transfer.InitCheck() != B_OK) { + request.SendReply(transfer.InitCheck(), &reply, sizeof(reply)); + return B_OK; } - reply.size = request->requestsize; - rv = GetParameterValue(request->parameter_id, &reply.last_change, data, &reply.size); - if (area != -1) - delete_area(area); - request->SendReply(rv, &reply, sizeof(reply)); + + reply.size = request.request_size; + status_t status = GetParameterValue(request.parameter_id, + &reply.last_change, transfer.Data(), &reply.size); + + request.SendReply(status, &reply, sizeof(reply)); return B_OK; } case CONTROLLABLE_SET_PARAMETER_DATA: { - const controllable_set_parameter_data_request *request = static_cast(data); + const controllable_set_parameter_data_request& request + = *static_cast( + data); controllable_set_parameter_data_reply reply; - area_id area; - const void *data; - - if (request->area == -1) { - // small data transfer uses buffer in request - area = -1; - data = request->rawdata; - } else { - // large data transfer, clone area - area = clone_area("set parameter data clone", (void **)&data, B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA, request->area); - if (area < B_OK) { - ERROR("CONTROLLABLE_SET_PARAMETER_DATA cloning area failed\n"); - request->SendReply(B_NO_MEMORY, &reply, sizeof(reply)); - return B_OK; - } + + ReceiveTransfer transfer(request, request.raw_data); + if (transfer.InitCheck() != B_OK) { + request.SendReply(transfer.InitCheck(), &reply, sizeof(reply)); + return B_OK; } - SetParameterValue(request->parameter_id, request->when, data, request->size); - if (area != -1) - delete_area(area); - request->SendReply(B_OK, &reply, sizeof(reply)); + + SetParameterValue(request.parameter_id, request.when, + transfer.Data(), request.size); + request.SendReply(B_OK, &reply, sizeof(reply)); return B_OK; } - + case CONTROLLABLE_GET_PARAMETER_WEB: { - const controllable_get_parameter_web_request *request = static_cast(data); + const controllable_get_parameter_web_request& request + = *static_cast( + data); controllable_get_parameter_web_reply reply; - bool waslocked = LockParameterWeb(); - if (fWeb != NULL && fWeb->FlattenedSize() > request->maxsize) { - reply.code = 0; - reply.size = -1; // parameter web too large - rv = B_OK; - } else if (fWeb != NULL && fWeb->FlattenedSize() <= request->maxsize) { - void *buffer; - area_id area; - area = clone_area("cloned parameter web", &buffer, B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA, request->area); - if (area < B_OK) { - ERROR("BControllable::HandleMessage CONTROLLABLE_GET_PARAMETER_WEB clone_area failed\n"); - rv = B_ERROR; + + status_t status = B_OK; + bool wasLocked = true; + if (!LockParameterWeb()) { + status = B_ERROR; + wasLocked = false; + } + + if (status == B_OK && fWeb != NULL) { + if (fWeb->FlattenedSize() > request.max_size) { + // parameter web too large + reply.code = 0; + reply.size = -1; + status = B_OK; } else { - reply.code = fWeb->TypeCode(); - reply.size = fWeb->FlattenedSize(); - rv = fWeb->Flatten(buffer, reply.size); - if (rv != B_OK) { - ERROR("BControllable::HandleMessage CONTROLLABLE_GET_PARAMETER_WEB Flatten failed\n"); - } else { - printf("BControllable::HandleMessage CONTROLLABLE_GET_PARAMETER_WEB %ld bytes, 0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx\n", - reply.size, ((uint32*)buffer)[0], ((uint32*)buffer)[1], ((uint32*)buffer)[2], ((uint32*)buffer)[3]); + ReceiveTransfer transfer(request, NULL); + status = transfer.InitCheck(); + if (status == B_OK) { + reply.code = fWeb->TypeCode(); + reply.size = fWeb->FlattenedSize(); + status = fWeb->Flatten(transfer.Data(), reply.size); + if (status != B_OK) { + ERROR("BControllable::HandleMessage " + "CONTROLLABLE_GET_PARAMETER_WEB Flatten failed\n"); +#if 0 + } else { + printf("BControllable::HandleMessage CONTROLLABLE_GET_PARAMETER_WEB %ld bytes, 0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx\n", + reply.size, ((uint32*)buffer)[0], ((uint32*)buffer)[1], ((uint32*)buffer)[2], ((uint32*)buffer)[3]); +#endif + } } - delete_area(area); } } else { + // no parameter web reply.code = 0; - reply.size = 0; // no parameter web - rv = B_OK; + reply.size = 0; } - if (waslocked) + if (wasLocked) UnlockParameterWeb(); - request->SendReply(rv, &reply, sizeof(reply)); + + request.SendReply(status, &reply, sizeof(reply)); return B_OK; } case CONTROLLABLE_START_CONTROL_PANEL: { - const controllable_start_control_panel_request *request = static_cast(data); + const controllable_start_control_panel_request* request + = static_cast( + data); controllable_start_control_panel_reply reply; BMessenger targetMessenger; - rv = StartControlPanel(&targetMessenger); - if (rv != B_OK) { - ERROR("BControllable::HandleMessage CONTROLLABLE_START_CONTROL_PANEL failed\n"); + status_t status = StartControlPanel(&targetMessenger); + if (status != B_OK) { + ERROR("BControllable::HandleMessage " + "CONTROLLABLE_START_CONTROL_PANEL failed\n"); } - reply.result = rv; + reply.result = status; reply.team = targetMessenger.Team(); - request->SendReply(rv, &reply, sizeof(reply)); + request->SendReply(status, &reply, sizeof(reply)); return B_OK; - } + } + + default: + return B_ERROR; } - return B_ERROR; + + return B_OK; } @@ -255,18 +320,17 @@ BControllable::BroadcastChangedParameter(int32 id) status_t -BControllable::BroadcastNewParameterValue(bigtime_t when, - int32 id, - void *newValue, - size_t valueSize) +BControllable::BroadcastNewParameterValue(bigtime_t when, int32 id, + void* newValue, size_t valueSize) { CALLED(); - return BPrivate::media::notifications::NewParameterValue(Node(), id, when, newValue, valueSize); + return BPrivate::media::notifications::NewParameterValue(Node(), id, when, + newValue, valueSize); } status_t -BControllable::StartControlPanel(BMessenger *out_messenger) +BControllable::StartControlPanel(BMessenger* _messenger) { CALLED(); @@ -277,43 +341,39 @@ BControllable::StartControlPanel(BMessenger *out_messenger) return B_ERROR; } - image_id imageId = addon->ImageID(); + image_id imageID = addon->ImageID(); image_info info; - if ((imageId <= 0) || (get_image_info(imageId, &info) != B_OK)) { + if (imageID <= 0 || get_image_info(imageID, &info) != B_OK) { ERROR("BControllable::StartControlPanel Error accessing image\n"); return B_BAD_VALUE; } - team_id id; entry_ref ref; - - if (BEntry(info.name).GetRef(&ref) != B_OK) { + if (get_ref_for_path(info.name, &ref) != B_OK) { ERROR("BControllable::StartControlPanel Error getting ref\n"); return B_BAD_VALUE; } // The first argument is "node=id" with id meaning the media_node_id - char *arg = (char*) malloc(10); - sprintf(arg, "node=%d" , (int) ID()); + char arg[32]; + snprintf(arg, sizeof(arg), "node=%d", (int)ID()); - if (be_roster->Launch(&ref, 1, &arg, &id) != B_OK) { - free(arg); + team_id team; + if (be_roster->Launch(&ref, 1, (const char* const*)&arg, &team) != B_OK) { ERROR("BControllable::StartControlPanel Error launching application\n"); return B_BAD_VALUE; } - printf("BControllable::StartControlPanel done with id: %ld\n", id); - free(arg); + printf("BControllable::StartControlPanel done with id: %ld\n", team); - if (out_messenger) - *out_messenger = BMessenger(0, id); + if (_messenger) + *_messenger = BMessenger(NULL, team); return B_OK; } status_t -BControllable::ApplyParameterData(const void *value, - size_t size) +BControllable::ApplyParameterData(const void* value, size_t size) { UNIMPLEMENTED(); @@ -322,25 +382,17 @@ BControllable::ApplyParameterData(const void *value, status_t -BControllable::MakeParameterData(const int32 *controls, - int32 count, - void *buf, - size_t *ioSize) +BControllable::MakeParameterData(const int32* controls, int32 count, + void* buffer, size_t* ioSize) { UNIMPLEMENTED(); return B_ERROR; } -/************************************************************* - * private BControllable - *************************************************************/ -/* -private unimplemented -BControllable::BControllable(const BControllable &clone) -BControllable & BControllable::operator=(const BControllable &clone) -*/ +// #pragma mark - private + status_t BControllable::_Reserved_Controllable_0(void *) { return B_ERROR; } status_t BControllable::_Reserved_Controllable_1(void *) { return B_ERROR; } @@ -358,5 +410,3 @@ status_t BControllable::_Reserved_Controllable_12(void *) { return B_ERROR; } status_t BControllable::_Reserved_Controllable_13(void *) { return B_ERROR; } status_t BControllable::_Reserved_Controllable_14(void *) { return B_ERROR; } status_t BControllable::_Reserved_Controllable_15(void *) { return B_ERROR; } - - diff --git a/src/kits/media/MediaRoster.cpp b/src/kits/media/MediaRoster.cpp index bb1e8a5593..3ef5c19a3a 100644 --- a/src/kits/media/MediaRoster.cpp +++ b/src/kits/media/MediaRoster.cpp @@ -1,3 +1,10 @@ +/* + * Copyright 2008 Maurice Kalinowski, haiku@kaldience.com + * Copyright 2009, Axel Dörfler, axeld@pinc-software.de. + * + * All rights reserved. Distributed under the terms of the MIT License. + */ + /* * Copyright (c) 2002-2006 Marcus Overhagen * @@ -26,12 +33,6 @@ * THE SOFTWARE. * */ -/* - * Copyright 2008 Maurice Kalinowski, haiku@kaldience.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ /* to comply with the license above, do not remove the following line */ @@ -88,7 +89,7 @@ using namespace BPrivate::media; // DefaultDeleter will delete the BMediaRoster object in it's destructor. DefaultDeleter _deleter; -BMediaRosterEx::BMediaRosterEx(status_t * out_error) +BMediaRosterEx::BMediaRosterEx(status_t* _error) : BMediaRoster() { status_t rv; @@ -97,15 +98,17 @@ BMediaRosterEx::BMediaRosterEx(status_t * out_error) server_register_app_reply reply; request.team = team; request.messenger = BMessenger(NULL, this); - rv = QueryServer(SERVER_REGISTER_APP, &request, sizeof(request), &reply, sizeof(reply)); + rv = QueryServer(SERVER_REGISTER_APP, &request, sizeof(request), &reply, + sizeof(reply)); if (rv != B_OK) - *out_error = B_MEDIA_SYSTEM_FAILURE; + *_error = B_MEDIA_SYSTEM_FAILURE; else - *out_error = B_OK; + *_error = B_OK; } + status_t -BMediaRosterEx::SaveNodeConfiguration(BMediaNode *node) +BMediaRosterEx::SaveNodeConfiguration(BMediaNode* node) { BMediaAddOn *addon; media_addon_id addonid; @@ -114,69 +117,80 @@ BMediaRosterEx::SaveNodeConfiguration(BMediaNode *node) if (!addon) { // NOTE: This node could have been created by an application, // it does not mean there is an error. - // XXX this check incorrectly triggers on BeOS R5 BT848 node + // TODO: this check incorrectly triggers on BeOS R5 BT848 node TRACE("BMediaRosterEx::SaveNodeConfiguration node %ld not instantiated " "from BMediaAddOn!\n", node->ID()); return B_ERROR; } addonid = addon->AddonID(); - - // XXX fix this + + // TODO: fix this printf("### BMediaRosterEx::SaveNodeConfiguration should save addon-id " "%ld, flavor-id %ld config NOW!\n", addonid, flavorid); return B_OK; } + status_t BMediaRosterEx::LoadNodeConfiguration(media_addon_id addonid, int32 flavorid, BMessage *out_msg) { - // XXX fix this + // TODO: fix this out_msg->MakeEmpty(); // to be fully R5 compliant printf("### BMediaRosterEx::LoadNodeConfiguration should load addon-id " "%ld, flavor-id %ld config NOW!\n", addonid, flavorid); return B_OK; } + status_t -BMediaRosterEx::IncrementAddonFlavorInstancesCount(media_addon_id addonid, int32 flavorid) +BMediaRosterEx::IncrementAddonFlavorInstancesCount(media_addon_id addonid, + int32 flavorid) { server_change_addon_flavor_instances_count_request request; server_change_addon_flavor_instances_count_reply reply; - + request.addonid = addonid; request.flavorid = flavorid; request.delta = 1; request.team = team; - return QueryServer(SERVER_CHANGE_ADDON_FLAVOR_INSTANCES_COUNT, &request, sizeof(request), &reply, sizeof(reply)); + return QueryServer(SERVER_CHANGE_ADDON_FLAVOR_INSTANCES_COUNT, &request, + sizeof(request), &reply, sizeof(reply)); } + status_t -BMediaRosterEx::DecrementAddonFlavorInstancesCount(media_addon_id addonid, int32 flavorid) +BMediaRosterEx::DecrementAddonFlavorInstancesCount(media_addon_id addonid, + int32 flavorid) { server_change_addon_flavor_instances_count_request request; server_change_addon_flavor_instances_count_reply reply; - + request.addonid = addonid; request.flavorid = flavorid; request.delta = -1; request.team = team; - return QueryServer(SERVER_CHANGE_ADDON_FLAVOR_INSTANCES_COUNT, &request, sizeof(request), &reply, sizeof(reply)); + return QueryServer(SERVER_CHANGE_ADDON_FLAVOR_INSTANCES_COUNT, &request, + sizeof(request), &reply, sizeof(reply)); } - + + status_t BMediaRosterEx::SetNodeCreator(media_node_id node, team_id creator) { server_set_node_creator_request request; server_set_node_creator_reply reply; - + request.node = node; request.creator = creator; - return QueryServer(SERVER_SET_NODE_CREATOR, &request, sizeof(request), &reply, sizeof(reply)); + return QueryServer(SERVER_SET_NODE_CREATOR, &request, sizeof(request), + &reply, sizeof(reply)); } + status_t -BMediaRosterEx::GetNode(node_type type, media_node * out_node, int32 * out_input_id, BString * out_input_name) +BMediaRosterEx::GetNode(node_type type, media_node* out_node, + int32* out_input_id, BString* out_input_name) { if (out_node == NULL) return B_BAD_VALUE; @@ -187,7 +201,8 @@ BMediaRosterEx::GetNode(node_type type, media_node * out_node, int32 * out_input request.type = type; request.team = team; - rv = QueryServer(SERVER_GET_NODE, &request, sizeof(request), &reply, sizeof(reply)); + rv = QueryServer(SERVER_GET_NODE, &request, sizeof(request), &reply, + sizeof(reply)); if (rv != B_OK) return rv; @@ -199,40 +214,46 @@ BMediaRosterEx::GetNode(node_type type, media_node * out_node, int32 * out_input return rv; } + status_t -BMediaRosterEx::SetNode(node_type type, const media_node *node, const dormant_node_info *info, const media_input *input) +BMediaRosterEx::SetNode(node_type type, const media_node* node, + const dormant_node_info* info, const media_input* input) { server_set_node_request request; server_set_node_reply reply; - + request.type = type; - request.use_node = node ? true : false; - if (node) + request.use_node = node != NULL; + if (node != NULL) request.node = *node; - request.use_dni = info ? true : false; - if (info) + request.use_dni = info != NULL; + if (info != NULL) request.dni = *info; - request.use_input = input ? true : false; - if (input) + request.use_input = input != NULL; + if (input != NULL) request.input = *input; - - return QueryServer(SERVER_SET_NODE, &request, sizeof(request), &reply, sizeof(reply)); + + return QueryServer(SERVER_SET_NODE, &request, sizeof(request), &reply, + sizeof(reply)); } + status_t -BMediaRosterEx::GetAllOutputs(const media_node & node, List *list) +BMediaRosterEx::GetAllOutputs(const media_node& node, List* list) { int32 cookie; status_t rv; status_t result; - - PRINT(4, "BMediaRosterEx::GetAllOutputs() node %ld, port %ld\n", node.node, node.port); + + PRINT(4, "BMediaRosterEx::GetAllOutputs() node %ld, port %ld\n", node.node, + node.port); if (!(node.kind & B_BUFFER_PRODUCER)) { - ERROR("BMediaRosterEx::GetAllOutputs: node %ld is not a B_BUFFER_PRODUCER\n", node.node); + ERROR("BMediaRosterEx::GetAllOutputs: node %ld is not a " + "B_BUFFER_PRODUCER\n", node.node); return B_MEDIA_BAD_NODE; } - + result = B_OK; cookie = 0; list->MakeEmpty(); @@ -240,7 +261,8 @@ BMediaRosterEx::GetAllOutputs(const media_node & node, List *list) producer_get_next_output_request request; producer_get_next_output_reply reply; request.cookie = cookie; - rv = QueryPort(node.port, PRODUCER_GET_NEXT_OUTPUT, &request, sizeof(request), &reply, sizeof(reply)); + rv = QueryPort(node.port, PRODUCER_GET_NEXT_OUTPUT, &request, + sizeof(request), &reply, sizeof(reply)); if (rv != B_OK) break; cookie = reply.cookie; @@ -256,19 +278,21 @@ BMediaRosterEx::GetAllOutputs(const media_node & node, List *list) producer_dispose_output_cookie_request request; producer_dispose_output_cookie_reply reply; - QueryPort(node.port, PRODUCER_DISPOSE_OUTPUT_COOKIE, &request, sizeof(request), &reply, sizeof(reply)); - + QueryPort(node.port, PRODUCER_DISPOSE_OUTPUT_COOKIE, &request, + sizeof(request), &reply, sizeof(reply)); + return result; } + status_t -BMediaRosterEx::GetAllOutputs(BBufferProducer *node, List *list) +BMediaRosterEx::GetAllOutputs(BBufferProducer* node, List* list) { int32 cookie; status_t result; - + PRINT(4, "BMediaRosterEx::GetAllOutputs() (by pointer) node %ld, port %ld\n", node->ID(), node->ControlPort()); - + result = B_OK; cookie = 0; list->MakeEmpty(); @@ -289,20 +313,23 @@ BMediaRosterEx::GetAllOutputs(BBufferProducer *node, List *list) return result; } + status_t -BMediaRosterEx::GetAllInputs(const media_node & node, List *list) +BMediaRosterEx::GetAllInputs(const media_node& node, List* list) { int32 cookie; status_t rv; status_t result; - PRINT(4, "BMediaRosterEx::GetAllInputs() node %ld, port %ld\n", node.node, node.port); + PRINT(4, "BMediaRosterEx::GetAllInputs() node %ld, port %ld\n", node.node, + node.port); if (!(node.kind & B_BUFFER_CONSUMER)) { - ERROR("BMediaRosterEx::GetAllInputs: node %ld is not a B_BUFFER_CONSUMER\n", node.node); + ERROR("BMediaRosterEx::GetAllInputs: node %ld is not a " + "B_BUFFER_CONSUMER\n", node.node); return B_MEDIA_BAD_NODE; } - + result = B_OK; cookie = 0; list->MakeEmpty(); @@ -310,7 +337,8 @@ BMediaRosterEx::GetAllInputs(const media_node & node, List *list) consumer_get_next_input_request request; consumer_get_next_input_reply reply; request.cookie = cookie; - rv = QueryPort(node.port, CONSUMER_GET_NEXT_INPUT, &request, sizeof(request), &reply, sizeof(reply)); + rv = QueryPort(node.port, CONSUMER_GET_NEXT_INPUT, &request, + sizeof(request), &reply, sizeof(reply)); if (rv != B_OK) break; cookie = reply.cookie; @@ -326,19 +354,21 @@ BMediaRosterEx::GetAllInputs(const media_node & node, List *list) consumer_dispose_input_cookie_request request; consumer_dispose_input_cookie_reply reply; - QueryPort(node.port, CONSUMER_DISPOSE_INPUT_COOKIE, &request, sizeof(request), &reply, sizeof(reply)); - + QueryPort(node.port, CONSUMER_DISPOSE_INPUT_COOKIE, &request, + sizeof(request), &reply, sizeof(reply)); + return result; } + status_t -BMediaRosterEx::GetAllInputs(BBufferConsumer *node, List *list) +BMediaRosterEx::GetAllInputs(BBufferConsumer* node, List* list) { int32 cookie; status_t result; - + PRINT(4, "BMediaRosterEx::GetAllInputs() (by pointer) node %ld, port %ld\n", node->ID(), node->ControlPort()); - + result = B_OK; cookie = 0; list->MakeEmpty(); @@ -359,28 +389,31 @@ BMediaRosterEx::GetAllInputs(BBufferConsumer *node, List *list) return result; } + status_t -BMediaRosterEx::PublishOutputs(const media_node & node, List *list) +BMediaRosterEx::PublishOutputs(const media_node& node, List* list) { server_publish_outputs_request request; server_publish_outputs_reply reply; - media_output *output; - media_output *outputs; + media_output* output; + media_output* outputs; int32 count; status_t rv; - + count = list->CountItems(); TRACE("PublishOutputs: publishing %ld\n", count); - + request.node = node; request.count = count; if (count > MAX_OUTPUTS) { void *start_addr; size_t size; size = ROUND_UP_TO_PAGE(count * sizeof(media_output)); - request.area = create_area("publish outputs", &start_addr, B_ANY_ADDRESS, size, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA); + request.area = create_area("publish outputs", &start_addr, + B_ANY_ADDRESS, size, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA); if (request.area < B_OK) { - ERROR("PublishOutputs: failed to create area, %#lx\n", request.area); + ERROR("PublishOutputs: failed to create area, %#lx\n", + request.area); return (status_t)request.area; } outputs = static_cast(start_addr); @@ -389,41 +422,44 @@ BMediaRosterEx::PublishOutputs(const media_node & node, List *list outputs = request.outputs; } TRACE("PublishOutputs: area %ld\n", request.area); - + int i; for (i = 0, list->Rewind(); list->GetNext(&output); i++) { ASSERT(i < count); outputs[i] = *output; } - - rv = QueryServer(SERVER_PUBLISH_OUTPUTS, &request, sizeof(request), &reply, sizeof(reply)); - + + rv = QueryServer(SERVER_PUBLISH_OUTPUTS, &request, sizeof(request), + &reply, sizeof(reply)); + if (request.area != -1) delete_area(request.area); - + return rv; } + status_t -BMediaRosterEx::PublishInputs(const media_node & node, List *list) +BMediaRosterEx::PublishInputs(const media_node& node, List* list) { server_publish_inputs_request request; server_publish_inputs_reply reply; - media_input *input; - media_input *inputs; + media_input* input; + media_input* inputs; int32 count; status_t rv; - + count = list->CountItems(); TRACE("PublishInputs: publishing %ld\n", count); - + request.node = node; request.count = count; if (count > MAX_INPUTS) { - void *start_addr; + void* start_addr; size_t size; size = ROUND_UP_TO_PAGE(count * sizeof(media_input)); - request.area = create_area("publish inputs", &start_addr, B_ANY_ADDRESS, size, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA); + request.area = create_area("publish inputs", &start_addr, + B_ANY_ADDRESS, size, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA); if (request.area < B_OK) { ERROR("PublishInputs: failed to create area, %#lx\n", request.area); return (status_t)request.area; @@ -434,295 +470,31 @@ BMediaRosterEx::PublishInputs(const media_node & node, List *list) inputs = request.inputs; } TRACE("PublishInputs: area %ld\n", request.area); - + int i; for (i = 0, list->Rewind(); list->GetNext(&input); i++) { ASSERT(i < count); inputs[i] = *input; } - - rv = QueryServer(SERVER_PUBLISH_INPUTS, &request, sizeof(request), &reply, sizeof(reply)); + + rv = QueryServer(SERVER_PUBLISH_INPUTS, &request, sizeof(request), + &reply, sizeof(reply)); if (request.area != -1) delete_area(request.area); - + return rv; } -/************************************************************* - * public BMediaRoster - *************************************************************/ -status_t -BMediaRoster::GetVideoInput(media_node * out_node) +BTimeSource* +BMediaRosterEx::MakeTimeSourceObject(media_node_id timesourceID) { - CALLED(); - return MediaRosterEx(this)->GetNode(VIDEO_INPUT, out_node); -} - - -status_t -BMediaRoster::GetAudioInput(media_node * out_node) -{ - CALLED(); - return MediaRosterEx(this)->GetNode(AUDIO_INPUT, out_node); -} - - -status_t -BMediaRoster::GetVideoOutput(media_node * out_node) -{ - CALLED(); - return MediaRosterEx(this)->GetNode(VIDEO_OUTPUT, out_node); -} - - -status_t -BMediaRoster::GetAudioMixer(media_node * out_node) -{ - CALLED(); - return MediaRosterEx(this)->GetNode(AUDIO_MIXER, out_node); -} - - -status_t -BMediaRoster::GetAudioOutput(media_node * out_node) -{ - CALLED(); - return MediaRosterEx(this)->GetNode(AUDIO_OUTPUT, out_node); -} - - -status_t -BMediaRoster::GetAudioOutput(media_node * out_node, - int32 * out_input_id, - BString * out_input_name) -{ - CALLED(); - return MediaRosterEx(this)->GetNode(AUDIO_OUTPUT_EX, out_node, out_input_id, out_input_name); -} - - -status_t -BMediaRoster::GetTimeSource(media_node * out_node) -{ - CALLED(); - status_t rv; - - // XXX need to do this in a nicer way. - - rv = MediaRosterEx(this)->GetNode(TIME_SOURCE, out_node); - if (rv != B_OK) - return rv; - - // We don't do reference counting for timesources, that's why we - // release the node immediately. - ReleaseNode(*out_node); - - // we need to remember to not use this node with server side reference counting - out_node->kind |= NODE_KIND_NO_REFCOUNTING; - - return B_OK; -} - - -status_t -BMediaRoster::SetVideoInput(const media_node & producer) -{ - CALLED(); - return MediaRosterEx(this)->SetNode(VIDEO_INPUT, &producer); -} - - -status_t -BMediaRoster::SetVideoInput(const dormant_node_info & producer) -{ - CALLED(); - return MediaRosterEx(this)->SetNode(VIDEO_INPUT, NULL, &producer); -} - - -status_t -BMediaRoster::SetAudioInput(const media_node & producer) -{ - CALLED(); - return MediaRosterEx(this)->SetNode(AUDIO_INPUT, &producer); -} - - -status_t -BMediaRoster::SetAudioInput(const dormant_node_info & producer) -{ - CALLED(); - return MediaRosterEx(this)->SetNode(AUDIO_INPUT, NULL, &producer); -} - - -status_t -BMediaRoster::SetVideoOutput(const media_node & consumer) -{ - CALLED(); - return MediaRosterEx(this)->SetNode(VIDEO_OUTPUT, &consumer); -} - - -status_t -BMediaRoster::SetVideoOutput(const dormant_node_info & consumer) -{ - CALLED(); - return MediaRosterEx(this)->SetNode(VIDEO_OUTPUT, NULL, &consumer); -} - - -status_t -BMediaRoster::SetAudioOutput(const media_node & consumer) -{ - CALLED(); - return MediaRosterEx(this)->SetNode(AUDIO_OUTPUT, &consumer); -} - - -status_t -BMediaRoster::SetAudioOutput(const media_input & input_to_output) -{ - CALLED(); - return MediaRosterEx(this)->SetNode(AUDIO_OUTPUT, NULL, NULL, &input_to_output); -} - - -status_t -BMediaRoster::SetAudioOutput(const dormant_node_info & consumer) -{ - CALLED(); - return MediaRosterEx(this)->SetNode(AUDIO_OUTPUT, NULL, &consumer); -} - - -status_t -BMediaRoster::GetNodeFor(media_node_id node, - media_node * clone) -{ - CALLED(); - if (clone == NULL) - return B_BAD_VALUE; - if (IS_INVALID_NODEID(node)) - return B_MEDIA_BAD_NODE; - - server_get_node_for_request request; - server_get_node_for_reply reply; - status_t rv; - - request.nodeid = node; - request.team = team; - - rv = QueryServer(SERVER_GET_NODE_FOR, &request, sizeof(request), &reply, sizeof(reply)); - if (rv != B_OK) - return rv; - - *clone = reply.clone; - return B_OK; -} - - -status_t -BMediaRoster::GetSystemTimeSource(media_node * clone) -{ - CALLED(); - status_t rv; - - // XXX need to do this in a nicer way. - - rv = MediaRosterEx(this)->GetNode(SYSTEM_TIME_SOURCE, clone); - if (rv != B_OK) - return rv; - - // We don't do reference counting for timesources, that's why we - // release the node immediately. - ReleaseNode(*clone); - - // we need to remember to not use this node with server side reference counting - clone->kind |= NODE_KIND_NO_REFCOUNTING; - - return B_OK; -} - - -status_t -BMediaRoster::ReleaseNode(const media_node & node) -{ - CALLED(); - if (IS_INVALID_NODE(node)) - return B_MEDIA_BAD_NODE; - - if (node.kind & NODE_KIND_NO_REFCOUNTING) { - printf("BMediaRoster::ReleaseNode, trying to release reference counting disabled timesource, node %ld, port %ld, team %ld\n", node.node, node.port, team); - return B_OK; - } - - server_release_node_request request; - server_release_node_reply reply; - status_t rv; - - request.node = node; - request.team = team; - - TRACE("BMediaRoster::ReleaseNode, node %ld, port %ld, team %ld\n", node.node, node.port, team); - - rv = QueryServer(SERVER_RELEASE_NODE, &request, sizeof(request), &reply, sizeof(reply)); - if (rv != B_OK) { - ERROR("BMediaRoster::ReleaseNode FAILED, node %ld, port %ld, team %ld!\n", node.node, node.port, team); - } - return rv; -} - -BTimeSource * -BMediaRoster::MakeTimeSourceFor(const media_node & for_node) -{ - // MakeTimeSourceFor() returns a BTimeSource object - // corresponding to the specified node's time source. - - CALLED(); - - if (IS_SYSTEM_TIMESOURCE(for_node)) { - // special handling for the system time source - TRACE("BMediaRoster::MakeTimeSourceFor, asked for system time source\n"); - return MediaRosterEx(this)->MakeTimeSourceObject(NODE_SYSTEM_TIMESOURCE_ID); - } - - if (IS_INVALID_NODE(for_node)) { - ERROR("BMediaRoster::MakeTimeSourceFor: for_node invalid, node %ld, port %ld, kinds 0x%lx\n", for_node.node, for_node.port, for_node.kind); - return NULL; - } - - TRACE("BMediaRoster::MakeTimeSourceFor: node %ld enter\n", for_node.node); - - node_get_timesource_request request; - node_get_timesource_reply reply; - BTimeSource *source; - status_t rv; - - // ask the node to get it's current timesource id - rv = QueryPort(for_node.port, NODE_GET_TIMESOURCE, &request, sizeof(request), &reply, sizeof(reply)); - if (rv != B_OK) { - ERROR("BMediaRoster::MakeTimeSourceFor: request failed\n"); - return NULL; - } - - source = MediaRosterEx(this)->MakeTimeSourceObject(reply.timesource_id); - - TRACE("BMediaRoster::MakeTimeSourceFor: node %ld leave\n", for_node.node); - - return source; -} - -BTimeSource * -BMediaRosterEx::MakeTimeSourceObject(media_node_id timesource_id) -{ - BTimeSource *source; + BTimeSource* source; media_node clone; status_t rv; - rv = GetNodeFor(timesource_id, &clone); + rv = GetNodeFor(timesourceID, &clone); if (rv != B_OK) { ERROR("BMediaRosterEx::MakeTimeSourceObject: GetNodeFor failed\n"); return NULL; @@ -734,32 +506,302 @@ BMediaRosterEx::MakeTimeSourceObject(media_node_id timesource_id) return NULL; } - // XXX release? + // TODO: release? ReleaseNode(clone); return source; } -status_t -BMediaRoster::Connect(const media_source & from, - const media_destination & to, - media_format * io_format, - media_output * out_output, - media_input * out_input) +// #pragma mark - public BMediaRoster + + +status_t +BMediaRoster::GetVideoInput(media_node* _node) { - return BMediaRoster::Connect(from, to, io_format, out_output, out_input, 0); + CALLED(); + return MediaRosterEx(this)->GetNode(VIDEO_INPUT, _node); } -status_t -BMediaRoster::Connect(const media_source & from, - const media_destination & to, - media_format * io_format, - media_output * out_output, - media_input * out_input, - uint32 in_flags, - void * _reserved) +status_t +BMediaRoster::GetAudioInput(media_node* _node) +{ + CALLED(); + return MediaRosterEx(this)->GetNode(AUDIO_INPUT, _node); +} + + +status_t +BMediaRoster::GetVideoOutput(media_node* _node) +{ + CALLED(); + return MediaRosterEx(this)->GetNode(VIDEO_OUTPUT, _node); +} + + +status_t +BMediaRoster::GetAudioMixer(media_node* _node) +{ + CALLED(); + return MediaRosterEx(this)->GetNode(AUDIO_MIXER, _node); +} + + +status_t +BMediaRoster::GetAudioOutput(media_node* _node) +{ + CALLED(); + return MediaRosterEx(this)->GetNode(AUDIO_OUTPUT, _node); +} + + +status_t +BMediaRoster::GetAudioOutput(media_node* _node, int32* _inputID, + BString* _inputName) +{ + CALLED(); + return MediaRosterEx(this)->GetNode(AUDIO_OUTPUT_EX, _node, _inputID, + _inputName); +} + + +status_t +BMediaRoster::GetTimeSource(media_node* _node) +{ + CALLED(); + status_t rv; + + // TODO: need to do this in a nicer way. + + rv = MediaRosterEx(this)->GetNode(TIME_SOURCE, _node); + if (rv != B_OK) + return rv; + + // We don't do reference counting for timesources, that's why we + // release the node immediately. + ReleaseNode(*_node); + + // we need to remember to not use this node with server side reference counting + _node->kind |= NODE_KIND_NO_REFCOUNTING; + return B_OK; +} + + +status_t +BMediaRoster::SetVideoInput(const media_node& producer) +{ + CALLED(); + return MediaRosterEx(this)->SetNode(VIDEO_INPUT, &producer); +} + + +status_t +BMediaRoster::SetVideoInput(const dormant_node_info& producer) +{ + CALLED(); + return MediaRosterEx(this)->SetNode(VIDEO_INPUT, NULL, &producer); +} + + +status_t +BMediaRoster::SetAudioInput(const media_node& producer) +{ + CALLED(); + return MediaRosterEx(this)->SetNode(AUDIO_INPUT, &producer); +} + + +status_t +BMediaRoster::SetAudioInput(const dormant_node_info& producer) +{ + CALLED(); + return MediaRosterEx(this)->SetNode(AUDIO_INPUT, NULL, &producer); +} + + +status_t +BMediaRoster::SetVideoOutput(const media_node& consumer) +{ + CALLED(); + return MediaRosterEx(this)->SetNode(VIDEO_OUTPUT, &consumer); +} + + +status_t +BMediaRoster::SetVideoOutput(const dormant_node_info& consumer) +{ + CALLED(); + return MediaRosterEx(this)->SetNode(VIDEO_OUTPUT, NULL, &consumer); +} + + +status_t +BMediaRoster::SetAudioOutput(const media_node& consumer) +{ + CALLED(); + return MediaRosterEx(this)->SetNode(AUDIO_OUTPUT, &consumer); +} + + +status_t +BMediaRoster::SetAudioOutput(const media_input& input) +{ + CALLED(); + return MediaRosterEx(this)->SetNode(AUDIO_OUTPUT, NULL, NULL, &input); +} + + +status_t +BMediaRoster::SetAudioOutput(const dormant_node_info& consumer) +{ + CALLED(); + return MediaRosterEx(this)->SetNode(AUDIO_OUTPUT, NULL, &consumer); +} + + +status_t +BMediaRoster::GetNodeFor(media_node_id node, media_node* clone) +{ + CALLED(); + if (clone == NULL) + return B_BAD_VALUE; + if (IS_INVALID_NODEID(node)) + return B_MEDIA_BAD_NODE; + + server_get_node_for_request request; + server_get_node_for_reply reply; + status_t rv; + + request.nodeid = node; + request.team = team; + + rv = QueryServer(SERVER_GET_NODE_FOR, &request, sizeof(request), &reply, + sizeof(reply)); + if (rv != B_OK) + return rv; + + *clone = reply.clone; + return B_OK; +} + + +status_t +BMediaRoster::GetSystemTimeSource(media_node* clone) +{ + CALLED(); + status_t rv; + + // TODO: need to do this in a nicer way. + + rv = MediaRosterEx(this)->GetNode(SYSTEM_TIME_SOURCE, clone); + if (rv != B_OK) + return rv; + + // We don't do reference counting for timesources, that's why we + // release the node immediately. + ReleaseNode(*clone); + + // we need to remember to not use this node with server side reference + // counting + clone->kind |= NODE_KIND_NO_REFCOUNTING; + + return B_OK; +} + + +status_t +BMediaRoster::ReleaseNode(const media_node& node) +{ + CALLED(); + if (IS_INVALID_NODE(node)) + return B_MEDIA_BAD_NODE; + + if (node.kind & NODE_KIND_NO_REFCOUNTING) { + printf("BMediaRoster::ReleaseNode, trying to release reference " + "counting disabled timesource, node %ld, port %ld, team %ld\n", + node.node, node.port, team); + return B_OK; + } + + server_release_node_request request; + server_release_node_reply reply; + status_t rv; + + request.node = node; + request.team = team; + + TRACE("BMediaRoster::ReleaseNode, node %ld, port %ld, team %ld\n", + node.node, node.port, team); + + rv = QueryServer(SERVER_RELEASE_NODE, &request, sizeof(request), &reply, + sizeof(reply)); + if (rv != B_OK) { + ERROR("BMediaRoster::ReleaseNode FAILED, node %ld, port %ld, team " + "%ld!\n", node.node, node.port, team); + } + return rv; +} + + +BTimeSource* +BMediaRoster::MakeTimeSourceFor(const media_node& forNode) +{ + // MakeTimeSourceFor() returns a BTimeSource object + // corresponding to the specified node's time source. + + CALLED(); + + if (IS_SYSTEM_TIMESOURCE(forNode)) { + // special handling for the system time source + TRACE("BMediaRoster::MakeTimeSourceFor, asked for system time " + "source\n"); + return MediaRosterEx(this)->MakeTimeSourceObject( + NODE_SYSTEM_TIMESOURCE_ID); + } + + if (IS_INVALID_NODE(forNode)) { + ERROR("BMediaRoster::MakeTimeSourceFor: for_node invalid, node %ld, " + "port %ld, kinds 0x%lx\n", forNode.node, forNode.port, + forNode.kind); + return NULL; + } + + TRACE("BMediaRoster::MakeTimeSourceFor: node %ld enter\n", forNode.node); + + node_get_timesource_request request; + node_get_timesource_reply reply; + BTimeSource *source; + status_t rv; + + // ask the node to get it's current timesource id + rv = QueryPort(forNode.port, NODE_GET_TIMESOURCE, &request, + sizeof(request), &reply, sizeof(reply)); + if (rv != B_OK) { + ERROR("BMediaRoster::MakeTimeSourceFor: request failed\n"); + return NULL; + } + + source = MediaRosterEx(this)->MakeTimeSourceObject(reply.timesource_id); + + TRACE("BMediaRoster::MakeTimeSourceFor: node %ld leave\n", forNode.node); + + return source; +} + + +status_t +BMediaRoster::Connect(const media_source& from, const media_destination& to, + media_format* _format, media_output* _output, media_input* _input) +{ + return BMediaRoster::Connect(from, to, _format, _output, _input, 0); +} + + +status_t +BMediaRoster::Connect(const media_source& from, const media_destination& to, + media_format* io_format, media_output* out_output, media_input* out_input, + uint32 in_flags, void* _reserved) { CALLED(); if (io_format == NULL || out_output == NULL || out_input == NULL) @@ -776,57 +818,67 @@ BMediaRoster::Connect(const media_source & from, status_t rv; // find the output and input nodes - // XXX isn't there a easier way? + // TODO: isn't there a easier way? media_node sourcenode; media_node destnode; rv = GetNodeFor(NodeIDFor(from.port), &sourcenode); if (rv != B_OK) { - ERROR("BMediaRoster::Connect: Can't find source node for port %ld\n", from.port); + ERROR("BMediaRoster::Connect: Can't find source node for port %ld\n", + from.port); return B_MEDIA_BAD_SOURCE; } ReleaseNode(sourcenode); rv = GetNodeFor(NodeIDFor(to.port), &destnode); if (rv != B_OK) { - ERROR("BMediaRoster::Connect: Can't find destination node for port %ld\n", to.port); + ERROR("BMediaRoster::Connect: Can't find destination node for port " + "%ld\n", to.port); return B_MEDIA_BAD_DESTINATION; } ReleaseNode(destnode); - + if (!(sourcenode.kind & B_BUFFER_PRODUCER)) { - ERROR("BMediaRoster::Connect: source node %ld is not a B_BUFFER_PRODUCER\n", sourcenode.node); + ERROR("BMediaRoster::Connect: source node %ld is not a " + "B_BUFFER_PRODUCER\n", sourcenode.node); return B_MEDIA_BAD_SOURCE; } if (!(destnode.kind & B_BUFFER_CONSUMER)) { - ERROR("BMediaRoster::Connect: destination node %ld is not a B_BUFFER_CONSUMER\n", destnode.node); + ERROR("BMediaRoster::Connect: destination node %ld is not a " + "B_BUFFER_CONSUMER\n", destnode.node); return B_MEDIA_BAD_DESTINATION; } producer_format_proposal_request request1; producer_format_proposal_reply reply1; - - PRINT_FORMAT("BMediaRoster::Connect calling BBufferProducer::FormatProposal with format ", *io_format); - + + PRINT_FORMAT("BMediaRoster::Connect calling " + "BBufferProducer::FormatProposal with format ", *io_format); + // BBufferProducer::FormatProposal request1.output = from; request1.format = *io_format; - rv = QueryPort(from.port, PRODUCER_FORMAT_PROPOSAL, &request1, sizeof(request1), &reply1, sizeof(reply1)); + rv = QueryPort(from.port, PRODUCER_FORMAT_PROPOSAL, &request1, + sizeof(request1), &reply1, sizeof(reply1)); if (rv != B_OK) { - ERROR("BMediaRoster::Connect: aborted after BBufferProducer::FormatProposal, status = %#lx\n",rv); + ERROR("BMediaRoster::Connect: aborted after " + "BBufferProducer::FormatProposal, status = %#lx\n",rv); return rv; } // reply1.format now contains the format proposed by the producer consumer_accept_format_request request2; consumer_accept_format_reply reply2; - - PRINT_FORMAT("BMediaRoster::Connect calling BBufferConsumer::AcceptFormat with format ", reply1.format); + + PRINT_FORMAT("BMediaRoster::Connect calling " + "BBufferConsumer::AcceptFormat with format ", reply1.format); // BBufferConsumer::AcceptFormat request2.dest = to; request2.format = reply1.format; - rv = QueryPort(to.port, CONSUMER_ACCEPT_FORMAT, &request2, sizeof(request2), &reply2, sizeof(reply2)); + rv = QueryPort(to.port, CONSUMER_ACCEPT_FORMAT, &request2, + sizeof(request2), &reply2, sizeof(reply2)); if (rv != B_OK) { - ERROR("BMediaRoster::Connect: aborted after BBufferConsumer::AcceptFormat, status = %#lx\n",rv); + ERROR("BMediaRoster::Connect: aborted after " + "BBufferConsumer::AcceptFormat, status = %#lx\n",rv); return rv; } // reply2.format now contains the format accepted by the consumer @@ -835,60 +887,72 @@ BMediaRoster::Connect(const media_source & from, producer_prepare_to_connect_request request3; producer_prepare_to_connect_reply reply3; - PRINT_FORMAT("BMediaRoster::Connect calling BBufferProducer::PrepareToConnect with format", reply2.format); + PRINT_FORMAT("BMediaRoster::Connect calling " + "BBufferProducer::PrepareToConnect with format", reply2.format); request3.source = from; request3.destination = to; request3.format = reply2.format; - strcpy(request3.name, "XXX some default name"); // XXX fix this - rv = QueryPort(from.port, PRODUCER_PREPARE_TO_CONNECT, &request3, sizeof(request3), &reply3, sizeof(reply3)); + strcpy(request3.name, "XXX some default name"); // TODO: fix this + rv = QueryPort(from.port, PRODUCER_PREPARE_TO_CONNECT, &request3, + sizeof(request3), &reply3, sizeof(reply3)); if (rv != B_OK) { - ERROR("BMediaRoster::Connect: aborted after BBufferProducer::PrepareToConnect, status = %#lx\n",rv); + ERROR("BMediaRoster::Connect: aborted after " + "BBufferProducer::PrepareToConnect, status = %#lx\n",rv); return rv; } // reply3.format is still our pretty media format // reply3.out_source the real source to be used for the connection - // reply3.name the name BBufferConsumer::Connected will see in the outInput->name argument - + // reply3.name the name BBufferConsumer::Connected will see in the + // outInput->name argument + // BBufferConsumer::Connected consumer_connected_request request4; consumer_connected_reply reply4; status_t con_status; - PRINT_FORMAT("BMediaRoster::Connect calling BBufferConsumer::Connected with format ", reply3.format); - + PRINT_FORMAT("BMediaRoster::Connect calling BBufferConsumer::Connected() " + "with format ", reply3.format); + request4.input.node = destnode; request4.input.source = reply3.out_source; request4.input.destination = to; request4.input.format = reply3.format; strcpy(request4.input.name, reply3.name); - - con_status = QueryPort(to.port, CONSUMER_CONNECTED, &request4, sizeof(request4), &reply4, sizeof(reply4)); + + con_status = QueryPort(to.port, CONSUMER_CONNECTED, &request4, + sizeof(request4), &reply4, sizeof(reply4)); if (con_status != B_OK) { - ERROR("BMediaRoster::Connect: aborting after BBufferConsumer::Connected, status = %#lx\n",con_status); + ERROR("BMediaRoster::Connect: aborting after " + "BBufferConsumer::Connected, status = %#lx\n",con_status); // we do NOT return here! } - // con_status contains the status code to be supplied to BBufferProducer::Connect's status argument - // reply4.input contains the media_input that describes the connection from the consumer point of view + // con_status contains the status code to be supplied to + // BBufferProducer::Connect's status argument + // reply4.input contains the media_input that describes the connection + // from the consumer point of view // BBufferProducer::Connect producer_connect_request request5; producer_connect_reply reply5; - PRINT_FORMAT("BMediaRoster::Connect calling BBufferProducer::Connect with format ", reply4.input.format); - + PRINT_FORMAT("BMediaRoster::Connect calling BBufferProducer::Connect with " + "format ", reply4.input.format); + request5.error = con_status; request5.source = reply3.out_source; request5.destination = reply4.input.destination; request5.format = reply4.input.format; strcpy(request5.name, reply4.input.name); - rv = QueryPort(reply4.input.source.port, PRODUCER_CONNECT, &request5, sizeof(request5), &reply5, sizeof(reply5)); + rv = QueryPort(reply4.input.source.port, PRODUCER_CONNECT, &request5, + sizeof(request5), &reply5, sizeof(reply5)); if (con_status != B_OK) { ERROR("BMediaRoster::Connect: aborted\n"); return con_status; } if (rv != B_OK) { - ERROR("BMediaRoster::Connect: aborted after BBufferProducer::Connect, status = %#lx\n",rv); + ERROR("BMediaRoster::Connect: aborted after BBufferProducer::Connect()" + ", status = %#lx\n",rv); return rv; } // reply5.name contains the name assigned to the connection by the producer @@ -908,33 +972,32 @@ BMediaRoster::Connect(const media_source & from, PRINT_INPUT(" input", *out_input); PRINT_OUTPUT(" output", *out_output); - // XXX register connection with server - // XXX we should just send a notification, instead of republishing all endpoints + // TODO: register connection with server + // TODO: we should just send a notification, instead of republishing all + // endpoints List outlist; List inlist; - if (B_OK == MediaRosterEx(this)->GetAllOutputs(out_output->node , &outlist)) + if (MediaRosterEx(this)->GetAllOutputs(out_output->node , &outlist) == B_OK) MediaRosterEx(this)->PublishOutputs(out_output->node , &outlist); - if (B_OK == MediaRosterEx(this)->GetAllInputs(out_input->node , &inlist)) + if (MediaRosterEx(this)->GetAllInputs(out_input->node , &inlist) == B_OK) MediaRosterEx(this)->PublishInputs(out_input->node, &inlist); - - // XXX if (mute) BBufferProducer::EnableOutput(false) + // TODO: if (mute) BBufferProducer::EnableOutput(false) if (in_flags & B_CONNECT_MUTED) { } - // send a notification - BPrivate::media::notifications::ConnectionMade(*out_input, *out_output, *io_format); + BPrivate::media::notifications::ConnectionMade(*out_input, *out_output, + *io_format); return B_OK; }; -status_t +status_t BMediaRoster::Disconnect(media_node_id source_nodeid, - const media_source & source, - media_node_id destination_nodeid, - const media_destination & destination) + const media_source& source, media_node_id destination_nodeid, + const media_destination& destination) { CALLED(); if (IS_INVALID_NODEID(source_nodeid)) { @@ -960,52 +1023,58 @@ BMediaRoster::Disconnect(media_node_id source_nodeid, consumer_disconnected_reply reply1; status_t rv1, rv2; - // XXX we should ask the server if this connection really exists + // TODO: we should ask the server if this connection really exists request1.source = source; request1.destination = destination; request2.source = source; request2.destination = destination; - rv1 = QueryPort(source.port, PRODUCER_DISCONNECT, &request1, sizeof(request1), &reply1, sizeof(reply1)); - rv2 = QueryPort(destination.port, CONSUMER_DISCONNECTED, &request2, sizeof(request2), &reply2, sizeof(reply2)); + rv1 = QueryPort(source.port, PRODUCER_DISCONNECT, &request1, + sizeof(request1), &reply1, sizeof(reply1)); + rv2 = QueryPort(destination.port, CONSUMER_DISCONNECTED, &request2, + sizeof(request2), &reply2, sizeof(reply2)); - // XXX unregister connection with server - // XXX we should just send a notification, instead of republishing all endpoints + // TODO: unregister connection with server + // TODO: we should just send a notification, instead of republishing all + // endpoints List outlist; List inlist; media_node sourcenode; media_node destnode; - if (B_OK == GetNodeFor(source_nodeid, &sourcenode)) { + if (GetNodeFor(source_nodeid, &sourcenode) == B_OK) { if (!(sourcenode.kind & B_BUFFER_PRODUCER)) { - ERROR("BMediaRoster::Disconnect: source_nodeid %ld is not a B_BUFFER_PRODUCER\n", source_nodeid); + ERROR("BMediaRoster::Disconnect: source_nodeid %ld is not a " + "B_BUFFER_PRODUCER\n", source_nodeid); } - if (B_OK == MediaRosterEx(this)->GetAllOutputs(sourcenode , &outlist)) + if (MediaRosterEx(this)->GetAllOutputs(sourcenode , &outlist) == B_OK) MediaRosterEx(this)->PublishOutputs(sourcenode , &outlist); ReleaseNode(sourcenode); } else { ERROR("BMediaRoster::Disconnect: GetNodeFor source_nodeid %ld failed\n", source_nodeid); } - if (B_OK == GetNodeFor(destination_nodeid, &destnode)) { + if (GetNodeFor(destination_nodeid, &destnode) == B_OK) { if (!(destnode.kind & B_BUFFER_CONSUMER)) { - ERROR("BMediaRoster::Disconnect: destination_nodeid %ld is not a B_BUFFER_CONSUMER\n", destination_nodeid); + ERROR("BMediaRoster::Disconnect: destination_nodeid %ld is not a " + "B_BUFFER_CONSUMER\n", destination_nodeid); } - if (B_OK == MediaRosterEx(this)->GetAllInputs(destnode , &inlist)) + if (MediaRosterEx(this)->GetAllInputs(destnode , &inlist) == B_OK) MediaRosterEx(this)->PublishInputs(destnode, &inlist); ReleaseNode(destnode); } else { - ERROR("BMediaRoster::Disconnect: GetNodeFor destination_nodeid %ld failed\n", destination_nodeid); + ERROR("BMediaRoster::Disconnect: GetNodeFor destination_nodeid %ld " + "failed\n", destination_nodeid); } - // send a notification BPrivate::media::notifications::ConnectionBroken(source, destination); - return (rv1 != B_OK || rv2 != B_OK) ? B_ERROR : B_OK; + return rv1 != B_OK || rv2 != B_OK ? B_ERROR : B_OK; } -status_t -BMediaRoster::Disconnect(const media_output &output, const media_input &input) + +status_t +BMediaRoster::Disconnect(const media_output& output, const media_input& input) { if (IS_INVALID_NODEID(output.node.node)) { printf("BMediaRoster::Disconnect: output.node.node %ld invalid\n", @@ -1018,106 +1087,109 @@ BMediaRoster::Disconnect(const media_output &output, const media_input &input) return B_MEDIA_BAD_DESTINATION; } if (!(output.node.kind & B_BUFFER_PRODUCER)) { - printf("BMediaRoster::Disconnect: output.node.kind 0x%lx is no B_BUFFER_PRODUCER\n", - output.node.kind); + printf("BMediaRoster::Disconnect: output.node.kind 0x%lx is no " + "B_BUFFER_PRODUCER\n", output.node.kind); return B_MEDIA_BAD_SOURCE; } if (!(input.node.kind & B_BUFFER_CONSUMER)) { - printf("BMediaRoster::Disconnect: input.node.kind 0x%lx is no B_BUFFER_PRODUCER\n", - input.node.kind); + printf("BMediaRoster::Disconnect: input.node.kind 0x%lx is no " + "B_BUFFER_PRODUCER\n", input.node.kind); return B_MEDIA_BAD_DESTINATION; } if (input.source.port != output.source.port) { - printf("BMediaRoster::Disconnect: input.source.port %ld doesn't match output.source.port %ld\n", - input.source.port, output.source.port); + printf("BMediaRoster::Disconnect: input.source.port %ld doesn't match " + "output.source.port %ld\n", input.source.port, output.source.port); return B_MEDIA_BAD_SOURCE; } if (input.source.id != output.source.id) { - printf("BMediaRoster::Disconnect: input.source.id %ld doesn't match output.source.id %ld\n", - input.source.id, output.source.id); + printf("BMediaRoster::Disconnect: input.source.id %ld doesn't match " + "output.source.id %ld\n", input.source.id, output.source.id); return B_MEDIA_BAD_SOURCE; } if (input.destination.port != output.destination.port) { - printf("BMediaRoster::Disconnect: input.destination.port %ld doesn't match output.destination.port %ld\n", - input.destination.port, output.destination.port); + printf("BMediaRoster::Disconnect: input.destination.port %ld doesn't " + "match output.destination.port %ld\n", input.destination.port, + output.destination.port); return B_MEDIA_BAD_DESTINATION; } if (input.destination.id != output.destination.id) { - printf("BMediaRoster::Disconnect: input.destination.id %ld doesn't match output.destination.id %ld\n", - input.destination.id, output.destination.id); + printf("BMediaRoster::Disconnect: input.destination.id %ld doesn't " + "match output.destination.id %ld\n", input.destination.id, + output.destination.id); return B_MEDIA_BAD_DESTINATION; } - return Disconnect(output.node.node, output.source, input.node.node, input.destination); + + return Disconnect(output.node.node, output.source, input.node.node, + input.destination); } -status_t -BMediaRoster::StartNode(const media_node & node, - bigtime_t at_performance_time) +status_t +BMediaRoster::StartNode(const media_node& node, bigtime_t atPerformanceTime) { CALLED(); if (node.node <= 0) return B_MEDIA_BAD_NODE; - - TRACE("BMediaRoster::StartNode, node %ld, at perf %Ld\n", node.node, at_performance_time); + + TRACE("BMediaRoster::StartNode, node %ld, at perf %Ld\n", node.node, + atPerformanceTime); node_start_command command; - command.performance_time = at_performance_time; - + command.performance_time = atPerformanceTime; + return SendToPort(node.port, NODE_START, &command, sizeof(command)); } -status_t -BMediaRoster::StopNode(const media_node & node, - bigtime_t at_performance_time, - bool immediate) +status_t +BMediaRoster::StopNode(const media_node& node, bigtime_t atPerformanceTime, + bool immediate) { CALLED(); if (IS_INVALID_NODE(node)) return B_MEDIA_BAD_NODE; - TRACE("BMediaRoster::StopNode, node %ld, at perf %Ld %s\n", node.node, at_performance_time, immediate ? "NOW" : ""); + TRACE("BMediaRoster::StopNode, node %ld, at perf %Ld %s\n", node.node, + atPerformanceTime, immediate ? "NOW" : ""); node_stop_command command; - command.performance_time = at_performance_time; + command.performance_time = atPerformanceTime; command.immediate = immediate; - + return SendToPort(node.port, NODE_STOP, &command, sizeof(command)); } - -status_t -BMediaRoster::SeekNode(const media_node & node, - bigtime_t to_media_time, - bigtime_t at_performance_time) + +status_t +BMediaRoster::SeekNode(const media_node& node, bigtime_t toMediaTime, + bigtime_t atPerformanceTime) { CALLED(); if (IS_INVALID_NODE(node)) return B_MEDIA_BAD_NODE; - TRACE("BMediaRoster::SeekNode, node %ld, at perf %Ld, to perf %Ld\n", node.node, at_performance_time, to_media_time); + TRACE("BMediaRoster::SeekNode, node %ld, at perf %Ld, to perf %Ld\n", + node.node, atPerformanceTime, toMediaTime); node_seek_command command; - command.media_time = to_media_time; - command.performance_time = at_performance_time; - + command.media_time = toMediaTime; + command.performance_time = atPerformanceTime; + return SendToPort(node.port, NODE_SEEK, &command, sizeof(command)); } -status_t -BMediaRoster::StartTimeSource(const media_node & node, - bigtime_t at_real_time) +status_t +BMediaRoster::StartTimeSource(const media_node& node, bigtime_t atRealTime) { CALLED(); if (IS_SYSTEM_TIMESOURCE(node)) { - // XXX debug this + // TODO: debug this //ERROR("BMediaRoster::StartTimeSource node %ld is system timesource\n", node.node); return B_OK; } // if (IS_SHADOW_TIMESOURCE(node)) { -// // XXX debug this +// // TODO: debug this // ERROR("BMediaRoster::StartTimeSource node %ld is shadow timesource\n", node.node); // return B_OK; // } @@ -1126,33 +1198,34 @@ BMediaRoster::StartTimeSource(const media_node & node, return B_MEDIA_BAD_NODE; } if ((node.kind & B_TIME_SOURCE) == 0) { - ERROR("BMediaRoster::StartTimeSource node %ld is no timesource\n", node.node); + ERROR("BMediaRoster::StartTimeSource node %ld is no timesource\n", + node.node); return B_MEDIA_BAD_NODE; } - TRACE("BMediaRoster::StartTimeSource, node %ld, at real %Ld\n", node.node, at_real_time); - + TRACE("BMediaRoster::StartTimeSource, node %ld, at real %Ld\n", node.node, + at_real_time); + BTimeSource::time_source_op_info msg; msg.op = BTimeSource::B_TIMESOURCE_START; - msg.real_time = at_real_time; + msg.real_time = atRealTime; return write_port(node.port, TIMESOURCE_OP, &msg, sizeof(msg)); } - -status_t -BMediaRoster::StopTimeSource(const media_node & node, - bigtime_t at_real_time, - bool immediate) + +status_t +BMediaRoster::StopTimeSource(const media_node& node, bigtime_t atRealTime, + bool immediate) { CALLED(); if (IS_SYSTEM_TIMESOURCE(node)) { - // XXX debug this + // TODO: debug this //ERROR("BMediaRoster::StopTimeSource node %ld is system timesource\n", node.node); return B_OK; } // if (IS_SHADOW_TIMESOURCE(node)) { -// // XXX debug this +// // TODO: debug this // ERROR("BMediaRoster::StopTimeSource node %ld is shadow timesource\n", node.node); // return B_OK; // } @@ -1161,35 +1234,37 @@ BMediaRoster::StopTimeSource(const media_node & node, return B_MEDIA_BAD_NODE; } if ((node.kind & B_TIME_SOURCE) == 0) { - ERROR("BMediaRoster::StopTimeSource node %ld is no timesource\n", node.node); + ERROR("BMediaRoster::StopTimeSource node %ld is no timesource\n", + node.node); return B_MEDIA_BAD_NODE; } - TRACE("BMediaRoster::StopTimeSource, node %ld, at real %Ld %s\n", node.node, at_real_time, immediate ? "NOW" : ""); - + TRACE("BMediaRoster::StopTimeSource, node %ld, at real %Ld %s\n", + node.node, atRealTime, immediate ? "NOW" : ""); + BTimeSource::time_source_op_info msg; - msg.op = immediate ? BTimeSource::B_TIMESOURCE_STOP_IMMEDIATELY : BTimeSource::B_TIMESOURCE_STOP; - msg.real_time = at_real_time; + msg.op = immediate ? BTimeSource::B_TIMESOURCE_STOP_IMMEDIATELY + : BTimeSource::B_TIMESOURCE_STOP; + msg.real_time = atRealTime; return write_port(node.port, TIMESOURCE_OP, &msg, sizeof(msg)); } - -status_t -BMediaRoster::SeekTimeSource(const media_node & node, - bigtime_t to_performance_time, - bigtime_t at_real_time) + +status_t +BMediaRoster::SeekTimeSource(const media_node& node, + bigtime_t toPerformanceTime, bigtime_t atRealTime) { CALLED(); if (IS_SYSTEM_TIMESOURCE(node)) { - // XXX debug this + // TODO: debug this // ERROR("BMediaRoster::SeekTimeSource node %ld is system timesource\n", node.node); // you can't seek the system time source, but // returning B_ERROR would break StampTV return B_OK; } // if (IS_SHADOW_TIMESOURCE(node)) { -// // XXX debug this +// // TODO: debug this // ERROR("BMediaRoster::SeekTimeSource node %ld is shadow timesource\n", node.node); // return B_OK; // } @@ -1198,34 +1273,34 @@ BMediaRoster::SeekTimeSource(const media_node & node, return B_MEDIA_BAD_NODE; } if ((node.kind & B_TIME_SOURCE) == 0) { - ERROR("BMediaRoster::SeekTimeSource node %ld is no timesource\n", node.node); + ERROR("BMediaRoster::SeekTimeSource node %ld is no timesource\n", + node.node); return B_MEDIA_BAD_NODE; } - TRACE("BMediaRoster::SeekTimeSource, node %ld, at real %Ld, to perf %Ld\n", node.node, at_real_time, to_performance_time); + TRACE("BMediaRoster::SeekTimeSource, node %ld, at real %Ld, to perf %Ld\n", + node.node, atRealTime, toPerformanceTime); BTimeSource::time_source_op_info msg; msg.op = BTimeSource::B_TIMESOURCE_SEEK; - msg.real_time = at_real_time; - msg.performance_time = to_performance_time; + msg.real_time = atRealTime; + msg.performance_time = toPerformanceTime; return write_port(node.port, TIMESOURCE_OP, &msg, sizeof(msg)); } -status_t -BMediaRoster::SyncToNode(const media_node & node, - bigtime_t at_time, - bigtime_t timeout) +status_t +BMediaRoster::SyncToNode(const media_node& node, bigtime_t atTime, + bigtime_t timeout) { UNIMPLEMENTED(); return B_OK; } - -status_t -BMediaRoster::SetRunModeNode(const media_node & node, - BMediaNode::run_mode mode) + +status_t +BMediaRoster::SetRunModeNode(const media_node& node, BMediaNode::run_mode mode) { TRACE("BMediaRoster::SetRunModeNode, node %ld, mode %d\n", node.node, mode); if (IS_INVALID_NODE(node)) @@ -1233,13 +1308,13 @@ BMediaRoster::SetRunModeNode(const media_node & node, node_set_run_mode_command msg; msg.mode = mode; - + return write_port(node.port, NODE_SET_RUN_MODE, &msg, sizeof(msg)); } - -status_t -BMediaRoster::PrerollNode(const media_node & node) + +status_t +BMediaRoster::PrerollNode(const media_node& node) { CALLED(); if (IS_INVALID_NODE(node)) @@ -1250,40 +1325,38 @@ BMediaRoster::PrerollNode(const media_node & node) } -status_t -BMediaRoster::RollNode(const media_node & node, - bigtime_t startPerformance, - bigtime_t stopPerformance, - bigtime_t atMediaTime) +status_t +BMediaRoster::RollNode(const media_node& node, bigtime_t startPerformance, + bigtime_t stopPerformance, bigtime_t atMediaTime) { UNIMPLEMENTED(); return B_ERROR; } -status_t -BMediaRoster::SetProducerRunModeDelay(const media_node & node, - bigtime_t delay, - BMediaNode::run_mode mode) +status_t +BMediaRoster::SetProducerRunModeDelay(const media_node& node, + bigtime_t delay, BMediaNode::run_mode mode) { - TRACE("BMediaRoster::SetProducerRunModeDelay, node %ld, delay %Ld, mode %d\n", node.node, delay, mode); + TRACE("BMediaRoster::SetProducerRunModeDelay, node %ld, delay %Ld, " + "mode %d\n", node.node, delay, mode); if (IS_INVALID_NODE(node)) return B_MEDIA_BAD_NODE; if ((node.kind & B_BUFFER_PRODUCER) == 0) return B_MEDIA_BAD_NODE; - + producer_set_run_mode_delay_command command; command.mode = mode; command.delay = delay; - return SendToPort(node.port, PRODUCER_SET_RUN_MODE_DELAY, &command, sizeof(command)); + return SendToPort(node.port, PRODUCER_SET_RUN_MODE_DELAY, &command, + sizeof(command)); } -status_t -BMediaRoster::SetProducerRate(const media_node & producer, - int32 numer, - int32 denom) +status_t +BMediaRoster::SetProducerRate(const media_node& producer, int32 numer, + int32 denom) { CALLED(); if (IS_INVALID_NODE(producer)) @@ -1310,125 +1383,131 @@ BMediaRoster::SetProducerRate(const media_node & producer, } -/* Nodes will have available inputs/outputs as long as they are capable */ -/* of accepting more connections. The node may create an additional */ -/* output or input as the currently available is taken into usage. */ -status_t -BMediaRoster::GetLiveNodeInfo(const media_node & node, - live_node_info * out_live_info) +/*! Nodes will have available inputs/outputs as long as they are capable + of accepting more connections. The node may create an additional + output or input as the currently available is taken into usage. +*/ +status_t +BMediaRoster::GetLiveNodeInfo(const media_node& node, + live_node_info* out_live_info) { CALLED(); if (out_live_info == NULL) - return B_BAD_VALUE; + return B_BAD_VALUE; if (IS_INVALID_NODE(node)) return B_MEDIA_BAD_NODE; server_get_live_node_info_request request; server_get_live_node_info_reply reply; status_t rv; - + request.node = node; - - rv = QueryServer(SERVER_GET_LIVE_NODE_INFO, &request, sizeof(request), &reply, sizeof(reply)); + + rv = QueryServer(SERVER_GET_LIVE_NODE_INFO, &request, sizeof(request), + &reply, sizeof(reply)); if (rv != B_OK) return rv; - + *out_live_info = reply.live_info; return B_OK; } -status_t -BMediaRoster::GetLiveNodes(live_node_info * out_live_nodes, - int32 * io_total_count, - const media_format * has_input, - const media_format * has_output, - const char * name, - uint64 node_kinds) +status_t +BMediaRoster::GetLiveNodes(live_node_info* _liveNodes, int32* _totalCount, + const media_format* hasInput, const media_format* hasOutput, + const char* name, uint64 nodeKinds) { CALLED(); - if (out_live_nodes == NULL || io_total_count == NULL) - return B_BAD_VALUE; - if (*io_total_count <= 0) + if (_liveNodes == NULL || _totalCount == NULL || *_totalCount <= 0) return B_BAD_VALUE; - // XXX we also support the wildcard search as GetDormantNodes does. This needs to be documented + // TODO: we also support the wildcard search as GetDormantNodes does. + // This needs to be documented server_get_live_nodes_request request; server_get_live_nodes_reply reply; status_t rv; - - request.maxcount = *io_total_count; - request.has_input = (bool) has_input; - if (has_input) - request.inputformat = *has_input; // XXX we should not make a flat copy of media_format - request.has_output = (bool) has_output; - if (has_output) - request.outputformat = *has_output; // XXX we should not make a flat copy of media_format - request.has_name = (bool) name; - if (name) { + + request.maxcount = *_totalCount; + request.has_input = hasInput != NULL; + if (hasInput != NULL) { + // TODO: we should not make a flat copy of media_format + request.inputformat = *hasInput; + } + request.has_output = hasOutput != NULL; + if (hasOutput != NULL) { + // TODO: we should not make a flat copy of media_format + request.outputformat = *hasOutput; + } + request.has_name = name != NULL; + if (name != NULL) { int len = strlen(name); len = min_c(len, (int)sizeof(request.name) - 1); memcpy(request.name, name, len); request.name[len] = 0; } - request.require_kinds = node_kinds; + request.require_kinds = nodeKinds; - rv = QueryServer(SERVER_GET_LIVE_NODES, &request, sizeof(request), &reply, sizeof(reply)); + rv = QueryServer(SERVER_GET_LIVE_NODES, &request, sizeof(request), + &reply, sizeof(reply)); if (rv != B_OK) { ERROR("BMediaRoster::GetLiveNodes failed querying server\n"); - *io_total_count = 0; + *_totalCount = 0; return rv; } if (reply.count > MAX_LIVE_INFO) { - live_node_info *live_info; + live_node_info* liveInfo; area_id clone; - clone = clone_area("live_node_info clone", reinterpret_cast(&live_info), B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA, reply.area); + clone = clone_area("live_node_info clone", + reinterpret_cast(&liveInfo), B_ANY_ADDRESS, + B_READ_AREA | B_WRITE_AREA, reply.area); if (clone < B_OK) { - ERROR("BMediaRoster::GetLiveNodes failed to clone area, %#lx\n", clone); + ERROR("BMediaRoster::GetLiveNodes failed to clone area, %#lx\n", + clone); delete_area(reply.area); - *io_total_count = 0; + *_totalCount = 0; return B_ERROR; } for (int32 i = 0; i < reply.count; i++) { - out_live_nodes[i] = live_info[i]; + _liveNodes[i] = liveInfo[i]; } delete_area(clone); delete_area(reply.area); } else { for (int32 i = 0; i < reply.count; i++) { - out_live_nodes[i] = reply.live_info[i]; + _liveNodes[i] = reply.live_info[i]; } } - *io_total_count = reply.count; + *_totalCount = reply.count; return B_OK; } -status_t -BMediaRoster::GetFreeInputsFor(const media_node & node, - media_input * out_free_inputs, - int32 buf_num_inputs, - int32 * out_total_count, - media_type filter_type) +status_t +BMediaRoster::GetFreeInputsFor(const media_node& node, + media_input * out_free_inputs, int32 buf_num_inputs, + int32 * out_total_count, media_type filter_type) { CALLED(); if (IS_INVALID_NODE(node)) { - ERROR("BMediaRoster::GetFreeInputsFor: node %ld, port %ld invalid\n", node.node, node.port); + ERROR("BMediaRoster::GetFreeInputsFor: node %ld, port %ld invalid\n", + node.node, node.port); return B_MEDIA_BAD_NODE; } if ((node.kind & B_BUFFER_CONSUMER) == 0) { - ERROR("BMediaRoster::GetFreeInputsFor: node %ld, port %ld is not a consumer\n", node.node, node.port); + ERROR("BMediaRoster::GetFreeInputsFor: node %ld, port %ld is not a " + "consumer\n", node.node, node.port); return B_MEDIA_BAD_NODE; } if (out_free_inputs == NULL || out_total_count == NULL) return B_BAD_VALUE; - + List list; media_input *input; status_t rv; @@ -1438,15 +1517,22 @@ BMediaRoster::GetFreeInputsFor(const media_node & node, rv = MediaRosterEx(this)->GetAllInputs(node, &list); if (B_OK != rv) return rv; - - PRINT(4, "BMediaRoster::GetFreeInputsFor node %ld, max %ld, filter-type %ld\n", node.node, buf_num_inputs, filter_type); + + PRINT(4, "BMediaRoster::GetFreeInputsFor node %ld, max %ld, filter-type " + "%ld\n", node.node, buf_num_inputs, filter_type); int32 i; for (i = 0, list.Rewind(); list.GetNext(&input);) { - if (filter_type != B_MEDIA_UNKNOWN_TYPE && filter_type != input->format.type) - continue; // media_type used, but doesn't match - if (input->source != media_source::null) - continue; // consumer source already connected + if (filter_type != B_MEDIA_UNKNOWN_TYPE + && filter_type != input->format.type) { + // media_type used, but doesn't match + continue; + } + if (input->source != media_source::null) { + // consumer source already connected + continue; + } + out_free_inputs[i] = *input; *out_total_count += 1; buf_num_inputs -= 1; @@ -1457,24 +1543,23 @@ BMediaRoster::GetFreeInputsFor(const media_node & node, break; i++; } - + MediaRosterEx(this)->PublishInputs(node, &list); return B_OK; } -status_t -BMediaRoster::GetConnectedInputsFor(const media_node & node, - media_input * out_active_inputs, - int32 buf_num_inputs, - int32 * out_total_count) +status_t +BMediaRoster::GetConnectedInputsFor(const media_node& node, + media_input* out_active_inputs, int32 buf_num_inputs, + int32* out_total_count) { CALLED(); if (IS_INVALID_NODE(node) || (node.kind & B_BUFFER_CONSUMER) == 0) return B_MEDIA_BAD_NODE; if (out_active_inputs == NULL || out_total_count == NULL) return B_BAD_VALUE; - + List list; media_input *input; status_t rv; @@ -1485,7 +1570,8 @@ BMediaRoster::GetConnectedInputsFor(const media_node & node, if (B_OK != rv) return rv; - PRINT(4, "BMediaRoster::GetConnectedInputsFor node %ld, max %ld\n", node.node, buf_num_inputs); + PRINT(4, "BMediaRoster::GetConnectedInputsFor node %ld, max %ld\n", + node.node, buf_num_inputs); int32 i; for (i = 0, list.Rewind(); list.GetNext(&input);) { @@ -1501,24 +1587,22 @@ BMediaRoster::GetConnectedInputsFor(const media_node & node, break; i++; } - + MediaRosterEx(this)->PublishInputs(node, &list); return B_OK; } -status_t -BMediaRoster::GetAllInputsFor(const media_node & node, - media_input * out_inputs, - int32 buf_num_inputs, - int32 * out_total_count) +status_t +BMediaRoster::GetAllInputsFor(const media_node& node, media_input* out_inputs, + int32 buf_num_inputs, int32* out_total_count) { CALLED(); if (IS_INVALID_NODE(node) || (node.kind & B_BUFFER_CONSUMER) == 0) return B_MEDIA_BAD_NODE; if (out_inputs == NULL || out_total_count == NULL) return B_BAD_VALUE; - + List list; media_input *input; status_t rv; @@ -1529,7 +1613,8 @@ BMediaRoster::GetAllInputsFor(const media_node & node, if (B_OK != rv) return rv; - PRINT(4, "BMediaRoster::GetAllInputsFor node %ld, max %ld\n", node.node, buf_num_inputs); + PRINT(4, "BMediaRoster::GetAllInputsFor node %ld, max %ld\n", node.node, + buf_num_inputs); int32 i; for (i = 0, list.Rewind(); list.GetNext(&input); i++) { @@ -1542,25 +1627,23 @@ BMediaRoster::GetAllInputsFor(const media_node & node, if (buf_num_inputs == 0) break; } - + MediaRosterEx(this)->PublishInputs(node, &list); return B_OK; } -status_t -BMediaRoster::GetFreeOutputsFor(const media_node & node, - media_output * out_free_outputs, - int32 buf_num_outputs, - int32 * out_total_count, - media_type filter_type) +status_t +BMediaRoster::GetFreeOutputsFor(const media_node& node, + media_output* out_free_outputs, int32 buf_num_outputs, + int32* out_total_count, media_type filter_type) { CALLED(); if (IS_INVALID_NODE(node) || (node.kind & B_BUFFER_PRODUCER) == 0) return B_MEDIA_BAD_NODE; if (out_free_outputs == NULL || out_total_count == NULL) return B_BAD_VALUE; - + List list; media_output *output; status_t rv; @@ -1571,14 +1654,21 @@ BMediaRoster::GetFreeOutputsFor(const media_node & node, if (B_OK != rv) return rv; - PRINT(4, "BMediaRoster::GetFreeOutputsFor node %ld, max %ld, filter-type %ld\n", node.node, buf_num_outputs, filter_type); + PRINT(4, "BMediaRoster::GetFreeOutputsFor node %ld, max %ld, filter-type " + "%ld\n", node.node, buf_num_outputs, filter_type); int32 i; for (i = 0, list.Rewind(); list.GetNext(&output);) { - if (filter_type != B_MEDIA_UNKNOWN_TYPE && filter_type != output->format.type) - continue; // media_type used, but doesn't match - if (output->destination != media_destination::null) - continue; // producer destination already connected + if (filter_type != B_MEDIA_UNKNOWN_TYPE + && filter_type != output->format.type) { + // media_type used, but doesn't match + continue; + } + if (output->destination != media_destination::null) { + // producer destination already connected + continue; + } + out_free_outputs[i] = *output; *out_total_count += 1; buf_num_outputs -= 1; @@ -1594,19 +1684,18 @@ BMediaRoster::GetFreeOutputsFor(const media_node & node, return B_OK; } - -status_t -BMediaRoster::GetConnectedOutputsFor(const media_node & node, - media_output * out_active_outputs, - int32 buf_num_outputs, - int32 * out_total_count) + +status_t +BMediaRoster::GetConnectedOutputsFor(const media_node& node, + media_output* out_active_outputs, int32 buf_num_outputs, + int32* out_total_count) { CALLED(); if (IS_INVALID_NODE(node) || (node.kind & B_BUFFER_PRODUCER) == 0) return B_MEDIA_BAD_NODE; if (out_active_outputs == NULL || out_total_count == NULL) return B_BAD_VALUE; - + List list; media_output *output; status_t rv; @@ -1617,12 +1706,15 @@ BMediaRoster::GetConnectedOutputsFor(const media_node & node, if (B_OK != rv) return rv; - PRINT(4, "BMediaRoster::GetConnectedOutputsFor node %ld, max %ld\n", node.node, buf_num_outputs); + PRINT(4, "BMediaRoster::GetConnectedOutputsFor node %ld, max %ld\n", + node.node, buf_num_outputs); int32 i; for (i = 0, list.Rewind(); list.GetNext(&output);) { - if (output->destination == media_destination::null) - continue; // producer destination not connected + if (output->destination == media_destination::null) { + // producer destination not connected + continue; + } out_active_outputs[i] = *output; *out_total_count += 1; buf_num_outputs -= 1; @@ -1633,24 +1725,22 @@ BMediaRoster::GetConnectedOutputsFor(const media_node & node, break; i++; } - + MediaRosterEx(this)->PublishOutputs(node, &list); return B_OK; } -status_t -BMediaRoster::GetAllOutputsFor(const media_node & node, - media_output * out_outputs, - int32 buf_num_outputs, - int32 * out_total_count) +status_t +BMediaRoster::GetAllOutputsFor(const media_node& node, + media_output* out_outputs, int32 buf_num_outputs, int32* out_total_count) { CALLED(); if (IS_INVALID_NODE(node) || (node.kind & B_BUFFER_PRODUCER) == 0) return B_MEDIA_BAD_NODE; if (out_outputs == NULL || out_total_count == NULL) return B_BAD_VALUE; - + List list; media_output *output; status_t rv; @@ -1661,7 +1751,8 @@ BMediaRoster::GetAllOutputsFor(const media_node & node, if (B_OK != rv) return rv; - PRINT(4, "BMediaRoster::GetAllOutputsFor node %ld, max %ld\n", node.node, buf_num_outputs); + PRINT(4, "BMediaRoster::GetAllOutputsFor node %ld, max %ld\n", node.node, + buf_num_outputs); int32 i; for (i = 0, list.Rewind(); list.GetNext(&output); i++) { @@ -1674,45 +1765,46 @@ BMediaRoster::GetAllOutputsFor(const media_node & node, if (buf_num_outputs == 0) break; } - + MediaRosterEx(this)->PublishOutputs(node, &list); return B_OK; } -status_t -BMediaRoster::StartWatching(const BMessenger & where) +status_t +BMediaRoster::StartWatching(const BMessenger& where) { CALLED(); if (!where.IsValid()) { ERROR("BMediaRoster::StartWatching: messenger invalid!\n"); return B_BAD_VALUE; } - return BPrivate::media::notifications::Register(where, media_node::null, B_MEDIA_WILDCARD); + return BPrivate::media::notifications::Register(where, media_node::null, + B_MEDIA_WILDCARD); } -status_t -BMediaRoster::StartWatching(const BMessenger & where, - int32 notificationType) +status_t +BMediaRoster::StartWatching(const BMessenger & where, int32 notificationType) { CALLED(); if (!where.IsValid()) { ERROR("BMediaRoster::StartWatching: messenger invalid!\n"); return B_BAD_VALUE; } - if (false == BPrivate::media::notifications::IsValidNotificationRequest(false, notificationType)) { + if (!BPrivate::media::notifications::IsValidNotificationRequest(false, + notificationType)) { ERROR("BMediaRoster::StartWatching: notificationType invalid!\n"); return B_BAD_VALUE; } - return BPrivate::media::notifications::Register(where, media_node::null, notificationType); + return BPrivate::media::notifications::Register(where, media_node::null, + notificationType); } -status_t -BMediaRoster::StartWatching(const BMessenger & where, - const media_node & node, - int32 notificationType) +status_t +BMediaRoster::StartWatching(const BMessenger& where, const media_node& node, + int32 notificationType) { CALLED(); if (!where.IsValid()) { @@ -1723,41 +1815,44 @@ BMediaRoster::StartWatching(const BMessenger & where, ERROR("BMediaRoster::StartWatching: node invalid!\n"); return B_MEDIA_BAD_NODE; } - if (false == BPrivate::media::notifications::IsValidNotificationRequest(true, notificationType)) { + if (!BPrivate::media::notifications::IsValidNotificationRequest(true, + notificationType)) { ERROR("BMediaRoster::StartWatching: notificationType invalid!\n"); return B_BAD_VALUE; } - return BPrivate::media::notifications::Register(where, node, notificationType); -} - - -status_t -BMediaRoster::StopWatching(const BMessenger & where) -{ - CALLED(); - // messenger may already be invalid, so we don't check this - return BPrivate::media::notifications::Unregister(where, media_node::null, B_MEDIA_WILDCARD); + return BPrivate::media::notifications::Register(where, node, + notificationType); } -status_t -BMediaRoster::StopWatching(const BMessenger & where, - int32 notificationType) +status_t +BMediaRoster::StopWatching(const BMessenger& where) { CALLED(); // messenger may already be invalid, so we don't check this - if (false == BPrivate::media::notifications::IsValidNotificationRequest(false, notificationType)) { + return BPrivate::media::notifications::Unregister(where, media_node::null, + B_MEDIA_WILDCARD); +} + + +status_t +BMediaRoster::StopWatching(const BMessenger& where, int32 notificationType) +{ + CALLED(); + // messenger may already be invalid, so we don't check this + if (!BPrivate::media::notifications::IsValidNotificationRequest(false, + notificationType)) { ERROR("BMediaRoster::StopWatching: notificationType invalid!\n"); return B_BAD_VALUE; } - return BPrivate::media::notifications::Unregister(where, media_node::null, notificationType); + return BPrivate::media::notifications::Unregister(where, media_node::null, + notificationType); } - -status_t -BMediaRoster::StopWatching(const BMessenger & where, - const media_node & node, - int32 notificationType) + +status_t +BMediaRoster::StopWatching(const BMessenger& where, const media_node& node, + int32 notificationType) { CALLED(); // messenger may already be invalid, so we don't check this @@ -1765,16 +1860,18 @@ BMediaRoster::StopWatching(const BMessenger & where, ERROR("BMediaRoster::StopWatching: node invalid!\n"); return B_MEDIA_BAD_NODE; } - if (false == BPrivate::media::notifications::IsValidNotificationRequest(true, notificationType)) { + if (!BPrivate::media::notifications::IsValidNotificationRequest(true, + notificationType)) { ERROR("BMediaRoster::StopWatching: notificationType invalid!\n"); return B_BAD_VALUE; } - return BPrivate::media::notifications::Unregister(where, node, notificationType); + return BPrivate::media::notifications::Unregister(where, node, + notificationType); } -status_t -BMediaRoster::RegisterNode(BMediaNode * node) +status_t +BMediaRoster::RegisterNode(BMediaNode* node) { CALLED(); // addon-id = -1 (unused), addon-flavor-id = 0 (unused, too) @@ -1783,12 +1880,13 @@ BMediaRoster::RegisterNode(BMediaNode * node) status_t -BMediaRosterEx::RegisterNode(BMediaNode * node, media_addon_id addonid, int32 flavorid) +BMediaRosterEx::RegisterNode(BMediaNode* node, media_addon_id addonid, + int32 flavorid) { CALLED(); if (node == NULL) return B_BAD_VALUE; - + // some sanity check // I'm not sure if the media kit warrants to call BMediaNode::AddOn() here. // Perhaps we don't need it. @@ -1802,11 +1900,11 @@ BMediaRosterEx::RegisterNode(BMediaNode * node, media_addon_id addonid, int32 fl ASSERT(addonid == addon_id); ASSERT(flavorid == addon_flavor_id); } - + status_t rv; server_register_node_request request; server_register_node_reply reply; - + request.addon_id = addonid; request.addon_flavor_id = flavorid; strcpy(request.name, node->Name()); @@ -1814,16 +1912,21 @@ BMediaRosterEx::RegisterNode(BMediaNode * node, media_addon_id addonid, int32 fl request.port = node->ControlPort(); request.team = team; - TRACE("BMediaRoster::RegisterNode: sending SERVER_REGISTER_NODE: port %ld, kinds 0x%Lx, team %ld, name '%s'\n", request.port, request.kinds, request.team, request.name); - - rv = QueryServer(SERVER_REGISTER_NODE, &request, sizeof(request), &reply, sizeof(reply)); + TRACE("BMediaRoster::RegisterNode: sending SERVER_REGISTER_NODE: port " + "%ld, kinds 0x%Lx, team %ld, name '%s'\n", request.port, request.kinds, + request.team, request.name); + + rv = QueryServer(SERVER_REGISTER_NODE, &request, sizeof(request), &reply, + sizeof(reply)); if (rv != B_OK) { - ERROR("BMediaRoster::RegisterNode: failed to register node %s (error %#lx)\n", node->Name(), rv); + ERROR("BMediaRoster::RegisterNode: failed to register node %s (error " + "%#lx)\n", node->Name(), rv); return rv; } - TRACE("BMediaRoster::RegisterNode: QueryServer SERVER_REGISTER_NODE finished\n"); - + TRACE("BMediaRoster::RegisterNode: QueryServer SERVER_REGISTER_NODE " + "finished\n"); + // we are a friend class of BMediaNode and initialize this member variable node->fNodeID = reply.nodeid; ASSERT(reply.nodeid == node->Node().node); @@ -1833,8 +1936,9 @@ BMediaRosterEx::RegisterNode(BMediaNode * node, media_addon_id addonid, int32 fl node->NodeRegistered(); TRACE("BMediaRoster::RegisterNode: NodeRegistered callback finished\n"); - - // if the BMediaNode also inherits from BTimeSource, we need to call BTimeSource::FinishCreate() + + // if the BMediaNode also inherits from BTimeSource, we need to call + // BTimeSource::FinishCreate() if (node->Kinds() & B_TIME_SOURCE) { BTimeSource *ts; ts = dynamic_cast(node); @@ -1884,13 +1988,13 @@ BMediaRosterEx::RegisterNode(BMediaNode * node, media_addon_id addonid, int32 fl TRACE("BMediaRoster::RegisterNode: node fFileInterfaceThis %p\n", node->fFileInterfaceThis); TRACE("BMediaRoster::RegisterNode: node fControllableThis %p\n", node->fControllableThis); TRACE("BMediaRoster::RegisterNode: node fTimeSourceThis %p\n", node->fTimeSourceThis); -*/ +*/ return B_OK; } -status_t -BMediaRoster::UnregisterNode(BMediaNode * node) +status_t +BMediaRoster::UnregisterNode(BMediaNode* node) { CALLED(); if (node == NULL) @@ -1899,23 +2003,29 @@ BMediaRoster::UnregisterNode(BMediaNode * node) TRACE("BMediaRoster::UnregisterNode %ld (%p)\n", node->ID(), node); if (node->fKinds & NODE_KIND_NO_REFCOUNTING) { - printf("BMediaRoster::UnregisterNode, trying to unregister reference counting disabled timesource, node %ld, port %ld, team %ld\n", node->ID(), node->ControlPort(), team); + TRACE("BMediaRoster::UnregisterNode, trying to unregister reference " + "counting disabled timesource, node %ld, port %ld, team %ld\n", + node->ID(), node->ControlPort(), team); return B_OK; } if (node->ID() == NODE_UNREGISTERED_ID) { - PRINT(1, "Warning: BMediaRoster::UnregisterNode: node id %ld, name '%s' already unregistered\n", node->ID(), node->Name()); + PRINT(1, "Warning: BMediaRoster::UnregisterNode: node id %ld, name " + "'%s' already unregistered\n", node->ID(), node->Name()); return B_OK; } if (node->fRefCount != 0) { - PRINT(1, "Warning: BMediaRoster::UnregisterNode: node id %ld, name '%s' has local reference count of %ld\n", node->ID(), node->Name(), node->fRefCount); + PRINT(1, "Warning: BMediaRoster::UnregisterNode: node id %ld, name " + "'%s' has local reference count of %ld\n", node->ID(), node->Name(), + node->fRefCount); // no return here, we continue and unregister! } - - // Calling BMediaAddOn::GetConfigurationFor(BMediaNode *node, BMessage *config) - // if this node was instanciated by an add-on needs to be done *somewhere* + + // Calling BMediaAddOn::GetConfigurationFor(BMediaNode *node, + // BMessage *config) if this node was instanciated by an add-on needs to + // be done *somewhere* // We can't do it here because it is already to late (destructor of the node // might have been called). - + server_unregister_node_request request; server_unregister_node_reply reply; status_t rv; @@ -1926,37 +2036,42 @@ BMediaRoster::UnregisterNode(BMediaNode * node) // send a notification BPrivate::media::notifications::NodesDeleted(&request.nodeid, 1); - rv = QueryServer(SERVER_UNREGISTER_NODE, &request, sizeof(request), &reply, sizeof(reply)); + rv = QueryServer(SERVER_UNREGISTER_NODE, &request, sizeof(request), &reply, + sizeof(reply)); if (rv != B_OK) { - ERROR("BMediaRoster::UnregisterNode: failed to unregister node id %ld, name '%s' (error %#lx)\n", node->ID(), node->Name(), rv); + ERROR("BMediaRoster::UnregisterNode: failed to unregister node id %ld, " + "name '%s' (error %#lx)\n", node->ID(), node->Name(), rv); return rv; } - + if (reply.addonid != -1) { // Small problem here, we can't use DormantNodeManager::PutAddon(), as - // UnregisterNode() is called by a dormant node itself (by the destructor). + // UnregisterNode() is called by a dormant node itself (by the + // destructor). // The add-on that contains the node needs to remain in memory until the // destructor execution is finished. // DormantNodeManager::PutAddonDelayed() will delay unloading. _DormantNodeManager->PutAddonDelayed(reply.addonid); - rv = MediaRosterEx(this)->DecrementAddonFlavorInstancesCount(reply.addonid, reply.flavorid); + rv = MediaRosterEx(this)->DecrementAddonFlavorInstancesCount( + reply.addonid, reply.flavorid); if (rv != B_OK) { - ERROR("BMediaRoster::UnregisterNode: DecrementAddonFlavorInstancesCount failed\n"); + ERROR("BMediaRoster::UnregisterNode: " + "DecrementAddonFlavorInstancesCount() failed\n"); // this is really a problem, but we can't fail now } } // we are a friend class of BMediaNode and invalidate this member variable node->fNodeID = NODE_UNREGISTERED_ID; - + return B_OK; } -// thread safe for multiple calls to Roster() -/* static */ BMediaRoster * -BMediaRoster::Roster(status_t *out_error) +//! Thread safe for multiple calls to Roster() +/*static*/ BMediaRoster* +BMediaRoster::Roster(status_t* out_error) { static BLocker locker("BMediaRoster::Roster locker"); locker.Lock(); @@ -1982,34 +2097,33 @@ BMediaRoster::Roster(status_t *out_error) } -// won't create it if there isn't one -// not thread safe if you call Roster() at the same time -/* static */ BMediaRoster * -BMediaRoster::CurrentRoster() +/*static*/ BMediaRoster* +BMediaRoster::CurrentRoster() { return sDefaultInstance; } - -status_t -BMediaRoster::SetTimeSourceFor(media_node_id node, - media_node_id time_source) + +status_t +BMediaRoster::SetTimeSourceFor(media_node_id node, media_node_id time_source) { CALLED(); if (IS_INVALID_NODEID(node) || IS_INVALID_NODEID(time_source)) return B_BAD_VALUE; - + media_node clone; status_t rv, result; - - TRACE("BMediaRoster::SetTimeSourceFor: node %ld will be assigned time source %ld\n", node, time_source); - printf("BMediaRoster::SetTimeSourceFor: node %ld time source %ld enter\n", node, time_source); + TRACE("BMediaRoster::SetTimeSourceFor: node %ld will be assigned time " + "source %ld\n", node, time_source); + TRACE("BMediaRoster::SetTimeSourceFor: node %ld time source %ld enter\n", + node, time_source); // we need to get a clone of the node to have a port id rv = GetNodeFor(node, &clone); if (rv != B_OK) { - ERROR("BMediaRoster::SetTimeSourceFor, GetNodeFor failed, node id %ld\n", node); + ERROR("BMediaRoster::SetTimeSourceFor, GetNodeFor failed, node id " + "%ld\n", node); return B_ERROR; } @@ -2018,82 +2132,94 @@ BMediaRoster::SetTimeSourceFor(media_node_id node, result = B_OK; node_set_timesource_command cmd; cmd.timesource_id = time_source; - rv = SendToPort(clone.port, NODE_SET_TIMESOURCE, &cmd, sizeof(cmd)); + rv = SendToPort(clone.port, NODE_SET_TIMESOURCE, &cmd, sizeof(cmd)); if (rv != B_OK) { - ERROR("BMediaRoster::SetTimeSourceFor, sending NODE_SET_TIMESOURCE failed, node id %ld\n", node); + ERROR("BMediaRoster::SetTimeSourceFor, sending NODE_SET_TIMESOURCE " + "failed, node id %ld\n", node); result = B_ERROR; } // we release the clone rv = ReleaseNode(clone); if (rv != B_OK) { - ERROR("BMediaRoster::SetTimeSourceFor, ReleaseNode failed, node id %ld\n", node); + ERROR("BMediaRoster::SetTimeSourceFor, ReleaseNode failed, node id " + "%ld\n", node); result = B_ERROR; } - printf("BMediaRoster::SetTimeSourceFor: node %ld time source %ld leave\n", node, time_source); + TRACE("BMediaRoster::SetTimeSourceFor: node %ld time source %ld leave\n", + node, time_source); return result; } -status_t -BMediaRoster::GetParameterWebFor(const media_node & node, - BParameterWeb ** out_web) +status_t +BMediaRoster::GetParameterWebFor(const media_node& node, BParameterWeb** _web) { CALLED(); - if (out_web == NULL) - return B_BAD_VALUE; + if (_web == NULL) + return B_BAD_VALUE; if (IS_INVALID_NODE(node)) return B_MEDIA_BAD_NODE; if ((node.kind & B_CONTROLLABLE) == 0) return B_MEDIA_BAD_NODE; - + controllable_get_parameter_web_request request; controllable_get_parameter_web_reply reply; - int32 requestsize[] = {B_PAGE_SIZE, 4*B_PAGE_SIZE, 16*B_PAGE_SIZE, 64*B_PAGE_SIZE, 128*B_PAGE_SIZE, 256*B_PAGE_SIZE, 0}; + int32 requestsize[] = {B_PAGE_SIZE, 4 * B_PAGE_SIZE, 16 * B_PAGE_SIZE, + 64 * B_PAGE_SIZE, 128 * B_PAGE_SIZE, 256 * B_PAGE_SIZE, 0}; int32 size; - - // XXX it might be better to query the node for the (current) parameter size first + + // TODO: it might be better to query the node for the (current) parameter + // size first for (int i = 0; (size = requestsize[i]) != 0; i++) { status_t rv; area_id area; void *data; - area = create_area("parameter web data", &data, B_ANY_ADDRESS, size, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA); + area = create_area("parameter web data", &data, B_ANY_ADDRESS, size, + B_NO_LOCK, B_READ_AREA | B_WRITE_AREA); if (area < B_OK) { - ERROR("BMediaRoster::GetParameterWebFor couldn't create area of size %ld\n", size); + ERROR("BMediaRoster::GetParameterWebFor couldn't create area of " + "size %ld\n", size); return B_ERROR; } - request.maxsize = size; + request.max_size = size; request.area = area; - rv = QueryPort(node.port, CONTROLLABLE_GET_PARAMETER_WEB, &request, sizeof(request), &reply, sizeof(reply)); + rv = QueryPort(node.port, CONTROLLABLE_GET_PARAMETER_WEB, &request, + sizeof(request), &reply, sizeof(reply)); if (rv != B_OK) { - ERROR("BMediaRoster::GetParameterWebFor CONTROLLABLE_GET_PARAMETER_WEB failed\n"); + ERROR("BMediaRoster::GetParameterWebFor " + "CONTROLLABLE_GET_PARAMETER_WEB failed\n"); delete_area(area); return B_ERROR; } if (reply.size == 0) { // no parameter web available - // XXX should we return an error? - ERROR("BMediaRoster::GetParameterWebFor node %ld has no parameter web\n", node.node); - *out_web = new (std::nothrow) BParameterWeb(); + // TODO: should we return an error? + ERROR("BMediaRoster::GetParameterWebFor node %ld has no parameter " + "web\n", node.node); + *_web = new (std::nothrow) BParameterWeb(); delete_area(area); - return *out_web != NULL ? B_OK : B_NO_MEMORY; + return *_web != NULL ? B_OK : B_NO_MEMORY; } if (reply.size > 0) { // we got a flattened parameter web! - *out_web = new (std::nothrow) BParameterWeb(); - if (*out_web == NULL) + *_web = new (std::nothrow) BParameterWeb(); + if (*_web == NULL) rv = B_NO_MEMORY; else { - printf("BMediaRoster::GetParameterWebFor Unflattening %ld bytes, 0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx\n", - reply.size, ((uint32*)data)[0], ((uint32*)data)[1], ((uint32*)data)[2], ((uint32*)data)[3]); + printf("BMediaRoster::GetParameterWebFor Unflattening %ld " + "bytes, 0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx\n", + reply.size, ((uint32*)data)[0], ((uint32*)data)[1], + ((uint32*)data)[2], ((uint32*)data)[3]); - rv = (*out_web)->Unflatten(reply.code, data, reply.size); + rv = (*_web)->Unflatten(reply.code, data, reply.size); } if (rv != B_OK) { - ERROR("BMediaRoster::GetParameterWebFor Unflatten failed, %s\n", strerror(rv)); - delete *out_web; + ERROR("BMediaRoster::GetParameterWebFor Unflatten failed, " + "%s\n", strerror(rv)); + delete *_web; } delete_area(area); return rv; @@ -2103,14 +2229,14 @@ BMediaRoster::GetParameterWebFor(const media_node & node, // parameter web data was too large // loop and try a larger size } - ERROR("BMediaRoster::GetParameterWebFor node %ld has no parameter web larger than %ld\n", node.node, size); + ERROR("BMediaRoster::GetParameterWebFor node %ld has no parameter web " + "larger than %ld\n", node.node, size); return B_ERROR; } - -status_t -BMediaRoster::StartControlPanel(const media_node & node, - BMessenger * out_messenger) + +status_t +BMediaRoster::StartControlPanel(const media_node& node, BMessenger* _messenger) { CALLED(); @@ -2120,32 +2246,25 @@ BMediaRoster::StartControlPanel(const media_node & node, request.node = node; status_t rv; - rv = QueryPort(node.port, CONTROLLABLE_START_CONTROL_PANEL, &request, sizeof(request), &reply, sizeof(reply)); + rv = QueryPort(node.port, CONTROLLABLE_START_CONTROL_PANEL, &request, + sizeof(request), &reply, sizeof(reply)); if (rv != B_OK) return rv; - if (reply.team != -1 && out_messenger) - *out_messenger = BMessenger(0, reply.team); + if (reply.team != -1 && _messenger != NULL) + *_messenger = BMessenger(NULL, reply.team); return B_OK; } -status_t -BMediaRoster::GetDormantNodes(dormant_node_info * out_info, - int32 * io_count, - const media_format * has_input /* = NULL */, - const media_format * has_output /* = NULL */, - const char * name /* = NULL */, - uint64 require_kinds /* = NULL */, - uint64 deny_kinds /* = NULL */) +status_t +BMediaRoster::GetDormantNodes(dormant_node_info* _info, int32* _count, + const media_format* hasInput, const media_format* hasOutput, + const char* name, uint64 requireKinds, uint64 denyKinds) { CALLED(); - if (out_info == NULL) - return B_BAD_VALUE; - if (io_count == NULL) - return B_BAD_VALUE; - if (*io_count <= 0) + if (_info == NULL || _count == NULL || *_count <= 0) return B_BAD_VALUE; xfer_server_get_dormant_nodes msg; @@ -2155,23 +2274,28 @@ BMediaRoster::GetDormantNodes(dormant_node_info * out_info, port = find_port(MEDIA_SERVER_PORT_NAME); if (port <= B_OK) return B_ERROR; - - msg.maxcount = *io_count; - msg.has_input = (bool) has_input; - if (has_input) - msg.inputformat = *has_input; // XXX we should not make a flat copy of media_format - msg.has_output = (bool) has_output; - if (has_output) - msg.outputformat = *has_output;; // XXX we should not make a flat copy of media_format - msg.has_name = (bool) name; - if (name) { + + msg.maxcount = *_count; + msg.has_input = hasInput != NULL; + if (hasInput != NULL) { + // TODO: we should not make a flat copy of media_format + msg.inputformat = *hasInput; + } + msg.has_output = hasOutput != NULL; + if (hasOutput != NULL) { + // TODO: we should not make a flat copy of media_format + msg.outputformat = *hasOutput; + } + + msg.has_name = name != NULL; + if (name != NULL) { int len = strlen(name); len = min_c(len, (int)sizeof(msg.name) - 1); memcpy(msg.name, name, len); msg.name[len] = 0; } - msg.require_kinds = require_kinds; - msg.deny_kinds = deny_kinds; + msg.require_kinds = requireKinds; + msg.deny_kinds = denyKinds; msg.reply_port = _PortPool->GetPort(); rv = write_port(port, SERVER_GET_DORMANT_NODES, &msg, sizeof(msg)); @@ -2189,26 +2313,29 @@ BMediaRoster::GetDormantNodes(dormant_node_info * out_info, return rv; } - *io_count = reply.count; - - if (*io_count > 0) { - rv = read_port(msg.reply_port, &code, out_info, *io_count * sizeof(dormant_node_info)); + *_count = reply.count; + + if (*_count > 0) { + rv = read_port(msg.reply_port, &code, _info, + *_count * sizeof(dormant_node_info)); if (rv < B_OK) reply.result = rv; } _PortPool->PutPort(msg.reply_port); - + return reply.result; } -/* This function is used to do the real work of instantiating a dormant node. It is either - * called by the media_addon_server to instantiate a global node, or it gets called from - * BMediaRoster::InstantiateDormantNode() to create a local one. - * - * Checks concerning global/local are not done here. - */ +/*! This function is used to do the real work of instantiating a dormant node. + It is either called by the media_addon_server to instantiate a global node, + or it gets called from BMediaRoster::InstantiateDormantNode() to create a + local one. + + Checks concerning global/local are not done here. +*/ status_t -BMediaRosterEx::InstantiateDormantNode(media_addon_id addonid, int32 flavorid, team_id creator, media_node *out_node) +BMediaRosterEx::InstantiateDormantNode(media_addon_id addonID, int32 flavorID, + team_id creator, media_node *_node) { // This function is always called from the correct context, if the node // is supposed to be global, it is called from the media_addon_server. @@ -2219,238 +2346,271 @@ BMediaRosterEx::InstantiateDormantNode(media_addon_id addonid, int32 flavorid, t // RegisterNode() must be called for nodes instantiated from add-ons, // since the media kit warrants that it's done automatically. - // addonid Indicates the ID number of the media add-on in which the node resides. - // flavorid Indicates the internal ID number that the add-on uses to identify the flavor, - // this is the number that was published by BMediaAddOn::GetFlavorAt() in the + // addonID Indicates the ID number of the media add-on in which the + // node resides. + // flavorID Indicates the internal ID number that the add-on uses to + // identify the flavor, this is the number that was published + // by BMediaAddOn::GetFlavorAt() in the // flavor_info::internal_id field. - // creator The creator team is -1 if nodes are created locally. If created globally, - // it will contain (while called in media_addon_server context) the team-id of - // the team that requested the instantiation. - - TRACE("BMediaRosterEx::InstantiateDormantNode: addon-id %ld, flavor_id %ld\n", addonid, flavorid); + // creator The creator team is -1 if nodes are created locally. If + // created globally, it will contain (while called in + // media_addon_server context) the team-id of the team that + // requested the instantiation. + + TRACE("BMediaRosterEx::InstantiateDormantNode: addonID %ld, flavorID " + "%ld\n", addonID, flavorID); // Get flavor_info from the server - dormant_flavor_info node_info; + dormant_flavor_info info; status_t rv; - rv = GetDormantFlavorInfo(addonid, flavorid, &node_info); + rv = GetDormantFlavorInfo(addonID, flavorID, &info); if (rv != B_OK) { - ERROR("BMediaRosterEx::InstantiateDormantNode error: failed to get dormant_flavor_info for addon-id %ld, flavor-id %ld\n", addonid, flavorid); - return B_ERROR; - } - - //ASSERT(node_info.internal_id == flavorid); - if (node_info.internal_id != flavorid) { - ERROR("############# BMediaRosterEx::InstantiateDormantNode failed: ID mismatch for addon-id %ld, flavor-id %ld, node_info.internal_id %ld, node_info.name %s\n", addonid, flavorid, node_info.internal_id, node_info.name); + ERROR("BMediaRosterEx::InstantiateDormantNode error: failed to get " + "dormant_flavor_info for addon-id %ld, flavor-id %ld\n", addonID, + flavorID); return B_ERROR; } + ASSERT(node_info.internal_id == flavorID); + // load the BMediaAddOn object - BMediaAddOn *addon; - addon = _DormantNodeManager->GetAddon(addonid); - if (!addon) { + BMediaAddOn* addon; + addon = _DormantNodeManager->GetAddon(addonID); + if (addon == NULL) { ERROR("BMediaRosterEx::InstantiateDormantNode: GetAddon failed\n"); return B_ERROR; } - + // Now we need to try to increment the use count of this addon flavor // in the server. This can fail if the total number instances of this // flavor is limited. - rv = IncrementAddonFlavorInstancesCount(addonid, flavorid); + rv = IncrementAddonFlavorInstancesCount(addonID, flavorID); if (rv != B_OK) { - ERROR("BMediaRosterEx::InstantiateDormantNode error: can't create more nodes for addon-id %ld, flavor-id %ld\n", addonid, flavorid); + ERROR("BMediaRosterEx::InstantiateDormantNode error: can't create " + "more nodes for addon-id %ld, flavor-id %ld\n", addonID, flavorID); // Put the addon back into the pool - _DormantNodeManager->PutAddon(addonid); + _DormantNodeManager->PutAddon(addonID); return B_ERROR; } BMessage config; - rv = LoadNodeConfiguration(addonid, flavorid, &config); + rv = LoadNodeConfiguration(addonID, flavorID, &config); if (rv != B_OK) { - ERROR("BMediaRosterEx::InstantiateDormantNode: couldn't load configuration for addon-id %ld, flavor-id %ld\n", addonid, flavorid); + ERROR("BMediaRosterEx::InstantiateDormantNode: couldn't load " + "configuration for addon-id %ld, flavor-id %ld\n", addonID, + flavorID); // do not return, this is a minor problem, not a reason to fail } - BMediaNode *node; - status_t out_error; - - out_error = B_OK; - node = addon->InstantiateNodeFor(&node_info, &config, &out_error); - if (!node) { - ERROR("BMediaRosterEx::InstantiateDormantNode: InstantiateNodeFor failed\n"); + status_t status = B_OK; + BMediaNode* node = addon->InstantiateNodeFor(&info, &config, &status); + if (node == NULL) { + ERROR("BMediaRosterEx::InstantiateDormantNode: InstantiateNodeFor " + "failed\n"); + // Put the addon back into the pool - _DormantNodeManager->PutAddon(addonid); + _DormantNodeManager->PutAddon(addonID); + // We must decrement the use count of this addon flavor in the // server to compensate the increment done in the beginning. - rv = DecrementAddonFlavorInstancesCount(addonid, flavorid); + rv = DecrementAddonFlavorInstancesCount(addonID, flavorID); if (rv != B_OK) { - ERROR("BMediaRosterEx::InstantiateDormantNode: DecrementAddonFlavorInstancesCount failed\n"); + ERROR("BMediaRosterEx::InstantiateDormantNode: DecrementAddon" + "FlavorInstancesCount failed\n"); } - return (out_error != B_OK) ? out_error : B_ERROR; + return status != B_OK ? status : B_ERROR; } - rv = RegisterNode(node, addonid, flavorid); + rv = RegisterNode(node, addonID, flavorID); if (rv != B_OK) { ERROR("BMediaRosterEx::InstantiateDormantNode: RegisterNode failed\n"); delete node; // Put the addon back into the pool - _DormantNodeManager->PutAddon(addonid); + _DormantNodeManager->PutAddon(addonID); // We must decrement the use count of this addon flavor in the // server to compensate the increment done in the beginning. - rv = DecrementAddonFlavorInstancesCount(addonid, flavorid); + rv = DecrementAddonFlavorInstancesCount(addonID, flavorID); if (rv != B_OK) { - ERROR("BMediaRosterEx::InstantiateDormantNode: DecrementAddonFlavorInstancesCount failed\n"); + ERROR("BMediaRosterEx::InstantiateDormantNode: DecrementAddon" + "FlavorInstancesCount failed\n"); } return B_ERROR; } - + if (creator != -1) { - // send a message to the server to assign team "creator" as creator of node "node->ID()" - printf("!!! BMediaRosterEx::InstantiateDormantNode assigning team %ld as creator of node %ld\n", creator, node->ID()); + // send a message to the server to assign team "creator" as creator + // of node "node->ID()" + printf("!!! BMediaRosterEx::InstantiateDormantNode assigning team " + "%ld as creator of node %ld\n", creator, node->ID()); + rv = MediaRosterEx(this)->SetNodeCreator(node->ID(), creator); if (rv != B_OK) { - ERROR("BMediaRosterEx::InstantiateDormantNode failed to assign team %ld as creator of node %ld\n", creator, node->ID()); + ERROR("BMediaRosterEx::InstantiateDormantNode failed to assign " + "team %ld as creator of node %ld\n", creator, node->ID()); // do not return, this is a minor problem, not a reason to fail } } - + // RegisterNode() does remember the add-on id in the server // and UnregisterNode() will call DormantNodeManager::PutAddon() // when the node is unregistered. - *out_node = node->Node(); + *_node = node->Node(); - TRACE("BMediaRosterEx::InstantiateDormantNode: addon-id %ld, flavor_id %ld instanciated as node %ld, port %ld in team %ld\n", addonid, flavorid, out_node->node, out_node->port, team); + TRACE("BMediaRosterEx::InstantiateDormantNode: addon-id %ld, flavor_id " + "%ld instanciated as node %ld, port %ld in team %ld\n", addonID, + flavorID, _node->node, _node->port, team); return B_OK; } -status_t -BMediaRoster::InstantiateDormantNode(const dormant_node_info & in_info, - media_node * out_node, - uint32 flags /* currently 0 or B_FLAVOR_IS_GLOBAL or B_FLAVOR_IS_LOCAL */ ) +status_t +BMediaRoster::InstantiateDormantNode(const dormant_node_info& info, + media_node* _node, uint32 flags) { CALLED(); - if (out_node == 0) + if (_node == NULL) return B_BAD_VALUE; - if (in_info.addon <= 0) { - ERROR("BMediaRoster::InstantiateDormantNode error: addon-id %ld invalid.\n", in_info.addon); + if (info.addon <= B_OK) { + ERROR("BMediaRoster::InstantiateDormantNode error: addon-id %ld " + "invalid.\n", info.addon); return B_BAD_VALUE; } - printf("BMediaRoster::InstantiateDormantNode: addon-id %ld, flavor_id %ld, flags 0x%lX\n", in_info.addon, in_info.flavor_id, flags); + printf("BMediaRoster::InstantiateDormantNode: addon-id %ld, flavor_id " + "%ld, flags 0x%lX\n", info.addon, info.flavor_id, flags); // Get flavor_info from the server - // XXX this is a little overhead, as we get the full blown dormant_flavor_info, - // XXX but only need the flags. - dormant_flavor_info node_info; + // TODO: this is a little overhead, as we get the full blown + // dormant_flavor_info, + // TODO: but only need the flags. + dormant_flavor_info flavorInfo; status_t rv; - rv = MediaRosterEx(this)->GetDormantFlavorInfo(in_info.addon, in_info.flavor_id, &node_info); + rv = MediaRosterEx(this)->GetDormantFlavorInfo(info.addon, info.flavor_id, + &flavorInfo); if (rv != B_OK) { - ERROR("BMediaRoster::InstantiateDormantNode: failed to get dormant_flavor_info for addon-id %ld, flavor-id %ld\n", in_info.addon, in_info.flavor_id); + ERROR("BMediaRoster::InstantiateDormantNode: failed to get " + "dormant_flavor_info for addon-id %ld, flavor-id %ld\n", + info.addon, info.flavor_id); return B_NAME_NOT_FOUND; } - ASSERT(node_info.internal_id == in_info.flavor_id); + ASSERT(flavorInfo.internal_id == info.flavor_id); - printf("BMediaRoster::InstantiateDormantNode: name \"%s\", info \"%s\", flavor_flags 0x%lX, internal_id %ld, possible_count %ld\n", - node_info.name, node_info.info, node_info.flavor_flags, node_info.internal_id, node_info.possible_count); +#if DEBUG + printf("BMediaRoster::InstantiateDormantNode: name \"%s\", info \"%s\", " + "flavor_flags 0x%lX, internal_id %ld, possible_count %ld\n", + flavorInfo.name, flavorInfo.info, flavorInfo.flavor_flags, + flavorInfo.internal_id, flavorInfo.possible_count); - #if DEBUG - if (flags & B_FLAVOR_IS_LOCAL) - printf("BMediaRoster::InstantiateDormantNode: caller requested B_FLAVOR_IS_LOCAL\n"); - if (flags & B_FLAVOR_IS_GLOBAL) - printf("BMediaRoster::InstantiateDormantNode: caller requested B_FLAVOR_IS_GLOBAL\n"); - if (node_info.flavor_flags & B_FLAVOR_IS_LOCAL) - printf("BMediaRoster::InstantiateDormantNode: node requires B_FLAVOR_IS_LOCAL\n"); - if (node_info.flavor_flags & B_FLAVOR_IS_GLOBAL) - printf("BMediaRoster::InstantiateDormantNode: node requires B_FLAVOR_IS_GLOBAL\n"); - #endif + if ((flags & B_FLAVOR_IS_LOCAL) != 0) { + printf("BMediaRoster::InstantiateDormantNode: caller requested " + "B_FLAVOR_IS_LOCAL\n"); + } + if ((flags & B_FLAVOR_IS_GLOBAL) != 0) { + printf("BMediaRoster::InstantiateDormantNode: caller requested " + "B_FLAVOR_IS_GLOBAL\n"); + } + if ((flavorInfo.flavor_flags & B_FLAVOR_IS_LOCAL) != 0) { + printf("BMediaRoster::InstantiateDormantNode: node requires " + "B_FLAVOR_IS_LOCAL\n"); + } + if ((flavorInfo.flavor_flags & B_FLAVOR_IS_GLOBAL) != 0) { + printf("BMediaRoster::InstantiateDormantNode: node requires " + "B_FLAVOR_IS_GLOBAL\n"); + } +#endif // Make sure that flags demanded by the dormant node and those requested // by the caller are not incompatible. - if ((node_info.flavor_flags & B_FLAVOR_IS_GLOBAL) && (flags & B_FLAVOR_IS_LOCAL)) { - ERROR("BMediaRoster::InstantiateDormantNode: requested B_FLAVOR_IS_LOCAL, but dormant node has B_FLAVOR_IS_GLOBAL\n"); + if ((flavorInfo.flavor_flags & B_FLAVOR_IS_GLOBAL) != 0 + && (flags & B_FLAVOR_IS_LOCAL) != 0) { + ERROR("BMediaRoster::InstantiateDormantNode: requested " + "B_FLAVOR_IS_LOCAL, but dormant node has B_FLAVOR_IS_GLOBAL\n"); return B_NAME_NOT_FOUND; } - if ((node_info.flavor_flags & B_FLAVOR_IS_LOCAL) && (flags & B_FLAVOR_IS_GLOBAL)) { - ERROR("BMediaRoster::InstantiateDormantNode: requested B_FLAVOR_IS_GLOBAL, but dormant node has B_FLAVOR_IS_LOCAL\n"); + if ((flavorInfo.flavor_flags & B_FLAVOR_IS_LOCAL) != 0 + && (flags & B_FLAVOR_IS_GLOBAL) != 0) { + ERROR("BMediaRoster::InstantiateDormantNode: requested " + "B_FLAVOR_IS_GLOBAL, but dormant node has B_FLAVOR_IS_LOCAL\n"); return B_NAME_NOT_FOUND; } // If either the node, or the caller requested to make the instance global - // we will do it by forwarding this request into the media_addon_server, which - // in turn will call BMediaRosterEx::InstantiateDormantNode to create the node - // there and make it globally available. - if ((node_info.flavor_flags & B_FLAVOR_IS_GLOBAL) || (flags & B_FLAVOR_IS_GLOBAL)) { - - printf("BMediaRoster::InstantiateDormantNode: creating global object in media_addon_server\n"); + // we will do it by forwarding this request into the media_addon_server, + // which in turn will call BMediaRosterEx::InstantiateDormantNode to create + // the node there and make it globally available. + if ((flavorInfo.flavor_flags & B_FLAVOR_IS_GLOBAL) != 0 + || (flags & B_FLAVOR_IS_GLOBAL) != 0) { + TRACE("BMediaRoster::InstantiateDormantNode: creating global object " + "in media_addon_server\n"); addonserver_instantiate_dormant_node_request request; addonserver_instantiate_dormant_node_reply reply; - request.addonid = in_info.addon; - request.flavorid = in_info.flavor_id; - request.creator_team = team; // creator team is allowed to also release global nodes - rv = QueryAddonServer(ADDONSERVER_INSTANTIATE_DORMANT_NODE, &request, sizeof(request), &reply, sizeof(reply)); - if (rv == B_OK) { - *out_node = reply.node; - } - + request.addonid = info.addon; + request.flavorid = info.flavor_id; + request.creator_team = team; + // creator team is allowed to also release global nodes + rv = QueryAddonServer(ADDONSERVER_INSTANTIATE_DORMANT_NODE, &request, + sizeof(request), &reply, sizeof(reply)); + if (rv == B_OK) + *_node = reply.node; } else { - // creator team = -1, as this is a local node - rv = MediaRosterEx(this)->InstantiateDormantNode(in_info.addon, in_info.flavor_id, -1, out_node); - + rv = MediaRosterEx(this)->InstantiateDormantNode(info.addon, + info.flavor_id, -1, _node); } if (rv != B_OK) { - *out_node = media_node::null; + *_node = media_node::null; return B_NAME_NOT_FOUND; } return B_OK; } - -status_t -BMediaRoster::InstantiateDormantNode(const dormant_node_info & in_info, - media_node * out_node) + +status_t +BMediaRoster::InstantiateDormantNode(const dormant_node_info& info, + media_node* _node) { - return InstantiateDormantNode(in_info, out_node, 0); + return InstantiateDormantNode(info, _node, 0); } -status_t -BMediaRoster::GetDormantNodeFor(const media_node & node, - dormant_node_info * out_info) +status_t +BMediaRoster::GetDormantNodeFor(const media_node& node, + dormant_node_info* _info) { CALLED(); - if (out_info == NULL) - return B_BAD_VALUE; + if (_info == NULL) + return B_BAD_VALUE; if (IS_INVALID_NODE(node)) return B_MEDIA_BAD_NODE; server_get_dormant_node_for_request request; server_get_dormant_node_for_reply reply; status_t rv; - + request.node = node; - - rv = QueryServer(SERVER_GET_DORMANT_NODE_FOR, &request, sizeof(request), &reply, sizeof(reply)); + + rv = QueryServer(SERVER_GET_DORMANT_NODE_FOR, &request, sizeof(request), + &reply, sizeof(reply)); if (rv != B_OK) return rv; - - *out_info = reply.node_info; + + *_info = reply.node_info; return B_OK; } -status_t -BMediaRosterEx::GetDormantFlavorInfo(media_addon_id addonid, - int32 flavorid, - dormant_flavor_info * out_flavor) + +status_t +BMediaRosterEx::GetDormantFlavorInfo(media_addon_id addonID, int32 flavorID, + dormant_flavor_info* _flavor) { CALLED(); - if (out_flavor == NULL) + if (_flavor == NULL) return B_BAD_VALUE; - + xfer_server_get_dormant_flavor_info msg; xfer_server_get_dormant_flavor_info_reply *reply; port_id port; @@ -2458,16 +2618,16 @@ BMediaRosterEx::GetDormantFlavorInfo(media_addon_id addonid, int32 code; port = find_port(MEDIA_SERVER_PORT_NAME); - if (port <= B_OK) + if (port < B_OK) return B_ERROR; - reply = (xfer_server_get_dormant_flavor_info_reply *) malloc(16000); - if (reply == 0) - return B_ERROR; - - msg.addon = addonid; - msg.flavor_id = flavorid; - msg.reply_port = _PortPool->GetPort(); + reply = (xfer_server_get_dormant_flavor_info_reply*)malloc(16000); + if (reply == NULL) + return B_NO_MEMORY; + + msg.addon = addonID; + msg.flavor_id = flavorID; + msg.reply_port = _PortPool->GetPort(); rv = write_port(port, SERVER_GET_DORMANT_FLAVOR_INFO, &msg, sizeof(msg)); if (rv != B_OK) { free(reply); @@ -2481,124 +2641,124 @@ BMediaRosterEx::GetDormantFlavorInfo(media_addon_id addonid, free(reply); return rv; } - + if (reply->result == B_OK) - rv = out_flavor->Unflatten(reply->dfi_type, &reply->dfi, reply->dfi_size); + rv = _flavor->Unflatten(reply->dfi_type, &reply->dfi, reply->dfi_size); else rv = reply->result; - + free(reply); return rv; } -status_t -BMediaRoster::GetDormantFlavorInfoFor(const dormant_node_info & in_dormant, - dormant_flavor_info * out_flavor) + +status_t +BMediaRoster::GetDormantFlavorInfoFor(const dormant_node_info& dormant, + dormant_flavor_info* _flavor) { - return MediaRosterEx(this)->GetDormantFlavorInfo(in_dormant.addon, in_dormant.flavor_id, out_flavor); + return MediaRosterEx(this)->GetDormantFlavorInfo(dormant.addon, + dormant.flavor_id, _flavor); } + // Reports in outLatency the maximum latency found downstream from // the specified BBufferProducer, producer, given the current connections. -status_t -BMediaRoster::GetLatencyFor(const media_node & producer, - bigtime_t * out_latency) +status_t +BMediaRoster::GetLatencyFor(const media_node& producer, bigtime_t* _latency) { CALLED(); - if (out_latency == NULL) + if (_latency == NULL) return B_BAD_VALUE; - if (IS_INVALID_NODE(producer)) + if (IS_INVALID_NODE(producer) + || (producer.kind & B_BUFFER_PRODUCER) == 0) return B_MEDIA_BAD_NODE; - if ((producer.kind & B_BUFFER_PRODUCER) == 0) - return B_MEDIA_BAD_NODE; - + producer_get_latency_request request; producer_get_latency_reply reply; status_t rv; - rv = QueryPort(producer.port, PRODUCER_GET_LATENCY, &request, sizeof(request), &reply, sizeof(reply)); + rv = QueryPort(producer.port, PRODUCER_GET_LATENCY, &request, + sizeof(request), &reply, sizeof(reply)); if (rv != B_OK) return rv; - - *out_latency = reply.latency; - + + *_latency = reply.latency; + // printf("BMediaRoster::GetLatencyFor producer %ld has maximum latency %Ld\n", producer.node, *out_latency); return B_OK; } -status_t -BMediaRoster::GetInitialLatencyFor(const media_node & producer, - bigtime_t * out_latency, - uint32 * out_flags /* = NULL */) +status_t +BMediaRoster::GetInitialLatencyFor(const media_node& producer, + bigtime_t* _latency, uint32* _flags) { CALLED(); - if (out_latency == NULL) + if (_latency == NULL) return B_BAD_VALUE; - if (IS_INVALID_NODE(producer)) + if (IS_INVALID_NODE(producer) + || (producer.kind & B_BUFFER_PRODUCER) == 0) return B_MEDIA_BAD_NODE; - if ((producer.kind & B_BUFFER_PRODUCER) == 0) - return B_MEDIA_BAD_NODE; - + producer_get_initial_latency_request request; producer_get_initial_latency_reply reply; status_t rv; - rv = QueryPort(producer.port, PRODUCER_GET_INITIAL_LATENCY, &request, sizeof(request), &reply, sizeof(reply)); + rv = QueryPort(producer.port, PRODUCER_GET_INITIAL_LATENCY, &request, + sizeof(request), &reply, sizeof(reply)); if (rv != B_OK) return rv; - - *out_latency = reply.initial_latency; - if (out_flags) - *out_flags = reply.flags; - - printf("BMediaRoster::GetInitialLatencyFor producer %ld has maximum initial latency %Ld\n", producer.node, *out_latency); + + *_latency = reply.initial_latency; + if (_flags != NULL) + *_flags = reply.flags; + + TRACE("BMediaRoster::GetInitialLatencyFor producer %ld has maximum " + "initial latency %Ld\n", producer.node, *_latency); return B_OK; } -status_t -BMediaRoster::GetStartLatencyFor(const media_node & time_source, - bigtime_t * out_latency) +status_t +BMediaRoster::GetStartLatencyFor(const media_node& timeSource, + bigtime_t* _latency) { CALLED(); - if (out_latency == NULL) + if (_latency == NULL) return B_BAD_VALUE; - if (IS_INVALID_NODE(time_source)) + if (IS_INVALID_NODE(timeSource) + || (timeSource.kind & B_TIME_SOURCE) == 0) return B_MEDIA_BAD_NODE; - if ((time_source.kind & B_TIME_SOURCE) == 0) - return B_MEDIA_BAD_NODE; - + timesource_get_start_latency_request request; timesource_get_start_latency_reply reply; status_t rv; - rv = QueryPort(time_source.port, TIMESOURCE_GET_START_LATENCY, &request, sizeof(request), &reply, sizeof(reply)); + rv = QueryPort(timeSource.port, TIMESOURCE_GET_START_LATENCY, &request, + sizeof(request), &reply, sizeof(reply)); if (rv != B_OK) return rv; - - *out_latency = reply.start_latency; - - printf("BMediaRoster::GetStartLatencyFor timesource %ld has maximum initial latency %Ld\n", time_source.node, *out_latency); + + *_latency = reply.start_latency; + + TRACE("BMediaRoster::GetStartLatencyFor timesource %ld has maximum " + "initial latency %Ld\n", timeSource.node, *_latency); return B_OK; } -status_t -BMediaRoster::GetFileFormatsFor(const media_node & file_interface, - media_file_format * out_formats, - int32 * io_num_infos) +status_t +BMediaRoster::GetFileFormatsFor(const media_node& fileInterface, + media_file_format* _formats, int32* _numFormats) { UNIMPLEMENTED(); return B_ERROR; } -status_t -BMediaRoster::SetRefFor(const media_node & file_interface, - const entry_ref & file, - bool create_and_truncate, - bigtime_t * out_length) /* if create is false */ +status_t +BMediaRoster::SetRefFor(const media_node& file_interface, const entry_ref& file, + bool createAndTruncate, bigtime_t* _length) { CALLED(); @@ -2609,57 +2769,55 @@ BMediaRoster::SetRefFor(const media_node & file_interface, request.device = file.device; request.directory = file.directory; strcpy(request.name, file.name); - request.create = create_and_truncate; - if (out_length) - request.duration = *out_length; + request.create = createAndTruncate; + if (_length != NULL) + request.duration = *_length; - rv = QueryPort(file_interface.port, FILEINTERFACE_SET_REF, &request, sizeof(request), &reply, sizeof(reply)); + rv = QueryPort(file_interface.port, FILEINTERFACE_SET_REF, &request, + sizeof(request), &reply, sizeof(reply)); if (rv != B_OK) return rv; - if (!create_and_truncate && out_length) - *out_length = reply.duration; + if (!createAndTruncate && _length) + *_length = reply.duration; return B_OK; } -status_t -BMediaRoster::GetRefFor(const media_node & node, - entry_ref * out_file, - BMimeType * mime_type) +status_t +BMediaRoster::GetRefFor(const media_node& node, entry_ref* _file, + BMimeType* mimeType) { CALLED(); - if (!out_file) + if (!_file) return B_BAD_VALUE; fileinterface_get_ref_request request; fileinterface_get_ref_reply reply; status_t rv; - rv = QueryPort(node.port, FILEINTERFACE_GET_REF, &request, sizeof(request), &reply, sizeof(reply)); + rv = QueryPort(node.port, FILEINTERFACE_GET_REF, &request, sizeof(request), + &reply, sizeof(reply)); if (rv != B_OK) return rv; - *out_file = entry_ref(reply.device, reply.directory, reply.name); + *_file = entry_ref(reply.device, reply.directory, reply.name); - if (mime_type) - mime_type->SetTo(reply.mimetype); + if (mimeType) + mimeType->SetTo(reply.mimetype); return B_OK; } -status_t -BMediaRoster::SniffRefFor(const media_node & file_interface, - const entry_ref & file, - BMimeType * mime_type, - float * out_capability) +status_t +BMediaRoster::SniffRefFor(const media_node& file_interface, + const entry_ref& file, BMimeType* mimeType, float* _capability) { CALLED(); - - if (!mime_type || !out_capability) + if (mimeType == NULL || _capability == NULL) return B_BAD_VALUE; fileinterface_sniff_ref_request request; @@ -2670,271 +2828,266 @@ BMediaRoster::SniffRefFor(const media_node & file_interface, request.directory = file.directory; strcpy(request.name, file.name); - rv = QueryPort(file_interface.port, FILEINTERFACE_SNIFF_REF, &request, sizeof(request), &reply, sizeof(reply)); + rv = QueryPort(file_interface.port, FILEINTERFACE_SNIFF_REF, &request, + sizeof(request), &reply, sizeof(reply)); if (rv != B_OK) return rv; - mime_type->SetTo(reply.mimetype); - *out_capability = reply.capability; + mimeType->SetTo(reply.mimetype); + *_capability = reply.capability; return B_OK; } -/* This is the generic "here's a file, now can someone please play it" interface */ -status_t -BMediaRoster::SniffRef(const entry_ref & file, - uint64 require_node_kinds, /* if you need an EntityInterface or BufferConsumer or something */ - dormant_node_info * out_node, - BMimeType * mime_type) +/*! This is the generic "here's a file, now can someone please play it" + interface. +*/ +status_t +BMediaRoster::SniffRef(const entry_ref& file, uint64 requireNodeKinds, + dormant_node_info* _node, BMimeType* mimeType) { UNIMPLEMENTED(); return B_ERROR; } -status_t -BMediaRoster::GetDormantNodeForType(const BMimeType & type, - uint64 require_node_kinds, - dormant_node_info * out_node) -{ - UNIMPLEMENTED(); - return B_ERROR; -} - - -status_t -BMediaRoster::GetReadFileFormatsFor(const dormant_node_info & in_node, - media_file_format * out_read_formats, - int32 in_read_count, - int32 * out_read_count) -{ - UNIMPLEMENTED(); - return B_ERROR; -} - - -status_t -BMediaRoster::GetWriteFileFormatsFor(const dormant_node_info & in_node, - media_file_format * out_write_formats, - int32 in_write_count, - int32 * out_write_count) +status_t +BMediaRoster::GetDormantNodeForType(const BMimeType& type, + uint64 requireNodeKinds, dormant_node_info* _node) { UNIMPLEMENTED(); return B_ERROR; } -status_t -BMediaRoster::GetFormatFor(const media_output & output, - media_format * io_format, - uint32 flags) +status_t +BMediaRoster::GetReadFileFormatsFor(const dormant_node_info& node, + media_file_format* _readFormats, int32 readCount, int32* _readCount) +{ + UNIMPLEMENTED(); + return B_ERROR; +} + + +status_t +BMediaRoster::GetWriteFileFormatsFor(const dormant_node_info& node, + media_file_format* _write_formats, int32 writeCount, int32* _writeCount) +{ + UNIMPLEMENTED(); + return B_ERROR; +} + + +status_t +BMediaRoster::GetFormatFor(const media_output& output, media_format* _format, + uint32 flags) { CALLED(); - if (io_format == NULL) + if (_format == NULL) return B_BAD_VALUE; if ((output.node.kind & B_BUFFER_PRODUCER) == 0) return B_MEDIA_BAD_NODE; if (IS_INVALID_SOURCE(output.source)) return B_MEDIA_BAD_SOURCE; - + producer_format_suggestion_requested_request request; producer_format_suggestion_requested_reply reply; status_t rv; - + request.type = B_MEDIA_UNKNOWN_TYPE; - request.quality = 0; // XXX what should this be? - - rv = QueryPort(output.source.port, PRODUCER_FORMAT_SUGGESTION_REQUESTED, &request, sizeof(request), &reply, sizeof(reply)); + request.quality = 0; // TODO: what should this be? + + rv = QueryPort(output.source.port, PRODUCER_FORMAT_SUGGESTION_REQUESTED, + &request, sizeof(request), &reply, sizeof(reply)); if (rv != B_OK) return rv; - *io_format = reply.format; + *_format = reply.format; return B_OK; } - -status_t -BMediaRoster::GetFormatFor(const media_input & input, - media_format * io_format, - uint32 flags) + +status_t +BMediaRoster::GetFormatFor(const media_input& input, media_format* _format, + uint32 flags) { CALLED(); - if (io_format == NULL) + if (_format == NULL) return B_BAD_VALUE; if ((input.node.kind & B_BUFFER_CONSUMER) == 0) return B_MEDIA_BAD_NODE; if (IS_INVALID_DESTINATION(input.destination)) return B_MEDIA_BAD_DESTINATION; - + consumer_accept_format_request request; consumer_accept_format_reply reply; status_t rv; - + request.dest = input.destination; memset(&request.format, 0, sizeof(request.format)); // wildcard - rv = QueryPort(input.destination.port, CONSUMER_ACCEPT_FORMAT, &request, sizeof(request), &reply, sizeof(reply)); + rv = QueryPort(input.destination.port, CONSUMER_ACCEPT_FORMAT, &request, + sizeof(request), &reply, sizeof(reply)); if (rv != B_OK) return rv; - *io_format = reply.format; + *_format = reply.format; return B_OK; } -status_t -BMediaRoster::GetFormatFor(const media_node & node, - media_format * io_format, - float quality) +status_t +BMediaRoster::GetFormatFor(const media_node& node, media_format* _format, + float quality) { UNIMPLEMENTED(); - if (io_format == NULL) + if (_format == NULL) return B_BAD_VALUE; if (IS_INVALID_NODE(node)) return B_MEDIA_BAD_NODE; if ((node.kind & (B_BUFFER_CONSUMER | B_BUFFER_PRODUCER)) == 0) return B_MEDIA_BAD_NODE; - return B_ERROR; } - -ssize_t -BMediaRoster::GetNodeAttributesFor(const media_node & node, - media_node_attribute * outArray, - size_t inMaxCount) + +ssize_t +BMediaRoster::GetNodeAttributesFor(const media_node& node, + media_node_attribute* _array, size_t maxCount) { UNIMPLEMENTED(); return B_ERROR; } - -media_node_id -BMediaRoster::NodeIDFor(port_id source_or_destination_port) + +media_node_id +BMediaRoster::NodeIDFor(port_id port) { CALLED(); - + server_node_id_for_request request; server_node_id_for_reply reply; status_t rv; - request.port = source_or_destination_port; - - rv = QueryServer(SERVER_NODE_ID_FOR, &request, sizeof(request), &reply, sizeof(reply)); + request.port = port; + + rv = QueryServer(SERVER_NODE_ID_FOR, &request, sizeof(request), &reply, + sizeof(reply)); if (rv != B_OK) { ERROR("BMediaRoster::NodeIDFor: failed (error %#lx)\n", rv); return -1; } - + return reply.nodeid; } -status_t -BMediaRoster::GetInstancesFor(media_addon_id addon, - int32 flavor, - media_node_id * out_id, - int32 * io_count) +status_t +BMediaRoster::GetInstancesFor(media_addon_id addon, int32 flavor, + media_node_id* _id, int32* _count) { CALLED(); - if (out_id == NULL) + if (_id == NULL) return B_BAD_VALUE; - if (io_count && *io_count <= 0) + if (_count && *_count <= 0) return B_BAD_VALUE; server_get_instances_for_request request; server_get_instances_for_reply reply; status_t rv; - request.maxcount = (io_count ? *io_count : 1); + request.maxcount = (_count ? *_count : 1); request.addon_id = addon; request.addon_flavor_id = flavor; - rv = QueryServer(SERVER_GET_INSTANCES_FOR, &request, sizeof(request), &reply, sizeof(reply)); + rv = QueryServer(SERVER_GET_INSTANCES_FOR, &request, sizeof(request), + &reply, sizeof(reply)); if (rv != B_OK) { ERROR("BMediaRoster::GetLiveNodes failed\n"); return rv; } - if (io_count) - *io_count = reply.count; + if (_count) + *_count = reply.count; if (reply.count > 0) - memcpy(out_id, reply.node_id, sizeof(media_node_id) * reply.count); + memcpy(_id, reply.node_id, sizeof(media_node_id) * reply.count); return B_OK; } -status_t -BMediaRoster::SetRealtimeFlags(uint32 in_enabled) +status_t +BMediaRoster::SetRealtimeFlags(uint32 enabled) { UNIMPLEMENTED(); return B_ERROR; } -status_t -BMediaRoster::GetRealtimeFlags(uint32 * out_enabled) +status_t +BMediaRoster::GetRealtimeFlags(uint32* _enabled) { UNIMPLEMENTED(); return B_ERROR; } -ssize_t -BMediaRoster::AudioBufferSizeFor(int32 channel_count, - uint32 sample_format, - float frame_rate, - bus_type bus_kind) +ssize_t +BMediaRoster::AudioBufferSizeFor(int32 channelCount, uint32 sampleFormat, + float frameRate, bus_type busKind) { - bigtime_t buffer_duration; - ssize_t buffer_size; + bigtime_t bufferDuration; + ssize_t bufferSize; system_info info; get_system_info(&info); - - if (info.cpu_clock_speed > 2000000000) - buffer_duration = 2500; + + if (info.cpu_clock_speed > 2000000000) // 2 GHz + bufferDuration = 2500; else if (info.cpu_clock_speed > 1000000000) - buffer_duration = 5000; + bufferDuration = 5000; else if (info.cpu_clock_speed > 600000000) - buffer_duration = 10000; + bufferDuration = 10000; else if (info.cpu_clock_speed > 200000000) - buffer_duration = 20000; + bufferDuration = 20000; else if (info.cpu_clock_speed > 100000000) - buffer_duration = 30000; + bufferDuration = 30000; else - buffer_duration = 50000; - - if ((bus_kind == B_ISA_BUS || bus_kind == B_PCMCIA_BUS) && buffer_duration < 25000) - buffer_duration = 25000; - - buffer_size = (sample_format & 0xf) * channel_count * (ssize_t)((frame_rate * buffer_duration) / 1000000.0); + bufferDuration = 50000; - printf("Suggested buffer duration %Ld, size %ld\n", buffer_duration, buffer_size); + if ((busKind == B_ISA_BUS || busKind == B_PCMCIA_BUS) + && bufferDuration < 25000) + bufferDuration = 25000; - return buffer_size; + bufferSize = (sampleFormat & 0xf) * channelCount + * (ssize_t)((frameRate * bufferDuration) / 1000000.0); + + printf("Suggested buffer duration %Ld, size %ld\n", bufferDuration, + bufferSize); + + return bufferSize; } - -/* Use MediaFlags to inquire about specific features of the Media Kit. */ -/* Returns < 0 for "not present", positive size for output data size. */ -/* 0 means that the capability is present, but no data about it. */ -/* static */ ssize_t -BMediaRoster::MediaFlags(media_flags cap, - void * buf, - size_t maxSize) + +/*! Use MediaFlags to inquire about specific features of the Media Kit. + Returns < 0 for "not present", positive size for output data size. + 0 means that the capability is present, but no data about it. +*/ +/*static*/ ssize_t +BMediaRoster::MediaFlags(media_flags cap, void* buffer, size_t maxSize) { UNIMPLEMENTED(); return 0; } -/* BLooper overrides */ -/* virtual */ void -BMediaRoster::MessageReceived(BMessage * message) +// #pragma mark - BLooper overrides + + +void +BMediaRoster::MessageReceived(BMessage* message) { switch (message->what) { case 'PING': @@ -2951,9 +3104,9 @@ BMediaRoster::MessageReceived(BMessage * message) // this function is called by a BMediaNode to delete // itself, as this needs to be done from another thread // context, it is done here. - // XXX If a node is released using BMediaRoster::ReleaseNode() - // XXX instead of using BMediaNode::Release() / BMediaNode::Acquire() - // XXX fRefCount of the BMediaNode will not be correct. + // TODO: If a node is released using BMediaRoster::ReleaseNode() + // TODO: instead of using BMediaNode::Release() / BMediaNode::Acquire() + // TODO: fRefCount of the BMediaNode will not be correct. BMediaNode *node; message->FindPointer("node", reinterpret_cast(&node)); @@ -2970,26 +3123,25 @@ BMediaRoster::MessageReceived(BMessage * message) message->PrintToStream(); } -/* virtual */ bool + +bool BMediaRoster::QuitRequested() { UNIMPLEMENTED(); return true; } -/* virtual */ BHandler * -BMediaRoster::ResolveSpecifier(BMessage *msg, - int32 index, - BMessage *specifier, - int32 form, - const char *property) + +BHandler* +BMediaRoster::ResolveSpecifier(BMessage* msg, int32 index, BMessage* specifier, + int32 form, const char* property) { return BLooper::ResolveSpecifier(msg, index, specifier, form, property); -} +} -/* virtual */ status_t -BMediaRoster::GetSupportedSuites(BMessage *data) +status_t +BMediaRoster::GetSupportedSuites(BMessage* data) { return BLooper::GetSupportedSuites(data); } @@ -2998,12 +3150,13 @@ BMediaRoster::GetSupportedSuites(BMessage *data) BMediaRoster::~BMediaRoster() { CALLED(); - + // unregister this application with the media server server_unregister_app_request request; server_unregister_app_reply reply; request.team = team; - QueryServer(SERVER_UNREGISTER_APP, &request, sizeof(request), &reply, sizeof(reply)); + QueryServer(SERVER_UNREGISTER_APP, &request, sizeof(request), &reply, + sizeof(reply)); // Unset the global instance pointer, the destructor is also called // if a client app calls Lock(); and Quit(); directly. @@ -3011,23 +3164,21 @@ BMediaRoster::~BMediaRoster() } -/************************************************************* - * private BMediaRoster - *************************************************************/ +// #pragma mark - private BMediaRoster + // deprecated call -status_t -BMediaRoster::SetOutputBuffersFor(const media_source & output, - BBufferGroup * group, - bool will_reclaim ) +status_t +BMediaRoster::SetOutputBuffersFor(const media_source& output, + BBufferGroup* group, bool willReclaim) { UNIMPLEMENTED(); debugger("BMediaRoster::SetOutputBuffersFor missing\n"); return B_ERROR; } - -/* FBC stuffing (Mmmh, Stuffing!) */ + +/* FBC reserved virtuals */ status_t BMediaRoster::_Reserved_MediaRoster_0(void *) { return B_ERROR; } status_t BMediaRoster::_Reserved_MediaRoster_1(void *) { return B_ERROR; } status_t BMediaRoster::_Reserved_MediaRoster_2(void *) { return B_ERROR; } @@ -3038,38 +3189,37 @@ status_t BMediaRoster::_Reserved_MediaRoster_6(void *) { return B_ERROR; } status_t BMediaRoster::_Reserved_MediaRoster_7(void *) { return B_ERROR; } -BMediaRoster::BMediaRoster() : - BLooper("_BMediaRoster_", B_URGENT_DISPLAY_PRIORITY, B_LOOPER_PORT_DEFAULT_CAPACITY) +BMediaRoster::BMediaRoster() + : BLooper("_BMediaRoster_", B_URGENT_DISPLAY_PRIORITY, + B_LOOPER_PORT_DEFAULT_CAPACITY) { CALLED(); - + // start the looper Run(); } // TODO: Looks like these can be safely removed: -/* static */ status_t -BMediaRoster::ParseCommand(BMessage & reply) +/*static*/ status_t +BMediaRoster::ParseCommand(BMessage& reply) { UNIMPLEMENTED(); return B_ERROR; } -status_t -BMediaRoster::GetDefaultInfo(media_node_id for_default, - BMessage & out_config) +status_t +BMediaRoster::GetDefaultInfo(media_node_id forDefault, BMessage& config) { UNIMPLEMENTED(); return B_ERROR; } - - -status_t -BMediaRoster::SetRunningDefault(media_node_id for_default, - const media_node & node) + +status_t +BMediaRoster::SetRunningDefault(media_node_id forDefault, + const media_node& node) { UNIMPLEMENTED(); return B_ERROR; diff --git a/src/kits/media/ParameterWeb.cpp b/src/kits/media/ParameterWeb.cpp index ac2b773db3..e2cc3078bf 100644 --- a/src/kits/media/ParameterWeb.cpp +++ b/src/kits/media/ParameterWeb.cpp @@ -15,13 +15,14 @@ #include #include +#include #include -#include -#include "DataExchange.h" -#include "MediaMisc.h" +#include +#include "DataExchange.h" #include "debug.h" +#include "MediaMisc.h" /* @@ -422,14 +423,22 @@ BParameterWeb::ParameterAt(int32 index) status_t BParameterWeb::StartWatching(const BMessenger& target, int32 notificationType) { - return B_ERROR; + if (BMediaRoster::CurrentRoster() == NULL) + return B_ERROR; + + return BMediaRoster::CurrentRoster()->StartWatching(target, fNode, + notificationType); } status_t BParameterWeb::StopWatching(const BMessenger& target, int32 notificationType) { - return B_ERROR; + if (BMediaRoster::CurrentRoster() == NULL) + return B_ERROR; + + return BMediaRoster::CurrentRoster()->StopWatching(target, fNode, + notificationType); } @@ -1285,11 +1294,11 @@ BParameter::GetValue(void* buffer, size_t* _size, bigtime_t* _when) } } else { area = -1; - data = reply.rawdata; + data = reply.raw_data; } request.parameter_id = fID; - request.requestsize = size; + request.request_size = size; request.area = area; status_t status = QueryPort(node.port, CONTROLLABLE_GET_PARAMETER_DATA, @@ -1356,7 +1365,7 @@ BParameter::SetValue(const void* buffer, size_t size, bigtime_t when) } } else { area = -1; - data = request.rawdata; + data = request.raw_data; } memcpy(data, buffer, size);