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

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

    From a26c147b40974ea70aa8207eb38a0f4d7fc11899 Mon Sep 17 00:00:00 2001
    From: Dario Casalinuovo <b.vitruvio@gmail.com>
    Date: Thu, 9 Apr 2015 15:36:57 +0200
    Subject: [PATCH 04/13] Implement BMediaRoster::GetFileFormatsFor.
    
    ---
     headers/private/media/ServerInterface.h |  9 ++++++++
     src/kits/media/FileInterface.cpp        | 28 ++++++++++++++++++++++++
     src/kits/media/MediaRoster.cpp          | 38 +++++++++++++++++++++++++++++++--
     3 files changed, 73 insertions(+), 2 deletions(-)
    
    diff --git a/headers/private/media/ServerInterface.h b/headers/private/media/ServerInterface.h
    index d2551c0..46a1329 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 {  
    994995    float                   capability;
    995996};
    996997
     998struct fileinterface_get_formats_request : request_data {
     999    int32                   num_formats;
     1000    area_id                 data_area;
     1001};
     1002
     1003struct fileinterface_get_formats_reply : reply_data {
     1004    int32                   filled_slots;
     1005};
    9971006
    9981007// #pragma mark - controllable commands
    9991008
  • src/kits/media/FileInterface.cpp

    diff --git a/src/kits/media/FileInterface.cpp b/src/kits/media/FileInterface.cpp
    index 891169f..644607c 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 < 0) {
     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            }
     122            reply.filled_slots = cookie;
     123            request->SendReply(B_OK, &reply, sizeof(reply));
     124
     125            delete_area(area);
     126            return B_OK;
     127        }
    100128        default:
    101129            return B_ERROR;
    102130    }
  • src/kits/media/MediaRoster.cpp

    diff --git a/src/kits/media/MediaRoster.cpp b/src/kits/media/MediaRoster.cpp
    index 739f66a..7137f6d 100644
    a b status_t  
    28112811BMediaRoster::GetFileFormatsFor(const media_node& fileInterface,
    28122812    media_file_format* _formats, int32* _numFormats)
    28132813{
    2814     UNIMPLEMENTED();
    2815     return B_ERROR;
     2814    CALLED();
     2815
     2816    if (IS_INVALID_NODE(fileInterface)
     2817        || (fileInterface.kind & B_FILE_INTERFACE) == 0)
     2818        return B_MEDIA_BAD_NODE;
     2819
     2820    if (_numFormats == NULL || *_numFormats < 1)
     2821        return B_BAD_VALUE;
     2822
     2823    fileinterface_get_formats_request request;
     2824    fileinterface_get_formats_reply reply;
     2825
     2826    media_file_format* formats;
     2827    size_t needSize = sizeof(media_file_format) * *_numFormats;
     2828    size_t size = (size_t)(ceil(needSize / B_PAGE_SIZE) * B_PAGE_SIZE);
     2829
     2830    area_id area = create_area("formats area", (void**)&formats,
     2831        B_ANY_ADDRESS, size, B_NO_LOCK,
     2832        B_READ_AREA | B_WRITE_AREA);
     2833
     2834    if (area < 0)
     2835        return B_ERROR;
     2836
     2837    request.num_formats = *_numFormats;
     2838    request.data_area = area;
     2839
     2840    status_t status = QueryPort(fileInterface.port,
     2841        FILEINTERFACE_GET_FORMATS, &request,
     2842        sizeof(request), &reply, sizeof(reply));
     2843
     2844    if (status == B_OK) {
     2845        memcpy(_formats, formats, sizeof(media_file_format)*reply.filled_slots);
     2846        *_numFormats = reply.filled_slots;
     2847    }
     2848    delete_area(area);
     2849    return status;
    28162850}
    28172851
    28182852