TestBenchMultipleInstance.c revision 0c1bc742181ded4930842b46e9507372f0b1b963
10c1bc742181ded4930842b46e9507372f0b1b963James Dong/* 20c1bc742181ded4930842b46e9507372f0b1b963James Dong * Copyright (C) 2009 The Android Open Source Project 30c1bc742181ded4930842b46e9507372f0b1b963James Dong * 40c1bc742181ded4930842b46e9507372f0b1b963James Dong * Licensed under the Apache License, Version 2.0 (the "License"); 50c1bc742181ded4930842b46e9507372f0b1b963James Dong * you may not use this file except in compliance with the License. 60c1bc742181ded4930842b46e9507372f0b1b963James Dong * You may obtain a copy of the License at 70c1bc742181ded4930842b46e9507372f0b1b963James Dong * 80c1bc742181ded4930842b46e9507372f0b1b963James Dong * http://www.apache.org/licenses/LICENSE-2.0 90c1bc742181ded4930842b46e9507372f0b1b963James Dong * 100c1bc742181ded4930842b46e9507372f0b1b963James Dong * Unless required by applicable law or agreed to in writing, software 110c1bc742181ded4930842b46e9507372f0b1b963James Dong * distributed under the License is distributed on an "AS IS" BASIS, 120c1bc742181ded4930842b46e9507372f0b1b963James Dong * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 130c1bc742181ded4930842b46e9507372f0b1b963James Dong * See the License for the specific language governing permissions and 140c1bc742181ded4930842b46e9507372f0b1b963James Dong * limitations under the License. 150c1bc742181ded4930842b46e9507372f0b1b963James Dong */ 160c1bc742181ded4930842b46e9507372f0b1b963James Dong 170c1bc742181ded4930842b46e9507372f0b1b963James Dong/* CVS tag name for identification */ 180c1bc742181ded4930842b46e9507372f0b1b963James Dongconst char tagName[256] = "$Name: FIRST_ANDROID_COPYRIGHT $"; 190c1bc742181ded4930842b46e9507372f0b1b963James Dong 200c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "H264SwDecApi.h" 210c1bc742181ded4930842b46e9507372f0b1b963James Dong#include <stdio.h> 220c1bc742181ded4930842b46e9507372f0b1b963James Dong#include <stdlib.h> 230c1bc742181ded4930842b46e9507372f0b1b963James Dong#include <string.h> 240c1bc742181ded4930842b46e9507372f0b1b963James Dong 250c1bc742181ded4930842b46e9507372f0b1b963James Dong#define DEBUG(argv) printf argv 260c1bc742181ded4930842b46e9507372f0b1b963James Dong 270c1bc742181ded4930842b46e9507372f0b1b963James Dong/* _NO_OUT disables output file writing */ 280c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef __arm 290c1bc742181ded4930842b46e9507372f0b1b963James Dong#define _NO_OUT 300c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif 310c1bc742181ded4930842b46e9507372f0b1b963James Dong 320c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 330c1bc742181ded4930842b46e9507372f0b1b963James Dong 340c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 350c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid WriteOutput(FILE *fid, u8 *data, u32 picSize); 360c1bc742181ded4930842b46e9507372f0b1b963James Dong 370c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 CropPicture(u8 *pOutImage, u8 *pInImage, 380c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 picWidth, u32 picHeight, CropParams *pCropParams); 390c1bc742181ded4930842b46e9507372f0b1b963James Dong 400c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid CropWriteOutput(FILE *fid, u8 *imageData, u32 cropDisplay, 410c1bc742181ded4930842b46e9507372f0b1b963James Dong H264SwDecInfo *decInfo); 420c1bc742181ded4930842b46e9507372f0b1b963James Dong 430c1bc742181ded4930842b46e9507372f0b1b963James Dongtypedef struct 440c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 450c1bc742181ded4930842b46e9507372f0b1b963James Dong H264SwDecInst decInst; 460c1bc742181ded4930842b46e9507372f0b1b963James Dong H264SwDecInput decInput; 470c1bc742181ded4930842b46e9507372f0b1b963James Dong H264SwDecOutput decOutput; 480c1bc742181ded4930842b46e9507372f0b1b963James Dong H264SwDecPicture decPicture; 490c1bc742181ded4930842b46e9507372f0b1b963James Dong H264SwDecInfo decInfo; 500c1bc742181ded4930842b46e9507372f0b1b963James Dong FILE *foutput; 510c1bc742181ded4930842b46e9507372f0b1b963James Dong char outFileName[256]; 520c1bc742181ded4930842b46e9507372f0b1b963James Dong u8 *byteStrmStart; 530c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 picNumber; 540c1bc742181ded4930842b46e9507372f0b1b963James Dong} Decoder; 550c1bc742181ded4930842b46e9507372f0b1b963James Dong 560c1bc742181ded4930842b46e9507372f0b1b963James Dong 570c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 580c1bc742181ded4930842b46e9507372f0b1b963James Dong 590c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 600c1bc742181ded4930842b46e9507372f0b1b963James Dongint main(int argc, char **argv) 610c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 620c1bc742181ded4930842b46e9507372f0b1b963James Dong 630c1bc742181ded4930842b46e9507372f0b1b963James Dong i32 instCount, instRunning; 640c1bc742181ded4930842b46e9507372f0b1b963James Dong i32 i; 650c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 maxNumPics; 660c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 strmLen; 670c1bc742181ded4930842b46e9507372f0b1b963James Dong H264SwDecRet ret; 680c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 numErrors = 0; 690c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 cropDisplay = 0; 700c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 disableOutputReordering = 0; 710c1bc742181ded4930842b46e9507372f0b1b963James Dong FILE *finput; 720c1bc742181ded4930842b46e9507372f0b1b963James Dong Decoder **decoder; 730c1bc742181ded4930842b46e9507372f0b1b963James Dong char outFileName[256] = "out.yuv"; 740c1bc742181ded4930842b46e9507372f0b1b963James Dong 750c1bc742181ded4930842b46e9507372f0b1b963James Dong 760c1bc742181ded4930842b46e9507372f0b1b963James Dong if ( argc > 1 && strcmp(argv[1], "-T") == 0 ) 770c1bc742181ded4930842b46e9507372f0b1b963James Dong { 780c1bc742181ded4930842b46e9507372f0b1b963James Dong fprintf(stderr, "%s\n", tagName); 790c1bc742181ded4930842b46e9507372f0b1b963James Dong return 0; 800c1bc742181ded4930842b46e9507372f0b1b963James Dong } 810c1bc742181ded4930842b46e9507372f0b1b963James Dong 820c1bc742181ded4930842b46e9507372f0b1b963James Dong if (argc < 2) 830c1bc742181ded4930842b46e9507372f0b1b963James Dong { 840c1bc742181ded4930842b46e9507372f0b1b963James Dong DEBUG(( 850c1bc742181ded4930842b46e9507372f0b1b963James Dong "Usage: %s [-Nn] [-Ooutfile] [-P] [-U] [-C] [-R] [-T] file1.264 [file2.264] .. [fileN.264]\n", 860c1bc742181ded4930842b46e9507372f0b1b963James Dong argv[0])); 870c1bc742181ded4930842b46e9507372f0b1b963James Dong DEBUG(("\t-Nn forces decoding to stop after n pictures\n")); 880c1bc742181ded4930842b46e9507372f0b1b963James Dong#if defined(_NO_OUT) 890c1bc742181ded4930842b46e9507372f0b1b963James Dong DEBUG(("\t-Ooutfile output writing disabled at compile time\n")); 900c1bc742181ded4930842b46e9507372f0b1b963James Dong#else 910c1bc742181ded4930842b46e9507372f0b1b963James Dong DEBUG(("\t-Ooutfile write output to \"outfile\" (default out.yuv)\n")); 920c1bc742181ded4930842b46e9507372f0b1b963James Dong DEBUG(("\t-Onone does not write output\n")); 930c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif 940c1bc742181ded4930842b46e9507372f0b1b963James Dong DEBUG(("\t-C display cropped image (default decoded image)\n")); 950c1bc742181ded4930842b46e9507372f0b1b963James Dong DEBUG(("\t-R disable DPB output reordering\n")); 960c1bc742181ded4930842b46e9507372f0b1b963James Dong DEBUG(("\t-T to print tag name and exit\n")); 970c1bc742181ded4930842b46e9507372f0b1b963James Dong exit(100); 980c1bc742181ded4930842b46e9507372f0b1b963James Dong } 990c1bc742181ded4930842b46e9507372f0b1b963James Dong 1000c1bc742181ded4930842b46e9507372f0b1b963James Dong instCount = argc - 1; 1010c1bc742181ded4930842b46e9507372f0b1b963James Dong 1020c1bc742181ded4930842b46e9507372f0b1b963James Dong /* read command line arguments */ 1030c1bc742181ded4930842b46e9507372f0b1b963James Dong maxNumPics = 0; 1040c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = 1; i < (argc-1); i++) 1050c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1060c1bc742181ded4930842b46e9507372f0b1b963James Dong if ( strncmp(argv[i], "-N", 2) == 0 ) 1070c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1080c1bc742181ded4930842b46e9507372f0b1b963James Dong maxNumPics = (u32)atoi(argv[i]+2); 1090c1bc742181ded4930842b46e9507372f0b1b963James Dong instCount--; 1100c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1110c1bc742181ded4930842b46e9507372f0b1b963James Dong else if ( strncmp(argv[i], "-O", 2) == 0 ) 1120c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1130c1bc742181ded4930842b46e9507372f0b1b963James Dong strcpy(outFileName, argv[i]+2); 1140c1bc742181ded4930842b46e9507372f0b1b963James Dong instCount--; 1150c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1160c1bc742181ded4930842b46e9507372f0b1b963James Dong else if ( strcmp(argv[i], "-C") == 0 ) 1170c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1180c1bc742181ded4930842b46e9507372f0b1b963James Dong cropDisplay = 1; 1190c1bc742181ded4930842b46e9507372f0b1b963James Dong instCount--; 1200c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1210c1bc742181ded4930842b46e9507372f0b1b963James Dong else if ( strcmp(argv[i], "-R") == 0 ) 1220c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1230c1bc742181ded4930842b46e9507372f0b1b963James Dong disableOutputReordering = 1; 1240c1bc742181ded4930842b46e9507372f0b1b963James Dong instCount--; 1250c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1260c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1270c1bc742181ded4930842b46e9507372f0b1b963James Dong 1280c1bc742181ded4930842b46e9507372f0b1b963James Dong if (instCount < 1) 1290c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1300c1bc742181ded4930842b46e9507372f0b1b963James Dong DEBUG(("No input files\n")); 1310c1bc742181ded4930842b46e9507372f0b1b963James Dong exit(100); 1320c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1330c1bc742181ded4930842b46e9507372f0b1b963James Dong 1340c1bc742181ded4930842b46e9507372f0b1b963James Dong /* allocate memory for multiple decoder instances 1350c1bc742181ded4930842b46e9507372f0b1b963James Dong * one instance for every stream file */ 1360c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder = (Decoder **)malloc(sizeof(Decoder*)*(u32)instCount); 1370c1bc742181ded4930842b46e9507372f0b1b963James Dong if (decoder == NULL) 1380c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1390c1bc742181ded4930842b46e9507372f0b1b963James Dong DEBUG(("Unable to allocate memory\n")); 1400c1bc742181ded4930842b46e9507372f0b1b963James Dong exit(100); 1410c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1420c1bc742181ded4930842b46e9507372f0b1b963James Dong 1430c1bc742181ded4930842b46e9507372f0b1b963James Dong /* prepare each decoder instance */ 1440c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = 0; i < instCount; i++) 1450c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1460c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i] = (Decoder *)calloc(1, sizeof(Decoder)); 1470c1bc742181ded4930842b46e9507372f0b1b963James Dong 1480c1bc742181ded4930842b46e9507372f0b1b963James Dong /* open input file */ 1490c1bc742181ded4930842b46e9507372f0b1b963James Dong finput = fopen(argv[argc-instCount+i],"rb"); 1500c1bc742181ded4930842b46e9507372f0b1b963James Dong if (finput == NULL) 1510c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1520c1bc742181ded4930842b46e9507372f0b1b963James Dong DEBUG(("Unable to open input file <%s>\n", argv[argc-instCount+i])); 1530c1bc742181ded4930842b46e9507372f0b1b963James Dong exit(100); 1540c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1550c1bc742181ded4930842b46e9507372f0b1b963James Dong 1560c1bc742181ded4930842b46e9507372f0b1b963James Dong DEBUG(("Reading input file[%d] %s\n", i, argv[argc-instCount+i])); 1570c1bc742181ded4930842b46e9507372f0b1b963James Dong 1580c1bc742181ded4930842b46e9507372f0b1b963James Dong /* read input stream to buffer */ 1590c1bc742181ded4930842b46e9507372f0b1b963James Dong fseek(finput,0L,SEEK_END); 1600c1bc742181ded4930842b46e9507372f0b1b963James Dong strmLen = (u32)ftell(finput); 1610c1bc742181ded4930842b46e9507372f0b1b963James Dong rewind(finput); 1620c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->byteStrmStart = (u8 *)malloc(sizeof(u8)*strmLen); 1630c1bc742181ded4930842b46e9507372f0b1b963James Dong if (decoder[i]->byteStrmStart == NULL) 1640c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1650c1bc742181ded4930842b46e9507372f0b1b963James Dong DEBUG(("Unable to allocate memory\n")); 1660c1bc742181ded4930842b46e9507372f0b1b963James Dong exit(100); 1670c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1680c1bc742181ded4930842b46e9507372f0b1b963James Dong fread(decoder[i]->byteStrmStart, sizeof(u8), strmLen, finput); 1690c1bc742181ded4930842b46e9507372f0b1b963James Dong fclose(finput); 1700c1bc742181ded4930842b46e9507372f0b1b963James Dong 1710c1bc742181ded4930842b46e9507372f0b1b963James Dong /* open output file */ 1720c1bc742181ded4930842b46e9507372f0b1b963James Dong if (strcmp(outFileName, "none") != 0) 1730c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1740c1bc742181ded4930842b46e9507372f0b1b963James Dong#if defined(_NO_OUT) 1750c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->foutput = NULL; 1760c1bc742181ded4930842b46e9507372f0b1b963James Dong#else 1770c1bc742181ded4930842b46e9507372f0b1b963James Dong sprintf(decoder[i]->outFileName, "%s%i", outFileName, i); 1780c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->foutput = fopen(decoder[i]->outFileName, "wb"); 1790c1bc742181ded4930842b46e9507372f0b1b963James Dong if (decoder[i]->foutput == NULL) 1800c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1810c1bc742181ded4930842b46e9507372f0b1b963James Dong DEBUG(("Unable to open output file\n")); 1820c1bc742181ded4930842b46e9507372f0b1b963James Dong exit(100); 1830c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1840c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif 1850c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1860c1bc742181ded4930842b46e9507372f0b1b963James Dong 1870c1bc742181ded4930842b46e9507372f0b1b963James Dong ret = H264SwDecInit(&(decoder[i]->decInst), disableOutputReordering); 1880c1bc742181ded4930842b46e9507372f0b1b963James Dong 1890c1bc742181ded4930842b46e9507372f0b1b963James Dong if (ret != H264SWDEC_OK) 1900c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1910c1bc742181ded4930842b46e9507372f0b1b963James Dong DEBUG(("Init failed %d\n", ret)); 1920c1bc742181ded4930842b46e9507372f0b1b963James Dong exit(100); 1930c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1940c1bc742181ded4930842b46e9507372f0b1b963James Dong 1950c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->decInput.pStream = decoder[i]->byteStrmStart; 1960c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->decInput.dataLen = strmLen; 1970c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->decInput.intraConcealmentMethod = 0; 1980c1bc742181ded4930842b46e9507372f0b1b963James Dong 1990c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2000c1bc742181ded4930842b46e9507372f0b1b963James Dong 2010c1bc742181ded4930842b46e9507372f0b1b963James Dong /* main decoding loop */ 2020c1bc742181ded4930842b46e9507372f0b1b963James Dong do 2030c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2040c1bc742181ded4930842b46e9507372f0b1b963James Dong /* decode once using each instance */ 2050c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = 0; i < instCount; i++) 2060c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2070c1bc742181ded4930842b46e9507372f0b1b963James Dong ret = H264SwDecDecode(decoder[i]->decInst, 2080c1bc742181ded4930842b46e9507372f0b1b963James Dong &(decoder[i]->decInput), 2090c1bc742181ded4930842b46e9507372f0b1b963James Dong &(decoder[i]->decOutput)); 2100c1bc742181ded4930842b46e9507372f0b1b963James Dong 2110c1bc742181ded4930842b46e9507372f0b1b963James Dong switch(ret) 2120c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2130c1bc742181ded4930842b46e9507372f0b1b963James Dong 2140c1bc742181ded4930842b46e9507372f0b1b963James Dong case H264SWDEC_HDRS_RDY_BUFF_NOT_EMPTY: 2150c1bc742181ded4930842b46e9507372f0b1b963James Dong 2160c1bc742181ded4930842b46e9507372f0b1b963James Dong ret = H264SwDecGetInfo(decoder[i]->decInst, 2170c1bc742181ded4930842b46e9507372f0b1b963James Dong &(decoder[i]->decInfo)); 2180c1bc742181ded4930842b46e9507372f0b1b963James Dong if (ret != H264SWDEC_OK) 2190c1bc742181ded4930842b46e9507372f0b1b963James Dong exit(1); 2200c1bc742181ded4930842b46e9507372f0b1b963James Dong 2210c1bc742181ded4930842b46e9507372f0b1b963James Dong if (cropDisplay && decoder[i]->decInfo.croppingFlag) 2220c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2230c1bc742181ded4930842b46e9507372f0b1b963James Dong DEBUG(("Decoder[%d] Cropping params: (%d, %d) %dx%d\n", 2240c1bc742181ded4930842b46e9507372f0b1b963James Dong i, 2250c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->decInfo.cropParams.cropLeftOffset, 2260c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->decInfo.cropParams.cropTopOffset, 2270c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->decInfo.cropParams.cropOutWidth, 2280c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->decInfo.cropParams.cropOutHeight)); 2290c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2300c1bc742181ded4930842b46e9507372f0b1b963James Dong 2310c1bc742181ded4930842b46e9507372f0b1b963James Dong DEBUG(("Decoder[%d] Width %d Height %d\n", i, 2320c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->decInfo.picWidth, 2330c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->decInfo.picHeight)); 2340c1bc742181ded4930842b46e9507372f0b1b963James Dong 2350c1bc742181ded4930842b46e9507372f0b1b963James Dong DEBUG(("Decoder[%d] videoRange %d, matricCoefficients %d\n", 2360c1bc742181ded4930842b46e9507372f0b1b963James Dong i, decoder[i]->decInfo.videoRange, 2370c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->decInfo.matrixCoefficients)); 2380c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->decInput.dataLen -= 2390c1bc742181ded4930842b46e9507372f0b1b963James Dong (u32)(decoder[i]->decOutput.pStrmCurrPos - 2400c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->decInput.pStream); 2410c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->decInput.pStream = 2420c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->decOutput.pStrmCurrPos; 2430c1bc742181ded4930842b46e9507372f0b1b963James Dong break; 2440c1bc742181ded4930842b46e9507372f0b1b963James Dong 2450c1bc742181ded4930842b46e9507372f0b1b963James Dong case H264SWDEC_PIC_RDY_BUFF_NOT_EMPTY: 2460c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->decInput.dataLen -= 2470c1bc742181ded4930842b46e9507372f0b1b963James Dong (u32)(decoder[i]->decOutput.pStrmCurrPos - 2480c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->decInput.pStream); 2490c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->decInput.pStream = 2500c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->decOutput.pStrmCurrPos; 2510c1bc742181ded4930842b46e9507372f0b1b963James Dong /* fall through */ 2520c1bc742181ded4930842b46e9507372f0b1b963James Dong case H264SWDEC_PIC_RDY: 2530c1bc742181ded4930842b46e9507372f0b1b963James Dong if (ret == H264SWDEC_PIC_RDY) 2540c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->decInput.dataLen = 0; 2550c1bc742181ded4930842b46e9507372f0b1b963James Dong 2560c1bc742181ded4930842b46e9507372f0b1b963James Dong ret = H264SwDecGetInfo(decoder[i]->decInst, 2570c1bc742181ded4930842b46e9507372f0b1b963James Dong &(decoder[i]->decInfo)); 2580c1bc742181ded4930842b46e9507372f0b1b963James Dong if (ret != H264SWDEC_OK) 2590c1bc742181ded4930842b46e9507372f0b1b963James Dong exit(1); 2600c1bc742181ded4930842b46e9507372f0b1b963James Dong 2610c1bc742181ded4930842b46e9507372f0b1b963James Dong while (H264SwDecNextPicture(decoder[i]->decInst, 2620c1bc742181ded4930842b46e9507372f0b1b963James Dong &(decoder[i]->decPicture), 0) == H264SWDEC_PIC_RDY) 2630c1bc742181ded4930842b46e9507372f0b1b963James Dong { 2640c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->picNumber++; 2650c1bc742181ded4930842b46e9507372f0b1b963James Dong 2660c1bc742181ded4930842b46e9507372f0b1b963James Dong numErrors += decoder[i]->decPicture.nbrOfErrMBs; 2670c1bc742181ded4930842b46e9507372f0b1b963James Dong 2680c1bc742181ded4930842b46e9507372f0b1b963James Dong DEBUG(("Decoder[%d] PIC %d, type %s, concealed %d\n", 2690c1bc742181ded4930842b46e9507372f0b1b963James Dong i, decoder[i]->picNumber, 2700c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->decPicture.isIdrPicture 2710c1bc742181ded4930842b46e9507372f0b1b963James Dong ? "IDR" : "NON-IDR", 2720c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->decPicture.nbrOfErrMBs)); 2730c1bc742181ded4930842b46e9507372f0b1b963James Dong fflush(stdout); 2740c1bc742181ded4930842b46e9507372f0b1b963James Dong 2750c1bc742181ded4930842b46e9507372f0b1b963James Dong CropWriteOutput(decoder[i]->foutput, 2760c1bc742181ded4930842b46e9507372f0b1b963James Dong (u8*)decoder[i]->decPicture.pOutputPicture, 2770c1bc742181ded4930842b46e9507372f0b1b963James Dong cropDisplay, &(decoder[i]->decInfo)); 2780c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2790c1bc742181ded4930842b46e9507372f0b1b963James Dong 2800c1bc742181ded4930842b46e9507372f0b1b963James Dong if (maxNumPics && decoder[i]->picNumber == maxNumPics) 2810c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->decInput.dataLen = 0; 2820c1bc742181ded4930842b46e9507372f0b1b963James Dong break; 2830c1bc742181ded4930842b46e9507372f0b1b963James Dong 2840c1bc742181ded4930842b46e9507372f0b1b963James Dong case H264SWDEC_STRM_PROCESSED: 2850c1bc742181ded4930842b46e9507372f0b1b963James Dong case H264SWDEC_STRM_ERR: 2860c1bc742181ded4930842b46e9507372f0b1b963James Dong case H264SWDEC_PARAM_ERR: 2870c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->decInput.dataLen = 0; 2880c1bc742181ded4930842b46e9507372f0b1b963James Dong break; 2890c1bc742181ded4930842b46e9507372f0b1b963James Dong 2900c1bc742181ded4930842b46e9507372f0b1b963James Dong default: 2910c1bc742181ded4930842b46e9507372f0b1b963James Dong DEBUG(("Decoder[%d] FATAL ERROR\n", i)); 2920c1bc742181ded4930842b46e9507372f0b1b963James Dong exit(10); 2930c1bc742181ded4930842b46e9507372f0b1b963James Dong break; 2940c1bc742181ded4930842b46e9507372f0b1b963James Dong 2950c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2960c1bc742181ded4930842b46e9507372f0b1b963James Dong } 2970c1bc742181ded4930842b46e9507372f0b1b963James Dong 2980c1bc742181ded4930842b46e9507372f0b1b963James Dong /* check if any of the instances is still running (=has more data) */ 2990c1bc742181ded4930842b46e9507372f0b1b963James Dong instRunning = instCount; 3000c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = 0; i < instCount; i++) 3010c1bc742181ded4930842b46e9507372f0b1b963James Dong { 3020c1bc742181ded4930842b46e9507372f0b1b963James Dong if (decoder[i]->decInput.dataLen == 0) 3030c1bc742181ded4930842b46e9507372f0b1b963James Dong instRunning--; 3040c1bc742181ded4930842b46e9507372f0b1b963James Dong } 3050c1bc742181ded4930842b46e9507372f0b1b963James Dong 3060c1bc742181ded4930842b46e9507372f0b1b963James Dong } while (instRunning); 3070c1bc742181ded4930842b46e9507372f0b1b963James Dong 3080c1bc742181ded4930842b46e9507372f0b1b963James Dong 3090c1bc742181ded4930842b46e9507372f0b1b963James Dong /* get last frames and close each instance */ 3100c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = 0; i < instCount; i++) 3110c1bc742181ded4930842b46e9507372f0b1b963James Dong { 3120c1bc742181ded4930842b46e9507372f0b1b963James Dong while (H264SwDecNextPicture(decoder[i]->decInst, 3130c1bc742181ded4930842b46e9507372f0b1b963James Dong &(decoder[i]->decPicture), 1) == H264SWDEC_PIC_RDY) 3140c1bc742181ded4930842b46e9507372f0b1b963James Dong { 3150c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->picNumber++; 3160c1bc742181ded4930842b46e9507372f0b1b963James Dong 3170c1bc742181ded4930842b46e9507372f0b1b963James Dong DEBUG(("Decoder[%d] PIC %d, type %s, concealed %d\n", 3180c1bc742181ded4930842b46e9507372f0b1b963James Dong i, decoder[i]->picNumber, 3190c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->decPicture.isIdrPicture 3200c1bc742181ded4930842b46e9507372f0b1b963James Dong ? "IDR" : "NON-IDR", 3210c1bc742181ded4930842b46e9507372f0b1b963James Dong decoder[i]->decPicture.nbrOfErrMBs)); 3220c1bc742181ded4930842b46e9507372f0b1b963James Dong fflush(stdout); 3230c1bc742181ded4930842b46e9507372f0b1b963James Dong 3240c1bc742181ded4930842b46e9507372f0b1b963James Dong CropWriteOutput(decoder[i]->foutput, 3250c1bc742181ded4930842b46e9507372f0b1b963James Dong (u8*)decoder[i]->decPicture.pOutputPicture, 3260c1bc742181ded4930842b46e9507372f0b1b963James Dong cropDisplay, &(decoder[i]->decInfo)); 3270c1bc742181ded4930842b46e9507372f0b1b963James Dong } 3280c1bc742181ded4930842b46e9507372f0b1b963James Dong 3290c1bc742181ded4930842b46e9507372f0b1b963James Dong H264SwDecRelease(decoder[i]->decInst); 3300c1bc742181ded4930842b46e9507372f0b1b963James Dong 3310c1bc742181ded4930842b46e9507372f0b1b963James Dong if (decoder[i]->foutput) 3320c1bc742181ded4930842b46e9507372f0b1b963James Dong fclose(decoder[i]->foutput); 3330c1bc742181ded4930842b46e9507372f0b1b963James Dong 3340c1bc742181ded4930842b46e9507372f0b1b963James Dong free(decoder[i]->byteStrmStart); 3350c1bc742181ded4930842b46e9507372f0b1b963James Dong 3360c1bc742181ded4930842b46e9507372f0b1b963James Dong free(decoder[i]); 3370c1bc742181ded4930842b46e9507372f0b1b963James Dong } 3380c1bc742181ded4930842b46e9507372f0b1b963James Dong 3390c1bc742181ded4930842b46e9507372f0b1b963James Dong free(decoder); 3400c1bc742181ded4930842b46e9507372f0b1b963James Dong 3410c1bc742181ded4930842b46e9507372f0b1b963James Dong if (numErrors) 3420c1bc742181ded4930842b46e9507372f0b1b963James Dong return 1; 3430c1bc742181ded4930842b46e9507372f0b1b963James Dong else 3440c1bc742181ded4930842b46e9507372f0b1b963James Dong return 0; 3450c1bc742181ded4930842b46e9507372f0b1b963James Dong 3460c1bc742181ded4930842b46e9507372f0b1b963James Dong} 3470c1bc742181ded4930842b46e9507372f0b1b963James Dong 3480c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 3490c1bc742181ded4930842b46e9507372f0b1b963James Dong 3500c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 3510c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid CropWriteOutput(FILE *foutput, u8 *imageData, u32 cropDisplay, 3520c1bc742181ded4930842b46e9507372f0b1b963James Dong H264SwDecInfo *decInfo) 3530c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 3540c1bc742181ded4930842b46e9507372f0b1b963James Dong u8 *tmpImage = NULL; 3550c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 tmp, picSize; 3560c1bc742181ded4930842b46e9507372f0b1b963James Dong 3570c1bc742181ded4930842b46e9507372f0b1b963James Dong if (cropDisplay && decInfo->croppingFlag) 3580c1bc742181ded4930842b46e9507372f0b1b963James Dong { 3590c1bc742181ded4930842b46e9507372f0b1b963James Dong picSize = decInfo->cropParams.cropOutWidth * 3600c1bc742181ded4930842b46e9507372f0b1b963James Dong decInfo->cropParams.cropOutHeight; 3610c1bc742181ded4930842b46e9507372f0b1b963James Dong picSize = (3 * picSize)/2; 3620c1bc742181ded4930842b46e9507372f0b1b963James Dong tmpImage = malloc(picSize); 3630c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmpImage == NULL) 3640c1bc742181ded4930842b46e9507372f0b1b963James Dong exit(1); 3650c1bc742181ded4930842b46e9507372f0b1b963James Dong tmp = CropPicture(tmpImage, imageData, 3660c1bc742181ded4930842b46e9507372f0b1b963James Dong decInfo->picWidth, decInfo->picHeight, 3670c1bc742181ded4930842b46e9507372f0b1b963James Dong &(decInfo->cropParams)); 3680c1bc742181ded4930842b46e9507372f0b1b963James Dong if (tmp) 3690c1bc742181ded4930842b46e9507372f0b1b963James Dong exit(1); 3700c1bc742181ded4930842b46e9507372f0b1b963James Dong WriteOutput(foutput, tmpImage, picSize); 3710c1bc742181ded4930842b46e9507372f0b1b963James Dong free(tmpImage); 3720c1bc742181ded4930842b46e9507372f0b1b963James Dong } 3730c1bc742181ded4930842b46e9507372f0b1b963James Dong else 3740c1bc742181ded4930842b46e9507372f0b1b963James Dong { 3750c1bc742181ded4930842b46e9507372f0b1b963James Dong picSize = decInfo->picWidth * decInfo->picHeight; 3760c1bc742181ded4930842b46e9507372f0b1b963James Dong picSize = (3 * picSize)/2; 3770c1bc742181ded4930842b46e9507372f0b1b963James Dong WriteOutput(foutput, imageData, picSize); 3780c1bc742181ded4930842b46e9507372f0b1b963James Dong } 3790c1bc742181ded4930842b46e9507372f0b1b963James Dong 3800c1bc742181ded4930842b46e9507372f0b1b963James Dong} 3810c1bc742181ded4930842b46e9507372f0b1b963James Dong 3820c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 3830c1bc742181ded4930842b46e9507372f0b1b963James Dong 3840c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 3850c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid WriteOutput(FILE *fid, u8 *data, u32 picSize) 3860c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 3870c1bc742181ded4930842b46e9507372f0b1b963James Dong if (fid) 3880c1bc742181ded4930842b46e9507372f0b1b963James Dong fwrite(data, 1, picSize, fid); 3890c1bc742181ded4930842b46e9507372f0b1b963James Dong} 3900c1bc742181ded4930842b46e9507372f0b1b963James Dong 3910c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 3920c1bc742181ded4930842b46e9507372f0b1b963James Dong 3930c1bc742181ded4930842b46e9507372f0b1b963James Dong Function name: H264SwDecTrace 3940c1bc742181ded4930842b46e9507372f0b1b963James Dong 3950c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 3960c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid H264SwDecTrace(char *string) 3970c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 3980c1bc742181ded4930842b46e9507372f0b1b963James Dong FILE *fp; 3990c1bc742181ded4930842b46e9507372f0b1b963James Dong 4000c1bc742181ded4930842b46e9507372f0b1b963James Dong fp = fopen("dec_api.trc", "at"); 4010c1bc742181ded4930842b46e9507372f0b1b963James Dong 4020c1bc742181ded4930842b46e9507372f0b1b963James Dong if (!fp) 4030c1bc742181ded4930842b46e9507372f0b1b963James Dong return; 4040c1bc742181ded4930842b46e9507372f0b1b963James Dong 4050c1bc742181ded4930842b46e9507372f0b1b963James Dong fwrite(string, 1, strlen(string), fp); 4060c1bc742181ded4930842b46e9507372f0b1b963James Dong fwrite("\n", 1,1, fp); 4070c1bc742181ded4930842b46e9507372f0b1b963James Dong 4080c1bc742181ded4930842b46e9507372f0b1b963James Dong fclose(fp); 4090c1bc742181ded4930842b46e9507372f0b1b963James Dong} 4100c1bc742181ded4930842b46e9507372f0b1b963James Dong 4110c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 4120c1bc742181ded4930842b46e9507372f0b1b963James Dong 4130c1bc742181ded4930842b46e9507372f0b1b963James Dong Function name: H264SwDecmalloc 4140c1bc742181ded4930842b46e9507372f0b1b963James Dong 4150c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 4160c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid* H264SwDecMalloc(u32 size) 4170c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 4180c1bc742181ded4930842b46e9507372f0b1b963James Dong return malloc(size); 4190c1bc742181ded4930842b46e9507372f0b1b963James Dong} 4200c1bc742181ded4930842b46e9507372f0b1b963James Dong 4210c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 4220c1bc742181ded4930842b46e9507372f0b1b963James Dong 4230c1bc742181ded4930842b46e9507372f0b1b963James Dong Function name: H264SwDecFree 4240c1bc742181ded4930842b46e9507372f0b1b963James Dong 4250c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 4260c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid H264SwDecFree(void *ptr) 4270c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 4280c1bc742181ded4930842b46e9507372f0b1b963James Dong free(ptr); 4290c1bc742181ded4930842b46e9507372f0b1b963James Dong} 4300c1bc742181ded4930842b46e9507372f0b1b963James Dong 4310c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 4320c1bc742181ded4930842b46e9507372f0b1b963James Dong 4330c1bc742181ded4930842b46e9507372f0b1b963James Dong Function name: H264SwDecMemcpy 4340c1bc742181ded4930842b46e9507372f0b1b963James Dong 4350c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 4360c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid H264SwDecMemcpy(void *dest, void *src, u32 count) 4370c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 4380c1bc742181ded4930842b46e9507372f0b1b963James Dong memcpy(dest, src, count); 4390c1bc742181ded4930842b46e9507372f0b1b963James Dong} 4400c1bc742181ded4930842b46e9507372f0b1b963James Dong 4410c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 4420c1bc742181ded4930842b46e9507372f0b1b963James Dong 4430c1bc742181ded4930842b46e9507372f0b1b963James Dong Function name: H264SwDecMemset 4440c1bc742181ded4930842b46e9507372f0b1b963James Dong 4450c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 4460c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid H264SwDecMemset(void *ptr, i32 value, u32 count) 4470c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 4480c1bc742181ded4930842b46e9507372f0b1b963James Dong memset(ptr, value, count); 4490c1bc742181ded4930842b46e9507372f0b1b963James Dong} 4500c1bc742181ded4930842b46e9507372f0b1b963James Dong 4510c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------ 4520c1bc742181ded4930842b46e9507372f0b1b963James Dong 4530c1bc742181ded4930842b46e9507372f0b1b963James Dong Function name: CropPicture 4540c1bc742181ded4930842b46e9507372f0b1b963James Dong 4550c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/ 4560c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 CropPicture(u8 *pOutImage, u8 *pInImage, 4570c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 picWidth, u32 picHeight, CropParams *pCropParams) 4580c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 4590c1bc742181ded4930842b46e9507372f0b1b963James Dong 4600c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 i, j; 4610c1bc742181ded4930842b46e9507372f0b1b963James Dong u32 outWidth, outHeight; 4620c1bc742181ded4930842b46e9507372f0b1b963James Dong u8 *pOut, *pIn; 4630c1bc742181ded4930842b46e9507372f0b1b963James Dong 4640c1bc742181ded4930842b46e9507372f0b1b963James Dong if (pOutImage == NULL || pInImage == NULL || pCropParams == NULL || 4650c1bc742181ded4930842b46e9507372f0b1b963James Dong !picWidth || !picHeight) 4660c1bc742181ded4930842b46e9507372f0b1b963James Dong { 4670c1bc742181ded4930842b46e9507372f0b1b963James Dong /* due to lint warning */ 4680c1bc742181ded4930842b46e9507372f0b1b963James Dong free(pOutImage); 4690c1bc742181ded4930842b46e9507372f0b1b963James Dong return(1); 4700c1bc742181ded4930842b46e9507372f0b1b963James Dong } 4710c1bc742181ded4930842b46e9507372f0b1b963James Dong 4720c1bc742181ded4930842b46e9507372f0b1b963James Dong if ( ((pCropParams->cropLeftOffset + pCropParams->cropOutWidth) > 4730c1bc742181ded4930842b46e9507372f0b1b963James Dong picWidth ) || 4740c1bc742181ded4930842b46e9507372f0b1b963James Dong ((pCropParams->cropTopOffset + pCropParams->cropOutHeight) > 4750c1bc742181ded4930842b46e9507372f0b1b963James Dong picHeight ) ) 4760c1bc742181ded4930842b46e9507372f0b1b963James Dong { 4770c1bc742181ded4930842b46e9507372f0b1b963James Dong /* due to lint warning */ 4780c1bc742181ded4930842b46e9507372f0b1b963James Dong free(pOutImage); 4790c1bc742181ded4930842b46e9507372f0b1b963James Dong return(1); 4800c1bc742181ded4930842b46e9507372f0b1b963James Dong } 4810c1bc742181ded4930842b46e9507372f0b1b963James Dong 4820c1bc742181ded4930842b46e9507372f0b1b963James Dong outWidth = pCropParams->cropOutWidth; 4830c1bc742181ded4930842b46e9507372f0b1b963James Dong outHeight = pCropParams->cropOutHeight; 4840c1bc742181ded4930842b46e9507372f0b1b963James Dong 4850c1bc742181ded4930842b46e9507372f0b1b963James Dong pIn = pInImage + pCropParams->cropTopOffset*picWidth + 4860c1bc742181ded4930842b46e9507372f0b1b963James Dong pCropParams->cropLeftOffset; 4870c1bc742181ded4930842b46e9507372f0b1b963James Dong pOut = pOutImage; 4880c1bc742181ded4930842b46e9507372f0b1b963James Dong 4890c1bc742181ded4930842b46e9507372f0b1b963James Dong /* luma */ 4900c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = outHeight; i; i--) 4910c1bc742181ded4930842b46e9507372f0b1b963James Dong { 4920c1bc742181ded4930842b46e9507372f0b1b963James Dong for (j = outWidth; j; j--) 4930c1bc742181ded4930842b46e9507372f0b1b963James Dong { 4940c1bc742181ded4930842b46e9507372f0b1b963James Dong *pOut++ = *pIn++; 4950c1bc742181ded4930842b46e9507372f0b1b963James Dong } 4960c1bc742181ded4930842b46e9507372f0b1b963James Dong pIn += picWidth - outWidth; 4970c1bc742181ded4930842b46e9507372f0b1b963James Dong } 4980c1bc742181ded4930842b46e9507372f0b1b963James Dong 4990c1bc742181ded4930842b46e9507372f0b1b963James Dong outWidth >>= 1; 5000c1bc742181ded4930842b46e9507372f0b1b963James Dong outHeight >>= 1; 5010c1bc742181ded4930842b46e9507372f0b1b963James Dong 5020c1bc742181ded4930842b46e9507372f0b1b963James Dong pIn = pInImage + picWidth*picHeight + 5030c1bc742181ded4930842b46e9507372f0b1b963James Dong pCropParams->cropTopOffset*picWidth/4 + pCropParams->cropLeftOffset/2; 5040c1bc742181ded4930842b46e9507372f0b1b963James Dong 5050c1bc742181ded4930842b46e9507372f0b1b963James Dong /* cb */ 5060c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = outHeight; i; i--) 5070c1bc742181ded4930842b46e9507372f0b1b963James Dong { 5080c1bc742181ded4930842b46e9507372f0b1b963James Dong for (j = outWidth; j; j--) 5090c1bc742181ded4930842b46e9507372f0b1b963James Dong { 5100c1bc742181ded4930842b46e9507372f0b1b963James Dong *pOut++ = *pIn++; 5110c1bc742181ded4930842b46e9507372f0b1b963James Dong } 5120c1bc742181ded4930842b46e9507372f0b1b963James Dong pIn += picWidth/2 - outWidth; 5130c1bc742181ded4930842b46e9507372f0b1b963James Dong } 5140c1bc742181ded4930842b46e9507372f0b1b963James Dong 5150c1bc742181ded4930842b46e9507372f0b1b963James Dong pIn = pInImage + 5*picWidth*picHeight/4 + 5160c1bc742181ded4930842b46e9507372f0b1b963James Dong pCropParams->cropTopOffset*picWidth/4 + pCropParams->cropLeftOffset/2; 5170c1bc742181ded4930842b46e9507372f0b1b963James Dong 5180c1bc742181ded4930842b46e9507372f0b1b963James Dong /* cr */ 5190c1bc742181ded4930842b46e9507372f0b1b963James Dong for (i = outHeight; i; i--) 5200c1bc742181ded4930842b46e9507372f0b1b963James Dong { 5210c1bc742181ded4930842b46e9507372f0b1b963James Dong for (j = outWidth; j; j--) 5220c1bc742181ded4930842b46e9507372f0b1b963James Dong { 5230c1bc742181ded4930842b46e9507372f0b1b963James Dong *pOut++ = *pIn++; 5240c1bc742181ded4930842b46e9507372f0b1b963James Dong } 5250c1bc742181ded4930842b46e9507372f0b1b963James Dong pIn += picWidth/2 - outWidth; 5260c1bc742181ded4930842b46e9507372f0b1b963James Dong } 5270c1bc742181ded4930842b46e9507372f0b1b963James Dong 5280c1bc742181ded4930842b46e9507372f0b1b963James Dong return (0); 5290c1bc742181ded4930842b46e9507372f0b1b963James Dong 5300c1bc742181ded4930842b46e9507372f0b1b963James Dong} 5310c1bc742181ded4930842b46e9507372f0b1b963James Dong 532