From a67786727aa5214387d110ffe21716ec7c322f8f Mon Sep 17 00:00:00 2001
From: Dario Casalinuovo <b.vitruvio@gmail.com>
Date: Tue, 17 Feb 2015 01:27:11 +0100
Subject: [PATCH 2/2] Implement BMediaRoster::SyncToNode.
---
headers/private/media/ServerInterface.h | 5 +++++
src/kits/media/MediaEventLooper.cpp | 12 +++++++++--
src/kits/media/MediaNode.cpp | 37 ++++++++++++++++++++++++++-------
src/kits/media/MediaRoster.cpp | 29 ++++++++++++++++++++++++--
4 files changed, 72 insertions(+), 11 deletions(-)
diff --git a/headers/private/media/ServerInterface.h b/headers/private/media/ServerInterface.h
index 13249eb..d3ddafb 100644
a
|
b
|
enum {
|
89 | 89 | NODE_TIME_WARP, |
90 | 90 | NODE_PREROLL, |
91 | 91 | NODE_ROLL, |
| 92 | NODE_SYNC_TO, |
92 | 93 | NODE_SET_TIMESOURCE, |
93 | 94 | NODE_GET_TIMESOURCE, |
94 | 95 | NODE_REQUEST_COMPLETED, |
… |
… |
struct node_get_timesource_reply : reply_data {
|
929 | 930 | struct node_final_release_command : command_data { |
930 | 931 | }; |
931 | 932 | |
| 933 | struct node_sync_to_command : command_data { |
| 934 | bigtime_t performance_time; |
| 935 | port_id port; |
| 936 | }; |
932 | 937 | |
933 | 938 | // #pragma mark - time source commands |
934 | 939 | |
diff --git a/src/kits/media/MediaEventLooper.cpp b/src/kits/media/MediaEventLooper.cpp
index fa79e52..ce30c2a 100644
a
|
b
|
BMediaEventLooper::AddTimer(bigtime_t at_performance_time,
|
157 | 157 | int32 cookie) |
158 | 158 | { |
159 | 159 | CALLED(); |
160 | | // XXX what do we need to do here? |
161 | | return BMediaNode::AddTimer(at_performance_time,cookie); |
| 160 | |
| 161 | media_timed_event event(at_performance_time, |
| 162 | BTimedEventQueue::B_TIMER, NULL, |
| 163 | BTimedEventQueue::B_EXPIRE_TIMER); |
| 164 | event.data = cookie; |
| 165 | return EventQueue()->AddEvent(event); |
162 | 166 | } |
163 | 167 | |
164 | 168 | |
… |
… |
BMediaEventLooper::DispatchEvent(const media_timed_event *event,
|
477 | 481 | /* nothing */ |
478 | 482 | break; |
479 | 483 | |
| 484 | case BTimedEventQueue::B_TIMER: |
| 485 | TimerExpired(TimeSource()->Now(), event->data); |
| 486 | break; |
| 487 | |
480 | 488 | default: |
481 | 489 | break; |
482 | 490 | } |
diff --git a/src/kits/media/MediaNode.cpp b/src/kits/media/MediaNode.cpp
index 77319ae..e19aff0 100644
a
|
b
|
|
1 | 1 | /* |
2 | 2 | * Copyright (c) 2002, 2003 Marcus Overhagen <Marcus@Overhagen.de> |
| 3 | * Copyright (c) 2015, Dario Casalinuovo |
3 | 4 | * |
4 | 5 | * Permission is hereby granted, free of charge, to any person obtaining |
5 | 6 | * a copy of this software and associated documentation files or portions |
… |
… |
BMediaNode::NodeStopped(bigtime_t whenPerformance)
|
327 | 328 | } |
328 | 329 | |
329 | 330 | |
| 331 | /* |
| 332 | * Used with AddTimer |
| 333 | * This will, in turn, cause the BMediaRoster::SyncToNode() call |
| 334 | * that instigated the timer to return to the caller. |
| 335 | */ |
330 | 336 | void |
331 | 337 | BMediaNode::TimerExpired(bigtime_t notifyPoint, |
332 | 338 | int32 cookie, |
333 | 339 | status_t error) |
334 | 340 | { |
335 | | UNIMPLEMENTED(); |
336 | | // Used with AddTimer |
337 | | // This will, in turn, cause the BMediaRoster::SyncToNode() call |
338 | | // that instigated the timer to return to the caller. |
339 | | // Probably only important to classes derived from BTimeSource. |
| 341 | CALLED(); |
| 342 | port_id port = (port_id) cookie; |
| 343 | int32 reply = 1; |
| 344 | write_port(port, NODE_SYNC_TO, &reply, sizeof(reply)); |
340 | 345 | } |
341 | 346 | |
342 | 347 | |
… |
… |
BMediaNode::HandleMessage(int32 message,
|
696 | 701 | return B_OK; |
697 | 702 | } |
698 | 703 | |
| 704 | case NODE_SYNC_TO: |
| 705 | { |
| 706 | const node_sync_to_command *command |
| 707 | = static_cast<const node_sync_to_command *>(data); |
| 708 | |
| 709 | TRACE("BMediaNode::HandleMessage NODE_SYNC_TO, node %ld\n", |
| 710 | fNodeID); |
| 711 | |
| 712 | if (AddTimer(command->performance_time, command->port) != B_OK) { |
| 713 | // When AddTimer return an error we will notify the caller |
| 714 | // that the node doesn't support this feature or there was |
| 715 | // a problem when adding the time, this will result in |
| 716 | // SyncToNode returning immediately to the caller with an error. |
| 717 | int32 reply = -1; |
| 718 | write_port(command->port, NODE_SYNC_TO, &reply, sizeof(reply)); |
| 719 | } |
| 720 | return B_OK; |
| 721 | } |
| 722 | |
699 | 723 | }; |
700 | 724 | return B_ERROR; |
701 | 725 | } |
… |
… |
BMediaNode::GetNodeAttributes(media_node_attribute *outAttributes,
|
878 | 902 | BMediaNode::AddTimer(bigtime_t at_performance_time, |
879 | 903 | int32 cookie) |
880 | 904 | { |
881 | | UNIMPLEMENTED(); |
882 | | |
| 905 | CALLED(); |
883 | 906 | return B_ERROR; |
884 | 907 | } |
885 | 908 | |
diff --git a/src/kits/media/MediaRoster.cpp b/src/kits/media/MediaRoster.cpp
index 8201be0..099dccb 100644
a
|
b
|
|
1 | 1 | /* |
2 | 2 | * Copyright 2008 Maurice Kalinowski, haiku@kaldience.com |
3 | 3 | * Copyright 2009-2012, Axel Dörfler, axeld@pinc-software.de. |
| 4 | * Copyright 2015 Dario Casalinuovo, b.vitruvio@gmail.com |
4 | 5 | * |
5 | 6 | * All rights reserved. Distributed under the terms of the MIT License. |
6 | 7 | */ |
… |
… |
status_t
|
1364 | 1365 | BMediaRoster::SyncToNode(const media_node& node, bigtime_t atTime, |
1365 | 1366 | bigtime_t timeout) |
1366 | 1367 | { |
1367 | | UNIMPLEMENTED(); |
1368 | | return B_OK; |
| 1368 | TRACE("BMediaRoster::SyncToNode, node %" B_PRId32 ", at real %" B_PRId64 |
| 1369 | ", at timeout %" B_PRId64 "\n", node.node, atTime, timeout); |
| 1370 | if (IS_INVALID_NODE(node)) |
| 1371 | return B_MEDIA_BAD_NODE; |
| 1372 | |
| 1373 | port_id wait_port = create_port(1, "SyncToNode wait port"); |
| 1374 | if (wait_port < 0) |
| 1375 | return wait_port; |
| 1376 | |
| 1377 | node_sync_to_command command; |
| 1378 | command.performance_time = atTime; |
| 1379 | command.port = wait_port; |
| 1380 | status_t status = write_port(node.port, |
| 1381 | NODE_SYNC_TO, &command, sizeof(command)); |
| 1382 | if (status == B_OK) { |
| 1383 | int32 code, reply = 0; |
| 1384 | ssize_t size = read_port_etc(wait_port, &code, &reply, sizeof(reply), |
| 1385 | B_TIMEOUT, timeout); |
| 1386 | if (size < 0) |
| 1387 | status = size; |
| 1388 | else if (code != NODE_SYNC_TO || reply != 1) |
| 1389 | status = B_ERROR; |
| 1390 | } |
| 1391 | close_port(wait_port); |
| 1392 | delete_port(wait_port); |
| 1393 | return status; |
1369 | 1394 | } |
1370 | 1395 | |
1371 | 1396 | |