summaryrefslogtreecommitdiffstats
path: root/media/cast/test/loopback_transport.h
blob: e61ae4d7f1496f8c697099371c33a444e840857c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_CAST_TEST_LOOPBACK_TRANSPORT_H_
#define MEDIA_CAST_TEST_LOOPBACK_TRANSPORT_H_

#include <stdint.h>

#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "media/cast/cast_environment.h"
#include "media/cast/net/cast_transport_config.h"

namespace base {
class SingleThreadTaskRunner;
class TickClock;
}  // namespace base

namespace media {
namespace cast {

namespace test {
class PacketPipe;
}  // namespace test

// Class that sends the packet to a receiver through a stack of PacketPipes.
class LoopBackTransport : public PacketSender {
 public:
  explicit LoopBackTransport(
      scoped_refptr<CastEnvironment> cast_environment);
  ~LoopBackTransport() final;

  bool SendPacket(PacketRef packet, const base::Closure& cb) final;

  int64_t GetBytesSent() final;

  // Initiailize this loopback transport.
  // Establish a flow of packets from |pipe| to |packet_receiver|.
  //
  // The data flow looks like:
  // SendPacket() -> |pipe| -> Fake loopback pipe -> |packet_receiver|.
  //
  // If |pipe| is NULL then the data flow looks like:
  // SendPacket() -> Fake loopback pipe -> |packet_receiver|.
  void Initialize(
      scoped_ptr<test::PacketPipe> pipe,
      const PacketReceiverCallback& packet_receiver,
      const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
      base::TickClock* clock);

 private:
  const scoped_refptr<CastEnvironment> cast_environment_;
  scoped_ptr<test::PacketPipe> packet_pipe_;
  int64_t bytes_sent_;

  DISALLOW_COPY_AND_ASSIGN(LoopBackTransport);
};

}  // namespace cast
}  // namespace media

#endif  // MEDIA_CAST_TEST_LOOPBACK_TRANSPORT_H_