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 732533 - omxvideoenc: doesn't recover after aspect ratio change on RPI
omxvideoenc: doesn't recover after aspect ratio change on RPI
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-omx
1.2.0
Other Linux
: Normal normal
: 1.9.1
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2014-07-01 06:38 UTC by m][sko
Modified: 2016-07-06 09:14 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
omxenc reconfigure caps patch (17.38 KB, patch)
2014-07-07 00:06 UTC, m][sko
needs-work Details | Review
Patch to fix this problem on RPI (2.27 KB, patch)
2014-08-27 03:28 UTC, Peng Liu
needs-work Details | Review
Implement the hack flag GST_OMX_HACK_NO_COMPONENT_RECONFIGURE support for video encoder (3.47 KB, patch)
2014-08-27 19:27 UTC, Peng Liu
committed Details | Review
rpi setup video encoder aspect ratio (3.58 KB, patch)
2014-08-27 22:53 UTC, m][sko
needs-work Details | Review
demug log (34.92 KB, application/octet-stream)
2014-08-28 19:01 UTC, m][sko
  Details
rpi setup aspect ratio (2.27 KB, patch)
2014-08-31 20:35 UTC, m][sko
committed Details | Review

Description m][sko 2014-07-01 06:38:34 UTC
omxvideoenc don't recover after aspect ratio change on RPI
test file
http://www.mdragon.org/test_ar_problem2.ts


GST_DEBUG="*:1,multifilesink:0,omxvideoenc:0,h264parse:4,mpegtsmux:0,omxvideodec:0"
\
gst-launch-1.0 -v  uridecodebin
uri="http://www.mdragon.org/test_ar_problem2.ts" use-buffering=false name=demux
\
 ! "video/x-raw, format=I420" \
 ! omxh264enc target-bitrate=1000000 control-rate=1 inline-header=true
periodicty-idr=250 interval-intraframes=250 ! "video/x-h264, profile=high" \
 ! h264parse ! "video/x-h264, alignment=au" \
 ! mpegtsmux name=mux0 \
 ! filesink location="test_ar_problem2_out.ts" sync=true \
 demux. ! "audio/x-raw" ! fakesink \
 2>&1


pipeline simple hangup
Comment 1 Sebastian Dröge (slomo) 2014-07-02 12:38:00 UTC
Can you provide a debug log with GST_DEBUG=omx*:6 and also a backtrace of all threads when it hangs?
Comment 2 m][sko 2014-07-02 13:06:18 UTC
http://live.mdragon.org/debug.log

Application don't crash
omxvideoenc simple stop after aspect ratio change
Comment 3 Sebastian Dröge (slomo) 2014-07-02 13:47:37 UTC
Thanks
Comment 4 m][sko 2014-07-07 00:06:44 UTC
Created attachment 280015 [details] [review]
omxenc reconfigure caps patch

I fixed flushing problem
but it still don't work on RPI(I don't have any other device) without
no-component-reconfigure

