Solved

Data passing

Posted on 2011-03-22
6
392 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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!    …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

911 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now