[rtmpdump] rtmpsuck duplicate filename patch
andrew.m.goth at gmail.com
Sun Apr 1 03:09:42 CEST 2012
(note: I am not subscribed; please Cc: me in responses)
While saving a stream, I had some network hiccup, and the player in my
browser reconnected and resumed playback where it had left off. This
caused rtmpsuck to overwrite the existing file to contain only the
section of the video following the break. It saw that one stream had
terminated and a new one began, but it didn't realize that maybe the new
stream might advertise the same filename as the old.
To fix, I modified rtmpsuck.c to check for duplicate filenames on disk
and alter the output filename so as to be unique. The unique names are
formed by appending "-" and one or more hexadecimal digits to the base
filename (which might already include a duplicate stream suffix,
described below). First it tries "-0", then "-1" if "-0" fails, then
"-2", etc., then "-f", then "-10", ..., then "-100", and so on.
While looking in the source, I found that there's already a duplicate
handler, though it appears to be for duplicate names within the stream,
or something to that effect. I couldn't help but notice that if it met
with more than 255 duplicates, it would overwrite the terminating NUL on
the filename and possibly subsequent bytes, resulting in chaos. I went
ahead and fixed that too. If there are 255 or fewer duplicates, it'll
behave as before. If more than 255, it'll use three- or more
hexadecimal digits for the duplicate counter.
I don't have a good way to test my change to the duplicate stream
handler, so I made a simple test harness containing only the digit
counting code and confirmed that it works. The duplicate filename
handler I tested by pre-creating a bunch of empty files with names
matching the stream names, some with "-" and hexadecimal digit suffixes.
I then ran rtmpsuck and saw that it picked sensible names for all new
files and didn't overwrite anything already on disk.
Patch attached. The patch is relative to today's git (2011-03-31).
Sorry, I don't know enough about git to give a more specific version
number. I went ahead and added a blurb to the changelog; I hope that's
okay. If not, you can just strip it out. Also, I tried to match the
existing coding style as best I could.
There's some obscene bit twiddling involved. I hope that's not a
problem. I needed to be able to figure out how many hexadecimal digits
are needed to represent a number.
opendir(), readdir(), rewinddir(), and closedir() are used. They're
portable, right? If not, someone who has access to the incompatible
systems will have to port. I only tested on Linux.
Oh hey, one more thing. Maybe mention in README how to make iptables
redirect traffic originating from other computers and being routed
through the machine. Here's what I'm using:
iptables -t nat -A PREROUTING -i wlan0 -p tcp --dport 1935 -j REDIRECT
Of course, you'll need to replace wlan0 with the proper interface from
which to redirect traffic. Or leave it out entirely.
Andy Goth | <andrew.m.goth/at/gmail/dot/com>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
More information about the rtmpdump