1 2 /* 3 * Copyright 2001-2008 Texas Instruments - http://www.ti.com/ 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 /* ==================================================================== 18 * Texas Instruments OMAP(TM) Platform Software 19 * (c) Copyright Texas Instruments, Incorporated. All Rights Reserved. 20 * 21 * Use of this software is controlled by the terms and conditions found 22 * in the license agreement under which this software has been supplied. 23 * ==================================================================== */ 24 /** 25 * @file JPEGTestEnc.c 26 * 27 * This file implements OMX Component for JPEG encoder that 28 * is fully compliant with the OMX specification 1.5. 29 * 30 * @path $(CSLPATH)\src 31 * 32 * @rev 0.1 33 */ 34 /* -------------------------------------------------------------------------------- */ 35 /* ================================================================================ 36 *! 37 *! Revision History 38 *! =================================== 39 *! 40 *! 22-May-2006 mf: Revisions appear in reverse chronological order; 41 *! that is, newest first. The date format is dd-Mon-yyyy. 42 * ================================================================================= */ 43 44 /*utilities includes */ 45 #ifdef UNDER_CE 46 #include <windows.h> 47 #endif 48 #include <stdio.h> 49 #include <stdlib.h> 50 #include <stdarg.h> 51 #include <string.h> 52 #include <sched.h> 53 #include <unistd.h> 54 #include <sys/types.h> 55 #include <sys/select.h> 56 #include <time.h> 57 //#include <mcheck.h> 58 #include <getopt.h> 59 #include <signal.h> 60 61 /* OMX includes */ 62 #include <OMX_Component.h> 63 #include "OMX_JpegEnc_CustomCmd.h" 64 #include "JPEGTestEnc.h" 65 #include "OMX_JpegEnc_Utils.h" 66 67 /* DSP recovery includes */ 68 #include <qosregistry.h> 69 #include <qosti.h> 70 #include <dbapi.h> 71 #include <DSPManager.h> 72 #include <DSPProcessor.h> 73 #include <DSPProcessor_OEM.h> 74 75 #define STRESS 76 #define NSTRESSCASES 1 77 #define STRESSMULTILOAD 1 78 #define NUM_OF_PORTS 2 79 #define NUM_OF_BUFFERSJPEG 1 80 81 #ifdef UNDER_CE 82 OMX_STRING StrJpegEncoder= "OMX.TI.IMAGE.JPEG.ENC"; 83 #else 84 OMX_STRING StrJpegEncoder= "OMX.TI.JPEG.Encoder"; 85 #endif 86 87 OMX_U8 APPLICATION1_NOTHUMB[]={ 88 89 /* 0 */0, 0, 0, 0, 0x45, 0x78, 0x69, 0x66, 0x00, 0x00, /* Indicate Exif Data*/ 90 91 /* 10 */ 0x49, 0x49, /* "Intel" type byte align*/ 92 93 0x2A, 0x00, /* Confirm "Intel" type byte align*/ 94 95 /* 14 */ 0x08, 0x00, 0x00, 0x00, /* Offset to first IFDc*/ 96 97 0x06, 0x00, /* Number of IFD as 1*/ 98 99 /* 21 */0x0f, 0x01, /* TAG: Make*/ 100 101 0x02, 0x00, /* Type: Data format is 0x0002, ASCII */ 102 103 0x0c, 0x00, 0x00, 0x00, /* Count: number of chars*/ 104 105 0x56, 0x00, 0x00, 0x00, /* Offset Make data*/ 106 107 /* 33 */0x10, 0x01, /* TAG: Model*/ 108 109 0x02, 0x00, /* Type: Data format is 0x0002, ASCII */ 110 111 0x05, 0x00, 0x00, 0x00, /* Count: number of chars*/ 112 113 0x62, 0x00, 0x00, 0x00, /* Offset Model data*/ 114 115 /*45*/0x12, 0x01, /* TAG: Orientation*/ 116 117 0x03, 0x00, /* Type: Data format is 0x0003, (short)*/ 118 119 0x01, 0x00, 0x00, 0x00, /* Count: number of chars*/ 120 121 0x01, 0x00, 0x00, 0x00, /* 1 means normal orientation*/ 122 123 /*57*/0x31, 0x01, /* TAG: Software*/ 124 125 0x02, 0x00, /* Type: ASCII*/ 126 127 0x08, 0x00, 0x00, 0x00, /* Count: number of chars*/ 128 129 0x67, 0x00, 0x00, 0x00, /* Offset*/ 130 131 /*69*/0x3b, 0x01, /* TAG: Artist*/ 132 133 0x02, 0x00, /* Type: ASCII*/ 134 135 0x09, 0x00, 0x00, 0x00, /* Count: number of chars*/ 136 137 0x6f, 0x00, 0x00, 0x00, /* Offset*/ 138 139 /* 81 */0x69, 0x87, /* Exif SubIFD*/ 140 141 /* 83 */ 0x04, 0x00, /* Data format is 0x0004, ULInt*/ 142 143 0x01, 0x00, 0x00, 0x00, /* number of components is 1.*/ 144 145 /*long integer data size is 4bytes/components, so total data length is 1x4=4bytes*/ 146 147 /* 89 */ 0x78, 0x00,0x00, 0x00, /* Offset of Exif data*/ 148 149 /*93*/0x9E, 0x00, 0x00, 0x00, /* Offset to next IFD. As we are saying only one directory( Number of IFD as 1) this indicate the offset of next IFD*/ 150 151 /*97*/0x53, 0x61, 0x73, 0x6b, 0x65, 0x6e, 0x20, 0x26, 0x20, 0x54, 0x49, 0x00, /*Make*/ 152 153 /*109*/0x4f, 0x4d, 0x41, 0x50,0x00, /*Model*/ 154 155 /*114*/0x4f, 0x70, 0x65, 0x6e, 0x4d, 0x61, 0x78, 0x00, /*Software*/ 156 157 /*122*/0x47, 0x65, 0x6f, 0x72, 0x67, 0x65, 0x20, 0x53, 0x00, /*Artist*/ 158 159 /* exif ub-ID start Here */ 160 161 /* 131 */ 0x03, 0x00, /* Number of Exif ID*/ 162 163 0x00, 0x90, /* Exif Version*/ 164 165 0x07, 0x00, /*Data format is 0x0007, undefined*/ 166 167 0x04, 0x00, 0x00, 0x00, /* number of components is 4.*/ 168 169 /*Undefined data size is 1bytes/components, so total data length is 4x1=4bytes*/ 170 171 0x30, 0x32, 0x32, 0x30, /* Exif version number 30 32 32 30 meaning 0220 (2.2)*/ 172 173 /* next IFD start Here */ 174 175 /*169*/0x03, 0x00, /* Number of IFD1*/ 176 177 /*171*/0x03, 0x01, /* Compression (0x0103)*/ 178 179 0x03, 0x00, /*Data format is 0x0003 unsigned short,*/ 180 181 0x01, 0x00, 0x00, 0x00, /* number of components is 1.*/ 182 183 /*unsigned short data size is 2bytes/components, so total data length is 1x2=2bytes*/ 184 185 /*183*/ 0x01, 0x02, /* JpegIFOffset (0x0201)*/ 186 187 0x04, 0x00, /* Data format is 0x0004, ULInt*/ 188 189 0x01, 0x00, 0x00, 0x00, /* number of components is 1.*/ 190 191 /*195*/ 0x02, 0x02, /* JpegIFByteCount (0x0202)*/ 192 193 0x04, 0x00, /* Data format is 0x0004, ULInt*/ 194 195 0x01, 0x00, 0x00, 0x00, /* number of components is 1.*/ 196 197 /*203*/ 0xff, 0xff,0xff, 0xff, /* Legth of thumbnail data*/ 198 199 }; 200 201 OMX_U8 APPLICATION1_THUMB[]={ 202 /* 0 */0, 0, 0, 0, 0x45, 0x78, 0x69, 0x66, 0x00, 0x00, /* Indicate Exif Data*/ 203 /* 10 */ 0x49, 0x49, /* "Intel" type byte align*/ 204 0x2A, 0x00, /* Confirm "Intel" type byte align*/ 205 /* 14 */ 0x08, 0x00, 0x00, 0x00, /* Offset to first IFDc*/ 206 0x06, 0x00, /* Number of IFD as 1*/ 207 208 /* 21 */0x0f, 0x01, /* TAG: Make*/ 209 0x02, 0x00, /* Type: Data format is 0x0002, ASCII */ 210 0x0c, 0x00, 0x00, 0x00, /* Count: number of chars*/ 211 0x56, 0x00, 0x00, 0x00, /* Offset Make data*/ 212 213 /* 33 */0x10, 0x01, /* TAG: Model*/ 214 0x02, 0x00, /* Type: Data format is 0x0002, ASCII */ 215 0x05, 0x00, 0x00, 0x00, /* Count: number of chars*/ 216 0x62, 0x00, 0x00, 0x00, /* Offset Model data*/ 217 218 /*45*/0x12, 0x01, /* TAG: Orientation*/ 219 0x03, 0x00, /* Type: Data format is 0x0003, (short)*/ 220 0x01, 0x00, 0x00, 0x00, /* Count: number of chars*/ 221 0x01, 0x00, 0x00, 0x00, /* 1 means normal orientation*/ 222 223 /*57*/0x31, 0x01, /* TAG: Software*/ 224 0x02, 0x00, /* Type: ASCII*/ 225 0x08, 0x00, 0x00, 0x00, /* Count: number of chars*/ 226 0x67, 0x00, 0x00, 0x00, /* Offset*/ 227 228 /*69*/0x3b, 0x01, /* TAG: Artist*/ 229 0x02, 0x00, /* Type: ASCII*/ 230 0x09, 0x00, 0x00, 0x00, /* Count: number of chars*/ 231 0x6f, 0x00, 0x00, 0x00, /* Offset*/ 232 233 234 /* 81 */0x69, 0x87, /* Exif SubIFD*/ 235 /* 83 */ 0x04, 0x00, /* Data format is 0x0004, ULInt*/ 236 0x01, 0x00, 0x00, 0x00, /* number of components is 1.*/ 237 /*long integer data size is 4bytes/components, so total data length is 1x4=4bytes*/ 238 /* 89 */ 0x78, 0x00,0x00, 0x00, /* Offset of Exif data*/ 239 240 /*93*/0x9E, 0x00, 0x00, 0x00, /* Offset to next IFD. As we are saying only one directory( Number of IFD as 1) this indicate the offset of next IFD*/ 241 242 /*97*/0x53, 0x61, 0x73, 0x6b, 0x65, 0x6e, 0x20, 0x26, 0x20, 0x54, 0x49, 0x00, /*Make*/ 243 244 /*109*/0x4f, 0x4d, 0x41, 0x50,0x00, /*Model*/ 245 246 /*114*/0x4f, 0x70, 0x65, 0x6e, 0x4d, 0x61, 0x78, 0x00, /*Software*/ 247 248 /*122*/0x47, 0x65, 0x6f, 0x72, 0x67, 0x65, 0x20, 0x53, 0x00, /*Artist*/ 249 250 /* exif ub-ID start Here */ 251 /* 131 */ 0x03, 0x00, /* Number of Exif ID*/ 252 0x00, 0x90, /* Exif Version*/ 253 0x07, 0x00, /*Data format is 0x0007, undefined*/ 254 0x04, 0x00, 0x00, 0x00, /* number of components is 4.*/ 255 /*Undefined data size is 1bytes/components, so total data length is 4x1=4bytes*/ 256 0x30, 0x32, 0x32, 0x30, /* Exif version number 30 32 32 30 meaning 0220 (2.2)*/ 257 258 /*145*/0x02, 0xA0, /* Exif Image Width (0xA002)*/ 259 0x04, 0x00, /* Data format is 0x0004, ULInt*/ 260 0x01, 0x00, 0x00, 0x00, /* number of components is 1.*/ 261 /* 153 */ 0xB0, 0x00,0x00, 0x00, /* Image width , 0x00000280 i.e. 640*/ 262 263 /*157*/0x03, 0xA0, /* Exif Image Width (0xA003)*/ 264 0x04, 0x00, /* Data format is 0x0004, ULInt*/ 265 0x01, 0x00, 0x00, 0x00, /* number of components is 1.*/ 266 /* 165 */ 0x90, 0x00,0x00, 0x00, /* Image Height , 0x000001E0 i.e. 480*/ 267 268 269 270 /* next IFD start Here */ 271 /*169*/0x03, 0x00, /* Number of IFD1*/ 272 /*171*/0x03, 0x01, /* Compression (0x0103)*/ 273 0x03, 0x00, /*Data format is 0x0003 unsigned short,*/ 274 0x01, 0x00, 0x00, 0x00, /* number of components is 1.*/ 275 /*unsigned short data size is 2bytes/components, so total data length is 1x2=2bytes*/ 276 277 0x06, 0x00,0x00, 0x00, /* '6' means JPEG compression.*/ 278 /*Shows compression method. 279 o '1' means no compression, 280 o '6' means JPEG compression.*/ 281 282 /*183*/ 0x01, 0x02, /* JpegIFOffset (0x0201)*/ 283 0x04, 0x00, /* Data format is 0x0004, ULInt*/ 284 0x01, 0x00, 0x00, 0x00, /* number of components is 1.*/ 285 /*191*/ 0xc4, 0x00,0x00, 0x00, /* Address 0f Thumbnail data*/ 286 287 /*195*/ 0x02, 0x02, /* JpegIFByteCount (0x0202)*/ 288 0x04, 0x00, /* Data format is 0x0004, ULInt*/ 289 0x01, 0x00, 0x00, 0x00, /* number of components is 1.*/ 290 /*203*/ 0xff, 0xff,0xff, 0xff, /* Legth of thumbnail data*/ 291 }; 292 293 /*Set the fist 4 bytes to 0*/ 294 OMX_U8 APPLICATION13[200] = { 295 0x00, 0x00, 0x00, 0x00, /*We should set the first 4 bytes to 0 */ 296 0x50, 0x68, 0x6f, 0x74, 0x6f, 0x73, 0x68, 0x6f, 0x70, 0x20, 0x33, 0x2e, 0x30, 0x00,/*Photoshop header*/ 297 0x38, 0x42, 0x49, 0x4d, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 298 0x4e, /* Initial marker*/ 299 /*IPTC Marker TAG Size of string*/ 300 0x1c, 0x02, 0x78, 0x00, 0x20, 301 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x61, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x69, 0x6d, 0x61, 0x67, 0x65, /*String of data (ASCII)*/ 302 0x1c, 0x02, 0x7a, 0x00, 0x16, 303 0x49, 0x27,0x6d, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x61, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, 0x72, 304 0x1c, 0x02, 0x5a, 0x00, 0x09, 305 0x4d, 0x6f, 0x6e, 0x74, 0x65, 0x72, 0x72, 0x65, 0x79, 306 307 }; 308 309 OMX_U8 APPLICATION0[19]={0, 0, 0, 0, 310 0x4A, 0x46, 0x49, 0x46, 0x00, // JFIF Identifier 311 0x01, 0x02, // Version 312 0x00, // X and Y Unit Densities. 313 0x00, 0x08, // Horizontal Pixel density 314 0x00, 0x09, // Vertical Pixel density 315 0x00, 316 0x00, 317 0x00, 318 }; 319 320 OMX_U8 APPLICATION5[6]={0xff,0xff,0xff,0xff,0xff,0xff}; 321 const OMX_U8 CustomLumaQuantizationTable[64]= { 322 14, 10, 9, 14, 22, 30, 41, 51, 323 12, 12, 14, 19, 26, 58, 60, 55, 324 14, 13, 16, 24, 40, 57, 69, 56, 325 14, 17, 22, 29, 51, 87, 80, 62, 326 18, 22, 37, 56, 68, 109, 103, 77, 327 24, 35, 55, 64, 81, 104, 113, 92, 328 49, 64, 78, 87, 103, 121, 120, 101, 329 72, 92, 95, 98, 112, 100, 103, 99, 330 }; 331 332 const OMX_U8 CustomChromaQuantizationTable[64]= { 333 15, 16, 22, 35, 99, 99, 99, 99, 334 18, 21, 26, 66, 99, 99, 99, 99, 335 24, 26, 56, 99, 99, 99, 99, 99, 336 47, 66, 99, 99, 99, 99, 99, 99, 337 99, 99, 99, 99, 99, 99, 99, 99, 338 99, 99, 99, 99, 99, 99, 99, 99, 339 99, 99, 99, 99, 99, 99, 99, 99, 340 99, 99, 99, 99, 99, 99, 99, 99 341 }; 342 343 JPEGENC_CUSTOM_HUFFMAN_TABLE CustomHuffmanTable = 344 { 345 /* VLC Tables */ 346 /*Set 1 for Y Component */ 347 /*DC-Y*/ 348 /*const unsigned int JPEGENC_DCHUFFY[12] */ 349 /*Length[16]-Codeword[16]*/ 350 { 351 0x00020000, 352 0x00030002, 353 0x00030003, 354 0x00030004, 355 0x00030005, 356 0x00030006, 357 0x0004000e, 358 0x0005001e, 359 0x0006003e, 360 0x0007007e, 361 0x000800fe, 362 0x000901fe 363 }, 364 365 /*AC-Y*/ 366 /*const unsigned int JPEGENC_ACHUFFY[16][16] */ 367 /*Length[16]-Codeword[16]*/ 368 { 369 { 370 0x0004000a, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 371 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 372 0x00000000, 0x00000000, 0x00000000, 0x000b07f9 373 }, 374 { 375 0x00020000, 0x0004000c, 0x0005001c, 0x0006003a, 0x0006003b, 0x0007007a, 376 0x0007007b, 0x000800fa, 0x000901f8, 0x000901f9, 0x000901fa, 0x000a03f9, 377 0x000a03fa, 0x000b07f8, 0x0010ffeb, 0x0010fff5 378 }, 379 { 380 0x00020001, 0x0005001b, 0x000800f9, 0x000901f7, 0x000a03f8, 0x000b07f7, 381 0x000c0ff6, 0x000c0ff7, 0x000f7fc0, 0x0010ffbe, 0x0010ffc7, 0x0010ffd0, 382 0x0010ffd9, 0x0010ffe2, 0x0010ffec, 0x0010fff6 383 }, 384 { 385 0x00030004, 0x00070079, 0x000a03f7, 0x000c0ff5, 0x0010ff96, 0x0010ff9e, 386 0x0010ffa6, 0x0010ffae, 0x0010ffb6, 0x0010ffbf, 0x0010ffc8, 0x0010ffd1, 387 0x0010ffda, 0x0010ffe3, 0x0010ffed, 0x0010fff7 388 }, 389 { 390 0x0004000b, 0x000901f6, 0x000c0ff4, 0x0010ff8f, 0x0010ff97, 0x0010ff9f, 391 0x0010ffa7, 0x0010ffaf, 0x0010ffb7, 0x0010ffc0, 0x0010ffc9, 0x0010ffd2, 392 0x0010ffdb, 0x0010ffe4, 0x0010ffee, 0x0010fff8 393 }, 394 { 395 0x0005001a, 0x000b07f6, 0x0010ff89, 0x0010ff90, 0x0010ff98, 0x0010ffa0, 396 0x0010ffa8, 0x0010ffb0, 0x0010ffb8, 0x0010ffc1, 0x0010ffca, 0x0010ffd3, 397 0x0010ffdc, 0x0010ffe5, 0x0010ffef, 0x0010fff9 398 }, 399 { 400 0x00070078, 0x0010ff84, 0x0010ff8a, 0x0010ff91, 0x0010ff99, 0x0010ffa1, 401 0x0010ffa9, 0x0010ffb1, 0x0010ffb9, 0x0010ffc2, 0x0010ffcb, 0x0010ffd4, 402 0x0010ffdd, 0x0010ffe6, 0x0010fff0, 0x0010fffa 403 }, 404 { 405 0x000800f8, 0x0010ff85, 0x0010ff8b, 0x0010ff92, 0x0010ff9a, 0x0010ffa2, 406 0x0010ffaa, 0x0010ffb2, 0x0010ffba, 0x0010ffc3, 0x0010ffcc, 0x0010ffd5, 407 0x0010ffde, 0x0010ffe7, 0x0010fff1, 0x0010fffb 408 }, 409 { 410 0x000a03f6, 0x0010ff86, 0x0010ff8c, 0x0010ff93, 0x0010ff9b, 0x0010ffa3, 411 0x0010ffab, 0x0010ffb3, 0x0010ffbb, 0x0010ffc4, 0x0010ffcd, 0x0010ffd6, 412 0x0010ffdf, 0x0010ffe8, 0x0010fff2, 0x0010fffc 413 }, 414 { 415 0x0010ff82, 0x0010ff87, 0x0010ff8d, 0x0010ff94, 0x0010ff9c, 0x0010ffa4, 416 0x0010ffac, 0x0010ffb4, 0x0010ffbc, 0x0010ffc5, 0x0010ffce, 0x0010ffd7, 417 0x0010ffe0, 0x0010ffe9, 0x0010fff3, 0x0010fffd 418 }, 419 { 420 0x0010ff83, 0x0010ff88, 0x0010ff8e, 0x0010ff95, 0x0010ff9d, 0x0010ffa5, 421 0x0010ffad, 0x0010ffb5, 0x0010ffbd, 0x0010ffc6, 0x0010ffcf, 0x0010ffd8, 422 0x0010ffe1, 0x0010ffea, 0x0010fff4, 0x0010fffe 423 }, 424 { 425 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 426 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 427 0x00000000, 0x00000000, 0x00000000, 0x00000000 428 }, 429 { 430 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 431 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 432 0x00000000, 0x00000000, 0x00000000, 0x00000000 433 }, 434 { 435 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 436 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 437 0x00000000, 0x00000000, 0x00000000, 0x00000000 438 }, 439 { 440 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 441 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 442 0x00000000, 0x00000000, 0x00000000, 0x00000000 443 }, 444 { 445 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 446 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 447 0x00000000, 0x00000000, 0x00000000, 0x00000000 448 } 449 }, 450 451 /*Set 2 for U & V Component */ 452 /*DC-UV*/ 453 /*const unsigned int JPEGENC_DCHUFFUV[12] */ 454 /*Length[16]-Codeword[16]*/ 455 { 456 0x00020000, 457 0x00020001, 458 0x00020002, 459 0x00030006, 460 0x0004000e, 461 0x0005001e, 462 0x0006003e, 463 0x0007007e, 464 0x000800fe, 465 0x000901fe, 466 0x000a03fe, 467 0x000b07fe 468 }, 469 470 /*AC-UV*/ 471 /*const unsigned int JPEGENC_ACHUFFUV[16][16] */ 472 /*Length[16]-Codeword[16]*/ 473 { 474 { 475 0x00020000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 476 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 477 0x00000000, 0x00000000, 0x00000000, 0x000a03fa 478 }, 479 { 480 0x00020001, 0x0004000b, 0x0005001a, 0x0005001b, 0x0006003a, 0x0006003b, 481 0x00070079, 0x0007007a, 0x000800f9, 0x000901f7, 0x000901f8, 0x000901f9, 482 0x000901fa, 0x000b07f9, 0x000e3fe0, 0x000f7fc3 483 }, 484 { 485 0x00030004, 0x00060039, 0x000800f7, 0x000800f8, 0x000901f6, 0x000a03f9, 486 0x000b07f7, 0x000b07f8, 0x0010ffb7, 0x0010ffc0, 0x0010ffc9, 0x0010ffd2, 487 0x0010ffdb, 0x0010ffe4, 0x0010ffed, 0x0010fff6 488 }, 489 { 490 0x0004000a, 0x000800f6, 0x000a03f7, 0x000a03f8, 0x0010ff97, 0x0010ff9f, 491 0x0010ffa7, 0x0010ffaf, 0x0010ffb8, 0x0010ffc1, 0x0010ffca, 0x0010ffd3, 492 0x0010ffdc, 0x0010ffe5, 0x0010ffee, 0x0010fff7 493 }, 494 { 495 0x00050018, 0x000901f5, 0x000c0ff6, 0x000c0ff7, 0x0010ff98, 0x0010ffa0, 496 0x0010ffa8, 0x0010ffb0, 0x0010ffb9, 0x0010ffc2, 0x0010ffcb, 0x0010ffd4, 497 0x0010ffdd, 0x0010ffe6, 0x0010ffef, 0x0010fff8 498 }, 499 { 500 0x00050019, 0x000b07f6, 0x000f7fc2, 0x0010ff91, 0x0010ff99, 0x0010ffa1, 501 0x0010ffa9, 0x0010ffb1, 0x0010ffba, 0x0010ffc3, 0x0010ffcc, 0x0010ffd5, 502 0x0010ffde, 0x0010ffe7, 0x0010fff0, 0x0010fff9 503 }, 504 { 505 0x00060038, 0x000c0ff5, 0x0010ff8c, 0x0010ff92, 0x0010ff9a, 0x0010ffa2, 506 0x0010ffaa, 0x0010ffb2, 0x0010ffbb, 0x0010ffc4, 0x0010ffcd, 0x0010ffd6, 507 0x0010ffdf, 0x0010ffe8, 0x0010fff1, 0x0010fffa 508 }, 509 { 510 0x00070078, 0x0010ff88, 0x0010ff8d, 0x0010ff93, 0x0010ff9b, 0x0010ffa3, 511 0x0010ffab, 0x0010ffb3, 0x0010ffbc, 0x0010ffc5, 0x0010ffce, 0x0010ffd7, 512 0x0010ffe0, 0x0010ffe9, 0x0010fff2, 0x0010fffb 513 }, 514 { 515 0x000901f4, 0x0010ff89, 0x0010ff8e, 0x0010ff94, 0x0010ff9c, 0x0010ffa4, 516 0x0010ffac, 0x0010ffb4, 0x0010ffbd, 0x0010ffc6, 0x0010ffcf, 0x0010ffd8, 517 0x0010ffe1, 0x0010ffea, 0x0010fff3, 0x0010fffc 518 }, 519 { 520 0x000a03f6, 0x0010ff8a, 0x0010ff8f, 0x0010ff95, 0x0010ff9d, 0x0010ffa5, 521 0x0010ffad, 0x0010ffb5, 0x0010ffbe, 0x0010ffc7, 0x0010ffd0, 0x0010ffd9, 522 0x0010ffe2, 0x0010ffeb, 0x0010fff4, 0x0010fffd 523 }, 524 { 525 0x000c0ff4, 0x0010ff8b, 0x0010ff90, 0x0010ff96, 0x0010ff9e, 0x0010ffa6, 526 0x0010ffae, 0x0010ffb6, 0x0010ffbf, 0x0010ffc8, 0x0010ffd1, 0x0010ffda, 527 0x0010ffe3, 0x0010ffec, 0x0010fff5, 0x0010fffe 528 }, 529 { 530 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 531 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 532 0x00000000, 0x00000000, 0x00000000, 0x00000000 533 }, 534 { 535 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 536 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 537 0x00000000, 0x00000000, 0x00000000, 0x00000000 538 }, 539 { 540 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 541 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 542 0x00000000, 0x00000000, 0x00000000, 0x00000000 543 }, 544 { 545 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 546 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 547 0x00000000, 0x00000000, 0x00000000, 0x00000000 548 }, 549 { 550 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 551 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 552 0x00000000, 0x00000000, 0x00000000, 0x00000000 553 } 554 }, 555 556 /* DHT Marker */ 557 /* lum_dc_codelens */ 558 {0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0}, 559 /* lum_dc_ncodes */ 560 16, 561 /* lum_dc_symbols */ 562 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 563 /* lum_dc_nsymbols */ 564 12, 565 /* lum_ac_codelens */ 566 {0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d}, 567 /* lum_ac_ncodes */ 568 16, 569 /* lum_ac_symbols */ 570 { 571 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 572 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, 573 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08, 574 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0, 575 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16, 576 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28, 577 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 578 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 579 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 580 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 581 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 582 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 583 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 584 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 585 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 586 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 587 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 588 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2, 589 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 590 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 591 0xf9, 0xfa 592 }, 593 594 /* lum_ac_nsymbols */ 595 162, 596 /* chm_dc_codelens */ 597 {0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}, 598 /* chm_dc_ncodes */ 599 16, 600 /* chm_dc_symbols */ 601 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 602 /* chm_dc_nsymbols */ 603 12, 604 /* chm_ac_codelens */ 605 {0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77}, 606 /* chm_ac_ncodes */ 607 16, 608 /* chm_ac_symbols */ 609 { 610 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 611 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, 612 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, 613 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0, 614 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34, 615 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26, 616 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, 617 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 618 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 619 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 620 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 621 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 622 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 623 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 624 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 625 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 626 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 627 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 628 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 629 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 630 0xf9, 0xfa 631 }, 632 /* chm_ac_nsymbols */ 633 162 634 }; 635 636 637 typedef unsigned char uchar; 638 /** 639 * Pipe used to communicate back to the main thread from the component thread; 640 **/ 641 int IpBuf_Pipe[2]; 642 int OpBuf_Pipe[2]; 643 int Event_Pipe[2]; 644 645 /* the FLAG when we need to DeInit the OMX */ 646 int DEINIT_FLAG = 0; 647 648 /* Flag set when component is preempted */ 649 int bPreempted=0; 650 651 /* Hardware error flag */ 652 OMX_BOOL bError = OMX_FALSE; 653 654 /*function prototypes */ 655 inline int maxint(int a, int b); 656 OMX_ERRORTYPE SetMarkers(OMX_HANDLETYPE pHandle, IMAGE_INFO *imageinfo, OMX_CONFIG_RECTTYPE sCrop, int nWidth, int nHeight); 657 658 #ifdef DSP_MMU_FAULT_HANDLING 659 int LoadBaseImage(); 660 #endif 661 662 /*Routine to get the maximum of 2 integers */ 663 inline int maxint(int a, int b) 664 { 665 return(a>b) ? a : b; 666 } 667 668 669 /** 670 * This method will wait for the component or mixer to get to the correct 671 * state. It is not a real implementation, but just simulates what a real 672 * wait routine may do. 673 **/ 674 static OMX_ERRORTYPE WaitForState(OMX_HANDLETYPE* pHandle, 675 OMX_STATETYPE DesiredState) 676 { 677 OMX_STATETYPE CurState = OMX_StateInvalid; 678 OMX_ERRORTYPE eError = OMX_ErrorNone; 679 int nCnt = 0; 680 OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle; 681 682 PRINT("Inside Test Application WaitForState function\n"); 683 eError = pComponent->GetState(pHandle, &CurState); 684 while ( (eError == OMX_ErrorNone) && 685 (CurState != DesiredState)) { 686 sched_yield(); 687 /*sleep(1);*/ 688 if ( nCnt++ == 0xFFFFFFFE ) { 689 fprintf(stderr, "Press CTL-C to continue\n"); 690 } 691 692 eError = pComponent->GetState(pHandle, &CurState); 693 if (CurState == OMX_StateInvalid && DesiredState != OMX_StateInvalid) { 694 eError = OMX_ErrorInvalidState; 695 break; 696 } 697 } 698 699 if ( eError != OMX_ErrorNone ) { 700 PRINT("Error: Couldn't get state for component or sent to invalid state because of an error.\n"); 701 return eError; 702 } 703 return OMX_ErrorNone; 704 } 705 706 OMX_ERRORTYPE EventHandler(OMX_HANDLETYPE hComponent,OMX_PTR pAppData,OMX_EVENTTYPE eEvent, 707 OMX_U32 nData1, OMX_U32 data2, OMX_PTR pEventData) 708 { 709 OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)hComponent; 710 OMX_STATETYPE state; 711 OMX_ERRORTYPE eError; 712 JPEGE_EVENTPRIVATE MyEvent; 713 714 MyEvent.eEvent = eEvent; 715 MyEvent.nData1 = nData1; 716 MyEvent.nData2 = data2; 717 MyEvent.pAppData = pAppData; 718 MyEvent.pEventInfo = pEventData; 719 PRINT("Inside Test Application EventHandler function\n"); 720 eError = pComponent->GetState (hComponent, &state); 721 722 if ( eError != OMX_ErrorNone ) { 723 PRINT("Error: From JPEGENC_GetState\n"); 724 } 725 switch ( eEvent ) { 726 727 case OMX_EventCmdComplete: 728 PRINT ("Component State Changed\n"); 729 break; 730 731 case OMX_EventError: 732 if (nData1 == OMX_ErrorHardware){ 733 printf("\n\nAPP:: ErrorNotification received: Error Num = %p Severity = %ld String = %s\n", (OMX_PTR)nData1, data2, (OMX_STRING)pEventData); 734 printf("\nAPP:: OMX_ErrorHardware. Deinitialization of the component....\n\n"); 735 if(!bError) { 736 bError = OMX_TRUE; 737 write(Event_Pipe[1], &MyEvent, sizeof(JPEGE_EVENTPRIVATE)); 738 } 739 } 740 else if(nData1 == OMX_ErrorResourcesPreempted) { 741 bPreempted = 1; 742 PRINT("APP:: OMX_ErrorResourcesPreempted !\n\n"); 743 } 744 else if(nData1 == OMX_ErrorInvalidState) { 745 printf("\n\nAPP:: ErrorNotification received: Error Num = %p Severity = %ld String = %s\n", (OMX_PTR)nData1, data2, (OMX_STRING)pEventData); 746 printf("\nAPP:: Invalid state\n\n"); 747 if(!bError) { 748 bError = OMX_TRUE; 749 write(Event_Pipe[1], &MyEvent, sizeof(JPEGE_EVENTPRIVATE)); 750 } 751 } 752 else if(nData1 == OMX_ErrorPortUnpopulated) { 753 printf("APP:: OMX_ErrorPortUnpopulated\n"); 754 bError = OMX_TRUE; 755 } 756 else if (nData1 == OMX_ErrorStreamCorrupt) { 757 printf("\n\nAPP:: ErrorNotification received: Error Num = %p Severity = %ld String = %s\n", (OMX_PTR)nData1, data2, (OMX_STRING)pEventData); 758 printf("%s: Stream Corrupt (%ld %s)\n",__FUNCTION__,data2,(char*)pEventData); 759 if(!bError) { 760 bError = OMX_TRUE; 761 write(Event_Pipe[1], &MyEvent, sizeof(JPEGE_EVENTPRIVATE)); 762 } 763 } 764 else { 765 bError = OMX_TRUE; 766 DEINIT_FLAG = 1; 767 } 768 769 break; 770 771 case OMX_EventResourcesAcquired: 772 bPreempted = 0; 773 break; 774 775 case OMX_EventPortSettingsChanged: 776 case OMX_EventBufferFlag: 777 PRINT("Event Buffer Flag detected\n"); 778 case OMX_EventMax: 779 case OMX_EventMark: 780 break; 781 782 default: 783 PRINT("ErrorNotification received: Error Num %p: String :%s\n", (OMX_PTR)nData1, (OMX_STRING)pEventData); 784 } 785 786 return OMX_ErrorNone; 787 } 788 789 790 void FillBufferDone (OMX_HANDLETYPE hComponent, OMX_PTR ptr, 791 OMX_BUFFERHEADERTYPE* pBuffHead) 792 { 793 PRINT("Inside Test Application FillBufferDone function\n"); 794 write(OpBuf_Pipe[1], &pBuffHead, sizeof(pBuffHead)); 795 } 796 797 798 void EmptyBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR ptr, 799 OMX_BUFFERHEADERTYPE* pBuffer) 800 { 801 PRINT("Inside Test Application EmptyBufferDone function\n"); 802 write(IpBuf_Pipe[1], &pBuffer, sizeof(pBuffer)); 803 } 804 805 #ifdef UNDER_CE 806 int fill_data (OMX_BUFFERHEADERTYPE *pBufferPrivate, HANDLE fIn, int buffSize) 807 #else 808 int fill_data (OMX_BUFFERHEADERTYPE *pBuf, FILE *fIn, int buffSize) 809 #endif 810 { 811 int nRead; 812 OMX_U8 oneByte; 813 PRINT("Inside Test Application fill_data function\n"); 814 815 #ifdef UNDER_CE 816 ReadFile(fIn, pBuf->pBuffer, lSize, &nRead, NULL); 817 #else 818 nRead = fread(pBuf->pBuffer,1, buffSize , fIn); 819 #endif 820 821 printf ("Buffer Size = %d. Read %d bytes from file. \n", (int) buffSize, (int)nRead); 822 pBuf->nFilledLen = nRead; 823 824 oneByte = fgetc(fIn); 825 if (feof(fIn)){ 826 pBuf->nFlags = OMX_BUFFERFLAG_ENDOFFRAME; 827 PRINT("Read full file...\n"); 828 rewind(fIn); 829 } 830 else{ 831 ungetc(oneByte, fIn); 832 } 833 834 return nRead; 835 } 836 837 OMX_ERRORTYPE SetMarkers(OMX_HANDLETYPE pHandle, IMAGE_INFO *imageinfo, OMX_CONFIG_RECTTYPE sCrop, int nWidth, int nHeight) { 838 839 OMX_ERRORTYPE eError = OMX_ErrorNone; 840 OMX_INDEXTYPE nCustomIndex = OMX_IndexMax; 841 842 /* Set APP0 Marker config (JFIF) */ 843 if (imageinfo->bAPP0) { 844 845 JPEG_APPTHUMB_MARKER sAPP0; 846 847 sAPP0.bMarkerEnabled = OMX_TRUE; 848 849 /* set JFIF marker buffer */ 850 sAPP0.nMarkerSize = sizeof(APPLICATION0); 851 sAPP0.pMarkerBuffer = APPLICATION0; 852 sAPP0.nThumbnailWidth = imageinfo->nThumbnailWidth_app0; 853 sAPP0.nThumbnailHeight = imageinfo->nThumbnailHeight_app0; 854 855 eError = OMX_GetExtensionIndex(pHandle, "OMX.TI.JPEG.encoder.Config.APP0", (OMX_INDEXTYPE*)&nCustomIndex); 856 if ( eError != OMX_ErrorNone ) { 857 printf("%d::APP_Error at function call: %x\n", __LINE__, eError); 858 eError = OMX_ErrorUndefined; 859 goto EXIT; 860 } 861 eError = OMX_SetConfig(pHandle, nCustomIndex, &sAPP0); 862 if ( eError != OMX_ErrorNone ) { 863 printf("%d::APP_Error at function call: %x\n", __LINE__, eError); 864 eError = OMX_ErrorUndefined; 865 goto EXIT; 866 } 867 868 } 869 870 /* Set APP1 Marker config (EXIF) */ 871 if (imageinfo->bAPP1) { 872 873 JPEG_APPTHUMB_MARKER sAPP1; 874 875 sAPP1.bMarkerEnabled = OMX_TRUE; 876 877 /* set JFIF marker buffer */ 878 sAPP1.nThumbnailWidth = imageinfo->nThumbnailWidth_app1; 879 sAPP1.nThumbnailHeight = imageinfo->nThumbnailHeight_app1; 880 881 /* if thumbnail is set, use APPLICATION structure with thumbnail */ 882 if(sAPP1.nThumbnailWidth > 0 && sAPP1.nThumbnailHeight > 0) { 883 sAPP1.nMarkerSize = sizeof(APPLICATION1_THUMB); 884 sAPP1.pMarkerBuffer = APPLICATION1_THUMB; 885 } 886 else { 887 sAPP1.nMarkerSize = sizeof(APPLICATION1_NOTHUMB); 888 sAPP1.pMarkerBuffer = APPLICATION1_NOTHUMB; 889 } 890 891 /*set crop */ 892 if (sCrop.nWidth != 0) 893 { 894 sAPP1.pMarkerBuffer[152] = sCrop.nWidth & 0xFF; 895 sAPP1.pMarkerBuffer[153] = (sCrop.nWidth >> 8) & 0xFF; 896 } 897 else 898 { 899 sAPP1.pMarkerBuffer[152] = nWidth & 0xFF; 900 sAPP1.pMarkerBuffer[153] = (nWidth >> 8) & 0xFF; 901 } 902 903 if (sCrop.nHeight != 0) 904 { 905 sAPP1.pMarkerBuffer[164] = sCrop.nHeight; 906 sAPP1.pMarkerBuffer[165] = (sCrop.nHeight >> 8) & 0xFF; 907 } 908 else 909 { 910 sAPP1.pMarkerBuffer[164] = nHeight; 911 sAPP1.pMarkerBuffer[165] = (nHeight >> 8) & 0xFF; 912 } 913 914 eError = OMX_GetExtensionIndex(pHandle, "OMX.TI.JPEG.encoder.Config.APP1", (OMX_INDEXTYPE*)&nCustomIndex); 915 if ( eError != OMX_ErrorNone ) { 916 printf("%d::APP_Error at function call: %x\n", __LINE__, eError); 917 eError = OMX_ErrorUndefined; 918 goto EXIT; 919 } 920 eError = OMX_SetConfig(pHandle, nCustomIndex, &sAPP1); 921 if ( eError != OMX_ErrorNone ) { 922 printf("%d::APP_Error at function call: %x\n", __LINE__, eError); 923 eError = OMX_ErrorUndefined; 924 goto EXIT; 925 } 926 } 927 928 /* Set APP5 Marker config */ 929 if (imageinfo->bAPP5) { 930 931 JPEG_APPTHUMB_MARKER sAPP5; 932 933 sAPP5.bMarkerEnabled = OMX_TRUE; 934 935 /* set JFIF marker buffer */ 936 sAPP5.nMarkerSize = sizeof(APPLICATION5); 937 sAPP5.pMarkerBuffer = APPLICATION5; 938 sAPP5.nThumbnailWidth = imageinfo->nThumbnailWidth_app5; 939 sAPP5.nThumbnailHeight = imageinfo->nThumbnailHeight_app5; 940 941 eError = OMX_GetExtensionIndex(pHandle, "OMX.TI.JPEG.encoder.Config.APP5", (OMX_INDEXTYPE*)&nCustomIndex); 942 if ( eError != OMX_ErrorNone ) { 943 printf("%d::APP_Error at function call: %x\n", __LINE__, eError); 944 eError = OMX_ErrorUndefined; 945 goto EXIT; 946 } 947 eError = OMX_SetConfig(pHandle, nCustomIndex, &sAPP5); 948 if ( eError != OMX_ErrorNone ) { 949 printf("%d::APP_Error at function call: %x\n", __LINE__, eError); 950 eError = OMX_ErrorUndefined; 951 goto EXIT; 952 } 953 954 } 955 956 /* Set APP13 Marker config */ 957 if (imageinfo->bAPP13) { 958 959 JPEG_APP13_MARKER sAPP13; 960 961 sAPP13.bMarkerEnabled = OMX_TRUE; 962 963 /* set JFIF marker buffer */ 964 sAPP13.nMarkerSize = sizeof(APPLICATION13); 965 sAPP13.pMarkerBuffer = APPLICATION13; 966 967 eError = OMX_GetExtensionIndex(pHandle, "OMX.TI.JPEG.encoder.Config.APP13", (OMX_INDEXTYPE*)&nCustomIndex); 968 if ( eError != OMX_ErrorNone ) { 969 printf("%d::APP_Error at function call: %x\n", __LINE__, eError); 970 eError = OMX_ErrorUndefined; 971 goto EXIT; 972 } 973 eError = OMX_SetConfig(pHandle, nCustomIndex, &sAPP13); 974 if ( eError != OMX_ErrorNone ) { 975 printf("%d::APP_Error at function call: %x\n", __LINE__, eError); 976 eError = OMX_ErrorUndefined; 977 goto EXIT; 978 } 979 } 980 981 /* set comment marker */ 982 if (imageinfo->nComment) { 983 eError = OMX_GetExtensionIndex(pHandle, "OMX.TI.JPEG.encoder.Config.CommentFlag", (OMX_INDEXTYPE*)&nCustomIndex); 984 if ( eError != OMX_ErrorNone ) { 985 printf("%d::APP_Error at function call: %x\n", __LINE__, eError); 986 eError = OMX_ErrorUndefined; 987 goto EXIT; 988 } 989 eError = OMX_SetConfig(pHandle, nCustomIndex, &(imageinfo->nComment)); 990 if ( eError != OMX_ErrorNone ) { 991 printf("%d::APP_Error at function call: %x\n", __LINE__, eError); 992 eError = OMX_ErrorUndefined; 993 goto EXIT; 994 } 995 996 eError = OMX_GetExtensionIndex(pHandle, "OMX.TI.JPEG.encoder.Config.CommentString", (OMX_INDEXTYPE*)&nCustomIndex); 997 if ( eError != OMX_ErrorNone ) { 998 printf("%d::APP_Error at function call: %x\n", __LINE__, eError); 999 eError = OMX_ErrorUndefined; 1000 goto EXIT; 1001 } 1002 eError = OMX_SetConfig(pHandle, nCustomIndex, imageinfo->pCommentString); 1003 if ( eError != OMX_ErrorNone ) { 1004 printf("%d::APP_Error at function call: %x\n", __LINE__, eError); 1005 eError = OMX_ErrorUndefined; 1006 goto EXIT; 1007 } 1008 } 1009 1010 EXIT: 1011 return eError; 1012 } 1013 1014 void PrintUsage(void) 1015 { 1016 printf("\ni.. Input File\n"); 1017 printf("o.. Output File\n"); 1018 printf("w.. Width Of Image\n"); 1019 printf("h.. Height Of Image\n"); 1020 printf("f.. Input Of Image:\n 1.- YUV 420 Planer\n 2.- YUV 422 Interleaved UYVY\n 3.- 32 bit RAW (RGB32)\n 4.- 16 bit RAW (RGB16)\n 5.- YUV 422 Interleaved YUYV\n"); 1021 printf("z.. 420p to 422i conversion before encode \n"); 1022 printf("q.. Quality Factor Of Image: 1 to 100\n"); 1023 printf("b.. Exit Buffer: 1 o 2\n"); 1024 printf("c.. Marker Comment: The comment string length should be less than 255 characters\n"); 1025 printf("j.. Marker APP0: Contain Information about JFIF\n"); 1026 printf("e.. Marker APP1: Contain Information about EXIF\n"); 1027 printf("d.. Marker APP5: Contain Miscellaneous Information\n"); 1028 printf("m.. Marker APP13: Contain Miscellaneous Information\n"); 1029 printf("x.. Width of Thumbnail of EXIF (default set to 88)\n"); 1030 printf("y.. Height of Thumbnail of EXIF (default set to 72)\n"); 1031 printf("s.. Width of Thumbnail of JFIF (default set to 88)\n"); 1032 printf("k.. Height of Thumbnail of JFIF (default set to 72)\n"); 1033 printf("n.. Width of Thumbnail of APP5 (default set to 88)\n"); 1034 printf("p.. Height of Thumbnail of APP5 (default set to 72)\n"); 1035 printf("t.. Type of Quantization Table \n\t 0.-Default Quantization Tables \n\t 1.-Custom Luma And Choma Tables\n"); 1036 printf("u.. Type of Huffman Table \n\t 0.-Default Huffman Table \n\t 1.-Custom Huffman Table\n"); 1037 printf("r.. No. of times to repeat\n"); 1038 printf("v.. Crop width value\n"); 1039 printf("l.. Crop height value\n"); 1040 1041 printf("\na.. Prints this information\n"); 1042 printf("\nExample: ./JPEGTestEnc_common -i patterns/JPGE_CONF_003.yuv -o output.jpg -w 176 -h 144 -f 2 -q 100 -b 1 -c JPEG -j -e -m -x 100 -y 100 -r 1\n\n"); 1043 } 1044 1045 1046 #ifdef UNDER_CE 1047 int _tmain(int argc, TCHAR **argv) 1048 #else 1049 int main(int argc, char** argv) 1050 #endif 1051 { 1052 1053 #ifndef UNDER_CE 1054 //mtrace(); 1055 #endif 1056 OMX_HANDLETYPE pHandle; 1057 OMX_U32 AppData = 100; 1058 1059 OMX_CALLBACKTYPE JPEGCaBa = {(void *)EventHandler, 1060 (void*) EmptyBufferDone, 1061 (void*)FillBufferDone}; 1062 int retval; 1063 int nWidth; 1064 int nHeight; 1065 int framesent = 0; 1066 int nRepeated = 0; 1067 int maxRepeat = 1; 1068 int inputformat; 1069 int qualityfactor; 1070 int buffertype; 1071 int bSetCustomHuffmanTable=0; 1072 int bSetCustomQuatizationTable=0; 1073 sigset_t set; 1074 1075 OMX_STATETYPE state; 1076 OMX_COMPONENTTYPE *pComponent; 1077 IMAGE_INFO* imageinfo = NULL; 1078 OMX_PORT_PARAM_TYPE* pPortParamType = NULL; 1079 OMX_IMAGE_PARAM_QFACTORTYPE* pQfactorType = NULL; 1080 JPEGENC_CUSTOM_HUFFMANTTABLETYPE *pHuffmanTable = NULL; 1081 OMX_IMAGE_PARAM_QUANTIZATIONTABLETYPE *pQuantizationTable = NULL; 1082 OMX_PARAM_PORTDEFINITIONTYPE* pInPortDef = NULL; 1083 OMX_PARAM_PORTDEFINITIONTYPE* pOutPortDef = NULL; 1084 OMX_CONFIG_RECTTYPE sCrop; 1085 1086 OMX_BOOL bConvertion_420pTo422i = OMX_FALSE; 1087 1088 #ifdef UNDER_CE 1089 TCHAR* szInFile = NULL; 1090 TCHAR* szOutFile = NULL; 1091 HANDLE fIn = NULL; 1092 HANDLE fOut = NULL; 1093 DWORD dwWritten; 1094 #else 1095 char* szInFile = NULL; 1096 char* szOutFile = NULL; 1097 1098 FILE* fIn = NULL; 1099 FILE* fOut = NULL; 1100 #endif 1101 1102 OMX_BUFFERHEADERTYPE* pInBuff[NUM_OF_BUFFERSJPEG]; 1103 OMX_BUFFERHEADERTYPE* pOutBuff[NUM_OF_BUFFERSJPEG]; 1104 int nCounter = 0; 1105 int fdmax; 1106 OMX_U8* pTemp; 1107 OMX_U8* pInBuffer[NUM_OF_BUFFERSJPEG]; 1108 OMX_U8* pOutBuffer[NUM_OF_BUFFERSJPEG]; 1109 OMX_BUFFERHEADERTYPE* pBuffer; 1110 OMX_BUFFERHEADERTYPE* pBuf; 1111 int nRead; 1112 int done; 1113 OMX_S32 sJPEGEnc_CompID = 300; 1114 int nIndex1= 0; 1115 int nIndex2 = 0; 1116 int nframerecieved = 0; 1117 int nMultFactor = 0; 1118 int nHeightNew, nWidthNew; 1119 OMX_INDEXTYPE nCustomIndex = OMX_IndexMax; 1120 OMX_ERRORTYPE error = OMX_ErrorNone; 1121 1122 #ifdef STRESS 1123 int multiload = 0; 1124 #endif 1125 1126 int next_option; 1127 const char* const short_options = "i:o:w:h:f:q:b:c:x:y:s:k:t:u:r:v:l:n:p:ajemdvlz"; 1128 const struct option long_options[] = 1129 { 1130 { "InputFile",1, NULL, 'i' }, 1131 { "OutputFile",1, NULL, 'o' }, 1132 { "WidthImage",1, NULL, 'w' }, 1133 { "HeightImage",1, NULL, 'h' }, 1134 { "inputFormat",1, NULL, 'f' }, 1135 { "QualityFactor",1, NULL, 'q' }, 1136 { "Ext/IntBuffer",1, NULL, 'b' }, 1137 { "MarkerComment",1, NULL, 'c' }, 1138 { "EXIFwidthThumbnail",1, NULL, 'x' }, 1139 { "EXIFheightThumbnail",1, NULL, 'y' }, 1140 { "JFIFwidthThumbnail",1, NULL, 's' }, 1141 { "JFIFheightThumbnail",1, NULL, 'k' }, 1142 { "APP5heightThumbnail",1, NULL, 'p' }, 1143 { "APP5widthThumbnail",1, NULL, 'n' }, 1144 { "Repetition",1, NULL, 'r' }, 1145 {"QuantizationTable",1,NULL,'t'}, 1146 {"HuffmanTable",1,NULL,'u'}, 1147 { "help", 0, NULL, 'a' }, 1148 { "MarkerAPP0",0,NULL,'j'}, 1149 { "MarkerAPP1",0,NULL,'e'}, 1150 { "MarkerAPP13",0,NULL,'m'}, 1151 { "MarkerAPP5",0,NULL,'d'}, 1152 { "CroppedWidth",0,NULL,'v'}, 1153 { "CroppedHeight",0,NULL,'l'}, 1154 { "420pTo422iConversion",0,NULL,'z'}, 1155 { NULL, 0, NULL, 0 } 1156 }; 1157 1158 MALLOC(pPortParamType, OMX_PORT_PARAM_TYPE); 1159 MALLOC(pQfactorType, OMX_IMAGE_PARAM_QFACTORTYPE); 1160 MALLOC(pQuantizationTable,OMX_IMAGE_PARAM_QUANTIZATIONTABLETYPE); 1161 MALLOC(pHuffmanTable, JPEGENC_CUSTOM_HUFFMANTTABLETYPE); 1162 MALLOC(pInPortDef, OMX_PARAM_PORTDEFINITIONTYPE); 1163 MALLOC(pOutPortDef, OMX_PARAM_PORTDEFINITIONTYPE); 1164 MALLOC(imageinfo, IMAGE_INFO); 1165 1166 /* Setting up default parameters */ 1167 szOutFile="output.jpg"; 1168 nWidth=176; 1169 nHeight=144; 1170 inputformat=1; 1171 qualityfactor=100; 1172 buffertype=1; 1173 1174 imageinfo->nThumbnailWidth_app0 = 0; 1175 imageinfo->nThumbnailHeight_app0 = 0; 1176 imageinfo->nThumbnailWidth_app1 = 0; 1177 imageinfo->nThumbnailHeight_app1 = 0; 1178 imageinfo->nThumbnailWidth_app5 = 0; 1179 imageinfo->nThumbnailHeight_app5 = 0; 1180 imageinfo->nThumbnailWidth_app13 = 0; 1181 imageinfo->nThumbnailHeight_app13 = 0; 1182 1183 imageinfo->bAPP0 = OMX_FALSE; 1184 imageinfo->bAPP1 = OMX_FALSE; 1185 imageinfo->bAPP5 = OMX_FALSE; 1186 imageinfo->bAPP13 = OMX_FALSE; 1187 imageinfo->nComment = OMX_FALSE; 1188 imageinfo->pCommentString = NULL; 1189 1190 sCrop.nTop = 0; 1191 sCrop.nLeft = 0; 1192 sCrop.nWidth = 0; 1193 sCrop.nHeight = 0; 1194 1195 if (argc <= 1) 1196 { 1197 PrintUsage(); 1198 return 0; 1199 } 1200 1201 do 1202 { 1203 next_option = getopt_long(argc, argv, short_options,long_options, NULL); 1204 switch(next_option) 1205 { 1206 case 'a': 1207 PrintUsage(); 1208 return 0; 1209 break; 1210 1211 case 'i': 1212 szInFile=optarg; 1213 break; 1214 1215 case 'o': 1216 szOutFile=optarg; 1217 break; 1218 1219 case 'w': 1220 nWidth = atoi(optarg); 1221 break; 1222 1223 case 'h': 1224 nHeight=atoi(optarg); 1225 break; 1226 1227 case 'f': 1228 inputformat=atoi(optarg); 1229 break; 1230 1231 case 'z': 1232 bConvertion_420pTo422i = OMX_TRUE; 1233 PRINT("\n ********* bConvertion_420pTo422i is set to TRUE \n"); 1234 break; 1235 1236 case 'q': 1237 qualityfactor=atoi(optarg); 1238 break; 1239 1240 case 'b': 1241 buffertype=atoi(optarg); 1242 break; 1243 1244 case 'c': 1245 imageinfo->nComment = 1; 1246 imageinfo->pCommentString = (char *)optarg; 1247 break; 1248 1249 /*EXIF */ 1250 1251 case 'e': 1252 imageinfo->bAPP1 = OMX_TRUE; 1253 break; 1254 1255 case 'x': 1256 imageinfo->nThumbnailWidth_app1 = atoi(optarg); 1257 break; 1258 1259 case 'y': 1260 imageinfo->nThumbnailHeight_app1 = atoi(optarg); 1261 break; 1262 1263 /* JFIF */ 1264 case 'j': 1265 imageinfo->bAPP0 = OMX_TRUE; 1266 break; 1267 1268 case 's': 1269 imageinfo->nThumbnailWidth_app0 = atoi(optarg); 1270 break; 1271 1272 case 'k': 1273 imageinfo->nThumbnailHeight_app0 = atoi(optarg); 1274 break; 1275 1276 1277 case 'n': 1278 imageinfo->nThumbnailWidth_app5 = atoi(optarg); 1279 break; 1280 1281 case 'p': 1282 imageinfo->nThumbnailHeight_app5 = atoi(optarg); 1283 break; 1284 1285 case 'm': 1286 imageinfo->bAPP13 = OMX_TRUE; 1287 break; 1288 1289 case 'd': 1290 imageinfo->bAPP5 = OMX_TRUE; 1291 break; 1292 1293 case 't': 1294 bSetCustomQuatizationTable=atoi(optarg); 1295 break; 1296 1297 case 'u': 1298 bSetCustomHuffmanTable=atoi(optarg); 1299 break; 1300 1301 case 'r': 1302 maxRepeat = atoi(optarg); 1303 break; 1304 1305 case 'v': 1306 sCrop.nWidth = atoi(optarg); 1307 break; 1308 1309 case 'l': 1310 sCrop.nHeight = atoi(optarg); 1311 break; 1312 1313 } 1314 }while (next_option != -1); 1315 1316 printf("\n------------------------------------------------\n"); 1317 printf("OMX JPEG Encoder Test App built on " __DATE__ ":" __TIME__ "\n"); 1318 printf("------------------------------------------------\n"); 1319 printf("Output File Name is %s \n" , szOutFile); 1320 1321 #ifdef STRESS 1322 1323 for (multiload = 0; multiload < STRESSMULTILOAD; multiload ++) { 1324 printf("Stress Test: Iteration %d\n", multiload + 1); 1325 #endif 1326 1327 1328 #ifdef DSP_MMU_FAULT_HANDLING 1329 /* LOAD BASE IMAGE FIRST TIME */ 1330 LoadBaseImage(); 1331 #endif 1332 1333 error = TIOMX_Init(); 1334 if ( error != OMX_ErrorNone ) { 1335 PRINT("Error returned by OMX_Init()\n"); 1336 goto EXIT; 1337 } 1338 1339 printf("OMX_Init Successful!\n"); 1340 1341 error = TIOMX_GetHandle(&pHandle,StrJpegEncoder,(void *)&AppData, &JPEGCaBa); 1342 if ( (error != OMX_ErrorNone) || (pHandle == NULL) ) { 1343 fprintf (stderr,"Error in Get Handle function\n"); 1344 goto EXIT; 1345 } 1346 1347 #ifdef STRESS 1348 OMX_U8 i; 1349 for(i=0; i < NSTRESSCASES; i++) { 1350 printf("Stress test number %d\n",i); 1351 #endif 1352 1353 /* Create a pipe used to queue data from the callback. */ 1354 retval = pipe(IpBuf_Pipe); 1355 if ( retval != 0 ) { 1356 fprintf(stderr, "Error:Fill Data Pipe failed to open\n"); 1357 goto EXIT; 1358 } 1359 1360 retval = pipe(OpBuf_Pipe); 1361 if ( retval != 0 ) { 1362 fprintf(stderr, "Error:Empty Data Pipe failed to open\n"); 1363 goto EXIT; 1364 } 1365 1366 retval = pipe(Event_Pipe); 1367 if ( retval != 0 ) { 1368 fprintf(stderr, "Error:Empty Data Pipe failed to open\n"); 1369 goto EXIT; 1370 } 1371 1372 PRINT("Input/Output Pipes created\n"); 1373 1374 /* save off the "max" of the handles for the selct statement */ 1375 fdmax = maxint(IpBuf_Pipe[0], OpBuf_Pipe[0]); 1376 fdmax = maxint(Event_Pipe[0], fdmax); 1377 1378 #ifdef UNDER_CE 1379 fIn = CreateFile(szInFile, GENERIC_READ, 0, 1380 NULL,OPEN_EXISTING, 0, NULL); 1381 if (INVALID_HANDLE_VALUE == fIn) 1382 { 1383 PRINT("Error: failed to open the file %s for " \ 1384 "reading\n", szInFile); 1385 goto EXIT; 1386 } 1387 #else 1388 fIn = fopen(szInFile, "r"); 1389 if ( fIn == NULL ) { 1390 printf("Error: failed to open the file <%s> for reading\n", 1391 szInFile); 1392 goto EXIT; 1393 } 1394 PRINT(" File %s opened \n" , szInFile); 1395 #endif 1396 1397 1398 error = OMX_GetParameter(pHandle, OMX_IndexParamImageInit, pPortParamType); 1399 if ( error != OMX_ErrorNone ) { 1400 printf("%d::APP_Error at function call: %x\n", __LINE__, error); 1401 error = OMX_ErrorBadParameter; 1402 goto EXIT; 1403 } 1404 1405 nIndex1 = pPortParamType->nStartPortNumber; 1406 nIndex2 = nIndex1 + 1; 1407 pInPortDef->nPortIndex = nIndex1; 1408 error = OMX_GetParameter (pHandle, OMX_IndexParamPortDefinition, pInPortDef); 1409 if ( error != OMX_ErrorNone ) { 1410 printf("%d::APP_Error at function call: %x\n", __LINE__, error); 1411 error = OMX_ErrorBadParameter; 1412 goto EXIT; 1413 } 1414 1415 if (pInPortDef->eDir == nIndex1 ) { 1416 pInPortDef->nPortIndex = nIndex1; 1417 } 1418 else { 1419 pInPortDef->nPortIndex = nIndex2; 1420 } 1421 1422 /* Set the component's OMX_PARAM_PORTDEFINITIONTYPE structure (input) */ 1423 pInPortDef->nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE); 1424 pInPortDef->nVersion.s.nVersionMajor = 0x1; 1425 pInPortDef->nVersion.s.nVersionMinor = 0x0; 1426 pInPortDef->nVersion.s.nRevision = 0x0; 1427 pInPortDef->nVersion.s.nStep = 0x0; 1428 pInPortDef->nPortIndex = 0x0; 1429 pInPortDef->eDir = OMX_DirInput; 1430 pInPortDef->nBufferCountActual = NUM_OF_BUFFERSJPEG; 1431 pInPortDef->nBufferCountMin = 1; 1432 pInPortDef->bEnabled = OMX_TRUE; 1433 pInPortDef->bPopulated = OMX_FALSE; 1434 pInPortDef->eDomain = OMX_PortDomainImage; 1435 1436 /* OMX_IMAGE_PORTDEFINITION values for input port */ 1437 pInPortDef->format.image.cMIMEType = "JPEGENC"; 1438 pInPortDef->format.image.pNativeRender = NULL; 1439 pInPortDef->format.image.nFrameWidth = nWidth; 1440 pInPortDef->format.image.nFrameHeight = nHeight; 1441 pInPortDef->format.image.nSliceHeight = -1; 1442 pInPortDef->format.image.bFlagErrorConcealment = OMX_FALSE; 1443 1444 if ( inputformat == 2) { 1445 pInPortDef->format.image.eColorFormat = OMX_COLOR_FormatCbYCrY; 1446 } 1447 else if ( inputformat == 3) { 1448 pInPortDef->format.image.eColorFormat = OMX_COLOR_Format32bitARGB8888; 1449 } 1450 else if (inputformat == 4) { 1451 pInPortDef->format.image.eColorFormat = OMX_COLOR_Format16bitRGB565; 1452 } 1453 else if ( inputformat == 5) { 1454 pInPortDef->format.image.eColorFormat = OMX_COLOR_FormatYCbYCr; 1455 } 1456 else { 1457 pInPortDef->format.image.eColorFormat = OMX_COLOR_FormatYUV420PackedPlanar; 1458 } 1459 1460 pInPortDef->format.image.eCompressionFormat = OMX_IMAGE_CodingUnused; 1461 1462 nMultFactor = (nWidth + 16 - 1)/16; 1463 nWidthNew = (int)(nMultFactor) * 16; 1464 1465 nMultFactor = (nHeight + 16 - 1)/16; 1466 nHeightNew = (int)(nMultFactor) * 16; 1467 1468 if (inputformat == 1) { 1469 pInPortDef->nBufferSize = (nWidthNew * nHeightNew * 1.5); 1470 if (pInPortDef->nBufferSize < 1600) { 1471 pInPortDef->nBufferSize = 1600; 1472 } 1473 } 1474 else if(inputformat == 3) { 1475 pInPortDef->nBufferSize = (nWidthNew * nHeightNew * 4); 1476 } 1477 else { 1478 pInPortDef->nBufferSize = (nWidthNew * nHeightNew * 2); 1479 if (pInPortDef->nBufferSize < 400) { 1480 pInPortDef->nBufferSize = 400; 1481 } 1482 } 1483 1484 1485 error = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pInPortDef); 1486 if ( error != OMX_ErrorNone ) { 1487 printf("%d::APP_Error at function call: %x\n", __LINE__, error); 1488 error = OMX_ErrorBadParameter; 1489 goto EXIT; 1490 } 1491 1492 pOutPortDef->nPortIndex = nIndex2; 1493 error = OMX_GetParameter(pHandle, OMX_IndexParamPortDefinition, pOutPortDef); 1494 if ( error != OMX_ErrorNone ) { 1495 printf("%d::APP_Error at function call: %x\n", __LINE__, error); 1496 error = OMX_ErrorBadParameter; 1497 goto EXIT; 1498 } 1499 if (pOutPortDef->eDir == nIndex1 ) { 1500 pOutPortDef->nPortIndex = nIndex1; 1501 } 1502 else { 1503 pOutPortDef->nPortIndex = nIndex2; 1504 } 1505 /* Set the component's OMX_PARAM_PORTDEFINITIONTYPE structure (input) */ 1506 1507 pOutPortDef->nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE); 1508 pOutPortDef->nVersion.s.nVersionMajor = 0x1; 1509 pOutPortDef->nVersion.s.nVersionMinor = 0x0; 1510 pOutPortDef->nVersion.s.nRevision = 0x0; 1511 pOutPortDef->nVersion.s.nStep = 0x0; 1512 pOutPortDef->nPortIndex = 0x1; 1513 pOutPortDef->eDir = OMX_DirInput; 1514 pOutPortDef->nBufferCountActual = NUM_OF_BUFFERSJPEG; 1515 pOutPortDef->nBufferCountMin = 1; 1516 pOutPortDef->bEnabled = OMX_TRUE; 1517 pOutPortDef->bPopulated = OMX_FALSE; 1518 pOutPortDef->eDomain = OMX_PortDomainImage; 1519 1520 /* OMX_IMAGE_PORTDEFINITION values for input port */ 1521 pOutPortDef->format.image.cMIMEType = "JPEGENC"; 1522 pOutPortDef->format.image.pNativeRender = NULL; 1523 pOutPortDef->format.image.nFrameWidth = nWidth; 1524 pOutPortDef->format.image.nFrameHeight = nHeight; 1525 pOutPortDef->format.image.nStride = -1; 1526 pOutPortDef->format.image.nSliceHeight = -1; 1527 pOutPortDef->format.image.bFlagErrorConcealment = OMX_FALSE; 1528 1529 /*Minimum buffer size requirement */ 1530 pOutPortDef->nBufferSize = (nWidth*nHeight); 1531 if( qualityfactor < 10){ 1532 pOutPortDef->nBufferSize /=10; 1533 } 1534 else if (qualityfactor <100){ 1535 pOutPortDef->nBufferSize /= (100/qualityfactor); 1536 } 1537 1538 /*Adding memory to include Thumbnail, comments & markers information and header (depends on the app)*/ 1539 pOutPortDef->nBufferSize += 12288; 1540 1541 1542 if ( inputformat == 2 || inputformat == 3 || inputformat == 4 ) { 1543 pOutPortDef->format.image.eColorFormat = OMX_COLOR_FormatCbYCrY; 1544 } 1545 else if ( inputformat == 1 && bConvertion_420pTo422i ) { 1546 pOutPortDef->format.image.eColorFormat = OMX_COLOR_FormatCbYCrY; 1547 } 1548 else { 1549 pOutPortDef->format.image.eColorFormat = OMX_COLOR_FormatYUV420PackedPlanar; 1550 } 1551 1552 if (imageinfo->bAPP1) { 1553 pOutPortDef->format.image.eCompressionFormat = OMX_IMAGE_CodingEXIF; 1554 } 1555 else { 1556 pOutPortDef->format.image.eCompressionFormat = OMX_IMAGE_CodingJPEG; 1557 } 1558 1559 error = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pOutPortDef); 1560 if ( error != OMX_ErrorNone ) { 1561 printf("%d::APP_Error at function call: %x\n", __LINE__, error); 1562 error = OMX_ErrorBadParameter; 1563 goto EXIT; 1564 } 1565 1566 pComponent = (OMX_COMPONENTTYPE *)pHandle; 1567 1568 error = OMX_SetConfig(pHandle, OMX_IndexConfigCommonInputCrop, &sCrop); 1569 if ( error != OMX_ErrorNone ) { 1570 printf("%d::APP_Error at function call: %x\n", __LINE__, error); 1571 error = OMX_ErrorBadParameter; 1572 goto EXIT; 1573 } 1574 1575 error = OMX_SetConfig(pHandle, OMX_IndexCustomColorFormatConvertion_420pTo422i, &bConvertion_420pTo422i); 1576 if ( error != OMX_ErrorNone ) { 1577 printf("%d::APP_Error at function call: %x\n", __LINE__, error); 1578 error = OMX_ErrorBadParameter; 1579 goto EXIT; 1580 } 1581 1582 if (bSetCustomQuatizationTable){ 1583 1584 pQuantizationTable->eQuantizationTable = OMX_IMAGE_QuantizationTableLuma; 1585 error = OMX_GetParameter(pHandle, OMX_IndexParamQuantizationTable, pQuantizationTable); 1586 if ( error != OMX_ErrorNone ) { 1587 printf("%d::APP_Error at function call: %x\n", __LINE__, error); 1588 error = OMX_ErrorBadParameter; 1589 goto EXIT; 1590 } 1591 1592 pTemp = (OMX_U8*)memcpy(pQuantizationTable->nQuantizationMatrix, CustomLumaQuantizationTable, sizeof(CustomLumaQuantizationTable)); 1593 if(pTemp == NULL){ 1594 printf("%d::APP_Error at function call\n", __LINE__); 1595 error = OMX_ErrorUndefined; 1596 goto EXIT; 1597 } 1598 1599 error = OMX_SetParameter(pHandle, OMX_IndexParamQuantizationTable, pQuantizationTable); 1600 if ( error != OMX_ErrorNone ) { 1601 printf("%d::APP_Error at function call: %x\n", __LINE__, error); 1602 error = OMX_ErrorBadParameter; 1603 goto EXIT; 1604 } 1605 1606 pQuantizationTable->eQuantizationTable = OMX_IMAGE_QuantizationTableChroma; 1607 error = OMX_GetParameter(pHandle, OMX_IndexParamQuantizationTable, pQuantizationTable); 1608 if ( error != OMX_ErrorNone ) { 1609 printf("%d::APP_Error at function call: %x\n", __LINE__, error); 1610 error = OMX_ErrorBadParameter; 1611 goto EXIT; 1612 } 1613 1614 pTemp = (OMX_U8*)memcpy(pQuantizationTable->nQuantizationMatrix, CustomChromaQuantizationTable, sizeof(CustomChromaQuantizationTable)); 1615 if(pTemp == NULL){ 1616 error = OMX_ErrorUndefined; 1617 goto EXIT; 1618 } 1619 1620 error = OMX_SetParameter(pHandle, OMX_IndexParamQuantizationTable, pQuantizationTable); 1621 if ( error != OMX_ErrorNone ) { 1622 printf("%d::APP_Error at function call: %x\n", __LINE__, error); 1623 error = OMX_ErrorBadParameter; 1624 goto EXIT; 1625 } 1626 } 1627 1628 if (bSetCustomHuffmanTable){ 1629 1630 error = OMX_GetExtensionIndex(pHandle, "OMX.TI.JPEG.encoder.Config.HuffmanTable", (OMX_INDEXTYPE*)&nCustomIndex); 1631 if ( error != OMX_ErrorNone ) { 1632 printf("%d::APP_Error at function call: %x\n", __LINE__, error); 1633 error = OMX_ErrorBadParameter; 1634 goto EXIT; 1635 } 1636 1637 error = OMX_GetParameter(pHandle, nCustomIndex, pHuffmanTable); 1638 if ( error != OMX_ErrorNone ) { 1639 printf("%d::APP_Error at function call: %x\n", __LINE__, error); 1640 error = OMX_ErrorBadParameter; 1641 goto EXIT; 1642 } 1643 1644 pTemp = (OMX_U8*)memcpy(&(pHuffmanTable->sHuffmanTable), &CustomHuffmanTable, sizeof(CustomHuffmanTable)); 1645 if(pTemp == NULL){ 1646 error = OMX_ErrorUndefined; 1647 goto EXIT; 1648 } 1649 1650 error = OMX_SetParameter(pHandle, nCustomIndex, pHuffmanTable); 1651 if ( error != OMX_ErrorNone ) { 1652 printf("%d::APP_Error at function call: %x\n", __LINE__, error); 1653 error = OMX_ErrorBadParameter; 1654 goto EXIT; 1655 } 1656 } 1657 1658 1659 pComponent = (OMX_COMPONENTTYPE *)pHandle; 1660 error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateIdle ,NULL); 1661 if ( error != OMX_ErrorNone ) { 1662 fprintf (stderr,"Error from SendCommand-Idle(Init) State function\n"); 1663 goto EXIT; 1664 } 1665 1666 if (buffertype == 1) { 1667 1668 for (nCounter = 0; nCounter < NUM_OF_BUFFERSJPEG; nCounter++) { 1669 pTemp=(OMX_U8*)malloc(pInPortDef->nBufferSize+256); 1670 if(pTemp == NULL){ 1671 error = OMX_ErrorInsufficientResources; 1672 goto EXIT; 1673 } 1674 pTemp+= 128; 1675 pInBuffer[nCounter] = pTemp; 1676 pTemp = NULL; 1677 1678 pTemp= (OMX_U8*)malloc(pOutPortDef->nBufferSize+256); 1679 if(pTemp == NULL){ 1680 error = OMX_ErrorInsufficientResources; 1681 goto EXIT; 1682 } 1683 pTemp+= 128; 1684 pOutBuffer[nCounter] = pTemp; 1685 } 1686 1687 for (nCounter = 0; nCounter < NUM_OF_BUFFERSJPEG; nCounter++) { 1688 error = OMX_UseBuffer(pHandle, &pInBuff[nCounter], nIndex1, (void*)&sJPEGEnc_CompID, pInPortDef->nBufferSize,pInBuffer[nCounter]); 1689 } 1690 for (nCounter = 0; nCounter < NUM_OF_BUFFERSJPEG; nCounter++) { 1691 error = OMX_UseBuffer(pHandle, &pOutBuff[nCounter], nIndex2, (void*)&sJPEGEnc_CompID, pOutPortDef->nBufferSize,pOutBuffer[nCounter]); 1692 } 1693 } 1694 1695 if (buffertype == 2) { 1696 for (nCounter = 0; nCounter < NUM_OF_BUFFERSJPEG; nCounter++) { 1697 error = OMX_AllocateBuffer(pHandle, &pInBuff[nCounter], nIndex1, (void *)&sJPEGEnc_CompID, pInPortDef->nBufferSize); 1698 } 1699 for (nCounter = 0; nCounter < NUM_OF_BUFFERSJPEG; nCounter++) { 1700 error = OMX_AllocateBuffer(pHandle, &pOutBuff[nCounter], nIndex2, (void *)&sJPEGEnc_CompID, pOutPortDef->nBufferSize); 1701 } 1702 } 1703 1704 /* set markers */ 1705 error = SetMarkers(pHandle, imageinfo, sCrop, nWidth, nHeight); 1706 if ( error != OMX_ErrorNone ) { 1707 fprintf (stderr,"Error from SetMarkers() function\n"); 1708 goto EXIT; 1709 } 1710 1711 /** 1712 * wait for initialization to complete (as indicated by the statechange 1713 * callback saying that component has been loaded (and is therefore 1714 * initialized. Note that you should probably handle GUI events 1715 * in the WaitForState method. 1716 **/ 1717 1718 PRINT("Waiting for state Idle\n"); 1719 error = WaitForState(pHandle, OMX_StateIdle); 1720 if ( error != OMX_ErrorNone ) { 1721 PRINT("Error: JpegEncoder->WaitForState has timed out or failed %X\n", 1722 error); 1723 goto EXIT; 1724 } 1725 1726 pQfactorType->nSize = sizeof(OMX_IMAGE_PARAM_QFACTORTYPE); 1727 pQfactorType->nQFactor = (OMX_U32) qualityfactor; 1728 pQfactorType->nVersion.s.nVersionMajor = 0x1; 1729 pQfactorType->nVersion.s.nVersionMinor = 0x0; 1730 pQfactorType->nVersion.s.nRevision = 0x0; 1731 pQfactorType->nVersion.s.nStep = 0x0; 1732 pQfactorType->nPortIndex = 0x0; 1733 1734 error = OMX_GetExtensionIndex(pHandle, "OMX.TI.JPEG.encoder.Config.QFactor", (OMX_INDEXTYPE*)&nCustomIndex); 1735 if ( error != OMX_ErrorNone ) { 1736 printf("%d::APP_Error at function call: %x\n", __LINE__, error); 1737 goto EXIT; 1738 } 1739 error = OMX_SetConfig (pHandle, nCustomIndex, pQfactorType); 1740 if ( error != OMX_ErrorNone ) { 1741 printf("%d::APP_Error at function call: %x\n", __LINE__, error); 1742 goto EXIT; 1743 } 1744 1745 1746 /** 1747 * Open the file of data to be rendered. Since this is a just sample 1748 * application, the data is "rendered" to a test mixer. So, the test 1749 * file better contain data that can be printed to the terminal w/o 1750 * problems or you will not be a happy camper. 1751 **/ 1752 PRINT("Opening output jpg file\n"); 1753 #ifdef UNDER_CE 1754 fOut = CreateFile(szOutFile, GENERIC_WRITE, 0, 1755 NULL,CREATE_ALWAYS, 0, NULL); 1756 if (INVALID_HANDLE_VALUE == fOut){ 1757 PRINT("Error: failed to open the file <%s> for writing\n", 1758 szOutFile); 1759 goto EXIT; 1760 } 1761 #else 1762 fOut = fopen(szOutFile, "w"); 1763 if ( fOut == NULL ) { 1764 PRINT("Error: failed to open the file <%s> for writing\n", 1765 szOutFile); 1766 goto EXIT; 1767 } 1768 #endif 1769 1770 error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateExecuting, NULL); 1771 if ( error != OMX_ErrorNone ) { 1772 fprintf (stderr,"Error from SendCommand-Executing State function\n"); 1773 goto EXIT; 1774 } 1775 pComponent = (OMX_COMPONENTTYPE *)pHandle; 1776 1777 /** 1778 * wait for startup to complete (as indicated by the statechange 1779 * callback saying that component has been loaded (and is therefore 1780 * initialized. Note that you should probably handle GUI events 1781 * in the WaitForState method. 1782 **/ 1783 1784 PRINT("Waiting for OMX_StateExcecuting\n"); 1785 error = WaitForState(pHandle, OMX_StateExecuting); 1786 if ( error != OMX_ErrorNone ) { 1787 PRINT("Error: JpegEncoder->WaitForState has timed out or failed %X\n", error); 1788 goto EXIT; 1789 } 1790 1791 #if 0 1792 if (imageinfo->nDRI) { 1793 error = OMX_GetExtensionIndex(pHandle, "OMX.TI.JPEG.encoder.Config.DRI", (OMX_INDEXTYPE*)&nCustomIndex); 1794 if ( error != OMX_ErrorNone ) { 1795 printf("%d::APP_Error at function call: %x\n", __LINE__, error); 1796 goto EXIT; 1797 } 1798 error = OMX_SetConfig(pHandle, nCustomIndex, &(imageinfo->nDRI)); 1799 if ( error != OMX_ErrorNone ) { 1800 printf("%d::APP_Error at function call: %x\n", __LINE__, error); 1801 goto EXIT; 1802 } 1803 } 1804 #endif 1805 1806 /** Handle the component's requests for data until we run out of data. Do this 1807 * in a way that will allow the UI to continue to run (if there is a UI, which 1808 * this sample application does NOT have) 1809 **/ 1810 1811 done = 0; 1812 pComponent->GetState(pHandle, &state); 1813 PRINT("Error is %d , cur state is %d ",error, state); 1814 1815 1816 for (nCounter =0; nCounter<1 /*NUM_OF_BUFFERSJPEG*/; nCounter++) { 1817 nRead = fill_data(pInBuff[nCounter], fIn,pInPortDef->nBufferSize); 1818 pComponent->FillThisBuffer(pHandle, pOutBuff[nCounter]); 1819 pComponent->EmptyThisBuffer(pHandle, pInBuff[nCounter]); 1820 framesent++; 1821 PRINT("Sent Frame # %d\n", framesent); 1822 if (pInBuff[nCounter]->nFlags == OMX_BUFFERFLAG_ENDOFFRAME) 1823 break; 1824 } 1825 1826 while ((error == OMX_ErrorNone) && 1827 (state != OMX_StateIdle)) { 1828 1829 if (bPreempted) 1830 { 1831 PRINT("Preempted - Forced tp Idle State - Waiting for OMX_StateIdle\n"); 1832 error = WaitForState(pHandle, OMX_StateIdle); 1833 if ( error != OMX_ErrorNone ) { 1834 PRINT("Error: JpegEncoder->WaitForState has timed out or failed %X", error); 1835 goto EXIT; 1836 } 1837 break; 1838 } 1839 1840 fd_set rfds; 1841 sigemptyset(&set); 1842 sigaddset(&set,SIGALRM); 1843 1844 FD_ZERO(&rfds); 1845 FD_SET(IpBuf_Pipe[0], &rfds); 1846 FD_SET(OpBuf_Pipe[0], &rfds); 1847 FD_SET(Event_Pipe[0], &rfds); 1848 retval = pselect(fdmax+1, &rfds, NULL, NULL, NULL,&set); 1849 if ( retval == -1 ) { 1850 #ifndef UNDER_CE 1851 perror("select()"); 1852 #endif 1853 fprintf (stderr, " : Error \n"); 1854 break; 1855 } 1856 else if ( retval == 0 ) { 1857 PRINT("App Timeout !!!!!!!!!!!\n"); 1858 } 1859 1860 /** 1861 * If FD_ISSET for Event_Pipe, there is an event remaining on the pipe. Read it 1862 * and get act accordingly to the event. 1863 **/ 1864 if ( FD_ISSET(Event_Pipe[0], &rfds)) { 1865 1866 JPEGE_EVENTPRIVATE EventPrivate; 1867 read(Event_Pipe[0], &EventPrivate, sizeof(JPEGE_EVENTPRIVATE)); 1868 1869 switch(EventPrivate.eEvent) { 1870 case OMX_EventError: 1871 if(bError) { 1872 error = WaitForState(pHandle, OMX_StateInvalid); 1873 if (error != OMX_ErrorNone) { 1874 printf("APP:: Error: JpegEncoder->WaitForState has timed out or failed %X\n", error); 1875 goto EXIT; 1876 } 1877 printf("APP:: Component is in Invalid state now.\n"); 1878 goto EXIT; 1879 } 1880 break; 1881 1882 case OMX_EventBufferFlag: 1883 printf("APP:: EOS flag received\n"); 1884 break; 1885 1886 default: 1887 printf("APP:: Non-error event rised. Event -> 0x%x\n", EventPrivate.eEvent); 1888 break; 1889 } 1890 } 1891 1892 /** 1893 * If FD_ISSET for IpBuf_Pipe, then there is an empty buffer available on the pipe. Read it 1894 * from the pipe, then re-fill the buffer and send it back. 1895 **/ 1896 if ( FD_ISSET(IpBuf_Pipe[0], &rfds) && !DEINIT_FLAG ) { 1897 1898 /*read buffer */ 1899 read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer)); 1900 1901 /* re-fill this buffer with data from JPEG file */ 1902 nRead = fill_data(pBuffer, fIn,pInPortDef->nBufferSize); 1903 1904 /* call EmptyThisBuffer (send buffer back to component */ 1905 OMX_EmptyThisBuffer(pHandle, pBuffer); 1906 1907 /*increment count */ 1908 framesent++; 1909 PRINT("Sent Frame # %d\n", framesent); 1910 } 1911 1912 /** 1913 * If FD_ISSET for OpBuf_Pipe, then there is a filled buffer available on the pipe. Read it 1914 * and get the buffer data out, write it to a file and then re-empty the buffer and send 1915 * the buffer back to the component. 1916 **/ 1917 if (FD_ISSET(OpBuf_Pipe[0], &rfds)) { 1918 1919 /* read buffer */ 1920 read(OpBuf_Pipe[0], &pBuf, sizeof(pBuf)); 1921 1922 /* write data to a file, buffer is assumed to be emptied after this*/ 1923 #ifdef UNDER_CE 1924 WriteFile(fOut, pBuf->pBuffer, pBuf->nFilledLen, &dwWritten, NULL); 1925 #else 1926 printf("APP:: Write into file %lu bytes (%d)\n",pBuf->nFilledLen, nframerecieved); 1927 fwrite(pBuf->pBuffer, 1, (int)pBuf->nFilledLen, fOut); 1928 fflush(fOut); 1929 #endif 1930 /*increment count and validate for limits; call FillThisBuffer */ 1931 nframerecieved++; 1932 nRepeated++; 1933 PRINT("\n%d***************%d***************%d***************%d***************%d\n", nRepeated, nRepeated, nRepeated, nRepeated, nRepeated); 1934 if (nRepeated >= maxRepeat) { 1935 DEINIT_FLAG = 1; 1936 } 1937 else { 1938 PRINT("Sending another output buffer\n"); 1939 pComponent->FillThisBuffer(pHandle,pBuf); 1940 } 1941 } 1942 1943 if (DEINIT_FLAG == 1) { 1944 done = 1; 1945 pHandle = (OMX_HANDLETYPE *) pComponent; 1946 error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateIdle, NULL); 1947 if ( error != OMX_ErrorNone ) { 1948 fprintf (stderr,"APP:: Error from SendCommand-Idle(Stop) State function\n"); 1949 goto EXIT; 1950 } 1951 1952 PRINT("Waiting for OMX_StateIdle\n"); 1953 error = WaitForState(pHandle, OMX_StateIdle); 1954 if ( error != OMX_ErrorNone ) { 1955 PRINT("Error: JpegEncoder->WaitForState has timed out %X", error); 1956 goto EXIT; 1957 } 1958 1959 error = OMX_SendCommand(pHandle, OMX_CommandPortDisable, 0, NULL); 1960 if ( error != OMX_ErrorNone ) { 1961 PRINT("Error from SendCommand-PortDisable function\n"); 1962 goto EXIT; 1963 } 1964 } 1965 1966 if (done == 1) { 1967 error = pComponent->GetState(pHandle, &state); 1968 if ( error != OMX_ErrorNone ){ 1969 fprintf(stderr, "Warning: JpegEncoder->JPEGENC_GetState has returned status %X\n", error); 1970 goto EXIT; 1971 } 1972 PRINT("After GetState() in while loop.\n"); 1973 } 1974 } 1975 1976 1977 1978 1979 #ifdef STRESS 1980 } 1981 #endif 1982 1983 printf("\nTest Completed Successfully! Deinitializing ... \n\n"); 1984 1985 EXIT: 1986 1987 printf("\nClosing application...\n"); 1988 1989 /** 1990 * Freeing memory 1991 **/ 1992 1993 /*close handles */ 1994 #ifdef UNDER_CE 1995 CloseHandle(fOut); 1996 CloseHandle(fIn); 1997 #else 1998 fclose(fOut); 1999 rewind (fIn); 2000 fclose(fIn); 2001 #endif 2002 2003 PRINT("Freeing memory from test app\n"); 2004 FREE(pPortParamType); 2005 FREE(pQfactorType); 2006 FREE(pInPortDef); 2007 FREE(pOutPortDef); 2008 FREE(imageinfo); 2009 FREE(pQuantizationTable); 2010 FREE(pHuffmanTable); 2011 2012 if( error != OMX_ErrorNone){ 2013 if (buffertype == 1) { 2014 for (nCounter = 0; nCounter < NUM_OF_BUFFERSJPEG; nCounter++) { 2015 pOutBuffer[nCounter]-=128; 2016 pInBuffer[nCounter]-=128; 2017 FREE(pOutBuffer[nCounter]); 2018 FREE(pInBuffer[nCounter]); 2019 } 2020 } 2021 for (nCounter = 0; nCounter < NUM_OF_BUFFERSJPEG; nCounter++) { 2022 error = OMX_FreeBuffer(pHandle, nIndex1, pInBuff[nCounter]); 2023 if ( (error != OMX_ErrorNone) ) { 2024 printf ("Error in OMX_FreeBuffer: %d\n", __LINE__); 2025 } 2026 error = OMX_FreeBuffer(pHandle, nIndex2, pOutBuff[nCounter]); 2027 if ( (error != OMX_ErrorNone) ) { 2028 printf ("Error in OMX_FreeBuffer: %d\n", __LINE__); 2029 } 2030 } 2031 } 2032 2033 error = TIOMX_FreeHandle(pHandle); 2034 if ( (error != OMX_ErrorNone) ) { 2035 printf ("Error in Free Handle function\n"); 2036 } 2037 2038 #ifdef DSP_MMU_FAULT_HANDLING 2039 2040 if(bError) { 2041 LoadBaseImage(); 2042 } 2043 2044 #endif 2045 2046 error = TIOMX_Deinit(); 2047 if ( error != OMX_ErrorNone ) { 2048 printf("Error returned by OMX_DeInit()\n"); 2049 } 2050 2051 #ifdef STRESS 2052 2053 } /* end of multiload loop */ 2054 2055 #endif 2056 2057 #ifndef UNDER_CE 2058 //muntrace(); 2059 #endif 2060 PRINT ("Free Handle returned Successfully = %x\n",error); 2061 return error; 2062 } 2063 2064 #ifdef DSP_MMU_FAULT_HANDLING 2065 2066 int LoadBaseImage() { 2067 unsigned int uProcId = 0; /* default proc ID is 0. */ 2068 unsigned int index = 0; 2069 2070 struct DSP_PROCESSORINFO dspInfo; 2071 DSP_HPROCESSOR hProc; 2072 DSP_STATUS status = DSP_SOK; 2073 unsigned int numProcs; 2074 char* argv[2]; 2075 2076 argv[0] = "/lib/dsp/baseimage.dof"; 2077 2078 status = (DBAPI)DspManager_Open(0, NULL); 2079 if (DSP_FAILED(status)) { 2080 printf("DSPManager_Open failed \n"); 2081 return -1; 2082 } 2083 while (DSP_SUCCEEDED(DSPManager_EnumProcessorInfo(index,&dspInfo, 2084 (unsigned int)sizeof(struct DSP_PROCESSORINFO),&numProcs))) { 2085 if ((dspInfo.uProcessorType == DSPTYPE_55) || 2086 (dspInfo.uProcessorType == DSPTYPE_64)) { 2087 uProcId = index; 2088 status = DSP_SOK; 2089 break; 2090 } 2091 index++; 2092 } 2093 status = DSPProcessor_Attach(uProcId, NULL, &hProc); 2094 if (DSP_SUCCEEDED(status)) { 2095 status = DSPProcessor_Stop(hProc); 2096 if (DSP_SUCCEEDED(status)) { 2097 status = DSPProcessor_Load(hProc,1,(const char **)argv,NULL); 2098 if (DSP_SUCCEEDED(status)) { 2099 status = DSPProcessor_Start(hProc); 2100 if (DSP_SUCCEEDED(status)) { 2101 } 2102 else { 2103 } 2104 } 2105 else { 2106 } 2107 DSPProcessor_Detach(hProc); 2108 } 2109 else { 2110 } 2111 } 2112 else { 2113 } 2114 fprintf(stderr,"Baseimage Loaded\n"); 2115 2116 return 0; 2117 } 2118 #endif 2119