summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/include/TimedEventQueue.h
diff options
context:
space:
mode:
authorAndreas Huber <andih@google.com>2009-11-17 10:25:01 -0800
committerAndreas Huber <andih@google.com>2009-11-17 10:29:32 -0800
commitbe11f392a8b8ff1006cf536350cc8a85f8788ff4 (patch)
treeb01deb5339fb3b15db63fa6d021cce441dfe1be1 /media/libstagefright/include/TimedEventQueue.h
parent057eacf4578ac6b90ee18c524670e01445bf2732 (diff)
downloadframeworks_av-be11f392a8b8ff1006cf536350cc8a85f8788ff4.zip
frameworks_av-be11f392a8b8ff1006cf536350cc8a85f8788ff4.tar.gz
frameworks_av-be11f392a8b8ff1006cf536350cc8a85f8788ff4.tar.bz2
Improvements to TimedEventQueue.
Events are now cancelled given their "unique" event_id instead of the event pointer itself (which may be reallocated in place if we're unlucky). Also the ability to cancel multiple events matching a predicate has been added.
Diffstat (limited to 'media/libstagefright/include/TimedEventQueue.h')
-rw-r--r--media/libstagefright/include/TimedEventQueue.h36
1 files changed, 30 insertions, 6 deletions
diff --git a/media/libstagefright/include/TimedEventQueue.h b/media/libstagefright/include/TimedEventQueue.h
index a264421..21eade3 100644
--- a/media/libstagefright/include/TimedEventQueue.h
+++ b/media/libstagefright/include/TimedEventQueue.h
@@ -28,16 +28,31 @@ namespace android {
struct TimedEventQueue {
+ typedef int32_t event_id;
+
struct Event : public RefBase {
- Event() {}
+ Event()
+ : mEventID(0) {
+ }
+
virtual ~Event() {}
+ event_id eventID() {
+ return mEventID;
+ }
+
protected:
virtual void fire(TimedEventQueue *queue, int64_t now_us) = 0;
private:
friend class TimedEventQueue;
+ event_id mEventID;
+
+ void setEventID(event_id id) {
+ mEventID = id;
+ }
+
Event(const Event &);
Event &operator=(const Event &);
};
@@ -55,21 +70,29 @@ struct TimedEventQueue {
// Posts an event to the front of the queue (after all events that
// have previously been posted to the front but before timed events).
- void postEvent(const sp<Event> &event);
+ event_id postEvent(const sp<Event> &event);
- void postEventToBack(const sp<Event> &event);
+ event_id postEventToBack(const sp<Event> &event);
// It is an error to post an event with a negative delay.
- void postEventWithDelay(const sp<Event> &event, int64_t delay_us);
+ event_id postEventWithDelay(const sp<Event> &event, int64_t delay_us);
// If the event is to be posted at a time that has already passed,
// it will fire as soon as possible.
- void postTimedEvent(const sp<Event> &event, int64_t realtime_us);
+ event_id postTimedEvent(const sp<Event> &event, int64_t realtime_us);
// Returns true iff event is currently in the queue and has been
// successfully cancelled. In this case the event will have been
// removed from the queue and won't fire.
- bool cancelEvent(const sp<Event> &event);
+ bool cancelEvent(event_id id);
+
+ // Cancel any pending event that satisfies the predicate.
+ // If stopAfterFirstMatch is true, only cancels the first event
+ // satisfying the predicate (if any).
+ void cancelEvents(
+ bool (*predicate)(void *cookie, const sp<Event> &event),
+ void *cookie,
+ bool stopAfterFirstMatch = false);
static int64_t getRealTimeUs();
@@ -90,6 +113,7 @@ private:
Mutex mLock;
Condition mQueueNotEmptyCondition;
Condition mQueueHeadChangedCondition;
+ event_id mNextEventID;
bool mRunning;
bool mStopped;