So someone recently asked me how to hack on Swfdec. And since that might be interesting to others, I thought I’d blog about it. One thing to note: All the action these days is in the “as” branch, which will become Swfdec 0.5 in the near future.
So the first thing I do is download the file I want to make work. Surprisingly, the Swfdec Mozilla plugin allows downloading Flash files from its properties dialog, which you can get to by right-clicking on the playing file.
Now I play the file with the little application (in Swfdec’s git checkout) player/swfplay inside a terminal. It will spew out debugging information. A lot of this debugging information will be about missing features. So I start at the top and implement all those missing features, most of the time by writing accompanying tests. (How to easily write good tests is a post as big as this, so I’ll leave that out for now. Poke me to write it if you care.)
Here’s a few of the more common messages and what to do about it:
SWFDEC: ERROR: swfdec_script.c(198): validate_action: no function for 36 0x24 CloneSprite in v6
This means a bytecode isn’t implemented yet. The bytecode interpreter is in libswfdec/swfdec_as_interpret.c – just add the function there that does the right thing.
SWFDEC: ERROR: swfdec_as_interpret.c(678): swfdec_action_call_method: no function named createEmptyMovieClip
An Actionscript function isn’t implemented. First I figure out what object it belongs to and what it does by looking at Brajeshwar’s excellent Actionscript reference. Then I implement it. Note that a lot of function have really weird effects if called with unexpected parameters. So it really helps to write tests here.
SWFDEC: WARN : swfdec_as_interpret.c(1316): swfdec_action_new_object: Sound is not a constructor
It looks like an object isn’t implemented at all. So I do the same thing as above. I implement it, then run player/swfplay to see which functions on the object are used and implement those.
If I managed to implement all the functions that needed to be implemented and it still doesn’t work, then the hard work starts. That’s where I launch player/swfdebug and step through the code looking if what it does is sane. Swfdebug is a nice little tools for debugging Flash files that unfortunately is a little crashy and accumulates features as I need them. There’s also some tools in the test/ directory that help understanding particular Flash files, in particular test/dump that dumps information about the static content of a file (run with -v for maximum output) or test/swfdec-extract that can extract contents of Flash files to png or svg and I think it even extracts audio these days.
And when I’m finally done doing all this, I have one more file to play with. And most of the time I also know 3 more places that need serious refactoring…
So, if you now want to hack on Swfdec, a good idea is to come to IRC on Freenode, channel #swfdec and start asking questions. If you don’t want to use IRC, you can also mail the mailing list, just reading commit messages there is boring anyway.
4 comments ↓
Nice explanation, but is there any internal documentation? I’d like to implement MovieClip::loadMovie but don’t really have an idea where to start :) Well, I do have a method that is called and prints the name of the clip to load so that’s easy enough, but then? Oh well :) I’ll just load that manually and see what is missing in it ;)
Fantastic work on swfdec, Ben. Thanks very much.
Since i had some trouble to find the exact command to checkout the as branch, here is how to do a checkout, in case someone has the same problem :
git clone git://swfdec.freedesktop.org/git/swfdec
cd swfdec
git checkout -b origin/as
check with git branch that you are using the good one :
$ git branch
master
* origin/as
( and then this is the usual stuff )
Hi Benjamin,
nice. Would you consider using trac instead of git http://www.techenclave.com/forums/trac-enhanced-wiki-issue-tracking-system-91435.html
Although I’m no developer but do find that trac is much more easier to know about roadmap & what feature-set is missing for next release.
http://www.hosted-projects.com/trac/TracDemo/Demo/wiki
Try it & see what you think ;)