Skip to content

Commit

Permalink
fix: #361 read mpeg-ts AF origin PCR extension value
Browse files Browse the repository at this point in the history
  • Loading branch information
ireader committed Nov 16, 2024
1 parent 53254e9 commit 0658496
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
8 changes: 4 additions & 4 deletions libflv/source/flv-muxer.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ static int flv_muxer_h265(struct flv_muxer_t* flv, uint32_t pts, uint32_t dts)
video.keyframe = 1 == flv->vcl ? FLV_VIDEO_KEY_FRAME : FLV_VIDEO_INTER_FRAME;
video.avpacket = FLV_AVPACKET;
n = flv_video_tag_header_write(&video, flv->ptr, flv->capacity);
assert(n == 5 + (flv->enhanced_rtmp && dts == pts) ? 0 : 3);
assert(n == 5 + ((flv->enhanced_rtmp && dts != pts) ? 3 : 0));
return flv->handler(flv->param, FLV_TYPE_VIDEO, flv->ptr, flv->bytes, dts);
}
return 0;
Expand All @@ -402,7 +402,7 @@ int flv_muxer_hevc(struct flv_muxer_t* flv, const void* data, size_t bytes, uint
return -ENOMEM;
}

flv->bytes = 5 + (flv->enhanced_rtmp && dts == pts) ? 0 : 3;
flv->bytes = 5 + ((flv->enhanced_rtmp && dts != pts) ? 3 : 0);
flv->bytes += h265_annexbtomp4(&flv->v.hevc, data, bytes, flv->ptr + flv->bytes, flv->capacity - flv->bytes, &flv->vcl, &flv->update);
if (flv->bytes <= 5)
return -ENOMEM;
Expand Down Expand Up @@ -441,7 +441,7 @@ static int flv_muxer_h266(struct flv_muxer_t* flv, uint32_t pts, uint32_t dts)
video.keyframe = 1 == flv->vcl ? FLV_VIDEO_KEY_FRAME : FLV_VIDEO_INTER_FRAME;
video.avpacket = FLV_AVPACKET;
n = flv_video_tag_header_write(&video, flv->ptr, flv->capacity);
assert(n == 5 + (flv->enhanced_rtmp && dts == pts) ? 0 : 3);
assert(n == 5 + ((flv->enhanced_rtmp && dts != pts) ? 3 : 0));
return flv->handler(flv->param, FLV_TYPE_VIDEO, flv->ptr, flv->bytes, dts);
}
return 0;
Expand All @@ -455,7 +455,7 @@ int flv_muxer_vvc(struct flv_muxer_t* flv, const void* data, size_t bytes, uint3
return -ENOMEM;
}

flv->bytes = 5 + (flv->enhanced_rtmp && dts == pts) ? 0 : 3;
flv->bytes = 5 + ((flv->enhanced_rtmp && dts != pts) ? 3 : 0);
flv->bytes += h266_annexbtomp4(&flv->v.vvc, data, bytes, flv->ptr + flv->bytes, flv->capacity - flv->bytes, &flv->vcl, &flv->update);
if (flv->bytes <= 5)
return -ENOMEM;
Expand Down
3 changes: 2 additions & 1 deletion libmpeg/source/mpeg-system-header.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ int system_header_read(struct ps_system_header_t* h, struct mpeg_bits_t* reader)
}

assert(0 == mpeg_bits_error(reader));
//assert(end == mpeg_bits_tell(reader));
//assert(end >= mpeg_bits_tell(reader));
mpeg_bits_seek(reader, end); // fix: read stream out of range
return MPEG_ERROR_OK;
}

