Toybrick

关于rtsp库使用遇到的问题

zhyy2345

注册会员

积分
131
QQ
发表于 2020-12-22 15:32:53    查看: 5274|回复: 2 | [复制链接]    打印 | 显示全部楼层
采用live555推流,vlc播放器可以正常打开rtsp地址:rtsp://192.168.1.85:8554/4.mkv从  http://t.rock-chips.com/forum.ph ... &extra=page%3D1 获取的代码编译,修改如下:

#define RTSP_URL        "rtsp://192.168.1.85:8554/4.mkv"
#define RTSP_USER        ""
#define RTSP_PWD        ""


出现如下错误:

toybrick@debian10:~/mnt/RockChip/local_rtsp/build$ ./rtsp_ssd
mpp[29980]: mpp_info: mpp version: unknown mpp version for missing VCS info
mpp[29980]: mpp_rt: NOT found ion allocator
mpp[29980]: mpp_rt: found drm allocator
[2020/12/22 07:22:17] D/: listening rtp port 43386
[2020/12/22 07:22:17] D/: listening rtp port 43396
[2020/12/22 07:22:17] D/: listening rtcp port 43387
[2020/12/22 07:22:17] D/: listening rtcp port 43397
[2020/12/22 07:22:17] D/: curlto rtsp://192.168.1.85:8554/4.mkv , cli 43386:43396, tcp: 0
[2020/12/22 07:22:17] D/: # FOUND[0] media: video
[2020/12/22 07:22:17] D/: # FOUND[0] rtpmap: id:96 format:H264 bitrate:90000
[2020/12/22 07:22:17] D/: # FOUND[0] control: track1
[2020/12/22 07:22:17] D/: # FOUND[1] media: audio
[2020/12/22 07:22:17] D/: # FOUND[1] rtpmap: id:97 format:MPEG4-GENERIC bitrate:8000
[2020/12/22 07:22:17] D/: # FOUND[1] control: track2
[2020/12/22 07:22:17] D/: # TOTAL FOUND  2
[2020/12/22 07:22:17] D/: TRACK [0] : track1
[2020/12/22 07:22:17] D/: setup 43386 , 43387, uri: rtsp://192.168.1.85:8554/4.mkv/track1
[2020/12/22 07:22:17] D/: TRACK [1] : track2
[2020/12/22 07:22:17] D/: Video SSRC Changed! 0 -> 135728680
[2020/12/22 07:22:17] W/: (onTransmitIn in unit_rtp_h264_unpack.cpp:53): rtp lost one packet ... mDebugCntRtpLost: 65535 > 14553
frame recived 692
[2020/12/22 07:22:17] D/: RTP4UP_UNIT_SE [0x55a6663968] loss/recv:-1699.43/ 0.03 SEI|SPS|PPS|NI|I: 0.03|0.00|0.00|0.00|0.00
frame recived 67825
[2020/12/22 07:22:18] W/: (onTransmitIn in unit_rtp_h264_unpack.cpp:58): rtp timestamp out of order ! cur(3723829809) < last(3723837099)
frame recived 4471
[2020/12/22 07:22:18] W/: (onTransmitIn in unit_rtp_h264_unpack.cpp:58): rtp timestamp out of order ! cur(3723826209) < last(3723829809)
frame recived 957
frame recived 535
frame recived 560
[2020/12/22 07:22:18] W/: (onTransmitIn in unit_rtp_h264_unpack.cpp:58): rtp timestamp out of order ! cur(3723844299) < last(3723851499)
frame recived 5331
[2020/12/22 07:22:18] W/: (onTransmitIn in unit_rtp_h264_unpack.cpp:58): rtp timestamp out of order ! cur(3723840699) < last(3723844299)
frame recived 1065
mpp[29980]: mpp_log: decode_get_frame failed, return -8.
frame recived 561
frame recived 622
[2020/12/22 07:22:18] W/: (onTransmitIn in unit_rtp_h264_unpack.cpp:58): rtp timestamp out of order ! cur(3723858699) < last(3723865989)
frame recived 5451
[2020/12/22 07:22:18] W/: (onTransmitIn in unit_rtp_h264_unpack.cpp:58): rtp timestamp out of order ! cur(3723855099) < last(3723858699)
frame recived 1109
frame recived 610
frame recived 562
frame recived 427
mpp[29980]: mpp_log: decode_get_frame failed, return -8.
[2020/12/22 07:22:18] W/: (onTransmitIn in unit_rtp_h264_unpack.cpp:58): rtp timestamp out of order ! cur(3723876789) < last(3723883989)
frame recived 787
[2020/12/22 07:22:18] W/: (onTransmitIn in unit_rtp_h264_unpack.cpp:58): rtp timestamp out of order ! cur(3723873189) < last(3723876789)
frame recived 320
frame recived 178
frame recived 148
[2020/12/22 07:22:18] W/: (onTransmitIn in unit_rtp_h264_unpack.cpp:58): rtp timestamp out of order ! cur(3723891279) < last(3723898479)
frame recived 1483
[2020/12/22 07:22:18] W/: (onTransmitIn in unit_rtp_h264_unpack.cpp:58): rtp timestamp out of order ! cur(3723887589) < last(3723891279)
frame recived 339
frame recived 135
frame recived 214
mpp[29980]: mpp_log: decode_get_frame failed, return -8.
[2020/12/22 07:22:18] W/: (onTransmitIn in unit_rtp_h264_unpack.cpp:58): rtp timestamp out of order ! cur(3723905679) < last(3723912879)
frame recived 3301
[2020/12/22 07:22:18] W/: (onTransmitIn in unit_rtp_h264_unpack.cpp:58): rtp timestamp out of order ! cur(3723902079) < last(3723905679)
frame recived 528
frame recived 296
frame recived 278
[2020/12/22 07:22:19] W/: (onTransmitIn in unit_rtp_h264_unpack.cpp:58): rtp timestamp out of order ! cur(3723916479) < last(3723920169)
frame recived 6646
frame recived 578
[2020/12/22 07:22:19] W/: (onTransmitIn in unit_rtp_h264_unpack.cpp:58): rtp timestamp out of order ! cur(3723927369) < last(3723934569)
frame recived 8418
mpp[29980]: mpp_log: decode_get_frame failed, return -8.
[2020/12/22 07:22:19] W/: (onTransmitIn in unit_rtp_h264_unpack.cpp:58): rtp timestamp out of order ! cur(3723923769) < last(3723927369)
frame recived 1216
frame recived 726
frame recived 576
[2020/12/22 07:22:19] W/: (onTransmitIn in unit_rtp_h264_unpack.cpp:58): rtp timestamp out of order ! cur(3723941769) < last(3723949059)
frame recived 11498



