payload-type-handler.h 3.01 KB
Newer Older
1 2
/*
 * payload-type-handler.h
3
 * Copyright (C) 2010-2018 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
#ifndef _L_PAYLOAD_TYPE_HANDLER_H_
#define _L_PAYLOAD_TYPE_HANDLER_H_
22 23

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

25
#include "c-wrapper/internal/c-sal.h"
26 27
#include "core/core.h"
#include "core/core-accessor.h"
28

29
#define PAYLOAD_TYPE_ENABLED PAYLOAD_TYPE_USER_FLAG_0
30
#define PAYLOAD_TYPE_BITRATE_OVERRIDE PAYLOAD_TYPE_USER_FLAG_3
31
#define PAYLOAD_TYPE_FROZEN_NUMBER PAYLOAD_TYPE_USER_FLAG_4
32

33 34
// =============================================================================

35 36 37 38 39 40 41 42
LINPHONE_BEGIN_NAMESPACE

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

43 44 45
class Core;

class PayloadTypeHandler : public CoreAccessor {
46
public:
47
	explicit PayloadTypeHandler (const std::shared_ptr<Core> &core) : CoreAccessor(core) {}
48

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

	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:
60 61 62 63 64 65 66 67 68 69
	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);

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

LINPHONE_END_NAMESPACE

78
#endif // ifndef _L_PAYLOAD_TYPE_HANDLER_H_