?
Solved

Data passing

Posted on 2011-03-22
6
Medium Priority
?
397 Views
Last Modified: 2012-05-11
I'm working on a DLL which will serve as the back end or engine for an arbitrary Win32 GUI front end to connect to. My back end should have no graphical code, of course. What I'm making is an interface for a camera-like device. This device has an SDK I'm using which utilizes CALLBACKs. Through several of these callbacks, which run in their own thread, I receive an image (as an object) from the camera device. I need an efficient way to forward this image to the Win32 GUI developer without exposing him to the SDK's callback functions. This image must be immediately forwarded because the Win32 Developer may want to display it the moment it is received, as these images are continually streaming from the device. (Ultimately, if you were to display the images as they came from the device, what you would get is a video in real-time of the images being captured by the device).

I'm not asking anyone here to solve my problem, but, as an entry level coder, I would like input as to what my options are and what the pros and cons are to each solution. I am concerned with speed.

I'm using MS VS 2008 on Windows XP to write the DLL in C++. The SDK is a DLL and static LIB written in C using an unknown compiler. I don't know how relevant that info is, but, there it is.
0
Comment
Question by:Josiah14
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 31

Expert Comment

by:moorhouselondon
ID: 35196661
Question to ask is whether you are simply sampling what happens on the camera, the point at which you say "data please" is effectively like a shutter release.  

I would start by dumping the output to files to see if that works.  If it does, how quickly can files be constructed?  Is that fast enough?  If so, your GUI Developer could just be told that the sequence of files is held in the image dump directory, the file names are in sequential order.  Last thing you want is for the GUI app to hold the data requester from firing, which would result in lost data.
0
 
LVL 35

Accepted Solution

by:
sarabande earned 1800 total points
ID: 35197646
(1) you adopt the callback technique

the gui makes a request by calling a function in your dll and passes a callback function pointer. when you got the image for the request you call the callback passing the image with that call.

advantage: known technique, fast, allows direct pointer access
disadvantage: passes responsibility to gui. callback runs asynchronously in own thread-context,

(2) you write to shared memory and notify the gui when done

the gui makes a request by calling a function in your dll and passes a handle to a memory mapped file (shared memory) where you could write (copy) the image to. after write you notify success by posting a windows message to the gui.

advantage: fast and safe exchange. you also could provide the handle for the shared memory yourself as return to the request.

disadvantage: needs additional call for clearing the memory. uses additional system resources. can give additional sync problems when updating the image continuously.

Sara



0
 

Author Comment

by:Josiah14
ID: 35199095
Perhaps I should clarify, the device is a camera, but it is continually taking pictures.  Part of the objective is to allow the GUI to catch the streaming images from the device to make a sort-of 2D animation of what the camera "sees" in real-time.  This is the real difficulty at the moment, for taking the image from the camera and throwing it out to the GUI in an object is as simple as a regular method call, but I need to be able to give the GUI a way of knowing when the image is available so every time the camera produces the image, the GUI has the option to display it.  Outputting the image to the file system will not work as it will certainly be too slow.

I had considered using callbacks, but had not considered writing to shared memory.  Since the GUI will have a WinProc anyway, this could be a good method.  For what we want to do, the user has to explicitly make a call for memory cleanup already, so I could just throw that in with the device object cleanup.  I dunno if actually writing the image data to a file in shared memory would be too much overhead, though...  Something for me to consider.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 31

Assisted Solution

by:moorhouselondon
moorhouselondon earned 200 total points
ID: 35202832
Another thing to consider is to use delta techniques.  If the camera is in a fixed position then the first sample will be of all pixels.  Subsequent calls can be just of the changes that have occurred since the last sample.  this will substantially cut down data traffic and is a well-known technique used in security monitoring.
0
 
LVL 35

Assisted Solution

by:sarabande
sarabande earned 1800 total points
ID: 35205385
the overhead for shared memory can be neglected if you use a sufficient large piece of memory where you could store more than one picture in a kind of ring buffer. that would decrease the amount of needed synchronisation to the overflow case where a camera has produced more pictures not yet displayed than the memory could take.

Sara
0
 

Author Closing Comment

by:Josiah14
ID: 35207095
This is great.  There's some applicable suggestions here that I never would have thought of.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We have adopted the strategy to use Computers in Student Labs as the bulletin boards. The same target can be achieved by using a Login Notice feature in Group policy but it’s not as attractive as graphical wallpapers with message which grabs the att…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question