Mercurial > pt1.oyama
comparison src/tssplitter_lite.h @ 124:9c7bc6c0327e
Add DLNA server function test. (from uShare project)
author | naoyan@johnstown.minaminoshima.org |
---|---|
date | Wed, 29 Sep 2010 23:18:55 +0900 |
parents | recpt1/tssplitter_lite.h@4009737ea899 |
children | 20442921bff5 |
comparison
equal
deleted
inserted
replaced
123:215a51fa3df3 | 124:9c7bc6c0327e |
---|---|
1 /* -*- tab-width: 4; indent-tabs-mode: t -*- */ | |
2 /* vim: set ts=4 sts=4 sw=4 noexpandtab number : */ | |
3 /* tssplitter_lite.h -- split TS stream program's header. | |
4 | |
5 Copyright 2009 querulous | |
6 Copyright 2010 Naoya OYAMA <naoya.oyama@gmail.com> | |
7 | |
8 This program is free software: you can redistribute it and/or modify | |
9 it under the terms of the GNU General Public License as published by | |
10 the Free Software Foundation, either version 3 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
20 #ifndef _TS_SPLITTER_LITE_H_ | |
21 #define _TS_SPLITTER_LITE_H_ | |
22 | |
23 #define __STDC_FORMAT_MACROS | |
24 #include <inttypes.h> | |
25 #include <unistd.h> | |
26 #include <limits.h> | |
27 | |
28 #define LENGTH_PACKET (188) | |
29 #define MAX_PID (8192) | |
30 #define MAX_SERVICES (50) | |
31 #define LENGTH_CRC_DATA (176) | |
32 #define false (0) | |
33 #define true (1) | |
34 | |
35 #define TSS_SUCCESS (0) | |
36 #define TSS_ERROR (-1) | |
37 #define TSS_NULL (-2) | |
38 #define LENGTH_PAT_HEADER (12) | |
39 #define C_CHAR_COMMA ',' | |
40 #define C_CHAR_DOT '.' | |
41 #define LENGTH_TS_HEADER (4) | |
42 #define LENGTH_PES_HEADER (9) | |
43 #define LENGTH_PTS (5) | |
44 | |
45 /* ²þÄûÈǥǥ¸¥¿¥ëÊüÁ÷¶µ²Ê½ñ(¾å) P101 ɽ1 ARIB¤Ç¤ÎPSI/SI¤Î¼ïÎà¤è¤ê»²¾È */ | |
46 #define PAT (0x0000) | |
47 //#define PMT /* PAT¤Ë¤è¤ë´ÖÀÜ»ØÄê */ | |
48 #define CAT (0x0001) | |
49 #define NIT (0x0010) | |
50 #define SDT (0x0011) | |
51 #define BAT (0x0011) | |
52 #define EIT (0x0012) /* 0x0026, 0x0027 */ | |
53 #define RST (0x0013) | |
54 #define TDT (0x0014) /* Ãϥǥ¸¤Ç¤Ï»ÈÍѤµ¤ì¤Ê¤¤ */ | |
55 #define TOT (0x0014) | |
56 #define LIT (0x0020) /* ¤Þ¤¿¤ÏPMT¤Ë¤è¤ë´ÖÀÜ»ØÄê */ | |
57 #define ERT (0x0021) /* ¤Þ¤¿¤ÏPMT¤Ë¤è¤ë´ÖÀÜ»ØÄê */ | |
58 //#define ITT /* PMT¤Ë¤è¤ë´ÖÀÜ»ØÄê */ | |
59 #define PCAT (0x0022) | |
60 #define BIT (0x0024) | |
61 #define NBIT (0x0025) | |
62 //#define ECM /* PMT¤Ë¤è¤ë´ÖÀÜ»ØÄê */ | |
63 //#define EMM /* CAT¤Ë¤è¤ë´ÖÀÜ»ØÄê */ | |
64 #define LDT (0x0025) | |
65 #define DCT (0x0017) | |
66 //#define DTL /* DCT¤Ë¤è¤ë´ÖÀÜ»ØÄê */ | |
67 #define DIT (0x001e) | |
68 #define SIT (0x001f) | |
69 #define SDTT (0x0023) | |
70 #define CDT (0x0029) | |
71 //#define DSM-CC_Section /* PMT¤Ë¤è¤ë´ÖÀÜ»ØÄê */ | |
72 | |
73 /* ¥»¥¯¥·¥ç¥ó¥Ø¥Ã¥ÀĹ */ | |
74 /* TS ¥Ñ¥±¥Ã¥È¤Ë³Æ¥»¥¯¥·¥ç¥ó¤òÀßÃÖ¤¹¤ëºÝ¡¢³ºÅöTS¥Ñ¥±¥Ã¥È¤Î»Ä¥µ¥¤¥º¤¬ | |
75 * ¤¤¤¯¤Ä°Ê¾å¤¢¤ì¤Ð½ñ¤¹þ¤á¤ë¤«¤ÎȽÄê¤Ë»ÈÍѤ¹¤ë¡£ | |
76 * ¥Ç¥³¡¼¥É¤Ë¤Ï¤¢¤Þ¤ê½ÅÍפǤÏ̵¤¤¤«¤â | |
77 */ | |
78 #define SECTION_LENGTH_PAT (8) | |
79 #define SECTION_LENGTH_PMT (8) | |
80 #define SECTION_LENGTH_CAT (8) | |
81 #define SECTION_LENGTH_NIT (8) | |
82 #define SECTION_LENGTH_BIT (8) | |
83 #define SECTION_LENGTH_SDT (11) | |
84 #define SECTION_LENGTH_EIT (14) /* H-EIT, M-EIT, L-EIT ¤ò¼¨¤¹ */ | |
85 #define SECTION_LENGTH_SDTT (15) | |
86 #define SECTION_LENGTH_CDT (13) | |
87 #define SECTION_LENGTH_TOT (10) | |
88 | |
89 enum { | |
90 PTS_FLAG = 0x80, | |
91 DTS_FLAG = 0x40, | |
92 ESCR_FLAG = 0x20, | |
93 ES_RATE_FLAG = 0x10, | |
94 DSM_TRICK_MODE_FLAG = 0x08, | |
95 COPY_INFO_FLAG = 0x04, | |
96 CRC_FLAG = 0x02, | |
97 EXTENSION_FLAG = 0x01 | |
98 }; | |
99 | |
100 enum { | |
101 PES_PRIVATE_DATA_FLAG = 0x80, | |
102 PACK_HEADER_FIELD_FLAG = 0x40, | |
103 PROGRAM_PACKET_SEQUENCE_COUNTER = 0x20, | |
104 PSTD_BUFFER_FLAG = 0x10, | |
105 PES_EXTENSION_FLAG2 = 0x01 | |
106 }; | |
107 | |
108 /* | |
109 * PCR¤«¤éSTC¤òÀ¸À®¤¹¤ë½èÍýÊý¼°(°Æ) | |
110 * 1. PCR¤òÆó¤Ä¼èÆÀ¤¹¤ë¤Þ¤Ç¥ë¡¼¥×(1.¢²4.¤Þ¤Ç¤Ï½é´ü½èÍý¤Ç¼Â»Ü¤¹¤ë¤³¤È) | |
111 * 2. ¥ë¡¼¥×³«»Ï»þ¹ï(PCR)¤È¡¢¥ë¡¼¥×È´¤±¤¿»þ¹ï(PCR)¤Îº¹Ê¬¤ò¼è¤ë | |
112 * 3. ¥ë¡¼¥×³«»Ï¡Á½ªÎ»¤Î´Ö¤Ë½èÍý¤·¤¿¥Ñ¥±¥Ã¥È¿ô¤ò¿ô¤¨¤ë | |
113 * 4. (2.¤ÎPCR¤Î¿Ê¤ó¤À»þ´Ö/3.¤Î¥Ñ¥±¥Ã¥È¿ô)¡¡¤Î·×»»¤Ë¤è¤Ã¤Æ¡¢1¥Ñ¥±¥Ã¥È¤Ë¤è¤Ã¤Æ¿Ê¤àPCR¤òÁÛÄꤹ¤ë | |
114 * 5. TS¼õ¿®»þ¤Ë¡¢1¤Ä¤Î¥Ñ¥±¥Ã¥È¤ò½èÍý¤¹¤ëÅÙ¤Ë4.¤ÎÁÛÄꤹ¤ë·Ð²á»þ¹ï¤òPCR¤Ë¤·¹þ¤ó¤ÇSTC¤È¤¹¤ë | |
115 * 6. PCR¤ò¿·µ¬¤Ë¼èÆÀ¤·¤¿¤é¡¢STC¤òÊäÀµ(¤½¤Î¤Þ¤ÞÂåÆþ)¤¹¤ë | |
116 */ | |
117 #define MAX_VIDEO (16) | |
118 #define MAX_AUDIO (32) | |
119 typedef struct _program_t | |
120 { | |
121 int64_t stc; | |
122 int64_t cue; /* Ï¿²è³«»Ï»þ¹ï */ | |
123 int pmt_packet_id; /* ³ºÅöProgram(Service ID)¤ËÂбþ¤¹¤ëPMT */ | |
124 int pmt_version; /* ³ºÅöProgram(Service ID)¤ËÂбþ¤¹¤ëPMT¤ÎVersion */ | |
125 int pcr_packet_id; /* ³ºÅöProgram(Service ID)¤ÎPCR¤òÊÝ»ý¤¹¤ëPID */ | |
126 int64_t pcr1; /* PCR1 */ | |
127 int64_t pcr2; /* PCR2 */ | |
128 int pcr_packet_nb; /* ľÁ°¤ÎPCR¤ò¼õ¿®¤·¤¿¤È¤¤Î¥Ñ¥±¥Ã¥È¿ô */ | |
129 int packet_nb; /* ľÁ°¤ÎProgram¤Î½èÍý¤ò¼Â»Ü¤·¤¿¤È¤¤Î¥Ñ¥±¥Ã¥È¿ô */ | |
130 int64_t pcr_incr; /* ³ºÅöProgram(Service ID)¤Ë±÷¤¤¤Æ¡¢1¤Ä¤ÎTS¥Ñ¥±¥Ã¥È¤ò½èÍý¤·¤¿»þ¤Ë·Ð²á¤¹¤ë(¤ÈÁÛÄꤹ¤ë»þ´Ö) */ | |
131 int video_start; /* VODEO0¤òÃßÀѳ«»Ï¤·¤Æ¤¤¤ë¡© */ | |
132 int64_t video_pts; /* ºÇ¸å¤Ë½èÍý¤·¤¿VODEO0¤ÎES¤ÎPTS */ | |
133 int video_nb; /* PMT ¤Ë¸ºß¤¹¤ë¥Ó¥Ç¥ª¥¹¥È¥ê¡¼¥à¤Î¿ô */ | |
134 int audio_nb; /* PMT ¤Ë¸ºß¤¹¤ë²»À¼¥¹¥È¥ê¡¼¥à¤Î¿ô */ | |
135 int video[MAX_VIDEO]; /* PS½ÐÎϤ¹¤ë¾ì¹ç¤Ë»È¤¦¤«¤â */ | |
136 int audio[MAX_AUDIO]; /* PS½ÐÎϤ¹¤ë¾ì¹ç¤Ë»È¤¦¤«¤â */ | |
137 } program_t; | |
138 /* | |
139 * program_t ¤ò¥µ¡¼¥Ó¥¹IDʬ½àÈ÷¤·¤Æ¡¢»ÈÍѤ¹¤ë¥¤¥á¡¼¥¸¤Ç¤¤¤¿¤±¤É¡¢ | |
140 * ¥µ¡¼¥Ó¥¹ID¤ÎºÇÂçÃͤÏ0xFFFF¤Ç¤¢¤ë¤Î¤Ç¡¢ÀÅŪ¤Ë³ÎÊݤ¹¤ë¤È stack ¤¬´Êñ¤Ë°î¤ë¤Î¤Ç¡¢ | |
141 * ¼Â¹Ô»þ¤Ë malloc ¤È¤¹¤ë¤«¤Ê¤¡ | |
142 * ËÜÅö¤ÏɬÍפʤÀ¤±alloc¤¹¤ë¤Î¤¬¹¥¤Þ¤·¤¤¤Î¤À¤±¤É¡Ä | |
143 */ | |
144 | |
145 typedef struct _splitpesbuf_t | |
146 { | |
147 program_t *Program; | |
148 int64_t pts; | |
149 int64_t dts; | |
150 int size; | |
151 u_char buffer[128*1024]; | |
152 } splitpesbuf_t; | |
153 | |
154 typedef struct _splitesbuf_t | |
155 { | |
156 program_t *Program; | |
157 int64_t pts; | |
158 int64_t dts; | |
159 int started; /* ³ºÅöES¤¬ÃßÀѳ«»Ï¤·¤Æ¤¤¤ë¤« */ | |
160 int random_access_indicator; /* TS ¤Î random_access_indicator */ | |
161 int fd; /* ³ºÅöES¤Îfd */ | |
162 int size; | |
163 u_char buffer[3*1024*1024]; | |
164 } splitesbuf_t; | |
165 | |
166 /* PCR ¶¦ÍÍѹ½Â¤ÂÎ */ | |
167 typedef struct _pcr_t | |
168 { | |
169 int pid; | |
170 int sid_nb; /* PCR¤ò»²¾È¤·¤Æ¤¤¤ëServiceID(ProgramID)¤Î¿ô */ | |
171 int sid[MAX_SERVICES]; | |
172 } pcr_t; | |
173 | |
174 | |
175 /** | |
176 * splitter¹½Â¤ÂÎ | |
177 */ | |
178 typedef struct splitter { | |
179 char *filename; /* ¥Õ¥¡¥¤¥ë̾¤ò¾å°Ì¤«¤é¤â¤é¤Ã¤Æ¤¯¤ë¤¿¤á¤Î¥Ý¥¤¥ó¥¿ */ | |
180 char *arg_cue; /* °ú¿ô¤Ç¼èÆÀ¤·¤Æ¤¤¿Ï¿²è³«»Ï»þ¹ï(HHMISS) */ | |
181 int esout; /* ES½ÐÎϤ¹¤ë¡© */ | |
182 unsigned char pids[MAX_PID]; | |
183 unsigned char pmt_pids[MAX_PID]; | |
184 uint8_t cat_pids[MAX_PID]; | |
185 uint8_t pcr_pids[MAX_PID]; /* PCR¤ÏÊ£¿ôServiceID(ProgramID)¤Ç¶¦Í¤µ¤ì¤ë */ | |
186 pcr_t pcr[MAX_SERVICES]; | |
187 int pcr_nb; | |
188 unsigned char* pat; | |
189 char** sid_list; | |
190 unsigned char pat_count; | |
191 int pmt_retain; | |
192 int pmt_counter; | |
193 int avail_pmts[MAX_SERVICES]; | |
194 int num_pmts; | |
195 splitpesbuf_t *pesbuf[MAX_PID]; | |
196 splitesbuf_t *esbuf[MAX_PID]; | |
197 program_t *program; | |
198 int pid_sid_table[MAX_PID]; /* pid to sid ¤ÎÊÑ´¹¤ò¹Ô¤¦¤¿¤á¤Î¥Æ¡¼¥Ö¥ë */ | |
199 time_t time_cue; | |
200 time_t time_tot; | |
201 int tot_packet_nb; /* TOT¼õ¿®»þ¤Î¥Ñ¥±¥Ã¥È¼õ¿®¿ô */ | |
202 } splitter; | |
203 | |
204 /* b25 decoder would hoard up large chank */ | |
205 typedef struct _splitbuf_t | |
206 { | |
207 int size; | |
208 u_char buffer[1024*1024]; | |
209 } splitbuf_t; | |
210 | |
211 splitter* split_startup(char *sid, char *filename, char *cue_time); | |
212 int split_select(splitter *sp, ARIB_STD_B25_BUFFER *sbuf); | |
213 void split_shutdown(splitter *sp); | |
214 int split_ts(splitter *splitter, ARIB_STD_B25_BUFFER *sbuf, splitbuf_t *dbuf); | |
215 | |
216 #endif |