SimpleMediaClient.h revision d64dd7be
1/*
2 * Copyright 2015, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5
6#ifndef _MEDIA_SIMPLE_CLIENT_H
7#define _MEDIA_SIMPLE_CLIENT_H
8
9#include <MediaClient.h>
10#include <MediaConnection.h>
11
12
13namespace BPrivate { namespace media {
14
15
16class BSimpleMediaInput;
17class BSimpleMediaOutput;
18
19class BSimpleMediaClient : public BMediaClient {
20public:
21	enum notification {
22		B_WILL_START = 1,			// performance_time
23		B_WILL_STOP,				// performance_time immediate
24		B_WILL_SEEK,				// performance_time media_time
25
26		B_FORMAT_SUGGESTION,		// media_type type, int32 quality,
27									// media_format* format
28	};
29
30	typedef void					(*notify_hook)(void* cookie,
31											notification what,
32											...);
33
34									BSimpleMediaClient(const char* name,
35										media_type type
36											= B_MEDIA_UNKNOWN_TYPE,
37										media_client_kinds
38											kinds = B_MEDIA_PLAYER
39												& B_MEDIA_RECORDER);
40
41	virtual							~BSimpleMediaClient();
42
43	// This is supplied to support generic connections not related
44	// to a certain destination or source node, however for various ambiguity
45	// reasons we want the BMediaConnection to be declared as input or output.
46	// You can pass the object returned by this function to another
47	// BMediaClient::Connect(), so that it will automatically connect to this node.
48	virtual BSimpleMediaInput*		BeginInput();
49	virtual BSimpleMediaOutput*		BeginOutput();
50
51			void					SetNotificationHook(notify_hook notifyHook = NULL,
52										void* cookie = NULL);
53
54protected:
55	virtual void					HandleStart(bigtime_t performanceTime);
56	virtual void					HandleStop(bigtime_t performanceTime);
57
58	virtual void					HandleSeek(bigtime_t mediaTime,
59										bigtime_t performanceTime);
60
61	virtual status_t				HandleFormatSuggestion(media_type type,
62										int32 quality, media_format* format);
63
64private:
65			notify_hook				fNotifyHook;
66			void*					fNotifyCookie;
67
68	virtual	void					_ReservedSimpleMediaClient0();
69	virtual	void					_ReservedSimpleMediaClient1();
70	virtual	void					_ReservedSimpleMediaClient2();
71	virtual	void					_ReservedSimpleMediaClient3();
72	virtual	void					_ReservedSimpleMediaClient4();
73	virtual	void					_ReservedSimpleMediaClient5();
74			uint32					fPadding[32];
75};
76
77
78class BSimpleMediaConnection : public virtual BMediaConnection {
79public:
80	enum notification {
81		// Inputs
82		B_INPUT_CONNECTED = 1,
83		B_INPUT_DISCONNECTED,
84
85		B_FORMAT_CHANGED,
86
87		// Outputs
88		B_OUTPUT_CONNECTED,
89		B_OUTPUT_DISCONNECTED,
90
91		B_PREPARE_TO_CONNECT,	// media_format* format, media_source* source,
92								// char* name
93
94		B_FORMAT_PROPOSAL,		// media_format* format
95		B_ASK_FORMAT_CHANGE,
96	};
97
98	// This function is called when it is the moment to handle a buffer.
99	typedef void					(*process_hook)(
100										BMediaConnection* connection,
101										BBuffer* buffer);
102
103	// Used to notify or inquire the client about what to do when certain
104	// events happen.
105	typedef status_t				(*notify_hook)(
106										notification what,
107										BMediaConnection* connection,
108										...);
109
110			// Use this to set your callbacks.
111			void					SetHooks(process_hook processHook = NULL,
112										notify_hook notifyHook = NULL,
113										void* cookie = NULL);
114
115			void*					Cookie() const;
116
117protected:
118									BSimpleMediaConnection(
119										media_connection_kinds kinds);
120
121			process_hook			fProcessHook;
122			notify_hook				fNotifyHook;
123			void*					fBufferCookie;
124};
125
126
127class BSimpleMediaInput : public BSimpleMediaConnection, public BMediaInput {
128public:
129									BSimpleMediaInput();
130
131protected:
132	virtual void					Connected(const media_format& format);
133	virtual void					Disconnected();
134
135	virtual void					BufferReceived(BBuffer* buffer);
136};
137
138
139class BSimpleMediaOutput : public BSimpleMediaConnection, public BMediaOutput {
140public:
141									BSimpleMediaOutput();
142
143protected:
144	virtual void					Connected(const media_format& format);
145	virtual void					Disconnected();
146
147	virtual status_t				FormatProposal(media_format* format);
148};
149
150
151}
152
153}
154
155using namespace BPrivate::media;
156
157#endif
158