简体   繁体   English

在Android上以Java或C / C ++解码Airplay数据包

[英]Decoding Airplay Packets in Java or C/C++ on Android

I'm currently working on an AirPlay receiver for a subpart of an android application. 我目前正在为Android应用程序的子部分开发AirPlay接收器。 I am using the following framework: 我正在使用以下框架:

https://github.com/pentateu/DroidAirPlay https://github.com/pentateu/DroidAirPlay

While this works great on some mid range devices such as the miPad, we need to get this running on a low spec custom device. 虽然这在某些中端设备(例如miPad)上效果很好,但我们需要让它在低规格的自定义设备上运行。 The custom device is decoding the airplay packets at 10x to 20x slower than the miPad. 定制设备以比miPad慢10倍至20倍的速度解码airplay数据包。 As a result, the audio packets lose time synchronisation and due to the time taken to decode the packets, the audio can never re-sync. 结果,音频分组失去时间同步,并且由于解码分组所花费的时间,音频永远无法重新同步。

I was looking into some other airplay receiver apps on the Play Store and from what I can see they tend to be based on Shairport ( https://github.com/abrasive/shairport ) for the airplay receiver side of things. 我在Play商店中研究了其他一些airplay接收器应用程序,从中可以看出,它们往往基于Shairport( https://github.com/abrasive/shairport )来实现airplay接收器方面的功能。

**Note: ** the Shairport based frameworks do not seem to suffer the synchronisation issue on the low end device. **注意:**基于Shairport的框架似乎在低端设备上没有出现同步问题。

The framework I am using is heavily based on the Shairport framework apart from that it is written in Java. 除了使用Java编写之外,我使用的框架很大程度上基于Shairport框架。

For decoding data, is C/C++ far superior than Java? 对于解码数据,C / C ++是否比Java优越?

If so, would directing the decoding part of the DroidAirPlay framework via a C or C++ implementation using the NDK give me a large boost to performance? 如果是这样,是否可以使用NDK通过C或C ++实现来指导DroidAirPlay框架的解码部分,从而大大提高性能?

Thanks in advance 提前致谢

Matt 马特

While it is true that Java compiles to bytecode that runs in a virtual machine, it may not necessarily be slower (or faster) than a natively compiled executable, whether C/C++ or not. 尽管Java确实可以编译为在虚拟机上运行的字节码,但它不一定比本机编译的可执行文件(无论是否为C / C ++)要慢(或快)。 It all depends on the program! 这完全取决于程序!

There's a number of reasons why in this case Java may be slower: 在这种情况下,Java的运行速度可能有多种原因:

  • The decoding implementation might just be poorly coded/optimized? 解码实现可能只是编码/优化不佳? (which isn't really Java's fault) (这不是Java的真正错)
  • The Java compiler may generate sub-optimal code for the JVM. Java编译器可能会为JVM生成次优代码。
  • Some of Java's language constructs are just too slow for the speed/resource demands placed on it here. 对于此处的速度/资源要求,某些Java语言结构太慢了。
  • The JVM just is another abstraction layer and the culprit JVM只是另一个抽象层和元凶
  • The garbage collection is in on it?! 垃圾收集在里面吗?

(I have to note here that I'm not an expert on Java!) (我必须在这里指出,我不是Java专家!)

However, I still wouldn't go so far as to call Java intrinsically slower than C or C++. 但是,我仍然称呼Java 本质上比C或C ++ I'm sure you can find many-a benchmarks and tests on the internet comparing one language to another, and some make claims to a certain degree (out of pride and ego?). 我敢肯定,您可以在互联网上找到许多基准测试,将一种语言与另一种语言进行比较,有些基准和测试在一定程度上声称(出于骄傲和自我?)。 But those tests are only specific cases, usually testing specific aspects of a larger language (hash-map lookup performance for instance!). 但是这些测试只是特定情况,通常会测试较大语言的特定方面 (例如,哈希映射查找性能!)。

LLVM had a three part blog post on C and why undefined behavior allows the compiler to generate still correct but more efficient code at the cost of inferring run-time safety checking or deciding that i+1 always comes after i, totally ignoring the existence of integer overflow. LLVM在C上有一个由三部分组成的博客文章 ,为什么未定义的行为使编译器能够生成仍然正确但更有效的代码,却以推断运行时安全性检查或判定i + 1 总是紧随i之后为代价,而完全忽略了i的存在整数溢出。 If the programmer is not careful, this can have disastrous consequences. 如果程序员不小心,可能会造成灾难性的后果。

In the words of Bjarne himself in Abstraction and the C++ machine model : 用Bjarne本人在Abstraction和C ++机器模型中所说的话:

C++ was designed to be a systems programming language and has been used for embedded systems programming and other resource-constrained types of programming since the earliest days. C ++被设计为一种系统编程语言,并且自最早以来就已用于嵌入式系统编程和其他资源受限的编程类型。

As such, I believe C and C++ can be pushed further than Java because of this undefined behavior and less restrictions placed on it. 因此,我相信C和C ++可以比Java进一步发展,因为这种不确定的行为并且对其施加的限制更少。 (And there's also the inline assembly bit, but that's not strictly C!) (还有内联汇编位,但严格来说不是C!)

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

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