| 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/webrtc/webrtc_video_track_adapter.h" | 5 #include "content/renderer/media/webrtc/webrtc_video_track_adapter.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 // WebRtcVideoTrackAdapter can be destroyed on the main render thread or | 42 // WebRtcVideoTrackAdapter can be destroyed on the main render thread or |
| 43 // libjingles worker thread since it posts video frames on that thread. But | 43 // libjingles worker thread since it posts video frames on that thread. But |
| 44 // |video_source_| must be released on the main render thread before the | 44 // |video_source_| must be released on the main render thread before the |
| 45 // PeerConnectionFactory has been destroyed. The only way to ensure that is | 45 // PeerConnectionFactory has been destroyed. The only way to ensure that is |
| 46 // to make sure |video_source_| is released when WebRtcVideoTrackAdapter() is | 46 // to make sure |video_source_| is released when WebRtcVideoTrackAdapter() is |
| 47 // destroyed. | 47 // destroyed. |
| 48 void ReleaseSourceOnMainThread(); | 48 void ReleaseSourceOnMainThread(); |
| 49 | 49 |
| 50 void OnVideoFrameOnIO(const scoped_refptr<media::VideoFrame>& frame, | 50 void OnVideoFrameOnIO(const scoped_refptr<media::VideoFrame>& frame, |
| 51 const base::TimeTicks& estimated_capture_time); | 51 base::TimeTicks estimated_capture_time); |
| 52 | 52 |
| 53 private: | 53 private: |
| 54 void OnVideoFrameOnWorkerThread( | 54 void OnVideoFrameOnWorkerThread( |
| 55 const scoped_refptr<media::VideoFrame>& frame); | 55 const scoped_refptr<media::VideoFrame>& frame); |
| 56 friend class base::RefCountedThreadSafe<WebRtcVideoSourceAdapter>; | 56 friend class base::RefCountedThreadSafe<WebRtcVideoSourceAdapter>; |
| 57 virtual ~WebRtcVideoSourceAdapter(); | 57 virtual ~WebRtcVideoSourceAdapter(); |
| 58 | 58 |
| 59 scoped_refptr<base::SingleThreadTaskRunner> render_thread_task_runner_; | 59 scoped_refptr<base::SingleThreadTaskRunner> render_thread_task_runner_; |
| 60 | 60 |
| 61 // |render_thread_checker_| is bound to the main render thread. | 61 // |render_thread_checker_| is bound to the main render thread. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 // on that thread. However, since |video_source_| was created on the render | 107 // on that thread. However, since |video_source_| was created on the render |
| 108 // thread, it should be released on the render thread. | 108 // thread, it should be released on the render thread. |
| 109 base::AutoLock auto_lock(capture_adapter_stop_lock_); | 109 base::AutoLock auto_lock(capture_adapter_stop_lock_); |
| 110 // |video_source| owns |capture_adapter_|. | 110 // |video_source| owns |capture_adapter_|. |
| 111 capture_adapter_ = NULL; | 111 capture_adapter_ = NULL; |
| 112 video_source_ = NULL; | 112 video_source_ = NULL; |
| 113 } | 113 } |
| 114 | 114 |
| 115 void WebRtcVideoTrackAdapter::WebRtcVideoSourceAdapter::OnVideoFrameOnIO( | 115 void WebRtcVideoTrackAdapter::WebRtcVideoSourceAdapter::OnVideoFrameOnIO( |
| 116 const scoped_refptr<media::VideoFrame>& frame, | 116 const scoped_refptr<media::VideoFrame>& frame, |
| 117 const base::TimeTicks& estimated_capture_time) { | 117 base::TimeTicks estimated_capture_time) { |
| 118 DCHECK(io_thread_checker_.CalledOnValidThread()); | 118 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 119 libjingle_worker_thread_->PostTask( | 119 libjingle_worker_thread_->PostTask( |
| 120 FROM_HERE, | 120 FROM_HERE, |
| 121 base::Bind(&WebRtcVideoSourceAdapter::OnVideoFrameOnWorkerThread, | 121 base::Bind(&WebRtcVideoSourceAdapter::OnVideoFrameOnWorkerThread, |
| 122 this, | 122 this, |
| 123 frame)); | 123 frame)); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void | 126 void |
| 127 WebRtcVideoTrackAdapter::WebRtcVideoSourceAdapter::OnVideoFrameOnWorkerThread( | 127 WebRtcVideoTrackAdapter::WebRtcVideoSourceAdapter::OnVideoFrameOnWorkerThread( |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 RemoveFromVideoTrack(this, web_track_); | 175 RemoveFromVideoTrack(this, web_track_); |
| 176 source_adapter_->ReleaseSourceOnMainThread(); | 176 source_adapter_->ReleaseSourceOnMainThread(); |
| 177 } | 177 } |
| 178 | 178 |
| 179 void WebRtcVideoTrackAdapter::OnEnabledChanged(bool enabled) { | 179 void WebRtcVideoTrackAdapter::OnEnabledChanged(bool enabled) { |
| 180 DCHECK(thread_checker_.CalledOnValidThread()); | 180 DCHECK(thread_checker_.CalledOnValidThread()); |
| 181 video_track_->set_enabled(enabled); | 181 video_track_->set_enabled(enabled); |
| 182 } | 182 } |
| 183 | 183 |
| 184 } // namespace content | 184 } // namespace content |
| OLD | NEW |