1 /*****************************************************************************
2  * live.c: HTTP read-only live stream
3  *****************************************************************************
4  * Copyright (C) 2015 Rémi Denis-Courmont
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation; either version 2.1 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19  *****************************************************************************/
20 
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
24 
25 #include <stdlib.h>
26 
27 #include <vlc_common.h>
28 #include "message.h"
29 #include "resource.h"
30 #include "live.h"
31 
32 #pragma GCC visibility push(default)
33 
vlc_http_live_req(const struct vlc_http_resource * res,struct vlc_http_msg * req,void * opaque)34 static int vlc_http_live_req(const struct vlc_http_resource *res,
35                              struct vlc_http_msg *req, void *opaque)
36 {
37     vlc_http_msg_add_header(req, "Accept-Encoding", "gzip, deflate");
38     (void) res;
39     (void) opaque;
40     return 0;
41 }
42 
vlc_http_live_resp(const struct vlc_http_resource * res,const struct vlc_http_msg * resp,void * opaque)43 static int vlc_http_live_resp(const struct vlc_http_resource *res,
44                               const struct vlc_http_msg *resp, void *opaque)
45 {
46     (void) res;
47     (void) resp;
48     (void) opaque;
49     return 0;
50 }
51 
52 static const struct vlc_http_resource_cbs vlc_http_live_callbacks =
53 {
54     vlc_http_live_req,
55     vlc_http_live_resp,
56 };
57 
vlc_http_live_create(struct vlc_http_mgr * mgr,const char * uri,const char * ua,const char * ref)58 struct vlc_http_resource *vlc_http_live_create(struct vlc_http_mgr *mgr,
59                                                const char *uri, const char *ua,
60                                                const char *ref)
61 {
62     struct vlc_http_resource *res = malloc(sizeof (*res));
63     if (unlikely(res == NULL))
64         return NULL;
65 
66     if (vlc_http_res_init(res, &vlc_http_live_callbacks, mgr, uri, ua, ref))
67     {
68         free(res);
69         res = NULL;
70     }
71 
72     return res;
73 }
74 
vlc_http_live_read(struct vlc_http_resource * res)75 block_t *vlc_http_live_read(struct vlc_http_resource *res)
76 {
77     struct block_t *block = vlc_http_res_read(res);
78     if (block != NULL && block != vlc_http_error)
79         return block;
80 
81     /* Automatically try to reconnect */
82     /* TODO: Retry-After parsing, loop and pacing timer */
83     vlc_http_msg_destroy(res->response);
84     res->response = NULL;
85     return vlc_http_res_read(res);
86 }
87