From 23d5326e2b400a4ffb0818b9875227d3f5a17a8d Mon Sep 17 00:00:00 2001 From: Dario Casalinuovo Date: Thu, 24 Nov 2016 00:14:00 +0100 Subject: [PATCH] MediaClient: Introduce media_client and media_connection * Those structs are provided as replacement for the classic media_kit ones. They provide better encapsulation of the data and the resulting code is heavily simplified. It's planned to introduce BMediaRoster functions to provide conversion from media_node and media_input/media_output to media_client and media_connection. --- headers/private/media/MediaClientDefs.h | 103 ++++++++++++++++++++++++ src/kits/media/MediaClientDefs.cpp | 89 ++++++++++++++++++++ 2 files changed, 192 insertions(+) create mode 100644 headers/private/media/MediaClientDefs.h create mode 100644 src/kits/media/MediaClientDefs.cpp diff --git a/headers/private/media/MediaClientDefs.h b/headers/private/media/MediaClientDefs.h new file mode 100644 index 0000000000..79325e5d0c --- /dev/null +++ b/headers/private/media/MediaClientDefs.h @@ -0,0 +1,103 @@ +/* + * Copyright 2015, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ + +#ifndef _MEDIA_CLIENT_DEFS_H +#define _MEDIA_CLIENT_DEFS_H + +#include +#include + + +namespace BPrivate { namespace media { + + +typedef int32 media_client_id; +typedef int32 media_client_kind; +typedef int32 media_connection_id; + + +enum media_client_kinds { + // The client can receive media data. + B_MEDIA_RECORDER = 0x000000001, + // The client can send media data to another client. + B_MEDIA_PLAYER = 0x000000002, + // The client specify a control GUI which can be used to configure it. + B_MEDIA_CONTROLLABLE = 0x000000004 +}; + +enum media_connection_kind { + B_MEDIA_INPUT = 0, + B_MEDIA_OUTPUT = 1 +}; + + +typedef struct media_client { + media_client_id Id() const; + media_client_kind Kind() const; + + BMessage* ToMessage(); + +private: + media_client_kind kind; + + media_node node; + uint32 padding[16]; + + friend class BMediaClient; + friend class BMediaConnection; + friend class media_connection; +} media_client; + + +typedef struct media_connection { + media_connection_id Id() const; + media_connection_kind Kind() const; + + media_client Client() const; + + const char* Name() const; + + bool IsInput() const; + bool IsOutput() const; + + BMessage* ToMessage() const; + +private: + media_input MediaInput() const; + media_output MediaOutput() const; + + const media_source& Source() const; + const media_destination& Destination() const; + + media_node RemoteNode() const; + +private: + media_connection_id id; + + media_client client; + // TODO really needed? + media_client remote_client; + + media_source source; + media_destination destination; + media_format format; + char name[B_MEDIA_NAME_LENGTH]; + + media_connection_kind kind; + uint32 padding[16]; + + friend class BMediaClient; + friend class BMediaConnection; + friend class BMediaClientNode; +} media_connection; + + +} + +} + +using namespace BPrivate::media; + +#endif diff --git a/src/kits/media/MediaClientDefs.cpp b/src/kits/media/MediaClientDefs.cpp new file mode 100644 index 0000000000..dd532b98fb --- /dev/null +++ b/src/kits/media/MediaClientDefs.cpp @@ -0,0 +1,89 @@ +/* + * Copyright 2015, Dario Casalinuovo. All rights reserved. + * Distributed under the terms of the MIT License. + */ + +#include +#include + +#include "debug.h" + + +media_client_id +media_client::Id() const +{ + return node.node; +} + + +media_connection_id +media_connection::Id() const +{ + return id; +} + + +media_connection_kind +media_connection::Kind() const +{ + return kind; +} + + +bool +media_connection::IsInput() const +{ + return Kind() == B_MEDIA_INPUT; +} + + +bool +media_connection::IsOutput() const +{ + return Kind() == B_MEDIA_OUTPUT; +} + + +media_input +media_connection::MediaInput() const +{ + media_input input; + input.node = client.node; + input.source = source; + input.destination = destination; + input.format = format; + return input; +} + + +media_output +media_connection::MediaOutput() const +{ + media_output output; + output.node = client.node; + output.source = source; + output.destination = destination; + output.format = format; + return output; +} + + +const media_source& +media_connection::Source() const +{ + return source; +} + + +const media_destination& +media_connection::Destination() const +{ + return destination; +} + + +media_node +media_connection::RemoteNode() const +{ + return remote_client.node; +}