Commit graph

161 commits

Author SHA1 Message Date
He Junyan
fe369fb523 libs: encoder: delete get_default_properties of H264 2019-08-30 21:21:04 +08:00
He Junyan
eb17703d43 libs: encoder: implement get_view_ids for h264 encoder. 2019-08-30 21:21:04 +08:00
He Junyan
bc2f8fd19e libs: encoder: add flags to all encoder properties.
G_PARAM_CONSTRUCT make all properties init correctly, we do not
need to init the properties manually.
G_PARAM_FLAG_VAAPI_ENCODER_EXPOSURE is a vaapi encoder specific
flag, means need to expose the property to according encode class.
2019-08-30 18:39:32 +08:00
He Junyan
3468edc20b libs: encoder: Add properties for h264 encoder.
Install properties for h264 encoder class. Also set the new get/set
property functions for gobject class. Still use the old properties
way now and this new feature will be enabled later.
2019-08-30 13:42:54 +08:00
He Junyan
c4a47f91ba lib: encoder: gstobjectfy all vaapi encoders.
Replace all gstvaapiobject in vaapi encoders with standard gstobject.
Let the gstobject common logic to handle all the init and finalize
works. But the property install/set/get still use the old way, need
to be improved later.
2019-08-30 13:05:50 +08:00
Víctor Manuel Jáquez Leal
1c73dc969c libs: profile: add gst_vaapi_profile_get_va_name()
gst_vaapi_profile_get_name() returns a proper name for
GstCaps. Nonetheless, there are many profiles which don't have a name
representation for that realm.

gst_vaapi_profile_get_va_name() returns the name of the profile
according to its VAProfile name.

This new funtion is used in the encoder error message.
2019-08-19 17:26:55 +00:00
Wangfei
9e0c133a24 libs: encoder: h264: support ICQ/QVBR bitrate control mode
ICQ is Intelligent Constant Quality. It will use the initial QP
vaule of icq-quality-factor to adjust QP at MB level intelligently
to improve subjective quality.

QVBR is Quality defined VBR. It will use qvbr-quality-factor to
adjust QP for each MB to get enough quality picture without waste
of bits.
2019-08-05 11:01:19 +08:00
Wangfei
8b8dfb127a libs: encoder: h264,h265: add new property "max-qp"
Add new property "max-qp" to allow set the maximum quantisation
parameter values.
2019-07-24 17:07:28 +00:00
He Junyan
0af3e36068 libs: encoder: not call ensure_num_slices inside g_assert
g_assert will take no effect when glib's G_DISABLE_ASSERT macro is
defined. The function inside the g_assert will take no effect and
we will fail to set the correct slice number.
2019-05-10 18:29:13 +08:00
He Junyan
a1ae75b500 libs: encoder: Enable trellis quantization method.
The advanced trellis algorithm is supported in VA driver. We add
its support as a property named "trellis" of encoder.
It only works for H264 now, should be more in future.
2019-05-09 05:54:09 +00:00
He Junyan
a3ce4446c1 libs: h264encoder: fix a typo of GstVaapiEncoderH264PredictionType 2019-04-29 20:10:39 +08:00
Víctor Manuel Jáquez Leal
029bb3e504 libs: encoder: h264,h265: guard VA version for max_qp property
This patch fixes a regression from commit 5b1fe9c6.

max_qp, in rate control configuration, appeared in libva release
2.1 (API 1.1), thus it is required to guard the VA API version.

Fixes: #150
2019-04-15 19:38:01 +02:00
He Junyan
5b1fe9c68a libs: encoder: h264,h265: Set max_qp if min_qp is non-zero.
media-driver currently fails to set a correct value of max_qp when
min_qp is different to zero, in CBR and VBR mode, generating full
quality frames, thus unexpected huge output.

This patch sets max_qp to an arbitrary value to avoid this output
temporary.

