/*
* 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 <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"
}
typedef struct {
const char *name;
D3DFORMAT format;
AVPixelFormat codec;
} d3d_format_t;
/* XXX Prefered format must come first */
static const d3d_format_t d3d_formats[] = {
{ "YV12", (D3DFORMAT)MAKEFOURCC('Y', 'V', '1', '2'), AV_PIX_FMT_YUV420P },
{ "NV12", (D3DFORMAT)MAKEFOURCC('N', 'V', '1', '2'), AV_PIX_FMT_NV12 },
{ NULL, (D3DFORMAT)0, AV_PIX_FMT_NONE }
};
/* 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;
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) {
//IDirectXVideoDecoder_Release(ctx->decoder);
ctx->decoder->Release();
ctx->decoder = NULL;
}
}
static void dxva2_uninit(AVCodecContext *s)
{
InputStream *ist = (InputStream *)s->opaque;
DXVA2Context *ctx = (DXVA2Context *)ist->hwaccel_ctx;
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)
//IDirectXVideoDecoderService_Release(ctx->decoder_service);
ctx->decoder_service->Release();
if (ctx->d3d9devmgr && ctx->deviceHandle != INVALID_HANDLE_VALUE)
//IDirect3DDeviceManager9_CloseDeviceHandle(ctx->d3d9devmgr, ctx->deviceHandle);
ctx->d3d9devmgr->CloseDeviceHandle(ctx->deviceHandle);
if (ctx->d3d9devmgr)
//IDirect3DDeviceManager9_Release(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);
//IDirectXVideoDecoder_Release(w->decoder);
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 == AV_PIX_FMT_DXVA2_VLD);
for (i = 0; i < ctx->num_surfaces; i++) {
surface_info *info = &ctx->surface_infos[i];
if (!info->used && (old_unused == -1 || info->age < ctx->surface_infos[old_un
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
ffmpeg实现dxva2硬件加速 (401个子文件)
ffmpeg_dxva2.cpp 23KB
Win32Project1.cpp 10KB
D3DVidRender.cpp 10KB
SShellNotifyIcon.cpp 3KB
SouiRealWndHandler.cpp 2KB
stdafx.cpp 219B
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
Win32Project1.exe 98KB
Win32Project1.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
xact3wb.h 17KB
共 401 条
- 1
- 2
- 3
- 4
- 5
betterwgo
- 粉丝: 18
- 资源: 21
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- HTML+CSS+JS网页设计:从入门到精通.zip
- 数据库课程设计:从理论到实践的全面指南.zip
- Python闭包:深入理解与应用场景解析.zip
- Win64OpenSSL-3-3-0.exe
- 课高分程设计-基于C++实现的民航飞行与地图简易管理系统-南京航空航天大学
- 航天器遥测数据故障检测系统python源码+文档说明+数据库(课程设计)
- 北京航空航天大学操作系统课设+ppt+实验报告
- 基于Vue+Echarts实现风力发电机中传感器的数据展示监控可视化系统+源代码+文档说明(高分课程设计)
- 基于单片机的风力发电机转速控制源码
- 基于C++实现的风力发电气动平衡监测系统+源代码+测量数据(高分课程设计)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页