Commit Graph

205 Commits

Author SHA1 Message Date
Giorgio Vazzana d7e088849e lavd/v4l2: introduce enqueue_buffer()
Additionally, make sure a buffer gets enqueued again (even in error paths) after
it has been succesfully dequeued.

Tested-by: Dmitry Volyntsev <xeioexception@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-09-06 00:05:59 +02:00
Giorgio Vazzana 0b890425e3 lavd/v4l2: simplify list_formats()
We can avoid passing file descriptor fd explicitely.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-09-05 20:25:58 +02:00
Giorgio Vazzana 7865cafec2 lavd/v4l2: simplify list_framesizes()
We can avoid passing file descriptor fd explicitely.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-09-05 18:52:34 +02:00
Giorgio Vazzana 55cf7d9713 lavd/v4l2: remove unneeded variable in device_init()
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-09-05 18:43:28 +02:00
Giorgio Vazzana 3da359c140 lavd/v4l2: simplify first_field()
There is no need to pass fd as a second parameter. Additionally remove
unneeded curly braces.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-09-05 18:36:04 +02:00
Giorgio Vazzana 39750b7364 lavd/v4l2: Replace s1 with ctx for consistency.
No functional change in the code.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-09-05 18:10:42 +02:00
Dmitry Volyntsev fe8f4c71e3 libavdevice/v4l2: fix descriptors leak on error paths
Signed-off-by: Dmitry Volytnsev <xeioexception@gmail.com>
Reviewed-by: Benoit Fouet <benoit.fouet@free.fr>
Reviewed-by: Giorgio Vazzana <mywing81@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-09-04 13:52:44 +02:00
Michael Niedermayer c5f43c8888 avdevice/v4l2: try to fix build for openbsd
Found-by: carl
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-08-18 14:03:03 +02:00
Andre Wolokita 44e95a017c lavd/v4l2: do not fail when VIDIOC_ENUMSTD returns ENODATA
As of September 14 2012, v4l_enumstd() will return ENODATA
when a device's std field is set to 0. That is, the device
does not have a standard format. In order to properly
handle this case, v4l2_set_parameters should catch the
ENODATA code and break instead of failing.

Below is the v4l2-core commit describing this change.

>>commit a5338190efc7cfa8c99a6856342a77d21c9a05cf
>>Author: Hans Verkuil <hans.verkuil@cisco.com>
>>Date:   Fri Sep 14 06:45:43 2012 -0300
>>
>>    [media] v4l2-core: tvnorms may be 0 for a given input, handle that case
>>
>>    Currently the core code looks at tvnorms to see whether ENUMSTD
>>    or G_PARM should be enabled. This is not a good check for drivers
>>    that support the STD API on one input and the DV Timings API on another.
>>    In that case tvnorms may be 0.
>>    Instead check whether s_std is present (for ENUMSTD) or whether g_std or
>>    current_norm is present for g_parm.
>>    Also, in the enumstd core function return ENODATA if tvnorms is 0,
>>    because in that case the current input does not support the STD API
>>    and ENUMSTD should return ENODATA for that.
>>
>>    Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
>>    Reviewed-by: Sakari Ailus <sakari.ailus@iki.fi>
>>    Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
2014-08-18 09:20:00 +02:00
Michael Niedermayer fb33bff990 Merge commit 'f929ab0569ff31ed5a59b0b0adb7ce09df3fca39'
* commit 'f929ab0569ff31ed5a59b0b0adb7ce09df3fca39':
  cosmetics: Write NULL pointer equality checks more compactly

Conflicts:
	cmdutils.c
	ffmpeg_opt.c
	ffplay.c
	libavcodec/dvbsub.c
	libavcodec/dvdsubdec.c
	libavcodec/dvdsubenc.c
	libavcodec/dxa.c
	libavcodec/libxvid_rc.c
	libavcodec/mpegvideo.c
	libavcodec/mpegvideo_enc.c
	libavcodec/rv10.c
	libavcodec/tiffenc.c
	libavcodec/utils.c
	libavcodec/vc1dec.c
	libavcodec/zmbv.c
	libavdevice/v4l2.c
	libavformat/matroskadec.c
	libavformat/movenc.c
	libavformat/sdp.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2014-08-15 21:00:50 +02:00
Gabriel Dume f929ab0569 cosmetics: Write NULL pointer equality checks more compactly
Signed-off-by: Diego Biurrun <diego@biurrun.de>
2014-08-15 03:18:18 -07:00
Michael Niedermayer 124c94a1c8 avdevice/v4l2: Use av_malloc_array()
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-05-22 15:08:12 +02:00
Olivier Langlois 0a15067047 lavd: Use av_gettime_relative()
Whenever av_gettime() is used to measure relative period of time,
av_gettime_relative() is prefered as it guarantee monotonic time
on supported platforms.

Since v4l2 is compiled only on Linux where av_gettime_relative()
is monotonic, a small wrapper function av_gettime_monotonic() is used
(should be inlined the compiler) to put emphasis on that fact.

