summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2011-07-30 14:33:37 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2011-07-30 14:33:37 +0200
commitfebcb53ca85d911619456c09c4be49fd73c4964b (patch)
tree12ae3a93d117b56da6e1213882f5cc6de3977adb
omap3-isp-live: Initial commit
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
-rw-r--r--.gitignore5
-rw-r--r--LICENSE340
-rw-r--r--Makefile31
-rw-r--r--README37
-rw-r--r--isp/LICENSE502
-rw-r--r--isp/Makefile24
-rw-r--r--isp/controls.c259
-rw-r--r--isp/controls.h29
-rw-r--r--isp/list.h88
-rw-r--r--isp/media.c390
-rw-r--r--isp/media.h156
-rw-r--r--isp/omap3isp-priv.h68
-rw-r--r--isp/omap3isp.c750
-rw-r--r--isp/omap3isp.h80
-rw-r--r--isp/subdev.c287
-rw-r--r--isp/subdev.h201
-rw-r--r--isp/tools.h34
-rw-r--r--isp/v4l2-pool.c80
-rw-r--r--isp/v4l2-pool.h87
-rw-r--r--isp/v4l2.c717
-rw-r--r--isp/v4l2.h289
-rw-r--r--live.c467
-rw-r--r--snapshot.c418
-rw-r--r--videoout.c228
-rw-r--r--videoout.h43
25 files changed, 5610 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..f43f831
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+*.a
+*.o
+*.so
+live
+snapshot
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..3912109
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) 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
+this service 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 make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. 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.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the 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 a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE 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.
+
+ 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
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 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, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision 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, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This 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 Library General
+Public License instead of this License.
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..849e367
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,31 @@
+CROSS_COMPILE ?=
+KDIR ?=
+
+CC := $(CROSS_COMPILE)gcc
+CFLAGS := -O2 -W -Wall -I$(KDIR)/usr/include
+LDFLAGS := -Lisp
+LIBS := -lomap3isp -lrt
+
+OBJ_LIVE := live.o videoout.o
+OBJ_SNAP := snapshot.o
+
+%.o : %.c
+ $(CC) $(CFLAGS) -c -o $@ $<
+
+all: __isp live snapshot
+
+live: $(OBJ_LIVE) isp/libomap3isp.so
+ $(CC) $(LDFLAGS) -o $@ $(OBJ_LIVE) $(LIBS)
+
+snapshot: $(OBJ_SNAP) isp/libomap3isp.so
+ $(CC) $(LDFLAGS) -o $@ $(OBJ_SNAP) $(LIBS)
+
+__isp:
+ $(MAKE) -C isp CROSS_COMPILE=$(CROSS_COMPILE) KDIR=$(KDIR)
+
+clean:
+ $(MAKE) -C isp clean
+ -$(RM) *.o
+ -$(RM) live
+ -$(RM) snapshot
+
diff --git a/README b/README
new file mode 100644
index 0000000..71da2aa
--- /dev/null
+++ b/README
@@ -0,0 +1,37 @@
+Pre-requisites
+==============
+
+ARM toolchain
+-------------
+
+The ARM development toolchain is based on the CodeSourcery version of GCC. This
+document is based on the hard floating point 2009q3 1.0.18-4 release from the
+scratchbox project, available from
+
+http://scratchbox.org/download/files/sbox-releases/hathor/tarball/scratchbox-toolchain-cs2009q3-eglibc2.10-armv7-hard-1.0.18-4-i386.tar.gz
+
+Other versions should work as well.
+
+Hard floating point is not a requirement but provides better floating point
+performances. Mixing soft floating point and hard floating point applications
+and libraries is *not* supported. Compiling the whole system with the same
+compiler is thus highly advisable.
+
+To install the toolchain, extract the tarball (this document assumes that the
+tarball will be extracted to /opt, but any location can be used) and add the
+compiler bin directory to the PATH environment variable. This can be automated
+by adding
+
+export PATH=/opt/scratchbox/compilers/cs2009q3-eglibc2.10-armv7-hard/bin:$PATH
+
+to ~/.bashrc (when using the bash shell).
+
+Compilation
+===========
+
+To compile the ARM software, run
+
+make KDIR=/path/to/kernel/sources CROSS_COMPILE=arm-none-linux-gnueabi-
+
+This will create the ts binary for ARM.
+
diff --git a/isp/LICENSE b/isp/LICENSE
new file mode 100644
index 0000000..4362b49
--- /dev/null
+++ b/isp/LICENSE
@@ -0,0 +1,502 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL. It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+ When we speak of free software, we are referring to freedom of use,
+not price. Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+ To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ To protect each distributor, we want to make it very clear that
+there is no warranty for the free library. Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+ Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+ Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License. This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License. We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+ When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+ We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less
+of an advantage over competing non-free programs. These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+
+ For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard. To achieve this, non-free programs must be
+allowed to use the library. A more frequent case is that a free
+library does the same job as widely used non-free libraries. In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+ In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software. For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+ Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+ 6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (1) uses at run time a
+ copy of the library already present on the user's computer system,
+ rather than copying library functions into the executable, and (2)
+ will operate properly with a modified version of the library, if
+ the user installs one, as long as the modified version is
+ interface-compatible with the version that the work was made with.
+
+ c) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ d) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ e) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded. In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Libraries
+
+ If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change. You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+ To apply these terms, attach the following notices to the library. It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the library's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+ <signature of Ty Coon>, 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
diff --git a/isp/Makefile b/isp/Makefile
new file mode 100644
index 0000000..4b47ee6
--- /dev/null
+++ b/isp/Makefile
@@ -0,0 +1,24 @@
+AR := $(CROSS_COMPILE)ar
+CC := $(CROSS_COMPILE)gcc
+CFLAGS := -O2 -W -Wall -I$(KDIR)/usr/include -fPIC
+LDFLAGS :=
+
+OBJECTS := controls.o \
+ media.o \
+ omap3isp.o \
+ subdev.o \
+ v4l2.o \
+ v4l2-pool.o
+
+%.o : %.c
+ $(CC) $(CFLAGS) -c -o $@ $<
+
+all: libomap3isp.so
+
+libomap3isp.so: $(OBJECTS)
+ $(CC) -o $@ -shared $^
+
+clean:
+ -$(RM) *.o
+ -$(RM) libomap3isp.so
+
diff --git a/isp/controls.c b/isp/controls.c
new file mode 100644
index 0000000..1c46039
--- /dev/null
+++ b/isp/controls.c
@@ -0,0 +1,259 @@
+/*
+ * OMAP3 ISP library - OMAP3 ISP controls
+ *
+ * Copyright (C) 2010-2011 Ideas on board SPRL
+ *
+ * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <sys/ioctl.h>
+#include <sys/time.h>
+#include <linux/omap3isp.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "controls.h"
+#include "omap3isp.h"
+#include "omap3isp-priv.h"
+#include "subdev.h"
+
+/* -----------------------------------------------------------------------------
+ * Matrix algebra helper functions
+ */
+
+struct matrix {
+ float coeff[3][3];
+};
+
+static void matrix_zero(struct matrix *m)
+{
+ unsigned int i, j;
+
+ for (i = 0; i < 3; ++i) {
+ for (j = 0; j < 3; ++j)
+ m->coeff[i][j] = 0.0;
+ }
+}
+
+static void matrix_invert(struct matrix *m)
+{
+ /* Invert the matrix using the transpose of the matrix of cofactors. The
+ * Gauss-Jordan elimination would be faster in the general case, but we
+ * know that the matrix is 3x3.
+ */
+ const float eps = 1e-6;
+ struct matrix out;
+ unsigned int i, j;
+ float det;
+
+ out.coeff[0][0] = m->coeff[1][1] * m->coeff[2][2]
+ - m->coeff[1][2] * m->coeff[2][1];
+ out.coeff[0][1] = m->coeff[0][2] * m->coeff[2][1]
+ - m->coeff[0][1] * m->coeff[2][2];
+ out.coeff[0][2] = m->coeff[0][1] * m->coeff[1][2]
+ - m->coeff[0][2] * m->coeff[1][1];
+ out.coeff[1][0] = m->coeff[1][2] * m->coeff[2][0]
+ - m->coeff[1][0] * m->coeff[2][2];
+ out.coeff[1][1] = m->coeff[0][0] * m->coeff[2][2]
+ - m->coeff[0][2] * m->coeff[2][0];
+ out.coeff[1][2] = m->coeff[0][2] * m->coeff[1][0]
+ - m->coeff[0][0] * m->coeff[1][2];
+ out.coeff[2][0] = m->coeff[1][0] * m->coeff[2][1]
+ - m->coeff[1][1] * m->coeff[2][0];
+ out.coeff[2][1] = m->coeff[0][1] * m->coeff[2][0]
+ - m->coeff[0][0] * m->coeff[2][1];
+ out.coeff[2][2] = m->coeff[0][0] * m->coeff[1][1]
+ - m->coeff[1][0] * m->coeff[0][1];
+
+ det = m->coeff[0][0] * out.coeff[0][0] +
+ m->coeff[0][1] * out.coeff[1][0] +
+ m->coeff[0][2] * out.coeff[2][0];
+
+ if (det < eps)
+ return;
+
+ det = 1/det;
+
+ for (i = 0; i < 3; ++i)
+ for (j = 0; j < 3; ++j)
+ m->coeff[i][j] = out.coeff[i][j] * det;
+}
+
+static void matrix_multiply(struct matrix *a, const struct matrix *b)
+{
+ struct matrix out;
+
+ /* Compute a * b and return the result in a. */
+ out.coeff[0][0] = a->coeff[0][0] * b->coeff[0][0]
+ + a->coeff[0][1] * b->coeff[1][0]
+ + a->coeff[0][2] * b->coeff[2][0];
+ out.coeff[0][1] = a->coeff[0][0] * b->coeff[0][1]
+ + a->coeff[0][1] * b->coeff[1][1]
+ + a->coeff[0][2] * b->coeff[2][1];
+ out.coeff[0][2] = a->coeff[0][0] * b->coeff[0][2]
+ + a->coeff[0][1] * b->coeff[1][2]
+ + a->coeff[0][2] * b->coeff[2][2];
+ out.coeff[1][0] = a->coeff[1][0] * b->coeff[0][0]
+ + a->coeff[1][1] * b->coeff[1][0]
+ + a->coeff[1][2] * b->coeff[2][0];
+ out.coeff[1][1] = a->coeff[1][0] * b->coeff[0][1]
+ + a->coeff[1][1] * b->coeff[1][1]
+ + a->coeff[1][2] * b->coeff[2][1];
+ out.coeff[1][2] = a->coeff[1][0] * b->coeff[0][2]
+ + a->coeff[1][1] * b->coeff[1][2]
+ + a->coeff[1][2] * b->coeff[2][2];
+ out.coeff[2][0] = a->coeff[2][0] * b->coeff[0][0]
+ + a->coeff[2][1] * b->coeff[1][0]
+ + a->coeff[2][2] * b->coeff[2][0];
+ out.coeff[2][1] = a->coeff[2][0] * b->coeff[0][1]
+ + a->coeff[2][1] * b->coeff[1][1]
+ + a->coeff[2][2] * b->coeff[2][1];
+ out.coeff[2][2] = a->coeff[2][0] * b->coeff[0][2]
+ + a->coeff[2][1] * b->coeff[1][2]
+ + a->coeff[2][2] * b->coeff[2][2];
+
+ *a = out;
+}
+
+static void matrix_float_to_s10q8(__u16 out[3][3], const struct matrix *in)
+{
+ unsigned int i, j;
+
+ for (i = 0; i < 3; ++i) {
+ for (j = 0; j < 3; ++j)
+ out[i][j] = (__u16)((__s16)(in->coeff[i][j] * 256) & 0x3ff);
+ }
+}
+
+static void matrix_float_to_s12q8(__u16 out[3][3], const struct matrix *in)
+{
+ unsigned int i, j;
+
+ for (i = 0; i < 3; ++i) {
+ for (j = 0; j < 3; ++j)
+ out[i][j] = (__u16)((__s16)(in->coeff[i][j] * 256) & 0xfff);
+ }
+}
+
+/* -----------------------------------------------------------------------------
+ * Preview engine parameters configuration
+ */
+
+static const struct matrix omap3isp_preview_csc = {
+ .coeff = {
+ /* Default values. */
+ { 0.2968750, 0.5937500, 0.1093750 },
+ { -0.1718750, -0.3281250, 0.5000000 },
+ { 0.5000000, -0.3828125, -0.0781250 },
+#if 0
+ /* Default values for fluorescent light. */
+ { 0.25781250, 0.50390625, 0.09765625 },
+ { -0.14843750, -0.29296875, 0.43750000 },
+ { 0.43750000, -0.36718750, -0.07031250 },
+#endif
+ },
+};
+
+static const struct matrix omap3isp_preview_rgb2rgb = {
+ .coeff = {
+ /* Default values. */
+ { 1.0, 0.0, 0.0 },
+ { 0.0, 1.0, 0.0 },
+ { 0.0, 0.0, 1.0 },
+#if 0
+ /* Default values for fluorescent light. */
+ { 1.88281250, -0.812500, -0.07031250 },
+ { -0.39453125, 1.671875, -0.27734375 },
+ { -0.12500000, -1.250000, 2.37500000 },
+#endif
+ },
+};
+
+int omap3_isp_preview_setup(struct omap3_isp_device *isp)
+{
+ struct omap3isp_prev_update_config config;
+ struct omap3isp_prev_rgbtorgb rgb2rgb;
+ struct omap3isp_prev_csc csc;
+ int ret;
+
+ memset(&config, 0, sizeof config);
+ config.update = OMAP3ISP_PREV_RGB2RGB | OMAP3ISP_PREV_COLOR_CONV;
+ config.flag = OMAP3ISP_PREV_RGB2RGB | OMAP3ISP_PREV_COLOR_CONV;
+ config.rgb2rgb = &rgb2rgb;
+ config.csc = &csc;
+
+ memset(&rgb2rgb, 0, sizeof rgb2rgb);
+ matrix_float_to_s12q8(rgb2rgb.matrix, &omap3isp_preview_rgb2rgb);
+
+ memset(&csc, 0, sizeof csc);
+ matrix_float_to_s10q8(csc.matrix, &omap3isp_preview_csc);
+
+ v4l2_subdev_open(isp->preview);
+
+ ret = ioctl(isp->preview->fd, VIDIOC_OMAP3ISP_PRV_CFG, &config);
+ if (ret < 0)
+ return -errno;
+
+ return ret;
+}
+
+int omap3_isp_preview_set_contrast(struct omap3_isp_device *isp, unsigned int value)
+{
+ int contrast = value;
+ int ret;
+
+ ret = v4l2_subdev_set_control(isp->preview, V4L2_CID_CONTRAST, &contrast);
+ if (ret < 0)
+ return -errno;
+
+ return ret;
+}
+int omap3_isp_preview_set_saturation(struct omap3_isp_device *isp, float value)
+{
+ struct omap3isp_prev_update_config config;
+ struct omap3isp_prev_rgbtorgb rgb2rgb;
+ struct matrix saturation;
+ struct matrix gain;
+ int ret;
+
+ matrix_zero(&gain);
+ gain.coeff[0][0] = 1.0;
+ gain.coeff[1][1] = value;
+ gain.coeff[2][2] = value;
+
+ saturation = omap3isp_preview_csc;
+ matrix_invert(&saturation);
+ matrix_multiply(&saturation, &gain);
+ matrix_multiply(&saturation, &omap3isp_preview_csc);
+
+ memset(&config, 0, sizeof config);
+ config.update = OMAP3ISP_PREV_RGB2RGB;
+ config.flag = OMAP3ISP_PREV_RGB2RGB;
+ config.rgb2rgb = &rgb2rgb;
+
+ memset(&rgb2rgb, 0, sizeof rgb2rgb);
+ matrix_float_to_s12q8(rgb2rgb.matrix, &saturation);
+
+ ret = ioctl(isp->preview->fd, VIDIOC_OMAP3ISP_PRV_CFG, &config);
+ if (ret < 0)
+ return -errno;
+
+ return ret;
+}
diff --git a/isp/controls.h b/isp/controls.h
new file mode 100644
index 0000000..6c7f74e
--- /dev/null
+++ b/isp/controls.h
@@ -0,0 +1,29 @@
+/*
+ * OMAP3 ISP library - OMAP3 ISP controls
+ *
+ * Copyright (C) 2010-2011 Ideas on board SPRL
+ *
+ * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#ifndef __OMAP3ISP_CONTROLS_H
+#define __OMAP3ISP_CONTROLS_H
+
+struct omap3_isp_device;
+
+int omap3_isp_preview_setup(struct omap3_isp_device *isp);
+
+#endif /* __OMAP3ISP_CONTROLS_H */
diff --git a/isp/list.h b/isp/list.h
new file mode 100644
index 0000000..081e2c4
--- /dev/null
+++ b/isp/list.h
@@ -0,0 +1,88 @@
+/*
+ * OMAP3 ISP library - Double linked lists
+ *
+ * Copyright (C) 2010-2011 Ideas on board SPRL
+ *
+ * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __LIST_H
+#define __LIST_H
+
+#include <stddef.h>
+
+struct list_entry {
+ struct list_entry *prev;
+ struct list_entry *next;
+};
+
+static inline void list_init(struct list_entry *list)
+{
+ list->next = list;
+ list->prev = list;
+}
+
+static inline void list_append(struct list_entry *entry, struct list_entry *list)
+{
+ entry->next = list;
+ entry->prev = list->prev;
+ list->prev->next = entry;
+ list->prev = entry;
+}
+
+static inline void list_prepend(struct list_entry *entry, struct list_entry *list)
+{
+ entry->next = list->next;
+ entry->prev = list;
+ list->next->prev = entry;
+ list->next = entry;
+}
+
+static inline void list_remove(struct list_entry *entry)
+{
+ entry->prev->next = entry->next;
+ entry->next->prev = entry->prev;
+}
+
+#define list_entry(entry, type, member) \
+ (type *)((char *)(entry) - offsetof(type, member))
+
+#define list_first_entry(list, type, member) \
+ list_entry(list->next, type, member)
+
+#define list_last_entry(list, type, member) \
+ list_entry(list->prev, type, member)
+
+#define list_for_each(entry, list) \
+ for (entry = (list)->next; entry != (list); entry = entry->next)
+
+#define list_for_each_entry(entry, list, member) \
+ for (entry = list_entry((list)->next, typeof(*entry), member); \
+ &entry->member != (list); \
+ entry = list_entry(entry->member.next, typeof(*entry), member))
+
+#define list_for_each_safe(entry, __next, list) \
+ for (entry = (list)->next, __next = entry->next; entry != (list); \
+ entry = __next, __next = entry->next)
+
+#define list_for_each_entry_safe(entry, __next, list, member) \
+ for (entry = list_entry((list)->next, typeof(*entry), member), \
+ __next = list_entry(entry->member.next, typeof(*entry), member); \
+ &entry->member != (list); \
+ entry = __next, __next = list_entry(entry->member.next, typeof(*entry), member))
+
+#endif /* __LIST_H */
diff --git a/isp/media.c b/isp/media.c
new file mode 100644
index 0000000..d2082f0
--- /dev/null
+++ b/isp/media.c
@@ -0,0 +1,390 @@
+/*
+ * OMAP3 ISP library - Media controller
+ *
+ * Copyright (C) 2010-2011 Ideas on board SPRL
+ *
+ * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <linux/videodev2.h>
+#include <linux/media.h>
+
+#include "media.h"
+#include "tools.h"
+
+struct media_entity_pad *media_entity_remote_source(struct media_entity_pad *pad)
+{
+ unsigned int i;
+
+ for (i = 0; i < pad->entity->num_links; ++i) {
+ struct media_entity_link *link = &pad->entity->links[i];
+
+ if (!(link->flags & MEDIA_LNK_FL_ENABLED))
+ continue;
+
+ if (link->source == pad)
+ return link->sink;
+
+ if (link->sink == pad)
+ return link->source;
+ }
+
+ return NULL;
+}
+
+struct media_entity *media_get_entity_by_name(struct media_device *media,
+ const char *name)
+{
+ unsigned int i;
+
+ for (i = 0; i < media->entities_count; ++i) {
+ struct media_entity *entity = &media->entities[i];
+
+ if (strcmp(entity->info.name, name) == 0)
+ return entity;
+ }
+
+ return NULL;
+}
+
+struct media_entity *media_get_entity_by_id(struct media_device *media,
+ __u32 id)
+{
+ unsigned int i;
+
+ for (i = 0; i < media->entities_count; ++i) {
+ struct media_entity *entity = &media->entities[i];
+
+ if (entity->info.id == id)
+ return entity;
+ }
+
+ return NULL;
+}
+
+int media_setup_link(struct media_device *media,
+ struct media_entity_pad *source,
+ struct media_entity_pad *sink,
+ __u32 flags)
+{
+ struct media_entity_link *link;
+ struct media_link_desc ulink;
+ unsigned int i;
+ int ret;
+
+ for (i = 0; i < source->entity->num_links; i++) {
+ link = &source->entity->links[i];
+
+ if (link->source->entity == source->entity &&
+ link->source->index == source->index &&
+ link->sink->entity == sink->entity &&
+ link->sink->index == sink->index)
+ break;
+ }
+
+ if (i == source->entity->num_links) {
+ printf("%s: Link not found\n", __func__);
+ return -EINVAL;
+ }
+
+ /* source pad */
+ ulink.source.entity = source->entity->info.id;
+ ulink.source.index = source->index;
+ ulink.source.flags = MEDIA_PAD_FL_SOURCE;
+
+ /* sink pad */
+ ulink.sink.entity = sink->entity->info.id;
+ ulink.sink.index = sink->index;
+ ulink.sink.flags = MEDIA_PAD_FL_SINK;
+
+ ulink.flags = flags | (link->flags & MEDIA_LNK_FL_IMMUTABLE);
+
+ ret = ioctl(media->fd, MEDIA_IOC_SETUP_LINK, &ulink);
+ if (ret < 0) {
+ printf("%s: Unable to setup link (%s)\n", __func__,
+ strerror(errno));
+ return ret;
+ }
+
+ link->flags = flags;
+ return 0;
+}
+
+int media_reset_links(struct media_device *media)
+{
+ unsigned int i, j;
+ int ret;
+
+ for (i = 0; i < media->entities_count; ++i) {
+ struct media_entity *entity = &media->entities[i];
+
+ for (j = 0; j < entity->num_links; j++) {
+ struct media_entity_link *link = &entity->links[j];
+
+ if (link->flags & MEDIA_LNK_FL_IMMUTABLE ||
+ link->source->entity != entity)
+ continue;
+
+ ret = media_setup_link(media, link->source, link->sink,
+ link->flags & ~MEDIA_LNK_FL_ENABLED);
+ if (ret < 0)
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
+static struct media_entity_link *media_entity_add_link(struct media_entity *entity)
+{
+ if (entity->num_links >= entity->max_links) {
+ struct media_entity_link *links = entity->links;
+ unsigned int max_links = entity->max_links * 2;
+ unsigned int i;
+
+ links = realloc(links, max_links * sizeof *links);
+ if (links == NULL)
+ return NULL;
+
+ for (i = 0; i < entity->num_links; ++i)
+ links[i].reverse->reverse = &links[i];
+
+ entity->max_links = max_links;
+ entity->links = links;
+ }
+
+ return &entity->links[entity->num_links++];
+}
+
+static int media_enum_links(struct media_device *media)
+{
+ __u32 id;
+ int ret = 0;
+
+ for (id = 1; id <= media->entities_count; id++) {
+ struct media_entity *entity = &media->entities[id - 1];
+ struct media_links_enum links;
+ unsigned int i;
+
+ links.entity = entity->info.id;
+ links.pads = malloc(entity->info.pads * sizeof(struct media_pad_desc));
+ links.links = malloc(entity->info.links * sizeof(struct media_link_desc));
+
+ if (ioctl(media->fd, MEDIA_IOC_ENUM_LINKS, &links) < 0) {
+ printf("%s: Unable to enumerate pads and links (%s).\n",
+ __func__, strerror(errno));
+ free(links.pads);
+ free(links.links);
+ return -errno;
+ }
+
+ for (i = 0; i < entity->info.pads; ++i) {
+ entity->pads[i].entity = entity;
+ entity->pads[i].index = links.pads[i].index;
+ entity->pads[i].flags = links.pads[i].flags;
+ }
+
+ for (i = 0; i < entity->info.links; ++i) {
+ struct media_link_desc *link = &links.links[i];
+ struct media_entity_link *fwdlink;
+ struct media_entity_link *backlink;
+ struct media_entity *source;
+ struct media_entity *sink;
+
+ source = media_get_entity_by_id(media, link->source.entity);
+ sink = media_get_entity_by_id(media, link->sink.entity);
+
+ if (source == NULL || sink == NULL) {
+ printf("WARNING entity %u link %u from %u/%u to %u/%u is invalid!\n",
+ id, i, link->source.entity, link->source.index,
+ link->sink.entity, link->sink.index);
+ ret = -EINVAL;
+ }
+
+ fwdlink = media_entity_add_link(source);
+ fwdlink->source = &source->pads[link->source.index];
+ fwdlink->sink = &sink->pads[link->sink.index];
+ fwdlink->flags = links.links[i].flags;
+
+ backlink = media_entity_add_link(sink);
+ backlink->source = &source->pads[link->source.index];
+ backlink->sink = &sink->pads[link->sink.index];
+ backlink->flags = links.links[i].flags;
+
+ fwdlink->reverse = backlink;
+ backlink->reverse = fwdlink;
+ }
+
+ free(links.pads);
+ free(links.links);
+ }
+
+ return ret;
+}
+
+static int media_enum_entities(struct media_device *media)
+{
+ struct media_entity *entity;
+ struct stat devstat;
+ unsigned int size;
+ char devname[32];
+ char sysname[32];
+ char target[1024];
+ char *p;
+ __u32 id;
+ int ret;
+
+ for (id = 0; ; id = entity->info.id) {
+ size = (media->entities_count + 1) * sizeof(*media->entities);
+ media->entities = realloc(media->entities, size);
+
+ entity = &media->entities[media->entities_count];
+ memset(entity, 0, sizeof(*entity));
+ entity->fd = -1;
+ entity->info.id = id | MEDIA_ENT_ID_FLAG_NEXT;
+
+ ret = ioctl(media->fd, MEDIA_IOC_ENUM_ENTITIES, &entity->info);
+ if (ret < 0) {
+ if (errno == EINVAL)
+ break;
+ return -errno;
+ }
+
+ /* Number of links (for outbound links) plus number of pads (for
+ * inbound links) is a good safe initial estimate of the total
+ * number of links.
+ */
+ entity->max_links = entity->info.pads + entity->info.links;
+
+ entity->pads = malloc(entity->info.pads * sizeof(*entity->pads));
+ entity->links = malloc(entity->max_links * sizeof(*entity->links));
+ if (entity->pads == NULL || entity->links == NULL)
+ return -ENOMEM;
+
+ media->entities_count++;
+
+ /* Find the corresponding device name. */
+ if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE &&
+ media_entity_type(entity) != MEDIA_ENT_T_V4L2_SUBDEV)
+ continue;
+
+ sprintf(sysname, "/sys/dev/char/%u:%u", entity->info.v4l.major,
+ entity->info.v4l.minor);
+ ret = readlink(sysname, target, sizeof(target));
+ if (ret < 0)
+ continue;
+
+ target[ret] = '\0';
+ p = strrchr(target, '/');
+ if (p == NULL)
+ continue;
+
+ sprintf(devname, "/dev/%s", p + 1);
+ ret = stat(devname, &devstat);
+ if (ret < 0)
+ continue;
+
+ /* Sanity check: udev might have reordered the device nodes.
+ * Make sure the major/minor match. We should really use
+ * libudev.
+ */
+ if (major(devstat.st_rdev) == entity->info.v4l.major &&
+ minor(devstat.st_rdev) == entity->info.v4l.minor)
+ strcpy(entity->devname, devname);
+ }
+
+ return 0;
+}
+
+struct media_device *media_open(const char *name, int verbose)
+{
+ struct media_device *media;
+ int ret;
+
+ media = malloc(sizeof(*media));
+ if (media == NULL) {
+ printf("%s: unable to allocate memory\n", __func__);
+ return NULL;
+ }
+ memset(media, 0, sizeof(*media));
+
+ if (verbose)
+ printf("Opening media device %s\n", name);
+ media->fd = open(name, O_RDWR);
+ if (media->fd < 0) {
+ media_close(media);
+ printf("%s: Can't open media device %s\n", __func__, name);
+ return NULL;
+ }
+
+ if (verbose)
+ printf("Enumerating entities\n");
+
+ ret = media_enum_entities(media);
+ if (ret < 0) {
+ printf("%s: Unable to enumerate entities for device %s (%s)\n",
+ __func__, name, strerror(-ret));
+ media_close(media);
+ return NULL;
+ }
+
+ if (verbose) {
+ printf("Found %u entities\n", media->entities_count);
+ printf("Enumerating pads and links\n");
+ }
+
+ ret = media_enum_links(media);
+ if (ret < 0) {
+ printf("%s: Unable to enumerate pads and linksfor device %s\n",
+ __func__, name);
+ media_close(media);
+ return NULL;
+ }
+
+ return media;
+}
+
+void media_close(struct media_device *media)
+{
+ unsigned int i;
+
+ if (media->fd != -1)
+ close(media->fd);
+
+ for (i = 0; i < media->entities_count; ++i) {
+ struct media_entity *entity = &media->entities[i];
+
+ free(entity->pads);
+ free(entity->links);
+ if (entity->fd != -1)
+ close(entity->fd);
+ }
+
+ free(media->entities);
+ free(media);
+}
diff --git a/isp/media.h b/isp/media.h
new file mode 100644
index 0000000..7940915
--- /dev/null
+++ b/isp/media.h
@@ -0,0 +1,156 @@
+/*
+ * OMAP3 ISP library - Media controller
+ *
+ * Copyright (C) 2010-2011 Ideas on board SPRL
+ *
+ * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __MEDIA_H__
+#define __MEDIA_H__
+
+#include <linux/media.h>
+
+struct media_entity_link {
+ struct media_entity_pad *source;
+ struct media_entity_pad *sink;
+ struct media_entity_link *reverse;
+ __u32 flags;
+};
+
+struct media_entity_pad {
+ struct media_entity *entity;
+ __u32 index;
+ __u32 flags;
+};
+
+struct media_entity {
+ struct media_entity_desc info;
+ struct media_entity_pad *pads;
+ struct media_entity_link *links;
+ unsigned int max_links;
+ unsigned int num_links;
+
+ char devname[32];
+ int fd;
+};
+
+struct media_device {
+ int fd;
+ struct media_entity *entities;
+ unsigned int entities_count;
+};
+
+/*
+ * media_open - Open a media device
+ * @name: Name (including path) of the device node
+ * @verbose: Whether to print verbose information on the standard output
+ *
+ * Open the media device referenced by @name and enumerate entities, pads and
+ * links.
+ *
+ * Return a pointer to a newly allocated media_device structure instance on
+ * success and NULL on failure. The returned pointer must be freed with
+ * media_close when the device isn't needed anymore.
+ */
+struct media_device *media_open(const char *name, int verbose);
+
+/*
+ * media_close - Close a media device
+ * @media: Device instance
+ *
+ * Close the @media device instance and free allocated resources. Access to the
+ * device instance is forbidden after this function returns.
+ */
+void media_close(struct media_device *media);
+
+/*
+ * media_entity_remote_source - Locate the pad at the other end of a link
+ * @pad: Sink pad at one end of the link
+ *
+ * Locate the source pad connected to @pad through an enabled link. As only one
+ * link connected to a sink pad can be enabled at a time, the connected source
+ * pad is guaranteed to be unique.
+ *
+ * Return a pointer to the connected source pad, or NULL if all links connected
+ * to @pad are disabled.
+ */
+struct media_entity_pad *media_entity_remote_source(struct media_entity_pad *pad);
+
+/*
+ * media_entity_type - Get the type of an entity
+ * @entity: The entity
+ *
+ * Return the type of @entity.
+ */
+static inline unsigned int media_entity_type(struct media_entity *entity)
+{
+ return entity->info.type & MEDIA_ENT_TYPE_MASK;
+}
+
+/*
+ * media_get_entity_by_name - Find an entity by its name
+ * @media: Media device
+ * @name: Entity name
+ *
+ * Search for an entity with a name equal to @name. Return a pointer to the
+ * entity if found, or NULL otherwise.
+ */
+struct media_entity *media_get_entity_by_name(struct media_device *media,
+ const char *name);
+
+/*
+ * media_get_entity_by_id - Find an entity by its ID
+ * @media: Media device
+ * @id: Entity ID
+ *
+ * Search for an entity with an ID equal to @id. Return a pointer to the entity
+ * if found, or NULL otherwise.
+ */
+struct media_entity *media_get_entity_by_id(struct media_device *media,
+ __u32 id);
+
+/*
+ * media_setup_link - Configure a link
+ * @media: Media device
+ * @source: Source pad at the link origin
+ * @sink: Sink pad at the link target
+ * @flags: Configuration flags
+ *
+ * Locate the link between @source and @sink, and configure it by applying the
+ * new @flags.
+ *
+ * Only the MEDIA_LINK_FLAG_ENABLED flag is writable.
+ *
+ * Return 0 on success, or a negative error code on failure.
+ */
+int media_setup_link(struct media_device *media,
+ struct media_entity_pad *source, struct media_entity_pad *sink,
+ __u32 flags);
+
+/*
+ * media_reset_links - Reset all links to the disabled state.
+ * @media: Media device
+ *
+ * Disable all links in the media device. This function is usually used after
+ * opening a media device to reset all links to a known state.
+ *
+ * Return 0 on success, or a negative error code on failure.
+ */
+int media_reset_links(struct media_device *media);
+
+#endif
diff --git a/isp/omap3isp-priv.h b/isp/omap3isp-priv.h
new file mode 100644
index 0000000..fe03d96
--- /dev/null
+++ b/isp/omap3isp-priv.h
@@ -0,0 +1,68 @@
+/*
+ * OMAP3 ISP library - OMAP3 ISP private header
+ *
+ * Copyright (C) 2010-2011 Ideas on board SPRL
+ *
+ * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __OMAP3ISP_PRIV_H
+#define __OMAP3ISP_PRIV_H
+
+#include "omap3isp.h"
+
+/*
+ * struct omap3_isp_video - OMAP3 video device
+ * @subdev: Sub-device from which video is captured for this device
+ * @node: Output video node entity
+ * @video: V4L2 capture device
+ * @format: Current video format
+ * @pool: Buffers pool
+ * @scaler: Whether scaling should be performed on the ISP or the sensor
+ * @dequeued: Bitmask of dequeued buffers that belong to the application
+ * @queued: Number of buffers queued to the driver
+ * @running: Whether video capture is running on the device
+ */
+struct omap3_isp_video {
+ struct media_entity *subdev;
+ struct media_entity *node;
+ struct v4l2_device *video;
+ struct v4l2_mbus_framefmt format;
+ struct v4l2_buffers_pool *pool;
+ enum omap3_isp_scaler scaler;
+ unsigned int dequeued;
+ unsigned int queued;
+ bool running;
+};
+
+struct omap3_isp_device {
+ struct media_device *mdev;
+
+ struct media_entity *ccdc;
+ struct media_entity *preview;
+ struct media_entity *resizer;
+ struct media_entity *sensor;
+
+ struct v4l2_mbus_framefmt sensor_format;
+
+ struct omap3_isp_video viewfinder;
+ struct omap3_isp_video snapshot;
+
+ const struct omap3_isp_operations *ops;
+};
+
+#endif
diff --git a/isp/omap3isp.c b/isp/omap3isp.c
new file mode 100644
index 0000000..19671c7
--- /dev/null
+++ b/isp/omap3isp.c
@@ -0,0 +1,750 @@
+/*
+ * OMAP3 ISP library - OMAP3 ISP
+ *
+ * Copyright (C) 2010-2011 Ideas on board SPRL
+ *
+ * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "controls.h"
+#include "omap3isp.h"
+#include "omap3isp-priv.h"
+#include "subdev.h"
+
+#define ENTITY_CCDC "OMAP3 ISP CCDC"
+#define ENTITY_PREVIEW "OMAP3 ISP preview"
+#define ENTITY_RESIZER "OMAP3 ISP resizer"
+
+/* -----------------------------------------------------------------------------
+ * Helper functions
+ */
+
+static int setup_link(struct omap3_isp_device *isp, struct media_entity *source,
+ struct media_entity *sink, __u32 flags)
+{
+ unsigned int i;
+ int ret;
+
+ for (i = 0; i < source->num_links; ++i) {
+ if (source->links[i].source->entity == source &&
+ source->links[i].sink->entity == sink)
+ break;
+ }
+
+ if (i == source->num_links)
+ return -ENOENT;
+
+ ret = media_setup_link(isp->mdev, source->links[i].source,
+ source->links[i].sink, flags);
+ if (ret < 0)
+ printf("error: unable to %s %s -> %s link.\n",
+ flags & MEDIA_LNK_FL_ENABLED ? "enable" : "disable",
+ source->info.name, sink->info.name);
+
+ return ret;
+}
+
+static struct media_entity_link *entity_output_link(struct media_entity *entity)
+{
+ unsigned int i;
+
+ for (i = 0; i < entity->num_links; ++i) {
+ if (entity->links[i].source->entity == entity &&
+ entity->links[i].flags & MEDIA_LNK_FL_ENABLED)
+ return &entity->links[i];
+ }
+
+ return NULL;
+}
+
+static struct media_entity *entity_output_node(struct media_entity *entity)
+{
+ struct media_entity *node;
+ unsigned int i;
+
+ for (i = 0; i < entity->num_links; ++i) {
+ node = entity->links[i].sink->entity;
+ if (media_entity_type(node) == MEDIA_ENT_T_DEVNODE)
+ break;
+ }
+
+ if (i == entity->num_links) {
+ printf("error: unable to locate %s output video node.\n",
+ entity->info.name);
+ return NULL;
+ }
+
+ return node;
+}
+
+static __u32 mbus_to_pix(enum v4l2_mbus_pixelcode code)
+{
+ switch (code) {
+ case V4L2_MBUS_FMT_SBGGR10_1X10:
+ return V4L2_PIX_FMT_SBGGR10;
+ case V4L2_MBUS_FMT_SGBRG10_1X10:
+ return V4L2_PIX_FMT_SGBRG10;
+ case V4L2_MBUS_FMT_SGRBG10_1X10:
+ return V4L2_PIX_FMT_SGRBG10;
+ case V4L2_MBUS_FMT_SRGGB10_1X10:
+ return V4L2_PIX_FMT_SRGGB10;
+ case V4L2_MBUS_FMT_UYVY8_1X16:
+ return V4L2_PIX_FMT_UYVY;
+ case V4L2_MBUS_FMT_YUYV8_1X16:
+ return V4L2_PIX_FMT_YUYV;
+ default:
+ return 0;
+ }
+}
+
+/* -----------------------------------------------------------------------------
+ * Open/close
+ */
+
+struct omap3_isp_device *omap3_isp_open(const char *devname,
+ const struct omap3_isp_operations *ops)
+{
+ struct omap3_isp_device *isp;
+ struct media_entity *entity;
+ unsigned int i;
+ int ret;
+
+ isp = malloc(sizeof *isp);
+ if (isp == NULL)
+ return NULL;
+
+ memset(isp, 0, sizeof *isp);
+ isp->ops = ops;
+
+ /* Open the media device and reset all links to make sure we're in a
+ * consistent, known state.
+ */
+ isp->mdev = media_open(devname, 0);
+ if (isp->mdev == NULL) {
+ printf("error: unable to open media device %s\n", devname);
+ goto error;
+ }
+
+ ret = media_reset_links(isp->mdev);
+ if (ret < 0) {
+ printf("error: unable to reset links.\n");
+ goto error;
+ }
+
+ /* Locate the entities that will be used in the pipelines. OMAP3 ISP
+ * modules are looked up by name.
+ */
+ isp->ccdc = media_get_entity_by_name(isp->mdev, ENTITY_CCDC);
+ isp->preview = media_get_entity_by_name(isp->mdev, ENTITY_PREVIEW);
+ isp->resizer = media_get_entity_by_name(isp->mdev, ENTITY_RESIZER);
+
+ if (isp->ccdc == NULL || isp->preview == NULL || isp->resizer == NULL) {
+ printf("error: unable to locate one or more ISP entities.\n");
+ goto error;
+ }
+
+ /* The sensor and video nodes are located by following links. */
+ for (i = 0; i < isp->ccdc->num_links; ++i) {
+ entity = isp->ccdc->links[i].source->entity;
+ if (media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV &&
+ entity->info.pads == 1)
+ break;
+ }
+
+ if (i == isp->ccdc->num_links) {
+ printf("error: unable to locate sensor.\n");
+ goto error;
+ }
+
+ isp->sensor = entity;
+
+ isp->viewfinder.scaler = OMAP3_ISP_SCALER_ISP;
+ isp->viewfinder.subdev = isp->resizer;
+ isp->viewfinder.node = entity_output_node(isp->resizer);
+ if (isp->viewfinder.node == NULL)
+ goto error;
+
+ /* Retrieve the sensor default format. */
+ ret = v4l2_subdev_get_format(isp->sensor, &isp->sensor_format, 0,
+ V4L2_SUBDEV_FORMAT_TRY);
+ if (ret < 0) {
+ printf("error: unable to get sensor default format.\n");
+ goto error;
+ }
+
+ /* Setup the viewfinder pipeline. */
+ ret = setup_link(isp, isp->sensor, isp->ccdc, MEDIA_LNK_FL_ENABLED);
+ if (ret < 0)
+ goto error;
+
+ ret = setup_link(isp, isp->ccdc, isp->preview, MEDIA_LNK_FL_ENABLED);
+ if (ret < 0)
+ goto error;
+
+ ret = setup_link(isp, isp->preview, isp->resizer, MEDIA_LNK_FL_ENABLED);
+ if (ret < 0)
+ goto error;
+
+ ret = setup_link(isp, isp->resizer, isp->viewfinder.node,
+ MEDIA_LNK_FL_ENABLED);
+ if (ret < 0)
+ goto error;
+
+ ret = omap3_isp_preview_setup(isp);
+ if (ret < 0) {
+ printf("error: unable to setup preview engine.\n");
+ goto error;
+ }
+
+ return isp;
+
+error:
+ omap3_isp_close(isp);
+ return NULL;
+}
+
+void omap3_isp_close(struct omap3_isp_device *isp)
+{
+ if (isp == NULL)
+ return;
+
+ media_close(isp->mdev);
+ free(isp);
+}
+
+/* -----------------------------------------------------------------------------
+ * Pipeline management
+ */
+
+static int omap3_isp_pipeline_set_format(struct omap3_isp_device *isp,
+ struct v4l2_mbus_framefmt *ofmt,
+ enum omap3_isp_scaler scaler,
+ enum v4l2_subdev_format_whence which)
+{
+ struct v4l2_mbus_framefmt format;
+ struct media_entity_link *link;
+ struct media_entity_pad *pad;
+ struct media_entity *entity;
+ int ret;
+
+ /* Configure formats. Start from the sensor output and propagate the
+ * format through the pipeline.
+ */
+
+ /* When scaling on the ISP, select the sensor default output format.
+ * Otherwise scale as much as possible on the sensor.
+ */
+ if (scaler == OMAP3_ISP_SCALER_ISP)
+ format = isp->sensor_format;
+ else
+ format = *ofmt;
+
+ ret = v4l2_subdev_set_format(isp->sensor, &format, 0, which);
+ if (ret < 0) {
+ printf("error: get format on sensor output failed.\n");
+ return ret;
+ }
+
+ for (entity = isp->sensor; ; ) {
+
+ link = entity_output_link(entity);
+ if (link == NULL)
+ break;
+
+ entity = link->sink->entity;
+ if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
+ break;
+
+ pad = link->source;
+ ret = v4l2_subdev_get_format(pad->entity, &format, pad->index, which);
+ if (ret < 0) {
+ printf("error: get format failed on %s:%u.\n",
+ pad->entity->info.name, pad->index);
+ return ret;
+ }
+
+ /* Try to force the output format code onto the output pad. */
+ format.code = ofmt->code;
+ ret = v4l2_subdev_set_format(pad->entity, &format, pad->index, which);
+ if (ret < 0) {
+ printf("error: set format failed on %s:%u.\n",
+ pad->entity->info.name, pad->index);
+ return ret;
+ }
+
+ pad = link->sink;
+ ret = v4l2_subdev_set_format(pad->entity, &format, pad->index, which);
+ if (ret < 0) {
+ printf("error: set format failed on %s:%u.\n",
+ pad->entity->info.name, pad->index);
+ return ret;
+ }
+ }
+
+ if (ofmt == NULL)
+ return 0;
+
+ pad = link->source;
+ ret = v4l2_subdev_set_format(pad->entity, ofmt, pad->index, which);
+ if (ret < 0) {
+ printf("error: set format failed on %s:%u.\n",
+ pad->entity->info.name, pad->index);
+ return ret;
+ }
+
+ return 0;
+}
+
+/* -----------------------------------------------------------------------------
+ * Viewfinder
+ */
+
+static int omap3_isp_viewfinder_setup_pipeline(struct omap3_isp_device *isp,
+ struct v4l2_mbus_framefmt *ofmt)
+{
+ int ret;
+
+ /* Configure the formats on the pipeline. */
+ ret = omap3_isp_pipeline_set_format(isp, ofmt, isp->viewfinder.scaler,
+ V4L2_SUBDEV_FORMAT_ACTIVE);
+ if (ret < 0) {
+ printf("error: unable to configure formats on pipeline.\n");
+ return ret;
+ }
+
+ return 0;
+}
+
+int omap3_isp_viewfinder_setup(struct omap3_isp_device *isp,
+ struct v4l2_mbus_framefmt *ofmt)
+{
+ struct v4l2_pix_format format;
+ int ret;
+
+ /* Setup the pipeline. */
+ ret = omap3_isp_viewfinder_setup_pipeline(isp, ofmt);
+ if (ret < 0)
+ return ret;
+
+ /* Open the V4L2 device. */
+ isp->viewfinder.video = v4l2_open(isp->viewfinder.node->devname);
+ if (isp->viewfinder.video == NULL) {
+ printf("error: unable to open video capture device %s\n",
+ isp->viewfinder.node->devname);
+ return -ENXIO;
+ }
+
+ /* Set the capture format on the output video node. */
+ memset(&format, 0, sizeof format);
+ format.pixelformat = mbus_to_pix(ofmt->code);
+ format.width = ofmt->width;
+ format.height = ofmt->height;
+
+ ret = v4l2_set_format(isp->viewfinder.video, &format);
+ if (ret < 0)
+ return ret;
+
+ isp->viewfinder.format = *ofmt;
+
+ return 0;
+}
+
+int omap3_isp_viewfinder_set_pool(struct omap3_isp_device *isp,
+ struct v4l2_buffers_pool *pool)
+{
+ int ret;
+
+ /* Allocate video buffers. */
+ ret = v4l2_alloc_buffers(isp->viewfinder.video, pool, V4L2_MEMORY_USERPTR);
+ if (ret < 0) {
+ printf("error: unable to allocate buffers for viewfinder.\n");
+ return ret;
+ }
+
+ isp->viewfinder.dequeued = 0;
+ isp->viewfinder.queued = 0;
+ return 0;
+}
+
+int omap3_isp_viewfinder_set_scaler(struct omap3_isp_device *isp,
+ enum omap3_isp_scaler scaler)
+{
+ struct v4l2_mbus_framefmt format;
+ int ret;
+
+ if (isp->viewfinder.scaler == scaler)
+ return 0;
+
+ isp->viewfinder.scaler = scaler;
+
+ /* If omap3_isp_viewfinder_setup() hasn't been called yet retur now. */
+ if (isp->viewfinder.format.width == 0 ||
+ isp->viewfinder.format.height == 0)
+ return 0;
+
+ format = isp->viewfinder.format;
+ ret = omap3_isp_viewfinder_setup_pipeline(isp, &format);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
+static void omap3_isp_viewfinder_event(void *priv)
+{
+ struct omap3_isp_device *isp = priv;
+ struct v4l2_video_buffer buffer;
+ int ret;
+
+ /* Dequeue the buffer */
+ ret = v4l2_dequeue_buffer(isp->viewfinder.video, &buffer);
+ if (ret < 0) {
+ printf("error: unable to dequeue buffer: %s (%d)\n",
+ strerror(-ret), ret);
+ return;
+ }
+
+ isp->viewfinder.dequeued |= 1 << buffer.index;
+ isp->viewfinder.queued--;
+
+ if (isp->viewfinder.queued == 0)
+ isp->ops->unwatch_fd(isp->viewfinder.video->fd);
+
+ isp->ops->viewfinder_ready(isp, &buffer);
+}
+
+int omap3_isp_viewfinder_start(struct omap3_isp_device *isp)
+{
+ struct v4l2_video_buffer buffer;
+ unsigned int i;
+ int ret;
+
+ /* Queue all buffers for video capture. */
+ for (i = 0; i < isp->viewfinder.video->nbufs; ++i) {
+ if (isp->viewfinder.dequeued & (1 << i))
+ continue;
+
+ buffer.index = i;
+
+ ret = v4l2_queue_buffer(isp->viewfinder.video, &buffer);
+ if (ret < 0) {
+ printf("error: unable to queue buffer %u (%d)\n", i, ret);
+ return -errno;
+ }
+
+ isp->viewfinder.queued++;
+ }
+
+ if (isp->ops->prepare_streamon)
+ isp->ops->prepare_streamon(isp);
+
+ /* Watch the viewfinder file descriptor. */
+ isp->ops->watch_fd(isp->viewfinder.video->fd, OMAP3_ISP_EVENT_READ,
+ omap3_isp_viewfinder_event, isp);
+
+ ret = v4l2_stream_on(isp->viewfinder.video);
+ if (ret < 0) {
+ printf("error: streamon failed for viewfinder\n");
+ return ret;
+ }
+
+ isp->viewfinder.running = true;
+ return 0;
+}
+
+
+int omap3_isp_viewfinder_stop(struct omap3_isp_device *isp)
+{
+ int ret;
+
+ isp->ops->unwatch_fd(isp->viewfinder.video->fd);
+
+ ret = v4l2_stream_off(isp->viewfinder.video);
+ if (ret < 0) {
+ printf("error: streamoff failed for viewfinder\n");
+ return ret;
+ }
+
+ isp->viewfinder.queued = 0;
+ isp->viewfinder.running = false;
+ return 0;
+}
+
+int omap3_isp_viewfinder_put_buffer(struct omap3_isp_device *isp,
+ struct v4l2_video_buffer *buffer)
+{
+ isp->viewfinder.dequeued &= ~(1 << buffer->index);
+
+ if (!isp->viewfinder.running)
+ return 0;
+
+ if (isp->viewfinder.queued == 0)
+ isp->ops->watch_fd(isp->viewfinder.video->fd,
+ OMAP3_ISP_EVENT_READ,
+ omap3_isp_viewfinder_event, isp);
+
+ isp->viewfinder.queued++;
+ return v4l2_queue_buffer(isp->viewfinder.video, buffer);
+}
+
+/* -----------------------------------------------------------------------------
+ * Snapshot
+ *
+ * Snapshot capture is optional. Applications using snapshot capture must call
+ * omap3_isp_snapshot_setup() before starting the viewfinder.
+ */
+
+static int omap3_isp_snapshot_restore_pipeline(struct omap3_isp_device *isp)
+{
+ int ret;
+
+ ret = setup_link(isp, isp->snapshot.subdev, isp->snapshot.node, 0);
+ if (ret < 0)
+ return ret;
+
+ if (isp->snapshot.format.code == V4L2_MBUS_FMT_UYVY8_1X16 ||
+ isp->snapshot.format.code == V4L2_MBUS_FMT_YUYV8_1X16)
+ ret = setup_link(isp, isp->viewfinder.subdev, isp->viewfinder.node,
+ MEDIA_LNK_FL_ENABLED);
+ else
+ ret = setup_link(isp, isp->ccdc, isp->preview, MEDIA_LNK_FL_ENABLED);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
+static int omap3_isp_snapshot_setup_pipeline(struct omap3_isp_device *isp,
+ struct v4l2_mbus_framefmt *ofmt,
+ enum v4l2_subdev_format_whence which)
+{
+ int ret;
+
+ /* Setup the links. */
+ if (ofmt->code == V4L2_MBUS_FMT_UYVY8_1X16 ||
+ ofmt->code == V4L2_MBUS_FMT_YUYV8_1X16)
+ ret = setup_link(isp, isp->viewfinder.subdev, isp->viewfinder.node, 0);
+ else
+ ret = setup_link(isp, isp->ccdc, isp->preview, 0);
+ if (ret < 0)
+ return ret;
+
+ ret = setup_link(isp, isp->snapshot.subdev, isp->snapshot.node,
+ MEDIA_LNK_FL_ENABLED);
+ if (ret < 0)
+ return ret;
+
+ /* Configure the formats on the pipeline. */
+ ret = omap3_isp_pipeline_set_format(isp, ofmt, isp->snapshot.scaler, which);
+ if (ret < 0) {
+ printf("error: unable to configure formats on pipeline.\n");
+ return ret;
+ }
+
+ return 0;
+}
+
+int omap3_isp_snapshot_setup(struct omap3_isp_device *isp,
+ struct v4l2_mbus_framefmt *ofmt)
+{
+ struct v4l2_video_buffer buffer;
+ struct v4l2_pix_format format;
+ struct media_entity *entity;
+ unsigned int i;
+ int ret;
+
+ /* Locate the entity at the end of the pipeline. Use the CCDC for raw
+ * capture and the resizer for YUV capture.
+ */
+ switch (ofmt->code) {
+ case V4L2_MBUS_FMT_UYVY8_1X16:
+ case V4L2_MBUS_FMT_YUYV8_1X16:
+ entity = isp->resizer;
+ break;
+ default:
+ entity = isp->ccdc;
+ break;
+ }
+
+ isp->snapshot.scaler = OMAP3_ISP_SCALER_ISP;
+ isp->snapshot.subdev = entity;
+ isp->snapshot.node = entity_output_node(entity);
+ if (isp->snapshot.node == NULL)
+ return -ENOENT;
+
+ /* Try the format. */
+ ret = omap3_isp_snapshot_setup_pipeline(isp, ofmt, V4L2_SUBDEV_FORMAT_TRY);
+ if (ret < 0)
+ return ret;
+
+ isp->snapshot.format = *ofmt;
+
+ ret = omap3_isp_snapshot_restore_pipeline(isp);
+ if (ret < 0)
+ return ret;
+
+ /* Open the V4L2 device. */
+ isp->snapshot.video = v4l2_open(isp->snapshot.node->devname);
+ if (isp->snapshot.video == NULL) {
+ printf("error: unable to open snaphost capture device %s\n",
+ isp->snapshot.node->devname);
+ return -ENODEV;
+ }
+
+ /* Set the capture format on the output video node. */
+ memset(&format, 0, sizeof format);
+ format.pixelformat = mbus_to_pix(ofmt->code);
+ format.width = ofmt->width;
+ format.height = ofmt->height;
+
+ ret = v4l2_set_format(isp->snapshot.video, &format);
+ if (ret < 0)
+ return ret;
+
+ /* Pre-allocate capture buffers. */
+ isp->snapshot.pool = v4l2_buffers_pool_new(2);
+ if (isp->snapshot.pool == NULL) {
+ printf("error: unable to allocate buffers pool for snapshot.\n");
+ return -ENOMEM;
+ }
+
+ ret = v4l2_alloc_buffers(isp->snapshot.video, isp->snapshot.pool,
+ V4L2_MEMORY_MMAP);
+ if (ret < 0) {
+ printf("error: unable to allocate buffers for snapshot.\n");
+ return ret;
+ }
+
+ /* Queue all buffers. */
+ for (i = 0; i < isp->snapshot.video->nbufs; ++i) {
+ buffer.index = i;
+
+ ret = v4l2_queue_buffer(isp->snapshot.video, &buffer);
+ if (ret < 0) {
+ printf("error: unable to queue buffer %u\n", i);
+ return -errno;
+ }
+ }
+
+ return 0;
+}
+
+static void omap3_isp_snapshot_event(void *priv)
+{
+ struct omap3_isp_device *isp = priv;
+ struct v4l2_mbus_framefmt format;
+ struct v4l2_video_buffer buffer;
+ unsigned int i;
+ int ret;
+
+ /* Dequeue a buffer, stop the stream and fire the snapshot event. */
+ ret = v4l2_dequeue_buffer(isp->snapshot.video, &buffer);
+ if (ret < 0) {
+ printf("error: unable to dequeue snapshot buffer.\n");
+ return;
+ }
+
+ isp->ops->unwatch_fd(isp->snapshot.video->fd);
+
+ ret = v4l2_stream_off(isp->snapshot.video);
+ if (ret < 0) {
+ printf("error: streamoff failed for snapshot\n");
+ return;
+ }
+
+ isp->snapshot.running = false;
+
+ isp->ops->snapshot_ready(isp, &buffer);
+
+ /* Resume the viewfinder. */
+ ret = omap3_isp_snapshot_restore_pipeline(isp);
+ if (ret < 0)
+ return;
+
+ format = isp->viewfinder.format;
+ ret = omap3_isp_viewfinder_setup_pipeline(isp, &format);
+ if (ret < 0)
+ return;
+
+ ret = omap3_isp_viewfinder_start(isp);
+ if (ret < 0) {
+ printf("error: unable to resume viewfinder.\n");
+ return;
+ }
+
+ /* Queue all buffers for the next snapshot. */
+ for (i = 0; i < isp->snapshot.video->nbufs; ++i) {
+ buffer.index = i;
+
+ ret = v4l2_queue_buffer(isp->snapshot.video, &buffer);
+ if (ret < 0) {
+ printf("error: unable to queue buffer %u\n", i);
+ return;
+ }
+ }
+}
+
+int omap3_isp_snapshot_capture(struct omap3_isp_device *isp)
+{
+ struct v4l2_mbus_framefmt format;
+ int ret;
+
+ /* Suspend the viewfinder. */
+ ret = omap3_isp_viewfinder_stop(isp);
+ if (ret < 0) {
+ printf("error: unable to suspend viewfinder.\n");
+ return ret;
+ }
+
+ /* Configure the pipeline. */
+ format = isp->snapshot.format;
+ ret = omap3_isp_snapshot_setup_pipeline(isp, &format, V4L2_SUBDEV_FORMAT_ACTIVE);
+ if (ret < 0) {
+ printf("error: unable to setup snapshot pipeline.\n");
+ return ret;
+ }
+
+ if (isp->ops->prepare_streamon)
+ isp->ops->prepare_streamon(isp);
+
+ /* Watch the snapshot file descriptor. */
+ isp->ops->watch_fd(isp->snapshot.video->fd, OMAP3_ISP_EVENT_READ,
+ omap3_isp_snapshot_event, isp);
+
+ ret = v4l2_stream_on(isp->snapshot.video);
+ if (ret < 0) {
+ printf("error: streamon failed for snapshot\n");
+ return ret;
+ }
+
+ isp->snapshot.running = true;
+ return 0;
+}
+
+int omap3_isp_snapshot_put_buffer(struct omap3_isp_device *isp __attribute__((__unused__)),
+ struct v4l2_video_buffer *buffer __attribute__((__unused__)))
+{
+ /* No-op, the stream is already stopped so we don't need to requeue the
+ * buffer.
+ */
+ return 0;
+}
diff --git a/isp/omap3isp.h b/isp/omap3isp.h
new file mode 100644
index 0000000..6427efc
--- /dev/null
+++ b/isp/omap3isp.h
@@ -0,0 +1,80 @@
+/*
+ * OMAP3 ISP library - OMAP3 ISP
+ *
+ * Copyright (C) 2010-2011 Ideas on board SPRL
+ *
+ * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __OMAP3ISP_H
+#define __OMAP3ISP_H
+
+#include <linux/v4l2-mediabus.h>
+#include <sys/select.h>
+#include <stdbool.h>
+
+#include "media.h"
+#include "v4l2.h"
+
+struct omap3_isp_device;
+
+enum omap3_isp_scaler {
+ OMAP3_ISP_SCALER_ISP = 0,
+ OMAP3_ISP_SCALER_SENSOR = 1,
+};
+
+enum omap3_isp_event_type {
+ OMAP3_ISP_EVENT_READ = 1,
+ OMAP3_ISP_EVENT_WRITE = 2,
+};
+
+struct omap3_isp_operations {
+ void (*prepare_streamon)(struct omap3_isp_device *isp);
+ void (*viewfinder_ready)(struct omap3_isp_device *isp,
+ struct v4l2_video_buffer *buffer);
+ void (*snapshot_ready)(struct omap3_isp_device *isp,
+ struct v4l2_video_buffer *buffer);
+ void (*watch_fd)(int fd, enum omap3_isp_event_type type,
+ void(*callback)(void *priv), void *priv);
+ void (*unwatch_fd)(int fd);
+};
+
+struct omap3_isp_device *omap3_isp_open(const char *devname,
+ const struct omap3_isp_operations *ops);
+void omap3_isp_close(struct omap3_isp_device *isp);
+
+int omap3_isp_viewfinder_setup(struct omap3_isp_device *isp,
+ struct v4l2_mbus_framefmt *ofmt);
+int omap3_isp_viewfinder_set_pool(struct omap3_isp_device *isp,
+ struct v4l2_buffers_pool *pool);
+int omap3_isp_viewfinder_set_scaler(struct omap3_isp_device *isp,
+ enum omap3_isp_scaler scaler);
+int omap3_isp_viewfinder_start(struct omap3_isp_device *isp);
+int omap3_isp_viewfinder_stop(struct omap3_isp_device *isp);
+int omap3_isp_viewfinder_put_buffer(struct omap3_isp_device *isp,
+ struct v4l2_video_buffer *buffer);
+
+int omap3_isp_snapshot_setup(struct omap3_isp_device *isp,
+ struct v4l2_mbus_framefmt *ofmt);
+int omap3_isp_snapshot_capture(struct omap3_isp_device *isp);
+int omap3_isp_snapshot_put_buffer(struct omap3_isp_device *isp,
+ struct v4l2_video_buffer *buffer);
+
+int omap3_isp_preview_set_contrast(struct omap3_isp_device *isp, unsigned int value);
+int omap3_isp_preview_set_saturation(struct omap3_isp_device *isp, float value);
+
+#endif
diff --git a/isp/subdev.c b/isp/subdev.c
new file mode 100644
index 0000000..b4894a2
--- /dev/null
+++ b/isp/subdev.c
@@ -0,0 +1,287 @@
+/*
+ * OMAP3 ISP library - V4L2 sub-devices
+ *
+ * Copyright (C) 2010-2011 Ideas on board SPRL
+ *
+ * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <linux/v4l2-subdev.h>
+
+#include "media.h"
+#include "subdev.h"
+#include "tools.h"
+
+static struct {
+ const char *name;
+ enum v4l2_mbus_pixelcode code;
+} mbus_formats[] = {
+ { "YUYV", V4L2_MBUS_FMT_YUYV8_1X16 },
+ { "UYVY", V4L2_MBUS_FMT_UYVY8_1X16 },
+ { "SGRBG10", V4L2_MBUS_FMT_SGRBG10_1X10 },
+ { "SGRBG10_DPCM8", V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8 },
+};
+
+static const char *pixelcode_to_string(enum v4l2_mbus_pixelcode code)
+{
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(mbus_formats); ++i) {
+ if (mbus_formats[i].code == code)
+ return mbus_formats[i].name;
+ }
+
+ return "unknown";
+}
+
+int v4l2_subdev_open(struct media_entity *entity)
+{
+ if (entity->fd != -1)
+ return 0;
+
+ entity->fd = open(entity->devname, O_RDWR);
+ if (entity->fd == -1) {
+ printf("%s: Failed to open subdev device node %s\n", __func__,
+ entity->devname);
+ return -errno;
+ }
+
+ return 0;
+}
+
+void v4l2_subdev_close(struct media_entity *entity)
+{
+ close(entity->fd);
+}
+
+int v4l2_subdev_get_format(struct media_entity *entity,
+ struct v4l2_mbus_framefmt *format, unsigned int pad,
+ enum v4l2_subdev_format_whence which)
+{
+ struct v4l2_subdev_format fmt;
+ int ret;
+
+ ret = v4l2_subdev_open(entity);
+ if (ret < 0)
+ return ret;
+
+ memset(&fmt, 0, sizeof(fmt));
+ fmt.pad = pad;
+ fmt.which = which;
+
+ ret = ioctl(entity->fd, VIDIOC_SUBDEV_G_FMT, &fmt);
+ if (ret < 0)
+ return -errno;
+
+ *format = fmt.format;
+ return 0;
+}
+
+int v4l2_subdev_set_format(struct media_entity *entity,
+ struct v4l2_mbus_framefmt *format, unsigned int pad,
+ enum v4l2_subdev_format_whence which)
+{
+ struct v4l2_subdev_format fmt;
+ int ret;
+
+ ret = v4l2_subdev_open(entity);
+ if (ret < 0)
+ return ret;
+
+ memset(&fmt, 0, sizeof(fmt));
+ fmt.pad = pad;
+ fmt.which = which;
+ fmt.format = *format;
+
+ ret = ioctl(entity->fd, VIDIOC_SUBDEV_S_FMT, &fmt);
+ if (ret < 0)
+ return -errno;
+
+ *format = fmt.format;
+ return 0;
+}
+
+int v4l2_subdev_get_crop(struct media_entity *entity, struct v4l2_rect *rect,
+ unsigned int pad, enum v4l2_subdev_format_whence which)
+{
+ struct v4l2_subdev_crop crop;
+ int ret;
+
+ ret = v4l2_subdev_open(entity);
+ if (ret < 0)
+ return ret;
+
+ memset(&crop, 0, sizeof(crop));
+ crop.pad = pad;
+ crop.which = which;
+
+ ret = ioctl(entity->fd, VIDIOC_SUBDEV_G_CROP, &crop);
+ if (ret < 0)
+ return -errno;
+
+ *rect = crop.rect;
+ return 0;
+}
+
+int v4l2_subdev_set_crop(struct media_entity *entity, struct v4l2_rect *rect,
+ unsigned int pad, enum v4l2_subdev_format_whence which)
+{
+ struct v4l2_subdev_crop crop;
+ int ret;
+
+ ret = v4l2_subdev_open(entity);
+ if (ret < 0)
+ return ret;
+
+ memset(&crop, 0, sizeof(crop));
+ crop.pad = pad;
+ crop.which = which;
+ crop.rect = *rect;
+
+ ret = ioctl(entity->fd, VIDIOC_SUBDEV_S_CROP, &crop);
+ if (ret < 0)
+ return -errno;
+
+ *rect = crop.rect;
+ return 0;
+}
+
+int v4l2_subdev_set_frame_interval(struct media_entity *entity,
+ struct v4l2_fract *interval)
+{
+ struct v4l2_subdev_frame_interval ival;
+ int ret;
+
+ ret = v4l2_subdev_open(entity);
+ if (ret < 0)
+ return ret;
+
+ memset(&ival, 0, sizeof(ival));
+ ival.interval = *interval;
+
+ ret = ioctl(entity->fd, VIDIOC_SUBDEV_S_FRAME_INTERVAL, &ival);
+ if (ret < 0)
+ return -errno;
+
+ *interval = ival.interval;
+ return 0;
+}
+
+/* -----------------------------------------------------------------------------
+ * Controls
+ */
+
+int v4l2_subdev_get_control(struct media_entity *entity, unsigned int id,
+ int32_t *value)
+{
+ struct v4l2_control ctrl;
+ int ret;
+
+ ret = v4l2_subdev_open(entity);
+ if (ret < 0)
+ return ret;
+
+ ctrl.id = id;
+
+ ret = ioctl(entity->fd, VIDIOC_G_CTRL, &ctrl);
+ if (ret < 0) {
+ printf("unable to get control: %s (%d).\n",
+ strerror(errno), errno);
+ return -errno;
+ }
+
+ *value = ctrl.value;
+ return 0;
+}
+
+int v4l2_subdev_set_control(struct media_entity *entity, unsigned int id,
+ int32_t *value)
+{
+ struct v4l2_control ctrl;
+ int ret;
+
+ ret = v4l2_subdev_open(entity);
+ if (ret < 0)
+ return ret;
+
+ ctrl.id = id;
+ ctrl.value = *value;
+
+ ret = ioctl(entity->fd, VIDIOC_S_CTRL, &ctrl);
+ if (ret < 0) {
+ printf("unable to set control: %s (%d).\n",
+ strerror(errno), errno);
+ return -errno;
+ }
+
+ *value = ctrl.value;
+ return 0;
+}
+
+int v4l2_subdev_get_controls(struct media_entity *entity, unsigned int count,
+ struct v4l2_ext_control *ctrls)
+{
+ struct v4l2_ext_controls controls;
+ int ret;
+
+ ret = v4l2_subdev_open(entity);
+ if (ret < 0)
+ return ret;
+
+ memset(&controls, 0, sizeof controls);
+ controls.count = count;
+ controls.controls = ctrls;
+
+ ret = ioctl(entity->fd, VIDIOC_G_EXT_CTRLS, &controls);
+ if (ret < 0)
+ printf("unable to get multiple controls: %s (%d).\n",
+ strerror(errno), errno);
+
+ return ret;
+}
+
+int v4l2_subdev_set_controls(struct media_entity *entity, unsigned int count,
+ struct v4l2_ext_control *ctrls)
+{
+ struct v4l2_ext_controls controls;
+ int ret;
+
+ ret = v4l2_subdev_open(entity);
+ if (ret < 0)
+ return ret;
+
+ memset(&controls, 0, sizeof controls);
+ controls.count = count;
+ controls.controls = ctrls;
+
+ ret = ioctl(entity->fd, VIDIOC_S_EXT_CTRLS, &controls);
+ if (ret < 0)
+ printf("unable to set multiple controls: %s (%d).\n",
+ strerror(errno), errno);
+
+ return ret;
+}
diff --git a/isp/subdev.h b/isp/subdev.h
new file mode 100644
index 0000000..5bbbe84
--- /dev/null
+++ b/isp/subdev.h
@@ -0,0 +1,201 @@
+/*
+ * OMAP3 ISP library - V4L2 sub-devices
+ *
+ * Copyright (C) 2010-2011 Ideas on board SPRL
+ *
+ * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __SUBDEV_H__
+#define __SUBDEV_H__
+
+#include <linux/v4l2-subdev.h>
+
+struct media_entity;
+
+/*
+ * v4l2_subdev_open - Open a sub-device
+ * @entity: Sub-device media entity
+ *
+ * Open the V4L2 subdev device node associated with @entity. The file descriptor
+ * is stored in the media_entity structure.
+ *
+ * Return 0 on success, or a negative error code on failure.
+ */
+int v4l2_subdev_open(struct media_entity *entity);
+
+/*
+ * v4l2_subdev_close - Close a sub-device
+ * @entity: Sub-device media entity
+ *
+ * Close the V4L2 subdev device node associated with the @entity and opened by
+ * a previous call to v4l2_subdev_open() (either explicit or implicit).
+ */
+void v4l2_subdev_close(struct media_entity *entity);
+
+/*
+ * v4l2_subdev_get_format - Retrieve the format on a pad
+ * @entity: Subdev-device media entity
+ * @format: Format to be filled
+ * @pad: Pad number
+ * @which: Identifier of the format to get
+ *
+ * Retrieve the current format on the @entity @pad and store it in the @format
+ * structure.
+ *
+ * @which is set to V4L2_SUBDEV_FORMAT_TRY to retrieve the try format stored in
+ * the file handle, of V4L2_SUBDEV_FORMAT_ACTIVE to retrieve the current active
+ * format.
+ *
+ * Return 0 on success, or a negative error code on failure.
+ */
+int v4l2_subdev_get_format(struct media_entity *entity,
+ struct v4l2_mbus_framefmt *format, unsigned int pad,
+ enum v4l2_subdev_format_whence which);
+
+/*
+ * v4l2_subdev_set_format - Set the format on a pad
+ * @entity: Subdev-device media entity
+ * @format: Format
+ * @pad: Pad number
+ * @which: Identifier of the format to set
+ *
+ * Set the format on the @entity @pad to @format. The driver is allowed to
+ * modify the requested format, in which case @format is updated with the
+ * modifications.
+ *
+ * @which is set to V4L2_SUBDEV_FORMAT_TRY to set the try format stored in the
+ * file handle, of V4L2_SUBDEV_FORMAT_ACTIVE to configure the device with an
+ * active format.
+ *
+ * Return 0 on success, or a negative error code on failure.
+ */
+int v4l2_subdev_set_format(struct media_entity *entity,
+ struct v4l2_mbus_framefmt *format, unsigned int pad,
+ enum v4l2_subdev_format_whence which);
+
+/*
+ * v4l2_subdev_get_crop - Retrieve the crop rectangle on a pad
+ * @entity: Subdev-device media entity
+ * @rect: Crop rectangle to be filled
+ * @pad: Pad number
+ * @which: Identifier of the format to get
+ *
+ * Retrieve the current crop rectangleon the @entity @pad and store it in the
+ * @rect structure.
+ *
+ * @which is set to V4L2_SUBDEV_FORMAT_TRY to retrieve the try crop rectangle
+ * stored in the file handle, of V4L2_SUBDEV_FORMAT_ACTIVE to retrieve the
+ * current active crop rectangle.
+ *
+ * Return 0 on success, or a negative error code on failure.
+ */
+int v4l2_subdev_get_crop(struct media_entity *entity, struct v4l2_rect *rect,
+ unsigned int pad, enum v4l2_subdev_format_whence which);
+
+/*
+ * v4l2_subdev_set_crop - Set the crop rectangle on a pad
+ * @entity: Subdev-device media entity
+ * @crop: Crop rectangle
+ * @pad: Pad number
+ * @which: Identifier of the format to set
+ *
+ * Set the crop rectangle on the @entity @pad to @rect. The driver is allowed to
+ * modify the requested rectangle, in which case @rect is updated with the
+ * modifications.
+ *
+ * @which is set to V4L2_SUBDEV_FORMAT_TRY to set the try crop rectangle stored
+ * in the file handle, of V4L2_SUBDEV_FORMAT_ACTIVE to configure the device with
+ * an active crop rectangle.
+ *
+ * Return 0 on success, or a negative error code on failure.
+ */
+int v4l2_subdev_set_crop(struct media_entity *entity, struct v4l2_rect *rect,
+ unsigned int pad, enum v4l2_subdev_format_whence which);
+
+/*
+ * v4l2_subdev_set_frame_interval - Set the frame interval on a sub-device
+ * @entity: Subdev-device media entity
+ * @interval: Frame interval
+ *
+ * Set the frame interval on subdev @entity to @interval. The driver is allowed
+ * to modify the requested frame interval, in which case @interval is updated
+ * with the modifications.
+ *
+ * Frame interval setting is usually supported only on devices at the beginning
+ * of video pipelines, such as sensors.
+ *
+ * Return 0 on success, or a negative error code on failure.
+ */
+int v4l2_subdev_set_frame_interval(struct media_entity *entity,
+ struct v4l2_fract *interval);
+
+/*
+ * v4l2_subdev_get_control - Read the value of a control
+ * @entity: Subdev-device media entity
+ * @id: Control ID
+ * @value: Control value to be filled
+ *
+ * Retrieve the current value of control @id and store it in @value.
+ *
+ * Return 0 on success or a negative error code on failure.
+ */
+int v4l2_subdev_get_control(struct media_entity *entity, unsigned int id,
+ int32_t *value);
+
+/*
+ * v4l2_subdev_set_control - Write the value of a control
+ * @entity: Subdev-device media entity
+ * @id: Control ID
+ * @value: Control value
+ *
+ * Set control @id to @value. The device is allowed to modify the requested
+ * value, in which case @value is updated to the modified value.
+ *
+ * Return 0 on success or a negative error code on failure.
+ */
+int v4l2_subdev_set_control(struct media_entity *entity, unsigned int id,
+ int32_t *value);
+
+/*
+ * v4l2_subdev_get_controls - Read the value of multiple controls
+ * @entity: Subdev-device media entity
+ * @count: Number of controls
+ * @ctrls: Controls to be read
+ *
+ * Retrieve the current value of controls identified by @ctrls.
+ *
+ * Return 0 on success or a negative error code on failure.
+ */
+int v4l2_subdev_get_controls(struct media_entity *entity, unsigned int count,
+ struct v4l2_ext_control *ctrls);
+
+/*
+ * v4l2_subdev_set_controls - Write the value of multiple controls
+ * @entity: Subdev-device media entity
+ * @count: Number of controls
+ * @ctrls: Controls to be written
+ *
+ * Set controls identified by @ctrls. The device is allowed to modify the
+ * requested values, in which case @ctrls is updated to the modified value.
+ *
+ * Return 0 on success or a negative error code on failure.
+ */
+int v4l2_subdev_set_controls(struct media_entity *entity, unsigned int count,
+ struct v4l2_ext_control *ctrls);
+
+#endif
diff --git a/isp/tools.h b/isp/tools.h
new file mode 100644
index 0000000..b60cc2e
--- /dev/null
+++ b/isp/tools.h
@@ -0,0 +1,34 @@
+/*
+ * OMAP3 ISP library - Tools
+ *
+ * Copyright (C) 2010-2011 Ideas on board SPRL
+ *
+ * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __TOOLS_H__
+#define __TOOLS_H__
+
+#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
+
+#define min(a, b) ((a) < (b) ? (a) : (b))
+#define max(a, b) ((a) > (b) ? (a) : (b))
+
+#define container_of(ptr, type, member) \
+ (type *)((char *)(ptr) - offsetof(type, member))
+
+#endif /* __TOOLS_H__ */
diff --git a/isp/v4l2-pool.c b/isp/v4l2-pool.c
new file mode 100644
index 0000000..b0bf3b5
--- /dev/null
+++ b/isp/v4l2-pool.c
@@ -0,0 +1,80 @@
+/*
+ * OMAP3 ISP library - V4L2 buffers pool
+ *
+ * Copyright (C) 2010-2011 Ideas on board SPRL
+ *
+ * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "v4l2-pool.h"
+
+struct v4l2_buffers_pool *v4l2_buffers_pool_new(unsigned int nbufs)
+{
+ struct v4l2_video_buffer *buffers;
+ struct v4l2_buffers_pool *pool;
+
+ pool = malloc(sizeof *pool);
+ if (pool == NULL)
+ return NULL;
+
+ buffers = malloc(sizeof *buffers * nbufs);
+ if (buffers == NULL) {
+ free(pool);
+ return NULL;
+ }
+
+ memset(buffers, 0, sizeof *buffers * nbufs);
+
+ pool->nbufs = nbufs;
+ pool->buffers = buffers;
+
+ return pool;
+}
+
+void v4l2_buffers_pool_delete(struct v4l2_buffers_pool *pool)
+{
+ unsigned int i;
+
+ for (i = 0; i < pool->nbufs; ++i) {
+ if (pool->buffers[i].allocated)
+ free(pool->buffers[i].mem);
+ }
+
+ free(pool->buffers);
+ free(pool);
+}
+
+int v4l2_buffers_pool_alloc(struct v4l2_buffers_pool *pool, size_t size,
+ size_t align)
+{
+ unsigned int i;
+ int ret;
+
+ for (i = 0; i < pool->nbufs; ++i) {
+ ret = posix_memalign(&pool->buffers[i].mem, align, size);
+ if (ret != 0)
+ return -ret;
+
+ pool->buffers[i].size = size;
+ pool->buffers[i].allocated = true;
+ }
+
+ return 0;
+}
diff --git a/isp/v4l2-pool.h b/isp/v4l2-pool.h
new file mode 100644
index 0000000..32f3b3b
--- /dev/null
+++ b/isp/v4l2-pool.h
@@ -0,0 +1,87 @@
+/*
+ * OMAP3 ISP library - V4L2 buffers pool
+ *
+ * Copyright (C) 2010-2011 Ideas on board SPRL
+ *
+ * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#ifndef __V4L2_POOL_H
+#define __V4L2_POOL_H
+
+#include <linux/videodev2.h>
+#include <stdbool.h>
+
+/*
+ * struct v4l2_video_buffer - Video buffer information
+ * @index: Zero-based buffer index, limited to the number of buffers minus one
+ * @size: Size of the video memory, in bytes
+ * @bytesused: Number of bytes used by video data, smaller or equal to @size
+ * @timestamp: Time stamp at which the buffer has been captured
+ * @error: True if an error occured while capturing video data for the buffer
+ * @allocated: True if memory for the buffer has been allocated by the pool
+ * @mem: Video data memory
+ */
+struct v4l2_video_buffer
+{
+ unsigned int index;
+ unsigned int size;
+ unsigned int bytesused;
+ struct timeval timestamp;
+ bool error;
+ bool allocated;
+ void *mem;
+};
+
+struct v4l2_buffers_pool
+{
+ unsigned int nbufs;
+ struct v4l2_video_buffer *buffers;
+};
+
+/*
+ * v4l2_buffers_pool_new - Create a new buffers pool
+ * @nbufs: Number of buffers in the pool
+ *
+ * Allocate a new buffers pool with space for @nbufs buffers. Memory for the
+ * buffers is not allocated.
+ */
+struct v4l2_buffers_pool *v4l2_buffers_pool_new(unsigned int nbufs);
+
+/*
+ * v4l2_buffers_pool_delete - Delete a buffers pool
+ * @pool: Buffers pool
+ *
+ * Delete a buffers pool and free buffers memory if it has been allocated by
+ * the pool.
+ */
+void v4l2_buffers_pool_delete(struct v4l2_buffers_pool *pool);
+
+/*
+ * v4l2_buffers_pool_alloc - Allocate memory for buffers in a pool
+ * @pool: Buffers pool
+ * @size: Buffer size
+ * @align: Buffer memory alignment in bytes
+ *
+ * Allocate @size bytes of memory for each buffer aligned to a multiple of
+ * @align bytes. The alignment must be a power of 2.
+ *
+ * Return 0 on success or a negative error code on failure.
+ */
+int v4l2_buffers_pool_alloc(struct v4l2_buffers_pool *pool, size_t size,
+ size_t align);
+
+#endif
diff --git a/isp/v4l2.c b/isp/v4l2.c
new file mode 100644
index 0000000..75e90b1
--- /dev/null
+++ b/isp/v4l2.c
@@ -0,0 +1,717 @@
+/*
+ * OMAP3 ISP library - V4L2 devices
+ *
+ * Copyright (C) 2010-2011 Ideas on board SPRL
+ *
+ * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <getopt.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/select.h>
+#include <sys/time.h>
+
+#include <linux/videodev2.h>
+
+#include "list.h"
+#include "tools.h"
+#include "v4l2.h"
+
+#ifndef V4L2_BUF_FLAG_ERROR
+#define V4L2_BUF_FLAG_ERROR 0x0040
+#endif
+
+struct v4l2_ival_desc {
+ struct v4l2_fract min;
+ struct v4l2_fract max;
+ struct v4l2_fract step;
+
+ struct list_entry list;
+};
+
+struct v4l2_frame_desc {
+ unsigned int min_width;
+ unsigned int min_height;
+ unsigned int max_width;
+ unsigned int max_height;
+ unsigned int step_width;
+ unsigned int step_height;
+
+ struct list_entry list;
+ struct list_entry ivals;
+};
+
+struct v4l2_format_desc {
+ unsigned int pixelformat;
+
+ struct list_entry list;
+ struct list_entry frames;
+};
+
+/* -----------------------------------------------------------------------------
+ * Formats enumeration
+ */
+
+static int
+v4l2_enum_frame_intervals(struct v4l2_device *dev, struct v4l2_format_desc *format,
+ struct v4l2_frame_desc *frame)
+{
+ struct v4l2_ival_desc *ival;
+ unsigned int i;
+ int ret;
+
+ for (i = 0; ; ++i) {
+ struct v4l2_frmivalenum ivalenum;
+
+ memset(&ivalenum, 0, sizeof ivalenum);
+ ivalenum.index = i;
+ ivalenum.pixel_format = format->pixelformat;
+ ivalenum.width = frame->min_width;
+ ivalenum.height = frame->min_height;
+ ret = ioctl(dev->fd, VIDIOC_ENUM_FRAMEINTERVALS, &ivalenum);
+ if (ret < 0)
+ break;
+
+ if (i != ivalenum.index)
+ printf("Warning: driver returned wrong ival index "
+ "%u.\n", ivalenum.index);
+ if (format->pixelformat != ivalenum.pixel_format)
+ printf("Warning: driver returned wrong ival pixel "
+ "format %08x.\n", ivalenum.pixel_format);
+ if (frame->min_width != ivalenum.width)
+ printf("Warning: driver returned wrong ival width "
+ "%u.\n", ivalenum.width);
+ if (frame->min_height != ivalenum.height)
+ printf("Warning: driver returned wrong ival height "
+ "%u.\n", ivalenum.height);
+
+ ival = malloc(sizeof *ival);
+ if (ival == NULL)
+ return -ENOMEM;
+
+ memset(ival, 0, sizeof *ival);
+
+ switch (ivalenum.type) {
+ case V4L2_FRMIVAL_TYPE_DISCRETE:
+ ival->min = ivalenum.discrete;
+ ival->max = ivalenum.discrete;
+ ival->step.numerator = 1;
+ ival->step.denominator = 1;
+ break;
+
+ case V4L2_FRMIVAL_TYPE_STEPWISE:
+ ival->min = ivalenum.stepwise.min;
+ ival->max = ivalenum.stepwise.max;
+ ival->step = ivalenum.stepwise.step;
+ break;
+
+ default:
+ printf("Error: driver returned invalid frame ival "
+ "type %u\n", ivalenum.type);
+ return -EINVAL;
+ }
+
+ list_append(&ival->list, &frame->ivals);
+ }
+
+ return 0;
+}
+
+static int
+v4l2_enum_frame_sizes(struct v4l2_device *dev, struct v4l2_format_desc *format)
+{
+ struct v4l2_frame_desc *frame;
+ unsigned int i;
+ int ret;
+
+ for (i = 0; ; ++i) {
+ struct v4l2_frmsizeenum frmenum;
+
+ memset(&frmenum, 0, sizeof frmenum);
+ frmenum.index = i;
+ frmenum.pixel_format = format->pixelformat;
+
+ ret = ioctl(dev->fd, VIDIOC_ENUM_FRAMESIZES, &frmenum);
+ if (ret < 0)
+ break;
+
+ if (i != frmenum.index)
+ printf("Warning: driver returned wrong frame index "
+ "%u.\n", frmenum.index);
+ if (format->pixelformat != frmenum.pixel_format)
+ printf("Warning: driver returned wrong frame pixel "
+ "format %08x.\n", frmenum.pixel_format);
+
+ frame = malloc(sizeof *frame);
+ if (frame == NULL)
+ return -ENOMEM;
+
+ memset(frame, 0, sizeof *frame);
+
+ list_init(&frame->ivals);
+ frame->step_width = 1;
+ frame->step_height = 1;
+
+ switch (frmenum.type) {
+ case V4L2_FRMSIZE_TYPE_DISCRETE:
+ frame->min_width = frmenum.discrete.width;
+ frame->min_height = frmenum.discrete.height;
+ frame->max_width = frmenum.discrete.width;
+ frame->max_height = frmenum.discrete.height;
+ break;
+
+ case V4L2_FRMSIZE_TYPE_STEPWISE:
+ frame->step_width = frmenum.stepwise.step_width;
+ frame->step_height = frmenum.stepwise.step_height;
+ case V4L2_FRMSIZE_TYPE_CONTINUOUS:
+ frame->min_width = frmenum.stepwise.min_width;
+ frame->min_height = frmenum.stepwise.min_height;
+ frame->max_width = frmenum.stepwise.max_width;
+ frame->max_height = frmenum.stepwise.max_height;
+ break;
+
+ default:
+ printf("Error: driver returned invalid frame size "
+ "type %u\n", frmenum.type);
+ return -EINVAL;
+ }
+
+ list_append(&frame->list, &format->frames);
+
+ ret = v4l2_enum_frame_intervals(dev, format, frame);
+ if (ret < 0)
+ return ret;
+ }
+
+ return 0;
+}
+static int v4l2_enum_formats(struct v4l2_device *dev)
+{
+ struct v4l2_format_desc *format;
+ unsigned int i;
+ int ret;
+
+ for (i = 0; ; ++i) {
+ struct v4l2_fmtdesc fmtenum;
+
+ memset(&fmtenum, 0, sizeof fmtenum);
+ fmtenum.index = i;
+ fmtenum.type = dev->type;
+
+ ret = ioctl(dev->fd, VIDIOC_ENUM_FMT, &fmtenum);
+ if (ret < 0)
+ break;
+
+ if (i != fmtenum.index)
+ printf("Warning: driver returned wrong format index "
+ "%u.\n", fmtenum.index);
+ if (dev->type != fmtenum.type)
+ printf("Warning: driver returned wrong format type "
+ "%u.\n", fmtenum.type);
+
+ format = malloc(sizeof *format);
+ if (format == NULL)
+ return -ENOMEM;
+
+ memset(format, 0, sizeof *format);
+
+ list_init(&format->frames);
+ format->pixelformat = fmtenum.pixelformat;
+
+ list_append(&format->list, &dev->formats);
+
+ ret = v4l2_enum_frame_sizes(dev, format);
+ if (ret < 0)
+ return ret;
+ }
+
+ return 0;
+}
+
+/* -----------------------------------------------------------------------------
+ * Open/close
+ */
+
+struct v4l2_device *v4l2_open(const char *devname)
+{
+ struct v4l2_device *dev;
+ struct v4l2_capability cap;
+ int ret;
+
+ dev = malloc(sizeof *dev);
+ if (dev == NULL)
+ return NULL;
+
+ memset(dev, 0, sizeof *dev);
+ dev->fd = -1;
+ list_init(&dev->formats);
+
+ dev->fd = open(devname, O_RDWR | O_NONBLOCK);
+ if (dev->fd < 0) {
+ printf("Error opening device %s: %d.\n", devname, errno);
+ v4l2_close(dev);
+ return NULL;
+ }
+
+ memset(&cap, 0, sizeof cap);
+ ret = ioctl(dev->fd, VIDIOC_QUERYCAP, &cap);
+ if (ret < 0) {
+ printf("Error opening device %s: unable to query "
+ "device.\n", devname);
+ v4l2_close(dev);
+ return NULL;
+ }
+
+ if (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)
+ dev->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ else if (cap.capabilities & V4L2_CAP_VIDEO_OUTPUT)
+ dev->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
+ else {
+ printf("Error opening device %s: neither video capture "
+ "nor video output supported.\n", devname);
+ v4l2_close(dev);
+ return NULL;
+ }
+
+ ret = v4l2_enum_formats(dev);
+ if (ret < 0) {
+ printf("Error opening device %s: unable to enumerate "
+ "formats.\n", devname);
+ v4l2_close(dev);
+ return NULL;
+ }
+
+ printf("Device %s opened: %s (%s).\n", devname, cap.card, cap.bus_info);
+
+ return dev;
+}
+
+void v4l2_close(struct v4l2_device *dev)
+{
+ struct v4l2_format_desc *format, *next_fmt;
+ struct v4l2_frame_desc *frame, *next_frm;
+ struct v4l2_ival_desc *ival, *next_ival;
+
+ if (dev == NULL)
+ return;
+
+ list_for_each_entry_safe(format, next_fmt, &dev->formats, list) {
+ list_for_each_entry_safe(frame, next_frm, &format->frames, list) {
+ list_for_each_entry_safe(ival, next_ival, &frame->ivals, list) {
+ free(ival);
+ }
+ free(frame);
+ }
+ free(format);
+ }
+
+ close(dev->fd);
+}
+
+/* -----------------------------------------------------------------------------
+ * Controls
+ */
+
+int v4l2_get_control(struct v4l2_device *dev, unsigned int id, int32_t *value)
+{
+ struct v4l2_control ctrl;
+ int ret;
+
+ ctrl.id = id;
+
+ ret = ioctl(dev->fd, VIDIOC_G_CTRL, &ctrl);
+ if (ret < 0) {
+ printf("unable to get control: %s (%d).\n",
+ strerror(errno), errno);
+ return -errno;
+ }
+
+ *value = ctrl.value;
+ return 0;
+}
+
+int v4l2_set_control(struct v4l2_device *dev, unsigned int id, int32_t *value)
+{
+ struct v4l2_control ctrl;
+ int ret;
+
+ ctrl.id = id;
+ ctrl.value = *value;
+
+ ret = ioctl(dev->fd, VIDIOC_S_CTRL, &ctrl);
+ if (ret < 0) {
+ printf("unable to set control: %s (%d).\n",
+ strerror(errno), errno);
+ return -errno;
+ }
+
+ *value = ctrl.value;
+ return 0;
+}
+
+int v4l2_get_controls(struct v4l2_device *dev, unsigned int count,
+ struct v4l2_ext_control *ctrls)
+{
+ struct v4l2_ext_controls controls;
+ int ret;
+
+ memset(&controls, 0, sizeof controls);
+ controls.count = count;
+ controls.controls = ctrls;
+
+ ret = ioctl(dev->fd, VIDIOC_G_EXT_CTRLS, &controls);
+ if (ret < 0)
+ printf("unable to get multiple controls: %s (%d).\n",
+ strerror(errno), errno);
+
+ return ret;
+}
+
+int v4l2_set_controls(struct v4l2_device *dev, unsigned int count,
+ struct v4l2_ext_control *ctrls)
+{
+ struct v4l2_ext_controls controls;
+ int ret;
+
+ memset(&controls, 0, sizeof controls);
+ controls.count = count;
+ controls.controls = ctrls;
+
+ ret = ioctl(dev->fd, VIDIOC_S_EXT_CTRLS, &controls);
+ if (ret < 0)
+ printf("unable to set multiple controls: %s (%d).\n",
+ strerror(errno), errno);
+
+ return ret;
+}
+
+/* -----------------------------------------------------------------------------
+ * Formats and frame rates
+ */
+
+int v4l2_get_crop(struct v4l2_device *dev, struct v4l2_rect *rect)
+{
+ struct v4l2_crop crop;
+ int ret;
+
+ memset(&crop, 0, sizeof crop);
+ crop.type = dev->type;
+
+ ret = ioctl(dev->fd, VIDIOC_G_CROP, &crop);
+ if (ret < 0) {
+ printf("Unable to get crop rectangle: %s (%d).\n",
+ strerror(errno), errno);
+ return -errno;
+ }
+
+ dev->crop = crop.c;
+ *rect = crop.c;
+
+ return 0;
+}
+
+int v4l2_set_crop(struct v4l2_device *dev, struct v4l2_rect *rect)
+{
+ struct v4l2_crop crop;
+ int ret;
+
+ memset(&crop, 0, sizeof crop);
+ crop.type = dev->type;
+ crop.c = *rect;
+
+ ret = ioctl(dev->fd, VIDIOC_S_CROP, &crop);
+ if (ret < 0) {
+ printf("Unable to set crop rectangle: %s (%d).\n",
+ strerror(errno), errno);
+ return -errno;
+ }
+
+ dev->crop = crop.c;
+ *rect = crop.c;
+
+ return 0;
+}
+
+int v4l2_get_format(struct v4l2_device *dev, struct v4l2_pix_format *format)
+{
+ struct v4l2_format fmt;
+ int ret;
+
+ memset(&fmt, 0, sizeof fmt);
+ fmt.type = dev->type;
+
+ ret = ioctl(dev->fd, VIDIOC_G_FMT, &fmt);
+ if (ret < 0) {
+ printf("Unable to get format: %s (%d).\n", strerror(errno),
+ errno);
+ return -errno;
+ }
+
+ dev->format = fmt.fmt.pix;
+ *format = fmt.fmt.pix;
+
+ return 0;
+}
+
+int v4l2_set_format(struct v4l2_device *dev, struct v4l2_pix_format *format)
+{
+ struct v4l2_format fmt;
+ int ret;
+
+ memset(&fmt, 0, sizeof fmt);
+ fmt.type = dev->type;
+ fmt.fmt.pix.width = format->width;
+ fmt.fmt.pix.height = format->height;
+ fmt.fmt.pix.pixelformat = format->pixelformat;
+ fmt.fmt.pix.field = V4L2_FIELD_ANY;
+
+ ret = ioctl(dev->fd, VIDIOC_S_FMT, &fmt);
+ if (ret < 0) {
+ printf("Unable to set format: %s (%d).\n", strerror(errno),
+ errno);
+ return -errno;
+ }
+
+ dev->format = fmt.fmt.pix;
+ *format = fmt.fmt.pix;
+
+ return 0;
+}
+
+/* -----------------------------------------------------------------------------
+ * Buffers management
+ */
+
+int v4l2_alloc_buffers(struct v4l2_device *dev, struct v4l2_buffers_pool *pool,
+ enum v4l2_memory memtype)
+{
+ struct v4l2_requestbuffers rb;
+ struct v4l2_buffer buf;
+ unsigned int i;
+ int ret;
+
+ dev->memtype = memtype;
+ dev->pool = pool;
+
+ memset(&rb, 0, sizeof rb);
+ rb.count = pool->nbufs;
+ rb.type = dev->type;
+ rb.memory = memtype;
+
+ ret = ioctl(dev->fd, VIDIOC_REQBUFS, &rb);
+ if (ret < 0) {
+ printf("Unable to request buffers: %d.\n", errno);
+ ret = -errno;
+ goto done;
+ }
+
+ if (rb.count > pool->nbufs) {
+ printf("Driver needs more buffers (%u) than available (%u).\n",
+ rb.count, pool->nbufs);
+ ret = -E2BIG;
+ goto done;
+ }
+
+ dev->nbufs = rb.count;
+
+ printf("%u buffers requested.\n", rb.count);
+
+ /* Map the buffers. */
+ for (i = 0; i < rb.count; ++i) {
+ memset(&buf, 0, sizeof buf);
+ buf.index = i;
+ buf.type = dev->type;
+ buf.memory = memtype;
+ ret = ioctl(dev->fd, VIDIOC_QUERYBUF, &buf);
+ if (ret < 0) {
+ printf("Unable to query buffer %u (%d).\n", i, errno);
+ ret = -errno;
+ goto done;
+ }
+
+ switch (memtype) {
+ case V4L2_MEMORY_MMAP:
+ pool->buffers[i].mem = mmap(0, buf.length, PROT_READ | PROT_WRITE,
+ MAP_SHARED, dev->fd, buf.m.offset);
+ if (pool->buffers[i].mem == MAP_FAILED) {
+ printf("Unable to map buffer %u (%d)\n", i, errno);
+ ret = -errno;
+ goto done;
+ }
+ pool->buffers[i].size = buf.length;
+ printf("Buffer %u mapped at address %p.\n", i, pool->buffers[i].mem);
+ break;
+
+ case V4L2_MEMORY_USERPTR:
+ if (pool->buffers[i].size < buf.length) {
+ printf("Buffer %u too small (%u bytes required, "
+ "%u bytes available.\n", i, buf.length,
+ pool->buffers[i].size);
+ ret = -EINVAL;
+ goto done;
+ }
+
+ printf("Buffer %u valid.\n", i);
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ ret = 0;
+
+done:
+ if (ret < 0)
+ v4l2_free_buffers(dev);
+
+ return ret;
+}
+
+int v4l2_free_buffers(struct v4l2_device *dev)
+{
+ struct v4l2_requestbuffers rb;
+ unsigned int i;
+ int ret;
+
+ if (dev->pool == NULL)
+ return 0;
+
+ if (dev->memtype == V4L2_MEMORY_MMAP) {
+ for (i = 0; i < dev->nbufs; ++i) {
+ struct v4l2_video_buffer *buffer = &dev->pool->buffers[i];
+
+ if (buffer->mem == NULL)
+ continue;
+
+ ret = munmap(buffer->mem, buffer->size);
+ if (ret < 0) {
+ printf("Unable to unmap buffer %u (%d)\n", i, errno);
+ return -errno;
+ }
+
+ buffer->mem = NULL;
+ buffer->size = 0;
+ }
+ }
+
+ memset(&rb, 0, sizeof rb);
+ rb.count = 0;
+ rb.type = dev->type;
+ rb.memory = dev->memtype;
+
+ ret = ioctl(dev->fd, VIDIOC_REQBUFS, &rb);
+ if (ret < 0) {
+ printf("Unable to release buffers: %d.\n", errno);
+ return -errno;
+ }
+
+ dev->nbufs = 0;
+ dev->pool = NULL;
+
+ return 0;
+}
+
+int v4l2_dequeue_buffer(struct v4l2_device *dev, struct v4l2_video_buffer *buffer)
+{
+ struct v4l2_buffer buf;
+ int ret;
+
+ memset(&buf, 0, sizeof buf);
+ buf.type = dev->type;
+ buf.memory = dev->memtype;
+
+ ret = ioctl(dev->fd, VIDIOC_DQBUF, &buf);
+ if (ret < 0) {
+ printf("Unable to dequeue buffer (%d).\n", errno);
+ return -errno;
+ }
+
+ *buffer = dev->pool->buffers[buf.index];
+ buffer->index = buf.index;
+ buffer->bytesused = buf.bytesused;
+ buffer->timestamp = buf.timestamp;
+ buffer->error = !!(buf.flags & V4L2_BUF_FLAG_ERROR);
+
+ return 0;
+}
+
+int v4l2_queue_buffer(struct v4l2_device *dev, struct v4l2_video_buffer *buffer)
+{
+ struct v4l2_buffer buf;
+ int ret;
+
+ if (buffer->index >= dev->nbufs)
+ return -EINVAL;
+
+ memset(&buf, 0, sizeof buf);
+ buf.index = buffer->index;
+ buf.type = dev->type;
+ buf.memory = dev->memtype;
+
+ if (dev->memtype == V4L2_MEMORY_USERPTR)
+ buf.m.userptr = (unsigned long)dev->pool->buffers[buffer->index].mem;
+
+ buf.length = dev->pool->buffers[buffer->index].size;
+
+ if (dev->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
+ buf.bytesused = buffer->bytesused;
+
+ ret = ioctl(dev->fd, VIDIOC_QBUF, &buf);
+ if (ret < 0) {
+ printf("Unable to queue buffer (%d).\n", errno);
+ return -errno;
+ }
+
+ return 0;
+}
+
+/* -----------------------------------------------------------------------------
+ * Stream management
+ */
+
+int v4l2_stream_on(struct v4l2_device *dev)
+{
+ int type = dev->type;
+ int ret;
+
+ ret = ioctl(dev->fd, VIDIOC_STREAMON, &type);
+ if (ret < 0)
+ return -errno;
+
+ return 0;
+}
+
+int v4l2_stream_off(struct v4l2_device *dev)
+{
+ int type = dev->type;
+ int ret;
+
+ ret = ioctl(dev->fd, VIDIOC_STREAMOFF, &type);
+ if (ret < 0)
+ return -errno;
+
+ return 0;
+}
diff --git a/isp/v4l2.h b/isp/v4l2.h
new file mode 100644
index 0000000..7d28d67
--- /dev/null
+++ b/isp/v4l2.h
@@ -0,0 +1,289 @@
+/*
+ * OMAP3 ISP library - V4L2 devices
+ *
+ * Copyright (C) 2010-2011 Ideas on board SPRL
+ *
+ * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#ifndef __V4L2_H
+#define __V4L2_H
+
+#include <linux/videodev2.h>
+#include <stdbool.h>
+#include <stdint.h>
+
+#include "list.h"
+#include "v4l2-pool.h"
+
+struct v4l2_device
+{
+ int fd;
+
+ enum v4l2_buf_type type;
+ enum v4l2_memory memtype;
+
+ struct list_entry formats;
+ struct v4l2_pix_format format;
+ struct v4l2_rect crop;
+
+ unsigned int nbufs;
+ struct v4l2_buffers_pool *pool;
+};
+
+/*
+ * v4l2_open - Open a V4L2 device
+ * @devname: Name (including path) of the device node
+ *
+ * Open the V4L2 device referenced by @devname for video capture or display in
+ * non-blocking mode.
+ *
+ * If the device can be opened, query its capabilities and enumerates frame
+ * formats, sizes and intervals.
+ *
+ * Return a pointer to a newly allocated v4l2_device structure instance on
+ * success and NULL on failure. The returned pointer must be freed with
+ * v4l2_close when the device isn't needed anymore.
+ */
+struct v4l2_device *v4l2_open(const char *devname);
+
+/*
+ * v4l2_close - Close a V4L2 device
+ * @dev: Device instance
+ *
+ * Close the device instance given as argument and free allocated resources.
+ * Access to the device instance is forbidden after this function returns.
+ */
+void v4l2_close(struct v4l2_device *dev);
+
+/*
+ * v4l2_get_format - Retrieve the current pixel format
+ * @dev: Device instance
+ * @format: Pixel format structure to be filled
+ *
+ * Query the device to retrieve the current pixel format and frame size and fill
+ * the @format structure.
+ *
+ * Return 0 on success or a negative error code on failure.
+ */
+int v4l2_get_format(struct v4l2_device *dev, struct v4l2_pix_format *format);
+
+/*
+ * v4l2_set_format - Set the pixel format
+ * @dev: Device instance
+ * @format: Pixel format structure to be set
+ *
+ * Set the pixel format and frame size stored in @format. The device can modify
+ * the requested format and size, in which case the @format structure will be
+ * updated to reflect the modified settings.
+ *
+ * Return 0 on success or a negative error code on failure.
+ */
+int v4l2_set_format(struct v4l2_device *dev, struct v4l2_pix_format *format);
+
+/*
+ * v4l2_get_crop - Retrieve the current crop rectangle
+ * @dev: Device instance
+ * @rect: Crop rectangle structure to be filled
+ *
+ * Query the device to retrieve the current crop rectangle and fill the @rect
+ * structure.
+ *
+ * Return 0 on success or a negative error code on failure.
+ */
+int v4l2_get_crop(struct v4l2_device *dev, struct v4l2_rect *rect);
+
+/*
+ * v4l2_set_crop - Set the crop rectangle
+ * @dev: Device instance
+ * @rect: Crop rectangle structure to be set
+ *
+ * Set the crop rectangle stored in @rect. The device can modify the requested
+ * rectangle, in which case the @rect structure will be updated to reflect the
+ * modified settings.
+ *
+ * Return 0 on success or a negative error code on failure.
+ */
+int v4l2_set_crop(struct v4l2_device *dev, struct v4l2_rect *rect);
+
+/*
+ * v4l2_alloc_buffers - Allocate buffers for video frames
+ * @dev: Device instance
+ * @pool: Buffers pool
+ * @memtype: Type of buffers
+ *
+ * Request the driver to allocate the number of buffers in the pool. The driver
+ * can modify the number of buffers depending on its needs. The number of
+ * allocated buffers will be stored in the @dev::nbufs field.
+ *
+ * When @memtype is set to V4L2_MEMORY_MMAP the buffers are allocated by the
+ * driver and mapped to userspace. When @memtype is set to V4L2_MEMORY_USERPTR
+ * the driver only allocates buffer objects and relies on the application to
+ * provide memory storage for video frames.
+ *
+ * Upon successful allocation the @dev::pool field points to the buffers pool.
+ *
+ * Return 0 on success or a negative error code on failure.
+ */
+int v4l2_alloc_buffers(struct v4l2_device *dev, struct v4l2_buffers_pool *pool,
+ enum v4l2_memory memtype);
+
+/*
+ * v4l2_free_buffers - Free buffers
+ * @dev: Device instance
+ *
+ * Free buffers previously allocated by v4l2_alloc_buffers(). If the buffers
+ * have been allocated with the V4L2_MEMORY_USERPTR memory type only the buffer
+ * objects are freed, and the caller is responsible for freeing the video frames
+ * memory if required.
+ *
+ * When successful this function sets the @dev::nbufs field to zero and the
+ * @dev::pool field to NULL.
+ *
+ * Return 0 on success or a negative error code on failure.
+ */
+int v4l2_free_buffers(struct v4l2_device *dev);
+
+/*
+ * v4l2_queue_buffer - Queue a buffer for video capture/output
+ * @dev: Device instance
+ * @buffer: Buffer to be queued
+ *
+ * Queue the buffer identified by @buffer for video capture or output, depending
+ * on the device type.
+ *
+ * The caller must initialize the @buffer::index field with the index of the
+ * buffer to be queued. The index is zero-based and must be lower than the
+ * number of allocated buffers.
+ *
+ * For V4L2_MEMORY_USERPTR buffers, the caller must initialize the @buffer::mem
+ * field with the address of the video frame memory, and the @buffer:length
+ * field with its size in bytes. For optimal performances the address and length
+ * should be identical between v4l2_queue_buffer() calls for a given buffer
+ * index.
+ *
+ * For video output, the caller must initialize the @buffer::bytesused field
+ * with the size of video data. The value should differ from the buffer length
+ * for variable-size video formats only.
+ *
+ * Upon successful return the buffer ownership is transferred to the driver. The
+ * caller must not touch video memory for that buffer before calling
+ * v4l2_dequeue_buffer(). Attempting to queue an already queued buffer will
+ * fail.
+ *
+ * Return 0 on success or a negative error code on failure.
+ */
+int v4l2_queue_buffer(struct v4l2_device *dev, struct v4l2_video_buffer *buffer);
+
+/*
+ * v4l2_dequeue_buffer - Dequeue the next buffer
+ * @dev: Device instance
+ * @buffer: Dequeued buffer data to be filled
+ *
+ * Dequeue the next buffer processed by the driver and fill all fields in
+ * @buffer.
+ *
+ * This function does not block. If no buffer is ready it will return
+ * immediately with -EAGAIN.
+ *
+ * If an error occured during video capture or display, the @buffer::error field
+ * is set to true. Depending on the device the video data can be partly
+ * corrupted or complete garbage.
+ *
+ * Once dequeued the buffer ownership is transferred to the caller. Video memory
+ * for that buffer can be safely read from and written to.
+ *
+ * Return 0 on success or a negative error code on failure. An error that
+ * results in @buffer:error being set is not considered as a failure condition
+ * for the purpose of the return value.
+ */
+int v4l2_dequeue_buffer(struct v4l2_device *dev, struct v4l2_video_buffer *buffer);
+
+/*
+ * v4l2_stream_on - Start video streaming
+ * @dev: Device instance
+ *
+ * Start video capture or output on the device. For video output devices at
+ * least one buffer must be queued before starting the stream.
+ *
+ * Return 0 on success or a negative error code on failure.
+ */
+int v4l2_stream_on(struct v4l2_device *dev);
+
+/*
+ * v4l2_stream_off - Stop video streaming
+ * @dev: Device instance
+ *
+ * Stop video capture or output on the device. Upon successful return ownership
+ * of all buffers is returned to the caller.
+ *
+ * Return 0 on success or a negative error code on failure.
+ */
+int v4l2_stream_off(struct v4l2_device *dev);
+
+/*
+ * v4l2_get_control - Read the value of a control
+ * @dev: Device instance
+ * @id: Control ID
+ * @value: Control value to be filled
+ *
+ * Retrieve the current value of control @id and store it in @value.
+ *
+ * Return 0 on success or a negative error code on failure.
+ */
+int v4l2_get_control(struct v4l2_device *dev, unsigned int id, int32_t *value);
+
+/*
+ * v4l2_set_control - Write the value of a control
+ * @dev: Device instance
+ * @id: Control ID
+ * @value: Control value
+ *
+ * Set control @id to @value. The device is allowed to modify the requested
+ * value, in which case @value is updated to the modified value.
+ *
+ * Return 0 on success or a negative error code on failure.
+ */
+int v4l2_set_control(struct v4l2_device *dev, unsigned int id, int32_t *value);
+
+/*
+ * v4l2_get_controls - Read the value of multiple controls
+ * @dev: Device instance
+ * @count: Number of controls
+ * @ctrls: Controls to be read
+ *
+ * Retrieve the current value of controls identified by @ctrls.
+ *
+ * Return 0 on success or a negative error code on failure.
+ */
+int v4l2_get_controls(struct v4l2_device *dev, unsigned int count,
+ struct v4l2_ext_control *ctrls);
+
+/*
+ * v4l2_set_controls - Write the value of multiple controls
+ * @dev: Device instance
+ * @count: Number of controls
+ * @ctrls: Controls to be written
+ *
+ * Set controls identified by @ctrls. The device is allowed to modify the
+ * requested values, in which case @ctrls is updated to the modified value.
+ *
+ * Return 0 on success or a negative error code on failure.
+ */
+int v4l2_set_controls(struct v4l2_device *dev, unsigned int count,
+ struct v4l2_ext_control *ctrls);
+
+#endif
diff --git a/live.c b/live.c
new file mode 100644
index 0000000..bd97036
--- /dev/null
+++ b/live.c
@@ -0,0 +1,467 @@
+/*
+ * OMAP3 live video display test application
+ *
+ * Copyright (C) 2010-2011 Ideas on board SPRL
+ *
+ * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ *
+ * 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 2 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#define _BSD_SOURCE
+#include <endian.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <signal.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/select.h>
+#include <sys/time.h>
+
+#include <linux/fb.h>
+#include <linux/spi/spidev.h>
+
+#include "isp/list.h"
+#include "isp/omap3isp.h"
+#include "isp/tools.h"
+#include "isp/v4l2.h"
+#include "isp/v4l2-pool.h"
+
+#include "videoout.h"
+
+#define MEDIA_DEVICE "/dev/media0"
+#define VIDEOOUT_DEVICE "/dev/video0"
+#define SELECT_TIMEOUT 2000 /* in milliseconds */
+
+static struct timespec fps_ts = { 0, 0 };
+static unsigned int fps_count = 0;
+static bool show_fps = true;
+
+static struct omap3_isp_device *isp = NULL;
+static struct videoout *vo = NULL;
+
+static bool done = false;
+
+/* -----------------------------------------------------------------------------
+ * Events
+ */
+
+struct event_fd {
+ struct list_entry list;
+
+ int fd;
+ bool write;
+ void (*callback)(void *priv);
+ void *priv;
+};
+
+static struct {
+ struct list_entry events;
+
+ int maxfd;
+ fd_set rfds;
+ fd_set wfds;
+} events;
+
+static void events_watch_fd(int fd, bool write, void(*callback)(void *), void *priv)
+{
+ struct event_fd *event;
+
+ event = malloc(sizeof *event);
+ if (event == NULL)
+ return;
+
+ event->fd = fd;
+ event->write = write;
+ event->callback = callback;
+ event->priv = priv;
+
+ if (write)
+ FD_SET(fd, &events.wfds);
+ else
+ FD_SET(fd, &events.rfds);
+
+ events.maxfd = max(events.maxfd, fd);
+
+ list_append(&event->list, &events.events);
+}
+
+static void events_unwatch_fd(int fd)
+{
+ struct event_fd *event = NULL;
+ struct event_fd *entry;
+ int maxfd = 0;
+
+ list_for_each_entry(entry, &events.events, list) {
+ if (entry->fd == fd)
+ event = entry;
+ else
+ maxfd = max(maxfd, entry->fd);
+ }
+
+ if (event == NULL)
+ return;
+
+ if (event->write)
+ FD_CLR(fd, &events.wfds);
+ else
+ FD_CLR(fd, &events.rfds);
+
+ events.maxfd = maxfd;
+
+ list_remove(&event->list);
+ free(event);
+}
+
+static void events_init(void)
+{
+ memset(&events, 0, sizeof events);
+
+ FD_ZERO(&events.rfds);
+ FD_ZERO(&events.wfds);
+ events.maxfd = 0;
+ list_init(&events.events);
+}
+
+static void events_dispatch(const fd_set *rfds, const fd_set *wfds)
+{
+ struct event_fd *event;
+
+ list_for_each_entry(event, &events.events, list) {
+ if (!event->write && FD_ISSET(event->fd, rfds))
+ event->callback(event->priv);
+ if (event->write && FD_ISSET(event->fd, wfds))
+ event->callback(event->priv);
+ }
+}
+
+/* -----------------------------------------------------------------------------
+ * Video input
+ */
+
+static void viewfinder_process(struct omap3_isp_device *isp __attribute__((__unused__)),
+ struct v4l2_video_buffer *buffer)
+{
+ struct timespec ts;
+ float interval;
+
+ if (show_fps){
+ fps_count++;
+
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+
+ interval = ts.tv_sec - fps_ts.tv_sec;
+ interval += (ts.tv_nsec - fps_ts.tv_nsec) / 1000000000.0;
+
+ if (interval >= 5) {
+ if (fps_count > 1)
+ printf("frame rate: %f fps\n", fps_count / interval);
+
+ fps_count = 0;
+ fps_ts = ts;
+ }
+ }
+
+ if (buffer->error) {
+ printf("warning: error in dequeued buffer, skipping\n");
+ return;
+ }
+
+ vo_queue_buffer(vo, buffer);
+}
+
+
+static void events_watch_fd_isp(int fd, enum omap3_isp_event_type type,
+ void (*callback)(void *priv), void *priv)
+{
+ events_watch_fd(fd, type == OMAP3_ISP_EVENT_WRITE, callback, priv);
+}
+
+static struct omap3_isp_operations isp_ops = {
+ .viewfinder_ready = viewfinder_process,
+ .watch_fd = events_watch_fd_isp,
+ .unwatch_fd = events_unwatch_fd,
+};
+
+/* -----------------------------------------------------------------------------
+ * Video output
+ */
+
+static void video_out_process(void *priv __attribute__((__unused__)))
+{
+ struct v4l2_video_buffer buffer;
+ int ret;
+
+ ret = vo_dequeue_buffer(vo, &buffer);
+ if (ret < 0)
+ return;
+
+ /* Requeue the buffer */
+ ret = omap3_isp_viewfinder_put_buffer(isp, &buffer);
+ if (ret < 0) {
+ printf("error: unable to requeue buffer: %s (%d)\n",
+ strerror(-ret), ret);
+ return;
+ }
+}
+
+static void events_watch_fd_vo(int fd)
+{
+ events_watch_fd(fd, true, video_out_process, NULL);
+}
+
+static struct video_out_operations vo_ops = {
+ .watch_fd = events_watch_fd_vo,
+ .unwatch_fd = events_unwatch_fd,
+};
+
+/* -----------------------------------------------------------------------------
+ * Frame buffer
+ */
+
+static int fb_init(struct v4l2_rect *rect)
+{
+ struct fb_fix_screeninfo fix;
+ struct fb_var_screeninfo var;
+ unsigned int i;
+ void *mem = NULL;
+ int ret;
+ int fd;
+
+ fd = open("/dev/fb0", O_RDWR);
+ if (fd == -1)
+ return -ENODEV;
+
+ ret = ioctl(fd, FBIOGET_FSCREENINFO, &fix);
+ if (ret < 0) {
+ printf("error: failed to get fixed screen info\n");
+ goto done;
+ }
+
+ ret = ioctl(fd, FBIOGET_VSCREENINFO, &var);
+ if (ret < 0) {
+ printf("error: failed to get variable screen info\n");
+ goto done;
+ }
+
+ mem = mmap(NULL, fix.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED,
+ fd, 0);
+ if (mem == MAP_FAILED) {
+ printf("error: unable to map frame buffer\n");
+ ret = -ENOMEM;
+ goto done;
+ }
+
+ /* Fill the frame buffer with the background color. */
+ for (i = 0; i < fix.smem_len; i += 4)
+ *(uint32_t *)(mem + i) = 0x00123456;
+
+ /* Return the frame buffer size. */
+ rect->left = var.xoffset;
+ rect->top = var.yoffset;
+ rect->width = var.xres;
+ rect->height = var.yres;
+
+done:
+ if (mem != NULL)
+ munmap(mem, fix.smem_len);
+ close(fd);
+
+ return ret;
+}
+
+/* -------------------------------------------------------------------------- */
+
+static void sigint_handler(int signal __attribute__((__unused__)))
+{
+ /* Set the done flag to true when the user presses CTRL-C to interrupt
+ * the main loop.
+ */
+ done = true;
+}
+
+static void usage(const char *argv0)
+{
+ printf("Usage: %s [options]\n", argv0);
+ printf("Supported options:\n");
+ printf("-h, --help Show this help screen\n");
+}
+
+static struct option opts[] = {
+ { "help", 0, 0, 'h' },
+ { 0, 0, 0, 0 }
+};
+
+int main(int argc __attribute__((__unused__)), char *argv[] __attribute__((__unused__)))
+{
+ struct v4l2_mbus_framefmt view_format;
+ struct v4l2_buffers_pool *pool = NULL;
+ struct timespec start, end;
+ unsigned int count = 0;
+ struct v4l2_rect rect;
+ int exit_code = EXIT_FAILURE;
+ float fps;
+ int ret;
+ int c;
+
+ while ((c = getopt_long(argc, argv, "h", opts, NULL)) != -1) {
+ switch (c) {
+ case 'h':
+ usage(argv[0]);
+ return 0;
+ default:
+ printf("Invalid option -%c\n", c);
+ printf("Run %s -h for help.\n", argv[0]);
+ return 1;
+ }
+ }
+
+ events_init();
+
+ memset(&rect, 0, sizeof rect);
+ ret = fb_init(&rect);
+ if (ret < 0) {
+ printf("error: unable to initialize frame buffer\n");
+ goto cleanup;
+ }
+
+ /* Register a signal handler for SIGINT, received when the user presses
+ * CTRL-C. This will allow the main loop to be interrupted, and resources
+ * to be freed cleanly.
+ */
+ signal(SIGINT, sigint_handler);
+
+ /* Open the OMAP3 ISP device and setup the capture pipeline. */
+ isp = omap3_isp_open(MEDIA_DEVICE, &isp_ops);
+ if (isp == NULL) {
+ printf("error: unable to open media device %s\n", MEDIA_DEVICE);
+ goto cleanup;
+ }
+
+ memset(&view_format, 0, sizeof view_format);
+ view_format.code = V4L2_MBUS_FMT_YUYV8_1X16;
+ view_format.width = rect.width;
+ view_format.height = rect.height;
+
+ ret = omap3_isp_viewfinder_setup(isp, &view_format);
+ if (ret < 0) {
+ printf("error: unable to setup pipeline\n");
+ goto cleanup;
+ }
+
+ printf("viewfinder configured for %04x %ux%u\n",
+ view_format.code, view_format.width, view_format.height);
+
+ /* Initialize video output. */
+ vo = vo_init(VIDEOOUT_DEVICE, &vo_ops, rect.width, rect.height);
+ if (vo == NULL) {
+ printf("error: unable to initialize video output\n");
+ goto cleanup;
+ }
+
+ vo_enable_colorkey(vo, 0x123456);
+
+ /* Allocate a buffers pool and use it for the viewfinder. */
+ pool = vo_get_pool(vo);
+ if (pool == NULL) {
+ printf("error: unable to get video output buffers pool\n");
+ goto cleanup;
+ }
+
+ ret = omap3_isp_viewfinder_set_pool(isp, pool);
+ if (ret < 0) {
+ printf("error: unable to set buffers pool\n");
+ goto cleanup;
+ }
+
+ /* Start the ISP. */
+ ret = omap3_isp_viewfinder_start(isp);
+ if (ret < 0)
+ goto cleanup;
+
+ clock_gettime(CLOCK_MONOTONIC, &start);
+
+ /* Main capture loop. Wait for a video buffer using select() and process
+ * it.
+ */
+ while (!done) {
+ struct timeval timeout;
+ fd_set rfds;
+ fd_set wfds;
+
+ timeout.tv_sec = SELECT_TIMEOUT / 1000;
+ timeout.tv_usec = (SELECT_TIMEOUT % 1000) * 1000;
+ rfds = events.rfds;
+ wfds = events.wfds;
+
+ ret = select(events.maxfd + 1, &rfds, &wfds, NULL, &timeout);
+ if (ret < 0) {
+ /* EINTR means that a signal has been received, continue
+ * to the next iteration in that case.
+ */
+ if (errno == EINTR)
+ continue;
+
+ printf("error: select failed with %d\n", errno);
+ goto cleanup;
+ }
+ if (ret == 0) {
+ /* select() should never time out as the ISP is supposed
+ * to capture images continuously. A timeout is thus
+ * considered as a fatal error.
+ */
+ printf("error: select timeout\n");
+ goto cleanup;
+ }
+
+ events_dispatch(&rfds, &wfds);
+ count++;
+ }
+
+ clock_gettime(CLOCK_MONOTONIC, &end);
+
+ /* Stop the ISP. */
+ omap3_isp_viewfinder_stop(isp);
+
+ /* Print some statistics. */
+ end.tv_sec -= start.tv_sec;
+ end.tv_nsec -= start.tv_nsec;
+ if (end.tv_nsec < 0) {
+ end.tv_sec--;
+ end.tv_nsec += 1000000000;
+ }
+
+ fps = count / (end.tv_sec + end.tv_nsec / 1000000000.0);
+
+ printf("%u images processed in %lu.%06lu seconds (%f fps)\n", count,
+ end.tv_sec, end.tv_nsec / 1000, fps);
+
+ exit_code = EXIT_SUCCESS;
+
+cleanup:
+ /* Cleanup the ISP resources. */
+ if (isp)
+ omap3_isp_close(isp);
+
+ return exit_code;
+}
diff --git a/snapshot.c b/snapshot.c
new file mode 100644
index 0000000..5728ae6
--- /dev/null
+++ b/snapshot.c
@@ -0,0 +1,418 @@
+/*
+ * OMAP3 ISP snapshot test application
+ *
+ * Copyright (C) 2010-2011 Ideas on board SPRL
+ *
+ * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ *
+ * 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 2 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#define _BSD_SOURCE
+#include <endian.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <signal.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/select.h>
+#include <sys/time.h>
+
+#include <linux/spi/spidev.h>
+
+#include "isp/list.h"
+#include "isp/omap3isp.h"
+#include "isp/tools.h"
+#include "isp/v4l2.h"
+#include "isp/v4l2-pool.h"
+
+#define MEDIA_DEVICE "/dev/media0"
+#define SELECT_TIMEOUT 2000 /* in milliseconds */
+
+#define VIEWFINDER_WIDTH 1024
+#define VIEWFINDER_HEIGHT 768
+#define SNAPSHOT_WIDTH 2048
+#define SNAPSHOT_HEIGHT 1536
+
+static unsigned int frame_count = 0;
+static bool done = false;
+
+static unsigned int snapshot_interval = 20;
+static struct timespec snapshot_time;
+
+/* -----------------------------------------------------------------------------
+ * Events
+ */
+
+struct event_fd {
+ struct list_entry list;
+
+ int fd;
+ enum omap3_isp_event_type type;
+ void (*callback)(void *priv);
+ void *priv;
+};
+
+static struct {
+ struct list_entry events;
+
+ int maxfd;
+ fd_set rfds;
+ fd_set wfds;
+} events;
+
+static void events_watch_fd(int fd, enum omap3_isp_event_type type,
+ void(*callback)(void *), void *priv)
+{
+ struct event_fd *event;
+
+ event = malloc(sizeof *event);
+ if (event == NULL)
+ return;
+
+ event->fd = fd;
+ event->type = type;
+ event->callback = callback;
+ event->priv = priv;
+
+ if (event->type == OMAP3_ISP_EVENT_READ)
+ FD_SET(fd, &events.rfds);
+ else
+ FD_SET(fd, &events.wfds);
+
+ events.maxfd = max(events.maxfd, fd);
+
+ list_append(&event->list, &events.events);
+}
+
+static void events_unwatch_fd(int fd)
+{
+ struct event_fd *event = NULL;
+ struct event_fd *entry;
+ int maxfd = 0;
+
+ list_for_each_entry(entry, &events.events, list) {
+ if (entry->fd == fd)
+ event = entry;
+ else
+ maxfd = max(maxfd, entry->fd);
+ }
+
+ if (event == NULL)
+ return;
+
+ if (event->type == OMAP3_ISP_EVENT_READ)
+ FD_CLR(fd, &events.rfds);
+ else
+ FD_CLR(fd, &events.wfds);
+
+ events.maxfd = maxfd;
+
+ list_remove(&event->list);
+ free(event);
+}
+
+static void events_init(void)
+{
+ memset(&events, 0, sizeof events);
+
+ FD_ZERO(&events.rfds);
+ FD_ZERO(&events.wfds);
+ events.maxfd = 0;
+ list_init(&events.events);
+}
+
+static void events_dispatch(const fd_set *rfds, const fd_set *wfds)
+{
+ struct event_fd *event;
+
+ list_for_each_entry(event, &events.events, list) {
+ if (event->type == OMAP3_ISP_EVENT_READ &&
+ FD_ISSET(event->fd, rfds))
+ event->callback(event->priv);
+ if (event->type == OMAP3_ISP_EVENT_WRITE &&
+ FD_ISSET(event->fd, wfds))
+ event->callback(event->priv);
+ }
+}
+
+/* -------------------------------------------------------------------------- */
+
+static void sigint_handler(int signal __attribute__((__unused__)))
+{
+ /* Set the done flag to true when the user presses CTRL-C to interrupt
+ * the main loop.
+ */
+ done = true;
+}
+
+static void snapshot_process(struct omap3_isp_device *isp,
+ struct v4l2_video_buffer *buffer)
+{
+ static struct timespec ts;
+ int ret;
+
+ if (buffer->error) {
+ printf("warning: error in dequeued buffer, skipping\n");
+ return;
+ }
+
+ ts.tv_sec = buffer->timestamp.tv_sec - snapshot_time.tv_sec;
+ ts.tv_nsec = (buffer->timestamp.tv_usec * 1000) - snapshot_time.tv_nsec;
+ if (ts.tv_nsec < 0) {
+ ts.tv_sec--;
+ ts.tv_nsec += 1000000000;
+ }
+
+ printf("snapshot captured in %lu.%06lus.\n", ts.tv_sec, ts.tv_nsec / 1000);
+
+ /* Requeue the buffer */
+ ret = omap3_isp_snapshot_put_buffer(isp, buffer);
+ if (ret < 0) {
+ printf("error: unable to requeue buffer: %s (%d)\n",
+ strerror(-ret), ret);
+ return;
+ }
+}
+
+static void viewfinder_process(struct omap3_isp_device *isp,
+ struct v4l2_video_buffer *buffer)
+{
+ int ret;
+
+ if (buffer->error) {
+ printf("warning: error in dequeued buffer, skipping\n");
+ return;
+ }
+
+ frame_count++;
+ printf("viewfinder frame %u captured.\n", frame_count);
+
+ if ((frame_count % snapshot_interval) == 0) {
+ clock_gettime(CLOCK_MONOTONIC, &snapshot_time);
+ omap3_isp_snapshot_capture(isp);
+ }
+
+ /* Requeue the buffer */
+ ret = omap3_isp_viewfinder_put_buffer(isp, buffer);
+ if (ret < 0) {
+ printf("error: unable to requeue buffer: %s (%d)\n",
+ strerror(-ret), ret);
+ return;
+ }
+}
+
+static void usage(const char *argv0)
+{
+ printf("Usage: %s [options]\n", argv0);
+ printf("Supported options:\n");
+ printf("-h, --help Show this help screen\n");
+ printf("-s, --snap n Capture a snapshot every n frames\n");
+ printf("-y, --yuv YUV snapshots\n");
+}
+
+static struct option opts[] = {
+ { "help", 0, 0, 'h' },
+ { "snap", 0, 0, 's' },
+ { "yuv", 0, 0, 'y' },
+ { 0, 0, 0, 0 }
+};
+
+int main(int argc __attribute__((__unused__)), char *argv[] __attribute__((__unused__)))
+{
+ enum v4l2_mbus_pixelcode snap_code = V4L2_MBUS_FMT_SGRBG10_1X10;
+ struct v4l2_mbus_framefmt view_format;
+ struct v4l2_mbus_framefmt snap_format;
+ struct v4l2_buffers_pool *pool = NULL;
+ struct omap3_isp_device *isp = NULL;
+ struct omap3_isp_operations ops;
+ struct timespec start, end;
+ unsigned int count = 0;
+ int exit_code = EXIT_FAILURE;
+ float fps;
+ int ret;
+ int c;
+
+ while ((c = getopt_long(argc, argv, "hs:y", opts, NULL)) != -1) {
+ switch (c) {
+ case 'h':
+ usage(argv[0]);
+ return 0;
+ case 's':
+ snapshot_interval = strtoul(optarg, NULL, 10);
+ if (snapshot_interval == 0) {
+ printf("snapshot interval value must be >0.\n");
+ return 1;
+ }
+ break;
+ case 'y':
+ snap_code = V4L2_MBUS_FMT_YUYV8_1X16;
+ break;
+ default:
+ printf("Invalid option -%c\n", c);
+ printf("Run %s -h for help.\n", argv[0]);
+ return 1;
+ }
+ }
+
+ events_init();
+
+ /* Register a signal handler for SIGINT, received when the user presses
+ * CTRL-C. This will allow the main loop to be interrupted, and resources
+ * to be freed cleanly.
+ */
+ signal(SIGINT, sigint_handler);
+
+ /* Open the OMAP3 ISP device and setup the capture pipeline. */
+ memset(&ops, 0, sizeof ops);
+ ops.viewfinder_ready = viewfinder_process;
+ ops.snapshot_ready = snapshot_process;
+ ops.watch_fd = events_watch_fd;
+ ops.unwatch_fd = events_unwatch_fd;
+
+ isp = omap3_isp_open(MEDIA_DEVICE, &ops);
+ if (isp == NULL) {
+ printf("error: unable to open media device %s\n", MEDIA_DEVICE);
+ goto cleanup;
+ }
+
+ memset(&view_format, 0, sizeof view_format);
+ view_format.code = V4L2_MBUS_FMT_YUYV8_1X16;
+ view_format.width = VIEWFINDER_WIDTH;
+ view_format.height = VIEWFINDER_HEIGHT;
+
+ ret = omap3_isp_viewfinder_setup(isp, &view_format);
+ if (ret < 0) {
+ printf("error: unable to setup pipeline\n");
+ goto cleanup;
+ }
+
+ printf("viewfinder configured for %04x %ux%u\n",
+ view_format.code, view_format.width, view_format.height);
+
+ memset(&snap_format, 0, sizeof snap_format);
+ snap_format.code = snap_code;
+ snap_format.width = SNAPSHOT_WIDTH;
+ snap_format.height = SNAPSHOT_HEIGHT;
+
+ ret = omap3_isp_snapshot_setup(isp, &snap_format);
+ if (ret < 0) {
+ printf("error: unable to setup pipeline\n");
+ goto cleanup;
+ }
+
+ printf("snapshot configured for %04x %ux%u\n",
+ snap_format.code, snap_format.width, snap_format.height);
+
+ /* Allocate a buffers pool and use it for the viewfinder. */
+ pool = v4l2_buffers_pool_new(4);
+ if (pool == NULL) {
+ printf("error: unable to create buffers pool\n");
+ goto cleanup;
+ }
+
+ ret = v4l2_buffers_pool_alloc(pool, view_format.width * view_format.height * 2, 4096);
+ if (ret < 0) {
+ printf("error: unable to allocate buffers memory\n");
+ goto cleanup;
+ }
+
+ ret = omap3_isp_viewfinder_set_pool(isp, pool);
+ if (ret < 0) {
+ printf("error: unable to set buffers pool\n");
+ goto cleanup;
+ }
+
+ /* Start the ISP. */
+ ret = omap3_isp_viewfinder_start(isp);
+ if (ret < 0)
+ goto cleanup;
+
+ clock_gettime(CLOCK_MONOTONIC, &start);
+
+ /* Main capture loop. Wait for a video buffer using select() and process
+ * it.
+ */
+ while (!done) {
+ struct timeval timeout;
+ fd_set rfds;
+ fd_set wfds;
+
+ timeout.tv_sec = SELECT_TIMEOUT / 1000;
+ timeout.tv_usec = (SELECT_TIMEOUT % 1000) * 1000;
+ rfds = events.rfds;
+ wfds = events.wfds;
+
+ ret = select(events.maxfd + 1, &rfds, &wfds, NULL, &timeout);
+ if (ret < 0) {
+ /* EINTR means that a signal has been received, continue
+ * to the next iteration in that case.
+ */
+ if (errno == EINTR)
+ continue;
+
+ printf("error: select failed with %d\n", errno);
+ goto cleanup;
+ }
+ if (ret == 0) {
+ /* select() should never time out as the ISP is supposed
+ * to capture images continuously. A timeout is thus
+ * considered as a fatal error.
+ */
+ printf("error: select timeout\n");
+ goto cleanup;
+ }
+
+ events_dispatch(&rfds, &wfds);
+ count++;
+ }
+
+ clock_gettime(CLOCK_MONOTONIC, &end);
+
+ /* Stop the ISP. */
+ omap3_isp_viewfinder_stop(isp);
+
+ /* Print some statistics. */
+ end.tv_sec -= start.tv_sec;
+ end.tv_nsec -= start.tv_nsec;
+ if (end.tv_nsec < 0) {
+ end.tv_sec--;
+ end.tv_nsec += 1000000000;
+ }
+
+ fps = count / (end.tv_sec + end.tv_nsec / 1000000000.0);
+
+ printf("%u images processed in %lu.%06lu seconds (%f fps)\n", count,
+ end.tv_sec, end.tv_nsec / 1000, fps);
+
+ exit_code = EXIT_SUCCESS;
+
+cleanup:
+ /* Cleanup the ISP resources. */
+ if (isp)
+ omap3_isp_close(isp);
+ if (pool)
+ v4l2_buffers_pool_delete(pool);
+
+ return exit_code;
+}
diff --git a/videoout.c b/videoout.c
new file mode 100644
index 0000000..6f68b30
--- /dev/null
+++ b/videoout.c
@@ -0,0 +1,228 @@
+/*
+ * V4L2 video output
+ *
+ * Copyright (C) 2010-2011 Ideas on board SPRL
+ *
+ * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ *
+ * 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 2 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <linux/videodev2.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <linux/fb.h>
+
+#include "videoout.h"
+#include "isp/v4l2.h"
+#include "isp/v4l2-pool.h"
+
+#define NUM_BUFFERS 3
+
+struct videoout
+{
+ struct v4l2_device *dev;
+ struct v4l2_buffers_pool *pool;
+ const struct video_out_operations *ops;
+
+ int streaming;
+
+ int queued[NUM_BUFFERS];
+ int num_queued;
+};
+
+struct videoout *vo_init(const char *devname,
+ const struct video_out_operations *ops,
+ unsigned int width, unsigned int height)
+{
+ struct v4l2_buffers_pool *pool = NULL;
+ struct v4l2_device *dev = NULL;
+ struct v4l2_pix_format pixfmt;
+ struct v4l2_format fmt;
+ struct v4l2_rect crop;
+ int ret;
+
+ dev = v4l2_open(devname);
+ if (dev == NULL) {
+ perror("Failed to open display device\n");
+ goto error;
+ }
+
+ crop.left = 0;
+ crop.top = 0;
+ crop.width = width;
+ crop.height = height;
+
+ ret = v4l2_set_crop(dev, &crop);
+ if (ret < 0) {
+ perror("VIDIOC_S_CROP\n");
+ goto error;
+ }
+
+ pixfmt.pixelformat = V4L2_PIX_FMT_YUYV;
+ pixfmt.width = width;
+ pixfmt.height = height;
+ pixfmt.field = V4L2_FIELD_ANY;
+
+ ret = v4l2_set_format(dev, &pixfmt);
+ if (ret < 0) {
+ perror("VIDIOC_S_FMT(output)\n");
+ goto error;
+ }
+
+ fmt.type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
+ fmt.fmt.win.w.left = 0;
+ fmt.fmt.win.w.top = 0;
+ fmt.fmt.win.w.width = width;
+ fmt.fmt.win.w.height = height;
+ ret = ioctl(dev->fd, VIDIOC_S_FMT, &fmt);
+ if (ret < 0) {
+ perror("VIDIOC_S_FMT(overlay)\n");
+ goto error;
+ }
+
+ pool = v4l2_buffers_pool_new(NUM_BUFFERS);
+ if (pool == NULL) {
+ printf("error: unable to allocate buffers pool for display.\n");
+ goto error;
+ }
+
+ ret = v4l2_alloc_buffers(dev, pool, V4L2_MEMORY_MMAP);
+ if (ret < 0) {
+ printf("error: unable to allocate buffers pool for display.\n");
+ goto error;
+ }
+
+ struct videoout *vo = malloc(sizeof *vo);
+ memset(vo, 0, sizeof *vo);
+ vo->dev = dev;
+ vo->pool = pool;
+ vo->ops = ops;
+
+ return vo;
+
+error:
+ if (dev)
+ v4l2_close(dev);
+ if (pool)
+ v4l2_buffers_pool_delete(pool);
+ return NULL;
+}
+
+int vo_enable_colorkey(struct videoout *vo, unsigned int val)
+{
+ struct v4l2_framebuffer framebuffer;
+ struct v4l2_format fmt;
+ int ret;
+
+ fmt.type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
+ ret = ioctl(vo->dev->fd, VIDIOC_G_FMT, &fmt);
+ if (ret < 0) {
+ perror("VIDIOC_G_FMT\n");
+ return 0;
+ }
+
+ fmt.fmt.win.chromakey = val;
+ ret = ioctl(vo->dev->fd, VIDIOC_S_FMT, &fmt);
+ if (ret < 0) {
+ perror("VIDIOC_G_FMT\n");
+ return 0;
+ }
+
+ ret = ioctl(vo->dev->fd, VIDIOC_G_FBUF, &framebuffer);
+ if (ret < 0) {
+ perror ("VIDIOC_G_FBUF");
+ return 0;
+ }
+
+ if (framebuffer.capability & V4L2_FBUF_CAP_CHROMAKEY) {
+ framebuffer.flags |= V4L2_FBUF_FLAG_CHROMAKEY;
+ framebuffer.flags &= ~V4L2_FBUF_FLAG_LOCAL_ALPHA;
+ ret = ioctl(vo->dev->fd, VIDIOC_S_FBUF, &framebuffer);
+ if (ret < 0) {
+ perror ("VIDIOC_S_FBUF");
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+struct v4l2_buffers_pool *vo_get_pool(struct videoout *vo)
+{
+ return vo->pool;
+}
+
+int vo_dequeue_buffer(struct videoout *vo, struct v4l2_video_buffer *buffer)
+{
+ int ret;
+
+ if (vo->num_queued < 2)
+ return -ENOBUFS;
+
+ ret = v4l2_dequeue_buffer(vo->dev, buffer);
+ if (ret < 0) {
+ if (errno != EIO)
+ perror("VIDIOC_DQBUF\n");
+ return -errno;
+ }
+
+ vo->queued[buffer->index] = 0;
+ vo->num_queued--;
+
+ if (vo->num_queued == 0)
+ vo->ops->unwatch_fd(vo->dev->fd);
+
+ return 0;
+}
+
+int vo_queue_buffer(struct videoout *vo, struct v4l2_video_buffer *buffer)
+{
+ int ret;
+
+ if (vo->queued[buffer->index]) {
+ fprintf (stderr, "buffer already queued\n");
+ return 0;
+ }
+
+ ret = v4l2_queue_buffer(vo->dev, buffer);
+ if (ret < 0) {
+ perror("VIDIOC_QBUF\n");
+ return 0;
+ }
+
+ vo->queued[buffer->index] = 1;
+
+ if (!vo->streaming) {
+ if (v4l2_stream_on(vo->dev)) {
+ printf ("error: failed to start display streamon\n");
+ }
+ vo->streaming = 1;
+ }
+
+ if (vo->num_queued == 0)
+ vo->ops->watch_fd(vo->dev->fd);
+
+ vo->num_queued++;
+ return 1;
+}
diff --git a/videoout.h b/videoout.h
new file mode 100644
index 0000000..815f112
--- /dev/null
+++ b/videoout.h
@@ -0,0 +1,43 @@
+/*
+ * V4L2 video output
+ *
+ * Copyright (C) 2010-2011 Ideas on board SPRL
+ *
+ * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ *
+ * 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 2 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __VIDEOOUT_H__
+#define __VIDEOOUT_H__
+
+#include "isp/v4l2-pool.h"
+
+struct videoout;
+
+struct video_out_operations {
+ void (*watch_fd)(int fd);
+ void (*unwatch_fd)(int fd);
+};
+
+struct videoout *vo_init(const char *devname,
+ const struct video_out_operations *ops,
+ unsigned int width, unsigned int height);
+int vo_enable_colorkey(struct videoout *vo, unsigned int val);
+struct v4l2_buffers_pool *vo_get_pool(struct videoout *vo);
+int vo_dequeue_buffer(struct videoout *vo, struct v4l2_video_buffer *buffer);
+int vo_queue_buffer(struct videoout *vo, struct v4l2_video_buffer *buffer);
+
+#endif /* __VIDEOOUT_H__ */