[MPlayer-dev-eng] [PATCH] AVISynth Audio support v2.1

Gianluigi Tiesi mplayer at netfarm.it
Sat Sep 9 10:46:19 CEST 2006


polite reminder :P
what about this patch?
http://oss.netfarm.it/mplayer/patches/xx_demux_avs_audio.diff

then optionally the attached cosmetic diff over patched code.

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 --------------
--- libmpdemux/demux_avs.c.orig	2006-09-09 10:40:08.185769600 +0200
+++ libmpdemux/demux_avs.c	2006-09-09 10:44:40.627521600 +0200
@@ -73,7 +73,7 @@
     int frameno;
     uint64_t sampleno;
     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;
@@ -85,24 +85,24 @@
 } AVS_T;
 
 AVS_T *initAVS(const char *filename)
-{   
+{
     AVS_T *AVS = (AVS_T *) malloc (sizeof(AVS_T));
     AVS_Value arg0 = avs_new_value_string(filename);
     AVS_Value args = avs_new_value_array(&arg0, 1);
-    
+
     memset(AVS, 0, sizeof(AVS_T));
 
 #ifdef WIN32_LOADER
     AVS->ldt_fs = 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");
         goto avs_err;
     }
-    
+
     /* Dynamic import of needed stuff from avisynth.dll */
     IMPORT_FUNC(avs_create_script_environment);
     IMPORT_FUNC(avs_invoke);
@@ -112,7 +112,7 @@
     IMPORT_FUNC(avs_get_frame);
     IMPORT_FUNC(avs_release_video_frame);
     IMPORT_FUNC(avs_get_audio);
-    
+
     AVS->avs_env = AVS->avs_create_script_environment(AVISYNTH_INTERFACE_VERSION);
     if (!AVS->avs_env)
     {
@@ -122,7 +122,7 @@
     
 
     AVS->handler = AVS->avs_invoke(AVS->avs_env, "Import", args, 0);
-    
+
     if (avs_is_error(AVS->handler))
     {
         mp_msg(MSGT_DEMUX, MSGL_V, "AVS: Avisynth error: %s\n", avs_as_string(AVS->handler));
@@ -171,12 +171,12 @@
 
     demux_stream_t *d_audio=demuxer->audio;
     sh_audio_t *sh_audio=d_audio->sh;
-    
+
     if (sh_video && ds == demuxer->video)
     {
         char *dst;
         int w, h;
-        if (AVS->video_info->num_frames < AVS->frameno) return 0; // EOF
+        if (AVS->video_info->num_frames < AVS->frameno) return 0; /* EOF */
 
         curr_frame = AVS->avs_get_frame(AVS->clip, AVS->frameno);
         if (!curr_frame)
@@ -206,14 +206,14 @@
         AVS->frameno++;
         AVS->avs_release_video_frame(curr_frame);
     }
-    
+
     /* Audio */
     if (sh_audio && ds == demuxer->audio)
     {   
-        if (AVS->sampleno >= AVS->video_info->num_audio_samples) return 0; // EOF
+        if (AVS->sampleno >= AVS->video_info->num_audio_samples) return 0; /* EOF */
 
-        int read_samples = sh_audio->wf->nSamplesPerSec / 10; // return 0.1 sec of audio per request
-        if (read_samples <= 0) read_samples = 1; // < 10 samples per sec audio?
+        int read_samples = sh_audio->wf->nSamplesPerSec / 10; /* return 0.1 sec of audio per request */
+        if (read_samples <= 0) read_samples = 1; /* < 10 samples per sec audio? */
 
         if (AVS->sampleno + (uint64_t) read_samples > AVS->video_info->num_audio_samples)
             read_samples = AVS->video_info->num_audio_samples - AVS->sampleno;
@@ -226,18 +226,19 @@
             mp_msg(MSGT_DEMUX, MSGL_V, "AVS: avs_get_audio() failed\n");
             return 0;
         }
-        
+
         dp->pts = (double) AVS->sampleno / (double) sh_audio->wf->nSamplesPerSec;
         ds_add_packet(demuxer->audio, dp);
         AVS->sampleno += read_samples;
     }
-    
+
     return 1;
 }
 
 static int avs_get_audio_format(int format)
 {
-    switch (format) {
+    switch (format)
+    {
         case AVS_SAMPLE_INT8:
         case AVS_SAMPLE_INT16:
         case AVS_SAMPLE_INT24:
@@ -252,7 +253,8 @@
 
 static int avs_get_audio_sample_size(int format)
 {
-    switch (format) {
+    switch (format)
+    {
         case AVS_SAMPLE_INT8:
             return 1;
         case AVS_SAMPLE_INT16:
@@ -290,7 +292,7 @@
         mp_msg(MSGT_DEMUX, MSGL_V, "AVS: avs_get_video_info() call failed\n");
         return NULL;
     }
-    
+
     if (!avs_is_yv12(AVS->video_info))
     {
         AVS->handler = AVS->avs_invoke(AVS->avs_env, "ConvertToYV12", avs_new_value_array(&AVS->handler, 1), 0);
@@ -299,9 +301,9 @@
             mp_msg(MSGT_DEMUX, MSGL_V, "AVS: Cannot convert input video to YV12: %s\n", avs_as_string(AVS->handler));
             return NULL;
         }
-        
+
         AVS->clip = AVS->avs_take_clip(AVS->handler, AVS->avs_env);
-        
+
         if(!AVS->clip)
         {
             mp_msg(MSGT_DEMUX, MSGL_V, "AVS: avs_take_clip() failed\n");
@@ -315,37 +317,36 @@
             return NULL;
         }
     }
-    
-    // TODO check field-based ??
+
+    /* TODO check field-based ?? */
 
     /* Video */  
     if (avs_has_video(AVS->video_info))
     {
         sh_video_t *sh_video = new_sh_video(demuxer, 0);
         found = 1;
-        
+
         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 = 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 = (BITMAPINFOHEADER*) 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->num_frames = 0;
         sh_video->num_frames_decoded = 0;
     }
-    
+
     /* Audio */
     if (avs_has_audio(AVS->video_info) && demuxer->audio->id != -2)
     {
@@ -360,7 +361,7 @@
 
             demuxer->audio->sh = sh_audio;
             sh_audio->ds = demuxer->audio;
-        
+
             sh_audio->wf = (WAVEFORMATEX*) malloc(sizeof(WAVEFORMATEX));
             sh_audio->wf->wFormatTag = sh_audio->format = audio_format;
             sh_audio->samplesize = avs_get_audio_sample_size(AVS->video_info->sample_type);
@@ -446,19 +447,18 @@
     AVS_T *AVS = (AVS_T *) demuxer->priv;
     double position = 0.0;
 
-    if (! flags&1) { // seek relative
+    if (!(flags & 1))  /* seek relative */
+    {
         if (sh_video)
             position = (double)AVS->frameno / sh_video->fps;
         else if (sh_audio)
             position = (double)AVS->sampleno / sh_audio->wf->nSamplesPerSec;
     }
-    
-    //mp_msg(MSGT_DEMUX, MSGL_V, "AVS: seek rel_seek_secs = %f - flags = %x\n", rel_seek_secs, flags);
-    
 
     position += rel_seek_secs;
 
-    if (sh_video) {
+    if (sh_video)
+    {
         AVS->frameno = position * ((double) AVS->video_info->fps_numerator / (double) AVS->video_info->fps_denominator);
         sh_video->num_frames_decoded = AVS->frameno;
         sh_video->num_frames = AVS->frameno;
@@ -466,9 +466,7 @@
     }
 
     if (sh_audio)
-    {
         AVS->sampleno = (position + audio_delay) * (double) sh_audio->wf->nSamplesPerSec;
-    }
 
 }
 
@@ -484,9 +482,9 @@
         mp_msg(MSGT_DEMUX,MSGL_V, "AVS: File is too big, aborting...\n");
         return 0;
     }
-    
+
     demuxer->priv = initAVS(demuxer->filename);
-    
+
     if (demuxer->priv)
     {
         mp_msg(MSGT_DEMUX,MSGL_V, "AVS: Init Ok\n");
@@ -497,14 +495,15 @@
 }
 
 
-demuxer_desc_t demuxer_desc_avs = {
+demuxer_desc_t demuxer_desc_avs =
+{
   "Avisynth demuxer",
   "avs",
   "AVS",
   "Gianluigi Tiesi",
   "Requires binary dll",
   DEMUXER_TYPE_AVS,
-  0, // unsafe autodetect
+  0, /* unsafe autodetect */
   avs_check_file,
   demux_avs_fill_buffer,
   demux_open_avs,


More information about the MPlayer-dev-eng mailing list