Why AxShockwaveFlash take so much memory or process while transitions? - c#

I have developed an application with 2 AxShockwaveFlash and textBlock.In AxShockwaveFlash there is 2 different flash files with their own animation and in the bottom of the form a textblock scroll some text(Ticker).While loading of flash my ticker get stuck and when the flash has some transition then also my ticker get stuck.
I am not getting any clue why my application responds slow while playing or transitioning a flash file.How can I track exactly the problem is?

The simple answer to : Why AxShockwaveFlash take so much memory or process while transitions? is simply because that Someone out there doesn't know how to code a transition without killing the CPU.
To be fair your question didnt give enough helpful info (which led to the rambling answer below). Many people will call something "a Flash animation" when that something is anything from simple text fading in/out.. to a full blown 3D engine game demo to.. some intensive realtime video pixel effects. Just happens to be done in Flash so it's a Flash animation, right?.
A) If you can improve the C# code... Look into improving your WPF/Textblock code
Because if your Textblock is getting slowed down by the additional loading of some multimedia elements (photo, sound, Flash etc) then you simply have to improve that Textblock code.
Is this slow WPF TextBlock performance expected?
http://social.msdn.microsoft.com/Forums/vstudio/en-US/378a1945-8f72-4641-a0b8-e8ba5a31eced/is-the-wpf-textbox-really-that-slow?forum=wpf
http://www.codeguru.com/csharp/.net/net_wpf/article.php/c18025/10-Ways-to-Improve-the-Performance-of-Your-WPF-Application.htm
B) If you can improve the AS3 code... Look for any CPU intense pixel activity. Use bitmapData.lock and .unlock if the transitions code uses bitmapData.
If the Flash is externally created by someone else then perhaps there is some ineffecient coding? Check CPU usage by loading just the SWF's (no Textblock). Also consider the nature of your Flash animations for example I've never known SWF's of advert banners & pop-up ads to NOT add CPU usage. I dont know what those people do with their "simple" adverts. Essentially if someone else made it, find an alternative. Else if you have the source code, improve upon the transitions function first amongst others.

Related

Good realtime display perfomance and input processing for .NET desktop application approach

I am tasked to write a .NET application that displays a slide-show with some information (words or images) and when the user sees certain items, s/he must immediately press space and the time of the key press must be recorded. The items will be displayed one after the other, for about 50ms. I need then to evaluate the difference between the timestamp of the keypress and and the one when the slideshow started (so I will know how long it took the user to react on the presented item). Edit: I must also record the time of the occurence of the special item.
I need to reduce any unpredictable lags that may occur as the application is running, so that the input processing is as realistic as possible, as well as to reduce any lags between the slides. Currently I am thinking of 3 approaches:
Write a standard Windows Forms (GDI+) application.
Write a WPF application
Write a DirectX-enabled windows forms application that utilizes the Tom Miller's Render loop concept (it is praised as effective in terms of performance).
Something else that you might suggest
I must clarify that I will not use advanced display techniques, special effects or designed for the purpose 3D environments - just plain text slides in different fonts and colours, or images. Unfortunately I cannot cite my sources, but I have read that Windows Forms and GDI+ cannot provide me with the desired accuracy. So, is WPF going to provide me with a better solution? Do I need to use the render loop, or some other approach. I am not experienced in such type of performance requirements for desktop applications, and all advices will be appreciated greatly.
I personally love WPF, but I would be very wary of using it for this application. It is not going to have the same time precision as GDI+ or DirectX. There are all sorts things you'll have to work with like the DispatchTimer and it just wasn't build for something like this. WPF is a whole set of gigantic abstractions on top of graphics and the farther you get away from the metal, you're introducing potential problems. If you want to put a video projected on top of a 3D sphere inside a combobox then WPF is the way to go, but if you need accuracy/precision on the scale you're talking, WPF is not the answer. I don't know where you read that WPF will provide you with better accuracy, I can practically guarantee that it will not.
DirectX would most likely be the most accurate in ensuring that a picture is only displayed for 50ms at a time. But GDI+ would be a decent alternative solution because it will make it easier to deal with text from a programming perspective.
Another consideration, screen refresh rates. yikes. if you do the math most LCDs have a 5ms response rate which is 10% of your allotted time. That and they only display at 60Hz. If you're displaying 20 pictures per second (50ms per picture) it is only going to be on the screen for 3 refresh cycles.
I hope this helps.
50 msec isn't long. Maybe encode and play the slideshow as a video?

c# Text over video

I've spent days googling and coding tryin to acheive the basic level of effect all media players have when showing fancy subtitles - that being text (optionally with outline/dropshadow/glow) written above a video (video being a videofile but would nice to also have option of being a videofeed eg webcam).
So far the only way I've managed to get anything over a video is either to write to a transparent picturebox above a video component which is aliased so has dodgy outline, or using the directshow.net library and the capture method from the dxtext example I have managed to actually write over a picturebox that is being spat frames of the video. The problem here is that as soona s I add the writing commands in (video plays to picturebox fine without it) then I get slight fps hit coming accross as marginal stuttering on the video.
Does noone have a way to just write/draw over a video without taking this kind of performance hit? Or am I going to have to resort to directx or something or just give up on this luxury? :/ I can paste any code needed for help but I think anyone with assistance will probably be the one wanting to post code!
TIA for any input, it's doing my head in D:

Poor StackPanel performance with WPF

I have an application which runs fullscreen on a high resolution display (1920x1080).
About 25% of the screen is a StackPanel that scrolls images across the screen.
(the X position is animated with double animation)
The scroll is very laggy and jumpy, and with visible tearing.
This is running on a brand new high-end gaming laptop, running Win7 64bit.
I don't understand why the performance is so poor. Am I doing something wrong? Does this kind of animation run on the CPU or GPU? Is there a smarter way to scroll images across the screen?
WPF can be hardware-accelerated, but only on newer video card drivers. Some of the onboard, out of box drivers, will default back to software rendering, which can feel really slow and clunky. As for the tearing, that's a normal video card setting, called V-Sync. I would try updating the video card drivers to a proprietary driver (nVidia, AMD, etc.), and enabling vertical sync on the card.
You can check to see if it falls into software, or hardware rendering using the methods explained here.
If that doesn't resolve the issue, the only other possibility I can think of is your animation/rendering is not synced to the GUI.
See this msdn article for more details.
A trick that I've seen that can get around this issue is to place a 3D object on your page, view it side on and rotate it e.g. for 4 images have a cube with an image set to each side.
Yes the rotation still requires GPU and processor time but it is taken care of internally by the WPF animation and so doesn't require interaction with code behind once set rolling.

Smooth Video Rendering in C#

I am trying to find a way to render video in WPF with lower CPU usage than MediaElement.
The goal is smooth and low CPU video playback as much as Direct3D/DirectDraw video rendering in C++ programming.
I tried Direct2D(with WindowsAPICodePack) to render video, and the result is CPU usage is pretty low, but the problem is that I have no way to render video smoothly since there's no accurate timer to update video at exact time like DirectX in C++.
Maybe I need to go back to C++ world to use Direct3D natively and hosting C++ with DirectX window in C# WPF window. Even though I don't know what will happen with that, it may worth to try, I guess.
If you guys have any advise, please let me know.
You could try writing a small XNA app to render the video and embed that into your winform

C#: Creating a graphical screensaver

I am thinking about creating a screen saver. I have the whole thing, its graphics and the back-end kind of ready in my head. But I am not quite sure how to get the graphics out in code.
What I would like is a slide show of images with a bit of movement (kind of like the slide show in media center) and some floating text and shapes on top. The shapes somehow translucent.
I currently have a very simple static slideshow made in WinForms. Just a simple application that goes fullscreen and displays some images and pretends to fade them in and out in a hackish kind of way. But it is not very well made, and the performance is not very good. For example to prevent lag, I fade in a black square on top of the image, instead of fading in the actual image. Silly perhaps, but it kind of worked :p
Anyways, I would like to do a better job. But not sure where to start. Is WPF a good solution for this? Or should I look into DirectX or OpenGL? Is this something that could be handled well with XNA, or is that too game spesific?
WPF is not a bad idea. It takes advantage of DirectX and hardware acceleration for its animations and effects.
You will get better performance if you write this kind of stuff natively (against directx or opengl), but the cost of writing it will be much higher. It's quite possible you will not need that edge anyway.
Have a look at hanselman's baby smash (which is a full screen wpf app with animations) to get a grasp of what you can do with wpf.
Note: I did write a slide show kind of thingy in WPF way back, the key to getting this to work smoothly is loading up the images in a background thread and freezing it.
I guess XNA works well. There's a sample screensaver in C# Express, by the way.
Actually XNA works pretty well. For example: this is an (advanced) example of what can be made with XNA. The community is quite helpful and XNA has great potential.
A few weeks ago I wrote a two-part article describing how to create a Windows screen saver with GDI+. I am not displaying a slide show in my screen saver, but instead I am randomly drawing shapes. I did however explain the fundamentals of creating a screen saver for Windows which should be of some help if you have never created a screen saver before.
Create a Screen Saver Using C# – Part 1
Create a Screen Saver Using C# – Part 2
If you want to go with just GDI and GDI+, I wrote some info here about how to speed them up when rendering images and drawing them to screen. There is also fully functional screen saver source code at the above link (which I wrote myself after digging for some of the more obscure screen saver details), in case that helps.
Recently I finished with my first WPF (I wanted to see, how it can be done with WPF) screen-saver. You can check-it out on YouTube. Try to see HD-version.
Though I never tried XNA, I'm really pleased with WPF so far. Easy and flexible. But I guess you probably wouldn't get an XNA-performance (or am I wrong here?).
You can google for GDI+ or WPF ScreenSaver-templates to start with.

Categories