pax_global_header 0000666 0000000 0000000 00000000064 14545740134 0014521 g ustar 00root root 0000000 0000000 52 comment=875963dd9ce5dee1adbe30751692bc6d255864e0
golang-github-korandiz-v4l-1.1.0/ 0000775 0000000 0000000 00000000000 14545740134 0016571 5 ustar 00root root 0000000 0000000 golang-github-korandiz-v4l-1.1.0/LICENSE.txt 0000664 0000000 0000000 00000104513 14545740134 0020420 0 ustar 00root root 0000000 0000000 GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is 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. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
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.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
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 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. Use with the GNU Affero General Public License.
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 Affero 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 special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU 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 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 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 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.
Copyright (C)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
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 GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
golang-github-korandiz-v4l-1.1.0/README 0000664 0000000 0000000 00000000053 14545740134 0017447 0 ustar 00root root 0000000 0000000 https://pkg.go.dev/github.com/korandiz/v4l
golang-github-korandiz-v4l-1.1.0/arch_386.go 0000664 0000000 0000000 00000012340 14545740134 0020435 0 ustar 00root root 0000000 0000000 //go:build linux && 386
// +build linux,386
/////////////////////////////////////////////////////
// //
// !!! THIS IS A GENERATED FILE, DO NOT EDIT !!! //
// //
/////////////////////////////////////////////////////
package v4l
const (
vidioc_querycap = 0x80685600
vidioc_gFmt = 0xc0cc5604
vidioc_sFmt = 0xc0cc5605
vidioc_gParm = 0xc0cc5615
vidioc_sParm = 0xc0cc5616
vidioc_reqbufs = 0xc0145608
vidioc_querybuf = 0xc0445609
vidioc_qbuf = 0xc044560f
vidioc_dqbuf = 0xc0445611
vidioc_streamon = 0x40045612
vidioc_streamoff = 0x40045613
vidioc_cropcap = 0xc02c563a
vidioc_sCrop = 0x4014563c
vidioc_enumstd = 0xc0405619
vidioc_enumFmt = 0xc0405602
vidioc_enumFramesizes = 0xc02c564a
vidioc_enumFrameintervals = 0xc034564b
vidioc_queryctrl = 0xc0445624
vidioc_querymenu = 0xc02c5625
vidioc_gCtrl = 0xc008561b
vidioc_sCtrl = 0xc008561c
)
const (
size_capability = 104
size_format = 204
size_streamparm = 204
size_requestbuffers = 20
size_buffer = 68
size_int = 4
size_cropcap = 44
size_crop = 20
size_standard = 64
size_fmtdesc = 64
size_frmsizeenum = 44
size_frmivalenum = 52
size_queryctrl = 68
size_querymenu = 44
size_control = 8
)
const (
offs_capability_driver = 0
size_capability_driver = 16
offs_capability_card = 16
size_capability_card = 32
offs_capability_busInfo = 48
size_capability_busInfo = 32
offs_capability_version = 80
offs_capability_capabilities = 84
offs_capability_deviceCaps = 88
)
const (
offs_format_typ = 0
offs_format_fmt = 4
)
const (
offs_pixFormat_width = 0
offs_pixFormat_height = 4
offs_pixFormat_pixelformat = 8
offs_pixFormat_field = 12
offs_pixFormat_bytesperline = 16
offs_pixFormat_sizeimage = 20
offs_pixFormat_colorspace = 24
offs_pixFormat_priv = 28
offs_pixFormat_flags = 32
offs_pixFormat_ycbcrEnc = 36
offs_pixFormat_quantization = 40
offs_pixFormat_xferFunc = 44
)
const (
offs_streamparm_typ = 0
offs_streamparm_parm = 4
)
const (
offs_captureparm_capability = 0
offs_captureparm_capturemode = 4
offs_captureparm_timeperframe = 8
offs_captureparm_extendedmode = 16
offs_captureparm_readbuffers = 20
)
const (
offs_requestbuffers_count = 0
offs_requestbuffers_typ = 4
offs_requestbuffers_memory = 8
)
const (
offs_buffer_index = 0
offs_buffer_typ = 4
offs_buffer_bytesused = 8
offs_buffer_flags = 12
offs_buffer_field = 16
offs_buffer_timecode = 28
offs_buffer_sequence = 44
offs_buffer_memory = 48
offs_buffer_offset = 52
offs_buffer_length = 56
)
const (
offs_cropcap_typ = 0
offs_cropcap_bounds = 4
offs_cropcap_defrect = 20
offs_cropcap_pixelaspect = 36
)
const (
offs_crop_typ = 0
offs_crop_c = 4
)
const (
offs_fract_numerator = 0
offs_fract_denominator = 4
)
const (
offs_timecode_typ = 0
offs_timecode_flags = 4
offs_timecode_frames = 8
offs_timecode_seconds = 9
offs_timecode_minutes = 10
offs_timecode_hours = 11
offs_timecode_userbits = 12
)
const (
offs_rect_left = 0
offs_rect_top = 4
offs_rect_width = 8
offs_rect_height = 12
)
const (
offs_standard_index = 0
offs_standard_id = 4
offs_standard_name = 12
size_standard_name = 24
offs_standard_frameperiod = 36
offs_standard_framelines = 44
)
const (
offs_fmtdesc_index = 0
offs_fmtdesc_typ = 4
offs_fmtdesc_flags = 8
offs_fmtdesc_description = 12
size_fmtdesc_description = 32
offs_fmtdesc_pixelformat = 44
)
const (
offs_frmsizeenum_index = 0
offs_frmsizeenum_pixelFormat = 4
offs_frmsizeenum_typ = 8
offs_frmsizeenum_discrete = 12
offs_frmsizeenum_stepwise = 12
)
const (
offs_frmsizeDiscrete_width = 0
offs_frmsizeDiscrete_height = 4
)
const (
offs_frmsizeStepwise_minWidth = 0
offs_frmsizeStepwise_maxWidth = 4
offs_frmsizeStepwise_stepWidth = 8
offs_frmsizeStepwise_minHeight = 12
offs_frmsizeStepwise_maxHeight = 16
offs_frmsizeStepwise_stepHeight = 20
)
const (
offs_frmivalenum_index = 0
offs_frmivalenum_pixelFormat = 4
offs_frmivalenum_width = 8
offs_frmivalenum_height = 12
offs_frmivalenum_typ = 16
offs_frmivalenum_discrete = 20
offs_frmivalenum_stepwise = 20
)
const (
offs_frmivalStepwise_min = 0
offs_frmivalStepwise_max = 8
offs_frmivalStepwise_step = 16
)
const (
offs_queryctrl_id = 0
offs_queryctrl_typ = 4
offs_queryctrl_name = 8
size_queryctrl_name = 32
offs_queryctrl_minimum = 40
offs_queryctrl_maximum = 44
offs_queryctrl_step = 48
offs_queryctrl_defaultValue = 52
offs_queryctrl_flags = 56
)
const (
offs_querymenu_id = 0
offs_querymenu_index = 4
offs_querymenu_name = 8
size_querymenu_name = 32
offs_querymenu_value = 8
)
const (
offs_control_id = 0
offs_control_value = 4
)
golang-github-korandiz-v4l-1.1.0/arch_amd64.go 0000664 0000000 0000000 00000012344 14545740134 0021034 0 ustar 00root root 0000000 0000000 //go:build linux && amd64
// +build linux,amd64
/////////////////////////////////////////////////////
// //
// !!! THIS IS A GENERATED FILE, DO NOT EDIT !!! //
// //
/////////////////////////////////////////////////////
package v4l
const (
vidioc_querycap = 0x80685600
vidioc_gFmt = 0xc0d05604
vidioc_sFmt = 0xc0d05605
vidioc_gParm = 0xc0cc5615
vidioc_sParm = 0xc0cc5616
vidioc_reqbufs = 0xc0145608
vidioc_querybuf = 0xc0585609
vidioc_qbuf = 0xc058560f
vidioc_dqbuf = 0xc0585611
vidioc_streamon = 0x40045612
vidioc_streamoff = 0x40045613
vidioc_cropcap = 0xc02c563a
vidioc_sCrop = 0x4014563c
vidioc_enumstd = 0xc0485619
vidioc_enumFmt = 0xc0405602
vidioc_enumFramesizes = 0xc02c564a
vidioc_enumFrameintervals = 0xc034564b
vidioc_queryctrl = 0xc0445624
vidioc_querymenu = 0xc02c5625
vidioc_gCtrl = 0xc008561b
vidioc_sCtrl = 0xc008561c
)
const (
size_capability = 104
size_format = 208
size_streamparm = 204
size_requestbuffers = 20
size_buffer = 88
size_int = 4
size_cropcap = 44
size_crop = 20
size_standard = 72
size_fmtdesc = 64
size_frmsizeenum = 44
size_frmivalenum = 52
size_queryctrl = 68
size_querymenu = 44
size_control = 8
)
const (
offs_capability_driver = 0
size_capability_driver = 16
offs_capability_card = 16
size_capability_card = 32
offs_capability_busInfo = 48
size_capability_busInfo = 32
offs_capability_version = 80
offs_capability_capabilities = 84
offs_capability_deviceCaps = 88
)
const (
offs_format_typ = 0
offs_format_fmt = 8
)
const (
offs_pixFormat_width = 0
offs_pixFormat_height = 4
offs_pixFormat_pixelformat = 8
offs_pixFormat_field = 12
offs_pixFormat_bytesperline = 16
offs_pixFormat_sizeimage = 20
offs_pixFormat_colorspace = 24
offs_pixFormat_priv = 28
offs_pixFormat_flags = 32
offs_pixFormat_ycbcrEnc = 36
offs_pixFormat_quantization = 40
offs_pixFormat_xferFunc = 44
)
const (
offs_streamparm_typ = 0
offs_streamparm_parm = 4
)
const (
offs_captureparm_capability = 0
offs_captureparm_capturemode = 4
offs_captureparm_timeperframe = 8
offs_captureparm_extendedmode = 16
offs_captureparm_readbuffers = 20
)
const (
offs_requestbuffers_count = 0
offs_requestbuffers_typ = 4
offs_requestbuffers_memory = 8
)
const (
offs_buffer_index = 0
offs_buffer_typ = 4
offs_buffer_bytesused = 8
offs_buffer_flags = 12
offs_buffer_field = 16
offs_buffer_timecode = 40
offs_buffer_sequence = 56
offs_buffer_memory = 60
offs_buffer_offset = 64
offs_buffer_length = 72
)
const (
offs_cropcap_typ = 0
offs_cropcap_bounds = 4
offs_cropcap_defrect = 20
offs_cropcap_pixelaspect = 36
)
const (
offs_crop_typ = 0
offs_crop_c = 4
)
const (
offs_fract_numerator = 0
offs_fract_denominator = 4
)
const (
offs_timecode_typ = 0
offs_timecode_flags = 4
offs_timecode_frames = 8
offs_timecode_seconds = 9
offs_timecode_minutes = 10
offs_timecode_hours = 11
offs_timecode_userbits = 12
)
const (
offs_rect_left = 0
offs_rect_top = 4
offs_rect_width = 8
offs_rect_height = 12
)
const (
offs_standard_index = 0
offs_standard_id = 8
offs_standard_name = 16
size_standard_name = 24
offs_standard_frameperiod = 40
offs_standard_framelines = 48
)
const (
offs_fmtdesc_index = 0
offs_fmtdesc_typ = 4
offs_fmtdesc_flags = 8
offs_fmtdesc_description = 12
size_fmtdesc_description = 32
offs_fmtdesc_pixelformat = 44
)
const (
offs_frmsizeenum_index = 0
offs_frmsizeenum_pixelFormat = 4
offs_frmsizeenum_typ = 8
offs_frmsizeenum_discrete = 12
offs_frmsizeenum_stepwise = 12
)
const (
offs_frmsizeDiscrete_width = 0
offs_frmsizeDiscrete_height = 4
)
const (
offs_frmsizeStepwise_minWidth = 0
offs_frmsizeStepwise_maxWidth = 4
offs_frmsizeStepwise_stepWidth = 8
offs_frmsizeStepwise_minHeight = 12
offs_frmsizeStepwise_maxHeight = 16
offs_frmsizeStepwise_stepHeight = 20
)
const (
offs_frmivalenum_index = 0
offs_frmivalenum_pixelFormat = 4
offs_frmivalenum_width = 8
offs_frmivalenum_height = 12
offs_frmivalenum_typ = 16
offs_frmivalenum_discrete = 20
offs_frmivalenum_stepwise = 20
)
const (
offs_frmivalStepwise_min = 0
offs_frmivalStepwise_max = 8
offs_frmivalStepwise_step = 16
)
const (
offs_queryctrl_id = 0
offs_queryctrl_typ = 4
offs_queryctrl_name = 8
size_queryctrl_name = 32
offs_queryctrl_minimum = 40
offs_queryctrl_maximum = 44
offs_queryctrl_step = 48
offs_queryctrl_defaultValue = 52
offs_queryctrl_flags = 56
)
const (
offs_querymenu_id = 0
offs_querymenu_index = 4
offs_querymenu_name = 8
size_querymenu_name = 32
offs_querymenu_value = 8
)
const (
offs_control_id = 0
offs_control_value = 4
)
golang-github-korandiz-v4l-1.1.0/arch_arm.go 0000664 0000000 0000000 00000012340 14545740134 0020674 0 ustar 00root root 0000000 0000000 //go:build linux && arm
// +build linux,arm
/////////////////////////////////////////////////////
// //
// !!! THIS IS A GENERATED FILE, DO NOT EDIT !!! //
// //
/////////////////////////////////////////////////////
package v4l
const (
vidioc_querycap = 0x80685600
vidioc_gFmt = 0xc0cc5604
vidioc_sFmt = 0xc0cc5605
vidioc_gParm = 0xc0cc5615
vidioc_sParm = 0xc0cc5616
vidioc_reqbufs = 0xc0145608
vidioc_querybuf = 0xc0445609
vidioc_qbuf = 0xc044560f
vidioc_dqbuf = 0xc0445611
vidioc_streamon = 0x40045612
vidioc_streamoff = 0x40045613
vidioc_cropcap = 0xc02c563a
vidioc_sCrop = 0x4014563c
vidioc_enumstd = 0xc0485619
vidioc_enumFmt = 0xc0405602
vidioc_enumFramesizes = 0xc02c564a
vidioc_enumFrameintervals = 0xc034564b
vidioc_queryctrl = 0xc0445624
vidioc_querymenu = 0xc02c5625
vidioc_gCtrl = 0xc008561b
vidioc_sCtrl = 0xc008561c
)
const (
size_capability = 104
size_format = 204
size_streamparm = 204
size_requestbuffers = 20
size_buffer = 68
size_int = 4
size_cropcap = 44
size_crop = 20
size_standard = 72
size_fmtdesc = 64
size_frmsizeenum = 44
size_frmivalenum = 52
size_queryctrl = 68
size_querymenu = 44
size_control = 8
)
const (
offs_capability_driver = 0
size_capability_driver = 16
offs_capability_card = 16
size_capability_card = 32
offs_capability_busInfo = 48
size_capability_busInfo = 32
offs_capability_version = 80
offs_capability_capabilities = 84
offs_capability_deviceCaps = 88
)
const (
offs_format_typ = 0
offs_format_fmt = 4
)
const (
offs_pixFormat_width = 0
offs_pixFormat_height = 4
offs_pixFormat_pixelformat = 8
offs_pixFormat_field = 12
offs_pixFormat_bytesperline = 16
offs_pixFormat_sizeimage = 20
offs_pixFormat_colorspace = 24
offs_pixFormat_priv = 28
offs_pixFormat_flags = 32
offs_pixFormat_ycbcrEnc = 36
offs_pixFormat_quantization = 40
offs_pixFormat_xferFunc = 44
)
const (
offs_streamparm_typ = 0
offs_streamparm_parm = 4
)
const (
offs_captureparm_capability = 0
offs_captureparm_capturemode = 4
offs_captureparm_timeperframe = 8
offs_captureparm_extendedmode = 16
offs_captureparm_readbuffers = 20
)
const (
offs_requestbuffers_count = 0
offs_requestbuffers_typ = 4
offs_requestbuffers_memory = 8
)
const (
offs_buffer_index = 0
offs_buffer_typ = 4
offs_buffer_bytesused = 8
offs_buffer_flags = 12
offs_buffer_field = 16
offs_buffer_timecode = 28
offs_buffer_sequence = 44
offs_buffer_memory = 48
offs_buffer_offset = 52
offs_buffer_length = 56
)
const (
offs_cropcap_typ = 0
offs_cropcap_bounds = 4
offs_cropcap_defrect = 20
offs_cropcap_pixelaspect = 36
)
const (
offs_crop_typ = 0
offs_crop_c = 4
)
const (
offs_fract_numerator = 0
offs_fract_denominator = 4
)
const (
offs_timecode_typ = 0
offs_timecode_flags = 4
offs_timecode_frames = 8
offs_timecode_seconds = 9
offs_timecode_minutes = 10
offs_timecode_hours = 11
offs_timecode_userbits = 12
)
const (
offs_rect_left = 0
offs_rect_top = 4
offs_rect_width = 8
offs_rect_height = 12
)
const (
offs_standard_index = 0
offs_standard_id = 8
offs_standard_name = 16
size_standard_name = 24
offs_standard_frameperiod = 40
offs_standard_framelines = 48
)
const (
offs_fmtdesc_index = 0
offs_fmtdesc_typ = 4
offs_fmtdesc_flags = 8
offs_fmtdesc_description = 12
size_fmtdesc_description = 32
offs_fmtdesc_pixelformat = 44
)
const (
offs_frmsizeenum_index = 0
offs_frmsizeenum_pixelFormat = 4
offs_frmsizeenum_typ = 8
offs_frmsizeenum_discrete = 12
offs_frmsizeenum_stepwise = 12
)
const (
offs_frmsizeDiscrete_width = 0
offs_frmsizeDiscrete_height = 4
)
const (
offs_frmsizeStepwise_minWidth = 0
offs_frmsizeStepwise_maxWidth = 4
offs_frmsizeStepwise_stepWidth = 8
offs_frmsizeStepwise_minHeight = 12
offs_frmsizeStepwise_maxHeight = 16
offs_frmsizeStepwise_stepHeight = 20
)
const (
offs_frmivalenum_index = 0
offs_frmivalenum_pixelFormat = 4
offs_frmivalenum_width = 8
offs_frmivalenum_height = 12
offs_frmivalenum_typ = 16
offs_frmivalenum_discrete = 20
offs_frmivalenum_stepwise = 20
)
const (
offs_frmivalStepwise_min = 0
offs_frmivalStepwise_max = 8
offs_frmivalStepwise_step = 16
)
const (
offs_queryctrl_id = 0
offs_queryctrl_typ = 4
offs_queryctrl_name = 8
size_queryctrl_name = 32
offs_queryctrl_minimum = 40
offs_queryctrl_maximum = 44
offs_queryctrl_step = 48
offs_queryctrl_defaultValue = 52
offs_queryctrl_flags = 56
)
const (
offs_querymenu_id = 0
offs_querymenu_index = 4
offs_querymenu_name = 8
size_querymenu_name = 32
offs_querymenu_value = 8
)
const (
offs_control_id = 0
offs_control_value = 4
)
golang-github-korandiz-v4l-1.1.0/arch_arm64.go 0000664 0000000 0000000 00000012344 14545740134 0021052 0 ustar 00root root 0000000 0000000 //go:build linux && arm64
// +build linux,arm64
/////////////////////////////////////////////////////
// //
// !!! THIS IS A GENERATED FILE, DO NOT EDIT !!! //
// //
/////////////////////////////////////////////////////
package v4l
const (
vidioc_querycap = 0x80685600
vidioc_gFmt = 0xc0d05604
vidioc_sFmt = 0xc0d05605
vidioc_gParm = 0xc0cc5615
vidioc_sParm = 0xc0cc5616
vidioc_reqbufs = 0xc0145608
vidioc_querybuf = 0xc0585609
vidioc_qbuf = 0xc058560f
vidioc_dqbuf = 0xc0585611
vidioc_streamon = 0x40045612
vidioc_streamoff = 0x40045613
vidioc_cropcap = 0xc02c563a
vidioc_sCrop = 0x4014563c
vidioc_enumstd = 0xc0485619
vidioc_enumFmt = 0xc0405602
vidioc_enumFramesizes = 0xc02c564a
vidioc_enumFrameintervals = 0xc034564b
vidioc_queryctrl = 0xc0445624
vidioc_querymenu = 0xc02c5625
vidioc_gCtrl = 0xc008561b
vidioc_sCtrl = 0xc008561c
)
const (
size_capability = 104
size_format = 208
size_streamparm = 204
size_requestbuffers = 20
size_buffer = 88
size_int = 4
size_cropcap = 44
size_crop = 20
size_standard = 72
size_fmtdesc = 64
size_frmsizeenum = 44
size_frmivalenum = 52
size_queryctrl = 68
size_querymenu = 44
size_control = 8
)
const (
offs_capability_driver = 0
size_capability_driver = 16
offs_capability_card = 16
size_capability_card = 32
offs_capability_busInfo = 48
size_capability_busInfo = 32
offs_capability_version = 80
offs_capability_capabilities = 84
offs_capability_deviceCaps = 88
)
const (
offs_format_typ = 0
offs_format_fmt = 8
)
const (
offs_pixFormat_width = 0
offs_pixFormat_height = 4
offs_pixFormat_pixelformat = 8
offs_pixFormat_field = 12
offs_pixFormat_bytesperline = 16
offs_pixFormat_sizeimage = 20
offs_pixFormat_colorspace = 24
offs_pixFormat_priv = 28
offs_pixFormat_flags = 32
offs_pixFormat_ycbcrEnc = 36
offs_pixFormat_quantization = 40
offs_pixFormat_xferFunc = 44
)
const (
offs_streamparm_typ = 0
offs_streamparm_parm = 4
)
const (
offs_captureparm_capability = 0
offs_captureparm_capturemode = 4
offs_captureparm_timeperframe = 8
offs_captureparm_extendedmode = 16
offs_captureparm_readbuffers = 20
)
const (
offs_requestbuffers_count = 0
offs_requestbuffers_typ = 4
offs_requestbuffers_memory = 8
)
const (
offs_buffer_index = 0
offs_buffer_typ = 4
offs_buffer_bytesused = 8
offs_buffer_flags = 12
offs_buffer_field = 16
offs_buffer_timecode = 40
offs_buffer_sequence = 56
offs_buffer_memory = 60
offs_buffer_offset = 64
offs_buffer_length = 72
)
const (
offs_cropcap_typ = 0
offs_cropcap_bounds = 4
offs_cropcap_defrect = 20
offs_cropcap_pixelaspect = 36
)
const (
offs_crop_typ = 0
offs_crop_c = 4
)
const (
offs_fract_numerator = 0
offs_fract_denominator = 4
)
const (
offs_timecode_typ = 0
offs_timecode_flags = 4
offs_timecode_frames = 8
offs_timecode_seconds = 9
offs_timecode_minutes = 10
offs_timecode_hours = 11
offs_timecode_userbits = 12
)
const (
offs_rect_left = 0
offs_rect_top = 4
offs_rect_width = 8
offs_rect_height = 12
)
const (
offs_standard_index = 0
offs_standard_id = 8
offs_standard_name = 16
size_standard_name = 24
offs_standard_frameperiod = 40
offs_standard_framelines = 48
)
const (
offs_fmtdesc_index = 0
offs_fmtdesc_typ = 4
offs_fmtdesc_flags = 8
offs_fmtdesc_description = 12
size_fmtdesc_description = 32
offs_fmtdesc_pixelformat = 44
)
const (
offs_frmsizeenum_index = 0
offs_frmsizeenum_pixelFormat = 4
offs_frmsizeenum_typ = 8
offs_frmsizeenum_discrete = 12
offs_frmsizeenum_stepwise = 12
)
const (
offs_frmsizeDiscrete_width = 0
offs_frmsizeDiscrete_height = 4
)
const (
offs_frmsizeStepwise_minWidth = 0
offs_frmsizeStepwise_maxWidth = 4
offs_frmsizeStepwise_stepWidth = 8
offs_frmsizeStepwise_minHeight = 12
offs_frmsizeStepwise_maxHeight = 16
offs_frmsizeStepwise_stepHeight = 20
)
const (
offs_frmivalenum_index = 0
offs_frmivalenum_pixelFormat = 4
offs_frmivalenum_width = 8
offs_frmivalenum_height = 12
offs_frmivalenum_typ = 16
offs_frmivalenum_discrete = 20
offs_frmivalenum_stepwise = 20
)
const (
offs_frmivalStepwise_min = 0
offs_frmivalStepwise_max = 8
offs_frmivalStepwise_step = 16
)
const (
offs_queryctrl_id = 0
offs_queryctrl_typ = 4
offs_queryctrl_name = 8
size_queryctrl_name = 32
offs_queryctrl_minimum = 40
offs_queryctrl_maximum = 44
offs_queryctrl_step = 48
offs_queryctrl_defaultValue = 52
offs_queryctrl_flags = 56
)
const (
offs_querymenu_id = 0
offs_querymenu_index = 4
offs_querymenu_name = 8
size_querymenu_name = 32
offs_querymenu_value = 8
)
const (
offs_control_id = 0
offs_control_value = 4
)
golang-github-korandiz-v4l-1.1.0/buffer.go 0000664 0000000 0000000 00000007155 14545740134 0020401 0 ustar 00root root 0000000 0000000 // Package v4l, a facade to the Video4Linux video capture interface
// Copyright (C) 2016 Zoltán Korándi
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//go:build linux
// +build linux
package v4l
import "io"
// A Buffer holds the raw image data of a frame captured from a Device. It
// implements io.Reader, io.ByteReader, io.ReaderAt, and io.Seeker. A call to
// Capture, Close, or TurnOff on the corresponding Device may cause the contents
// of the buffer to go away.
type Buffer struct {
d *device
n uint64
pos int
seq uint32
}
// Size returns the total number of bytes in the buffer. As long as the data is
// available, the return value is constant and unaffected by calls to the
// methods of Buffer. If the data is no longer available, it returns 0.
func (b *Buffer) Size() int64 {
return int64(len(b.source()))
}
// Len returns the number of unread bytes in the buffer. If the data is no
// longer available, it returns 0.
func (b *Buffer) Len() int {
src := b.source()
if src == nil {
return 0
}
return len(src) - b.pos
}
// SeqNum returns the sequence number of the frame in the buffer as reported by
// the kernel.
func (b *Buffer) SeqNum() uint32 {
return b.seq
}
// Read reads up to len(dst) bytes into dst, and returns the number of bytes
// read, along with any error encountered.
func (b *Buffer) Read(dst []byte) (int, error) {
src := b.source()
if src == nil {
return 0, ErrBufferGone
}
if b.pos == len(src) {
return 0, io.EOF
}
n := copy(dst, src[b.pos:])
b.pos += n
return n, nil
}
// ReadAt reads up to len(dst) bytes into dst starting at the specified offset,
// and returns the number of bytes read, along with any error encountered.
// The seek offset is unaffected by ReadAt.
func (b *Buffer) ReadAt(dst []byte, offset int64) (int, error) {
src := b.source()
if src == nil {
return 0, ErrBufferGone
}
if offset < 0 {
return 0, Error("negative offset")
}
if offset >= int64(len(src)) {
return 0, io.EOF
}
n := copy(dst, src[offset:])
if n < len(dst) {
return n, io.EOF
}
return n, nil
}
// ReadByte returns the next byte in the buffer.
func (b *Buffer) ReadByte() (byte, error) {
src := b.source()
if src == nil {
return 0, ErrBufferGone
}
if b.pos == len(src) {
return 0, io.EOF
}
x := src[b.pos]
b.pos++
return x, nil
}
// Seek sets the seek offset.
func (b *Buffer) Seek(offset int64, whence int) (int64, error) {
src := b.source()
if src == nil {
return 0, ErrBufferGone
}
var i int64
switch whence {
case io.SeekStart:
i = offset
case io.SeekCurrent:
i = int64(b.pos) + offset
case io.SeekEnd:
i = int64(len(src)) + offset
default:
return 0, Error("invalid whence")
}
if i < 0 {
return 0, Error("negative offset")
}
if i > int64(len(src)) {
i = int64(len(src))
}
b.pos = int(i)
return i, nil
}
// source returns the underlying byte slice of the buffer, or nil, if it's no
// longer available.
func (b *Buffer) source() []byte {
if b.d.nCaptures != b.n || b.d.bufIndex == noBuffer {
return nil
}
return b.d.buffers[b.d.bufIndex]
}
golang-github-korandiz-v4l-1.1.0/buffer_test.go 0000664 0000000 0000000 00000012640 14545740134 0021433 0 ustar 00root root 0000000 0000000 // Package v4l, a facade to the Video4Linux video capture interface
// Copyright (C) 2016 Zoltán Korándi
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//go:build linux
// +build linux
package v4l
import (
"io"
"math/rand"
"testing"
)
const N = 100
func TestBuffer_Size(t *testing.T) {
buf := initBufferTest()
for i := 0; i < N+10; i++ {
size := buf.Size()
if size != N {
t.Errorf("got: %d, expected: %d (i=%d)\n", size, N, i)
return
}
buf.ReadByte()
}
}
func TestBuffer_Len(t *testing.T) {
buf := initBufferTest()
for i := 0; i < N+10; i++ {
length := buf.Len()
n := N - i
if n < 0 {
n = 0
}
if length != n {
t.Errorf("got: %d, expected: %d (i=%d)\n", length, n, i)
return
}
buf.ReadByte()
}
}
func TestBuffer_Read(t *testing.T) {
var (
buf = initBufferTest()
arr = make([]byte, 2*N)
err error
n, m int
)
for err == nil {
n, err = buf.Read(arr[m : m+15])
m += n
}
if err != io.EOF {
t.Errorf("expected EOF, got: %v (m=%d)\n", err, m)
return
}
if m != N {
t.Errorf("wrong byte count: %d (expected: %d)\n", m, N)
return
}
for i := 0; i < N; i++ {
if arr[i] != byte(i) {
t.Errorf("got: %d, expected: %d (i=%d)\n", arr[i], byte(i), i)
return
}
}
}
func TestBuffer_ReadAt(t *testing.T) {
buf := initBufferTest()
arr := make([]byte, N+10)
for start := -10; start < N+10; start++ {
for length := 0; length < N+10; length++ {
n, err := buf.ReadAt(arr[:length], int64(start))
if start < 0 {
if err == nil || n != 0 {
t.Errorf("read at %d should have failed (length=%d, n=%d)\n",
start, length, n)
return
}
continue
}
if n > length {
t.Errorf("read too many bytes (start=%d, length=%d, n=%d)\n",
start, length, n)
return
}
if n < length && err == nil {
t.Errorf("short read with nil error (start=%d, length=%d, n=%d)\n",
start, length, n)
return
}
if start+length <= N && n < length {
t.Errorf("short read (start=%d, length=%d, n=%d)\n",
start, length, n)
return
}
m := N - start
if m < 0 {
m = 0
}
if start+length > N && n != m {
t.Errorf("read %d bytes instead of %d (start=%d, length=%d)\n",
n, m, start, length)
return
}
if start+length > N && err != io.EOF {
t.Errorf("expected EOF, got: %v (start=%d, length=%d)\n",
err, start, length)
return
}
for i := 0; i < n; i++ {
if arr[i] != byte(start+i) {
t.Errorf("expected: %d, got: %d (start=%d, length=%d, i=%d)\n",
start+i, arr[i], start, length, i)
return
}
}
}
}
}
func TestBuffer_ReadByte(t *testing.T) {
buf := initBufferTest()
for i := 0; i < N; i++ {
b, err := buf.ReadByte()
if err != nil {
t.Errorf("unexpected error: %v (i=%d)\n", err, i)
return
}
if b != byte(i) {
t.Errorf("got: %d, expected: %d\n", b, i)
return
}
}
if _, err := buf.ReadByte(); err != io.EOF {
t.Error("expected EOF, got:", err)
return
}
}
func TestBuffer_Seek(t *testing.T) {
buf := initBufferTest()
rand.Seed(42)
for _, whence := range []int{io.SeekStart, io.SeekEnd} {
for i := 0; i < 10*N; i++ {
offs := rand.Int63n(N)
var m int64
if whence == io.SeekEnd {
offs = -offs - 1
m = N
}
m += offs
n, err := buf.Seek(offs, whence)
if err != nil {
t.Errorf("unexpected error: %v (i=%d, offs=%d, whence=%d)\n",
err, i, offs, whence)
return
}
if n != m {
t.Errorf("bad offset: %d (m=%d, i=%d, offs=%d, whence=%d)\n",
n, m, i, offs, whence)
return
}
b, err := buf.ReadByte()
if err != nil {
t.Errorf("unexpected error: %v (i=%d, offs=%d, whence=%d)\n",
err, i, offs, whence)
return
}
if b != byte(m) {
t.Errorf("read: %d (m=%d, i=%d, offs=%d, whence=%d)\n",
b, m, i, offs, whence)
return
}
}
}
buf = initBufferTest()
var p int64
for i := 0; i < 10*N; i++ {
m := rand.Int63n(N)
offs := m - p
n, err := buf.Seek(offs, io.SeekCurrent)
if err != nil {
t.Errorf("unexpected error: %v (i=%d, offs=%d, whence=%d)\n",
err, i, offs, io.SeekCurrent)
return
}
if n != m {
t.Errorf("bad offset: %d (m=%d, i=%d, offs=%d, whence=%d)\n",
n, m, i, offs, io.SeekCurrent)
return
}
b, err := buf.ReadByte()
if err != nil {
t.Errorf("unexpected error: %v (i=%d, offs=%d, whence=%d)\n",
err, i, offs, io.SeekCurrent)
return
}
if b != byte(m) {
t.Errorf("read: %d (m=%d, i=%d, offs=%d, whence=%d)\n",
b, m, i, offs, io.SeekCurrent)
return
}
p = n + 1
}
_, err := buf.Seek(-1, io.SeekStart)
if err == nil {
t.Error("seek to offset -1 should have failed")
return
}
}
func initBufferTest() *Buffer {
buf := make([]byte, N)
for i := range buf {
buf[i] = byte(i)
}
d := device{
buffers: [][]byte{nil, nil, buf, nil},
bufIndex: 2,
nCaptures: 1,
}
return &Buffer{
d: &d,
n: 1,
pos: 0,
}
}
golang-github-korandiz-v4l-1.1.0/demos/ 0000775 0000000 0000000 00000000000 14545740134 0017700 5 ustar 00root root 0000000 0000000 golang-github-korandiz-v4l-1.1.0/demos/streamcam/ 0000775 0000000 0000000 00000000000 14545740134 0021654 5 ustar 00root root 0000000 0000000 golang-github-korandiz-v4l-1.1.0/demos/streamcam/LICENSE.txt 0000664 0000000 0000000 00000104513 14545740134 0023503 0 ustar 00root root 0000000 0000000 GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is 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. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
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.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
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 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. Use with the GNU Affero General Public License.
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 Affero 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 special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU 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 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 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 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.
Copyright (C)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
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 GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
golang-github-korandiz-v4l-1.1.0/demos/streamcam/go.mod 0000664 0000000 0000000 00000000140 14545740134 0022755 0 ustar 00root root 0000000 0000000 module github.com/korandiz/v4l/demos/streamcam
go 1.15
require github.com/korandiz/v4l v1.0.5
golang-github-korandiz-v4l-1.1.0/demos/streamcam/go.sum 0000664 0000000 0000000 00000000245 14545740134 0023010 0 ustar 00root root 0000000 0000000 github.com/korandiz/v4l v1.0.5 h1:LdbunFQJ+EBuU9v60ryeRefofTim6css+B56VkwPiMg=
github.com/korandiz/v4l v1.0.5/go.mod h1:pftxPG7hkuUgepioAY6PAE81mShaVjzd95X/WF4Izus=
golang-github-korandiz-v4l-1.1.0/demos/streamcam/streamcam.go 0000664 0000000 0000000 00000015402 14545740134 0024161 0 ustar 00root root 0000000 0000000 // Package v4l, a facade to the Video4Linux video capture interface
// Copyright (C) 2016 Zoltán Korándi
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
// Command streamcam streams MJPEG from a V4L device over HTTP.
//
// Command Line
//
// Usage:
// streamcam [flags]
//
// Flags:
// -a string
// address to listen on (default ":8080")
// -d string
// path to the capture device
// -f int
// frame rate
// -h int
// image height
// -l
// print supported device configs and quit
// -r
// reset all controls to default
// -w int
// image width
package main
import (
"bytes"
"flag"
"fmt"
"image"
"image/jpeg"
"log"
"net/http"
"os"
"os/signal"
"sync"
"time"
"github.com/korandiz/v4l"
"github.com/korandiz/v4l/fmt/mjpeg"
)
func main() {
var (
d = flag.String("d", "", "path to the capture device")
w = flag.Int("w", 0, "image width")
h = flag.Int("h", 0, "image height")
f = flag.Int("f", 0, "frame rate")
a = flag.String("a", ":8080", "address to listen on")
l = flag.Bool("l", false, "print supported device configs and quit")
r = flag.Bool("r", false, "reset all controls to default")
)
flag.Parse()
if *d == "" {
devs := v4l.FindDevices()
if len(devs) != 1 {
fmt.Fprintln(os.Stderr, "Use -d to select device.")
for _, info := range devs {
fmt.Fprintln(os.Stderr, " ", info.Path)
}
os.Exit(1)
}
*d = devs[0].Path
}
fmt.Fprintln(os.Stderr, "Using device", *d)
cam, err := v4l.Open(*d)
fatal("Open", err)
if *l {
configs, err := cam.ListConfigs()
fatal("ListConfigs", err)
fmt.Fprintln(os.Stderr, "Supported device configs:")
found := false
for _, cfg := range configs {
if cfg.Format != mjpeg.FourCC {
continue
}
found = true
fmt.Fprintln(os.Stderr, " ", cfg2str(cfg))
}
if !found {
fmt.Fprintln(os.Stderr, " (none)")
}
os.Exit(0)
}
cfg, err := cam.GetConfig()
fatal("GetConfig", err)
cfg.Format = mjpeg.FourCC
if *w > 0 {
cfg.Width = *w
}
if *h > 0 {
cfg.Height = *h
}
if *f > 0 {
cfg.FPS = v4l.Frac{uint32(*f), 1}
}
fmt.Fprintln(os.Stderr, "Requested config:", cfg2str(cfg))
err = cam.SetConfig(cfg)
fatal("SetConfig", err)
err = cam.TurnOn()
fatal("TurnOn", err)
cfg, err = cam.GetConfig()
fatal("GetConfig", err)
if cfg.Format != mjpeg.FourCC {
fmt.Fprintln(os.Stderr, "Failed to set MJPEG format.")
os.Exit(1)
}
fmt.Fprintln(os.Stderr, "Actual device config:", cfg2str(cfg))
if *r {
ctrls, err := cam.ListControls()
fatal("ListControls", err)
for _, ctrl := range ctrls {
cam.SetControl(ctrl.CID, ctrl.Default)
}
}
blankImg := image.NewRGBA(image.Rect(0, 0, cfg.Width, cfg.Height))
buf := new(bytes.Buffer)
jpeg.Encode(buf, blankImg, nil)
blank = buf.Bytes()
go handleInterrupt()
go stream(cam)
log.Println("Listening on address", *a)
srv := http.Server{
Addr: *a,
Handler: http.HandlerFunc(serveHTTP),
}
err = srv.ListenAndServe()
fatal("ListenAndServe", err)
}
func cfg2str(cfg v4l.DeviceConfig) string {
return fmt.Sprintf("%dx%d @ %.4g FPS", cfg.Width, cfg.Height,
float64(cfg.FPS.N)/float64(cfg.FPS.D))
}
var (
mu sync.Mutex
clients []*client
stopped bool
quit = make(chan int, 1)
blank []byte
)
type client struct {
i int
ch chan []byte
}
func newClient() *client {
mu.Lock()
defer mu.Unlock()
if stopped {
return nil
}
clt := &client{
i: len(clients),
ch: make(chan []byte, 1),
}
clt.ch <- blank
clients = append(clients, clt)
return clt
}
func (clt *client) remove() {
mu.Lock()
defer mu.Unlock()
i := clt.i
last := len(clients) - 1
clients[i] = clients[last]
clients[i].i = i
clients[last] = nil
clients = clients[:last]
clt.i = -1
if stopped && len(clients) == 0 {
quit <- 1
}
}
func handleInterrupt() {
ch := make(chan os.Signal, 1)
signal.Notify(ch, os.Interrupt)
<-ch
log.Println("Stopping...")
mu.Lock()
stopped = true
if len(clients) == 0 {
quit <- 1
} else {
for _, clt := range clients {
close(clt.ch)
}
}
mu.Unlock()
<-quit
os.Exit(0)
}
func stream(cam *v4l.Device) {
for {
buf, err := cam.Capture()
if err != nil {
log.Println("Capture:", err)
proc, _ := os.FindProcess(os.Getpid())
proc.Signal(os.Interrupt)
break
}
b := make([]byte, buf.Size())
buf.ReadAt(b, 0)
mu.Lock()
if stopped {
mu.Unlock()
break
}
for _, clt := range clients {
select {
case clt.ch <- b:
case <-clt.ch:
clt.ch <- b
}
}
mu.Unlock()
}
}
func serveHTTP(w http.ResponseWriter, r *http.Request) {
log.Printf("[%s] New connection\n", r.RemoteAddr)
hj, ok := w.(http.Hijacker)
if !ok {
log.Printf("[%s] ResponseWrite is not a Hijacker", r.RemoteAddr)
http.Error(w, "Internal Server Error", 500)
return
}
conn, _, err := hj.Hijack()
if err != nil {
log.Printf("[%s] Hijack: %v\n", r.RemoteAddr, err)
http.Error(w, "Internal Server Error", 500)
return
}
defer conn.Close()
clt := newClient()
if clt == nil {
return
}
defer clt.remove()
const B = "45c7pIy0cxa4vWtwGuVuAkbzKAQGpRjz9eyhyHTv"
_, err = conn.Write([]byte("HTTP/1.1 200 OK\r\n" +
"Date: " + time.Now().UTC().Format(http.TimeFormat) + "\r\n" +
"Content-Type: multipart/x-mixed-replace; boundary=" + B + "\r\n" +
"Cache-Control: no-cache, no-store, max-age=0, must-revalidate\r\n" +
"Pragma: no-cache\r\n" +
"\r\n" +
"--" + B + "\r\n"))
if err != nil {
log.Printf("[%s] %v\n", r.RemoteAddr, err)
return
}
for {
buf := <-clt.ch
conn.SetDeadline(time.Now().Add(time.Second))
_, err := conn.Write([]byte("Content-Type: image/jpeg\r\n\r\n"))
if err != nil {
log.Printf("[%s] %v\n", r.RemoteAddr, err)
return
}
if buf == nil {
_, err := conn.Write(blank)
if err == nil {
conn.Write([]byte("--" + B + "--\r\n"))
} else {
log.Printf("[%s] %v\n", r.RemoteAddr, err)
}
log.Printf("[%s] Quitting\n", r.RemoteAddr)
return
}
_, err = conn.Write(buf)
if err != nil {
log.Printf("[%s] %v\n", r.RemoteAddr, err)
return
}
_, err = conn.Write([]byte("--" + B + "\r\n"))
if err != nil {
log.Printf("[%s] %v\n", r.RemoteAddr, err)
return
}
}
}
func fatal(p string, err error) {
if err != nil {
fmt.Fprintf(os.Stderr, "%s: %v\n", p, err)
os.Exit(1)
}
}
golang-github-korandiz-v4l-1.1.0/demos/viewcam/ 0000775 0000000 0000000 00000000000 14545740134 0021333 5 ustar 00root root 0000000 0000000 golang-github-korandiz-v4l-1.1.0/demos/viewcam/LICENSE.txt 0000664 0000000 0000000 00000104513 14545740134 0023162 0 ustar 00root root 0000000 0000000 GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is 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. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
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.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
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 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. Use with the GNU Affero General Public License.
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 Affero 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 special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU 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 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 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 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.
Copyright (C)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
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 GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
golang-github-korandiz-v4l-1.1.0/demos/viewcam/go.mod 0000664 0000000 0000000 00000000202 14545740134 0022433 0 ustar 00root root 0000000 0000000 module github.com/korandiz/v4l/demos/viewcam
go 1.15
require (
github.com/gotk3/gotk3 v0.6.1
github.com/korandiz/v4l v1.0.5
)
golang-github-korandiz-v4l-1.1.0/demos/viewcam/go.sum 0000664 0000000 0000000 00000000510 14545740134 0022462 0 ustar 00root root 0000000 0000000 github.com/gotk3/gotk3 v0.6.1 h1:GJ400a0ecEEWrzjBvzBzH+pB/esEMIGdB9zPSmBdoeo=
github.com/gotk3/gotk3 v0.6.1/go.mod h1:/hqFpkNa9T3JgNAE2fLvCdov7c5bw//FHNZrZ3Uv9/Q=
github.com/korandiz/v4l v1.0.5 h1:LdbunFQJ+EBuU9v60ryeRefofTim6css+B56VkwPiMg=
github.com/korandiz/v4l v1.0.5/go.mod h1:pftxPG7hkuUgepioAY6PAE81mShaVjzd95X/WF4Izus=
golang-github-korandiz-v4l-1.1.0/demos/viewcam/viewcam.go 0000664 0000000 0000000 00000045550 14545740134 0023326 0 ustar 00root root 0000000 0000000 // Package v4l, a facade to the Video4Linux video capture interface
// Copyright (C) 2016 Zoltán Korándi
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
// Command viewcam displays the video captured from a V4L device in a GTK-based
// GUI.
//
// Usage:
// viewcam
package main
import (
"errors"
"fmt"
"image"
"strconv"
"github.com/gotk3/gotk3/gdk"
"github.com/gotk3/gotk3/glib"
"github.com/gotk3/gotk3/gtk"
"github.com/korandiz/v4l"
"github.com/korandiz/v4l/fmt/yuyv"
)
func main() {
var (
dp DevicePickerWindow
vc VideoCaptureWindow
cp ControlPanelWindow
)
dp.OnClose = func() {
if dp.Video {
vc.DevicePath = dp.DevicePath
vc.DeviceConfig = dp.DeviceConfig
vc.Open()
}
if dp.ControlPanel {
cp.DevicePath = dp.DevicePath
cp.Open()
}
if !dp.Video && !dp.ControlPanel {
gtk.MainQuit()
}
}
vc.OnClose = func() {
cp.Close()
dp.Open()
}
cp.OnClose = func() {
vc.Close()
dp.Open()
}
gtk.Init(nil)
dp.Open()
gtk.Main()
}
type DevicePickerWindow struct {
DevicePath string
DeviceConfig v4l.DeviceConfig
Video bool
ControlPanel bool
OnClose func()
open bool
devices []v4l.DeviceInfo
configs []v4l.DeviceConfig
ticker *ticker
window *gtk.Window
deviceList *gtk.ListBox
configList *gtk.ListBox
pathLabel *gtk.Label
nameLabel *gtk.Label
businfoLabel *gtk.Label
driverLabel *gtk.Label
cameraLabel *gtk.Label
videoButton *gtk.RadioButton
ctrlButton *gtk.RadioButton
bothButton *gtk.RadioButton
}
func (w *DevicePickerWindow) Open() {
if w.open {
return
}
w.DevicePath = ""
w.DeviceConfig = v4l.DeviceConfig{}
w.Video = false
w.ControlPanel = false
w.initWidgets()
w.open = true
w.updateDeviceList()
w.ticker = newTicker(500, w.updateDeviceList)
}
func (w *DevicePickerWindow) Close() {
if !w.open {
return
}
w.window.Destroy()
}
func (w *DevicePickerWindow) initWidgets() {
var err error
w.window, err = gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
fatal(err)
w.window.SetTitle("Video Capture Demo")
w.window.SetIconName("camera-web")
w.window.SetPosition(gtk.WIN_POS_CENTER)
w.window.SetSizeRequest(640, 320)
w.window.SetBorderWidth(6)
w.window.Connect("destroy", w.windowDestroyed)
grid1, err := gtk.GridNew()
fatal(err)
grid1.SetColumnHomogeneous(true)
grid1.SetColumnSpacing(6)
grid1.SetRowSpacing(6)
w.window.Add(grid1)
frame, err := gtk.FrameNew("Devices:")
fatal(err)
grid1.Attach(frame, 0, 0, 1, 1)
scrolled, err := gtk.ScrolledWindowNew(nil, nil)
fatal(err)
scrolled.SetHExpand(true)
scrolled.SetVExpand(true)
frame.Add(scrolled)
w.deviceList, err = gtk.ListBoxNew()
fatal(err)
w.deviceList.Connect("selected-rows-changed", w.deviceSelected)
scrolled.Add(w.deviceList)
frame, err = gtk.FrameNew("Configurations:")
fatal(err)
grid1.Attach(frame, 1, 0, 1, 1)
scrolled, err = gtk.ScrolledWindowNew(nil, nil)
fatal(err)
scrolled.SetHExpand(true)
scrolled.SetVExpand(true)
frame.Add(scrolled)
w.configList, err = gtk.ListBoxNew()
fatal(err)
w.configList.Connect("selected-rows-changed", w.configSelected)
scrolled.Add(w.configList)
grid2, err := gtk.GridNew()
fatal(err)
grid2.SetColumnSpacing(12)
grid2.SetRowSpacing(6)
grid1.Attach(grid2, 0, 1, 1, 1)
w.pathLabel = labelNew("")
w.nameLabel = labelNew("")
w.businfoLabel = labelNew("")
w.driverLabel = labelNew("")
w.cameraLabel = labelNew("")
grid2.Attach(labelNew("Path:"), 0, 0, 1, 1)
grid2.Attach(labelNew("Name:"), 0, 1, 1, 1)
grid2.Attach(labelNew("BusInfo:"), 0, 2, 1, 1)
grid2.Attach(labelNew("Driver:"), 0, 3, 1, 1)
grid2.Attach(labelNew("Camera:"), 0, 4, 1, 1)
grid2.Attach(w.pathLabel, 1, 0, 1, 1)
grid2.Attach(w.nameLabel, 1, 1, 1, 1)
grid2.Attach(w.businfoLabel, 1, 2, 1, 1)
grid2.Attach(w.driverLabel, 1, 3, 1, 1)
grid2.Attach(w.cameraLabel, 1, 4, 1, 1)
w.clearLabels()
box, err := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 6)
fatal(err)
grid1.Attach(box, 1, 1, 1, 1)
w.videoButton, err = gtk.RadioButtonNewWithLabel(nil, "Video")
fatal(err)
box.Add(w.videoButton)
w.ctrlButton, err = gtk.RadioButtonNewWithLabelFromWidget(w.videoButton,
"Control Panel")
fatal(err)
box.Add(w.ctrlButton)
w.bothButton, err = gtk.RadioButtonNewWithLabelFromWidget(w.videoButton,
"Both")
fatal(err)
box.Add(w.bothButton)
button, err := gtk.ButtonNewWithLabel("Start")
fatal(err)
button.Connect("clicked", w.startClicked)
box.Add(button)
w.window.ShowAll()
}
func (w *DevicePickerWindow) windowDestroyed() {
w.ticker.cancel()
*w = DevicePickerWindow{
DevicePath: w.DevicePath,
DeviceConfig: w.DeviceConfig,
Video: w.Video,
ControlPanel: w.ControlPanel,
OnClose: w.OnClose,
}
w.OnClose()
}
func (w *DevicePickerWindow) updateDeviceList() {
devices := v4l.FindDevices()
if deviceListsEqual(devices, w.devices) {
return
}
oldIndex := -1
newIndex := -1
if row := w.deviceList.GetSelectedRow(); row != nil {
oldIndex = row.GetIndex()
for i := range devices {
if devices[i] == w.devices[oldIndex] {
newIndex = i
}
}
}
for i := range w.devices {
if i < oldIndex || newIndex == -1 {
w.deviceList.Remove(w.deviceList.GetRowAtIndex(0))
} else if i > oldIndex {
w.deviceList.Remove(w.deviceList.GetRowAtIndex(1))
}
}
for i := range devices {
if i < newIndex {
w.deviceList.Insert(labelNew(devices[i].Path), i)
} else if i > newIndex {
w.deviceList.Add(labelNew(devices[i].Path))
}
}
w.devices = devices
w.deviceList.ShowAll()
}
func (w *DevicePickerWindow) deviceSelected() {
if !w.open {
return
}
w.clearConfigList()
row := w.deviceList.GetSelectedRow()
if row == nil {
w.clearLabels()
w.DevicePath = ""
return
}
err := w.fillConfigList(w.devices[row.GetIndex()])
if err != nil {
w.modalWarning(err.Error())
w.deviceList.SelectRow(nil)
return
}
device := w.devices[row.GetIndex()]
w.setLabels(device)
w.DevicePath = device.Path
}
func (w *DevicePickerWindow) clearConfigList() {
w.configs = nil
w.DeviceConfig = v4l.DeviceConfig{}
for {
row := w.configList.GetRowAtIndex(0)
if row == nil {
break
}
w.configList.Remove(row)
}
}
func (w *DevicePickerWindow) clearLabels() {
w.pathLabel.SetLabel("\u2014")
w.nameLabel.SetLabel("\u2014")
w.businfoLabel.SetLabel("\u2014")
w.driverLabel.SetLabel("\u2014")
w.cameraLabel.SetLabel("\u2014")
}
func (w *DevicePickerWindow) setLabels(info v4l.DeviceInfo) {
dn := info.DriverName
dv := info.DriverVersion
c := "No"
if info.Camera {
c = "Yes"
}
w.pathLabel.SetLabel(info.Path)
w.nameLabel.SetLabel(info.DeviceName)
w.businfoLabel.SetLabel(info.BusInfo)
w.driverLabel.SetLabel(fmt.Sprintf("%s %v.%v.%v", dn, dv[0], dv[1], dv[2]))
w.cameraLabel.SetLabel(c)
}
func (w *DevicePickerWindow) fillConfigList(info v4l.DeviceInfo) error {
dev, err := v4l.Open(info.Path)
if err != nil {
return errors.New("Open: " + err.Error())
}
defer dev.Close()
cfgs, err := dev.ListConfigs()
if err != nil {
return errors.New("ListConfigs: " + err.Error())
}
for i := range cfgs {
if cfgs[i].Format != yuyv.FourCC {
continue
}
w.configList.Add(labelNew(cfg2str(cfgs[i])))
w.configs = append(w.configs, cfgs[i])
}
w.configList.ShowAll()
return nil
}
func (w *DevicePickerWindow) configSelected() {
if !w.open {
return
}
row := w.configList.GetSelectedRow()
if row == nil {
w.DeviceConfig = v4l.DeviceConfig{}
return
}
w.DeviceConfig = w.configs[row.GetIndex()]
}
func (w *DevicePickerWindow) startClicked() {
video := w.videoButton.GetActive() || w.bothButton.GetActive()
controlPanel := w.ctrlButton.GetActive() || w.bothButton.GetActive()
if row := w.deviceList.GetSelectedRow(); row == nil {
w.modalWarning("Please select a device.")
return
}
if row := w.configList.GetSelectedRow(); row == nil && video {
w.modalWarning("Please select a configuration.")
return
}
w.Video = video
w.ControlPanel = controlPanel
w.window.Destroy()
}
func (w *DevicePickerWindow) modalWarning(msg string) {
dlg := gtk.MessageDialogNew(w.window,
gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, msg)
dlg.SetTitle("Error")
dlg.SetPosition(gtk.WIN_POS_CENTER_ON_PARENT)
dlg.Connect("response", dlg.Destroy)
dlg.ShowAll()
}
type VideoCaptureWindow struct {
DevicePath string
DeviceConfig v4l.DeviceConfig
OnClose func()
open bool
capture *capture
window *gtk.Window
pixbuf *gdk.Pixbuf
image *gtk.Image
}
func (w *VideoCaptureWindow) Open() {
if w.open {
return
}
w.initWidgets()
w.open = true
w.capture = newCapture(w)
}
func (w *VideoCaptureWindow) Close() {
if !w.open {
return
}
w.window.Destroy()
}
func (w *VideoCaptureWindow) initWidgets() {
var err error
w.window, err = gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
fatal(err)
w.window.SetTitle("Video Capture Demo")
w.window.SetIconName("camera-web")
w.window.SetPosition(gtk.WIN_POS_CENTER)
w.window.SetResizable(false)
w.window.Connect("destroy", w.windowDestroyed)
w.pixbuf, err = gdk.PixbufNew(gdk.COLORSPACE_RGB, true, 8,
w.DeviceConfig.Width, w.DeviceConfig.Height)
fatal(err)
for p := w.pixbuf.GetPixels(); len(p) > 0; p = p[1:] {
p[0] = 0
}
w.image, err = gtk.ImageNew()
fatal(err)
w.image.SetFromPixbuf(w.pixbuf)
w.window.Add(w.image)
w.window.ShowAll()
}
func (w *VideoCaptureWindow) windowDestroyed() {
w.capture.cancel()
*w = VideoCaptureWindow{
DevicePath: w.DevicePath,
DeviceConfig: w.DeviceConfig,
OnClose: w.OnClose,
}
w.OnClose()
}
func (w *VideoCaptureWindow) modalError(prefix string, err error) {
msg := prefix + ": " + err.Error()
dlg := gtk.MessageDialogNew(w.window,
gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, msg)
dlg.SetTitle("Error")
dlg.SetPosition(gtk.WIN_POS_CENTER_ON_PARENT)
dlg.Connect("response", dlg.Destroy)
dlg.Connect("destroy", w.window.Destroy)
dlg.ShowAll()
}
type capture struct {
cancelled bool
w *VideoCaptureWindow
yuyv *yuyv.Image
}
func newCapture(w *VideoCaptureWindow) *capture {
c := &capture{w: w}
go c.captureFrames(w.DevicePath, w.DeviceConfig)
return c
}
func (c *capture) cancel() {
c.cancelled = true
}
func (c *capture) captureFrames(path string, config v4l.DeviceConfig) {
device, err := v4l.Open(path)
if err != nil {
c.modalError("Open", err)
return
}
defer device.Close()
if err := device.SetConfig(config); err != nil {
c.modalError("SetConfig", err)
return
}
if err := device.TurnOn(); err != nil {
c.modalError("TurnOn", err)
return
}
config, err = device.GetConfig()
if err != nil {
c.modalError("GetConfig", err)
return
}
if config.Format != yuyv.FourCC {
c.modalError("SetConfig", errors.New("failed to set YUYV format"))
return
}
binfo, err := device.BufferInfo()
if err != nil {
c.modalError("BufferInfo", err)
return
}
c.yuyv = &yuyv.Image{
Pix: make([]byte, binfo.BufferSize),
Stride: binfo.ImageStride,
Rect: image.Rect(0, 0, config.Width, config.Height),
}
for {
buffer, err := device.Capture()
if err != nil {
c.modalError("Capture", err)
return
}
buffer.ReadAt(c.yuyv.Pix, 0)
ok := c.updateImage()
if !ok {
return
}
}
}
func (c *capture) modalError(prefix string, err error) {
ch := make(chan struct{})
glib.IdleAdd(func() {
if !c.cancelled {
c.w.modalError(prefix, err)
}
ch <- struct{}{}
})
<-ch
}
func (c *capture) updateImage() bool {
ch := make(chan bool)
glib.IdleAdd(func() {
if c.cancelled {
ch <- false
return
}
w := c.w
rgba := &image.RGBA{
Pix: w.pixbuf.GetPixels(),
Stride: w.pixbuf.GetRowstride(),
Rect: image.Rect(0, 0, w.pixbuf.GetWidth(), w.pixbuf.GetHeight()),
}
yuyv.ToRGBA(rgba, rgba.Rect, c.yuyv, c.yuyv.Rect.Min)
w.image.SetFromPixbuf(c.w.pixbuf)
ch <- true
})
return <-ch
}
type ControlPanelWindow struct {
DevicePath string
OnClose func()
open bool
device *v4l.Device
controls []v4l.ControlInfo
updaters []updater
ticker *ticker
window *gtk.Window
}
type updater func(int32)
func (w *ControlPanelWindow) Open() {
if w.open {
return
}
w.initWidgets()
w.open = true
w.initControls()
w.updateControls()
w.ticker = newTicker(100, w.updateControls)
}
func (w *ControlPanelWindow) Close() {
if !w.open {
return
}
w.window.Destroy()
}
func (w *ControlPanelWindow) initWidgets() {
var err error
w.window, err = gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
fatal(err)
w.window.SetTitle("Control Panel")
w.window.SetIconName("camera-web")
w.window.SetPosition(gtk.WIN_POS_CENTER)
w.window.SetSizeRequest(640, 320)
w.window.Connect("destroy", w.windowDestroyed)
w.window.ShowAll()
}
func (w *ControlPanelWindow) initControls() {
var err error
w.device, err = v4l.Open(w.DevicePath)
if err != nil {
w.modalError("Open", err)
return
}
w.controls, err = w.device.ListControls()
if err != nil {
w.modalError("ListControls", err)
return
}
notebook, err := gtk.NotebookNew()
fatal(err)
notebook.SetScrollable(true)
notebook.SetShowBorder(false)
w.window.Add(notebook)
tabs := make(map[uint32]*gtk.Grid)
for i, ctrl := range w.controls {
class := (ctrl.CID & 0x0fff0000) >> 16
grid, ok := tabs[class]
if !ok {
grid, err = gtk.GridNew()
fatal(err)
grid.SetBorderWidth(12)
grid.SetColumnSpacing(12)
grid.SetRowSpacing(12)
grid.SetRowHomogeneous(true)
grid.SetVAlign(gtk.ALIGN_START)
className := ctrlClassNames[class]
if len(className) == 0 {
className = fmt.Sprintf("Class %03x", class)
}
notebook.AppendPage(grid, labelNew(className))
tabs[class] = grid
}
frame, err := gtk.FrameNew("")
fatal(err)
if ctrl.Type != "button" {
grid.Attach(labelNew(ctrl.Name), 0, i, 1, 1)
}
if ctrl.Type != "int" {
frame.SetHAlign(gtk.ALIGN_START)
frame.SetVAlign(gtk.ALIGN_CENTER)
}
frame.SetShadowType(gtk.SHADOW_NONE)
grid.Attach(frame, 1, i, 1, 1)
var upd updater
switch ctrl.Type {
case "int":
upd = w.createIntControl(&frame.Container, ctrl)
case "bool":
upd = w.createBoolControl(&frame.Container, ctrl)
case "enum":
upd = w.createEnumControl(&frame.Container, ctrl)
case "button":
upd = w.createButtonControl(&frame.Container, ctrl)
}
w.updaters = append(w.updaters, upd)
}
notebook.ShowAll()
}
var ctrlClassNames = map[uint32]string{
0x098: "User Controls",
0x099: "Codec",
0x09a: "Camera",
0x09b: "FM Modulator",
0x09c: "Flash",
0x09d: "JPEG",
0x09e: "Image Source",
0x09f: "Image Processing",
0x0a0: "Digital Video",
0x0a1: "FM Receiver",
0x0a2: "RF Tuner",
0x0a3: "Detection",
0x0a4: "Stateless Codec",
0x0a5: "Colorimetry",
}
func (w *ControlPanelWindow) createIntControl(parent *gtk.Container, ctrl v4l.ControlInfo) updater {
var err error
box, err := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 6)
fatal(err)
parent.Add(box)
scale, err := gtk.ScaleNewWithRange(gtk.ORIENTATION_HORIZONTAL,
float64(ctrl.Min), float64(ctrl.Max), float64(ctrl.Step))
fatal(err)
scale.SetHExpand(true)
scale.SetProperty("draw-value", false)
box.Add(scale)
frame, err := gtk.FrameNew("")
fatal(err)
frame.SetShadowType(gtk.SHADOW_NONE)
frame.SetSizeRequest(50, 0)
box.Add(frame)
label, err := gtk.LabelNew("")
fatal(err)
label.SetHAlign(gtk.ALIGN_END)
frame.Add(label)
scale.Connect("value-changed", func() {
value := scale.GetValue()
if value >= 0 {
value += 0.5
} else {
value -= 0.5
}
w.device.SetControl(ctrl.CID, int32(value))
w.updateControls()
})
return func(value int32) {
scale.SetValue(float64(value))
label.SetLabel(strconv.Itoa(int(value)))
}
}
func (w *ControlPanelWindow) createBoolControl(parent *gtk.Container, ctrl v4l.ControlInfo) updater {
checkButton, err := gtk.CheckButtonNew()
fatal(err)
checkButton.SetHExpand(false)
checkButton.SetVExpand(false)
parent.Add(checkButton)
checkButton.Connect("toggled", func() {
value := int32(0)
if checkButton.GetActive() {
value = 1
}
w.device.SetControl(ctrl.CID, value)
w.updateControls()
})
return func(value int32) {
active := false
if value != 0 {
active = true
}
checkButton.SetActive(active)
}
}
func (w *ControlPanelWindow) createEnumControl(parent *gtk.Container, ctrl v4l.ControlInfo) updater {
comboBox, err := gtk.ComboBoxTextNew()
fatal(err)
parent.Add(comboBox)
for _, opt := range ctrl.Options {
comboBox.Append("", opt.Name)
}
comboBox.Connect("changed", func() {
value := ctrl.Options[comboBox.GetActive()].Value
w.device.SetControl(ctrl.CID, value)
w.updateControls()
})
return func(value int32) {
for i, opt := range ctrl.Options {
if opt.Value == value {
comboBox.SetActive(i)
break
}
}
}
}
func (w *ControlPanelWindow) createButtonControl(parent *gtk.Container, ctrl v4l.ControlInfo) updater {
button, err := gtk.ButtonNewWithLabel(ctrl.Name)
fatal(err)
parent.Add(button)
button.Connect("clicked", func() {
w.device.SetControl(ctrl.CID, 0)
w.updateControls()
})
return nil
}
func (w *ControlPanelWindow) windowDestroyed() {
w.ticker.cancel()
if w.device != nil {
w.device.Close()
}
*w = ControlPanelWindow{
DevicePath: w.DevicePath,
OnClose: w.OnClose,
}
w.OnClose()
}
func (w *ControlPanelWindow) updateControls() {
for i, ctrl := range w.controls {
if ctrl.Type == "button" {
continue
}
value, err := w.device.GetControl(ctrl.CID)
if err != nil {
continue
}
if w.updaters[i] != nil {
w.updaters[i](value)
}
}
}
func (w *ControlPanelWindow) modalError(prefix string, err error) {
msg := prefix + ": " + err.Error()
dlg := gtk.MessageDialogNew(w.window,
gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, msg)
dlg.SetTitle("Error")
dlg.SetPosition(gtk.WIN_POS_CENTER_ON_PARENT)
dlg.Connect("response", dlg.Destroy)
dlg.Connect("destroy", w.window.Destroy)
dlg.ShowAll()
}
type ticker struct {
interval uint
callback func()
cancelled bool
}
func newTicker(interval uint, callback func()) *ticker {
t := &ticker{
interval: interval,
callback: callback,
}
glib.TimeoutAdd(interval, t.handler)
return t
}
func (t *ticker) cancel() {
t.cancelled = true
}
func (t *ticker) handler() bool {
if t.cancelled {
return false
}
t.callback()
return true
}
func deviceListsEqual(d1, d2 []v4l.DeviceInfo) bool {
if len(d1) != len(d2) {
return false
}
for i := range d1 {
if d1[i] != d2[i] {
return false
}
}
return true
}
func cfg2str(cfg v4l.DeviceConfig) string {
w := cfg.Width
h := cfg.Height
f := cfg.FPS
return fmt.Sprintf("%dx%d @ %.4g FPS", w, h, float64(f.N)/float64(f.D))
}
func labelNew(s string) *gtk.Label {
l, err := gtk.LabelNew(s)
fatal(err)
l.SetHAlign(gtk.ALIGN_START)
return l
}
func fatal(err error) {
if err != nil {
panic(err)
}
}
golang-github-korandiz-v4l-1.1.0/device.go 0000664 0000000 0000000 00000052212 14545740134 0020361 0 ustar 00root root 0000000 0000000 // Package v4l, a facade to the Video4Linux video capture interface
// Copyright (C) 2016 Zoltán Korándi
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//go:build linux
// +build linux
// Package v4l is a facade to the Video4Linux video capture interface.
package v4l
import "syscall"
// Control IDs. Devices may have other controls than these, including custom
// (driver specific) ones.
const (
// Integer controls
CtrlBrightness = 0x00980900
CtrlContrast = 0x00980901
CtrlSaturation = 0x00980902
CtrlHue = 0x00980903
CtrlGamma = 0x00980910
CtrlExposure = 0x00980911
CtrlGain = 0x00980913
CtrlWhiteBalance = 0x0098091a
CtrlSharpness = 0x0098091b
CtrlBacklightCompensation = 0x0098091c
// Boolean controls
CtrlHFlip = 0x00980914
CtrlVFlip = 0x00980915
CtrlAutoWhiteBalance = 0x0098090c
CtrlAutoGain = 0x00980912
CtrlAutoHue = 0x00980919
CtrlAutoBrightness = 0x00980920
// Enums
CtrlPowerLineFreq = 0x00980918
PowerLineFreqDisabled = 0
PowerLineFreq50Hz = 1
PowerLineFreq60Hz = 2
PowerLineFreqAuto = 3
// Buttons
CtrlDoWhiteBalance = 0x0098090d
)
// A Device represents a V4L capture device.
type Device struct {
*device
}
// device is the real representation of Device. The extra level of indirection
// is there to prevent clients from tampering with the file descriptor and the
// buffers.
type device struct {
path string
fd int
buffers [][]byte
bufIndex uint32
nCaptures uint64
}
// noBuffer is the value assinged to device.bufIndex when none of the buffers
// contain valid image data.
const noBuffer = ^uint32(0)
// A DeviceInfo provides information about a capture device.
type DeviceInfo struct {
// Path is the device path. (e.g. /dev/video0)
Path string
// DeviceName is the name of the device. (e.g. "Yoyodyne TV/FM")
DeviceName string
// BusInfo is the location of the device in the system.
// (e.g. "PCI:0000:05:06.0")
BusInfo string
// DriverName is the name of the driver. (e.g. "bttv")
DriverName string
// DriverVersion contains the three components of the driver's version
// number. (e.g. [3]int{1, 2, 3} for version 1.2.3)
DriverVersion [3]int
// Camera tells if the device is a camera. If false, then this is some other
// kind of capture device, e.g. an analog TV tuner.
Camera bool
}
// A DeviceConfig encapsulates the configuration of a capture device.
type DeviceConfig struct {
// Format is the four-character code (FourCC) of the pixel format, with the
// first character at the lowest byte.
Format uint32
// Width and Height specify the image dimensions.
Width int
Height int
// FPS specifies the frame rate.
FPS Frac
}
// A BufferInfo provides information about how image data is laid out in a
// buffer.
type BufferInfo struct {
// BufferSize is the number of bytes required to hold an image. For variable
// length compressed formats, it's the maximum size an image may take up.
BufferSize int
// ImageStride is the distance in bytes between the leftmost pixels of
// adjacent lines.
ImageStride int
}
// A ControlInfo provides information about a control.
type ControlInfo struct {
// CID is the identifier of the control. (e.g. 0x00980900)
CID uint32
// Name is the name of the control. (e.g. "Brightness")
Name string
// Type tells what kind of control this is. It's one of "int", "bool",
// "enum", "int-enum", or "button".
// - The valid values of an integer control are determined by Min, Max,
// and Step.
// - A boolean control can only have the values 0 and 1, where 0 means
// "disabled" and 1 means "enabled".
// - Enums can only take values from a predefined set. The values are
// identifiers which select one of a few named options. (see Options)
// - An "int-enum" is similar to an enum, except that, the options are
// 64-bit unsigned integers, rather than strings.
// - Buttons perform some action when pushed, and they don't have a value.
// Reading the value of a button fails, while setting it to any value is
// interpreted as a push.
Type string
// Min and Max specify the range of values the control can take, and Step is
// the smallest change actually affecting the hardware. They are only
// meaningful for integer type controls.
Min int32
Max int32
Step int32
// Default is the default value of the control.
Default int32
// Options is the list of valid values of an enum or int-enum type control.
// For other types it's nil.
Options []struct {
// Value is the identifier of this option. (e.g. 0, 1, 2, etc)
Value int32
// Name is the label of this option. Only valid for enum type controls.
// (e.g. "50 Hz", "60 Hz", "Auto")
Name string
// Int64 is the integer value of this option. Only valid for int-enum
// type controls. (e.g. 0, 333, 667)
Int64 int64
}
}
// errBadControl is returned by Device.controlInfo when the control is disabled
// or of unsupported type.
const errBadControl = Error("control disabled or of unsupported type")
// Open opens the capture device named by path. If the file is not a capture
// device, it fails with ErrWrongDevice.
func Open(path string) (*Device, error) {
// Open the file.
fd, err := syscall.Open(path, syscall.O_RDWR|syscall.O_CLOEXEC, 0)
if err != nil {
return nil, err
}
// Check if it's a V4L device.
var stat syscall.Stat_t
if err := syscall.Fstat(fd, &stat); err != nil {
syscall.Close(fd)
return nil, err
}
if stat.Mode&syscall.S_IFCHR == 0 || stat.Rdev>>8 != 81 {
syscall.Close(fd)
return nil, ErrWrongDevice
}
// Check if it's a capture device.
var c v4l_capability
if err := ioctl_querycap(fd, &c); err != nil {
syscall.Close(fd)
return nil, err
}
caps := c.capabilities
if caps&v4l_capDeviceCaps != 0 {
caps = c.deviceCaps
}
if caps&v4l_capVideoCapture == 0 {
syscall.Close(fd)
return nil, ErrWrongDevice
}
d := device{path: path, fd: fd, bufIndex: noBuffer}
return &Device{&d}, nil
}
// Close closes the device, freeing all native resources associated with it. It
// stops any capture session in progress, and it may also render the contents of
// previously captured buffers unavailable.
func (d *Device) Close() {
d.TurnOff()
syscall.Close(d.fd)
d.fd = -1
}
// DeviceInfo returns information about the device.
func (d *Device) DeviceInfo() (DeviceInfo, error) {
// Query capabilities.
var c v4l_capability
if err := ioctl_querycap(d.fd, &c); err != nil {
return DeviceInfo{}, err
}
// Check if the device is a camera. Cameras do not enumerate any video
// standards.
s := v4l_standard{index: 0}
var cam bool
switch err := ioctl_enumstd(d.fd, &s); err {
case nil:
cam = false
case syscall.ENOTTY, syscall.EINVAL:
cam = true
default:
return DeviceInfo{}, err
}
info := DeviceInfo{
Path: d.path,
DeviceName: c.card,
BusInfo: c.busInfo,
DriverName: c.driver,
DriverVersion: [3]int{
int(c.version>>16) & 0xff,
int(c.version>>8) & 0xff,
int(c.version) & 0xff,
},
Camera: cam,
}
return info, nil
}
// TurnOn initiates a capture session with the device. It may fail with
// ErrUnsupported. While the device is turned on, its configuration cannot be
// changed.
func (d *Device) TurnOn() error {
// Switch to progressive format and reset the colorspace to device default.
f := v4l_format_pix{typ: v4l_bufTypeVideoCapture}
if err := ioctl_gFmt_pix(d.fd, &f); err != nil {
return err
}
f.fmt.field = v4l_fieldNone
f.fmt.colorspace = v4l_colorspaceDefault
f.fmt.priv = 0
if err := ioctl_sFmt_pix(d.fd, &f); err != nil {
return err
}
// Reset cropping.
cc := v4l_cropcap{typ: v4l_bufTypeVideoCapture}
switch err := ioctl_cropcap(d.fd, &cc); err {
case nil:
c := v4l_crop{
typ: v4l_bufTypeVideoCapture,
c: cc.defrect,
}
switch err := ioctl_sCrop(d.fd, &c); err {
case nil:
// Success.
case syscall.ENOTTY, syscall.EINVAL:
// VIDIOC_S_CROP unsupported.
default:
return err
}
case syscall.ENOTTY:
// No support for cropping. That's okay.
default:
return err
}
// Allocate buffers.
if err := d.allocBuffers(4); err != nil {
return err
}
// Start streaming I/O.
if err := ioctl_streamon(d.fd, v4l_bufTypeVideoCapture); err != nil {
d.freeBuffers()
return err
}
return nil
}
// TurnOff ends the capture session in progress. It does not close the device,
// so it can be reused for another session.
func (d *Device) TurnOff() {
ioctl_streamoff(d.fd, v4l_bufTypeVideoCapture)
d.freeBuffers()
}
// allocBuffers allocates n buffers in device memory, and mmaps and queues them.
func (d *Device) allocBuffers(n int) error {
// Request buffers.
rb := v4l_requestbuffers{
count: uint32(n),
typ: v4l_bufTypeVideoCapture,
memory: v4l_memoryMmap,
}
if err := ioctl_reqbufs(d.fd, &rb); err != nil {
if err == syscall.EINVAL {
// Memory-mapped I/O method unsupported.
err = ErrUnsupported
}
return err
}
if rb.count == 0 {
return Error("out of device memory")
}
// Map and enqueue the buffers.
d.buffers = make([][]byte, 0, rb.count)
for i := 0; i < cap(d.buffers); i++ {
b := v4l_buffer{
index: uint32(i),
typ: v4l_bufTypeVideoCapture,
memory: v4l_memoryMmap,
}
if err := ioctl_querybuf(d.fd, &b); err != nil {
d.freeBuffers()
return err
}
buf, err := syscall.Mmap(d.fd, int64(b.offset), int(b.length),
syscall.PROT_READ, syscall.MAP_SHARED)
if err != nil {
d.freeBuffers()
return err
}
d.buffers = append(d.buffers, buf)
if err := ioctl_qbuf(d.fd, &b); err != nil {
d.freeBuffers()
return err
}
}
return nil
}
// freeBuffers munmaps and frees any buffers allocated in device memory, and
// removes all pointers to them.
func (d *Device) freeBuffers() {
d.bufIndex = noBuffer
for i := range d.buffers {
syscall.Munmap(d.buffers[i])
d.buffers[i] = nil
}
d.buffers = nil
rb := v4l_requestbuffers{
count: 0,
typ: v4l_bufTypeVideoCapture,
memory: v4l_memoryMmap,
}
ioctl_reqbufs(d.fd, &rb)
}
// Capture grabs the next frame, and returns a new Buffer holding the raw image
// data. The device must be turned on for Capture to succeed. A call to Capture
// may render the contents of previously captured buffers unavailable.
func (d *Device) Capture() (*Buffer, error) {
d.nCaptures++
// Enqueue the old buffer (if any).
if d.bufIndex != noBuffer {
b := v4l_buffer{
typ: v4l_bufTypeVideoCapture,
memory: v4l_memoryMmap,
index: d.bufIndex,
}
d.bufIndex = noBuffer
if err := ioctl_qbuf(d.fd, &b); err != nil {
return nil, err
}
}
// Dequeue a new buffer.
b := v4l_buffer{
typ: v4l_bufTypeVideoCapture,
memory: v4l_memoryMmap,
}
if err := ioctl_dqbuf(d.fd, &b); err != nil {
return nil, err
}
d.buffers[b.index] = d.buffers[b.index][:b.bytesused]
d.bufIndex = b.index
return &Buffer{d.device, d.nCaptures, 0, b.sequence}, nil
}
// GetConfig returns the current configuration of the device.
func (d *Device) GetConfig() (DeviceConfig, error) {
// Get format.
f := v4l_format_pix{typ: v4l_bufTypeVideoCapture}
if err := ioctl_gFmt_pix(d.fd, &f); err != nil {
return DeviceConfig{}, err
}
// Get streaming parameters.
p := v4l_streamparm_capture{typ: v4l_bufTypeVideoCapture}
if err := ioctl_gParm_capture(d.fd, &p); err != nil {
return DeviceConfig{}, err
}
cfg := DeviceConfig{
Format: f.fmt.pixelformat,
Width: int(f.fmt.width),
Height: int(f.fmt.height),
FPS: Frac{
p.parm.timeperframe.denominator,
p.parm.timeperframe.numerator,
},
}
return cfg, nil
}
// SetConfig configures the device according to cfg. The configuration actually
// applied may be different from what was requested, as drivers are allowed to
// adjust the parameters against hardware capabilities (or even completely
// ignore them). The configuration cannot be changed while the device is turned
// on.
func (d *Device) SetConfig(cfg DeviceConfig) error {
// Set format.
f := v4l_format_pix{
typ: v4l_bufTypeVideoCapture,
fmt: v4l_pixFormat{
width: uint32(cfg.Width),
height: uint32(cfg.Height),
pixelformat: cfg.Format,
field: v4l_fieldNone,
colorspace: v4l_colorspaceDefault,
priv: 0,
},
}
if err := ioctl_sFmt_pix(d.fd, &f); err != nil {
return err
}
// Set streaming parameters.
cfg.FPS = cfg.FPS.Reduce()
p := v4l_streamparm_capture{
typ: v4l_bufTypeVideoCapture,
parm: v4l_captureparm{
timeperframe: v4l_fract{cfg.FPS.D, cfg.FPS.N},
},
}
if err := ioctl_sParm_capture(d.fd, &p); err != nil {
return err
}
return nil
}
// BufferInfo returns information about how image data is laid out in a buffer.
// For the same device configuration it always returns the same value.
func (d *Device) BufferInfo() (BufferInfo, error) {
f := v4l_format_pix{typ: v4l_bufTypeVideoCapture}
if err := ioctl_gFmt_pix(d.fd, &f); err != nil {
return BufferInfo{}, err
}
info := BufferInfo{
BufferSize: int(f.fmt.sizeimage),
ImageStride: int(f.fmt.bytesperline),
}
return info, nil
}
// ListConfigs returns the configurations supported by the device.
func (d *Device) ListConfigs() ([]DeviceConfig, error) {
var cfgs []DeviceConfig
for fmt := 0; ; fmt++ {
fd := v4l_fmtdesc{
index: uint32(fmt),
typ: v4l_bufTypeVideoCapture,
}
if err := ioctl_enumFmt(d.fd, &fd); err != nil {
if err != syscall.EINVAL {
return nil, err
}
break
}
sizes, err := d.enumFrameSizes(fd.pixelformat)
if err != nil {
return nil, err
}
for _, sz := range sizes {
ivals, err := d.enumFrameIvals(fd.pixelformat, sz.width, sz.height)
if err != nil {
return nil, err
}
for _, ival := range ivals {
cfg := DeviceConfig{
Format: fd.pixelformat,
Width: int(sz.width),
Height: int(sz.height),
FPS: Frac{
ival.denominator,
ival.numerator,
}.Reduce(),
}
cfgs = append(cfgs, cfg)
}
}
}
// Some devices/drivers seem to return duplicates. Fix that.
n := 0
for i := 0; i < len(cfgs); i++ {
dupe := false
for j := 0; j < n && !dupe; j++ {
dupe = cfgs[i] == cfgs[j]
}
if !dupe {
cfgs[n] = cfgs[i]
n++
}
}
cfgs = cfgs[:n]
return cfgs, nil
}
// enumFrameSizes returns the supported frame sizes. If the device does not
// enumerate a discrete set of frame sizes, then a few common ones within the
// supported range are returned.
func (d *Device) enumFrameSizes(fmt uint32) ([]v4l_frmsizeDiscrete, error) {
var (
sizes []v4l_frmsizeDiscrete
fs v4l_frmsizeenum
)
// Try to enumerate discrete frame sizes.
loop:
for index := 0; ; index++ {
fs = v4l_frmsizeenum{
index: uint32(index),
pixelFormat: fmt,
}
if err := ioctl_enumFramesizes(d.fd, &fs); err != nil {
if err != syscall.EINVAL {
return nil, err
}
return sizes, nil
}
switch fs.typ {
case v4l_frmsizeTypeDiscrete:
sizes = append(sizes, fs.discrete)
case v4l_frmsizeTypeContinuous, v4l_frmsizeTypeStepwise:
break loop
default:
return nil, nil
}
}
// Fall back to a default list.
fss := fs.stepwise
for _, fsd := range defaultFrameSizes {
if fsd.width < fss.minWidth || fsd.width > fss.maxWidth ||
(fsd.width-fss.minWidth)%fss.stepWidth != 0 {
continue
}
if fsd.height < fss.minHeight || fsd.height > fss.maxHeight ||
(fsd.height-fss.minHeight)%fss.stepHeight != 0 {
continue
}
sizes = append(sizes, fsd)
}
sizes = append(sizes, v4l_frmsizeDiscrete{fss.maxWidth, fss.maxHeight})
return sizes, nil
}
// defaultFrameSizes lists a few common resolutions.
var defaultFrameSizes = []v4l_frmsizeDiscrete{
{160, 120},
{176, 144},
{320, 180},
{320, 240},
{352, 288},
{640, 360},
{640, 480},
{800, 600},
{960, 540},
{1024, 768},
{1280, 720},
{1280, 960},
{1600, 1200},
{1920, 1080},
{3840, 2160},
{7680, 4320},
}
// enumFrameIvals returns the supported frame intervals. If the device does not
// enumerate a discrete set of frame intervals, then a few common ones within
// the supported range are returned.
func (d *Device) enumFrameIvals(fmt, w, h uint32) ([]v4l_fract, error) {
var (
ivals []v4l_fract
fi v4l_frmivalenum
)
// Try to enumerate discrete frame intervals.
loop:
for index := 0; ; index++ {
fi = v4l_frmivalenum{
index: uint32(index),
pixelFormat: fmt,
width: w,
height: h,
}
if err := ioctl_enumFrameintervals(d.fd, &fi); err != nil {
if err != syscall.EINVAL {
return nil, err
}
return ivals, nil
}
switch fi.typ {
case v4l_frmivalTypeDiscrete:
ivals = append(ivals, fi.discrete)
case v4l_frmivalTypeContinuous, v4l_frmivalTypeStepwise:
break loop
default:
return nil, nil
}
}
// Fall back to a default list.
var (
fis = fi.stepwise
min_n = fis.min.numerator
min_d = fis.min.denominator
max_n = fis.max.numerator
max_d = fis.max.denominator
)
for _, fid := range defaultFrameIntervals {
if fid.numerator*min_d < min_n*fid.denominator ||
fid.numerator*max_d > max_n*fid.denominator {
continue
}
ivals = append(ivals, fid)
}
ivals = append(ivals, fis.min)
return ivals, nil
}
// defaultFrameIntervals lists a few common frame intervals.
var defaultFrameIntervals = []v4l_fract{
{1, 5},
{1, 10},
{1, 15},
{1, 25},
{1, 30},
{1, 60},
}
// ControlInfo returns information about a control.
func (d *Device) ControlInfo(cid uint32) (ControlInfo, error) {
info, err := d.controlInfo(cid)
if err == errBadControl {
// Pretend the control does not exist.
err = syscall.EINVAL
}
return info, err
}
// ListControls returns the ControlInfo for every control the device has.
func (d *Device) ListControls() ([]ControlInfo, error) {
var (
lastCID uint32
infos []ControlInfo
)
for {
info, err := d.controlInfo(lastCID | v4l_ctrlFlagNextCtrl)
switch err {
case nil:
infos = append(infos, info)
lastCID = info.CID
case errBadControl:
// Pretend the control does not exist.
lastCID = info.CID
case syscall.EINVAL:
if lastCID == 0 {
// No support for v4l_ctrlFlagNextCtrl.
// Fall back to legacy method.
return d.listControlsLegacy()
}
return infos, nil
default:
return nil, err
}
}
}
// listControlsLegacy enumerates all controls the device has by querying them
// one-by-one rather than using the v4l_ctrlFlagNextCtrl flag.
func (d *Device) listControlsLegacy() ([]ControlInfo, error) {
var infos []ControlInfo
// Standard controls.
for cid := uint32(v4l_cidBase); cid < v4l_cidLastp1; cid++ {
info, err := d.controlInfo(cid)
if err != nil {
if err == syscall.EINVAL || err == errBadControl {
continue
}
return nil, err
}
infos = append(infos, info)
}
// Custom controls.
for cid := uint32(v4l_cidPrivateBase); ; cid++ {
info, err := d.controlInfo(cid)
if err != nil {
if err == syscall.EINVAL {
break
}
if err == errBadControl {
continue
}
return nil, err
}
infos = append(infos, info)
}
return infos, nil
}
// controlInfo returns information about a control. For disabled contorls and
// contorls of unsupported type it fails with errBadControl.
func (d *device) controlInfo(cid uint32) (ControlInfo, error) {
qc := v4l_queryctrl{id: cid}
if err := ioctl_queryctrl(d.fd, &qc); err != nil {
return ControlInfo{}, err
}
info := ControlInfo{
CID: qc.id,
Name: qc.name,
Min: qc.minimum,
Max: qc.maximum,
Step: qc.step,
Default: qc.defaultValue,
}
if qc.flags&v4l_ctrlFlagDisabled != 0 {
return info, errBadControl
}
switch qc.typ {
case v4l_ctrlTypeInteger:
info.Type = "int"
case v4l_ctrlTypeBoolean:
info.Type = "bool"
case v4l_ctrlTypeMenu:
info.Type = "enum"
case v4l_ctrlTypeButton:
info.Type = "button"
case v4l_ctrlTypeIntegerMenu:
info.Type = "int-enum"
default:
return info, errBadControl
}
if qc.typ == v4l_ctrlTypeMenu || qc.typ == v4l_ctrlTypeIntegerMenu {
for i := qc.minimum; i <= qc.maximum; i++ {
qm := v4l_querymenu{
id: qc.id,
index: uint32(i),
}
if err := ioctl_querymenu(d.fd, &qm); err != nil {
if err == syscall.EINVAL {
continue
}
return ControlInfo{}, err
}
opt := struct {
Value int32
Name string
Int64 int64
}{
Value: int32(qm.index),
}
if qc.typ == v4l_ctrlTypeMenu {
opt.Name = qm.name
} else {
opt.Int64 = qm.value
}
info.Options = append(info.Options, opt)
}
}
return info, nil
}
// GetControl returns the current value of a control.
func (d *Device) GetControl(cid uint32) (int32, error) {
c := v4l_control{id: cid}
if err := ioctl_gCtrl(d.fd, &c); err != nil {
return 0, err
}
return c.value, nil
}
// SetControl sets the value of a control.
func (d *Device) SetControl(cid uint32, value int32) error {
c := v4l_control{
id: cid,
value: value,
}
if err := ioctl_sCtrl(d.fd, &c); err != nil {
return err
}
return nil
}
golang-github-korandiz-v4l-1.1.0/errors.go 0000664 0000000 0000000 00000002667 14545740134 0020447 0 ustar 00root root 0000000 0000000 // Package v4l, a facade to the Video4Linux video capture interface
// Copyright (C) 2016 Zoltán Korándi
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//go:build linux
// +build linux
package v4l
// An Error is simply an error message.
type Error string
// Error returns e as a string.
func (e Error) Error() string {
return string(e)
}
const (
// ErrWrongDevice is returned by Open when attempting to open a file that is
// not a V4L capture device.
ErrWrongDevice = Error("not a V4L capture device")
// ErrUnsupported indicates that an operation failed due to a limitation of
// this library.
ErrUnsupported = Error("unsupported device or operation")
// ErrBufferGone is returned by methods of Buffer when the contents of the
// buffer is no longer available.
ErrBufferGone = Error("buffer contents not available")
)
golang-github-korandiz-v4l-1.1.0/find.go 0000664 0000000 0000000 00000003310 14545740134 0020035 0 ustar 00root root 0000000 0000000 // Package v4l, a facade to the Video4Linux video capture interface
// Copyright (C) 2016 Zoltán Korándi
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//go:build linux
// +build linux
package v4l
import (
"os"
"path/filepath"
"syscall"
)
// FindDevices returns the DeviceInfo for every capture device found in the
// system. The paths are always returned in absolute form.
func FindDevices() []DeviceInfo {
var (
devs = make(map[int]string)
dInfos []DeviceInfo
)
filepath.Walk("/dev", func(path string, fInfo os.FileInfo, _ error) error {
if fInfo == nil || fInfo.Mode()&os.ModeCharDevice == 0 {
return nil
}
var stat syscall.Stat_t
if err := syscall.Stat(path, &stat); err != nil {
return nil
}
major, minor := int(stat.Rdev>>8), int(stat.Rdev&255)
if major != 81 {
return nil
}
if _, ok := devs[minor]; ok {
return nil
}
dev, err := Open(path)
if err != nil {
return nil
}
defer dev.Close()
dInfo, err := dev.DeviceInfo()
if err != nil {
return nil
}
dInfos = append(dInfos, dInfo)
devs[minor] = path
return nil
})
return dInfos
}
golang-github-korandiz-v4l-1.1.0/fmt/ 0000775 0000000 0000000 00000000000 14545740134 0017357 5 ustar 00root root 0000000 0000000 golang-github-korandiz-v4l-1.1.0/fmt/mjpeg/ 0000775 0000000 0000000 00000000000 14545740134 0020461 5 ustar 00root root 0000000 0000000 golang-github-korandiz-v4l-1.1.0/fmt/mjpeg/fourcc.go 0000664 0000000 0000000 00000001757 14545740134 0022303 0 ustar 00root root 0000000 0000000 // Package v4l, a facade to the Video4Linux video capture interface
// Copyright (C) 2016 Zoltán Korándi
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
// Package mjpeg just defines the FourCC of the MJPEG format.
//
// An MJPEG stream is simply a sequence of JPEG images. Use the image/jpeg
// package for decoding.
package mjpeg
const FourCC = 'M' | 'J'<<8 | 'P'<<16 | 'G'<<24
golang-github-korandiz-v4l-1.1.0/fmt/yuyv/ 0000775 0000000 0000000 00000000000 14545740134 0020373 5 ustar 00root root 0000000 0000000 golang-github-korandiz-v4l-1.1.0/fmt/yuyv/convert.go 0000664 0000000 0000000 00000011041 14545740134 0022377 0 ustar 00root root 0000000 0000000 // Package v4l, a facade to the Video4Linux video capture interface
// Copyright (C) 2016 Zoltán Korándi
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
package yuyv
import "image"
// ToRGBA aligns r.Min in dst with p in src, and draws the part of src visible
// through r over src.
//
// It's several times faster than the image/draw package.
func ToRGBA(dst *image.RGBA, r image.Rectangle, src *Image, p image.Point) {
v := p.Sub(r.Min)
r = r.Intersect(dst.Rect).Intersect(src.Rect.Sub(v))
p = r.Min.Add(v)
if r.Empty() {
return
}
for y := 0; y < r.Dy(); y++ {
s := src.Pix[src.PixPairOffset(p.X, p.Y+y):]
d := dst.Pix[dst.PixOffset(r.Min.X, r.Min.Y+y):]
n := r.Dx()
if p.X&1 != 0 {
cb := int32(s[1]) - 128
y2 := int32(s[2]) * 0x010101
cr := int32(s[3]) - 128
d[0] = clamp(y2 + 91881*cr)
d[1] = clamp(y2 - 22554*cb - 46802*cr)
d[2] = clamp(y2 + 116130*cb)
d[3] = 255
s = s[4:]
d = d[4:]
n--
}
for x := 0; x < n; x += 2 {
y1 := int32(s[2*x+0]) * 0x010101
cb := int32(s[2*x+1]) - 128
y2 := int32(s[2*x+2]) * 0x010101
cr := int32(s[2*x+3]) - 128
d[4*x+0] = clamp(y1 + 91881*cr)
d[4*x+1] = clamp(y1 - 22554*cb - 46802*cr)
d[4*x+2] = clamp(y1 + 116130*cb)
d[4*x+3] = 255
if x < n-1 {
d[4*x+4] = clamp(y2 + 91881*cr)
d[4*x+5] = clamp(y2 - 22554*cb - 46802*cr)
d[4*x+6] = clamp(y2 + 116130*cb)
d[4*x+7] = 255
}
}
}
}
func clamp(x int32) uint8 {
if uint32(x)&0xff000000 == 0 {
return uint8(x >> 16)
} else {
return uint8(^(x >> 31))
}
}
// ToGray aligns r.Min in dst with p in src, and draws the part of src visible
// through r over src.
//
// It's several times faster than the image/draw package.
func ToGray(dst *image.Gray, r image.Rectangle, src *Image, p image.Point) {
v := p.Sub(r.Min)
r = r.Intersect(dst.Rect).Intersect(src.Rect.Sub(v))
p = r.Min.Add(v)
if r.Empty() {
return
}
for y := 0; y < r.Dy(); y++ {
s := src.Pix[src.PixPairOffset(p.X, p.Y+y):]
d := dst.Pix[dst.PixOffset(r.Min.X, r.Min.Y+y):]
n := r.Dx()
if p.X&1 != 0 {
cb := int32(s[1]) - 128
y2 := int32(s[2]) * 0x010101
cr := int32(s[3]) - 128
r := clamp2(y2 + 91881*cr)
g := clamp2(y2 - 22554*cb - 46802*cr)
b := clamp2(y2 + 116130*cb)
d[0] = uint8((19595*r + 38470*g + 7471*b + 1<<15) >> 24)
s = s[4:]
d = d[1:]
n--
}
for x := 0; x < n; x += 2 {
y1 := int32(s[2*x+0]) * 0x010101
cb := int32(s[2*x+1]) - 128
y2 := int32(s[2*x+2]) * 0x010101
cr := int32(s[2*x+3]) - 128
r := clamp2(y1 + 91881*cr)
g := clamp2(y1 - 22554*cb - 46802*cr)
b := clamp2(y1 + 116130*cb)
d[x] = uint8((19595*r + 38470*g + 7471*b + 1<<15) >> 24)
if x < n-1 {
r := clamp2(y2 + 91881*cr)
g := clamp2(y2 - 22554*cb - 46802*cr)
b := clamp2(y2 + 116130*cb)
d[x+1] = uint8((19595*r + 38470*g + 7471*b + 1<<15) >> 24)
}
}
}
}
func clamp2(x int32) int32 {
if uint32(x)&0xff000000 == 0 {
return (x >> 8) & 0xffff
} else {
return ^(x >> 31) & 0xffff
}
}
// ToYCbCr aligns r.Min in dst with p in src, and draws the part of src visible
// through r over src.
//
// Panics if the subsample ratio of dst is not 4:4:4.
func ToYCbCr(dst *image.YCbCr, r image.Rectangle, src *Image, p image.Point) {
if dst.SubsampleRatio != image.YCbCrSubsampleRatio444 {
panic("subsample ratio must be 4:4:4")
}
v := p.Sub(r.Min)
r = r.Intersect(dst.Rect).Intersect(src.Rect.Sub(v))
p = r.Min.Add(v)
if r.Empty() {
return
}
for y := 0; y < r.Dy(); y++ {
s := src.Pix[src.PixPairOffset(p.X, p.Y+y):]
dy := dst.Y[dst.YOffset(r.Min.X, r.Min.Y+y):]
dcb := dst.Cb[dst.COffset(r.Min.X, r.Min.Y+y):]
dcr := dst.Cr[dst.COffset(r.Min.X, r.Min.Y+y):]
n := r.Dx()
if p.X&1 != 0 {
dy[0], dcb[0], dcr[0] = s[2], s[1], s[3]
s = s[4:]
dy = dy[1:]
dcb = dcb[1:]
dcr = dcr[1:]
n--
}
for x := 0; x < n; x += 2 {
dy[x], dcb[x], dcr[x] = s[2*x], s[2*x+1], s[2*x+3]
if x < n-1 {
dy[x+1], dcb[x+1], dcr[x+1] = s[2*x+2], s[2*x+1], s[2*x+3]
}
}
}
}
golang-github-korandiz-v4l-1.1.0/fmt/yuyv/image.go 0000664 0000000 0000000 00000006763 14545740134 0022020 0 ustar 00root root 0000000 0000000 // Package v4l, a facade to the Video4Linux video capture interface
// Copyright (C) 2016 Zoltán Korándi
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
// Package yuyv provides support for the YUYV format.
package yuyv
import (
"image"
"image/color"
)
// FourCC of the YUYV format.
const FourCC = 'Y' | 'U'<<8 | 'Y'<<16 | 'V'<<24
// An Image is an in-memory YUYV image. It implements the image.Image interface.
type Image struct {
// Pix holds the pixel data. Every four bytes corresponds to a pair of
// horizontally adjacent pixels. The two pixels have separate luma values
// and shared chroma. The sample order is Y0, Cb, Y1, Cr.
Pix []uint8
// Stride is the distance in bytes between vertically adjacent pixels.
// Line y starts at index (y-Rect.Min.Y)*Stride.
Stride int
// Rect is the bounds of the image.
Rect image.Rectangle
}
// New returns a new YUYV image with the given bounds.
func New(rect image.Rectangle) *Image {
l, r := rect.Min.X&^1, (rect.Max.X+1)&^1
w, h := r-l, rect.Dy()
return &Image{make([]uint8, 2*w*h), 2 * w, rect}
}
// ColorModel returns color.YCbCrModel.
func (img *Image) ColorModel() color.Model {
return color.YCbCrModel
}
// Bounds returns the bounds of the image.
func (img *Image) Bounds() image.Rectangle {
return img.Rect
}
// At returns the color of the pixel at (x, y).
func (img *Image) At(x, y int) color.Color {
return img.YCbCrAt(x, y)
}
// YCbCrAt returns the color of the pixel at (x, y).
func (img *Image) YCbCrAt(x, y int) color.YCbCr {
if !(image.Point{x, y}.In(img.Rect)) {
return color.YCbCr{}
}
return color.YCbCr{
img.Pix[img.YOffset(x, y)],
img.Pix[img.CbOffset(x, y)],
img.Pix[img.CrOffset(x, y)],
}
}
// YOffset returns the index at which the Y component of the pixel at (x, y) is
// located in Pix.
func (img *Image) YOffset(x, y int) int {
return img.PixPairOffset(x, y) + 2*(x&1)
}
// CbOffset returns the index at which the Cb component of the pixel at (x, y)
// is located in Pix.
func (img *Image) CbOffset(x, y int) int {
return img.PixPairOffset(x, y) + 1
}
// CrOffset returns the index at which the Cr component of the pixel at (x, y)
// is located in Pix.
func (img *Image) CrOffset(x, y int) int {
return img.PixPairOffset(x, y) + 3
}
// PixPairOffset returns the index of the first element in Pix that corresponds
// to the pixel pair to which (x, y) belongs.
func (img *Image) PixPairOffset(x, y int) int {
return (y-img.Rect.Min.Y)*img.Stride + (x&^1-img.Rect.Min.X&^1)*2
}
// SubImage returns an image representing the portion of img visible through
// rect. The returned value shares pixels with the original image.
func (img *Image) SubImage(rect image.Rectangle) image.Image {
rect = rect.Intersect(img.Rect)
if rect.Empty() {
return &Image{}
}
i := img.PixPairOffset(rect.Min.X, rect.Min.Y)
return &Image{img.Pix[i:], img.Stride, rect}
}
// Opaque returns true.
func (img *Image) Opaque() bool {
return true
}
golang-github-korandiz-v4l-1.1.0/fmt/yuyv/yuyv_test.go 0000664 0000000 0000000 00000017531 14545740134 0023004 0 ustar 00root root 0000000 0000000 // Package v4l, a facade to the Video4Linux video capture interface
// Copyright (C) 2016 Zoltán Korándi
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
package yuyv
import (
"image"
"image/color"
"image/draw"
"testing"
)
var src = &Image{
Pix: []byte{
// +---+---+---+---+---+---+---+---+
// Y: | x | y | 0 | 0 |
// +---+---+---+---+---+---+---+---+
//
// +---+---+---+---+---+---+---+---+
// Cb: | x/2 | y | 0 | 0 | 1 |
// +---+---+---+---+---+---+---+---+
//
// +---+---+---+---+---+---+---+---+
// Cr: | x/2 | y | 1 | 1 | 1 |
// +---+---+---+---+---+---+---+---+
0x00, 0x01, 0x20, 0x07, 0x40, 0x41, 0x60, 0x47, 0x80, 0x81, 0xa0, 0x87, 0xc0, 0xc1, 0xe0, 0xc7, 0xff, 0xff, 0xff,
0x04, 0x09, 0x24, 0x0f, 0x44, 0x49, 0x64, 0x4f, 0x84, 0x89, 0xa4, 0x8f, 0xc4, 0xc9, 0xe4, 0xcf, 0xff, 0xff, 0xff,
0x08, 0x11, 0x28, 0x17, 0x48, 0x51, 0x68, 0x57, 0x88, 0x91, 0xa8, 0x97, 0xc8, 0xd1, 0xe8, 0xd7, 0xff, 0xff, 0xff,
0x0c, 0x19, 0x2c, 0x1f, 0x4c, 0x59, 0x6c, 0x5f, 0x8c, 0x99, 0xac, 0x9f, 0xcc, 0xd9, 0xec, 0xdf, 0xff, 0xff, 0xff,
0x10, 0x21, 0x30, 0x27, 0x50, 0x61, 0x70, 0x67, 0x90, 0xa1, 0xb0, 0xa7, 0xd0, 0xe1, 0xf0, 0xe7, 0xff, 0xff, 0xff,
0x14, 0x29, 0x34, 0x2f, 0x54, 0x69, 0x74, 0x6f, 0x94, 0xa9, 0xb4, 0xaf, 0xd4, 0xe9, 0xf4, 0xef, 0xff, 0xff, 0xff,
0x18, 0x31, 0x38, 0x37, 0x58, 0x71, 0x78, 0x77, 0x98, 0xb1, 0xb8, 0xb7, 0xd8, 0xf1, 0xf8, 0xf7, 0xff, 0xff, 0xff,
0x1c, 0x39, 0x3c, 0x3f, 0x5c, 0x79, 0x7c, 0x7f, 0x9c, 0xb9, 0xbc, 0xbf, 0xdc, 0xf9, 0xfc, 0xff, 0xff, 0xff, 0xff,
},
Stride: 19,
Rect: image.Rectangle{
Min: image.Point{10, 20},
Max: image.Point{18, 28},
},
}
func TestNew(t *testing.T) {
// This test never fails explicitly. If it doesn't panic, it's okay.
for L := 0; L < 4; L++ {
for T := 0; T < 4; T++ {
for R := 8; R < 12; R++ {
for B := 8; B < 12; B++ {
img := New(image.Rect(L, T, R, B))
for y := T; y < B; y++ {
for x := L; x < R; x++ {
img.At(x, y)
}
}
}
}
}
}
}
func TestImage(t *testing.T) {
for L := src.Rect.Min.X - 4; L < src.Rect.Max.X+4; L++ {
for T := src.Rect.Min.Y - 4; T < src.Rect.Max.Y+4; T++ {
for R := src.Rect.Min.X - 4; R < src.Rect.Max.X+4; R++ {
for B := src.Rect.Min.Y - 4; B < src.Rect.Max.Y+4; B++ {
r := image.Rect(L, T, R, B)
s := src.SubImage(r)
for y := src.Rect.Min.Y - 4; y < src.Rect.Max.Y+4; y++ {
for x := src.Rect.Min.X - 4; x < src.Rect.Max.X+4; x++ {
p := image.Pt(x, y)
c0 := s.At(x, y)
c1 := color.YCbCr{}
if p.In(r) && p.In(src.Rect) {
c1 = expectedAt(x, y)
}
if c0 != c1 {
t.Errorf("got: %v, expected: %v (x=%d, y=%d, r=%v)\n",
c0, c1, x, y, r)
return
}
}
}
}
}
}
}
}
func TestToRGBA(t *testing.T) {
t.Parallel()
r0 := image.Rect(-2, -6, 14, 10)
for L := r0.Min.X; L < r0.Max.X; L++ {
for T := r0.Min.Y; T < r0.Max.Y; T++ {
for R := r0.Min.X; R < r0.Max.X; R++ {
for B := r0.Min.Y; B < r0.Max.Y; B++ {
for X := src.Rect.Min.X - 4; X < src.Rect.Max.X+4; X++ {
for Y := src.Rect.Min.Y - 4; Y < src.Rect.Max.Y+4; Y++ {
r := image.Rect(L, T, R, B)
p := image.Pt(X, Y)
dst0 := image.NewRGBA(r0)
dst1 := image.NewRGBA(r0)
ToRGBA(dst0, r, src, p)
draw.Draw(dst1, r, src, p, draw.Over)
for x := r0.Min.X; x < r0.Max.X; x++ {
for y := r0.Min.Y; y < r0.Max.Y; y++ {
c0 := dst0.At(x, y)
c1 := dst1.At(x, y)
if c0 != c1 {
t.Errorf("got: %v, expected: %v (x=%d, y=%d, r=%v, p=%v)\n",
c0, c1, x, y, r, p)
return
}
}
}
}
}
}
}
}
}
}
func TestToGray(t *testing.T) {
t.Parallel()
r0 := image.Rect(-2, -6, 14, 10)
for L := r0.Min.X; L < r0.Max.X; L++ {
for T := r0.Min.Y; T < r0.Max.Y; T++ {
for R := r0.Min.X; R < r0.Max.X; R++ {
for B := r0.Min.Y; B < r0.Max.Y; B++ {
for X := src.Rect.Min.X - 4; X < src.Rect.Max.X+4; X++ {
for Y := src.Rect.Min.Y - 4; Y < src.Rect.Max.Y+4; Y++ {
r := image.Rect(L, T, R, B)
p := image.Pt(X, Y)
dst0 := image.NewGray(r0)
dst1 := image.NewGray(r0)
ToGray(dst0, r, src, p)
draw.Draw(dst1, r, src, p, draw.Over)
for x := r0.Min.X; x < r0.Max.X; x++ {
for y := r0.Min.Y; y < r0.Max.Y; y++ {
c0 := dst0.At(x, y)
c1 := dst1.At(x, y)
if c0 != c1 {
t.Errorf("got: %v, expected: %v (x=%d, y=%d, r=%v, p=%v)\n",
c0, c1, x, y, r, p)
return
}
}
}
}
}
}
}
}
}
}
func TestToYCbCr(t *testing.T) {
t.Parallel()
r0 := image.Rect(-2, -6, 14, 10)
for L := r0.Min.X; L < r0.Max.X; L++ {
for T := r0.Min.Y; T < r0.Max.Y; T++ {
for R := r0.Min.X; R < r0.Max.X; R++ {
for B := r0.Min.Y; B < r0.Max.Y; B++ {
for X := src.Rect.Min.X - 4; X < src.Rect.Max.X+4; X++ {
for Y := src.Rect.Min.Y - 4; Y < src.Rect.Max.Y+4; Y++ {
r := image.Rect(L, T, R, B)
p := image.Pt(X, Y)
d := p.Sub(r.Min)
dst := image.NewYCbCr(r0, image.YCbCrSubsampleRatio444)
ToYCbCr(dst, r, src, p)
for x := r0.Min.X; x < r0.Max.X; x++ {
for y := r0.Min.Y; y < r0.Max.Y; y++ {
c0 := dst.At(x, y)
c1 := color.YCbCr{}
if image.Pt(x, y).In(r) && image.Pt(x, y).Add(d).In(src.Rect) {
c1 = expectedAt(x+d.X, y+d.Y)
}
if c0 != c1 {
t.Errorf("got: %v, expected: %v (x=%d, y=%d, r=%v, p=%v)\n",
c0, c1, x, y, r, p)
return
}
}
}
}
}
}
}
}
}
}
func expectedAt(x, y int) color.YCbCr {
x = (x - src.Rect.Min.X) & 7
y = (y - src.Rect.Min.Y) & 7
return color.YCbCr{
Y: byte(x<<5 + y<<2),
Cb: byte(x&^1<<5 + y<<3 + 1),
Cr: byte(x&^1<<5 + y<<3 + 7),
}
}
func TestRGBConversion(t *testing.T) {
var (
ycc = New(image.Rect(0, 0, 2, 1))
rgb1 = image.NewRGBA(ycc.Rect)
rgb2 = image.NewRGBA(ycc.Rect)
)
for y := 0; y < 256; y++ {
for cb := 0; cb < 256; cb++ {
for cr := 0; cr < 256; cr++ {
var (
y = uint8(y)
cb = uint8(cb)
cr = uint8(cr)
)
ycc.Pix[0] = y
ycc.Pix[1] = cb
ycc.Pix[2] = y
ycc.Pix[3] = cr
draw.Draw(rgb1, rgb1.Rect, ycc, ycc.Rect.Min, draw.Over)
ToRGBA(rgb2, rgb2.Rect, ycc, ycc.Rect.Min)
for i, v := range rgb2.Pix {
if v != rgb1.Pix[i] {
t.Errorf("got: %v, expected: %v (y=%d, cb=%d, cr=%d)\n",
rgb2.Pix, rgb1.Pix, y, cb, cr)
return
}
}
}
}
}
}
func TestGrayConversion(t *testing.T) {
var (
ycc = New(image.Rect(0, 0, 2, 1))
gray1 = image.NewGray(ycc.Rect)
gray2 = image.NewGray(ycc.Rect)
)
for y := 0; y < 256; y++ {
for cb := 0; cb < 256; cb++ {
for cr := 0; cr < 256; cr++ {
var (
y = uint8(y)
cb = uint8(cb)
cr = uint8(cr)
)
ycc.Pix[0] = y
ycc.Pix[1] = cb
ycc.Pix[2] = y
ycc.Pix[3] = cr
draw.Draw(gray1, gray1.Rect, ycc, ycc.Rect.Min, draw.Over)
ToGray(gray2, gray2.Rect, ycc, ycc.Rect.Min)
for i, v := range gray2.Pix {
if v != gray1.Pix[i] {
t.Errorf("got: %v, expected: %v (y=%d, cb=%d, cr=%d)\n",
gray2.Pix, gray1.Pix, y, cb, cr)
return
}
}
}
}
}
}
golang-github-korandiz-v4l-1.1.0/frac.go 0000664 0000000 0000000 00000002553 14545740134 0020040 0 ustar 00root root 0000000 0000000 // Package v4l, a facade to the Video4Linux video capture interface
// Copyright (C) 2016 Zoltán Korándi
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//go:build linux
// +build linux
package v4l
// A Frac represents the fractional number N/D.
type Frac struct {
N uint32
D uint32
}
// Cmp returns -1, 0, or 1 if f is less then, equal to, or greater than g,
// respectively.
func (f Frac) Cmp(g Frac) int {
F := uint64(f.N) * uint64(g.D)
G := uint64(g.N) * uint64(f.D)
switch {
case F < G:
return -1
case F > G:
return 1
default:
return 0
}
}
// Reduce returns f reduced to lowest terms.
func (f Frac) Reduce() Frac {
gcd, r := f.N, f.D
for r != 0 {
gcd, r = r, gcd%r
}
if gcd == 0 {
gcd = 1
}
return Frac{f.N / gcd, f.D / gcd}
}
golang-github-korandiz-v4l-1.1.0/frac_test.go 0000664 0000000 0000000 00000007642 14545740134 0021103 0 ustar 00root root 0000000 0000000 // Package v4l, a facade to the Video4Linux video capture interface
// Copyright (C) 2016 Zoltán Korándi
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//go:build linux
// +build linux
package v4l
import "testing"
func TestFrac_Reduce(t *testing.T) {
var x = []struct{ in, out Frac }{
{Frac{0, 1}, Frac{0, 1}},
{Frac{0, 2}, Frac{0, 1}},
{Frac{0, 3}, Frac{0, 1}},
{Frac{0, 4}, Frac{0, 1}},
{Frac{0, 6}, Frac{0, 1}},
{Frac{0, 12}, Frac{0, 1}},
{Frac{1, 0}, Frac{1, 0}},
{Frac{1, 1}, Frac{1, 1}},
{Frac{1, 2}, Frac{1, 2}},
{Frac{1, 3}, Frac{1, 3}},
{Frac{1, 4}, Frac{1, 4}},
{Frac{1, 6}, Frac{1, 6}},
{Frac{1, 12}, Frac{1, 12}},
{Frac{2, 0}, Frac{1, 0}},
{Frac{2, 1}, Frac{2, 1}},
{Frac{2, 2}, Frac{1, 1}},
{Frac{2, 3}, Frac{2, 3}},
{Frac{2, 4}, Frac{1, 2}},
{Frac{2, 6}, Frac{1, 3}},
{Frac{2, 12}, Frac{1, 6}},
{Frac{3, 0}, Frac{1, 0}},
{Frac{3, 1}, Frac{3, 1}},
{Frac{3, 2}, Frac{3, 2}},
{Frac{3, 3}, Frac{1, 1}},
{Frac{3, 4}, Frac{3, 4}},
{Frac{3, 6}, Frac{1, 2}},
{Frac{3, 12}, Frac{1, 4}},
{Frac{4, 0}, Frac{1, 0}},
{Frac{4, 1}, Frac{4, 1}},
{Frac{4, 2}, Frac{2, 1}},
{Frac{4, 3}, Frac{4, 3}},
{Frac{4, 4}, Frac{1, 1}},
{Frac{4, 6}, Frac{2, 3}},
{Frac{4, 12}, Frac{1, 3}},
{Frac{6, 0}, Frac{1, 0}},
{Frac{6, 1}, Frac{6, 1}},
{Frac{6, 2}, Frac{3, 1}},
{Frac{6, 3}, Frac{2, 1}},
{Frac{6, 4}, Frac{3, 2}},
{Frac{6, 6}, Frac{1, 1}},
{Frac{6, 12}, Frac{1, 2}},
{Frac{12, 0}, Frac{1, 0}},
{Frac{12, 1}, Frac{12, 1}},
{Frac{12, 2}, Frac{6, 1}},
{Frac{12, 3}, Frac{4, 1}},
{Frac{12, 4}, Frac{3, 1}},
{Frac{12, 6}, Frac{2, 1}},
{Frac{12, 12}, Frac{1, 1}},
{Frac{54665710, 239322993}, Frac{54665710, 239322993}},
{Frac{239322993, 54665710}, Frac{239322993, 54665710}},
{Frac{223092870, 1078282205}, Frac{6, 29}},
{Frac{1078282205, 223092870}, Frac{29, 6}},
{Frac{0, 0}, Frac{0, 0}},
}
for _, y := range x {
out := y.in.Reduce()
if out != y.out {
t.Errorf("in: %d/%d, out: %d/%d, expected: %d/%d\n",
y.in.N, y.in.D, out.N, out.D, y.out.N, y.out.D)
}
}
}
func TestFrac_Cmp(t *testing.T) {
rel := map[int]string{-1: "<", 0: "=", 1: ">"}
var x = [][]Frac{
{Frac{0, 1}, Frac{0, 2}, Frac{0, 3}, Frac{0, 4}, Frac{0, 6}, Frac{0, 12}},
{Frac{1, 12}},
{Frac{1, 6}, Frac{2, 12}},
{Frac{223092870, 1078282205}, Frac{6, 29}},
{Frac{54665710, 239322993}},
{Frac{1, 4}, Frac{3, 12}},
{Frac{1, 3}, Frac{2, 6}, Frac{4, 12}},
{Frac{1, 2}, Frac{2, 4}, Frac{3, 6}, Frac{6, 12}},
{Frac{2, 3}, Frac{4, 6}},
{Frac{3, 4}},
{Frac{1, 1}, Frac{2, 2}, Frac{3, 3}, Frac{4, 4}, Frac{6, 6}, Frac{12, 12}},
{Frac{4, 3}},
{Frac{3, 2}, Frac{6, 4}},
{Frac{2, 1}, Frac{4, 2}, Frac{6, 3}, Frac{12, 6}},
{Frac{3, 1}, Frac{6, 2}, Frac{12, 4}},
{Frac{4, 1}, Frac{12, 3}},
{Frac{239322993, 54665710}},
{Frac{1078282205, 223092870}},
{Frac{6, 1}, Frac{12, 2}},
{Frac{12, 1}},
{Frac{1, 0}, Frac{2, 0}, Frac{3, 0}, Frac{4, 0}, Frac{6, 0}, Frac{12, 0}},
}
for i1 := range x {
for _, f := range x[i1] {
for i2 := range x {
for _, g := range x[i2] {
var r int
if i1 < i2 {
r = -1
} else if i1 > i2 {
r = 1
}
cmp := f.Cmp(g)
if cmp != r {
t.Errorf("got: %d/%d %s %d/%d, expected: %d/%d %s %d/%d\n",
f.N, f.D, rel[cmp], g.N, g.D,
f.N, f.D, rel[r], g.N, g.D)
}
}
}
}
}
}
golang-github-korandiz-v4l-1.1.0/generate/ 0000775 0000000 0000000 00000000000 14545740134 0020363 5 ustar 00root root 0000000 0000000 golang-github-korandiz-v4l-1.1.0/generate/arch_go.c 0000664 0000000 0000000 00000043611 14545740134 0022136 0 ustar 00root root 0000000 0000000 // Package v4l, a facade to the Video4Linux video capture interface
// Copyright (C) 2016 Zoltán Korándi
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
#include
#include
#include
#include
int main() {
printf("// +build linux\n");
printf("// +build ");
fflush(stdout);
system("go env GOHOSTARCH");
printf("\n");
printf("/////////////////////////////////////////////////////\n");
printf("// //\n");
printf("// !!! THIS IS A GENERATED FILE, DO NOT EDIT !!! //\n");
printf("// //\n");
printf("/////////////////////////////////////////////////////\n");
printf("\n");
printf("package v4l\n\n");
printf("const (\n");
printf("\tvidioc_querycap = 0x%08llx\n", (long long unsigned) VIDIOC_QUERYCAP);
printf("\tvidioc_gFmt = 0x%08llx\n", (long long unsigned) VIDIOC_G_FMT);
printf("\tvidioc_sFmt = 0x%08llx\n", (long long unsigned) VIDIOC_S_FMT);
printf("\tvidioc_gParm = 0x%08llx\n", (long long unsigned) VIDIOC_G_PARM);
printf("\tvidioc_sParm = 0x%08llx\n", (long long unsigned) VIDIOC_S_PARM);
printf("\tvidioc_reqbufs = 0x%08llx\n", (long long unsigned) VIDIOC_REQBUFS);
printf("\tvidioc_querybuf = 0x%08llx\n", (long long unsigned) VIDIOC_QUERYBUF);
printf("\tvidioc_qbuf = 0x%08llx\n", (long long unsigned) VIDIOC_QBUF);
printf("\tvidioc_dqbuf = 0x%08llx\n", (long long unsigned) VIDIOC_DQBUF);
printf("\tvidioc_streamon = 0x%08llx\n", (long long unsigned) VIDIOC_STREAMON);
printf("\tvidioc_streamoff = 0x%08llx\n", (long long unsigned) VIDIOC_STREAMOFF);
printf("\tvidioc_cropcap = 0x%08llx\n", (long long unsigned) VIDIOC_CROPCAP);
printf("\tvidioc_sCrop = 0x%08llx\n", (long long unsigned) VIDIOC_S_CROP);
printf("\tvidioc_enumstd = 0x%08llx\n", (long long unsigned) VIDIOC_ENUMSTD);
printf("\tvidioc_enumFmt = 0x%08llx\n", (long long unsigned) VIDIOC_ENUM_FMT);
printf("\tvidioc_enumFramesizes = 0x%08llx\n", (long long unsigned) VIDIOC_ENUM_FRAMESIZES);
printf("\tvidioc_enumFrameintervals = 0x%08llx\n", (long long unsigned) VIDIOC_ENUM_FRAMEINTERVALS);
printf("\tvidioc_queryctrl = 0x%08llx\n", (long long unsigned) VIDIOC_QUERYCTRL);
printf("\tvidioc_querymenu = 0x%08llx\n", (long long unsigned) VIDIOC_QUERYMENU);
printf("\tvidioc_gCtrl = 0x%08llx\n", (long long unsigned) VIDIOC_G_CTRL);
printf("\tvidioc_sCtrl = 0x%08llx\n", (long long unsigned) VIDIOC_S_CTRL);
printf(")\n\n");
printf("const (\n");
printf("\tsize_capability = %llu\n", (long long unsigned) sizeof(struct v4l2_capability));
printf("\tsize_format = %llu\n", (long long unsigned) sizeof(struct v4l2_format));
printf("\tsize_streamparm = %llu\n", (long long unsigned) sizeof(struct v4l2_streamparm));
printf("\tsize_requestbuffers = %llu\n", (long long unsigned) sizeof(struct v4l2_requestbuffers));
printf("\tsize_buffer = %llu\n", (long long unsigned) sizeof(struct v4l2_buffer));
printf("\tsize_int = %llu\n", (long long unsigned) sizeof(int));
printf("\tsize_cropcap = %llu\n", (long long unsigned) sizeof(struct v4l2_cropcap));
printf("\tsize_crop = %llu\n", (long long unsigned) sizeof(struct v4l2_crop));
printf("\tsize_standard = %llu\n", (long long unsigned) sizeof(struct v4l2_standard));
printf("\tsize_fmtdesc = %llu\n", (long long unsigned) sizeof(struct v4l2_fmtdesc));
printf("\tsize_frmsizeenum = %llu\n", (long long unsigned) sizeof(struct v4l2_frmsizeenum));
printf("\tsize_frmivalenum = %llu\n", (long long unsigned) sizeof(struct v4l2_frmivalenum));
printf("\tsize_queryctrl = %llu\n", (long long unsigned) sizeof(struct v4l2_queryctrl));
printf("\tsize_querymenu = %llu\n", (long long unsigned) sizeof(struct v4l2_querymenu));
printf("\tsize_control = %llu\n", (long long unsigned) sizeof(struct v4l2_control));
printf(")\n\n");
printf("const (\n");
printf("\toffs_capability_driver = %llu\n", (long long unsigned) offsetof(struct v4l2_capability, driver));
printf("\tsize_capability_driver = %llu\n", (long long unsigned) sizeof((struct v4l2_capability){0}.driver));
printf("\toffs_capability_card = %llu\n", (long long unsigned) offsetof(struct v4l2_capability, card));
printf("\tsize_capability_card = %llu\n", (long long unsigned) sizeof((struct v4l2_capability){0}.card));
printf("\toffs_capability_busInfo = %llu\n", (long long unsigned) offsetof(struct v4l2_capability, bus_info));
printf("\tsize_capability_busInfo = %llu\n", (long long unsigned) sizeof((struct v4l2_capability){0}.bus_info));
printf("\toffs_capability_version = %llu\n", (long long unsigned) offsetof(struct v4l2_capability, version));
printf("\toffs_capability_capabilities = %llu\n", (long long unsigned) offsetof(struct v4l2_capability, capabilities));
printf("\toffs_capability_deviceCaps = %llu\n", (long long unsigned) offsetof(struct v4l2_capability, device_caps));
printf(")\n\n");
printf("const (\n");
printf("\toffs_format_typ = %llu\n", (long long unsigned) offsetof(struct v4l2_format, type));
printf("\toffs_format_fmt = %llu\n", (long long unsigned) offsetof(struct v4l2_format, fmt));
printf(")\n\n");
printf("const (\n");
printf("\toffs_pixFormat_width = %llu\n", (long long unsigned) offsetof(struct v4l2_pix_format, width));
printf("\toffs_pixFormat_height = %llu\n", (long long unsigned) offsetof(struct v4l2_pix_format, height));
printf("\toffs_pixFormat_pixelformat = %llu\n", (long long unsigned) offsetof(struct v4l2_pix_format, pixelformat));
printf("\toffs_pixFormat_field = %llu\n", (long long unsigned) offsetof(struct v4l2_pix_format, field));
printf("\toffs_pixFormat_bytesperline = %llu\n", (long long unsigned) offsetof(struct v4l2_pix_format, bytesperline));
printf("\toffs_pixFormat_sizeimage = %llu\n", (long long unsigned) offsetof(struct v4l2_pix_format, sizeimage));
printf("\toffs_pixFormat_colorspace = %llu\n", (long long unsigned) offsetof(struct v4l2_pix_format, colorspace));
printf("\toffs_pixFormat_priv = %llu\n", (long long unsigned) offsetof(struct v4l2_pix_format, priv));
printf("\toffs_pixFormat_flags = %llu\n", (long long unsigned) offsetof(struct v4l2_pix_format, flags));
printf("\toffs_pixFormat_ycbcrEnc = %llu\n", (long long unsigned) offsetof(struct v4l2_pix_format, ycbcr_enc));
printf("\toffs_pixFormat_quantization = %llu\n", (long long unsigned) offsetof(struct v4l2_pix_format, quantization));
printf("\toffs_pixFormat_xferFunc = %llu\n", (long long unsigned) offsetof(struct v4l2_pix_format, xfer_func));
printf(")\n\n");
printf("const (\n");
printf("\toffs_streamparm_typ = %llu\n", (long long unsigned) offsetof(struct v4l2_streamparm, type));
printf("\toffs_streamparm_parm = %llu\n", (long long unsigned) offsetof(struct v4l2_streamparm, parm));
printf(")\n\n");
printf("const (\n");
printf("\toffs_captureparm_capability = %llu\n", (long long unsigned) offsetof(struct v4l2_captureparm, capability));
printf("\toffs_captureparm_capturemode = %llu\n", (long long unsigned) offsetof(struct v4l2_captureparm, capturemode));
printf("\toffs_captureparm_timeperframe = %llu\n", (long long unsigned) offsetof(struct v4l2_captureparm, timeperframe));
printf("\toffs_captureparm_extendedmode = %llu\n", (long long unsigned) offsetof(struct v4l2_captureparm, extendedmode));
printf("\toffs_captureparm_readbuffers = %llu\n", (long long unsigned) offsetof(struct v4l2_captureparm, readbuffers));
printf(")\n\n");
printf("const (\n");
printf("\toffs_requestbuffers_count = %llu\n", (long long unsigned) offsetof(struct v4l2_requestbuffers, count));
printf("\toffs_requestbuffers_typ = %llu\n", (long long unsigned) offsetof(struct v4l2_requestbuffers, type));
printf("\toffs_requestbuffers_memory = %llu\n", (long long unsigned) offsetof(struct v4l2_requestbuffers, memory));
printf(")\n\n");
printf("const (\n");
printf("\toffs_buffer_index = %llu\n", (long long unsigned) offsetof(struct v4l2_buffer, index));
printf("\toffs_buffer_typ = %llu\n", (long long unsigned) offsetof(struct v4l2_buffer, type));
printf("\toffs_buffer_bytesused = %llu\n", (long long unsigned) offsetof(struct v4l2_buffer, bytesused));
printf("\toffs_buffer_flags = %llu\n", (long long unsigned) offsetof(struct v4l2_buffer, flags));
printf("\toffs_buffer_field = %llu\n", (long long unsigned) offsetof(struct v4l2_buffer, field));
printf("\toffs_buffer_timecode = %llu\n", (long long unsigned) offsetof(struct v4l2_buffer, timecode));
printf("\toffs_buffer_sequence = %llu\n", (long long unsigned) offsetof(struct v4l2_buffer, sequence));
printf("\toffs_buffer_memory = %llu\n", (long long unsigned) offsetof(struct v4l2_buffer, memory));
printf("\toffs_buffer_offset = %llu\n", (long long unsigned) offsetof(struct v4l2_buffer, m.offset));
printf("\toffs_buffer_length = %llu\n", (long long unsigned) offsetof(struct v4l2_buffer, length));
printf(")\n\n");
printf("const (\n");
printf("\toffs_cropcap_typ = %llu\n", (long long unsigned) offsetof(struct v4l2_cropcap, type));
printf("\toffs_cropcap_bounds = %llu\n", (long long unsigned) offsetof(struct v4l2_cropcap, bounds));
printf("\toffs_cropcap_defrect = %llu\n", (long long unsigned) offsetof(struct v4l2_cropcap, defrect));
printf("\toffs_cropcap_pixelaspect = %llu\n", (long long unsigned) offsetof(struct v4l2_cropcap, pixelaspect));
printf(")\n\n");
printf("const (\n");
printf("\toffs_crop_typ = %llu\n", (long long unsigned) offsetof(struct v4l2_crop, type));
printf("\toffs_crop_c = %llu\n", (long long unsigned) offsetof(struct v4l2_crop, c));
printf(")\n\n");
printf("const (\n");
printf("\toffs_fract_numerator = %llu\n", (long long unsigned) offsetof(struct v4l2_fract, numerator));
printf("\toffs_fract_denominator = %llu\n", (long long unsigned) offsetof(struct v4l2_fract, denominator));
printf(")\n\n");
printf("const (\n");
printf("\toffs_timecode_typ = %llu\n", (long long unsigned) offsetof(struct v4l2_timecode, type));
printf("\toffs_timecode_flags = %llu\n", (long long unsigned) offsetof(struct v4l2_timecode, flags));
printf("\toffs_timecode_frames = %llu\n", (long long unsigned) offsetof(struct v4l2_timecode, frames));
printf("\toffs_timecode_seconds = %llu\n", (long long unsigned) offsetof(struct v4l2_timecode, seconds));
printf("\toffs_timecode_minutes = %llu\n", (long long unsigned) offsetof(struct v4l2_timecode, minutes));
printf("\toffs_timecode_hours = %llu\n", (long long unsigned) offsetof(struct v4l2_timecode, hours));
printf("\toffs_timecode_userbits = %llu\n", (long long unsigned) offsetof(struct v4l2_timecode, userbits));
printf(")\n\n");
printf("const (\n");
printf("\toffs_rect_left = %llu\n", (long long unsigned) offsetof(struct v4l2_rect, left));
printf("\toffs_rect_top = %llu\n", (long long unsigned) offsetof(struct v4l2_rect, top));
printf("\toffs_rect_width = %llu\n", (long long unsigned) offsetof(struct v4l2_rect, width));
printf("\toffs_rect_height = %llu\n", (long long unsigned) offsetof(struct v4l2_rect, height));
printf(")\n\n");
printf("const (\n");
printf("\toffs_standard_index = %llu\n", (long long unsigned) offsetof(struct v4l2_standard, index));
printf("\toffs_standard_id = %llu\n", (long long unsigned) offsetof(struct v4l2_standard, id));
printf("\toffs_standard_name = %llu\n", (long long unsigned) offsetof(struct v4l2_standard, name));
printf("\tsize_standard_name = %llu\n", (long long unsigned) sizeof((struct v4l2_standard){0}.name));
printf("\toffs_standard_frameperiod = %llu\n", (long long unsigned) offsetof(struct v4l2_standard, frameperiod));
printf("\toffs_standard_framelines = %llu\n", (long long unsigned) offsetof(struct v4l2_standard, framelines));
printf(")\n\n");
printf("const (\n");
printf("\toffs_fmtdesc_index = %llu\n", (long long unsigned) offsetof(struct v4l2_fmtdesc, index));
printf("\toffs_fmtdesc_typ = %llu\n", (long long unsigned) offsetof(struct v4l2_fmtdesc, type));
printf("\toffs_fmtdesc_flags = %llu\n", (long long unsigned) offsetof(struct v4l2_fmtdesc, flags));
printf("\toffs_fmtdesc_description = %llu\n", (long long unsigned) offsetof(struct v4l2_fmtdesc, description));
printf("\tsize_fmtdesc_description = %llu\n", (long long unsigned) sizeof((struct v4l2_fmtdesc){0}.description));
printf("\toffs_fmtdesc_pixelformat = %llu\n", (long long unsigned) offsetof(struct v4l2_fmtdesc, pixelformat));
printf(")\n\n");
printf("const (\n");
printf("\toffs_frmsizeenum_index = %llu\n", (long long unsigned) offsetof(struct v4l2_frmsizeenum, index));
printf("\toffs_frmsizeenum_pixelFormat = %llu\n", (long long unsigned) offsetof(struct v4l2_frmsizeenum, pixel_format));
printf("\toffs_frmsizeenum_typ = %llu\n", (long long unsigned) offsetof(struct v4l2_frmsizeenum, type));
printf("\toffs_frmsizeenum_discrete = %llu\n", (long long unsigned) offsetof(struct v4l2_frmsizeenum, discrete));
printf("\toffs_frmsizeenum_stepwise = %llu\n", (long long unsigned) offsetof(struct v4l2_frmsizeenum, stepwise));
printf(")\n\n");
printf("const (\n");
printf("\toffs_frmsizeDiscrete_width = %llu\n", (long long unsigned) offsetof(struct v4l2_frmsize_discrete, width));
printf("\toffs_frmsizeDiscrete_height = %llu\n", (long long unsigned) offsetof(struct v4l2_frmsize_discrete, height));
printf(")\n\n");
printf("const (\n");
printf("\toffs_frmsizeStepwise_minWidth = %llu\n", (long long unsigned) offsetof(struct v4l2_frmsize_stepwise, min_width));
printf("\toffs_frmsizeStepwise_maxWidth = %llu\n", (long long unsigned) offsetof(struct v4l2_frmsize_stepwise, max_width));
printf("\toffs_frmsizeStepwise_stepWidth = %llu\n", (long long unsigned) offsetof(struct v4l2_frmsize_stepwise, step_width));
printf("\toffs_frmsizeStepwise_minHeight = %llu\n", (long long unsigned) offsetof(struct v4l2_frmsize_stepwise, min_height));
printf("\toffs_frmsizeStepwise_maxHeight = %llu\n", (long long unsigned) offsetof(struct v4l2_frmsize_stepwise, max_height));
printf("\toffs_frmsizeStepwise_stepHeight = %llu\n", (long long unsigned) offsetof(struct v4l2_frmsize_stepwise, step_height));
printf(")\n\n");
printf("const (\n");
printf("\toffs_frmivalenum_index = %llu\n", (long long unsigned) offsetof(struct v4l2_frmivalenum, index));
printf("\toffs_frmivalenum_pixelFormat = %llu\n", (long long unsigned) offsetof(struct v4l2_frmivalenum, pixel_format));
printf("\toffs_frmivalenum_width = %llu\n", (long long unsigned) offsetof(struct v4l2_frmivalenum, width));
printf("\toffs_frmivalenum_height = %llu\n", (long long unsigned) offsetof(struct v4l2_frmivalenum, height));
printf("\toffs_frmivalenum_typ = %llu\n", (long long unsigned) offsetof(struct v4l2_frmivalenum, type));
printf("\toffs_frmivalenum_discrete = %llu\n", (long long unsigned) offsetof(struct v4l2_frmivalenum, discrete));
printf("\toffs_frmivalenum_stepwise = %llu\n", (long long unsigned) offsetof(struct v4l2_frmivalenum, stepwise));
printf(")\n\n");
printf("const (\n");
printf("\toffs_frmivalStepwise_min = %llu\n", (long long unsigned) offsetof(struct v4l2_frmival_stepwise, min));
printf("\toffs_frmivalStepwise_max = %llu\n", (long long unsigned) offsetof(struct v4l2_frmival_stepwise, max));
printf("\toffs_frmivalStepwise_step = %llu\n", (long long unsigned) offsetof(struct v4l2_frmival_stepwise, step));
printf(")\n\n");
printf("const (\n");
printf("\toffs_queryctrl_id = %llu\n", (long long unsigned) offsetof(struct v4l2_queryctrl, id));
printf("\toffs_queryctrl_typ = %llu\n", (long long unsigned) offsetof(struct v4l2_queryctrl, type));
printf("\toffs_queryctrl_name = %llu\n", (long long unsigned) offsetof(struct v4l2_queryctrl, name));
printf("\tsize_queryctrl_name = %llu\n", (long long unsigned) sizeof((struct v4l2_queryctrl){0}.name));
printf("\toffs_queryctrl_minimum = %llu\n", (long long unsigned) offsetof(struct v4l2_queryctrl, minimum));
printf("\toffs_queryctrl_maximum = %llu\n", (long long unsigned) offsetof(struct v4l2_queryctrl, maximum));
printf("\toffs_queryctrl_step = %llu\n", (long long unsigned) offsetof(struct v4l2_queryctrl, step));
printf("\toffs_queryctrl_defaultValue = %llu\n", (long long unsigned) offsetof(struct v4l2_queryctrl, default_value));
printf("\toffs_queryctrl_flags = %llu\n", (long long unsigned) offsetof(struct v4l2_queryctrl, flags));
printf(")\n\n");
printf("const (\n");
printf("\toffs_querymenu_id = %llu\n", (long long unsigned) offsetof(struct v4l2_querymenu, id));
printf("\toffs_querymenu_index = %llu\n", (long long unsigned) offsetof(struct v4l2_querymenu, index));
printf("\toffs_querymenu_name = %llu\n", (long long unsigned) offsetof(struct v4l2_querymenu, name));
printf("\tsize_querymenu_name = %llu\n", (long long unsigned) sizeof((struct v4l2_querymenu){0}.name));
printf("\toffs_querymenu_value = %llu\n", (long long unsigned) offsetof(struct v4l2_querymenu, value));
printf(")\n\n");
printf("const (\n");
printf("\toffs_control_id = %llu\n", (long long unsigned) offsetof(struct v4l2_control, id));
printf("\toffs_control_value = %llu\n", (long long unsigned) offsetof(struct v4l2_control, value));
printf(")\n");
return 0;
}
golang-github-korandiz-v4l-1.1.0/go.mod 0000664 0000000 0000000 00000000050 14545740134 0017672 0 ustar 00root root 0000000 0000000 module github.com/korandiz/v4l
go 1.15
golang-github-korandiz-v4l-1.1.0/v4l.go 0000664 0000000 0000000 00000057107 14545740134 0017637 0 ustar 00root root 0000000 0000000 // Package v4l, a facade to the Video4Linux video capture interface
// Copyright (C) 2016 Zoltán Korándi
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//go:build linux
// +build linux
package v4l
import (
"syscall"
"unsafe"
)
// Constants.
const (
v4l_capVideoCapture = 0x00000001
v4l_capDeviceCaps = 0x80000000
)
const (
v4l_bufTypeVideoCapture = 1
)
const (
v4l_colorspaceDefault = 0
)
const (
v4l_fieldNone = 1
)
const (
v4l_memoryMmap = 1
)
const (
v4l_frmsizeTypeDiscrete = 1
v4l_frmsizeTypeContinuous = 2
v4l_frmsizeTypeStepwise = 3
)
const (
v4l_frmivalTypeDiscrete = 1
v4l_frmivalTypeContinuous = 2
v4l_frmivalTypeStepwise = 3
)
const (
v4l_ctrlFlagDisabled = 0x0001
v4l_ctrlFlagNextCtrl = 0x80000000
)
const (
v4l_ctrlTypeInteger = 1
v4l_ctrlTypeBoolean = 2
v4l_ctrlTypeMenu = 3
v4l_ctrlTypeButton = 4
v4l_ctrlTypeIntegerMenu = 9
)
const (
v4l_cidBase = 0x00980900
v4l_cidLastp1 = 0x0098092b
v4l_cidPrivateBase = 0x08000000
)
// Structs.
type v4l_capability struct {
driver string
card string
busInfo string
version uint32
capabilities uint32
deviceCaps uint32
}
type v4l_format_pix struct {
typ uint32
fmt v4l_pixFormat
}
type v4l_pixFormat struct {
width uint32
height uint32
pixelformat uint32
field uint32
bytesperline uint32
sizeimage uint32
colorspace uint32
priv uint32
flags uint32
ycbcrEnc uint32
quantization uint32
xferFunc uint32
}
type v4l_streamparm_capture struct {
typ uint32
parm v4l_captureparm
}
type v4l_captureparm struct {
capability uint32
capturemode uint32
timeperframe v4l_fract
extendedmode uint32
readbuffers uint32
}
type v4l_requestbuffers struct {
count uint32
typ uint32
memory uint32
}
type v4l_buffer struct {
index uint32
typ uint32
bytesused uint32
flags uint32
field uint32
timecode v4l_timecode
sequence uint32
memory uint32
offset uint32
length uint32
}
type v4l_int int32
type v4l_cropcap struct {
typ uint32
bounds v4l_rect
defrect v4l_rect
pixelaspect v4l_fract
}
type v4l_crop struct {
typ uint32
c v4l_rect
}
type v4l_fract struct {
numerator uint32
denominator uint32
}
type v4l_timecode struct {
typ uint32
flags uint32
frames uint8
seconds uint8
minutes uint8
hours uint8
userbits [4]uint8
}
type v4l_rect struct {
left int32
top int32
width uint32
height uint32
}
type v4l_standard struct {
index uint32
id uint64
name string
frameperiod v4l_fract
framelines uint32
}
type v4l_fmtdesc struct {
index uint32
typ uint32
flags uint32
description string
pixelformat uint32
}
type v4l_frmsizeenum struct {
index uint32
pixelFormat uint32
typ uint32
discrete v4l_frmsizeDiscrete
stepwise v4l_frmsizeStepwise
}
type v4l_frmsizeDiscrete struct {
width uint32
height uint32
}
type v4l_frmsizeStepwise struct {
minWidth uint32
maxWidth uint32
stepWidth uint32
minHeight uint32
maxHeight uint32
stepHeight uint32
}
type v4l_frmivalenum struct {
index uint32
pixelFormat uint32
width uint32
height uint32
typ uint32
discrete v4l_fract
stepwise v4l_frmivalStepwise
}
type v4l_frmivalStepwise struct {
min v4l_fract
max v4l_fract
step v4l_fract
}
type v4l_queryctrl struct {
id uint32
typ uint32
name string
minimum int32
maximum int32
step int32
defaultValue int32
flags uint32
}
type v4l_querymenu struct {
id uint32
index uint32
name string
value int64
}
type v4l_control struct {
id uint32
value int32
}
// IOCTLs.
func ioctl_querycap(fd int, argp *v4l_capability) error {
return ioctl(fd, vidioc_querycap, argp)
}
func ioctl_gFmt_pix(fd int, argp *v4l_format_pix) error {
return ioctl(fd, vidioc_gFmt, argp)
}
func ioctl_sFmt_pix(fd int, argp *v4l_format_pix) error {
return ioctl(fd, vidioc_sFmt, argp)
}
func ioctl_gParm_capture(fd int, argp *v4l_streamparm_capture) error {
return ioctl(fd, vidioc_gParm, argp)
}
func ioctl_sParm_capture(fd int, argp *v4l_streamparm_capture) error {
return ioctl(fd, vidioc_sParm, argp)
}
func ioctl_reqbufs(fd int, argp *v4l_requestbuffers) error {
return ioctl(fd, vidioc_reqbufs, argp)
}
func ioctl_querybuf(fd int, argp *v4l_buffer) error {
return ioctl(fd, vidioc_querybuf, argp)
}
func ioctl_qbuf(fd int, argp *v4l_buffer) error {
return ioctl(fd, vidioc_qbuf, argp)
}
func ioctl_dqbuf(fd int, argp *v4l_buffer) error {
return ioctl(fd, vidioc_dqbuf, argp)
}
func ioctl_streamon(fd int, typ v4l_int) error {
return ioctl(fd, vidioc_streamon, &typ)
}
func ioctl_streamoff(fd int, typ v4l_int) error {
return ioctl(fd, vidioc_streamoff, &typ)
}
func ioctl_cropcap(fd int, argp *v4l_cropcap) error {
return ioctl(fd, vidioc_cropcap, argp)
}
func ioctl_sCrop(fd int, argp *v4l_crop) error {
return ioctl(fd, vidioc_sCrop, argp)
}
func ioctl_enumstd(fd int, argp *v4l_standard) error {
return ioctl(fd, vidioc_enumstd, argp)
}
func ioctl_enumFmt(fd int, argp *v4l_fmtdesc) error {
return ioctl(fd, vidioc_enumFmt, argp)
}
func ioctl_enumFramesizes(fd int, argp *v4l_frmsizeenum) error {
return ioctl(fd, vidioc_enumFramesizes, argp)
}
func ioctl_enumFrameintervals(fd int, argp *v4l_frmivalenum) error {
return ioctl(fd, vidioc_enumFrameintervals, argp)
}
func ioctl_queryctrl(fd int, argp *v4l_queryctrl) error {
return ioctl(fd, vidioc_queryctrl, argp)
}
func ioctl_querymenu(fd int, argp *v4l_querymenu) error {
return ioctl(fd, vidioc_querymenu, argp)
}
func ioctl_gCtrl(fd int, argp *v4l_control) error {
return ioctl(fd, vidioc_gCtrl, argp)
}
func ioctl_sCtrl(fd int, argp *v4l_control) error {
return ioctl(fd, vidioc_sCtrl, argp)
}
func ioctl(fd int, request uint, argp ioctlArg) error {
buf := make([]uint64, (argp.size()+7)/8)
p := unsafe.Pointer(&buf[0])
argp.put(p)
_, _, err := syscall.Syscall(syscall.SYS_IOCTL,
uintptr(fd), uintptr(request), uintptr(p))
if err != 0 {
return err
}
argp.get(p)
return nil
}
// Getters and putters.
type ioctlArg interface {
get(unsafe.Pointer)
put(unsafe.Pointer)
size() int
}
func (p *v4l_capability) get(q unsafe.Pointer) {
p.driver = getString(q, offs_capability_driver, size_capability_driver)
p.card = getString(q, offs_capability_card, size_capability_card)
p.busInfo = getString(q, offs_capability_busInfo, size_capability_busInfo)
p.version = getUint32(q, offs_capability_version)
p.capabilities = getUint32(q, offs_capability_capabilities)
p.deviceCaps = getUint32(q, offs_capability_deviceCaps)
}
func (p *v4l_capability) put(q unsafe.Pointer) {
putString(q, offs_capability_driver, size_capability_driver, p.driver)
putString(q, offs_capability_card, size_capability_card, p.card)
putString(q, offs_capability_busInfo, size_capability_busInfo, p.busInfo)
putUint32(q, offs_capability_version, p.version)
putUint32(q, offs_capability_capabilities, p.capabilities)
putUint32(q, offs_capability_deviceCaps, p.deviceCaps)
}
func (p *v4l_capability) size() int {
return size_capability
}
func (p *v4l_format_pix) get(q unsafe.Pointer) {
p.typ = getUint32(q, offs_format_typ)
p.fmt.get(unsafe.Pointer(uintptr(q) + offs_format_fmt))
}
func (p *v4l_format_pix) put(q unsafe.Pointer) {
putUint32(q, offs_format_typ, p.typ)
p.fmt.put(unsafe.Pointer(uintptr(q) + offs_format_fmt))
}
func (p *v4l_format_pix) size() int {
return size_format
}
func (p *v4l_pixFormat) get(q unsafe.Pointer) {
p.width = getUint32(q, offs_pixFormat_width)
p.height = getUint32(q, offs_pixFormat_height)
p.pixelformat = getUint32(q, offs_pixFormat_pixelformat)
p.field = getUint32(q, offs_pixFormat_field)
p.bytesperline = getUint32(q, offs_pixFormat_bytesperline)
p.sizeimage = getUint32(q, offs_pixFormat_sizeimage)
p.colorspace = getUint32(q, offs_pixFormat_colorspace)
p.priv = getUint32(q, offs_pixFormat_priv)
p.flags = getUint32(q, offs_pixFormat_flags)
p.ycbcrEnc = getUint32(q, offs_pixFormat_ycbcrEnc)
p.quantization = getUint32(q, offs_pixFormat_quantization)
p.xferFunc = getUint32(q, offs_pixFormat_xferFunc)
}
func (p *v4l_pixFormat) put(q unsafe.Pointer) {
putUint32(q, offs_pixFormat_width, p.width)
putUint32(q, offs_pixFormat_height, p.height)
putUint32(q, offs_pixFormat_pixelformat, p.pixelformat)
putUint32(q, offs_pixFormat_field, p.field)
putUint32(q, offs_pixFormat_bytesperline, p.bytesperline)
putUint32(q, offs_pixFormat_sizeimage, p.sizeimage)
putUint32(q, offs_pixFormat_colorspace, p.colorspace)
putUint32(q, offs_pixFormat_priv, p.priv)
putUint32(q, offs_pixFormat_flags, p.flags)
putUint32(q, offs_pixFormat_ycbcrEnc, p.ycbcrEnc)
putUint32(q, offs_pixFormat_quantization, p.quantization)
putUint32(q, offs_pixFormat_xferFunc, p.xferFunc)
}
func (p *v4l_streamparm_capture) get(q unsafe.Pointer) {
p.typ = getUint32(q, offs_streamparm_typ)
p.parm.get(unsafe.Pointer(uintptr(q) + offs_streamparm_parm))
}
func (p *v4l_streamparm_capture) put(q unsafe.Pointer) {
putUint32(q, offs_streamparm_typ, p.typ)
p.parm.put(unsafe.Pointer(uintptr(q) + offs_streamparm_parm))
}
func (p *v4l_streamparm_capture) size() int {
return size_streamparm
}
func (p *v4l_captureparm) get(q unsafe.Pointer) {
p.capability = getUint32(q, offs_captureparm_capability)
p.capturemode = getUint32(q, offs_captureparm_capturemode)
p.timeperframe.get(unsafe.Pointer(uintptr(q) + offs_captureparm_timeperframe))
p.extendedmode = getUint32(q, offs_captureparm_extendedmode)
p.readbuffers = getUint32(q, offs_captureparm_readbuffers)
}
func (p *v4l_captureparm) put(q unsafe.Pointer) {
putUint32(q, offs_captureparm_capability, p.capability)
putUint32(q, offs_captureparm_capturemode, p.capturemode)
p.timeperframe.put(unsafe.Pointer(uintptr(q) + offs_captureparm_timeperframe))
putUint32(q, offs_captureparm_extendedmode, p.extendedmode)
putUint32(q, offs_captureparm_readbuffers, p.readbuffers)
}
func (p *v4l_requestbuffers) get(q unsafe.Pointer) {
p.count = getUint32(q, offs_requestbuffers_count)
p.typ = getUint32(q, offs_requestbuffers_typ)
p.memory = getUint32(q, offs_requestbuffers_memory)
}
func (p *v4l_requestbuffers) put(q unsafe.Pointer) {
putUint32(q, offs_requestbuffers_count, p.count)
putUint32(q, offs_requestbuffers_typ, p.typ)
putUint32(q, offs_requestbuffers_memory, p.memory)
}
func (p *v4l_requestbuffers) size() int {
return size_requestbuffers
}
func (p *v4l_buffer) get(q unsafe.Pointer) {
p.index = getUint32(q, offs_buffer_index)
p.typ = getUint32(q, offs_buffer_typ)
p.bytesused = getUint32(q, offs_buffer_bytesused)
p.flags = getUint32(q, offs_buffer_flags)
p.field = getUint32(q, offs_buffer_field)
p.timecode.get(unsafe.Pointer(uintptr(q) + offs_buffer_timecode))
p.sequence = getUint32(q, offs_buffer_sequence)
p.memory = getUint32(q, offs_buffer_memory)
p.offset = getUint32(q, offs_buffer_offset)
p.length = getUint32(q, offs_buffer_length)
}
func (p *v4l_buffer) put(q unsafe.Pointer) {
putUint32(q, offs_buffer_index, p.index)
putUint32(q, offs_buffer_typ, p.typ)
putUint32(q, offs_buffer_bytesused, p.bytesused)
putUint32(q, offs_buffer_flags, p.flags)
putUint32(q, offs_buffer_field, p.field)
p.timecode.put(unsafe.Pointer(uintptr(q) + offs_buffer_timecode))
putUint32(q, offs_buffer_sequence, p.sequence)
putUint32(q, offs_buffer_memory, p.memory)
putUint32(q, offs_buffer_offset, p.offset)
putUint32(q, offs_buffer_length, p.length)
}
func (p *v4l_buffer) size() int {
return size_buffer
}
func (p *v4l_int) get(q unsafe.Pointer) {
*p = v4l_int(getInt(q, 0))
}
func (p *v4l_int) put(q unsafe.Pointer) {
putInt(q, 0, int32(*p))
}
func (p *v4l_int) size() int {
return size_int
}
func (p *v4l_cropcap) get(q unsafe.Pointer) {
p.typ = getUint32(q, offs_cropcap_typ)
p.bounds.get(unsafe.Pointer(uintptr(q) + offs_cropcap_bounds))
p.defrect.get(unsafe.Pointer(uintptr(q) + offs_cropcap_defrect))
p.pixelaspect.get(unsafe.Pointer(uintptr(q) + offs_cropcap_pixelaspect))
}
func (p *v4l_cropcap) put(q unsafe.Pointer) {
putUint32(q, offs_cropcap_typ, p.typ)
p.bounds.put(unsafe.Pointer(uintptr(q) + offs_cropcap_bounds))
p.defrect.put(unsafe.Pointer(uintptr(q) + offs_cropcap_defrect))
p.pixelaspect.put(unsafe.Pointer(uintptr(q) + offs_cropcap_pixelaspect))
}
func (p *v4l_cropcap) size() int {
return size_cropcap
}
func (p *v4l_crop) get(q unsafe.Pointer) {
p.typ = getUint32(q, offs_crop_typ)
p.c.get(unsafe.Pointer(uintptr(q) + offs_crop_c))
}
func (p *v4l_crop) put(q unsafe.Pointer) {
putUint32(q, offs_crop_typ, p.typ)
p.c.put(unsafe.Pointer(uintptr(q) + offs_crop_c))
}
func (p *v4l_crop) size() int {
return size_crop
}
func (p *v4l_fract) get(q unsafe.Pointer) {
p.numerator = getUint32(q, offs_fract_numerator)
p.denominator = getUint32(q, offs_fract_denominator)
}
func (p *v4l_fract) put(q unsafe.Pointer) {
putUint32(q, offs_fract_numerator, p.numerator)
putUint32(q, offs_fract_denominator, p.denominator)
}
func (p *v4l_timecode) get(q unsafe.Pointer) {
p.typ = getUint32(q, offs_timecode_typ)
p.flags = getUint32(q, offs_timecode_flags)
p.frames = getUint8(q, offs_timecode_frames)
p.seconds = getUint8(q, offs_timecode_seconds)
p.minutes = getUint8(q, offs_timecode_minutes)
p.hours = getUint8(q, offs_timecode_hours)
for i := range p.userbits {
p.userbits[i] = getUint8(q, offs_timecode_userbits+i)
}
}
func (p *v4l_timecode) put(q unsafe.Pointer) {
putUint32(q, offs_timecode_typ, p.typ)
putUint32(q, offs_timecode_flags, p.flags)
putUint8(q, offs_timecode_frames, p.frames)
putUint8(q, offs_timecode_seconds, p.seconds)
putUint8(q, offs_timecode_minutes, p.minutes)
putUint8(q, offs_timecode_hours, p.hours)
for i := range p.userbits {
putUint8(q, offs_timecode_userbits+i, p.userbits[i])
}
}
func (p *v4l_rect) get(q unsafe.Pointer) {
p.left = getInt32(q, offs_rect_left)
p.top = getInt32(q, offs_rect_top)
p.width = getUint32(q, offs_rect_width)
p.height = getUint32(q, offs_rect_height)
}
func (p *v4l_rect) put(q unsafe.Pointer) {
putInt32(q, offs_rect_left, p.left)
putInt32(q, offs_rect_top, p.top)
putUint32(q, offs_rect_width, p.width)
putUint32(q, offs_rect_height, p.height)
}
func (p *v4l_standard) get(q unsafe.Pointer) {
p.index = getUint32(q, offs_standard_index)
p.id = getUint64(q, offs_standard_id)
p.name = getString(q, offs_standard_name, size_standard_name)
p.frameperiod.get(unsafe.Pointer(uintptr(q) + offs_standard_frameperiod))
p.framelines = getUint32(q, offs_standard_framelines)
}
func (p *v4l_standard) put(q unsafe.Pointer) {
putUint32(q, offs_standard_index, p.index)
putUint64(q, offs_standard_id, p.id)
putString(q, offs_standard_name, size_standard_name, p.name)
p.frameperiod.put(unsafe.Pointer(uintptr(q) + offs_standard_frameperiod))
putUint32(q, offs_standard_framelines, p.framelines)
}
func (p *v4l_standard) size() int {
return size_standard
}
func (p *v4l_fmtdesc) get(q unsafe.Pointer) {
p.index = getUint32(q, offs_fmtdesc_index)
p.typ = getUint32(q, offs_fmtdesc_typ)
p.flags = getUint32(q, offs_fmtdesc_flags)
p.description = getString(q, offs_fmtdesc_description, size_fmtdesc_description)
p.pixelformat = getUint32(q, offs_fmtdesc_pixelformat)
}
func (p *v4l_fmtdesc) put(q unsafe.Pointer) {
putUint32(q, offs_fmtdesc_index, p.index)
putUint32(q, offs_fmtdesc_typ, p.typ)
putUint32(q, offs_fmtdesc_flags, p.flags)
putString(q, offs_fmtdesc_description, size_fmtdesc_description, p.description)
putUint32(q, offs_fmtdesc_pixelformat, p.pixelformat)
}
func (p *v4l_fmtdesc) size() int {
return size_fmtdesc
}
func (p *v4l_frmsizeenum) get(q unsafe.Pointer) {
p.index = getUint32(q, offs_frmsizeenum_index)
p.pixelFormat = getUint32(q, offs_frmsizeenum_pixelFormat)
p.typ = getUint32(q, offs_frmsizeenum_typ)
p.discrete.get(unsafe.Pointer(uintptr(q) + offs_frmsizeenum_discrete))
p.stepwise.get(unsafe.Pointer(uintptr(q) + offs_frmsizeenum_stepwise))
}
func (p *v4l_frmsizeenum) put(q unsafe.Pointer) {
putUint32(q, offs_frmsizeenum_index, p.index)
putUint32(q, offs_frmsizeenum_pixelFormat, p.pixelFormat)
putUint32(q, offs_frmsizeenum_typ, p.typ)
switch p.typ {
case v4l_frmsizeTypeDiscrete:
p.discrete.put(unsafe.Pointer(uintptr(q) + offs_frmsizeenum_discrete))
case v4l_frmsizeTypeContinuous, v4l_frmsizeTypeStepwise:
p.stepwise.put(unsafe.Pointer(uintptr(q) + offs_frmsizeenum_stepwise))
}
}
func (p *v4l_frmsizeenum) size() int {
return size_frmsizeenum
}
func (p *v4l_frmsizeDiscrete) get(q unsafe.Pointer) {
p.width = getUint32(q, offs_frmsizeDiscrete_width)
p.height = getUint32(q, offs_frmsizeDiscrete_height)
}
func (p *v4l_frmsizeDiscrete) put(q unsafe.Pointer) {
putUint32(q, offs_frmsizeDiscrete_width, p.width)
putUint32(q, offs_frmsizeDiscrete_height, p.height)
}
func (p *v4l_frmsizeStepwise) get(q unsafe.Pointer) {
p.minWidth = getUint32(q, offs_frmsizeStepwise_minWidth)
p.maxWidth = getUint32(q, offs_frmsizeStepwise_maxWidth)
p.stepWidth = getUint32(q, offs_frmsizeStepwise_stepWidth)
p.minHeight = getUint32(q, offs_frmsizeStepwise_minHeight)
p.maxHeight = getUint32(q, offs_frmsizeStepwise_maxHeight)
p.stepHeight = getUint32(q, offs_frmsizeStepwise_stepHeight)
}
func (p *v4l_frmsizeStepwise) put(q unsafe.Pointer) {
putUint32(q, offs_frmsizeStepwise_minWidth, p.minWidth)
putUint32(q, offs_frmsizeStepwise_maxWidth, p.maxWidth)
putUint32(q, offs_frmsizeStepwise_stepWidth, p.stepWidth)
putUint32(q, offs_frmsizeStepwise_minHeight, p.minHeight)
putUint32(q, offs_frmsizeStepwise_maxHeight, p.maxHeight)
putUint32(q, offs_frmsizeStepwise_stepHeight, p.stepHeight)
}
func (p *v4l_frmivalenum) get(q unsafe.Pointer) {
p.index = getUint32(q, offs_frmivalenum_index)
p.pixelFormat = getUint32(q, offs_frmivalenum_pixelFormat)
p.width = getUint32(q, offs_frmivalenum_width)
p.height = getUint32(q, offs_frmivalenum_height)
p.typ = getUint32(q, offs_frmivalenum_typ)
p.discrete.get(unsafe.Pointer(uintptr(q) + offs_frmivalenum_discrete))
p.stepwise.get(unsafe.Pointer(uintptr(q) + offs_frmivalenum_stepwise))
}
func (p *v4l_frmivalenum) put(q unsafe.Pointer) {
putUint32(q, offs_frmivalenum_index, p.index)
putUint32(q, offs_frmivalenum_pixelFormat, p.pixelFormat)
putUint32(q, offs_frmivalenum_width, p.width)
putUint32(q, offs_frmivalenum_height, p.height)
putUint32(q, offs_frmivalenum_typ, p.typ)
switch p.typ {
case v4l_frmivalTypeDiscrete:
p.discrete.put(unsafe.Pointer(uintptr(q) + offs_frmivalenum_discrete))
case v4l_frmivalTypeContinuous, v4l_frmivalTypeStepwise:
p.stepwise.put(unsafe.Pointer(uintptr(q) + offs_frmivalenum_stepwise))
}
}
func (p *v4l_frmivalenum) size() int {
return size_frmivalenum
}
func (p *v4l_frmivalStepwise) get(q unsafe.Pointer) {
p.min.get(unsafe.Pointer(uintptr(q) + offs_frmivalStepwise_min))
p.max.get(unsafe.Pointer(uintptr(q) + offs_frmivalStepwise_max))
p.step.get(unsafe.Pointer(uintptr(q) + offs_frmivalStepwise_step))
}
func (p *v4l_frmivalStepwise) put(q unsafe.Pointer) {
p.min.put(unsafe.Pointer(uintptr(q) + offs_frmivalStepwise_min))
p.max.put(unsafe.Pointer(uintptr(q) + offs_frmivalStepwise_max))
p.step.put(unsafe.Pointer(uintptr(q) + offs_frmivalStepwise_step))
}
func (p *v4l_queryctrl) get(q unsafe.Pointer) {
p.id = getUint32(q, offs_queryctrl_id)
p.typ = getUint32(q, offs_queryctrl_typ)
p.name = getString(q, offs_queryctrl_name, size_queryctrl_name)
p.minimum = getInt32(q, offs_queryctrl_minimum)
p.maximum = getInt32(q, offs_queryctrl_maximum)
p.step = getInt32(q, offs_queryctrl_step)
p.defaultValue = getInt32(q, offs_queryctrl_defaultValue)
p.flags = getUint32(q, offs_queryctrl_flags)
}
func (p *v4l_queryctrl) put(q unsafe.Pointer) {
putUint32(q, offs_queryctrl_id, p.id)
putUint32(q, offs_queryctrl_typ, p.typ)
putString(q, offs_queryctrl_name, size_queryctrl_name, p.name)
putInt32(q, offs_queryctrl_minimum, p.minimum)
putInt32(q, offs_queryctrl_maximum, p.maximum)
putInt32(q, offs_queryctrl_step, p.step)
putInt32(q, offs_queryctrl_defaultValue, p.defaultValue)
putUint32(q, offs_queryctrl_flags, p.flags)
}
func (p *v4l_queryctrl) size() int {
return size_queryctrl
}
func (p *v4l_querymenu) get(q unsafe.Pointer) {
p.id = getUint32(q, offs_querymenu_id)
p.index = getUint32(q, offs_querymenu_index)
p.name = getString(q, offs_querymenu_name, size_querymenu_name)
p.value = getInt64(q, offs_querymenu_value)
}
func (p *v4l_querymenu) put(q unsafe.Pointer) {
putUint32(q, offs_querymenu_id, p.id)
putUint32(q, offs_querymenu_index, p.index)
}
func (p *v4l_querymenu) size() int {
return size_querymenu
}
func (p *v4l_control) get(q unsafe.Pointer) {
p.id = getUint32(q, offs_control_id)
p.value = getInt32(q, offs_control_value)
}
func (p *v4l_control) put(q unsafe.Pointer) {
putUint32(q, offs_control_id, p.id)
putInt32(q, offs_control_value, p.value)
}
func (p *v4l_control) size() int {
return size_control
}
// Getters and putters for built-in types.
func getUint64(base unsafe.Pointer, offset int) uint64 {
ptr := (*uint64)(unsafe.Pointer(uintptr(base) + uintptr(offset)))
return *ptr
}
func putUint64(base unsafe.Pointer, offset int, value uint64) {
ptr := (*uint64)(unsafe.Pointer(uintptr(base) + uintptr(offset)))
*ptr = value
}
func getInt64(base unsafe.Pointer, offset int) int64 {
ptr := (*int64)(unsafe.Pointer(uintptr(base) + uintptr(offset)))
return *ptr
}
func putInt64(base unsafe.Pointer, offset int, value int64) {
ptr := (*int64)(unsafe.Pointer(uintptr(base) + uintptr(offset)))
*ptr = value
}
func getUint32(base unsafe.Pointer, offset int) uint32 {
ptr := (*uint32)(unsafe.Pointer(uintptr(base) + uintptr(offset)))
return *ptr
}
func putUint32(base unsafe.Pointer, offset int, value uint32) {
ptr := (*uint32)(unsafe.Pointer(uintptr(base) + uintptr(offset)))
*ptr = value
}
func getInt32(base unsafe.Pointer, offset int) int32 {
ptr := (*int32)(unsafe.Pointer(uintptr(base) + uintptr(offset)))
return *ptr
}
func putInt32(base unsafe.Pointer, offset int, value int32) {
ptr := (*int32)(unsafe.Pointer(uintptr(base) + uintptr(offset)))
*ptr = value
}
func getUint8(base unsafe.Pointer, offset int) uint8 {
ptr := (*uint8)(unsafe.Pointer(uintptr(base) + uintptr(offset)))
return *ptr
}
func putUint8(base unsafe.Pointer, offset int, value uint8) {
ptr := (*uint8)(unsafe.Pointer(uintptr(base) + uintptr(offset)))
*ptr = value
}
func getInt(base unsafe.Pointer, offset int) int64 {
p := unsafe.Pointer(uintptr(base) + uintptr(offset))
switch size_int {
case 4:
return int64(*(*uint32)(p))
case 8:
return *(*int64)(p)
default:
panic("bad int size")
}
}
func putInt(base unsafe.Pointer, offset int, value int32) {
p := unsafe.Pointer(uintptr(base) + uintptr(offset))
switch size_int {
case 4:
*(*int32)(p) = value
case 8:
*(*int64)(p) = int64(value)
default:
panic("bad int size")
}
}
func getString(base unsafe.Pointer, offset, maxLen int) string {
buf := make([]byte, 0, maxLen)
for i := 0; i < maxLen; i++ {
ptr := (*byte)(unsafe.Pointer(uintptr(base) + uintptr(offset+i)))
ch := *ptr
if ch == 0 {
break
}
buf = append(buf, ch)
}
return string(buf)
}
func putString(base unsafe.Pointer, offset, maxLen int, value string) {
for i := 0; i < maxLen; i++ {
ptr := (*byte)(unsafe.Pointer(uintptr(base) + uintptr(offset+i)))
var ch byte
if i < len(value) && i != maxLen-1 {
ch = value[i]
}
*ptr = ch
}
}