• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

hardware/intel/libva


Commit MetaInfo

Revisiona7face7810264e61cdff84b1f022c1c63d039ab5 (tree)
Zeit2016-05-09 17:48:52
AutorXiang, Haihao <haihao.xiang@inte...>
CommiterXiang, Haihao

Log Message

test/encode/avcenc: use getopt_long_only() to parse optional command-line options

It's convenient to add new option later

Signed-off-by: Xiang, Haihao <haihao.xiang@intel.com>
Reviewed-By: Sean V Kelley <sean.v.kelley@intel.com>

Ändern Zusammenfassung

Diff

--- a/test/encode/avcenc.c
+++ b/test/encode/avcenc.c
@@ -99,6 +99,13 @@ static unsigned int MaxFrameNum = (1<<12);
9999 static unsigned int Log2MaxFrameNum = 12;
100100 static unsigned int Log2MaxPicOrderCntLsb = 8;
101101
102+static const struct option longopts[] = {
103+ {"qp", required_argument, 0, 1},
104+ {"fb", required_argument, 0, 2},
105+ {"mode", required_argument, 0, 3},
106+ { NULL, 0, NULL, 0}
107+};
108+
102109 static int
103110 build_packed_pic_buffer(unsigned char **header_buffer);
104111
@@ -1681,7 +1688,7 @@ encode_picture(FILE *yuv_fp, FILE *avc_fp,
16811688
16821689 static void show_help()
16831690 {
1684- printf("Usage: avnenc <width> <height> <input_yuvfile> <output_avcfile> [qp=qpvalue|fb=framebitrate] [mode=0(I frames only)/1(I and P frames)/2(I, P and B frames)\n");
1691+ printf("Usage: avnenc <width> <height> <input_yuvfile> <output_avcfile> [--qp=qpvalue|--fb=framebitrate] [--mode=0(I frames only)/1(I and P frames)/2(I, P and B frames)\n");
16851692 }
16861693
16871694 static void avcenc_context_seq_param_init(VAEncSequenceParameterBufferH264 *seq_param,
@@ -1853,8 +1860,7 @@ int main(int argc, char *argv[])
18531860
18541861 va_init_display_args(&argc, argv);
18551862
1856- //TODO may be we should using option analytics library
1857- if(argc != 5 && argc != 6 && argc != 7) {
1863+ if(argc < 5) {
18581864 show_help();
18591865 return -1;
18601866 }
@@ -1864,43 +1870,63 @@ int main(int argc, char *argv[])
18641870 picture_width_in_mbs = (picture_width + 15) / 16;
18651871 picture_height_in_mbs = (picture_height + 15) / 16;
18661872
1867- if (argc == 6 || argc == 7) {
1868- qp_value = -1;
1869- sscanf(argv[5], "qp=%d", &qp_value);
1870- if ( qp_value == -1 ) {
1871- frame_bit_rate = -1;
1872- sscanf(argv[5], "fb=%d", &frame_bit_rate);
1873- if ( frame_bit_rate == -1 ) {
1873+ if (argc > 5) {
1874+ char o;
1875+
1876+ optind = 5;
1877+
1878+ while ((o = getopt_long_only(argc, argv, "", longopts, NULL)) != -1) {
1879+ switch (o) {
1880+ case 1: // qp
1881+ frame_bit_rate = -1;
1882+ qp_value = atoi(optarg);
1883+
1884+ if (qp_value > 51)
1885+ qp_value = 51;
1886+
1887+ if (qp_value < 0)
1888+ qp_value = 0;
1889+
1890+ break;
1891+
1892+ case 2: // fb
1893+ qp_value = -1;
1894+ frame_bit_rate = atoi(optarg);
1895+
1896+ if (frame_bit_rate <= 0) {
1897+ show_help();
1898+
1899+ return -1;
1900+ }
1901+
1902+ break;
1903+
1904+ case 3: // mode
1905+ mode_value = atoi(optarg);
1906+
1907+ if (mode_value == 0)
1908+ ip_period = 0;
1909+ else if (mode_value == 1)
1910+ ip_period = 1;
1911+ else if (mode_value == 2)
1912+ /* Hack mechanism before adding the parameter of B-frame number */
1913+ ip_period = 2;
1914+ else {
1915+ printf("mode_value = %d\n", mode_value);
1916+ show_help();
1917+ return -1;
1918+ }
1919+
1920+ break;
1921+
1922+ default:
18741923 show_help();
18751924 return -1;
18761925 }
1877- } else if (qp_value > 51) {
1878- qp_value = 51;
1879- } else if (qp_value < 0) {
1880- qp_value = 0;
18811926 }
18821927 } else
18831928 qp_value = 28; //default const QP mode
18841929
1885- if (argc == 7) {
1886- sscanf(argv[6], "mode=%d", &mode_value);
1887- if ( mode_value == 0 ) {
1888- ip_period = 0;
1889- }
1890- else if ( mode_value == 1) {
1891- ip_period = 1;
1892- }
1893- else if ( mode_value == 2 ) {
1894- /* Hack mechanism before adding the parameter of B-frame number */
1895- ip_period = 3;
1896- }
1897- else {
1898- printf("mode_value=%d\n",mode_value);
1899- show_help();
1900- return -1;
1901- }
1902- }
1903-
19041930 yuv_fp = fopen(argv[3],"rb");
19051931 if ( yuv_fp == NULL){
19061932 printf("Can't open input YUV file\n");