Solved

Data passing

Posted on 2011-03-22
6
396 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 34

Accepted Solution

by:
sarabande earned 450 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
Technology Partners: 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!

 
LVL 31

Assisted Solution

by:moorhouselondon
moorhouselondon earned 50 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 34

Assisted Solution

by:sarabande
sarabande earned 450 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

cPanel is a Unix based web hosting control panel that provides a graphical interface and automation tools designed to simplify the process of hosting a web site. cPanel utilizes a 3 tier structure that provides functionality for administrators, rese…
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

724 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