PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Event Handling

Hi everyone! This is question for those who managed to link video playback to EDGE.
It was easy to code using EDGE framework, but now I have to implement DirectShow for movie playback, and I'm still pretty noob at understanding event handling.

I linked and compiled all ready samples from MSDN, exept this:
Code:
/* WindowProc goes here. Add the following case statement:
case WM_GRAPHNOTIFY:
HandleEvent();
break;
*/

I want to understand this part of code. WM_GRAPHNOTIFY is event message, am I correct?

WindowProc is main event loop, so when WindowProc will receive WM_GRAPHNOTIFY, it will execute HandleEvent()?

And what this WM_APP is here for?#define WM_GRAPHNOTIFY WM_APP + 1?

Last question: Where do this WM_GRAPHNOTIFY comes from? I just do not get , do I have to sent it manually to WindowProc Loop using OnNativeEvent or something like that?

I really do appreciate all help here.
Hi Ryumaster,

Windows events are handled through callback functions, every window has one (this includes the EDGELIB window for your application). You can use this callback function by implementing OnNativeMessage and check for the message and parameters.

So what you'd like to do is the following:
Code:

bool ClassMain::OnNativeEvent(ENATIVETYPE winhandle, ENATIVETYPE msg, ENATIVETYPE param1, ENATIVETYPE param2)
{
#if defined(DEVICE_WIN32)
HWND hwnd = (HWND)winhandle;
UINT wmsg = (UINT)msg;
WPARAM wparam = (WPARAM)param1;
LPARAM lparam = (LPARAM)param2;
switch(msg)
{
case WM_GRAPHNOTIFY:
//Handle this event
break;
}
#else
return(true);
#endif
}


WM_APP is an offset (number) to define custom window messages. It is only used by internal Windows API's. If you like to make your own window message, use WM_USER.
Thank You very much! I think I can figure the rest myself from this point.
Hi! I managed to use Media Player ActiveX, so now progam compiles and video runs on my WM5 Device outside EDGELIB framework, but if I try to port portion of code, I get errors like:

Code:
1>C:\Program Files\Microsoft Visual Studio 8\VC\ce\atlmfc\include\atltrace.h(143) : error C2664: 'ATL::AtlTraceRegisterCategoryU' : cannot convert parameter 2 from 'LPCWSTR' to 'const unsigned short []'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>C:\Program Files\Microsoft Visual Studio 8\VC\ce\atlmfc\include\atltrace.h(171) : error C2664: 'ATL::AtlTraceVU' : cannot convert parameter 6 from 'LPCWSTR' to 'const unsigned short *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>C:\Program Files\Microsoft Visual Studio 8\VC\ce\atlmfc\include\atlchecked.h(95) : error C2664: 'wcscpy_s' : cannot convert parameter 1 from 'unsigned short *' to 'wchar_t *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>C:\Program Files\Microsoft Visual Studio 8\VC\ce\atlmfc\include\atlchecked.h(118) : error C2664: 'wcsncpy_s' : cannot convert parameter 1 from 'unsigned short *' to 'wchar_t *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>C:\Program Files\Microsoft Visual Studio 8\VC\ce\atlmfc\include\atlchecked.h(141) : error C2664: 'wcscat_s' : cannot convert parameter 1 from 'unsigned short *' to 'wchar_t *'



Why are those errors there, when I use EDGE framework?
Do I have to adjust something in VS2005 properties?
Hi Ryumaster,

It's odd that the error is coming from an official Windows header file. Try to disable or enable the built-in 'wchar' type in your C++ project settings to see if that solves the issue.

If you can't get it to work, then perhaps editing the header file is an option. Type cast the parameters to the functions that's giving the errors. For example, the first function you can typecast is the second parameter to (const unsigned short *).
Hi, edge! I can not get rid of one problem.

I'm creating window for Windows Media Player Controller using this:

Code:
//To create it inside EDGELIB
a = ClassMain::GetWindowHandle();
n_hWnd = (HWND)a;

CWMPHost frame;
frame.Create(n_hWnd, CWindow::rcDefault, _T("CE WMP Host ML"));
frame.ShowWindow(SW_SHOW);


And this is definition of CWMPhost

Code:
class CWMPHost : public CWindowImpl<CWMPHost, CWindow, CWinTraits<WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS> >



The problem is, no matter what, the video plays hidden by edge screen. I can hear only sound, and manual flipping helps not. I've tried many different parent/children combinations, and show/hide as well. Where might be the trick?
Btw, if I set this : frame.ShowWindow(SW_SHOWMAXIMIZED); , I can see my video "appearing from behind", like it trying to force it way from the back. But it is blinking and not acceptable.
Hi Ryumaster,

