⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 epgdec.cpp

📁 drm 支程式編寫 for radio
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************\
 * British Broadcasting Corporation
 * Copyright (c) 2006
 *
 * Author(s):
 *	Julian Cable
 *
 * Description:
 *	ETSI DAB/DRM Electronic Programme Guide XML Decompressor
 *
 *
 ******************************************************************************
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later 
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
\******************************************************************************/

#include <string>
#include <map>
#include <iostream>
#include <sstream>
#include "epgdec.h"
#include "../DABMOT.h"
#include "../../util/Utilities.h"

static QDomElement element(QDomDocument& doc, const tag_length_value& tlv);

void
CEPGDecoder::decode (const vector<_BYTE>& vecData)
{
    /* clear the doc, allowing re-use */
    doc.setContent (QString (""));
    tag_length_value tlv(&vecData[0]);
    if(tlv.is_epg()) {
      doc.appendChild (element(doc, tlv));
    }
}

typedef enum { nu_attr, enum_attr, string_attr, u16_attr, u24_attr, datetime_attr,
  duration_attr, sid_attr, genre_href_attr, bitrate_attr} enum_attr_t;

typedef struct
{
    const char *name;
    const char **vals;
    enum_attr_t decode;
} dectab;

static char token_list[20][255];

static uint32_t default_content_id;

static const char *enums0[] = { (char*)2, "DAB", "DRM" };
static const char *enums1[] = { (char*)9, 0, "series",
    "show",
    "programConcept",
    "magazine",
    "programCompilation",
    "otherCollection",
    "otherChoice",
    "topic"
};
static const char *enums2[] = { (char*)3, "URL", "DAB", "DRM" };
static const char *enums3[] = { (char*)4, "identical", "more", "less", "similar" };
static const char *enums4[] = { (char*)2, "primary", "alternative" };
static const char *enums5[] = { (char*)7, "audio", "DLS",
    "MOTSlideshow", "MOTBWS", "TPEG", "DGPS", "proprietary"
};
static const char *enums6[] = { (char*)2, "primary", "secondary" };
static const char *enums7[] = { (char*)2, "none", "unspecified" };
static const char *enums8[] = { (char*)2, "on-air", "off-air" };
static const char *enums9[] = { (char*)2, "no", "yes" };
static const char *enums10[] =
    { (char*)4, 0, "logo_unrestricted", "logo_mono_square",
    "logo_colour_square", "logo_mono_rectangle"
};

static const char *enums11[] = { (char*)3, "main", "secondary", "other" };

static const char *classificationScheme[] = { 
    0,
    "IntentionCS",
    "FormatCS",
    "ContentCS",
    "IntendedAudienceCS",
    "OriginationCS",
    "ContentalertCS",
    "MediaTypeCS",
    "AtmosphereCS",
    0, 0, 0, 0, 0, 0, 0
};
  

static dectab attribute_tags_epg[] = {
    {"system", enums0, enum_attr},
    {"id", 0, string_attr}
};

static dectab attribute_tags_sch[] = {
    {"version", 0, u16_attr},
    {"creationTime", 0, datetime_attr},
    {"originator", 0, string_attr}
};

static dectab attribute_tags_si[] = {
    {"version", 0, u16_attr},
    {"creationTime", 0, datetime_attr},
    {"originator", 0, string_attr},
    {"serviceProvider", 0, string_attr},
    {"system", enums0, enum_attr}
};

static dectab attribute_tags2[] = {
    {"shortId", 0, u24_attr},
    {"version", 0, u16_attr},
    {"type", enums1, enum_attr},
    {"numOfItems", 0, u16_attr},
};
static dectab attribute_tags_scope[] = {
    {"startTime", 0, datetime_attr},
    {"stopTime", 0, datetime_attr}
};
static dectab attribute_tags4[] = {
    {"protocol", enums2, enum_attr},
    {"type", enums3, enum_attr},
    {"url", 0, string_attr},
};
static dectab attribute_tags5[] = {
    {"id", 0, string_attr},
    {"version", 0, u16_attr}
};
static dectab attribute_tags6[] = {
    {"type", enums4, enum_attr},
    {"kHz", 0, u24_attr}
};
static dectab attribute_tags7[] = {
    {"version", 0, u16_attr},
    {"format", enums5, enum_attr},
    {"Not used", 0, nu_attr},
    {"bitrate", 0, bitrate_attr}
};
static dectab attribute_tags8[] = {
    {"id", 0, string_attr},
    {"type", enums6, enum_attr}
};
static dectab attribute_tags_name[] = {
    {"xml:lang", 0, string_attr}
};
static dectab attribute_tags10[] = {
    {"mimeValue", 0, string_attr},
    {"xml:lang", 0, string_attr},
    {"url", 0, string_attr},
    {"type", enums10, enum_attr},
    {"width", 0, u16_attr},
    {"height", 0, u16_attr}
};
static dectab attribute_tags11[] = {
    {"time", 0, datetime_attr},
    {"duration", 0, duration_attr},
    {"actualTime", 0, datetime_attr},
    {"actualDuration", 0, duration_attr}
};
static dectab attribute_tags12[] = {
    {"id", 0, sid_attr},
    {"trigger", 0, u16_attr}
};
static dectab attribute_tags13[] = {
    {"id", 0, string_attr},
    {"shortId", 0, u24_attr},
    {"index", 0, u16_attr}
};
static dectab attribute_tags14[] = {
    {"url", 0, string_attr},
    {"mimeValue", 0, string_attr},
    {"xml:lang", 0, string_attr},
    {"description", 0, string_attr},
    {"expiryTime", 0, datetime_attr}
};
static dectab attribute_tags15[] = {
    {"id", 0, string_attr},
    {"shortId", 0, u24_attr},
    {"version", 0, u16_attr},
    {"recommendation", enums9, enum_attr},
    {"broadcast", enums8, enum_attr},
    {"Not used", 0, nu_attr},
    {"xml:lang", 0, string_attr},
    {"bitrate", 0, string_attr}
};
static dectab attribute_tags_genre[] = {
    {"href", 0, genre_href_attr},
    {"type", enums11, enum_attr}
};

