Skip to content

Commit

Permalink
Added subtutile support for Samsung devices
Browse files Browse the repository at this point in the history
Applied patch from Marcin Jurkowski:
https://sourceforge.net/p/mediatomb/patches/21/
  • Loading branch information
Sergey 'Jin' Bostandzhyan committed Dec 24, 2013
1 parent 70df27a commit b70382e
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/cds_resource_manager.cc
Expand Up @@ -483,6 +483,14 @@ void CdsResourceManager::addResources(Ref<CdsItem> item, Ref<Element> element)
res_attrs->put(MetadataHandler::getResAttrName(R_PROTOCOLINFO),
protocolInfo);

if (config->getBoolOption(CFG_SERVER_EXTEND_PROTOCOLINFO_SM_HACK))
{
if (mimeType.startsWith(_("video")))
{
element->appendElementChild(UpnpXML_DIDLRenderCaptionInfo(url));
}
}

log_debug("extended protocolInfo: %s\n", protocolInfo.c_str());
}
#endif
Expand Down
3 changes: 3 additions & 0 deletions src/common.h
Expand Up @@ -196,6 +196,8 @@
#define XML_DC_NAMESPACE "http://purl.org/dc/elements/1.1/"
#define XML_UPNP_NAMESPACE_ATTR "xmlns:upnp"
#define XML_UPNP_NAMESPACE "urn:schemas-upnp-org:metadata-1-0/upnp/"
#define XML_SEC_NAMESPACE_ATTR "xmlns:sec"
#define XML_SEC_NAMESPACE "http://www.sec.co.kr/"

// default values
#define DEFAULT_INTERNAL_CHARSET "UTF-8"
Expand Down Expand Up @@ -243,6 +245,7 @@
#define DEFAULT_LAYOUT_TYPE "builtin"
#define DEFAULT_EXTEND_PROTOCOLINFO NO
//#define DEFAULT_EXTEND_PROTOCOLINFO_CL_HACK NO
#define DEFAULT_EXTEND_PROTOCOLINFO_SM_HACK NO
#define DEFAULT_HIDE_PC_DIRECTORY NO
#ifdef YOUTUBE
#define YOUTUBE_PAGESIZE 106496
Expand Down
8 changes: 8 additions & 0 deletions src/config_manager.cc
Expand Up @@ -1440,6 +1440,14 @@ void ConfigManager::validate(String serverhome)
NEW_BOOL_OPTION(temp == "yes" ? true : false);
SET_BOOL_OPTION(CFG_SERVER_EXTEND_PROTOCOLINFO_CL_HACK);
*/
temp = getOption(_("/server/protocolInfo/attribute::samsung-hack"),
_(DEFAULT_EXTEND_PROTOCOLINFO_SM_HACK));
if (!validateYesNo(temp))
throw _Exception(_("Error in config file: samsung-hack attribute of the "
"protocolInfo tag must be either \"yes\" or \"no\""));

NEW_BOOL_OPTION(temp == "yes" ? true : false);
SET_BOOL_OPTION(CFG_SERVER_EXTEND_PROTOCOLINFO_SM_HACK);
#endif