Fixes: #144
2019-04-10 14:59:23 +02:00
Víctor Manuel Jáquez Leal
d4bc0cb6da libs: encoder: h264,h265: initial and minimal QP can be zero
Currently the minimal value for either min_qp and init_qp are 1,
but VA documentation specifiy that zero is also valid and means
to ignore the quantiser.

The default value is not changed though to avoid behaivor changes
to users.
2019-04-09 13:14:18 +02:00
Víctor Manuel Jáquez Leal
7dc77ebf60 libs: encoder: h264: simplify the view-ids setting 2019-03-29 18:29:51 +01:00
He Junyan
6404bd399d libs: encoder: h264: Use gst_param_spec_array for view-ids
GValueArray is deprecated. Use GstValueArray instead.

gst_param_spec_array can be deserialized from command line using:

vaapih264enc view-ids="<(uint)40,(uint)100>" num-views=2

While the g_param_spec_value_array() can not, and always get
error: "gst_value_deserialize_g_value_array: unimplemented"

Also fixed an out-of-range bug.
2019-03-29 18:18:03 +01:00
Wangfei
e6943d668a encoder: h264/h265: set SPS cbr_flag with correct value.
The flag only set as 1 when the rate-control mode is CBR.
2019-01-22 08:50:46 +00:00
Víctor Manuel Jáquez Leal
220016aa6c libs: encoder: h264/h265: flush pending ordered pictures
In order to flush the pending pictures, a new internal encoder vmethod
is used: get_pending_reordered()

This method follows an iterator pattern which will return the next
picture to encode and push.

The base encoder will call this function in a loop when flush() is called.

For now, only H.264 and H.265 encoders implement this flushing mechanism.
2019-01-14 20:09:57 +01:00
Wangfei
f50fb8748f libs: encoder: h264/h265: fix encode lose frame issue.
Instead of dropping all remain frames in reorder_frame_list during
flush, keep encoding.

https://gitlab.freedesktop.org/gstreamer/gstreamer-vaapi/issues/97
2019-01-14 19:08:29 +00:00
Víctor Manuel Jáquez Leal
77527d67ab libs: remove gstbitwriter
Since it is deployed in gstreamer-core, there is no need to use
our custom version.

https://bugzilla.gnome.org/show_bug.cgi?id=795848
2018-05-06 17:29:45 +02:00
Víctor Manuel Jáquez Leal
c49a17ed15 libs: encoder: reimplement ROI using meta
Check input buffers for ROI metas and pass them to VA. Also added a
new "default-roi-delta-qp" property in order to tell the encoder what
delta QP should be applied to ROI by default.

Enabled it for H264 and H265 encoders.

https://bugzilla.gnome.org/show_bug.cgi?id=768248
2018-02-27 17:51:02 -05:00
Matteo Valdina
83886ced66 libs: encoder: h264,h265: extend max periodic keyframe.
Increased max values of periodic key frame for h26x codecs.
This allow more fine tunning of encoder that in certian scenario
want higher periodic key frame.

For example: it doesn't want a key frame each 10 seconds but
each 120 seconds.

https://bugzilla.gnome.org/show_bug.cgi?id=786320
2018-02-19 22:34:53 +01:00
Víctor Manuel Jáquez Leal
bfc7f66708 libs: encoder: h264,h265: guard rate control's macroblock
macroblock parameter appear on VA-API 1.0.0. It should be guarded.
2017-11-27 12:18:56 +01:00
Sreerenj Balachandran
6a3f30aab1 libs: encoder: h264: Add Hierarchical-B encode
Frames are encoded as different layers. Frame in a particular
layer will use pictures in lower or same layer as references.
Which means decoder can drop the frames in upper layer but still
decode lower layer frames.

B-frames, except the one in top most layer, are reference frames.
All the base layer frames are I or P.

