问题
I want to make a custom sipdroid client by using reverse byte order. I think that makes other Voip clients cannot decode these data.
So I read the code of the SipDroid. I found RTP data goes this way: 1. AudioRecord.read(originalPCM) 2. encode(originalPCM, encodedData) 3. rtp_socket.send(rtp_packet) //the encodeData is rtp_packet's data part
And the other side is: 1. rtp_receive(rtp_packet) 2. decode(encodeData, PCMData) //the encodeData is rtp_packet's data part 3. AudioTrack.write(PCMData)
So I modified the SipdroidSocket class. In send method, I add the following code at the beginning.
byte[] b = pack.getData();
reverse(b);
pack.setData(b);
And add the following code at the end of the receive method.
byte[] b = pack.getData();
reverse(b);
pack.setData(b);
I think in this way, the two client can work as usual. But it failed. And I don't know the reason. Please help me to find out why. Thanks.
回答1:
You should not reverse the hole buffer unless you receive 2,4,8 bytes at a time. You should treat the data as elements of 2,4,8 bytes depending on how the data were stored. The code i see here will not work. suppose you have a buffer of data bytes 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08 stored as 4 byte elements of 0x04030201-0x08070605. Reversing the hole buffer will produce 0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01 which is wrong because you will end up with 0x05060708-0x04030201 If you reverse one element(4 bytes) at a time. Keep in mind that the size of an element depends on how the values were stored
来源:https://stackoverflow.com/questions/16538893/sipdroid-data-encrypt-failed