Expand Down
2 changes: 1 addition & 1 deletion libmpeg/source/mpeg-ts-dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static uint32_t adaptation_filed_read(struct ts_adaptation_field_t *adp, const u
if(adp->OPCR_flag && i + 6 <= adp->adaptation_field_length + 1)
{
adp->original_program_clock_reference_base = (((uint64_t)data[i]) << 25) | ((uint64_t)data[i+1] << 17) | ((uint64_t)data[i+2] << 9) | ((uint64_t)data[i+3] << 1) | ((data[i+4] >> 7) & 0x01);
adp->original_program_clock_reference_extension = ((data[i+4] & 0x01) << 1) | data[i+5];
adp->original_program_clock_reference_extension = ((data[i+4] & 0x01) << 8) | data[i+5];

i += 6;
}
Expand Down
20 changes: 10 additions & 10 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,78 +51,78 @@ void usage(int argc, char const *argv[]){
/* 用于套壳调用函数,参数 char* */
#define DEF_FUN_PCHAR(name, ...) void name ( __VA_ARGS__ ); \
int t_##name(int argc, char const *argv[]){\
if(4 != argc) return -1;\
if(4 > argc) return -1;\
name(argv[3]);return 0;\
} \
RE_REGISTER(name, "void " #name "(" #__VA_ARGS__ ")", t_##name)

/* 用于套壳调用函数,参数 char*, char* */
#define DEF_FUN_2PCHAR(name, ...) void name ( __VA_ARGS__ ); \
int t_##name(int argc, char const *argv[]){\
if(5 != argc) return -1;\
if(5 > argc) return -1;\
name(argv[3], argv[4]);return 0;\
} \
RE_REGISTER(name, "void " #name "(" #__VA_ARGS__ ")", t_##name)

#define DEF_FUN_3PCHAR(name, ...) void name ( __VA_ARGS__ ); \
int t_##name(int argc, char const *argv[]){\
if(6 != argc) return -1;\
if(6 > argc) return -1;\
name(argv[3], argv[4], argv[5]);return 0;\
} \
RE_REGISTER(name, "void " #name "(" #__VA_ARGS__ ")", t_##name)

/* 用于套壳调用函数,参数 char*, char*, char*, char* */
#define DEF_FUN_4PCHAR(name, ...) void name ( __VA_ARGS__ ); \
int t_##name(int argc, char const *argv[]){\
if(7 != argc) return -1;\
if(7 > argc) return -1;\
name(argv[3], argv[4], argv[5], argv[6]);return 0;\
} \
RE_REGISTER(name, "void " #name "(" #__VA_ARGS__ ")", t_##name)

/* 用于套壳调用函数,参数 char*, int */
#define DEF_FUN_PCHAR_INT(name, ...) void name ( __VA_ARGS__ ); \
int t_##name(int argc, char const *argv[]){\
if(5 != argc) return -1;\
if(5 > argc) return -1;\
name(argv[3], (int)atoi(argv[4]));return 0;\
} \
RE_REGISTER(name, "void " #name "(" #__VA_ARGS__ ")", t_##name)

/* 用于套壳调用函数,参数 int, int, char*, char* */
#define DEF_FUN_INT_INT_PCHAR_PCHAR(name, ...) void name ( __VA_ARGS__ ); \
int t_##name(int argc, char const *argv[]){\
if(7 != argc) return -1;\
if(7 > argc) return -1;\
name((int)atoi(argv[3]), (int)atoi(argv[4]), argv[5], argv[6]);return 0;\
}\
RE_REGISTER(name, "void " #name "(" #__VA_ARGS__ ")", t_##name)

/* 用于套壳调用函数,参数 char*, int, int, char* */
#define DEF_FUN_PCHAR_INT_INT_PCHAR(name, ...) void name ( __VA_ARGS__ ); \
int t_##name(int argc, char const *argv[]){\
if(7 != argc) return -1;\
if(7 > argc) return -1;\
name(argv[3], (int)atoi(argv[4]), (int)atoi(argv[5]), argv[6]);return 0;\
} \
RE_REGISTER(name, "void " #name "(" # __VA_ARGS__ ")", t_##name)

/* 用于套壳调用函数,参数 char*, int, char* */
#define DEF_FUN_PCHAR_INT_PCHAR(name, ...) void name ( __VA_ARGS__ ); \
int t_##name(int argc, char const *argv[]){\
if(6 != argc) return -1;\
if(6 > argc) return -1;\
name(argv[3], (int)atoi(argv[4]), argv[5]);return 0;\
} \
RE_REGISTER(name, "void " #name "(" # __VA_ARGS__ ")", t_##name)

/* 用于套壳调用函数,参数 char*, int, char*,int, int */
#define DEF_FUN_PCHAR_INT_PCHAR_INT_INT(name, ...) void name ( __VA_ARGS__ ); \
int t_##name(int argc, char const *argv[]){\
if(8 != argc) return -1;\
if(8 > argc) return -1;\
name(argv[3], (int)atoi(argv[4]), argv[5], (int)atoi(argv[6]), (int)atoi(argv[7]));return 0;\
} \
RE_REGISTER(name, "void " #name "(" # __VA_ARGS__ ")", t_##name)

/* 用于套壳调用函数,参数 int, const char*, uint16_t, uint32_t, const char* */
#define DEF_FUN_INT_PCHAR_INT_INT_PCHAR(name, ...) void name ( __VA_ARGS__ ); \
int t_##name(int argc, char const *argv[]){\
if(8 != argc) return -1;\
if(8 > argc) return -1;\
name((int)atoi(argv[3]), argv[4], (uint16_t)atoi(argv[5]), (uint32_t)atoi(argv[6]), argv[7]);return 0;\
} \
RE_REGISTER(name, "void " #name "(" # __VA_ARGS__ ")", t_##name)
Expand Down
3 changes: 3 additions & 0 deletions test/test.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,9 @@
<ClCompile Include="..\libmpeg\test\mov-2-mpeg-ps-test.cpp">
<Filter>libmpeg</Filter>
</ClCompile>
<ClCompile Include="..\librtsp\source\sdp\sdp-h266.c">
<Filter>librtsp\sdp</Filter>
</ClCompile>
<ClCompile Include="..\librtsp\test\media\ps-file-reader.cpp">
<Filter>librtsp\media</Filter>
</ClCompile>
Expand Down

0 comments on commit 0658496

Please sign in to comment.