Patch to LPCM audio transcoding

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

Patch to LPCM audio transcoding

Postby tomeko » Sun Jan 30, 2011 1:22 pm

I've created patch that adds real LPCM support for audio transcoding (LPCM != WAV). At this moment PS3MS can transcode to MP3 and lossless WAV. Internet radios can be transcoded to WAV only.
Because LPCM is more generic than WAV (is required by DLNA standard) it should be default for audio transcoding. For non DLNA renderes, that supports WAV, not LPCM
TranscodeAudio=WAV
could be set.

This patch fix issue 457 http://code.google.com/p/ps3mediaserver/issues/detail?id=457, and some problems with other renderers (like Samsung)
Code: Select all
Index: net/pms/configuration/RendererConfiguration.java
===================================================================
--- net/pms/configuration/RendererConfiguration.java   (wersja 470)
+++ net/pms/configuration/RendererConfiguration.java   (kopia robocza)
@@ -265,7 +265,8 @@
    public static final String MPEGTSAC3 = "MPEGTSAC3";
    public static final String WMV = "WMV";
    
-   public static final String PCM = "PCM";
+   public static final String WAV = "WAV";
+   public static final String LPCM = "LPCM";
    public static final String MP3 = "MP3";
    
    private static final String TRANSCODE_AUDIO="TranscodeAudio";
@@ -424,9 +425,13 @@
       return getAudioTranscode().startsWith(MP3);
    }
    
