正在显示
1 个修改的文件
包含
198 行增加
和
0 行删除
@@ -2,6 +2,12 @@ | @@ -2,6 +2,12 @@ | ||
2 | g++ -o ts_info ts_info.cpp -g -O0 -ansi | 2 | g++ -o ts_info ts_info.cpp -g -O0 -ansi |
3 | */ | 3 | */ |
4 | #if 1 | 4 | #if 1 |
5 | +// for int64_t print using PRId64 format. | ||
6 | +#ifndef __STDC_FORMAT_MACROS | ||
7 | + #define __STDC_FORMAT_MACROS | ||
8 | +#endif | ||
9 | +#include <inttypes.h> | ||
10 | + | ||
5 | #include <sys/types.h> | 11 | #include <sys/types.h> |
6 | #include <sys/stat.h> | 12 | #include <sys/stat.h> |
7 | #include <fcntl.h> | 13 | #include <fcntl.h> |
@@ -361,6 +367,45 @@ public: | @@ -361,6 +367,45 @@ public: | ||
361 | int demux(TSContext* ctx, TSPacket* pkt, u_int8_t* start, u_int8_t* last, u_int8_t*& p); | 367 | int demux(TSContext* ctx, TSPacket* pkt, u_int8_t* start, u_int8_t* last, u_int8_t*& p); |
362 | }; | 368 | }; |
363 | 369 | ||
370 | +/** | ||
371 | +* Table 2-18 – Stream_id assignments. page 52. | ||
372 | +*/ | ||
373 | +enum TSPESStreamId | ||
374 | +{ | ||
375 | + PES_program_stream_map = 0b10111100, | ||
376 | + PES_private_stream_1 = 0b10111101, | ||
377 | + PES_padding_stream = 0b10111110, | ||
378 | + PES_private_stream_2 = 0b10111111, | ||
379 | + | ||
380 | + // 110x xxxx | ||
381 | + // ISO/IEC 13818-3 or ISO/IEC 11172-3 or ISO/IEC 13818-7 or ISO/IEC | ||
382 | + // 14496-3 audio stream number x xxxx | ||
383 | + // (stream_id>>5)&0x07 == PES_audio_prefix | ||
384 | + PES_audio_prefix = 0b110, | ||
385 | + | ||
386 | + // 1110 xxxx | ||
387 | + // ITU-T Rec. H.262 | ISO/IEC 13818-2 or ISO/IEC 11172-2 or ISO/IEC | ||
388 | + // 14496-2 video stream number xxxx | ||
389 | + // (stream_id>>5)&0x07 == PES_audio_prefix | ||
390 | + PES_video_prefix = 0b1110, | ||
391 | + | ||
392 | + PES_ECM_stream = 0b11110000, | ||
393 | + PES_EMM_stream = 0b11110001, | ||
394 | + PES_DSMCC_stream = 0b11110010, | ||
395 | + PES_13522_stream = 0b11110011, | ||
396 | + PES_H_222_1_type_A = 0b11110100, | ||
397 | + PES_H_222_1_type_B = 0b11110101, | ||
398 | + PES_H_222_1_type_C = 0b11110110, | ||
399 | + PES_H_222_1_type_D = 0b11110111, | ||
400 | + PES_H_222_1_type_E = 0b11111000, | ||
401 | + PES_ancillary_stream = 0b11111001, | ||
402 | + PES_SL_packetized_stream = 0b11111010, | ||
403 | + PES_FlexMux_stream = 0b11111011, | ||
404 | + // reserved data stream | ||
405 | + // 1111 1100 … 1111 1110 | ||
406 | + PES_program_stream_directory= 0b11111111, | ||
407 | +}; | ||
408 | + | ||
364 | 409 | ||
365 | /** | 410 | /** |
366 | * 2.4.3.7 Semantic definition of fields in PES packet. page 49. | 411 | * 2.4.3.7 Semantic definition of fields in PES packet. page 49. |
@@ -374,6 +419,33 @@ public: | @@ -374,6 +419,33 @@ public: | ||
374 | u_int8_t stream_id; //8bits | 419 | u_int8_t stream_id; //8bits |
375 | // 2B | 420 | // 2B |
376 | u_int16_t PES_packet_length; //16bits | 421 | u_int16_t PES_packet_length; //16bits |
422 | + | ||
423 | + // 1B | ||
424 | + // 2bits const '10' | ||
425 | + int8_t PES_scrambling_control; //2bits | ||
426 | + int8_t PES_priority; //1bit | ||
427 | + int8_t data_alignment_indicator; //1bit | ||
428 | + int8_t copyright; //1bit | ||
429 | + int8_t original_or_copy; //1bit | ||
430 | + | ||
431 | + // 1B | ||
432 | + int8_t PTS_DTS_flags; //2bits | ||
433 | + int8_t ESCR_flag; //1bit | ||
434 | + int8_t ES_rate_flag; //1bit | ||
435 | + int8_t DSM_trick_mode_flag; //1bit | ||
436 | + int8_t additional_copy_info_flag; //1bit | ||
437 | + int8_t PES_CRC_flag; //1bit | ||
438 | + int8_t PES_extension_flag; //1bit | ||
439 | + | ||
440 | + // 1B | ||
441 | + u_int8_t PES_header_data_length; //8bits | ||
442 | + | ||
443 | + /** | ||
444 | + * logic data. | ||
445 | + */ | ||
446 | + // generated by PTS_DTS_flags | ||
447 | + int64_t pts; // 33bits | ||
448 | + int64_t dts; // 33bits | ||
377 | 449 | ||
378 | TSPayloadPES(); | 450 | TSPayloadPES(); |
379 | virtual ~TSPayloadPES(); | 451 | virtual ~TSPayloadPES(); |
@@ -832,6 +904,7 @@ int TSPayloadPMT::demux(TSContext* ctx, TSPacket* pkt, u_int8_t* start, u_int8_t | @@ -832,6 +904,7 @@ int TSPayloadPMT::demux(TSContext* ctx, TSPacket* pkt, u_int8_t* start, u_int8_t | ||
832 | 904 | ||
833 | TSPayloadPES::TSPayloadPES() | 905 | TSPayloadPES::TSPayloadPES() |
834 | { | 906 | { |
907 | + pts = dts = 0; | ||
835 | } | 908 | } |
836 | 909 | ||
837 | TSPayloadPES::~TSPayloadPES() | 910 | TSPayloadPES::~TSPayloadPES() |
@@ -854,6 +927,131 @@ int TSPayloadPES::demux(TSContext* ctx, TSPacket* pkt, u_int8_t* start, u_int8_t | @@ -854,6 +927,131 @@ int TSPayloadPES::demux(TSContext* ctx, TSPacket* pkt, u_int8_t* start, u_int8_t | ||
854 | pp = (char*)&PES_packet_length; | 927 | pp = (char*)&PES_packet_length; |
855 | pp[1] = *p++; | 928 | pp[1] = *p++; |
856 | pp[0] = *p++; | 929 | pp[0] = *p++; |
930 | + | ||
931 | + if (stream_id != PES_program_stream_map | ||
932 | + && stream_id != PES_padding_stream | ||
933 | + && stream_id != PES_private_stream_2 | ||
934 | + && stream_id != PES_ECM_stream | ||
935 | + && stream_id != PES_EMM_stream | ||
936 | + && stream_id != PES_program_stream_directory | ||
937 | + && stream_id != PES_DSMCC_stream | ||
938 | + && stream_id != PES_H_222_1_type_E | ||
939 | + ) { | ||
940 | + original_or_copy = *p++; | ||
941 | + | ||
942 | + //int8_t const2bits = (original_or_copy >> 6) & 0x03; | ||
943 | + PES_scrambling_control = (original_or_copy >> 4) & 0x03; | ||
944 | + PES_priority = (original_or_copy >> 3) & 0x01; | ||
945 | + data_alignment_indicator = (original_or_copy >> 2) & 0x01; | ||
946 | + copyright = (original_or_copy >> 1) & 0x01; | ||
947 | + original_or_copy &= 0x01; | ||
948 | + | ||
949 | + PES_extension_flag = *p++; | ||
950 | + | ||
951 | + PTS_DTS_flags = (PES_extension_flag >> 6) & 0x03; | ||
952 | + ESCR_flag = (PES_extension_flag >> 5) & 0x01; | ||
953 | + ES_rate_flag = (PES_extension_flag >> 4) & 0x01; | ||
954 | + DSM_trick_mode_flag = (PES_extension_flag >> 3) & 0x01; | ||
955 | + additional_copy_info_flag = (PES_extension_flag >> 2) & 0x01; | ||
956 | + PES_CRC_flag = (PES_extension_flag >> 1) & 0x01; | ||
957 | + PES_extension_flag &= 0x01; | ||
958 | + | ||
959 | + PES_header_data_length = *p++; | ||
960 | + | ||
961 | + if (PTS_DTS_flags == 0x2) { | ||
962 | + int64_t temp = 0; | ||
963 | + pp = (char*)&temp; | ||
964 | + pp[4] = *p++; | ||
965 | + pp[3] = *p++; | ||
966 | + pp[2] = *p++; | ||
967 | + pp[1] = *p++; | ||
968 | + pp[0] = *p++; | ||
969 | + | ||
970 | + // marker_bit 1bit | ||
971 | + temp = temp >> 1; | ||
972 | + // PTS [14..0] 15bits | ||
973 | + pts |= temp & 0x3FFF; | ||
974 | + // marker_bit 1bit | ||
975 | + temp = temp >> 1; | ||
976 | + // PTS [29..15] 15bits | ||
977 | + pts |= temp & 0x3fff8000; | ||
978 | + // marker_bit 1bit | ||
979 | + temp = temp >> 1; | ||
980 | + // PTS [32..30] 3bits | ||
981 | + pts |= temp & 0x1c0000000; | ||
982 | + // '0010' 4bits | ||
983 | + //int8_t const4bits = (temp >> 32) & 0x0F; | ||
984 | + } | ||
985 | + | ||
986 | + if (PTS_DTS_flags == 0x3) { | ||
987 | + int64_t temp = 0; | ||
988 | + | ||
989 | + pp = (char*)&temp; | ||
990 | + pp[4] = *p++; | ||
991 | + pp[3] = *p++; | ||
992 | + pp[2] = *p++; | ||
993 | + pp[1] = *p++; | ||
994 | + pp[0] = *p++; | ||
995 | + | ||
996 | + // marker_bit 1bit | ||
997 | + temp = temp >> 1; | ||
998 | + // PTS [14..0] 15bits | ||
999 | + pts |= temp & 0x3FFF; | ||
1000 | + // marker_bit 1bit | ||
1001 | + temp = temp >> 1; | ||
1002 | + // PTS [29..15] 15bits | ||
1003 | + pts |= temp & 0x3fff8000; | ||
1004 | + // marker_bit 1bit | ||
1005 | + temp = temp >> 1; | ||
1006 | + // PTS [32..30] 3bits | ||
1007 | + pts |= temp & 0x1c0000000; | ||
1008 | + // '0010' 4bits | ||
1009 | + //int8_t const4bits = (temp >> 32) & 0x0F; | ||
1010 | + | ||
1011 | + pp = (char*)&temp; | ||
1012 | + pp[4] = *p++; | ||
1013 | + pp[3] = *p++; | ||
1014 | + pp[2] = *p++; | ||
1015 | + pp[1] = *p++; | ||
1016 | + pp[0] = *p++; | ||
1017 | + | ||
1018 | + // marker_bit 1bit | ||
1019 | + temp = temp >> 1; | ||
1020 | + // PTS [14..0] 15bits | ||
1021 | + dts |= temp & 0x3FFF; | ||
1022 | + // marker_bit 1bit | ||
1023 | + temp = temp >> 1; | ||
1024 | + // PTS [29..15] 15bits | ||
1025 | + dts |= temp & 0x3fff8000; | ||
1026 | + // marker_bit 1bit | ||
1027 | + temp = temp >> 1; | ||
1028 | + // PTS [32..30] 3bits | ||
1029 | + dts |= temp & 0x1c0000000; | ||
1030 | + // '0010' 4bits | ||
1031 | + //int8_t const4bits = (temp >> 32) & 0x0F; | ||
1032 | + } | ||
1033 | + | ||
1034 | + if (ESCR_flag) { | ||
1035 | + } | ||
1036 | + } else if (stream_id == PES_program_stream_map | ||
1037 | + || stream_id == PES_private_stream_2 | ||
1038 | + || stream_id == PES_ECM_stream | ||
1039 | + || stream_id == PES_EMM_stream | ||
1040 | + || stream_id == PES_program_stream_directory | ||
1041 | + || stream_id == PES_DSMCC_stream | ||
1042 | + || stream_id == PES_H_222_1_type_E | ||
1043 | + ) { | ||
1044 | + // for (i = 0; i < PES_packet_length; i++) { | ||
1045 | + // PES_packet_data_byte | ||
1046 | + // } | ||
1047 | + } else if (stream_id != PES_padding_stream) { | ||
1048 | + // for (i = 0; i < PES_packet_length; i++) { | ||
1049 | + // padding_byte | ||
1050 | + // } | ||
1051 | + } | ||
1052 | + | ||
1053 | + trace("ts+pes stream_id: %d size: %d pts: %"PRId64" dts: %"PRId64"", | ||
1054 | + stream_id, PES_packet_length, pts, dts); | ||
857 | 1055 | ||
858 | return ret; | 1056 | return ret; |
859 | } | 1057 | } |
-
请 注册 或 登录 后发表评论