[PATCH v2 0/3] gstreamer-imx: add efficient GRAY8/h264 conversion

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH v2 0/3] gstreamer-imx: add efficient GRAY8/h264 conversion

Philippe De Muyter
From: Philippe De Muyter <[hidden email]>

Hi Carlos,

I hope this (gstreamer-devel mailing list) is the right place to send
patches for gstreamer-imx.

This patch series adds efficient GRAY8/h264 conversion to gstreamer-imx,
by using a constant memory zone populated with the value '128' for the
Cb and Cr planes that are requested by h268, but not provided by GRAY8.
Because of the API of libimxvpuapi, I had to set cb_offset and cr_offset
to the difference between the physical address of the new zone and
the physical address of the Y plane, which is a hack I admit, but
this works perfectly.

In order to free cleanly this zone, I needed to add a 'close' vfunc
to encoder_base.

There is also a unrelated new check to allow compilation when
GST_VIDEO_FORMAT_NV61 is not defined.

Philippe De Muyter

v2: move allocation of cbcr_buffer from gst_imx_vpu_encoder_h264_set_frame_enc_params to gst_imx_vpu_encoder_h264_set_open_params.

Philippe De Muyter (3):
  v4l2src: Add GST_VIDEO_FORMAT_NV61 check.
  vpu/encoder_base: add a 'close' subclass vfunc
  vpu/encoder_h264: accept GRAY8 on input.

 src/v4l2src/v4l2src.c  |  2 ++
 src/vpu/encoder_base.c |  8 ++++++++
 src/vpu/encoder_base.h |  4 ++++
 src/vpu/encoder_h264.c | 39 ++++++++++++++++++++++++++++++++++++++-
 src/vpu/encoder_h264.h |  2 ++
 5 files changed, 54 insertions(+), 1 deletion(-)

--
1.8.4.5

_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

[PATCH 1/3] v4l2src: Add GST_VIDEO_FORMAT_NV61 check.

Philippe De Muyter
From: Philippe De Muyter <[hidden email]>

Signed-off-by: Philippe De Muyter <[hidden email]>
---
 src/v4l2src/v4l2src.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/v4l2src/v4l2src.c b/src/v4l2src/v4l2src.c
