mirror of
https://github.com/mpv-player/mpv
synced 2025-01-03 13:32:16 +00:00
hwdec: add mediacodec hardware decoder for IMGFMT_MEDIACODEC frames
This commit is contained in:
parent
6f0fdac6f1
commit
61a1612de9
@ -681,6 +681,7 @@ Video
|
||||
:d3d11va: requires ``--vo=gpu`` with ``--gpu-context=angle``
|
||||
(Windows 8+ only)
|
||||
:d3d11va-copy: copies video back to system RAM (Windows 8+ only)
|
||||
:mediacodec: requires ``--vo=mediacodec_embed`` (Android only)
|
||||
:mediacodec-copy: copies video back to system RAM (Android only)
|
||||
:rpi: requires ``--vo=gpu`` (Raspberry Pi only - default if available)
|
||||
:rpi-copy: copies video back to system RAM (Raspberry Pi only)
|
||||
@ -2480,6 +2481,10 @@ Window
|
||||
support window embedding of foreign processes, this works only with libmpv,
|
||||
and will crash when used from the command line.
|
||||
|
||||
On Android, the ID is interpreted as ``android.view.Surface``. Pass it as a
|
||||
value cast to ``intptr_t``. Use with ``--vo=mediacodec_embed`` and
|
||||
``--hwdec=mediacodec`` for direct rendering using MediaCodec.
|
||||
|
||||
``--no-window-dragging``
|
||||
Don't move the window when clicking on it and moving the mouse pointer.
|
||||
|
||||
|
@ -111,6 +111,7 @@ const struct m_opt_choice_alternatives mp_hwdec_names[] = {
|
||||
{"d3d11va-copy",HWDEC_D3D11VA_COPY},
|
||||
{"rpi", HWDEC_RPI},
|
||||
{"rpi-copy", HWDEC_RPI_COPY},
|
||||
{"mediacodec", HWDEC_MEDIACODEC},
|
||||
{"mediacodec-copy",HWDEC_MEDIACODEC_COPY},
|
||||
{"cuda", HWDEC_CUDA},
|
||||
{"cuda-copy", HWDEC_CUDA_COPY},
|
||||
|
@ -15,8 +15,55 @@
|
||||
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <libavcodec/mediacodec.h>
|
||||
|
||||
#include "options/options.h"
|
||||
#include "video/decode/lavc.h"
|
||||
|
||||
static int probe(struct lavc_ctx *ctx, struct vd_lavc_hwdec *hwdec,
|
||||
const char *codec)
|
||||
{
|
||||
if (ctx->opts->vo->WinID == 0)
|
||||
return HWDEC_ERR_NO_CTX;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int init(struct lavc_ctx *ctx)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int init_decoder(struct lavc_ctx *ctx, int w, int h)
|
||||
{
|
||||
av_mediacodec_default_free(ctx->avctx);
|
||||
|
||||
AVMediaCodecContext *mcctx = av_mediacodec_alloc_context();
|
||||
if (!mcctx)
|
||||
return -1;
|
||||
|
||||
void *surface = (void *)(intptr_t)(ctx->opts->vo->WinID);
|
||||
return av_mediacodec_default_init(ctx->avctx, mcctx, surface);
|
||||
}
|
||||
|
||||
static void uninit(struct lavc_ctx *ctx)
|
||||
{
|
||||
if (ctx->avctx)
|
||||
av_mediacodec_default_free(ctx->avctx);
|
||||
}
|
||||
|
||||
const struct vd_lavc_hwdec mp_vd_lavc_mediacodec = {
|
||||
.type = HWDEC_MEDIACODEC,
|
||||
.image_format = IMGFMT_MEDIACODEC,
|
||||
.lavc_suffix = "_mediacodec",
|
||||
.probe = probe,
|
||||
.init = init,
|
||||
.init_decoder = init_decoder,
|
||||
.uninit = uninit,
|
||||
};
|
||||
|
||||
const struct vd_lavc_hwdec mp_vd_lavc_mediacodec_copy = {
|
||||
.type = HWDEC_MEDIACODEC_COPY,
|
||||
.lavc_suffix = "_mediacodec",
|
||||
|
@ -129,6 +129,7 @@ const struct m_sub_options vd_lavc_conf = {
|
||||
},
|
||||
};
|
||||
|
||||
extern const struct vd_lavc_hwdec mp_vd_lavc_mediacodec;
|
||||
extern const struct vd_lavc_hwdec mp_vd_lavc_mediacodec_copy;
|
||||
extern const struct vd_lavc_hwdec mp_vd_lavc_videotoolbox;
|
||||
extern const struct vd_lavc_hwdec mp_vd_lavc_videotoolbox_copy;
|
||||
@ -261,6 +262,7 @@ static const struct vd_lavc_hwdec *const hwdec_list[] = {
|
||||
&mp_vd_lavc_d3d11va_copy,
|
||||
#endif
|
||||
#if HAVE_ANDROID
|
||||
&mp_vd_lavc_mediacodec,
|
||||
&mp_vd_lavc_mediacodec_copy,
|
||||
#endif
|
||||
#if HAVE_CUDA_HWACCEL
|
||||
|
@ -60,6 +60,9 @@ static const struct {
|
||||
{IMGFMT_VDPAU, AV_PIX_FMT_VDPAU},
|
||||
#if HAVE_VIDEOTOOLBOX_HWACCEL
|
||||
{IMGFMT_VIDEOTOOLBOX, AV_PIX_FMT_VIDEOTOOLBOX},
|
||||
#endif
|
||||
#if HAVE_ANDROID
|
||||
{IMGFMT_MEDIACODEC, AV_PIX_FMT_MEDIACODEC},
|
||||
#endif
|
||||
{IMGFMT_VAAPI, AV_PIX_FMT_VAAPI},
|
||||
{IMGFMT_DXVA2, AV_PIX_FMT_DXVA2_VLD},
|
||||
|
@ -22,6 +22,7 @@ enum hwdec_type {
|
||||
HWDEC_D3D11VA_COPY,
|
||||
HWDEC_RPI,
|
||||
HWDEC_RPI_COPY,
|
||||
HWDEC_MEDIACODEC,
|
||||
HWDEC_MEDIACODEC_COPY,
|
||||
HWDEC_CUDA,
|
||||
HWDEC_CUDA_COPY,
|
||||
|
@ -203,6 +203,7 @@ enum mp_imgfmt {
|
||||
IMGFMT_DXVA2, // IDirect3DSurface9 (NV12/P010/P016)
|
||||
IMGFMT_MMAL, // MMAL_BUFFER_HEADER_T
|
||||
IMGFMT_VIDEOTOOLBOX, // CVPixelBufferRef
|
||||
IMGFMT_MEDIACODEC, // AVMediaCodecBuffer
|
||||
|
||||
IMGFMT_CUDA, // CUDA Buffer
|
||||
// Generic pass-through of AV_PIX_FMT_*. Used for formats which don't have
|
||||
|
Loading…
Reference in New Issue
Block a user