-// Copyright 2014 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MEDIA_BASE_RENDERER_H_
#define MEDIA_BASE_RENDERER_H_
-#include "base/callback.h"
-#include "base/macros.h"
-#include "base/memory/ref_counted.h"
+#include "base/functional/callback.h"
#include "base/time/time.h"
#include "media/base/buffering_state.h"
-#include "media/base/cdm_context.h"
#include "media/base/demuxer_stream.h"
#include "media/base/media_export.h"
#include "media/base/pipeline_status.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
+
+#if defined(TIZEN_VIDEO_HOLE)
+#include "ui/gfx/geometry/rect_f.h"
+#endif
namespace media {
+class CdmContext;
class MediaResource;
class RendererClient;
+#if defined(TIZEN_MULTIMEDIA)
+namespace mojom {
+enum class HardwareResourceConfig;
+}
+#endif
+
+// Types of media::Renderer.
+// WARNING: These values are reported to metrics. Entries should not be
+// renumbered and numeric values should not be reused. When adding new entries,
+// also update media::mojom::RendererType & tools/metrics/histograms/enums.xml.
+enum class RendererType {
+ kRendererImpl = 0, // RendererImplFactory
+ kMojo = 1, // MojoRendererFactory
+ kMediaPlayer = 2, // MediaPlayerRendererClientFactory
+ kCourier = 3, // CourierRendererFactory
+ kFlinging = 4, // FlingingRendererClientFactory
+ kCast = 5, // CastRendererClientFactory
+ kMediaFoundation = 6, // MediaFoundationRendererClientFactory
+ // kFuchsia = 7, // Deprecated
+ kRemoting = 8, // RemotingRendererFactory for remoting::Receiver
+ kCastStreaming = 9, // PlaybackCommandForwardingRendererFactory
+ kContentEmbedderDefined = 10, // Defined by the content embedder
+ kTest = 11, // Renderer implementations used in tests
+ kMaxValue = kTest,
+};
+
+// Get the name of the Renderer for `renderer_type`. The returned name could be
+// the actual Renderer class name or a descriptive name.
+std::string MEDIA_EXPORT GetRendererName(RendererType renderer_type);
class MEDIA_EXPORT Renderer {
public:
Renderer();
+ Renderer(const Renderer&) = delete;
+ Renderer& operator=(const Renderer&) = delete;
+
// Stops rendering and fires any pending callbacks.
virtual ~Renderer();
// be run only prior to returning.
virtual void Initialize(MediaResource* media_resource,
RendererClient* client,
- const PipelineStatusCB& init_cb) = 0;
+ PipelineStatusCallback init_cb) = 0;
// Associates the |cdm_context| with this Renderer for decryption (and
- // decoding) of media data, then fires |cdm_attached_cb| with the result.
- virtual void SetCdm(CdmContext* cdm_context,
- const CdmAttachedCB& cdm_attached_cb) = 0;
+ // decoding) of media data, then fires |cdm_attached_cb| with whether the
+ // operation succeeded.
+ using CdmAttachedCB = base::OnceCallback<void(bool)>;
+ virtual void SetCdm(CdmContext* cdm_context, CdmAttachedCB cdm_attached_cb);
+
+ // Specifies a latency hint from the site. Renderers should clamp the hint
+ // value to reasonable min and max and use the resulting value as a target
+ // latency such that the buffering state reaches HAVE_ENOUGH when this amount
+ // of decoded data is buffered. A nullopt hint indicates the user is clearing
+ // their preference and the renderer should restore its default buffering
+ // thresholds.
+ virtual void SetLatencyHint(absl::optional<base::TimeDelta> latency_hint) = 0;
+
+ // Sets whether pitch adjustment should be applied when the playback rate is
+ // different than 1.0.
+ virtual void SetPreservesPitch(bool preserves_pitch);
+
+ // Sets a flag indicating whether the audio stream was played with user
+ // activation.
+ virtual void SetWasPlayedWithUserActivation(
+ bool was_played_with_user_activation);
// The following functions must be called after Initialize().
// Discards any buffered data, executing |flush_cb| when completed.
- virtual void Flush(const base::Closure& flush_cb) = 0;
+ virtual void Flush(base::OnceClosure flush_cb) = 0;
+
+#if defined(TIZEN_MULTIMEDIA)
+ virtual void Seek(base::TimeDelta time, base::OnceClosure seek_cb) {}
+ virtual void Suspend() {}
+ virtual void EnableLowLatencyMode() {}
+ using SetHardwareResourceCB = base::OnceCallback<void(bool)>;
+ virtual void SetHardwareResource(media::mojom::HardwareResourceConfig config,
+ SetHardwareResourceCB cb) {}
+ using RequestVideoDecodedBufferCB = base::OnceCallback<void(bool)>;
+ virtual void RequestVideoDecodedBuffer(RequestVideoDecodedBufferCB cb) {}
+ using ToggledFullscreenCB = base::OnceCallback<void()>;
+ virtual void ToggleFullscreenMode(bool is_fullscreen,
+ ToggledFullscreenCB cb) {}
+#endif
+
+#if defined(TIZEN_VIDEO_HOLE)
+ virtual void SetPlayerVideoAbove(int32_t other_id) {}
+ virtual void UseSubsurfaceController() {}
+ virtual void SetVideoHole(bool is_video_hole) {}
+ virtual void SetMediaGeometry(const gfx::RectF& rect,
+ media::VideoRotation rotation) {}
+#endif
+
+ using StartDateCB = base::OnceCallback<void(double)>;
+#if BUILDFLAG(IS_TIZEN_TV)
+ using GetVideoIdCB = base::OnceCallback<void(int32_t)>;
+ virtual void GetVideoId(GetVideoIdCB cb) {}
+ virtual void SetContentMimeType(const std::string& mime_type) {}
+ virtual void AudioTracksCountChanged(unsigned count) {}
+ virtual void SetParentalRatingResult(bool is_pass) {}
+ virtual void SetActiveTextTrack(int id, bool is_in_band) {}
+ virtual void SetActiveAudioTrack(int index) {}
+ virtual void SetActiveVideoTrack(int index) {}
+ virtual void SetPreferTextLanguage(const std::string& lang) {}
+ virtual void GetStartDate(StartDateCB cb) {}
+ virtual void DestroyPlayerSync(base::OnceClosure cb) {}
+#endif
// Starts rendering from |time|.
virtual void StartPlayingFrom(base::TimeDelta time) = 0;
virtual void SetVolume(float volume) = 0;
// Returns the current media time.
+ //
+ // This method must be safe to call from any thread.
virtual base::TimeDelta GetMediaTime() = 0;
// Provides a list of DemuxerStreams correlating to the tracks which should
const std::vector<DemuxerStream*>& enabled_tracks,
base::OnceClosure change_completed_cb);
- private:
- DISALLOW_COPY_AND_ASSIGN(Renderer);
+ // Signal to the renderer that there has been a client request to access a
+ // VideoFrame. This signal may be used by the renderer to ensure it is
+ // operating in a mode which produces a VideoFrame usable by the client.
+ // E.g., the MediaFoundationRendererClient on Windows has two modes
+ // of operation: Frame Server & Direct Composition. Direct Composition mode
+ // does not produce a VideoFrame with an accessible 'data' buffer, so clients
+ // cannot access the underlying image data. In order for
+ // MediaFoundationRendererClient to produce a VideoFrame with 'data'
+ // accessible by the client it must switch to operate in Frame Server mode.
+ virtual void OnExternalVideoFrameRequest();
+
+ // Returns the type of the Renderer implementation. Marked as pure virtual to
+ // enforce RendererType registration for all Renderer implementations.
+ // Note: New implementation should update RendererType.
+ virtual RendererType GetRendererType() = 0;
};
} // namespace media