Fix A/V Sync code : Fix 23.976/25fps A/V Mismatch

Discuss issues related to PS3 Media Server development (only for programmers)

Fix A/V Sync code : Fix 23.976/25fps A/V Mismatch

Postby ExSport » Mon Aug 10, 2009 4:23 am

Hi
Please could someone tell me how to call configuration change in code?
I am trying to modify TranscodeVirtualFolder.java in way that when it is called, it will set A/V alternate sync to ENABLED/DISABLED:
package net.pms.dlna.virtual;
import net.pms.PMS;
public class TranscodeVirtualFolder extends VirtualFolder {
public void enable() {
PMS.getConfiguration().setMencoderNoOutOfSync(false);
}

public TranscodeVirtualFolder(String thumbnailIcon) {
super(TRANSCODE_FOLDER, thumbnailIcon);
enable();
}
}

But this modification is not working(red is new code)...no difference if TRUE or FALSE is set :(
Please could someone help me?
Purpose is that I have 2 similar codes for #TRANSCODE# and #FIXED A/V# folders and need to enable/disable "A/V sync Alternative method" settings automatically when browsed to these 2 folders
Many thanks

EDIT: Purpose of this is viewtopic.php?f=6&t=3277&start=0

First tryouts of working code(with precompiled .jar file):
viewtopic.php?f=2&t=3336&start=10#p14905
Last edited by ExSport on Fri Oct 16, 2009 8:53 pm, edited 11 times in total.
ExSport
 
Posts: 2167
Joined: Mon Jan 19, 2009 5:40 pm

Re: How to call "configuration change" in PMS java code?

Postby ExSport » Tue Aug 11, 2009 10:00 am

Hello guys.
It seems that "PMS.getConfiguration().setMencoderNoOutOfSync(false);" is working but I implemented TRUE variant in bad part of code so everytime TRUE variant will replace FALSE one when browsing #TRANSCODE FOLDER# :?
Need to find correct code place which is not called when I am outside #TRANSCODE# path.
Did someone know how to retrieve currend browsed PATH so I can detect where I am now? Then it will be easier to call proper TRUE/FALSE variant of code.
Many thanks.
ExSport
 
Posts: 2167
Joined: Mon Jan 19, 2009 5:40 pm

Re: How to call "configuration change" in PMS java code?

Postby ExSport » Tue Aug 11, 2009 6:19 pm

Hmm, found problem :idea:
Lot of UPnP clients cache data so when folder was already browsed client doesn't send list/dir request so PMS doesn't know where user is actually browsing :?
So only solution is to detect current folder path when client asks for file to be played and at this moment change setting depending on path or directly change used parameters for tsMuxeR and MEncoder.
Do someone know where in the code it is or which method or class is responsible for that?
Thanks
ExSport
 
Posts: 2167
Joined: Mon Jan 19, 2009 5:40 pm

Re: How to call "configuration change" in PMS java code?

Postby ronin.kenji » Tue Aug 11, 2009 11:06 pm

ExSport,

Maybe you can add/copy the "A/V sync alternative method" option found under #-Video Settings-#.
It's in PMS.java
Code: Select all
                        VirtualFolder vf = new VirtualFolder(Messages.getString("PMS.37"), null); //$NON-NLS-1$
                        vf.addChild(new VirtualVideoAction(Messages.getString("PMS.3"), configuration.isMencoderNoOutOfSync()) { //$NON-NLS-1$
                                public boolean enable() {
                                        configuration.setMencoderNoOutOfSync(!configuration.isMencoderNoOutOfSync());
                                        return configuration.isMencoderNoOutOfSync();
                                }
                        });


At least this way you can toggle it on demand from any #Transcode# folder.
PMS: r372
MEncoder: SVN-r30392-4.2.4
FFmpeg: git-73608e1
OS: Slackware 12.2
Shuttle K45: E7400@2.8, 4Gb (3.3 visible), 1Tb WD Green Caviar (shifting to 1.5TB soon)
ronin.kenji
 
Posts: 20
Joined: Thu Jul 09, 2009 12:57 am

Re: How to call "configuration change" in PMS java code?

Postby ExSport » Wed Aug 12, 2009 1:30 am

Thanks.
But I already created new similar folder as #TRANSCODE# with name #--A/V ALTERNATE FIX--# and modified mencoder and tsmuxer parameters depending on settings.
But it is not working correctly for me :?
I need something like:
Code: Select all
Set 25fps when file displayed is instanceof AlternateA/V Class(object) = #A/V Alternate Fix folder# and use original fps when displayed file is instanceof #transcode# folder.

So in other words I created new folder where 25fps is forced everytime instead of 23.976 but it is not working as expected. Maybe my poor JAVA knowledge or also other factors as caching or bad place where I made modifications.
I used TsMuxer_Force_Fps and MEncoder_Force_Fps settings for this purpose because it is not used by me. In GUI it is "Force FPS parsed from FFmpeg...."
I want to do it automatically depending on browsed folder because when you forgot to disable it when you use #Video Settings# folder ===> all files will be then out of sync.
But for now I am not successfull to make a fully working plugin :roll:
ExSport
 
Posts: 2167
Joined: Mon Jan 19, 2009 5:40 pm

Re: How to call "configuration change" in PMS java code?

Postby ExSport » Wed Aug 12, 2009 2:02 am

I did these modifications (thanks to jaqb for his MovieInfo plugin example):
Code: Select all
Index: net/pms/dlna/DLNAResource.java
===================================================================
--- net/pms/dlna/DLNAResource.java   (revision 356)
+++ net/pms/dlna/DLNAResource.java   (working copy)
@@ -225,6 +225,8 @@
                      for(DLNAResource r:children) {
                         if (r instanceof TranscodeVirtualFolder) {
                            vf = (TranscodeVirtualFolder) r;
+                           PMS.getConfiguration().setMencoderForceFps(false);
+                           PMS.getConfiguration().setTsmuxerForceFps(false);
                            break;
                         }
                      }

Code: Select all
Index: net/pms/encoders/MEncoderVideo.java
===================================================================
--- net/pms/encoders/MEncoderVideo.java   (revision 356)
+++ net/pms/encoders/MEncoderVideo.java   (working copy)
@@ -1239,10 +1239,10 @@
       cmdArray[cmdArray.length-8] = "-quiet"; //$NON-NLS-1$
       cmdArray[cmdArray.length-7] = "-quiet"; //$NON-NLS-1$
       
-      if (configuration.isMencoderForceFps()) {
-         cmdArray[cmdArray.length-8] = "-fps"; //$NON-NLS-1$
-         cmdArray[cmdArray.length-7] = "24000/1001"; //$NON-NLS-1$
-      }
+//      if (configuration.isMencoderForceFps()) {
+//         cmdArray[cmdArray.length-8] = "-fps"; //$NON-NLS-1$
+//         cmdArray[cmdArray.length-7] = "24000/1001"; //$NON-NLS-1$
+//      }
       cmdArray[cmdArray.length-6] = "-ofps"; //$NON-NLS-1$
       cmdArray[cmdArray.length-5] = "24000/1001"; //$NON-NLS-1$
       String frameRate = null;
@@ -1252,7 +1252,7 @@
       if (frameRate != null) {
          cmdArray[cmdArray.length-5] = frameRate;
          if (configuration.isMencoderForceFps())
-            cmdArray[cmdArray.length-7] = cmdArray[cmdArray.length-5];
+            cmdArray[cmdArray.length-5] = "25";
       }
       
       if (subString != null && !configuration.isMencoderDisableSubs() && !avisynth()) {
Index: net/pms/encoders/TSMuxerVideo.java

Code: Select all
===================================================================
--- net/pms/encoders/TSMuxerVideo.java   (revision 356)
+++ net/pms/encoders/TSMuxerVideo.java   (working copy)
@@ -392,6 +392,9 @@
             String videoparams = "level=4.1, insertSEI, contSPS, track=1"; //$NON-NLS-1$
             if (this instanceof TsMuxerAudio)
                videoparams = "track=224"; //$NON-NLS-1$
+            if (configuration.isTsmuxerForceFps()) {
+               fps = "25";
+            }
             pw.println(videoType + ", \"" + ffVideoPipe.getOutputPipe() + "\", "  + (fps!=null?("fps=" +fps + ", "):"") + videoparams); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
          }
          if (ffAudioPipe != null && ffAudioPipe.length == 1) {
Index: net/pms/external/FixAVMismatch.java

And now new classes.
This one similar to original TranscodeVirtualFolder.java:
Code: Select all
Index: net/pms/dlna/virtual/FixAVVirtualFolder.java
===================================================================
--- net/pms/dlna/virtual/FixAVVirtualFolder.java   (revision 0)
+++ net/pms/dlna/virtual/FixAVVirtualFolder.java   (revision 0)
@@ -0,0 +1,14 @@
+package net.pms.dlna.virtual;
+
+public class FixAVVirtualFolder extends VirtualFolder {
+
+   public static String FIXAV_FOLDER = "#--A/V ALTERNATE FIX--#";
+
+   public FixAVVirtualFolder(String thumbnailIcon) {
+      super(FIXAV_FOLDER, thumbnailIcon);
+   }
+   
+   public FixAVVirtualFolder(String name, String thumbnailIcon) {
+      super(name, thumbnailIcon);
+   }
+}

And now external plugin code:
Code: Select all
===================================================================
--- net/pms/external/FixAVMismatch.java   (revision 0)
+++ net/pms/external/FixAVMismatch.java   (revision 0)
@@ -0,0 +1,77 @@
+package net.pms.external;
+
+import javax.swing.JCheckBox;
+import javax.swing.JComponent;
+
+import net.pms.dlna.DLNAResource;
+
+import net.pms.dlna.ResourceExtension0;
+
+import java.awt.Font;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+
+import net.pms.PMS;
+
+import com.jgoodies.forms.builder.PanelBuilder;
+import com.jgoodies.forms.factories.Borders;
+import com.jgoodies.forms.layout.CellConstraints;
+import com.jgoodies.forms.layout.FormLayout;
+
+public class FixAVMismatch implements AdditionalResourceFolderListener {
+
+   public void addAdditionalFolder(DLNAResource currentResource, DLNAResource child) {
+      ResourceExtension0 ext = new ResourceExtension0(currentResource);
+      ext.addChild(child);
+   }
+   
+   @Override
+   public void shutdown() {
+      
+   }
+   
+   @Override
+   public String name() {
+      return "A/V Mismatch Fix Plugin";
+   }
+   
+   private JCheckBox CoverField;
+
+   @Override
+   public JComponent config() {
+      FormLayout layout = new FormLayout("left:pref, 2dlu, p,2dlu, p,2dlu, p, 2dlu, p, 2dlu, p,2dlu, p,200dlu, pref:grow", //$NON-NLS-1$
+            "p, 5dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, 0:grow"); //$NON-NLS-1$
+      PanelBuilder builder = new PanelBuilder(layout);
+      builder.setBorder(Borders.EMPTY_BORDER);
+      builder.setOpaque(false);
+
+      CellConstraints cc = new CellConstraints();
+      
+      JComponent cmp = builder.addSeparator("Fix A/V CONFIGURATION",  cc.xy(1, 1));
+         cmp = (JComponent) cmp.getComponent(0);
+         cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));
+
+      CoverField = new JCheckBox();
+      CoverField.addKeyListener(new KeyListener() {
+         
+         @Override
+         public void keyPressed(KeyEvent e) {
+         }
+         
+         @Override
+         public void keyTyped(KeyEvent e) {
+         }
+         
+         @Override
+         public void keyReleased(KeyEvent e) {
+            PMS.getConfiguration().setCustomProperty(
+                  "cmd", CoverField.getText());
+         }
+         
+      });
+      builder.addLabel("Enable/Disable 23.976/25fps Fix: ", cc.xy(5, 5));
+      builder.add(CoverField, cc.xy(7, 5));
+
+      return builder.getPanel();      
+   }
+}

