Remove INJECT_EVENTS permissions from test APKs.
[chromium-blink-merge.git] / media / cast / test / utility / in_process_receiver.h
blob545699be31425c6c3406786c39da7be2d96eb2f0
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
3 // found in the LICENSE file.
5 #ifndef MEDIA_CAST_TEST_IN_PROCESS_RECEIVER_H_
6 #define MEDIA_CAST_TEST_IN_PROCESS_RECEIVER_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "media/base/audio_bus.h"
12 #include "media/cast/cast_config.h"
13 #include "media/cast/net/cast_transport_config.h"
14 #include "media/cast/net/cast_transport_sender.h"
15 #include "net/base/ip_endpoint.h"
17 namespace base {
18 class TimeTicks;
19 class WaitableEvent;
20 } // namespace base
22 namespace net {
23 class IPEndPoint;
24 } // namespace net
26 namespace media {
28 class VideoFrame;
30 namespace cast {
32 class CastEnvironment;
33 class CastReceiver;
34 class UdpTransport;
36 // Common base functionality for an in-process Cast receiver. This is meant to
37 // be subclassed with the OnAudioFrame() and OnVideoFrame() methods implemented,
38 // so that the implementor can focus on what is to be done with the frames,
39 // rather than on the boilerplate "glue" code.
40 class InProcessReceiver {
41 public:
42 // Construct a receiver with the given configuration. |remote_end_point| can
43 // be left empty, if the transport should automatically mate with the first
44 // remote sender it encounters.
45 InProcessReceiver(const scoped_refptr<CastEnvironment>& cast_environment,
46 const net::IPEndPoint& local_end_point,
47 const net::IPEndPoint& remote_end_point,
48 const FrameReceiverConfig& audio_config,
49 const FrameReceiverConfig& video_config);
51 virtual ~InProcessReceiver();
53 // Convenience accessors.
54 scoped_refptr<CastEnvironment> cast_env() const { return cast_environment_; }
55 const FrameReceiverConfig& audio_config() const { return audio_config_; }
56 const FrameReceiverConfig& video_config() const { return video_config_; }
58 // Begin delivering any received audio/video frames to the OnXXXFrame()
59 // methods.
60 virtual void Start();
62 // Destroy the sub-compontents of this class.
63 // After this call, it is safe to destroy this object on any thread.
64 virtual void Stop();
66 protected:
67 // To be implemented by subclasses. These are called on the Cast MAIN thread
68 // as each frame is received.
69 virtual void OnAudioFrame(scoped_ptr<AudioBus> audio_frame,
70 const base::TimeTicks& playout_time,
71 bool is_continuous) = 0;
72 virtual void OnVideoFrame(const scoped_refptr<VideoFrame>& video_frame,
73 const base::TimeTicks& playout_time,
74 bool is_continuous) = 0;
76 // Helper method that creates |transport_| and |cast_receiver_|, starts
77 // |transport_| receiving, and requests the first audio/video frame.
78 // Subclasses may final to provide additional start-up functionality.
79 virtual void StartOnMainThread();
81 // Helper method that destroys |transport_| and |cast_receiver_|.
82 // Subclasses may final to provide additional start-up functionality.
83 virtual void StopOnMainThread(base::WaitableEvent* event);
85 // Callback for the transport to notify of status changes. A default
86 // implementation is provided here that simply logs socket errors.
87 virtual void UpdateCastTransportStatus(CastTransportStatus status);
89 private:
90 friend class base::RefCountedThreadSafe<InProcessReceiver>;
92 // CastReceiver callbacks that receive a frame and then request another. See
93 // comments for the callbacks defined in src/media/cast/cast_receiver.h for
94 // argument description and semantics.
95 void GotAudioFrame(scoped_ptr<AudioBus> audio_frame,
96 const base::TimeTicks& playout_time,
97 bool is_continuous);
98 void GotVideoFrame(const scoped_refptr<VideoFrame>& video_frame,
99 const base::TimeTicks& playout_time,
100 bool is_continuous);
101 void PullNextAudioFrame();
102 void PullNextVideoFrame();
104 void ReceivePacket(scoped_ptr<Packet> packet);
106 const scoped_refptr<CastEnvironment> cast_environment_;
107 const net::IPEndPoint local_end_point_;
108 const net::IPEndPoint remote_end_point_;
109 const FrameReceiverConfig audio_config_;
110 const FrameReceiverConfig video_config_;
112 scoped_ptr<CastTransportSender> transport_;
113 scoped_ptr<CastReceiver> cast_receiver_;
115 // NOTE: Weak pointers must be invalidated before all other member variables.
116 base::WeakPtrFactory<InProcessReceiver> weak_factory_;
118 DISALLOW_COPY_AND_ASSIGN(InProcessReceiver);
121 } // namespace cast
122 } // namespace media
124 #endif // MEDIA_CAST_TEST_IN_PROCESS_RECEIVER_H_