为什么 JMF 不能使用 Mjsip 进行音频流处理?

发布于 2024-12-31 23:21:19 字数 4207 浏览 0 评论 0原文

我正在使用 Mjsip 创建软件电话。在代码中,有三种类型的音频流选项。

  1. 使用 JMF(Java 媒体框架)
  2. 使用 Java 音频
  3. 使用 RAT(鲁棒音频工具)

我没有使用 RAT。它的价值是我自己弄假的。这是调用 JMF 的代码:

public JMFAudioLauncher(int local_port, String remote_addr, int remote_port, int direction, Log logger)
{  
    log=logger;
    localport=local_port;
    remoteport=remote_port;
    remoteaddr=remote_addr;
    // Patch for working with JMF with local streams
    if (remote_addr.startsWith("127."))
    {  
        printLog("Patch for JMF: replaced local destination address "+remote_addr+" with 255.255.255.255");
        remote_addr="255.255.255.255";
    }
    dir=direction;
    if (dir>=0) sender=new JMediaSender("audio",null,remote_addr,remote_port);
    if (dir<=0) receiver=new JMediaReceiver("audio",local_port,null);
}

/** Starts media application */
public boolean startMedia()
{  
    printLog("launching JMF-Audio...");
    String err1=null, err2=null;

    if (sender!=null) err1=sender.start();
    if (err1!=null) printLog("Error trying to send audio stream: "+err1);    

    if (receiver!=null) err2=receiver.start();
    if (err2!=null) printLog("Error trying to receive audio stream: "+err2);    

    return (err1==null && err2==null);      
}

/** Stops media application */
public boolean stopMedia()
{  
    String err1=null, err2=null;

    if (sender!=null) err1=sender.stop();      
    if (err1!=null) printLog("Error stopping audio sender: "+err1);    

    if (receiver!=null) err2=receiver.stop();      
    if (err2!=null) printLog("Error stopping audio receiver: "+err2);    

    return (err1==null && err2==null);      
}

但它没有被启动。我仍然可以用我的软件电话通话。但在日志中它显示...

UA: REGISTRATION
UA: Registration success: 200 OK
UA: INCOMING
UA: CONFIRMED/CALL
UA: Error trying to create the JMFAudioLauncher
AudioInput: TargetDataLine: com.sun.media.sound.DirectAudioDevice$DirectTDL@239525
AudioOutput: SourceDataLine: com.sun.media.sound.DirectAudioDevice$DirectSDL@f942c4
AudioLauncher: starting java audio..

但使用 JMF 值对于 user_agent_profile 是正确的,并且此代码生成错误。

if (user_profile.audio && local_audio_port!=0 && remote_audio_port!=0)
     {  
         if (user_profile.use_rat)
         // create an audio_app and start it
         {  
            audio_app=new RATLauncher(user_profile.bin_rat,local_audio_port,remote_media_address,remote_audio_port,log);
         }
         else if (user_profile.use_jmf)
        {  
            // check if JMF is supported
            try
            {  
                Class myclass=Class.forName("local.ua.JMFAudioLauncher");
                Class[] parameter_types={ Class.forName("int"), Class.forName("java.lang.String"),Class.forName("int"), Class.forName("int"), Class.forName("org.zoolu.tools.Log") };
                Object[] parameters={ new Integer(local_audio_port), remote_media_address, new Integer(remote_audio_port), new Integer(dir), log };
                java.lang.reflect.Constructor constructor=myclass.getConstructor(parameter_types);
                audio_app=(MediaLauncher)constructor.newInstance(parameters);

            }
            catch (Exception e)
            {  
                printException(e,LogLevel.HIGH);
                printLog("Error trying to create the JMFAudioLauncher",LogLevel.HIGH);
            }
        }
        // else
        if (audio_app==null)
        {  
            // for testing..
            String audio_in=null;
            if (user_profile.send_tone) audio_in=JAudioLauncher.TONE;
            else if (user_profile.send_file!=null) audio_in=user_profile.send_file;
            String audio_out=null;
            if (user_profile.recv_file!=null) audio_out=user_profile.recv_file;        

            //audio_app=new JAudioLauncher(local_audio_port,remote_media_address,remote_audio_port,dir,log);
            audio_app=new JAudioLauncher(local_audio_port,remote_media_address,remote_audio_port,dir,audio_in,audio_out,user_profile.audio_sample_rate,user_profile.audio_sample_size,user_profile.audio_frame_size,log);
        }
        audio_app.startMedia();
    }

我该怎么做才能启用 JMF?

I am using Mjsip to create a softphone. In the code there is three type option for audio straming.

  1. Using JMF (Java Media Framework)
  2. Using Java Audio
  3. Using RAT (Robust Audio Tool)

I am not using the RAT. Its value is been made false by myself. This is the code below to call JMF:

public JMFAudioLauncher(int local_port, String remote_addr, int remote_port, int direction, Log logger)
{  
    log=logger;
    localport=local_port;
    remoteport=remote_port;
    remoteaddr=remote_addr;
    // Patch for working with JMF with local streams
    if (remote_addr.startsWith("127."))
    {  
        printLog("Patch for JMF: replaced local destination address "+remote_addr+" with 255.255.255.255");
        remote_addr="255.255.255.255";
    }
    dir=direction;
    if (dir>=0) sender=new JMediaSender("audio",null,remote_addr,remote_port);
    if (dir<=0) receiver=new JMediaReceiver("audio",local_port,null);
}

