00001
00021 #ifndef _SPLICE_DESCRIPTOR_H_
00022 #define _SPLICE_DESCRIPTOR_H_
00023
00024 #include "splicedescriptors.h"
00025 #include "mythmiscutil.h"
00026
00027 desc_list_t SpliceDescriptor::Parse(
00028 const unsigned char *data, uint len)
00029 {
00030 desc_list_t tmp;
00031 uint off = 0;
00032 while (off < len)
00033 {
00034 tmp.push_back(data+off);
00035 SpliceDescriptor desc(data+off, len-off);
00036 if (!desc.IsValid())
00037 {
00038 tmp.pop_back();
00039 break;
00040 }
00041 off += desc.size();
00042 }
00043 return tmp;
00044 }
00045
00046 desc_list_t SpliceDescriptor::ParseAndExclude(
00047 const unsigned char *data, uint len, int excluded_descid)
00048 {
00049 desc_list_t tmp;
00050 uint off = 0;
00051 while (off < len)
00052 {
00053 if ((data+off)[0] != excluded_descid)
00054 tmp.push_back(data+off);
00055 SpliceDescriptor desc(data+off, len-off);
00056 if (!desc.IsValid())
00057 {
00058 if ((data+off)[0] != excluded_descid)
00059 tmp.pop_back();
00060 break;
00061 }
00062 off += desc.size();
00063 }
00064 return tmp;
00065 }
00066
00067 desc_list_t SpliceDescriptor::ParseOnlyInclude(
00068 const unsigned char *data, uint len, int excluded_descid)
00069 {
00070 desc_list_t tmp;
00071 uint off = 0;
00072 while (off < len)
00073 {
00074 if ((data+off)[0] == excluded_descid)
00075 tmp.push_back(data+off);
00076 SpliceDescriptor desc(data+off, len-off);
00077 if (!desc.IsValid())
00078 {
00079 if ((data+off)[0] == excluded_descid)
00080 tmp.pop_back();
00081 break;
00082 }
00083 off += desc.size();
00084 }
00085 return tmp;
00086 }
00087
00088 const unsigned char *SpliceDescriptor::Find(
00089 const desc_list_t &parsed, uint desc_tag)
00090 {
00091 desc_list_t::const_iterator it = parsed.begin();
00092 for (; it != parsed.end(); ++it)
00093 {
00094 if ((*it)[0] == desc_tag)
00095 return *it;
00096 }
00097 return NULL;
00098 }
00099
00100 desc_list_t SpliceDescriptor::FindAll(const desc_list_t &parsed, uint desc_tag)
00101 {
00102 desc_list_t tmp;
00103 desc_list_t::const_iterator it = parsed.begin();
00104 for (; it != parsed.end(); ++it)
00105 {
00106 if ((*it)[0] == desc_tag)
00107 tmp.push_back(*it);
00108 }
00109 return tmp;
00110 }
00111
00112 QString SpliceDescriptor::DescriptorTagString(void) const
00113 {
00114 switch (DescriptorTag())
00115 {
00116 case SpliceDescriptorID::avail:
00117 return QString("Avail");
00118 case SpliceDescriptorID::dtmf:
00119 return QString("DTMF");
00120 case SpliceDescriptorID::segmentation:
00121 return QString("Segmentation");
00122 default:
00123 return QString("Unknown(%1)").arg(DescriptorTag());
00124 }
00125 }
00126
00127 QString SpliceDescriptor::toString(void) const
00128 {
00129 QString str;
00130
00131 if (SpliceDescriptorID::avail == DescriptorTag())
00132 str = AvailDescriptor(_data).toString();
00133 else if (SpliceDescriptorID::dtmf == DescriptorTag())
00134 str = DTMFDescriptor(_data).toString();
00135 else if (SpliceDescriptorID::segmentation == DescriptorTag())
00136 str = SegmentationDescriptor(_data).toString();
00137 else
00138 {
00139 str.append(QString("%1 Splice Descriptor (0x%2)")
00140 .arg(DescriptorTagString())
00141 .arg(int(DescriptorTag()), 0, 16));
00142 str.append(QString(" length(%1)").arg(int(DescriptorLength())));
00143 for (uint i=0; i<DescriptorLength(); i++)
00144 str.append(QString(" 0x%1").arg(int(_data[i+2]), 0, 16));
00145 }
00146
00147 return str;
00148 }
00149
00152 QString SpliceDescriptor::toStringXML(uint level) const
00153 {
00154 QString indent_0 = xml_indent(level);
00155 QString indent_1 = xml_indent(level+1);
00156 QString str;
00157
00158 str += indent_0 + "<DESCRIPTOR namespace=\"splice\">\n";
00159 str += indent_1 + QString("<TAG>0x%1</TAG>\n")
00160 .arg(DescriptorTag(),2,16,QChar('0'));
00161 str += indent_1 + QString("<DESCRIPTION>%1</DESCRIPTION>\n")
00162 .arg(DescriptorTagString(),0,16);
00163
00164 str += indent_1 + "<DATA>";
00165 for (uint i = 0; i < DescriptorLength(); i++)
00166 str += QString("0x%1 ").arg(_data[i+2],2,16,QChar('0'));
00167 str = str.trimmed();
00168 str += "</DATA>\n";
00169
00170 str += indent_1 + "<DECODED>" + toString() + "</DECODED>";
00171
00172 str += indent_0 + "</DESCRIPTOR>";
00173
00174 return str;
00175 }
00176
00177 bool DTMFDescriptor::IsParsible(const unsigned char *data, uint safe_bytes)
00178 {
00179 if (safe_bytes < 8)
00180 return false;
00181 if (data[0] != SpliceDescriptorID::dtmf)
00182 return false;
00183 uint len = data[1];
00184 if (len + 2 > safe_bytes)
00185 return false;
00186 if (data[2] != 'C' || data[3] != 'U' ||
00187 data[4] != 'E' || data[5] != 'I')
00188 return false;
00189 return len == (6 + uint(data[7]>>5));
00190 }
00191
00192 bool SegmentationDescriptor::Parse(void)
00193 {
00194 _ptrs[0] = _data + (IsProgramSegmentation() ? 12 : 13 + ComponentCount() * 6);
00195 _ptrs[1] = _ptrs[0] + (HasSegmentationDuration() ? 5 : 0);
00196 _ptrs[2] = _ptrs[1] + 2 + SegmentationUPIDLength();
00197 return true;
00198 }
00199
00200 QString SegmentationDescriptor::toString() const
00201 {
00202
00203 return QString("Segmentation: id(%1)").arg(SegmentationEventIdString());
00204 }
00205
00206 #endif // _SPLICE_DESCRIPTOR_H_