Signed-off-by: Olivier Langlois <olivier@trillion01.com>
Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-05-18 16:10:12 +02:00
Michael Niedermayer 68c3e6025f Fix convertion typos
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-04-29 00:09:08 +02:00
Lukasz Marek f607767d93 lavd: add categories to device implementations
Signed-off-by: Lukasz Marek <lukasz.m.luki@gmail.com>
2014-03-03 23:34:46 +01:00
Michael Niedermayer 0997c2504b avdevice/v4l2: only use average frame rate if set
It might be unset on some platforms with some drivers and some input

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-02-02 00:15:11 +01:00
Michael Niedermayer 4aa4533ee8 avdevice/v4l2: only use frame period from v4l2 if valid
There is evidence that some drivers do not set a valid value

See: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=718805
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-02-02 00:13:01 +01:00
Federico Simoncelli b1ad931233 v4l2: setting device parameters early
Setting the v4l2 device parameters may influence video properties
such as width, height and pixel format.
This patch moves v4l2_set_parameters to be executed before fetching
the video properties, avoiding errors such as (pal vs ntsc):

 The v4l2 frame is 829440 bytes, but 691200 bytes are expected

Signed-off-by: Federico Simoncelli <fsimonce@redhat.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-01-05 14:02:06 +01:00
Derek Buitenhuis 6ef30976e0 timefilter: Handle memory allocation failure
Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2013-10-27 19:14:23 +00:00
mrlika ed72542539 lavd/v4l2: do not fail when VIDIOC_ENUMSTD returns EINVAL without a valid match
With some (buggy) drivers, the VIDIOC_G_STD ioctl returns a std_id that cannot
be matched with any of the enumerated v4l2_standard structures (for example
std_id = 0 or std_id = 0xffffff). Do not fail when we reach the end of the
enumeration without a valid match.

Fixes ticket #2370

Note: This commit message has been modified by Giorgio Vazzana, the original
commit message was:

"Fixed regression for mandatory VIDIOC_ENUMSTD support by v4l2"

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-09-17 22:57:31 +02:00
Giorgio Vazzana 7f6ec05f09 lavd/v4l2: Improve debug message
In particular, print the standard supported by the selected input.
Additionally, use PRIx64 everywhere when printing standards.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-09-08 14:30:52 +02:00
Carl Eugen Hoyos e337c9d564 Read h264 headers from v4l2 to allow stream-copying.
Fixes ticket #2882.
Analyzed and tested by William C Bonner.
2013-09-01 21:27:43 +02:00
Rémi Denis-Courmont 71bf6b41d9 libavdevice: use avpriv_open()
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2013-08-07 21:16:05 +02:00
Michael Niedermayer 20be5e0a0e Merge commit '7950e519bb094897f957b9a9531cc60ba46cbc91'
* commit '7950e519bb094897f957b9a9531cc60ba46cbc91':
  Disable deprecation warnings for cases where a replacement is available

Conflicts:
	libavcodec/avpacket.c
	libavcodec/pthread.c
	libavcodec/utils.c
	libavdevice/v4l2.c
	libavfilter/avfiltergraph.c
	libavfilter/buffersrc.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-08-03 10:08:30 +02:00
Diego Biurrun 7950e519bb Disable deprecation warnings for cases where a replacement is available 2013-08-02 19:19:02 +02:00
Clément Bœsch 165bc9caa2 v4l2: make possible to disable libv4l2 at runtime.
Also disable it by default since it looks currently buggy. The
usefulness of such library is mostly limited to backward compatibility
with very old devices.
2013-05-22 19:49:29 +02:00
Clément Bœsch 8eec655320 lavd/v4l2: move pixel format conversion code to a separate place.
This will be shared with the output device.
2013-05-20 01:11:28 +02:00
Michael Niedermayer 0104570fb6 Merge commit 'a5f8873620ce502d37d0cc3ef93ada2ea8fb8de7'
* commit 'a5f8873620ce502d37d0cc3ef93ada2ea8fb8de7':
  silly typo fixes

Conflicts:
	doc/protocols.texi
	libavcodec/aacpsy.c
	libavformat/utils.c
	tools/patcheck

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-05-04 10:17:52 +02:00
Diego Biurrun a5f8873620 silly typo fixes 2013-05-03 18:26:12 +02:00
Nicolas George 9dd54d7422 lavd/v4l2: fully init an ioctl argument.
Silence a valgrind warning about uninitialized memory.
2013-04-01 10:38:14 +02:00
Giorgio Vazzana 5009863ab5 lavd/v4l2: fix printing of list_formats table
In particular we needed a '\n' at the end of the line when the format is emulated.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-03-28 16:17:42 +01:00
Giorgio Vazzana b97f7d9d24 lavd/v4l2: replace ioctl() with v4l2_ioctl()
This is consistent with the rest of the file and makes listing of
emulated formats possible when ffmpeg is compiled with libv4l2.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-03-28 16:17:04 +01:00
Giorgio Vazzana 785b849f1c lavd/v4l2: honor previously selected input channel
An input channel could have been previously set with another application, like
v4l2-ctl, so if no input channel is specified use the previosly selected one.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-03-23 13:43:56 +01:00
Giorgio Vazzana bcd3eb3e7a lavd/v4l2: silence libv4l2 logging
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-03-16 02:44:36 +01:00
Giorgio Vazzana ee4a658695 lavd/v4l2: fix bug in init_convert_timestamp()
The current code returned a period=0, resulting in identical pts for all frames
after time-filtering. This is because AV_TIME_BASE_Q={1, AV_TIME_BASE} and
not {AV_TIME_BASE, 1}. With this patch the correct period in microseconds is computed.
2013-03-12 17:14:47 +01:00
Michael Niedermayer 9cf788eca8 avformat/avdevice: add missing time.h includes
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-03-12 15:28:22 +01:00
Giorgio Vazzana 9222978aed lavd/v4l2: simplify code
struct buff_data contains a pointer to struct video_data, so passing the
file descriptor again is redundant.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-03-09 16:59:13 +01:00
Giorgio Vazzana 0286b42540 lavd/v4l2: correctly handle error conditions in mmap_read_frame()
In particular:

