vfs: check userland buffers before reading them.
[haiku.git] / src / kits / media / experimental / SimpleMediaClient.cpp
blob0bc1d7640f174139184a5ac15722ff8b702febf2
1 /*
2 * Copyright 2015, Dario Casalinuovo. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
6 #include <SimpleMediaClient.h>
8 #include <debug.h>
11 BSimpleMediaClient::BSimpleMediaClient(const char* name,
12 media_type type, media_client_kinds kinds)
14 BMediaClient(name, type, kinds),
15 fNotifyHook(NULL),
16 fNotifyCookie(NULL)
18 CALLED();
22 BSimpleMediaClient::~BSimpleMediaClient()
24 CALLED();
28 BSimpleMediaInput*
29 BSimpleMediaClient::BeginInput()
31 CALLED();
33 BSimpleMediaInput* input = new BSimpleMediaInput();
34 RegisterInput(input);
35 return input;
39 BSimpleMediaOutput*
40 BSimpleMediaClient::BeginOutput()
42 CALLED();
44 BSimpleMediaOutput* output = new BSimpleMediaOutput();
45 RegisterOutput(output);
46 return output;
50 void
51 BSimpleMediaClient::SetHook(notify_hook notifyHook, void* cookie)
53 CALLED();
55 fNotifyHook = notifyHook;
56 fNotifyCookie = cookie;
60 void
61 BSimpleMediaClient::HandleStart(bigtime_t performanceTime)
63 if (fNotifyHook != NULL) {
64 (*fNotifyHook)(BSimpleMediaClient::fNotifyCookie,
65 BSimpleMediaClient::B_WILL_START,
66 performanceTime);
71 void
72 BSimpleMediaClient::HandleStop(bigtime_t performanceTime)
74 if (fNotifyHook != NULL) {
75 (*fNotifyHook)(BSimpleMediaClient::fNotifyCookie,
76 BSimpleMediaClient::B_WILL_STOP,
77 performanceTime);
82 void
83 BSimpleMediaClient::HandleSeek(bigtime_t mediaTime, bigtime_t performanceTime)
85 if (fNotifyHook != NULL) {
86 (*fNotifyHook)(BSimpleMediaClient::fNotifyCookie,
87 BSimpleMediaClient::B_WILL_SEEK,
88 performanceTime, mediaTime);
93 status_t
94 BSimpleMediaClient::FormatSuggestion(media_type type, int32 quality,
95 media_format* format)
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;
104 return B_ERROR;
108 void BSimpleMediaClient::_ReservedSimpleMediaClient0() {}
109 void BSimpleMediaClient::_ReservedSimpleMediaClient1() {}
110 void BSimpleMediaClient::_ReservedSimpleMediaClient2() {}
111 void BSimpleMediaClient::_ReservedSimpleMediaClient3() {}
112 void BSimpleMediaClient::_ReservedSimpleMediaClient4() {}
113 void BSimpleMediaClient::_ReservedSimpleMediaClient5() {}
116 BSimpleMediaConnection::BSimpleMediaConnection(media_connection_kinds kinds)
118 BMediaConnection(kinds),
119 fProcessHook(NULL),
120 fNotifyHook(NULL),
121 fBufferCookie(NULL)
126 BSimpleMediaConnection::~BSimpleMediaConnection()
128 CALLED();
132 void
133 BSimpleMediaConnection::SetHooks(process_hook processHook,
134 notify_hook notifyHook, void* cookie)
136 CALLED();
138 fProcessHook = processHook;
139 fNotifyHook = notifyHook;
140 fBufferCookie = cookie;
144 void*
145 BSimpleMediaConnection::Cookie() const
147 CALLED();
149 return fBufferCookie;
153 BSimpleMediaInput::BSimpleMediaInput()
155 BMediaConnection(B_MEDIA_INPUT),
156 BSimpleMediaConnection(B_MEDIA_INPUT),
157 BMediaInput()
162 BSimpleMediaInput::~BSimpleMediaInput()
164 CALLED();
168 void
169 BSimpleMediaInput::Connected(const media_format& format)
171 if (fNotifyHook != NULL)
172 (*fNotifyHook)(this, BSimpleMediaConnection::B_INPUT_CONNECTED);
174 BMediaInput::Connected(format);
178 void
179 BSimpleMediaInput::Disconnected()
181 if (fNotifyHook != NULL)
182 (*fNotifyHook)(this, BSimpleMediaConnection::B_INPUT_DISCONNECTED);
184 BMediaConnection::Disconnected();
188 void
189 BSimpleMediaInput::HandleBuffer(BBuffer* buffer)
191 CALLED();
193 if (fProcessHook != NULL)
194 (*fProcessHook)(this, buffer);
198 BSimpleMediaOutput::BSimpleMediaOutput()
200 BMediaConnection(B_MEDIA_OUTPUT),
201 BSimpleMediaConnection(B_MEDIA_OUTPUT),
202 BMediaOutput()
207 BSimpleMediaOutput::~BSimpleMediaOutput()
209 CALLED();
213 status_t
214 BSimpleMediaOutput::FormatProposal(media_format* format)
216 if (fNotifyHook != NULL) {
217 return (*fNotifyHook)(this,
218 BSimpleMediaConnection::B_FORMAT_PROPOSAL, format);
221 return BMediaOutput::FormatProposal(format);
225 void
226 BSimpleMediaOutput::Connected(const media_format& format)
228 if (fNotifyHook != NULL)
229 (*fNotifyHook)(this, BSimpleMediaConnection::B_OUTPUT_CONNECTED);
231 BSimpleMediaConnection::Connected(format);
235 void
236 BSimpleMediaOutput::Disconnected()
238 if (fNotifyHook != NULL)
239 (*fNotifyHook)(this, BSimpleMediaConnection::B_OUTPUT_DISCONNECTED);
241 BSimpleMediaConnection::Disconnected();