Skip to content

Commit

Permalink
Update to libopus v1.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
cgutman committed Mar 18, 2024
1 parent 124bfdf commit f54f8c8
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 450 deletions.
1 change: 1 addition & 0 deletions app/src/main/jni/moonlight-core/Build.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Static libraries were built from https://github.com/cgutman/moonlight-mobile-deps using AppVeyor CI
Binary file modified app/src/main/jni/moonlight-core/libopus/arm64-v8a/libopus.a
Binary file not shown.
Binary file modified app/src/main/jni/moonlight-core/libopus/armeabi-v7a/libopus.a
Binary file not shown.
100 changes: 0 additions & 100 deletions app/src/main/jni/moonlight-core/libopus/build_android.sh

This file was deleted.

126 changes: 122 additions & 4 deletions app/src/main/jni/moonlight-core/libopus/include/opus.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ extern "C" {
* @endcode
*
* where opus_encoder_get_size() returns the required size for the encoder state. Note that
* future versions of this code may change the size, so no assuptions should be made about it.
* future versions of this code may change the size, so no assumptions should be made about it.
*
* The encoder state is always continuous in memory and only a shallow copy is sufficient
* to copy it (e.g. memcpy())
Expand Down Expand Up @@ -198,7 +198,7 @@ OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_encoder_get_size(int channels);
* This must be one of 8000, 12000, 16000,
* 24000, or 48000.
* @param [in] channels <tt>int</tt>: Number of channels (1 or 2) in input signal
* @param [in] application <tt>int</tt>: Coding mode (@ref OPUS_APPLICATION_VOIP/@ref OPUS_APPLICATION_AUDIO/@ref OPUS_APPLICATION_RESTRICTED_LOWDELAY)
* @param [in] application <tt>int</tt>: Coding mode (one of @ref OPUS_APPLICATION_VOIP, @ref OPUS_APPLICATION_AUDIO, or @ref OPUS_APPLICATION_RESTRICTED_LOWDELAY)
* @param [out] error <tt>int*</tt>: @ref opus_errorcodes
* @note Regardless of the sampling rate and number channels selected, the Opus encoder
* can switch to a lower audio bandwidth or number of channels if the bitrate
Expand All @@ -222,7 +222,7 @@ OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusEncoder *opus_encoder_create(
* This must be one of 8000, 12000, 16000,
* 24000, or 48000.
* @param [in] channels <tt>int</tt>: Number of channels (1 or 2) in input signal
* @param [in] application <tt>int</tt>: Coding mode (OPUS_APPLICATION_VOIP/OPUS_APPLICATION_AUDIO/OPUS_APPLICATION_RESTRICTED_LOWDELAY)
* @param [in] application <tt>int</tt>: Coding mode (one of OPUS_APPLICATION_VOIP, OPUS_APPLICATION_AUDIO, or OPUS_APPLICATION_RESTRICTED_LOWDELAY)
* @retval #OPUS_OK Success or @ref opus_errorcodes
*/
OPUS_EXPORT int opus_encoder_init(
Expand Down Expand Up @@ -357,7 +357,7 @@ OPUS_EXPORT int opus_encoder_ctl(OpusEncoder *st, int request, ...) OPUS_ARG_NON
* error = opus_decoder_init(dec, Fs, channels);
* @endcode
* where opus_decoder_get_size() returns the required size for the decoder state. Note that
* future versions of this code may change the size, so no assuptions should be made about it.
* future versions of this code may change the size, so no assumptions should be made about it.
*
* The decoder state is always continuous in memory and only a shallow copy is sufficient
* to copy it (e.g. memcpy())
Expand Down Expand Up @@ -398,6 +398,21 @@ OPUS_EXPORT int opus_encoder_ctl(OpusEncoder *st, int request, ...) OPUS_ARG_NON
*/
typedef struct OpusDecoder OpusDecoder;

/** Opus DRED decoder.
* This contains the complete state of an Opus DRED decoder.
* It is position independent and can be freely copied.
* @see opus_dred_decoder_create,opus_dred_decoder_init
*/
typedef struct OpusDREDDecoder OpusDREDDecoder;


/** Opus DRED state.
* This contains the complete state of an Opus DRED packet.
* It is position independent and can be freely copied.
* @see opus_dred_create,opus_dred_init
*/
typedef struct OpusDRED OpusDRED;

/** Gets the size of an <code>OpusDecoder</code> structure.
* @param [in] channels <tt>int</tt>: Number of channels.
* This must be 1 or 2.
Expand Down Expand Up @@ -511,6 +526,101 @@ OPUS_EXPORT int opus_decoder_ctl(OpusDecoder *st, int request, ...) OPUS_ARG_NON
*/
OPUS_EXPORT void opus_decoder_destroy(OpusDecoder *st);

/** Gets the size of an <code>OpusDREDDecoder</code> structure.
* @returns The size in bytes.
*/
OPUS_EXPORT int opus_dred_decoder_get_size(void);

/** Allocates and initializes an OpusDREDDecoder state.
* @param [out] error <tt>int*</tt>: #OPUS_OK Success or @ref opus_errorcodes
*/
OPUS_EXPORT OpusDREDDecoder *opus_dred_decoder_create(int *error);

/** Initializes an <code>OpusDREDDecoder</code> state.
* @param[in] dec <tt>OpusDREDDecoder*</tt>: State to be initialized.
*/
OPUS_EXPORT int opus_dred_decoder_init(OpusDREDDecoder *dec);

/** Frees an <code>OpusDREDDecoder</code> allocated by opus_dred_decoder_create().
* @param[in] dec <tt>OpusDREDDecoder*</tt>: State to be freed.
*/
OPUS_EXPORT void opus_dred_decoder_destroy(OpusDREDDecoder *dec);

/** Perform a CTL function on an Opus DRED decoder.
*
* Generally the request and subsequent arguments are generated
* by a convenience macro.
* @param dred_dec <tt>OpusDREDDecoder*</tt>: DRED Decoder state.
* @param request This and all remaining parameters should be replaced by one
* of the convenience macros in @ref opus_genericctls or
* @ref opus_decoderctls.
* @see opus_genericctls
* @see opus_decoderctls
*/
OPUS_EXPORT int opus_dred_decoder_ctl(OpusDREDDecoder *dred_dec, int request, ...);

/** Gets the size of an <code>OpusDRED</code> structure.
* @returns The size in bytes.
*/
OPUS_EXPORT int opus_dred_get_size(void);

/** Allocates and initializes a DRED state.
* @param [out] error <tt>int*</tt>: #OPUS_OK Success or @ref opus_errorcodes
*/
OPUS_EXPORT OpusDRED *opus_dred_alloc(int *error);

/** Frees an <code>OpusDRED</code> allocated by opus_dred_create().
* @param[in] dec <tt>OpusDRED*</tt>: State to be freed.
*/
OPUS_EXPORT void opus_dred_free(OpusDRED *dec);

/** Decode an Opus DRED packet.
* @param [in] dred_dec <tt>OpusDRED*</tt>: DRED Decoder state
* @param [in] dred <tt>OpusDRED*</tt>: DRED state
* @param [in] data <tt>char*</tt>: Input payload
* @param [in] len <tt>opus_int32</tt>: Number of bytes in payload
* @param [in] max_dred_samples <tt>opus_int32</tt>: Maximum number of DRED samples that may be needed (if available in the packet).
* @param [in] sampling_rate <tt>opus_int32</tt>: Sampling rate used for max_dred_samples argument. Needs not match the actual sampling rate of the decoder.
* @param [out] dred_end <tt>opus_int32*</tt>: Number of non-encoded (silence) samples between the DRED timestamp and the last DRED sample.
* @param [in] defer_processing <tt>int</tt>: Flag (0 or 1). If set to one, the CPU-intensive part of the DRED decoding is deferred until opus_dred_process() is called.
* @returns Offset (positive) of the first decoded DRED samples, zero if no DRED is present, or @ref opus_errorcodes
*/
OPUS_EXPORT int opus_dred_parse(OpusDREDDecoder *dred_dec, OpusDRED *dred, const unsigned char *data, opus_int32 len, opus_int32 max_dred_samples, opus_int32 sampling_rate, int *dred_end, int defer_processing) OPUS_ARG_NONNULL(1);

/** Finish decoding an Opus DRED packet. The function only needs to be called if opus_dred_parse() was called with defer_processing=1.
* The source and destination will often be the same DRED state.
* @param [in] dred_dec <tt>OpusDRED*</tt>: DRED Decoder state
* @param [in] src <tt>OpusDRED*</tt>: Source DRED state to start the processing from.
* @param [out] dst <tt>OpusDRED*</tt>: Destination DRED state to store the updated state after processing.
* @returns @ref opus_errorcodes
*/
OPUS_EXPORT int opus_dred_process(OpusDREDDecoder *dred_dec, const OpusDRED *src, OpusDRED *dst);

/** Decode audio from an Opus DRED packet with floating point output.
* @param [in] st <tt>OpusDecoder*</tt>: Decoder state
* @param [in] dred <tt>OpusDRED*</tt>: DRED state
* @param [in] dred_offset <tt>opus_int32</tt>: position of the redundancy to decode (in samples before the beginning of the real audio data in the packet).
* @param [out] pcm <tt>opus_int16*</tt>: Output signal (interleaved if 2 channels). length
* is frame_size*channels*sizeof(opus_int16)
* @param [in] frame_size Number of samples per channel to decode in \a pcm.
* frame_size <b>must</b> be a multiple of 2.5 ms.
* @returns Number of decoded samples or @ref opus_errorcodes
*/
OPUS_EXPORT int opus_decoder_dred_decode(OpusDecoder *st, const OpusDRED *dred, opus_int32 dred_offset, opus_int16 *pcm, opus_int32 frame_size);

/** Decode audio from an Opus DRED packet with floating point output.
* @param [in] st <tt>OpusDecoder*</tt>: Decoder state
* @param [in] dred <tt>OpusDRED*</tt>: DRED state
* @param [in] dred_offset <tt>opus_int32</tt>: position of the redundancy to decode (in samples before the beginning of the real audio data in the packet).
* @param [out] pcm <tt>float*</tt>: Output signal (interleaved if 2 channels). length
* is frame_size*channels*sizeof(float)
* @param [in] frame_size Number of samples per channel to decode in \a pcm.
* frame_size <b>must</b> be a multiple of 2.5 ms.
* @returns Number of decoded samples or @ref opus_errorcodes
*/
OPUS_EXPORT int opus_decoder_dred_decode_float(OpusDecoder *st, const OpusDRED *dred, opus_int32 dred_offset, float *pcm, opus_int32 frame_size);


/** Parse an opus packet into one or more frames.
* Opus_decode will perform this operation internally so most applications do
* not need to use this function.
Expand Down Expand Up @@ -583,6 +693,14 @@ OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_frames(const unsigned
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_samples(const unsigned char packet[], opus_int32 len, opus_int32 Fs) OPUS_ARG_NONNULL(1);

/** Checks whether an Opus packet has LBRR.
* @param [in] packet <tt>char*</tt>: Opus packet
* @param [in] len <tt>opus_int32</tt>: Length of packet
* @returns 1 is LBRR is present, 0 otherwise
* @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type
*/
OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_has_lbrr(const unsigned char packet[], opus_int32 len);

/** Gets the number of samples of an Opus packet.
* @param [in] dec <tt>OpusDecoder*</tt>: Decoder state
* @param [in] packet <tt>char*</tt>: Opus packet
Expand Down
Loading

0 comments on commit f54f8c8

Please sign in to comment.