1 /*****************************************************************************
2 * hwdummy.c: dummy hardware decoding acceleration plugin for VLC/libav
3 *****************************************************************************
4 * Copyright (C) 2013 RĂ©mi Denis-Courmont
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
29 #include <libavutil/mem.h>
30 #include <libavcodec/avcodec.h>
31 #include <libavcodec/vdpau.h>
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_fourcc.h>
35 #include <vlc_picture.h>
36 #include "../../codec/avcodec/va.h"
38 static int Open(vlc_va_t *, AVCodecContext *, const es_format_t *);
39 static void Close(vlc_va_t *);
42 set_description(N_("Dummy video decoder"))
43 set_capability("hw decoder", 0)
44 set_category(CAT_INPUT)
45 set_subcategory(SUBCAT_INPUT_VCODEC)
46 set_callbacks(Open, Close)
50 #define DECODER_MAGIC 0xdec0dea0
51 #define DATA_MAGIC 0xda1a0000
52 #define OPAQUE_MAGIC 0x0da00e00
54 static int Lock(vlc_va_t *va, void **opaque, uint8_t **data)
56 *data = (void *)(uintptr_t)DATA_MAGIC;
57 *opaque = (void *)(uintptr_t)OPAQUE_MAGIC;
62 static void Unlock(void *opaque, uint8_t *data)
64 assert((uintptr_t)opaque == OPAQUE_MAGIC);
65 assert((uintptr_t)data == DATA_MAGIC);
68 static VdpStatus Render(VdpDecoder decoder, VdpVideoSurface target,
69 VdpPictureInfo const *picture_info,
70 uint32_t bitstream_buffer_count,
71 VdpBitstreamBuffer const *bitstream_buffers)
73 (void) decoder; (void) target; (void) picture_info;
74 (void) bitstream_buffer_count; (void) bitstream_buffers;
75 assert(decoder == DECODER_MAGIC);
76 assert(target == DATA_MAGIC);
80 static int Copy(vlc_va_t *va, picture_t *pic, void *opaque, uint8_t *data)
84 assert((uintptr_t)opaque == OPAQUE_MAGIC);
85 assert((uintptr_t)data == DATA_MAGIC);
87 /* Put some dummy picture content */
88 memset(pic->p[0].p_pixels, 0xF0,
89 pic->p[0].i_pitch * pic->p[0].i_visible_lines);
90 for (int i = 0; i < pic->p[1].i_visible_lines; i++)
91 memset(pic->p[1].p_pixels + (i * pic->p[1].i_pitch), i,
92 pic->p[1].i_visible_pitch);
93 for (int i = 0; i < pic->p[2].i_visible_lines; i++)
94 for (int j = 0; j < pic->p[2].i_visible_pitch; j++)
95 pic->p[2].p_pixels[(i * pic->p[2].i_pitch) + j] = j;
99 static int Setup(vlc_va_t *va, void **ctxp, vlc_fourcc_t *chromap,
100 int width, int height)
102 (void) width; (void) height;
103 *ctxp = (AVVDPAUContext *)va->sys;
104 *chromap = VLC_CODEC_YV12;
108 static int Open(vlc_va_t *va, AVCodecContext *ctx, const es_format_t *fmt)
114 } u = { .fourcc = fmt->i_codec };
116 AVVDPAUContext *hwctx = av_vdpau_alloc_context();
117 if (unlikely(hwctx == NULL))
120 msg_Dbg(va, "codec %d (%4.4s) profile %d level %d", ctx->codec_id, u.str,
121 fmt->i_profile, fmt->i_level);
123 hwctx->decoder = DECODER_MAGIC;
124 hwctx->render = Render;
126 va->sys = (vlc_va_sys_t *)hwctx;
127 va->description = "Dummy video decoding accelerator";
128 va->pix_fmt = AV_PIX_FMT_VDPAU;
131 va->release = Unlock;
136 static void Close(vlc_va_t *va)