From dbb12bcc711fd15a6c91fdb678ad72c8cf7e380b Mon Sep 17 00:00:00 2001
From: Dario Casalinuovo <b.vitruvio@gmail.com>
Date: Thu, 9 Apr 2015 11:22:06 +0200
Subject: [PATCH 2/2] Implement BMediaRoster::SyncToNode.
---
headers/private/media/ServerInterface.h | 9 ++++++++
src/kits/media/MediaEventLooper.cpp | 12 ++++++++--
src/kits/media/MediaNode.cpp | 39 +++++++++++++++++++++++++++------
src/kits/media/MediaRoster.cpp | 31 +++++++++++++++++++++++---
4 files changed, 79 insertions(+), 12 deletions(-)
diff --git a/headers/private/media/ServerInterface.h b/headers/private/media/ServerInterface.h
index 13249eb..d2551c0 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 | }; |
| 917 | |
909 | 918 | struct node_set_run_mode_command : command_data { |
910 | 919 | BMediaNode::run_mode mode; |
911 | 920 | }; |
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..8ff64f4 100644
a
|
b
|
|
1 | 1 | /* |
| 2 | * Copyright (c) 2015, Dario Casalinuovo |
2 | 3 | * Copyright (c) 2002, 2003 Marcus Overhagen <Marcus@Overhagen.de> |
3 | 4 | * |
4 | 5 | * Permission is hereby granted, free of charge, to any person obtaining |
… |
… |
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 | if (write_port((port_id)cookie, 0, &error, sizeof(error)) < 0) { |
| 343 | TRACE("BMediaNode::TimerExpired: error writing port" B_PRId32 |
| 344 | ", at notifyPoint" B_PRId64 "\n", cookie, notifyPoint); |
| 345 | } |
340 | 346 | } |
341 | 347 | |
342 | 348 | |
… |
… |
BMediaNode::HandleMessage(int32 message,
|
649 | 655 | return B_OK; |
650 | 656 | } |
651 | 657 | |
| 658 | case NODE_SYNC_TO: |
| 659 | { |
| 660 | const node_sync_to_request *request |
| 661 | = static_cast<const node_sync_to_request *>(data); |
| 662 | node_sync_to_reply reply; |
| 663 | |
| 664 | TRACE("BMediaNode::HandleMessage NODE_SYNC_TO, node %ld\n", |
| 665 | fNodeID); |
| 666 | |
| 667 | // If AddTimer return an error the caller will know that the node |
| 668 | // doesn't support this feature or there was a problem when adding |
| 669 | // it, this will result in SyncToNode returning immediately |
| 670 | // to the caller with an error. |
| 671 | status_t status = AddTimer(request->performance_time, |
| 672 | request->port); |
| 673 | |
| 674 | request->SendReply(status, &reply, sizeof(reply)); |
| 675 | return B_OK; |
| 676 | } |
| 677 | |
652 | 678 | case NODE_SET_TIMESOURCE: |
653 | 679 | { |
654 | 680 | const node_set_timesource_command *command = static_cast<const node_set_timesource_command *>(data); |
… |
… |
BMediaNode::GetNodeAttributes(media_node_attribute *outAttributes,
|
878 | 904 | BMediaNode::AddTimer(bigtime_t at_performance_time, |
879 | 905 | int32 cookie) |
880 | 906 | { |
881 | | UNIMPLEMENTED(); |
882 | | |
| 907 | CALLED(); |
883 | 908 | return B_ERROR; |
884 | 909 | } |
885 | 910 | |
diff --git a/src/kits/media/MediaRoster.cpp b/src/kits/media/MediaRoster.cpp
index 8201be0..eb25312 100644
a
|
b
|
|
1 | 1 | /* |
2 | | * Copyright 2008 Maurice Kalinowski, haiku@kaldience.com |
| 2 | * Copyright 2015 Dario Casalinuovo, b.vitruvio@gmail.com |
3 | 3 | * Copyright 2009-2012, Axel Dörfler, axeld@pinc-software.de. |
| 4 | * Copyright 2008 Maurice Kalinowski, haiku@kaldience.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 | ssize_t readSize = read_port_etc(waitPort, NULL, &status, |
| 1387 | sizeof(status), B_TIMEOUT, timeout); |
| 1388 | if (readSize < 0) |
| 1389 | status = readSize; |
| 1390 | } |
| 1391 | close_port(waitPort); |
| 1392 | delete_port(waitPort); |
| 1393 | return status; |
1369 | 1394 | } |
1370 | 1395 | |
1371 | 1396 | |