Handle RTMP redirect

This patch allows RtmpDump to follow RTMP URL redirects. Before this you could
run rtmpdump --verbose and see the redirect URL

DEBUG: Property: <Name:      redirect, STRING:     rtmp://46.19.140.146:190/vod>

This patch simply automates the following process. Taken from KSV patch file
http://github.com/downloads/K-S-V/Scripts/rtmpdump-2.4.zip
Tested on
http://datastreaming.altervista.org/LA7.html
Check bandwidth response

With RtmpSrv, some servers will cause RtmpSrv to stop at this step

  WARNING: Trying different position for client digest!

With these servers the bandwidth needs to be checked from client to server.

Taken from KSV patch file
http://github.com/downloads/K-S-V/Scripts/rtmpdump-2.4.zip
Tested with
http://kanalia.eu/player.php?id=91
Related link
http://wowza.com/forums/content.php?252
ConnectPacket

Some servers were causing RtmpDump to stop at this step

  DEBUG: Invoking connect
  INFO: Connected...
  ERROR: RTMP_ReadPacket, failed to read RTMP packet header
  DEBUG: Closing connection.

Ref
http://github.com/downloads/K-S-V/Scripts/rtmpdump-2.4.zip
http://lists.mplayerhq.hu/pipermail/rtmpdump/2011-December/001756.html
Problem server
http://tvpublica.com.ar/vivo
Other tested servers
http://canaldosconcursos.com.br/video_demo.php?id_cursos=3130
http://tape.tv
http://viki.com/channels/5453-killer-k/videos/51483
http://zonytvcom.info/colorstv.php
StripParams

The querystring for the "-a" parameter was also being used with the "-r"
parameter. This is not necessary. Cannot use with "-W" as some servers require
the querystring. Function was moved to librtmp to allow use across the project.

Taken from KSV patch file
http://github.com/downloads/K-S-V/Scripts/rtmpdump-2.4.zip
Tested with
http://history.com/shows/the-universe/videos#the-universe-spaceship-earth
http://myspace.com/music/player?sid=87831010
http://teledunet.com
RtmpSrv command line options

-c, --cert cert
-h, --help
-i, --printonly
-k, --key key
-p, --port port
-v, --version
-z, --debug

I chose to reuse the internal global variable "RTMP_ctrlC" for "--printonly" to
avoid rewriting several function calls.
Better URL decoding support

Currently RtmpDump has limited URL decoding support. If you use Bastien’s patch
as shown here
http://lists.mplayerhq.hu/pipermail/rtmpdump/2012-September/002093.html
You can pass encoded characters like this

  rtmpdump -o a.flv -i "rtmp://server.com/app playpath=foobar\0a"

Where "\0a" will be decoded as a newline.

Also the Playpath can be decoded using an unpatched RtmpDump, as long as it is
part of the "-r" parameter and properly parsed. Example

  rtmpdump -o a.flv -r rtmp://server.com/app/foobar%0a

Where "%0a" will be decoded as a newline. This presents two problems. One, many
times RtmpDump is unable to correctly parse the Playpath, mixing it with the
"app". Two, if you explicitly state the Playpath with "-y", you lose the URL
decoding support. I have simply moved the URL decoding function that Howard
wrote to parseurl.c and declared it in rtmp.h, so that it can be used across the
project. This patch also address concerns here
http://lists.mplayerhq.hu/pipermail/rtmpdump/2012-October/002112.html
RtmpSuck print UsherToken

RtmpSuck already supports streams with UsherToken. This patch merely prints the
UsherToken if found, for those who might want to invoke RtmpDump.

Taken from KSV patch file
http://github.com/downloads/K-S-V/Scripts/rtmpdump-2.4.zip
Tested with
http://de.twitch.tv
Fix rtmpdump.c compiler warning

rtmpdump.c: In function `GetLastKeyframe':
rtmpdump.c:297:7: warning: unknown conversion type character `l' in format
rtmpdump.c:297:7: warning: too many arguments for format

http://stackoverflow.com/q/586928/how-should-i-print-types-like-off-t-and-size-t
Fix thread.c compiler warning

thread.c: In function `ThreadCreate':
thread.c:35:11: warning: comparison between pointer and integer

http://stackoverflow.com/q/3905538/testing-for-an-invalid-windows-handle-should
Allow AMF_NULL

If encountering AMF_NULL, print null instead of INVALID TYPE

Test page
http://www.slavishow.com/виктор-калев-в-образа-на-силвия-кацаро
RtmpSuck command line options

-h, --help     prints this help screen
-t, --txt      copy RtmpDump command to rtmpsuck.txt and exit
-v, --version  print version information and exit
-z, --debug    debug level command output

I chose to reuse the internal global variable "RTMP_ctrlC" for "--txt" to avoid
rewriting several function calls.
RtmpDumpHelper switch

-e, --helper   launch RtmpDumpHelper

Running "rtmpsuck -e" will start RtmpDumpHelper if it is found on the
PATH.
Kill RtmpDumpHelper on close

If RtmpSuck exits or is killed, then kill RtmpDumpHelper as well.

Related
http://stackoverflow.com/q/53208/how-do-i-automatically-destroy-child-processes
Clean up RtmpDump usage page

fix wrapping of long lines
add space before each param
comma instead of pipe character
short form first
capitalized some acronyms
SendInvoke

Some servers were stopping after about 500 kB downloaded.

  Connecting ...
  WARNING: HandShake: client signature does not match!
  INFO: Connected...
  Starting download at: 0.000 kB
  INFO: Metadata:
  INFO:   height                480.00
  INFO:   width                 640.00
  571.996 kB / 7.12 sec
  ERROR: RTMP_ReadPacket, failed to read RTMP packet header
  574.196 kB / 7.28 sec
  Download complete

Ref
http://github.com/downloads/K-S-V/Scripts/rtmpdump-2.4.zip
Problem server
http://www.cybc.com.cy/index.php/tv?id=90
verifyClient

Some servers were stopping after about 2 MB downloaded.

  Connecting ...
  INFO: Connected...
  Starting download at: 0.000 kB
  INFO: Metadata:
  INFO:   width                 768.00
  INFO:   height                572.00
  INFO:   fps                   25.00
  1636.427 kB / 7.44 sec
  ERROR: RTMP_ReadPacket, failed to read RTMP packet body. len: 7597
  1671.344 kB / 7.68 sec
  Download complete

Running with debug shows server invoking verifyClient

  DEBUG: RTMP_ClientPacket, received: invoke 34 bytes
  DEBUG: (object begin)
  DEBUG: Property: <Name:           no-name., STRING:     verifyClient>
  DEBUG: Property: <Name:           no-name., NUMBER:     120781448.00>
  DEBUG: Property: NULL
  DEBUG: Property: <Name:           no-name., NUMBER:     38.54>
  DEBUG: (object end)
  DEBUG: HandleInvoke, server invoking <verifyClient>

Ref
http://github.com/downloads/K-S-V/Scripts/rtmpdump-2.4.zip
Problem server
http://kissfm.ro/kisstv