Commit Graph

269 Commits

Author SHA1 Message Date
Andreas Rheinhardt 2b41463b87 avformat/internal: Don't include avcodec.h
The general demuxing API uses parsers and decoders. Therefore
FFStream contains pointers to AVCodecContexts and
AVCodecParserContext and lavf/internal.h includes lavc/avcodec.h.

Yet actually only a few files files really use these; and it is best
when this number stays small. Therefore this commit uses opaque
structs in lavf/internal.h for these contexts and stops including
avcodec.h.
This also avoids including lavc/codec_desc.h implicitly. All other
headers are implicitly included as now (mostly through codec.h).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-09-26 03:02:50 +02:00
Zhao Zhili 30aa0c3f48 avdevice/v4l2: fix leak of timefilter
Fixes ticket #9844.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2022-08-03 17:52:25 +08:00
Andreas Rheinhardt 8550a05ece avdevice/v4l2*: Improve included headers
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-10 07:38:01 +02:00
Andreas Rheinhardt 284313c664 avformat/utils: Move parser functions to a new file, demux_utils.c
This file is both for the various public APIs that are demuxer-only
as well as for the demuxer-only internal functions.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-05-10 07:37:50 +02:00
Anton Khirnov 877b6a9e82 lavd/v4l2: detect device name truncation
Silences the following warning with gcc 10:
src/libavdevice/v4l2.c: In function ‘v4l2_get_device_list’:
src/libavdevice/v4l2.c:1042:64: warning: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size 251 [-Wformat-truncation=]
 1042 |         ret = snprintf(device_name, sizeof(device_name), "/dev/%s", entry->d_name);
      |                                                                ^~
src/libavdevice/v4l2.c:1042:15: note: ‘snprintf’ output between 6 and 261 bytes into a destination of size 256
 1042 |         ret = snprintf(device_name, sizeof(device_name), "/dev/%s", entry->d_name);
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Previous patches intending to silence it have proposed increasing the
buffer size, but doing that correctly seems to be tricky. Failing on
truncation is simpler and just as effective (as excessively long device
names are unlikely).
2021-12-07 11:16:14 +01:00
Anton Khirnov b532ca3d2f lavd/v4l2: reduce variable scope
device and cap are local to the loop iteration, there is no need for
them to retain their values. Especially for device it may be dangerous,
since it points to av_malloc'ed data.
2021-12-07 11:16:14 +01:00
Anton Khirnov e1151fbf22 lavd/v4l2: do not clobber the context FD in v4l2_get_device_list()
The FD opened here is local to the loop iteration, there is no reason to
store it in the context. Since read_header() may have already been
called, this may ovewrite an existing valid FD.
2021-12-07 11:16:14 +01:00
Andreas Rheinhardt fd101c9c3b avformat/internal: Move ff_read_line_to_bprint_overwrite to avio_internal.h
It only uses an AVIOContext and an AVBPrint.

