direct_transport.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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/mutex.h"
  19. #include "rtc_base/synchronization/sequence_checker.h"
  20. #include "rtc_base/task_utils/repeating_task.h"
  21. #include "rtc_base/thread_annotations.h"
  22. namespace webrtc {
  23. class PacketReceiver;
  24. namespace test {
  25. class Demuxer {
  26. public:
  27. explicit Demuxer(const std::map<uint8_t, MediaType>& payload_type_map);
  28. ~Demuxer() = default;
  29. MediaType GetMediaType(const uint8_t* packet_data,
  30. const size_t packet_length) const;
  31. const std::map<uint8_t, MediaType> payload_type_map_;
  32. RTC_DISALLOW_COPY_AND_ASSIGN(Demuxer);
  33. };
  34. // Objects of this class are expected to be allocated and destroyed on the
  35. // same task-queue - the one that's passed in via the constructor.
  36. class DirectTransport : public Transport {
  37. public:
  38. DirectTransport(TaskQueueBase* task_queue,
  39. std::unique_ptr<SimulatedPacketReceiverInterface> pipe,
  40. Call* send_call,
  41. const std::map<uint8_t, MediaType>& payload_type_map);
  42. ~DirectTransport() override;
  43. // TODO(holmer): Look into moving this to the constructor.
  44. virtual void SetReceiver(PacketReceiver* receiver);
  45. bool SendRtp(const uint8_t* data,
  46. size_t length,
  47. const PacketOptions& options) override;
  48. bool SendRtcp(const uint8_t* data, size_t length) override;
  49. int GetAverageDelayMs();
  50. private:
  51. void ProcessPackets() RTC_EXCLUSIVE_LOCKS_REQUIRED(&process_lock_);
  52. void SendPacket(const uint8_t* data, size_t length);
  53. void Start();
  54. Call* const send_call_;
  55. TaskQueueBase* const task_queue_;
  56. Mutex process_lock_;
  57. RepeatingTaskHandle next_process_task_ RTC_GUARDED_BY(&process_lock_);
  58. const Demuxer demuxer_;
  59. const std::unique_ptr<SimulatedPacketReceiverInterface> fake_network_;
  60. };
  61. } // namespace test
  62. } // namespace webrtc
  63. #endif // TEST_DIRECT_TRANSPORT_H_