mirror of
https://github.com/mpv-player/mpv
synced 2025-03-04 05:07:51 +00:00
Support mp_image with allocated palette.
Fixes playback and a memory leak for FFmpeg codecs which use reget_buffer with paletted data, e.g. cdgraphics. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@30116 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
bd06a94738
commit
afc5a627d8
@ -38,7 +38,7 @@
|
||||
#define MP_IMGFLAG_YUV 0x200
|
||||
// set if it's swapped (BGR or YVU) plane/byteorder
|
||||
#define MP_IMGFLAG_SWAPPED 0x400
|
||||
// using palette for RGB data
|
||||
// set if you want memory for palette allocated and managed by vf_get_image etc.
|
||||
#define MP_IMGFLAG_RGB_PALETTE 0x800
|
||||
|
||||
#define MP_IMGFLAGMASK_COLORS 0xF00
|
||||
@ -223,6 +223,8 @@ static inline void free_mp_image(mp_image_t* mpi){
|
||||
if(mpi->flags&MP_IMGFLAG_ALLOCATED){
|
||||
/* becouse we allocate the whole image in once */
|
||||
if(mpi->planes[0]) free(mpi->planes[0]);
|
||||
if (mpi->flags & MP_IMGFLAG_RGB_PALETTE)
|
||||
free(mpi->planes[1]);
|
||||
}
|
||||
free(mpi);
|
||||
}
|
||||
|
@ -27,6 +27,10 @@ LIBVD_EXTERN(ffmpeg)
|
||||
|
||||
#include "libavcodec/avcodec.h"
|
||||
|
||||
#if AVPALETTE_SIZE > 1024
|
||||
#error palette too large, adapt libmpcodecs/vf.c:vf_get_image
|
||||
#endif
|
||||
|
||||
#if CONFIG_XVMC
|
||||
#include "libavcodec/xvmc.h"
|
||||
#endif
|
||||
@ -593,6 +597,8 @@ static int get_buffer(AVCodecContext *avctx, AVFrame *pic){
|
||||
mp_msg(MSGT_DECVIDEO, MSGL_DBG2, type== MP_IMGTYPE_IPB ? "using IPB\n" : "using IP\n");
|
||||
}
|
||||
|
||||
if (ctx->best_csp == IMGFMT_RGB8 || ctx->best_csp == IMGFMT_BGR8)
|
||||
flags |= MP_IMGFLAG_RGB_PALETTE;
|
||||
mpi= mpcodecs_get_image(sh, type, flags, width, height);
|
||||
if (!mpi) return -1;
|
||||
|
||||
@ -630,10 +636,6 @@ static int get_buffer(AVCodecContext *avctx, AVFrame *pic){
|
||||
}
|
||||
#endif
|
||||
|
||||
// Palette support: libavcodec copies palette to *data[1]
|
||||
if (mpi->bpp == 8)
|
||||
mpi->planes[1] = av_malloc(AVPALETTE_SIZE);
|
||||
|
||||
pic->data[0]= mpi->planes[0];
|
||||
pic->data[1]= mpi->planes[1];
|
||||
pic->data[2]= mpi->planes[2];
|
||||
|
@ -322,8 +322,8 @@ mp_image_t* vf_get_image(vf_instance_t* vf, unsigned int outfmt, int mp_imgtype,
|
||||
// keep buffer allocation status & color flags only:
|
||||
// mpi->flags&=~(MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE|MP_IMGFLAG_DIRECT);
|
||||
mpi->flags&=MP_IMGFLAG_ALLOCATED|MP_IMGFLAG_TYPE_DISPLAYED|MP_IMGFLAGMASK_COLORS;
|
||||
// accept restrictions & draw_slice flags only:
|
||||
mpi->flags|=mp_imgflag&(MP_IMGFLAGMASK_RESTRICTIONS|MP_IMGFLAG_DRAW_CALLBACK);
|
||||
// accept restrictions, draw_slice and palette flags only:
|
||||
mpi->flags|=mp_imgflag&(MP_IMGFLAGMASK_RESTRICTIONS|MP_IMGFLAG_DRAW_CALLBACK|MP_IMGFLAG_RGB_PALETTE);
|
||||
if(!vf->draw_slice) mpi->flags&=~MP_IMGFLAG_DRAW_CALLBACK;
|
||||
if(mpi->width!=w2 || mpi->height!=h){
|
||||
// printf("vf.c: MPI parameters changed! %dx%d -> %dx%d \n", mpi->width,mpi->height,w2,h);
|
||||
@ -406,6 +406,8 @@ mp_image_t* vf_get_image(vf_instance_t* vf, unsigned int outfmt, int mp_imgtype,
|
||||
} else {
|
||||
//if(!mpi->stride[0])
|
||||
mpi->stride[0]=mpi->width*mpi->bpp/8;
|
||||
if (mpi->flags & MP_IMGFLAG_RGB_PALETTE)
|
||||
mpi->planes[1] = memalign(64, 1024);
|
||||
}
|
||||
// printf("clearing img!\n");
|
||||
vf_mpi_clear(mpi,0,0,mpi->width,mpi->height);
|
||||
|
Loading…
Reference in New Issue
Block a user