MythTV master
HLSSegment.cpp
Go to the documentation of this file.
1#include "HLSSegment.h"
2
3// C/C++
4#include <utility>
5
6#include "libmythbase/mythconfig.h"
7
8#if CONFIG_LIBCRYPTO
9#include <openssl/aes.h>
10#endif // CONFIG_LIBCRYPTO
11
13
14#define LOC QString("HLSSegment[%1]: ").arg(m_inputId)
15
17 : m_inputId(inputId)
18{
19 LOG(VB_RECORD, LOG_DEBUG, LOC + "ctor");
20}
21
23{
24 operator=(rhs);
25 LOG(VB_RECORD, LOG_DEBUG, LOC + "ctor");
26}
27
28HLSRecSegment::HLSRecSegment(int inputId, int sequence,
29 std::chrono::milliseconds duration,
30 QString title, QUrl uri)
31 : m_inputId(inputId),
32 m_sequence(sequence),
33 m_duration(duration),
34 m_title(std::move(title)),
35 m_url(std::move(uri))
36{
37 LOG(VB_RECORD, LOG_DEBUG, LOC + "ctor");
38}
39
41{
42 if (&rhs != this)
43 {
44 m_inputId = rhs.m_inputId;
47 m_bitrate = rhs.m_bitrate;
48 m_title = rhs.m_title;
49 m_url = rhs.m_url;
50#if CONFIG_LIBCRYPTO
51 m_keypath = rhs.m_keypath;
52 m_ivLoaded = rhs.m_ivLoaded;
53 m_aesIV = rhs.m_aesIV;
54#endif
55 }
56 return *this;
57}
58
60{
61 LOG(VB_RECORD, LOG_DEBUG, LOC + "dtor");
62}
63
64QString HLSRecSegment::toString(void) const
65{
66 return QString("[%1] '%2' @ '%3' for %4")
67 .arg(m_sequence).arg(m_title, m_url.toString(), QString::number(m_duration.count()));
68}
69
70#if CONFIG_LIBCRYPTO
71bool HLSRecSegment::SetAESIV(QString line)
72{
73 LOG(VB_RECORD, LOG_INFO, LOC + "SetAESIV line:"+ line);
74
75 /*
76 * If the EXT-X-KEY tag has the IV attribute, implementations MUST use
77 * the attribute value as the IV when encrypting or decrypting with that
78 * key. The value MUST be interpreted as a 128-bit hexadecimal number
79 * and MUST be prefixed with 0x or 0X.
80 */
81 if (!line.startsWith(QLatin1String("0x"), Qt::CaseInsensitive))
82 {
83 LOG(VB_RECORD, LOG_ERR, LOC + "SetAESIV does not start with 0x");
84 return false;
85 }
86
87 if (line.size() % 2)
88 {
89 // not even size, pad with front 0
90 line.insert(2, QLatin1String("0"));
91 }
92#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
93 int padding = std::max(0, AES_BLOCK_SIZE - (line.size() - 2));
94#else
95 int padding = std::max(static_cast<qsizetype>(0), AES_BLOCK_SIZE - (line.size() - 2));
96#endif
97 QByteArray ba = QByteArray(padding, 0x0);
98 ba.append(QByteArray::fromHex(QByteArray(line.toLatin1().constData() + 2)));
99 m_aesIV = ba;
100 m_ivLoaded = true;
101 return true;
102}
103#endif // CONFIG_LIBCRYPTO
#define LOC
Definition: HLSSegment.cpp:14
int64_t m_sequence
Definition: HLSSegment.h:53
uint64_t m_bitrate
Definition: HLSSegment.h:55
QString toString(void) const
Definition: HLSSegment.cpp:64
QString m_title
Definition: HLSSegment.h:56
HLSRecSegment(int input)
Definition: HLSSegment.cpp:16
std::chrono::milliseconds m_duration
Definition: HLSSegment.h:54
HLSRecSegment & operator=(const HLSRecSegment &rhs)
Definition: HLSSegment.cpp:40
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39