Refactor management of overview window copy lifetime into a separate class.
[chromium-blink-merge.git] / media / cast / video_receiver / video_receiver.h
blob8b14aae566a05d82a1cfc2e81ba79c00dcb1e544
1 // Copyright 2013 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_VIDEO_RECEIVER_VIDEO_RECEIVER_H_
6 #define MEDIA_CAST_VIDEO_RECEIVER_VIDEO_RECEIVER_H_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/threading/non_thread_safe.h"
14 #include "base/time/tick_clock.h"
15 #include "base/time/time.h"
16 #include "media/cast/cast_config.h"
17 #include "media/cast/cast_environment.h"
18 #include "media/cast/cast_receiver.h"
19 #include "media/cast/rtcp/rtcp.h"
20 #include "media/cast/rtp_common/rtp_defines.h"
21 #include "media/cast/rtp_receiver/rtp_receiver.h"
23 namespace media {
24 namespace cast {
26 class Framer;
27 class LocalRtpVideoData;
28 class LocalRtpVideoFeedback;
29 class PacedPacketSender;
30 class PeerVideoReceiver;
31 class Rtcp;
32 class RtpReceiverStatistics;
33 class VideoDecoder;
36 // Should only be called from the Main cast thread.
37 class VideoReceiver : public base::NonThreadSafe,
38 public base::SupportsWeakPtr<VideoReceiver> {
39 public:
40 VideoReceiver(scoped_refptr<CastEnvironment> cast_environment,
41 const VideoReceiverConfig& video_config,
42 PacedPacketSender* const packet_sender);
44 virtual ~VideoReceiver();
46 // Request a raw frame. Will return frame via callback when available.
47 void GetRawVideoFrame(const VideoFrameDecodedCallback& callback);
49 // Request an encoded frame. Will return frame via callback when available.
50 void GetEncodedVideoFrame(const VideoFrameEncodedCallback& callback);
52 // Insert a RTP packet to the video receiver.
53 void IncomingPacket(const uint8* packet, size_t length,
54 const base::Closure callback);
56 protected:
57 void IncomingRtpPacket(const uint8* payload_data,
58 size_t payload_size,
59 const RtpCastHeader& rtp_header);
61 void DecodeVideoFrameThread(
62 scoped_ptr<EncodedVideoFrame> encoded_frame,
63 const base::TimeTicks render_time,
64 const VideoFrameDecodedCallback& frame_decoded_callback);
66 private:
67 friend class LocalRtpVideoData;
68 friend class LocalRtpVideoFeedback;
70 void CastFeedback(const RtcpCastMessage& cast_message);
71 void RequestKeyFrame();
73 void DecodeVideoFrame(const VideoFrameDecodedCallback& callback,
74 scoped_ptr<EncodedVideoFrame> encoded_frame,
75 const base::TimeTicks& render_time);
77 bool PullEncodedVideoFrame(uint32 rtp_timestamp,
78 bool next_frame,
79 scoped_ptr<EncodedVideoFrame>* encoded_frame,
80 base::TimeTicks* render_time);
82 void PlayoutTimeout();
84 // Returns Render time based on current time and the rtp timestamp.
85 base::TimeTicks GetRenderTime(base::TimeTicks now, uint32 rtp_timestamp);
87 // Schedule timing for the next cast message.
88 void ScheduleNextCastMessage();
90 // Schedule timing for the next RTCP report.
91 void ScheduleNextRtcpReport();
93 // Actually send the next cast message.
94 void SendNextCastMessage();
96 // Actually send the next RTCP report.
97 void SendNextRtcpReport();
99 scoped_ptr<VideoDecoder> video_decoder_;
100 scoped_refptr<CastEnvironment> cast_environment_;
101 scoped_ptr<Framer> framer_;
102 const VideoCodec codec_;
103 const uint32 incoming_ssrc_;
104 base::TimeDelta target_delay_delta_;
105 base::TimeDelta frame_delay_;
106 scoped_ptr<LocalRtpVideoData> incoming_payload_callback_;
107 scoped_ptr<LocalRtpVideoFeedback> incoming_payload_feedback_;
108 RtpReceiver rtp_receiver_;
109 scoped_ptr<Rtcp> rtcp_;
110 scoped_ptr<RtpReceiverStatistics> rtp_video_receiver_statistics_;
111 base::TimeTicks time_last_sent_cast_message_;
112 // Sender-receiver offset estimation.
113 base::TimeDelta time_offset_;
115 std::list<VideoFrameEncodedCallback> queued_encoded_callbacks_;
117 base::WeakPtrFactory<VideoReceiver> weak_factory_;
119 DISALLOW_COPY_AND_ASSIGN(VideoReceiver);
122 } // namespace cast
123 } // namespace media
125 #endif // MEDIA_CAST_VIDEO_RECEIVER_VIDEO_RECEIVER_H_