/*****************************************************************************
- * subtitle.c: subtitle decoder using ffmpeg library
+ * subtitle.c: subtitle decoder using libavcodec library
*****************************************************************************
* Copyright (C) 2009 Laurent Aimar
* $Id$
*
* Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
*
- * 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.
*****************************************************************************/
/*****************************************************************************
#include <vlc_common.h>
#include <vlc_codec.h>
#include <vlc_avcodec.h>
-#include <vlc_osd.h>
-
-/* ffmpeg header */
-#ifdef HAVE_LIBAVCODEC_AVCODEC_H
-# include <libavcodec/avcodec.h>
-# ifdef HAVE_AVCODEC_VAAPI
-# include <libavcodec/vaapi.h>
-# endif
-#elif defined(HAVE_FFMPEG_AVCODEC_H)
-# include <ffmpeg/avcodec.h>
-#else
-# include <avcodec.h>
-#endif
-#include "avcodec.h"
+#include <libavcodec/avcodec.h>
+#include <libavutil/mem.h>
-#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);
{
decoder_sys_t *sys;
+ /* */
+ switch (codec_id) {
+ case AV_CODEC_ID_HDMV_PGS_SUBTITLE:
+ case AV_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;
context->extradata = NULL;
/* */
+ int ret;
vlc_avcodec_lock();
- if (avcodec_open(context, codec) < 0) {
- vlc_avcodec_unlock();
+ ret = avcodec_open2(context, codec, NULL /* options */);
+ 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;
}
/**
- * 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 =
}
/**
- * 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;
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);
*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