[Swfdec] Porting Swfdec to Mac OS X & Timing question

Nick Zitzmann seiryu at comcast.net
Mon Sep 1 09:20:16 PDT 2008


Hi all:

I've been working on porting Swfdec to Mac OS X on my own time. So far  
I'm making some progress; stuff is displaying and events are working.  
I still have a bit of work to do, but in the meantime, I have some  
questions:

1. How does one get the ability to commit things to the repository? I  
don't expect this right away; I'll probably just distribute the Mac OS  
X specific files separately at first, but it would be nice to be able  
to use the repository at some point in the future...

2. I also have a question about timing. Here is my current timer code;  
it's written in Objective-C but should be quite readable:

- (void)scheduleNextEvent
{
	glong millisecondsToNextEvent = swfdec_player_get_next_event(_private- 
 >_player);
	
	[_private->_nextEventTimer release];
	_private->_nextEventTimer = nil;
	
	if (millisecondsToNextEvent == -1)	// nothing's going on, so do nothing
		return;
	else if (millisecondsToNextEvent == 0)	// we need to trigger the next  
event immediately
	{
		swfdec_player_advance(_private->_player, millisecondsToNextEvent);
		if (swfdec_player_is_initialized(_private->_player))
		{
			unsigned int width, height;
			
			swfdec_player_get_default_size(_private->_player, &width, &height);
			[self setBounds:NSMakeRect(0.0, 0.0, width, height)];
			[self setNeedsDisplay:YES];
		}
		[[NSRunLoop currentRunLoop]  
performSelector:@selector(scheduleNextEvent) target:self argument:nil  
order:100 modes:[NSArray arrayWithObject:NSDefaultRunLoopMode]];
	}
	else
	{
		NSTimeInterval fMillisecondsToNextEvent = millisecondsToNextEvent;
		
		fMillisecondsToNextEvent /= 1000000.0;	// translate to seconds so we  
can use NSTimer
		_private->_timeOfLastTimer = CFAbsoluteTimeGetCurrent();
		_private->_nextEventTimer = [[NSTimer  
scheduledTimerWithTimeInterval:fMillisecondsToNextEvent target:self  
selector:@selector(triggerNextEvent:) userInfo:nil repeats:NO] retain];
	}
}


- (void)triggerNextEvent:(NSTimer *)timer
{
	CFAbsoluteTime timeElapsed = CFAbsoluteTimeGetCurrent()-_private- 
 >_timeOfLastTimer;
	
	swfdec_player_advance(_private->_player, timeElapsed*1000000.0);
	if (swfdec_player_is_initialized(_private->_player))
		[self setNeedsDisplay:YES];
	[self scheduleNextEvent];
}

Here's what the code does:

a. When -scheduleNextEvent is called, it gets the time to the next  
event. If it is 0, then it triggers the next event immediately, and  
schedules itself to run again the next time the run loop cycles around.
b. If it is a positive number, then it converts the time to seconds,  
and schedules a timer to trigger after the given time has elapsed.
c. The timer calls -triggerNextEvent:, which triggers the next event  
using the time that elapsed between -scheduleNextEvent and - 
triggerNextEvent:, updates the display, and calls -scheduleNextEvent  
to schedule the next event.

I get the feeling that I'm doing this way wrong, though, because  
everything happens either way too fast or way too slowly, depending on  
the size of the drawing view. How do I do this correctly? What did I  
not understand?

Nick Zitzmann
<http://seiryu.home.comcast.net/>
S/MIME signature available upon request






More information about the Swfdec mailing list