2

I have frames of a Video with 30FPS in my C# code and I want to broadcast it in local host so all other applications can use it. I though because it is a video and there is no concern if any packet lost and no need to connect/accept from clients, UDP is a good choose.

But there are number of problems here.

  • If I use UDP Unicast speed is enough, about 25FPS (CPU Usage is 25% that mean 100% on one thread in my 4 core CPU which is not ideal. But at least it send enough set of data). But unicast cant deliver data to all clients.
  • If I use broadcast speed is very low. About 10FPS with same CPU usage.

What can I do?! Data are in same computer so there is no need to remote access from LAN or etc. I just want a way to transfer about 30MBytes of data per second between different applications of same machine. (640x480 is fixed size of Image x 30fps x 3byte per pixel is about 27000KByte per second)

  1. Is UDP Multicast has better performance?!
  2. Is TCP can give me better performance even if I accept each client and send to them independently?!
  3. Is there any better way than Socket?! Memory sharing or something?!
  4. Why UDP broadcast is that much slow?! Only about 10MBytes per second?!
  5. Is there a fast way to compress frames with high performance (to encode 30fps in a sec and decode on other part)? Client apps are in C++ so this must be a cross platform way.

I just want to know other developers experiences and ideas here so please write what you think.

Edit:

More info about data: Data are in Bitmap RGB24 format and they are streaming from a device to my application with 30FPS. I want to broadcast this data to other applications and they need to have this images in RGB24 format again. There is no header or any thing, only bitmap data with fixed size. All operations must perform on the fly. No matter of using a lossy compression algorithm or any thing.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Soroush Falahati
  • 2,196
  • 1
  • 27
  • 38
  • Is there some reason one of the many existing streaming video protocols is unsuitable and why using one of the many video streaming solutions won't work? This is a problem that has been solved a number of different ways. Surely one of those ways ought to meet your needs and not require to you reinvent the wheel. – Pete Feb 18 '13 at 17:38
  • @Pete, Do you know any UDP based cross platform (.Net, C++) video streaming library?! Unfortunately I cant find one. Because implementing one of these protocols without a library is not easier then inventing whole solution. – Soroush Falahati Feb 18 '13 at 17:47
  • Isn't FFMPEG a commend line application to convert (encode/decode) video formats?! How can I use it for Streaming of Bitmap objects in .Net?! – Soroush Falahati Feb 18 '13 at 18:08

2 Answers2

2

I experiment Multicast in an industrial environment, it's a good choice over a not staturated reliable network.

In local host, shared memory may be a good choice because you may build a circular queue of frames and flip from one to the next only with a single mutex to protect a pointer assignment (writter side). With one writter, several reader, no problem arise.

On Windows with C++ and C#, shared memory is called File Mapping, but you may use system paging file (RAM and/or disk).

See these links to more information

The shared memory space isn't protected nor private but it'd named.

Usually, the writer process creates it, and the readers opens it by its name. Antivirus softwares takes a look at this kind of I/O in a same fashion as they do for all others but don't block the communication.

Here is a sample to begin with File Mapping:

char shmName[MAX_PATH+1];
sprintf( shmName, "shmVideo_%s", name );
shmName[MAX_PATH] = '\0';
_hMap =
   CreateFileMapping(
      INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, size, shmName );
if( _hMap == 0 ) {
   throw OSException( __FILE__, __LINE__ );
}
_owner = ( GetLastError() != ERROR_ALREADY_EXISTS );
_mutex = Mutex::getMutex( name );
Synchronize sync( *_mutex );
_data = (char *)MapViewOfFile( _hMap, FILE_MAP_ALL_ACCESS, 0, 0, 0 );
if( _data == 0 ) {
   throw OSException( __FILE__, __LINE__ );
}
Community
  • 1
  • 1
Aubin
  • 14,617
  • 9
  • 61
  • 84
  • This seems like a good answer. Thanks, But I have number of question about memory mapped files. First, How can I access an other managed process memory file from my unmanaged side (C++ clients)?! And second, What about user privileges, antiviruses and other security softwares/limits?! – Soroush Falahati Feb 20 '13 at 21:06
  • Ok thanks. Let me take a look and I will accept your answer. Currently I cant give bounty because it need more 7 hours :) – Soroush Falahati Feb 20 '13 at 22:12
  • Currently using Memory Mapped Files and it has very good performance. Fortunately there was no problem with accessing it from managed and unmanaged side. Only thing some one may need to take care is multi process writes that need little precision. Thanks. – Soroush Falahati Feb 21 '13 at 16:29
0

Use live555 http://www.live555.com/ for streaming in combination with your favorite compressor - ffmpeg.

Markus Schumann
  • 7,636
  • 1
  • 21
  • 27
  • So how can I use it to send Bitmaps of data?! It is a Live cam so I cant save them to disk then convert them to video using FFMPEG and then send them using Live555! I need some sort of real time solution which is capable of encoding 30 bitmap from memory to video (again in memory, and bitmaps are streaming so they are not available when app start) and then using an other solution (or same library, or I can write this sending part) send them to other apps. They also must can decode data to frames of RGB data in memory. – Soroush Falahati Feb 19 '13 at 19:29