| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/rtc_video_renderer.h" | 5 #include "content/renderer/media/rtc_video_renderer.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop_proxy.h" | 7 #include "base/message_loop/message_loop_proxy.h" |
| 8 #include "base/trace_event/trace_event.h" | 8 #include "base/trace_event/trace_event.h" |
| 9 #include "media/base/bind_to_current_loop.h" | 9 #include "media/base/bind_to_current_loop.h" |
| 10 #include "media/base/video_frame.h" | 10 #include "media/base/video_frame.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 DCHECK(state_ == STARTED || state_ == PAUSED); | 55 DCHECK(state_ == STARTED || state_ == PAUSED); |
| 56 RemoveFromVideoTrack(this, video_track_); | 56 RemoveFromVideoTrack(this, video_track_); |
| 57 weak_factory_.InvalidateWeakPtrs(); | 57 weak_factory_.InvalidateWeakPtrs(); |
| 58 state_ = STOPPED; | 58 state_ = STOPPED; |
| 59 frame_size_.set_width(kMinFrameSize); | 59 frame_size_.set_width(kMinFrameSize); |
| 60 frame_size_.set_height(kMinFrameSize); | 60 frame_size_.set_height(kMinFrameSize); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void RTCVideoRenderer::Play() { | 63 void RTCVideoRenderer::Play() { |
| 64 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 64 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 65 if (state_ == PAUSED) { | 65 if (state_ == PAUSED) |
| 66 state_ = STARTED; | 66 state_ = STARTED; |
| 67 } | |
| 68 } | 67 } |
| 69 | 68 |
| 70 void RTCVideoRenderer::Pause() { | 69 void RTCVideoRenderer::Pause() { |
| 71 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 70 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 72 if (state_ == STARTED) { | 71 if (state_ == STARTED) |
| 73 state_ = PAUSED; | 72 state_ = PAUSED; |
| 74 } | |
| 75 } | 73 } |
| 76 | 74 |
| 77 void RTCVideoRenderer::OnReadyStateChanged( | 75 void RTCVideoRenderer::OnReadyStateChanged( |
| 78 blink::WebMediaStreamSource::ReadyState state) { | 76 blink::WebMediaStreamSource::ReadyState state) { |
| 79 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 77 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 80 if (state == blink::WebMediaStreamSource::ReadyStateEnded) | 78 if (state == blink::WebMediaStreamSource::ReadyStateEnded) |
| 81 RenderSignalingFrame(); | 79 RenderSignalingFrame(); |
| 82 } | 80 } |
| 83 | 81 |
| 84 void RTCVideoRenderer::OnVideoFrame( | 82 void RTCVideoRenderer::OnVideoFrame( |
| 85 const scoped_refptr<media::VideoFrame>& frame, | 83 const scoped_refptr<media::VideoFrame>& frame, |
| 86 const base::TimeTicks& estimated_capture_time) { | 84 const base::TimeTicks& estimated_capture_time) { |
| 87 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); | 85 DCHECK(message_loop_proxy_->BelongsToCurrentThread()); |
| 88 if (state_ != STARTED) { | 86 if (state_ != STARTED) |
| 89 return; | 87 return; |
| 90 } | |
| 91 | 88 |
| 92 frame_size_ = frame->natural_size(); | 89 frame_size_ = frame->natural_size(); |
| 93 | 90 |
| 94 TRACE_EVENT_INSTANT1("rtc_video_renderer", | 91 TRACE_EVENT_INSTANT1("rtc_video_renderer", |
| 95 "OnVideoFrame", | 92 "OnVideoFrame", |
| 96 TRACE_EVENT_SCOPE_THREAD, | 93 TRACE_EVENT_SCOPE_THREAD, |
| 97 "timestamp", | 94 "timestamp", |
| 98 frame->timestamp().InMilliseconds()); | 95 frame->timestamp().InMilliseconds()); |
| 99 repaint_cb_.Run(frame); | 96 repaint_cb_.Run(frame); |
| 100 } | 97 } |
| 101 | 98 |
| 102 void RTCVideoRenderer::RenderSignalingFrame() { | 99 void RTCVideoRenderer::RenderSignalingFrame() { |
| 103 // This is necessary to make sure audio can play if the video tag src is | 100 // This is necessary to make sure audio can play if the video tag src is |
| 104 // a MediaStream video track that has been rejected or ended. | 101 // a MediaStream video track that has been rejected or ended. |
| 105 // It also ensure that the renderer don't hold a reference to a real video | 102 // It also ensure that the renderer don't hold a reference to a real video |
| 106 // frame if no more frames are provided. This is since there might be a | 103 // frame if no more frames are provided. This is since there might be a |
| 107 // finite number of available buffers. E.g, video that | 104 // finite number of available buffers. E.g, video that |
| 108 // originates from a video camera. | 105 // originates from a video camera. |
| 109 scoped_refptr<media::VideoFrame> video_frame = | 106 scoped_refptr<media::VideoFrame> video_frame = |
| 110 media::VideoFrame::CreateBlackFrame(frame_size_); | 107 media::VideoFrame::CreateBlackFrame(frame_size_); |
| 111 OnVideoFrame(video_frame, base::TimeTicks()); | 108 OnVideoFrame(video_frame, base::TimeTicks()); |
| 112 } | 109 } |
| 113 | 110 |
| 114 } // namespace content | 111 } // namespace content |
| OLD | NEW |