mscodecutils.h 8.9 KB
Newer Older
1 2 3
/*
 mediastreamer2 library - modular sound and video processing and streaming
 Copyright (C) 2012  Belledonne Communications, Grenoble, France
4

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
 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.
14

15 16 17 18 19
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

20 21
#ifndef mscodecutils_h
#define mscodecutils_h
22

23 24
#include "mediastreamer2/mscommon.h"

25 26 27 28
#ifdef __cplusplus
extern "C"{
#endif

29 30 31
/**
 * Helper object for audio decoders to determine whether PLC (packet loss concealment is needed).
**/
32 33
typedef struct _MSConcealerContext MSConcealerContext;

34 35 36 37
/**
 * Creates a new concealer object.
 * @param max_plc_count the number of consecutive milliseconds of PLC allowed.
**/
38
MS2_PUBLIC MSConcealerContext* ms_concealer_context_new(uint32_t max_plc_count);
39 40 41 42 43 44 45 46 47 48
/**
 * Destroys a concealer object.
**/
MS2_PUBLIC void ms_concealer_context_destroy(MSConcealerContext* context);

/**
 * Returns 1 when PLC is needed, 0 otherwise.
 * @param obj the concealer object
 * @param current_time the current time in milliseconds, as pointed by f->ticker->time .
**/
49
MS2_PUBLIC unsigned int ms_concealer_context_is_concealement_required(MSConcealerContext* obj, uint64_t current_time);
50 51 52 53 54 55 56

/**
 * Call this function whenever you decoded a packet, for true or in PLC mode, to inform the concealer
 * of how the audio stream is going.
 * @param obj the concealer object
 * @param current_time the current time in milliseconds, as pointed by f->ticker->time.
 * @param time_increment the number of milliseconds of audio decoded.
57
 * @param got_packet set to TRUE if a real frame was decoded, FALSE if it was a PLC frame.
58
 * @return if a PLC period terminates, returns the duration of this PLC period in milliseconds, 0 otherwise.
59
**/
60
MS2_PUBLIC uint32_t ms_concealer_inc_sample_time(MSConcealerContext* obj, uint64_t current_time, uint32_t time_increment, bool_t got_packet);
61

62

Simon Morlat's avatar
Simon Morlat committed
63
MS2_PUBLIC unsigned long ms_concealer_context_get_total_number_of_plc(MSConcealerContext* obj);
64

jehan's avatar
jehan committed
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
/**
 * Helper object for audio decoders to determine whether PLC (packet loss concealment is needed), based on timestamp information.
**/
typedef struct _MSConcealerTsContext MSConcealerTsContext;

/**
 * Creates a new concealer object.
 * @param max_plc_count maximum duration of PLC allowed, expressed in timestamp units.
**/
MS2_PUBLIC MSConcealerTsContext* ms_concealer_ts_context_new(unsigned int max_plc_ts);
/**
 * Destroys a concealer object.
**/
MS2_PUBLIC void ms_concealer_ts_context_destroy(MSConcealerTsContext* context);

/**
 * Returns 1 when PLC is needed, 0 otherwise.
 * @param obj the concealer object
 * @param current_ts the current time converted in timestamp units, usually (f->ticker->time*clock_rate)/1000 .
**/
MS2_PUBLIC unsigned int ms_concealer_ts_context_is_concealement_required(MSConcealerTsContext* obj,uint64_t current_ts);

/**
 * Call this function whenever you decoded a packet, for true or in PLC mode, to inform the concealer
 * of how the audio stream is going.
 * @param obj the concealer object
92
 * @param current_ts the current time converted in timestamp units, usually (f->ticker->time*clock_rate)/1000
93
 * @param ts_increment the duration of audio decoded expressed in timestamp units
94
 * @param got_packet set to TRUE if a real frame was decoded, FALSE if it was a PLC frame.
95
 * @return if a PLC period terminates, returns the duration of this PLC period in timestamp units, 0 otherwise.
96
**/
97
MS2_PUBLIC uint32_t ms_concealer_ts_context_inc_sample_ts(MSConcealerTsContext* obj, uint64_t current_ts, uint32_t ts_increment, bool_t got_packet);
98 99 100 101 102


MS2_PUBLIC unsigned long ms_concealer_ts_context_get_total_number_of_plc(MSConcealerTsContext* obj);


jehan's avatar
jehan committed
103 104
/*FEC API*/
typedef struct _MSRtpPayloadPickerContext MSRtpPayloadPickerContext;
105
typedef mblk_t* (*RtpPayloadPicker)(MSRtpPayloadPickerContext* context,unsigned int sequence_number);
jehan's avatar
jehan committed
106 107 108 109 110
struct _MSRtpPayloadPickerContext {
	void* filter_graph_manager; /*I.E stream*/
	RtpPayloadPicker picker;
};

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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
struct _MSOfferAnswerContext;

