Sophie

Sophie

distrib > Arklinux > devel > x86_64 > media > main-src > by-pkgid > 8e6c5dbb99d83d77d4e45979d4b2c327 > files > 3

vlc-1.1.12-1ark.src.rpm

--- vlc/configure.ac.xvid~	2007-07-03 14:15:00.000000000 +0200
+++ vlc/configure.ac	2007-07-03 14:15:00.000000000 +0200
@@ -3780,6 +3780,20 @@
 fi
 
 dnl
+dnl MPEG-4 encoder plugin (using xvid)
+dnl
+AC_ARG_ENABLE(xvid,
+  [  --enable-xvid           MPEG-4 encoding support with xvid (default enabled)])
+if test "${enable_xvid}" != "no"; then
+  LDFLAGS="${LDFLAGS_save} ${LDFLAGS_xvid}"
+  AC_CHECK_HEADERS(xvid.h, [
+      VLC_ADD_PLUGINS([xvid])
+      VLC_ADD_LDFLAGS([xvid],[-lxvidcore])
+  ])
+  LDFLAGS="${LDFLAGS_save}"
+fi
+
+dnl
 dnl  CMML plugin
 dnl
 AC_ARG_ENABLE(cmml,
--- vlc/modules/codec/Modules.am.xvid~	2007-03-22 18:39:55.000000000 +0100
+++ vlc/modules/codec/Modules.am	2007-07-03 14:15:00.000000000 +0200
@@ -28,4 +28,5 @@
 SOURCES_cvdsub = cvdsub.c
 SOURCES_fake = fake.c
 SOURCES_realaudio = realaudio.c
+SOURCES_xvid = xvidenc.c
 SOURCES_sdl_image = sdl_image.c
--- vlc/modules/codec/xvidenc.c.xvid~	2007-07-03 14:15:00.000000000 +0200
+++ vlc/modules/codec/xvidenc.c	2007-07-03 14:15:00.000000000 +0200
@@ -0,0 +1,287 @@
+/*****************************************************************************
+ * xvidenc.c: xvid video encoder
+ *****************************************************************************
+ * Copyright (C) 2004 LINUX4MEDIA GmbH
+ * $Id$
+ *
+ * Authors: Bernhard Rosenkraenzer <bero@arklinux.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
+ * (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.
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA  0211, USA.
+ ****************************************************************************/
+
+/****************************************************************************
+ * Preamble
+ ****************************************************************************/
+#include <vlc/vlc.h>
+#include <vlc/vout.h>
+#include <vlc/sout.h>
+#include <vlc/decoder.h>
+
+#include <xvid.h>
+
+#define SOUT_CFG_PREFIX "sout-xvid-"
+
+/****************************************************************************
+ * Module descriptor
+ ****************************************************************************/
+static int  Open ( vlc_object_t * );
+static void Close( vlc_object_t * );
+
+vlc_module_begin();
+    set_description( _("MPEG-4 video encoder using the xvid library"));
+    set_capability( "encoder", 200 );
+    set_callbacks( Open, Close );
+vlc_module_end();
+
+/****************************************************************************
+ * Local prototypes
+ ****************************************************************************/
+static const char *ppsz_sout_options[] = {
+    NULL
+};
+
+static block_t *Encode( encoder_t *, picture_t * );
+
+struct encoder_sys_t
+{
+    xvid_plugin_single_t	xvid_1pass;
+    xvid_enc_create_t		xvid_enc;
+    xvid_enc_plugin_t		xvid_plugins[1];
+    xvid_gbl_init_t		xvid_init;
+    uint8_t			*buffer;
+};
+
+/****************************************************************************
+ * Chroma fourcc -> xvid_id mapping
+ ****************************************************************************/
+static struct
+{
+    vlc_fourcc_t		i_chroma;
+    int				i_chroma_id;
+} chroma_table[] =
+{
+    { VLC_FOURCC('I', '4', '2', '0'), XVID_CSP_I420 },
+    { VLC_FOURCC('Y', 'V', '1', '2'), XVID_CSP_YV12 },
+    { VLC_FOURCC('Y', 'U', 'Y', '2'), XVID_CSP_YUY2 },
+    { VLC_FOURCC('U', 'Y', 'V', 'Y'), XVID_CSP_UYVY },
+    { VLC_FOURCC('Y', 'V', 'Y', 'U'), XVID_CSP_YVYU },
+    { VLC_FOURCC('B', 'G', 'R', 'A'), XVID_CSP_BGRA },
+    { VLC_FOURCC('A', 'B', 'G', 'R'), XVID_CSP_ABGR },
+    { VLC_FOURCC('R', 'G', 'B', 'A'), XVID_CSP_RGBA },
+    { VLC_FOURCC('A', 'R', 'G', 'B'), XVID_CSP_ARGB },
+    { VLC_FOURCC('B', 'G', 'R', ' '), XVID_CSP_BGR },
+    { VLC_FOURCC('R', 'V', '1', '5'), XVID_CSP_RGB555 },
+    { VLC_FOURCC('R', 'V', '1', '6'), XVID_CSP_RGB565 },
+    { VLC_FOURCC('R', 'V', '3', '2'), XVID_CSP_RGBA },
+    { 0 }
+};
+
+int E_(GetXvidChroma)( vlc_fourcc_t i_chroma )
+{
+    int i;
+    for( i = 0; chroma_table[i].i_chroma; i++ )
+    {
+        if( chroma_table[i].i_chroma == i_chroma )
+            return chroma_table[i].i_chroma_id;
+    }
+    return -1;
+}
+
+vlc_fourcc_t E_(GetVlcChromaXvid)( int i_xvid_chroma )
+{
+    int i;
+    for( i = 0; chroma_table[i].i_chroma; i++ )
+    {
+        if( chroma_table[i].i_chroma_id == i_xvid_chroma )
+		return chroma_table[i].i_chroma;
+    }
+    return 0;
+}
+
+/****************************************************************************
+ * Stuff missing from the XVid API
+ ****************************************************************************/
+static const char *xvid_strerror(int err)
+{
+    const char *error;
+    switch(err) {
+    case XVID_ERR_FAIL:
+        error = "General failure";
+	break;
+    case XVID_ERR_MEMORY:
+	error = "Out of memory";
+	break;
+    case XVID_ERR_FORMAT:
+        error = "File format error";
+	break;
+    case XVID_ERR_VERSION:
+        error = "Wrong structure version";
+	break;
+    case XVID_ERR_END:
+        error = "End of stream reached";
+	break;
+    default:
+	error=(const char*)malloc(128);
+	snprintf(error, 128, "Unknown error #%d", err);
+    }
+    return error;
+}
+
+/****************************************************************************
+ * Open: probe the encoder
+ ****************************************************************************/
+static int  Open ( vlc_object_t *p_this )
+{
+    encoder_t     *p_enc = (encoder_t *)p_this;
+    encoder_sys_t *p_sys;
+    vlc_value_t    val;
+    int            result;
+
+    if( p_enc->fmt_out.i_codec != VLC_FOURCC( 'X', 'V', 'I', 'D' ) &&
+        !p_enc->b_force )
+    {
+        return VLC_EGENERIC;
+    }
+
+    sout_CfgParse( p_enc, SOUT_CFG_PREFIX, ppsz_sout_options, p_enc->p_cfg );
+
+    if( !E_(GetXvidChroma)( p_enc->fmt_out.i_codec ) < 0 )
+        return VLC_EGENERIC;
+
+    p_enc->fmt_in.i_codec = VLC_FOURCC( 'I', '4', '2', '0' );
+    p_enc->fmt_out.i_codec = VLC_FOURCC( 'X', 'V', 'I', 'D' );
+
+    p_enc->pf_encode_video = Encode;
+    p_enc->pf_encode_audio = NULL;
+    p_enc->p_sys = p_sys = malloc( sizeof( encoder_sys_t ) );
+
+    memset( &p_sys->xvid_1pass, 0, sizeof( xvid_plugin_single_t ) );
+    memset( &p_sys->xvid_enc, 0, sizeof( xvid_enc_create_t ) );
+    memset( &p_sys->xvid_plugins, 0, sizeof( xvid_enc_plugin_t ) * 2 );
+    memset( &p_sys->xvid_init, 0, sizeof( xvid_gbl_init_t ) );
+
+    p_sys->xvid_init.version = XVID_VERSION;
+    p_sys->xvid_init.debug = 0;
+
+    if ( (result = xvid_global( NULL, XVID_GBL_INIT, &p_sys->xvid_init, NULL ) ) < 0 ) {
+        msg_Warn( p_enc, "Failed to initialize xvid: %s", xvid_strerror(result) );
+	return VLC_EGENERIC;
+    }
+
+    p_sys->xvid_1pass.version = XVID_VERSION;
+    p_sys->xvid_1pass.bitrate = 1024000;
+
+    p_sys->xvid_enc.version = XVID_VERSION;
+    p_sys->xvid_enc.width = p_enc->fmt_in.video.i_width;
+    p_sys->xvid_enc.height = p_enc->fmt_in.video.i_height;
+    p_sys->xvid_enc.fincr = p_enc->fmt_in.video.i_frame_rate;
+    p_sys->xvid_enc.fbase = p_enc->fmt_in.video.i_frame_rate_base;
+    p_sys->xvid_enc.profile = XVID_PROFILE_AS_L4;
+    p_sys->xvid_enc.num_zones = 0;
+    p_sys->xvid_enc.plugins = p_sys->xvid_plugins;
+    p_sys->xvid_enc.num_plugins = 0;
+    p_sys->xvid_enc.max_key_interval = 250;
+    p_sys->xvid_enc.max_bframes = 2;
+    p_sys->xvid_enc.bquant_ratio = 150;
+    p_sys->xvid_enc.bquant_offset = 100;
+    p_sys->xvid_enc.frame_drop_ratio = 0;
+    p_sys->xvid_enc.global = 0;
+
+    p_sys->xvid_enc.plugins[p_sys->xvid_enc.num_plugins].func = xvid_plugin_single;
+    p_sys->xvid_enc.plugins[p_sys->xvid_enc.num_plugins++].param = &p_sys->xvid_1pass;
+
+    p_sys->buffer=(uint8_t*)malloc(p_sys->xvid_enc.width * p_sys->xvid_enc.height * 4 * 2);
+    
+    result=xvid_encore(NULL, XVID_ENC_CREATE, &p_sys->xvid_enc, NULL);
+    if ( result < 0 ) {
+        msg_Warn( p_enc, "Failed to initialize encoder: %s", xvid_strerror(result) );
+	return VLC_EGENERIC;
+    }
+
+    return VLC_SUCCESS;
+}
+
+/****************************************************************************
+ * Encode:
+ ****************************************************************************/
+static block_t *Encode( encoder_t *p_enc, picture_t *p_pict )
+{
+    encoder_sys_t *p_sys = p_enc->p_sys;
+
+    xvid_enc_frame_t frame;
+    xvid_enc_stats_t stats;
+
+    block_t *p_block;
+
+    int i, ret;
+
+    memset( &frame, 0, sizeof( xvid_enc_frame_t ) );
+    memset( &stats, 0, sizeof( xvid_enc_stats_t ) );
+
+    frame.version = XVID_VERSION;
+    stats.version = XVID_VERSION;
+
+    frame.bitstream = p_sys->buffer;
+    frame.input.csp = XVID_CSP_I420;
+    for( i = 0; i < p_pict->i_planes; i++ ) {
+    	frame.input.plane[i] = p_pict->p[i].p_pixels;
+	frame.input.stride[i] = p_pict->p[i].i_pitch;
+    }
+    frame.length = -1;
+    frame.vol_flags = XVID_VOL_GMC | XVID_VOL_QUARTERPEL;
+    frame.vop_flags = XVID_VOP_HALFPEL | XVID_VOP_INTER4V | XVID_VOP_TRELLISQUANT | XVID_VOP_HQACPRED;
+    frame.type = XVID_TYPE_AUTO;
+    frame.quant = 0;
+    frame.motion = XVID_ME_ADVANCEDDIAMOND16 | XVID_ME_HALFPELREFINE16 | XVID_ME_EXTSEARCH16 | XVID_ME_ADVANCEDDIAMOND8 | XVID_ME_HALFPELREFINE8 | XVID_ME_EXTSEARCH8 | XVID_ME_CHROMA_PVOP | XVID_ME_CHROMA_BVOP | XVID_ME_GME_REFINE | XVID_ME_QUARTERPELREFINE16 | XVID_ME_QUARTERPELREFINE8;
+
+    ret = xvid_encore( p_sys->xvid_enc.handle, XVID_ENC_ENCODE, &frame, &stats);
+    if ( ret < 0 ) {
+        msg_Warn( p_enc, "Failed to encode frame: %s", xvid_strerror(ret) );
+    }
+
+    p_block = block_New( p_enc, ret );
+    p_block->i_dts = p_pict->date;
+    p_block->i_pts = p_pict->date;
+    memcpy( p_block->p_buffer, p_sys->buffer, ret );
+
+    if(stats.type == XVID_TYPE_IVOP)
+        p_block->i_flags |= BLOCK_FLAG_TYPE_I;
+    else if(stats.type == XVID_TYPE_PVOP)
+        p_block->i_flags |= BLOCK_FLAG_TYPE_P;
+    else if(stats.type == XVID_TYPE_BVOP)
+        p_block->i_flags |= BLOCK_FLAG_TYPE_B;
+    
+    return p_block;
+}
+
+/****************************************************************************
+ * Close: Close encoder
+ ****************************************************************************/
+static void Close( vlc_object_t *p_this )
+{
+    encoder_t     *p_enc = (encoder_t *)p_this;
+    encoder_sys_t *p_sys = p_enc->p_sys;
+    int           result;
+
+    if ( p_sys->xvid_enc.handle ) {
+        result = xvid_encore( p_sys->xvid_enc.handle, XVID_ENC_DESTROY, NULL, NULL );
+	if ( result < 0 )
+            msg_Warn( p_enc, "Failed to stop encoder: %s", xvid_strerror(result) );
+    }
+    if ( p_sys->buffer ) {
+        free(p_sys->buffer);
+	p_sys->buffer = NULL;
+    }
+}
--- vlc/modules/misc/rtsp.c.xvid~	2007-06-10 15:56:06.000000000 +0200
+++ vlc/modules/misc/rtsp.c	2007-07-03 14:15:00.000000000 +0200
@@ -582,6 +582,9 @@
                 p_es->psz_fmtp = strdup( "packetization-mode=1" );
             break;
         case VLC_FOURCC( 'm', 'p', '4', 'v' ):
+	case VLC_FOURCC( 'x', 'v', 'i', 'd' ):
+	case VLC_FOURCC( 'X', 'V', 'I', 'D' ):
+	case VLC_FOURCC( 'X', 'v', 'i', 'd' ):
             p_es->i_payload_type = p_media->i_payload_type++;
             p_es->psz_rtpmap = strdup( "MP4V-ES/90000" );
             if( p_fmt->i_extra > 0 )
--- vlc/modules/mux/mp4.c.xvid~	2007-06-10 15:56:08.000000000 +0200
+++ vlc/modules/mux/mp4.c	2007-07-03 14:15:46.000000000 +0200
@@ -408,6 +408,9 @@
         case VLC_FOURCC( 's', 'a', 'w', 'b' ):
         case VLC_FOURCC( 'Y', 'V', '1', '2' ):
         case VLC_FOURCC( 'Y', 'U', 'Y', '2' ):
+	case VLC_FOURCC( 'x', 'v', 'i', 'd' ):
+	case VLC_FOURCC( 'X', 'v', 'i', 'd' ):
+	case VLC_FOURCC( 'X', 'V', 'I', 'D' ):
             break;
         case VLC_FOURCC( 's', 'u', 'b', 't' ):
             msg_Warn( p_mux, "subtitle track added like in .mov (even when creating .mp4)" );
--- vlc/modules/mux/ogg.c.xvid~	2007-03-22 18:39:41.000000000 +0100
+++ vlc/modules/mux/ogg.c	2007-07-03 14:15:00.000000000 +0200
@@ -345,6 +345,9 @@
         case VLC_FOURCC( 'W', 'M', 'V', '2' ):
         case VLC_FOURCC( 'W', 'M', 'V', '3' ):
         case VLC_FOURCC( 'S', 'N', 'O', 'W' ):
+	case VLC_FOURCC( 'X', 'V', 'I', 'D' ):
+	case VLC_FOURCC( 'x', 'v', 'i', 'd' ):
+	case VLC_FOURCC( 'X', 'v', 'i', 'd' ):
         case VLC_FOURCC( 'd', 'r', 'a', 'c' ):
             p_stream->p_oggds_header = malloc( sizeof(oggds_header_t) );
             memset( p_stream->p_oggds_header, 0, sizeof(oggds_header_t) );
--- vlc/modules/stream_out/rtp.c.xvid~	2007-06-10 15:56:01.000000000 +0200
+++ vlc/modules/stream_out/rtp.c	2007-07-03 14:15:00.000000000 +0200
@@ -1128,6 +1128,9 @@
             break;
 
         case VLC_FOURCC( 'm', 'p', '4', 'v' ):
+        case VLC_FOURCC( 'x', 'v', 'i', 'd' ):
+        case VLC_FOURCC( 'X', 'V', 'I', 'D' ):
+        case VLC_FOURCC( 'X', 'v', 'i', 'd' ):
         {
             char hexa[2*p_fmt->i_extra +1];