diff --git a/README.md b/README.md index 328225e..3dc7856 100644 --- a/README.md +++ b/README.md @@ -10,3 +10,8 @@ You can try this driver with VLC but don't forget to tell libVA to use this backend: 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/ diff --git a/src/Makefile.am b/src/Makefile.am index 542702d..ca2e539 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 picture.c subpicture.c surface.c + context.c image.c mpeg2.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 picture.h subpicture.h surface.h \ + context.h image.h mpeg2.h picture.h subpicture.h surface.h \ tiled_yuv.h sunxi_cedrus_drv_video_la_LTLIBRARIES = sunxi_cedrus_drv_video.la diff --git a/src/context.c b/src/context.c index 1e149de..dfbb4fc 100644 --- a/src/context.c +++ b/src/context.c @@ -117,6 +117,10 @@ VAStatus sunxi_cedrus_CreateContext(VADriverContextP ctx, VAConfigID config_id, fmt.fmt.pix_mp.height = picture_height; fmt.fmt.pix_mp.plane_fmt[0].sizeimage = INPUT_BUFFER_MAX_SIZE; switch(obj_config->profile) { + case VAProfileMPEG2Simple: + case VAProfileMPEG2Main: + fmt.fmt.pix_mp.pixelformat = V4L2_PIX_FMT_MPEG2_FRAME; + break; default: vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE; return vaStatus; diff --git a/src/context.h b/src/context.h index d4922b1..ba4eac2 100644 --- a/src/context.h +++ b/src/context.h @@ -50,6 +50,8 @@ struct object_context { int flags; VASurfaceID *render_targets; uint32_t num_rendered_surfaces; + + struct v4l2_ctrl_mpeg2_frame_hdr mpeg2_frame_hdr; }; typedef struct object_context *object_context_p; diff --git a/src/mpeg2.c b/src/mpeg2.c new file mode 100644 index 0000000..3d8a642 --- /dev/null +++ b/src/mpeg2.c @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2016 Florent Revest, + * 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 +#include + +#include +#include + +#include + +/* + * 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; +} + + diff --git a/src/mpeg2.h b/src/mpeg2.h new file mode 100644 index 0000000..18a4d10 --- /dev/null +++ b/src/mpeg2.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2016 Florent Revest, + * 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 + +#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_ */ diff --git a/src/picture.c b/src/picture.c index aa4d535..1d506f9 100644 --- a/src/picture.c +++ b/src/picture.c @@ -30,6 +30,8 @@ #include "surface.h" #include "va_config.h" +#include "mpeg2.h" + #include #include @@ -107,6 +109,18 @@ VAStatus sunxi_cedrus_RenderPicture(VADriverContextP ctx, VAContextID context, vaStatus = VA_STATUS_ERROR_INVALID_BUFFER; 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; @@ -147,6 +161,13 @@ VAStatus sunxi_cedrus_EndPicture(VADriverContextP ctx, VAContextID context) out_buf.request = obj_surface->request; 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: out_buf.m.planes[0].bytesused = 0; ctrl.id = V4L2_CID_MPEG_VIDEO_MPEG2_FRAME_HDR; diff --git a/src/va_config.c b/src/va_config.c index 069e999..9467547 100644 --- a/src/va_config.c +++ b/src/va_config.c @@ -51,6 +51,11 @@ VAStatus sunxi_cedrus_QueryConfigProfiles(VADriverContextP ctx, 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++; } @@ -65,6 +70,13 @@ VAStatus sunxi_cedrus_QueryConfigEntrypoints(VADriverContextP ctx, int *num_entrypoints) { switch (profile) { + case VAProfileMPEG2Simple: + case VAProfileMPEG2Main: + *num_entrypoints = 2; + entrypoint_list[0] = VAEntrypointVLD; + entrypoint_list[1] = VAEntrypointMoComp; + break; + default: *num_entrypoints = 0; break; @@ -135,6 +147,15 @@ VAStatus sunxi_cedrus_CreateConfig(VADriverContextP ctx, VAProfile profile, /* Validate profile & entrypoint */ switch (profile) { + case VAProfileMPEG2Simple: + case VAProfileMPEG2Main: + if ((VAEntrypointVLD == entrypoint) || + (VAEntrypointMoComp == entrypoint)) + vaStatus = VA_STATUS_SUCCESS; + else + vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT; + break; + default: vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE; break;