简体   繁体   English

在Windows上的Java和C ++之间发送数据?

[英]Sending data between Java to c++ on windows?

I want to send the raw audio buffer to c++ for audio transcoding. 我想将原始音频缓冲区发送到c ++以进行音频转码。 I have two option 我有两个选择

  1. using piped stream 使用管道流
    • using direct buffers (java.nio) 使用直接缓冲区(java.nio)

Are these really my 2 best options (and which would people recommend?) Thanks! 这些真的是我的2个最佳选择吗(人们会推荐哪个?)谢谢!

JNI is easy to screw up, therefore people tend to complain about it. JNI很容易搞砸,因此人们倾向于抱怨它。 But it is an excellent and extremely stable option, when done correctly. 但是,如果正确完成的话,它是一个极佳且极其稳定的选择。

Direct buffers in NIO will almost certainly have better performance. NIO中的直接缓冲区几乎肯定会具有更好的性能。 This is pretty much the ideal case for direct buffers. 这几乎是直接缓冲区的理想情况。

I'm not sure what the point of your question is - if you want to know if there are other options, then the answer is certainly yet (you could, for example, write to a file then invoke an external application to process it - or you could use JNI without direct buffers). 我不确定您要问的问题是什么-如果您想知道是否还有其他选择,那么答案肯定是(例如,您可以写入文件,然后调用外部应用程序进行处理-或者您可以使用不带直接缓冲区的JNI)。 But if you want a tightly coupled, highly performant interface between Java and C++ code, JNI along with direct buffers, is going to be the tool to use. 但是,如果您想在Java和C ++代码之间建立紧密耦合的高性能接口,则可以将JNI与直接缓冲区一起使用。

您可以使用套接字(接受来自本地的连接),但是我猜想它在* nix系统上会更有效。

If you don't need realtime transcoding, I would choose the buffers approach. 如果您不需要实时转码,我会选择缓冲区方法。 In this way you have better control and you'll be sure that no byte is lost. 这样,您可以更好地进行控制,并且可以确保没有字节丢失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM