MythTV  master
dsmcc.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) David C.J. Matthews 2005, 2006
3  * Derived from libdsmcc by Richard Palmer
4  */
5 #ifndef LIBDSMCC_H
6 #define LIBDSMCC_H
7 
8 #include <list>
9 
10 #include <QStringList>
11 
12 #include "dsmccreceiver.h"
13 #include "dsmccobjcarousel.h"
14 
15 /*
16  Overview.
17  This is brief, perhaps simplistic, overview of the DSMCC object carousel.
18 
19  The purpose of the carousel is to make available to the MHEG or MHP application
20  a small, Unix-like, filing system. The notion of a carousel comes from the idea
21  that the files and directories of the filing system are constantly retransmitted
22  so that whenever a receiver tunes in it will eventually see all the components.
23 
24  The input to this code is in the form of MPEG tables which have been constructed
25  out of MPEG TS packets. There are three kinds of tables that are processed: DSI,
26  DII and DDB.
27 
28  DSI tables contain the address (IOR) of the root directory of the filing system.
29  Why this is needed and how it works is described below.
30 
31  DII tables describe "modules". A module is collection of one or more files
32  or directories. Because a module may be larger than the maximum allowed table
33  size (4k) the entries in the DII say how many blocks, contained in DDB tables,
34  are needed to make the module and also whether, when all the blocks have been
35  found, the module needs to be decompressed.
36 
37  Each DDB contains data forming part of a module as well as information saying
38  which module it belongs to and which block within the module it is. Once all
39  the blocks of a module have been found and, if necessary, the module
40  decompressed, the data is ready for the next stage.
41 
42  A module comprises one of more directory, service gateway or file objects.
43  A service gateway is exactly the same as a directory except that it is a
44  root directory. Directories and service gateways are tables with a text
45  name, whether the entry is a file or sub-directory, and the address (IOR)
46  of the file or sub-directory. File objects contain the data for the file
47  itself. Note that this arrangement allows for the directory structure to
48  be an arbitrary directed graph.
49 
50  There may be multiple service gateways in the carousel and this is the
51  reason for the DSI message. The DSI message identifies one service
52  gateway as the root to be used. Working from this it is possible to
53  construct a tree of sub-directories and files to make the filing system.
54 
55  The reason for having multiple service gateways and DSI messages rather
56  than just transmitting a single service gateway is that it allows for
57  the same carousel to be used for several services on a DVB multiplex
58  and so reduce the overall bandwidth requirements on the multiplex. For
59  example, several BBC radio programmes are transmitted on the same multiplex.
60  The PMT for each programme identifies an initial PID stream containing
61  DSMCC packets and a secondary stream. The initial stream is different
62  for each programme and sends only DSI messages. Everything else is
63  transmitted on the common stream with a service gateway and a few extra
64  files, such as the programme logo, specific to that programme, but with
65  everything else shared.
66 
67  The MHEG or MHP library makes requests for files by passing in a
68  Unix-like path name. The organisation of the carousel allows a
69  receiver to pick out the file by building the data structures needed
70  to satisfy only the request. That minimises the memory requirements
71  but provides a slow response since every file request requires the
72  application to wait until the file appears on the carousel. Instead
73  this code builds the filing system as the information appears.
74 */
75 
76 class TestMhegDsmcc;
77 class Dsmcc
78 {
79  friend TestMhegDsmcc;
80  public:
81  Dsmcc() = default;
82  ~Dsmcc() { Reset(); }
83  // Reset the object carousel and clear the caches.
84  void Reset();
85  // Process an incoming DSMCC carousel table
86  void ProcessSection(const unsigned char *data, int length,
87  int componentTag, unsigned carouselId,
88  int dataBroadcastId);
89  // Request for a carousel object.
90  int GetDSMCCObject(QStringList &objectPath, QByteArray &result);
91 
92  // Add a tap. This indicates the component tag of the stream that is to
93  // be used to receive subsequent messages for this carousel.
94  // Creates a new carousel object if there isn't one for this ID.
95  ObjCarousel *AddTap(unsigned short componentTag, unsigned carouselId);
96 
97  protected:
98  void ProcessSectionIndication(const unsigned char *data, int length,
99  unsigned short streamTag);
100  void ProcessSectionData(const unsigned char *data, int length);
101  static void ProcessSectionDesc(const unsigned char *data, int length);
102 
103  static bool ProcessSectionHeader(DsmccSectionHeader *header,
104  const unsigned char *data, int length);
105 
106  void ProcessDownloadServerInitiate(const unsigned char *data, int length);
107  void ProcessDownloadInfoIndication(const unsigned char *data,
108  unsigned short streamTag);
109 
110  // Return a carousel with the given ID.
111  ObjCarousel *GetCarouselById(unsigned int carouselId);
112 
113  // Known carousels.
114  std::list<ObjCarousel*> m_carousels;
115 
116  // Initial stream
117  unsigned short m_startTag {0};
118 };
119 
120 static constexpr uint32_t COMBINE32(const uint8_t *data, int idx)
121 {
122  return (static_cast<uint32_t>(data[idx + 0]) << 24) |
123  (static_cast<uint32_t>(data[idx + 1]) << 16) |
124  (static_cast<uint32_t>(data[idx + 2]) << 8) |
125  (static_cast<uint32_t>(data[idx + 3]));
126 };
127 
128 #endif
Dsmcc::ProcessDownloadServerInitiate
void ProcessDownloadServerInitiate(const unsigned char *data, int length)
Process a DSI message.
Definition: dsmcc.cpp:132
Dsmcc::ProcessSectionData
void ProcessSectionData(const unsigned char *data, int length)
Definition: dsmcc.cpp:381
DsmccSectionHeader
Definition: dsmccreceiver.h:28
Dsmcc::ProcessSectionIndication
void ProcessSectionIndication(const unsigned char *data, int length, unsigned short streamTag)
Definition: dsmcc.cpp:308
dsmccobjcarousel.h
Dsmcc::TestMhegDsmcc
friend TestMhegDsmcc
Definition: dsmcc.h:79
Dsmcc::GetCarouselById
ObjCarousel * GetCarouselById(unsigned int carouselId)
Returns a carousel with the given ID.
Definition: dsmcc.cpp:43
Dsmcc::Dsmcc
Dsmcc()=default
Dsmcc::m_startTag
unsigned short m_startTag
Definition: dsmcc.h:117
Dsmcc::ProcessSectionDesc
static void ProcessSectionDesc(const unsigned char *data, int length)
Definition: dsmcc.cpp:441
Dsmcc::ProcessDownloadInfoIndication
void ProcessDownloadInfoIndication(const unsigned char *data, unsigned short streamTag)
Definition: dsmcc.cpp:242
ObjCarousel
Definition: dsmccobjcarousel.h:62
dsmccreceiver.h
Dsmcc::GetDSMCCObject
int GetDSMCCObject(QStringList &objectPath, QByteArray &result)
Definition: dsmcc.cpp:549
Dsmcc::ProcessSection
void ProcessSection(const unsigned char *data, int length, int componentTag, unsigned carouselId, int dataBroadcastId)
Definition: dsmcc.cpp:450
Dsmcc::AddTap
ObjCarousel * AddTap(unsigned short componentTag, unsigned carouselId)
Add a tap.
Definition: dsmcc.cpp:61
Dsmcc::Reset
void Reset()
Definition: dsmcc.cpp:540
Dsmcc::ProcessSectionHeader
static bool ProcessSectionHeader(DsmccSectionHeader *header, const unsigned char *data, int length)
Definition: dsmcc.cpp:91
Dsmcc
Definition: dsmcc.h:77
Dsmcc::~Dsmcc
~Dsmcc()
Definition: dsmcc.h:82
COMBINE32
static constexpr uint32_t COMBINE32(const uint8_t *data, int idx)
Definition: dsmcc.h:120
Dsmcc::m_carousels
std::list< ObjCarousel * > m_carousels
Definition: dsmcc.h:114