[FFmpeg-cvslog] rtpenc: Add a payload type private option

Rafaël Carré git at videolan.org
Tue Sep 27 02:25:29 CEST 2011


ffmpeg | branch: master | Rafaël Carré <rafael.carre at savoirfairelinux.com> | Mon Sep 26 11:56:48 2011 -0400| [9152880e9503f193032304c65c78b297171c81ee] | committer: 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: Martin Storsjö <martin at martin.st>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9152880e9503f193032304c65c78b297171c81ee
---

 libavformat/rtp.c    |   11 ++++++++++-
 libavformat/rtp.h    |    6 ++++--
 libavformat/rtpenc.c |    4 +++-
 libavformat/sdp.c    |    2 +-
 4 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/libavformat/rtp.c b/libavformat/rtp.c
index 35edb50..5dee436 100644
--- a/libavformat/rtp.c
+++ b/libavformat/rtp.c
@@ -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)
diff --git a/libavformat/rtp.h b/libavformat/rtp.h
index 4d948ad..4f35142 100644
--- a/libavformat/rtp.h
+++ b/libavformat/rtp.h
@@ -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.
diff --git a/libavformat/rtpenc.c b/libavformat/rtpenc.c
index 1f5d9ba..ce42e3e 100644
--- a/libavformat/rtpenc.c
+++ b/libavformat/rtpenc.c
@@ -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;
diff --git a/libavformat/sdp.c b/libavformat/sdp.c
index f27a899..a586690 100644
--- a/libavformat/sdp.c
+++ b/libavformat/sdp.c
@@ -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;



More information about the ffmpeg-cvslog mailing list