temp = getOption(_("/server/pc-directory/attribute::upnp-hide"),
Expand Down
1 change: 1 addition & 0 deletions src/config_manager.h
Expand Up @@ -73,6 +73,7 @@ typedef enum
CFG_SERVER_EXTEND_PROTOCOLINFO_CL_HACK,
#endif
#endif//EXTEND_PROTOCOLINFO
CFG_SERVER_EXTEND_PROTOCOLINFO_SM_HACK,
CFG_SERVER_HIDE_PC_DIRECTORY,
CFG_SERVER_BOOKMARK_FILE,
CFG_SERVER_CUSTOM_HTTP_HEADERS,
Expand Down
47 changes: 47 additions & 0 deletions src/file_request_handler.cc
Expand Up @@ -305,6 +305,53 @@ void FileRequestHandler::get_info(IN const char *filename, OUT struct File_Info
/// header, since chunked encoding may be active and we do not
/// know that here
}

#ifdef EXTEND_PROTOCOLINFO
Ref<ConfigManager> cfg = ConfigManager::getInstance();
if (cfg->getBoolOption(CFG_SERVER_EXTEND_PROTOCOLINFO_SM_HACK))
{
if (item->getMimeType().startsWith(_("video"))) {
// Look for subtitle file and returns it's URL
// in CaptionInfo.sec response header.
// To be more compliant with original Samsung
// server we should check for getCaptionInfo.sec: 1
// request header.
Ref<Array<StringBase> > subexts(new Array<StringBase>());
subexts->append(_(".srt"));
subexts->append(_(".ssa"));
subexts->append(_(".smi"));
subexts->append(_(".sub"));

String bfilepath = path.substring(0, path.rindex('.'));
String validext;
for (int i=0; i<subexts->size(); i++) {
String ext = subexts->get(i);

String fpath = bfilepath + ext;
if (access(fpath.c_str(), R_OK) == 0)
{
validext = ext;
break;
}
}


if (validext.length() > 0)
{
String burlpath = _(filename);
burlpath = burlpath.substring(0, burlpath.rindex('.'));
Ref<Server> server = Server::getInstance();
String url = _("http://")
+ server->getIP() + ":" + server->getPort()
+ burlpath + validext;

if (string_ok(header))
header = header + _("\r\n");
header = header + "CaptionInfo.sec: " + url;
}
}
#endif
}
}

if (!string_ok(mimeType))
Expand Down
8 changes: 8 additions & 0 deletions src/upnp_cds_actions.cc
Expand Up @@ -106,6 +106,14 @@ void ContentDirectoryService::upnp_action_Browse(Ref<ActionRequest> request)

Ref<ConfigManager> cfg = ConfigManager::getInstance();

#ifdef EXTEND_PROTOCOLINFO
if (cfg->getBoolOption(CFG_SERVER_EXTEND_PROTOCOLINFO_SM_HACK))
{
didl_lite->setAttribute(_(XML_SEC_NAMESPACE_ATTR),
_(XML_SEC_NAMESPACE));
}
#endif

for(int i = 0; i < arr->size(); i++)
{
Ref<CdsObject> obj = arr->get(i);
Expand Down
17 changes: 17 additions & 0 deletions src/upnp_xml.cc
Expand Up @@ -381,3 +381,20 @@ Ref<Element> UpnpXML_DIDLRenderResource(String URL, Ref<Dictionary> attributes)

return res;
}

Ref<Element> UpnpXML_DIDLRenderCaptionInfo(String URL) {
Ref<Element> cap(new Element(_("sec:CaptionInfoEx")));

// Samsung DLNA clients don't follow this URL and
// obtain subtitle location from video HTTP headers.
// We don't need to know here what the subtitle type
// is and even if there is a subtitle.
// This tag seems to be only a hint for Samsung devices,
// though it's necessary.

int endp = URL.rindex('.');
cap->setText(URL.substring(0, endp) + ".srt");
cap->setAttribute(_("sec:type"), _("srt"));

return cap;
}
4 changes: 4 additions & 0 deletions src/upnp_xml.h
Expand Up @@ -76,4 +76,8 @@ zmm::Ref<mxml::Element> UpnpXML_RenderDeviceDescription(zmm::String presentation
/// \param URL download location of the item (will be child element of the <res> tag)
/// \param attributes Dictionary containing the <res> tag attributes (like resolution, etc.)
zmm::Ref<mxml::Element> UpnpXML_DIDLRenderResource(zmm::String URL, zmm::Ref<Dictionary> attributes);

/// \brief Renders a subtitle resource tag (Samsung proprietary extension)
/// \param URL download location of the video item
zmm::Ref<mxml::Element> UpnpXML_DIDLRenderCaptionInfo(zmm::String URL);
#endif // __UPNP_XML_H__

0 comments on commit b70382e

Please sign in to comment.