From a61b8de6916a82f4597c87411cda86bf1530ed78 Mon Sep 17 00:00:00 2001 From: Jacek Jendrzej Date: Fri, 25 Mar 2016 17:16:54 +0100 Subject: [PATCH] add headers ffmpeg option for luascript bg play; use in script 'entry['header'] = 'Cookie: var=name'; --- src/driver/record.cpp | 6 ++++-- src/driver/streamts.cpp | 6 ++++-- src/gui/movieplayer.cpp | 31 +++++++++++++++++++++++++------ src/gui/movieplayer.h | 4 +++- 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/driver/record.cpp b/src/driver/record.cpp index a9be1ea70..04e3871b2 100644 --- a/src/driver/record.cpp +++ b/src/driver/record.cpp @@ -2065,8 +2065,8 @@ bool CStreamRec::Open(CZapitChannel * channel) if (url.empty()) return false; - std::string pretty_name; - if (!CMoviePlayerGui::getInstance(true).getLiveUrl(channel->getChannelID(), channel->getUrl(), channel->getScriptName(), url, pretty_name, recMovieInfo->epgInfo1, recMovieInfo->epgInfo2)) { + std::string pretty_name,headers; + if (!CMoviePlayerGui::getInstance(true).getLiveUrl(channel->getChannelID(), channel->getUrl(), channel->getScriptName(), url, pretty_name, recMovieInfo->epgInfo1, recMovieInfo->epgInfo2,headers)) { printf("%s: getLiveUrl() [%s] failed!\n", __FUNCTION__, url.c_str()); return false; } @@ -2078,6 +2078,8 @@ bool CStreamRec::Open(CZapitChannel * channel) printf("%s: Open input [%s]....\n", __FUNCTION__, url.c_str()); AVDictionary *options = NULL; + if (!headers.empty())//add cookies + av_dict_set(&options, "headers", headers.c_str(), 0); if (avformat_open_input(&ifcx, url.c_str(), NULL, &options) != 0) { printf("%s: Cannot open input [%s]!\n", __FUNCTION__, url.c_str()); diff --git a/src/driver/streamts.cpp b/src/driver/streamts.cpp index f729fe580..b1740bfd1 100644 --- a/src/driver/streamts.cpp +++ b/src/driver/streamts.cpp @@ -770,8 +770,8 @@ bool CStreamStream::Open() if (url.empty()) return false; - std::string pretty_name, livestreamInfo1, livestreamInfo2; - if (!CMoviePlayerGui::getInstance(true).getLiveUrl(channel->getChannelID(), channel->getUrl(), channel->getScriptName(), url, pretty_name, livestreamInfo1, livestreamInfo2)) { + std::string pretty_name, livestreamInfo1, livestreamInfo2, headers; + if (!CMoviePlayerGui::getInstance(true).getLiveUrl(channel->getChannelID(), channel->getUrl(), channel->getScriptName(), url, pretty_name, livestreamInfo1, livestreamInfo2,headers)) { printf("%s: getLiveUrl() [%s] failed!\n", __FUNCTION__, url.c_str()); return false; } @@ -784,6 +784,8 @@ bool CStreamStream::Open() printf("%s: Open input [%s]....\n", __FUNCTION__, url.c_str()); AVDictionary *options = NULL; + if (!headers.empty()) + av_dict_set(&options, "headers", headers.c_str(), 0); if (avformat_open_input(&ifcx, url.c_str(), NULL, &options) != 0) { printf("%s: Cannot open input [%s]!\n", __FUNCTION__, channel->getUrl().c_str()); return false; diff --git a/src/gui/movieplayer.cpp b/src/gui/movieplayer.cpp index 336a4107a..b33d2de7e 100644 --- a/src/gui/movieplayer.cpp +++ b/src/gui/movieplayer.cpp @@ -532,6 +532,7 @@ bool CMoviePlayerGui::SelectFile() info_2 = ""; pretty_name.clear(); file_name.clear(); + cookie_header.clear(); //reinit Path_local for webif reloadsetup if (g_settings.network_nfs_moviedir.empty()) Path_local = "/"; @@ -735,7 +736,7 @@ bool CMoviePlayerGui::luaGetUrl(const std::string &script, const std::string &fi bool haveurl = false; if ( !root.isObject() ) { for (Json::Value::iterator it = root.begin(); it != root.end(); ++it) { - info.url=""; info.name=""; info.bandwidth = 1; info.resolution=""; info.res1 = 1; + info.url=""; info.name=""; info.header=""; info.bandwidth = 1; info.resolution=""; info.res1 = 1; tmp = "0"; Json::Value object_it = *it; for (Json::Value::iterator iti = object_it.begin(); iti != object_it.end(); iti++) { @@ -745,7 +746,11 @@ bool CMoviePlayerGui::luaGetUrl(const std::string &script, const std::string &fi haveurl = true; } else if (name=="name") { info.name = (*iti).asString(); - } else if (name=="band") { + } + else if (name=="header") { + info.header = (*iti).asString(); + } + else if (name=="band") { info.bandwidth = atoi((*iti).asString().c_str()); } else if (name=="res1") { tmp = (*iti).asString(); @@ -762,7 +767,7 @@ bool CMoviePlayerGui::luaGetUrl(const std::string &script, const std::string &fi } if (root.isObject()) { for (Json::Value::iterator it = root.begin(); it != root.end(); ++it) { - info.url=""; info.name=""; info.bandwidth = 1; info.resolution=""; info.res1 = 1; + info.url=""; info.name=""; info.header=""; info.bandwidth = 1; info.resolution=""; info.res1 = 1; tmp = "0"; std::string name = it.name(); if (name=="url") { @@ -770,6 +775,8 @@ bool CMoviePlayerGui::luaGetUrl(const std::string &script, const std::string &fi haveurl = true; } else if (name=="name") { info.name = (*it).asString(); + } else if (name=="header") { + info.header = (*it).asString(); } else if (name=="band") { info.bandwidth = atoi((*it).asString().c_str()); } else if (name=="res1") { @@ -827,6 +834,7 @@ bool CMoviePlayerGui::selectLivestream(std::vector &streamLis if (_info->res1 == _res) { info->url = _info->url; info->name = _info->name; + info->header = _info->header; info->resolution = _info->resolution; info->res1 = _info->res1; info->bandwidth = _info->bandwidth; @@ -856,7 +864,7 @@ bool CMoviePlayerGui::selectLivestream(std::vector &streamLis return false; } -bool CMoviePlayerGui::getLiveUrl(const t_channel_id chan, const std::string &url, const std::string &script, std::string &realUrl, std::string &_pretty_name, std::string &info1, std::string &info2) +bool CMoviePlayerGui::getLiveUrl(const t_channel_id chan, const std::string &url, const std::string &script, std::string &realUrl, std::string &_pretty_name, std::string &info1, std::string &info2, std::string &header) { static t_channel_id oldChan = 0; static std::vector liveStreamList; @@ -898,6 +906,10 @@ bool CMoviePlayerGui::getLiveUrl(const t_channel_id chan, const std::string &url info1 = info.name; _pretty_name = info.name; } + if (!info.header.empty()) { + header = info.header; + } + #if 0 if (!info.resolution.empty()) info2 = info.resolution; @@ -952,7 +964,7 @@ bool CMoviePlayerGui::PlayBackgroundStart(const std::string &file, const std::st std::string realUrl = file; std::string _pretty_name = name; - if (!getLiveUrl(chan, file, script, realUrl, _pretty_name, livestreamInfo1, livestreamInfo2)) { + if (!getLiveUrl(chan, file, script, realUrl, _pretty_name, livestreamInfo1, livestreamInfo2, cookie_header)) { /* FIXME: lua->runScript calling channelRezap, which makes neutrino to loop at start, let playback start -> drop messages in ShowStartHint */ //return false; @@ -969,6 +981,7 @@ bool CMoviePlayerGui::PlayBackgroundStart(const std::string &file, const std::st instance_bg->isHTTP = true; instance_bg->file_name = realUrl; instance_bg->pretty_name = _pretty_name; + instance_bg->cookie_header = cookie_header; instance_bg->movie_info.epgTitle = name; instance_bg->movie_info.epgChannel = realUrl; @@ -1070,7 +1083,13 @@ bool CMoviePlayerGui::PlayFileStart(void) showStartingHint = true; pthread_create(&thrStartHint, NULL, CMoviePlayerGui::ShowStartHint, this); } - bool res = playback->Start((char *) file_name.c_str(), vpid, vtype, currentapid, currentac3, duration); + bool res = false; + if(cookie_header.empty()){ + res = playback->Start((char *) file_name.c_str(), vpid, vtype, currentapid, currentac3, duration); + }else{ + res = playback->Start((char *) file_name.c_str(), cookie_header);//url with cookies + } + if (thrStartHint) { showStartingHint = false; pthread_join(thrStartHint, NULL); diff --git a/src/gui/movieplayer.h b/src/gui/movieplayer.h index 5219d84c2..4585aca37 100644 --- a/src/gui/movieplayer.h +++ b/src/gui/movieplayer.h @@ -90,6 +90,7 @@ class CMoviePlayerGui : public CMenuTarget std::string url; std::string name; std::string resolution; + std::string header;//cookie int res1; int bandwidth; } livestream_info_struct_t; @@ -102,6 +103,7 @@ class CMoviePlayerGui : public CMenuTarget std::string file_name; std::string pretty_name; + std::string cookie_header; std::string info_1, info_2; std::string currentaudioname; bool playing; @@ -261,7 +263,7 @@ class CMoviePlayerGui : public CMenuTarget bool getBlockedFromPlugin() { return blockedFromPlugin; }; void setLuaInfoFunc(lua_State* L, bool func) { luaState = L; haveLuaInfoFunc = func; }; void getLivestreamInfo(std::string *i1, std::string *i2) { *i1=livestreamInfo1; *i2=livestreamInfo2; }; - bool getLiveUrl(const t_channel_id chan, const std::string &url, const std::string &script, std::string &realUrl, std::string &_pretty_name, std::string &info1, std::string &info2); + bool getLiveUrl(const t_channel_id chan, const std::string &url, const std::string &script, std::string &realUrl, std::string &_pretty_name, std::string &info1, std::string &info2, std::string &header); }; #endif