Ticket #11922: 0002-Implement-BMediaRoster-SyncToNode.patch

File 0002-Implement-BMediaRoster-SyncToNode.patch, 5.8 KB (added by Barrett, 5 years ago)

Fix things suggested by korli

  • headers/private/media/ServerInterface.h

    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 {  
    8989    NODE_TIME_WARP,
    9090    NODE_PREROLL,
    9191    NODE_ROLL,
     92    NODE_SYNC_TO,
    9293    NODE_SET_TIMESOURCE,
    9394    NODE_GET_TIMESOURCE,
    9495    NODE_REQUEST_COMPLETED,
    struct node_roll_command : command_data {  
    906907    bigtime_t               seek_media_time;
    907908};
    908909
     910struct node_sync_to_request : request_data {
     911    bigtime_t               performance_time;
     912    port_id                 port;
     913};
     914
     915struct node_sync_to_reply : reply_data {
     916    status_t                status;
     917};
     918
    909919struct node_set_run_mode_command : command_data {
    910920    BMediaNode::run_mode    mode;
    911921};
  • src/kits/media/MediaEventLooper.cpp

    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,  
    157157                            int32 cookie)
    158158{
    159159    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);
    162166}
    163167
    164168
    BMediaEventLooper::DispatchEvent(const media_timed_event *event,  
    477481            /* nothing */
    478482            break;
    479483
     484        case BTimedEventQueue::B_TIMER:
     485            TimerExpired(event->event_time, event->data);
     486            break;
     487
    480488        default:
    481489            break;
    482490    }
  • src/kits/media/MediaNode.cpp

    diff --git a/src/kits/media/MediaNode.cpp b/src/kits/media/MediaNode.cpp
    index 77319ae..f8780c0 100644
    a b  
    11/*
    22 * Copyright (c) 2002, 2003 Marcus Overhagen <Marcus@Overhagen.de>
     3 * Copyright (c) 2015, Dario Casalinuovo
    34 *
    45 * Permission is hereby granted, free of charge, to any person obtaining
    56 * a copy of this software and associated documentation files or portions
    BMediaNode::NodeStopped(bigtime_t whenPerformance)  
    327328}
    328329
    329330
     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 */
    330336void
    331337BMediaNode::TimerExpired(bigtime_t notifyPoint,
    332338                         int32 cookie,
    333339                         status_t error)
    334340{
    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));
    340344}
    341345
    342346
    BMediaNode::HandleMessage(int32 message,  
    649653            return B_OK;
    650654        }
    651655
     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
    652676        case NODE_SET_TIMESOURCE:
    653677        {
    654678            const node_set_timesource_command *command = static_cast<const node_set_timesource_command *>(data);
    BMediaNode::GetNodeAttributes(media_node_attribute *outAttributes,  
    878902BMediaNode::AddTimer(bigtime_t at_performance_time,
    879903                     int32 cookie)
    880904{
    881     UNIMPLEMENTED();
    882 
     905    CALLED();
    883906    return B_ERROR;
    884907}
    885908
  • src/kits/media/MediaRoster.cpp

    diff --git a/src/kits/media/MediaRoster.cpp b/src/kits/media/MediaRoster.cpp
    index 8201be0..d9b7a00 100644
    a b  
    11/*
    22 * Copyright 2008 Maurice Kalinowski, haiku@kaldience.com
    33 * Copyright 2009-2012, Axel Dörfler, axeld@pinc-software.de.
     4 * Copyright 2015 Dario Casalinuovo, b.vitruvio@gmail.com
    45 *
    56 * All rights reserved. Distributed under the terms of the MIT License.
    67 */
    status_t  
    13641365BMediaRoster::SyncToNode(const media_node& node, bigtime_t atTime,
    13651366    bigtime_t timeout)
    13661367{
    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;
    13691398}
    13701399
    13711400