1 /*****************************************************************************
2 * dash.cpp: DASH module
3 *****************************************************************************
4 * Copyright (C) 2010 - 2011 Klagenfurt University
6 * Created on: Aug 10, 2010
7 * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
8 * Christian Timmerer <christian.timmerer@itec.uni-klu.ac.at>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published
12 * by the Free Software Foundation; either version 2.1 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
34 #include <vlc_common.h>
35 #include <vlc_plugin.h>
36 #include <vlc_demux.h>
37 #include <vlc_stream.h>
38 #include <vlc_modules.h>
39 #include <vlc_input.h>
48 #include "DASHManager.h"
49 #include "xml/DOMParser.h"
50 #include "http/HTTPConnectionManager.h"
51 #include "adaptationlogic/IAdaptationLogic.h"
55 /*****************************************************************************
57 *****************************************************************************/
58 static int Open (vlc_object_t *);
59 static void Close (vlc_object_t *);
62 set_shortname( N_("DASH"))
63 set_description( N_("Dynamic Adaptive Streaming over HTTP") )
64 set_capability( "stream_filter", 19 )
65 set_category( CAT_INPUT )
66 set_subcategory( SUBCAT_INPUT_STREAM_FILTER )
67 set_callbacks( Open, Close )
69 /*****************************************************************************
71 *****************************************************************************/
74 dash::DASHManager *p_dashManager;
75 dash::http::HTTPConnectionManager *p_conManager;
76 dash::xml::Node *p_node;
81 static int Read (stream_t *p_stream, void *p_buffer, unsigned int i_len);
82 static int Peek (stream_t *p_stream, const uint8_t **pp_peek, unsigned int i_peek);
83 static int Control (stream_t *p_stream, int i_query, va_list args);
84 static bool IsDash (stream_t *p_stream, dash::xml::DOMParser *p_parser);
85 /*****************************************************************************
87 *****************************************************************************/
88 static int Open(vlc_object_t *p_this)
90 stream_t *p_stream = (stream_t*) p_this;
92 dash::xml::DOMParser *p_parser = new dash::xml::DOMParser(p_stream->p_source);
94 if(!IsDash(p_stream, p_parser))
100 stream_sys_t *p_sys = (stream_sys_t *) malloc(sizeof(stream_sys_t));
102 if (unlikely(p_sys == NULL))
105 dash::http::HTTPConnectionManager *p_conManager = new dash::http::HTTPConnectionManager(p_stream);
106 dash::xml::Node *p_node = p_parser->getRootNode();
107 dash::DASHManager *p_dashManager = new dash::DASHManager(p_conManager,
109 dash::logic::IAdaptationLogic::RateBased,
110 p_parser->getProfile(p_node));
113 p_sys->p_dashManager = p_dashManager;
114 p_sys->p_node = p_node;
115 p_sys->p_conManager = p_conManager;
117 p_sys->isLive = true;
118 p_stream->p_sys = p_sys;
119 p_stream->pf_read = Read;
120 p_stream->pf_peek = Peek;
121 p_stream->pf_control = Control;
123 msg_Dbg(p_this,"DASH filter: open (%s)", p_stream->psz_path);
127 /*****************************************************************************
129 *****************************************************************************/
130 static void Close(vlc_object_t *p_this)
132 stream_t *p_stream = (stream_t*) p_this;
133 stream_sys_t *p_sys = (stream_sys_t *) p_stream->p_sys;
134 dash::DASHManager *p_dashManager = p_sys->p_dashManager;
135 dash::http::HTTPConnectionManager *p_conManager = p_sys->p_conManager;
136 dash::xml::Node *p_node = p_sys->p_node;
138 delete(p_conManager);
139 delete(p_dashManager);
143 /*****************************************************************************
145 *****************************************************************************/
146 static int Read (stream_t *p_stream, void *p_buffer, unsigned int i_len)
148 stream_sys_t *p_sys = (stream_sys_t *) p_stream->p_sys;
149 dash::DASHManager *p_dashManager = p_sys->p_dashManager;
152 i_ret = p_dashManager->read(p_buffer, i_len);
162 msg_Dbg(p_stream, "DASH Read: failed to read (%m)");
168 p_sys->position += i_ret;
172 static int Peek (stream_t *p_stream, const uint8_t **pp_peek, unsigned int i_peek)
174 stream_sys_t *p_sys = (stream_sys_t *) p_stream->p_sys;
175 dash::DASHManager *p_dashManager = p_sys->p_dashManager;
177 return p_dashManager->peek(pp_peek, i_peek);
179 static int Control (stream_t *p_stream, int i_query, va_list args)
181 stream_sys_t *p_sys = p_stream->p_sys;
185 case STREAM_CAN_SEEK:
186 case STREAM_CAN_FASTSEEK:
187 /*TODO Support Seek */
188 *(va_arg (args, bool *)) = SEEK;
190 case STREAM_GET_POSITION:
191 *(va_arg (args, uint64_t *)) = p_sys->position;
193 case STREAM_SET_POSITION:
195 case STREAM_GET_SIZE:
197 *(va_arg (args, uint64_t *)) = 0;
204 /*****************************************************************************
206 *****************************************************************************/
207 static bool IsDash (stream_t *p_stream, dash::xml::DOMParser *p_parser)
209 if(!p_parser->isDash())
211 msg_Dbg(p_stream,"DASH filter: file is no mpd");
215 if(!p_parser->parse())
217 msg_Dbg(p_stream,"DASH filter: could not parse file");