xref: /haiku/src/kits/media/experimental/SimpleMediaClient.cpp (revision e81a954787e50e56a7f06f72705b7859b6ab06d1)
1 /*
2  * Copyright 2015, Dario Casalinuovo. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 #include <SimpleMediaClient.h>
7 
8 #include <debug.h>
9 
10 
11 BSimpleMediaClient::BSimpleMediaClient(const char* name,
12 	media_type type, media_client_kinds kinds)
13 	:
14 	BMediaClient(name, type, kinds),
15 	fNotifyHook(NULL),
16 	fNotifyCookie(NULL)
17 {
18 	CALLED();
19 }
20 
21 
22 BSimpleMediaClient::~BSimpleMediaClient()
23 {
24 	CALLED();
25 }
26 
27 
28 BSimpleMediaInput*
29 BSimpleMediaClient::BeginInput()
30 {
31 	CALLED();
32 
33 	BSimpleMediaInput* input = new BSimpleMediaInput();
34 	RegisterInput(input);
35 	return input;
36 }
37 
38 
39 BSimpleMediaOutput*
40 BSimpleMediaClient::BeginOutput()
41 {
42 	CALLED();
43 
44 	BSimpleMediaOutput* output = new BSimpleMediaOutput();
45 	RegisterOutput(output);
46 	return output;
47 }
48 
49 
50 void
51 BSimpleMediaClient::SetHook(notify_hook notifyHook, void* cookie)
52 {
53 	CALLED();
54 
55 	fNotifyHook = notifyHook;
56 	fNotifyCookie = cookie;
57 }
58 
59 
60 void
61 BSimpleMediaClient::HandleStart(bigtime_t performanceTime)
62 {
63 	if (fNotifyHook != NULL) {
64 		(*fNotifyHook)(BSimpleMediaClient::fNotifyCookie,
65 			BSimpleMediaClient::B_WILL_START,
66 			performanceTime);
67 	}
68 }
69 
70 
71 void
72 BSimpleMediaClient::HandleStop(bigtime_t performanceTime)
73 {
74 	if (fNotifyHook != NULL) {
75 		(*fNotifyHook)(BSimpleMediaClient::fNotifyCookie,
76 			BSimpleMediaClient::B_WILL_STOP,
77 			performanceTime);
78 	}
79 }
80 
81 
82 void
83 BSimpleMediaClient::HandleSeek(bigtime_t mediaTime, bigtime_t performanceTime)
84 {
85 	if (fNotifyHook != NULL) {
86 		(*fNotifyHook)(BSimpleMediaClient::fNotifyCookie,
87 			BSimpleMediaClient::B_WILL_SEEK,
88 			performanceTime, mediaTime);
89 	}
90 }
91 
92 
93 status_t
94 BSimpleMediaClient::FormatSuggestion(media_type type, int32 quality,
95 	media_format* format)
96 {
97 	if (fNotifyHook != NULL) {
98 		status_t result = B_ERROR;
99 		(*fNotifyHook)(BSimpleMediaClient::fNotifyCookie,
100 			BSimpleMediaClient::B_FORMAT_SUGGESTION,
101 			type, quality, format, &result);
102 		return result;
103 	}
104 	return B_ERROR;
105 }
106 
107 
108 void BSimpleMediaClient::_ReservedSimpleMediaClient0() {}
109 void BSimpleMediaClient::_ReservedSimpleMediaClient1() {}
110 void BSimpleMediaClient::_ReservedSimpleMediaClient2() {}
111 void BSimpleMediaClient::_ReservedSimpleMediaClient3() {}
112 void BSimpleMediaClient::_ReservedSimpleMediaClient4() {}
113 void BSimpleMediaClient::_ReservedSimpleMediaClient5() {}
114 
115 
116 BSimpleMediaConnection::BSimpleMediaConnection(media_connection_kinds kinds)
117 	:
118 	BMediaConnection(kinds),
119 	fProcessHook(NULL),
120 	fNotifyHook(NULL),
121 	fBufferCookie(NULL)
122 {
123 }
124 
125 
126 BSimpleMediaConnection::~BSimpleMediaConnection()
127 {
128 	CALLED();
129 }
130 
131 
132 void
133 BSimpleMediaConnection::SetHooks(process_hook processHook,
134 	notify_hook notifyHook, void* cookie)
135 {
136 	CALLED();
137 
138 	fProcessHook = processHook;
139 	fNotifyHook = notifyHook;
140 	fBufferCookie = cookie;
141 }
142 
143 
144 void*
145 BSimpleMediaConnection::Cookie() const
146 {
147 	CALLED();
148 
149 	return fBufferCookie;
150 }
151 
152 
153 BSimpleMediaInput::BSimpleMediaInput()
154 	:
155 	BMediaConnection(B_MEDIA_INPUT),
156 	BSimpleMediaConnection(B_MEDIA_INPUT),
157 	BMediaInput()
158 {
159 }
160 
161 
162 BSimpleMediaInput::~BSimpleMediaInput()
163 {
164 	CALLED();
165 }
166 
167 
168 void
169 BSimpleMediaInput::Connected(const media_format& format)
170 {
171 	if (fNotifyHook != NULL)
172 		(*fNotifyHook)(this, BSimpleMediaConnection::B_INPUT_CONNECTED);
173 
174 	BMediaInput::Connected(format);
175 }
176 
177 
178 void
179 BSimpleMediaInput::Disconnected()
180 {
181 	if (fNotifyHook != NULL)
182 		(*fNotifyHook)(this, BSimpleMediaConnection::B_INPUT_DISCONNECTED);
183 
184 	BMediaConnection::Disconnected();
185 }
186 
187 
188 void
189 BSimpleMediaInput::HandleBuffer(BBuffer* buffer)
190 {
191 	CALLED();
192 
193 	if (fProcessHook != NULL)
194 		(*fProcessHook)(this, buffer);
195 }
196 
197 
198 BSimpleMediaOutput::BSimpleMediaOutput()
199 	:
200 	BMediaConnection(B_MEDIA_OUTPUT),
201 	BSimpleMediaConnection(B_MEDIA_OUTPUT),
202 	BMediaOutput()
203 {
204 }
205 
206 
207 BSimpleMediaOutput::~BSimpleMediaOutput()
208 {
209 	CALLED();
210 }
211 
212 
213 status_t
214 BSimpleMediaOutput::FormatProposal(media_format* format)
215 {
216 	if (fNotifyHook != NULL) {
217 		return (*fNotifyHook)(this,
218 			BSimpleMediaConnection::B_FORMAT_PROPOSAL, format);
219 	}
220 
221 	return BMediaOutput::FormatProposal(format);
222 }
223 
224 
225 void
226 BSimpleMediaOutput::Connected(const media_format& format)
227 {
228 	if (fNotifyHook != NULL)
229 		(*fNotifyHook)(this, BSimpleMediaConnection::B_OUTPUT_CONNECTED);
230 
231 	BSimpleMediaConnection::Connected(format);
232 }
233 
234 
235 void
236 BSimpleMediaOutput::Disconnected()
237 {
238 	if (fNotifyHook != NULL)
239 		(*fNotifyHook)(this, BSimpleMediaConnection::B_OUTPUT_DISCONNECTED);
240 
241 	BSimpleMediaConnection::Disconnected();
242 }
243