eg: with 3 temporal layers

    T3:             B1            B3              B5              B7

    T2:                   B2                              B6

    T1:   I0                                P4                        P8

    T1, T2, T3: Temporal Layers
    P1...Pn:   P-Frames:
    B1...Bn:   B-frames:
    T1: I0->P4 , P4->P8 etc..
    T2: I0--> B2 <-- P4
    T3: I0--> B1 <-- B2, B2 --> B3 <-- P4

Signed-off-by: Sreerenj Balachandran <sreerenj.balachandran@intel.com>

https://bugzilla.gnome.org/show_bug.cgi?id=788918
2017-11-08 13:15:03 +01:00
Sreerenj Balachandran
53c83691f3 libs: encoder: h264: Add Hierarchical-P encode
Frames are encoded as different layers. A frame in a particular
layer will use pictures in lower or same layer as references.
Which means decoder can drop the frames in upper layer but still
decode lower layer frames.

eg: with 3 temporal layers

T3:             P1            P3              P5              P7

T2:                   P2                              P6

T1:   P0                                P4                        P8

T1, T2, T3: Temporal Layers
P1...pn:   P-Frames:
P0->P1 , P0->P2, P2->P3, P0->P4......repeat

Signed-off-by: Sreerenj Balachandran <sreerenj.balachandran@intel.com>

https://bugzilla.gnome.org/show_bug.cgi?id=788918
2017-11-08 13:15:03 +01:00
Sreerenj Balachandran
904931d7f3 libs: encoder: h264: Fix frame_num generation
The frame_num generation was not correctly implemented.
According to h264 spec, frame_num should get incremented
for each frame if previous frame is a referece frame.

For eg: IPBPB sequece should have the frame numbers 0,1,2,2,3

Signed-off-by: Sreerenj Balachandran <sreerenj.balachandran@intel.com>

https://bugzilla.gnome.org/show_bug.cgi?id=788918
2017-11-08 13:15:03 +01:00
Sreerenj Balachandran
ff91d62415 libs: encoder: h264: Add new property "prediction-type"
Adds new property "prediction-type" to select different reference
picture selection modes like hierarchical-p, hierarchical-b etc.

Signed-off-by: Sreerenj Balachandran <sreerenj.balachandran@intel.com>

https://bugzilla.gnome.org/show_bug.cgi?id=788918
2017-11-08 13:14:54 +01:00
XuGuangxin
dc583452d8 libs: encoder: h264: Add machinery for implementing hierarchical-prediction
Adds some basic building blocks to ease the implementation
of hierarchical prediction modes.

-- add an utility method to find temporal level of each frame
-- define max_ref_frame count based on temporal level count
-- add temporal_level_div[] for finding temporal level each frame
to be encoded.
-- find ip_period based on temporal level count

Signed-off-by: Sreerenj Balachandran <sreerenj.balachandran@intel.com>

https://bugzilla.gnome.org/show_bug.cgi?id=788918
2017-11-08 12:33:50 +01:00
XuGuangxin
e49859fde0 libs: encoder: h264: Add property "temporal-levels"
Adds new property "temporal-levels" to select the number of
temporal levels to be included in the encoded stream.

Signed-off-by: Sreerenj Balachandran <sreerenj.balachandran@intel.com>

https://bugzilla.gnome.org/show_bug.cgi?id=788918
2017-11-08 12:33:50 +01:00
Víctor Manuel Jáquez Leal
e308b452d6 libs: encoder: change mbbrc from uint to enum
Instead of handling the macroblock bitrate control as a integer, this
patch changes it as a enum, which is more self documented in the
GStreamer elements.

https://bugzilla.gnome.org/show_bug.cgi?id=787855
2017-09-18 20:19:20 +02:00
Jan Schmidt
b7c7335238 Fix a typo in the prop string for compliance-mode 2017-09-18 13:55:49 +10:00
Hyunjun Ko
64a38a16f1 libs: encoder: h264: support I/P/B QP setting seperatedly
Creates 2 properties, qp-ip and qp-ib for setting different QP for P/B
frames
and set slice_qp_delta for each frame according to the value provided.
In addition, remove the limitation of (<= 4) when setting
slice_qp_delta.

