[MPlayer-cygwin] [PATCH] preliminary support for avisynth

Gianluigi Tiesi mplayer at netfarm.it
Mon Jan 17 07:18:27 CET 2005


The "fixed" version, at least I've resolved the flickering and fixed the
seeking (slow btw).
Bye

-- 
Gianluigi Tiesi <sherpya at netfarm.it>
EDP Project Leader
Netfarm S.r.l. - http://www.netfarm.it/
Free Software: http://oss.netfarm.it/
-------------- next part --------------
diff -NubBr -xCVS -xhelp_mp.h -xGui -x'*.a' -x'*.exe' -x'*.o' -xconfigure.log -xconfig.mak -x.cvsignore -x'*.ini' -xconfig.h -xcodecs.conf.h -xversion.h -x.depend main/libmpdemux/Makefile sherpya/libmpdemux/Makefile
--- main/libmpdemux/Makefile	2005-01-08 11:06:36.349604800 +0100
+++ sherpya/libmpdemux/Makefile	2005-01-17 05:36:53.765974400 +0100
@@ -21,6 +21,10 @@
 SRCS += dvb_tune.c
 endif
 
+ifneq ($(W32_LIB),)
+SRCS += demux_avs.c
+endif
+
 ifeq ($(MATROSKA),yes)
 SRCS += demux_mkv.c ebml.c
 endif