index 12b392a..68ecea2 100644
--- a/src/v4l2src/v4l2src.c
+++ b/src/v4l2src/v4l2src.c
@@ -529,12 +529,14 @@ static GstCaps *gst_imx_v4l2src_caps_for_current_setup(GstImxV4l2VideoSrc *v4l2s
 #endif
  gst_fmt = GST_VIDEO_FORMAT_NV16;
  break;
+#ifdef GST_VIDEO_FORMAT_NV61
  case V4L2_PIX_FMT_NV61:
 #ifdef V4L2_PIX_FMT_NV61M
  case V4L2_PIX_FMT_NV61M:
 #endif
  gst_fmt = GST_VIDEO_FORMAT_NV61;
  break;
+#endif
  case V4L2_PIX_FMT_NV24:
  gst_fmt = GST_VIDEO_FORMAT_NV24;
  break;
--
1.8.4.5

_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

[PATCH 2/3] vpu/encoder_base: add a 'close' subclass vfunc

Philippe De Muyter
In reply to this post by Philippe De Muyter
From: Philippe De Muyter <[hidden email]>

Signed-off-by: Philippe De Muyter <[hidden email]>
---
 src/vpu/encoder_base.c | 8 ++++++++
 src/vpu/encoder_base.h | 4 ++++
 2 files changed, 12 insertions(+)

diff --git a/src/vpu/encoder_base.c b/src/vpu/encoder_base.c
index 458aec1..fe020d1 100644
--- a/src/vpu/encoder_base.c
+++ b/src/vpu/encoder_base.c
@@ -316,6 +316,14 @@ static gboolean gst_imx_vpu_encoder_base_start(GstVideoEncoder *encoder)
 static gboolean gst_imx_vpu_encoder_base_stop(GstVideoEncoder *encoder)
 {
  GstImxVpuEncoderBase *vpu_encoder_base = GST_IMX_VPU_ENCODER_BASE(encoder);
+ GstImxVpuEncoderBaseClass *klass;
+
+ klass = GST_IMX_VPU_ENCODER_BASE_CLASS(G_OBJECT_GET_CLASS(vpu_encoder_base));
+ /* Let the derived class terminate cleanly */
+ if ((klass->close != NULL) && !klass->close(vpu_encoder_base))
+ {
+ GST_ERROR_OBJECT(vpu_encoder_base, "derived class could not terminate cleanly");
+ }
 
  gst_imx_vpu_encoder_base_close(vpu_encoder_base);
 
diff --git a/src/vpu/encoder_base.h b/src/vpu/encoder_base.h
index 73a42f7..19bc15f 100644
--- a/src/vpu/encoder_base.h
+++ b/src/vpu/encoder_base.h
@@ -130,6 +130,9 @@ struct _GstImxVpuEncoderBase
  *                         *output_buffer must point to this new buffer, and the previous
  *                         *output_buffer must be unref'd.
  *                         Returns TRUE if the call succeeded, and FALSE otherwise.
+ * @close:   Optional.
+ *                         Free all the private allocations done by the subclass
+ *                         Returns TRUE if the call succeeded, and FALSE otherwise.
  */
 struct _GstImxVpuEncoderBaseClass
 {
@@ -141,6 +144,7 @@ struct _GstImxVpuEncoderBaseClass
  GstCaps* (*get_output_caps)(GstImxVpuEncoderBase *vpu_encoder_base);
  gboolean (*set_frame_enc_params)(GstImxVpuEncoderBase *vpu_encoder_base, ImxVpuEncParams *enc_params);
  gboolean (*process_output_buffer)(GstImxVpuEncoderBase *vpu_encoder_base, GstVideoCodecFrame *frame, GstBuffer **output_buffer);
+ gboolean (*close)(GstImxVpuEncoderBase *vpu_encoder_base);
 };
 
 
--
1.8.4.5

_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

[PATCH 3/3] vpu/encoder_h264: accept GRAY8 on input.

Philippe De Muyter
In reply to this post by Philippe De Muyter
From: Philippe De Muyter <[hidden email]>

Signed-off-by: Philippe De Muyter <[hidden email]>
---
 src/vpu/encoder_h264.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
 src/vpu/encoder_h264.h |  2 ++
 2 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/src/vpu/encoder_h264.c b/src/vpu/encoder_h264.c
index 98c401d..3fcffef 100644
--- a/src/vpu/encoder_h264.c
+++ b/src/vpu/encoder_h264.c
@@ -49,7 +49,7 @@ static GstStaticPadTemplate static_sink_template = GST_STATIC_PAD_TEMPLATE(
  GST_PAD_ALWAYS,
  GST_STATIC_CAPS(
  "video/x-raw,"
- "format = (string) { I420, NV12 }, "
+ "format = (string) { I420, NV12, GRAY8 }, "
  "width = (int) [ 48, 1920, 8 ], "
  "height = (int) [ 32, 1080, 8 ], "
  "framerate = (fraction) [ 0, MAX ]"
@@ -77,6 +77,7 @@ gboolean gst_imx_vpu_encoder_h264_set_open_params(GstImxVpuEncoderBase *vpu_enco
 GstCaps* gst_imx_vpu_encoder_h264_get_output_caps(GstImxVpuEncoderBase *vpu_encoder_base);
 gboolean gst_imx_vpu_encoder_h264_set_frame_enc_params(GstImxVpuEncoderBase *vpu_encoder_base, ImxVpuEncParams *enc_params);
 gboolean gst_imx_vpu_encoder_h264_process_output_buffer(GstImxVpuEncoderBase *vpu_encoder_base, GstVideoCodecFrame *frame, GstBuffer **output_buffer);
+gboolean gst_imx_vpu_encoder_h264_close(GstImxVpuEncoderBase *vpu_encoder_base);
 
 
 
@@ -102,6 +103,7 @@ static void gst_imx_vpu_encoder_h264_class_init(GstImxVpuEncoderH264Class *klass
  encoder_base_class->get_output_caps       = GST_DEBUG_FUNCPTR(gst_imx_vpu_encoder_h264_get_output_caps);
  encoder_base_class->set_frame_enc_params  = GST_DEBUG_FUNCPTR(gst_imx_vpu_encoder_h264_set_frame_enc_params);
  encoder_base_class->process_output_buffer = GST_DEBUG_FUNCPTR(gst_imx_vpu_encoder_h264_process_output_buffer);
+ encoder_base_class->close  = GST_DEBUG_FUNCPTR(gst_imx_vpu_encoder_h264_close);
 
  gst_element_class_add_pad_template(element_class, gst_static_pad_template_get(&static_sink_template));
  gst_element_class_add_pad_template(element_class, gst_static_pad_template_get(&static_src_template));
@@ -191,6 +193,21 @@ gboolean gst_imx_vpu_encoder_h264_set_open_params(GstImxVpuEncoderBase *vpu_enco
 {
  GstCaps *template_caps, *allowed_caps;
  GstImxVpuEncoderH264 *vpu_encoder_h264 = GST_IMX_VPU_ENCODER_H264(vpu_encoder_base);
+ GstVideoFormat fmt = GST_VIDEO_INFO_FORMAT(&(input_state->info));
+
+ if (fmt == GST_VIDEO_FORMAT_GRAY8)
+ {
+ open_params->color_format = IMX_VPU_COLOR_FORMAT_YUV400;
+ if (vpu_encoder_h264->cbcr_buffer == 0)
+ {
+#define CBCR_PLANE_SIZE (1920 * 1080 / 4)
+ vpu_encoder_h264->cbcr_buffer = imx_vpu_dma_buffer_allocate(imx_vpu_enc_get_default_allocator(), CBCR_PLANE_SIZE, 1, 0);
+ vpu_encoder_h264->cbcr_physaddr = imx_vpu_dma_buffer_get_physical_address(vpu_encoder_h264->cbcr_buffer);
+ void *mapped_virtual_address = imx_vpu_dma_buffer_map(vpu_encoder_h264->cbcr_buffer, IMX_VPU_MAPPING_FLAG_WRITE);
+ memset(mapped_virtual_address, 128, CBCR_PLANE_SIZE);
+ imx_vpu_dma_buffer_unmap(vpu_encoder_h264->cbcr_buffer);
+ }
+ }
 
  /* Default h.264 open params are already set by the imx_vpu_enc_set_default_open_params()
  * call in the base class */
@@ -256,6 +273,16 @@ GstCaps* gst_imx_vpu_encoder_h264_get_output_caps(GstImxVpuEncoderBase *vpu_enco
 gboolean gst_imx_vpu_encoder_h264_set_frame_enc_params(GstImxVpuEncoderBase *vpu_encoder_base, ImxVpuEncParams *enc_params)
 {
  GstImxVpuEncoderH264 *vpu_encoder_h264 = GST_IMX_VPU_ENCODER_H264(vpu_encoder_base);
+ ImxVpuFramebuffer *input_framebuffer = &vpu_encoder_base->input_framebuffer;
+
+
+ if (input_framebuffer->cb_offset == 0 && input_framebuffer->cr_offset == 0)
+ {
+ unsigned long y_physaddr = imx_vpu_dma_buffer_get_physical_address(vpu_encoder_base->input_frame.framebuffer->dma_buffer);
+ size_t cbcr_offset = vpu_encoder_h264->cbcr_physaddr - y_physaddr;
+ input_framebuffer->cb_offset = cbcr_offset;
+ input_framebuffer->cr_offset = cbcr_offset;
+ }
 
  enc_params->quant_param = vpu_encoder_h264->quant_param;
  if (vpu_encoder_h264->idr_interval > 0)
@@ -297,3 +324,17 @@ gboolean gst_imx_vpu_encoder_h264_process_output_buffer(GstImxVpuEncoderBase *vp
 
  return TRUE;
 }
+
+gboolean gst_imx_vpu_encoder_h264_close(GstImxVpuEncoderBase *vpu_encoder_base)
+{
+ GstImxVpuEncoderH264 *vpu_encoder_h264 = GST_IMX_VPU_ENCODER_H264(vpu_encoder_base);
+
+ if (vpu_encoder_h264->cbcr_physaddr)
+ {
+ imx_vpu_dma_buffer_deallocate(vpu_encoder_h264->cbcr_buffer);
+ vpu_encoder_h264->cbcr_buffer = 0;
+ vpu_encoder_h264->cbcr_physaddr = 0;
+ }
+
+ return TRUE;
+}
diff --git a/src/vpu/encoder_h264.h b/src/vpu/encoder_h264.h
index f3698e2..fa93e2c 100644
--- a/src/vpu/encoder_h264.h
+++ b/src/vpu/encoder_h264.h
@@ -46,6 +46,8 @@ struct _GstImxVpuEncoderH264
  guint idr_interval;
  gboolean produce_access_units;
  guint frame_count;
+ ImxVpuDMABuffer *cbcr_buffer;
+ unsigned long cbcr_physaddr;
 };
 
 
--
1.8.4.5

_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH v2 0/3] gstreamer-imx: add efficient GRAY8/h264 conversion

Philippe Normand
In reply to this post by Philippe De Muyter
On Tue, 2016-09-06 at 14:52 +0200, [hidden email] wrote:
> From: Philippe De Muyter <[hidden email]>
>
> Hi Carlos,
>
> I hope this (gstreamer-devel mailing list) is the right place to send
> patches for gstreamer-imx.

We use Bugzilla for patch reviews but gstreamer-imx not being part of
the official modules you should create a pull request on their Github
repository.

Philippe

>
> This patch series adds efficient GRAY8/h264 conversion to gstreamer-
> imx,
> by using a constant memory zone populated with the value '128' for
> the
> Cb and Cr planes that are requested by h268, but not provided by
> GRAY8.
> Because of the API of libimxvpuapi, I had to set cb_offset and
> cr_offset
> to the difference between the physical address of the new zone and
> the physical address of the Y plane, which is a hack I admit, but
> this works perfectly.
>
> In order to free cleanly this zone, I needed to add a 'close' vfunc
> to encoder_base.
>
> There is also a unrelated new check to allow compilation when
> GST_VIDEO_FORMAT_NV61 is not defined.
>
> Philippe De Muyter
>
> v2: move allocation of cbcr_buffer from
> gst_imx_vpu_encoder_h264_set_frame_enc_params to
> gst_imx_vpu_encoder_h264_set_open_params.
>
> Philippe De Muyter (3):
>   v4l2src: Add GST_VIDEO_FORMAT_NV61 check.
>   vpu/encoder_base: add a 'close' subclass vfunc
>   vpu/encoder_h264: accept GRAY8 on input.
>
>  src/v4l2src/v4l2src.c  |  2 ++
>  src/vpu/encoder_base.c |  8 ++++++++
>  src/vpu/encoder_base.h |  4 ++++
>  src/vpu/encoder_h264.c | 39 ++++++++++++++++++++++++++++++++++++++-
>  src/vpu/encoder_h264.h |  2 ++
>  5 files changed, 54 insertions(+), 1 deletion(-)
>
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1/3] v4l2src: Add GST_VIDEO_FORMAT_NV61 check.

Vivia Nikolaidou
In reply to this post by Philippe De Muyter
Hi and thanks for your contribution.

Please use Bugzilla to send us your patches:
https://bugzilla.gnome.org/enter_bug.cgi?product=GStreamer

Thanks a lot,

Vivia

On 6 September 2016 at 15:53,  <[hidden email]> wrote:

> From: Philippe De Muyter <[hidden email]>
>
> Signed-off-by: Philippe De Muyter <[hidden email]>
> ---
>  src/v4l2src/v4l2src.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/src/v4l2src/v4l2src.c b/src/v4l2src/v4l2src.c
> index 12b392a..68ecea2 100644
> --- a/src/v4l2src/v4l2src.c
> +++ b/src/v4l2src/v4l2src.c
> @@ -529,12 +529,14 @@ static GstCaps *gst_imx_v4l2src_caps_for_current_setup(GstImxV4l2VideoSrc *v4l2s
>  #endif
>                         gst_fmt = GST_VIDEO_FORMAT_NV16;
>                         break;
> +#ifdef GST_VIDEO_FORMAT_NV61
>                 case V4L2_PIX_FMT_NV61:
>  #ifdef V4L2_PIX_FMT_NV61M
>                 case V4L2_PIX_FMT_NV61M:
>  #endif
>                         gst_fmt = GST_VIDEO_FORMAT_NV61;
>                         break;
> +#endif
>                 case V4L2_PIX_FMT_NV24:
>                         gst_fmt = GST_VIDEO_FORMAT_NV24;
>                         break;
> --
> 1.8.4.5
>
> _______________________________________________
> gstreamer-devel mailing list
> [hidden email]
> https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 2/3] vpu/encoder_base: add a 'close' subclass vfunc

Carlos Rafael Giani
In reply to this post by Philippe De Muyter
Hi,

I saw your patches, but I am absolutely, extremely busy with a super
important deadline. I will go back to the gstreamer-imx and libimxvpuapi
projects in a few days.

cheers,
   Carlos


On 2016-09-06 14:53, [hidden email] wrote:

> From: Philippe De Muyter <[hidden email]>
>
> Signed-off-by: Philippe De Muyter <[hidden email]>
> ---
>   src/vpu/encoder_base.c | 8 ++++++++
>   src/vpu/encoder_base.h | 4 ++++
>   2 files changed, 12 insertions(+)
>
> diff --git a/src/vpu/encoder_base.c b/src/vpu/encoder_base.c
> index 458aec1..fe020d1 100644
> --- a/src/vpu/encoder_base.c
> +++ b/src/vpu/encoder_base.c
> @@ -316,6 +316,14 @@ static gboolean gst_imx_vpu_encoder_base_start(GstVideoEncoder *encoder)
>   static gboolean gst_imx_vpu_encoder_base_stop(GstVideoEncoder *encoder)
>   {
>   GstImxVpuEncoderBase *vpu_encoder_base = GST_IMX_VPU_ENCODER_BASE(encoder);
> + GstImxVpuEncoderBaseClass *klass;
> +
> + klass = GST_IMX_VPU_ENCODER_BASE_CLASS(G_OBJECT_GET_CLASS(vpu_encoder_base));
> + /* Let the derived class terminate cleanly */
> + if ((klass->close != NULL) && !klass->close(vpu_encoder_base))
> + {
> + GST_ERROR_OBJECT(vpu_encoder_base, "derived class could not terminate cleanly");
> + }
>  
>   gst_imx_vpu_encoder_base_close(vpu_encoder_base);
>  
> diff --git a/src/vpu/encoder_base.h b/src/vpu/encoder_base.h
> index 73a42f7..19bc15f 100644
> --- a/src/vpu/encoder_base.h
> +++ b/src/vpu/encoder_base.h
> @@ -130,6 +130,9 @@ struct _GstImxVpuEncoderBase
>    *                         *output_buffer must point to this new buffer, and the previous
>    *                         *output_buffer must be unref'd.
>    *                         Returns TRUE if the call succeeded, and FALSE otherwise.
> + * @close:   Optional.
> + *                         Free all the private allocations done by the subclass
> + *                         Returns TRUE if the call succeeded, and FALSE otherwise.
>    */
>   struct _GstImxVpuEncoderBaseClass
>   {
> @@ -141,6 +144,7 @@ struct _GstImxVpuEncoderBaseClass
>   GstCaps* (*get_output_caps)(GstImxVpuEncoderBase *vpu_encoder_base);
>   gboolean (*set_frame_enc_params)(GstImxVpuEncoderBase *vpu_encoder_base, ImxVpuEncParams *enc_params);
>   gboolean (*process_output_buffer)(GstImxVpuEncoderBase *vpu_encoder_base, GstVideoCodecFrame *frame, GstBuffer **output_buffer);
> + gboolean (*close)(GstImxVpuEncoderBase *vpu_encoder_base);
>   };
>  
>  

_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 2/3] vpu/encoder_base: add a 'close' subclass vfunc

Philippe De Muyter
On Tue, Sep 06, 2016 at 05:10:31PM +0200, Carlos Rafael Giani wrote:
> Hi,
>
> I saw your patches, but I am absolutely, extremely busy with a super
> important deadline. I will go back to the gstreamer-imx and libimxvpuapi
> projects in a few days.

OK.  In the meantime I have another one.  What is your preferred channel
to receive it ?

Best regards

Philippe
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 2/3] vpu/encoder_base: add a 'close' subclass vfunc

Carlos Rafael Giani
Let's keep it on github. I also just responded there.


On 2016-09-09 11:46, Philippe De Muyter wrote:

> On Tue, Sep 06, 2016 at 05:10:31PM +0200, Carlos Rafael Giani wrote:
>> Hi,
>>
>> I saw your patches, but I am absolutely, extremely busy with a super
>> important deadline. I will go back to the gstreamer-imx and libimxvpuapi
>> projects in a few days.
> OK.  In the meantime I have another one.  What is your preferred channel
> to receive it ?
>
> Best regards
>
> Philippe
> _______________________________________________
> gstreamer-devel mailing list
> [hidden email]
> https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel