You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 8 месеца
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 <assert.h>
  11. #include "mk_pusher.h"
  12. #include "Pusher/MediaPusher.h"
  13. using namespace toolkit;
  14. using namespace mediakit;
  15. API_EXPORT mk_pusher API_CALL mk_pusher_create(const char *schema,const char *vhost,const char *app, const char *stream){
  16. assert(schema && vhost && app && schema);
  17. MediaPusher::Ptr *obj = new MediaPusher::Ptr(new MediaPusher(schema,vhost,app,stream));
  18. return obj;
  19. }
  20. API_EXPORT mk_pusher API_CALL mk_pusher_create_src(mk_media_source ctx){
  21. assert(ctx);
  22. MediaSource *src = (MediaSource *)ctx;
  23. MediaPusher::Ptr *obj = new MediaPusher::Ptr(new MediaPusher(src->shared_from_this()));
  24. return obj;
  25. }
  26. API_EXPORT void API_CALL mk_pusher_release(mk_pusher ctx){
  27. assert(ctx);
  28. MediaPusher::Ptr *obj = (MediaPusher::Ptr *)ctx;
  29. delete obj;
  30. }
  31. API_EXPORT void API_CALL mk_pusher_set_option(mk_pusher ctx, const char *key, const char *val){
  32. assert(ctx && key && val);
  33. MediaPusher::Ptr &obj = *((MediaPusher::Ptr *)ctx);
  34. std::string key_str(key), val_str(val);
  35. obj->getPoller()->async([obj,key_str,val_str](){
  36. //切换线程再操作
  37. (*obj)[key_str] = val_str;
  38. });
  39. }
  40. API_EXPORT void API_CALL mk_pusher_publish(mk_pusher ctx,const char *url){
  41. assert(ctx && url);
  42. MediaPusher::Ptr &obj = *((MediaPusher::Ptr *)ctx);
  43. std::string url_str(url);
  44. obj->getPoller()->async([obj,url_str](){
  45. //切换线程再操作
  46. obj->publish(url_str);
  47. });
  48. }
  49. API_EXPORT void API_CALL mk_pusher_set_on_result(mk_pusher ctx, on_mk_push_event cb, void *user_data){
  50. assert(ctx && cb);
  51. MediaPusher::Ptr &obj = *((MediaPusher::Ptr *)ctx);
  52. obj->getPoller()->async([obj,cb,user_data](){
  53. //切换线程再操作
  54. obj->setOnPublished([cb,user_data](const SockException &ex){
  55. cb(user_data,ex.getErrCode(),ex.what());
  56. });
  57. });
  58. }
  59. API_EXPORT void API_CALL mk_pusher_set_on_shutdown(mk_pusher ctx, on_mk_push_event cb, void *user_data){
  60. assert(ctx && cb);
  61. MediaPusher::Ptr &obj = *((MediaPusher::Ptr *)ctx);
  62. obj->getPoller()->async([obj,cb,user_data](){
  63. //切换线程再操作
  64. obj->setOnShutdown([cb,user_data](const SockException &ex){
  65. cb(user_data,ex.getErrCode(),ex.what());
  66. });
  67. });
  68. }