• 流媒体分析之rtmp ffmpeg 实现-两种技术实现


    ffmpeg rtmp 流媒体实现有两种方式,一种是基于librtmp实现:libavformat/librtmp.c

    1. #define RTMP_CLASS(flavor)\
    2. static const AVClass lib ## flavor ## _class = {\
    3. .class_name = "lib" #flavor " protocol",\
    4. .item_name = av_default_item_name,\
    5. .option = options,\
    6. .version = LIBAVUTIL_VERSION_INT,\
    7. };
    8. RTMP_CLASS(rtmp)
    9. const URLProtocol ff_librtmp_protocol = {
    10. .name = "rtmp",
    11. .url_open = rtmp_open,
    12. .url_read = rtmp_read,
    13. .url_write = rtmp_write,
    14. .url_close = rtmp_close,
    15. .url_read_pause = rtmp_read_pause,
    16. .url_read_seek = rtmp_read_seek,
    17. .url_get_file_handle = rtmp_get_file_handle,
    18. .priv_data_size = sizeof(LibRTMPContext),
    19. .priv_data_class = &librtmp_class,
    20. .flags = URL_PROTOCOL_FLAG_NETWORK,
    21. };
    22. RTMP_CLASS(rtmpt)
    23. const URLProtocol ff_librtmpt_protocol = {
    24. .name = "rtmpt",
    25. .url_open = rtmp_open,
    26. .url_read = rtmp_read,
    27. .url_write = rtmp_write,
    28. .url_close = rtmp_close,
    29. .url_read_pause = rtmp_read_pause,
    30. .url_read_seek = rtmp_read_seek,
    31. .url_get_file_handle = rtmp_get_file_handle,
    32. .priv_data_size = sizeof(LibRTMPContext),
    33. .priv_data_class = &librtmpt_class,
    34. .flags = URL_PROTOCOL_FLAG_NETWORK,
    35. };
    36. RTMP_CLASS(rtmpe)
    37. const URLProtocol ff_librtmpe_protocol = {
    38. .name = "rtmpe",
    39. .url_open = rtmp_open,
    40. .url_read = rtmp_read,
    41. .url_write = rtmp_write,
    42. .url_close = rtmp_close,
    43. .url_read_pause = rtmp_read_pause,
    44. .url_read_seek = rtmp_read_seek,
    45. .url_get_file_handle = rtmp_get_file_handle,
    46. .priv_data_size = sizeof(LibRTMPContext),
    47. .priv_data_class = &librtmpe_class,
    48. .flags = URL_PROTOCOL_FLAG_NETWORK,
    49. };
    50. RTMP_CLASS(rtmpte)
    51. const URLProtocol ff_librtmpte_protocol = {
    52. .name = "rtmpte",
    53. .url_open = rtmp_open,
    54. .url_read = rtmp_read,
    55. .url_write = rtmp_write,
    56. .url_close = rtmp_close,
    57. .url_read_pause = rtmp_read_pause,
    58. .url_read_seek = rtmp_read_seek,
    59. .url_get_file_handle = rtmp_get_file_handle,
    60. .priv_data_size = sizeof(LibRTMPContext),
    61. .priv_data_class = &librtmpte_class,
    62. .flags = URL_PROTOCOL_FLAG_NETWORK,
    63. };
    64. RTMP_CLASS(rtmps)
    65. const URLProtocol ff_librtmps_protocol = {
    66. .name = "rtmps",
    67. .url_open = rtmp_open,
    68. .url_read = rtmp_read,
    69. .url_write = rtmp_write,
    70. .url_close = rtmp_close,
    71. .url_read_pause = rtmp_read_pause,
    72. .url_read_seek = rtmp_read_seek,
    73. .url_get_file_handle = rtmp_get_file_handle,
    74. .priv_data_size = sizeof(LibRTMPContext),
    75. .priv_data_class = &librtmps_class,
    76. .flags = URL_PROTOCOL_FLAG_NETWORK,
    77. };

     一种是ffmpeg 自己实现的rtmp 协议 libavformat/rtmpproto.c

    1. #define RTMP_PROTOCOL(flavor) \
    2. static const AVClass flavor##_class = { \
    3. .class_name = #flavor, \
    4. .item_name = av_default_item_name, \
    5. .option = rtmp_options, \
    6. .version = LIBAVUTIL_VERSION_INT, \
    7. }; \
    8. \
    9. const URLProtocol ff_##flavor##_protocol = { \
    10. .name = #flavor, \
    11. .url_open2 = rtmp_open, \
    12. .url_read = rtmp_read, \
    13. .url_read_seek = rtmp_seek, \
    14. .url_read_pause = rtmp_pause, \
    15. .url_write = rtmp_write, \
    16. .url_close = rtmp_close, \
    17. .priv_data_size = sizeof(RTMPContext), \
    18. .flags = URL_PROTOCOL_FLAG_NETWORK, \
    19. .priv_data_class= &flavor##_class, \
    20. };
    21. RTMP_PROTOCOL(rtmp)
    22. RTMP_PROTOCOL(rtmpe)
    23. RTMP_PROTOCOL(rtmps)
    24. RTMP_PROTOCOL(rtmpt)
    25. RTMP_PROTOCOL(rtmpte)
    26. RTMP_PROTOCOL(rtmpts)

  • 相关阅读:
    SAP abap ALV 自定义按钮功能
    ubuntu更换清华源
    Windows OpenGL 图像阴影
    c++中的enum class强转
    [SpringMVC笔记] SpringMVC-14-SSM整合-异常处理器
    Django学习日志10
    SpringCloud alibaba
    04 flink 集群搭建
    文件传输工具WinSCP下载安装使用教程
    纯IP地址可以申请SSL证书实现HTTPS访问吗?
  • 原文地址:https://blog.csdn.net/u012794472/article/details/126727250