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