Commit e02e73ca authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

https: old-style live streaming (http-continuous) helper

parent 3f0a94de
......@@ -7,6 +7,7 @@ libvlc_http_la_SOURCES = \
access/http/message.c access/http/message.h \
access/http/resource.c access/http/resource.h \
access/http/file.c access/http/file.h \
access/http/live.c access/http/live.h \
access/http/hpack.c access/http/hpack.h access/http/hpackenc.c \
access/http/h2frame.c access/http/h2frame.h \
access/http/h2output.c access/http/h2output.h \
......
......@@ -32,14 +32,19 @@
#include "connmgr.h"
#include "file.h"
#include "live.h"
struct access_sys_t
{
struct vlc_http_mgr *manager;
struct vlc_http_file *file;
union
{
struct vlc_http_file *file;
struct vlc_http_live *live;
};
};
static block_t *Read(access_t *access)
static block_t *FileRead(access_t *access)
{
access_sys_t *sys = access->p_sys;
......@@ -49,7 +54,7 @@ static block_t *Read(access_t *access)
return b;
}
static int Seek(access_t *access, uint64_t pos)
static int FileSeek(access_t *access, uint64_t pos)
{
access_sys_t *sys = access->p_sys;
access->info.b_eof = false;
......@@ -59,7 +64,7 @@ static int Seek(access_t *access, uint64_t pos)
return VLC_SUCCESS;
}
static int Control(access_t *access, int query, va_list args)
static int FileControl(access_t *access, int query, va_list args)
{
access_sys_t *sys = access->p_sys;
......@@ -102,7 +107,51 @@ static int Control(access_t *access, int query, va_list args)
default:
return VLC_EGENERIC;
}
return VLC_SUCCESS;
}
static block_t *LiveRead(access_t *access)
{
access_sys_t *sys = access->p_sys;
block_t *b = vlc_http_live_read(sys->live);
if (b == NULL) /* TODO: loop instead of EOF, see vlc_http_live_read() */
access->info.b_eof = true;
return b;
}
static int NoSeek(access_t *access, uint64_t pos)
{
(void) access;
(void) pos;
return VLC_EGENERIC;
}
static int LiveControl(access_t *access, int query, va_list args)
{
access_sys_t *sys = access->p_sys;
switch (query)
{
case ACCESS_CAN_SEEK:
case ACCESS_CAN_FASTSEEK:
case ACCESS_CAN_PAUSE:
case ACCESS_CAN_CONTROL_PACE:
*va_arg(args, bool *) = false;
break;
case ACCESS_GET_PTS_DELAY:
*va_arg(args, int64_t *) = var_InheritInteger(access,
"network-caching");
break;
case ACCESS_GET_CONTENT_TYPE:
*va_arg(args, char **) = vlc_http_live_get_type(sys->live);
break;
default:
return VLC_EGENERIC;
}
return VLC_SUCCESS;
}
......@@ -111,9 +160,6 @@ static int Open(vlc_object_t *obj)
{
access_t *access = (access_t *)obj;
if (var_InheritBool(obj, "http-continuous"))
return VLC_EGENERIC; /* FIXME not implemented yet */
char *proxy = vlc_getProxyUrl(access->psz_url);
free(proxy);
if (proxy != NULL)
......@@ -139,15 +185,35 @@ static int Open(vlc_object_t *obj)
goto error;
char *ua = var_InheritString(obj, "http-user-agent");
char *ref = var_InheritString(obj, "http-referrer");
sys->file = vlc_http_file_create(sys->manager, access->psz_url, ua, ref);
free(ref);
char *referer = var_InheritString(obj, "http-referrer");
bool live = var_InheritBool(obj, "http-continuous");
if (live)
sys->live = vlc_http_live_create(sys->manager, access->psz_url, ua,
referer);
else
sys->file = vlc_http_file_create(sys->manager, access->psz_url, ua,
referer);
free(referer);
free(ua);
if (sys->file == NULL)
goto error;
char *redir = vlc_http_file_get_redirect(sys->file);
char *redir;
if (live)
{
if (sys->live == NULL)
goto error;
redir = vlc_http_live_get_redirect(sys->live);
}
else
{
if (sys->file == NULL)
goto error;
redir = vlc_http_file_get_redirect(sys->file);
}
if (redir != NULL)
{
access->psz_url = redir;
......@@ -157,7 +223,8 @@ static int Open(vlc_object_t *obj)
ret = VLC_EGENERIC;
int status = vlc_http_file_get_status(sys->file);
int status = live ? vlc_http_live_get_status(sys->live)
: vlc_http_file_get_status(sys->file);
if (status < 0)
{
msg_Err(access, "HTTP connection failure");
......@@ -173,9 +240,18 @@ static int Open(vlc_object_t *obj)
access->info.b_eof = false;
access->pf_read = NULL;
access->pf_block = Read;
access->pf_seek = Seek;
access->pf_control = Control;
if (live)
{
access->pf_block = LiveRead;
access->pf_seek = NoSeek;
access->pf_control = LiveControl;
}
else
{
access->pf_block = FileRead;
access->pf_seek = FileSeek;
access->pf_control = FileControl;
}
access->p_sys = sys;
return VLC_SUCCESS;
......@@ -193,7 +269,10 @@ static void Close(vlc_object_t *obj)
access_t *access = (access_t *)obj;
access_sys_t *sys = access->p_sys;
vlc_http_file_destroy(sys->file);
if (access->pf_block == LiveRead)
vlc_http_live_destroy(sys->live);
else
vlc_http_file_destroy(sys->file);
vlc_http_mgr_destroy(sys->manager);
free(sys);
}
......
/*****************************************************************************
* live.c: HTTP read-only live stream
*****************************************************************************
* Copyright (C) 2015 Rémi Denis-Courmont
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <vlc_common.h>
#include "message.h"
#include "resource.h"
#include "live.h"
#pragma GCC visibility push(default)
struct vlc_http_live
{
struct vlc_http_resource resource;
struct vlc_http_msg *resp;
};
static int vlc_http_live_req(struct vlc_http_msg *req,
const struct vlc_http_resource *res, void *opaque)
{
#if 0 // TODO
vlc_http_msg_add_header(req, "Accept-Encoding", "gzip, deflate");
#else
(void) req;
#endif
(void) res;
(void) opaque;
return 0;
}
static struct vlc_http_msg *vlc_http_live_open(struct vlc_http_live *live)
{
return vlc_http_res_open(&live->resource, vlc_http_live_req, NULL);
}
void vlc_http_live_destroy(struct vlc_http_live *live)
{
if (live->resp != NULL)
vlc_http_msg_destroy(live->resp);
vlc_http_res_deinit(&live->resource);
free(live);
}
struct vlc_http_live *vlc_http_live_create(struct vlc_http_mgr *mgr,
const char *uri, const char *ua,
const char *ref)
{
struct vlc_http_live *live = malloc(sizeof (*live));
if (unlikely(live == NULL))
return NULL;
if (vlc_http_res_init(&live->resource, mgr, uri, ua, ref))
{
free(live);
return NULL;
}
live->resp = NULL;
return live;
}
int vlc_http_live_get_status(struct vlc_http_live *live)
{
if (live->resp == NULL)
{
live->resp = vlc_http_live_open(live);
if (live->resp == NULL)
return -1;
}
return vlc_http_msg_get_status(live->resp);
}
char *vlc_http_live_get_redirect(struct vlc_http_live *live)
{
if (vlc_http_live_get_status(live) < 0)
return NULL;
return vlc_http_res_get_redirect(&live->resource, live->resp);
}
char *vlc_http_live_get_type(struct vlc_http_live *live)
{
if (vlc_http_live_get_status(live) < 0)
return NULL;
return vlc_http_res_get_type(live->resp);
}
block_t *vlc_http_live_read(struct vlc_http_live *live)
{
if (vlc_http_live_get_status(live) < 0)
return NULL;
struct block_t *block = vlc_http_res_read(live->resp);
if (block != NULL)
return block;
/* Automatically try to reconnect */
/* TODO: Retry-After parsing, loop and pacing timer */
vlc_http_msg_destroy(live->resp);
live->resp = NULL;
if (vlc_http_live_get_status(live) < 0)
return NULL;
return vlc_http_res_read(live->resp);
}
/*****************************************************************************
* live.h: HTTP read-only live stream declarations
*****************************************************************************
* Copyright (C) 2015 Rémi Denis-Courmont
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
struct vlc_http_live;
struct block_t;
struct vlc_http_live *vlc_http_live_create(struct vlc_http_mgr *mgr,
const char *uri, const char *ua,
const char *ref);
void vlc_http_live_destroy(struct vlc_http_live *live);
int vlc_http_live_get_status(struct vlc_http_live *live);
char *vlc_http_live_get_redirect(struct vlc_http_live *live);
char *vlc_http_live_get_type(struct vlc_http_live *live);
block_t *vlc_http_live_read(struct vlc_http_live *live);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment