Commit 9152880e authored by Rafaël Carré's avatar Rafaël Carré Committed by Martin Storsjö

rtpenc: Add a payload type private option

Specifying the payload type is useful when the type number has
already been negotiated before creating the stream, for example
in SIP protocol.
Signed-off-by: 's avatarMartin Storsjö <martin@martin.st>
parent 14288774
......@@ -19,6 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <libavutil/opt.h>
#include "avformat.h"
#include "rtp.h"
......@@ -89,9 +90,17 @@ int ff_rtp_get_codec_info(AVCodecContext *codec, int payload_type)
return -1;
}
int ff_rtp_get_payload_type(AVCodecContext *codec)
int ff_rtp_get_payload_type(AVFormatContext *fmt, AVCodecContext *codec)
{
int i, payload_type;
AVOutputFormat *ofmt = fmt ? fmt->oformat : NULL;
/* Was the payload type already specified for the RTP muxer? */
if (ofmt && ofmt->priv_class)
payload_type = av_get_int(fmt->priv_data, "payload_type", NULL);
if (payload_type >= 0)
return payload_type;
/* compute the payload type */
for (payload_type = -1, i = 0; AVRtpPayloadTypes[i].pt >= 0; ++i)
......
......@@ -21,15 +21,17 @@
#ifndef AVFORMAT_RTP_H
#define AVFORMAT_RTP_H
#include "libavformat/avformat.h"
#include "libavcodec/avcodec.h"
/**
* Return the payload type for a given codec.
* Return the payload type for a given codec used in the given format context.
*
* @param fmt The context of the format
* @param codec The context of the codec
* @return The payload type (the 'PT' field in the RTP header).
*/
int ff_rtp_get_payload_type(AVCodecContext *codec);
int ff_rtp_get_payload_type(AVFormatContext *fmt, AVCodecContext *codec);
/**
* Initialize a codec context based on the payload type.
......
......@@ -32,6 +32,7 @@
static const AVOption options[] = {
FF_RTP_FLAG_OPTS(RTPMuxContext, flags),
{ "payload_type", "Specify RTP payload type", offsetof(RTPMuxContext, payload_type), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 127, AV_OPT_FLAG_ENCODING_PARAM },
{ NULL },
};
......@@ -92,7 +93,8 @@ static int rtp_write_header(AVFormatContext *s1)
return -1;
}
s->payload_type = ff_rtp_get_payload_type(st->codec);
if (s->payload_type < 0)
s->payload_type = ff_rtp_get_payload_type(s1, st->codec);
s->base_timestamp = av_get_random_seed();
s->timestamp = s->base_timestamp;
s->cur_timestamp = 0;
......
......@@ -532,7 +532,7 @@ void ff_sdp_write_media(char *buff, int size, AVCodecContext *c, const char *des
const char *type;
int payload_type;
payload_type = ff_rtp_get_payload_type(c);
payload_type = ff_rtp_get_payload_type(fmt, c);
switch (c->codec_type) {
case AVMEDIA_TYPE_VIDEO : type = "video" ; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment