direct_transport.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef TEST_DIRECT_TRANSPORT_H_
  11. #define TEST_DIRECT_TRANSPORT_H_
  12. #include <memory>
  13. #include "api/call/transport.h"
  14. #include "api/task_queue/task_queue_base.h"
  15. #include "api/test/simulated_network.h"
  16. #include "call/call.h"
  17. #include "call/simulated_packet_receiver.h"
  18. #include "rtc_base/synchronization/sequence_checker.h"
  19. #include "rtc_base/task_utils/repeating_task.h"
  20. #include "rtc_base/thread_annotations.h"
  21. namespace webrtc {
  22. class PacketReceiver;
  23. namespace test {
  24. class Demuxer {
  25. public:
  26. explicit Demuxer(const std::map<uint8_t, MediaType>& payload_type_map);
  27. ~Demuxer() = default;
  28. MediaType GetMediaType(const uint8_t* packet_data,
  29. const size_t packet_length) const;
  30. const std::map<uint8_t, MediaType> payload_type_map_;
  31. RTC_DISALLOW_COPY_AND_ASSIGN(Demuxer);
  32. };
  33. // Objects of this class are expected to be allocated and destroyed on the
  34. // same task-queue - the one that's passed in via the constructor.
  35. class DirectTransport : public Transport {
  36. public:
  37. DirectTransport(TaskQueueBase* task_queue,
  38. std::unique_ptr<SimulatedPacketReceiverInterface> pipe,
  39. Call* send_call,
  40. const std::map<uint8_t, MediaType>& payload_type_map);
  41. ~DirectTransport() override;
  42. // TODO(holmer): Look into moving this to the constructor.
  43. virtual void SetReceiver(PacketReceiver* receiver);
  44. bool SendRtp(const uint8_t* data,
  45. size_t length,
  46. const PacketOptions& options) override;
  47. bool SendRtcp(const uint8_t* data, size_t length) override;
  48. int GetAverageDelayMs();
  49. private:
  50. void ProcessPackets() RTC_EXCLUSIVE_LOCKS_REQUIRED(&process_lock_);
  51. void SendPacket(const uint8_t* data, size_t length);
  52. void Start();
  53. Call* const send_call_;
  54. TaskQueueBase* const task_queue_;
  55. rtc::CriticalSection process_lock_;
  56. RepeatingTaskHandle next_process_task_ RTC_GUARDED_BY(&process_lock_);
  57. const Demuxer demuxer_;
  58. const std::unique_ptr<SimulatedPacketReceiverInterface> fake_network_;
  59. };
  60. } // namespace test
  61. } // namespace webrtc
  62. #endif // TEST_DIRECT_TRANSPORT_H_