Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[imx] Move deinterlacing into render thread and use gui settings #29

Merged
merged 4 commits into from
Mar 24, 2014

Conversation

smallint
Copy link
Member

@smallint smallint commented Mar 3, 2014

This moves deinterlacing into the render thread and uses the GUI settings to configure deinterlacing during runtime.

@smallint
Copy link
Member Author

smallint commented Mar 3, 2014

This is primarily for discussion. We don't need to merge it soon but at least to revise the concept and the current gui settings implementation whether it is correct or needs fundamental changes. To discuss with code is probably easier for devs ;)

@smallint
Copy link
Member Author

smallint commented Mar 7, 2014

I have tested it during the last days and the integration seems to work well. I can turn on/off deinterlacing and xbmc remembers the settings. You just need to know for streams that render too slow that you need turn off deinterlacing (currently only the Sky samples). For end users probably hard to figure out though ...

@koying
Copy link

koying commented Mar 7, 2014

Cool. I'll test and review this WE.

@koying
Copy link

koying commented Mar 8, 2014

@smallint Would you mind rebasing on master, so that this can be applied? Thanks

@smallint
Copy link
Member Author

smallint commented Mar 8, 2014

Done.

@@ -1638,7 +1640,15 @@ void CLinuxRendererGLES::RenderIMXMAPTexture(int index, int field)
YUVPLANE &plane = m_buffers[index].fields[field][0];
CDVDVideoCodecBuffer* codecinfo = m_buffers[index].codecinfo;

if((codecinfo == NULL) || !codecinfo->IsValid()) return;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an actual reason for doing CDVDVideoCodecIMX::Enter() even if IsValid is false?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CDVDVideoCodecIMX::Enter() locks the mutex which was done before in IsValid() itself. IsValid() is now not thread safe anymore.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm... Any reasons for de-thread-safe it ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the local locking IsValid does not help to prevent segfaults if you call Close at the decoder stage that cleans up all resources. Calling Process after IsValid is dangerous thats why the entire clean up procedure is guarded with Enter/Leave as well as rendering.

@smallint
Copy link
Member Author

I pushed the changes.

@wolfgar
Copy link
Member

wolfgar commented Mar 13, 2014

Following this issue #40, I have just tried this PR and I confirm that I find the de-interlacing on the screen a little worse than before moving the rendering in the rendering thread. On the other hand it greatly improves the experience while browsing the GUI
Can't you see a regression on your side guys ?
On the other hand de-interlacing was neither perfect before and would require the double rate option to be set (IPU_DEINTERLACE_RATE_EN flag).
What is your mind about it @smallint ?

@smallint
Copy link
Member Author

For me it works quite well but only if I set the deinterlace method to auto. I added for testing both options: low motion (deinterlace) and fast motion (deinterlace half). Unfortunately the names are not freely selectable in the GUI. The latter uses only the current frame while the first needs two frames and is too slow to be used for 1080i on my side. To set IPU_DEINTERLACE_RATE_EN is easy enough but I haven't tried with this PR if it helps. Could you explain what exactly this flag does?

@wolfgar
Copy link
Member

wolfgar commented Mar 13, 2014

OK, I was not aware deinterlace was associated to low motion. As I said in the issue #40, switching to fast motion improved visibly the behavior from my point of view...
I don't know precisely what IPU_DEINTERLACE_RATE_EN does but they call it "vdi double rate" and the horizontal text scroll are really improved with this setting...

@smallint
Copy link
Member Author

Have you already tried to apply IPU_DEINTERLACE_RATE_EN? I am going to try that tonight. The question is if it has impacts on the performance. If 1080i slows down significantly we would need an additional deinterlacing option which enables IPU_DEINTERLACE_RATE_EN. It is a pitty that xmbc does not allow to assign custom names for deinterlacing modes. The only option is to change the definitions itself according to HAS_IMXVPU.

@smallint
Copy link
Member Author

According to the IPU driver the IPU_DEINTERLACE_RATE_EN flag does nothing if IPU_DEINTERLACE_RATE_FRAME1 is not set correctly. I don't know if that flags needs to be toggled for each input (probably yes). Is there a documentation for the IPU driver and its ioctl calls? I haven't been able to find one. Also LOW_MOTION seems to be implemented wrongly in this PR. At least I am quite sure that I have swapped the input buffers (current - next vs. current - previous). This whole thing needs some more attention ;)

@wolfgar
Copy link
Member

wolfgar commented Mar 14, 2014

