blob: 310772944aa26fee0a7c34aec8af3c380d7fc846 [file] [log] [blame]
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/time/time.h"
#include "content/common/content_export.h"
#include "media/capture/video_capturer_source.h"
#include "third_party/blink/public/common/media/video_capture.h"
#include "third_party/blink/public/platform/modules/mediastream/web_media_stream_sink.h"
#include "third_party/blink/public/platform/web_media_stream_track.h"
namespace content {
// MediaStreamVideoSink is a base class that contains implementation commonly
// useful for implementations of blink::WebMediaStreamSink which
// connect/disconnect the sink implementation to a track to start/stop the flow
// of video frames.
// All methods calls must be made from the main render thread.
class CONTENT_EXPORT MediaStreamVideoSink : public blink::WebMediaStreamSink {
void OnFrameDropped(media::VideoCaptureFrameDropReason reason);
~MediaStreamVideoSink() override;
// A subclass should call ConnectToTrack when it is ready to receive data from
// a video track. Before destruction, DisconnectFromTrack must be called.
// This base class holds a reference to the WebMediaStreamTrack until
// DisconnectFromTrack is called.
// Calls to these methods must be done on the main render thread.
// Note that |callback| for frame delivery happens on the IO thread.
// Warning: Calling DisconnectFromTrack does not immediately stop frame
// delivery through the |callback|, since frames are being delivered on a
// different thread.
// |is_sink_secure| indicates if this MediaStreamVideoSink is secure (i.e.
// meets output protection requirement). Generally, this should be false
// unless you know what you are doing.
void ConnectToTrack(const blink::WebMediaStreamTrack& track,
const blink::VideoCaptureDeliverFrameCB& callback,
bool is_sink_secure);
void DisconnectFromTrack();
// Returns the currently-connected track, or a null instance otherwise.
const blink::WebMediaStreamTrack& connected_track() const {
return connected_track_;
// Set by ConnectToTrack() and cleared by DisconnectFromTrack().
blink::WebMediaStreamTrack connected_track_;
} // namespace content