Implement the backend of get_next_file_format(). The AddOnManager maintains

a list for known media_file_formats. The internal IDs map to plugins.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31950 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2009-07-29 22:49:23 +00:00
parent 891446f596
commit 7c06546a8e
6 changed files with 76 additions and 28 deletions
+11 -1
View File
@@ -132,6 +132,7 @@ enum {
SERVER_GET_READERS,
SERVER_GET_DECODER_FOR_FORMAT,
SERVER_GET_WRITER_FOR_FORMAT_FAMILY,
SERVER_GET_FILE_FORMAT_FOR_COOKIE,
SERVER_GET_ENCODER_FOR_FORMAT,
SERVER_MESSAGE_END,
NODE_MESSAGE_START = 0x200,
@@ -826,7 +827,7 @@ struct server_get_readers_reply : reply_data {
};
struct server_get_writer_request : request_data {
media_file_format file_format;
uint32 internal_id;
};
struct server_get_writer_reply : reply_data {
@@ -834,6 +835,15 @@ struct server_get_writer_reply : reply_data {
// a ref to the writer
};
struct server_get_file_format_request : request_data {
int32 cookie;
};
struct server_get_file_format_reply : reply_data {
media_file_format file_format;
// the file format matching the cookie
};
struct node_request_completed_command : command_data {
media_request_info info;
};
+16 -2
View File
@@ -1189,8 +1189,22 @@ operator<(const media_file_format_id& a, const media_file_format_id& b)
status_t
get_next_file_format(int32* cookie, media_file_format* mff)
{
UNIMPLEMENTED();
return B_ERROR;
if (cookie == NULL || mff == NULL)
return B_BAD_VALUE;
// get list of available readers from the server
server_get_file_format_request request;
request.cookie = *cookie;
server_get_file_format_reply reply;
status_t ret = QueryServer(SERVER_GET_FILE_FORMAT_FOR_COOKIE, &request,
sizeof(request), &reply, sizeof(reply));
if (ret != B_OK)
return ret;
*cookie = *cookie + 1;
*mff = reply.file_format;
return B_OK;
}
+2 -2
View File
@@ -195,9 +195,9 @@ PluginManager::CreateWriter(Writer** writer, const media_file_format& mff,
{
TRACE("PluginManager::CreateWriter enter\n");
// get list of available readers from the server
// Get the Writer responsible for this media_file_format from the server.
server_get_writer_request request;
request.file_format = mff;
request.internal_id = mff.id.internal_id;
server_get_writer_reply reply;
status_t ret = QueryServer(SERVER_GET_WRITER_FOR_FORMAT_FAMILY, &request,
sizeof(request), &reply, sizeof(reply));
+21 -14
View File
@@ -178,24 +178,15 @@ AddOnManager::GetEncoderForFormat(xfer_entry_ref* _encoderRef,
status_t
AddOnManager::GetWriter(xfer_entry_ref* _ref, const media_file_format& format)
AddOnManager::GetWriter(xfer_entry_ref* _ref, uint32 internalID)
{
BAutolock locker(fLock);
writer_info* info;
for (fWriterList.Rewind(); fWriterList.GetNext(&info);) {
media_file_format* fileFormat;
for (info->fileFormats.Rewind();
info->fileFormats.GetNext(&fileFormat);) {
// Check if the writer matches the supplied file format
// TODO: There must be a trick here which makes all this
// much simpler and probably lets us create a Writer client
// side...
if (fileFormat->id.internal_id != format.id.internal_id)
continue;
if (info->internalID == internalID) {
printf("AddOnManager::GetWriter: found writer %s for "
"file format %s\n", info->ref.name, format.pretty_name);
"internal_id %lu\n", info->ref.name, internalID);
*_ref = info->ref;
return B_OK;
@@ -206,6 +197,21 @@ AddOnManager::GetWriter(xfer_entry_ref* _ref, const media_file_format& format)
}
status_t
AddOnManager::GetFileFormat(media_file_format* _fileFormat, int32 cookie)
{
BAutolock locker(fLock);
media_file_format* fileFormat;
if (fFileFormats.Get(cookie, &fileFormat)) {
*_fileFormat = *fileFormat;
return B_OK;
}
return B_BAD_INDEX;
}
// #pragma mark -
@@ -412,6 +418,7 @@ AddOnManager::_RegisterWriter(WriterPlugin* writer, const entry_ref& ref)
writer_info info;
info.ref = ref;
info.internalID = fNextWriterFormatFamilyID++;
// Get list of support media_file_formats...
media_file_format* fileFormats = NULL;
@@ -427,9 +434,9 @@ AddOnManager::_RegisterWriter(WriterPlugin* writer, const entry_ref& ref)
media_file_format fileFormat = fileFormats[i];
fileFormat.id.node = ref.directory;
fileFormat.id.device = ref.device;
fileFormat.id.internal_id = fNextWriterFormatFamilyID++;
fileFormat.id.internal_id = info.internalID;
info.fileFormats.Insert(fileFormat);
fFileFormats.Insert(fileFormat);
}
fWriterList.Insert(info);
+13 -8
View File
@@ -45,7 +45,10 @@ public:
const media_format& format);
status_t GetWriter(xfer_entry_ref* _ref,
const media_file_format& format);
uint32 internalID);
status_t GetFileFormat(media_file_format* _fileFormat,
int32 cookie);
private:
status_t _RegisterAddOn(BEntry& entry);
@@ -63,19 +66,19 @@ private:
private:
struct reader_info {
entry_ref ref;
entry_ref ref;
};
struct writer_info {
entry_ref ref;
List<media_file_format> fileFormats;
entry_ref ref;
uint32 internalID;
};
struct decoder_info {
entry_ref ref;
List<media_format> formats;
entry_ref ref;
List<media_format> formats;
};
struct encoder_info {
entry_ref ref;
List<media_format> formats;
entry_ref ref;
List<media_format> formats;
};
BLocker fLock;
@@ -84,6 +87,8 @@ private:
List<decoder_info> fDecoderList;
List<encoder_info> fEncoderList;
List<media_file_format> fFileFormats;
uint32 fNextWriterFormatFamilyID;
AddOnMonitorHandler* fHandler;
+13 -1
View File
@@ -891,7 +891,19 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
const server_get_writer_request *request
= reinterpret_cast<const server_get_writer_request *>(data);
server_get_writer_reply reply;
rv = gAddOnManager->GetWriter(&reply.ref, request->file_format);
rv = gAddOnManager->GetWriter(&reply.ref, request->internal_id);
request->SendReply(rv, &reply, sizeof(reply));
break;
}
case SERVER_GET_FILE_FORMAT_FOR_COOKIE:
{
const server_get_file_format_request *request
= reinterpret_cast<
const server_get_file_format_request *>(data);
server_get_file_format_reply reply;
rv = gAddOnManager->GetFileFormat(&reply.file_format,
request->cookie);
request->SendReply(rv, &reply, sizeof(reply));
break;
}