mirror of
https://github.com/Monibuca/plugin-gb28181.git
synced 2025-12-24 13:27:57 +08:00
Compare commits
133 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
63eba38094 | ||
|
|
3f03146f5c | ||
|
|
c5ac90cdff | ||
|
|
9c818244cb | ||
|
|
bf5f2b804d | ||
|
|
a2bfeec948 | ||
|
|
3a618fc0ce | ||
|
|
75f3601326 | ||
|
|
c07309f14f | ||
|
|
aefd8e72f5 | ||
|
|
0db5da87a8 | ||
|
|
50da427ab7 | ||
|
|
35c9142d0e | ||
|
|
de4a9668cd | ||
|
|
fc7758e1da | ||
|
|
4cae096425 | ||
|
|
cad56c207d | ||
|
|
75b1890e20 | ||
|
|
83f7d3711a | ||
|
|
b2d65700bc | ||
|
|
eb7e47e98a | ||
|
|
57bce22209 | ||
|
|
97d65b9710 | ||
|
|
416818ff53 | ||
|
|
fd7ee7f80c | ||
|
|
b251f8471a | ||
|
|
a2647a1564 | ||
|
|
8e6544766e | ||
|
|
86f7effd47 | ||
|
|
65c1864d5b | ||
|
|
d474a500c9 | ||
|
|
ba14fdafa7 | ||
|
|
a7c866d453 | ||
|
|
ae6400cfc0 | ||
|
|
bd7f5eba92 | ||
|
|
195c0ac124 | ||
|
|
6fd2d3f5a7 | ||
|
|
523d1e8e5f | ||
|
|
0c4a7356a1 | ||
|
|
ad0402fcbf | ||
|
|
fd2e614d74 | ||
|
|
8704c54137 | ||
|
|
9c99033b3c | ||
|
|
00aa30e428 | ||
|
|
51583d3885 | ||
|
|
837b6b287d | ||
|
|
4e25222df8 | ||
|
|
2f7a6e617d | ||
|
|
cb10ae14bf | ||
|
|
e982c74f1b | ||
|
|
9d59bb33cf | ||
|
|
3341b07812 | ||
|
|
0ea755f462 | ||
|
|
2e71a7115d | ||
|
|
797a59965f | ||
|
|
6555dda300 | ||
|
|
4d401c909f | ||
|
|
84d7f92479 | ||
|
|
4b38e56063 | ||
|
|
a111dafebe | ||
|
|
a5197ed196 | ||
|
|
4a654a6b07 | ||
|
|
034fdbcfea | ||
|
|
1b8dbea862 | ||
|
|
9ed42a3564 | ||
|
|
3244823fff | ||
|
|
3fbe12edc5 | ||
|
|
a7ea95e419 | ||
|
|
4de15502ff | ||
|
|
348676428b | ||
|
|
0676b08d58 | ||
|
|
6b0b31230f | ||
|
|
db7a186647 | ||
|
|
e76d1b7d86 | ||
|
|
8eff1b3373 | ||
|
|
8af13e0b4a | ||
|
|
ca0b019be7 | ||
|
|
bd2dd4c5c3 | ||
|
|
518b20e145 | ||
|
|
aee38b5053 | ||
|
|
5682750723 | ||
|
|
609b9d0f9a | ||
|
|
8c248fc0c0 | ||
|
|
51d8a8fa91 | ||
|
|
1105d732ae | ||
|
|
72be771799 | ||
|
|
5cae3bd5c4 | ||
|
|
686ce753a3 | ||
|
|
0f3fda9159 | ||
|
|
0fcd23cee0 | ||
|
|
28f5774073 | ||
|
|
e813086907 | ||
|
|
8a8d97c676 | ||
|
|
356142a2db | ||
|
|
0c9712e1e5 | ||
|
|
f22a6303c6 | ||
|
|
53bb479588 | ||
|
|
aea30f751a | ||
|
|
4b33a4c8a3 | ||
|
|
0a0f58b1db | ||
|
|
4528a67e92 | ||
|
|
87ac220de1 | ||
|
|
640c310a77 | ||
|
|
53bb4244db | ||
|
|
6b193a4208 | ||
|
|
bf54332376 | ||
|
|
a527903825 | ||
|
|
bb0209fed9 | ||
|
|
23e01d4ccc | ||
|
|
c52549b0c2 | ||
|
|
3a00e5dccc | ||
|
|
65d758ed0b | ||
|
|
5cf4b49033 | ||
|
|
04c93225a1 | ||
|
|
709b394af6 | ||
|
|
57e7977eae | ||
|
|
ed0826a35d | ||
|
|
4495bd2d4d | ||
|
|
7d235cdd04 | ||
|
|
6188118ef6 | ||
|
|
0481b71d52 | ||
|
|
6ab0f9d1c8 | ||
|
|
fd3564afe0 | ||
|
|
0d0208f0f7 | ||
|
|
cc47907517 | ||
|
|
8729b32cb2 | ||
|
|
43fa8b3c37 | ||
|
|
c33b93431a | ||
|
|
1c8618076d | ||
|
|
12d069d949 | ||
|
|
779a868821 | ||
|
|
5841faa3cb | ||
|
|
e5f9aa54c1 |
661
LICENSE
Normal file
661
LICENSE
Normal file
@@ -0,0 +1,661 @@
|
||||
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/>.
|
||||
142
README.md
142
README.md
@@ -1,2 +1,140 @@
|
||||
# plugin-gb28181
|
||||
gb28181 plugin for monibuca
|
||||
# GB28181插件
|
||||
|
||||
该插件提供SIP server的服务,以及流媒体服务器能力,可以将NVR和摄像头的流抓到m7s中,可获取的设备的录像数据以及访问录像视频。也可以控制摄像头的旋转、缩放等。
|
||||
|
||||
## 插件地址
|
||||
|
||||
github.com/Monibuca/plugin-gb28181
|
||||
|
||||
## 插件引入
|
||||
|
||||
```go
|
||||
import (
|
||||
_ "github.com/Monibuca/plugin-gb28181"
|
||||
)
|
||||
```
|
||||
|
||||
## 默认插件配置
|
||||
|
||||
```toml
|
||||
[GB28181]
|
||||
Serial = "34020000002000000001"
|
||||
Realm = "3402000000"
|
||||
Expires = 3600
|
||||
ListenAddr = "127.0.0.1:5060"
|
||||
AutoCloseAfter = -1
|
||||
AutoInvite = false
|
||||
MediaPort = 58200
|
||||
CatalogInterval = 30
|
||||
RemoveBanInterval = 600
|
||||
Username = ""
|
||||
Password = ""
|
||||
UdpCacheSize = 0
|
||||
TCP = false
|
||||
```
|
||||
|
||||
- `ListenAddr`是监听的地址,这里需要注意的是必须要带上Server的IP地址,这个IP地址是向设备发送信息的时候需要带上的。
|
||||
- `Serial` Server(SIP)的编号
|
||||
- `Realm` Server(SIP)的域
|
||||
- `AutoCloseAfter` 如果设置大于等于0,则当某个流最后一个订阅者取消订阅时会延迟N秒,会自动发送bye,节省流量。如果为了响应及时,可以设置成-1,保持流的连接
|
||||
- `AutoInvite` 表示自动发起invite,当Server(SIP)接收到设备信息时,立即向设备发送invite命令获取流
|
||||
- `MediaPort` 表示用于接收设备流的端口号
|
||||
- `CatalogInterval` 定时获取设备目录的间隔,单位秒
|
||||
- `RemoveBanInterval` 定时移除注册失败的设备黑名单,单位秒,默认10分钟(600秒)
|
||||
- `Username` 国标用户名
|
||||
- `Password` 国标密码
|
||||
- `TCP` 是否开启TCP接收国标流,默认false
|
||||
- `UdpCacheSize` 表示UDP缓存大小,默认为0,不开启。仅当TCP关闭,切缓存大于0时才开启,会最多缓存最多N个包,并排序,修复乱序造成的无法播放问题,注意开启后,会有一定的性能损耗,并丢失部分包。
|
||||
|
||||
**注意某些摄像机没有设置用户名的地方,摄像机会以自身的国标id作为用户名,这个时候m7s会忽略使用摄像机的用户名,忽略配置的用户名**
|
||||
如果设备配置了错误的用户名和密码,连续三次上报错误后,m7s会记录设备id,并在10分钟内禁止设备注册
|
||||
|
||||
## 插件功能
|
||||
|
||||
### 使用SIP协议接受NVR或其他GB28181设备的注册
|
||||
|
||||
- 服务器启动时自动监听SIP协议端口,当有设备注册时,会记录该设备信息,可以从UI的列表中看到设备
|
||||
- 定时发送Catalog命令查询设备的目录信息,可获得通道数据或者子设备
|
||||
- 发送RecordInfo命令查询设备对录像数据
|
||||
- 发送Invite命令获取设备的实时视频或者录像视频
|
||||
- 发送PTZ命令来控制摄像头云台
|
||||
|
||||
### 作为GB28281的流媒体服务器接受设备的媒体流
|
||||
|
||||
- 当invite设备的**实时**视频流时,会在m7s中创建对应的流,StreamPath由设备编号和通道编号组成,即[设备编号]/[通道编号],如果有多个层级,通道编号是最后一个层级的编号
|
||||
- 当invite设备的**录像**视频流时,StreamPath由设备编号和通道编号以及录像的起止时间拼接而成即[设备编号]/[通道编号]/[开始时间]-[结束时间]
|
||||
|
||||
### 如何设置UDP缓存大小
|
||||
|
||||
通过wireshark抓包,分析rtp,然后看一下大概多少个包可以有序
|
||||
|
||||
## 接口API
|
||||
|
||||
### 罗列所有的gb28181协议的设备
|
||||
|
||||
`/api/gb28181/list`
|
||||
设备的结构体如下
|
||||
|
||||
```go
|
||||
type Device struct {
|
||||
*transaction.Core `json:"-"`
|
||||
ID string
|
||||
RegisterTime time.Time
|
||||
UpdateTime time.Time
|
||||
Status string
|
||||
Channels []*Channel
|
||||
queryChannel bool
|
||||
sn int
|
||||
from *sip.Contact
|
||||
to *sip.Contact
|
||||
Addr string
|
||||
SipIP string //暴露的IP
|
||||
channelMap map[string]*Channel
|
||||
channelMutex sync.RWMutex
|
||||
}
|
||||
```
|
||||
|
||||
> 根据golang的规则,小写字母开头的变量不会被序列化
|
||||
|
||||
### 从设备拉取视频流
|
||||
|
||||
`/api/gb28181/invite`
|
||||
|
||||
参数名 | 必传 | 含义
|
||||
|----|---|---
|
||||
id|是 | 设备ID
|
||||
channel|是|通道编号
|
||||
startTime|否|开始时间(纯数字Unix时间戳)
|
||||
endTime|否|结束时间(纯数字Unix时间戳)
|
||||
|
||||
返回200代表成功
|
||||
|
||||
### 停止从设备拉流
|
||||
|
||||
`/api/gb28181/bye`
|
||||
|
||||
参数名 | 必传 | 含义
|
||||
|----|---|---
|
||||
id|是 | 设备ID
|
||||
channel|是|通道编号
|
||||
|
||||
### 发送控制命令
|
||||
|
||||
`/api/gb28181/control`
|
||||
|
||||
参数名 | 必传 | 含义
|
||||
|----|---|---
|
||||
id|是 | 设备ID
|
||||
channel|是|通道编号
|
||||
ptzcmd|是|PTZ控制指令
|
||||
|
||||
### 查询录像
|
||||
|
||||
`/api/gb28181/query/records`
|
||||
|
||||
参数名 | 必传 | 含义
|
||||
|----|---|---
|
||||
id|是 | 设备ID
|
||||
channel|是|通道编号
|
||||
startTime|否|开始时间(字符串,格式:2021-7-23T12:00:00)
|
||||
endTime|否|结束时间(字符串格式同上)
|
||||
|
||||
321
channel.go
Normal file
321
channel.go
Normal file
@@ -0,0 +1,321 @@
|
||||
package gb28181
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/Monibuca/engine/v3"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/sip"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/transaction"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/utils"
|
||||
)
|
||||
|
||||
type ChannelEx struct {
|
||||
device *Device
|
||||
inviteRes *sip.Message
|
||||
recordInviteRes *sip.Message
|
||||
RecordPublisher *Publisher
|
||||
LivePublisher *Publisher
|
||||
LiveSubSP string //实时子码流
|
||||
Records []*Record
|
||||
RecordStartTime string
|
||||
RecordEndTime string
|
||||
recordStartTime time.Time
|
||||
recordEndTime time.Time
|
||||
state int32
|
||||
tcpPortIndex uint16
|
||||
}
|
||||
|
||||
// Channel 通道
|
||||
type Channel struct {
|
||||
DeviceID string
|
||||
ParentID string
|
||||
Name string
|
||||
Manufacturer string
|
||||
Model string
|
||||
Owner string
|
||||
CivilCode string
|
||||
Address string
|
||||
Parental int
|
||||
SafetyWay int
|
||||
RegisterWay int
|
||||
Secrecy int
|
||||
Status string
|
||||
Children []*Channel
|
||||
*ChannelEx //自定义属性
|
||||
}
|
||||
|
||||
func (c *Channel) CreateMessage(Method sip.Method) (requestMsg *sip.Message) {
|
||||
requestMsg = c.device.CreateMessage(Method)
|
||||
requestMsg.StartLine.Uri = sip.NewURI(c.DeviceID + "@" + c.device.to.Uri.Domain())
|
||||
requestMsg.To = &sip.Contact{
|
||||
Uri: requestMsg.StartLine.Uri,
|
||||
}
|
||||
requestMsg.From = &sip.Contact{
|
||||
Uri: sip.NewURI(config.Serial + "@" + config.Realm),
|
||||
Params: map[string]string{"tag": utils.RandNumString(9)},
|
||||
}
|
||||
return
|
||||
}
|
||||
func (channel *Channel) QueryRecord(startTime, endTime string) int {
|
||||
d := channel.device
|
||||
channel.RecordStartTime = startTime
|
||||
channel.RecordEndTime = endTime
|
||||
channel.recordStartTime, _ = time.Parse(TIME_LAYOUT, startTime)
|
||||
channel.recordEndTime, _ = time.Parse(TIME_LAYOUT, endTime)
|
||||
channel.Records = nil
|
||||
requestMsg := channel.CreateMessage(sip.MESSAGE)
|
||||
requestMsg.ContentType = "Application/MANSCDP+xml"
|
||||
requestMsg.Body = fmt.Sprintf(`<?xml version="1.0"?>
|
||||
<Query>
|
||||
<CmdType>RecordInfo</CmdType>
|
||||
<SN>%d</SN>
|
||||
<DeviceID>%s</DeviceID>
|
||||
<StartTime>%s</StartTime>
|
||||
<EndTime>%s</EndTime>
|
||||
<Secrecy>0</Secrecy>
|
||||
<Type>time</Type>
|
||||
</Query>`, d.sn, requestMsg.To.Uri.UserInfo(), startTime, endTime)
|
||||
requestMsg.ContentLength = len(requestMsg.Body)
|
||||
return d.SendMessage(requestMsg).Code
|
||||
}
|
||||
func (channel *Channel) Control(PTZCmd string) int {
|
||||
d := channel.device
|
||||
requestMsg := channel.CreateMessage(sip.MESSAGE)
|
||||
requestMsg.ContentType = "Application/MANSCDP+xml"
|
||||
requestMsg.Body = fmt.Sprintf(`<?xml version="1.0"?>
|
||||
<Control>
|
||||
<CmdType>DeviceControl</CmdType>
|
||||
<SN>%d</SN>
|
||||
<DeviceID>%s</DeviceID>
|
||||
<PTZCmd>%s</PTZCmd>
|
||||
</Control>`, d.sn, requestMsg.To.Uri.UserInfo(), PTZCmd)
|
||||
requestMsg.ContentLength = len(requestMsg.Body)
|
||||
return d.SendMessage(requestMsg).Code
|
||||
}
|
||||
|
||||
/*
|
||||
f字段: f = v/编码格式/分辨率/帧率/码率类型/码率大小a/编码格式/码率大小/采样率
|
||||
各项具体含义:
|
||||
v:后续参数为视频的参数;各参数间以 “/”分割;
|
||||
编码格式:十进制整数字符串表示
|
||||
1 –MPEG-4 2 –H.264 3 – SVAC 4 –3GP
|
||||
分辨率:十进制整数字符串表示
|
||||
1 – QCIF 2 – CIF 3 – 4CIF 4 – D1 5 –720P 6 –1080P/I
|
||||
帧率:十进制整数字符串表示 0~99
|
||||
码率类型:十进制整数字符串表示
|
||||
1 – 固定码率(CBR) 2 – 可变码率(VBR)
|
||||
码率大小:十进制整数字符串表示 0~100000(如 1表示1kbps)
|
||||
a:后续参数为音频的参数;各参数间以 “/”分割;
|
||||
编码格式:十进制整数字符串表示
|
||||
1 – G.711 2 – G.723.1 3 – G.729 4 – G.722.1
|
||||
码率大小:十进制整数字符串
|
||||
音频编码码率: 1 — 5.3 kbps (注:G.723.1中使用)
|
||||
2 — 6.3 kbps (注:G.723.1中使用)
|
||||
3 — 8 kbps (注:G.729中使用)
|
||||
4 — 16 kbps (注:G.722.1中使用)
|
||||
5 — 24 kbps (注:G.722.1中使用)
|
||||
6 — 32 kbps (注:G.722.1中使用)
|
||||
7 — 48 kbps (注:G.722.1中使用)
|
||||
8 — 64 kbps(注:G.711中使用)
|
||||
采样率:十进制整数字符串表示
|
||||
1 — 8 kHz(注:G.711/ G.723.1/ G.729中使用)
|
||||
2—14 kHz(注:G.722.1中使用)
|
||||
3—16 kHz(注:G.722.1中使用)
|
||||
4—32 kHz(注:G.722.1中使用)
|
||||
注1:字符串说明
|
||||
本节中使用的“十进制整数字符串”的含义为“0”~“4294967296” 之间的十进制数字字符串。
|
||||
注2:参数分割标识
|
||||
各参数间以“/”分割,参数间的分割符“/”不能省略;
|
||||
若两个分割符 “/”间的某参数为空时(即两个分割符 “/”直接将相连时)表示无该参数值;
|
||||
注3:f字段说明
|
||||
使用f字段时,应保证视频和音频参数的结构完整性,即在任何时候,f字段的结构都应是完整的结构:
|
||||
f = v/编码格式/分辨率/帧率/码率类型/码率大小a/编码格式/码率大小/采样率
|
||||
若只有视频时,音频中的各参数项可以不填写,但应保持 “a///”的结构:
|
||||
f = v/编码格式/分辨率/帧率/码率类型/码率大小a///
|
||||
若只有音频时也类似处理,视频中的各参数项可以不填写,但应保持 “v/”的结构:
|
||||
f = v/a/编码格式/码率大小/采样率
|
||||
f字段中视、音频参数段之间不需空格分割。
|
||||
可使用f字段中的分辨率参数标识同一设备不同分辨率的码流。
|
||||
*/
|
||||
func (channel *Channel) Invite(start, end string) (code int) {
|
||||
if start == "" {
|
||||
if !atomic.CompareAndSwapInt32(&channel.state, 0, 1) {
|
||||
return 304
|
||||
}
|
||||
defer func() {
|
||||
if code != 200 {
|
||||
atomic.StoreInt32(&channel.state, 0)
|
||||
}
|
||||
}()
|
||||
channel.Bye(true)
|
||||
} else {
|
||||
channel.Bye(false)
|
||||
}
|
||||
sint, err1 := strconv.ParseInt(start, 10, 0)
|
||||
eint, err2 := strconv.ParseInt(end, 10, 0)
|
||||
d := channel.device
|
||||
streamPath := fmt.Sprintf("%s/%s", d.ID, channel.DeviceID)
|
||||
s := "Play"
|
||||
ssrc := make([]byte, 10)
|
||||
if start != "" {
|
||||
if err1 != nil || err2 != nil {
|
||||
return 400
|
||||
}
|
||||
s = "Playback"
|
||||
ssrc[0] = '1'
|
||||
streamPath = fmt.Sprintf("%s/%s/%s-%s", d.ID, channel.DeviceID, start, end)
|
||||
} else {
|
||||
ssrc[0] = '0'
|
||||
}
|
||||
|
||||
// size := 1
|
||||
// fps := 15
|
||||
// bitrate := 200
|
||||
// fmt.Sprintf("f=v/2/%d/%d/1/%da///", size, fps, bitrate)
|
||||
copy(ssrc[1:6], []byte(config.Serial[3:8]))
|
||||
randNum := rand.Intn(10000)
|
||||
copy(ssrc[6:], []byte(strconv.Itoa(randNum)))
|
||||
protocol := ""
|
||||
port := config.MediaPort
|
||||
if config.TCP {
|
||||
protocol = "TCP/"
|
||||
port = config.MediaPort + channel.tcpPortIndex
|
||||
if channel.tcpPortIndex++; channel.tcpPortIndex >= config.TCPMediaPortNum {
|
||||
channel.tcpPortIndex = 0
|
||||
}
|
||||
}
|
||||
sdpInfo := []string{
|
||||
"v=0",
|
||||
fmt.Sprintf("o=%s 0 0 IN IP4 %s", d.Serial, d.SipIP),
|
||||
"s=" + s,
|
||||
"u=" + channel.DeviceID + ":0",
|
||||
"c=IN IP4 " + d.SipIP,
|
||||
fmt.Sprintf("t=%d %d", sint, eint),
|
||||
fmt.Sprintf("m=video %d %sRTP/AVP 96", port, protocol),
|
||||
"a=recvonly",
|
||||
"a=rtpmap:96 PS/90000",
|
||||
}
|
||||
if config.TCP {
|
||||
sdpInfo = append(sdpInfo, "a=setup:passive", "a=connection:new")
|
||||
}
|
||||
invite := channel.CreateMessage(sip.INVITE)
|
||||
invite.ContentType = "application/sdp"
|
||||
invite.Contact = &sip.Contact{
|
||||
Uri: sip.NewURI(fmt.Sprintf("%s@%s:%d", d.Serial, d.SipIP, d.SipPort)),
|
||||
}
|
||||
invite.Body = strings.Join(sdpInfo, "\r\n") + "\r\ny=" + string(ssrc) + "\r\n"
|
||||
invite.ContentLength = len(invite.Body)
|
||||
invite.Subject = fmt.Sprintf("%s:%s,%s:0", channel.DeviceID, ssrc, config.Serial)
|
||||
response := d.SendMessage(invite)
|
||||
fmt.Printf("invite response statuscode: %d\n", response.Code)
|
||||
if response.Code == 200 {
|
||||
ds := strings.Split(response.Data.Body, "\r\n")
|
||||
_SSRC, _ := strconv.ParseInt(string(ssrc), 10, 0)
|
||||
SSRC := uint32(_SSRC)
|
||||
for _, l := range ds {
|
||||
if ls := strings.Split(l, "="); len(ls) > 1 {
|
||||
if ls[0] == "y" && len(ls[1]) > 0 {
|
||||
_SSRC, _ = strconv.ParseInt(ls[1], 10, 0)
|
||||
SSRC = uint32(_SSRC)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
publisher := &Publisher{
|
||||
Stream: &engine.Stream{
|
||||
StreamPath: streamPath,
|
||||
AutoCloseAfter: &config.AutoCloseAfter,
|
||||
},
|
||||
}
|
||||
if config.UdpCacheSize > 0 && !config.TCP {
|
||||
publisher.udpCache = utils.NewPqRtp()
|
||||
}
|
||||
if start == "" {
|
||||
publisher.Type = "GB28181 Live"
|
||||
publisher.OnClose = func() {
|
||||
publishers.Remove(SSRC)
|
||||
channel.LivePublisher = nil
|
||||
channel.ByeBye(channel.inviteRes)
|
||||
channel.inviteRes = nil
|
||||
atomic.StoreInt32(&channel.state, 0)
|
||||
if config.AutoInvite {
|
||||
go channel.Invite("", "")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
publisher.Type = "GB28181 Record"
|
||||
publisher.OnClose = func() {
|
||||
publishers.Remove(SSRC)
|
||||
channel.RecordPublisher = nil
|
||||
channel.ByeBye(channel.recordInviteRes)
|
||||
channel.recordInviteRes = nil
|
||||
}
|
||||
}
|
||||
if !publisher.Publish() {
|
||||
return 403
|
||||
}
|
||||
publishers.Add(SSRC, publisher)
|
||||
if start == "" {
|
||||
channel.inviteRes = response.Data
|
||||
channel.LivePublisher = publisher
|
||||
} else {
|
||||
channel.RecordPublisher = publisher
|
||||
channel.recordInviteRes = response.Data
|
||||
}
|
||||
ack := d.CreateMessage(sip.ACK)
|
||||
ack.StartLine = &sip.StartLine{
|
||||
Uri: sip.NewURI(channel.DeviceID + "@" + d.to.Uri.Domain()),
|
||||
Method: sip.ACK,
|
||||
}
|
||||
ack.From = response.Data.From
|
||||
ack.To = response.Data.To
|
||||
ack.CallID = response.Data.CallID
|
||||
ack.CSeq.ID = invite.CSeq.ID
|
||||
go d.Send(ack)
|
||||
} else if start == "" && config.AutoInvite {
|
||||
time.AfterFunc(time.Second*5, func() {
|
||||
channel.Invite("", "")
|
||||
})
|
||||
}
|
||||
return response.Code
|
||||
}
|
||||
func (channel *Channel) Bye(live bool) int {
|
||||
if live && channel.inviteRes != nil {
|
||||
defer func() {
|
||||
channel.inviteRes = nil
|
||||
if channel.LivePublisher != nil {
|
||||
channel.LivePublisher.Close()
|
||||
}
|
||||
}()
|
||||
return channel.ByeBye(channel.inviteRes).Code
|
||||
}
|
||||
if !live && channel.recordInviteRes != nil {
|
||||
defer func() {
|
||||
channel.recordInviteRes = nil
|
||||
if channel.RecordPublisher != nil {
|
||||
channel.RecordPublisher.Close()
|
||||
}
|
||||
}()
|
||||
return channel.ByeBye(channel.recordInviteRes).Code
|
||||
}
|
||||
return 404
|
||||
}
|
||||
func (c *Channel) ByeBye(res *sip.Message) *transaction.Response {
|
||||
if res == nil {
|
||||
return nil
|
||||
}
|
||||
bye := c.device.CreateMessage(sip.BYE)
|
||||
bye.StartLine = &sip.StartLine{
|
||||
Uri: sip.NewURI(c.DeviceID + "@" + c.device.to.Uri.Domain()),
|
||||
Method: sip.BYE,
|
||||
}
|
||||
bye.From = res.From
|
||||
bye.To = res.To
|
||||
bye.CallID = res.CallID
|
||||
return c.device.SendMessage(bye)
|
||||
}
|
||||
364
device.go
364
device.go
@@ -3,55 +3,18 @@ package gb28181
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/Monibuca/plugin-gb28181/transaction"
|
||||
|
||||
"github.com/Monibuca/plugin-gb28181/sip"
|
||||
"github.com/Monibuca/plugin-gb28181/utils"
|
||||
"github.com/Monibuca/engine/v3"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/sip"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/transaction"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/utils"
|
||||
// . "github.com/Monibuca/utils/v3"
|
||||
// . "github.com/logrusorgru/aurora"
|
||||
)
|
||||
|
||||
type ChannelEx struct {
|
||||
device *Device
|
||||
inviteRes *sip.Message
|
||||
recordInviteRes *sip.Message
|
||||
RecordSP string //正在播放录像的StreamPath
|
||||
LiveSP string //实时StreamPath
|
||||
Connected bool
|
||||
Records []*Record
|
||||
}
|
||||
|
||||
// Channel 通道
|
||||
type Channel struct {
|
||||
DeviceID string
|
||||
Name string
|
||||
Manufacturer string
|
||||
Model string
|
||||
Owner string
|
||||
CivilCode string
|
||||
Address string
|
||||
Parental int
|
||||
SafetyWay int
|
||||
RegisterWay int
|
||||
Secrecy int
|
||||
Status string
|
||||
ChannelEx //自定义属性
|
||||
}
|
||||
|
||||
// func (c *Channel) MarshalJSON() ([]byte, error) {
|
||||
// var data = map[string]interface{}{
|
||||
// "DeviceID": c.DeviceID,
|
||||
// "Name": c.Name,
|
||||
// "Manufacturer": c.Manufacturer,
|
||||
// "Address": c.Address,
|
||||
// "Status": c.Status,
|
||||
// "RecordSP": c.RecordSP,
|
||||
// "LiveSP": c.LiveSP,
|
||||
// "Records": c.Records,
|
||||
// "Connected": c.Connected,
|
||||
// }
|
||||
// return json.Marshal(data)
|
||||
// }
|
||||
const TIME_LAYOUT = "2006-01-02T15:04:05"
|
||||
|
||||
// Record 录像
|
||||
type Record struct {
|
||||
@@ -82,54 +45,90 @@ type Device struct {
|
||||
to *sip.Contact
|
||||
Addr string
|
||||
SipIP string //暴露的IP
|
||||
channelMap map[string]*Channel
|
||||
channelMutex sync.RWMutex
|
||||
subscriber struct {
|
||||
CallID string
|
||||
Timeout time.Time
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Device) addChannel(channel *Channel) {
|
||||
for _, c := range d.Channels {
|
||||
if c.DeviceID == channel.DeviceID {
|
||||
return
|
||||
}
|
||||
}
|
||||
d.Channels = append(d.Channels, channel)
|
||||
}
|
||||
|
||||
func (d *Device) CheckSubStream() {
|
||||
d.channelMutex.Lock()
|
||||
defer d.channelMutex.Unlock()
|
||||
for _, c := range d.Channels {
|
||||
if s := engine.FindStream("sub/" + c.DeviceID); s != nil {
|
||||
c.LiveSubSP = s.StreamPath
|
||||
} else {
|
||||
c.LiveSubSP = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
func (d *Device) UpdateChannels(list []*Channel) {
|
||||
d.channelMutex.Lock()
|
||||
defer d.channelMutex.Unlock()
|
||||
for _, c := range list {
|
||||
c.device = d
|
||||
have := false
|
||||
for i, o := range d.Channels {
|
||||
if o.DeviceID == c.DeviceID {
|
||||
c.ChannelEx = o.ChannelEx
|
||||
d.Channels[i] = c
|
||||
have = true
|
||||
break
|
||||
if _, ok := Ignores[c.DeviceID]; ok {
|
||||
continue
|
||||
}
|
||||
if c.ParentID != "" {
|
||||
path := strings.Split(c.ParentID, "/")
|
||||
parentId := path[len(path)-1]
|
||||
if parent, ok := d.channelMap[parentId]; ok {
|
||||
parent.Children = append(parent.Children, c)
|
||||
} else {
|
||||
d.addChannel(c)
|
||||
}
|
||||
} else {
|
||||
d.addChannel(c)
|
||||
}
|
||||
if old, ok := d.channelMap[c.DeviceID]; ok {
|
||||
c.ChannelEx = old.ChannelEx
|
||||
if len(old.Children) == 0 {
|
||||
if config.PreFetchRecord {
|
||||
n := time.Now()
|
||||
n = time.Date(n.Year(), n.Month(), n.Day(), 0, 0, 0, 0, time.Local)
|
||||
if len(c.Records) == 0 || (n.Format(TIME_LAYOUT) == c.RecordStartTime && n.Add(time.Hour*24-time.Second).Format(TIME_LAYOUT) == c.RecordEndTime) {
|
||||
go c.QueryRecord(n.Format(TIME_LAYOUT), n.Add(time.Hour*24-time.Second).Format(TIME_LAYOUT))
|
||||
}
|
||||
}
|
||||
if config.AutoInvite && c.LivePublisher == nil {
|
||||
go c.Invite("", "")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
c.ChannelEx = &ChannelEx{
|
||||
device: d,
|
||||
}
|
||||
if config.AutoInvite {
|
||||
go c.Invite("", "")
|
||||
}
|
||||
}
|
||||
if !have {
|
||||
d.Channels = append(d.Channels, c)
|
||||
if s := engine.FindStream("sub/" + c.DeviceID); s != nil {
|
||||
c.LiveSubSP = s.StreamPath
|
||||
} else {
|
||||
c.LiveSubSP = ""
|
||||
}
|
||||
d.channelMap[c.DeviceID] = c
|
||||
}
|
||||
}
|
||||
func (d *Device) UpdateRecord(channelId string, list []*Record) {
|
||||
for _, c := range d.Channels {
|
||||
if c.DeviceID == channelId {
|
||||
c.Records = list
|
||||
//for _, o := range list {
|
||||
// o.channel = c
|
||||
//}
|
||||
break
|
||||
}
|
||||
d.channelMutex.RLock()
|
||||
if c, ok := d.channelMap[channelId]; ok {
|
||||
c.Records = append(c.Records, list...)
|
||||
}
|
||||
d.channelMutex.RUnlock()
|
||||
}
|
||||
func (c *Channel) CreateMessage(Method sip.Method) (requestMsg *sip.Message) {
|
||||
requestMsg = c.device.CreateMessage(Method)
|
||||
requestMsg.StartLine.Uri = sip.NewURI(c.DeviceID + "@" + c.device.to.Uri.Domain())
|
||||
requestMsg.To = &sip.Contact{
|
||||
Uri: requestMsg.StartLine.Uri,
|
||||
}
|
||||
requestMsg.From = &sip.Contact{
|
||||
Uri: sip.NewURI(config.Serial + "@" + config.Realm),
|
||||
Params: map[string]string{"tag": utils.RandNumString(9)},
|
||||
}
|
||||
return
|
||||
}
|
||||
func (c *Channel) GetPublishStreamPath(start string) string {
|
||||
if start == "0" {
|
||||
return fmt.Sprintf("%s/%s", c.device.ID, c.DeviceID)
|
||||
}
|
||||
return fmt.Sprintf("%s/%s", c.DeviceID, start)
|
||||
}
|
||||
|
||||
func (d *Device) CreateMessage(Method sip.Method) (requestMsg *sip.Message) {
|
||||
d.sn++
|
||||
requestMsg = &sip.Message{
|
||||
@@ -147,20 +146,25 @@ func (d *Device) CreateMessage(Method sip.Method) (requestMsg *sip.Message) {
|
||||
"branch": fmt.Sprintf("z9hG4bK%s", utils.RandNumString(8)),
|
||||
"rport": "-1", //only key,no-value
|
||||
},
|
||||
}, From: d.from,
|
||||
}, From: &sip.Contact{Uri: d.from.Uri, Params: map[string]string{"tag": utils.RandNumString(9)}},
|
||||
To: d.to, CSeq: &sip.CSeq{
|
||||
ID: uint32(d.sn),
|
||||
Method: Method,
|
||||
}, CallID: utils.RandNumString(10),
|
||||
Addr: d.Addr,
|
||||
}
|
||||
requestMsg.From.Params["tag"] = utils.RandNumString(9)
|
||||
return
|
||||
}
|
||||
func (d *Device) Query() int {
|
||||
requestMsg := d.CreateMessage(sip.MESSAGE)
|
||||
func (d *Device) Subscribe() int {
|
||||
requestMsg := d.CreateMessage(sip.SUBSCRIBE)
|
||||
if d.subscriber.CallID != "" {
|
||||
requestMsg.CallID = d.subscriber.CallID
|
||||
}
|
||||
requestMsg.Expires = 3600
|
||||
requestMsg.Event = "Catalog"
|
||||
d.subscriber.Timeout = time.Now().Add(time.Second * time.Duration(requestMsg.Expires))
|
||||
requestMsg.ContentType = "Application/MANSCDP+xml"
|
||||
requestMsg.Body = fmt.Sprintf(`<?xml version="1.0"?>
|
||||
requestMsg.Body = fmt.Sprintf(`<?xml version="1.0" encoding="gb2312"?>
|
||||
<Query>
|
||||
<CmdType>Catalog</CmdType>
|
||||
<SN>%d</SN>
|
||||
@@ -168,172 +172,34 @@ func (d *Device) Query() int {
|
||||
</Query>`, d.sn, requestMsg.To.Uri.UserInfo())
|
||||
requestMsg.ContentLength = len(requestMsg.Body)
|
||||
response := d.SendMessage(requestMsg)
|
||||
if response.Data != nil && response.Data.Via.Params["received"] != "" {
|
||||
d.SipIP = response.Data.Via.Params["received"]
|
||||
}
|
||||
return response.Code
|
||||
}
|
||||
func (d *Device) QueryRecord(channelIndex int, startTime, endTime string) int {
|
||||
channel := d.Channels[channelIndex]
|
||||
requestMsg := channel.CreateMessage(sip.MESSAGE)
|
||||
requestMsg.ContentType = "Application/MANSCDP+xml"
|
||||
requestMsg.Body = fmt.Sprintf(`<?xml version="1.0"?>
|
||||
<Query>
|
||||
<CmdType>RecordInfo</CmdType>
|
||||
<SN>%d</SN>
|
||||
<DeviceID>%s</DeviceID>
|
||||
<StartTime>%s</StartTime>
|
||||
<EndTime>%s</EndTime>
|
||||
<Secrecy>0</Secrecy>
|
||||
<Type>time</Type>
|
||||
</Query>`, d.sn, requestMsg.To.Uri.UserInfo(), startTime, endTime)
|
||||
requestMsg.ContentLength = len(requestMsg.Body)
|
||||
return d.SendMessage(requestMsg).Code
|
||||
}
|
||||
func (d *Device) Control(channelIndex int, PTZCmd string) int {
|
||||
channel := d.Channels[channelIndex]
|
||||
requestMsg := channel.CreateMessage(sip.MESSAGE)
|
||||
requestMsg.ContentType = "Application/MANSCDP+xml"
|
||||
requestMsg.Body = fmt.Sprintf(`<?xml version="1.0"?>
|
||||
<Control>
|
||||
<CmdType>DeviceControl</CmdType>
|
||||
<SN>%d</SN>
|
||||
<DeviceID>%s</DeviceID>
|
||||
<PTZCmd>%s</PTZCmd>
|
||||
</Control>`, d.sn, requestMsg.To.Uri.UserInfo(), PTZCmd)
|
||||
requestMsg.ContentLength = len(requestMsg.Body)
|
||||
return d.SendMessage(requestMsg).Code
|
||||
}
|
||||
|
||||
/*
|
||||
f字段: f = v/编码格式/分辨率/帧率/码率类型/码率大小a/编码格式/码率大小/采样率
|
||||
各项具体含义:
|
||||
v:后续参数为视频的参数;各参数间以 “/”分割;
|
||||
编码格式:十进制整数字符串表示
|
||||
1 –MPEG-4 2 –H.264 3 – SVAC 4 –3GP
|
||||
分辨率:十进制整数字符串表示
|
||||
1 – QCIF 2 – CIF 3 – 4CIF 4 – D1 5 –720P 6 –1080P/I
|
||||
帧率:十进制整数字符串表示 0~99
|
||||
码率类型:十进制整数字符串表示
|
||||
1 – 固定码率(CBR) 2 – 可变码率(VBR)
|
||||
码率大小:十进制整数字符串表示 0~100000(如 1表示1kbps)
|
||||
a:后续参数为音频的参数;各参数间以 “/”分割;
|
||||
编码格式:十进制整数字符串表示
|
||||
1 – G.711 2 – G.723.1 3 – G.729 4 – G.722.1
|
||||
码率大小:十进制整数字符串
|
||||
音频编码码率: 1 — 5.3 kbps (注:G.723.1中使用)
|
||||
2 — 6.3 kbps (注:G.723.1中使用)
|
||||
3 — 8 kbps (注:G.729中使用)
|
||||
4 — 16 kbps (注:G.722.1中使用)
|
||||
5 — 24 kbps (注:G.722.1中使用)
|
||||
6 — 32 kbps (注:G.722.1中使用)
|
||||
7 — 48 kbps (注:G.722.1中使用)
|
||||
8 — 64 kbps(注:G.711中使用)
|
||||
采样率:十进制整数字符串表示
|
||||
1 — 8 kHz(注:G.711/ G.723.1/ G.729中使用)
|
||||
2—14 kHz(注:G.722.1中使用)
|
||||
3—16 kHz(注:G.722.1中使用)
|
||||
4—32 kHz(注:G.722.1中使用)
|
||||
注1:字符串说明
|
||||
本节中使用的“十进制整数字符串”的含义为“0”~“4294967296” 之间的十进制数字字符串。
|
||||
注2:参数分割标识
|
||||
各参数间以“/”分割,参数间的分割符“/”不能省略;
|
||||
若两个分割符 “/”间的某参数为空时(即两个分割符 “/”直接将相连时)表示无该参数值;
|
||||
注3:f字段说明
|
||||
使用f字段时,应保证视频和音频参数的结构完整性,即在任何时候,f字段的结构都应是完整的结构:
|
||||
f = v/编码格式/分辨率/帧率/码率类型/码率大小a/编码格式/码率大小/采样率
|
||||
若只有视频时,音频中的各参数项可以不填写,但应保持 “a///”的结构:
|
||||
f = v/编码格式/分辨率/帧率/码率类型/码率大小a///
|
||||
若只有音频时也类似处理,视频中的各参数项可以不填写,但应保持 “v/”的结构:
|
||||
f = v/a/编码格式/码率大小/采样率
|
||||
f字段中视、音频参数段之间不需空格分割。
|
||||
可使用f字段中的分辨率参数标识同一设备不同分辨率的码流。
|
||||
*/
|
||||
func (d *Device) Invite(channelIndex int, start, end string, f string) int {
|
||||
channel := d.Channels[channelIndex]
|
||||
port, publisher := d.publish(channel.GetPublishStreamPath(start))
|
||||
if port == 0 {
|
||||
channel.Connected = true
|
||||
return 304
|
||||
}
|
||||
ssrc := "0200000001"
|
||||
// size := 1
|
||||
// fps := 15
|
||||
// bitrate := 200
|
||||
// fmt.Sprintf("f=v/2/%d/%d/1/%da///", size, fps, bitrate)
|
||||
s := "Play"
|
||||
if start != "0" {
|
||||
s = "Playback"
|
||||
publisher.AutoUnPublish = true
|
||||
channel.RecordSP = publisher.StreamPath
|
||||
} else {
|
||||
channel.LiveSP = publisher.StreamPath
|
||||
}
|
||||
sdpInfo := []string{
|
||||
"v=0",
|
||||
fmt.Sprintf("o=%s 0 0 IN IP4 %s", d.Serial, d.SipIP),
|
||||
"s=" + s,
|
||||
"u=" + channel.DeviceID + ":0",
|
||||
"c=IN IP4 " + d.SipIP,
|
||||
fmt.Sprintf("t=%s %s", start, end),
|
||||
fmt.Sprintf("m=video %d RTP/AVP 96 97 98", port),
|
||||
"a=recvonly",
|
||||
"a=rtpmap:96 PS/90000",
|
||||
"a=rtpmap:97 MPEG4/90000",
|
||||
"a=rtpmap:98 H264/90000",
|
||||
"y=" + ssrc,
|
||||
"f=" + f,
|
||||
}
|
||||
|
||||
invite := channel.CreateMessage(sip.INVITE)
|
||||
invite.ContentType = "application/sdp"
|
||||
invite.Contact = &sip.Contact{
|
||||
Uri: sip.NewURI(fmt.Sprintf("%s@%s:%d", d.Serial, d.SipIP, d.SipPort)),
|
||||
}
|
||||
invite.Body = strings.Join(sdpInfo, "\r\n") + "\r\n"
|
||||
invite.ContentLength = len(invite.Body)
|
||||
invite.Subject = fmt.Sprintf("%s:%s,%s:0", channel.DeviceID, ssrc, config.Serial)
|
||||
response := d.SendMessage(invite)
|
||||
fmt.Printf("invite response statuscode: %d\n", response.Code)
|
||||
if response.Code == 200 {
|
||||
if start == "0" {
|
||||
channel.inviteRes = response.Data
|
||||
channel.Connected = true
|
||||
} else {
|
||||
channel.recordInviteRes = response.Data
|
||||
}
|
||||
ack := d.CreateMessage(sip.ACK)
|
||||
ack.StartLine = &sip.StartLine{
|
||||
Uri: sip.NewURI(channel.DeviceID + "@" + d.to.Uri.Domain()),
|
||||
Method: sip.ACK,
|
||||
}
|
||||
ack.From = response.Data.From
|
||||
ack.To = response.Data.To
|
||||
ack.CallID = response.Data.CallID
|
||||
ack.CSeq.ID = invite.CSeq.ID
|
||||
go d.Send(ack)
|
||||
d.subscriber.CallID = requestMsg.CallID
|
||||
} else {
|
||||
d.subscriber.CallID = ""
|
||||
}
|
||||
return response.Code
|
||||
}
|
||||
func (d *Device) Bye(channelIndex int) int {
|
||||
channel := d.Channels[channelIndex]
|
||||
defer func() {
|
||||
channel.inviteRes = nil
|
||||
channel.Connected = false
|
||||
}()
|
||||
return channel.Bye(channel.inviteRes).Code
|
||||
}
|
||||
func (c *Channel) Bye(res *sip.Message) *transaction.Response {
|
||||
if res == nil {
|
||||
return nil
|
||||
func (d *Device) Query() {
|
||||
for i := time.Duration(5); i < 100; i++ {
|
||||
time.Sleep(time.Second * i)
|
||||
requestMsg := d.CreateMessage(sip.MESSAGE)
|
||||
requestMsg.ContentType = "Application/MANSCDP+xml"
|
||||
requestMsg.Body = fmt.Sprintf(`<?xml version="1.0" encoding="gb2312"?>
|
||||
<Query>
|
||||
<CmdType>Catalog</CmdType>
|
||||
<SN>%d</SN>
|
||||
<DeviceID>%s</DeviceID>
|
||||
</Query>`, d.sn, requestMsg.To.Uri.UserInfo())
|
||||
requestMsg.ContentLength = len(requestMsg.Body)
|
||||
response := d.SendMessage(requestMsg)
|
||||
if response.Data != nil && response.Data.Via.Params["received"] != "" {
|
||||
d.SipIP = response.Data.Via.Params["received"]
|
||||
}
|
||||
if response.Code != 200 {
|
||||
fmt.Printf("device %s send Catalog : %d\n", d.ID, response.Code)
|
||||
} else {
|
||||
d.Subscribe()
|
||||
break
|
||||
}
|
||||
}
|
||||
bye := c.device.CreateMessage(sip.BYE)
|
||||
bye.StartLine = &sip.StartLine{
|
||||
Uri: sip.NewURI(c.DeviceID + "@" + c.device.to.Uri.Domain()),
|
||||
Method: sip.BYE,
|
||||
}
|
||||
bye.From = res.From
|
||||
bye.To = res.To
|
||||
bye.CallID = res.CallID
|
||||
return c.device.SendMessage(bye)
|
||||
}
|
||||
|
||||
20
go.mod
20
go.mod
@@ -1,19 +1,13 @@
|
||||
module github.com/Monibuca/plugin-gb28181
|
||||
module github.com/Monibuca/plugin-gb28181/v3
|
||||
|
||||
go 1.13
|
||||
|
||||
require (
|
||||
github.com/Monibuca/engine/v2 v2.2.5
|
||||
github.com/Monibuca/plugin-gateway v1.2.6 // indirect
|
||||
github.com/Monibuca/plugin-hdl v1.2.5 // indirect
|
||||
github.com/Monibuca/plugin-hls v1.2.1 // indirect
|
||||
github.com/Monibuca/plugin-jessica v1.3.0 // indirect
|
||||
github.com/Monibuca/plugin-logrotate v1.2.3 // indirect
|
||||
github.com/Monibuca/plugin-record v1.0.4 // indirect
|
||||
github.com/Monibuca/plugin-rtmp v1.2.5 // indirect
|
||||
github.com/Monibuca/plugin-rtp v1.0.0
|
||||
github.com/Monibuca/plugin-rtsp v1.3.1 // indirect
|
||||
github.com/Monibuca/plugin-webrtc v1.2.2 // indirect
|
||||
github.com/Monibuca/engine/v3 v3.4.5
|
||||
github.com/Monibuca/utils/v3 v3.0.5
|
||||
github.com/agiledragon/gomonkey/v2 v2.2.0
|
||||
github.com/logrusorgru/aurora v2.0.3+incompatible
|
||||
golang.org/x/net v0.0.0-20201029221708-28c70e62bb1d
|
||||
github.com/pion/rtp v1.7.4
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2
|
||||
golang.org/x/text v0.3.7
|
||||
)
|
||||
|
||||
192
go.sum
192
go.sum
@@ -1,180 +1,98 @@
|
||||
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/Monibuca/engine/v2 v2.0.0/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc=
|
||||
github.com/Monibuca/engine/v2 v2.1.9/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc=
|
||||
github.com/Monibuca/engine/v2 v2.2.0/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc=
|
||||
github.com/Monibuca/engine/v2 v2.2.2/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc=
|
||||
github.com/Monibuca/engine/v2 v2.2.5 h1:/w0BrvdTy4cqLD2uaIRaqBwdnu+/VDk+r3sjFbpbc1E=
|
||||
github.com/Monibuca/engine/v2 v2.2.5/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc=
|
||||
github.com/Monibuca/plugin-gateway v1.2.6 h1:ZHwHMmjBs3Itxxd/Z/OR7c5QdED1sqSmBJ/6U+Y/Hc0=
|
||||
github.com/Monibuca/plugin-gateway v1.2.6/go.mod h1:l+BaE5QZY0Pr92iiIXS67gt2VxcBuOxYyqIGOEGbuFk=
|
||||
github.com/Monibuca/plugin-hdl v1.2.5 h1:zIo4ptkIzn/L1KhutsZ2Bk17OoyRbundXG+8c1ki6cQ=
|
||||
github.com/Monibuca/plugin-hdl v1.2.5/go.mod h1:+Qm9B5tQfxQdZ1hJQZbW4BZLOQWbPwN9qkB0vPGFo1U=
|
||||
github.com/Monibuca/plugin-hls v1.2.1 h1:vD8LFB1t87fKuEycuQYa1nayCcEkRpIo0xosDJX3yGM=
|
||||
github.com/Monibuca/plugin-hls v1.2.1/go.mod h1:8mIEvD09qDxp2Lso7fOQnfNFcxPcMxa6P9dGBbUOZD0=
|
||||
github.com/Monibuca/plugin-jessica v1.3.0 h1:VPLPl76ykEHvrtQMy4+UZQBJd2gjYfWQbrg47qnOIT0=
|
||||
github.com/Monibuca/plugin-jessica v1.3.0/go.mod h1:9TOsOzeVNbTCbgZ6xMANNMA0h5O/GxdlCLhavo6yVHM=
|
||||
github.com/Monibuca/plugin-logrotate v1.2.3 h1:Q3V4VrN8fVUQnN+RIP+wn/+ZrZ/cu8xM5rTeIg74QVM=
|
||||
github.com/Monibuca/plugin-logrotate v1.2.3/go.mod h1:bo2zR3H2CuyN2+dbsnZ6IvM+NT87r9H2RptVyyxkvTY=
|
||||
github.com/Monibuca/plugin-record v1.0.4 h1:dPXJKlkljyhNUrpVP3586QO1L2DFvvl8m+ZXmQlEul8=
|
||||
github.com/Monibuca/plugin-record v1.0.4/go.mod h1:POh+M09c+U1YAt6ratoKXahjt8GopEL0k6M8DUXbmAc=
|
||||
github.com/Monibuca/plugin-rtmp v1.2.5 h1:y9tQ7ayg8y3PE8jpBmb3/EHNgBL5cppptKvulFdvkzE=
|
||||
github.com/Monibuca/plugin-rtmp v1.2.5/go.mod h1:RSbufAndiyYfeLz4OiZwcGS/UTHCyTDtqvHzvzRQtWE=
|
||||
github.com/Monibuca/plugin-rtp v1.0.0 h1:yksNsIIGxoKX8UZirkAUK+mGZ/XoEeS2vqbIqtqXyCg=
|
||||
github.com/Monibuca/plugin-rtp v1.0.0/go.mod h1:0xkNm23a/BjVnEMz1zXyOqfEjoVmGe3PJqPNF1KyFGc=
|
||||
github.com/Monibuca/plugin-rtsp v1.3.1 h1:b7xtRIBVcoa6WDseErVDzt+8dZGaUwhDLHxGuutROag=
|
||||
github.com/Monibuca/plugin-rtsp v1.3.1/go.mod h1:N5nEu2SZTf4NMJn7DLlw39wQ4kXZAuMrfbbNtYES894=
|
||||
github.com/Monibuca/plugin-ts v1.2.1 h1:Y2QgEal9/ot43QEvtzRkmA8yk+N2uzieAzKuujZJFMs=
|
||||
github.com/Monibuca/plugin-ts v1.2.1/go.mod h1:MZsdv34Od1Kh1WOkuqIAO/t2irjzW39RMO9WbpFks4g=
|
||||
github.com/Monibuca/plugin-webrtc v1.2.2 h1:XTc3kUyzpoxXC0L9qVUhrhGFBy9YagdRzJb6lDU9HTc=
|
||||
github.com/Monibuca/plugin-webrtc v1.2.2/go.mod h1:ZPcGimoI8Yl/IzQJhSp4jgVOpmMeqPDcN7H8xv1Xj9g=
|
||||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk=
|
||||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
|
||||
github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wXkRAgjxjQ=
|
||||
github.com/BurntSushi/toml v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw=
|
||||
github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||
github.com/Monibuca/engine/v3 v3.4.5 h1:gPRsliBVC70EhKK7sJz/3LoNO7lfnXNC8uUaOIHZkUE=
|
||||
github.com/Monibuca/engine/v3 v3.4.5/go.mod h1:Dik9pFxU9TFI5vj8Sv5QXZM+ooCs2fm9P7Uhe4yYNkQ=
|
||||
github.com/Monibuca/utils/v3 v3.0.5 h1:w14x0HkWTbF4MmHbINLlOwe4VJNoSOeaQChMk5E/4es=
|
||||
github.com/Monibuca/utils/v3 v3.0.5/go.mod h1:RpNS95gapWs6gimwh8Xn2x72FN5tO7Powabj7dTFyvE=
|
||||
github.com/agiledragon/gomonkey/v2 v2.2.0 h1:QJWqpdEhGV/JJy70sZ/LDnhbSlMrqHAWHcNOjz1kyuI=
|
||||
github.com/agiledragon/gomonkey/v2 v2.2.0/go.mod h1:ap1AmDzcVOAz1YpeJ3TCzIgstoaWLA6jbbgxfB4w2iY=
|
||||
github.com/cnotch/apirouter v0.0.0-20200731232942-89e243a791f3/go.mod h1:5deJPLON/x/s2dLOQfuKS0lenhOIT4xX0pvtN/OEIuY=
|
||||
github.com/cnotch/ipchub v1.1.0 h1:hH0lh2mU3AZXPiqMwA0pdtqrwo7PFIMRGush9OobMUs=
|
||||
github.com/cnotch/ipchub v1.1.0/go.mod h1:2PbeBs2q2VxxTVCn1eYCDwpAWuVXbq1+N0FU7GimOH4=
|
||||
github.com/cnotch/loader v0.0.0-20200405015128-d9d964d09439/go.mod h1:oWpDagHB6p+Kqqq7RoRZKyC4XAXft50hR8pbTxdbYYs=
|
||||
github.com/cnotch/queue v0.0.0-20200326024423-6e88bdbf2ad4/go.mod h1:zOssjAlNusOxvtaqT+EMA+Iyi8rrtKr4/XfzN1Fgoeg=
|
||||
github.com/cnotch/queue v0.0.0-20201224060551-4191569ce8f6/go.mod h1:zOssjAlNusOxvtaqT+EMA+Iyi8rrtKr4/XfzN1Fgoeg=
|
||||
github.com/cnotch/scheduler v0.0.0-20200522024700-1d2da93eefc5/go.mod h1:F4GE3SZkJZ8an1Y0ZCqvSM3jeozNuKzoC67erG1PhIo=
|
||||
github.com/cnotch/xlog v0.0.0-20201208005456-cfda439cd3a0/go.mod h1:RW9oHsR79ffl3sR3yMGgxYupMn2btzdtJUwoxFPUE5E=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/emitter-io/address v1.0.0/go.mod h1:GfZb5+S/o8694B1GMGK2imUYQyn2skszMvGNA5D84Ug=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/funny/slab v0.0.0-20180511031532-b1fad5e5d478 h1:Db9StoJ6RZN3YttC0Pm0I4Y5izITRYch3RMbT59BYN0=
|
||||
github.com/funny/slab v0.0.0-20180511031532-b1fad5e5d478/go.mod h1:0j1+svBH8ABEIPdUP0AIg4qedsybnXGJBakCEw8cfoo=
|
||||
github.com/funny/utest v0.0.0-20161029064919-43870a374500 h1:Z0r1CZnoIWFB/Uiwh1BU5FYmuFe6L5NPi6XWQEmsTRg=
|
||||
github.com/funny/utest v0.0.0-20161029064919-43870a374500/go.mod h1:mUn39tBov9jKnTWV1RlOYoNzxdBFHiSzXWdY1FoNGGg=
|
||||
github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
|
||||
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
|
||||
github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee h1:s+21KNqlpePfkah2I+gwHF8xmJWRjooY+5248k6m4A0=
|
||||
github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo=
|
||||
github.com/gobwas/pool v0.2.0 h1:QEmUOlnSjWtnpRGHF3SauEiOsy82Cup83Vf2LcMlnc8=
|
||||
github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
|
||||
github.com/gobwas/ws v1.0.2 h1:CoAavW/wd/kulfZmSIBt6p24n4j7tHgNVCjsfHVNUbo=
|
||||
github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM=
|
||||
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
|
||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||
github.com/kelindar/process v0.0.0-20170730150328-69a29e249ec3/go.mod h1:+lTCLnZFXOkqwD8sLPl6u4erAc0cP8wFegQHfipz7KE=
|
||||
github.com/kelindar/rate v1.0.0/go.mod h1:AjT4G+hTItNwt30lucEGZIz8y7Uk5zPho6vurIZ+1Es=
|
||||
github.com/kelindar/tcp v1.0.0/go.mod h1:JB5hj1cshLU60XrLij2BBxW3JQ4hOye8vqbyvuKb52k=
|
||||
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
|
||||
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
|
||||
github.com/lucas-clemente/quic-go v0.7.1-0.20190401152353-907071221cf9/go.mod h1:PpMmPfPKO9nKJ/psF49ESTAGQSdfXxlg1otPbEB2nOw=
|
||||
github.com/marten-seemann/qtls v0.2.3/go.mod h1:xzjG7avBwGGbdZ8dTGxlBnLArsVKLvwmjgmPuiQEcYk=
|
||||
github.com/mask-pp/rtp-ps v1.0.0 h1:JFxuJL9N+gD1ldgJlAy3b7rYfY8wAVHi9ODNmdP4+EE=
|
||||
github.com/mask-pp/rtp-ps v1.0.0/go.mod h1:jCxsZ2G7z/jX+aqFypEWMePnhNrfnUiXUEKm6Xp0vgU=
|
||||
github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE=
|
||||
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||
github.com/mattn/go-colorable v0.1.7 h1:bQGKb3vps/j0E9GfJQ03JyhRuxsvdAanXlT9BTw3mdw=
|
||||
github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
|
||||
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/pion/datachannel v1.4.17 h1:8CChK5VrJoGrwKCysoTscoWvshCAFpUkgY11Tqgz5hE=
|
||||
github.com/pion/datachannel v1.4.17/go.mod h1:+vPQfypU9vSsyPXogYj1hBThWQ6MNXEQoQAzxoPvjYM=
|
||||
github.com/pion/dtls/v2 v2.0.0 h1:Fk+MBhLZ/U1bImzAhmzwbO/pP2rKhtTw8iA934H3ybE=
|
||||
github.com/pion/dtls/v2 v2.0.0/go.mod h1:VkY5VL2wtsQQOG60xQ4lkV5pdn0wwBBTzCfRJqXhp3A=
|
||||
github.com/pion/ice v0.7.15 h1:s1In+gnuyVq7WKWGVQL+1p+OcrMsbfL+VfSe2isH8Ag=
|
||||
github.com/pion/ice v0.7.15/go.mod h1:Z6zybEQgky5mZkKcLfmvc266JukK2srz3VZBBD1iXBw=
|
||||
github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY=
|
||||
github.com/pion/logging v0.2.2/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms=
|
||||
github.com/pion/mdns v0.0.4 h1:O4vvVqr4DGX63vzmO6Fw9vpy3lfztVWHGCQfyw0ZLSY=
|
||||
github.com/pion/mdns v0.0.4/go.mod h1:R1sL0p50l42S5lJs91oNdUL58nm0QHrhxnSegr++qC0=
|
||||
github.com/pion/quic v0.1.1/go.mod h1:zEU51v7ru8Mp4AUBJvj6psrSth5eEFNnVQK5K48oV3k=
|
||||
github.com/pion/randutil v0.0.0 h1:aLWLVhTG2jzoD25F0OlW6nXvXrjoGwiXq2Sz7j7NzL0=
|
||||
github.com/pion/randutil v0.0.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8=
|
||||
github.com/pion/rtcp v1.2.1 h1:S3yG4KpYAiSmBVqKAfgRa5JdwBNj4zK3RLUa8JYdhak=
|
||||
github.com/pion/rtcp v1.2.1/go.mod h1:a5dj2d6BKIKHl43EnAOIrCczcjESrtPuMgfmL6/K6QM=
|
||||
github.com/pion/rtp v1.5.4 h1:PuNg6xqV3brIUihatcKZj1YDUs+M45L0ZbrZWYtkDxY=
|
||||
github.com/pion/rtp v1.5.4/go.mod h1:bg60AL5GotNOlYZsqycbhDtEV3TkfbpXG0KBiUq29Mg=
|
||||
github.com/pion/rtp v1.6.0 h1:4Ssnl/T5W2LzxHj9ssYpGVEQh3YYhQFNVmSWO88MMwk=
|
||||
github.com/pion/rtp v1.6.0/go.mod h1:QgfogHsMBVE/RFNno467U/KBqfUywEH+HK+0rtnwsdI=
|
||||
github.com/pion/sctp v1.7.6 h1:8qZTdJtbKfAns/Hv5L0PAj8FyXcsKhMH1pKUCGisQg4=
|
||||
github.com/pion/sctp v1.7.6/go.mod h1:ichkYQ5tlgCQwEwvgfdcAolqx1nHbYCxo4D7zK/K0X8=
|
||||
github.com/pion/sdp/v2 v2.3.7 h1:WUZHI3pfiYCaE8UGUYcabk863LCK+Bq3AklV5O0oInQ=
|
||||
github.com/pion/sdp/v2 v2.3.7/go.mod h1:+ZZf35r1+zbaWYiZLfPutWfx58DAWcGb2QsS3D/s9M8=
|
||||
github.com/pion/srtp v1.3.3 h1:8bjs9YaSNvSrbH0OfKxzPX+PTrCyAC2LoT9Qesugi+U=
|
||||
github.com/pion/srtp v1.3.3/go.mod h1:jNe0jmIOqksuurR9S/7yoKDalfPeluUFrNPCBqI4FOI=
|
||||
github.com/pion/stun v0.3.3/go.mod h1:xrCld6XM+6GWDZdvjPlLMsTU21rNxnO6UO8XsAvHr/M=
|
||||
github.com/pion/stun v0.3.5 h1:uLUCBCkQby4S1cf6CGuR9QrVOKcvUwFeemaC865QHDg=
|
||||
github.com/pion/stun v0.3.5/go.mod h1:gDMim+47EeEtfWogA37n6qXZS88L5V6LqFcf+DZA2UA=
|
||||
github.com/pion/transport v0.6.0/go.mod h1:iWZ07doqOosSLMhZ+FXUTq+TamDoXSllxpbGcfkCmbE=
|
||||
github.com/pion/transport v0.8.10/go.mod h1:tBmha/UCjpum5hqTWhfAEs3CO4/tHSg0MYRhSzR+CZ8=
|
||||
github.com/pion/transport v0.10.0/go.mod h1:BnHnUipd0rZQyTVB2SBGojFHT9CBt5C5TcsJSQGkvSE=
|
||||
github.com/pion/transport v0.10.1 h1:2W+yJT+0mOQ160ThZYUx5Zp2skzshiNgxrNE9GUfhJM=
|
||||
github.com/pion/transport v0.10.1/go.mod h1:PBis1stIILMiis0PewDw91WJeLJkyIMcEk+DwKOzf4A=
|
||||
github.com/pion/turn/v2 v2.0.3/go.mod h1:kl1hmT3NxcLynpXVnwJgObL8C9NaCyPTeqI2DcCpSZs=
|
||||
github.com/pion/turn/v2 v2.0.4 h1:oDguhEv2L/4rxwbL9clGLgtzQPjtuZwCdoM7Te8vQVk=
|
||||
github.com/pion/turn/v2 v2.0.4/go.mod h1:1812p4DcGVbYVBTiraUmP50XoKye++AMkbfp+N27mog=
|
||||
github.com/pion/webrtc/v2 v2.2.14 h1:bRjnXTqMDJ3VERPF45z439Sv6QfDfjdYvdQk1QcIx8M=
|
||||
github.com/pion/webrtc/v2 v2.2.14/go.mod h1:G+8lShCMbHhjpMF1ZJBkyuvrxXrvW4bxs3nOt+mJ2UI=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA=
|
||||
github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8=
|
||||
github.com/pion/rtp v1.6.2/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko=
|
||||
github.com/pion/rtp v1.7.4 h1:4dMbjb1SuynU5OpA3kz1zHK+u+eOCQjW3MAeVHf1ODA=
|
||||
github.com/pion/rtp v1.7.4/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko=
|
||||
github.com/pixelbender/go-sdp v1.1.0/go.mod h1:6IBlz9+BrUHoFTea7gcp4S54khtOhjCW/nVDLhmZBAs=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/quangngotan95/go-m3u8 v0.1.0 h1:8oseBjJn5IKHQKdRZwSNskkua3NLrRtlvXXtoVgBzMk=
|
||||
github.com/quangngotan95/go-m3u8 v0.1.0/go.mod h1:smzfWHlYpBATVNu1GapKLYiCtEo5JxridIgvvudZ+Wc=
|
||||
github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw=
|
||||
github.com/shirou/gopsutil v2.20.1+incompatible h1:oIq9Cq4i84Hk8uQAUOG3eNdI/29hBawGrD5YRl6JRDY=
|
||||
github.com/shirou/gopsutil v2.20.1+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||
github.com/shirou/gopsutil v2.20.7+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||
github.com/shirou/gopsutil v2.20.8+incompatible h1:8c7Atn0FAUZJo+f4wYbN0iVpdWniCQk7IYwGtgdh1mY=
|
||||
github.com/shirou/gopsutil v2.20.8+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||
github.com/q191201771/naza v0.19.1 h1:4KLcxT2CHztO+7miPRtBG3FFgadSQYQw1gPPPKN7rnY=
|
||||
github.com/q191201771/naza v0.19.1/go.mod h1:5LeGupZZFtYP1g/S203n9vXoUNVdlRnPIfM6rExjqt0=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||
github.com/sqs/goreturns v0.0.0-20181028201513-538ac6014518/go.mod h1:CKI4AZ4XmGV240rTHfO0hfE83S6/a3/Q1siZJ/vXf7A=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf h1:Z2X3Os7oRzpdJ75iPqWZc0HeJWFYNCvKsfpQwFpRNTA=
|
||||
github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf/go.mod h1:M8agBzgqHIhgj7wEn9/0hJUZcrvt9VY+Ln+S1I5Mha0=
|
||||
github.com/zhangpeihao/goamf v0.0.0-20140409082417-3ff2c19514a8 h1:r1JUI0wuHlgRb8jNd3zPBBkjUdrjpVKr8SdJWc8ntg8=
|
||||
github.com/zhangpeihao/goamf v0.0.0-20140409082417-3ff2c19514a8/go.mod h1:RZd/IqzNpFANwOB9rVmsnAYpo/6KesK4PqrN1a5cRgg=
|
||||
golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20201029221708-28c70e62bb1d h1:dOiJ2n2cMwGLce/74I/QHMbnpk5GfY7InR8rczoMqRM=
|
||||
golang.org/x/net v0.0.0-20201029221708-28c70e62bb1d/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 h1:SQFwaSi55rU7vdNs9Yr0Z324VNlrF+0wMqRXT4St8ck=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a h1:DcqTD9SDLc+1P/r1EmRBwnVsrOwW+kk2vWf9n+1sGhs=
|
||||
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8=
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200828161417-c663848e9a16/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
429
main.go
429
main.go
@@ -1,45 +1,93 @@
|
||||
package gb28181
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"io"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/Monibuca/plugin-gb28181/sip"
|
||||
"golang.org/x/net/html/charset"
|
||||
|
||||
. "github.com/Monibuca/engine/v2"
|
||||
"github.com/Monibuca/engine/v2/util"
|
||||
"github.com/Monibuca/plugin-gb28181/transaction"
|
||||
rtp "github.com/Monibuca/plugin-rtp"
|
||||
"github.com/Monibuca/engine/v3"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/sip"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/transaction"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/utils"
|
||||
. "github.com/Monibuca/utils/v3"
|
||||
. "github.com/logrusorgru/aurora"
|
||||
"github.com/pion/rtp"
|
||||
"golang.org/x/net/html/charset"
|
||||
)
|
||||
|
||||
var Devices sync.Map
|
||||
var (
|
||||
Devices sync.Map
|
||||
DeviceNonce = make(map[string]string) //保存nonce防止设备伪造
|
||||
DeviceRegisterCount = make(map[string]int) //设备注册次数
|
||||
Ignores = make(map[string]struct{})
|
||||
publishers Publishers
|
||||
)
|
||||
|
||||
const MaxRegisterCount = 3
|
||||
|
||||
func FindChannel(deviceId string, channelId string) (c *Channel) {
|
||||
if v, ok := Devices.Load(deviceId); ok {
|
||||
d := v.(*Device)
|
||||
d.channelMutex.RLock()
|
||||
c = d.channelMap[channelId]
|
||||
d.channelMutex.RUnlock()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type Publishers struct {
|
||||
data map[uint32]*Publisher
|
||||
sync.RWMutex
|
||||
}
|
||||
|
||||
func (p *Publishers) Add(key uint32, pp *Publisher) {
|
||||
p.Lock()
|
||||
p.data[key] = pp
|
||||
p.Unlock()
|
||||
}
|
||||
func (p *Publishers) Remove(key uint32) {
|
||||
p.Lock()
|
||||
delete(p.data, key)
|
||||
p.Unlock()
|
||||
}
|
||||
func (p *Publishers) Get(key uint32) *Publisher {
|
||||
p.RLock()
|
||||
defer p.RUnlock()
|
||||
return p.data[key]
|
||||
}
|
||||
|
||||
var config = struct {
|
||||
Serial string
|
||||
Realm string
|
||||
ListenAddr string
|
||||
Expires int
|
||||
AutoInvite bool
|
||||
MediaPortMin uint16
|
||||
MediaPortMax uint16
|
||||
}{"34020000002000000001", "3402000000", "127.0.0.1:5060", 3600, true, 58200, 58300}
|
||||
Serial string
|
||||
Realm string
|
||||
ListenAddr string
|
||||
Expires int
|
||||
MediaPort uint16
|
||||
AutoInvite bool
|
||||
AutoCloseAfter int
|
||||
Ignore []string
|
||||
TCP bool
|
||||
TCPMediaPortNum uint16
|
||||
RemoveBanInterval int
|
||||
PreFetchRecord bool
|
||||
Username string
|
||||
Password string
|
||||
UdpCacheSize int //udp排序缓存
|
||||
}{"34020000002000000001", "3402000000", "127.0.0.1:5060", 3600, 58200, false, -1, nil, false, 1, 600, false, "", "", 0}
|
||||
|
||||
func init() {
|
||||
InstallPlugin(&PluginConfig{
|
||||
pc := engine.PluginConfig{
|
||||
Name: "GB28181",
|
||||
Config: &config,
|
||||
Type: PLUGIN_PUBLISHER,
|
||||
Run: run,
|
||||
})
|
||||
}
|
||||
pc.Install(run)
|
||||
publishers.data = make(map[uint32]*Publisher)
|
||||
}
|
||||
|
||||
func run() {
|
||||
@@ -48,44 +96,45 @@ func run() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
Print(Green("server gb28181 start at"), BrightBlue(config.ListenAddr))
|
||||
for _, id := range config.Ignore {
|
||||
Ignores[id] = struct{}{}
|
||||
}
|
||||
useTCP := config.TCP
|
||||
config := &transaction.Config{
|
||||
SipIP: ipAddr.IP.String(),
|
||||
SipPort: uint16(ipAddr.Port),
|
||||
SipNetwork: "UDP",
|
||||
Serial: config.Serial,
|
||||
Realm: config.Realm,
|
||||
Username: config.Username,
|
||||
Password: config.Password,
|
||||
AckTimeout: 10,
|
||||
MediaIP: ipAddr.IP.String(),
|
||||
RegisterValidity: config.Expires,
|
||||
RegisterInterval: 60,
|
||||
HeartbeatInterval: 60,
|
||||
HeartbeatRetry: 3,
|
||||
|
||||
AudioEnable: true,
|
||||
WaitKeyFrame: true,
|
||||
MediaPortMin: config.MediaPortMin,
|
||||
MediaPortMax: config.MediaPortMax,
|
||||
MediaIdleTimeout: 30,
|
||||
AudioEnable: true,
|
||||
WaitKeyFrame: true,
|
||||
MediaIdleTimeout: 30,
|
||||
RemoveBanInterval: config.RemoveBanInterval,
|
||||
UdpCacheSize: config.UdpCacheSize,
|
||||
}
|
||||
|
||||
http.HandleFunc("/gb28181/query/records", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
http.HandleFunc("/api/gb28181/query/records", func(w http.ResponseWriter, r *http.Request) {
|
||||
CORS(w, r)
|
||||
id := r.URL.Query().Get("id")
|
||||
channel, err := strconv.Atoi(r.URL.Query().Get("channel"))
|
||||
if err != nil {
|
||||
w.WriteHeader(404)
|
||||
}
|
||||
channel := r.URL.Query().Get("channel")
|
||||
startTime := r.URL.Query().Get("startTime")
|
||||
endTime := r.URL.Query().Get("endTime")
|
||||
if v, ok := Devices.Load(id); ok {
|
||||
w.WriteHeader(v.(*Device).QueryRecord(channel, startTime, endTime))
|
||||
if c := FindChannel(id, channel); c != nil {
|
||||
w.WriteHeader(c.QueryRecord(startTime, endTime))
|
||||
} else {
|
||||
w.WriteHeader(404)
|
||||
}
|
||||
})
|
||||
http.HandleFunc("/gb28181/list", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
sse := util.NewSSE(w, r.Context())
|
||||
http.HandleFunc("/api/gb28181/list", func(w http.ResponseWriter, r *http.Request) {
|
||||
CORS(w, r)
|
||||
sse := NewSSE(w, r.Context())
|
||||
for {
|
||||
var list []*Device
|
||||
Devices.Range(func(key, value interface{}) bool {
|
||||
@@ -105,75 +154,116 @@ func run() {
|
||||
}
|
||||
}
|
||||
})
|
||||
http.HandleFunc("/gb28181/control", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
http.HandleFunc("/api/gb28181/control", func(w http.ResponseWriter, r *http.Request) {
|
||||
CORS(w, r)
|
||||
id := r.URL.Query().Get("id")
|
||||
channel, err := strconv.Atoi(r.URL.Query().Get("channel"))
|
||||
if err != nil {
|
||||
w.WriteHeader(404)
|
||||
}
|
||||
channel := r.URL.Query().Get("channel")
|
||||
ptzcmd := r.URL.Query().Get("ptzcmd")
|
||||
if v, ok := Devices.Load(id); ok {
|
||||
w.WriteHeader(v.(*Device).Control(channel, ptzcmd))
|
||||
if c := FindChannel(id, channel); c != nil {
|
||||
w.WriteHeader(c.Control(ptzcmd))
|
||||
} else {
|
||||
w.WriteHeader(404)
|
||||
}
|
||||
})
|
||||
http.HandleFunc("/gb28181/invite", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
http.HandleFunc("/api/gb28181/invite", func(w http.ResponseWriter, r *http.Request) {
|
||||
CORS(w, r)
|
||||
query := r.URL.Query()
|
||||
id := query.Get("id")
|
||||
channel, err := strconv.Atoi(query.Get("channel"))
|
||||
channel := r.URL.Query().Get("channel")
|
||||
startTime := query.Get("startTime")
|
||||
endTime := query.Get("endTime")
|
||||
f := query.Get("f")
|
||||
if startTime == "" {
|
||||
startTime = "0"
|
||||
}
|
||||
if endTime == "" {
|
||||
endTime = "0"
|
||||
}
|
||||
if err != nil {
|
||||
w.WriteHeader(404)
|
||||
}
|
||||
if v, ok := Devices.Load(id); ok {
|
||||
w.WriteHeader(v.(*Device).Invite(channel, startTime, endTime, f))
|
||||
if c := FindChannel(id, channel); c != nil {
|
||||
if startTime == "" && c.LivePublisher != nil {
|
||||
w.WriteHeader(304) //直播流已存在
|
||||
} else {
|
||||
w.WriteHeader(c.Invite(startTime, endTime))
|
||||
}
|
||||
} else {
|
||||
w.WriteHeader(404)
|
||||
}
|
||||
})
|
||||
http.HandleFunc("/gb28181/bye", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
http.HandleFunc("/api/gb28181/bye", func(w http.ResponseWriter, r *http.Request) {
|
||||
CORS(w, r)
|
||||
id := r.URL.Query().Get("id")
|
||||
channel, err := strconv.Atoi(r.URL.Query().Get("channel"))
|
||||
if err != nil {
|
||||
w.WriteHeader(404)
|
||||
}
|
||||
if v, ok := Devices.Load(id); ok {
|
||||
w.WriteHeader(v.(*Device).Bye(channel))
|
||||
channel := r.URL.Query().Get("channel")
|
||||
live := r.URL.Query().Get("live")
|
||||
if c := FindChannel(id, channel); c != nil {
|
||||
w.WriteHeader(c.Bye(live != "false"))
|
||||
} else {
|
||||
w.WriteHeader(404)
|
||||
}
|
||||
})
|
||||
s := transaction.NewCore(config)
|
||||
s.OnRegister = func(msg *sip.Message) {
|
||||
Devices.Store(msg.From.Uri.UserInfo(), &Device{
|
||||
ID: msg.From.Uri.UserInfo(),
|
||||
RegisterTime: time.Now(),
|
||||
UpdateTime: time.Now(),
|
||||
Status: string(sip.REGISTER),
|
||||
Core: s,
|
||||
from: &sip.Contact{Uri: msg.StartLine.Uri, Params: make(map[string]string)},
|
||||
to: msg.To,
|
||||
Addr: msg.Via.GetSendBy(),
|
||||
SipIP: config.MediaIP,
|
||||
})
|
||||
id := msg.From.Uri.UserInfo()
|
||||
storeDevice := func() {
|
||||
var d *Device
|
||||
|
||||
if _d, loaded := Devices.LoadOrStore(id, &Device{
|
||||
ID: id,
|
||||
RegisterTime: time.Now(),
|
||||
UpdateTime: time.Now(),
|
||||
Status: string(sip.REGISTER),
|
||||
Core: s,
|
||||
from: &sip.Contact{Uri: msg.StartLine.Uri, Params: make(map[string]string)},
|
||||
to: msg.To,
|
||||
Addr: msg.Via.GetSendBy(),
|
||||
SipIP: config.MediaIP,
|
||||
channelMap: make(map[string]*Channel),
|
||||
}); loaded {
|
||||
d = _d.(*Device)
|
||||
d.UpdateTime = time.Now()
|
||||
d.from = &sip.Contact{Uri: msg.StartLine.Uri, Params: make(map[string]string)}
|
||||
d.to = msg.To
|
||||
d.Addr = msg.Via.GetSendBy()
|
||||
}
|
||||
}
|
||||
// 不需要密码情况
|
||||
if config.Username == "" && config.Password == "" {
|
||||
storeDevice()
|
||||
return
|
||||
}
|
||||
sendUnauthorized := func() {
|
||||
response := msg.BuildResponseWithPhrase(401, "Unauthorized")
|
||||
if DeviceNonce[id] == "" {
|
||||
nonce := utils.RandNumString(32)
|
||||
DeviceNonce[id] = nonce
|
||||
}
|
||||
response.WwwAuthenticate = sip.NewWwwAuthenticate(s.Realm, DeviceNonce[id], sip.DIGEST_ALGO_MD5)
|
||||
s.Send(response)
|
||||
}
|
||||
// 需要密码情况 设备第一次上报,返回401和加密算法
|
||||
if msg.Authorization == nil || msg.Authorization.GetUsername() == "" {
|
||||
sendUnauthorized()
|
||||
return
|
||||
}
|
||||
// 有些摄像头没有配置用户名的地方,用户名就是摄像头自己的国标id
|
||||
username := config.Username
|
||||
if msg.Authorization.GetUsername() == id {
|
||||
username = id
|
||||
}
|
||||
|
||||
if DeviceRegisterCount[id] >= MaxRegisterCount {
|
||||
s.Send(msg.BuildResponse(403))
|
||||
return
|
||||
}
|
||||
|
||||
// 设备第二次上报,校验
|
||||
if !msg.Authorization.Verify(username, config.Password, config.Realm, DeviceNonce[id]) {
|
||||
sendUnauthorized()
|
||||
DeviceRegisterCount[id] += 1
|
||||
return
|
||||
}
|
||||
storeDevice()
|
||||
delete(DeviceNonce, id)
|
||||
delete(DeviceRegisterCount, id)
|
||||
}
|
||||
s.OnMessage = func(msg *sip.Message) bool {
|
||||
if v, ok := Devices.Load(msg.From.Uri.UserInfo()); ok {
|
||||
d := v.(*Device)
|
||||
if d.Status == string(sip.REGISTER) {
|
||||
d.Status = "ONLINE"
|
||||
go d.Query()
|
||||
}
|
||||
d.UpdateTime = time.Now()
|
||||
temp := &struct {
|
||||
@@ -185,10 +275,24 @@ func run() {
|
||||
}{}
|
||||
decoder := xml.NewDecoder(bytes.NewReader([]byte(msg.Body)))
|
||||
decoder.CharsetReader = charset.NewReaderLabel
|
||||
decoder.Decode(temp)
|
||||
err := decoder.Decode(temp)
|
||||
if err != nil {
|
||||
err = utils.DecodeGbk(temp, []byte(msg.Body))
|
||||
if err != nil {
|
||||
log.Printf("decode catelog err: %s", err)
|
||||
}
|
||||
}
|
||||
switch temp.XMLName.Local {
|
||||
case "Notify":
|
||||
go d.Query()
|
||||
switch temp.CmdType {
|
||||
case "Keeyalive":
|
||||
if d.subscriber.CallID != "" && time.Now().After(d.subscriber.Timeout) {
|
||||
go d.Subscribe()
|
||||
}
|
||||
d.CheckSubStream()
|
||||
case "Catalog":
|
||||
d.UpdateChannels(temp.DeviceList)
|
||||
}
|
||||
case "Response":
|
||||
switch temp.CmdType {
|
||||
case "Catalog":
|
||||
@@ -211,85 +315,88 @@ func run() {
|
||||
// }
|
||||
// })
|
||||
//})
|
||||
if useTCP {
|
||||
listenMediaTCP()
|
||||
} else {
|
||||
go listenMediaUDP()
|
||||
}
|
||||
// go queryCatalog(config)
|
||||
if config.Username != "" || config.Password != "" {
|
||||
go removeBanDevice(config)
|
||||
}
|
||||
s.Start()
|
||||
}
|
||||
|
||||
func (d *Device) publish(name string) (port int, publisher *rtp.RTP_PS) {
|
||||
publisher = new(rtp.RTP_PS)
|
||||
if !publisher.Publish(name) {
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
if port == 0 {
|
||||
publisher.Close()
|
||||
}
|
||||
}()
|
||||
publisher.Type = "GB28181"
|
||||
publisher.AutoUnPublish = true
|
||||
var conn *net.UDPConn
|
||||
var err error
|
||||
rang := int(config.MediaPortMax - config.MediaPortMin)
|
||||
for count := rang; count > 0; count-- {
|
||||
randNum := rand.Intn(rang)
|
||||
port = int(config.MediaPortMin) + randNum
|
||||
addr, _ := net.ResolveUDPAddr("udp", ":"+strconv.Itoa(port))
|
||||
conn, err = net.ListenUDP("udp", addr)
|
||||
if err != nil {
|
||||
continue
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
networkBuffer := 1048576
|
||||
if err = conn.SetReadBuffer(networkBuffer); err != nil {
|
||||
Printf("udp server video conn set read buffer error, %v", err)
|
||||
}
|
||||
if err = conn.SetWriteBuffer(networkBuffer); err != nil {
|
||||
Printf("udp server video conn set write buffer error, %v", err)
|
||||
}
|
||||
la := conn.LocalAddr().String()
|
||||
strPort := la[strings.LastIndex(la, ":")+1:]
|
||||
if port, err = strconv.Atoi(strPort); err != nil {
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
bufUDP := make([]byte, 1048576)
|
||||
Printf("udp server start listen video port[%d]", port)
|
||||
defer Printf("udp server stop listen video port[%d]", port)
|
||||
for publisher.Err() == nil {
|
||||
if err = conn.SetReadDeadline(time.Now().Add(time.Second * 30)); err != nil {
|
||||
return
|
||||
}
|
||||
if n, _, err := conn.ReadFromUDP(bufUDP); err == nil {
|
||||
publisher.PushPS(bufUDP[:n])
|
||||
} else {
|
||||
Println("udp server read video pack error", err)
|
||||
publisher.Close()
|
||||
if !publisher.AutoUnPublish {
|
||||
for _, channel := range d.Channels {
|
||||
if channel.LiveSP == name {
|
||||
channel.LiveSP = ""
|
||||
channel.Connected = false
|
||||
channel.Bye(channel.inviteRes)
|
||||
break
|
||||
}
|
||||
}
|
||||
func listenMediaTCP() {
|
||||
for i := uint16(0); i < config.TCPMediaPortNum; i++ {
|
||||
addr := ":" + strconv.Itoa(int(config.MediaPort+i))
|
||||
go ListenTCP(addr, func(conn net.Conn) {
|
||||
var rtpPacket rtp.Packet
|
||||
reader := bufio.NewReader(conn)
|
||||
lenBuf := make([]byte, 2)
|
||||
defer conn.Close()
|
||||
var err error
|
||||
for err == nil {
|
||||
if _, err = io.ReadFull(reader, lenBuf); err != nil {
|
||||
return
|
||||
}
|
||||
ps := make([]byte, BigEndian.Uint16(lenBuf))
|
||||
if _, err = io.ReadFull(reader, ps); err != nil {
|
||||
return
|
||||
}
|
||||
if err := rtpPacket.Unmarshal(ps); err != nil {
|
||||
Println("gb28181 decode rtp error:", err)
|
||||
} else if publisher := publishers.Get(rtpPacket.SSRC); publisher != nil && publisher.Err() == nil {
|
||||
publisher.PushPS(&rtpPacket)
|
||||
}
|
||||
}
|
||||
}
|
||||
conn.Close()
|
||||
if publisher.AutoUnPublish {
|
||||
for _, channel := range d.Channels {
|
||||
if channel.RecordSP == name {
|
||||
channel.RecordSP = ""
|
||||
channel.Bye(channel.recordInviteRes)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
return
|
||||
})
|
||||
}
|
||||
}
|
||||
func listenMediaUDP() {
|
||||
var rtpPacket rtp.Packet
|
||||
networkBuffer := 1048576
|
||||
addr := ":" + strconv.Itoa(int(config.MediaPort))
|
||||
conn, err := ListenUDP(addr, networkBuffer)
|
||||
if err != nil {
|
||||
Printf("listen udp %s err: %v", addr, err)
|
||||
return
|
||||
}
|
||||
bufUDP := make([]byte, networkBuffer)
|
||||
Printf("udp server start listen video port[%d]", config.MediaPort)
|
||||
defer Printf("udp server stop listen video port[%d]", config.MediaPort)
|
||||
for n, _, err := conn.ReadFromUDP(bufUDP); err == nil; n, _, err = conn.ReadFromUDP(bufUDP) {
|
||||
ps := bufUDP[:n]
|
||||
if err := rtpPacket.Unmarshal(ps); err != nil {
|
||||
Println("gb28181 decode rtp error:", err)
|
||||
}
|
||||
if publisher := publishers.Get(rtpPacket.SSRC); publisher != nil && publisher.Err() == nil {
|
||||
publisher.PushPS(&rtpPacket)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// func queryCatalog(config *transaction.Config) {
|
||||
// t := time.NewTicker(time.Duration(config.CatalogInterval) * time.Second)
|
||||
// for range t.C {
|
||||
// Devices.Range(func(key, value interface{}) bool {
|
||||
// device := value.(*Device)
|
||||
// if time.Since(device.UpdateTime) > time.Duration(config.RegisterValidity)*time.Second {
|
||||
// Devices.Delete(key)
|
||||
// } else if device.Channels != nil {
|
||||
// go device.Subscribe()
|
||||
// }
|
||||
// return true
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
|
||||
func removeBanDevice(config *transaction.Config) {
|
||||
t := time.NewTicker(time.Duration(config.RemoveBanInterval) * time.Second)
|
||||
for range t.C {
|
||||
for id, cnt := range DeviceRegisterCount {
|
||||
if cnt >= MaxRegisterCount {
|
||||
delete(DeviceRegisterCount, id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
103
publisher.go
Normal file
103
publisher.go
Normal file
@@ -0,0 +1,103 @@
|
||||
package gb28181
|
||||
|
||||
import (
|
||||
"github.com/Monibuca/engine/v3"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/utils"
|
||||
. "github.com/Monibuca/utils/v3"
|
||||
"github.com/pion/rtp"
|
||||
)
|
||||
|
||||
type Publisher struct {
|
||||
*engine.Stream
|
||||
parser utils.DecPSPackage
|
||||
pushVideo func(uint32, uint32, []byte)
|
||||
pushAudio func(uint32, []byte)
|
||||
lastSeq uint16
|
||||
udpCache *utils.PriorityQueueRtp
|
||||
}
|
||||
|
||||
func (p *Publisher) PushVideo(ts uint32, cts uint32, payload []byte) {
|
||||
p.pushVideo(ts, cts, payload)
|
||||
}
|
||||
func (p *Publisher) PushAudio(ts uint32, payload []byte) {
|
||||
p.pushAudio(ts, payload)
|
||||
}
|
||||
func (p *Publisher) Publish() (result bool) {
|
||||
if result = p.Stream.Publish(); result {
|
||||
p.pushVideo = func(ts uint32, cts uint32, payload []byte) {
|
||||
var vt *engine.VideoTrack
|
||||
switch p.parser.VideoStreamType {
|
||||
case utils.StreamTypeH264:
|
||||
vt = p.Stream.NewVideoTrack(7)
|
||||
case utils.StreamTypeH265:
|
||||
vt = p.Stream.NewVideoTrack(12)
|
||||
default:
|
||||
return
|
||||
}
|
||||
vt.PushAnnexB(ts, cts, payload)
|
||||
p.pushVideo = vt.PushAnnexB
|
||||
}
|
||||
p.pushAudio = func(ts uint32, payload []byte) {
|
||||
switch p.parser.AudioStreamType {
|
||||
case utils.G711A:
|
||||
at := p.Stream.NewAudioTrack(7)
|
||||
at.SoundRate = 8000
|
||||
at.SoundSize = 16
|
||||
at.Channels = 1
|
||||
at.ExtraData = []byte{(at.CodecID << 4) | (1 << 1)}
|
||||
at.PushRaw(ts, payload)
|
||||
p.pushAudio = at.PushRaw
|
||||
// case utils.G711U:
|
||||
// at := p.Stream.NewAudioTrack(8)
|
||||
// at.SoundRate = 8000
|
||||
// at.SoundSize = 16
|
||||
// asc := at.CodecID << 4
|
||||
// asc = asc + 1<<1
|
||||
// at.ExtraData = []byte{asc}
|
||||
// at.PushRaw(pack)
|
||||
// p.pushAudio = at.PushRaw
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
func (p *Publisher) PushPS(rtp *rtp.Packet) {
|
||||
originRtp := *rtp
|
||||
if config.UdpCacheSize > 0 && config.TCP == false {
|
||||
//序号小于第一个包的丢弃,rtp包序号达到65535后会从0开始,所以这里需要判断一下
|
||||
if rtp.SequenceNumber < p.lastSeq && p.lastSeq-rtp.SequenceNumber < utils.MaxRtpDiff {
|
||||
return
|
||||
}
|
||||
p.udpCache.Push(*rtp)
|
||||
rtpTmp, _ := p.udpCache.Pop()
|
||||
rtp = &rtpTmp
|
||||
}
|
||||
ps := rtp.Payload
|
||||
if p.lastSeq != 0 {
|
||||
// rtp序号不连续,丢弃PS
|
||||
if p.lastSeq+1 != rtp.SequenceNumber {
|
||||
if config.UdpCacheSize > 0 && config.TCP == false {
|
||||
if p.udpCache.Len() < config.UdpCacheSize {
|
||||
p.udpCache.Push(*rtp)
|
||||
return
|
||||
} else {
|
||||
p.udpCache.Empty()
|
||||
rtp = &originRtp // 还原rtp包,而不是使用缓存中,避免rtp序号断裂
|
||||
}
|
||||
}
|
||||
p.parser.Reset()
|
||||
}
|
||||
}
|
||||
p.lastSeq = rtp.SequenceNumber
|
||||
p.Update()
|
||||
if len(ps) >= 4 && BigEndian.Uint32(ps) == utils.StartCodePS {
|
||||
if p.parser.Len() > 0 {
|
||||
p.parser.Uint32()
|
||||
p.parser.Read(rtp.Timestamp, p)
|
||||
p.parser.Reset()
|
||||
}
|
||||
p.parser.Write(ps)
|
||||
} else if p.parser.Len() > 0 {
|
||||
p.parser.Write(ps)
|
||||
}
|
||||
}
|
||||
114
rtpsort_test.go
Executable file
114
rtpsort_test.go
Executable file
@@ -0,0 +1,114 @@
|
||||
package gb28181
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Monibuca/engine/v3"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/utils"
|
||||
"github.com/agiledragon/gomonkey/v2"
|
||||
"github.com/pion/rtp"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// 测试rtp序号数据
|
||||
var items = []uint16{
|
||||
65526, 65530, 65524, 65525, 65527, 65528, 65529,
|
||||
0, 65533, 65531, 65532, 65534, 65535, 1,
|
||||
3, 6, 5, 4, 2, 8, 7,
|
||||
}
|
||||
|
||||
var items2 = []uint16{
|
||||
11672, 11673, 11674, 11675, 11676, 11677, 11678,
|
||||
11679, 11680, 11681, 11682, 11683, 11684, 11685,
|
||||
11686, 11687, 11688, 11689, 11690, 11691, 11692,
|
||||
11693, 11694, 11695, 11696, 11697, 11698, 11699,
|
||||
11700, 11701, 11702, 11703, 11704, 11705, 11706,
|
||||
11707, 11708, 11709, 11710, 11711, 11712,
|
||||
}
|
||||
|
||||
func _pushPsWithCache(p *Publisher, rtp *rtp.Packet) {
|
||||
originRtp := *rtp
|
||||
if config.UdpCacheSize > 0 && !config.TCP {
|
||||
//序号小于第一个包的丢弃,rtp包序号达到65535后会从0开始,所以这里需要判断一下
|
||||
if rtp.SequenceNumber < p.lastSeq && p.lastSeq-rtp.SequenceNumber < utils.MaxRtpDiff {
|
||||
return
|
||||
}
|
||||
p.udpCache.Push(*rtp)
|
||||
rtpTmp, _ := p.udpCache.Pop()
|
||||
rtp = &rtpTmp
|
||||
}
|
||||
|
||||
if p.lastSeq != 0 {
|
||||
// rtp序号不连续,丢弃PS
|
||||
if p.lastSeq+1 != rtp.SequenceNumber {
|
||||
if config.UdpCacheSize > 0 && !config.TCP {
|
||||
if p.udpCache.Len() < config.UdpCacheSize {
|
||||
p.udpCache.Push(*rtp)
|
||||
return
|
||||
} else {
|
||||
p.udpCache.Empty()
|
||||
rtp = &originRtp
|
||||
}
|
||||
}
|
||||
p.parser.Reset()
|
||||
}
|
||||
}
|
||||
|
||||
p.lastSeq = rtp.SequenceNumber
|
||||
fmt.Println("rtp.SequenceNumber:", rtp.SequenceNumber)
|
||||
|
||||
}
|
||||
|
||||
// 如果运行失败可以关闭gc,go test -gcflags=all=-l -v
|
||||
func TestRtpSort(t *testing.T) {
|
||||
publisher := Publisher{
|
||||
Stream: &engine.Stream{
|
||||
StreamPath: "live/test",
|
||||
},
|
||||
udpCache: utils.NewPqRtp(),
|
||||
}
|
||||
config.UdpCacheSize = 7
|
||||
|
||||
patches := gomonkey.ApplyMethod(reflect.TypeOf(&publisher), "PushPS", _pushPsWithCache)
|
||||
defer patches.Reset()
|
||||
|
||||
for i := 0; i < len(items); i++ {
|
||||
rtpPacket := &rtp.Packet{Header: rtp.Header{SequenceNumber: items[i]}}
|
||||
publisher.PushPS(rtpPacket)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 如果运行失败可以关闭gc,go test -gcflags=all=-l -v
|
||||
// 测试有empty的情况
|
||||
func TestRtpSortWithEmpty(t *testing.T) {
|
||||
publisher := Publisher{
|
||||
Stream: &engine.Stream{
|
||||
StreamPath: "live/test",
|
||||
},
|
||||
udpCache: utils.NewPqRtp(),
|
||||
}
|
||||
config.UdpCacheSize = 7
|
||||
publisher.udpCache.Push(rtp.Packet{Header: rtp.Header{SequenceNumber: 11665}})
|
||||
patches := gomonkey.ApplyMethod(reflect.TypeOf(&publisher), "PushPS", _pushPsWithCache)
|
||||
defer patches.Reset()
|
||||
|
||||
for i := 0; i < len(items2); i++ {
|
||||
rtpPacket := &rtp.Packet{Header: rtp.Header{SequenceNumber: items2[i]}}
|
||||
publisher.PushPS(rtpPacket)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestPqSort(t *testing.T) {
|
||||
pq := utils.NewPqRtp()
|
||||
for i := 0; i < len(items); i++ {
|
||||
rtpPacket := rtp.Packet{Header: rtp.Header{SequenceNumber: items[i]}}
|
||||
pq.Push(rtpPacket)
|
||||
}
|
||||
|
||||
for pq.Len() > 0 {
|
||||
rtpPacket, _ := pq.Pop()
|
||||
fmt.Println("packet seq:", rtpPacket.SequenceNumber)
|
||||
}
|
||||
}
|
||||
143
sip/head.go
143
sip/head.go
@@ -1,6 +1,7 @@
|
||||
package sip
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
@@ -12,10 +13,10 @@ import (
|
||||
//windows : \n
|
||||
//Mac OS : \r
|
||||
const (
|
||||
VERSION = "SIP/2.0" // sip version
|
||||
CRLF = "\r\n" // 0x0D0A
|
||||
CRLFCRLF = "\r\n\r\n" // 0x0D0A0D0A
|
||||
|
||||
VERSION = "SIP/2.0" // sip version
|
||||
CRLF = "\r\n" // 0x0D0A
|
||||
CRLFCRLF = "\r\n\r\n" // 0x0D0A0D0A
|
||||
DIGEST_ALGO_MD5 = "MD5"
|
||||
//CRLF = "\n" // 0x0D
|
||||
//CRLFCRLF = "\n\n" // 0x0D0D
|
||||
)
|
||||
@@ -377,6 +378,9 @@ func (c *CSeq) Parse(str string) error {
|
||||
return err
|
||||
}
|
||||
c.ID = uint32(n)
|
||||
if len(arr1) < 2 {
|
||||
return errors.New("no method: " + str)
|
||||
}
|
||||
c.Method = Method(arr1[1])
|
||||
return nil
|
||||
}
|
||||
@@ -562,10 +566,139 @@ func parseURI(str string) (ret URI, err error) {
|
||||
arr2 := strings.Split(paramStr, "&")
|
||||
for _, one := range arr2 {
|
||||
tmp := strings.Split(one, "=")
|
||||
k, v := tmp[0], tmp[1]
|
||||
var k, v string
|
||||
if len(tmp) == 2 {
|
||||
k, v = tmp[0], tmp[1]
|
||||
} else {
|
||||
k = tmp[0]
|
||||
}
|
||||
ret.headers[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
type WwwAuthenticate struct {
|
||||
realm string
|
||||
nonce string
|
||||
algorithm string
|
||||
//opaque string // gb28181不需要这字段,海康有
|
||||
}
|
||||
|
||||
func NewWwwAuthenticate(realm, nonce, algorithm string) *WwwAuthenticate {
|
||||
return &WwwAuthenticate{
|
||||
realm: realm,
|
||||
nonce: nonce,
|
||||
algorithm: algorithm,
|
||||
}
|
||||
}
|
||||
|
||||
// WWW-Authenticate: Digest realm="hik", nonce="a8afe6fcbee6331d89d3eb0d3d19ce39", opaque="a853e4f25298413f9bf3a9aa6767857d", algorithm=MD5
|
||||
func (w *WwwAuthenticate) String() string {
|
||||
return fmt.Sprintf(`Digest realm="%s", nonce="%s", algorithm=%s`, w.realm, w.nonce, w.algorithm)
|
||||
}
|
||||
|
||||
func (w *WwwAuthenticate) Parse(str string) error {
|
||||
arr := strings.Split(str, ",")
|
||||
for _, s := range arr {
|
||||
tmp := strings.Split(s, "=")
|
||||
if len(tmp) != 2 {
|
||||
continue
|
||||
}
|
||||
v := strings.ReplaceAll(tmp[1], "\"", "")
|
||||
if strings.Contains(tmp[0], "realm") {
|
||||
w.realm = v
|
||||
}
|
||||
if strings.Contains(tmp[0], "nonce") {
|
||||
w.nonce = v
|
||||
}
|
||||
if strings.Contains(tmp[0], "algorithm") {
|
||||
w.algorithm = v
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Authorization struct {
|
||||
username string
|
||||
realm string
|
||||
nonce string
|
||||
uri string
|
||||
response string
|
||||
algorithm string
|
||||
//opaque string // gb28181不需要这字段,海康有
|
||||
}
|
||||
|
||||
// Authorization: Digest username="admin", realm="hik", nonce="a8afe6fcbee6331d89d3eb0d3d19ce39", uri="sip:130909115229300920@10.64.49.44:7100", response="907ddb1bcc25174d7de4a96c947fb066", algorithm=MD5, opaque="a853e4f25298413f"
|
||||
func (a *Authorization) String() string {
|
||||
return fmt.Sprintf(`Digest username="%s", realm="%s", nonce="%s", uri="%s", response="%s", algorithm=%s`,
|
||||
a.username, a.realm, a.nonce, a.uri, a.response, a.algorithm)
|
||||
}
|
||||
|
||||
func (a *Authorization) GetUsername() string {
|
||||
return a.username
|
||||
}
|
||||
|
||||
func (a *Authorization) Parse(str string) error {
|
||||
arr := strings.Split(str, ",")
|
||||
for _, s := range arr {
|
||||
tmp := strings.Split(s, "=")
|
||||
if len(tmp) != 2 {
|
||||
continue
|
||||
}
|
||||
v := strings.ReplaceAll(tmp[1], "\"", "")
|
||||
if strings.Contains(tmp[0], "username") {
|
||||
a.username = v
|
||||
}
|
||||
if strings.Contains(tmp[0], "realm") {
|
||||
a.realm = v
|
||||
}
|
||||
if strings.Contains(tmp[0], "nonce") {
|
||||
a.nonce = v
|
||||
}
|
||||
if strings.Contains(tmp[0], "uri") {
|
||||
a.uri = v
|
||||
}
|
||||
if strings.Contains(tmp[0], "response") {
|
||||
a.response = v
|
||||
}
|
||||
if strings.Contains(tmp[0], "algorithm") {
|
||||
a.algorithm = strings.Trim(v,"H:")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *Authorization) Verify(username, passwd, realm, nonce string) bool {
|
||||
|
||||
//1、将 username,realm,password 依次组合获取 1 个字符串,并用算法加密的到密文 r1
|
||||
s1 := fmt.Sprintf("%s:%s:%s", username, realm, passwd)
|
||||
r1 := a.getDigest(s1)
|
||||
//2、将 method,即REGISTER ,uri 依次组合获取 1 个字符串,并对这个字符串使用算法 加密得到密文 r2
|
||||
s2 := fmt.Sprintf("REGISTER:%s", a.uri)
|
||||
r2 := a.getDigest(s2)
|
||||
|
||||
if r1 == "" || r2 == "" {
|
||||
fmt.Println("Authorization algorithm wrong")
|
||||
return false
|
||||
}
|
||||
//3、将密文 1,nonce 和密文 2 依次组合获取 1 个字符串,并对这个字符串使用算法加密,获得密文 r3,即Response
|
||||
s3 := fmt.Sprintf("%s:%s:%s", r1, nonce, r2)
|
||||
r3 := a.getDigest(s3)
|
||||
|
||||
//4、计算服务端和客户端上报的是否相等
|
||||
if r3 == a.response {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (a *Authorization) getDigest(raw string) string {
|
||||
switch a.algorithm {
|
||||
case DIGEST_ALGO_MD5:
|
||||
return fmt.Sprintf("%x", md5.Sum([]byte(raw)))
|
||||
default: //如果没有算法,默认使用MD5
|
||||
return fmt.Sprintf("%x", md5.Sum([]byte(raw)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,3 +112,60 @@ y=0009093131`
|
||||
fmt.Println("output:")
|
||||
fmt.Println(string(out))
|
||||
}
|
||||
|
||||
func TestAuthorization_Verify(t *testing.T) {
|
||||
type fields struct {
|
||||
username string
|
||||
realm string
|
||||
nonce string
|
||||
uri string
|
||||
response string
|
||||
algorithm string
|
||||
}
|
||||
type args struct {
|
||||
username string
|
||||
passwd string
|
||||
realm string
|
||||
nonce string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "test1",
|
||||
fields: fields{
|
||||
username: "34020000001320000001",
|
||||
realm: "3402000000",
|
||||
nonce: "1628819207",
|
||||
uri: "sip:34020000002000000001@172.165.0.10:15060",
|
||||
response: "fa2b30e05ea42dd0ab69ef05d3a06096",
|
||||
algorithm: "MD5",
|
||||
},
|
||||
args: args{
|
||||
username: "34020000001320000001",
|
||||
passwd: "12345678",
|
||||
realm: "3402000000",
|
||||
nonce: "1628819207",
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
a := &Authorization{
|
||||
username: tt.fields.username,
|
||||
realm: tt.fields.realm,
|
||||
nonce: tt.fields.nonce,
|
||||
uri: tt.fields.uri,
|
||||
response: tt.fields.response,
|
||||
algorithm: tt.fields.algorithm,
|
||||
}
|
||||
if got := a.Verify(tt.args.username, tt.args.passwd, tt.args.realm, tt.args.nonce); got != tt.want {
|
||||
t.Errorf("Verify() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,9 @@ import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Monibuca/plugin-gb28181/utils"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/utils"
|
||||
)
|
||||
|
||||
//Content-Type: Application/MANSCDP+xml
|
||||
@@ -20,26 +21,35 @@ import (
|
||||
type Message struct {
|
||||
Mode Mode //0:REQUEST, 1:RESPONSE
|
||||
|
||||
StartLine *StartLine
|
||||
Via *Via //Via
|
||||
From *Contact //From
|
||||
To *Contact //To
|
||||
CallID string //Call-ID
|
||||
CSeq *CSeq //CSeq
|
||||
Contact *Contact //Contact
|
||||
Authorization string //Authorization
|
||||
MaxForwards int //Max-Forwards
|
||||
UserAgent string //User-Agent
|
||||
Subject string //Subject
|
||||
ContentType string //Content-Type
|
||||
Expires int //Expires
|
||||
ContentLength int //Content-Length
|
||||
Route *Contact
|
||||
Body string
|
||||
Addr string
|
||||
StartLine *StartLine
|
||||
Via *Via //Via
|
||||
From *Contact //From
|
||||
To *Contact //To
|
||||
CallID string //Call-ID
|
||||
CSeq *CSeq //CSeq
|
||||
Contact *Contact //Contact
|
||||
Authorization *Authorization //Authorization
|
||||
MaxForwards int //Max-Forwards
|
||||
UserAgent string //User-Agent
|
||||
Subject string //Subject
|
||||
ContentType string //Content-Type
|
||||
Expires int //Expires
|
||||
ContentLength int //Content-Length
|
||||
Route *Contact
|
||||
Body string
|
||||
Addr string
|
||||
Event string
|
||||
Date time.Time
|
||||
WwwAuthenticate *WwwAuthenticate //gb28181 密码验证 上级发给下级是WwwAuthenticate;下级发给上级是Authorization
|
||||
}
|
||||
|
||||
func (m *Message) BuildResponse(code int) *Message {
|
||||
return m.BuildResponseWithPhrase(code, "")
|
||||
}
|
||||
func (m *Message) BuildOK() *Message {
|
||||
return m.BuildResponseWithPhrase(200, "OK")
|
||||
}
|
||||
func (m *Message) BuildResponseWithPhrase(code int, phrase string) *Message {
|
||||
response := Message{
|
||||
Mode: SIP_MESSAGE_RESPONSE,
|
||||
From: m.From,
|
||||
@@ -48,9 +58,12 @@ func (m *Message) BuildResponse(code int) *Message {
|
||||
CSeq: m.CSeq,
|
||||
Via: m.Via,
|
||||
MaxForwards: m.MaxForwards,
|
||||
UserAgent: "Monibuca",
|
||||
StartLine: &StartLine{
|
||||
Code: code,
|
||||
Code: code,
|
||||
phrase: phrase,
|
||||
},
|
||||
Date: time.Now(),
|
||||
}
|
||||
return &response
|
||||
}
|
||||
@@ -156,7 +169,7 @@ func (m *Message) GetBranch() string {
|
||||
|
||||
b, ok := m.Via.Params["branch"]
|
||||
if !ok {
|
||||
panic("invalid via paramas branch")
|
||||
return ""
|
||||
}
|
||||
|
||||
return b
|
||||
@@ -356,13 +369,19 @@ func Decode(data []byte) (msg *Message, err error) {
|
||||
msg.ContentLength = int(n)
|
||||
|
||||
case "authorization":
|
||||
msg.Authorization = v
|
||||
msg.Authorization = &Authorization{}
|
||||
msg.Authorization.Parse(v)
|
||||
|
||||
case "content-type":
|
||||
msg.ContentType = v
|
||||
case "route":
|
||||
//msg.Route = new(Contact)
|
||||
//msg.Route.Parse(v)
|
||||
case "www-authenticate":
|
||||
msg.WwwAuthenticate = &WwwAuthenticate{}
|
||||
msg.WwwAuthenticate.Parse(v)
|
||||
case "event":
|
||||
msg.Event = v
|
||||
default:
|
||||
fmt.Printf("invalid sip head: %s,%s\n", k, v)
|
||||
}
|
||||
@@ -434,6 +453,21 @@ func Encode(msg *Message) ([]byte, error) {
|
||||
sb.WriteString(CRLF)
|
||||
}
|
||||
|
||||
if msg.WwwAuthenticate != nil {
|
||||
sb.WriteString("WWW-Authenticate: ")
|
||||
sb.WriteString(msg.WwwAuthenticate.String())
|
||||
sb.WriteString(CRLF)
|
||||
}
|
||||
if !msg.Date.IsZero() {
|
||||
sb.WriteString("Date: ")
|
||||
sb.WriteString(msg.Date.Format("2006-01-02T15:04:05.999"))
|
||||
sb.WriteString(CRLF)
|
||||
}
|
||||
if msg.Event != "" {
|
||||
sb.WriteString("Event: ")
|
||||
sb.WriteString(msg.Event)
|
||||
sb.WriteString(CRLF)
|
||||
}
|
||||
if msg.IsRequest() {
|
||||
//request only
|
||||
|
||||
@@ -441,9 +475,9 @@ func Encode(msg *Message) ([]byte, error) {
|
||||
sb.WriteString(strconv.Itoa(msg.MaxForwards))
|
||||
sb.WriteString(CRLF)
|
||||
|
||||
if msg.Authorization != "" {
|
||||
if msg.Authorization != nil {
|
||||
sb.WriteString("Authorization: ")
|
||||
sb.WriteString(msg.Authorization)
|
||||
sb.WriteString(msg.Authorization.String())
|
||||
sb.WriteString(CRLF)
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -42,6 +42,8 @@ type Config struct {
|
||||
SipPort uint16 //sip 服务器端口,默认 5060
|
||||
Serial string //sip 服务器 id, 默认 34020000002000000001
|
||||
Realm string //sip 服务器域,默认 3402000000
|
||||
Username string //sip 服务器账号
|
||||
Password string //sip 服务器密码
|
||||
|
||||
AckTimeout uint16 //sip 服务应答超时,单位秒
|
||||
RegisterValidity int //注册有效期,单位秒,默认 3600
|
||||
@@ -50,11 +52,13 @@ type Config struct {
|
||||
HeartbeatRetry int //心跳超时次数,默认 3
|
||||
|
||||
//媒体服务器配置
|
||||
MediaIP string //媒体服务器地址
|
||||
MediaPort uint16 //媒体服务器端口
|
||||
MediaPortMin uint16
|
||||
MediaPortMax uint16
|
||||
MediaIdleTimeout uint16 //推流超时时间,超过则断开链接,让设备重连
|
||||
AudioEnable bool //是否开启音频
|
||||
WaitKeyFrame bool //是否等待关键帧,如果等待,则在收到第一个关键帧之前,忽略所有媒体流
|
||||
MediaIP string //媒体服务器地址
|
||||
MediaPort uint16 //媒体服务器端口
|
||||
MediaPortMin uint16
|
||||
MediaPortMax uint16
|
||||
MediaIdleTimeout uint16 //推流超时时间,超过则断开链接,让设备重连
|
||||
AudioEnable bool //是否开启音频
|
||||
WaitKeyFrame bool //是否等待关键帧,如果等待,则在收到第一个关键帧之前,忽略所有媒体流
|
||||
RemoveBanInterval int //移除禁止设备间隔
|
||||
UdpCacheSize int //udp缓存大小
|
||||
}
|
||||
|
||||
@@ -4,13 +4,11 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/Monibuca/plugin-gb28181/sip"
|
||||
"github.com/Monibuca/plugin-gb28181/transport"
|
||||
"github.com/Monibuca/plugin-gb28181/utils"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/sip"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/transport"
|
||||
)
|
||||
|
||||
//Core: transactions manager
|
||||
@@ -20,7 +18,6 @@ type Core struct {
|
||||
handlers map[State]map[Event]Handler //每个状态都可以处理有限个事件。不必加锁。
|
||||
transactions map[string]*Transaction //管理所有 transactions,key:tid,value:transaction
|
||||
mutex sync.RWMutex //transactions的锁
|
||||
removeTa chan string //要删除transaction的时候,通过chan传递tid
|
||||
tp transport.ITransport //transport
|
||||
*Config //sip server配置信息
|
||||
OnRegister func(*sip.Message)
|
||||
@@ -37,7 +34,6 @@ func NewCore(config *Config) *Core {
|
||||
core := &Core{
|
||||
handlers: make(map[State]map[Event]Handler),
|
||||
transactions: make(map[string]*Transaction),
|
||||
removeTa: make(chan string, 10),
|
||||
Config: config,
|
||||
ctx: context.Background(),
|
||||
}
|
||||
@@ -59,7 +55,6 @@ func (c *Core) AddTransaction(ta *Transaction) {
|
||||
c.mutex.Lock()
|
||||
c.transactions[ta.id] = ta
|
||||
c.mutex.Unlock()
|
||||
go ta.Run()
|
||||
}
|
||||
|
||||
//delete transaction
|
||||
@@ -69,44 +64,22 @@ func (c *Core) DelTransaction(tid string) {
|
||||
c.mutex.Unlock()
|
||||
}
|
||||
|
||||
//创建事件:根据接收到的消息创建消息事件
|
||||
func (c *Core) NewInComingMessageEvent(m *sip.Message) *EventObj {
|
||||
return &EventObj{
|
||||
evt: getInComingMessageEvent(m),
|
||||
tid: getMessageTransactionID(m),
|
||||
msg: m,
|
||||
}
|
||||
}
|
||||
|
||||
//创建事件:根据发出的消息创建消息事件
|
||||
func (c *Core) NewOutGoingMessageEvent(m *sip.Message) *EventObj {
|
||||
return &EventObj{
|
||||
evt: getOutGoingMessageEvent(m),
|
||||
tid: getMessageTransactionID(m),
|
||||
msg: m,
|
||||
}
|
||||
}
|
||||
|
||||
//创建事物
|
||||
//填充此事物的参数:via、from、to、callID、cseq
|
||||
func (c *Core) initTransaction(ctx context.Context, obj *EventObj) *Transaction {
|
||||
m := obj.msg
|
||||
|
||||
func (c *Core) initTransaction(ctx context.Context, tid string, m *sip.Message) *Transaction {
|
||||
//ack要么属于一个invite事物,要么由TU层直接管理,不通过事物管理。
|
||||
if m.GetMethod() == sip.ACK {
|
||||
fmt.Println("ack nerver create transaction")
|
||||
return nil
|
||||
}
|
||||
ta := &Transaction{
|
||||
id: obj.tid,
|
||||
id: tid,
|
||||
core: c,
|
||||
ctx: ctx,
|
||||
done: make(chan struct{}),
|
||||
event: make(chan *EventObj, 10), //带缓冲的event channel
|
||||
response: make(chan *Response),
|
||||
startAt: time.Now(),
|
||||
endAt: time.Now().Add(1000000 * time.Hour),
|
||||
}
|
||||
ta.Context, ta.cancel = context.WithTimeout(ctx, time.Second*5)
|
||||
//填充其他transaction的信息
|
||||
ta.via = m.Via
|
||||
ta.from = m.From
|
||||
@@ -210,26 +183,14 @@ func (c *Core) Start() {
|
||||
}
|
||||
|
||||
func (c *Core) Handler() {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
fmt.Println("packet handler panic: ", err)
|
||||
utils.PrintStack()
|
||||
os.Exit(1)
|
||||
}
|
||||
}()
|
||||
ch := c.tp.ReadPacketChan()
|
||||
//阻塞读取消息
|
||||
for {
|
||||
//fmt.Println("PacketHandler ========== SIP Client")
|
||||
select {
|
||||
case tid := <-c.removeTa:
|
||||
c.DelTransaction(tid)
|
||||
case p := <-ch:
|
||||
err := c.HandleReceiveMessage(p)
|
||||
if err != nil {
|
||||
fmt.Println("handler sip response message failed:", err.Error())
|
||||
continue
|
||||
}
|
||||
for p := range c.tp.ReadPacketChan() {
|
||||
if len(p.Data) < 5 {
|
||||
continue
|
||||
}
|
||||
if err := c.HandleReceiveMessage(p); err != nil {
|
||||
fmt.Println("handler sip response message failed:", err.Error())
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -245,17 +206,16 @@ func (c *Core) Handler() {
|
||||
func (c *Core) SendMessage(msg *sip.Message) *Response {
|
||||
method := msg.GetMethod()
|
||||
// data, _ := sip.Encode(msg)
|
||||
fmt.Println("send message:", method)
|
||||
|
||||
e := c.NewOutGoingMessageEvent(msg)
|
||||
|
||||
// fmt.Println("send message:", method)
|
||||
evt := getOutGoingMessageEvent(msg)
|
||||
tid := getMessageTransactionID(msg)
|
||||
//匹配事物
|
||||
c.mutex.RLock()
|
||||
ta, ok := c.transactions[e.tid]
|
||||
ta, ok := c.transactions[tid]
|
||||
c.mutex.RUnlock()
|
||||
if !ok {
|
||||
//新的请求
|
||||
ta = c.initTransaction(c.ctx, e)
|
||||
ta = c.initTransaction(c.ctx, tid, msg)
|
||||
|
||||
//如果是sip 消息事件,则将消息缓存,填充typo和state
|
||||
if msg.IsRequest() {
|
||||
@@ -276,8 +236,8 @@ func (c *Core) SendMessage(msg *sip.Message) *Response {
|
||||
}
|
||||
|
||||
//把event推到transaction
|
||||
ta.event <- e
|
||||
<-ta.done
|
||||
ta.Run(evt, msg)
|
||||
<-ta.Done()
|
||||
if ta.lastResponse != nil {
|
||||
return &Response{
|
||||
Code: ta.lastResponse.GetStatusCode(),
|
||||
@@ -304,7 +264,7 @@ func (c *Core) HandleReceiveMessage(p *transport.Packet) (err error) {
|
||||
fmt.Println("parse sip message failed:", err.Error())
|
||||
return ErrorParse
|
||||
}
|
||||
if msg.Via == nil {
|
||||
if msg.Via == nil || msg.From == nil {
|
||||
return ErrorParse
|
||||
}
|
||||
//这里不处理超过MTU的包,不处理半包
|
||||
@@ -314,9 +274,8 @@ func (c *Core) HandleReceiveMessage(p *transport.Packet) (err error) {
|
||||
}
|
||||
|
||||
//fmt.Println("receive message:", msg.GetMethod())
|
||||
|
||||
e := c.NewInComingMessageEvent(msg)
|
||||
|
||||
evt := getInComingMessageEvent(msg)
|
||||
tid := getMessageTransactionID(msg)
|
||||
//一般应该是uas对于接收到的request做预处理
|
||||
if msg.IsRequest() {
|
||||
fixReceiveMessageViaParams(msg, p.Addr)
|
||||
@@ -326,7 +285,7 @@ func (c *Core) HandleReceiveMessage(p *transport.Packet) (err error) {
|
||||
//TODO:CANCEL、BYE 和 ACK 需要特殊处理,使用事物或者直接由TU层处理
|
||||
//查找transaction
|
||||
c.mutex.RLock()
|
||||
ta, ok := c.transactions[e.tid]
|
||||
ta, ok := c.transactions[tid]
|
||||
c.mutex.RUnlock()
|
||||
method := msg.GetMethod()
|
||||
if msg.IsRequest() {
|
||||
@@ -335,24 +294,28 @@ func (c *Core) HandleReceiveMessage(p *transport.Packet) (err error) {
|
||||
//TODO:this should be a ACK for 2xx (but could be a late ACK!)
|
||||
return
|
||||
case sip.BYE:
|
||||
c.Send(msg.BuildResponse(200))
|
||||
c.Send(msg.BuildOK())
|
||||
return
|
||||
case sip.MESSAGE:
|
||||
if c.OnMessage(msg) && ta == nil {
|
||||
c.Send(msg.BuildResponse(200))
|
||||
c.Send(msg.BuildOK())
|
||||
}
|
||||
if ta != nil {
|
||||
ta.event <- c.NewOutGoingMessageEvent(msg.BuildResponse(200))
|
||||
m := msg.BuildOK()
|
||||
ta.Run(getOutGoingMessageEvent(m), m)
|
||||
}
|
||||
case sip.REGISTER:
|
||||
if !ok {
|
||||
ta = c.initTransaction(c.ctx, e)
|
||||
ta = c.initTransaction(c.ctx, tid, msg)
|
||||
ta.typo = FSM_NIST
|
||||
ta.state = NIST_PROCEEDING
|
||||
c.AddTransaction(ta)
|
||||
}
|
||||
c.OnRegister(msg)
|
||||
ta.event <- c.NewOutGoingMessageEvent(msg.BuildResponse(200))
|
||||
m := msg.BuildOK()
|
||||
m.Contact = msg.Contact
|
||||
m.Expires = msg.Expires
|
||||
ta.Run(getOutGoingMessageEvent(m), m)
|
||||
//case sip.INVITE:
|
||||
// ta.typo = FSM_IST
|
||||
// ta.state = IST_PRE_PROCEEDING
|
||||
@@ -364,8 +327,7 @@ func (c *Core) HandleReceiveMessage(p *transport.Packet) (err error) {
|
||||
return
|
||||
}
|
||||
} else if ok {
|
||||
ta.event <- e
|
||||
|
||||
ta.Run(evt, msg)
|
||||
}
|
||||
//TODO:TU层处理:根据需要,创建,或者匹配 Dialog
|
||||
//通过tag匹配到call和dialog
|
||||
@@ -397,7 +359,7 @@ func (c *Core) Send(msg *sip.Message) error {
|
||||
addr = fmt.Sprintf("%s:%s", host, port)
|
||||
}
|
||||
|
||||
fmt.Println("dest addr:", addr)
|
||||
// fmt.Println("dest addr:", addr)
|
||||
var err1, err2 error
|
||||
pkt := &transport.Packet{}
|
||||
pkt.Data, err1 = sip.Encode(msg)
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package transaction
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/Monibuca/plugin-gb28181/sip"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/sip"
|
||||
)
|
||||
|
||||
/*
|
||||
@@ -49,40 +46,30 @@ resp. to TU | 1xx V |
|
||||
|
||||
Figure 5: INVITE client transaction
|
||||
*/
|
||||
func ict_snd_invite(t *Transaction, e *EventObj) error {
|
||||
msg := e.msg
|
||||
func ict_snd_invite(t *Transaction, evt Event, m *sip.Message) error {
|
||||
|
||||
t.isReliable = msg.IsReliable()
|
||||
t.origRequest = msg
|
||||
t.isReliable = m.IsReliable()
|
||||
t.origRequest = m
|
||||
t.state = ICT_CALLING
|
||||
|
||||
//发送出去之后,开启 timer
|
||||
if msg.IsReliable() {
|
||||
if m.IsReliable() {
|
||||
//stop timer E in reliable transport
|
||||
fmt.Println("Reliabel")
|
||||
//fmt.Println("Reliabel")
|
||||
} else {
|
||||
fmt.Println("Not Reliable")
|
||||
//fmt.Println("Not Reliable")
|
||||
//发送定时器,每次加倍,没有上限?
|
||||
t.timerA = NewSipTimer(T1, 0, func() {
|
||||
t.event <- &EventObj{
|
||||
evt: TIMEOUT_A,
|
||||
tid: t.id,
|
||||
if t.Err() == nil {
|
||||
t.Run(TIMEOUT_A, nil)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//事物定时器
|
||||
t.timerB = time.AfterFunc(TimeB, func() {
|
||||
t.event <- &EventObj{
|
||||
evt: TIMEOUT_B,
|
||||
tid: t.id,
|
||||
}
|
||||
})
|
||||
|
||||
t.RunAfter(TimeB, TIMEOUT_B)
|
||||
return nil
|
||||
}
|
||||
|
||||
func osip_ict_timeout_a_event(t *Transaction, e *EventObj) error {
|
||||
func osip_ict_timeout_a_event(t *Transaction, evt Event, m *sip.Message) error {
|
||||
err := t.SipSend(t.origRequest)
|
||||
if err != nil {
|
||||
//发送失败
|
||||
@@ -94,41 +81,33 @@ func osip_ict_timeout_a_event(t *Transaction, e *EventObj) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func osip_ict_timeout_b_event(t *Transaction, e *EventObj) error {
|
||||
func osip_ict_timeout_b_event(t *Transaction, evt Event, m *sip.Message) error {
|
||||
t.Terminate()
|
||||
return nil
|
||||
}
|
||||
|
||||
func ict_rcv_1xx(t *Transaction, e *EventObj) error {
|
||||
t.lastResponse = e.msg
|
||||
func ict_rcv_1xx(t *Transaction, evt Event, m *sip.Message) error {
|
||||
t.lastResponse = m
|
||||
t.state = ICT_PROCEEDING
|
||||
return nil
|
||||
}
|
||||
func ict_rcv_2xx(t *Transaction, e *EventObj) error {
|
||||
t.lastResponse = e.msg
|
||||
func ict_rcv_2xx(t *Transaction, evt Event, m *sip.Message) error {
|
||||
t.lastResponse = m
|
||||
t.Terminate()
|
||||
|
||||
return nil
|
||||
}
|
||||
func ict_rcv_3456xx(t *Transaction, e *EventObj) error {
|
||||
t.lastResponse = e.msg
|
||||
func ict_rcv_3456xx(t *Transaction, evt Event, m *sip.Message) error {
|
||||
t.lastResponse = m
|
||||
if t.state != ICT_COMPLETED {
|
||||
/* not a retransmission */
|
||||
/* automatic handling of ack! */
|
||||
ack := ict_create_ack(t, e.msg)
|
||||
ack := ict_create_ack(t, m)
|
||||
t.ack = ack
|
||||
_ = t.SipSend(t.ack)
|
||||
t.Terminate()
|
||||
}
|
||||
|
||||
/* start timer D (length is set to MAX (64*DEFAULT_T1 or 32000) */
|
||||
t.timerD = time.AfterFunc(TimeD, func() {
|
||||
t.event <- &EventObj{
|
||||
evt: TIMEOUT_D,
|
||||
tid: t.id,
|
||||
}
|
||||
})
|
||||
|
||||
t.RunAfter(TimeD, TIMEOUT_D)
|
||||
t.state = ICT_COMPLETED
|
||||
|
||||
return nil
|
||||
@@ -156,7 +135,7 @@ func ict_create_ack(t *Transaction, resp *sip.Message) *sip.Message {
|
||||
}
|
||||
}
|
||||
|
||||
func ict_retransmit_ack(t *Transaction, e *EventObj) error {
|
||||
func ict_retransmit_ack(t *Transaction, evt Event, m *sip.Message) error {
|
||||
if t.ack == nil {
|
||||
/* ??? we should make a new ACK and send it!!! */
|
||||
return nil
|
||||
@@ -170,7 +149,7 @@ func ict_retransmit_ack(t *Transaction, e *EventObj) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func osip_ict_timeout_d_event(t *Transaction, e *EventObj) error {
|
||||
func osip_ict_timeout_d_event(t *Transaction, evt Event, m *sip.Message) error {
|
||||
t.Terminate()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,26 +1,28 @@
|
||||
package transaction
|
||||
|
||||
func ist_rcv_invite(t *Transaction, e *EventObj) error {
|
||||
import "github.com/Monibuca/plugin-gb28181/v3/sip"
|
||||
|
||||
func ist_rcv_invite(t *Transaction, evt Event,m *sip.Message) error {
|
||||
return nil
|
||||
}
|
||||
func osip_ist_timeout_g_event(t *Transaction, e *EventObj) error {
|
||||
func osip_ist_timeout_g_event(t *Transaction, evt Event,m *sip.Message) error {
|
||||
return nil
|
||||
}
|
||||
func osip_ist_timeout_h_event(t *Transaction, e *EventObj) error {
|
||||
func osip_ist_timeout_h_event(t *Transaction, evt Event,m *sip.Message) error {
|
||||
return nil
|
||||
}
|
||||
func ist_snd_1xx(t *Transaction, e *EventObj) error {
|
||||
func ist_snd_1xx(t *Transaction, evt Event,m *sip.Message) error {
|
||||
return nil
|
||||
}
|
||||
func ist_snd_2xx(t *Transaction, e *EventObj) error {
|
||||
func ist_snd_2xx(t *Transaction, evt Event,m *sip.Message) error {
|
||||
return nil
|
||||
}
|
||||
func ist_snd_3456xx(t *Transaction, e *EventObj) error {
|
||||
func ist_snd_3456xx(t *Transaction, evt Event,m *sip.Message) error {
|
||||
return nil
|
||||
}
|
||||
func ist_rcv_ack(t *Transaction, e *EventObj) error {
|
||||
func ist_rcv_ack(t *Transaction, evt Event,m *sip.Message) error {
|
||||
return nil
|
||||
}
|
||||
func osip_ist_timeout_i_event(t *Transaction, e *EventObj) error {
|
||||
func osip_ist_timeout_i_event(t *Transaction, evt Event,m *sip.Message) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package transaction
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/sip"
|
||||
)
|
||||
|
||||
/*
|
||||
@@ -51,52 +50,43 @@ import (
|
||||
|
||||
Figure 6: non-INVITE client transaction
|
||||
*/
|
||||
func nict_snd_request(t *Transaction, e *EventObj) error {
|
||||
msg := e.msg
|
||||
fmt.Println("nict request:", msg.GetMethod())
|
||||
func nict_snd_request(t *Transaction, evt Event, m *sip.Message) error {
|
||||
//fmt.Println("nict request:", msg.GetMethod())
|
||||
|
||||
t.origRequest = msg
|
||||
t.origRequest = m
|
||||
t.state = NICT_TRYING
|
||||
|
||||
err := t.SipSend(msg)
|
||||
err := t.SipSend(m)
|
||||
if err != nil {
|
||||
t.Terminate()
|
||||
return err
|
||||
}
|
||||
|
||||
//发送出去之后,开启 timer
|
||||
if msg.IsReliable() {
|
||||
if m.IsReliable() {
|
||||
//stop timer E in reliable transport
|
||||
fmt.Println("Reliabel")
|
||||
//fmt.Println("Reliabel")
|
||||
} else {
|
||||
fmt.Println("Not Reliable")
|
||||
//fmt.Println("Not Reliable")
|
||||
//发送定时器
|
||||
|
||||
t.timerE = NewSipTimer(T1, T2, func() {
|
||||
t.event <- &EventObj{
|
||||
evt: TIMEOUT_E,
|
||||
tid: t.id,
|
||||
if t.Err() == nil {
|
||||
t.Run(TIMEOUT_E, nil)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//事物定时器
|
||||
t.timerF = time.AfterFunc(TimeF, func() {
|
||||
t.event <- &EventObj{
|
||||
evt: TIMEOUT_F,
|
||||
tid: t.id,
|
||||
}
|
||||
})
|
||||
|
||||
t.RunAfter(TimeF, TIMEOUT_F)
|
||||
return nil
|
||||
}
|
||||
|
||||
//事物超时
|
||||
func osip_nict_timeout_f_event(t *Transaction, e *EventObj) error {
|
||||
func osip_nict_timeout_f_event(t *Transaction, evt Event, m *sip.Message) error {
|
||||
t.Terminate()
|
||||
return nil
|
||||
}
|
||||
|
||||
func osip_nict_timeout_e_event(t *Transaction, e *EventObj) error {
|
||||
func osip_nict_timeout_e_event(t *Transaction, evt Event, m *sip.Message) error {
|
||||
if t.state == NICT_TRYING {
|
||||
//reset timer
|
||||
t.timerE.Reset(t.timerE.timeout * 2)
|
||||
@@ -115,8 +105,8 @@ func osip_nict_timeout_e_event(t *Transaction, e *EventObj) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func nict_rcv_1xx(t *Transaction, e *EventObj) error {
|
||||
t.lastResponse = e.msg
|
||||
func nict_rcv_1xx(t *Transaction, evt Event, m *sip.Message) error {
|
||||
t.lastResponse = m
|
||||
t.state = NICT_PROCEEDING
|
||||
|
||||
//重置发送定时器
|
||||
@@ -125,25 +115,20 @@ func nict_rcv_1xx(t *Transaction, e *EventObj) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func nict_rcv_23456xx(t *Transaction, e *EventObj) error {
|
||||
t.lastResponse = e.msg
|
||||
func nict_rcv_23456xx(t *Transaction, evt Event, m *sip.Message) error {
|
||||
t.lastResponse = m
|
||||
t.state = NICT_COMPLETED
|
||||
|
||||
if e.msg.IsReliable() {
|
||||
//不设置timerK
|
||||
} else {
|
||||
t.timerK = time.AfterFunc(T4, func() {
|
||||
t.event <- &EventObj{
|
||||
evt: TIMEOUT_K,
|
||||
tid: t.id,
|
||||
}
|
||||
})
|
||||
}
|
||||
t.Terminate()
|
||||
// if m.IsReliable() {
|
||||
// //不设置timerK
|
||||
// } else {
|
||||
// t.RunAfter(T4*64, TIMEOUT_K)
|
||||
// }
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func osip_nict_timeout_k_event(t *Transaction, e *EventObj) error {
|
||||
func osip_nict_timeout_k_event(t *Transaction, evt Event, m *sip.Message) error {
|
||||
t.Terminate()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@ package transaction
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/Monibuca/plugin-gb28181/v3/sip"
|
||||
)
|
||||
|
||||
/*
|
||||
@@ -51,8 +52,8 @@ import (
|
||||
|
||||
*/
|
||||
|
||||
func nist_rcv_request(t *Transaction, e *EventObj) error {
|
||||
fmt.Println("rcv request: ", e.msg.GetMethod())
|
||||
func nist_rcv_request(t *Transaction, evt Event, m *sip.Message) error {
|
||||
fmt.Println("rcv request: ", m.GetMethod())
|
||||
fmt.Println("transaction state: ", t.state.String())
|
||||
if t.state != NIST_PRE_TRYING {
|
||||
fmt.Println("rcv request retransmission,do response")
|
||||
@@ -65,16 +66,16 @@ func nist_rcv_request(t *Transaction, e *EventObj) error {
|
||||
}
|
||||
return nil
|
||||
} else {
|
||||
t.origRequest = e.msg
|
||||
t.origRequest = m
|
||||
t.state = NIST_TRYING
|
||||
t.isReliable = e.msg.IsReliable()
|
||||
t.isReliable = m.IsReliable()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func nist_snd_1xx(t *Transaction, e *EventObj) error {
|
||||
t.lastResponse = e.msg
|
||||
func nist_snd_1xx(t *Transaction, evt Event, m *sip.Message) error {
|
||||
t.lastResponse = m
|
||||
err := t.SipSend(t.lastResponse)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -84,27 +85,21 @@ func nist_snd_1xx(t *Transaction, e *EventObj) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func nist_snd_23456xx(t *Transaction, e *EventObj) error {
|
||||
t.lastResponse = e.msg
|
||||
err := t.SipSend(t.lastResponse)
|
||||
if err != nil {
|
||||
func nist_snd_23456xx(t *Transaction, evt Event, m *sip.Message) error {
|
||||
t.lastResponse = m
|
||||
if err := t.SipSend(t.lastResponse); err != nil {
|
||||
return err
|
||||
}
|
||||
if t.state != NIST_COMPLETED {
|
||||
if !t.isReliable {
|
||||
t.timerJ = time.AfterFunc(T1*64, func() {
|
||||
t.event <- &EventObj{
|
||||
evt: TIMEOUT_J,
|
||||
tid: t.id,
|
||||
}
|
||||
})
|
||||
t.RunAfter(T1*64, TIMEOUT_J)
|
||||
}
|
||||
}
|
||||
|
||||
t.state = NIST_COMPLETED
|
||||
return nil
|
||||
}
|
||||
func osip_nist_timeout_j_event(t *Transaction, e *EventObj) error {
|
||||
func osip_nist_timeout_j_event(t *Transaction, evt Event, m *sip.Message) error {
|
||||
t.Terminate()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -4,10 +4,11 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/Monibuca/plugin-gb28181/sip"
|
||||
"github.com/Monibuca/plugin-gb28181/transport"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/sip"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/transport"
|
||||
)
|
||||
|
||||
//状态机之状态
|
||||
@@ -229,13 +230,13 @@ type Response struct {
|
||||
Data *sip.Message
|
||||
}
|
||||
|
||||
type Handler func(t *Transaction, e *EventObj) error //操作
|
||||
type Handler func(*Transaction, Event, *sip.Message) error //操作
|
||||
|
||||
type Header map[string]string
|
||||
|
||||
// timer相关基础常量、方法等定义
|
||||
const (
|
||||
T1 = 100 * time.Millisecond
|
||||
T1 = 250 * time.Millisecond
|
||||
T2 = 4 * time.Second
|
||||
T4 = 5 * time.Second
|
||||
TimeA = T1
|
||||
@@ -257,15 +258,15 @@ const (
|
||||
|
||||
//是否需要tp layer?
|
||||
type Transaction struct {
|
||||
ctx context.Context //线程管理、其他参数
|
||||
id string //transaction ID
|
||||
isReliable bool //是否可靠传输
|
||||
core *Core //全局参数
|
||||
typo FSMType //状态机类型
|
||||
done chan struct{} //主动退出
|
||||
cancel context.CancelFunc
|
||||
context.Context //线程管理、其他参数
|
||||
sync.Mutex
|
||||
id string //transaction ID
|
||||
isReliable bool //是否可靠传输
|
||||
core *Core //全局参数
|
||||
typo FSMType //状态机类型
|
||||
|
||||
state State //当前状态
|
||||
event chan *EventObj //输入的事件,带缓冲
|
||||
response chan *Response //输出的响应
|
||||
startAt time.Time //开始时间
|
||||
endAt time.Time //结束时间
|
||||
@@ -280,24 +281,10 @@ type Transaction struct {
|
||||
origRequest *sip.Message //Initial request
|
||||
lastResponse *sip.Message //Last response,可能是临时的,也可能是最终的
|
||||
ack *sip.Message //ack request sent
|
||||
|
||||
//timer for ict
|
||||
timerA *SipTimer
|
||||
timerB *time.Timer
|
||||
timerD *time.Timer
|
||||
|
||||
//timer for nict
|
||||
timerE *SipTimer
|
||||
timerF *time.Timer
|
||||
timerK *time.Timer
|
||||
|
||||
//timer for ist
|
||||
timerG *time.Timer
|
||||
timerH *time.Timer
|
||||
timerI *time.Timer
|
||||
|
||||
//timer for nist
|
||||
timerJ *time.Timer
|
||||
}
|
||||
|
||||
type SipTimer struct {
|
||||
@@ -330,40 +317,37 @@ func (ta *Transaction) GetTid() string {
|
||||
return ta.id
|
||||
}
|
||||
|
||||
func (ta *Transaction) RunAfter(t time.Duration, evt Event) {
|
||||
time.AfterFunc(t, func() {
|
||||
if ta.Err() == nil {
|
||||
ta.Run(evt, nil)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//每一个transaction至少有一个状态机线程运行
|
||||
//TODO:如果是一个uac的transaction,则把最后响应的消息返回(通过response chan)
|
||||
//transaction有很多消息需要传递到TU,也接收来自TU的消息。
|
||||
func (ta *Transaction) Run() {
|
||||
for {
|
||||
select {
|
||||
case e := <-ta.event:
|
||||
//根据event调用对应的handler
|
||||
fmt.Println("fsm run event:", e.evt.String())
|
||||
core := ta.core
|
||||
state := ta.state
|
||||
evtHandlers, ok1 := core.handlers[state]
|
||||
if !ok1 {
|
||||
fmt.Println("invalid state:", ta.state.String())
|
||||
break
|
||||
}
|
||||
f, ok2 := evtHandlers[e.evt]
|
||||
if !ok2 {
|
||||
fmt.Println("invalid handler for this event:", e.evt.String())
|
||||
break
|
||||
}
|
||||
fmt.Printf("state:%s, event:%s\n", state.String(), e.evt.String())
|
||||
err := f(ta, e)
|
||||
if err != nil {
|
||||
fmt.Printf("transaction run failed, state:%s, event:%s\n", state.String(), e.evt.String())
|
||||
}
|
||||
case <-ta.done:
|
||||
fmt.Println("fsm exit")
|
||||
return
|
||||
|
||||
case <-ta.ctx.Done():
|
||||
fmt.Println("fsm killed")
|
||||
return
|
||||
}
|
||||
func (ta *Transaction) Run(evt Event, m *sip.Message) {
|
||||
//根据event调用对应的handler
|
||||
//fmt.Println("fsm run event:", e.evt.String())
|
||||
core := ta.core
|
||||
ta.Lock()
|
||||
defer ta.Unlock()
|
||||
evtHandlers, ok1 := core.handlers[ta.state]
|
||||
if !ok1 {
|
||||
//fmt.Println("invalid state:", ta.state.String())
|
||||
return
|
||||
}
|
||||
f, ok2 := evtHandlers[evt]
|
||||
if !ok2 {
|
||||
//fmt.Println("invalid handler for this event:", e.evt.String())
|
||||
return
|
||||
}
|
||||
//fmt.Printf("state:%s, event:%s\n", state.String(), e.evt.String())
|
||||
err := f(ta, evt, m)
|
||||
if err != nil {
|
||||
//fmt.Printf("transaction run failed, state:%s, event:%s\n", state.String(), e.evt.String())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,13 +368,10 @@ func (ta *Transaction) Terminate() {
|
||||
ta.state = NIST_TERMINATED
|
||||
}
|
||||
|
||||
//关掉事物的线程
|
||||
close(ta.done)
|
||||
|
||||
//关掉事物
|
||||
ta.cancel()
|
||||
//TODO:某些timer需要检查并关掉,并且设置为nil
|
||||
|
||||
//remove ta from core
|
||||
ta.core.removeTa <- ta.id
|
||||
ta.core.DelTransaction(ta.id)
|
||||
}
|
||||
|
||||
//根据sip消息,解析出目标服务器地址,发送消息
|
||||
@@ -424,7 +405,7 @@ func (ta *Transaction) SipSend(msg *sip.Message) error {
|
||||
addr = fmt.Sprintf("%s:%s", host, port)
|
||||
}
|
||||
|
||||
fmt.Println("dest addr:", addr)
|
||||
//fmt.Println("dest addr:", addr)
|
||||
|
||||
var err1, err2 error
|
||||
pkt := &transport.Packet{}
|
||||
|
||||
@@ -2,7 +2,7 @@ package transaction
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Monibuca/plugin-gb28181/sip"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/sip"
|
||||
"net"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -2,7 +2,7 @@ package transport
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Monibuca/plugin-gb28181/utils"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/utils"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -2,7 +2,7 @@ package tu
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Monibuca/plugin-gb28181/transaction"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/transaction"
|
||||
)
|
||||
|
||||
//sip server和client的配置,可以得到sip URI:sip
|
||||
|
||||
@@ -2,8 +2,8 @@ package tu
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Monibuca/plugin-gb28181/sip"
|
||||
"github.com/Monibuca/plugin-gb28181/utils"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/sip"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/utils"
|
||||
)
|
||||
|
||||
//根据参数构建各种消息
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package tu
|
||||
|
||||
import (
|
||||
"github.com/Monibuca/plugin-gb28181/transaction"
|
||||
"sync"
|
||||
|
||||
"github.com/Monibuca/plugin-gb28181/v3/transaction"
|
||||
)
|
||||
|
||||
//TODO:参考http服务,使用者仅需要根据需要实现某些handler,替换某些header fileds or body信息。其他的处理都由库来实现。
|
||||
|
||||
19
ui/dist/demo.html
vendored
19
ui/dist/demo.html
vendored
@@ -1,19 +0,0 @@
|
||||
<meta charset="utf-8">
|
||||
<title>plugin-gb28181 demo</title>
|
||||
<script src="https://unpkg.com/vue"></script>
|
||||
<script src="./plugin-gb28181.umd.js"></script>
|
||||
|
||||
<link rel="stylesheet" href="./plugin-gb28181.css">
|
||||
|
||||
|
||||
<div id="app">
|
||||
<demo></demo>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
new Vue({
|
||||
components: {
|
||||
demo: plugin-gb28181
|
||||
}
|
||||
}).$mount('#app')
|
||||
</script>
|
||||
3623
ui/dist/plugin-gb28181.common.js
vendored
3623
ui/dist/plugin-gb28181.common.js
vendored
File diff suppressed because one or more lines are too long
1
ui/dist/plugin-gb28181.common.js.map
vendored
1
ui/dist/plugin-gb28181.common.js.map
vendored
File diff suppressed because one or more lines are too long
1
ui/dist/plugin-gb28181.css
vendored
1
ui/dist/plugin-gb28181.css
vendored
@@ -1 +0,0 @@
|
||||
.arrow1[data-v-43b2c727]{grid-column:2;grid-row:1}.arrow2[data-v-43b2c727]{transform:rotate(90deg);grid-column:3;grid-row:2}.arrow3[data-v-43b2c727]{transform:rotate(180deg);grid-column:2;grid-row:3}.arrow4[data-v-43b2c727]{transform:rotate(270deg);grid-column:1;grid-row:2}.arrow5[data-v-43b2c727]{transform:rotate(-45deg);grid-column:1;grid-row:1}.arrow6[data-v-43b2c727]{transform:rotate(45deg);grid-column:3;grid-row:1}.arrow7[data-v-43b2c727]{transform:rotate(-135deg);grid-column:1;grid-row:3}.arrow8[data-v-43b2c727]{transform:rotate(135deg);grid-column:3;grid-row:3}.arrow9[data-v-43b2c727]{grid-column:2;grid-row:2}.container[data-v-43b2c727]{position:relative;height:350px}.control[data-v-43b2c727]{position:absolute;top:20px;right:0;display:grid;grid-template-columns:repeat(3,33.33%);grid-template-rows:repeat(3,33.33%);width:192px;height:192px}.control2[data-v-43b2c727]{top:210px}.control3[data-v-43b2c727]{top:260px}.control4[data-v-43b2c727]{top:310px}.control5[data-v-43b2c727]{top:360px}.control>[data-v-43b2c727]{cursor:pointer;fill:grey;width:50px;height:50px}.control5>[data-v-43b2c727]{margin-right:10px}.control2>[data-v-43b2c727],.control3>[data-v-43b2c727],.control4>[data-v-43b2c727]{width:40px;height:40px}.control>[data-v-43b2c727]:hover,.cycling[data-v-43b2c727]{fill:#0ff}.player-wrap[data-v-3d23233a]{width:100%;height:100%;border-radius:4px;box-shadow:0 0 5px #40d3fc,inset 0 0 5px #40d3fc,0 0 0 1px #40d3fc}.player-wrap video[data-v-3d23233a]{width:100%;height:100%}.container[data-v-1496ea1d]{position:relative;height:500px;background-image:radial-gradient(rgba(197,45,208,.48),rgba(74,23,152,.48),rgba(3,0,19,.48));color:#fff;background-color:#000;overflow:auto}.search[data-v-1496ea1d]{padding:10px 0}.flex-box[data-v-6660cc55]{display:flex;flex-flow:row wrap;align-content:flex-start}.flex-item[data-v-6660cc55]{flex:0 0 33.3333%;height:275px;box-sizing:border-box;padding:10px}
|
||||
3633
ui/dist/plugin-gb28181.umd.js
vendored
3633
ui/dist/plugin-gb28181.umd.js
vendored
File diff suppressed because one or more lines are too long
1
ui/dist/plugin-gb28181.umd.js.map
vendored
1
ui/dist/plugin-gb28181.umd.js.map
vendored
File diff suppressed because one or more lines are too long
9
ui/dist/plugin-gb28181.umd.min.js
vendored
9
ui/dist/plugin-gb28181.umd.min.js
vendored
File diff suppressed because one or more lines are too long
1
ui/dist/plugin-gb28181.umd.min.js.map
vendored
1
ui/dist/plugin-gb28181.umd.min.js.map
vendored
File diff suppressed because one or more lines are too long
9471
ui/package-lock.json
generated
9471
ui/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,18 +0,0 @@
|
||||
{
|
||||
"name": "dashboard",
|
||||
"version": "1.0.0",
|
||||
"description": "dashboard of gb28181 plugin for monibuca",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "vue-cli-service build --target lib --name plugin-gb28181"
|
||||
},
|
||||
"author": "dexter",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@vue/cli-service": "^4.5.4",
|
||||
"vue-template-compiler": "^2.6.12"
|
||||
},
|
||||
"dependencies": {
|
||||
"vue": "^2.6.12"
|
||||
}
|
||||
}
|
||||
321
ui/src/App.vue
321
ui/src/App.vue
@@ -1,321 +0,0 @@
|
||||
<template>
|
||||
<div>
|
||||
<div class="tabpanel" v-if="$parent.titleTabActive === 0">
|
||||
<mu-data-table :data="Devices" :columns="columns">
|
||||
<template #expand="prop">
|
||||
<mu-data-table
|
||||
:data="prop.row.Channels"
|
||||
:columns="columns2"
|
||||
>
|
||||
<template #default="{ row: item, $index }">
|
||||
<td>{{ item.DeviceID }}</td>
|
||||
<td>{{ item.Name }}</td>
|
||||
<td>{{ item.Manufacturer }}</td>
|
||||
<td>{{ item.Address }}</td>
|
||||
<td>{{ item.Status }}</td>
|
||||
<td>
|
||||
<mu-button
|
||||
flat
|
||||
@click="ptz(prop.row.ID, $index, item)"
|
||||
>云台
|
||||
</mu-button>
|
||||
<!-- <mu-button
|
||||
flat
|
||||
v-if="item.Connected"
|
||||
@click="bye(prop.row.ID, $index, item)"
|
||||
>断开
|
||||
</mu-button>
|
||||
<mu-button
|
||||
v-else
|
||||
flat
|
||||
@click="invite(prop.row.ID, $index, item)"
|
||||
>连接
|
||||
</mu-button> -->
|
||||
<mu-button
|
||||
flat
|
||||
@click="
|
||||
getRecords(prop.row.ID, $index, item)
|
||||
"
|
||||
>录像</mu-button
|
||||
>
|
||||
</td>
|
||||
</template>
|
||||
</mu-data-table>
|
||||
</template>
|
||||
<template #default="{ row: item }">
|
||||
<td>{{ item.ID }}</td>
|
||||
<td>{{ item.Addr }}</td>
|
||||
<td>{{ item.Channels ? item.Channels.length : 0 }}</td>
|
||||
<td>
|
||||
<StartTime :value="item.RegisterTime"></StartTime>
|
||||
</td>
|
||||
<td>
|
||||
<StartTime :value="item.UpdateTime"></StartTime>
|
||||
</td>
|
||||
<td>{{ item.Status }}</td>
|
||||
</template>
|
||||
</mu-data-table>
|
||||
</div>
|
||||
<div class="tabpanel" v-if="$parent.titleTabActive === 1">
|
||||
<div class="flex-box">
|
||||
<template v-for="(channel, index) in channelShowList">
|
||||
<div class="flex-item" :key="index">
|
||||
<webrtc-player2
|
||||
@hook:mounted="
|
||||
invite(
|
||||
channel.device.ID,
|
||||
channel.device.Channels.indexOf(channel),
|
||||
channel,
|
||||
'v/2/1/15/1/200a///'
|
||||
)
|
||||
"
|
||||
:stream-path="
|
||||
channel.device.ID + '/' + channel.DeviceID
|
||||
"
|
||||
></webrtc-player2>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<template v-if="channelList.length > 0">
|
||||
<Page
|
||||
:total="channelList.length"
|
||||
:page-size="pageInfo.onePageSize"
|
||||
@on-change="handlePageChange"
|
||||
></Page>
|
||||
</template>
|
||||
</div>
|
||||
<webrtc-player
|
||||
ref="player"
|
||||
@ptz="sendPtz"
|
||||
v-model="previewStreamPath"
|
||||
></webrtc-player>
|
||||
<records
|
||||
ref="records"
|
||||
v-model="recordModal"
|
||||
:search="recordSearch"
|
||||
:channel="currentChannel"
|
||||
@close="initRecordSearch"
|
||||
></records>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import WebrtcPlayer from "./components/Player";
|
||||
import WebrtcPlayer2 from "./components/Player2";
|
||||
import Records from "./components/Records";
|
||||
import { getPTZCmd, PTZ_TYPE } from "./utils/ptz-cmd";
|
||||
import { getOneTimeRange } from "./utils";
|
||||
|
||||
export default {
|
||||
components: {
|
||||
WebrtcPlayer,
|
||||
WebrtcPlayer2,
|
||||
Records,
|
||||
},
|
||||
props: {
|
||||
ListenAddr: String,
|
||||
},
|
||||
computed: {
|
||||
PublicIP() {
|
||||
return this.ListenAddr.split(":")[0];
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
Devices: [],
|
||||
previewStreamPath: false,
|
||||
channelList: [],
|
||||
channelShowList: [],
|
||||
pageInfo: {
|
||||
onePageSize: 9,
|
||||
totalPage: 0,
|
||||
currentPage: 0,
|
||||
},
|
||||
currentChannel: null,
|
||||
recordModal: false,
|
||||
recordSearch: {
|
||||
id: null,
|
||||
channel: null,
|
||||
deviceId: null,
|
||||
},
|
||||
context: {
|
||||
id: null,
|
||||
channel: 0,
|
||||
item: null,
|
||||
},
|
||||
columns: Object.freeze(
|
||||
[
|
||||
"设备号",
|
||||
"地址",
|
||||
"通道数",
|
||||
"注册时间",
|
||||
"更新时间",
|
||||
"状态",
|
||||
].map((title) => ({
|
||||
title,
|
||||
}))
|
||||
),
|
||||
columns2: Object.freeze([
|
||||
"通道编号",
|
||||
"名称",
|
||||
"厂商",
|
||||
"地址",
|
||||
"状态",
|
||||
"操作",
|
||||
]).map((title) => ({ title })),
|
||||
};
|
||||
},
|
||||
created() {
|
||||
this.fetchlist();
|
||||
},
|
||||
mounted() {
|
||||
this.$parent.titleTabs = ["列表", "N路播放"];
|
||||
},
|
||||
methods: {
|
||||
fetchlist() {
|
||||
const listES = new EventSource("/gb28181/list");
|
||||
listES.onmessage = (evt) => {
|
||||
if (!evt.data) return;
|
||||
this.Devices = JSON.parse(evt.data) || [];
|
||||
this.Devices.sort((a, b) => (a.ID > b.ID ? 1 : -1));
|
||||
let channelList = [];
|
||||
this.Devices.forEach((device) => {
|
||||
const channels = device.Channels || [];
|
||||
if (channels.length > 0) {
|
||||
channelList = channelList.concat(
|
||||
channels.map((x) => ((x.device = device), x))
|
||||
);
|
||||
}
|
||||
if (this.recordSearch.id && this.recordSearch.deviceId) {
|
||||
const channel = channels.find((i) => {
|
||||
return (
|
||||
i.DeviceID === this.recordSearch.deviceId &&
|
||||
this.recordSearch.id === device.ID
|
||||
);
|
||||
});
|
||||
if (channel) this.currentChannel = channel;
|
||||
}
|
||||
});
|
||||
if (channelList.length > 0) {
|
||||
this.channelList = channelList;
|
||||
this.updatePageInfo(channelList.length);
|
||||
}
|
||||
};
|
||||
this.$once("hook:destroyed", () => listES.close());
|
||||
},
|
||||
async ptz(id, channel, item) {
|
||||
await this.invite(id, channel, item);
|
||||
this.context = {
|
||||
id,
|
||||
channel,
|
||||
item,
|
||||
};
|
||||
this.previewStreamPath = true;
|
||||
const unwatch = this.$watch(
|
||||
"previewStreamPath",
|
||||
(newValue, oldValue) => {
|
||||
this.bye(id, channel, item);
|
||||
unwatch();
|
||||
}
|
||||
);
|
||||
this.$nextTick(() =>
|
||||
this.$refs.player.play(id + "/" + item.DeviceID)
|
||||
);
|
||||
},
|
||||
sendPtz(options) {
|
||||
const ptzCmd = getPTZCmd(options);
|
||||
const ptzCmdStop = getPTZCmd({ type: PTZ_TYPE.stop });
|
||||
this.ajax
|
||||
.get("/gb28181/control", {
|
||||
id: this.context.id,
|
||||
channel: this.context.channel,
|
||||
ptzcmd: ptzCmd,
|
||||
})
|
||||
.then((x) => {
|
||||
if (
|
||||
options.type === PTZ_TYPE.stop ||
|
||||
options.cycle === true
|
||||
) {
|
||||
return;
|
||||
}
|
||||
setTimeout(() => {
|
||||
this.ajax.get("/gb28181/control", {
|
||||
id: this.context.id,
|
||||
channel: this.context.channel,
|
||||
ptzcmd: ptzCmdStop,
|
||||
});
|
||||
}, 500);
|
||||
});
|
||||
},
|
||||
|
||||
sendQueryRecords(options) {},
|
||||
|
||||
handlePageChange(page) {
|
||||
let showList = [];
|
||||
const onePageSize = this.pageInfo.onePageSize;
|
||||
const firstIndex = page * onePageSize - onePageSize;
|
||||
const lastIndex = page * onePageSize - 1;
|
||||
showList = this.channelList.filter((item, index) => {
|
||||
return index >= firstIndex && index <= lastIndex;
|
||||
});
|
||||
|
||||
this.channelShowList = showList;
|
||||
|
||||
if (showList.length > 0) {
|
||||
this.pageInfo.currentPage = page;
|
||||
}
|
||||
},
|
||||
updatePageInfo(totalSize) {
|
||||
const onePageSize = this.pageInfo.onePageSize;
|
||||
let totalPage = totalSize / onePageSize;
|
||||
|
||||
if (totalSize % onePageSize > 0) {
|
||||
totalPage = totalPage + 1;
|
||||
}
|
||||
this.pageInfo.totalPage = totalPage;
|
||||
if (this.pageInfo.currentPage === 0) {
|
||||
this.handlePageChange(1);
|
||||
}
|
||||
},
|
||||
invite(id, channel, item, f = "") {
|
||||
return this.ajax
|
||||
.get("/gb28181/invite", { id, channel, f })
|
||||
.then((x) => {
|
||||
item.Connected = true;
|
||||
});
|
||||
},
|
||||
bye(id, channel, item) {
|
||||
return this.ajax.get("/gb28181/bye", { id, channel }).then((x) => {
|
||||
item.Connected = false;
|
||||
});
|
||||
},
|
||||
|
||||
getRecords(id, channel, item) {
|
||||
this.recordSearch.id = id;
|
||||
this.recordSearch.channel = channel;
|
||||
this.recordSearch.deviceId = item.DeviceID;
|
||||
this.recordModal = true;
|
||||
},
|
||||
|
||||
initRecordSearch() {
|
||||
this.recordModal = false;
|
||||
this.recordSearch.id = null;
|
||||
this.recordSearch.channel = null;
|
||||
this.recordSearch.deviceId = null;
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
<style scoped>
|
||||
.flex-box {
|
||||
display: flex;
|
||||
flex-flow: row wrap;
|
||||
align-content: flex-start;
|
||||
}
|
||||
|
||||
.flex-item {
|
||||
flex: 0 0 33.3333%;
|
||||
height: 275px;
|
||||
box-sizing: border-box;
|
||||
padding: 10px;
|
||||
}
|
||||
</style>
|
||||
@@ -1,234 +0,0 @@
|
||||
<template>
|
||||
<Modal
|
||||
v-bind="$attrs"
|
||||
draggable
|
||||
width="750"
|
||||
v-on="$listeners"
|
||||
:title="streamPath"
|
||||
@on-ok="onClosePreview"
|
||||
@on-cancel="onClosePreview"
|
||||
>
|
||||
<div class="container">
|
||||
<video ref="webrtc" :srcObject.prop="stream" width="488" height="275" autoplay muted controls></video>
|
||||
<div class="control">
|
||||
<svg v-for="n in 8" @click="ptzCmdDirection(n)" :class="'arrow'+n" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="64" height="64"><defs><style type="text/css"></style></defs><path d="M682.666667 955.733333H341.333333a17.066667 17.066667 0 0 1-17.066666-17.066666V529.066667H85.333333a17.066667 17.066667 0 0 1-12.066133-29.1328l426.666667-426.666667a17.0496 17.0496 0 0 1 24.132266 0l426.666667 426.666667A17.066667 17.066667 0 0 1 938.666667 529.066667H699.733333v409.6a17.066667 17.066667 0 0 1-17.066666 17.066666z m-324.266667-34.133333h307.2V512a17.066667 17.066667 0 0 1 17.066667-17.066667h214.801066L512 109.4656 126.532267 494.933333H341.333333a17.066667 17.066667 0 0 1 17.066667 17.066667v409.6z" p-id="6849"></path></svg>
|
||||
<svg @mousedown="startPtzCmdCycle" @mouseup="stopPtzCmdCycle" class="arrow9" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M512 960c-210.96 0-395.36-149.68-438.47-355.91-2.98-14.24 6.16-28.21 20.4-31.19 14.22-2.93 28.21 6.15 31.18 20.41C163.15 775.25 325.86 907.29 512 907.29s348.85-132.05 386.89-313.98c2.99-14.26 16.97-23.35 31.19-20.41 14.24 2.99 23.38 16.95 20.41 31.19C907.36 810.32 722.95 960 512 960zM927.48 466.94c-12.61 0-23.75-9.07-25.95-21.91C869.06 254.78 705.24 116.71 512 116.71c-193.23 0-357.05 138.07-389.52 328.32-2.45 14.35-16.08 24.01-30.41 21.54-14.35-2.46-23.99-16.07-21.55-30.42C107.33 220.51 293 64 512 64c219.01 0 404.68 156.51 441.48 372.15 2.44 14.35-7.21 27.97-21.54 30.42-1.5 0.25-3 0.37-4.46 0.37z" /><path d="M96.52 466.94c-9.11 0-17.97-4.72-22.85-13.18-7.28-12.61-2.96-28.72 9.64-36l131.76-76.07c12.6-7.26 28.73-2.96 36 9.65 7.28 12.61 2.96 28.72-9.64 36l-131.76 76.07a26.18 26.18 0 0 1-13.15 3.53zM792.95 701.14c-9.11 0-17.96-4.72-22.85-13.18-7.28-12.6-2.96-28.72 9.64-36l131.76-76.09c12.58-7.28 28.72-2.95 36 9.65 7.27 12.6 2.96 28.72-9.65 36l-131.75 76.1a26.271 26.271 0 0 1-13.15 3.52z" /></svg>
|
||||
</div>
|
||||
<div class="control control2">
|
||||
<svg @click="ptzCmd(ptzType.zoomFar)" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M994.990643 859.352971L713.884166 578.246494A381.208198 381.208198 0 0 0 767.307984 383.653992C767.307984 171.765089 595.542895 0 383.653992 0S0 171.765089 0 383.653992s171.765089 383.653992 383.653992 383.653992c71.119859 0 137.507985-19.694238 194.592502-53.423818l281.106477 281.090491a95.913498 95.913498 0 1 0 135.637672-135.621686zM383.653992 671.394486c-158.912681 0-287.740494-128.827813-287.740494-287.740494S224.741311 95.913498 383.653992 95.913498s287.740494 128.827813 287.740494 287.740494-128.827813 287.740494-287.740494 287.740494z m159.85583-335.697243h-111.899081v-111.899081a47.956749 47.956749 0 1 0-95.913498 0v111.899081h-111.899081a47.956749 47.956749 0 1 0 0 95.913498h111.899081v111.899081a47.956749 47.956749 0 1 0 95.913498 0v-111.899081h111.899081a47.956749 47.956749 0 1 0 0-95.913498z" /></svg>
|
||||
<svg @click="ptzCmd(ptzType.zoomNear)" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M994.990643 859.352971L713.884166 578.246494A381.208198 381.208198 0 0 0 767.307984 383.653992C767.307984 171.765089 595.542895 0 383.653992 0S0 171.765089 0 383.653992s171.765089 383.653992 383.653992 383.653992c71.119859 0 137.507985-19.694238 194.592502-53.423818l281.106477 281.090491a95.913498 95.913498 0 1 0 135.637672-135.621686zM383.653992 671.394486c-158.912681 0-287.740494-128.827813-287.740494-287.740494S224.741311 95.913498 383.653992 95.913498s287.740494 128.827813 287.740494 287.740494-128.827813 287.740494-287.740494 287.740494z m159.85583-335.697243H223.798162a47.956749 47.956749 0 1 0 0 95.913498h319.71166a47.956749 47.956749 0 1 0 0-95.913498z" /></svg>
|
||||
</div>
|
||||
<div class="control control3">
|
||||
<svg @click="ptzCmd(ptzType.apertureFar)" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M956.39 400.827C922.164 266.675 828.186 155.703 701.502 99.874l94.522 443.782L956.39 400.827zM206.208 189.167C106.183 286.191 56.845 424.181 72.696 562.659l351.347-309.096-217.835-64.396zM643.118 78.847a446.363 446.363 0 0 0-138.947-16.775 448.047 448.047 0 0 0-250.583 86.934l437.868 146.949-48.338-217.108zM83.786 623.979c34.443 133.772 128.248 244.407 254.583 300.291l-95.915-426.55L83.786 623.979zM969.893 496.089a372.746 372.746 0 0 0-2.37-34.138l-329.972 303.78 196.157 69.256c91.522-88.456 141.056-211.704 136.185-338.898zM396.862 945.166a447.857 447.857 0 0 0 139.077 16.766 447.784 447.784 0 0 0 250.322-86.718L349.286 733.05l47.576 212.116z" /><path fill="#333333" d="M397.253 471.171h245.668c22.593 0 40.923 18.32 40.923 40.913 0 22.592-18.33 40.922-40.923 40.922H397.253c-22.592 0-40.922-18.33-40.922-40.922 0-22.593 18.33-40.913 40.922-40.913z" /><path fill="#333333" d="M479.17 634.879V389.21c0-22.593 18.32-40.923 40.913-40.923s40.923 18.33 40.923 40.923v245.668c0 22.592-18.33 40.922-40.923 40.922s-40.913-18.329-40.913-40.921z" /></svg>
|
||||
<svg @click="ptzCmd(ptzType.apertureNear)" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M956.39 400.827C922.164 266.675 828.186 155.703 701.502 99.874l94.522 443.782L956.39 400.827z m-750.182-211.66C106.183 286.191 56.845 424.181 72.696 562.659l351.347-309.096-217.835-64.396z m436.91-110.32a446.363 446.363 0 0 0-138.947-16.775 448.047 448.047 0 0 0-250.583 86.934l437.868 146.949-48.338-217.108zM83.786 623.979c34.443 133.772 128.248 244.407 254.583 300.291l-95.915-426.55L83.786 623.979z m886.107-127.89a372.746 372.746 0 0 0-2.37-34.138l-329.972 303.78 196.157 69.256c91.522-88.456 141.056-211.704 136.185-338.898zM396.862 945.166a447.857 447.857 0 0 0 139.077 16.766 447.784 447.784 0 0 0 250.322-86.718L349.286 733.05l47.576 212.116z m0.391-474.039h245.668c22.593 0 40.923 18.32 40.923 40.912 0 22.593-18.33 40.923-40.923 40.923H397.253c-22.592 0-40.922-18.33-40.922-40.923 0-22.592 18.33-40.912 40.922-40.912z" /></svg>
|
||||
</div>
|
||||
<div class="control control4">
|
||||
<svg @click="ptzCmd(ptzType.focusFar)" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M849.07153297 646.81872559c9.30432153 0 17.26391602 3.30249 23.82934617 9.88769507 6.60992408 6.59509253 9.88769508 14.52502465 9.88769508 23.79473901v101.14617896c0 27.90801978-9.87780761 51.70275879-29.61364722 71.47814965-19.75067115 19.77539086-43.56518578 29.66308594-71.48803711 29.66308594h-101.1165166c-9.32409644 0-17.25402856-3.29754663-23.83428954-9.9865725-6.59509253-6.49127173-9.90252662-14.52502465-9.90252662-23.7947383 0-9.26971435 3.30743408-17.20458984 9.90252662-23.79473901 6.58026099-6.59014916 14.51019311-9.88769508 23.83428954-9.88769507h101.1165166c9.29937744 0 17.26391602-3.29754663 23.82440137-9.88769579 6.61486816-6.59014916 9.88769508-14.52008057 9.88769579-23.89361573v-101.04235815c0-9.36859107 3.28765845-17.30346656 9.89758254-23.78979493 6.57531762-6.69396997 14.52502465-9.99151587 23.83923363-9.99151587l-0.06427025 0.09887671zM242.38726782 141.3103025h101.10168506c9.30432153 0 17.2688601 3.29754663 23.819458 9.88769578 6.62475562 6.59509253 9.89758325 14.52502465 9.89758254 23.7947383 0 9.37353516-3.27282691 17.30346656-9.89758254 23.79473901-6.5505979 6.69396997-14.51513648 9.9865725-23.81451463 9.9865725h-101.10168433c-9.31915307 0-17.2688601 3.19372583-23.82934547 9.88769508-6.62475562 6.49127173-9.91241479 14.52502465-9.91241479 23.794739v101.04235816c0 9.36859107-3.28271508 17.30346656-9.89758324 23.89361573-6.57531762 6.59014916-14.51513648 9.88769508-23.81451392 9.88769507-9.31420898 0-17.25402856-3.29754663-23.82934547-9.88769507C144.49908423 360.80230689 141.21142578 352.86743141 141.21142578 343.49884033V242.45648217c0-27.91296386 9.86792016-51.70275879 29.62353539-71.47814965 19.75067115-19.77539086 43.57507324-29.66308594 71.48803711-29.66308594h0.06426954zM174.9877932 646.81872559c9.30432153 0 17.24414039 3.30249 23.81451393 9.88769507 6.62475562 6.59509253 9.90252662 14.52502465 9.90252662 23.79473901v101.14617896c0 9.26971435 3.27282691 17.19964576 9.89758324 23.78979492 6.57531762 6.59014916 14.51513648 9.88769508 23.81451393 9.88769579h101.12640404c9.29937744 0 17.25402856 3.29754663 23.82934547 9.88769507 6.60992408 6.59014916 9.88769508 14.52502465 9.88769579 23.89361572 0 9.26971435-3.27777099 17.20458984-9.88769579 23.79473901-6.57531762 6.59014916-14.52996803 9.88769508-23.82934547 9.88769508H242.41693092c-27.91296386 0-51.71264625-9.88769508-71.47814895-29.66308594-19.75561523-19.67651344-29.62353539-43.57012915-29.62353539-71.47814965v-101.04235816c0-9.26971435 3.27282691-17.30346656 9.88769507-23.89361573 6.58026099-6.59509253 14.52502465-9.88769508 23.81451464-9.88769507h-0.02966309zM680.57037329 141.3103025h101.1165166c27.92285133 0 51.73736596 9.88769508 71.48803711 29.56420922 19.73583961 19.77539086 29.61364722 43.57012915 29.61364722 71.47814965v101.14617896c0 9.26971435-3.27777099 17.30346656-9.88769508 23.78979493-6.56542945 6.69396997-14.52502465 9.88769508-23.82934617 9.88769506-9.29937744 0-17.26391602-3.19372583-23.82440139-9.88769506-6.61486816-6.48632836-9.88769508-14.52008057-9.88769579-23.78979493V242.35266137c0-9.26971435-3.28765845-17.19964576-9.90252661-23.78979492-6.57037354-6.59509253-14.52008057-9.88769508-23.83428955-9.88769579h-101.10168433c-9.31420898 0-17.2688601-3.29754663-23.82934618-9.88769507-6.60992408-6.59509253-9.89758325-14.52502465-9.89758254-23.79473902 0-9.37353516 3.28765845-17.30346656 9.89758254-23.89361571 6.56048608-6.59014916 14.51513648-9.88769508 23.82934618-9.88769508l0.04943799 0.09887672z" /></svg>
|
||||
<svg @click="ptzCmd(ptzType.focusNear)" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M512 170.666667A341.333333 341.333333 0 1 1 170.666667 512 341.333333 341.333333 0 0 1 512 170.666667m0-42.666667a384 384 0 1 0 384 384A384 384 0 0 0 512 128z" /><path fill="#333333" d="M298.666667 533.333333H170.666667a21.333333 21.333333 0 0 1 0-42.666666h128a21.333333 21.333333 0 0 1 0 42.666666zM853.333333 533.333333h-128a21.333333 21.333333 0 0 1 0-42.666666h128a21.333333 21.333333 0 0 1 0 42.666666zM512 320a21.333333 21.333333 0 0 1-21.333333-21.333333V170.666667a21.333333 21.333333 0 0 1 42.666666 0v128a21.333333 21.333333 0 0 1-21.333333 21.333333zM512 874.666667a21.333333 21.333333 0 0 1-21.333333-21.333334v-128a21.333333 21.333333 0 0 1 42.666666 0v128a21.333333 21.333333 0 0 1-21.333333 21.333334z" /></svg>
|
||||
</div>
|
||||
<div class="control5">
|
||||
<i-select v-model="ptzPositionIndex" style="width: 100px">
|
||||
<Option v-for="n in 10" :value="n" :key="n">预置点{{n}}</Option>
|
||||
</i-select>
|
||||
<i-button type="primary" @click="ptzCmd(ptzType.setPos)">设置</i-button>
|
||||
<i-button type="success" @click="ptzCmd(ptzType.calPos)">调用</i-button>
|
||||
<i-button type="error" @click="ptzCmd(ptzType.delPos)">删除</i-button>
|
||||
速度:
|
||||
<InputNumber :max="10" :min="1" v-model="ptzSpeed"></InputNumber>
|
||||
</div>
|
||||
</div>
|
||||
<div slot="footer">
|
||||
<mu-badge v-if="remoteSDP">
|
||||
<a slot="content" :href="remoteSDPURL" download="remoteSDP.txt">remoteSDP</a>
|
||||
</mu-badge>
|
||||
<mu-badge v-if="localSDP">
|
||||
<a slot="content" :href="localSDPURL" download="localSDP.txt">localSDP</a>
|
||||
</mu-badge>
|
||||
</div>
|
||||
</Modal>
|
||||
</template>
|
||||
<script>
|
||||
import {PTZ_TYPE} from "../utils/ptz-cmd";
|
||||
const PTZ_DIRECTION_ARRAY = [PTZ_TYPE.up,PTZ_TYPE.right,PTZ_TYPE.down,PTZ_TYPE.left,PTZ_TYPE.leftUp,PTZ_TYPE.rightUp,PTZ_TYPE.leftDown,PTZ_TYPE.rightDown];
|
||||
let pc = null;
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
iceConnectionState: pc && pc.iceConnectionState,
|
||||
stream: null,
|
||||
localSDP: "",
|
||||
remoteSDP: "",
|
||||
remoteSDPURL: "",
|
||||
localSDPURL: "",
|
||||
streamPath: "",
|
||||
ptzSpeed:5,
|
||||
ptzPositionIndex:1,
|
||||
ptzType:PTZ_TYPE,
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
async play(streamPath) {
|
||||
pc = new RTCPeerConnection();
|
||||
pc.addTransceiver('video',{
|
||||
direction:'recvonly'
|
||||
})
|
||||
this.streamPath = streamPath;
|
||||
pc.onsignalingstatechange = e => {
|
||||
//console.log(e);
|
||||
};
|
||||
pc.oniceconnectionstatechange = e => {
|
||||
this.$toast.info(pc.iceConnectionState);
|
||||
this.iceConnectionState = pc.iceConnectionState;
|
||||
};
|
||||
pc.onicecandidate = event => {
|
||||
console.log(event)
|
||||
};
|
||||
pc.ontrack = event => {
|
||||
// console.log(event);
|
||||
if (event.track.kind == "video")
|
||||
this.stream = event.streams[0];
|
||||
};
|
||||
await pc.setLocalDescription(await pc.createOffer());
|
||||
this.localSDP = pc.localDescription.sdp;
|
||||
this.localSDPURL = URL.createObjectURL(
|
||||
new Blob([this.localSDP], { type: "text/plain" })
|
||||
);
|
||||
const result = await this.ajax({
|
||||
type: "POST",
|
||||
processData: false,
|
||||
data: JSON.stringify(pc.localDescription.toJSON()),
|
||||
url: "/webrtc/play?streamPath=" + this.streamPath,
|
||||
dataType: "json"
|
||||
});
|
||||
if (result.errmsg) {
|
||||
this.$toast.error(result.errmsg);
|
||||
return;
|
||||
} else {
|
||||
this.remoteSDP = result.sdp;
|
||||
this.remoteSDPURL = URL.createObjectURL(new Blob([this.remoteSDP], { type: "text/plain" }));
|
||||
}
|
||||
await pc.setRemoteDescription(new RTCSessionDescription(result));
|
||||
},
|
||||
ptzCmdDirection(direction){
|
||||
const type = PTZ_DIRECTION_ARRAY[direction-1];
|
||||
this.ptzCmd(type);
|
||||
},
|
||||
startPtzCmdCycle(){
|
||||
this.ptzCmd(PTZ_TYPE.right,true);
|
||||
},
|
||||
stopPtzCmdCycle(){
|
||||
this.ptzCmd(PTZ_TYPE.stop);
|
||||
},
|
||||
ptzCmd(type,isCycling){
|
||||
this.$emit('ptz',{type:type,speed:this.ptzSpeed,index:this.ptzPositionIndex,cycle:isCycling})
|
||||
},
|
||||
onClosePreview() {
|
||||
pc.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<style scoped>
|
||||
.arrow1{
|
||||
grid-column: 2;
|
||||
grid-row: 1;
|
||||
}
|
||||
.arrow2{
|
||||
transform: rotate(90deg);
|
||||
grid-column: 3;
|
||||
grid-row: 2;
|
||||
}
|
||||
.arrow3{
|
||||
transform: rotate(180deg);
|
||||
grid-column: 2;
|
||||
grid-row: 3;
|
||||
}
|
||||
.arrow4{
|
||||
transform: rotate(270deg);
|
||||
grid-column: 1;
|
||||
grid-row: 2;
|
||||
}
|
||||
|
||||
.arrow5{
|
||||
transform: rotate(-45deg);
|
||||
grid-column: 1;
|
||||
grid-row: 1;
|
||||
}
|
||||
|
||||
.arrow6{
|
||||
transform: rotate(45deg);
|
||||
grid-column: 3;
|
||||
grid-row: 1;
|
||||
}
|
||||
|
||||
.arrow7{
|
||||
transform: rotate(-135deg);
|
||||
grid-column: 1;
|
||||
grid-row: 3;
|
||||
}
|
||||
|
||||
.arrow8{
|
||||
transform: rotate(135deg);
|
||||
grid-column: 3;
|
||||
grid-row: 3;
|
||||
}
|
||||
|
||||
.arrow9{
|
||||
grid-column: 2;
|
||||
grid-row: 2;
|
||||
}
|
||||
|
||||
.container {
|
||||
position: relative;
|
||||
height: 350px;
|
||||
}
|
||||
.control {
|
||||
position: absolute;
|
||||
top: 20px;
|
||||
right: 0;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 33.33%);
|
||||
grid-template-rows: repeat(3, 33.33%);
|
||||
width: 192px;
|
||||
height: 192px;
|
||||
}
|
||||
|
||||
.control2{
|
||||
top: 210px;
|
||||
}
|
||||
|
||||
.control3{
|
||||
top: 260px;
|
||||
}
|
||||
|
||||
.control4{
|
||||
top: 310px;
|
||||
}
|
||||
|
||||
.control5{
|
||||
top: 360px;
|
||||
}
|
||||
|
||||
.control >* {
|
||||
cursor: pointer;
|
||||
fill: gray;
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
}
|
||||
|
||||
.control5 >*{
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.control2 >*,.control3 >*,.control4 >*{
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
.control >*:hover,.cycling{
|
||||
fill: cyan
|
||||
}
|
||||
|
||||
|
||||
|
||||
</style>
|
||||
@@ -1,111 +0,0 @@
|
||||
<template>
|
||||
<div class="player-wrap">
|
||||
<template v-if="rtcStream">
|
||||
<video :srcObject.prop="rtcStream" autoplay muted controls></video>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: "WebrtcPlayer",
|
||||
rtcPeerConnection: null,
|
||||
data() {
|
||||
return {
|
||||
iceConnectionState: '',
|
||||
rtcPeerConnectionInit: false,
|
||||
rtcStream: null
|
||||
}
|
||||
},
|
||||
props: {
|
||||
streamPath: {
|
||||
type: String,
|
||||
default: ''
|
||||
}
|
||||
},
|
||||
async created() {
|
||||
await this.initRtcPeerConnection();
|
||||
console.log('initRtcPeerConnectioned');
|
||||
if (this.streamPath) {
|
||||
await this.play(this.streamPath);
|
||||
console.log('played');
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async initRtcPeerConnection() {
|
||||
const rtcPeerConnection = new RTCPeerConnection();
|
||||
|
||||
rtcPeerConnection.addTransceiver('video', {
|
||||
direction: "recvonly"
|
||||
});
|
||||
|
||||
rtcPeerConnection.onsignalingstatechange = e => {
|
||||
console.log('onsignalingstatechange', e);
|
||||
};
|
||||
|
||||
rtcPeerConnection.oniceconnectionstatechange = e => {
|
||||
console.log('oniceconnectionstatechange', rtcPeerConnection.iceConnectionState);
|
||||
};
|
||||
|
||||
rtcPeerConnection.onicecandidate = event => {
|
||||
console.log('onicecandidate', event);
|
||||
};
|
||||
|
||||
rtcPeerConnection.ontrack = event => {
|
||||
console.log('ontrack', event);
|
||||
if (event.track.kind === "video") {
|
||||
this.rtcStream = event.streams[0];
|
||||
}
|
||||
};
|
||||
|
||||
const rtcSessionDescriptionInit = await rtcPeerConnection.createOffer();
|
||||
await rtcPeerConnection.setLocalDescription(rtcSessionDescriptionInit);
|
||||
this.rtcPeerConnectionInit = true;
|
||||
this.$options.rtcPeerConnection = rtcPeerConnection;
|
||||
},
|
||||
|
||||
//
|
||||
async play(streamPath) {
|
||||
const rtcPeerConnection = this.$options.rtcPeerConnection;
|
||||
const localDescriptionData = rtcPeerConnection.localDescription.toJSON();
|
||||
const result = await this.ajax({
|
||||
type: "POST",
|
||||
processData: false,
|
||||
data: JSON.stringify(localDescriptionData),
|
||||
url: "/webrtc/play?streamPath=" + streamPath,
|
||||
dataType: "json"
|
||||
});
|
||||
if (result.errmsg) {
|
||||
console.error(result.errmsg);
|
||||
return;
|
||||
}
|
||||
//
|
||||
rtcPeerConnection.setRemoteDescription(new RTCSessionDescription({
|
||||
type: result.type,
|
||||
sdp: result.sdp
|
||||
}));
|
||||
},
|
||||
close() {
|
||||
const rtcPeerConnection = this.$options.rtcPeerConnection;
|
||||
rtcPeerConnection && rtcPeerConnection.close();
|
||||
}
|
||||
},
|
||||
destroyed() {
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.player-wrap {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 4px;
|
||||
box-shadow: 0 0 5px #40d3fc, inset 0 0 5px #40d3fc, 0 0 0 1px #40d3fc;
|
||||
}
|
||||
|
||||
.player-wrap video {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -1,172 +0,0 @@
|
||||
<template>
|
||||
<Modal
|
||||
v-bind="$attrs"
|
||||
draggable
|
||||
width="900"
|
||||
v-on="$listeners"
|
||||
title="录像列表"
|
||||
@on-ok="$emit('close')"
|
||||
>
|
||||
<webrtc-player2
|
||||
v-if="channel && channel.RecordSP && player"
|
||||
:streamPath="channel.RecordSP"
|
||||
></webrtc-player2>
|
||||
<div class="container" v-else-if="!player">
|
||||
<div class="search">
|
||||
<DatePicker
|
||||
type="date"
|
||||
:options="timeOptions"
|
||||
:value="search.time"
|
||||
placeholder="请选择时间"
|
||||
style="width: 200px"
|
||||
:clearable="false"
|
||||
@on-change="handleTimeChange"
|
||||
></DatePicker>
|
||||
</div>
|
||||
<div>
|
||||
<mu-data-table :columns="columns" :data="recordList">
|
||||
<template #default="scope">
|
||||
<td>{{ scope.row.DeviceID }}</td>
|
||||
<td>{{ scope.row.Name }}</td>
|
||||
<td>{{ scope.row.startTime }}</td>
|
||||
<td>{{ scope.row.endTime }}</td>
|
||||
<td>{{ scope.row.length }}</td>
|
||||
<td>
|
||||
<m-button @click="play(scope.row)">播放</m-button>
|
||||
</td>
|
||||
</template>
|
||||
</mu-data-table>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else>正在连接,请稍后</div>
|
||||
<div slot="footer" v-if="player">
|
||||
<mu-button @click="back">返回</mu-button>
|
||||
</div>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getOneTimeRange, formatTimeTips, parseTime, isDef } from "../utils";
|
||||
import WebrtcPlayer2 from "./Player2";
|
||||
const _now = new Date();
|
||||
|
||||
export default {
|
||||
name: "Records",
|
||||
components: {
|
||||
WebrtcPlayer2,
|
||||
},
|
||||
props: ["search", "channel"],
|
||||
data() {
|
||||
return {
|
||||
player: false,
|
||||
timeOptions: {
|
||||
disabledDate(date) {
|
||||
return date && date.valueOf() > Date.now();
|
||||
},
|
||||
},
|
||||
columns: Object.freeze(
|
||||
["设备ID", "名称", "开始时间", "结束时间", "时长", "操作"].map(
|
||||
(title) => ({
|
||||
title,
|
||||
})
|
||||
)
|
||||
),
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
records() {
|
||||
return (this.channel && this.channel.Records) || [];
|
||||
},
|
||||
startTime() {
|
||||
if (!this.search.time) {
|
||||
return "";
|
||||
}
|
||||
const start = getOneTimeRange(this.search.time).start;
|
||||
const isoString = new Date(start).toISOString();
|
||||
return isoString.replace(".000Z", "");
|
||||
},
|
||||
endTime() {
|
||||
if (!this.search.time) {
|
||||
return "";
|
||||
}
|
||||
const end = getOneTimeRange(this.search.time).end;
|
||||
const isoString = new Date(end).toISOString();
|
||||
return isoString.replace(".000Z", "");
|
||||
},
|
||||
recordList() {
|
||||
const list = this.records.map((record) => {
|
||||
const startTime = new Date(record.StartTime).getTime();
|
||||
const endTime = new Date(record.EndTime).getTime();
|
||||
const timestamp = endTime - startTime;
|
||||
const timeLength = formatTimeTips(timestamp / 1000);
|
||||
|
||||
const _startTime = parseTime(startTime);
|
||||
const _endTime = parseTime(endTime);
|
||||
record._startTime = (startTime / 1000) >> 0;
|
||||
record._endTime = (endTime / 1000) >> 0;
|
||||
record.length = timeLength;
|
||||
record.startTime = _startTime;
|
||||
record.endTime = _endTime;
|
||||
return record;
|
||||
});
|
||||
return list;
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
this._fetchList();
|
||||
},
|
||||
methods: {
|
||||
_fetchList() {
|
||||
if (
|
||||
isDef(this.search.id) &&
|
||||
isDef(this.search.channel) &&
|
||||
this.startTime &&
|
||||
this.endTime
|
||||
) {
|
||||
const query = {
|
||||
id: this.search.id,
|
||||
channel: this.search.channel,
|
||||
startTime: this.startTime,
|
||||
endTime: this.endTime,
|
||||
};
|
||||
|
||||
this.ajax.get("/gb28181/query/records", query).then((x) => {});
|
||||
}
|
||||
},
|
||||
handleTimeChange(date) {
|
||||
this.search.time = new Date(date);
|
||||
this._fetchList();
|
||||
},
|
||||
play(record) {
|
||||
const query = {
|
||||
id: this.search.id,
|
||||
channel: this.search.channel,
|
||||
startTime: record._startTime,
|
||||
endTime: record._endTime,
|
||||
};
|
||||
|
||||
this.ajax.get("/gb28181/invite", query).then((x) => {});
|
||||
this.player = true;
|
||||
},
|
||||
back() {
|
||||
fetch("/api/stop?stream=" + this.streamPath);
|
||||
this.player = false;
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.container {
|
||||
position: relative;
|
||||
height: 500px;
|
||||
background-image: radial-gradient(#c52dd07a, #4a17987a, #0300137a);
|
||||
color: #ffffff;
|
||||
background-color: black;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.search {
|
||||
padding: 10px 0;
|
||||
}
|
||||
</style>
|
||||
@@ -1,125 +0,0 @@
|
||||
/**
|
||||
* Date:2020/12/24
|
||||
* Desc:
|
||||
*/
|
||||
|
||||
export function getOneTimeRange(time, options) {
|
||||
let date;
|
||||
|
||||
// 都为空的时候
|
||||
if (!time && !options) {
|
||||
date = new Date();
|
||||
} else if (Object.prototype.toString.call(time) !== '[object Date]' && time !== null && typeof time === 'object') {
|
||||
// time 为 options 参数。
|
||||
options = time;
|
||||
date = new Date();
|
||||
} else if (Object.prototype.toString.call(time) === '[object Date]') {
|
||||
// time 是时间格式
|
||||
date = time;
|
||||
} else {
|
||||
// time 是 int 格式。
|
||||
if (('' + time).length === 10) time = parseInt(time) * 1000;
|
||||
time = +time; // 转成int 型
|
||||
date = new Date(time);
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
|
||||
let result = {
|
||||
start: 0,
|
||||
end: 0
|
||||
};
|
||||
|
||||
let _startTime = new Date(date).setHours(options.startHour || 0, options.startMin || 0, 0, 0);
|
||||
let _endTime = new Date(date).setHours(options.endHour || 23, options.endMin || 59, 59, 0);
|
||||
result.start = new Date(_startTime).getTime();
|
||||
result.end = new Date(_endTime).getTime();
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
|
||||
export function formatTimestamp(t) {
|
||||
var d = 0,
|
||||
h = 0,
|
||||
m = 0,
|
||||
s = 0;
|
||||
if (t > 0) {
|
||||
d = Math.floor(t / 1000 / 3600 / 24)
|
||||
h = Math.floor(t / 1000 / 60 / 60 % 24)
|
||||
m = Math.floor(t / 1000 / 60 % 60)
|
||||
s = Math.floor(t / 1000 % 60)
|
||||
}
|
||||
|
||||
return `${d}天${h}时${m}分${s}秒`
|
||||
}
|
||||
|
||||
// 单位秒
|
||||
export function formatTimeTips(timestamp) {
|
||||
let result;
|
||||
|
||||
//
|
||||
if (timestamp > -1) {
|
||||
let hour = Math.floor(timestamp / 3600);
|
||||
let min = Math.floor(timestamp / 60) % 60;
|
||||
let sec = timestamp % 60;
|
||||
|
||||
sec = Math.round(sec);
|
||||
|
||||
if (hour < 10) {
|
||||
result = '0' + hour + ":";
|
||||
} else {
|
||||
result = hour + ":";
|
||||
}
|
||||
|
||||
if (min < 10) {
|
||||
result += "0";
|
||||
}
|
||||
result += min + ":";
|
||||
if (sec < 10) {
|
||||
result += "0";
|
||||
}
|
||||
result += sec.toFixed(0);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
export function parseTime(time, cFormat) {
|
||||
if (arguments.length === 0) {
|
||||
return null
|
||||
}
|
||||
var format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
|
||||
var date;
|
||||
if (typeof time === 'object') {
|
||||
date = time
|
||||
} else {
|
||||
if (('' + time).length === 10) time = parseInt(time) * 1000;
|
||||
time = +time; // 转成int 型
|
||||
date = new Date(time)
|
||||
}
|
||||
var formatObj = {
|
||||
y: date.getFullYear(),
|
||||
m: date.getMonth() + 1,
|
||||
d: date.getDate(),
|
||||
h: date.getHours(),
|
||||
i: date.getMinutes(),
|
||||
s: date.getSeconds(),
|
||||
a: date.getDay()
|
||||
};
|
||||
var time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
|
||||
var value = formatObj[key]
|
||||
if (key === 'a') return ['一', '二', '三', '四', '五', '六', '日'][value - 1]
|
||||
if (result.length > 0 && value < 10) {
|
||||
value = '0' + value
|
||||
}
|
||||
return value || 0
|
||||
});
|
||||
return time_str
|
||||
}
|
||||
|
||||
|
||||
export function isDef(v) {
|
||||
return v !== undefined && v !== null;
|
||||
}
|
||||
@@ -1,172 +0,0 @@
|
||||
/**
|
||||
* Date:2020/11/9
|
||||
* Desc:
|
||||
*/
|
||||
/**
|
||||
* Date:2020/11/2
|
||||
* Desc: ptz cmd 封装
|
||||
* cmd[0] //首字节以05H开头
|
||||
* cmd[1] //组合码,高4位为版本信息v1.0,版本信息0H,低四位为校验码
|
||||
* // 校验码 = (cmd[0]的高4位+cmd[0]的低4位+cmd[1]的高4位)%16
|
||||
* cmd[2] //地址的低8位???什么地址,地址范围000h ~ FFFh(0~4095),其中000h为广播地址
|
||||
* cmd[3] //指令码
|
||||
* cmd[4] //数据1,水平控制速度、聚焦速度
|
||||
* cmd[5] //数据2,垂直控制速度、光圈速度
|
||||
* cmd[6] // 高4位为数据3=变倍控制速度,低4位为地址高4位
|
||||
*/
|
||||
|
||||
const PTZ_TYPE = {
|
||||
stop: 'stop',
|
||||
right: 'right',
|
||||
left: 'left',
|
||||
up: 'up',
|
||||
down: 'down',
|
||||
leftUp: 'leftUp',
|
||||
leftDown: 'leftDown',
|
||||
rightUp: 'rightUp',
|
||||
rightDown: 'rightDown',
|
||||
zoomFar: 'zoomFar',
|
||||
zoomNear: 'zoomNear',
|
||||
apertureFar: 'apertureFar',
|
||||
apertureNear: 'apertureNear',
|
||||
focusFar: 'focusFar',
|
||||
focusNear: 'focusNear',
|
||||
setPos: 'setPos',
|
||||
calPos: 'calPos',
|
||||
delPos: 'delPos'
|
||||
};
|
||||
|
||||
const PTZ_CMD_TYPE = {
|
||||
stop: 0x00,
|
||||
|
||||
right: 0x01,
|
||||
left: 0x02,
|
||||
up: 0x08,
|
||||
down: 0x04,
|
||||
|
||||
leftUp: 0x0A,
|
||||
leftDown: 0x06,
|
||||
rightUp: 0x09,
|
||||
rightDown: 0x05,
|
||||
|
||||
zoomFar: 0x10, // 镜头 放大
|
||||
zoomNear: 0x20, // 镜头 缩小
|
||||
|
||||
apertureFar: 0x48, // 光圈 缩小
|
||||
apertureNear: 0x44, // 光圈 放大
|
||||
|
||||
focusFar: 0x42, // 聚焦 近
|
||||
focusNear: 0x41, // 聚焦 远
|
||||
|
||||
setPos: 0x81,
|
||||
calPos: 0x82,
|
||||
delPos: 0x83
|
||||
};
|
||||
|
||||
const SPEED_ARRAY = [0x19, 0x32, 0x4b, 0x64, 0x7d, 0x96, 0xAF, 0xC8, 0xE1, 0xFA];
|
||||
const POSITION_ARRAY = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10];
|
||||
|
||||
// 获取 direction 方向型
|
||||
/**
|
||||
*
|
||||
* @param options
|
||||
* type:
|
||||
* speed:default 5
|
||||
* index:
|
||||
* @returns {string}
|
||||
*/
|
||||
function getPTZCmd(options) {
|
||||
const {type, speed, index} = options;
|
||||
const ptzSpeed = getPTZSpeed(speed);
|
||||
let indexValue3, indexValue4, indexValue5, indexValue6;
|
||||
indexValue3 = PTZ_CMD_TYPE[type];
|
||||
switch (type) {
|
||||
case PTZ_TYPE.up:
|
||||
case PTZ_TYPE.down:
|
||||
case PTZ_TYPE.apertureFar:
|
||||
case PTZ_TYPE.apertureNear:
|
||||
indexValue5 = ptzSpeed;
|
||||
break;
|
||||
case PTZ_TYPE.right:
|
||||
case PTZ_TYPE.left:
|
||||
case PTZ_TYPE.focusFar:
|
||||
case PTZ_TYPE.focusNear:
|
||||
indexValue4 = ptzSpeed;
|
||||
break;
|
||||
case PTZ_TYPE.leftUp:
|
||||
case PTZ_TYPE.leftDown:
|
||||
case PTZ_TYPE.rightUp:
|
||||
case PTZ_TYPE.rightDown:
|
||||
indexValue4 = ptzSpeed;
|
||||
indexValue5 = ptzSpeed;
|
||||
break;
|
||||
case PTZ_TYPE.zoomFar:
|
||||
case PTZ_TYPE.zoomNear:
|
||||
indexValue6 = 0x10;
|
||||
break;
|
||||
case PTZ_TYPE.calPos:
|
||||
case PTZ_TYPE.delPos:
|
||||
case PTZ_TYPE.setPos:
|
||||
indexValue5 = getPTZPositionIndex(index);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ptzCmdToString(indexValue3, indexValue4, indexValue5, indexValue6);
|
||||
}
|
||||
|
||||
function getPTZSpeed(speed) {
|
||||
speed = speed || 5;
|
||||
const speedIndex = speed - 1;
|
||||
const ptzSpeed = SPEED_ARRAY[speedIndex] || SPEED_ARRAY[4];
|
||||
return ptzSpeed;
|
||||
}
|
||||
|
||||
function getPTZPositionIndex(index) {
|
||||
return POSITION_ARRAY[index - 1];
|
||||
}
|
||||
|
||||
function ptzCmdToString(indexValue3, indexValue4, indexValue5, indexValue6) {
|
||||
//
|
||||
let cmd = Buffer.alloc(8);
|
||||
// 首字节以05H开头
|
||||
cmd[0] = 0xA5;
|
||||
// 组合码,高4位为版本信息v1.0,版本信息0H,低四位为校验码
|
||||
cmd[1] = 0x0F;
|
||||
// 校验码 = (cmd[0]的高4位+cmd[0]的低4位+cmd[1]的高4位)%16
|
||||
cmd[2] = 0x01;
|
||||
//
|
||||
if (indexValue3) {
|
||||
cmd[3] = indexValue3;
|
||||
}
|
||||
if (indexValue4) {
|
||||
cmd[4] = indexValue4;
|
||||
}
|
||||
if (indexValue5) {
|
||||
cmd[5] = indexValue5;
|
||||
}
|
||||
if (indexValue6) {
|
||||
cmd[6] = indexValue6;
|
||||
}
|
||||
|
||||
cmd[7] = (cmd[0] + cmd[1] + cmd[2] + cmd[3] + cmd[4] + cmd[5] + cmd[6]) % 256;
|
||||
|
||||
return bytes2HexString(cmd);
|
||||
}
|
||||
|
||||
function bytes2HexString(byte) {
|
||||
let hexs = "";
|
||||
for (let i = 0; i < byte.length; i++) {
|
||||
let hex = (byte[i]).toString(16);
|
||||
if (hex.length === 1) {
|
||||
hex = '0' + hex;
|
||||
}
|
||||
hexs += hex.toUpperCase();
|
||||
}
|
||||
return hexs;
|
||||
}
|
||||
|
||||
export {
|
||||
getPTZCmd,
|
||||
PTZ_TYPE
|
||||
}
|
||||
6793
ui/yarn.lock
6793
ui/yarn.lock
File diff suppressed because it is too large
Load Diff
100
utils/buffer.go
Normal file
100
utils/buffer.go
Normal file
@@ -0,0 +1,100 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"io"
|
||||
)
|
||||
|
||||
type IOBuffer struct {
|
||||
buf []byte // contents are the bytes buf[off : len(buf)]
|
||||
off int // read at &buf[off], write at &buf[len(buf)]
|
||||
}
|
||||
|
||||
func (b *IOBuffer) Next(n int) []byte {
|
||||
m := b.Len()
|
||||
if n > m {
|
||||
n = m
|
||||
}
|
||||
data := b.buf[b.off : b.off+n]
|
||||
b.off += n
|
||||
return data
|
||||
}
|
||||
func (b *IOBuffer) Uint16() (uint16, error) {
|
||||
if b.Len() > 1 {
|
||||
|
||||
return binary.BigEndian.Uint16(b.Next(2)), nil
|
||||
}
|
||||
return 0, io.EOF
|
||||
}
|
||||
|
||||
func (b *IOBuffer) Skip(n int) (err error) {
|
||||
_, err = b.ReadN(n)
|
||||
return
|
||||
}
|
||||
|
||||
func (b *IOBuffer) Uint32() (uint32, error) {
|
||||
if b.Len() > 3 {
|
||||
return binary.BigEndian.Uint32(b.Next(4)), nil
|
||||
}
|
||||
return 0, io.EOF
|
||||
}
|
||||
|
||||
func (b *IOBuffer) ReadN(length int) ([]byte, error) {
|
||||
if b.Len() >= length {
|
||||
return b.Next(length), nil
|
||||
}
|
||||
return nil, io.EOF
|
||||
}
|
||||
|
||||
// empty reports whether the unread portion of the buffer is empty.
|
||||
func (b *IOBuffer) empty() bool { return b.Len() <= b.off }
|
||||
|
||||
func (b *IOBuffer) ReadByte() (byte, error) {
|
||||
if b.empty() {
|
||||
// Buffer is empty, reset to recover space.
|
||||
b.Reset()
|
||||
return 0, io.EOF
|
||||
}
|
||||
c := b.buf[b.off]
|
||||
b.off++
|
||||
return c, nil
|
||||
}
|
||||
func (b *IOBuffer) Reset() {
|
||||
b.buf = b.buf[:0]
|
||||
b.off = 0
|
||||
}
|
||||
|
||||
func (b *IOBuffer) Len() int { return len(b.buf) - b.off }
|
||||
|
||||
// tryGrowByReslice is a inlineable version of grow for the fast-case where the
|
||||
// internal buffer only needs to be resliced.
|
||||
// It returns the index where bytes should be written and whether it succeeded.
|
||||
func (b *IOBuffer) tryGrowByReslice(n int) (int, bool) {
|
||||
if l := len(b.buf); n <= cap(b.buf)-l {
|
||||
b.buf = b.buf[:l+n]
|
||||
return l, true
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
|
||||
var ErrTooLarge = errors.New("bytes.Buffer: too large")
|
||||
|
||||
func (b *IOBuffer) Write(p []byte) (n int, err error) {
|
||||
defer func() {
|
||||
if recover() != nil {
|
||||
panic(ErrTooLarge)
|
||||
}
|
||||
}()
|
||||
l := len(p)
|
||||
oldLen := len(b.buf)
|
||||
m, ok := b.tryGrowByReslice(l)
|
||||
if !ok {
|
||||
buf := make([]byte, oldLen+l)
|
||||
copy(buf, b.buf[b.off:])
|
||||
m = oldLen - b.off
|
||||
b.off = 0
|
||||
b.buf = buf
|
||||
}
|
||||
return copy(b.buf[m:], p), nil
|
||||
}
|
||||
320
utils/ps.go
Normal file
320
utils/ps.go
Normal file
@@ -0,0 +1,320 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/Monibuca/utils/v3"
|
||||
)
|
||||
|
||||
//
|
||||
const (
|
||||
UDPTransfer int = 0
|
||||
TCPTransferActive int = 1
|
||||
TCPTransferPassive int = 2
|
||||
LocalCache int = 3
|
||||
|
||||
StreamTypeH264 = 0x1b
|
||||
StreamTypeH265 = 0x24
|
||||
G711A = 0x90 //PCMA
|
||||
G7221AUDIOTYPE = 0x92
|
||||
G7231AUDIOTYPE = 0x93
|
||||
G729AUDIOTYPE = 0x99
|
||||
|
||||
StreamIDVideo = 0xe0
|
||||
StreamIDAudio = 0xc0
|
||||
|
||||
StartCodePS = 0x000001ba
|
||||
StartCodeSYS = 0x000001bb
|
||||
StartCodeMAP = 0x000001bc
|
||||
StartCodeVideo = 0x000001e0
|
||||
StartCodeAudio = 0x000001c0
|
||||
HaiKangCode = 0x000001bd
|
||||
MEPGProgramEndCode = 0x000001b9
|
||||
|
||||
RTPHeaderLength int = 12
|
||||
PSHeaderLength int = 14
|
||||
SystemHeaderLength int = 18
|
||||
MAPHeaderLength int = 24
|
||||
PESHeaderLength int = 19
|
||||
RtpLoadLength int = 1460
|
||||
PESLoadLength int = 0xFFFF
|
||||
MAXFrameLen int = 1024 * 1024 * 2
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNotFoundStartCode = errors.New("not found the need start code flag")
|
||||
ErrMarkerBit = errors.New("marker bit value error")
|
||||
ErrFormatPack = errors.New("not package standard")
|
||||
ErrParsePakcet = errors.New("parse ps packet error")
|
||||
)
|
||||
|
||||
type Pusher interface {
|
||||
PushVideo(uint32, uint32, []byte)
|
||||
PushAudio(uint32, []byte)
|
||||
}
|
||||
|
||||
/*
|
||||
This implement from VLC source code
|
||||
notes: https://github.com/videolan/vlc/blob/master/modules/mux/mpeg/bits.h
|
||||
*/
|
||||
|
||||
//bitsBuffer bits buffer
|
||||
// type bitsBuffer struct {
|
||||
// iSize int
|
||||
// iData int
|
||||
// iMask uint8
|
||||
// pData []byte
|
||||
// }
|
||||
|
||||
// func bitsInit(isize int, buffer []byte) *bitsBuffer {
|
||||
|
||||
// bits := &bitsBuffer{
|
||||
// iSize: isize,
|
||||
// iData: 0,
|
||||
// iMask: 0x80,
|
||||
// pData: buffer,
|
||||
// }
|
||||
// if bits.pData == nil {
|
||||
// bits.pData = make([]byte, isize)
|
||||
// }
|
||||
// return bits
|
||||
// }
|
||||
|
||||
// func bitsAlign(bits *bitsBuffer) {
|
||||
|
||||
// if bits.iMask != 0x80 && bits.iData < bits.iSize {
|
||||
// bits.iMask = 0x80
|
||||
// bits.iData++
|
||||
// bits.pData[bits.iData] = 0x00
|
||||
// }
|
||||
// }
|
||||
// func bitsWrite(bits *bitsBuffer, count int, src uint64) *bitsBuffer {
|
||||
|
||||
// for count > 0 {
|
||||
// count--
|
||||
// if ((src >> uint(count)) & 0x01) != 0 {
|
||||
// bits.pData[bits.iData] |= bits.iMask
|
||||
// } else {
|
||||
// bits.pData[bits.iData] &= ^bits.iMask
|
||||
// }
|
||||
// bits.iMask >>= 1
|
||||
// if bits.iMask == 0 {
|
||||
// bits.iData++
|
||||
// bits.iMask = 0x80
|
||||
// }
|
||||
// }
|
||||
|
||||
// return bits
|
||||
// }
|
||||
|
||||
/*
|
||||
https://github.com/videolan/vlc/blob/master/modules/demux/mpeg
|
||||
*/
|
||||
type DecPSPackage struct {
|
||||
systemClockReferenceBase uint64
|
||||
systemClockReferenceExtension uint64
|
||||
programMuxRate uint32
|
||||
|
||||
VideoStreamType uint32
|
||||
AudioStreamType uint32
|
||||
IOBuffer
|
||||
Payload []byte
|
||||
PTS uint32
|
||||
DTS uint32
|
||||
}
|
||||
|
||||
func (dec *DecPSPackage) clean() {
|
||||
dec.systemClockReferenceBase = 0
|
||||
dec.systemClockReferenceExtension = 0
|
||||
dec.programMuxRate = 0
|
||||
dec.Payload = nil
|
||||
dec.PTS = 0
|
||||
dec.DTS = 0
|
||||
}
|
||||
|
||||
func (dec *DecPSPackage) ReadPayload() (payload []byte, err error) {
|
||||
payloadlen, err := dec.Uint16()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return dec.ReadN(int(payloadlen))
|
||||
}
|
||||
|
||||
func (dec *DecPSPackage) Read(ts uint32, pusher Pusher) error {
|
||||
var nextStartCode uint32
|
||||
dec.clean()
|
||||
|
||||
if err := dec.Skip(9); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
psl, err := dec.ReadByte()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
psl &= 0x07
|
||||
if err = dec.Skip(int(psl)); err != nil {
|
||||
return err
|
||||
}
|
||||
var video []byte
|
||||
var videoTs, videoCts uint32
|
||||
defer func() {
|
||||
if video != nil {
|
||||
pusher.PushVideo(videoTs, videoCts, video)
|
||||
video = nil
|
||||
}
|
||||
if nextStartCode == StartCodePS {
|
||||
err = dec.Read(ts, pusher)
|
||||
}
|
||||
}()
|
||||
for err == nil {
|
||||
nextStartCode, err = dec.Uint32()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch nextStartCode {
|
||||
case StartCodeSYS:
|
||||
dec.ReadPayload()
|
||||
//err = dec.decSystemHeader()
|
||||
case StartCodeMAP:
|
||||
err = dec.decProgramStreamMap()
|
||||
case StartCodeVideo:
|
||||
var cts uint32
|
||||
if err = dec.decPESPacket(); err == nil {
|
||||
if video == nil {
|
||||
if dec.PTS == 0 {
|
||||
dec.PTS = ts
|
||||
}
|
||||
if dec.DTS != 0 {
|
||||
cts = dec.PTS - dec.DTS
|
||||
} else {
|
||||
dec.DTS = dec.PTS
|
||||
}
|
||||
videoTs = dec.DTS / 90
|
||||
videoCts = cts / 90
|
||||
}
|
||||
video = append(video, dec.Payload...)
|
||||
} else {
|
||||
utils.Println("video", err)
|
||||
}
|
||||
case StartCodeAudio:
|
||||
if err = dec.decPESPacket(); err == nil {
|
||||
var payload []byte
|
||||
ts := ts / 90
|
||||
if dec.PTS != 0 {
|
||||
ts = dec.PTS / 90
|
||||
}
|
||||
pusher.PushAudio(ts, append(payload, dec.Payload...))
|
||||
} else {
|
||||
utils.Println("audio", err)
|
||||
}
|
||||
case StartCodePS:
|
||||
return nil
|
||||
default:
|
||||
dec.ReadPayload()
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
/*
|
||||
func (dec *DecPSPackage) decSystemHeader() error {
|
||||
syslens, err := dec.Uint16()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// drop rate video audio bound and lock flag
|
||||
syslens -= 6
|
||||
if err = dec.Skip(6); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// ONE WAY: do not to parse the stream and skip the buffer
|
||||
//br.Skip(syslen * 8)
|
||||
|
||||
// TWO WAY: parse every stream info
|
||||
for syslens > 0 {
|
||||
if nextbits, err := dec.Uint8(); err != nil {
|
||||
return err
|
||||
} else if (nextbits&0x80)>>7 != 1 {
|
||||
break
|
||||
}
|
||||
if err = dec.Skip(2); err != nil {
|
||||
return err
|
||||
}
|
||||
syslens -= 3
|
||||
}
|
||||
return nil
|
||||
}
|
||||
*/
|
||||
func (dec *DecPSPackage) decProgramStreamMap() error {
|
||||
psm, err := dec.ReadPayload()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
l := len(psm)
|
||||
index := 2
|
||||
programStreamInfoLen := utils.BigEndian.Uint16(psm[index:])
|
||||
index += 2
|
||||
index += int(programStreamInfoLen)
|
||||
programStreamMapLen := utils.BigEndian.Uint16(psm[index:])
|
||||
index += 2
|
||||
for programStreamMapLen > 0 {
|
||||
if l <= index+1 {
|
||||
break
|
||||
}
|
||||
streamType := psm[index]
|
||||
index++
|
||||
elementaryStreamID := psm[index]
|
||||
index++
|
||||
if elementaryStreamID >= 0xe0 && elementaryStreamID <= 0xef {
|
||||
dec.VideoStreamType = uint32(streamType)
|
||||
} else if elementaryStreamID >= 0xc0 && elementaryStreamID <= 0xdf {
|
||||
dec.AudioStreamType = uint32(streamType)
|
||||
}
|
||||
if l <= index+1 {
|
||||
break
|
||||
}
|
||||
elementaryStreamInfoLength := utils.BigEndian.Uint16(psm[index:])
|
||||
index += 2
|
||||
index += int(elementaryStreamInfoLength)
|
||||
programStreamMapLen -= 4 + elementaryStreamInfoLength
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dec *DecPSPackage) decPESPacket() error {
|
||||
payload, err := dec.ReadPayload()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(payload) < 4 {
|
||||
return errors.New("not enough data")
|
||||
}
|
||||
//data_alignment_indicator := (payload[0]&0b0001_0000)>>4 == 1
|
||||
flag := payload[1]
|
||||
ptsFlag := flag>>7 == 1
|
||||
dtsFlag := (flag&0b0100_0000)>>6 == 1
|
||||
var pts, dts uint32
|
||||
pesHeaderDataLen := payload[2]
|
||||
payload = payload[3:]
|
||||
extraData := payload[:pesHeaderDataLen]
|
||||
if ptsFlag && len(extraData) > 4 {
|
||||
pts = uint32(extraData[0]&0b0000_1110) << 29
|
||||
pts += uint32(extraData[1]) << 22
|
||||
pts += uint32(extraData[2]&0b1111_1110) << 14
|
||||
pts += uint32(extraData[3]) << 7
|
||||
pts += uint32(extraData[4]) >> 1
|
||||
if dtsFlag && len(extraData) > 9 {
|
||||
dts = uint32(extraData[5]&0b0000_1110) << 29
|
||||
dts += uint32(extraData[6]) << 22
|
||||
dts += uint32(extraData[7]&0b1111_1110) << 14
|
||||
dts += uint32(extraData[8]) << 7
|
||||
dts += uint32(extraData[9]) >> 1
|
||||
}
|
||||
}
|
||||
dec.PTS = pts
|
||||
dec.DTS = dts
|
||||
dec.Payload = payload[pesHeaderDataLen:]
|
||||
return err
|
||||
}
|
||||
97
utils/rtp_sort.go
Executable file
97
utils/rtp_sort.go
Executable file
@@ -0,0 +1,97 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"container/heap"
|
||||
"errors"
|
||||
"github.com/pion/rtp"
|
||||
)
|
||||
|
||||
const MaxRtpDiff = 65000 //相邻两个包之间的最大差值
|
||||
|
||||
type PriorityQueueRtp struct {
|
||||
itemHeap *packets
|
||||
current *rtp.Packet
|
||||
priorityMap map[uint16]bool
|
||||
lastPacket *rtp.Packet
|
||||
}
|
||||
|
||||
func NewPqRtp() *PriorityQueueRtp {
|
||||
return &PriorityQueueRtp{
|
||||
itemHeap: &packets{},
|
||||
priorityMap: make(map[uint16]bool),
|
||||
}
|
||||
}
|
||||
|
||||
func (p *PriorityQueueRtp) Len() int {
|
||||
return p.itemHeap.Len()
|
||||
}
|
||||
|
||||
func (p *PriorityQueueRtp) Push(v rtp.Packet) {
|
||||
if p.priorityMap[v.SequenceNumber] {
|
||||
return
|
||||
}
|
||||
newItem := &packet{
|
||||
value: v,
|
||||
priority: v.SequenceNumber,
|
||||
}
|
||||
heap.Push(p.itemHeap, newItem)
|
||||
}
|
||||
|
||||
func (p *PriorityQueueRtp) Pop() (rtp.Packet, error) {
|
||||
if len(*p.itemHeap) == 0 {
|
||||
return rtp.Packet{}, errors.New("empty queue")
|
||||
}
|
||||
|
||||
item := heap.Pop(p.itemHeap).(*packet)
|
||||
return item.value, nil
|
||||
}
|
||||
|
||||
func (p *PriorityQueueRtp) Empty() {
|
||||
old := *p.itemHeap
|
||||
*p.itemHeap = old[:0]
|
||||
}
|
||||
|
||||
type packets []*packet
|
||||
|
||||
type packet struct {
|
||||
value rtp.Packet
|
||||
priority uint16
|
||||
index int
|
||||
}
|
||||
|
||||
func (p *packets) Len() int {
|
||||
return len(*p)
|
||||
}
|
||||
|
||||
func (p *packets) Less(i, j int) bool {
|
||||
a, b := (*p)[i].priority, (*p)[j].priority
|
||||
if int(a)-int(b) > MaxRtpDiff || int(b)-int(a) > MaxRtpDiff {
|
||||
if a < b {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
return a < b
|
||||
}
|
||||
|
||||
func (p *packets) Swap(i, j int) {
|
||||
(*p)[i], (*p)[j] = (*p)[j], (*p)[i]
|
||||
(*p)[i].index = i
|
||||
(*p)[j].index = j
|
||||
}
|
||||
|
||||
func (p *packets) Push(x interface{}) {
|
||||
it := x.(*packet)
|
||||
it.index = len(*p)
|
||||
*p = append(*p, it)
|
||||
}
|
||||
|
||||
func (p *packets) Pop() interface{} {
|
||||
old := *p
|
||||
n := len(old)
|
||||
item := old[n-1]
|
||||
old[n-1] = nil // avoid memory leak
|
||||
item.index = -1 // for safety
|
||||
*p = old[0 : n-1]
|
||||
return item
|
||||
}
|
||||
@@ -1,6 +1,14 @@
|
||||
package utils
|
||||
|
||||
import "encoding/json"
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
"golang.org/x/net/html/charset"
|
||||
"golang.org/x/text/encoding/simplifiedchinese"
|
||||
"golang.org/x/text/transform"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func ToJSONString(v interface{}) string {
|
||||
b, _ := json.Marshal(v)
|
||||
@@ -11,3 +19,23 @@ func ToPrettyString(v interface{}) string {
|
||||
b, _ := json.MarshalIndent(v, "", " ")
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func GbkToUtf8(s []byte) ([]byte, error) {
|
||||
reader := transform.NewReader(bytes.NewReader(s), simplifiedchinese.GBK.NewDecoder())
|
||||
d, e := ioutil.ReadAll(reader)
|
||||
if e != nil {
|
||||
return s, e
|
||||
}
|
||||
return d, nil
|
||||
}
|
||||
|
||||
func DecodeGbk(v interface{}, body []byte) error {
|
||||
bodyBytes, err := GbkToUtf8(body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
decoder := xml.NewDecoder(bytes.NewReader(bodyBytes))
|
||||
decoder.CharsetReader = charset.NewReaderLabel
|
||||
err = decoder.Decode(v)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user