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 {
|
134 | 134 | FILEINTERFACE_SET_REF, |
135 | 135 | FILEINTERFACE_GET_REF, |
136 | 136 | FILEINTERFACE_SNIFF_REF, |
| 137 | FILEINTERFACE_GET_FORMATS, |
137 | 138 | FILEINTERFACE_MESSAGE_END, |
138 | 139 | |
139 | 140 | CONTROLLABLE_MESSAGE_START = 0x600, |
… |
… |
struct fileinterface_sniff_ref_reply : reply_data {
|
994 | 995 | float capability; |
995 | 996 | }; |
996 | 997 | |
| 998 | struct fileinterface_get_formats_request : request_data { |
| 999 | int32 num_formats; |
| 1000 | area_id data_area; |
| 1001 | }; |
| 1002 | |
| 1003 | struct fileinterface_get_formats_reply : reply_data { |
| 1004 | int32 filled_slots; |
| 1005 | }; |
997 | 1006 | |
998 | 1007 | // #pragma mark - controllable commands |
999 | 1008 | |
diff --git a/src/kits/media/FileInterface.cpp b/src/kits/media/FileInterface.cpp
index 891169f..644607c 100644
a
|
b
|
BFileInterface::HandleMessage(int32 message,
|
97 | 97 | |
98 | 98 | return B_OK; |
99 | 99 | } |
| 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 | } |
100 | 128 | default: |
101 | 129 | return B_ERROR; |
102 | 130 | } |
diff --git a/src/kits/media/MediaRoster.cpp b/src/kits/media/MediaRoster.cpp
index 739f66a..7137f6d 100644
a
|
b
|
status_t
|
2811 | 2811 | BMediaRoster::GetFileFormatsFor(const media_node& fileInterface, |
2812 | 2812 | media_file_format* _formats, int32* _numFormats) |
2813 | 2813 | { |
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; |
2816 | 2850 | } |
2817 | 2851 | |
2818 | 2852 | |