[09/16] rtpdec: Allow setting the need_parsing field in RTPDynamicProtocolHandler

Message ID 1424727122-2827-9-git-send-email-martin@martin.st
State Committed
Commit b7a4c319fda22aa91ce29692d728ec6103b514f6
Headers show

Commit Message

Martin Storsjö Feb. 23, 2015, 9:31 p.m.
This allows getting rid of quite a bit of boilerplate in depacketizers.

The default value (initializing need_parsing to 0, aka
AVSTREAM_PARSE_NONE) is the same as it is initialized to by default
in AVStream.
---
 libavformat/rtpdec.h | 1 +
 libavformat/rtsp.c   | 9 ++++++---
 2 files changed, 7 insertions(+), 3 deletions(-)

Comments

Luca Barbato Feb. 23, 2015, 9:37 p.m. | #1
On 23/02/15 22:31, Martin Storsjö wrote:
> This allows getting rid of quite a bit of boilerplate in depacketizers.
>

Ok.

Patch

diff --git a/libavformat/rtpdec.h b/libavformat/rtpdec.h
index 9f1a475..e015942 100644
--- a/libavformat/rtpdec.h
+++ b/libavformat/rtpdec.h
@@ -116,6 +116,7 @@  struct RTPDynamicProtocolHandler {
     const char *enc_name;
     enum AVMediaType codec_type;
     enum AVCodecID codec_id;
+    enum AVStreamParseType need_parsing;
     int static_payload_id; /* 0 means no payload id is set. 0 is a valid
                             * payload ID (PCMU), too, but that format doesn't
                             * require any custom depacketization code. */
diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index a3d6814..72e5b5b 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -176,13 +176,16 @@  static int get_sockaddr(const char *buf, struct sockaddr_storage *sock)
 
 #if CONFIG_RTPDEC
 static void init_rtp_handler(RTPDynamicProtocolHandler *handler,
-                             RTSPStream *rtsp_st, AVCodecContext *codec)
+                             RTSPStream *rtsp_st, AVStream *st)
 {
+    AVCodecContext *codec = st ? st->codec : NULL;
     if (!handler)
         return;
     if (codec)
         codec->codec_id          = handler->codec_id;
     rtsp_st->dynamic_handler = handler;
+    if (st)
+        st->need_parsing = handler->need_parsing;
     if (handler->alloc) {
         rtsp_st->dynamic_protocol_context = handler->alloc();
         if (!rtsp_st->dynamic_protocol_context)
@@ -215,7 +218,7 @@  static int sdp_parse_rtpmap(AVFormatContext *s,
     if (codec->codec_id == AV_CODEC_ID_NONE) {
         RTPDynamicProtocolHandler *handler =
             ff_rtp_handler_find_by_name(buf, codec->codec_type);
-        init_rtp_handler(handler, rtsp_st, codec);
+        init_rtp_handler(handler, rtsp_st, st);
         /* If no dynamic handler was found, check with the list of standard
          * allocated types, if such a stream for some reason happens to
          * use a private payload type. This isn't handled in rtpdec.c, since
@@ -465,7 +468,7 @@  static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1,
                 /* Even static payload types may need a custom depacketizer */
                 handler = ff_rtp_handler_find_by_id(
                               rtsp_st->sdp_payload_type, st->codec->codec_type);
-                init_rtp_handler(handler, rtsp_st, st->codec);
+                init_rtp_handler(handler, rtsp_st, st);
                 if (handler && handler->init)
                     handler->init(s, st->index,
                                   rtsp_st->dynamic_protocol_context);