Solved

Data passing

Posted on 2011-03-22
6
394 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
  • 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 33

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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
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 33

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Step by step guide to Clean and Sort your windows registry! Introduction: Always remember: A Clean registry = Better performance = Save your invaluable time In this article we're going to clear our registry manually! Yes, manually! The e…
It is only natural that we all want our PCs to be in good working order, improved system performance, so that is exactly how programs are advertised to entice. They say things like:            •      PC crashes? Get registry cleaner to repair it!    …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

828 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