/* SPDX-License-Identifier: GPL-2.0 */ /* * Copyright (C) STMicroelectronics SA 2015 * Author: Hugues Fruchet <[email protected]> for STMicroelectronics. */ #ifndef DELTA_H #define DELTA_H #include <linux/rpmsg.h> #include <media/v4l2-device.h> #include <media/v4l2-mem2mem.h> #include "delta-cfg.h" /* * enum delta_state - state of decoding instance * *@DELTA_STATE_WF_FORMAT: * Wait for compressed format to be set by V4L2 client in order * to know what is the relevant decoder to open. * *@DELTA_STATE_WF_STREAMINFO: * Wait for stream information to be available (bitstream * header parsing is done). * *@DELTA_STATE_READY: * Decoding instance is ready to decode compressed access unit. * *@DELTA_STATE_WF_EOS: * Decoding instance is waiting for EOS (End Of Stream) completion. * *@DELTA_STATE_EOS: * EOS (End Of Stream) is completed (signaled to user). Decoding instance * should then be closed. */ enum delta_state { … }; /* * struct delta_streaminfo - information about stream to decode * * @flags: validity of fields (crop, pixelaspect, other) * @width: width of video stream * @height: height "" * @streamformat: fourcc compressed format of video (MJPEG, MPEG2, ...) * @dpb: number of frames needed to decode a single frame * (h264 dpb, up to 16) * @crop: cropping window inside decoded frame (1920x1080@0,0 * inside 1920x1088 frame for ex.) * @pixelaspect: pixel aspect ratio of video (4/3, 5/4) * @field: interlaced or not * @profile: profile string * @level: level string * @other: other string information from codec * @colorspace: colorspace identifier * @xfer_func: transfer function identifier * @ycbcr_enc: Y'CbCr encoding identifier * @quantization: quantization identifier */ struct delta_streaminfo { … }; #define DELTA_STREAMINFO_FLAG_CROP … #define DELTA_STREAMINFO_FLAG_PIXELASPECT … #define DELTA_STREAMINFO_FLAG_OTHER … /* * struct delta_au - access unit structure. * * @vbuf: video buffer information for V4L2 * @list: V4L2 m2m list that the frame belongs to * @prepared: if set vaddr/paddr are resolved * @vaddr: virtual address (kernel can read/write) * @paddr: physical address (for hardware) * @flags: access unit type (V4L2_BUF_FLAG_KEYFRAME/PFRAME/BFRAME) * @dts: decoding timestamp of this access unit */ struct delta_au { … }; /* * struct delta_frameinfo - information about decoded frame * * @flags: validity of fields (crop, pixelaspect) * @pixelformat: fourcc code for uncompressed video format * @width: width of frame * @height: height of frame * @aligned_width: width of frame (with encoder or decoder alignment * constraint) * @aligned_height: height of frame (with encoder or decoder alignment * constraint) * @size: maximum size in bytes required for data * @crop: cropping window inside frame (1920x1080@0,0 * inside 1920x1088 frame for ex.) * @pixelaspect: pixel aspect ratio of video (4/3, 5/4) * @field: interlaced mode * @colorspace: colorspace identifier * @xfer_func: transfer function identifier * @ycbcr_enc: Y'CbCr encoding identifier * @quantization: quantization identifier */ struct delta_frameinfo { … }; #define DELTA_FRAMEINFO_FLAG_CROP … #define DELTA_FRAMEINFO_FLAG_PIXELASPECT … /* * struct delta_frame - frame structure. * * @vbuf: video buffer information for V4L2 * @list: V4L2 m2m list that the frame belongs to * @info: frame information (width, height, format, alignment...) * @prepared: if set pix/vaddr/paddr are resolved * @index: frame index, aligned on V4L2 wow * @vaddr: virtual address (kernel can read/write) * @paddr: physical address (for hardware) * @state: frame state for frame lifecycle tracking * (DELTA_FRAME_FREE/DEC/OUT/REC/...) * @flags: frame type (V4L2_BUF_FLAG_KEYFRAME/PFRAME/BFRAME) * @dts: decoding timestamp of this frame * @field: field order for interlaced frame */ struct delta_frame { … }; /* frame state for frame lifecycle tracking */ #define DELTA_FRAME_FREE … #define DELTA_FRAME_REF … #define DELTA_FRAME_BSY … #define DELTA_FRAME_DEC … #define DELTA_FRAME_OUT … #define DELTA_FRAME_RDY … #define DELTA_FRAME_M2M … /* * struct delta_dts - decoding timestamp. * * @list: list to chain timestamps * @val: timestamp in microseconds */ struct delta_dts { … }; struct delta_buf { … }; struct delta_ipc_ctx { … }; struct delta_ipc_param { … }; struct delta_ctx; /* * struct delta_dec - decoder structure. * * @name: name of this decoder * @streamformat: input stream format that this decoder support * @pixelformat: pixel format of decoded frame that this decoder support * @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 * if not set, maximum height is DELTA_MAX_HEIGHT * @pm: (optional) if set, decoder will manage power on its own * @open: open this decoder * @close: close this decoder * @setup_frame: setup frame to be used by decoder, see below * @get_streaminfo: get stream related infos, see below * @get_frameinfo: get decoded frame related infos, see below * @set_frameinfo: (optional) set decoded frame related infos, see below * @setup_frame: setup frame to be used by decoder, see below * @decode: decode a single access unit, see below * @get_frame: get the next decoded frame available, see below * @recycle: recycle the given frame, see below * @flush: (optional) flush decoder, see below * @drain: (optional) drain decoder, see below */ struct delta_dec { … }; struct delta_dev; /* * struct delta_ctx - instance structure. * * @flags: validity of fields (streaminfo) * @fh: V4L2 file handle * @dev: device context * @dec: selected decoder context for this instance * @ipc_ctx: context of IPC communication with firmware * @state: instance state * @frame_num: frame number * @au_num: access unit number * @max_au_size: max size of an access unit * @streaminfo: stream information (width, height, dpb, interlacing...) * @frameinfo: frame information (width, height, format, alignment...) * @nb_of_frames: number of frames available for decoding * @frames: array of decoding frames to keep track of frame * state and manage frame recycling * @decoded_frames: nb of decoded frames from opening * @output_frames: nb of output frames from opening * @dropped_frames: nb of frames dropped (ie access unit not parsed * or frame decoded but not output) * @stream_errors: nb of stream errors (corrupted, not supported, ...) * @decode_errors: nb of decode errors (firmware error) * @sys_errors: nb of system errors (memory, ipc, ...) * @dts: FIFO of decoding timestamp. * output frames are timestamped with incoming access * unit timestamps using this fifo. * @name: string naming this instance (debug purpose) * @run_work: decoding work * @lock: lock for decoding work serialization * @aborting: true if current job aborted * @priv: private decoder context for this instance, allocated * by decoder @open time. */ struct delta_ctx { … }; #define DELTA_FLAG_STREAMINFO … #define DELTA_FLAG_FRAMEINFO … #define DELTA_MAX_FORMATS … /* * struct delta_dev - device struct, 1 per probe (so single one for * all platform life) * * @v4l2_dev: v4l2 device * @vdev: v4l2 video device * @pdev: platform device * @dev: device * @m2m_dev: memory-to-memory V4L2 device * @lock: device lock, for crit section & V4L2 ops serialization. * @clk_delta: delta main clock * @clk_st231: st231 coprocessor main clock * @clk_flash_promip: flash promip clock * @decoders: list of registered decoders * @nb_of_decoders: nb of registered decoders * @pixelformats: supported uncompressed video formats * @nb_of_pixelformats: number of supported umcompressed video formats * @streamformats: supported compressed video formats * @nb_of_streamformats:number of supported compressed video formats * @instance_id: rolling counter identifying an instance (debug purpose) * @work_queue: decoding job work queue * @rpmsg_driver: rpmsg IPC driver * @rpmsg_device: rpmsg IPC device */ struct delta_dev { … }; static inline char *frame_type_str(u32 flags) { … } static inline char *frame_field_str(enum v4l2_field field) { … } static inline char *frame_state_str(u32 state, char *str, unsigned int len) { … } int delta_get_frameinfo_default(struct delta_ctx *ctx, struct delta_frameinfo *frameinfo); int delta_recycle_default(struct delta_ctx *pctx, struct delta_frame *frame); int delta_get_free_frame(struct delta_ctx *ctx, struct delta_frame **pframe); int delta_get_sync(struct delta_ctx *ctx); void delta_put_autosuspend(struct delta_ctx *ctx); #endif /* DELTA_H */