[vlc-commits] demux: hls: add keystore (fix #18259)
Francois Cartegnie
git at videolan.org
Wed Apr 26 18:39:40 CEST 2017
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Apr 26 18:38:24 2017 +0200| [2de6e358177a1b805090283ab1ed21d3ae686829] | committer: Francois Cartegnie
demux: hls: add keystore (fix #18259)
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2de6e358177a1b805090283ab1ed21d3ae686829
---
modules/demux/hls/playlist/M3U8.cpp | 33 +++++++++++++++++++++++++++++++++
modules/demux/hls/playlist/M3U8.hpp | 5 +++++
modules/demux/hls/playlist/Parser.cpp | 15 +++------------
3 files changed, 41 insertions(+), 12 deletions(-)
diff --git a/modules/demux/hls/playlist/M3U8.cpp b/modules/demux/hls/playlist/M3U8.cpp
index 648414122e..1d2ec2b5ac 100644
--- a/modules/demux/hls/playlist/M3U8.cpp
+++ b/modules/demux/hls/playlist/M3U8.cpp
@@ -25,9 +25,11 @@
#include "Representation.hpp"
#include "../adaptive/playlist/BasePeriod.h"
#include "../adaptive/playlist/BaseAdaptationSet.h"
+#include "../adaptive/tools/Retrieve.hpp"
#include <vlc_common.h>
#include <vlc_stream.h>
+#include <vlc_block.h>
using namespace hls::playlist;
@@ -35,11 +37,42 @@ M3U8::M3U8 (vlc_object_t *p_object) :
AbstractPlaylist(p_object)
{
minUpdatePeriod.Set( 5 * CLOCK_FREQ );
+ vlc_mutex_init(&keystore_lock);
}
M3U8::~M3U8()
{
+ vlc_mutex_destroy(&keystore_lock);
+}
+
+std::vector<std::uint8_t> M3U8::getEncryptionKey(const std::string &uri)
+{
+ std::vector<std::uint8_t> key;
+
+ vlc_mutex_lock( &keystore_lock );
+ std::map<std::string, std::vector<std::uint8_t>>::iterator it = keystore.find(uri);
+ if(it == keystore.end())
+ {
+ /* Pretty bad inside the lock */
+ block_t *p_block = Retrieve::HTTP(p_object, uri);
+ if(p_block)
+ {
+ if(p_block->i_buffer == 16)
+ {
+ key.resize(16);
+ memcpy(&key[0], p_block->p_buffer, 16);
+ keystore.insert(std::pair<std::string, std::vector<std::uint8_t>>(uri, key));
+ }
+ block_Release(p_block);
+ }
+ }
+ else
+ {
+ key = (*it).second;
+ }
+ vlc_mutex_unlock(&keystore_lock);
+ return key;
}
bool M3U8::isLive() const
diff --git a/modules/demux/hls/playlist/M3U8.hpp b/modules/demux/hls/playlist/M3U8.hpp
index 823f2b2da1..4f656e5f17 100644
--- a/modules/demux/hls/playlist/M3U8.hpp
+++ b/modules/demux/hls/playlist/M3U8.hpp
@@ -22,6 +22,8 @@
#define M3U8_H_
#include "../adaptive/playlist/AbstractPlaylist.hpp"
+#include <vlc_threads.h>
+#include <map>
namespace hls
{
@@ -35,11 +37,14 @@ namespace hls
M3U8(vlc_object_t *);
virtual ~M3U8();
+ std::vector<std::uint8_t> getEncryptionKey(const std::string &);
virtual bool isLive() const;
virtual void debug();
private:
std::string data;
+ vlc_mutex_t keystore_lock;
+ std::map<std::string, std::vector<std::uint8_t>> keystore;
};
}
}
diff --git a/modules/demux/hls/playlist/Parser.cpp b/modules/demux/hls/playlist/Parser.cpp
index 178d019295..9ae82072b3 100644
--- a/modules/demux/hls/playlist/Parser.cpp
+++ b/modules/demux/hls/playlist/Parser.cpp
@@ -179,7 +179,7 @@ bool M3U8Parser::appendSegmentsFromPlaylistURI(vlc_object_t *p_obj, Representati
return false;
}
-void M3U8Parser::parseSegments(vlc_object_t *p_obj, Representation *rep, const std::list<Tag *> &tagslist)
+void M3U8Parser::parseSegments(vlc_object_t *, Representation *rep, const std::list<Tag *> &tagslist)
{
SegmentList *segmentList = new (std::nothrow) SegmentList(rep);
@@ -309,17 +309,8 @@ void M3U8Parser::parseSegments(vlc_object_t *p_obj, Representation *rep, const s
keyurl.prepend(Helper::getDirectoryPath(rep->getPlaylistUrl().toString()).append("/"));
}
- block_t *p_block = Retrieve::HTTP(p_obj, keyurl.toString());
- if(p_block)
- {
- if(p_block->i_buffer == 16)
- {
- encryption.key.resize(16);
- memcpy(&encryption.key[0], p_block->p_buffer, 16);
- }
- block_Release(p_block);
- }
-
+ M3U8 *m3u8 = dynamic_cast<M3U8 *>(rep->getPlaylist());
+ encryption.key = m3u8->getEncryptionKey(keyurl.toString());
if(keytag->getAttributeByName("IV"))
{
encryption.iv.clear();
More information about the vlc-commits
mailing list