PacketDumper.h (1785B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #ifndef _PACKET_DUMPER_H_ 6 #define _PACKET_DUMPER_H_ 7 8 #include <vector> 9 10 #include "mozilla/RefPtr.h" 11 #include "mozilla/dom/RTCPeerConnectionBinding.h" 12 #include "nsISupportsImpl.h" 13 14 namespace mozilla { 15 class PeerConnectionImpl; 16 17 class PacketDumper { 18 public: 19 static RefPtr<PacketDumper> GetPacketDumper(const std::string& aPcHandle); 20 21 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(PacketDumper) 22 23 PacketDumper(const PacketDumper&) = delete; 24 PacketDumper& operator=(const PacketDumper&) = delete; 25 26 void Dump(size_t aLevel, dom::mozPacketDumpType aType, bool aSending, 27 const void* aData, size_t aSize); 28 29 nsresult EnablePacketDump(unsigned long aLevel, dom::mozPacketDumpType aType, 30 bool aSending); 31 32 nsresult DisablePacketDump(unsigned long aLevel, dom::mozPacketDumpType aType, 33 bool aSending); 34 35 private: 36 friend class PeerConnectionImpl; 37 explicit PacketDumper(const std::string& aPcHandle); 38 ~PacketDumper() = default; 39 bool ShouldDumpPacket(size_t aLevel, dom::mozPacketDumpType aType, 40 bool aSending) const; 41 42 // This class is not cycle-collected, so it cannot hold onto a strong ref 43 const std::string mPcHandle; 44 std::vector<unsigned> mSendPacketDumpFlags 45 MOZ_GUARDED_BY(mPacketDumpFlagsMutex); 46 std::vector<unsigned> mRecvPacketDumpFlags 47 MOZ_GUARDED_BY(mPacketDumpFlagsMutex); 48 Atomic<bool> mPacketDumpEnabled{false}; 49 Atomic<int> mPacketDumpRtcpRecvCount{0}; 50 mutable Mutex mPacketDumpFlagsMutex; 51 }; 52 53 } // namespace mozilla 54 55 #endif // _PACKET_DUMPER_H_