[vlc-devel] [PATCH 5/6] copy: drop requirement for a memory cache for NV12/YV12 frames copies
Jean-Yves Avenard
jyavenard at gmail.com
Fri Jun 13 14:02:40 CEST 2014
From: Jean-Yves Avenard <jyavenard at mythtv.org>
---
modules/codec/avcodec/dxva2.c | 19 ++-------------
modules/codec/avcodec/vaapi.c | 15 ++----------
modules/codec/avcodec/vda.c | 19 +++------------
modules/codec/omxil/utils.c | 17 +------------
modules/video_chroma/copy.c | 55 +++++--------------------------------------
modules/video_chroma/copy.h | 16 ++-----------
6 files changed, 16 insertions(+), 125 deletions(-)
diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index 8b6dc5f..3405421 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -270,7 +270,6 @@ struct vlc_va_sys_t
/* Option conversion */
D3DFORMAT output;
- copy_cache_t surface_cache;
/* */
struct dxva_context hw;
@@ -306,7 +305,6 @@ static void DxDestroyVideoDecoder(vlc_va_sys_t *);
static int DxResetVideoDecoder(vlc_va_t *);
static void DxCreateVideoConversion(vlc_va_sys_t *);
-static void DxDestroyVideoConversion(vlc_va_sys_t *);
/* */
static int Setup(vlc_va_t *va, void **hw, vlc_fourcc_t *chroma,
@@ -318,7 +316,6 @@ static int Setup(vlc_va_t *va, void **hw, vlc_fourcc_t *chroma,
goto ok;
/* */
- DxDestroyVideoConversion(sys);
DxDestroyVideoDecoder(sys);
*hw = NULL;
@@ -358,9 +355,6 @@ static int Extract(vlc_va_t *va, picture_t *picture, void *opaque,
vlc_va_sys_t *sys = va->sys;
LPDIRECT3DSURFACE9 d3d = (LPDIRECT3DSURFACE9)(uintptr_t)data;
- if (!sys->surface_cache.buffer)
- return VLC_EGENERIC;
-
/* */
assert(sys->output == MAKEFOURCC('Y','V','1','2'));
@@ -394,8 +388,7 @@ static int Extract(vlc_va_t *va, picture_t *picture, void *opaque,
plane[1] = plane[2];
plane[2] = V;
}
- CopyFromYv12(picture, plane, pitch, sys->width, sys->height,
- &sys->surface_cache);
+ CopyFromYv12(picture, plane, pitch, sys->width, sys->height);
} else {
assert(sys->render == MAKEFOURCC('N','V','1','2'));
uint8_t *plane[2] = {
@@ -406,8 +399,7 @@ static int Extract(vlc_va_t *va, picture_t *picture, void *opaque,
lock.Pitch,
lock.Pitch,
};
- CopyFromNv12(picture, plane, pitch, sys->width, sys->height,
- &sys->surface_cache);
+ CopyFromNv12(picture, plane, pitch, sys->width, sys->height);
}
/* */
@@ -467,7 +459,6 @@ static void Close(vlc_va_t *va)
{
vlc_va_sys_t *sys = va->sys;
- DxDestroyVideoConversion(sys);
DxDestroyVideoDecoder(sys);
DxDestroyVideoService(sys);
D3dDestroyDeviceManager(sys);
@@ -1010,10 +1001,4 @@ static void DxCreateVideoConversion(vlc_va_sys_t *va)
va->output = va->render;
break;
}
- CopyInitCache(&va->surface_cache, va->surface_width);
-}
-
-static void DxDestroyVideoConversion(vlc_va_sys_t *va)
-{
- CopyCleanCache(&va->surface_cache);
}
diff --git a/modules/codec/avcodec/vaapi.c b/modules/codec/avcodec/vaapi.c
index 204e8da..80dcdca 100644
--- a/modules/codec/avcodec/vaapi.c
+++ b/modules/codec/avcodec/vaapi.c
@@ -104,7 +104,6 @@ struct vlc_va_sys_t
vlc_va_surface_t *p_surface;
VAImage image;
- copy_cache_t image_cache;
bool b_supports_derive;
};
@@ -262,13 +261,8 @@ static void DestroySurfaces( vlc_va_sys_t *sys )
{
if( sys->image.image_id != VA_INVALID_ID )
{
- CopyCleanCache( &sys->image_cache );
vaDestroyImage( sys->p_display, sys->image.image_id );
}
- else if(sys->b_supports_derive)
- {
- CopyCleanCache( &sys->image_cache );
- }
if( sys->i_context_id != VA_INVALID_ID )
vaDestroyContext( sys->p_display, sys->i_context_id );
@@ -415,9 +409,6 @@ static int CreateSurfaces( vlc_va_sys_t *sys, void **pp_hw_ctx, vlc_fourcc_t *pi
sys->image.image_id = VA_INVALID_ID;
}
- if( unlikely(CopyInitCache( &sys->image_cache, i_width )) )
- goto error;
-
/* Setup the ffmpeg hardware context */
*pp_hw_ctx = &sys->hw_ctx;
@@ -507,8 +498,7 @@ static int Extract( vlc_va_t *va, picture_t *p_picture, void *opaque,
}
CopyFromYv12( p_picture, pp_plane, pi_pitch,
sys->i_surface_width,
- sys->i_surface_height,
- &sys->image_cache );
+ sys->i_surface_height);
}
else
{
@@ -523,8 +513,7 @@ static int Extract( vlc_va_t *va, picture_t *p_picture, void *opaque,
}
CopyFromNv12( p_picture, pp_plane, pi_pitch,
sys->i_surface_width,
- sys->i_surface_height,
- &sys->image_cache );
+ sys->i_surface_height);
}
if( vaUnmapBuffer( sys->p_display, sys->image.buf ) )
diff --git a/modules/codec/avcodec/vda.c b/modules/codec/avcodec/vda.c
index 9da0527..90ee139 100644
--- a/modules/codec/avcodec/vda.c
+++ b/modules/codec/avcodec/vda.c
@@ -104,8 +104,6 @@ struct vlc_va_sys_t
vlc_fourcc_t i_chroma;
- copy_cache_t image_cache;
-
vlc_object_t *p_log;
};
@@ -162,9 +160,6 @@ static void Close( vlc_va_t *external )
ff_vda_destroy_decoder( &p_va->hw_ctx ) ;
- if( p_va->hw_ctx.cv_pix_fmt_type == kCVPixelFormatType_420YpCbCr8Planar )
- CopyCleanCache( &p_va->image_cache );
-
free( p_va );
}
@@ -205,7 +200,6 @@ static int Setup( vlc_va_t *external, void **pp_hw_ctx, vlc_fourcc_t *pi_chroma,
default :
p_va->hw_ctx.cv_pix_fmt_type = kCVPixelFormatType_420YpCbCr8Planar;
p_va->i_chroma = VLC_CODEC_I420;
- CopyInitCache( &p_va->image_cache, i_width );
msg_Dbg(p_va->p_log, "using pixel format 420YpCbCr8Planar");
}
@@ -237,8 +231,7 @@ ok:
static void vda_Copy420YpCbCr8Planar( picture_t *p_pic,
CVPixelBufferRef buffer,
unsigned i_width,
- unsigned i_height,
- copy_cache_t *cache )
+ unsigned i_height )
{
uint8_t *pp_plane[3];
size_t pi_pitch[3];
@@ -255,7 +248,7 @@ static void vda_Copy420YpCbCr8Planar( picture_t *p_pic,
}
CopyFromYv12( p_pic, pp_plane, pi_pitch,
- i_width, i_height, cache );
+ i_width, i_height );
CVPixelBufferUnlockBaseAddress( buffer, 0 );
}
@@ -288,16 +281,10 @@ static int Extract( vlc_va_t *external, picture_t *p_picture, void *opaque,
if( p_va->hw_ctx.cv_pix_fmt_type == kCVPixelFormatType_420YpCbCr8Planar )
{
- if( !p_va->image_cache.buffer ) {
- CVPixelBufferRelease( cv_buffer );
- return VLC_EGENERIC;
- }
-
vda_Copy420YpCbCr8Planar( p_picture,
cv_buffer,
p_va->hw_ctx.width,
- p_va->hw_ctx.height,
- &p_va->image_cache );
+ p_va->hw_ctx.height );
}
else
vda_Copy422YpCbCr8( p_picture, cv_buffer );
diff --git a/modules/codec/omxil/utils.c b/modules/codec/omxil/utils.c
index af050c3..35edf61 100644
--- a/modules/codec/omxil/utils.c
+++ b/modules/codec/omxil/utils.c
@@ -173,13 +173,6 @@ void ArchitectureSpecificCopyHooks( decoder_t *p_dec, int i_color_format,
#ifdef CAN_COMPILE_SSE2
if( i_color_format == OMX_COLOR_FormatYUV420SemiPlanar && vlc_CPU_SSE2() )
{
- copy_cache_t *p_surface_cache = malloc( sizeof(copy_cache_t) );
- if( !p_surface_cache || CopyInitCache( p_surface_cache, i_src_stride ) )
- {
- free( p_surface_cache );
- return;
- }
- p_architecture_specific->data = p_surface_cache;
p_dec->fmt_out.i_codec = VLC_CODEC_YV12;
}
#endif
@@ -190,13 +183,6 @@ void ArchitectureSpecificCopyHooksDestroy( int i_color_format,
{
if (!p_architecture_specific->data)
return;
-#ifdef CAN_COMPILE_SSE2
- if( i_color_format == OMX_COLOR_FormatYUV420SemiPlanar && vlc_CPU_SSE2() )
- {
- copy_cache_t *p_surface_cache = (copy_cache_t*)p_architecture_specific->data;
- CopyCleanCache(p_surface_cache);
- }
-#endif
free(p_architecture_specific->data);
p_architecture_specific->data = NULL;
}
@@ -218,10 +204,9 @@ void CopyOmxPicture( int i_color_format, picture_t *p_pic,
if( i_color_format == OMX_COLOR_FormatYUV420SemiPlanar
&& vlc_CPU_SSE2() && p_architecture_specific->data )
{
- copy_cache_t *p_surface_cache = (copy_cache_t*)p_architecture_specific->data;
uint8_t *ppi_src_pointers[2] = { p_src, p_src + i_src_stride * i_slice_height };
size_t pi_src_strides[2] = { i_src_stride, i_src_stride };
- CopyFromNv12( p_pic, ppi_src_pointers, pi_src_strides, i_src_stride, i_slice_height, p_surface_cache );
+ CopyFromNv12( p_pic, ppi_src_pointers, pi_src_strides, i_src_stride, i_slice_height );
return;
}
#endif
diff --git a/modules/video_chroma/copy.c b/modules/video_chroma/copy.c
index 3c907a4..9a0408a 100644
--- a/modules/video_chroma/copy.c
+++ b/modules/video_chroma/copy.c
@@ -33,30 +33,6 @@
#include "copy.h"
-int CopyInitCache(copy_cache_t *cache, unsigned width)
-{
-#ifdef CAN_COMPILE_SSE2
- cache->size = __MAX((width + 0x0f) & ~ 0x0f, 4096);
- cache->buffer = vlc_memalign(16, cache->size);
- if (!cache->buffer)
- return VLC_EGENERIC;
-#else
- (void) cache; (void) width;
-#endif
- return VLC_SUCCESS;
-}
-
-void CopyCleanCache(copy_cache_t *cache)
-{
-#ifdef CAN_COMPILE_SSE2
- vlc_free(cache->buffer);
- cache->buffer = NULL;
- cache->size = 0;
-#else
- (void) cache;
-#endif
-}
-
#ifdef CAN_COMPILE_SSE2
/* Copy 64 bytes from srcp to dstp loading data with the SSE>=2 instruction
* load and storing data with the SSE>=2 instruction store.
@@ -95,12 +71,8 @@ void CopyCleanCache(copy_cache_t *cache)
VLC_SSE
static void SSE_CopyPlane(uint8_t *dst, size_t dst_pitch,
const uint8_t *src, size_t src_pitch,
- uint8_t *cache, size_t cache_size,
unsigned width, unsigned height, unsigned cpu)
{
- VLC_UNUSED(cache);
- VLC_UNUSED(cache_size);
-
asm volatile ("mfence");
for (unsigned y = 0; y < height; y++) {
@@ -145,12 +117,8 @@ static void SSE_CopyPlane(uint8_t *dst, size_t dst_pitch,
static void SSE_SplitPlanes(uint8_t *dstu, size_t dstu_pitch,
uint8_t *dstv, size_t dstv_pitch,
const uint8_t *src, size_t src_pitch,
- uint8_t *cache, size_t cache_size,
unsigned width, unsigned height, unsigned cpu)
{
- VLC_UNUSED(cache);
- VLC_UNUSED(cache_size);
-
const uint8_t shuffle[] = { 0, 2, 4, 6, 8, 10, 12, 14,
1, 3, 5, 7, 9, 11, 13, 15 };
const uint8_t mask[] = { 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00,
@@ -288,16 +256,14 @@ static void SSE_SplitPlanes(uint8_t *dstu, size_t dstu_pitch,
static void SSE_CopyFromNv12(picture_t *dst,
uint8_t *src[2], size_t src_pitch[2],
unsigned width, unsigned height,
- copy_cache_t *cache, unsigned cpu)
+ unsigned cpu)
{
SSE_CopyPlane(dst->p[0].p_pixels, dst->p[0].i_pitch,
src[0], src_pitch[0],
- cache->buffer, cache->size,
width, height, cpu);
SSE_SplitPlanes(dst->p[2].p_pixels, dst->p[2].i_pitch,
dst->p[1].p_pixels, dst->p[1].i_pitch,
src[1], src_pitch[1],
- cache->buffer, cache->size,
(width+1)/2, (height+1)/2, cpu);
asm volatile ("emms");
}
@@ -305,13 +271,12 @@ static void SSE_CopyFromNv12(picture_t *dst,
static void SSE_CopyFromYv12(picture_t *dst,
uint8_t *src[3], size_t src_pitch[3],
unsigned width, unsigned height,
- copy_cache_t *cache, unsigned cpu)
+ unsigned cpu)
{
for (unsigned n = 0; n < 3; n++) {
const unsigned d = n > 0 ? 2 : 1;
SSE_CopyPlane(dst->p[n].p_pixels, dst->p[n].i_pitch,
src[n], src_pitch[n],
- cache->buffer, cache->size,
(width+d-1)/d, (height+d-1)/d, cpu);
}
asm volatile ("emms");
@@ -347,16 +312,12 @@ static void SplitPlanes(uint8_t *dstu, size_t dstu_pitch,
}
void CopyFromNv12(picture_t *dst, uint8_t *src[2], size_t src_pitch[2],
- unsigned width, unsigned height,
- copy_cache_t *cache)
+ unsigned width, unsigned height)
{
#ifdef CAN_COMPILE_SSE2
unsigned cpu = vlc_CPU();
if (vlc_CPU_SSE2())
- return SSE_CopyFromNv12(dst, src, src_pitch, width, height,
- cache, cpu);
-#else
- (void) cache;
+ return SSE_CopyFromNv12(dst, src, src_pitch, width, height, cpu);
#endif
CopyPlane(dst->p[0].p_pixels, dst->p[0].i_pitch,
@@ -369,16 +330,12 @@ void CopyFromNv12(picture_t *dst, uint8_t *src[2], size_t src_pitch[2],
}
void CopyFromYv12(picture_t *dst, uint8_t *src[3], size_t src_pitch[3],
- unsigned width, unsigned height,
- copy_cache_t *cache)
+ unsigned width, unsigned height)
{
#ifdef CAN_COMPILE_SSE2
unsigned cpu = vlc_CPU();
if (vlc_CPU_SSE2())
- return SSE_CopyFromYv12(dst, src, src_pitch, width, height,
- cache, cpu);
-#else
- (void) cache;
+ return SSE_CopyFromYv12(dst, src, src_pitch, width, height, cpu);
#endif
CopyPlane(dst->p[0].p_pixels, dst->p[0].i_pitch,
diff --git a/modules/video_chroma/copy.h b/modules/video_chroma/copy.h
index 39dbf1e..b86eb14 100644
--- a/modules/video_chroma/copy.h
+++ b/modules/video_chroma/copy.h
@@ -24,21 +24,9 @@
#ifndef _VLC_VIDEOCHROMA_COPY_H
#define _VLC_VIDEOCHROMA_COPY_H 1
-typedef struct {
-# ifdef CAN_COMPILE_SSE2
- uint8_t *buffer;
- size_t size;
-# endif
-} copy_cache_t;
-
-int CopyInitCache(copy_cache_t *cache, unsigned width);
-void CopyCleanCache(copy_cache_t *cache);
-
void CopyFromNv12(picture_t *dst, uint8_t *src[2], size_t src_pitch[2],
- unsigned width, unsigned height,
- copy_cache_t *cache);
+ unsigned width, unsigned height);
void CopyFromYv12(picture_t *dst, uint8_t *src[3], size_t src_pitch[3],
- unsigned width, unsigned height,
- copy_cache_t *cache);
+ unsigned width, unsigned height);
#endif
--
1.9.1
More information about the vlc-devel
mailing list