summaryrefslogtreecommitdiff
path: root/pjmedia/src/pjmedia-codec/g7221.c
diff options
context:
space:
mode:
authorNanang Izzuddin <nanang@teluu.com>2009-04-06 11:45:25 +0000
committerNanang Izzuddin <nanang@teluu.com>2009-04-06 11:45:25 +0000
commitc8a381e4f05692c740b7f0b7a45e64968fa5ef1d (patch)
treecdf99354f98d6d3758014c77afc0cd40cea91877 /pjmedia/src/pjmedia-codec/g7221.c
parent98a09e8c16579772fb7aec05371fc5f13c69dbe2 (diff)
Ticket #774: Fixed G722.1 codec to aware about endianness in packing/unpacking RTP payload (the underlying implementation, ITU impl ref, works with 16-bits coded data).
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@2572 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjmedia/src/pjmedia-codec/g7221.c')
-rw-r--r--pjmedia/src/pjmedia-codec/g7221.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/pjmedia/src/pjmedia-codec/g7221.c b/pjmedia/src/pjmedia-codec/g7221.c
index 7d9db6ea..91c89628 100644
--- a/pjmedia/src/pjmedia-codec/g7221.c
+++ b/pjmedia/src/pjmedia-codec/g7221.c
@@ -763,13 +763,28 @@ static pj_status_t codec_encode( pjmedia_codec *codec,
mlt_coefs,
codec_data->samples_per_frame);
- /* Encode the mlt coefs */
+ /* Encode the mlt coefs. Note that encoder output stream is 16 bit array,
+ * so we need to take care about endianness.
+ */
encoder(codec_data->frame_size_bits,
codec_data->number_of_regions,
mlt_coefs,
mag_shift,
output->buf);
+#if defined(PJ_IS_LITTLE_ENDIAN) && PJ_IS_LITTLE_ENDIAN!=0
+ {
+ pj_uint16_t *p, *p_end;
+
+ p = (pj_uint16_t*)output->buf;
+ p_end = p + codec_data->frame_size/2;
+ while (p < p_end) {
+ *p = pj_htons(*p);
+ ++p;
+ }
+ }
+#endif
+
output->type = PJMEDIA_FRAME_TYPE_AUDIO;
output->size = codec_data->frame_size;
@@ -800,6 +815,23 @@ static pj_status_t codec_decode( pjmedia_codec *codec,
/* Check frame in length size */
PJ_ASSERT_RETURN((pj_uint16_t)input->size == codec_data->frame_size,
PJMEDIA_CODEC_EFRMINLEN);
+
+ /* Decoder requires input of 16-bits array, so we need to take care
+ * about endianness.
+ */
+#if defined(PJ_IS_LITTLE_ENDIAN) && PJ_IS_LITTLE_ENDIAN!=0
+ {
+ pj_uint16_t *p, *p_end;
+
+ p = (pj_uint16_t*)input->buf;
+ p_end = p + codec_data->frame_size/2;
+ while (p < p_end) {
+ *p = pj_ntohs(*p);
+ ++p;
+ }
+ }
+#endif
+
bitobj.code_word_ptr = (Word16*)input->buf;
bitobj.current_word = *bitobj.code_word_ptr;
bitobj.code_bit_count = 0;