loaders: JPG: Fix bussy loop on corrupted file.
[gfxprim.git] / doc / grabbers.txt
blob871cfdca287cbc2c5e2b4562173b53cab62336d1
1 Grabbers
2 --------
4 Grabber is an abstraction for a device whose output is a stream of images.
6 There is currently V4L2 driver that implements a grabber.
8 Link with +-lgfxprim-grabbers+ or better +\`gfxprim-config --libs-grabbers`+.
10 TIP: For example usage see grabber link:example_v4l2.html[examples].
12 Grabber API
13 ~~~~~~~~~~~
15 The grabber API consist of structure with callbacks. Every grabber
16 initialization yields pointer to this structure. Although is possible to call
17 these pointers directly it's not recommended and everybody should rather use
18 the inline functions instead.
20 The grabber API consist GP_Grabber structure and of several functions:
22 [source,c]
23 -------------------------------------------------------------------------------
24 typdef struct GP_Grabber {
25         /*
26          * Currently loaded frame.
27          */
28         GP_Pixmap *frame;
30         /*
31          * Connection fd usable for select() or poll().
32          *
33          * Set to -1 if not available.
34          */
35         int fd;
37         /* ... */
39 -------------------------------------------------------------------------------
41 The frame is a pointer to currently loaded frame. Its content is undefined
42 until you start the grabber with 'GP_GrabberStart()' and receive frame with
43 'GP_GrabberPoll()'.
45 The 'fd' is a file descriptor suitable for select() or poll(). It's set to -1
46 if there is none.
49 [source,c]
50 -------------------------------------------------------------------------------
51 #include <grabbers/GP_Grabber.h>
52 /* or */
53 #include <GP.h>
55 void GP_GrabberExit(GP_Grabber *backend);
56 -------------------------------------------------------------------------------
58 Exits the grabber, frees memory, unmaps memory mappings, closes file
59 descriptors etc...
61 [source,c]
62 -------------------------------------------------------------------------------
63 #include <grabbers/GP_Grabber.h>
64 /* or */
65 #include <GP.h>
67 int GP_GrabberStart(struct GP_Grabber *self);
68 -------------------------------------------------------------------------------
70 Starts a grabber. After calling this you can start retrieving frames with
71 'GP_GrabberPoll()'.
73 Returns zero on success and non-zero on failure.
75 [source,c]
76 -------------------------------------------------------------------------------
77 #include <grabbers/GP_Grabber.h>
78 /* or */
79 #include <GP.h>
81 int GP_GrabberStop(struct GP_Grabber *self);
82 -------------------------------------------------------------------------------
84 Stops a grabber. Call this when you doesn't need to receive frames but still
85 plan to use the grabber later.
87 Returns zero on success and non-zero on failure.
89 [source,c]
90 -------------------------------------------------------------------------------
91 #include <grabbers/GP_Grabber.h>
92 /* or */
93 #include <GP.h>
95 int GP_GrabberPoll(struct GP_Grabber *self);
96 -------------------------------------------------------------------------------
98 Once grabber is created you can call this function to receive a frame. If
99 grabber 'fd' is not -1 it's preferable to call it when select() or poll()
100 returns that data are available on the 'fd'.
102 This function returns non-zero if new frame was received and stored into the
103 'frame' pixmap. Otherwise zero is returned.
105 Grabber Initializations
106 ~~~~~~~~~~~~~~~~~~~~~~
108 [source,c]
109 -------------------------------------------------------------------------------
110 #include <grabbers/GP_V4L2.h>
111 /* or */
112 #include <GP.h>
114 struct GP_Grabber *GP_GrabberV4L2Init(const char *device,
115                                       unsigned int preferred_width,
116                                       unsigned int preferred_height);
117 -------------------------------------------------------------------------------
119 Opens and initializes V4L2 device. The device is a path in +/dev+ filesystem
120 the first V4L2 device in your system should be +/dev/video0+.
122 The height and width are preferred values, you will most likely get frame by
123 that width and height, but the driver may return different values if chosen
124 width and height are not supported.
126 Returns either pointer to the initialized grabber or, in case of failure,
127 NULL and errno is set.