Problem with using shmsink/shmsrc

Matthias Kattanek mkattanek at mediapointe.com
Thu May 16 10:28:25 PDT 2013


On Wed, 15 May 2013 23:04:42 -0700 (PDT) "shiva.mudugal"
<shiva.mudugal at gmail.com> wrote

> Hi Mattes,
> 
> Now, in my custom application sending side I can't use "shmsink" rather I
> should emulate what "shmsink" is doing in a native c code(without gstreamer)
> and on the receiving side I should use "shmsrc" gstreamer plugin to process
> further. Now I have started using shmpipe.[ch] for this purposes. As you
> have already done this can you please share a sample application that you
> wrote or share some hints on this.
> 
> -shiva
> 

Good, now you have the basic two (send/recv) pipelines working.
I actually followed some guidelines I got from Oliver Crete:
The API itself is pretty much documented by the shmpipe.[ch]
code itself.

  * First, create a writer with sp_writer_create()
  * And selectes() on the socket from sp_get_fd()
  * If the socket is closed or there are errors from any function, the app
  * should call sp_close() and assume the writer is dead
  * The server calls sp_writer_accept_client() when there is something to read
  * from the server fd
  * It then needs to select() on the socket from sp_writer_get_client_fd()
  * If it gets an error on that socket, it call sp_writer_close_client().
  * If there is something to read, it calls sp_writer_recv().
  *
  * The writer allocates buffers with sp_writer_alloc_block(),
  * writes something in the buffer (retrieved with sp_writer_block_get_buf(),
  * then calls  sp_writer_send_buf() to send the buffer or a subsection to
  * the other side. When it is done with the block, it calls
  * sp_writer_free_block().
  * If alloc fails, then the server must wait for events from the clients
before
  * trying again.


Here is what I am doing (roughly):
 
 - create the listener interface. 
     spipe = sp_writer_create( udSocketName, shmbufLen, FILE_MODE  );
 - wait for incoming connections
     readsocks = select( highsock+1, &socks, (fd_set *)0, (fd_set *)0,
&timeout);
 - start gstreamer shmsrc pipeline
 - receive and prep incoming connection
          sblock = sp_writer_alloc_block( spipe, shmbufLen );
          shmBuf = sp_writer_block_get_buf( sblock );
      to assign a single large shared memory buffer 
 - monitor status of the connection
         rc = sp_writer_recv( spipe, client );
 
 - frame gets fed into shmsink via
    memcpy( shmBuf, frame, shmbufLen );
    sp_writer_send_buf( spipe, shmBuf, shmbufLen );
 
I am not using dynamically allocated shm buffers as shown in
shmpipe. I opted for a single large ring buffer, which can hold multiple
frames. Not recommended, just my preference.

Look at shmpipe.[ch] for further details.

In case you are app is multi threaded, there needs to be a lock around
sp_writer_recv() and sp_writer_send_buf(), to protect spipe.

Hope that helps.

Mat




More information about the gstreamer-devel mailing list