<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>214689</bug_id>
          
          <creation_ts>2020-07-23 09:23:31 -0700</creation_ts>
          <short_desc>getUserMedia aspectRatio overconstrained in portrait orientation</short_desc>
          <delta_ts>2020-07-24 09:30:01 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebRTC</component>
          <version>Safari 13</version>
          <rep_platform>iPhone / iPad</rep_platform>
          <op_sys>iOS 13</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Kyle Dunn">kpd400</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>webkit-bug-importer</cc>
    
    <cc>youennf</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1674249</commentid>
    <comment_count>0</comment_count>
      <attachid>405046</attachid>
    <who name="Kyle Dunn">kpd400</who>
    <bug_when>2020-07-23 09:23:31 -0700</bug_when>
    <thetext>Created attachment 405046
Demo of aspect ratio bug in portrait mode

I have a use case that requires me to get a 4:3 video from getUserMedia on iPad / iOS devices. I can do this reliably when the device is in landscape by setting the `aspectRatio` constraint to 4/3 but when the device is in portrait (thus requiring a relative 3/4 aspect ratio) an `OverconstrainedError: Invalid constraint` error is thrown.

If I specify exact dimensions, e.g. 640x480 in landscape or 480x640 in portrait, I am able to obtain a 4:3 video regardless of orientation but this requires exact dimensions which is problematic when trying to obtain a maximum camera resolution that may or may not be supported by the device.

I am using an iPad Pro (12.9-inch) (3rd generation) on iPadOS 13.6 and I have attached a demo to reproduce the issue when tested on a mobile device in portrait mode.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1674459</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2020-07-23 16:34:59 -0700</bug_when>
    <thetext>&lt;rdar://problem/66020174&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1674628</commentid>
    <comment_count>2</comment_count>
    <who name="youenn fablet">youennf</who>
    <bug_when>2020-07-24 07:23:33 -0700</bug_when>
    <thetext>I confirmed the issue.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1674632</commentid>
    <comment_count>3</comment_count>
    <who name="youenn fablet">youennf</who>
    <bug_when>2020-07-24 07:34:13 -0700</bug_when>
    <thetext>In general, I would recommend to use ideal constraints for getUserMedia.
Then, you can check the results and use applyConstraints to resize at will.

Would the following workaround work for you:
- Call getUserMedia with aspectRatio 4/3 as ideal constraints whatever the orientation.
- Use applyConstraints to flip height and width in case of portrait mode.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1674634</commentid>
    <comment_count>4</comment_count>
    <who name="youenn fablet">youennf</who>
    <bug_when>2020-07-24 07:39:53 -0700</bug_when>
    <thetext>In case we can resize frames at will, we could also potentially have arbitrary aspect ratio as well.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1674664</commentid>
    <comment_count>5</comment_count>
      <attachid>405149</attachid>
    <who name="Kyle Dunn">kpd400</who>
    <bug_when>2020-07-24 09:03:15 -0700</bug_when>
    <thetext>Created attachment 405149
applyConstraint Workaround Test

