/*
* This file is part of FFmpeg.
*
* FFmpeg 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.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "stdafx.h"
#include <d3d9.h>
#include<d3dx9.h>
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")
#include <dxva2api.h>
#include "ffmpeg_dxva2.h"
extern "C"
{
#include "libavcodec/dxva2.h"
#include "libavutil/avassert.h"
#include "libavutil/buffer.h"
#include "libavutil/frame.h"
#include "libavutil/imgutils.h"
#include "libavutil/pixfmt.h"
}
/* define all the GUIDs used directly here,
to avoid problems with inconsistent dxva2api.h versions in mingw-w64 and different MSVC version */
#include <initguid.h>
DEFINE_GUID(IID_IDirectXVideoDecoderService, 0xfc51a551, 0xd5e7, 0x11d9, 0xaf, 0x55, 0x00, 0x05, 0x4e, 0x43, 0xff, 0x02);
DEFINE_GUID(DXVA2_ModeMPEG2_VLD, 0xee27417f, 0x5e28, 0x4e65, 0xbe, 0xea, 0x1d, 0x26, 0xb5, 0x08, 0xad, 0xc9);
DEFINE_GUID(DXVA2_ModeMPEG2and1_VLD, 0x86695f12, 0x340e, 0x4f04, 0x9f, 0xd3, 0x92, 0x53, 0xdd, 0x32, 0x74, 0x60);
DEFINE_GUID(DXVA2_ModeH264_E, 0x1b81be68, 0xa0c7, 0x11d3, 0xb9, 0x84, 0x00, 0xc0, 0x4f, 0x2e, 0x73, 0xc5);
DEFINE_GUID(DXVA2_ModeH264_F, 0x1b81be69, 0xa0c7, 0x11d3, 0xb9, 0x84, 0x00, 0xc0, 0x4f, 0x2e, 0x73, 0xc5);
DEFINE_GUID(DXVADDI_Intel_ModeH264_E, 0x604F8E68, 0x4951, 0x4C54, 0x88, 0xFE, 0xAB, 0xD2, 0x5C, 0x15, 0xB3, 0xD6);
DEFINE_GUID(DXVA2_ModeVC1_D, 0x1b81beA3, 0xa0c7, 0x11d3, 0xb9, 0x84, 0x00, 0xc0, 0x4f, 0x2e, 0x73, 0xc5);
DEFINE_GUID(DXVA2_ModeVC1_D2010, 0x1b81beA4, 0xa0c7, 0x11d3, 0xb9, 0x84, 0x00, 0xc0, 0x4f, 0x2e, 0x73, 0xc5);
DEFINE_GUID(DXVA2_ModeHEVC_VLD_Main, 0x5b11d51b, 0x2f4c, 0x4452, 0xbc, 0xc3, 0x09, 0xf2, 0xa1, 0x16, 0x0c, 0xc0);
DEFINE_GUID(DXVA2_ModeHEVC_VLD_Main10, 0x107af0e0, 0xef1a, 0x4d19, 0xab, 0xa8, 0x67, 0xa1, 0x63, 0x07, 0x3d, 0x13);
DEFINE_GUID(DXVA2_ModeVP9_VLD_Profile0, 0x463707f8, 0xa1d0, 0x4585, 0x87, 0x6d, 0x83, 0xaa, 0x6d, 0x60, 0xb8, 0x9e);
DEFINE_GUID(DXVA2_NoEncrypt, 0x1b81beD0, 0xa0c7, 0x11d3, 0xb9, 0x84, 0x00, 0xc0, 0x4f, 0x2e, 0x73, 0xc5);
DEFINE_GUID(GUID_NULL, 0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
typedef IDirect3D9* WINAPI pDirect3DCreate9(UINT);
typedef HRESULT WINAPI pCreateDeviceManager9(UINT *, IDirect3DDeviceManager9 **);
CRITICAL_SECTION cs;
typedef struct dxva2_mode {
const GUID *guid;
enum AVCodecID codec;
} dxva2_mode;
static const dxva2_mode dxva2_modes[] = {
/* MPEG-2 */
{ &DXVA2_ModeMPEG2_VLD, AV_CODEC_ID_MPEG2VIDEO },
{ &DXVA2_ModeMPEG2and1_VLD, AV_CODEC_ID_MPEG2VIDEO },
/* H.264 */
{ &DXVA2_ModeH264_F, AV_CODEC_ID_H264 },
{ &DXVA2_ModeH264_E, AV_CODEC_ID_H264 },
/* Intel specific H.264 mode */
{ &DXVADDI_Intel_ModeH264_E, AV_CODEC_ID_H264 },
/* VC-1 / WMV3 */
{ &DXVA2_ModeVC1_D2010, AV_CODEC_ID_VC1 },
{ &DXVA2_ModeVC1_D2010, AV_CODEC_ID_WMV3 },
{ &DXVA2_ModeVC1_D, AV_CODEC_ID_VC1 },
{ &DXVA2_ModeVC1_D, AV_CODEC_ID_WMV3 },
/* HEVC/H.265 */
{ &DXVA2_ModeHEVC_VLD_Main, AV_CODEC_ID_HEVC },
{ &DXVA2_ModeHEVC_VLD_Main10, AV_CODEC_ID_HEVC },
/* VP8/9 */
{ &DXVA2_ModeVP9_VLD_Profile0, AV_CODEC_ID_VP9 },
{ NULL, AV_CODEC_ID_NONE },
};
typedef struct surface_info {
int used;
uint64_t age;
} surface_info;
typedef struct DXVA2Context {
HMODULE d3dlib;
HMODULE dxva2lib;
HANDLE deviceHandle;
IDirect3D9 *d3d9;
IDirect3DDevice9 *d3d9device;
IDirect3DDeviceManager9 *d3d9devmgr;
IDirectXVideoDecoderService *decoder_service;
IDirectXVideoDecoder *decoder;
GUID decoder_guid;
DXVA2_ConfigPictureDecode decoder_config;
LPDIRECT3DSURFACE9 *surfaces;
surface_info *surface_infos;
uint32_t num_surfaces;
uint64_t surface_age;
AVFrame *tmp_frame;
} DXVA2Context;
typedef struct DXVA2SurfaceWrapper {
DXVA2Context *ctx;
LPDIRECT3DSURFACE9 surface;
IDirectXVideoDecoder *decoder;
} DXVA2SurfaceWrapper;
typedef struct Dxva2TexVertex
{
Dxva2TexVertex(float x, float y, float z,
float u0, float v0,
float u1, float v1,
float u2, float v2)
{
_x = x; _y = y; _z = z;
_u0 = u0; _v0 = v0;
_u1 = u1; _v1 = v1;
_u2 = u2, _v2 = v2;
}
float _x, _y, _z;
float _u0, _v0;
float _u1, _v1;
float _u2, _v2;
static const DWORD FVF ;
};
const DWORD Dxva2TexVertex::FVF = D3DFVF_XYZ | D3DFVF_TEX3;
typedef struct
{
FLOAT x,y,z; // vertex untransformed position
FLOAT rhw; // eye distance
D3DCOLOR diffuse; // diffuse color
FLOAT tu, tv; // texture relative coordinates
} CUSTOMVERTEX;
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1)
IDirect3DVertexBuffer9* QuadVB ;
static void dxva2_destroy_decoder(AVCodecContext *s)
{
InputStream *ist = (InputStream *)s->opaque;
DXVA2Context *ctx = (DXVA2Context *)ist->hwaccel_ctx;
int i;
if (ctx->surfaces) {
for (i = 0; i < ctx->num_surfaces; i++) {
if (ctx->surfaces[i])
IDirect3DSurface9_Release(ctx->surfaces[i]);
}
}
av_freep(&ctx->surfaces);
av_freep(&ctx->surface_infos);
ctx->num_surfaces = 0;
ctx->surface_age = 0;
if (ctx->decoder) {
ctx->decoder->Release();
ctx->decoder = NULL;
}
}
void dxva2_uninit(AVCodecContext *s)
{
InputStream *ist = (InputStream *)s->opaque;
if (!ist)
{
return ;
}
DXVA2Context *ctx = (DXVA2Context *)ist->hwaccel_ctx;
if (!ctx)
{
return ;
}
ist->hwaccel_uninit = NULL;
ist->hwaccel_get_buffer = NULL;
ist->hwaccel_retrieve_data = NULL;
if (ctx->decoder)
dxva2_destroy_decoder(s);
if (ctx->decoder_service)
ctx->decoder_service->Release();
if (ctx->d3d9devmgr && ctx->deviceHandle != INVALID_HANDLE_VALUE)
ctx->d3d9devmgr->CloseDeviceHandle(ctx->deviceHandle);
if (ctx->d3d9devmgr)
ctx->d3d9devmgr->Release();
if (ctx->d3d9device)
IDirect3DDevice9_Release(ctx->d3d9device);
if (ctx->d3d9)
IDirect3D9_Release(ctx->d3d9);
if (ctx->d3dlib)
FreeLibrary(ctx->d3dlib);
if (ctx->dxva2lib)
FreeLibrary(ctx->dxva2lib);
av_frame_free(&ctx->tmp_frame);
av_freep(&ist->hwaccel_ctx);
av_freep(&s->hwaccel_context);
DeleteCriticalSection(&cs);
}
static void dxva2_release_buffer(void *opaque, uint8_t *data)
{
DXVA2SurfaceWrapper *w = (DXVA2SurfaceWrapper *)opaque;
DXVA2Context *ctx = w->ctx;
int i;
for (i = 0; i < ctx->num_surfaces; i++) {
if (ctx->surfaces[i] == w->surface) {
ctx->surface_infos[i].used = 0;
break;
}
}
IDirect3DSurface9_Release(w->surface);
w->decoder->Release();
av_free(w);
}
static int dxva2_get_buffer(AVCodecContext *s, AVFrame *frame, int flags)
{
InputStream *ist = (InputStream *)s->opaque;
DXVA2Context *ctx = (DXVA2Context *)ist->hwaccel_ctx;
int i, old_unused = -1;
LPDIRECT3DSURFACE9 surface;
DXVA2SurfaceWrapper *w = NULL;
av_assert0(frame->format == A
没有合适的资源?快使用搜索试试~ 我知道了~
DXVA2解码数据用texture纹理渲染
共377个文件
h:300个
lib:45个
dll:8个
4星 · 超过85%的资源 需积分: 50 171 下载量 34 浏览量
2017-01-20
21:34:40
上传
评论 2
收藏 18.75MB ZIP 举报
温馨提示
FFmpeg DXVA2解码得到的数据使用surface来承载的,surface限制很多,如果能用纹理来渲染的话,那我们就可以充分开发D3D,比如可以用坐标变换来实现电子放大的功能,还可以用坐标变换来实现视频图像任意角度的旋转等功能。而对于我来说,最重要的是纹理渲染可以使得解码后的数据能够用像素着色器来做简单的视频图像处理,如果是用的是D3D11,对于更为复杂的视频图像处理算法也是有望可以用Compute Shader实现,以便充分利用显卡来加速和释放CPU。
资源推荐
资源详情
资源评论
收起资源包目录
DXVA2解码数据用texture纹理渲染 (377个子文件)
MyDxva2.aps 10KB
ffmpeg_dxva2.cpp 24KB
D3DVidRender.cpp 10KB
MyDxva2.cpp 9KB
SShellNotifyIcon.cpp 3KB
SouiRealWndHandler.cpp 2KB
stdafx.cpp 213B
avcodec-57.dll 23.42MB
avformat-57.dll 4.71MB
avfilter-6.dll 3.67MB
avdevice-57.dll 1.25MB
avutil-55.dll 550KB
swscale-4.dll 498KB
swresample-2.dll 283KB
postproc-54.dll 108KB
MyDxva2.exe 78KB
MyDxva2.vcxproj.filters 2KB
SDL_opengl_glext.h 714KB
D3D11.h 365KB
ddraw.h 241KB
D2D1.h 237KB
D3D10.h 228KB
dinput.h 222KB
strsafe.h 216KB
DWrite.h 207KB
avcodec.h 201KB
d3d9.h 160KB
dxtrans.h 155KB
d3dx9mesh.h 125KB
D3D11SDKLayers.h 119KB
xnamath.h 113KB
dsound.h 111KB
avformat.h 109KB
dmusici.h 105KB
SDL_opengles2_gl2ext.h 96KB
d3d9types.h 88KB
d3d10sdklayers.h 87KB
d3d.h 86KB
dplay.h 85KB
DXGI.h 81KB
SDL_opengl.h 80KB
d3dtypes.h 78KB
d3drmobj.h 78KB
xact3.h 77KB
xact.h 77KB
dmusicf.h 73KB
SDL_egl.h 72KB
d3d8.h 71KB
D3D10_1.h 71KB
D3D10effect.h 70KB
dplay8.h 69KB
xaudio2.h 62KB
d3d8types.h 62KB
D3DX10math.h 61KB
d3dx9tex.h 60KB
d3dx9math.h 58KB
d3dx9anim.h 42KB
d3dx9effect.h 41KB
avfilter.h 40KB
d3dx9shader.h 38KB
SDL_video.h 38KB
SDL_haptic.h 38KB
dmusicc.h 35KB
opt.h 35KB
XAPO.h 34KB
dvoice.h 34KB
XDSP.h 34KB
SDL_render.h 33KB
dvp.h 32KB
dinputd.h 32KB
xma2defs.h 32KB
SDL_opengles2_gl2.h 31KB
D3D10shader.h 31KB
pixfmt.h 31KB
dplobby.h 29KB
avio.h 29KB
rpcsal.h 29KB
SDL_hints.h 28KB
SDL_events.h 27KB
dmerror.h 27KB
D3DX11tex.h 26KB
D3DX10tex.h 26KB
d3dcaps.h 26KB
D2D1Helper.h 25KB
d3d9caps.h 24KB
SDL_audio.h 24KB
gameux.h 24KB
frame.h 24KB
d3drmdef.h 24KB
d3dx9core.h 23KB
X3DAudio.h 22KB
xaudio2fx.h 21KB
swresample.h 20KB
dplobby8.h 19KB
SDL_surface.h 18KB
intreadwrite.h 18KB
SDL_stdinc.h 18KB
avdevice.h 18KB
XAPOBase.h 17KB
rmxftmpl.h 17KB
共 377 条
- 1
- 2
- 3
- 4
betterwgo
- 粉丝: 18
- 资源: 21
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页