And at last not finished part which should be responsible to display exact files as in #TRANSCODE# folder but I accidentally deleted some part of code and now it is not working :oops:
Maybe someone will help? 8-)

Code: Select all
Index: net/pms/dlna/ResourceExtension.java
===================================================================
--- net/pms/dlna/ResourceExtension0.java   (revision 0)
+++ net/pms/dlna/ResourceExtension0.java   (revision 0)
@@ -0,0 +1,265 @@
+package net.pms.dlna;
+
+import net.pms.PMS;
+import net.pms.configuration.RendererConfiguration;
+import net.pms.dlna.DLNAResource;
+import net.pms.dlna.FileTranscodeVirtualFolder;
+import net.pms.dlna.virtual.FixAVVirtualFolder;
+import net.pms.dlna.virtual.VirtualFolder;
+import net.pms.encoders.Player;
+
+public class ResourceExtension0 {
+   
+   private DLNAResource original;
+   private RendererConfiguration defaultRenderer;
+   
+   public ResourceExtension0(DLNAResource original) {
+      this.original = original;
+   }
+
+   public void addChild(DLNAResource child) {
+      if (child.isValid()) {
................ etc.

Any help much appreciated.
Many thanks :mrgreen:

P.S.
Who don't know the purpose of my tryings....
I have few H264 HD movies which are in 23.976 fps but because Bluray disk doesn't include my native audio, I added 25fps audio from DVD.
These kind of files are then out of sync but when you use
-ofps 25 -mc 0.005 in MEncoder or fps=25 in tsMuxeR metafile ===> movies are perfectly in sync :mrgreen:
Last edited by ExSport on Sat Sep 12, 2009 7:51 am, edited 1 time in total.
ExSport
 
Posts: 2167
Joined: Mon Jan 19, 2009 5:40 pm

Re: New A/V Sync Plugin : How to detect used "Resource folder"?

Postby ExSport » Thu Aug 13, 2009 9:11 am

Where are all JAVA gurus :mrgreen:
Tried to use some code from DLNAResource class - method addChild - but my code import is not working as expected :? It means same file listing and behavior as in #TRANSCODE# folder.
Someone will help with addChild method creation in my code?
Many thanks
ExSport
 
Posts: 2167
Joined: Mon Jan 19, 2009 5:40 pm

Re: New A/V Sync Plugin : How to detect used "Resource folder"?

Postby jaqb » Mon Aug 17, 2009 6:58 pm

It's a bird, it's a plane... no, it's Superman!! ...err its just me ;-)
The solution is simple, u have to add your code to FileTranscodeVirtualFolder and not to TranscodeVirtualFolder :-)
HD YouTube on PS3 -> PS3 Youtube :D Are you a F1 fan ? Check out F1Reader.com
jaqb
 
Posts: 163
Joined: Tue Jan 27, 2009 11:50 am

Re: New A/V Sync Plugin : How to detect used "Resource folder"?

Postby ExSport » Mon Aug 17, 2009 7:06 pm

Thanks jaqb but I am little bit lost now in code 8-)
But I need to create new folder which will use forced 25fps instead of automatic detection and because that I need to create new folder like TRANSCODE and it is not possible to do it in FileTranscodeFolder, right? Because I need to list same structure as #transcode# folder has and in same level of directories.
I want new folder which will play all files like in #transcode# but with forced 25fps for Mencoder and Tsmuxer.
Any further tips are welcomed because I am JAVA beginner :mrgreen:
Many thanks
P.S
Or best solution is virtual file which will enable forced 25fps in #TRASCODE# folder for time of browsing this folder. It means when user leave this folder, forced fps will be cleared.
But I don't know how to do it at all.
ExSport
 
Posts: 2167
Joined: Mon Jan 19, 2009 5:40 pm

Re: New A/V Sync Plugin : How to detect used "Resource folder"?

Postby jaqb » Mon Aug 17, 2009 7:38 pm

You can duplicate TranscodeVirtualFolder and FileTranscodeVirtualFolder by only changing their names. (by adding "B" ie) And only adding your enable() method to FileTransodeVirtualFolderB, this will work for all options in the TranscodeVirtualFolderB. If I'll have time I'll try to create a patch tonight if you havent manged to get it working by then ;-)
HD YouTube on PS3 -> PS3 Youtube :D Are you a F1 fan ? Check out F1Reader.com
jaqb
 
Posts: 163
Joined: Tue Jan 27, 2009 11:50 am

Next

Return to Developers

Who is online

Users browsing this forum: No registered users and 0 guests