Implement BMediaRoster::SyncToNode

This commit is contained in:
Dario Casalinuovo
2015-07-10 18:46:19 +02:00
parent 5720dfd49a
commit 7548648420
4 changed files with 77 additions and 11 deletions
+9
View File
@@ -90,6 +90,7 @@ enum {
NODE_TIME_WARP, NODE_TIME_WARP,
NODE_PREROLL, NODE_PREROLL,
NODE_ROLL, NODE_ROLL,
NODE_SYNC_TO,
NODE_SET_TIMESOURCE, NODE_SET_TIMESOURCE,
NODE_GET_TIMESOURCE, NODE_GET_TIMESOURCE,
NODE_REQUEST_COMPLETED, NODE_REQUEST_COMPLETED,
@@ -916,6 +917,14 @@ struct node_roll_command : command_data {
bigtime_t seek_media_time; bigtime_t seek_media_time;
}; };
struct node_sync_to_request : request_data {
bigtime_t performance_time;
port_id port;
};
struct node_sync_to_reply : reply_data {
};
struct node_set_run_mode_command : command_data { struct node_set_run_mode_command : command_data {
BMediaNode::run_mode mode; BMediaNode::run_mode mode;
}; };
+10 -2
View File
@@ -157,8 +157,12 @@ BMediaEventLooper::AddTimer(bigtime_t at_performance_time,
int32 cookie) int32 cookie)
{ {
CALLED(); CALLED();
// XXX what do we need to do here?
return BMediaNode::AddTimer(at_performance_time,cookie); media_timed_event event(at_performance_time,
BTimedEventQueue::B_TIMER, NULL,
BTimedEventQueue::B_EXPIRE_TIMER);
event.data = cookie;
return EventQueue()->AddEvent(event);
} }
@@ -477,6 +481,10 @@ BMediaEventLooper::DispatchEvent(const media_timed_event *event,
/* nothing */ /* nothing */
break; break;
case BTimedEventQueue::B_TIMER:
TimerExpired(event->event_time, event->data);
break;
default: default:
break; break;
} }
+32 -7
View File
@@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2015, Dario Casalinuovo
* Copyright (c) 2002, 2003 Marcus Overhagen <[email protected]> * Copyright (c) 2002, 2003 Marcus Overhagen <[email protected]>
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
@@ -327,16 +328,21 @@ BMediaNode::NodeStopped(bigtime_t whenPerformance)
} }
/*
* Used in couple with AddTimer, this will cause the BMediaRoster::SyncToNode()
* call that requested the timer to return to the caller with an appropriate
* value.
*/
void void
BMediaNode::TimerExpired(bigtime_t notifyPoint, BMediaNode::TimerExpired(bigtime_t notifyPoint,
int32 cookie, int32 cookie,
status_t error) status_t error)
{ {
UNIMPLEMENTED(); CALLED();
// Used with AddTimer if (write_port((port_id)cookie, 0, &error, sizeof(error)) < 0) {
// This will, in turn, cause the BMediaRoster::SyncToNode() call TRACE("BMediaNode::TimerExpired: error writing port" B_PRId32
// that instigated the timer to return to the caller. ", at notifyPoint" B_PRId64 "\n", cookie, notifyPoint);
// Probably only important to classes derived from BTimeSource. }
} }
@@ -649,6 +655,26 @@ BMediaNode::HandleMessage(int32 message,
return B_OK; return B_OK;
} }
case NODE_SYNC_TO:
{
const node_sync_to_request *request
= static_cast<const node_sync_to_request *>(data);
node_sync_to_reply reply;
TRACE("BMediaNode::HandleMessage NODE_SYNC_TO, node %ld\n",
fNodeID);
// If AddTimer return an error the caller will know that the node
// doesn't support this feature or there was a problem when adding
// it, this will result in SyncToNode returning immediately
// to the caller with an error.
status_t status = AddTimer(request->performance_time,
request->port);
request->SendReply(status, &reply, sizeof(reply));
return B_OK;
}
case NODE_SET_TIMESOURCE: case NODE_SET_TIMESOURCE:
{ {
const node_set_timesource_command *command = static_cast<const node_set_timesource_command *>(data); const node_set_timesource_command *command = static_cast<const node_set_timesource_command *>(data);
@@ -878,8 +904,7 @@ BMediaNode::GetNodeAttributes(media_node_attribute *outAttributes,
BMediaNode::AddTimer(bigtime_t at_performance_time, BMediaNode::AddTimer(bigtime_t at_performance_time,
int32 cookie) int32 cookie)
{ {
UNIMPLEMENTED(); CALLED();
return B_ERROR; return B_ERROR;
} }
+26 -2
View File
@@ -1365,8 +1365,32 @@ status_t
BMediaRoster::SyncToNode(const media_node& node, bigtime_t atTime, BMediaRoster::SyncToNode(const media_node& node, bigtime_t atTime,
bigtime_t timeout) bigtime_t timeout)
{ {
UNIMPLEMENTED(); TRACE("BMediaRoster::SyncToNode, node %" B_PRId32 ", at real %" B_PRId64
return B_OK; ", at timeout %" B_PRId64 "\n", node.node, atTime, timeout);
if (IS_INVALID_NODE(node))
return B_MEDIA_BAD_NODE;
port_id waitPort = create_port(1, "SyncToNode wait port");
if (waitPort < B_OK)
return waitPort;
node_sync_to_request request;
node_sync_to_reply reply;
request.performance_time = atTime;
request.port = waitPort;
status_t status = QueryPort(node.port, NODE_SYNC_TO, &request,
sizeof(request), &reply, sizeof(reply));
if (status == B_OK) {
ssize_t readSize = read_port_etc(waitPort, NULL, &status,
sizeof(status), B_TIMEOUT, timeout);
if (readSize < 0)
status = readSize;
}
close_port(waitPort);
delete_port(waitPort);
return status;
} }