I rewrote some code base on decoder (flushing, draining,..)
Comment 5 m][sko 2014-08-06 21:18:29 UTC
anybody can look at my patch?
Comment 6 Peng Liu 2014-08-27 03:07:20 UTC
(In reply to comment #4)
> Created an attachment (id=280015) [details] [review]
> omxenc reconfigure caps patch
> 
> I fixed flushing problem
> but it still don't work on RPI(I don't have any other device) without
> no-component-reconfigure
> 
> I rewrote some code base on decoder (flushing, draining,..)

You mean the issue can be fixed with no-component-reconfigure? Thanks.
Comment 7 Peng Liu 2014-08-27 03:28:50 UTC
Created attachment 284574 [details] [review]
Patch to fix this problem on RPI

I guess the OpenMAX implementation for RPI has some issue in such kind of special case. Actually I was not able to find clear explanation in OpenMAX specification about the component reconfiguration.

My patch can be used to fix this problem, by the way.
Comment 8 Sebastian Dröge (slomo) 2014-08-27 07:09:36 UTC
Review of attachment 284574 [details] [review]:

See how this is done in gstomxvideodec.c. Look for GST_OMX_HACK_NO_COMPONENT_RECONFIGURE

It should be done optionally via that hack flag, and ideally with the same code as there.

::: omx/gstomxvideoenc.c
@@ +1100,3 @@
       return FALSE;
+    if (gst_omx_component_set_state (self->enc, OMX_StateIdle) != OMX_ErrorNone)
+      return FALSE;

Why do you only go to Idle here and not Loaded too?
Comment 9 Sebastian Dröge (slomo) 2014-08-27 07:15:15 UTC
Comment on attachment 280015 [details] [review]
omxenc reconfigure caps patch

Is this patch still necessary when using the other one? If so it probably needs to be ported to latest git master... and also needs a better commit message that actually describes what the patch is trying to do
Comment 10 Peng Liu 2014-08-27 17:23:23 UTC
(In reply to comment #8)
> Review of attachment 284574 [details] [review]:
> 
> See how this is done in gstomxvideodec.c. Look for
> GST_OMX_HACK_NO_COMPONENT_RECONFIGURE
> 
> It should be done optionally via that hack flag, and ideally with the same code
> as there.
> 
Oh, I see.
In that way, we need to change gstomx.conf for RPI to enable the hack for video encoder, right?
Thanks.
Comment 11 Sebastian Dröge (slomo) 2014-08-27 18:50:18 UTC
Yes, it needs to be added to the config but first of all the code for it has to be added to gstomxvidenc.c :)
Comment 12 Peng Liu 2014-08-27 19:27:52 UTC
Created attachment 284631 [details] [review]
Implement the hack flag GST_OMX_HACK_NO_COMPONENT_RECONFIGURE support for video encoder

Thanks Sebastian!

I updated the patch based on your comment and it can fix the problem in my test.
Comment 13 m][sko 2014-08-27 21:24:33 UTC
now we need to add support for this 
http://home.nouwen.name/RaspberryPi/documentation/ilcomponents/prop.html#OMX_IndexParamBrcmPixelAspectRatio

Allowed values are: 1:1, 10:11, 16:11, 40:33, 59:54, and 118:81.
ouch :(

I don't really understand why broadcom don't support full range.
Is it really that hard to generate proper SPS.
Comment 14 m][sko 2014-08-27 22:53:29 UTC
Created attachment 284643 [details] [review]
rpi setup video encoder aspect ratio

rpi setup video encoder aspect ratio

as rpi encoder don't support all aspect ratios
http://home.nouwen.name/RaspberryPi/documentation/ilcomponents/prop.html#OMX_IndexParamBrcmPixelAspectRatio

I use closest value.
Comment 15 m][sko 2014-08-27 23:57:38 UTC
after aspect ratio change I get this:
http://pastebin.com/UDcxixUa
many gst_h264_parse_reset_frame

Any idea?
Comment 16 Sebastian Dröge (slomo) 2014-08-28 07:46:04 UTC
Comment on attachment 284631 [details] [review]
Implement the hack flag GST_OMX_HACK_NO_COMPONENT_RECONFIGURE support for video encoder

commit cdb918aefba276a0df70052948ff846deb128bf1
Author: Sebastian Dröge <sebastian@centricular.com>
Date:   Thu Aug 28 10:44:31 2014 +0300

    omxaudioenc: Implement the hack flag GST_OMX_HACK_NO_COMPONENT_RECONFIGURE

commit 2c98a6ab7ec2e67c6838ea84175eec50c4b02045
Author: Sebastian Dröge <sebastian@centricular.com>
Date:   Thu Aug 28 10:43:22 2014 +0300

    omxaudioenc: Use the base class' open/close vfuncs instead of calling them ourselves

commit d3d0a82ba4d6dbb475759f895f5a5a41247bdc1c
Author: Peng Liu <pengliu.mail@gmail.com>
Date:   Tue Aug 26 22:13:53 2014 -0500

    omxvideoenc: Implement the hack flag GST_OMX_HACK_NO_COMPONENT_RECONFIGURE
    
    Fix a video encoder stall problem on RPi when changing the aspect ratio.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=732533
Comment 17 Sebastian Dröge (slomo) 2014-08-28 07:49:30 UTC
Review of attachment 284643 [details] [review]:

::: omx/gstomxvideoenc.c
@@ +931,3 @@
+  guint par_n;
+  guint par_d;
+} PAR;

Just use OMX_CONFIG_POINTTYPE here

@@ +933,3 @@
+} PAR;
+
+static PAR broadcom_supported_aspect_ratios[] = {

Make the table const

@@ +954,3 @@
+  par = &broadcom_supported_aspect_ratios[0];
+  best_par = par;
+  best_ar_diff =

Instead of choosing the closest value, just put the only allowed values in the sinkpad template caps. You'll distort the frames if you choose a value different from the actual one, no matter how close it is

@@ +1112,3 @@
 
+#ifdef USE_OMX_TARGET_RPI
+  // aspect ratio

No C99 comments
Comment 18 m][sko 2014-08-28 08:45:00 UTC
broadcom don't support any other aspect ratios
1:1, 10:11, 16:11, 40:33, 59:54, and 118:81.

If I don't choose one of supported, broadcom choose 1:1 and that isn't good at all.
I prefer my solution.

As plan B I have SPS generator base on current h264parser (1.2.3 version) 
but I don't know If anybody will maintain it.

broadcom openmax encoder also don't generate AU delimiters
and I think we should add it here to encoder instead of h264parse
Comment 19 Sebastian Dröge (slomo) 2014-08-28 09:17:30 UTC
(In reply to comment #18)
> broadcom don't support any other aspect ratios
> 1:1, 10:11, 16:11, 40:33, 59:54, and 118:81.
> 
> If I don't choose one of supported, broadcom choose 1:1 and that isn't good at
> all.
> I prefer my solution.

That's also not what I said. You would put those 6 PAR into the sinkpad template caps, and then do an exact match for setting the broadcom specific property. If no exact match is found it is considered an error instead of using the closest one (which would distort the picture).
Comment 20 m][sko 2014-08-28 11:33:11 UTC
(In reply to comment #19)
> (In reply to comment #18)
> > broadcom don't support any other aspect ratios
> > 1:1, 10:11, 16:11, 40:33, 59:54, and 118:81.
> > 
> > If I don't choose one of supported, broadcom choose 1:1 and that isn't good at
> > all.
> > I prefer my solution.
> 
> That's also not what I said. You would put those 6 PAR into the sinkpad
> template caps, and then do an exact match for setting the broadcom specific
> property. If no exact match is found it is considered an error instead of using
> the closest one (which would distort the picture).

And benefit of you idea?
encoder will not work in same unsupported aspect ratios?
Comment 21 Sebastian Dröge (slomo) 2014-08-28 11:37:59 UTC
Yes, it will not work with unsupported aspect ratios instead of claiming to work with them and then using a completely different one. That allows upstream elements to generate data with an appropriate aspect ratio, e.g. videoscale can do that.
Comment 22 m][sko 2014-08-28 12:31:54 UTC
What if we add property for this dilemma?
aproximate_aspectratio_in_SPS

Can we change sink caps dynamically or base on change in property?
Comment 23 Sebastian Dröge (slomo) 2014-08-28 12:40:03 UTC
What would this solve?
Comment 24 m][sko 2014-08-28 13:01:52 UTC
working encoder with approximate aspect ratio if you switch it on
in all other cases you will need to handle it with videoscale
Comment 25 m][sko 2014-08-28 13:30:27 UTC
plan C
I'am in contact with don from RPI.
He has access to source codes and we will try to add support for all ARs.
I hope it will be eazy
Comment 26 Sebastian Dröge (slomo) 2014-08-28 13:44:23 UTC
Plan C sounds best of course, but until then I would still prefer my solution. Just pretending to accept a PAR and using a completely different one is not a good idea, you produce broken videos.
Comment 27 m][sko 2014-08-28 19:01:00 UTC
Created attachment 284736 [details]
demug log

I still have problem with this
http://pastebin.com/UDcxixUa
after aspect ratio change h264 parser generate many
gst_h264_parse_reset_frame

If I add
h264parse disable-passthrought=true all works fine


GST_DEBUG="*:3,aacparse:3,tsmux:0,mpegtsmux:4,omx*:1,omxvideoenc:1,omxh264enc:1,h264parse:5" \
gst-launch-1.0 uridecodebin uri="file:///home/pi/test13_aspect_ratio_change/test_ar_problem2.ts" use-buffering=false name=demux caps="video/mpeg, parsed=true; audio/x-raw; text/x-raw" \
 ! 'video/mpeg, parsed=true' \
 ! omxmpeg2videodec ! tee name="decdata"\
 ! omxh264enc target-bitrate=1000000 control-rate=1 periodicty-idr=50 interval-intraframes=50 inline-header=true ! 'video/x-h264, profile=high' \
 ! h264parse disable-passthrough=true \
 ! fakesink \
 demux. ! 'audio/x-raw'  \
 ! fakesink \
 2>&1
Comment 28 m][sko 2014-08-28 20:59:49 UTC
http://pastebin.com/wPdRhezj
0:00:09.248553095 29707 0xb06cc780 INFO               baseparse gstbaseparse.c:3583:gst_base_parse_set_passthrough:<h264parse0> passthrough: yes
and whole parsing process stoped
Comment 29 Sebastian Dröge (slomo) 2014-08-29 08:39:35 UTC
Can you provide a sample stream for that and create another bug against h264parse for it?
Comment 30 Sebastian Dröge (slomo) 2014-08-29 08:40:11 UTC
Same goes for the RPi specific aspect ratio configuration, it's independent of this bug here.
Comment 31 m][sko 2014-08-29 08:50:18 UTC
(In reply to comment #29)
> Can you provide a sample stream for that and create another bug against
> h264parse for it?

in my first post
http://www.mdragon.org/test_ar_problem2.ts
Comment 32 m][sko 2014-08-29 08:55:45 UTC
bug report
https://bugzilla.gnome.org/show_bug.cgi?id=735655
Comment 33 m][sko 2014-08-31 20:35:30 UTC
Created attachment 284956 [details] [review]
rpi setup aspect ratio

dan add support for all aspect rations in latest rpi firmware
So if anybody want to use this patch on all aspect rations you will need firmware since 30.Aug.2014
Comment 34 Sebastian Dröge (slomo) 2014-09-01 09:20:02 UTC
commit bfeab29a398455d8c89af6d1bbd80817c5e3ad0e
Author: Michal Lazo <michal.lazo@mdragon.org>
Date:   Sun Aug 31 20:30:13 2014 +0000

    omxvideoenc: Setup aspect ratio on RPi
    
    Needs firmware from yesterday or newer to work with all possible
    aspect ratios. Before that it only supported a fixed list.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=732533