[10/16] rtpdec: Set need_parsing via a handler field

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

Commit Message

Martin Storsjö Feb. 23, 2015, 9:31 p.m.
This avoids implementing a full function just to set this one
field.
---
 libavformat/rtpdec_ac3.c          | 11 +----------
 libavformat/rtpdec_dv.c           | 15 +--------------
 libavformat/rtpdec_h261.c         | 13 +------------
 libavformat/rtpdec_h263.c         | 13 ++-----------
 libavformat/rtpdec_h263_rfc2190.c | 10 +---------
 libavformat/rtpdec_h264.c         | 11 +----------
 libavformat/rtpdec_hevc.c         | 15 +--------------
 libavformat/rtpdec_mpa_robust.c   |  3 +--
 libavformat/rtpdec_mpeg12.c       | 12 ++----------
 libavformat/rtpdec_mpeg4.c        | 11 +----------
 libavformat/rtpdec_xiph.c         | 11 +----------
 11 files changed, 13 insertions(+), 112 deletions(-)

Comments

Luca Barbato Feb. 23, 2015, 9:37 p.m. | #1
On 23/02/15 22:31, Martin Storsjö wrote:
> This avoids implementing a full function just to set this one
> field.
> ---
>   libavformat/rtpdec_ac3.c          | 11 +----------
>   libavformat/rtpdec_dv.c           | 15 +--------------
>   libavformat/rtpdec_h261.c         | 13 +------------
>   libavformat/rtpdec_h263.c         | 13 ++-----------
>   libavformat/rtpdec_h263_rfc2190.c | 10 +---------
>   libavformat/rtpdec_h264.c         | 11 +----------
>   libavformat/rtpdec_hevc.c         | 15 +--------------
>   libavformat/rtpdec_mpa_robust.c   |  3 +--
>   libavformat/rtpdec_mpeg12.c       | 12 ++----------
>   libavformat/rtpdec_mpeg4.c        | 11 +----------
>   libavformat/rtpdec_xiph.c         | 11 +----------
>   11 files changed, 13 insertions(+), 112 deletions(-)
>

Ok.

Patch

diff --git a/libavformat/rtpdec_ac3.c b/libavformat/rtpdec_ac3.c
index a594389..1b04a0b 100644
--- a/libavformat/rtpdec_ac3.c
+++ b/libavformat/rtpdec_ac3.c
@@ -31,15 +31,6 @@  struct PayloadContext {
     AVIOContext *fragment;
 };
 
