Cleanup audio decoding code

This commit is contained in:
Iwan Timmer
2017-05-25 16:48:58 +02:00
parent 441bf6c7e0
commit fca16aa801
5 changed files with 34 additions and 57 deletions

View File

@@ -1,7 +1,7 @@
/*
* 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
* it under the terms of the GNU General Public License as published by
@@ -21,6 +21,10 @@
#include <Limelight.h>
#define MAX_CHANNEL_COUNT 6
#define FRAME_SIZE 240
#define FRAME_BUFFER 12
extern const char* audio_device;
extern AUDIO_RENDERER_CALLBACKS audio_callbacks_alsa;

View File

@@ -1,7 +1,7 @@
/*
* 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
* 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 MAX_CHANNEL_COUNT 6
#define FRAME_SIZE 240
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) {
int rc;
unsigned char alsaMapping[6];
unsigned char alsaMapping[MAX_CHANNEL_COUNT];
/* The supplied mapping array has order: FL-FR-C-LFE-RL-RR
* 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];
}
decoder = opus_multistream_decoder_create(opusConfig->sampleRate,
opusConfig->channelCount,
opusConfig->streams,
opusConfig->coupledStreams,
alsaMapping,
&rc);
decoder = opus_multistream_decoder_create(opusConfig->sampleRate, opusConfig->channelCount, opusConfig->streams, opusConfig->coupledStreams, alsaMapping, &rc);
snd_pcm_hw_params_t *hw_params;
snd_pcm_sw_params_t *sw_params;
snd_pcm_uframes_t period_size = FRAME_SIZE * opusConfig->channelCount * 2;
snd_pcm_uframes_t buffer_size = 12 * period_size;
snd_pcm_uframes_t period_size = FRAME_SIZE * FRAME_BUFFER;
snd_pcm_uframes_t buffer_size = 2 * period_size;
unsigned int sampleRate = opusConfig->sampleRate;
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_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_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_buffer_size_near(handle, hw_params, &buffer_size));
CHECK_RETURN(snd_pcm_hw_params(handle, hw_params));
snd_pcm_hw_params_free(hw_params);
/* Set software parameters */
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_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_start_threshold(handle, sw_params, 1));
CHECK_RETURN(snd_pcm_sw_params(handle, sw_params));
snd_pcm_sw_params_free(sw_params);

View File

@@ -1,7 +1,7 @@
/*
* 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
* it under the terms of the GNU General Public License as published by
@@ -25,9 +25,6 @@
#include "bcm_host.h"
#include "ilclient.h"
#define MAX_CHANNEL_COUNT 6
#define FRAME_SIZE 240
static OpusMSDecoder* decoder;
ILCLIENT_T* handle;
COMPONENT_T* component;
@@ -38,7 +35,7 @@ static int channelCount;
static void omx_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig) {
int rc, error;
OMX_ERRORTYPE err;
unsigned char omxMapping[6];
unsigned char omxMapping[MAX_CHANNEL_COUNT];
char* componentName = "audio_render";
channelCount = opusConfig->channelCount;
@@ -52,17 +49,12 @@ static void omx_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGUR
omxMapping[3] = opusConfig->mapping[2];
}
decoder = opus_multistream_decoder_create(opusConfig->sampleRate,
opusConfig->channelCount,
opusConfig->streams,
opusConfig->coupledStreams,
omxMapping,
&rc);
decoder = opus_multistream_decoder_create(opusConfig->sampleRate, opusConfig->channelCount, opusConfig->streams, opusConfig->coupledStreams, omxMapping, &rc);
handle = ilclient_init();
if (handle == NULL) {
fprintf(stderr, "IL client init failed\n");
exit(1);
fprintf(stderr, "IL client init failed\n");
exit(1);
}
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) {
case 1:
sPCMMode.eChannelMapping[0] = OMX_AUDIO_ChannelCF;
break;
sPCMMode.eChannelMapping[0] = OMX_AUDIO_ChannelCF;
break;
case 8:
sPCMMode.eChannelMapping[7] = OMX_AUDIO_ChannelRS;
sPCMMode.eChannelMapping[7] = OMX_AUDIO_ChannelRS;
case 7:
sPCMMode.eChannelMapping[6] = OMX_AUDIO_ChannelLS;
sPCMMode.eChannelMapping[6] = OMX_AUDIO_ChannelLS;
case 6:
sPCMMode.eChannelMapping[5] = OMX_AUDIO_ChannelRR;
sPCMMode.eChannelMapping[5] = OMX_AUDIO_ChannelRR;
case 5:
sPCMMode.eChannelMapping[4] = OMX_AUDIO_ChannelLR;
sPCMMode.eChannelMapping[4] = OMX_AUDIO_ChannelLR;
case 4:
sPCMMode.eChannelMapping[3] = OMX_AUDIO_ChannelLFE;
sPCMMode.eChannelMapping[3] = OMX_AUDIO_ChannelLFE;
case 3:
sPCMMode.eChannelMapping[2] = OMX_AUDIO_ChannelCF;
sPCMMode.eChannelMapping[2] = OMX_AUDIO_ChannelCF;
case 2:
sPCMMode.eChannelMapping[1] = OMX_AUDIO_ChannelRF;
sPCMMode.eChannelMapping[0] = OMX_AUDIO_ChannelLF;
break;
sPCMMode.eChannelMapping[1] = OMX_AUDIO_ChannelRF;
sPCMMode.eChannelMapping[0] = OMX_AUDIO_ChannelLF;
break;
}
err = OMX_SetParameter(ilclient_get_handle(component), OMX_IndexParamAudioPcm, &sPCMMode);
if(err != OMX_ErrorNone){
fprintf(stderr, "PCM mode unsupported\n");
return;
fprintf(stderr, "PCM mode unsupported\n");
return;
}
OMX_CONFIG_BRCMAUDIODESTINATIONTYPE arDest;

View File

@@ -1,7 +1,7 @@
/*
* 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
* it under the terms of the GNU General Public License as published by
@@ -26,9 +26,6 @@
#include <pulse/simple.h>
#include <pulse/error.h>
#define MAX_CHANNEL_COUNT 6
#define FRAME_SIZE 240
static OpusMSDecoder* decoder;
static pa_simple *dev = NULL;
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) {
int rc, error;
unsigned char alsaMapping[6];
unsigned char alsaMapping[MAX_CHANNEL_COUNT];
channelCount = opusConfig->channelCount;

View File

@@ -1,7 +1,7 @@
/*
* 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
* it under the terms of the GNU General Public License as published by
@@ -25,9 +25,6 @@
#include <stdio.h>
#include <opus_multistream.h>
#define MAX_CHANNEL_COUNT 6
#define FRAME_SIZE 240
static OpusMSDecoder* decoder;
static short pcmBuffer[FRAME_SIZE * MAX_CHANNEL_COUNT];
static SDL_AudioDeviceID dev;
@@ -35,12 +32,7 @@ static int channelCount;
static void 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);
decoder = opus_multistream_decoder_create(opusConfig->sampleRate, opusConfig->channelCount, opusConfig->streams, opusConfig->coupledStreams, opusConfig->mapping, &rc);
channelCount = opusConfig->channelCount;