OSDN Git Service

TS分離用テストコードの削除など
[tsparser/tsparser.git] / src / epg.h
1 #pragma once
2
3 #include <inttypes.h>
4 #include <string>
5 #include <vector>
6 #include <map>
7 #include <set>
8 #include "TS/ts_packet.h"
9 #include "TS/psi.h"
10 #include "ARIB/si.h"
11
12 using namespace TS;
13 using namespace TS::PSI;
14 using namespace TS::PSI::ARIB;
15 using namespace TS::Description::ARIB;
16
17 class EPG
18 {
19 private:
20         struct CONTENT {
21                 const char *jpn;
22                 const char *eng;
23         };
24
25         struct SERVICE {
26                 uint16_t                                transport_stream_id;
27                 uint16_t                                original_network_id;
28                 uint16_t                                service_id;
29
30                 struct Less : public std::binary_function< SERVICE, SERVICE, bool> {
31                         bool operator()( const SERVICE &a, const SERVICE &b) const {
32                                 if( a.original_network_id < b.original_network_id) {
33                                         return true;
34                                 }
35                                 else if( a.transport_stream_id < a.transport_stream_id) {
36                                         return true;
37                                 }
38                                 else if( a.service_id < b.service_id) {
39                                         return true;
40                                 }
41                                 else {
42                                         return false;
43                                 }
44                         }
45                 };
46         };
47
48         struct EXTEND {
49                 struct ITEM {
50                         std::string                             description;
51                         std::string                             item;
52                         
53                         void clear() {
54                                 description.clear();
55                                 item.clear();
56                         }
57                 };
58
59                 typedef std::list< ITEM>        ITEMS;
60
61                 ITEMS                                           items;
62                 std::string                                     text;
63                 
64                 void clear() {
65                         items.clear();
66                         text.clear();
67                 }
68         };
69
70         struct EVENT {
71                 typedef std::vector< uint8_t>   CATEGORYS;
72
73                 uint16_t                                event_id;
74                 time_t                                  start_time;
75                 time_t                                  end_time;
76                 std::string                             title;
77                 std::string                             desc;
78                 CATEGORYS                               categorys;
79
80                 uint8_t                                 table_id;
81
82                 bool                                    extend_flag;
83                 EXTEND                                  extend;
84
85                 EVENT() {
86                         extend_flag = false;
87                 }
88 #if 0
89                 struct Less : public std::binary_function< EVENT, EVENT, bool> {
90                         bool operator()( const EVENT &a, const EVENT &b) const {
91                                 return (a.start_time < b.start_time);
92                         }
93                 };
94 #endif
95         };
96
97         typedef std::map< uint8_t , EIT*>                       EITS;
98
99         typedef std::map< SERVICE, std::string, SERVICE::Less>  SERVICES;
100 //      typedef std::set< EVENT, EVENT::Less>                                   EVENTS;
101         typedef std::map< uint16_t, EVENT>                                              EVENTS;
102         typedef std::map< SERVICE, EVENTS, SERVICE::Less>               EPG_DATA;
103
104         static const int32_t            EIT_PID_NUM     = 3;
105         static const uint16_t           SDT_PID         = 0x0011;
106         static const uint16_t           EIT_PID[ EIT_PID_NUM];
107         static const int32_t            CONTENT_NUM = 16;
108                 
109         static const CONTENT            contents[ CONTENT_NUM];
110
111         AribDescriptorParser            descriptor_parser;
112         SDT                                                     *sdt;
113         EITS                                            eits;
114
115         SERVICES                                        services;
116 //      EVENTS                                          events;
117         EPG_DATA                                        epg_data;
118
119         const   std::string                     channel;
120
121 public:
122         EPG( std::string ch);
123         ~EPG();
124
125         bool    append( TSPacket *ts);
126         bool    write( const char *xml_file);
127
128 private:
129         bool    appendSDT( TSPacket *ts);
130         bool    appendEIT( TSPacket *ts);
131
132         void    appendEvnet( EIT *p);
133
134         const std::string       createChannelID( const SERVICE *s);
135
136         void    convertCharactor( std::string *str);
137
138         bool    writeHeader( int fd);
139         bool    writeChannel( int fd);
140         bool    writeFooter( int fd);
141 };
142