1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
/*****************************************************************************
* DASHManager.cpp
*****************************************************************************
* Copyright © 2010 - 2011 Klagenfurt University
*
* Created on: Aug 10, 2010
* Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
* Christian Timmerer <christian.timmerer@itec.uni-klu.ac.at>
*
* 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 <vlc_fixups.h>
#include <cinttypes>
#include "DASHManager.h"
#include "mpd/ProgramInformation.h"
#include "mpd/IsoffMainParser.h"
#include "xml/DOMParser.h"
#include "xml/Node.h"
#include "../adaptive/SharedResources.hpp"
#include "../adaptive/tools/Helper.h"
#include "../adaptive/http/HTTPConnectionManager.h"
#include <vlc_stream.h>
#include <vlc_demux.h>
#include <vlc_meta.h>
#include <vlc_block.h>
#include "../adaptive/tools/Retrieve.hpp"
#include <algorithm>
#include <ctime>
using namespace dash;
using namespace dash::mpd;
using namespace adaptive::logic;
DASHManager::DASHManager(demux_t *demux_,
SharedResources *res,
MPD *mpd,
AbstractStreamFactory *factory,
AbstractAdaptationLogic::LogicType type) :
PlaylistManager(demux_, res, mpd, factory, type)
{
}
DASHManager::~DASHManager ()
{
}
void DASHManager::scheduleNextUpdate()
{
time_t now = time(nullptr);
vlc_tick_t minbuffer = getMinAheadTime() / 2;
if(playlist->minUpdatePeriod > minbuffer)
minbuffer = playlist->minUpdatePeriod;
if(minbuffer < 5 * CLOCK_FREQ)
minbuffer = 5 * CLOCK_FREQ;
nextPlaylistupdate = now + minbuffer / CLOCK_FREQ;
msg_Dbg(p_demux, "Updated MPD, next update in %" PRId64 "s", (vlc_tick_t) nextPlaylistupdate - now );
}
bool DASHManager::needsUpdate() const
{
if(nextPlaylistupdate && time(nullptr) < nextPlaylistupdate)
return false;
return PlaylistManager::needsUpdate();
}
bool DASHManager::updatePlaylist()
{
/* do update */
if(nextPlaylistupdate)
{
std::string url(p_demux->psz_access);
url.append("://");
url.append(p_demux->psz_location);
block_t *p_block = Retrieve::HTTP(resources, ChunkType::Playlist, url);
if(!p_block)
return false;
stream_t *mpdstream = vlc_stream_MemoryNew(p_demux, p_block->p_buffer, p_block->i_buffer, true);
if(!mpdstream)
{
block_Release(p_block);
return false;
}
xml::DOMParser parser(mpdstream);
if(!parser.parse(true))
{
vlc_stream_Delete(mpdstream);
block_Release(p_block);
return false;
}
IsoffMainParser mpdparser(parser.getRootNode(), VLC_OBJECT(p_demux),
mpdstream, Helper::getDirectoryPath(url).append("/"));
MPD *newmpd = mpdparser.parse();
if(newmpd)
{
playlist->updateWith(newmpd);
delete newmpd;
}
vlc_stream_Delete(mpdstream);
block_Release(p_block);
}
return true;
}
int DASHManager::doControl(int i_query, va_list args)
{
switch (i_query)
{
case DEMUX_GET_META:
{
MPD *mpd = dynamic_cast<MPD *>(playlist);
if(!mpd)
return VLC_EGENERIC;
if(!mpd->programInfo)
break;
vlc_meta_t *p_meta = va_arg (args, vlc_meta_t *);
vlc_meta_t *meta = vlc_meta_New();
if (meta == nullptr)
return VLC_EGENERIC;
if(!mpd->programInfo->getTitle().empty())
vlc_meta_SetTitle(meta, mpd->programInfo->getTitle().c_str());
if(!mpd->programInfo->getSource().empty())
vlc_meta_SetPublisher(meta, mpd->programInfo->getSource().c_str());
if(!mpd->programInfo->getCopyright().empty())
vlc_meta_SetCopyright(meta, mpd->programInfo->getCopyright().c_str());
if(!mpd->programInfo->getMoreInformationUrl().empty())
vlc_meta_SetURL(meta, mpd->programInfo->getMoreInformationUrl().c_str());
vlc_meta_Merge(p_meta, meta);
vlc_meta_Delete(meta);
break;
}
}
return PlaylistManager::doControl(i_query, args);
}
bool DASHManager::isDASH(xml::Node *root)
{
const std::string namespaces[] = {
"urn:mpeg:mpegB:schema:DASH:MPD:DIS2011",
"urn:mpeg:schema:dash:mpd:2011",
"urn:mpeg:DASH:schema:MPD:2011",
"urn:mpeg:mpegB:schema:DASH:MPD:DIS2011",
"urn:mpeg:schema:dash:mpd:2011",
"urn:mpeg:DASH:schema:MPD:2011",
};
if(root->getName() != "MPD")
return false;
std::string ns = root->getAttributeValue("xmlns");
for( size_t i=0; i<ARRAY_SIZE(namespaces); i++ )
{
if ( adaptive::Helper::ifind(ns, namespaces[i]) )
return true;
}
return false;
}
bool DASHManager::mimeMatched(const std::string &mime)
{
return (mime == "application/dash+xml");
}
|