00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <qapplication.h>
00013
00014 #include <stdio.h>
00015 #include <string.h>
00016 #include <errno.h>
00017 #include <iostream>
00018
00019 #ifndef WIN32
00020 #include <unistd.h>
00021 #include <fcntl.h>
00022 #include <sys/ioctl.h>
00023
00024 #include <mythtv/mythcontext.h>
00025 #include "config.h"
00026 #endif
00027
00028 #include "rtp.h"
00029 #include "g711.h"
00030
00031 extern "C" {
00032 #include "gsm/gsm.h"
00033 }
00034
00035 using namespace std;
00036
00037
00038
00039 gsmCodec::gsmCodec() : codec()
00040 {
00041 gsmEncData = gsm_create();
00042 gsmDecData = gsm_create();
00043 gsmMicrosoftCompatability = false;
00044 }
00045
00046 gsmCodec::~gsmCodec()
00047 {
00048 gsm_destroy(gsmEncData);
00049 gsm_destroy(gsmDecData);
00050 }
00051
00052 int gsmCodec::Encode(short *In, unsigned char *Out, int Samples, short &maxPower, int gain)
00053 {
00054 (void)gain;
00055 if (Samples != 160)
00056 cout << "GSM Encode unsupported length " << Samples << endl;
00057 gsm_encode(gsmEncData, In, Out);
00058 maxPower = 0;
00059 for (int i=0;i<Samples;i++)
00060 maxPower = QMAX(maxPower, *In++);
00061 return 33;
00062 }
00063
00064 int gsmCodec::Decode(unsigned char *In, short *Out, int Len, short &maxPower)
00065 {
00066 if (Len == 65)
00067 {
00068
00069
00070
00071 if (!gsmMicrosoftCompatability)
00072 {
00073 cout << "SIP: Switching GSM decoder to Microsoft Compatability mode\n";
00074 gsmMicrosoftCompatability = true;
00075 int opt=1;
00076 gsm_option(gsmDecData, GSM_OPT_WAV49, &opt);
00077 }
00078 gsm_decode(gsmDecData, In, Out);
00079 gsm_decode(gsmDecData, In+33, Out+160);
00080 maxPower = 0;
00081 for (int i=0;i<320;i++)
00082 maxPower = QMAX(maxPower, *Out++);
00083 return (320*sizeof(short));
00084 }
00085
00086 if (Len != 33)
00087 cout << "GSM Invalid receive length " << Len << endl;
00088 gsm_decode(gsmDecData, In, Out);
00089 maxPower = 0;
00090 for (int i=0;i<160;i++)
00091 maxPower = QMAX(maxPower, *Out++);
00092 return (160*sizeof(short));
00093 }
00094
00095 int gsmCodec::Silence(uchar *out, int ms)
00096 {
00097 if (ms != 20)
00098 cout << "GSM Silence unsupported length " << ms << endl;
00099
00100 short pcmSilence[160];
00101 memset(pcmSilence, 0, 160*sizeof(short));
00102 gsm_encode(gsmEncData, pcmSilence, out);
00103 return 33;
00104 }
00105