| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "content/renderer/media/video_track_adapter.h" | 5 #include "content/renderer/media/video_track_adapter.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 // |callback| will however be released on the main render thread. | 49 // |callback| will however be released on the main render thread. |
| 50 void AddCallback(const MediaStreamVideoTrack* track, | 50 void AddCallback(const MediaStreamVideoTrack* track, |
| 51 const VideoCaptureDeliverFrameCB& callback); | 51 const VideoCaptureDeliverFrameCB& callback); |
| 52 | 52 |
| 53 // Removes |callback| associated with |track| from receiving video frames if | 53 // Removes |callback| associated with |track| from receiving video frames if |
| 54 // |track| has been added. It is ok to call RemoveCallback even if the |track| | 54 // |track| has been added. It is ok to call RemoveCallback even if the |track| |
| 55 // has not been added. The |callback| is released on the main render thread. | 55 // has not been added. The |callback| is released on the main render thread. |
| 56 void RemoveCallback(const MediaStreamVideoTrack* track); | 56 void RemoveCallback(const MediaStreamVideoTrack* track); |
| 57 | 57 |
| 58 void DeliverFrame(const scoped_refptr<media::VideoFrame>& frame, | 58 void DeliverFrame(const scoped_refptr<media::VideoFrame>& frame, |
| 59 const media::VideoCaptureFormat& format); | 59 const media::VideoCaptureFormat& format, |
| 60 const base::TimeTicks& estimated_capture_time); |
| 60 | 61 |
| 61 // Returns true if all arguments match with the output of this adapter. | 62 // Returns true if all arguments match with the output of this adapter. |
| 62 bool ConstraintsMatch(int max_width, | 63 bool ConstraintsMatch(int max_width, |
| 63 int max_height, | 64 int max_height, |
| 64 double min_aspect_ratio, | 65 double min_aspect_ratio, |
| 65 double max_aspect_ratio) const; | 66 double max_aspect_ratio) const; |
| 66 | 67 |
| 67 bool IsEmpty() const; | 68 bool IsEmpty() const; |
| 68 | 69 |
| 69 private: | 70 private: |
| 70 virtual ~VideoFrameResolutionAdapter(); | 71 virtual ~VideoFrameResolutionAdapter(); |
| 71 friend class base::RefCountedThreadSafe<VideoFrameResolutionAdapter>; | 72 friend class base::RefCountedThreadSafe<VideoFrameResolutionAdapter>; |
| 72 | 73 |
| 73 virtual void DoDeliverFrame( | 74 virtual void DoDeliverFrame( |
| 74 const scoped_refptr<media::VideoFrame>& frame, | 75 const scoped_refptr<media::VideoFrame>& frame, |
| 75 const media::VideoCaptureFormat& format); | 76 const media::VideoCaptureFormat& format, |
| 77 const base::TimeTicks& estimated_capture_time); |
| 76 | 78 |
| 77 // Bound to the IO-thread. | 79 // Bound to the IO-thread. |
| 78 base::ThreadChecker io_thread_checker_; | 80 base::ThreadChecker io_thread_checker_; |
| 79 | 81 |
| 80 // The task runner where we will release VideoCaptureDeliverFrameCB | 82 // The task runner where we will release VideoCaptureDeliverFrameCB |
| 81 // registered in AddCallback. | 83 // registered in AddCallback. |
| 82 scoped_refptr<base::SingleThreadTaskRunner> renderer_task_runner_; | 84 scoped_refptr<base::SingleThreadTaskRunner> renderer_task_runner_; |
| 83 | 85 |
| 84 gfx::Size max_frame_size_; | 86 gfx::Size max_frame_size_; |
| 85 double min_aspect_ratio_; | 87 double min_aspect_ratio_; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 115 } | 117 } |
| 116 | 118 |
| 117 VideoTrackAdapter:: | 119 VideoTrackAdapter:: |
| 118 VideoFrameResolutionAdapter::~VideoFrameResolutionAdapter() { | 120 VideoFrameResolutionAdapter::~VideoFrameResolutionAdapter() { |
| 119 DCHECK(io_thread_checker_.CalledOnValidThread()); | 121 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 120 DCHECK(callbacks_.empty()); | 122 DCHECK(callbacks_.empty()); |
| 121 } | 123 } |
| 122 | 124 |
| 123 void VideoTrackAdapter::VideoFrameResolutionAdapter::DeliverFrame( | 125 void VideoTrackAdapter::VideoFrameResolutionAdapter::DeliverFrame( |
| 124 const scoped_refptr<media::VideoFrame>& frame, | 126 const scoped_refptr<media::VideoFrame>& frame, |
| 125 const media::VideoCaptureFormat& format) { | 127 const media::VideoCaptureFormat& format, |
| 128 const base::TimeTicks& estimated_capture_time) { |
| 126 DCHECK(io_thread_checker_.CalledOnValidThread()); | 129 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 127 // TODO(perkj): Allow cropping / scaling of textures once | 130 // TODO(perkj): Allow cropping / scaling of textures once |
| 128 // http://crbug/362521 is fixed. | 131 // http://crbug/362521 is fixed. |
| 129 if (frame->format() == media::VideoFrame::NATIVE_TEXTURE) { | 132 if (frame->format() == media::VideoFrame::NATIVE_TEXTURE) { |
| 130 DoDeliverFrame(frame, format); | 133 DoDeliverFrame(frame, format, estimated_capture_time); |
| 131 return; | 134 return; |
| 132 } | 135 } |
| 133 scoped_refptr<media::VideoFrame> video_frame(frame); | 136 scoped_refptr<media::VideoFrame> video_frame(frame); |
| 134 double input_ratio = | 137 double input_ratio = |
| 135 static_cast<double>(frame->natural_size().width()) / | 138 static_cast<double>(frame->natural_size().width()) / |
| 136 frame->natural_size().height(); | 139 frame->natural_size().height(); |
| 137 | 140 |
| 138 // If |frame| has larger width or height than requested, or the aspect ratio | 141 // If |frame| has larger width or height than requested, or the aspect ratio |
| 139 // does not match the requested, we want to create a wrapped version of this | 142 // does not match the requested, we want to create a wrapped version of this |
| 140 // frame with a size that fulfills the constraints. | 143 // frame with a size that fulfills the constraints. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 region_in_frame, | 185 region_in_frame, |
| 183 desired_size, | 186 desired_size, |
| 184 base::Bind(&ReleaseOriginalFrame, frame)); | 187 base::Bind(&ReleaseOriginalFrame, frame)); |
| 185 | 188 |
| 186 DVLOG(3) << "desired size " << desired_size.ToString() | 189 DVLOG(3) << "desired size " << desired_size.ToString() |
| 187 << " output natural size " | 190 << " output natural size " |
| 188 << video_frame->natural_size().ToString() | 191 << video_frame->natural_size().ToString() |
| 189 << " output visible rect " | 192 << " output visible rect " |
| 190 << video_frame->visible_rect().ToString(); | 193 << video_frame->visible_rect().ToString(); |
| 191 } | 194 } |
| 192 DoDeliverFrame(video_frame, format); | 195 DoDeliverFrame(video_frame, format, estimated_capture_time); |
| 193 } | 196 } |
| 194 | 197 |
| 195 void VideoTrackAdapter:: | 198 void VideoTrackAdapter:: |
| 196 VideoFrameResolutionAdapter::DoDeliverFrame( | 199 VideoFrameResolutionAdapter::DoDeliverFrame( |
| 197 const scoped_refptr<media::VideoFrame>& frame, | 200 const scoped_refptr<media::VideoFrame>& frame, |
| 198 const media::VideoCaptureFormat& format) { | 201 const media::VideoCaptureFormat& format, |
| 202 const base::TimeTicks& estimated_capture_time) { |
| 199 DCHECK(io_thread_checker_.CalledOnValidThread()); | 203 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 200 for (std::vector<VideoIdCallbackPair>::const_iterator it = callbacks_.begin(); | 204 for (std::vector<VideoIdCallbackPair>::const_iterator it = callbacks_.begin(); |
| 201 it != callbacks_.end(); ++it) { | 205 it != callbacks_.end(); ++it) { |
| 202 it->second.Run(frame, format); | 206 it->second.Run(frame, format, estimated_capture_time); |
| 203 } | 207 } |
| 204 } | 208 } |
| 205 | 209 |
| 206 void VideoTrackAdapter::VideoFrameResolutionAdapter::AddCallback( | 210 void VideoTrackAdapter::VideoFrameResolutionAdapter::AddCallback( |
| 207 const MediaStreamVideoTrack* track, | 211 const MediaStreamVideoTrack* track, |
| 208 const VideoCaptureDeliverFrameCB& callback) { | 212 const VideoCaptureDeliverFrameCB& callback) { |
| 209 DCHECK(io_thread_checker_.CalledOnValidThread()); | 213 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 210 callbacks_.push_back(std::make_pair(track, callback)); | 214 callbacks_.push_back(std::make_pair(track, callback)); |
| 211 } | 215 } |
| 212 | 216 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 (*it)->RemoveCallback(track); | 320 (*it)->RemoveCallback(track); |
| 317 if ((*it)->IsEmpty()) { | 321 if ((*it)->IsEmpty()) { |
| 318 adapters_.erase(it); | 322 adapters_.erase(it); |
| 319 break; | 323 break; |
| 320 } | 324 } |
| 321 } | 325 } |
| 322 } | 326 } |
| 323 | 327 |
| 324 void VideoTrackAdapter::DeliverFrameOnIO( | 328 void VideoTrackAdapter::DeliverFrameOnIO( |
| 325 const scoped_refptr<media::VideoFrame>& frame, | 329 const scoped_refptr<media::VideoFrame>& frame, |
| 326 const media::VideoCaptureFormat& format) { | 330 const media::VideoCaptureFormat& format, |
| 331 const base::TimeTicks& estimated_capture_time) { |
| 327 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 332 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 328 TRACE_EVENT0("video", "VideoTrackAdapter::DeliverFrameOnIO"); | 333 TRACE_EVENT0("video", "VideoTrackAdapter::DeliverFrameOnIO"); |
| 329 for (FrameAdapters::iterator it = adapters_.begin(); | 334 for (FrameAdapters::iterator it = adapters_.begin(); |
| 330 it != adapters_.end(); ++it) { | 335 it != adapters_.end(); ++it) { |
| 331 (*it)->DeliverFrame(frame, format); | 336 (*it)->DeliverFrame(frame, format, estimated_capture_time); |
| 332 } | 337 } |
| 333 } | 338 } |
| 334 | 339 |
| 335 } // namespace content | 340 } // namespace content |
| OLD | NEW |