After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 727483 - v4l2sink: Keep aspect ratio when device scale
v4l2sink: Keep aspect ratio when device scale
Status: RESOLVED OBSOLETE
Product: GStreamer
Classification: Platform
Component: gst-plugins-good
unspecified
Other Linux
: Normal enhancement
: git master
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2014-04-02 09:20 UTC by Aurélien Zanelli
Modified: 2018-11-03 14:52 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
v4l2sink: Keep aspect ratio when device scale (9.02 KB, patch)
2014-04-02 09:20 UTC, Aurélien Zanelli
none Details | Review
v4l2: Add a function to probe device cropping capability (6.03 KB, patch)
2014-07-31 13:46 UTC, Aurélien Zanelli
none Details | Review
v4l2: check if the device can scale (4.07 KB, patch)
2014-07-31 13:54 UTC, Aurélien Zanelli
needs-work Details | Review
v4l2sink: keep aspect ratio when device scale (4.32 KB, patch)
2014-07-31 13:57 UTC, Aurélien Zanelli
none Details | Review
v4l2: Add a function to probe device cropping capability (6.15 KB, patch)
2014-09-03 17:22 UTC, Aurélien Zanelli
none Details | Review
v4l2: check if the device can scale (4.58 KB, patch)
2014-09-03 17:24 UTC, Aurélien Zanelli
none Details | Review
v4l2sink: keep aspect ratio when device scale (4.30 KB, patch)
2014-09-03 17:24 UTC, Aurélien Zanelli
reviewed Details | Review

Description Aurélien Zanelli 2014-04-02 09:20:21 UTC
Created attachment 273456 [details] [review]
v4l2sink: Keep aspect ratio when device scale

It seems to be the responsibility of the application to ensure that aspect ratio is preserved. The device aspect ratio is constant within a standard. I attached a preliminary work which preserve display aspect ratio of the video. It has been written on 1.2 branch but it should apply on master with a little conflict in v4l2_calls.c

Here is the main idea of the solution:
First we determine if device can scale using VIDIOC_CROPCAP ioctl by checking if cropcap.bounds and cropcaps.defrect differs. If so we doesn't want to force PAR in caps.
Then, when we know video information and if scaling is supported, we determine the target rectangle and we set it with CROP ioctl.

This work is not complete since is conflicting with cropping property (crop_*) of v4l2sink element and it scale into output device bounds instead of user-defined display windows.
However before working further on this topic, I think it's better to have comments and remarks.

Regards
Comment 1 Nicolas Dufresne (ndufresne) 2014-04-02 12:15:43 UTC
Thanks for looking in to this, I'll have a look and provide feedback as soon as possible.
Comment 2 Nicolas Dufresne (ndufresne) 2014-04-19 02:42:13 UTC
I've given this a quick look, and it looks pretty neat. I'll definitely consider as soon as I have more time. Thanks for this works.
Comment 3 Aurélien Zanelli 2014-07-31 13:46:33 UTC
Created attachment 282138 [details] [review]
v4l2: Add a function to probe device cropping capability

Since the v4l2 plugins has changed, I updated my previous patch, split it and improve it.

Here is the first patch. It adds a function to probe device cropping capabilities.
The idea is to get cropcap and try to set a crop window using S_CROP. If underlying device doesn't support crop, it should returns EINVAL. See Exemple 1.11 in http://www.linuxtv.org/downloads/v4l-dvb-apis/crop.html.
Comment 4 Aurélien Zanelli 2014-07-31 13:54:07 UTC
Created attachment 282139 [details] [review]
v4l2: check if the device can scale

This patch intends to check if the device have scaling capabilities.
The main idea is to check if crop window can be different from the format.

Currently, I only test it with a device which support scaling, I will have a device without scaling support, but I don't know why. So test with a device with no scaler should be done.
Comment 5 Aurélien Zanelli 2014-07-31 13:57:31 UTC
Created attachment 282140 [details] [review]
v4l2sink: keep aspect ratio when device scale

This patch is a proposal to keep display aspect ratio when rendering a video.

I think an enhancement could be to add a new property set in v4l2sink, or replace crop-* properties, to define a display window.
Comment 6 Aurélien Zanelli 2014-08-28 15:57:51 UTC
Review of attachment 282139 [details] [review]:

This patch is not complete because if device supports overlay, I think the crop window should be tested against the overlay window rather than the format.

::: sys/v4l2/v4l2_calls.c
@@ +1178,3 @@
   v4l2object->vcropcap = cropcap;
   v4l2object->can_crop = TRUE;
+

format.type is not set

@@ +1200,3 @@
+    if (format.fmt.pix_mp.width != crop.c.width ||
+        format.fmt.pix_mp.height != crop.c.height)
+      v4l2object->can_scale = FALSE;

Mistake, should be v4l2object->can_scale = TRUE
Comment 7 Aurélien Zanelli 2014-09-03 17:22:46 UTC
Created attachment 285270 [details] [review]
v4l2: Add a function to probe device cropping capability

Add a debug message and rebase against master
Comment 8 Aurélien Zanelli 2014-09-03 17:24:08 UTC
Created attachment 285271 [details] [review]
v4l2: check if the device can scale

Now we check crop window against overlay windows if device support overlay.
It has also been rebased against master and tested with a device with no scaler.
Comment 9 Aurélien Zanelli 2014-09-03 17:24:47 UTC
Created attachment 285272 [details] [review]
v4l2sink: keep aspect ratio when device scale

Rebased against master
Comment 10 Nicolas Dufresne (ndufresne) 2015-01-25 16:36:54 UTC
Review of attachment 285272 [details] [review]:

Just checking, do we keep aspect ratio by default with that path ?

::: sys/v4l2/gstv4l2sink.c
@@ +586,3 @@
   /* TODO: videosink width/height should be scaled according to
    * pixel-aspect-ratio
    */

Can't this comment be removed now ? If not why ?
Comment 11 Aurélien Zanelli 2015-01-26 10:15:08 UTC
(In reply to comment #10)
> Review of attachment 285272 [details] [review]:
> 
> Just checking, do we keep aspect ratio by default with that path ?
Yes unless we can't keep the DAR at all. Which is bad since we have a property to say if we want to keep aspect or not: 'force-aspect-ratio'. :)
Maybe, before doing anything, we should check it.

> 
> ::: sys/v4l2/gstv4l2sink.c
> @@ +586,3 @@
>    /* TODO: videosink width/height should be scaled according to
>     * pixel-aspect-ratio
>     */
> 
> Can't this comment be removed now ? If not why ?

At the moment I wrote the patch, I think I didn't know what to do with it. And since i let v4l2sink video_width and video_height, which are unscaled value, i let the comment. But according to it, I should have set the scaled value.

By the way, what is the purpose of videosink width and height attributes ?
Comment 12 Nicolas Dufresne (ndufresne) 2015-01-26 14:26:03 UTC
Hmm, the code after this comment is a no-op:

  GST_VIDEO_SINK_WIDTH (v4l2sink) = v4l2sink->video_width;
  GST_VIDEO_SINK_HEIGHT (v4l2sink) = v4l2sink->video_height;

Is the same as:

  v4l2sink->video_width = v4l2sink->video_width;
  v4l2sink->video_height =  v4l2sink->video_height;

These though are the width and height of the stream. I must say, this seems bit messy, it's likely the porting was done wrong due to lack of testing.
Comment 13 GStreamer system administrator 2018-11-03 14:52:08 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/issues/112.