webrtc_m130/modules/desktop_capture/desktop_capturer.h
Alex Cooper 86015a6610 Reland "Add plumbing to control PipeWire picker visibility"
This reverts commit 0098a441e3990f80bcbe05dfce8c6e2359f7ef25.

Reason for revert: Fix chromium build break

Original change's description:
> Revert "Add plumbing to control PipeWire picker visibility"
>
> This reverts commit fbea8c519684577a38cb35b9287ba4645a905094.
>
> Reason for revert: Breaks WebRTC import into Chromium, e.g:
> https://chromium-review.googlesource.com/c/chromium/src/+/3863998/
>
> Original change's description:
> > Add plumbing to control PipeWire picker visibility
> >
> > Introduces the notion of a "delegated source list" and corresponding
> > controller. This is used by desktop capturers (currently just the
> > PipeWire capturer), who control selecting the source through their own
> > (often system-level) UI, rather than returning a source list with all
> > available options that can then be selected by the embedder.
> >
> > Adds a method to get the controller which serves to also tell embedders
> > if the capturer makes use of a delegated source list. The controller
> > currently allows the embedder to request that the delegated source list
> > be shown or hidden, and will in the future be used to expose events
> > from the source list (e.g. selection, dismissal, error).
> >
> > Bug: chromium:1351572
> > Change-Id: Ie1d36ed654013f59b8d9095deef01a4705fd5bde
> > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/272621
> > Reviewed-by: Mark Foltz <mfoltz@chromium.org>
> > Commit-Queue: Alexander Cooper <alcooper@chromium.org>
> > Cr-Commit-Position: refs/heads/main@{#37956}
>
> Bug: chromium:1351572
> Change-Id: I06f76ab9c8bc1aa303dae177d48698951fdc5ecd
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/273703
> Auto-Submit: Henrik Boström <hbos@webrtc.org>
> Reviewed-by: Henrik Andreassson <henrika@webrtc.org>
> Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com>
> Reviewed-by: Henrik Boström <hbos@webrtc.org>
> Commit-Queue: Henrik Andreassson <henrika@webrtc.org>
> Cr-Commit-Position: refs/heads/main@{#37964}

Bug: chromium:1351572
Change-Id: I9e5e691746b81517bf0e211d0ad5a23371ab29ba
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/273685
Reviewed-by: Mark Foltz <mfoltz@chromium.org>
Auto-Submit: Alexander Cooper <alcooper@chromium.org>
Commit-Queue: Mark Foltz <mfoltz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#37972}
2022-08-31 20:59:19 +00:00

221 lines
8.5 KiB
C++

/*
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef MODULES_DESKTOP_CAPTURE_DESKTOP_CAPTURER_H_
#define MODULES_DESKTOP_CAPTURE_DESKTOP_CAPTURER_H_
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <string>
#include <type_traits>
#include <vector>
#if defined(WEBRTC_USE_GIO)
#include "modules/desktop_capture/desktop_capture_metadata.h"
#endif // defined(WEBRTC_USE_GIO)
#include "modules/desktop_capture/desktop_capture_types.h"
#include "modules/desktop_capture/desktop_frame.h"
#include "modules/desktop_capture/shared_memory.h"
#include "rtc_base/system/rtc_export.h"
namespace webrtc {
class DesktopCaptureOptions;
class DesktopFrame;
// A controller to be implemented and returned by
// GetDelegatedSourceListController in capturers that require showing their own
// source list and managing user selection there. Apart from ensuring the
// visibility of the source list, these capturers should largely be interacted
// with the same as a normal capturer, though there may be some caveats for
// some DesktopCapturer methods. See GetDelegatedSourceListController for more
// information.
class RTC_EXPORT DelegatedSourceListController {
public:
// Used to prompt the capturer to show the delegated source list. If the
// source list is already visible, this will be a no-op. Must be called after
// starting the DesktopCapturer.
//
// Note that any selection from a previous invocation of the source list may
// be cleared when this method is called.
virtual void EnsureVisible() = 0;
// Used to prompt the capturer to hide the delegated source list. If the
// source list is already hidden, this will be a no-op.
virtual void EnsureHidden() = 0;
protected:
virtual ~DelegatedSourceListController() {}
};
// Abstract interface for screen and window capturers.
class RTC_EXPORT DesktopCapturer {
public:
enum class Result {
// The frame was captured successfully.
SUCCESS,
// There was a temporary error. The caller should continue calling
// CaptureFrame(), in the expectation that it will eventually recover.
ERROR_TEMPORARY,
// Capture has failed and will keep failing if the caller tries calling
// CaptureFrame() again.
ERROR_PERMANENT,
MAX_VALUE = ERROR_PERMANENT
};
// Interface that must be implemented by the DesktopCapturer consumers.
class Callback {
public:
// Called after a frame has been captured. `frame` is not nullptr if and
// only if `result` is SUCCESS.
virtual void OnCaptureResult(Result result,
std::unique_ptr<DesktopFrame> frame) = 0;
protected:
virtual ~Callback() {}
};
#if defined(CHROMEOS)
typedef int64_t SourceId;
#else
typedef intptr_t SourceId;
#endif
static_assert(std::is_same<SourceId, ScreenId>::value,
"SourceId should be a same type as ScreenId.");
struct Source {
// The unique id to represent a Source of current DesktopCapturer.
SourceId id;
// Title of the window or screen in UTF-8 encoding, maybe empty. This field
// should not be used to identify a source.
std::string title;
};
typedef std::vector<Source> SourceList;
virtual ~DesktopCapturer();
// Called at the beginning of a capturing session. `callback` must remain
// valid until capturer is destroyed.
virtual void Start(Callback* callback) = 0;
// Returns a valid pointer if the capturer requires the user to make a
// selection from a source list provided by the capturer.
// Returns nullptr if the capturer does not provide a UI for the user to make
// a selection.
//
// Callers should not take ownership of the returned pointer, but it is
// guaranteed to be valid as long as the desktop_capturer is valid.
// Note that consumers should still use GetSourceList and SelectSource, but
// their behavior may be modified if this returns a value. See those methods
// for a more in-depth discussion of those potential modifications.
virtual DelegatedSourceListController* GetDelegatedSourceListController();
// Sets SharedMemoryFactory that will be used to create buffers for the
// captured frames. The factory can be invoked on a thread other than the one
// where CaptureFrame() is called. It will be destroyed on the same thread.
// Shared memory is currently supported only by some DesktopCapturer
// implementations.
virtual void SetSharedMemoryFactory(
std::unique_ptr<SharedMemoryFactory> shared_memory_factory);
// Captures next frame, and involve callback provided by Start() function.
// Pending capture requests are canceled when DesktopCapturer is deleted.
virtual void CaptureFrame() = 0;
// Sets the window to be excluded from the captured image in the future
// Capture calls. Used to exclude the screenshare notification window for
// screen capturing.
virtual void SetExcludedWindow(WindowId window);
// TODO(zijiehe): Following functions should be pure virtual. The default
// implementations are for backward compatibility only. Remove default
// implementations once all DesktopCapturer implementations in Chromium have
// implemented these functions.
// Gets a list of sources current capturer supports. Returns false in case of
// a failure.
// For DesktopCapturer implementations to capture screens, this function
// should return monitors.
// For DesktopCapturer implementations to capture windows, this function
// should only return root windows owned by applications.
//
// Note that capturers who use a delegated source list will return a
// SourceList with exactly one value, but it may not be viable for capture
// (e.g. CaptureFrame will return ERROR_TEMPORARY) until a selection has been
// made.
virtual bool GetSourceList(SourceList* sources);
// Selects a source to be captured. Returns false in case of a failure (e.g.
// if there is no source with the specified type and id.)
//
// Note that some capturers with delegated source lists may also support
// selecting a SourceID that is not in the returned source list as a form of
// restore token.
virtual bool SelectSource(SourceId id);
// Brings the selected source to the front and sets the input focus on it.
// Returns false in case of a failure or no source has been selected or the
// implementation does not support this functionality.
virtual bool FocusOnSelectedSource();
// Returns true if the `pos` on the selected source is covered by other
// elements on the display, and is not visible to the users.
// `pos` is in full desktop coordinates, i.e. the top-left monitor always
// starts from (0, 0).
// The return value if `pos` is out of the scope of the source is undefined.
virtual bool IsOccluded(const DesktopVector& pos);
// Creates a DesktopCapturer instance which targets to capture windows.
static std::unique_ptr<DesktopCapturer> CreateWindowCapturer(
const DesktopCaptureOptions& options);
// Creates a DesktopCapturer instance which targets to capture screens.
static std::unique_ptr<DesktopCapturer> CreateScreenCapturer(
const DesktopCaptureOptions& options);
#if defined(WEBRTC_USE_PIPEWIRE) || defined(WEBRTC_USE_X11)
static bool IsRunningUnderWayland();
virtual void UpdateResolution(uint32_t width, uint32_t height) {}
#endif // defined(WEBRTC_USE_PIPEWIRE) || defined(WEBRTC_USE_X11)
#if defined(WEBRTC_USE_GIO)
// Populates implementation specific metadata into the passed in pointer.
// Classes can choose to override it or use the default no-op implementation.
virtual DesktopCaptureMetadata GetMetadata() { return {}; }
#endif // defined(WEBRTC_USE_GIO)
protected:
// CroppingWindowCapturer needs to create raw capturers without wrappers, so
// the following two functions are protected.
// Creates a platform specific DesktopCapturer instance which targets to
// capture windows.
static std::unique_ptr<DesktopCapturer> CreateRawWindowCapturer(
const DesktopCaptureOptions& options);
// Creates a platform specific DesktopCapturer instance which targets to
// capture screens.
static std::unique_ptr<DesktopCapturer> CreateRawScreenCapturer(
const DesktopCaptureOptions& options);
};
} // namespace webrtc
#endif // MODULES_DESKTOP_CAPTURE_DESKTOP_CAPTURER_H_