| OLD | NEW |
| 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 #include "chrome/renderer/media/cast_rtp_stream.h" | 5 #include "chrome/renderer/media/cast_rtp_stream.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 } | 225 } |
| 226 | 226 |
| 227 // This static method is used to forward video frames to |frame_input|. | 227 // This static method is used to forward video frames to |frame_input|. |
| 228 static void OnVideoFrame( | 228 static void OnVideoFrame( |
| 229 // These parameters are already bound when callback is created. | 229 // These parameters are already bound when callback is created. |
| 230 const gfx::Size& expected_coded_size, | 230 const gfx::Size& expected_coded_size, |
| 231 const CastRtpStream::ErrorCallback& error_callback, | 231 const CastRtpStream::ErrorCallback& error_callback, |
| 232 const scoped_refptr<media::cast::VideoFrameInput> frame_input, | 232 const scoped_refptr<media::cast::VideoFrameInput> frame_input, |
| 233 // These parameters are passed for each frame. | 233 // These parameters are passed for each frame. |
| 234 const scoped_refptr<media::VideoFrame>& frame, | 234 const scoped_refptr<media::VideoFrame>& frame, |
| 235 const media::VideoCaptureFormat& format) { | 235 const media::VideoCaptureFormat& format, |
| 236 const base::TimeTicks& estimated_capture_time) { |
| 236 if (frame->coded_size() != expected_coded_size) { | 237 if (frame->coded_size() != expected_coded_size) { |
| 237 error_callback.Run("Video frame resolution does not match config."); | 238 error_callback.Run("Video frame resolution does not match config."); |
| 238 return; | 239 return; |
| 239 } | 240 } |
| 240 | 241 |
| 241 const base::TimeTicks now = base::TimeTicks::Now(); | 242 base::TimeTicks timestamp; |
| 243 if (estimated_capture_time.is_null()) |
| 244 timestamp = base::TimeTicks::Now(); |
| 245 else |
| 246 timestamp = estimated_capture_time; |
| 242 | 247 |
| 243 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc | 248 // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc |
| 244 TRACE_EVENT_INSTANT2( | 249 TRACE_EVENT_INSTANT2( |
| 245 "cast_perf_test", "MediaStreamVideoSink::OnVideoFrame", | 250 "cast_perf_test", "MediaStreamVideoSink::OnVideoFrame", |
| 246 TRACE_EVENT_SCOPE_THREAD, | 251 TRACE_EVENT_SCOPE_THREAD, |
| 247 "timestamp", now.ToInternalValue(), | 252 "timestamp", timestamp.ToInternalValue(), |
| 248 "time_delta", frame->timestamp().ToInternalValue()); | 253 "time_delta", frame->timestamp().ToInternalValue()); |
| 249 frame_input->InsertRawVideoFrame(frame, now); | 254 frame_input->InsertRawVideoFrame(frame, timestamp); |
| 250 } | 255 } |
| 251 | 256 |
| 252 // Attach this sink to a video track represented by |track_|. | 257 // Attach this sink to a video track represented by |track_|. |
| 253 // Data received from the track will be submitted to |frame_input|. | 258 // Data received from the track will be submitted to |frame_input|. |
| 254 void AddToTrack( | 259 void AddToTrack( |
| 255 const scoped_refptr<media::cast::VideoFrameInput>& frame_input) { | 260 const scoped_refptr<media::cast::VideoFrameInput>& frame_input) { |
| 256 DCHECK(!sink_added_); | 261 DCHECK(!sink_added_); |
| 257 sink_added_ = true; | 262 sink_added_ = true; |
| 258 AddToVideoTrack( | 263 AddToVideoTrack( |
| 259 this, | 264 this, |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 } | 539 } |
| 535 | 540 |
| 536 void CastRtpStream::DidEncounterError(const std::string& message) { | 541 void CastRtpStream::DidEncounterError(const std::string& message) { |
| 537 // Save the WeakPtr first because the error callback might delete this object. | 542 // Save the WeakPtr first because the error callback might delete this object. |
| 538 base::WeakPtr<CastRtpStream> ptr = weak_factory_.GetWeakPtr(); | 543 base::WeakPtr<CastRtpStream> ptr = weak_factory_.GetWeakPtr(); |
| 539 error_callback_.Run(message); | 544 error_callback_.Run(message); |
| 540 content::RenderThread::Get()->GetMessageLoop()->PostTask( | 545 content::RenderThread::Get()->GetMessageLoop()->PostTask( |
| 541 FROM_HERE, | 546 FROM_HERE, |
| 542 base::Bind(&CastRtpStream::Stop, ptr)); | 547 base::Bind(&CastRtpStream::Stop, ptr)); |
| 543 } | 548 } |
| OLD | NEW |