Can you explain more about the issue, perhaps attach a screenshot? Maybe EDGELIB tries to draw over your video window?
Hi, EDGE!
Unfortunately, I can not get screenshot - for some reason, it just shutdowns
whole application 0_0. I have made full sample, and I'll attach it to this message.

You will need Windows Media Player 10 SDK to run it, so if You dont have it, then
let it be - I'm still trying to find solution on my own. So, in case you got
everything by Your hand:

To build and run this sample, just set default wchar off, copy 1.wmv file to root
directory, comment second line at "altwin.h" file (I'm still thinking on how to fix it)

Code:
ATLTRACE(atlTraceWindowing, 0, _T("ERROR - Object deleted before window was destroyed\n"));
//ATLASSERT(FALSE); //COMMENT THIS;


and see "main.h" file.

Here what You can do with it:

1. frame.Create(n_hWnd, CWindow::rcDefault, _T("CE WMP Host ML"));

Change n_hWnd to NULL. The whole new window will be created on the top of
everything, and You will see video playing and hear the music.


2. Don't change n_hWnd, so it will receive EDGE'S window handler. Now, You will see
EDGE black screen drawn on top of the video and hear only sound.


3. Don't change n_hWnd to NULL, and set EDGE to manual flip. Now, You will not see
EDGE's black screen, but You will not see video as well - there is just caption,
and else if folder with all files like window is totaly transparent.

I'm trying to understand why video is hidden and how all this stuff works right now,
but I hope maybe it will be very easy for You to figure it out with all experience You
have got and e.t.c.
Attachments:
CEWMPHostML.rar (418 KB)
Hi Ryumaster,

Perhaps it's a good idea to get the video frames manually, and then copy them to the backbuffer. This way you have total control over the graphics. Also, it could be possible to overlay your own graphics on top of the video.
Hi! Thanks, this was the only one suitable solution. I ported ffmpeg coder libs to wince and linked them with Vs2005 and edgelib. Everything working perfectly with sounds and decoding to files, but now I'm stuck on passing video frames to edgelib buffer. When I'm writing data from frames to file, I'm using this function:
Code:
// Write pixel data
for(y=0; y<height; y++)
fwrite(pFrame->data[0]+y*pFrame->linesize[0], 1, width*3, pFile);


(pFrame hold decoded frame data).

How can I pass it to edge's buffer? Maybe something like that?

Code:
display->buffer.Lock();
ClassEMemory::Copy(display->buffer, pFrame, sizeof(pFrame),true);
display->buffer.Unlock();

Or do I have to use Blt function somehow, or put ot pixel by pixel?
Hi Ryumaster,

Locking the backbuffer and copy the frames manually is the right way to do it. However, please use the x/y pitch members of the surface to check memory layout. You can receive those by passing an E2DSURFACEINFO structure to the Lock() function.
Hi! I'm almost there, stuck at the last point. I'm using LANDSCAPE
MODE, and this code is to copy frame pixel by pixel:



Code:
for (y = 0; y < 240; y++)
{
for (x = 320 * y; x < 320 + 320 * y; x++)
{
if (lockinfo.pixelformat == EDSP_INDEXED8)
*bufptr = 0;
else if (lockinfo.pixelformat == EDSP_TRUE12 || lockinfo.pixelformat == EDSP_TRUE16 || lockinfo.pixelformat == EDSP_TRUE32)
ecd.mem->Copy(bufptr,&pFrameRGB->data[0][(y+x)*2],2,true);
bufptr += lockinfo.xpitch;
}
bufptr += lockinfo.ypitch - 320 * lockinfo.xpitch;
}



Why do I get stretched image? (attached in broken.rar)
Looking at the code, it should work fine.
I put pixel (2 bytes) 320 times in a row, adding xpitch to buffer pointer.
Then I add ypitch and substruct xpicthes added to move down to the
second row. Where is the mistake? I have tried many combinations,
but it is just now working and crashes.
The image looks like some xpicth is going missing every row. But this point of thinking brought me to nothing.
Maybe it has something to do with memory layout?
Attachments:
broken.rar (44 KB)
Hi Ryumaster,

Perhaps the size of the camera frame isn't matching the 320x240 resolution, or it has a different pitch?

Also, you need to add the buffer offset to the pointer returned by Lock(). The buffer offset can be read from the E2DSURFACEINFO structure.