2016-11-11 15:39:33 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2015, Haiku, Inc. All rights reserved.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _MEDIA_CLIENT_H
|
|
|
|
#define _MEDIA_CLIENT_H
|
|
|
|
|
|
|
|
#include <ObjectList.h>
|
|
|
|
#include <Buffer.h>
|
|
|
|
|
|
|
|
#include <MediaAddOn.h>
|
2016-11-24 02:19:06 +03:00
|
|
|
#include <MediaClientDefs.h>
|
2016-11-11 15:39:33 +03:00
|
|
|
#include <MediaDefs.h>
|
|
|
|
#include <MediaNode.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace BPrivate { namespace media {
|
|
|
|
|
|
|
|
|
2017-01-17 00:49:49 +03:00
|
|
|
class BMediaClientNode;
|
2016-11-25 19:29:17 +03:00
|
|
|
class BMediaConnection;
|
|
|
|
class BMediaInput;
|
|
|
|
class BMediaOutput;
|
|
|
|
|
2017-01-18 21:34:07 +03:00
|
|
|
// Private stuff
|
|
|
|
class InputReleaser;
|
|
|
|
class OutputReleaser;
|
|
|
|
|
|
|
|
|
2016-11-11 15:39:33 +03:00
|
|
|
// BMediaClient is a general purpose class allowing to create any kind
|
|
|
|
// of media_node. It automatically manage the expected behavior under
|
2016-12-06 18:47:16 +03:00
|
|
|
// different run modes, and allow to specify the different capabilities needed.
|
|
|
|
// BMediaClient is not using any of the coding patterns you might be used to.
|
|
|
|
// There are no events to care, and threading is managed internally using
|
|
|
|
// the data processing specified by the BMediaGraph class.
|
2016-11-11 15:39:33 +03:00
|
|
|
class BMediaClient {
|
|
|
|
public:
|
|
|
|
BMediaClient(const char* name,
|
|
|
|
media_type type
|
|
|
|
= B_MEDIA_UNKNOWN_TYPE,
|
2016-12-06 23:05:15 +03:00
|
|
|
media_client_kinds
|
2016-11-24 02:19:06 +03:00
|
|
|
kind = B_MEDIA_PLAYER
|
2016-11-11 15:39:33 +03:00
|
|
|
& B_MEDIA_RECORDER);
|
|
|
|
|
|
|
|
virtual ~BMediaClient();
|
|
|
|
|
2016-11-24 02:19:06 +03:00
|
|
|
const media_client& Client() const;
|
2016-11-11 15:39:33 +03:00
|
|
|
|
2016-12-06 23:05:15 +03:00
|
|
|
media_client_id Id() const;
|
|
|
|
const char* Name() const;
|
2016-11-11 15:39:33 +03:00
|
|
|
// Return the capabilities of this BMediaClient instance.
|
2016-12-06 23:05:15 +03:00
|
|
|
media_client_kinds Kinds() const;
|
2016-11-24 02:19:06 +03:00
|
|
|
media_type MediaType() const;
|
|
|
|
|
|
|
|
status_t InitCheck() const;
|
2016-11-11 15:39:33 +03:00
|
|
|
|
2016-11-29 03:19:45 +03:00
|
|
|
// TODO: Should allow BControllable capabilities
|
|
|
|
// TODO: Add file interface
|
|
|
|
// TODO: Offline mode is still missing
|
|
|
|
|
2016-11-11 15:39:33 +03:00
|
|
|
// When those functions return, the BMediaConnection is added to the
|
2016-12-06 18:47:16 +03:00
|
|
|
// list and is visible to other nodes as not connected. Any input/output
|
2017-02-18 22:40:38 +03:00
|
|
|
// should be registered to a BMediaClient to become visible in the system.
|
2016-11-29 03:19:45 +03:00
|
|
|
virtual status_t RegisterInput(BMediaInput* input);
|
|
|
|
virtual status_t RegisterOutput(BMediaOutput* output);
|
2016-11-11 15:39:33 +03:00
|
|
|
|
|
|
|
// Bind internally two connections of the same BMediaClient, so that the
|
|
|
|
// input will be automatically forwarded to the output just after the
|
|
|
|
// ProcessFunc is called. The buffer is automatically recycled too.
|
|
|
|
// Beware that the binding operation is valid only for local connections
|
|
|
|
// which belong to this node, otherwise return B_ERROR.
|
2016-11-25 19:29:17 +03:00
|
|
|
virtual status_t Bind(BMediaInput* input,
|
|
|
|
BMediaOutput* output);
|
2016-11-11 15:39:33 +03:00
|
|
|
|
2016-11-25 19:29:17 +03:00
|
|
|
virtual status_t Unbind(BMediaInput* input,
|
|
|
|
BMediaOutput* output);
|
2016-11-11 15:39:33 +03:00
|
|
|
|
|
|
|
// If the user want a particular format for a connection it should
|
|
|
|
// use BMediaConnection::SetAcceptedFormat(), if it's not specified
|
|
|
|
// BMediaClient::Format() will be used, in case both aren't specified
|
2016-11-17 04:43:40 +03:00
|
|
|
// an error is returned. The first parameter should always belong to
|
|
|
|
// this node, the second will be a connection obtained from another
|
2017-02-18 22:40:38 +03:00
|
|
|
// BMediaClient. Unregistered connections will be registered automatically.
|
2016-11-11 15:39:33 +03:00
|
|
|
virtual status_t Connect(BMediaConnection* ourConnection,
|
|
|
|
BMediaConnection* theirConnection);
|
|
|
|
|
|
|
|
virtual status_t Connect(BMediaConnection* ourConnection,
|
2016-11-24 02:19:06 +03:00
|
|
|
const media_connection& theirConnection);
|
2016-11-11 15:39:33 +03:00
|
|
|
|
2016-11-24 02:19:06 +03:00
|
|
|
// Find a free input/output and try to connect to the media_client,
|
|
|
|
// return meaningful error otherwise.
|
2016-11-11 15:39:33 +03:00
|
|
|
virtual status_t Connect(BMediaConnection* ourConnection,
|
2016-11-24 02:19:06 +03:00
|
|
|
const media_client& client);
|
2016-11-11 15:39:33 +03:00
|
|
|
|
|
|
|
// Disconnect any connection belonging to this object, to disconnect
|
|
|
|
// a single connection use BMediaConnection::Disconnect().
|
|
|
|
virtual status_t Disconnect();
|
|
|
|
|
|
|
|
int32 CountInputs() const;
|
|
|
|
int32 CountOutputs() const;
|
2016-11-24 02:19:06 +03:00
|
|
|
|
2016-11-25 19:29:17 +03:00
|
|
|
BMediaInput* InputAt(int32 index) const;
|
|
|
|
BMediaOutput* OutputAt(int32 index) const;
|
2016-11-11 15:39:33 +03:00
|
|
|
|
2016-11-25 19:29:17 +03:00
|
|
|
BMediaInput* FindInput(
|
2016-11-24 23:37:14 +03:00
|
|
|
const media_connection& input) const;
|
2016-11-25 19:29:17 +03:00
|
|
|
BMediaOutput* FindOutput(
|
2016-11-24 23:37:14 +03:00
|
|
|
const media_connection& output) const;
|
2016-11-11 15:39:33 +03:00
|
|
|
|
|
|
|
bool IsRunning() const;
|
|
|
|
|
2016-12-06 18:47:16 +03:00
|
|
|
// NOTE: The following functions aren't provided to be inherited,
|
|
|
|
// always use the protected HandleSomething version. This is because
|
|
|
|
// otherwise you could break the connection mechanism and mine interoperability
|
|
|
|
// from remote nodes.
|
2017-01-15 17:00:09 +03:00
|
|
|
status_t Start();
|
|
|
|
status_t Stop();
|
2016-11-11 15:39:33 +03:00
|
|
|
status_t Seek(bigtime_t mediaTime,
|
|
|
|
bigtime_t performanceTime);
|
|
|
|
status_t Roll(bigtime_t start, bigtime_t stop,
|
|
|
|
bigtime_t seek);
|
2017-01-15 17:00:09 +03:00
|
|
|
|
|
|
|
// Preroll the client to buffer startup latency
|
2016-11-11 15:39:33 +03:00
|
|
|
status_t Preroll();
|
2017-01-15 17:00:09 +03:00
|
|
|
|
|
|
|
// This function return when the client reach the specified performanceTime
|
2016-11-11 15:39:33 +03:00
|
|
|
status_t SyncTo(bigtime_t performanceTime,
|
|
|
|
bigtime_t timeout = -1);
|
|
|
|
|
|
|
|
// It will be B_INCREASE_LATENCY by default
|
|
|
|
BMediaNode::run_mode RunMode() const;
|
|
|
|
status_t SetRunMode(BMediaNode::run_mode mode);
|
|
|
|
|
2016-11-25 19:35:10 +03:00
|
|
|
// Return the current performance time handled by the object when
|
|
|
|
// run_mode != B_OFFLINE. Otherwise returns the current offline time.
|
|
|
|
bigtime_t CurrentTime() const;
|
2016-11-11 15:39:33 +03:00
|
|
|
|
|
|
|
// This is supplied to support using this class in a BMediaAddOn.
|
|
|
|
// Default version just return NULL.
|
|
|
|
virtual BMediaAddOn* AddOn(int32* id) const;
|
|
|
|
|
|
|
|
protected:
|
2016-11-29 03:19:45 +03:00
|
|
|
virtual void HandleStart(bigtime_t performanceTime);
|
|
|
|
virtual void HandleStop(bigtime_t performanceTime);
|
|
|
|
|
|
|
|
virtual void HandleSeek(bigtime_t mediaTime,
|
|
|
|
bigtime_t performanceTime);
|
|
|
|
|
2017-01-17 03:59:24 +03:00
|
|
|
virtual status_t FormatSuggestion(media_type type,
|
2016-11-29 03:19:45 +03:00
|
|
|
int32 quality, media_format* format);
|
|
|
|
|
2016-11-11 15:39:33 +03:00
|
|
|
private:
|
2017-01-17 03:59:24 +03:00
|
|
|
void _Init();
|
|
|
|
void _Deinit();
|
2016-12-06 18:47:16 +03:00
|
|
|
|
2017-01-17 03:59:24 +03:00
|
|
|
void _AddInput(BMediaInput* input);
|
|
|
|
void _AddOutput(BMediaOutput* output);
|
|
|
|
|
|
|
|
BMediaInput* _FindInput(
|
2016-11-24 23:37:14 +03:00
|
|
|
const media_destination& dest) const;
|
2017-01-17 03:59:24 +03:00
|
|
|
BMediaOutput* _FindOutput(
|
2016-11-24 23:37:14 +03:00
|
|
|
const media_source& source) const;
|
2016-11-11 15:39:33 +03:00
|
|
|
|
2016-11-25 19:29:17 +03:00
|
|
|
status_t _ConnectInput(BMediaOutput* output,
|
2016-11-24 02:19:06 +03:00
|
|
|
const media_connection& input);
|
2016-11-25 19:29:17 +03:00
|
|
|
status_t _ConnectOutput(BMediaInput* input,
|
2016-11-24 02:19:06 +03:00
|
|
|
const media_connection& output);
|
2016-11-11 15:39:33 +03:00
|
|
|
|
2017-01-18 22:16:53 +03:00
|
|
|
status_t _DisconnectConnection(BMediaConnection* conn);
|
|
|
|
status_t _ReleaseConnection(BMediaConnection* conn);
|
|
|
|
|
2016-11-11 15:39:33 +03:00
|
|
|
status_t fInitErr;
|
|
|
|
|
2016-11-24 02:19:06 +03:00
|
|
|
media_client fClient;
|
2016-11-11 15:39:33 +03:00
|
|
|
|
|
|
|
bool fRunning;
|
|
|
|
BMediaClientNode* fNode;
|
|
|
|
|
2016-11-25 19:35:10 +03:00
|
|
|
bigtime_t fCurrentTime;
|
2016-11-11 15:39:33 +03:00
|
|
|
|
2017-01-18 21:34:07 +03:00
|
|
|
BObjectList<InputReleaser> fInputs;
|
|
|
|
BObjectList<OutputReleaser> fOutputs;
|
2016-11-11 15:39:33 +03:00
|
|
|
|
2016-11-25 02:26:02 +03:00
|
|
|
media_connection_id fLastID;
|
2016-11-24 02:19:06 +03:00
|
|
|
|
2016-11-11 15:39:33 +03:00
|
|
|
virtual void _ReservedMediaClient0();
|
|
|
|
virtual void _ReservedMediaClient1();
|
|
|
|
virtual void _ReservedMediaClient2();
|
|
|
|
virtual void _ReservedMediaClient3();
|
|
|
|
virtual void _ReservedMediaClient4();
|
|
|
|
virtual void _ReservedMediaClient5();
|
|
|
|
virtual void _ReservedMediaClient6();
|
|
|
|
virtual void _ReservedMediaClient7();
|
|
|
|
virtual void _ReservedMediaClient8();
|
|
|
|
virtual void _ReservedMediaClient9();
|
|
|
|
virtual void _ReservedMediaClient10();
|
|
|
|
uint32 fPadding[64];
|
|
|
|
|
|
|
|
friend class BMediaClientNode;
|
|
|
|
friend class BMediaConnection;
|
2016-11-26 19:13:02 +03:00
|
|
|
friend class BMediaInput;
|
|
|
|
friend class BMediaOutput;
|
2016-11-11 15:39:33 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
using namespace BPrivate::media;
|
|
|
|
|
|
|
|
#endif
|