Commit graph

136 commits

Author SHA1 Message Date
Sebastian Dröge
776a9470a0 adaptivedemux: Also never have the SINK flag set on adaptivedemux 2016-09-12 18:38:36 +02:00
Thiago Santos
08da514528 adaptivedemux: fix typo in new API
Fixes supressed -> suppressed typo in previous commit

https://bugzilla.gnome.org/show_bug.cgi?id=770627
2016-09-10 16:53:59 -03:00
Wonchul Lee
aa314c43ba adaptivedemux: prevent to propagate source flag to itself
https://bugzilla.gnome.org/show_bug.cgi?id=770627
2016-09-10 09:49:45 -03:00
Thibault Saunier
2fb716409c Use the new API to post flow ERROR messages on the bus
https://bugzilla.gnome.org/show_bug.cgi?id=770158
2016-08-26 19:23:31 -03:00
Sebastian Dröge
4f6ae1f48c adaptivedemux: Enable bitrate selection for trick mode streaming again
And scale the bitrate with the absolute rate (if it's bigger than 1.0) to get
to the real bitrate due to faster playback.

This allowed in my tests to play a stream with 10x speed without buffering as
the lowest bitrate is chosen, instead of staying/selecting the highest bitrate
and then buffering all the time.

It was previously disabled for not very well specified reasons, which seem to
be not valid anymore nowadays.
2016-08-25 19:52:37 +03:00
Jan Schmidt
1d5b32ee91 adaptivedemux: Fix the previous commit
Remove extra files that were not meant to be added to the commit
2016-08-23 02:13:19 +10:00
Jan Schmidt
389e35d032 adaptivedemux: Fix broken updates loop on live streams
Prevent the manifest update loop from looping endlessly
after a seek event, by clearing the variable that tells
the task function not to immediately exit.
2016-08-23 01:57:55 +10:00
Michael Olbrich
0a63569fd1 adaptivedemux: fix stream exposure condition
The new streams should not be exposed until all streams are done with the
current fragment. The old code is incorrect and actually only checked the
current stream. Fix this by properly checking all streams.

Also, ignore the current stream. The code is only reached when the current
stream finished downloading and since
07f49f15b1 ("adaptivedemux: On EOS, handle it
before waking download loop") download_finished is set after
gst_adaptive_demux_stream_advance_fragment_unlocked() is called.

Without this HLS playback with multiple streams is broken, because the new
streams are never exposed.

https://bugzilla.gnome.org/show_bug.cgi?id=770075
2016-08-23 01:40:39 +10:00
Nirbheek Chauhan
42af2d66d8 Add support for Meson as alternative/parallel build system
https://github.com/mesonbuild/meson

With contributions from:

Tim-Philipp Müller <tim@centricular.com>
Matej Knopp <matej.knopp@gmail.com>
Jussi Pakkanen <jpakkane@gmail.com> (original port)

Highlights of the features provided are:
* Faster builds on Linux (~40-50% faster)
* The ability to build with MSVC on Windows
* Generate Visual Studio project files
* Generate XCode project files
* Much faster builds on Windows (on-par with Linux)
* Seriously fast configure and building on embedded

... and many more. For more details see:

http://blog.nirbheek.in/2016/05/gstreamer-and-meson-new-hope.html
http://blog.nirbheek.in/2016/07/building-and-developing-gstreamer-using.html

Building with Meson should work on both Linux and Windows, but may
need a few more tweaks on other operating systems.
2016-08-20 11:35:54 +01:00
Sebastian Dröge
a9e38d3fec adaptivedemux: Add API for allowing subclasses to download URLs in chunks
This allows to gradually download part of a fragment when the final size is
not known and only a part of it should be downloaded. For example when only
the moof should be parsed and/or a single keyframe should be downloaded.

https://bugzilla.gnome.org/show_bug.cgi?id=741104
2016-08-11 11:56:55 +02:00
Jan Schmidt
07f49f15b1 adaptivedemux: On EOS, handle it before waking download loop
Otherwise, if the download loop wakes too quickly, it
might miss the last_ret value update from the processing
thread and loop again.
2016-08-04 04:29:38 +10:00
Sebastian Dröge
050b253d1c adaptivedemux: Never ever hold the manifest lock while changing the source element state
Otherwise we will deadlock in various situations that take the manifest lock
from the streaming thread or when shutting down or ...
2016-08-03 09:15:08 +03:00
Vincent Penquerc'h
535f10b61d adaptivedemux: retry once on 4xx/5xx in certain conditions
This helps catch those 404 server errors in live streams when
seeking to the very beginning, as the server will handle a
request with some delay, which can cause it to drop the fragment
before sending it.

https://bugzilla.gnome.org/show_bug.cgi?id=753751
2016-08-02 12:52:34 +01:00
Alex Ashley
341cdb198f adaptivedemux: expose HTTP status
To allow adaptivedemux to make retry decisions, it needs to know what
sort of HTTP error has occurred. For example, the retry logic for a
410 error is different from a 504 error.

https://bugzilla.gnome.org/show_bug.cgi?id=753751
2016-08-02 12:52:34 +01:00
Vincent Penquerc'h
5b7f60dada adaptivedemux: allow seeking before start in live streams
Some derived classes (at least dashdemux) expose a seeking range
based on wall clock. This means that a subsequent seek to the start
of this range will be before the allowed range.

To solve this, seeks without the ACCURATE flag are allowed to seek
before the start for live streams, in which case the segment is
shifted to start at the start of the new seek range. If there is
an end position, is is shifted too, to keep the duration constant.

https://bugzilla.gnome.org/show_bug.cgi?id=753751
2016-08-02 12:52:34 +01:00
Sebastian Dröge
c1982d8b2f adaptivedemux: Also call reset() in READY->PAUSED
This allows subclasses to have initialization code in a single place.
2016-07-29 12:34:19 +03:00
Jan Schmidt
585e60c4ab adaptivedemux: Add more safeguards around state changes.
Make state changes of internal elements more reliable by locking
their state, and ensuring that they aren't blocked pushing data
downstream before trying to set their state.

Add a boolean to avoid starting tasks when the main
thread is busy trying to shut the element down.
2016-07-15 14:33:23 +10:00
Jan Schmidt
5fc21d5c74 adaptivedemux: Add debug code to change bitrate.
Add some disabled-by-default debugging code that forces
bitrate changes by modulating the measured bitrate every
few fragments
2016-07-15 14:33:23 +10:00
Jan Schmidt
03f96dd731 adaptivedemux: More locking/switching fixes
Try harder to make switching pads work better by
making sure concurrent downloads are finished before exposing
a new set of pads.

Release the manifest lock when signalling no-more-pads, as
that can call back into adaptivedemux again
2016-07-15 14:33:23 +10:00
Jan Schmidt
963a273f61 adaptivedemux: Don't switch streams and expose pads while downloading.
If other stream fragments are still downloading but new streams
have been scheduled, don't expose them yet - wait until the last
one finishes. Otherwise, we can cancel a partially downloaded
auxilliary stream and cause a gap.
2016-07-15 14:33:23 +10:00
Jan Schmidt
62ca319927 adaptivedemux: Drop the manifest lock during outbound actions
Drop the manifest lock when performing actions that might
call back into adaptivedemux and trigger deadlocks, such
as adding/removing pads or sending in-band events (EOS).

Unlock the manifest lock when changing the child bin state to
NULL, as it might call back to acquire the manifest lock when
shutting down pads.

Drop the manifest lock while pushing events.
2016-07-15 14:33:23 +10:00
Edward Hervey
e4c955e4d7 adaptivedemux: Also consider more seek flags as "snap" seeks
In the case of KEY_UNIT and TRICKMODE_KEY_UNITS seeks, we want to
"snap" to the closest fragment.

Without this, we end up pushing out a segment which does not match
the first fragment timestamp being pushed out, resulting in one or
more buffers being eventually dropped because they are out of segment.
2016-07-07 17:28:57 +02:00
Sebastian Dröge
43a2ee8948 adaptivedemux: Add custom flow return for allowing subclasses to specify when a fragment is finished
If it is finished before upstream going EOS.

https://bugzilla.gnome.org/show_bug.cgi?id=767365
2016-07-01 14:11:51 +02:00
Sebastian Dröge
ca9f62e1d0 adaptivedemux: Get rid of internal stream adapter and let subclasses handle this directly
This allows subclasses to have more control and especially ensure that they
push data downstream with the correct offsets.

https://bugzilla.gnome.org/show_bug.cgi?id=764684
2016-07-01 14:10:31 +02:00
Edward Hervey
deb686cfe1 adaptivedemux: Move SEEK handling to a separate function
Just for code readability. Doesn't change behaviour
2016-06-09 19:25:26 +03:00
Edward Hervey
9296b26095 adaptivedemux: Set DISCONT on startup, resume and after seeks
Initial buffers after STREAM_START and seeks should always have the
DISCONT flag set.

https://bugzilla.gnome.org/show_bug.cgi?id=766650
2016-06-06 13:07:30 +03:00
Guillaume Desmottes
d7c47107ce adaptivedemux: fix pending tags leak
https://bugzilla.gnome.org/show_bug.cgi?id=766662
2016-05-19 20:44:25 +01:00
Alex Ashley
792e9a6033 adaptivedemux: fix threading issues in gst_adaptive_demux_wait_until function
The gst_adaptive_demux_wait_until() function can be woken up either
by its end_time being reached, or from other threads that want to
interrupt the waiting thread.

If the thread is interrupted, it needs to cancel its async clock callback
by unscheduling the clock callback. However, the callback task might already
have been activated, but is waiting for the mutex to become available. In this
case, the call to unschedule does not stop the callback from executing.

The solution to this second issue is to use a reference counted object that
is decremented by both the gst_adaptive_demux_wait_until() function and the
call to gst_clock_id_wait_async (). In this way, the GstAdaptiveDemuxTimer
object is only deleted when both the gst_adaptive_demux_wait_until() function
and the async callback are finished with the object.

https://bugzilla.gnome.org/show_bug.cgi?id=765728
2016-05-06 09:42:41 +01:00
Florin Apostol
aa58a70d66 adaptivedemux: use realtime_clock for waiting for a condition
There are several places in adaptivedemux where it waits for
time to pass, for example to wait until it should next download
a fragment. The problem with this approach is that it means that
unit tests are forced to execute in realtime.

This commit replaces the use of g_cond_wait_until() with single
shot GstClockID that signals the condition variable. Under normal
usage, this behaves exactly as before. A unit test can replace the
system clock with a GstTestClock, allowing the test to control the
timing in adaptivedemux.

https://bugzilla.gnome.org/show_bug.cgi?id=762147
2016-04-21 16:46:09 -03:00
Florin Apostol
74d62b9144 adaptivedemux: use GstSystemClock to all real-time calculations
A realtime clock is used in many places, such as deciding which
fragment to select at start up and deciding how long to sleep
before a fragment becomes available. For example dashdemux needs
sample the client's estimate of UTC when selecting where to start
in a live DASH stream.

The problem with dashdemux calculating the client's idea of UTC is
that it makes it difficult to create unit tests, because the passage
of time is a factor in the test.

This commit changes dashdemux and adaptivedemux to use the
GstSystemClock, so that a unit test can replace the system clock when
it needs to be able to control the clock.

This commit makes no change to the behaviour under normal usage, as
GstSystemClock is based upon the system time.

https://bugzilla.gnome.org/show_bug.cgi?id=762147
2016-04-21 16:46:09 -03:00
Sebastian Dröge
2125124755 adaptivedemux: Handle find_stream_for_pad() without g_assert_not_reached() if no pad is found
Happens e.g. if a RECONFIGURE event is sent from downstream while we're
switching pads at this very moment. The old pad is gone and the stream has a
new pad.

https://bugzilla.gnome.org/show_bug.cgi?id=764404
2016-03-31 12:21:57 +03:00
Sebastian Dröge
c22a8a6224 adaptivedemux: Fix REMOVE_SNAP_FLAGS() macro
!(flag1 | flag2 | flag3) is always evaluation to 0. ~ was meant here
instead of !.

CID 1352032.
2016-03-02 10:41:17 +02:00
Thiago Santos
c65b0e3a57 adaptivedemux: handle snap seeking without setting any position
When the start_type is GST_SEEK_TYPE_NONE for a forward seek
(or stop_type for a reverse) is not set on a snap seeking operation,
the element should use the current position and then snap as requested.

Also fixes uninitialized variable complaint by clang about
'ts' variable.
2016-02-26 18:17:37 -03:00
Philippe Normand
0b7276d01a adaptivedemux: restore bitrate averaging support
This was accidentally removed in commit ccff3be3.
https://bugzilla.gnome.org/show_bug.cgi?id=733959
2016-02-16 17:11:03 +02:00
Philippe Normand
4d1489b3de adaptivedemux: remove queue2 overrun notification
Due to performance impact concerns this is removed. An alternative
approach would be to rely on buffering messages monitoring.

https://bugzilla.gnome.org/show_bug.cgi?id=733959
2016-02-16 17:11:03 +02:00
Florin Apostol
88e21e6089 dashdemux: gst_dash_demux_get_live_seek_range returns positive values
https://bugzilla.gnome.org/show_bug.cgi?id=752374
2016-02-10 14:34:48 -03:00
Luis de Bethencourt
44c0d75cff adaptivedemux: remove overwritten value
ret is overwitten before used with the return of the subclass seek.

CID #1352044
2016-02-08 23:17:40 +00:00
David Waring
90fe6c5a5b adaptivedemux: Update position in stream->segment for new stream segment message.
https://bugzilla.gnome.org/show_bug.cgi?id=761458
2016-02-05 10:47:37 -03:00
Thiago Santos
731ab94cc3 adaptivedemux: handle snap seeks
Adaptive demuxers need to start downloading from specific positions
(fragments) for every stream, this means that all streams can snap-seek
to a different position when requested. Snap seeking in this case will
be done in 2 steps:

1) do the snap seeking on the pad that received the seek event and
   get the final position

2) use this position to do a regular seek on the other streams to
   make sure they all start from the same position

More arguments were added to the stream_seek function, allowing better control
of how seeking is done. Knowing the flags and the playback direction allows
subclasses to handle snap-seeking.
And also adds a new return parameter to inform of the final
selected seeking position that is used to align the other streams.

https://bugzilla.gnome.org/show_bug.cgi?id=759158
2016-02-04 14:05:08 -03:00
Thiago Santos
f16916f7e7 adaptivedemux: add utility function to get stream from pad
Simplifies the code a bit and avoid repeating this
common operation
2016-02-04 14:03:55 -03:00
Alex Ashley
cfb1b79516 adaptivedemux: fix leak of stream->internal_pad
The function gst_adaptive_demux_stream_update_source() function creates
a new GstPad called internal_pad. This pad is not freed when releasing
the stream.

The solution is to set GST_PAD_FLAG_NEED_PARENT so that the chain
functions do not get called when the pad has no parent and then
remove the parent in the gst_adaptive_demux_stream_free() function. This
causes the refcount of the pad to be set to zero.

https://bugzilla.gnome.org/show_bug.cgi?id=760982
2016-01-22 19:04:42 +02:00
Thiago Santos
b7a0be23c6 adaptivedemux: replace ghostpad with a standard pad
Handling the ghostpad and its internal pad was causing more issues
than helping because of their coupled activation/deactivation
actions.

