[vlc-devel] [PATCH 12/14] stream_out: dlna: publicly expose protocol info function
Alaric Senat
dev.asenat at posteo.net
Fri Mar 19 11:40:07 UTC 2021
This will allow for other dlna compliant modules (for instance a server)
to use the same code as formatting the Protocol Info is a pretty common
operation.
---
modules/stream_out/dlna/dlna.cpp | 28 +++++-----------------------
modules/stream_out/dlna/dlna.hpp | 27 +++++++++++++++++++++++++++
2 files changed, 32 insertions(+), 23 deletions(-)
diff --git a/modules/stream_out/dlna/dlna.cpp b/modules/stream_out/dlna/dlna.cpp
index 7b76cbd2ac..27cafed2ba 100644
--- a/modules/stream_out/dlna/dlna.cpp
+++ b/modules/stream_out/dlna/dlna.cpp
@@ -157,29 +157,11 @@ char *getServerIPAddress() {
std::string dlna_write_protocol_info (const protocol_info_t info)
{
- std::ostringstream protocol;
- char dlna_info[448];
-
- if (info.transport == DLNA_TRANSPORT_PROTOCOL_HTTP)
- protocol << "http-get:*:";
-
- protocol << info.profile.mime;
- protocol << ":";
-
- if (info.profile.name != "*")
- protocol << "DLNA.ORG_PN=" << info.profile.name.c_str() << ";";
-
- dlna_org_flags_t flags = DLNA_ORG_FLAG_STREAMING_TRANSFER_MODE |
- DLNA_ORG_FLAG_BACKGROUND_TRANSFERT_MODE |
- DLNA_ORG_FLAG_CONNECTION_STALL |
- DLNA_ORG_FLAG_DLNA_V15;
- sprintf (dlna_info, "%s=%.2x;%s=%d;%s=%.8x%.24x",
- "DLNA.ORG_OP", DLNA_ORG_OPERATION_RANGE,
- "DLNA.ORG_CI", info.ci,
- "DLNA.ORG_FLAGS", flags, 0);
- protocol << dlna_info;
-
- return protocol.str();
+ const dlna_org_flags_t flags = DLNA_ORG_FLAG_STREAMING_TRANSFER_MODE |
+ DLNA_ORG_FLAG_BACKGROUND_TRANSFERT_MODE |
+ DLNA_ORG_FLAG_CONNECTION_STALL |
+ DLNA_ORG_FLAG_DLNA_V15;
+ return dlna_write_protocol_info(info, flags, DLNA_ORG_OPERATION_RANGE);
}
std::vector<std::string> split(const std::string &s, char delim) {
diff --git a/modules/stream_out/dlna/dlna.hpp b/modules/stream_out/dlna/dlna.hpp
index 128ee1c423..5e954f2ed7 100644
--- a/modules/stream_out/dlna/dlna.hpp
+++ b/modules/stream_out/dlna/dlna.hpp
@@ -28,6 +28,8 @@
#include "dlna_common.hpp"
#include "profile_names.hpp"
+#include <sstream>
+
struct protocol_info_t {
protocol_info_t() = default;
protocol_info_t(const protocol_info_t&) = default;
@@ -47,6 +49,31 @@ struct protocol_info_t {
dlna_profile_t profile;
};
+static inline std::string dlna_write_protocol_info(const protocol_info_t infos,
+ const dlna_org_flags_t flags,
+ const dlna_org_operation_t op)
+{
+ std::ostringstream protocol;
+ char dlna_info[448];
+
+ if (infos.transport == DLNA_TRANSPORT_PROTOCOL_HTTP)
+ protocol << "http-get:*:";
+
+ protocol << infos.profile.mime;
+ protocol << ":";
+
+ if (infos.profile.name != "*")
+ protocol << "DLNA.ORG_PN=" << infos.profile.name.c_str() << ";";
+
+ sprintf (dlna_info, "%s=%.2x;%s=%d;%s=%.8x%.24x",
+ "DLNA.ORG_OP", op,
+ "DLNA.ORG_CI", infos.ci,
+ "DLNA.ORG_FLAGS", flags, 0);
+ protocol << dlna_info;
+
+ return protocol.str();
+}
+
using ProtocolPtr = std::unique_ptr<protocol_info_t>;
static inline ProtocolPtr make_protocol(protocol_info_t a)
{
--
2.29.2
More information about the vlc-devel
mailing list