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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
// Copyright 2013 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_VIDEO_RECEIVER_VIDEO_RECEIVER_H_
#define MEDIA_CAST_VIDEO_RECEIVER_VIDEO_RECEIVER_H_
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/non_thread_safe.h"
#include "base/time/tick_clock.h"
#include "base/time/time.h"
#include "media/cast/cast_config.h"
#include "media/cast/cast_environment.h"
#include "media/cast/cast_receiver.h"
#include "media/cast/rtcp/rtcp.h"
#include "media/cast/rtp_common/rtp_defines.h"
#include "media/cast/rtp_receiver/rtp_receiver.h"
namespace media {
namespace cast {
class Framer;
class LocalRtpVideoData;
class LocalRtpVideoFeedback;
class PacedPacketSender;
class PeerVideoReceiver;
class Rtcp;
class RtpReceiverStatistics;
class VideoDecoder;
// Should only be called from the Main cast thread.
class VideoReceiver : public base::NonThreadSafe,
public base::SupportsWeakPtr<VideoReceiver> {
public:
VideoReceiver(scoped_refptr<CastEnvironment> cast_environment,
const VideoReceiverConfig& video_config,
PacedPacketSender* const packet_sender);
virtual ~VideoReceiver();
// Request a raw frame. Will return frame via callback when available.
void GetRawVideoFrame(const VideoFrameDecodedCallback& callback);
// Request an encoded frame. Will return frame via callback when available.
void GetEncodedVideoFrame(const VideoFrameEncodedCallback& callback);
// Insert a RTP packet to the video receiver.
void IncomingPacket(const uint8* packet, size_t length,
const base::Closure callback);
protected:
void IncomingRtpPacket(const uint8* payload_data,
size_t payload_size,
const RtpCastHeader& rtp_header);
void DecodeVideoFrameThread(
scoped_ptr<EncodedVideoFrame> encoded_frame,
const base::TimeTicks render_time,
const VideoFrameDecodedCallback& frame_decoded_callback);
private:
friend class LocalRtpVideoData;
friend class LocalRtpVideoFeedback;
void CastFeedback(const RtcpCastMessage& cast_message);
void RequestKeyFrame();
void DecodeVideoFrame(const VideoFrameDecodedCallback& callback,
scoped_ptr<EncodedVideoFrame> encoded_frame,
const base::TimeTicks& render_time);
bool PullEncodedVideoFrame(uint32 rtp_timestamp,
bool next_frame,
scoped_ptr<EncodedVideoFrame>* encoded_frame,
base::TimeTicks* render_time);
void PlayoutTimeout();
// Returns Render time based on current time and the rtp timestamp.
base::TimeTicks GetRenderTime(base::TimeTicks now, uint32 rtp_timestamp);
// Schedule timing for the next cast message.
void ScheduleNextCastMessage();
// Schedule timing for the next RTCP report.
void ScheduleNextRtcpReport();
// Actually send the next cast message.
void SendNextCastMessage();
// Actually send the next RTCP report.
void SendNextRtcpReport();
scoped_ptr<VideoDecoder> video_decoder_;
scoped_refptr<CastEnvironment> cast_environment_;
scoped_ptr<Framer> framer_;
const VideoCodec codec_;
const uint32 incoming_ssrc_;
base::TimeDelta target_delay_delta_;
base::TimeDelta frame_delay_;
scoped_ptr<LocalRtpVideoData> incoming_payload_callback_;
scoped_ptr<LocalRtpVideoFeedback> incoming_payload_feedback_;
RtpReceiver rtp_receiver_;
scoped_ptr<Rtcp> rtcp_;
scoped_ptr<RtpReceiverStatistics> rtp_video_receiver_statistics_;
base::TimeTicks time_last_sent_cast_message_;
// Sender-receiver offset estimation.
base::TimeDelta time_offset_;
std::list<VideoFrameEncodedCallback> queued_encoded_callbacks_;
base::WeakPtrFactory<VideoReceiver> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(VideoReceiver);
};
} // namespace cast
} // namespace media
#endif // MEDIA_CAST_VIDEO_RECEIVER_VIDEO_RECEIVER_H_
|