Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/media/webrtc/signaling/src/peerconnection/PacketDumper.cpp
Line
Count
Source (jump to first uncovered line)
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
#include "signaling/src/peerconnection/PacketDumper.h"
6
#include "signaling/src/peerconnection/PeerConnectionImpl.h"
7
#include "mozilla/media/MediaUtils.h" // NewRunnableFrom
8
#include "nsThreadUtils.h" // NS_DispatchToMainThread
9
10
namespace mozilla {
11
12
PacketDumper::PacketDumper(PeerConnectionImpl* aPc) :
13
  mPc(aPc)
14
0
{
15
0
}
16
17
PacketDumper::PacketDumper(const std::string& aPcHandle)
18
0
{
19
0
  if (!aPcHandle.empty()) {
20
0
    PeerConnectionWrapper pcw(aPcHandle);
21
0
    mPc = pcw.impl();
22
0
  }
23
0
}
24
25
PacketDumper::~PacketDumper()
26
0
{
27
0
  RefPtr<Runnable> pcDisposeRunnable =
28
0
    media::NewRunnableFrom(
29
0
        std::bind(
30
0
          [](RefPtr<PeerConnectionImpl> pc) {
31
0
            return NS_OK;
32
0
          },
33
0
          mPc.forget()));
34
0
  NS_DispatchToMainThread(pcDisposeRunnable);
35
0
}
36
37
void
38
PacketDumper::Dump(size_t level, dom::mozPacketDumpType type, bool sending,
39
                   const void* data, size_t size)
40
0
{
41
0
  // Optimization; avoids making a copy of the buffer, but we need to lock a
42
0
  // mutex and check the flags. Could be optimized further, if we really want to
43
0
  if (!mPc || !mPc->ShouldDumpPacket(level, type, sending)) {
44
0
    return;
45
0
  }
46
0
47
0
  RefPtr<PeerConnectionImpl> pc = mPc;
48
0
49
0
  UniquePtr<uint8_t[]> ownedPacket = MakeUnique<uint8_t[]>(size);
50
0
  memcpy(ownedPacket.get(), data, size);
51
0
52
0
  RefPtr<Runnable> dumpRunnable =
53
0
    media::NewRunnableFrom(
54
0
        std::bind(
55
0
          [pc, level, type, sending, size](UniquePtr<uint8_t[]>& packet)
56
0
            -> nsresult
57
0
          {
58
0
            pc->DumpPacket_m(level, type, sending, packet, size);
59
0
            return NS_OK;
60
0
          },
61
0
          std::move(ownedPacket)));
62
0
63
0
  NS_DispatchToMainThread(dumpRunnable);
64
0
}
65
66
} //namespace mozilla
67