~ubuntu-branches/ubuntu/raring/gst-plugins-good0.10/raring-proposed

« back to all changes in this revision

Viewing changes to sys/shm/shmpipe.c

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2012-02-09 16:44:53 UTC
  • mfrom: (40.2.38 experimental)
  • Revision ID: package-import@ubuntu.com-20120209164453-6hjokwrvdn42zopb
Tags: 0.10.30.3-1ubuntu1
* Merge from Debian experimental, remaining changes:
  - 04_move_farsight_plugins_to_good.patch
    Import autoconvert, dtmf, liveadder, rptmux from -plugins-bad
  - 05_move_shm_to_good.patch
    Import shm from -plugins-bad.
  - 07_move-camerabin.patch
    Import camerabin, camerabin2, jpegformat and basecamerabinsrc
    from -plugins-bad.
  - control*:
    * Drop dependency from gstreamer0.10-plugins-good on
      gstreamer0.10-gconf. It pulls gconf and gtk3 onto the Kubuntu cd.
    * Use Breaks instead of Conflicts.
    * Add a 'Pre-Depends: ${misc:Pre-Depends}' to the plugin package,
      since we're shipping shared libraries in the package that Debian
      isn't.
* Update the patches by pulling new version of the code from
  -plugins-bad 0.10.22.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
78
78
};
79
79
 
80
80
typedef struct _ShmArea ShmArea;
81
 
typedef struct _ShmBuffer ShmBuffer;
82
81
 
83
82
struct _ShmArea
84
83
{
112
111
 
113
112
  int num_clients;
114
113
  int clients[0];
 
114
 
 
115
  uint64_t tag;
115
116
};
116
117
 
117
118
 
192
193
{
193
194
  ShmPipe *self = spalloc_new (ShmPipe);
194
195
  int flags;
195
 
  struct sockaddr_un sun;
 
196
  struct sockaddr_un sock_un;
196
197
  int i = 0;
197
198
 
198
199
  memset (self, 0, sizeof (ShmPipe));
211
212
  if (fcntl (self->main_socket, F_SETFL, flags | O_NONBLOCK | FD_CLOEXEC) < 0)
212
213
    RETURN_ERROR ("fcntl(F_SETFL) failed (%d): %s\n", errno, strerror (errno));
213
214
 
214
 
  sun.sun_family = AF_UNIX;
215
 
  strncpy (sun.sun_path, path, sizeof (sun.sun_path) - 1);
 
215
  sock_un.sun_family = AF_UNIX;
 
216
  strncpy (sock_un.sun_path, path, sizeof (sock_un.sun_path) - 1);
216
217
 
217
 
  while (bind (self->main_socket, (struct sockaddr *) &sun,
 
218
  while (bind (self->main_socket, (struct sockaddr *) &sock_un,
218
219
          sizeof (struct sockaddr_un)) < 0) {
219
220
    if (errno != EADDRINUSE)
220
221
      RETURN_ERROR ("bind() failed (%d): %s\n", errno, strerror (errno));
222
223
    if (i > 256)
223
224
      RETURN_ERROR ("Could not find a free socket name for %s", path);
224
225
 
225
 
    snprintf (sun.sun_path, sizeof (sun.sun_path), "%s.%d", path, i);
 
226
    snprintf (sock_un.sun_path, sizeof (sock_un.sun_path), "%s.%d", path, i);
226
227
    i++;
227
228
  }
228
229
 
229
 
  self->socket_path = strdup (sun.sun_path);
 
230
  self->socket_path = strdup (sock_un.sun_path);
230
231
 
231
232
  if (listen (self->main_socket, LISTEN_BACKLOG) < 0)
232
233
    RETURN_ERROR ("listen() failed (%d): %s\n", errno, strerror (errno));
262
263
sp_open_shm (char *path, int id, mode_t perms, size_t size)
263
264
{
264
265
  ShmArea *area = spalloc_new (ShmArea);
265
 
  char tmppath[PATH_MAX];
 
266
  char tmppath[32];
266
267
  int flags;
267
268
  int prot;
268
269
  int i = 0;
285
286
    area->shm_fd = shm_open (path, flags, perms);
286
287
  } else {
287
288
    do {
288
 
      snprintf (tmppath, PATH_MAX, "/shmpipe.5%d.%5d", getpid (), i++);
 
289
      snprintf (tmppath, sizeof (tmppath), "/shmpipe.%5d.%5d", getpid (), i++);
289
290
      area->shm_fd = shm_open (tmppath, flags, perms);
290
291
    } while (area->shm_fd < 0 && errno == EEXIST);
291
292
  }
542
543
/* Returns the number of client this has successfully been sent to */
543
544
 
544
545
int
545
 
sp_writer_send_buf (ShmPipe * self, char *buf, size_t size)
 
546
sp_writer_send_buf (ShmPipe * self, char *buf, size_t size, uint64_t tag)
546
547
{
547
548
  ShmArea *area = NULL;
548
549
  unsigned long offset = 0;
577
578
  sb->size = size;
578
579
  sb->num_clients = self->num_clients;
579
580
  sb->ablock = ablock;
 
581
  sb->tag = tag;
580
582
 
581
583
  for (client = self->clients; client; client = client->next) {
582
584
    struct CommandBuffer cb = { 0 };
621
623
sp_client_recv (ShmPipe * self, char **buf)
622
624
{
623
625
  char *area_name = NULL;
624
 
  ShmArea *newarea, *oldarea;
 
626
  ShmArea *newarea;
625
627
  ShmArea *area;
626
628
  struct CommandBuffer cb;
627
629
  int retval;
648
650
      if (!newarea)
649
651
        return -4;
650
652
 
651
 
      oldarea = self->shm_area;
652
653
      newarea->next = self->shm_area;
653
654
      self->shm_area = newarea;
654
 
      /*
655
 
         if (oldarea)
656
 
         sp_shm_area_dec (self, oldarea);
657
 
       */
658
655
      break;
659
656
 
660
657
    case COMMAND_CLOSE_SHM_AREA:
744
741
sp_client_open (const char *path)
745
742
{
746
743
  ShmPipe *self = spalloc_new (ShmPipe);
747
 
  struct sockaddr_un sun;
 
744
  struct sockaddr_un sock_un;
748
745
 
749
746
  memset (self, 0, sizeof (ShmPipe));
750
747
 
754
751
  if (self->main_socket < 0)
755
752
    goto error;
756
753
 
757
 
  sun.sun_family = AF_UNIX;
758
 
  strncpy (sun.sun_path, path, sizeof (sun.sun_path) - 1);
 
754
  sock_un.sun_family = AF_UNIX;
 
755
  strncpy (sock_un.sun_path, path, sizeof (sock_un.sun_path) - 1);
759
756
 
760
 
  if (connect (self->main_socket, (struct sockaddr *) &sun,
 
757
  if (connect (self->main_socket, (struct sockaddr *) &sock_un,
761
758
          sizeof (struct sockaddr_un)) < 0)
762
759
    goto error;
763
760
 
897
894
{
898
895
  return pipe->socket_path;
899
896
}
 
897
 
 
898
ShmBuffer *
 
899
sp_writer_get_pending_buffers (ShmPipe * self)
 
900
{
 
901
  return self->buffers;
 
902
}
 
903
 
 
904
ShmBuffer *
 
905
sp_writer_get_next_buffer (ShmBuffer * buffer)
 
906
{
 
907
  return buffer->next;
 
908
}
 
909
 
 
910
uint64_t
 
911
sp_writer_buf_get_tag (ShmBuffer * buffer)
 
912
{
 
913
  return buffer->tag;
 
914
}