@smallint I know IPU_DEINTERLACE_RATE_EN is at play when the option vdi_rate_double is used for mxc_vout driver and I know it greatly improves the final result. That's why I suggested to investigate its use directly (now that ipu is directly used instead of indirectly through the mxc_vout driver...)
Well, I have just checked : You are definitively right : IPU_DEINTERLACE_RATE_FRAME1 has to be set/clear in field_fmt and you are responsible for submitting properly the frames twice for the double rate to work properly. Have a look at media/video/mxc/output/mxc_vout.c to see how it has to be setup (check especially for IPU_DEINTERLACE_RATE_EN flag use)
I guess You don't need an additional ioctl for this and just have to set properly the field_fmt field...
I don't know for documentation regarding IPU ioctls. Source code is a good doc ;-) drivers/mxc/ipu3/ipu_device.c (function mxc_ipu_ioctl)

For the low motion, as I said, the final result on screen is visibly not good. Here again you are right : It deserves more attention and a fix...

@smallint
Copy link
Member Author

According to mxc_vout.c it is queuing the task twice (IPU -> FB). This means we have to render the image twice and prepare virtual pictures between two real picture to double the rate: 25Hz -> 50Hz. I checked already ipu_device.c and from what I see is that FRAME1 just swaps the top/bottom field. The real work goes in mxc_vout.c to run the IPU task twice for one additional frame.

@wolfgar
Copy link
Member

wolfgar commented Mar 14, 2014

yes as I have just written : "you are responsible for submitting properly the frames twice for the double rate to work properly."

@smallint
Copy link
Member Author

I was referring to "I guess You don't need an additional ioctl for this" and I think you need one. I am currently on fixing the visual issues with low motion and reworking the buffer management. Lets see if we manage to integrate the double rate properly.

@wolfgar
Copy link
Member

wolfgar commented Mar 14, 2014

ho, OK sorry...
Regarding IPU ioctl, Do you still think you need an additional one ? Or do you agree that everything is handled through flags/value in field_fmt and by invoking twice the ipu task (it is my current understanding but I may be wrong) ?
Nice for the low motion I will be glad to give it a try..

@smallint
Copy link
Member Author

Now I am confused ;) Isn't ioctl and the ipu task the same? ipu_device.c does not call a second task if FRAME_EN is given. It just adjusts the parameters (e.g. swapping bottom and top fields). As I understand the mxc code, it does not use ioctl at all because it can call the kernel function directly. But we need to use ioctl from user land. Am I totally wrong here?

@wolfgar
Copy link
Member

wolfgar commented Mar 14, 2014

Sorry I think I have just understood the misunderstanding : I though you were saying that you need a new ioctl code but you only mean that you need an additional call, right ? If so, then we perfectly agree ... ;)

@smallint
Copy link
Member Author

Haha :) Yes, I meant a second call not another ioctl function. No need to hack the kernel.

A side question: do you know how to reliably detect if a frame is interlaced? I have a 1080i stream here which is showing interlacing clearly but it reports a field type of VPU_FIELD_NONE. Other SD stream report VPU_FIELD_TOP which is perfect. The sky streams probably do not need deinterlacing but also report VPU_FIELD_TOP, hmmm.

@smallint
Copy link
Member Author

I pushed a fix that solves the picture jumping for me with low motion. Each frame keeps now track of its previous frame and does not rely on the deinterlacers previous frame which can be quite old due to frame drops and such things. It does not help with performance though. Please let me know if that helps with respect to your bad impressions of the previous version.

Next thing is to integrate the double rate. Basically it should be straight forward, to hard part is to decide when to activate it or not since the Decoder has not feedback from the GUI.

@wolfgar
Copy link
Member

wolfgar commented Mar 14, 2014

I have just tested your last push and it is really better with low motion for sure ! Congratulations...
(You are right for performance : it is not fluid with all streams but it was the same with v4l and mxc_vout I think)

@smallint
Copy link
Member Author

Yep, have it working and it is really smooth, wow!

@smallint
Copy link
Member Author

I pushed the double rate feature. This is very experimental and does only work for SD streams. It is automatically disabled for HD (too slow for me). I noticed a strange flickering pixel line at the top with this mode. But otherwise it looks pretty good. Since I won't find the time to work on it during the weekend I want to share the code with you at least to test or to play with it. 9da0417 is even more important since this enables high motion on request again.

@wolfgar
Copy link
Member

wolfgar commented Mar 14, 2014

Very nice for double rate ! it was really worthy to enable it...
Unfortunately the little bug I already mentioned regarding this option is also present.
It is not your fault : we have the same issue with the double rate option..
There is a kind of vertical oscillation : can you see it ?
It is a shame because deinterlacing is so good with this option...

@wolfgar
Copy link
Member

wolfgar commented Mar 14, 2014

Sorry I tried and commented before reading your message ;)

@smallint
Copy link
Member Author

Have you tried 9da0417 or 09915d4? 9da0417 fixes the problem that low motion is always used regardless of the GUi deinterlacer mode. 09915d4 implements the double rate feature which really improves the smoothness. Maybe there are still some problems with setting the right state for FRAME1 and for low motion: what is previous and current frame? But it is a proof of concept that it can work but still needs more tweaking.

I am off, have a nice weekend!

@wolfgar
Copy link
Member

