[MPlayer-users] streaming mplayer

Jerry Geis geisj at pagestation.com
Tue Sep 25 21:57:27 CEST 2007


I am starting mplayer with a command like:
 mplayer  http://camera/img/video.asf  -dumpstream -dumpfile 
/tmp/fifofile.mp4

I then wrote a small program that reads from /tmp/fifofile.mp4 and sends 
it out over
connecting sockets.

The first mplayer  connection reads and shows the camera data.
The second mplayer connection says "filling cache" and never displays 
anything.

Is there something wrong about what  I am attempting?
Can I not just "relay" the mp4 data that is read from the fifo?
I also tried "mencoder -o fifofile.mp4 -oac copy -ovc copy 
http://camera/img/video.asf"
but I get the same result.

Thanks,

Jerry
------------

for(i = 0; i < MAX_STREAMING; i++)
	{
	stream_fd[i] = -1;
	}

stream_input_file_fd = open(file_name, O_RDONLY);

fd = SystemSocketReceive(listen_port, &socket_fd);
goto first_connection;

while(1)
	{
	int new_connections;

	/* check for new connections */
	for(new_connections = TRUE; new_connections; )
		{
		fd_set readfs;
		struct timeval timeout;

		timeout.tv_usec = 10;
		timeout.tv_sec = 0;
	
		new_connections = FALSE;

		FD_ZERO(&readfs);
		FD_SET(socket_fd, &readfs);
		ret = select(socket_fd + 1, &readfs, NULL, NULL, &timeout);
		
		if(FD_ISSET(socket_fd, &readfs))
			{
			fd = SystemSocketAccept(socket_fd);
			if(fd >= 0)
				{
				/* add new connection to the list of streaming data */
				for(i = 0; i < MAX_STREAMING; i++)
					{
					if(stream_fd[i] < 0)
						{
						/* additional connections */
						stream_fd[i] = fd;
						write(stream_fd[i], server_response, strlen(server_response)); 
	
						new_connections = TRUE;
						total_connections++;
						break;

first_connection:				/* first connection */
						stream_fd[0] = fd;
						write(stream_fd[0], server_response, strlen(server_response)); 
						new_connections = TRUE;
						total_connections++;
						break;
						}
					}
				}
			}
		}

	/* check for the duration having expired */
	if((time(NULL) - start_time) >= duration)
		{
		goto duration_over;
		}
	
	stream_read_size = read(stream_input_file_fd, stream_data, sizeof(stream_data));	

	if(stream_read_size < 0)
		{
duration_over:
		/* error in data so close everything and exit */
		for(i = 0; i < MAX_STREAMING; i++)
			{
			if(stream_fd[i] >= 0)
				{
				close(fd);
				}
			}

		break;
		}
	else if(stream_read_size == 0)
		{
		printf("Waiting on data in file\n");
		usleep(1000);				/* no data at this time */
		}
	else
		{
		for(i = 0; i < MAX_STREAMING; i++)
			{
			if(stream_fd[i] >= 0)
				{
				if(write(stream_fd[i], stream_data, stream_read_size) < 0)
					{
					printf("Error on stream %d, closing connection.\n", i);
					close(stream_fd[i]);
					stream_fd[i] = -1;
					}
				}
			}
		}
	}

close(stream_input_file_fd);
close(socket_fd);

return(ret);







More information about the MPlayer-users mailing list