1
/* $Id: event.h 3905 2011-12-09 05:15:39Z ming $ */
3
* Copyright (C) 2011-2011 Teluu Inc. (http://www.teluu.com)
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
#ifndef __PJMEDIA_EVENT_H__
20
#define __PJMEDIA_EVENT_H__
23
* @file pjmedia/event.h
24
* @brief Event framework
26
#include <pjmedia/format.h>
27
#include <pjmedia/signatures.h>
32
* @defgroup PJMEDIA_EVENT Event Framework
33
* @brief PJMEDIA event framework
38
* This enumeration describes list of media events.
40
typedef enum pjmedia_event_type
48
* Media format has changed event.
50
PJMEDIA_EVENT_FMT_CHANGED = PJMEDIA_FOURCC('F', 'M', 'C', 'H'),
53
* Video window is being closed.
55
PJMEDIA_EVENT_WND_CLOSING = PJMEDIA_FOURCC('W', 'N', 'C', 'L'),
58
* Video window has been closed event.
60
PJMEDIA_EVENT_WND_CLOSED = PJMEDIA_FOURCC('W', 'N', 'C', 'O'),
63
* Video window has been resized event.
65
PJMEDIA_EVENT_WND_RESIZED = PJMEDIA_FOURCC('W', 'N', 'R', 'Z'),
68
* Mouse button has been pressed event.
70
PJMEDIA_EVENT_MOUSE_BTN_DOWN = PJMEDIA_FOURCC('M', 'S', 'D', 'N'),
73
* Video keyframe has just been decoded event.
75
PJMEDIA_EVENT_KEYFRAME_FOUND = PJMEDIA_FOURCC('I', 'F', 'R', 'F'),
78
* Video decoding error due to missing keyframe event.
80
PJMEDIA_EVENT_KEYFRAME_MISSING = PJMEDIA_FOURCC('I', 'F', 'R', 'M'),
83
* Video orientation has been changed event.
85
PJMEDIA_EVENT_ORIENT_CHANGED = PJMEDIA_FOURCC('O', 'R', 'N', 'T')
90
* Additional data/parameters for media format changed event
91
* (PJMEDIA_EVENT_FMT_CHANGED).
93
typedef struct pjmedia_event_fmt_changed_data
95
/** The media flow direction */
98
/** The new media format. */
99
pjmedia_format new_fmt;
100
} pjmedia_event_fmt_changed_data;
103
* Additional data/parameters are not needed.
105
typedef struct pjmedia_event_dummy_data
109
} pjmedia_event_dummy_data;
112
* Additional data/parameters for window resized event
113
* (PJMEDIA_EVENT_WND_RESIZED).
115
typedef struct pjmedia_event_wnd_resized_data
118
* The new window size.
120
pjmedia_rect_size new_size;
121
} pjmedia_event_wnd_resized_data;
124
* Additional data/parameters for window closing event.
126
typedef struct pjmedia_event_wnd_closing_data
128
/** Consumer may set this field to PJ_TRUE to cancel the closing */
130
} pjmedia_event_wnd_closing_data;
132
/** Additional parameters for window changed event. */
133
typedef pjmedia_event_dummy_data pjmedia_event_wnd_closed_data;
135
/** Additional parameters for mouse button down event */
136
typedef pjmedia_event_dummy_data pjmedia_event_mouse_btn_down_data;
138
/** Additional parameters for keyframe found event */
139
typedef pjmedia_event_dummy_data pjmedia_event_keyframe_found_data;
141
/** Additional parameters for keyframe missing event */
142
typedef pjmedia_event_dummy_data pjmedia_event_keyframe_missing_data;
145
* Maximum size of additional parameters section in pjmedia_event structure
147
#define PJMEDIA_EVENT_DATA_MAX_SIZE sizeof(pjmedia_event_fmt_changed_data)
149
/** Type of storage to hold user data in pjmedia_event structure */
150
typedef char pjmedia_event_user_data[PJMEDIA_EVENT_DATA_MAX_SIZE];
153
* This structure describes a media event. It consists mainly of the event
154
* type and additional data/parameters for the event. Applications can
155
* use #pjmedia_event_init() to initialize this event structure with
156
* basic information about the event.
158
typedef struct pjmedia_event
163
pjmedia_event_type type;
166
* The media timestamp when the event occurs.
168
pj_timestamp timestamp;
171
* Pointer information about the source of this event. This field
172
* is provided mainly for comparison purpose so that event subscribers
173
* can check which source the event originated from. Usage of this
174
* pointer for other purpose may require special care such as mutex
175
* locking or checking whether the object is already destroyed.
180
* Pointer information about the publisher of this event. This field
181
* is provided mainly for comparison purpose so that event subscribers
182
* can check which object published the event. Usage of this
183
* pointer for other purpose may require special care such as mutex
184
* locking or checking whether the object is already destroyed.
189
* Additional data/parameters about the event. The type of data
190
* will be specific to the event type being reported.
193
/** Media format changed event data. */
194
pjmedia_event_fmt_changed_data fmt_changed;
196
/** Window resized event data */
197
pjmedia_event_wnd_resized_data wnd_resized;
199
/** Window closing event data. */
200
pjmedia_event_wnd_closing_data wnd_closing;
202
/** Window closed event data */
203
pjmedia_event_wnd_closed_data wnd_closed;
205
/** Mouse button down event data */
206
pjmedia_event_mouse_btn_down_data mouse_btn_down;
208
/** Keyframe found event data */
209
pjmedia_event_keyframe_found_data keyframe_found;
211
/** Keyframe missing event data */
212
pjmedia_event_keyframe_missing_data keyframe_missing;
214
/** Storage for user event data */
215
pjmedia_event_user_data user;
217
/** Pointer to storage to user event data, if it's outside
225
* The callback to receive media events.
227
* @param event The media event.
228
* @param user_data The user data associated with the callback.
230
* @return If the callback returns non-PJ_SUCCESS, this return
231
* code may be propagated back to the caller.
233
typedef pj_status_t pjmedia_event_cb(pjmedia_event *event,
237
* This enumeration describes flags for event publication via
238
* #pjmedia_event_publish().
240
typedef enum pjmedia_event_publish_flag
243
* Publisher will only post the event to the event manager. It is the
244
* event manager that will later notify all the publisher's subscribers.
246
PJMEDIA_EVENT_PUBLISH_POST_EVENT = 1
248
} pjmedia_event_publish_flag;
251
* Event manager flag.
253
typedef enum pjmedia_event_mgr_flag
256
* Tell the event manager not to create any event worker thread.
258
PJMEDIA_EVENT_MGR_NO_THREAD = 1
260
} pjmedia_event_mgr_flag;
263
* Opaque data type for event manager. Typically, the event manager
264
* is a singleton instance, although application may instantiate more than one
265
* instances of this if required.
267
typedef struct pjmedia_event_mgr pjmedia_event_mgr;
270
* Create a new event manager instance. This will also set the pointer
271
* to the singleton instance if the value is still NULL.
273
* @param pool Pool to allocate memory from.
274
* @param options Options. Bitmask flags from #pjmedia_event_mgr_flag
275
* @param mgr Pointer to hold the created instance of the
278
* @return PJ_SUCCESS on success or the appropriate error code.
280
PJ_DECL(pj_status_t) pjmedia_event_mgr_create(pj_pool_t *pool,
282
pjmedia_event_mgr **mgr);
285
* Get the singleton instance of the event manager.
287
* @return The instance.
289
PJ_DECL(pjmedia_event_mgr*) pjmedia_event_mgr_instance(void);
292
* Manually assign a specific event manager instance as the singleton
293
* instance. Normally this is not needed if only one instance is ever
294
* going to be created, as the library automatically assign the singleton
297
* @param mgr The instance to be used as the singleton instance.
298
* Application may specify NULL to clear the singleton
299
* singleton instance.
301
PJ_DECL(void) pjmedia_event_mgr_set_instance(pjmedia_event_mgr *mgr);
304
* Destroy an event manager. If the manager happens to be the singleton
305
* instance, the singleton instance will be set to NULL.
307
* @param mgr The eventmanager. Specify NULL to use
308
* the singleton instance.
310
PJ_DECL(void) pjmedia_event_mgr_destroy(pjmedia_event_mgr *mgr);
313
* Initialize event structure with basic data about the event.
315
* @param event The event to be initialized.
316
* @param type The event type to be set for this event.
317
* @param ts Event timestamp. May be set to NULL to set the event
319
* @param src Event source.
321
PJ_DECL(void) pjmedia_event_init(pjmedia_event *event,
322
pjmedia_event_type type,
323
const pj_timestamp *ts,
327
* Subscribe a callback function to events published by the specified
328
* publisher. Note that the subscriber may receive not only events emitted by
329
* the specific publisher specified in the argument, but also from other
330
* publishers contained by the publisher, if the publisher is republishing
331
* events from other publishers.
333
* @param mgr The event manager.
334
* @param cb The callback function to receive the event.
335
* @param user_data The user data to be associated with the callback
337
* @param epub The event publisher.
339
* @return PJ_SUCCESS on success or the appropriate error code.
341
PJ_DECL(pj_status_t) pjmedia_event_subscribe(pjmedia_event_mgr *mgr,
342
pjmedia_event_cb *cb,
347
* Unsubscribe the callback associated with the user data from a publisher.
348
* If the user data is not specified, this function will do the
349
* unsubscription for all user data. If the publisher, epub, is not
350
* specified, this function will do the unsubscription from all publishers.
352
* @param mgr The event manager.
353
* @param cb The callback function.
354
* @param user_data The user data associated with the callback
355
* function, can be NULL.
356
* @param epub The event publisher, can be NULL.
358
* @return PJ_SUCCESS on success or the appropriate error code.
361
pjmedia_event_unsubscribe(pjmedia_event_mgr *mgr,
362
pjmedia_event_cb *cb,
367
* Publish the specified event to all subscribers of the specified event
368
* publisher. By default, the function will call all the subcribers'
369
* callbacks immediately. If the publisher uses the flag
370
* PJMEDIA_EVENT_PUBLISH_POST_EVENT, publisher will only post the event
371
* to the event manager and return immediately. It is the event manager
372
* that will later notify all the publisher's subscribers.
374
* @param mgr The event manager.
375
* @param epub The event publisher.
376
* @param event The event to be published.
377
* @param flag Publication flag.
379
* @return PJ_SUCCESS only if all subscription callbacks returned
382
PJ_DECL(pj_status_t) pjmedia_event_publish(pjmedia_event_mgr *mgr,
384
pjmedia_event *event,
385
pjmedia_event_publish_flag flag);
395
#endif /* __PJMEDIA_EVENT_H__ */