Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: trunk/src/media/cast/test/utility/udp_proxy.cc

Issue 328313002: Revert 276603 "Cast: Synthetic benchmark tool." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdlib.h>
6
7 #include "media/cast/test/utility/udp_proxy.h" 5 #include "media/cast/test/utility/udp_proxy.h"
8 6
9 #include "base/logging.h" 7 #include "base/logging.h"
10 #include "base/memory/linked_ptr.h" 8 #include "base/memory/linked_ptr.h"
11 #include "base/rand_util.h" 9 #include "base/rand_util.h"
12 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
13 #include "base/threading/thread.h" 11 #include "base/threading/thread.h"
14 #include "base/time/default_tick_clock.h" 12 #include "base/time/default_tick_clock.h"
15 #include "net/base/io_buffer.h" 13 #include "net/base/io_buffer.h"
16 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
(...skipping 26 matching lines...) Expand all
43 41
44 // Roughly emulates a buffer inside a device. 42 // Roughly emulates a buffer inside a device.
45 // If the buffer is full, packets are dropped. 43 // If the buffer is full, packets are dropped.
46 // Packets are output at a maximum bandwidth. 44 // Packets are output at a maximum bandwidth.
47 class Buffer : public PacketPipe { 45 class Buffer : public PacketPipe {
48 public: 46 public:
49 Buffer(size_t buffer_size, double max_megabits_per_second) 47 Buffer(size_t buffer_size, double max_megabits_per_second)
50 : buffer_size_(0), 48 : buffer_size_(0),
51 max_buffer_size_(buffer_size), 49 max_buffer_size_(buffer_size),
52 max_megabits_per_second_(max_megabits_per_second), 50 max_megabits_per_second_(max_megabits_per_second),
53 weak_factory_(this) { 51 weak_factory_(this) {}
54 CHECK_GT(max_buffer_size_, 0UL);
55 CHECK_GT(max_megabits_per_second, 0);
56 }
57 52
58 virtual void Send(scoped_ptr<transport::Packet> packet) OVERRIDE { 53 virtual void Send(scoped_ptr<transport::Packet> packet) OVERRIDE {
59 if (packet->size() + buffer_size_ <= max_buffer_size_) { 54 if (packet->size() + buffer_size_ <= max_buffer_size_) {
60 buffer_size_ += packet->size(); 55 buffer_size_ += packet->size();
61 buffer_.push_back(linked_ptr<transport::Packet>(packet.release())); 56 buffer_.push_back(linked_ptr<transport::Packet>(packet.release()));
62 if (buffer_.size() == 1) { 57 if (buffer_.size() == 1) {
63 Schedule(); 58 Schedule();
64 } 59 }
65 } 60 }
66 } 61 }
(...skipping 26 matching lines...) Expand all
93 double max_megabits_per_second_; // megabits per second 88 double max_megabits_per_second_; // megabits per second
94 base::WeakPtrFactory<Buffer> weak_factory_; 89 base::WeakPtrFactory<Buffer> weak_factory_;
95 }; 90 };
96 91
97 scoped_ptr<PacketPipe> NewBuffer(size_t buffer_size, double bandwidth) { 92 scoped_ptr<PacketPipe> NewBuffer(size_t buffer_size, double bandwidth) {
98 return scoped_ptr<PacketPipe>(new Buffer(buffer_size, bandwidth)).Pass(); 93 return scoped_ptr<PacketPipe>(new Buffer(buffer_size, bandwidth)).Pass();
99 } 94 }
100 95
101 class RandomDrop : public PacketPipe { 96 class RandomDrop : public PacketPipe {
102 public: 97 public:
103 RandomDrop(double drop_fraction) 98 RandomDrop(double drop_fraction) : drop_fraction_(drop_fraction) {
104 : drop_fraction_(static_cast<int>(drop_fraction * RAND_MAX)) {} 99 }
105 100
106 virtual void Send(scoped_ptr<transport::Packet> packet) OVERRIDE { 101 virtual void Send(scoped_ptr<transport::Packet> packet) OVERRIDE {
107 if (rand() > drop_fraction_) { 102 if (base::RandDouble() >= drop_fraction_) {
108 pipe_->Send(packet.Pass()); 103 pipe_->Send(packet.Pass());
109 } 104 }
110 } 105 }
111 106
112 private: 107 private:
113 int drop_fraction_; 108 double drop_fraction_;
114 }; 109 };
115 110
116 scoped_ptr<PacketPipe> NewRandomDrop(double drop_fraction) { 111 scoped_ptr<PacketPipe> NewRandomDrop(double drop_fraction) {
117 return scoped_ptr<PacketPipe>(new RandomDrop(drop_fraction)).Pass(); 112 return scoped_ptr<PacketPipe>(new RandomDrop(drop_fraction)).Pass();
118 } 113 }
119 114
120 class SimpleDelayBase : public PacketPipe { 115 class SimpleDelayBase : public PacketPipe {
121 public: 116 public:
122 SimpleDelayBase() : weak_factory_(this) {} 117 SimpleDelayBase() : weak_factory_(this) {}
123 virtual ~SimpleDelayBase() {} 118 virtual ~SimpleDelayBase() {}
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 destination, 579 destination,
585 to_dest_pipe.Pass(), 580 to_dest_pipe.Pass(),
586 from_dest_pipe.Pass(), 581 from_dest_pipe.Pass(),
587 net_log)); 582 net_log));
588 return ret.Pass(); 583 return ret.Pass();
589 } 584 }
590 585
591 } // namespace test 586 } // namespace test
592 } // namespace cast 587 } // namespace cast
593 } // namespace media 588 } // namespace media
OLDNEW
« no previous file with comments | « trunk/src/media/cast/test/utility/test_util.cc ('k') | trunk/src/media/cast/video_sender/fake_software_video_encoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698