comparison recpt1/tssplitter_lite.c @ 142:1e7718cc2556

use utf-8 instead of euc-jp
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Wed, 30 Apr 2014 11:26:24 +0900
parents 61ff9cabf962
children
comparison
equal deleted inserted replaced
141:c8688d7d6382 142:1e7718cc2556
36 static int AnalyzePmt(splitter *sp, unsigned char *buf, unsigned char mark); 36 static int AnalyzePmt(splitter *sp, unsigned char *buf, unsigned char mark);
37 static int GetCrc32(unsigned char *data, int len); 37 static int GetCrc32(unsigned char *data, int len);
38 static int GetPid(unsigned char *data); 38 static int GetPid(unsigned char *data);
39 39
40 /** 40 /**
41 * サービスID解析 41 * 泣若ID茹f
42 */ 42 */
43 static char** AnalyzeSid( 43 static char** AnalyzeSid(
44 char* sid) // [in] サービスID(カンマ区切りテキスト) 44 char* sid) // [in] 泣若ID(潟阪鴻)
45 { 45 {
46 int i = 0; 46 int i = 0;
47 char** sid_list = NULL; 47 char** sid_list = NULL;
48 char* p; 48 char* p;
49 int CommaNum = 0; 49 int CommaNum = 0;
50 50
51 /* sid は次の形式の引数を許容する */ 51 /* sid 罨<綵√綣違荐怨鴻 */
52 /* 指定無し */ 52 /* 絎< */
53 /* SID[0] */ 53 /* SID[0] */
54 /* SID[0],SID[1],...,SID[N-1],SID[N] */ 54 /* SID[0],SID[1],...,SID[N-1],SID[N] */
55 55
56 /*カンマの数を数える*/ 56 /*潟違違*/
57 p = sid; 57 p = sid;
58 while(*p != '\0') 58 while(*p != '\0')
59 { 59 {
60 if( *p == C_CHAR_COMMA ){ 60 if( *p == C_CHAR_COMMA ){
61 CommaNum++; 61 CommaNum++;
62 } 62 }
63 p++; 63 p++;
64 } 64 }
65 65
66 /* sid_listの数はカンマの数+2(NULL止めするから) */ 66 /* sid_list違潟+2(NULL罩≪) */
67 sid_list = malloc(sizeof(char*)*(CommaNum+2)); 67 sid_list = malloc(sizeof(char*)*(CommaNum+2));
68 if ( sid_list == NULL ) 68 if ( sid_list == NULL )
69 { 69 {
70 fprintf(stderr, "AnalyzeSid() malloc error.\n"); 70 fprintf(stderr, "AnalyzeSid() malloc error.\n");
71 return NULL; 71 return NULL;
72 } 72 }
73 73
74 /* sidが空である場合 */ 74 /* sid腥冴с翫 */
75 p = sid; 75 p = sid;
76 if ( strlen(p) == 0 ) 76 if ( strlen(p) == 0 )
77 { 77 {
78 sid_list[0] = NULL; 78 sid_list[0] = NULL;
79 return sid_list; 79 return sid_list;
80 } 80 }
81 81
82 /* カンマ無し */ 82 /* 潟< */
83 if ( CommaNum == 0 ) 83 if ( CommaNum == 0 )
84 { 84 {
85 sid_list[0] = sid; 85 sid_list[0] = sid;
86 sid_list[1] = NULL; 86 sid_list[1] = NULL;
87 return sid_list; 87 return sid_list;
88 } 88 }
89 89
90 /* カンマ区切りで複数指定時 */ 90 /* 潟阪ц井絎 */
91 i=0; 91 i=0;
92 p = sid; 92 p = sid;
93 /* 文字列端に到達するか、カンマ数が数えた数に達したら終了 */ 93 /* 絖腴育潟違違違腟篋 */
94 while((*p != '\0') || i < CommaNum) 94 while((*p != '\0') || i < CommaNum)
95 { 95 {
96 /* 現在の処理位置をsid_list[i]にセット */ 96 /* 憜篏臀sid_list[i]祉 */
97 /* このタイミングの p は 97 /* 帥ゃ潟違 p
98 * ・sid先頭 98 * sid
99 * ・[,]の次の文字 99 * [,]罨<絖
100 * いずれかであるので p を sid_list[i] に代入してよい 100 * с p sid_list[i] 篁eャ
101 */ 101 */
102 sid_list[i] = p; 102 sid_list[i] = p;
103 i++; 103 i++;
104 104
105 /* 最初に現れる[,]をNULL文字で置換する */ 105 /* 憗[,]NULL絖х舟 */
106 p = strchr(p, C_CHAR_COMMA); 106 p = strchr(p, C_CHAR_COMMA);
107 if ( p == NULL ) 107 if ( p == NULL )
108 { 108 {
109 /* カンマが見つからない場合は最後の処理対象なので終了 */ 109 /* 潟荀ゃ翫緇絲乗院х篋 */
110 break; 110 break;
111 } 111 }
112 *p = '\0'; 112 *p = '\0';
113 /* 処理位置をNULLで置換した文字の次の位置に設定する */ 113 /* 篏臀NULLх舟絖罨<篏臀荐絎 */
114 p++; 114 p++;
115 } 115 }
116 116
117 /* 最後のsid_list[n]はNULLポインタで止める */ 117 /* 緇sid_list[n]NULLゃ潟帥ф≪ */
118 sid_list[i] = NULL; 118 sid_list[i] = NULL;
119 119
120 i=0; 120 i=0;
121 while( sid_list[i] != NULL ) 121 while( sid_list[i] != NULL )
122 { 122 {
130 #endif 130 #endif
131 return sid_list; 131 return sid_list;
132 } 132 }
133 133
134 /** 134 /**
135 * 初期化処理 135 *
136 */ 136 */
137 splitter* split_startup( 137 splitter* split_startup(
138 char *sid // [in] サービスID(引数で指定した文字列) 138 char *sid // [in] 泣若ID(綣違ф絎絖)
139 ) 139 )
140 { 140 {
141 splitter* sp; 141 splitter* sp;
142 sp = malloc(sizeof(splitter)); 142 sp = malloc(sizeof(splitter));
143 if ( sp == NULL ) 143 if ( sp == NULL )
165 165
166 return sp; 166 return sp;
167 } 167 }
168 168
169 /** 169 /**
170 * 落とすPIDを確定させる 170 * 純PID腆阪
171 */ 171 */
172 int split_select( 172 int split_select(
173 splitter *sp, // [in/out] splitter構造体 173 splitter *sp, // [in/out] splitter罕篏
174 ARIB_STD_B25_BUFFER *sbuf // [in] 入力TS 174 ARIB_STD_B25_BUFFER *sbuf // [in] ュTS
175 ) 175 )
176 { 176 {
177 int result; 177 int result;
178 // TS解析 178 // TS茹f
179 result = ReadTs(sp, sbuf); 179 result = ReadTs(sp, sbuf);
180 180
181 return result; 181 return result;
182 } 182 }
183 183
184 /** 184 /**
185 * 終了処理 185 * 腟篋
186 */ 186 */
187 void split_shutdown(splitter* sp) 187 void split_shutdown(splitter* sp)
188 { 188 {
189 if ( sp != NULL ) { 189 if ( sp != NULL ) {
190 if ( sp->pat != NULL ) 190 if ( sp->pat != NULL )
201 sp = NULL; 201 sp = NULL;
202 } 202 }
203 } 203 }
204 204
205 /** 205 /**
206 * TS 解析処理 206 * TS 茹f
207 * 207 *
208 * 対象のチャンネル番号のみの PAT の再構築と出力対象 PID の抽出を行う 208 * 絲乗院c潟垩帥 PAT 罕膀阪絲乗院 PID 遵冴茵
209 */ 209 */
210 static int ReadTs(splitter *sp, ARIB_STD_B25_BUFFER *sbuf) 210 static int ReadTs(splitter *sp, ARIB_STD_B25_BUFFER *sbuf)
211 #if 0 211 #if 0
212 unsigned char **pat, // [out] PAT 情報(再構築後) 212 unsigned char **pat, // [out] PAT 縁罕膀緇鐚
213 unsigned char* pids, // [out] 出力対象 PID 情報 213 unsigned char* pids, // [out] 阪絲乗院 PID
214 char** sid_list, // [in] 出力対象サービス ID のリスト 214 char** sid_list, // [in] 阪絲乗院泣若 ID 鴻
215 unsigned char* pmt_pids, // [in] 出力対象PIDのPMT PID 215 unsigned char* pmt_pids, // [in] 阪絲乗院PIDPMT PID
216 , // [in] pt1_drvの入力TS 216 , // [in] pt1_drvュTS
217 int* pmt_retain, // [in] 残すべきPMTの数 217 int* pmt_retain, // [in] 罧鴻PMT
218 int* pmt_counter // [out] 残したPMTの数 218 int* pmt_counter // [out] 罧PMT
219 #endif 219 #endif
220 { 220 {
221 int length = sbuf->size; 221 int length = sbuf->size;
222 int pid; 222 int pid;
223 int result = TSS_ERROR; 223 int result = TSS_ERROR;
229 pid = GetPid(sbuf->data + index + 1); 229 pid = GetPid(sbuf->data + index + 1);
230 // PAT 230 // PAT
231 if(0x0000 == pid) { 231 if(0x0000 == pid) {
232 result = AnalyzePat(sp, sbuf->data + index); 232 result = AnalyzePat(sp, sbuf->data + index);
233 if(result != TSS_SUCCESS) { 233 if(result != TSS_SUCCESS) {
234 /* 下位の関数内部でmalloc error発生 */ 234 /* 筝篏∽医malloc error榊 */
235 return result; 235 return result;
236 } 236 }
237 } 237 }
238 238
239 // PMT 239 // PMT
240 /* 残すpmt_pidである場合には、pmtに書かれている 240 /* 罧pmt_pidс翫pmt吾
241 * 残すべきPCR/AUDIO/VIDEO PIDを取得する */ 241 * 罧鴻PCR/AUDIO/VIDEO PID緇 */
242 if(sp->pmt_pids[pid] == 1) { 242 if(sp->pmt_pids[pid] == 1) {
243 /* この中にはPMT毎に一度しか入らないようにしておく */ 243 /* 筝PMT罸筝綺ャ */
244 analyze_result = AnalyzePmt(sp, sbuf->data + index, 1); 244 analyze_result = AnalyzePmt(sp, sbuf->data + index, 1);
245 if(TSS_SUCCESS == analyze_result) { 245 if(TSS_SUCCESS == analyze_result) {
246 sp->pmt_pids[pid]++; 246 sp->pmt_pids[pid]++;
247 sp->pmt_counter += 1; 247 sp->pmt_counter += 1;
248 *(sbuf->data + index + 1) = 0xff; 248 *(sbuf->data + index + 1) = 0xff;
249 *(sbuf->data + index + 2) = 0xff; 249 *(sbuf->data + index + 2) = 0xff;
250 } 250 }
251 } 251 }
252 /* 録画する全てのPMTについて、中にあるPCR/AUDIO/VIDEOのPIDを 252 /* 牙祉PMTゃ筝PCR/AUDIO/VIDEOPID
253 * 得る */ 253 * 緇 */
254 /* pmt_counter と pmt_retain が一致する場合に条件は満たされる */ 254 /* pmt_counter pmt_retain 筝眼翫>散羣 */
255 if(sp->pmt_counter == sp->pmt_retain) { 255 if(sp->pmt_counter == sp->pmt_retain) {
256 result = TSS_SUCCESS; 256 result = TSS_SUCCESS;
257 break; 257 break;
258 } 258 }
259 else { 259 else {
295 } 295 }
296 296
297 return result; 297 return result;
298 } 298 }
299 /** 299 /**
300 * TS 分離処理 300 * TS √
301 */ 301 */
302 int split_ts( 302 int split_ts(
303 splitter *splitter, // [in] splitterパラメータ 303 splitter *splitter, // [in] splitter<若
304 ARIB_STD_B25_BUFFER *sbuf, // [in] 入力TS 304 ARIB_STD_B25_BUFFER *sbuf, // [in] ュTS
305 splitbuf_t *dbuf // [out] 出力TS 305 splitbuf_t *dbuf // [out] 阪TS
306 ) 306 )
307 { 307 {
308 int pid; 308 int pid;
309 unsigned char *sptr, *dptr; 309 unsigned char *sptr, *dptr;
310 int s_offset = 0; 310 int s_offset = 0;
311 int d_offset = 0; 311 int d_offset = 0;
312 int result = TSS_SUCCESS; 312 int result = TSS_SUCCESS;
313 int pmts = 0; 313 int pmts = 0;
314 int version = 0; 314 int version = 0;
315 315
316 /* 初期化 */ 316 /* */
317 dbuf->buffer_filled = 0; 317 dbuf->buffer_filled = 0;
318 if (sbuf->size < 0) { 318 if (sbuf->size < 0) {
319 return TSS_ERROR; 319 return TSS_ERROR;
320 } 320 }
321 321
326 pid = GetPid(sptr + s_offset + 1); 326 pid = GetPid(sptr + s_offset + 1);
327 switch(pid) { 327 switch(pid) {
328 328
329 // PAT 329 // PAT
330 case 0x0000: 330 case 0x0000:
331 // 巡回カウンタカウントアップ 331 // 綏≦潟帥潟≪
332 if(0xFF == splitter->pat_count) { 332 if(0xFF == splitter->pat_count) {
333 splitter->pat_count = splitter->pat[3]; 333 splitter->pat_count = splitter->pat[3];
334 } 334 }
335 else { 335 else {
336 splitter->pat_count += 1; 336 splitter->pat_count += 1;
345 dbuf->buffer_filled += LENGTH_PACKET; 345 dbuf->buffer_filled += LENGTH_PACKET;
346 break; 346 break;
347 default: 347 default:
348 if(0 != splitter->pmt_pids[pid]) { 348 if(0 != splitter->pmt_pids[pid]) {
349 //PMT 349 //PMT
350 if ((sptr + s_offset)[1] & 0x40) { // PES開始インジケータ 350 if ((sptr + s_offset)[1] & 0x40) { // PES紮ゃ潟吾宴若
351 // バージョンチェック 351 // 若吾с潟с
352 for(pmts = 0; splitter->pmt_retain > pmts; pmts++) { 352 for(pmts = 0; splitter->pmt_retain > pmts; pmts++) {
353 if (splitter->pmt_version[pmts].pid == pid) { 353 if (splitter->pmt_version[pmts].pid == pid) {
354 version = splitter->pmt_version[pmts].version; 354 version = splitter->pmt_version[pmts].version;
355 break; 355 break;
356 } 356 }
357 } 357 }
358 if((version != ((sptr + s_offset)[10] & 0x3e)) 358 if((version != ((sptr + s_offset)[10] & 0x3e))
359 ||(splitter->pmt_retain != splitter->pmt_counter)) { 359 ||(splitter->pmt_retain != splitter->pmt_counter)) {
360 // 再チェック 360 // с
361 result = RescanPID(splitter, sptr + s_offset); 361 result = RescanPID(splitter, sptr + s_offset);
362 } 362 }
363 } 363 }
364 else { 364 else {
365 if (splitter->pmt_retain != splitter->pmt_counter) { 365 if (splitter->pmt_retain != splitter->pmt_counter) {
366 // 再チェック 366 // с
367 result = RescanPID(splitter, sptr + s_offset); 367 result = RescanPID(splitter, sptr + s_offset);
368 } 368 }
369 } 369 }
370 } 370 }
371 /* pids[pid] が 1 は残すパケットなので書き込む */ 371 /* pids[pid] 1 罧宴ф吾莨若 */
372 if(0 != splitter->pids[pid]) { 372 if(0 != splitter->pids[pid]) {
373 memcpy(dptr + d_offset, sptr + s_offset, LENGTH_PACKET); 373 memcpy(dptr + d_offset, sptr + s_offset, LENGTH_PACKET);
374 d_offset += LENGTH_PACKET; 374 d_offset += LENGTH_PACKET;
375 dbuf->buffer_filled += LENGTH_PACKET; 375 dbuf->buffer_filled += LENGTH_PACKET;
376 } 376 }
382 382
383 return result; 383 return result;
384 } 384 }
385 385
386 /** 386 /**
387 * PAT 解析処理 387 * PAT 茹f
388 * 388 *
389 * PAT を解析し、出力対象チャンネルが含まれているかチェックを行い、PAT を再構築する 389 * PAT 茹f阪絲乗院c潟障с茵PAT 罕膀
390 */ 390 */
391 static int AnalyzePat(splitter *sp, unsigned char *buf) 391 static int AnalyzePat(splitter *sp, unsigned char *buf)
392 #if 0 392 #if 0
393 splitter *sp 393 splitter *sp
394 unsigned char** pat, // [out] PAT 情報(再構築後) 394 unsigned char** pat, // [out] PAT 縁罕膀緇鐚
395 unsigned char* pids, // [out] 出力対象 PID 情報 395 unsigned char* pids, // [out] 阪絲乗院 PID
396 char** sid_list, // [in] 出力対象サービス ID のリスト 396 char** sid_list, // [in] 阪絲乗院泣若 ID 鴻
397 unsigned char* pmt_pids, // [out] サービス ID に対応する PMT の PID 397 unsigned char* pmt_pids, // [out] 泣若 ID 絲上 PMT PID
398 int* pmt_retain // [out] 残すPMTの数 398 int* pmt_retain // [out] 罧PMT
399 399
400 unsigned char* buf, // [in] 読み込んだバッファ 400 unsigned char* buf, // [in] 茯粋昭
401 #endif 401 #endif
402 { 402 {
403 int pos[MAX_PID]; 403 int pos[MAX_PID];
404 int service_id; 404 int service_id;
405 int i, j, k; 405 int i, j, k;
417 417
418 char chosen_sid[512]; 418 char chosen_sid[512];
419 chosen_sid[0] = '\0'; 419 chosen_sid[0] = '\0';
420 420
421 if(pat == NULL) { 421 if(pat == NULL) {
422 /* 初期化 */ 422 /* */
423 sp->pmt_retain = 0; 423 sp->pmt_retain = 0;
424 memset(pos, 0, sizeof(pos)); 424 memset(pos, 0, sizeof(pos));
425 size = buf[7]; 425 size = buf[7];
426 426
427 /* prescan SID/PMT */ 427 /* prescan SID/PMT */
435 sp->avail_pmts[j] = pid; 435 sp->avail_pmts[j] = pid;
436 j++; 436 j++;
437 } 437 }
438 sp->num_pmts = j; 438 sp->num_pmts = j;
439 439
440 // 対象チャンネル判定 440 // 絲乗院c潟ゅ
441 /* size + 8 = パケット全長 */ 441 /* size + 8 = 宴 */
442 /* 最終 4 バイトはCRCなので飛ばす */ 442 /* 腟 4 ゃCRCч違 */
443 for(i = 13; i < (size + 8) - 4; i = i + 4) { 443 for(i = 13; i < (size + 8) - 4; i = i + 4) {
444 444
445 pid = GetPid(&buf[i+2]); 445 pid = GetPid(&buf[i+2]);
446 if(pid == 0x0010) 446 if(pid == 0x0010)
447 continue; 447 continue;
449 service_id = (buf[i] << 8) + buf[i+1]; 449 service_id = (buf[i] << 8) + buf[i+1];
450 p = sid_list; 450 p = sid_list;
451 451
452 while(*p) { 452 while(*p) {
453 if(service_id == atoi(*p)) { 453 if(service_id == atoi(*p)) {
454 /* 録画対象の pmt_pids は 1 とする */ 454 /* 牙糸乗院 pmt_pids 1 */
455 /* 録画対象の pmt の pids は 1 とする */ 455 /* 牙糸乗院 pmt pids 1 */
456 pid = GetPid(&buf[i + 2]); 456 pid = GetPid(&buf[i + 2]);
457 *(pmt_pids+pid) = 1; 457 *(pmt_pids+pid) = 1;
458 *(pids+pid) = 1; 458 *(pids+pid) = 1;
459 pos[pid] = i; 459 pos[pid] = i;
460 sid_found = TRUE; 460 sid_found = TRUE;
463 sprintf(chosen_sid, "%s %d", *chosen_sid ? chosen_sid : "", service_id); 463 sprintf(chosen_sid, "%s %d", *chosen_sid ? chosen_sid : "", service_id);
464 p++; 464 p++;
465 continue; 465 continue;
466 } 466 }
467 else if(!strcasecmp(*p, "hd") || !strcasecmp(*p, "sd1")) { 467 else if(!strcasecmp(*p, "hd") || !strcasecmp(*p, "sd1")) {
468 /* hd/sd1 指定時には1番目のサービスを保存する */ 468 /* hd/sd1 絎1泣若鴻篆絖 */
469 if(service_id == avail_sids[0]) { 469 if(service_id == avail_sids[0]) {
470 pid = GetPid(&buf[i + 2]); 470 pid = GetPid(&buf[i + 2]);
471 *(pmt_pids+pid) = 1; 471 *(pmt_pids+pid) = 1;
472 *(pids+pid) = 1; 472 *(pids+pid) = 1;
473 pos[pid] = i; 473 pos[pid] = i;
478 } 478 }
479 p++; 479 p++;
480 continue; 480 continue;
481 } 481 }
482 else if(!strcasecmp(*p, "sd2")) { 482 else if(!strcasecmp(*p, "sd2")) {
483 /* sd2 指定時には2番目のサービスを保存する */ 483 /* sd2 絎2泣若鴻篆絖 */
484 if(service_id == avail_sids[1]) { 484 if(service_id == avail_sids[1]) {
485 pid = GetPid(&buf[i + 2]); 485 pid = GetPid(&buf[i + 2]);
486 *(pmt_pids+pid) = 1; 486 *(pmt_pids+pid) = 1;
487 *(pids+pid) = 1; 487 *(pids+pid) = 1;
488 pos[pid] = i; 488 pos[pid] = i;
493 } 493 }
494 p++; 494 p++;
495 continue; 495 continue;
496 } 496 }
497 else if(!strcasecmp(*p, "sd3")) { 497 else if(!strcasecmp(*p, "sd3")) {
498 /* sd3 指定時には3番目のサービスを保存する */ 498 /* sd3 絎3泣若鴻篆絖 */
499 if(service_id == avail_sids[2]) { 499 if(service_id == avail_sids[2]) {
500 pid = GetPid(&buf[i + 2]); 500 pid = GetPid(&buf[i + 2]);
501 *(pmt_pids+pid) = 1; 501 *(pmt_pids+pid) = 1;
502 *(pids+pid) = 1; 502 *(pids+pid) = 1;
503 pos[pid] = i; 503 pos[pid] = i;
508 } 508 }
509 p++; 509 p++;
510 continue; 510 continue;
511 } 511 }
512 else if(!strcasecmp(*p, "1seg")) { 512 else if(!strcasecmp(*p, "1seg")) {
513 /* 1seg 指定時には PMTPID=0x1FC8 のサービスを保存する */ 513 /* 1seg 絎 PMTPID=0x1FC8 泣若鴻篆絖 */
514 pid = GetPid(&buf[i + 2]); 514 pid = GetPid(&buf[i + 2]);
515 if(pid == 0x1FC8) { 515 if(pid == 0x1FC8) {
516 *(pmt_pids+pid) = 1; 516 *(pmt_pids+pid) = 1;
517 *(pids+pid) = 1; 517 *(pids+pid) = 1;
518 pos[pid] = i; 518 pos[pid] = i;
523 } 523 }
524 p++; 524 p++;
525 continue; 525 continue;
526 } 526 }
527 else if(!strcasecmp(*p, "all")) { 527 else if(!strcasecmp(*p, "all")) {
528 /* all指定時には全保存する */ 528 /* all絎篆絖 */
529 pid = GetPid(&buf[i + 2]); 529 pid = GetPid(&buf[i + 2]);
530 *(pmt_pids+pid) = 1; 530 *(pmt_pids+pid) = 1;
531 *(pids+pid) = 1; 531 *(pids+pid) = 1;
532 pos[pid] = i; 532 pos[pid] = i;
533 sid_found = TRUE; 533 sid_found = TRUE;
535 sp->pmt_retain += 1; 535 sp->pmt_retain += 1;
536 sprintf(chosen_sid, "%s %d", *chosen_sid ? chosen_sid : "", service_id); 536 sprintf(chosen_sid, "%s %d", *chosen_sid ? chosen_sid : "", service_id);
537 break; 537 break;
538 } 538 }
539 else if(!strcasecmp(*p, "epg")) { 539 else if(!strcasecmp(*p, "epg")) {
540 /* epg抽出に必要なPIDのみを保存する */ 540 /* epg遵冴綽荀PID帥篆絖 */
541 sid_found = TRUE; 541 sid_found = TRUE;
542 *(pids+0x11) = 1; 542 *(pids+0x11) = 1;
543 *(pids+0x12) = 1; 543 *(pids+0x12) = 1;
544 *(pids+0x26) = 1; 544 *(pids+0x26) = 1;
545 *(pids+0x27) = 1; 545 *(pids+0x27) = 1;
583 for(k=0; k < sp->num_pmts; k++) 583 for(k=0; k < sp->num_pmts; k++)
584 fprintf(stderr, "0x%x ", sp->avail_pmts[k]); 584 fprintf(stderr, "0x%x ", sp->avail_pmts[k]);
585 fprintf(stderr, "\n"); 585 fprintf(stderr, "\n");
586 #endif 586 #endif
587 587
588 // PAT 再構築 588 // PAT 罕膀
589 result = RecreatePat(sp, buf, pos); 589 result = RecreatePat(sp, buf, pos);
590 #if 0 590 #if 0
591 int tc; 591 int tc;
592 for(tc=0; tc<188; tc++) 592 for(tc=0; tc<188; tc++)
593 fprintf(stderr, "%02x ", *(sp->pat+tc)); 593 fprintf(stderr, "%02x ", *(sp->pat+tc));
596 596
597 return(result); 597 return(result);
598 } 598 }
599 599
600 /** 600 /**
601 * PAT 再構築処理 601 * PAT 罕膀
602 * 602 *
603 * PMT から出力対象チャンネル以外のチャンネル情報を削除し、PAT を再構築する 603 * PMT 阪絲乗院c潟篁ュc潟宴ゃPAT 罕膀
604 */ 604 */
605 static int RecreatePat(splitter *sp, unsigned char *buf, int *pos) 605 static int RecreatePat(splitter *sp, unsigned char *buf, int *pos)
606 #if 0 606 #if 0
607 splitter *sp // [in/out] 607 splitter *sp // [in/out]
608 unsigned char** pat, // [out] PAT 情報(再構築後) 608 unsigned char** pat, // [out] PAT 縁罕膀緇鐚
609 unsigned char* pids, // [out] 出力対象 PID 情報 609 unsigned char* pids, // [out] 阪絲乗院 PID
610 610
611 unsigned char* buf, // [in] 読み込んだバッファ 611 unsigned char* buf, // [in] 茯粋昭
612 int *pos // [in] 取得対象 PMT のバッファ中の位置 612 int *pos // [in] 緇絲乗院 PMT >賢篏臀
613 #endif 613 #endif
614 { 614 {
615 unsigned char y[LENGTH_CRC_DATA]; 615 unsigned char y[LENGTH_CRC_DATA];
616 int crc; 616 int crc;
617 int i; 617 int i;
618 int j; 618 int j;
619 int pos_i; 619 int pos_i;
620 int pid_num = 0; 620 int pid_num = 0;
621 621
622 // CRC 計算のためのデータ 622 // CRC 荐膊若
623 { 623 {
624 // チャンネルによって変わらない部分 624 // c潟c紊
625 for (i = 0; i < LENGTH_PAT_HEADER - 4; i++) 625 for (i = 0; i < LENGTH_PAT_HEADER - 4; i++)
626 { 626 {
627 y[i] = buf[i + 5]; 627 y[i] = buf[i + 5];
628 } 628 }
629 629
631 y[LENGTH_PAT_HEADER-4] = 0x00; 631 y[LENGTH_PAT_HEADER-4] = 0x00;
632 y[LENGTH_PAT_HEADER-3] = 0x00; 632 y[LENGTH_PAT_HEADER-3] = 0x00;
633 y[LENGTH_PAT_HEADER-2] = 0xe0; 633 y[LENGTH_PAT_HEADER-2] = 0xe0;
634 y[LENGTH_PAT_HEADER-1] = 0x10; 634 y[LENGTH_PAT_HEADER-1] = 0x10;
635 635
636 // チャンネルによって変わる部分 636 // c潟c紊
637 for (i = 0; i < MAX_PID; i++) 637 for (i = 0; i < MAX_PID; i++)
638 { 638 {
639 if(pos[i] != 0) 639 if(pos[i] != 0)
640 { 640 {
641 /* buf[pos_i] を y にコピー(抽出したPIDの数) */ 641 /* buf[pos_i] y 潟(遵冴PID) */
642 pos_i = pos[i]; 642 pos_i = pos[i];
643 for (j = 0; j < 4; j++) 643 for (j = 0; j < 4; j++)
644 { 644 {
645 y[LENGTH_PAT_HEADER + ((4*pid_num) + j)] = buf[pos_i + j]; 645 y[LENGTH_PAT_HEADER + ((4*pid_num) + j)] = buf[pos_i + j];
646 } 646 }
647 pid_num++; 647 pid_num++;
648 } 648 }
649 } 649 }
650 } 650 }
651 /* パケットサイズ計算 */ 651 /* 宴泣ゃ肴膊 */
652 y[2] = pid_num * 4 + 0x0d; 652 y[2] = pid_num * 4 + 0x0d;
653 // CRC 計算 653 // CRC 荐膊
654 crc = GetCrc32(y, LENGTH_PAT_HEADER + pid_num*4); 654 crc = GetCrc32(y, LENGTH_PAT_HEADER + pid_num*4);
655 655
656 // PAT 再構成 656 // PAT 罕
657 sp->pat = (unsigned char*)malloc(LENGTH_PACKET); 657 sp->pat = (unsigned char*)malloc(LENGTH_PACKET);
658 if(sp->pat == NULL) 658 if(sp->pat == NULL)
659 { 659 {
660 fprintf(stderr, "RecreatePat() malloc error.\n"); 660 fprintf(stderr, "RecreatePat() malloc error.\n");
661 return(TSS_NULL); 661 return(TSS_NULL);
676 676
677 return(TSS_SUCCESS); 677 return(TSS_SUCCESS);
678 } 678 }
679 679
680 /** 680 /**
681 * PMT 解析処理 681 * PMT 茹f
682 * 682 *
683 * PMT を解析し、保存対象の PID を特定する 683 * PMT 茹f篆絖絲乗院 PID 劫
684 */ 684 */
685 static int AnalyzePmt(splitter *sp, unsigned char *buf, unsigned char mark) 685 static int AnalyzePmt(splitter *sp, unsigned char *buf, unsigned char mark)
686 #if 0 686 #if 0
687 unsigned char* buf, // [in] 読み込んだバッファ 687 unsigned char* buf, // [in] 茯粋昭
688 unsigned char* pids // [out] 出力対象 PID 情報 688 unsigned char* pids // [out] 阪絲乗院 PID
689 #endif 689 #endif
690 { 690 {
691 unsigned char Nall; 691 unsigned char Nall;
692 unsigned char N; 692 unsigned char N;
693 int pcr; 693 int pcr;
696 int retry_count = 0; 696 int retry_count = 0;
697 int count; 697 int count;
698 int payload_offset; // offset to payload 698 int payload_offset; // offset to payload
699 699
700 pid = GetPid(&buf[1]); 700 pid = GetPid(&buf[1]);
701 if (buf[1] & 0x40) { // PES開始インジケータ 701 if (buf[1] & 0x40) { // PES紮ゃ潟吾宴若
702 sp->section_remain[pid] = ((buf[6] & 0x0F) << 8) + buf[7] + 3; // セクションサイズ取得(ヘッダ込) 702 sp->section_remain[pid] = ((buf[6] & 0x0F) << 8) + buf[7] + 3; // 祉激с潟泣ゃ阪緇(莨)
703 payload_offset = 5; 703 payload_offset = 5;
704 704
705 for (count = 0; sp->pmt_retain > count; count++) { 705 for (count = 0; sp->pmt_retain > count; count++) {
706 if (sp->pmt_version[count].pid == pid) { 706 if (sp->pmt_version[count].pid == pid) {
707 sp->pmt_version[count].version = buf[10] & 0x3e; 707 sp->pmt_version[count].version = buf[10] & 0x3e;
708 } 708 }
709 } 709 }
710 // PCR, 番組情報が先頭からはみ出ることはないだろう 710 // PCR, 腟宴水冴
711 711
712 // PCR 712 // PCR
713 pcr = GetPid(&buf[payload_offset + 8]); 713 pcr = GetPid(&buf[payload_offset + 8]);
714 sp->pids[pcr] = mark; 714 sp->pids[pcr] = mark;
715 715
716 // ECM 716 // ECM
717 N = ((buf[payload_offset + 10] & 0x0F) << 8) + buf[payload_offset + 11] + payload_offset + 12; // ES情報開始点 717 N = ((buf[payload_offset + 10] & 0x0F) << 8) + buf[payload_offset + 11] + payload_offset + 12; // ES演紮
718 int p = payload_offset + 12; 718 int p = payload_offset + 12;
719 719
720 while(p < N) { 720 while(p < N) {
721 uint32_t ca_pid; 721 uint32_t ca_pid;
722 uint32_t tag; 722 uint32_t tag;
732 } 732 }
733 p += len; 733 p += len;
734 } 734 }
735 } 735 }
736 else { 736 else {
737 if (sp->section_remain[pid] == 0) return TSS_ERROR; // セクション先頭が飛んでいる 737 if (sp->section_remain[pid] == 0) return TSS_ERROR; // 祉激с喝蕋с
738 if ((buf[3] & 0x0F) != ((sp->packet_seq[pid] + 1) & 0x0F)) return TSS_ERROR; // パケットカウンタが飛んだ 738 if ((buf[3] & 0x0F) != ((sp->packet_seq[pid] + 1) & 0x0F)) return TSS_ERROR; // 宴潟帥蕋
739 payload_offset = 4; 739 payload_offset = 4;
740 N = payload_offset; 740 N = payload_offset;
741 } 741 }
742 sp->packet_seq[pid] = buf[3] & 0x0F; // 巡回カウンタ 742 sp->packet_seq[pid] = buf[3] & 0x0F; // 綏≦潟
743 743
744 Nall = sp->section_remain[pid]; 744 Nall = sp->section_remain[pid];
745 if(Nall > LENGTH_PACKET - payload_offset) 745 if(Nall > LENGTH_PACKET - payload_offset)
746 Nall = LENGTH_PACKET - payload_offset; 746 Nall = LENGTH_PACKET - payload_offset;
747 747
748 // ES PID 748 // ES PID
749 while (N <= Nall + payload_offset - 5) 749 while (N <= Nall + payload_offset - 5)
750 { 750 {
751 // ストリーム種別が 0x0D(type D)は出力対象外 751 // 鴻若腮ャ 0x0D鐚type D鐚阪絲乗院紊
752 if (0x0D != buf[N]) 752 if (0x0D != buf[N])
753 { 753 {
754 epid = GetPid(&buf[N + 1]); 754 epid = GetPid(&buf[N + 1]);
755 755
756 sp->pids[epid] = mark; 756 sp->pids[epid] = mark;
768 else 768 else
769 return TSS_SUCCESS; 769 return TSS_SUCCESS;
770 } 770 }
771 771
772 /** 772 /**
773 * CRC 計算 773 * CRC 荐膊
774 */ 774 */
775 static int GetCrc32( 775 static int GetCrc32(
776 unsigned char* data, // [in] CRC 計算対象データ 776 unsigned char* data, // [in] CRC 荐膊絲乗院若
777 int len) // [in] CRC 計算対象データ長 777 int len) // [in] CRC 荐膊絲乗院若翠
778 { 778 {
779 int crc; 779 int crc;
780 int i, j; 780 int i, j;
781 int c; 781 int c;
782 int bit; 782 int bit;
811 811
812 return crc; 812 return crc;
813 } 813 }
814 814
815 /** 815 /**
816 * PID 取得 816 * PID 緇
817 */ 817 */
818 static int GetPid( 818 static int GetPid(
819 unsigned char* data) // [in] 取得対象データのポインタ 819 unsigned char* data) // [in] 緇絲乗院若帥ゃ潟
820 { 820 {
821 return ((data[0] & 0x1F) << 8) + data[1]; 821 return ((data[0] & 0x1F) << 8) + data[1];
822 } 822 }