-static av_cold int ac3_init(AVFormatContext *s, int st_index,
-                            PayloadContext *data)
-{
-    if (st_index < 0)
-        return 0;
-    s->streams[st_index]->need_parsing = AVSTREAM_PARSE_FULL;
-    return 0;
-}
-
 static PayloadContext *ac3_new_context(void)
 {
     return av_mallocz(sizeof(PayloadContext));
@@ -150,7 +141,7 @@  RTPDynamicProtocolHandler ff_ac3_dynamic_handler = {
     .enc_name           = "ac3",
     .codec_type         = AVMEDIA_TYPE_AUDIO,
     .codec_id           = AV_CODEC_ID_AC3,
-    .init               = ac3_init,
+    .need_parsing       = AVSTREAM_PARSE_FULL,
     .alloc              = ac3_new_context,
     .free               = ac3_free_context,
     .parse_packet       = ac3_handle_packet,
diff --git a/libavformat/rtpdec_dv.c b/libavformat/rtpdec_dv.c
index 12e1fcf..f83fd90 100644
--- a/libavformat/rtpdec_dv.c
+++ b/libavformat/rtpdec_dv.c
@@ -50,19 +50,6 @@  static av_cold void dv_free_context(PayloadContext *data)
     av_free(data);
 }
 
-static av_cold int dv_init(AVFormatContext *ctx, int st_index,
-                           PayloadContext *data)
-{
-    av_dlog(ctx, "dv_init() for stream %d\n", st_index);
-
-    if (st_index < 0)
-        return 0;
-
-    ctx->streams[st_index]->need_parsing = AVSTREAM_PARSE_FULL;
-
-    return 0;
-}
-
 static av_cold int dv_sdp_parse_fmtp_config(AVFormatContext *s,
                                             AVStream *stream,
                                             PayloadContext *dv_data,
@@ -161,7 +148,7 @@  RTPDynamicProtocolHandler ff_dv_dynamic_handler = {
     .enc_name         = "DV",
     .codec_type       = AVMEDIA_TYPE_VIDEO,
     .codec_id         = AV_CODEC_ID_DVVIDEO,
-    .init             = dv_init,
+    .need_parsing     = AVSTREAM_PARSE_FULL,
     .parse_sdp_a_line = dv_parse_sdp_line,
     .alloc            = dv_new_context,
     .free             = dv_free_context,
diff --git a/libavformat/rtpdec_h261.c b/libavformat/rtpdec_h261.c
index 4988300..5972a14 100644
--- a/libavformat/rtpdec_h261.c
+++ b/libavformat/rtpdec_h261.c
@@ -60,17 +60,6 @@  static av_cold void h261_free_context(PayloadContext *pl_ctx)
     av_free(pl_ctx);
 }
 
-static av_cold int h261_init(AVFormatContext *ctx, int st_index,
-                             PayloadContext *data)
-{
-    if (st_index < 0)
-        return 0;
-
-    ctx->streams[st_index]->need_parsing = AVSTREAM_PARSE_FULL;
-
-    return 0;
-}
-
 static int h261_handle_packet(AVFormatContext *ctx, PayloadContext *rtp_h261_ctx,
                               AVStream *st, AVPacket *pkt, uint32_t *timestamp,
                               const uint8_t *buf, int len, uint16_t seq,
@@ -194,7 +183,7 @@  RTPDynamicProtocolHandler ff_h261_dynamic_handler = {
     .enc_name          = "H261",
     .codec_type        = AVMEDIA_TYPE_VIDEO,
     .codec_id          = AV_CODEC_ID_H261,
-    .init              = h261_init,
+    .need_parsing      = AVSTREAM_PARSE_FULL,
     .alloc             = h261_new_context,
     .free              = h261_free_context,
     .parse_packet      = h261_handle_packet,
diff --git a/libavformat/rtpdec_h263.c b/libavformat/rtpdec_h263.c
index b371491..710cfd2 100644
--- a/libavformat/rtpdec_h263.c
+++ b/libavformat/rtpdec_h263.c
@@ -24,15 +24,6 @@ 
 #include "libavutil/attributes.h"
 #include "libavutil/intreadwrite.h"
 
-static av_cold int h263_init(AVFormatContext *ctx, int st_index,
-                             PayloadContext *data)
-{
-    if (st_index < 0)
-        return 0;
-    ctx->streams[st_index]->need_parsing = AVSTREAM_PARSE_FULL;
-    return 0;
-}
-
 int ff_h263_handle_packet(AVFormatContext *ctx, PayloadContext *data,
                           AVStream *st, AVPacket *pkt, uint32_t *timestamp,
                           const uint8_t *buf, int len, uint16_t seq, int flags)
@@ -102,7 +93,7 @@  RTPDynamicProtocolHandler ff_h263_1998_dynamic_handler = {
     .enc_name         = "H263-1998",
     .codec_type       = AVMEDIA_TYPE_VIDEO,
     .codec_id         = AV_CODEC_ID_H263,
-    .init             = h263_init,
+    .need_parsing     = AVSTREAM_PARSE_FULL,
     .parse_packet     = ff_h263_handle_packet,
 };
 
@@ -110,6 +101,6 @@  RTPDynamicProtocolHandler ff_h263_2000_dynamic_handler = {
     .enc_name         = "H263-2000",
     .codec_type       = AVMEDIA_TYPE_VIDEO,
     .codec_id         = AV_CODEC_ID_H263,
-    .init             = h263_init,
+    .need_parsing     = AVSTREAM_PARSE_FULL,
     .parse_packet     = ff_h263_handle_packet,
 };
diff --git a/libavformat/rtpdec_h263_rfc2190.c b/libavformat/rtpdec_h263_rfc2190.c
index d507ef7..e4e4e21 100644
--- a/libavformat/rtpdec_h263_rfc2190.c
+++ b/libavformat/rtpdec_h263_rfc2190.c
@@ -56,14 +56,6 @@  static void h263_free_context(PayloadContext *data)
     av_free(data);
 }
 
-static av_cold int h263_init(AVFormatContext *ctx, int st_index, PayloadContext *data)
-{
-    if (st_index < 0)
-        return 0;
-    ctx->streams[st_index]->need_parsing = AVSTREAM_PARSE_FULL;
-    return 0;
-}
-
 static int h263_handle_packet(AVFormatContext *ctx, PayloadContext *data,
                               AVStream *st, AVPacket *pkt, uint32_t *timestamp,
                               const uint8_t *buf, int len, uint16_t seq,
@@ -208,7 +200,7 @@  static int h263_handle_packet(AVFormatContext *ctx, PayloadContext *data,
 RTPDynamicProtocolHandler ff_h263_rfc2190_dynamic_handler = {
     .codec_type        = AVMEDIA_TYPE_VIDEO,
     .codec_id          = AV_CODEC_ID_H263,
-    .init              = h263_init,
+    .need_parsing      = AVSTREAM_PARSE_FULL,
     .parse_packet      = h263_handle_packet,
     .alloc             = h263_new_context,
     .free              = h263_free_context,
diff --git a/libavformat/rtpdec_h264.c b/libavformat/rtpdec_h264.c
index 94c802d..597e137 100644
--- a/libavformat/rtpdec_h264.c
+++ b/libavformat/rtpdec_h264.c
@@ -362,15 +362,6 @@  static void h264_free_context(PayloadContext *data)
     av_free(data);
 }
 
-static av_cold int h264_init(AVFormatContext *s, int st_index,
-                             PayloadContext *data)
-{
-    if (st_index < 0)
-        return 0;
-    s->streams[st_index]->need_parsing = AVSTREAM_PARSE_FULL;
-    return 0;
-}
-
 static int parse_h264_sdp_line(AVFormatContext *s, int st_index,
                                PayloadContext *h264_data, const char *line)
 {
@@ -416,7 +407,7 @@  RTPDynamicProtocolHandler ff_h264_dynamic_handler = {
     .enc_name         = "H264",
     .codec_type       = AVMEDIA_TYPE_VIDEO,
     .codec_id         = AV_CODEC_ID_H264,
-    .init             = h264_init,
+    .need_parsing     = AVSTREAM_PARSE_FULL,
     .parse_sdp_a_line = parse_h264_sdp_line,
     .alloc            = h264_new_context,
     .free             = h264_free_context,
diff --git a/libavformat/rtpdec_hevc.c b/libavformat/rtpdec_hevc.c
index 314ce4d..518cfa8 100644
--- a/libavformat/rtpdec_hevc.c
+++ b/libavformat/rtpdec_hevc.c
@@ -53,19 +53,6 @@  static av_cold void hevc_free_context(PayloadContext *data)
     av_free(data);
 }
 
-static av_cold int hevc_init(AVFormatContext *ctx, int st_index,
-                             PayloadContext *data)
-{
-    av_dlog(ctx, "hevc_init() for stream %d\n", st_index);
-
-    if (st_index < 0)
-        return 0;
-
-    ctx->streams[st_index]->need_parsing = AVSTREAM_PARSE_FULL;
-
-    return 0;
-}
-
 static av_cold int hevc_sdp_parse_fmtp_config(AVFormatContext *s,
                                               AVStream *stream,
                                               PayloadContext *hevc_data,
@@ -417,7 +404,7 @@  RTPDynamicProtocolHandler ff_hevc_dynamic_handler = {
     .enc_name         = "H265",
     .codec_type       = AVMEDIA_TYPE_VIDEO,
     .codec_id         = AV_CODEC_ID_HEVC,
-    .init             = hevc_init,
+    .need_parsing     = AVSTREAM_PARSE_FULL,
     .parse_sdp_a_line = hevc_parse_sdp_line,
     .alloc            = hevc_new_context,
     .free             = hevc_free_context,
diff --git a/libavformat/rtpdec_mpa_robust.c b/libavformat/rtpdec_mpa_robust.c
index ebf1b72..548718c 100644
--- a/libavformat/rtpdec_mpa_robust.c
+++ b/libavformat/rtpdec_mpa_robust.c
@@ -38,7 +38,6 @@  static av_cold int mpa_robust_init(AVFormatContext *ctx, int st_index,
 {
     if (st_index < 0)
         return 0;
-    ctx->streams[st_index]->need_parsing = AVSTREAM_PARSE_HEADERS;
     return 0;
 }
 
@@ -217,7 +216,7 @@  RTPDynamicProtocolHandler ff_mpeg_audio_robust_dynamic_handler = {
     .enc_name          = "mpa-robust",
     .codec_type        = AVMEDIA_TYPE_AUDIO,
     .codec_id          = AV_CODEC_ID_MP3ADU,
-    .init              = mpa_robust_init,
+    .need_parsing      = AVSTREAM_PARSE_HEADERS,
     .alloc             = mpa_robust_new_context,
     .free              = mpa_robust_free_context,
     .parse_packet      = mpa_robust_parse_packet,
diff --git a/libavformat/rtpdec_mpeg12.c b/libavformat/rtpdec_mpeg12.c
index b059fcf..2b884be 100644
--- a/libavformat/rtpdec_mpeg12.c
+++ b/libavformat/rtpdec_mpeg12.c
@@ -23,14 +23,6 @@ 
 #include "libavutil/intreadwrite.h"
 #include "rtpdec_formats.h"
 
-static av_cold int mpeg_init(AVFormatContext *ctx, int st_index, PayloadContext *data)
-{
-    if (st_index < 0)
-        return 0;
-    ctx->streams[st_index]->need_parsing = AVSTREAM_PARSE_FULL;
-    return 0;
-}
-
 static int mpeg_parse_packet(AVFormatContext *ctx, PayloadContext *data,
                              AVStream *st, AVPacket *pkt, uint32_t *timestamp,
                              const uint8_t *buf, int len, uint16_t seq,
@@ -59,7 +51,7 @@  static int mpeg_parse_packet(AVFormatContext *ctx, PayloadContext *data,
 RTPDynamicProtocolHandler ff_mpeg_audio_dynamic_handler = {
     .codec_type        = AVMEDIA_TYPE_AUDIO,
     .codec_id          = AV_CODEC_ID_MP3,
-    .init              = mpeg_init,
+    .need_parsing      = AVSTREAM_PARSE_FULL,
     .parse_packet      = mpeg_parse_packet,
     .static_payload_id = 14,
 };
@@ -67,7 +59,7 @@  RTPDynamicProtocolHandler ff_mpeg_audio_dynamic_handler = {
 RTPDynamicProtocolHandler ff_mpeg_video_dynamic_handler = {
     .codec_type        = AVMEDIA_TYPE_VIDEO,
     .codec_id          = AV_CODEC_ID_MPEG2VIDEO,
-    .init              = mpeg_init,
+    .need_parsing      = AVSTREAM_PARSE_FULL,
     .parse_packet      = mpeg_parse_packet,
     .static_payload_id = 32,
 };
diff --git a/libavformat/rtpdec_mpeg4.c b/libavformat/rtpdec_mpeg4.c
index 1b6a552..c449ea6 100644
--- a/libavformat/rtpdec_mpeg4.c
+++ b/libavformat/rtpdec_mpeg4.c
@@ -321,20 +321,11 @@  static int parse_sdp_line(AVFormatContext *s, int st_index,
     return 0;
 }
 
-static av_cold int init_video(AVFormatContext *s, int st_index,
-                              PayloadContext *data)
-{
-    if (st_index < 0)
-        return 0;
-    s->streams[st_index]->need_parsing = AVSTREAM_PARSE_FULL;
-    return 0;
-}
-
 RTPDynamicProtocolHandler ff_mp4v_es_dynamic_handler = {
     .enc_name           = "MP4V-ES",
     .codec_type         = AVMEDIA_TYPE_VIDEO,
     .codec_id           = AV_CODEC_ID_MPEG4,
-    .init               = init_video,
+    .need_parsing       = AVSTREAM_PARSE_FULL,
     .parse_sdp_a_line   = parse_sdp_line,
 };
 
diff --git a/libavformat/rtpdec_xiph.c b/libavformat/rtpdec_xiph.c
index c3385e4..ce3d591 100644
--- a/libavformat/rtpdec_xiph.c
+++ b/libavformat/rtpdec_xiph.c
@@ -71,15 +71,6 @@  static void xiph_free_context(PayloadContext * data)
     av_free(data);
 }
 
-static av_cold int xiph_vorbis_init(AVFormatContext *ctx, int st_index,
-                                    PayloadContext *data)
-{
-    if (st_index < 0)
-        return 0;
-    ctx->streams[st_index]->need_parsing = AVSTREAM_PARSE_HEADERS;
-    return 0;
-}
-
 
 static int xiph_handle_packet(AVFormatContext *ctx, PayloadContext *data,
                               AVStream *st, AVPacket *pkt, uint32_t *timestamp,
@@ -404,7 +395,7 @@  RTPDynamicProtocolHandler ff_vorbis_dynamic_handler = {
     .enc_name         = "vorbis",
     .codec_type       = AVMEDIA_TYPE_AUDIO,
     .codec_id         = AV_CODEC_ID_VORBIS,
-    .init             = xiph_vorbis_init,
+    .need_parsing     = AVSTREAM_PARSE_HEADERS,
     .parse_sdp_a_line = xiph_parse_sdp_line,
     .alloc            = xiph_new_context,
     .free             = xiph_free_context,