Add MPEG 4 codec

This patch introduces the support of MPEG4 video decoding. It basically
just copies data from VA's frame/slice headers data structures to v4l's
MPEG4 frame header extended controls data structures.
This commit is contained in:
Florent Revest
2016-08-25 15:50:40 +02:00
parent 728b1b41b9
commit f645948921
8 changed files with 232 additions and 2 deletions
+1
View File
@@ -15,3 +15,4 @@ backend:
Sample media files can be found here:
http://samplemedia.linaro.org/MPEG2/
http://samplemedia.linaro.org/MPEG4/SVT/
+2 -2
View File
@@ -20,13 +20,13 @@ driver_libs = \
$(LIBVA_DEPS_LIBS)
source_c = sunxi_cedrus_drv_video.c object_heap.c buffer.c va_config.c \
context.c image.c mpeg2.c picture.c subpicture.c surface.c
context.c image.c mpeg2.c mpeg4.c picture.c subpicture.c surface.c
source_s = \
tiled_yuv.S
source_h = sunxi_cedrus_drv_video.h object_heap.h buffer.h va_config.h \
context.h image.h mpeg2.h picture.h subpicture.h surface.h \
context.h image.h mpeg2.h mpeg4.h picture.h subpicture.h surface.h \
tiled_yuv.h
sunxi_cedrus_drv_video_la_LTLIBRARIES = sunxi_cedrus_drv_video.la
+5
View File
@@ -121,6 +121,11 @@ VAStatus sunxi_cedrus_CreateContext(VADriverContextP ctx, VAConfigID config_id,
case VAProfileMPEG2Main:
fmt.fmt.pix_mp.pixelformat = V4L2_PIX_FMT_MPEG2_FRAME;
break;
case VAProfileMPEG4Simple:
case VAProfileMPEG4AdvancedSimple:
case VAProfileMPEG4Main:
fmt.fmt.pix_mp.pixelformat = V4L2_PIX_FMT_MPEG4_FRAME;
break;
default:
vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
return vaStatus;
+1
View File
@@ -52,6 +52,7 @@ struct object_context {
uint32_t num_rendered_surfaces;
struct v4l2_ctrl_mpeg2_frame_hdr mpeg2_frame_hdr;
struct v4l2_ctrl_mpeg4_frame_hdr mpeg4_frame_hdr;
};
typedef struct object_context *object_context_p;
+134
View File
@@ -0,0 +1,134 @@
/*
* Copyright (c) 2016 Florent Revest, <florent.revest@free-electrons.com>
* 2007 Intel Corporation. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "sunxi_cedrus_drv_video.h"
#include "mpeg4.h"
#include <assert.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <linux/videodev2.h>
/*
* This file takes care of filling v4l2's frame API MPEG4 headers extended
* controls from VA's data structures.
*/
VAStatus sunxi_cedrus_render_mpeg4_slice_data(VADriverContextP ctx,
object_context_p obj_context, object_surface_p obj_surface,
object_buffer_p obj_buffer)
{
INIT_DRIVER_DATA
VAStatus vaStatus = VA_STATUS_SUCCESS;
struct v4l2_buffer buf;
struct v4l2_plane plane[1];
/* Query */
memset(&(buf), 0, sizeof(buf));
buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
buf.memory = V4L2_MEMORY_MMAP;
buf.index = obj_surface->input_buf_index;
buf.length = 1;
buf.m.planes = plane;
assert(ioctl(driver_data->mem2mem_fd, VIDIOC_QUERYBUF, &buf)==0);
/* Populate frame */
char *src_buf = mmap(NULL, obj_buffer->size,
PROT_READ | PROT_WRITE, MAP_SHARED,
driver_data->mem2mem_fd, buf.m.planes[0].m.mem_offset);
assert(src_buf != MAP_FAILED);
memcpy(src_buf, obj_buffer->buffer_data, obj_buffer->size);
return vaStatus;
}
VAStatus sunxi_cedrus_render_mpeg4_picture_parameter(VADriverContextP ctx,
object_context_p obj_context, object_surface_p obj_surface,
object_buffer_p obj_buffer)
{
INIT_DRIVER_DATA
VAStatus vaStatus = VA_STATUS_SUCCESS;
VAPictureParameterBufferMPEG4 *pic_param = (VAPictureParameterBufferMPEG4 *)obj_buffer->buffer_data;
obj_context->mpeg4_frame_hdr.width = pic_param->vop_width;
obj_context->mpeg4_frame_hdr.height = pic_param->vop_height;
obj_context->mpeg4_frame_hdr.vol_fields.short_video_header = pic_param->vol_fields.bits.short_video_header;
obj_context->mpeg4_frame_hdr.vol_fields.chroma_format = pic_param->vol_fields.bits.chroma_format;
obj_context->mpeg4_frame_hdr.vol_fields.interlaced = pic_param->vol_fields.bits.interlaced;
obj_context->mpeg4_frame_hdr.vol_fields.obmc_disable = pic_param->vol_fields.bits.obmc_disable;
obj_context->mpeg4_frame_hdr.vol_fields.sprite_enable = pic_param->vol_fields.bits.sprite_enable;
obj_context->mpeg4_frame_hdr.vol_fields.sprite_warping_accuracy = pic_param->vol_fields.bits.sprite_warping_accuracy;
obj_context->mpeg4_frame_hdr.vol_fields.quant_type = pic_param->vol_fields.bits.quant_type;
obj_context->mpeg4_frame_hdr.vol_fields.quarter_sample = pic_param->vol_fields.bits.quarter_sample;
obj_context->mpeg4_frame_hdr.vol_fields.data_partitioned = pic_param->vol_fields.bits.data_partitioned;
obj_context->mpeg4_frame_hdr.vol_fields.reversible_vlc = pic_param->vol_fields.bits.reversible_vlc;
obj_context->mpeg4_frame_hdr.vol_fields.resync_marker_disable = pic_param->vol_fields.bits.resync_marker_disable;
obj_context->mpeg4_frame_hdr.vop_fields.vop_coding_type = pic_param->vop_fields.bits.vop_coding_type;
obj_context->mpeg4_frame_hdr.vop_fields.backward_reference_vop_coding_type = pic_param->vop_fields.bits.backward_reference_vop_coding_type;
obj_context->mpeg4_frame_hdr.vop_fields.vop_rounding_type = pic_param->vop_fields.bits.vop_rounding_type;
obj_context->mpeg4_frame_hdr.vop_fields.intra_dc_vlc_thr = pic_param->vop_fields.bits.intra_dc_vlc_thr;
obj_context->mpeg4_frame_hdr.vop_fields.top_field_first = pic_param->vop_fields.bits.top_field_first;
obj_context->mpeg4_frame_hdr.vop_fields.alternate_vertical_scan_flag = pic_param->vop_fields.bits.alternate_vertical_scan_flag;
obj_context->mpeg4_frame_hdr.vop_fcode_forward = pic_param->vop_fcode_forward;
obj_context->mpeg4_frame_hdr.vop_fcode_backward = pic_param->vop_fcode_backward;
obj_context->mpeg4_frame_hdr.trb = pic_param->TRB;
obj_context->mpeg4_frame_hdr.trd = pic_param->TRD;
object_surface_p fwd_surface = SURFACE(pic_param->forward_reference_picture);
if(fwd_surface)
obj_context->mpeg4_frame_hdr.forward_index = fwd_surface->output_buf_index;
else
obj_context->mpeg4_frame_hdr.forward_index = obj_surface->output_buf_index;
object_surface_p bwd_surface = SURFACE(pic_param->backward_reference_picture);
if(bwd_surface)
obj_context->mpeg4_frame_hdr.backward_index = bwd_surface->output_buf_index;
else
obj_context->mpeg4_frame_hdr.backward_index = obj_surface->output_buf_index;
return vaStatus;
}
VAStatus sunxi_cedrus_render_mpeg4_slice_parameter(VADriverContextP ctx,
object_context_p obj_context, object_surface_p obj_surface,
object_buffer_p obj_buffer)
{
VASliceParameterBufferMPEG4 *slice_param = (VASliceParameterBufferMPEG4 *)obj_buffer->buffer_data;
obj_context->mpeg4_frame_hdr.slice_pos = slice_param->slice_data_offset*8+slice_param->macroblock_offset;
obj_context->mpeg4_frame_hdr.slice_len = slice_param->slice_data_size*8;
obj_context->mpeg4_frame_hdr.quant_scale = slice_param->quant_scale;
return VA_STATUS_SUCCESS;
}
+48
View File
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2016 Florent Revest, <florent.revest@free-electrons.com>
* 2007 Intel Corporation. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef _MPEG4_H_
#define _MPEG4_H_
#include <va/va_backend.h>
#include "context.h"
#include "buffer.h"
#include "surface.h"
VAStatus sunxi_cedrus_render_mpeg4_slice_data(VADriverContextP ctx,
object_context_p obj_context, object_surface_p obj_surface,
object_buffer_p obj_buffer);
VAStatus sunxi_cedrus_render_mpeg4_picture_parameter(VADriverContextP ctx,
object_context_p obj_context, object_surface_p obj_surface,
object_buffer_p obj_buffer);
VAStatus sunxi_cedrus_render_mpeg4_slice_parameter(VADriverContextP ctx,
object_context_p obj_context, object_surface_p obj_surface,
object_buffer_p obj_buffer);
#endif /* _MPEG4_H_ */
+19
View File
@@ -31,6 +31,7 @@
#include "va_config.h"
#include "mpeg2.h"
#include "mpeg4.h"
#include <assert.h>
#include <string.h>
@@ -118,6 +119,16 @@ VAStatus sunxi_cedrus_RenderPicture(VADriverContextP ctx, VAContextID context,
else if(obj_buffer->type == VAPictureParameterBufferType)
vaStatus = sunxi_cedrus_render_mpeg2_picture_parameter(ctx, obj_context, obj_surface, obj_buffer);
break;
case VAProfileMPEG4Simple:
case VAProfileMPEG4AdvancedSimple:
case VAProfileMPEG4Main:
if(obj_buffer->type == VASliceDataBufferType)
vaStatus = sunxi_cedrus_render_mpeg4_slice_data(ctx, obj_context, obj_surface, obj_buffer);
else if(obj_buffer->type == VAPictureParameterBufferType)
vaStatus = sunxi_cedrus_render_mpeg4_picture_parameter(ctx, obj_context, obj_surface, obj_buffer);
else if(obj_buffer->type == VASliceParameterBufferType)
vaStatus = sunxi_cedrus_render_mpeg4_slice_parameter(ctx, obj_context, obj_surface, obj_buffer);
break;
default:
break;
}
@@ -168,6 +179,14 @@ VAStatus sunxi_cedrus_EndPicture(VADriverContextP ctx, VAContextID context)
ctrl.ptr = &obj_context->mpeg2_frame_hdr;
ctrl.size = sizeof(obj_context->mpeg2_frame_hdr);
break;
case VAProfileMPEG4Simple:
case VAProfileMPEG4AdvancedSimple:
case VAProfileMPEG4Main:
out_buf.m.planes[0].bytesused = obj_context->mpeg4_frame_hdr.slice_len/8;
ctrl.id = V4L2_CID_MPEG_VIDEO_MPEG4_FRAME_HDR;
ctrl.ptr = &obj_context->mpeg4_frame_hdr;
ctrl.size = sizeof(obj_context->mpeg4_frame_hdr);
break;
default:
out_buf.m.planes[0].bytesused = 0;
ctrl.id = V4L2_CID_MPEG_VIDEO_MPEG2_FRAME_HDR;
+22
View File
@@ -56,6 +56,12 @@ VAStatus sunxi_cedrus_QueryConfigProfiles(VADriverContextP ctx,
profile_list[i++] = VAProfileMPEG2Simple;
profile_list[i++] = VAProfileMPEG2Main;
break;
case V4L2_PIX_FMT_MPEG4_FRAME:
profile_list[i++] = VAProfileMPEG4Simple;
profile_list[i++] = VAProfileMPEG4AdvancedSimple;
profile_list[i++] = VAProfileMPEG4Main;
break;
}
vid_fmtdesc.index++;
}
@@ -77,6 +83,13 @@ VAStatus sunxi_cedrus_QueryConfigEntrypoints(VADriverContextP ctx,
entrypoint_list[1] = VAEntrypointMoComp;
break;
case VAProfileMPEG4Simple:
case VAProfileMPEG4AdvancedSimple:
case VAProfileMPEG4Main:
*num_entrypoints = 1;
entrypoint_list[0] = VAEntrypointVLD;
break;
default:
*num_entrypoints = 0;
break;
@@ -156,6 +169,15 @@ VAStatus sunxi_cedrus_CreateConfig(VADriverContextP ctx, VAProfile profile,
vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
break;
case VAProfileMPEG4Simple:
case VAProfileMPEG4AdvancedSimple:
case VAProfileMPEG4Main:
if (VAEntrypointVLD == entrypoint)
vaStatus = VA_STATUS_SUCCESS;
else
vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
break;
default:
vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
break;