X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=modules%2Fcodec%2Favcodec%2Fsubtitle.c;h=c6305b414237c62795d07301148a30b729d7e098;hb=fef270581f736d4f6289a77cb115195241ed691d;hp=1e8047b1a98e318e3e9f01e8ec3278b9964ea275;hpb=7c4b1eb97355b17f4ff3b77147156f6e97f024b5;p=vlc diff --git a/modules/codec/avcodec/subtitle.c b/modules/codec/avcodec/subtitle.c index 1e8047b1a9..c6305b4142 100644 --- a/modules/codec/avcodec/subtitle.c +++ b/modules/codec/avcodec/subtitle.c @@ -1,24 +1,24 @@ /***************************************************************************** - * subtitle.c: subtitle decoder using ffmpeg library + * subtitle.c: subtitle decoder using libavcodec library ***************************************************************************** * Copyright (C) 2009 Laurent Aimar * $Id$ * * Authors: Laurent Aimar * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * This program 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. * * This program 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 General Public License for more details. + * 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 General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ /***************************************************************************** @@ -32,26 +32,14 @@ #include #include #include -#include - -/* ffmpeg header */ -#ifdef HAVE_LIBAVCODEC_AVCODEC_H -# include -# ifdef HAVE_AVCODEC_VAAPI -# include -# endif -#elif defined(HAVE_FFMPEG_AVCODEC_H) -# include -#else -# include -#endif -#include "avcodec.h" +#include +#include -#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 52, 25, 0 ) +#include "avcodec.h" struct decoder_sys_t { - FFMPEG_COMMON_MEMBERS + AVCODEC_COMMON_MEMBERS }; static subpicture_t *ConvertSubtitle(decoder_t *, AVSubtitle *, mtime_t pts); @@ -64,11 +52,24 @@ int InitSubtitleDec(decoder_t *dec, AVCodecContext *context, { decoder_sys_t *sys; + /* */ + switch (codec_id) { + case CODEC_ID_HDMV_PGS_SUBTITLE: + case CODEC_ID_XSUB: + break; + default: + msg_Warn(dec, "refusing to decode non validated subtitle codec"); + return VLC_EGENERIC; + } + /* */ dec->p_sys = sys = malloc(sizeof(*sys)); if (!sys) return VLC_ENOMEM; + codec->type = AVMEDIA_TYPE_SUBTITLE; + context->codec_type = AVMEDIA_TYPE_SUBTITLE; + context->codec_id = codec_id; sys->p_context = context; sys->p_codec = codec; sys->i_codec_id = codec_id; @@ -80,18 +81,23 @@ int InitSubtitleDec(decoder_t *dec, AVCodecContext *context, context->extradata = NULL; /* */ + int ret; vlc_avcodec_lock(); - if (avcodec_open(context, codec) < 0) { - vlc_avcodec_unlock(); +#if LIBAVCODEC_VERSION_MAJOR < 54 + ret = avcodec_open(context, codec); +#else + ret = avcodec_open2(context, codec, NULL /* options */); +#endif + vlc_avcodec_unlock(); + if (ret < 0) { msg_Err(dec, "cannot open codec (%s)", namecodec); free(context->extradata); free(sys); return VLC_EGENERIC; } - vlc_avcodec_unlock(); /* */ - msg_Dbg(dec, "ffmpeg codec (%s) started", namecodec); + msg_Dbg(dec, "libavcodec codec (%s) started", namecodec); dec->fmt_out.i_cat = SPU_ES; return VLC_SUCCESS; @@ -176,15 +182,16 @@ void EndSubtitleDec(decoder_t *dec) } /** - * Convert a RGBA ffmpeg region to our format. + * Convert a RGBA libavcodec region to our format. */ static subpicture_region_t *ConvertRegionRGBA(AVSubtitleRect *ffregion) { - video_format_t fmt; + if (ffregion->w <= 0 || ffregion->h <= 0) + return NULL; + video_format_t fmt; memset(&fmt, 0, sizeof(fmt)); fmt.i_chroma = VLC_FOURCC('R','G','B','A'); - fmt.i_aspect = 0; fmt.i_width = fmt.i_visible_width = ffregion->w; fmt.i_height = @@ -222,11 +229,11 @@ static subpicture_region_t *ConvertRegionRGBA(AVSubtitleRect *ffregion) } /** - * Convert a ffmpeg subtitle to our format. + * Convert a libavcodec subtitle to our format. */ static subpicture_t *ConvertSubtitle(decoder_t *dec, AVSubtitle *ffsub, mtime_t pts) { - subpicture_t *spu = decoder_NewSubpicture(dec); + subpicture_t *spu = decoder_NewSubpicture(dec, NULL); if (!spu) return NULL; @@ -246,10 +253,10 @@ static subpicture_t *ConvertSubtitle(decoder_t *dec, AVSubtitle *ffsub, mtime_t for (unsigned i = 0; i < ffsub->num_rects; i++) { AVSubtitleRect *rec = ffsub->rects[i]; - msg_Err(dec, "SUBS RECT[%d]: %dx%d @%dx%d", - i, rec->w, rec->h, rec->x, rec->y); + //msg_Err(dec, "SUBS RECT[%d]: %dx%d @%dx%d", + // i, rec->w, rec->h, rec->x, rec->y); - subpicture_region_t *region; + subpicture_region_t *region = NULL; switch (ffsub->format) { case 0: region = ConvertRegionRGBA(rec); @@ -263,15 +270,12 @@ static subpicture_t *ConvertSubtitle(decoder_t *dec, AVSubtitle *ffsub, mtime_t *region_next = region; region_next = ®ion->p_next; } - /* Free AVSubtitleRect - * FIXME isn't there an avcodec function ? */ - free(rec->pict.data[0]); /* Plane */ - free(rec->pict.data[1]); /* Palette */ - free(rec); + /* Free AVSubtitleRect */ + avpicture_free(&rec->pict); + av_free(rec); } - free(ffsub->rects); + av_free(ffsub->rects); return spu; } -#endif