1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137

media / gpu / vaapi / vaapi_common.h [blame]

// Copyright 2018 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_GPU_VAAPI_VAAPI_COMMON_H_
#define MEDIA_GPU_VAAPI_VAAPI_COMMON_H_

#include "build/chromeos_buildflags.h"
#include "media/gpu/av1_picture.h"
#include "media/gpu/h264_dpb.h"
#include "media/gpu/vaapi/vaapi_utils.h"
#include "media/gpu/vp8_picture.h"
#include "media/gpu/vp9_picture.h"
#include "media/media_buildflags.h"

#if BUILDFLAG(ENABLE_HEVC_PARSER_AND_HW_DECODER)
#include "media/gpu/h265_dpb.h"
#endif  // BUILDFLAG(ENABLE_HEVC_PARSER_AND_HW_DECODER)

namespace media {

// These picture classes derive from platform-independent, codec-specific
// classes to allow augmenting them with VA-API-specific traits; used when
// providing associated hardware resources and parameters to VA-API drivers.

class VaapiH264Picture : public H264Picture {
 public:
  explicit VaapiH264Picture(std::unique_ptr<VASurfaceHandle> va_surface);

  VaapiH264Picture(const VaapiH264Picture&) = delete;
  VaapiH264Picture& operator=(const VaapiH264Picture&) = delete;

  VaapiH264Picture* AsVaapiH264Picture() override;

  VASurfaceID va_surface_id() const { return va_surface_->id(); }

 protected:
  ~VaapiH264Picture() override;

 private:
  std::unique_ptr<VASurfaceHandle> va_surface_;
};

#if BUILDFLAG(ENABLE_HEVC_PARSER_AND_HW_DECODER)
class VaapiH265Picture : public H265Picture {
 public:
  explicit VaapiH265Picture(std::unique_ptr<VASurfaceHandle> va_surface);

  VaapiH265Picture(const VaapiH265Picture&) = delete;
  VaapiH265Picture& operator=(const VaapiH265Picture&) = delete;

  VaapiH265Picture* AsVaapiH265Picture() override;

  VASurfaceID va_surface_id() const { return va_surface_->id(); }

 protected:
  ~VaapiH265Picture() override;

 private:
  std::unique_ptr<VASurfaceHandle> va_surface_;
};
#endif  // BUILDFLAG(ENABLE_HEVC_PARSER_AND_HW_DECODER)

class VaapiVP8Picture : public VP8Picture {
 public:
  explicit VaapiVP8Picture(std::unique_ptr<VASurfaceHandle> va_surface);

  VaapiVP8Picture(const VaapiVP8Picture&) = delete;
  VaapiVP8Picture& operator=(const VaapiVP8Picture&) = delete;

  VaapiVP8Picture* AsVaapiVP8Picture() override;

  VASurfaceID va_surface_id() const { return va_surface_->id(); }

 protected:
  ~VaapiVP8Picture() override;

 private:
  std::unique_ptr<VASurfaceHandle> va_surface_;
};

class VaapiVP9Picture : public VP9Picture {
 public:
  explicit VaapiVP9Picture(std::unique_ptr<VASurfaceHandle> va_surface);

  VaapiVP9Picture(const VaapiVP9Picture&) = delete;
  VaapiVP9Picture& operator=(const VaapiVP9Picture&) = delete;

  VaapiVP9Picture* AsVaapiVP9Picture() override;

  VASurfaceID va_surface_id() const { return va_surface_->id(); }

 protected:
  ~VaapiVP9Picture() override;

 private:
  scoped_refptr<VP9Picture> CreateDuplicate() override;

  std::unique_ptr<VASurfaceHandle> va_surface_;
};

class VaapiAV1Picture : public AV1Picture {
 public:
  VaapiAV1Picture(std::unique_ptr<VASurfaceHandle> display_va_surface,
                  std::unique_ptr<VASurfaceHandle> reconstruct_va_surface);
  VaapiAV1Picture(const VaapiAV1Picture&) = delete;
  VaapiAV1Picture& operator=(const VaapiAV1Picture&) = delete;

  VASurfaceID display_va_surface_id() const {
    return display_va_surface_->id();
  }
  VASurfaceID reconstruct_va_surface_id() const {
    return reconstruct_va_surface_->id();
  }

 protected:
  ~VaapiAV1Picture() override;

 private:
  scoped_refptr<AV1Picture> CreateDuplicate() override;

  // |display_va_surface_| refers to the final decoded frame, both when using
  // film grain synthesis and when not using film grain.
  // |reconstruct_va_surface_| is only useful when using film grain synthesis:
  // it's the decoded frame prior to applying the film grain.
  // When not using film grain synthesis, |reconstruct_va_surface_| is equal to
  // |display_va_surface_|. This is necessary to simplify the reference frame
  // code when filling the VA-API structures and to be able to always use
  // reconstruct_va_surface() when calling ExecuteAndDestroyPendingBuffers()
  // (the driver expects the reconstructed surface as the target in the case
  // of film grain synthesis).
  std::unique_ptr<VASurfaceHandle> display_va_surface_;
  std::unique_ptr<VASurfaceHandle> reconstruct_va_surface_;
};

}  // namespace media

#endif  // MEDIA_GPU_VAAPI_VAAPI_COMMON_H_