diff options
Diffstat (limited to 'src/combined/ffmpeg')
-rw-r--r-- | src/combined/ffmpeg/Makefile.am | 49 | ||||
-rw-r--r-- | src/combined/ffmpeg/ff_audio_decoder.c | 69 | ||||
-rw-r--r-- | src/combined/ffmpeg/ff_dvaudio_decoder.c | 417 | ||||
-rw-r--r-- | src/combined/ffmpeg/ff_video_decoder.c | 149 | ||||
-rw-r--r-- | src/combined/ffmpeg/ffmpeg_encoder.c | 328 |
5 files changed, 3 insertions, 1009 deletions
diff --git a/src/combined/ffmpeg/Makefile.am b/src/combined/ffmpeg/Makefile.am index b9f0eac5c..c0eeccffd 100644 --- a/src/combined/ffmpeg/Makefile.am +++ b/src/combined/ffmpeg/Makefile.am @@ -4,57 +4,14 @@ AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG) AM_CPPFLAGS = $(ZLIB_CPPFLAGS) AM_LDFLAGS = $(xineplug_ldflags) -if WITH_EXTERNAL_FFMPEG -AM_CFLAGS += $(FFMPEG_CFLAGS) $(FFMPEG_POSTPROC_CFLAGS) -link_ffmpeg = $(FFMPEG_LIBS) $(FFMPEG_POSTPROC_LIBS) -else -AM_CPPFLAGS += -I$(top_srcdir)/contrib/ffmpeg -link_ffmpeg = $(top_builddir)/contrib/ffmpeg/libavcodec/libavcodec.a \ - $(top_builddir)/contrib/ffmpeg/libavutil/libavutil.a \ - $(top_builddir)/contrib/ffmpeg/libpostproc/libpostproc.a +xineplug_LTLIBRARIES = xineplug_decode_ff.la -$(top_builddir)/contrib/ffmpeg/libavcodec/libavcodec.a: - $(MAKE) -C $(top_builddir)/contrib/ ffmpeg/libavcodec/libavcodec.a - -$(top_builddir)/contrib/ffmpeg/libavutil/libavutil.a: - $(MAKE) -C $(top_builddir)/contrib/ ffmpeg/libavutil/libavutil.a - -$(top_builddir)/contrib/ffmpeg/libpostproc/libpostproc.a: - $(MAKE) -C $(top_builddir)/contrib/ ffmpeg/libpostproc/libpostproc.a - -$(top_builddir)/contrib/ffmpeg/config.h: - $(MAKE) -C $(top_builddir)/contrib/ ffmpeg/config.mak - -ffmpeg_config.h: $(top_builddir)/contrib/ffmpeg/config.h - cp $(top_builddir)/contrib/ffmpeg/config.h ffmpeg_config.h - -BUILT_SOURCES = ffmpeg_config.h -CLEANFILES = $(BUILT_SOURCES) - -endif - -# this must always be included, even if the current machine has no DXR3... -EXTRA_DIST = ffmpeg_encoder.c - -xineplug_LTLIBRARIES = xineplug_decode_ff.la xineplug_decode_dvaudio.la - -if ENABLE_DXR3 -AM_CFLAGS += $(X_CFLAGS) -AM_CPPFLAGS += -I$(top_srcdir)/src/dxr3 -xineplug_decode_ff_la_SOURCES = ffmpeg_decoder.c ff_audio_decoder.c ff_video_decoder.c \ - ffmpeg_encoder.c ff_mpeg_parser.c ffmpeg_decoder.h \ - ff_mpeg_parser.h -else xineplug_decode_ff_la_SOURCES = ffmpeg_decoder.c ff_audio_decoder.c ff_video_decoder.c \ ff_mpeg_parser.c ffmpeg_decoder.h ff_mpeg_parser.h -endif nodist_xineplug_decode_ff_la_SOURCES = ffmpeg_config.h +xineplug_decode_ff_la_CFLAGS = $(AM_CFLAGS) $(FFMPEG_CFLAGS) $(FFMPEG_POSTPROC_CFLAGS) xineplug_decode_ff_la_LIBADD = $(XINE_LIB) $(MLIB_LIBS) -lm $(ZLIB_LIBS) \ - $(link_ffmpeg) $(PTHREAD_LIBS) $(LTLIBINTL) + $(FFMPEG_LIBS) $(FFMPEG_POSTPROC_LIBS) $(PTHREAD_LIBS) $(LTLIBINTL) xineplug_decode_ff_la_LDFLAGS = $(AM_LDFLAGS) $(IMPURE_TEXT_LDFLAGS) - -xineplug_decode_dvaudio_la_SOURCES = ff_dvaudio_decoder.c -xineplug_decode_dvaudio_la_LIBADD = $(XINE_LIB) $(LTLIBINTL) -xineplug_decode_dvaudio_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/contrib/ffmpeg -I$(top_srcdir)/contrib/ffmpeg/libavutil diff --git a/src/combined/ffmpeg/ff_audio_decoder.c b/src/combined/ffmpeg/ff_audio_decoder.c index f79014fde..b7f966325 100644 --- a/src/combined/ffmpeg/ff_audio_decoder.c +++ b/src/combined/ffmpeg/ff_audio_decoder.c @@ -22,9 +22,6 @@ #ifdef HAVE_CONFIG_H #include "config.h" -# ifndef HAVE_FFMPEG -# include "ffmpeg_config.h" -# endif #endif #include <stdlib.h> @@ -432,105 +429,39 @@ void *init_audio_plugin (xine_t *xine, void *data) { } static const uint32_t supported_audio_types[] = { -#if defined(HAVE_FFMPEG) || CONFIG_WMAV1_DECODER BUF_AUDIO_WMAV1, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_WMAV2_DECODER BUF_AUDIO_WMAV2, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_RA_144_DECODER BUF_AUDIO_14_4, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_RA_288_DECODER BUF_AUDIO_28_8, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_MP3_DECODER BUF_AUDIO_MPEG, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_ADPCM_MS_DECODER BUF_AUDIO_MSADPCM, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_ADPCM_IMA_QT_DECODER BUF_AUDIO_QTIMAADPCM, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_ADPCM_IMA_WAV_DECODER BUF_AUDIO_MSIMAADPCM, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_ADPCM_IMA_DK3_DECODER BUF_AUDIO_DK3ADPCM, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_ADPCM_IMA_DK4_DECODER BUF_AUDIO_DK4ADPCM, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_ADPCM_IMA_WS_DECODER BUF_AUDIO_VQA_IMA, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_ADPCM_IMA_SMJPEG_DECODER BUF_AUDIO_SMJPEG_IMA, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_ADPCM_XA_DECODER BUF_AUDIO_XA_ADPCM, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_ADPCM_4XM_DECODER BUF_AUDIO_4X_ADPCM, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_ADPCM_EA_DECODER BUF_AUDIO_EA_ADPCM, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_PCM_MULAW_DECODER BUF_AUDIO_MULAW, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_PCM_ALAW_DECODER BUF_AUDIO_ALAW, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_ROQ_DPCM_DECODER BUF_AUDIO_ROQ, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_INTERPLAY_DPCM_DECODER BUF_AUDIO_INTERPLAY, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_MACE3_DECODER BUF_AUDIO_MAC3, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_MACE6_DECODER BUF_AUDIO_MAC6, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_XAN_DPCM_DECODER BUF_AUDIO_XAN_DPCM, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_VMDAUDIO_DECODER BUF_AUDIO_VMD, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_FLAC_DECODER BUF_AUDIO_FLAC, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_SHORTEN_DECODER BUF_AUDIO_SHORTEN, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_ALAC_DECODER BUF_AUDIO_ALAC, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_QDM2_DECODER BUF_AUDIO_QDESIGN2, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_COOK_DECODER BUF_AUDIO_COOK, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_TRUESPEECH_DECODER BUF_AUDIO_TRUESPEECH, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_TTA_DECODER BUF_AUDIO_TTA, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_SMACKAUDIO_DECODER BUF_AUDIO_SMACKER, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_ADPCM_SWF_DECODER BUF_AUDIO_FLVADPCM, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_WAVPACK_DECODER BUF_AUDIO_WAVPACK, -#endif 0 }; diff --git a/src/combined/ffmpeg/ff_dvaudio_decoder.c b/src/combined/ffmpeg/ff_dvaudio_decoder.c deleted file mode 100644 index be7e8025f..000000000 --- a/src/combined/ffmpeg/ff_dvaudio_decoder.c +++ /dev/null @@ -1,417 +0,0 @@ -/* - * Copyright (C) 2005 the xine project - * - * This file is part of xine, a free video player. - * - * xine 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 - * (at your option) any later version. - * - * xine 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. - * - * 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, USA - * - * dv audio decoder based on patch by Dan Dennedy <dan@dennedy.org> - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdlib.h> -#include <stdio.h> -#include <inttypes.h> -#include <string.h> -#include <math.h> - -#define LOG_MODULE "dvaudio" -#define LOG_VERBOSE -/* -#define LOG -*/ - -#include <xine/xine_internal.h> -#include <xine/buffer.h> -#include <xine/xineutils.h> - -#ifdef _MSC_VER -/* ffmpeg has own definitions of those types */ -# undef int8_t -# undef uint8_t -# undef int16_t -# undef uint16_t -# undef int32_t -# undef uint32_t -# undef int64_t -# undef uint64_t -#endif - -#ifdef HAVE_FFMPEG_AVCODEC_H -# include <avcodec.h> -#else -# include <libavcodec/avcodec.h> -#endif - -#include <libavcodec/dvdata.h> /* This is not installed by FFmpeg, its usage has to be cleared up */ - -#ifdef _MSC_VER -# undef malloc -# undef free -# undef realloc -#endif - -#define AUDIOBUFSIZE 128*1024 -#define MAXFRAMESIZE 131072 - - -typedef struct { - audio_decoder_class_t decoder_class; -} dvaudio_class_t; - -typedef struct dvaudio_decoder_s { - audio_decoder_t audio_decoder; - - xine_stream_t *stream; - - int output_open; - int audio_channels; - int audio_bits; - int audio_sample_rate; - - unsigned char *buf; - int bufsize; - int size; - - char *decode_buffer; - int decoder_ok; - -} dvaudio_decoder_t; - -/* - * This is the dumbest implementation of all -- it simply looks at - * a fixed offset and if pack isn't there -- fails. We might want - * to have a fallback mechanism for complete search of missing packs. - */ -static const uint8_t* dv_extract_pack(uint8_t* frame, enum dv_pack_type t) -{ - int offs; - - switch (t) { - case dv_audio_source: - offs = (80*6 + 80*16*3 + 3); - break; - case dv_audio_control: - offs = (80*6 + 80*16*4 + 3); - break; - case dv_video_control: - offs = (80*5 + 48 + 5); - break; - default: - return NULL; - } - - return (frame[offs] == t ? &frame[offs] : NULL); -} - -static inline uint16_t dv_audio_12to16(uint16_t sample) -{ - uint16_t shift, result; - - sample = (sample < 0x800) ? sample : sample | 0xf000; - shift = (sample & 0xf00) >> 8; - - if (shift < 0x2 || shift > 0xd) { - result = sample; - } else if (shift < 0x8) { - shift--; - result = (sample - (256 * shift)) << shift; - } else { - shift = 0xe - shift; - result = ((sample + ((256 * shift) + 1)) << shift) - 1; - } - - return result; -} - -/* - * There's a couple of assumptions being made here: - * 1. By default we silence erroneous (0x8000/16bit 0x800/12bit) audio samples. - * We can pass them upwards when ffmpeg will be ready to deal with them. - * 2. We don't do software emphasis. - * 3. Audio is always returned as 16bit linear samples: 12bit nonlinear samples - * are converted into 16bit linear ones. - */ -static int dv_extract_audio(uint8_t* frame, uint8_t* pcm, uint8_t* pcm2) -{ - int size, i, j, d, of, smpls, freq, quant, half_ch; - uint16_t lc, rc; - const DVprofile* sys; - const uint8_t* as_pack; - - as_pack = dv_extract_pack(frame, dv_audio_source); - if (!as_pack) /* No audio ? */ - return 0; - - sys = dv_frame_profile(frame); - smpls = as_pack[1] & 0x3f; /* samples in this frame - min. samples */ - freq = (as_pack[4] >> 3) & 0x07; /* 0 - 48KHz, 1 - 44,1kHz, 2 - 32 kHz */ - quant = as_pack[4] & 0x07; /* 0 - 16bit linear, 1 - 12bit nonlinear */ - - if (quant > 1) - return -1; /* Unsupported quantization */ - - size = (sys->audio_min_samples[freq] + smpls) * 4; /* 2ch, 2bytes */ - half_ch = sys->difseg_size/2; - - /* for each DIF segment */ - for (i = 0; i < sys->difseg_size; i++) { - frame += 6 * 80; /* skip DIF segment header */ - if (quant == 1 && i == half_ch) { - if (!pcm2) - break; - else - pcm = pcm2; - } - - for (j = 0; j < 9; j++) { - for (d = 8; d < 80; d += 2) { - if (quant == 0) { /* 16bit quantization */ - of = sys->audio_shuffle[i][j] + (d - 8)/2 * sys->audio_stride; - if (of*2 >= size) - continue; - -#ifdef WORDS_BIGENDIAN - pcm[of*2] = frame[d]; - pcm[of*2+1] = frame[d+1]; -#else - pcm[of*2] = frame[d+1]; - pcm[of*2+1] = frame[d]; -#endif - if (pcm[of*2+1] == 0x80 && pcm[of*2] == 0x00) - pcm[of*2+1] = 0; - } else { /* 12bit quantization */ - lc = ((uint16_t)frame[d] << 4) | - ((uint16_t)frame[d+2] >> 4); - rc = ((uint16_t)frame[d+1] << 4) | - ((uint16_t)frame[d+2] & 0x0f); - lc = (lc == 0x800 ? 0 : dv_audio_12to16(lc)); - rc = (rc == 0x800 ? 0 : dv_audio_12to16(rc)); - - of = sys->audio_shuffle[i%half_ch][j] + (d - 8)/3 * sys->audio_stride; - if (of*2 >= size) - continue; - -#ifdef WORDS_BIGENDIAN - pcm[of*2] = lc >> 8; - pcm[of*2+1] = lc & 0xff; -#else - pcm[of*2] = lc & 0xff; - pcm[of*2+1] = lc >> 8; -#endif - of = sys->audio_shuffle[i%half_ch+half_ch][j] + - (d - 8)/3 * sys->audio_stride; -#ifdef WORDS_BIGENDIAN - pcm[of*2] = rc >> 8; - pcm[of*2+1] = rc & 0xff; -#else - pcm[of*2] = rc & 0xff; - pcm[of*2+1] = rc >> 8; -#endif - ++d; - } - } - - frame += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */ - } - } - - return size; -} - -static void dvaudio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { - - dvaudio_decoder_t *this = (dvaudio_decoder_t *) this_gen; - int bytes_consumed; - int decode_buffer_size; - int offset; - int out; - audio_buffer_t *audio_buffer; - int bytes_to_send; - - if (buf->decoder_flags & BUF_FLAG_PREVIEW) - return; - - if (buf->decoder_flags & BUF_FLAG_STDHEADER) { - this->buf = xine_xmalloc(AUDIOBUFSIZE); - this->bufsize = AUDIOBUFSIZE; - this->size = 0; - this->decode_buffer = xine_xmalloc(MAXFRAMESIZE); - - this->audio_sample_rate = buf->decoder_info[1]; - this->audio_bits = buf->decoder_info[2]; - this->audio_channels = buf->decoder_info[3]; - - _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "DV Audio"); - - this->decoder_ok = 1; - - return; - } - - if (this->decoder_ok && !(buf->decoder_flags & (BUF_FLAG_HEADER|BUF_FLAG_SPECIAL))) { - - if (!this->output_open) { - this->output_open = (this->stream->audio_out->open) (this->stream->audio_out, - this->stream, this->audio_bits, this->audio_sample_rate, - _x_ao_channels2mode(this->audio_channels)); - } - - /* if the audio still isn't open, bail */ - if (!this->output_open) - return; - - if( this->size + buf->size > this->bufsize ) { - this->bufsize = this->size + 2 * buf->size; - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - _("dvaudio: increasing buffer to %d to avoid overflow.\n"), - this->bufsize); - this->buf = realloc( this->buf, this->bufsize ); - } - - xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); - this->size += buf->size; - - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { /* time to decode a frame */ - - offset = 0; - while (this->size>0) { - decode_buffer_size = dv_extract_audio(&this->buf[offset], this->decode_buffer, NULL); - - if (decode_buffer_size > -1) - bytes_consumed = dv_frame_profile(&this->buf[offset])->frame_size; - else - bytes_consumed = decode_buffer_size; - - /* dispatch the decoded audio */ - out = 0; - while (out < decode_buffer_size) { - audio_buffer = - this->stream->audio_out->get_buffer (this->stream->audio_out); - if (audio_buffer->mem_size == 0) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "dvaudio: Help! Allocated audio buffer with nothing in it!\n"); - return; - } - - if ((decode_buffer_size - out) > audio_buffer->mem_size) - bytes_to_send = audio_buffer->mem_size; - else - bytes_to_send = decode_buffer_size - out; - - /* fill up this buffer */ - xine_fast_memcpy(audio_buffer->mem, &this->decode_buffer[out], - bytes_to_send); - /* byte count / 2 (bytes / sample) / channels */ - audio_buffer->num_frames = bytes_to_send / 2 / this->audio_channels; - - audio_buffer->vpts = buf->pts; - buf->pts = 0; /* only first buffer gets the real pts */ - this->stream->audio_out->put_buffer (this->stream->audio_out, - audio_buffer, this->stream); - - out += bytes_to_send; - } - - this->size -= bytes_consumed; - offset += bytes_consumed; - } - - /* reset internal accumulation buffer */ - this->size = 0; - } - } -} - -static void dvaudio_reset (audio_decoder_t *this_gen) { - dvaudio_decoder_t *this = (dvaudio_decoder_t *) this_gen; - - this->size = 0; -} - -static void dvaudio_discontinuity (audio_decoder_t *this_gen) { -} - -static void dvaudio_dispose (audio_decoder_t *this_gen) { - - dvaudio_decoder_t *this = (dvaudio_decoder_t *) this_gen; - - if (this->output_open) - this->stream->audio_out->close (this->stream->audio_out, this->stream); - this->output_open = 0; - - free(this->buf); - free(this->decode_buffer); - - free (this_gen); -} - -static audio_decoder_t *dvaudio_open_plugin (audio_decoder_class_t *class_gen, xine_stream_t *stream) { - - dvaudio_decoder_t *this ; - - this = (dvaudio_decoder_t *) xine_xmalloc (sizeof (dvaudio_decoder_t)); - - this->audio_decoder.decode_data = dvaudio_decode_data; - this->audio_decoder.reset = dvaudio_reset; - this->audio_decoder.discontinuity = dvaudio_discontinuity; - this->audio_decoder.dispose = dvaudio_dispose; - - this->output_open = 0; - this->audio_channels = 0; - this->stream = stream; - this->buf = NULL; - this->size = 0; - this->decoder_ok = 0; - - return &this->audio_decoder; -} - -static void *init_dvaudio_plugin (xine_t *xine, void *data) { - - dvaudio_class_t *this ; - - this = (dvaudio_class_t *) xine_xmalloc (sizeof (dvaudio_class_t)); - - this->decoder_class.open_plugin = dvaudio_open_plugin; - this->decoder_class.identifier = "dv audio"; - this->decoder_class.description = N_("dv audio decoder plugin"); - this->decoder_class.dispose = default_audio_decoder_class_dispose; - - return this; -} - -static uint32_t supported_audio_types[] = { - BUF_AUDIO_DV, - 0 -}; - -static const decoder_info_t dec_info_dvaudio = { - supported_audio_types, /* supported types */ - 5 /* priority */ -}; - -/* - * exported plugin catalog entry - */ - -const plugin_info_t xine_plugin_info[] EXPORTED = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_AUDIO_DECODER, 16, "dvaudio", XINE_VERSION_CODE, &dec_info_dvaudio, init_dvaudio_plugin }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; diff --git a/src/combined/ffmpeg/ff_video_decoder.c b/src/combined/ffmpeg/ff_video_decoder.c index 845ef5d79..7cb584593 100644 --- a/src/combined/ffmpeg/ff_video_decoder.c +++ b/src/combined/ffmpeg/ff_video_decoder.c @@ -22,9 +22,6 @@ #ifdef HAVE_CONFIG_H #include "config.h" -# ifndef HAVE_FFMPEG -# include "ffmpeg_config.h" -# endif #endif #include <stdlib.h> @@ -1626,229 +1623,83 @@ void *init_video_plugin (xine_t *xine, void *data) { } static const uint32_t supported_video_types[] = { -#if defined(HAVE_FFMPEG) || CONFIG_MSMPEG4V1_DECODER BUF_VIDEO_MSMPEG4_V1, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_MSMPEG4V2_DECODER BUF_VIDEO_MSMPEG4_V2, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_MSMPEG4V3_DECODER BUF_VIDEO_MSMPEG4_V3, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_WMV1_DECODER BUF_VIDEO_WMV7, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_WMV2_DECODER BUF_VIDEO_WMV8, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_WMV3_DECODER BUF_VIDEO_WMV9, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_VC1_DECODER BUF_VIDEO_VC1, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_MPEG4_DECODER BUF_VIDEO_MPEG4, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_MPEG4_DECODER BUF_VIDEO_XVID, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_MPEG4_DECODER BUF_VIDEO_DIVX5, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_MPEG4_DECODER BUF_VIDEO_3IVX, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_MJPEG_DECODER BUF_VIDEO_JPEG, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_MJPEG_DECODER BUF_VIDEO_MJPEG, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_MJPEGB_DECODER BUF_VIDEO_MJPEG_B, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_H263I_DECODER BUF_VIDEO_I263, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_H263_DECODER BUF_VIDEO_H263, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_RV10_DECODER BUF_VIDEO_RV10, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_RV20_DECODER BUF_VIDEO_RV20, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_INDEO3_DECODER BUF_VIDEO_IV31, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_INDEO3_DECODER BUF_VIDEO_IV32, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_SVQ1_DECODER BUF_VIDEO_SORENSON_V1, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_SVQ3_DECODER BUF_VIDEO_SORENSON_V3, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_DVVIDEO_DECODER BUF_VIDEO_DV, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_HUFFYUV_DECODER BUF_VIDEO_HUFFYUV, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_VP3_DECODER BUF_VIDEO_VP31, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_VP5_DECODER BUF_VIDEO_VP5, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_VP6_DECODER BUF_VIDEO_VP6, BUF_VIDEO_VP6F, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_4XM_DECODER BUF_VIDEO_4XM, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_CINEPAK_DECODER BUF_VIDEO_CINEPAK, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_MSVIDEO1_DECODER BUF_VIDEO_MSVC, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_MSRLE_DECODER BUF_VIDEO_MSRLE, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_RPZA_DECODER BUF_VIDEO_RPZA, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_CYUV_DECODER BUF_VIDEO_CYUV, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_ROQ_DECODER BUF_VIDEO_ROQ, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_IDCIN_DECODER BUF_VIDEO_IDCIN, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_XAN_WC3_DECODER BUF_VIDEO_WC3, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_WS_VQA_DECODER BUF_VIDEO_VQA, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_INTERPLAY_VIDEO_DECODER BUF_VIDEO_INTERPLAY, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_FLIC_DECODER BUF_VIDEO_FLI, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_8BPS_DECODER BUF_VIDEO_8BPS, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_SMC_DECODER BUF_VIDEO_SMC, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_TRUEMOTION1_DECODER BUF_VIDEO_DUCKTM1, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_TRUEMOTION2_DECODER BUF_VIDEO_DUCKTM2, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_VMDVIDEO_DECODER BUF_VIDEO_VMD, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_ZLIB_DECODER BUF_VIDEO_ZLIB, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_MSZH_DECODER BUF_VIDEO_MSZH, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_ASV1_DECODER BUF_VIDEO_ASV1, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_ASV2_DECODER BUF_VIDEO_ASV2, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_VCR1_DECODER BUF_VIDEO_ATIVCR1, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_FLV_DECODER BUF_VIDEO_FLV1, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_QTRLE_DECODER BUF_VIDEO_QTRLE, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_H264_DECODER BUF_VIDEO_H264, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_H261_DECODER BUF_VIDEO_H261, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_AASC_DECODER BUF_VIDEO_AASC, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_LOCO_DECODER BUF_VIDEO_LOCO, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_QDRAW_DECODER BUF_VIDEO_QDRW, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_QPEG_DECODER BUF_VIDEO_QPEG, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_TSCC_DECODER BUF_VIDEO_TSCC, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_ULTI_DECODER BUF_VIDEO_ULTI, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_WNV1_DECODER BUF_VIDEO_WNV1, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_VIXL_DECODER BUF_VIDEO_XL, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_INDEO2_DECODER BUF_VIDEO_RT21, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_FRAPS_DECODER BUF_VIDEO_FPS1, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_MPEG1VIDEO_DECODER BUF_VIDEO_MPEG, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_CSCD_DECODER BUF_VIDEO_CSCD, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_AVS_DECODER BUF_VIDEO_AVS, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_MMVIDEO_DECODER BUF_VIDEO_ALGMM, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_ZMBV_DECODER BUF_VIDEO_ZMBV, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_SMACKVIDEO_DECODER BUF_VIDEO_SMACKER, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_NUV_DECODER BUF_VIDEO_NUV, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_KMVC_DECODER BUF_VIDEO_KMVC, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_FLASHSV_DECODER BUF_VIDEO_FLASHSV, -#endif -#if defined(HAVE_FFMPEG) || CONFIG_CAVS_DECODER BUF_VIDEO_CAVS, #endif #if defined(HAVE_FFMPEG) || CONFIG_VMNC_DECODER BUF_VIDEO_VMNC, -#endif BUF_VIDEO_THEORA_RAW, 0 }; diff --git a/src/combined/ffmpeg/ffmpeg_encoder.c b/src/combined/ffmpeg/ffmpeg_encoder.c deleted file mode 100644 index 7fe65c7fa..000000000 --- a/src/combined/ffmpeg/ffmpeg_encoder.c +++ /dev/null @@ -1,328 +0,0 @@ -/* - * Copyright (C) 2000-2004 the xine project - * - * This file is part of xine, a unix video player. - * - * xine 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 - * (at your option) any later version. - * - * xine 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. - * - * 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, USA - */ - -/* mpeg encoders for the dxr3 video out plugin. */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdio.h> -#include <stdlib.h> -#include <sys/ioctl.h> -#include <fcntl.h> -#include <unistd.h> -#include <errno.h> -#include <math.h> - -#define LOG_MODULE "dxr3_mpeg_encoder" -/* #define LOG_VERBOSE */ -/* #define LOG */ - -#include "video_out_dxr3.h" - -#include <avcodec.h> - -/* buffer size for encoded mpeg1 stream; will hold one intra frame - * at 640x480 typical sizes are <50 kB. 512 kB should be plenty */ -#define DEFAULT_BUFFER_SIZE 512*1024 - - -/*initialisation function, used by the dxr3 plugin */ -int dxr3_encoder_init(dxr3_driver_t *drv) EXPORTED; - -/* functions required by encoder api */ -static int lavc_on_update_format(dxr3_driver_t *drv, dxr3_frame_t *frame); -static int lavc_on_display_frame(dxr3_driver_t *drv, dxr3_frame_t *frame); -static int lavc_on_unneeded(dxr3_driver_t *drv); - -/*encoder structure*/ -typedef struct lavc_data_s { - encoder_data_t encoder_data; - AVCodecContext *context; /* handle for encoding */ - int width, height; /* width and height of the video frame */ - uint8_t *ffmpeg_buffer; /* lavc buffer */ - AVFrame *picture; /* picture to be encoded */ - uint8_t *out[3]; /* aligned buffer for YV12 data */ - uint8_t *buf; /* unaligned YV12 buffer */ -} lavc_data_t; - - -int dxr3_encoder_init(dxr3_driver_t *drv) -{ - lavc_data_t* this; - avcodec_init(); - - avcodec_register_all(); - lprintf("lavc init , version %x\n", avcodec_version()); - this = xine_xmalloc(sizeof(lavc_data_t)); - if (!this) return 0; - - this->encoder_data.type = ENC_LAVC; - this->encoder_data.on_update_format = lavc_on_update_format; - this->encoder_data.on_frame_copy = NULL; - this->encoder_data.on_display_frame = lavc_on_display_frame; - this->encoder_data.on_unneeded = lavc_on_unneeded; - this->context = 0; - - drv->enc = &this->encoder_data; - return 1; -} - -/* helper function */ -static int lavc_prepare_frame(lavc_data_t *this, dxr3_driver_t *drv, dxr3_frame_t *frame); - -static int lavc_on_update_format(dxr3_driver_t *drv, dxr3_frame_t *frame) -{ - lavc_data_t *this = (lavc_data_t *)drv->enc; - AVCodec *codec; - unsigned char use_quantizer; - - if (this->context) { - avcodec_close(this->context); - free(this->context); - free(this->picture); - this->context = NULL; - this->picture = NULL; - } - - /* if YUY2 and dimensions changed, we need to re-allocate the - * internal YV12 buffer */ - if (frame->vo_frame.format == XINE_IMGFMT_YUY2) { - int image_size = frame->vo_frame.pitches[0] * frame->oheight; - - this->out[0] = xine_xmalloc_aligned(16, image_size * 3/2, - (void *)&this->buf); - this->out[1] = this->out[0] + image_size; - this->out[2] = this->out[1] + image_size/4; - - /* fill with black (yuv 16,128,128) */ - memset(this->out[0], 16, image_size); - memset(this->out[1], 128, image_size/4); - memset(this->out[2], 128, image_size/4); - lprintf("Using YUY2->YV12 conversion\n"); - } - - /* resolution must be a multiple of two */ - if ((frame->vo_frame.pitches[0] % 2 != 0) || (frame->oheight % 2 != 0)) { - xprintf(drv->class->xine, XINE_VERBOSITY_LOG, - "dxr3_mpeg_encoder: lavc only handles video dimensions which are multiples of 2\n"); - return 0; - } - - /* get mpeg codec handle */ - codec = avcodec_find_encoder(CODEC_ID_MPEG1VIDEO); - if (!codec) { - xprintf(drv->class->xine, XINE_VERBOSITY_LOG, - "dxr3_mpeg_encoder: lavc MPEG1 codec not found\n"); - return 0; - } - lprintf("lavc MPEG1 encoder found.\n"); - - this->width = frame->vo_frame.pitches[0]; - this->height = frame->oheight; - - this->context = avcodec_alloc_context(); - if (!this->context) { - xprintf(drv->class->xine, XINE_VERBOSITY_LOG, - "dxr3_mpeg_encoder: Couldn't start the ffmpeg library\n"); - return 0; - } - this->picture = avcodec_alloc_frame(); - if (!this->picture) { - xprintf(drv->class->xine, XINE_VERBOSITY_LOG, - "dxr3_mpeg_encoder: Couldn't allocate ffmpeg frame\n"); - return 0; - } - - /* mpeg1 encoder only support YUV420P */ - this->context->pix_fmt = PIX_FMT_YUVJ420P; - - /* put sample parameters */ - this->context->bit_rate = drv->class->xine->config->register_range(drv->class->xine->config, - "dxr3.encoding.lavc_bitrate", 10000, 1000, 20000, - _("libavcodec mpeg output bitrate (kbit/s)"), - _("The bitrate the libavcodec mpeg encoder should use for DXR3's encoding mode. " - "Higher values will increase quality and CPU usage.\n" - "This setting is only considered, when constant quality mode is disabled."), 10, NULL, NULL); - this->context->bit_rate *= 1000; /* config in kbit/s, libavcodec wants bit/s */ - - use_quantizer = drv->class->xine->config->register_bool(drv->class->xine->config, - "dxr3.encoding.lavc_quantizer", 1, - _("constant quality mode"), - _("When enabled, libavcodec will use a constant quality mode by dynamically " - "compressing the images based on their complexity. When disabled, libavcodec " - "will use constant bitrate mode."), 10, NULL, NULL); - - if (use_quantizer) { - this->context->qmin = drv->class->xine->config->register_range(drv->class->xine->config, - "dxr3.encoding.lavc_qmin", 1, 1, 10, - _("minimum compression"), - _("The minimum compression to apply to an image in constant quality mode."), - 10, NULL, NULL); - - this->context->qmax = drv->class->xine->config->register_range(drv->class->xine->config, - "dxr3.encoding.lavc_qmax", 2, 1, 20, - _("maximum quantizer"), - _("The maximum compression to apply to an image in constant quality mode."), - 10, NULL, NULL); - } - - lprintf("lavc -> bitrate %d \n", this->context->bit_rate); - - this->context->width = frame->vo_frame.pitches[0]; - this->context->height = frame->oheight; - - this->context->gop_size = 0; /*intra frames only */ - this->context->me_method = ME_ZERO; /*motion estimation type*/ - - this->context->time_base.den = 90000; - if (frame->vo_frame.duration > 90000 / 24) - this->context->time_base.num = 90000 / 24; - else if (frame->vo_frame.duration < 90000 / 60) - this->context->time_base.num = 90000 / 60; - else - this->context->time_base.num = frame->vo_frame.duration; - /* ffmpeg can complain about illegal framerates, but since this seems no - * problem for the DXR3, we just tell ffmpeg to be more lax with */ - this->context->strict_std_compliance = -1; - - /* open avcodec */ - if (avcodec_open(this->context, codec) < 0) { - xprintf(drv->class->xine, XINE_VERBOSITY_LOG, "dxr3_mpeg_encoder: could not open codec\n"); - return 0; - } - lprintf("dxr3_mpeg_encoder: lavc MPEG1 codec opened.\n"); - - if (!this->ffmpeg_buffer) - this->ffmpeg_buffer = (unsigned char *)malloc(DEFAULT_BUFFER_SIZE); /* why allocate more than needed ?! */ - if (!this->ffmpeg_buffer) { - xprintf(drv->class->xine, XINE_VERBOSITY_LOG, - "dxr3_mpeg_encoder: Couldn't allocate temp buffer for mpeg data\n"); - return 0; - } - - return 1; -} - -static int lavc_on_display_frame(dxr3_driver_t *drv, dxr3_frame_t *frame) -{ - int size; - lavc_data_t* this = (lavc_data_t *)drv->enc; - ssize_t written; - - if (frame->vo_frame.bad_frame) return 1; - /* ignore old frames */ - if ((frame->vo_frame.pitches[0] != this->context->width) || (frame->oheight != this->context->height)) { - frame->vo_frame.free(&frame->vo_frame); - lprintf("LAVC ignoring frame !!!\n"); - return 1; - } - - /* prepare frame for conversion, handles YUY2 -> YV12 conversion when necessary */ - lavc_prepare_frame(this, drv, frame); - - /* do the encoding */ - size = avcodec_encode_video(this->context, this->ffmpeg_buffer, DEFAULT_BUFFER_SIZE, this->picture); - - frame->vo_frame.free(&frame->vo_frame); - - if (size < 0) { - xprintf(drv->class->xine, XINE_VERBOSITY_LOG, - "dxr3_mpeg_encoder: encoding failed\n"); - return 0; - } - - written = write(drv->fd_video, this->ffmpeg_buffer, size); - if (written < 0) { - xprintf(drv->class->xine, XINE_VERBOSITY_LOG, - "dxr3_mpeg_encoder: video device write failed (%s)\n", strerror(errno)); - return 0; - } - if (written != size) - xprintf(drv->class->xine, XINE_VERBOSITY_LOG, - "dxr3_mpeg_encoder: Could only write %zd of %d mpeg bytes.\n", written, size); - return 1; -} - -static int lavc_on_unneeded(dxr3_driver_t *drv) -{ - lavc_data_t *this = (lavc_data_t *)drv->enc; - lprintf("flushing buffers\n"); - if (this->context) { - avcodec_close(this->context); - free(this->context); - free(this->picture); - this->context = NULL; - this->picture = NULL; - } - return 1; -} - -static int lavc_prepare_frame(lavc_data_t *this, dxr3_driver_t *drv, dxr3_frame_t *frame) -{ - int i, j, w2; - uint8_t *yuy2; - - if (frame->vo_frame.bad_frame) return 1; - - if (frame->vo_frame.format == XINE_IMGFMT_YUY2) { - /* need YUY2->YV12 conversion */ - if (!(this->out[0] && this->out[1] && this->out[2]) ) { - lprintf("Internal YV12 buffer not created.\n"); - return 0; - } - this->picture->data[0] = this->out[0] + frame->vo_frame.pitches[0] * drv->top_bar; /* y */ - this->picture->data[1] = this->out[1] + (frame->vo_frame.pitches[0] / 2) * (drv->top_bar / 2); /* u */ - this->picture->data[2] = this->out[2] + (frame->vo_frame.pitches[0] / 2) * (drv->top_bar / 2); /* v */ - yuy2 = frame->vo_frame.base[0]; - w2 = frame->vo_frame.pitches[0] / 2; - for (i = 0; i < frame->vo_frame.height; i += 2) { - for (j = 0; j < w2; j++) { - /* packed YUV 422 is: Y[i] U[i] Y[i+1] V[i] */ - *(this->picture->data[0]++) = *(yuy2++); - *(this->picture->data[1]++) = *(yuy2++); - *(this->picture->data[0]++) = *(yuy2++); - *(this->picture->data[2]++) = *(yuy2++); - } - /* down sampling */ - for (j = 0; j < w2; j++) { - /* skip every second line for U and V */ - *(this->picture->data[0]++) = *(yuy2++); - yuy2++; - *(this->picture->data[0]++) = *(yuy2++); - yuy2++; - } - } - /* reset for encoder */ - this->picture->data[0] = this->out[0]; - this->picture->data[1] = this->out[1]; - this->picture->data[2] = this->out[2]; - } - else { /* YV12 **/ - this->picture->data[0] = frame->real_base[0]; - this->picture->data[1] = frame->real_base[1]; - this->picture->data[2] = frame->real_base[2]; - } - this->picture->linesize[0] = this->context->width; - this->picture->linesize[1] = this->context->width / 2; - this->picture->linesize[2] = this->context->width / 2; - return 1; -} |