@@ -1322,6 +1322,50 @@ int cls_netcam::resize()
13221322 return 0 ;
13231323}
13241324
1325+ void cls_netcam::pkt_ts ()
1326+ {
1327+ int64_t usec_ltncy;
1328+ AVRational tbase;
1329+ struct timespec tmp_tm;
1330+
1331+ if (connection_pts == -1 ) {
1332+ if (packet_recv->pts == AV_NOPTS_VALUE) {
1333+ connection_pts = 0 ;
1334+ } else {
1335+ connection_pts = packet_recv->pts ;
1336+ }
1337+ clock_gettime (CLOCK_MONOTONIC, &connection_tm);
1338+ }
1339+
1340+ if (packet_recv->pts == AV_NOPTS_VALUE) {
1341+ clock_gettime (CLOCK_MONOTONIC, &tmp_tm);
1342+
1343+ tbase = format_context->streams [packet_recv->stream_index ]->time_base ;
1344+ if (tbase.num == 0 ) {
1345+ tbase.num = 1 ;
1346+ }
1347+ usec_ltncy = (((tmp_tm.tv_sec - connection_tm.tv_sec ) * 1000000 ) +
1348+ ((tmp_tm.tv_nsec - connection_tm.tv_nsec ) / 1000 ));
1349+ if (usec_ltncy < 0 ) {
1350+ MOTPLS_LOG (ERR, TYPE_NETCAM, NO_ERRNO
1351+ ,_ (" %s:Latency calculation error " )
1352+ , cameratype.c_str ());
1353+ usec_ltncy = 0 ;
1354+ }
1355+
1356+ packet_recv->pts = connection_pts
1357+ + av_rescale (usec_ltncy, tbase.den /tbase.num , 1000000 );
1358+
1359+ }
1360+
1361+ if (packet_recv->dts == AV_NOPTS_VALUE) {
1362+ packet_recv->dts = packet_recv->pts ;
1363+ }
1364+
1365+ last_pts = packet_recv->pts ;
1366+
1367+ }
1368+
13251369int cls_netcam::read_image ()
13261370{
13271371 int size_decoded, retcd, errcnt, nodata;
@@ -1403,7 +1447,8 @@ int cls_netcam::read_image()
14031447 clock_gettime (CLOCK_MONOTONIC, &ist_tm);
14041448 clock_gettime (CLOCK_MONOTONIC, &img_recv->image_time );
14051449 last_stream_index = packet_recv->stream_index ;
1406- last_pts = packet_recv->pts ;
1450+
1451+ pkt_ts ();
14071452
14081453 if (!first_image) {
14091454 status = NETCAM_CONNECTED;
@@ -1672,7 +1717,7 @@ void cls_netcam::set_parms ()
16721717 swsframe_size = 0 ;
16731718 hw_type = AV_HWDEVICE_TYPE_NONE;
16741719 hw_pix_fmt = AV_PIX_FMT_NONE;
1675- connection_pts = 0 ;
1720+ connection_pts = - 1 ;
16761721 last_pts = 0 ;
16771722 filenbr = 0 ;
16781723 filelist.clear ();
@@ -1901,8 +1946,6 @@ int cls_netcam::open_context()
19011946 return -1 ;
19021947 }
19031948
1904- connection_pts = AV_NOPTS_VALUE;
1905-
19061949 return 0 ;
19071950}
19081951
@@ -1996,18 +2039,11 @@ void cls_netcam::handler_wait()
19962039
19972040 /* Adjust to clock and pts timer */
19982041 if (pts_adj == true ) {
1999- if (connection_pts == AV_NOPTS_VALUE) {
2000- connection_pts = last_pts;
2001- clock_gettime (CLOCK_MONOTONIC, &connection_tm);
2002- return ;
2003- }
2004- if (last_pts != AV_NOPTS_VALUE) {
2005- usec_ltncy +=
2006- + (av_rescale (last_pts, 1000000 , tbase.den /tbase.num )
2007- - av_rescale (connection_pts, 1000000 , tbase.den /tbase.num ))
2008- -(((tmp_tm.tv_sec - connection_tm.tv_sec ) * 1000000 ) +
2009- ((tmp_tm.tv_nsec - connection_tm.tv_nsec ) / 1000 ));
2010- }
2042+ usec_ltncy +=
2043+ + (av_rescale (last_pts, 1000000 , tbase.den /tbase.num )
2044+ - av_rescale (connection_pts, 1000000 , tbase.den /tbase.num ))
2045+ -(((tmp_tm.tv_sec - connection_tm.tv_sec ) * 1000000 ) +
2046+ ((tmp_tm.tv_nsec - connection_tm.tv_nsec ) / 1000 ));
20112047 }
20122048
20132049 if ((usec_ltncy > 0 ) && (usec_ltncy < 1000000L )) {
0 commit comments