chromium/third_party/blink/renderer/platform/peerconnection/stats_collecting_decoder.h

// Copyright 2022 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_PLATFORM_PEERCONNECTION_STATS_COLLECTING_DECODER_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_PEERCONNECTION_STATS_COLLECTING_DECODER_H_

#include "base/memory/raw_ptr.h"
#include "base/thread_annotations.h"
#include "base/time/time.h"
#include "third_party/blink/renderer/platform/peerconnection/stats_collector.h"
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/webrtc/api/video_codecs/sdp_video_format.h"
#include "third_party/webrtc/api/video_codecs/video_decoder.h"

namespace blink {

// This class acts as a wrapper around the WebRTC video decoder that is used in
// Chrome.
//
// Its purpose is to collect decode performance statistics for the current video
// stream. The performance statistics is pushed to a local database through a
// callback and is later used to determine if a specific video configuration is
// considered to be smooth or not, see
// https://w3c.github.io/media-capabilities/. Smooth will be an optimistic
// prediction and data collection therefore only takes place if there's a single
// decoder active.
//
// It's assumed that Configure(), Decode(), and RegisterDecodeCompleteCallback()
// are called on the decode sequence. Decoded() may be called on either the
// decode sequecene or the media sequence depending on if the underlying decoder
// is a HW or SW decoder. However, the calls to Decoded() on these sequences are
// mutual exclusive. Release() may be called on any sequence as long as the
// decoding sequence has stopped.
class PLATFORM_EXPORT StatsCollectingDecoder
    : private StatsCollector,
      public webrtc::VideoDecoder,
      private webrtc::DecodedImageCallback {};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_PEERCONNECTION_STATS_COLLECTING_DECODER_H_