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