mirror of
https://github.com/Genymobile/scrcpy.git
synced 2026-01-25 16:44:26 +01:00
Play the decoded audio using SDL. The audio player frame sink receives the audio frames, resample them and write them to a byte buffer (introduced by this commit). On SDL audio callback (from an internal SDL thread), copy samples from this byte buffer to the SDL audio buffer. The byte buffer is protected by the SDL_AudioDeviceLock(), but it has been designed so that the producer and the consumer may write and read in parallel, provided that they don't access the same slices of the ring-buffer buffer. PR #3757 <https://github.com/Genymobile/scrcpy/pull/3757> Co-authored-by: Simon Chan <1330321+yume-chan@users.noreply.github.com>
41 lines
844 B
C
41 lines
844 B
C
#ifndef SC_AVERAGE
|
|
#define SC_AVERAGE
|
|
|
|
#include "common.h"
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
struct sc_average {
|
|
// Current average value
|
|
float avg;
|
|
|
|
// Target range, to update the average as follow:
|
|
// avg = ((range - 1) * avg + new_value) / range
|
|
unsigned range;
|
|
|
|
// Number of values pushed when less than range (count <= range).
|
|
// The purpose is to handle the first (range - 1) values properly.
|
|
unsigned count;
|
|
};
|
|
|
|
void
|
|
sc_average_init(struct sc_average *avg, unsigned range);
|
|
|
|
/**
|
|
* Push a new value to update the "rolling" average
|
|
*/
|
|
void
|
|
sc_average_push(struct sc_average *avg, float value);
|
|
|
|
/**
|
|
* Get the current average value
|
|
*
|
|
* It is an error to call this function if sc_average_push() has not been
|
|
* called at least once.
|
|
*/
|
|
float
|
|
sc_average_get(struct sc_average *avg);
|
|
|
|
#endif
|