diff -NubBr -xCVS -xhelp_mp.h -xGui -x'*.a' -x'*.exe' -x'*.o' -xconfigure.log -xconfig.mak -x.cvsignore -x'*.ini' -xconfig.h -xcodecs.conf.h -xversion.h -x.depend main/libmpdemux/demux_avs.c sherpya/libmpdemux/demux_avs.c
--- main/libmpdemux/demux_avs.c	1970-01-01 01:00:00.000000000 +0100
+++ sherpya/libmpdemux/demux_avs.c	2005-01-17 07:14:09.467300800 +0100
@@ -0,0 +1,353 @@
+/*
+ * Demuxer for avisynth
+ * Copyright (c) 2005 Gianluigi Tiesi <sherpya at netfarm.it>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "config.h"
+#include "mp_msg.h"
+#include "help_mp.h"
+
+#include "stream.h"
+#include "demuxer.h"
+#include "stheader.h"
+
+#include "wine/windef.h"
+
+#ifdef WIN32_LOADER
+#include "ldt_keeper.h"
+#endif
+
+#include "demux_avs.h"
+
+HMODULE WINAPI LoadLibraryA(LPCSTR);
+FARPROC WINAPI GetProcAddress(HMODULE,LPCSTR);
+int     WINAPI FreeLibrary(HMODULE);
+
+typedef WINAPI AVS_ScriptEnvironment* (*imp_avs_create_script_environment)(int version);
+typedef WINAPI AVS_Value (*imp_avs_invoke)(AVS_ScriptEnvironment *, const char * name, AVS_Value args, const char** arg_names);
+typedef WINAPI const AVS_VideoInfo *(*imp_avs_get_video_info)(AVS_Clip *);
+typedef WINAPI AVS_Clip* (*imp_avs_take_clip)(AVS_Value, AVS_ScriptEnvironment *);
+typedef WINAPI AVS_VideoFrame* (*imp_avs_get_frame)(AVS_Clip *, int n);
+typedef WINAPI void (*imp_avs_release_video_frame)(AVS_VideoFrame *);
+
+#define Q(string) # string
+#define IMPORT_FUNC(x) \
+    AVS->x = ( imp_##x ) GetProcAddress(AVS->dll, Q(x)); \
+    if (!AVS->x) { mp_msg(MSGT_DEMUX,MSGL_V,"AVS: failed to load "Q(x)"()\n"); return 0; }
+
+typedef struct tagAVS
+{
+    AVS_ScriptEnvironment *avs_env;
+    AVS_Value handler;
+    AVS_Clip *clip;
+    const AVS_VideoInfo *video_info;
+    HMODULE dll;
+    int frameno;
+    int init;
+    
+    imp_avs_create_script_environment avs_create_script_environment;
+    imp_avs_invoke avs_invoke;
+    imp_avs_get_video_info avs_get_video_info;
+    imp_avs_take_clip avs_take_clip;
+    imp_avs_get_frame avs_get_frame;
+    imp_avs_release_video_frame avs_release_video_frame;
+} AVS_T;
+
+AVS_T *initAVS(const char *filename)
+{   
+    AVS_T *AVS = (AVS_T *) malloc (sizeof(AVS_T));
+    memset(AVS, 0, sizeof(AVS_T));
+
+#ifdef WIN32_LOADER
+    Setup_LDT_Keeper();
+#endif
+    
+    AVS->dll = LoadLibraryA("avisynth.dll");
+    if(!AVS->dll)
+    {
+        mp_msg(MSGT_DEMUX ,MSGL_V, "AVS: failed to load avisynth.dll\n");
+        return NULL;
+    }
+    
+    /* Dynamic import of needed stuff from avisynth.dll */
+    IMPORT_FUNC(avs_create_script_environment);
+    IMPORT_FUNC(avs_create_script_environment);
+    IMPORT_FUNC(avs_invoke);
+    IMPORT_FUNC(avs_get_video_info);
+    IMPORT_FUNC(avs_take_clip);
+    IMPORT_FUNC(avs_get_frame);
+    IMPORT_FUNC(avs_release_video_frame);
+    
+    AVS->avs_env = AVS->avs_create_script_environment(AVISYNTH_INTERFACE_VERSION);
+    if (!AVS->avs_env)
+    {
+        mp_msg(MSGT_DEMUX, MSGL_V, "AVS: avs_create_script_environment failed\n");
+        return NULL;
+    }
+    
+    AVS_Value arg0 = avs_new_value_string(filename);
+    AVS_Value args = avs_new_value_array(&arg0, 1);
+
+    AVS->handler = AVS->avs_invoke(AVS->avs_env, "Import", args, 0);
+    
+    if (avs_is_error(AVS->handler))
+    {
+        char buf[256];
+        sprintf(buf, "AVS: Avisynth error: %s\n", avs_as_string(AVS->handler));
+        mp_msg(MSGT_DEMUX, MSGL_V, buf);
+        return NULL;
+    }
+
+    if (!avs_is_clip(AVS->handler))
+    {
+        mp_msg(MSGT_DEMUX, MSGL_V, "AVS: Avisynth doesn't return a clip\n");
+        return NULL;
+    }
+    
+    return AVS;
+}
+
+/* Implement RGB MODES ?? */
+/*
+int get_mmioFOURCC(const AVS_VideoInfo *v)
+{
+    if (avs_is_rgb(v)) return mmioFOURCC(8, 'R', 'G', 'B');
+    if (avs_is_rgb24(v)) return mmioFOURCC(24, 'R', 'G', 'B');
+    if (avs_is_rgb32(v)) return mmioFOURCC(32, 'R', 'G', 'B');
+    if (avs_is_yv12(v)) return mmioFOURCC('Y', 'V', '1', '2');
+    //if (avs_is_yuy(v)) return mmioFOURCC('Y', 'U', 'Y', ' ');
+    if (avs_is_yuy2(v)) return mmioFOURCC('Y', 'U', 'Y', '2');    
+    return 0;
+}*/
+
+int demux_avs_fill_buffer(demuxer_t *demuxer)
+{
+    //static AVS_VideoFrame *curr_frame; // static no thread safe?
+    AVS_VideoFrame *curr_frame;
+    demux_packet_t *dp = NULL;
+    AVS_T *AVS = (AVS_T *) demuxer->priv;
+
+    demux_stream_t *d_video=demuxer->video;
+    sh_video_t *sh_video=d_video->sh;
+    
+    if (AVS->video_info->num_frames < AVS->frameno) return 0; // EOF
+    
+    curr_frame = AVS->avs_get_frame(AVS->clip, AVS->frameno);
+    if (!curr_frame)
+    {
+        mp_msg(MSGT_DEMUX, MSGL_V, "AVS: error getting frame -- EOF??\n");
+        return 0;
+    }
+        
+    dp = new_demux_packet(curr_frame->vfb->data_size);
+    dp->pts = curr_frame->vfb->sequence_number / sh_video->fps;
+    dp->flags=0;
+    
+    memcpy(dp->buffer, curr_frame->vfb->data + curr_frame->offset, curr_frame->vfb->data_size);
+    
+    AVS->frameno++;
+    
+    demuxer->video->dpos++;
+    ds_add_packet(demuxer->video, dp);
+    
+    AVS->avs_release_video_frame(curr_frame);
+    return 1;
+}
+
+int demux_open_avs(demuxer_t* demuxer)
+{
+    sh_video_t *sh_video = NULL;
+    sh_audio_t *sh_audio = NULL;
+    char buf[128];
+    int found = 0;
+    AVS_T *AVS = (AVS_T *) demuxer->priv;
+    
+    AVS->frameno = 0;
+
+    mp_msg(MSGT_DEMUX, MSGL_V, "AVS: demux_open_avs()\n");
+    demuxer->seekable = 1;
+
+    AVS->clip = AVS->avs_take_clip(AVS->handler, AVS->avs_env);
+    if(!AVS->clip)
+    {
+        mp_msg(MSGT_DEMUX, MSGL_V, "AVS: cannot take the clip\n");
+        return 0;
+    }
+
+    AVS->video_info = AVS->avs_get_video_info(AVS->clip);
+    if (!AVS->video_info)
+    {
+        mp_msg(MSGT_DEMUX, MSGL_V, "AVS: avs_get_video_info() call failed\n");
+        return 0;
+    }
+    
+    if (!avs_is_yv12(AVS->video_info))
+    {
+        AVS->handler = AVS->avs_invoke(AVS->avs_env, "ConvertToYV12", avs_new_value_array(&AVS->handler, 1), 0);
+        if (avs_is_error(AVS->handler))
+        {
+            sprintf(buf, "AVS: Cannot convert input video to YV12: %s\n", avs_as_string(AVS->handler));
+            mp_msg(MSGT_DEMUX, MSGL_V, buf);
+            return 0;
+        }
+        
+        AVS->clip = AVS->avs_take_clip(AVS->handler, AVS->avs_env);
+        
+        if(!AVS->clip)
+        {
+            mp_msg(MSGT_DEMUX, MSGL_V, "AVS: cannot take the clip\n");
+            return 0;
+        }
+
+        AVS->video_info = AVS->avs_get_video_info(AVS->clip);
+        if (!AVS->video_info)
+        {
+            mp_msg(MSGT_DEMUX, MSGL_V, "AVS: avs_get_video_info() call failed\n");
+            return 0;
+        }
+        AVS->video_info = AVS->avs_get_video_info(AVS->clip);
+    }
+    
+    // TODO check field-based ??
+
+    /* Video */  
+    if (avs_has_video(AVS->video_info))
+    {
+        found = 1;
+        sh_video = new_sh_video(demuxer, 0);
+        
+        demuxer->video->sh = sh_video;
+        sh_video->ds = demuxer->video;
+        
+        sh_video->disp_w = AVS->video_info->width;
+        sh_video->disp_h = AVS->video_info->height;
+        
+        //sh_video->format = get_mmioFOURCC(AVS.video_info);
+        sh_video->format = mmioFOURCC('Y', 'V', '1', '2');
+        sh_video->fps = (float) ((float) AVS->video_info->fps_numerator / (float) AVS->video_info->fps_denominator);
+        sh_video->frametime = 1.0 / sh_video->fps;
+        
+        sh_video->bih = malloc(sizeof(BITMAPINFOHEADER) + (256 * 4));
+        sh_video->bih->biCompression = sh_video->format;
+        sh_video->bih->biBitCount = avs_bits_per_pixel(AVS->video_info);
+        //sh_video->bih->biPlanes = 2;
+        
+        sh_video->bih->biWidth = AVS->video_info->width;
+        sh_video->bih->biHeight = AVS->video_info->height;
+
+        //sh_video->bih->biBitCount = avs_bits_per_pixel(AVS->video_info);
+    }
+
+    /* Audio */
+    if (avs_has_audio(AVS->video_info))
+    {
+        //found = 1;
+        sprintf(buf, "AVS: Clip has audio -> Channels = %d - Freq = %d\n", AVS->video_info->nchannels, AVS->video_info->audio_samples_per_second);
+        mp_msg(MSGT_DEMUX, MSGL_V, buf);
+
+        //sh_audio = new_sh_audio(demuxer, 0);
+        //demuxer->audio->sh = sh_audio;
+    }
+
+    AVS->init = 1;
+    return found;
+}
+
+int demux_avs_control(demuxer_t *demuxer, int cmd, void *arg)
+{   
+    demux_stream_t *d_video=demuxer->video;
+    sh_video_t *sh_video=d_video->sh;
+    AVS_T *AVS = (AVS_T *) demuxer->priv;
+
+    switch(cmd)
+    {
+        case DEMUXER_CTRL_GET_TIME_LENGTH:
+        {
+            if (!AVS->video_info->num_frames) return DEMUXER_CTRL_DONTKNOW;
+
+            *((unsigned long *)arg) = AVS->video_info->num_frames / sh_video->fps;
+            return DEMUXER_CTRL_OK;
+        }
+        case DEMUXER_CTRL_GET_PERCENT_POS:
+        {
+            if (!AVS->video_info->num_frames) return DEMUXER_CTRL_DONTKNOW;
+                
+            *((int *)arg) = (int) (AVS->frameno * 100 / AVS->video_info->num_frames);
+            return DEMUXER_CTRL_OK;
+        }
+    default:
+        return DEMUXER_CTRL_NOTIMPL;
+    }
+}
+
+void demux_close_avs(demuxer_t* demuxer)
+{
+    AVS_T *AVS = (AVS_T *) demuxer->priv;
+    
+    if (AVS)
+    {
+        if (AVS->dll)
+        {
+            mp_msg(MSGT_DEMUX, MSGL_V, "AVS: Unloading avisynth.dll\n");
+            FreeLibrary(AVS->dll);
+        }
+        free(AVS);
+    }
+}
+
+void demux_seek_avs(demuxer_t *demuxer, float rel_seek_secs,int flags)
+{
+    //char buf[128];
+    demux_stream_t *d_video=demuxer->video;
+    sh_video_t *sh_video=d_video->sh;
+    AVS_T *AVS = (AVS_T *) demuxer->priv;
+    int video_pos=AVS->frameno;
+    
+    //sprintf(buf, "AVS: seek rel_seek_secs = %f - flags = 0x%08x\n", rel_seek_secs, flags);
+    //mp_msg(MSGT_DEMUX, MSGL_V, buf);
+    
+    // seek absolute
+    if (flags&1) video_pos=0;
+
+    video_pos += (rel_seek_secs * sh_video->fps);
+    if (video_pos < 0) video_pos = 0;
+    if (video_pos > AVS->video_info->num_frames) video_pos = AVS->video_info->num_frames;
+        
+    AVS->frameno = video_pos;
+}
+
+int avs_check_file(demuxer_t *demuxer, const char *filename)
+{
+    mp_msg(MSGT_DEMUX, MSGL_V, "AVS: avs_check_file\n");
+    mp_msg(MSGT_DEMUX, MSGL_V, "AVS: attempting to open file\n");
+
+    if (!filename) return 0;
+    demuxer->priv = initAVS(filename);
+    
+    if (demuxer->priv)
+    {
+        mp_msg(MSGT_DEMUX,MSGL_V, "AVS: Init Ok\n");
+        return 1;
+    }
+    mp_msg(MSGT_DEMUX,MSGL_V, "AVS: Init failed\n");
+    return 0;
+}
diff -NubBr -xCVS -xhelp_mp.h -xGui -x'*.a' -x'*.exe' -x'*.o' -xconfigure.log -xconfig.mak -x.cvsignore -x'*.ini' -xconfig.h -xcodecs.conf.h -xversion.h -x.depend main/libmpdemux/demux_avs.h sherpya/libmpdemux/demux_avs.h
--- main/libmpdemux/demux_avs.h	1970-01-01 01:00:00.000000000 +0100
+++ sherpya/libmpdemux/demux_avs.h	2005-01-17 05:36:53.806032000 +0100
@@ -0,0 +1,152 @@
+/*
+ * Demuxer for avisynth
+ * Copyright (c) 2005 Gianluigi Tiesi <sherpya at netfarm.it>
+ *
+ * Avisynth C Interface Version 0.20
+ * Copyright 2003 Kevin Atkinson
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+enum { AVISYNTH_INTERFACE_VERSION = 2 };
+
+enum
+{
+  AVS_SAMPLE_INT8  = 1<<0,
+  AVS_SAMPLE_INT16 = 1<<1, 
+  AVS_SAMPLE_INT24 = 1<<2,
+  AVS_SAMPLE_INT32 = 1<<3,
+  AVS_SAMPLE_FLOAT = 1<<4
+};
+
+enum
+{
+  AVS_PLANAR_Y=1<<0,
+  AVS_PLANAR_U=1<<1,
+  AVS_PLANAR_V=1<<2,
+  AVS_PLANAR_ALIGNED=1<<3,
+  AVS_PLANAR_Y_ALIGNED=AVS_PLANAR_Y|AVS_PLANAR_ALIGNED,
+  AVS_PLANAR_U_ALIGNED=AVS_PLANAR_U|AVS_PLANAR_ALIGNED,
+  AVS_PLANAR_V_ALIGNED=AVS_PLANAR_V|AVS_PLANAR_ALIGNED
+};
+
+// Colorspace properties.
+enum
+{
+  AVS_CS_BGR = 1<<28,  
+  AVS_CS_YUV = 1<<29,
+  AVS_CS_INTERLEAVED = 1<<30,
+  AVS_CS_PLANAR = 1<<31
+};
+
+// Specific colorformats
+enum
+{
+  AVS_CS_UNKNOWN = 0,
+  AVS_CS_BGR24 = 1<<0 | AVS_CS_BGR | AVS_CS_INTERLEAVED,
+  AVS_CS_BGR32 = 1<<1 | AVS_CS_BGR | AVS_CS_INTERLEAVED,
+  AVS_CS_YUY2 = 1<<2 | AVS_CS_YUV | AVS_CS_INTERLEAVED,
+  AVS_CS_YV12 = 1<<3 | AVS_CS_YUV | AVS_CS_PLANAR,  // y-v-u, planar
+  AVS_CS_I420 = 1<<4 | AVS_CS_YUV | AVS_CS_PLANAR,  // y-u-v, planar
+  AVS_CS_IYUV = 1<<4 | AVS_CS_YUV | AVS_CS_PLANAR  // same as above
+};
+
+typedef struct AVS_Clip AVS_Clip;
+typedef struct AVS_ScriptEnvironment AVS_ScriptEnvironment;
+
+typedef struct AVS_Value AVS_Value;
+struct AVS_Value {
+  short type;  // 'a'rray, 'c'lip, 'b'ool, 'i'nt, 'f'loat, 's'tring, 'v'oid, or 'l'ong
+               // for some function e'rror
+  short array_size;
+  union {
+    void * clip; // do not use directly, use avs_take_clip
+    char boolean;
+    int integer;
+    float floating_pt;
+    const char * string;
+    const AVS_Value * array;
+  } d;
+};
+
+static const AVS_Value avs_void = {'v'};
+
+// AVS_VideoInfo is layed out identicly to VideoInfo
+typedef struct AVS_VideoInfo {
+  int width, height;    // width=0 means no video
+  unsigned fps_numerator, fps_denominator;
+  int num_frames;
+
+  int pixel_type;
+  
+  int audio_samples_per_second;   // 0 means no audio
+  int sample_type;
+  uint64_t num_audio_samples;
+  int nchannels;
+
+  // Imagetype properties
+
+  int image_type;
+} AVS_VideoInfo;
+
+typedef struct AVS_VideoFrameBuffer {
+  BYTE * data;
+  int data_size;
+  // sequence_number is incremented every time the buffer is changed, so
+  // that stale views can tell they're no longer valid.
+  long sequence_number;
+
+  long refcount;
+} AVS_VideoFrameBuffer;
+
+typedef struct AVS_VideoFrame {
+  int refcount;
+  AVS_VideoFrameBuffer * vfb;
+  int offset, pitch, row_size, height, offsetU, offsetV, pitchUV;  // U&V offsets are from top of picture.
+} AVS_VideoFrame;
+
+
+static __inline AVS_Value avs_new_value_string(const char * v0) 
+{ AVS_Value v; v.type = 's'; v.d.string = v0; return v; }
+
+static __inline AVS_Value avs_new_value_array(AVS_Value * v0, int size)
+{ AVS_Value v; v.type = 'a'; v.d.array = v0; v.array_size = size; return v; }
+
+
+static __inline int avs_is_error(AVS_Value v) { return v.type == 'e'; }
+static __inline int avs_is_clip(AVS_Value v) { return v.type == 'c'; }
+static __inline int avs_is_string(AVS_Value v) { return v.type == 's'; }
+static __inline int avs_has_video(const AVS_VideoInfo * p) { return (p->width!=0); }
+static __inline int avs_has_audio(const AVS_VideoInfo * p) { return (p->audio_samples_per_second!=0); }
+
+static __inline const char * avs_as_string(AVS_Value v) 
+{ return avs_is_error(v) || avs_is_string(v) ? v.d.string : 0; }
+
+static __inline int avs_is_yv12(const AVS_VideoInfo * p) 
+{ return ((p->pixel_type & AVS_CS_YV12) == AVS_CS_YV12)||((p->pixel_type & AVS_CS_I420) == AVS_CS_I420); }
+
+
+static __inline int avs_bits_per_pixel(const AVS_VideoInfo * p) 
+{ 
+  switch (p->pixel_type) {
+      case AVS_CS_BGR24: return 24;
+      case AVS_CS_BGR32: return 32;
+      case AVS_CS_YUY2:  return 16;
+      case AVS_CS_YV12:
+      case AVS_CS_I420:  return 12;
+      default:           return 0;
+    }
+}
diff -NubBr -xCVS -xhelp_mp.h -xGui -x'*.a' -x'*.exe' -x'*.o' -xconfigure.log -xconfig.mak -x.cvsignore -x'*.ini' -xconfig.h -xcodecs.conf.h -xversion.h -x.depend main/libmpdemux/demuxer.c sherpya/libmpdemux/demuxer.c
--- main/libmpdemux/demuxer.c	2005-01-16 02:02:51.853753600 +0100
+++ sherpya/libmpdemux/demuxer.c	2005-01-17 05:36:53.806032000 +0100
@@ -157,6 +157,9 @@
 extern void demux_close_ty(demuxer_t* demuxer);
 extern void demux_close_lavf(demuxer_t* demuxer);
 extern void demux_close_vqf(demuxer_t* demuxer);
+#ifdef USE_WIN32DLL
+extern void demux_close_avs(demuxer_t* demuxer);
+#endif
 
 
 #ifdef USE_TV
@@ -248,6 +251,10 @@
     case DEMUXER_TYPE_LAVF:
       demux_close_lavf(demuxer); break;
 #endif
+#ifdef USE_WIN32DLL
+    case DEMUXER_TYPE_AVS:
+      demux_close_avs(demuxer); break;
+#endif
     }
     // free streams:
     for(i=0;i<256;i++){
@@ -339,6 +346,9 @@
 extern int demux_lmlm4_fill_buffer(demuxer_t* demux);
 extern int demux_mkv_fill_buffer(demuxer_t *d);
 extern int demux_lavf_fill_buffer(demuxer_t *d);
+#ifdef USE_WIN32DLL
+extern int demux_avs_fill_buffer(demuxer_t *d);
+#endif
 
 int demux_fill_buffer(demuxer_t *demux,demux_stream_t *ds){
   // Note: parameter 'ds' can be NULL!
@@ -398,6 +408,9 @@
 #ifdef USE_LIBAVFORMAT
      case DEMUXER_TYPE_LAVF: return demux_lavf_fill_buffer(demux);
 #endif
+#ifdef USE_WIN32DLL
+    case DEMUXER_TYPE_AVS: return demux_avs_fill_buffer(demux);
+#endif
   }
   return 0;
 }
@@ -609,6 +622,10 @@
 extern int rawdv_check_file(demuxer_t *demuxer);
 #endif
 
+#ifdef USE_WIN32DLL
+int avs_check_file(demuxer_t *demuxer, const char *filename);
+#endif
+
 extern int vivo_check_file(demuxer_t *demuxer);
 extern void demux_open_vivo(demuxer_t *demuxer);
 extern int y4m_check_file(demuxer_t *demuxer);
@@ -646,6 +663,9 @@
 #endif
 extern int lavf_check_file(demuxer_t *demuxer);
 extern int demux_open_lavf(demuxer_t* demuxer);
+#ifdef USE_WIN32DLL
+extern int demux_open_avs(demuxer_t* demuxer);
+#endif
 
 extern demuxer_t* init_avi_with_ogg(demuxer_t* demuxer);
 #ifdef STREAMING_LIVE_DOT_COM
@@ -836,7 +856,7 @@
   file_format=demuxer_type_by_filename(filename);
   if(file_format!=DEMUXER_TYPE_UNKNOWN){
     // we like recursion :)
-    demuxer=demux_open_stream(stream,file_format,audio_id,video_id,dvdsub_id,NULL);
+    demuxer=demux_open_stream(stream,file_format,audio_id,video_id,dvdsub_id,filename);
     if(demuxer) return demuxer; // done!
     file_format=DEMUXER_TYPE_UNKNOWN; // continue fuzzy guessing...
     mp_msg(MSGT_DEMUXER,MSGL_V,"demuxer: continue fuzzy content-based format guessing...\n");
@@ -934,6 +954,19 @@
   }
 }
 #endif
+#ifdef USE_WIN32DLL
+//=============== Try to open as Avisynth file: =================
+if(file_format==DEMUXER_TYPE_UNKNOWN || file_format==DEMUXER_TYPE_AVS){
+  demuxer=new_demuxer(stream,DEMUXER_TYPE_AVS,audio_id,video_id,dvdsub_id);
+  if (avs_check_file(demuxer, filename)){
+      mp_msg(MSGT_DEMUXER,MSGL_INFO,MSGTR_Detected_XXX_FileFormat,"AVS");
+      file_format=DEMUXER_TYPE_AVS;
+  } else {
+      free_demuxer(demuxer);
+      demuxer = NULL;
+  }
+}
+#endif
 //=============== Try to open as PVA file: =================
 if(file_format == DEMUXER_TYPE_UNKNOWN || file_format==DEMUXER_TYPE_PVA){
 	demuxer=new_demuxer(stream,DEMUXER_TYPE_PVA,audio_id,video_id,dvdsub_id);
@@ -1384,6 +1417,12 @@
   break;
  }
 #endif
+#ifdef USE_WIN32DLL
+  case DEMUXER_TYPE_AVS: {
+  if (!demux_open_avs(demuxer)) return NULL;
+  break;
+ }
+#endif
 } // switch(file_format)
 pts_from_bps=0; // !!!
 if ((sh_video=demuxer->video->sh) && sh_video->bih)
@@ -1485,6 +1524,9 @@
 int demux_seek_pva(demuxer_t *demuxer,float rel_seek_secs,int flags);
 int demux_seek_ts(demuxer_t *demuxer,float rel_seek_secs,int flags);
 int demux_seek_lavf(demuxer_t *demuxer,float rel_seek_secs,int flags);
+#ifdef USE_WIN32DLL
+int demux_seek_avs(demuxer_t *demuxer,float rel_seek_secs,int flags);
+#endif
 
 #ifdef HAVE_LIBDV095
 int demux_seek_rawdv(demuxer_t *demuxer, float pts, int flags);
@@ -1602,6 +1644,10 @@
  #endif
  case DEMUXER_TYPE_VQF:
       demux_seek_vqf(demuxer,rel_seek_secs,flags); break;
+ #ifdef USE_WIN32DLL
+ case DEMUXER_TYPE_AVS:
+      demux_seek_avs(demuxer,rel_seek_secs,flags); break;
+ #endif
 
 } // switch(demuxer->file_format)
 
@@ -1669,6 +1715,9 @@
 extern int demux_real_control(demuxer_t *demuxer, int cmd, void *arg);
 extern int demux_lavf_control(demuxer_t *demuxer, int cmd, void *arg);
 extern int demux_mov_control(demuxer_t *demuxer, int cmd, void *arg);
+#ifdef USE_WIN32DLL
+extern int demux_avs_control(demuxer_t *demuxer, int cmd, void *arg);
+#endif
 
 int demux_control(demuxer_t *demuxer, int cmd, void *arg) {
     switch(demuxer->type) {
@@ -1707,7 +1756,10 @@
 #endif
         case DEMUXER_TYPE_MOV:
    	    return demux_mov_control(demuxer, cmd, arg);
-
+#ifdef USE_WIN32DLL
+        case DEMUXER_TYPE_AVS:
+   	    return demux_avs_control(demuxer, cmd, arg);
+#endif 
 	default:
 	    return DEMUXER_CTRL_NOTIMPL;
     }
diff -NubBr -xCVS -xhelp_mp.h -xGui -x'*.a' -x'*.exe' -x'*.o' -xconfigure.log -xconfig.mak -x.cvsignore -x'*.ini' -xconfig.h -xcodecs.conf.h -xversion.h -x.depend main/libmpdemux/demuxer.h sherpya/libmpdemux/demuxer.h
--- main/libmpdemux/demuxer.h	2005-01-08 11:06:37.200828800 +0100
+++ sherpya/libmpdemux/demuxer.h	2005-01-17 05:36:53.816046400 +0100
@@ -45,11 +45,12 @@
 #define DEMUXER_TYPE_LAVF 35
 #define DEMUXER_TYPE_NSV 36
 #define DEMUXER_TYPE_VQF 37
+#define DEMUXER_TYPE_AVS 38
 
 // This should always match the higest demuxer type number.
 // Unless you want to disallow users to force the demuxer to some types
 #define DEMUXER_TYPE_MIN 0
-#define DEMUXER_TYPE_MAX 37
+#define DEMUXER_TYPE_MAX 38
 
 #define DEMUXER_TYPE_DEMUXERS (1<<16)
 // A virtual demuxer type for the network code
diff -NubBr -xCVS -xhelp_mp.h -xGui -x'*.a' -x'*.exe' -x'*.o' -xconfigure.log -xconfig.mak -x.cvsignore -x'*.ini' -xconfig.h -xcodecs.conf.h -xversion.h -x.depend main/libmpdemux/extension.c sherpya/libmpdemux/extension.c
--- main/libmpdemux/extension.c	2004-12-04 23:59:35.000000000 +0100
+++ sherpya/libmpdemux/extension.c	2005-01-17 05:36:53.816046400 +0100
@@ -51,7 +51,8 @@
         { "vqf", DEMUXER_TYPE_XMMS },
         { "nsv", DEMUXER_TYPE_NSV },
         { "nsa", DEMUXER_TYPE_NSV },
-	{ "nut", DEMUXER_TYPE_LAVF }
+        { "nut", DEMUXER_TYPE_LAVF },
+        { "avs", DEMUXER_TYPE_AVS }
 };
 
 int demuxer_type_by_filename(char* filename){


More information about the MPlayer-cygwin mailing list