Commit Graph

205 Commits

Author SHA1 Message Date
Martin Storsjö
fab8156b2f avio: Copy URLContext generic options into child URLContexts
Since all URLContexts have the same AVOptions, such AVOptions
will be applied on the outermost context only and removed from the
dict, while they probably make sense on all contexts.

This makes sure that rw_timeout gets propagated to the innermost
URLContext (to make sure it gets passed to the tcp protocol, when
opening a http connection for instance).

Alternatively, such matching options would be kept in the dict
and only removed after the ffurl_connect call.

Signed-off-by: Martin Storsjö <martin@martin.st>
2016-03-24 10:34:19 +02:00
Anton Khirnov
8c0ceafb0f urlprotocol: receive a list of protocols from the caller
This way, the decisions about which protocols are available for use in
any given situations can be delegated to the caller.
2016-02-22 11:45:31 +01:00
Anton Khirnov
2758cdedfb lavf: reorganize URLProtocols
Instead of a linked list constructed at av_register_all(), store them
in a constant array of pointers.

Since no registration is necessary now, this removes some global state
from lavf. This will also allow the urlprotocol layer caller to limit
the available protocols in a simple and flexible way in the following
commits.
2016-02-22 11:30:58 +01:00
Martin Storsjö
64f8c439fd rtmpproto: Include the full path as app when "slist=" is found
This matches what librtmp does. This fixes automatic url parsing of
crunchyroll urls.

Signed-off-by: Martin Storsjö <martin@martin.st>
2015-12-13 23:23:06 +02:00
Michael Niedermayer
e55376a1fd rtmpproto: Write correct flv packet sizes at the end of packets
In one case it was written as zero, one case left it uninitialized,
missed the 11 bytes for the flv header.

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
2015-10-14 14:35:33 +02:00
James Almer
9487ffd4c0 rtmpproto: free hmac context properly
Signed-off-by: James Almer <jamrial@gmail.com>
Signed-off-by: Martin Storsjö <martin@martin.st>
2015-07-30 09:26:49 +03:00
James Almer
65dd6a1f84 rtmpproto: use AVHMAC instead of a custom implementation
Signed-off-by: James Almer <jamrial@gmail.com>
Signed-off-by: Martin Storsjö <martin@martin.st>
2015-07-29 22:09:16 +03:00
Vittorio Giovara
1a3eb042c7 Replace av_dlog with normal av_log at trace level
This applies to every library where performance is not critical.
2015-04-19 12:41:59 +01:00
Martin Storsjö
491805636c rtmpproto: Fix a typo in a comment
Signed-off-by: Martin Storsjö <martin@martin.st>
2014-11-28 20:56:45 +02:00
Martin Storsjö
01eac895ab rtmpproto: Only prepend @setDataFrame for onMetaData and |RtmpSampleAccess
Currently, when streaming to an RTMP server, any time a packet of type
RTMP_PT_NOTIFY is encountered, the packet is prepended with @setDataFrame
before it gets sent to the server. This is incorrect; only packets for
onMetaData and |RtmpSampleAccess should invoke @setDataFrame on the RTMP
server. Specifically, the current bug manifests itself when trying to
stream onTextData or onCuePoint invocations.

This fix addresses that problem and ensures that the @setDataFrame is
only prepended for onMetaData and |RtmpSampleAccess.

Since data is fed to the rtmp_write function in smaller pieces (depending
on the calling IO buffer size), we can't generally assume that the
whole packet (or even the whole command string) is available at once,
therefore we can only check the command string once the full packet
has been transferred to us for sending.

Based on a patch by Jeffrey Wescott.

Signed-off-by: Martin Storsjö <martin@martin.st>
2014-11-28 09:59:29 +02:00
Martin Storsjö
3c3b8003a1 rtmpproto: Simplify code for copying data into the output packet
Signed-off-by: Martin Storsjö <martin@martin.st>
2014-11-28 09:59:27 +02:00
Martin Storsjö
857e6667f9 rtmpproto: Clarify a comment
Signed-off-by: Martin Storsjö <martin@martin.st>
2014-11-28 09:59:25 +02:00
Martin Storsjö
a490391157 rtmpproto: Ignore errors from the getStreamLength method
It is never an error if this method failed. If rt->live was
explicitly set to 0 (known to be a recorded file), print it
as a warning, otherwise print it as a debug message.

Based on a patch by Michael Niedermayer.

Signed-off-by: Martin Storsjö <martin@martin.st>
2014-11-05 09:18:22 +02:00
Vittorio Giovara
322b571d55 rtmpproto: remove dead code
Expression already evaluated before, redundant since
0533868642.

Bug-Id: CID 732199
2014-10-20 10:44:22 +01:00
Alexander Drozdov
0034314a69 rtmp: Always call rtmp_close() on rtmp_open() failure
Prevent possible memory leaks.

Connect to nginx and request a non-existent resource to
trigger the issue.

CC: libav-stable@libav.org

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Signed-off-by: Uwe L. Korn <uwelk@xhochy.com>
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
2014-10-18 17:37:11 +02:00
Uwe L. Korn
9bec3ca2b8 rtmpproto: Add pause support
Signed-off-by: Martin Storsjö <martin@martin.st>
2014-10-17 23:13:51 +03:00
Uwe L. Korn
f4cd8b80b9 rtmpproto: Track last received timestamp
Some RTMP commands need the most recent timestamp as their parameter, so
keep track of it. This must be the most recent one and not e.g. the max
received timestamp as it can decrease again through seeking.

Signed-off-by: Martin Storsjö <martin@martin.st>
2014-10-17 23:13:37 +03:00
Uwe L. Korn
e65c776d18 rtmpproto: Add getStreamLength call to query duration
In (non-live) streams with no metadata, the duration of a stream can
be retrieved by calling the RTMP function getStreamLength with the
playpath. The server will return a positive duration upon the request if
the duration is known, otherwise either no response or a duration of 0
will be returned.

Signed-off-by: Martin Storsjö <martin@martin.st>
2014-10-17 12:07:19 +03:00
Uwe L. Korn
324b23dde1 rtmpproto: Add function to read a number response
Packets that contain a number as a result to a rtmp function call are
structured the same way (String, Number, Null, Number). This new method
also includes more bounds checks to better handle packets that are not
structured as expected.

Signed-off-by: Martin Storsjö <martin@martin.st>
2014-10-17 12:07:19 +03:00
Martin Storsjö
79dd756e14 rtmpproto: Fix a typo
Signed-off-by: Martin Storsjö <martin@martin.st>
2014-10-15 21:00:39 +03:00
Gabriel Dume
4b1f5e5090 cosmetics: Write NULL pointer inequality checks more compactly
Signed-off-by: Diego Biurrun <diego@biurrun.de>
2014-08-15 05:34:13 -07:00
Uwe L. Korn
59cb5747ec rtmpproto: read metadata to set correct FLV header
In the presence of no metadata, do not set any stream flag in the FLV
header but let the demuxer handle the detection and creation of streams
as data arrives.

Signed-off-by: Martin Storsjö <martin@martin.st>
2014-06-01 23:30:48 +03:00
Martin Storsjö
0bacfa8d37 rtmpproto: Check the buffer sizes when copying app/playpath strings
As pointed out by Reimar Döffinger.

CC: libav-stable@libav.org
Signed-off-by: Martin Storsjö <martin@martin.st>
2014-05-08 19:02:43 +03:00
Uwe L. Korn
7ce3bd9614 rtmpproto: Support alternative slist parameter in rtmp URLs
Support the URL scheme where the playpath is in an RTMP URL is
passed as the slist argument and the app is given infront of the
query part of the URL:

rtmp://host[:port]/[app]?slist=[playpath]

(other arguments in the query part are stripped as they are not used)

Signed-off-by: Martin Storsjö <martin@martin.st>
2014-05-06 23:41:56 +03:00
Stephan Soller
4d40e073dc rtmpproto: Handle RTMP chunk size packets before the connect packet
In all other cases where ff_rtmp_packet_read is used, the packet returned
is passed to rtmp_parse_result more or less immediately. In this single
case, the content of the packet was required to be a connect packet.

