Mercurial > pt1.oyama
comparison src/tssplitter_lite.c @ 181:863ac6807ee3
Changed to stdout stderr from the log output.
author | Naoya OYAMA <naoya.oyama@gmail.com> |
---|---|
date | Mon, 24 Feb 2014 23:51:52 +0900 |
parents | 4f3640bf350d |
children | 27e5f99f8991 |
comparison
equal
deleted
inserted
replaced
180:2659ebefb192 | 181:863ac6807ee3 |
---|---|
192 i++; | 192 i++; |
193 } | 193 } |
194 #if 0 | 194 #if 0 |
195 for(i=0; sid_list[i] != NULL; i++) | 195 for(i=0; sid_list[i] != NULL; i++) |
196 { | 196 { |
197 printf("sid_list[%d]=[%s].\n",i, sid_list[i]); | 197 printf(stderr, "sid_list[%d]=[%s].\n",i, sid_list[i]); |
198 } | 198 } |
199 #endif | 199 #endif |
200 return sid_list; | 200 return sid_list; |
201 } | 201 } |
202 | 202 |
492 /* こっから */ | 492 /* こっから */ |
493 if ( ret == 0 ) { /* PCR の解析に成功 */ | 493 if ( ret == 0 ) { /* PCR の解析に成功 */ |
494 program->stc = pcr_h * 300 + pcr_l; /* PCR受信時にSTCを補正*/ | 494 program->stc = pcr_h * 300 + pcr_l; /* PCR受信時にSTCを補正*/ |
495 if ( program->pcr1 == 0 ) { | 495 if ( program->pcr1 == 0 ) { |
496 program->pcr1 = program->stc; | 496 program->pcr1 = program->stc; |
497 printf("pcr1 pid[%d] sid[%d] packet_nb[%d] sid_nb[%d] i[%d]\n", | 497 fprintf(stderr, "pcr1 pid[%d] sid[%d] packet_nb[%d] sid_nb[%d] i[%d]\n", |
498 pid, sid, packet_nb, sp->pcr[pcr_index].sid_nb, i); | 498 pid, sid, packet_nb, sp->pcr[pcr_index].sid_nb, i); |
499 } else if ( program->pcr2 == 0 ) { | 499 } else if ( program->pcr2 == 0 ) { |
500 // printf("pcr2 pid[%d] sid[%d] packet_nb[%d], p_packet_nb[%d] sid_nb[%d] i[%d]\n", | 500 // fprintf(stderr, "pcr2 pid[%d] sid[%d] packet_nb[%d], p_packet_nb[%d] sid_nb[%d] i[%d]\n", |
501 // pid, sid, packet_nb, program->pcr_packet_nb, sp->pcr[pcr_index].sid_nb, i); | 501 // pid, sid, packet_nb, program->pcr_packet_nb, sp->pcr[pcr_index].sid_nb, i); |
502 program->pcr2 = program->stc; | 502 program->pcr2 = program->stc; |
503 program->pcr_incr = (program->pcr2 -program->pcr1) | 503 program->pcr_incr = (program->pcr2 -program->pcr1) |
504 /(packet_nb -program->pcr_packet_nb); | 504 /(packet_nb -program->pcr_packet_nb); |
505 printf("pcr2 pid[%d] sid[%d] pcr_incr[%llu]\n", | 505 fprintf(stderr, "pcr2 pid[%d] sid[%d] pcr_incr[%llu]\n", |
506 pid, sid, program->pcr_incr); | 506 pid, sid, program->pcr_incr); |
507 } else { | 507 } else { |
508 /* PCR処理済み */ | 508 /* PCR処理済み */ |
509 ; /* 得に処理無し */ | 509 ; /* 得に処理無し */ |
510 } | 510 } |
519 */ | 519 */ |
520 program->cue = program->stc | 520 program->cue = program->stc |
521 +(sp->time_cue -sp->time_tot)*27e6 | 521 +(sp->time_cue -sp->time_tot)*27e6 |
522 +(packet_nb -sp->tot_packet_nb)*program->pcr_incr | 522 +(packet_nb -sp->tot_packet_nb)*program->pcr_incr |
523 -(27e6*49/100); | 523 -(27e6*49/100); |
524 printf("STC[%llu] CUE[%llu] SID[%d]\n", | 524 fprintf(stderr, "STC[%llu] CUE[%llu] SID[%d]\n", |
525 program->stc, program->cue, sid); | 525 program->stc, program->cue, sid); |
526 } | 526 } |
527 program->pcr_packet_nb = packet_nb; | 527 program->pcr_packet_nb = packet_nb; |
528 program->packet_nb = packet_nb; | 528 program->packet_nb = packet_nb; |
529 } else if ( program->pcr_incr ) { /* PCRの解析に失敗且つpcr_incr変数の計算済み*/ | 529 } else if ( program->pcr_incr ) { /* PCRの解析に失敗且つpcr_incr変数の計算済み*/ |
546 } | 546 } |
547 #if 0 | 547 #if 0 |
548 // NHK Gを ALL とすると SID 1024 しか出ない...orz.. | 548 // NHK Gを ALL とすると SID 1024 しか出ない...orz.. |
549 if ( !(packet_nb % 1000) ) { | 549 if ( !(packet_nb % 1000) ) { |
550 program = &(sp->program[sid]); | 550 program = &(sp->program[sid]); |
551 printf("STC[%llu] SID[%d]\n", program->stc, sid); | 551 fprintf("STC[%llu] SID[%d]\n", program->stc, sid); |
552 } | 552 } |
553 #endif | 553 #endif |
554 /* TS処理 */ | 554 /* TS処理 */ |
555 DemuxTs((sptr+s_offset), sp, pid); | 555 DemuxTs((sptr+s_offset), sp, pid); |
556 memcpy(dptr + d_offset, sptr + s_offset, LENGTH_PACKET); | 556 memcpy(dptr + d_offset, sptr + s_offset, LENGTH_PACKET); |
962 cat_pid = (AV_RB16(buf+p+2)) & 0x1fff; | 962 cat_pid = (AV_RB16(buf+p+2)) & 0x1fff; |
963 sp->pids[cat_pid] = 1; | 963 sp->pids[cat_pid] = 1; |
964 sp->cat_pids[cat_pid] = 1; | 964 sp->cat_pids[cat_pid] = 1; |
965 sp->pid_sid_table[cat_pid] = sid; /* CATも複数ServiceIDで重複がある */ | 965 sp->pid_sid_table[cat_pid] = sid; /* CATも複数ServiceIDで重複がある */ |
966 #ifdef PmtDebug | 966 #ifdef PmtDebug |
967 printf(" CAT PacketID[%d][0x%04x]\n", cat_pid, cat_pid); | 967 fprintf(stderr, " CAT PacketID[%d][0x%04x]\n", cat_pid, cat_pid); |
968 #endif | 968 #endif |
969 } | 969 } |
970 p += len; | 970 p += len; |
971 } | 971 } |
972 | 972 |
1010 if ( buf[N] == 0x02 ) { /* 13818-2 Video */ | 1010 if ( buf[N] == 0x02 ) { /* 13818-2 Video */ |
1011 sp->program[sid].video[sp->program[sid].video_nb] = epid; | 1011 sp->program[sid].video[sp->program[sid].video_nb] = epid; |
1012 sp->program[sid].video_nb += 1; | 1012 sp->program[sid].video_nb += 1; |
1013 av_flag = TSS_STREAM_TYPE_VIDEO; | 1013 av_flag = TSS_STREAM_TYPE_VIDEO; |
1014 #ifdef PmtDebug | 1014 #ifdef PmtDebug |
1015 printf(" VIDEO PacketID[%d][0x%04x] StreamType[0x%02x]\n", epid, epid, buf[N]); | 1015 fprintf(stderr, " VIDEO PacketID[%d][0x%04x] StreamType[0x%02x]\n", epid, epid, buf[N]); |
1016 #endif | 1016 #endif |
1017 } else if ( (buf[N] == 0x04) || (buf[N] == 0x0f) ) { | 1017 } else if ( (buf[N] == 0x04) || (buf[N] == 0x0f) ) { |
1018 /* 13818-3 Audio or 13818-7 Audio with ADTS transport syntax */ | 1018 /* 13818-3 Audio or 13818-7 Audio with ADTS transport syntax */ |
1019 sp->program[sid].audio[sp->program[sid].audio_nb] = epid; | 1019 sp->program[sid].audio[sp->program[sid].audio_nb] = epid; |
1020 sp->program[sid].audio_nb += 1; | 1020 sp->program[sid].audio_nb += 1; |
1021 av_flag = TSS_STREAM_TYPE_AUDIO; | 1021 av_flag = TSS_STREAM_TYPE_AUDIO; |
1022 #ifdef PmtDebug | 1022 #ifdef PmtDebug |
1023 printf(" AUDIO PacketID[%d][0x%04x] StreamType[0x%02x]\n", epid, epid, buf[N]); | 1023 fprintf(stderr, " AUDIO PacketID[%d][0x%04x] StreamType[0x%02x]\n", epid, epid, buf[N]); |
1024 #endif | 1024 #endif |
1025 } else { | 1025 } else { |
1026 #ifdef PmtDebug | 1026 #ifdef PmtDebug |
1027 printf(" OTHER PacketID[%d][0x%04x] StreamType[0x%02x]\n", epid, epid, buf[N]); | 1027 fprintf (stderr, " OTHER PacketID[%d][0x%04x] StreamType[0x%02x]\n", epid, epid, buf[N]); |
1028 #endif | 1028 #endif |
1029 ; /* A/V どちらでもないものはとりあえずスルー */ | 1029 ; /* A/V どちらでもないものはとりあえずスルー */ |
1030 } | 1030 } |
1031 if ( av_flag && sp->esout ) { | 1031 if ( av_flag && sp->esout ) { |
1032 /* ESバッファはNULLか? */ | 1032 /* ESバッファはNULLか? */ |
1492 } | 1492 } |
1493 if ( flags & ES_RATE_FLAG ) { | 1493 if ( flags & ES_RATE_FLAG ) { |
1494 es_rate = AV_RB24(p); | 1494 es_rate = AV_RB24(p); |
1495 es_rate = (es_rate >>1) & 0x3fffff; | 1495 es_rate = (es_rate >>1) & 0x3fffff; |
1496 es_rate = es_rate * 50; | 1496 es_rate = es_rate * 50; |
1497 printf("pid[%d] es_rate[%d]Byte/Sec.\n", pid, es_rate); | 1497 fprintf(stderr, "pid[%d] es_rate[%d]Byte/Sec.\n", pid, es_rate); |
1498 p += 3; | 1498 p += 3; |
1499 len_pesh_supposed += 3; | 1499 len_pesh_supposed += 3; |
1500 } | 1500 } |
1501 if ( flags & DSM_TRICK_MODE_FLAG ) { | 1501 if ( flags & DSM_TRICK_MODE_FLAG ) { |
1502 p += 1; | 1502 p += 1; |
1597 (esbuf->Program->cue <= esbuf->pts*300) ) { /* CUEを過ぎている? */ | 1597 (esbuf->Program->cue <= esbuf->pts*300) ) { /* CUEを過ぎている? */ |
1598 /* 該当ストリームをファイル出力開始する */ | 1598 /* 該当ストリームをファイル出力開始する */ |
1599 esbuf->started = 1; | 1599 esbuf->started = 1; |
1600 esbuf->Program->video_start = 1; | 1600 esbuf->Program->video_start = 1; |
1601 esbuf->Program->video_pts = esbuf->pts; | 1601 esbuf->Program->video_pts = esbuf->pts; |
1602 printf("video stream. pid[%d] v_pts[%llu].\n", pid, esbuf->pts); | 1602 fprintf(stderr, "video stream. pid[%d] v_pts[%llu].\n", pid, esbuf->pts); |
1603 } else { | 1603 } else { |
1604 /* GOP先頭を含まないものはクリア */ | 1604 /* GOP先頭を含まないものはクリア */ |
1605 esbuf_clear(esbuf, pesbuf->pts, pesbuf->dts); | 1605 esbuf_clear(esbuf, pesbuf->pts, pesbuf->dts); |
1606 } | 1606 } |
1607 } else if ( (is_video_stream(pid, esbuf) != -1) && !(esbuf->started) ) { | 1607 } else if ( (is_video_stream(pid, esbuf) != -1) && !(esbuf->started) ) { |
1639 if ( esbuf->size + payload_length > sizeof esbuf->buffer ){ | 1639 if ( esbuf->size + payload_length > sizeof esbuf->buffer ){ |
1640 /* 溢れそうになったらクリア */ | 1640 /* 溢れそうになったらクリア */ |
1641 esbuf_clear(esbuf, pesbuf->pts, pesbuf->dts); | 1641 esbuf_clear(esbuf, pesbuf->pts, pesbuf->dts); |
1642 } | 1642 } |
1643 } else if ( esbuf->Program->video_start ) { /* video 蓄積が開始されている?*/ | 1643 } else if ( esbuf->Program->video_start ) { /* video 蓄積が開始されている?*/ |
1644 printf("audio stream. pid[%d] a_pts[%llu] v_pts[%llu] size[%d].\n", pid, esbuf->pts, esbuf->Program->video_pts, esbuf->size); | 1644 fprintf(stderr, "audio stream. pid[%d] a_pts[%llu] v_pts[%llu] size[%d].\n", pid, esbuf->pts, esbuf->Program->video_pts, esbuf->size); |
1645 audio_lipsync_offset = 0; | 1645 audio_lipsync_offset = 0; |
1646 audio_pts = esbuf->pts; | 1646 audio_pts = esbuf->pts; |
1647 adts_freq = AnalyzeAdifHeader(esbuf); | 1647 adts_freq = AnalyzeAdifHeader(esbuf); |
1648 adts_frame_time = (int64_t)((float)1024*90000/adts_freq); /* PTSは90KHz */ | 1648 adts_frame_time = (int64_t)((float)1024*90000/adts_freq); /* PTSは90KHz */ |
1649 /* オーディオをフレーム単位で捨ててPTSを進める */ | 1649 /* オーディオをフレーム単位で捨ててPTSを進める */ |
1655 } else { | 1655 } else { |
1656 /* バッファ終端まで進めたが、オーディオPTSの方が古い場合ESバッファはクリアする */ | 1656 /* バッファ終端まで進めたが、オーディオPTSの方が古い場合ESバッファはクリアする */ |
1657 esbuf_clear(esbuf, pesbuf->pts, pesbuf->dts); | 1657 esbuf_clear(esbuf, pesbuf->pts, pesbuf->dts); |
1658 break; | 1658 break; |
1659 } | 1659 } |
1660 printf("audio stream drop. pid[%d] pts[%llu].\n", pid, audio_pts); | 1660 fprintf(stderr, "audio stream drop. pid[%d] pts[%llu].\n", pid, audio_pts); |
1661 audio_pts += adts_frame_time; /* AACの1フレーム分、時間を進める */ | 1661 audio_pts += adts_frame_time; /* AACの1フレーム分、時間を進める */ |
1662 } | 1662 } |
1663 if ( (esbuf->Program->video_pts <= audio_pts +adts_frame_time/2) ) { | 1663 if ( (esbuf->Program->video_pts <= audio_pts +adts_frame_time/2) ) { |
1664 printf("lipsync start. v_pts[%llu] a_pts[%llu].\n", esbuf->Program->video_pts, audio_pts); | 1664 fprintf(stderr, "lipsync start. v_pts[%llu] a_pts[%llu].\n", esbuf->Program->video_pts, audio_pts); |
1665 memmove(esbuf->buffer +audio_lipsync_offset, | 1665 memmove(esbuf->buffer +audio_lipsync_offset, |
1666 esbuf->buffer, | 1666 esbuf->buffer, |
1667 esbuf->size -audio_lipsync_offset); | 1667 esbuf->size -audio_lipsync_offset); |
1668 esbuf->size -= audio_lipsync_offset; | 1668 esbuf->size -= audio_lipsync_offset; |
1669 esbuf->started = 1; /* オーディオのファイル出力を有効化 */ | 1669 esbuf->started = 1; /* オーディオのファイル出力を有効化 */ |
1794 | 1794 |
1795 p += 8; | 1795 p += 8; |
1796 MJD = (*(p) & 0xff) <<8; | 1796 MJD = (*(p) & 0xff) <<8; |
1797 p++; | 1797 p++; |
1798 MJD |= *(p) & 0xff; | 1798 MJD |= *(p) & 0xff; |
1799 printf("MJD[%x].\n", MJD); | |
1800 | 1799 |
1801 /* ARIB STD-B10 第2部 付録C の公式より MJD to YYYYMMDD */ | 1800 /* ARIB STD-B10 第2部 付録C の公式より MJD to YYYYMMDD */ |
1802 tm.tm_year = (int)floor((MJD - 15078.2)/365.25); | 1801 tm.tm_year = (int)floor((MJD - 15078.2)/365.25); |
1803 tm.tm_mon = (int)floor((MJD - 14956.1 - floor(tm.tm_year * 365.25))/30.6001); | 1802 tm.tm_mon = (int)floor((MJD - 14956.1 - floor(tm.tm_year * 365.25))/30.6001); |
1804 tm.tm_mday = MJD - 14956 - floor(tm.tm_year * 365.25) - floor(tm.tm_mon * 30.6001); | 1803 tm.tm_mday = MJD - 14956 - floor(tm.tm_year * 365.25) - floor(tm.tm_mon * 30.6001); |
1818 p++; | 1817 p++; |
1819 tm.tm_sec = ((*p & 0xf0) >>4)*10 + (*p & 0x0f); | 1818 tm.tm_sec = ((*p & 0xf0) >>4)*10 + (*p & 0x0f); |
1820 | 1819 |
1821 *t = mktime(&tm); | 1820 *t = mktime(&tm); |
1822 time(&t2); | 1821 time(&t2); |
1823 // printf("time[%d] TOT[%d].\n", t2, *t); | |
1824 | 1822 |
1825 return TRUE; | 1823 return TRUE; |
1826 } | 1824 } |
1827 | 1825 |
1828 static int64_t get_pts(const uint8_t *p) | 1826 static int64_t get_pts(const uint8_t *p) |
1873 return -1; | 1871 return -1; |
1874 } | 1872 } |
1875 for(; i < esbuf->size - sizeof(adts_start_code); i++) { | 1873 for(; i < esbuf->size - sizeof(adts_start_code); i++) { |
1876 startcode = AV_RB16(esbuf->buffer+i); | 1874 startcode = AV_RB16(esbuf->buffer+i); |
1877 if( startcode == adts_start_code ) { /* 該当位置から12bit連続1が立っているか? */ | 1875 if( startcode == adts_start_code ) { /* 該当位置から12bit連続1が立っているか? */ |
1878 #if 0 | |
1879 printf("adts start code found.i[%d]. 0[%02x] 1[%02x] 2[%02x] 3[%02x] 4[%02x] 5[%02x] 6[%02x]\n", | |
1880 i, *(esbuf->buffer+i+0), *(esbuf->buffer+i+1), *(esbuf->buffer+i+2), *(esbuf->buffer+i+3), *(esbuf->buffer+i+4), *(esbuf->buffer+i+5), *(esbuf->buffer+i+6) ); | |
1881 #endif | |
1882 return (i-offset); | 1876 return (i-offset); |
1883 } | 1877 } |
1884 } | 1878 } |
1885 return -1; | 1879 return -1; |
1886 } | 1880 } |