18e9a21e730449c10cac6e6f69d255611c93f63c2hding/*
2430ce5c32361119ed81a62c918be6afbdd053eddhding * Copyright (c) 2011 Intel Corporation. All Rights Reserved.
3430ce5c32361119ed81a62c918be6afbdd053eddhding * Copyright (c) Imagination Technologies Limited, UK
48e9a21e730449c10cac6e6f69d255611c93f63c2hding *
5430ce5c32361119ed81a62c918be6afbdd053eddhding * Permission is hereby granted, free of charge, to any person obtaining a
6430ce5c32361119ed81a62c918be6afbdd053eddhding * copy of this software and associated documentation files (the
7430ce5c32361119ed81a62c918be6afbdd053eddhding * "Software"), to deal in the Software without restriction, including
8430ce5c32361119ed81a62c918be6afbdd053eddhding * without limitation the rights to use, copy, modify, merge, publish,
9430ce5c32361119ed81a62c918be6afbdd053eddhding * distribute, sub license, and/or sell copies of the Software, and to
10430ce5c32361119ed81a62c918be6afbdd053eddhding * permit persons to whom the Software is furnished to do so, subject to
11430ce5c32361119ed81a62c918be6afbdd053eddhding * the following conditions:
12430ce5c32361119ed81a62c918be6afbdd053eddhding *
13430ce5c32361119ed81a62c918be6afbdd053eddhding * The above copyright notice and this permission notice (including the
14430ce5c32361119ed81a62c918be6afbdd053eddhding * next paragraph) shall be included in all copies or substantial portions
15430ce5c32361119ed81a62c918be6afbdd053eddhding * of the Software.
16430ce5c32361119ed81a62c918be6afbdd053eddhding *
17430ce5c32361119ed81a62c918be6afbdd053eddhding * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18430ce5c32361119ed81a62c918be6afbdd053eddhding * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19430ce5c32361119ed81a62c918be6afbdd053eddhding * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20430ce5c32361119ed81a62c918be6afbdd053eddhding * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
21430ce5c32361119ed81a62c918be6afbdd053eddhding * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22430ce5c32361119ed81a62c918be6afbdd053eddhding * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23430ce5c32361119ed81a62c918be6afbdd053eddhding * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
248e9a21e730449c10cac6e6f69d255611c93f63c2hding *
258e9a21e730449c10cac6e6f69d255611c93f63c2hding * Authors:
268e9a21e730449c10cac6e6f69d255611c93f63c2hding *    Elaine Wang <elaine.wang@intel.com>
278e9a21e730449c10cac6e6f69d255611c93f63c2hding *    Zeng Li <zeng.li@intel.com>
288e9a21e730449c10cac6e6f69d255611c93f63c2hding *    Edward Lin <edward.lin@intel.com>
298e9a21e730449c10cac6e6f69d255611c93f63c2hding *    Zhaohan Ren <zhaohan.ren@intel.com>
308e9a21e730449c10cac6e6f69d255611c93f63c2hding *
318e9a21e730449c10cac6e6f69d255611c93f63c2hding */
328e9a21e730449c10cac6e6f69d255611c93f63c2hding
338e9a21e730449c10cac6e6f69d255611c93f63c2hding
348e9a21e730449c10cac6e6f69d255611c93f63c2hding#include <errno.h>
358e9a21e730449c10cac6e6f69d255611c93f63c2hding#include <stdlib.h>
368e9a21e730449c10cac6e6f69d255611c93f63c2hding#include <unistd.h>
378e9a21e730449c10cac6e6f69d255611c93f63c2hding#include <stdint.h>
388e9a21e730449c10cac6e6f69d255611c93f63c2hding#include <string.h>
398e9a21e730449c10cac6e6f69d255611c93f63c2hding
408e9a21e730449c10cac6e6f69d255611c93f63c2hding#include "psb_def.h"
418e9a21e730449c10cac6e6f69d255611c93f63c2hding#include "psb_surface.h"
42430ce5c32361119ed81a62c918be6afbdd053eddhding#include "tng_cmdbuf.h"
43430ce5c32361119ed81a62c918be6afbdd053eddhding#include "tng_hostcode.h"
44430ce5c32361119ed81a62c918be6afbdd053eddhding#include "tng_hostheader.h"
45430ce5c32361119ed81a62c918be6afbdd053eddhding#include "tng_MPEG4ES.h"
468e9a21e730449c10cac6e6f69d255611c93f63c2hding#include "psb_drv_debug.h"
478e9a21e730449c10cac6e6f69d255611c93f63c2hding
488e9a21e730449c10cac6e6f69d255611c93f63c2hding#include "hwdefs/coreflags.h"
498e9a21e730449c10cac6e6f69d255611c93f63c2hding#include "hwdefs/topaz_vlc_regs.h"
508e9a21e730449c10cac6e6f69d255611c93f63c2hding#include "hwdefs/topaz_db_regs.h"
518e9a21e730449c10cac6e6f69d255611c93f63c2hding#include "hwdefs/topazhp_default_params.h"
528e9a21e730449c10cac6e6f69d255611c93f63c2hding
538e9a21e730449c10cac6e6f69d255611c93f63c2hding#define TOPAZ_MPEG4_MAX_BITRATE 16000000
548e9a21e730449c10cac6e6f69d255611c93f63c2hding
558e9a21e730449c10cac6e6f69d255611c93f63c2hding#define INIT_CONTEXT_MPEG4ES    context_ENC_p ctx = (context_ENC_p) obj_context->format_data
568e9a21e730449c10cac6e6f69d255611c93f63c2hding#define SURFACE(id)    ((object_surface_p) object_heap_lookup( &ctx->obj_context->driver_data->surface_heap, id ))
578e9a21e730449c10cac6e6f69d255611c93f63c2hding#define BUFFER(id)  ((object_buffer_p) object_heap_lookup( &ctx->obj_context->driver_data->buffer_heap, id ))
588e9a21e730449c10cac6e6f69d255611c93f63c2hding
59430ce5c32361119ed81a62c918be6afbdd053eddhdingstatic void tng_MPEG4ES_QueryConfigAttributes(
60cecb10be5449aa74cd1d9a2eb41c2a6a76d9ee79ywan    VAProfile __maybe_unused profile,
61cecb10be5449aa74cd1d9a2eb41c2a6a76d9ee79ywan    VAEntrypoint __maybe_unused entrypoint,
628e9a21e730449c10cac6e6f69d255611c93f63c2hding    VAConfigAttrib *attrib_list,
638e9a21e730449c10cac6e6f69d255611c93f63c2hding    int num_attribs)
648e9a21e730449c10cac6e6f69d255611c93f63c2hding{
658e9a21e730449c10cac6e6f69d255611c93f63c2hding    int i;
668e9a21e730449c10cac6e6f69d255611c93f63c2hding
678e9a21e730449c10cac6e6f69d255611c93f63c2hding    drv_debug_msg(VIDEO_DEBUG_GENERAL, "%s\n", __FUNCTION__);
688e9a21e730449c10cac6e6f69d255611c93f63c2hding
698e9a21e730449c10cac6e6f69d255611c93f63c2hding    /* RateControl attributes */
708e9a21e730449c10cac6e6f69d255611c93f63c2hding    for (i = 0; i < num_attribs; i++) {
718e9a21e730449c10cac6e6f69d255611c93f63c2hding        switch (attrib_list[i].type) {
728e9a21e730449c10cac6e6f69d255611c93f63c2hding        case VAConfigAttribRTFormat:
738e9a21e730449c10cac6e6f69d255611c93f63c2hding            break;
748e9a21e730449c10cac6e6f69d255611c93f63c2hding
75c55c648390836eba6e0da72e263a26caa2129f39jiguoliang        case VAConfigAttribEncAutoReference:
76c55c648390836eba6e0da72e263a26caa2129f39jiguoliang            attrib_list[i].value = 1;
77c55c648390836eba6e0da72e263a26caa2129f39jiguoliang            break;
78c55c648390836eba6e0da72e263a26caa2129f39jiguoliang
7935b15a0a6456d1ca2b2c1ccae60e548743175526Ren Zhaohan        case VAConfigAttribEncMaxRefFrames:
8035b15a0a6456d1ca2b2c1ccae60e548743175526Ren Zhaohan            attrib_list[i].value = 2;
8135b15a0a6456d1ca2b2c1ccae60e548743175526Ren Zhaohan            break;
8235b15a0a6456d1ca2b2c1ccae60e548743175526Ren Zhaohan
838e9a21e730449c10cac6e6f69d255611c93f63c2hding        case VAConfigAttribRateControl:
84f5f1ed485ec5506202f592b898425f7c11354ed5Ren Zhaohan            attrib_list[i].value = VA_RC_NONE | VA_RC_CBR | VA_RC_VBR;
858e9a21e730449c10cac6e6f69d255611c93f63c2hding            break;
868e9a21e730449c10cac6e6f69d255611c93f63c2hding
878e9a21e730449c10cac6e6f69d255611c93f63c2hding        default:
888e9a21e730449c10cac6e6f69d255611c93f63c2hding            attrib_list[i].value = VA_ATTRIB_NOT_SUPPORTED;
898e9a21e730449c10cac6e6f69d255611c93f63c2hding            break;
908e9a21e730449c10cac6e6f69d255611c93f63c2hding        }
918e9a21e730449c10cac6e6f69d255611c93f63c2hding    }
928e9a21e730449c10cac6e6f69d255611c93f63c2hding}
938e9a21e730449c10cac6e6f69d255611c93f63c2hding
948e9a21e730449c10cac6e6f69d255611c93f63c2hding
95430ce5c32361119ed81a62c918be6afbdd053eddhdingstatic VAStatus tng_MPEG4ES_ValidateConfig(
968e9a21e730449c10cac6e6f69d255611c93f63c2hding    object_config_p obj_config)
978e9a21e730449c10cac6e6f69d255611c93f63c2hding{
98d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun    int i;
998e9a21e730449c10cac6e6f69d255611c93f63c2hding    drv_debug_msg(VIDEO_DEBUG_GENERAL, "%s\n", __FUNCTION__);
100d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun    /* Check all attributes */
101d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun    for (i = 0; i < obj_config->attrib_count; i++) {
102d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun        switch (obj_config->attrib_list[i].type) {
103d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun        case VAConfigAttribRTFormat:
104d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun            /* Ignore */
105d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun            break;
106d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun        case VAConfigAttribRateControl:
107d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun            break;
108d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun        case VAConfigAttribEncAutoReference:
109d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun            break;
110d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun        case VAConfigAttribEncMaxRefFrames:
111d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun            break;
112d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun        default:
113d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun            return VA_STATUS_ERROR_ATTR_NOT_SUPPORTED;
114d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun        }
115d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun    }
1168e9a21e730449c10cac6e6f69d255611c93f63c2hding
117d51aa094f181d181c94e845950ffeba168c8fe5aLiu, Bolun    return VA_STATUS_SUCCESS;
1188e9a21e730449c10cac6e6f69d255611c93f63c2hding}
1198e9a21e730449c10cac6e6f69d255611c93f63c2hding
120430ce5c32361119ed81a62c918be6afbdd053eddhdingstatic VAStatus tng_MPEG4ES_CreateContext(
1218e9a21e730449c10cac6e6f69d255611c93f63c2hding    object_context_p obj_context,
1228e9a21e730449c10cac6e6f69d255611c93f63c2hding    object_config_p obj_config)
1238e9a21e730449c10cac6e6f69d255611c93f63c2hding{
1248e9a21e730449c10cac6e6f69d255611c93f63c2hding    VAStatus vaStatus = VA_STATUS_SUCCESS;
1258e9a21e730449c10cac6e6f69d255611c93f63c2hding    context_ENC_p ctx;
1268e9a21e730449c10cac6e6f69d255611c93f63c2hding    unsigned int eRCMode;
127f1b4be712bc1e4f29cc1eb85e0b2cd42f5b40841pingshix
1288e9a21e730449c10cac6e6f69d255611c93f63c2hding    drv_debug_msg(VIDEO_DEBUG_GENERAL, "%s\n", __FUNCTION__);
1298e9a21e730449c10cac6e6f69d255611c93f63c2hding
130430ce5c32361119ed81a62c918be6afbdd053eddhding    vaStatus = tng_CreateContext(obj_context, obj_config, 0);
1318e9a21e730449c10cac6e6f69d255611c93f63c2hding
1328e9a21e730449c10cac6e6f69d255611c93f63c2hding    if (VA_STATUS_SUCCESS != vaStatus)
1338e9a21e730449c10cac6e6f69d255611c93f63c2hding        return VA_STATUS_ERROR_ALLOCATION_FAILED;
1348e9a21e730449c10cac6e6f69d255611c93f63c2hding
1358e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx = (context_ENC_p) obj_context->format_data;
1368e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->eStandard = IMG_STANDARD_MPEG4;
1378e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->eFormat = IMG_CODEC_PL12;                          // use default
1388e9a21e730449c10cac6e6f69d255611c93f63c2hding
1398e9a21e730449c10cac6e6f69d255611c93f63c2hding    switch(ctx->sRCParams.eRCMode) {
1408e9a21e730449c10cac6e6f69d255611c93f63c2hding	case IMG_RCMODE_NONE:
1418e9a21e730449c10cac6e6f69d255611c93f63c2hding	    ctx->eCodec = IMG_CODEC_MPEG4_NO_RC;
1428e9a21e730449c10cac6e6f69d255611c93f63c2hding	    break;
1438e9a21e730449c10cac6e6f69d255611c93f63c2hding	case IMG_RCMODE_VBR:
1448e9a21e730449c10cac6e6f69d255611c93f63c2hding	    ctx->eCodec = IMG_CODEC_MPEG4_VBR;
1458e9a21e730449c10cac6e6f69d255611c93f63c2hding	    break;
1468e9a21e730449c10cac6e6f69d255611c93f63c2hding	case IMG_RCMODE_CBR:
1478e9a21e730449c10cac6e6f69d255611c93f63c2hding	    ctx->eCodec = IMG_CODEC_MPEG4_CBR;
1488e9a21e730449c10cac6e6f69d255611c93f63c2hding	    break;
1498e9a21e730449c10cac6e6f69d255611c93f63c2hding	default:
1508e9a21e730449c10cac6e6f69d255611c93f63c2hding	    drv_debug_msg(VIDEO_DEBUG_ERROR, "Unknown RCMode %08x\n", ctx->sRCParams.eRCMode);
1518e9a21e730449c10cac6e6f69d255611c93f63c2hding	    break;
1528e9a21e730449c10cac6e6f69d255611c93f63c2hding    }
1538e9a21e730449c10cac6e6f69d255611c93f63c2hding
1548e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->bIsInterlaced = IMG_FALSE;
1558e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->bIsInterleaved = IMG_FALSE;
1568e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->ui16PictureHeight = ctx->ui16FrameHeight;
1578e9a21e730449c10cac6e6f69d255611c93f63c2hding
1588e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->bVPAdaptiveRoundingDisable = IMG_TRUE;
1598e9a21e730449c10cac6e6f69d255611c93f63c2hding
160fc84bd8b6852aff0a3f70c4f21533ce36e1937behding    /* TopazHP only support Simple Profile */
1618e9a21e730449c10cac6e6f69d255611c93f63c2hding    switch (obj_config->profile) {
1628e9a21e730449c10cac6e6f69d255611c93f63c2hding        case VAProfileMPEG4Simple:
163fc84bd8b6852aff0a3f70c4f21533ce36e1937behding            ctx->ui8ProfileIdc = SP;
1648e9a21e730449c10cac6e6f69d255611c93f63c2hding            break;
1658e9a21e730449c10cac6e6f69d255611c93f63c2hding        default:
166fc84bd8b6852aff0a3f70c4f21533ce36e1937behding            ctx->ui8ProfileIdc = SP;
1678e9a21e730449c10cac6e6f69d255611c93f63c2hding        break;
1688e9a21e730449c10cac6e6f69d255611c93f63c2hding    }
1698e9a21e730449c10cac6e6f69d255611c93f63c2hding
1708e9a21e730449c10cac6e6f69d255611c93f63c2hding    //This parameter need not be exposed
1718e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->ui8InterIntraIndex = 3;
1728e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->ui8CodedSkippedIndex = 3;
1738e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->bEnableHostQP = IMG_FALSE;
1748e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->uMaxChunks = 0xA0;
1758e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->uChunksPerMb = 0x40;
1768e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->uPriorityChunks = (0xA0 - 0x60);
1778e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->ui32FCode = 4;
1788e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->iFineYSearchSize = 2;
1798e9a21e730449c10cac6e6f69d255611c93f63c2hding
1808e9a21e730449c10cac6e6f69d255611c93f63c2hding    //This parameter need not be exposed
1818e9a21e730449c10cac6e6f69d255611c93f63c2hding    //host to control the encoding process
1828e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->bEnableInpCtrl = IMG_FALSE;
1838e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->bEnableHostBias = IMG_FALSE;
1848e9a21e730449c10cac6e6f69d255611c93f63c2hding    //By default false Newly Added
1858e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->bEnableCumulativeBiases = IMG_FALSE;
1868e9a21e730449c10cac6e6f69d255611c93f63c2hding
1878e9a21e730449c10cac6e6f69d255611c93f63c2hding    //Weighted Prediction is not supported in TopazHP Version 3.0
1888e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->bWeightedPrediction = IMG_FALSE;
1898e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->ui8VPWeightedImplicitBiPred = 0;
1908e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->bInsertHRDParams = 0;
1918e9a21e730449c10cac6e6f69d255611c93f63c2hding
1928e9a21e730449c10cac6e6f69d255611c93f63c2hding
1938e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->bArbitrarySO = IMG_FALSE;
1948e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->ui32BasicUnit = 0;
1958e9a21e730449c10cac6e6f69d255611c93f63c2hding
1968e9a21e730449c10cac6e6f69d255611c93f63c2hding    return vaStatus;
1978e9a21e730449c10cac6e6f69d255611c93f63c2hding}
1988e9a21e730449c10cac6e6f69d255611c93f63c2hding
199430ce5c32361119ed81a62c918be6afbdd053eddhdingstatic void tng_MPEG4ES_DestroyContext(
2008e9a21e730449c10cac6e6f69d255611c93f63c2hding    object_context_p obj_context)
2018e9a21e730449c10cac6e6f69d255611c93f63c2hding{
2028e9a21e730449c10cac6e6f69d255611c93f63c2hding    drv_debug_msg(VIDEO_DEBUG_GENERAL, "%s\n", __FUNCTION__);
203430ce5c32361119ed81a62c918be6afbdd053eddhding    tng_DestroyContext(obj_context, 0);
2048e9a21e730449c10cac6e6f69d255611c93f63c2hding}
2058e9a21e730449c10cac6e6f69d255611c93f63c2hding
206430ce5c32361119ed81a62c918be6afbdd053eddhdingstatic VAStatus tng_MPEG4ES_BeginPicture(
2078e9a21e730449c10cac6e6f69d255611c93f63c2hding    object_context_p obj_context)
2088e9a21e730449c10cac6e6f69d255611c93f63c2hding{
2098e9a21e730449c10cac6e6f69d255611c93f63c2hding    INIT_CONTEXT_MPEG4ES;
210430ce5c32361119ed81a62c918be6afbdd053eddhding    tng_cmdbuf_p cmdbuf = ctx->obj_context->tng_cmdbuf;
2118e9a21e730449c10cac6e6f69d255611c93f63c2hding    context_ENC_mem *ps_mem = &(ctx->ctx_mem[ctx->ui32StreamID]);
2128e9a21e730449c10cac6e6f69d255611c93f63c2hding    VAStatus vaStatus = VA_STATUS_SUCCESS;
2138e9a21e730449c10cac6e6f69d255611c93f63c2hding    drv_debug_msg(VIDEO_DEBUG_GENERAL, "%s start\n", __FUNCTION__);
214430ce5c32361119ed81a62c918be6afbdd053eddhding    vaStatus = tng_BeginPicture(ctx);
2158e9a21e730449c10cac6e6f69d255611c93f63c2hding
2168e9a21e730449c10cac6e6f69d255611c93f63c2hding    drv_debug_msg(VIDEO_DEBUG_GENERAL, "%s end\n", __FUNCTION__);
2178e9a21e730449c10cac6e6f69d255611c93f63c2hding    return vaStatus;
2188e9a21e730449c10cac6e6f69d255611c93f63c2hding}
2198e9a21e730449c10cac6e6f69d255611c93f63c2hding
220430ce5c32361119ed81a62c918be6afbdd053eddhdingstatic VAStatus tng__MPEG4ES_process_sequence_param(context_ENC_p ctx, object_buffer_p obj_buffer)
2218e9a21e730449c10cac6e6f69d255611c93f63c2hding{
2228e9a21e730449c10cac6e6f69d255611c93f63c2hding    context_ENC_mem *ps_mem = &(ctx->ctx_mem[ctx->ui32StreamID]);
2238e9a21e730449c10cac6e6f69d255611c93f63c2hding    VAEncSequenceParameterBufferMPEG4 *psSeqParams;
224430ce5c32361119ed81a62c918be6afbdd053eddhding    tng_cmdbuf_p cmdbuf = ctx->obj_context->tng_cmdbuf;
2258e9a21e730449c10cac6e6f69d255611c93f63c2hding    IMG_RC_PARAMS *psRCParams = &(ctx->sRCParams);
2268e9a21e730449c10cac6e6f69d255611c93f63c2hding
2278e9a21e730449c10cac6e6f69d255611c93f63c2hding    ASSERT(obj_buffer->type == VAEncSequenceParameterBufferType);
2288e9a21e730449c10cac6e6f69d255611c93f63c2hding    ASSERT(obj_buffer->size == sizeof(VAEncSequenceParameterBufferMPEG4));
2298e9a21e730449c10cac6e6f69d255611c93f63c2hding
2308e9a21e730449c10cac6e6f69d255611c93f63c2hding    if (obj_buffer->size != sizeof(VAEncSequenceParameterBufferMPEG4)) {
2318e9a21e730449c10cac6e6f69d255611c93f63c2hding        return VA_STATUS_ERROR_UNKNOWN;
2328e9a21e730449c10cac6e6f69d255611c93f63c2hding    }
2338e9a21e730449c10cac6e6f69d255611c93f63c2hding
2348e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->obj_context->frame_count = 0;
2358e9a21e730449c10cac6e6f69d255611c93f63c2hding    psSeqParams = (VAEncSequenceParameterBufferMPEG4 *) obj_buffer->buffer_data;
2368e9a21e730449c10cac6e6f69d255611c93f63c2hding    obj_buffer->buffer_data = NULL;
2378e9a21e730449c10cac6e6f69d255611c93f63c2hding    obj_buffer->size = 0;
2388e9a21e730449c10cac6e6f69d255611c93f63c2hding
2398e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->ui32IdrPeriod = psSeqParams->intra_period;
2408e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->ui32IntraCnt = psSeqParams->intra_period;
2414dd34bf685c54fbeab2dcfd01dd76cc826465219Ren Zhaohan
2424dd34bf685c54fbeab2dcfd01dd76cc826465219Ren Zhaohan    if (ctx->ui32IntraCnt == 0) {
2434dd34bf685c54fbeab2dcfd01dd76cc826465219Ren Zhaohan        ctx->ui32IntraCnt = INT_MAX;
2444dd34bf685c54fbeab2dcfd01dd76cc826465219Ren Zhaohan        ctx->ui32IdrPeriod = 1;
2454dd34bf685c54fbeab2dcfd01dd76cc826465219Ren Zhaohan        drv_debug_msg(VIDEO_DEBUG_GENERAL,
2464dd34bf685c54fbeab2dcfd01dd76cc826465219Ren Zhaohan           "%s: only ONE I frame in the sequence, %d\n",
2474dd34bf685c54fbeab2dcfd01dd76cc826465219Ren Zhaohan           __FUNCTION__, ctx->ui32IdrPeriod);
2484dd34bf685c54fbeab2dcfd01dd76cc826465219Ren Zhaohan    }
2494dd34bf685c54fbeab2dcfd01dd76cc826465219Ren Zhaohan
2508e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->bCustomScaling = IMG_FALSE;
2518e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->bUseDefaultScalingList = IMG_FALSE;
2528e9a21e730449c10cac6e6f69d255611c93f63c2hding
2538e9a21e730449c10cac6e6f69d255611c93f63c2hding    //set MV limit infor
2548e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->ui32VertMVLimit = 255 ;//(63.75 in qpel increments)
2558e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->bLimitNumVectors = IMG_TRUE;
2568e9a21e730449c10cac6e6f69d255611c93f63c2hding
257fc84bd8b6852aff0a3f70c4f21533ce36e1937behding    ctx->ui8LevelIdc = psSeqParams->profile_and_level_indication;
258fc84bd8b6852aff0a3f70c4f21533ce36e1937behding
2598e9a21e730449c10cac6e6f69d255611c93f63c2hding    /**************set rc params ****************/
2608e9a21e730449c10cac6e6f69d255611c93f63c2hding    if (psSeqParams->bits_per_second > TOPAZ_MPEG4_MAX_BITRATE) {
2618e9a21e730449c10cac6e6f69d255611c93f63c2hding        ctx->sRCParams.ui32BitsPerSecond = TOPAZ_MPEG4_MAX_BITRATE;
2628e9a21e730449c10cac6e6f69d255611c93f63c2hding        drv_debug_msg(VIDEO_DEBUG_GENERAL, " bits_per_second(%d) exceeds \
2638e9a21e730449c10cac6e6f69d255611c93f63c2hding		the maximum bitrate, set it with %d\n",
2648e9a21e730449c10cac6e6f69d255611c93f63c2hding                                 psSeqParams->bits_per_second,
2658e9a21e730449c10cac6e6f69d255611c93f63c2hding                                 TOPAZ_MPEG4_MAX_BITRATE);
2668e9a21e730449c10cac6e6f69d255611c93f63c2hding    } else
2678e9a21e730449c10cac6e6f69d255611c93f63c2hding        ctx->sRCParams.ui32BitsPerSecond = psSeqParams->bits_per_second;
2688e9a21e730449c10cac6e6f69d255611c93f63c2hding
2698e9a21e730449c10cac6e6f69d255611c93f63c2hding    //FIXME: Zhaohan, this should be figured out in testsuite?
2708e9a21e730449c10cac6e6f69d255611c93f63c2hding    if (!ctx->uiCbrBufferTenths)
2718e9a21e730449c10cac6e6f69d255611c93f63c2hding	ctx->uiCbrBufferTenths = TOPAZHP_DEFAULT_uiCbrBufferTenths;
2728e9a21e730449c10cac6e6f69d255611c93f63c2hding
2738e9a21e730449c10cac6e6f69d255611c93f63c2hding    if (ctx->uiCbrBufferTenths) {
2748e9a21e730449c10cac6e6f69d255611c93f63c2hding        psRCParams->ui32BufferSize      = (IMG_UINT32)(psRCParams->ui32BitsPerSecond * ctx->uiCbrBufferTenths / 10.0);
2758e9a21e730449c10cac6e6f69d255611c93f63c2hding    } else {
2768e9a21e730449c10cac6e6f69d255611c93f63c2hding        if (psRCParams->ui32BitsPerSecond < 256000)
2778e9a21e730449c10cac6e6f69d255611c93f63c2hding            psRCParams->ui32BufferSize = ((9 * psRCParams->ui32BitsPerSecond) >> 1);
2788e9a21e730449c10cac6e6f69d255611c93f63c2hding        else
2798e9a21e730449c10cac6e6f69d255611c93f63c2hding            psRCParams->ui32BufferSize = ((5 * psRCParams->ui32BitsPerSecond) >> 1);
2808e9a21e730449c10cac6e6f69d255611c93f63c2hding    }
2818e9a21e730449c10cac6e6f69d255611c93f63c2hding
2828e9a21e730449c10cac6e6f69d255611c93f63c2hding    psRCParams->i32InitialDelay = (13 * psRCParams->ui32BufferSize) >> 4;
2838e9a21e730449c10cac6e6f69d255611c93f63c2hding    psRCParams->i32InitialLevel = (3 * psRCParams->ui32BufferSize) >> 4;
2848e9a21e730449c10cac6e6f69d255611c93f63c2hding    psRCParams->ui32IntraFreq = psSeqParams->intra_period;
285f1b4be712bc1e4f29cc1eb85e0b2cd42f5b40841pingshix
2868e9a21e730449c10cac6e6f69d255611c93f63c2hding    psRCParams->ui32InitialQp = psSeqParams->initial_qp;
2878e9a21e730449c10cac6e6f69d255611c93f63c2hding    psRCParams->iMinQP = psSeqParams->min_qp;
2888e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->ui32BasicUnit = psSeqParams->min_qp;
2898e9a21e730449c10cac6e6f69d255611c93f63c2hding    //psRCParams->ui32BUSize = psSeqParams->basic_unit_size;
2908e9a21e730449c10cac6e6f69d255611c93f63c2hding    //ctx->ui32KickSize = psRCParams->ui32BUSize;
2918e9a21e730449c10cac6e6f69d255611c93f63c2hding    psRCParams->ui32FrameRate = psSeqParams->frame_rate;
2928e9a21e730449c10cac6e6f69d255611c93f63c2hding
2938e9a21e730449c10cac6e6f69d255611c93f63c2hding    //B-frames are not supported for non-H.264 streams
2948e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->sRCParams.ui16BFrames = 0;
295e26d82700f9514cc175d2b54733ebdeb8824922ehding    ctx->ui8SlotsInUse = psRCParams->ui16BFrames + 2;
2968e9a21e730449c10cac6e6f69d255611c93f63c2hding
2978e9a21e730449c10cac6e6f69d255611c93f63c2hding#if HEADERS_VERBOSE_OUTPUT
2988e9a21e730449c10cac6e6f69d255611c93f63c2hding    drv_debug_msg(VIDEO_DEBUG_GENERAL, "\n\n**********************************************************************\n");
2998e9a21e730449c10cac6e6f69d255611c93f63c2hding    drv_debug_msg(VIDEO_DEBUG_GENERAL, "******** HOST FIRMWARE ROUTINES TO PASS HEADERS AND TOKENS TO MTX******\n");
3008e9a21e730449c10cac6e6f69d255611c93f63c2hding    drv_debug_msg(VIDEO_DEBUG_GENERAL, "**********************************************************************\n\n");
3018e9a21e730449c10cac6e6f69d255611c93f63c2hding#endif
3028e9a21e730449c10cac6e6f69d255611c93f63c2hding
3038e9a21e730449c10cac6e6f69d255611c93f63c2hding    free(psSeqParams);
3048e9a21e730449c10cac6e6f69d255611c93f63c2hding
3058e9a21e730449c10cac6e6f69d255611c93f63c2hding    return VA_STATUS_SUCCESS;
3068e9a21e730449c10cac6e6f69d255611c93f63c2hding}
3078e9a21e730449c10cac6e6f69d255611c93f63c2hding
308430ce5c32361119ed81a62c918be6afbdd053eddhdingstatic VAStatus tng__MPEG4ES_process_picture_param(context_ENC_p ctx, object_buffer_p obj_buffer)
3098e9a21e730449c10cac6e6f69d255611c93f63c2hding{
3108e9a21e730449c10cac6e6f69d255611c93f63c2hding    VAStatus vaStatus = VA_STATUS_SUCCESS;
3118e9a21e730449c10cac6e6f69d255611c93f63c2hding    context_ENC_mem *ps_mem = &(ctx->ctx_mem[ctx->ui32StreamID]);
3128e9a21e730449c10cac6e6f69d255611c93f63c2hding    context_ENC_frame_buf *ps_buf = &(ctx->ctx_frame_buf);
3138e9a21e730449c10cac6e6f69d255611c93f63c2hding    VAEncPictureParameterBufferMPEG4 *psPicParams;
3148e9a21e730449c10cac6e6f69d255611c93f63c2hding    IMG_BOOL bDepViewPPS = IMG_FALSE;
3158e9a21e730449c10cac6e6f69d255611c93f63c2hding    void* pTmpBuf = NULL;
3168e9a21e730449c10cac6e6f69d255611c93f63c2hding
3178e9a21e730449c10cac6e6f69d255611c93f63c2hding    drv_debug_msg(VIDEO_DEBUG_GENERAL, "%s: start\n",__FUNCTION__);
3188e9a21e730449c10cac6e6f69d255611c93f63c2hding    ASSERT(obj_buffer->type == VAEncPictureParameterBufferType);
3198e9a21e730449c10cac6e6f69d255611c93f63c2hding    if (obj_buffer->size != sizeof(VAEncPictureParameterBufferMPEG4)) {
3208e9a21e730449c10cac6e6f69d255611c93f63c2hding        drv_debug_msg(VIDEO_DEBUG_ERROR, "%s L%d Invalid coded buffer handle\n", __FUNCTION__, __LINE__);
3218e9a21e730449c10cac6e6f69d255611c93f63c2hding        return VA_STATUS_ERROR_UNKNOWN;
3228e9a21e730449c10cac6e6f69d255611c93f63c2hding    }
3238e9a21e730449c10cac6e6f69d255611c93f63c2hding
3248e9a21e730449c10cac6e6f69d255611c93f63c2hding    /* Transfer ownership of VAEncPictureParameterBufferMPEG4 data */
3258e9a21e730449c10cac6e6f69d255611c93f63c2hding    psPicParams = (VAEncPictureParameterBufferMPEG4 *) obj_buffer->buffer_data;
3268e9a21e730449c10cac6e6f69d255611c93f63c2hding    obj_buffer->buffer_data = NULL;
3278e9a21e730449c10cac6e6f69d255611c93f63c2hding    obj_buffer->size = 0;
3288e9a21e730449c10cac6e6f69d255611c93f63c2hding
3298e9a21e730449c10cac6e6f69d255611c93f63c2hding    ASSERT(ctx->ui16Width == psPicParams->picture_width);
3308e9a21e730449c10cac6e6f69d255611c93f63c2hding    ASSERT(ctx->ui16PictureHeight == psPicParams->picture_height);
3315dded681fc06f6f765840c45a5e6d57cdf79e561edward lin#ifndef _TNG_FRAMES_
3325dded681fc06f6f765840c45a5e6d57cdf79e561edward lin    ps_buf->ref_surface[0] = ps_buf->ref_surface[2] = SURFACE(psPicParams->reference_picture);
3335dded681fc06f6f765840c45a5e6d57cdf79e561edward lin    ps_buf->ref_surface[1] = ps_buf->ref_surface[3] = SURFACE(psPicParams->reconstructed_picture);
3340cb7e3aca829a30af7cbb32df4271b06c906a323Ren Zhaohan
3350cb7e3aca829a30af7cbb32df4271b06c906a323Ren Zhaohan    ps_buf->ref_surface[0]->is_ref_surface = ps_buf->ref_surface[2]->is_ref_surface = 1;
3360cb7e3aca829a30af7cbb32df4271b06c906a323Ren Zhaohan    ps_buf->ref_surface[1]->is_ref_surface = ps_buf->ref_surface[3]->is_ref_surface = 1;
3375dded681fc06f6f765840c45a5e6d57cdf79e561edward lin#else
3388e9a21e730449c10cac6e6f69d255611c93f63c2hding    ps_buf->ref_surface = SURFACE(psPicParams->reference_picture);
3398e9a21e730449c10cac6e6f69d255611c93f63c2hding    ps_buf->rec_surface = SURFACE(psPicParams->reconstructed_picture);
3405dded681fc06f6f765840c45a5e6d57cdf79e561edward lin#endif
3418e9a21e730449c10cac6e6f69d255611c93f63c2hding    ps_buf->coded_buf = BUFFER(psPicParams->coded_buf);
3428e9a21e730449c10cac6e6f69d255611c93f63c2hding
3438e9a21e730449c10cac6e6f69d255611c93f63c2hding    if (NULL == ps_buf->coded_buf) {
3448e9a21e730449c10cac6e6f69d255611c93f63c2hding        drv_debug_msg(VIDEO_DEBUG_ERROR, "%s L%d Invalid coded buffer handle\n", __FUNCTION__, __LINE__);
3458e9a21e730449c10cac6e6f69d255611c93f63c2hding        free(psPicParams);
3468e9a21e730449c10cac6e6f69d255611c93f63c2hding        return VA_STATUS_ERROR_INVALID_BUFFER;
3478e9a21e730449c10cac6e6f69d255611c93f63c2hding    }
3488e9a21e730449c10cac6e6f69d255611c93f63c2hding
3498e9a21e730449c10cac6e6f69d255611c93f63c2hding    free(psPicParams);
3508e9a21e730449c10cac6e6f69d255611c93f63c2hding    drv_debug_msg(VIDEO_DEBUG_GENERAL, "%s: end\n",__FUNCTION__);
3518e9a21e730449c10cac6e6f69d255611c93f63c2hding
3528e9a21e730449c10cac6e6f69d255611c93f63c2hding    return vaStatus;
3538e9a21e730449c10cac6e6f69d255611c93f63c2hding}
3548e9a21e730449c10cac6e6f69d255611c93f63c2hding
355430ce5c32361119ed81a62c918be6afbdd053eddhdingstatic VAStatus tng__MPEG4ES_process_slice_param(context_ENC_p ctx, object_buffer_p obj_buffer)
3568e9a21e730449c10cac6e6f69d255611c93f63c2hding{
3578e9a21e730449c10cac6e6f69d255611c93f63c2hding    VAStatus vaStatus = VA_STATUS_SUCCESS;
3588e9a21e730449c10cac6e6f69d255611c93f63c2hding    VAEncSliceParameterBuffer *psSliceParams;
3598e9a21e730449c10cac6e6f69d255611c93f63c2hding
3608e9a21e730449c10cac6e6f69d255611c93f63c2hding    ASSERT(obj_buffer->type == VAEncSliceParameterBufferType);
3618e9a21e730449c10cac6e6f69d255611c93f63c2hding    /* Prepare InParams for macros of current slice, insert slice header, insert do slice command */
3628e9a21e730449c10cac6e6f69d255611c93f63c2hding
3638e9a21e730449c10cac6e6f69d255611c93f63c2hding    /* Transfer ownership of VAEncPictureParameterBufferMPEG4 data */
3648e9a21e730449c10cac6e6f69d255611c93f63c2hding    psSliceParams = (VAEncSliceParameterBuffer*) obj_buffer->buffer_data;
3658e9a21e730449c10cac6e6f69d255611c93f63c2hding    obj_buffer->size = 0;
3668e9a21e730449c10cac6e6f69d255611c93f63c2hding
3678e9a21e730449c10cac6e6f69d255611c93f63c2hding    //deblocking behaviour
3688e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->bArbitrarySO = IMG_FALSE;
3698e9a21e730449c10cac6e6f69d255611c93f63c2hding    ctx->ui8DeblockIDC = psSliceParams->slice_flags.bits.disable_deblocking_filter_idc;
3708e9a21e730449c10cac6e6f69d255611c93f63c2hding    ++ctx->ui8SlicesPerPicture;
3718e9a21e730449c10cac6e6f69d255611c93f63c2hding    return vaStatus;
3728e9a21e730449c10cac6e6f69d255611c93f63c2hding}
3738e9a21e730449c10cac6e6f69d255611c93f63c2hding
374430ce5c32361119ed81a62c918be6afbdd053eddhdingstatic VAStatus tng__MPEG4ES_process_misc_param(context_ENC_p ctx, object_buffer_p obj_buffer)
3758e9a21e730449c10cac6e6f69d255611c93f63c2hding{
3768e9a21e730449c10cac6e6f69d255611c93f63c2hding    VAStatus vaStatus = VA_STATUS_SUCCESS;
3778e9a21e730449c10cac6e6f69d255611c93f63c2hding    VAEncMiscParameterBuffer *pBuffer;
3788e9a21e730449c10cac6e6f69d255611c93f63c2hding    VAEncMiscParameterFrameRate *frame_rate_param;
3798e9a21e730449c10cac6e6f69d255611c93f63c2hding    VAEncMiscParameterRateControl *rate_control_param;
3808e9a21e730449c10cac6e6f69d255611c93f63c2hding    IMG_RC_PARAMS   *psRCParams = &(ctx->sRCParams);
3818e9a21e730449c10cac6e6f69d255611c93f63c2hding
3828e9a21e730449c10cac6e6f69d255611c93f63c2hding    ASSERT(obj_buffer->type == VAEncMiscParameterBufferType);
3838e9a21e730449c10cac6e6f69d255611c93f63c2hding
3848e9a21e730449c10cac6e6f69d255611c93f63c2hding    /* Transfer ownership of VAEncMiscParameterBuffer data */
3858e9a21e730449c10cac6e6f69d255611c93f63c2hding    pBuffer = (VAEncMiscParameterBuffer *) obj_buffer->buffer_data;
3868e9a21e730449c10cac6e6f69d255611c93f63c2hding    obj_buffer->size = 0;
3878e9a21e730449c10cac6e6f69d255611c93f63c2hding
3888e9a21e730449c10cac6e6f69d255611c93f63c2hding    switch (pBuffer->type) {
3898e9a21e730449c10cac6e6f69d255611c93f63c2hding    case VAEncMiscParameterTypeRateControl:
3908e9a21e730449c10cac6e6f69d255611c93f63c2hding        rate_control_param = (VAEncMiscParameterRateControl *)pBuffer->data;
3918e9a21e730449c10cac6e6f69d255611c93f63c2hding
3928e9a21e730449c10cac6e6f69d255611c93f63c2hding        if (rate_control_param->initial_qp > 51 || rate_control_param->min_qp > 51) {
3938e9a21e730449c10cac6e6f69d255611c93f63c2hding            drv_debug_msg(VIDEO_DEBUG_ERROR, "Initial_qp(%d) and min_qpinitial_qp(%d) "
3948e9a21e730449c10cac6e6f69d255611c93f63c2hding                               "are invalid.\nQP shouldn't be larger than 51 for MPEG4\n",
3958e9a21e730449c10cac6e6f69d255611c93f63c2hding                               rate_control_param->initial_qp, rate_control_param->min_qp);
3968e9a21e730449c10cac6e6f69d255611c93f63c2hding            vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
3978e9a21e730449c10cac6e6f69d255611c93f63c2hding            break;
3988e9a21e730449c10cac6e6f69d255611c93f63c2hding        }
3998e9a21e730449c10cac6e6f69d255611c93f63c2hding
4008e9a21e730449c10cac6e6f69d255611c93f63c2hding        drv_debug_msg(VIDEO_DEBUG_GENERAL, "rate control changed from %d to %d\n",
4018e9a21e730449c10cac6e6f69d255611c93f63c2hding                                 psRCParams->ui32BitsPerSecond,
4028e9a21e730449c10cac6e6f69d255611c93f63c2hding                                 rate_control_param->bits_per_second);
4038e9a21e730449c10cac6e6f69d255611c93f63c2hding
4048e9a21e730449c10cac6e6f69d255611c93f63c2hding        if ((rate_control_param->bits_per_second == psRCParams->ui32BitsPerSecond) &&
4058e9a21e730449c10cac6e6f69d255611c93f63c2hding            (psRCParams->ui32BufferSize == psRCParams->ui32BitsPerSecond / 1000 * rate_control_param->window_size) &&
4068e9a21e730449c10cac6e6f69d255611c93f63c2hding            (psRCParams->iMinQP == rate_control_param->min_qp) &&
4078e9a21e730449c10cac6e6f69d255611c93f63c2hding            (psRCParams->ui32InitialQp == rate_control_param->initial_qp))
4088e9a21e730449c10cac6e6f69d255611c93f63c2hding            break;
4098e9a21e730449c10cac6e6f69d255611c93f63c2hding
4108e9a21e730449c10cac6e6f69d255611c93f63c2hding        if (rate_control_param->bits_per_second > TOPAZ_MPEG4_MAX_BITRATE) {
4118e9a21e730449c10cac6e6f69d255611c93f63c2hding            psRCParams->ui32BitsPerSecond = TOPAZ_MPEG4_MAX_BITRATE;
4128e9a21e730449c10cac6e6f69d255611c93f63c2hding            drv_debug_msg(VIDEO_DEBUG_GENERAL, " bits_per_second(%d) exceeds \
4138e9a21e730449c10cac6e6f69d255611c93f63c2hding				the maximum bitrate, set it with %d\n",
4148e9a21e730449c10cac6e6f69d255611c93f63c2hding                                     rate_control_param->bits_per_second,
4158e9a21e730449c10cac6e6f69d255611c93f63c2hding                                     TOPAZ_MPEG4_MAX_BITRATE);
4168e9a21e730449c10cac6e6f69d255611c93f63c2hding        } else
4178e9a21e730449c10cac6e6f69d255611c93f63c2hding            psRCParams->ui32BitsPerSecond = rate_control_param->bits_per_second;
4188e9a21e730449c10cac6e6f69d255611c93f63c2hding
4198e9a21e730449c10cac6e6f69d255611c93f63c2hding        if (rate_control_param->window_size != 0)
4208e9a21e730449c10cac6e6f69d255611c93f63c2hding            psRCParams->ui32BufferSize = psRCParams->ui32BitsPerSecond * rate_control_param->window_size / 1000;
4218e9a21e730449c10cac6e6f69d255611c93f63c2hding        if (rate_control_param->initial_qp != 0)
4228e9a21e730449c10cac6e6f69d255611c93f63c2hding            psRCParams->ui32InitialQp = rate_control_param->initial_qp;
4238e9a21e730449c10cac6e6f69d255611c93f63c2hding        if (rate_control_param->min_qp != 0)
4248e9a21e730449c10cac6e6f69d255611c93f63c2hding            psRCParams->iMinQP = rate_control_param->min_qp;
4258e9a21e730449c10cac6e6f69d255611c93f63c2hding        break;
4268e9a21e730449c10cac6e6f69d255611c93f63c2hding    default:
4278e9a21e730449c10cac6e6f69d255611c93f63c2hding        break;
4288e9a21e730449c10cac6e6f69d255611c93f63c2hding    }
4298e9a21e730449c10cac6e6f69d255611c93f63c2hding
4308e9a21e730449c10cac6e6f69d255611c93f63c2hding    return vaStatus;
4318e9a21e730449c10cac6e6f69d255611c93f63c2hding}
4328e9a21e730449c10cac6e6f69d255611c93f63c2hding
433430ce5c32361119ed81a62c918be6afbdd053eddhdingstatic VAStatus tng_MPEG4ES_RenderPicture(
4348e9a21e730449c10cac6e6f69d255611c93f63c2hding    object_context_p obj_context,
4358e9a21e730449c10cac6e6f69d255611c93f63c2hding    object_buffer_p *buffers,
4368e9a21e730449c10cac6e6f69d255611c93f63c2hding    int num_buffers)
4378e9a21e730449c10cac6e6f69d255611c93f63c2hding{
4388e9a21e730449c10cac6e6f69d255611c93f63c2hding    INIT_CONTEXT_MPEG4ES;
4398e9a21e730449c10cac6e6f69d255611c93f63c2hding    VAStatus vaStatus = VA_STATUS_SUCCESS;
4408e9a21e730449c10cac6e6f69d255611c93f63c2hding    int i;
4418e9a21e730449c10cac6e6f69d255611c93f63c2hding
4428e9a21e730449c10cac6e6f69d255611c93f63c2hding    drv_debug_msg(VIDEO_DEBUG_GENERAL, "%s: start\n", __FUNCTION__);
4438e9a21e730449c10cac6e6f69d255611c93f63c2hding    for (i = 0; i < num_buffers; i++) {
4448e9a21e730449c10cac6e6f69d255611c93f63c2hding        object_buffer_p obj_buffer = buffers[i];
4458e9a21e730449c10cac6e6f69d255611c93f63c2hding        drv_debug_msg(VIDEO_DEBUG_GENERAL, "%s: type = %d, num = %d\n", __FUNCTION__, obj_buffer->type, num_buffers);
4468e9a21e730449c10cac6e6f69d255611c93f63c2hding
4478e9a21e730449c10cac6e6f69d255611c93f63c2hding        switch (obj_buffer->type) {
4488e9a21e730449c10cac6e6f69d255611c93f63c2hding        case VAEncSequenceParameterBufferType:
449430ce5c32361119ed81a62c918be6afbdd053eddhding            drv_debug_msg(VIDEO_DEBUG_GENERAL, "tng_MPEG4_RenderPicture got VAEncSequenceParameterBufferType\n");
450430ce5c32361119ed81a62c918be6afbdd053eddhding            vaStatus = tng__MPEG4ES_process_sequence_param(ctx, obj_buffer);
4518e9a21e730449c10cac6e6f69d255611c93f63c2hding            DEBUG_FAILURE;
4528e9a21e730449c10cac6e6f69d255611c93f63c2hding            break;
4538e9a21e730449c10cac6e6f69d255611c93f63c2hding        case VAEncPictureParameterBufferType:
454430ce5c32361119ed81a62c918be6afbdd053eddhding            drv_debug_msg(VIDEO_DEBUG_GENERAL, "tng_MPEG4_RenderPicture got VAEncPictureParameterBuffer\n");
455430ce5c32361119ed81a62c918be6afbdd053eddhding            vaStatus = tng__MPEG4ES_process_picture_param(ctx, obj_buffer);
4568e9a21e730449c10cac6e6f69d255611c93f63c2hding            DEBUG_FAILURE;
4578e9a21e730449c10cac6e6f69d255611c93f63c2hding            break;
4588e9a21e730449c10cac6e6f69d255611c93f63c2hding
4598e9a21e730449c10cac6e6f69d255611c93f63c2hding        case VAEncSliceParameterBufferType:
460430ce5c32361119ed81a62c918be6afbdd053eddhding            drv_debug_msg(VIDEO_DEBUG_GENERAL, "tng_MPEG4_RenderPicture got VAEncSliceParameterBufferType\n");
461430ce5c32361119ed81a62c918be6afbdd053eddhding            vaStatus = tng__MPEG4ES_process_slice_param(ctx, obj_buffer);
4628e9a21e730449c10cac6e6f69d255611c93f63c2hding            DEBUG_FAILURE;
4638e9a21e730449c10cac6e6f69d255611c93f63c2hding            break;
4648e9a21e730449c10cac6e6f69d255611c93f63c2hding
4658e9a21e730449c10cac6e6f69d255611c93f63c2hding        case VAEncMiscParameterBufferType:
466430ce5c32361119ed81a62c918be6afbdd053eddhding            drv_debug_msg(VIDEO_DEBUG_GENERAL, "tng_MPEG4_RenderPicture got VAEncMiscParameterBufferType\n");
467430ce5c32361119ed81a62c918be6afbdd053eddhding            vaStatus = tng__MPEG4ES_process_misc_param(ctx, obj_buffer);
4688e9a21e730449c10cac6e6f69d255611c93f63c2hding            DEBUG_FAILURE;
4698e9a21e730449c10cac6e6f69d255611c93f63c2hding            break;
4708e9a21e730449c10cac6e6f69d255611c93f63c2hding        default:
4718e9a21e730449c10cac6e6f69d255611c93f63c2hding            vaStatus = VA_STATUS_ERROR_UNKNOWN;
4728e9a21e730449c10cac6e6f69d255611c93f63c2hding            DEBUG_FAILURE;
4738e9a21e730449c10cac6e6f69d255611c93f63c2hding        }
4748e9a21e730449c10cac6e6f69d255611c93f63c2hding        if (vaStatus != VA_STATUS_SUCCESS) {
4758e9a21e730449c10cac6e6f69d255611c93f63c2hding            break;
4768e9a21e730449c10cac6e6f69d255611c93f63c2hding        }
4778e9a21e730449c10cac6e6f69d255611c93f63c2hding    }
4788e9a21e730449c10cac6e6f69d255611c93f63c2hding    drv_debug_msg(VIDEO_DEBUG_GENERAL, "%s: end\n", __FUNCTION__);
4798e9a21e730449c10cac6e6f69d255611c93f63c2hding
4808e9a21e730449c10cac6e6f69d255611c93f63c2hding    return vaStatus;
4818e9a21e730449c10cac6e6f69d255611c93f63c2hding}
4828e9a21e730449c10cac6e6f69d255611c93f63c2hding
483430ce5c32361119ed81a62c918be6afbdd053eddhdingstatic VAStatus tng_MPEG4ES_EndPicture(
4848e9a21e730449c10cac6e6f69d255611c93f63c2hding    object_context_p obj_context)
4858e9a21e730449c10cac6e6f69d255611c93f63c2hding{
4868e9a21e730449c10cac6e6f69d255611c93f63c2hding    INIT_CONTEXT_MPEG4ES;
4878e9a21e730449c10cac6e6f69d255611c93f63c2hding    VAStatus vaStatus = VA_STATUS_SUCCESS;
4888e9a21e730449c10cac6e6f69d255611c93f63c2hding    drv_debug_msg(VIDEO_DEBUG_GENERAL, "%s start\n", __FUNCTION__);
489430ce5c32361119ed81a62c918be6afbdd053eddhding    vaStatus = tng_EndPicture(ctx);
4908e9a21e730449c10cac6e6f69d255611c93f63c2hding    drv_debug_msg(VIDEO_DEBUG_GENERAL, "%s end\n", __FUNCTION__);
4918e9a21e730449c10cac6e6f69d255611c93f63c2hding
4928e9a21e730449c10cac6e6f69d255611c93f63c2hding    return vaStatus;
4938e9a21e730449c10cac6e6f69d255611c93f63c2hding}
4948e9a21e730449c10cac6e6f69d255611c93f63c2hding
495430ce5c32361119ed81a62c918be6afbdd053eddhdingstruct format_vtable_s tng_MPEG4ES_vtable = {
4968e9a21e730449c10cac6e6f69d255611c93f63c2hdingqueryConfigAttributes:
497430ce5c32361119ed81a62c918be6afbdd053eddhding    tng_MPEG4ES_QueryConfigAttributes,
4988e9a21e730449c10cac6e6f69d255611c93f63c2hdingvalidateConfig:
499430ce5c32361119ed81a62c918be6afbdd053eddhding    tng_MPEG4ES_ValidateConfig,
5008e9a21e730449c10cac6e6f69d255611c93f63c2hdingcreateContext:
501430ce5c32361119ed81a62c918be6afbdd053eddhding    tng_MPEG4ES_CreateContext,
5028e9a21e730449c10cac6e6f69d255611c93f63c2hdingdestroyContext:
503430ce5c32361119ed81a62c918be6afbdd053eddhding    tng_MPEG4ES_DestroyContext,
5048e9a21e730449c10cac6e6f69d255611c93f63c2hdingbeginPicture:
505430ce5c32361119ed81a62c918be6afbdd053eddhding    tng_MPEG4ES_BeginPicture,
5068e9a21e730449c10cac6e6f69d255611c93f63c2hdingrenderPicture:
507430ce5c32361119ed81a62c918be6afbdd053eddhding    tng_MPEG4ES_RenderPicture,
5088e9a21e730449c10cac6e6f69d255611c93f63c2hdingendPicture:
509430ce5c32361119ed81a62c918be6afbdd053eddhding    tng_MPEG4ES_EndPicture
5108e9a21e730449c10cac6e6f69d255611c93f63c2hding};
5118e9a21e730449c10cac6e6f69d255611c93f63c2hding
5128e9a21e730449c10cac6e6f69d255611c93f63c2hding/*EOF*/
513