mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-04-18 22:39:53 +00:00
Cleanup audio decoding code
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Moonlight Embedded.
|
* This file is part of Moonlight Embedded.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2015 Iwan Timmer
|
* Copyright (C) 2015-2017 Iwan Timmer
|
||||||
*
|
*
|
||||||
* Moonlight is free software; you can redistribute it and/or modify
|
* Moonlight is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -21,6 +21,10 @@
|
|||||||
|
|
||||||
#include <Limelight.h>
|
#include <Limelight.h>
|
||||||
|
|
||||||
|
#define MAX_CHANNEL_COUNT 6
|
||||||
|
#define FRAME_SIZE 240
|
||||||
|
#define FRAME_BUFFER 12
|
||||||
|
|
||||||
extern const char* audio_device;
|
extern const char* audio_device;
|
||||||
|
|
||||||
extern AUDIO_RENDERER_CALLBACKS audio_callbacks_alsa;
|
extern AUDIO_RENDERER_CALLBACKS audio_callbacks_alsa;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Moonlight Embedded.
|
* This file is part of Moonlight Embedded.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2015, 2016 Iwan Timmer
|
* Copyright (C) 2015-2017 Iwan Timmer
|
||||||
*
|
*
|
||||||
* Moonlight is free software; you can redistribute it and/or modify
|
* Moonlight is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -25,16 +25,13 @@
|
|||||||
|
|
||||||
#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); exit(-1); }
|
||||||
|
|
||||||
#define MAX_CHANNEL_COUNT 6
|
|
||||||
#define FRAME_SIZE 240
|
|
||||||
|
|
||||||
static snd_pcm_t *handle;
|
static snd_pcm_t *handle;
|
||||||
static OpusMSDecoder* decoder;
|
static OpusMSDecoder* decoder;
|
||||||
static short pcmBuffer[FRAME_SIZE * MAX_CHANNEL_COUNT];
|
static short pcmBuffer[FRAME_SIZE * MAX_CHANNEL_COUNT];
|
||||||
|
|
||||||
static void alsa_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig) {
|
static void alsa_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig) {
|
||||||
int rc;
|
int rc;
|
||||||
unsigned char alsaMapping[6];
|
unsigned char alsaMapping[MAX_CHANNEL_COUNT];
|
||||||
|
|
||||||
/* The supplied mapping array has order: FL-FR-C-LFE-RL-RR
|
/* The supplied mapping array has order: FL-FR-C-LFE-RL-RR
|
||||||
* ALSA expects the order: FL-FR-RL-RR-C-LFE
|
* ALSA expects the order: FL-FR-RL-RR-C-LFE
|
||||||
@@ -49,17 +46,12 @@ static void alsa_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGU
|
|||||||
alsaMapping[5] = opusConfig->mapping[3];
|
alsaMapping[5] = opusConfig->mapping[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
decoder = opus_multistream_decoder_create(opusConfig->sampleRate,
|
decoder = opus_multistream_decoder_create(opusConfig->sampleRate, opusConfig->channelCount, opusConfig->streams, opusConfig->coupledStreams, alsaMapping, &rc);
|
||||||
opusConfig->channelCount,
|
|
||||||
opusConfig->streams,
|
|
||||||
opusConfig->coupledStreams,
|
|
||||||
alsaMapping,
|
|
||||||
&rc);
|
|
||||||
|
|
||||||
snd_pcm_hw_params_t *hw_params;
|
snd_pcm_hw_params_t *hw_params;
|
||||||
snd_pcm_sw_params_t *sw_params;
|
snd_pcm_sw_params_t *sw_params;
|
||||||
snd_pcm_uframes_t period_size = FRAME_SIZE * opusConfig->channelCount * 2;
|
snd_pcm_uframes_t period_size = FRAME_SIZE * FRAME_BUFFER;
|
||||||
snd_pcm_uframes_t buffer_size = 12 * period_size;
|
snd_pcm_uframes_t buffer_size = 2 * period_size;
|
||||||
unsigned int sampleRate = opusConfig->sampleRate;
|
unsigned int sampleRate = opusConfig->sampleRate;
|
||||||
|
|
||||||
if (audio_device == NULL)
|
if (audio_device == NULL)
|
||||||
@@ -75,16 +67,16 @@ static void alsa_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGU
|
|||||||
CHECK_RETURN(snd_pcm_hw_params_set_format(handle, hw_params, SND_PCM_FORMAT_S16_LE));
|
CHECK_RETURN(snd_pcm_hw_params_set_format(handle, hw_params, SND_PCM_FORMAT_S16_LE));
|
||||||
CHECK_RETURN(snd_pcm_hw_params_set_rate_near(handle, hw_params, &sampleRate, NULL));
|
CHECK_RETURN(snd_pcm_hw_params_set_rate_near(handle, hw_params, &sampleRate, NULL));
|
||||||
CHECK_RETURN(snd_pcm_hw_params_set_channels(handle, hw_params, opusConfig->channelCount));
|
CHECK_RETURN(snd_pcm_hw_params_set_channels(handle, hw_params, opusConfig->channelCount));
|
||||||
CHECK_RETURN(snd_pcm_hw_params_set_buffer_size_near(handle, hw_params, &buffer_size));
|
|
||||||
CHECK_RETURN(snd_pcm_hw_params_set_period_size_near(handle, hw_params, &period_size, NULL));
|
CHECK_RETURN(snd_pcm_hw_params_set_period_size_near(handle, hw_params, &period_size, NULL));
|
||||||
|
CHECK_RETURN(snd_pcm_hw_params_set_buffer_size_near(handle, hw_params, &buffer_size));
|
||||||
CHECK_RETURN(snd_pcm_hw_params(handle, hw_params));
|
CHECK_RETURN(snd_pcm_hw_params(handle, hw_params));
|
||||||
snd_pcm_hw_params_free(hw_params);
|
snd_pcm_hw_params_free(hw_params);
|
||||||
|
|
||||||
/* Set software parameters */
|
/* Set software parameters */
|
||||||
CHECK_RETURN(snd_pcm_sw_params_malloc(&sw_params));
|
CHECK_RETURN(snd_pcm_sw_params_malloc(&sw_params));
|
||||||
CHECK_RETURN(snd_pcm_sw_params_current(handle, sw_params));
|
CHECK_RETURN(snd_pcm_sw_params_current(handle, sw_params));
|
||||||
CHECK_RETURN(snd_pcm_sw_params_set_start_threshold(handle, sw_params, buffer_size - period_size));
|
|
||||||
CHECK_RETURN(snd_pcm_sw_params_set_avail_min(handle, sw_params, period_size));
|
CHECK_RETURN(snd_pcm_sw_params_set_avail_min(handle, sw_params, period_size));
|
||||||
|
CHECK_RETURN(snd_pcm_sw_params_set_start_threshold(handle, sw_params, 1));
|
||||||
CHECK_RETURN(snd_pcm_sw_params(handle, sw_params));
|
CHECK_RETURN(snd_pcm_sw_params(handle, sw_params));
|
||||||
snd_pcm_sw_params_free(sw_params);
|
snd_pcm_sw_params_free(sw_params);
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Moonlight Embedded.
|
* This file is part of Moonlight Embedded.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2015, 2016 Iwan Timmer
|
* Copyright (C) 2015-2017 Iwan Timmer
|
||||||
*
|
*
|
||||||
* Moonlight is free software; you can redistribute it and/or modify
|
* Moonlight is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -25,9 +25,6 @@
|
|||||||
#include "bcm_host.h"
|
#include "bcm_host.h"
|
||||||
#include "ilclient.h"
|
#include "ilclient.h"
|
||||||
|
|
||||||
#define MAX_CHANNEL_COUNT 6
|
|
||||||
#define FRAME_SIZE 240
|
|
||||||
|
|
||||||
static OpusMSDecoder* decoder;
|
static OpusMSDecoder* decoder;
|
||||||
ILCLIENT_T* handle;
|
ILCLIENT_T* handle;
|
||||||
COMPONENT_T* component;
|
COMPONENT_T* component;
|
||||||
@@ -38,7 +35,7 @@ static int channelCount;
|
|||||||
static void omx_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig) {
|
static void omx_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig) {
|
||||||
int rc, error;
|
int rc, error;
|
||||||
OMX_ERRORTYPE err;
|
OMX_ERRORTYPE err;
|
||||||
unsigned char omxMapping[6];
|
unsigned char omxMapping[MAX_CHANNEL_COUNT];
|
||||||
char* componentName = "audio_render";
|
char* componentName = "audio_render";
|
||||||
|
|
||||||
channelCount = opusConfig->channelCount;
|
channelCount = opusConfig->channelCount;
|
||||||
@@ -52,17 +49,12 @@ static void omx_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGUR
|
|||||||
omxMapping[3] = opusConfig->mapping[2];
|
omxMapping[3] = opusConfig->mapping[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
decoder = opus_multistream_decoder_create(opusConfig->sampleRate,
|
decoder = opus_multistream_decoder_create(opusConfig->sampleRate, opusConfig->channelCount, opusConfig->streams, opusConfig->coupledStreams, omxMapping, &rc);
|
||||||
opusConfig->channelCount,
|
|
||||||
opusConfig->streams,
|
|
||||||
opusConfig->coupledStreams,
|
|
||||||
omxMapping,
|
|
||||||
&rc);
|
|
||||||
|
|
||||||
handle = ilclient_init();
|
handle = ilclient_init();
|
||||||
if (handle == NULL) {
|
if (handle == NULL) {
|
||||||
fprintf(stderr, "IL client init failed\n");
|
fprintf(stderr, "IL client init failed\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ilclient_create_component(handle, &component, componentName, ILCLIENT_DISABLE_ALL_PORTS | ILCLIENT_ENABLE_INPUT_BUFFERS) != 0) {
|
if (ilclient_create_component(handle, &component, componentName, ILCLIENT_DISABLE_ALL_PORTS | ILCLIENT_ENABLE_INPUT_BUFFERS) != 0) {
|
||||||
@@ -104,30 +96,30 @@ static void omx_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGUR
|
|||||||
|
|
||||||
switch(channelCount) {
|
switch(channelCount) {
|
||||||
case 1:
|
case 1:
|
||||||
sPCMMode.eChannelMapping[0] = OMX_AUDIO_ChannelCF;
|
sPCMMode.eChannelMapping[0] = OMX_AUDIO_ChannelCF;
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
sPCMMode.eChannelMapping[7] = OMX_AUDIO_ChannelRS;
|
sPCMMode.eChannelMapping[7] = OMX_AUDIO_ChannelRS;
|
||||||
case 7:
|
case 7:
|
||||||
sPCMMode.eChannelMapping[6] = OMX_AUDIO_ChannelLS;
|
sPCMMode.eChannelMapping[6] = OMX_AUDIO_ChannelLS;
|
||||||
case 6:
|
case 6:
|
||||||
sPCMMode.eChannelMapping[5] = OMX_AUDIO_ChannelRR;
|
sPCMMode.eChannelMapping[5] = OMX_AUDIO_ChannelRR;
|
||||||
case 5:
|
case 5:
|
||||||
sPCMMode.eChannelMapping[4] = OMX_AUDIO_ChannelLR;
|
sPCMMode.eChannelMapping[4] = OMX_AUDIO_ChannelLR;
|
||||||
case 4:
|
case 4:
|
||||||
sPCMMode.eChannelMapping[3] = OMX_AUDIO_ChannelLFE;
|
sPCMMode.eChannelMapping[3] = OMX_AUDIO_ChannelLFE;
|
||||||
case 3:
|
case 3:
|
||||||
sPCMMode.eChannelMapping[2] = OMX_AUDIO_ChannelCF;
|
sPCMMode.eChannelMapping[2] = OMX_AUDIO_ChannelCF;
|
||||||
case 2:
|
case 2:
|
||||||
sPCMMode.eChannelMapping[1] = OMX_AUDIO_ChannelRF;
|
sPCMMode.eChannelMapping[1] = OMX_AUDIO_ChannelRF;
|
||||||
sPCMMode.eChannelMapping[0] = OMX_AUDIO_ChannelLF;
|
sPCMMode.eChannelMapping[0] = OMX_AUDIO_ChannelLF;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = OMX_SetParameter(ilclient_get_handle(component), OMX_IndexParamAudioPcm, &sPCMMode);
|
err = OMX_SetParameter(ilclient_get_handle(component), OMX_IndexParamAudioPcm, &sPCMMode);
|
||||||
if(err != OMX_ErrorNone){
|
if(err != OMX_ErrorNone){
|
||||||
fprintf(stderr, "PCM mode unsupported\n");
|
fprintf(stderr, "PCM mode unsupported\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
OMX_CONFIG_BRCMAUDIODESTINATIONTYPE arDest;
|
OMX_CONFIG_BRCMAUDIODESTINATIONTYPE arDest;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Moonlight Embedded.
|
* This file is part of Moonlight Embedded.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2015 Iwan Timmer
|
* Copyright (C) 2015-2017 Iwan Timmer
|
||||||
*
|
*
|
||||||
* Moonlight is free software; you can redistribute it and/or modify
|
* Moonlight is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -26,9 +26,6 @@
|
|||||||
#include <pulse/simple.h>
|
#include <pulse/simple.h>
|
||||||
#include <pulse/error.h>
|
#include <pulse/error.h>
|
||||||
|
|
||||||
#define MAX_CHANNEL_COUNT 6
|
|
||||||
#define FRAME_SIZE 240
|
|
||||||
|
|
||||||
static OpusMSDecoder* decoder;
|
static OpusMSDecoder* decoder;
|
||||||
static pa_simple *dev = NULL;
|
static pa_simple *dev = NULL;
|
||||||
static short pcmBuffer[FRAME_SIZE * MAX_CHANNEL_COUNT];
|
static short pcmBuffer[FRAME_SIZE * MAX_CHANNEL_COUNT];
|
||||||
@@ -52,7 +49,7 @@ bool audio_pulse_init() {
|
|||||||
|
|
||||||
static void pulse_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig) {
|
static void pulse_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig) {
|
||||||
int rc, error;
|
int rc, error;
|
||||||
unsigned char alsaMapping[6];
|
unsigned char alsaMapping[MAX_CHANNEL_COUNT];
|
||||||
|
|
||||||
channelCount = opusConfig->channelCount;
|
channelCount = opusConfig->channelCount;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Moonlight Embedded.
|
* This file is part of Moonlight Embedded.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2015 Iwan Timmer
|
* Copyright (C) 2015-2017 Iwan Timmer
|
||||||
*
|
*
|
||||||
* Moonlight is free software; you can redistribute it and/or modify
|
* Moonlight is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -25,9 +25,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <opus_multistream.h>
|
#include <opus_multistream.h>
|
||||||
|
|
||||||
#define MAX_CHANNEL_COUNT 6
|
|
||||||
#define FRAME_SIZE 240
|
|
||||||
|
|
||||||
static OpusMSDecoder* decoder;
|
static OpusMSDecoder* decoder;
|
||||||
static short pcmBuffer[FRAME_SIZE * MAX_CHANNEL_COUNT];
|
static short pcmBuffer[FRAME_SIZE * MAX_CHANNEL_COUNT];
|
||||||
static SDL_AudioDeviceID dev;
|
static SDL_AudioDeviceID dev;
|
||||||
@@ -35,12 +32,7 @@ static int channelCount;
|
|||||||
|
|
||||||
static void sdl_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig) {
|
static void sdl_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig) {
|
||||||
int rc;
|
int rc;
|
||||||
decoder = opus_multistream_decoder_create(opusConfig->sampleRate,
|
decoder = opus_multistream_decoder_create(opusConfig->sampleRate, opusConfig->channelCount, opusConfig->streams, opusConfig->coupledStreams, opusConfig->mapping, &rc);
|
||||||
opusConfig->channelCount,
|
|
||||||
opusConfig->streams,
|
|
||||||
opusConfig->coupledStreams,
|
|
||||||
opusConfig->mapping,
|
|
||||||
&rc);
|
|
||||||
|
|
||||||
channelCount = opusConfig->channelCount;
|
channelCount = opusConfig->channelCount;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user