No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

70 líneas
2.4KB

  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_proxyplayer.h"
  11. #include "Player/PlayerProxy.h"
  12. using namespace toolkit;
  13. using namespace mediakit;
  14. API_EXPORT mk_proxy_player API_CALL mk_proxy_player_create(const char *vhost, const char *app, const char *stream, int hls_enabled, int mp4_enabled) {
  15. assert(vhost && app && stream);
  16. ProtocolOption option;
  17. option.enable_hls = hls_enabled;
  18. option.enable_mp4 = mp4_enabled;
  19. PlayerProxy::Ptr *obj(new PlayerProxy::Ptr(new PlayerProxy(vhost, app, stream, option)));
  20. return (mk_proxy_player) obj;
  21. }
  22. API_EXPORT void API_CALL mk_proxy_player_release(mk_proxy_player ctx) {
  23. assert(ctx);
  24. PlayerProxy::Ptr *obj = (PlayerProxy::Ptr *) ctx;
  25. delete obj;
  26. }
  27. API_EXPORT void API_CALL mk_proxy_player_set_option(mk_proxy_player ctx, const char *key, const char *val){
  28. assert(ctx && key && val);
  29. PlayerProxy::Ptr &obj = *((PlayerProxy::Ptr *) ctx);
  30. std::string key_str(key), val_str(val);
  31. obj->getPoller()->async([obj,key_str,val_str](){
  32. //切换线程再操作
  33. (*obj)[key_str] = val_str;
  34. });
  35. }
  36. API_EXPORT void API_CALL mk_proxy_player_play(mk_proxy_player ctx, const char *url) {
  37. assert(ctx && url);
  38. PlayerProxy::Ptr &obj = *((PlayerProxy::Ptr *) ctx);
  39. std::string url_str(url);
  40. obj->getPoller()->async([obj,url_str](){
  41. //切换线程再操作
  42. obj->play(url_str);
  43. });
  44. }
  45. API_EXPORT void API_CALL mk_proxy_player_set_on_close(mk_proxy_player ctx, on_mk_proxy_player_close cb, void *user_data){
  46. assert(ctx);
  47. PlayerProxy::Ptr &obj = *((PlayerProxy::Ptr *) ctx);
  48. obj->getPoller()->async([obj,cb,user_data](){
  49. //切换线程再操作
  50. obj->setOnClose([cb,user_data](const SockException &ex){
  51. if(cb){
  52. cb(user_data, ex.getErrCode(), ex.what(), ex.getCustomCode());
  53. }
  54. });
  55. });
  56. }
  57. API_EXPORT int API_CALL mk_proxy_player_total_reader_count(mk_proxy_player ctx){
  58. assert(ctx);
  59. PlayerProxy::Ptr &obj = *((PlayerProxy::Ptr *) ctx);
  60. return obj->totalReaderCount();
  61. }