1) save errno before it (possibly) gets overwritten by other calls
2) do not forget to enqueue the buffer again in case of error

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-03-09 16:58:53 +01:00
Michael Niedermayer 2653e12520 Merge commit '1afddbe59e96af75f1c07605afc95615569f388f'
* commit '1afddbe59e96af75f1c07605afc95615569f388f':
  avpacket: use AVBuffer to allow refcounting the packets.

Conflicts:
	libavcodec/avpacket.c
	libavcodec/utils.c
	libavdevice/v4l2.c
	libavformat/avidec.c
	libavformat/flacdec.c
	libavformat/id3v2.c
	libavformat/matroskaenc.c
	libavformat/mux.c
	libavformat/utils.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-03-08 19:12:03 +01:00
Anton Khirnov 1afddbe59e avpacket: use AVBuffer to allow refcounting the packets.
This will allow us to avoid copying the packets in many cases.

This breaks ABI.
2013-03-08 07:33:45 +01:00
Michael Niedermayer 3827734591 v4l2: fix regression that caused ffmpeg to occasionally get stuck
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-03-02 01:55:08 +01:00
Giorgio Vazzana 0d66268e15 lavd/v4l2: copy frames into normally allocated packets whenever there is just one buffer left available
This will avoid the possibility that we dequeue more buffers than we
have obtained from the v4l2 driver.

Fixes ticket #1570

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-03-02 00:50:17 +01:00
Michael Niedermayer 54b2bddd22 v4l2: try to fix build on BSD
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-02-18 00:53:17 +01:00
Carl Eugen Hoyos fdbe7628a9 Add yvu410 as a supported v4l2 input format. 2013-02-17 19:45:58 +01:00
Carl Eugen Hoyos fdec49cbe8 Add gray16 as a supported v4l2 input format. 2013-02-17 19:44:13 +01:00
Stefano Sabatini f0703b6cba lavd/v4l2: fix error logic when enumerating standards
Set ret to 0 before enumerating standards in v4l2_set_parameters(), avoid
use of uninitialized variable.

Regression introduced in 60950adc18.
2013-02-10 20:59:06 +01:00
Stefano Sabatini 60950adc18 lavd/v4l2: implement consistent error handling
In particular, avoid use of non-thread-safe strerror(), and store errno
before calling av_log().
2013-02-10 17:09:57 +01:00
Giorgio Vazzana 514216d8a9 lavd/v4l2: read the correct time per frame from devices that support a standard
Generally speaking, there are two types of v4l2 devices [1]:

1) devices that support a standard, like PAL or NTFS (tv cards, for example). For
this class of devices the framerate is fixed by the standard (for example PAL uses
25 fps) and the v4l2 driver cannot usually negotiate a different framerate (unless
it can skip frames on the driver side, to save I/O bandwidth).

2) devices for which the notion of standard does not make sense (webcams, for example).
For these devices it is usually possibile to request a desidered framerate.

In either case, the desidered frame rate can be requested when the VIDIOC_G_PARM
ioctl returns the V4L2_CAP_TIMEPERFRAME flag in the capability field.

Currently the code does not check for V4L2_CAP_TIMEPERFRAME and supports only the
second category of devices, returning a time per frame of 0/0 for devices in the
first group that do not permit to negotiate the framerate.

This patch adds support to read the correct framerate in all cases.

[1] http://linuxtv.org/downloads/v4l-dvb-apis/standard.html

Signed-off-by: Stefano Sabatini <stefasab@gmail.com>
2013-01-31 15:29:53 +01:00
Giorgio Vazzana ff23b76899 lavd/v4l2: add list_standards option
Since the user is expected to choose the standard by name (with -standard
option), add the possibility to list all the supported standards.

Signed-off-by: Stefano Sabatini <stefasab@gmail.com>
2013-01-31 12:38:03 +01:00
Stephan Hilb 0501d06468 lavd/v4l2: use avcodec_find_decoder in list_formats
Because libavdevice/v4l2 is a demuxer, it makes sense to look for
decoders instead of encoders when listing the formats supported by the
device.

Signed-off-by: Stefano Sabatini <stefasab@gmail.com>
2013-01-28 00:11:49 +01:00