(In reply to youenn fablet from comment #3)
&gt; In general, I would recommend to use ideal constraints for getUserMedia.
&gt; Then, you can check the results and use applyConstraints to resize at will.
&gt; 
&gt; Would the following workaround work for you:
&gt; - Call getUserMedia with aspectRatio 4/3 as ideal constraints whatever the
&gt; orientation.
&gt; - Use applyConstraints to flip height and width in case of portrait mode.

Thanks for the quick response/workaround. I&apos;m seeing odd behavior when initially applying constraints in portrait mode - I have to flip the height/width with applyConstraints multiple times before it actually crops the video. This does not seem to be an issue in landscape. The dimensions set with applyConstraints do get reflected in getSettings, but only reliably crop the video after &quot;flipping&quot; 3-5 times. However, once the video is reliably cropping it works exactly as expected and would be an acceptable workaround. 

A new demo with this workaround is attached.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1674675</commentid>
    <comment_count>6</comment_count>
    <who name="youenn fablet">youennf</who>
    <bug_when>2020-07-24 09:18:22 -0700</bug_when>
    <thetext>https://bugs.webkit.org/show_bug.cgi?id=214741 should allow to set an aspect ratio of 3/4.
Let&apos;s keep this bug open until we get a good idea of how we want to handle rotation.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1674677</commentid>
    <comment_count>7</comment_count>
    <who name="youenn fablet">youennf</who>
    <bug_when>2020-07-24 09:19:34 -0700</bug_when>
    <thetext>(In reply to youenn fablet from comment #6)
&gt; https://bugs.webkit.org/show_bug.cgi?id=214741 should allow to set an aspect
&gt; ratio of 3/4.
&gt; Let&apos;s keep this bug open until we get a good idea of how we want to handle
&gt; rotation.

And fix the potential bug of needing to call applyConstraints multiple times.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1674680</commentid>
    <comment_count>8</comment_count>
    <who name="Kyle Dunn">kpd400</who>
    <bug_when>2020-07-24 09:22:35 -0700</bug_when>
    <thetext>(In reply to youenn fablet from comment #7)
&gt; (In reply to youenn fablet from comment #6)
&gt; &gt; https://bugs.webkit.org/show_bug.cgi?id=214741 should allow to set an aspect
&gt; &gt; ratio of 3/4.
&gt; &gt; Let&apos;s keep this bug open until we get a good idea of how we want to handle
&gt; &gt; rotation.
&gt; 
&gt; And fix the potential bug of needing to call applyConstraints multiple times.

Awesome, thanks Youenn!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1674681</commentid>
    <comment_count>9</comment_count>
    <who name="youenn fablet">youennf</who>
    <bug_when>2020-07-24 09:23:18 -0700</bug_when>
    <thetext>&gt; crop the video after &quot;flipping&quot; 3-5 times. However, once the video is

Doing your test, it seems to work for me after clicking 2 times.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1674692</commentid>
    <comment_count>10</comment_count>
    <who name="Kyle Dunn">kpd400</who>
    <bug_when>2020-07-24 09:30:01 -0700</bug_when>
    <thetext>(In reply to youenn fablet from comment #9)
&gt; &gt; crop the video after &quot;flipping&quot; 3-5 times. However, once the video is
&gt; 
&gt; Doing your test, it seems to work for me after clicking 2 times.

I&apos;m seeing the following in portrait:

Click 1  - No change
Click 2  - Crops to 4:3
Click 3  - No change
Click 4  - No change
Click 5+ - Always crops, when in 3:4 aspect ratio the video is &quot;zoomed&quot; compared to the original 3:4 video.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>405046</attachid>
            <date>2020-07-23 09:23:31 -0700</date>
            <delta_ts>2020-07-23 09:23:31 -0700</delta_ts>
            <desc>Demo of aspect ratio bug in portrait mode</desc>
            <filename>aspect_ratio_repro.html</filename>
            <type>text/html</type>
            <size>1978</size>
            <attacher name="Kyle Dunn">kpd400</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+CjxodG1sPgoKPGhlYWQ+CiAgPG1ldGEgY2hhcnNldD0idXRmLTgiPgog
IDx0aXRsZT5TYWZhcmkgQXNwZWN0UmF0aW8gQ29uc3RyYWludCBQb3J0cmFpdCBCdWc8L3RpdGxl
Pgo8L2hlYWQ+Cgo8Ym9keT4KICA8ZGl2IGlkPSJ3cmFwcGVyIj4KICAgIDxkaXYgaWQ9ImNvbnRy
b2xzIj4KICAgICAgPGJ1dHRvbiBpZD0iZXhhY3QtZGltZW5zaW9ucyI+UmVxdWVzdCBFeGFjdCBE
aW1lbnNpb25zPC9idXR0b24+CiAgICAgIDxidXR0b24gaWQ9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ID0gJycKICAgICAgICB2aWRlby5zcmNPYmplY3QgPSBzdHJlYW0KICAg
ICAgfQogICAgfSkKICA8L3NjcmlwdD4KPC9ib2R5PgoKPC9odG1sPg==
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>405149</attachid>
            <date>2020-07-24 09:03:15 -0700</date>
            <delta_ts>2020-07-24 09:03:15 -0700</delta_ts>
            <desc>applyConstraint Workaround Test</desc>
            <filename>apply_constraints_workaround.html</filename>
            <type>text/html</type>
            <size>2201</size>
            <attacher name="Kyle Dunn">kpd400</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+CjxodG1sPgoKPGhlYWQ+CiAgPG1ldGEgY2hhcnNldD0idXRmLTgiPgog
IDx0aXRsZT5TYWZhcmkgQXNwZWN0UmF0aW8gQXBwbHkgQ29uc3RyYWludCBQb3J0cmFpdCBXb3Jr
YXJvdW5kPC90aXRsZT4KPC9oZWFkPgoKPGJvZHk+CiAgPGRpdiBpZD0id3JhcHBlciI+CiAgICA8
ZGl2IGlkPSJjb250cm9scyI+CiAgICAgIDxidXR0b24gaWQ9InRvZ2dsZS12aWRlbyI+U3RhcnQg
NDozIFZpZGVvPC9idXR0b24+CiAgICAgIDxidXR0b24gaWQ9ImZsaXAtdmlkZW8iIGRpc2FibGVk
PSJ0cnVlIj5BcHBseSBGbGlwcGVkIERpbWVuc2lvbnM8L2J1dHRvbj4KICAgIDwvZGl2PgogICAg
PHAgaWQ9Im1lc3NhZ2UiPjwvcD4KICAgIDxkaXYgaWQ9ImNvbnRhaW5lciI+CiAgICAgIDx2aWRl
byBpZD0idmlkZW8iIHBsYXlzaW5saW5lPSJ0cnVlIiBhdXRvcGxheT0idHJ1ZSI+PC9jYW52YXM+
CiAgICA8L2Rpdj4KICA8L2Rpdj4KCiAgPHNjcmlwdD4KICAgIGNvbnN0IHZpZGVvID0gZG9jdW1l
bnQuZ2V0RWxlbWVudEJ5SWQoJ3ZpZGVvJykK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