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

Side by Side Diff: media/cast/video_receiver/video_receiver.h

Issue 280993002: [Cast] Repair receiver playout time calculations and frame skip logic. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed hubbe's comments. Created 6 years, 7 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 2013 The Chromium Authors. All rights reserved. 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 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 #ifndef MEDIA_CAST_VIDEO_RECEIVER_VIDEO_RECEIVER_H_ 5 #ifndef MEDIA_CAST_VIDEO_RECEIVER_VIDEO_RECEIVER_H_
6 #define MEDIA_CAST_VIDEO_RECEIVER_VIDEO_RECEIVER_H_ 6 #define MEDIA_CAST_VIDEO_RECEIVER_VIDEO_RECEIVER_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 23 matching lines...) Expand all
34 // VideoReceiver receives packets out-of-order while clients make requests for 34 // VideoReceiver receives packets out-of-order while clients make requests for
35 // complete frames in-order. (A frame consists of one or more packets.) 35 // complete frames in-order. (A frame consists of one or more packets.)
36 // 36 //
37 // VideoReceiver also includes logic for computing the playout time for each 37 // VideoReceiver also includes logic for computing the playout time for each
38 // frame, accounting for a constant targeted playout delay. The purpose of the 38 // frame, accounting for a constant targeted playout delay. The purpose of the
39 // playout delay is to provide a fixed window of time between the capture event 39 // playout delay is to provide a fixed window of time between the capture event
40 // on the sender and the playout on the receiver. This is important because 40 // on the sender and the playout on the receiver. This is important because
41 // each step of the pipeline (i.e., encode frame, then transmit/retransmit from 41 // each step of the pipeline (i.e., encode frame, then transmit/retransmit from
42 // the sender, then receive and re-order packets on the receiver, then decode 42 // the sender, then receive and re-order packets on the receiver, then decode
43 // frame) can vary in duration and is typically very hard to predict. 43 // frame) can vary in duration and is typically very hard to predict.
44 // Heuristics will determine when the targeted playout delay is insufficient in
45 // the current environment; and the receiver can then increase the playout
46 // delay, notifying the sender, to account for the extra variance.
47 // TODO(miu): Make the last sentence true. http://crbug.com/360111
48 // 44 //
49 // Two types of frames can be requested: 1) A frame of decoded video data; or 2) 45 // Two types of frames can be requested: 1) A frame of decoded video data; or 2)
50 // a frame of still-encoded video data, to be passed into an external video 46 // a frame of still-encoded video data, to be passed into an external video
51 // decoder. Each request for a frame includes a callback which VideoReceiver 47 // decoder. Each request for a frame includes a callback which VideoReceiver
52 // guarantees will be called at some point in the future unless the 48 // guarantees will be called at some point in the future unless the
53 // VideoReceiver is destroyed. Clients should generally limit the number of 49 // VideoReceiver is destroyed. Clients should generally limit the number of
54 // outstanding requests (perhaps to just one or two). 50 // outstanding requests (perhaps to just one or two).
55 // 51 //
56 // This class is not thread safe. Should only be called from the Main cast 52 // This class is not thread safe. Should only be called from the Main cast
57 // thread. 53 // thread.
(...skipping 17 matching lines...) Expand all
75 // Request an encoded video frame. 71 // Request an encoded video frame.
76 // 72 //
77 // The given |callback| is guaranteed to be run at some point in the future, 73 // The given |callback| is guaranteed to be run at some point in the future,
78 // even if to respond with NULL at shutdown time. 74 // even if to respond with NULL at shutdown time.
79 void GetEncodedVideoFrame(const VideoFrameEncodedCallback& callback); 75 void GetEncodedVideoFrame(const VideoFrameEncodedCallback& callback);
80 76
81 // Deliver another packet, possibly a duplicate, and possibly out-of-order. 77 // Deliver another packet, possibly a duplicate, and possibly out-of-order.
82 void IncomingPacket(scoped_ptr<Packet> packet); 78 void IncomingPacket(scoped_ptr<Packet> packet);
83 79
84 protected: 80 protected:
85 friend class VideoReceiverTest; // Invoked OnReceivedPayloadData(). 81 friend class VideoReceiverTest; // Invokes OnReceivedPayloadData().
86 82
87 virtual void OnReceivedPayloadData(const uint8* payload_data, 83 virtual void OnReceivedPayloadData(const uint8* payload_data,
88 size_t payload_size, 84 size_t payload_size,
89 const RtpCastHeader& rtp_header) OVERRIDE; 85 const RtpCastHeader& rtp_header) OVERRIDE;
90 86
91 // RtpPayloadFeedback implementation. 87 // RtpPayloadFeedback implementation.
92 virtual void CastFeedback(const RtcpCastMessage& cast_message) OVERRIDE; 88 virtual void CastFeedback(const RtcpCastMessage& cast_message) OVERRIDE;
93 89
94 private: 90 private:
95 // Processes ready-to-consume packets from |framer_|, decrypting each packet's 91 // Processes ready-to-consume packets from |framer_|, decrypting each packet's
96 // payload data, and then running the enqueued callbacks in order (one for 92 // payload data, and then running the enqueued callbacks in order (one for
97 // each packet). This method may post a delayed task to re-invoke itself in 93 // each packet). This method may post a delayed task to re-invoke itself in
98 // the future to wait for missing/incomplete frames. 94 // the future to wait for missing/incomplete frames.
99 void EmitAvailableEncodedFrames(); 95 void EmitAvailableEncodedFrames();
100 96
97 // Helper used by EmitAvailableEncodedFrames() to schedule itself to be called
98 // again after |wait_time| has elapsed.
99 void RetryEmitAfterWaiting(base::TimeDelta wait_time);
100
101 // Clears the |is_waiting_for_consecutive_frame_| flag and invokes 101 // Clears the |is_waiting_for_consecutive_frame_| flag and invokes
102 // EmitAvailableEncodedFrames(). 102 // EmitAvailableEncodedFrames().
103 void EmitAvailableEncodedFramesAfterWaiting(); 103 void EmitAvailableEncodedFramesAfterWaiting();
104 104
105 // Feeds an EncodedVideoFrame into |video_decoder_|. GetRawVideoFrame() uses 105 // Feeds an EncodedVideoFrame into |video_decoder_|. GetRawVideoFrame() uses
106 // this as a callback for GetEncodedVideoFrame(). 106 // this as a callback for GetEncodedVideoFrame().
107 void DecodeEncodedVideoFrame( 107 void DecodeEncodedVideoFrame(
108 const VideoFrameDecodedCallback& callback, 108 const VideoFrameDecodedCallback& callback,
109 scoped_ptr<transport::EncodedVideoFrame> encoded_frame, 109 scoped_ptr<transport::EncodedVideoFrame> encoded_frame,
110 const base::TimeTicks& playout_time); 110 const base::TimeTicks& playout_time);
111 111
112 // Return the playout time based on the current time and rtp timestamp. 112 // Computes the playout time for a frame with the given |rtp_timestamp|. If
113 base::TimeTicks GetPlayoutTime(base::TimeTicks now, uint32 rtp_timestamp); 113 // lip-sync info is not available, a best-guess is returned (a hack).
114 114 base::TimeTicks GetPlayoutTime(uint32 rtp_timestamp) const;
115 void InitializeTimers();
116 115
117 // Schedule timing for the next cast message. 116 // Schedule timing for the next cast message.
118 void ScheduleNextCastMessage(); 117 void ScheduleNextCastMessage();
119 118
120 // Schedule timing for the next RTCP report. 119 // Schedule timing for the next RTCP report.
121 void ScheduleNextRtcpReport(); 120 void ScheduleNextRtcpReport();
122 121
123 // Actually send the next cast message. 122 // Actually send the next cast message.
124 void SendNextCastMessage(); 123 void SendNextCastMessage();
125 124
(...skipping 13 matching lines...) Expand all
139 const base::TimeTicks& playout_time, 138 const base::TimeTicks& playout_time,
140 const scoped_refptr<VideoFrame>& video_frame, 139 const scoped_refptr<VideoFrame>& video_frame,
141 bool is_continuous); 140 bool is_continuous);
142 141
143 const scoped_refptr<CastEnvironment> cast_environment_; 142 const scoped_refptr<CastEnvironment> cast_environment_;
144 143
145 // Subscribes to raw events. 144 // Subscribes to raw events.
146 // Processes raw audio events to be sent over to the cast sender via RTCP. 145 // Processes raw audio events to be sent over to the cast sender via RTCP.
147 ReceiverRtcpEventSubscriber event_subscriber_; 146 ReceiverRtcpEventSubscriber event_subscriber_;
148 147
148 // Configured audio codec.
149 const transport::VideoCodec codec_; 149 const transport::VideoCodec codec_;
150 const base::TimeDelta target_delay_delta_; 150
151 // The total amount of time between a frame's capture/recording on the sender
152 // and its playback on the receiver (i.e., shown to a user). This is fixed as
153 // a value large enough to give the system sufficient time to encode,
154 // transmit/retransmit, receive, decode, and render; given its run-time
155 // environment (sender/receiver hardware performance, network conditions,
156 // etc.).
157 const base::TimeDelta target_playout_delay_;
158
159 // Hack: This is used in logic that: 1) determines whether to skip frames; and
160 // 2) guesses playout times before lip-sync info is available.
151 const base::TimeDelta expected_frame_duration_; 161 const base::TimeDelta expected_frame_duration_;
162
163 // Set to false initially, then set to true after scheduling the periodic
164 // sending of reports back to the sender. Reports are first scheduled just
165 // after receiving a first packet (since the first packet identifies the
166 // sender for the remainder of the session).
167 bool reports_are_scheduled_;
168
169 // Assembles packets into frames, providing this receiver with complete,
170 // decodable EncodedFrames.
152 Framer framer_; 171 Framer framer_;
172
173 // Decodes frames into media::VideoFrame images for playback.
153 scoped_ptr<VideoDecoder> video_decoder_; 174 scoped_ptr<VideoDecoder> video_decoder_;
175
176 // Manages sending/receiving of RTCP packets, including sender/receiver
177 // reports.
154 Rtcp rtcp_; 178 Rtcp rtcp_;
155 base::TimeDelta time_offset_; // Sender-receiver offset estimation. 179
156 int time_offset_counter_; 180 // Decrypts encrypted frames.
157 bool time_incoming_packet_updated_;
158 base::TimeTicks time_incoming_packet_;
159 uint32 incoming_rtp_timestamp_;
160 transport::TransportEncryptionHandler decryptor_; 181 transport::TransportEncryptionHandler decryptor_;
161 182
162 // Outstanding callbacks to run to deliver on client requests for frames. 183 // Outstanding callbacks to run to deliver on client requests for frames.
163 std::list<VideoFrameEncodedCallback> frame_request_queue_; 184 std::list<VideoFrameEncodedCallback> frame_request_queue_;
164 185
165 // True while there's an outstanding task to re-invoke 186 // True while there's an outstanding task to re-invoke
166 // EmitAvailableEncodedFrames(). 187 // EmitAvailableEncodedFrames().
167 bool is_waiting_for_consecutive_frame_; 188 bool is_waiting_to_emit_frames_;
168 189
169 // This mapping allows us to log FRAME_ACK_SENT as a frame event. In addition 190 // This mapping allows us to log FRAME_ACK_SENT as a frame event. In addition
170 // it allows the event to be transmitted via RTCP. 191 // it allows the event to be transmitted via RTCP.
171 RtpTimestamp frame_id_to_rtp_timestamp_[256]; 192 RtpTimestamp frame_id_to_rtp_timestamp_[256];
172 193
173 // NOTE: Weak pointers must be invalidated before all other member variables. 194 // NOTE: Weak pointers must be invalidated before all other member variables.
174 base::WeakPtrFactory<VideoReceiver> weak_factory_; 195 base::WeakPtrFactory<VideoReceiver> weak_factory_;
175 196
176 DISALLOW_COPY_AND_ASSIGN(VideoReceiver); 197 DISALLOW_COPY_AND_ASSIGN(VideoReceiver);
177 }; 198 };
178 199
179 } // namespace cast 200 } // namespace cast
180 } // namespace media 201 } // namespace media
181 202
182 #endif // MEDIA_CAST_VIDEO_RECEIVER_VIDEO_RECEIVER_H_ 203 #endif // MEDIA_CAST_VIDEO_RECEIVER_VIDEO_RECEIVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698