Update Moonlight-common-c

This commit is contained in:
Iwan Timmer
2017-05-28 14:56:36 +02:00
parent 343e3992c1
commit a0462e49b8
10 changed files with 66 additions and 49 deletions

View File

@@ -23,13 +23,13 @@
#include <opus_multistream.h>
#include <alsa/asoundlib.h>
#define CHECK_RETURN(f) if ((rc = f) < 0) { printf("Alsa error code %d\n", rc); exit(-1); }
#define CHECK_RETURN(f) if ((rc = f) < 0) { printf("Alsa error code %d\n", rc); return -1; }
static snd_pcm_t *handle;
static OpusMSDecoder* decoder;
static short pcmBuffer[FRAME_SIZE * MAX_CHANNEL_COUNT];
static void alsa_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig) {
static int alsa_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig) {
int rc;
unsigned char alsaMapping[MAX_CHANNEL_COUNT];
@@ -81,6 +81,8 @@ static void alsa_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGU
snd_pcm_sw_params_free(sw_params);
CHECK_RETURN(snd_pcm_prepare(handle));
return 0;
}
static void alsa_renderer_cleanup() {

View File

@@ -32,7 +32,7 @@ static OMX_BUFFERHEADERTYPE *buf;
static short pcmBuffer[FRAME_SIZE * MAX_CHANNEL_COUNT];
static int channelCount;
static void omx_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig) {
static int omx_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig) {
int rc, error;
OMX_ERRORTYPE err;
unsigned char omxMapping[MAX_CHANNEL_COUNT];
@@ -54,17 +54,17 @@ static void omx_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGUR
handle = ilclient_init();
if (handle == NULL) {
fprintf(stderr, "IL client init failed\n");
exit(1);
return -1;
}
if (ilclient_create_component(handle, &component, componentName, ILCLIENT_DISABLE_ALL_PORTS | ILCLIENT_ENABLE_INPUT_BUFFERS) != 0) {
fprintf(stderr, "Component create failed\n");
exit(1);
return -1;
}
if (ilclient_change_component_state(component, OMX_StateIdle)!= 0) {
fprintf(stderr, "Couldn't change state to Idle\n");
exit(1);
return -1;
}
// must be before we enable buffers
@@ -119,7 +119,7 @@ static void omx_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGUR
err = OMX_SetParameter(ilclient_get_handle(component), OMX_IndexParamAudioPcm, &sPCMMode);
if(err != OMX_ErrorNone){
fprintf(stderr, "PCM mode unsupported\n");
return;
return -1;
}
OMX_CONFIG_BRCMAUDIODESTINATIONTYPE arDest;
@@ -136,7 +136,7 @@ static void omx_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGUR
err = OMX_SetParameter(ilclient_get_handle(component), OMX_IndexConfigBrcmAudioDestination, &arDest);
if (err != OMX_ErrorNone) {
fprintf(stderr, "Error on setting audio destination\nomx option must be set to hdmi or local\n");
exit(1);
return -1;
}
}
@@ -146,9 +146,11 @@ static void omx_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGUR
err = ilclient_change_component_state(component, OMX_StateExecuting);
if (err < 0) {
fprintf(stderr, "Couldn't change state to Executing\n");
exit(1);
fprintf(stderr, "Couldn't change state to Executing\n");
return -1;
}
return 0;
}
static void omx_renderer_cleanup() {

View File

@@ -47,7 +47,7 @@ bool audio_pulse_init() {
return (bool) dev;
}
static void pulse_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig) {
static int pulse_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig) {
int rc, error;
unsigned char alsaMapping[MAX_CHANNEL_COUNT];
@@ -78,8 +78,10 @@ static void pulse_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIG
if (!dev) {
printf("Pulseaudio error: %s\n", pa_strerror(error));
exit(-1);
return -1;
}
return 0;
}
static void pulse_renderer_decode_and_play_sample(char* data, int length) {

View File

@@ -30,7 +30,7 @@ static short pcmBuffer[FRAME_SIZE * MAX_CHANNEL_COUNT];
static SDL_AudioDeviceID dev;
static int channelCount;
static void sdl_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig) {
static int sdl_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig) {
int rc;
decoder = opus_multistream_decoder_create(opusConfig->sampleRate, opusConfig->channelCount, opusConfig->streams, opusConfig->coupledStreams, opusConfig->mapping, &rc);
@@ -48,11 +48,14 @@ static void sdl_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGUR
dev = SDL_OpenAudioDevice(NULL, 0, &want, &have, SDL_AUDIO_ALLOW_FORMAT_CHANGE);
if (dev == 0) {
printf("Failed to open audio: %s\n", SDL_GetError());
return -1;
} else {
if (have.format != want.format) // we let this one thing change.
printf("We didn't get requested audio format.\n");
SDL_PauseAudioDevice(dev, 0); // start audio playing.
}
return 0;
}
static void sdl_renderer_cleanup() {