Mercurial > pt1
comparison recpt1/recpt1.c @ 99:3a3f15b063e1
now recpt1 accepts single sid for terrestrial channels.
technical summary:
- mark pid to record instead of pid to drop
- split after decoding for now
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Fri, 12 Feb 2010 21:40:21 +0900 |
parents | 3fd15032fd3a |
children | aeba1988234f |
comparison
equal
deleted
inserted
replaced
98:3fd15032fd3a | 99:3a3f15b063e1 |
---|---|
299 boolean use_splitter = splitter ? TRUE : FALSE; | 299 boolean use_splitter = splitter ? TRUE : FALSE; |
300 int sfd = -1; | 300 int sfd = -1; |
301 pthread_t signal_thread = data->signal_thread; | 301 pthread_t signal_thread = data->signal_thread; |
302 struct sockaddr_in *addr = NULL; | 302 struct sockaddr_in *addr = NULL; |
303 BUFSZ *qbuf; | 303 BUFSZ *qbuf; |
304 BUFSZ splitbuf; | 304 splitbuf_t splitbuf; |
305 ARIB_STD_B25_BUFFER sbuf, dbuf, buf; | 305 ARIB_STD_B25_BUFFER sbuf, dbuf, buf; |
306 int code; | 306 int code; |
307 int split_select_finish = TSS_ERROR; | 307 int split_select_finish = TSS_ERROR; |
308 | |
309 buf.size = 0; | |
310 buf.data = NULL; | |
311 splitbuf.size = 0; | |
308 | 312 |
309 if(wfd == -1) | 313 if(wfd == -1) |
310 fileless = TRUE; | 314 fileless = TRUE; |
311 | 315 |
312 if(use_udp) { | 316 if(use_udp) { |
326 sbuf.data = qbuf->buffer; | 330 sbuf.data = qbuf->buffer; |
327 sbuf.size = qbuf->size; | 331 sbuf.size = qbuf->size; |
328 | 332 |
329 buf = sbuf; /* default */ | 333 buf = sbuf; /* default */ |
330 | 334 |
331 if ( use_splitter ) | |
332 { | |
333 /* $BJ,N%BP>](BPID$B$NCj=P(B */ | |
334 if ( split_select_finish != TSS_SUCCESS ) | |
335 { | |
336 split_select_finish = split_select(splitter, &sbuf); | |
337 if ( split_select_finish == TSS_NULL ) | |
338 { | |
339 /* malloc$B%(%i!<H/@8(B */ | |
340 use_splitter = FALSE; | |
341 } | |
342 else if ( split_select_finish != TSS_SUCCESS ) | |
343 { | |
344 /* $BJ,N%BP>](BPID$B$,40A4$KCj=P$G$-$k$^$G=PNO$7$J$$(B | |
345 * 1$BICDxEYM>M5$r8+$k$H$$$$$+$b(B | |
346 */ | |
347 free(qbuf); | |
348 qbuf = NULL; | |
349 continue; | |
350 } | |
351 } | |
352 /* $BJ,N%BP>]0J30$r$U$k$$Mn$H$9(B */ | |
353 code = split_ts(splitter, &sbuf, &splitbuf); | |
354 if ( code != TSS_SUCCESS ) | |
355 { | |
356 free(qbuf); | |
357 qbuf = NULL; | |
358 continue; | |
359 } | |
360 /* $BJ,N%7k2L$,%<%m%P%$%H$G$"$k>l9g$K$O(Bb25$B$K2s$5$J$$(B */ | |
361 if ( splitbuf.size == 0 ) | |
362 { | |
363 free(qbuf); | |
364 qbuf = NULL; | |
365 continue; | |
366 } | |
367 sbuf.data = splitbuf.buffer; | |
368 sbuf.size = splitbuf.size; | |
369 buf = sbuf; | |
370 } | |
371 | |
372 if(use_b25) { | 335 if(use_b25) { |
373 code = b25_decode(dec, &sbuf, &dbuf); | 336 code = b25_decode(dec, &sbuf, &dbuf); |
374 if(code < 0) { | 337 if(code < 0) { |
375 fprintf(stderr, "b25_decode failed. fall back to encrypted recording.\n"); | 338 fprintf(stderr, "b25_decode failed. fall back to encrypted recording.\n"); |
376 use_b25 = FALSE; /* local flag */ | 339 use_b25 = FALSE; /* local flag */ |
377 } | 340 } |
378 else | 341 else |
379 buf = dbuf; | 342 buf = dbuf; |
380 } | 343 } |
381 | 344 |
345 | |
346 if(use_splitter) { | |
347 splitbuf.size = 0; | |
348 | |
349 while(buf.size) { | |
350 /* $BJ,N%BP>](BPID$B$NCj=P(B */ | |
351 if(split_select_finish != TSS_SUCCESS) { | |
352 split_select_finish = split_select(splitter, &buf); | |
353 if(split_select_finish == TSS_NULL) { | |
354 /* malloc$B%(%i!<H/@8(B */ | |
355 fprintf(stderr, "split_select malloc failed\n"); | |
356 use_splitter = FALSE; | |
357 goto fin; | |
358 } | |
359 else if(split_select_finish != TSS_SUCCESS) { | |
360 /* $BJ,N%BP>](BPID$B$,40A4$KCj=P$G$-$k$^$G=PNO$7$J$$(B | |
361 * 1$BICDxEYM>M5$r8+$k$H$$$$$+$b(B | |
362 */ | |
363 break; | |
364 } | |
365 } | |
366 /* $BJ,N%BP>]0J30$r$U$k$$Mn$H$9(B */ | |
367 code = split_ts(splitter, &buf, &splitbuf); | |
368 if(code != TSS_SUCCESS) { | |
369 fprintf(stderr, "split_ts failed\n"); | |
370 break; | |
371 } | |
372 | |
373 break; | |
374 } /* while */ | |
375 | |
376 buf.size = splitbuf.size; | |
377 buf.data = splitbuf.buffer; | |
378 fin: | |
379 ; | |
380 } /* if */ | |
381 | |
382 | |
382 if(!fileless) { | 383 if(!fileless) { |
383 /* write data to output file */ | 384 /* write data to output file */ |
384 int size_remain = buf.size; | 385 int size_remain = buf.size; |
385 int offset = 0; | 386 int offset = 0; |
387 | |
386 while(size_remain > 0) { | 388 while(size_remain > 0) { |
387 int ws = size_remain < SIZE_CHANK ? size_remain : SIZE_CHANK; | 389 int ws = size_remain < SIZE_CHANK ? size_remain : SIZE_CHANK; |
390 | |
388 wc = write(wfd, buf.data + offset, ws); | 391 wc = write(wfd, buf.data + offset, ws); |
389 if(wc < 0) { | 392 if(wc < 0) { |
390 perror("write"); | 393 perror("write"); |
391 file_err = 1; | 394 file_err = 1; |
392 pthread_kill(signal_thread, | 395 pthread_kill(signal_thread, |
413 size_remain -= wc; | 416 size_remain -= wc; |
414 offset += wc; | 417 offset += wc; |
415 } | 418 } |
416 } | 419 } |
417 | 420 |
418 if ( qbuf != NULL ) { | 421 free(qbuf); |
419 free(qbuf); | 422 qbuf = NULL; |
420 qbuf = NULL; | |
421 } | |
422 | 423 |
423 /* normal exit */ | 424 /* normal exit */ |
424 if((f_exit && !p_queue->num_used) || file_err) { | 425 if((f_exit && !p_queue->num_used) || file_err) { |
425 | 426 |
426 buf = sbuf; /* default */ | 427 buf = sbuf; /* default */ |
427 | |
428 if ( use_splitter ) | |
429 { | |
430 /* $BJ,N%BP>]0J30$r$U$k$$Mn$H$9(B */ | |
431 code = split_ts(splitter, &sbuf, &splitbuf); | |
432 if ( code != TSS_SUCCESS ) | |
433 { | |
434 break; | |
435 } | |
436 /* $BJ,N%7k2L$,%<%m%P%$%H$G$"$k>l9g$K$O(Bb25$B$K2s$5$J$$(B */ | |
437 if ( splitbuf.size == 0 ) | |
438 { | |
439 break; | |
440 } | |
441 sbuf.data = splitbuf.buffer; | |
442 sbuf.size = splitbuf.size; | |
443 buf = sbuf; | |
444 } | |
445 | 428 |
446 if(use_b25) { | 429 if(use_b25) { |
447 code = b25_finish(dec, &sbuf, &dbuf); | 430 code = b25_finish(dec, &sbuf, &dbuf); |
448 if(code < 0) | 431 if(code < 0) |
449 fprintf(stderr, "b25_finish failed\n"); | 432 fprintf(stderr, "b25_finish failed\n"); |
450 else | 433 else |
451 buf = dbuf; | 434 buf = dbuf; |
435 } | |
436 | |
437 if(use_splitter) { | |
438 /* $BJ,N%BP>]0J30$r$U$k$$Mn$H$9(B */ | |
439 code = split_ts(splitter, &buf, &splitbuf); | |
440 if(code != TSS_SUCCESS) { | |
441 break; | |
442 } | |
443 | |
444 buf.data = splitbuf.buffer; | |
445 buf.size = splitbuf.size; | |
452 } | 446 } |
453 | 447 |
454 if(!fileless && !file_err) { | 448 if(!fileless && !file_err) { |
455 wc = write(wfd, buf.data, buf.size); | 449 wc = write(wfd, buf.data, buf.size); |
456 if(wc < 0) { | 450 if(wc < 0) { |