Skip to content

Commit

Permalink
fix: mpeg-ps rewind at start code
Browse files Browse the repository at this point in the history
  • Loading branch information
ireader committed Nov 12, 2023
1 parent fa275d5 commit f32776e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
2 changes: 2 additions & 0 deletions libflv/include/mpeg4-avc.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ struct mpeg4_avc_t
};

// load avc from AVCDecoderConfigurationRecord
/// @return <=0-error, >0-output bytes
int mpeg4_avc_decoder_configuration_record_load(const uint8_t* data, size_t bytes, struct mpeg4_avc_t* avc);

/// @return <=0-error, >0-output bytes
int mpeg4_avc_decoder_configuration_record_save(const struct mpeg4_avc_t* avc, uint8_t* data, size_t bytes);

// load avc from annex-b bitstream
Expand Down
4 changes: 2 additions & 2 deletions libmpeg/source/mpeg-packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ static int mpeg_packet_h26x(struct packet_t* pkt, const struct pes_t* pes, size_
// video data contain 00 00 01 BA
// maybe previous packet data lost
r = (p + n - pkt->data) - (pkt->size - *consume);
assert(r > 0 && r <= *consume);
*consume = (r <= 0 || r > *consume) ? *consume : r;
assert(r >= 0 && r <= *consume); // r == 0: previous packet lost, new start code find
*consume = (r < 0 || r > *consume) ? *consume : r;
pkt->flags |= MPEG_FLAG_PACKET_CORRUPT;
pkt->size = 0; // clear
pkt->vcl = 0;
Expand Down
18 changes: 11 additions & 7 deletions librtp/test/rtp-dump-test.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#define RTP_DEMUXER 0

#if RTP_DEMUXER
#include "rtp-dump.h"
#if RTP_DEMUXER
#include "rtp-demuxer.h"
#else
#include "rtsp-demuxer.h"
Expand All @@ -10,10 +10,11 @@
#include <stdio.h>
#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>



struct rtp_dump_test_t
{
#if RTP_DEMUXER
Expand Down Expand Up @@ -41,11 +42,14 @@ static int rtsp_onpacket(void* param, struct avpacket_t* pkt)
int r;
struct rtp_dump_test_t* ctx = (struct rtp_dump_test_t*)param;

static int64_t s_dts = 0;
if (0 == s_dts)
s_dts = pkt->dts;
printf("[%d:0x%x] pts: %" PRId64 ", dts: %" PRId64 ", cts: %" PRId64 ", diff: %" PRId64 ", bytes: %d\n", pkt->stream->stream, (unsigned int)pkt->stream->codecid, pkt->pts, pkt->dts, pkt->pts - pkt->dts, pkt->dts - s_dts, pkt->size);
s_dts = pkt->dts;
static int64_t s_dts[8] = { 0 };
if (0 == s_dts[pkt->stream->stream])
s_dts[pkt->stream->stream] = pkt->dts;
printf("[%d:0x%x] pts: %" PRId64 ", dts: %" PRId64 ", cts: %" PRId64 ", diff: %" PRId64 ", bytes: %d\n", pkt->stream->stream, (unsigned int)pkt->stream->codecid, pkt->pts, pkt->dts, pkt->pts - pkt->dts, pkt->dts - s_dts[pkt->stream->stream], pkt->size);
s_dts[pkt->stream->stream] = pkt->dts;

if (avstream_type(pkt->stream) != AVSTREAM_VIDEO)
return 0;

r = avpkt2bs_input(&ctx->bs, pkt);
fwrite(ctx->bs.ptr, 1, r, ctx->fp);
Expand Down
2 changes: 1 addition & 1 deletion test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ else
LIBPATHS +=
endif

LIBS = rt pthread dl aio ssl crypt
LIBS = rt pthread dl aio #ssl crypt

STATIC_LIBS = ../libdash/$(BUILD).$(PLATFORM)/libdash.a \
../libflv/$(BUILD).$(PLATFORM)/libflv.a \
Expand Down
8 changes: 8 additions & 0 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ extern "C" DEF_FUN_VOID(mpeg4_aac_test);
extern "C" DEF_FUN_VOID(mpeg4_avc_test);
extern "C" DEF_FUN_VOID(mpeg4_hevc_test);
extern "C" DEF_FUN_VOID(mpeg4_vvc_test);
extern "C" DEF_FUN_VOID(avswg_avs3_test);
extern "C" DEF_FUN_VOID(mp3_header_test);
extern "C" DEF_FUN_VOID(h264_mp4toannexb_test);
extern "C" DEF_FUN_VOID(sdp_a_fmtp_test);
Expand Down Expand Up @@ -181,6 +182,12 @@ DEF_FUN_PCHAR_INT_PCHAR(mov_writer_audio, const char* audio, int type, const cha
DEF_FUN_2PCHAR(fmp4_writer_test2, const char* mp4, const char* outmp4);
DEF_FUN_PCHAR(mov_rtp_test, const char* mp4);

DEF_FUN_PCHAR(mkv_reader_test, const char* mkv);
DEF_FUN_INT_INT_PCHAR_PCHAR(mkv_writer_test, int w, int h, const char* inflv, const char* outmkv);
DEF_FUN_2PCHAR(mkv_writer_test2, const char* mkv, const char* newmkv);
DEF_FUN_2PCHAR(mkv_2_mp4_test, const char* mkv, const char* mp4);
DEF_FUN_PCHAR_INT_PCHAR(mkv_writer_audio, const char* audio, int type, const char* mkv);

DEF_FUN_PCHAR(mpeg_ts_dec_test, const char* file);
DEF_FUN_PCHAR(mpeg_ts_test, const char* input);
DEF_FUN_PCHAR(mpeg_ps_test, const char* input);
Expand Down Expand Up @@ -239,6 +246,7 @@ int main(int argc, const char* argv[])
RE_RUN_REG("mpeg4_avc_test", argc, argv);
RE_RUN_REG("mpeg4_hevc_test", argc, argv);
RE_RUN_REG("mpeg4_vvc_test", argc, argv);
RE_RUN_REG("avswg_avs3_test", argc, argv);
RE_RUN_REG("mp3_header_test", argc, argv);
RE_RUN_REG("h264_mp4toannexb_test", argc, argv);
RE_RUN_REG("sdp_a_fmtp_test", argc, argv);
Expand Down
2 changes: 1 addition & 1 deletion test/test.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;OS_WINDOWS;_HAVE_FFMPEG_1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;OS_WINDOWS;__ERROR__=(00 * 10000000 + __LINE__ * 1000);_HAVE_FFMPEG_1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>../librtmp/include;../libflv/include;../libmov/include;../librtsp/include;../librtp/include;../libmpeg/include;../libhls/include;../libdash/include;../libsip/include;../libmkv/include;../librtmp/aio;../../sdk/include;../../sdk/libaio/include;../../sdk/libhttp/include;../../sdk/libice/include;../../3rd/ffmpeg/include;../../3rd/openssl/include;../../avcodec/avbsf/include;../../avcodec/avcodec/include</AdditionalIncludeDirectories>
</ClCompile>
Expand Down

0 comments on commit f32776e

Please sign in to comment.