Skip to contentSkip to conversation

Add support for MPEG-2 in DELTA video decoder

PATCH Superseded Hugues Fruchet 1 participant 4 messages Feb 21, 2017

Subsystems (2)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v4 cover Add support for MPEG-2 in DELTA video decoder

The patchset implements the MPEG-2 part of V4L2 unified low-level decoder API RFC [0] needed by stateless video decoders, ie decoders which requires specific parsing metadata in addition to video bitstream chunk in order to complete decoding.
A reference implementation using STMicroelectronics DELTA video decoder is provided as initial support in this patchset.
In addition to this patchset, a libv4l plugin is also provided which convert MPEG-2 video bitstream to "parsed MPEG-2" by parsing the user video bitstream and filling accordingly the dedicated controls, doing so user code remains unchanged whatever decoder is: stateless or not.

The first patch implements the MPEG-2 part of V4L2 unified low-level decoder API RFC [0]. A dedicated "parsed MPEG-2" pixel format has been introduced with its related extended controls in order that user provides both video bitstream chunk and the associated extra data resulting from this video bitstream chunk parsing.

The second patch adds the support of "parsed" pixel format inside DELTA video decoder including handling of the dedicated controls and setting of parsing metadata required by decoder layer.
Please note that the current implementation has a restriction regarding the atomicity of S_EXT_CTRL/QBUF that must be guaranteed by user. This restriction will be removed when V4L2 request API will be implemented [1]. Please also note the failure in v4l2-compliance in controls section, related to complex compound controls handling, to be discussed to find the right way to fix it in v4l2-compliance.

The third patch adds the support of DELTA MPEG-2 stateless video decoder back-end.

This driver depends on:
[PATCH v7 00/10] Add support for DELTA video decoder of STMicroelectronics STiH4xx SoC series https://patchwork.linuxtv.org/patch/39186/

References:
[0] [RFC] V4L2 unified low-level decoder API https://www.spinics.net/lists/linux-media/msg107150.html
[1] [ANN] Report of the V4L2 Request API brainstorm meeting https://www.spinics.net/lists/linux-media/msg106699.html

===========
= history =
===========
version 4:
- patchset 3 review from Nicolas Dufresne
- one attribute per line in structure
- fix some multilines comments

version 3:
- fix warning on parisc architecture

version 2:
- rebase on top of DELTA v7, refer to [0]
- change VIDEO_STI_DELTA_DRIVER to default=y as per Mauro recommendations

version 1:
- Initial submission

===================
= v4l2-compliance =
===================
Below is the v4l2-compliance report, v4l2-compliance has been build from SHA1:
003f31e59f353b4aecc82e8fb1c7555964da7efa (v4l2-compliance: allow S_SELECTION to return ENOTTY)

root@sti-4:~# v4l2-compliance -d /dev/video3
v4l2-compliance SHA   : 003f31e59f353b4aecc82e8fb1c7555964da7efa
root@sti-lts:~# v4l2-compliance -d /dev/video3 
v4l2-compliance SHA   : not available

Driver Info:

	Driver name   : st-delta
	Card type     : st-delta-21.1-3
	Bus info      : platform:soc:delta0
	Driver version: 4.9.0
	Capabilities  : 0x84208000
		Video Memory-to-Memory
		Streaming
		Extended Pix Format
		Device Capabilities
	Device Caps   : 0x04208000
		Video Memory-to-Memory
		Streaming
		Extended Pix Format

Compliance test for device /dev/video3 (not using libv4l2):

Required ioctls:
test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second video open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported) test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0

Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_ENUMAUDOUT: OK (Not Supported) test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported) test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported) test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported) test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)

Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK
test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
fail: ../../../../../../../../../sources/v4l-utils/utils/v4l2-compliance/v4l2-test-controls.cpp(585): g_ext_ctrls worked even when no controls are present test VIDIOC_G/S/TRY_EXT_CTRLS: FAIL
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK (Not Supported)
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 0 Private Controls: 0

Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK
warn: ../../../../../../../../../sources/v4l-utils/utils/v4l2-compliance/v4l2-test-formats.cpp(717): TRY_FMT cannot handle an invalid pixelformat.
warn: ../../../../../../../../../sources/v4l-utils/utils/v4l2-compliance/v4l2-test-formats.cpp(718): This may or may not be a problem. For more information see:
warn: ../../../../../../../../../sources/v4l-utils/utils/v4l2-compliance/v4l2-test-formats.cpp(719): http://www.mail-archive.com/[email protected]/msg56550.html
test VIDIOC_TRY_FMT: OK
warn: ../../../../../../../../../sources/v4l-utils/utils/v4l2-compliance/v4l2-test-formats.cpp(977): S_FMT cannot handle an invalid pixelformat.
warn: ../../../../../../../../../sources/v4l-utils/utils/v4l2-compliance/v4l2-test-formats.cpp(978): This may or may not be a problem. For more information see:
warn: ../../../../../../../../../sources/v4l-utils/utils/v4l2-compliance/v4l2-test-formats.cpp(979): http://www.mail-archive.com/[email protected]/msg56550.html
test VIDIOC_S_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK
test Scaling: OK

Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) test VIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK

Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test VIDIOC_EXPBUF: OK

Test input 0:

Total: 43, Succeeded: 42, Failed: 1, Warnings: 6

