Skip to content

Commit

Permalink
[aml] move aml_cpufreq_limit out of AESinkAUDIOTRACK.cpp and into AML…
Browse files Browse the repository at this point in the history
…Utils where it belongs
  • Loading branch information
davilla committed Sep 29, 2012
1 parent a9e5d90 commit a2b0ee3
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 52 deletions.
55 changes: 3 additions & 52 deletions xbmc/cores/AudioEngine/Sinks/AESinkAUDIOTRACK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include "Utils/AERingBuffer.h"
#include "android/activity/XBMCApp.h"
#include "utils/log.h"
#if defined(HAS_AMLPLAYER)
#include "cores/amlplayer/AMLUtils.h"
#endif

#include <jni.h>

Expand Down Expand Up @@ -52,58 +55,6 @@ static void pa_sconv_s16le_from_f32ne_neon(unsigned n, const float32_t *a, int16
}
#endif

#if defined(HAS_AMLPLAYER)
// yes this is nasty here but there is really no place else to do it.
static void aml_cpufreq_limit(bool limit)
{
static int audiotrack_cputype = -1;

if (audiotrack_cputype == -1)
{
// defualt to m1 SoC
audiotrack_cputype = 1;

FILE *cpuinfo_fd = fopen("/proc/cpuinfo", "r");
if (cpuinfo_fd)
{
char buffer[512];
while (fgets(buffer, sizeof(buffer), cpuinfo_fd))
{
std::string stdbuffer(buffer);
if (stdbuffer.find("MESON-M3") != std::string::npos)
{
audiotrack_cputype = 3;
CLog::Log(LOGDEBUG, "CAMLPlayer::GetCpuType is AMLOGIC MESON-M3");
break;
}
}
fclose(cpuinfo_fd);
}
}
// On M1 SoCs, when playing hw decoded audio, we cannot drop below 600MHz
// or risk hw audio dropouts. AML code does a 2X scaling based off
// /sys/class/audiodsp/codec_mips but tests show that this is
// seems risky so we just clamp to 600Mhz to be safe.
if (audiotrack_cputype == 3)
return;

int cpufreq;
if (limit)
cpufreq = 600000;
else
cpufreq = 300000;

int fd = open("/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq", O_CREAT | O_RDWR | O_TRUNC, 0644);
if (fd >= 0)
{
char bcmd[16];
sprintf(bcmd, "%d", cpufreq);
write(fd, bcmd, strlen(bcmd));
close(fd);
}
}
#endif

static jint GetStaticIntField(JNIEnv *jenv, std::string class_name, std::string field_name)
{
class_name.insert(0, "android/media/");
Expand Down
48 changes: 48 additions & 0 deletions xbmc/cores/amlplayer/AMLUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string>

int aml_set_sysfs_str(const char *path, const char *val)
{
Expand Down Expand Up @@ -79,6 +80,53 @@ int aml_get_sysfs_int(const char *path)
return val;
}

void aml_cpufreq_limit(bool limit)
{
static int audiotrack_cputype = -1;
if (audiotrack_cputype == -1)
{
// defualt to m1 SoC
audiotrack_cputype = 1;

FILE *cpuinfo_fd = fopen("/proc/cpuinfo", "r");
if (cpuinfo_fd)
{
char buffer[512];
while (fgets(buffer, sizeof(buffer), cpuinfo_fd))
{
std::string stdbuffer(buffer);
if (stdbuffer.find("MESON-M3") != std::string::npos)
{
audiotrack_cputype = 3;
break;
}
}
fclose(cpuinfo_fd);
}
}
// On M1 SoCs, when playing hw decoded audio, we cannot drop below 600MHz
// or risk hw audio dropouts. AML code does a 2X scaling based off
// /sys/class/audiodsp/codec_mips but tests show that this is
// seems risky so we just clamp to 600Mhz to be safe.
if (audiotrack_cputype == 3)
return;

int cpufreq;
if (limit)
cpufreq = 600000;
else
cpufreq = 300000;

int fd = open("/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq", O_CREAT | O_RDWR | O_TRUNC, 0644);
if (fd >= 0)
{
char bcmd[16];
sprintf(bcmd, "%d", cpufreq);
write(fd, bcmd, strlen(bcmd));
close(fd);
}
}

int aml_set_audio_passthrough(bool passthrough)
{
static int has_aml = -1;
Expand Down
1 change: 1 addition & 0 deletions xbmc/cores/amlplayer/AMLUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ int aml_get_sysfs_str(const char *path, char *valstr, const int size);
int aml_set_sysfs_int(const char *path, const int val);
int aml_get_sysfs_int(const char *path);

void aml_cpufreq_limit(bool limit);
void aml_set_audio_passthrough(bool passthrough);

0 comments on commit a2b0ee3

Please sign in to comment.