On Fri, 23 Sep 2011, Rafaël Carré wrote:

Specifying the payload type is useful when the type number has
already been negociated before creating the stream, for example
in SIP protocol.
---
libavformat/movenc.h |    1 +
libavformat/rtp.c    |   10 +++++++++-
libavformat/rtp.h    |    6 ++++--
libavformat/rtpenc.c |    3 ++-
libavformat/rtpenc.h |    3 ++-
libavformat/rtsp.h   |    5 +++++
libavformat/sdp.c    |    2 +-
7 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/libavformat/movenc.h b/libavformat/movenc.h
index 39cdb39..e4f905b 100644
--- a/libavformat/movenc.h
+++ b/libavformat/movenc.h
@@ -112,6 +112,7 @@ typedef struct MOVMuxContext {

    int flags;
    int rtp_flags;
+    int payload_type; ///< for RTP hinting
} MOVMuxContext;

#define FF_MOV_FLAG_RTP_HINT 1

Passing this option through from the mov and rtsp muxers doesn't really make much sense in its current form, I think, since it's on the AVFormatContext level, and you'd want to specify it per AVStream. (If you'd want to pass this option through, you'd need to copy it to the chained muxers in rtpenc_chain.c.)

But since I don't off-hand see an easy and clean way to do this, it might be better to just leave out the mov and rtsp muxer parts for now - they weren't needed for your usecase at the moment anyway, right?

diff --git a/libavformat/rtp.c b/libavformat/rtp.c
index 35edb50..a94a46e 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,16 @@ 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->oformat;

fmt ? fmt->oformat : NULL
would perhaps be better, so that an user could ignore this new parameter and just pass NULL instead.

+
+    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..43fb514 100644
--- a/libavformat/rtpenc.c
+++ b/libavformat/rtpenc.c
@@ -92,7 +92,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/rtpenc.h b/libavformat/rtpenc.h
index 3a9e19b..880af83 100644
--- a/libavformat/rtpenc.h
+++ b/libavformat/rtpenc.h
@@ -67,7 +67,8 @@ typedef struct RTPMuxContext RTPMuxContext;

#define FF_RTP_FLAG_OPTS(ctx, fieldname) \
    { "rtpflags", "RTP muxer flags", offsetof(ctx, fieldname), FF_OPT_TYPE_FLAGS, {.dbl = 
0}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "rtpflags" }, \
-    { "latm", "Use MP4A-LATM packetization instead of MPEG4-GENERIC for AAC", 0, 
FF_OPT_TYPE_CONST, {.dbl = FF_RTP_FLAG_MP4A_LATM}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, 
"rtpflags" } \
+    { "latm", "Use MP4A-LATM packetization instead of MPEG4-GENERIC for AAC", 0, 
FF_OPT_TYPE_CONST, {.dbl = FF_RTP_FLAG_MP4A_LATM}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, 
"rtpflags" }, \
+    { "payload_type", "Specify RTP payload type", offsetof(ctx, payload_type), 
FF_OPT_TYPE_INT, {.dbl = -1 }, -1, 127, AV_OPT_FLAG_ENCODING_PARAM } \

void ff_rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m);

If we don't add this option to the mov/rtsp muxers, this should be moved to the rtp muxer specific option list in rtpenc.c instead.

diff --git a/libavformat/rtsp.h b/libavformat/rtsp.h
index 265d9f8..b7dd78d 100644
--- a/libavformat/rtsp.h
+++ b/libavformat/rtsp.h
@@ -346,6 +346,11 @@ typedef struct RTSPState {
     * Option flags for the chained RTP muxer.
     */
    int rtp_muxer_flags;
+
+    /**
+     * Option for the chained RTP muxer.
+     */
+    int payload_type;
} RTSPState;

... and this can be left out then.

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;
--
1.7.5.4

Except for those minor changes, it looks quite promising to me. I'll test it when you submit a revised version :-)

// Martin
_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to