gstreamer/subprojects/gst-plugins-bad
Marek Vasut a0755e5d74 v4l2codecs: Avoid QBUF/DQBUF struct timeval .tv_usec wrap-around at frame 1000000
When decoding stream using hardware V4L2 decoder element, in any of the
currently supported formats, the decoding will fail once frame number
1000000 is reached. The reported error clearly indicates a wrap-around
occured, instead of receiving decoded frame 1000000, frame 0 is received
from the hardware V4L2 decoder driver.

The problem is actually not in the driver itself, but rather in gstreamer,
which uses `struct v4l2_buffer` member `.timestamp` in a special way. The
timestamp of buffers with encoded data added to the SINK (input) queue of
the driver is copied by the driver into matching buffers with decoded data
added to the SOURCE (output) queue of the driver. In fact, the timestamp
is not a timestamp at all, but rather in this special case, only part of
it is used as an incrementing frame counter.

The `.timestamp` is of type `struct timeval`, which is defined in
`sys/time.h` [1]. Only the `tv_usec` member of this structure is used
for the incrementing frame counter. However, suseconds_t tv_usec [2]
may be limited to range [-1, 1000000]:
"
[XSI] The type suseconds_t shall be a signed integer type capable of
      storing values at least in the range [-1, 1000000].
"
Therefore, once frame 1000000 is reached, a rollover occurs and decoding
fails.

Fix this by using both `struct timeval` members, `.tv_sec` and `.tv_usec`
with matching modular arithmetic, this way the failure would occur again
just short of 2^84 frames, which should be plenty.

[1] https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_time.h.html
[2] https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_types.h.html

A test case using stateless hardware h264 decoder, the WARN/ERROR output
in gstreamer log indicates a failure occurred. With this change, that
error no longer occurs and the WARN/ERROR are not present:
```
pc$ gst-launch-1.0 videotestsrc num-buffers=1001001 pattern=6 ! \
                   video/x-raw,width=16,height=16,format=I420 ! \
                   x264enc ! filesink location=/tmp/test.h264

dut$ GST_DEBUG="*:3" gst-launch-1.0 filesrc location=/tmp/test.h264 ! \
                                    h264parse ! v4l2slh264dec ! fakesink
...
0:03:51.393677606 12111     0x370df400 WARN      \
  v4l2codecs-decoder gstv4l2decoder.c:1157:gst_v4l2_request_set_done:<v4l2decoder2> \
  Requested frame 1000000, but driver returned frame 0.
0:03:51.394140597 12111     0x370df400 WARN      \
  v4l2codecs-decoder gstv4l2decoder.c:1157:gst_v4l2_request_set_done:<v4l2decoder2> \
  Requested frame 1000001, but driver returned frame 1.
0:03:51.394425216 12111     0x370df400 WARN      \
  v4l2codecs-decoder gstv4l2decoder.c:1157:gst_v4l2_request_set_done:<v4l2decoder2> \
  Requested frame 1000002, but driver returned frame 2.
0:03:51.394665211 12111     0x370df400 WARN      \
  v4l2codecs-decoder gstv4l2decoder.c:1157:gst_v4l2_request_set_done:<v4l2decoder2> \
  Requested frame 1000003, but driver returned frame 3.
0:03:51.394785833 12111     0x370df400 WARN      \
  v4l2codecs-h264dec gstv4l2codech264dec.c:1059:gst_v4l2_codec_h264_dec_output_picture:<v4l2slh264dec0> \
  error: Failed to decode frame 1000000
ERROR: from element /GstPipeline:pipeline0/v4l2slh264dec:v4l2slh264dec0: Failed to decode frame 1000000
```

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5603>
2023-11-04 16:59:51 +00:00
..
data devenv: Add some missing GStreamer specific env variables 2022-02-25 20:35:26 +00:00
docs decklink: fix 10 bit RGB (r210) format auto detection 2023-04-05 10:38:45 +00:00
ext openh264: Fail gracefully if openh264 encoder/decoder creation fails 2023-11-01 17:10:01 +00:00
gst tsmux: Fix default get_es_descrs_func 2023-10-20 08:53:19 +00:00
gst-libs codecs: h265: Do not free slice header before using it 2023-10-18 00:17:54 +00:00
po gst-plugins-bad: update translations 2023-02-22 13:19:58 +00:00
scripts Fix translation pot files when creating dist tarballs 2023-01-11 19:20:17 +00:00
sys v4l2codecs: Avoid QBUF/DQBUF struct timeval .tv_usec wrap-around at frame 1000000 2023-11-04 16:59:51 +00:00
tests h265parse: Allow partially broken hvcC data 2023-08-23 11:20:33 +00:00
tools taglist, plugins: fix compiler warnings with GLib >= 2.76 2023-07-12 08:58:50 +00:00
.gitignore Move files from gst-plugins-bad into the "subprojects/gst-plugins-bad/" subdir 2021-09-24 16:14:36 -03:00
AUTHORS Move files from gst-plugins-bad into the "subprojects/gst-plugins-bad/" subdir 2021-09-24 16:14:36 -03:00
COPYING Move files from gst-plugins-bad into the "subprojects/gst-plugins-bad/" subdir 2021-09-24 16:14:36 -03:00
gst-plugins-bad.doap Release 1.22.6 2023-09-20 18:10:57 +01:00
MAINTAINERS Move files from gst-plugins-bad into the "subprojects/gst-plugins-bad/" subdir 2021-09-24 16:14:36 -03:00
meson.build Back to development 2023-09-20 19:41:00 +01:00
meson_options.txt win32ipc: Add WIN32 shared memory videosrc/sink elements 2022-11-24 12:41:18 +00:00
NEWS Release 1.22.6 2023-09-20 18:10:57 +01:00
README.md Release 1.22.3 2023-05-19 09:23:19 +01:00
README.static-linking Move files from gst-plugins-bad into the "subprojects/gst-plugins-bad/" subdir 2021-09-24 16:14:36 -03:00
RELEASE Release 1.22.6 2023-09-20 18:10:57 +01:00
REQUIREMENTS mms: remove mmssrc plugin 2021-10-20 17:05:34 +00:00

GStreamer 1.22.x stable series

WHAT IT IS

This is GStreamer, a framework for streaming media.

WHERE TO START

We have a website at

https://gstreamer.freedesktop.org

Our documentation, including tutorials, API reference and FAQ can be found at

https://gstreamer.freedesktop.org/documentation/

You can subscribe to our mailing lists:

https://lists.freedesktop.org/mailman/listinfo/gstreamer-announce

https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

We track bugs, feature requests and merge requests (patches) in GitLab at

https://gitlab.freedesktop.org/gstreamer/

You can join us on IRC - #gstreamer on irc.oftc.net

GStreamer 1.0 series

Starring

GSTREAMER

The core around which all other modules revolve. Base functionality and libraries, some essential elements, documentation, and testing.

BASE

A well-groomed and well-maintained collection of GStreamer plug-ins and elements, spanning the range of possible types of elements one would want to write for GStreamer.

And introducing, for the first time ever, on the development screen ...

THE GOOD

--- "Such ingratitude. After all the times I've saved your life."

A collection of plug-ins you'd want to have right next to you on the battlefield. Shooting sharp and making no mistakes, these plug-ins have it all: good looks, good code, and good licensing. Documented and dressed up in tests. If you're looking for a role model to base your own plug-in on, here it is.

If you find a plot hole or a badly lip-synced line of code in them, let us know - it is a matter of honour for us to ensure Blondie doesn't look like he's been walking 100 miles through the desert without water.

THE UGLY

--- "When you have to shoot, shoot. Don't talk."

There are times when the world needs a color between black and white. Quality code to match the good's, but two-timing, backstabbing and ready to sell your freedom down the river. These plug-ins might have a patent noose around their neck, or a lock-up license, or any other problem that makes you think twice about shipping them.

We don't call them ugly because we like them less. Does a mother love her son less because he's not as pretty as the other ones ? No - she commends him on his great personality. These plug-ins are the life of the party. And we'll still step in and set them straight if you report any unacceptable behaviour - because there are two kinds of people in the world, my friend: those with a rope around their neck and the people who do the cutting.

THE BAD

--- "That an accusation?"

No perfectly groomed moustache or any amount of fine clothing is going to cover up the truth - these plug-ins are Bad with a capital B. They look fine on the outside, and might even appear to get the job done, but at the end of the day they're a black sheep. Without a golden-haired angel to watch over them, they'll probably land in an unmarked grave at the final showdown.

Don't bug us about their quality - exercise your Free Software rights, patch up the offender and send us the patch on the fastest steed you can steal from the Confederates. Because you see, in this world, there's two kinds of people, my friend: those with loaded guns and those who dig. You dig.

The Lowdown

--- "I've never seen so many plug-ins wasted so badly."

GStreamer Plug-ins has grown so big that it's hard to separate the wheat from the chaff. Also, distributors have brought up issues about the legal status of some of the plug-ins we ship. To remedy this, we've divided the previous set of available plug-ins into four modules:

  • gst-plugins-base: a small and fixed set of plug-ins, covering a wide range of possible types of elements; these are continuously kept up-to-date with any core changes during the development series.

    • We believe distributors can safely ship these plug-ins.
    • People writing elements should base their code on these elements.
    • These elements come with examples, documentation, and regression tests.
  • gst-plugins-good: a set of plug-ins that we consider to have good quality code, correct functionality, our preferred license (LGPL for the plug-in code, LGPL or LGPL-compatible for the supporting library).

    • We believe distributors can safely ship these plug-ins.
    • People writing elements should base their code on these elements.
  • gst-plugins-ugly: a set of plug-ins that have good quality and correct functionality, but distributing them might pose problems. The license on either the plug-ins or the supporting libraries might not be how we'd like. The code might be widely known to present patent problems.

    • Distributors should check if they want/can ship these plug-ins.
    • People writing elements should base their code on these elements.
  • gst-plugins-bad: a set of plug-ins that aren't up to par compared to the rest. They might be close to being good quality, but they're missing something - be it a good code review, some documentation, a set of tests, a real live maintainer, or some actual wide use. If the blanks are filled in they might be upgraded to become part of either gst-plugins-good or gst-plugins-ugly, depending on the other factors.

    • If the plug-ins break, you can't complain - instead, you can fix the problem and send us a patch, or bribe someone into fixing them for you.
    • New contributors can start here for things to work on.

PLATFORMS

  • Linux is of course fully supported
  • FreeBSD is reported to work; other BSDs should work too; same for Solaris
  • MacOS works, binary 1.x packages can be built using the cerbero build tool
  • Windows works; binary 1.x packages can be built using the cerbero build tool
    • MSys/MinGW builds
    • Microsoft Visual Studio builds are also available and supported
  • Android works, binary 1.x packages can be built using the cerbero build tool
  • iOS works

INSTALLING FROM PACKAGES

You should always prefer installing from packages first. GStreamer is well-maintained for a number of distributions, including Fedora, Debian, Ubuntu, Mandrake, Arch Linux, Gentoo, ...

Only in cases where you:

  • want to hack on GStreamer
  • want to verify that a bug has been fixed
  • do not have a sane distribution

should you choose to build from source tarballs or git.

Find more information about the various packages at

https://gstreamer.freedesktop.org/download/

For in-depth instructions about building GStreamer visit: getting-started.

PLUG-IN DEPENDENCIES AND LICENSES

GStreamer is developed under the terms of the LGPL (see COPYING file for details). Some of our plug-ins however rely on libraries which are available under other licenses. This means that if you are distributing an application which has a non-GPL compatible license (for instance a closed-source application) with GStreamer, you have to make sure not to distribute GPL-linked plug-ins.

When using GPL-linked plug-ins, GStreamer is for all practical reasons under the GPL itself.

HISTORY

The fundamental design comes from the video pipeline at Oregon Graduate Institute, as well as some ideas from DirectMedia. It's based on plug-ins that will provide the various codec and other functionality. The interface hopefully is generic enough for various companies (ahem, Apple) to release binary codecs for Linux, until such time as they get a clue and release the source.