audiocodec.cpp 3.17 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * Copyright (C) 2004 Savoir-Faire Linux inc.
 * Author: Laurielle Lea <laurielle.lea@savoirfairelinux.com> 
 *
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2,
 * or (at your option) any later version.
 *
 * This is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with dpkg; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

savoirfairelinux's avatar
savoirfairelinux committed
20 21 22 23 24 25
#include <qapplication.h>

#include "audiocodec.h"
#include "configuration.h"
#include "g711.h"

26 27 28 29
#include <string>
#ifdef  CCXX_NAMESPACES
using namespace std;
#endif
savoirfairelinux's avatar
savoirfairelinux committed
30 31 32

AudioCodec::AudioCodec (void) {
	// Init array handleCodecs
33 34 35 36 37
	handleCodecs[0] = matchPayloadCodec(Config::gets("Audio", "Codecs.codec1"));
	handleCodecs[1] = matchPayloadCodec(Config::gets("Audio", "Codecs.codec2"));
	handleCodecs[2] = matchPayloadCodec(Config::gets("Audio", "Codecs.codec3"));
	handleCodecs[3] = matchPayloadCodec(Config::gets("Audio", "Codecs.codec4"));
	handleCodecs[4] = matchPayloadCodec(Config::gets("Audio", "Codecs.codec5"));
savoirfairelinux's avatar
savoirfairelinux committed
38 39 40 41 42 43
}

AudioCodec::~AudioCodec (void) {
}

int
44
AudioCodec::matchPayloadCodec (std::string codecname) {
savoirfairelinux's avatar
savoirfairelinux committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
	if (codecname == CODEC_ALAW) {
		return PAYLOAD_CODEC_ALAW;
	} else if (codecname == CODEC_ULAW) {
		return PAYLOAD_CODEC_ULAW;
	} else if (codecname == CODEC_GSM) {
		return PAYLOAD_CODEC_GSM;
	} else if (codecname == CODEC_ILBC) {
		return PAYLOAD_CODEC_ILBC;
	} else if (codecname == CODEC_SPEEX) {
		return PAYLOAD_CODEC_SPEEX;
	} else 
		return -1;
}

char *
AudioCodec::rtpmapPayload (int payload) {
	switch (payload) {
		case PAYLOAD_CODEC_ALAW:
 			return "PCMA";
 			break;

 		case PAYLOAD_CODEC_ULAW:
 			return "PCMU";
 			break;

 		case PAYLOAD_CODEC_GSM:
 			return "GSM";
 			break;

 		case PAYLOAD_CODEC_ILBC:
 			return "iLBC";
 			break;

 		case PAYLOAD_CODEC_SPEEX:
 			return "speex";
 			break;

		default:
			break;
	}
	return NULL;
}

int
AudioCodec::codecDecode (int pt, short *dst, unsigned char *src, unsigned int size) {
	switch (pt) {
	case PAYLOAD_CODEC_ULAW:
		return G711::ULawDecode (dst, src, size);
		break;

	case PAYLOAD_CODEC_ALAW:
		return G711::ALawDecode (dst, src, size);
		break;

	case PAYLOAD_CODEC_GSM:
		// TODO: 
		break;

	case PAYLOAD_CODEC_ILBC:
		// TODO
		break;

	case PAYLOAD_CODEC_SPEEX:
		// TODO
		break;

	default:
		break;
	}
	return 0;
}

int
AudioCodec::codecEncode (int pt, unsigned char *dst, short *src, unsigned int size) {
		switch (pt) {
			case PAYLOAD_CODEC_ULAW:
				return G711::ULawEncode (dst, src, size);
				break;

			case PAYLOAD_CODEC_ALAW:
				return G711::ALawEncode (dst, src, size);
				break;

			case PAYLOAD_CODEC_GSM:
				// TODO
				break;

			case PAYLOAD_CODEC_ILBC:
				// TODO
				break;

			case PAYLOAD_CODEC_SPEEX:
				// TODO
				break;

			default:
				break;
		}
	return 0;
}

void
AudioCodec::noSupportedCodec (void) {
	qDebug("Codec no supported");
}