payload-type-handler.h 2.95 KB
Newer Older
1 2
/*
 * payload-type-handler.h
Ghislain MARY's avatar
Ghislain MARY committed
3
 * Copyright (C) 2010-2017 Belledonne Communications SARL
4
 *
Ghislain MARY's avatar
Ghislain MARY committed
5 6 7 8
 * This program 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
 * of the License, or (at your option) any later version.
9 10 11 12 13 14 15
 *
 * This program 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
Ghislain MARY's avatar
Ghislain MARY committed
16 17
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 19 20 21 22 23
 */

#ifndef _PAYLOAD_TYPE_HANDLER_H_
#define _PAYLOAD_TYPE_HANDLER_H_

#include "linphone/utils/general.h"
24

25
#include "c-wrapper/internal/c-sal.h"
26

27
#define PAYLOAD_TYPE_ENABLED PAYLOAD_TYPE_USER_FLAG_0
28
#define PAYLOAD_TYPE_BITRATE_OVERRIDE PAYLOAD_TYPE_USER_FLAG_3
29
#define PAYLOAD_TYPE_FROZEN_NUMBER PAYLOAD_TYPE_USER_FLAG_4
30

31 32 33 34
// =============================================================================

L_DECL_C_STRUCT(LinphoneCore);

35 36 37 38 39 40 41 42 43 44
LINPHONE_BEGIN_NAMESPACE

struct VbrCodecBitrate {
	int maxAvailableBitrate;
	int minClockRate;
	int recommendedBitrate;
};

class PayloadTypeHandler {
public:
45
	explicit PayloadTypeHandler (LinphoneCore *core) : core(core) {}
46

47
	bctbx_list_t *makeCodecsList (SalStreamType type, int bandwidthLimit, int maxCodecs, const bctbx_list_t *previousList);
48 49 50 51 52 53 54 55 56 57

	static bool bandwidthIsGreater (int bandwidth1, int bandwidth2);
	static int getAudioPayloadTypeBandwidth (const OrtpPayloadType *pt, int maxBandwidth);
	static double getAudioPayloadTypeBandwidthFromCodecBitrate (const OrtpPayloadType *pt);
	static int getMaxCodecSampleRate (const bctbx_list_t *codecs);
	static int getMinBandwidth (int downBandwidth, int upBandwidth);
	static int getRemainingBandwidthForVideo (int total, int audio);
	static bool isPayloadTypeNumberAvailable (const bctbx_list_t *codecs, int number, const OrtpPayloadType *ignore);

private:
58 59 60 61 62 63 64 65 66 67
	static int findPayloadTypeNumber (const bctbx_list_t *assigned, const OrtpPayloadType *pt);
	static bool hasTelephoneEventPayloadType (const bctbx_list_t *tev, int rate);
	static bool isPayloadTypeUsableForBandwidth (const OrtpPayloadType *pt, int bandwidthLimit);
	static int lookupTypicalVbrBitrate (int maxBandwidth, int clockRate);

	void assignPayloadTypeNumbers (const bctbx_list_t *codecs);
	bctbx_list_t *createSpecialPayloadTypes (const bctbx_list_t *codecs);
	bctbx_list_t *createTelephoneEventPayloadTypes (const bctbx_list_t *codecs);
	bool isPayloadTypeUsable (const OrtpPayloadType *pt);

68 69 70 71 72 73 74 75 76 77 78
	static const int udpHeaderSize;
	static const int rtpHeaderSize;
	static const int ipv4HeaderSize;
	static const VbrCodecBitrate defaultVbrCodecBitrates[];

	LinphoneCore *core = nullptr;
};

LINPHONE_END_NAMESPACE

#endif // ifndef _PAYLOAD_TYPE_HANDLER_H_