// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_WEBCODECS_VIDEO_DECODER_BROKER_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBCODECS_VIDEO_DECODER_BROKER_H_ #include <memory> #include <optional> #include <string> #include <vector> #include "base/functional/callback.h" #include "base/memory/scoped_refptr.h" #include "base/memory/weak_ptr.h" #include "base/sequence_checker.h" #include "media/base/decoder_status.h" #include "media/base/video_decoder.h" #include "media/base/video_frame.h" #include "media/video/gpu_video_accelerator_factories.h" #include "third_party/blink/renderer/core/execution_context/execution_context.h" #include "third_party/blink/renderer/modules/modules_export.h" #include "third_party/blink/renderer/modules/webcodecs/hardware_preference.h" #include "third_party/blink/renderer/platform/wtf/hash_map.h" namespace base { class SequencedTaskRunner; } // namespace base namespace blink { // Implementation detail of VideoDecoderBroker. Helps safely perform decoder // tasks on the media thread. class MediaVideoTaskWrapper; // Client interface for MediaVideoTaskWrapper. Implementation detail of // VideoDecoderBroker, but we need to define it here to implement it below. // // This avoids having pass-through callbacks from main->media task sequence, // which is unsafe because the public callers of broker APIs may be broken if // their callback is destructed on another thread. // // An int "cb_id" is used for those that are traditionally OnceCallbacks to // lookup the correct public callback. class CrossThreadVideoDecoderClient { … }; // This class brokers the connection between WebCodecs and an underlying // media::VideoDecoder. It abstracts away details of construction and selection // of the media/ decoder. It also handles thread-hopping as required by // underlying APIS. // // A new underlying decoder is selected anytime Initialize() is called. // TODO(chcunningham): Elide re-selection if the config has not significantly // changed. // // All API calls and callbacks must occur on the main thread. class MODULES_EXPORT VideoDecoderBroker : public media::VideoDecoder, public CrossThreadVideoDecoderClient { … }; } // namespace blink #endif // THIRD_PARTY_BLINK_RENDERER_MODULES_WEBCODECS_VIDEO_DECODER_BROKER_H_