diff mbox series

[FFmpeg-devel,5/8] avformat/rtpdec_rfc4175: add support for exactframerate

Message ID 1633515251-5156-5-git-send-email-lance.lmwang@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/8] avcodec/bitpacked: check av_buffer_ref result | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Lance Wang Oct. 6, 2021, 10:14 a.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavformat/rtpdec_rfc4175.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Comments

Andreas Rheinhardt Oct. 11, 2021, 3 p.m. UTC | #1
lance.lmwang@gmail.com:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libavformat/rtpdec_rfc4175.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/libavformat/rtpdec_rfc4175.c b/libavformat/rtpdec_rfc4175.c
> index 46d30ed..367567d 100644
> --- a/libavformat/rtpdec_rfc4175.c
> +++ b/libavformat/rtpdec_rfc4175.c
> @@ -25,9 +25,11 @@
>  #include "rtpdec_formats.h"
>  #include "libavutil/avstring.h"
>  #include "libavutil/pixdesc.h"
> +#include "libavutil/parseutils.h"
>  
>  struct PayloadContext {
>      char *sampling;
> +    char *framerate;
>      int depth;
>      int width;
>      int height;
> @@ -45,6 +47,7 @@ static int rfc4175_parse_format(AVStream *stream, PayloadContext *data)
>      enum AVPixelFormat pixfmt;
>      int tag;
>      const AVPixFmtDescriptor *desc;
> +    AVRational framerate;
>  
>      if (!strncmp(data->sampling, "YCbCr-4:2:2", 11)) {
>          tag = MKTAG('U', 'Y', 'V', 'Y');
> @@ -69,6 +72,14 @@ static int rfc4175_parse_format(AVStream *stream, PayloadContext *data)
>      stream->codecpar->bits_per_coded_sample = av_get_bits_per_pixel(desc);
>      data->frame_size = data->width * data->height * data->pgroup / data->xinc;
>  
> +    if (data->framerate) {
> +        if (av_parse_video_rate(&framerate, data->framerate) < 0)
> +            return AVERROR(EINVAL);
> +        stream->avg_frame_rate = framerate;
> +        if (framerate.den)
> +            stream->codecpar->bit_rate = data->frame_size * av_q2d(framerate) * 8;
> +    }
> +
>      return 0;
>  }
>  
> @@ -84,6 +95,8 @@ static int rfc4175_parse_fmtp(AVFormatContext *s, AVStream *stream,
>          data->sampling = av_strdup(value);
>      else if (!strncmp(attr, "depth", 5))
>          data->depth = atoi(value);
> +    else if (!strncmp(attr, "exactframerate", 14))
> +        data->framerate = av_strdup(value);
>  
>      return 0;
>  }
> @@ -112,6 +125,7 @@ static int rfc4175_parse_sdp_line(AVFormatContext *s, int st_index,
>  
>          ret = rfc4175_parse_format(stream, data);
>          av_freep(&data->sampling);
> +        av_freep(&data->framerate);
>  
>          return ret;
>      }
> 

Why the (unchecked!) allocation of a temporary string if you only want
the number anyway?

- Andreas
Lance Wang Oct. 11, 2021, 3:12 p.m. UTC | #2
On Mon, Oct 11, 2021 at 05:00:29PM +0200, Andreas Rheinhardt wrote:
> lance.lmwang@gmail.com:
> > From: Limin Wang <lance.lmwang@gmail.com>
> > 
> > Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> > ---
> >  libavformat/rtpdec_rfc4175.c | 14 ++++++++++++++
> >  1 file changed, 14 insertions(+)
> > 
> > diff --git a/libavformat/rtpdec_rfc4175.c b/libavformat/rtpdec_rfc4175.c
> > index 46d30ed..367567d 100644
> > --- a/libavformat/rtpdec_rfc4175.c
> > +++ b/libavformat/rtpdec_rfc4175.c
> > @@ -25,9 +25,11 @@
> >  #include "rtpdec_formats.h"
> >  #include "libavutil/avstring.h"
> >  #include "libavutil/pixdesc.h"
> > +#include "libavutil/parseutils.h"
> >  
> >  struct PayloadContext {
> >      char *sampling;
> > +    char *framerate;
> >      int depth;
> >      int width;
> >      int height;
> > @@ -45,6 +47,7 @@ static int rfc4175_parse_format(AVStream *stream, PayloadContext *data)
> >      enum AVPixelFormat pixfmt;
> >      int tag;
> >      const AVPixFmtDescriptor *desc;
> > +    AVRational framerate;
> >  
> >      if (!strncmp(data->sampling, "YCbCr-4:2:2", 11)) {
> >          tag = MKTAG('U', 'Y', 'V', 'Y');
> > @@ -69,6 +72,14 @@ static int rfc4175_parse_format(AVStream *stream, PayloadContext *data)
> >      stream->codecpar->bits_per_coded_sample = av_get_bits_per_pixel(desc);
> >      data->frame_size = data->width * data->height * data->pgroup / data->xinc;
> >  
> > +    if (data->framerate) {
> > +        if (av_parse_video_rate(&framerate, data->framerate) < 0)
> > +            return AVERROR(EINVAL);
> > +        stream->avg_frame_rate = framerate;
> > +        if (framerate.den)
> > +            stream->codecpar->bit_rate = data->frame_size * av_q2d(framerate) * 8;
> > +    }
> > +
> >      return 0;
> >  }
> >  
> > @@ -84,6 +95,8 @@ static int rfc4175_parse_fmtp(AVFormatContext *s, AVStream *stream,
> >          data->sampling = av_strdup(value);
> >      else if (!strncmp(attr, "depth", 5))
> >          data->depth = atoi(value);
> > +    else if (!strncmp(attr, "exactframerate", 14))
> > +        data->framerate = av_strdup(value);
> >  
> >      return 0;
> >  }
> > @@ -112,6 +125,7 @@ static int rfc4175_parse_sdp_line(AVFormatContext *s, int st_index,
> >  
> >          ret = rfc4175_parse_format(stream, data);
> >          av_freep(&data->sampling);
> > +        av_freep(&data->framerate);
> >  
> >          return ret;
> >      }
> > 
> 
> Why the (unchecked!) allocation of a temporary string if you only want
> the number anyway?

I'm just following the same style for sampling, but I can change to parse the frame rate when
parsing fmtp string to save the temporary string allocation if you prefer to. 

> 
> - Andreas
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavformat/rtpdec_rfc4175.c b/libavformat/rtpdec_rfc4175.c
index 46d30ed..367567d 100644
--- a/libavformat/rtpdec_rfc4175.c
+++ b/libavformat/rtpdec_rfc4175.c
@@ -25,9 +25,11 @@ 
 #include "rtpdec_formats.h"
 #include "libavutil/avstring.h"
 #include "libavutil/pixdesc.h"
+#include "libavutil/parseutils.h"
 
 struct PayloadContext {
     char *sampling;
+    char *framerate;
     int depth;
     int width;
     int height;
@@ -45,6 +47,7 @@  static int rfc4175_parse_format(AVStream *stream, PayloadContext *data)
     enum AVPixelFormat pixfmt;
     int tag;
     const AVPixFmtDescriptor *desc;
+    AVRational framerate;
 
     if (!strncmp(data->sampling, "YCbCr-4:2:2", 11)) {
         tag = MKTAG('U', 'Y', 'V', 'Y');
@@ -69,6 +72,14 @@  static int rfc4175_parse_format(AVStream *stream, PayloadContext *data)
     stream->codecpar->bits_per_coded_sample = av_get_bits_per_pixel(desc);
     data->frame_size = data->width * data->height * data->pgroup / data->xinc;
 
+    if (data->framerate) {
+        if (av_parse_video_rate(&framerate, data->framerate) < 0)
+            return AVERROR(EINVAL);
+        stream->avg_frame_rate = framerate;
+        if (framerate.den)
+            stream->codecpar->bit_rate = data->frame_size * av_q2d(framerate) * 8;
+    }
+
     return 0;
 }
 
@@ -84,6 +95,8 @@  static int rfc4175_parse_fmtp(AVFormatContext *s, AVStream *stream,
         data->sampling = av_strdup(value);
     else if (!strncmp(attr, "depth", 5))
         data->depth = atoi(value);
+    else if (!strncmp(attr, "exactframerate", 14))
+        data->framerate = av_strdup(value);
 
     return 0;
 }
@@ -112,6 +125,7 @@  static int rfc4175_parse_sdp_line(AVFormatContext *s, int st_index,
 
         ret = rfc4175_parse_format(stream, data);
         av_freep(&data->sampling);
+        av_freep(&data->framerate);
 
         return ret;
     }