Commit Graph

18 Commits

Author SHA1 Message Date
Andreas Rheinhardt 636631d9db Remove unnecessary libavutil/(avutil|common|internal).h inclusions
Some of these were made possible by moving several common macros to
libavutil/macros.h.

While just at it, also improve the other headers a bit.

Reviewed-by: Martin Storsjö <martin@martin.st>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-24 12:56:49 +01:00
Andreas Rheinhardt 4e0da7d311 avutil/buffer: Avoid allocation of AVBuffer when using buffer pool
Do this by putting an AVBuffer structure into BufferPoolEntry and
reuse it for all subsequent uses of said BufferPoolEntry.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-18 23:16:49 +02:00
Andreas Rheinhardt ef6a9e5e31 avutil/buffer: Switch AVBuffer API to size_t
Announced in 14040a1d91.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 10:43:13 -03:00
Andreas Rheinhardt 1ad628d2c2 avutil/buffer_internal: Include internal for buffer_size_t
Fixes checkheaders.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-03-11 14:07:15 +01:00
James Almer 14040a1d91 avutil/buffer: change public function and struct size parameter types to size_t
Signed-off-by: James Almer <jamrial@gmail.com>
2021-03-10 20:26:36 -03:00
James Almer b6c8444e23 avutil/buffer: separate public and internal flags inside AVBuffers
It's better to not mix user provided flags and internal flags set by
AVBufferRef helper functions.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-06-05 10:07:05 -03:00
Clément Bœsch 443e969293 Merge commit '27079a426c9d3db918b158976e44b9b143d78e1c'
* commit '27079a426c9d3db918b158976e44b9b143d78e1c':
  buffer: convert to stdatomic

Merged-by: Clément Bœsch <u@pkh.me>
2017-03-22 17:46:01 +01:00
Clément Bœsch 67d8eabdbb lavu/buffer: drop USE_ATOMICS
USE_ATOMICS is only set if there is no thread implementation enabled, in
which case you can't expect any lock mechanism from FFmpeg.

This is also conflicting with the incoming use of stdatomic.
2017-03-22 17:40:03 +01:00
Anton Khirnov 27079a426c buffer: convert to stdatomic 2016-10-02 18:58:04 +02:00
Derek Buitenhuis 26abd5149e Merge commit '721a4efc0545548a241080b53ab480e34f366240'
* commit '721a4efc0545548a241080b53ab480e34f366240':
  buffer: add support for pools using caller data in allocation

Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2016-02-17 16:07:16 +00:00
Anton Khirnov 721a4efc05 buffer: add support for pools using caller data in allocation
This should allow using more complex allocators than simple malloc
wrappers.
2016-02-14 21:24:39 +01:00
Michael Niedermayer 6db8cd8f37 Merge commit 'fbd6c97f9ca858140df16dd07200ea0d4bdc1a83'
* commit 'fbd6c97f9ca858140df16dd07200ea0d4bdc1a83':
  lavu: fix memory leaks by using a mutex instead of atomics

Conflicts:
	libavutil/buffer.c

The atomics code is left in place as a fallback for synchronization in the
absence of p/w32 threads. Our ABI did not requires applications to
only use threads (and matching ones) to what libavutil was build with
Our code also was not affected by the leak this change fixes, though
no question the atomics based implementation is not pretty at all.
First and foremost the code must work, being pretty comes after that.

If this causes problems, for example when libavutil is used by multiple
applications each using a different kind of threading system then the
default possibly has to be changed to the uglier atomics.

See: cea3a63ba3
Merged-by: Michael Niedermayer <michaelni@gmx.at>
2014-11-27 23:42:16 +01:00
wm4 fbd6c97f9c lavu: fix memory leaks by using a mutex instead of atomics
The buffer pool has to atomically add and remove entries from the linked
list of available buffers. This was done by removing the entire list
with a CAS operation, working on it, and then setting it back again
(using a retry-loop in case another thread was doing the same thing).

This could effectively cause memory leaks: while a thread was working on
the buffer list, other threads would allocate new buffers, increasing
the pool's total size. There was no real leak, but since these extra
buffers were not needed, but not free'd either (except when the buffer
pool was destroyed), this had the same effects as a real leak. For some
reason, growth was exponential, and could easily kill the process due
to OOM in real-world uses.

Fix this by using a mutex to protect the list operations. The fancy
way atomics remove the whole list to work on it is not needed anymore,
which also avoids the situation which was causing the leak.

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2014-11-27 13:36:00 +01:00
Michael Niedermayer cea3a63ba3 avutil/buffer: Fix race in pool.
This race will always happen sooner or later in a multi-threaded
environment and it will over time lead to OOM.
This fix works by spinning, there are other ways by which this
can be fixed, like simply detecting the issue after it happened
and freeing the over-allocated memory or simply using a mutex.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-03-18 19:19:22 +01:00
Michael Niedermayer 532f31a695 Merge commit '1cec0624d0e6f48590283a57169b58b9fe8449d3'
* commit '1cec0624d0e6f48590283a57169b58b9fe8449d3':
  AVBuffer: add a new API for buffer pools

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-03-08 16:06:20 +01:00
Michael Niedermayer 36099df521 Merge commit '8e401dbe90cc77b1f3067a917d9fa48cefa3fcdb'
* commit '8e401dbe90cc77b1f3067a917d9fa48cefa3fcdb':
  lavu: add a new API for reference-counted data buffers.

Conflicts:
	libavutil/Makefile

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-03-08 16:01:00 +01:00
Anton Khirnov 1cec0624d0 AVBuffer: add a new API for buffer pools 2013-03-08 07:33:28 +01:00
Anton Khirnov 8e401dbe90 lavu: add a new API for reference-counted data buffers. 2013-03-08 07:33:03 +01:00