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

Side by Side Diff: media/cast/test/utility/in_process_receiver.h

Issue 184813009: Cast Streaming API end-to-end browser_test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix LoggingImplTest + REBASE Created 6 years, 9 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
(Empty)
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.
4
5 #ifndef MEDIA_CAST_TEST_IN_PROCESS_RECEIVER_H_
6 #define MEDIA_CAST_TEST_IN_PROCESS_RECEIVER_H_
7
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "media/cast/cast_config.h"
12 #include "media/cast/transport/cast_transport_config.h"
13
14 namespace base {
15 class TimeTicks;
16 } // namespace base
17
18 namespace net {
19 class IPEndPoint;
20 } // namespace net
21
22 namespace media {
23
24 class VideoFrame;
25
26 namespace cast {
27
28 class CastEnvironment;
29 class CastReceiver;
30
31 namespace transport {
32 class UdpTransport;
33 } // namespace transport
34
35 // Common base functionality for an in-process Cast receiver. This is meant to
36 // be subclassed with the OnAudioFrame() and OnVideoFrame() methods implemented,
37 // so that the implementor can focus on what is to be done with the frames,
38 // rather than on the boilerplate "glue" code.
39 class InProcessReceiver {
40 public:
41 // Construct a receiver with the given configuration. |remote_end_point| can
42 // be left empty, if the transport should automatically mate with the first
43 // remote sender it encounters.
44 InProcessReceiver(const scoped_refptr<CastEnvironment>& cast_environment,
45 const net::IPEndPoint& local_end_point,
46 const net::IPEndPoint& remote_end_point,
47 const AudioReceiverConfig& audio_config,
48 const VideoReceiverConfig& video_config);
49
50 // Must be destroyed on the cast MAIN thread. See DestroySoon().
51 virtual ~InProcessReceiver();
52
53 // Convenience accessor to CastEnvironment.
54 scoped_refptr<CastEnvironment> cast_env() const { return cast_environment_; }
55
56 // Begin delivering any received audio/video frames to the OnXXXFrame()
57 // methods.
58 void Start();
59
60 // Schedules destruction on the cast MAIN thread. Any external references to
61 // the InProcessReceiver instance become invalid.
62 void DestroySoon();
63
64 protected:
65 // To be implemented by subclasses. These are called on the Cast MAIN thread
66 // as each frame is received.
67 virtual void OnAudioFrame(scoped_ptr<PcmAudioFrame> audio_frame,
68 const base::TimeTicks& playout_time) = 0;
69 virtual void OnVideoFrame(const scoped_refptr<VideoFrame>& video_frame,
70 const base::TimeTicks& render_time) = 0;
71
72 // Helper method that creates |transport_| and |cast_receiver_|, starts
73 // |transport_| receiving, and requests the first audio/video frame.
74 // Subclasses may override to provide additional start-up functionality.
75 virtual void StartOnMainThread();
76
77 // Callback for the transport to notify of status changes. A default
78 // implementation is provided here that simply logs socket errors.
79 virtual void UpdateCastTransportStatus(transport::CastTransportStatus status);
80
81 private:
82 friend class base::RefCountedThreadSafe<InProcessReceiver>;
83
84 // CastReceiver callbacks that receive a frame and then request another.
85 void GotAudioFrame(scoped_ptr<PcmAudioFrame> audio_frame,
86 const base::TimeTicks& playout_time);
87 void GotVideoFrame(const scoped_refptr<VideoFrame>& video_frame,
88 const base::TimeTicks& render_time);
89 void PullNextAudioFrame();
90 void PullNextVideoFrame();
91
92 // Invoked just before the destruction of |receiver| on the cast MAIN thread.
93 static void WillDestroyReceiver(InProcessReceiver* receiver);
94
95 const scoped_refptr<CastEnvironment> cast_environment_;
96 const net::IPEndPoint local_end_point_;
97 const net::IPEndPoint remote_end_point_;
98 const AudioReceiverConfig audio_config_;
99 const VideoReceiverConfig video_config_;
100
101 scoped_ptr<transport::UdpTransport> transport_;
102 scoped_ptr<CastReceiver> cast_receiver_;
103
104 // For shutdown safety, this member must be last:
105 base::WeakPtrFactory<InProcessReceiver> weak_factory_;
106
107 DISALLOW_COPY_AND_ASSIGN(InProcessReceiver);
108 };
109
110 } // namespace cast
111 } // namespace media
112
113 #endif // MEDIA_CAST_TEST_IN_PROCESS_RECEIVER_H_
OLDNEW
« no previous file with comments | « media/cast/test/utility/default_config.cc ('k') | media/cast/test/utility/in_process_receiver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698