am 21ae1ad6: RTP: Minor fixes with polishing.

Merge commit '21ae1ad6a695d6f1f253797fcf2a77b975b82cd3' into gingerbread-plus-aosp

* commit '21ae1ad6a695d6f1f253797fcf2a77b975b82cd3':
  RTP: Minor fixes with polishing.
This commit is contained in:
Chia-chi Yeh
2010-09-30 10:11:07 -07:00
committed by Android Git Automerger
3 changed files with 20 additions and 19 deletions

View File

@@ -89,7 +89,6 @@ public:
void encode(int tick, AudioStream *chain); void encode(int tick, AudioStream *chain);
void decode(int tick); void decode(int tick);
private:
enum { enum {
NORMAL = 0, NORMAL = 0,
SEND_ONLY = 1, SEND_ONLY = 1,
@@ -97,6 +96,7 @@ private:
LAST_MODE = 2, LAST_MODE = 2,
}; };
private:
int mMode; int mMode;
int mSocket; int mSocket;
sockaddr_storage mRemote; sockaddr_storage mRemote;
@@ -202,8 +202,8 @@ bool AudioStream::set(int mode, int socket, sockaddr_storage *remote,
} }
} }
LOGD("stream[%d] is configured as %s %dkHz %dms", mSocket, LOGD("stream[%d] is configured as %s %dkHz %dms mode %d", mSocket,
(codec ? codec->name : "RAW"), mSampleRate, mInterval); (codec ? codec->name : "RAW"), mSampleRate, mInterval, mMode);
return true; return true;
} }
@@ -253,7 +253,7 @@ void AudioStream::encode(int tick, AudioStream *chain)
mTick += skipped * mInterval; mTick += skipped * mInterval;
mSequence += skipped; mSequence += skipped;
mTimestamp += skipped * mSampleCount; mTimestamp += skipped * mSampleCount;
LOGD("stream[%d] skips %d packets", mSocket, skipped); LOGV("stream[%d] skips %d packets", mSocket, skipped);
} }
tick = mTick; tick = mTick;
@@ -302,7 +302,7 @@ void AudioStream::encode(int tick, AudioStream *chain)
if (!mixed) { if (!mixed) {
if ((mTick ^ mLogThrottle) >> 10) { if ((mTick ^ mLogThrottle) >> 10) {
mLogThrottle = mTick; mLogThrottle = mTick;
LOGD("stream[%d] no data", mSocket); LOGV("stream[%d] no data", mSocket);
} }
return; return;
} }
@@ -330,7 +330,7 @@ void AudioStream::encode(int tick, AudioStream *chain)
buffer[2] = mSsrc; buffer[2] = mSsrc;
int length = mCodec->encode(&buffer[3], samples); int length = mCodec->encode(&buffer[3], samples);
if (length <= 0) { if (length <= 0) {
LOGD("stream[%d] encoder error", mSocket); LOGV("stream[%d] encoder error", mSocket);
return; return;
} }
sendto(mSocket, buffer, length + 12, MSG_DONTWAIT, (sockaddr *)&mRemote, sendto(mSocket, buffer, length + 12, MSG_DONTWAIT, (sockaddr *)&mRemote,
@@ -369,14 +369,14 @@ void AudioStream::decode(int tick)
mLatencyTimer = tick; mLatencyTimer = tick;
mLatencyScore = score; mLatencyScore = score;
} else if (tick - mLatencyTimer >= MEASURE_PERIOD) { } else if (tick - mLatencyTimer >= MEASURE_PERIOD) {
LOGD("stream[%d] reduces latency of %dms", mSocket, mLatencyScore); LOGV("stream[%d] reduces latency of %dms", mSocket, mLatencyScore);
mBufferTail -= mLatencyScore; mBufferTail -= mLatencyScore;
mLatencyTimer = tick; mLatencyTimer = tick;
} }
if (mBufferTail - mBufferHead > BUFFER_SIZE - mInterval) { if (mBufferTail - mBufferHead > BUFFER_SIZE - mInterval) {
// Buffer overflow. Drop the packet. // Buffer overflow. Drop the packet.
LOGD("stream[%d] buffer overflow", mSocket); LOGV("stream[%d] buffer overflow", mSocket);
recv(mSocket, &c, 1, MSG_DONTWAIT); recv(mSocket, &c, 1, MSG_DONTWAIT);
return; return;
} }
@@ -400,7 +400,7 @@ void AudioStream::decode(int tick)
// reliable but at least they can be used to identify duplicates? // reliable but at least they can be used to identify duplicates?
if (length < 12 || length > (int)sizeof(buffer) || if (length < 12 || length > (int)sizeof(buffer) ||
(ntohl(*(uint32_t *)buffer) & 0xC07F0000) != mCodecMagic) { (ntohl(*(uint32_t *)buffer) & 0xC07F0000) != mCodecMagic) {
LOGD("stream[%d] malformed packet", mSocket); LOGV("stream[%d] malformed packet", mSocket);
return; return;
} }
int offset = 12 + ((buffer[0] & 0x0F) << 2); int offset = 12 + ((buffer[0] & 0x0F) << 2);
@@ -420,13 +420,13 @@ void AudioStream::decode(int tick)
} }
} }
if (length <= 0) { if (length <= 0) {
LOGD("stream[%d] decoder error", mSocket); LOGV("stream[%d] decoder error", mSocket);
return; return;
} }
if (tick - mBufferTail > 0) { if (tick - mBufferTail > 0) {
// Buffer underrun. Reset the jitter buffer. // Buffer underrun. Reset the jitter buffer.
LOGD("stream[%d] buffer underrun", mSocket); LOGV("stream[%d] buffer underrun", mSocket);
if (mBufferTail - mBufferHead <= 0) { if (mBufferTail - mBufferHead <= 0) {
mBufferHead = tick + mInterval; mBufferHead = tick + mInterval;
mBufferTail = mBufferHead; mBufferTail = mBufferHead;
@@ -462,7 +462,6 @@ public:
bool add(AudioStream *stream); bool add(AudioStream *stream);
bool remove(int socket); bool remove(int socket);
private:
enum { enum {
ON_HOLD = 0, ON_HOLD = 0,
MUTED = 1, MUTED = 1,
@@ -471,6 +470,7 @@ private:
LAST_MODE = 3, LAST_MODE = 3,
}; };
private:
AudioStream *mChain; AudioStream *mChain;
int mEventQueue; int mEventQueue;
volatile int mDtmfEvent; volatile int mDtmfEvent;
@@ -946,6 +946,10 @@ void remove(JNIEnv *env, jobject thiz, jint socket)
void setMode(JNIEnv *env, jobject thiz, jint mode) void setMode(JNIEnv *env, jobject thiz, jint mode)
{ {
if (mode < 0 || mode > AudioGroup::LAST_MODE) {
jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
return;
}
AudioGroup *group = (AudioGroup *)env->GetIntField(thiz, gNative); AudioGroup *group = (AudioGroup *)env->GetIntField(thiz, gNative);
if (group && !group->setMode(mode)) { if (group && !group->setMode(mode)) {
jniThrowException(env, "java/lang/IllegalArgumentException", NULL); jniThrowException(env, "java/lang/IllegalArgumentException", NULL);

View File

@@ -18,7 +18,7 @@
namespace { namespace {
int8_t gExponents[128] = { const int8_t gExponents[128] = {
0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,

View File

@@ -88,13 +88,11 @@ jint create(JNIEnv *env, jobject thiz, jstring jAddress)
jint dup(JNIEnv *env, jobject thiz) jint dup(JNIEnv *env, jobject thiz)
{ {
int socket1 = env->GetIntField(thiz, gNative); int socket = ::dup(env->GetIntField(thiz, gNative));
int socket2 = ::dup(socket1); if (socket == -1) {
if (socket2 == -1) {
jniThrowException(env, "java/lang/IllegalStateException", strerror(errno)); jniThrowException(env, "java/lang/IllegalStateException", strerror(errno));
} }
LOGD("dup %d to %d", socket1, socket2); return socket;
return socket2;
} }
void close(JNIEnv *env, jobject thiz) void close(JNIEnv *env, jobject thiz)
@@ -102,7 +100,6 @@ void close(JNIEnv *env, jobject thiz)
int socket = env->GetIntField(thiz, gNative); int socket = env->GetIntField(thiz, gNative);
::close(socket); ::close(socket);
env->SetIntField(thiz, gNative, -1); env->SetIntField(thiz, gNative, -1);
LOGD("close %d", socket);
} }
JNINativeMethod gMethods[] = { JNINativeMethod gMethods[] = {