As we have to install custom chain,event and query functions it is
better to use a floating sink pad internally in the demuxer and just
use those pad functions to push through a standard pad in the demuxer

https://bugzilla.gnome.org/show_bug.cgi?id=757951
2016-01-15 11:32:37 -03:00
Florin Apostol
d92f11b819 adaptivedemux: do not flush the input pad
gst_adaptive_demux_stream_clear_eos_and_flush_state() function will do
all the necessary cleaning.

https://bugzilla.gnome.org/show_bug.cgi?id=757951
2016-01-15 11:32:37 -03:00
Thiago Santos
16a2f7f5c0 adaptivedemux: fix seeking that just updates stop position
Fixed adaptivedemux seeking without flushing that just wants
to update stop position. This required protecting the segment
variables with a new mutex so that the seeking thread and the
download threads could safely manipulate the segment and
events related to it.

This contention is only locked/unlocked when starting a new
download, when the first fragment of a segment is received and
when seeking so, hopefully, it won't damage performance.
2016-01-07 15:46:01 -03:00
Thiago Santos
eaace4922c adaptivedemux: fix segment update on seeks
Fixes typo on reverse rate check and also only update the
position when the start/stop was actually changed.
2016-01-07 15:45:56 -03:00
Thiago Santos
f57109ad2e adaptivedemux: stop reverse playback when we reach the limit
Avoids downloading and pushing a full segment just to get 1 nanosecond
of data. This happens frequently when seeking is done with flags
that adjust to boundaries or when the start is aligned with segment
starts. The later is common when segment durations is a multiple of
a second.
2016-01-06 10:23:13 -03:00
Thiago Santos
bf272edaf3 adaptivedemux: correctly track segment.position in reverse playback
For reverse, set position to segment.stop when starting and also
don't set the position to fragment end timestamp when it finishes,
just leave it at the fragment start.
2016-01-06 10:23:13 -03:00
Thiago Santos
2fdd5dca14 adaptivedemux: avoid pushing events with manifest lock
It can be an easy source of deadlocks. Reproducible with very
fast connections (local server).
2015-12-08 16:12:37 -03:00
Sebastian Dröge
280de75d89 adaptivedemux: Log PTS of buffers that are pushed downstream 2015-12-03 10:08:53 +02:00
Jan Schmidt
08544a459b adaptivedemux: Send the bitrate of the stream as a tag
If we know or can measure the nominal bitrate of a stream,
send that info as a tag downstream
2015-12-02 22:29:38 +11:00