Hugues Fruchet (3):
[media] v4l: add parsed MPEG-2 support
[media] st-delta: add parsing metadata controls support [media] st-delta: add mpeg2 support

 Documentation/media/uapi/v4l/extended-controls.rst |  363 +++++
 Documentation/media/uapi/v4l/pixfmt-013.rst        |   10 +
 drivers/media/platform/Kconfig                     |   11 +-
 drivers/media/platform/sti/delta/Makefile          |    3 +
 drivers/media/platform/sti/delta/delta-cfg.h       |    5 +
 drivers/media/platform/sti/delta/delta-mpeg2-dec.c | 1401 ++++++++++++++++++++
 drivers/media/platform/sti/delta/delta-mpeg2-fw.h  |  423 ++++++
 drivers/media/platform/sti/delta/delta-v4l2.c      |  129 +-
 drivers/media/platform/sti/delta/delta.h           |   34 +
 drivers/media/v4l2-core/v4l2-ctrls.c               |   53 +
 drivers/media/v4l2-core/v4l2-ioctl.c               |    2 +
 include/uapi/linux/v4l2-controls.h                 |   94 ++
 include/uapi/linux/videodev2.h                     |    8 +
 13 files changed, 2533 insertions(+), 3 deletions(-)
 create mode 100644 drivers/media/platform/sti/delta/delta-mpeg2-dec.c
 create mode 100644 drivers/media/platform/sti/delta/delta-mpeg2-fw.h
Signature · 1 line
1.9.1
#1 lore raw

PATCH v4 1/3 v4l: add parsed MPEG-2 support

Add "parsed MPEG-2" pixel format & related controls needed by stateless video decoders.
In order to decode the video bitstream chunk provided by user on output queue, stateless decoders require also some extra data resulting from this video bitstream chunk parsing.
Those parsed extra data have to be set by user through control framework using the dedicated mpeg video extended controls introduced in this patchset.

---
 Documentation/media/uapi/v4l/extended-controls.rst | 363 +++++++++++++++++++++
 Documentation/media/uapi/v4l/pixfmt-013.rst        |  10 +
 drivers/media/v4l2-core/v4l2-ctrls.c               |  53 +++
 drivers/media/v4l2-core/v4l2-ioctl.c               |   2 +
 include/uapi/linux/v4l2-controls.h                 |  94 ++++++
 include/uapi/linux/videodev2.h                     |   8 +
 6 files changed, 530 insertions(+)
Documentation/media/uapi/v4l/extended-controls.rst +363 -0
index abb1057..cd1a8d6 100644
@@ -1827,6 +1827,369 @@ enum v4l2_mpeg_cx2341x_video_median_filter_type -
     not insert, 1 = insert packets.
 
 
