Commit 690bfceb authored by Anuradha Suraparaju's avatar Anuradha Suraparaju Committed by Diego Biurrun

Dirac decoding/encoding support via libdirac.

patch by Anuradha Suraparaju, anuradha rd.bbc.co uk

Originally committed as revision 13042 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 575e696c
...@@ -90,6 +90,7 @@ show_help(){ ...@@ -90,6 +90,7 @@ show_help(){
echo " --enable-libamr-wb enable libamr-wb floating point audio codec" echo " --enable-libamr-wb enable libamr-wb floating point audio codec"
echo " --enable-libdc1394 enable IIDC-1394 grabbing using libdc1394" echo " --enable-libdc1394 enable IIDC-1394 grabbing using libdc1394"
echo " and libraw1394 [default=no]" echo " and libraw1394 [default=no]"
echo " --enable-libdirac enable Dirac support via libdirac [default=no]"
echo " --enable-libfaac enable FAAC support via libfaac [default=no]" echo " --enable-libfaac enable FAAC support via libfaac [default=no]"
echo " --enable-libfaad enable FAAD support via libfaad [default=no]" echo " --enable-libfaad enable FAAD support via libfaad [default=no]"
echo " --enable-libfaadbin open libfaad.so.0 at runtime [default=no]" echo " --enable-libfaadbin open libfaad.so.0 at runtime [default=no]"
...@@ -641,6 +642,7 @@ CONFIG_LIST=" ...@@ -641,6 +642,7 @@ CONFIG_LIST="
libamr_nb libamr_nb
libamr_wb libamr_wb
libdc1394 libdc1394
libdirac
libfaac libfaac
libfaad libfaad
libfaadbin libfaadbin
...@@ -822,6 +824,8 @@ libamr_nb_decoder_deps="libamr_nb" ...@@ -822,6 +824,8 @@ libamr_nb_decoder_deps="libamr_nb"
libamr_nb_encoder_deps="libamr_nb" libamr_nb_encoder_deps="libamr_nb"
libamr_wb_decoder_deps="libamr_wb" libamr_wb_decoder_deps="libamr_wb"
libamr_wb_encoder_deps="libamr_wb" libamr_wb_encoder_deps="libamr_wb"
libdirac_decoder_deps="libdirac"
libdirac_encoder_deps="libdirac"
libfaac_encoder_deps="libfaac" libfaac_encoder_deps="libfaac"
libfaad_decoder_deps="libfaad" libfaad_decoder_deps="libfaad"
libfaadbin_decoder_extralibs='$ldl' libfaadbin_decoder_extralibs='$ldl'
...@@ -1625,6 +1629,9 @@ enabled avisynth && require2 vfw32 "windows.h vfw.h" AVIFileInit -lvfw32 ...@@ -1625,6 +1629,9 @@ enabled avisynth && require2 vfw32 "windows.h vfw.h" AVIFileInit -lvfw32
enabled liba52 && require liba52 a52dec/a52.h a52_init -la52 enabled liba52 && require liba52 a52dec/a52.h a52_init -la52
enabled libamr_nb && require libamrnb amrnb/interf_dec.h Speech_Decode_Frame_init -lamrnb -lm enabled libamr_nb && require libamrnb amrnb/interf_dec.h Speech_Decode_Frame_init -lamrnb -lm
enabled libamr_wb && require libamrwb amrwb/dec_if.h D_IF_init -lamrwb -lm enabled libamr_wb && require libamrwb amrwb/dec_if.h D_IF_init -lamrwb -lm
enabled libdirac && add_cflags "$(pkg-config --cflags dirac)" \
&& require libdirac libdirac_decoder/dirac_parser.h dirac_decoder_init -ldirac_decoder \
&& require libdirac libdirac_encoder/dirac_encoder.h dirac_encoder_init -ldirac_encoder
enabled libfaac && require2 libfaac "stdint.h faac.h" faacEncGetVersion -lfaac enabled libfaac && require2 libfaac "stdint.h faac.h" faacEncGetVersion -lfaac
enabled libfaad && require2 libfaad faad.h faacDecOpen -lfaad enabled libfaad && require2 libfaad faad.h faacDecOpen -lfaad
enabled libgsm && require libgsm gsm.h gsm_create -lgsm enabled libgsm && require libgsm gsm.h gsm_create -lgsm
...@@ -1845,6 +1852,7 @@ check_deps $CONFIG_LIST \ ...@@ -1845,6 +1852,7 @@ check_deps $CONFIG_LIST \
$PROTOCOL_LIST \ $PROTOCOL_LIST \
enabled libdc1394 && append pkg_requires "libraw1394" enabled libdc1394 && append pkg_requires "libraw1394"
enabled libdirac && append pkg_requires "dirac"
enabled libtheora && append pkg_requires "theora" enabled libtheora && append pkg_requires "theora"
enabled libvorbis && append pkg_requires "vorbisenc" enabled libvorbis && append pkg_requires "vorbisenc"
...@@ -1908,6 +1916,7 @@ echo "liba52 dlopened ${liba52bin-no}" ...@@ -1908,6 +1916,7 @@ echo "liba52 dlopened ${liba52bin-no}"
echo "libamr-nb support ${libamr_nb-no}" echo "libamr-nb support ${libamr_nb-no}"
echo "libamr-wb support ${libamr_wb-no}" echo "libamr-wb support ${libamr_wb-no}"
echo "libdc1394 support ${libdc1394-no}" echo "libdc1394 support ${libdc1394-no}"
echo "libdirac enabled ${libdirac-no}"
echo "libfaac enabled ${libfaac-no}" echo "libfaac enabled ${libfaac-no}"
echo "libfaad enabled ${libfaad-no}" echo "libfaad enabled ${libfaad-no}"
echo "libfaad dlopened ${libfaadbin-no}" echo "libfaad dlopened ${libfaadbin-no}"
......
...@@ -319,6 +319,8 @@ OBJS-$(CONFIG_RTP_MUXER) += mpegvideo.o ...@@ -319,6 +319,8 @@ OBJS-$(CONFIG_RTP_MUXER) += mpegvideo.o
OBJS-$(CONFIG_LIBA52) += liba52.o OBJS-$(CONFIG_LIBA52) += liba52.o
OBJS-$(CONFIG_LIBAMR_NB) += libamr.o OBJS-$(CONFIG_LIBAMR_NB) += libamr.o
OBJS-$(CONFIG_LIBAMR_WB) += libamr.o OBJS-$(CONFIG_LIBAMR_WB) += libamr.o
OBJS-$(CONFIG_LIBDIRAC_DECODER) += libdiracdec.o
OBJS-$(CONFIG_LIBDIRAC_ENCODER) += libdiracenc.o libdirac_libschro.o
OBJS-$(CONFIG_LIBFAAC) += libfaac.o OBJS-$(CONFIG_LIBFAAC) += libfaac.o
OBJS-$(CONFIG_LIBFAAD) += libfaad.o OBJS-$(CONFIG_LIBFAAD) += libfaad.o
OBJS-$(CONFIG_LIBGSM) += libgsm.o OBJS-$(CONFIG_LIBGSM) += libgsm.o
......
...@@ -277,6 +277,7 @@ void avcodec_register_all(void) ...@@ -277,6 +277,7 @@ void avcodec_register_all(void)
REGISTER_DECODER (LIBA52, liba52); REGISTER_DECODER (LIBA52, liba52);
REGISTER_ENCDEC (LIBAMR_NB, libamr_nb); REGISTER_ENCDEC (LIBAMR_NB, libamr_nb);
REGISTER_ENCDEC (LIBAMR_WB, libamr_wb); REGISTER_ENCDEC (LIBAMR_WB, libamr_wb);
REGISTER_ENCDEC (LIBDIRAC, libdirac);
REGISTER_ENCODER (LIBFAAC, libfaac); REGISTER_ENCODER (LIBFAAC, libfaac);
REGISTER_DECODER (LIBFAAD, libfaad); REGISTER_DECODER (LIBFAAD, libfaad);
REGISTER_ENCDEC (LIBGSM, libgsm); REGISTER_ENCDEC (LIBGSM, libgsm);
......
/*
* Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
*
* 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
*/
/**
* @file libdirac.h
* data structures common to libdiracenc.c and libdiracdec.c
*/
#ifndef FFMPEG_LIBDIRAC_H
#define FFMPEG_LIBDIRAC_H
#include "avcodec.h"
#include <libdirac_common/dirac_types.h>
/**
* Table providing a Dirac chroma format to FFmpeg pixel format mapping.
*/
static const struct {
enum PixelFormat ff_pix_fmt;
dirac_chroma_t dirac_pix_fmt;
} ffmpeg_dirac_pixel_format_map[] = {
{ PIX_FMT_YUV420P, format420 },
{ PIX_FMT_YUV422P, format422 },
{ PIX_FMT_YUV444P, format444 },
};
#endif /* FFMPEG_LIBDIRAC_H */
/*
* Dirac decoder support via libdirac library
* Copyright (c) 2005 BBC, Andrew Kennedy <dirac at rd dot bbc dot co dot uk>
* Copyright (c) 2006-2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
*
* 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
*/
/**
* @file libdiracdec.c
* Dirac decoder support via libdirac library; more details about the Dirac
* project can be found at http://dirac.sourceforge.net/.
* The libdirac_decoder library implements Dirac specification version 2.2
* (http://dirac.sourceforge.net/specification.html).
*/
#include "libdirac.h"
#undef NDEBUG
#include <assert.h>
#include <libdirac_decoder/dirac_parser.h>
/** contains a single frame returned from Dirac */
typedef struct FfmpegDiracDecoderParams
{
/** decoder handle */
dirac_decoder_t* p_decoder;
/** buffer to hold decoded frame */
unsigned char* p_out_frame_buf;
} FfmpegDiracDecoderParams;
/**
* returns FFmpeg chroma format
*/
static enum PixelFormat GetFfmpegChromaFormat(dirac_chroma_t dirac_pix_fmt)
{
int num_formats = sizeof(ffmpeg_dirac_pixel_format_map) /
sizeof(ffmpeg_dirac_pixel_format_map[0]);
int idx;
for (idx = 0; idx < num_formats; ++idx) {
if (ffmpeg_dirac_pixel_format_map[idx].dirac_pix_fmt == dirac_pix_fmt) {
return ffmpeg_dirac_pixel_format_map[idx].ff_pix_fmt;
}
}
return PIX_FMT_NONE;
}
static int libdirac_decode_init(AVCodecContext *avccontext)
{
FfmpegDiracDecoderParams *p_dirac_params = avccontext->priv_data ;
p_dirac_params->p_decoder = dirac_decoder_init(avccontext->debug);
if (!p_dirac_params->p_decoder)
return -1;
return 0 ;
}
static int libdirac_decode_frame(AVCodecContext *avccontext,
void *data, int *data_size,
const uint8_t *buf, int buf_size)
{
FfmpegDiracDecoderParams *p_dirac_params = avccontext->priv_data;
AVPicture *picture = data;
AVPicture pic;
int pict_size;
unsigned char *buffer[3];
*data_size = 0;
if (buf_size>0)
/* set data to decode into buffer */
dirac_buffer (p_dirac_params->p_decoder, buf, buf+buf_size);
while (1) {
/* parse data and process result */
DecoderState state = dirac_parse (p_dirac_params->p_decoder);
switch (state)
{
case STATE_BUFFER:
return buf_size;
case STATE_SEQUENCE:
{
/* tell FFmpeg about sequence details */
dirac_sourceparams_t *src_params =
&p_dirac_params->p_decoder->src_params;
if (avcodec_check_dimensions(avccontext, src_params->width,
src_params->height) < 0) {
av_log(avccontext, AV_LOG_ERROR, "Invalid dimensions (%dx%d)\n",
src_params->width, src_params->height);
avccontext->height = avccontext->width = 0;
return -1;
}
avccontext->height = src_params->height;
avccontext->width = src_params->width;
avccontext->pix_fmt = GetFfmpegChromaFormat(src_params->chroma);
if (avccontext->pix_fmt == PIX_FMT_NONE) {
av_log (avccontext, AV_LOG_ERROR,
"Dirac chroma format %d not supported currently\n",
src_params->chroma);
return -1;
}
avccontext->time_base.den = src_params->frame_rate.numerator;
avccontext->time_base.num = src_params->frame_rate.denominator;
/* calculate output dimensions */
avpicture_fill(&pic, NULL, avccontext->pix_fmt,
avccontext->width, avccontext->height);
pict_size = avpicture_get_size(avccontext->pix_fmt,
avccontext->width,
avccontext->height);
/* allocate output buffer */
if (p_dirac_params->p_out_frame_buf == NULL)
p_dirac_params->p_out_frame_buf = av_malloc (pict_size);
buffer[0] = p_dirac_params->p_out_frame_buf;
buffer[1] = p_dirac_params->p_out_frame_buf +
pic.linesize[0] * avccontext->height;
buffer[2] = buffer[1] +
pic.linesize[1] * src_params->chroma_height;
/* tell Dirac about output destination */
dirac_set_buf(p_dirac_params->p_decoder, buffer, NULL);
break;
}
case STATE_SEQUENCE_END:
break;
case STATE_PICTURE_AVAIL:
/* fill picture with current buffer data from Dirac */
avpicture_fill(picture, p_dirac_params->p_out_frame_buf,
avccontext->pix_fmt,
avccontext->width, avccontext->height);
*data_size = sizeof(AVPicture);
return buf_size;
case STATE_INVALID:
return -1;
default:
break;
}
}
return buf_size;
}
static int libdirac_decode_close(AVCodecContext *avccontext)
{
FfmpegDiracDecoderParams *p_dirac_params = avccontext->priv_data;
dirac_decoder_close (p_dirac_params->p_decoder);
av_freep(&p_dirac_params->p_out_frame_buf);
return 0 ;
}
static void libdirac_flush (AVCodecContext *avccontext)
{
/* Got a seek request. We will need free memory held in the private
* context and free the current Dirac decoder handle and then open
* a new decoder handle. */
libdirac_decode_close (avccontext);
libdirac_decode_init (avccontext);
return;
}
AVCodec libdirac_decoder = {
"libdirac",
CODEC_TYPE_VIDEO,
CODEC_ID_DIRAC,
sizeof(FfmpegDiracDecoderParams),
libdirac_decode_init,
NULL,
libdirac_decode_close,
libdirac_decode_frame,
CODEC_CAP_DELAY,
.flush = libdirac_flush
} ;
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment