2006-08-04 18:32:36 +00:00
|
|
|
/*
|
2008-05-14 17:20:42 +00:00
|
|
|
* stream layer for MPEG over UDP, based on previous work from Dave Chapman
|
2006-08-04 18:32:36 +00:00
|
|
|
*
|
2008-05-14 17:20:42 +00:00
|
|
|
* Copyright (C) 2006 Benjamin Zores
|
2006-08-04 18:32:36 +00:00
|
|
|
*
|
2008-05-14 17:20:42 +00:00
|
|
|
* This file is part of MPlayer.
|
2006-08-04 18:32:36 +00:00
|
|
|
*
|
2008-05-14 17:20:42 +00:00
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2006-08-04 18:32:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "stream.h"
|
|
|
|
#include "url.h"
|
2006-08-04 19:31:53 +00:00
|
|
|
#include "udp.h"
|
2006-08-04 18:32:36 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
udp_streaming_start (stream_t *stream)
|
|
|
|
{
|
|
|
|
streaming_ctrl_t *streaming_ctrl;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
if (!stream)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
streaming_ctrl = stream->streaming_ctrl;
|
|
|
|
fd = stream->fd;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-08-04 18:32:36 +00:00
|
|
|
if (fd < 0)
|
|
|
|
{
|
2009-07-06 23:26:13 +00:00
|
|
|
fd = udp_open_socket (streaming_ctrl->url);
|
2006-08-04 18:32:36 +00:00
|
|
|
if (fd < 0)
|
|
|
|
return -1;
|
|
|
|
stream->fd = fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
streaming_ctrl->streaming_read = nop_streaming_read;
|
|
|
|
streaming_ctrl->streaming_seek = nop_streaming_seek;
|
|
|
|
streaming_ctrl->status = streaming_playing_e;
|
2012-12-01 22:28:58 +00:00
|
|
|
stream->streaming = false;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-08-04 18:32:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
udp_stream_open (stream_t *stream, int mode, void *opts, int *file_format)
|
|
|
|
{
|
|
|
|
mp_msg (MSGT_OPEN, MSGL_INFO, "STREAM_UDP, URL: %s\n", stream->url);
|
|
|
|
stream->streaming_ctrl = streaming_ctrl_new ();
|
|
|
|
if (!stream->streaming_ctrl)
|
|
|
|
return STREAM_ERROR;
|
|
|
|
|
|
|
|
stream->streaming_ctrl->bandwidth = network_bandwidth;
|
2012-10-30 17:28:34 +00:00
|
|
|
stream->streaming_ctrl->url = url_new(stream->url);
|
2006-08-04 18:32:36 +00:00
|
|
|
|
2012-10-30 17:28:34 +00:00
|
|
|
if (stream->streaming_ctrl->url->port == 0)
|
2006-08-04 18:32:36 +00:00
|
|
|
{
|
|
|
|
mp_msg (MSGT_NETWORK, MSGL_ERR,
|
|
|
|
"You must enter a port number for UDP streams!\n");
|
|
|
|
streaming_ctrl_free (stream->streaming_ctrl);
|
|
|
|
stream->streaming_ctrl = NULL;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2007-08-28 22:38:45 +00:00
|
|
|
return STREAM_UNSUPPORTED;
|
2006-08-04 18:32:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (udp_streaming_start (stream) < 0)
|
|
|
|
{
|
|
|
|
mp_msg (MSGT_NETWORK, MSGL_ERR, "udp_streaming_start failed\n");
|
|
|
|
streaming_ctrl_free (stream->streaming_ctrl);
|
|
|
|
stream->streaming_ctrl = NULL;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2007-08-28 22:38:45 +00:00
|
|
|
return STREAM_UNSUPPORTED;
|
2006-08-04 18:32:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
stream->type = STREAMTYPE_STREAM;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2006-08-04 18:32:36 +00:00
|
|
|
return STREAM_OK;
|
|
|
|
}
|
|
|
|
|
2007-12-02 13:22:53 +00:00
|
|
|
const stream_info_t stream_info_udp = {
|
2006-08-04 18:32:36 +00:00
|
|
|
"MPEG over UDP streaming",
|
|
|
|
"udp",
|
|
|
|
"Dave Chapman, Benjamin Zores",
|
|
|
|
"native udp support",
|
|
|
|
udp_stream_open,
|
|
|
|
{ "udp", NULL},
|
|
|
|
NULL,
|
|
|
|
0 // Urls are an option string
|
|
|
|
};
|