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  desc_list_t::const_iterator it = parsed.begin();
92  for (; it != parsed.end(); ++it)
93  {
94  if ((*it)[0] == desc_tag)
95  return *it;
96  }
97  return nullptr;
98 }
99 
101 {
103  desc_list_t::const_iterator it = parsed.begin();
104  for (; it != parsed.end(); ++it)
105  {
106  if ((*it)[0] == desc_tag)
107  tmp.push_back(*it);
108  }
109  return tmp;
110 }
111 
113 {
114  switch (DescriptorTag())
115  {
117  return QString("Avail");
119  return QString("DTMF");
121  return QString("Segmentation");
122  default:
123  return QString("Unknown(%1)").arg(DescriptorTag());
124  }
125 }
126 
127 QString SpliceDescriptor::toString(void) const
128 {
129  QString str;
130 
132  str = AvailDescriptor(_data).toString();
134  str = DTMFDescriptor(_data).toString();
137  else
138  {
139  str.append(QString("%1 Splice Descriptor (0x%2)")
140  .arg(DescriptorTagString())
141  .arg(int(DescriptorTag()), 0, 16));
142  str.append(QString(" length(%1)").arg(int(DescriptorLength())));
143  for (uint i=0; i<DescriptorLength(); i++)
144  str.append(QString(" 0x%1").arg(int(_data[i+2]), 0, 16));
145  }
146 
147  return str;
148 }
149 
153 {
154  QString indent_0 = xml_indent(level);
155  QString indent_1 = xml_indent(level+1);
156  QString str;
157 
158  str += indent_0 + "<DESCRIPTOR namespace=\"splice\">\n";
159  str += indent_1 + QString("<TAG>0x%1</TAG>\n")
160  .arg(DescriptorTag(),2,16,QChar('0'));
161  str += indent_1 + QString("<DESCRIPTION>%1</DESCRIPTION>\n")
162  .arg(DescriptorTagString(),0,16);
163 
164  str += indent_1 + "<DATA>";
165  for (uint i = 0; i < DescriptorLength(); i++)
166  str += QString("0x%1 ").arg(_data[i+2],2,16,QChar('0'));
167  str = str.trimmed();
168  str += "</DATA>\n";
169 
170  str += indent_1 + "<DECODED>" + toString() + "</DECODED>";
171 
172  str += indent_0 + "</DESCRIPTOR>";
173 
174  return str;
175 }
176 
177 bool DTMFDescriptor::IsParsible(const unsigned char *data, uint safe_bytes)
178 {
179  if (safe_bytes < 8)
180  return false;
181  if (data[0] != SpliceDescriptorID::dtmf)
182  return false;
183  uint len = data[1];
184  if (len + 2 > safe_bytes)
185  return false;
186  if (data[2] != 'C' || data[3] != 'U' ||
187  data[4] != 'E' || data[5] != 'I')
188  return false;
189  return len == (6 + uint(data[7]>>5));
190 }
191 
193 {
194  _ptrs[0] = _data + (IsProgramSegmentation() ? 12 : 13 + ComponentCount() * 6);
195  _ptrs[1] = _ptrs[0] + (HasSegmentationDuration() ? 5 : 0);
196  _ptrs[2] = _ptrs[1] + 2 + SegmentationUPIDLength();
197  return true;
198 }
199 
201 {
202  // TODO
203  return QString("Segmentation: id(%1)").arg(SegmentationEventIdString());
204 }
205 
206 #endif // _SPLICE_DESCRIPTOR_H_
QString toString(void) const override
uint DescriptorLength(void) const
QString SegmentationEventIdString(void) const
QString toString(void) const override
unsigned int uint
Definition: compat.h:140
vector< const unsigned char * > desc_list_t
bool HasSegmentationDuration(void) const
static guint32 * tmp
Definition: goom_core.c:35
uint ComponentCount(void) const
static bool IsParsible(const unsigned char *data, uint safe_bytes)
QString DescriptorTagString(void) const
static const unsigned char * Find(const desc_list_t &parsed, uint desc_tag)
QString toString(void) const override
unsigned char const * _ptrs[3]
virtual bool Parse(void)
uint size(void) const
bool IsValid(void) const
static desc_list_t ParseOnlyInclude(const unsigned char *data, uint len, int descriptorid)
virtual QString toString(void) const
virtual QString toStringXML(uint indent_level) const
Returns XML representation of string the TS Reader XML format.
uint SegmentationUPIDLength(void) const
const unsigned char * _data
bool IsProgramSegmentation(void) const
static desc_list_t FindAll(const desc_list_t &parsed, uint desc_tag)
static desc_list_t ParseAndExclude(const unsigned char *data, uint len, int descriptorid)
bool Parse(void) override
uint DescriptorTag(void) const
QString xml_indent(uint level)