Some clients, e.g. Open Broadcaster Software, send a chunk size packet
before the connect packet. If the first packet is a chunk size packet,
handle it and read another one, requiring this to be a connect packet
instead.

Signed-off-by: Martin Storsjö <martin@martin.st>
2014-04-14 11:09:26 +03:00
Martin Storsjö
6477139721 rtmpproto: Make sure to pass on the error code if read_connect failed
Previously, if read_connect failed, the ret variable was unmodified
and had the value 0, indicating success, which then was returned from
the rtmp_open function, even though it actually failed.

CC: libav-stable@libav.org
Signed-off-by: Martin Storsjö <martin@martin.st>
2014-04-14 11:09:20 +03:00
Martin Storsjö
24eb3c7916 rtmpproto: Avoid using uninitialized memory
If the url ends with .flv, we stripped it but didn't initialize
rt->playpath, doing av_strlcat on an uninitialized buffer.

Signed-off-by: Martin Storsjö <martin@martin.st>
2014-01-20 21:56:57 +02:00
Vittorio Giovara
d763978583 rtmpproto: Reorder conditions to help dead code elimination
This makes sure that these branches are eliminated properly
with clang with optimizations disabled.
2013-11-03 11:51:41 +01:00
Martin Storsjö
84a125c4c2 rtmp: Allocate the prev_pkt arrays dynamically
Normally, all channel ids are between 0 and 10, while they in
uncommon cases can have values up to 64k.

This avoids allocating two arrays for up to 64k entries (at a total
of over 6 MB in size) each when most of them aren't used at all.

Signed-off-by: Martin Storsjö <martin@martin.st>
2013-10-14 14:27:35 +03:00
Martin Storsjö
cd818b3a57 rtmpproto: Validate the embedded flv packet size before copying
This wasn't an issue prior to 58404738, when the whole RTMP packet
was copied at once and the length of the individual embedded flv
packets only were validated by the flv demuxer.

Prior to this patch, this could lead to reads and writes out of bound.

Signed-off-by: Martin Storsjö <martin@martin.st>
2013-10-04 09:25:10 +03:00
Martin Storsjö
8921e32f73 rtmpproto: Readjust the end of the flv buffer if handle_metadata exited early
If the embedded flv packets were incomplete and we aborted the
copying loop early, make sure the flv buffer is trimmed to
only contain full packets.

Signed-off-by: Martin Storsjö <martin@martin.st>
2013-10-04 09:25:08 +03:00
Martin Storsjö
24fee95321 rtmpproto: Move the flv header/trailer addition to append_flv_data
update_offset is also called from handle_metadata, where the
packet header sizes is already included in the size.

Previously this lead to flv_data/flv_size including 15 uninitialized
bytes at the end after each call to handle_metadata, making the
flv demuxer lose sync with the stream.

Also remove leftover copying in handle_metadata. This is a leftover
from the refactoring in 5840473. (Previously this final mempcy was
the one that copied all the packets at once, while this is done
within the loop right now.) After making sure flv_size is set to
the right size, this write was out of bounds.

Signed-off-by: Martin Storsjö <martin@martin.st>
2013-10-04 09:25:07 +03:00
Martin Storsjö
72540e514c rtmpproto: Clear the flv allocation size on reallocp failures
This was overlooked in d872fb0f7 since I assumed all the realloc
issues in the rtmp code was fixed already.

Signed-off-by: Martin Storsjö <martin@martin.st>
2013-10-04 09:25:06 +03:00
Martin Storsjö
4d6d70292e rtmpproto: Pass the 'live' parameter in the right unit
The current magic numbers passed are values in seconds, while the
parameter itself should be passed over the wire in milliseconds.

This makes (some/all?) live streams from Red5 work correctly, that
previously returned StreamNotFound even with "-rtmp_live live". After
this commit, the default 'any' also works on these streams.

Signed-off-by: Martin Storsjö <martin@martin.st>
2013-10-04 09:25:05 +03:00
Martin Storsjö
a6b361325f rtmpproto: Print the error code string if there's no description
On (certain streams/setups at least on) Red5, the description string
actually is present, but empty. Therefore, first try loading the
description, but if not found or empty, load the code string instead.
The code string is quite understandable in most cases anyway (like
"NetStream.Play.StreamNotFound").