https://bugzilla.gnome.org/show_bug.cgi?id=785923
2017-09-13 10:47:22 +02:00
Hyunjun Ko
5796750604 libs: encoder: h264/h265: keep min_qp as is unless it's over init_qp
Creates new variable for QP for I frame and keep it at configuration and
use this for pic_init_qp and slice_qp_delta setting.

Since changing min qp doesn't make sense, keep min qp as is.

https://bugzilla.gnome.org/show_bug.cgi?id=785923
2017-09-13 10:47:22 +02:00
Hyunjun Ko
6816d7c151 libs: encoder: h264: Add mbbrc property
This property supports Macroblock level Bitrate Control as the
following:
0: auto
1: on
2: off

https://bugzilla.gnome.org/show_bug.cgi?id=785917
2017-09-13 10:45:49 +02:00
Hyunjun Ko
f14563759a libs: encoder: h264/5: determine num_ref_idx_active_override_flag according to reference list
Follows the specification as below:

7.4.7.1 in Rec. ITU-T H.265 v4 (12/2016)
num_ref_idx_active_override_flag equal to 1 specifies that the syntax
element num_ref_idx_l0_active_minus1 is present for P and B slices and
that the syntax element num_ref_idx_l1_active_minus1 is present for B
slices.
num_ref_idx_active_override_flag equal to 0 specifies that the syntax
elements num_ref_idx_l0_active_minus1 and num_ref_idx_l1_active_minus1
are not present.

https://bugzilla.gnome.org/show_bug.cgi?id=783804
2017-09-13 10:36:34 +02:00
Víctor Manuel Jáquez Leal
3bfb29e4c2 libs: encoder: remove unused cast macro
Remove internal macro to cast structure that are already declared
in the header.
2017-08-28 19:20:42 +02:00
Víctor Manuel Jáquez Leal
b942f9e17f libs: encoder: h264: handle deprecated enum
In VA-API 1.0 the enum VAEncPackedHeaderH264_SEI is deprecated, and
instead VAEncPackedHeaderRawData should be used.

This patch creates a compatibility symbol,
VA_ENC_PACKED_HEADER_H264_SEI, to expose the used enum according the
VA-API version.

https://bugzilla.gnome.org/show_bug.cgi?id=784398
2017-08-25 16:44:27 +02:00
Víctor Manuel Jáquez Leal
ffffb99473 libs: encoder: h264: fix enum namespace 2017-08-18 18:16:18 +02:00
Víctor Manuel Jáquez Leal
75fd0d4ff0 libs: encoder: h264: remove spurious assignation
Coverity scan bug:

An assigned value that is never used may represent unnecessary
computation, an incorrect algorithm, or possibly the need for cleanup
or refactoring.

ip_period is assigned first to be rewritter inmediatly after. The
first assignation is spurious.
2017-08-17 11:03:35 +02:00
Víctor Manuel Jáquez Leal
aaca75fefb libs: encoder: remove va.h include
Since it is already managed by gstvaapicompat.h

https://bugzilla.gnome.org/show_bug.cgi?id=786119
2017-08-13 18:08:19 +02:00
Víctor Manuel Jáquez Leal
9891f1a9e2 build: consolidate the VA sub API includes
Include all VA sub APIs headers in a single point (gstvaapicompat.h),
since they are all already included in va.h after VA-API 0.38.

https://bugzilla.gnome.org/show_bug.cgi?id=786119
2017-08-13 18:08:19 +02:00
Víctor Manuel Jáquez Leal
f197749343 libs: encoder: h264: fix copy & paste error
Coverity scan bug:

The copied code will not have its intended effect.

This is a bug from commit cdaf15b2, where the intention is to
initialize RefPicList1 while setting RefPicList0.
2017-08-08 16:57:12 +02:00
Víctor Manuel Jáquez Leal
bd7716a739 libs: encoder: h265: fix possible integer overflow
Coverity scan bug:

Unintentional integer overflow. The expression's value may not be what
the programmer intended, because the expression is evaluated using a
narrow (i.e. few bits) integer type.

Cast operator to guint64 before computation to avoid narrowing.

merge with 3c5a6add
2017-08-08 16:56:58 +02:00
Hyunjun Ko
cdaf15b24d libs: encoder: h264: add multi reference support
Using num_ref_frames provided and the result of the Query
VAConfigAttribEncMaxRefFrames, it determines the size of reference list
and perform encoding with multi reference frames as the following:

1\ The num_ref_frames is being considered as the number of
reference picture list0
2\ Encoder adds 1 reference frame more to the reference picture list1
internally if b-frame encoding.
3\ If num_ref_frames is bigger than the number of refrence frames
supported in the driver, it will be lowered.

https://bugzilla.gnome.org/show_bug.cgi?id=783803
2017-08-02 11:21:02 +02:00
Hyunjun Ko
cd6a9736bd libs: encoder: h264: add refs property
Users can provide the number of reference frame by this property.

The value of the property will be considered as the number of
reference picture list0 and will add 1 reference frame more to the
reference picture list1 internally if b-frame encoding.

If the value provided is bigger than the number of refrence frames
supported in the driver, it will be lowered.

https://bugzilla.gnome.org/show_bug.cgi?id=783803
2017-08-02 11:20:35 +02:00
Sreerenj Balachandran
aa3543929b libs: encoder: h264: Add uncompliant mode reducing coded buffer size
Added a new property "compliance-mode", which default is the normal
strict compliant mode.

The second mode, "restrict-buf-alloc", is to limit the coded buffer
allocation size to improve performance in some specific Intel
platforms (there is asignificant performance improvement in parallel
encodings). Under this new mode, we use the MinCR field in A.3.1 for
pre-calculating the coded-buffer size.

https://bugzilla.gnome.org/show_bug.cgi?id=784590
2017-08-01 14:37:44 +02:00
Hyunjun Ko
6ebf7b10ae libs: encoder: h264: submit sps in case of IDR picture
If the picture is IDR, also submit a SPS header.

This means when frame number reaches to keyframe-period or an force
key unit event arrives, we insert SPS/PPS again.

https://bugzilla.gnome.org/show_bug.cgi?id=776712
2017-07-04 14:25:39 +02:00
Hyunjun Ko
465d5868d9 libs: encoder: h264: set the frame as IDR if forced key unit
GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME() is a flag usually used to manage
the `frame-lost` event in the case of streaming, such as RTP.

In case of this event, it is needed to start new GOP rather than just
produce an I-frame.

https://bugzilla.gnome.org/show_bug.cgi?id=776712
2017-07-04 14:25:39 +02:00
Sreerenj Balachandran
02a6e9a273 libs: encoder: h264: insert AU delimiter
Insert an AUD as the first NAL of each encoded frame.

Some applications require Access Unit Delimiter for decoding the
stream.

The AU delimeter insertion is done only when the aud parameter is
TRUE (by default is disabled). The reason of this it is because this
header is only available from Intel Gen9 and the VA intel driver
should be 1.8 or superior. Otherwise, the output will be corrupted.

https://bugzilla.gnome.org/show_bug.cgi?id=776712

Signed-off-by: Victor Jaquez <vjaquez@igalia.com>
2017-07-04 14:22:52 +02:00
Hyunjun Ko
9b73b31c7a libs: encoder: h264: initialize all elements of view_ids
Currently when num_views is changed by multiview-mode on sink caps, it produces
wrong MVC encoded stream since the array view_ids is not set properly according
to changed num_views.

So this patch initializes all of the array sequentially to handle this case.
Side effect is not going to happen by this patch since this array is being
handled by num_views.

https://bugzilla.gnome.org/show_bug.cgi?id=784321
2017-07-04 13:27:56 +02:00