+MPEG-2 Parsed Control Reference
+---------------------------------
+
+The MPEG-2 parsed decoding controls are needed by stateless video decoders.
+Those decoders expose :ref:`Compressed formats <compressed-formats>` :ref:`V4L2_PIX_FMT_MPEG1_PARSED<V4L2-PIX-FMT-MPEG1-PARSED>` or :ref:`V4L2_PIX_FMT_MPEG2_PARSED<V4L2-PIX-FMT-MPEG2-PARSED>`.
+In order to decode the video bitstream chunk provided by user on output queue,
+stateless decoders require also some extra data resulting from this video
+bitstream chunk parsing. Those parsed extra data have to be set by user
+through control framework using the mpeg video extended controls defined
+in this section. Those controls have been defined based on MPEG-2 standard
+ISO/IEC 13818-2, and so derive directly from the MPEG-2 video bitstream syntax
+including how it is coded inside bitstream (enumeration values for ex.).
+
+MPEG-2 Parsed Control IDs
+^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+.. _mpeg2-parsed-control-id:
+
+``V4L2_CID_MPEG_VIDEO_MPEG2_SEQ_HDR``
+    (enum)
+
+.. tabularcolumns:: |p{4.0cm}|p{2.5cm}|p{11.0cm}|
+
+.. c:type:: v4l2_mpeg_video_mpeg2_seq_hdr
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_mpeg_video_mpeg2_seq_hdr
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __u16
+      - ``width``
+      - Video width in pixels.
+    * - __u16
+      - ``height``
+      - Video height in pixels.
+    * - __u8
+      - ``aspect_ratio_info``
+      - Aspect ratio code as in the bitstream (1: 1:1 square pixels,
+        2: 4:3 display, 3: 16:9 display, 4: 2.21:1 display)
+    * - __u8
+      - ``framerate code``
+      - Framerate code as in the bitstream
+        (1: 24000/1001.0 '23.976 fps, 2: 24.0, 3: 25.0,
+        4: 30000/1001.0 '29.97, 5: 30.0, 6: 50.0, 7: 60000/1001.0,
+        8: 60.0)
+    * - __u32
+      - ``bitrate_value``
+      - Bitrate value as in the bitstream, expressed in 400bps unit
+    * - __u16
+      - ``vbv_buffer_size``
+      -  Video Buffering Verifier size, expressed in 16KBytes unit.
+    * - __u8
+      - ``constrained_parameters_flag``
+      - Set to 1 if this bitstream uses constrained parameters.
+    * - __u8
+      - ``load_intra_quantiser_matrix``
+      - If set to 1, ``intra_quantiser_matrix`` table is to be used for
+        decoding.
+    * - __u8
+      - ``load_non_intra_quantiser_matrix``
+      - If set to 1, ``non_intra_quantiser_matrix`` table is to be used for
+        decoding.
+    * - __u8
+      - ``intra_quantiser_matrix[64]``
+      - Intra quantization table, in zig-zag scan order.
+    * - __u8
+      - ``non_intra_quantiser_matrix[64]``
+      - Non-intra quantization table, in zig-zag scan order.
+    * - __u32
+      - ``par_w``
+      - Pixel aspect ratio width in pixels.
+    * - __u32
+      - ``par_h``
+      - Pixel aspect ratio height in pixels.
+    * - __u32
+      - ``fps_n``
+      - Framerate nominator.
+    * - __u32
+      - ``fps_d``
+      - Framerate denominator.
+    * - __u32
+      - ``bitrate``
+      - Bitrate in bps if constant bitrate, 0 otherwise.
+    * - :cspan:`2`
+
+
+``V4L2_CID_MPEG_VIDEO_MPEG2_SEQ_EXT``
+    (enum)
+
+.. tabularcolumns:: |p{4.0cm}|p{2.5cm}|p{11.0cm}|
+
+.. c:type:: v4l2_mpeg_video_mpeg2_seq_ext
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_mpeg_video_mpeg2_seq_ext
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __u8
+      - ``profile``
+      - Encoding profile used to encode this bitstream.
+        (1: High Profile, 2: Spatially Scalable Profile,
+        3: SNR Scalable Profile, 4: Main Profile, 5: Simple Profile).
+    * - __u8
+      - ``level``
+      - Encoding level used to encode this bitstream
+        (4: High Level, 6: High 1440 Level, 8: Main Level, 10: Low Level).
+    * - __u8
+      - ``progressive``
+      - Set to 1 if frames are progressive (vs interlaced).
+    * - __u8
+      - ``chroma_format``
+      - Chrominance format (1: 420, 2: 422, 3: 444).
+    * - __u8
+      - ``horiz_size_ext``
+      - Horizontal size extension. This value is to be shifted 12 bits left
+        and added to ''seq_hdr->width'' to get the final video width:
+        `width = seq_hdr->width + seq_ext->horiz_size_ext << 12`
+    * - __u8
+      - ``vert_size_ext``
+      - Vertical size extension. This value is to be shifted 12 bits left
+        and added to ''seq_hdr->height'' to get the final video height:
+        `height = seq_hdr->height + seq_ext->vert_size_ext << 12`
+    * - __u16
+      - ``bitrate_ext``
+      -  Bitrate extension. This value, expressed in 400bps unit, is to be
+         shifted 18 bits left and added to ''seq_hdr->bitrate'' to get the
+         final bitrate:
+         `bitrate = seq_hdr->bitrate + (seq_ext->bitrate_ext << 18) * 400`
+    * - __u8
+      - ``vbv_buffer_size_ext``
+      -  Video Buffering Verifier size extension in bits.
+    * - __u8
+      - ``low_delay``
+      -  Low delay. Set to 1 if no B pictures are present.
+    * - __u8
+      - ``fps_n_ext``
+      -  Framerate extension nominator. This value is to be incremented and
+         multiplied by ''seq_hdr->fps_n'' to get the final framerate
+         nominator:
+         `fps_n = seq_hdr->fps_n * (seq_ext->fps_n_ext + 1)`
+    * - __u8
+      - ``fps_d_ext``
+      -  Framerate extension denominator. This value is to be incremented and
+         multiplied by ''seq_hdr->fps_d'' to get the final framerate
+         denominator:
+         `fps_d = seq_hdr->fps_d * (seq_ext->fps_d_ext + 1)`
+    * - :cspan:`2`
+
+
+``V4L2_CID_MPEG_VIDEO_MPEG2_SEQ_DISPLAY_EXT``
+    (enum)
+
+.. tabularcolumns:: |p{4.0cm}|p{2.5cm}|p{11.0cm}|
+
+.. c:type:: v4l2_mpeg_video_mpeg2_seq_display_ext
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_mpeg_video_mpeg2_seq_ext
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __u8
+      - ``video_format``
+      - Video standard (0: Components, 1: PAL, 2: NTSC, 3: SECAM, 4:MAC)
+    * - __u8
+      - ``colour_description_flag``
+      - If set to 1, ''colour_primaries'', ''transfer_characteristics'',
+        ''matrix_coefficients'' are to be used for decoding.
+    * - __u8
+      - ``colour_primaries``
+      - Colour coding standard (1: ITU-R Rec. 709 (1990),
+        4: ITU-R Rec. 624-4 System M, 5: ITU-R Rec. 624-4 System B, G,
+        6: SMPTE 170M, 7: SMPTE 240M (1987))
+    * - __u8
+      - ``transfer_characteristics``
+      - Transfer characteristics coding standard (1: ITU-R Rec. 709 (1990),
+        4: ITU-R Rec. 624-4 System M, 5: ITU-R Rec. 624-4 System B, G,
+        6: SMPTE 170M, 7: SMPTE 240M (1987))
+    * - __u8
+      - ``matrix_coefficients``
+      - Matrix coefficients coding standard (1: ITU-R Rec. 709 (1990),
+        4: FCC, 5: ITU-R Rec. 624-4 System B, G, 6: SMPTE 170M,
+        7: SMPTE 240M (1987))
+    * - __u16
+      - ``display_horizontal_size``, ``display_vertical_size``
+      - Dimensions of the video to be displayed. If those dimensions
+        are smaller than the final video dimensions, only this area
+        must be displayed.
+    * - :cspan:`2`
+
+
+``V4L2_CID_MPEG_VIDEO_MPEG2_SEQ_MATRIX_EXT``
+    (enum)
+
+.. tabularcolumns:: |p{4.0cm}|p{2.5cm}|p{11.0cm}|
+
+.. c:type:: v4l2_mpeg_video_mpeg2_seq_matrix_ext
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_mpeg_video_mpeg2_seq_matrix_ext
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __u8
+      - ``load_intra_quantiser_matrix``
+      - If set to 1, ``intra_quantiser_matrix`` table is to be used for
+        decoding.
+    * - __u8
+      - ``intra_quantiser_matrix[64]``
+      - Intra quantization table, in zig-zag scan order.
+    * - __u8
+      - ``load_non_intra_quantiser_matrix``
+      - If set to 1, ``non_intra_quantiser_matrix`` table is to be used for
+        decoding.
+    * - __u8
+      - ``non_intra_quantiser_matrix[64]``
+      - Non-intra quantization table, in zig-zag scan order.
+    * - __u8
+      - ``load_chroma_intra_quantiser_matrix``
+      - If set to 1, ``chroma_intra_quantiser_matrix`` table is to be used for
+        decoding.
+    * - __u8
+      - ``chroma_intra_quantiser_matrix[64]``
+      - Chroma intra quantization table, in zig-zag scan order.
+    * - __u8
+      - ``load_chroma_non_intra_quantiser_matrix``
+      - If set to 1, ``chroma_non_intra_quantiser_matrix`` table is to be used for
+        decoding.
+    * - __u8
+      - ``chroma_non_intra_quantiser_matrix[64]``
+      - Chroma non-intra quantization table, in zig-zag scan order.
+    * - :cspan:`2`
+
+
+``V4L2_CID_MPEG_VIDEO_MPEG2_PIC_HDR``
+    (enum)
+
+.. tabularcolumns:: |p{4.0cm}|p{2.5cm}|p{11.0cm}|
+
+.. c:type:: v4l2_mpeg_video_mpeg2_pic_hdr
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_mpeg_video_mpeg2_pic_hdr
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __u32
+      - ``offset``
+      - Offset in bytes of the slice data from the beginning of packet.
+    * - __u16
+      - ``tsn``
+      - Temporal Sequence Number: order in which the frames must be displayed.
+    * - __u8
+      - ``pic_type``
+      - Picture coding type (1: Intra, 2: Predictive,
+        3: B, Bidirectionally Predictive, 4: D, DC Intra).
+    * - __u16
+      - ``vbv_delay``
+      - Video Buffering Verifier delay, in 90KHz cycles unit.
+    * - __u8
+      - ``full_pel_forward_vector``
+      - If set to 1, forward vectors are expressed in full pixel unit instead
+        half pixel unit.
+    * - __u8
+      - ``full_pel_backward_vector``
+      - If set to 1, backward vectors are expressed in full pixel unit instead
+        half pixel unit.
+    * - __u8
+      - ``f_code[2][2]``
+      - Motion vectors code.
+    * - :cspan:`2`
+
+
+``V4L2_CID_MPEG_VIDEO_MPEG2_PIC_EXT``
+    (enum)
+
+.. tabularcolumns:: |p{4.0cm}|p{2.5cm}|p{11.0cm}|
+
+.. c:type:: v4l2_mpeg_video_mpeg2_pic_ext
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_mpeg_video_mpeg2_pic_ext
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __u8
+      - ``f_code[2][2]``
+      - Motion vectors code.
+    * - __u8
+      - ``intra_dc_precision``
+      - Precision of Discrete Cosine transform (0: 8 bits precision,
+        1: 9 bits precision, 2: 10 bits precision, 11: 11 bits precision).
+    * - __u8
+      - ``picture_structure``
+      - Picture structure (1: interlaced top field,
+        2: interlaced bottom field, 3: progressive frame).
+    * - __u8
+      - ``top_field_first``
+      - If set to 1 and interlaced stream, top field is output first.
+    * - __u8
+      - ``frame_pred_frame_dct``
+      - If set to 1, only frame-DCT and frame prediction are used.
+    * - __u8
+      - ``concealment_motion_vectors``
+      -  If set to 1, motion vectors are coded for intra macroblocks.
+    * - __u8
+      - ``q_scale_type``
+      - This flag affects the inverse quantisation process.
+    * - __u8
+      - ``intra_vlc_format``
+      - This flag affects the decoding of transform coefficient data.
+    * - __u8
+      - ``alternate_scan``
+      - This flag affects the decoding of transform coefficient data.
+    * - __u8
+      - ``repeat_first_field``
+      - This flag affects how the frames or fields are output by decoder.
+    * - __u8
+      - ``chroma_420_type``
+      - Set the same as ``progressive_frame``. Exists for historical reasons.
+    * - __u8
+      - ``progressive_frame``
+      - If this flag is set to 0, the two fields of a frame are two interlaced fields,
+        ``repeat_first_field`` must be 0 (two field duration). If the flag is set to 1,
+        the two fields are merged into one frame, ``picture_structure`` is so set to "Frame"
+        and ``frame_pred_frame_dct`` to 1.
+    * - __u8
+      - ``composite_display``
+      - This flag is set to 1 if pictures are encoded as (analog) composite video.
+    * - __u8
+      - ``v_axis``
+      - Used only when pictures are encoded according to PAL systems. This flag is set to 1
+        on a positive sign, 0 otherwise.
+    * - __u8
+      - ``field_sequence``
+      - Specifies the number of the field of an eight Field Sequence for a PAL system or
+        a five Field Sequence for a NTSC system
+    * - __u8
+      - ``sub_carrier``
+      - If the flag is set to 0, the sub-carrier/line-frequency relationship is correct.
+    * - __u8
+      - ``burst_amplitude``
+      - Specifies the burst amplitude for PAL and NTSC.
+    * - __u8
+      - ``sub_carrier_phase``
+      - Specifies the phase of the reference sub-carrier for the field synchronization.
+    * - :cspan:`2`
+
+
 VPX Control Reference
 ---------------------
 
