Add MPEG 2 codec
This patch introduces the support of MPEG2 video decoding. It basically just copies data from VA's frame/slice headers data structures to v4l's MPEG2 frame header extended controls data structures.
This commit is contained in:
@@ -10,3 +10,8 @@ You can try this driver with VLC but don't forget to tell libVA to use this
|
|||||||
backend:
|
backend:
|
||||||
|
|
||||||
export LIBVA_DRIVER_NAME=sunxi_cedrus
|
export LIBVA_DRIVER_NAME=sunxi_cedrus
|
||||||
|
vlc big_buck_bunny_480p_MPEG2_MP2_25fps_1800K.MPG
|
||||||
|
|
||||||
|
Sample media files can be found here:
|
||||||
|
|
||||||
|
http://samplemedia.linaro.org/MPEG2/
|
||||||
|
|||||||
+2
-2
@@ -20,13 +20,13 @@ driver_libs = \
|
|||||||
$(LIBVA_DEPS_LIBS)
|
$(LIBVA_DEPS_LIBS)
|
||||||
|
|
||||||
source_c = sunxi_cedrus_drv_video.c object_heap.c buffer.c va_config.c \
|
source_c = sunxi_cedrus_drv_video.c object_heap.c buffer.c va_config.c \
|
||||||
context.c image.c picture.c subpicture.c surface.c
|
context.c image.c mpeg2.c picture.c subpicture.c surface.c
|
||||||
|
|
||||||
source_s = \
|
source_s = \
|
||||||
tiled_yuv.S
|
tiled_yuv.S
|
||||||
|
|
||||||
source_h = sunxi_cedrus_drv_video.h object_heap.h buffer.h va_config.h \
|
source_h = sunxi_cedrus_drv_video.h object_heap.h buffer.h va_config.h \
|
||||||
context.h image.h picture.h subpicture.h surface.h \
|
context.h image.h mpeg2.h picture.h subpicture.h surface.h \
|
||||||
tiled_yuv.h
|
tiled_yuv.h
|
||||||
|
|
||||||
sunxi_cedrus_drv_video_la_LTLIBRARIES = sunxi_cedrus_drv_video.la
|
sunxi_cedrus_drv_video_la_LTLIBRARIES = sunxi_cedrus_drv_video.la
|
||||||
|
|||||||
@@ -117,6 +117,10 @@ VAStatus sunxi_cedrus_CreateContext(VADriverContextP ctx, VAConfigID config_id,
|
|||||||
fmt.fmt.pix_mp.height = picture_height;
|
fmt.fmt.pix_mp.height = picture_height;
|
||||||
fmt.fmt.pix_mp.plane_fmt[0].sizeimage = INPUT_BUFFER_MAX_SIZE;
|
fmt.fmt.pix_mp.plane_fmt[0].sizeimage = INPUT_BUFFER_MAX_SIZE;
|
||||||
switch(obj_config->profile) {
|
switch(obj_config->profile) {
|
||||||
|
case VAProfileMPEG2Simple:
|
||||||
|
case VAProfileMPEG2Main:
|
||||||
|
fmt.fmt.pix_mp.pixelformat = V4L2_PIX_FMT_MPEG2_FRAME;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
|
vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
|
||||||
return vaStatus;
|
return vaStatus;
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ struct object_context {
|
|||||||
int flags;
|
int flags;
|
||||||
VASurfaceID *render_targets;
|
VASurfaceID *render_targets;
|
||||||
uint32_t num_rendered_surfaces;
|
uint32_t num_rendered_surfaces;
|
||||||
|
|
||||||
|
struct v4l2_ctrl_mpeg2_frame_hdr mpeg2_frame_hdr;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct object_context *object_context_p;
|
typedef struct object_context *object_context_p;
|
||||||
|
|||||||
+116
@@ -0,0 +1,116 @@
|
|||||||
|
/*
|
||||||
|
* 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 "mpeg2.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 MPEG2 headers extended
|
||||||
|
* controls from VA's data structures.
|
||||||
|
*/
|
||||||
|
|
||||||
|
VAStatus sunxi_cedrus_render_mpeg2_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);
|
||||||
|
|
||||||
|
obj_context->mpeg2_frame_hdr.slice_pos = 0;
|
||||||
|
obj_context->mpeg2_frame_hdr.slice_len = obj_buffer->size*8;
|
||||||
|
|
||||||
|
return vaStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
VAStatus sunxi_cedrus_render_mpeg2_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;
|
||||||
|
|
||||||
|
VAPictureParameterBufferMPEG2 *pic_param = (VAPictureParameterBufferMPEG2 *)obj_buffer->buffer_data;
|
||||||
|
obj_context->mpeg2_frame_hdr.type = MPEG2;
|
||||||
|
|
||||||
|
obj_context->mpeg2_frame_hdr.width = pic_param->horizontal_size;
|
||||||
|
obj_context->mpeg2_frame_hdr.height = pic_param->vertical_size;
|
||||||
|
|
||||||
|
obj_context->mpeg2_frame_hdr.picture_coding_type = pic_param->picture_coding_type;
|
||||||
|
obj_context->mpeg2_frame_hdr.f_code[0][0] = (pic_param->f_code >> 12) & 0xf;
|
||||||
|
obj_context->mpeg2_frame_hdr.f_code[0][1] = (pic_param->f_code >> 8) & 0xf;
|
||||||
|
obj_context->mpeg2_frame_hdr.f_code[1][0] = (pic_param->f_code >> 4) & 0xf;
|
||||||
|
obj_context->mpeg2_frame_hdr.f_code[1][1] = pic_param->f_code & 0xf;
|
||||||
|
|
||||||
|
obj_context->mpeg2_frame_hdr.intra_dc_precision = pic_param->picture_coding_extension.bits.intra_dc_precision;
|
||||||
|
obj_context->mpeg2_frame_hdr.picture_structure = pic_param->picture_coding_extension.bits.picture_structure;
|
||||||
|
obj_context->mpeg2_frame_hdr.top_field_first = pic_param->picture_coding_extension.bits.top_field_first;
|
||||||
|
obj_context->mpeg2_frame_hdr.frame_pred_frame_dct = pic_param->picture_coding_extension.bits.frame_pred_frame_dct;
|
||||||
|
obj_context->mpeg2_frame_hdr.concealment_motion_vectors = pic_param->picture_coding_extension.bits.concealment_motion_vectors;
|
||||||
|
obj_context->mpeg2_frame_hdr.q_scale_type = pic_param->picture_coding_extension.bits.q_scale_type;
|
||||||
|
obj_context->mpeg2_frame_hdr.intra_vlc_format = pic_param->picture_coding_extension.bits.intra_vlc_format;
|
||||||
|
obj_context->mpeg2_frame_hdr.alternate_scan = pic_param->picture_coding_extension.bits.alternate_scan;
|
||||||
|
|
||||||
|
object_surface_p fwd_surface = SURFACE(pic_param->forward_reference_picture);
|
||||||
|
if(fwd_surface)
|
||||||
|
obj_context->mpeg2_frame_hdr.forward_index = fwd_surface->output_buf_index;
|
||||||
|
else
|
||||||
|
obj_context->mpeg2_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->mpeg2_frame_hdr.backward_index = bwd_surface->output_buf_index;
|
||||||
|
else
|
||||||
|
obj_context->mpeg2_frame_hdr.backward_index = obj_surface->output_buf_index;
|
||||||
|
|
||||||
|
return vaStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* 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 _MPEG2_H_
|
||||||
|
#define _MPEG2_H_
|
||||||
|
|
||||||
|
#include <va/va_backend.h>
|
||||||
|
|
||||||
|
#include "context.h"
|
||||||
|
#include "buffer.h"
|
||||||
|
|
||||||
|
#include "surface.h"
|
||||||
|
|
||||||
|
VAStatus sunxi_cedrus_render_mpeg2_slice_data(VADriverContextP ctx,
|
||||||
|
object_context_p obj_context, object_surface_p obj_surface,
|
||||||
|
object_buffer_p obj_buffer);
|
||||||
|
|
||||||
|
VAStatus sunxi_cedrus_render_mpeg2_picture_parameter(VADriverContextP ctx,
|
||||||
|
object_context_p obj_context, object_surface_p obj_surface,
|
||||||
|
object_buffer_p obj_buffer);
|
||||||
|
|
||||||
|
#endif /* _MPEG2_H_ */
|
||||||
@@ -30,6 +30,8 @@
|
|||||||
#include "surface.h"
|
#include "surface.h"
|
||||||
#include "va_config.h"
|
#include "va_config.h"
|
||||||
|
|
||||||
|
#include "mpeg2.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -107,6 +109,18 @@ VAStatus sunxi_cedrus_RenderPicture(VADriverContextP ctx, VAContextID context,
|
|||||||
vaStatus = VA_STATUS_ERROR_INVALID_BUFFER;
|
vaStatus = VA_STATUS_ERROR_INVALID_BUFFER;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch(obj_config->profile) {
|
||||||
|
case VAProfileMPEG2Simple:
|
||||||
|
case VAProfileMPEG2Main:
|
||||||
|
if(obj_buffer->type == VASliceDataBufferType)
|
||||||
|
vaStatus = sunxi_cedrus_render_mpeg2_slice_data(ctx, obj_context, obj_surface, obj_buffer);
|
||||||
|
else if(obj_buffer->type == VAPictureParameterBufferType)
|
||||||
|
vaStatus = sunxi_cedrus_render_mpeg2_picture_parameter(ctx, obj_context, obj_surface, obj_buffer);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return vaStatus;
|
return vaStatus;
|
||||||
@@ -147,6 +161,13 @@ VAStatus sunxi_cedrus_EndPicture(VADriverContextP ctx, VAContextID context)
|
|||||||
out_buf.request = obj_surface->request;
|
out_buf.request = obj_surface->request;
|
||||||
|
|
||||||
switch(obj_config->profile) {
|
switch(obj_config->profile) {
|
||||||
|
case VAProfileMPEG2Simple:
|
||||||
|
case VAProfileMPEG2Main:
|
||||||
|
out_buf.m.planes[0].bytesused = obj_context->mpeg2_frame_hdr.slice_len/8;
|
||||||
|
ctrl.id = V4L2_CID_MPEG_VIDEO_MPEG2_FRAME_HDR;
|
||||||
|
ctrl.ptr = &obj_context->mpeg2_frame_hdr;
|
||||||
|
ctrl.size = sizeof(obj_context->mpeg2_frame_hdr);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
out_buf.m.planes[0].bytesused = 0;
|
out_buf.m.planes[0].bytesused = 0;
|
||||||
ctrl.id = V4L2_CID_MPEG_VIDEO_MPEG2_FRAME_HDR;
|
ctrl.id = V4L2_CID_MPEG_VIDEO_MPEG2_FRAME_HDR;
|
||||||
|
|||||||
@@ -51,6 +51,11 @@ VAStatus sunxi_cedrus_QueryConfigProfiles(VADriverContextP ctx,
|
|||||||
|
|
||||||
while(ioctl(driver_data->mem2mem_fd, VIDIOC_ENUM_FMT, &vid_fmtdesc) == 0)
|
while(ioctl(driver_data->mem2mem_fd, VIDIOC_ENUM_FMT, &vid_fmtdesc) == 0)
|
||||||
{
|
{
|
||||||
|
switch(vid_fmtdesc.pixelformat) {
|
||||||
|
case V4L2_PIX_FMT_MPEG2_FRAME:
|
||||||
|
profile_list[i++] = VAProfileMPEG2Simple;
|
||||||
|
profile_list[i++] = VAProfileMPEG2Main;
|
||||||
|
break;
|
||||||
vid_fmtdesc.index++;
|
vid_fmtdesc.index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,6 +70,13 @@ VAStatus sunxi_cedrus_QueryConfigEntrypoints(VADriverContextP ctx,
|
|||||||
int *num_entrypoints)
|
int *num_entrypoints)
|
||||||
{
|
{
|
||||||
switch (profile) {
|
switch (profile) {
|
||||||
|
case VAProfileMPEG2Simple:
|
||||||
|
case VAProfileMPEG2Main:
|
||||||
|
*num_entrypoints = 2;
|
||||||
|
entrypoint_list[0] = VAEntrypointVLD;
|
||||||
|
entrypoint_list[1] = VAEntrypointMoComp;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
*num_entrypoints = 0;
|
*num_entrypoints = 0;
|
||||||
break;
|
break;
|
||||||
@@ -135,6 +147,15 @@ VAStatus sunxi_cedrus_CreateConfig(VADriverContextP ctx, VAProfile profile,
|
|||||||
|
|
||||||
/* Validate profile & entrypoint */
|
/* Validate profile & entrypoint */
|
||||||
switch (profile) {
|
switch (profile) {
|
||||||
|
case VAProfileMPEG2Simple:
|
||||||
|
case VAProfileMPEG2Main:
|
||||||
|
if ((VAEntrypointVLD == entrypoint) ||
|
||||||
|
(VAEntrypointMoComp == entrypoint))
|
||||||
|
vaStatus = VA_STATUS_SUCCESS;
|
||||||
|
else
|
||||||
|
vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
|
vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user