From 8262d11c82e79f324142e872fd10e4efa97eb78e Mon Sep 17 00:00:00 2001
From: Dario Casalinuovo <b.vitruvio@gmail.com>
Date: Sat, 28 Mar 2015 15:53:44 +0100
Subject: [PATCH 02/13] Implement BMediaRoster::SyncToNode.
---
headers/private/media/ServerInterface.h | 10 +++++++++
src/kits/media/MediaEventLooper.cpp | 12 +++++++++--
src/kits/media/MediaNode.cpp | 37 ++++++++++++++++++++++++++-------
src/kits/media/MediaRoster.cpp | 33 +++++++++++++++++++++++++++--
4 files changed, 81 insertions(+), 11 deletions(-)
diff --git a/headers/private/media/ServerInterface.h b/headers/private/media/ServerInterface.h
index 13249eb..f84f3e1 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_roll_command : command_data {
|
906 | 907 | bigtime_t seek_media_time; |
907 | 908 | }; |
908 | 909 | |
| 910 | struct node_sync_to_request : request_data { |
| 911 | bigtime_t performance_time; |
| 912 | port_id port; |
| 913 | }; |
| 914 | |
| 915 | struct node_sync_to_reply : reply_data { |
| 916 | status_t status; |
| 917 | }; |
| 918 | |
909 | 919 | struct node_set_run_mode_command : command_data { |
910 | 920 | BMediaNode::run_mode mode; |
911 | 921 | }; |
diff --git a/src/kits/media/MediaEventLooper.cpp b/src/kits/media/MediaEventLooper.cpp
index fa79e52..0ce44f5 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(event->event_time, 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..f8780c0 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 in couple with AddTimer, this will cause the BMediaRoster::SyncToNode() |
| 333 | * call that requested the timer to return to the caller with an appropriate |
| 334 | * value. |
| 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 | write_port(port, 0, &error, sizeof(error)); |
340 | 344 | } |
341 | 345 | |
342 | 346 | |
… |
… |
BMediaNode::HandleMessage(int32 message,
|
649 | 653 | return B_OK; |
650 | 654 | } |
651 | 655 | |
| 656 | case NODE_SYNC_TO: |
| 657 | { |
| 658 | const node_sync_to_request *request |
| 659 | = static_cast<const node_sync_to_request *>(data); |
| 660 | node_sync_to_reply reply; |
| 661 | |
| 662 | TRACE("BMediaNode::HandleMessage NODE_SYNC_TO, node %ld\n", |
| 663 | fNodeID); |
| 664 | |
| 665 | // If AddTimer return an error the caller will know that the node |
| 666 | // doesn't support this feature or there was a problem when adding |
| 667 | // it, this will result in SyncToNode returning immediately |
| 668 | // to the caller with an error. |
| 669 | reply.status = AddTimer(request->performance_time, |
| 670 | request->port); |
| 671 | |
| 672 | request->SendReply(B_OK, &reply, sizeof(reply)); |
| 673 | return B_OK; |
| 674 | } |
| 675 | |
652 | 676 | case NODE_SET_TIMESOURCE: |
653 | 677 | { |
654 | 678 | const node_set_timesource_command *command = static_cast<const node_set_timesource_command *>(data); |
… |
… |
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..d9b7a00 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 waitPort = create_port(1, "SyncToNode wait port"); |
| 1374 | if (waitPort < B_OK) |
| 1375 | return waitPort; |
| 1376 | |
| 1377 | node_sync_to_request request; |
| 1378 | node_sync_to_reply reply; |
| 1379 | request.performance_time = atTime; |
| 1380 | request.port = waitPort; |
| 1381 | |
| 1382 | status_t status = QueryPort(node.port, NODE_SYNC_TO, &request, |
| 1383 | sizeof(request), &reply, sizeof(reply)); |
| 1384 | |
| 1385 | if (status == B_OK |
| 1386 | && reply.status == B_OK) { |
| 1387 | status_t expireResult = B_ERROR; |
| 1388 | ssize_t size = read_port_etc(waitPort, 0, &expireResult, |
| 1389 | sizeof(expireResult), B_TIMEOUT, timeout); |
| 1390 | if (size < 0) |
| 1391 | status = size; |
| 1392 | else if (expireResult != B_OK) |
| 1393 | status = expireResult; |
| 1394 | } |
| 1395 | close_port(waitPort); |
| 1396 | delete_port(waitPort); |
| 1397 | return status; |
1369 | 1398 | } |
1370 | 1399 | |
1371 | 1400 | |