This source file includes following definitions.
- video_track_
- Start
- Stop
- Play
- Pause
- OnReadyStateChanged
- OnEnabledChanged
- OnVideoFrame
- RenderSignalingFrame
#include "content/renderer/media/rtc_video_renderer.h"
#include "base/debug/trace_event.h"
#include "base/message_loop/message_loop_proxy.h"
#include "media/base/video_frame.h"
#include "media/base/video_util.h"
const int kMinFrameSize = 2;
namespace content {
RTCVideoRenderer::RTCVideoRenderer(
const blink::WebMediaStreamTrack& video_track,
const base::Closure& error_cb,
const RepaintCB& repaint_cb)
: error_cb_(error_cb),
repaint_cb_(repaint_cb),
message_loop_proxy_(base::MessageLoopProxy::current()),
state_(STOPPED),
frame_size_(kMinFrameSize, kMinFrameSize),
video_track_(video_track) {
}
RTCVideoRenderer::~RTCVideoRenderer() {
}
void RTCVideoRenderer::Start() {
DCHECK(message_loop_proxy_->BelongsToCurrentThread());
DCHECK_EQ(state_, STOPPED);
AddToVideoTrack(this, video_track_);
state_ = STARTED;
if (video_track_.source().readyState() ==
blink::WebMediaStreamSource::ReadyStateEnded ||
!video_track_.isEnabled()) {
RenderSignalingFrame();
}
}
void RTCVideoRenderer::Stop() {
DCHECK(message_loop_proxy_->BelongsToCurrentThread());
DCHECK(state_ == STARTED || state_ == PAUSED);
RemoveFromVideoTrack(this, video_track_);
state_ = STOPPED;
frame_size_.set_width(kMinFrameSize);
frame_size_.set_height(kMinFrameSize);
}
void RTCVideoRenderer::Play() {
DCHECK(message_loop_proxy_->BelongsToCurrentThread());
if (state_ == PAUSED) {
state_ = STARTED;
}
}
void RTCVideoRenderer::Pause() {
DCHECK(message_loop_proxy_->BelongsToCurrentThread());
if (state_ == STARTED) {
state_ = PAUSED;
}
}
void RTCVideoRenderer::OnReadyStateChanged(
blink::WebMediaStreamSource::ReadyState state) {
DCHECK(message_loop_proxy_->BelongsToCurrentThread());
if (state == blink::WebMediaStreamSource::ReadyStateEnded)
RenderSignalingFrame();
}
void RTCVideoRenderer::OnEnabledChanged(bool enabled) {
DCHECK(message_loop_proxy_->BelongsToCurrentThread());
if (!enabled)
RenderSignalingFrame();
}
void RTCVideoRenderer::OnVideoFrame(
const scoped_refptr<media::VideoFrame>& frame) {
DCHECK(message_loop_proxy_->BelongsToCurrentThread());
if (state_ != STARTED) {
return;
}
frame_size_ = frame->natural_size();
TRACE_EVENT_INSTANT1("rtc_video_renderer",
"OnVideoFrame",
TRACE_EVENT_SCOPE_THREAD,
"timestamp",
frame->GetTimestamp().InMilliseconds());
repaint_cb_.Run(frame);
}
void RTCVideoRenderer::RenderSignalingFrame() {
scoped_refptr<media::VideoFrame> video_frame =
media::VideoFrame::CreateBlackFrame(frame_size_);
OnVideoFrame(video_frame);
}
}