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 784590 - encoder: h264: Performance tuning for specific platforms
encoder: h264: Performance tuning for specific platforms
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gstreamer-vaapi
git master
Other Linux
: Normal enhancement
: 1.13.1
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2017-07-06 00:13 UTC by sreerenj
Modified: 2017-08-01 18:48 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
libs: utils_h264: Extend LevelLimit table with MinCR field (4.65 KB, patch)
2017-07-06 00:41 UTC, sreerenj
committed Details | Review
libs: encoder: h264: Add less restrictive compliance mode to reduce the coded buffer size (5.95 KB, patch)
2017-07-06 00:42 UTC, sreerenj
none Details | Review
libs: encoder: h264: Add less restrictive compliance mode to reduce the coded buffer size (5.97 KB, patch)
2017-07-19 19:05 UTC, sreerenj
committed Details | Review

Description sreerenj 2017-07-06 00:13:25 UTC
Some of the small core Intel platform (eg: APL) doesn't have LLC and the driver using cflush to ensure data consistency which seems to be expensive, but we can still limit the impact by reducing the original size of coded-buffer from middleware. 

We always have to pre-calculate the coded-buffer-size and later driver copy the encoded data to this pre-allocated buffer.Currently, we pre-calculate buffer size based on worst case scenario. Even if we use the specification LevelLimits it will end up with a maximum possible value.

But we can do some optimization based on MinCR field in AnnexA which helps to reduce the buffer size.

This is not strictly following the specification. The idea is to add a new "compliance-mode" enum property to vaapih264enc. So that we can add other tweaks under this single property in future.
Comment 1 sreerenj 2017-07-06 00:41:38 UTC
Created attachment 354984 [details] [review]
libs: utils_h264: Extend LevelLimit table with MinCR field
Comment 2 sreerenj 2017-07-06 00:42:04 UTC
Created attachment 354985 [details] [review]
libs: encoder: h264: Add less restrictive compliance mode to reduce the coded buffer size
Comment 3 Víctor Manuel Jáquez Leal 2017-07-19 10:13:43 UTC
Review of attachment 354984 [details] [review]:

lgtm
Comment 4 Víctor Manuel Jáquez Leal 2017-07-19 10:16:45 UTC
Review of attachment 354985 [details] [review]:

::: gst-libs/gst/vaapi/gstvaapiencoder_h264.c
@@ +98,3 @@
+      {GST_VAAPI_ENCODER_H264_COMPLIANCE_MODE_RESTRICT_CODED_BUFFER_ALLOC,
+            "Restict the allocation size of coded-buffer",
+          "restrict-buf-alloc"}

the array needs a null structure
{0,NULL,NULL}

otherwise the code might crash

@@ +2925,3 @@
+  if (encoder->compliance_mode ==
+      GST_VAAPI_ENCODER_H264_COMPLIANCE_MODE_RESTRICT_CODED_BUFFER_ALLOC)
+    base_encoder->codedbuf_size /= encoder->min_cr;

I don't like having a property for this. 

would be possible to query the driver to know if this is required, avoiding the property?
Comment 5 sreerenj 2017-07-19 18:00:21 UTC
(In reply to Víctor Manuel Jáquez Leal from comment #4)
> Review of attachment 354985 [details] [review] [review]:
> 
> ::: gst-libs/gst/vaapi/gstvaapiencoder_h264.c
> @@ +98,3 @@
> +      {GST_VAAPI_ENCODER_H264_COMPLIANCE_MODE_RESTRICT_CODED_BUFFER_ALLOC,
> +            "Restict the allocation size of coded-buffer",
> +          "restrict-buf-alloc"}
> 
> the array needs a null structure
> {0,NULL,NULL}
> 
> otherwise the code might crash

I will fix it, thanks!

> 
> @@ +2925,3 @@
> +  if (encoder->compliance_mode ==
> +      GST_VAAPI_ENCODER_H264_COMPLIANCE_MODE_RESTRICT_CODED_BUFFER_ALLOC)
> +    base_encoder->codedbuf_size /= encoder->min_cr;
> 
> I don't like having a property for this. 

I too, but I can't find a better way to do this.

A property named "restrict-coded-buf-size" is another option. But we may add more of this kind of properties in future, specific to some hardware for eg. May be it is better to consolidate everything under a single property "compliance-mode" like we did for vaapih264dec?

> would be possible to query the driver to know if this is required, avoiding
> the property?

Not possible. This is not related with libva at all. In theory, using the min-compression-ratio outside of the equations provided in the spec is not correct, but we are only considering intel-vaapi-driver here and which should work with the new size calculation. So in nutshell, it is a *tweak* which we don't want to enable by default, but on the other hand, many of the customers don't care about specification/implementation as long as they get better performance :). Software like yami is allocating even lower size for coded-buffer which is something I don't want to do. So enabling this under a property seems to be a fair compromise IMHO.
Comment 6 sreerenj 2017-07-19 19:05:39 UTC
Created attachment 355978 [details] [review]
libs: encoder: h264: Add less restrictive compliance mode to reduce the coded buffer size
Comment 7 Víctor Manuel Jáquez Leal 2017-08-01 12:46:11 UTC
Attachment 354984 [details] pushed as f775bbf - libs: utils_h264: Extend LevelLimit table with MinCR field
Attachment 355978 [details] pushed as aa35439 - libs: encoder: h264: Add uncompliant mode reducing coded buffer size (modified a bit the commit log)
Comment 8 sreerenj 2017-08-01 18:48:25 UTC
Thanks !