19b410c41SDario Casalinuovo/*
29b410c41SDario Casalinuovo * Copyright 2015, Dario Casalinuovo. All rights reserved.
39b410c41SDario Casalinuovo * Distributed under the terms of the MIT License.
49b410c41SDario Casalinuovo */
59b410c41SDario Casalinuovo
69b410c41SDario Casalinuovo#ifndef _MEDIA_CLIENT_NODE_H
79b410c41SDario Casalinuovo#define _MEDIA_CLIENT_NODE_H
89b410c41SDario Casalinuovo
99b410c41SDario Casalinuovo
109b410c41SDario Casalinuovo#include <BufferConsumer.h>
119b410c41SDario Casalinuovo#include <BufferProducer.h>
129b410c41SDario Casalinuovo#include <Controllable.h>
139b410c41SDario Casalinuovo#include <MediaDefs.h>
149b410c41SDario Casalinuovo#include <MediaEventLooper.h>
159b410c41SDario Casalinuovo
169b410c41SDario Casalinuovo
179b410c41SDario Casalinuovonamespace BPrivate { namespace media {
189b410c41SDario Casalinuovo
195854fc4aSDario Casalinuovo
209b410c41SDario Casalinuovoclass BMediaClient;
219b410c41SDario Casalinuovoclass BMediaConnection;
225854fc4aSDario Casalinuovoclass BMediaOutput;
239b410c41SDario Casalinuovo
249b410c41SDario Casalinuovoclass BMediaClientNode : public BBufferConsumer, public BBufferProducer,
259b410c41SDario Casalinuovo	public BMediaEventLooper {
269b410c41SDario Casalinuovopublic:
279b410c41SDario Casalinuovo							BMediaClientNode(const char* name,
289b410c41SDario Casalinuovo								BMediaClient* owner,
299b410c41SDario Casalinuovo								media_type type
309b410c41SDario Casalinuovo									= B_MEDIA_UNKNOWN_TYPE);
319b410c41SDario Casalinuovo
329b410c41SDario Casalinuovo	// Various useful stuff
339b410c41SDario Casalinuovo
349b410c41SDario Casalinuovo			status_t		SendBuffer(BBuffer* buffer, BMediaConnection* conn);
359b410c41SDario Casalinuovo
369b410c41SDario Casalinuovoprotected:
379b410c41SDario Casalinuovo
389b410c41SDario Casalinuovo	virtual	BMediaAddOn*	AddOn(int32* id) const;
399b410c41SDario Casalinuovo
409b410c41SDario Casalinuovo	virtual void			NodeRegistered();
419b410c41SDario Casalinuovo
429b410c41SDario Casalinuovo	virtual void			SetRunMode(run_mode mode);
439b410c41SDario Casalinuovo
449b410c41SDario Casalinuovo	virtual	void			Start(bigtime_t performanceTime);
459b410c41SDario Casalinuovo
469b410c41SDario Casalinuovo	virtual	void			Stop(bigtime_t performanceTime,
479b410c41SDario Casalinuovo								bool immediate);
489b410c41SDario Casalinuovo
499b410c41SDario Casalinuovo	virtual	void			Seek(bigtime_t mediaTime,
509b410c41SDario Casalinuovo								bigtime_t performanceTime);
519b410c41SDario Casalinuovo
529b410c41SDario Casalinuovo	virtual	void			TimeWarp(bigtime_t realTime,
539b410c41SDario Casalinuovo								bigtime_t performanceTime);
549b410c41SDario Casalinuovo
559b410c41SDario Casalinuovo	virtual	status_t		HandleMessage(int32 message,
569b410c41SDario Casalinuovo								const void* data,
579b410c41SDario Casalinuovo								size_t size);
589b410c41SDario Casalinuovo
599b410c41SDario Casalinuovo	// BBufferConsumer
609b410c41SDario Casalinuovo
619b410c41SDario Casalinuovo	virtual	status_t		AcceptFormat(const media_destination& dest,
629b410c41SDario Casalinuovo								media_format* format);
639b410c41SDario Casalinuovo
649b410c41SDario Casalinuovo	virtual	status_t		GetNextInput(int32* cookie,
659b410c41SDario Casalinuovo								media_input* input);
669b410c41SDario Casalinuovo
679b410c41SDario Casalinuovo	virtual	void			DisposeInputCookie(int32 cookie);
689b410c41SDario Casalinuovo
699b410c41SDario Casalinuovo	virtual	void			BufferReceived(BBuffer* buffer);
709b410c41SDario Casalinuovo
719b410c41SDario Casalinuovo	virtual	status_t		GetLatencyFor(const media_destination& dest,
729b410c41SDario Casalinuovo								bigtime_t* latency,
739b410c41SDario Casalinuovo								media_node_id* timesource);
749b410c41SDario Casalinuovo
759b410c41SDario Casalinuovo	virtual	status_t		Connected(const media_source& source,
763c1e0133SDario Casalinuovo								const media_destination& dest,
779b410c41SDario Casalinuovo								const media_format& format,
789b410c41SDario Casalinuovo								media_input* outInput);
799b410c41SDario Casalinuovo
809b410c41SDario Casalinuovo	virtual	void			Disconnected(const media_source& source,
813c1e0133SDario Casalinuovo								const media_destination& dest);
829b410c41SDario Casalinuovo
839b410c41SDario Casalinuovo	virtual	status_t		FormatChanged(const media_source& source,
849b410c41SDario Casalinuovo								const media_destination& consumer,
859b410c41SDario Casalinuovo								int32 tag,
869b410c41SDario Casalinuovo								const media_format& format);
879b410c41SDario Casalinuovo
889b410c41SDario Casalinuovo	// BBufferProducer
899b410c41SDario Casalinuovo
909b410c41SDario Casalinuovo	virtual 	status_t 	FormatSuggestionRequested(media_type type,
919b410c41SDario Casalinuovo									int32 quality, media_format* format);
929b410c41SDario Casalinuovo	virtual 	status_t 	FormatProposal(const media_source& source,
939b410c41SDario Casalinuovo									media_format *format);
949b410c41SDario Casalinuovo	virtual 	status_t 	FormatChangeRequested(const media_source& source,
959b410c41SDario Casalinuovo									const media_destination& dest,
969b410c41SDario Casalinuovo									media_format *format,
979b410c41SDario Casalinuovo									int32* _deprecated_);
989b410c41SDario Casalinuovo	virtual 	void 		LateNoticeReceived(const media_source& source,
999b410c41SDario Casalinuovo									bigtime_t late,	bigtime_t when);
1009b410c41SDario Casalinuovo	virtual 	status_t	GetNextOutput(int32 *cookie, media_output *output);
1019b410c41SDario Casalinuovo	virtual 	status_t 	DisposeOutputCookie(int32 cookie);
1029b410c41SDario Casalinuovo	virtual 	status_t	SetBufferGroup(const media_source& source,
1039b410c41SDario Casalinuovo									BBufferGroup *group);
1049b410c41SDario Casalinuovo	virtual 	status_t 	PrepareToConnect(const media_source& source,
1059b410c41SDario Casalinuovo									const media_destination& dest,
1069b410c41SDario Casalinuovo									media_format *format,
1079b410c41SDario Casalinuovo									media_source *out_source,
1089b410c41SDario Casalinuovo									char *name);
1099b410c41SDario Casalinuovo	virtual 	void 		Connect(status_t status,
1109b410c41SDario Casalinuovo									const media_source& source,
1119b410c41SDario Casalinuovo									const media_destination& dest,
1129b410c41SDario Casalinuovo									const media_format &format,
1139b410c41SDario Casalinuovo									char* name);
1149b410c41SDario Casalinuovo	virtual		void 		Disconnect(const media_source& source,
1159b410c41SDario Casalinuovo									const media_destination& dest);
1169b410c41SDario Casalinuovo	virtual 	void 		EnableOutput(const media_source& source,
1179b410c41SDario Casalinuovo									bool enabled, int32* _deprecated_);
1189b410c41SDario Casalinuovo	virtual 	status_t 	GetLatency(bigtime_t *outLatency);
1199b410c41SDario Casalinuovo	virtual 	void 		LatencyChanged(	const media_source& source,
1209b410c41SDario Casalinuovo									const media_destination& dest,
1219b410c41SDario Casalinuovo									bigtime_t latency, uint32 flags);
1229b410c41SDario Casalinuovo
1239b410c41SDario Casalinuovo				void 		ProducerDataStatus(const media_destination& dest,
1249b410c41SDario Casalinuovo								int32 status, bigtime_t when);
1259b410c41SDario Casalinuovoprotected:
1269b410c41SDario Casalinuovo	virtual 	void 		HandleEvent(const media_timed_event *event,
1279b410c41SDario Casalinuovo									bigtime_t late,
1289b410c41SDario Casalinuovo									bool realTimeEvent=false);
1299b410c41SDario Casalinuovo
1309b410c41SDario Casalinuovo	virtual					~BMediaClientNode();
1319b410c41SDario Casalinuovo
1329b410c41SDario Casalinuovoprivate:
1332c9fa0f2SDario Casalinuovo				void		_ScheduleConnections(bigtime_t eventTime);
1349b410c41SDario Casalinuovo				void		_HandleBuffer(BBuffer* buffer);
1359b410c41SDario Casalinuovo				void		_ProduceNewBuffer(const media_timed_event* event,
1369b410c41SDario Casalinuovo								bigtime_t late);
1375854fc4aSDario Casalinuovo				BBuffer*	_GetNextBuffer(BMediaOutput* output,
1385854fc4aSDario Casalinuovo								bigtime_t eventTime);
1399b410c41SDario Casalinuovo
1409b410c41SDario Casalinuovo			BMediaClient*	fOwner;
1412c9fa0f2SDario Casalinuovo			bigtime_t		fStartTime;
1429b410c41SDario Casalinuovo};
1439b410c41SDario Casalinuovo
1449b410c41SDario Casalinuovo}
1459b410c41SDario Casalinuovo}
1469b410c41SDario Casalinuovo
1479b410c41SDario Casalinuovousing namespace BPrivate::media;
1489b410c41SDario Casalinuovo
1499b410c41SDario Casalinuovo#endif
150