回复

使用道具 举报

jefferyzhang

版主

积分
12848
发表于 2020-12-22 15:53:12 | 显示全部楼层
看过去像是RTP包解的有问题。
可以把这个文件发给我我有空调试下。

做项目的话不建议用Toybrick提供的rtsp库,这个库仅作为sample演示试用,还有很多BUG。
回复

使用道具 举报

zhyy2345

注册会员

积分
131
QQ
 楼主| 发表于 2020-12-22 16:14:05 | 显示全部楼层
jefferyzhang 发表于 2020-12-22 15:53
看过去像是RTP包解的有问题。
可以把这个文件发给我我有空调试下。

代码如下:
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <iostream>
  4. #include <string.h>
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7. #include <fcntl.h>
  8. #include <thread>
  9. #include <memory.h>
  10. #include <sys/time.h>
  11. #include <queue>

  12. using namespace std;

  13. #include "opencv2/core/core.hpp"
  14. #include "opencv2/highgui/highgui.hpp"

  15. #include <rockchip/rockchip_rtsp.h>
  16. #include <rockchip/rockchip_mpp.h>
  17. extern "C" {
  18. #include <rockchip/rockchip_rga.h>
  19. }

  20. #define RTSP_URL        "rtsp://192.168.1.85:8554/4.mkv"
  21. #define RTSP_USER        ""
  22. #define RTSP_PWD        ""

  23. static MppDecoder *mpp_dec = NULL;
  24. static std::queue<DecFrame *> frame_queue;
  25. static int run_flag = 0;
  26. int cnt=0;
  27. unsigned long get_time(void)
  28. {
  29.         struct timeval ts;
  30.         gettimeofday(&ts, NULL);
  31.         return (ts.tv_sec * 1000 + ts.tv_usec / 1000);
  32. }

  33. void onRtspHandle(unsigned char *buf, size_t len)
  34. {
  35.         std::cout << "frame recived " << len << std::endl;

  36.         mpp_dec->ops->enqueue(mpp_dec, buf, len);
  37. }

  38. void inference_thread(RockchipRga *rga, int width, int height)
  39. {
  40.         int ret;
  41.         int resize_w = 640, resize_h = 480;
  42.         static int frame_size = 0;
  43.         unsigned char *frame_rgb = NULL;

  44.         rga->ops->initCtx(rga);
  45.         rga->ops->setRotate(rga, RGA_ROTATE_NONE);
  46.         rga->ops->setSrcFormat(rga, V4L2_PIX_FMT_NV12, width, height);
  47.         rga->ops->setDstFormat(rga, V4L2_PIX_FMT_RGB24, resize_w, resize_h);
  48.        
  49.         frame_size = resize_w * resize_h * 3;
  50.         frame_rgb = (unsigned char *)malloc(frame_size);
  51.         cv::Mat img(resize_h , resize_w , CV_8UC3, frame_rgb);
  52.         if (!frame_rgb)
  53.                 goto exit;
  54.        
  55.         rga->ops->setDstBufferPtr(rga, frame_rgb);

  56.         while (run_flag)
  57.         {
  58.                 if (frame_queue.empty())
  59.                 {
  60.                         usleep(1000);
  61.                         continue;
  62.                 }

  63.                 auto frame = frame_queue.front();

  64.                 rga->ops->setSrcBufferPtr(rga, frame->data);

  65.                 ret = rga->ops->go(rga);
  66.                 printf("inference_thread ................\n");
  67.                 if (!ret) {
  68.                         ///do something with frame_rgb
  69.                         std::string jpg="./image/frame_"+std::to_string(cnt)+".jpg";
  70.                         cv::imwrite(jpg,img);
  71.                         //cv::imshow("test", img);
  72.                         std::cout<<"image width="<<img.cols<<std::endl;
  73.                         std::cout<<"image height="<<img.rows<<std::endl;
  74.                         cv::waitKey(30);
  75.                 }

  76.                 frame_queue.pop();
  77.                 mpp_dec->ops->freeFrame(frame);
  78.         }

  79. exit:
  80.         run_flag = 0;

  81.         while (!frame_queue.empty()) {
  82.                 auto frame = frame_queue.front();
  83.                 mpp_dec->ops->freeFrame(frame);
  84.                 frame_queue.pop();
  85.         }

  86.         if (frame_rgb)
  87.                 free(frame_rgb);
  88. }

  89. void decode_thread(RockchipRga *rga)
  90. {
  91.         int ret;
  92.         int first_frame = 0;
  93.         std::thread t_inference;

  94.         while (run_flag)
  95.         {
  96.                 //std::cout<<"$$$$$$$$$$$"<<std::endl;
  97.                 DecFrame *frame = mpp_dec->ops->dequeue_timeout(mpp_dec, 300);
  98.                 if (frame != NULL)
  99.                 {
  100.                         std::cout << "decode frame" << frame->width << "x" << frame->height << std::endl;
  101.                
  102.                         if (!first_frame)
  103.                         {
  104.                                 std::cout << "first_frame" << std::endl;
  105.                                 t_inference = std::thread(inference_thread, rga, frame->width, frame->height);
  106.                                 first_frame = 1;
  107.                         }

  108.                         if (frame_queue.size() < 30)
  109.                                 frame_queue.push(frame);
  110.                         else
  111.                                 mpp_dec->ops->freeFrame(frame);
  112.                 }
  113.                 // else
  114.                 // {
  115.                 //         std::cout<<"frame=NULL"<<std::endl;
  116.                 // }
  117.                
  118.         }

  119. exit:
  120.         run_flag = 0;

  121.         t_inference.join();

  122.         while (!frame_queue.empty()) {
  123.                 auto frame = frame_queue.front();
  124.                 mpp_dec->ops->freeFrame(frame);
  125.                 frame_queue.pop();
  126.         }

  127. }

  128. int main(int argc, char **argv)
  129. {
  130.         int ret;
  131.         RockchipRga *rga;
  132.         unsigned char ready[5] = {'r', 'e', 'a', 'd', 'y'};
  133.         RtspClient rtsp_client(RTSP_URL, RTSP_USER, RTSP_PWD);

  134.         rtsp_client.setDataCallback(onRtspHandle);

  135.         mpp_dec = MppDecoderCreate(DECODE_TYPE_H264);
  136.         if (!mpp_dec)
  137.         {
  138.                 std::cout << "MppDecoderCreate error!\n" << std::endl;
  139.                 return -1;
  140.         }

  141.         rga = RgaCreate();
  142.         if (!rga)
  143.         {
  144.                 MppDecoderDestroy(mpp_dec);
  145.                 std::cout << "rgaCreate error!\n" << std::endl;
  146.                 return -1;
  147.         }

  148.         run_flag = 1;

  149.         rtsp_client.enable();

  150.         std::thread t_decode(decode_thread, rga);

  151.         while (run_flag) {
  152.                 usleep(10000);
  153.         }

  154.         rtsp_client.disable();

  155.         run_flag = 0;

  156.         t_decode.join();

  157.         RgaDestroy(rga);

  158.         MppDecoderDestroy(mpp_dec);

  159.         return 0;
  160. }
复制代码

[url=链接:https://pan.baidu.com/s/1ZfNvL93sQT5RlYhQGNp6Ig  提取码:5one  ]4.mp4的视频链接[/url]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

产品中心 购买渠道 开源社区 Wiki教程 资料下载 关于Toybrick


快速回复 返回顶部 返回列表