|
The DirectShow SDK and the Windows Media Format SDK may be helpful resources. Even though
you have your own codec and you don't need to use those SDKs there may be some helpful
hints on how Microsoft does it.
Typically...
There's two areas that can be dealt with separately - I/O/Uncompress and rendering.
I/O and uncompress is reading the source data and uncompressing into individual video frames.
Using some kind of buffer allocator scheme, the decompressor allocates a frame buffer, writes
the uncompressed frame data to the buffer, and queues it for rendering.
The renderer checks the frame buffer queue. If there is a buffer available it checks the time
stamp. If it's not time to display the frame yet then it waits. If the time for the frame has
passed then the frame is either rendered immediately or discarded.
That's the typical scenario using the SDKs I mentioned above.
To implement it, there's all kinds of possibilities. For human-viewed video, frame rates don't
need to be beyond 30fps so you don't have to get too crazy with timing issues.
It's possible to do both steps on one thread but the performance can be bad. You decompress
a frame and then wait until it's time to render it. This relatively large gap in time of
doing nothing could be used to decompress another frame and have it ready.
A more elegant solution would be to use two threads. One thread reads and uncompresses frames.
It does so until enough frames are queued (some pre-defined read-ahead value) then pauses.
On another thread you could render the frames. This thread could wait on an event like a
multimedia timer event set to the frame rate or be triggerred by an event from the
decompressor thread (set every time it adds a frame to the queue perhaps).
There's some things that can make the process more efficient...
1)Pre allocate a pool of buffers so they don't have to be allocated every
time you need one. Typically you'd want enough buffers to hold the read-ahead amount of frames
mentioned above. You could actually use this to control the uncompress thread - when the
thread tries to obtain a buffer from the pool and there's none available then it waits.
2)Design the buffers to be in a format ready for rendering. If the buffers are alread DIB
sections for instance, then as soon as the frame data is uncompressed to the buffer then it's
ready to render. No second copy is necessary. For Direct3D (formerly DirectDraw) the buffers
could be Direct3D surfaces.
3) Don't do any of this on the app's main/UI thread. That way the user interface stays
responsive while the video plays.
I hope this gives you a few helpful tips to get you started.
Mark
|
|
|
|
|
Thanks a lot for the detailed suggestions. I will be back after a detailed study of those.
|
|
|
|
|
some text tell me that: allocate a Global memory, then give it to clipboard.
But I want to know: who/how/when free clipboard's memory?
Maybe EmptyClipboard()? I am not sure.
anyone can help me?
|
|
|
|
|
DollfaceYY wrote: But I want to know: who/how/when free clipboard's memory?
Got this from MSDN...
To place information on the clipboard, a window first clears any previous clipboard content by using the <code>EmptyClipboard </code>function. This function sends the <code>WM_DESTROYCLIPBOARD </code>message to the previous clipboard owner,<code> frees resources associated with data on the clipboard,</code> and assigns clipboard ownership to the window that has the clipboard open.
|
|
|
|
|
Does it matter where I define a variable? For example, take the following two cases. Does one result in more efficient execution code than the other? Variable x is defined in differnt places. Are there any general guidlines for this? Thanks.
CASE 1
int x = 0;<br />
for(int i = 0; i< 10; i++)<br />
{<br />
x = a + b + c;<br />
}
CASE 2
for(int i = 0; i< 10; i++)<br />
{<br />
int x = a + b + c;<br />
}
|
|
|
|
|
Case 2 defines it over and over. I've been told this can be *more* efficient, I suspect otherwise. The truth is, that sort of optimisation is rarely going to give you visible benefits
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian Graus wrote: The truth is, that sort of optimisation is rarely going to give you visible benefits
Anytime you can optimize the better, I say. The compiler may or may not optimize it, why take the chance. Like Christian said, it probably won't matter in most sutuations, but if you're looping through a million rows it will.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
When the variable doesn't have a ctor or a dtor (as in this case) it makes no difference in release mode - the optimizer will alloc space for the variable on the stack once. In debug builds, x will be reset to 0xCCCCCCCC every time through the loop, but speed isn't a concern in debug mode.
|
|
|
|
|
I always try to define a variable like that only one time (outside the loop). It shouldn't make a difference unless it's a more complex type that has a lengthy constructor/destructor. I'm old, and set in my ways.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi.
Using Visual C++ 6, can i include controls like edit box to SDI application without the use of dialog?
|
|
|
|
|
Yes, sort of. You derive your window from formview, and it essentially becomes a dialog with a template. There's also no reason you can't just add controls dynamically to any view type you like
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
UnknownBlue wrote: Using Visual C++ 6, can i include controls like edit box to SDI application without the use of dialog?
Yes, CFormView should help you, but then it takes a dialog resource.
Another option is to directly create controls using their create method.
|
|
|
|
|
Can you use of CFormView ?
|
|
|
|
|
We have an SDI application that we'd like to be able to shrink up to just a small height (approx 60 pixals of client height). I've got the code to shrink it and expand it back to the original size. Unfortunately, when it's shrunk down, the framework makes the actual size much larger and adds in vertical scrollbars.
Anyone know how I can remove the scrollbars when they are added in automatically?
|
|
|
|
|
You could try and remove the WS_VSCROLL window style in PreCreateWindow.
The CREATESTRUCT structure has a style member from which to remove this style.
cs.style &= (~WS_VSCROLL)
« Superman »
|
|
|
|
|
Good idea, but it doesn't seem to have any affect. I also tried
cs.dwExStyle &= (~WS_EX_RIGHTSCROLLBAR);
It didn't work either. Seems like the document interface has some limit on the minimum size of the document window.
|
|
|
|
|
I need to run some application at the same time when I execute my project.
Please advise me, how to add this application in resource of my project.
|
|
|
|
|
Use ShellExecute to run the program. I don't think you want to make it a resource.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
ShellExecute() need path of application but I don't khow how to get the path that my project is working.
|
|
|
|
|
I don't understand what you mean by execute my project.
If you mean build the project, you could create a batch file in which you can first run the application and then use msbuild or devenv to build the project.
If you want to include another application as part of your application, embed the other application as a binary or custom resource. During runtime you can use FindResource , LoadResource and LockResource functions to get a pointer to the resource. Then copy the entire application to a file with extension .EXE. After that you can execute the newly created .EXE file using CreateProcess .
« Superman »
|
|
|
|
|
Going through an adjustment period as I have just "upgraded" from Visual Studio 6 to Visual Studio 2005. I am having a few problems adjusting, although they are not so serious. I have, however, just discovered that a managed class (ie: declared as:
<code>ref class CMyClass</code>
cannot apparently have any friend classes. I assume therefore that if I want to work with inheritance I should avoid use of managed classes, correct? Or is there a way to access the protected members of a managed class? If not, then what is the advantage of a managed class in C++? I realize they are created on a garbage collected stack, but if inheritance cannot be used aren't we sacrificing alot of the functionality and power of C++? Yes, I know I can just declare my classes as unmanaged, but I am curious as to the answers to the above questions.
Thanks.
Windows with no internet connection is safe, but that's not what Windows was built for.
|
|
|
|
|
The Apocalyptic Teacup wrote: I assume therefore that if I want to work with inheritance I should avoid use of managed classes, correct?
Inheritance has nothing to do with friend classes. But, yes, the .NET framework does not support friend classes. Which sucks.
The Apocalyptic Teacup wrote: Or is there a way to access the protected members of a managed class?
Yes, derive your classes from them ( inheritance ). Or, put the classes that work together in an assembly and use 'internal'
The Apocalyptic Teacup wrote: If not, then what is the advantage of a managed class in C++?
The fact that it can use the .NET framework
The Apocalyptic Teacup wrote: but if inheritance cannot be used
Just not true
The Apocalyptic Teacup wrote: aren't we sacrificing alot of the functionality and power of C++?
The whole point of C++/CLI is that you can access the power of C++, things like templates ( no, generics suck and do not count ) and the STL are available to you.
The Apocalyptic Teacup wrote: Yes, I know I can just declare my classes as unmanaged
You probably should, if you can, it means you don't rely on the framework. Why add baggage if you don't need it ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian Graus wrote: Inheritance has nothing to do with friend classes. But, yes, the .NET framework does not support friend classes. Which sucks.
Yes, okay true. Re-reading my post I see I worded that very badly. Anyways, I had a nice class all written up with protected member functions, etc... it was great and then I tried to derive a class (declared as friend) from it and - wow - the compiler errors. Do you have any idea why friend classes can't be used? Do they interfere with the garbage collection?
Windows with no internet connection is safe, but that's not what Windows was built for.
|
|
|
|
|
The Apocalyptic Teacup wrote: then I tried to derive a class (declared as friend)
Why would you declare a derived class as a friend ?
The Apocalyptic Teacup wrote: Do you have any idea why friend classes can't be used?
Because the .NET teams always seem to go for the 'lite' implimentation.
The Apocalyptic Teacup wrote: Do they interfere with the garbage collection?
I don't see how that's possible.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian Graus wrote: Why would you declare a derived class as a friend ?
OMG I'm tired. I meant I declared a friend class an instantiated it.
Windows with no internet connection is safe, but that's not what Windows was built for.
|
|
|
|