Skip to content

Commit

Permalink
utils/dav1d: add Dav1dPicture wrappers
Browse files Browse the repository at this point in the history
Almost identical to the libav helpers, with some code taken from the
boilerplate I wrote for dav1dplay.

Should be fairly comprehensive.
  • Loading branch information
haasn committed Jan 27, 2021
1 parent 519aa43 commit b70170f
Show file tree
Hide file tree
Showing 6 changed files with 690 additions and 6 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,10 @@ identifiers (so they can be freely merged together).
supported by the GPU. (Note: Eventually, this function will also support
on-CPU conversions to a different format where necessary, but for now, it
will just fail)
- `utils/libav.h`: A set of high-level helpers for interoperation between
libplacebo and FFmpeg's libav* abstractions. This is implemented as a single
header library, to avoid libplacebo depending on libavutil directly.
- `utils/dav1d.h`: High level helper for translating between Dav1dPicture
and libplacebo's `pl_frame`. (Single header library)
- `utils/libav.h`: High-level helpers for interoperation between
libplacebo and FFmpeg's libav* abstractions. (Single header library)

This is the "primary" interface to libplacebo, and the one most users will be
interested in. It takes care of internal details such as degrading to simpler
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ project('libplacebo', ['c', 'cpp'],
license: 'LGPL2.1+',
default_options: ['c_std=c99', 'cpp_std=c++11', 'warning_level=2'],
meson_version: '>=0.51',
version: '3.107.0',
version: '3.108.0',
)

# Version number
Expand Down
83 changes: 83 additions & 0 deletions src/include/libplacebo/utils/dav1d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* This file is part of libplacebo.
*
* libplacebo is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* libplacebo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with libplacebo. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef LIBPLACEBO_DAV1D_H_
#define LIBPLACEBO_DAV1D_H_

#include <libplacebo/gpu.h>
#include <libplacebo/utils/upload.h>
#include <dav1d/picture.h>

// Fill in the details of a `pl_frame` from a Dav1dPicture. This function will
// explicitly clear `out_frame`, setting all extra fields to 0. After this
// function returns, the only missing data is information related to the plane
// texture itself (`planes[N].texture`).
static void pl_frame_from_dav1dpicture(struct pl_frame *out_frame,
const Dav1dPicture *picture);

// Very high level helper function to take a `Dav1dPicture` and upload it to
// the GPU. Similar in spirit to `pl_upload_plane`, and the same notes apply.
// `tex` must be an array of 3 pointers of type (const struct pl_tex *), each
// either pointing to a valid texture, or NULL. Returns whether successful.
//
// Note: This is less efficient than `pl_upload_and_unref_dav1dpicture`!
static bool pl_upload_dav1dpicture(const struct pl_gpu *gpu,
struct pl_frame *out_frame,
const struct pl_tex *tex[3],
const Dav1dPicture *picture);

// Variant of `pl_upload_dav1dpicture` that also unrefs the picture after
// uploading. This is needed to take advantage of internal asynchronous
// operations. `picture` will be cleared to {0}, and the internally referenced
// buffers unref'd at some arbitrary time in the future.
//
// Note: If this fails (returns false), the Dav1dPicture does not get unref'd.
static bool pl_upload_and_unref_dav1dpicture(const struct pl_gpu *gpu,
struct pl_frame *out_frame,
const struct pl_tex *tex[3],
Dav1dPicture *picture);

// Allocate a Dav1dPicture from persistently mapped buffers. This can be more
// efficient than regular Dav1dPictures, especially when using the synchronous
// `pl_upload_dav1dpicture`, or on platforms that don't support importing
// PL_HANDLE_HOST_PTR as buffers. Returns 0 or a negative DAV1D_ERR value.
//
// Note: These are *not* thread-safe, and should not be used directly as a
// Dav1dPicAllocator unless wrapped by a thread-safe layer.
static int pl_allocate_dav1dpicture(Dav1dPicture *picture, const struct pl_gpu *gpu);
static void pl_release_dav1dpicture(Dav1dPicture *picture, const struct pl_gpu *gpu);

// Mapping functions for the various Dav1dColor* enums. Note that these are not
// quite 1:1, and even for values that exist in both, the semantics sometimes
// differ. Some special cases (e.g. ICtCp, or XYZ) are handled differently in
// libplacebo and libdav1d, respectively.
static enum pl_color_system pl_system_from_dav1d(enum Dav1dMatrixCoefficients mc);
static enum Dav1dMatrixCoefficients pl_system_to_dav1d(enum pl_color_system sys);
static enum pl_color_levels pl_levels_from_dav1d(int color_range);
static int pl_levels_to_dav1d(enum pl_color_levels levels);
static enum pl_color_primaries pl_primaries_from_dav1d(enum Dav1dColorPrimaries prim);
static enum Dav1dColorPrimaries pl_primaries_to_dav1d(enum pl_color_primaries prim);
static enum pl_color_transfer pl_transfer_from_dav1d(enum Dav1dTransferCharacteristics trc);
static enum Dav1dTransferCharacteristics pl_transfer_to_dav1d(enum pl_color_transfer trc);
static enum pl_chroma_location pl_chroma_from_dav1d(enum Dav1dChromaSamplePosition loc);
static enum Dav1dChromaSamplePosition pl_chroma_to_dav1d(enum pl_chroma_location loc);

// Actual implementation, included as part of this header to avoid having
// a compile-time dependency on libdav1d.
#include <libplacebo/utils/dav1d_internal.h>

#endif // LIBPLACEBO_DAV1D_H_
Loading

0 comments on commit b70170f

Please sign in to comment.