static dectab attribute_tags18[] = {
    {"type", enums7, enum_attr}
};

struct eltab_t {
  char * element_name;
  dectab* tags;
  size_t size;      
};

const static eltab_t element_tables[] = {
    { "", 0, 0 },
    { "", 0, 0 },
    { "epg", attribute_tags_epg, sizeof (attribute_tags_epg) / sizeof (dectab) },
    { "serviceInformation", attribute_tags_si, sizeof (attribute_tags_si) / sizeof (dectab) },
    { 0, 0 },
    { 0, 0 },
    { 0, 0 },
    { 0, 0 },
    { 0, 0 },
    { 0, 0 },
    { 0, 0 },
    { 0, 0 },
    { 0, 0 },
    { 0, 0 },
    { 0, 0 },
    { 0, 0 },
    { "shortName", attribute_tags_name, sizeof (attribute_tags_name) / sizeof (dectab) },
    { "mediumName", attribute_tags_name, sizeof (attribute_tags_name) / sizeof (dectab) },
    { "longName", attribute_tags_name, sizeof (attribute_tags_name) / sizeof (dectab) },
    { "mediaDescription", 0, 0 },
    { "genre", attribute_tags_genre, sizeof (attribute_tags_genre) / sizeof (dectab) },
    { "CA", attribute_tags18, sizeof (attribute_tags18) / sizeof (dectab) },
    { "keywords", attribute_tags_name, sizeof (attribute_tags_name) / sizeof (dectab) },
    { "memberOf", attribute_tags13, sizeof (attribute_tags13) / sizeof (dectab) },
    { "link", attribute_tags14, sizeof (attribute_tags14) / sizeof (dectab) },
    { "location", 0, 0 },
    { "shortDescription", attribute_tags_name, sizeof (attribute_tags_name) / sizeof (dectab) },
    { "longDescription", attribute_tags_name, sizeof (attribute_tags_name) / sizeof (dectab) },
    { "programme", attribute_tags15, sizeof (attribute_tags15) / sizeof (dectab) },
    { "", 0, 0 },
    { "", 0, 0 },
    { "", 0, 0 },
    { "programmeGroups", attribute_tags_sch, sizeof (attribute_tags_sch) / sizeof (dectab) },
    { "schedule", attribute_tags_sch, sizeof (attribute_tags_sch) / sizeof (dectab) },
    { "alternateSource", attribute_tags4, sizeof (attribute_tags4) / sizeof (dectab) },
    { "programmeGroup", attribute_tags2, sizeof (attribute_tags2) / sizeof (dectab) },
    { "scope", attribute_tags_scope, sizeof (attribute_tags_scope) / sizeof (dectab) },
    { "serviceScope", attribute_tags12, sizeof (attribute_tags12) / sizeof (dectab) },
    { "ensemble", attribute_tags6, sizeof (attribute_tags6) / sizeof (dectab) },
    { "frequency", attribute_tags7, sizeof (attribute_tags7) / sizeof (dectab) },
    { "service", attribute_tags8, sizeof (attribute_tags8) / sizeof (dectab) },
    { "serviceID", attribute_tags6, sizeof (attribute_tags6) / sizeof (dectab) },
    { "epgLanguage", attribute_tags_name, sizeof (attribute_tags_name) / sizeof (dectab) },
    { "multimedia", attribute_tags10, sizeof (attribute_tags10) / sizeof (dectab) },
    { "time", attribute_tags11, sizeof (attribute_tags11) / sizeof (dectab) },
    { "bearer", attribute_tags12, sizeof (attribute_tags12) / sizeof (dectab) },
    { "programmeEvent", attribute_tags15, sizeof (attribute_tags15) / sizeof (dectab) },
    { "relativeTime", attribute_tags11, sizeof (attribute_tags11) / sizeof (dectab) },
    { "simulcast", attribute_tags_epg, sizeof (attribute_tags_epg) / sizeof (dectab) }
};




string decode_string (const _BYTE * p, size_t len);
const string element_name (_BYTE tag);
static void attribute(map<string,string>& out, _BYTE element_tag, tag_length_value& tlv);
static void string_token_table(const tag_length_value& tlv);

uint16_t
get_uint16 (const _BYTE* p)
{
    uint16_t h = p[0], l = p[1];
    return ((h << 8) | l);
}

uint32_t
get_uint24 (const _BYTE* p)
{
    uint32_t h = p[0], m = p[1], l = p[2];
    return ((((h << 8) | m) << 8) | l);
}

tag_length_value::tag_length_value(const _BYTE* q)
{
  _BYTE* p=const_cast<_BYTE*>(q);
  tag = *p++;
  length = *p++;
  if (length == 0xFE) {
     length = get_uint16(p);
     p+=2;
  }
  else if (length == 0xFF) {
     length = get_uint24(p);
     p+=3;
  }
  value = p;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -