Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 1 | .. -*- coding: utf-8; mode: rst -*- |
| 2 | |
| 3 | .. _func-open: |
| 4 | |
| 5 | *********** |
| 6 | V4L2 open() |
| 7 | *********** |
| 8 | |
Mauro Carvalho Chehab | 15e7d61 | 2016-07-05 15:14:35 -0300 | [diff] [blame] | 9 | Name |
Mauro Carvalho Chehab | 586027c | 2016-07-05 07:58:48 -0300 | [diff] [blame] | 10 | ==== |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 11 | |
Mauro Carvalho Chehab | 586027c | 2016-07-05 07:58:48 -0300 | [diff] [blame] | 12 | v4l2-open - Open a V4L2 device |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 13 | |
Mauro Carvalho Chehab | 15e7d61 | 2016-07-05 15:14:35 -0300 | [diff] [blame] | 14 | |
| 15 | Synopsis |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 16 | ======== |
| 17 | |
| 18 | .. code-block:: c |
| 19 | |
| 20 | #include <fcntl.h> |
| 21 | |
| 22 | |
Mauro Carvalho Chehab | b7e67f6 | 2016-07-02 09:49:16 -0300 | [diff] [blame] | 23 | .. cpp:function:: int open( const char *device_name, int flags ) |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 24 | |
Mauro Carvalho Chehab | 586027c | 2016-07-05 07:58:48 -0300 | [diff] [blame] | 25 | |
Mauro Carvalho Chehab | 15e7d61 | 2016-07-05 15:14:35 -0300 | [diff] [blame] | 26 | Arguments |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 27 | ========= |
| 28 | |
| 29 | ``device_name`` |
| 30 | Device to be opened. |
| 31 | |
| 32 | ``flags`` |
| 33 | Open flags. Access mode must be ``O_RDWR``. This is just a |
| 34 | technicality, input devices still support only reading and output |
| 35 | devices only writing. |
| 36 | |
Mauro Carvalho Chehab | f84dd90 | 2016-07-04 18:16:57 -0300 | [diff] [blame] | 37 | When the ``O_NONBLOCK`` flag is given, the :ref:`read() <func-read>` |
| 38 | function and the :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` ioctl will |
| 39 | return the ``EAGAIN`` error code when no data is available or no |
| 40 | buffer is in the driver outgoing queue, otherwise these functions |
| 41 | block until data becomes available. All V4L2 drivers exchanging data |
| 42 | with applications must support the ``O_NONBLOCK`` flag. |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 43 | |
| 44 | Other flags have no effect. |
| 45 | |
| 46 | |
Mauro Carvalho Chehab | 15e7d61 | 2016-07-05 15:14:35 -0300 | [diff] [blame] | 47 | Description |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 48 | =========== |
| 49 | |
Mauro Carvalho Chehab | 760c701 | 2016-07-04 12:56:17 -0300 | [diff] [blame] | 50 | To open a V4L2 device applications call :ref:`open() <func-open>` with the |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 51 | desired device name. This function has no side effects; all data format |
| 52 | parameters, current input or output, control values or other properties |
Mauro Carvalho Chehab | 760c701 | 2016-07-04 12:56:17 -0300 | [diff] [blame] | 53 | remain unchanged. At the first :ref:`open() <func-open>` call after loading the |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 54 | driver they will be reset to default values, drivers are never in an |
| 55 | undefined state. |
| 56 | |
| 57 | |
Mauro Carvalho Chehab | 15e7d61 | 2016-07-05 15:14:35 -0300 | [diff] [blame] | 58 | Return Value |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 59 | ============ |
| 60 | |
Mauro Carvalho Chehab | 760c701 | 2016-07-04 12:56:17 -0300 | [diff] [blame] | 61 | On success :ref:`open() <func-open>` returns the new file descriptor. On error |
Markus Heiser | 5377d91 | 2016-06-30 15:18:56 +0200 | [diff] [blame] | 62 | -1 is returned, and the ``errno`` variable is set appropriately. |
| 63 | Possible error codes are: |
| 64 | |
| 65 | EACCES |
| 66 | The caller has no permission to access the device. |
| 67 | |
| 68 | EBUSY |
| 69 | The driver does not support multiple opens and the device is already |
| 70 | in use. |
| 71 | |
| 72 | ENXIO |
| 73 | No device corresponding to this device special file exists. |
| 74 | |
| 75 | ENOMEM |
| 76 | Not enough kernel memory was available to complete the request. |
| 77 | |
| 78 | EMFILE |
| 79 | The process already has the maximum number of files open. |
| 80 | |
| 81 | ENFILE |
| 82 | The limit on the total number of files open on the system has been |
| 83 | reached. |