mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
refine the type of RTMP from int to char. add srs_parse_timestamp(), 2.0.19
This commit is contained in:
parent
9b2da59eeb
commit
7ebca6cb5b
10 changed files with 180 additions and 55 deletions
|
@ -35,9 +35,10 @@ int main(int argc, char** argv)
|
|||
srs_rtmp_t rtmp;
|
||||
|
||||
// packet data
|
||||
int type, size;
|
||||
u_int32_t timestamp = 0;
|
||||
int size;
|
||||
char type;
|
||||
char* data;
|
||||
u_int32_t timestamp;
|
||||
|
||||
// srs debug info.
|
||||
char srs_server_ip[128];
|
||||
|
|
|
@ -49,10 +49,11 @@ int main(int argc, char** argv)
|
|||
int64_t bytes_nrecv = 0;
|
||||
|
||||
// packet data
|
||||
int type, size;
|
||||
u_int32_t basetime = 0;
|
||||
u_int32_t timestamp = 0;
|
||||
int size;
|
||||
char type;
|
||||
char* data;
|
||||
u_int32_t timestamp;
|
||||
u_int32_t basetime = 0;
|
||||
|
||||
// user options
|
||||
const char* rtmp_url = NULL;
|
||||
|
|
|
@ -125,7 +125,7 @@ int parse_bytes(char* data, int size, char* hbuf, int hsize, char* tbuf, int tsi
|
|||
}
|
||||
|
||||
#define FLV_HEADER_SIZE 11
|
||||
int parse_script_data(u_int32_t timestamp, char* data, int size, int64_t offset)
|
||||
int parse_script_data(u_int32_t timestamp, u_int32_t pts, char* data, int size, int64_t offset)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
|
@ -152,10 +152,10 @@ int parse_script_data(u_int32_t timestamp, char* data, int size, int64_t offset)
|
|||
}
|
||||
amf0_data = srs_amf0_parse(data + nparsed, size - nparsed, &nparsed);
|
||||
|
||||
srs_lib_trace("packet type=%s, time=%d, size=%d, data-size=%d, \n"
|
||||
srs_lib_trace("packet type=%s, dts=%d, pts=%d, size=%d, data-size=%d, \n"
|
||||
"offset=%d\n[+00, +15] %s\n[-15, EOF] %s\n%s%s",
|
||||
srs_type2string(SRS_RTMP_TYPE_SCRIPT), timestamp, size + FLV_HEADER_SIZE, size,
|
||||
(int)offset, hbuf, tbuf,
|
||||
srs_type2string(SRS_RTMP_TYPE_SCRIPT), timestamp, pts,
|
||||
size + FLV_HEADER_SIZE, size, (int)offset, hbuf, tbuf,
|
||||
srs_amf0_human_print(amf0_name, &amf0_name_str, &amf0_size),
|
||||
srs_amf0_human_print(amf0_data, &amf0_data_str, &amf0_size));
|
||||
|
||||
|
@ -168,7 +168,7 @@ int parse_script_data(u_int32_t timestamp, char* data, int size, int64_t offset)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int parse_audio_data(u_int32_t timestamp, char* data, int size, int64_t offset)
|
||||
int parse_audio_data(u_int32_t timestamp, u_int32_t pts, char* data, int size, int64_t offset)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
|
@ -178,15 +178,15 @@ int parse_audio_data(u_int32_t timestamp, char* data, int size, int64_t offset)
|
|||
// bytes
|
||||
parse_bytes(data, size, hbuf, sizeof(hbuf), tbuf, sizeof(tbuf), 16);
|
||||
|
||||
srs_lib_trace("packet type=%s, time=%d, size=%d, data-size=%d, \n"
|
||||
srs_lib_trace("packet type=%s, dts=%d, pts=%d, size=%d, data-size=%d, \n"
|
||||
"offset=%d\n[+00, +15] %s\n[-15, EOF] %s\n",
|
||||
srs_type2string(SRS_RTMP_TYPE_AUDIO), timestamp, size + FLV_HEADER_SIZE, size,
|
||||
(int)offset, hbuf, tbuf);
|
||||
srs_type2string(SRS_RTMP_TYPE_AUDIO), timestamp, pts,
|
||||
size + FLV_HEADER_SIZE, size, (int)offset, hbuf, tbuf);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int parse_video_data(u_int32_t timestamp, char* data, int size, int64_t offset)
|
||||
int parse_video_data(u_int32_t timestamp, u_int32_t pts, char* data, int size, int64_t offset)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
|
@ -196,10 +196,10 @@ int parse_video_data(u_int32_t timestamp, char* data, int size, int64_t offset)
|
|||
// bytes
|
||||
parse_bytes(data, size, hbuf, sizeof(hbuf), tbuf, sizeof(tbuf), 16);
|
||||
|
||||
srs_lib_trace("packet type=%s, time=%d, size=%d, data-size=%d, \n"
|
||||
srs_lib_trace("packet type=%s, dts=%d, pts=%d, size=%d, data-size=%d, \n"
|
||||
"offset=%d\n[+00, +15] %s\n[-15, EOF] %s\n",
|
||||
srs_type2string(SRS_RTMP_TYPE_VIDEO), timestamp, size + FLV_HEADER_SIZE, size,
|
||||
(int)offset, hbuf, tbuf);
|
||||
srs_type2string(SRS_RTMP_TYPE_VIDEO), timestamp, pts,
|
||||
size + FLV_HEADER_SIZE, size, (int)offset, hbuf, tbuf);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -240,27 +240,27 @@ int parse_flv(srs_flv_t flv)
|
|||
break;
|
||||
}
|
||||
|
||||
u_int32_t pts = 0;
|
||||
data = (char*)malloc(size);
|
||||
if ((ret = srs_flv_read_tag_data(flv, data, size)) != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// data tag
|
||||
if (type == SRS_RTMP_TYPE_AUDIO) {
|
||||
if ((ret = parse_audio_data(timestamp, data, size, offset)) != 0) {
|
||||
return ret;
|
||||
}
|
||||
} else if (type == SRS_RTMP_TYPE_VIDEO) {
|
||||
if ((ret = parse_video_data(timestamp, data, size, offset)) != 0) {
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
if ((ret = parse_script_data(timestamp, data, size, offset)) != 0) {
|
||||
return ret;
|
||||
if ((ret = srs_flv_read_tag_data(flv, data, size)) == 0
|
||||
&& (ret = srs_parse_timestamp(timestamp, type, data, size, &pts)) == 0
|
||||
) {
|
||||
if (type == SRS_RTMP_TYPE_AUDIO) {
|
||||
ret = parse_audio_data(timestamp, pts, data, size, offset);
|
||||
} else if (type == SRS_RTMP_TYPE_VIDEO) {
|
||||
ret = parse_video_data(timestamp, pts, data, size, offset);
|
||||
} else {
|
||||
ret = parse_script_data(timestamp, pts, data, size, offset);
|
||||
}
|
||||
}
|
||||
|
||||
free(data);
|
||||
|
||||
if (ret != 0) {
|
||||
srs_lib_trace("parse failed, ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -94,9 +94,10 @@ int proxy(srs_rtmp_t irtmp, srs_rtmp_t ortmp)
|
|||
int ret = 0;
|
||||
|
||||
// packet data
|
||||
int type, size;
|
||||
u_int32_t timestamp = 0;
|
||||
char* data = NULL;
|
||||
int size;
|
||||
char type;
|
||||
char* data;
|
||||
u_int32_t timestamp;
|
||||
|
||||
if ((ret = connect_ic(irtmp)) != 0) {
|
||||
return ret;
|
||||
|
|
|
@ -66,15 +66,19 @@ int main(int argc, char** argv)
|
|||
srs_lib_trace("play stream success");
|
||||
|
||||
for (;;) {
|
||||
int type, size;
|
||||
u_int32_t timestamp = 0;
|
||||
int size;
|
||||
char type;
|
||||
char* data;
|
||||
u_int32_t timestamp, pts;
|
||||
|
||||
if (srs_read_packet(rtmp, &type, ×tamp, &data, &size) != 0) {
|
||||
goto rtmp_destroy;
|
||||
}
|
||||
srs_lib_trace("got packet: type=%s, time=%d, size=%d",
|
||||
srs_type2string(type), timestamp, size);
|
||||
if (srs_parse_timestamp(timestamp, type, data, size, &pts) != 0) {
|
||||
goto rtmp_destroy;
|
||||
}
|
||||
srs_lib_trace("got packet: type=%s, dts=%d, pts=%d, size=%d",
|
||||
srs_type2string(type), timestamp, pts, size);
|
||||
|
||||
free(data);
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ int main(int argc, char** argv)
|
|||
|
||||
u_int32_t timestamp = 0;
|
||||
for (;;) {
|
||||
int type = SRS_RTMP_TYPE_VIDEO;
|
||||
char type = SRS_RTMP_TYPE_VIDEO;
|
||||
int size = 4096;
|
||||
char* data = (char*)malloc(4096);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue