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

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

An attempt to be more consistent.

  • headers/private/media/ServerInterface.h

    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 {  
    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};
     917
    909918struct node_set_run_mode_command : command_data {
    910919    BMediaNode::run_mode    mode;
    911920};
  • 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..8ff64f4 100644
    a b  
    11/*
     2 * Copyright (c) 2015, Dario Casalinuovo
    23 * Copyright (c) 2002, 2003 Marcus Overhagen <Marcus@Overhagen.de>
    34 *
    45 * Permission is hereby granted, free of charge, to any person obtaining
    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    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    }
    340346}
    341347
    342348
    BMediaNode::HandleMessage(int32 message,  
    649655            return B_OK;
    650656        }
    651657
     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
    652678        case NODE_SET_TIMESOURCE:
    653679        {
    654680            const node_set_timesource_command *command = static_cast<const node_set_timesource_command *>(data);
    BMediaNode::GetNodeAttributes(media_node_attribute *outAttributes,  
    878904BMediaNode::AddTimer(bigtime_t at_performance_time,
    879905                     int32 cookie)
    880906{
    881     UNIMPLEMENTED();
    882 
     907    CALLED();
    883908    return B_ERROR;
    884909}
    885910
  • src/kits/media/MediaRoster.cpp

    diff --git a/src/kits/media/MediaRoster.cpp b/src/kits/media/MediaRoster.cpp
    index 8201be0..eb25312 100644
    a b  
    11/*
    2  * Copyright 2008 Maurice Kalinowski, haiku@kaldience.com
     2 * Copyright 2015 Dario Casalinuovo, b.vitruvio@gmail.com
    33 * Copyright 2009-2012, Axel Dörfler, axeld@pinc-software.de.
     4 * Copyright 2008 Maurice Kalinowski, haiku@kaldience.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        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;
    13691394}
    13701395
    13711396