Documentation/media/uapi/v4l/pixfmt-013.rst +10 -0
index 728d7ed..32c9ef7 100644
@@ -55,11 +55,21 @@ Compressed Formats
       - ``V4L2_PIX_FMT_MPEG1``
       - 'MPG1'
       - MPEG1 video elementary stream.
+    * .. _V4L2-PIX-FMT-MPEG1-PARSED:
+
+      - ``V4L2_PIX_FMT_MPEG1_PARSED``
+      - 'MG1P'
+      - MPEG-1 with parsing metadata given through controls, see :ref:`MPEG-2 Parsed Control IDs<mpeg2-parsed-control-id>`.
     * .. _V4L2-PIX-FMT-MPEG2:
 
       - ``V4L2_PIX_FMT_MPEG2``
       - 'MPG2'
       - MPEG2 video elementary stream.
+    * .. _V4L2-PIX-FMT-MPEG2-PARSED:
+
+      - ``V4L2_PIX_FMT_MPEG2_PARSED``
+      - 'MG2P'
+      - MPEG-2 with parsing metadata given through controls, see :ref:`MPEG-2 Parsed Control IDs<mpeg2-parsed-control-id>`.
     * .. _V4L2-PIX-FMT-MPEG4:
 
       - ``V4L2_PIX_FMT_MPEG4``
