diff --git a/INSTALL b/INSTALL old mode 100644 new mode 100755 index 7d1c323..2550dab --- a/INSTALL +++ b/INSTALL @@ -4,10 +4,8 @@ Installation Instructions Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. - Copying and distribution of this file, with or without modification, -are permitted in any medium without royalty provided the copyright -notice and this notice are preserved. This file is offered as-is, -without warranty of any kind. + This file is free documentation; the Free Software Foundation gives +unlimited permission to copy, distribute and modify it. Basic Installation ================== @@ -15,11 +13,7 @@ Basic Installation Briefly, the shell commands `./configure; make; make install' should configure, build, and install this package. The following more-detailed instructions are generic; see the `README' file for -instructions specific to this package. Some packages provide this -`INSTALL' file but do not implement all of the features documented -below. The lack of an optional feature in a given package is not -necessarily a bug. More recommendations for GNU packages can be found -in *note Makefile Conventions: (standards)Makefile Conventions. +instructions specific to this package. The `configure' shell script attempts to guess correct values for various system-dependent variables used during compilation. It uses @@ -48,7 +42,7 @@ may remove or edit it. you want to change it or regenerate `configure' using a newer version of `autoconf'. - The simplest way to compile this package is: +The simplest way to compile this package is: 1. `cd' to the directory containing the package's source code and type `./configure' to configure the package for your system. @@ -59,22 +53,12 @@ of `autoconf'. 2. Type `make' to compile the package. 3. Optionally, type `make check' to run any self-tests that come with - the package, generally using the just-built uninstalled binaries. + the package. 4. Type `make install' to install the programs and any data files and - documentation. When installing into a prefix owned by root, it is - recommended that the package be configured and built as a regular - user, and only the `make install' phase executed with root - privileges. - - 5. Optionally, type `make installcheck' to repeat any self-tests, but - this time using the binaries in their final installed location. - This target does not install anything. Running this target as a - regular user, particularly if the prior `make install' required - root privileges, verifies that the installation completed - correctly. - - 6. You can remove the program binaries and object files from the + documentation. + + 5. You can remove the program binaries and object files from the source code directory by typing `make clean'. To also remove the files that `configure' created (so you can compile the package for a different kind of computer), type `make distclean'. There is @@ -83,15 +67,8 @@ of `autoconf'. all sorts of other programs in order to regenerate files that came with the distribution. - 7. Often, you can also type `make uninstall' to remove the installed - files again. In practice, not all packages have tested that - uninstallation works correctly, even though it is required by the - GNU Coding Standards. - - 8. Some packages, particularly those that use Automake, provide `make - distcheck', which can by used by developers to test that all other - targets like `make install' and `make uninstall' work correctly. - This target is generally not run by end users. + 6. Often, you can also type `make uninstall' to remove the installed + files again. Compilers and Options ===================== @@ -116,8 +93,7 @@ same time, by placing the object files for each architecture in their own directory. To do this, you can use GNU `make'. `cd' to the directory where you want the object files and executables to go and run the `configure' script. `configure' automatically checks for the -source code in the directory that `configure' is in and in `..'. This -is known as a "VPATH" build. +source code in the directory that `configure' is in and in `..'. With a non-GNU `make', it is safer to compile the package for one architecture at a time in the source code directory. After you have @@ -144,8 +120,7 @@ Installation Names By default, `make install' installs the package's commands under `/usr/local/bin', include files under `/usr/local/include', etc. You can specify an installation prefix other than `/usr/local' by giving -`configure' the option `--prefix=PREFIX', where PREFIX must be an -absolute file name. +`configure' the option `--prefix=PREFIX'. You can specify separate installation prefixes for architecture-specific files and architecture-independent files. If you @@ -156,46 +131,15 @@ Documentation and other data files still use the regular prefix. In addition, if you use an unusual directory layout you can give options like `--bindir=DIR' to specify different values for particular kinds of files. Run `configure --help' for a list of the directories -you can set and what kinds of files go in them. In general, the -default for these options is expressed in terms of `${prefix}', so that -specifying just `--prefix' will affect all of the other directory -specifications that were not explicitly provided. - - The most portable way to affect installation locations is to pass the -correct locations to `configure'; however, many packages provide one or -both of the following shortcuts of passing variable assignments to the -`make install' command line to change installation locations without -having to reconfigure or recompile. - - The first method involves providing an override variable for each -affected directory. For example, `make install -prefix=/alternate/directory' will choose an alternate location for all -directory configuration variables that were expressed in terms of -`${prefix}'. Any directories that were specified during `configure', -but not in terms of `${prefix}', must each be overridden at install -time for the entire installation to be relocated. The approach of -makefile variable overrides for each directory variable is required by -the GNU Coding Standards, and ideally causes no recompilation. -However, some platforms have known limitations with the semantics of -shared libraries that end up requiring recompilation when using this -method, particularly noticeable in packages that use GNU Libtool. - - The second method involves providing the `DESTDIR' variable. For -example, `make install DESTDIR=/alternate/directory' will prepend -`/alternate/directory' before all installation names. The approach of -`DESTDIR' overrides is not required by the GNU Coding Standards, and -does not work on platforms that have drive letters. On the other hand, -it does better at avoiding recompilation issues, and works well even -when some directory options were not specified in terms of `${prefix}' -at `configure' time. - -Optional Features -================= +you can set and what kinds of files go in them. If the package supports it, you can cause programs to be installed with an extra prefix or suffix on their names by giving `configure' the option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. +Optional Features +================= + Some packages pay attention to `--enable-FEATURE' options to `configure', where FEATURE indicates an optional part of the package. They may also pay attention to `--with-PACKAGE' options, where PACKAGE @@ -208,13 +152,6 @@ find the X include and library files automatically, but if it doesn't, you can use the `configure' options `--x-includes=DIR' and `--x-libraries=DIR' to specify their locations. - Some packages offer the ability to configure how verbose the -execution of `make' will be. For these packages, running `./configure ---enable-silent-rules' sets the default to minimal output, which can be -overridden with `make V=1'; while running `./configure ---disable-silent-rules' sets the default to verbose, which can be -overridden with `make V=0'. - Particular systems ================== @@ -351,7 +288,7 @@ operates. `configure' can determine that directory automatically. `--prefix=DIR' - Use DIR as the installation prefix. *note Installation Names:: + Use DIR as the installation prefix. *Note Installation Names:: for more details, including other options available for fine-tuning the installation locations. diff --git a/configure.ac b/configure.ac index 5280433..5f97c0c 100644 --- a/configure.ac +++ b/configure.ac @@ -81,38 +81,38 @@ else fi AM_CONDITIONAL(HAVE_OGGZ, [test "x$HAVE_OGGZ" = "xyes"]) -dnl -dnl Check for libuiomux -dnl -PKG_CHECK_MODULES(UIOMUX, uiomux >= 1.1.0, HAVE_UIOMUX="yes", HAVE_UIOMUX="no") -if test "x$HAVE_UIOMUX" = "xyes" ; then - AC_DEFINE(HAVE_UIOMUX, [], [Define if have libuiomux]) - AC_SUBST(UIOMUX_CFLAGS) - AC_SUBST(UIOMUX_LIBS) -fi -AM_CONDITIONAL(HAVE_UIOMUX, [test "x$HAVE_UIOMUX" = "xyes"]) - -dnl -dnl Check for libshveu -dnl -PKG_CHECK_MODULES(SHVEU, shveu >= 1.2.0, HAVE_SHVEU="yes", HAVE_SHVEU="no") -if test "x$HAVE_SHVEU" = "xyes" ; then - AC_DEFINE(HAVE_SHVEU, [], [Define if have libshveu]) - AC_SUBST(SHVEU_CFLAGS) - AC_SUBST(SHVEU_LIBS) -fi -AM_CONDITIONAL(HAVE_SHVEU, [test "x$HAVE_SHVEU" = "xyes"]) - -dnl -dnl Check for libshcodecs -dnl -PKG_CHECK_MODULES(SHCODECS, shcodecs >= 1.1.0, HAVE_SHCODECS="yes", HAVE_SHCODECS="no") -if test "x$HAVE_SHCODECS" = "xyes" ; then - AC_DEFINE(HAVE_SHCODECS, [], [Define if have libshcodecs]) - AC_SUBST(SHCODECS_CFLAGS) - AC_SUBST(SHCODECS_LIBS) -fi -AM_CONDITIONAL(HAVE_SHCODECS, [test "x$HAVE_SHCODECS" = "xyes"]) +#dnl +#dnl Check for libuiomux +#dnl +#PKG_CHECK_MODULES(UIOMUX, uiomux >= 1.1.0, HAVE_UIOMUX="yes", HAVE_UIOMUX="no") +#if test "x$HAVE_UIOMUX" = "xyes" ; then +# AC_DEFINE(HAVE_UIOMUX, [], [Define if have libuiomux]) +# AC_SUBST(UIOMUX_CFLAGS) +# AC_SUBST(UIOMUX_LIBS) +#fi +#AM_CONDITIONAL(HAVE_UIOMUX, [test "x$HAVE_UIOMUX" = "xyes"]) + +#dnl +#dnl Check for libshveu +#dnl +#PKG_CHECK_MODULES(SHVEU, shveu >= 1.2.0, HAVE_SHVEU="yes", HAVE_SHVEU="no") +#if test "x$HAVE_SHVEU" = "xyes" ; then +# AC_DEFINE(HAVE_SHVEU, [], [Define if have libshveu]) +# AC_SUBST(SHVEU_CFLAGS) +# AC_SUBST(SHVEU_LIBS) +#fi +#AM_CONDITIONAL(HAVE_SHVEU, [test "x$HAVE_SHVEU" = "xyes"]) + +#dnl +#dnl Check for libshcodecs +#dnl +#PKG_CHECK_MODULES(SHCODECS, shcodecs >= 1.1.0, HAVE_SHCODECS="yes", HAVE_SHCODECS="no") +#if test "x$HAVE_SHCODECS" = "xyes" ; then +# AC_DEFINE(HAVE_SHCODECS, [], [Define if have libshcodecs]) +# AC_SUBST(SHCODECS_CFLAGS) +# AC_SUBST(SHCODECS_LIBS) +#fi +#AM_CONDITIONAL(HAVE_SHCODECS, [test "x$HAVE_SHCODECS" = "xyes"]) # Checks for header files. AC_HEADER_RESOLV diff --git a/src/ControlFileUtil.c b/src/ControlFileUtil.c deleted file mode 100644 index 0564ac8..0000000 --- a/src/ControlFileUtil.c +++ /dev/null @@ -1,2580 +0,0 @@ -/* - * libshcodecs: A library for controlling SH-Mobile hardware codecs - * Copyright (C) 2009 Renesas Technology Corp. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include /* 050523 */ - -#include "avcbencsmp.h" - -#include - -/* サブ関数 */ -/* キーワードが一致する行を探し、その行の"="と";"の間の文字列を引数buf_valueに入れて返す */ -static int ReadUntilKeyMatch(FILE * fp_in, const char *key_word, char *buf_value) -{ - char buf_line[256], buf_work_value[256], *pos; - int line_length, keyword_length, try_count; - - keyword_length = strlen(key_word); - - try_count = 1; - - retry:; - while (fgets(buf_line, 256, fp_in)) { - line_length = strlen(buf_line); - if (line_length < keyword_length) { - continue; - } - - if (strncmp(key_word, &buf_line[0], keyword_length) == 0) { - pos = strchr(&buf_line[keyword_length], '='); - if (pos == NULL) { - return (-2); - /* キーワードに一致する行は見つかったが、"="が見つからなかった */ - ; - } - strcpy(buf_work_value, (pos + 2)); - pos = strchr(&buf_work_value[1], ';'); - if (pos == NULL) { - return (-3); - /* キーワードに一致する行は見つかったが、";"が見つからなかった */ - ; - } else { - *pos = '\0'; - } - - strcpy(buf_value, buf_work_value); - return (1); /* 見つかった */ - } - } - - /* 見つからなかったときは、ファイルの先頭に戻る */ - if (try_count == 1) { - rewind(fp_in); - try_count = 2; - goto retry; - } else { - return (-1); /* 見つからなった */ - } -} - -/***************************************************************************** - * Function Name : GetStringFromCtrlFile - * Description : コントロールファイルから、キーワードに対する文字列を読み込み、引数return_stringで返す - * - * Parameters : - * Called functions : - * Global Data : - * Return Value : - *****************************************************************************/ -static void GetStringFromCtrlFile(FILE * fp_in, const char *key_word, - char *return_string, int *status_flag) -{ - long return_code; - - *status_flag = 1; /* 正常のとき */ - - if ((fp_in == NULL) || (key_word == NULL) - || (return_string == NULL)) { - *status_flag = -1; /* 引数エラーのとき */ - return; - } - - return_code = ReadUntilKeyMatch(fp_in, key_word, return_string); - if (return_code == 1) { - *status_flag = 1; /* 正常のとき */ - - } else { - *status_flag = -1; /* 見つからなかった等のエラーのとき */ - } -} - -/***************************************************************************** - * Function Name : GetValueFromCtrlFile - * Description : コントロールファイルから、キーワードに対する数値を読み込み、戻り値で返す - * - * Parameters : - * Called functions : - * Global Data : - * Return Value : - *****************************************************************************/ -static long GetValueFromCtrlFile(FILE * fp_in, const char *key_word, - int *status_flag) -{ - char buf_line[256]; - long return_code, work_value; - - *status_flag = 1; /* 正常のとき */ - - if ((fp_in == NULL) || (key_word == NULL)) { - *status_flag = -1; /* 引数エラーのとき */ - return (0); - } - - return_code = ReadUntilKeyMatch(fp_in, key_word, &buf_line[0]); - if (return_code == 1) { - *status_flag = 1; /* 正常のとき */ - work_value = atoi((const char *) &buf_line[0]); - } else { - *status_flag = -1; /* 見つからなかった等のエラーのとき */ - work_value = 0; - } - - return (work_value); -} - -#if 0 -/***************************************************************************** - * Function Name : GetFromCtrlFtoOTHER_API_ENC_PARAM_SEI - * Description : コントロールファイルから、avebe_init_encode()以外のAPI関数で設定するもののうち、 - *          SEIパラメータだけを読み込み、引数に設定して返す - * - * Parameters : - * Called functions : - * Global Data : - * Return Value : - *****************************************************************************/ -static void GetFromCtrlFtoOTHER_API_ENC_PARAM_SEI(FILE * fp_in, - OTHER_API_ENC_PARAM * - other_API_enc_param) -{ - int status_flag, index; - long return_value; - avcbe_sei_buffering_period_param *sei_buffering_period_param; - avcbe_sei_pic_timing_param *sei_pic_timing_param; - avcbe_sei_pan_scan_rect_param *sei_pan_scan_rect_param; - avcbe_sei_filler_payload_param *sei_filler_payload_param; - avcbe_sei_recovery_point_param *sei_recovery_point_param; -/* 050324 avcbe_sei_dec_ref_pic_marking_repetition_param *sei_dec_ref_pic_marking_repetition_param; */ - - sei_buffering_period_param = - &(other_API_enc_param->sei_buffering_period_param); - sei_pic_timing_param = - &(other_API_enc_param->sei_pic_timing_param); - sei_pan_scan_rect_param = - &(other_API_enc_param->sei_pan_scan_rect_param); - sei_filler_payload_param = - &(other_API_enc_param->sei_filler_payload_param); - sei_recovery_point_param = - &(other_API_enc_param->sei_recovery_point_param); -/* 050324 sei_dec_ref_pic_marking_repetition_param = &(other_API_enc_param->sei_dec_ref_pic_marking_repetition_param); */ - - /* SEI_MESSAGE_BUFFERING_PERIOD */ - other_API_enc_param->out_buffering_period_SEI = AVCBE_OFF; - - return_value = - GetValueFromCtrlFile(fp_in, "SEI_BUFF_message_exist", - &status_flag); - if ((status_flag == 1) && (return_value == 1)) { - - other_API_enc_param->out_buffering_period_SEI = AVCBE_ON; - - /* 内部で設定PPSのseq_parameter_set_idを引っ張る *//* 041216 */ -/** return_value = GetValueFromCtrlFile(fp_in, "SEI_BUFF_SEQ_ID", &status_flag); - if (status_flag == 1) { - sei_buffering_period_param->avcbe_seq_parameter_set_id = return_value; - } -**/ - return_value = - GetValueFromCtrlFile(fp_in, "SEI_BUFF_NAL_DELAY", - &status_flag); - if (status_flag == 1) { - sei_buffering_period_param-> - avcbe_NalHrdBp - [0].avcbe_initial_cpb_removal_delay = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "SEI_BUFF_NAL_OFFSET", - &status_flag); - if (status_flag == 1) { - sei_buffering_period_param-> - avcbe_NalHrdBp - [0].avcbe_initial_cpb_removal_delay_offset = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "SEI_BUFF_VCL_DELAY", - &status_flag); - if (status_flag == 1) { - sei_buffering_period_param-> - avcbe_VclHrdBp - [0].avcbe_initial_cpb_removal_delay = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "SEI_BUFF_VCL_OFFSET", - &status_flag); - if (status_flag == 1) { - sei_buffering_period_param-> - avcbe_VclHrdBp - [0].avcbe_initial_cpb_removal_delay_offset = - return_value; - } - } - - /* if ((status_flag == 1)&&(return_value == 1))の終わり */ - /* SEI_MESSAGE_PIC_TIMING */ - other_API_enc_param->out_pic_timing_SEI = AVCBE_OFF; - - return_value = - GetValueFromCtrlFile(fp_in, "SEI_PICTM_message_exist", - &status_flag); - if ((status_flag == 1) && (return_value == 1)) { - - other_API_enc_param->out_pic_timing_SEI = AVCBE_ON; - - return_value = - GetValueFromCtrlFile(fp_in, "SEI_PICTIM_CPB_DELAY", - &status_flag); - if (status_flag == 1) { - sei_pic_timing_param->avcbe_cpb_removal_delay = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "SEI_PICTIM_DPB_DELAY", - &status_flag); - if (status_flag == 1) { - sei_pic_timing_param->avcbe_dpb_output_delay = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "SEI_PICTIM_PIC_STRUCT", - &status_flag); - if (status_flag == 1) { - sei_pic_timing_param->avcbe_pic_struct = - return_value; - } - - /* ここから下は、pic_structの値に応じてavcbe_clockts[]の要素数を決めること() */ - for (index = 0; index < 1; index++) { - return_value = - GetValueFromCtrlFile(fp_in, - "SEI_PICTIM_USE_CLOCK", - &status_flag); - if (status_flag == 1) { - sei_pic_timing_param->avcbe_clockts[index].avcbe_clock_timestamp = return_value; /* 050531 */ - } - - return_value = - GetValueFromCtrlFile(fp_in, - "SEI_PICTIM_CT_TYPE", - &status_flag); - if (status_flag == 1) { - sei_pic_timing_param-> - avcbe_clockts[index].avcbe_ct_type = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "SEI_PICTIM_NUNIT", - &status_flag); - if (status_flag == 1) { - sei_pic_timing_param-> - avcbe_clockts - [index].avcbe_nuit_field_based_flag = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, - "SEI_PICTIM_COUNTING", - &status_flag); - if (status_flag == 1) { - sei_pic_timing_param-> - avcbe_clockts - [index].avcbe_counting_type = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, - "SEI_PICTIM_FULLTMSTM", - &status_flag); - if (status_flag == 1) { - sei_pic_timing_param-> - avcbe_clockts - [index].avcbe_full_timestamp_flag = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, - "SEI_PICTIM_DISCONT", - &status_flag); - if (status_flag == 1) { - sei_pic_timing_param-> - avcbe_clockts - [index].avcbe_discontinuity_flag = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, - "SEI_PICTIM_CNT_DROP", - &status_flag); - if (status_flag == 1) { - sei_pic_timing_param-> - avcbe_clockts - [index].avcbe_cnt_dropped_flag = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, - "SEI_PICTIM_N_FRAMES", - &status_flag); - if (status_flag == 1) { - sei_pic_timing_param-> - avcbe_clockts[index].avcbe_n_frames = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, - "SEI_PICTIM_USE_SEC", - &status_flag); - if (status_flag == 1) { - sei_pic_timing_param->avcbe_clockts[index].avcbe_seconds_flag = return_value; /* 050531 */ - } - - return_value = - GetValueFromCtrlFile(fp_in, - "SEI_PICTIM_SEC_VAL", - &status_flag); - if (status_flag == 1) { - sei_pic_timing_param-> - avcbe_clockts - [index].avcbe_seconds_value = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, - "SEI_PICTIM_USE_MINU", - &status_flag); - if (status_flag == 1) { - sei_pic_timing_param->avcbe_clockts[index].avcbe_minutes_flag = return_value; /* 050531 */ - } - - return_value = - GetValueFromCtrlFile(fp_in, - "SEI_PICTIM_MINU_VAL", - &status_flag); - if (status_flag == 1) { - sei_pic_timing_param-> - avcbe_clockts - [index].avcbe_minutes_value = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, - "SEI_PICTIM_USE_HOUR", - &status_flag); - if (status_flag == 1) { - sei_pic_timing_param->avcbe_clockts[index].avcbe_hours_flag = return_value; /* 050531 */ - } - - return_value = - GetValueFromCtrlFile(fp_in, - "SEI_PICTIM_HOUR_VAL", - &status_flag); - if (status_flag == 1) { - sei_pic_timing_param-> - avcbe_clockts[index].avcbe_hours_value - = return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, - "SEI_PICTIM_TIME_OFFSET", - &status_flag); - if (status_flag == 1) { - sei_pic_timing_param-> - avcbe_clockts[index].avcbe_time_offset - = return_value; - } - } - /* ここまでは、pic_structの値に応じてavcbe_clockts[]の要素数を決めること */ - } - - /* SEI_MESSAGE_PAN_SCAN_RECT */ - other_API_enc_param->out_pan_scan_rect_SEI = AVCBE_OFF; - - return_value = - GetValueFromCtrlFile(fp_in, "SEI_PANSCAN_message_exist", - &status_flag); - if ((status_flag == 1) && (return_value == 1)) { - - other_API_enc_param->out_pan_scan_rect_SEI = AVCBE_ON; - - return_value = - GetValueFromCtrlFile(fp_in, "SEI_PANSCAN_RECT_ID", - &status_flag); - if (status_flag == 1) { - sei_pan_scan_rect_param->avcbe_pan_scan_rect_id = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "SEI_PANSCAN_CANCEL", - &status_flag); - if (status_flag == 1) { - sei_pan_scan_rect_param->avcbe_pan_scan_rect_cancel_flag - = return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "SEI_PANSCAN_CNT_MINUS1", - &status_flag); - if (status_flag == 1) { - sei_pan_scan_rect_param->avcbe_pan_scan_cnt_minus1 - = return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "SEI_PANSCAN_LEFT", - &status_flag); - if (status_flag == 1) { - sei_pan_scan_rect_param-> - avcbe_rect_offset - [0].avcbe_pan_scan_rect_left_offset = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "SEI_PANSCAN_RIGHT", - &status_flag); - if (status_flag == 1) { - sei_pan_scan_rect_param-> - avcbe_rect_offset - [0].avcbe_pan_scan_rect_right_offset = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "SEI_PANSCAN_TOP", - &status_flag); - if (status_flag == 1) { - sei_pan_scan_rect_param-> - avcbe_rect_offset - [0].avcbe_pan_scan_rect_top_offset = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "SEI_PANSCAN_BOTTOM", - &status_flag); - if (status_flag == 1) { - sei_pan_scan_rect_param-> - avcbe_rect_offset - [0].avcbe_pan_scan_rect_bottom_offset = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "SEI_PANSCAN_RECT_REPET", - &status_flag); - if (status_flag == 1) { - sei_pan_scan_rect_param->avcbe_pan_scan_rect_repetition_period - = return_value; - } - } - - /* SEI_MESSAGE_FILLER_PAYLOAD */ - other_API_enc_param->out_filler_payload_SEI = AVCBE_OFF; - - return_value = - GetValueFromCtrlFile(fp_in, "SEI_FILLER_message_exist", - &status_flag); - if ((status_flag == 1) && (return_value == 1)) { - - other_API_enc_param->out_filler_payload_SEI = AVCBE_ON; - - /* last payload size byte for Filler SEI */ - return_value = - GetValueFromCtrlFile(fp_in, "SEI_FILLER_SIZE", - &status_flag); - if (status_flag == 1) { - sei_filler_payload_param->avcbe_filler_payload_size - = return_value; - } - } - - /* SEI_MESSAGE_RECOVERY_POINT */ - other_API_enc_param->out_recovery_point_SEI = AVCBE_OFF; - - return_value = - GetValueFromCtrlFile(fp_in, "SEI_RECOVERY_message_exist", - &status_flag); - if ((status_flag == 1) && (return_value == 1)) { - - other_API_enc_param->out_recovery_point_SEI = AVCBE_ON; - - /* recovery frame cnt *//* 0 - MaxFrameNum(255)-1 */ - /* 内部で設定する *//* 041214 */ -/** return_value = GetValueFromCtrlFile(fp_in, "SEI_RECOVERY_FRAME", &status_flag); - if (status_flag == 1) { - sei_recovery_point_param->avcbe_recovery_frame_cnt = return_value; - } -**/ - - /* exact match flag */ - return_value = - GetValueFromCtrlFile(fp_in, "SEI_RECOVERY_MATCH", - &status_flag); - if (status_flag == 1) { - sei_recovery_point_param->avcbe_exact_match_flag = - return_value; - } - - /* broken link flag */ - return_value = - GetValueFromCtrlFile(fp_in, "SEI_RECOVERY_BROKEN", - &status_flag); - if (status_flag == 1) { - sei_recovery_point_param->avcbe_broken_link_flag = - return_value; - } - - /* changing slice group idc */ - /* 内部で設定する *//* 041214 */ -/** return_value = GetValueFromCtrlFile(fp_in, "SEI_RECOVERY_SLICE_GROUP", &status_flag); - if (status_flag == 1) { - sei_recovery_point_param->avcbe_changing_slice_group_idc = return_value; - } -**/ - } - - /* SEI_MESSAGE_DEC_REF_PIC_MARKING_REPETITION */ - other_API_enc_param->out_dec_ref_pic_marking_repetition_SEI = - AVCBE_OFF; - - return_value = - GetValueFromCtrlFile(fp_in, "SEI_REPET_message_exist", - &status_flag); - if ((status_flag == 1) && (return_value == 1)) { - - other_API_enc_param->out_dec_ref_pic_marking_repetition_SEI - = AVCBE_ON; - - /* original idr flag */ - /* 内部で設定する *//* 041214 */ -/** return_value = GetValueFromCtrlFile(fp_in, "SEI_REPET_IDR", &status_flag); - if (status_flag == 1) { - sei_dec_ref_pic_marking_repetition_param->avcbe_original_idr_flag = return_value; - } -**/ - /* original frame num */ - /* 内部で設定する *//* 041214 */ -/** return_value = GetValueFromCtrlFile(fp_in, "SEI_REPET_FRAME", &status_flag); - if (status_flag == 1) { - sei_dec_ref_pic_marking_repetition_param->avcbe_original_frame_num = return_value; - } -**/ - /* frame_mbs_only_flagは、baselineなので「1」固定。よって以下の2つは設定付加 */ -/** return_value = GetValueFromCtrlFile(fp_in, "SEI_REPET_FIELD", &status_flag); - if (status_flag == 1) { - sei_dec_ref_pic_marking_repetition_param->avcbe_original_field_pic_flag = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "SEI_REPET_BOTTOM", &status_flag); - if (status_flag == 1) { - sei_dec_ref_pic_marking_repetition_param->avcbe_original_bottom_field_flag = return_value; - } -**/ - /* ここから下はスライスヘッダの値を内部で引っ張る */ -/** return_value = GetValueFromCtrlFile(fp_in, "SEI_REPET_USE_OUTPUT_LONGT", &status_flag); - if (status_flag == 1) { - sei_dec_ref_pic_marking_repetition_param->avcbe_use_output_of_prior_pics_long_term_reference = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "SEI_REPET_OUTPUT", &status_flag); - if (status_flag == 1) { - sei_dec_ref_pic_marking_repetition_param->avcbe_no_output_of_prior_pics_flag = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "SEI_REPET_LONGT", &status_flag); - if (status_flag == 1) { - sei_dec_ref_pic_marking_repetition_param->avcbe_long_term_reference_flag = return_value; - } -**/ - } -} - -/***************************************************************************** - * Function Name : GetFromCtrlFtoOTHER_API_ENC_PARAM_VUI - * Description : コントロールファイルから、avebe_init_encode()以外のAPI関数で設定するもののうち、 - *          VUIパラメータだけを読み込み、引数に設定して返す - * - * Parameters : - * Called functions : - * Global Data : - * Return Value : - *****************************************************************************/ -static void GetFromCtrlFtoOTHER_API_ENC_PARAM_VUI(FILE * fp_in, - OTHER_API_ENC_PARAM * - other_API_enc_param) -{ - int status_flag; - long return_value; - avcbe_vui_main_param *vui_main_param; - - - vui_main_param = &(other_API_enc_param->vui_main_param); - - return_value = GetValueFromCtrlFile(fp_in, "VUI_use_aspect_ratio_info", &status_flag); /* (1) */ - if (status_flag == 1) { - vui_main_param->avcbe_aspect_ratio_info_present_flag = return_value; /* 050518 */ - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_aspect_ratio_idc", &status_flag); /* (2) */ - if (status_flag == 1) { - vui_main_param->avcbe_aspect_ratio_idc = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_sar_width", &status_flag); /* (3) */ - if (status_flag == 1) { - vui_main_param->avcbe_sar_width = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_sar_height", &status_flag); /* (4) */ - if (status_flag == 1) { - vui_main_param->avcbe_sar_height = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_use_overscan_info", &status_flag); /* (5) */ - if (status_flag == 1) { - vui_main_param->avcbe_overscan_info_present_flag = return_value; /* 050518 */ - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_overscan_appropriate_flag", &status_flag); /* (6) */ - if (status_flag == 1) { - vui_main_param->avcbe_overscan_appropriate_flag = - return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_use_video_signal_type", &status_flag); /* (7) */ - if (status_flag == 1) { - vui_main_param->avcbe_video_signal_type_present_flag = - return_value; - } - -/** return_value = GetValueFromCtrlFile(fp_in, "VUI_video_format", &status_flag); 041026削除 - if (status_flag == 1) { - vui_main_param->avcbe_video_format = return_value; - } **/ - - return_value = GetValueFromCtrlFile(fp_in, "VUI_video_full_range_flag", &status_flag); /* (8) */ - if (status_flag == 1) { - vui_main_param->avcbe_video_full_range_flag = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_use_colour_description", &status_flag); /* (9) */ - if (status_flag == 1) { - vui_main_param->avcbe_colour_description_present_flag = return_value; /* 050518 */ - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_colour_primaries", &status_flag); /* (10) */ - if (status_flag == 1) { - vui_main_param->avcbe_colour_primaries = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_transfer_characteristics", &status_flag); /* (11) */ - if (status_flag == 1) { - vui_main_param->avcbe_transfer_characteristics = - return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_matrix_coefficients", &status_flag); /* (12) */ - if (status_flag == 1) { - vui_main_param->avcbe_matrix_coefficients = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_use_chroma_loc_info", &status_flag); /* (13) */ - if (status_flag == 1) { - vui_main_param->avcbe_chroma_loc_info_present_flag = - return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_chroma_sample_loc_type_top_field", &status_flag); /* (14) */ - if (status_flag == 1) { - vui_main_param->avcbe_chroma_sample_loc_type_top_field = - return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_chroma_sample_loc_type_bottom_field", &status_flag); /* (15) */ - if (status_flag == 1) { - vui_main_param->avcbe_chroma_sample_loc_type_bottom_field = - return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_use_timing_info", &status_flag); /* (16) */ - if (status_flag == 1) { - vui_main_param->avcbe_timing_info_present_flag = - return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_num_units_in_tick", &status_flag); /* (17) */ - if (status_flag == 1) { - vui_main_param->avcbe_num_units_in_tick = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_time_scale", &status_flag); /* (18) */ - if (status_flag == 1) { - vui_main_param->avcbe_time_scale = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_fixed_frame_rate_flag", &status_flag); /* (19) */ - if (status_flag == 1) { - vui_main_param->avcbe_fixed_frame_rate_flag = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_use_nal_hrd_parameters", &status_flag); /* (20) */ - if (status_flag == 1) { - vui_main_param->avcbe_nal_hrd_parameters_present_flag = return_value; /* 050518 */ - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_nal_hrd_param_avcbe_cpb_cnt_minus1", &status_flag); /* (21-1) */ - if (status_flag == 1) { - vui_main_param->avcbe_nal_hrd_param.avcbe_cpb_cnt_minus1 = - return_value; - } -#if 1 /* 050526 */ - return_value = GetValueFromCtrlFile(fp_in, "VUI_nal_hrd_param_avcbe_bit_rate_scale", &status_flag); /* (21-2) */ - if (status_flag == 1) { - vui_main_param->avcbe_nal_hrd_param.avcbe_bit_rate_scale = - return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_nal_hrd_param.avcbe_cpb_size_scale", &status_flag); /* (21-3) */ - if (status_flag == 1) { - vui_main_param->avcbe_nal_hrd_param.avcbe_cpb_size_scale = - return_value; - } -#endif - -#if 1 /* こっちで使用すること */ - return_value = GetValueFromCtrlFile(fp_in, "VUI_nal_hrd_param_avcbe_schedsel_table[0]_avcbe_bit_rate_value_minus1", &status_flag); /* (21-4-1) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_nal_hrd_param.avcbe_schedsel_table[0]. - avcbe_bit_rate_value_minus1 = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_nal_hrd_param_avcbe_schedsel_table[0]_avcbe_cpb_size_value_minus1", &status_flag); /* (21-4-2) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_nal_hrd_param.avcbe_schedsel_table[0]. - avcbe_cpb_size_value_minus1 = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_nal_hrd_param_avcbe_schedsel_table[0]_avcbe_cbr_flag", &status_flag); /* (21-4-3) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_nal_hrd_param.avcbe_schedsel_table[0]. - avcbe_cbr_flag = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_nal_hrd_param_avcbe_schedsel_table[1]_avcbe_bit_rate_value_minus1", &status_flag); /* (21-4-1) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_nal_hrd_param.avcbe_schedsel_table[1]. - avcbe_bit_rate_value_minus1 = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_nal_hrd_param_avcbe_schedsel_table[1]_avcbe_cpb_size_value_minus1", &status_flag); /* (21-4-2) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_nal_hrd_param.avcbe_schedsel_table[1]. - avcbe_cpb_size_value_minus1 = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_nal_hrd_param_avcbe_schedsel_table[1]_avcbe_cbr_flag", &status_flag); /* (21-4-3) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_nal_hrd_param.avcbe_schedsel_table[1]. - avcbe_cbr_flag = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_nal_hrd_param_avcbe_schedsel_table[2]_avcbe_bit_rate_value_minus1", &status_flag); /* (21-4-1) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_nal_hrd_param.avcbe_schedsel_table[2]. - avcbe_bit_rate_value_minus1 = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_nal_hrd_param_avcbe_schedsel_table[2]_avcbe_cpb_size_value_minus1", &status_flag); /* (21-4-2) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_nal_hrd_param.avcbe_schedsel_table[2]. - avcbe_cpb_size_value_minus1 = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_nal_hrd_param_avcbe_schedsel_table[2]_avcbe_cbr_flag", &status_flag); /* (21-4-3) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_nal_hrd_param.avcbe_schedsel_table[2]. - avcbe_cbr_flag = return_value; - } -#else - { - int loop_index; - - for (loop_index = 0; - loop_index <= - vui_main_param-> - avcbe_nal_hrd_param.avcbe_cpb_cnt_minus1; - loop_index++) { - return_value = GetValueFromCtrlFile(fp_in, "VUI_nal_hrd_param_avcbe_schedsel_table[loop_index]_avcbe_bit_rate_value_minus1", &status_flag); /* (21-4-1) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_nal_hrd_param.avcbe_schedsel_table - [loop_index].avcbe_bit_rate_value_minus1 - = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_nal_hrd_param_avcbe_schedsel_table[loop_index]_avcbe_cpb_size_value_minus1", &status_flag); /* (21-4-2) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_nal_hrd_param.avcbe_schedsel_table - [loop_index].avcbe_cpb_size_value_minus1 - = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_nal_hrd_param_avcbe_schedsel_table[loop_index]_avcbe_cbr_flag", &status_flag); /* (21-4-3) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_nal_hrd_param.avcbe_schedsel_table - [loop_index].avcbe_cbr_flag = - return_value; - } - } - } -#endif - - return_value = GetValueFromCtrlFile(fp_in, "VUI_nal_hrd_param_avcbe_initial_cpb_removal_delay_length_minus1", &status_flag); /* (21-5) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_nal_hrd_param.avcbe_initial_cpb_removal_delay_length_minus1 - = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_nal_hrd_param_avcbe_cpb_removal_delay_length_minus1", &status_flag); /* (21-6) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_nal_hrd_param.avcbe_cpb_removal_delay_length_minus1 - = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_nal_hrd_param_avcbe_dpb_output_delay_length_minus1", &status_flag); /* (21-7) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_nal_hrd_param.avcbe_dpb_output_delay_length_minus1 - = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_nal_hrd_param_avcbe_time_offset_length", &status_flag); /* (21-8) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_nal_hrd_param.avcbe_time_offset_length = - return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_use_vcl_hrd_parameters", &status_flag); /* (22) */ - if (status_flag == 1) { - vui_main_param->avcbe_vcl_hrd_parameters_present_flag = return_value; /* 050518 */ - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_vcl_hrd_param.avcbe_cpb_cnt_minus1", &status_flag); /* (23-1) */ - if (status_flag == 1) { - vui_main_param->avcbe_vcl_hrd_param.avcbe_cpb_cnt_minus1 = - return_value; - } -#if 1 /* 050526 */ - return_value = GetValueFromCtrlFile(fp_in, "VUI_vcl_hrd_param.avcbe_bit_rate_scale", &status_flag); /* (23-2) */ - if (status_flag == 1) { - vui_main_param->avcbe_vcl_hrd_param.avcbe_bit_rate_scale = - return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_vcl_hrd_param.avcbe_cpb_size_scale", &status_flag); /* (23-3) */ - if (status_flag == 1) { - vui_main_param->avcbe_vcl_hrd_param.avcbe_cpb_size_scale = - return_value; - } -#endif - -#if 1 /* こっちで使用すること */ - return_value = GetValueFromCtrlFile(fp_in, "VUI_vcl_hrd_param_avcbe_schedsel_table[0]_avcbe_bit_rate_value_minus1", &status_flag); /* (23-4-1) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_vcl_hrd_param.avcbe_schedsel_table[0]. - avcbe_bit_rate_value_minus1 = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_vcl_hrd_param_avcbe_schedsel_table[0]_avcbe_cpb_size_value_minus1", &status_flag); /* (23-4-2) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_vcl_hrd_param.avcbe_schedsel_table[0]. - avcbe_cpb_size_value_minus1 = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_vcl_hrd_param_avcbe_schedsel_table[0]_avcbe_cbr_flag", &status_flag); /* (23-4-3) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_vcl_hrd_param.avcbe_schedsel_table[0]. - avcbe_cbr_flag = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_vcl_hrd_param_avcbe_schedsel_table[1]_avcbe_bit_rate_value_minus1", &status_flag); /* (23-4-1) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_vcl_hrd_param.avcbe_schedsel_table[1]. - avcbe_bit_rate_value_minus1 = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_vcl_hrd_param_avcbe_schedsel_table[1]_avcbe_cpb_size_value_minus1", &status_flag); /* (23-4-2) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_vcl_hrd_param.avcbe_schedsel_table[1]. - avcbe_cpb_size_value_minus1 = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_vcl_hrd_param_avcbe_schedsel_table[1]_avcbe_cbr_flag", &status_flag); /* (23-4-3) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_vcl_hrd_param.avcbe_schedsel_table[1]. - avcbe_cbr_flag = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_vcl_hrd_param_avcbe_schedsel_table[2]_avcbe_bit_rate_value_minus1", &status_flag); /* (23-4-1) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_vcl_hrd_param.avcbe_schedsel_table[2]. - avcbe_bit_rate_value_minus1 = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_vcl_hrd_param_avcbe_schedsel_table[2]_avcbe_cpb_size_value_minus1", &status_flag); /* (23-4-2) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_vcl_hrd_param.avcbe_schedsel_table[2]. - avcbe_cpb_size_value_minus1 = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_vcl_hrd_param_avcbe_schedsel_table[2]_avcbe_cbr_flag", &status_flag); /* (23-4-3) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_vcl_hrd_param.avcbe_schedsel_table[2]. - avcbe_cbr_flag = return_value; - } -#else - { - int loop_index; - - for (loop_index = 0; - loop_index <= - vui_main_param-> - avcbe_vcl_hrd_param.avcbe_cpb_cnt_minus1; - loop_index++) { - - return_value = GetValueFromCtrlFile(fp_in, "VUI_vcl_hrd_param_avcbe_schedsel_table[loop_index]_avcbe_bit_rate_value_minus1", &status_flag); /* (23-4-1) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_vcl_hrd_param.avcbe_schedsel_table - [loop_index].avcbe_bit_rate_value_minus1 - = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_vcl_hrd_param_avcbe_schedsel_table[loop_index]_avcbe_cpb_size_value_minus1", &status_flag); /* (23-4-2) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_vcl_hrd_param.avcbe_schedsel_table - [loop_index].avcbe_cpb_size_value_minus1 - = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_vcl_hrd_param_avcbe_schedsel_table[loop_index]_avcbe_cbr_flag", &status_flag); /* (23-4-3) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_vcl_hrd_param.avcbe_schedsel_table - [loop_index].avcbe_cbr_flag = - return_value; - } - } - } -#endif - - return_value = GetValueFromCtrlFile(fp_in, "VUI_vcl_hrd_param_avcbe_initial_cpb_removal_delay_length_minus1", &status_flag); /* (23-5) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_vcl_hrd_param.avcbe_initial_cpb_removal_delay_length_minus1 - = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_vcl_hrd_param_avcbe_cpb_removal_delay_length_minus1", &status_flag); /* (23-6) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_vcl_hrd_param.avcbe_cpb_removal_delay_length_minus1 - = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_vcl_hrd_param_avcbe_dpb_output_delay_length_minus1", &status_flag); /* (23-7) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_vcl_hrd_param.avcbe_dpb_output_delay_length_minus1 - = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_vcl_hrd_param_avcbe_time_offset_length", &status_flag); /* (23-8) */ - if (status_flag == 1) { - vui_main_param-> - avcbe_vcl_hrd_param.avcbe_time_offset_length = - return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_low_delay_hrd_flag", &status_flag); /* (24) */ - if (status_flag == 1) { - vui_main_param->avcbe_low_delay_hrd_flag = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_use_pic_struct", &status_flag); /* (25) */ - if (status_flag == 1) { - vui_main_param->avcbe_pic_struct_present_flag = return_value; /* 050518 */ - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_use_bitstream_restriction", &status_flag); /* (26) */ - if (status_flag == 1) { - vui_main_param->avcbe_bitstream_restriction_present_flag = return_value; /* 050518 */ - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_motion_vectors_over_pic_boundaries_flag", &status_flag); /* (27) */ - if (status_flag == 1) { - vui_main_param->avcbe_motion_vectors_over_pic_boundaries_flag - = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_max_bytes_per_pic_denom", &status_flag); /* (28) */ - if (status_flag == 1) { - vui_main_param->avcbe_max_bytes_per_pic_denom = - return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_max_bits_per_mb_denom", &status_flag); /* (29) */ - if (status_flag == 1) { - vui_main_param->avcbe_max_bits_per_mb_denom = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_log2_max_mv_length_horizontal", &status_flag); /* (30) */ - if (status_flag == 1) { - vui_main_param->avcbe_log2_max_mv_length_horizontal = - return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_log2_max_mv_length_vertical", &status_flag); /* (31) */ - if (status_flag == 1) { - vui_main_param->avcbe_log2_max_mv_length_vertical = - return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_num_reorder_frames", &status_flag); /* (32) */ - if (status_flag == 1) { - vui_main_param->avcbe_num_reorder_frames = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "VUI_max_dec_frame_buffering", &status_flag); /* (33) */ - if (status_flag == 1) { - vui_main_param->avcbe_max_dec_frame_buffering = - return_value; - } - -} -#endif - -/***************************************************************************** - * Function Name : GetFromCtrlFtoEncoding_property - * Description : コントロールファイルから、構造体avcbe_encoding_propertyのメンバ値を読み込み、引数に設定して返す - * - * Parameters : - * Called functions : - * Global Data : - * Return Value : - *****************************************************************************/ -static int GetFromCtrlFtoEncoding_property(FILE * fp_in, - SHCodecs_Encoder * encoder) -{ - int status_flag; - long return_value; - - return_value = - GetValueFromCtrlFile(fp_in, "stream_type", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_stream_type (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "bitrate", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_bitrate (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "x_pic_size", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_xpic_size (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "y_pic_size", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_ypic_size (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "frame_rate", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_frame_rate (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "I_vop_interval", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_I_vop_interval (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "mv_mode", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mv_mode (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "fcode_forward", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_fcode_forward (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "search_mode", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_search_mode (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "search_time_fixed", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_search_time_fixed (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "rate_ctrl_skip_enable", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_ratecontrol_skip_enable (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "rate_ctrl_use_prevquant", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_ratecontrol_use_prevquant (encoder, return_value); - } - - return_value = GetValueFromCtrlFile(fp_in, "rate_ctrl_respect_type ", &status_flag); /* 050426 */ - if (status_flag == 1) { - shcodecs_encoder_set_ratecontrol_respect_type (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "rate_ctrl_intra_thr_changeable", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_ratecontrol_intra_thr_changeable (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "control_bitrate_length", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_control_bitrate_length (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "intra_macroblock_refresh_cycle", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_intra_macroblock_refresh_cycle (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "video_format", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_video_format (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "frame_num_resolution", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_frame_num_resolution (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "noise_reduction", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_noise_reduction (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "reaction_param_coeff", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_reaction_param_coeff (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "weightedQ_mode", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_weightedQ_mode (encoder, return_value); - } - - return (1); /* 正常終了 */ -} - -/***************************************************************************** - * Function Name : GetFromCtrlFtoOther_options_H264 - * Description : コントロールファイルから、構造体avcbe_other_options_h264のメンバ値を読み込み、引数に設定して返す - * - * Parameters : - * Called functions : - * Global Data : - * Return Value : - *****************************************************************************/ -static int GetFromCtrlFtoOther_options_H264(FILE * fp_in, - SHCodecs_Encoder * encoder) -{ - int status_flag; - long return_value; - - return_value = - GetValueFromCtrlFile(fp_in, "Ivop_quant_initial_value", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_Ivop_quant_initial_value (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "Pvop_quant_initial_value", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_Pvop_quant_initial_value (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "use_dquant", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_use_dquant (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "clip_dquant_next_mb", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_clip_dquant_next_mb (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "clip_dquant_frame", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_clip_dquant_frame (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "quant_min", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_quant_min (encoder, return_value); - } - - return_value = GetValueFromCtrlFile(fp_in, "quant_min_Ivop_under_range", &status_flag); /* 050509 */ - if (status_flag == 1) { - shcodecs_encoder_set_h264_quant_min_Ivop_under_range (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "quant_max", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_quant_max (encoder, return_value); - } - - - return_value = GetValueFromCtrlFile(fp_in, "rate_ctrl_cpb_skipcheck_enable ", &status_flag); /* 050524 */ - if (status_flag == 1) { - shcodecs_encoder_set_h264_ratecontrol_cpb_skipcheck_enable (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "rate_ctrl_cpb_Ivop_noskip", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_ratecontrol_cpb_Ivop_noskip (encoder, return_value); - } - - return_value = GetValueFromCtrlFile(fp_in, "rate_ctrl_cpb_remain_zero_skip_enable", &status_flag); /* 050524 */ - if (status_flag == 1) { - shcodecs_encoder_set_h264_ratecontrol_cpb_remain_zero_skip_enable (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "rate_ctrl_cpb_offset", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_ratecontrol_cpb_offset (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "rate_ctrl_cpb_offset_rate", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_ratecontrol_cpb_offset_rate (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "rate_ctrl_cpb_buffer_mode", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_ratecontrol_cpb_buffer_mode (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "rate_ctrl_cpb_max_size", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_ratecontrol_cpb_max_size (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "rate_ctrl_cpb_buffer_unit_size", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_ratecontrol_cpb_buffer_unit_size (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "intra_thr_1", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_intra_thr_1 (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "intra_thr_2", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_intra_thr_2 (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "sad_intra_bias", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_sad_intra_bias (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "regularly_inserted_I_type", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_regularly_inserted_I_type (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "call_unit", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_call_unit (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "use_slice", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_use_slice (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "slice_size_mb", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_slice_size_mb (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "slice_size_bit", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_slice_size_bit (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "slice_type_value_pattern", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_slice_type_value_pattern (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "use_mb_partition", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_use_mb_partition (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "mb_partition_vector_thr", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_mb_partition_vector_thr (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "deblocking_mode", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_deblocking_mode (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "use_deblocking_filter_control", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_use_deblocking_filter_control (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "deblocking_alpha_offset", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_deblocking_alpha_offset (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "deblocking_beta_offset", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_deblocking_beta_offset (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "me_skip_mode", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_me_skip_mode (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "put_start_code", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_put_start_code (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "param_changeable", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_param_changeable (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "changeable_max_bitrate", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_changeable_max_bitrate (encoder, return_value); - } - - /* SequenceHeaderParameter */ - return_value = - GetValueFromCtrlFile(fp_in, "seq_param_set_id", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_seq_param_set_id (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "profile", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_profile (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "constraint_set_flag", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_constraint_set_flag (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "level_type", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_level_type (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "level_value", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_level_value (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "out_vui_parameters", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_out_vui_parameters (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "chroma_qp_index_offset", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_chroma_qp_index_offset (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "constrained_intra_pred", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_h264_constrained_intra_pred (encoder, return_value); - } - - return (1); /* 正常終了 */ -} - -/***************************************************************************** - * Function Name : GetFromCtrlFtoOther_options_MPEG4 - * Description : コントロールファイルから、構造体avcbe_other_options_mpeg4のメンバ値を読み込み、引数に設定して返す - * - * Parameters : - * Called functions : - * Global Data : - * Return Value : - *****************************************************************************/ -static int GetFromCtrlFtoOther_options_MPEG4(FILE * fp_in, - SHCodecs_Encoder * encoder) -{ - int status_flag; - long return_value; - - return_value = - GetValueFromCtrlFile(fp_in, "out_vos", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_out_vos (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "out_gov", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_out_gov (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "aspect_ratio_info_type", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_aspect_ratio_info_type (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "aspect_ratio_info_value", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_aspect_ratio_info_value (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "vos_profile_level_type", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_vos_profile_level_type (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "vos_profile_level_value", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_vos_profile_level_value (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "out_visual_object_identifier", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_out_visual_object_identifier (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "visual_object_verid", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_visual_object_verid (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "visual_object_priority", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_visual_object_priority (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "video_object_type_indication", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_video_object_type_indication (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "out_object_layer_identifier", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_out_object_layer_identifier (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "video_object_layer_verid", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_video_object_layer_verid (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "video_object_layer_priority", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_video_object_layer_priority (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "error_resilience_mode", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_error_resilience_mode (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "video_packet_size_mb", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_video_packet_size_mb (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "video_packet_size_bit", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_video_packet_size_bit (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "video_packet_header_extention", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_video_packet_header_extention (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "data_partitioned", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_data_partitioned (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "reversible_vlc", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_reversible_vlc (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "high_quality", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_high_quality (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "param_changeable", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_param_changeable (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "changeable_max_bitrate", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_changeable_max_bitrate (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "Ivop_quant_initial_value", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_Ivop_quant_initial_value (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "Pvop_quant_initial_value", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_Pvop_quant_initial_value (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "use_dquant", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_use_dquant (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "clip_dquant_frame", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_clip_dquant_frame (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "quant_min", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_quant_min (encoder, return_value); - } - - return_value = GetValueFromCtrlFile(fp_in, "quant_min_Ivop_under_range", &status_flag); /* 050509 */ - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_quant_min_Ivop_under_range (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "quant_max", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_quant_max (encoder, return_value); - } - -/* return_value = GetValueFromCtrlFile(fp_in, "rate_ctrl_rcperiod_skipcheck_enable", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_ratecontrol_rcperiod_skipcheck_enable (encoder, return_value); - } - - return_value = GetValueFromCtrlFile(fp_in, "rate_ctrl_rcperiod_Ivop_noskip", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_ratecontrol_rcperiod_Ivop_noskip (encoder, return_value); - } -*//* 050603 パラメータから削除されたので */ - - return_value = - GetValueFromCtrlFile(fp_in, "rate_ctrl_vbv_skipcheck_enable", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_ratecontrol_vbv_skipcheck_enable (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "rate_ctrl_vbv_Ivop_noskip", - &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_ratecontrol_vbv_Ivop_noskip (encoder, return_value); - } - - return_value = GetValueFromCtrlFile(fp_in, "rate_ctrl_vbv_remain_zero_skip_enable", &status_flag); /* 050524 */ - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_ratecontrol_vbv_remain_zero_skip_enable (encoder, return_value); - } - - return_value = GetValueFromCtrlFile(fp_in, "rate_ctrl_vbv_buffer_unit_size", &status_flag); /* 順序変更 050601 */ - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_ratecontrol_vbv_buffer_unit_size (encoder, return_value); - } - - return_value = GetValueFromCtrlFile(fp_in, "rate_ctrl_vbv_buffer_mode", &status_flag); /* 順序変更 050601 */ - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_ratecontrol_vbv_buffer_mode (encoder, return_value); - } - - return_value = GetValueFromCtrlFile(fp_in, "rate_ctrl_vbv_max_size", &status_flag); /* 順序変更 050601 */ - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_ratecontrol_vbv_max_size (encoder, return_value); - } - - return_value = GetValueFromCtrlFile(fp_in, "rate_ctrl_vbv_offset", &status_flag); /* 順序変更 050601 */ - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_ratecontrol_vbv_offset (encoder, return_value); - } - - return_value = GetValueFromCtrlFile(fp_in, "rate_ctrl_vbv_offset_rate", &status_flag); /* 順序変更 050601 */ - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_ratecontrol_vbv_offset_rate (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "quant_type", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_quant_type (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "use_AC_prediction", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_use_AC_prediction (encoder, return_value); - } - - return_value = GetValueFromCtrlFile(fp_in, "vop_min_mode", &status_flag); /* 050524 */ - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_vop_min_mode (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "vop_min_size", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_vop_min_size (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "intra_thr", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_intra_thr (encoder, return_value); - } - - return_value = - GetValueFromCtrlFile(fp_in, "b_vop_num", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_mpeg4_b_vop_num (encoder, return_value); - } - - return (1); /* 正常終了 */ -} - -#if 0 -/***************************************************************************** - * Function Name : GetFromCtrlFtoOTHER_API_ENC_PARAM - * Description : コントロールファイルから、avebe_init_encode()以外のAPI関数で設定するもの - *          を読み込み、引数に設定して返す - * - * Parameters : - * Called functions : - * Global Data : - * Return Value : - *****************************************************************************/ -static int GetFromCtrlFtoOTHER_API_ENC_PARAM(FILE * fp_in, - OTHER_API_ENC_PARAM * - other_API_enc_param, - avcbe_encoding_property * - encoding_property, - avcbe_other_options_h264 * - other_options_h264) -{ - int status_flag; - long return_value; - -/** return_value = GetValueFromCtrlFile(fp_in, "out_filter_image", &status_flag); 041026 - if (status_flag == 1) { - other_API_enc_param->out_filter_image = (unsigned char)return_value; - } **/ - - other_API_enc_param->weightdQ_enable = AVCBE_OFF; - -#if 0 /* 050324 */ - if (encoding_property->avcbe_weightedQ_mode == - AVCBE_WEIGHTEDQ_BY_USER) { - other_API_enc_param->weightdQ_enable = AVCBE_ON; - - return_value = - GetValueFromCtrlFile(fp_in, "wq_USER_weight_type", - &status_flag); - if (status_flag == 1) { - other_API_enc_param-> - weightedQ_info_user.avcbe_weight_type = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "wq_USER_mode_for_bit1", - &status_flag); - if (status_flag == 1) { - other_API_enc_param-> - weightedQ_info_user.avcbe_mode_for_bit1 = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "wq_USER_mode_for_bit2", - &status_flag); - if (status_flag == 1) { - other_API_enc_param-> - weightedQ_info_user.avcbe_mode_for_bit2 = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "wq_USER_mode_for_bit3", - &status_flag); - if (status_flag == 1) { - other_API_enc_param-> - weightedQ_info_user.avcbe_mode_for_bit3 = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "wq_USER_Qweight_for_bit1", - &status_flag); - if (status_flag == 1) { - other_API_enc_param-> - weightedQ_info_user.avcbe_Qweight_for_bit1 = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "wq_USER_Qweight_for_bit2", - &status_flag); - if (status_flag == 1) { - other_API_enc_param-> - weightedQ_info_user.avcbe_Qweight_for_bit2 = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "wq_USER_Qweight_for_bit3", - &status_flag); - if (status_flag == 1) { - other_API_enc_param-> - weightedQ_info_user.avcbe_Qweight_for_bit3 = - return_value; - } - - GetStringFromCtrlFile(fp_in, "wq_USER_table_filepath", - other_API_enc_param->weightedQ_table_filepath, - &status_flag); - - } -#endif - if (encoding_property->avcbe_weightedQ_mode == - AVCBE_WEIGHTEDQ_CENTER) { - other_API_enc_param->weightdQ_enable = AVCBE_ON; - - return_value = - GetValueFromCtrlFile(fp_in, "wq_CENTER_zone_size", - &status_flag); - if (status_flag == 1) { - other_API_enc_param-> - weightedQ_info_center.avcbe_zone_size = - return_value; - } - return_value = - GetValueFromCtrlFile(fp_in, "wq_CENTER_Qweight_range", - &status_flag); - if (status_flag == 1) { - other_API_enc_param-> - weightedQ_info_center.avcbe_Qweight_range = - return_value; - } - - } - if (encoding_property->avcbe_weightedQ_mode == - AVCBE_WEIGHTEDQ_RECT) { - other_API_enc_param->weightdQ_enable = AVCBE_ON; - - return_value = - GetValueFromCtrlFile(fp_in, "wq_RECT_zone_num", - &status_flag); - if (status_flag == 1) { - other_API_enc_param-> - weightedQ_info_rect.avcbe_zone_num = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, - "wq_RECT_zone1_pos_left_column", - &status_flag); - if (status_flag == 1) { - other_API_enc_param-> - weightedQ_info_rect.avcbe_zone1_pos. - avcbe_left_column = return_value; - } - return_value = - GetValueFromCtrlFile(fp_in, - "wq_RECT_zone1_pos_top_row", - &status_flag); - if (status_flag == 1) { - other_API_enc_param-> - weightedQ_info_rect.avcbe_zone1_pos. - avcbe_top_row = return_value; - } - return_value = - GetValueFromCtrlFile(fp_in, - "wq_RECT_zone1_pos_right_column", - &status_flag); - if (status_flag == 1) { - other_API_enc_param-> - weightedQ_info_rect.avcbe_zone1_pos. - avcbe_right_column = return_value; - } - return_value = - GetValueFromCtrlFile(fp_in, - "wq_RECT_zone1_pos_bottom_row", - &status_flag); - if (status_flag == 1) { - other_API_enc_param-> - weightedQ_info_rect.avcbe_zone1_pos. - avcbe_bottom_row = return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, - "wq_RECT_zone2_pos_left_column", - &status_flag); - if (status_flag == 1) { - other_API_enc_param-> - weightedQ_info_rect.avcbe_zone2_pos. - avcbe_left_column = return_value; - } - return_value = - GetValueFromCtrlFile(fp_in, - "wq_RECT_zone2_pos_top_row", - &status_flag); - if (status_flag == 1) { - other_API_enc_param-> - weightedQ_info_rect.avcbe_zone2_pos. - avcbe_top_row = return_value; - } - return_value = - GetValueFromCtrlFile(fp_in, - "wq_RECT_zone2_pos_right_column", - &status_flag); - if (status_flag == 1) { - other_API_enc_param-> - weightedQ_info_rect.avcbe_zone2_pos. - avcbe_right_column = return_value; - } - return_value = - GetValueFromCtrlFile(fp_in, - "wq_RECT_zone2_pos_bottom_row", - &status_flag); - if (status_flag == 1) { - other_API_enc_param-> - weightedQ_info_rect.avcbe_zone2_pos. - avcbe_bottom_row = return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, - "wq_RECT_zone1_Qweight_range", - &status_flag); - if (status_flag == 1) { - other_API_enc_param-> - weightedQ_info_rect.avcbe_zone1_Qweight_range = - return_value; - } - return_value = - GetValueFromCtrlFile(fp_in, - "wq_RECT_zone2_Qweight_type", - &status_flag); - if (status_flag == 1) { - other_API_enc_param-> - weightedQ_info_rect.avcbe_zone2_Qweight_type = - return_value; - } - } - - if (encoding_property->avcbe_stream_type == AVCBE_H264) { - if (other_options_h264->avcbe_out_vui_parameters == - AVCBE_ON) { - GetFromCtrlFtoOTHER_API_ENC_PARAM_VUI(fp_in, - other_API_enc_param); - } - } - - - if (encoding_property->avcbe_stream_type == AVCBE_H264) { - /* SEI messageがコントロールファイルに出力されているかチェック */ - return_value = - GetValueFromCtrlFile(fp_in, "SEI_message_exist", - &status_flag); - if ((status_flag == 1) && (return_value == 1)) { /* 出力されている */ - GetFromCtrlFtoOTHER_API_ENC_PARAM_SEI(fp_in, - other_API_enc_param); - } - } - - - return (1); /* 正常終了 */ -} - - -/***************************************************************************** - * Function Name : GetFromCtrlFtoVPU4_ENC - * Description : コントロールファイルから、構造体M4IPH_VPU4_ENCのメンバ値 - *         (VPU4版エンコーダの非公開エンコードパラメータのみ)を読み込み、引数に設定して返す - * - * Parameters : - * Called functions : - * Global Data : - * Return Value : - *****************************************************************************/ -static int GetFromCtrlFtoVPU4_ENC(FILE * fp_in, M4IPH_VPU4_ENC * vpu4_enc, - avcbe_encoding_property * encoding_property) -{ /* 050106 第3引数追加 */ - int status_flag; - long return_value; - - -#if 0 /* avcbe_set_interlace()で設定できるようにしたので削除 */ - if (encoding_property->avcbe_stream_type == AVCBE_MPEG4) { /* 041218 if追加 */ - - return_value = - GetValueFromCtrlFile(fp_in, "m4iph_interlaced", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_interlaced = (char) return_value; - } - - /* VP4_VOP_CTRL */ - return_value = - GetValueFromCtrlFile(fp_in, "m4iph_top_field_first", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_top_field_first = - (char) return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, - "m4iph_alternate_vertical_scan", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_alternate_vertical_scan = - (char) return_value; - } - } /* if (encoding_property->avcbe_stream_type == AVCBE_MPEG4)の終わり */ -#endif /* 0 */ - -#if 0 /* avcbe_set_h263_profile3()で設定できるようにしたので削除 */ - if (encoding_property->avcbe_stream_type == AVCBE_H263) { /* 041218 if追加 */ - - /* VP4_263_CTRL */ - return_value = GetValueFromCtrlFile(fp_in, "m4iph_force_mpeg4_pmv", &status_flag); /* 041111 */ - if (status_flag == 1) { - vpu4_enc->m4iph_force_mpeg4_pmv = return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "m4iph_gfid_first_slice", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_gfid_first_slice = return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "m4iph_op_ptype", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_op_ptype = return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "m4iph_plus_ptype", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_plus_ptype = return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "m4iph_annex_t", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_annex_t = return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "m4iph_annex_k", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_annex_k = return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "m4iph_annex_j", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_annex_j = return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, - "m4iph_split_screen_indicator", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_split_screen_indicator = - (char) return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, - "m4iph_doc_camera_indicator", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_doc_camera_indicator = - (char) return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, - "m4iph_full_pic_freeze_release", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_full_pic_freeze_release = - (char) return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "m4iph_source_format", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_source_format = - (char) return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "m4iph_gob_frame_id", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_gob_frame_id = (char) return_value; - } - - /* 041218追加 ------------ここから */ - /* VP4_VLC_PIC */ - return_value = - GetValueFromCtrlFile(fp_in, "m4iph_par_code", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_par_code = return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, - "m4iph_pic_width_indicator", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_pic_width_indicator = return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, - "m4iph_pic_height_indicator", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_pic_height_indicator = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "m4iph_custom_pic_format", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_custom_pic_format = return_value; - } - - /* VP4_VLC_CLK */ - return_value = - GetValueFromCtrlFile(fp_in, - "m4iph_ext_pixel_aspect_ratio_width", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_ext_pixel_aspect_ratio_width = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, - "m4iph_ext_pixel_aspect_ratio_height", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_ext_pixel_aspect_ratio_height = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, - "m4iph_custom_pic_clock_conv_code", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_custom_pic_clock_conv_code = - return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "m4iph_clock_divider", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_clock_divider = return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, - "m4iph_custom_pic_clock_freq_enable", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_custom_pic_clock_freq_enable = - return_value; - } - - /* VP4_RCQNT */ - return_value = - GetValueFromCtrlFile(fp_in, "m4iph_clipping_dq", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_clipping_dq = return_value; - } - - } - /* if (encoding_property->avcbe_stream_type == AVCBE_H263)の終わり */ - /* 041218追加 ------------ここまで */ -#endif /* 0 */ - -#if 0 /* 必要なら復活させること */ - /* VP4_VLC_CTRL */ - return_value = - GetValueFromCtrlFile(fp_in, "m4iph_mb_info_out", &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_mb_info_out = return_value; - } - - /* VP4_MC_CTRL */ - return_value = GetValueFromCtrlFile(fp_in, "m4iph_field_chroma_mode", &status_flag); /* 041111 */ - if (status_flag == 1) { - vpu4_enc->m4iph_field_chroma_mode = return_value; - } - - /* VP4_PRED_CTRL */ - return_value = - GetValueFromCtrlFile(fp_in, "m4iph_scan_mode", &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_scan_mode = return_value; - } - - return_value = GetValueFromCtrlFile(fp_in, "m4iph_idct_mode", &status_flag); /* 041218 */ - if (status_flag == 1) { - vpu4_enc->m4iph_idct_mode = return_value; - } - - /* VP4_MB_MAXBIT */ - return_value = - GetValueFromCtrlFile(fp_in, "m4iph_mb_max_bits", &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_mb_max_bits = return_value; - } - - /* VP4_RCQNT */ - return_value = - GetValueFromCtrlFile(fp_in, "m4iph_coef_cut_enable", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_coef_cut_enable = (char) return_value; - } -#endif /* 0 */ - - if (encoding_property->avcbe_stream_type == AVCBE_H264) { /* 050602 */ - - /* VP4_MQ_CTRL */ - return_value = - GetValueFromCtrlFile(fp_in, "m4iph_average_activity", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_average_activity = return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "m4iph_mq_act_enable", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_mq_act_enable = return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "m4iph_mq_intra_enable", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_mq_intra_enable = return_value; - } - - /* VP4_CTD_CTRL */ - return_value = - GetValueFromCtrlFile(fp_in, "m4iph_cut_diff_mode", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_cut_diff_mode = return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "m4iph_cut_diff_mv_th", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_cut_diff_mv_th = return_value; - } - - /* VP4_CTD_SADTHR */ - return_value = - GetValueFromCtrlFile(fp_in, "m4iph_cut_diff_sad_th0", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_cut_diff_sad_th0 = return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "m4iph_cut_diff_sad_th1", - &status_flag); - if (status_flag == 1) { - vpu4_enc->m4iph_cut_diff_sad_th1 = return_value; - } - } - - return (1); /* 正常終了 */ -} -#endif - -/***************************************************************************** - * Function Name : ctrlfile_get_params - * Description : コントロールファイルから、入力ファイル、出力先、ストリームタイプを得る - * Parameters : 省略 - * Called functions : - * Global Data : - * Return Value : 1: 正常終了、-1: エラー - *****************************************************************************/ -int ctrlfile_get_params(const char *ctrl_file, - APPLI_INFO * appli_info, long *stream_type) -{ - FILE *fp_in; - int status_flag; - long return_value; - char path_buf[256 + 8]; /* ÆþÎÏYUV¥Õ¥¡¥€¥ëÌŸ¡Ê¥Ñ¥¹ÉÕ€­¡Ë *//* 041201 */ - char file_buf[64 + 8]; /* ÆþÎÏYUV¥Õ¥¡¥€¥ëÌŸ¡Ê¥Ñ¥¹€Ê€·¡Ë */ - - if ((ctrl_file == NULL) || - (appli_info == NULL) || (stream_type == NULL)) { - return (-1); - } - - fp_in = fopen(ctrl_file, "rt"); - if (fp_in == NULL) { - return (-1); - } - - GetStringFromCtrlFile(fp_in, "input_yuv_path", path_buf, &status_flag); - GetStringFromCtrlFile(fp_in, "input_yuv_file", file_buf, &status_flag); - snprintf(appli_info->input_file_name_buf, 256, "%s/%s", path_buf, file_buf); - - GetStringFromCtrlFile(fp_in, "output_directry", path_buf, &status_flag); - GetStringFromCtrlFile(fp_in, "output_stream_file", file_buf, &status_flag); - if (!strcmp (file_buf, "-")) { - snprintf (appli_info->output_file_name_buf, 256, "-"); - } else { - snprintf(appli_info->output_file_name_buf, 256, "%s/%s", path_buf, file_buf); - } - - return_value = - GetValueFromCtrlFile(fp_in, "stream_type", &status_flag); - if (status_flag == 1) { - *stream_type = return_value; - } - return_value = - GetValueFromCtrlFile(fp_in, "x_pic_size", &status_flag); - if (status_flag == 1) { - appli_info->xpic = return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "y_pic_size", &status_flag); - if (status_flag == 1) { - appli_info->ypic = return_value; - } - - /*** ENC_EXEC_INFO ***/ - appli_info->yuv_CbCr_format = 2; /* 指定されなかったときのデフォルト値(2:Cb0,Cr0,Cb1,Cr1,...) *//* 050520 */ - return_value = GetValueFromCtrlFile(fp_in, "yuv_CbCr_format", &status_flag); /* 050520 */ - if (status_flag == 1) { - appli_info->yuv_CbCr_format = (char) return_value; - } - - return_value = - GetValueFromCtrlFile(fp_in, "frame_number_to_encode", &status_flag); - if (status_flag == 1) { - appli_info->frames_to_encode = return_value; - } - - fclose(fp_in); - - return (1); /* 正常終了 */ - -} - -/***************************************************************************** - * Function Name : ctrlfile_set_enc_param - * Description : コントロールファイルから、構造体avcbe_encoding_property、avcbe_other_options_h264、 - *          avcbe_other_options_mpeg4等のメンバ値を読み込み、設定して返す - * Parameters : 省略 - * Called functions : - * Global Data : - * Return Value : 0: 正常終了、-1: エラー - *****************************************************************************/ -int ctrlfile_set_enc_param(SHCodecs_Encoder * encoder, const char *ctrl_file) -{ - FILE *fp_in; - int status_flag; - long return_value; - long stream_type; - - fp_in = fopen(ctrl_file, "rt"); - if (fp_in == NULL) { - return -1; - } - - /*** avcbe_encoding_property ***/ - GetFromCtrlFtoEncoding_property(fp_in, encoder); - - stream_type = shcodecs_encoder_get_stream_type (encoder); - - if (stream_type == SHCodecs_Format_H264) { - /*** avcbe_other_options_h264 ***/ - GetFromCtrlFtoOther_options_H264(fp_in, encoder); - return_value = GetValueFromCtrlFile(fp_in, "ref_frame_num", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_ref_frame_num (encoder, return_value); - } - return_value = GetValueFromCtrlFile(fp_in, "filler_output_on", &status_flag); - if (status_flag == 1) { - shcodecs_encoder_set_output_filler_enable (encoder, return_value); - } - } else { - /*** avcbe_other_options_mpeg4 ***/ - GetFromCtrlFtoOther_options_MPEG4(fp_in, encoder); - } - - shcodecs_encoder_set_frame_no_increment(encoder, 1); - shcodecs_encoder_set_frame_no_increment(encoder, - shcodecs_encoder_get_frame_num_resolution(encoder) / - (shcodecs_encoder_get_frame_rate(encoder) / 10)); - - fclose(fp_in); - - return 0; -} - diff --git a/src/ControlFileUtil.h b/src/ControlFileUtil.h deleted file mode 100644 index 6e9bf96..0000000 --- a/src/ControlFileUtil.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * libshcodecs: A library for controlling SH-Mobile hardware codecs - * Copyright (C) 2009 Renesas Technology Corp. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA - */ - -#ifndef CONTROL_FILE_UTIL_H -#define CONTROL_FILE_UTIL_H - -#include -#include "avcbencsmp.h" - -int ctrlfile_get_params(const char *ctrl_file, - APPLI_INFO * appli_info, long *stream_type); - -int ctrlfile_set_enc_param(SHCodecs_Encoder * encoder, const char *ctrl_file); - -#endif /* CONTROL_FILE_UTIL_H */ diff --git a/src/Makefile.am b/src/Makefile.am index 6b75168..dc21d42 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -60,31 +60,25 @@ oggstdin_libs = $(OGGZ_LIBS) endif # SHRecord -if HAVE_SHCODECS -if HAVE_SHVEU -if HAVE_UIOMUX shrecord_headers = \ - shrecord.h \ - avcbencsmp.h \ - capture.h \ - display.h \ - framerate.h \ - thrqueue.h \ - ControlFileUtil.h + shrecord.h +# avcbencsmp.h \ +# capture.h \ +# display.h \ +# framerate.h \ +# thrqueue.h \ +# ControlFileUtil.h shrecord_sources = \ - shrecord.c \ - capture.c \ - display.c \ - framerate.c \ - thrqueue.c \ - ControlFileUtil.c - -shrecord_cflags = $(SHCODECS_CFLAGS) $(SHVEU_CFLAGS) $(UIOMUX_CFLAGS) -shrecord_libs = $(SHCODECS_LIBS) $(SHVEU_LIBS) $(UIOMUX_LIBS) -endif -endif -endif + shrecord.c +# capture.c \ +# display.c \ +# framerate.c \ +# thrqueue.c \ +# ControlFileUtil.c + +shrecord_cflags = # $(SHCODECS_CFLAGS) $(SHVEU_CFLAGS) $(UIOMUX_CFLAGS) +shrecord_libs = # $(SHCODECS_LIBS) $(SHVEU_LIBS) $(UIOMUX_LIBS) # Main noinst_HEADERS = \ diff --git a/src/avcbencsmp.h b/src/avcbencsmp.h deleted file mode 100644 index 3cc5d7c..0000000 --- a/src/avcbencsmp.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * libshcodecs: A library for controlling SH-Mobile hardware codecs - * Copyright (C) 2009 Renesas Technology Corp. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA - */ - -#ifndef AVCBENCSMP_H -#define AVCBENCSMP_H - -#include - -/*----- structures -----*/ - -typedef struct { - - /* Input YUV file name and it's file pointer */ - char input_file_name_buf[256]; /* for stream-1 */ - FILE *input_yuv_fp; /* for stream-1 */ - long yuv_CbCr_format; /* YUVǡʽϤǥɥե - Cb,Crǡ¤ӽ1:CbCr2:Cb0,Cr0,Cb1,Cr1,... - 3:Cb1饤ʬ,Cr1饤ʬ,... */ - - FILE *output_file_fp; /* for output stream-2 */ - char output_file_name_buf[256]; /* m4vե̾ */ - - long xpic; - long ypic; - - long frames_to_encode; /* target number of frames to encode */ - long frame_counter_of_input; /* the number of input frames encoded so far */ - -} APPLI_INFO; - - -//#define ALIGN(a, w) (void *)(((unsigned long)(a) + (w) - 1) & ~((w) - 1)) - - -int open_input_image_file(APPLI_INFO * appli_info); -int load_1frame_from_image_file(SHCodecs_Encoder * encoder, APPLI_INFO * appli_info); -void close_input_image_file(APPLI_INFO * appli_info); - - -FILE * -open_output_file(const char *fname); - -void close_output_file(FILE *fp); - - -#endif /* AVCBENCSMP */ diff --git a/src/capture.c b/src/capture.c deleted file mode 100644 index 268b05d..0000000 --- a/src/capture.c +++ /dev/null @@ -1,682 +0,0 @@ -/* - * V4L2 video capture example - * - * This program can be used and distributed without restrictions. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include - -#include /* low-level i/o */ -#include -#include -#include -#include -#include -#include - -#include -#include -#include "capture.h" - -#define CLEAR(x) memset (&(x), 0, sizeof (x)) -#define PAGE_ALIGN(addr) (((addr) + getpagesize() - 1) & ~(getpagesize()-1)) - -typedef enum { - IO_METHOD_READ, - IO_METHOD_MMAP, - IO_METHOD_USERPTR, -} io_method; - -struct buffer { - void *start; /* User space addr */ - unsigned char *phys_addr; /* Only used for USERPTR I/O */ - size_t length; - struct v4l2_buffer v4l2buf; -}; - -struct capture_ { - const char *dev_name; - int fd; - io_method io; - struct buffer *buffers; - unsigned int n_buffers; - int width; - int height; - unsigned int pixel_format; - int use_physical; - UIOMux *uiomux; -} sh_ceu; - - -static void errno_exit(const char *s) -{ - fprintf(stderr, "%s error %d, %s\n", s, errno, strerror(errno)); - - exit(EXIT_FAILURE); -} - -static int xioctl(int fd, int request, void *arg) -{ - int r; - - do - r = ioctl(fd, request, arg); - while (-1 == r && EINTR == errno); - - return r; -} - -static int -read_frame(capture * cap, capture_callback cb, void *user_data) -{ - struct v4l2_buffer buf; - unsigned int i; - - CLEAR(buf); - - switch (cap->io) { - case IO_METHOD_READ: - if (-1 == read(cap->fd, cap->buffers[0].start, cap->buffers[0].length)) { - switch (errno) { - case EAGAIN: - return 0; - - case EIO: - /* Could ignore EIO, see spec. */ - - /* fall through */ - - default: - errno_exit ("read"); - } - } - - cb(cap, cap->buffers[0].start, cap->buffers[0].length, user_data); - - break; - - case IO_METHOD_MMAP: - buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - buf.memory = V4L2_MEMORY_MMAP; - - if (-1 == xioctl(cap->fd, VIDIOC_DQBUF, &buf)) { - switch (errno) { - case EAGAIN: - return 0; - - case EIO: - /* Could ignore EIO, see spec. */ - - /* fall through */ - - default: - errno_exit("VIDIOC_DQBUF"); - } - } - - assert(buf.index < cap->n_buffers); - memcpy(&cap->buffers[buf.index].v4l2buf, &buf, sizeof(struct v4l2_buffer)); - cb(cap, cap->buffers[buf.index].start, - cap->buffers[buf.index].length, user_data); - - break; - - case IO_METHOD_USERPTR: - buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - buf.memory = V4L2_MEMORY_USERPTR; - - if (-1 == xioctl(cap->fd, VIDIOC_DQBUF, &buf)) { - switch (errno) { - case EAGAIN: - return 0; - - case EIO: - /* Could ignore EIO, see spec. */ - - /* fall through */ - - default: - errno_exit("VIDIOC_DQBUF"); - } - } - - for (i = 0; i < cap->n_buffers; ++i){ - /* TODO Work around the kernel - it sets the buffer size incorrectly */ - buf.length = cap->buffers[i].length; - - if (buf.m.userptr == (unsigned long) cap->buffers[i].start - && buf.length == cap->buffers[i].length) - break; - } - assert(i < cap->n_buffers); - memcpy(&cap->buffers[buf.index].v4l2buf, &buf, sizeof(struct v4l2_buffer)); - - if (cap->use_physical) - cb(cap, cap->buffers[i].phys_addr, buf.length, user_data); - else - cb(cap, cap->buffers[i].start, buf.length, user_data); - - break; - } - - return 1; -} - -void -capture_queue_buffer(capture * cap, const void * buffer_data) -{ - int i; - - if (cap->use_physical) { - for (i = 0; i < cap->n_buffers; ++i) { - if (cap->buffers[i].phys_addr == buffer_data) { - goto found; - } - } - } else { - for (i = 0; i < cap->n_buffers; ++i) { - if (cap->buffers[i].start == buffer_data) { - goto found; - } - } - } - - fprintf (stderr, "%s: Tried to release bad buffer %d %p\n", __func__, i, buffer_data); - exit (EXIT_FAILURE); - -found: - if (-1 == xioctl(cap->fd, VIDIOC_QBUF, &cap->buffers[i].v4l2buf)) - errno_exit("VIDIOC_QBUF"); -} - -int -capture_set_use_physical(capture * cap, int use_physical) -{ - if (!cap) return -1; - - cap->use_physical = use_physical; - return 0; -} - -void -capture_get_frame(capture * cap, capture_callback cb, void *user_data) -{ - - for (;;) { - fd_set fds; - struct timeval tv; - int r; - - FD_ZERO(&fds); - FD_SET(cap->fd, &fds); - - /* Timeout. */ - tv.tv_sec = 2; - tv.tv_usec = 0; - - r = select(cap->fd + 1, &fds, NULL, NULL, &tv); - - if (-1 == r) { - if (EINTR == errno) - continue; - - errno_exit("select"); - } - - if (0 == r) { - fprintf(stderr, "select timeout\n"); - exit(EXIT_FAILURE); - } - - if (read_frame(cap, cb, user_data)) - break; - /* EAGAIN - continue select loop. */ - } -} - -void capture_stop_capturing(capture * cap) -{ - enum v4l2_buf_type type; - - switch (cap->io) { - case IO_METHOD_READ: - /* Nothing to do. */ - break; - - case IO_METHOD_MMAP: - case IO_METHOD_USERPTR: - type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - - if (-1 == xioctl(cap->fd, VIDIOC_STREAMOFF, &type)) - errno_exit("VIDIOC_STREAMOFF"); - - break; - } -} - -void capture_start_capturing(capture * cap) -{ - unsigned int i; - enum v4l2_buf_type type; - - switch (cap->io) { - case IO_METHOD_READ: - /* Nothing to do. */ - break; - - case IO_METHOD_MMAP: - for (i = 0; i < cap->n_buffers; ++i) { - struct v4l2_buffer buf; - - CLEAR(buf); - - buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - buf.memory = V4L2_MEMORY_MMAP; - buf.index = i; - - if (-1 == xioctl(cap->fd, VIDIOC_QBUF, &buf)) - errno_exit("VIDIOC_QBUF"); - } - - type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - - if (-1 == xioctl(cap->fd, VIDIOC_STREAMON, &type)) - errno_exit("VIDIOC_STREAMON"); - - break; - - case IO_METHOD_USERPTR: - for (i = 0; i < cap->n_buffers; ++i) { - struct v4l2_buffer buf; - - CLEAR(buf); - - buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - buf.memory = V4L2_MEMORY_USERPTR; - buf.index = i; - buf.m.userptr = (unsigned long) cap->buffers[i].start; - buf.length = cap->buffers[i].length; - - if (-1 == xioctl(cap->fd, VIDIOC_QBUF, &buf)) - errno_exit("VIDIOC_QBUF"); - } - - type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - if (-1 == xioctl(cap->fd, VIDIOC_STREAMON, &type)) - errno_exit("VIDIOC_STREAMON"); - - break; - } -} - -static void uninit_device(capture * cap) -{ - unsigned int i; - - switch (cap->io) { - case IO_METHOD_READ: - free(cap->buffers[0].start); - break; - - case IO_METHOD_MMAP: - for (i = 0; i < cap->n_buffers; ++i) - if (-1 == - munmap(cap->buffers[i].start, cap->buffers[i].length)) - errno_exit("munmap"); - break; - - case IO_METHOD_USERPTR: - /* UIO memory, not stuff we malloc'ed */ - break; - } - - free(cap->buffers); -} - -static void init_read(capture * cap, unsigned int buffer_size) -{ - cap->buffers = calloc (1, sizeof (*cap->buffers)); - - if (!cap->buffers) { - fprintf (stderr, "Out of memory\n"); - exit (EXIT_FAILURE); - } - - cap->buffers[0].length = buffer_size; - cap->buffers[0].start = malloc (buffer_size); - - if (!cap->buffers[0].start) { - fprintf (stderr, "Out of memory\n"); - exit (EXIT_FAILURE); - } -} - -static void init_mmap(capture * cap) -{ - struct v4l2_requestbuffers req; - - CLEAR(req); - - req.count = 2; - req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - req.memory = V4L2_MEMORY_MMAP; - - if (-1 == xioctl(cap->fd, VIDIOC_REQBUFS, &req)) { - if (EINVAL == errno) { - fprintf(stderr, "%s does not support " - "memory mapping\n", cap->dev_name); - exit(EXIT_FAILURE); - } else { - errno_exit("VIDIOC_REQBUFS"); - } - } - - if (req.count < 2) { - fprintf(stderr, "Insufficient buffer memory on %s\n", - cap->dev_name); - exit(EXIT_FAILURE); - } - - cap->buffers = calloc(req.count, sizeof(*cap->buffers)); - - if (!cap->buffers) { - fprintf(stderr, "Out of memory\n"); - exit(EXIT_FAILURE); - } - - for (cap->n_buffers = 0; cap->n_buffers < req.count; - ++cap->n_buffers) { - struct v4l2_buffer buf; - - CLEAR(buf); - - buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - buf.memory = V4L2_MEMORY_MMAP; - buf.index = cap->n_buffers; - - if (-1 == xioctl(cap->fd, VIDIOC_QUERYBUF, &buf)) - errno_exit("VIDIOC_QUERYBUF"); - - cap->buffers[cap->n_buffers].length = buf.length; - cap->buffers[cap->n_buffers].start = - mmap(NULL /* start anywhere */ , - buf.length, - PROT_READ | PROT_WRITE /* required */ , - MAP_SHARED /* recommended */ , - cap->fd, buf.m.offset); - - if (MAP_FAILED == cap->buffers[cap->n_buffers].start) - errno_exit("mmap"); - } -} - -static void -init_userp(capture * cap, unsigned int buffer_size) -{ - struct v4l2_requestbuffers req; - unsigned int page_size; - - page_size = getpagesize(); - - CLEAR(req); - - req.count = 2; - req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - req.memory = V4L2_MEMORY_USERPTR; - - if (-1 == xioctl(cap->fd, VIDIOC_REQBUFS, &req)) { - if (EINVAL == errno) { - fprintf(stderr, "%s does not support " - "user pointer i/o\n", cap->dev_name); - exit(EXIT_FAILURE); - } else { - errno_exit("VIDIOC_REQBUFS"); - } - } - - if (req.count < 2) { - fprintf(stderr, "Insufficient buffer memory on %s\n", - cap->dev_name); - exit(EXIT_FAILURE); - } - - cap->buffers = calloc(req.count, sizeof (*cap->buffers)); - - if (!cap->buffers) { - fprintf(stderr, "Out of memory\n"); - exit(EXIT_FAILURE); - } - - for (cap->n_buffers = 0; cap->n_buffers < req.count; ++cap->n_buffers) { - void *user; - unsigned long phys; - - /* Get user memory from UIO */ - user = uiomux_malloc(cap->uiomux, UIOMUX_SH_VEU, - buffer_size, page_size); - phys = uiomux_virt_to_phys(cap->uiomux, UIOMUX_SH_VEU, user); - - cap->buffers[cap->n_buffers].length = buffer_size; - cap->buffers[cap->n_buffers].start = user; - cap->buffers[cap->n_buffers].phys_addr = (void *)phys; - - if (!cap->buffers[cap->n_buffers].start) { - fprintf(stderr, "Out of memory\n"); - exit(EXIT_FAILURE); - } - } -} - -static void init_device(capture * cap) -{ - struct v4l2_capability capb; - struct v4l2_cropcap cropcap; - struct v4l2_crop crop; - struct v4l2_format fmt; - unsigned int min; - - if (-1 == xioctl(cap->fd, VIDIOC_QUERYCAP, &capb)) { - if (EINVAL == errno) { - fprintf(stderr, "%s is no V4L2 device\n", - cap->dev_name); - exit(EXIT_FAILURE); - } else { - errno_exit("VIDIOC_QUERYCAP"); - } - } - - if (!(capb.capabilities & V4L2_CAP_VIDEO_CAPTURE)) { - fprintf(stderr, "%s is no video capture device\n", - cap->dev_name); - exit(EXIT_FAILURE); - } - - switch (cap->io) { - case IO_METHOD_READ: - if (!(capb.capabilities & V4L2_CAP_READWRITE)) { - fprintf(stderr, "%s does not support read i/o\n", - cap->dev_name); - exit(EXIT_FAILURE); - } - - break; - - case IO_METHOD_MMAP: - case IO_METHOD_USERPTR: - if (!(capb.capabilities & V4L2_CAP_STREAMING)) { - fprintf(stderr, "%s does not support streaming i/o\n", - cap->dev_name); - exit(EXIT_FAILURE); - } - - break; - } - - - /* Select video input, video standard and tune here. */ - - - CLEAR(cropcap); - - cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - - if (0 == xioctl(cap->fd, VIDIOC_CROPCAP, &cropcap)) { - crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - crop.c = cropcap.defrect; /* reset to default */ - - if (-1 == xioctl(cap->fd, VIDIOC_S_CROP, &crop)) { - switch (errno) { - case EINVAL: - /* Cropping not supported. */ - break; - default: - /* Errors ignored. */ - break; - } - } - } else { - /* Errors ignored. */ - } - - - CLEAR(fmt); - - fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - fmt.fmt.pix.width = cap->width; - fmt.fmt.pix.height = cap->height; - fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_NV12; - fmt.fmt.pix.field = V4L2_FIELD_ANY; - - if (-1 == xioctl(cap->fd, VIDIOC_S_FMT, &fmt)) { - errno_exit("VIDIOC_S_FMT"); - } - cap->pixel_format = fmt.fmt.pix.pixelformat; - - /* Note VIDIOC_S_FMT may change width and height. */ - cap->width = fmt.fmt.pix.width; - cap->height = fmt.fmt.pix.height; - - /* Buggy driver paranoia. */ - min = fmt.fmt.pix.width * 2; - if (fmt.fmt.pix.bytesperline < min) - fmt.fmt.pix.bytesperline = min; - min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height; - if (fmt.fmt.pix.sizeimage < min) - fmt.fmt.pix.sizeimage = min; - - /* TODO Work around the kernel - it sets the buffer size incorrectly */ - fmt.fmt.pix.sizeimage = PAGE_ALIGN(fmt.fmt.pix.sizeimage); - - switch (cap->io) { - case IO_METHOD_READ: - init_read(cap, fmt.fmt.pix.sizeimage); - break; - - case IO_METHOD_MMAP: - init_mmap(cap); - break; - - case IO_METHOD_USERPTR: - init_userp(cap, fmt.fmt.pix.sizeimage); - break; - } -} - -static void close_device(capture * cap) -{ - if (-1 == close(cap->fd)) - errno_exit("close"); - - cap->fd = -1; -} - -static void open_device(capture * cap, UIOMux * uiomux) -{ - struct stat st; - - - if (-1 == stat(cap->dev_name, &st)) { - fprintf(stderr, "Cannot identify '%s': %d, %s\n", - cap->dev_name, errno, strerror(errno)); - exit(EXIT_FAILURE); - } - - if (!S_ISCHR(st.st_mode)) { - fprintf(stderr, "%s is no device\n", cap->dev_name); - exit(EXIT_FAILURE); - } - - cap->fd = - open(cap->dev_name, O_RDWR /* required */ | O_NONBLOCK, 0); - - if (-1 == cap->fd) { - fprintf(stderr, "Cannot open '%s': %d, %s\n", - cap->dev_name, errno, strerror(errno)); - exit(EXIT_FAILURE); - } - - /* User mapped memory */ - cap->uiomux = uiomux; -} - -void capture_close(capture * cap) -{ - uninit_device(cap); - - close_device(cap); - - free(cap); -} - -static capture *capture_open_mode(const char *device_name, int width, int height, int mode, UIOMux * uiomux) -{ - capture *cap; - - cap = malloc(sizeof(*cap)); - if (!cap) - return NULL; - - cap->dev_name = device_name; - cap->io = mode; - cap->width = width; - cap->height = height; - cap->use_physical = 0; - - open_device(cap, uiomux); - init_device(cap); - - return cap; -} - -capture *capture_open(const char *device_name, int width, int height) -{ - return capture_open_mode(device_name, width, height, IO_METHOD_MMAP, NULL); -} - -capture *capture_open_userio(const char *device_name, int width, int height, UIOMux * uiomux) -{ - return capture_open_mode(device_name, width, height, IO_METHOD_USERPTR, uiomux); -} - -int capture_get_width(capture * cap) -{ - return cap->width; -} - -int capture_get_height(capture * cap) -{ - return cap->height; -} - -unsigned int capture_get_pixel_format(capture * cap) -{ - return cap->pixel_format; -} - diff --git a/src/capture.h b/src/capture.h deleted file mode 100644 index c58f65a..0000000 --- a/src/capture.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * libshcodecs: A library for controlling SH-Mobile hardware codecs - * Copyright (C) 2009 Renesas Technology Corp. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA - */ - -#ifndef __CAPTURE_H__ -#define __CAPTURE_H__ - -struct capture_; -typedef struct capture_ capture; - -typedef void (*capture_callback) (capture * cap, const unsigned char *frame_data, - size_t length, void *user_data); - -capture *capture_open(const char *device_name, int width, int height); - -capture *capture_open_userio(const char *device_name, int width, int height, UIOMux * uiomux); - -void capture_close(capture * cap); - -/** - * Set the data output mode to use physical addresses. - * If the calling application is interfacing to other IP blocks such as - * the VEU, then set this function. Otherwise, captured frame output will - * be mapped to userspace addresses, usable by normal applications. - * \param cap The capture handle - * \param use_physical Flag: Physical addresses will be reported for - * output frame data if set to a non-zero value. - * \retval 0 Success - */ -int -capture_set_use_physical(capture * cap, int use_physical); - -void capture_start_capturing(capture * cap); - -void capture_stop_capturing(capture * cap); - -void capture_get_frame(capture * cap, capture_callback cb, - void *user_data); - -void capture_queue_buffer(capture * cap, const void * buffer_data); - -/* Get the properties of the captured frames - * The v4l device may not support the request size - */ -int capture_get_width(capture * cap); -int capture_get_height(capture * cap); -unsigned int capture_get_pixel_format(capture * cap); - -#endif /* __CAPTURE_H__ */ diff --git a/src/cfg-read.c b/src/cfg-read.c index 4e81364..0e55e79 100644 --- a/src/cfg-read.c +++ b/src/cfg-read.c @@ -48,10 +48,8 @@ cfg_read_block_end (const char * name, void * user_data) } else if (!strncasecmp (name, "OggStdin", 8)) { cfg->resources = list_join (cfg->resources, oggstdin_resources (cfg->block_dict)); #endif -#ifdef HAVE_SHCODECS } else if (!strncasecmp (name, "SHRecord", 8)) { cfg->resources = list_join (cfg->resources, shrecord_resources (cfg->block_dict)); -#endif } dictionary_delete (cfg->block_dict); diff --git a/src/display.c b/src/display.c deleted file mode 100644 index 97f532a..0000000 --- a/src/display.c +++ /dev/null @@ -1,262 +0,0 @@ -/** - * SH display - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA - * - * Phil Edworthy - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include /* For pixel formats */ -#include - -#include "display.h" - -#ifndef FBIO_WAITFORVSYNC -#define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32) -#endif - -#define min(a, b) ((a) < (b) ? (a) : (b)) - -#define HW_ALIGN 2 - -struct display_t { - int fb_handle; - struct fb_fix_screeninfo fb_fix; - struct fb_var_screeninfo fb_var; - unsigned char *fb_base; - unsigned char *fb_screenMem; - int fb_index; - int lcd_w; - int lcd_h; - - int out_w; - int out_h; - int out_x; - int out_y; - - int veu; -}; - -/* Local functions */ -static int display_flip(void *disp); - - - -void *display_open(int veu) -{ - const char *device; - struct display_t *pvt; - void *iomem; - int size; - - pvt = calloc(1, sizeof(*pvt)); - if (!pvt) - return NULL; - pvt->veu = veu; - - /* Initialize display */ - device = getenv("FRAMEBUFFER"); - if (!device) { - if (access("/dev/.devfsd", F_OK) == 0) { - device = "/dev/fb/0"; - } else { - device = "/dev/fb0"; - } - } - - if ((pvt->fb_handle = open(device, O_RDWR)) < 0) { - fprintf(stderr, "Open %s: %s.\n", device, strerror(errno)); - free(pvt); - return 0; - } - if (ioctl(pvt->fb_handle, FBIOGET_FSCREENINFO, &pvt->fb_fix) < 0) { - fprintf(stderr, "Ioctl FBIOGET_FSCREENINFO error.\n"); - free(pvt); - return 0; - } - if (ioctl(pvt->fb_handle, FBIOGET_VSCREENINFO, &pvt->fb_var) < 0) { - fprintf(stderr, "Ioctl FBIOGET_VSCREENINFO error.\n"); - free(pvt); - return 0; - } - if (pvt->fb_fix.type != FB_TYPE_PACKED_PIXELS) { - fprintf(stderr, "Frame buffer isn't packed pixel.\n"); - free(pvt); - return 0; - } - - /* clear framebuffer and back buffer */ - size = (2 * pvt->fb_var.xres * pvt->fb_var.yres * pvt->fb_var.bits_per_pixel) / 8; - iomem = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, pvt->fb_handle, 0); - if (iomem != MAP_FAILED) { - memset(iomem, 0, size); - munmap(iomem, size); - } - - /* clear framebuffer (in case we couldn't mmap 2 x LCD) */ - size = (pvt->fb_var.xres * pvt->fb_var.yres * pvt->fb_var.bits_per_pixel) / 8; - iomem = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, pvt->fb_handle, 0); - if (iomem != MAP_FAILED) { - memset(iomem, 0, size); - munmap(iomem, size); - } - - pvt->lcd_w = pvt->fb_var.xres; - pvt->lcd_h = pvt->fb_var.yres; - - pvt->fb_screenMem = pvt->fb_base = (unsigned char*)pvt->fb_fix.smem_start; - pvt->fb_index = 0; - display_flip(pvt); - - display_set_fullscreen(pvt); - - return pvt; -} - -void display_close(void *p_display) -{ - struct display_t *pvt = (struct display_t *)p_display; - - pvt->fb_var.xoffset = 0; - pvt->fb_var.yoffset = 0; - - /* Restore the framebuffer to the front buffer */ - ioctl(pvt->fb_handle, FBIOPAN_DISPLAY, &pvt->fb_var); - - close(pvt->fb_handle); - free(pvt); -} - -static int display_flip(void *p_display) -{ - struct display_t *pvt = (struct display_t *)p_display; - struct fb_var_screeninfo fb_screen = pvt->fb_var; - - fb_screen.xoffset = 0; - fb_screen.yoffset = 0; - if (pvt->fb_index==0) - fb_screen.yoffset = pvt->fb_var.yres; - if (-1 == ioctl(pvt->fb_handle, FBIOPAN_DISPLAY, &fb_screen)) - return 0; - - /* Point to the back buffer */ - pvt->fb_screenMem = pvt->fb_base; - if (pvt->fb_index!=0) - pvt->fb_screenMem += pvt->fb_fix.line_length * pvt->fb_var.yres; - - pvt->fb_index = (pvt->fb_index+1) & 1; - - return 1; -} - -/* TODO Fixed at YCbCr420 to RGB565 fullscreen */ -int display_update( - void *p_display, - unsigned long py, - unsigned long pc, - int w, - int h, - int pitch, - int v4l_fmt) -{ - struct display_t *pvt = (struct display_t *)p_display; - unsigned long fb_addr; - double scale, aspect_x, aspect_y; - int dst_w, dst_h; - int ret; - unsigned long crt = 0; - - if (v4l_fmt != V4L2_PIX_FMT_NV12) - return -1; - - if ((pvt->out_w == -1) && (pvt->out_h == -1)) { - /* Fullscreen - stick with the source aspect ratio */ - aspect_x = (double) pvt->lcd_w / (double) w; - aspect_y = (double) pvt->lcd_h / (double) h; - if (aspect_x > aspect_y) { - scale = aspect_y; - } else { - scale = aspect_x; - } - - dst_w = (long) ((double) w * scale); - dst_h = (long) ((double) h * scale); - } else { - dst_w = pvt->out_w; - dst_h = pvt->out_h; - } - /* Observe hardware alignment */ - dst_w = dst_w - (dst_w % HW_ALIGN); - dst_h = dst_h - (dst_h % HW_ALIGN); - - if ((pvt->out_x == -1) && (pvt->out_y == -1)) { - /* Center - Assuming 2 bytes per pixel */ - fb_addr = (unsigned long)pvt->fb_screenMem - + (pvt->lcd_w - dst_w) - + (pvt->lcd_h - dst_h) * pvt->lcd_w; - } else { - fb_addr = (unsigned long)pvt->fb_screenMem - + (pvt->out_x + (pvt->out_y * pvt->lcd_w)) * 2; - } - - w = w - (w % HW_ALIGN); - h = h - (h % HW_ALIGN); - shveu_operation(pvt->veu, - py, pc, (long) w, (long) h, (long) pitch, SHVEU_YCbCr420, - fb_addr, 0UL, dst_w, dst_h, pvt->lcd_w, SHVEU_RGB565, - SHVEU_NO_ROT); - - display_flip(pvt); - - /* wait for vsync interrupt */ - ret = ioctl(pvt->fb_handle, FBIO_WAITFORVSYNC, &crt); - - return ret; -} - -int display_set_fullscreen(void *p_display) -{ - struct display_t *pvt = (struct display_t *)p_display; - pvt->out_w = -1; - pvt->out_h = -1; - pvt->out_x = -1; - pvt->out_y = -1; -} - -int display_set_position(void *p_display, int w, int h, int x, int y) -{ - struct display_t *pvt = (struct display_t *)p_display; - pvt->out_w = w; - pvt->out_h = h; - pvt->out_x = x - (x % HW_ALIGN); - pvt->out_y = y - (y % HW_ALIGN); - - /* Ensure the output is no bigger than the LCD */ - pvt->out_x = min(pvt->out_x, pvt->lcd_w); - pvt->out_y = min(pvt->out_y, pvt->lcd_h); - pvt->out_w = min(pvt->out_w, pvt->lcd_w - pvt->out_x); - pvt->out_h = min(pvt->out_h, pvt->lcd_h - pvt->out_y); -} - diff --git a/src/display.h b/src/display.h deleted file mode 100644 index 17ae170..0000000 --- a/src/display.h +++ /dev/null @@ -1,72 +0,0 @@ -/** - * SH display - * Helper to send YCbCr420 frames to the frame buffer. It uses the VEU - * hardware to scale & color convert the frames. it also handles aspect - * ratios for you and double buffered screens. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA - * - * Phil Edworthy - * - */ - -#include /* For pixel formats */ - -/** - * Open the frame buffer - * \param veu Handle to VEU driver (opened with shveu_open) - * \retval 0 Failure - * \retval >0 Handle - */ -void *display_open(int veu); - -/** - * Close the frame buffer - * \param p_display Handle returned from display_open - */ -void display_close(void *p_display); - -/** - * Position the output fullscreen (but observe aspect ratio) - * \param p_display Handle returned from display_open - */ -int display_set_fullscreen(void *p_display); - -/** - * Explicity position the output - * \param p_display Handle returned from display_open - */ -int display_set_position(void *p_display, int w, int h, int x, int y); - -/** - * Send frame to the framebuffer - * \param p_display Handle returned from display_open - * \param py Physical address of Y or RGB plane of source image - * \param pc Physical address of CbCr plane of source image (ignored for RGB) - * \param w Width in pixels of source image - * \param h Height in pixels of source image - * \param pitch Line pitch of source image - * \param v4l_fmt Format of source image (see ) - */ -int display_update( - void *p_display, - unsigned long py, - unsigned long pc, - int w, - int h, - int pitch, - int v4l_fmt -); - diff --git a/src/framerate.c b/src/framerate.c deleted file mode 100644 index c9e00ab..0000000 --- a/src/framerate.c +++ /dev/null @@ -1,234 +0,0 @@ -/* - * libshcodecs: A library for controlling SH-Mobile hardware codecs - * Copyright (C) 2009 Renesas Technology Corp. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include /* Definition of uint64_t */ - -#include "framerate.h" - -#define handle_error(msg) \ - do { perror(msg); exit(EXIT_FAILURE); } while (0) - -#define U_SEC_PER_SEC 1000000 -#define N_SEC_PER_SEC 1000000000 - -struct framerate * framerate_new_measurer (void) -{ - struct framerate * framerate; - struct timespec * now; - - framerate = calloc (1, sizeof(*framerate)); - if (framerate == NULL) - return NULL; - - now = &framerate->start; - - if (clock_gettime(CLOCK_MONOTONIC, now) == -1) - goto err_out; - - return framerate; - -err_out: - free (framerate); - return NULL; -} - -struct framerate * framerate_new_timer (double fps) -{ - struct framerate * framerate; - struct itimerspec new_value; - struct timespec * now; - long interval; - - if (fps < 0.0) - return NULL; - - framerate = framerate_new_measurer (); - if (framerate == NULL) - return NULL; - - /* Treat fps == 0.0 as a measurer, and avoid divide-by-zero */ - if (fps == 0.0) - return framerate; - - interval = (long) (N_SEC_PER_SEC / fps); - - now = &framerate->start; - -#ifdef HAVE_TIMERFD - /* Create a CLOCK_REALTIME absolute timer with initial - * expiration "now" and interval for the given framerate */ - - new_value.it_value.tv_sec = now->tv_sec; - new_value.it_value.tv_nsec = now->tv_nsec; - new_value.it_interval.tv_sec = 0; - new_value.it_interval.tv_nsec = interval; - - framerate->timer_fd = timerfd_create(CLOCK_MONOTONIC, 0); - if (framerate->timer_fd == -1) - goto err_out; - - if (timerfd_settime(framerate->timer_fd, TFD_TIMER_ABSTIME, - &new_value, NULL) == -1) - goto err_out; -#else - framerate->frame_us = interval / 1000; -#endif - - return framerate; - -err_out: - free (framerate); - return NULL; -} - -int framerate_destroy (struct framerate * framerate) -{ - int ret=0; - - if (framerate == NULL) return -1; - -#ifdef HAVE_TIMERFD - if (framerate->timer_fd != 0) - ret = close (framerate->timer_fd); -#endif - - free (framerate); - - return ret; -} - -long framerate_elapsed_time (struct framerate * framerate) -{ - if (framerate == NULL) return -1; - - return framerate->total_elapsed_us; -} - -double framerate_mean_fps (struct framerate * framerate) -{ - if (framerate == NULL) return -1.0; - - if (framerate->total_elapsed_us == 0) - return 0.0; - - return (double)framerate->nr_handled * U_SEC_PER_SEC / - framerate->total_elapsed_us; -} - -double framerate_instantaneous_fps (struct framerate * framerate) -{ - double curr_fps; - - if (framerate == NULL) return -1.0; - - if (framerate->curr_elapsed_us == 0) - return 0.0; - - if (framerate->curr_elapsed_us > 1000) { - curr_fps = (double)U_SEC_PER_SEC/framerate->curr_elapsed_us; - } else { - curr_fps = framerate->prev_fps; - } - - framerate->prev_fps = curr_fps; - - return curr_fps; -} - -/* Total microseconds elapsed */ -static long -framerate_elapsed_us (struct framerate * framerate) -{ - struct timespec curr; - long secs, nsecs; - int ret; - - ret = clock_gettime(CLOCK_MONOTONIC, &curr); - if (ret == -1) return ret; - - secs = curr.tv_sec - framerate->start.tv_sec; - nsecs = curr.tv_nsec - framerate->start.tv_nsec; - if (nsecs < 0) { - secs--; - nsecs += N_SEC_PER_SEC; - } - - return (secs*U_SEC_PER_SEC) + nsecs/1000; -} - -int framerate_mark (struct framerate * framerate) -{ - long prev_elapsed_us; - - if (framerate == NULL) return -1; - - framerate->nr_handled++; - - prev_elapsed_us = framerate->total_elapsed_us; - - framerate->total_elapsed_us = framerate_elapsed_us (framerate); - framerate->curr_elapsed_us = framerate->total_elapsed_us - prev_elapsed_us; - - return 0; -} - -uint64_t -framerate_wait (struct framerate * framerate) -{ - uint64_t exp; -#ifdef HAVE_TIMERFD - ssize_t s; - - if (framerate == NULL) return 0; - - s = read(framerate->timer_fd, &exp, sizeof(uint64_t)); - if (s != sizeof(uint64_t)) - handle_error("read"); - -#else - long expected, delta; - - if (framerate == NULL) return 0; - - expected = framerate->total_elapsed_us + framerate->frame_us; - delta = expected - framerate_elapsed_us (framerate); - - if (delta > 0) { - usleep (delta); - exp = 1; - } else { - exp = 1 + (-delta) / framerate->frame_us; - } - -#endif - framerate_mark (framerate); - framerate->nr_dropped += exp-1; - - return exp; -} diff --git a/src/framerate.h b/src/framerate.h deleted file mode 100644 index 1146d62..0000000 --- a/src/framerate.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * libshcodecs: A library for controlling SH-Mobile hardware codecs - * Copyright (C) 2009 Renesas Technology Corp. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA - */ -#ifndef __FRAMERATE_H__ -#define __FRAMERATE_H__ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include /* Definition of uint64_t */ -#include - -struct framerate { - int nr_handled; - int nr_dropped; - struct timespec start; - long total_elapsed_us; - long curr_elapsed_us; - double fps; - double prev_fps; - -#ifdef HAVE_TIMERFD - int timer_fd; -#else - long frame_us; -#endif -}; - -/* Create a framerate object without timer */ -struct framerate * framerate_new_measurer (void); - -/* Create a framerate object with timer */ -struct framerate * framerate_new_timer (double fps); - -/* Destroy a framerate object */ -int framerate_destroy (struct framerate * framerate); - -/* Mark a frame as done, without waiting. Increments nr_handled */ -int framerate_mark (struct framerate * framerate); - -/* Wait for the next timeout. Increments nr_handled, and will - * increment nr_dropped by the number of events missed since the last - * call to framerate_wait() */ -uint64_t framerate_wait (struct framerate * framerate); - -/* Time in microseconds since calling framerate_new_*() */ -long framerate_elapsed_time (struct framerate * framerate); - -/* Mean average FPS over the entire elapsed time */ -double framerate_mean_fps (struct framerate * framerate); - -/* Instantaneous FPS ... */ -double framerate_instantaneous_fps (struct framerate * framerate); - -#endif /* __FRAMERATE_H__ */ diff --git a/src/main.c b/src/main.c index f0a55fd..dbc7d1c 100644 --- a/src/main.c +++ b/src/main.c @@ -24,9 +24,7 @@ #include "ogg-stdin.h" #endif -#ifdef HAVE_SHCODECS #include "shrecord.h" -#endif /* #define DEBUG */ @@ -64,9 +62,7 @@ void sig_handler(int sig) oggstdin_sighandler (); #endif -#ifdef HAVE_SHCODECS shrecord_sighandler (); -#endif #ifdef DEBUG fprintf (stderr, "Got signal %d\n", sig); @@ -91,9 +87,7 @@ int main(int argc, char *argv[]) progname = argv[0]; -#ifdef HAVE_SHCODECS shrecord_init(); -#endif while (1) { #ifdef HAVE_GETOPT_LONG @@ -163,9 +157,7 @@ int main(int argc, char *argv[]) oggstdin_run(); #endif -#ifdef HAVE_SHCODECS shrecord_run(); -#endif signal (SIGINT, sig_handler); signal (SIGPIPE, sig_handler); diff --git a/src/shrecord.c b/src/shrecord.c old mode 100644 new mode 100755 index 8fdb1c7..c70b009 --- a/src/shrecord.c +++ b/src/shrecord.c @@ -38,29 +38,18 @@ #include #include #include +#include #include -#include /* For pixel formats */ -#include #include #include -#include - -#include -#include -#include +#include #include "http-reqline.h" #include "http-status.h" #include "params.h" #include "resource.h" -#include "avcbencsmp.h" -#include "capture.h" -#include "ControlFileUtil.h" -#include "framerate.h" -#include "display.h" #include "ringbuffer.h" -#include "thrqueue.h" /* #define DEBUG */ @@ -70,64 +59,34 @@ /* Maximum number of encoders per camera */ #define MAX_ENCODERS 8 -#define x_strdup(s) ((s)?strdup((s)):(NULL)) - -struct camera_data { - char * devicename; - - /* Captured frame information */ - capture *ceu; - unsigned long cap_w; - unsigned long cap_h; - int captured_frames; - - pthread_t convert_thread; - pthread_t capture_thread; - struct Queue * captured_queue; - pthread_mutex_t capture_start_mutex; +/* Directory path to the named pipe */ +#define TMP_DIR "/tmp" - struct framerate * cap_framerate; -}; +#define x_strdup(s) ((s)?strdup((s)):(NULL)) struct encode_data { - char * path; - char * ctlfile; - - APPLI_INFO ainfo; - - struct camera_data * camera; - - long stream_type; + pthread_t thread; + int alive; - pthread_mutex_t encode_start_mutex; + char path[MAXPATHLEN]; + char ctrl_filename[MAXPATHLEN]; + char fifo[MAXPATHLEN]; + char fifo_path[MAXPATHLEN]; - unsigned long enc_w; - unsigned long enc_h; - - int active; - struct ringbuffer rb; - - struct framerate * enc_framerate; + struct ringbuffer rb; }; struct private_data { - UIOMux * uiomux; - pthread_t main_thread; - int nr_cameras; - struct camera_data cameras[MAX_CAMERAS]; - int nr_encoders; - SHCodecs_Encoder *encoders[MAX_ENCODERS]; - struct encode_data *encdata[MAX_ENCODERS]; - - int do_preview; - void *display; + struct encode_data encdata[MAX_ENCODERS]; - int rotate_cap; + struct pollfd pfds[MAX_ENCODERS]; + pid_t shrecord_pid; + pid_t pid; - int output_frames; + int do_preview; }; void debug_printf(const char *fmt, ...) @@ -144,200 +103,28 @@ struct private_data pvt_data; static int alive=1; -/*****************************************************************************/ +static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; -/* Callback for frame capture */ -static void -capture_image_cb(capture *ceu, const unsigned char *frame_data, size_t length, - void *user_data) -{ - struct camera_data *cam = (struct camera_data*)user_data; - - queue_enq (cam->captured_queue, frame_data); - cam->captured_frames++; -} - -void *capture_main(void *data) -{ - struct camera_data *cam = (struct camera_data*)data; - - while(alive){ - framerate_wait(cam->cap_framerate); - capture_get_frame(cam->ceu, capture_image_cb, cam); - - /* This mutex is unlocked once the capture buffer is free */ - pthread_mutex_lock(&cam->capture_start_mutex); - } - - capture_stop_capturing(cam->ceu); - - pthread_mutex_unlock(&cam->capture_start_mutex); - - return NULL; -} - - -void *convert_main(void *data) -{ - struct camera_data *cam = (struct camera_data*)data; - struct private_data *pvt = &pvt_data; - int pitch, offset; - void *ptr; - unsigned long enc_y, enc_c; - unsigned long cap_y, cap_c; - int i; - - while(alive){ - cap_y = (unsigned long) queue_deq(cam->captured_queue); - cap_c = cap_y + (cam->cap_w * cam->cap_h); - - for (i=0; i < pvt->nr_encoders; i++) { - if (pvt->encdata[i]->camera != cam) continue; - - shcodecs_encoder_get_input_physical_addr (pvt->encoders[i], (unsigned int *)&enc_y, (unsigned int *)&enc_c); - - /* We are clipping, not scaling, as we need to perform a rotation, - but the VEU cannot do a rotate & scale at the same time. */ - uiomux_lock (pvt->uiomux, UIOMUX_SH_VEU); - shveu_operation(0, - cap_y, cap_c, - cam->cap_w, cam->cap_h, cam->cap_w, SHVEU_YCbCr420, - enc_y, enc_c, - pvt->encdata[i]->enc_w, pvt->encdata[i]->enc_h, pvt->encdata[i]->enc_w, SHVEU_YCbCr420, - pvt->rotate_cap); - uiomux_unlock (pvt->uiomux, UIOMUX_SH_VEU); - - /* Let the encoder get_input function return */ - pthread_mutex_unlock(&pvt->encdata[i]->encode_start_mutex); - } - - if (cam == pvt->encdata[0]->camera && pvt->do_preview) { - /* Use the VEU to scale the capture buffer to the frame buffer */ - uiomux_lock (pvt->uiomux, UIOMUX_SH_VEU); - display_update(pvt->display, - cap_y, cap_c, - cam->cap_w, cam->cap_h, cam->cap_w, - V4L2_PIX_FMT_NV12); - uiomux_unlock (pvt->uiomux, UIOMUX_SH_VEU); - } - - capture_queue_buffer (cam->ceu, cap_y); - pthread_mutex_unlock(&cam->capture_start_mutex); - - pvt->output_frames++; - } - - return NULL; -} - -/* SHCodecs_Encoder_Input callback for acquiring an image */ -static int get_input(SHCodecs_Encoder *encoder, void *user_data) -{ - struct encode_data *encdata = (struct encode_data*)user_data; - - /* This mutex is unlocked once the capture buffer has been copied to the - encoder input buffer */ - pthread_mutex_lock(&encdata->encode_start_mutex); - - if (encdata->enc_framerate == NULL) { - encdata->enc_framerate = framerate_new_measurer (); - } - - return (alive?0:1); -} - -/* SHCodecs_Encoder_Output callback for writing out the encoded data */ -static int write_output(SHCodecs_Encoder *encoder, - unsigned char *data, int length, void *user_data) -{ - struct encode_data *encdata = (struct encode_data*)user_data; - double ifps, mfps; - - if (shcodecs_encoder_get_frame_num_delta(encoder) > 0 && - encdata->enc_framerate != NULL) { - if (encdata->enc_framerate->nr_handled >= encdata->ainfo.frames_to_encode && - encdata->ainfo.frames_to_encode > 0) - return 1; - framerate_mark (encdata->enc_framerate); - ifps = framerate_instantaneous_fps (encdata->enc_framerate); - mfps = framerate_mean_fps (encdata->enc_framerate); - if (encdata->enc_framerate->nr_handled % 10 == 0) { - fprintf (stderr, " Encoding @ %4.2f fps \t(avg %4.2f fps)\r", ifps, mfps); - } - } - - ringbuffer_write (&encdata->rb, data, length); - - return (alive?0:1); -} +/*****************************************************************************/ -static void +void shrecord_cleanup (void) { - double time; struct private_data *pvt = &pvt_data; - int i; - - for (i=0; i < pvt->nr_cameras; i++) { - struct camera_data * cam = &pvt->cameras[i]; + struct encode_data *eds = pvt->encdata; + int i, status; - time = (double)framerate_elapsed_time (cam->cap_framerate); - time /= 1000000; - - debug_printf ("\n"); - debug_printf("Elapsed time (capture): %0.3g s\n", time); - - debug_printf("Captured %d frames (%.2f fps)\n", cam->captured_frames, - (double)cam->captured_frames/time); - if (pvt->do_preview) { - debug_printf("Displayed %d frames (%.2f fps)\n", pvt->output_frames, - (double)pvt->output_frames/time); - } - - framerate_destroy (cam->cap_framerate); + /* kill child process if needed */ + if (pvt->shrecord_pid) { + kill(pvt->shrecord_pid, SIGKILL); + waitpid(pvt->shrecord_pid, &status, 0); } - for (i=0; i < pvt->nr_encoders; i++) { - time = (double)framerate_elapsed_time (pvt->encdata[i]->enc_framerate); - time /= 1000000; - - debug_printf("[%d] Elapsed time (encode): %0.3g s\n", i, time); - debug_printf("[%d] Encoded %d frames (%.2f fps)\n", i, - pvt->encdata[i]->enc_framerate->nr_handled, - framerate_mean_fps (pvt->encdata[i]->enc_framerate)); - - shcodecs_encoder_close(pvt->encoders[i]); - - framerate_destroy (pvt->encdata[i]->enc_framerate); + /* clean files & fifos */ + for(i = 0; i < pvt->nr_encoders; i++) { + unlink(eds[i].fifo_path); + unlink(eds[i].ctrl_filename); } - - alive=0; - - for (i=0; i < pvt->nr_cameras; i++) { - struct camera_data * cam = &pvt->cameras[i]; - - pthread_join (cam->convert_thread, NULL); - pthread_join (cam->capture_thread, NULL); - - capture_close(cam->ceu); - } - - if (pvt->do_preview) - display_close(pvt->display); - shveu_close(); - - for (i=0; i < pvt->nr_encoders; i++) { - pvt->encdata[i]->active = 0; - pthread_mutex_unlock(&pvt->encdata[i]->encode_start_mutex); - pthread_mutex_destroy (&pvt->encdata[i]->encode_start_mutex); - } - - for (i=0; i < pvt->nr_cameras; i++) { - struct camera_data * cam = &pvt->cameras[i]; - pthread_mutex_destroy (&cam->capture_start_mutex); - } - - uiomux_close (pvt->uiomux); } void @@ -345,174 +132,106 @@ shrecord_sighandler (void) { struct private_data *pvt = &pvt_data; - alive = 0; - - pthread_join (pvt->main_thread, NULL); + shrecord_cleanup(); } -struct camera_data * get_camera (char * devicename, int width, int height) +void +shrecord_sigchld_handler (int ignore) { struct private_data *pvt = &pvt_data; - int i; - - for (i=0; i < MAX_CAMERAS; i++) { - if (pvt->cameras[i].devicename == NULL) - break; - - if (!strcmp (pvt->cameras[i].devicename, devicename)) { - return &pvt->cameras[i]; - } - } + int status; - if (i == MAX_CAMERAS) return NULL; + waitpid(pvt->shrecord_pid, &status, 0); + pvt->shrecord_pid = 0; - pvt->cameras[i].devicename = devicename; - pvt->cameras[i].cap_w = width; - pvt->cameras[i].cap_h = height; - - pvt->nr_cameras = i+1; - - return &pvt->cameras[i]; + shrecord_cleanup(); } +#define BUFFER_SIZE (128 * 1024) void * shrecord_main (void * data) { struct private_data *pvt = (struct private_data *)data; - int return_code, rc; - unsigned int pixel_format; - int c, i=0; - long target_fps10; - unsigned long rotate_input; + struct pollfd *pfds = pvt->pfds; + struct encode_data *eds = pvt->encdata; + int i, n, count; + unsigned char buffer[BUFFER_SIZE]; + char *argv[MAX_ENCODERS + 3]; + static char *shcodec_record = "shcodecs-record"; + static char *preview_off = "-P"; + + /* structure argument */ + n = 0; + argv[n++] = shcodec_record; + if (!pvt->do_preview) + argv[n++] = preview_off; + for(i = 0; i < pvt->nr_encoders; i++) + argv[n++] = eds[i].ctrl_filename; + + /* launch shcodec_record */ + pvt->shrecord_pid = fork(); + if (pvt->shrecord_pid < 0) { + fprintf(stderr, "Can't fork()\n"); + goto clean; + } if (pvt->shrecord_pid == 0) { + execvp(argv[0], argv); + + perror("execvp() failed"); + exit(1); + } else { + fprintf(stderr, "Launched shcodec-record successively\n"); + signal(SIGCHLD, shrecord_sigchld_handler); + } + + fprintf(stderr, "# of encs = %d\n", pvt->nr_encoders); if (pvt->nr_encoders == 0) return NULL; - pvt->output_frames = 0; - pvt->rotate_cap = SHVEU_NO_ROT; - - pvt->uiomux = uiomux_open (); - - for (i=0; i < pvt->nr_cameras; i++) { - /* Initalise the mutexes */ - pthread_mutex_init(&pvt->cameras[i].capture_start_mutex, NULL); - pthread_mutex_lock(&pvt->cameras[i].capture_start_mutex); - - /* Initialize the queues */ - pvt->cameras[i].captured_queue = queue_init(); - queue_limit (pvt->cameras[i].captured_queue, 2); - - /* Create the threads */ - rc = pthread_create(&pvt->cameras[i].convert_thread, NULL, convert_main, &pvt->cameras[i]); - if (rc) { - fprintf(stderr, "pthread_create failed, exiting\n"); - return NULL; - } - - /* Camera capture initialisation */ - pvt->cameras[i].ceu = capture_open_userio(pvt->cameras[i].devicename, pvt->cameras[i].cap_w, pvt->cameras[i].cap_h, pvt->uiomux); - if (pvt->cameras[i].ceu == NULL) { - fprintf(stderr, "capture_open failed, exiting\n"); - return NULL; - } - capture_set_use_physical(pvt->cameras[i].ceu, 1); - pvt->cameras[i].cap_w = capture_get_width(pvt->cameras[i].ceu); - pvt->cameras[i].cap_h = capture_get_height(pvt->cameras[i].ceu); - - pixel_format = capture_get_pixel_format (pvt->cameras[i].ceu); - if (pixel_format != V4L2_PIX_FMT_NV12) { - fprintf(stderr, "Camera capture pixel format is not supported\n"); - return NULL; - } - debug_printf("Camera %d resolution: %dx%d\n", i, pvt->cameras[i].cap_w, pvt->cameras[i].cap_h); - } - - /* VEU initialisation */ - if (shveu_open() < 0) { - fprintf (stderr, "Could not open VEU, exiting\n"); + for(i = 0; i < pvt->nr_encoders; i++) + pfds[i].fd = -1; + + for(i = 0; i < pvt->nr_encoders; i++) { + fprintf(stderr, "fifo for #%d = '%s'\n",i, eds[i].fifo_path); + pfds[i].fd = open(eds[i].fifo_path, O_RDWR, 0); + if (pfds[i].fd < 0) { + fprintf(stderr, "Can't open fifo - %s\n", eds[i].fifo_path); + goto clean; + } + pfds[i].events = POLLIN; + pfds[i].revents = 0; } - if (pvt->do_preview) { - pvt->display = display_open(0); - if (!pvt->display) { - return NULL; - } - } + while(1) { + n = poll(pfds, pvt->nr_encoders, 0); - for (i=0; i < pvt->nr_encoders; i++) { -#if 0 - if (pvt->rotate_cap == SHVEU_NO_ROT) { - pvt->encdata[i]->enc_w = pvt->cap_w; - pvt->encdata[i]->enc_h = pvt->cap_h; - } else { - pvt->encdata[i]->enc_w = pvt->cap_h; - pvt->encdata[i]->enc_h = pvt->cap_h * pvt->cap_h / pvt->cap_w; - /* Round down to nearest multiple of 16 for VPU */ - pvt->encdata[i]->enc_w = pvt->encdata[i]->enc_w - (pvt->encdata[i]->enc_w % 16); - pvt->encdata[i]->enc_h = pvt->encdata[i]->enc_h - (pvt->encdata[i]->enc_h % 16); - debug_printf("[%d] Rotating & cropping camera image ...\n", i); - } -#else - /* Override the encoding frame size in case of rotation */ - if (pvt->rotate_cap == SHVEU_NO_ROT) { - pvt->encdata[i]->enc_w = pvt->encdata[i]->ainfo.xpic; - pvt->encdata[i]->enc_h = pvt->encdata[i]->ainfo.ypic; - } else { - pvt->encdata[i]->enc_w = pvt->encdata[i]->ainfo.ypic; - pvt->encdata[i]->enc_h = pvt->encdata[i]->ainfo.xpic; + if (n < 0) { + fprintf(stderr, "poll() failed.\n"); + goto clean; } - debug_printf("[%d] Encode resolution: %dx%d\n", i, pvt->encdata[i]->enc_w, pvt->encdata[i]->enc_h); -#endif - /* VPU Encoder initialisation */ - pvt->encoders[i] = shcodecs_encoder_init(pvt->encdata[i]->enc_w, pvt->encdata[i]->enc_h, pvt->encdata[i]->stream_type); - if (pvt->encoders[i] == NULL) { - fprintf(stderr, "shcodecs_encoder_init failed, exiting\n"); - return NULL; + if (n > 0) { + for(i = 0; i < pvt->nr_encoders; i++) { + if (pfds[i].revents & POLLIN) { + pfds[i].revents = 0; + + count = read(pfds[i].fd, buffer, BUFFER_SIZE); + if (count < 0) { + fprintf(stderr, "read() failed on %s.\n", + eds[i].fifo); + goto clean; + } + ringbuffer_write(&eds[i].rb, buffer, count); + } + } } - shcodecs_encoder_set_input_callback(pvt->encoders[i], get_input, pvt->encdata[i]); - shcodecs_encoder_set_output_callback(pvt->encoders[i], write_output, pvt->encdata[i]); - - return_code = ctrlfile_set_enc_param(pvt->encoders[i], pvt->encdata[i]->ctlfile); - if (return_code < 0) { - fprintf (stderr, "Problem with encoder params in control file!\n"); - return NULL; - } - - //shcodecs_encoder_set_xpic_size(pvt->encoders[i], pvt->encdata[i]->enc_w); - //shcodecs_encoder_set_ypic_size(pvt->encoders[i], pvt->encdata[i]->enc_h); - } - - /* Set up the frame rate timer to match the encode framerate */ - target_fps10 = shcodecs_encoder_get_frame_rate(pvt->encoders[0]); - fprintf (stderr, "Target framerate: %.1f fps\n", target_fps10 / 10.0); - - for (i=0; i < pvt->nr_cameras; i++) { - /* Initialize framerate timer */ - pvt->cameras[i].cap_framerate = framerate_new_timer (target_fps10 / 10.0); - - capture_start_capturing(pvt->cameras[i].ceu); - - rc = pthread_create(&pvt->cameras[i].capture_thread, NULL, capture_main, &pvt->cameras[i]); - if (rc){ - fprintf(stderr, "pthread_create failed, exiting\n"); - return NULL; - } - } - rc = shcodecs_encoder_run_multiple(pvt->encoders, pvt->nr_encoders); - if (rc < 0) { - fprintf(stderr, "Error encoding, error code=%d\n", rc); - rc = NULL; } - /* Exit ok if shcodecs_encoder_run was stopped cleanly */ - if (rc == 1) rc = NULL; /* ??? */ + - shrecord_cleanup (); +clean: + shrecord_cleanup(); - return rc; - -exit_err: - /* General exit, prior to thread creation */ + /* shrecord_run() and caller anyway ignore the return value... */ return NULL; } @@ -520,6 +239,8 @@ int shrecord_run (void) { struct private_data *pvt = &pvt_data; + fprintf(stderr, "starting shrecord_main thread\n"); + return pthread_create(&pvt->main_thread, NULL, shrecord_main, pvt); } @@ -553,7 +274,7 @@ shrecord_body (int fd, http_request * request, params_t * request_headers, void rd = ringbuffer_open (&ed->rb); - while (ed->active) { + while (ed->alive) { while ((avail = ringbuffer_avail (&ed->rb, rd)) == 0) usleep (10000); @@ -579,72 +300,88 @@ shrecord_delete (void * data) { struct encode_data * ed = (struct encode_data *)data; - free (ed->path); - free (ed->ctlfile); free (ed->rb.data); - free (ed); +} + +static int +shrecord_tweak_ctrlfile(const char *orig_ctrl, const char *new_ctrl, const char *fifo) +{ + char path[MAXPATHLEN]; + char buffer[BUFSIZ]; + FILE *ofp, *nfp; + + if ((nfp = fopen(new_ctrl, "w")) == NULL) { + fprintf(stderr, "Can't open '%s'.\n", new_ctrl); + return -1; + } + + if ((ofp = fopen(orig_ctrl, "r")) == NULL) { + fprintf(stderr, "Can't open original control file '%s'\n", orig_ctrl); + return -1; + } + + while(fgets(buffer, BUFSIZ, ofp)) { + if (!strncmp(buffer, "output_directry", 15)) + fprintf(nfp, "output_directry = %s;\n", TMP_DIR); + else if (!strncmp(buffer, "output_stream_file", 18)) + fprintf(nfp, "output_stream_file = %s;\n", fifo); + else + fputs(buffer, nfp); + } + + fclose(nfp); + fclose(ofp); + + return 0; +} + +static int +shrecord_mkfifo ( char *fifo ) +{ + struct stat stat; + + if (!lstat(fifo, &stat)) + return (stat.st_mode & S_IFIFO) ? 0 : -1; + + return mkfifo(fifo, 077); } struct resource * -shrecord_resource (char * path, char * ctlfile) +shrecord_resource (const char * path, const char * ctlfile) { - struct encode_data * ed; + struct encode_data * ed = NULL; struct private_data *pvt = &pvt_data; int return_code; - unsigned char * data; + unsigned char * data = NULL; size_t len = 4096*16*32; if (pvt->nr_encoders > MAX_ENCODERS) return NULL; - if ((ed = calloc (1, sizeof(*ed))) == NULL) - return NULL; + ed = &pvt->encdata[pvt->nr_encoders]; - if ((data = malloc (len)) == NULL) { - free (ed); - return NULL; - } + strncpy(ed->path, path, MAXPATHLEN); + snprintf(ed->ctrl_filename, MAXPATHLEN, TMP_DIR "/shrecord_ctrl-%d.%d", + pvt->pid, pvt->nr_encoders); + snprintf(ed->fifo, MAXPATHLEN, "shrecord_fifo-%d.%d", + pvt->pid, pvt->nr_encoders); + snprintf(ed->fifo_path, MAXPATHLEN, TMP_DIR "/%s", ed->fifo); - ed->path = x_strdup (path); - if (ed->path == NULL) { - free (ed); - free (data); - return NULL; - } - ed->ctlfile = x_strdup (ctlfile); - if (ed->ctlfile == NULL) { - free (ed); - free (data); - free (ed->path); + /* create tweaked control file */ + if (shrecord_tweak_ctrlfile(ctlfile, ed->ctrl_filename, ed->fifo) < 0) return NULL; - } - return_code = ctrlfile_get_params(ed->ctlfile, - &ed->ainfo, &ed->stream_type); - if (return_code < 0) { - fprintf(stderr, "Error opening control file %s.\n", ed->ctlfile); + /* create fifo */ + if (shrecord_mkfifo(ed->fifo_path) < 0) return NULL; - } - - /* Override frames_to_encode to ensure streaming */ - ed->ainfo.frames_to_encode = -1; - - ed->camera = get_camera (ed->ainfo.input_file_name_buf, ed->ainfo.xpic, ed->ainfo.ypic); - - pvt->encdata[pvt->nr_encoders] = ed; - pvt->nr_encoders++; - -#if 0 - debug_printf("Input file: %s\n", ed->ainfo.input_file_name_buf); - debug_printf("Output file: %s\n", ed->ainfo.output_file_name_buf); -#endif + /* init ring buffer */ + if ((data = malloc (len)) == NULL) + return NULL; ringbuffer_init (&ed->rb, data, len); - pthread_mutex_init(&ed->encode_start_mutex, NULL); - pthread_mutex_unlock(&ed->encode_start_mutex); - - ed->active = 1; + ed->alive = 1; + pvt->nr_encoders++; return resource_new (shrecord_check, shrecord_head, shrecord_body, shrecord_delete, ed); } @@ -661,6 +398,8 @@ shrecord_resources (Dictionary * config) l = list_new(); + pvt->pid = getpid(); + path = dictionary_lookup (config, "Path"); ctlfile = dictionary_lookup (config, "CtlFile"); @@ -685,9 +424,6 @@ shrecord_init (void) struct private_data *pvt = &pvt_data; int ret; - if (prctl (PR_SET_UNALIGN, PR_UNALIGN_NOPRINT, 0, 0, 0) == -1) - perror ("prctl"); - memset (pvt, 0, sizeof (pvt_data)); /* Set preview on by default, allow to turn off by setting "Preview off" */ diff --git a/src/thrqueue.c b/src/thrqueue.c deleted file mode 100644 index 9dbfb20..0000000 --- a/src/thrqueue.c +++ /dev/null @@ -1,306 +0,0 @@ -/*- - * Copyright (c) 2007-2009, Thomas Hurst - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -/* - * thrqueue -- a thread-safe queue using STAILQ and pthreads. - * - * This allows for easy passing around of void *'s between threads; - * N threads can push work onto the queue, M threads can pull work - * off. - * - * Internal mallocs are cached up to an optional limit set by - * queue_pool_limit(), and the queue itself can optionally be limited - * with queue_limit(), which will block enqueues while the limit is - * reached. - * - * Enqueue and dequeue are serialized, so work units should be fairly - * chunky if performance is a concern. - * - * To build with the included example: - * - * gcc -O2 -Wall -Wextra -pthread -o thrqueue thrqueue.c -DBUILD_EXAMPLE - * - * Comments, criticism, and beer welcome. - */ - -#include - -#include -#include -#include - -#include "thrqueue.h" - -#ifdef NDEBUG -# define AZ(foo) do { if ((foo) != 0) abort(); } while (0) -#else -# define AZ(foo) do { assert((foo) == 0); } while (0) -#endif - -struct Queue* -queue_init() -{ - struct Queue *q; - q = (struct Queue *)malloc(sizeof(struct Queue)); - - if (q) - { - q->length = 0; - q->limit = -1; - q->pool_length = 0; - q->pool_limit = -1; - q->enq_waiters = 0; - AZ(pthread_mutex_init(&q->mutex, NULL)); - AZ(pthread_cond_init(&q->cv, NULL)); - AZ(pthread_cond_init(&q->enq_wait_cv, NULL)); - STAILQ_INIT(&q->queue); - STAILQ_INIT(&q->pool); - } - return(q); -} - -int -queue_destroy(struct Queue *q) -{ - struct QueueEntry *qi; - - assert(STAILQ_EMPTY(&q->queue)); - while (!STAILQ_EMPTY(&q->pool)) - { - qi = STAILQ_FIRST(&q->pool); - STAILQ_REMOVE_HEAD(&q->pool, entries); - q->pool_length--; - free(qi); - } - AZ(pthread_cond_destroy(&q->cv)); - AZ(pthread_mutex_destroy(&q->mutex)); - free(q); - return 1; -} - -int -queue_empty(struct Queue *q) -{ - /* This is safe as it's just checking if the head pointer == NULL */ - return(STAILQ_EMPTY(&q->queue)); -} - -int -queue_full(struct Queue *q) -{ - return (q->limit > 0 && q->length >= q->limit); -} - -int -queue_enq(struct Queue *q, void *item) -{ - struct QueueEntry *qi; - - AZ(pthread_mutex_lock(&q->mutex)); - if (queue_full(q)) - { - q->enq_waiters++; - while (queue_full(q)) - AZ(pthread_cond_wait(&q->enq_wait_cv, &q->mutex)); - q->enq_waiters--; - } - - if (!STAILQ_EMPTY(&q->pool)) - { - qi = STAILQ_FIRST(&q->pool); - STAILQ_REMOVE_HEAD(&q->pool, entries); - q->pool_length--; - } - else - { - if (!(qi = (struct QueueEntry *)malloc(sizeof(struct QueueEntry)))) - abort(); // could return 0/-1, but meh. - } - - qi->item = item; - - STAILQ_INSERT_TAIL(&q->queue, qi, entries); - q->length++; - AZ(pthread_cond_signal(&q->cv)); - AZ(pthread_mutex_unlock(&q->mutex)); - return 1; -} - -void * -queue_deq(struct Queue *q) -{ - void *ret = NULL; - struct QueueEntry *qi; - - AZ(pthread_mutex_lock(&q->mutex)); - while (STAILQ_EMPTY(&q->queue)) - AZ(pthread_cond_wait(&q->cv, &q->mutex)); - - qi = STAILQ_FIRST(&q->queue); - STAILQ_REMOVE_HEAD(&q->queue, entries); - q->length--; - ret = qi->item; - if (q->pool_limit < 0 || q->pool_length < q->pool_limit) - { - STAILQ_INSERT_TAIL(&q->pool, qi, entries); - q->pool_length++; - } - else free(qi); - - if (q->enq_waiters > 0) - AZ(pthread_cond_signal(&q->enq_wait_cv)); - AZ(pthread_mutex_unlock(&q->mutex)); - return ret; -} - -int -queue_length(struct Queue *q) -{ - return(q->length); -} - -int -queue_pool_length(struct Queue *q) -{ - return(q->pool_length); -} - -void -queue_limit(struct Queue *q, int limit) -{ - q->limit = limit; -} - -void -queue_pool_limit(struct Queue *q, int limit) -{ - q->pool_limit = limit; -} - -#ifdef BUILD_EXAMPLE -#include - -#define PRODUCER_ITERS 10000 -#define CONSUMER_THREADS 4 -#define PRODUCER_THREADS 2 - -struct Queue *q; - -void * -consume(void *args) -{ - char *buf; - int *bla = args; - int id = *bla; - - printf("Consumer %d launched, waiting for producer...\n", id); - while ((buf = queue_deq(q))) - { - printf("Consumer %d ate '%s'\n", id, buf); - fflush(stdout); - free(buf); -#ifndef NOSLEEP - usleep(random() % 100000); -#endif - } - printf("Consumer %d got a NULL, queue consumed, bye!\n", id); - return 0; -} - -void * -produce(void *args) -{ - int i; - char *str; - int *bla = args; - int id = *bla; - - printf("Producer %d launched, stand by...\n", id); - for(i=0;i - -STAILQ_HEAD(QueueHead,QueueEntry); - -struct Queue { - pthread_mutex_t mutex; - pthread_cond_t cv; - pthread_cond_t enq_wait_cv; - int enq_waiters; - int length; - int limit; - int pool_length; - int pool_limit; - struct QueueHead queue; - struct QueueHead pool; -}; - -struct QueueEntry { - void *item; - STAILQ_ENTRY(QueueEntry) entries; -}; - -struct Queue* queue_init(); -int queue_destroy(struct Queue *q); -int queue_empty(struct Queue *q); -int queue_full(struct Queue *q); -int queue_enq(struct Queue *q, void *item); -int queue_length(struct Queue *q); -int queue_pool_length(struct Queue *q); -void queue_limit(struct Queue *q, int limit); -void queue_pool_limit(struct Queue *q, int limit); -void *queue_deq(struct Queue *q); - -#endif