1 /* 2 * Copyright 2002, Marcus Overhagen. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 #ifndef _DATA_EXCHANGE_H 7 #define _DATA_EXCHANGE_H 8 9 #include <MediaDefs.h> 10 #include <MediaNode.h> 11 #include <MediaAddOn.h> 12 #include <Messenger.h> 13 #include <Buffer.h> 14 #include <Entry.h> 15 16 namespace BPrivate { 17 namespace media { 18 namespace dataexchange { 19 20 struct reply_data; 21 struct request_data; 22 struct command_data; 23 24 // BMessage based data exchange with the media_server 25 status_t SendToServer(BMessage *msg); 26 27 // Raw data based data exchange with the media_server 28 status_t SendToServer(int32 msgcode, command_data *msg, int size); 29 status_t QueryServer(int32 msgcode, request_data *request, int requestsize, reply_data *reply, int replysize); 30 31 // Raw data based data exchange with the media_addon_server 32 status_t SendToAddonServer(int32 msgcode, command_data *msg, int size); 33 status_t QueryAddonServer(int32 msgcode, request_data *request, int requestsize, reply_data *reply, int replysize); 34 35 // Raw data based data exchange with any (media node control-) port 36 status_t SendToPort(port_id sendport, int32 msgcode, command_data *msg, int size); 37 status_t QueryPort(port_id requestport, int32 msgcode, request_data *request, int requestsize, reply_data *reply, int replysize); 38 39 // The base struct used for all raw requests 40 struct request_data 41 { 42 port_id reply_port; 43 44 status_t SendReply(status_t result, reply_data *reply, int replysize) const; 45 }; 46 47 // The base struct used for all raw replys 48 struct reply_data 49 { 50 status_t result; 51 }; 52 53 // The base struct used for all raw commands (asynchronous, no answer) 54 struct command_data 55 { 56 // yes, it's empty ;) 57 }; 58 59 }; // dataexchange 60 }; // media 61 }; // BPrivate 62 63 using namespace BPrivate::media::dataexchange; 64 65 // BMessage based server communication 66 enum { 67 68 // BMediaRoster notification service 69 MEDIA_SERVER_REQUEST_NOTIFICATIONS = 1000, 70 MEDIA_SERVER_CANCEL_NOTIFICATIONS, 71 MEDIA_SERVER_SEND_NOTIFICATIONS 72 73 }; 74 75 // Raw port based communication 76 enum { 77 ADDONSERVER_RESCAN_MEDIAADDON_FLAVORS = 0x50, 78 79 SERVER_MESSAGE_START = 0x100, 80 SERVER_REGISTER_ADDONSERVER, 81 SERVER_REGISTER_APP, 82 SERVER_UNREGISTER_APP, 83 SERVER_GET_NODE, 84 SERVER_SET_NODE, 85 SERVER_PUBLISH_INPUTS, 86 SERVER_PUBLISH_OUTPUTS, 87 SERVER_NODE_ID_FOR, 88 SERVER_GET_LIVE_NODE_INFO, 89 SERVER_GET_LIVE_NODES, 90 SERVER_GET_NODE_FOR, 91 SERVER_RELEASE_NODE, 92 SERVER_REGISTER_NODE, 93 SERVER_UNREGISTER_NODE, 94 SERVER_GET_DORMANT_NODE_FOR, 95 SERVER_GET_INSTANCES_FOR, 96 SERVER_GET_SHARED_BUFFER_AREA, 97 SERVER_REGISTER_BUFFER, 98 SERVER_UNREGISTER_BUFFER, 99 SERVER_RESCAN_DEFAULTS, 100 SERVER_SET_NODE_CREATOR, 101 SERVER_CHANGE_ADDON_FLAVOR_INSTANCES_COUNT, 102 SERVER_MESSAGE_END, 103 NODE_MESSAGE_START = 0x200, 104 105 NODE_START, 106 NODE_STOP, 107 NODE_SEEK, 108 NODE_SET_RUN_MODE, 109 NODE_TIME_WARP, 110 NODE_PREROLL, 111 NODE_SET_TIMESOURCE, 112 NODE_GET_TIMESOURCE, 113 NODE_REQUEST_COMPLETED, 114 NODE_FINAL_RELEASE, 115 116 NODE_MESSAGE_END, 117 CONSUMER_MESSAGE_START = 0x300, 118 CONSUMER_GET_NEXT_INPUT, 119 CONSUMER_DISPOSE_INPUT_COOKIE, 120 CONSUMER_ACCEPT_FORMAT, 121 CONSUMER_CONNECTED, 122 CONSUMER_DISCONNECTED, 123 124 CONSUMER_BUFFER_RECEIVED, 125 CONSUMER_PRODUCER_DATA_STATUS, 126 CONSUMER_GET_LATENCY_FOR, 127 CONSUMER_FORMAT_CHANGED, 128 CONSUMER_SEEK_TAG_REQUESTED, 129 130 CONSUMER_MESSAGE_END, 131 PRODUCER_MESSAGE_START = 0x400, 132 PRODUCER_GET_NEXT_OUTPUT, 133 PRODUCER_DISPOSE_OUTPUT_COOKIE, 134 PRODUCER_FORMAT_PROPOSAL, 135 PRODUCER_PREPARE_TO_CONNECT, 136 PRODUCER_CONNECT, 137 PRODUCER_DISCONNECT, 138 139 PRODUCER_LATE_NOTICE_RECEIVED, 140 PRODUCER_LATENCY_CHANGED, 141 PRODUCER_ADDITIONAL_BUFFER_REQUESTED, 142 PRODUCER_VIDEO_CLIPPING_CHANGED, 143 PRODUCER_FORMAT_CHANGE_REQUESTED, 144 PRODUCER_SET_BUFFER_GROUP, 145 PRODUCER_GET_LATENCY, 146 PRODUCER_GET_INITIAL_LATENCY, 147 PRODUCER_FORMAT_SUGGESTION_REQUESTED, 148 PRODUCER_SET_PLAY_RATE, 149 PRODUCER_ENABLE_OUTPUT, 150 PRODUCER_SET_RUN_MODE_DELAY, 151 152 PRODUCER_MESSAGE_END, 153 FILEINTERFACE_MESSAGE_START = 0x500, 154 FILEINTERFACE_MESSAGE_END, 155 CONTROLLABLE_MESSAGE_START = 0x600, 156 CONTROLLABLE_GET_PARAMETER_WEB, 157 CONTROLLABLE_GET_PARAMETER_DATA, 158 CONTROLLABLE_SET_PARAMETER_DATA, 159 CONTROLLABLE_MESSAGE_END, 160 TIMESOURCE_MESSAGE_START = 0x700, 161 162 TIMESOURCE_OP, // datablock is a struct time_source_op_info 163 TIMESOURCE_ADD_SLAVE_NODE, 164 TIMESOURCE_REMOVE_SLAVE_NODE, 165 166 TIMESOURCE_MESSAGE_END, 167 }; 168 169 170 /* We can't send an entry_ref through a port to another team, 171 * but we can assign it to an xfer_entry_ref and send this one, 172 * when we receive it we can assign it to a normal entry_ref 173 */ 174 struct xfer_entry_ref 175 { 176 public: 177 xfer_entry_ref() 178 { 179 device = -1; 180 directory = -1; 181 name[0] = 0; 182 } 183 operator entry_ref() const 184 { 185 entry_ref ref(device, directory, name); 186 return ref; 187 } 188 void operator=(const entry_ref &ref) 189 { 190 device = ref.device; 191 directory = ref.directory; 192 strcpy(name, ref.name); 193 } 194 private: 195 dev_t device; 196 ino_t directory; 197 char name[B_FILE_NAME_LENGTH]; 198 }; 199 200 201 202 // used by SERVER_GET_NODE and SERVER_SET_NODE 203 enum node_type 204 { 205 VIDEO_INPUT, 206 AUDIO_INPUT, 207 VIDEO_OUTPUT, 208 AUDIO_MIXER, 209 AUDIO_OUTPUT, 210 AUDIO_OUTPUT_EX, 211 TIME_SOURCE, 212 SYSTEM_TIME_SOURCE 213 }; 214 215 // used by SERVER_PUBLISH_INPUTS and SERVER_PUBLISH_OUTPUTS 216 enum 217 { 218 MAX_OUTPUTS = 8, 219 MAX_INPUTS = 8, 220 }; 221 222 // used by SERVER_GET_LIVE_NODES 223 enum 224 { 225 MAX_LIVE_INFO = 16, 226 }; 227 228 // used by SERVER_GET_INSTANCES_FOR 229 enum 230 { 231 MAX_NODE_ID = 4000, 232 }; 233 234 struct addonserver_instantiate_dormant_node_request : public request_data 235 { 236 media_addon_id addonid; 237 int32 flavorid; 238 team_id creator_team; 239 }; 240 241 struct addonserver_instantiate_dormant_node_reply : public reply_data 242 { 243 media_node node; 244 }; 245 246 struct server_set_node_request : public request_data 247 { 248 node_type type; 249 bool use_node; 250 media_node node; 251 bool use_dni; 252 dormant_node_info dni; 253 bool use_input; 254 media_input input; 255 }; 256 257 struct server_set_node_reply : public reply_data 258 { 259 }; 260 261 struct server_get_node_request : public request_data 262 { 263 node_type type; 264 team_id team; 265 }; 266 267 struct server_get_node_reply : public reply_data 268 { 269 media_node node; 270 271 // for AUDIO_OUTPUT_EX 272 char input_name[B_MEDIA_NAME_LENGTH]; 273 int32 input_id; 274 }; 275 276 struct producer_format_proposal_request : public request_data 277 { 278 media_source output; 279 media_format format; 280 }; 281 282 struct producer_format_proposal_reply : public reply_data 283 { 284 media_format format; 285 }; 286 287 struct producer_prepare_to_connect_request : public request_data 288 { 289 media_source source; 290 media_destination destination; 291 media_format format; 292 char name[B_MEDIA_NAME_LENGTH]; 293 }; 294 295 struct producer_prepare_to_connect_reply : public reply_data 296 { 297 media_format format; 298 media_source out_source; 299 char name[B_MEDIA_NAME_LENGTH]; 300 }; 301 302 struct producer_connect_request : public request_data 303 { 304 status_t error; 305 media_source source; 306 media_destination destination; 307 media_format format; 308 char name[B_MEDIA_NAME_LENGTH]; 309 }; 310 311 struct producer_connect_reply : public reply_data 312 { 313 char name[B_MEDIA_NAME_LENGTH]; 314 }; 315 316 struct producer_disconnect_request : public request_data 317 { 318 media_source source; 319 media_destination destination; 320 }; 321 322 struct producer_disconnect_reply : public reply_data 323 { 324 }; 325 326 struct producer_format_suggestion_requested_request : public request_data 327 { 328 media_type type; 329 int32 quality; 330 }; 331 332 struct producer_format_suggestion_requested_reply : public reply_data 333 { 334 media_format format; 335 }; 336 337 struct producer_set_play_rate_request : public request_data 338 { 339 int32 numer; 340 int32 denom; 341 }; 342 343 struct producer_set_play_rate_reply : public reply_data 344 { 345 }; 346 347 struct producer_get_initial_latency_request : public request_data 348 { 349 }; 350 351 struct producer_get_initial_latency_reply : public reply_data 352 { 353 bigtime_t initial_latency; 354 uint32 flags; 355 }; 356 357 struct producer_get_latency_request : public request_data 358 { 359 }; 360 361 struct producer_get_latency_reply : public reply_data 362 { 363 bigtime_t latency; 364 }; 365 366 struct producer_set_buffer_group_command : public command_data 367 { 368 media_source source; 369 media_destination destination; 370 void *user_data; 371 int32 change_tag; 372 int32 buffer_count; 373 media_buffer_id buffers[1]; 374 }; 375 376 struct producer_format_change_requested_command : public command_data 377 { 378 media_source source; 379 media_destination destination; 380 media_format format; 381 void *user_data; 382 int32 change_tag; 383 }; 384 385 struct producer_video_clipping_changed_command : public command_data 386 { 387 media_source source; 388 media_destination destination; 389 media_video_display_info display; 390 void *user_data; 391 int32 change_tag; 392 int32 short_count; 393 int16 shorts[1]; 394 }; 395 396 struct producer_additional_buffer_requested_command : public command_data 397 { 398 media_source source; 399 media_buffer_id prev_buffer; 400 bigtime_t prev_time; 401 bool has_seek_tag; 402 media_seek_tag prev_tag; 403 }; 404 405 struct producer_latency_changed_command : public command_data 406 { 407 media_source source; 408 media_destination destination; 409 bigtime_t latency; 410 uint32 flags; 411 }; 412 413 struct producer_enable_output_command : public command_data 414 { 415 media_source source; 416 media_destination destination; 417 bool enabled; 418 void *user_data; 419 int32 change_tag; 420 }; 421 422 struct producer_late_notice_received_command : public command_data 423 { 424 media_source source; 425 bigtime_t how_much; 426 bigtime_t performance_time; 427 }; 428 429 struct producer_set_run_mode_delay_command : public command_data 430 { 431 BMediaNode::run_mode mode; 432 bigtime_t delay; 433 }; 434 435 struct consumer_accept_format_request : public request_data 436 { 437 media_destination dest; 438 media_format format; 439 }; 440 441 struct consumer_accept_format_reply : public reply_data 442 { 443 media_format format; 444 }; 445 446 struct consumer_connected_request : public request_data 447 { 448 media_input input; 449 }; 450 451 struct consumer_connected_reply : public reply_data 452 { 453 media_input input; 454 }; 455 456 struct server_publish_inputs_request : public request_data 457 { 458 media_node node; 459 int32 count; 460 area_id area; // if count > MAX_INPUTS, inputs are in the area 461 // area is created in the library, and also deleted 462 // in the library after the reply has been received 463 media_input inputs[MAX_INPUTS]; 464 }; 465 466 struct server_publish_inputs_reply : public reply_data 467 { 468 }; 469 470 struct server_publish_outputs_request : public request_data 471 { 472 media_node node; 473 int32 count; 474 area_id area; // if count > MAX_OUTPUTS, outputs are in the area 475 // area is created in the library, and also deleted 476 // in the library after the reply has been received 477 media_output outputs[MAX_OUTPUTS]; 478 }; 479 480 struct server_publish_outputs_reply : public reply_data 481 { 482 }; 483 484 struct producer_get_next_output_request : public request_data 485 { 486 int32 cookie; 487 }; 488 489 struct producer_get_next_output_reply : public reply_data 490 { 491 int32 cookie; 492 media_output output; 493 }; 494 495 struct producer_dispose_output_cookie_request : public request_data 496 { 497 int32 cookie; 498 }; 499 500 struct producer_dispose_output_cookie_reply : public reply_data 501 { 502 }; 503 504 struct consumer_get_next_input_request : public request_data 505 { 506 int32 cookie; 507 }; 508 509 struct consumer_get_next_input_reply : public reply_data 510 { 511 int32 cookie; 512 media_input input; 513 }; 514 515 struct consumer_dispose_input_cookie_request : public request_data 516 { 517 int32 cookie; 518 }; 519 520 struct consumer_dispose_input_cookie_reply : public reply_data 521 { 522 }; 523 524 struct consumer_disconnected_request : public request_data 525 { 526 media_source source; 527 media_destination destination; 528 }; 529 530 struct consumer_disconnected_reply : public reply_data 531 { 532 }; 533 534 struct consumer_buffer_received_command : public command_data 535 { 536 media_buffer_id buffer; 537 media_header header; 538 }; 539 540 struct consumer_producer_data_status_command : public command_data 541 { 542 media_destination for_whom; 543 int32 status; 544 bigtime_t at_performance_time; 545 }; 546 547 struct consumer_get_latency_for_request : public request_data 548 { 549 media_destination for_whom; 550 }; 551 552 struct consumer_get_latency_for_reply : public reply_data 553 { 554 bigtime_t latency; 555 media_node_id timesource; 556 }; 557 558 struct consumer_format_changed_request : public request_data 559 { 560 media_source producer; 561 media_destination consumer; 562 int32 change_tag; 563 media_format format; 564 }; 565 566 struct consumer_format_changed_reply : public reply_data 567 { 568 }; 569 570 struct consumer_seek_tag_requested_request : public request_data 571 { 572 media_destination destination; 573 bigtime_t target_time; 574 uint32 flags; 575 }; 576 577 struct consumer_seek_tag_requested_reply : public reply_data 578 { 579 media_seek_tag seek_tag; 580 bigtime_t tagged_time; 581 uint32 flags; 582 }; 583 584 struct server_register_addonserver_request : public request_data 585 { 586 team_id team; 587 }; 588 589 struct server_register_addonserver_reply : public reply_data 590 { 591 }; 592 593 struct server_register_app_request : public request_data 594 { 595 team_id team; 596 BMessenger messenger; 597 }; 598 599 struct server_register_app_reply : public reply_data 600 { 601 }; 602 603 struct server_unregister_app_request : public request_data 604 { 605 team_id team; 606 }; 607 608 struct server_unregister_app_reply : public reply_data 609 { 610 }; 611 612 struct server_set_node_creator_request : public request_data 613 { 614 media_node_id node; 615 team_id creator; 616 }; 617 618 struct server_set_node_creator_reply : public reply_data 619 { 620 }; 621 622 struct server_change_addon_flavor_instances_count_request : public request_data 623 { 624 media_addon_id addonid; 625 int32 flavorid; 626 int32 delta; // must be +1 or -1 627 team_id team; 628 }; 629 630 struct server_change_addon_flavor_instances_count_reply : public reply_data 631 { 632 }; 633 634 struct server_register_node_request : public request_data 635 { 636 media_addon_id addon_id; 637 int32 addon_flavor_id; 638 char name[B_MEDIA_NAME_LENGTH]; 639 uint64 kinds; 640 port_id port; 641 team_id team; 642 }; 643 644 struct server_register_node_reply : public reply_data 645 { 646 media_node_id nodeid; 647 }; 648 649 struct server_unregister_node_request : public request_data 650 { 651 media_node_id nodeid; 652 team_id team; 653 }; 654 655 struct server_unregister_node_reply : public reply_data 656 { 657 media_addon_id addonid; 658 int32 flavorid; 659 }; 660 661 struct server_get_live_node_info_request : public request_data 662 { 663 media_node node; 664 }; 665 666 struct server_get_live_node_info_reply : public reply_data 667 { 668 live_node_info live_info; 669 }; 670 671 struct server_get_live_nodes_request : public request_data 672 { 673 int32 maxcount; 674 bool has_input; 675 bool has_output; 676 bool has_name; 677 media_format inputformat; 678 media_format outputformat; 679 char name[B_MEDIA_NAME_LENGTH + 1]; // 1 for a trailing "*" 680 uint64 require_kinds; 681 }; 682 683 struct server_get_live_nodes_reply : public reply_data 684 { 685 int32 count; 686 area_id area; // if count > MAX_LIVE_INFO, live_node_infos are in the area 687 // area is created in the server, but deleted in the library 688 live_node_info live_info[MAX_LIVE_INFO]; 689 }; 690 691 struct server_node_id_for_request : public request_data 692 { 693 port_id port; 694 }; 695 696 struct server_node_id_for_reply : public reply_data 697 { 698 media_node_id nodeid; 699 }; 700 701 struct server_get_node_for_request : public request_data 702 { 703 media_node_id nodeid; 704 team_id team; 705 }; 706 707 struct server_get_node_for_reply : public reply_data 708 { 709 media_node clone; 710 }; 711 712 struct server_release_node_request : public request_data 713 { 714 media_node node; 715 team_id team; 716 }; 717 718 struct server_release_node_reply : public reply_data 719 { 720 }; 721 722 struct server_get_dormant_node_for_request : public request_data 723 { 724 media_node node; 725 }; 726 727 struct server_get_dormant_node_for_reply : public reply_data 728 { 729 dormant_node_info node_info; 730 }; 731 732 struct server_get_instances_for_request : public request_data 733 { 734 int32 maxcount; 735 media_addon_id addon_id; 736 int32 addon_flavor_id; 737 }; 738 739 struct server_get_instances_for_reply : public reply_data 740 { 741 int32 count; 742 media_node_id node_id[MAX_NODE_ID]; // no area here, MAX_NODE_ID is really large 743 }; 744 745 struct server_rescan_defaults_command : public command_data 746 { 747 }; 748 749 struct addonserver_rescan_mediaaddon_flavors_command : public command_data 750 { 751 media_addon_id addonid; 752 }; 753 754 struct server_register_mediaaddon_request : public request_data 755 { 756 xfer_entry_ref ref; // a ref to the file 757 }; 758 759 struct server_register_mediaaddon_reply : public reply_data 760 { 761 media_addon_id addonid; 762 }; 763 764 struct server_unregister_mediaaddon_command : public command_data 765 { 766 media_addon_id addonid; 767 }; 768 769 struct server_get_mediaaddon_ref_request : public request_data 770 { 771 media_addon_id addonid; 772 }; 773 774 struct server_get_mediaaddon_ref_reply : public reply_data 775 { 776 xfer_entry_ref ref; // a ref to the file 777 }; 778 779 struct server_get_shared_buffer_area_request : public request_data 780 { 781 }; 782 783 struct server_get_shared_buffer_area_reply : public reply_data 784 { 785 area_id area; 786 }; 787 788 struct server_register_buffer_request : public request_data 789 { 790 team_id team; 791 //either info.buffer is != 0, or the area, size, offset is used 792 buffer_clone_info info; 793 }; 794 795 struct server_register_buffer_reply : public reply_data 796 { 797 buffer_clone_info info; 798 }; 799 800 struct server_unregister_buffer_command : public command_data 801 { 802 team_id team; 803 media_buffer_id bufferid; 804 }; 805 806 struct node_request_completed_command : public command_data 807 { 808 media_request_info info; 809 }; 810 811 struct node_start_command : public command_data 812 { 813 bigtime_t performance_time; 814 }; 815 816 struct node_stop_command : public command_data 817 { 818 bigtime_t performance_time; 819 bool immediate; 820 }; 821 822 struct node_seek_command : public command_data 823 { 824 bigtime_t media_time; 825 bigtime_t performance_time; 826 }; 827 828 struct node_set_run_mode_command : public command_data 829 { 830 BMediaNode::run_mode mode; 831 }; 832 833 struct node_time_warp_command : public command_data 834 { 835 bigtime_t at_real_time; 836 bigtime_t to_performance_time; 837 }; 838 839 struct node_set_timesource_command : public command_data 840 { 841 media_node_id timesource_id; 842 }; 843 844 struct node_get_timesource_request : public request_data 845 { 846 }; 847 848 struct node_get_timesource_reply : public reply_data 849 { 850 media_node_id timesource_id; 851 }; 852 853 struct node_final_release_command : public command_data 854 { 855 }; 856 857 struct timesource_add_slave_node_command : public command_data 858 { 859 media_node node; 860 }; 861 862 struct timesource_remove_slave_node_command : public command_data 863 { 864 media_node node; 865 }; 866 867 struct controllable_get_parameter_web_request : public request_data 868 { 869 area_id area; 870 int32 maxsize; 871 }; 872 873 struct controllable_get_parameter_web_reply : public reply_data 874 { 875 type_code code; 876 int32 size; // = -1: parameter web data too large, = 0: no p.w., > 0: flattened p.w. data 877 }; 878 879 #define MAX_PARAMETER_DATA (B_MEDIA_MESSAGE_SIZE - 100) 880 881 struct controllable_get_parameter_data_request : public request_data 882 { 883 int32 parameter_id; 884 size_t requestsize; 885 area_id area; //if area != -1, data is too large and must be passed in the area 886 }; 887 888 struct controllable_get_parameter_data_reply : public reply_data 889 { 890 bigtime_t last_change; 891 char rawdata[MAX_PARAMETER_DATA]; 892 size_t size; 893 }; 894 895 struct controllable_set_parameter_data_request : public request_data 896 { 897 int32 parameter_id; 898 bigtime_t when; 899 area_id area; //if area != -1, data is too large and is passed in the area 900 size_t size; 901 char rawdata[MAX_PARAMETER_DATA]; 902 }; 903 904 struct controllable_set_parameter_data_reply : public reply_data 905 { 906 }; 907 908 #endif // _DATA_EXCHANGE_H 909