-   public boolean isTranscodeToPCM() {
-      return getAudioTranscode().startsWith(PCM);
+   public boolean isTranscodeToLPCM() {
+      return getAudioTranscode().startsWith(LPCM);
    }
+
+   public boolean isTranscodeToWAV() {
+      return getAudioTranscode().startsWith(WAV);
+   }
    
    public boolean isTranscodeAudioTo441() {
       return getBoolean(TRANSCODE_AUDIO_441KHZ, false);
@@ -447,14 +452,18 @@
    public String getMimeType(String mimetype) {
       if (isMediaParserV2()) {
          if (mimetype != null && mimetype.equals(HTTPResource.VIDEO_TRANSCODE)) {
-            if (isTranscodeToMPEGPSAC3())
-               mimetype = getFormatConfiguration().match(FormatConfiguration.MPEGPS, FormatConfiguration.MPEG2, FormatConfiguration.AC3);
-            else if (isTranscodeToMPEGTSAC3())
+            mimetype = getFormatConfiguration().match(FormatConfiguration.MPEGPS, FormatConfiguration.MPEG2, FormatConfiguration.AC3);
+            if (isTranscodeToMPEGTSAC3())
                mimetype = getFormatConfiguration().match(FormatConfiguration.MPEGTS, FormatConfiguration.MPEG2, FormatConfiguration.AC3);
             else if (isTranscodeToWMV())
                mimetype = getFormatConfiguration().match(FormatConfiguration.WMV, FormatConfiguration.WMV, FormatConfiguration.WMA);
          } else if (mimetype != null && mimetype.equals(HTTPResource.AUDIO_TRANSCODE)) {
-            if (isTranscodeToPCM())
+            mimetype = getFormatConfiguration().match(FormatConfiguration.LPCM, null, null);
+            if (isTranscodeAudioTo441())
+               mimetype += ";rate=44100;channels=2";
+            else
+               mimetype += ";rate=48000;channels=2";
+            if (isTranscodeToWAV())
                mimetype = getFormatConfiguration().match(FormatConfiguration.WAV, null, null);
             else if (isTranscodeToMP3())
                mimetype = getFormatConfiguration().match(FormatConfiguration.MP3, null, null);
@@ -466,9 +475,15 @@
          if (isTranscodeToWMV())
             mimetype = HTTPResource.WMV_TYPEMIME;
       } else if (mimetype != null && mimetype.equals(HTTPResource.AUDIO_TRANSCODE)) {
-         mimetype = HTTPResource.AUDIO_WAV_TYPEMIME;
+         mimetype = HTTPResource.AUDIO_LPCM_TYPEMIME;
+         if (isTranscodeAudioTo441())
+            mimetype += ";rate=44100;channels=2";
+         else
+            mimetype += ";rate=48000;channels=2";
          if (isTranscodeToMP3())
             mimetype = HTTPResource.AUDIO_MP3_TYPEMIME;
+         if (isTranscodeToWAV())
+            mimetype = HTTPResource.AUDIO_WAV_TYPEMIME;
       }
       if (mimes.containsKey(mimetype)) {
          return mimes.get(mimetype);
@@ -583,7 +598,7 @@
          else if (FormatConfiguration.MP3.equals(audioTranscoder))
             return MP3;
       }*/
-      return getString(TRANSCODE_AUDIO, PCM);
+      return getString(TRANSCODE_AUDIO, LPCM);
    }
    
    public boolean isDefaultVBVSize() {
Index: net/pms/dlna/DLNAResource.java
===================================================================
--- net/pms/dlna/DLNAResource.java   (wersja 470)
+++ net/pms/dlna/DLNAResource.java   (kopia robocza)
@@ -898,7 +898,7 @@
                dlnaspec = "DLNA.ORG_PN=JPEG_LRG";
             else if (mime.equals("audio/mpeg"))
                dlnaspec = "DLNA.ORG_PN=MP3";
-            else if (mime.equals("audio/L16") || mime.equals("audio/wav"))
+            else if (mime.substring(0,9).equals("audio/L16") || mime.equals("audio/wav"))
                dlnaspec = "DLNA.ORG_PN=LPCM";
          }
          
Index: net/pms/encoders/FFMpegAudio.java
===================================================================
--- net/pms/encoders/FFMpegAudio.java   (wersja 470)
+++ net/pms/encoders/FFMpegAudio.java   (kopia robocza)
@@ -116,7 +116,7 @@
       /*if (overridenArgs != null)
          return overridenArgs;
       else*/
-         return new String [] { "-f", "wav", "-ar", "48000"}; //$NON-NLS-1$ //$NON-NLS-2$
+         return new String [] { "-f", "s16be", "-ar", "48000"}; //$NON-NLS-1$ //$NON-NLS-2$
    }
 
    @Override
@@ -138,6 +138,9 @@
       if (params.mediaRenderer.isTranscodeToMP3()) {
          args = new String [] { "-f", "mp3", "-ar", "48000", "-ab", "320000" };
       }
+      if (params.mediaRenderer.isTranscodeToWAV()) {
+         args = new String [] { "-f", "wav", "-ar", "48000"};
+       }
       if (params.mediaRenderer.isTranscodeAudioTo441())
          args[3] = "44100";
       if (!configuration.isAudioResample()) {
Index: net/pms/encoders/MPlayerAudio.java
===================================================================
--- net/pms/encoders/MPlayerAudio.java   (wersja 470)
+++ net/pms/encoders/MPlayerAudio.java   (kopia robocza)
@@ -90,7 +90,10 @@
       params.maxBufferSize = PMS.getConfiguration().getMaxAudioBuffer();
       PipeProcess audioP = new PipeProcess("mplayer_aud" + System.currentTimeMillis()); //$NON-NLS-1$
          
-      String mPlayerdefaultAudioArgs [] = new String [] { PMS.getConfiguration().getMplayerPath(), fileName, "-prefer-ipv4", "-nocache", "-af", "channels=2", "-srate", "48000", "-vo", "null", "-ao", "pcm:waveheader:fast:file=" + audioP.getInputPipe(), "-quiet" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$
+      String mPlayerdefaultAudioArgs [] = new String [] { PMS.getConfiguration().getMplayerPath(), fileName, "-prefer-ipv4", "-nocache", "-af", "channels=2", "-srate", "48000", "-vo", "null", "-ao", "pcm:nowaveheader:fast:file=" + audioP.getInputPipe(), "-format", "s16be" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$
+      if (params.mediaRenderer.isTranscodeToWAV()) {
+         mPlayerdefaultAudioArgs[11] = "pcm:waveheader:fast:file="  + audioP.getInputPipe();
+      }
       if (params.mediaRenderer.isTranscodeAudioTo441())
          mPlayerdefaultAudioArgs[7] = "44100";
       if (!configuration.isAudioResample()) {
Index: net/pms/network/HTTPResource.java
===================================================================
--- net/pms/network/HTTPResource.java   (wersja 470)
+++ net/pms/network/HTTPResource.java   (kopia robocza)
@@ -49,6 +49,7 @@
    public static final String AUDIO_WMA_TYPEMIME = "audio/x-ms-wma";
    public static final String AUDIO_FLAC_TYPEMIME = "audio/x-flac";
    public static final String AUDIO_OGG_TYPEMIME = "audio/x-ogg";
+   public static final String AUDIO_LPCM_TYPEMIME = "audio/L16";
    
    public static final String MPEG_TYPEMIME = "video/mpeg";
    public static final String MP4_TYPEMIME = "video/mp4";
Index: renderers/Bravia4500.conf
===================================================================
--- renderers/Bravia4500.conf   (wersja 470)
+++ renderers/Bravia4500.conf   (kopia robocza)
@@ -11,7 +11,7 @@
 Image=true
 SeekByTime=false
 TranscodeVideo=MPEGAC3
-TranscodeAudio=MP3
+TranscodeAudio=LPCM
 DefaultVBVBufSize=true
 MuxH264ToMpegTS=true
 MuxDTSToMpeg=true
Index: renderers/Bravia5500.conf
===================================================================
--- renderers/Bravia5500.conf   (wersja 470)
+++ renderers/Bravia5500.conf   (kopia robocza)
@@ -11,7 +11,7 @@
 Image=true
 SeekByTime=true
 TranscodeVideo=MPEGAC3
-TranscodeAudio=MP3
+TranscodeAudio=LPCM
 DefaultVBVBufSize=true
 MuxH264ToMpegTS=true
 MuxDTSToMpeg=false
@@ -21,16 +21,16 @@
 MaxVideoWidth=0
 MaxVideoHeight=0
 H264Level41Limited=true
-MimeTypesChanges=audio/wav=audio/L16|video/mp4=video/mpeg
+#MimeTypesChanges=video/mp4=video/mpeg
 DLNALocalizationRequired=true
 TranscodeExtensions=dvr-ms,dvr,mkv,dv,ty,mov,ogm,hdmov,hdm,rmv,rmvb,rm,asf,evo,asx,flv,m2v,mpe,mod,tivo,ty,tmf,ts,tp,m2p,mp4,m4v,avi,wmv,wm,divx,div,flac,mlp,fla,wma,m4a,aac,dts,mka,ape,ogg,shn,mpc,ra,mp2,wv,oma,aa3,gif,png,arw,cr2,crw,dng,raf,mrw,nef,pef,tif,tiff
 StreamExtensions=
 
-
 #Better/faster codec detection method ! true to enable it
 #Need testing !
-MediaInfo=false
-Supported = f:mpegps|mpegts    v:mpeg2|mp4|h264    a:ac3|lpcm|aac|mpa   m:video/mpeg
+MediaInfo=true
+# temporary removed lpcm
+Supported = f:mpegps|mpegts    v:mpeg2|h264    a:ac3|aac|mpa   m:video/mpeg
 Supported = f:mp3   m:audio/mpeg
-Supported = f:wav   m:audio/L16
+Supported = f:lpcm   m:audio/L16
 Supported = f:jpg   m:image/jpeg
\ No newline at end of file
Index: renderers/BraviaEX.conf
===================================================================
--- renderers/BraviaEX.conf   (wersja 470)
+++ renderers/BraviaEX.conf   (kopia robocza)
@@ -11,7 +11,7 @@
 Image=true
 SeekByTime=true
 TranscodeVideo=MPEGAC3
-TranscodeAudio=MP3
+TranscodeAudio=LPCM
 DefaultVBVBufSize=true
 MuxH264ToMpegTS=true
 MuxDTSToMpeg=false
Index: renderers/FreeboxHD.conf
===================================================================
--- renderers/FreeboxHD.conf   (wersja 470)
+++ renderers/FreeboxHD.conf   (kopia robocza)
@@ -12,7 +12,7 @@
 TranscodeVideo=MPEGTSAC3
 MimeTypesChanges=video/mpeg=video/mp2t
 UseSameExtension=ts
-TranscodeAudio=PCM
+TranscodeAudio=WAV
 DefaultVBVBufSize=true
 MuxH264ToMpegTS=true
 MuxDTSToMpeg=false
Index: renderers/FreecomMusicPal.conf
===================================================================
--- renderers/FreecomMusicPal.conf   (wersja 470)
+++ renderers/FreecomMusicPal.conf   (kopia robocza)
@@ -27,9 +27,9 @@
 #
 
 #Transcode codecs for video and audio engines
-#currently supported: MPEGAC3 or WMV for video, PCM or MP3 for audio
+#currently supported: MPEGAC3 or WMV for video, LPCM, WAV or MP3 for audio
 TranscodeVideo=MPEGAC3
-TranscodeAudio=PCM
+TranscodeAudio=WAV
 
 #Use default DVD buffer size: false = greater bitrate and faster encoding,
 #but can generate incompatible videos, depends of your media renderer
Index: renderers/PS3.conf
===================================================================
--- renderers/PS3.conf   (wersja 470)
+++ renderers/PS3.conf   (kopia robocza)
@@ -35,9 +35,9 @@
 #
 
 #Transcode codecs for video and audio engines
-#currently supported: MPEGAC3, MPEGTSAC3 or WMV for video, PCM or MP3 for audio
+#currently supported: MPEGAC3, MPEGTSAC3 or WMV for video, LPCM, WAV or MP3 for audio
 TranscodeVideo=MPEGAC3
-TranscodeAudio=PCM
+TranscodeAudio=WAV
 
 #Use default DVD buffer size: false = greater bitrate and faster encoding,
 #but can generate incompatible videos, depends of your media renderer
Index: renderers/Philips.conf
===================================================================
--- renderers/Philips.conf   (wersja 470)
+++ renderers/Philips.conf   (kopia robocza)
@@ -30,9 +30,9 @@
 ## Transcoding/Muxing capabilities
 
 ##Transcode codecs for video and audio engines #
-##currently supported: MPEGAC3 or WMV for video, PCM or MP3 for audio
+##currently supported: MPEGAC3 or WMV for video, LPCM, WAV or MP3 for audio
 TranscodeVideo=MPEGAC3
-TranscodeAudio=PCM
+TranscodeAudio=LPCM
 ## TranscodeAudio=MP3
 
 ##Use default DVD buffer size: false = greater bitrate and faster encoding,
Index: renderers/PopcornHour.conf
===================================================================
--- renderers/PopcornHour.conf   (wersja 470)
+++ renderers/PopcornHour.conf   (kopia robocza)
@@ -9,7 +9,7 @@
 Image=true
 SeekByTime=false
 TranscodeVideo=MPEGAC3
-TranscodeAudio=PCM
+TranscodeAudio=LPCM
 DefaultVBVBufSize=true
 MuxH264ToMpegTS=true
 MuxDTSToMpeg=true
Index: renderers/Realtek.conf
===================================================================
--- renderers/Realtek.conf   (wersja 470)
+++ renderers/Realtek.conf   (kopia robocza)
@@ -36,9 +36,9 @@
 #
 
 #Transcode codecs for video and audio engines
-#currently supported: MPEGAC3 or WMV for video, PCM or MP3 for audio
+#currently supported: MPEGAC3 or WMV for video, LPCM, WAV or MP3 for audio
 TranscodeVideo=MPEGAC3
-TranscodeAudio=PCM
+TranscodeAudio=LPCM
 
 #Use default DVD buffer size: false = greater bitrate and faster encoding,
 #but can generate incompatible videos, depends of your media renderer
Index: renderers/Samsung.conf
===================================================================
--- renderers/Samsung.conf   (wersja 470)
+++ renderers/Samsung.conf   (kopia robocza)
@@ -9,7 +9,7 @@
 Image=true
 SeekByTime=false
 TranscodeVideo=MPEGAC3
-TranscodeAudio=PCM
+TranscodeAudio=LPCM
 DefaultVBVBufSize=true
 MuxH264ToMpegTS=true
 MuxDTSToMpeg=true
Index: renderers/Streamium.conf
===================================================================
--- renderers/Streamium.conf   (wersja 470)
+++ renderers/Streamium.conf   (kopia robocza)
@@ -28,9 +28,9 @@
 #
 
 #Transcode codecs for video and audio engines
-#currently supported: MPEGAC3 or WMV for video, PCM or MP3 for audio
+#currently supported: MPEGAC3 or WMV for video, LPCM, WAV or MP3 for audio
 TranscodeVideo=MPEGAC3
-TranscodeAudio=PCM
+TranscodeAudio=WAV
 
 #Use default DVD buffer size: false = greater bitrate and faster encoding,
 #but can generate incompatible videos, depends of your media renderer
Index: renderers/WDTVLive.conf
===================================================================
--- renderers/WDTVLive.conf   (wersja 470)
+++ renderers/WDTVLive.conf   (kopia robocza)
@@ -9,7 +9,7 @@
 Image=true
 SeekByTime=false
 TranscodeVideo=MPEGAC3
-TranscodeAudio=PCM
+TranscodeAudio=WAV
 DefaultVBVBufSize=false
 MuxH264ToMpegTS=false
 MuxDTSToMpeg=true
Index: renderers/XBMC.conf
===================================================================
--- renderers/XBMC.conf   (wersja 470)
+++ renderers/XBMC.conf   (kopia robocza)
@@ -9,7 +9,7 @@
 Image=true
 SeekByTime=false
 TranscodeVideo=MPEGAC3
-TranscodeAudio=PCM
+TranscodeAudio=WAV
 DefaultVBVBufSize=true
 MuxH264ToMpegTS=true
 MuxDTSToMpeg=true
tomeko
Project Member
 
Posts: 154
Joined: Sat Jun 06, 2009 11:02 am

Re: Patch to LPCM audio transcoding

Postby shagrath » Tue Feb 01, 2011 12:23 am

Thanks, I'm reviewing it right now

For non DLNA renderes, that supports WAV, not LPCM


I'm ok with this, but may I ask how do you choose between WAV and LPCM for these renderers ? (you put LPCM for Realtek renderers for example). you checked the specs for each device ?
shagrath
Project Lead
 
Posts: 2667
Joined: Wed Jan 14, 2009 1:39 pm

Re: Patch to LPCM audio transcoding

Postby shagrath » Tue Feb 01, 2011 12:38 am

Also, is the
Code: Select all
mimetype += ";rate=44100;channels=2";
really necessary ?
shagrath
Project Lead
 
Posts: 2667
Joined: Wed Jan 14, 2009 1:39 pm

Re: Patch to LPCM audio transcoding

Postby mazey » Tue Feb 01, 2011 2:56 am

just a slight #note error

Modify /trunk/ps3mediaserver/renderers/PS3.conf diff
...
37 37 #Transcode codecs for video and audio engines
38 38 #currently supported: MPEGAC3, MPEGTSAC3 or WMV for video, PCM or MP3 for audio
39 39 TranscodeVideo=MPEGAC3
40 - TranscodeAudio=PCM
40 + TranscodeAudio=WAV

line 38 of ps3.conf should change PCM to WAV now in the note.
PMS 1.90.2 Snapshot - Intel Celeron G1840 2.8Ghz / Asus Z97m-plus / Corsair Vengeance 8GB / Windows 8.1 Pro (64 bit)
mazey
 
Posts: 775
Joined: Sat Oct 24, 2009 9:07 am

Re: Patch to LPCM audio transcoding

Postby tomeko » Tue Feb 01, 2011 9:17 am

shagrath wrote: you checked the specs for each device ?

Yes, I briefly reviewed.
shagrath wrote:Also, is the
Code: Select all
mimetype += ";rate=44100;channels=2";
really necessary ?

There's no any headers in LPCM stream with any information about parameters, only bitstream.
tomeko
Project Member
 
Posts: 154
Joined: Sat Jun 06, 2009 11:02 am

Re: Patch to LPCM audio transcoding

Postby shagrath » Wed Feb 02, 2011 1:21 am

tomeko wrote:
shagrath wrote:Also, is the
Code: Select all
mimetype += ";rate=44100;channels=2";
really necessary ?

There's no any headers in LPCM stream with any information about parameters, only bitstream.


yeah make sense ;) (I confused raw LPCM stream with the "LPCM wrapper" I wrote with a payload, PCMAudioOutputStream.java)
shagrath
Project Lead
 
Posts: 2667
Joined: Wed Jan 14, 2009 1:39 pm

Re: Patch to LPCM audio transcoding

Postby tsynik » Fri Sep 23, 2011 4:54 pm

Thanks for patch and information. Found this thread trying setting FLAC playback on Bravia CX520 TV (Latest PMS 1.40b2). None of the other suggestions help, but modifying BraviaEX.conf as described in patch helped me:

Code: Select all
TranscodeAudio=LPCM
-MimeTypesChanges=audio/wav=audio/L16|video/mp4=video/mpeg
+MimeTypesChanges=video/mp4=video/mpeg
+# Temporary removed for LPCM/FLAC
-Supported = f:wav a:dts|lpcm n:6 s:48000 m:audio/wav
-Supported = f:wav n:2 s:48000 m:audio/wav
+Supported = f:lpcm   m:audio/L16


Also, for correct stereo FLAC audio playback need to switch to FFmpeg audio engine instead of MPlayer audio (move it up in PMS preferences). With MPlayer Audio I have "digital noise" instead of actual audio. Both MPlayer Audio and MPlayer Web generate digital noise instead of actual sound for audio streams (FLAC / any audio WEB streams like Engadget Podcast). I think it related to transcode command line options for them (http://code.google.com/p/ps3mediaserver ... ail?id=457)

MPlayer seems to procude valid LPCM with additional command line option "-format s16be" and nowaveheader. I locally changed MPlayerAudio.java accordingly and now my BRAVIA is able to playback wma files transcoded to LPCM by MPlayer.


There is no -format s16be in debug logs:

Code: Select all
[osx/mplayer] DEBUG 21:26:20.638 Starting /Applications/PS3 Media Server.app/Contents/Resources/Java/osx/mplayer http://www.engadget.com/podcasts/Engadget_Podcast_257.mp3 -prefer-ipv4 -nocache -af channels=2 -srate 48000 -vo null -ao pcm:nowaveheader:fast:file=/var/folders/k7/5t4zlt790lg9kl5j655ycnf80000gn/T/ps3mediaserver/mplayer_aud1316971580536 -quiet


This one for FFMpeg works fine an have -f s16be:
Code: Select all
Starting transcode/remux of 01. Interzone - Army of me.flac
[osx/ffmpeg] DEBUG 21:11:16.265 Starting /Applications/PS3 Media Server.app/Contents/Resources/Java/osx/ffmpeg -sn -sn -sn -sn -sn -sn -i /Users/nikk/Music/LoSSLeSS/Bjork (2005) Army of Me Remixes and Covers/01. Interzone - Army of me.flac -sn -sn -f s16be -ar 48000 -muxpreload 0 pipe:
[osx/ffmpeg] DEBUG 21:11:16.331 Attaching thread: osx/ffmpeg


Now I have working FLAC playback. I think we have old BraviaEX.conf in stock PMS 1.40.b2, and it need to be modified in that way to support FLAC audio playback. FLAC audio playback doesn't work for me from PMS 1.30.0 till 1.40.b2 with BraviaEX.conf, now its OK!

Also, I can play FLAC or any WEB audio streams with TranscodeAudio=MP3. In that case they all appear as MP3 on my TV and no sound issues at all.
tsynik
 
Posts: 4
Joined: Mon Jul 18, 2011 7:02 am


Return to Developers

Who is online

Users browsing this forum: No registered users and 1 guest