S026: vendored gst_mse 1.28.9 with fixes for early update-end, idle ticks, split A/V init segments; loaded ahead of the system copy

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
astar76 2026-11-12 11:14:43 -06:00
commit e3dc9422ca
44 changed files with 11182 additions and 2 deletions

8
build.rs Normal file
View file

@ -0,0 +1,8 @@
// Nacre's patched libgstmse-1.0.so.0 (tools/gst-mse.sh) must win over the system copy: the binary's RUNPATH
// looks next to it first (`lib/`, the release layout), then in a dev tree's `target/gst-mse/lib`.
fn main() {
if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("linux") {
println!("cargo:rustc-link-arg-bins=-Wl,-rpath,$ORIGIN/lib:$ORIGIN/../gst-mse/lib");
}
println!("cargo:rerun-if-changed=build.rs");
}

View file

@ -99,6 +99,34 @@ fn choose_gl(settings: &store::settings::Settings) {
}
}
/// Points GStreamer at Nacre's patched MSE plugin (`msesrc`, docs/engine/gst-mse-patches.md) ahead of the
/// system one. The matching library, libgstmse-1.0.so.0, is found through the binary's RUNPATH (build.rs).
/// Release layout: `<exe dir>/lib/gstreamer-1.0`; a dev build: `target/gst-mse/gstreamer-1.0` (tools/gst-mse.sh).
fn use_own_gst_mse() {
let Some(dir) = std::env::current_exe().ok().and_then(|exe| exe.parent().map(|dir| dir.to_path_buf())) else {
return;
};
let Some(plugins) = [dir.join("lib/gstreamer-1.0"), dir.join("../gst-mse/gstreamer-1.0")]
.into_iter()
.find(|plugins| plugins.join(if cfg!(windows) { "gstmse.dll" } else { "libgstmse.so" }).is_file())
else {
eprintln!("nacre: gst-mse: no patched mse plugin next to the binary, using the system one");
return;
};
let mut paths = vec![plugins.clone()];
paths.extend(std::env::var_os("GST_PLUGIN_PATH").iter().flat_map(std::env::split_paths));
if let Ok(value) = std::env::join_paths(paths) {
// SAFETY: called on the main thread before any other thread exists.
unsafe { std::env::set_var("GST_PLUGIN_PATH", value) };
}
let library = std::fs::read_to_string("/proc/self/maps")
.unwrap_or_default()
.lines()
.find_map(|line| line.split_whitespace().nth(5).filter(|path| path.contains("libgstmse-1.0")).map(str::to_owned))
.unwrap_or_else(|| "not loaded".into());
eprintln!("nacre: gst-mse: plugin {}, library {library}", plugins.display());
}
fn main() {
let launch = match parse_args() {
Ok(launch) => launch,
@ -113,6 +141,7 @@ fn main() {
return;
}
choose_gl(&store::settings::Settings::load(&paths.settings()));
use_own_gst_mse();
let event_loop = match EventLoop::<AppEvent>::with_user_event().build() {
Ok(event_loop) => event_loop,
Err(error) => {

Binary file not shown.

Binary file not shown.

333
tests/gst-mse/mse-fixes.c Normal file
View file

@ -0,0 +1,333 @@
/* Regression tests for Nacre's gst_mse patches (docs/engine/gst-mse-patches.md), one per defect of
* gst-plugins-bad 1.28.9's MSE library:
* /mse/update-end-after-parse bug 1: `buffered` is current at the first update-end of an append
* /mse/no-idle-updates bug 2: no update / update-end while nothing is appended
* /mse/split-audio-video bug 3: separate audio and video SourceBuffers, video appended 2 s
* before audio, expose no stream until both have an init segment, then play
*
* Built and run by `tools/gst-mse.sh test` against target/gst-mse (GST_PLUGIN_PATH, own registry).
* Clips in data/ (TESTS_DATA_DIR), made with ffmpeg:
* video-vp9.webm testsrc2 320x180 30 fps 5 s, libvpx-vp9, no audio
* audio-aac.mp4 sine 440 Hz 5 s, aac 64k, fragmented (frag_keyframe+empty_moov+default_base_moof, 1 s)
* Running the binary with LD_LIBRARY_PATH=/usr/lib and GST_PLUGIN_PATH unset tests the system copy instead
* (all three fail there).
*/
#include <gst/gst.h>
#include <gst/mse/mse.h>
#define VIDEO_TYPE "video/webm; codecs=\"vp9\""
#define AUDIO_TYPE "audio/mp4; codecs=\"mp4a.40.2\""
typedef struct
{
GMutex lock;
GCond cond;
gint updates;
gint update_ends;
gint errors;
/* buffered ranges seen at each update-end */
GArray *buffered_at_end;
} Counter;
static void
counter_init (Counter * c)
{
g_mutex_init (&c->lock);
g_cond_init (&c->cond);
c->updates = c->update_ends = c->errors = 0;
c->buffered_at_end = g_array_new (FALSE, TRUE, sizeof (guint));
}
static void
counter_clear (Counter * c)
{
g_array_unref (c->buffered_at_end);
g_mutex_clear (&c->lock);
g_cond_clear (&c->cond);
}
static void
on_update (GstSourceBuffer * buffer, Counter * c)
{
g_mutex_lock (&c->lock);
c->updates++;
g_mutex_unlock (&c->lock);
}
static void
on_update_end (GstSourceBuffer * buffer, Counter * c)
{
GArray *ranges = gst_source_buffer_get_buffered (buffer, NULL);
guint n = ranges ? ranges->len : 0;
g_clear_pointer (&ranges, g_array_unref);
g_mutex_lock (&c->lock);
c->update_ends++;
g_array_append_val (c->buffered_at_end, n);
g_cond_broadcast (&c->cond);
g_mutex_unlock (&c->lock);
}
static void
on_error (GstSourceBuffer * buffer, Counter * c)
{
g_mutex_lock (&c->lock);
c->errors++;
g_cond_broadcast (&c->cond);
g_mutex_unlock (&c->lock);
}
/* Waits up to @seconds for @n update-ends in total; returns whether they came. */
static gboolean
wait_update_ends (Counter * c, gint n, gint seconds)
{
gint64 deadline = g_get_monotonic_time () + seconds * G_TIME_SPAN_SECOND;
gboolean ok = TRUE;
g_mutex_lock (&c->lock);
while (c->update_ends < n && ok) {
ok = g_cond_wait_until (&c->cond, &c->lock, deadline);
}
ok = c->update_ends >= n;
g_mutex_unlock (&c->lock);
return ok;
}
static void
watch (GstSourceBuffer * buffer, Counter * c)
{
g_signal_connect (buffer, "on-update", G_CALLBACK (on_update), c);
g_signal_connect (buffer, "on-update-end", G_CALLBACK (on_update_end), c);
g_signal_connect (buffer, "on-error", G_CALLBACK (on_error), c);
}
static GstBuffer *
clip (const gchar * name)
{
gchar *path = g_build_filename (g_getenv ("TESTS_DATA_DIR"), name, NULL);
gchar *data;
gsize size;
GError *error = NULL;
g_file_get_contents (path, &data, &size, &error);
g_assert_no_error (error);
g_free (path);
return gst_buffer_new_wrapped (data, size);
}
static void
sleep_seconds (gdouble seconds)
{
g_usleep ((gulong) (seconds * G_USEC_PER_SEC));
}
/* A MediaSource attached to a lone msesrc (no pipeline), opened, with one SourceBuffer. */
typedef struct
{
GstElement *src;
GstMediaSource *source;
GstSourceBuffer *buffer;
} Lone;
static void
lone_setup (Lone * lone, const gchar * type)
{
lone->src = gst_element_factory_make ("msesrc", NULL);
g_assert_nonnull (lone->src);
gst_object_ref_sink (lone->src);
lone->source = gst_media_source_new ();
gst_media_source_attach (lone->source, GST_MSE_SRC (lone->src));
g_assert_cmpint (gst_media_source_get_ready_state (lone->source), ==,
GST_MEDIA_SOURCE_READY_STATE_OPEN);
GError *error = NULL;
lone->buffer = gst_media_source_add_source_buffer (lone->source, type, &error);
g_assert_no_error (error);
}
static void
lone_teardown (Lone * lone)
{
gst_media_source_detach (lone->source);
gst_clear_object (&lone->buffer);
gst_clear_object (&lone->source);
gst_clear_object (&lone->src);
}
static void
test_update_end_after_parse (void)
{
Lone lone;
Counter c;
counter_init (&c);
lone_setup (&lone, VIDEO_TYPE);
watch (lone.buffer, &c);
g_assert_true (gst_source_buffer_append_buffer (lone.buffer,
clip ("video-vp9.webm"), NULL));
g_assert_true (wait_update_ends (&c, 1, 10));
g_assert_cmpint (c.errors, ==, 0);
/* The whole clip (init segment and media) was in that append. */
g_assert_cmpuint (g_array_index (c.buffered_at_end, guint, 0), >, 0);
lone_teardown (&lone);
counter_clear (&c);
}
static void
test_no_idle_updates (void)
{
Lone lone;
Counter c;
counter_init (&c);
lone_setup (&lone, AUDIO_TYPE);
watch (lone.buffer, &c);
sleep_seconds (3);
g_assert_cmpint (c.updates, ==, 0);
g_assert_cmpint (c.update_ends, ==, 0);
g_assert_true (gst_source_buffer_append_buffer (lone.buffer,
clip ("audio-aac.mp4"), NULL));
g_assert_true (wait_update_ends (&c, 1, 10));
sleep_seconds (3);
g_assert_cmpint (c.updates, ==, 1);
g_assert_cmpint (c.update_ends, ==, 1);
g_assert_cmpint (c.errors, ==, 0);
lone_teardown (&lone);
counter_clear (&c);
}
/* playbin on mse://, both sinks fakesink (no audio device in test runs). */
typedef struct
{
GstElement *playbin;
GstMediaSource *source;
GstElement *src;
GMutex lock;
GCond cond;
gboolean opened;
} Player;
static void
on_source_setup (GstElement * playbin, GstElement * src, Player * p)
{
g_mutex_lock (&p->lock);
p->src = gst_object_ref (src);
g_mutex_unlock (&p->lock);
gst_media_source_attach (p->source, GST_MSE_SRC (src));
}
static void
on_source_open (GstMediaSource * source, Player * p)
{
g_mutex_lock (&p->lock);
p->opened = TRUE;
g_cond_broadcast (&p->cond);
g_mutex_unlock (&p->lock);
}
static GstClockTime
position (GstElement * playbin)
{
gint64 pos = -1;
if (!gst_element_query_position (playbin, GST_FORMAT_TIME, &pos))
return GST_CLOCK_TIME_NONE;
return pos;
}
static void
test_split_audio_video (void)
{
Player p = { 0 };
g_mutex_init (&p.lock);
g_cond_init (&p.cond);
p.source = gst_media_source_new ();
g_signal_connect (p.source, "on-source-open", G_CALLBACK (on_source_open), &p);
p.playbin = gst_element_factory_make ("playbin", NULL);
g_assert_nonnull (p.playbin);
GstElement *vsink = gst_element_factory_make ("fakesink", NULL);
GstElement *asink = gst_element_factory_make ("fakesink", NULL);
g_object_set (vsink, "sync", TRUE, NULL);
g_object_set (asink, "sync", TRUE, NULL);
g_object_set (p.playbin, "uri", "mse://test", "video-sink", vsink,
"audio-sink", asink, NULL);
g_signal_connect (p.playbin, "source-setup", G_CALLBACK (on_source_setup), &p);
gst_element_set_state (p.playbin, GST_STATE_PAUSED);
gint64 deadline = g_get_monotonic_time () + 5 * G_TIME_SPAN_SECOND;
g_mutex_lock (&p.lock);
while (!p.opened && g_cond_wait_until (&p.cond, &p.lock, deadline));
g_assert_true (p.opened);
g_mutex_unlock (&p.lock);
GError *error = NULL;
Counter cv, ca;
counter_init (&cv);
counter_init (&ca);
GstSourceBuffer *video =
gst_media_source_add_source_buffer (p.source, VIDEO_TYPE, &error);
g_assert_no_error (error);
GstSourceBuffer *audio =
gst_media_source_add_source_buffer (p.source, AUDIO_TYPE, &error);
g_assert_no_error (error);
watch (video, &cv);
watch (audio, &ca);
/* Video first, then 2 s with only one init segment, like YouTube's separate buffers. */
g_assert_true (gst_source_buffer_append_buffer (video, clip ("video-vp9.webm"),
NULL));
g_assert_true (wait_update_ends (&cv, 1, 10));
sleep_seconds (2);
guint n_video = 0, n_audio = 0;
GstMseSrcReadyState ready;
g_object_get (p.src, "n-video", &n_video, "n-audio", &n_audio, "ready-state",
&ready, NULL);
g_assert_cmpuint (n_video, ==, 0);
g_assert_cmpuint (n_audio, ==, 0);
g_assert_cmpint (ready, ==, GST_MSE_SRC_READY_STATE_HAVE_NOTHING);
g_assert_true (gst_source_buffer_append_buffer (audio, clip ("audio-aac.mp4"),
NULL));
g_assert_true (wait_update_ends (&ca, 1, 10));
g_assert_true (gst_media_source_end_of_stream (p.source,
GST_MEDIA_SOURCE_EOS_ERROR_NONE, &error));
g_assert_no_error (error);
g_object_get (p.src, "n-video", &n_video, "n-audio", &n_audio, NULL);
g_assert_cmpuint (n_video, ==, 1);
g_assert_cmpuint (n_audio, ==, 1);
gst_element_set_state (p.playbin, GST_STATE_PLAYING);
GstClockTime pos = GST_CLOCK_TIME_NONE;
for (gint i = 0; i < 100; i++) {
sleep_seconds (0.1);
pos = position (p.playbin);
if (GST_CLOCK_TIME_IS_VALID (pos) && pos > GST_SECOND)
break;
}
g_test_message ("position after play: %" GST_TIME_FORMAT, GST_TIME_ARGS (pos));
g_assert_true (GST_CLOCK_TIME_IS_VALID (pos) && pos > GST_SECOND);
g_object_get (p.src, "ready-state", &ready, NULL);
g_assert_cmpint (ready, >=, GST_MSE_SRC_READY_STATE_HAVE_CURRENT_DATA);
g_assert_cmpint (cv.errors + ca.errors, ==, 0);
gst_element_set_state (p.playbin, GST_STATE_NULL);
gst_clear_object (&video);
gst_clear_object (&audio);
gst_clear_object (&p.src);
gst_clear_object (&p.playbin);
gst_clear_object (&p.source);
counter_clear (&cv);
counter_clear (&ca);
g_mutex_clear (&p.lock);
g_cond_clear (&p.cond);
}
int
main (int argc, char **argv)
{
g_test_init (&argc, &argv, NULL);
gst_init (&argc, &argv);
g_test_add_func ("/mse/update-end-after-parse", test_update_end_after_parse);
g_test_add_func ("/mse/no-idle-updates", test_no_idle_updates);
g_test_add_func ("/mse/split-audio-video", test_split_audio_video);
return g_test_run ();
}

58
tools/gst-mse.sh Executable file
View file

@ -0,0 +1,58 @@
#!/usr/bin/env bash
# Builds Nacre's patched copy of GStreamer's MSE library and plugin (vendor/gst-mse, gst-plugins-bad 1.28.9, LGPL)
# into target/gst-mse/:
# lib/libgstmse-1.0.so.0 the library (same soname as the system one; Nacre's RUNPATH finds this first)
# gstreamer-1.0/libgstmse.so the `mse` plugin (msesrc), found through GST_PLUGIN_PATH (src/main.rs)
# and, with `test`, builds and runs the C tests in tests/gst-mse/ against that library.
#
# Usage: tools/gst-mse.sh [test]
# Needs: cc, pkg-config, gstreamer-1.0, gstreamer-base-1.0, gstreamer-app-1.0.
set -eu
root=$(cd "$(dirname "$0")/.." && pwd)
src=$root/vendor/gst-mse
out=$root/target/gst-mse
mkdir -p "$out/obj" "$out/lib" "$out/gstreamer-1.0"
cflags="-O2 -g -fPIC -fvisibility=hidden -std=gnu11 -Wall -Wno-unused-function
-DGST_USE_UNSTABLE_API -DHAVE_CONFIG_H
-I$src/gen -I$src/gen/gst/mse -I$src/gst-libs -I$src/gst-libs/gst/mse
$(pkg-config --cflags gstreamer-1.0 gstreamer-base-1.0 gstreamer-app-1.0)"
libs=$(pkg-config --libs gstreamer-1.0 gstreamer-base-1.0 gstreamer-app-1.0)
objs=()
for c in "$src"/gst-libs/gst/mse/*.c "$src"/gen/gst/mse/mse-enumtypes.c; do
o=$out/obj/$(basename "$c" .c).o
if [ ! -f "$o" ] || [ "$c" -nt "$o" ] || [ -n "$(find "$src/gst-libs" "$src/gen" -name '*.h' -newer "$o")" ]; then
# shellcheck disable=SC2086
cc $cflags -DBUILDING_GST_MSE -DG_LOG_DOMAIN='"GStreamer-MSE"' -c "$c" -o "$o"
fi
objs+=("$o")
done
# shellcheck disable=SC2086
cc -shared -Wl,-soname,libgstmse-1.0.so.0 -Wl,--no-undefined -o "$out/lib/libgstmse-1.0.so.0" "${objs[@]}" $libs
ln -sf libgstmse-1.0.so.0 "$out/lib/libgstmse-1.0.so"
# The plugin links our library; its RUNPATH points at ../lib so it never pulls in the system copy.
# shellcheck disable=SC2086
cc $cflags -shared -Wl,--no-undefined -Wl,-rpath,'$ORIGIN/../lib' -o "$out/gstreamer-1.0/libgstmse.so" \
"$src/gst/mse/gstmse.c" -L"$out/lib" -lgstmse-1.0 $libs
echo "gst-mse: built $out/lib/libgstmse-1.0.so.0 and $out/gstreamer-1.0/libgstmse.so"
[ "${1:-}" = test ] || exit 0
# C tests: each tests/gst-mse/*.c is a GLib test program run against our library and plugin only.
tcflags="-O0 -g -std=gnu11 -Wall -DGST_USE_UNSTABLE_API -I$src/gen -I$src/gst-libs
$(pkg-config --cflags gstreamer-1.0)"
tlibs="-L$out/lib -lgstmse-1.0 $(pkg-config --libs gstreamer-1.0)"
mkdir -p "$out/tests"
status=0
for t in "$root"/tests/gst-mse/*.c; do
bin=$out/tests/$(basename "$t" .c)
# shellcheck disable=SC2086
cc $tcflags -Wl,-rpath,"$out/lib" -o "$bin" "$t" $tlibs
echo "gst-mse: running $(basename "$bin")"
GST_PLUGIN_PATH=$out/gstreamer-1.0 GST_REGISTRY=$out/tests/registry.bin \
TESTS_DATA_DIR=$root/tests/gst-mse/data "$bin" || status=1
done
exit $status

502
vendor/gst-mse/COPYING vendored Normal file
View file

@ -0,0 +1,502 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the Lesser GPL. It also counts
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it. You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.
When we speak of free software, we are referring to freedom of use,
not price. Our General Public Licenses are designed to make sure that
you have the freedom to distribute copies of free software (and charge
for this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.
To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights. These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.
To protect each distributor, we want to make it very clear that
there is no warranty for the free library. Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.
Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder. Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.
Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License. This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License. We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.
When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library. The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom. The Lesser General
Public License permits more lax criteria for linking other code with
the library.
We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License. It also provides other free software developers Less
of an advantage over competing non-free programs. These disadvantages
are the reason we use the ordinary General Public License for many
libraries. However, the Lesser license provides advantages in certain
special circumstances.
For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard. To achieve this, non-free programs must be
allowed to use the library. A more frequent case is that a free
library does the same job as widely used non-free libraries. In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.
In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software. For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.
Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
e) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Lesser General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the library's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!

8
vendor/gst-mse/gen/config.h vendored Normal file
View file

@ -0,0 +1,8 @@
/* Nacre patch: the few config.h macros the gst_mse sources use (normally written by meson). */
#pragma once
#define PACKAGE "gst-plugins-bad"
#define VERSION "1.28.9"
#define GST_LICENSE "LGPL"
#define GST_PACKAGE_NAME "GStreamer Bad Plug-ins (Nacre patched gst_mse)"
#define GST_PACKAGE_ORIGIN "https://archlinux.tail7c4f5e.ts.net/git/astar76/Nacre"
#define GST_API_VERSION "1.0"

View file

@ -0,0 +1,16 @@
/* Nacre patch: written by hand in place of the glib-mkenums output (no meson build here). */
#pragma once
#include <glib-object.h>
#include <gst/mse/mse-prelude.h>
G_BEGIN_DECLS
/* enumerations from "gstmediasourcetrack-private.h" */
GST_MSE_PRIVATE
GType gst_media_source_track_type_get_type (void);
#define GST_TYPE_MEDIA_SOURCE_TRACK_TYPE (gst_media_source_track_type_get_type())
G_END_DECLS

View file

@ -0,0 +1,43 @@
/* Nacre patch: written by hand in place of the glib-mkenums output (no meson build here).
* Value nicks follow glib-mkenums: the common prefix removed, lower case, '-' for '_'. */
#include "gstmediasource.h"
#include "gstmsesrc.h"
#include "gstsourcebuffer.h"
#include "gstmediasourcetrack-private.h"
#include <gst/mse/mse-enumtypes.h>
#include <gst/mse/mse-enumtypes-private.h>
G_DEFINE_ENUM_TYPE (GstMediaSourceReadyState, gst_media_source_ready_state,
G_DEFINE_ENUM_VALUE (GST_MEDIA_SOURCE_READY_STATE_CLOSED, "closed"),
G_DEFINE_ENUM_VALUE (GST_MEDIA_SOURCE_READY_STATE_OPEN, "open"),
G_DEFINE_ENUM_VALUE (GST_MEDIA_SOURCE_READY_STATE_ENDED, "ended"));
G_DEFINE_ENUM_TYPE (GstMediaSourceError, gst_media_source_error,
G_DEFINE_ENUM_VALUE (GST_MEDIA_SOURCE_ERROR_INVALID_STATE, "invalid-state"),
G_DEFINE_ENUM_VALUE (GST_MEDIA_SOURCE_ERROR_TYPE, "type"),
G_DEFINE_ENUM_VALUE (GST_MEDIA_SOURCE_ERROR_NOT_SUPPORTED, "not-supported"),
G_DEFINE_ENUM_VALUE (GST_MEDIA_SOURCE_ERROR_NOT_FOUND, "not-found"),
G_DEFINE_ENUM_VALUE (GST_MEDIA_SOURCE_ERROR_QUOTA_EXCEEDED, "quota-exceeded"));
G_DEFINE_ENUM_TYPE (GstMediaSourceEOSError, gst_media_source_eos_error,
G_DEFINE_ENUM_VALUE (GST_MEDIA_SOURCE_EOS_ERROR_NONE, "none"),
G_DEFINE_ENUM_VALUE (GST_MEDIA_SOURCE_EOS_ERROR_NETWORK, "network"),
G_DEFINE_ENUM_VALUE (GST_MEDIA_SOURCE_EOS_ERROR_DECODE, "decode"));
G_DEFINE_ENUM_TYPE (GstMseSrcReadyState, gst_mse_src_ready_state,
G_DEFINE_ENUM_VALUE (GST_MSE_SRC_READY_STATE_HAVE_NOTHING, "nothing"),
G_DEFINE_ENUM_VALUE (GST_MSE_SRC_READY_STATE_HAVE_METADATA, "metadata"),
G_DEFINE_ENUM_VALUE (GST_MSE_SRC_READY_STATE_HAVE_CURRENT_DATA, "current-data"),
G_DEFINE_ENUM_VALUE (GST_MSE_SRC_READY_STATE_HAVE_FUTURE_DATA, "future-data"),
G_DEFINE_ENUM_VALUE (GST_MSE_SRC_READY_STATE_HAVE_ENOUGH_DATA, "enough-data"));
G_DEFINE_ENUM_TYPE (GstSourceBufferAppendMode, gst_source_buffer_append_mode,
G_DEFINE_ENUM_VALUE (GST_SOURCE_BUFFER_APPEND_MODE_SEGMENTS, "segments"),
G_DEFINE_ENUM_VALUE (GST_SOURCE_BUFFER_APPEND_MODE_SEQUENCE, "sequence"));
G_DEFINE_ENUM_TYPE (GstMediaSourceTrackType, gst_media_source_track_type,
G_DEFINE_ENUM_VALUE (GST_MEDIA_SOURCE_TRACK_TYPE_AUDIO, "audio"),
G_DEFINE_ENUM_VALUE (GST_MEDIA_SOURCE_TRACK_TYPE_VIDEO, "video"),
G_DEFINE_ENUM_VALUE (GST_MEDIA_SOURCE_TRACK_TYPE_TEXT, "text"),
G_DEFINE_ENUM_VALUE (GST_MEDIA_SOURCE_TRACK_TYPE_OTHER, "other"));

View file

@ -0,0 +1,40 @@
/* Nacre patch: written by hand in place of the glib-mkenums output (no meson build here). */
/* This file is generated by glib-mkenums, do not modify it. This code is licensed under the same license as the containing project. Note that it links to GLib, so must comply with the LGPL linking clauses. */
#pragma once
#include <glib-object.h>
#include <gst/mse/mse-prelude.h>
G_BEGIN_DECLS
/* enumerations from "gstmediasource.h" */
GST_MSE_API
GType gst_media_source_ready_state_get_type (void);
#define GST_TYPE_MEDIA_SOURCE_READY_STATE (gst_media_source_ready_state_get_type())
GST_MSE_API
GType gst_media_source_error_get_type (void);
#define GST_TYPE_MEDIA_SOURCE_ERROR (gst_media_source_error_get_type())
GST_MSE_API
GType gst_media_source_eos_error_get_type (void);
#define GST_TYPE_MEDIA_SOURCE_EOS_ERROR (gst_media_source_eos_error_get_type())
/* enumerations from "gstmsesrc.h" */
GST_MSE_API
GType gst_mse_src_ready_state_get_type (void);
#define GST_TYPE_MSE_SRC_READY_STATE (gst_mse_src_ready_state_get_type())
/* enumerations from "gstsourcebuffer.h" */
GST_MSE_API
GType gst_source_buffer_append_mode_get_type (void);
#define GST_TYPE_SOURCE_BUFFER_APPEND_MODE (gst_source_buffer_append_mode_get_type())
G_END_DECLS
/* Generated data ends here */

View file

@ -0,0 +1,102 @@
/* GStreamer
*
* SPDX-License-Identifier: LGPL-2.1
*
* Copyright (C) 2016, 2017 Metrological Group B.V.
* Copyright (C) 2016, 2017 Igalia S.L
* Copyright (C) 2022, 2023 Collabora Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#pragma once
#include <gst/gst.h>
#include <glib-object.h>
#include <gst/mse/mse-prelude.h>
#include <gst/mse/gstmediasourcetrack-private.h>
G_BEGIN_DECLS
#define GST_TYPE_APPEND_PIPELINE (gst_append_pipeline_get_type())
GST_MSE_PRIVATE
G_DECLARE_FINAL_TYPE (GstAppendPipeline, gst_append_pipeline, GST,
APPEND_PIPELINE, GstObject);
typedef struct
{
void (*received_init_segment) (GstAppendPipeline * self,
gpointer user_data);
void (*duration_changed) (GstAppendPipeline * self,
gpointer user_data);
void (*new_sample) (GstAppendPipeline * self,
GstMediaSourceTrack * track,
GstSample * sample,
gpointer user_data);
void (*eos) (GstAppendPipeline * self,
GstMediaSourceTrack * track,
gpointer user_data);
void (*error) (GstAppendPipeline * self,
gpointer user_data);
} GstAppendPipelineCallbacks;
GST_MSE_PRIVATE
GstAppendPipeline * gst_append_pipeline_new (
GstAppendPipelineCallbacks * callbacks, gpointer user_data,
GError ** error);
GST_MSE_PRIVATE
GstFlowReturn gst_append_pipeline_append (GstAppendPipeline * self,
GstBuffer * buffer);
GST_MSE_PRIVATE
GstFlowReturn gst_append_pipeline_eos (GstAppendPipeline * self);
GST_MSE_PRIVATE
gboolean gst_append_pipeline_stop (GstAppendPipeline * self);
GST_MSE_PRIVATE
gboolean gst_append_pipeline_reset (GstAppendPipeline * self);
GST_MSE_PRIVATE
gsize gst_append_pipeline_n_tracks (GstAppendPipeline * self);
GST_MSE_PRIVATE
gboolean gst_append_pipeline_has_init_segment (GstAppendPipeline * self);
GST_MSE_PRIVATE
GstClockTime gst_append_pipeline_get_duration (GstAppendPipeline * self);
GST_MSE_PRIVATE
GPtrArray *gst_append_pipeline_get_audio_tracks (GstAppendPipeline * self);
GST_MSE_PRIVATE
GPtrArray *gst_append_pipeline_get_text_tracks (GstAppendPipeline * self);
GST_MSE_PRIVATE
GPtrArray *gst_append_pipeline_get_video_tracks (GstAppendPipeline * self);
GST_MSE_PRIVATE
gboolean gst_append_pipeline_get_eos (GstAppendPipeline * self);
GST_MSE_PRIVATE
void gst_append_pipeline_fail (GstAppendPipeline * self);
GST_MSE_PRIVATE
gboolean gst_append_pipeline_get_failed (GstAppendPipeline * self);
G_END_DECLS

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,58 @@
/* GStreamer
*
* SPDX-License-Identifier: LGPL-2.1
*
* Copyright (C) 2022, 2023 Collabora Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#pragma once
#include "gstmediasource.h"
#include "gstmseeventqueue-private.h"
G_BEGIN_DECLS
GST_MSE_PRIVATE
gboolean gst_media_source_is_attached (GstMediaSource * self);
GST_MSE_PRIVATE
void gst_media_source_open (GstMediaSource * self);
GST_MSE_PRIVATE
GstMseSrc * gst_media_source_get_source_element (GstMediaSource * self);
GST_MSE_PRIVATE
void gst_media_source_seek (GstMediaSource * self, GstClockTime time);
struct _GstMediaSource
{
GstObject parent_instance;
GstMseSrc *element;
GstMseEventQueue *event_queue;
GstSourceBufferList *buffers;
GstSourceBufferList *active_buffers;
GstMediaSourceRange live_seekable_range;
GstClockTime duration;
GstMediaSourceReadyState ready_state;
};
G_END_DECLS

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,203 @@
/* GStreamer
*
* SPDX-License-Identifier: LGPL-2.1
*
* Copyright (C) 2013 Google Inc. All rights reserved.
* Copyright (C) 2013 Orange
* Copyright (C) 2013-2017 Apple Inc. All rights reserved.
* Copyright (C) 2014 Sebastian Dröge <sebastian@centricular.com>
* Copyright (C) 2015, 2016 Igalia, S.L
* Copyright (C) 2015, 2016 Metrological Group B.V.
* Copyright (C) 2022, 2023 Collabora Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#pragma once
#include <gst/gst.h>
#include <gst/mse/mse-prelude.h>
#include <gst/mse/gstmsesrc.h>
#include "gstsourcebufferlist.h"
G_BEGIN_DECLS
/**
* GstMediaSourceReadyState:
* @GST_MEDIA_SOURCE_READY_STATE_CLOSED: The #GstMediaSource is not connected to
* any playback element.
* @GST_MEDIA_SOURCE_READY_STATE_OPEN: The #GstMediaSource is connected to a
* playback element and ready to append data to its #GstSourceBuffer (s).
* @GST_MEDIA_SOURCE_READY_STATE_ENDED: gst_media_source_end_of_stream() has
* been called on the current #GstMediaSource
*
* Describes the possible states of the Media Source.
*
* [Specification](https://www.w3.org/TR/media-source-2/#dom-readystate)
*
* Since: 1.24
*/
typedef enum
{
GST_MEDIA_SOURCE_READY_STATE_CLOSED,
GST_MEDIA_SOURCE_READY_STATE_OPEN,
GST_MEDIA_SOURCE_READY_STATE_ENDED,
} GstMediaSourceReadyState;
/**
* GstMediaSourceError:
* @GST_MEDIA_SOURCE_ERROR_INVALID_STATE:
* @GST_MEDIA_SOURCE_ERROR_TYPE:
* @GST_MEDIA_SOURCE_ERROR_NOT_SUPPORTED:
* @GST_MEDIA_SOURCE_ERROR_NOT_FOUND:
* @GST_MEDIA_SOURCE_ERROR_QUOTA_EXCEEDED:
*
* Any error that can occur within #GstMediaSource or #GstSourceBuffer APIs.
* These values correspond directly to those in the Web IDL specification.
*
* [Specification](https://webidl.spec.whatwg.org/#idl-DOMException-error-names)
*
* Since: 1.24
*/
typedef enum
{
GST_MEDIA_SOURCE_ERROR_INVALID_STATE,
GST_MEDIA_SOURCE_ERROR_TYPE,
GST_MEDIA_SOURCE_ERROR_NOT_SUPPORTED,
GST_MEDIA_SOURCE_ERROR_NOT_FOUND,
GST_MEDIA_SOURCE_ERROR_QUOTA_EXCEEDED,
} GstMediaSourceError;
/**
* GstMediaSourceEOSError:
* @GST_MEDIA_SOURCE_EOS_ERROR_NONE: End the stream successfully
* @GST_MEDIA_SOURCE_EOS_ERROR_NETWORK: End the stream due to a networking error
* @GST_MEDIA_SOURCE_EOS_ERROR_DECODE: End the stream due to a decoding error
*
* Reasons for ending a #GstMediaSource using gst_media_source_end_of_stream().
*
* [Specification](https://www.w3.org/TR/media-source-2/#dom-endofstreamerror)
*
* Since: 1.24
*/
typedef enum
{
GST_MEDIA_SOURCE_EOS_ERROR_NONE,
GST_MEDIA_SOURCE_EOS_ERROR_NETWORK,
GST_MEDIA_SOURCE_EOS_ERROR_DECODE,
} GstMediaSourceEOSError;
/**
* GstMediaSourceRange:
* @start: The start of this range.
* @end: The end of this range.
*
* A structure describing a simplified version of the TimeRanges concept in the
* HTML specification, only representing a single @start and @end time.
*
* [Specification](https://html.spec.whatwg.org/multipage/media.html#timeranges)
*
* Since: 1.24
*/
typedef struct
{
GstClockTime start;
GstClockTime end;
} GstMediaSourceRange;
GST_MSE_API
gboolean gst_media_source_is_type_supported (const gchar * type);
#define GST_TYPE_MEDIA_SOURCE (gst_media_source_get_type())
#define GST_MEDIA_SOURCE_ERROR (gst_media_source_error_quark())
/**
* gst_media_source_error_quark:
*
* Any error type that can be reported by the Media Source API.
*
* Since: 1.24
*/
GST_MSE_API
GQuark gst_media_source_error_quark (void);
GST_MSE_API
G_DECLARE_FINAL_TYPE (GstMediaSource, gst_media_source, GST, MEDIA_SOURCE,
GstObject);
GST_MSE_API
GstMediaSource *gst_media_source_new (void) G_GNUC_WARN_UNUSED_RESULT;
GST_MSE_API
void gst_media_source_attach (GstMediaSource * self, GstMseSrc * element);
GST_MSE_API
void gst_media_source_detach (GstMediaSource * self);
GST_MSE_API
GstSourceBufferList * gst_media_source_get_source_buffers (
GstMediaSource * self) G_GNUC_WARN_UNUSED_RESULT;
GST_MSE_API
GstSourceBufferList * gst_media_source_get_active_source_buffers (
GstMediaSource * self) G_GNUC_WARN_UNUSED_RESULT;
GST_MSE_API
GstMediaSourceReadyState gst_media_source_get_ready_state (
GstMediaSource * self);
GST_MSE_API
GstClockTime gst_media_source_get_position (GstMediaSource * self);
GST_MSE_API
GstClockTime gst_media_source_get_duration (GstMediaSource * self);
GST_MSE_API
gboolean gst_media_source_set_duration (GstMediaSource * self,
GstClockTime duration,
GError ** error);
GST_MSE_API
GstSourceBuffer * gst_media_source_add_source_buffer (GstMediaSource * self,
const gchar * type,
GError ** error) G_GNUC_WARN_UNUSED_RESULT;
GST_MSE_API
gboolean gst_media_source_remove_source_buffer (GstMediaSource * self,
GstSourceBuffer * buffer,
GError ** error);
GST_MSE_API
gboolean gst_media_source_end_of_stream (GstMediaSource * self,
GstMediaSourceEOSError eos_error,
GError ** error);
GST_MSE_API
gboolean gst_media_source_set_live_seekable_range (GstMediaSource * self,
GstClockTime start,
GstClockTime end,
GError ** error);
GST_MSE_API
gboolean gst_media_source_clear_live_seekable_range (GstMediaSource * self,
GError ** error);
GST_MSE_API
void gst_media_source_get_live_seekable_range (GstMediaSource * self,
GstMediaSourceRange * range);
G_END_DECLS

View file

@ -0,0 +1,108 @@
/* GStreamer
*
* SPDX-License-Identifier: LGPL-2.1
*
* Copyright (C) 2022, 2023 Collabora Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#pragma once
#include <gst/gst.h>
#include <gst/mse/mse-prelude.h>
G_BEGIN_DECLS
#define GST_TYPE_MEDIA_SOURCE_SAMPLE_MAP \
(gst_media_source_sample_map_get_type())
#define GST_TYPE_MEDIA_SOURCE_CODED_FRAME_GROUP \
(gst_media_source_coded_frame_group_get_type())
#define gst_value_get_media_source_coded_frame_group(v) \
(GstMediaSourceCodedFrameGroup *)(g_value_get_boxed (v))
#define gst_value_take_media_source_coded_frame_group(v, g) \
g_value_take_boxed ((v), (g))
typedef struct {
GstClockTime start;
GstClockTime end;
gsize size;
GList *samples;
} GstMediaSourceCodedFrameGroup;
GST_MSE_PRIVATE
G_DECLARE_FINAL_TYPE (GstMediaSourceSampleMap, gst_media_source_sample_map, GST,
MEDIA_SOURCE_SAMPLE_MAP, GstObject);
GST_MSE_PRIVATE
GstMediaSourceSampleMap *gst_media_source_sample_map_new (void);
GST_MSE_PRIVATE
void gst_media_source_sample_map_add (GstMediaSourceSampleMap * self,
GstSample * sample);
GST_MSE_PRIVATE
void gst_media_source_sample_map_remove (GstMediaSourceSampleMap * self,
GstSample * sample);
GST_MSE_PRIVATE
gsize gst_media_source_sample_map_remove_range (GstMediaSourceSampleMap * self,
GstClockTime earliest, GstClockTime latest);
GST_MSE_PRIVATE
gboolean gst_media_source_sample_map_contains (GstMediaSourceSampleMap * self,
GstSample * sample);
GST_MSE_PRIVATE
GSequenceIter * gst_media_source_sample_map_get_begin_iter_by_pts (
GstMediaSourceSampleMap * self);
GST_MSE_PRIVATE
GstClockTime gst_media_source_sample_map_get_highest_end_time (
GstMediaSourceSampleMap * self);
GST_MSE_PRIVATE
guint gst_media_source_sample_map_get_size (GstMediaSourceSampleMap * self);
GST_MSE_PRIVATE
gsize gst_media_source_sample_map_get_storage_size (
GstMediaSourceSampleMap * self);
GST_MSE_PRIVATE
GstIterator *
gst_media_source_sample_map_iter_samples_by_dts (GstMediaSourceSampleMap * self,
GMutex * lock, guint32 * master_cookie);
GST_MSE_PRIVATE
GstIterator *
gst_media_source_sample_map_iter_samples_by_pts (GstMediaSourceSampleMap * self,
GMutex * lock, guint32 * master_cookie);
GST_MSE_PRIVATE
GType gst_media_source_coded_frame_group_get_type (void);
GST_MSE_PRIVATE
GstMediaSourceCodedFrameGroup *
gst_media_source_coded_frame_group_copy (GstMediaSourceCodedFrameGroup * group);
GST_MSE_PRIVATE
void
gst_media_source_coded_frame_group_free (GstMediaSourceCodedFrameGroup * group);
G_END_DECLS

View file

@ -0,0 +1,552 @@
/* GStreamer
*
* SPDX-License-Identifier: LGPL-2.1
*
* Copyright (C) 2022, 2023 Collabora Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gstmediasourcesamplemap-private.h"
#include "gstmselogging-private.h"
G_DEFINE_BOXED_TYPE (GstMediaSourceCodedFrameGroup,
gst_media_source_coded_frame_group,
gst_media_source_coded_frame_group_copy,
gst_media_source_coded_frame_group_free);
#define TIME_RANGE_FORMAT \
"[%" GST_TIMEP_FORMAT "..%" GST_TIMEP_FORMAT ")"
#define TIME_RANGE_ARGS(a, b) &(a), &(b)
#define CODED_FRAME_GROUP_ARGS(g) TIME_RANGE_ARGS ((g)->start, (g)->end)
struct _GstMediaSourceSampleMap
{
GstObject parent_instance;
GHashTable *samples;
GSequence *samples_by_dts;
GSequence *samples_by_pts;
gsize storage_size;
};
G_DEFINE_TYPE (GstMediaSourceSampleMap, gst_media_source_sample_map,
GST_TYPE_OBJECT);
static GstMediaSourceCodedFrameGroup *new_coded_frame_group_from_memory (const
GstMediaSourceCodedFrameGroup * src);
static gint compare_pts (GstSample * a, GstSample * b, gpointer user_data);
static GSequenceIter *next_coded_frame_group (GSequenceIter * it, GValue * val);
static inline GstClockTime
sample_duration (GstSample * sample)
{
return GST_BUFFER_DURATION (gst_sample_get_buffer (sample));
}
static inline GstClockTime
sample_dts (GstSample * sample)
{
return GST_BUFFER_DTS (gst_sample_get_buffer (sample));
}
static inline GstClockTime
sample_dts_end (GstSample * sample)
{
return sample_dts (sample) + sample_duration (sample);
}
static inline GstClockTime
sample_pts (GstSample * sample)
{
return GST_BUFFER_PTS (gst_sample_get_buffer (sample));
}
static gsize
sample_buffer_size (GstSample * sample)
{
return gst_buffer_get_size (gst_sample_get_buffer (sample));
}
static inline gboolean
sample_is_key_unit (GstSample * sample)
{
GstBuffer *buffer = gst_sample_get_buffer (sample);
return !GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT);
}
static gint
compare_dts (GstSample * a, GstSample * b, gpointer user_data)
{
GstClockTime a_dts = sample_dts (a);
GstClockTime b_dts = sample_dts (b);
if (a_dts == b_dts) {
return compare_pts (a, b, user_data);
}
return a_dts > b_dts ? +1 : -1;
}
static gint
compare_pts (GstSample * a, GstSample * b, gpointer user_data)
{
GstClockTime a_pts = sample_pts (a);
GstClockTime b_pts = sample_pts (b);
if (a_pts == b_pts) {
return 0;
}
return a_pts > b_pts ? +1 : -1;
}
static inline void
remove_sample (GSequence * sequence, GCompareDataFunc compare,
GstSample * sample, GstMediaSourceSampleMap * self)
{
GSequenceIter *match = g_sequence_lookup (sequence, sample, compare, self);
if (match == NULL) {
return;
}
g_sequence_remove (match);
}
GstMediaSourceSampleMap *
gst_media_source_sample_map_new (void)
{
gst_mse_init_logging ();
return gst_object_ref_sink (g_object_new (GST_TYPE_MEDIA_SOURCE_SAMPLE_MAP,
NULL));
}
static void
gst_media_source_sample_map_finalize (GObject * object)
{
GstMediaSourceSampleMap *self = GST_MEDIA_SOURCE_SAMPLE_MAP (object);
g_sequence_free (self->samples_by_dts);
g_sequence_free (self->samples_by_pts);
g_hash_table_unref (self->samples);
G_OBJECT_CLASS (gst_media_source_sample_map_parent_class)->finalize (object);
}
static void
gst_media_source_sample_map_class_init (GstMediaSourceSampleMapClass * klass)
{
GObjectClass *oclass = G_OBJECT_CLASS (klass);
oclass->finalize = GST_DEBUG_FUNCPTR (gst_media_source_sample_map_finalize);
}
static void
gst_media_source_sample_map_init (GstMediaSourceSampleMap * self)
{
self->samples = g_hash_table_new_full (g_direct_hash, g_direct_equal,
(GDestroyNotify) gst_sample_unref, NULL);
self->samples_by_dts = g_sequence_new ((GDestroyNotify) gst_sample_unref);
self->samples_by_pts = g_sequence_new ((GDestroyNotify) gst_sample_unref);
}
void
gst_media_source_sample_map_add (GstMediaSourceSampleMap * self,
GstSample * sample)
{
g_return_if_fail (GST_IS_MEDIA_SOURCE_SAMPLE_MAP (self));
g_return_if_fail (GST_IS_SAMPLE (sample));
GstBuffer *buffer = gst_sample_get_buffer (sample);
g_return_if_fail (GST_BUFFER_DTS_IS_VALID (buffer));
g_return_if_fail (GST_BUFFER_PTS_IS_VALID (buffer));
g_return_if_fail (GST_BUFFER_DURATION_IS_VALID (buffer));
if (g_hash_table_contains (self->samples, sample)) {
return;
}
g_hash_table_add (self->samples, gst_sample_ref (sample));
g_sequence_insert_sorted (self->samples_by_dts, gst_sample_ref (sample),
(GCompareDataFunc) compare_dts, self);
g_sequence_insert_sorted (self->samples_by_pts, gst_sample_ref (sample),
(GCompareDataFunc) compare_pts, self);
self->storage_size += gst_buffer_get_size (buffer);
GST_TRACE_OBJECT (self, "new storage size=%" G_GSIZE_FORMAT,
self->storage_size);
}
void
gst_media_source_sample_map_remove (GstMediaSourceSampleMap * self,
GstSample * sample)
{
g_return_if_fail (GST_IS_MEDIA_SOURCE_SAMPLE_MAP (self));
g_return_if_fail (GST_IS_SAMPLE (sample));
if (!g_hash_table_contains (self->samples, sample)) {
return;
}
gsize buffer_size = sample_buffer_size (sample);
remove_sample (self->samples_by_dts, (GCompareDataFunc) compare_dts, sample,
self);
remove_sample (self->samples_by_pts, (GCompareDataFunc) compare_pts, sample,
self);
g_hash_table_remove (self->samples, sample);
self->storage_size -= MIN (buffer_size, self->storage_size);
}
gboolean
gst_media_source_sample_map_contains (GstMediaSourceSampleMap * self,
GstSample * sample)
{
g_return_val_if_fail (GST_IS_MEDIA_SOURCE_SAMPLE_MAP (self), FALSE);
return g_hash_table_contains (self->samples, sample);
}
static GSequenceIter *
next_key_unit (GSequenceIter * it)
{
for (; !g_sequence_iter_is_end (it); it = g_sequence_iter_next (it)) {
GstSample *sample = g_sequence_get (it);
if (sample_is_key_unit (sample)) {
break;
}
}
return it;
}
static GSequenceIter *
next_coded_frame_group (GSequenceIter * it, GValue * val)
{
it = next_key_unit (it);
if (g_sequence_iter_is_end (it)) {
return it;
}
GstSample *head = g_sequence_get (it);
g_return_val_if_fail (sample_is_key_unit (head), NULL);
GstMediaSourceCodedFrameGroup group = {
.start = sample_dts (head),
.end = sample_dts_end (head),
.samples = g_list_prepend (NULL, gst_sample_ref (head)),
.size = 1,
};
it = g_sequence_iter_next (it);
for (; !g_sequence_iter_is_end (it); it = g_sequence_iter_next (it)) {
GstSample *sample = g_sequence_get (it);
if (sample_is_key_unit (sample)) {
goto done;
}
group.end = sample_dts_end (sample), group.size++;
group.samples = g_list_prepend (group.samples, gst_sample_ref (sample));
}
done:
group.samples = g_list_reverse (group.samples);
GstMediaSourceCodedFrameGroup *box =
new_coded_frame_group_from_memory (&group);
gst_value_take_media_source_coded_frame_group (val, box);
return it;
}
static GSequenceIter *
find_start_point (GstMediaSourceSampleMap * self, GSequenceIter * it,
GList ** to_remove, GstClockTime earliest, GstClockTime latest)
{
while (TRUE) {
GValue value = G_VALUE_INIT;
g_value_init (&value, GST_TYPE_MEDIA_SOURCE_CODED_FRAME_GROUP);
it = next_coded_frame_group (it, &value);
GstMediaSourceCodedFrameGroup *group =
gst_value_get_media_source_coded_frame_group (&value);
if (group == NULL) {
GST_TRACE_OBJECT (self,
"reached end of coded frames before finding start point");
goto done;
}
if (group->start >= earliest && group->end <= latest) {
GST_TRACE_OBJECT (self, "found start point for %" GST_TIMEP_FORMAT ": "
TIME_RANGE_FORMAT, &earliest, CODED_FRAME_GROUP_ARGS (group));
*to_remove = g_list_prepend (*to_remove,
gst_media_source_coded_frame_group_copy (group));
goto done;
}
g_value_unset (&value);
continue;
done:
g_value_unset (&value);
return it;
}
return it;
}
static GSequenceIter *
find_end_point (GstMediaSourceSampleMap * self, GSequenceIter * it, GList **
to_remove, GstClockTime latest)
{
while (TRUE) {
GValue value = G_VALUE_INIT;
g_value_init (&value, GST_TYPE_MEDIA_SOURCE_CODED_FRAME_GROUP);
it = next_coded_frame_group (it, &value);
GstMediaSourceCodedFrameGroup *group =
gst_value_get_media_source_coded_frame_group (&value);
if (group == NULL) {
GST_TRACE_OBJECT (self,
"reached end of coded frames before finding end point");
goto done;
}
if (group->end >= latest) {
GST_TRACE_OBJECT (self, "found end point for %" GST_TIMEP_FORMAT ": "
TIME_RANGE_FORMAT, &latest, CODED_FRAME_GROUP_ARGS (group));
goto done;
}
*to_remove = g_list_prepend (*to_remove,
gst_media_source_coded_frame_group_copy (group));
g_value_unset (&value);
continue;
done:
g_value_unset (&value);
return it;
}
return it;
}
gsize
gst_media_source_sample_map_remove_range (GstMediaSourceSampleMap * self,
GstClockTime earliest, GstClockTime latest)
{
g_return_val_if_fail (GST_IS_MEDIA_SOURCE_SAMPLE_MAP (self), 0);
g_return_val_if_fail (earliest <= latest, 0);
GST_TRACE_OBJECT (self, "request remove range " TIME_RANGE_FORMAT,
TIME_RANGE_ARGS (earliest, latest));
GSequenceIter *it = g_sequence_get_begin_iter (self->samples_by_dts);
GList *to_remove = NULL;
it = find_start_point (self, it, &to_remove, earliest, latest);
if (to_remove == NULL) {
return 0;
}
it = find_end_point (self, it, &to_remove, latest);
to_remove = g_list_reverse (to_remove);
gsize bytes_removed = 0;
for (GList * group_iter = to_remove; group_iter != NULL;
group_iter = g_list_next (group_iter)) {
GstMediaSourceCodedFrameGroup *group = group_iter->data;
for (GList * sample_iter = group->samples; sample_iter != NULL;
sample_iter = g_list_next (sample_iter)) {
GstSample *sample = sample_iter->data;
bytes_removed += sample_buffer_size (sample);
gst_media_source_sample_map_remove (self, sample);
}
}
g_list_free_full (to_remove,
(GDestroyNotify) gst_media_source_coded_frame_group_free);
GST_TRACE_OBJECT (self, "removed=%" G_GSIZE_FORMAT "B, latest=%"
GST_TIMEP_FORMAT, bytes_removed, &latest);
return bytes_removed;
}
GstClockTime
gst_media_source_sample_map_get_highest_end_time (GstMediaSourceSampleMap *
self)
{
g_return_val_if_fail (GST_IS_MEDIA_SOURCE_SAMPLE_MAP (self),
GST_CLOCK_TIME_NONE);
GSequenceIter *iter = g_sequence_get_end_iter (self->samples_by_pts);
iter = g_sequence_iter_prev (iter);
if (g_sequence_iter_is_begin (iter)) {
return GST_CLOCK_TIME_NONE;
}
GstSample *sample = g_sequence_get (iter);
GstBuffer *buffer = gst_sample_get_buffer (sample);
g_return_val_if_fail (GST_BUFFER_PTS_IS_VALID (buffer), GST_CLOCK_TIME_NONE);
g_return_val_if_fail (GST_BUFFER_DURATION_IS_VALID (buffer),
GST_CLOCK_TIME_NONE);
return GST_BUFFER_PTS (buffer) + GST_BUFFER_DURATION (buffer);
}
guint
gst_media_source_sample_map_get_size (GstMediaSourceSampleMap * self)
{
g_return_val_if_fail (GST_IS_MEDIA_SOURCE_SAMPLE_MAP (self), 0);
return g_hash_table_size (self->samples);
}
gsize
gst_media_source_sample_map_get_storage_size (GstMediaSourceSampleMap * self)
{
g_return_val_if_fail (GST_IS_MEDIA_SOURCE_SAMPLE_MAP (self), 0);
return self->storage_size;
}
typedef struct _SampleMapIterator SampleMapIterator;
struct _SampleMapIterator
{
GstIterator iterator;
GstMediaSourceSampleMap *map;
GSequenceIter *(*reset_func) (SampleMapIterator *);
GSequenceIter *current_iter;
};
static void
iter_copy (const SampleMapIterator * it, SampleMapIterator * copy)
{
copy->map = gst_object_ref (it->map);
copy->reset_func = it->reset_func;
copy->current_iter = it->current_iter;
}
static GSequenceIter *
iter_reset_by_dts (SampleMapIterator * it)
{
return g_sequence_get_begin_iter (it->map->samples_by_dts);
}
static GSequenceIter *
iter_reset_by_pts (SampleMapIterator * it)
{
return g_sequence_get_begin_iter (it->map->samples_by_pts);
}
static GstIteratorResult
iter_next_sample (SampleMapIterator * it, GValue * result)
{
if (g_sequence_iter_is_end (it->current_iter)) {
return GST_ITERATOR_DONE;
}
GstSample *sample = g_sequence_get (it->current_iter);
it->current_iter = g_sequence_iter_next (it->current_iter);
gst_value_set_sample (result, sample);
return GST_ITERATOR_OK;
}
static GstIteratorResult
iter_next_group (SampleMapIterator * it, GValue * result)
{
if (g_sequence_iter_is_end (it->current_iter)) {
return GST_ITERATOR_DONE;
}
it->current_iter = next_coded_frame_group (it->current_iter, result);
return GST_ITERATOR_OK;
}
static void
iter_resync (SampleMapIterator * it)
{
GST_TRACE_OBJECT (it->map, "resync");
it->current_iter = it->reset_func (it);
}
static void
iter_free (SampleMapIterator * it)
{
gst_clear_object (&it->map);
}
GstIterator *
gst_media_source_sample_map_iter_samples_by_dts (GstMediaSourceSampleMap * self,
GMutex * lock, guint32 * master_cookie)
{
/* *INDENT-OFF* */
SampleMapIterator *it = (SampleMapIterator *) gst_iterator_new (
sizeof (SampleMapIterator),
GST_TYPE_MEDIA_SOURCE_CODED_FRAME_GROUP,
lock,
master_cookie,
(GstIteratorCopyFunction) iter_copy,
(GstIteratorNextFunction) iter_next_group,
(GstIteratorItemFunction) NULL,
(GstIteratorResyncFunction) iter_resync,
(GstIteratorFreeFunction) iter_free
);
/* *INDENT-ON* */
it->map = gst_object_ref (self);
it->reset_func = iter_reset_by_dts;
it->current_iter = iter_reset_by_dts (it);
return GST_ITERATOR (it);
}
GstIterator *
gst_media_source_sample_map_iter_samples_by_pts (GstMediaSourceSampleMap * self,
GMutex * lock, guint32 * master_cookie)
{
/* *INDENT-OFF* */
SampleMapIterator *it = (SampleMapIterator *) gst_iterator_new (
sizeof (SampleMapIterator),
GST_TYPE_SAMPLE,
lock,
master_cookie,
(GstIteratorCopyFunction) iter_copy,
(GstIteratorNextFunction) iter_next_sample,
(GstIteratorItemFunction) NULL,
(GstIteratorResyncFunction) iter_resync,
(GstIteratorFreeFunction) iter_free
);
/* *INDENT-ON* */
it->map = gst_object_ref (self);
it->reset_func = iter_reset_by_pts;
it->current_iter = iter_reset_by_pts (it);
return GST_ITERATOR (it);
}
static GstMediaSourceCodedFrameGroup *
new_coded_frame_group_from_memory (const GstMediaSourceCodedFrameGroup * src)
{
GstMediaSourceCodedFrameGroup *box =
g_atomic_rc_box_new0 (GstMediaSourceCodedFrameGroup);
memcpy (box, src, sizeof (GstMediaSourceCodedFrameGroup));
return box;
}
GstMediaSourceCodedFrameGroup *
gst_media_source_coded_frame_group_copy (GstMediaSourceCodedFrameGroup * self)
{
return g_atomic_rc_box_acquire (self);
}
static void
free_group_inner (GstMediaSourceCodedFrameGroup * self)
{
g_list_free_full (self->samples, (GDestroyNotify) gst_sample_unref);
}
void
gst_media_source_coded_frame_group_free (GstMediaSourceCodedFrameGroup * self)
{
g_atomic_rc_box_release_full (self, (GDestroyNotify) free_group_inner);
}

View file

@ -0,0 +1,106 @@
/* GStreamer
*
* SPDX-License-Identifier: LGPL-2.1
*
* Copyright (C) 2022, 2023 Collabora Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#pragma once
#include <gst/gst.h>
#include <gst/mse/mse-prelude.h>
G_BEGIN_DECLS
typedef enum
{
GST_MEDIA_SOURCE_TRACK_TYPE_AUDIO,
GST_MEDIA_SOURCE_TRACK_TYPE_VIDEO,
GST_MEDIA_SOURCE_TRACK_TYPE_TEXT,
GST_MEDIA_SOURCE_TRACK_TYPE_OTHER,
} GstMediaSourceTrackType;
#define GST_TYPE_MEDIA_SOURCE_TRACK (gst_media_source_track_get_type())
GST_MSE_PRIVATE
G_DECLARE_FINAL_TYPE (GstMediaSourceTrack, gst_media_source_track, GST,
MEDIA_SOURCE_TRACK, GstObject);
GST_MSE_PRIVATE
GstMediaSourceTrackType gst_media_source_track_get_track_type (
GstMediaSourceTrack * self);
GST_MSE_PRIVATE
const gchar *
gst_media_source_track_get_id (GstMediaSourceTrack * self);
GST_MSE_PRIVATE
gboolean gst_media_source_track_get_active (GstMediaSourceTrack * self);
GST_MSE_PRIVATE
GstMediaSourceTrack *gst_media_source_track_new (GstMediaSourceTrackType type,
const gchar * track_id);
GST_MSE_PRIVATE
GstMediaSourceTrack *
gst_media_source_track_new_with_initial_caps (GstMediaSourceTrackType type,
const gchar * track_id, GstCaps * initial_caps);
GST_MSE_PRIVATE
GstMediaSourceTrack * gst_media_source_track_new_with_size (
GstMediaSourceTrackType type, const gchar * track_id, gsize size);
GST_MSE_PRIVATE
GstCaps *gst_media_source_track_get_initial_caps (GstMediaSourceTrack * self);
GST_MSE_PRIVATE
GstStreamType
gst_media_source_track_get_stream_type (GstMediaSourceTrack * self);
GST_MSE_API
void gst_media_source_track_set_active (GstMediaSourceTrack * self,
gboolean active);
GST_MSE_PRIVATE
GstMiniObject *gst_media_source_track_pop (GstMediaSourceTrack * self);
GST_MSE_PRIVATE
gboolean gst_media_source_track_push (GstMediaSourceTrack * self,
GstSample * sample);
GST_MSE_PRIVATE
gboolean gst_media_source_track_push_eos (GstMediaSourceTrack * self);
GST_MSE_PRIVATE
void gst_media_source_track_flush (GstMediaSourceTrack * self);
GST_MSE_PRIVATE
void gst_media_source_track_resume (GstMediaSourceTrack * self);
GST_MSE_PRIVATE
gboolean gst_media_source_track_is_empty (GstMediaSourceTrack * self);
GST_MSE_PRIVATE
GstStreamType gst_media_source_track_type_to_stream_type (
GstMediaSourceTrackType type);
GST_MSE_PRIVATE
GstMediaSourceTrackType gst_media_source_track_type_from_stream_type (
GstStreamType type);
G_END_DECLS

View file

@ -0,0 +1,446 @@
/* GStreamer
*
* SPDX-License-Identifier: LGPL-2.1
*
* Copyright (C) 2022, 2023 Collabora Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/mse/mse-enumtypes.h>
#include <gst/mse/mse-enumtypes-private.h>
#include "gstmediasourcetrack-private.h"
#include "gstmselogging-private.h"
#include <gst/base/gstdataqueue.h>
struct _GstMediaSourceTrack
{
GstObject parent_instance;
GstMediaSourceTrackType track_type;
gchar *track_id;
gboolean active;
GstCaps *initial_caps;
gsize queue_size;
GstDataQueue *samples;
};
G_DEFINE_TYPE (GstMediaSourceTrack, gst_media_source_track, GST_TYPE_OBJECT);
#define DEFAULT_QUEUE_SIZE (1 << 10)
enum
{
PROP_0,
PROP_TRACK_TYPE,
PROP_TRACK_ID,
PROP_ACTIVE,
PROP_INITIAL_CAPS,
PROP_QUEUE_SIZE,
N_PROPS,
};
enum
{
ON_NOT_EMPTY,
N_SIGNALS,
};
static GParamSpec *properties[N_PROPS];
static guint signals[N_SIGNALS];
static GstMediaSourceTrack *
_gst_media_source_track_new_full (GstMediaSourceTrackType type,
const gchar * track_id, gsize size, GstCaps * initial_caps)
{
g_return_val_if_fail (type >= 0, NULL);
g_return_val_if_fail (type <= GST_MEDIA_SOURCE_TRACK_TYPE_OTHER, NULL);
gst_mse_init_logging ();
GstMediaSourceTrack *self = g_object_new (GST_TYPE_MEDIA_SOURCE_TRACK,
"track-type", type, "track-id", track_id, "queue-size", size,
"initial-caps", initial_caps, NULL);
return gst_object_ref_sink (self);
}
GstMediaSourceTrack *
gst_media_source_track_new_with_size (GstMediaSourceTrackType type,
const gchar * track_id, gsize size)
{
return _gst_media_source_track_new_full (type, track_id, size, NULL);
}
GstMediaSourceTrack *
gst_media_source_track_new (GstMediaSourceTrackType type,
const gchar * track_id)
{
return _gst_media_source_track_new_full (type, track_id, DEFAULT_QUEUE_SIZE,
NULL);
}
GstMediaSourceTrack *
gst_media_source_track_new_with_initial_caps (GstMediaSourceTrackType type,
const gchar * track_id, GstCaps * initial_caps)
{
g_return_val_if_fail (GST_IS_CAPS (initial_caps), NULL);
return _gst_media_source_track_new_full (type, track_id, DEFAULT_QUEUE_SIZE,
initial_caps);
}
static void
gst_media_source_track_finalize (GObject * object)
{
GstMediaSourceTrack *self = (GstMediaSourceTrack *) object;
g_free (self->track_id);
gst_clear_caps (&self->initial_caps);
g_object_unref (self->samples);
G_OBJECT_CLASS (gst_media_source_track_parent_class)->finalize (object);
}
static void
gst_media_source_track_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
GstMediaSourceTrack *self = GST_MEDIA_SOURCE_TRACK (object);
switch (prop_id) {
case PROP_TRACK_TYPE:
g_value_set_enum (value, gst_media_source_track_get_track_type (self));
break;
case PROP_TRACK_ID:
g_value_set_static_string (value, gst_media_source_track_get_id (self));
break;
case PROP_ACTIVE:
g_value_set_boolean (value, gst_media_source_track_get_active (self));
break;
case PROP_INITIAL_CAPS:
g_value_take_boxed (value,
gst_media_source_track_get_initial_caps (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
gst_media_source_track_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstMediaSourceTrack *self = GST_MEDIA_SOURCE_TRACK (object);
switch (prop_id) {
case PROP_TRACK_TYPE:
self->track_type = g_value_get_enum (value);
break;
case PROP_TRACK_ID:
/* G_PARAM_CONSTRUCT_ONLY */
self->track_id = g_value_dup_string (value);
break;
case PROP_ACTIVE:
gst_media_source_track_set_active (self, g_value_get_boolean (value));
break;
case PROP_INITIAL_CAPS:{
const GstCaps *caps = gst_value_get_caps (value);
self->initial_caps = caps == NULL ? NULL : gst_caps_copy (caps);
break;
}
case PROP_QUEUE_SIZE:{
self->queue_size = g_value_get_ulong (value);
break;
}
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
gst_media_source_track_class_init (GstMediaSourceTrackClass * klass)
{
GObjectClass *oclass = G_OBJECT_CLASS (klass);
oclass->finalize = GST_DEBUG_FUNCPTR (gst_media_source_track_finalize);
oclass->get_property =
GST_DEBUG_FUNCPTR (gst_media_source_track_get_property);
oclass->set_property =
GST_DEBUG_FUNCPTR (gst_media_source_track_set_property);
signals[ON_NOT_EMPTY] = g_signal_new ("on-not-empty",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
properties[PROP_TRACK_TYPE] =
g_param_spec_enum ("track-type", "Track Type",
"Type of media in this Track, either Audio, Video, Text, or Other.",
GST_TYPE_MEDIA_SOURCE_TRACK_TYPE, GST_MEDIA_SOURCE_TRACK_TYPE_OTHER,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
properties[PROP_TRACK_ID] =
g_param_spec_string ("track-id", "Track ID",
"Identifier for this Track that must be unique within a Source Buffer.",
"", G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
properties[PROP_ACTIVE] =
g_param_spec_boolean ("active", "Active",
"Whether this Track requires its parent Source Buffer to be in its "
"parent Media Source's Active Source Buffers list", FALSE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
properties[PROP_INITIAL_CAPS] =
g_param_spec_boxed ("initial-caps", "Initial Caps",
"GstCaps discovered in the first Initialization Segment",
GST_TYPE_CAPS, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
properties[PROP_QUEUE_SIZE] =
g_param_spec_ulong ("queue-size", "Queue Size",
"Maximum Track Queue size",
0, G_MAXULONG, DEFAULT_QUEUE_SIZE,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (oclass, N_PROPS, properties);
}
static gboolean
check_queue_depth (GstDataQueue * queue, guint visible, guint bytes,
guint64 time, gpointer checkdata)
{
GstMediaSourceTrack *self = GST_MEDIA_SOURCE_TRACK (checkdata);
return visible >= self->queue_size;
}
static void
gst_media_source_track_init (GstMediaSourceTrack * self)
{
self->samples = gst_data_queue_new (check_queue_depth, NULL, NULL, self);
}
GstMediaSourceTrackType
gst_media_source_track_get_track_type (GstMediaSourceTrack * self)
{
g_return_val_if_fail (GST_IS_MEDIA_SOURCE_TRACK (self),
GST_MEDIA_SOURCE_TRACK_TYPE_OTHER);
return self->track_type;
}
GstStreamType
gst_media_source_track_get_stream_type (GstMediaSourceTrack * self)
{
g_return_val_if_fail (GST_IS_MEDIA_SOURCE_TRACK (self),
GST_STREAM_TYPE_UNKNOWN);
return gst_media_source_track_type_to_stream_type (self->track_type);
}
const gchar *
gst_media_source_track_get_id (GstMediaSourceTrack * self)
{
g_return_val_if_fail (GST_IS_MEDIA_SOURCE_TRACK (self), NULL);
return self->track_id;
}
GstCaps *
gst_media_source_track_get_initial_caps (GstMediaSourceTrack * self)
{
g_return_val_if_fail (GST_IS_MEDIA_SOURCE_TRACK (self), NULL);
if (GST_IS_CAPS (self->initial_caps)) {
return self->initial_caps;
} else {
return NULL;
}
}
gboolean
gst_media_source_track_get_active (GstMediaSourceTrack * self)
{
g_return_val_if_fail (GST_IS_MEDIA_SOURCE_TRACK (self), FALSE);
return self->active;
}
void
gst_media_source_track_set_active (GstMediaSourceTrack * self, gboolean active)
{
g_return_if_fail (GST_IS_MEDIA_SOURCE_TRACK (self));
self->active = active;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ACTIVE]);
}
GstMiniObject *
gst_media_source_track_pop (GstMediaSourceTrack * self)
{
g_return_val_if_fail (GST_IS_MEDIA_SOURCE_TRACK (self), NULL);
GstDataQueueItem *item = NULL;
if (!gst_data_queue_pop (self->samples, &item)) {
return NULL;
}
GstMiniObject *object = item->object;
item->object = NULL;
item->destroy (item);
return object;
}
static inline gsize
sample_size (GstSample * sample)
{
GstBuffer *buffer = gst_sample_get_buffer (sample);
return gst_buffer_get_size (buffer);
}
static inline GstClockTime
sample_duration (GstSample * sample)
{
GstBuffer *buffer = gst_sample_get_buffer (sample);
return GST_BUFFER_DURATION (buffer);
}
static void
destroy_item (GstDataQueueItem * item)
{
gst_clear_mini_object (&item->object);
g_free (item);
}
static inline GstDataQueueItem *
wrap_sample (GstSample * sample)
{
GstDataQueueItem item = {
.object = GST_MINI_OBJECT (sample),
.size = sample_size (sample),
.duration = sample_duration (sample),
.destroy = (GDestroyNotify) destroy_item,
.visible = TRUE,
};
return g_memdup2 (&item, sizeof (GstDataQueueItem));
}
gboolean
gst_media_source_track_push (GstMediaSourceTrack * self, GstSample * sample)
{
g_return_val_if_fail (GST_IS_MEDIA_SOURCE_TRACK (self), FALSE);
g_return_val_if_fail (GST_IS_SAMPLE (sample), FALSE);
gboolean was_empty = gst_media_source_track_is_empty (self);
GstDataQueueItem *item = wrap_sample (gst_sample_ref (sample));
gboolean result = gst_data_queue_push (self->samples, item);
if (result) {
if (was_empty) {
g_signal_emit (self, signals[ON_NOT_EMPTY], 0);
}
return TRUE;
} else {
item->destroy (item);
return FALSE;
}
}
static inline GstDataQueueItem *
wrap_eos (void)
{
GstEvent *event = gst_event_ref (gst_event_new_eos ());
GstDataQueueItem item = {
.object = GST_MINI_OBJECT (event),
.size = 0,
.duration = 0,
.destroy = (GDestroyNotify) destroy_item,
.visible = TRUE,
};
return g_memdup2 (&item, sizeof (GstDataQueueItem));
}
gboolean
gst_media_source_track_push_eos (GstMediaSourceTrack * self)
{
g_return_val_if_fail (GST_IS_MEDIA_SOURCE_TRACK (self), FALSE);
GstDataQueueItem *item = wrap_eos ();
gboolean result = gst_data_queue_push (self->samples, item);
if (result) {
return TRUE;
} else {
item->destroy (item);
return FALSE;
}
}
void
gst_media_source_track_flush (GstMediaSourceTrack * self)
{
g_return_if_fail (GST_IS_MEDIA_SOURCE_TRACK (self));
gst_data_queue_set_flushing (self->samples, TRUE);
gst_data_queue_flush (self->samples);
}
void
gst_media_source_track_resume (GstMediaSourceTrack * self)
{
g_return_if_fail (GST_IS_MEDIA_SOURCE_TRACK (self));
gst_data_queue_set_flushing (self->samples, FALSE);
}
gboolean
gst_media_source_track_is_empty (GstMediaSourceTrack * self)
{
g_return_val_if_fail (GST_IS_MEDIA_SOURCE_TRACK (self), FALSE);
return gst_data_queue_is_empty (self->samples);
}
GstStreamType
gst_media_source_track_type_to_stream_type (GstMediaSourceTrackType type)
{
switch (type) {
case GST_MEDIA_SOURCE_TRACK_TYPE_AUDIO:
return GST_STREAM_TYPE_AUDIO;
case GST_MEDIA_SOURCE_TRACK_TYPE_TEXT:
return GST_STREAM_TYPE_TEXT;
case GST_MEDIA_SOURCE_TRACK_TYPE_VIDEO:
return GST_STREAM_TYPE_VIDEO;
default:
return GST_STREAM_TYPE_UNKNOWN;
}
}
GstMediaSourceTrackType
gst_media_source_track_type_from_stream_type (GstStreamType type)
{
switch (type) {
case GST_STREAM_TYPE_AUDIO:
return GST_MEDIA_SOURCE_TRACK_TYPE_AUDIO;
case GST_STREAM_TYPE_TEXT:
return GST_MEDIA_SOURCE_TRACK_TYPE_TEXT;
case GST_STREAM_TYPE_VIDEO:
return GST_MEDIA_SOURCE_TRACK_TYPE_VIDEO;
default:
return GST_MEDIA_SOURCE_TRACK_TYPE_OTHER;
}
}

Some files were not shown because too many files have changed in this diff Show more