Skip to content

Commit

Permalink
fix: PSM update with sid/pid
Browse files Browse the repository at this point in the history
  • Loading branch information
ireader committed Sep 17, 2022
1 parent a47d184 commit 15ecded
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
38 changes: 30 additions & 8 deletions libmpeg/source/mpeg-psm.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,29 @@
#include <assert.h>
#include <string.h>

static struct pes_t* psm_fetch(struct psm_t* psm, uint8_t sid)
{
size_t i;
for (i = 0; i < psm->stream_count; i++)
{
if (psm->streams[i].sid == sid)
return &psm->streams[i];
}

if (psm->stream_count >= sizeof(psm->streams) / sizeof(psm->streams[0]))
{
assert(0);
return NULL;
}

// new stream
return &psm->streams[psm->stream_count++];
}

size_t psm_read(struct psm_t *psm, const uint8_t* data, size_t bytes)
{
size_t i, j, k;
struct pes_t* stream;
//uint8_t current_next_indicator;
uint8_t single_extension_stream_flag;
uint16_t program_stream_map_length;
Expand Down Expand Up @@ -50,18 +70,21 @@ size_t psm_read(struct psm_t *psm, const uint8_t* data, size_t bytes)
element_stream_map_length = program_stream_map_length - program_stream_info_length - 10;

i += 2;
psm->stream_count = 0;
for(j = i; j + 4/*element_stream_info_length*/ <= i+element_stream_map_length && psm->stream_count < sizeof(psm->streams)/sizeof(psm->streams[0]); j += 4 + element_stream_info_length)
{
psm->streams[psm->stream_count].codecid = data[j];
psm->streams[psm->stream_count].sid = data[j+1];
psm->streams[psm->stream_count].pid = psm->streams[psm->stream_count].sid; // for ts PID
element_stream_info_length = (data[j+2] << 8) | data[j+3];
if (j + 4 + element_stream_info_length > i+element_stream_map_length)
element_stream_info_length = (data[j + 2] << 8) | data[j + 3];
if (j + 4 + element_stream_info_length > i + element_stream_map_length)
return 0; // TODO: error

stream = psm_fetch(psm, data[j + 1]); // sid
if (NULL == stream)
continue;
stream->codecid = data[j];
stream->sid = data[j+1];
stream->pid = stream->sid; // for ts PID

k = j + 4;
if(0xFD == psm->streams[psm->stream_count].sid && 0 == single_extension_stream_flag)
if(0xFD == stream->sid && 0 == single_extension_stream_flag)
{
if(element_stream_info_length < 3)
return 0; // TODO: error
Expand All @@ -78,7 +101,6 @@ size_t psm_read(struct psm_t *psm, const uint8_t* data, size_t bytes)
k += mpeg_elment_descriptor(data+k, j + 4 + element_stream_info_length - k);
}

++psm->stream_count;
assert(k - j - 4 == element_stream_info_length);
}

Expand Down
8 changes: 4 additions & 4 deletions libmpeg/test/mpeg-ps-dec-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ static int onpacket(void* /*param*/, int /*stream*/, int avtype, int flags, int6
{
static char s_pts[64], s_dts[64];

if (PSI_STREAM_AAC == avtype)
if (PSI_STREAM_AAC == avtype || PSI_STREAM_AUDIO_G711A == avtype || PSI_STREAM_AUDIO_G711U == avtype)
{
static int64_t a_pts = 0, a_dts = 0;
if (PTS_NO_VALUE == dts)
dts = pts;
//assert(0 == a_dts || dts >= a_dts);
printf("[A] pts: %s(%lld), dts: %s(%lld), diff: %03d/%03d\n", ftimestamp(pts, s_pts), pts, ftimestamp(dts, s_dts), dts, (int)(pts - a_pts) / 90, (int)(dts - a_dts) / 90);
printf("[A] pts: %s(%lld), dts: %s(%lld), diff: %03d/%03d, size: %u\n", ftimestamp(pts, s_pts), pts, ftimestamp(dts, s_dts), dts, (int)(pts - a_pts) / 90, (int)(dts - a_dts) / 90, (unsigned int)bytes);
a_pts = pts;
a_dts = dts;

Expand All @@ -42,7 +42,7 @@ static int onpacket(void* /*param*/, int /*stream*/, int avtype, int flags, int6
{
static int64_t v_pts = 0, v_dts = 0;
assert(0 == v_dts || dts >= v_dts);
printf("[V] pts: %s(%lld), dts: %s(%lld), diff: %03d/%03d, size: %u\n", ftimestamp(pts, s_pts), pts, ftimestamp(dts, s_dts), dts, (int)(pts - v_pts) / 90, (int)(dts - v_dts) / 90, bytes);
printf("[V] pts: %s(%lld), dts: %s(%lld), diff: %03d/%03d, size: %u\n", ftimestamp(pts, s_pts), pts, ftimestamp(dts, s_dts), dts, (int)(pts - v_pts) / 90, (int)(dts - v_dts) / 90, (unsigned int)bytes);
v_pts = pts;
v_dts = dts;

Expand All @@ -56,7 +56,7 @@ static int onpacket(void* /*param*/, int /*stream*/, int avtype, int flags, int6
if (PTS_NO_VALUE == dts)
dts = pts;
//assert(0 == x_dts || dts >= x_dts);
//printf("[X] pts: %s(%lld), dts: %s(%lld), diff: %03d/%03d\n", ftimestamp(pts, s_pts), pts, ftimestamp(dts, s_dts), dts, (int)(pts - x_pts), (int)(dts - x_dts));
printf("[X] pts: %s(%lld), dts: %s(%lld), diff: %03d/%03d\n", ftimestamp(pts, s_pts), pts, ftimestamp(dts, s_dts), dts, (int)(pts - x_pts), (int)(dts - x_dts));
x_pts = pts;
x_dts = dts;
}
Expand Down
4 changes: 2 additions & 2 deletions librtsp/source/sdp/sdp-av1.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ int sdp_av1(uint8_t *data, int bytes, const char* proto, unsigned short port, in
*/
static const char* pattern =
"m=video %hu %s %d\n"
//"a=rtpmap:%d AV1/90000\n"
"a=rtpmap:%d AV1X/90000\n" // https://bugs.chromium.org/p/webrtc/issues/detail?id=11042
"a=rtpmap:%d AV1/90000\n"
//"a=rtpmap:%d AV1X/90000\n" // https://bugs.chromium.org/p/webrtc/issues/detail?id=11042
"a=fmtp:%d profile=%u;level-idx=%u;tier=%u";

int r, n;
Expand Down

0 comments on commit 15ecded

Please sign in to comment.