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>
|
|
|
|
|
|
|
|
#include "MediaClientNode.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace BPrivate { namespace media {
|
|
|
|
|
|
|
|
|
2016-11-25 19:29:17 +03:00
|
|
|
class BMediaConnection;
|
|
|
|
class BMediaInput;
|
|
|
|
class BMediaOutput;
|
|
|
|
|
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
|
2016-12-06 23:05:15 +03:00
|
|
|
// should be registered to a BMediaClient to become something useful.
|
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
|
|
|
|
// BMediaClient.
|
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.
|
2016-11-29 03:19:45 +03:00
|
|
|
status_t Start(bool force = false);
|
|
|
|
status_t Stop(bool force = false);
|
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);
|
|
|
|
status_t Preroll();
|
|
|
|
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);
|
|
|
|
|
|
|
|
// Specify a latency range to allow the node behave correctly.
|
|
|
|
// Ideally the minimum latency should be the algorithmic latency you expect
|
|
|
|
// from the node and will be used as starting point. The max latency is the
|
|
|
|
// maximum acceptable by you, over that point the node will adjust it's
|
|
|
|
// performance time to recover if a big delay happen.
|
|
|
|
void SetLatencyRange(bigtime_t min,
|
|
|
|
bigtime_t max);
|
|
|
|
|
|
|
|
void GetLatencyRange(bigtime_t* min,
|
|
|
|
bigtime_t* max) const;
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
virtual status_t HandleFormatSuggestion(media_type type,
|
|
|
|
int32 quality, media_format* format);
|
|
|
|
|
2016-11-11 15:39:33 +03:00
|
|
|
// Called from BMediaConnection
|
2016-11-29 03:19:45 +03:00
|
|
|
status_t ConnectionDisconnected(BMediaConnection* conn);
|
|
|
|
status_t ConnectionReleased(BMediaConnection* conn);
|
2016-11-24 02:19:06 +03:00
|
|
|
|
2016-11-11 15:39:33 +03:00
|
|
|
private:
|
2016-12-06 18:47:16 +03:00
|
|
|
virtual void AddInput(BMediaInput* input);
|
|
|
|
virtual void AddOutput(BMediaOutput* output);
|
|
|
|
|
2016-11-25 19:29:17 +03:00
|
|
|
BMediaInput* FindInput(
|
2016-11-24 23:37:14 +03:00
|
|
|
const media_destination& dest) const;
|
2016-11-25 19:29:17 +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-12-17 20:52:51 +03:00
|
|
|
// Possible canditates for removal
|
|
|
|
void HandleTimeWarp(bigtime_t realTime,
|
|
|
|
bigtime_t performanceTime);
|
|
|
|
|
|
|
|
status_t SetTimeSource(
|
|
|
|
const media_client& timesource);
|
|
|
|
|
|
|
|
private:
|
2016-11-11 15:39:33 +03:00
|
|
|
void _Init();
|
|
|
|
void _Deinit();
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
bigtime_t fMinLatency;
|
|
|
|
bigtime_t fMaxLatency;
|
|
|
|
|
2016-11-25 19:29:17 +03:00
|
|
|
BObjectList<BMediaInput> fInputs;
|
|
|
|
BObjectList<BMediaOutput> 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
|