/** Starts media application */
public boolean startMedia()
{  
    printLog("launching JMF-Audio...");
    String err1=null, err2=null;

    if (sender!=null) err1=sender.start();
    if (err1!=null) printLog("Error trying to send audio stream: "+err1);    

    if (receiver!=null) err2=receiver.start();
    if (err2!=null) printLog("Error trying to receive audio stream: "+err2);    

    return (err1==null && err2==null);      
}

/** Stops media application */
public boolean stopMedia()
{  
    String err1=null, err2=null;

    if (sender!=null) err1=sender.stop();      
    if (err1!=null) printLog("Error stopping audio sender: "+err1);    

    if (receiver!=null) err2=receiver.stop();      
    if (err2!=null) printLog("Error stopping audio receiver: "+err2);    

    return (err1==null && err2==null);      
}

But it is not being launched. I can still talk with my softphone. But in the log it shows...

UA: REGISTRATION
UA: Registration success: 200 OK
UA: INCOMING
UA: CONFIRMED/CALL
UA: Error trying to create the JMFAudioLauncher
AudioInput: TargetDataLine: com.sun.media.sound.DirectAudioDevice$DirectTDL@239525
AudioOutput: SourceDataLine: com.sun.media.sound.DirectAudioDevice$DirectSDL@f942c4
AudioLauncher: starting java audio..

But using JMF value is true for the user_agent_profile and the error generates from this code.

if (user_profile.audio && local_audio_port!=0 && remote_audio_port!=0)
     {  
         if (user_profile.use_rat)
         // create an audio_app and start it
         {  
            audio_app=new RATLauncher(user_profile.bin_rat,local_audio_port,remote_media_address,remote_audio_port,log);
         }
         else if (user_profile.use_jmf)
        {  
            // check if JMF is supported
            try
            {  
                Class myclass=Class.forName("local.ua.JMFAudioLauncher");
                Class[] parameter_types={ Class.forName("int"), Class.forName("java.lang.String"),Class.forName("int"), Class.forName("int"), Class.forName("org.zoolu.tools.Log") };
                Object[] parameters={ new Integer(local_audio_port), remote_media_address, new Integer(remote_audio_port), new Integer(dir), log };
                java.lang.reflect.Constructor constructor=myclass.getConstructor(parameter_types);
                audio_app=(MediaLauncher)constructor.newInstance(parameters);

            }
            catch (Exception e)
            {  
                printException(e,LogLevel.HIGH);
                printLog("Error trying to create the JMFAudioLauncher",LogLevel.HIGH);
            }
        }
        // else
        if (audio_app==null)
        {  
            // for testing..
            String audio_in=null;
            if (user_profile.send_tone) audio_in=JAudioLauncher.TONE;
            else if (user_profile.send_file!=null) audio_in=user_profile.send_file;
            String audio_out=null;
            if (user_profile.recv_file!=null) audio_out=user_profile.recv_file;        

            //audio_app=new JAudioLauncher(local_audio_port,remote_media_address,remote_audio_port,dir,log);
            audio_app=new JAudioLauncher(local_audio_port,remote_media_address,remote_audio_port,dir,audio_in,audio_out,user_profile.audio_sample_rate,user_profile.audio_sample_size,user_profile.audio_frame_size,log);
        }
        audio_app.startMedia();
    }

What can I do to enable JMF?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

可遇━不可求 2025-01-07 23:21:19

您能花点时间找出这部分代码在哪一行抛出错误吗?

// check if JMF is supported
try{  
    Class myclass=Class.forName("local.ua.JMFAudioLauncher");
    Class[] parameter_types={ Class.forName("int"), Class.forName("java.lang.String"),Class.forName("int"), Class.forName("int"), Class.forName("org.zoolu.tools.Log") };
    Object[] parameters={ new Integer(local_audio_port), remote_media_address, new Integer(remote_audio_port), new Integer(dir), log };
    java.lang.reflect.Constructor constructor=myclass.getConstructor(parameter_types);
    audio_app=(MediaLauncher)constructor.newInstance(parameters);
    }
catch (Exception e){  
    printException(e,LogLevel.HIGH);
    printLog("Error trying to create the JMFAudioLauncher",LogLevel.HIGH);
    }

Can you please take some time and find in which line the error is thrown on this part of code?

// check if JMF is supported
try{  
    Class myclass=Class.forName("local.ua.JMFAudioLauncher");
    Class[] parameter_types={ Class.forName("int"), Class.forName("java.lang.String"),Class.forName("int"), Class.forName("int"), Class.forName("org.zoolu.tools.Log") };
    Object[] parameters={ new Integer(local_audio_port), remote_media_address, new Integer(remote_audio_port), new Integer(dir), log };
    java.lang.reflect.Constructor constructor=myclass.getConstructor(parameter_types);
    audio_app=(MediaLauncher)constructor.newInstance(parameters);
    }
catch (Exception e){  
    printException(e,LogLevel.HIGH);
    printLog("Error trying to create the JMFAudioLauncher",LogLevel.HIGH);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文