When doing so, it turned out that several non-users of
ff_read_line_to_bprint_overwrite() and ff_bprint_to_codecpar_extradata()
relied on libavformat/internal.h to include bprint.h or avstring.h
for them. In order to avoid a repeat of this and in order to reduce
unnecessary dependencies, a forward declaration of struct AVBPrint is
used instead of including bprint.h.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-07-29 22:02:05 +02:00
Andreas Rheinhardt 2934a4b9a5 Remove unnecessary avassert.h inclusions
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-07-22 15:02:30 +02:00
James Almer b9c5fdf602 avformat: move AVStream.{parser,need_parsing} to AVStreamInternal
Those are private fields, no reason to have them exposed in a public
header.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-05-07 09:27:21 -03:00
Andreas Rheinhardt d92f38c179 avdevice: Constify all devices
This is possible now that the next-API is gone.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 11:48:05 -03:00
Andreas Rheinhardt 11bc790893 avcodec: Remove deprecated AVCodecContext.coded_frame
Deprecated in 40cf1bbacc.
(The currently disabled filter vf_mcdeint and vf_uspp were users of
this field; they have not been changed, so that whoever wants to fix
them can see the state of these filters when they were disabled.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 10:43:12 -03:00
Andriy Gelman 7b2ce27e56 avdevice/v4l2: Remove av_assert0 when format not supported
Before this commit an av_assert0 would fail if a v4l2 device did not
support a target format.
For example,
./ffmpeg -f v4l2 -codec:v h264 -i /dev/video0 -f mpegts -
would signal an abort if /dev/video0 did not support h264.

The new behaviour is to return an AVERROR(EINVAL) error code. An
av_assert0 has been added to verify this return.

Fixes #6629

Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-11-06 20:38:03 +01:00
Stephan Hilb b761ae072a lavd/v4l2: produce a 0 byte packet when a dequeued buffer's size is unexpected
Behave like we do for V4L2_BUF_FLAG_ERROR, implemented in commit 28f20d2ff4 .

For some devices (probably also related to the V4L driver implementation)
it happens that when invoking the ioctl DQBUF, the returned buffer is not
of the expected size. Here are two examples for such occurrences:

    [video4linux2,v4l2 @ 0x258b440] Dequeued v4l2 buffer contains 609596 bytes, but 614400 were expected. Flags: 0x00000001.
    /dev/video1: Invalid data found when processing input

    [video4linux2,v4l2 @ 0x225f440] Dequeued v4l2 buffer contains 609508 bytes, but 614400 were expected. Flags: 0x00000001.
    /dev/video1: Invalid data found when processing input

For the ffmpeg CLI tool this means it will stop capturing and exit.

The described behaviour was observed at least with one OmniVision USB
web cam and with some stk1160 devices.

If you search the web for the error message, you will find quite a few
instances of this problem. Some of them experienced on other devices.

Probably fixes ticket #4795

Signed-off-by: Alexander Strasser <eclipse7@gmx.net>
2019-07-30 12:05:52 +02:00
Carl Eugen Hoyos 5fceac1cdb lavd/v4l2: Fix the type of the probe function. 2019-03-23 23:42:09 +01:00
Carl Eugen Hoyos 73251678c8 lavd/v4l2: Use "int request" as second parameter for ioctl() on Android.
Fixes build with new Android toolchain.
2018-12-11 00:49:22 +01:00
Marton Balint 4bb0409820 avdevice: migrate to AVFormatContext->url
Signed-off-by: Marton Balint <cus@passwd.hu>
2018-01-28 23:06:43 +01:00
Jaroslav Beran 00a1e1337f libavdevice/v4l2: fix invalid access to struct v4l2_buffer
In case we are short of queued buffers, at first v4l2_buffer was enqueued to kernel so it's not owned by
user-space anymore. After that it's timestamp field was read, but it might be overwritten by driver at
that moment. It resulted in invalid timestamp sometimes.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-09-24 02:33:48 +02:00
Clément Bœsch a0ffd66caa Merge commit '0fea8555ae25124c21f4c4f55a5fa76e9169aa03'
* commit '0fea8555ae25124c21f4c4f55a5fa76e9169aa03':
  v4l2: use codec descriptors for mapping a codec name to id

Merged-by: Clément Bœsch <u@pkh.me>
2017-04-26 17:17:50 +02:00
Clément Bœsch b7336faa39 Merge commit '3a165c187da7d74f46f6c1778294e8c5a3a7151f'
* commit '3a165c187da7d74f46f6c1778294e8c5a3a7151f':
  v4l2: convert to stdatomic

Merged-by: Clément Bœsch <u@pkh.me>
2017-03-22 17:55:18 +01:00
Carl Eugen Hoyos 0b607228bf Cosmetics: Reindent after last commit. 2017-01-25 00:55:36 +01:00
Carl Eugen Hoyos 9d5141d1fb lavd/v4l2: Avoid setting frame_size to a negative value. 2017-01-25 00:54:10 +01:00
Anton Khirnov 0fea8555ae v4l2: use codec descriptors for mapping a codec name to id
This mapping has nothing to do with decoder implementations, so using
decoder names is wrong.
2016-12-19 08:07:15 +01:00
Hendrik Leppkes d7d6f9c782 Merge commit '0b1bd1b2057d41fd0ccba7317911c484a50f9207'
* commit '0b1bd1b2057d41fd0ccba7317911c484a50f9207':
  lavd: Drop unneeded av_init_packet()s

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
2016-11-18 10:20:14 +01:00
Anton Khirnov 3a165c187d v4l2: convert to stdatomic 2016-10-02 19:34:57 +02:00
Vittorio Giovara 0b1bd1b205 lavd: Drop unneeded av_init_packet()s
The input packet is already unref'd by the calling function.
2016-07-13 18:20:27 -04:00
Clément Bœsch a444a50510 Merge commit '11de006babf735aafa3462d43dd2c02bb6ac6e2f'
* commit '11de006babf735aafa3462d43dd2c02bb6ac6e2f':
  Combine deprecation guards where appropriate

Merged-by: Clément Bœsch <clement@stupeflix.com>
2016-06-22 17:36:42 +02:00
Clément Bœsch a4403e49b9 Merge commit 'b7e64fba7f37cc0399beae844f0a5dbef9219376'
* commit 'b7e64fba7f37cc0399beae844f0a5dbef9219376':
  Reduce the scope of some variables

Merged-by: Clément Bœsch <u@pkh.me>
2016-06-21 22:40:56 +02:00
Niklas Söderlund 6fd4145a1e lavd/v4l2: allow devices not implementing VIDIOC_G_PARM
Not all v4l2 devices implement the VIDIOC_G_PARM ioctl. This patch allow
ffmpeg to open such device and treat it the same as devices that do
implement the ioctl but returns that it do not implement the
V4L2_CAP_TIMEPERFRAME capability.

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Reviewed-by: Benoit Fouet <benoit.fouet@free.fr>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-06-16 16:27:35 +02:00
Diego Biurrun 11de006bab Combine deprecation guards where appropriate
Some code blocks use multiple bits of deprecated API.
2016-05-13 15:14:30 +02:00
Diego Biurrun b7e64fba7f Reduce the scope of some variables
This avoids unused variable warnings after the next version bump.
Also drop a trace level av_log() call that is in the way.
2016-05-11 12:21:25 +02:00
Derek Buitenhuis 6f69f7a8bf Merge commit '9200514ad8717c63f82101dc394f4378854325bf'
* commit '9200514ad8717c63f82101dc394f4378854325bf':
  lavf: replace AVStream.codec with AVStream.codecpar

This has been a HUGE effort from:
    - Derek Buitenhuis <derek.buitenhuis@gmail.com>
    - Hendrik Leppkes <h.leppkes@gmail.com>
    - wm4 <nfxjfg@googlemail.com>
    - Clément Bœsch <clement@stupeflix.com>
    - James Almer <jamrial@gmail.com>
    - Michael Niedermayer <michael@niedermayer.cc>
    - Rostislav Pehlivanov <atomnuker@gmail.com>

Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2016-04-10 20:59:55 +01:00
Anton Khirnov 9200514ad8 lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.

In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.

There are multiple important problems with this approach:
    - the fields in AVCodecContext are in general one of
        * stream parameters
        * codec options
        * codec state
      However, it's not clear which ones are which. It is consequently
      unclear which fields are a demuxer allowed to set or a muxer allowed to
      read. This leads to erratic behaviour depending on whether decoding or
      encoding is being performed or not (and whether it uses the AVStream
      embedded codec context).
    - various synchronization issues arising from the fact that the same
      context is used by several different APIs (muxers/demuxers,
      parsers, bitstream filters and encoders/decoders) simultaneously, with
      there being no clear rules for who can modify what and the different
      processes being typically delayed with respect to each other.
    - avformat_find_stream_info() making it necessary to support opening
      and closing a single codec context multiple times, thus
      complicating the semantics of freeing various allocated objects in the
      codec context.

Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2016-02-23 17:01:58 +01:00
Timothy Gu d64d6edfc7 Correct two build/built typos
Found-by: Leo Izen <leo.izen@gmail.com> as thebombzen on IRC
Signed-off-by: Timothy Gu <timothygu99@gmail.com>
2016-01-11 20:53:11 -08:00
Hendrik Leppkes 7f5af80ba4 Merge commit 'ce70f28a1732c74a9cd7fec2d56178750bd6e457'
* commit 'ce70f28a1732c74a9cd7fec2d56178750bd6e457':
  avpacket: Replace av_free_packet with av_packet_unref

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
2015-10-27 14:28:56 +01:00
Luca Barbato ce70f28a17 avpacket: Replace av_free_packet with av_packet_unref
`av_packet_unref` matches the AVFrame ref-counted API and can be used as
a drop in replacement.

Deprecate `av_free_packet`.
2015-10-26 18:00:55 +01:00
Hendrik Leppkes 470204218f Merge commit 'f890677d05bc4e8b494a73373ab4cc19791bf884'
* commit 'f890677d05bc4e8b494a73373ab4cc19791bf884':
  Replace any remaining avpicture function with imgutils

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
2015-10-22 20:48:54 +02:00
Vittorio Giovara f890677d05 Replace any remaining avpicture function with imgutils
avpicture_get_size() -> av_image_get_buffer_size()

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2015-10-21 11:59:59 +02:00
Clément Bœsch 5cae43e718 avdevice/v4l2: use AV_OPT_TYPE_BOOL for use_libv4l2 option 2015-09-12 18:24:49 +02:00
Hendrik Leppkes 87c8812270 Merge commit '01bcc2d5c23fa757d163530abb396fd02f1be7c8'
* commit '01bcc2d5c23fa757d163530abb396fd02f1be7c8':
  lavc: Drop deprecated destruct_packet related functions

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
2015-09-05 16:50:09 +02:00
Vittorio Giovara 01bcc2d5c2 lavc: Drop deprecated destruct_packet related functions
Deprecated in 10/2012.
2015-08-28 16:01:16 +02:00
Carl Eugen Hoyos 4c4f14c717 lavd/v4l2: Use AVSTREAM_PARSE_FULL_ONCE when reading a h264 stream.
Reported, debugged and tested by trac user noah.
Fixes ticket #4644.
2015-08-04 14:59:26 +02:00
Michael Niedermayer 495eee0123 Merge commit '40cf1bbacc6220a0aa6bed5c331871d43f9ce370'
* commit '40cf1bbacc6220a0aa6bed5c331871d43f9ce370':
  Deprecate avctx.coded_frame

Conflicts:
	ffmpeg.c
	libavcodec/a64multienc.c
	libavcodec/asvenc.c
	libavcodec/cljrenc.c
	libavcodec/dpxenc.c
	libavcodec/gif.c
	libavcodec/mpegvideo_enc.c
	libavcodec/nvenc.c
	libavcodec/proresenc_kostya.c
	libavcodec/pthread_frame.c
	libavcodec/rawenc.c
	libavcodec/sunrastenc.c
	libavcodec/tiffenc.c
	libavcodec/version.h
	libavcodec/xbmenc.c
	libavcodec/xwdenc.c
	libavdevice/v4l2.c

Merged-by: Michael Niedermayer <michael@niedermayer.cc>
2015-07-21 01:17:15 +02:00
Vittorio Giovara 40cf1bbacc Deprecate avctx.coded_frame
The rationale is that coded_frame was only used to communicate key_frame,
pict_type and quality to the caller, as well as a few other random fields,
in a non predictable, let alone consistent way.

There was agreement that there was no use case for coded_frame, as it is
a full-sized AVFrame container used for just 2-3 int-sized properties,
which shouldn't even belong into the AVCodecContext in the first place.

The appropriate AVPacket flag can be used instead of key_frame, while
quality is exported with the new AVPacketSideData quality factor.
There is no replacement for the other fields as they were unreliable,
mishandled or just not used at all.

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2015-07-20 15:06:50 +01:00
Michael Niedermayer f8598cefe9 avdevice/v4l2: Fix vertical alignment in list_formats() output
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-05-16 14:35:36 +02:00
Michael Niedermayer d1d8ee5e91 avdevice/v4l2: Try to fix build on netbsd/openbsd
Found-by: James Almer <jamrial@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-05-09 00:27:00 +02:00
Giorgio Vazzana 28f20d2ff4 lavd/v4l2: produce a 0 byte packet when a dequeued buffer is flagged with V4L2_BUF_FLAG_ERROR
Fixes ticket #4030.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-05-08 22:31:09 +02:00
Giorgio Vazzana 23e6cf832f lavd/v4l2: fix typo
This was introduced in cde6e328de

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-05-08 18:02:28 +02:00
Giorgio Vazzana 00a452a9ad lavd/v4l2: print buffer flags in case of error
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-04-24 13:25:40 +02:00
Andreas Cadhalpun 482c86f231 fix spelling errors
opttimizations -> optimizations
 grabing        -> grabbing
 many resource  -> many resources
 isnt           -> isn't
 silcense       -> silence

Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-03-06 21:35:00 +01:00