summaryrefslogtreecommitdiffstats
path: root/voip/jni/rtp/AmrCodec.cpp
diff options
context:
space:
mode:
authorChia-chi Yeh <chiachi@android.com>2011-09-06 14:18:37 -0700
committerChia-chi Yeh <chiachi@android.com>2011-09-06 14:34:44 -0700
commit35d05dcba1e829782813b6ec21afceb5cffc22e6 (patch)
tree4f5287ebc5edea42a12ff4f772c5574f57cf2542 /voip/jni/rtp/AmrCodec.cpp
parent1ed7a407fafe50b1eb0878f560bb0618706e4e82 (diff)
downloadframeworks_base-35d05dcba1e829782813b6ec21afceb5cffc22e6.zip
frameworks_base-35d05dcba1e829782813b6ec21afceb5cffc22e6.tar.gz
frameworks_base-35d05dcba1e829782813b6ec21afceb5cffc22e6.tar.bz2
RTP: support payloads with larger packetization interval.
RFC 3551 section 4.2 said that a receiver should accept packets representing between 0 and 200ms of audio data. Now we add the ability to decode multiple frames in a payload as long as the jitter buffer is not full. This change covers G711, GSM, and GSM-EFR. AMR will be added later. Bug: 3029736 Change-Id: Ifd194596766d14f02177925c58432cd620e44dd7
Diffstat (limited to 'voip/jni/rtp/AmrCodec.cpp')
-rw-r--r--voip/jni/rtp/AmrCodec.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/voip/jni/rtp/AmrCodec.cpp b/voip/jni/rtp/AmrCodec.cpp
index 84c7166..e2d820e 100644
--- a/voip/jni/rtp/AmrCodec.cpp
+++ b/voip/jni/rtp/AmrCodec.cpp
@@ -52,7 +52,7 @@ public:
int set(int sampleRate, const char *fmtp);
int encode(void *payload, int16_t *samples);
- int decode(int16_t *samples, void *payload, int length);
+ int decode(int16_t *samples, int count, void *payload, int length);
private:
void *mEncoder;
@@ -128,7 +128,7 @@ int AmrCodec::encode(void *payload, int16_t *samples)
return length;
}
-int AmrCodec::decode(int16_t *samples, void *payload, int length)
+int AmrCodec::decode(int16_t *samples, int count, void *payload, int length)
{
unsigned char *bytes = (unsigned char *)payload;
Frame_Type_3GPP type;
@@ -213,7 +213,7 @@ public:
}
int encode(void *payload, int16_t *samples);
- int decode(int16_t *samples, void *payload, int length);
+ int decode(int16_t *samples, int count, void *payload, int length);
private:
void *mEncoder;
@@ -239,20 +239,24 @@ int GsmEfrCodec::encode(void *payload, int16_t *samples)
return -1;
}
-int GsmEfrCodec::decode(int16_t *samples, void *payload, int length)
+int GsmEfrCodec::decode(int16_t *samples, int count, void *payload, int length)
{
unsigned char *bytes = (unsigned char *)payload;
- if (length == 31 && (bytes[0] >> 4) == 0x0C) {
+ int n = 0;
+ while (n + 160 <= count && length >= 31 && (bytes[0] >> 4) == 0x0C) {
for (int i = 0; i < 30; ++i) {
bytes[i] = (bytes[i] << 4) | (bytes[i + 1] >> 4);
}
bytes[30] <<= 4;
- if (AMRDecode(mDecoder, AMR_122, bytes, samples, MIME_IETF) == 31) {
- return 160;
+ if (AMRDecode(mDecoder, AMR_122, bytes, &samples[n], MIME_IETF) != 31) {
+ break;
}
+ n += 160;
+ length -= 31;
+ bytes += 31;
}
- return -1;
+ return n;
}
} // namespace