Correct the count of bytes written to the initial FLV buffer

This matters if the buffer overflows, when the count is used
for patching the buffer back together. This happens if there
are multiple video packets with zero timestamp at the start
of the stream (before any audio packets), enough to fill the buffer.
Free the extra read buffer if the initial FLV buffer overflowed

This fixes a leak in this cornercase.
Fix leaks in AMF objects that contain arrays
Extended timestamp field may be present in type 3 chunk headers

As described in Adobe’s RTMP specification dated 21 Dec 2012; also:

* RTMPY ticket #107, “Compressed headers also can have an extended
  timestamp”,
  http://web.archive.org/web/20120624031323/http://dev.rtmpy.org/ticket/107
* https://rarut.wordpress.com/2012/03/21/announcing-nginx-rtmp-module/

This resolves intermittent hangs, segfaults and crashes I was seeing when
starting ABC News 24 streams, e.g.:

rtmpdump -r rtmp://cp81899.live.edgefcs.net/live/news24-med@28772 --live

Some of the packets seemed to contain junk timestamp fields, which often
required the extended field.
Reconnect directly when authenticating, don't wait for the close message

This fixes authentication with wowza 4.x servers, which don't
send any close message in the authentication process.
Set RTMP_PUB_ALLOC if tcUrl is allocated in PublisherAuth

This makes sure we don't free tcUrl in RTMP_Close when reconnecting,
and avoids leaks (or simplifies code to avoid leaks).

This fixes connecting with authentication (both adobe and limelight)
when the app has been specified separately from the rest of the url.

This is only a temporary step while refactoring, this is removed
in a later commit.
Simplify the logic for freeing reused strings in RTMP_Close

Instead of having a plethora of flags indicating the current
state (just to avoid freeing them when closing the previous
connection when reconnecting), split RTMP_Close into CloseInternal,
taking a flag saying whether this is a reconnect or a normal,
final RTMP_Close call.

This also avoids leaks of some strings, if the whole session is
closed while the authentication process is underway.
Replace RTMP_PUB_ALLOC with RTMP_LF_FTCU and RTMP_LF_FAPU

This gets rid of the overlap between these two flags, shortening
the code somewhat.
My Fixes:

1. add timestamp to detected filename (rtmpsrv and rtmpsuck) to avoid overwriting the streams

2. replace invalid characters in filename with underscore

3. fixed a crash in rtmpsuck when closed using 'q' command

4. fixed generation of invalid flv file in some rare cases

5. few other minor fixes

Update 17/04/2013:

1. fixed rtmpsrv command generation in some specific cases + other minor fixes

Update 22/04/2013:

1. enhanced keyframe search for much better resume functionality
2. fixed a bug in RTMP_FindPrefixProperty and RTMP_FindFirstMatchingProperty function

Update 25/04/2013:

1. added onFCSubscribe response to rtmpsrv to detect more streams
2. show complete debug info in rtmpsuck when connection is closed
3. fixed a small bug in redirect handling (allocating 1 byte less than required)

Update 07/05/2013:

1. fixed timestamp generation on some platforms

Update 15/05/2013:

1. added support for featve.com changes

Update 19/05/2013:

1. added support for wfctv.com

Update 11/06/2013:

1. updated support for webvideocore.net servers

Update 14/09/2013:

1. added support for yycast.com changes

Update 18/10/2013:

1. added support for yukons.net, axcast.com changes

Update 14/03/2014:

1. also check client signature to detect if server wanna use old rtmp handshake

    (fixes handshake problems with some lousy servers)

2. added support for ddoss.me, streampiraten.ws changes
3. handle NetConnection.Connect.Rejected for onStatus response along with _error

Update 21/03/2014:

1. updated support for streampiraten.ws and clones
2. fixed a small bug