Signed-off-by: Martin Storsjö <martin@martin.st>
2013-10-04 09:25:04 +03:00
Luca Barbato
628a17d78a rtmp: alias rtmp_listen to listen
Make it uniform with the other protocols.
2013-10-01 15:42:06 +02:00
Martin Storsjö
d872fb0f7f lavf: Reset the entry count and allocation size variables on av_reallocp failures
When av_reallocp fails, the associated variables that keep track of
the number of elements in the array (and in some cases, the
separate number of allocated elements) need to be reset.

Not all of these might technically be needed, but it's better to
reset them if in doubt, to make sure variables don't end up
conflicting.

Signed-off-by: Martin Storsjö <martin@martin.st>
2013-09-26 23:14:03 +03:00
Luca Barbato
ba77757a7e rtmp: Replace a magic number with a macro
11 is the RTMP header size.
2013-09-22 01:09:33 +02:00
Luca Barbato
5840473890 rtmp: Rewrite embedded flv handling
Use update_offset() as done for rtmp audio, video and notifications and
read update and write the fields instead of replacing them in the rtmp
packet and then memcpying it to the output buffer.
2013-09-22 01:09:33 +02:00
Luca Barbato
e40a0e8228 rtmp: Refactor get_packet 2013-09-22 01:09:33 +02:00
Luca Barbato
5532ee6d7d rtmp: Unbreak get_packet
Commit 5626f994f2 broke it.
2013-09-20 13:38:22 +02:00
Martin Storsjö
b97b1adb3f rtmpproto: Add a comment explaining the logic in handle_notify
This explains why the cleanup in 5626f994f was wrong and why
ae0f316a was needed.

Signed-off-by: Martin Storsjö <martin@martin.st>
2013-09-20 10:47:15 +03:00
Luca Barbato
ae0f316a47 rtmp: Unbreak handle_notify
Commit 5626f994f2 broke it.
2013-09-19 09:13:04 +02:00
Alexandra Khirnova
5626f994f2 avformat: Use av_reallocp() where suitable
Signed-off-by: Diego Biurrun <diego@biurrun.de>
2013-09-18 18:28:38 +02:00
Josh Allmann
8583b14252 rtmp: Support reading interleaved chunks.
A given packet won't always come in contiguously; sometimes
they may be broken up on chunk boundaries by packets of another
channel.

This support primarily involves tracking information about the
data that's been read, so the reader can pick up where it left
off for a given channel.

As a side effect, we no longer over-report the bytes read if
(toread = MIN(size, chunk_size)) == size

Signed-off-by: Martin Storsjö <martin@martin.st>
2013-09-17 23:19:11 +03:00
Martin Storsjö
dc4acc8200 rtmpproto: Extend a comment to explain the prev_pkt arrays roles
Signed-off-by: Martin Storsjö <martin@martin.st>
2013-09-17 20:09:25 +03:00
Martin Storsjö
647d655d19 rtmpproto: Consistently use the right prev_pkt array
prev_pkt[0] is used for input packets, while prev_pkt[1] is
used for output.

Signed-off-by: Martin Storsjö <martin@martin.st>
2013-09-17 20:09:24 +03:00
Martin Storsjö
0d3784396b rtmpproto: Check for the right return code
Signed-off-by: Martin Storsjö <martin@martin.st>
2013-09-17 20:09:22 +03:00
Josh Allmann
f8d1bb6723 rtmp: rename main_channel_id to stream_id.
This more closely corresponds to the usage of the field.
Its usage here is unrelated to the channel ID.

Signed-off-by: Martin Storsjö <martin@martin.st>
2013-09-17 11:03:36 +03:00
Josh Allmann
d4aef99780 rtmp: Follow Flash player numbering for channels.
Channel 4 is typically used by the Flash player to transmit
audio, channel 6 for video, and various stream-specific invokes
get sent over channel 8, which is designated the source channel.

This more closely matches the behavior of the Flash player,
including the transmission of play requests over channel 8.

Signed-off-by: Martin Storsjö <martin@martin.st>
2013-09-17 11:03:36 +03:00