Commit 89762a9e authored by Alexandre Courbot's avatar Alexandre Courbot Committed by Commit Bot

media/gpu/v4l2: move kernel-specific structures out of public sight

As we add support for the request API and upstream H264 structures, two
sets of V4L2 H264 controls/structures will have to coexist:

- The ones we used so far for our own kernels and the config store,
- The official upstream ones, relying on request API.

Thus we will need two versions of the V4L2H264Accelerator, each of which
will use a different set of kernel controls/structures. However these
kernel members share the same name and cannot be both included in the
same compilation unit: thus, we cannot have them included in any .h file
that the decoder will include, or name collision will occurs.

The CL takes care of this last point my moving all kernel-specific
definitions and includes into a private structure inside
v4l2_h264_accelerator.cc. That way, none of the kernel members are
visible to files that include v4l2_h264_accelerator.h, and we won't have
any name collision as we introduce the other accelerator class.

Bug: 917279
Test: vdatest passes on veyron_minnie.
Change-Id: I1601fccd37624244b3351e647c1c7e75f526f4a2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1705928
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: default avatarHirokazu Honda <hiroh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#678501}
parent 35944641
......@@ -4,6 +4,7 @@
#include "media/gpu/v4l2/v4l2_h264_accelerator.h"
#include <linux/videodev2.h>
#include <type_traits>
#include "base/logging.h"
......@@ -15,6 +16,17 @@
namespace media {
// This struct contains the kernel-specific parts of the H264 acceleration,
// that we don't want to expose in the .h file since they may differ from
// upstream.
struct V4L2H264AcceleratorPrivate {
// TODO(posciak): This should be queried from hardware once supported.
static constexpr size_t kMaxSlices = 16;
struct v4l2_ctrl_h264_slice_param v4l2_slice_params[kMaxSlices];
struct v4l2_ctrl_h264_decode_param v4l2_decode_param;
};
class V4L2H264Picture : public H264Picture {
public:
explicit V4L2H264Picture(const scoped_refptr<V4L2DecodeSurface>& dec_surface)
......@@ -34,7 +46,10 @@ class V4L2H264Picture : public H264Picture {
V4L2H264Accelerator::V4L2H264Accelerator(
V4L2DecodeSurfaceHandler* surface_handler,
V4L2Device* device)
: num_slices_(0), surface_handler_(surface_handler), device_(device) {
: num_slices_(0),
surface_handler_(surface_handler),
device_(device),
priv_(std::make_unique<V4L2H264AcceleratorPrivate>()) {
DCHECK(surface_handler_);
}
......@@ -65,10 +80,10 @@ void V4L2H264Accelerator::H264PictureListToDPBIndicesList(
void V4L2H264Accelerator::H264DPBToV4L2DPB(
const H264DPB& dpb,
std::vector<scoped_refptr<V4L2DecodeSurface>>* ref_surfaces) {
memset(v4l2_decode_param_.dpb, 0, sizeof(v4l2_decode_param_.dpb));
memset(priv_->v4l2_decode_param.dpb, 0, sizeof(priv_->v4l2_decode_param.dpb));
size_t i = 0;
for (const auto& pic : dpb) {
if (i >= base::size(v4l2_decode_param_.dpb)) {
if (i >= base::size(priv_->v4l2_decode_param.dpb)) {
VLOGF(1) << "Invalid DPB size";
break;
}
......@@ -81,7 +96,7 @@ void V4L2H264Accelerator::H264DPBToV4L2DPB(
ref_surfaces->push_back(dec_surface);
}
struct v4l2_h264_dpb_entry& entry = v4l2_decode_param_.dpb[i++];
struct v4l2_h264_dpb_entry& entry = priv_->v4l2_decode_param.dpb[i++];
entry.buf_index = index;
entry.frame_num = pic->frame_num;
entry.pic_num = pic->pic_num;
......@@ -264,11 +279,11 @@ H264Decoder::H264Accelerator::Status V4L2H264Accelerator::SubmitFrameMetadata(
}
H264PictureListToDPBIndicesList(ref_pic_listp0,
v4l2_decode_param_.ref_pic_list_p0);
priv_->v4l2_decode_param.ref_pic_list_p0);
H264PictureListToDPBIndicesList(ref_pic_listb0,
v4l2_decode_param_.ref_pic_list_b0);
priv_->v4l2_decode_param.ref_pic_list_b0);
H264PictureListToDPBIndicesList(ref_pic_listb1,
v4l2_decode_param_.ref_pic_list_b1);
priv_->v4l2_decode_param.ref_pic_list_b1);
std::vector<scoped_refptr<V4L2DecodeSurface>> ref_surfaces;
H264DPBToV4L2DPB(dpb, &ref_surfaces);
......@@ -286,13 +301,13 @@ H264Decoder::H264Accelerator::Status V4L2H264Accelerator::SubmitSlice(
const uint8_t* data,
size_t size,
const std::vector<SubsampleEntry>& subsamples) {
if (num_slices_ == kMaxSlices) {
if (num_slices_ == priv_->kMaxSlices) {
VLOGF(1) << "Over limit of supported slices per frame";
return Status::kFail;
}
struct v4l2_ctrl_h264_slice_param& v4l2_slice_param =
v4l2_slice_params_[num_slices_++];
priv_->v4l2_slice_params[num_slices_++];
memset(&v4l2_slice_param, 0, sizeof(v4l2_slice_param));
v4l2_slice_param.size = size;
......@@ -386,7 +401,7 @@ H264Decoder::H264Accelerator::Status V4L2H264Accelerator::SubmitSlice(
scoped_refptr<V4L2DecodeSurface> dec_surface =
H264PictureToV4L2DecodeSurface(pic.get());
v4l2_decode_param_.nal_ref_idc = slice_hdr->nal_ref_idc;
priv_->v4l2_decode_param.nal_ref_idc = slice_hdr->nal_ref_idc;
// TODO(posciak): Don't add start code back here, but have it passed from
// the parser.
......@@ -406,24 +421,24 @@ H264Decoder::H264Accelerator::Status V4L2H264Accelerator::SubmitDecode(
scoped_refptr<V4L2DecodeSurface> dec_surface =
H264PictureToV4L2DecodeSurface(pic.get());
v4l2_decode_param_.num_slices = num_slices_;
v4l2_decode_param_.idr_pic_flag = pic->idr;
v4l2_decode_param_.top_field_order_cnt = pic->top_field_order_cnt;
v4l2_decode_param_.bottom_field_order_cnt = pic->bottom_field_order_cnt;
priv_->v4l2_decode_param.num_slices = num_slices_;
priv_->v4l2_decode_param.idr_pic_flag = pic->idr;
priv_->v4l2_decode_param.top_field_order_cnt = pic->top_field_order_cnt;
priv_->v4l2_decode_param.bottom_field_order_cnt = pic->bottom_field_order_cnt;
struct v4l2_ext_control ctrl;
std::vector<struct v4l2_ext_control> ctrls;
memset(&ctrl, 0, sizeof(ctrl));
ctrl.id = V4L2_CID_MPEG_VIDEO_H264_SLICE_PARAM;
ctrl.size = sizeof(v4l2_slice_params_);
ctrl.ptr = v4l2_slice_params_;
ctrl.size = sizeof(priv_->v4l2_slice_params);
ctrl.ptr = priv_->v4l2_slice_params;
ctrls.push_back(ctrl);
memset(&ctrl, 0, sizeof(ctrl));
ctrl.id = V4L2_CID_MPEG_VIDEO_H264_DECODE_PARAM;
ctrl.size = sizeof(v4l2_decode_param_);
ctrl.ptr = &v4l2_decode_param_;
ctrl.size = sizeof(priv_->v4l2_decode_param);
ctrl.ptr = &priv_->v4l2_decode_param;
ctrls.push_back(ctrl);
struct v4l2_ext_controls ext_ctrls;
......@@ -453,8 +468,8 @@ bool V4L2H264Accelerator::OutputPicture(scoped_refptr<H264Picture> pic) {
void V4L2H264Accelerator::Reset() {
num_slices_ = 0;
memset(&v4l2_decode_param_, 0, sizeof(v4l2_decode_param_));
memset(&v4l2_slice_params_, 0, sizeof(v4l2_slice_params_));
memset(&priv_->v4l2_decode_param, 0, sizeof(priv_->v4l2_decode_param));
memset(&priv_->v4l2_slice_params, 0, sizeof(priv_->v4l2_slice_params));
}
scoped_refptr<V4L2DecodeSurface>
......
......@@ -5,8 +5,7 @@
#ifndef MEDIA_GPU_V4L2_V4L2_H264_ACCELERATOR_H_
#define MEDIA_GPU_V4L2_V4L2_H264_ACCELERATOR_H_
#include <linux/videodev2.h>
#include <memory>
#include <vector>
#include "base/macros.h"
......@@ -19,6 +18,7 @@ namespace media {
class V4L2Device;
class V4L2DecodeSurface;
class V4L2DecodeSurfaceHandler;
struct V4L2H264AcceleratorPrivate;
class V4L2H264Accelerator : public H264Decoder::H264Accelerator {
public:
......@@ -52,8 +52,6 @@ class V4L2H264Accelerator : public H264Decoder::H264Accelerator {
private:
// Max size of reference list.
static constexpr size_t kDPBIndicesListSize = 32;
// TODO(posciak): This should be queried from hardware once supported.
static constexpr size_t kMaxSlices = 16;
void H264PictureListToDPBIndicesList(const H264Picture::Vector& src_pic_list,
uint8_t dst_list[kDPBIndicesListSize]);
......@@ -67,8 +65,9 @@ class V4L2H264Accelerator : public H264Decoder::H264Accelerator {
V4L2DecodeSurfaceHandler* const surface_handler_;
V4L2Device* const device_;
struct v4l2_ctrl_h264_slice_param v4l2_slice_params_[kMaxSlices];
struct v4l2_ctrl_h264_decode_param v4l2_decode_param_;
// Contains the kernel-specific structures that we don't want to expose
// outside of the compilation unit.
const std::unique_ptr<V4L2H264AcceleratorPrivate> priv_;
DISALLOW_COPY_AND_ASSIGN(V4L2H264Accelerator);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment