Today learn gstshmsink plugin,main_socket and shm_area I don't understand
zhang007z
zhang007z at gmail.com
Sun Jan 17 21:25:15 PST 2016
in according to gstshmsink.c code snippet as below:
//-------------------------------------------------------------//
ShmPipe *
sp_writer_create (const char *path, size_t size, mode_t perms)
{
ShmPipe *self = spalloc_new (ShmPipe);
int flags;
struct sockaddr_un sock_un;
int i = 0;
memset (self, 0, sizeof (ShmPipe));
self->main_socket = socket (PF_UNIX, SOCK_STREAM, 0);
self->use_count = 1;
if (self->main_socket < 0)
RETURN_ERROR ("Could not create socket (%d): %s\n", errno,
strerror (errno));
flags = fcntl (self->main_socket, F_GETFL, 0);
if (flags < 0)
RETURN_ERROR ("fcntl(F_GETFL) failed (%d): %s\n", errno, strerror
(errno));
if (fcntl (self->main_socket, F_SETFL, flags | O_NONBLOCK | FD_CLOEXEC) <
0)
RETURN_ERROR ("fcntl(F_SETFL) failed (%d): %s\n", errno, strerror
(errno));
sock_un.sun_family = AF_UNIX;
strncpy (sock_un.sun_path, path, sizeof (sock_un.sun_path) - 1);
while (bind (self->main_socket, (struct sockaddr *) &sock_un,
sizeof (struct sockaddr_un)) < 0) {
if (errno != EADDRINUSE)
RETURN_ERROR ("bind() failed (%d): %s\n", errno, strerror (errno));
if (i > 256)
RETURN_ERROR ("Could not find a free socket name for %s", path);
snprintf (sock_un.sun_path, sizeof (sock_un.sun_path), "%s.%d", path,
i);
i++;
}
self->socket_path = strdup (sock_un.sun_path);
if (chmod (self->socket_path, perms) < 0)
RETURN_ERROR ("failed to set socket permissions (%d): %s\n", errno,
strerror (errno));
if (listen (self->main_socket, LISTEN_BACKLOG) < 0)
RETURN_ERROR ("listen() failed (%d): %s\n", errno, strerror (errno));
self->shm_area = sp_open_shm (NULL, ++self->next_area_id, perms, size);
self->perms = perms;
if (!self->shm_area)
RETURN_ERROR ("Could not open shm area (%d): %s", errno, strerror
(errno));
return self;
}
//-----------------------------------------------------------------------------------//
this function creates two file descriptors:
(1)self->main_socket = socket (PF_UNIX, SOCK_STREAM, 0);
(2)self->shm_area = sp_open_shm (NULL, ++self->next_area_id, perms, size);
I don't understand that what effect there is between this two file
descriptors? by this plugsin name I think it use shared-memory technology
for transforming of data,but I don't understand that socket function create
fd and what purpose it use this fd?
if anybody have any idea for me ,thank you in advance.
--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/Today-learn-gstshmsink-plugin-main-socket-and-shm-area-I-don-t-understand-tp4675320.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.
More information about the gstreamer-devel
mailing list