Ticket #11922: 0004-Implement-BMediaRoster-GetFileFormatsFor.2.patch

File 0004-Implement-BMediaRoster-GetFileFormatsFor.2.patch, 3.7 KB (added by Barrett, 5 years ago)
  • headers/private/media/ServerInterface.h

    From 8d9f09ea8fb20549a24e09da1a9477757291dedf Mon Sep 17 00:00:00 2001
    From: Dario Casalinuovo <b.vitruvio@gmail.com>
    Date: Sat, 28 Mar 2015 16:10:59 +0100
    Subject: [PATCH 04/13] Implement BMediaRoster::GetFileFormatsFor.
    
    ---
     headers/private/media/ServerInterface.h |  9 ++++++++
     src/kits/media/FileInterface.cpp        | 29 +++++++++++++++++++++++
     src/kits/media/MediaRoster.cpp          | 41 +++++++++++++++++++++++++++++++--
     3 files changed, 77 insertions(+), 2 deletions(-)
    
    diff --git a/headers/private/media/ServerInterface.h b/headers/private/media/ServerInterface.h
    index f84f3e1..256c267 100644
    a b enum {  
    134134    FILEINTERFACE_SET_REF,
    135135    FILEINTERFACE_GET_REF,
    136136    FILEINTERFACE_SNIFF_REF,
     137    FILEINTERFACE_GET_FORMATS,
    137138    FILEINTERFACE_MESSAGE_END,
    138139
    139140    CONTROLLABLE_MESSAGE_START = 0x600,
    struct fileinterface_sniff_ref_reply : reply_data {  
    995996    float                   capability;
    996997};
    997998
     999struct fileinterface_get_formats_request : request_data {
     1000    int32                   num_formats;
     1001    area_id                 data_area;
     1002};
     1003
     1004struct fileinterface_get_formats_reply : reply_data {
     1005    int32                   filled_slots;
     1006};
    9981007
    9991008// #pragma mark - controllable commands
    10001009
  • src/kits/media/FileInterface.cpp

    diff --git a/src/kits/media/FileInterface.cpp b/src/kits/media/FileInterface.cpp
    index 891169f..5eba9b2 100644
    a b BFileInterface::HandleMessage(int32 message,  
    9797
    9898            return B_OK;
    9999        }
     100        case FILEINTERFACE_GET_FORMATS:
     101        {
     102            const fileinterface_get_formats_request *request =
     103                    (const fileinterface_get_formats_request*) data;
     104            fileinterface_get_formats_reply reply;
     105
     106            media_file_format* formats;
     107            area_id area = clone_area("client formats area",
     108                (void**)&formats, B_ANY_ADDRESS, B_WRITE_AREA,
     109                request->data_area);
     110
     111            if (area != B_OK) {
     112                ERROR("FILEINTERFACE_GET_FORMATS: can't clone area");
     113                break;
     114            }
     115
     116            int32 cookie = 0;
     117            while (GetNextFileFormat(&cookie, formats) == B_OK) {
     118                if (cookie >= request->num_formats)
     119                    break;
     120                formats += sizeof(media_format);
     121                cookie++;
     122            }
     123            reply.filled_slots = cookie;
     124            request->SendReply(B_OK, &reply, sizeof(reply));
     125
     126            delete_area(area);
     127            return B_OK;
     128        }
    100129        default:
    101130            return B_ERROR;
    102131    }
  • src/kits/media/MediaRoster.cpp

    diff --git a/src/kits/media/MediaRoster.cpp b/src/kits/media/MediaRoster.cpp
    index 97dbe6b..af938b9 100644
    a b status_t  
    28152815BMediaRoster::GetFileFormatsFor(const media_node& fileInterface,
    28162816    media_file_format* _formats, int32* _numFormats)
    28172817{
    2818     UNIMPLEMENTED();
    2819     return B_ERROR;
     2818    CALLED();
     2819
     2820    if (IS_INVALID_NODE(fileInterface)
     2821        || (fileInterface.kind & B_FILE_INTERFACE) == 0)
     2822        return B_MEDIA_BAD_NODE;
     2823
     2824    if (_numFormats == NULL || *_numFormats < 1)
     2825        return B_BAD_VALUE;
     2826
     2827    fileinterface_get_formats_request request;
     2828    fileinterface_get_formats_reply reply;
     2829    status_t rv;
     2830
     2831    media_file_format* formats;
     2832    size_t size = (size_t)(ceil(sizeof(media_file_format) * *_numFormats
     2833        / B_PAGE_SIZE) * B_PAGE_SIZE);
     2834
     2835    area_id area = create_area("formats area", (void**)&formats,
     2836        B_ANY_ADDRESS, size, B_NO_LOCK,
     2837        B_READ_AREA | B_WRITE_AREA);
     2838
     2839    if (area < B_OK)
     2840        return B_ERROR;
     2841
     2842    request.num_formats = *_numFormats;
     2843    request.data_area = area;
     2844
     2845    rv = QueryPort(fileInterface.port, FILEINTERFACE_GET_FORMATS, &request,
     2846        sizeof(request), &reply, sizeof(reply));
     2847    if (rv != B_OK) {
     2848        delete_area(area);
     2849        return rv;
     2850    }
     2851
     2852    memcpy(_formats, formats, sizeof(media_file_format)*reply.filled_slots);
     2853    *_numFormats = reply.filled_slots;
     2854
     2855    delete_area(area);
     2856    return B_OK;
    28202857}
    28212858
    28222859