drivers/media/v4l2-core/v4l2-ctrls.c +53 -0

77 lines not on this page · raw message

drivers/media/v4l2-core/v4l2-ioctl.c +2 -0
index 0c3f238..55be85d 100644
@@ -1232,7 +1232,9 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
 		case V4L2_PIX_FMT_H264_MVC:	descr = "H.264 MVC"; break;
 		case V4L2_PIX_FMT_H263:		descr = "H.263"; break;
 		case V4L2_PIX_FMT_MPEG1:	descr = "MPEG-1 ES"; break;
+		case V4L2_PIX_FMT_MPEG1_PARSED:	descr = "MPEG-1 with parsing metadata"; break;
 		case V4L2_PIX_FMT_MPEG2:	descr = "MPEG-2 ES"; break;
+		case V4L2_PIX_FMT_MPEG2_PARSED:	descr = "MPEG-2 with parsing metadata"; break;
 		case V4L2_PIX_FMT_MPEG4:	descr = "MPEG-4 part 2 ES"; break;
 		case V4L2_PIX_FMT_XVID:		descr = "Xvid"; break;
 		case V4L2_PIX_FMT_VC1_ANNEX_G:	descr = "VC-1 (SMPTE 412M Annex G)"; break;
include/uapi/linux/v4l2-controls.h +94 -0

100 lines not on this page · raw message

include/uapi/linux/videodev2.h +8 -0
index 46e8a2e3..ada8a62 100644
@@ -623,7 +623,9 @@ struct v4l2_pix_format {
 #define V4L2_PIX_FMT_H264_MVC v4l2_fourcc('M', '2', '6', '4') /* H264 MVC */
 #define V4L2_PIX_FMT_H263     v4l2_fourcc('H', '2', '6', '3') /* H263          */
 #define V4L2_PIX_FMT_MPEG1    v4l2_fourcc('M', 'P', 'G', '1') /* MPEG-1 ES     */
+#define V4L2_PIX_FMT_MPEG1_PARSED v4l2_fourcc('M', 'G', '1', 'P') /* MPEG1 with parsing metadata given through controls */
 #define V4L2_PIX_FMT_MPEG2    v4l2_fourcc('M', 'P', 'G', '2') /* MPEG-2 ES     */
+#define V4L2_PIX_FMT_MPEG2_PARSED v4l2_fourcc('M', 'G', '2', 'P') /* MPEG2 with parsing metadata given through controls */
 #define V4L2_PIX_FMT_MPEG4    v4l2_fourcc('M', 'P', 'G', '4') /* MPEG-4 part 2 ES */
 #define V4L2_PIX_FMT_XVID     v4l2_fourcc('X', 'V', 'I', 'D') /* Xvid           */
 #define V4L2_PIX_FMT_VC1_ANNEX_G v4l2_fourcc('V', 'C', '1', 'G') /* SMPTE 421M Annex G compliant stream */
@@ -1601,6 +1603,12 @@ enum v4l2_ctrl_type {
 	V4L2_CTRL_TYPE_U8	     = 0x0100,
 	V4L2_CTRL_TYPE_U16	     = 0x0101,
 	V4L2_CTRL_TYPE_U32	     = 0x0102,
+	V4L2_CTRL_TYPE_MPEG2_SEQ_HDR  = 0x0109,
+	V4L2_CTRL_TYPE_MPEG2_SEQ_EXT  = 0x010A,
+	V4L2_CTRL_TYPE_MPEG2_SEQ_DISPLAY_EXT  = 0x010B,
+	V4L2_CTRL_TYPE_MPEG2_SEQ_MATRIX_EXT  = 0x010C,
+	V4L2_CTRL_TYPE_MPEG2_PIC_HDR  = 0x010D,
+	V4L2_CTRL_TYPE_MPEG2_PIC_EXT  = 0x010E,
 };
 
 /*  Used in the VIDIOC_QUERYCTRL ioctl for querying controls */
Signature · 1 line
1.9.1
#2 lore raw

PATCH v4 2/3 st-delta: add parsing metadata controls support

In reply to Hugues Fruchet

Install all metadata controls required by registered decoders. Update the decoding context with the set of metadata received from user through extended control.
Set the received metadata in access unit prior to call the decoder decoding ops.

---
 drivers/media/platform/sti/delta/delta-v4l2.c | 125 +++++++++++++++++++++++++-
 drivers/media/platform/sti/delta/delta.h      |  34 +++++++
 2 files changed, 158 insertions(+), 1 deletion(-)
drivers/media/platform/sti/delta/delta-v4l2.c +124 -1
index c6f2e24..1d4436e 100644
@@ -339,6 +339,30 @@ static void register_decoders(struct delta_dev *delta)
 	}
 }
 
