| 660 | } |
| 661 | |
| 662 | FrameObservation classifySoundFrame(const QByteArray& frame) |
| 663 | { |
| 664 | FrameObservation observation; |
| 665 | observation.stream = StreamMode::Sound; |
| 666 | observation.frameBytes = frame.size(); |
| 667 | if (!frame.startsWith("SND")) { |
| 668 | observation.layout = FrameLayout::UnknownBinary; |
| 669 | observation.unsupportedReason = QStringLiteral("Binary frame is not an SND frame"); |
| 670 | return observation; |
| 671 | } |
| 672 | |
| 673 | const SoundFrameHeader header = parseSoundFrameHeader(frame); |
| 674 | const int payloadOffset = header.valid ? soundPayloadOffset(frame) : 0; |
| 675 | observation.payloadBytes = static_cast<int>( |
| 676 | std::max<qsizetype>(0, frame.size() - payloadOffset)); |
| 677 | if (!header.valid) { |
| 678 | observation.layout = FrameLayout::Unsupported; |
| 679 | observation.unsupportedReason = QStringLiteral("SND header is too short"); |
| 680 | return observation; |
| 681 | } |
| 682 | if (soundFrameCompressed(header.flags)) { |
| 683 | observation.layout = FrameLayout::SndCompressed; |
| 684 | if (frame.size() < kServerSoundHeaderBytes) { |
| 685 | observation.unsupportedReason = |
| 686 | QStringLiteral("SND compressed ADPCM header is too short"); |
| 687 | return observation; |
| 688 | } |
| 689 | if (soundFrameStereo(header.flags)) { |
| 690 | observation.unsupportedReason = |
| 691 | QStringLiteral("SND compressed stereo/IQ layout is unsupported"); |
| 692 | return observation; |
| 693 | } |
| 694 | if (observation.payloadBytes <= 0) { |
| 695 | observation.unsupportedReason = |
| 696 | QStringLiteral("SND compressed ADPCM payload is empty"); |
| 697 | return observation; |
| 698 | } |
| 699 | observation.supported = true; |
| 700 | return observation; |
| 701 | } |
| 702 | if (observation.payloadBytes <= 0 || (observation.payloadBytes % 2) != 0) { |
| 703 | observation.layout = FrameLayout::Unsupported; |
| 704 | observation.unsupportedReason = QStringLiteral("SND PCM payload is empty or not 16-bit aligned"); |
| 705 | return observation; |
| 706 | } |
| 707 | |
| 708 | observation.supported = true; |
| 709 | observation.layout = frame.size() == kObservedExtendedSoundFrameBytes |
| 710 | ? FrameLayout::SndObservedPcm16WithMeter |
| 711 | : FrameLayout::SndPcm16; |
| 712 | return observation; |
| 713 | } |
| 714 | |
| 715 | void resetSoundAdpcmState(SoundAdpcmState* state) |
| 716 | { |