Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

166 lignes
6.9KB

  1. /*
  2. * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
  3. *
  4. * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
  5. *
  6. * Use of this source code is governed by MIT license that can be found in the
  7. * LICENSE file in the root of the source tree. All contributing project authors
  8. * may be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include "mk_events.h"
  11. #include "Common/config.h"
  12. #include "Common/MediaSource.h"
  13. #include "Http/HttpSession.h"
  14. #include "Rtsp/RtspSession.h"
  15. #include "Record/MP4Recorder.h"
  16. using namespace toolkit;
  17. using namespace mediakit;
  18. static void* s_tag;
  19. static mk_events s_events = {0};
  20. API_EXPORT void API_CALL mk_events_listen(const mk_events *events){
  21. if (events) {
  22. memcpy(&s_events, events, sizeof(s_events));
  23. } else {
  24. memset(&s_events, 0, sizeof(s_events));
  25. }
  26. static onceToken token([]{
  27. NoticeCenter::Instance().addListener(&s_tag,Broadcast::kBroadcastMediaChanged,[](BroadcastMediaChangedArgs){
  28. if(s_events.on_mk_media_changed){
  29. s_events.on_mk_media_changed(bRegist,
  30. (mk_media_source)&sender);
  31. }
  32. });
  33. NoticeCenter::Instance().addListener(&s_tag,Broadcast::kBroadcastRecordMP4,[](BroadcastRecordMP4Args){
  34. if(s_events.on_mk_record_mp4){
  35. s_events.on_mk_record_mp4((mk_mp4_info)&info);
  36. }
  37. });
  38. NoticeCenter::Instance().addListener(&s_tag,Broadcast::kBroadcastHttpRequest,[](BroadcastHttpRequestArgs){
  39. if(s_events.on_mk_http_request){
  40. int consumed_int = consumed;
  41. s_events.on_mk_http_request((mk_parser)&parser,
  42. (mk_http_response_invoker)&invoker,
  43. &consumed_int,
  44. (mk_sock_info)&sender);
  45. consumed = consumed_int;
  46. }
  47. });
  48. NoticeCenter::Instance().addListener(&s_tag,Broadcast::kBroadcastHttpAccess,[](BroadcastHttpAccessArgs){
  49. if(s_events.on_mk_http_access){
  50. s_events.on_mk_http_access((mk_parser)&parser,
  51. path.c_str(),
  52. is_dir,
  53. (mk_http_access_path_invoker)&invoker,
  54. (mk_sock_info)&sender);
  55. } else{
  56. invoker("","",0);
  57. }
  58. });
  59. NoticeCenter::Instance().addListener(&s_tag,Broadcast::kBroadcastHttpBeforeAccess,[](BroadcastHttpBeforeAccessArgs){
  60. if(s_events.on_mk_http_before_access){
  61. char path_c[4 * 1024] = {0};
  62. strcpy(path_c,path.c_str());
  63. s_events.on_mk_http_before_access((mk_parser) &parser,
  64. path_c,
  65. (mk_sock_info) &sender);
  66. path = path_c;
  67. }
  68. });
  69. NoticeCenter::Instance().addListener(&s_tag,Broadcast::kBroadcastOnGetRtspRealm,[](BroadcastOnGetRtspRealmArgs){
  70. if (s_events.on_mk_rtsp_get_realm) {
  71. s_events.on_mk_rtsp_get_realm((mk_media_info) &args,
  72. (mk_rtsp_get_realm_invoker) &invoker,
  73. (mk_sock_info) &sender);
  74. }else{
  75. invoker("");
  76. }
  77. });
  78. NoticeCenter::Instance().addListener(&s_tag,Broadcast::kBroadcastOnRtspAuth,[](BroadcastOnRtspAuthArgs){
  79. if (s_events.on_mk_rtsp_auth) {
  80. s_events.on_mk_rtsp_auth((mk_media_info) &args,
  81. realm.c_str(),
  82. user_name.c_str(),
  83. must_no_encrypt,
  84. (mk_rtsp_auth_invoker) &invoker,
  85. (mk_sock_info) &sender);
  86. }
  87. });
  88. NoticeCenter::Instance().addListener(&s_tag,Broadcast::kBroadcastMediaPublish,[](BroadcastMediaPublishArgs){
  89. if (s_events.on_mk_media_publish) {
  90. s_events.on_mk_media_publish((mk_media_info) &args,
  91. (mk_publish_auth_invoker) &invoker,
  92. (mk_sock_info) &sender);
  93. } else {
  94. invoker("", ProtocolOption());
  95. }
  96. });
  97. NoticeCenter::Instance().addListener(&s_tag,Broadcast::kBroadcastMediaPlayed,[](BroadcastMediaPlayedArgs){
  98. if (s_events.on_mk_media_play) {
  99. s_events.on_mk_media_play((mk_media_info) &args,
  100. (mk_auth_invoker) &invoker,
  101. (mk_sock_info) &sender);
  102. }else{
  103. invoker("");
  104. }
  105. });
  106. NoticeCenter::Instance().addListener(&s_tag,Broadcast::kBroadcastShellLogin,[](BroadcastShellLoginArgs){
  107. if (s_events.on_mk_shell_login) {
  108. s_events.on_mk_shell_login(user_name.c_str(),
  109. passwd.c_str(),
  110. (mk_auth_invoker) &invoker,
  111. (mk_sock_info) &sender);
  112. }else{
  113. invoker("");
  114. }
  115. });
  116. NoticeCenter::Instance().addListener(&s_tag,Broadcast::kBroadcastFlowReport,[](BroadcastFlowReportArgs){
  117. if (s_events.on_mk_flow_report) {
  118. s_events.on_mk_flow_report((mk_media_info) &args,
  119. totalBytes,
  120. totalDuration,
  121. isPlayer,
  122. (mk_sock_info)&sender);
  123. }
  124. });
  125. NoticeCenter::Instance().addListener(&s_tag,Broadcast::kBroadcastNotFoundStream,[](BroadcastNotFoundStreamArgs){
  126. if (s_events.on_mk_media_not_found) {
  127. if (s_events.on_mk_media_not_found((mk_media_info) &args,
  128. (mk_sock_info) &sender)) {
  129. closePlayer();
  130. }
  131. }
  132. });
  133. NoticeCenter::Instance().addListener(&s_tag,Broadcast::kBroadcastStreamNoneReader,[](BroadcastStreamNoneReaderArgs){
  134. if (s_events.on_mk_media_no_reader) {
  135. s_events.on_mk_media_no_reader((mk_media_source) &sender);
  136. }
  137. });
  138. NoticeCenter::Instance().addListener(&s_tag, EventChannel::kBroadcastLogEvent,[](BroadcastLogEventArgs){
  139. if (s_events.on_mk_log) {
  140. auto log = ctx->str();
  141. s_events.on_mk_log((int) ctx->_level, ctx->_file.data(), ctx->_line, ctx->_function.data(), log.data());
  142. }
  143. });
  144. });
  145. }