+static void register_ctrls(struct delta_dev *delta)
+{
+	const struct delta_dec *dec;
+	unsigned int i, j;
+	u32 meta_cid;
+
+	/* decoders optional meta controls */
+	for (i = 0; i < delta->nb_of_decoders; i++) {
+		dec = delta->decoders[i];
+		if (!dec->meta_cids)
+			continue;
+
+		for (j = 0; j < dec->nb_of_metas; j++) {
+			meta_cid = dec->meta_cids[j];
+			if (!meta_cid)
+				continue;
+
+			delta->cids[delta->nb_of_ctrls++] = meta_cid;
+		}
+	}
+
+	/* add here additional controls if needed */
+}
+
 static void delta_lock(void *priv)
 {
 	struct delta_ctx *ctx = priv;
@@ -355,6 +379,79 @@ static void delta_unlock(void *priv)
 	mutex_unlock(&delta->lock);
 }
 
+static int delta_s_ctrl(struct v4l2_ctrl *ctrl)
+{
+	struct delta_ctx *ctx =
+		container_of(ctrl->handler, struct delta_ctx, ctrl_handler);
+	struct delta_dev *delta = ctx->dev;
+
+	if (ctx->nb_of_metas >= DELTA_MAX_METAS) {
+		dev_err(delta->dev, "%s not enough room to set meta control\n",
+			ctx->name);
+		return -EINVAL;
+	}
+
+	dev_dbg(delta->dev, "%s set metas[%d] from control id=%d (%s)\n",
+		ctx->name, ctx->nb_of_metas, ctrl->id, ctrl->name);
+
+	ctx->metas[ctx->nb_of_metas].cid = ctrl->id;
+	ctx->metas[ctx->nb_of_metas].p = ctrl->p_new.p;
+	ctx->nb_of_metas++;
+
+	return 0;
+}
+
+static const struct v4l2_ctrl_ops delta_ctrl_ops = {
+	.s_ctrl = delta_s_ctrl,
+};
+
+static int delta_ctrls_setup(struct delta_ctx *ctx)
+{
+	struct delta_dev *delta = ctx->dev;
+	struct v4l2_ctrl_handler *hdl = &ctx->ctrl_handler;
+	unsigned int i;
+
+	v4l2_ctrl_handler_init(hdl, delta->nb_of_ctrls);
+
+	for (i = 0; i < delta->nb_of_ctrls; i++) {
+		struct v4l2_ctrl *ctrl;
+		u32 cid = delta->cids[i];
+		struct v4l2_ctrl_config cfg;
+
+		/* override static config to set delta_ctrl_ops */
+		memset(&cfg, 0, sizeof(cfg));
+		cfg.id = cid;
+		cfg.ops = &delta_ctrl_ops;
+
+		ctrl = v4l2_ctrl_new_custom(hdl, &cfg, NULL);
+		if (hdl->error) {
+			int err = hdl->error;
+
+			dev_err(delta->dev, "%s failed to setup control '%s' (id=%d, size=%d, err=%d)\n",
+				ctx->name, cfg.name, cfg.id,
+				cfg.elem_size, err);
+			v4l2_ctrl_handler_free(hdl);
+			return err;
+		}
+
+		/* force unconditional execution of s_ctrl() by
+		 * disabling control value evaluation in case of
+		 * meta control (passed by pointer)
+		 */
+		if (ctrl->is_ptr)
+			ctrl->flags |= V4L2_CTRL_FLAG_EXECUTE_ON_WRITE;
+	}
+
+	v4l2_ctrl_handler_setup(hdl);
+	ctx->fh.ctrl_handler = hdl;
+
+	ctx->nb_of_metas = 0;
+	memset(ctx->metas, 0, sizeof(ctx->metas));
+
+	dev_dbg(delta->dev, "%s controls setup done\n", ctx->name);
+	return 0;
+}
+
 static int delta_open_decoder(struct delta_ctx *ctx, u32 streamformat,
 			      u32 pixelformat, const struct delta_dec **pdec)
 {
@@ -964,6 +1061,12 @@ static void delta_run_work(struct work_struct *work)
 	au->size = vb2_get_plane_payload(&vbuf->vb2_buf, 0);
 	au->dts = vbuf->vb2_buf.timestamp;
 
+	/* set access unit meta data in case of decoder requires it */
+	memcpy(au->metas, ctx->metas, ctx->nb_of_metas * sizeof(au->metas[0]));
+	au->nb_of_metas = ctx->nb_of_metas;
+	/* reset context metas for next decoding */
+	ctx->nb_of_metas = 0;
+
 	/* dump access unit */
 	dump_au(ctx, au);
 
@@ -1364,6 +1467,12 @@ static int delta_vb2_au_start_streaming(struct vb2_queue *q,
 	au->size = vb2_get_plane_payload(&vbuf->vb2_buf, 0);
 	au->dts = vbuf->vb2_buf.timestamp;
 
+	/* set access unit meta data in case of decoder requires it */
+	memcpy(au->metas, ctx->metas, ctx->nb_of_metas * sizeof(au->metas[0]));
+	au->nb_of_metas = ctx->nb_of_metas;
+	/* reset context metas for next decoding */
+	ctx->nb_of_metas = 0;
+
 	delta_push_dts(ctx, au->dts);
 
 	/* dump access unit */
@@ -1659,6 +1768,13 @@ static int delta_open(struct file *file)
 	file->private_data = &ctx->fh;
 	v4l2_fh_add(&ctx->fh);
 
+	ret = delta_ctrls_setup(ctx);
+	if (ret) {
+		dev_err(delta->dev, "%s failed to setup controls (%d)\n",
+			DELTA_PREFIX, ret);
+		goto err_fh_del;
+	}
+
 	INIT_WORK(&ctx->run_work, delta_run_work);
 	mutex_init(&ctx->lock);
 
@@ -1668,7 +1784,7 @@ static int delta_open(struct file *file)
 		ret = PTR_ERR(ctx->fh.m2m_ctx);
 		dev_err(delta->dev, "%s failed to initialize m2m context (%d)\n",
 			DELTA_PREFIX, ret);
-		goto err_fh_del;
+		goto err_ctrls;
 	}
 
 	/*
@@ -1703,6 +1819,8 @@ static int delta_open(struct file *file)
 
 	return 0;
 
+err_ctrls:
+	v4l2_ctrl_handler_free(&ctx->ctrl_handler);
 err_fh_del:
 	v4l2_fh_del(&ctx->fh);
 	v4l2_fh_exit(&ctx->fh);
@@ -1732,6 +1850,8 @@ static int delta_release(struct file *file)
 
 	v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
 
+	v4l2_ctrl_handler_free(&ctx->ctrl_handler);
+
 	v4l2_fh_del(&ctx->fh);
 	v4l2_fh_exit(&ctx->fh);
 
@@ -1887,6 +2007,9 @@ static int delta_probe(struct platform_device *pdev)
 	/* register all supported formats */
 	register_formats(delta);
 
+	/* register all supported controls */
+	register_ctrls(delta);
+
 	/* register on V4L2 */
 	ret = v4l2_device_register(dev, &delta->v4l2_dev);
 	if (ret) {
drivers/media/platform/sti/delta/delta.h +34 -0
index 60c07324..0893948 100644
@@ -8,6 +8,7 @@
 #define DELTA_H
 
 #include <linux/rpmsg.h>
+#include <media/v4l2-ctrls.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-mem2mem.h>
 
@@ -86,6 +87,19 @@ struct delta_streaminfo {
 #define DELTA_STREAMINFO_FLAG_OTHER		0x0004
 
 /*
+ * struct delta_meta - access unit metadata structure.
+ *
+ * @cid:	control identifier for this meta
+ * @p:		pointer to control data
+ */
+struct delta_meta {
+	u32 cid;
+	void *p;
+};
+
+#define DELTA_MAX_METAS 20
+
+/*
  * struct delta_au - access unit structure.
  *
  * @vbuf:	video buffer information for V4L2
@@ -106,6 +120,8 @@ struct delta_au {
 	dma_addr_t paddr;
 	u32 flags;
 	u64 dts;
+	struct delta_meta metas[DELTA_MAX_METAS];
+	unsigned int nb_of_metas;
 };
 
 /*
@@ -229,6 +245,9 @@ struct delta_ipc_param {
  * @name:		name of this decoder
  * @streamformat:	input stream format that this decoder support
  * @pixelformat:	pixel format of decoded frame that this decoder support
+ * @meta_cids:		(optional) meta control identifiers if decoder needs
+ *			additional parsing metadata to be able to decode
+ * @nb_of_metas:	(optional) nb of meta controls
  * @max_width:		(optional) maximum width that can decode this decoder
  *			if not set, maximum width is DELTA_MAX_WIDTH
  * @max_height:		(optional) maximum height that can decode this decoder
@@ -251,6 +270,8 @@ struct delta_dec {
 	const char *name;
 	u32 streamformat;
 	u32 pixelformat;
+	const u32 *meta_cids;
+	unsigned int nb_of_metas;
 	u32 max_width;
 	u32 max_height;
 	bool pm;
@@ -396,11 +417,17 @@ struct delta_dec {
 
 struct delta_dev;
 
+#define DELTA_MAX_CTRLS  (DELTA_MAX_DECODERS * DELTA_MAX_METAS)
+
 /*
  * struct delta_ctx - instance structure.
  *
  * @flags:		validity of fields (streaminfo)
  * @fh:			V4L2 file handle
+ * @ctrl_handler:	controls handler
+ * @metas:		set of parsing metadata required to
+ *			decode the current access unit
+ * @nb_of_metas:	number of metatada
  * @dev:		device context
  * @dec:		selected decoder context for this instance
  * @ipc_ctx:		context of IPC communication with firmware
@@ -433,6 +460,9 @@ struct delta_dec {
 struct delta_ctx {
 	u32 flags;
 	struct v4l2_fh fh;
+	struct v4l2_ctrl_handler ctrl_handler;
+	struct delta_meta metas[DELTA_MAX_METAS];
+	unsigned int nb_of_metas;
 	struct delta_dev *dev;
 	const struct delta_dec *dec;
 	struct delta_ipc_ctx ipc_ctx;
@@ -483,6 +513,8 @@ struct delta_ctx {
  * @nb_of_pixelformats:	number of supported umcompressed video formats
  * @streamformats:	supported compressed video formats
  * @nb_of_streamformats:number of supported compressed video formats
+ * @cids:		set of all control identifiers used by device
+ * @nb_of_ctrls:	overall number of controls used by device
  * @instance_id:	rolling counter identifying an instance (debug purpose)
  * @work_queue:		decoding job work queue
  * @rpmsg_driver:	rpmsg IPC driver
@@ -504,6 +536,8 @@ struct delta_dev {
 	u32 nb_of_pixelformats;
 	u32 streamformats[DELTA_MAX_FORMATS];
 	u32 nb_of_streamformats;
+	u32 cids[DELTA_MAX_CTRLS];
+	u32 nb_of_ctrls;
 	u8 instance_id;
 	struct workqueue_struct *work_queue;
 	struct rpmsg_driver rpmsg_driver;
Signature · 1 line
1.9.1
#3 lore raw

PATCH v4 3/3 st-delta: add mpeg2 support

In reply to Hugues Fruchet

Adds support of DELTA MPEG-2 video decoder back-end, implemented by calling MPEG2_TRANSFORMER0 firmware using RPMSG IPC communication layer.
MPEG-2 decoder back-end is a stateless decoder which require specific parsing metadata in access unit in order to complete decoding.

---
 drivers/media/platform/Kconfig                     |   11 +-
 drivers/media/platform/sti/delta/Makefile          |    3 +
 drivers/media/platform/sti/delta/delta-cfg.h       |    5 +
 drivers/media/platform/sti/delta/delta-mpeg2-dec.c | 1401 ++++++++++++++++++++
 drivers/media/platform/sti/delta/delta-mpeg2-fw.h  |  423 ++++++
 drivers/media/platform/sti/delta/delta-v4l2.c      |    4 +
 6 files changed, 1845 insertions(+), 2 deletions(-)
 create mode 100644 drivers/media/platform/sti/delta/delta-mpeg2-dec.c
 create mode 100644 drivers/media/platform/sti/delta/delta-mpeg2-fw.h
drivers/media/platform/Kconfig +9 -2
index c9106e1..bf9695a 100644
@@ -340,15 +340,22 @@ config VIDEO_STI_DELTA_MJPEG
 		To compile this driver as a module, choose M here:
 		the module will be called st-delta.
 
+config VIDEO_STI_DELTA_MPEG2
+	bool "STMicroelectronics DELTA MPEG2/MPEG1 support"
+	default y
+	help
+		Enables DELTA MPEG2 hardware support.
+
 config VIDEO_STI_DELTA_DRIVER
 	tristate
 	depends on VIDEO_STI_DELTA
-	depends on VIDEO_STI_DELTA_MJPEG
-	default VIDEO_STI_DELTA_MJPEG
+	depends on VIDEO_STI_DELTA_MJPEG || VIDEO_STI_DELTA_MPEG2
+	default y
 	select VIDEOBUF2_DMA_CONTIG
 	select V4L2_MEM2MEM_DEV
 	select RPMSG
 
+
 endif # VIDEO_STI_DELTA
 
 config VIDEO_SH_VEU
drivers/media/platform/sti/delta/Makefile +3 -0
index 8d032508..b18ed37 100644
@@ -4,3 +4,6 @@ st-delta-y := delta-v4l2.o delta-mem.o delta-ipc.o delta-debug.o
 # MJPEG support
 st-delta-$(CONFIG_VIDEO_STI_DELTA_MJPEG) += delta-mjpeg-hdr.o
 st-delta-$(CONFIG_VIDEO_STI_DELTA_MJPEG) += delta-mjpeg-dec.o
+
+# MPEG2 support
+st-delta-$(CONFIG_VIDEO_STI_DELTA_MPEG2) += delta-mpeg2-dec.o
drivers/media/platform/sti/delta/delta-cfg.h +5 -0
index c6388f5..bce2c74 100644
@@ -61,4 +61,9 @@
 extern const struct delta_dec mjpegdec;
 #endif
 
+#ifdef CONFIG_VIDEO_STI_DELTA_MPEG2
+extern const struct delta_dec mpeg2dec;
+extern const struct delta_dec mpeg1dec;
+#endif
+
 #endif /* DELTA_CFG_H */
drivers/media/platform/sti/delta/delta-mpeg2-dec.c new file +1401 -0

1,401 lines not on this page · raw message

drivers/media/platform/sti/delta/delta-mpeg2-fw.h new file +423 -0

423 lines not on this page · raw message

drivers/media/platform/sti/delta/delta-v4l2.c +4 -0
index 1d4436e..8b00c81 100644
@@ -36,6 +36,10 @@
 #ifdef CONFIG_VIDEO_STI_DELTA_MJPEG
 	&mjpegdec,
 #endif
+#ifdef CONFIG_VIDEO_STI_DELTA_MPEG2
+	&mpeg2dec,
+	&mpeg1dec,
+#endif
 };
 
 static inline int frame_size(u32 w, u32 h, u32 fmt)
Signature · 1 line
1.9.1