forked from len0rd/rockbox
Adhere to the 80-char line width limit.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28067 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
c98f5845f6
commit
51c91c599b
3 changed files with 54 additions and 31 deletions
|
@ -39,11 +39,13 @@ public class RockboxPCM extends AudioTrack
|
||||||
private Handler h = null;
|
private Handler h = null;
|
||||||
private static final int samplerate = 44100;
|
private static final int samplerate = 44100;
|
||||||
/* should be CHANNEL_OUT_STEREO in 2.0 and above */
|
/* should be CHANNEL_OUT_STEREO in 2.0 and above */
|
||||||
private static final int channels = AudioFormat.CHANNEL_CONFIGURATION_STEREO;
|
private static final int channels =
|
||||||
private static final int encoding = AudioFormat.ENCODING_PCM_16BIT;
|
AudioFormat.CHANNEL_CONFIGURATION_STEREO;
|
||||||
|
private static final int encoding =
|
||||||
|
AudioFormat.ENCODING_PCM_16BIT;
|
||||||
/* 24k is plenty, but some devices may have a higher minimum */
|
/* 24k is plenty, but some devices may have a higher minimum */
|
||||||
private static final int buf_len =
|
private static final int buf_len =
|
||||||
Math.max(24<<10, getMinBufferSize(samplerate, channels, encoding));
|
Math.max(24<<10, getMinBufferSize(samplerate, channels, encoding));
|
||||||
|
|
||||||
private void LOG(CharSequence text)
|
private void LOG(CharSequence text)
|
||||||
{
|
{
|
||||||
|
@ -54,7 +56,8 @@ public class RockboxPCM extends AudioTrack
|
||||||
{
|
{
|
||||||
super(AudioManager.STREAM_MUSIC, samplerate, channels, encoding,
|
super(AudioManager.STREAM_MUSIC, samplerate, channels, encoding,
|
||||||
buf_len, AudioTrack.MODE_STREAM);
|
buf_len, AudioTrack.MODE_STREAM);
|
||||||
ht = new HandlerThread("audio thread", Process.THREAD_PRIORITY_URGENT_AUDIO);
|
ht = new HandlerThread("audio thread",
|
||||||
|
Process.THREAD_PRIORITY_URGENT_AUDIO);
|
||||||
ht.start();
|
ht.start();
|
||||||
raw_data = new byte[buf_len]; /* in shorts */
|
raw_data = new byte[buf_len]; /* in shorts */
|
||||||
Arrays.fill(raw_data, (byte) 0);
|
Arrays.fill(raw_data, (byte) 0);
|
||||||
|
@ -88,13 +91,15 @@ public class RockboxPCM extends AudioTrack
|
||||||
{
|
{
|
||||||
if (h == null)
|
if (h == null)
|
||||||
h = new Handler(ht.getLooper());
|
h = new Handler(ht.getLooper());
|
||||||
if (setNotificationMarkerPosition(bytes2frames(buf_len)/4) != AudioTrack.SUCCESS)
|
if (setNotificationMarkerPosition(bytes2frames(buf_len)/4)
|
||||||
|
!= AudioTrack.SUCCESS)
|
||||||
LOG("setNotificationMarkerPosition Error");
|
LOG("setNotificationMarkerPosition Error");
|
||||||
else
|
else
|
||||||
setPlaybackPositionUpdateListener(l, h);
|
setPlaybackPositionUpdateListener(l, h);
|
||||||
}
|
}
|
||||||
/* need to fill with silence before starting playback */
|
/* need to fill with silence before starting playback */
|
||||||
write(raw_data, frames2bytes(getPlaybackHeadPosition()), raw_data.length);
|
write(raw_data, frames2bytes(getPlaybackHeadPosition()),
|
||||||
|
raw_data.length);
|
||||||
}
|
}
|
||||||
play();
|
play();
|
||||||
}
|
}
|
||||||
|
@ -115,9 +120,11 @@ public class RockboxPCM extends AudioTrack
|
||||||
private void set_volume(int volume)
|
private void set_volume(int volume)
|
||||||
{
|
{
|
||||||
/* volume comes from 0..-990 from Rockbox */
|
/* volume comes from 0..-990 from Rockbox */
|
||||||
/* TODO volume is in dB, but this code acts as if it were in %, convert? */
|
/* TODO:
|
||||||
|
* volume is in dB, but this code acts as if it were in %, convert? */
|
||||||
float fvolume;
|
float fvolume;
|
||||||
/* special case min and max volume to not suffer from floating point accuracy */
|
/* special case min and max volume to not suffer from
|
||||||
|
* floating point accuracy */
|
||||||
if (volume == 0)
|
if (volume == 0)
|
||||||
fvolume = 1.0f;
|
fvolume = 1.0f;
|
||||||
else if (volume == -990)
|
else if (volume == -990)
|
||||||
|
@ -155,10 +162,15 @@ public class RockboxPCM extends AudioTrack
|
||||||
{
|
{
|
||||||
case AudioTrack.PLAYSTATE_PLAYING:
|
case AudioTrack.PLAYSTATE_PLAYING:
|
||||||
case AudioTrack.PLAYSTATE_PAUSED:
|
case AudioTrack.PLAYSTATE_PAUSED:
|
||||||
/* refill at 25% no matter of how many bytes we've written */
|
/* refill at 25% no matter of how many
|
||||||
if (setNotificationMarkerPosition(bytes2frames(refill_mark))
|
* bytes we've written */
|
||||||
!= AudioTrack.SUCCESS)
|
if (setNotificationMarkerPosition(
|
||||||
LOG("Error in onMarkerReached: Could not set notification marker");
|
bytes2frames(refill_mark))
|
||||||
|
!= AudioTrack.SUCCESS)
|
||||||
|
{
|
||||||
|
LOG("Error in onMarkerReached: " +
|
||||||
|
"Could not set notification marker");
|
||||||
|
}
|
||||||
else /* recharge */
|
else /* recharge */
|
||||||
setPlaybackPositionUpdateListener(this, h);
|
setPlaybackPositionUpdateListener(this, h);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -52,10 +52,10 @@ public class RockboxService extends Service
|
||||||
public static RockboxFramebuffer fb = null;
|
public static RockboxFramebuffer fb = null;
|
||||||
private static RockboxService instance;
|
private static RockboxService instance;
|
||||||
private Notification notification;
|
private Notification notification;
|
||||||
private static final Class<?>[] mStartForegroundSignature = new Class[] {
|
private static final Class<?>[] mStartForegroundSignature =
|
||||||
int.class, Notification.class};
|
new Class[] { int.class, Notification.class };
|
||||||
private static final Class<?>[] mStopForegroundSignature = new Class[] {
|
private static final Class<?>[] mStopForegroundSignature =
|
||||||
boolean.class};
|
new Class[] { boolean.class };
|
||||||
|
|
||||||
private NotificationManager mNM;
|
private NotificationManager mNM;
|
||||||
private Method mStartForeground;
|
private Method mStartForeground;
|
||||||
|
@ -89,7 +89,8 @@ public class RockboxService extends Service
|
||||||
private void do_start(Intent intent)
|
private void do_start(Intent intent)
|
||||||
{
|
{
|
||||||
LOG("Start Service");
|
LOG("Start Service");
|
||||||
/* Display a notification about us starting. We put an icon in the status bar. */
|
/* Display a notification about us starting.
|
||||||
|
* We put an icon in the status bar. */
|
||||||
create_notification();
|
create_notification();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,9 +128,11 @@ public class RockboxService extends Service
|
||||||
BufferedOutputStream dest = null;
|
BufferedOutputStream dest = null;
|
||||||
BufferedInputStream is = null;
|
BufferedInputStream is = null;
|
||||||
ZipEntry entry;
|
ZipEntry entry;
|
||||||
File file = new File("/data/data/org.rockbox/lib/libmisc.so");
|
File file = new File("/data/data/org.rockbox/" +
|
||||||
|
"lib/libmisc.so");
|
||||||
/* use arbitary file to determine whether extracting is needed */
|
/* use arbitary file to determine whether extracting is needed */
|
||||||
File file2 = new File("/data/data/org.rockbox/app_rockbox/rockbox/codecs/mpa.codec");
|
File file2 = new File("/data/data/org.rockbox/" +
|
||||||
|
"app_rockbox/rockbox/codecs/mpa.codec");
|
||||||
if (!file2.exists() || (file.lastModified() > file2.lastModified()))
|
if (!file2.exists() || (file.lastModified() > file2.lastModified()))
|
||||||
{
|
{
|
||||||
ZipFile zipfile = new ZipFile(file);
|
ZipFile zipfile = new ZipFile(file);
|
||||||
|
@ -150,7 +153,8 @@ public class RockboxService extends Service
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
is = new BufferedInputStream(zipfile.getInputStream(entry), BUFFER);
|
is = new BufferedInputStream(zipfile.getInputStream(entry),
|
||||||
|
BUFFER);
|
||||||
int count;
|
int count;
|
||||||
byte data[] = new byte[BUFFER];
|
byte data[] = new byte[BUFFER];
|
||||||
folder = new File(new File(entry.getName()).getParent());
|
folder = new File(new File(entry.getName()).getParent());
|
||||||
|
@ -240,18 +244,22 @@ public class RockboxService extends Service
|
||||||
|
|
||||||
private void create_notification()
|
private void create_notification()
|
||||||
{
|
{
|
||||||
/* For now we'll use the same text for the ticker and the expanded notification */
|
/* For now we'll use the same text for the ticker and the
|
||||||
|
* expanded notification */
|
||||||
CharSequence text = getText(R.string.notification);
|
CharSequence text = getText(R.string.notification);
|
||||||
/* Set the icon, scrolling text and timestamp */
|
/* Set the icon, scrolling text and timestamp */
|
||||||
notification = new Notification(R.drawable.icon, text,
|
notification = new Notification(R.drawable.icon, text,
|
||||||
System.currentTimeMillis());
|
System.currentTimeMillis());
|
||||||
|
|
||||||
/* The PendingIntent to launch our activity if the user selects this notification */
|
/* The PendingIntent to launch our activity if the user selects
|
||||||
|
* this notification */
|
||||||
Intent intent = new Intent(this, RockboxActivity.class);
|
Intent intent = new Intent(this, RockboxActivity.class);
|
||||||
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
|
PendingIntent contentIntent =
|
||||||
|
PendingIntent.getActivity(this, 0, intent, 0);
|
||||||
|
|
||||||
/* Set the info for the views that show in the notification panel. */
|
/* Set the info for the views that show in the notification panel. */
|
||||||
notification.setLatestEventInfo(this, getText(R.string.notification), text, contentIntent);
|
notification.setLatestEventInfo(this,
|
||||||
|
getText(R.string.notification), text, contentIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void startForeground()
|
public static void startForeground()
|
||||||
|
@ -260,7 +268,8 @@ public class RockboxService extends Service
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Send the notification.
|
* Send the notification.
|
||||||
* We use a layout id because it is a unique number. We use it later to cancel.
|
* We use a layout id because it is a unique number.
|
||||||
|
* We use it later to cancel.
|
||||||
*/
|
*/
|
||||||
instance.mNM.notify(R.string.notification, instance.notification);
|
instance.mNM.notify(R.string.notification, instance.notification);
|
||||||
/*
|
/*
|
||||||
|
@ -268,7 +277,8 @@ public class RockboxService extends Service
|
||||||
* provides enough cpu time to do music decoding in the
|
* provides enough cpu time to do music decoding in the
|
||||||
* background
|
* background
|
||||||
*/
|
*/
|
||||||
instance.startForegroundCompat(R.string.notification, instance.notification);
|
instance.startForegroundCompat(R.string.notification,
|
||||||
|
instance.notification);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,12 +34,13 @@ public class RockboxTimer extends Timer
|
||||||
long interval;
|
long interval;
|
||||||
|
|
||||||
private class RockboxTimerTask extends TimerTask {
|
private class RockboxTimerTask extends TimerTask {
|
||||||
private RockboxTimer t;
|
private RockboxTimer timer;
|
||||||
private TelephonyManager tm;
|
private TelephonyManager tm;
|
||||||
private int last_state;
|
private int last_state;
|
||||||
public RockboxTimerTask(RockboxService s, RockboxTimer parent) {
|
public RockboxTimerTask(RockboxService s, RockboxTimer parent)
|
||||||
|
{
|
||||||
super();
|
super();
|
||||||
t = parent;
|
timer = parent;
|
||||||
tm = (TelephonyManager)s.getSystemService(Context.TELEPHONY_SERVICE);
|
tm = (TelephonyManager)s.getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
last_state = tm.getCallState();
|
last_state = tm.getCallState();
|
||||||
}
|
}
|
||||||
|
@ -63,8 +64,8 @@ public class RockboxTimer extends Timer
|
||||||
}
|
}
|
||||||
last_state = state;
|
last_state = state;
|
||||||
}
|
}
|
||||||
synchronized(t) {
|
synchronized(timer) {
|
||||||
t.notify();
|
timer.notify();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue