WebRtcEchoTest.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
  3. *
  4. * This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
  5. *
  6. * Use of this source code is governed by MIT-like 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 "WebRtcEchoTest.h"
  11. namespace mediakit {
  12. WebRtcEchoTest::Ptr WebRtcEchoTest::create(const EventPoller::Ptr &poller) {
  13. WebRtcEchoTest::Ptr ret(new WebRtcEchoTest(poller), [](WebRtcEchoTest *ptr) {
  14. ptr->onDestory();
  15. delete ptr;
  16. });
  17. ret->onCreate();
  18. return ret;
  19. }
  20. WebRtcEchoTest::WebRtcEchoTest(const EventPoller::Ptr &poller) : WebRtcTransportImp(poller) {}
  21. void WebRtcEchoTest::onRtcConfigure(RtcConfigure &configure) const {
  22. WebRtcTransportImp::onRtcConfigure(configure);
  23. configure.audio.direction = configure.video.direction = RtpDirection::sendrecv;
  24. configure.audio.extmap.emplace(RtpExtType::sdes_mid, RtpDirection::sendrecv);
  25. configure.video.extmap.emplace(RtpExtType::sdes_mid, RtpDirection::sendrecv);
  26. }
  27. void WebRtcEchoTest::onRtp(const char *buf, size_t len, uint64_t stamp_ms) {
  28. updateTicker();
  29. sendRtpPacket(buf, len, true, nullptr);
  30. }
  31. void WebRtcEchoTest::onRtcp(const char *buf, size_t len) {
  32. sendRtcpPacket(buf, len, true, nullptr);
  33. }
  34. // 修改mline的a=msid属性,目的是在echo test的情况下,如果offer和answer的msid相同,chrome会忽略远端的track [AUTO-TRANSLATED:f2e3da54]
  35. // Modify the a=msid attribute of mline, the purpose is that in the echo test case, if the offer and answer have the same msid, chrome will ignore the remote track.
  36. void WebRtcEchoTest::onCheckSdp(SdpType type, RtcSession &sdp) {
  37. if (type == SdpType::answer) {
  38. for (auto &m : sdp.media) {
  39. for (auto &ssrc : m.rtp_rtx_ssrc) {
  40. if (!ssrc.msid.empty()) {
  41. ssrc.msid = "zlmediakit-mslabel zlmediakit-label-" + m.mid;
  42. }
  43. }
  44. }
  45. }
  46. }
  47. }// namespace mediakit