Ticket #11856: 0002-Implement-BMediaRoster-SyncToNode.2.patch

File 0002-Implement-BMediaRoster-SyncToNode.2.patch, 5.5 KB (added by Barrett, 10 years ago)
  • headers/private/media/ServerInterface.h

    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 {  
    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_get_timesource_reply : reply_data {  
    929930struct node_final_release_command : command_data {
    930931};
    931932
     933struct node_sync_to_command : command_data {
     934    bigtime_t               performance_time;
     935    port_id                 port;
     936};
    932937
    933938// #pragma mark - time source commands
    934939
  • src/kits/media/MediaEventLooper.cpp

    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,  
    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(TimeSource()->Now(), 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..e19aff0 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 with AddTimer
     333 * This will, in turn, cause the BMediaRoster::SyncToNode() call
     334 * that instigated the timer to return to the caller.
     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    int32 reply = 1;
     344    write_port(port, NODE_SYNC_TO, &reply, sizeof(reply));
    340345}
    341346
    342347
    BMediaNode::HandleMessage(int32 message,  
    696701            return B_OK;
    697702        }
    698703
     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
    699723    };
    700724    return B_ERROR;
    701725}
    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..099dccb 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 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;
    13691394}
    13701395
    13711396