hardware/intel/libva
Revision | a7face7810264e61cdff84b1f022c1c63d039ab5 (tree) |
---|---|
Zeit | 2016-05-09 17:48:52 |
Autor | Xiang, Haihao <haihao.xiang@inte...> |
Commiter | Xiang, Haihao |
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>
@@ -99,6 +99,13 @@ static unsigned int MaxFrameNum = (1<<12); | ||
99 | 99 | static unsigned int Log2MaxFrameNum = 12; |
100 | 100 | static unsigned int Log2MaxPicOrderCntLsb = 8; |
101 | 101 | |
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 | + | |
102 | 109 | static int |
103 | 110 | build_packed_pic_buffer(unsigned char **header_buffer); |
104 | 111 |
@@ -1681,7 +1688,7 @@ encode_picture(FILE *yuv_fp, FILE *avc_fp, | ||
1681 | 1688 | |
1682 | 1689 | static void show_help() |
1683 | 1690 | { |
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"); | |
1685 | 1692 | } |
1686 | 1693 | |
1687 | 1694 | static void avcenc_context_seq_param_init(VAEncSequenceParameterBufferH264 *seq_param, |
@@ -1853,8 +1860,7 @@ int main(int argc, char *argv[]) | ||
1853 | 1860 | |
1854 | 1861 | va_init_display_args(&argc, argv); |
1855 | 1862 | |
1856 | - //TODO may be we should using option analytics library | |
1857 | - if(argc != 5 && argc != 6 && argc != 7) { | |
1863 | + if(argc < 5) { | |
1858 | 1864 | show_help(); |
1859 | 1865 | return -1; |
1860 | 1866 | } |
@@ -1864,43 +1870,63 @@ int main(int argc, char *argv[]) | ||
1864 | 1870 | picture_width_in_mbs = (picture_width + 15) / 16; |
1865 | 1871 | picture_height_in_mbs = (picture_height + 15) / 16; |
1866 | 1872 | |
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: | |
1874 | 1923 | show_help(); |
1875 | 1924 | return -1; |
1876 | 1925 | } |
1877 | - } else if (qp_value > 51) { | |
1878 | - qp_value = 51; | |
1879 | - } else if (qp_value < 0) { | |
1880 | - qp_value = 0; | |
1881 | 1926 | } |
1882 | 1927 | } else |
1883 | 1928 | qp_value = 28; //default const QP mode |
1884 | 1929 | |
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 | - | |
1904 | 1930 | yuv_fp = fopen(argv[3],"rb"); |
1905 | 1931 | if ( yuv_fp == NULL){ |
1906 | 1932 | printf("Can't open input YUV file\n"); |