#ifndef MS_OFFER_ANSWER_CONTEXT_DEFINED
#define MS_OFFER_ANSWER_CONTEXT_DEFINED
typedef struct _MSOfferAnswerContext MSOfferAnswerContext;
#endif

/* SDP offer answer payload matching API*/

/**
 * The MSPayloadMatcherFunc prototype takes:
 * - a list of local payload types
 * - a remote payload type (offered or answered) by remote to be matched agains payload types of the local payload type list.
 * - the full list of remote (offered or answered) payload types, which is sometimes necessary to do the matching in ambiguous situations.
 * - is_reading, a boolean indicating whether we are doing the match processing while reading a SDP response, or (if FALSE) to prepare a response to be sent.
 * The expected return value is a newly allocated PayloadType similar to the local payload type that was matched.
 * Due to specific per codec offer/answer logic, the fmtp of the payload type might be changed compared to the original local payload type.
 * If there is no match, NULL must be returned.
**/
typedef PayloadType * (*MSPayloadMatcherFunc)(MSOfferAnswerContext *context, const MSList *local_payloads, const PayloadType *remote_payload, const MSList *remote_payloads, bool_t is_reading);

/**
 * The MSOfferAnswerContext is only there to provide a context during the SDP offer/answer handshake.
 * It could be used in the future to provide extra information, for the moment the context is almost useless*/
struct _MSOfferAnswerContext{
	MSPayloadMatcherFunc match_payload;
	void (*destroy)(MSOfferAnswerContext *ctx);
	void *context_data;
};


/**
 * Executes an offer/answer processing for a given codec.
 * @param context the context
 * @param local_payloads the local payload type supported
 * @param remote_payload a remote payload type (offered or answered) by remote to be matched agains payload types of the local payload type list.
 * @param remote_payloads the full list of remote (offered or answered) payload types, which is sometimes necessary to do the matching in ambiguous situations.
 * @param is_reading, a boolean indicating whether we are doing the match processing while reading a SDP response, or (if FALSE) to prepare a response to be sent.
 * The expected return value is a newly allocated PayloadType similar to the local payload type that was matched.
 * Due to specific per codec offer/answer logic, the fmtp of the payload type might be changed compared to the original local payload type.
 * If there is no match, NULL must be returned.
**/
MS2_PUBLIC PayloadType * ms_offer_answer_context_match_payload(MSOfferAnswerContext *context, const MSList *local_payloads, const PayloadType *remote_payload, const MSList *remote_payloads, bool_t is_reading); 
MS2_PUBLIC void ms_offer_answer_context_destroy(MSOfferAnswerContext *ctx);

/**
 * A convenience function to instanciate an offer answer context giving only the payload matching function pointer.
**/
MS2_PUBLIC MSOfferAnswerContext *ms_offer_answer_create_simple_context(MSPayloadMatcherFunc func);
/**
 * The struct to declare offer-answer provider, that act as factories per mime type to instanciate MSOfferAnswerContext object able to take in charge
 * the offer answer model for a particular codec
**/
struct _MSOfferAnswerProvider{
	const char *mime_type;
	MSOfferAnswerContext *(*create_context)(void);
};

169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
/**
 * A convenience structure and API to intellengently limit the number of key frame request of an encoder.
 **/
typedef struct _MSIFrameRequestsLimiterCtx {
	uint64_t last_sent_iframe_time;
	int min_iframe_interval;
	bool_t iframe_required;
} MSIFrameRequestsLimiterCtx;

MS2_PUBLIC void ms_iframe_requests_limiter_init(MSIFrameRequestsLimiterCtx *obj, int min_iframe_interval_ms);

MS2_PUBLIC void ms_iframe_requests_limiter_request_iframe(MSIFrameRequestsLimiterCtx *obj);

MS2_PUBLIC bool_t ms_iframe_requests_limiter_iframe_requested(const MSIFrameRequestsLimiterCtx *obj, uint64_t curtime_ms);

MS2_PUBLIC void ms_iframe_requests_limiter_notify_iframe_sent(MSIFrameRequestsLimiterCtx *obj, uint64_t curtime_ms);

/**
 * The goal of this small object is to tell when to send I frames at startup:
 * at 2 and 4 seconds.
 */


typedef struct MSVideoStarter {
	uint64_t next_time;
	int i_frame_count;
	bool_t active;
} MSVideoStarter;
197

198 199 200 201
MS2_PUBLIC void ms_video_starter_init(MSVideoStarter *vs);
MS2_PUBLIC void ms_video_starter_first_frame(MSVideoStarter *vs, uint64_t curtime);
MS2_PUBLIC bool_t ms_video_starter_need_i_frame(MSVideoStarter *vs, uint64_t curtime);
MS2_PUBLIC void ms_video_starter_deactivate(MSVideoStarter *vs);
202

203 204 205 206
#ifdef __cplusplus
}
#endif

207
#endif