wolfgar commented Mar 14, 2014

I have tried both of them, one after the other... So my last comment applies to the double rate implementation in 09915d4
Have a very good weekend...

@smallint
Copy link
Member Author

Stéphan, I am right in my understanding that this vertical oscillation is also present in the original v4l implementation? Is it a bug in the kernel modules? Can we work around it? It seems that is the input buffer is just offset wrongly by one scanline!?

@wolfgar
Copy link
Member

wolfgar commented Mar 17, 2014

Yes jan, You are right : this vertical oscillation was the same in original v4l implementation
I don't know the root cause nor how to prevent it but it deserves investigations as the result is pretty good apart this drawback...

@wolfgar
Copy link
Member

wolfgar commented Mar 22, 2014

Hi,
GUI settings and moving deinterlacing to the rendering thread are ready to be merged I think.
We could merge that part quickly and take time to try to solve the vertical oscillation and enhance the behavior for HD as a second run. What do you think about it ?

@smallint
Copy link
Member Author

Stéphan, I am basically fine with it. Currently the double rate option cannot be disabled for SD streams. I would like to see all 4 options in xbmc (high motion, low motion, high motion + double rate, low motion + double rate) with its corresponding descriptions in the GUI. Is this feasible or would it be accepted by the xbmc devs to add new enumerations and text representations for the IMX6 path to media settings? Another thing is to do the processing itself: I have checked the vpdau implementation and it is reading the media settings directly (not in the renderer) and does the mixing as they call it in a dedicated thread. I would also like to try that path as well to get rid of the quite complex ::UploadTexture implementation. But all this can go into the next run.

@emveepee
Copy link

I'm not sure it's relevant but a user posted about OTA 1080i being noticeably inferior now http://imx.solid-run.com/forums/viewtopic.php?f=7&t=641&start=110#p6088 to the wolgar.git and however it was deinterlacing/rendering.

@smallint
Copy link
Member Author

As I understand he is complaining that deinterlacing is disabled at all for HD streams and this is the current state of master, yes. He should see the following log entry "IMX: Disable hardware deinterlacing for HD playback" - so nothing new to me. This is exactly what this PR addresses.

@emveepee
Copy link

I appreciate the improvement but I don't understand how it could worse now. PR 29 is already in the Geexbox he is commenting on.

Martin

@smallint
Copy link
Member Author

Worse in what sense? And what version of #29? Since #29 is not merged so far I also included the fix for low motion deinterlacing and added the experimental double rate feature. And even more important for me: what is actually the issue? Is it too slow, no deinterlacing at all although enabled in the GUI? If it renders too slow could you please provide an example?

@emveepee
Copy link

It would depend on which GeexBox he use the base line has this http://hg.openbricks.org/openbricks/rev/a95a9a4e4fc4 and I kept my experimental builds current to featdeintrender until it stopped merging because of conflicts with fixdts3. Since the i.MX6 is not ready for production use I felt that getting experimental patches into the wild would help you guys with real world testing, but unfortunately I can't control the quality of the reports that you will get from users.

Martin

@smallint
Copy link
Member Author

OK, thats the last version. Again, "worse" means he does not get deinterlacing at all? I always checked your 1080i example (the commercial) and I did it 5 minutes ago after rebasing this PR. I can clearly see interlacing when I disable deinterlacing and I see a smooth picture with deinterlacing set to auto. My advice is to check the GUI deinterlacing settings (I think the default is off) and set them to auto.

@emveepee
Copy link

Thanks for the good suggestion I will enable Auto, with the next master build and whatever it includes. (still not clear if xbmc-imx6.git is continuing with xbmc 14 or forking with Gotham etc)

Martin

@wolfgar
Copy link
Member

wolfgar commented Mar 22, 2014

@smallint : thanks a lot for your feedback : I propose to open a new PR with all stuff except double rate and we merge it right now...
@emveepee : For the user feedback, odds are high the deinterlacing was simply disabled. It was a known drawback when we switched to the new rendering method : deinterlacing had to be reimplemented and large part of this work has been already addressed for smallint. I thank him very much for this.
At last, we had private exchanges regarding the xbmc versions : xmbc-imx6 master will follow gotham while master-pr will follow the xbmc master (xbmc 14) with the aim of being merged in xbmc during this next cycle...

@smallint
Copy link
Member Author

@wolfgar I removed the double rate stuff in this PR since its name is quite descriptive right now ;) Lets open a new PR for the double rate, OK?

@wolfgar
Copy link
Member

wolfgar commented Mar 23, 2014

that's perfect to me.
Except if there is an objection, I will merge this PR tomorrow in the evening...

wolfgar added a commit that referenced this pull request Mar 24, 2014
[imx] Move deinterlacing into render thread and use gui settings
@wolfgar wolfgar merged commit 1579e85 into master Mar 24, 2014
@smallint smallint deleted the featdeintrender branch December 17, 2014 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants