MythTV  master
splicedescriptors.cpp
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
21 #ifndef SPLICE_DESCRIPTOR_H
22 #define SPLICE_DESCRIPTOR_H
23 
24 #include "splicedescriptors.h"
25 #include "mythmiscutil.h" // for xml_indent
26 
28  const unsigned char *data, uint len)
29 {
31  uint off = 0;
32  while (off < len)
33  {
34  tmp.push_back(data+off);
35  SpliceDescriptor desc(data+off, len-off);
36  if (!desc.IsValid())
37  {
38  tmp.pop_back();
39  break;
40  }
41  off += desc.size();
42  }
43  return tmp;
44 }
45 
47  const unsigned char *data, uint len, int excluded_descid)
48 {
50  uint off = 0;
51  while (off < len)
52  {
53  if ((data+off)[0] != excluded_descid)
54  tmp.push_back(data+off);
55  SpliceDescriptor desc(data+off, len-off);
56  if (!desc.IsValid())
57  {
58  if ((data+off)[0] != excluded_descid)
59  tmp.pop_back();
60  break;
61  }
62  off += desc.size();
63  }
64  return tmp;
65 }
66 
68  const unsigned char *data, uint len, int excluded_descid)
69 {
71  uint off = 0;
72  while (off < len)
73  {
74  if ((data+off)[0] == excluded_descid)
75  tmp.push_back(data+off);
76  SpliceDescriptor desc(data+off, len-off);
77  if (!desc.IsValid())
78  {
79  if ((data+off)[0] == excluded_descid)
80  tmp.pop_back();
81  break;
82  }
83  off += desc.size();
84  }
85  return tmp;
86 }
87 
88 const unsigned char *SpliceDescriptor::Find(
89  const desc_list_t &parsed, uint desc_tag)
90 {
91  for (const auto *item : parsed)
92  {
93  if (item[0] == desc_tag)
94  return item;
95  }
96  return nullptr;
97 }
98 
100 {
102  for (const auto *item : parsed)
103  {
104  if (item[0] == desc_tag)
105  tmp.push_back(item);
106  }
107  return tmp;
108 }
109 
111 {
112  switch (DescriptorTag())
113  {
115  return QString("Avail");
117  return QString("DTMF");
119  return QString("Segmentation");
120  default:
121  return QString("Unknown(%1)").arg(DescriptorTag());
122  }
123 }
124 
125 QString SpliceDescriptor::toString(void) const
126 {
127  QString str;
128 
129  if (!IsValid())
130  return "Invalid Splice Descriptor";
132  {
133  auto desc = AvailDescriptor(m_data);
134  if (desc.IsValid())
135  str = desc.toString();
136  }
138  {
139  auto desc = DTMFDescriptor(m_data);
140  if (desc.IsValid())
141  str = desc.toString();
142  }
144  {
145  auto desc = SegmentationDescriptor(m_data);
146  if (desc.IsValid())
147  str = desc.toString();
148  }
149  else
150  {
151  str.append(QString("%1 Splice Descriptor (0x%2)")
153  .arg(int(DescriptorTag()), 0, 16));
154  str.append(QString(" length(%1)").arg(int(DescriptorLength())));
155  for (uint i=0; i<DescriptorLength(); i++)
156  str.append(QString(" 0x%1").arg(int(m_data[i+2]), 0, 16));
157  }
158 
159  return str.isEmpty() ? "Invalid Splice Descriptor" : str;
160 }
161 
165 {
166  QString indent_0 = xml_indent(level);
167  QString indent_1 = xml_indent(level+1);
168  QString str;
169 
170  str += indent_0 + "<DESCRIPTOR namespace=\"splice\">\n";
171  str += indent_1 + QString("<TAG>0x%1</TAG>\n")
172  .arg(DescriptorTag(),2,16,QChar('0'));
173  str += indent_1 + QString("<DESCRIPTION>%1</DESCRIPTION>\n")
174  .arg(DescriptorTagString(),0,16);
175 
176  str += indent_1 + "<DATA>";
177  for (uint i = 0; i < DescriptorLength(); i++)
178  str += QString("0x%1 ").arg(m_data[i+2],2,16,QChar('0'));
179  str = str.trimmed();
180  str += "</DATA>\n";
181 
182  str += indent_1 + "<DECODED>" + toString() + "</DECODED>";
183 
184  str += indent_0 + "</DESCRIPTOR>";
185 
186  return str;
187 }
188 
189 bool DTMFDescriptor::IsParsible(const unsigned char *data, uint safe_bytes)
190 {
191  if (safe_bytes < 8)
192  return false;
193  if (data[0] != SpliceDescriptorID::dtmf)
194  return false;
195  uint len = data[1];
196  if (len + 2 > safe_bytes)
197  return false;
198  if (data[2] != 'C' || data[3] != 'U' ||
199  data[4] != 'E' || data[5] != 'I')
200  return false;
201  return len == (6 + uint(data[7]>>5));
202 }
203 
205 {
206  _ptrs[0] = m_data + (IsProgramSegmentation() ? 12 : 13 + ComponentCount() * 6);
207  _ptrs[1] = _ptrs[0] + (HasSegmentationDuration() ? 5 : 0);
208  _ptrs[2] = _ptrs[1] + 2 + SegmentationUPIDLength();
209  return true;
210 }
211 
213 {
214  // TODO
215  return QString("Segmentation: id(%1)").arg(SegmentationEventIdString());
216 }
217 
218 #endif // SPLICE_DESCRIPTOR_H
SpliceDescriptor::toString
virtual QString toString(void) const
Definition: splicedescriptors.cpp:125
SpliceDescriptor::IsValid
bool IsValid(void) const
Definition: splicedescriptors.h:61
SegmentationDescriptor::_ptrs
unsigned const char * _ptrs[3]
Definition: splicedescriptors.h:283
SpliceDescriptor::toStringXML
virtual QString toStringXML(uint indent_level) const
Returns XML representation of string the TS Reader XML format.
Definition: splicedescriptors.cpp:164
SpliceDescriptor::ParseAndExclude
static desc_list_t ParseAndExclude(const unsigned char *data, uint len, int excluded_descid)
Definition: splicedescriptors.cpp:46
SegmentationDescriptor::Parse
bool Parse(void) override
Definition: splicedescriptors.cpp:204
arg
arg(title).arg(filename).arg(doDelete))
desc_list_t
vector< const unsigned char * > desc_list_t
Definition: mpegdescriptors.h:18
SegmentationDescriptor::IsProgramSegmentation
bool IsProgramSegmentation(void) const
Definition: splicedescriptors.h:187
SpliceDescriptor::FindAll
static desc_list_t FindAll(const desc_list_t &parsed, uint desc_tag)
Definition: splicedescriptors.cpp:99
tmp
static guint32 * tmp
Definition: goom_core.cpp:30
SpliceDescriptorID::segmentation
@ segmentation
Definition: splicedescriptors.h:38
SpliceDescriptor
Definition: splicedescriptors.h:42
splicedescriptors.h
AvailDescriptor
Definition: splicedescriptors.h:99
SpliceDescriptorID::avail
@ avail
Definition: splicedescriptors.h:36
SegmentationDescriptor::SegmentationUPIDLength
uint SegmentationUPIDLength(void) const
Definition: splicedescriptors.h:235
SegmentationDescriptor::toString
QString toString(void) const override
Definition: splicedescriptors.cpp:212
SpliceDescriptor::DescriptorTag
uint DescriptorTag(void) const
Definition: splicedescriptors.h:66
SegmentationDescriptor::SegmentationEventIdString
QString SegmentationEventIdString(void) const
Definition: splicedescriptors.h:177
SegmentationDescriptor::ComponentCount
uint ComponentCount(void) const
Definition: splicedescriptors.h:193
SegmentationDescriptor
Definition: splicedescriptors.h:157
uint
unsigned int uint
Definition: compat.h:140
SpliceDescriptor::DescriptorLength
uint DescriptorLength(void) const
Definition: splicedescriptors.h:69
SpliceDescriptor::ParseOnlyInclude
static desc_list_t ParseOnlyInclude(const unsigned char *data, uint len, int excluded_descid)
Definition: splicedescriptors.cpp:67
SpliceDescriptor::m_data
const unsigned char * m_data
Definition: splicedescriptors.h:96
mythmiscutil.h
xml_indent
QString xml_indent(uint level)
Definition: mythmiscutil.cpp:1006
SpliceDescriptor::DescriptorTagString
QString DescriptorTagString(void) const
Definition: splicedescriptors.cpp:110
DTMFDescriptor::IsParsible
static bool IsParsible(const unsigned char *data, uint safe_bytes)
Definition: splicedescriptors.cpp:189
SpliceDescriptor::Find
static const unsigned char * Find(const desc_list_t &parsed, uint desc_tag)
Definition: splicedescriptors.cpp:88
SpliceDescriptor::size
uint size(void) const
Definition: splicedescriptors.h:62
SpliceDescriptor::Parse
virtual bool Parse(void)
Definition: splicedescriptors.h:94
SegmentationDescriptor::HasSegmentationDuration
bool HasSegmentationDuration(void) const
Definition: splicedescriptors.h:189
DTMFDescriptor
Definition: splicedescriptors.h:125
SpliceDescriptorID::dtmf
@ dtmf
Definition: splicedescriptors.h:37