mirror of
https://github.com/nestriness/warp.git
synced 2025-12-13 02:15:42 +02:00
Add fmp4
This commit is contained in:
7
.gitignore
vendored
7
.gitignore
vendored
@@ -7,3 +7,10 @@
|
|||||||
# already existing elements were commented out
|
# already existing elements were commented out
|
||||||
|
|
||||||
#/target
|
#/target
|
||||||
|
|
||||||
|
|
||||||
|
# Added by cargo
|
||||||
|
#
|
||||||
|
# already existing elements were commented out
|
||||||
|
|
||||||
|
#/target
|
||||||
|
|||||||
982
Cargo.lock
generated
982
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
20
Cargo.toml
20
Cargo.toml
@@ -1,21 +1,15 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "warp"
|
name = "me"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
url = "2"
|
anyhow = "1"
|
||||||
gst = { package = "gstreamer", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs", features = ["v1_18"] }
|
|
||||||
gst-base = { package = "gstreamer-base", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs", features = ["v1_18"] }
|
|
||||||
gst-video = { package = "gstreamer-video", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs", features = ["v1_18"] }
|
|
||||||
wayland-display-core = { path = "../wayland-display-core" }
|
|
||||||
moq-transport = { path = "../moq-transport" }
|
|
||||||
tracing = "0.1.37"
|
|
||||||
once_cell = "1.17.0"
|
|
||||||
tracing-subscriber = "0.3.16"
|
|
||||||
|
|
||||||
[[bin]]
|
gst = { package = "gstreamer", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }
|
||||||
name = "warp"
|
gst-base = { package = "gstreamer-base", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }
|
||||||
path = "main.rs"
|
gst-video = { package = "gstreamer-video", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }
|
||||||
|
gst-gl = { package = "gstreamer-gl", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }
|
||||||
|
gst-plugin-fmp4 = { git = "https://github.com/sdroege/gst-plugin-rs", version = "0.12.0-alpha.1" }
|
||||||
|
|||||||
661
LICENSE
661
LICENSE
@@ -1,661 +0,0 @@
|
|||||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
|
||||||
Version 3, 19 November 2007
|
|
||||||
|
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
Preamble
|
|
||||||
|
|
||||||
The GNU Affero General Public License is a free, copyleft license for
|
|
||||||
software and other kinds of works, specifically designed to ensure
|
|
||||||
cooperation with the community in the case of network server software.
|
|
||||||
|
|
||||||
The licenses for most software and other practical works are designed
|
|
||||||
to take away your freedom to share and change the works. By contrast,
|
|
||||||
our General Public Licenses are intended to guarantee your freedom to
|
|
||||||
share and change all versions of a program--to make sure it remains free
|
|
||||||
software for all its users.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, 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
|
|
||||||
them if you wish), that you receive source code or can get it if you
|
|
||||||
want it, that you can change the software or use pieces of it in new
|
|
||||||
free programs, and that you know you can do these things.
|
|
||||||
|
|
||||||
Developers that use our General Public Licenses protect your rights
|
|
||||||
with two steps: (1) assert copyright on the software, and (2) offer
|
|
||||||
you this License which gives you legal permission to copy, distribute
|
|
||||||
and/or modify the software.
|
|
||||||
|
|
||||||
A secondary benefit of defending all users' freedom is that
|
|
||||||
improvements made in alternate versions of the program, if they
|
|
||||||
receive widespread use, become available for other developers to
|
|
||||||
incorporate. Many developers of free software are heartened and
|
|
||||||
encouraged by the resulting cooperation. However, in the case of
|
|
||||||
software used on network servers, this result may fail to come about.
|
|
||||||
The GNU General Public License permits making a modified version and
|
|
||||||
letting the public access it on a server without ever releasing its
|
|
||||||
source code to the public.
|
|
||||||
|
|
||||||
The GNU Affero General Public License is designed specifically to
|
|
||||||
ensure that, in such cases, the modified source code becomes available
|
|
||||||
to the community. It requires the operator of a network server to
|
|
||||||
provide the source code of the modified version running there to the
|
|
||||||
users of that server. Therefore, public use of a modified version, on
|
|
||||||
a publicly accessible server, gives the public access to the source
|
|
||||||
code of the modified version.
|
|
||||||
|
|
||||||
An older license, called the Affero General Public License and
|
|
||||||
published by Affero, was designed to accomplish similar goals. This is
|
|
||||||
a different license, not a version of the Affero GPL, but Affero has
|
|
||||||
released a new version of the Affero GPL which permits relicensing under
|
|
||||||
this license.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
|
||||||
modification follow.
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
0. Definitions.
|
|
||||||
|
|
||||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
|
||||||
|
|
||||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
|
||||||
works, such as semiconductor masks.
|
|
||||||
|
|
||||||
"The Program" refers to any copyrightable work licensed under this
|
|
||||||
License. Each licensee is addressed as "you". "Licensees" and
|
|
||||||
"recipients" may be individuals or organizations.
|
|
||||||
|
|
||||||
To "modify" a work means to copy from or adapt all or part of the work
|
|
||||||
in a fashion requiring copyright permission, other than the making of an
|
|
||||||
exact copy. The resulting work is called a "modified version" of the
|
|
||||||
earlier work or a work "based on" the earlier work.
|
|
||||||
|
|
||||||
A "covered work" means either the unmodified Program or a work based
|
|
||||||
on the Program.
|
|
||||||
|
|
||||||
To "propagate" a work means to do anything with it that, without
|
|
||||||
permission, would make you directly or secondarily liable for
|
|
||||||
infringement under applicable copyright law, except executing it on a
|
|
||||||
computer or modifying a private copy. Propagation includes copying,
|
|
||||||
distribution (with or without modification), making available to the
|
|
||||||
public, and in some countries other activities as well.
|
|
||||||
|
|
||||||
To "convey" a work means any kind of propagation that enables other
|
|
||||||
parties to make or receive copies. Mere interaction with a user through
|
|
||||||
a computer network, with no transfer of a copy, is not conveying.
|
|
||||||
|
|
||||||
An interactive user interface displays "Appropriate Legal Notices"
|
|
||||||
to the extent that it includes a convenient and prominently visible
|
|
||||||
feature that (1) displays an appropriate copyright notice, and (2)
|
|
||||||
tells the user that there is no warranty for the work (except to the
|
|
||||||
extent that warranties are provided), that licensees may convey the
|
|
||||||
work under this License, and how to view a copy of this License. If
|
|
||||||
the interface presents a list of user commands or options, such as a
|
|
||||||
menu, a prominent item in the list meets this criterion.
|
|
||||||
|
|
||||||
1. Source Code.
|
|
||||||
|
|
||||||
The "source code" for a work means the preferred form of the work
|
|
||||||
for making modifications to it. "Object code" means any non-source
|
|
||||||
form of a work.
|
|
||||||
|
|
||||||
A "Standard Interface" means an interface that either is an official
|
|
||||||
standard defined by a recognized standards body, or, in the case of
|
|
||||||
interfaces specified for a particular programming language, one that
|
|
||||||
is widely used among developers working in that language.
|
|
||||||
|
|
||||||
The "System Libraries" of an executable work include anything, other
|
|
||||||
than the work as a whole, that (a) is included in the normal form of
|
|
||||||
packaging a Major Component, but which is not part of that Major
|
|
||||||
Component, and (b) serves only to enable use of the work with that
|
|
||||||
Major Component, or to implement a Standard Interface for which an
|
|
||||||
implementation is available to the public in source code form. A
|
|
||||||
"Major Component", in this context, means a major essential component
|
|
||||||
(kernel, window system, and so on) of the specific operating system
|
|
||||||
(if any) on which the executable work runs, or a compiler used to
|
|
||||||
produce the work, or an object code interpreter used to run it.
|
|
||||||
|
|
||||||
The "Corresponding Source" for a work in object code form means all
|
|
||||||
the source code needed to generate, install, and (for an executable
|
|
||||||
work) run the object code and to modify the work, including scripts to
|
|
||||||
control those activities. However, it does not include the work's
|
|
||||||
System Libraries, or general-purpose tools or generally available free
|
|
||||||
programs which are used unmodified in performing those activities but
|
|
||||||
which are not part of the work. For example, Corresponding Source
|
|
||||||
includes interface definition files associated with source files for
|
|
||||||
the work, and the source code for shared libraries and dynamically
|
|
||||||
linked subprograms that the work is specifically designed to require,
|
|
||||||
such as by intimate data communication or control flow between those
|
|
||||||
subprograms and other parts of the work.
|
|
||||||
|
|
||||||
The Corresponding Source need not include anything that users
|
|
||||||
can regenerate automatically from other parts of the Corresponding
|
|
||||||
Source.
|
|
||||||
|
|
||||||
The Corresponding Source for a work in source code form is that
|
|
||||||
same work.
|
|
||||||
|
|
||||||
2. Basic Permissions.
|
|
||||||
|
|
||||||
All rights granted under this License are granted for the term of
|
|
||||||
copyright on the Program, and are irrevocable provided the stated
|
|
||||||
conditions are met. This License explicitly affirms your unlimited
|
|
||||||
permission to run the unmodified Program. The output from running a
|
|
||||||
covered work is covered by this License only if the output, given its
|
|
||||||
content, constitutes a covered work. This License acknowledges your
|
|
||||||
rights of fair use or other equivalent, as provided by copyright law.
|
|
||||||
|
|
||||||
You may make, run and propagate covered works that you do not
|
|
||||||
convey, without conditions so long as your license otherwise remains
|
|
||||||
in force. You may convey covered works to others for the sole purpose
|
|
||||||
of having them make modifications exclusively for you, or provide you
|
|
||||||
with facilities for running those works, provided that you comply with
|
|
||||||
the terms of this License in conveying all material for which you do
|
|
||||||
not control copyright. Those thus making or running the covered works
|
|
||||||
for you must do so exclusively on your behalf, under your direction
|
|
||||||
and control, on terms that prohibit them from making any copies of
|
|
||||||
your copyrighted material outside their relationship with you.
|
|
||||||
|
|
||||||
Conveying under any other circumstances is permitted solely under
|
|
||||||
the conditions stated below. Sublicensing is not allowed; section 10
|
|
||||||
makes it unnecessary.
|
|
||||||
|
|
||||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
|
||||||
|
|
||||||
No covered work shall be deemed part of an effective technological
|
|
||||||
measure under any applicable law fulfilling obligations under article
|
|
||||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
|
||||||
similar laws prohibiting or restricting circumvention of such
|
|
||||||
measures.
|
|
||||||
|
|
||||||
When you convey a covered work, you waive any legal power to forbid
|
|
||||||
circumvention of technological measures to the extent such circumvention
|
|
||||||
is effected by exercising rights under this License with respect to
|
|
||||||
the covered work, and you disclaim any intention to limit operation or
|
|
||||||
modification of the work as a means of enforcing, against the work's
|
|
||||||
users, your or third parties' legal rights to forbid circumvention of
|
|
||||||
technological measures.
|
|
||||||
|
|
||||||
4. Conveying Verbatim Copies.
|
|
||||||
|
|
||||||
You may convey verbatim copies of the Program's source code as you
|
|
||||||
receive it, in any medium, provided that you conspicuously and
|
|
||||||
appropriately publish on each copy an appropriate copyright notice;
|
|
||||||
keep intact all notices stating that this License and any
|
|
||||||
non-permissive terms added in accord with section 7 apply to the code;
|
|
||||||
keep intact all notices of the absence of any warranty; and give all
|
|
||||||
recipients a copy of this License along with the Program.
|
|
||||||
|
|
||||||
You may charge any price or no price for each copy that you convey,
|
|
||||||
and you may offer support or warranty protection for a fee.
|
|
||||||
|
|
||||||
5. Conveying Modified Source Versions.
|
|
||||||
|
|
||||||
You may convey a work based on the Program, or the modifications to
|
|
||||||
produce it from the Program, in the form of source code under the
|
|
||||||
terms of section 4, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) The work must carry prominent notices stating that you modified
|
|
||||||
it, and giving a relevant date.
|
|
||||||
|
|
||||||
b) The work must carry prominent notices stating that it is
|
|
||||||
released under this License and any conditions added under section
|
|
||||||
7. This requirement modifies the requirement in section 4 to
|
|
||||||
"keep intact all notices".
|
|
||||||
|
|
||||||
c) You must license the entire work, as a whole, under this
|
|
||||||
License to anyone who comes into possession of a copy. This
|
|
||||||
License will therefore apply, along with any applicable section 7
|
|
||||||
additional terms, to the whole of the work, and all its parts,
|
|
||||||
regardless of how they are packaged. This License gives no
|
|
||||||
permission to license the work in any other way, but it does not
|
|
||||||
invalidate such permission if you have separately received it.
|
|
||||||
|
|
||||||
d) If the work has interactive user interfaces, each must display
|
|
||||||
Appropriate Legal Notices; however, if the Program has interactive
|
|
||||||
interfaces that do not display Appropriate Legal Notices, your
|
|
||||||
work need not make them do so.
|
|
||||||
|
|
||||||
A compilation of a covered work with other separate and independent
|
|
||||||
works, which are not by their nature extensions of the covered work,
|
|
||||||
and which are not combined with it such as to form a larger program,
|
|
||||||
in or on a volume of a storage or distribution medium, is called an
|
|
||||||
"aggregate" if the compilation and its resulting copyright are not
|
|
||||||
used to limit the access or legal rights of the compilation's users
|
|
||||||
beyond what the individual works permit. Inclusion of a covered work
|
|
||||||
in an aggregate does not cause this License to apply to the other
|
|
||||||
parts of the aggregate.
|
|
||||||
|
|
||||||
6. Conveying Non-Source Forms.
|
|
||||||
|
|
||||||
You may convey a covered work in object code form under the terms
|
|
||||||
of sections 4 and 5, provided that you also convey the
|
|
||||||
machine-readable Corresponding Source under the terms of this License,
|
|
||||||
in one of these ways:
|
|
||||||
|
|
||||||
a) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by the
|
|
||||||
Corresponding Source fixed on a durable physical medium
|
|
||||||
customarily used for software interchange.
|
|
||||||
|
|
||||||
b) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by a
|
|
||||||
written offer, valid for at least three years and valid for as
|
|
||||||
long as you offer spare parts or customer support for that product
|
|
||||||
model, to give anyone who possesses the object code either (1) a
|
|
||||||
copy of the Corresponding Source for all the software in the
|
|
||||||
product that is covered by this License, on a durable physical
|
|
||||||
medium customarily used for software interchange, for a price no
|
|
||||||
more than your reasonable cost of physically performing this
|
|
||||||
conveying of source, or (2) access to copy the
|
|
||||||
Corresponding Source from a network server at no charge.
|
|
||||||
|
|
||||||
c) Convey individual copies of the object code with a copy of the
|
|
||||||
written offer to provide the Corresponding Source. This
|
|
||||||
alternative is allowed only occasionally and noncommercially, and
|
|
||||||
only if you received the object code with such an offer, in accord
|
|
||||||
with subsection 6b.
|
|
||||||
|
|
||||||
d) Convey the object code by offering access from a designated
|
|
||||||
place (gratis or for a charge), and offer equivalent access to the
|
|
||||||
Corresponding Source in the same way through the same place at no
|
|
||||||
further charge. You need not require recipients to copy the
|
|
||||||
Corresponding Source along with the object code. If the place to
|
|
||||||
copy the object code is a network server, the Corresponding Source
|
|
||||||
may be on a different server (operated by you or a third party)
|
|
||||||
that supports equivalent copying facilities, provided you maintain
|
|
||||||
clear directions next to the object code saying where to find the
|
|
||||||
Corresponding Source. Regardless of what server hosts the
|
|
||||||
Corresponding Source, you remain obligated to ensure that it is
|
|
||||||
available for as long as needed to satisfy these requirements.
|
|
||||||
|
|
||||||
e) Convey the object code using peer-to-peer transmission, provided
|
|
||||||
you inform other peers where the object code and Corresponding
|
|
||||||
Source of the work are being offered to the general public at no
|
|
||||||
charge under subsection 6d.
|
|
||||||
|
|
||||||
A separable portion of the object code, whose source code is excluded
|
|
||||||
from the Corresponding Source as a System Library, need not be
|
|
||||||
included in conveying the object code work.
|
|
||||||
|
|
||||||
A "User Product" is either (1) a "consumer product", which means any
|
|
||||||
tangible personal property which is normally used for personal, family,
|
|
||||||
or household purposes, or (2) anything designed or sold for incorporation
|
|
||||||
into a dwelling. In determining whether a product is a consumer product,
|
|
||||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
|
||||||
product received by a particular user, "normally used" refers to a
|
|
||||||
typical or common use of that class of product, regardless of the status
|
|
||||||
of the particular user or of the way in which the particular user
|
|
||||||
actually uses, or expects or is expected to use, the product. A product
|
|
||||||
is a consumer product regardless of whether the product has substantial
|
|
||||||
commercial, industrial or non-consumer uses, unless such uses represent
|
|
||||||
the only significant mode of use of the product.
|
|
||||||
|
|
||||||
"Installation Information" for a User Product means any methods,
|
|
||||||
procedures, authorization keys, or other information required to install
|
|
||||||
and execute modified versions of a covered work in that User Product from
|
|
||||||
a modified version of its Corresponding Source. The information must
|
|
||||||
suffice to ensure that the continued functioning of the modified object
|
|
||||||
code is in no case prevented or interfered with solely because
|
|
||||||
modification has been made.
|
|
||||||
|
|
||||||
If you convey an object code work under this section in, or with, or
|
|
||||||
specifically for use in, a User Product, and the conveying occurs as
|
|
||||||
part of a transaction in which the right of possession and use of the
|
|
||||||
User Product is transferred to the recipient in perpetuity or for a
|
|
||||||
fixed term (regardless of how the transaction is characterized), the
|
|
||||||
Corresponding Source conveyed under this section must be accompanied
|
|
||||||
by the Installation Information. But this requirement does not apply
|
|
||||||
if neither you nor any third party retains the ability to install
|
|
||||||
modified object code on the User Product (for example, the work has
|
|
||||||
been installed in ROM).
|
|
||||||
|
|
||||||
The requirement to provide Installation Information does not include a
|
|
||||||
requirement to continue to provide support service, warranty, or updates
|
|
||||||
for a work that has been modified or installed by the recipient, or for
|
|
||||||
the User Product in which it has been modified or installed. Access to a
|
|
||||||
network may be denied when the modification itself materially and
|
|
||||||
adversely affects the operation of the network or violates the rules and
|
|
||||||
protocols for communication across the network.
|
|
||||||
|
|
||||||
Corresponding Source conveyed, and Installation Information provided,
|
|
||||||
in accord with this section must be in a format that is publicly
|
|
||||||
documented (and with an implementation available to the public in
|
|
||||||
source code form), and must require no special password or key for
|
|
||||||
unpacking, reading or copying.
|
|
||||||
|
|
||||||
7. Additional Terms.
|
|
||||||
|
|
||||||
"Additional permissions" are terms that supplement the terms of this
|
|
||||||
License by making exceptions from one or more of its conditions.
|
|
||||||
Additional permissions that are applicable to the entire Program shall
|
|
||||||
be treated as though they were included in this License, to the extent
|
|
||||||
that they are valid under applicable law. If additional permissions
|
|
||||||
apply only to part of the Program, that part may be used separately
|
|
||||||
under those permissions, but the entire Program remains governed by
|
|
||||||
this License without regard to the additional permissions.
|
|
||||||
|
|
||||||
When you convey a copy of a covered work, you may at your option
|
|
||||||
remove any additional permissions from that copy, or from any part of
|
|
||||||
it. (Additional permissions may be written to require their own
|
|
||||||
removal in certain cases when you modify the work.) You may place
|
|
||||||
additional permissions on material, added by you to a covered work,
|
|
||||||
for which you have or can give appropriate copyright permission.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, for material you
|
|
||||||
add to a covered work, you may (if authorized by the copyright holders of
|
|
||||||
that material) supplement the terms of this License with terms:
|
|
||||||
|
|
||||||
a) Disclaiming warranty or limiting liability differently from the
|
|
||||||
terms of sections 15 and 16 of this License; or
|
|
||||||
|
|
||||||
b) Requiring preservation of specified reasonable legal notices or
|
|
||||||
author attributions in that material or in the Appropriate Legal
|
|
||||||
Notices displayed by works containing it; or
|
|
||||||
|
|
||||||
c) Prohibiting misrepresentation of the origin of that material, or
|
|
||||||
requiring that modified versions of such material be marked in
|
|
||||||
reasonable ways as different from the original version; or
|
|
||||||
|
|
||||||
d) Limiting the use for publicity purposes of names of licensors or
|
|
||||||
authors of the material; or
|
|
||||||
|
|
||||||
e) Declining to grant rights under trademark law for use of some
|
|
||||||
trade names, trademarks, or service marks; or
|
|
||||||
|
|
||||||
f) Requiring indemnification of licensors and authors of that
|
|
||||||
material by anyone who conveys the material (or modified versions of
|
|
||||||
it) with contractual assumptions of liability to the recipient, for
|
|
||||||
any liability that these contractual assumptions directly impose on
|
|
||||||
those licensors and authors.
|
|
||||||
|
|
||||||
All other non-permissive additional terms are considered "further
|
|
||||||
restrictions" within the meaning of section 10. If the Program as you
|
|
||||||
received it, or any part of it, contains a notice stating that it is
|
|
||||||
governed by this License along with a term that is a further
|
|
||||||
restriction, you may remove that term. If a license document contains
|
|
||||||
a further restriction but permits relicensing or conveying under this
|
|
||||||
License, you may add to a covered work material governed by the terms
|
|
||||||
of that license document, provided that the further restriction does
|
|
||||||
not survive such relicensing or conveying.
|
|
||||||
|
|
||||||
If you add terms to a covered work in accord with this section, you
|
|
||||||
must place, in the relevant source files, a statement of the
|
|
||||||
additional terms that apply to those files, or a notice indicating
|
|
||||||
where to find the applicable terms.
|
|
||||||
|
|
||||||
Additional terms, permissive or non-permissive, may be stated in the
|
|
||||||
form of a separately written license, or stated as exceptions;
|
|
||||||
the above requirements apply either way.
|
|
||||||
|
|
||||||
8. Termination.
|
|
||||||
|
|
||||||
You may not propagate or modify a covered work except as expressly
|
|
||||||
provided under this License. Any attempt otherwise to propagate or
|
|
||||||
modify it is void, and will automatically terminate your rights under
|
|
||||||
this License (including any patent licenses granted under the third
|
|
||||||
paragraph of section 11).
|
|
||||||
|
|
||||||
However, if you cease all violation of this License, then your
|
|
||||||
license from a particular copyright holder is reinstated (a)
|
|
||||||
provisionally, unless and until the copyright holder explicitly and
|
|
||||||
finally terminates your license, and (b) permanently, if the copyright
|
|
||||||
holder fails to notify you of the violation by some reasonable means
|
|
||||||
prior to 60 days after the cessation.
|
|
||||||
|
|
||||||
Moreover, your license from a particular copyright holder is
|
|
||||||
reinstated permanently if the copyright holder notifies you of the
|
|
||||||
violation by some reasonable means, this is the first time you have
|
|
||||||
received notice of violation of this License (for any work) from that
|
|
||||||
copyright holder, and you cure the violation prior to 30 days after
|
|
||||||
your receipt of the notice.
|
|
||||||
|
|
||||||
Termination of your rights under this section does not terminate the
|
|
||||||
licenses of parties who have received copies or rights from you under
|
|
||||||
this License. If your rights have been terminated and not permanently
|
|
||||||
reinstated, you do not qualify to receive new licenses for the same
|
|
||||||
material under section 10.
|
|
||||||
|
|
||||||
9. Acceptance Not Required for Having Copies.
|
|
||||||
|
|
||||||
You are not required to accept this License in order to receive or
|
|
||||||
run a copy of the Program. Ancillary propagation of a covered work
|
|
||||||
occurring solely as a consequence of using peer-to-peer transmission
|
|
||||||
to receive a copy likewise does not require acceptance. However,
|
|
||||||
nothing other than this License grants you permission to propagate or
|
|
||||||
modify any covered work. These actions infringe copyright if you do
|
|
||||||
not accept this License. Therefore, by modifying or propagating a
|
|
||||||
covered work, you indicate your acceptance of this License to do so.
|
|
||||||
|
|
||||||
10. Automatic Licensing of Downstream Recipients.
|
|
||||||
|
|
||||||
Each time you convey a covered work, the recipient automatically
|
|
||||||
receives a license from the original licensors, to run, modify and
|
|
||||||
propagate that work, subject to this License. You are not responsible
|
|
||||||
for enforcing compliance by third parties with this License.
|
|
||||||
|
|
||||||
An "entity transaction" is a transaction transferring control of an
|
|
||||||
organization, or substantially all assets of one, or subdividing an
|
|
||||||
organization, or merging organizations. If propagation of a covered
|
|
||||||
work results from an entity transaction, each party to that
|
|
||||||
transaction who receives a copy of the work also receives whatever
|
|
||||||
licenses to the work the party's predecessor in interest had or could
|
|
||||||
give under the previous paragraph, plus a right to possession of the
|
|
||||||
Corresponding Source of the work from the predecessor in interest, if
|
|
||||||
the predecessor has it or can get it with reasonable efforts.
|
|
||||||
|
|
||||||
You may not impose any further restrictions on the exercise of the
|
|
||||||
rights granted or affirmed under this License. For example, you may
|
|
||||||
not impose a license fee, royalty, or other charge for exercise of
|
|
||||||
rights granted under this License, and you may not initiate litigation
|
|
||||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
|
||||||
any patent claim is infringed by making, using, selling, offering for
|
|
||||||
sale, or importing the Program or any portion of it.
|
|
||||||
|
|
||||||
11. Patents.
|
|
||||||
|
|
||||||
A "contributor" is a copyright holder who authorizes use under this
|
|
||||||
License of the Program or a work on which the Program is based. The
|
|
||||||
work thus licensed is called the contributor's "contributor version".
|
|
||||||
|
|
||||||
A contributor's "essential patent claims" are all patent claims
|
|
||||||
owned or controlled by the contributor, whether already acquired or
|
|
||||||
hereafter acquired, that would be infringed by some manner, permitted
|
|
||||||
by this License, of making, using, or selling its contributor version,
|
|
||||||
but do not include claims that would be infringed only as a
|
|
||||||
consequence of further modification of the contributor version. For
|
|
||||||
purposes of this definition, "control" includes the right to grant
|
|
||||||
patent sublicenses in a manner consistent with the requirements of
|
|
||||||
this License.
|
|
||||||
|
|
||||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
|
||||||
patent license under the contributor's essential patent claims, to
|
|
||||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
|
||||||
propagate the contents of its contributor version.
|
|
||||||
|
|
||||||
In the following three paragraphs, a "patent license" is any express
|
|
||||||
agreement or commitment, however denominated, not to enforce a patent
|
|
||||||
(such as an express permission to practice a patent or covenant not to
|
|
||||||
sue for patent infringement). To "grant" such a patent license to a
|
|
||||||
party means to make such an agreement or commitment not to enforce a
|
|
||||||
patent against the party.
|
|
||||||
|
|
||||||
If you convey a covered work, knowingly relying on a patent license,
|
|
||||||
and the Corresponding Source of the work is not available for anyone
|
|
||||||
to copy, free of charge and under the terms of this License, through a
|
|
||||||
publicly available network server or other readily accessible means,
|
|
||||||
then you must either (1) cause the Corresponding Source to be so
|
|
||||||
available, or (2) arrange to deprive yourself of the benefit of the
|
|
||||||
patent license for this particular work, or (3) arrange, in a manner
|
|
||||||
consistent with the requirements of this License, to extend the patent
|
|
||||||
license to downstream recipients. "Knowingly relying" means you have
|
|
||||||
actual knowledge that, but for the patent license, your conveying the
|
|
||||||
covered work in a country, or your recipient's use of the covered work
|
|
||||||
in a country, would infringe one or more identifiable patents in that
|
|
||||||
country that you have reason to believe are valid.
|
|
||||||
|
|
||||||
If, pursuant to or in connection with a single transaction or
|
|
||||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
|
||||||
covered work, and grant a patent license to some of the parties
|
|
||||||
receiving the covered work authorizing them to use, propagate, modify
|
|
||||||
or convey a specific copy of the covered work, then the patent license
|
|
||||||
you grant is automatically extended to all recipients of the covered
|
|
||||||
work and works based on it.
|
|
||||||
|
|
||||||
A patent license is "discriminatory" if it does not include within
|
|
||||||
the scope of its coverage, prohibits the exercise of, or is
|
|
||||||
conditioned on the non-exercise of one or more of the rights that are
|
|
||||||
specifically granted under this License. You may not convey a covered
|
|
||||||
work if you are a party to an arrangement with a third party that is
|
|
||||||
in the business of distributing software, under which you make payment
|
|
||||||
to the third party based on the extent of your activity of conveying
|
|
||||||
the work, and under which the third party grants, to any of the
|
|
||||||
parties who would receive the covered work from you, a discriminatory
|
|
||||||
patent license (a) in connection with copies of the covered work
|
|
||||||
conveyed by you (or copies made from those copies), or (b) primarily
|
|
||||||
for and in connection with specific products or compilations that
|
|
||||||
contain the covered work, unless you entered into that arrangement,
|
|
||||||
or that patent license was granted, prior to 28 March 2007.
|
|
||||||
|
|
||||||
Nothing in this License shall be construed as excluding or limiting
|
|
||||||
any implied license or other defenses to infringement that may
|
|
||||||
otherwise be available to you under applicable patent law.
|
|
||||||
|
|
||||||
12. No Surrender of Others' Freedom.
|
|
||||||
|
|
||||||
If 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 convey a
|
|
||||||
covered work so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you may
|
|
||||||
not convey it at all. For example, if you agree to terms that obligate you
|
|
||||||
to collect a royalty for further conveying from those to whom you convey
|
|
||||||
the Program, the only way you could satisfy both those terms and this
|
|
||||||
License would be to refrain entirely from conveying the Program.
|
|
||||||
|
|
||||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, if you modify the
|
|
||||||
Program, your modified version must prominently offer all users
|
|
||||||
interacting with it remotely through a computer network (if your version
|
|
||||||
supports such interaction) an opportunity to receive the Corresponding
|
|
||||||
Source of your version by providing access to the Corresponding Source
|
|
||||||
from a network server at no charge, through some standard or customary
|
|
||||||
means of facilitating copying of software. This Corresponding Source
|
|
||||||
shall include the Corresponding Source for any work covered by version 3
|
|
||||||
of the GNU General Public License that is incorporated pursuant to the
|
|
||||||
following paragraph.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, you have
|
|
||||||
permission to link or combine any covered work with a work licensed
|
|
||||||
under version 3 of the GNU General Public License into a single
|
|
||||||
combined work, and to convey the resulting work. The terms of this
|
|
||||||
License will continue to apply to the part which is the covered work,
|
|
||||||
but the work with which it is combined will remain governed by version
|
|
||||||
3 of the GNU General Public License.
|
|
||||||
|
|
||||||
14. Revised Versions of this License.
|
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions of
|
|
||||||
the GNU Affero 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
|
|
||||||
Program specifies that a certain numbered version of the GNU Affero General
|
|
||||||
Public License "or any later version" applies to it, you have the
|
|
||||||
option of following the terms and conditions either of that numbered
|
|
||||||
version or of any later version published by the Free Software
|
|
||||||
Foundation. If the Program does not specify a version number of the
|
|
||||||
GNU Affero General Public License, you may choose any version ever published
|
|
||||||
by the Free Software Foundation.
|
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future
|
|
||||||
versions of the GNU Affero General Public License can be used, that proxy's
|
|
||||||
public statement of acceptance of a version permanently authorizes you
|
|
||||||
to choose that version for the Program.
|
|
||||||
|
|
||||||
Later license versions may give you additional or different
|
|
||||||
permissions. However, no additional obligations are imposed on any
|
|
||||||
author or copyright holder as a result of your choosing to follow a
|
|
||||||
later version.
|
|
||||||
|
|
||||||
15. Disclaimer of Warranty.
|
|
||||||
|
|
||||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
|
||||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
|
||||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "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 PROGRAM
|
|
||||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
|
||||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
16. Limitation of Liability.
|
|
||||||
|
|
||||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
|
||||||
THE PROGRAM 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 PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
|
||||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
|
||||||
SUCH DAMAGES.
|
|
||||||
|
|
||||||
17. Interpretation of Sections 15 and 16.
|
|
||||||
|
|
||||||
If the disclaimer of warranty and limitation of liability provided
|
|
||||||
above cannot be given local legal effect according to their terms,
|
|
||||||
reviewing courts shall apply local law that most closely approximates
|
|
||||||
an absolute waiver of all civil liability in connection with the
|
|
||||||
Program, unless a warranty or assumption of liability accompanies a
|
|
||||||
copy of the Program in return for a fee.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
|
||||||
possible use to the public, the best way to achieve this is to make it
|
|
||||||
free software which everyone can redistribute and change under these terms.
|
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
|
||||||
to attach them to the start of each source file to most effectively
|
|
||||||
state 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 program's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU Affero General Public License as published
|
|
||||||
by the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program 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 Affero General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
If your software can interact with users remotely through a computer
|
|
||||||
network, you should also make sure that it provides a way for users to
|
|
||||||
get its source. For example, if your program is a web application, its
|
|
||||||
interface could display a "Source" link that leads users to an archive
|
|
||||||
of the code. There are many ways you could offer source, and different
|
|
||||||
solutions will be better for different programs; see section 13 for the
|
|
||||||
specific requirements.
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or school,
|
|
||||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
|
||||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
|
||||||
<https://www.gnu.org/licenses/>.
|
|
||||||
13
devbox.json
13
devbox.json
@@ -1,13 +0,0 @@
|
|||||||
{
|
|
||||||
"packages": ["rustup"],
|
|
||||||
"shell": {
|
|
||||||
"init_hook": [
|
|
||||||
"echo 'Welcome to devbox!' > /dev/null"
|
|
||||||
],
|
|
||||||
"scripts": {
|
|
||||||
"test": [
|
|
||||||
"echo \"Error: no test specified\" && exit 1"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"lockfile_version": "1",
|
|
||||||
"packages": {
|
|
||||||
"rustup": {
|
|
||||||
"resolved": "github:NixOS/nixpkgs/75a52265bda7fd25e06e3a67dee3f0354e73243c#rustup",
|
|
||||||
"source": "nixpkg"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
724
gstreamer/Cargo.lock
generated
724
gstreamer/Cargo.lock
generated
@@ -1,724 +0,0 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
|
||||||
# It is not intended for manual editing.
|
|
||||||
version = 3
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "atomic_refcell"
|
|
||||||
version = "0.1.13"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "41e67cd8309bbd06cd603a9e693a784ac2e5d1e955f11286e355089fcab3047c"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "autocfg"
|
|
||||||
version = "1.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bitflags"
|
|
||||||
version = "2.4.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cfg-expr"
|
|
||||||
version = "0.15.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "03915af431787e6ffdcc74c645077518c6b6e01f80b761e0fbbfa288536311b3"
|
|
||||||
dependencies = [
|
|
||||||
"smallvec",
|
|
||||||
"target-lexicon",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cfg-if"
|
|
||||||
version = "1.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "either"
|
|
||||||
version = "1.9.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "equivalent"
|
|
||||||
version = "1.0.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "form_urlencoded"
|
|
||||||
version = "1.2.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456"
|
|
||||||
dependencies = [
|
|
||||||
"percent-encoding",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "futures-channel"
|
|
||||||
version = "0.3.29"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb"
|
|
||||||
dependencies = [
|
|
||||||
"futures-core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "futures-core"
|
|
||||||
version = "0.3.29"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "futures-executor"
|
|
||||||
version = "0.3.29"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0f4fb8693db0cf099eadcca0efe2a5a22e4550f98ed16aba6c48700da29597bc"
|
|
||||||
dependencies = [
|
|
||||||
"futures-core",
|
|
||||||
"futures-task",
|
|
||||||
"futures-util",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "futures-macro"
|
|
||||||
version = "0.3.29"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 2.0.39",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "futures-task"
|
|
||||||
version = "0.3.29"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "futures-util"
|
|
||||||
version = "0.3.29"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104"
|
|
||||||
dependencies = [
|
|
||||||
"futures-core",
|
|
||||||
"futures-macro",
|
|
||||||
"futures-task",
|
|
||||||
"pin-project-lite",
|
|
||||||
"pin-utils",
|
|
||||||
"slab",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "gio-sys"
|
|
||||||
version = "0.19.0"
|
|
||||||
source = "git+https://github.com/gtk-rs/gtk-rs-core#a07ec7484ab68bbac04d3f2d2d393a1beda6a48e"
|
|
||||||
dependencies = [
|
|
||||||
"glib-sys",
|
|
||||||
"gobject-sys",
|
|
||||||
"libc",
|
|
||||||
"system-deps",
|
|
||||||
"windows-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "glib"
|
|
||||||
version = "0.19.0"
|
|
||||||
source = "git+https://github.com/gtk-rs/gtk-rs-core#a07ec7484ab68bbac04d3f2d2d393a1beda6a48e"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags",
|
|
||||||
"futures-channel",
|
|
||||||
"futures-core",
|
|
||||||
"futures-executor",
|
|
||||||
"futures-task",
|
|
||||||
"futures-util",
|
|
||||||
"gio-sys",
|
|
||||||
"glib-macros",
|
|
||||||
"glib-sys",
|
|
||||||
"gobject-sys",
|
|
||||||
"libc",
|
|
||||||
"memchr",
|
|
||||||
"once_cell",
|
|
||||||
"smallvec",
|
|
||||||
"thiserror",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "glib-macros"
|
|
||||||
version = "0.19.0"
|
|
||||||
source = "git+https://github.com/gtk-rs/gtk-rs-core#a07ec7484ab68bbac04d3f2d2d393a1beda6a48e"
|
|
||||||
dependencies = [
|
|
||||||
"heck",
|
|
||||||
"proc-macro-crate",
|
|
||||||
"proc-macro-error",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 2.0.39",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "glib-sys"
|
|
||||||
version = "0.19.0"
|
|
||||||
source = "git+https://github.com/gtk-rs/gtk-rs-core#a07ec7484ab68bbac04d3f2d2d393a1beda6a48e"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
"system-deps",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "gobject-sys"
|
|
||||||
version = "0.19.0"
|
|
||||||
source = "git+https://github.com/gtk-rs/gtk-rs-core#a07ec7484ab68bbac04d3f2d2d393a1beda6a48e"
|
|
||||||
dependencies = [
|
|
||||||
"glib-sys",
|
|
||||||
"libc",
|
|
||||||
"system-deps",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "gstreamer"
|
|
||||||
version = "0.22.0"
|
|
||||||
source = "git+https://gitlab.freedesktop.org/gstreamer/gstreamer-rs#897c7dfd391e6228ea11a6efa0737c0e3ca87cd6"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"futures-channel",
|
|
||||||
"futures-core",
|
|
||||||
"futures-util",
|
|
||||||
"glib",
|
|
||||||
"gstreamer-sys",
|
|
||||||
"itertools",
|
|
||||||
"libc",
|
|
||||||
"muldiv",
|
|
||||||
"num-integer",
|
|
||||||
"num-rational",
|
|
||||||
"option-operations",
|
|
||||||
"paste",
|
|
||||||
"pin-project-lite",
|
|
||||||
"pretty-hex",
|
|
||||||
"smallvec",
|
|
||||||
"thiserror",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "gstreamer-base"
|
|
||||||
version = "0.22.0"
|
|
||||||
source = "git+https://gitlab.freedesktop.org/gstreamer/gstreamer-rs#897c7dfd391e6228ea11a6efa0737c0e3ca87cd6"
|
|
||||||
dependencies = [
|
|
||||||
"atomic_refcell",
|
|
||||||
"cfg-if",
|
|
||||||
"glib",
|
|
||||||
"gstreamer",
|
|
||||||
"gstreamer-base-sys",
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "gstreamer-base-sys"
|
|
||||||
version = "0.22.0"
|
|
||||||
source = "git+https://gitlab.freedesktop.org/gstreamer/gstreamer-rs#897c7dfd391e6228ea11a6efa0737c0e3ca87cd6"
|
|
||||||
dependencies = [
|
|
||||||
"glib-sys",
|
|
||||||
"gobject-sys",
|
|
||||||
"gstreamer-sys",
|
|
||||||
"libc",
|
|
||||||
"system-deps",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "gstreamer-sys"
|
|
||||||
version = "0.22.0"
|
|
||||||
source = "git+https://gitlab.freedesktop.org/gstreamer/gstreamer-rs#897c7dfd391e6228ea11a6efa0737c0e3ca87cd6"
|
|
||||||
dependencies = [
|
|
||||||
"glib-sys",
|
|
||||||
"gobject-sys",
|
|
||||||
"libc",
|
|
||||||
"system-deps",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "hashbrown"
|
|
||||||
version = "0.14.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "heck"
|
|
||||||
version = "0.4.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "idna"
|
|
||||||
version = "0.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6"
|
|
||||||
dependencies = [
|
|
||||||
"unicode-bidi",
|
|
||||||
"unicode-normalization",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "indexmap"
|
|
||||||
version = "2.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f"
|
|
||||||
dependencies = [
|
|
||||||
"equivalent",
|
|
||||||
"hashbrown",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "itertools"
|
|
||||||
version = "0.12.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "25db6b064527c5d482d0423354fcd07a89a2dfe07b67892e62411946db7f07b0"
|
|
||||||
dependencies = [
|
|
||||||
"either",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "libc"
|
|
||||||
version = "0.2.150"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "memchr"
|
|
||||||
version = "2.6.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "muldiv"
|
|
||||||
version = "1.0.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "956787520e75e9bd233246045d19f42fb73242759cc57fba9611d940ae96d4b0"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "num-integer"
|
|
||||||
version = "0.1.45"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
"num-traits",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "num-rational"
|
|
||||||
version = "0.4.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
"num-integer",
|
|
||||||
"num-traits",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "num-traits"
|
|
||||||
version = "0.2.17"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "once_cell"
|
|
||||||
version = "1.18.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "option-operations"
|
|
||||||
version = "0.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7c26d27bb1aeab65138e4bf7666045169d1717febcc9ff870166be8348b223d0"
|
|
||||||
dependencies = [
|
|
||||||
"paste",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "paste"
|
|
||||||
version = "1.0.14"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "percent-encoding"
|
|
||||||
version = "2.3.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pin-project-lite"
|
|
||||||
version = "0.2.13"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pin-utils"
|
|
||||||
version = "0.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pkg-config"
|
|
||||||
version = "0.3.27"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pretty-hex"
|
|
||||||
version = "0.3.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c6fa0831dd7cc608c38a5e323422a0077678fa5744aa2be4ad91c4ece8eec8d5"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro-crate"
|
|
||||||
version = "2.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8"
|
|
||||||
dependencies = [
|
|
||||||
"toml_edit 0.20.7",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro-error"
|
|
||||||
version = "1.0.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro-error-attr",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 1.0.109",
|
|
||||||
"version_check",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro-error-attr"
|
|
||||||
version = "1.0.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"version_check",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro2"
|
|
||||||
version = "1.0.69"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
|
|
||||||
dependencies = [
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "quote"
|
|
||||||
version = "1.0.33"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "serde"
|
|
||||||
version = "1.0.193"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89"
|
|
||||||
dependencies = [
|
|
||||||
"serde_derive",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "serde_derive"
|
|
||||||
version = "1.0.193"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 2.0.39",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "serde_spanned"
|
|
||||||
version = "0.6.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "12022b835073e5b11e90a14f86838ceb1c8fb0325b72416845c487ac0fa95e80"
|
|
||||||
dependencies = [
|
|
||||||
"serde",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "slab"
|
|
||||||
version = "0.4.9"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "smallvec"
|
|
||||||
version = "1.11.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "syn"
|
|
||||||
version = "1.0.109"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "syn"
|
|
||||||
version = "2.0.39"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "system-deps"
|
|
||||||
version = "6.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2a2d580ff6a20c55dfb86be5f9c238f67835d0e81cbdea8bf5680e0897320331"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-expr",
|
|
||||||
"heck",
|
|
||||||
"pkg-config",
|
|
||||||
"toml",
|
|
||||||
"version-compare",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "target-lexicon"
|
|
||||||
version = "0.12.12"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "14c39fd04924ca3a864207c66fc2cd7d22d7c016007f9ce846cbb9326331930a"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "thiserror"
|
|
||||||
version = "1.0.50"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2"
|
|
||||||
dependencies = [
|
|
||||||
"thiserror-impl",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "thiserror-impl"
|
|
||||||
version = "1.0.50"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 2.0.39",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tinyvec"
|
|
||||||
version = "1.6.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50"
|
|
||||||
dependencies = [
|
|
||||||
"tinyvec_macros",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tinyvec_macros"
|
|
||||||
version = "0.1.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "toml"
|
|
||||||
version = "0.8.8"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a1a195ec8c9da26928f773888e0742ca3ca1040c6cd859c919c9f59c1954ab35"
|
|
||||||
dependencies = [
|
|
||||||
"serde",
|
|
||||||
"serde_spanned",
|
|
||||||
"toml_datetime",
|
|
||||||
"toml_edit 0.21.0",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "toml_datetime"
|
|
||||||
version = "0.6.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1"
|
|
||||||
dependencies = [
|
|
||||||
"serde",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "toml_edit"
|
|
||||||
version = "0.20.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "70f427fce4d84c72b5b732388bf4a9f4531b53f74e2887e3ecb2481f68f66d81"
|
|
||||||
dependencies = [
|
|
||||||
"indexmap",
|
|
||||||
"toml_datetime",
|
|
||||||
"winnow",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "toml_edit"
|
|
||||||
version = "0.21.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d34d383cd00a163b4a5b85053df514d45bc330f6de7737edfe0a93311d1eaa03"
|
|
||||||
dependencies = [
|
|
||||||
"indexmap",
|
|
||||||
"serde",
|
|
||||||
"serde_spanned",
|
|
||||||
"toml_datetime",
|
|
||||||
"winnow",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unicode-bidi"
|
|
||||||
version = "0.3.13"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unicode-ident"
|
|
||||||
version = "1.0.12"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unicode-normalization"
|
|
||||||
version = "0.1.22"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921"
|
|
||||||
dependencies = [
|
|
||||||
"tinyvec",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "url"
|
|
||||||
version = "2.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633"
|
|
||||||
dependencies = [
|
|
||||||
"form_urlencoded",
|
|
||||||
"idna",
|
|
||||||
"percent-encoding",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "version-compare"
|
|
||||||
version = "0.1.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "579a42fc0b8e0c63b76519a339be31bed574929511fa53c1a3acae26eb258f29"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "version_check"
|
|
||||||
version = "0.9.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "warp"
|
|
||||||
version = "0.1.0-alpha.1"
|
|
||||||
dependencies = [
|
|
||||||
"gstreamer",
|
|
||||||
"gstreamer-base",
|
|
||||||
"url",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows-sys"
|
|
||||||
version = "0.52.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
|
|
||||||
dependencies = [
|
|
||||||
"windows-targets",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows-targets"
|
|
||||||
version = "0.52.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd"
|
|
||||||
dependencies = [
|
|
||||||
"windows_aarch64_gnullvm",
|
|
||||||
"windows_aarch64_msvc",
|
|
||||||
"windows_i686_gnu",
|
|
||||||
"windows_i686_msvc",
|
|
||||||
"windows_x86_64_gnu",
|
|
||||||
"windows_x86_64_gnullvm",
|
|
||||||
"windows_x86_64_msvc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_aarch64_gnullvm"
|
|
||||||
version = "0.52.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_aarch64_msvc"
|
|
||||||
version = "0.52.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_i686_gnu"
|
|
||||||
version = "0.52.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_i686_msvc"
|
|
||||||
version = "0.52.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_x86_64_gnu"
|
|
||||||
version = "0.52.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_x86_64_gnullvm"
|
|
||||||
version = "0.52.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows_x86_64_msvc"
|
|
||||||
version = "0.52.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winnow"
|
|
||||||
version = "0.5.19"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "829846f3e3db426d4cee4510841b71a8e58aa2a76b1132579487ae430ccd9c7b"
|
|
||||||
dependencies = [
|
|
||||||
"memchr",
|
|
||||||
]
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "warp"
|
|
||||||
version = "0.1.0-alpha.1"
|
|
||||||
authors = ["Wanjohi Ryan<elviswanjohi47@gmail.com>"]
|
|
||||||
repository = "https://github.com/netrisme/warp"
|
|
||||||
license = "MIT OR Apache-2.0"
|
|
||||||
description = "GStreamer MoQ Sink Plugin"
|
|
||||||
edition = "2021"
|
|
||||||
rust-version = "1.70"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
gst-base = { package = "gstreamer-base", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs",features = ["v1_18"]}
|
|
||||||
gst-audio = { package = "gstreamer-audio", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs",features = ["v1_18"]}
|
|
||||||
gst-video = { package = "gstreamer-video", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs",features = ["v1_18"]}
|
|
||||||
wayland-display-core = { path = "../wayland-display-core" }
|
|
||||||
moq-transport = { path = "../moq-transport" }
|
|
||||||
|
|
||||||
# QUIC
|
|
||||||
quinn = "0.10"
|
|
||||||
webtransport-quinn = "0.6.1"
|
|
||||||
url = "2"
|
|
||||||
|
|
||||||
# Crypto
|
|
||||||
rustls = { version = "0.21", features = ["dangerous_configuration"] }
|
|
||||||
rustls-native-certs = "0.6"
|
|
||||||
rustls-pemfile = "1"
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
name = "gstwarp"
|
|
||||||
crate-type = ["cdylib", "rlib"]
|
|
||||||
path = "src/lib.rs"
|
|
||||||
|
|
||||||
[features]
|
|
||||||
static = []
|
|
||||||
capi = []
|
|
||||||
doc = []
|
|
||||||
default = []
|
|
||||||
|
|
||||||
[package.metadata.capi]
|
|
||||||
min_version = "0.9.21"
|
|
||||||
|
|
||||||
[package.metadata.capi.header]
|
|
||||||
enabled = false
|
|
||||||
|
|
||||||
[package.metadata.capi.library]
|
|
||||||
install_subdir = "gstreamer-1.0"
|
|
||||||
versioning = false
|
|
||||||
import_library = false
|
|
||||||
|
|
||||||
[package.metadata.capi.pkg_config]
|
|
||||||
requires_private = "gstreamer-1.0, gstreamer-base-1.0, gstreamer-audio-1.0, gstreamer-video-1.0, gobject-2.0, glib-2.0, gmodule-2.0"
|
|
||||||
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
fn main() {
|
|
||||||
gst_plugin_version_helper::info()
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
To be used as follows:
|
|
||||||
|
|
||||||
```rust
|
|
||||||
use gst::prelude::*;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
// Initialize GStreamer
|
|
||||||
gst::init().unwrap();
|
|
||||||
|
|
||||||
// Create the elements
|
|
||||||
let source = gst::ElementFactory::make("videotestsrc", Some("source")).unwrap();
|
|
||||||
let encoder = gst::ElementFactory::make("x264enc", Some("encoder")).unwrap();
|
|
||||||
let muxer = gst::ElementFactory::make("fmp4mux", Some("muxer")).unwrap();
|
|
||||||
let sink = gst::ElementFactory::make("warpsink", Some("sink")).unwrap();
|
|
||||||
|
|
||||||
// Create an empty pipeline
|
|
||||||
let pipeline = gst::Pipeline::new(Some("pipeline"));
|
|
||||||
|
|
||||||
// Build the pipeline
|
|
||||||
pipeline.add_many(&[&source, &encoder, &muxer, &sink]).unwrap();
|
|
||||||
gst::Element::link_many(&[&source, &encoder, &muxer, &sink]).unwrap();
|
|
||||||
|
|
||||||
// Start playing
|
|
||||||
pipeline.set_state(gst::State::Playing).unwrap();
|
|
||||||
|
|
||||||
// Wait until error or EOS
|
|
||||||
let bus = pipeline.bus().unwrap();
|
|
||||||
for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
|
|
||||||
use gst::MessageView;
|
|
||||||
|
|
||||||
match msg.view() {
|
|
||||||
MessageView::Error(err) => {
|
|
||||||
eprintln!(
|
|
||||||
"Error from {:?}: {} ({:?})",
|
|
||||||
err.src().map(|s| s.path_string()),
|
|
||||||
err.error(),
|
|
||||||
err.debug()
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
MessageView::Eos(..) => break,
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clean up
|
|
||||||
pipeline.set_state(gst::State::Null).unwrap();
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,373 +0,0 @@
|
|||||||
Mozilla Public License Version 2.0
|
|
||||||
==================================
|
|
||||||
|
|
||||||
1. Definitions
|
|
||||||
--------------
|
|
||||||
|
|
||||||
1.1. "Contributor"
|
|
||||||
means each individual or legal entity that creates, contributes to
|
|
||||||
the creation of, or owns Covered Software.
|
|
||||||
|
|
||||||
1.2. "Contributor Version"
|
|
||||||
means the combination of the Contributions of others (if any) used
|
|
||||||
by a Contributor and that particular Contributor's Contribution.
|
|
||||||
|
|
||||||
1.3. "Contribution"
|
|
||||||
means Covered Software of a particular Contributor.
|
|
||||||
|
|
||||||
1.4. "Covered Software"
|
|
||||||
means Source Code Form to which the initial Contributor has attached
|
|
||||||
the notice in Exhibit A, the Executable Form of such Source Code
|
|
||||||
Form, and Modifications of such Source Code Form, in each case
|
|
||||||
including portions thereof.
|
|
||||||
|
|
||||||
1.5. "Incompatible With Secondary Licenses"
|
|
||||||
means
|
|
||||||
|
|
||||||
(a) that the initial Contributor has attached the notice described
|
|
||||||
in Exhibit B to the Covered Software; or
|
|
||||||
|
|
||||||
(b) that the Covered Software was made available under the terms of
|
|
||||||
version 1.1 or earlier of the License, but not also under the
|
|
||||||
terms of a Secondary License.
|
|
||||||
|
|
||||||
1.6. "Executable Form"
|
|
||||||
means any form of the work other than Source Code Form.
|
|
||||||
|
|
||||||
1.7. "Larger Work"
|
|
||||||
means a work that combines Covered Software with other material, in
|
|
||||||
a separate file or files, that is not Covered Software.
|
|
||||||
|
|
||||||
1.8. "License"
|
|
||||||
means this document.
|
|
||||||
|
|
||||||
1.9. "Licensable"
|
|
||||||
means having the right to grant, to the maximum extent possible,
|
|
||||||
whether at the time of the initial grant or subsequently, any and
|
|
||||||
all of the rights conveyed by this License.
|
|
||||||
|
|
||||||
1.10. "Modifications"
|
|
||||||
means any of the following:
|
|
||||||
|
|
||||||
(a) any file in Source Code Form that results from an addition to,
|
|
||||||
deletion from, or modification of the contents of Covered
|
|
||||||
Software; or
|
|
||||||
|
|
||||||
(b) any new file in Source Code Form that contains any Covered
|
|
||||||
Software.
|
|
||||||
|
|
||||||
1.11. "Patent Claims" of a Contributor
|
|
||||||
means any patent claim(s), including without limitation, method,
|
|
||||||
process, and apparatus claims, in any patent Licensable by such
|
|
||||||
Contributor that would be infringed, but for the grant of the
|
|
||||||
License, by the making, using, selling, offering for sale, having
|
|
||||||
made, import, or transfer of either its Contributions or its
|
|
||||||
Contributor Version.
|
|
||||||
|
|
||||||
1.12. "Secondary License"
|
|
||||||
means either the GNU General Public License, Version 2.0, the GNU
|
|
||||||
Lesser General Public License, Version 2.1, the GNU Affero General
|
|
||||||
Public License, Version 3.0, or any later versions of those
|
|
||||||
licenses.
|
|
||||||
|
|
||||||
1.13. "Source Code Form"
|
|
||||||
means the form of the work preferred for making modifications.
|
|
||||||
|
|
||||||
1.14. "You" (or "Your")
|
|
||||||
means an individual or a legal entity exercising rights under this
|
|
||||||
License. For legal entities, "You" includes any entity that
|
|
||||||
controls, is controlled by, or is under common control with You. For
|
|
||||||
purposes of this definition, "control" means (a) the power, direct
|
|
||||||
or indirect, to cause the direction or management of such entity,
|
|
||||||
whether by contract or otherwise, or (b) ownership of more than
|
|
||||||
fifty percent (50%) of the outstanding shares or beneficial
|
|
||||||
ownership of such entity.
|
|
||||||
|
|
||||||
2. License Grants and Conditions
|
|
||||||
--------------------------------
|
|
||||||
|
|
||||||
2.1. Grants
|
|
||||||
|
|
||||||
Each Contributor hereby grants You a world-wide, royalty-free,
|
|
||||||
non-exclusive license:
|
|
||||||
|
|
||||||
(a) under intellectual property rights (other than patent or trademark)
|
|
||||||
Licensable by such Contributor to use, reproduce, make available,
|
|
||||||
modify, display, perform, distribute, and otherwise exploit its
|
|
||||||
Contributions, either on an unmodified basis, with Modifications, or
|
|
||||||
as part of a Larger Work; and
|
|
||||||
|
|
||||||
(b) under Patent Claims of such Contributor to make, use, sell, offer
|
|
||||||
for sale, have made, import, and otherwise transfer either its
|
|
||||||
Contributions or its Contributor Version.
|
|
||||||
|
|
||||||
2.2. Effective Date
|
|
||||||
|
|
||||||
The licenses granted in Section 2.1 with respect to any Contribution
|
|
||||||
become effective for each Contribution on the date the Contributor first
|
|
||||||
distributes such Contribution.
|
|
||||||
|
|
||||||
2.3. Limitations on Grant Scope
|
|
||||||
|
|
||||||
The licenses granted in this Section 2 are the only rights granted under
|
|
||||||
this License. No additional rights or licenses will be implied from the
|
|
||||||
distribution or licensing of Covered Software under this License.
|
|
||||||
Notwithstanding Section 2.1(b) above, no patent license is granted by a
|
|
||||||
Contributor:
|
|
||||||
|
|
||||||
(a) for any code that a Contributor has removed from Covered Software;
|
|
||||||
or
|
|
||||||
|
|
||||||
(b) for infringements caused by: (i) Your and any other third party's
|
|
||||||
modifications of Covered Software, or (ii) the combination of its
|
|
||||||
Contributions with other software (except as part of its Contributor
|
|
||||||
Version); or
|
|
||||||
|
|
||||||
(c) under Patent Claims infringed by Covered Software in the absence of
|
|
||||||
its Contributions.
|
|
||||||
|
|
||||||
This License does not grant any rights in the trademarks, service marks,
|
|
||||||
or logos of any Contributor (except as may be necessary to comply with
|
|
||||||
the notice requirements in Section 3.4).
|
|
||||||
|
|
||||||
2.4. Subsequent Licenses
|
|
||||||
|
|
||||||
No Contributor makes additional grants as a result of Your choice to
|
|
||||||
distribute the Covered Software under a subsequent version of this
|
|
||||||
License (see Section 10.2) or under the terms of a Secondary License (if
|
|
||||||
permitted under the terms of Section 3.3).
|
|
||||||
|
|
||||||
2.5. Representation
|
|
||||||
|
|
||||||
Each Contributor represents that the Contributor believes its
|
|
||||||
Contributions are its original creation(s) or it has sufficient rights
|
|
||||||
to grant the rights to its Contributions conveyed by this License.
|
|
||||||
|
|
||||||
2.6. Fair Use
|
|
||||||
|
|
||||||
This License is not intended to limit any rights You have under
|
|
||||||
applicable copyright doctrines of fair use, fair dealing, or other
|
|
||||||
equivalents.
|
|
||||||
|
|
||||||
2.7. Conditions
|
|
||||||
|
|
||||||
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
|
|
||||||
in Section 2.1.
|
|
||||||
|
|
||||||
3. Responsibilities
|
|
||||||
-------------------
|
|
||||||
|
|
||||||
3.1. Distribution of Source Form
|
|
||||||
|
|
||||||
All distribution of Covered Software in Source Code Form, including any
|
|
||||||
Modifications that You create or to which You contribute, must be under
|
|
||||||
the terms of this License. You must inform recipients that the Source
|
|
||||||
Code Form of the Covered Software is governed by the terms of this
|
|
||||||
License, and how they can obtain a copy of this License. You may not
|
|
||||||
attempt to alter or restrict the recipients' rights in the Source Code
|
|
||||||
Form.
|
|
||||||
|
|
||||||
3.2. Distribution of Executable Form
|
|
||||||
|
|
||||||
If You distribute Covered Software in Executable Form then:
|
|
||||||
|
|
||||||
(a) such Covered Software must also be made available in Source Code
|
|
||||||
Form, as described in Section 3.1, and You must inform recipients of
|
|
||||||
the Executable Form how they can obtain a copy of such Source Code
|
|
||||||
Form by reasonable means in a timely manner, at a charge no more
|
|
||||||
than the cost of distribution to the recipient; and
|
|
||||||
|
|
||||||
(b) You may distribute such Executable Form under the terms of this
|
|
||||||
License, or sublicense it under different terms, provided that the
|
|
||||||
license for the Executable Form does not attempt to limit or alter
|
|
||||||
the recipients' rights in the Source Code Form under this License.
|
|
||||||
|
|
||||||
3.3. Distribution of a Larger Work
|
|
||||||
|
|
||||||
You may create and distribute a Larger Work under terms of Your choice,
|
|
||||||
provided that You also comply with the requirements of this License for
|
|
||||||
the Covered Software. If the Larger Work is a combination of Covered
|
|
||||||
Software with a work governed by one or more Secondary Licenses, and the
|
|
||||||
Covered Software is not Incompatible With Secondary Licenses, this
|
|
||||||
License permits You to additionally distribute such Covered Software
|
|
||||||
under the terms of such Secondary License(s), so that the recipient of
|
|
||||||
the Larger Work may, at their option, further distribute the Covered
|
|
||||||
Software under the terms of either this License or such Secondary
|
|
||||||
License(s).
|
|
||||||
|
|
||||||
3.4. Notices
|
|
||||||
|
|
||||||
You may not remove or alter the substance of any license notices
|
|
||||||
(including copyright notices, patent notices, disclaimers of warranty,
|
|
||||||
or limitations of liability) contained within the Source Code Form of
|
|
||||||
the Covered Software, except that You may alter any license notices to
|
|
||||||
the extent required to remedy known factual inaccuracies.
|
|
||||||
|
|
||||||
3.5. Application of Additional Terms
|
|
||||||
|
|
||||||
You may choose to offer, and to charge a fee for, warranty, support,
|
|
||||||
indemnity or liability obligations to one or more recipients of Covered
|
|
||||||
Software. However, You may do so only on Your own behalf, and not on
|
|
||||||
behalf of any Contributor. You must make it absolutely clear that any
|
|
||||||
such warranty, support, indemnity, or liability obligation is offered by
|
|
||||||
You alone, and You hereby agree to indemnify every Contributor for any
|
|
||||||
liability incurred by such Contributor as a result of warranty, support,
|
|
||||||
indemnity or liability terms You offer. You may include additional
|
|
||||||
disclaimers of warranty and limitations of liability specific to any
|
|
||||||
jurisdiction.
|
|
||||||
|
|
||||||
4. Inability to Comply Due to Statute or Regulation
|
|
||||||
---------------------------------------------------
|
|
||||||
|
|
||||||
If it is impossible for You to comply with any of the terms of this
|
|
||||||
License with respect to some or all of the Covered Software due to
|
|
||||||
statute, judicial order, or regulation then You must: (a) comply with
|
|
||||||
the terms of this License to the maximum extent possible; and (b)
|
|
||||||
describe the limitations and the code they affect. Such description must
|
|
||||||
be placed in a text file included with all distributions of the Covered
|
|
||||||
Software under this License. Except to the extent prohibited by statute
|
|
||||||
or regulation, such description must be sufficiently detailed for a
|
|
||||||
recipient of ordinary skill to be able to understand it.
|
|
||||||
|
|
||||||
5. Termination
|
|
||||||
--------------
|
|
||||||
|
|
||||||
5.1. The rights granted under this License will terminate automatically
|
|
||||||
if You fail to comply with any of its terms. However, if You become
|
|
||||||
compliant, then the rights granted under this License from a particular
|
|
||||||
Contributor are reinstated (a) provisionally, unless and until such
|
|
||||||
Contributor explicitly and finally terminates Your grants, and (b) on an
|
|
||||||
ongoing basis, if such Contributor fails to notify You of the
|
|
||||||
non-compliance by some reasonable means prior to 60 days after You have
|
|
||||||
come back into compliance. Moreover, Your grants from a particular
|
|
||||||
Contributor are reinstated on an ongoing basis if such Contributor
|
|
||||||
notifies You of the non-compliance by some reasonable means, this is the
|
|
||||||
first time You have received notice of non-compliance with this License
|
|
||||||
from such Contributor, and You become compliant prior to 30 days after
|
|
||||||
Your receipt of the notice.
|
|
||||||
|
|
||||||
5.2. If You initiate litigation against any entity by asserting a patent
|
|
||||||
infringement claim (excluding declaratory judgment actions,
|
|
||||||
counter-claims, and cross-claims) alleging that a Contributor Version
|
|
||||||
directly or indirectly infringes any patent, then the rights granted to
|
|
||||||
You by any and all Contributors for the Covered Software under Section
|
|
||||||
2.1 of this License shall terminate.
|
|
||||||
|
|
||||||
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
|
|
||||||
end user license agreements (excluding distributors and resellers) which
|
|
||||||
have been validly granted by You or Your distributors under this License
|
|
||||||
prior to termination shall survive termination.
|
|
||||||
|
|
||||||
************************************************************************
|
|
||||||
* *
|
|
||||||
* 6. Disclaimer of Warranty *
|
|
||||||
* ------------------------- *
|
|
||||||
* *
|
|
||||||
* Covered Software is provided under this License on an "as is" *
|
|
||||||
* basis, without warranty of any kind, either expressed, implied, or *
|
|
||||||
* statutory, including, without limitation, warranties that the *
|
|
||||||
* Covered Software is free of defects, merchantable, fit for a *
|
|
||||||
* particular purpose or non-infringing. The entire risk as to the *
|
|
||||||
* quality and performance of the Covered Software is with You. *
|
|
||||||
* Should any Covered Software prove defective in any respect, You *
|
|
||||||
* (not any Contributor) assume the cost of any necessary servicing, *
|
|
||||||
* repair, or correction. This disclaimer of warranty constitutes an *
|
|
||||||
* essential part of this License. No use of any Covered Software is *
|
|
||||||
* authorized under this License except under this disclaimer. *
|
|
||||||
* *
|
|
||||||
************************************************************************
|
|
||||||
|
|
||||||
************************************************************************
|
|
||||||
* *
|
|
||||||
* 7. Limitation of Liability *
|
|
||||||
* -------------------------- *
|
|
||||||
* *
|
|
||||||
* Under no circumstances and under no legal theory, whether tort *
|
|
||||||
* (including negligence), contract, or otherwise, shall any *
|
|
||||||
* Contributor, or anyone who distributes Covered Software as *
|
|
||||||
* permitted above, be liable to You for any direct, indirect, *
|
|
||||||
* special, incidental, or consequential damages of any character *
|
|
||||||
* including, without limitation, damages for lost profits, loss of *
|
|
||||||
* goodwill, work stoppage, computer failure or malfunction, or any *
|
|
||||||
* and all other commercial damages or losses, even if such party *
|
|
||||||
* shall have been informed of the possibility of such damages. This *
|
|
||||||
* limitation of liability shall not apply to liability for death or *
|
|
||||||
* personal injury resulting from such party's negligence to the *
|
|
||||||
* extent applicable law prohibits such limitation. Some *
|
|
||||||
* jurisdictions do not allow the exclusion or limitation of *
|
|
||||||
* incidental or consequential damages, so this exclusion and *
|
|
||||||
* limitation may not apply to You. *
|
|
||||||
* *
|
|
||||||
************************************************************************
|
|
||||||
|
|
||||||
8. Litigation
|
|
||||||
-------------
|
|
||||||
|
|
||||||
Any litigation relating to this License may be brought only in the
|
|
||||||
courts of a jurisdiction where the defendant maintains its principal
|
|
||||||
place of business and such litigation shall be governed by laws of that
|
|
||||||
jurisdiction, without reference to its conflict-of-law provisions.
|
|
||||||
Nothing in this Section shall prevent a party's ability to bring
|
|
||||||
cross-claims or counter-claims.
|
|
||||||
|
|
||||||
9. Miscellaneous
|
|
||||||
----------------
|
|
||||||
|
|
||||||
This License represents the complete agreement concerning the subject
|
|
||||||
matter hereof. If any provision of this License is held to be
|
|
||||||
unenforceable, such provision shall be reformed only to the extent
|
|
||||||
necessary to make it enforceable. Any law or regulation which provides
|
|
||||||
that the language of a contract shall be construed against the drafter
|
|
||||||
shall not be used to construe this License against a Contributor.
|
|
||||||
|
|
||||||
10. Versions of the License
|
|
||||||
---------------------------
|
|
||||||
|
|
||||||
10.1. New Versions
|
|
||||||
|
|
||||||
Mozilla Foundation is the license steward. Except as provided in Section
|
|
||||||
10.3, no one other than the license steward has the right to modify or
|
|
||||||
publish new versions of this License. Each version will be given a
|
|
||||||
distinguishing version number.
|
|
||||||
|
|
||||||
10.2. Effect of New Versions
|
|
||||||
|
|
||||||
You may distribute the Covered Software under the terms of the version
|
|
||||||
of the License under which You originally received the Covered Software,
|
|
||||||
or under the terms of any subsequent version published by the license
|
|
||||||
steward.
|
|
||||||
|
|
||||||
10.3. Modified Versions
|
|
||||||
|
|
||||||
If you create software not governed by this License, and you want to
|
|
||||||
create a new license for such software, you may create and use a
|
|
||||||
modified version of this License if you rename the license and remove
|
|
||||||
any references to the name of the license steward (except to note that
|
|
||||||
such modified license differs from this License).
|
|
||||||
|
|
||||||
10.4. Distributing Source Code Form that is Incompatible With Secondary
|
|
||||||
Licenses
|
|
||||||
|
|
||||||
If You choose to distribute Source Code Form that is Incompatible With
|
|
||||||
Secondary Licenses under the terms of this version of the License, the
|
|
||||||
notice described in Exhibit B of this License must be attached.
|
|
||||||
|
|
||||||
Exhibit A - Source Code Form License Notice
|
|
||||||
-------------------------------------------
|
|
||||||
|
|
||||||
This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
||||||
|
|
||||||
If it is not possible or desirable to put the notice in a particular
|
|
||||||
file, then You may include the notice in a location (such as a LICENSE
|
|
||||||
file in a relevant directory) where a recipient would be likely to look
|
|
||||||
for such a notice.
|
|
||||||
|
|
||||||
You may add additional accurate notices of copyright ownership.
|
|
||||||
|
|
||||||
Exhibit B - "Incompatible With Secondary Licenses" Notice
|
|
||||||
---------------------------------------------------------
|
|
||||||
|
|
||||||
This Source Code Form is "Incompatible With Secondary Licenses", as
|
|
||||||
defined by the Mozilla Public License, v. 2.0.
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
https://github.com/sdroege/gst-plugin-rs/tree/main/mux/fmp4
|
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,208 +0,0 @@
|
|||||||
// Copyright (C) 2021 Sebastian Dröge <sebastian@centricular.com>
|
|
||||||
//
|
|
||||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v2.0.
|
|
||||||
// If a copy of the MPL was not distributed with this file, You can obtain one at
|
|
||||||
// <https://mozilla.org/MPL/2.0/>.
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: MPL-2.0
|
|
||||||
|
|
||||||
use gst::glib;
|
|
||||||
use gst::prelude::*;
|
|
||||||
|
|
||||||
mod boxes;
|
|
||||||
mod imp;
|
|
||||||
|
|
||||||
glib::wrapper! {
|
|
||||||
pub(crate) struct FMP4MuxPad(ObjectSubclass<imp::FMP4MuxPad>) @extends gst_base::AggregatorPad, gst::Pad, gst::Object;
|
|
||||||
}
|
|
||||||
|
|
||||||
glib::wrapper! {
|
|
||||||
pub(crate) struct FMP4Mux(ObjectSubclass<imp::FMP4Mux>) @extends gst_base::Aggregator, gst::Element, gst::Object;
|
|
||||||
}
|
|
||||||
|
|
||||||
glib::wrapper! {
|
|
||||||
pub(crate) struct ISOFMP4Mux(ObjectSubclass<imp::ISOFMP4Mux>) @extends FMP4Mux, gst_base::Aggregator, gst::Element, gst::Object;
|
|
||||||
}
|
|
||||||
|
|
||||||
glib::wrapper! {
|
|
||||||
pub(crate) struct CMAFMux(ObjectSubclass<imp::CMAFMux>) @extends FMP4Mux, gst_base::Aggregator, gst::Element, gst::Object;
|
|
||||||
}
|
|
||||||
|
|
||||||
glib::wrapper! {
|
|
||||||
pub(crate) struct DASHMP4Mux(ObjectSubclass<imp::DASHMP4Mux>) @extends FMP4Mux, gst_base::Aggregator, gst::Element, gst::Object;
|
|
||||||
}
|
|
||||||
|
|
||||||
glib::wrapper! {
|
|
||||||
pub(crate) struct ONVIFFMP4Mux(ObjectSubclass<imp::ONVIFFMP4Mux>) @extends FMP4Mux, gst_base::Aggregator, gst::Element, gst::Object;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
|
|
||||||
#[cfg(feature = "doc")]
|
|
||||||
{
|
|
||||||
FMP4Mux::static_type().mark_as_plugin_api(gst::PluginAPIFlags::empty());
|
|
||||||
FMP4MuxPad::static_type().mark_as_plugin_api(gst::PluginAPIFlags::empty());
|
|
||||||
HeaderUpdateMode::static_type().mark_as_plugin_api(gst::PluginAPIFlags::empty());
|
|
||||||
}
|
|
||||||
gst::Element::register(
|
|
||||||
Some(plugin),
|
|
||||||
"isofmp4mux",
|
|
||||||
gst::Rank::PRIMARY,
|
|
||||||
ISOFMP4Mux::static_type(),
|
|
||||||
)?;
|
|
||||||
gst::Element::register(
|
|
||||||
Some(plugin),
|
|
||||||
"cmafmux",
|
|
||||||
gst::Rank::PRIMARY,
|
|
||||||
CMAFMux::static_type(),
|
|
||||||
)?;
|
|
||||||
gst::Element::register(
|
|
||||||
Some(plugin),
|
|
||||||
"dashmp4mux",
|
|
||||||
gst::Rank::PRIMARY,
|
|
||||||
DASHMP4Mux::static_type(),
|
|
||||||
)?;
|
|
||||||
gst::Element::register(
|
|
||||||
Some(plugin),
|
|
||||||
"onviffmp4mux",
|
|
||||||
gst::Rank::PRIMARY,
|
|
||||||
ONVIFFMP4Mux::static_type(),
|
|
||||||
)?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub(crate) struct HeaderConfiguration {
|
|
||||||
variant: Variant,
|
|
||||||
update: bool,
|
|
||||||
|
|
||||||
/// Pre-defined movie timescale if not 0.
|
|
||||||
movie_timescale: u32,
|
|
||||||
|
|
||||||
/// First caps must be the video/reference stream. Must be in the order the tracks are going to
|
|
||||||
/// be used later for the fragments too.
|
|
||||||
streams: Vec<HeaderStream>,
|
|
||||||
|
|
||||||
write_mehd: bool,
|
|
||||||
duration: Option<gst::ClockTime>,
|
|
||||||
|
|
||||||
/// Start UTC time in ONVIF mode.
|
|
||||||
/// Since Jan 1 1601 in 100ns units.
|
|
||||||
start_utc_time: Option<u64>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub(crate) struct HeaderStream {
|
|
||||||
/// Caps of this stream
|
|
||||||
caps: gst::Caps,
|
|
||||||
|
|
||||||
/// Set if this is an intra-only stream
|
|
||||||
delta_frames: DeltaFrames,
|
|
||||||
|
|
||||||
/// Pre-defined trak timescale if not 0.
|
|
||||||
trak_timescale: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub(crate) struct FragmentHeaderConfiguration<'a> {
|
|
||||||
variant: Variant,
|
|
||||||
|
|
||||||
/// Sequence number for this fragment.
|
|
||||||
sequence_number: u32,
|
|
||||||
|
|
||||||
/// If this is a full fragment or only a chunk.
|
|
||||||
chunk: bool,
|
|
||||||
|
|
||||||
streams: &'a [FragmentHeaderStream],
|
|
||||||
buffers: &'a [Buffer],
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub(crate) struct FragmentHeaderStream {
|
|
||||||
/// Caps of this stream
|
|
||||||
caps: gst::Caps,
|
|
||||||
|
|
||||||
/// Set if this is an intra-only stream
|
|
||||||
delta_frames: DeltaFrames,
|
|
||||||
|
|
||||||
/// Pre-defined trak timescale if not 0.
|
|
||||||
trak_timescale: u32,
|
|
||||||
|
|
||||||
/// Start time of this fragment
|
|
||||||
///
|
|
||||||
/// `None` if this stream has no buffers in this fragment.
|
|
||||||
start_time: Option<gst::ClockTime>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
pub(crate) enum DeltaFrames {
|
|
||||||
/// Only single completely decodable frames
|
|
||||||
IntraOnly,
|
|
||||||
/// Frames may depend on past frames
|
|
||||||
PredictiveOnly,
|
|
||||||
/// Frames may depend on past or future frames
|
|
||||||
Bidirectional,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DeltaFrames {
|
|
||||||
/// Whether dts is required to order buffers differently from presentation order
|
|
||||||
pub(crate) fn requires_dts(&self) -> bool {
|
|
||||||
matches!(self, Self::Bidirectional)
|
|
||||||
}
|
|
||||||
/// Whether this coding structure does not allow delta flags on buffers
|
|
||||||
pub(crate) fn intra_only(&self) -> bool {
|
|
||||||
matches!(self, Self::IntraOnly)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub(crate) struct Buffer {
|
|
||||||
/// Track index
|
|
||||||
idx: usize,
|
|
||||||
|
|
||||||
/// Actual buffer
|
|
||||||
buffer: gst::Buffer,
|
|
||||||
|
|
||||||
/// Timestamp
|
|
||||||
timestamp: gst::ClockTime,
|
|
||||||
|
|
||||||
/// Sample duration
|
|
||||||
duration: gst::ClockTime,
|
|
||||||
|
|
||||||
/// Composition time offset
|
|
||||||
composition_time_offset: Option<i64>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::upper_case_acronyms)]
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
||||||
pub(crate) enum Variant {
|
|
||||||
ISO,
|
|
||||||
CMAF,
|
|
||||||
DASH,
|
|
||||||
ONVIF,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Variant {
|
|
||||||
pub(crate) fn is_single_stream(self) -> bool {
|
|
||||||
match self {
|
|
||||||
Variant::ISO | Variant::ONVIF => false,
|
|
||||||
Variant::CMAF | Variant::DASH => true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub(crate) struct FragmentOffset {
|
|
||||||
time: gst::ClockTime,
|
|
||||||
offset: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::upper_case_acronyms)]
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, glib::Enum)]
|
|
||||||
#[repr(i32)]
|
|
||||||
#[enum_type(name = "GstFMP4MuxHeaderUpdateMode")]
|
|
||||||
pub(crate) enum HeaderUpdateMode {
|
|
||||||
None,
|
|
||||||
Rewrite,
|
|
||||||
Update,
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
// Copyright (C) 2021 Sebastian Dröge <sebastian@centricular.com>
|
|
||||||
//
|
|
||||||
// This Source Code Form is subject to the terms of the Mozilla Public License, v2.0.
|
|
||||||
// If a copy of the MPL was not distributed with this file, You can obtain one at
|
|
||||||
// <https://mozilla.org/MPL/2.0/>.
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: MPL-2.0
|
|
||||||
#![allow(clippy::non_send_fields_in_send_ty, unused_doc_comments)]
|
|
||||||
|
|
||||||
/**
|
|
||||||
* plugin-warp:
|
|
||||||
*
|
|
||||||
* Since: plugins-rs-0.8.0
|
|
||||||
*/
|
|
||||||
use gst::glib;
|
|
||||||
|
|
||||||
mod fmp4mux;
|
|
||||||
// mod warpsink;
|
|
||||||
mod waylandsrc;
|
|
||||||
|
|
||||||
fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
|
|
||||||
waylandsrc::register(plugin)?;
|
|
||||||
fmp4mux::register(plugin)?;
|
|
||||||
// warpsink::register(plugin)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
gst::plugin_define!(
|
|
||||||
warp,
|
|
||||||
env!("CARGO_PKG_DESCRIPTION"),
|
|
||||||
plugin_init,
|
|
||||||
concat!(env!("CARGO_PKG_VERSION"), "-", env!("COMMIT_ID")),
|
|
||||||
// FIXME: MPL-2.0 is only allowed since 1.18.3 (as unknown) and 1.20 (as known)
|
|
||||||
"MPL",
|
|
||||||
env!("CARGO_PKG_NAME"),
|
|
||||||
env!("CARGO_PKG_NAME"),
|
|
||||||
env!("CARGO_PKG_REPOSITORY"),
|
|
||||||
env!("BUILD_REL_DATE")
|
|
||||||
);
|
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
use gst::glib;
|
|
||||||
use gst::prelude::*;
|
|
||||||
use gst::subclass::prelude::*;
|
|
||||||
use gst_base::subclass::prelude::*;
|
|
||||||
use gst_base::BaseSink;
|
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use std::sync::Mutex;
|
|
||||||
|
|
||||||
// Define the plugin's instance structure with a URL property.
|
|
||||||
pub struct MoqSink {
|
|
||||||
sink: gst_base::BaseSink,
|
|
||||||
url: Mutex<Option<String>>, // Store the URL property value
|
|
||||||
// Add additional fields for moq_transport as needed.
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implement the GObject subclass for our sink.
|
|
||||||
#[glib::object_subclass]
|
|
||||||
impl ObjectSubclass for MoqSink {
|
|
||||||
const NAME: &'static str = "MoqSink";
|
|
||||||
type Type = super::MoqSink;
|
|
||||||
type ParentType = BaseSink;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implement the GstObject trait for our sink to set up the metadata.
|
|
||||||
impl GstObjectImpl for MoqSink {}
|
|
||||||
|
|
||||||
// Implement the Element trait for our sink. This is where we can add pads and set up
|
|
||||||
// the element's functionality.
|
|
||||||
impl ElementImpl for MoqSink {
|
|
||||||
// Define metadata for the element.
|
|
||||||
fn metadata() -> Option<&'static gst::subclass::ElementMetadata> {
|
|
||||||
static ELEMENT_METADATA: Lazy<gst::subclass::ElementMetadata> = Lazy::new(|| {
|
|
||||||
gst::subclass::ElementMetadata::new(
|
|
||||||
"MoQ Sink",
|
|
||||||
"Sink/Network",
|
|
||||||
"Send data over QUIC using the MoQ protocol",
|
|
||||||
"Wanjohi Ryan<wanjohi.ryan@example.com>",
|
|
||||||
)
|
|
||||||
});
|
|
||||||
Some(&*ELEMENT_METADATA)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implement the properties and their behavior for the sink.
|
|
||||||
impl ObjectImpl for MoqSink {
|
|
||||||
fn properties() -> &'static [glib::ParamSpec] {
|
|
||||||
static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| {
|
|
||||||
vec![
|
|
||||||
glib::ParamSpecString::new(
|
|
||||||
"url",
|
|
||||||
"URL",
|
|
||||||
"URL to send data to",
|
|
||||||
None, // Default value
|
|
||||||
glib::ParamFlags::READWRITE,
|
|
||||||
),
|
|
||||||
]
|
|
||||||
});
|
|
||||||
|
|
||||||
PROPERTIES.as_ref()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_property(&self, _id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
|
|
||||||
match pspec.name() {
|
|
||||||
"url" => {
|
|
||||||
let mut url = self.url.lock().unwrap();
|
|
||||||
*url = value.get().expect("Type checked upstream");
|
|
||||||
}
|
|
||||||
_ => unimplemented!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn property(&self, _id: usize, pspec: &glib::ParamSpec) -> glib::Value {
|
|
||||||
match pspec.name() {
|
|
||||||
"url" => {
|
|
||||||
let url = self.url.lock().unwrap();
|
|
||||||
url.as_ref().to_value()
|
|
||||||
}
|
|
||||||
_ => unimplemented!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implement the BaseSink trait for our sink. This is where most of the sink logic is implemented.
|
|
||||||
impl BaseSinkImpl for MoqSink {
|
|
||||||
fn start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
|
|
||||||
// Initialize moq_transport here.
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
|
|
||||||
// Clean up moq_transport here.
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn render(&self, element: &Self::Type, buffer: &gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError> {
|
|
||||||
// Send buffer data over QUIC using moq_transport.
|
|
||||||
// from the provided `imp.rs` code. For simplicity, we'll just print the buffer size.
|
|
||||||
|
|
||||||
let size = buffer.size();
|
|
||||||
println!("Received buffer of size {}", size);
|
|
||||||
|
|
||||||
// You would then send the buffer data over QUIC using moq_transport.
|
|
||||||
// This part is omitted and should be implemented based on your transport protocol.
|
|
||||||
|
|
||||||
Ok(gst::FlowSuccess::Ok)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
use gst::glib;
|
|
||||||
use gst::prelude::*;
|
|
||||||
|
|
||||||
mod imp;
|
|
||||||
|
|
||||||
glib::wrapper! {
|
|
||||||
pub struct MoqSink(ObjectSubclass<imp::MoqSink>) @extends gst_base::BaseSink, gst::Element, gst::Object;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
|
|
||||||
gst::Element::register(
|
|
||||||
Some(plugin),
|
|
||||||
"moqsink",
|
|
||||||
gst::Rank::None,
|
|
||||||
MoqSink::static_type(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,282 +0,0 @@
|
|||||||
use std::sync::Mutex;
|
|
||||||
|
|
||||||
use gst::message::Application;
|
|
||||||
use gst_video::{VideoCapsBuilder, VideoFormat};
|
|
||||||
|
|
||||||
use gst::subclass::prelude::*;
|
|
||||||
use gst::{glib, Event, Fraction};
|
|
||||||
use gst::{
|
|
||||||
glib::{once_cell::sync::Lazy, ValueArray},
|
|
||||||
LibraryError,
|
|
||||||
};
|
|
||||||
use gst::{prelude::*, Structure};
|
|
||||||
|
|
||||||
use gst_base::subclass::base_src::CreateSuccess;
|
|
||||||
use gst_base::subclass::prelude::*;
|
|
||||||
use gst_base::traits::BaseSrcExt;
|
|
||||||
|
|
||||||
use waylanddisplaycore::WaylandDisplay;
|
|
||||||
use tracing_subscriber::layer::SubscriberExt;
|
|
||||||
use tracing_subscriber::Registry;
|
|
||||||
|
|
||||||
use crate::utils::{GstLayer, CAT};
|
|
||||||
|
|
||||||
pub struct WaylandDisplaySrc {
|
|
||||||
state: Mutex<Option<State>>,
|
|
||||||
settings: Mutex<Settings>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for WaylandDisplaySrc {
|
|
||||||
fn default() -> Self {
|
|
||||||
WaylandDisplaySrc {
|
|
||||||
state: Mutex::new(None),
|
|
||||||
settings: Mutex::new(Settings::default()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
|
||||||
pub struct Settings {
|
|
||||||
render_node: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct State {
|
|
||||||
display: WaylandDisplay,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[glib::object_subclass]
|
|
||||||
impl ObjectSubclass for WaylandDisplaySrc {
|
|
||||||
const NAME: &'static str = "GstWaylandDisplaySrc";
|
|
||||||
type Type = super::WaylandDisplaySrc;
|
|
||||||
type ParentType = gst_base::PushSrc;
|
|
||||||
type Interfaces = ();
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ObjectImpl for WaylandDisplaySrc {
|
|
||||||
fn properties() -> &'static [glib::ParamSpec] {
|
|
||||||
static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| {
|
|
||||||
vec![glib::ParamSpecString::builder("render-node")
|
|
||||||
.nick("DRM Render Node")
|
|
||||||
.blurb("DRM Render Node to use (e.g. /dev/dri/renderD128")
|
|
||||||
.construct()
|
|
||||||
.build()]
|
|
||||||
});
|
|
||||||
|
|
||||||
PROPERTIES.as_ref()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_property(&self, _id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
|
|
||||||
match pspec.name() {
|
|
||||||
"render-node" => {
|
|
||||||
let mut settings = self.settings.lock().unwrap();
|
|
||||||
settings.render_node = value
|
|
||||||
.get::<Option<String>>()
|
|
||||||
.expect("Type checked upstream");
|
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn property(&self, _id: usize, pspec: &glib::ParamSpec) -> glib::Value {
|
|
||||||
match pspec.name() {
|
|
||||||
"render-node" => {
|
|
||||||
let settings = self.settings.lock().unwrap();
|
|
||||||
settings
|
|
||||||
.render_node
|
|
||||||
.clone()
|
|
||||||
.unwrap_or_else(|| String::from("/dev/dri/renderD128"))
|
|
||||||
.to_value()
|
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn constructed(&self) {
|
|
||||||
self.parent_constructed();
|
|
||||||
|
|
||||||
let obj = self.obj();
|
|
||||||
obj.set_element_flags(gst::ElementFlags::SOURCE);
|
|
||||||
obj.set_live(true);
|
|
||||||
obj.set_format(gst::Format::Time);
|
|
||||||
obj.set_automatic_eos(false);
|
|
||||||
obj.set_do_timestamp(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GstObjectImpl for WaylandDisplaySrc {}
|
|
||||||
|
|
||||||
impl ElementImpl for WaylandDisplaySrc {
|
|
||||||
fn metadata() -> Option<&'static gst::subclass::ElementMetadata> {
|
|
||||||
static ELEMENT_METADATA: Lazy<gst::subclass::ElementMetadata> = Lazy::new(|| {
|
|
||||||
gst::subclass::ElementMetadata::new(
|
|
||||||
"Wayland display source",
|
|
||||||
"Source/Video",
|
|
||||||
"GStreamer video src running a wayland compositor",
|
|
||||||
"Victoria Brekenfeld <wayland@drakulix.de>",
|
|
||||||
)
|
|
||||||
});
|
|
||||||
|
|
||||||
Some(&*ELEMENT_METADATA)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn pad_templates() -> &'static [gst::PadTemplate] {
|
|
||||||
static PAD_TEMPLATES: Lazy<Vec<gst::PadTemplate>> = Lazy::new(|| {
|
|
||||||
let caps = gst_video::VideoCapsBuilder::new()
|
|
||||||
.format(VideoFormat::Rgbx)
|
|
||||||
.height_range(..i32::MAX)
|
|
||||||
.width_range(..i32::MAX)
|
|
||||||
.framerate_range(Fraction::new(1, 1)..Fraction::new(i32::MAX, 1))
|
|
||||||
.build();
|
|
||||||
let src_pad_template = gst::PadTemplate::new(
|
|
||||||
"src",
|
|
||||||
gst::PadDirection::Src,
|
|
||||||
gst::PadPresence::Always,
|
|
||||||
&caps,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
vec![src_pad_template]
|
|
||||||
});
|
|
||||||
|
|
||||||
PAD_TEMPLATES.as_ref()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn change_state(
|
|
||||||
&self,
|
|
||||||
transition: gst::StateChange,
|
|
||||||
) -> Result<gst::StateChangeSuccess, gst::StateChangeError> {
|
|
||||||
let res = self.parent_change_state(transition);
|
|
||||||
match res {
|
|
||||||
Ok(gst::StateChangeSuccess::Success) => {
|
|
||||||
if transition.next() == gst::State::Paused {
|
|
||||||
// this is a live source
|
|
||||||
Ok(gst::StateChangeSuccess::NoPreroll)
|
|
||||||
} else {
|
|
||||||
Ok(gst::StateChangeSuccess::Success)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
x => x,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn query(&self, query: &mut gst::QueryRef) -> bool {
|
|
||||||
ElementImplExt::parent_query(self, query)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BaseSrcImpl for WaylandDisplaySrc {
|
|
||||||
fn query(&self, query: &mut gst::QueryRef) -> bool {
|
|
||||||
BaseSrcImplExt::parent_query(self, query)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn caps(&self, filter: Option<&gst::Caps>) -> Option<gst::Caps> {
|
|
||||||
let mut caps = VideoCapsBuilder::new()
|
|
||||||
.format(VideoFormat::Rgbx)
|
|
||||||
.height_range(..i32::MAX)
|
|
||||||
.width_range(..i32::MAX)
|
|
||||||
.framerate_range(Fraction::new(1, 1)..Fraction::new(i32::MAX, 1))
|
|
||||||
.build();
|
|
||||||
|
|
||||||
if let Some(filter) = filter {
|
|
||||||
caps = caps.intersect(filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
Some(caps)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn negotiate(&self) -> Result<(), gst::LoggableError> {
|
|
||||||
self.parent_negotiate()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn event(&self, event: &Event) -> bool {
|
|
||||||
if event.type_() == gst::EventType::CustomUpstream {
|
|
||||||
let structure = event.structure().expect("Unable to get message structure");
|
|
||||||
if structure.has_name("VirtualDevicesReady") {
|
|
||||||
let mut state = self.state.lock().unwrap();
|
|
||||||
let display = &mut state.as_mut().unwrap().display;
|
|
||||||
|
|
||||||
let paths = structure
|
|
||||||
.get::<ValueArray>("paths")
|
|
||||||
.expect("Should contain paths");
|
|
||||||
for value in paths.into_iter() {
|
|
||||||
let path = value.get::<String>().expect("Paths are strings");
|
|
||||||
display.add_input_device(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.parent_event(event)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_caps(&self, caps: &gst::Caps) -> Result<(), gst::LoggableError> {
|
|
||||||
let video_info = gst_video::VideoInfo::from_caps(caps).expect("failed to get video info");
|
|
||||||
self.state
|
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.as_mut()
|
|
||||||
.unwrap()
|
|
||||||
.display
|
|
||||||
.set_video_info(video_info);
|
|
||||||
|
|
||||||
self.parent_set_caps(caps)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn start(&self) -> Result<(), gst::ErrorMessage> {
|
|
||||||
let mut state = self.state.lock().unwrap();
|
|
||||||
if state.is_some() {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
let settings = self.settings.lock().unwrap();
|
|
||||||
let elem = self.obj().upcast_ref::<gst::Element>().to_owned();
|
|
||||||
let subscriber = Registry::default().with(GstLayer);
|
|
||||||
|
|
||||||
let Ok(mut display) = tracing::subscriber::with_default(subscriber, || WaylandDisplay::new(settings.render_node.clone())) else {
|
|
||||||
return Err(gst::error_msg!(LibraryError::Failed, ("Failed to open drm node {}, if you want to utilize software rendering set `render-node=software`.", settings.render_node.as_deref().unwrap_or("/dev/dri/renderD128"))));
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut structure = Structure::builder("wayland.src");
|
|
||||||
for (key, var) in display.env_vars().flat_map(|var| var.split_once("=")) {
|
|
||||||
structure = structure.field(key, var);
|
|
||||||
}
|
|
||||||
let structure = structure.build();
|
|
||||||
if let Err(err) = elem.post_message(Application::builder(structure).src(&elem).build()) {
|
|
||||||
gst::warning!(CAT, "Failed to post environment to gstreamer bus: {}", err);
|
|
||||||
}
|
|
||||||
|
|
||||||
*state = Some(State { display });
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn stop(&self) -> Result<(), gst::ErrorMessage> {
|
|
||||||
let mut state = self.state.lock().unwrap();
|
|
||||||
if let Some(state) = state.take() {
|
|
||||||
let subscriber = Registry::default().with(GstLayer);
|
|
||||||
tracing::subscriber::with_default(subscriber, || std::mem::drop(state.display));
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_seekable(&self) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PushSrcImpl for WaylandDisplaySrc {
|
|
||||||
fn create(
|
|
||||||
&self,
|
|
||||||
_buffer: Option<&mut gst::BufferRef>,
|
|
||||||
) -> Result<CreateSuccess, gst::FlowError> {
|
|
||||||
let mut state_guard = self.state.lock().unwrap();
|
|
||||||
let Some(state) = state_guard.as_mut() else {
|
|
||||||
return Err(gst::FlowError::Eos);
|
|
||||||
};
|
|
||||||
|
|
||||||
let subscriber = Registry::default().with(GstLayer);
|
|
||||||
tracing::subscriber::with_default(subscriber, || {
|
|
||||||
state.display.frame().map(CreateSuccess::NewBuffer)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
use gst::glib;
|
|
||||||
use gst::prelude::*;
|
|
||||||
|
|
||||||
mod imp;
|
|
||||||
|
|
||||||
glib::wrapper! {
|
|
||||||
pub struct WaylandDisplaySrc(ObjectSubclass<imp::WaylandDisplaySrc>) @extends gst_base::PushSrc, gst_base::BaseSrc, gst::Element, gst::Object;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
|
|
||||||
gst::Element::register(
|
|
||||||
Some(plugin),
|
|
||||||
"waylanddisplaysrc",
|
|
||||||
gst::Rank::Marginal,
|
|
||||||
WaylandDisplaySrc::static_type(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
46
main.rs
46
main.rs
@@ -1,46 +0,0 @@
|
|||||||
use gst::prelude::*;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
// Initialize GStreamer
|
|
||||||
gst::init().unwrap();
|
|
||||||
|
|
||||||
// Create the elements
|
|
||||||
let source = gst::ElementFactory::make("waylanddisplaysrc", Some("source")).unwrap();
|
|
||||||
let encoder = gst::ElementFactory::make("x264enc", Some("encoder")).unwrap();
|
|
||||||
let muxer = gst::ElementFactory::make("fmp4mux", Some("muxer")).unwrap();
|
|
||||||
// let sink = gst::ElementFactory::make("warpsink", Some("sink")).unwrap();
|
|
||||||
let sink = gst::ElementFactory::make("autovideosink", Some("sink")).unwrap();
|
|
||||||
|
|
||||||
// Create an empty pipeline
|
|
||||||
let pipeline = gst::Pipeline::new(Some("pipeline"));
|
|
||||||
|
|
||||||
// Build the pipeline
|
|
||||||
pipeline.add_many(&[&source, &encoder, &muxer, &sink]).unwrap();
|
|
||||||
gst::Element::link_many(&[&source, &encoder, &muxer, &sink]).unwrap();
|
|
||||||
|
|
||||||
// Start playing
|
|
||||||
pipeline.set_state(gst::State::Playing).unwrap();
|
|
||||||
|
|
||||||
// Wait until error or EOS
|
|
||||||
let bus = pipeline.bus().unwrap();
|
|
||||||
for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
|
|
||||||
use gst::MessageView;
|
|
||||||
|
|
||||||
match msg.view() {
|
|
||||||
MessageView::Error(err) => {
|
|
||||||
eprintln!(
|
|
||||||
"Error from {:?}: {} ({:?})",
|
|
||||||
err.src().map(|s| s.path_string()),
|
|
||||||
err.error(),
|
|
||||||
err.debug()
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
MessageView::Eos(..) => break,
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clean up
|
|
||||||
pipeline.set_state(gst::State::Null).unwrap();
|
|
||||||
}
|
|
||||||
1905
moq-transport/Cargo.lock
generated
1905
moq-transport/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,52 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "moq-transport"
|
|
||||||
description = "Media over QUIC"
|
|
||||||
authors = ["Luke Curley"]
|
|
||||||
repository = "https://github.com/kixelated/moq-rs"
|
|
||||||
license = "MIT OR Apache-2.0"
|
|
||||||
|
|
||||||
version = "0.2.0"
|
|
||||||
edition = "2021"
|
|
||||||
|
|
||||||
keywords = ["quic", "http3", "webtransport", "media", "live"]
|
|
||||||
categories = ["multimedia", "network-programming", "web-programming"]
|
|
||||||
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
bytes = "1"
|
|
||||||
thiserror = "1"
|
|
||||||
tokio = { version = "1", features = ["macros", "io-util", "sync"] }
|
|
||||||
log = "0.4"
|
|
||||||
indexmap = "2"
|
|
||||||
|
|
||||||
quinn = "0.10"
|
|
||||||
webtransport-quinn = "0.6.1"
|
|
||||||
#webtransport-quinn = { path = "../../webtransport-rs/webtransport-quinn" }
|
|
||||||
|
|
||||||
async-trait = "0.1"
|
|
||||||
paste = "1"
|
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
# QUIC
|
|
||||||
url = "2"
|
|
||||||
|
|
||||||
# Crypto
|
|
||||||
rustls = { version = "0.21", features = ["dangerous_configuration"] }
|
|
||||||
rustls-native-certs = "0.6"
|
|
||||||
rustls-pemfile = "1"
|
|
||||||
|
|
||||||
# Async stuff
|
|
||||||
tokio = { version = "1", features = ["full"] }
|
|
||||||
|
|
||||||
# CLI, logging, error handling
|
|
||||||
clap = { version = "4", features = ["derive"] }
|
|
||||||
log = { version = "0.4", features = ["std"] }
|
|
||||||
env_logger = "0.9"
|
|
||||||
mp4 = "0.13"
|
|
||||||
anyhow = { version = "1", features = ["backtrace"] }
|
|
||||||
serde_json = "1"
|
|
||||||
rfc6381-codec = "0.1"
|
|
||||||
tracing = "0.1"
|
|
||||||
tracing-subscriber = "0.3"
|
|
||||||
@@ -1,202 +0,0 @@
|
|||||||
|
|
||||||
Apache License
|
|
||||||
Version 2.0, January 2004
|
|
||||||
http://www.apache.org/licenses/
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
||||||
|
|
||||||
1. Definitions.
|
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction,
|
|
||||||
and distribution as defined by Sections 1 through 9 of this document.
|
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by
|
|
||||||
the copyright owner that is granting the License.
|
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all
|
|
||||||
other entities that control, are controlled by, or are under common
|
|
||||||
control with that entity. For the purposes of this definition,
|
|
||||||
"control" means (i) the power, direct or indirect, to cause the
|
|
||||||
direction or management of such entity, whether by contract or
|
|
||||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
||||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity
|
|
||||||
exercising permissions granted by this License.
|
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications,
|
|
||||||
including but not limited to software source code, documentation
|
|
||||||
source, and configuration files.
|
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical
|
|
||||||
transformation or translation of a Source form, including but
|
|
||||||
not limited to compiled object code, generated documentation,
|
|
||||||
and conversions to other media types.
|
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or
|
|
||||||
Object form, made available under the License, as indicated by a
|
|
||||||
copyright notice that is included in or attached to the work
|
|
||||||
(an example is provided in the Appendix below).
|
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object
|
|
||||||
form, that is based on (or derived from) the Work and for which the
|
|
||||||
editorial revisions, annotations, elaborations, or other modifications
|
|
||||||
represent, as a whole, an original work of authorship. For the purposes
|
|
||||||
of this License, Derivative Works shall not include works that remain
|
|
||||||
separable from, or merely link (or bind by name) to the interfaces of,
|
|
||||||
the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including
|
|
||||||
the original version of the Work and any modifications or additions
|
|
||||||
to that Work or Derivative Works thereof, that is intentionally
|
|
||||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
||||||
or by an individual or Legal Entity authorized to submit on behalf of
|
|
||||||
the copyright owner. For the purposes of this definition, "submitted"
|
|
||||||
means any form of electronic, verbal, or written communication sent
|
|
||||||
to the Licensor or its representatives, including but not limited to
|
|
||||||
communication on electronic mailing lists, source code control systems,
|
|
||||||
and issue tracking systems that are managed by, or on behalf of, the
|
|
||||||
Licensor for the purpose of discussing and improving the Work, but
|
|
||||||
excluding communication that is conspicuously marked or otherwise
|
|
||||||
designated in writing by the copyright owner as "Not a Contribution."
|
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
||||||
on behalf of whom a Contribution has been received by Licensor and
|
|
||||||
subsequently incorporated within the Work.
|
|
||||||
|
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
copyright license to reproduce, prepare Derivative Works of,
|
|
||||||
publicly display, publicly perform, sublicense, and distribute the
|
|
||||||
Work and such Derivative Works in Source or Object form.
|
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
(except as stated in this section) patent license to make, have made,
|
|
||||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
||||||
where such license applies only to those patent claims licensable
|
|
||||||
by such Contributor that are necessarily infringed by their
|
|
||||||
Contribution(s) alone or by combination of their Contribution(s)
|
|
||||||
with the Work to which such Contribution(s) was submitted. If You
|
|
||||||
institute patent litigation against any entity (including a
|
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
||||||
or a Contribution incorporated within the Work constitutes direct
|
|
||||||
or contributory patent infringement, then any patent licenses
|
|
||||||
granted to You under this License for that Work shall terminate
|
|
||||||
as of the date such litigation is filed.
|
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the
|
|
||||||
Work or Derivative Works thereof in any medium, with or without
|
|
||||||
modifications, and in Source or Object form, provided that You
|
|
||||||
meet the following conditions:
|
|
||||||
|
|
||||||
(a) You must give any other recipients of the Work or
|
|
||||||
Derivative Works a copy of this License; and
|
|
||||||
|
|
||||||
(b) You must cause any modified files to carry prominent notices
|
|
||||||
stating that You changed the files; and
|
|
||||||
|
|
||||||
(c) You must retain, in the Source form of any Derivative Works
|
|
||||||
that You distribute, all copyright, patent, trademark, and
|
|
||||||
attribution notices from the Source form of the Work,
|
|
||||||
excluding those notices that do not pertain to any part of
|
|
||||||
the Derivative Works; and
|
|
||||||
|
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its
|
|
||||||
distribution, then any Derivative Works that You distribute must
|
|
||||||
include a readable copy of the attribution notices contained
|
|
||||||
within such NOTICE file, excluding those notices that do not
|
|
||||||
pertain to any part of the Derivative Works, in at least one
|
|
||||||
of the following places: within a NOTICE text file distributed
|
|
||||||
as part of the Derivative Works; within the Source form or
|
|
||||||
documentation, if provided along with the Derivative Works; or,
|
|
||||||
within a display generated by the Derivative Works, if and
|
|
||||||
wherever such third-party notices normally appear. The contents
|
|
||||||
of the NOTICE file are for informational purposes only and
|
|
||||||
do not modify the License. You may add Your own attribution
|
|
||||||
notices within Derivative Works that You distribute, alongside
|
|
||||||
or as an addendum to the NOTICE text from the Work, provided
|
|
||||||
that such additional attribution notices cannot be construed
|
|
||||||
as modifying the License.
|
|
||||||
|
|
||||||
You may add Your own copyright statement to Your modifications and
|
|
||||||
may provide additional or different license terms and conditions
|
|
||||||
for use, reproduction, or distribution of Your modifications, or
|
|
||||||
for any such Derivative Works as a whole, provided Your use,
|
|
||||||
reproduction, and distribution of the Work otherwise complies with
|
|
||||||
the conditions stated in this License.
|
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
||||||
any Contribution intentionally submitted for inclusion in the Work
|
|
||||||
by You to the Licensor shall be under the terms and conditions of
|
|
||||||
this License, without any additional terms or conditions.
|
|
||||||
Notwithstanding the above, nothing herein shall supersede or modify
|
|
||||||
the terms of any separate license agreement you may have executed
|
|
||||||
with Licensor regarding such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade
|
|
||||||
names, trademarks, service marks, or product names of the Licensor,
|
|
||||||
except as required for reasonable and customary use in describing the
|
|
||||||
origin of the Work and reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
||||||
agreed to in writing, Licensor provides the Work (and each
|
|
||||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
||||||
implied, including, without limitation, any warranties or conditions
|
|
||||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
||||||
appropriateness of using or redistributing the Work and assume any
|
|
||||||
risks associated with Your exercise of permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory,
|
|
||||||
whether in tort (including negligence), contract, or otherwise,
|
|
||||||
unless required by applicable law (such as deliberate and grossly
|
|
||||||
negligent acts) or agreed to in writing, shall any Contributor be
|
|
||||||
liable to You for damages, including any direct, indirect, special,
|
|
||||||
incidental, or consequential damages of any character arising as a
|
|
||||||
result of this License or out of the use or inability to use the
|
|
||||||
Work (including but not limited to damages for loss of goodwill,
|
|
||||||
work stoppage, computer failure or malfunction, or any and all
|
|
||||||
other commercial damages or losses), even if such Contributor
|
|
||||||
has been advised of the possibility of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing
|
|
||||||
the Work or Derivative Works thereof, You may choose to offer,
|
|
||||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
||||||
or other liability obligations and/or rights consistent with this
|
|
||||||
License. However, in accepting such obligations, You may act only
|
|
||||||
on Your own behalf and on Your sole responsibility, not on behalf
|
|
||||||
of any other Contributor, and only if You agree to indemnify,
|
|
||||||
defend, and hold each Contributor harmless for any liability
|
|
||||||
incurred by, or claims asserted against, such Contributor by reason
|
|
||||||
of your accepting any such warranty or additional liability.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
APPENDIX: How to apply the Apache License to your work.
|
|
||||||
|
|
||||||
To apply the Apache License to your work, attach the following
|
|
||||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
||||||
replaced with your own identifying information. (Don't include
|
|
||||||
the brackets!) The text should be enclosed in the appropriate
|
|
||||||
comment syntax for the file format. We also recommend that a
|
|
||||||
file or class name and description of purpose be included on the
|
|
||||||
same "printed page" as the copyright notice for easier
|
|
||||||
identification within third-party archives.
|
|
||||||
|
|
||||||
Copyright [yyyy] [name of copyright owner]
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2023 Luke Curley
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
[](https://docs.rs/moq-transport/)
|
|
||||||
[](https://crates.io/crates/moq-transport)
|
|
||||||
[](LICENSE-MIT)
|
|
||||||
|
|
||||||
# moq-transport
|
|
||||||
|
|
||||||
A Rust implementation of the proposed IETF standard.
|
|
||||||
|
|
||||||
[Specification](https://datatracker.ietf.org/doc/draft-ietf-moq-transport/)
|
|
||||||
[Github](https://github.com/moq-wg/moq-transport)
|
|
||||||
262
moq-transport/src/cache/broadcast.rs
vendored
262
moq-transport/src/cache/broadcast.rs
vendored
@@ -1,262 +0,0 @@
|
|||||||
//! A broadcast is a collection of tracks, split into two handles: [Publisher] and [Subscriber].
|
|
||||||
//!
|
|
||||||
//! The [Publisher] can create tracks, either manually or on request.
|
|
||||||
//! It receives all requests by a [Subscriber] for a tracks that don't exist.
|
|
||||||
//! The simplest implementation is to close every unknown track with [CacheError::NotFound].
|
|
||||||
//!
|
|
||||||
//! A [Subscriber] can request tracks by name.
|
|
||||||
//! If the track already exists, it will be returned.
|
|
||||||
//! If the track doesn't exist, it will be sent to [Unknown] to be handled.
|
|
||||||
//! A [Subscriber] can be cloned to create multiple subscriptions.
|
|
||||||
//!
|
|
||||||
//! The broadcast is automatically closed with [CacheError::Closed] when [Publisher] is dropped, or all [Subscriber]s are dropped.
|
|
||||||
use std::{
|
|
||||||
collections::{hash_map, HashMap, VecDeque},
|
|
||||||
fmt,
|
|
||||||
ops::Deref,
|
|
||||||
sync::Arc,
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::{track, CacheError, Watch};
|
|
||||||
|
|
||||||
/// Create a new broadcast.
|
|
||||||
pub fn new(id: &str) -> (Publisher, Subscriber) {
|
|
||||||
let state = Watch::new(State::default());
|
|
||||||
let info = Arc::new(Info { id: id.to_string() });
|
|
||||||
|
|
||||||
let publisher = Publisher::new(state.clone(), info.clone());
|
|
||||||
let subscriber = Subscriber::new(state, info);
|
|
||||||
|
|
||||||
(publisher, subscriber)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Static information about a broadcast.
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct Info {
|
|
||||||
pub id: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Dynamic information about the broadcast.
|
|
||||||
#[derive(Debug)]
|
|
||||||
struct State {
|
|
||||||
tracks: HashMap<String, track::Subscriber>,
|
|
||||||
requested: VecDeque<track::Publisher>,
|
|
||||||
closed: Result<(), CacheError>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl State {
|
|
||||||
pub fn get(&self, name: &str) -> Result<Option<track::Subscriber>, CacheError> {
|
|
||||||
// Don't check closed, so we can return from cache.
|
|
||||||
Ok(self.tracks.get(name).cloned())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn insert(&mut self, track: track::Subscriber) -> Result<(), CacheError> {
|
|
||||||
self.closed.clone()?;
|
|
||||||
|
|
||||||
match self.tracks.entry(track.name.clone()) {
|
|
||||||
hash_map::Entry::Occupied(_) => return Err(CacheError::Duplicate),
|
|
||||||
hash_map::Entry::Vacant(v) => v.insert(track),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn request(&mut self, name: &str) -> Result<track::Subscriber, CacheError> {
|
|
||||||
self.closed.clone()?;
|
|
||||||
|
|
||||||
// Create a new track.
|
|
||||||
let (publisher, subscriber) = track::new(name);
|
|
||||||
|
|
||||||
// Insert the track into our Map so we deduplicate future requests.
|
|
||||||
self.tracks.insert(name.to_string(), subscriber.clone());
|
|
||||||
|
|
||||||
// Send the track to the Publisher to handle.
|
|
||||||
self.requested.push_back(publisher);
|
|
||||||
|
|
||||||
Ok(subscriber)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn has_next(&self) -> Result<bool, CacheError> {
|
|
||||||
// Check if there's any elements in the queue before checking closed.
|
|
||||||
if !self.requested.is_empty() {
|
|
||||||
return Ok(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.closed.clone()?;
|
|
||||||
Ok(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn next(&mut self) -> track::Publisher {
|
|
||||||
// We panic instead of erroring to avoid a nasty wakeup loop if you don't call has_next first.
|
|
||||||
self.requested.pop_front().expect("no entry in queue")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn close(&mut self, err: CacheError) -> Result<(), CacheError> {
|
|
||||||
self.closed.clone()?;
|
|
||||||
self.closed = Err(err);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for State {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
tracks: HashMap::new(),
|
|
||||||
closed: Ok(()),
|
|
||||||
requested: VecDeque::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Publish new tracks for a broadcast by name.
|
|
||||||
// TODO remove Clone
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct Publisher {
|
|
||||||
state: Watch<State>,
|
|
||||||
info: Arc<Info>,
|
|
||||||
_dropped: Arc<Dropped>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Publisher {
|
|
||||||
fn new(state: Watch<State>, info: Arc<Info>) -> Self {
|
|
||||||
let _dropped = Arc::new(Dropped::new(state.clone()));
|
|
||||||
Self { state, info, _dropped }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a new track with the given name, inserting it into the broadcast.
|
|
||||||
pub fn create_track(&mut self, name: &str) -> Result<track::Publisher, CacheError> {
|
|
||||||
let (publisher, subscriber) = track::new(name);
|
|
||||||
self.state.lock_mut().insert(subscriber)?;
|
|
||||||
Ok(publisher)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Insert a track into the broadcast.
|
|
||||||
pub fn insert_track(&mut self, track: track::Subscriber) -> Result<(), CacheError> {
|
|
||||||
self.state.lock_mut().insert(track)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Block until the next track requested by a subscriber.
|
|
||||||
pub async fn next_track(&mut self) -> Result<track::Publisher, CacheError> {
|
|
||||||
loop {
|
|
||||||
let notify = {
|
|
||||||
let state = self.state.lock();
|
|
||||||
if state.has_next()? {
|
|
||||||
return Ok(state.into_mut().next());
|
|
||||||
}
|
|
||||||
|
|
||||||
state.changed()
|
|
||||||
};
|
|
||||||
|
|
||||||
notify.await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Close the broadcast with an error.
|
|
||||||
pub fn close(self, err: CacheError) -> Result<(), CacheError> {
|
|
||||||
self.state.lock_mut().close(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for Publisher {
|
|
||||||
type Target = Info;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.info
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for Publisher {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
f.debug_struct("Publisher")
|
|
||||||
.field("state", &self.state)
|
|
||||||
.field("info", &self.info)
|
|
||||||
.finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Subscribe to a broadcast by requesting tracks.
|
|
||||||
///
|
|
||||||
/// This can be cloned to create handles.
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct Subscriber {
|
|
||||||
state: Watch<State>,
|
|
||||||
info: Arc<Info>,
|
|
||||||
_dropped: Arc<Dropped>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Subscriber {
|
|
||||||
fn new(state: Watch<State>, info: Arc<Info>) -> Self {
|
|
||||||
let _dropped = Arc::new(Dropped::new(state.clone()));
|
|
||||||
Self { state, info, _dropped }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get a track from the broadcast by name.
|
|
||||||
/// If the track does not exist, it will be created and potentially fufilled by the publisher (via Unknown).
|
|
||||||
/// Otherwise, it will return [CacheError::NotFound].
|
|
||||||
pub fn get_track(&self, name: &str) -> Result<track::Subscriber, CacheError> {
|
|
||||||
let state = self.state.lock();
|
|
||||||
if let Some(track) = state.get(name)? {
|
|
||||||
return Ok(track);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Request a new track if it does not exist.
|
|
||||||
state.into_mut().request(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Check if the broadcast is closed, either because the publisher was dropped or called [Publisher::close].
|
|
||||||
pub fn is_closed(&self) -> Option<CacheError> {
|
|
||||||
self.state.lock().closed.as_ref().err().cloned()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Wait until if the broadcast is closed, either because the publisher was dropped or called [Publisher::close].
|
|
||||||
pub async fn closed(&self) -> CacheError {
|
|
||||||
loop {
|
|
||||||
let notify = {
|
|
||||||
let state = self.state.lock();
|
|
||||||
if let Some(err) = state.closed.as_ref().err() {
|
|
||||||
return err.clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
state.changed()
|
|
||||||
};
|
|
||||||
|
|
||||||
notify.await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for Subscriber {
|
|
||||||
type Target = Info;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.info
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for Subscriber {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
f.debug_struct("Subscriber")
|
|
||||||
.field("state", &self.state)
|
|
||||||
.field("info", &self.info)
|
|
||||||
.finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// A handle that closes the broadcast when dropped:
|
|
||||||
// - when all Subscribers are dropped or
|
|
||||||
// - when Publisher and Unknown are dropped.
|
|
||||||
struct Dropped {
|
|
||||||
state: Watch<State>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Dropped {
|
|
||||||
fn new(state: Watch<State>) -> Self {
|
|
||||||
Self { state }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Drop for Dropped {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
self.state.lock_mut().close(CacheError::Closed).ok();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
51
moq-transport/src/cache/error.rs
vendored
51
moq-transport/src/cache/error.rs
vendored
@@ -1,51 +0,0 @@
|
|||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
use crate::MoqError;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Error)]
|
|
||||||
pub enum CacheError {
|
|
||||||
/// A clean termination, represented as error code 0.
|
|
||||||
/// This error is automatically used when publishers or subscribers are dropped without calling close.
|
|
||||||
#[error("closed")]
|
|
||||||
Closed,
|
|
||||||
|
|
||||||
/// An ANNOUNCE_RESET or SUBSCRIBE_RESET was sent by the publisher.
|
|
||||||
#[error("reset code={0:?}")]
|
|
||||||
Reset(u32),
|
|
||||||
|
|
||||||
/// An ANNOUNCE_STOP or SUBSCRIBE_STOP was sent by the subscriber.
|
|
||||||
#[error("stop")]
|
|
||||||
Stop,
|
|
||||||
|
|
||||||
/// The requested resource was not found.
|
|
||||||
#[error("not found")]
|
|
||||||
NotFound,
|
|
||||||
|
|
||||||
/// A resource already exists with that ID.
|
|
||||||
#[error("duplicate")]
|
|
||||||
Duplicate,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MoqError for CacheError {
|
|
||||||
/// An integer code that is sent over the wire.
|
|
||||||
fn code(&self) -> u32 {
|
|
||||||
match self {
|
|
||||||
Self::Closed => 0,
|
|
||||||
Self::Reset(code) => *code,
|
|
||||||
Self::Stop => 206,
|
|
||||||
Self::NotFound => 404,
|
|
||||||
Self::Duplicate => 409,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A reason that is sent over the wire.
|
|
||||||
fn reason(&self) -> String {
|
|
||||||
match self {
|
|
||||||
Self::Closed => "closed".to_owned(),
|
|
||||||
Self::Reset(code) => format!("reset code: {}", code),
|
|
||||||
Self::Stop => "stop".to_owned(),
|
|
||||||
Self::NotFound => "not found".to_owned(),
|
|
||||||
Self::Duplicate => "duplicate".to_owned(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
208
moq-transport/src/cache/fragment.rs
vendored
208
moq-transport/src/cache/fragment.rs
vendored
@@ -1,208 +0,0 @@
|
|||||||
//! A fragment is a stream of bytes with a header, split into a [Publisher] and [Subscriber] handle.
|
|
||||||
//!
|
|
||||||
//! A [Publisher] writes an ordered stream of bytes in chunks.
|
|
||||||
//! There's no framing, so these chunks can be of any size or position, and won't be maintained over the network.
|
|
||||||
//!
|
|
||||||
//! A [Subscriber] reads an ordered stream of bytes in chunks.
|
|
||||||
//! These chunks are returned directly from the QUIC connection, so they may be of any size or position.
|
|
||||||
//! You can clone the [Subscriber] and each will read a copy of of all future chunks. (fanout)
|
|
||||||
//!
|
|
||||||
//! The fragment is closed with [CacheError::Closed] when all publishers or subscribers are dropped.
|
|
||||||
use core::fmt;
|
|
||||||
use std::{ops::Deref, sync::Arc};
|
|
||||||
|
|
||||||
use crate::VarInt;
|
|
||||||
use bytes::Bytes;
|
|
||||||
|
|
||||||
use super::{CacheError, Watch};
|
|
||||||
|
|
||||||
/// Create a new segment with the given info.
|
|
||||||
pub fn new(info: Info) -> (Publisher, Subscriber) {
|
|
||||||
let state = Watch::new(State::default());
|
|
||||||
let info = Arc::new(info);
|
|
||||||
|
|
||||||
let publisher = Publisher::new(state.clone(), info.clone());
|
|
||||||
let subscriber = Subscriber::new(state, info);
|
|
||||||
|
|
||||||
(publisher, subscriber)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Static information about the segment.
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct Info {
|
|
||||||
// The sequence number of the fragment within the segment.
|
|
||||||
// NOTE: These may be received out of order or with gaps.
|
|
||||||
pub sequence: VarInt,
|
|
||||||
|
|
||||||
// The size of the fragment, optionally None if this is the last fragment in a segment.
|
|
||||||
// TODO enforce this size.
|
|
||||||
pub size: Option<usize>,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct State {
|
|
||||||
// The data that has been received thus far.
|
|
||||||
chunks: Vec<Bytes>,
|
|
||||||
|
|
||||||
// Set when the publisher is dropped.
|
|
||||||
closed: Result<(), CacheError>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl State {
|
|
||||||
pub fn close(&mut self, err: CacheError) -> Result<(), CacheError> {
|
|
||||||
self.closed.clone()?;
|
|
||||||
self.closed = Err(err);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for State {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
chunks: Vec::new(),
|
|
||||||
closed: Ok(()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for State {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
// We don't want to print out the contents, so summarize.
|
|
||||||
f.debug_struct("State").field("closed", &self.closed).finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Used to write data to a segment and notify subscribers.
|
|
||||||
pub struct Publisher {
|
|
||||||
// Mutable segment state.
|
|
||||||
state: Watch<State>,
|
|
||||||
|
|
||||||
// Immutable segment state.
|
|
||||||
info: Arc<Info>,
|
|
||||||
|
|
||||||
// Closes the segment when all Publishers are dropped.
|
|
||||||
_dropped: Arc<Dropped>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Publisher {
|
|
||||||
fn new(state: Watch<State>, info: Arc<Info>) -> Self {
|
|
||||||
let _dropped = Arc::new(Dropped::new(state.clone()));
|
|
||||||
Self { state, info, _dropped }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Write a new chunk of bytes.
|
|
||||||
pub fn chunk(&mut self, chunk: Bytes) -> Result<(), CacheError> {
|
|
||||||
let mut state = self.state.lock_mut();
|
|
||||||
state.closed.clone()?;
|
|
||||||
state.chunks.push(chunk);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Close the segment with an error.
|
|
||||||
pub fn close(self, err: CacheError) -> Result<(), CacheError> {
|
|
||||||
self.state.lock_mut().close(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for Publisher {
|
|
||||||
type Target = Info;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.info
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for Publisher {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
f.debug_struct("Publisher")
|
|
||||||
.field("state", &self.state)
|
|
||||||
.field("info", &self.info)
|
|
||||||
.finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Notified when a segment has new data available.
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct Subscriber {
|
|
||||||
// Modify the segment state.
|
|
||||||
state: Watch<State>,
|
|
||||||
|
|
||||||
// Immutable segment state.
|
|
||||||
info: Arc<Info>,
|
|
||||||
|
|
||||||
// The number of chunks that we've read.
|
|
||||||
// NOTE: Cloned subscribers inherit this index, but then run in parallel.
|
|
||||||
index: usize,
|
|
||||||
|
|
||||||
// Dropped when all Subscribers are dropped.
|
|
||||||
_dropped: Arc<Dropped>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Subscriber {
|
|
||||||
fn new(state: Watch<State>, info: Arc<Info>) -> Self {
|
|
||||||
let _dropped = Arc::new(Dropped::new(state.clone()));
|
|
||||||
|
|
||||||
Self {
|
|
||||||
state,
|
|
||||||
info,
|
|
||||||
index: 0,
|
|
||||||
_dropped,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Block until the next chunk of bytes is available.
|
|
||||||
pub async fn chunk(&mut self) -> Result<Option<Bytes>, CacheError> {
|
|
||||||
loop {
|
|
||||||
let notify = {
|
|
||||||
let state = self.state.lock();
|
|
||||||
if self.index < state.chunks.len() {
|
|
||||||
let chunk = state.chunks[self.index].clone();
|
|
||||||
self.index += 1;
|
|
||||||
return Ok(Some(chunk));
|
|
||||||
}
|
|
||||||
|
|
||||||
match &state.closed {
|
|
||||||
Err(CacheError::Closed) => return Ok(None),
|
|
||||||
Err(err) => return Err(err.clone()),
|
|
||||||
Ok(()) => state.changed(),
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
notify.await; // Try again when the state changes
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for Subscriber {
|
|
||||||
type Target = Info;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.info
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for Subscriber {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
f.debug_struct("Subscriber")
|
|
||||||
.field("state", &self.state)
|
|
||||||
.field("info", &self.info)
|
|
||||||
.field("index", &self.index)
|
|
||||||
.finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Dropped {
|
|
||||||
// Modify the segment state.
|
|
||||||
state: Watch<State>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Dropped {
|
|
||||||
fn new(state: Watch<State>) -> Self {
|
|
||||||
Self { state }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Drop for Dropped {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
self.state.lock_mut().close(CacheError::Closed).ok();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
21
moq-transport/src/cache/mod.rs
vendored
21
moq-transport/src/cache/mod.rs
vendored
@@ -1,21 +0,0 @@
|
|||||||
//! Allows a publisher to push updates, automatically caching and fanning it out to any subscribers.
|
|
||||||
//!
|
|
||||||
//! The hierarchy is: [broadcast] -> [track] -> [segment] -> [fragment] -> [Bytes](bytes::Bytes)
|
|
||||||
//!
|
|
||||||
//! The naming scheme doesn't match the spec because it's more strict, and bikeshedding of course:
|
|
||||||
//!
|
|
||||||
//! - [broadcast] is kinda like "track namespace"
|
|
||||||
//! - [track] is "track"
|
|
||||||
//! - [segment] is "group" but MUST use a single stream.
|
|
||||||
//! - [fragment] is "object" but MUST have the same properties as the segment.
|
|
||||||
|
|
||||||
pub mod broadcast;
|
|
||||||
mod error;
|
|
||||||
pub mod fragment;
|
|
||||||
pub mod segment;
|
|
||||||
pub mod track;
|
|
||||||
|
|
||||||
pub(crate) mod watch;
|
|
||||||
pub(crate) use watch::*;
|
|
||||||
|
|
||||||
pub use error::*;
|
|
||||||
226
moq-transport/src/cache/segment.rs
vendored
226
moq-transport/src/cache/segment.rs
vendored
@@ -1,226 +0,0 @@
|
|||||||
//! A segment is a stream of fragments with a header, split into a [Publisher] and [Subscriber] handle.
|
|
||||||
//!
|
|
||||||
//! A [Publisher] writes an ordered stream of fragments.
|
|
||||||
//! Each fragment can have a sequence number, allowing the subscriber to detect gaps fragments.
|
|
||||||
//!
|
|
||||||
//! A [Subscriber] reads an ordered stream of fragments.
|
|
||||||
//! The subscriber can be cloned, in which case each subscriber receives a copy of each fragment. (fanout)
|
|
||||||
//!
|
|
||||||
//! The segment is closed with [CacheError::Closed] when all publishers or subscribers are dropped.
|
|
||||||
use core::fmt;
|
|
||||||
use std::{ops::Deref, sync::Arc, time};
|
|
||||||
|
|
||||||
use crate::VarInt;
|
|
||||||
|
|
||||||
use super::{fragment, CacheError, Watch};
|
|
||||||
|
|
||||||
/// Create a new segment with the given info.
|
|
||||||
pub fn new(info: Info) -> (Publisher, Subscriber) {
|
|
||||||
let state = Watch::new(State::default());
|
|
||||||
let info = Arc::new(info);
|
|
||||||
|
|
||||||
let publisher = Publisher::new(state.clone(), info.clone());
|
|
||||||
let subscriber = Subscriber::new(state, info);
|
|
||||||
|
|
||||||
(publisher, subscriber)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Static information about the segment.
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct Info {
|
|
||||||
// The sequence number of the segment within the track.
|
|
||||||
// NOTE: These may be received out of order or with gaps.
|
|
||||||
pub sequence: VarInt,
|
|
||||||
|
|
||||||
// The priority of the segment within the BROADCAST.
|
|
||||||
pub priority: u32,
|
|
||||||
|
|
||||||
// Cache the segment for at most this long.
|
|
||||||
pub expires: Option<time::Duration>,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct State {
|
|
||||||
// The data that has been received thus far.
|
|
||||||
fragments: Vec<fragment::Subscriber>,
|
|
||||||
|
|
||||||
// Set when the publisher is dropped.
|
|
||||||
closed: Result<(), CacheError>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl State {
|
|
||||||
pub fn close(&mut self, err: CacheError) -> Result<(), CacheError> {
|
|
||||||
self.closed.clone()?;
|
|
||||||
self.closed = Err(err);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for State {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
fragments: Vec::new(),
|
|
||||||
closed: Ok(()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for State {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
f.debug_struct("State")
|
|
||||||
.field("fragments", &self.fragments)
|
|
||||||
.field("closed", &self.closed)
|
|
||||||
.finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Used to write data to a segment and notify subscribers.
|
|
||||||
pub struct Publisher {
|
|
||||||
// Mutable segment state.
|
|
||||||
state: Watch<State>,
|
|
||||||
|
|
||||||
// Immutable segment state.
|
|
||||||
info: Arc<Info>,
|
|
||||||
|
|
||||||
// Closes the segment when all Publishers are dropped.
|
|
||||||
_dropped: Arc<Dropped>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Publisher {
|
|
||||||
fn new(state: Watch<State>, info: Arc<Info>) -> Self {
|
|
||||||
let _dropped = Arc::new(Dropped::new(state.clone()));
|
|
||||||
Self { state, info, _dropped }
|
|
||||||
}
|
|
||||||
|
|
||||||
// Not public because it's a footgun.
|
|
||||||
pub(crate) fn push_fragment(
|
|
||||||
&mut self,
|
|
||||||
sequence: VarInt,
|
|
||||||
size: Option<usize>,
|
|
||||||
) -> Result<fragment::Publisher, CacheError> {
|
|
||||||
let (publisher, subscriber) = fragment::new(fragment::Info { sequence, size });
|
|
||||||
|
|
||||||
let mut state = self.state.lock_mut();
|
|
||||||
state.closed.clone()?;
|
|
||||||
state.fragments.push(subscriber);
|
|
||||||
Ok(publisher)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Write a fragment
|
|
||||||
pub fn fragment(&mut self, sequence: VarInt, size: usize) -> Result<fragment::Publisher, CacheError> {
|
|
||||||
self.push_fragment(sequence, Some(size))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Write the last fragment, which means size can be unknown.
|
|
||||||
pub fn final_fragment(mut self, sequence: VarInt) -> Result<fragment::Publisher, CacheError> {
|
|
||||||
self.push_fragment(sequence, None)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Close the segment with an error.
|
|
||||||
pub fn close(self, err: CacheError) -> Result<(), CacheError> {
|
|
||||||
self.state.lock_mut().close(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for Publisher {
|
|
||||||
type Target = Info;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.info
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for Publisher {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
f.debug_struct("Publisher")
|
|
||||||
.field("state", &self.state)
|
|
||||||
.field("info", &self.info)
|
|
||||||
.finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Notified when a segment has new data available.
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct Subscriber {
|
|
||||||
// Modify the segment state.
|
|
||||||
state: Watch<State>,
|
|
||||||
|
|
||||||
// Immutable segment state.
|
|
||||||
info: Arc<Info>,
|
|
||||||
|
|
||||||
// The number of chunks that we've read.
|
|
||||||
// NOTE: Cloned subscribers inherit this index, but then run in parallel.
|
|
||||||
index: usize,
|
|
||||||
|
|
||||||
// Dropped when all Subscribers are dropped.
|
|
||||||
_dropped: Arc<Dropped>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Subscriber {
|
|
||||||
fn new(state: Watch<State>, info: Arc<Info>) -> Self {
|
|
||||||
let _dropped = Arc::new(Dropped::new(state.clone()));
|
|
||||||
|
|
||||||
Self {
|
|
||||||
state,
|
|
||||||
info,
|
|
||||||
index: 0,
|
|
||||||
_dropped,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Block until the next chunk of bytes is available.
|
|
||||||
pub async fn fragment(&mut self) -> Result<Option<fragment::Subscriber>, CacheError> {
|
|
||||||
loop {
|
|
||||||
let notify = {
|
|
||||||
let state = self.state.lock();
|
|
||||||
if self.index < state.fragments.len() {
|
|
||||||
let fragment = state.fragments[self.index].clone();
|
|
||||||
self.index += 1;
|
|
||||||
return Ok(Some(fragment));
|
|
||||||
}
|
|
||||||
|
|
||||||
match &state.closed {
|
|
||||||
Err(CacheError::Closed) => return Ok(None),
|
|
||||||
Err(err) => return Err(err.clone()),
|
|
||||||
Ok(()) => state.changed(),
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
notify.await; // Try again when the state changes
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for Subscriber {
|
|
||||||
type Target = Info;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.info
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for Subscriber {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
f.debug_struct("Subscriber")
|
|
||||||
.field("state", &self.state)
|
|
||||||
.field("info", &self.info)
|
|
||||||
.field("index", &self.index)
|
|
||||||
.finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Dropped {
|
|
||||||
// Modify the segment state.
|
|
||||||
state: Watch<State>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Dropped {
|
|
||||||
fn new(state: Watch<State>) -> Self {
|
|
||||||
Self { state }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Drop for Dropped {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
self.state.lock_mut().close(CacheError::Closed).ok();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
337
moq-transport/src/cache/track.rs
vendored
337
moq-transport/src/cache/track.rs
vendored
@@ -1,337 +0,0 @@
|
|||||||
//! A track is a collection of semi-reliable and semi-ordered segments, split into a [Publisher] and [Subscriber] handle.
|
|
||||||
//!
|
|
||||||
//! A [Publisher] creates segments with a sequence number and priority.
|
|
||||||
//! The sequest number is used to determine the order of segments, while the priority is used to determine which segment to transmit first.
|
|
||||||
//! This may seem counter-intuitive, but is designed for live streaming where the newest segments may be higher priority.
|
|
||||||
//! A cloned [Publisher] can be used to create segments in parallel, but will error if a duplicate sequence number is used.
|
|
||||||
//!
|
|
||||||
//! A [Subscriber] may not receive all segments in order or at all.
|
|
||||||
//! These segments are meant to be transmitted over congested networks and the key to MoQ Tranport is to not block on them.
|
|
||||||
//! Segments will be cached for a potentially limited duration added to the unreliable nature.
|
|
||||||
//! A cloned [Subscriber] will receive a copy of all new segment going forward (fanout).
|
|
||||||
//!
|
|
||||||
//! The track is closed with [CacheError::Closed] when all publishers or subscribers are dropped.
|
|
||||||
|
|
||||||
use std::{collections::BinaryHeap, fmt, ops::Deref, sync::Arc, time};
|
|
||||||
|
|
||||||
use indexmap::IndexMap;
|
|
||||||
|
|
||||||
use super::{segment, CacheError, Watch};
|
|
||||||
use crate::VarInt;
|
|
||||||
|
|
||||||
/// Create a track with the given name.
|
|
||||||
pub fn new(name: &str) -> (Publisher, Subscriber) {
|
|
||||||
let state = Watch::new(State::default());
|
|
||||||
let info = Arc::new(Info { name: name.to_string() });
|
|
||||||
|
|
||||||
let publisher = Publisher::new(state.clone(), info.clone());
|
|
||||||
let subscriber = Subscriber::new(state, info);
|
|
||||||
|
|
||||||
(publisher, subscriber)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Static information about a track.
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct Info {
|
|
||||||
pub name: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct State {
|
|
||||||
// Store segments in received order so subscribers can detect changes.
|
|
||||||
// The key is the segment sequence, which could have gaps.
|
|
||||||
// A None value means the segment has expired.
|
|
||||||
lookup: IndexMap<VarInt, Option<segment::Subscriber>>,
|
|
||||||
|
|
||||||
// Store when segments will expire in a priority queue.
|
|
||||||
expires: BinaryHeap<SegmentExpiration>,
|
|
||||||
|
|
||||||
// The number of None entries removed from the start of the lookup.
|
|
||||||
pruned: usize,
|
|
||||||
|
|
||||||
// Set when the publisher is closed/dropped, or all subscribers are dropped.
|
|
||||||
closed: Result<(), CacheError>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl State {
|
|
||||||
pub fn close(&mut self, err: CacheError) -> Result<(), CacheError> {
|
|
||||||
self.closed.clone()?;
|
|
||||||
self.closed = Err(err);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn insert(&mut self, segment: segment::Subscriber) -> Result<(), CacheError> {
|
|
||||||
self.closed.clone()?;
|
|
||||||
|
|
||||||
let entry = match self.lookup.entry(segment.sequence) {
|
|
||||||
indexmap::map::Entry::Occupied(_entry) => return Err(CacheError::Duplicate),
|
|
||||||
indexmap::map::Entry::Vacant(entry) => entry,
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(expires) = segment.expires {
|
|
||||||
self.expires.push(SegmentExpiration {
|
|
||||||
sequence: segment.sequence,
|
|
||||||
expires: time::Instant::now() + expires,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
entry.insert(Some(segment));
|
|
||||||
|
|
||||||
// Expire any existing segments on insert.
|
|
||||||
// This means if you don't insert then you won't expire... but it's probably fine since the cache won't grow.
|
|
||||||
// TODO Use a timer to expire segments at the correct time instead
|
|
||||||
self.expire();
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try expiring any segments
|
|
||||||
pub fn expire(&mut self) {
|
|
||||||
let now = time::Instant::now();
|
|
||||||
while let Some(segment) = self.expires.peek() {
|
|
||||||
if segment.expires > now {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the entry to None while preserving the index.
|
|
||||||
match self.lookup.entry(segment.sequence) {
|
|
||||||
indexmap::map::Entry::Occupied(mut entry) => entry.insert(None),
|
|
||||||
indexmap::map::Entry::Vacant(_) => panic!("expired segment not found"),
|
|
||||||
};
|
|
||||||
|
|
||||||
self.expires.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove None entries from the start of the lookup.
|
|
||||||
while let Some((_, None)) = self.lookup.get_index(0) {
|
|
||||||
self.lookup.shift_remove_index(0);
|
|
||||||
self.pruned += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for State {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
lookup: Default::default(),
|
|
||||||
expires: Default::default(),
|
|
||||||
pruned: 0,
|
|
||||||
closed: Ok(()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for State {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
f.debug_struct("State")
|
|
||||||
.field("lookup", &self.lookup)
|
|
||||||
.field("pruned", &self.pruned)
|
|
||||||
.field("closed", &self.closed)
|
|
||||||
.finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates new segments for a track.
|
|
||||||
pub struct Publisher {
|
|
||||||
state: Watch<State>,
|
|
||||||
info: Arc<Info>,
|
|
||||||
_dropped: Arc<Dropped>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Publisher {
|
|
||||||
fn new(state: Watch<State>, info: Arc<Info>) -> Self {
|
|
||||||
let _dropped = Arc::new(Dropped::new(state.clone()));
|
|
||||||
Self { state, info, _dropped }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Insert a new segment.
|
|
||||||
pub fn insert_segment(&mut self, segment: segment::Subscriber) -> Result<(), CacheError> {
|
|
||||||
self.state.lock_mut().insert(segment)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create an insert a segment with the given info.
|
|
||||||
pub fn create_segment(&mut self, info: segment::Info) -> Result<segment::Publisher, CacheError> {
|
|
||||||
let (publisher, subscriber) = segment::new(info);
|
|
||||||
self.insert_segment(subscriber)?;
|
|
||||||
Ok(publisher)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Close the segment with an error.
|
|
||||||
pub fn close(self, err: CacheError) -> Result<(), CacheError> {
|
|
||||||
self.state.lock_mut().close(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for Publisher {
|
|
||||||
type Target = Info;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.info
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for Publisher {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
f.debug_struct("Publisher")
|
|
||||||
.field("state", &self.state)
|
|
||||||
.field("info", &self.info)
|
|
||||||
.finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Receives new segments for a track.
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct Subscriber {
|
|
||||||
state: Watch<State>,
|
|
||||||
info: Arc<Info>,
|
|
||||||
|
|
||||||
// The index of the next segment to return.
|
|
||||||
index: usize,
|
|
||||||
|
|
||||||
// If there are multiple segments to return, we put them in here to return them in priority order.
|
|
||||||
pending: BinaryHeap<SegmentPriority>,
|
|
||||||
|
|
||||||
// Dropped when all subscribers are dropped.
|
|
||||||
_dropped: Arc<Dropped>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Subscriber {
|
|
||||||
fn new(state: Watch<State>, info: Arc<Info>) -> Self {
|
|
||||||
let _dropped = Arc::new(Dropped::new(state.clone()));
|
|
||||||
Self {
|
|
||||||
state,
|
|
||||||
info,
|
|
||||||
index: 0,
|
|
||||||
pending: Default::default(),
|
|
||||||
_dropped,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Block until the next segment arrives
|
|
||||||
pub async fn segment(&mut self) -> Result<Option<segment::Subscriber>, CacheError> {
|
|
||||||
loop {
|
|
||||||
let notify = {
|
|
||||||
let state = self.state.lock();
|
|
||||||
|
|
||||||
// Get our adjusted index, which could be negative if we've removed more broadcasts than read.
|
|
||||||
let mut index = self.index.saturating_sub(state.pruned);
|
|
||||||
|
|
||||||
// Push all new segments into a priority queue.
|
|
||||||
while index < state.lookup.len() {
|
|
||||||
let (_, segment) = state.lookup.get_index(index).unwrap();
|
|
||||||
|
|
||||||
// Skip None values (expired segments).
|
|
||||||
// TODO These might actually be expired, so we should check the expiration time.
|
|
||||||
if let Some(segment) = segment {
|
|
||||||
self.pending.push(SegmentPriority(segment.clone()));
|
|
||||||
}
|
|
||||||
|
|
||||||
index += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.index = state.pruned + index;
|
|
||||||
|
|
||||||
// Return the higher priority segment.
|
|
||||||
if let Some(segment) = self.pending.pop() {
|
|
||||||
return Ok(Some(segment.0));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise check if we need to return an error.
|
|
||||||
match &state.closed {
|
|
||||||
Err(CacheError::Closed) => return Ok(None),
|
|
||||||
Err(err) => return Err(err.clone()),
|
|
||||||
Ok(()) => state.changed(),
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
notify.await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for Subscriber {
|
|
||||||
type Target = Info;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.info
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for Subscriber {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
f.debug_struct("Subscriber")
|
|
||||||
.field("state", &self.state)
|
|
||||||
.field("info", &self.info)
|
|
||||||
.field("index", &self.index)
|
|
||||||
.finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Closes the track on Drop.
|
|
||||||
struct Dropped {
|
|
||||||
state: Watch<State>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Dropped {
|
|
||||||
fn new(state: Watch<State>) -> Self {
|
|
||||||
Self { state }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Drop for Dropped {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
self.state.lock_mut().close(CacheError::Closed).ok();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Used to order segments by expiration time.
|
|
||||||
struct SegmentExpiration {
|
|
||||||
sequence: VarInt,
|
|
||||||
expires: time::Instant,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Ord for SegmentExpiration {
|
|
||||||
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
|
||||||
// Reverse order so the earliest expiration is at the top of the heap.
|
|
||||||
other.expires.cmp(&self.expires)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PartialOrd for SegmentExpiration {
|
|
||||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
|
||||||
Some(self.cmp(other))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PartialEq for SegmentExpiration {
|
|
||||||
fn eq(&self, other: &Self) -> bool {
|
|
||||||
self.expires == other.expires
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Eq for SegmentExpiration {}
|
|
||||||
|
|
||||||
// Used to order segments by priority
|
|
||||||
#[derive(Clone)]
|
|
||||||
struct SegmentPriority(pub segment::Subscriber);
|
|
||||||
|
|
||||||
impl Ord for SegmentPriority {
|
|
||||||
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
|
||||||
// Reverse order so the highest priority is at the top of the heap.
|
|
||||||
// TODO I let CodePilot generate this code so yolo
|
|
||||||
other.0.priority.cmp(&self.0.priority)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PartialOrd for SegmentPriority {
|
|
||||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
|
||||||
Some(self.cmp(other))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PartialEq for SegmentPriority {
|
|
||||||
fn eq(&self, other: &Self) -> bool {
|
|
||||||
self.0.priority == other.0.priority
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Eq for SegmentPriority {}
|
|
||||||
180
moq-transport/src/cache/watch.rs
vendored
180
moq-transport/src/cache/watch.rs
vendored
@@ -1,180 +0,0 @@
|
|||||||
use std::{
|
|
||||||
fmt,
|
|
||||||
future::Future,
|
|
||||||
ops::{Deref, DerefMut},
|
|
||||||
pin::Pin,
|
|
||||||
sync::{Arc, Mutex, MutexGuard},
|
|
||||||
task,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct State<T> {
|
|
||||||
value: T,
|
|
||||||
wakers: Vec<task::Waker>,
|
|
||||||
epoch: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> State<T> {
|
|
||||||
pub fn new(value: T) -> Self {
|
|
||||||
Self {
|
|
||||||
value,
|
|
||||||
wakers: Vec::new(),
|
|
||||||
epoch: 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn register(&mut self, waker: &task::Waker) {
|
|
||||||
self.wakers.retain(|existing| !existing.will_wake(waker));
|
|
||||||
self.wakers.push(waker.clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn notify(&mut self) {
|
|
||||||
self.epoch += 1;
|
|
||||||
for waker in self.wakers.drain(..) {
|
|
||||||
waker.wake();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Default> Default for State<T> {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new(T::default())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: fmt::Debug> fmt::Debug for State<T> {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
self.value.fmt(f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Watch<T> {
|
|
||||||
state: Arc<Mutex<State<T>>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Watch<T> {
|
|
||||||
pub fn new(initial: T) -> Self {
|
|
||||||
let state = Arc::new(Mutex::new(State::new(initial)));
|
|
||||||
Self { state }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn lock(&self) -> WatchRef<T> {
|
|
||||||
WatchRef {
|
|
||||||
state: self.state.clone(),
|
|
||||||
lock: self.state.lock().unwrap(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn lock_mut(&self) -> WatchMut<T> {
|
|
||||||
WatchMut {
|
|
||||||
lock: self.state.lock().unwrap(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Clone for Watch<T> {
|
|
||||||
fn clone(&self) -> Self {
|
|
||||||
Self {
|
|
||||||
state: self.state.clone(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Default> Default for Watch<T> {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new(T::default())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: fmt::Debug> fmt::Debug for Watch<T> {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
match self.state.try_lock() {
|
|
||||||
Ok(lock) => lock.value.fmt(f),
|
|
||||||
Err(_) => write!(f, "<locked>"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct WatchRef<'a, T> {
|
|
||||||
state: Arc<Mutex<State<T>>>,
|
|
||||||
lock: MutexGuard<'a, State<T>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, T> WatchRef<'a, T> {
|
|
||||||
// Release the lock and wait for a notification when next updated.
|
|
||||||
pub fn changed(self) -> WatchChanged<T> {
|
|
||||||
WatchChanged {
|
|
||||||
state: self.state,
|
|
||||||
epoch: self.lock.epoch,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Upgrade to a mutable references that automatically calls notify on drop.
|
|
||||||
pub fn into_mut(self) -> WatchMut<'a, T> {
|
|
||||||
WatchMut { lock: self.lock }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, T> Deref for WatchRef<'a, T> {
|
|
||||||
type Target = T;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.lock.value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, T: fmt::Debug> fmt::Debug for WatchRef<'a, T> {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
self.lock.fmt(f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct WatchMut<'a, T> {
|
|
||||||
lock: MutexGuard<'a, State<T>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, T> Deref for WatchMut<'a, T> {
|
|
||||||
type Target = T;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.lock.value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, T> DerefMut for WatchMut<'a, T> {
|
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
||||||
&mut self.lock.value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, T> Drop for WatchMut<'a, T> {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
self.lock.notify();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, T: fmt::Debug> fmt::Debug for WatchMut<'a, T> {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
self.lock.fmt(f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct WatchChanged<T> {
|
|
||||||
state: Arc<Mutex<State<T>>>,
|
|
||||||
epoch: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Future for WatchChanged<T> {
|
|
||||||
type Output = ();
|
|
||||||
|
|
||||||
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> task::Poll<Self::Output> {
|
|
||||||
// TODO is there an API we can make that doesn't drop this lock?
|
|
||||||
let mut state = self.state.lock().unwrap();
|
|
||||||
|
|
||||||
if state.epoch > self.epoch {
|
|
||||||
task::Poll::Ready(())
|
|
||||||
} else {
|
|
||||||
state.register(cx.waker());
|
|
||||||
task::Poll::Pending
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
use super::{BoundsExceeded, VarInt};
|
|
||||||
use std::{io, str};
|
|
||||||
|
|
||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
// I'm too lazy to add these trait bounds to every message type.
|
|
||||||
// TODO Use trait aliases when they're stable, or add these bounds to every method.
|
|
||||||
pub trait AsyncRead: tokio::io::AsyncRead + Unpin + Send {}
|
|
||||||
impl AsyncRead for webtransport_quinn::RecvStream {}
|
|
||||||
impl<T> AsyncRead for tokio::io::Take<&mut T> where T: AsyncRead {}
|
|
||||||
impl<T: AsRef<[u8]> + Unpin + Send> AsyncRead for io::Cursor<T> {}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
pub trait Decode: Sized {
|
|
||||||
async fn decode<R: AsyncRead>(r: &mut R) -> Result<Self, DecodeError>;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A decode error.
|
|
||||||
#[derive(Error, Debug)]
|
|
||||||
pub enum DecodeError {
|
|
||||||
#[error("unexpected end of buffer")]
|
|
||||||
UnexpectedEnd,
|
|
||||||
|
|
||||||
#[error("invalid string")]
|
|
||||||
InvalidString(#[from] str::Utf8Error),
|
|
||||||
|
|
||||||
#[error("invalid message: {0:?}")]
|
|
||||||
InvalidMessage(VarInt),
|
|
||||||
|
|
||||||
#[error("invalid role: {0:?}")]
|
|
||||||
InvalidRole(VarInt),
|
|
||||||
|
|
||||||
#[error("invalid subscribe location")]
|
|
||||||
InvalidSubscribeLocation,
|
|
||||||
|
|
||||||
#[error("varint bounds exceeded")]
|
|
||||||
BoundsExceeded(#[from] BoundsExceeded),
|
|
||||||
|
|
||||||
// TODO move these to ParamError
|
|
||||||
#[error("duplicate parameter")]
|
|
||||||
DupliateParameter,
|
|
||||||
|
|
||||||
#[error("missing parameter")]
|
|
||||||
MissingParameter,
|
|
||||||
|
|
||||||
#[error("invalid parameter")]
|
|
||||||
InvalidParameter,
|
|
||||||
|
|
||||||
#[error("io error: {0}")]
|
|
||||||
IoError(#[from] std::io::Error),
|
|
||||||
|
|
||||||
// Used to signal that the stream has ended.
|
|
||||||
#[error("no more messages")]
|
|
||||||
Final,
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
use super::BoundsExceeded;
|
|
||||||
|
|
||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
// I'm too lazy to add these trait bounds to every message type.
|
|
||||||
// TODO Use trait aliases when they're stable, or add these bounds to every method.
|
|
||||||
pub trait AsyncWrite: tokio::io::AsyncWrite + Unpin + Send {}
|
|
||||||
impl AsyncWrite for webtransport_quinn::SendStream {}
|
|
||||||
impl AsyncWrite for Vec<u8> {}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
pub trait Encode: Sized {
|
|
||||||
async fn encode<W: AsyncWrite>(&self, w: &mut W) -> Result<(), EncodeError>;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// An encode error.
|
|
||||||
#[derive(Error, Debug)]
|
|
||||||
pub enum EncodeError {
|
|
||||||
#[error("varint too large")]
|
|
||||||
BoundsExceeded(#[from] BoundsExceeded),
|
|
||||||
|
|
||||||
#[error("invalid value")]
|
|
||||||
InvalidValue,
|
|
||||||
|
|
||||||
#[error("i/o error: {0}")]
|
|
||||||
IoError(#[from] std::io::Error),
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
mod decode;
|
|
||||||
mod encode;
|
|
||||||
mod params;
|
|
||||||
mod string;
|
|
||||||
mod varint;
|
|
||||||
|
|
||||||
pub use decode::*;
|
|
||||||
pub use encode::*;
|
|
||||||
pub use params::*;
|
|
||||||
pub use string::*;
|
|
||||||
pub use varint::*;
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
use std::io::Cursor;
|
|
||||||
use std::{cmp::max, collections::HashMap};
|
|
||||||
|
|
||||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
|
||||||
|
|
||||||
use crate::coding::{AsyncRead, AsyncWrite, Decode, Encode};
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
coding::{DecodeError, EncodeError},
|
|
||||||
VarInt,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Default, Debug, Clone)]
|
|
||||||
pub struct Params(pub HashMap<VarInt, Vec<u8>>);
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl Decode for Params {
|
|
||||||
async fn decode<R: AsyncRead>(mut r: &mut R) -> Result<Self, DecodeError> {
|
|
||||||
let mut params = HashMap::new();
|
|
||||||
|
|
||||||
// I hate this shit so much; let me encode my role and get on with my life.
|
|
||||||
let count = VarInt::decode(r).await?;
|
|
||||||
for _ in 0..count.into_inner() {
|
|
||||||
let kind = VarInt::decode(r).await?;
|
|
||||||
if params.contains_key(&kind) {
|
|
||||||
return Err(DecodeError::DupliateParameter);
|
|
||||||
}
|
|
||||||
|
|
||||||
let size = VarInt::decode(r).await?;
|
|
||||||
|
|
||||||
// Don't allocate the entire requested size to avoid a possible attack
|
|
||||||
// Instead, we allocate up to 1024 and keep appending as we read further.
|
|
||||||
let mut pr = r.take(size.into_inner());
|
|
||||||
let mut buf = Vec::with_capacity(max(1024, pr.limit() as usize));
|
|
||||||
pr.read_to_end(&mut buf).await?;
|
|
||||||
params.insert(kind, buf);
|
|
||||||
|
|
||||||
r = pr.into_inner();
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(Params(params))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl Encode for Params {
|
|
||||||
async fn encode<W: AsyncWrite>(&self, w: &mut W) -> Result<(), EncodeError> {
|
|
||||||
VarInt::try_from(self.0.len())?.encode(w).await?;
|
|
||||||
|
|
||||||
for (kind, value) in self.0.iter() {
|
|
||||||
kind.encode(w).await?;
|
|
||||||
VarInt::try_from(value.len())?.encode(w).await?;
|
|
||||||
w.write_all(value).await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Params {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self::default()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn set<P: Encode>(&mut self, kind: VarInt, p: P) -> Result<(), EncodeError> {
|
|
||||||
let mut value = Vec::new();
|
|
||||||
p.encode(&mut value).await?;
|
|
||||||
self.0.insert(kind, value);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn has(&self, kind: VarInt) -> bool {
|
|
||||||
self.0.contains_key(&kind)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn get<P: Decode>(&mut self, kind: VarInt) -> Result<Option<P>, DecodeError> {
|
|
||||||
if let Some(value) = self.0.remove(&kind) {
|
|
||||||
let mut cursor = Cursor::new(value);
|
|
||||||
Ok(Some(P::decode(&mut cursor).await?))
|
|
||||||
} else {
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
use std::cmp::min;
|
|
||||||
|
|
||||||
use crate::coding::{AsyncRead, AsyncWrite};
|
|
||||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
|
||||||
|
|
||||||
use crate::VarInt;
|
|
||||||
|
|
||||||
use super::{Decode, DecodeError, Encode, EncodeError};
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl Encode for String {
|
|
||||||
async fn encode<W: AsyncWrite>(&self, w: &mut W) -> Result<(), EncodeError> {
|
|
||||||
let size = VarInt::try_from(self.len())?;
|
|
||||||
size.encode(w).await?;
|
|
||||||
w.write_all(self.as_ref()).await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl Decode for String {
|
|
||||||
/// Decode a string with a varint length prefix.
|
|
||||||
async fn decode<R: AsyncRead>(r: &mut R) -> Result<Self, DecodeError> {
|
|
||||||
let size = VarInt::decode(r).await?.into_inner();
|
|
||||||
let mut str = String::with_capacity(min(1024, size) as usize);
|
|
||||||
r.take(size).read_to_string(&mut str).await?;
|
|
||||||
Ok(str)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,232 +0,0 @@
|
|||||||
// Based on quinn-proto
|
|
||||||
// https://github.com/quinn-rs/quinn/blob/main/quinn-proto/src/varint.rs
|
|
||||||
// Licensed via Apache 2.0 and MIT
|
|
||||||
|
|
||||||
use std::convert::{TryFrom, TryInto};
|
|
||||||
use std::fmt;
|
|
||||||
|
|
||||||
use crate::coding::{AsyncRead, AsyncWrite};
|
|
||||||
use thiserror::Error;
|
|
||||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
|
||||||
|
|
||||||
use super::{Decode, DecodeError, Encode, EncodeError};
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Error)]
|
|
||||||
#[error("value out of range")]
|
|
||||||
pub struct BoundsExceeded;
|
|
||||||
|
|
||||||
/// An integer less than 2^62
|
|
||||||
///
|
|
||||||
/// Values of this type are suitable for encoding as QUIC variable-length integer.
|
|
||||||
// It would be neat if we could express to Rust that the top two bits are available for use as enum
|
|
||||||
// discriminants
|
|
||||||
#[derive(Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
|
||||||
pub struct VarInt(u64);
|
|
||||||
|
|
||||||
impl VarInt {
|
|
||||||
/// The largest possible value.
|
|
||||||
pub const MAX: Self = Self((1 << 62) - 1);
|
|
||||||
|
|
||||||
/// The smallest possible value.
|
|
||||||
pub const ZERO: Self = Self(0);
|
|
||||||
|
|
||||||
/// Construct a `VarInt` infallibly using the largest available type.
|
|
||||||
/// Larger values need to use `try_from` instead.
|
|
||||||
pub const fn from_u32(x: u32) -> Self {
|
|
||||||
Self(x as u64)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Extract the integer value
|
|
||||||
pub const fn into_inner(self) -> u64 {
|
|
||||||
self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<VarInt> for u64 {
|
|
||||||
fn from(x: VarInt) -> Self {
|
|
||||||
x.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<VarInt> for usize {
|
|
||||||
fn from(x: VarInt) -> Self {
|
|
||||||
x.0 as usize
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<VarInt> for u128 {
|
|
||||||
fn from(x: VarInt) -> Self {
|
|
||||||
x.0 as u128
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<u8> for VarInt {
|
|
||||||
fn from(x: u8) -> Self {
|
|
||||||
Self(x.into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<u16> for VarInt {
|
|
||||||
fn from(x: u16) -> Self {
|
|
||||||
Self(x.into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<u32> for VarInt {
|
|
||||||
fn from(x: u32) -> Self {
|
|
||||||
Self(x.into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<u64> for VarInt {
|
|
||||||
type Error = BoundsExceeded;
|
|
||||||
|
|
||||||
/// Succeeds iff `x` < 2^62
|
|
||||||
fn try_from(x: u64) -> Result<Self, BoundsExceeded> {
|
|
||||||
if x <= Self::MAX.into_inner() {
|
|
||||||
Ok(Self(x))
|
|
||||||
} else {
|
|
||||||
Err(BoundsExceeded)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<u128> for VarInt {
|
|
||||||
type Error = BoundsExceeded;
|
|
||||||
|
|
||||||
/// Succeeds iff `x` < 2^62
|
|
||||||
fn try_from(x: u128) -> Result<Self, BoundsExceeded> {
|
|
||||||
if x <= Self::MAX.into() {
|
|
||||||
Ok(Self(x as u64))
|
|
||||||
} else {
|
|
||||||
Err(BoundsExceeded)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<usize> for VarInt {
|
|
||||||
type Error = BoundsExceeded;
|
|
||||||
|
|
||||||
/// Succeeds iff `x` < 2^62
|
|
||||||
fn try_from(x: usize) -> Result<Self, BoundsExceeded> {
|
|
||||||
Self::try_from(x as u64)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<VarInt> for u32 {
|
|
||||||
type Error = BoundsExceeded;
|
|
||||||
|
|
||||||
/// Succeeds iff `x` < 2^32
|
|
||||||
fn try_from(x: VarInt) -> Result<Self, BoundsExceeded> {
|
|
||||||
if x.0 <= u32::MAX.into() {
|
|
||||||
Ok(x.0 as u32)
|
|
||||||
} else {
|
|
||||||
Err(BoundsExceeded)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<VarInt> for u16 {
|
|
||||||
type Error = BoundsExceeded;
|
|
||||||
|
|
||||||
/// Succeeds iff `x` < 2^16
|
|
||||||
fn try_from(x: VarInt) -> Result<Self, BoundsExceeded> {
|
|
||||||
if x.0 <= u16::MAX.into() {
|
|
||||||
Ok(x.0 as u16)
|
|
||||||
} else {
|
|
||||||
Err(BoundsExceeded)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<VarInt> for u8 {
|
|
||||||
type Error = BoundsExceeded;
|
|
||||||
|
|
||||||
/// Succeeds iff `x` < 2^8
|
|
||||||
fn try_from(x: VarInt) -> Result<Self, BoundsExceeded> {
|
|
||||||
if x.0 <= u8::MAX.into() {
|
|
||||||
Ok(x.0 as u8)
|
|
||||||
} else {
|
|
||||||
Err(BoundsExceeded)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for VarInt {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
self.0.fmt(f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for VarInt {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
self.0.fmt(f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl Decode for VarInt {
|
|
||||||
/// Decode a varint from the given reader.
|
|
||||||
async fn decode<R: AsyncRead>(r: &mut R) -> Result<Self, DecodeError> {
|
|
||||||
let b = r.read_u8().await?;
|
|
||||||
Self::decode_byte(b, r).await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl VarInt {
|
|
||||||
/// Decode a varint given the first byte, reading the rest as needed.
|
|
||||||
/// This is silly but useful for determining if the stream has ended.
|
|
||||||
pub async fn decode_byte<R: AsyncRead>(b: u8, r: &mut R) -> Result<Self, DecodeError> {
|
|
||||||
let tag = b >> 6;
|
|
||||||
|
|
||||||
let mut buf = [0u8; 8];
|
|
||||||
buf[0] = b & 0b0011_1111;
|
|
||||||
|
|
||||||
let x = match tag {
|
|
||||||
0b00 => u64::from(buf[0]),
|
|
||||||
0b01 => {
|
|
||||||
r.read_exact(buf[1..2].as_mut()).await?;
|
|
||||||
u64::from(u16::from_be_bytes(buf[..2].try_into().unwrap()))
|
|
||||||
}
|
|
||||||
0b10 => {
|
|
||||||
r.read_exact(buf[1..4].as_mut()).await?;
|
|
||||||
u64::from(u32::from_be_bytes(buf[..4].try_into().unwrap()))
|
|
||||||
}
|
|
||||||
0b11 => {
|
|
||||||
r.read_exact(buf[1..8].as_mut()).await?;
|
|
||||||
u64::from_be_bytes(buf)
|
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(Self(x))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl Encode for VarInt {
|
|
||||||
/// Encode a varint to the given writer.
|
|
||||||
async fn encode<W: AsyncWrite>(&self, w: &mut W) -> Result<(), EncodeError> {
|
|
||||||
let x = self.0;
|
|
||||||
if x < 2u64.pow(6) {
|
|
||||||
w.write_u8(x as u8).await?;
|
|
||||||
} else if x < 2u64.pow(14) {
|
|
||||||
w.write_u16(0b01 << 14 | x as u16).await?;
|
|
||||||
} else if x < 2u64.pow(30) {
|
|
||||||
w.write_u32(0b10 << 30 | x as u32).await?;
|
|
||||||
} else if x < 2u64.pow(62) {
|
|
||||||
w.write_u64(0b11 << 62 | x).await?;
|
|
||||||
} else {
|
|
||||||
unreachable!("malformed VarInt");
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is a fork of quinn::VarInt.
|
|
||||||
impl From<quinn::VarInt> for VarInt {
|
|
||||||
fn from(v: quinn::VarInt) -> Self {
|
|
||||||
Self(v.into_inner())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
pub trait MoqError {
|
|
||||||
/// An integer code that is sent over the wire.
|
|
||||||
fn code(&self) -> u32;
|
|
||||||
|
|
||||||
/// An optional reason sometimes sent over the wire.
|
|
||||||
fn reason(&self) -> String;
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
//! An implementation of the MoQ Transport protocol.
|
|
||||||
//!
|
|
||||||
//! MoQ Transport is a pub/sub protocol over QUIC.
|
|
||||||
//! While originally designed for live media, MoQ Transport is generic and can be used for other live applications.
|
|
||||||
//! The specification is a work in progress and will change.
|
|
||||||
//! See the [specification](https://datatracker.ietf.org/doc/draft-ietf-moq-transport/) and [github](https://github.com/moq-wg/moq-transport) for any updates.
|
|
||||||
//!
|
|
||||||
//! This implementation has some required extensions until the draft stablizes. See: [Extensions](crate::setup::Extensions)
|
|
||||||
mod coding;
|
|
||||||
mod error;
|
|
||||||
|
|
||||||
pub mod cache;
|
|
||||||
pub mod message;
|
|
||||||
pub mod session;
|
|
||||||
pub mod setup;
|
|
||||||
|
|
||||||
pub use coding::VarInt;
|
|
||||||
pub use error::MoqError;
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
use crate::coding::{Decode, DecodeError, Encode, EncodeError, Params};
|
|
||||||
|
|
||||||
use crate::coding::{AsyncRead, AsyncWrite};
|
|
||||||
use crate::setup::Extensions;
|
|
||||||
|
|
||||||
/// Sent by the publisher to announce the availability of a group of tracks.
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct Announce {
|
|
||||||
/// The track namespace
|
|
||||||
pub namespace: String,
|
|
||||||
|
|
||||||
/// Optional parameters
|
|
||||||
pub params: Params,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Announce {
|
|
||||||
pub async fn decode<R: AsyncRead>(r: &mut R, _ext: &Extensions) -> Result<Self, DecodeError> {
|
|
||||||
let namespace = String::decode(r).await?;
|
|
||||||
let params = Params::decode(r).await?;
|
|
||||||
|
|
||||||
Ok(Self { namespace, params })
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn encode<W: AsyncWrite>(&self, w: &mut W, _ext: &Extensions) -> Result<(), EncodeError> {
|
|
||||||
self.namespace.encode(w).await?;
|
|
||||||
self.params.encode(w).await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
use crate::{
|
|
||||||
coding::{AsyncRead, AsyncWrite, Decode, DecodeError, Encode, EncodeError},
|
|
||||||
setup::Extensions,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Sent by the subscriber to accept an Announce.
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct AnnounceOk {
|
|
||||||
// Echo back the namespace that was announced.
|
|
||||||
// TODO Propose using an ID to save bytes.
|
|
||||||
pub namespace: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AnnounceOk {
|
|
||||||
pub async fn decode<R: AsyncRead>(r: &mut R, _ext: &Extensions) -> Result<Self, DecodeError> {
|
|
||||||
let namespace = String::decode(r).await?;
|
|
||||||
Ok(Self { namespace })
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn encode<W: AsyncWrite>(&self, w: &mut W, _ext: &Extensions) -> Result<(), EncodeError> {
|
|
||||||
self.namespace.encode(w).await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
use crate::coding::{Decode, DecodeError, Encode, EncodeError, VarInt};
|
|
||||||
|
|
||||||
use crate::coding::{AsyncRead, AsyncWrite};
|
|
||||||
use crate::setup::Extensions;
|
|
||||||
|
|
||||||
/// Sent by the subscriber to reject an Announce.
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct AnnounceError {
|
|
||||||
// Echo back the namespace that was reset
|
|
||||||
pub namespace: String,
|
|
||||||
|
|
||||||
// An error code.
|
|
||||||
pub code: u32,
|
|
||||||
|
|
||||||
// An optional, human-readable reason.
|
|
||||||
pub reason: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AnnounceError {
|
|
||||||
pub async fn decode<R: AsyncRead>(r: &mut R, _ext: &Extensions) -> Result<Self, DecodeError> {
|
|
||||||
let namespace = String::decode(r).await?;
|
|
||||||
let code = VarInt::decode(r).await?.try_into()?;
|
|
||||||
let reason = String::decode(r).await?;
|
|
||||||
|
|
||||||
Ok(Self {
|
|
||||||
namespace,
|
|
||||||
code,
|
|
||||||
reason,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn encode<W: AsyncWrite>(&self, w: &mut W, _ext: &Extensions) -> Result<(), EncodeError> {
|
|
||||||
self.namespace.encode(w).await?;
|
|
||||||
VarInt::from_u32(self.code).encode(w).await?;
|
|
||||||
self.reason.encode(w).await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
use crate::coding::{Decode, DecodeError, Encode, EncodeError};
|
|
||||||
|
|
||||||
use crate::coding::{AsyncRead, AsyncWrite};
|
|
||||||
use crate::setup::Extensions;
|
|
||||||
|
|
||||||
/// Sent by the server to indicate that the client should connect to a different server.
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct GoAway {
|
|
||||||
pub url: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GoAway {
|
|
||||||
pub async fn decode<R: AsyncRead>(r: &mut R, _ext: &Extensions) -> Result<Self, DecodeError> {
|
|
||||||
let url = String::decode(r).await?;
|
|
||||||
Ok(Self { url })
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn encode<W: AsyncWrite>(&self, w: &mut W, _ext: &Extensions) -> Result<(), EncodeError> {
|
|
||||||
self.url.encode(w).await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,160 +0,0 @@
|
|||||||
//! Low-level message sent over the wire, as defined in the specification.
|
|
||||||
//!
|
|
||||||
//! All of these messages are sent over a bidirectional QUIC stream.
|
|
||||||
//! This introduces some head-of-line blocking but preserves ordering.
|
|
||||||
//! The only exception are OBJECT "messages", which are sent over dedicated QUIC streams.
|
|
||||||
//!
|
|
||||||
//! Messages sent by the publisher:
|
|
||||||
//! - [Announce]
|
|
||||||
//! - [Unannounce]
|
|
||||||
//! - [SubscribeOk]
|
|
||||||
//! - [SubscribeError]
|
|
||||||
//! - [SubscribeReset]
|
|
||||||
//! - [Object]
|
|
||||||
//!
|
|
||||||
//! Messages sent by the subscriber:
|
|
||||||
//! - [Subscribe]
|
|
||||||
//! - [Unsubscribe]
|
|
||||||
//! - [AnnounceOk]
|
|
||||||
//! - [AnnounceError]
|
|
||||||
//!
|
|
||||||
//! Example flow:
|
|
||||||
//! ```test
|
|
||||||
//! -> ANNOUNCE namespace="foo"
|
|
||||||
//! <- ANNOUNCE_OK namespace="foo"
|
|
||||||
//! <- SUBSCRIBE id=0 namespace="foo" name="bar"
|
|
||||||
//! -> SUBSCRIBE_OK id=0
|
|
||||||
//! -> OBJECT id=0 sequence=69 priority=4 expires=30
|
|
||||||
//! -> OBJECT id=0 sequence=70 priority=4 expires=30
|
|
||||||
//! -> OBJECT id=0 sequence=70 priority=4 expires=30
|
|
||||||
//! <- SUBSCRIBE_STOP id=0
|
|
||||||
//! -> SUBSCRIBE_RESET id=0 code=206 reason="closed by peer"
|
|
||||||
//! ```
|
|
||||||
mod announce;
|
|
||||||
mod announce_ok;
|
|
||||||
mod announce_reset;
|
|
||||||
mod go_away;
|
|
||||||
mod object;
|
|
||||||
mod subscribe;
|
|
||||||
mod subscribe_error;
|
|
||||||
mod subscribe_fin;
|
|
||||||
mod subscribe_ok;
|
|
||||||
mod subscribe_reset;
|
|
||||||
mod unannounce;
|
|
||||||
mod unsubscribe;
|
|
||||||
|
|
||||||
pub use announce::*;
|
|
||||||
pub use announce_ok::*;
|
|
||||||
pub use announce_reset::*;
|
|
||||||
pub use go_away::*;
|
|
||||||
pub use object::*;
|
|
||||||
pub use subscribe::*;
|
|
||||||
pub use subscribe_error::*;
|
|
||||||
pub use subscribe_fin::*;
|
|
||||||
pub use subscribe_ok::*;
|
|
||||||
pub use subscribe_reset::*;
|
|
||||||
pub use unannounce::*;
|
|
||||||
pub use unsubscribe::*;
|
|
||||||
|
|
||||||
use crate::coding::{Decode, DecodeError, Encode, EncodeError, VarInt};
|
|
||||||
|
|
||||||
use std::fmt;
|
|
||||||
|
|
||||||
use crate::coding::{AsyncRead, AsyncWrite};
|
|
||||||
use crate::setup::Extensions;
|
|
||||||
|
|
||||||
// Use a macro to generate the message types rather than copy-paste.
|
|
||||||
// This implements a decode/encode method that uses the specified type.
|
|
||||||
macro_rules! message_types {
|
|
||||||
{$($name:ident = $val:expr,)*} => {
|
|
||||||
/// All supported message types.
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub enum Message {
|
|
||||||
$($name($name)),*
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Message {
|
|
||||||
pub async fn decode<R: AsyncRead>(r: &mut R, ext: &Extensions) -> Result<Self, DecodeError> {
|
|
||||||
let t = VarInt::decode(r).await?;
|
|
||||||
|
|
||||||
match t.into_inner() {
|
|
||||||
$($val => {
|
|
||||||
let msg = $name::decode(r, ext).await?;
|
|
||||||
Ok(Self::$name(msg))
|
|
||||||
})*
|
|
||||||
_ => Err(DecodeError::InvalidMessage(t)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn encode<W: AsyncWrite>(&self, w: &mut W, ext: &Extensions) -> Result<(), EncodeError> {
|
|
||||||
match self {
|
|
||||||
$(Self::$name(ref m) => {
|
|
||||||
VarInt::from_u32($val).encode(w).await?;
|
|
||||||
m.encode(w, ext).await
|
|
||||||
},)*
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn id(&self) -> VarInt {
|
|
||||||
match self {
|
|
||||||
$(Self::$name(_) => {
|
|
||||||
VarInt::from_u32($val)
|
|
||||||
},)*
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn name(&self) -> &'static str {
|
|
||||||
match self {
|
|
||||||
$(Self::$name(_) => {
|
|
||||||
stringify!($name)
|
|
||||||
},)*
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$(impl From<$name> for Message {
|
|
||||||
fn from(m: $name) -> Self {
|
|
||||||
Message::$name(m)
|
|
||||||
}
|
|
||||||
})*
|
|
||||||
|
|
||||||
impl fmt::Debug for Message {
|
|
||||||
// Delegate to the message formatter
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
match self {
|
|
||||||
$(Self::$name(ref m) => m.fmt(f),)*
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Each message is prefixed with the given VarInt type.
|
|
||||||
message_types! {
|
|
||||||
// NOTE: Object and Setup are in other modules.
|
|
||||||
// Object = 0x0
|
|
||||||
// ObjectUnbounded = 0x2
|
|
||||||
// SetupClient = 0x40
|
|
||||||
// SetupServer = 0x41
|
|
||||||
|
|
||||||
// SUBSCRIBE family, sent by subscriber
|
|
||||||
Subscribe = 0x3,
|
|
||||||
Unsubscribe = 0xa,
|
|
||||||
|
|
||||||
// SUBSCRIBE family, sent by publisher
|
|
||||||
SubscribeOk = 0x4,
|
|
||||||
SubscribeError = 0x5,
|
|
||||||
SubscribeFin = 0xb,
|
|
||||||
SubscribeReset = 0xc,
|
|
||||||
|
|
||||||
// ANNOUNCE family, sent by publisher
|
|
||||||
Announce = 0x6,
|
|
||||||
Unannounce = 0x9,
|
|
||||||
|
|
||||||
// ANNOUNCE family, sent by subscriber
|
|
||||||
AnnounceOk = 0x7,
|
|
||||||
AnnounceError = 0x8,
|
|
||||||
|
|
||||||
// Misc
|
|
||||||
GoAway = 0x10,
|
|
||||||
}
|
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
use std::{io, time};
|
|
||||||
|
|
||||||
use tokio::io::AsyncReadExt;
|
|
||||||
|
|
||||||
use crate::coding::{AsyncRead, AsyncWrite};
|
|
||||||
use crate::coding::{Decode, DecodeError, Encode, EncodeError, VarInt};
|
|
||||||
use crate::setup;
|
|
||||||
|
|
||||||
/// Sent by the publisher as the header of each data stream.
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct Object {
|
|
||||||
// An ID for this track.
|
|
||||||
// Proposal: https://github.com/moq-wg/moq-transport/issues/209
|
|
||||||
pub track: VarInt,
|
|
||||||
|
|
||||||
// The sequence number within the track.
|
|
||||||
pub group: VarInt,
|
|
||||||
|
|
||||||
// The sequence number within the group.
|
|
||||||
pub sequence: VarInt,
|
|
||||||
|
|
||||||
// The priority, where **smaller** values are sent first.
|
|
||||||
pub priority: u32,
|
|
||||||
|
|
||||||
// Cache the object for at most this many seconds.
|
|
||||||
// Zero means never expire.
|
|
||||||
pub expires: Option<time::Duration>,
|
|
||||||
|
|
||||||
/// An optional size, allowing multiple OBJECTs on the same stream.
|
|
||||||
pub size: Option<VarInt>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Object {
|
|
||||||
pub async fn decode<R: AsyncRead>(r: &mut R, extensions: &setup::Extensions) -> Result<Self, DecodeError> {
|
|
||||||
// Try reading the first byte, returning a special error if the stream naturally ended.
|
|
||||||
let typ = match r.read_u8().await {
|
|
||||||
Ok(b) => VarInt::decode_byte(b, r).await?,
|
|
||||||
Err(e) if e.kind() == io::ErrorKind::UnexpectedEof => return Err(DecodeError::Final),
|
|
||||||
Err(e) => return Err(e.into()),
|
|
||||||
};
|
|
||||||
|
|
||||||
let size_present = match typ.into_inner() {
|
|
||||||
0 => false,
|
|
||||||
2 => true,
|
|
||||||
_ => return Err(DecodeError::InvalidMessage(typ)),
|
|
||||||
};
|
|
||||||
|
|
||||||
let track = VarInt::decode(r).await?;
|
|
||||||
let group = VarInt::decode(r).await?;
|
|
||||||
let sequence = VarInt::decode(r).await?;
|
|
||||||
let priority = VarInt::decode(r).await?.try_into()?;
|
|
||||||
|
|
||||||
let expires = match extensions.object_expires {
|
|
||||||
true => match VarInt::decode(r).await?.into_inner() {
|
|
||||||
0 => None,
|
|
||||||
secs => Some(time::Duration::from_secs(secs)),
|
|
||||||
},
|
|
||||||
false => None,
|
|
||||||
};
|
|
||||||
|
|
||||||
// The presence of the size field depends on the type.
|
|
||||||
let size = match size_present {
|
|
||||||
true => Some(VarInt::decode(r).await?),
|
|
||||||
false => None,
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(Self {
|
|
||||||
track,
|
|
||||||
group,
|
|
||||||
sequence,
|
|
||||||
priority,
|
|
||||||
expires,
|
|
||||||
size,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn encode<W: AsyncWrite>(&self, w: &mut W, extensions: &setup::Extensions) -> Result<(), EncodeError> {
|
|
||||||
// The kind changes based on the presence of the size.
|
|
||||||
let kind = match self.size {
|
|
||||||
Some(_) => VarInt::from_u32(2),
|
|
||||||
None => VarInt::ZERO,
|
|
||||||
};
|
|
||||||
|
|
||||||
kind.encode(w).await?;
|
|
||||||
self.track.encode(w).await?;
|
|
||||||
self.group.encode(w).await?;
|
|
||||||
self.sequence.encode(w).await?;
|
|
||||||
VarInt::from_u32(self.priority).encode(w).await?;
|
|
||||||
|
|
||||||
// Round up if there's any decimal points.
|
|
||||||
let expires = match self.expires {
|
|
||||||
None => 0,
|
|
||||||
Some(time::Duration::ZERO) => return Err(EncodeError::InvalidValue), // there's no way of expressing zero currently.
|
|
||||||
Some(expires) if expires.subsec_nanos() > 0 => expires.as_secs() + 1,
|
|
||||||
Some(expires) => expires.as_secs(),
|
|
||||||
};
|
|
||||||
|
|
||||||
if extensions.object_expires {
|
|
||||||
VarInt::try_from(expires)?.encode(w).await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(size) = self.size {
|
|
||||||
size.encode(w).await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,142 +0,0 @@
|
|||||||
use crate::coding::{Decode, DecodeError, Encode, EncodeError, Params, VarInt};
|
|
||||||
|
|
||||||
use crate::coding::{AsyncRead, AsyncWrite};
|
|
||||||
use crate::setup::Extensions;
|
|
||||||
|
|
||||||
/// Sent by the subscriber to request all future objects for the given track.
|
|
||||||
///
|
|
||||||
/// Objects will use the provided ID instead of the full track name, to save bytes.
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct Subscribe {
|
|
||||||
/// An ID we choose so we can map to the track_name.
|
|
||||||
// Proposal: https://github.com/moq-wg/moq-transport/issues/209
|
|
||||||
pub id: VarInt,
|
|
||||||
|
|
||||||
/// The track namespace.
|
|
||||||
///
|
|
||||||
/// Must be None if `extensions.subscribe_split` is false.
|
|
||||||
pub namespace: Option<String>,
|
|
||||||
|
|
||||||
/// The track name.
|
|
||||||
pub name: String,
|
|
||||||
|
|
||||||
/// The start/end group/object.
|
|
||||||
pub start_group: SubscribeLocation,
|
|
||||||
pub start_object: SubscribeLocation,
|
|
||||||
pub end_group: SubscribeLocation,
|
|
||||||
pub end_object: SubscribeLocation,
|
|
||||||
|
|
||||||
/// Optional parameters
|
|
||||||
pub params: Params,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Subscribe {
|
|
||||||
pub async fn decode<R: AsyncRead>(r: &mut R, ext: &Extensions) -> Result<Self, DecodeError> {
|
|
||||||
let id = VarInt::decode(r).await?;
|
|
||||||
|
|
||||||
let namespace = match ext.subscribe_split {
|
|
||||||
true => Some(String::decode(r).await?),
|
|
||||||
false => None,
|
|
||||||
};
|
|
||||||
|
|
||||||
let name = String::decode(r).await?;
|
|
||||||
|
|
||||||
let start_group = SubscribeLocation::decode(r).await?;
|
|
||||||
let start_object = SubscribeLocation::decode(r).await?;
|
|
||||||
let end_group = SubscribeLocation::decode(r).await?;
|
|
||||||
let end_object = SubscribeLocation::decode(r).await?;
|
|
||||||
|
|
||||||
// You can't have a start object without a start group.
|
|
||||||
if start_group == SubscribeLocation::None && start_object != SubscribeLocation::None {
|
|
||||||
return Err(DecodeError::InvalidSubscribeLocation);
|
|
||||||
}
|
|
||||||
|
|
||||||
// You can't have an end object without an end group.
|
|
||||||
if end_group == SubscribeLocation::None && end_object != SubscribeLocation::None {
|
|
||||||
return Err(DecodeError::InvalidSubscribeLocation);
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: There's some more location restrictions in the draft, but they're enforced at a higher level.
|
|
||||||
|
|
||||||
let params = Params::decode(r).await?;
|
|
||||||
|
|
||||||
Ok(Self {
|
|
||||||
id,
|
|
||||||
namespace,
|
|
||||||
name,
|
|
||||||
start_group,
|
|
||||||
start_object,
|
|
||||||
end_group,
|
|
||||||
end_object,
|
|
||||||
params,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn encode<W: AsyncWrite>(&self, w: &mut W, ext: &Extensions) -> Result<(), EncodeError> {
|
|
||||||
self.id.encode(w).await?;
|
|
||||||
|
|
||||||
if self.namespace.is_some() != ext.subscribe_split {
|
|
||||||
panic!("namespace must be None if subscribe_split is false");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ext.subscribe_split {
|
|
||||||
self.namespace.as_ref().unwrap().encode(w).await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.name.encode(w).await?;
|
|
||||||
|
|
||||||
self.start_group.encode(w).await?;
|
|
||||||
self.start_object.encode(w).await?;
|
|
||||||
self.end_group.encode(w).await?;
|
|
||||||
self.end_object.encode(w).await?;
|
|
||||||
|
|
||||||
self.params.encode(w).await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Signal where the subscription should begin, relative to the current cache.
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
|
||||||
pub enum SubscribeLocation {
|
|
||||||
None,
|
|
||||||
Absolute(VarInt),
|
|
||||||
Latest(VarInt),
|
|
||||||
Future(VarInt),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SubscribeLocation {
|
|
||||||
pub async fn decode<R: AsyncRead>(r: &mut R) -> Result<Self, DecodeError> {
|
|
||||||
let kind = VarInt::decode(r).await?;
|
|
||||||
|
|
||||||
match kind.into_inner() {
|
|
||||||
0 => Ok(Self::None),
|
|
||||||
1 => Ok(Self::Absolute(VarInt::decode(r).await?)),
|
|
||||||
2 => Ok(Self::Latest(VarInt::decode(r).await?)),
|
|
||||||
3 => Ok(Self::Future(VarInt::decode(r).await?)),
|
|
||||||
_ => Err(DecodeError::InvalidSubscribeLocation),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn encode<W: AsyncWrite>(&self, w: &mut W) -> Result<(), EncodeError> {
|
|
||||||
match self {
|
|
||||||
Self::None => {
|
|
||||||
VarInt::from_u32(0).encode(w).await?;
|
|
||||||
}
|
|
||||||
Self::Absolute(val) => {
|
|
||||||
VarInt::from_u32(1).encode(w).await?;
|
|
||||||
val.encode(w).await?;
|
|
||||||
}
|
|
||||||
Self::Latest(val) => {
|
|
||||||
VarInt::from_u32(2).encode(w).await?;
|
|
||||||
val.encode(w).await?;
|
|
||||||
}
|
|
||||||
Self::Future(val) => {
|
|
||||||
VarInt::from_u32(3).encode(w).await?;
|
|
||||||
val.encode(w).await?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
use crate::coding::{AsyncRead, AsyncWrite};
|
|
||||||
use crate::coding::{Decode, DecodeError, Encode, EncodeError, VarInt};
|
|
||||||
use crate::setup::Extensions;
|
|
||||||
|
|
||||||
/// Sent by the publisher to reject a Subscribe.
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct SubscribeError {
|
|
||||||
// NOTE: No full track name because of this proposal: https://github.com/moq-wg/moq-transport/issues/209
|
|
||||||
|
|
||||||
// The ID for this subscription.
|
|
||||||
pub id: VarInt,
|
|
||||||
|
|
||||||
// An error code.
|
|
||||||
pub code: u32,
|
|
||||||
|
|
||||||
// An optional, human-readable reason.
|
|
||||||
pub reason: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SubscribeError {
|
|
||||||
pub async fn decode<R: AsyncRead>(r: &mut R, _ext: &Extensions) -> Result<Self, DecodeError> {
|
|
||||||
let id = VarInt::decode(r).await?;
|
|
||||||
let code = VarInt::decode(r).await?.try_into()?;
|
|
||||||
let reason = String::decode(r).await?;
|
|
||||||
|
|
||||||
Ok(Self { id, code, reason })
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn encode<W: AsyncWrite>(&self, w: &mut W, _ext: &Extensions) -> Result<(), EncodeError> {
|
|
||||||
self.id.encode(w).await?;
|
|
||||||
VarInt::from_u32(self.code).encode(w).await?;
|
|
||||||
self.reason.encode(w).await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
use crate::coding::{AsyncRead, AsyncWrite};
|
|
||||||
use crate::coding::{Decode, DecodeError, Encode, EncodeError, VarInt};
|
|
||||||
use crate::setup::Extensions;
|
|
||||||
|
|
||||||
/// Sent by the publisher to cleanly terminate a Subscribe.
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct SubscribeFin {
|
|
||||||
// NOTE: No full track name because of this proposal: https://github.com/moq-wg/moq-transport/issues/209
|
|
||||||
/// The ID for this subscription.
|
|
||||||
pub id: VarInt,
|
|
||||||
|
|
||||||
/// The final group/object sent on this subscription.
|
|
||||||
pub final_group: VarInt,
|
|
||||||
pub final_object: VarInt,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SubscribeFin {
|
|
||||||
pub async fn decode<R: AsyncRead>(r: &mut R, _ext: &Extensions) -> Result<Self, DecodeError> {
|
|
||||||
let id = VarInt::decode(r).await?;
|
|
||||||
let final_group = VarInt::decode(r).await?;
|
|
||||||
let final_object = VarInt::decode(r).await?;
|
|
||||||
|
|
||||||
Ok(Self {
|
|
||||||
id,
|
|
||||||
final_group,
|
|
||||||
final_object,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn encode<W: AsyncWrite>(&self, w: &mut W, _ext: &Extensions) -> Result<(), EncodeError> {
|
|
||||||
self.id.encode(w).await?;
|
|
||||||
self.final_group.encode(w).await?;
|
|
||||||
self.final_object.encode(w).await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
use crate::coding::{Decode, DecodeError, Encode, EncodeError, VarInt};
|
|
||||||
|
|
||||||
use crate::coding::{AsyncRead, AsyncWrite};
|
|
||||||
use crate::setup::Extensions;
|
|
||||||
|
|
||||||
/// Sent by the publisher to accept a Subscribe.
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct SubscribeOk {
|
|
||||||
// NOTE: No full track name because of this proposal: https://github.com/moq-wg/moq-transport/issues/209
|
|
||||||
/// The ID for this track.
|
|
||||||
pub id: VarInt,
|
|
||||||
|
|
||||||
/// The subscription will expire in this many milliseconds.
|
|
||||||
pub expires: VarInt,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SubscribeOk {
|
|
||||||
pub async fn decode<R: AsyncRead>(r: &mut R, _ext: &Extensions) -> Result<Self, DecodeError> {
|
|
||||||
let id = VarInt::decode(r).await?;
|
|
||||||
let expires = VarInt::decode(r).await?;
|
|
||||||
Ok(Self { id, expires })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SubscribeOk {
|
|
||||||
pub async fn encode<W: AsyncWrite>(&self, w: &mut W, _ext: &Extensions) -> Result<(), EncodeError> {
|
|
||||||
self.id.encode(w).await?;
|
|
||||||
self.expires.encode(w).await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
use crate::coding::{AsyncRead, AsyncWrite};
|
|
||||||
use crate::coding::{Decode, DecodeError, Encode, EncodeError, VarInt};
|
|
||||||
use crate::setup::Extensions;
|
|
||||||
|
|
||||||
/// Sent by the publisher to terminate a Subscribe.
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct SubscribeReset {
|
|
||||||
// NOTE: No full track name because of this proposal: https://github.com/moq-wg/moq-transport/issues/209
|
|
||||||
/// The ID for this subscription.
|
|
||||||
pub id: VarInt,
|
|
||||||
|
|
||||||
/// An error code.
|
|
||||||
pub code: u32,
|
|
||||||
|
|
||||||
/// An optional, human-readable reason.
|
|
||||||
pub reason: String,
|
|
||||||
|
|
||||||
/// The final group/object sent on this subscription.
|
|
||||||
pub final_group: VarInt,
|
|
||||||
pub final_object: VarInt,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SubscribeReset {
|
|
||||||
pub async fn decode<R: AsyncRead>(r: &mut R, _ext: &Extensions) -> Result<Self, DecodeError> {
|
|
||||||
let id = VarInt::decode(r).await?;
|
|
||||||
let code = VarInt::decode(r).await?.try_into()?;
|
|
||||||
let reason = String::decode(r).await?;
|
|
||||||
let final_group = VarInt::decode(r).await?;
|
|
||||||
let final_object = VarInt::decode(r).await?;
|
|
||||||
|
|
||||||
Ok(Self {
|
|
||||||
id,
|
|
||||||
code,
|
|
||||||
reason,
|
|
||||||
final_group,
|
|
||||||
final_object,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn encode<W: AsyncWrite>(&self, w: &mut W, _ext: &Extensions) -> Result<(), EncodeError> {
|
|
||||||
self.id.encode(w).await?;
|
|
||||||
VarInt::from_u32(self.code).encode(w).await?;
|
|
||||||
self.reason.encode(w).await?;
|
|
||||||
|
|
||||||
self.final_group.encode(w).await?;
|
|
||||||
self.final_object.encode(w).await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
use crate::coding::{Decode, DecodeError, Encode, EncodeError};
|
|
||||||
|
|
||||||
use crate::coding::{AsyncRead, AsyncWrite};
|
|
||||||
use crate::setup::Extensions;
|
|
||||||
|
|
||||||
/// Sent by the publisher to terminate an Announce.
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct Unannounce {
|
|
||||||
// Echo back the namespace that was reset
|
|
||||||
pub namespace: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Unannounce {
|
|
||||||
pub async fn decode<R: AsyncRead>(r: &mut R, _ext: &Extensions) -> Result<Self, DecodeError> {
|
|
||||||
let namespace = String::decode(r).await?;
|
|
||||||
|
|
||||||
Ok(Self { namespace })
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn encode<W: AsyncWrite>(&self, w: &mut W, _ext: &Extensions) -> Result<(), EncodeError> {
|
|
||||||
self.namespace.encode(w).await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
use crate::coding::{Decode, DecodeError, Encode, EncodeError, VarInt};
|
|
||||||
|
|
||||||
use crate::coding::{AsyncRead, AsyncWrite};
|
|
||||||
use crate::setup::Extensions;
|
|
||||||
|
|
||||||
/// Sent by the subscriber to terminate a Subscribe.
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct Unsubscribe {
|
|
||||||
// NOTE: No full track name because of this proposal: https://github.com/moq-wg/moq-transport/issues/209
|
|
||||||
|
|
||||||
// The ID for this subscription.
|
|
||||||
pub id: VarInt,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Unsubscribe {
|
|
||||||
pub async fn decode<R: AsyncRead>(r: &mut R, _ext: &Extensions) -> Result<Self, DecodeError> {
|
|
||||||
let id = VarInt::decode(r).await?;
|
|
||||||
Ok(Self { id })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Unsubscribe {
|
|
||||||
pub async fn encode<W: AsyncWrite>(&self, w: &mut W, _ext: &Extensions) -> Result<(), EncodeError> {
|
|
||||||
self.id.encode(w).await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
use super::{Control, Publisher, SessionError, Subscriber};
|
|
||||||
use crate::{cache::broadcast, setup};
|
|
||||||
use webtransport_quinn::Session;
|
|
||||||
|
|
||||||
/// An endpoint that connects to a URL to publish and/or consume live streams.
|
|
||||||
pub struct Client {}
|
|
||||||
|
|
||||||
impl Client {
|
|
||||||
/// Connect using an established WebTransport session, performing the MoQ handshake as a publisher.
|
|
||||||
pub async fn publisher(session: Session, source: broadcast::Subscriber) -> Result<Publisher, SessionError> {
|
|
||||||
let control = Self::send_setup(&session, setup::Role::Publisher).await?;
|
|
||||||
let publisher = Publisher::new(session, control, source);
|
|
||||||
Ok(publisher)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Connect using an established WebTransport session, performing the MoQ handshake as a subscriber.
|
|
||||||
pub async fn subscriber(session: Session, source: broadcast::Publisher) -> Result<Subscriber, SessionError> {
|
|
||||||
let control = Self::send_setup(&session, setup::Role::Subscriber).await?;
|
|
||||||
let subscriber = Subscriber::new(session, control, source);
|
|
||||||
Ok(subscriber)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO support performing both roles
|
|
||||||
/*
|
|
||||||
pub async fn connect(self) -> anyhow::Result<(Publisher, Subscriber)> {
|
|
||||||
self.connect_role(setup::Role::Both).await
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
async fn send_setup(session: &Session, role: setup::Role) -> Result<Control, SessionError> {
|
|
||||||
let mut control = session.open_bi().await?;
|
|
||||||
|
|
||||||
let versions: setup::Versions = [setup::Version::DRAFT_01, setup::Version::KIXEL_01].into();
|
|
||||||
|
|
||||||
let client = setup::Client {
|
|
||||||
role,
|
|
||||||
versions: versions.clone(),
|
|
||||||
params: Default::default(),
|
|
||||||
|
|
||||||
// Offer all extensions
|
|
||||||
extensions: setup::Extensions {
|
|
||||||
object_expires: true,
|
|
||||||
subscriber_id: true,
|
|
||||||
subscribe_split: true,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
log::debug!("sending client SETUP: {:?}", client);
|
|
||||||
client.encode(&mut control.0).await?;
|
|
||||||
|
|
||||||
let mut server = setup::Server::decode(&mut control.1).await?;
|
|
||||||
|
|
||||||
log::debug!("received server SETUP: {:?}", server);
|
|
||||||
|
|
||||||
match server.version {
|
|
||||||
setup::Version::DRAFT_01 => {
|
|
||||||
// We always require this extension
|
|
||||||
server.extensions.require_subscriber_id()?;
|
|
||||||
|
|
||||||
if server.role.is_publisher() {
|
|
||||||
// We only require object expires if we're a subscriber, so we don't cache objects indefinitely.
|
|
||||||
server.extensions.require_object_expires()?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setup::Version::KIXEL_01 => {
|
|
||||||
// KIXEL_01 didn't support extensions; all were enabled.
|
|
||||||
server.extensions = client.extensions.clone()
|
|
||||||
}
|
|
||||||
_ => return Err(SessionError::Version(versions, [server.version].into())),
|
|
||||||
}
|
|
||||||
|
|
||||||
let control = Control::new(control.0, control.1, server.extensions);
|
|
||||||
|
|
||||||
Ok(control)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
// A helper class to guard sending control messages behind a Mutex.
|
|
||||||
|
|
||||||
use std::{fmt, sync::Arc};
|
|
||||||
|
|
||||||
use tokio::sync::Mutex;
|
|
||||||
use webtransport_quinn::{RecvStream, SendStream};
|
|
||||||
|
|
||||||
use super::SessionError;
|
|
||||||
use crate::{message::Message, setup::Extensions};
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub(crate) struct Control {
|
|
||||||
send: Arc<Mutex<SendStream>>,
|
|
||||||
recv: Arc<Mutex<RecvStream>>,
|
|
||||||
pub ext: Extensions,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Control {
|
|
||||||
pub fn new(send: SendStream, recv: RecvStream, ext: Extensions) -> Self {
|
|
||||||
Self {
|
|
||||||
send: Arc::new(Mutex::new(send)),
|
|
||||||
recv: Arc::new(Mutex::new(recv)),
|
|
||||||
ext,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn send<T: Into<Message> + fmt::Debug>(&self, msg: T) -> Result<(), SessionError> {
|
|
||||||
let mut stream = self.send.lock().await;
|
|
||||||
log::info!("sending message: {:?}", msg);
|
|
||||||
msg.into()
|
|
||||||
.encode(&mut *stream, &self.ext)
|
|
||||||
.await
|
|
||||||
.map_err(|e| SessionError::Unknown(e.to_string()))?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
// It's likely a mistake to call this from two different tasks, but it's easier to just support it.
|
|
||||||
pub async fn recv(&self) -> Result<Message, SessionError> {
|
|
||||||
let mut stream = self.recv.lock().await;
|
|
||||||
let msg = Message::decode(&mut *stream, &self.ext)
|
|
||||||
.await
|
|
||||||
.map_err(|e| SessionError::Unknown(e.to_string()))?;
|
|
||||||
Ok(msg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
use crate::{cache, coding, setup, MoqError, VarInt};
|
|
||||||
|
|
||||||
#[derive(thiserror::Error, Debug)]
|
|
||||||
pub enum SessionError {
|
|
||||||
#[error("webtransport error: {0}")]
|
|
||||||
Session(#[from] webtransport_quinn::SessionError),
|
|
||||||
|
|
||||||
#[error("cache error: {0}")]
|
|
||||||
Cache(#[from] cache::CacheError),
|
|
||||||
|
|
||||||
#[error("encode error: {0}")]
|
|
||||||
Encode(#[from] coding::EncodeError),
|
|
||||||
|
|
||||||
#[error("decode error: {0}")]
|
|
||||||
Decode(#[from] coding::DecodeError),
|
|
||||||
|
|
||||||
#[error("unsupported versions: client={0:?} server={1:?}")]
|
|
||||||
Version(setup::Versions, setup::Versions),
|
|
||||||
|
|
||||||
#[error("incompatible roles: client={0:?} server={1:?}")]
|
|
||||||
RoleIncompatible(setup::Role, setup::Role),
|
|
||||||
|
|
||||||
/// An error occured while reading from the QUIC stream.
|
|
||||||
#[error("failed to read from stream: {0}")]
|
|
||||||
Read(#[from] webtransport_quinn::ReadError),
|
|
||||||
|
|
||||||
/// An error occured while writing to the QUIC stream.
|
|
||||||
#[error("failed to write to stream: {0}")]
|
|
||||||
Write(#[from] webtransport_quinn::WriteError),
|
|
||||||
|
|
||||||
/// The role negiotiated in the handshake was violated. For example, a publisher sent a SUBSCRIBE, or a subscriber sent an OBJECT.
|
|
||||||
#[error("role violation: msg={0}")]
|
|
||||||
RoleViolation(VarInt),
|
|
||||||
|
|
||||||
/// Our enforced stream mapping was disrespected.
|
|
||||||
#[error("stream mapping conflict")]
|
|
||||||
StreamMapping,
|
|
||||||
|
|
||||||
/// The priority was invalid.
|
|
||||||
#[error("invalid priority: {0}")]
|
|
||||||
InvalidPriority(VarInt),
|
|
||||||
|
|
||||||
/// The size was invalid.
|
|
||||||
#[error("invalid size: {0}")]
|
|
||||||
InvalidSize(VarInt),
|
|
||||||
|
|
||||||
/// A required extension was not offered.
|
|
||||||
#[error("required extension not offered: {0:?}")]
|
|
||||||
RequiredExtension(VarInt),
|
|
||||||
|
|
||||||
/// Some VarInt was too large and we were too lazy to handle it
|
|
||||||
#[error("varint bounds exceeded")]
|
|
||||||
BoundsExceeded(#[from] coding::BoundsExceeded),
|
|
||||||
|
|
||||||
/// An unclassified error because I'm lazy. TODO classify these errors
|
|
||||||
#[error("unknown error: {0}")]
|
|
||||||
Unknown(String),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MoqError for SessionError {
|
|
||||||
/// An integer code that is sent over the wire.
|
|
||||||
fn code(&self) -> u32 {
|
|
||||||
match self {
|
|
||||||
Self::Cache(err) => err.code(),
|
|
||||||
Self::RoleIncompatible(..) => 406,
|
|
||||||
Self::RoleViolation(..) => 405,
|
|
||||||
Self::StreamMapping => 409,
|
|
||||||
Self::Unknown(_) => 500,
|
|
||||||
Self::Write(_) => 501,
|
|
||||||
Self::Read(_) => 502,
|
|
||||||
Self::Session(_) => 503,
|
|
||||||
Self::Version(..) => 406,
|
|
||||||
Self::Encode(_) => 500,
|
|
||||||
Self::Decode(_) => 500,
|
|
||||||
Self::InvalidPriority(_) => 400,
|
|
||||||
Self::InvalidSize(_) => 400,
|
|
||||||
Self::RequiredExtension(_) => 426,
|
|
||||||
Self::BoundsExceeded(_) => 500,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A reason that is sent over the wire.
|
|
||||||
fn reason(&self) -> String {
|
|
||||||
match self {
|
|
||||||
Self::Cache(err) => err.reason(),
|
|
||||||
Self::RoleViolation(kind) => format!("role violation for message type {:?}", kind),
|
|
||||||
Self::RoleIncompatible(client, server) => {
|
|
||||||
format!(
|
|
||||||
"role incompatible: client wanted {:?} but server wanted {:?}",
|
|
||||||
client, server
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Self::Read(err) => format!("read error: {}", err),
|
|
||||||
Self::Write(err) => format!("write error: {}", err),
|
|
||||||
Self::Session(err) => format!("session error: {}", err),
|
|
||||||
Self::Unknown(err) => format!("unknown error: {}", err),
|
|
||||||
Self::Version(client, server) => format!("unsupported versions: client={:?} server={:?}", client, server),
|
|
||||||
Self::Encode(err) => format!("encode error: {}", err),
|
|
||||||
Self::Decode(err) => format!("decode error: {}", err),
|
|
||||||
Self::StreamMapping => "streaming mapping conflict".to_owned(),
|
|
||||||
Self::InvalidPriority(priority) => format!("invalid priority: {}", priority),
|
|
||||||
Self::InvalidSize(size) => format!("invalid size: {}", size),
|
|
||||||
Self::RequiredExtension(id) => format!("required extension was missing: {:?}", id),
|
|
||||||
Self::BoundsExceeded(_) => "varint bounds exceeded".to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
//! A MoQ Transport session, on top of a WebTransport session, on top of a QUIC connection.
|
|
||||||
//!
|
|
||||||
//! The handshake is relatively simple but split into different steps.
|
|
||||||
//! All of these handshakes slightly differ depending on if the endpoint is a client or server.
|
|
||||||
//! 1. Complete the QUIC handhake.
|
|
||||||
//! 2. Complete the WebTransport handshake.
|
|
||||||
//! 3. Complete the MoQ handshake.
|
|
||||||
//!
|
|
||||||
//! Use [Client] or [Server] for the MoQ handshake depending on the endpoint.
|
|
||||||
//! Then, decide if you want to create a [Publisher] or [Subscriber], or both (TODO).
|
|
||||||
//!
|
|
||||||
//! A [Publisher] can announce broadcasts, which will automatically be served over the network.
|
|
||||||
//! A [Subscriber] can subscribe to broadcasts, which will automatically be served over the network.
|
|
||||||
|
|
||||||
mod client;
|
|
||||||
mod control;
|
|
||||||
mod error;
|
|
||||||
mod publisher;
|
|
||||||
mod server;
|
|
||||||
mod subscriber;
|
|
||||||
|
|
||||||
pub use client::*;
|
|
||||||
pub(crate) use control::*;
|
|
||||||
pub use error::*;
|
|
||||||
pub use publisher::*;
|
|
||||||
pub use server::*;
|
|
||||||
pub use subscriber::*;
|
|
||||||
@@ -1,237 +0,0 @@
|
|||||||
use std::{
|
|
||||||
collections::{hash_map, HashMap},
|
|
||||||
sync::{Arc, Mutex},
|
|
||||||
};
|
|
||||||
|
|
||||||
use tokio::task::AbortHandle;
|
|
||||||
use webtransport_quinn::Session;
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
cache::{broadcast, segment, track, CacheError},
|
|
||||||
message,
|
|
||||||
message::Message,
|
|
||||||
MoqError, VarInt,
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::{Control, SessionError};
|
|
||||||
|
|
||||||
/// Serves broadcasts over the network, automatically handling subscriptions and caching.
|
|
||||||
// TODO Clone specific fields when a task actually needs it.
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct Publisher {
|
|
||||||
// A map of active subscriptions, containing an abort handle to cancel them.
|
|
||||||
subscribes: Arc<Mutex<HashMap<VarInt, AbortHandle>>>,
|
|
||||||
webtransport: Session,
|
|
||||||
control: Control,
|
|
||||||
source: broadcast::Subscriber,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Publisher {
|
|
||||||
pub(crate) fn new(webtransport: Session, control: Control, source: broadcast::Subscriber) -> Self {
|
|
||||||
Self {
|
|
||||||
webtransport,
|
|
||||||
control,
|
|
||||||
subscribes: Default::default(),
|
|
||||||
source,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO Serve a broadcast without sending an ANNOUNCE.
|
|
||||||
// fn serve(&mut self, broadcast: broadcast::Subscriber) -> Result<(), SessionError> {
|
|
||||||
|
|
||||||
// TODO Wait until the next subscribe that doesn't route to an ANNOUNCE.
|
|
||||||
// pub async fn subscribed(&mut self) -> Result<track::Producer, SessionError> {
|
|
||||||
|
|
||||||
pub async fn run(mut self) -> Result<(), SessionError> {
|
|
||||||
let res = self.run_inner().await;
|
|
||||||
|
|
||||||
// Terminate all active subscribes on error.
|
|
||||||
self.subscribes
|
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.drain()
|
|
||||||
.for_each(|(_, abort)| abort.abort());
|
|
||||||
|
|
||||||
res
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn run_inner(&mut self) -> Result<(), SessionError> {
|
|
||||||
loop {
|
|
||||||
tokio::select! {
|
|
||||||
stream = self.webtransport.accept_uni() => {
|
|
||||||
stream?;
|
|
||||||
return Err(SessionError::RoleViolation(VarInt::ZERO));
|
|
||||||
}
|
|
||||||
// NOTE: this is not cancel safe, but it's fine since the other branchs are fatal.
|
|
||||||
msg = self.control.recv() => {
|
|
||||||
let msg = msg?;
|
|
||||||
|
|
||||||
log::info!("message received: {:?}", msg);
|
|
||||||
if let Err(err) = self.recv_message(&msg).await {
|
|
||||||
log::warn!("message error: {:?} {:?}", err, msg);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// No more broadcasts are available.
|
|
||||||
err = self.source.closed() => {
|
|
||||||
self.webtransport.close(err.code(), err.reason().as_bytes());
|
|
||||||
return Ok(());
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn recv_message(&mut self, msg: &Message) -> Result<(), SessionError> {
|
|
||||||
match msg {
|
|
||||||
Message::AnnounceOk(msg) => self.recv_announce_ok(msg).await,
|
|
||||||
Message::AnnounceError(msg) => self.recv_announce_error(msg).await,
|
|
||||||
Message::Subscribe(msg) => self.recv_subscribe(msg).await,
|
|
||||||
Message::Unsubscribe(msg) => self.recv_unsubscribe(msg).await,
|
|
||||||
_ => Err(SessionError::RoleViolation(msg.id())),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn recv_announce_ok(&mut self, _msg: &message::AnnounceOk) -> Result<(), SessionError> {
|
|
||||||
// We didn't send an announce.
|
|
||||||
Err(CacheError::NotFound.into())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn recv_announce_error(&mut self, _msg: &message::AnnounceError) -> Result<(), SessionError> {
|
|
||||||
// We didn't send an announce.
|
|
||||||
Err(CacheError::NotFound.into())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn recv_subscribe(&mut self, msg: &message::Subscribe) -> Result<(), SessionError> {
|
|
||||||
// Assume that the subscribe ID is unique for now.
|
|
||||||
let abort = match self.start_subscribe(msg.clone()) {
|
|
||||||
Ok(abort) => abort,
|
|
||||||
Err(err) => return self.reset_subscribe(msg.id, err).await,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Insert the abort handle into the lookup table.
|
|
||||||
match self.subscribes.lock().unwrap().entry(msg.id) {
|
|
||||||
hash_map::Entry::Occupied(_) => return Err(CacheError::Duplicate.into()), // TODO fatal, because we already started the task
|
|
||||||
hash_map::Entry::Vacant(entry) => entry.insert(abort),
|
|
||||||
};
|
|
||||||
|
|
||||||
self.control
|
|
||||||
.send(message::SubscribeOk {
|
|
||||||
id: msg.id,
|
|
||||||
expires: VarInt::ZERO,
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn reset_subscribe<E: MoqError>(&mut self, id: VarInt, err: E) -> Result<(), SessionError> {
|
|
||||||
let msg = message::SubscribeReset {
|
|
||||||
id,
|
|
||||||
code: err.code(),
|
|
||||||
reason: err.reason(),
|
|
||||||
|
|
||||||
// TODO properly populate these
|
|
||||||
// But first: https://github.com/moq-wg/moq-transport/issues/313
|
|
||||||
final_group: VarInt::ZERO,
|
|
||||||
final_object: VarInt::ZERO,
|
|
||||||
};
|
|
||||||
|
|
||||||
self.control.send(msg).await
|
|
||||||
}
|
|
||||||
|
|
||||||
fn start_subscribe(&mut self, msg: message::Subscribe) -> Result<AbortHandle, SessionError> {
|
|
||||||
// We currently don't use the namespace field in SUBSCRIBE
|
|
||||||
// Make sure the namespace is empty if it's provided.
|
|
||||||
if msg.namespace.as_ref().map_or(false, |namespace| !namespace.is_empty()) {
|
|
||||||
return Err(CacheError::NotFound.into());
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut track = self.source.get_track(&msg.name)?;
|
|
||||||
|
|
||||||
// TODO only clone the fields we need
|
|
||||||
let mut this = self.clone();
|
|
||||||
|
|
||||||
let handle = tokio::spawn(async move {
|
|
||||||
log::info!("serving track: name={}", track.name);
|
|
||||||
|
|
||||||
let res = this.run_subscribe(msg.id, &mut track).await;
|
|
||||||
if let Err(err) = &res {
|
|
||||||
log::warn!("failed to serve track: name={} err={:#?}", track.name, err);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure we send a reset at the end.
|
|
||||||
let err = res.err().unwrap_or(CacheError::Closed.into());
|
|
||||||
this.reset_subscribe(msg.id, err).await.ok();
|
|
||||||
|
|
||||||
// We're all done, so clean up the abort handle.
|
|
||||||
this.subscribes.lock().unwrap().remove(&msg.id);
|
|
||||||
});
|
|
||||||
|
|
||||||
Ok(handle.abort_handle())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn run_subscribe(&self, id: VarInt, track: &mut track::Subscriber) -> Result<(), SessionError> {
|
|
||||||
// TODO add an Ok method to track::Publisher so we can send SUBSCRIBE_OK
|
|
||||||
|
|
||||||
while let Some(mut segment) = track.segment().await? {
|
|
||||||
// TODO only clone the fields we need
|
|
||||||
let this = self.clone();
|
|
||||||
|
|
||||||
tokio::spawn(async move {
|
|
||||||
if let Err(err) = this.run_segment(id, &mut segment).await {
|
|
||||||
log::warn!("failed to serve segment: {:?}", err)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn run_segment(&self, id: VarInt, segment: &mut segment::Subscriber) -> Result<(), SessionError> {
|
|
||||||
log::trace!("serving group: {:?}", segment);
|
|
||||||
|
|
||||||
let mut stream = self.webtransport.open_uni().await?;
|
|
||||||
|
|
||||||
// Convert the u32 to a i32, since the Quinn set_priority is signed.
|
|
||||||
let priority = (segment.priority as i64 - i32::MAX as i64) as i32;
|
|
||||||
stream.set_priority(priority).ok();
|
|
||||||
|
|
||||||
while let Some(mut fragment) = segment.fragment().await? {
|
|
||||||
log::trace!("serving fragment: {:?}", fragment);
|
|
||||||
|
|
||||||
let object = message::Object {
|
|
||||||
track: id,
|
|
||||||
|
|
||||||
// Properties of the segment
|
|
||||||
group: segment.sequence,
|
|
||||||
priority: segment.priority,
|
|
||||||
expires: segment.expires,
|
|
||||||
|
|
||||||
// Properties of the fragment
|
|
||||||
sequence: fragment.sequence,
|
|
||||||
size: fragment.size.map(VarInt::try_from).transpose()?,
|
|
||||||
};
|
|
||||||
|
|
||||||
object
|
|
||||||
.encode(&mut stream, &self.control.ext)
|
|
||||||
.await
|
|
||||||
.map_err(|e| SessionError::Unknown(e.to_string()))?;
|
|
||||||
|
|
||||||
while let Some(chunk) = fragment.chunk().await? {
|
|
||||||
//log::trace!("writing chunk: {:?}", chunk);
|
|
||||||
stream.write_all(&chunk).await?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn recv_unsubscribe(&mut self, msg: &message::Unsubscribe) -> Result<(), SessionError> {
|
|
||||||
let abort = self
|
|
||||||
.subscribes
|
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.remove(&msg.id)
|
|
||||||
.ok_or(CacheError::NotFound)?;
|
|
||||||
abort.abort();
|
|
||||||
|
|
||||||
self.reset_subscribe(msg.id, CacheError::Stop).await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,116 +0,0 @@
|
|||||||
use super::{Control, Publisher, SessionError, Subscriber};
|
|
||||||
use crate::{cache::broadcast, setup};
|
|
||||||
|
|
||||||
use webtransport_quinn::{RecvStream, SendStream, Session};
|
|
||||||
|
|
||||||
/// An endpoint that accepts connections, publishing and/or consuming live streams.
|
|
||||||
pub struct Server {}
|
|
||||||
|
|
||||||
impl Server {
|
|
||||||
/// Accept an established Webtransport session, performing the MoQ handshake.
|
|
||||||
///
|
|
||||||
/// This returns a [Request] half-way through the handshake that allows the application to accept or deny the session.
|
|
||||||
pub async fn accept(session: Session) -> Result<Request, SessionError> {
|
|
||||||
let mut control = session.accept_bi().await?;
|
|
||||||
|
|
||||||
let mut client = setup::Client::decode(&mut control.1).await?;
|
|
||||||
|
|
||||||
log::debug!("received client SETUP: {:?}", client);
|
|
||||||
|
|
||||||
if client.versions.contains(&setup::Version::DRAFT_01) {
|
|
||||||
// We always require subscriber ID.
|
|
||||||
client.extensions.require_subscriber_id()?;
|
|
||||||
|
|
||||||
// We require OBJECT_EXPIRES for publishers only.
|
|
||||||
if client.role.is_publisher() {
|
|
||||||
client.extensions.require_object_expires()?;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We don't require SUBSCRIBE_SPLIT since it's easy enough to support, but it's clearly an oversight.
|
|
||||||
// client.extensions.require(&Extension::SUBSCRIBE_SPLIT)?;
|
|
||||||
} else if client.versions.contains(&setup::Version::KIXEL_01) {
|
|
||||||
// Extensions didn't exist in KIXEL_01, so we set them manually.
|
|
||||||
client.extensions = setup::Extensions {
|
|
||||||
object_expires: true,
|
|
||||||
subscriber_id: true,
|
|
||||||
subscribe_split: true,
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return Err(SessionError::Version(
|
|
||||||
client.versions,
|
|
||||||
[setup::Version::DRAFT_01, setup::Version::KIXEL_01].into(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(Request {
|
|
||||||
session,
|
|
||||||
client,
|
|
||||||
control,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A partially complete MoQ Transport handshake.
|
|
||||||
pub struct Request {
|
|
||||||
session: Session,
|
|
||||||
client: setup::Client,
|
|
||||||
control: (SendStream, RecvStream),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Request {
|
|
||||||
/// Accept the session as a publisher, using the provided broadcast to serve subscriptions.
|
|
||||||
pub async fn publisher(mut self, source: broadcast::Subscriber) -> Result<Publisher, SessionError> {
|
|
||||||
let setup = self.setup(setup::Role::Publisher)?;
|
|
||||||
setup.encode(&mut self.control.0).await?;
|
|
||||||
|
|
||||||
let control = Control::new(self.control.0, self.control.1, setup.extensions);
|
|
||||||
let publisher = Publisher::new(self.session, control, source);
|
|
||||||
Ok(publisher)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Accept the session as a subscriber only.
|
|
||||||
pub async fn subscriber(mut self, source: broadcast::Publisher) -> Result<Subscriber, SessionError> {
|
|
||||||
let setup = self.setup(setup::Role::Subscriber)?;
|
|
||||||
setup.encode(&mut self.control.0).await?;
|
|
||||||
|
|
||||||
let control = Control::new(self.control.0, self.control.1, setup.extensions);
|
|
||||||
let subscriber = Subscriber::new(self.session, control, source);
|
|
||||||
Ok(subscriber)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO Accept the session and perform both roles.
|
|
||||||
/*
|
|
||||||
pub async fn accept(self) -> anyhow::Result<(Publisher, Subscriber)> {
|
|
||||||
self.ok(setup::Role::Both).await
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
fn setup(&mut self, role: setup::Role) -> Result<setup::Server, SessionError> {
|
|
||||||
let server = setup::Server {
|
|
||||||
role,
|
|
||||||
version: setup::Version::DRAFT_01,
|
|
||||||
extensions: self.client.extensions.clone(),
|
|
||||||
params: Default::default(),
|
|
||||||
};
|
|
||||||
|
|
||||||
log::debug!("sending server SETUP: {:?}", server);
|
|
||||||
|
|
||||||
// We need to sure we support the opposite of the client's role.
|
|
||||||
// ex. if the client is a publisher, we must be a subscriber ONLY.
|
|
||||||
if !self.client.role.is_compatible(server.role) {
|
|
||||||
return Err(SessionError::RoleIncompatible(self.client.role, server.role));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(server)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Reject the request, closing the Webtransport session.
|
|
||||||
pub fn reject(self, code: u32) {
|
|
||||||
self.session.close(code, b"")
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The role advertised by the client.
|
|
||||||
pub fn role(&self) -> setup::Role {
|
|
||||||
self.client.role
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,211 +0,0 @@
|
|||||||
use webtransport_quinn::{RecvStream, Session};
|
|
||||||
|
|
||||||
use std::{
|
|
||||||
collections::HashMap,
|
|
||||||
sync::{atomic, Arc, Mutex},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
cache::{broadcast, segment, track, CacheError},
|
|
||||||
coding::DecodeError,
|
|
||||||
message,
|
|
||||||
message::Message,
|
|
||||||
session::{Control, SessionError},
|
|
||||||
VarInt,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Receives broadcasts over the network, automatically handling subscriptions and caching.
|
|
||||||
// TODO Clone specific fields when a task actually needs it.
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct Subscriber {
|
|
||||||
// The webtransport session.
|
|
||||||
webtransport: Session,
|
|
||||||
|
|
||||||
// The list of active subscriptions, each guarded by an mutex.
|
|
||||||
subscribes: Arc<Mutex<HashMap<VarInt, track::Publisher>>>,
|
|
||||||
|
|
||||||
// The sequence number for the next subscription.
|
|
||||||
next: Arc<atomic::AtomicU32>,
|
|
||||||
|
|
||||||
// A channel for sending messages.
|
|
||||||
control: Control,
|
|
||||||
|
|
||||||
// All unknown subscribes comes here.
|
|
||||||
source: broadcast::Publisher,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Subscriber {
|
|
||||||
pub(crate) fn new(webtransport: Session, control: Control, source: broadcast::Publisher) -> Self {
|
|
||||||
Self {
|
|
||||||
webtransport,
|
|
||||||
subscribes: Default::default(),
|
|
||||||
next: Default::default(),
|
|
||||||
control,
|
|
||||||
source,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn run(self) -> Result<(), SessionError> {
|
|
||||||
let inbound = self.clone().run_inbound();
|
|
||||||
let streams = self.clone().run_streams();
|
|
||||||
let source = self.clone().run_source();
|
|
||||||
|
|
||||||
// Return the first error.
|
|
||||||
tokio::select! {
|
|
||||||
res = inbound => res,
|
|
||||||
res = streams => res,
|
|
||||||
res = source => res,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn run_inbound(mut self) -> Result<(), SessionError> {
|
|
||||||
loop {
|
|
||||||
let msg = self.control.recv().await?;
|
|
||||||
|
|
||||||
log::info!("message received: {:?}", msg);
|
|
||||||
if let Err(err) = self.recv_message(&msg) {
|
|
||||||
log::warn!("message error: {:?} {:?}", err, msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn recv_message(&mut self, msg: &Message) -> Result<(), SessionError> {
|
|
||||||
match msg {
|
|
||||||
Message::Announce(_) => Ok(()), // don't care
|
|
||||||
Message::Unannounce(_) => Ok(()), // also don't care
|
|
||||||
Message::SubscribeOk(_msg) => Ok(()), // don't care
|
|
||||||
Message::SubscribeReset(msg) => self.recv_subscribe_error(msg.id, CacheError::Reset(msg.code)),
|
|
||||||
Message::SubscribeFin(msg) => self.recv_subscribe_error(msg.id, CacheError::Closed),
|
|
||||||
Message::SubscribeError(msg) => self.recv_subscribe_error(msg.id, CacheError::Reset(msg.code)),
|
|
||||||
Message::GoAway(_msg) => unimplemented!("GOAWAY"),
|
|
||||||
_ => Err(SessionError::RoleViolation(msg.id())),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn recv_subscribe_error(&mut self, id: VarInt, err: CacheError) -> Result<(), SessionError> {
|
|
||||||
let mut subscribes = self.subscribes.lock().unwrap();
|
|
||||||
let subscribe = subscribes.remove(&id).ok_or(CacheError::NotFound)?;
|
|
||||||
subscribe.close(err)?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn run_streams(self) -> Result<(), SessionError> {
|
|
||||||
loop {
|
|
||||||
// Accept all incoming unidirectional streams.
|
|
||||||
let stream = self.webtransport.accept_uni().await?;
|
|
||||||
let this = self.clone();
|
|
||||||
|
|
||||||
tokio::spawn(async move {
|
|
||||||
if let Err(err) = this.run_stream(stream).await {
|
|
||||||
log::warn!("failed to receive stream: err={:#?}", err);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn run_stream(self, mut stream: RecvStream) -> Result<(), SessionError> {
|
|
||||||
// Decode the object on the data stream.
|
|
||||||
let mut object = message::Object::decode(&mut stream, &self.control.ext)
|
|
||||||
.await
|
|
||||||
.map_err(|e| SessionError::Unknown(e.to_string()))?;
|
|
||||||
|
|
||||||
log::trace!("first object: {:?}", object);
|
|
||||||
|
|
||||||
// A new scope is needed because the async compiler is dumb
|
|
||||||
let mut segment = {
|
|
||||||
let mut subscribes = self.subscribes.lock().unwrap();
|
|
||||||
let track = subscribes.get_mut(&object.track).ok_or(CacheError::NotFound)?;
|
|
||||||
|
|
||||||
track.create_segment(segment::Info {
|
|
||||||
sequence: object.group,
|
|
||||||
priority: object.priority,
|
|
||||||
expires: object.expires,
|
|
||||||
})?
|
|
||||||
};
|
|
||||||
|
|
||||||
log::trace!("received segment: {:?}", segment);
|
|
||||||
|
|
||||||
// Create the first fragment
|
|
||||||
let mut fragment = segment.push_fragment(object.sequence, object.size.map(usize::from))?;
|
|
||||||
let mut remain = object.size.map(usize::from);
|
|
||||||
|
|
||||||
loop {
|
|
||||||
if let Some(0) = remain {
|
|
||||||
// Decode the next object from the stream.
|
|
||||||
let next = match message::Object::decode(&mut stream, &self.control.ext).await {
|
|
||||||
Ok(next) => next,
|
|
||||||
|
|
||||||
// No more objects
|
|
||||||
Err(DecodeError::Final) => break,
|
|
||||||
|
|
||||||
// Unknown error
|
|
||||||
Err(err) => return Err(err.into()),
|
|
||||||
};
|
|
||||||
|
|
||||||
log::trace!("next object: {:?}", object);
|
|
||||||
|
|
||||||
// NOTE: This is a custom restriction; not part of the moq-transport draft.
|
|
||||||
// We require every OBJECT to contain the same priority since prioritization is done per-stream.
|
|
||||||
// We also require every OBJECT to contain the same group so we know when the group ends, and can detect gaps.
|
|
||||||
if next.priority != object.priority && next.group != object.group {
|
|
||||||
return Err(SessionError::StreamMapping);
|
|
||||||
}
|
|
||||||
|
|
||||||
object = next;
|
|
||||||
|
|
||||||
// Create a new object.
|
|
||||||
fragment = segment.push_fragment(object.sequence, object.size.map(usize::from))?;
|
|
||||||
remain = object.size.map(usize::from);
|
|
||||||
|
|
||||||
log::trace!("next fragment: {:?}", fragment);
|
|
||||||
}
|
|
||||||
|
|
||||||
match stream.read_chunk(remain.unwrap_or(usize::MAX), true).await? {
|
|
||||||
// Unbounded object has ended
|
|
||||||
None if remain.is_none() => break,
|
|
||||||
|
|
||||||
// Bounded object ended early, oops.
|
|
||||||
None => return Err(DecodeError::UnexpectedEnd.into()),
|
|
||||||
|
|
||||||
// NOTE: This does not make a copy!
|
|
||||||
// Bytes are immutable and ref counted.
|
|
||||||
Some(data) => {
|
|
||||||
remain = remain.map(|r| r - data.bytes.len());
|
|
||||||
|
|
||||||
log::trace!("next chunk: {:?}", data);
|
|
||||||
fragment.chunk(data.bytes)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn run_source(mut self) -> Result<(), SessionError> {
|
|
||||||
loop {
|
|
||||||
// NOTE: This returns Closed when the source is closed.
|
|
||||||
let track = self.source.next_track().await?;
|
|
||||||
let name = track.name.clone();
|
|
||||||
|
|
||||||
let id = VarInt::from_u32(self.next.fetch_add(1, atomic::Ordering::SeqCst));
|
|
||||||
self.subscribes.lock().unwrap().insert(id, track);
|
|
||||||
|
|
||||||
let msg = message::Subscribe {
|
|
||||||
id,
|
|
||||||
namespace: self.control.ext.subscribe_split.then(|| "".to_string()),
|
|
||||||
name,
|
|
||||||
|
|
||||||
// TODO correctly support these
|
|
||||||
start_group: message::SubscribeLocation::Latest(VarInt::ZERO),
|
|
||||||
start_object: message::SubscribeLocation::Absolute(VarInt::ZERO),
|
|
||||||
end_group: message::SubscribeLocation::None,
|
|
||||||
end_object: message::SubscribeLocation::None,
|
|
||||||
|
|
||||||
params: Default::default(),
|
|
||||||
};
|
|
||||||
|
|
||||||
self.control.send(msg).await?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
use super::{Extensions, Role, Versions};
|
|
||||||
use crate::{
|
|
||||||
coding::{Decode, DecodeError, Encode, EncodeError, Params},
|
|
||||||
VarInt,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::coding::{AsyncRead, AsyncWrite};
|
|
||||||
|
|
||||||
/// Sent by the client to setup the session.
|
|
||||||
// NOTE: This is not a message type, but rather the control stream header.
|
|
||||||
// Proposal: https://github.com/moq-wg/moq-transport/issues/138
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct Client {
|
|
||||||
/// The list of supported versions in preferred order.
|
|
||||||
pub versions: Versions,
|
|
||||||
|
|
||||||
/// Indicate if the client is a publisher, a subscriber, or both.
|
|
||||||
pub role: Role,
|
|
||||||
|
|
||||||
/// A list of known/offered extensions.
|
|
||||||
pub extensions: Extensions,
|
|
||||||
|
|
||||||
/// Unknown parameters.
|
|
||||||
pub params: Params,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Client {
|
|
||||||
/// Decode a client setup message.
|
|
||||||
pub async fn decode<R: AsyncRead>(r: &mut R) -> Result<Self, DecodeError> {
|
|
||||||
let typ = VarInt::decode(r).await?;
|
|
||||||
if typ.into_inner() != 0x40 {
|
|
||||||
return Err(DecodeError::InvalidMessage(typ));
|
|
||||||
}
|
|
||||||
|
|
||||||
let versions = Versions::decode(r).await?;
|
|
||||||
let mut params = Params::decode(r).await?;
|
|
||||||
|
|
||||||
let role = params
|
|
||||||
.get::<Role>(VarInt::from_u32(0))
|
|
||||||
.await?
|
|
||||||
.ok_or(DecodeError::MissingParameter)?;
|
|
||||||
|
|
||||||
// Make sure the PATH parameter isn't used
|
|
||||||
// TODO: This assumes WebTransport support only
|
|
||||||
if params.has(VarInt::from_u32(1)) {
|
|
||||||
return Err(DecodeError::InvalidParameter);
|
|
||||||
}
|
|
||||||
|
|
||||||
let extensions = Extensions::load(&mut params).await?;
|
|
||||||
|
|
||||||
Ok(Self {
|
|
||||||
versions,
|
|
||||||
role,
|
|
||||||
extensions,
|
|
||||||
params,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Encode a server setup message.
|
|
||||||
pub async fn encode<W: AsyncWrite>(&self, w: &mut W) -> Result<(), EncodeError> {
|
|
||||||
VarInt::from_u32(0x40).encode(w).await?;
|
|
||||||
self.versions.encode(w).await?;
|
|
||||||
|
|
||||||
let mut params = self.params.clone();
|
|
||||||
params.set(VarInt::from_u32(0), self.role).await?;
|
|
||||||
self.extensions.store(&mut params).await?;
|
|
||||||
|
|
||||||
params.encode(w).await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
use tokio::io::{AsyncRead, AsyncWrite};
|
|
||||||
|
|
||||||
use crate::coding::{Decode, DecodeError, Encode, EncodeError, Params};
|
|
||||||
use crate::session::SessionError;
|
|
||||||
use crate::VarInt;
|
|
||||||
use paste::paste;
|
|
||||||
|
|
||||||
/// This is a custom extension scheme to allow/require draft PRs.
|
|
||||||
///
|
|
||||||
/// By convention, the extension number is the PR number + 0xe0000.
|
|
||||||
|
|
||||||
macro_rules! extensions {
|
|
||||||
{$($name:ident = $val:expr,)*} => {
|
|
||||||
#[derive(Clone, Default, Debug)]
|
|
||||||
pub struct Extensions {
|
|
||||||
$(
|
|
||||||
pub $name: bool,
|
|
||||||
)*
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Extensions {
|
|
||||||
pub async fn load(params: &mut Params) -> Result<Self, DecodeError> {
|
|
||||||
let mut extensions = Self::default();
|
|
||||||
|
|
||||||
$(
|
|
||||||
if let Some(_) = params.get::<ExtensionExists>(VarInt::from_u32($val)).await? {
|
|
||||||
extensions.$name = true
|
|
||||||
}
|
|
||||||
)*
|
|
||||||
|
|
||||||
Ok(extensions)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn store(&self, params: &mut Params) -> Result<(), EncodeError> {
|
|
||||||
$(
|
|
||||||
if self.$name {
|
|
||||||
params.set(VarInt::from_u32($val), ExtensionExists{}).await?;
|
|
||||||
}
|
|
||||||
)*
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
paste! {
|
|
||||||
$(
|
|
||||||
pub fn [<require_ $name>](&self) -> Result<(), SessionError> {
|
|
||||||
match self.$name {
|
|
||||||
true => Ok(()),
|
|
||||||
false => Err(SessionError::RequiredExtension(VarInt::from_u32($val))),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)*
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ExtensionExists;
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl Decode for ExtensionExists {
|
|
||||||
async fn decode<R: AsyncRead>(_r: &mut R) -> Result<Self, DecodeError> {
|
|
||||||
Ok(ExtensionExists {})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl Encode for ExtensionExists {
|
|
||||||
async fn encode<W: AsyncWrite>(&self, _w: &mut W) -> Result<(), EncodeError> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extensions! {
|
|
||||||
// required for publishers: OBJECT contains expires VarInt in seconds: https://github.com/moq-wg/moq-transport/issues/249
|
|
||||||
// TODO write up a PR
|
|
||||||
object_expires = 0xe00f9,
|
|
||||||
|
|
||||||
// required: SUBSCRIBE chooses track ID: https://github.com/moq-wg/moq-transport/pull/258
|
|
||||||
subscriber_id = 0xe0102,
|
|
||||||
|
|
||||||
// optional: SUBSCRIBE contains namespace/name tuple: https://github.com/moq-wg/moq-transport/pull/277
|
|
||||||
subscribe_split = 0xe0115,
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
//! Messages used for the MoQ Transport handshake.
|
|
||||||
//!
|
|
||||||
//! After establishing the WebTransport session, the client creates a bidirectional QUIC stream.
|
|
||||||
//! The client sends the [Client] message and the server responds with the [Server] message.
|
|
||||||
//! Both sides negotate the [Version] and [Role].
|
|
||||||
|
|
||||||
mod client;
|
|
||||||
mod extension;
|
|
||||||
mod role;
|
|
||||||
mod server;
|
|
||||||
mod version;
|
|
||||||
|
|
||||||
pub use client::*;
|
|
||||||
pub use extension::*;
|
|
||||||
pub use role::*;
|
|
||||||
pub use server::*;
|
|
||||||
pub use version::*;
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
use crate::coding::{AsyncRead, AsyncWrite};
|
|
||||||
|
|
||||||
use crate::coding::{Decode, DecodeError, Encode, EncodeError, VarInt};
|
|
||||||
|
|
||||||
/// Indicates the endpoint is a publisher, subscriber, or both.
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
||||||
pub enum Role {
|
|
||||||
Publisher,
|
|
||||||
Subscriber,
|
|
||||||
Both,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Role {
|
|
||||||
/// Returns true if the role is publisher.
|
|
||||||
pub fn is_publisher(&self) -> bool {
|
|
||||||
match self {
|
|
||||||
Self::Publisher | Self::Both => true,
|
|
||||||
Self::Subscriber => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if the role is a subscriber.
|
|
||||||
pub fn is_subscriber(&self) -> bool {
|
|
||||||
match self {
|
|
||||||
Self::Subscriber | Self::Both => true,
|
|
||||||
Self::Publisher => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if two endpoints are compatible.
|
|
||||||
pub fn is_compatible(&self, other: Role) -> bool {
|
|
||||||
self.is_publisher() == other.is_subscriber() && self.is_subscriber() == other.is_publisher()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Role> for VarInt {
|
|
||||||
fn from(r: Role) -> Self {
|
|
||||||
VarInt::from_u32(match r {
|
|
||||||
Role::Publisher => 0x1,
|
|
||||||
Role::Subscriber => 0x2,
|
|
||||||
Role::Both => 0x3,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<VarInt> for Role {
|
|
||||||
type Error = DecodeError;
|
|
||||||
|
|
||||||
fn try_from(v: VarInt) -> Result<Self, Self::Error> {
|
|
||||||
match v.into_inner() {
|
|
||||||
0x1 => Ok(Self::Publisher),
|
|
||||||
0x2 => Ok(Self::Subscriber),
|
|
||||||
0x3 => Ok(Self::Both),
|
|
||||||
_ => Err(DecodeError::InvalidRole(v)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl Decode for Role {
|
|
||||||
/// Decode the role.
|
|
||||||
async fn decode<R: AsyncRead>(r: &mut R) -> Result<Self, DecodeError> {
|
|
||||||
let v = VarInt::decode(r).await?;
|
|
||||||
v.try_into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl Encode for Role {
|
|
||||||
/// Encode the role.
|
|
||||||
async fn encode<W: AsyncWrite>(&self, w: &mut W) -> Result<(), EncodeError> {
|
|
||||||
VarInt::from(*self).encode(w).await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
use super::{Extensions, Role, Version};
|
|
||||||
use crate::{
|
|
||||||
coding::{Decode, DecodeError, Encode, EncodeError, Params},
|
|
||||||
VarInt,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::coding::{AsyncRead, AsyncWrite};
|
|
||||||
|
|
||||||
/// Sent by the server in response to a client setup.
|
|
||||||
// NOTE: This is not a message type, but rather the control stream header.
|
|
||||||
// Proposal: https://github.com/moq-wg/moq-transport/issues/138
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct Server {
|
|
||||||
/// The list of supported versions in preferred order.
|
|
||||||
pub version: Version,
|
|
||||||
|
|
||||||
/// Indicate if the server is a publisher, a subscriber, or both.
|
|
||||||
// Proposal: moq-wg/moq-transport#151
|
|
||||||
pub role: Role,
|
|
||||||
|
|
||||||
/// Custom extensions.
|
|
||||||
pub extensions: Extensions,
|
|
||||||
|
|
||||||
/// Unknown parameters.
|
|
||||||
pub params: Params,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Server {
|
|
||||||
/// Decode the server setup.
|
|
||||||
pub async fn decode<R: AsyncRead>(r: &mut R) -> Result<Self, DecodeError> {
|
|
||||||
let typ = VarInt::decode(r).await?;
|
|
||||||
if typ.into_inner() != 0x41 {
|
|
||||||
return Err(DecodeError::InvalidMessage(typ));
|
|
||||||
}
|
|
||||||
|
|
||||||
let version = Version::decode(r).await?;
|
|
||||||
let mut params = Params::decode(r).await?;
|
|
||||||
|
|
||||||
let role = params
|
|
||||||
.get::<Role>(VarInt::from_u32(0))
|
|
||||||
.await?
|
|
||||||
.ok_or(DecodeError::MissingParameter)?;
|
|
||||||
|
|
||||||
// Make sure the PATH parameter isn't used
|
|
||||||
if params.has(VarInt::from_u32(1)) {
|
|
||||||
return Err(DecodeError::InvalidParameter);
|
|
||||||
}
|
|
||||||
|
|
||||||
let extensions = Extensions::load(&mut params).await?;
|
|
||||||
|
|
||||||
Ok(Self {
|
|
||||||
version,
|
|
||||||
role,
|
|
||||||
extensions,
|
|
||||||
params,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Encode the server setup.
|
|
||||||
pub async fn encode<W: AsyncWrite>(&self, w: &mut W) -> Result<(), EncodeError> {
|
|
||||||
VarInt::from_u32(0x41).encode(w).await?;
|
|
||||||
self.version.encode(w).await?;
|
|
||||||
|
|
||||||
let mut params = self.params.clone();
|
|
||||||
params.set(VarInt::from_u32(0), self.role).await?;
|
|
||||||
self.extensions.store(&mut params).await?;
|
|
||||||
params.encode(w).await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,155 +0,0 @@
|
|||||||
use crate::coding::{Decode, DecodeError, Encode, EncodeError, VarInt};
|
|
||||||
|
|
||||||
use crate::coding::{AsyncRead, AsyncWrite};
|
|
||||||
|
|
||||||
use std::ops::Deref;
|
|
||||||
|
|
||||||
/// A version number negotiated during the setup.
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
||||||
pub struct Version(pub VarInt);
|
|
||||||
|
|
||||||
impl Version {
|
|
||||||
/// https://www.ietf.org/archive/id/draft-ietf-moq-transport-00.html
|
|
||||||
pub const DRAFT_00: Version = Version(VarInt::from_u32(0xff000000));
|
|
||||||
|
|
||||||
/// https://www.ietf.org/archive/id/draft-ietf-moq-transport-01.html
|
|
||||||
pub const DRAFT_01: Version = Version(VarInt::from_u32(0xff000001));
|
|
||||||
|
|
||||||
/// Fork of draft-ietf-moq-transport-00.
|
|
||||||
///
|
|
||||||
/// Rough list of differences:
|
|
||||||
///
|
|
||||||
/// # Messages
|
|
||||||
/// - Messages are sent over a control stream or a data stream.
|
|
||||||
/// - Data streams: each unidirectional stream contains a single OBJECT message.
|
|
||||||
/// - Control stream: a (client-initiated) bidirectional stream containing SETUP and then all other messages.
|
|
||||||
/// - Messages do not contain a length; unknown messages are fatal.
|
|
||||||
///
|
|
||||||
/// # SETUP
|
|
||||||
/// - SETUP is split into SETUP_CLIENT and SETUP_SERVER with separate IDs.
|
|
||||||
/// - SETUP uses version `0xff00` for draft-00.
|
|
||||||
/// - SETUP no longer contains optional parameters; all are encoded in order and possibly zero.
|
|
||||||
/// - SETUP `role` indicates the role of the sender, not the role of the server.
|
|
||||||
/// - SETUP `path` field removed; use WebTransport for path.
|
|
||||||
///
|
|
||||||
/// # SUBSCRIBE
|
|
||||||
/// - SUBSCRIBE `full_name` is split into separate `namespace` and `name` fields.
|
|
||||||
/// - SUBSCRIBE no longer contains optional parameters; all are encoded in order and possibly zero.
|
|
||||||
/// - SUBSCRIBE no longer contains the `auth` parameter; use WebTransport for auth.
|
|
||||||
/// - SUBSCRIBE no longer contains the `group` parameter; concept no longer exists.
|
|
||||||
/// - SUBSCRIBE contains the `id` instead of SUBSCRIBE_OK.
|
|
||||||
/// - SUBSCRIBE_OK and SUBSCRIBE_ERROR reference the subscription `id` the instead of the track `full_name`.
|
|
||||||
/// - SUBSCRIBE_ERROR was renamed to SUBSCRIBE_RESET, sent by publisher to terminate a SUBSCRIBE.
|
|
||||||
/// - SUBSCRIBE_STOP was added, sent by the subscriber to terminate a SUBSCRIBE.
|
|
||||||
/// - SUBSCRIBE_OK no longer has `expires`.
|
|
||||||
///
|
|
||||||
/// # ANNOUNCE
|
|
||||||
/// - ANNOUNCE no longer contains optional parameters; all are encoded in order and possibly zero.
|
|
||||||
/// - ANNOUNCE no longer contains the `auth` field; use WebTransport for auth.
|
|
||||||
/// - ANNOUNCE_ERROR was renamed to ANNOUNCE_RESET, sent by publisher to terminate an ANNOUNCE.
|
|
||||||
/// - ANNOUNCE_STOP was added, sent by the subscriber to terminate an ANNOUNCE.
|
|
||||||
///
|
|
||||||
/// # OBJECT
|
|
||||||
/// - OBJECT uses a dedicated QUIC stream.
|
|
||||||
/// - OBJECT has no size and continues until stream FIN.
|
|
||||||
/// - OBJECT `priority` is a i32 instead of a varint. (for practical reasons)
|
|
||||||
/// - OBJECT `expires` was added, a varint in seconds.
|
|
||||||
/// - OBJECT `group` was removed.
|
|
||||||
///
|
|
||||||
/// # GROUP
|
|
||||||
/// - GROUP concept was removed, replaced with OBJECT as a QUIC stream.
|
|
||||||
pub const KIXEL_00: Version = Version(VarInt::from_u32(0xbad00));
|
|
||||||
|
|
||||||
/// Fork of draft-ietf-moq-transport-01.
|
|
||||||
///
|
|
||||||
/// Most of the KIXEL_00 changes made it into the draft, or were reverted.
|
|
||||||
/// This was only used for a short time until extensions were created.
|
|
||||||
///
|
|
||||||
/// - SUBSCRIBE contains a separate track namespace and track name field (accidental revert). [#277](https://github.com/moq-wg/moq-transport/pull/277)
|
|
||||||
/// - SUBSCRIBE contains the `track_id` instead of SUBSCRIBE_OK. [#145](https://github.com/moq-wg/moq-transport/issues/145)
|
|
||||||
/// - SUBSCRIBE_* reference `track_id` the instead of the `track_full_name`. [#145](https://github.com/moq-wg/moq-transport/issues/145)
|
|
||||||
/// - OBJECT `priority` is still a VarInt, but the max value is a u32 (implementation reasons)
|
|
||||||
/// - OBJECT messages within the same `group` MUST be on the same QUIC stream.
|
|
||||||
pub const KIXEL_01: Version = Version(VarInt::from_u32(0xbad01));
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<VarInt> for Version {
|
|
||||||
fn from(v: VarInt) -> Self {
|
|
||||||
Self(v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Version> for VarInt {
|
|
||||||
fn from(v: Version) -> Self {
|
|
||||||
v.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Version {
|
|
||||||
/// Decode the version number.
|
|
||||||
pub async fn decode<R: AsyncRead>(r: &mut R) -> Result<Self, DecodeError> {
|
|
||||||
let v = VarInt::decode(r).await?;
|
|
||||||
Ok(Self(v))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Encode the version number.
|
|
||||||
pub async fn encode<W: AsyncWrite>(&self, w: &mut W) -> Result<(), EncodeError> {
|
|
||||||
self.0.encode(w).await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A list of versions in arbitrary order.
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
||||||
pub struct Versions(Vec<Version>);
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl Decode for Versions {
|
|
||||||
/// Decode the version list.
|
|
||||||
async fn decode<R: AsyncRead>(r: &mut R) -> Result<Self, DecodeError> {
|
|
||||||
let count = VarInt::decode(r).await?.into_inner();
|
|
||||||
let mut vs = Vec::new();
|
|
||||||
|
|
||||||
for _ in 0..count {
|
|
||||||
let v = Version::decode(r).await?;
|
|
||||||
vs.push(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(Self(vs))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
impl Encode for Versions {
|
|
||||||
/// Encode the version list.
|
|
||||||
async fn encode<W: AsyncWrite>(&self, w: &mut W) -> Result<(), EncodeError> {
|
|
||||||
let size: VarInt = self.0.len().try_into()?;
|
|
||||||
size.encode(w).await?;
|
|
||||||
|
|
||||||
for v in &self.0 {
|
|
||||||
v.encode(w).await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for Versions {
|
|
||||||
type Target = Vec<Version>;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Vec<Version>> for Versions {
|
|
||||||
fn from(vs: Vec<Version>) -> Self {
|
|
||||||
Self(vs)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<const N: usize> From<[Version; N]> for Versions {
|
|
||||||
fn from(vs: [Version; N]) -> Self {
|
|
||||||
Self(vs.to_vec())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
43
src/main.rs
Normal file
43
src/main.rs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
use anyhow::Error;
|
||||||
|
use gst::prelude::*;
|
||||||
|
|
||||||
|
fn main() -> Result<(), Error> {
|
||||||
|
gst::init()?;
|
||||||
|
gstfmp4::plugin_register_static().expect("Failed to register fmp4 plugin");
|
||||||
|
|
||||||
|
let pipeline = gst::parse_launch("videotestsrc num-buffers=2500 ! timecodestamper ! video/x-raw,format=I420,width=1280,height=720,framerate=30/1 ! timeoverlay ! x264enc bframes=0 bitrate=2048 ! video/x-h264,profile=main ! cmafmux fragment-duration=10000000000 header-update-mode=update write-mehd=true ! testsink").unwrap().downcast::<gst::Pipeline>().unwrap();
|
||||||
|
|
||||||
|
pipeline.set_state(gst::State::Playing)?;
|
||||||
|
|
||||||
|
let bus = pipeline
|
||||||
|
.bus()
|
||||||
|
.expect("Pipeline without bus. Shouldn't happen!");
|
||||||
|
|
||||||
|
for msg in bus.iter_timed(gst::ClockTime::NONE) {
|
||||||
|
use gst::MessageView;
|
||||||
|
|
||||||
|
match msg.view() {
|
||||||
|
MessageView::Eos(..) => {
|
||||||
|
println!("EOS");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
MessageView::Error(err) => {
|
||||||
|
pipeline.set_state(gst::State::Null)?;
|
||||||
|
eprintln!(
|
||||||
|
"Got error from {}: {} ({})",
|
||||||
|
msg.src()
|
||||||
|
.map(|s| String::from(s.path_string()))
|
||||||
|
.unwrap_or_else(|| "None".into()),
|
||||||
|
err.error(),
|
||||||
|
err.debug().unwrap_or_else(|| "".into()),
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pipeline.set_state(gst::State::Null)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "wayland-display-core"
|
|
||||||
authors = ["Victoria Brekenfeld <git@drakulix.de>", "Alessandro Beltramo <github.com/ABeltramo>"]
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2021"
|
|
||||||
license = "MIT"
|
|
||||||
description = "Wayland Compositor producing GStreamer buffers"
|
|
||||||
rust-version = "1.70"
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
name = "waylanddisplaycore"
|
|
||||||
crate-type = ["cdylib", "staticlib", "rlib"]
|
|
||||||
path = "src/lib.rs"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
gst.workspace = true
|
|
||||||
gst-video.workspace = true
|
|
||||||
tracing.workspace = true
|
|
||||||
once_cell.workspace = true
|
|
||||||
wayland-backend = "0.1.0"
|
|
||||||
wayland-scanner = "0.30.0"
|
|
||||||
|
|
||||||
[dependencies.smithay]
|
|
||||||
git = "https://github.com/smithay/Smithay"
|
|
||||||
rev = "b1c682742a"
|
|
||||||
default-features = false
|
|
||||||
features = [
|
|
||||||
"backend_drm",
|
|
||||||
"backend_egl",
|
|
||||||
"backend_libinput",
|
|
||||||
"backend_udev",
|
|
||||||
"renderer_gl",
|
|
||||||
"use_system_lib",
|
|
||||||
"desktop",
|
|
||||||
"wayland_frontend"
|
|
||||||
]
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2023 Games on Whales https://github.com/games-on-whales/
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
# gst-wayland-display
|
|
||||||
|
|
||||||
A micro Wayland compositor that can be used as a Gstreamer plugin
|
|
||||||
|
|
||||||
## Install
|
|
||||||
|
|
||||||
see [cargo-c](https://github.com/lu-zero/cargo-c)
|
|
||||||
|
|
||||||
```bash
|
|
||||||
git clone ...
|
|
||||||
cd gst-wayland-display
|
|
||||||
cargo cinstall --prefix=/usr/local
|
|
||||||
```
|
|
||||||
|
|
||||||
## GStreamer plugin
|
|
||||||
|
|
||||||
TODO
|
|
||||||
|
|
||||||
## C Bindings
|
|
||||||
|
|
||||||
CmakeLists.txt
|
|
||||||
|
|
||||||
```cmake
|
|
||||||
pkg_check_modules(libgstwaylanddisplay REQUIRED IMPORTED_TARGET libgstwaylanddisplay)
|
|
||||||
target_link_libraries(<YOUR_PROJECT_HERE> PUBLIC PkgConfig::libgstwaylanddisplay)
|
|
||||||
```
|
|
||||||
|
|
||||||
Include in your code:
|
|
||||||
|
|
||||||
```c
|
|
||||||
#include <libgstwaylanddisplay/libgstwaylanddisplay.h>
|
|
||||||
```
|
|
||||||
|
|
||||||
Example usage:
|
|
||||||
|
|
||||||
```c++
|
|
||||||
auto w_state = display_init("/dev/dri/renderD128"); // Pass a render node
|
|
||||||
|
|
||||||
display_add_input_device(w_state, "/dev/input/event20"); // Mouse
|
|
||||||
display_add_input_device(w_state, "/dev/input/event21"); // Keyboard
|
|
||||||
|
|
||||||
// Setting video as 1920x1080@60
|
|
||||||
auto video_info = gst_caps_new_simple("video/x-raw",
|
|
||||||
"width", G_TYPE_INT, 1920,
|
|
||||||
"height", G_TYPE_INT, 1080,
|
|
||||||
"framerate", GST_TYPE_FRACTION, 60, 1,
|
|
||||||
"format", G_TYPE_STRING, "RGBx",
|
|
||||||
NULL);
|
|
||||||
display_set_video_info(w_state, video_info);
|
|
||||||
|
|
||||||
// Get a list of the devices needed, ex: ["/dev/dri/renderD128", "/dev/dri/card0"]
|
|
||||||
auto n_devices = display_get_devices_len(w_state);
|
|
||||||
const char *devs[n_devices];
|
|
||||||
display_get_devices(w_state, devs, n_devices);
|
|
||||||
|
|
||||||
// Get a list of the env vars needed, notably the wayland socket
|
|
||||||
// ex: ["WAYLAND_DISPLAY=wayland-1"]
|
|
||||||
auto n_envs = display_get_envvars_len(w_state);
|
|
||||||
const char *envs[n_envs];
|
|
||||||
display_get_envvars(w_state, envs, n_envs);
|
|
||||||
|
|
||||||
// Example of polling for new video data
|
|
||||||
GstBuffer * v_buffer;
|
|
||||||
while(true){
|
|
||||||
v_buffer = display_get_frame(w_state);
|
|
||||||
// TODO: do something with the video data
|
|
||||||
}
|
|
||||||
|
|
||||||
display_finish(w_state); // Cleanup
|
|
||||||
```
|
|
||||||
Binary file not shown.
@@ -1,189 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<protocol name="drm">
|
|
||||||
|
|
||||||
<copyright>
|
|
||||||
Copyright © 2008-2011 Kristian Høgsberg
|
|
||||||
Copyright © 2010-2011 Intel Corporation
|
|
||||||
|
|
||||||
Permission to use, copy, modify, distribute, and sell this
|
|
||||||
software and its documentation for any purpose is hereby granted
|
|
||||||
without fee, provided that\n the above copyright notice appear in
|
|
||||||
all copies and that both that copyright notice and this permission
|
|
||||||
notice appear in supporting documentation, and that the name of
|
|
||||||
the copyright holders not be used in advertising or publicity
|
|
||||||
pertaining to distribution of the software without specific,
|
|
||||||
written prior permission. The copyright holders make no
|
|
||||||
representations about the suitability of this software for any
|
|
||||||
purpose. It is provided "as is" without express or implied
|
|
||||||
warranty.
|
|
||||||
|
|
||||||
THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
|
|
||||||
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
||||||
FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
||||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
|
|
||||||
AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
|
||||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
|
||||||
THIS SOFTWARE.
|
|
||||||
</copyright>
|
|
||||||
|
|
||||||
<!-- drm support. This object is created by the server and published
|
|
||||||
using the display's global event. -->
|
|
||||||
<interface name="wl_drm" version="2">
|
|
||||||
<enum name="error">
|
|
||||||
<entry name="authenticate_fail" value="0"/>
|
|
||||||
<entry name="invalid_format" value="1"/>
|
|
||||||
<entry name="invalid_name" value="2"/>
|
|
||||||
</enum>
|
|
||||||
|
|
||||||
<enum name="format">
|
|
||||||
<!-- The drm format codes match the #defines in drm_fourcc.h.
|
|
||||||
The formats actually supported by the compositor will be
|
|
||||||
reported by the format event. New codes must not be added,
|
|
||||||
unless directly taken from drm_fourcc.h. -->
|
|
||||||
<entry name="c8" value="0x20203843"/>
|
|
||||||
<entry name="rgb332" value="0x38424752"/>
|
|
||||||
<entry name="bgr233" value="0x38524742"/>
|
|
||||||
<entry name="xrgb4444" value="0x32315258"/>
|
|
||||||
<entry name="xbgr4444" value="0x32314258"/>
|
|
||||||
<entry name="rgbx4444" value="0x32315852"/>
|
|
||||||
<entry name="bgrx4444" value="0x32315842"/>
|
|
||||||
<entry name="argb4444" value="0x32315241"/>
|
|
||||||
<entry name="abgr4444" value="0x32314241"/>
|
|
||||||
<entry name="rgba4444" value="0x32314152"/>
|
|
||||||
<entry name="bgra4444" value="0x32314142"/>
|
|
||||||
<entry name="xrgb1555" value="0x35315258"/>
|
|
||||||
<entry name="xbgr1555" value="0x35314258"/>
|
|
||||||
<entry name="rgbx5551" value="0x35315852"/>
|
|
||||||
<entry name="bgrx5551" value="0x35315842"/>
|
|
||||||
<entry name="argb1555" value="0x35315241"/>
|
|
||||||
<entry name="abgr1555" value="0x35314241"/>
|
|
||||||
<entry name="rgba5551" value="0x35314152"/>
|
|
||||||
<entry name="bgra5551" value="0x35314142"/>
|
|
||||||
<entry name="rgb565" value="0x36314752"/>
|
|
||||||
<entry name="bgr565" value="0x36314742"/>
|
|
||||||
<entry name="rgb888" value="0x34324752"/>
|
|
||||||
<entry name="bgr888" value="0x34324742"/>
|
|
||||||
<entry name="xrgb8888" value="0x34325258"/>
|
|
||||||
<entry name="xbgr8888" value="0x34324258"/>
|
|
||||||
<entry name="rgbx8888" value="0x34325852"/>
|
|
||||||
<entry name="bgrx8888" value="0x34325842"/>
|
|
||||||
<entry name="argb8888" value="0x34325241"/>
|
|
||||||
<entry name="abgr8888" value="0x34324241"/>
|
|
||||||
<entry name="rgba8888" value="0x34324152"/>
|
|
||||||
<entry name="bgra8888" value="0x34324142"/>
|
|
||||||
<entry name="xrgb2101010" value="0x30335258"/>
|
|
||||||
<entry name="xbgr2101010" value="0x30334258"/>
|
|
||||||
<entry name="rgbx1010102" value="0x30335852"/>
|
|
||||||
<entry name="bgrx1010102" value="0x30335842"/>
|
|
||||||
<entry name="argb2101010" value="0x30335241"/>
|
|
||||||
<entry name="abgr2101010" value="0x30334241"/>
|
|
||||||
<entry name="rgba1010102" value="0x30334152"/>
|
|
||||||
<entry name="bgra1010102" value="0x30334142"/>
|
|
||||||
<entry name="yuyv" value="0x56595559"/>
|
|
||||||
<entry name="yvyu" value="0x55595659"/>
|
|
||||||
<entry name="uyvy" value="0x59565955"/>
|
|
||||||
<entry name="vyuy" value="0x59555956"/>
|
|
||||||
<entry name="ayuv" value="0x56555941"/>
|
|
||||||
<entry name="xyuv8888" value="0x56555958"/>
|
|
||||||
<entry name="nv12" value="0x3231564e"/>
|
|
||||||
<entry name="nv21" value="0x3132564e"/>
|
|
||||||
<entry name="nv16" value="0x3631564e"/>
|
|
||||||
<entry name="nv61" value="0x3136564e"/>
|
|
||||||
<entry name="yuv410" value="0x39565559"/>
|
|
||||||
<entry name="yvu410" value="0x39555659"/>
|
|
||||||
<entry name="yuv411" value="0x31315559"/>
|
|
||||||
<entry name="yvu411" value="0x31315659"/>
|
|
||||||
<entry name="yuv420" value="0x32315559"/>
|
|
||||||
<entry name="yvu420" value="0x32315659"/>
|
|
||||||
<entry name="yuv422" value="0x36315559"/>
|
|
||||||
<entry name="yvu422" value="0x36315659"/>
|
|
||||||
<entry name="yuv444" value="0x34325559"/>
|
|
||||||
<entry name="yvu444" value="0x34325659"/>
|
|
||||||
<entry name="abgr16f" value="0x48344241"/>
|
|
||||||
<entry name="xbgr16f" value="0x48344258"/>
|
|
||||||
</enum>
|
|
||||||
|
|
||||||
<!-- Call this request with the magic received from drmGetMagic().
|
|
||||||
It will be passed on to the drmAuthMagic() or
|
|
||||||
DRIAuthConnection() call. This authentication must be
|
|
||||||
completed before create_buffer could be used. -->
|
|
||||||
<request name="authenticate">
|
|
||||||
<arg name="id" type="uint"/>
|
|
||||||
</request>
|
|
||||||
|
|
||||||
<!-- Create a wayland buffer for the named DRM buffer. The DRM
|
|
||||||
surface must have a name using the flink ioctl -->
|
|
||||||
<request name="create_buffer">
|
|
||||||
<arg name="id" type="new_id" interface="wl_buffer"/>
|
|
||||||
<arg name="name" type="uint"/>
|
|
||||||
<arg name="width" type="int"/>
|
|
||||||
<arg name="height" type="int"/>
|
|
||||||
<arg name="stride" type="uint"/>
|
|
||||||
<arg name="format" type="uint"/>
|
|
||||||
</request>
|
|
||||||
|
|
||||||
<!-- Create a wayland buffer for the named DRM buffer. The DRM
|
|
||||||
surface must have a name using the flink ioctl -->
|
|
||||||
<request name="create_planar_buffer">
|
|
||||||
<arg name="id" type="new_id" interface="wl_buffer"/>
|
|
||||||
<arg name="name" type="uint"/>
|
|
||||||
<arg name="width" type="int"/>
|
|
||||||
<arg name="height" type="int"/>
|
|
||||||
<arg name="format" type="uint"/>
|
|
||||||
<arg name="offset0" type="int"/>
|
|
||||||
<arg name="stride0" type="int"/>
|
|
||||||
<arg name="offset1" type="int"/>
|
|
||||||
<arg name="stride1" type="int"/>
|
|
||||||
<arg name="offset2" type="int"/>
|
|
||||||
<arg name="stride2" type="int"/>
|
|
||||||
</request>
|
|
||||||
|
|
||||||
<!-- Notification of the path of the drm device which is used by
|
|
||||||
the server. The client should use this device for creating
|
|
||||||
local buffers. Only buffers created from this device should
|
|
||||||
be be passed to the server using this drm object's
|
|
||||||
create_buffer request. -->
|
|
||||||
<event name="device">
|
|
||||||
<arg name="name" type="string"/>
|
|
||||||
</event>
|
|
||||||
|
|
||||||
<event name="format">
|
|
||||||
<arg name="format" type="uint"/>
|
|
||||||
</event>
|
|
||||||
|
|
||||||
<!-- Raised if the authenticate request succeeded -->
|
|
||||||
<event name="authenticated"/>
|
|
||||||
|
|
||||||
<enum name="capability" since="2">
|
|
||||||
<description summary="wl_drm capability bitmask">
|
|
||||||
Bitmask of capabilities.
|
|
||||||
</description>
|
|
||||||
<entry name="prime" value="1" summary="wl_drm prime available"/>
|
|
||||||
</enum>
|
|
||||||
|
|
||||||
<event name="capabilities">
|
|
||||||
<arg name="value" type="uint"/>
|
|
||||||
</event>
|
|
||||||
|
|
||||||
<!-- Version 2 additions -->
|
|
||||||
|
|
||||||
<!-- Create a wayland buffer for the prime fd. Use for regular and planar
|
|
||||||
buffers. Pass 0 for offset and stride for unused planes. -->
|
|
||||||
<request name="create_prime_buffer" since="2">
|
|
||||||
<arg name="id" type="new_id" interface="wl_buffer"/>
|
|
||||||
<arg name="name" type="fd"/>
|
|
||||||
<arg name="width" type="int"/>
|
|
||||||
<arg name="height" type="int"/>
|
|
||||||
<arg name="format" type="uint"/>
|
|
||||||
<arg name="offset0" type="int"/>
|
|
||||||
<arg name="stride0" type="int"/>
|
|
||||||
<arg name="offset1" type="int"/>
|
|
||||||
<arg name="stride1" type="int"/>
|
|
||||||
<arg name="offset2" type="int"/>
|
|
||||||
<arg name="stride2" type="int"/>
|
|
||||||
</request>
|
|
||||||
|
|
||||||
</interface>
|
|
||||||
|
|
||||||
</protocol>
|
|
||||||
@@ -1,156 +0,0 @@
|
|||||||
use smithay::{
|
|
||||||
backend::input::KeyState,
|
|
||||||
desktop::{PopupKind, Window},
|
|
||||||
input::{
|
|
||||||
keyboard::{KeyboardTarget, KeysymHandle, ModifiersState},
|
|
||||||
pointer::{AxisFrame, ButtonEvent, MotionEvent, PointerTarget, RelativeMotionEvent},
|
|
||||||
Seat,
|
|
||||||
},
|
|
||||||
reexports::wayland_server::{backend::ObjectId, protocol::wl_surface::WlSurface},
|
|
||||||
utils::{IsAlive, Serial},
|
|
||||||
wayland::seat::WaylandFocus,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
|
||||||
pub enum FocusTarget {
|
|
||||||
Wayland(Window),
|
|
||||||
Popup(PopupKind),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IsAlive for FocusTarget {
|
|
||||||
fn alive(&self) -> bool {
|
|
||||||
match self {
|
|
||||||
FocusTarget::Wayland(w) => w.alive(),
|
|
||||||
FocusTarget::Popup(p) => p.alive(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Window> for FocusTarget {
|
|
||||||
fn from(w: Window) -> Self {
|
|
||||||
FocusTarget::Wayland(w)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<PopupKind> for FocusTarget {
|
|
||||||
fn from(p: PopupKind) -> Self {
|
|
||||||
FocusTarget::Popup(p)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl KeyboardTarget<super::State> for FocusTarget {
|
|
||||||
fn enter(
|
|
||||||
&self,
|
|
||||||
seat: &Seat<super::State>,
|
|
||||||
data: &mut super::State,
|
|
||||||
keys: Vec<KeysymHandle<'_>>,
|
|
||||||
serial: Serial,
|
|
||||||
) {
|
|
||||||
match self {
|
|
||||||
FocusTarget::Wayland(w) => KeyboardTarget::enter(w, seat, data, keys, serial),
|
|
||||||
FocusTarget::Popup(p) => {
|
|
||||||
KeyboardTarget::enter(p.wl_surface(), seat, data, keys, serial)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn leave(&self, seat: &Seat<super::State>, data: &mut super::State, serial: Serial) {
|
|
||||||
match self {
|
|
||||||
FocusTarget::Wayland(w) => KeyboardTarget::leave(w, seat, data, serial),
|
|
||||||
FocusTarget::Popup(p) => KeyboardTarget::leave(p.wl_surface(), seat, data, serial),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn key(
|
|
||||||
&self,
|
|
||||||
seat: &Seat<super::State>,
|
|
||||||
data: &mut super::State,
|
|
||||||
key: KeysymHandle<'_>,
|
|
||||||
state: KeyState,
|
|
||||||
serial: Serial,
|
|
||||||
time: u32,
|
|
||||||
) {
|
|
||||||
match self {
|
|
||||||
FocusTarget::Wayland(w) => w.key(seat, data, key, state, serial, time),
|
|
||||||
FocusTarget::Popup(p) => p.wl_surface().key(seat, data, key, state, serial, time),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn modifiers(
|
|
||||||
&self,
|
|
||||||
seat: &Seat<super::State>,
|
|
||||||
data: &mut super::State,
|
|
||||||
modifiers: ModifiersState,
|
|
||||||
serial: Serial,
|
|
||||||
) {
|
|
||||||
match self {
|
|
||||||
FocusTarget::Wayland(w) => w.modifiers(seat, data, modifiers, serial),
|
|
||||||
FocusTarget::Popup(p) => p.wl_surface().modifiers(seat, data, modifiers, serial),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PointerTarget<super::State> for FocusTarget {
|
|
||||||
fn enter(&self, seat: &Seat<super::State>, data: &mut super::State, event: &MotionEvent) {
|
|
||||||
match self {
|
|
||||||
FocusTarget::Wayland(w) => PointerTarget::enter(w, seat, data, event),
|
|
||||||
FocusTarget::Popup(p) => PointerTarget::enter(p.wl_surface(), seat, data, event),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn motion(&self, seat: &Seat<super::State>, data: &mut super::State, event: &MotionEvent) {
|
|
||||||
match self {
|
|
||||||
FocusTarget::Wayland(w) => w.motion(seat, data, event),
|
|
||||||
FocusTarget::Popup(p) => p.wl_surface().motion(seat, data, event),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn relative_motion(
|
|
||||||
&self,
|
|
||||||
seat: &Seat<super::State>,
|
|
||||||
data: &mut super::State,
|
|
||||||
event: &RelativeMotionEvent,
|
|
||||||
) {
|
|
||||||
match self {
|
|
||||||
FocusTarget::Wayland(w) => w.relative_motion(seat, data, event),
|
|
||||||
FocusTarget::Popup(p) => p.wl_surface().relative_motion(seat, data, event),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn button(&self, seat: &Seat<super::State>, data: &mut super::State, event: &ButtonEvent) {
|
|
||||||
match self {
|
|
||||||
FocusTarget::Wayland(w) => w.button(seat, data, event),
|
|
||||||
FocusTarget::Popup(p) => p.wl_surface().button(seat, data, event),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn axis(&self, seat: &Seat<super::State>, data: &mut super::State, frame: AxisFrame) {
|
|
||||||
match self {
|
|
||||||
FocusTarget::Wayland(w) => w.axis(seat, data, frame),
|
|
||||||
FocusTarget::Popup(p) => p.wl_surface().axis(seat, data, frame),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn leave(&self, seat: &Seat<super::State>, data: &mut super::State, serial: Serial, time: u32) {
|
|
||||||
match self {
|
|
||||||
FocusTarget::Wayland(w) => PointerTarget::leave(w, seat, data, serial, time),
|
|
||||||
FocusTarget::Popup(p) => PointerTarget::leave(p.wl_surface(), seat, data, serial, time),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WaylandFocus for FocusTarget {
|
|
||||||
fn wl_surface(&self) -> Option<WlSurface> {
|
|
||||||
match self {
|
|
||||||
FocusTarget::Wayland(w) => w.wl_surface(),
|
|
||||||
FocusTarget::Popup(p) => Some(p.wl_surface().clone()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn same_client_as(&self, object_id: &ObjectId) -> bool {
|
|
||||||
match self {
|
|
||||||
FocusTarget::Wayland(w) => w.same_client_as(object_id),
|
|
||||||
FocusTarget::Popup(p) => p.wl_surface().same_client_as(object_id),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,264 +0,0 @@
|
|||||||
use super::{focus::FocusTarget, State};
|
|
||||||
use smithay::{
|
|
||||||
backend::{
|
|
||||||
input::{
|
|
||||||
Axis, AxisSource, Event, InputEvent, KeyState, KeyboardKeyEvent, PointerAxisEvent,
|
|
||||||
PointerButtonEvent, PointerMotionEvent,
|
|
||||||
},
|
|
||||||
libinput::LibinputInputBackend,
|
|
||||||
},
|
|
||||||
input::{
|
|
||||||
keyboard::{keysyms, FilterResult},
|
|
||||||
pointer::{AxisFrame, ButtonEvent, MotionEvent, RelativeMotionEvent},
|
|
||||||
},
|
|
||||||
reexports::{
|
|
||||||
input::LibinputInterface,
|
|
||||||
nix::{fcntl, fcntl::OFlag, sys::stat},
|
|
||||||
wayland_server::protocol::wl_pointer,
|
|
||||||
},
|
|
||||||
utils::{Logical, Point, Serial, SERIAL_COUNTER},
|
|
||||||
};
|
|
||||||
use std::{
|
|
||||||
os::{fd::FromRawFd, unix::io::OwnedFd},
|
|
||||||
path::Path,
|
|
||||||
time::Instant,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub struct NixInterface;
|
|
||||||
|
|
||||||
impl LibinputInterface for NixInterface {
|
|
||||||
fn open_restricted(&mut self, path: &Path, flags: i32) -> Result<OwnedFd, i32> {
|
|
||||||
fcntl::open(path, OFlag::from_bits_truncate(flags), stat::Mode::empty())
|
|
||||||
.map(|fd| unsafe { OwnedFd::from_raw_fd(fd) })
|
|
||||||
.map_err(|err| err as i32)
|
|
||||||
}
|
|
||||||
fn close_restricted(&mut self, fd: OwnedFd) {
|
|
||||||
let _ = fd;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl State {
|
|
||||||
pub fn process_input_event(&mut self, event: InputEvent<LibinputInputBackend>) {
|
|
||||||
match event {
|
|
||||||
InputEvent::Keyboard { event, .. } => {
|
|
||||||
let keycode = event.key_code();
|
|
||||||
let state = event.state();
|
|
||||||
let serial = SERIAL_COUNTER.next_serial();
|
|
||||||
let time = event.time_msec();
|
|
||||||
let keyboard = self.seat.get_keyboard().unwrap();
|
|
||||||
|
|
||||||
keyboard.input::<(), _>(
|
|
||||||
self,
|
|
||||||
keycode,
|
|
||||||
state,
|
|
||||||
serial,
|
|
||||||
time,
|
|
||||||
|data, modifiers, handle| {
|
|
||||||
if state == KeyState::Pressed {
|
|
||||||
if modifiers.ctrl
|
|
||||||
&& modifiers.shift
|
|
||||||
&& !modifiers.alt
|
|
||||||
&& !modifiers.logo
|
|
||||||
{
|
|
||||||
match handle.modified_sym() {
|
|
||||||
keysyms::KEY_Tab => {
|
|
||||||
if let Some(element) = data.space.elements().last().cloned()
|
|
||||||
{
|
|
||||||
data.surpressed_keys.insert(keysyms::KEY_Tab);
|
|
||||||
let location =
|
|
||||||
data.space.element_location(&element).unwrap();
|
|
||||||
data.space.map_element(element.clone(), location, true);
|
|
||||||
data.seat.get_keyboard().unwrap().set_focus(
|
|
||||||
data,
|
|
||||||
Some(FocusTarget::from(element)),
|
|
||||||
serial,
|
|
||||||
);
|
|
||||||
return FilterResult::Intercept(());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
keysyms::KEY_Q => {
|
|
||||||
if let Some(target) =
|
|
||||||
data.seat.get_keyboard().unwrap().current_focus()
|
|
||||||
{
|
|
||||||
match target {
|
|
||||||
FocusTarget::Wayland(window) => {
|
|
||||||
window.toplevel().send_close();
|
|
||||||
}
|
|
||||||
_ => return FilterResult::Forward,
|
|
||||||
};
|
|
||||||
data.surpressed_keys.insert(keysyms::KEY_Q);
|
|
||||||
return FilterResult::Intercept(());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if data.surpressed_keys.remove(&handle.modified_sym()) {
|
|
||||||
return FilterResult::Intercept(());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FilterResult::Forward
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
InputEvent::PointerMotion { event, .. } => {
|
|
||||||
self.last_pointer_movement = Instant::now();
|
|
||||||
let serial = SERIAL_COUNTER.next_serial();
|
|
||||||
let delta = event.delta();
|
|
||||||
self.pointer_location += delta;
|
|
||||||
self.pointer_location = self.clamp_coords(self.pointer_location);
|
|
||||||
|
|
||||||
let pointer = self.seat.get_pointer().unwrap();
|
|
||||||
let under = self
|
|
||||||
.space
|
|
||||||
.element_under(self.pointer_location)
|
|
||||||
.map(|(w, pos)| (w.clone().into(), pos));
|
|
||||||
pointer.motion(
|
|
||||||
self,
|
|
||||||
under.clone(),
|
|
||||||
&MotionEvent {
|
|
||||||
location: self.pointer_location,
|
|
||||||
serial,
|
|
||||||
time: event.time_msec(),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
pointer.relative_motion(
|
|
||||||
self,
|
|
||||||
under,
|
|
||||||
&RelativeMotionEvent {
|
|
||||||
delta,
|
|
||||||
delta_unaccel: event.delta_unaccel(),
|
|
||||||
utime: event.time(),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
InputEvent::PointerMotionAbsolute { event } => {
|
|
||||||
self.last_pointer_movement = Instant::now();
|
|
||||||
let serial = SERIAL_COUNTER.next_serial();
|
|
||||||
if let Some(output) = self.output.as_ref() {
|
|
||||||
let output_size = output
|
|
||||||
.current_mode()
|
|
||||||
.unwrap()
|
|
||||||
.size
|
|
||||||
.to_f64()
|
|
||||||
.to_logical(output.current_scale().fractional_scale())
|
|
||||||
.to_i32_round();
|
|
||||||
self.pointer_location = (
|
|
||||||
event.absolute_x_transformed(output_size.w),
|
|
||||||
event.absolute_y_transformed(output_size.h),
|
|
||||||
)
|
|
||||||
.into();
|
|
||||||
|
|
||||||
let pointer = self.seat.get_pointer().unwrap();
|
|
||||||
let under = self
|
|
||||||
.space
|
|
||||||
.element_under(self.pointer_location)
|
|
||||||
.map(|(w, pos)| (w.clone().into(), pos));
|
|
||||||
pointer.motion(
|
|
||||||
self,
|
|
||||||
under.clone(),
|
|
||||||
&MotionEvent {
|
|
||||||
location: self.pointer_location,
|
|
||||||
serial,
|
|
||||||
time: event.time_msec(),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
InputEvent::PointerButton { event, .. } => {
|
|
||||||
self.last_pointer_movement = Instant::now();
|
|
||||||
let serial = SERIAL_COUNTER.next_serial();
|
|
||||||
let button = event.button_code();
|
|
||||||
|
|
||||||
let state = wl_pointer::ButtonState::from(event.state());
|
|
||||||
if wl_pointer::ButtonState::Pressed == state {
|
|
||||||
self.update_keyboard_focus(serial);
|
|
||||||
};
|
|
||||||
self.seat.get_pointer().unwrap().button(
|
|
||||||
self,
|
|
||||||
&ButtonEvent {
|
|
||||||
button,
|
|
||||||
state: state.try_into().unwrap(),
|
|
||||||
serial,
|
|
||||||
time: event.time_msec(),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
InputEvent::PointerAxis { event, .. } => {
|
|
||||||
self.last_pointer_movement = Instant::now();
|
|
||||||
let horizontal_amount = event
|
|
||||||
.amount(Axis::Horizontal)
|
|
||||||
.or_else(|| event.amount_discrete(Axis::Horizontal).map(|x| x * 2.0))
|
|
||||||
.unwrap_or(0.0);
|
|
||||||
let vertical_amount = event
|
|
||||||
.amount(Axis::Vertical)
|
|
||||||
.or_else(|| event.amount_discrete(Axis::Vertical).map(|y| y * 2.0))
|
|
||||||
.unwrap_or(0.0);
|
|
||||||
let horizontal_amount_discrete = event.amount_discrete(Axis::Horizontal);
|
|
||||||
let vertical_amount_discrete = event.amount_discrete(Axis::Vertical);
|
|
||||||
|
|
||||||
{
|
|
||||||
let mut frame = AxisFrame::new(event.time_msec()).source(event.source());
|
|
||||||
if horizontal_amount != 0.0 {
|
|
||||||
frame = frame.value(Axis::Horizontal, horizontal_amount);
|
|
||||||
if let Some(discrete) = horizontal_amount_discrete {
|
|
||||||
frame = frame.discrete(Axis::Horizontal, discrete as i32);
|
|
||||||
}
|
|
||||||
} else if event.source() == AxisSource::Finger {
|
|
||||||
frame = frame.stop(Axis::Horizontal);
|
|
||||||
}
|
|
||||||
if vertical_amount != 0.0 {
|
|
||||||
frame = frame.value(Axis::Vertical, vertical_amount);
|
|
||||||
if let Some(discrete) = vertical_amount_discrete {
|
|
||||||
frame = frame.discrete(Axis::Vertical, discrete as i32);
|
|
||||||
}
|
|
||||||
} else if event.source() == AxisSource::Finger {
|
|
||||||
frame = frame.stop(Axis::Vertical);
|
|
||||||
}
|
|
||||||
self.seat.get_pointer().unwrap().axis(self, frame);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn clamp_coords(&self, pos: Point<f64, Logical>) -> Point<f64, Logical> {
|
|
||||||
if let Some(output) = self.output.as_ref() {
|
|
||||||
if let Some(mode) = output.current_mode() {
|
|
||||||
return (
|
|
||||||
pos.x.max(0.0).min(mode.size.w as f64),
|
|
||||||
pos.y.max(0.0).min(mode.size.h as f64),
|
|
||||||
)
|
|
||||||
.into();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pos
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_keyboard_focus(&mut self, serial: Serial) {
|
|
||||||
let pointer = self.seat.get_pointer().unwrap();
|
|
||||||
let keyboard = self.seat.get_keyboard().unwrap();
|
|
||||||
// change the keyboard focus unless the pointer or keyboard is grabbed
|
|
||||||
// We test for any matching surface type here but always use the root
|
|
||||||
// (in case of a window the toplevel) surface for the focus.
|
|
||||||
// So for example if a user clicks on a subsurface or popup the toplevel
|
|
||||||
// will receive the keyboard focus. Directly assigning the focus to the
|
|
||||||
// matching surface leads to issues with clients dismissing popups and
|
|
||||||
// subsurface menus (for example firefox-wayland).
|
|
||||||
// see here for a discussion about that issue:
|
|
||||||
// https://gitlab.freedesktop.org/wayland/wayland/-/issues/294
|
|
||||||
if !pointer.is_grabbed() && !keyboard.is_grabbed() {
|
|
||||||
if let Some((window, _)) = self
|
|
||||||
.space
|
|
||||||
.element_under(self.pointer_location)
|
|
||||||
.map(|(w, p)| (w.clone(), p))
|
|
||||||
{
|
|
||||||
self.space.raise_element(&window, true);
|
|
||||||
keyboard.set_focus(self, Some(FocusTarget::from(window)), serial);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,521 +0,0 @@
|
|||||||
use std::{
|
|
||||||
collections::{HashMap, HashSet},
|
|
||||||
ffi::CString,
|
|
||||||
os::unix::prelude::AsRawFd,
|
|
||||||
sync::{mpsc::Sender, Arc, Mutex, Weak},
|
|
||||||
time::{Duration, Instant},
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::Command;
|
|
||||||
use gst_video::VideoInfo;
|
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use smithay::{
|
|
||||||
backend::{
|
|
||||||
allocator::dmabuf::Dmabuf,
|
|
||||||
drm::{DrmNode, NodeType},
|
|
||||||
egl::{EGLContext, EGLDevice, EGLDisplay},
|
|
||||||
libinput::LibinputInputBackend,
|
|
||||||
renderer::{
|
|
||||||
damage::{DamageTrackedRenderer, DamageTrackedRendererError as DTRError},
|
|
||||||
element::memory::MemoryRenderBuffer,
|
|
||||||
gles2::{Gles2Renderbuffer, Gles2Renderer},
|
|
||||||
Bind, Offscreen,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
desktop::{
|
|
||||||
utils::{
|
|
||||||
send_frames_surface_tree, surface_presentation_feedback_flags_from_states,
|
|
||||||
surface_primary_scanout_output, update_surface_primary_scanout_output,
|
|
||||||
OutputPresentationFeedback,
|
|
||||||
},
|
|
||||||
PopupManager, Space, Window,
|
|
||||||
},
|
|
||||||
input::{keyboard::XkbConfig, pointer::CursorImageStatus, Seat, SeatState},
|
|
||||||
output::{Mode as OutputMode, Output, PhysicalProperties, Subpixel},
|
|
||||||
reexports::{
|
|
||||||
calloop::{
|
|
||||||
channel::{Channel, Event},
|
|
||||||
generic::Generic,
|
|
||||||
timer::{TimeoutAction, Timer},
|
|
||||||
EventLoop, Interest, LoopHandle, Mode, PostAction,
|
|
||||||
},
|
|
||||||
input::Libinput,
|
|
||||||
wayland_protocols::wp::presentation_time::server::wp_presentation_feedback,
|
|
||||||
wayland_server::{
|
|
||||||
backend::{ClientData, ClientId, DisconnectReason},
|
|
||||||
Display, DisplayHandle,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
utils::{Clock, Logical, Monotonic, Physical, Point, Rectangle, Size, Transform},
|
|
||||||
wayland::{
|
|
||||||
compositor::{with_states, CompositorState},
|
|
||||||
data_device::DataDeviceState,
|
|
||||||
dmabuf::{DmabufGlobal, DmabufState},
|
|
||||||
output::OutputManagerState,
|
|
||||||
presentation::PresentationState,
|
|
||||||
shell::xdg::{XdgShellState, XdgToplevelSurfaceData},
|
|
||||||
shm::ShmState,
|
|
||||||
socket::ListeningSocketSource,
|
|
||||||
viewporter::ViewporterState,
|
|
||||||
relative_pointer::RelativePointerManagerState,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
use wayland_backend::server::GlobalId;
|
|
||||||
|
|
||||||
mod focus;
|
|
||||||
mod input;
|
|
||||||
mod rendering;
|
|
||||||
|
|
||||||
pub use self::focus::*;
|
|
||||||
pub use self::input::*;
|
|
||||||
pub use self::rendering::*;
|
|
||||||
use crate::{utils::RenderTarget, wayland::protocols::wl_drm::create_drm_global};
|
|
||||||
|
|
||||||
static EGL_DISPLAYS: Lazy<Mutex<HashMap<Option<DrmNode>, Weak<EGLDisplay>>>> =
|
|
||||||
Lazy::new(|| Mutex::new(HashMap::new()));
|
|
||||||
|
|
||||||
struct ClientState;
|
|
||||||
impl ClientData for ClientState {
|
|
||||||
fn initialized(&self, _client_id: ClientId) {}
|
|
||||||
fn disconnected(&self, _client_id: ClientId, _reason: DisconnectReason) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) struct Data {
|
|
||||||
pub(crate) display: Display<State>,
|
|
||||||
pub(crate) state: State,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) struct State {
|
|
||||||
handle: LoopHandle<'static, Data>,
|
|
||||||
should_quit: bool,
|
|
||||||
clock: Clock<Monotonic>,
|
|
||||||
|
|
||||||
// render
|
|
||||||
dtr: Option<DamageTrackedRenderer>,
|
|
||||||
renderbuffer: Option<Gles2Renderbuffer>,
|
|
||||||
pub renderer: Gles2Renderer,
|
|
||||||
egl_display_ref: Arc<EGLDisplay>,
|
|
||||||
dmabuf_global: Option<(DmabufGlobal, GlobalId)>,
|
|
||||||
last_render: Option<Instant>,
|
|
||||||
|
|
||||||
// management
|
|
||||||
pub output: Option<Output>,
|
|
||||||
pub video_info: Option<VideoInfo>,
|
|
||||||
pub seat: Seat<Self>,
|
|
||||||
pub space: Space<Window>,
|
|
||||||
pub popups: PopupManager,
|
|
||||||
pointer_location: Point<f64, Logical>,
|
|
||||||
last_pointer_movement: Instant,
|
|
||||||
cursor_element: MemoryRenderBuffer,
|
|
||||||
pub cursor_state: CursorImageStatus,
|
|
||||||
surpressed_keys: HashSet<u32>,
|
|
||||||
pub pending_windows: Vec<Window>,
|
|
||||||
input_context: Libinput,
|
|
||||||
|
|
||||||
// wayland state
|
|
||||||
pub dh: DisplayHandle,
|
|
||||||
pub compositor_state: CompositorState,
|
|
||||||
pub data_device_state: DataDeviceState,
|
|
||||||
pub dmabuf_state: DmabufState,
|
|
||||||
output_state: OutputManagerState,
|
|
||||||
presentation_state: PresentationState,
|
|
||||||
relative_ptr_state: RelativePointerManagerState,
|
|
||||||
pub seat_state: SeatState<Self>,
|
|
||||||
pub shell_state: XdgShellState,
|
|
||||||
pub shm_state: ShmState,
|
|
||||||
viewporter_state: ViewporterState,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_egl_device_for_node(drm_node: &DrmNode) -> EGLDevice {
|
|
||||||
let drm_node = drm_node
|
|
||||||
.node_with_type(NodeType::Render)
|
|
||||||
.and_then(Result::ok)
|
|
||||||
.unwrap_or(drm_node.clone());
|
|
||||||
EGLDevice::enumerate()
|
|
||||||
.expect("Failed to enumerate EGLDevices")
|
|
||||||
.find(|d| d.try_get_render_node().unwrap_or_default() == Some(drm_node))
|
|
||||||
.expect("Unable to find EGLDevice for drm-node")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn init(
|
|
||||||
command_src: Channel<Command>,
|
|
||||||
render: impl Into<RenderTarget>,
|
|
||||||
devices_tx: Sender<Vec<CString>>,
|
|
||||||
envs_tx: Sender<Vec<CString>>,
|
|
||||||
) {
|
|
||||||
let clock = Clock::new().expect("Failed to initialize clock");
|
|
||||||
let mut display = Display::<State>::new().unwrap();
|
|
||||||
let dh = display.handle();
|
|
||||||
|
|
||||||
// init state
|
|
||||||
let compositor_state = CompositorState::new::<State>(&dh);
|
|
||||||
let data_device_state = DataDeviceState::new::<State>(&dh);
|
|
||||||
let mut dmabuf_state = DmabufState::new();
|
|
||||||
let output_state = OutputManagerState::new_with_xdg_output::<State>(&dh);
|
|
||||||
let presentation_state = PresentationState::new::<State>(&dh, clock.id() as _);
|
|
||||||
let relative_ptr_state = RelativePointerManagerState::new::<State>(&dh);
|
|
||||||
let mut seat_state = SeatState::new();
|
|
||||||
let shell_state = XdgShellState::new::<State>(&dh);
|
|
||||||
let viewporter_state = ViewporterState::new::<State>(&dh);
|
|
||||||
|
|
||||||
let render_target = render.into();
|
|
||||||
let render_node: Option<DrmNode> = render_target.clone().into();
|
|
||||||
|
|
||||||
// init render backend
|
|
||||||
let (egl_display_ref, context) = {
|
|
||||||
let mut displays = EGL_DISPLAYS.lock().unwrap();
|
|
||||||
let maybe_display = displays
|
|
||||||
.get(&render_node)
|
|
||||||
.and_then(|weak_display| weak_display.upgrade());
|
|
||||||
|
|
||||||
let egl = match maybe_display {
|
|
||||||
Some(display) => display,
|
|
||||||
None => {
|
|
||||||
let device = match render_node.as_ref() {
|
|
||||||
Some(render_node) => get_egl_device_for_node(render_node),
|
|
||||||
None => EGLDevice::enumerate()
|
|
||||||
.expect("Failed to enumerate EGLDevices")
|
|
||||||
.find(|device| {
|
|
||||||
device
|
|
||||||
.extensions()
|
|
||||||
.iter()
|
|
||||||
.any(|e| e == "EGL_MESA_device_software")
|
|
||||||
})
|
|
||||||
.expect("Failed to find software device"),
|
|
||||||
};
|
|
||||||
let display =
|
|
||||||
Arc::new(EGLDisplay::new(device).expect("Failed to initialize EGL display"));
|
|
||||||
displays.insert(render_node, Arc::downgrade(&display));
|
|
||||||
display
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let context = EGLContext::new(&egl).expect("Failed to initialize EGL context");
|
|
||||||
(egl, context)
|
|
||||||
};
|
|
||||||
let renderer = unsafe { Gles2Renderer::new(context) }.expect("Failed to initialize renderer");
|
|
||||||
let _ = devices_tx.send(render_target.as_devices());
|
|
||||||
|
|
||||||
let shm_state = ShmState::new::<State>(&dh, vec![]);
|
|
||||||
let dmabuf_global = if let RenderTarget::Hardware(node) = render_target {
|
|
||||||
let formats = Bind::<Dmabuf>::supported_formats(&renderer)
|
|
||||||
.expect("Failed to query formats")
|
|
||||||
.into_iter()
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
// dma buffer
|
|
||||||
let dmabuf_global = dmabuf_state.create_global::<State>(&dh, formats.clone());
|
|
||||||
// wl_drm (mesa protocol, so we don't need EGL_WL_bind_display)
|
|
||||||
let wl_drm_global = create_drm_global::<State>(
|
|
||||||
&dh,
|
|
||||||
node.dev_path().expect("Failed to determine DrmNode path?"),
|
|
||||||
formats.clone(),
|
|
||||||
&dmabuf_global,
|
|
||||||
);
|
|
||||||
|
|
||||||
Some((dmabuf_global, wl_drm_global))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
let cursor_element =
|
|
||||||
MemoryRenderBuffer::from_memory(CURSOR_DATA_BYTES, (64, 64), 1, Transform::Normal, None);
|
|
||||||
|
|
||||||
// init input backend
|
|
||||||
let libinput_context = Libinput::new_from_path(NixInterface);
|
|
||||||
let input_context = libinput_context.clone();
|
|
||||||
let libinput_backend = LibinputInputBackend::new(libinput_context);
|
|
||||||
|
|
||||||
let space = Space::default();
|
|
||||||
|
|
||||||
let mut seat = seat_state.new_wl_seat(&dh, "seat-0");
|
|
||||||
seat.add_keyboard(XkbConfig::default(), 200, 25)
|
|
||||||
.expect("Failed to add keyboard to seat");
|
|
||||||
seat.add_pointer();
|
|
||||||
|
|
||||||
let mut event_loop =
|
|
||||||
EventLoop::<Data>::try_new_high_precision().expect("Unable to create event_loop");
|
|
||||||
let state = State {
|
|
||||||
handle: event_loop.handle(),
|
|
||||||
should_quit: false,
|
|
||||||
clock,
|
|
||||||
|
|
||||||
renderer,
|
|
||||||
egl_display_ref,
|
|
||||||
dtr: None,
|
|
||||||
renderbuffer: None,
|
|
||||||
dmabuf_global,
|
|
||||||
video_info: None,
|
|
||||||
last_render: None,
|
|
||||||
|
|
||||||
space,
|
|
||||||
popups: PopupManager::default(),
|
|
||||||
seat,
|
|
||||||
output: None,
|
|
||||||
pointer_location: (0., 0.).into(),
|
|
||||||
last_pointer_movement: Instant::now(),
|
|
||||||
cursor_element,
|
|
||||||
cursor_state: CursorImageStatus::Default,
|
|
||||||
surpressed_keys: HashSet::new(),
|
|
||||||
pending_windows: Vec::new(),
|
|
||||||
input_context,
|
|
||||||
|
|
||||||
dh: display.handle(),
|
|
||||||
compositor_state,
|
|
||||||
data_device_state,
|
|
||||||
dmabuf_state,
|
|
||||||
output_state,
|
|
||||||
presentation_state,
|
|
||||||
relative_ptr_state,
|
|
||||||
seat_state,
|
|
||||||
shell_state,
|
|
||||||
shm_state,
|
|
||||||
viewporter_state,
|
|
||||||
};
|
|
||||||
|
|
||||||
// init event loop
|
|
||||||
event_loop
|
|
||||||
.handle()
|
|
||||||
.insert_source(libinput_backend, move |event, _, data| {
|
|
||||||
data.state.process_input_event(event)
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
event_loop
|
|
||||||
.handle()
|
|
||||||
.insert_source(command_src, move |event, _, data| {
|
|
||||||
match event {
|
|
||||||
Event::Msg(Command::VideoInfo(info)) => {
|
|
||||||
let size: Size<i32, Physical> =
|
|
||||||
(info.width() as i32, info.height() as i32).into();
|
|
||||||
let framerate = info.fps();
|
|
||||||
let duration = Duration::from_secs_f64(
|
|
||||||
framerate.numer() as f64 / framerate.denom() as f64,
|
|
||||||
);
|
|
||||||
|
|
||||||
// init wayland objects
|
|
||||||
let output = data.state.output.get_or_insert_with(|| {
|
|
||||||
let output = Output::new(
|
|
||||||
"HEADLESS-1".into(),
|
|
||||||
PhysicalProperties {
|
|
||||||
make: "Virtual".into(),
|
|
||||||
model: "Wolf".into(),
|
|
||||||
size: (0, 0).into(),
|
|
||||||
subpixel: Subpixel::Unknown,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
output.create_global::<State>(&data.display.handle());
|
|
||||||
output
|
|
||||||
});
|
|
||||||
let mode = OutputMode {
|
|
||||||
size: size.into(),
|
|
||||||
refresh: (duration.as_secs_f64() * 1000.0).round() as i32,
|
|
||||||
};
|
|
||||||
output.change_current_state(Some(mode), None, None, None);
|
|
||||||
output.set_preferred(mode);
|
|
||||||
let dtr = DamageTrackedRenderer::from_output(&output);
|
|
||||||
|
|
||||||
data.state.space.map_output(&output, (0, 0));
|
|
||||||
data.state.dtr = Some(dtr);
|
|
||||||
data.state.pointer_location = (size.w as f64 / 2.0, size.h as f64 / 2.0).into();
|
|
||||||
data.state.renderbuffer = Some(
|
|
||||||
data.state
|
|
||||||
.renderer
|
|
||||||
.create_buffer((info.width() as i32, info.height() as i32).into())
|
|
||||||
.expect("Failed to create renderbuffer"),
|
|
||||||
);
|
|
||||||
data.state.video_info = Some(info);
|
|
||||||
|
|
||||||
let new_size = size
|
|
||||||
.to_f64()
|
|
||||||
.to_logical(output.current_scale().fractional_scale())
|
|
||||||
.to_i32_round();
|
|
||||||
for window in data.state.space.elements() {
|
|
||||||
let toplevel = window.toplevel();
|
|
||||||
let max_size = Rectangle::from_loc_and_size(
|
|
||||||
(0, 0),
|
|
||||||
with_states(toplevel.wl_surface(), |states| {
|
|
||||||
states
|
|
||||||
.data_map
|
|
||||||
.get::<XdgToplevelSurfaceData>()
|
|
||||||
.map(|attrs| attrs.lock().unwrap().max_size)
|
|
||||||
})
|
|
||||||
.unwrap_or(new_size),
|
|
||||||
);
|
|
||||||
|
|
||||||
let new_size = max_size
|
|
||||||
.intersection(Rectangle::from_loc_and_size((0, 0), new_size))
|
|
||||||
.map(|rect| rect.size);
|
|
||||||
toplevel.with_pending_state(|state| state.size = new_size);
|
|
||||||
toplevel.send_configure();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Event::Msg(Command::InputDevice(path)) => {
|
|
||||||
tracing::info!(path, "Adding input device.");
|
|
||||||
data.state.input_context.path_add_device(&path);
|
|
||||||
}
|
|
||||||
Event::Msg(Command::Buffer(buffer_sender)) => {
|
|
||||||
let wait = if let Some(last_render) = data.state.last_render {
|
|
||||||
let framerate = data.state.video_info.as_ref().unwrap().fps();
|
|
||||||
let duration = Duration::from_secs_f64(
|
|
||||||
framerate.denom() as f64 / framerate.numer() as f64,
|
|
||||||
);
|
|
||||||
let time_passed = Instant::now().duration_since(last_render);
|
|
||||||
if time_passed < duration {
|
|
||||||
Some(duration - time_passed)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
let render = move |data: &mut Data, now: Instant| {
|
|
||||||
if let Err(_) = match data.state.create_frame() {
|
|
||||||
Ok((buf, damage, render_element_states)) => {
|
|
||||||
data.state.last_render = Some(now);
|
|
||||||
let res = buffer_sender.send(Ok(buf));
|
|
||||||
|
|
||||||
if let Some(output) = data.state.output.as_ref() {
|
|
||||||
let mut output_presentation_feedback =
|
|
||||||
OutputPresentationFeedback::new(output);
|
|
||||||
for window in data.state.space.elements() {
|
|
||||||
window.with_surfaces(|surface, states| {
|
|
||||||
update_surface_primary_scanout_output(
|
|
||||||
surface,
|
|
||||||
output,
|
|
||||||
states,
|
|
||||||
&render_element_states,
|
|
||||||
|next_output, _, _, _| next_output,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
window.send_frame(
|
|
||||||
output,
|
|
||||||
data.state.clock.now(),
|
|
||||||
Some(Duration::ZERO),
|
|
||||||
|_, _| Some(output.clone()),
|
|
||||||
);
|
|
||||||
window.take_presentation_feedback(
|
|
||||||
&mut output_presentation_feedback,
|
|
||||||
surface_primary_scanout_output,
|
|
||||||
|surface, _| {
|
|
||||||
surface_presentation_feedback_flags_from_states(
|
|
||||||
surface,
|
|
||||||
&render_element_states,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if damage.is_some() {
|
|
||||||
output_presentation_feedback.presented(
|
|
||||||
data.state.clock.now(),
|
|
||||||
output
|
|
||||||
.current_mode()
|
|
||||||
.map(|mode| mode.refresh as u32)
|
|
||||||
.unwrap_or_default(),
|
|
||||||
0,
|
|
||||||
wp_presentation_feedback::Kind::Vsync,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if let CursorImageStatus::Surface(wl_surface) =
|
|
||||||
&data.state.cursor_state
|
|
||||||
{
|
|
||||||
send_frames_surface_tree(
|
|
||||||
wl_surface,
|
|
||||||
output,
|
|
||||||
data.state.clock.now(),
|
|
||||||
None,
|
|
||||||
|_, _| Some(output.clone()),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
res
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
tracing::error!(?err, "Rendering failed.");
|
|
||||||
buffer_sender.send(Err(match err {
|
|
||||||
DTRError::OutputNoMode(_) => unreachable!(),
|
|
||||||
DTRError::Rendering(err) => err.into(),
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
} {
|
|
||||||
data.state.should_quit = true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
match wait {
|
|
||||||
Some(duration) => {
|
|
||||||
if let Err(err) = data.state.handle.insert_source(
|
|
||||||
Timer::from_duration(duration),
|
|
||||||
move |now, _, data| {
|
|
||||||
render(data, now);
|
|
||||||
TimeoutAction::Drop
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
tracing::error!(?err, "Event loop error.");
|
|
||||||
data.state.should_quit = true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
None => render(data, Instant::now()),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
Event::Msg(Command::Quit) | Event::Closed => {
|
|
||||||
data.state.should_quit = true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let source = ListeningSocketSource::new_auto().unwrap();
|
|
||||||
let socket_name = source.socket_name().to_string_lossy().into_owned();
|
|
||||||
tracing::info!(?socket_name, "Listening on wayland socket.");
|
|
||||||
event_loop
|
|
||||||
.handle()
|
|
||||||
.insert_source(source, |client_stream, _, data| {
|
|
||||||
if let Err(err) = data
|
|
||||||
.display
|
|
||||||
.handle()
|
|
||||||
.insert_client(client_stream, std::sync::Arc::new(ClientState))
|
|
||||||
{
|
|
||||||
tracing::error!(?err, "Error adding wayland client.");
|
|
||||||
};
|
|
||||||
})
|
|
||||||
.expect("Failed to init wayland socket source");
|
|
||||||
|
|
||||||
event_loop
|
|
||||||
.handle()
|
|
||||||
.insert_source(
|
|
||||||
Generic::new(
|
|
||||||
display.backend().poll_fd().as_raw_fd(),
|
|
||||||
Interest::READ,
|
|
||||||
Mode::Level,
|
|
||||||
),
|
|
||||||
|_, _, data| {
|
|
||||||
data.display.dispatch_clients(&mut data.state).unwrap();
|
|
||||||
Ok(PostAction::Continue)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.expect("Failed to init wayland server source");
|
|
||||||
|
|
||||||
let env_vars = vec![CString::new(format!("WAYLAND_DISPLAY={}", socket_name)).unwrap()];
|
|
||||||
if let Err(err) = envs_tx.send(env_vars) {
|
|
||||||
tracing::warn!(?err, "Failed to post environment to application.");
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut data = Data { display, state };
|
|
||||||
let signal = event_loop.get_signal();
|
|
||||||
if let Err(err) = event_loop.run(None, &mut data, |data| {
|
|
||||||
data.display
|
|
||||||
.flush_clients()
|
|
||||||
.expect("Failed to flush clients");
|
|
||||||
data.state.space.refresh();
|
|
||||||
data.state.popups.cleanup();
|
|
||||||
|
|
||||||
if data.state.should_quit {
|
|
||||||
signal.stop();
|
|
||||||
}
|
|
||||||
}) {
|
|
||||||
tracing::error!(?err, "Event loop broke.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
use std::time::{Duration, Instant};
|
|
||||||
|
|
||||||
use smithay::{
|
|
||||||
backend::renderer::{
|
|
||||||
damage::DamageTrackedRendererError as DTRError,
|
|
||||||
element::{
|
|
||||||
memory::MemoryRenderBufferRenderElement, surface::WaylandSurfaceRenderElement,
|
|
||||||
RenderElementStates,
|
|
||||||
},
|
|
||||||
gles2::Gles2Renderer,
|
|
||||||
Bind, ExportMem, ImportAll, ImportMem, Renderer, Unbind,
|
|
||||||
},
|
|
||||||
desktop::space::render_output,
|
|
||||||
input::pointer::CursorImageStatus,
|
|
||||||
render_elements,
|
|
||||||
utils::{Physical, Rectangle},
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::State;
|
|
||||||
|
|
||||||
pub const CURSOR_DATA_BYTES: &[u8] = include_bytes!("../../resources/cursor.rgba");
|
|
||||||
|
|
||||||
render_elements! {
|
|
||||||
CursorElement<R> where R: Renderer + ImportAll + ImportMem;
|
|
||||||
Surface=WaylandSurfaceRenderElement<R>,
|
|
||||||
Memory=MemoryRenderBufferRenderElement<R>
|
|
||||||
}
|
|
||||||
|
|
||||||
impl State {
|
|
||||||
pub fn create_frame(
|
|
||||||
&mut self,
|
|
||||||
) -> Result<
|
|
||||||
(
|
|
||||||
gst::Buffer,
|
|
||||||
Option<Vec<Rectangle<i32, Physical>>>,
|
|
||||||
RenderElementStates,
|
|
||||||
),
|
|
||||||
DTRError<Gles2Renderer>,
|
|
||||||
> {
|
|
||||||
assert!(self.output.is_some());
|
|
||||||
assert!(self.dtr.is_some());
|
|
||||||
assert!(self.video_info.is_some());
|
|
||||||
assert!(self.renderbuffer.is_some());
|
|
||||||
|
|
||||||
let elements =
|
|
||||||
if Instant::now().duration_since(self.last_pointer_movement) < Duration::from_secs(5) {
|
|
||||||
match &self.cursor_state {
|
|
||||||
CursorImageStatus::Default => vec![CursorElement::Memory(
|
|
||||||
MemoryRenderBufferRenderElement::from_buffer(
|
|
||||||
&mut self.renderer,
|
|
||||||
self.pointer_location.to_physical_precise_round(1),
|
|
||||||
&self.cursor_element,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.map_err(DTRError::Rendering)?,
|
|
||||||
)],
|
|
||||||
CursorImageStatus::Surface(wl_surface) => {
|
|
||||||
smithay::backend::renderer::element::surface::render_elements_from_surface_tree(
|
|
||||||
&mut self.renderer,
|
|
||||||
wl_surface,
|
|
||||||
self.pointer_location.to_physical_precise_round(1),
|
|
||||||
1.,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
CursorImageStatus::Hidden => vec![],
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
vec![]
|
|
||||||
};
|
|
||||||
|
|
||||||
self.renderer
|
|
||||||
.bind(self.renderbuffer.clone().unwrap())
|
|
||||||
.map_err(DTRError::Rendering)?;
|
|
||||||
let (damage, render_element_states) = render_output(
|
|
||||||
self.output.as_ref().unwrap(),
|
|
||||||
&mut self.renderer,
|
|
||||||
1,
|
|
||||||
[&self.space],
|
|
||||||
&*elements,
|
|
||||||
self.dtr.as_mut().unwrap(),
|
|
||||||
[0.0, 0.0, 0.0, 1.0],
|
|
||||||
)?;
|
|
||||||
|
|
||||||
let mapping = self
|
|
||||||
.renderer
|
|
||||||
.copy_framebuffer(Rectangle::from_loc_and_size(
|
|
||||||
(0, 0),
|
|
||||||
(
|
|
||||||
self.video_info.as_ref().unwrap().width() as i32,
|
|
||||||
self.video_info.as_ref().unwrap().height() as i32,
|
|
||||||
),
|
|
||||||
))
|
|
||||||
.expect("Failed to export framebuffer");
|
|
||||||
let map = self
|
|
||||||
.renderer
|
|
||||||
.map_texture(&mapping)
|
|
||||||
.expect("Failed to download framebuffer");
|
|
||||||
|
|
||||||
let buffer = {
|
|
||||||
let mut buffer = gst::Buffer::with_size(map.len()).expect("failed to create buffer");
|
|
||||||
{
|
|
||||||
let buffer = buffer.get_mut().unwrap();
|
|
||||||
|
|
||||||
let mut vframe = gst_video::VideoFrameRef::from_buffer_ref_writable(
|
|
||||||
buffer,
|
|
||||||
self.video_info.as_ref().unwrap(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
let plane_data = vframe.plane_data_mut(0).unwrap();
|
|
||||||
plane_data.clone_from_slice(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer
|
|
||||||
};
|
|
||||||
self.renderer.unbind().map_err(DTRError::Rendering)?;
|
|
||||||
|
|
||||||
Ok((buffer, damage, render_element_states))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,134 +0,0 @@
|
|||||||
use gst_video::VideoInfo;
|
|
||||||
|
|
||||||
use smithay::backend::drm::CreateDrmNodeError;
|
|
||||||
use smithay::backend::SwapBuffersError;
|
|
||||||
use smithay::reexports::calloop::channel::Sender;
|
|
||||||
|
|
||||||
use std::ffi::{CString};
|
|
||||||
use std::str::FromStr;
|
|
||||||
use std::sync::mpsc::{self, Receiver, SyncSender};
|
|
||||||
use std::thread::JoinHandle;
|
|
||||||
|
|
||||||
use utils::RenderTarget;
|
|
||||||
|
|
||||||
pub(crate) mod comp;
|
|
||||||
pub(crate) mod utils;
|
|
||||||
pub(crate) mod wayland;
|
|
||||||
|
|
||||||
pub(crate) enum Command {
|
|
||||||
InputDevice(String),
|
|
||||||
VideoInfo(VideoInfo),
|
|
||||||
Buffer(SyncSender<Result<gst::Buffer, SwapBuffersError>>),
|
|
||||||
Quit,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct WaylandDisplay {
|
|
||||||
thread_handle: Option<JoinHandle<()>>,
|
|
||||||
command_tx: Sender<Command>,
|
|
||||||
|
|
||||||
pub devices: MaybeRecv<Vec<CString>>,
|
|
||||||
pub envs: MaybeRecv<Vec<CString>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum MaybeRecv<T: Clone> {
|
|
||||||
Rx(Receiver<T>),
|
|
||||||
Value(T),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Clone> MaybeRecv<T> {
|
|
||||||
pub fn get(&mut self) -> &T {
|
|
||||||
match self {
|
|
||||||
MaybeRecv::Rx(recv) => {
|
|
||||||
let value = recv.recv().unwrap();
|
|
||||||
*self = MaybeRecv::Value(value.clone());
|
|
||||||
self.get()
|
|
||||||
}
|
|
||||||
MaybeRecv::Value(val) => val,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WaylandDisplay {
|
|
||||||
pub fn new(render_node: Option<String>) -> Result<WaylandDisplay, CreateDrmNodeError> {
|
|
||||||
let (channel_tx, channel_rx) = std::sync::mpsc::sync_channel(0);
|
|
||||||
let (devices_tx, devices_rx) = std::sync::mpsc::channel();
|
|
||||||
let (envs_tx, envs_rx) = std::sync::mpsc::channel();
|
|
||||||
let render_target = RenderTarget::from_str(
|
|
||||||
&render_node.unwrap_or_else(|| String::from("/dev/dri/renderD128")),
|
|
||||||
)?;
|
|
||||||
|
|
||||||
let thread_handle = std::thread::spawn(move || {
|
|
||||||
if let Err(err) = std::panic::catch_unwind(|| {
|
|
||||||
// calloops channel is not "UnwindSafe", but the std channel is... *sigh* lets workaround it creatively
|
|
||||||
let (command_tx, command_src) = smithay::reexports::calloop::channel::channel();
|
|
||||||
channel_tx.send(command_tx).unwrap();
|
|
||||||
comp::init(command_src, render_target, devices_tx, envs_tx);
|
|
||||||
}) {
|
|
||||||
tracing::error!(?err, "Compositor thread panic'ed!");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let command_tx = channel_rx.recv().unwrap();
|
|
||||||
|
|
||||||
Ok(WaylandDisplay {
|
|
||||||
thread_handle: Some(thread_handle),
|
|
||||||
command_tx,
|
|
||||||
devices: MaybeRecv::Rx(devices_rx),
|
|
||||||
envs: MaybeRecv::Rx(envs_rx),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn devices(&mut self) -> impl Iterator<Item = &str> {
|
|
||||||
self.devices
|
|
||||||
.get()
|
|
||||||
.iter()
|
|
||||||
.map(|string| string.to_str().unwrap())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn env_vars(&mut self) -> impl Iterator<Item = &str> {
|
|
||||||
self.envs
|
|
||||||
.get()
|
|
||||||
.iter()
|
|
||||||
.map(|string| string.to_str().unwrap())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn add_input_device(&self, path: impl Into<String>) {
|
|
||||||
let _ = self.command_tx.send(Command::InputDevice(path.into()));
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_video_info(&self, info: VideoInfo) {
|
|
||||||
let _ = self.command_tx.send(Command::VideoInfo(info));
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn frame(&self) -> Result<gst::Buffer, gst::FlowError> {
|
|
||||||
let (buffer_tx, buffer_rx) = mpsc::sync_channel(0);
|
|
||||||
if let Err(err) = self.command_tx.send(Command::Buffer(buffer_tx)) {
|
|
||||||
tracing::warn!(?err, "Failed to send buffer command.");
|
|
||||||
return Err(gst::FlowError::Eos);
|
|
||||||
}
|
|
||||||
|
|
||||||
match buffer_rx.recv() {
|
|
||||||
Ok(Ok(buffer)) => Ok(buffer),
|
|
||||||
Ok(Err(err)) => match err {
|
|
||||||
SwapBuffersError::AlreadySwapped => unreachable!(),
|
|
||||||
SwapBuffersError::ContextLost(_) => Err(gst::FlowError::Eos),
|
|
||||||
SwapBuffersError::TemporaryFailure(_) => Err(gst::FlowError::Error),
|
|
||||||
},
|
|
||||||
Err(err) => {
|
|
||||||
tracing::warn!(?err, "Failed to recv buffer ack.");
|
|
||||||
Err(gst::FlowError::Error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Drop for WaylandDisplay {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
if let Err(err) = self.command_tx.send(Command::Quit) {
|
|
||||||
tracing::warn!("Failed to send stop command: {}", err);
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
if self.thread_handle.take().unwrap().join().is_err() {
|
|
||||||
tracing::warn!("Failed to join compositor thread");
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
mod target;
|
|
||||||
|
|
||||||
pub use self::target::*;
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
use std::{ffi::CString, os::unix::fs::MetadataExt, str::FromStr};
|
|
||||||
|
|
||||||
use smithay::{
|
|
||||||
backend::{
|
|
||||||
drm::{CreateDrmNodeError, DrmNode, NodeType},
|
|
||||||
udev,
|
|
||||||
},
|
|
||||||
reexports::nix::sys::stat::major,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
|
||||||
pub enum RenderTarget {
|
|
||||||
Hardware(DrmNode),
|
|
||||||
Software,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FromStr for RenderTarget {
|
|
||||||
type Err = CreateDrmNodeError;
|
|
||||||
fn from_str(s: &str) -> Result<Self, CreateDrmNodeError> {
|
|
||||||
Ok(match s {
|
|
||||||
"software" => RenderTarget::Software,
|
|
||||||
path => RenderTarget::Hardware(DrmNode::from_path(path)?),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<Option<DrmNode>> for RenderTarget {
|
|
||||||
fn into(self) -> Option<DrmNode> {
|
|
||||||
match self {
|
|
||||||
RenderTarget::Hardware(node) => Some(node),
|
|
||||||
RenderTarget::Software => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<RenderTarget> for DrmNode {
|
|
||||||
fn into(self) -> RenderTarget {
|
|
||||||
RenderTarget::Hardware(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
const NVIDIA_MAJOR: u64 = 195;
|
|
||||||
|
|
||||||
// no clue how this number is on BSDs, feel free to contribute
|
|
||||||
|
|
||||||
impl RenderTarget {
|
|
||||||
pub fn as_devices(&self) -> Vec<CString> {
|
|
||||||
match self {
|
|
||||||
RenderTarget::Hardware(node) => {
|
|
||||||
let mut devices = Vec::new();
|
|
||||||
if let Some(primary) = node.dev_path_with_type(NodeType::Primary) {
|
|
||||||
devices.push(primary);
|
|
||||||
}
|
|
||||||
if let Some(render) = node.dev_path_with_type(NodeType::Render) {
|
|
||||||
devices.push(render);
|
|
||||||
}
|
|
||||||
if udev::driver(node.dev_id())
|
|
||||||
.ok()
|
|
||||||
.flatten()
|
|
||||||
.map(|s| s.to_str() == Some("nvidia"))
|
|
||||||
.unwrap_or(false)
|
|
||||||
{
|
|
||||||
// no idea how match nvidia device nodes to kms/dri-nodes, so lets map all nvidia-nodes to be sure
|
|
||||||
for entry in std::fs::read_dir("/dev").expect("Unable to access /dev") {
|
|
||||||
if let Ok(entry) = entry {
|
|
||||||
if let Ok(metadata) = entry.metadata() {
|
|
||||||
if metadata.is_file() && major(metadata.dev()) == NVIDIA_MAJOR {
|
|
||||||
devices.push(entry.path());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
devices
|
|
||||||
.into_iter()
|
|
||||||
.flat_map(|path| {
|
|
||||||
path.to_str()
|
|
||||||
.map(String::from)
|
|
||||||
.and_then(|string| CString::new(string).ok())
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
RenderTarget::Software => Vec::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,147 +0,0 @@
|
|||||||
use smithay::{
|
|
||||||
backend::renderer::utils::{on_commit_buffer_handler},
|
|
||||||
delegate_compositor,
|
|
||||||
desktop::PopupKind,
|
|
||||||
reexports::{
|
|
||||||
wayland_protocols::xdg::shell::server::xdg_toplevel::State as XdgState,
|
|
||||||
wayland_server::protocol::{wl_buffer::WlBuffer, wl_surface::WlSurface},
|
|
||||||
},
|
|
||||||
utils::{Size, SERIAL_COUNTER},
|
|
||||||
wayland::{
|
|
||||||
buffer::BufferHandler,
|
|
||||||
compositor::{with_states, CompositorHandler, CompositorState},
|
|
||||||
seat::WaylandFocus,
|
|
||||||
shell::xdg::{XdgPopupSurfaceData, XdgToplevelSurfaceData},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::comp::{FocusTarget, State};
|
|
||||||
|
|
||||||
impl BufferHandler for State {
|
|
||||||
fn buffer_destroyed(&mut self, _buffer: &WlBuffer) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CompositorHandler for State {
|
|
||||||
fn compositor_state(&mut self) -> &mut CompositorState {
|
|
||||||
&mut self.compositor_state
|
|
||||||
}
|
|
||||||
|
|
||||||
fn commit(&mut self, surface: &WlSurface) {
|
|
||||||
on_commit_buffer_handler(surface);
|
|
||||||
|
|
||||||
if let Some(window) = self
|
|
||||||
.space
|
|
||||||
.elements()
|
|
||||||
.find(|w| w.wl_surface().as_ref() == Some(surface))
|
|
||||||
{
|
|
||||||
window.on_commit();
|
|
||||||
}
|
|
||||||
self.popups.commit(surface);
|
|
||||||
|
|
||||||
// send the initial configure if relevant
|
|
||||||
if let Some(idx) = self
|
|
||||||
.pending_windows
|
|
||||||
.iter_mut()
|
|
||||||
.position(|w| w.wl_surface().as_ref() == Some(surface))
|
|
||||||
{
|
|
||||||
let window = self.pending_windows.swap_remove(idx);
|
|
||||||
|
|
||||||
let toplevel = window.toplevel();
|
|
||||||
let (initial_configure_sent, max_size) = with_states(surface, |states| {
|
|
||||||
let attributes = states.data_map.get::<XdgToplevelSurfaceData>().unwrap();
|
|
||||||
let attributes_guard = attributes.lock().unwrap();
|
|
||||||
|
|
||||||
(
|
|
||||||
attributes_guard.initial_configure_sent,
|
|
||||||
attributes_guard.max_size,
|
|
||||||
)
|
|
||||||
});
|
|
||||||
|
|
||||||
if self.output.is_none() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if !initial_configure_sent {
|
|
||||||
if max_size.w == 0 && max_size.h == 0 {
|
|
||||||
toplevel.with_pending_state(|state| {
|
|
||||||
state.size = Some(
|
|
||||||
self.output
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.current_mode()
|
|
||||||
.unwrap()
|
|
||||||
.size
|
|
||||||
.to_f64()
|
|
||||||
.to_logical(
|
|
||||||
self.output
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.current_scale()
|
|
||||||
.fractional_scale(),
|
|
||||||
)
|
|
||||||
.to_i32_round(),
|
|
||||||
);
|
|
||||||
state.states.set(XdgState::Fullscreen);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
toplevel.with_pending_state(|state| {
|
|
||||||
state.states.set(XdgState::Activated);
|
|
||||||
});
|
|
||||||
toplevel.send_configure();
|
|
||||||
self.pending_windows.push(window);
|
|
||||||
} else {
|
|
||||||
let window_size = toplevel.current_state().size.unwrap_or((0, 0).into());
|
|
||||||
let output_size: Size<i32, _> = self
|
|
||||||
.output
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.current_mode()
|
|
||||||
.unwrap()
|
|
||||||
.size
|
|
||||||
.to_f64()
|
|
||||||
.to_logical(
|
|
||||||
self.output
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.current_scale()
|
|
||||||
.fractional_scale(),
|
|
||||||
)
|
|
||||||
.to_i32_round();
|
|
||||||
let loc = (
|
|
||||||
(output_size.w / 2) - (window_size.w / 2),
|
|
||||||
(output_size.h / 2) - (window_size.h / 2),
|
|
||||||
);
|
|
||||||
self.space.map_element(window.clone(), loc, true);
|
|
||||||
self.seat.get_keyboard().unwrap().set_focus(
|
|
||||||
self,
|
|
||||||
Some(FocusTarget::from(window)),
|
|
||||||
SERIAL_COUNTER.next_serial(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(popup) = self.popups.find_popup(surface) {
|
|
||||||
let PopupKind::Xdg(ref popup) = popup;
|
|
||||||
let initial_configure_sent = with_states(surface, |states| {
|
|
||||||
states
|
|
||||||
.data_map
|
|
||||||
.get::<XdgPopupSurfaceData>()
|
|
||||||
.unwrap()
|
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.initial_configure_sent
|
|
||||||
});
|
|
||||||
if !initial_configure_sent {
|
|
||||||
// NOTE: This should never fail as the initial configure is always
|
|
||||||
// allowed.
|
|
||||||
popup.send_configure().expect("initial configure failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
delegate_compositor!(State);
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
use smithay::{
|
|
||||||
delegate_data_device,
|
|
||||||
wayland::data_device::{
|
|
||||||
ClientDndGrabHandler, DataDeviceHandler, DataDeviceState, ServerDndGrabHandler,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::comp::State;
|
|
||||||
|
|
||||||
impl ServerDndGrabHandler for State {}
|
|
||||||
impl ClientDndGrabHandler for State {}
|
|
||||||
impl DataDeviceHandler for State {
|
|
||||||
fn data_device_state(&self) -> &DataDeviceState {
|
|
||||||
&self.data_device_state
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
delegate_data_device!(State);
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
use smithay::{
|
|
||||||
backend::{allocator::dmabuf::Dmabuf, renderer::ImportDma},
|
|
||||||
delegate_dmabuf,
|
|
||||||
wayland::dmabuf::{DmabufGlobal, DmabufHandler, DmabufState, ImportError},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::comp::State;
|
|
||||||
|
|
||||||
impl DmabufHandler for State {
|
|
||||||
fn dmabuf_state(&mut self) -> &mut DmabufState {
|
|
||||||
&mut self.dmabuf_state
|
|
||||||
}
|
|
||||||
|
|
||||||
fn dmabuf_imported(
|
|
||||||
&mut self,
|
|
||||||
_global: &DmabufGlobal,
|
|
||||||
dmabuf: Dmabuf,
|
|
||||||
) -> Result<(), ImportError> {
|
|
||||||
self.renderer
|
|
||||||
.import_dmabuf(&dmabuf, None)
|
|
||||||
.map(|_| ())
|
|
||||||
.map_err(|_| ImportError::Failed)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
delegate_dmabuf!(State);
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
pub mod compositor;
|
|
||||||
pub mod data_device;
|
|
||||||
pub mod dmabuf;
|
|
||||||
pub mod output;
|
|
||||||
pub mod presentation;
|
|
||||||
pub mod relative_pointer;
|
|
||||||
pub mod seat;
|
|
||||||
pub mod shm;
|
|
||||||
pub mod viewporter;
|
|
||||||
pub mod wl_drm;
|
|
||||||
pub mod xdg;
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
use smithay::delegate_output;
|
|
||||||
|
|
||||||
use crate::comp::State;
|
|
||||||
|
|
||||||
delegate_output!(State);
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
|
||||||
|
|
||||||
use crate::comp::State;
|
|
||||||
use smithay::delegate_presentation;
|
|
||||||
|
|
||||||
delegate_presentation!(State);
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
use smithay::delegate_relative_pointer;
|
|
||||||
|
|
||||||
use crate::comp::State;
|
|
||||||
|
|
||||||
delegate_relative_pointer!(State);
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
use smithay::{
|
|
||||||
delegate_seat,
|
|
||||||
input::{pointer::CursorImageStatus, Seat, SeatHandler, SeatState},
|
|
||||||
reexports::wayland_server::Resource,
|
|
||||||
wayland::data_device::set_data_device_focus,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::comp::{FocusTarget, State};
|
|
||||||
|
|
||||||
impl SeatHandler for State {
|
|
||||||
type KeyboardFocus = FocusTarget;
|
|
||||||
type PointerFocus = FocusTarget;
|
|
||||||
|
|
||||||
fn seat_state(&mut self) -> &mut SeatState<Self> {
|
|
||||||
&mut self.seat_state
|
|
||||||
}
|
|
||||||
|
|
||||||
fn focus_changed(&mut self, seat: &Seat<Self>, focus: Option<&Self::KeyboardFocus>) {
|
|
||||||
if let Some(surface) = focus {
|
|
||||||
let client = match surface {
|
|
||||||
FocusTarget::Wayland(w) => w.toplevel().wl_surface().client(),
|
|
||||||
FocusTarget::Popup(p) => p.wl_surface().client(),
|
|
||||||
};
|
|
||||||
set_data_device_focus(&self.dh, seat, client);
|
|
||||||
} else {
|
|
||||||
set_data_device_focus(&self.dh, seat, None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn cursor_image(&mut self, _seat: &Seat<Self>, image: CursorImageStatus) {
|
|
||||||
self.cursor_state = image;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
delegate_seat!(State);
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
use smithay::{
|
|
||||||
delegate_shm,
|
|
||||||
wayland::shm::{ShmHandler, ShmState},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::comp::State;
|
|
||||||
|
|
||||||
impl ShmHandler for State {
|
|
||||||
fn shm_state(&self) -> &ShmState {
|
|
||||||
&self.shm_state
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
delegate_shm!(State);
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
use smithay::delegate_viewporter;
|
|
||||||
|
|
||||||
use crate::comp::State;
|
|
||||||
|
|
||||||
delegate_viewporter!(State);
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
use crate::{comp::State, wayland::protocols::wl_drm::delegate_wl_drm};
|
|
||||||
|
|
||||||
delegate_wl_drm!(State);
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
use smithay::{
|
|
||||||
delegate_xdg_shell,
|
|
||||||
desktop::{
|
|
||||||
find_popup_root_surface, PopupKeyboardGrab, PopupKind, PopupPointerGrab,
|
|
||||||
PopupUngrabStrategy, Window,
|
|
||||||
},
|
|
||||||
input::{pointer::Focus, Seat},
|
|
||||||
reexports::wayland_server::protocol::wl_seat::WlSeat,
|
|
||||||
utils::Serial,
|
|
||||||
wayland::{
|
|
||||||
seat::WaylandFocus,
|
|
||||||
shell::xdg::{
|
|
||||||
PopupSurface, PositionerState, ToplevelSurface, XdgShellHandler, XdgShellState,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::comp::{FocusTarget, State};
|
|
||||||
|
|
||||||
impl XdgShellHandler for State {
|
|
||||||
fn xdg_shell_state(&mut self) -> &mut XdgShellState {
|
|
||||||
&mut self.shell_state
|
|
||||||
}
|
|
||||||
|
|
||||||
fn new_toplevel(&mut self, surface: ToplevelSurface) {
|
|
||||||
let window = Window::new(surface);
|
|
||||||
self.pending_windows.push(window);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn new_popup(&mut self, surface: PopupSurface, positioner: PositionerState) {
|
|
||||||
// TODO: properly recompute the geometry with the whole of positioner state
|
|
||||||
surface.with_pending_state(|state| {
|
|
||||||
// NOTE: This is not really necessary as the default geometry
|
|
||||||
// is already set the same way, but for demonstrating how
|
|
||||||
// to set the initial popup geometry this code is left as
|
|
||||||
// an example
|
|
||||||
state.geometry = positioner.get_geometry();
|
|
||||||
});
|
|
||||||
if let Err(err) = self.popups.track_popup(PopupKind::from(surface)) {
|
|
||||||
tracing::warn!(?err, "Failed to track popup.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn grab(&mut self, surface: PopupSurface, seat: WlSeat, serial: Serial) {
|
|
||||||
let seat: Seat<State> = Seat::from_resource(&seat).unwrap();
|
|
||||||
let kind = PopupKind::Xdg(surface.clone());
|
|
||||||
if let Some(root) = find_popup_root_surface(&kind).ok().and_then(|root| {
|
|
||||||
self.space
|
|
||||||
.elements()
|
|
||||||
.find(|w| w.wl_surface().map(|s| s == root).unwrap_or(false))
|
|
||||||
.cloned()
|
|
||||||
.map(FocusTarget::from)
|
|
||||||
}) {
|
|
||||||
let ret = self.popups.grab_popup(root, surface.into(), &seat, serial);
|
|
||||||
if let Ok(mut grab) = ret {
|
|
||||||
if let Some(keyboard) = seat.get_keyboard() {
|
|
||||||
if keyboard.is_grabbed()
|
|
||||||
&& !(keyboard.has_grab(serial)
|
|
||||||
|| keyboard.has_grab(grab.previous_serial().unwrap_or(serial)))
|
|
||||||
{
|
|
||||||
grab.ungrab(PopupUngrabStrategy::All);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
keyboard.set_focus(self, grab.current_grab(), serial);
|
|
||||||
keyboard.set_grab(PopupKeyboardGrab::new(&grab), serial);
|
|
||||||
}
|
|
||||||
if let Some(pointer) = seat.get_pointer() {
|
|
||||||
if pointer.is_grabbed()
|
|
||||||
&& !(pointer.has_grab(serial)
|
|
||||||
|| pointer
|
|
||||||
.has_grab(grab.previous_serial().unwrap_or_else(|| grab.serial())))
|
|
||||||
{
|
|
||||||
grab.ungrab(PopupUngrabStrategy::All);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
pointer.set_grab(self, PopupPointerGrab::new(&grab), serial, Focus::Clear);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
delegate_xdg_shell!(State);
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
pub mod handlers;
|
|
||||||
pub mod protocols;
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
pub mod wl_drm;
|
|
||||||
@@ -1,255 +0,0 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
|
||||||
|
|
||||||
// Re-export only the actual code, and then only use this re-export
|
|
||||||
// The `generated` module below is just some boilerplate to properly isolate stuff
|
|
||||||
// and avoid exposing internal details.
|
|
||||||
//
|
|
||||||
// You can use all the types from my_protocol as if they went from `wayland_client::protocol`.
|
|
||||||
pub use generated::wl_drm;
|
|
||||||
|
|
||||||
mod generated {
|
|
||||||
use smithay::reexports::wayland_server::{self, protocol::*};
|
|
||||||
|
|
||||||
pub mod __interfaces {
|
|
||||||
use smithay::reexports::wayland_server::protocol::__interfaces::*;
|
|
||||||
use wayland_backend;
|
|
||||||
wayland_scanner::generate_interfaces!("resources/protocols/wayland-drm.xml");
|
|
||||||
}
|
|
||||||
use self::__interfaces::*;
|
|
||||||
|
|
||||||
wayland_scanner::generate_server_code!("resources/protocols/wayland-drm.xml");
|
|
||||||
}
|
|
||||||
|
|
||||||
use smithay::{
|
|
||||||
backend::allocator::{
|
|
||||||
dmabuf::{Dmabuf, DmabufFlags},
|
|
||||||
Format, Fourcc, Modifier,
|
|
||||||
},
|
|
||||||
reexports::wayland_server::{
|
|
||||||
backend::GlobalId, protocol::wl_buffer::WlBuffer, Client, DataInit, Dispatch,
|
|
||||||
DisplayHandle, GlobalDispatch, New, Resource,
|
|
||||||
},
|
|
||||||
wayland::{
|
|
||||||
buffer::BufferHandler,
|
|
||||||
dmabuf::{DmabufGlobal, DmabufHandler, ImportError},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
use std::{convert::TryFrom, path::PathBuf, sync::Arc};
|
|
||||||
|
|
||||||
pub struct WlDrmState;
|
|
||||||
|
|
||||||
/// Data associated with a drm global.
|
|
||||||
pub struct DrmGlobalData {
|
|
||||||
filter: Box<dyn for<'a> Fn(&'a Client) -> bool + Send + Sync>,
|
|
||||||
formats: Arc<Vec<Fourcc>>,
|
|
||||||
device_path: PathBuf,
|
|
||||||
dmabuf_global: DmabufGlobal,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct DrmInstanceData {
|
|
||||||
formats: Arc<Vec<Fourcc>>,
|
|
||||||
dmabuf_global: DmabufGlobal,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<D> GlobalDispatch<wl_drm::WlDrm, DrmGlobalData, D> for WlDrmState
|
|
||||||
where
|
|
||||||
D: GlobalDispatch<wl_drm::WlDrm, DrmGlobalData>
|
|
||||||
+ Dispatch<wl_drm::WlDrm, DrmInstanceData>
|
|
||||||
+ BufferHandler
|
|
||||||
+ DmabufHandler
|
|
||||||
+ 'static,
|
|
||||||
{
|
|
||||||
fn bind(
|
|
||||||
_state: &mut D,
|
|
||||||
_dh: &DisplayHandle,
|
|
||||||
_client: &Client,
|
|
||||||
resource: New<wl_drm::WlDrm>,
|
|
||||||
global_data: &DrmGlobalData,
|
|
||||||
data_init: &mut DataInit<'_, D>,
|
|
||||||
) {
|
|
||||||
let data = DrmInstanceData {
|
|
||||||
formats: global_data.formats.clone(),
|
|
||||||
dmabuf_global: global_data.dmabuf_global.clone(),
|
|
||||||
};
|
|
||||||
let drm_instance = data_init.init(resource, data);
|
|
||||||
|
|
||||||
drm_instance.device(global_data.device_path.to_string_lossy().into_owned());
|
|
||||||
if drm_instance.version() >= 2 {
|
|
||||||
drm_instance.capabilities(wl_drm::Capability::Prime as u32);
|
|
||||||
}
|
|
||||||
for format in global_data.formats.iter() {
|
|
||||||
if let Ok(converted) = wl_drm::Format::try_from(*format as u32) {
|
|
||||||
drm_instance.format(converted as u32);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn can_view(client: Client, global_data: &DrmGlobalData) -> bool {
|
|
||||||
(global_data.filter)(&client)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<D> Dispatch<wl_drm::WlDrm, DrmInstanceData, D> for WlDrmState
|
|
||||||
where
|
|
||||||
D: GlobalDispatch<wl_drm::WlDrm, DrmGlobalData>
|
|
||||||
+ Dispatch<wl_drm::WlDrm, DrmInstanceData>
|
|
||||||
+ Dispatch<WlBuffer, Dmabuf>
|
|
||||||
+ BufferHandler
|
|
||||||
+ DmabufHandler
|
|
||||||
+ 'static,
|
|
||||||
{
|
|
||||||
fn request(
|
|
||||||
state: &mut D,
|
|
||||||
_client: &Client,
|
|
||||||
drm: &wl_drm::WlDrm,
|
|
||||||
request: wl_drm::Request,
|
|
||||||
data: &DrmInstanceData,
|
|
||||||
_dh: &DisplayHandle,
|
|
||||||
data_init: &mut DataInit<'_, D>,
|
|
||||||
) {
|
|
||||||
match request {
|
|
||||||
wl_drm::Request::Authenticate { .. } => drm.authenticated(),
|
|
||||||
wl_drm::Request::CreateBuffer { .. } => drm.post_error(
|
|
||||||
wl_drm::Error::InvalidName,
|
|
||||||
String::from("Flink handles are unsupported, use PRIME"),
|
|
||||||
),
|
|
||||||
wl_drm::Request::CreatePlanarBuffer { .. } => drm.post_error(
|
|
||||||
wl_drm::Error::InvalidName,
|
|
||||||
String::from("Flink handles are unsupported, use PRIME"),
|
|
||||||
),
|
|
||||||
wl_drm::Request::CreatePrimeBuffer {
|
|
||||||
id,
|
|
||||||
name,
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
format,
|
|
||||||
offset0,
|
|
||||||
stride0,
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
let format = match Fourcc::try_from(format) {
|
|
||||||
Ok(format) => {
|
|
||||||
if !data.formats.contains(&format) {
|
|
||||||
drm.post_error(
|
|
||||||
wl_drm::Error::InvalidFormat,
|
|
||||||
String::from("Format not advertised by wl_drm"),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
format
|
|
||||||
}
|
|
||||||
Err(_) => {
|
|
||||||
drm.post_error(
|
|
||||||
wl_drm::Error::InvalidFormat,
|
|
||||||
String::from("Format unknown / not advertised by wl_drm"),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if width < 1 || height < 1 {
|
|
||||||
drm.post_error(
|
|
||||||
wl_drm::Error::InvalidFormat,
|
|
||||||
String::from("width or height not positive"),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut dma = Dmabuf::builder((width, height), format, DmabufFlags::empty());
|
|
||||||
dma.add_plane(name, 0, offset0 as u32, stride0 as u32, Modifier::Invalid);
|
|
||||||
match dma.build() {
|
|
||||||
Some(dmabuf) => {
|
|
||||||
match state.dmabuf_imported(&data.dmabuf_global, dmabuf.clone()) {
|
|
||||||
Ok(_) => {
|
|
||||||
// import was successful
|
|
||||||
data_init.init(id, dmabuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
Err(ImportError::InvalidFormat) => {
|
|
||||||
drm.post_error(
|
|
||||||
wl_drm::Error::InvalidFormat,
|
|
||||||
"format and plane combination are not valid",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Err(ImportError::Failed) => {
|
|
||||||
// Buffer import failed. The protocol documentation heavily implies killing the
|
|
||||||
// client is the right thing to do here.
|
|
||||||
drm.post_error(wl_drm::Error::InvalidName, "buffer import failed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
// Buffer import failed. The protocol documentation heavily implies killing the
|
|
||||||
// client is the right thing to do here.
|
|
||||||
drm.post_error(
|
|
||||||
wl_drm::Error::InvalidName,
|
|
||||||
"dmabuf global was destroyed on server",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn create_drm_global<D>(
|
|
||||||
display: &DisplayHandle,
|
|
||||||
device_path: PathBuf,
|
|
||||||
formats: Vec<Format>,
|
|
||||||
dmabuf_global: &DmabufGlobal,
|
|
||||||
) -> GlobalId
|
|
||||||
where
|
|
||||||
D: GlobalDispatch<wl_drm::WlDrm, DrmGlobalData>
|
|
||||||
+ Dispatch<wl_drm::WlDrm, DrmInstanceData>
|
|
||||||
+ BufferHandler
|
|
||||||
+ DmabufHandler
|
|
||||||
+ 'static,
|
|
||||||
{
|
|
||||||
create_drm_global_with_filter::<D, _>(display, device_path, formats, dmabuf_global, |_| true)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn create_drm_global_with_filter<D, F>(
|
|
||||||
display: &DisplayHandle,
|
|
||||||
device_path: PathBuf,
|
|
||||||
formats: Vec<Format>,
|
|
||||||
dmabuf_global: &DmabufGlobal,
|
|
||||||
client_filter: F,
|
|
||||||
) -> GlobalId
|
|
||||||
where
|
|
||||||
D: GlobalDispatch<wl_drm::WlDrm, DrmGlobalData>
|
|
||||||
+ Dispatch<wl_drm::WlDrm, DrmInstanceData>
|
|
||||||
+ BufferHandler
|
|
||||||
+ DmabufHandler
|
|
||||||
+ 'static,
|
|
||||||
F: for<'a> Fn(&'a Client) -> bool + Send + Sync + 'static,
|
|
||||||
{
|
|
||||||
let formats = Arc::new(
|
|
||||||
formats
|
|
||||||
.into_iter()
|
|
||||||
.filter(|f| f.modifier == Modifier::Invalid)
|
|
||||||
.map(|f| f.code)
|
|
||||||
.collect(),
|
|
||||||
);
|
|
||||||
let data = DrmGlobalData {
|
|
||||||
filter: Box::new(client_filter),
|
|
||||||
formats,
|
|
||||||
device_path,
|
|
||||||
dmabuf_global: dmabuf_global.clone(),
|
|
||||||
};
|
|
||||||
|
|
||||||
display.create_global::<D, wl_drm::WlDrm, _>(2, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! delegate_wl_drm {
|
|
||||||
($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {
|
|
||||||
smithay::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [
|
|
||||||
$crate::wayland::protocols::wl_drm::wl_drm::WlDrm: $crate::wayland::protocols::wl_drm::DrmGlobalData
|
|
||||||
] => $crate::wayland::protocols::wl_drm::WlDrmState);
|
|
||||||
smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [
|
|
||||||
$crate::wayland::protocols::wl_drm::wl_drm::WlDrm: $crate::wayland::protocols::wl_drm::DrmInstanceData
|
|
||||||
] => $crate::wayland::protocols::wl_drm::WlDrmState);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
pub(crate) use delegate_wl_drm;
|
|
||||||
Reference in New Issue
Block a user