[FFmpeg-devel] avcodec/mediacodecdec: propagate SAR to h/w frames

Submitted by Aman Gupta on March 19, 2018, 11:33 p.m.

Details

Message ID 20180319233343.19909-1-ffmpeg@tmm1.net
State New
Headers show

Commit Message

Aman Gupta March 19, 2018, 11:33 p.m.
From: Aman Gupta <aman@tmm1.net>

Allows consumers who are converting hardware buffers
to OpenGL textures to render the frames at the intended
display resolution.
---
 libavcodec/mediacodecdec_common.c | 13 +++++++++++++
 libavcodec/mediacodecdec_common.h |  2 ++
 2 files changed, 15 insertions(+)

Comments

Derek Buitenhuis March 20, 2018, 2:16 p.m.
On 3/19/2018 11:33 PM, Aman Gupta wrote:
> From: Aman Gupta <aman@tmm1.net>
> 
> Allows consumers who are converting hardware buffers
> to OpenGL textures to render the frames at the intended
> display resolution.
> ---
>  libavcodec/mediacodecdec_common.c | 13 +++++++++++++
>  libavcodec/mediacodecdec_common.h |  2 ++
>  2 files changed, 15 insertions(+)

Concept sounds reasonable to me.

> +    } else {
> +        ff_set_sar(avctx, (AVRational){0,1});
> +    }

Wouldn't it be better to use the codecpar or avctx SAR 
here? Anyone trying to do per-frame correct display is
going to hit trouble with a 0:1 SAR...

- Derek
Aman Gupta March 20, 2018, 6:44 p.m.
On Tue, Mar 20, 2018 at 7:16 AM, Derek Buitenhuis <
derek.buitenhuis@gmail.com> wrote:

> On 3/19/2018 11:33 PM, Aman Gupta wrote:
> > From: Aman Gupta <aman@tmm1.net>
> >
> > Allows consumers who are converting hardware buffers
> > to OpenGL textures to render the frames at the intended
> > display resolution.
> > ---
> >  libavcodec/mediacodecdec_common.c | 13 +++++++++++++
> >  libavcodec/mediacodecdec_common.h |  2 ++
> >  2 files changed, 15 insertions(+)
>
> Concept sounds reasonable to me.
>
> > +    } else {
> > +        ff_set_sar(avctx, (AVRational){0,1});
> > +    }
>
> Wouldn't it be better to use the codecpar or avctx SAR
> here? Anyone trying to do per-frame correct display is
> going to hit trouble with a 0:1 SAR...
>

My intention was to set it to the default value, which I think is actually
0,0

How can I access codecpar here?

Aman


>
> - Derek
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
Aman Gupta March 20, 2018, 7:06 p.m.
On Tue, Mar 20, 2018 at 11:44 AM, Aman Gupta <ffmpeg@tmm1.net> wrote:

>
>
> On Tue, Mar 20, 2018 at 7:16 AM, Derek Buitenhuis <
> derek.buitenhuis@gmail.com> wrote:
>
>> On 3/19/2018 11:33 PM, Aman Gupta wrote:
>> > From: Aman Gupta <aman@tmm1.net>
>> >
>> > Allows consumers who are converting hardware buffers
>> > to OpenGL textures to render the frames at the intended
>> > display resolution.
>> > ---
>> >  libavcodec/mediacodecdec_common.c | 13 +++++++++++++
>> >  libavcodec/mediacodecdec_common.h |  2 ++
>> >  2 files changed, 15 insertions(+)
>>
>> Concept sounds reasonable to me.
>>
>> > +    } else {
>> > +        ff_set_sar(avctx, (AVRational){0,1});
>> > +    }
>>
>> Wouldn't it be better to use the codecpar or avctx SAR
>> here? Anyone trying to do per-frame correct display is
>> going to hit trouble with a 0:1 SAR...
>>
>
> My intention was to set it to the default value, which I think is actually
> 0,0
>
> How can I access codecpar here?
>

I see, it seems this whole if/else is unnecessary. The avctx sar is already
set correctly, and the only thing required was to propagate it into the
frames with the earlier chunk in the patch.

I guess I could leave just the if statement, to override the sar when
display-width/height is available (which is only on newer Android OS
versions).

Aman


>
> Aman
>
>
>>
>> - Derek
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>
>
Derek Buitenhuis March 20, 2018, 7:20 p.m.
On 3/20/2018 7:06 PM, Aman Gupta wrote:
> I guess I could leave just the if statement, to override the sar when
> display-width/height is available (which is only on newer Android OS
> versions).

Seems reasonable to me.

- Derek
Aman Gupta March 21, 2018, 4:11 a.m.
On Tue, Mar 20, 2018 at 12:21 PM Derek Buitenhuis <
derek.buitenhuis@gmail.com> wrote:

> On 3/20/2018 7:06 PM, Aman Gupta wrote:
> > I guess I could leave just the if statement, to override the sar when
> > display-width/height is available (which is only on newer Android OS
> > versions).
>
> Seems reasonable to me.


Applied. Thanks a lot for the review!

Aman


>
> - Derek
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

Patch hide | download patch | download mbox

diff --git a/libavcodec/mediacodecdec_common.c b/libavcodec/mediacodecdec_common.c
index 635ee73486..437bffcd7c 100644
--- a/libavcodec/mediacodecdec_common.c
+++ b/libavcodec/mediacodecdec_common.c
@@ -205,6 +205,7 @@  static int mediacodec_wrap_hw_buffer(AVCodecContext *avctx,
     frame->width = avctx->width;
     frame->height = avctx->height;
     frame->format = avctx->pix_fmt;
+    frame->sample_aspect_ratio = avctx->sample_aspect_ratio;
 
     if (avctx->pkt_timebase.num && avctx->pkt_timebase.den) {
         frame->pts = av_rescale_q(info->presentationTimeUs,
@@ -414,6 +415,18 @@  static int mediacodec_dec_parse_format(AVCodecContext *avctx, MediaCodecDecConte
     width = s->crop_right + 1 - s->crop_left;
     height = s->crop_bottom + 1 - s->crop_top;
 
+    AMEDIAFORMAT_GET_INT32(s->display_width,  "display-width",  0);
+    AMEDIAFORMAT_GET_INT32(s->display_height, "display-height", 0);
+
+    if (s->display_width && s->display_height) {
+        AVRational sar = av_div_q(
+            (AVRational){ s->display_width, s->display_height },
+            (AVRational){ width, height });
+        ff_set_sar(avctx, sar);
+    } else {
+        ff_set_sar(avctx, (AVRational){0,1});
+    }
+
     av_log(avctx, AV_LOG_INFO,
         "Output crop parameters top=%d bottom=%d left=%d right=%d, "
         "resulting dimensions width=%d height=%d\n",
diff --git a/libavcodec/mediacodecdec_common.h b/libavcodec/mediacodecdec_common.h
index 4f3b4f9fa5..023d4c5fa7 100644
--- a/libavcodec/mediacodecdec_common.h
+++ b/libavcodec/mediacodecdec_common.h
@@ -61,6 +61,8 @@  typedef struct MediaCodecDecContext {
     int crop_bottom;
     int crop_left;
     int crop_right;
+    int display_width;
+    int display_height;
 
     uint64_t output_buffer_count;