1 /******************************************************************************
2 *
3 * Copyright (C) 2015 The Android Open Source Project
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 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19 */
20
21 /**
22 *******************************************************************************
23 * @file
24 * main.c
25 *
26 * @brief
27 * sample test application
28 *
29 * @author
30 * ittiam
31 *
32 * @remarks
33 * none
34 *
35 *******************************************************************************
36 */
37
38 /*****************************************************************************/
39 /* File Includes */
40 /*****************************************************************************/
41
42 /* System include files */
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <stddef.h>
46 #include <assert.h>
47 #include <string.h>
48 #include <stdbool.h>
49
50 #ifdef WINDOWS_TIMER
51 #include "windows.h"
52 #else
53 #include <sys/time.h>
54 #endif
55
56 /* User include files */
57 #include "ih264_typedefs.h"
58 #include "iv2.h"
59 #include "ive2.h"
60 #include "ih264e.h"
61 #include "app.h"
62 #include "psnr.h"
63
64 /*****************************************************************************/
65 /* Enums */
66 /*****************************************************************************/
67 typedef enum
68 {
69 INVALID,
70 HELP,
71 INPUT_FILE,
72 OUTPUT_FILE,
73 RECON_FILE,
74 RECON_ENABLE,
75 CHKSUM_ENABLE,
76 CHKSUM_FILE,
77 INPUT_CHROMA_FORMAT,
78 RECON_CHROMA_FORMAT,
79 MAX_WD,
80 MAX_HT,
81 WD,
82 HT,
83 MAX_LEVEL,
84 ENC_SPEED,
85 ME_SPEED,
86 START_FRM,
87 NUM_FRMS,
88 MAX_FRAMERATE,
89 SRC_FRAMERATE,
90 TGT_FRAMERATE,
91 RC,
92 MAX_BITRATE,
93 BITRATE,
94 I_QP,
95 P_QP,
96 B_QP,
97 I_QP_MAX,
98 P_QP_MAX,
99 B_QP_MAX,
100 I_QP_MIN,
101 P_QP_MIN,
102 B_QP_MIN,
103 ENTROPY,
104 AIR,
105 AIR_REFRESH_PERIOD,
106 ARCH,
107 SOC,
108 NUMCORES,
109 PRE_ENC_ME,
110 PRE_ENC_IPE,
111 HPEL,
112 QPEL,
113 SRCH_RNG_X,
114 SRCH_RNG_Y,
115 I_INTERVAL,
116 IDR_INTERVAL,
117 CONSTRAINED_INTRA_PRED,
118 B_FRMS,
119 NUM_B_FRMS,
120 DISABLE_DBLK,
121 PROFILE,
122 FAST_SAD,
123 ALT_REF,
124 DISABLE_DEBLOCK_LEVEL,
125 PSNR,
126 SLICE_MODE,
127 SLICE_PARAM,
128 CONFIG,
129 LOOPBACK,
130 VBV_DELAY,
131 VBV_SIZE,
132 INTRA_4x4_ENABLE,
133 MB_INFO_FILE,
134 MB_INFO_TYPE,
135 PIC_INFO_FILE,
136 PIC_INFO_TYPE,
137 } ARGUMENT_T;
138
139 /*****************************************************************************/
140 /* Structure definitions */
141 /*****************************************************************************/
142
143 /**
144 **************************************************************************
145 * @brief argument mapping construct
146 **************************************************************************
147 */
148 typedef struct
149 {
150 CHAR argument_shortname[8];
151 CHAR argument_name[128];
152 ARGUMENT_T argument;
153 CHAR description[512];
154 } argument_t;
155
156 /*****************************************************************************/
157 /* Global definitions */
158 /*****************************************************************************/
159
160 /**
161 **************************************************************************
162 * @brief list of supported arguments
163 **************************************************************************
164 */
165 static const argument_t argument_mapping[] =
166 {
167 { "--", "--help", HELP, "Print this help\n" },
168 { "-i", "--input", INPUT_FILE, "Input file\n" },
169 { "-o", "--output", OUTPUT_FILE, "Output file\n" },
170 { "--", "--recon_enable", RECON_ENABLE, "Recon enable flag\n" },
171 { "-r", "--recon", RECON_FILE, "Recon file \n" },
172 { "--", "--input_chroma_format", INPUT_CHROMA_FORMAT,
173 "Input Chroma format Supported values YUV_420P, YUV_420SP_UV, YUV_420SP_VU\n" },
174 { "--", "--recon_chroma_format", RECON_CHROMA_FORMAT,
175 "Recon Chroma format Supported values YUV_420P, YUV_420SP_UV, YUV_420SP_VU\n" },
176 { "-w", "--width", WD, "Width of input file\n" },
177 { "-h", "--height", HT, "Height of input file\n" },
178 { "--", "--start_frame", START_FRM, "Starting frame number\n" },
179 { "-f", "--num_frames", NUM_FRMS, "Number of frames to be encoded\n" },
180 { "--", "--rc", RC, "Rate control mode 0: Constant Qp, 1: Storage, 2: CBR non low delay \n" },
181 { "--", "--max_framerate", MAX_FRAMERATE, "Maximum frame rate \n" },
182 { "--", "--tgt_framerate", TGT_FRAMERATE, "Target frame rate \n" },
183 { "--", "--src_framerate", SRC_FRAMERATE, "Source frame rate \n" },
184 { "--", "--i_interval", I_INTERVAL, "Intra frame interval \n" },
185 { "--", "--idr_interval", IDR_INTERVAL, "IDR frame interval \n" },
186 { "--", "--constrained_intrapred", CONSTRAINED_INTRA_PRED, "Constrained IntraPrediction Flag \n" },
187 { "--", "--bframes", NUM_B_FRMS, "Maximum number of consecutive B frames \n" },
188 { "--", "--speed", ENC_SPEED, "Encoder speed preset 0 (slowest) and 100 (fastest)\n" },
189 { "--", "--me_speed", ME_SPEED, "Encoder speed preset 0 (slowest) and 100 (fastest)\n" },
190 { "--", "--fast_sad", FAST_SAD, "Flag for faster sad execution\n" },
191 { "--", "--alt_ref", ALT_REF , "Flag to enable alternate reference frames\n"},
192 { "--", "--hpel", HPEL, "Flag to enable/disable Quarter pel estimation \n" },
193 { "--", "--qpel", QPEL, "Flag to enable/disable Quarter pel estimation \n" },
194 { "--", "--disable_deblock_level", DISABLE_DEBLOCK_LEVEL,
195 "Disable deblock level - 0 : Enables deblock completely, "
196 "1: enables for I and 8th frame , 2: Enables for I only, "
197 "3 : disables completely\n" },
198 { "--", "--search_range_x", SRCH_RNG_X, "Search range for X \n" },
199 { "--", "--search_range_y", SRCH_RNG_Y, "Search range for Y \n" },
200 { "--", "--psnr", PSNR, "Enable PSNR computation (Disable while benchmarking performance) \n" },
201 { "--", "--pre_enc_me", PRE_ENC_ME, "Flag to enable/disable Pre Enc Motion Estimation\n" },
202 { "--", "--pre_enc_ipe", PRE_ENC_IPE, "Flag to enable/disable Pre Enc Intra prediction Estimation\n" },
203 { "-n", "--num_cores", NUMCORES, "Number of cores to be used\n" },
204 { "--", "--adaptive_intra_refresh", AIR, "Adaptive Intra Refresh enable/disable\n"},
205 { "--", "--air_refresh_period", AIR_REFRESH_PERIOD,"adaptive intra refresh period\n"},
206 { "--", "--slice", SLICE_MODE, "Slice mode - 0 :No slice, 1: Bytes per slice, 2: MB/CTB per slice\n" },
207 { "--", "--slice_param", SLICE_PARAM, "Slice param value based on slice mode. Slice mode of 1 implies number of bytes per slice, 2 implies number of MBs/CTBs, for 0 value is neglected \n" },
208 { "--", "--max_wd", MAX_WD, "Maximum width (Default: 1920) \n" },
209 { "--", "--max_ht", MAX_HT, "Maximum height (Default: 1088)\n" },
210 { "--", "--max_level", MAX_LEVEL, "Maximum Level (Default: 50)\n" },
211 { "--", "--arch", ARCH, "Set Architecture. Supported values ARM_NONEON, ARM_A9Q, ARM_A7, ARM_A5, ARM_NEONINTR, X86_GENERIC, X86_SSSE3, X86_SSE4 \n" },
212 { "--", "--soc", SOC, "Set SOC. Supported values GENERIC\n" },
213 { "--", "--chksum", CHKSUM_FILE, "Save Check sum file for recon data\n" },
214 { "--", "--chksum_enable", CHKSUM_ENABLE, "Recon MD5 Checksum file\n"},
215 { "-c", "--config", CONFIG, "config file (Default: enc.cfg)\n" },
216 { "--", "--loopback", LOOPBACK, "Enable encoding in a loop\n" },
217 { "--", "--profile", PROFILE, "Profile mode: Supported values BASE, MAIN, HIGH\n" },
218 { "--", "--max_bitrate", MAX_BITRATE, "Max bitrate\n"},
219 { "--", "--bitrate", BITRATE, "Target bitrate\n"},
220 { "--", "--qp_i", I_QP, "QP for I frames\n"},
221 { "--", "--qp_p", P_QP, "QP for P frames\n"},
222 { "--", "--qp_b", B_QP, "QP for B frames\n"},
223 { "--", "--qp_i_max",I_QP_MAX, "Max QP for I frames\n"},
224 { "--", "--qp_p_max", P_QP_MAX, "Max QP for P frames\n"},
225 { "--", "--qp_b_max", B_QP_MAX, "Max QP for B frames\n"},
226 { "--", "--qp_i_min", I_QP_MIN, "Min QP for I frames\n"},
227 { "--", "--qp_p_min", P_QP_MIN, "Min QP for P frames\n"},
228 { "--", "--qp_b_min", B_QP_MIN, "Min QP for B frames\n"},
229 { "--", "--entropy", ENTROPY, "Entropy coding mode(0: CAVLC or 1: CABAC)\n"},
230 { "--", "--vbv_delay", VBV_DELAY, "VBV buffer delay\n"},
231 { "--", "--vbv_size", VBV_SIZE, "VBV buffer size\n"},
232 { "--", "--intra_4x4_enable", INTRA_4x4_ENABLE, "Intra 4x4 enable \n" },
233 { "--", "--mb_info_file", MB_INFO_FILE, "MB info file\n"},
234 { "--", "--mb_info_type", MB_INFO_TYPE, "MB info type\n"},
235 { "--", "--pic_info_file", PIC_INFO_FILE, "Pic info file\n"},
236 { "--", "--pic_info_type", PIC_INFO_TYPE, "Pic info type\n"},
237 };
238
239
240 /*****************************************************************************/
241 /* Function Definitions */
242 /*****************************************************************************/
243
244 /**
245 *******************************************************************************
246 *
247 * @brief Returns malloc data. Ideally should return aligned memory
248 *
249 * @param[in] alignment
250 * Alignment
251 *
252 * @param[in] size
253 * size
254 *
255 * @returns pointer to allocated memory
256 *
257 * @remarks none
258 *
259 *******************************************************************************
260 */
261 #if(defined X86) && (defined X86_MINGW)
262
ih264a_aligned_malloc(WORD32 alignment,WORD32 size)263 void * ih264a_aligned_malloc(WORD32 alignment, WORD32 size)
264 {
265 return _aligned_malloc(size, alignment);
266 }
267
ih264a_aligned_free(void * pv_buf)268 void ih264a_aligned_free(void *pv_buf)
269 {
270 _aligned_free(pv_buf);
271 return;
272 }
273
274 #elif IOS
275
ih264a_aligned_malloc(WORD32 alignment,WORD32 size)276 void * ih264a_aligned_malloc(WORD32 alignment, WORD32 size)
277 {
278 return malloc(size);
279 }
280
ih264a_aligned_free(void * pv_buf)281 void ih264a_aligned_free(void *pv_buf)
282 {
283 free(pv_buf);
284 return;
285 }
286
287 #else
288
ih264a_aligned_malloc(WORD32 alignment,WORD32 size)289 void * ih264a_aligned_malloc(WORD32 alignment, WORD32 size)
290 {
291 void *buf = NULL;
292 if (0 != posix_memalign(&buf, alignment, size))
293 {
294 return NULL;
295 }
296 return buf;
297 }
298
ih264a_aligned_free(void * pv_buf)299 void ih264a_aligned_free(void *pv_buf)
300 {
301 free(pv_buf);
302 return;
303 }
304
305 #endif
306
307 /**
308 *******************************************************************************
309 *
310 * @brief handles unrecoverable errors. Prints error message to console and exits.
311 *
312 * @param[in] pc_err_message
313 * error message
314 *
315 * @returns none
316 *
317 *******************************************************************************
318 */
codec_exit(CHAR * pc_err_message)319 void codec_exit(CHAR *pc_err_message)
320 {
321 printf("%s\n", pc_err_message);
322 exit(-1);
323 }
324
325 /**
326 *******************************************************************************
327 *
328 * @brief Maps input string to color format
329 *
330 * @param[in] value
331 * string
332 *
333 * @returns color format ID
334 *
335 * @remarks If the input string is not recognized, display a message and choose
336 * YUV420P as color format
337 *
338 *******************************************************************************
339 */
get_chroma_fmt(CHAR * value)340 IV_COLOR_FORMAT_T get_chroma_fmt(CHAR *value)
341 {
342 IV_COLOR_FORMAT_T e_chroma_format = IV_YUV_420P;
343
344 if((strcmp(value, "YUV_420P")) == 0)
345 e_chroma_format = IV_YUV_420P;
346 else if((strcmp(value, "YUV_422ILE")) == 0)
347 e_chroma_format = IV_YUV_422ILE;
348 else if((strcmp(value, "RGB_565")) == 0)
349 e_chroma_format = IV_RGB_565;
350 else if((strcmp(value, "RGBA_8888")) == 0)
351 e_chroma_format = IV_RGBA_8888;
352 else if((strcmp(value, "YUV_420SP_UV")) == 0)
353 e_chroma_format = IV_YUV_420SP_UV;
354 else if((strcmp(value, "YUV_420SP_VU")) == 0)
355 e_chroma_format = IV_YUV_420SP_VU;
356 else
357 printf("\nInvalid colour format setting it to IV_YUV_420P\n");
358
359 return e_chroma_format;
360 }
361
362 /**
363 *******************************************************************************
364 *
365 * @brief Maps input string to a speed preset
366 *
367 * @param[in] value
368 * string
369 *
370 * @returns speed preset ID
371 *
372 * @remarks If the input string is not recognized, display a message and choose
373 * IVE_FASTEST as speed preset
374 *
375 *******************************************************************************
376 */
get_speed_preset(CHAR * value)377 IVE_SPEED_CONFIG get_speed_preset(CHAR *value)
378 {
379 IVE_SPEED_CONFIG e_enc_speed_preset = IVE_FASTEST;
380
381 if((strcmp(value, "CONFIG")) == 0)
382 e_enc_speed_preset = IVE_CONFIG;
383 else if((strcmp(value, "SLOWEST")) == 0)
384 e_enc_speed_preset = IVE_SLOWEST;
385 else if((strcmp(value, "NORMAL")) == 0)
386 e_enc_speed_preset = IVE_NORMAL;
387 else if((strcmp(value, "FAST")) == 0)
388 e_enc_speed_preset = IVE_FAST;
389 else if((strcmp(value, "HIGH_SPEED")) == 0)
390 e_enc_speed_preset = IVE_HIGH_SPEED;
391 else if((strcmp(value, "FASTEST")) == 0)
392 e_enc_speed_preset = IVE_FASTEST;
393 else
394 printf("\nInvalid speed preset, setting it to IVE_FASTEST\n");
395
396 return e_enc_speed_preset;
397 }
398
399 /**
400 *******************************************************************************
401 * @brief prints application usage
402 *******************************************************************************
403 */
print_usage(void)404 void print_usage(void)
405 {
406 WORD32 i = 0;
407 WORD32 num_entries = sizeof(argument_mapping) / sizeof(argument_t);
408
409 printf("\nUsage:\n");
410 while(i < num_entries)
411 {
412 printf("%-32s\t %s", argument_mapping[i].argument_name,
413 argument_mapping[i].description);
414 i++;
415 }
416 }
417
418 /**
419 *******************************************************************************
420 *
421 * @brief Maps input string to a argument
422 *
423 * @param[in] value
424 * string
425 *
426 * @returns argument ID
427 *
428 * @remarks If the input string is not recognized, returns INVALID
429 *
430 *******************************************************************************
431 */
get_argument(CHAR * name)432 ARGUMENT_T get_argument(CHAR *name)
433 {
434 WORD32 i;
435 WORD32 num_entries = sizeof(argument_mapping) / sizeof(argument_t);
436
437 for(i = 0;i < num_entries;i++)
438 {
439 if((0 == strcmp(argument_mapping[i].argument_name, name)) ||
440 ((0 == strcmp(argument_mapping[i].argument_shortname, name)) &&
441 (0 != strcmp(argument_mapping[i].argument_shortname, "--"))))
442 {
443 return argument_mapping[i].argument;
444 }
445 }
446 return INVALID;
447 }
448
449 /**
450 *******************************************************************************
451 *
452 * @brief Parse input argument
453 *
454 * @param[in] ps_app_ctxt
455 * pointer to application context
456 *
457 * @param[in] argument
458 * argument string
459 *
460 * @param[in] value
461 * value corresponding to the argument
462 *
463 * @returns none
464 *
465 * @remarks none
466 *
467 *******************************************************************************
468 */
parse_argument(app_ctxt_t * ps_app_ctxt,CHAR * argument,CHAR * value)469 void parse_argument(app_ctxt_t *ps_app_ctxt, CHAR *argument, CHAR *value)
470 {
471 ARGUMENT_T arg = get_argument(argument);
472
473 switch(arg)
474 {
475 case HELP:
476 print_usage();
477 exit(-1);
478 break;
479
480 case SLICE_MODE:
481 sscanf(value, "%d", &ps_app_ctxt->u4_slice_mode);
482 break;
483
484 case SLICE_PARAM:
485 sscanf(value, "%d", &ps_app_ctxt->u4_slice_param);
486 break;
487
488 case INPUT_FILE:
489 sscanf(value, "%s", ps_app_ctxt->ac_ip_fname);
490 break;
491
492 case OUTPUT_FILE:
493 sscanf(value, "%s", ps_app_ctxt->ac_op_fname);
494 break;
495
496 case RECON_FILE:
497 sscanf(value, "%s", ps_app_ctxt->ac_recon_fname);
498 break;
499
500 case RECON_ENABLE:
501 sscanf(value, "%d", &ps_app_ctxt->u4_recon_enable);
502 break;
503
504 case CHKSUM_FILE:
505 sscanf(value, "%s", ps_app_ctxt->ac_chksum_fname);
506 break;
507
508 case CHKSUM_ENABLE:
509 sscanf(value, "%d", &ps_app_ctxt->u4_chksum_enable);
510 break;
511
512 case MB_INFO_FILE:
513 sscanf(value, "%s", ps_app_ctxt->ac_mb_info_fname);
514 break;
515
516 case MB_INFO_TYPE:
517 sscanf(value, "%d", &ps_app_ctxt->u4_mb_info_type);
518 break;
519
520 case PIC_INFO_FILE:
521 sscanf(value, "%s", ps_app_ctxt->ac_pic_info_fname);
522 break;
523
524 case PIC_INFO_TYPE:
525 sscanf(value, "%d", &ps_app_ctxt->u4_pic_info_type);
526 break;
527
528 case INPUT_CHROMA_FORMAT:
529 ps_app_ctxt->e_inp_color_fmt = get_chroma_fmt(value);
530 break;
531
532 case RECON_CHROMA_FORMAT:
533 ps_app_ctxt->e_recon_color_fmt = get_chroma_fmt(value);
534 break;
535
536 case MAX_WD:
537 sscanf(value, "%d", &ps_app_ctxt->u4_max_wd);
538 break;
539
540 case MAX_HT:
541 sscanf(value, "%d", &ps_app_ctxt->u4_max_ht);
542 break;
543
544 case WD:
545 sscanf(value, "%d", &ps_app_ctxt->u4_wd);
546 break;
547
548 case HT:
549 sscanf(value, "%d", &ps_app_ctxt->u4_ht);
550 break;
551
552 case MAX_LEVEL:
553 sscanf(value, "%d", &ps_app_ctxt->u4_max_level);
554 break;
555
556 case ENC_SPEED:
557 ps_app_ctxt->u4_enc_speed = get_speed_preset(value);
558 break;
559
560 case ME_SPEED:
561 sscanf(value, "%d", &ps_app_ctxt->u4_me_speed);
562 break;
563
564 case START_FRM:
565 sscanf(value, "%d", &ps_app_ctxt->u4_start_frm);
566 break;
567
568 case NUM_FRMS:
569 sscanf(value, "%d", &ps_app_ctxt->u4_max_num_frms);
570 break;
571
572 case MAX_FRAMERATE:
573 sscanf(value, "%d", &ps_app_ctxt->u4_max_frame_rate);
574 if(ps_app_ctxt->u4_max_frame_rate <= 0)
575 ps_app_ctxt->u4_max_frame_rate = DEFAULT_MAX_FRAMERATE;
576 break;
577
578 case SRC_FRAMERATE:
579 sscanf(value, "%d", &ps_app_ctxt->u4_src_frame_rate);
580 if(ps_app_ctxt->u4_src_frame_rate <= 0)
581 ps_app_ctxt->u4_src_frame_rate = DEFAULT_SRC_FRAME_RATE;
582 break;
583
584 case TGT_FRAMERATE:
585 sscanf(value, "%d", &ps_app_ctxt->u4_tgt_frame_rate);
586 if(ps_app_ctxt->u4_tgt_frame_rate <= 0)
587 ps_app_ctxt->u4_tgt_frame_rate = DEFAULT_TGT_FRAME_RATE;
588 break;
589
590 case RC:
591 sscanf(value, "%d", &ps_app_ctxt->u4_rc);
592 break;
593
594 case MAX_BITRATE:
595 sscanf(value, "%d", &ps_app_ctxt->u4_max_bitrate);
596 break;
597
598 case BITRATE:
599 sscanf(value, "%d", &ps_app_ctxt->u4_bitrate);
600 break;
601
602 case I_QP:
603 sscanf(value, "%d", &ps_app_ctxt->u4_i_qp);
604 break;
605
606 case I_QP_MAX:
607 sscanf(value, "%d", &ps_app_ctxt->u4_i_qp_max);
608 break;
609
610 case I_QP_MIN:
611 sscanf(value, "%d", &ps_app_ctxt->u4_i_qp_min);
612 break;
613
614 case P_QP:
615 sscanf(value, "%d", &ps_app_ctxt->u4_p_qp);
616 break;
617
618 case P_QP_MAX:
619 sscanf(value, "%d", &ps_app_ctxt->u4_p_qp_max);
620 break;
621
622 case P_QP_MIN:
623 sscanf(value, "%d", &ps_app_ctxt->u4_p_qp_min);
624 break;
625
626 case B_QP:
627 sscanf(value, "%d", &ps_app_ctxt->u4_b_qp);
628 break;
629
630 case B_QP_MAX:
631 sscanf(value, "%d", &ps_app_ctxt->u4_b_qp_max);
632 break;
633
634 case B_QP_MIN:
635 sscanf(value, "%d", &ps_app_ctxt->u4_b_qp_min);
636 break;
637
638 case ENTROPY:
639 sscanf(value, "%d", &ps_app_ctxt->u4_entropy_coding_mode);
640 break;
641
642 case AIR:
643 sscanf(value, "%d", &ps_app_ctxt->u4_air);
644 break;
645
646 case ARCH:
647 if((strcmp(value, "ARM_NONEON")) == 0)
648 ps_app_ctxt->e_arch = ARCH_ARM_NONEON;
649 else if((strcmp(value, "ARM_A9Q")) == 0)
650 ps_app_ctxt->e_arch = ARCH_ARM_A9Q;
651 else if((strcmp(value, "ARM_A7")) == 0)
652 ps_app_ctxt->e_arch = ARCH_ARM_A7;
653 else if((strcmp(value, "ARM_A5")) == 0)
654 ps_app_ctxt->e_arch = ARCH_ARM_A5;
655 else if((strcmp(value, "ARM_NEONINTR")) == 0)
656 ps_app_ctxt->e_arch = ARCH_ARM_NEONINTR;
657 else if((strcmp(value, "X86_GENERIC")) == 0)
658 ps_app_ctxt->e_arch = ARCH_X86_GENERIC;
659 else if((strcmp(value, "X86_SSSE3")) == 0)
660 ps_app_ctxt->e_arch = ARCH_X86_SSSE3;
661 else if((strcmp(value, "X86_SSE42")) == 0)
662 ps_app_ctxt->e_arch = ARCH_X86_SSE42;
663 else if((strcmp(value, "ARM_A53")) == 0)
664 ps_app_ctxt->e_arch = ARCH_ARM_A53;
665 else if((strcmp(value, "ARM_A57")) == 0)
666 ps_app_ctxt->e_arch = ARCH_ARM_A57;
667 else if((strcmp(value, "ARM_V8_NEON")) == 0)
668 ps_app_ctxt->e_arch = ARCH_ARM_V8_NEON;
669 else
670 {
671 printf("\nInvalid Arch. Setting it to ARM_A9Q\n");
672 ps_app_ctxt->e_arch = ARCH_ARM_A9Q;
673 }
674 break;
675
676 case SOC:
677 if((strcmp(value, "GENERIC")) == 0)
678 ps_app_ctxt->e_soc = SOC_GENERIC;
679 else
680 {
681 printf("\nInvalid SOC. Setting it to SOC_GENERIC\n");
682 ps_app_ctxt->e_soc = SOC_GENERIC;
683 }
684 break;
685
686 case NUMCORES:
687 sscanf(value, "%d", &ps_app_ctxt->u4_num_cores);
688 break;
689
690 case LOOPBACK:
691 sscanf(value, "%d", &ps_app_ctxt->u4_loopback);
692 break;
693
694 case PRE_ENC_ME:
695 sscanf(value, "%d", &ps_app_ctxt->u4_pre_enc_me);
696 break;
697
698 case PRE_ENC_IPE:
699 sscanf(value, "%d", &ps_app_ctxt->u4_pre_enc_ipe);
700 break;
701
702 case HPEL:
703 sscanf(value, "%d", &ps_app_ctxt->u4_hpel);
704 break;
705
706 case QPEL:
707 sscanf(value, "%d", &ps_app_ctxt->u4_qpel);
708 break;
709
710 case SRCH_RNG_X:
711 sscanf(value, "%d", &ps_app_ctxt->u4_srch_rng_x);
712 break;
713
714 case SRCH_RNG_Y:
715 sscanf(value, "%d", &ps_app_ctxt->u4_srch_rng_y);
716 break;
717
718 case I_INTERVAL:
719 sscanf(value, "%d", &ps_app_ctxt->u4_i_interval);
720 break;
721
722 case IDR_INTERVAL:
723 sscanf(value, "%d", &ps_app_ctxt->u4_idr_interval);
724 break;
725
726 case CONSTRAINED_INTRA_PRED:
727 sscanf(value, "%d", &ps_app_ctxt->u4_constrained_intra_pred);
728 break;
729
730 case NUM_B_FRMS:
731 sscanf(value, "%d", &ps_app_ctxt->u4_num_bframes);
732 break;
733
734 case DISABLE_DEBLOCK_LEVEL:
735 sscanf(value, "%d", &ps_app_ctxt->u4_disable_deblk_level);
736 break;
737
738 case VBV_DELAY:
739 sscanf(value, "%d", &ps_app_ctxt->u4_vbv_buffer_delay);
740 break;
741
742 case VBV_SIZE:
743 sscanf(value, "%d", &ps_app_ctxt->u4_vbv_buf_size);
744 break;
745
746 case FAST_SAD:
747 sscanf(value, "%d", &ps_app_ctxt->u4_enable_fast_sad);
748 break;
749
750 case ALT_REF:
751 sscanf(value, "%d", &ps_app_ctxt->u4_enable_alt_ref);
752 break;
753
754 case AIR_REFRESH_PERIOD:
755 sscanf(value, "%d", &ps_app_ctxt->u4_air_refresh_period);
756 break;
757
758 case PROFILE:
759 if((strcmp(value, "BASE")) == 0)
760 ps_app_ctxt->e_profile = IV_PROFILE_BASE;
761 else if((strcmp(value, "MAIN")) == 0)
762 ps_app_ctxt->e_profile = IV_PROFILE_MAIN;
763 else if((strcmp(value, "HIGH")) == 0)
764 ps_app_ctxt->e_profile = IV_PROFILE_HIGH;
765 else
766 {
767 printf("\nInvalid profile. Setting it to BASE\n");
768 ps_app_ctxt->e_profile = IV_PROFILE_BASE;
769 }
770 break;
771
772 case PSNR:
773 sscanf(value, "%d", &ps_app_ctxt->u4_psnr_enable);
774 break;
775
776 case INTRA_4x4_ENABLE:
777 sscanf(value, "%d", &ps_app_ctxt->u4_enable_intra_4x4);
778 break;
779
780 case INVALID:
781 default:
782 printf("Ignoring argument : %s\n", argument);
783 break;
784 }
785 }
786
787 /**
788 *******************************************************************************
789 *
790 * @brief Parse config file
791 *
792 * @param[in] ps_app_ctxt
793 * pointer to application context
794 *
795 * @param[in] fp_cfg
796 * config file pointer
797 *
798 * @returns none
799 *
800 * @remarks none
801 *
802 *******************************************************************************
803 */
read_cfg_file(app_ctxt_t * ps_app_ctxt,FILE * fp_cfg)804 void read_cfg_file(app_ctxt_t *ps_app_ctxt, FILE *fp_cfg)
805 {
806 while(1)
807 {
808 CHAR line[STRLENGTH] = {'\0'};
809 CHAR argument[STRLENGTH] = {'\0'};
810 CHAR value[STRLENGTH];
811 CHAR description[STRLENGTH];
812
813 if(NULL == fgets(line, STRLENGTH, fp_cfg)) return;
814
815 /* split string on whitespace */
816 sscanf(line, "%s %s %s", argument, value, description);
817 if(argument[0] == '\0')
818 continue;
819
820 parse_argument(ps_app_ctxt, argument, value);
821 }
822 }
823
824 /**
825 *******************************************************************************
826 *
827 * @brief handles unrecoverable errors. Prints error message to console and exits.
828 *
829 * @param[in] pc_err_message
830 * error message
831 *
832 * @returns none
833 *
834 * @remarks none
835 *
836 *******************************************************************************
837 */
invalid_argument_exit(CHAR * pc_err_message)838 void invalid_argument_exit(CHAR *pc_err_message)
839 {
840 print_usage();
841 codec_exit(pc_err_message);
842 }
843
844 /**
845 *******************************************************************************
846 *
847 * @brief validate configured params
848 *
849 * @param[in] ps_app_ctxt
850 * pointer to application context
851 *
852 * @returns none
853 *
854 * @remarks none
855 *
856 *******************************************************************************
857 */
validate_params(app_ctxt_t * ps_app_ctxt)858 void validate_params(app_ctxt_t *ps_app_ctxt)
859 {
860 CHAR ac_error[STRLENGTH];
861
862 if(ps_app_ctxt->ac_ip_fname[0] == '\0')
863 {
864 invalid_argument_exit("Specify input file");
865 }
866 if(ps_app_ctxt->ac_op_fname[0] == '\0')
867 {
868 invalid_argument_exit("Specify output file");
869 }
870 if((1 == ps_app_ctxt->u4_recon_enable) && (ps_app_ctxt->ac_recon_fname[0] == '\0'))
871 {
872 invalid_argument_exit("Specify recon file");
873 }
874 if((1 == ps_app_ctxt->u4_chksum_enable) && (ps_app_ctxt->ac_chksum_fname[0] == '\0'))
875 {
876 invalid_argument_exit("Specify checksum file");
877 }
878 if(0 >= (WORD32)ps_app_ctxt->u4_wd)
879 {
880 sprintf(ac_error, "Invalid width: %d", ps_app_ctxt->u4_wd);
881 invalid_argument_exit(ac_error);
882 }
883 if(0 >= (WORD32)ps_app_ctxt->u4_ht)
884 {
885 sprintf(ac_error, "Invalid height: %d", ps_app_ctxt->u4_ht);
886 invalid_argument_exit(ac_error);
887 }
888 if(0 == (WORD32)ps_app_ctxt->u4_max_num_frms)
889 {
890 sprintf(ac_error, "Invalid number of frames to be encoded: %d", ps_app_ctxt->u4_max_num_frms);
891 invalid_argument_exit(ac_error);
892 }
893 }
894
895 /**
896 *******************************************************************************
897 *
898 * @brief initialize default params
899 *
900 * @param[in] ps_app_ctxt
901 * pointer to application context
902 *
903 * @returns none
904 *
905 * @remarks none
906 *
907 *******************************************************************************
908 */
init_default_params(app_ctxt_t * ps_app_ctxt)909 void init_default_params(app_ctxt_t *ps_app_ctxt)
910 {
911 ps_app_ctxt->ps_enc = NULL;
912 ps_app_ctxt->ps_mem_rec = NULL;
913 ps_app_ctxt->u4_num_mem_rec = DEFAULT_MEM_REC_CNT;
914 ps_app_ctxt->u4_recon_enable = DEFAULT_RECON_ENABLE;
915 ps_app_ctxt->u4_chksum_enable = DEFAULT_CHKSUM_ENABLE;
916 ps_app_ctxt->u4_mb_info_type = 0;
917 ps_app_ctxt->u4_pic_info_type = 0;
918 ps_app_ctxt->u4_mb_info_size = 0;
919 ps_app_ctxt->u4_pic_info_size = 0;
920 ps_app_ctxt->u4_start_frm = DEFAULT_START_FRM;
921 ps_app_ctxt->u4_max_num_frms = DEFAULT_NUM_FRMS;
922 ps_app_ctxt->u4_total_bytes = 0;
923 ps_app_ctxt->u4_pics_cnt = 0;
924 ps_app_ctxt->e_inp_color_fmt = DEFAULT_INP_COLOR_FMT;
925 ps_app_ctxt->e_recon_color_fmt = DEFAULT_RECON_COLOR_FMT;
926 ps_app_ctxt->e_arch = ARCH_ARM_A9Q;
927 ps_app_ctxt->e_soc = SOC_GENERIC;
928 ps_app_ctxt->header_generated = 0;
929 ps_app_ctxt->pv_codec_obj = NULL;
930 ps_app_ctxt->u4_num_cores = DEFAULT_NUM_CORES;
931 ps_app_ctxt->u4_pre_enc_me = 0;
932 ps_app_ctxt->u4_pre_enc_ipe = 0;
933 ps_app_ctxt->ac_ip_fname[0] = '\0';
934 ps_app_ctxt->ac_op_fname[0] = '\0';
935 ps_app_ctxt->ac_recon_fname[0] = '\0';
936 ps_app_ctxt->ac_chksum_fname[0] = '\0';
937 ps_app_ctxt->ac_mb_info_fname[0] = '\0';
938 ps_app_ctxt->fp_ip = NULL;
939 ps_app_ctxt->fp_op = NULL;
940 ps_app_ctxt->fp_recon = NULL;
941 ps_app_ctxt->fp_chksum = NULL;
942 ps_app_ctxt->fp_psnr_ip = NULL;
943 ps_app_ctxt->fp_mb_info = NULL;
944 ps_app_ctxt->fp_pic_info = NULL;
945 ps_app_ctxt->u4_loopback = DEFAULT_LOOPBACK;
946 ps_app_ctxt->u4_max_frame_rate = DEFAULT_MAX_FRAMERATE;
947 ps_app_ctxt->u4_src_frame_rate = DEFAULT_SRC_FRAME_RATE;
948 ps_app_ctxt->u4_tgt_frame_rate = DEFAULT_TGT_FRAME_RATE;
949 ps_app_ctxt->u4_max_wd = DEFAULT_MAX_WD;
950 ps_app_ctxt->u4_max_ht = DEFAULT_MAX_HT;
951 ps_app_ctxt->u4_max_level = DEFAULT_MAX_LEVEL;
952 ps_app_ctxt->u4_strd = DEFAULT_STRIDE;
953 ps_app_ctxt->u4_wd = DEFAULT_WD;
954 ps_app_ctxt->u4_ht = DEFAULT_HT;
955 ps_app_ctxt->u4_psnr_enable = DEFAULT_PSNR_ENABLE;
956 ps_app_ctxt->u4_enc_speed = IVE_FASTEST;
957 ps_app_ctxt->u4_me_speed = DEFAULT_ME_SPEED;
958 ps_app_ctxt->u4_enable_fast_sad = DEFAULT_ENABLE_FAST_SAD;
959 ps_app_ctxt->u4_enable_alt_ref = DEFAULT_ENABLE_ALT_REF;
960 ps_app_ctxt->u4_rc = DEFAULT_RC;
961 ps_app_ctxt->u4_max_bitrate = DEFAULT_MAX_BITRATE;
962 ps_app_ctxt->u4_bitrate = DEFAULT_BITRATE;
963 ps_app_ctxt->u4_i_qp = DEFAULT_I_QP;
964 ps_app_ctxt->u4_i_qp_max = DEFAULT_QP_MAX;
965 ps_app_ctxt->u4_i_qp_min = DEFAULT_QP_MIN;
966 ps_app_ctxt->u4_p_qp = DEFAULT_P_QP;
967 ps_app_ctxt->u4_p_qp_max = DEFAULT_QP_MAX;
968 ps_app_ctxt->u4_p_qp_min = DEFAULT_QP_MIN;
969 ps_app_ctxt->u4_b_qp = DEFAULT_B_QP;
970 ps_app_ctxt->u4_b_qp_max = DEFAULT_QP_MAX;
971 ps_app_ctxt->u4_b_qp_min = DEFAULT_QP_MIN;
972 ps_app_ctxt->u4_air = DEFAULT_AIR;
973 ps_app_ctxt->u4_air_refresh_period = DEFAULT_AIR_REFRESH_PERIOD;
974 ps_app_ctxt->u4_srch_rng_x = DEFAULT_SRCH_RNG_X;
975 ps_app_ctxt->u4_srch_rng_y = DEFAULT_SRCH_RNG_Y;
976 ps_app_ctxt->u4_i_interval = DEFAULT_I_INTERVAL;
977 ps_app_ctxt->u4_idr_interval = DEFAULT_IDR_INTERVAL;
978 ps_app_ctxt->u4_constrained_intra_pred = DEFAULT_CONSTRAINED_INTRAPRED;
979 ps_app_ctxt->u4_num_bframes = DEFAULT_NUM_BFRAMES;
980 ps_app_ctxt->u4_disable_deblk_level = DEFAULT_DISABLE_DEBLK_LEVEL;
981 ps_app_ctxt->u4_hpel = DEFAULT_HPEL;
982 ps_app_ctxt->u4_qpel = DEFAULT_QPEL;
983 ps_app_ctxt->u4_enable_intra_4x4 = DEFAULT_I4;
984 ps_app_ctxt->e_profile = DEFAULT_EPROFILE;
985 ps_app_ctxt->u4_slice_mode = DEFAULT_SLICE_MODE;
986 ps_app_ctxt->u4_slice_param = DEFAULT_SLICE_PARAM;
987 ps_app_ctxt->u4_entropy_coding_mode = DEFAULT_ENTROPY_CODING_MODE;
988 ps_app_ctxt->pv_input_thread_handle = NULL;
989 ps_app_ctxt->pv_output_thread_handle = NULL;
990 ps_app_ctxt->pv_recon_thread_handle = NULL;
991 ps_app_ctxt->adbl_psnr[0] = 0.0;
992 ps_app_ctxt->adbl_psnr[1] = 0.0;
993 ps_app_ctxt->adbl_psnr[2] = 0.0;
994 ps_app_ctxt->u4_psnr_cnt = 0;
995 ps_app_ctxt->pu1_psnr_buf = NULL;
996 ps_app_ctxt->u4_psnr_buf_size = 0;
997 ps_app_ctxt->u4_vbv_buffer_delay = 1000;
998 ps_app_ctxt->u4_vbv_buf_size = 0;
999 ps_app_ctxt->avg_time = 0;
1000 }
1001
1002 /**
1003 *******************************************************************************
1004 * @brief configure input dimensions
1005 *******************************************************************************
1006 */
set_dimensions(app_ctxt_t * ps_app_ctxt,UWORD32 u4_timestamp_low,UWORD32 u4_timestamp_high)1007 void set_dimensions(app_ctxt_t *ps_app_ctxt,
1008 UWORD32 u4_timestamp_low,
1009 UWORD32 u4_timestamp_high)
1010 {
1011 ih264e_ctl_set_dimensions_ip_t s_frame_dimensions_ip;
1012 ih264e_ctl_set_dimensions_op_t s_frame_dimensions_op;
1013 IV_STATUS_T status;
1014
1015 s_frame_dimensions_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_dimensions_ip_t);
1016 s_frame_dimensions_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL;
1017 s_frame_dimensions_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_DIMENSIONS;
1018 s_frame_dimensions_ip.s_ive_ip.u4_wd = ps_app_ctxt->u4_wd;
1019 s_frame_dimensions_ip.s_ive_ip.u4_ht = ps_app_ctxt->u4_ht;
1020 s_frame_dimensions_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low;
1021 s_frame_dimensions_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high;
1022
1023 s_frame_dimensions_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_dimensions_op_t);
1024
1025 status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_frame_dimensions_ip,
1026 &s_frame_dimensions_op);
1027 if(status != IV_SUCCESS)
1028 {
1029 CHAR ac_error[STRLENGTH];
1030 sprintf(ac_error, "Unable to set frame dimensions = 0x%x\n",
1031 s_frame_dimensions_op.s_ive_op.u4_error_code);
1032 codec_exit(ac_error);
1033 }
1034 }
1035
1036 /**
1037 *******************************************************************************
1038 * @brief configure source & target framerates
1039 *******************************************************************************
1040 */
set_frame_rate(app_ctxt_t * ps_app_ctxt,UWORD32 u4_timestamp_low,UWORD32 u4_timestamp_high)1041 void set_frame_rate(app_ctxt_t *ps_app_ctxt,
1042 UWORD32 u4_timestamp_low,
1043 UWORD32 u4_timestamp_high)
1044 {
1045 ih264e_ctl_set_frame_rate_ip_t s_frame_rate_ip;
1046 ih264e_ctl_set_frame_rate_op_t s_frame_rate_op;
1047 IV_STATUS_T status;
1048
1049 s_frame_rate_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_frame_rate_ip_t);
1050 s_frame_rate_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL;
1051 s_frame_rate_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_FRAMERATE;
1052 s_frame_rate_ip.s_ive_ip.u4_src_frame_rate = ps_app_ctxt->u4_src_frame_rate;
1053 s_frame_rate_ip.s_ive_ip.u4_tgt_frame_rate = ps_app_ctxt->u4_tgt_frame_rate;
1054 s_frame_rate_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low;
1055 s_frame_rate_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high;
1056
1057 s_frame_rate_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_frame_rate_op_t);
1058
1059 status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_frame_rate_ip,
1060 &s_frame_rate_op);
1061 if(status != IV_SUCCESS)
1062 {
1063 CHAR ac_error[STRLENGTH];
1064 sprintf(ac_error, "Unable to set frame rate = 0x%x\n",
1065 s_frame_rate_op.s_ive_op.u4_error_code);
1066 codec_exit(ac_error);
1067 }
1068 }
1069
1070 /**
1071 *******************************************************************************
1072 * @brief configure IPE params
1073 *******************************************************************************
1074 */
set_ipe_params(app_ctxt_t * ps_app_ctxt,UWORD32 u4_timestamp_low,UWORD32 u4_timestamp_high)1075 void set_ipe_params(app_ctxt_t *ps_app_ctxt,
1076 UWORD32 u4_timestamp_low,
1077 UWORD32 u4_timestamp_high)
1078 {
1079 ih264e_ctl_set_ipe_params_ip_t s_ipe_params_ip;
1080 ih264e_ctl_set_ipe_params_op_t s_ipe_params_op;
1081 IV_STATUS_T status;
1082
1083 s_ipe_params_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_ipe_params_ip_t);
1084 s_ipe_params_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL;
1085 s_ipe_params_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_IPE_PARAMS;
1086 s_ipe_params_ip.s_ive_ip.u4_enable_intra_4x4 = ps_app_ctxt->u4_enable_intra_4x4;
1087 s_ipe_params_ip.s_ive_ip.u4_enc_speed_preset = ps_app_ctxt->u4_enc_speed;
1088 s_ipe_params_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low;
1089 s_ipe_params_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high;
1090 s_ipe_params_ip.s_ive_ip.u4_constrained_intra_pred = ps_app_ctxt->u4_constrained_intra_pred;
1091
1092 s_ipe_params_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_ipe_params_op_t);
1093
1094 status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_ipe_params_ip,
1095 &s_ipe_params_op);
1096 if(status != IV_SUCCESS)
1097 {
1098 CHAR ac_error[STRLENGTH];
1099 sprintf(ac_error, "Unable to set ipe params = 0x%x\n",
1100 s_ipe_params_op.s_ive_op.u4_error_code);
1101 codec_exit(ac_error);
1102 }
1103 }
1104
1105 /**
1106 *******************************************************************************
1107 * @brief configure bitrate
1108 *******************************************************************************
1109 */
set_bit_rate(app_ctxt_t * ps_app_ctxt,UWORD32 u4_timestamp_low,UWORD32 u4_timestamp_high)1110 void set_bit_rate(app_ctxt_t *ps_app_ctxt,
1111 UWORD32 u4_timestamp_low,
1112 UWORD32 u4_timestamp_high)
1113 {
1114 ih264e_ctl_set_bitrate_ip_t s_bitrate_ip;
1115 ih264e_ctl_set_bitrate_op_t s_bitrate_op;
1116 IV_STATUS_T status;
1117
1118 s_bitrate_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_bitrate_ip_t);
1119 s_bitrate_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL;
1120 s_bitrate_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_BITRATE;
1121 s_bitrate_ip.s_ive_ip.u4_target_bitrate = ps_app_ctxt->u4_bitrate;
1122 s_bitrate_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low;
1123 s_bitrate_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high;
1124
1125 s_bitrate_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_bitrate_op_t);
1126
1127 status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_bitrate_ip,
1128 &s_bitrate_op);
1129 if(status != IV_SUCCESS)
1130 {
1131 CHAR ac_error[STRLENGTH];
1132 sprintf(ac_error, "Unable to set bit rate = 0x%x\n",
1133 s_bitrate_op.s_ive_op.u4_error_code);
1134 codec_exit(ac_error);
1135 }
1136 }
1137
1138 /**
1139 *******************************************************************************
1140 * @brief configure frame type
1141 *******************************************************************************
1142 */
set_frame_type(app_ctxt_t * ps_app_ctxt,UWORD32 u4_timestamp_low,UWORD32 u4_timestamp_high,IV_PICTURE_CODING_TYPE_T e_frame_type)1143 void set_frame_type(app_ctxt_t *ps_app_ctxt,
1144 UWORD32 u4_timestamp_low,
1145 UWORD32 u4_timestamp_high,
1146 IV_PICTURE_CODING_TYPE_T e_frame_type)
1147 {
1148 ih264e_ctl_set_frame_type_ip_t s_frame_type_ip;
1149 ih264e_ctl_set_frame_type_op_t s_frame_type_op;
1150 IV_STATUS_T status;
1151
1152 s_frame_type_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_frame_type_ip_t);
1153 s_frame_type_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL;
1154 s_frame_type_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_FRAMETYPE;
1155 s_frame_type_ip.s_ive_ip.e_frame_type = e_frame_type;
1156 s_frame_type_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low;
1157 s_frame_type_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high;
1158
1159 s_frame_type_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_frame_type_op_t);
1160
1161 status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_frame_type_ip,
1162 &s_frame_type_op);
1163 if(status != IV_SUCCESS)
1164 {
1165 CHAR ac_error[STRLENGTH];
1166 sprintf(ac_error, "Unable to set frame type = 0x%x\n",
1167 s_frame_type_op.s_ive_op.u4_error_code);
1168 codec_exit(ac_error);
1169 }
1170 }
1171
1172 /**
1173 *******************************************************************************
1174 * @brief configure qp
1175 *******************************************************************************
1176 */
set_qp(app_ctxt_t * ps_app_ctxt,UWORD32 u4_timestamp_low,UWORD32 u4_timestamp_high)1177 void set_qp(app_ctxt_t *ps_app_ctxt,
1178 UWORD32 u4_timestamp_low,
1179 UWORD32 u4_timestamp_high)
1180 {
1181 ih264e_ctl_set_qp_ip_t s_qp_ip;
1182 ih264e_ctl_set_qp_op_t s_qp_op;
1183 IV_STATUS_T status;
1184
1185 s_qp_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_qp_ip_t);
1186 s_qp_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL;
1187 s_qp_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_QP;
1188 s_qp_ip.s_ive_ip.u4_i_qp = ps_app_ctxt->u4_i_qp;
1189 s_qp_ip.s_ive_ip.u4_i_qp_max = ps_app_ctxt->u4_i_qp_max;
1190 s_qp_ip.s_ive_ip.u4_i_qp_min = ps_app_ctxt->u4_i_qp_min;
1191 s_qp_ip.s_ive_ip.u4_p_qp = ps_app_ctxt->u4_p_qp;
1192 s_qp_ip.s_ive_ip.u4_p_qp_max = ps_app_ctxt->u4_p_qp_max;
1193 s_qp_ip.s_ive_ip.u4_p_qp_min = ps_app_ctxt->u4_p_qp_min;
1194 s_qp_ip.s_ive_ip.u4_b_qp = ps_app_ctxt->u4_b_qp;
1195 s_qp_ip.s_ive_ip.u4_b_qp_max = ps_app_ctxt->u4_b_qp_max;
1196 s_qp_ip.s_ive_ip.u4_b_qp_min = ps_app_ctxt->u4_b_qp_min;
1197 s_qp_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low;
1198 s_qp_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high;
1199
1200 s_qp_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_qp_op_t);
1201
1202 status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_qp_ip, &s_qp_op);
1203 if(status != IV_SUCCESS)
1204 {
1205 CHAR ac_error[STRLENGTH];
1206 sprintf(ac_error, "Unable to set qp 0x%x\n",
1207 s_qp_op.s_ive_op.u4_error_code);
1208 codec_exit(ac_error);
1209 }
1210 }
1211
1212 /**
1213 *******************************************************************************
1214 * @brief configure encoder mode
1215 *******************************************************************************
1216 */
set_enc_mode(app_ctxt_t * ps_app_ctxt,UWORD32 u4_timestamp_low,UWORD32 u4_timestamp_high,IVE_ENC_MODE_T e_enc_mode)1217 void set_enc_mode(app_ctxt_t *ps_app_ctxt,
1218 UWORD32 u4_timestamp_low,
1219 UWORD32 u4_timestamp_high,
1220 IVE_ENC_MODE_T e_enc_mode)
1221 {
1222 ih264e_ctl_set_enc_mode_ip_t s_enc_mode_ip;
1223 ih264e_ctl_set_enc_mode_op_t s_enc_mode_op;
1224 IV_STATUS_T status;
1225
1226 s_enc_mode_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_enc_mode_ip_t);
1227 s_enc_mode_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL;
1228 s_enc_mode_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_ENC_MODE;
1229 s_enc_mode_ip.s_ive_ip.e_enc_mode = e_enc_mode;
1230 s_enc_mode_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low;
1231 s_enc_mode_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high;
1232
1233 s_enc_mode_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_enc_mode_op_t);
1234
1235 status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_enc_mode_ip,
1236 &s_enc_mode_op);
1237 if(status != IV_SUCCESS)
1238 {
1239 CHAR ac_error[STRLENGTH];
1240 sprintf(ac_error, "Unable to set in header encode mode = 0x%x\n",
1241 s_enc_mode_op.s_ive_op.u4_error_code);
1242 codec_exit(ac_error);
1243 }
1244 }
1245
1246 /**
1247 *******************************************************************************
1248 * @brief configure vbv params
1249 *******************************************************************************
1250 */
set_vbv_params(app_ctxt_t * ps_app_ctxt,UWORD32 u4_timestamp_low,UWORD32 u4_timestamp_high)1251 void set_vbv_params(app_ctxt_t *ps_app_ctxt,
1252 UWORD32 u4_timestamp_low,
1253 UWORD32 u4_timestamp_high)
1254 {
1255 ih264e_ctl_set_vbv_params_ip_t s_vbv_ip;
1256 ih264e_ctl_set_vbv_params_op_t s_vbv_op;
1257 IV_STATUS_T status;
1258
1259 s_vbv_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_vbv_params_ip_t);
1260 s_vbv_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL;
1261 s_vbv_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_VBV_PARAMS;
1262 s_vbv_ip.s_ive_ip.u4_vbv_buffer_delay = ps_app_ctxt->u4_vbv_buffer_delay;
1263 s_vbv_ip.s_ive_ip.u4_vbv_buf_size = ps_app_ctxt->u4_vbv_buf_size;
1264 s_vbv_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low;
1265 s_vbv_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high;
1266
1267 s_vbv_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_vbv_params_op_t);
1268
1269 status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_vbv_ip, &s_vbv_op);
1270 if(status != IV_SUCCESS)
1271 {
1272 CHAR ac_error[STRLENGTH];
1273 sprintf(ac_error, "Unable to set VBC params = 0x%x\n",
1274 s_vbv_op.s_ive_op.u4_error_code);
1275 codec_exit(ac_error);
1276 }
1277 }
1278
1279 /**
1280 *******************************************************************************
1281 * @brief configure air params
1282 *******************************************************************************
1283 */
set_air_params(app_ctxt_t * ps_app_ctxt,UWORD32 u4_timestamp_low,UWORD32 u4_timestamp_high)1284 void set_air_params(app_ctxt_t *ps_app_ctxt,
1285 UWORD32 u4_timestamp_low,
1286 UWORD32 u4_timestamp_high)
1287 {
1288 ih264e_ctl_set_air_params_ip_t s_air_ip;
1289 ih264e_ctl_set_air_params_op_t s_air_op;
1290 IV_STATUS_T status;
1291
1292 s_air_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_air_params_ip_t);
1293 s_air_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL;
1294 s_air_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_AIR_PARAMS;
1295 s_air_ip.s_ive_ip.e_air_mode = ps_app_ctxt->u4_air;
1296 s_air_ip.s_ive_ip.u4_air_refresh_period = ps_app_ctxt->u4_air_refresh_period;
1297 s_air_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low;
1298 s_air_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high;
1299
1300 s_air_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_air_params_op_t);
1301
1302 status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_air_ip, &s_air_op);
1303 if(status != IV_SUCCESS)
1304 {
1305 CHAR ac_error[STRLENGTH];
1306 sprintf(ac_error, "Unable to set air params = 0x%x\n",
1307 s_air_op.s_ive_op.u4_error_code);
1308 codec_exit(ac_error);
1309 }
1310 }
1311
1312 /**
1313 *******************************************************************************
1314 * @brief configure me params
1315 *******************************************************************************
1316 */
set_me_params(app_ctxt_t * ps_app_ctxt,UWORD32 u4_timestamp_low,UWORD32 u4_timestamp_high)1317 void set_me_params(app_ctxt_t *ps_app_ctxt,
1318 UWORD32 u4_timestamp_low,
1319 UWORD32 u4_timestamp_high)
1320 {
1321 ih264e_ctl_set_me_params_ip_t s_me_params_ip;
1322 ih264e_ctl_set_me_params_op_t s_me_params_op;
1323 IV_STATUS_T status;
1324
1325 s_me_params_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_me_params_ip_t);
1326 s_me_params_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL;
1327 s_me_params_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_ME_PARAMS;
1328 s_me_params_ip.s_ive_ip.u4_me_speed_preset = ps_app_ctxt->u4_me_speed;
1329 s_me_params_ip.s_ive_ip.u4_enable_hpel = ps_app_ctxt->u4_hpel;
1330 s_me_params_ip.s_ive_ip.u4_enable_qpel = ps_app_ctxt->u4_qpel;
1331 s_me_params_ip.s_ive_ip.u4_enable_fast_sad = ps_app_ctxt->u4_enable_fast_sad;
1332 s_me_params_ip.s_ive_ip.u4_enable_alt_ref = ps_app_ctxt->u4_enable_alt_ref;
1333 s_me_params_ip.s_ive_ip.u4_srch_rng_x = ps_app_ctxt->u4_srch_rng_x;
1334 s_me_params_ip.s_ive_ip.u4_srch_rng_y = ps_app_ctxt->u4_srch_rng_y;
1335 s_me_params_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low;
1336 s_me_params_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high;
1337
1338 s_me_params_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_me_params_op_t);
1339
1340 status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_me_params_ip,
1341 &s_me_params_op);
1342 if(status != IV_SUCCESS)
1343 {
1344 CHAR ac_error[STRLENGTH];
1345 sprintf(ac_error, "Unable to set me params = 0x%x\n",
1346 s_me_params_op.s_ive_op.u4_error_code);
1347 codec_exit(ac_error);
1348 }
1349 }
1350
1351 /**
1352 *******************************************************************************
1353 * @brief configure gop params
1354 *******************************************************************************
1355 */
set_gop_params(app_ctxt_t * ps_app_ctxt,UWORD32 u4_timestamp_low,UWORD32 u4_timestamp_high)1356 void set_gop_params(app_ctxt_t *ps_app_ctxt,
1357 UWORD32 u4_timestamp_low,
1358 UWORD32 u4_timestamp_high)
1359 {
1360 ih264e_ctl_set_gop_params_ip_t s_gop_params_ip;
1361 ih264e_ctl_set_gop_params_op_t s_gop_params_op;
1362 IV_STATUS_T status;
1363
1364 s_gop_params_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_gop_params_ip_t);
1365 s_gop_params_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL;
1366 s_gop_params_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_GOP_PARAMS;
1367 s_gop_params_ip.s_ive_ip.u4_i_frm_interval = ps_app_ctxt->u4_i_interval;
1368 s_gop_params_ip.s_ive_ip.u4_idr_frm_interval = ps_app_ctxt->u4_idr_interval;
1369 s_gop_params_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low;
1370 s_gop_params_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high;
1371
1372 s_gop_params_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_gop_params_op_t);
1373
1374 status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_gop_params_ip,
1375 &s_gop_params_op);
1376 if(status != IV_SUCCESS)
1377 {
1378 CHAR ac_error[STRLENGTH];
1379 sprintf(ac_error, "Unable to set GOP params = 0x%x\n",
1380 s_gop_params_op.s_ive_op.u4_error_code);
1381 codec_exit(ac_error);
1382 }
1383 }
1384
1385 /**
1386 *******************************************************************************
1387 * @brief configure profile params
1388 *******************************************************************************
1389 */
set_profile_params(app_ctxt_t * ps_app_ctxt,UWORD32 u4_timestamp_low,UWORD32 u4_timestamp_high)1390 void set_profile_params(app_ctxt_t *ps_app_ctxt,
1391 UWORD32 u4_timestamp_low,
1392 UWORD32 u4_timestamp_high)
1393 {
1394 ih264e_ctl_set_profile_params_ip_t s_profile_params_ip;
1395 ih264e_ctl_set_profile_params_op_t s_profile_params_op;
1396 IV_STATUS_T status;
1397
1398 s_profile_params_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_profile_params_ip_t);
1399 s_profile_params_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL;
1400 s_profile_params_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_PROFILE_PARAMS;
1401 s_profile_params_ip.s_ive_ip.e_profile = ps_app_ctxt->e_profile;
1402 s_profile_params_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high;
1403 s_profile_params_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low;
1404 s_profile_params_ip.s_ive_ip.u4_entropy_coding_mode = ps_app_ctxt->u4_entropy_coding_mode;
1405
1406 s_profile_params_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_profile_params_op_t);
1407
1408 status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_profile_params_ip,
1409 &s_profile_params_op);
1410 if(status != IV_SUCCESS)
1411 {
1412 CHAR ac_error[STRLENGTH];
1413 sprintf(ac_error, "Unable to set profile params = 0x%x\n",
1414 s_profile_params_op.s_ive_op.u4_error_code);
1415 codec_exit(ac_error);
1416 }
1417 }
1418
1419 /**
1420 *******************************************************************************
1421 * @brief configure deblock params
1422 *******************************************************************************
1423 */
set_deblock_params(app_ctxt_t * ps_app_ctxt,UWORD32 u4_timestamp_low,UWORD32 u4_timestamp_high)1424 void set_deblock_params(app_ctxt_t *ps_app_ctxt,
1425 UWORD32 u4_timestamp_low,
1426 UWORD32 u4_timestamp_high)
1427 {
1428 ih264e_ctl_set_deblock_params_ip_t s_deblock_params_ip;
1429 ih264e_ctl_set_deblock_params_op_t s_deblock_params_op;
1430 IV_STATUS_T status;
1431
1432 s_deblock_params_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_deblock_params_ip_t);
1433 s_deblock_params_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL;
1434 s_deblock_params_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_DEBLOCK_PARAMS;
1435 s_deblock_params_ip.s_ive_ip.u4_disable_deblock_level = ps_app_ctxt->u4_disable_deblk_level;
1436 s_deblock_params_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high;
1437 s_deblock_params_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low;
1438
1439 s_deblock_params_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_deblock_params_op_t);
1440
1441 status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_deblock_params_ip,
1442 &s_deblock_params_op);
1443 if(status != IV_SUCCESS)
1444 {
1445 CHAR ac_error[STRLENGTH];
1446 sprintf(ac_error, "Unable to enable/disable deblock params = 0x%x\n",
1447 s_deblock_params_op.s_ive_op.u4_error_code);
1448 codec_exit(ac_error);
1449 }
1450 }
1451
1452 /**
1453 *******************************************************************************
1454 * @brief configure VUI params
1455 *******************************************************************************
1456 */
set_vui_params(app_ctxt_t * ps_app_ctxt)1457 void set_vui_params(app_ctxt_t *ps_app_ctxt)
1458 {
1459 ih264e_vui_ip_t s_vui_params_ip;
1460 ih264e_vui_op_t s_vui_params_op;
1461 IV_STATUS_T status;
1462
1463 s_vui_params_ip.u4_size = sizeof(ih264e_vui_ip_t);
1464 s_vui_params_ip.e_cmd = IVE_CMD_VIDEO_CTL;
1465 s_vui_params_ip.e_sub_cmd = IVE_CMD_CTL_SET_VUI_PARAMS;
1466 s_vui_params_ip.u1_aspect_ratio_info_present_flag = 0;
1467 s_vui_params_ip.u1_aspect_ratio_idc = 0;
1468 s_vui_params_ip.u2_sar_width = 0;
1469 s_vui_params_ip.u2_sar_height = 0;
1470 s_vui_params_ip.u1_overscan_info_present_flag = 0;
1471 s_vui_params_ip.u1_overscan_appropriate_flag = 0;
1472 s_vui_params_ip.u1_video_signal_type_present_flag = 1;
1473 s_vui_params_ip.u1_video_format = 0;
1474 s_vui_params_ip.u1_video_full_range_flag = 0;
1475 s_vui_params_ip.u1_colour_description_present_flag = 1;
1476 s_vui_params_ip.u1_colour_primaries = 2;
1477 s_vui_params_ip.u1_transfer_characteristics = 2;
1478 s_vui_params_ip.u1_matrix_coefficients = 2;
1479 s_vui_params_ip.u1_chroma_loc_info_present_flag = 0;
1480 s_vui_params_ip.u1_chroma_sample_loc_type_top_field = 0;
1481 s_vui_params_ip.u1_chroma_sample_loc_type_bottom_field = 0;
1482 s_vui_params_ip.u1_vui_timing_info_present_flag = 0;
1483 s_vui_params_ip.u4_vui_num_units_in_tick = 0;
1484 s_vui_params_ip.u4_vui_time_scale = ps_app_ctxt->u4_tgt_frame_rate * 2000;
1485 s_vui_params_ip.u1_fixed_frame_rate_flag = 0;
1486 s_vui_params_ip.u1_nal_hrd_parameters_present_flag = 0;
1487 s_vui_params_ip.u1_vcl_hrd_parameters_present_flag = 0;
1488 s_vui_params_ip.u1_low_delay_hrd_flag = 0;
1489 s_vui_params_ip.u1_pic_struct_present_flag = 0;
1490 s_vui_params_ip.u1_bitstream_restriction_flag = 0;
1491 s_vui_params_ip.u1_motion_vectors_over_pic_boundaries_flag = 0;
1492 s_vui_params_ip.u1_max_bytes_per_pic_denom = 0;
1493 s_vui_params_ip.u1_max_bits_per_mb_denom = 0;
1494 s_vui_params_ip.u1_log2_max_mv_length_horizontal = 0;
1495 s_vui_params_ip.u1_log2_max_mv_length_vertical = 0;
1496 s_vui_params_ip.u1_num_reorder_frames = 0;
1497 s_vui_params_ip.u1_max_dec_frame_buffering = 0;
1498
1499 s_vui_params_op.u4_size = sizeof(ih264e_vui_op_t);
1500
1501 status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_vui_params_ip,
1502 &s_vui_params_op);
1503 if(status != IV_SUCCESS)
1504 {
1505 CHAR ac_error[STRLENGTH];
1506 sprintf(ac_error, "Unable to set vui params = 0x%x\n",
1507 s_vui_params_op.u4_error_code);
1508 codec_exit(ac_error);
1509 }
1510 return;
1511 }
1512
set_sei_mdcv_params(app_ctxt_t * ps_app_ctxt,UWORD32 u4_timestamp_low,UWORD32 u4_timestamp_high)1513 void set_sei_mdcv_params(app_ctxt_t *ps_app_ctxt,
1514 UWORD32 u4_timestamp_low,
1515 UWORD32 u4_timestamp_high)
1516 {
1517 WORD32 i4_count;
1518 IV_STATUS_T status;
1519
1520 ih264e_ctl_set_sei_mdcv_params_ip_t s_sei_mdcv_params_ip;
1521 ih264e_ctl_set_sei_mdcv_params_op_t s_sei_mdcv_params_op;
1522
1523 s_sei_mdcv_params_ip.e_cmd = IVE_CMD_VIDEO_CTL;
1524 s_sei_mdcv_params_ip.e_sub_cmd = IVE_CMD_CTL_SET_SEI_MDCV_PARAMS;
1525
1526 s_sei_mdcv_params_ip.u1_sei_mdcv_params_present_flag =
1527 (UWORD8)ps_app_ctxt->u4_sei_mdcv_params_present_flag;
1528
1529 for(i4_count = 0; i4_count < NUM_SEI_MDCV_PRIMARIES; i4_count++)
1530 {
1531 s_sei_mdcv_params_ip.au2_display_primaries_x[i4_count] =
1532 (UWORD16)ps_app_ctxt->au4_display_primaries_x[i4_count];
1533 s_sei_mdcv_params_ip.au2_display_primaries_y[i4_count] =
1534 (UWORD16)ps_app_ctxt->au4_display_primaries_y[i4_count];
1535 }
1536
1537 s_sei_mdcv_params_ip.u2_white_point_x = (UWORD16)ps_app_ctxt->u4_white_point_x;
1538 s_sei_mdcv_params_ip.u2_white_point_y = (UWORD16)ps_app_ctxt->u4_white_point_y;
1539 s_sei_mdcv_params_ip.u4_max_display_mastering_luminance =
1540 ps_app_ctxt->u4_max_display_mastering_luminance;
1541 s_sei_mdcv_params_ip.u4_min_display_mastering_luminance =
1542 ps_app_ctxt->u4_min_display_mastering_luminance;
1543
1544 s_sei_mdcv_params_ip.u4_timestamp_high = u4_timestamp_high;
1545 s_sei_mdcv_params_ip.u4_timestamp_low = u4_timestamp_low;
1546
1547 s_sei_mdcv_params_ip.u4_size = sizeof(ih264e_ctl_set_sei_mdcv_params_ip_t);
1548 s_sei_mdcv_params_op.u4_size = sizeof(ih264e_ctl_set_sei_mdcv_params_op_t);
1549
1550 if((ps_app_ctxt->s_sei_mdcv_params.au2_display_primaries_x[0] !=
1551 s_sei_mdcv_params_ip.au2_display_primaries_x[0]) ||
1552 (ps_app_ctxt->s_sei_mdcv_params.au2_display_primaries_x[1] !=
1553 s_sei_mdcv_params_ip.au2_display_primaries_x[1]) ||
1554 (ps_app_ctxt->s_sei_mdcv_params.au2_display_primaries_x[2] !=
1555 s_sei_mdcv_params_ip.au2_display_primaries_x[2]) ||
1556 (ps_app_ctxt->s_sei_mdcv_params.au2_display_primaries_y[0] !=
1557 s_sei_mdcv_params_ip.au2_display_primaries_y[0]) ||
1558 (ps_app_ctxt->s_sei_mdcv_params.au2_display_primaries_y[1] !=
1559 s_sei_mdcv_params_ip.au2_display_primaries_y[1]) ||
1560 (ps_app_ctxt->s_sei_mdcv_params.au2_display_primaries_y[2] !=
1561 s_sei_mdcv_params_ip.au2_display_primaries_y[2]) ||
1562 (ps_app_ctxt->s_sei_mdcv_params.u2_white_point_x !=
1563 s_sei_mdcv_params_ip.u2_white_point_x) ||
1564 (ps_app_ctxt->s_sei_mdcv_params.u2_white_point_y !=
1565 s_sei_mdcv_params_ip.u2_white_point_x) ||
1566 (ps_app_ctxt->s_sei_mdcv_params.u4_max_display_mastering_luminance !=
1567 s_sei_mdcv_params_ip.u4_max_display_mastering_luminance) ||
1568 (ps_app_ctxt->s_sei_mdcv_params.u4_min_display_mastering_luminance !=
1569 s_sei_mdcv_params_ip.u4_min_display_mastering_luminance))
1570 {
1571 status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_sei_mdcv_params_ip,
1572 &s_sei_mdcv_params_op);
1573 if(status != IV_SUCCESS)
1574 {
1575 printf("Unable to set sei mdcv params = 0x%x\n",
1576 s_sei_mdcv_params_op.u4_error_code);
1577 }
1578 ps_app_ctxt->s_sei_mdcv_params = s_sei_mdcv_params_ip;
1579 }
1580 return;
1581 }
1582
set_sei_cll_params(app_ctxt_t * ps_app_ctxt,UWORD32 u4_timestamp_low,UWORD32 u4_timestamp_high)1583 void set_sei_cll_params(app_ctxt_t *ps_app_ctxt,
1584 UWORD32 u4_timestamp_low,
1585 UWORD32 u4_timestamp_high)
1586 {
1587 IV_STATUS_T status;
1588
1589 ih264e_ctl_set_sei_cll_params_ip_t s_sei_cll_params_ip;
1590 ih264e_ctl_set_sei_cll_params_op_t s_sei_cll_params_op;
1591
1592 s_sei_cll_params_ip.e_cmd = IVE_CMD_VIDEO_CTL;
1593 s_sei_cll_params_ip.e_sub_cmd = IVE_CMD_CTL_SET_SEI_CLL_PARAMS;
1594
1595 s_sei_cll_params_ip.u1_sei_cll_params_present_flag =
1596 (UWORD8)ps_app_ctxt->u4_sei_cll_params_present_flag;
1597
1598 s_sei_cll_params_ip.u2_max_content_light_level =
1599 (UWORD16)ps_app_ctxt->u4_max_content_light_level;
1600 s_sei_cll_params_ip.u2_max_pic_average_light_level =
1601 (UWORD16)ps_app_ctxt->u4_max_pic_average_light_level;
1602
1603 s_sei_cll_params_ip.u4_timestamp_high = u4_timestamp_high;
1604 s_sei_cll_params_ip.u4_timestamp_low = u4_timestamp_low;
1605
1606 s_sei_cll_params_ip.u4_size = sizeof(ih264e_ctl_set_sei_cll_params_ip_t);
1607 s_sei_cll_params_op.u4_size = sizeof(ih264e_ctl_set_sei_cll_params_op_t);
1608
1609 if((ps_app_ctxt->s_sei_cll_params.u2_max_content_light_level !=
1610 s_sei_cll_params_ip.u2_max_content_light_level) ||
1611 (ps_app_ctxt->s_sei_cll_params.u2_max_pic_average_light_level !=
1612 s_sei_cll_params_ip.u2_max_pic_average_light_level))
1613 {
1614 status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_sei_cll_params_ip,
1615 &s_sei_cll_params_op);
1616 if(status != IV_SUCCESS)
1617 {
1618 printf("Unable to set sei cll params = 0x%x\n",
1619 s_sei_cll_params_op.u4_error_code);
1620 }
1621 ps_app_ctxt->s_sei_cll_params = s_sei_cll_params_ip;
1622 }
1623 return;
1624 }
1625
set_sei_ave_params(app_ctxt_t * ps_app_ctxt,UWORD32 u4_timestamp_low,UWORD32 u4_timestamp_high)1626 void set_sei_ave_params(app_ctxt_t *ps_app_ctxt,
1627 UWORD32 u4_timestamp_low,
1628 UWORD32 u4_timestamp_high)
1629 {
1630 IV_STATUS_T status;
1631
1632 ih264e_ctl_set_sei_ave_params_ip_t s_sei_ave_params_ip;
1633 ih264e_ctl_set_sei_ave_params_op_t s_sei_ave_params_op;
1634
1635 s_sei_ave_params_ip.e_cmd = IVE_CMD_VIDEO_CTL;
1636 s_sei_ave_params_ip.e_sub_cmd = IVE_CMD_CTL_SET_SEI_AVE_PARAMS;
1637
1638 s_sei_ave_params_ip.u1_sei_ave_params_present_flag =
1639 (UWORD8)ps_app_ctxt->u4_sei_ave_params_present_flag;
1640
1641 s_sei_ave_params_ip.u4_ambient_illuminance = ps_app_ctxt->u4_ambient_illuminance;
1642 s_sei_ave_params_ip.u2_ambient_light_x = (UWORD16)ps_app_ctxt->u4_ambient_light_x;
1643 s_sei_ave_params_ip.u2_ambient_light_y = (UWORD16)ps_app_ctxt->u4_ambient_light_y;
1644
1645 s_sei_ave_params_ip.u4_timestamp_high = u4_timestamp_high;
1646 s_sei_ave_params_ip.u4_timestamp_low = u4_timestamp_low;
1647
1648 s_sei_ave_params_ip.u4_size = sizeof(ih264e_ctl_set_sei_ave_params_ip_t);
1649 s_sei_ave_params_op.u4_size = sizeof(ih264e_ctl_set_sei_ave_params_op_t);
1650
1651 if((ps_app_ctxt->s_sei_ave_params.u4_ambient_illuminance !=
1652 s_sei_ave_params_ip.u4_ambient_illuminance) ||
1653 (ps_app_ctxt->s_sei_ave_params.u2_ambient_light_x !=
1654 s_sei_ave_params_ip.u2_ambient_light_x) ||
1655 (ps_app_ctxt->s_sei_ave_params.u2_ambient_light_y !=
1656 s_sei_ave_params_ip.u2_ambient_light_y))
1657 {
1658 status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_sei_ave_params_ip,
1659 &s_sei_ave_params_op);
1660 if(status != IV_SUCCESS)
1661 {
1662 printf("Unable to set sei ave params = 0x%x\n",
1663 s_sei_ave_params_op.u4_error_code);
1664 }
1665 ps_app_ctxt->s_sei_ave_params = s_sei_ave_params_ip;
1666 }
1667 return;
1668 }
1669
set_sei_ccv_params(app_ctxt_t * ps_app_ctxt,UWORD32 u4_timestamp_low,UWORD32 u4_timestamp_high)1670 void set_sei_ccv_params(app_ctxt_t *ps_app_ctxt,
1671 UWORD32 u4_timestamp_low,
1672 UWORD32 u4_timestamp_high)
1673 {
1674 WORD32 i4_count;
1675 IV_STATUS_T status;
1676
1677 ih264e_ctl_set_sei_ccv_params_ip_t s_sei_ccv_params_ip;
1678 ih264e_ctl_set_sei_ccv_params_op_t s_sei_ccv_params_op;
1679
1680 s_sei_ccv_params_ip.e_cmd = IVE_CMD_VIDEO_CTL;
1681 s_sei_ccv_params_ip.e_sub_cmd = IVE_CMD_CTL_SET_SEI_CCV_PARAMS;
1682
1683 s_sei_ccv_params_ip.u1_sei_ccv_params_present_flag =
1684 (UWORD8)ps_app_ctxt->u4_sei_ccv_params_present_flag;
1685
1686 s_sei_ccv_params_ip.u1_ccv_cancel_flag = (UWORD8)ps_app_ctxt->u4_ccv_cancel_flag;
1687 s_sei_ccv_params_ip.u1_ccv_persistence_flag =
1688 (UWORD8)ps_app_ctxt->u4_ccv_persistence_flag;
1689 s_sei_ccv_params_ip.u1_ccv_primaries_present_flag =
1690 (UWORD8)ps_app_ctxt->u4_ccv_primaries_present_flag;
1691 s_sei_ccv_params_ip.u1_ccv_min_luminance_value_present_flag =
1692 (UWORD8)ps_app_ctxt->u4_ccv_min_luminance_value_present_flag;
1693 s_sei_ccv_params_ip.u1_ccv_max_luminance_value_present_flag =
1694 (UWORD8)ps_app_ctxt->u4_ccv_max_luminance_value_present_flag;
1695 s_sei_ccv_params_ip.u1_ccv_avg_luminance_value_present_flag =
1696 (UWORD8)ps_app_ctxt->u4_ccv_avg_luminance_value_present_flag;
1697 s_sei_ccv_params_ip.u1_ccv_reserved_zero_2bits =
1698 (UWORD8)ps_app_ctxt->u4_ccv_reserved_zero_2bits;
1699
1700 for(i4_count = 0; i4_count < NUM_SEI_CCV_PRIMARIES; i4_count++)
1701 {
1702 s_sei_ccv_params_ip.ai4_ccv_primaries_x[i4_count] =
1703 ps_app_ctxt->ai4_ccv_primaries_x[i4_count];
1704 s_sei_ccv_params_ip.ai4_ccv_primaries_y[i4_count] =
1705 ps_app_ctxt->ai4_ccv_primaries_y[i4_count];
1706 }
1707
1708 s_sei_ccv_params_ip.u4_ccv_min_luminance_value = ps_app_ctxt->u4_ccv_min_luminance_value;
1709 s_sei_ccv_params_ip.u4_ccv_max_luminance_value = ps_app_ctxt->u4_ccv_max_luminance_value;
1710 s_sei_ccv_params_ip.u4_ccv_avg_luminance_value = ps_app_ctxt->u4_ccv_avg_luminance_value;
1711
1712 s_sei_ccv_params_ip.u4_timestamp_high = u4_timestamp_high;
1713 s_sei_ccv_params_ip.u4_timestamp_low = u4_timestamp_low;
1714
1715 s_sei_ccv_params_ip.u4_size = sizeof(ih264e_ctl_set_sei_ccv_params_ip_t);
1716 s_sei_ccv_params_op.u4_size = sizeof(ih264e_ctl_set_sei_ccv_params_op_t);
1717
1718 status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_sei_ccv_params_ip,
1719 &s_sei_ccv_params_op);
1720 if(status != IV_SUCCESS)
1721 {
1722 printf("Unable to set sei ccv params = 0x%x\n",
1723 s_sei_ccv_params_op.u4_error_code);
1724 }
1725 return;
1726 }
1727
set_sei_sii_params(app_ctxt_t * ps_app_ctxt,UWORD32 u4_timestamp_low,UWORD32 u4_timestamp_high)1728 void set_sei_sii_params(app_ctxt_t *ps_app_ctxt, UWORD32 u4_timestamp_low,
1729 UWORD32 u4_timestamp_high)
1730 {
1731 IV_STATUS_T status;
1732 int i;
1733 bool au4_sub_layer_num_units_in_shutter_interval_flag = 0;
1734
1735 ih264e_ctl_set_sei_sii_params_ip_t s_sei_sii_params_ip = {0};
1736 ih264e_ctl_set_sei_sii_params_op_t s_sei_sii_params_op = {0};
1737
1738 s_sei_sii_params_ip.e_cmd = IVE_CMD_VIDEO_CTL;
1739 s_sei_sii_params_ip.e_sub_cmd = IVE_CMD_CTL_SET_SEI_SII_PARAMS;
1740
1741 s_sei_sii_params_ip.u4_sii_sub_layer_idx = ps_app_ctxt->u4_sii_sub_layer_idx;
1742
1743 if(0 == s_sei_sii_params_ip.u4_sii_sub_layer_idx)
1744 {
1745 s_sei_sii_params_ip.u1_shutter_interval_info_present_flag =
1746 (UWORD8) ps_app_ctxt->u4_shutter_interval_info_present_flag;
1747
1748 if(1 == s_sei_sii_params_ip.u1_shutter_interval_info_present_flag)
1749 {
1750 s_sei_sii_params_ip.u4_sii_time_scale = ps_app_ctxt->u4_sii_time_scale;
1751 s_sei_sii_params_ip.u1_fixed_shutter_interval_within_cvs_flag =
1752 (UWORD8) ps_app_ctxt->u4_fixed_shutter_interval_within_cvs_flag;
1753
1754 if(1 == s_sei_sii_params_ip.u1_fixed_shutter_interval_within_cvs_flag)
1755 {
1756 s_sei_sii_params_ip.u4_sii_num_units_in_shutter_interval =
1757 ps_app_ctxt->u4_sii_num_units_in_shutter_interval;
1758 }
1759 else
1760 {
1761 s_sei_sii_params_ip.u1_sii_max_sub_layers_minus1 =
1762 (UWORD8) ps_app_ctxt->u4_sii_max_sub_layers_minus1;
1763
1764 for(i = 0; i <= s_sei_sii_params_ip.u1_sii_max_sub_layers_minus1; i++)
1765 {
1766 s_sei_sii_params_ip.au4_sub_layer_num_units_in_shutter_interval[i] =
1767 ps_app_ctxt->au4_sub_layer_num_units_in_shutter_interval[i];
1768 }
1769 }
1770 }
1771 }
1772
1773 s_sei_sii_params_ip.u4_timestamp_high = u4_timestamp_high;
1774 s_sei_sii_params_ip.u4_timestamp_low = u4_timestamp_low;
1775
1776 s_sei_sii_params_ip.u4_size = sizeof(ih264e_ctl_set_sei_sii_params_ip_t);
1777 s_sei_sii_params_op.u4_size = sizeof(ih264e_ctl_set_sei_sii_params_op_t);
1778
1779 for(i = 0; i <= s_sei_sii_params_ip.u1_sii_max_sub_layers_minus1; i++)
1780 {
1781 au4_sub_layer_num_units_in_shutter_interval_flag =
1782 (au4_sub_layer_num_units_in_shutter_interval_flag ||
1783 (ps_app_ctxt->s_sei_sii_params.au4_sub_layer_num_units_in_shutter_interval[i] !=
1784 s_sei_sii_params_ip.au4_sub_layer_num_units_in_shutter_interval[i]));
1785 }
1786
1787 if((ps_app_ctxt->s_sei_sii_params.u4_sii_sub_layer_idx !=
1788 s_sei_sii_params_ip.u4_sii_sub_layer_idx) ||
1789 (ps_app_ctxt->s_sei_sii_params.u1_shutter_interval_info_present_flag !=
1790 s_sei_sii_params_ip.u1_shutter_interval_info_present_flag) ||
1791 (ps_app_ctxt->s_sei_sii_params.u4_sii_time_scale != s_sei_sii_params_ip.u4_sii_time_scale) ||
1792 (ps_app_ctxt->s_sei_sii_params.u1_fixed_shutter_interval_within_cvs_flag !=
1793 s_sei_sii_params_ip.u1_fixed_shutter_interval_within_cvs_flag) ||
1794 (ps_app_ctxt->s_sei_sii_params.u4_sii_num_units_in_shutter_interval !=
1795 s_sei_sii_params_ip.u4_sii_num_units_in_shutter_interval) ||
1796 (ps_app_ctxt->s_sei_sii_params.u1_sii_max_sub_layers_minus1 !=
1797 s_sei_sii_params_ip.u1_sii_max_sub_layers_minus1) ||
1798 au4_sub_layer_num_units_in_shutter_interval_flag)
1799 {
1800 status =
1801 ih264e_api_function(ps_app_ctxt->ps_enc, &s_sei_sii_params_ip, &s_sei_sii_params_op);
1802 if(status != IV_SUCCESS)
1803 {
1804 printf("Unable to set sei sii params = 0x%x\n", s_sei_sii_params_op.u4_error_code);
1805 }
1806 ps_app_ctxt->s_sei_sii_params = s_sei_sii_params_ip;
1807 }
1808 return;
1809 }
1810
1811 /**
1812 *******************************************************************************
1813 * @brief encode input
1814 *******************************************************************************
1815 */
synchronous_encode(iv_obj_t * ps_enc,app_ctxt_t * ps_app_ctxt)1816 void synchronous_encode(iv_obj_t *ps_enc, app_ctxt_t *ps_app_ctxt)
1817 {
1818 #define PEAK_WINDOW_SIZE 8
1819 ih264e_video_encode_ip_t ih264e_video_encode_ip = {0};
1820 ih264e_video_encode_op_t ih264e_video_encode_op = {0};
1821
1822 ive_video_encode_ip_t *ps_video_encode_ip = &ih264e_video_encode_ip.s_ive_ip;
1823 ive_video_encode_op_t *ps_video_encode_op = &ih264e_video_encode_op.s_ive_op;
1824
1825 iv_raw_buf_t *ps_inp_raw_buf = &ps_video_encode_ip->s_inp_buf;
1826
1827 IV_STATUS_T status = IV_SUCCESS;
1828
1829 WORD32 i, is_last = 0, buff_size = 0, num_bytes = 0;
1830 UWORD32 u4_total_time = 0;
1831 UWORD8 *pu1_buf = NULL;
1832 UWORD32 u4_timestamp_low = 0, u4_timestamp_high = 0;
1833 void *pv_mb_info = NULL, *pv_pic_info = NULL;
1834
1835 TIMER curtime;
1836 #ifdef WINDOWS_TIMER
1837 TIMER frequency;
1838 #endif
1839 WORD32 peak_window[PEAK_WINDOW_SIZE] = {0};
1840 WORD32 peak_window_idx = 0;
1841 WORD32 peak_avg_max = 0, timetaken = 0;
1842 iv_raw_buf_t s_inp_buf, s_recon_buf;
1843 CHAR ac_error[STRLENGTH];
1844 WORD32 end_of_frames = 0;
1845 WORD32 i4_inp_done = 0;
1846
1847 /* Allocate I/O Buffers */
1848 allocate_input(ps_app_ctxt);
1849 allocate_output(ps_app_ctxt);
1850 allocate_recon(ps_app_ctxt);
1851
1852 /* init psnr ctxt */
1853 init_psnr(ps_app_ctxt);
1854
1855 /* open file pointers */
1856 ps_app_ctxt->fp_ip = fopen(ps_app_ctxt->ac_ip_fname, "rb");
1857 if(NULL == ps_app_ctxt->fp_ip)
1858 {
1859 sprintf(ac_error, "Unable to open input file for reading: %s",
1860 ps_app_ctxt->ac_ip_fname);
1861 invalid_argument_exit(ac_error);
1862 }
1863
1864 ps_app_ctxt->fp_op = fopen(ps_app_ctxt->ac_op_fname, "wb");
1865 if(NULL == ps_app_ctxt->fp_op)
1866 {
1867 sprintf(ac_error, "Unable to open output file for writing: %s",
1868 ps_app_ctxt->ac_op_fname);
1869 invalid_argument_exit(ac_error);
1870 }
1871
1872 if(1 == ps_app_ctxt->u4_recon_enable)
1873 {
1874 ps_app_ctxt->fp_recon = fopen(ps_app_ctxt->ac_recon_fname, "wb");
1875 if(NULL == ps_app_ctxt->fp_recon)
1876 {
1877 sprintf(ac_error, "Unable to open recon file for writing: %s",
1878 ps_app_ctxt->ac_recon_fname);
1879 invalid_argument_exit(ac_error);
1880 }
1881 }
1882
1883 if(1 == ps_app_ctxt->u4_chksum_enable)
1884 {
1885 ps_app_ctxt->fp_chksum = fopen(ps_app_ctxt->ac_chksum_fname, "wb");
1886 if(NULL == ps_app_ctxt->fp_chksum)
1887 {
1888 sprintf(ac_error, "Unable to open checksum file for writing: %s",
1889 ps_app_ctxt->ac_chksum_fname);
1890 invalid_argument_exit(ac_error);
1891 }
1892 }
1893
1894 /*
1895 * If PSNR is enabled, open input file again and hold a different file pointer
1896 * This makes it easy to compute PSNR without adding dependency between
1897 * input and recon threads
1898 */
1899 if(1 == ps_app_ctxt->u4_psnr_enable)
1900 {
1901 ps_app_ctxt->fp_psnr_ip = fopen(ps_app_ctxt->ac_ip_fname, "rb");
1902 if(NULL == ps_app_ctxt->fp_psnr_ip)
1903 {
1904 sprintf(ac_error, "Unable to open input file for reading: %s",
1905 ps_app_ctxt->ac_ip_fname);
1906 invalid_argument_exit(ac_error);
1907 }
1908 }
1909
1910 if(0 != ps_app_ctxt->u4_mb_info_type)
1911 {
1912 ps_app_ctxt->fp_mb_info = fopen(ps_app_ctxt->ac_mb_info_fname, "rb");
1913 if(NULL == ps_app_ctxt->fp_mb_info)
1914 {
1915 sprintf(ac_error, "Unable to open MB info file for reading: %s",
1916 ps_app_ctxt->ac_mb_info_fname);
1917 invalid_argument_exit(ac_error);
1918 }
1919 }
1920
1921 if(ps_app_ctxt->u4_pic_info_type)
1922 {
1923 ps_app_ctxt->fp_pic_info = fopen(ps_app_ctxt->ac_pic_info_fname, "rb");
1924 if(NULL == ps_app_ctxt->fp_pic_info)
1925 {
1926 sprintf(ac_error, "Unable to open Pic info file for reading: %s",
1927 ps_app_ctxt->ac_pic_info_fname);
1928 invalid_argument_exit(ac_error);
1929 }
1930 }
1931
1932 /*****************************************************************************/
1933 /* Video control Set in Encode header mode */
1934 /*****************************************************************************/
1935 set_enc_mode(ps_app_ctxt, -1, -1, IVE_ENC_MODE_HEADER);
1936
1937 // Encode header
1938 memset(&ih264e_video_encode_ip, 0, sizeof(ih264e_video_encode_ip));
1939 memset(&ih264e_video_encode_op, 0, sizeof(ih264e_video_encode_op));
1940
1941 ps_video_encode_ip->u4_size = sizeof(ih264e_video_encode_ip_t);
1942 ps_video_encode_op->u4_size = sizeof(ih264e_video_encode_op_t);
1943
1944 ps_inp_raw_buf->apv_bufs[0] = NULL;
1945 ps_inp_raw_buf->apv_bufs[1] = NULL;
1946 ps_inp_raw_buf->apv_bufs[2] = NULL;
1947
1948 ps_video_encode_ip->e_cmd = IVE_CMD_VIDEO_ENCODE;
1949 ps_video_encode_ip->pv_bufs = NULL;
1950 ps_video_encode_ip->pv_mb_info = NULL;
1951 ps_video_encode_ip->pv_pic_info = NULL;
1952 ps_video_encode_ip->u4_pic_info_type = ps_app_ctxt->u4_pic_info_type;
1953 ps_video_encode_ip->u4_is_last = 0;
1954 ps_video_encode_ip->u4_mb_info_type = ps_app_ctxt->u4_mb_info_type;
1955 ps_video_encode_ip->u4_pic_info_type = ps_app_ctxt->u4_pic_info_type;
1956 ps_video_encode_ip->s_out_buf.pv_buf = ps_app_ctxt->as_output_buf[0].pu1_buf;
1957 ps_video_encode_ip->s_out_buf.u4_bytes = 0;
1958 ps_video_encode_ip->s_out_buf.u4_bufsize = ps_app_ctxt->as_output_buf[0].u4_buf_size;
1959 ps_video_encode_ip->u4_timestamp_high = 0;
1960 ps_video_encode_ip->u4_timestamp_low = 0;
1961
1962 status = ih264e_api_function(ps_enc, &ih264e_video_encode_ip, &ih264e_video_encode_op);
1963 if(IV_SUCCESS != status)
1964 {
1965 printf("Encode Header failed = 0x%x\n", ih264e_video_encode_op.s_ive_op.u4_error_code);
1966 return;
1967 }
1968
1969 if(1 == ps_video_encode_op->output_present)
1970 {
1971 status = write_output(ps_app_ctxt->fp_op, (UWORD8 *) ps_video_encode_op->s_out_buf.pv_buf,
1972 ps_video_encode_op->s_out_buf.u4_bytes);
1973 if(IV_SUCCESS != status)
1974 {
1975 printf("Error: Unable to write to output file\n");
1976 return;
1977 }
1978 }
1979
1980 /*****************************************************************************/
1981 /* Video control Set in Encode picture mode */
1982 /*****************************************************************************/
1983 set_enc_mode(ps_app_ctxt, -1, -1, IVE_ENC_MODE_PICTURE);
1984
1985 GETTIME(&ps_app_ctxt->enc_start_time);
1986 ps_app_ctxt->enc_last_time = ps_app_ctxt->enc_start_time;
1987
1988 while(1)
1989 {
1990 IV_PICTURE_CODING_TYPE_T e_frame_type;
1991 WORD32 i4_count;
1992
1993 /* Default sei params values*/
1994 ps_app_ctxt->u4_sei_mdcv_params_present_flag = 1;
1995 if(1 == ps_app_ctxt->u4_sei_mdcv_params_present_flag)
1996 {
1997 for(i4_count = 0; i4_count < NUM_SEI_MDCV_PRIMARIES; i4_count++)
1998 {
1999 ps_app_ctxt->au4_display_primaries_x[i4_count] = 0;
2000 ps_app_ctxt->au4_display_primaries_y[i4_count] = 0;
2001 }
2002 ps_app_ctxt->u4_white_point_x = 0;
2003 ps_app_ctxt->u4_white_point_y = 0;
2004 ps_app_ctxt->u4_max_display_mastering_luminance = DEFAULT_MAX_DISPLAY_MASTERING_LUMINANCE;
2005 ps_app_ctxt->u4_min_display_mastering_luminance = DEFAULT_MIN_DISPLAY_MASTERING_LUMINANCE;
2006 set_sei_mdcv_params(ps_app_ctxt, u4_timestamp_low, u4_timestamp_high);
2007 }
2008
2009 ps_app_ctxt->u4_sei_cll_params_present_flag = 1;
2010 if(1 == ps_app_ctxt->u4_sei_cll_params_present_flag)
2011 {
2012 ps_app_ctxt->u4_max_content_light_level = 0;
2013 ps_app_ctxt->u4_max_pic_average_light_level = 0;
2014 set_sei_cll_params(ps_app_ctxt, u4_timestamp_low, u4_timestamp_high);
2015 }
2016
2017 ps_app_ctxt->u4_sei_ave_params_present_flag = 1;
2018 if(1 == ps_app_ctxt->u4_sei_ave_params_present_flag)
2019 {
2020 ps_app_ctxt->u4_ambient_illuminance = 1;
2021 ps_app_ctxt->u4_ambient_light_x = 0;
2022 ps_app_ctxt->u4_ambient_light_y = 0;
2023 set_sei_ave_params(ps_app_ctxt, u4_timestamp_low, u4_timestamp_high);
2024 }
2025
2026 ps_app_ctxt->u4_sei_ccv_params_present_flag = 1;
2027 if(1 == ps_app_ctxt->u4_sei_ccv_params_present_flag)
2028 {
2029 ps_app_ctxt->u4_ccv_cancel_flag = 0;
2030 ps_app_ctxt->u4_ccv_persistence_flag = 1;
2031 ps_app_ctxt->u4_ccv_primaries_present_flag = 1;
2032 ps_app_ctxt->u4_ccv_min_luminance_value_present_flag = 1;
2033 ps_app_ctxt->u4_ccv_max_luminance_value_present_flag = 1;
2034 ps_app_ctxt->u4_ccv_avg_luminance_value_present_flag = 1;
2035 ps_app_ctxt->u4_ccv_reserved_zero_2bits = 0;
2036 for(i4_count = 0; i4_count < NUM_SEI_CCV_PRIMARIES; i4_count++)
2037 {
2038 ps_app_ctxt->ai4_ccv_primaries_x[i4_count] = 1;
2039 ps_app_ctxt->ai4_ccv_primaries_y[i4_count] = 1;
2040 }
2041 ps_app_ctxt->u4_ccv_min_luminance_value = 1;
2042 ps_app_ctxt->u4_ccv_max_luminance_value = 1;
2043 ps_app_ctxt->u4_ccv_avg_luminance_value = 1;
2044 set_sei_ccv_params(ps_app_ctxt, u4_timestamp_low, u4_timestamp_high);
2045 }
2046
2047 ps_app_ctxt->u4_sii_sub_layer_idx = SII_SUB_LAYER_IDX;
2048
2049 if(0 == ps_app_ctxt->u4_sii_sub_layer_idx)
2050 {
2051 ps_app_ctxt->u4_shutter_interval_info_present_flag = SHUTTER_INTERVAL_INFO_PRESENT_FLAG;
2052
2053 if(1 == ps_app_ctxt->u4_shutter_interval_info_present_flag)
2054 {
2055 ps_app_ctxt->u4_sii_time_scale = SII_TIME_SCALE;
2056 ps_app_ctxt->u4_fixed_shutter_interval_within_cvs_flag =
2057 FIXED_SHUTTER_INTERVAL_WITHIN_CVS_FLAG;
2058
2059 if(1 == ps_app_ctxt->u4_fixed_shutter_interval_within_cvs_flag)
2060 {
2061 ps_app_ctxt->u4_sii_num_units_in_shutter_interval =
2062 SII_NUM_UNITS_IN_SHUTTER_INTERVAL;
2063 }
2064 else
2065 {
2066 int i;
2067 ps_app_ctxt->u4_sii_max_sub_layers_minus1 = SII_MAX_SUB_LAYERS_MINUS1;
2068
2069 for(i = 0; i <= (int) ps_app_ctxt->u4_sii_max_sub_layers_minus1; i++)
2070 {
2071 ps_app_ctxt->au4_sub_layer_num_units_in_shutter_interval[i] =
2072 SUB_LAYER_NUM_UNITS_IN_SHUTTER_INTERVAL_HFR;
2073 }
2074 ps_app_ctxt->au4_sub_layer_num_units_in_shutter_interval
2075 [ps_app_ctxt->u4_sii_max_sub_layers_minus1] =
2076 SUB_LAYER_NUM_UNITS_IN_SHUTTER_INTERVAL_SFR;
2077 }
2078 }
2079 }
2080 set_sei_sii_params(ps_app_ctxt, u4_timestamp_low, u4_timestamp_high);
2081
2082 /* Input Initialization */
2083 for(i = 0; i < DEFAULT_MAX_INPUT_BUFS; i++)
2084 {
2085 if(ps_app_ctxt->as_input_buf[i].u4_is_free)
2086 {
2087 pu1_buf = ps_app_ctxt->as_input_buf[i].pu1_buf;
2088 pv_mb_info = ps_app_ctxt->as_input_buf[i].pv_mb_info;
2089 pv_pic_info = ps_app_ctxt->as_input_buf[i].pv_pic_info;
2090 ps_app_ctxt->as_input_buf[i].u4_is_free = 0;
2091 break;
2092 }
2093 }
2094 if (i == DEFAULT_MAX_INPUT_BUFS)
2095 {
2096 printf("\n Unable to find a free input buffer!!");
2097 exit(0);
2098 }
2099
2100 ps_video_encode_ip->u4_size = sizeof(ih264e_video_encode_ip_t);
2101 ps_video_encode_ip->e_cmd = IVE_CMD_VIDEO_ENCODE;
2102 ps_video_encode_ip->pv_bufs = pu1_buf;
2103 ps_video_encode_ip->pv_mb_info = pv_mb_info;
2104 ps_video_encode_ip->pv_pic_info = pv_pic_info;
2105 ps_video_encode_ip->u4_pic_info_type = ps_app_ctxt->u4_pic_info_type;
2106
2107 ps_video_encode_op->u4_size = sizeof(ih264e_video_encode_op_t);
2108
2109 /*
2110 * Since the buffers are used for reading,
2111 * And after each row we have a stride we need to calculate
2112 * the luma size according to the stride
2113 */
2114 ps_inp_raw_buf->e_color_fmt = ps_app_ctxt->e_inp_color_fmt;
2115 if(IV_YUV_420SP_UV == ps_app_ctxt->e_inp_color_fmt
2116 || IV_YUV_420SP_VU == ps_app_ctxt->e_inp_color_fmt)
2117 {
2118 /* init luma buffer */
2119 ps_inp_raw_buf->apv_bufs[0] = pu1_buf;
2120
2121 /* init chroma buffer */
2122 pu1_buf += ps_app_ctxt->u4_strd * ps_app_ctxt->u4_ht;
2123 ps_inp_raw_buf->apv_bufs[1] = pu1_buf;
2124
2125 ps_inp_raw_buf->au4_wd[0] = ps_app_ctxt->u4_wd;
2126 ps_inp_raw_buf->au4_wd[1] = ps_app_ctxt->u4_wd;
2127
2128 ps_inp_raw_buf->au4_ht[0] = ps_app_ctxt->u4_ht;
2129 ps_inp_raw_buf->au4_ht[1] = ps_app_ctxt->u4_ht / 2;
2130
2131 ps_inp_raw_buf->au4_strd[0] = ps_app_ctxt->u4_strd;
2132 ps_inp_raw_buf->au4_strd[1] = ps_app_ctxt->u4_strd;
2133 }
2134 else if(IV_YUV_420P == ps_app_ctxt->e_inp_color_fmt)
2135 {
2136 /* init luma buffer */
2137 ps_inp_raw_buf->apv_bufs[0] = pu1_buf;
2138 pu1_buf += (ps_app_ctxt->u4_wd) * ps_app_ctxt->u4_ht;
2139
2140 /* init chroma buffer U */
2141 ps_inp_raw_buf->apv_bufs[1] = pu1_buf;
2142 pu1_buf += (ps_app_ctxt->u4_wd >> 1) * (ps_app_ctxt->u4_ht >> 1);
2143
2144 /* init chroma buffer V */
2145 ps_inp_raw_buf->apv_bufs[2] = pu1_buf;
2146
2147 ps_inp_raw_buf->au4_wd[0] = ps_app_ctxt->u4_wd;
2148 ps_inp_raw_buf->au4_wd[1] = ps_app_ctxt->u4_wd / 2;
2149 ps_inp_raw_buf->au4_wd[2] = ps_app_ctxt->u4_wd / 2;
2150
2151 ps_inp_raw_buf->au4_ht[0] = ps_app_ctxt->u4_ht;
2152 ps_inp_raw_buf->au4_ht[1] = ps_app_ctxt->u4_ht / 2;
2153 ps_inp_raw_buf->au4_ht[2] = ps_app_ctxt->u4_ht / 2;
2154
2155 ps_inp_raw_buf->au4_strd[0] = ps_app_ctxt->u4_strd;
2156 ps_inp_raw_buf->au4_strd[1] = ps_app_ctxt->u4_strd / 2;
2157 ps_inp_raw_buf->au4_strd[2] = ps_app_ctxt->u4_strd / 2;
2158
2159 }
2160 else if(IV_YUV_422ILE == ps_app_ctxt->e_inp_color_fmt)
2161 {
2162 /* init luma buffer */
2163 ps_inp_raw_buf->apv_bufs[0] = pu1_buf;
2164
2165 ps_inp_raw_buf->au4_wd[0] = ps_app_ctxt->u4_wd * 2;
2166
2167 ps_inp_raw_buf->au4_ht[0] = ps_app_ctxt->u4_ht;
2168
2169 ps_inp_raw_buf->au4_strd[0] = ps_app_ctxt->u4_strd * 2;
2170 }
2171
2172 /* Read input and other associated buffers */
2173 while(1)
2174 {
2175 IV_STATUS_T mb_info_status = IV_SUCCESS;
2176 IV_STATUS_T pic_info_status = IV_SUCCESS;
2177
2178 status = read_input(ps_app_ctxt->fp_ip, ps_inp_raw_buf);
2179
2180 if(ps_app_ctxt->u4_mb_info_type != 0)
2181 {
2182 mb_info_status = read_mb_info(ps_app_ctxt, pv_mb_info);
2183 }
2184 if(ps_app_ctxt->u4_pic_info_type != 0)
2185 {
2186 pic_info_status = read_pic_info(ps_app_ctxt, pv_pic_info);
2187 }
2188 if((IV_SUCCESS != status) || (IV_SUCCESS != mb_info_status)
2189 || (IV_SUCCESS != pic_info_status))
2190 {
2191 if(0 == ps_app_ctxt->u4_loopback)
2192 {
2193 is_last = 1;
2194 break;
2195 }
2196 else
2197 {
2198 fseek(ps_app_ctxt->fp_ip, 0, SEEK_SET);
2199 }
2200 }
2201 break;
2202 }
2203
2204 /* Output Initialization */
2205 for(i = 0; i < DEFAULT_MAX_OUTPUT_BUFS; i++)
2206 {
2207 if(ps_app_ctxt->as_output_buf[i].u4_is_free)
2208 {
2209 pu1_buf = ps_app_ctxt->as_output_buf[i].pu1_buf;
2210 buff_size = ps_app_ctxt->as_output_buf[i].u4_buf_size;
2211 ps_app_ctxt->as_output_buf[i].u4_is_free = 0;
2212 break;
2213 }
2214 }
2215 if (i == DEFAULT_MAX_OUTPUT_BUFS)
2216 {
2217 printf("\n Unable to find a free output buffer!!");
2218 exit(0);
2219 }
2220 ps_video_encode_ip->s_out_buf.pv_buf = pu1_buf;
2221 ps_video_encode_ip->s_out_buf.u4_bytes = 0;
2222 ps_video_encode_ip->s_out_buf.u4_bufsize = buff_size;
2223
2224 /* Recon Initialization */
2225 init_raw_buf_descr(ps_app_ctxt, &s_recon_buf,
2226 ps_app_ctxt->as_recon_buf[0].pu1_buf,
2227 ps_app_ctxt->e_recon_color_fmt);
2228 ps_video_encode_ip->s_recon_buf = s_recon_buf;
2229
2230 if(ps_app_ctxt->u4_psnr_enable)
2231 {
2232 init_raw_buf_descr(ps_app_ctxt, &s_inp_buf,
2233 ps_app_ctxt->pu1_psnr_buf,
2234 ps_app_ctxt->e_inp_color_fmt);
2235 }
2236
2237 if(0 == ps_app_ctxt->u4_loopback)
2238 {
2239 /* If input file is read completely and loopback is not enabled,
2240 * then exit the loop */
2241 if(feof(ps_app_ctxt->fp_ip))
2242 {
2243 is_last = 1;
2244 }
2245 }
2246
2247 /* If last frame, send input null to get back encoded frames */
2248 if(is_last == 1 || ((ps_app_ctxt->u4_max_num_frms) <= u4_timestamp_low))
2249 {
2250 is_last = 1;
2251 ps_inp_raw_buf->apv_bufs[0] = NULL;
2252 ps_inp_raw_buf->apv_bufs[1] = NULL;
2253 ps_inp_raw_buf->apv_bufs[2] = NULL;
2254 }
2255
2256 ps_video_encode_ip->u4_is_last = is_last;
2257 ps_video_encode_ip->u4_mb_info_type = ps_app_ctxt->u4_mb_info_type;
2258 ps_video_encode_ip->u4_pic_info_type = ps_app_ctxt->u4_pic_info_type;
2259 ps_video_encode_op->s_out_buf.pv_buf = NULL;
2260 ps_video_encode_ip->u4_timestamp_high = u4_timestamp_high;
2261 ps_video_encode_ip->u4_timestamp_low = u4_timestamp_low;
2262
2263 GETTIME(&ps_app_ctxt->enc_last_time);
2264
2265 /* encoder api call */
2266 status = ih264e_api_function(ps_enc, &ih264e_video_encode_ip,
2267 &ih264e_video_encode_op);
2268 if(IV_SUCCESS != status)
2269 {
2270 printf("Encode Frame failed = 0x%x\n",
2271 ih264e_video_encode_op.s_ive_op.u4_error_code);
2272 break;
2273 }
2274
2275 #ifdef WINDOWS_TIMER
2276 QueryPerformanceFrequency ( &frequency);
2277 #endif
2278 GETTIME(&curtime);
2279 ELAPSEDTIME(ps_app_ctxt->enc_last_time, curtime, timetaken, frequency);
2280 ps_app_ctxt->enc_last_time = curtime;
2281
2282 #ifdef PROFILE_ENABLE
2283 {
2284 WORD32 peak_avg, id;
2285
2286 u4_total_time += timetaken;
2287 peak_window[peak_window_idx++] = timetaken;
2288 if(peak_window_idx == PEAK_WINDOW_SIZE)
2289 peak_window_idx = 0;
2290 peak_avg = 0;
2291 for(id = 0; id < PEAK_WINDOW_SIZE; id++)
2292 {
2293 peak_avg += peak_window[id];
2294 }
2295 peak_avg /= PEAK_WINDOW_SIZE;
2296 if (peak_avg > peak_avg_max)
2297 peak_avg_max = peak_avg;
2298 }
2299 #endif
2300
2301 /* Write Output */
2302 num_bytes = 0;
2303 if(1 == ps_video_encode_op->output_present)
2304 {
2305 num_bytes = ps_video_encode_op->s_out_buf.u4_bytes;
2306 buff_size = ps_video_encode_op->s_out_buf.u4_bufsize;
2307 pu1_buf = (UWORD8*)ps_video_encode_op->s_out_buf.pv_buf;
2308 status = write_output(ps_app_ctxt->fp_op, pu1_buf, num_bytes);
2309 if(IV_SUCCESS != status)
2310 {
2311 printf("Error: Unable to write to output file\n");
2312 break;
2313 }
2314 }
2315
2316 /* free input bufer if codec returns a valid input buffer */
2317 if(ps_video_encode_op->s_inp_buf.apv_bufs[0])
2318 {
2319 /* Reuse of freed input buffer */
2320 for(i = 0; i < DEFAULT_MAX_INPUT_BUFS; i++)
2321 {
2322 if(ps_app_ctxt->as_input_buf[i].pu1_buf
2323 == ps_video_encode_op->s_inp_buf.apv_bufs[0])
2324 {
2325 ps_app_ctxt->as_input_buf[i].u4_is_free = 1;
2326 break;
2327 }
2328 }
2329 }
2330
2331 /* free output buffer if codec returns a valid output buffer */
2332 if(ps_video_encode_op->s_out_buf.pv_buf)
2333 {
2334 for(i = 0; i < DEFAULT_MAX_OUTPUT_BUFS; i++)
2335 {
2336 if(ps_app_ctxt->as_output_buf[i].pu1_buf
2337 == ps_video_encode_op->s_out_buf.pv_buf)
2338 {
2339 ps_app_ctxt->as_output_buf[i].u4_is_free = 1;
2340 break;
2341 }
2342 }
2343 }
2344
2345 /* Print stats */
2346 {
2347 UWORD8 u1_pic_type[][5] = { "IDR", "I", "P", "B", "NA" };
2348 WORD32 lookup_idx = 0;
2349
2350 switch(ih264e_video_encode_op.s_ive_op.u4_encoded_frame_type)
2351 {
2352 case IV_IDR_FRAME:
2353 lookup_idx = 0;
2354 break;
2355 case IV_I_FRAME:
2356 lookup_idx = 1;
2357 break;
2358 case IV_P_FRAME:
2359 lookup_idx = 2;
2360 break;
2361 case IV_B_FRAME:
2362 lookup_idx = 3;
2363 break;
2364 case IV_NA_FRAME:
2365 lookup_idx = 4;
2366 break;
2367 default:
2368 break;
2369 }
2370
2371 if(ih264e_video_encode_op.s_ive_op.u4_encoded_frame_type
2372 != IV_NA_FRAME)
2373 {
2374 ps_app_ctxt->u4_pics_cnt++;
2375 ps_app_ctxt->avg_time = u4_total_time / ps_app_ctxt->u4_pics_cnt;
2376 ps_app_ctxt->u4_total_bytes += num_bytes;
2377 }
2378
2379 if(ps_app_ctxt->u4_psnr_enable == 0)
2380 {
2381 printf("[%s] PicNum %4d Bytes Generated %6d TimeTaken(microsec): %6d AvgTime: %6d PeakAvgTimeMax: %6d\n",
2382 u1_pic_type[lookup_idx], ps_app_ctxt->u4_pics_cnt,
2383 num_bytes, timetaken, ps_app_ctxt->avg_time,
2384 peak_avg_max);
2385 }
2386 }
2387
2388
2389 /* For psnr computation, we need to read the correct input frame and
2390 * compare with recon. The difficulty with doing it is that we only know
2391 * that the frame number of recon is monotonically increasing. There
2392 * may be gaps in the recon if any pre or post enc skip happens. There are
2393 * 3 senarios
2394 * 1) A frame is encoded -> returns the pic type
2395 * 2) A frame is not encoded -> Encoder is waiting, the frame may get
2396 * encoded later
2397 * 3) A frame is not encoded -> A post enc or pre enc skip happend. The
2398 * frame is not going to be encoded
2399 *
2400 * The 1st and 2nd scenarios are easy, since we just needs to increment
2401 * recon cnt whenever we get a valid recon. This cnt can we used to
2402 * sync the recon and input
2403 * 3rd scenario in conjuction with 2nd will pose problems. Even if
2404 * the returning frame is NA, we donot know we should increment the
2405 * recon cnt or not becasue it can be case 2 or case 3.
2406 *
2407 * Solutions:
2408 * -------------------------
2409 * One way to over come this will be to return more information as of
2410 * the frame type. We can send if a frame was skipped as a part of the
2411 * return frame type.
2412 * This will not work. Since the output and recon are not in sync, we
2413 * cannot use the current output frame type to determine if a recon
2414 * is present currently or not. We need some other way to acheive this.
2415 *
2416 * Other way to do this which is cleaner and maintains the seperation
2417 * between recon and the ouptut is to set the width [& height] of output recon
2418 * buffer to be zero. Hence we will in effect be saying :"look there
2419 * is a recon, but due to frame not being encoded it is having a width 0".
2420 * To be more clear we need to make height also to be zero.
2421 *
2422 * But are we using these variables for allocating and deallocating
2423 * the buffers some where ? No we are not. The buffer gets re-init
2424 * at every encode call
2425 *
2426 * Fixes
2427 * ------------------------
2428 * Currently the recon buff width and height are set in the encoder.
2429 * This will not work now because since recon and input are not
2430 * in sync. Hence a recon buff sent at time stamp x will get used to
2431 * fill recon of input at time stamp y (x > y). If we reduced the
2432 * frame dimensions in between, the recon buffer will not have enough
2433 * space. Hence we need to set the with and height appropriatley inside
2434 * lib itself.
2435 */
2436
2437 if (ps_app_ctxt->u4_recon_enable || ps_app_ctxt->u4_chksum_enable
2438 || ps_app_ctxt->u4_psnr_enable)
2439 {
2440 if (ps_video_encode_op->dump_recon)
2441 {
2442 s_recon_buf = ps_video_encode_op->s_recon_buf;
2443
2444 /* Read input for psnr computuation */
2445 if (ps_app_ctxt->u4_psnr_enable)
2446 read_input(ps_app_ctxt->fp_psnr_ip, &s_inp_buf);
2447
2448 /* if we have a valid recon buffer do the assocated tasks */
2449 if (s_recon_buf.au4_wd[0])
2450 {
2451 /* Dump recon when enabled, and output bytes != 0 */
2452 if (ps_app_ctxt->u4_recon_enable)
2453 {
2454 status = write_recon(ps_app_ctxt->fp_recon, &s_recon_buf);
2455 if (IV_SUCCESS != status)
2456 {
2457 printf("Error: Unable to write to recon file\n");
2458 break;
2459 }
2460 }
2461
2462 if (ps_app_ctxt->u4_psnr_enable)
2463 {
2464 compute_psnr(ps_app_ctxt, &s_recon_buf, &s_inp_buf);
2465 }
2466
2467
2468 if (ps_app_ctxt->u4_chksum_enable)
2469 {
2470 WORD32 comp, num_comp = 2;
2471
2472 if (IV_YUV_420P == s_recon_buf.e_color_fmt)
2473 num_comp = 3;
2474
2475 for (comp = 0; comp < num_comp; comp++)
2476 {
2477 UWORD8 au1_chksum[16];
2478 calc_md5_cksum((UWORD8 *)s_recon_buf.apv_bufs[comp],
2479 s_recon_buf.au4_strd[comp],
2480 s_recon_buf.au4_wd[comp],
2481 s_recon_buf.au4_ht[comp],
2482 au1_chksum);
2483 fwrite(au1_chksum, sizeof(UWORD8), 16, ps_app_ctxt->fp_chksum);
2484 }
2485 }
2486 }
2487 }
2488 }
2489
2490 u4_timestamp_low++;
2491
2492 /* Break if all the encoded frames are taken from encoder */
2493 if (1 == ps_video_encode_op->u4_is_last)
2494 {
2495 break;
2496 }
2497 }
2498
2499 /* Pic count is 1 more than actual num frames encoded, because last call is
2500 * to just get the output */
2501 ps_app_ctxt->u4_pics_cnt--;
2502
2503 if(ps_app_ctxt->u4_psnr_enable)
2504 {
2505 print_average_psnr(ps_app_ctxt);
2506 }
2507
2508 /* house keeping operations */
2509 fclose(ps_app_ctxt->fp_ip);
2510 fclose(ps_app_ctxt->fp_op);
2511 if(1 == ps_app_ctxt->u4_recon_enable)
2512 {
2513 fclose(ps_app_ctxt->fp_recon);
2514 }
2515 if(1 == ps_app_ctxt->u4_chksum_enable)
2516 {
2517 fclose(ps_app_ctxt->fp_chksum);
2518 }
2519 if(1 == ps_app_ctxt->u4_psnr_enable)
2520 {
2521 fclose(ps_app_ctxt->fp_psnr_ip);
2522 }
2523
2524 if(0 != ps_app_ctxt->u4_mb_info_type)
2525 {
2526 fclose(ps_app_ctxt->fp_mb_info);
2527 }
2528 if (ps_app_ctxt->u4_pic_info_type)
2529 {
2530 fclose(ps_app_ctxt->fp_pic_info);
2531 }
2532
2533 free_input(ps_app_ctxt);
2534 free_output(ps_app_ctxt);
2535 free_recon(ps_app_ctxt);
2536 }
2537
2538 /**
2539 *******************************************************************************
2540 * @brief Application to demonstrate codec API. Shows how to use create,
2541 * process, control and delete
2542 *******************************************************************************
2543 */
2544 #ifdef IOS
h264enc_main(char * homedir,char * documentdir,int screen_wd,int screen_ht)2545 int h264enc_main(char * homedir,char *documentdir, int screen_wd, int screen_ht)
2546 #else
2547 int main(int argc, char *argv[])
2548 #endif
2549 {
2550 /* Config Parameters for Encoding */
2551 app_ctxt_t s_app_ctxt;
2552
2553 /* error string */
2554 CHAR ac_error[STRLENGTH];
2555
2556 /* config file name */
2557 CHAR ac_cfg_fname[STRLENGTH];
2558
2559 /* error status */
2560 IV_STATUS_T status = IV_SUCCESS;
2561 #ifdef IOS
2562 /* temp var */
2563 CHAR filename_with_path[STRLENGTH];
2564 #endif
2565 WORD32 num_mem_recs;
2566 iv_obj_t *ps_enc;
2567 WORD32 i;
2568 FILE *fp_cfg = NULL;
2569
2570 #ifdef X86_MINGW
2571
2572 /* For getting printfs without any delay in eclipse */
2573 setvbuf(stdout, NULL, _IONBF, 0);
2574 setvbuf(stderr, NULL, _IONBF, 0);
2575
2576 #endif
2577
2578 init_default_params(&s_app_ctxt);
2579
2580 #ifndef IOS
2581
2582 /* Usage */
2583 if(argc < 2)
2584 {
2585 printf("Using enc.cfg as configuration file \n");
2586 strcpy(ac_cfg_fname, "enc.cfg");
2587 }
2588 else if(argc == 2)
2589 {
2590 if (!strcmp(argv[1], "--help"))
2591 {
2592 print_usage();
2593 exit(-1);
2594 }
2595 strcpy(ac_cfg_fname, argv[1]);
2596 }
2597
2598 #else
2599 strcpy(ac_cfg_fname, "test.cfg");
2600
2601 #endif
2602
2603 /*************************************************************************/
2604 /* Parse arguments */
2605 /*************************************************************************/
2606
2607 #ifndef IOS
2608
2609 /* Read command line arguments */
2610 if(argc > 2)
2611 {
2612 for(i = 1; i + 1 < argc; i += 2)
2613 {
2614 if(CONFIG == get_argument(argv[i]))
2615 {
2616 strcpy(ac_cfg_fname, argv[i + 1]);
2617 if((fp_cfg = fopen(ac_cfg_fname, "r")) == NULL)
2618 {
2619 sprintf(ac_error,
2620 "Could not open Configuration file %s",
2621 ac_cfg_fname);
2622 codec_exit(ac_error);
2623 }
2624 read_cfg_file(&s_app_ctxt, fp_cfg);
2625 fclose(fp_cfg);
2626 }
2627 else
2628 {
2629 parse_argument(&s_app_ctxt, argv[i], argv[i + 1]);
2630 }
2631 }
2632 }
2633 else
2634 {
2635 if((fp_cfg = fopen(ac_cfg_fname, "r")) == NULL)
2636 {
2637 sprintf(ac_error, "Could not open Configuration file %s",
2638 ac_cfg_fname);
2639 codec_exit(ac_error);
2640 }
2641 read_cfg_file(&s_app_ctxt, fp_cfg);
2642 fclose(fp_cfg);
2643 }
2644
2645 #else
2646
2647 sprintf(filename_with_path, "%s/%s", homedir, "enc.cfg");
2648 if((fp_cfg = fopen(filename_with_path, "r")) == NULL)
2649 {
2650 sprintf(ac_error, "Could not open Configuration file %s",
2651 ac_cfg_fname);
2652 codec_exit(ac_error);
2653
2654 }
2655 read_cfg_file(&s_app_ctxt, fp_cfg);
2656 fclose(fp_cfg);
2657
2658 #endif
2659
2660 validate_params(&s_app_ctxt);
2661
2662
2663 /*************************************************************************/
2664 /* Getting Number of MemRecords */
2665 /*************************************************************************/
2666 {
2667 ih264e_num_mem_rec_ip_t s_num_mem_rec_ip;
2668 ih264e_num_mem_rec_op_t s_num_mem_rec_op;
2669
2670 s_num_mem_rec_ip.s_ive_ip.u4_size = sizeof(ih264e_num_mem_rec_ip_t);
2671 s_num_mem_rec_ip.s_ive_ip.e_cmd = IV_CMD_GET_NUM_MEM_REC;
2672
2673 s_num_mem_rec_op.s_ive_op.u4_size = sizeof(ih264e_num_mem_rec_op_t);
2674
2675 status = ih264e_api_function(NULL, &s_num_mem_rec_ip, &s_num_mem_rec_op);
2676 if(status != IV_SUCCESS)
2677 {
2678 sprintf(ac_error, "Get number of memory records failed = 0x%x\n",
2679 s_num_mem_rec_op.s_ive_op.u4_error_code);
2680 codec_exit(ac_error);
2681 }
2682
2683 s_app_ctxt.u4_num_mem_rec = s_num_mem_rec_op.s_ive_op.u4_num_mem_rec;
2684 num_mem_recs = s_num_mem_rec_op.s_ive_op.u4_num_mem_rec;
2685 }
2686
2687 /*************************************************************************/
2688 /* Allocate and Default initialize MemRecords */
2689 /*************************************************************************/
2690 s_app_ctxt.ps_mem_rec = malloc(num_mem_recs * sizeof(iv_mem_rec_t));
2691 if(NULL == s_app_ctxt.ps_mem_rec)
2692 {
2693 sprintf(ac_error,
2694 "Unable to allocate memory for hold memory records: Size %d",
2695 (WORD32)(num_mem_recs * sizeof(iv_mem_rec_t)));
2696 codec_exit(ac_error);
2697 }
2698 /* Default init memory records */
2699 {
2700 iv_mem_rec_t *ps_mem_rec = s_app_ctxt.ps_mem_rec;
2701
2702 for(i = 0; i < num_mem_recs; i++, ps_mem_rec++)
2703 {
2704 ps_mem_rec->u4_size = sizeof(iv_mem_rec_t);
2705 ps_mem_rec->pv_base = NULL;
2706 ps_mem_rec->u4_mem_size = 0;
2707 ps_mem_rec->u4_mem_alignment = 0;
2708 ps_mem_rec->e_mem_type = IV_NA_MEM_TYPE;
2709 }
2710 }
2711
2712 /*************************************************************************/
2713 /* Getting MemRecords Attributes */
2714 /*************************************************************************/
2715 {
2716 ih264e_fill_mem_rec_ip_t s_fill_mem_rec_ip;
2717 ih264e_fill_mem_rec_op_t s_fill_mem_rec_op;
2718
2719 s_fill_mem_rec_ip.s_ive_ip.u4_size = sizeof(ih264e_fill_mem_rec_ip_t);
2720 s_fill_mem_rec_ip.s_ive_ip.e_cmd = IV_CMD_FILL_NUM_MEM_REC;
2721 s_fill_mem_rec_ip.s_ive_ip.ps_mem_rec = s_app_ctxt.ps_mem_rec;
2722 s_fill_mem_rec_ip.s_ive_ip.u4_num_mem_rec = s_app_ctxt.u4_num_mem_rec;
2723 s_fill_mem_rec_ip.s_ive_ip.u4_max_wd = s_app_ctxt.u4_max_wd;
2724 s_fill_mem_rec_ip.s_ive_ip.u4_max_ht = s_app_ctxt.u4_max_ht;
2725 s_fill_mem_rec_ip.s_ive_ip.u4_max_ref_cnt = DEFAULT_MAX_REF_FRM;
2726 s_fill_mem_rec_ip.s_ive_ip.u4_max_reorder_cnt = DEFAULT_MAX_REORDER_FRM;
2727 s_fill_mem_rec_ip.s_ive_ip.u4_max_level = s_app_ctxt.u4_max_level;
2728 s_fill_mem_rec_ip.s_ive_ip.e_color_format = DEFAULT_INP_COLOR_FMT;
2729 s_fill_mem_rec_ip.s_ive_ip.u4_max_srch_rng_x = DEFAULT_MAX_SRCH_RANGE_X;
2730 s_fill_mem_rec_ip.s_ive_ip.u4_max_srch_rng_y = DEFAULT_MAX_SRCH_RANGE_Y;
2731
2732 s_fill_mem_rec_op.s_ive_op.u4_size = sizeof(ih264e_fill_mem_rec_op_t);
2733
2734 status = ih264e_api_function(NULL, &s_fill_mem_rec_ip, &s_fill_mem_rec_op);
2735 if(status != IV_SUCCESS)
2736 {
2737 sprintf(ac_error, "Fill memory records failed = 0x%x\n",
2738 s_fill_mem_rec_op.s_ive_op.u4_error_code);
2739 codec_exit(ac_error);
2740 }
2741 }
2742
2743 /*************************************************************************/
2744 /* Allocating Memory for Mem Records */
2745 /*************************************************************************/
2746 {
2747 iv_mem_rec_t *ps_mem_rec = s_app_ctxt.ps_mem_rec;
2748 WORD32 total_size = 0;
2749
2750 for(i = 0; i < num_mem_recs; i++)
2751 {
2752 ps_mem_rec->pv_base = ih264a_aligned_malloc(
2753 ps_mem_rec->u4_mem_alignment,
2754 ps_mem_rec->u4_mem_size);
2755 if(ps_mem_rec->pv_base == NULL)
2756 {
2757 sprintf(ac_error,
2758 "Allocation failure for mem record id %d size %d\n", i,
2759 ps_mem_rec->u4_mem_size);
2760 codec_exit(ac_error);
2761 }
2762 total_size += ps_mem_rec->u4_mem_size;
2763
2764 ps_mem_rec++;
2765 }
2766 printf("\nTotal memory for codec %d\n", total_size);
2767 }
2768
2769
2770 /*************************************************************************/
2771 /* Codec Instance Creation */
2772 /*************************************************************************/
2773 {
2774 ih264e_init_ip_t s_init_ip;
2775 ih264e_init_op_t s_init_op;
2776
2777 ps_enc = s_app_ctxt.ps_mem_rec[0].pv_base;
2778 ps_enc->u4_size = sizeof(iv_obj_t);
2779 ps_enc->pv_fxns = ih264e_api_function;
2780 s_app_ctxt.ps_enc = ps_enc;
2781
2782 s_init_ip.s_ive_ip.u4_size = sizeof(ih264e_init_ip_t);
2783 s_init_ip.s_ive_ip.e_cmd = IV_CMD_INIT;
2784 s_init_ip.s_ive_ip.u4_num_mem_rec = s_app_ctxt.u4_num_mem_rec;
2785 s_init_ip.s_ive_ip.ps_mem_rec = s_app_ctxt.ps_mem_rec;
2786 s_init_ip.s_ive_ip.u4_max_wd = s_app_ctxt.u4_max_wd;
2787 s_init_ip.s_ive_ip.u4_max_ht = s_app_ctxt.u4_max_ht;
2788 s_init_ip.s_ive_ip.u4_max_ref_cnt = DEFAULT_MAX_REF_FRM;
2789 s_init_ip.s_ive_ip.u4_max_reorder_cnt = DEFAULT_MAX_REORDER_FRM;
2790 s_init_ip.s_ive_ip.u4_max_level = s_app_ctxt.u4_max_level;
2791 s_init_ip.s_ive_ip.e_inp_color_fmt = s_app_ctxt.e_inp_color_fmt;
2792 if(s_app_ctxt.u4_recon_enable || s_app_ctxt.u4_psnr_enable
2793 || s_app_ctxt.u4_chksum_enable)
2794 {
2795 s_init_ip.s_ive_ip.u4_enable_recon = 1;
2796 }
2797 else
2798 {
2799 s_init_ip.s_ive_ip.u4_enable_recon = 0;
2800 }
2801 s_init_ip.s_ive_ip.e_recon_color_fmt = s_app_ctxt.e_recon_color_fmt;
2802 s_init_ip.s_ive_ip.e_rc_mode = s_app_ctxt.u4_rc;
2803 s_init_ip.s_ive_ip.u4_max_framerate = s_app_ctxt.u4_max_frame_rate;
2804 s_init_ip.s_ive_ip.u4_max_bitrate = s_app_ctxt.u4_max_bitrate;
2805 s_init_ip.s_ive_ip.u4_num_bframes = s_app_ctxt.u4_num_bframes;
2806 s_init_ip.s_ive_ip.e_content_type = IV_PROGRESSIVE;
2807 s_init_ip.s_ive_ip.u4_max_srch_rng_x = DEFAULT_MAX_SRCH_RANGE_X;
2808 s_init_ip.s_ive_ip.u4_max_srch_rng_y = DEFAULT_MAX_SRCH_RANGE_Y;
2809 s_init_ip.s_ive_ip.e_slice_mode = s_app_ctxt.u4_slice_mode;
2810 s_init_ip.s_ive_ip.u4_slice_param = s_app_ctxt.u4_slice_param;
2811 s_init_ip.s_ive_ip.e_arch = s_app_ctxt.e_arch;
2812 s_init_ip.s_ive_ip.e_soc = s_app_ctxt.e_soc;
2813
2814 s_init_op.s_ive_op.u4_size = sizeof(ih264e_init_op_t);
2815
2816 status = ih264e_api_function(ps_enc, &s_init_ip, &s_init_op);
2817 if(status != IV_SUCCESS)
2818 {
2819 sprintf(ac_error, "Init memory records failed = 0x%x\n",
2820 s_init_op.s_ive_op.u4_error_code);
2821 codec_exit(ac_error);
2822 }
2823 }
2824
2825 /*************************************************************************/
2826 /* set processor details */
2827 /*************************************************************************/
2828 {
2829 ih264e_ctl_set_num_cores_ip_t s_ctl_set_num_cores_ip;
2830 ih264e_ctl_set_num_cores_op_t s_ctl_set_num_cores_op;
2831
2832 s_ctl_set_num_cores_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_num_cores_ip_t);
2833 s_ctl_set_num_cores_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL;
2834 s_ctl_set_num_cores_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_NUM_CORES;
2835 s_ctl_set_num_cores_ip.s_ive_ip.u4_num_cores = s_app_ctxt.u4_num_cores;
2836 s_ctl_set_num_cores_ip.s_ive_ip.u4_timestamp_high = 0;
2837 s_ctl_set_num_cores_ip.s_ive_ip.u4_timestamp_low = 0;
2838
2839 s_ctl_set_num_cores_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_num_cores_op_t);
2840
2841 status = ih264e_api_function(ps_enc, (void *)&s_ctl_set_num_cores_ip,
2842 (void *)&s_ctl_set_num_cores_op);
2843 if(status != IV_SUCCESS)
2844 {
2845 sprintf(ac_error, "Unable to set processor params = 0x%x\n",
2846 s_ctl_set_num_cores_op.s_ive_op.u4_error_code);
2847 codec_exit(ac_error);
2848 }
2849 }
2850
2851 /*************************************************************************/
2852 /* Get Codec Version */
2853 /*************************************************************************/
2854 {
2855 ih264e_ctl_getversioninfo_ip_t s_ctl_set_getversioninfo_ip;
2856 ih264e_ctl_getversioninfo_op_t s_ctl_set_getversioninfo_op;
2857 CHAR ac_version_string[STRLENGTH];
2858
2859 s_ctl_set_getversioninfo_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_getversioninfo_ip_t);
2860 s_ctl_set_getversioninfo_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL;
2861 s_ctl_set_getversioninfo_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_GETVERSION;
2862 s_ctl_set_getversioninfo_ip.s_ive_ip.pu1_version = (UWORD8 *)ac_version_string;
2863 s_ctl_set_getversioninfo_ip.s_ive_ip.u4_version_bufsize = sizeof(ac_version_string);
2864
2865 s_ctl_set_getversioninfo_op.s_ive_op.u4_size = sizeof(ih264e_ctl_getversioninfo_op_t);
2866
2867 status = ih264e_api_function(ps_enc,
2868 (void *)&s_ctl_set_getversioninfo_ip,
2869 (void *)&s_ctl_set_getversioninfo_op);
2870 if(status != IV_SUCCESS)
2871 {
2872 sprintf(ac_error, "Unable to get codec version = 0x%x\n",
2873 s_ctl_set_getversioninfo_op.s_ive_op.u4_error_code);
2874 codec_exit(ac_error);
2875 }
2876 printf("CODEC VERSION %s\n", ac_version_string);
2877 }
2878
2879 /*************************************************************************/
2880 /* Get I/O Buffer Requirement */
2881 /*************************************************************************/
2882 {
2883 ih264e_ctl_getbufinfo_ip_t s_get_buf_info_ip;
2884 ih264e_ctl_getbufinfo_op_t s_get_buf_info_op;
2885
2886 s_get_buf_info_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_getbufinfo_ip_t);
2887 s_get_buf_info_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL;
2888 s_get_buf_info_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_GETBUFINFO;
2889 s_get_buf_info_ip.s_ive_ip.u4_max_ht = s_app_ctxt.u4_max_ht;
2890 s_get_buf_info_ip.s_ive_ip.u4_max_wd = s_app_ctxt.u4_max_wd;
2891 s_get_buf_info_ip.s_ive_ip.e_inp_color_fmt = s_app_ctxt.e_inp_color_fmt;
2892
2893 s_get_buf_info_op.s_ive_op.u4_size = sizeof(ih264e_ctl_getbufinfo_op_t);
2894
2895 status = ih264e_api_function(ps_enc, &s_get_buf_info_ip,
2896 &s_get_buf_info_op);
2897 if(status != IV_SUCCESS)
2898 {
2899 sprintf(ac_error, "Unable to get I/O buffer requirements = 0x%x\n",
2900 s_get_buf_info_op.s_ive_op.u4_error_code);
2901 codec_exit(ac_error);
2902 }
2903 s_app_ctxt.s_get_buf_info_op = s_get_buf_info_op;
2904 }
2905
2906 /**************************************************************************/
2907 /* Add the following initializations based on the parameters in context */
2908 /**************************************************************************/
2909
2910 /**************************************************************************/
2911 /* Video control Set Frame dimensions */
2912 /**************************************************************************/
2913 s_app_ctxt.u4_strd = s_app_ctxt.u4_wd;
2914 set_dimensions(&s_app_ctxt, 0, 0);
2915
2916 /**************************************************************************/
2917 /* Video control Set Frame rates */
2918 /**************************************************************************/
2919 set_frame_rate(&s_app_ctxt, 0, 0);
2920
2921 /**************************************************************************/
2922 /* Video control Set IPE Params */
2923 /**************************************************************************/
2924 set_ipe_params(&s_app_ctxt, 0, 0);
2925
2926 /**************************************************************************/
2927 /* Video control Set Bitrate */
2928 /**************************************************************************/
2929 set_bit_rate(&s_app_ctxt, 0, 0);
2930
2931 /**************************************************************************/
2932 /* Video control Set QP */
2933 /**************************************************************************/
2934 set_qp(&s_app_ctxt, 0, 0);
2935
2936 /**************************************************************************/
2937 /* Video control Set AIR params */
2938 /**************************************************************************/
2939 set_air_params(&s_app_ctxt, 0, 0);
2940
2941 /**************************************************************************/
2942 /* Video control Set VBV params */
2943 /**************************************************************************/
2944 set_vbv_params(&s_app_ctxt, 0, 0);
2945
2946 /**************************************************************************/
2947 /* Video control Set Motion estimation params */
2948 /**************************************************************************/
2949 set_me_params(&s_app_ctxt, 0, 0);
2950
2951 /**************************************************************************/
2952 /* Video control Set GOP params */
2953 /**************************************************************************/
2954 set_gop_params(&s_app_ctxt, 0, 0);
2955
2956 /**************************************************************************/
2957 /* Video control Set Deblock params */
2958 /**************************************************************************/
2959 set_deblock_params(&s_app_ctxt, 0, 0);
2960
2961 /**************************************************************************/
2962 /* Video control Set Profile params */
2963 /**************************************************************************/
2964 set_profile_params(&s_app_ctxt, 0, 0);
2965
2966 /**************************************************************************/
2967 /* Video usability information */
2968 /**************************************************************************/
2969 set_vui_params(&s_app_ctxt);
2970
2971 #ifdef IOS
2972 /* Correct file paths */
2973 sprintf(filename_with_path, "%s/%s", documentdir, s_app_ctxt.ac_ip_fname);
2974 strcpy (s_app_ctxt.ac_ip_fname, filename_with_path);
2975
2976 sprintf(filename_with_path, "%s/%s", documentdir, s_app_ctxt.ac_op_fname);
2977 strcpy (s_app_ctxt.ac_op_fname, filename_with_path);
2978
2979 sprintf(filename_with_path, "%s/%s", documentdir, s_app_ctxt.ac_recon_fname);
2980 strcpy (s_app_ctxt.ac_recon_fname, filename_with_path);
2981
2982 sprintf(filename_with_path, "%s/%s", documentdir, s_app_ctxt.ac_chksum_fname);
2983 strcpy (s_app_ctxt.ac_chksum_fname, filename_with_path);
2984
2985 sprintf(filename_with_path, "%s/%s", documentdir, s_app_ctxt.ac_mb_info_fname);
2986 strcpy (s_app_ctxt.ac_mb_info_fname, filename_with_path);
2987
2988 sprintf(filename_with_path, "%s/%s", documentdir, s_app_ctxt.ac_pic_info_fname);
2989 strcpy (s_app_ctxt.ac_pic_info_fname, filename_with_path);
2990 #endif
2991
2992 /*************************************************************************/
2993 /* Encoding */
2994 /*************************************************************************/
2995 synchronous_encode(ps_enc, &s_app_ctxt);
2996
2997 /*************************************************************************/
2998 /* Print summary */
2999 /*************************************************************************/
3000 {
3001 DOUBLE bytes_per_frame;
3002 DOUBLE bytes_per_second;
3003 WORD32 achieved_bitrate;
3004
3005 if(s_app_ctxt.u4_pics_cnt != 0)
3006 {
3007 bytes_per_frame = (s_app_ctxt.u4_total_bytes) / (s_app_ctxt.u4_pics_cnt);
3008 }
3009 else
3010 {
3011 bytes_per_frame = 0;
3012 }
3013 bytes_per_second = (bytes_per_frame * s_app_ctxt.u4_tgt_frame_rate);
3014
3015 achieved_bitrate = bytes_per_second * 8;
3016
3017 printf("\nEncoding Completed\n");
3018 printf("Summary\n");
3019 printf("Input filename : %s\n", s_app_ctxt.ac_ip_fname);
3020 printf("Output filename : %s\n", s_app_ctxt.ac_op_fname);
3021 printf("Output Width : %-4d\n", s_app_ctxt.u4_wd);
3022 printf("Output Height : %-4d\n", s_app_ctxt.u4_ht);
3023 printf("Target Bitrate (bps) : %-4d\n", s_app_ctxt.u4_bitrate);
3024 printf("Achieved Bitrate (bps) : %-4d\n", achieved_bitrate);
3025 printf("Average Time per Frame : %-4d\n", s_app_ctxt.avg_time);
3026 printf("Achieved FPS : %-4.2f\n", 1000000.0 / s_app_ctxt.avg_time);
3027 }
3028
3029
3030 /*************************************************************************/
3031 /* Close Codec Instance */
3032 /*************************************************************************/
3033 {
3034 ih264e_retrieve_mem_rec_ip_t s_retrieve_mem_ip;
3035 ih264e_retrieve_mem_rec_op_t s_retrieve_mem_op;
3036 iv_mem_rec_t *ps_mem_rec = s_app_ctxt.ps_mem_rec;
3037
3038 s_retrieve_mem_ip.s_ive_ip.u4_size = sizeof(ih264e_retrieve_mem_rec_ip_t);
3039 s_retrieve_mem_ip.s_ive_ip.e_cmd = IV_CMD_RETRIEVE_MEMREC;
3040 s_retrieve_mem_ip.s_ive_ip.ps_mem_rec = s_app_ctxt.ps_mem_rec;
3041
3042 s_retrieve_mem_op.s_ive_op.u4_size = sizeof(ih264e_retrieve_mem_rec_op_t);
3043
3044 status = ih264e_api_function(ps_enc, &s_retrieve_mem_ip, &s_retrieve_mem_op);
3045 if(status != IV_SUCCESS)
3046 {
3047 sprintf(ac_error, "Unable to retrieve memory records = 0x%x\n",
3048 s_retrieve_mem_op.s_ive_op.u4_error_code);
3049 codec_exit(ac_error);
3050 }
3051
3052 /* Free memory records */
3053 for(i = 0; i < num_mem_recs; i++)
3054 {
3055 ih264a_aligned_free(ps_mem_rec->pv_base);
3056 ps_mem_rec++;
3057 }
3058 free(s_app_ctxt.ps_mem_rec);
3059 }
3060
3061 return 0;
3062 }
3063
3064
3065 #ifdef ANDROID_NDK
raise(int a)3066 int raise(int a)
3067 {
3068 printf("Divide by zero\n");
3069 return 0;
3070 }
__aeabi_assert(const char * assertion,const char * file,unsigned int line)3071 void __aeabi_assert(const char *assertion, const char *file, unsigned int line)
3072 {
3073 return;
3074 }
3075 #endif
3076